GIFT-Grab  1708
Copyright (c) 2015-7, University College London (UCL)
ivideotarget.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "videoframe.h"
4 #include "except.h"
5 #include "iobserver.h"
6 #include "macros.h"
7 
8 namespace gg
9 {
10 
17 class IVideoTarget : public IObserver
18 {
19 protected:
25  {
26  // nop
27  }
28 
29 public:
33  virtual ~IVideoTarget()
34  {
35  // nop
36  }
37 
38 public:
50  virtual void append(const VideoFrame & frame) = 0;
51 
52  void update(VideoFrame & frame) override
53  {
54  append(frame);
55  }
56 
57 protected:
65  virtual void init(const std::string filepath, const float framerate) = 0;
66 
72  virtual void finalise() = 0;
73 
74 protected:
85  virtual void check_filetype_support(
86  const std::string filepath,
87  const std::string filetype)
88  {
89  if (filepath.empty())
90  throw VideoTargetError("Empty filepath specified");
91  else if (filepath.length() <= filetype.length()+1) // +1 for the dot, i.e. .mp4
92  throw VideoTargetError("Filepath not long enough to deduce output format");
93  else if (0 != filepath.compare(
94  filepath.length() - filetype.length(),
95  filetype.length(),
96  filetype))
97  {
98  std::string msg;
99  msg.append("Filetype of ")
100  .append(filepath)
101  .append(" not supported, use *.")
102  .append(filetype)
103  .append(" instead");
104  throw VideoTargetError(msg);
105  }
106  else
107  return; // nop, i.e. pass
108  }
109 
110 protected:
112 };
113 
114 }
virtual ~IVideoTarget()
Destructor, doing nothing.
Definition: ivideotarget.h:33
virtual void finalise()=0
Finalise writer, e.g. close file.
void update(VideoFrame &frame) override
Definition: ivideotarget.h:52
DISALLOW_COPY_AND_ASSIGNMENT(IVideoTarget)
virtual void append(const VideoFrame &frame)=0
Append frame to output.
Definition: broadcastdaemon.cpp:7
virtual void check_filetype_support(const std::string filepath, const std::string filetype)
Directly throw a VideoTargetError if specified filepath is not of required filetype.
Definition: ivideotarget.h:85
Thrown in case of problems outputting video, e.g. to files.
Definition: except.h:120
This abstract class provides the API to be implemented by classes that provide functionality to save ...
Definition: ivideotarget.h:17
A class to represent a video frame.
Definition: videoframe.h:47
IVideoTarget()
Default constructor that should never be called publicly.
Definition: ivideotarget.h:24
Every observer interested in listening to IVideoSource data must implement this interface, which defines the observer (subscriber) part of the observer design pattern (aka subscriber-publisher).
Definition: iobserver.h:35
virtual void init(const std::string filepath, const float framerate)=0
Initialise a file writer.