VTK
vtkFFMPEGVideoSource.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkFFMPEGVideoSource.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
30 #ifndef vtkFFMPEGVideoSource_h
31 #define vtkFFMPEGVideoSource_h
32 
33 #include "vtkIOFFMPEGModule.h" // For export macro
34 #include "vtkVideoSource.h"
35 #include "vtkMultiThreader.h" // for ivar
36 #include "vtkNew.h" // for ivar
37 #include <functional> // for audio callback
38 
39 class vtkFFMPEGVideoSourceInternal;
40 
42 class vtkMutexLock;
44 
45 // audio callback struct, outside the class so that we
46 // can forward ref it
48 {
53  int DataType;
54  bool Packed;
55  unsigned char** Data;
57  void *ClientData;
58 };
59 
60 class VTKIOFFMPEG_EXPORT vtkFFMPEGVideoSource : public vtkVideoSource
61 {
62 public:
63  static vtkFFMPEGVideoSource *New();
65 
69  void Record() override;
70 
74  void Play() override;
75 
79  void Stop() override;
80 
84  void Grab() override;
85 
87 
90  void SetFrameSize(int x, int y, int z) override;
91  void SetFrameSize(int dim[3]) override {
92  this->SetFrameSize(dim[0], dim[1], dim[2]); };
94 
98  void SetFrameRate(float rate) override;
99 
103  void SetOutputFormat(int format) override;
104 
109  void Initialize() override;
110 
115  void ReleaseSystemResources() override;
116 
118 
121  vtkSetStringMacro(FileName);
122  vtkGetStringMacro(FileName);
124 
130  void InternalGrab() override;
131 
132  // is the video at the end of file?
133  // Usefull for while loops
134  vtkGetMacro(EndOfFile,bool);
135 
136  // we do not use Invoke Observers here because this callback
137  // will happen in a different thread that could conflict
138  // with events from other threads. In this function you should
139  // not block the thread (for example waiting for audio to play)
140  // instead you should have enough buffering that you can consume
141  // the provided data and return. Typically even 1 second of
142  // buffer storage is enough to prevent blocking.
143  typedef std::function<void(vtkFFMPEGVideoSourceAudioCallbackData &data)> AudioCallbackType;
144  void SetAudioCallback(AudioCallbackType cb, void *clientData)
145  {
146  this->AudioCallback = cb;
147  this->AudioCallbackClientData = clientData;
148  }
149 
151 
156  vtkSetMacro(DecodingThreads, int);
157  vtkGetMacro(DecodingThreads, int);
159 
160 protected:
163 
164  AudioCallbackType AudioCallback;
166 
168 
169  static void *DrainAudioThread(
171  void *DrainAudio(vtkMultiThreader::ThreadInfo *data);
173 
174  static void *DrainThread(
176  void *Drain(vtkMultiThreader::ThreadInfo *data);
178 
179  bool EndOfFile;
180 
185  static void *FeedThread(
187  void *Feed(vtkMultiThreader::ThreadInfo *data);
189 
190  char *FileName;
191 
192  vtkFFMPEGVideoSourceInternal *Internal;
193 
194  void ReadFrame();
195 
196 private:
198  void operator=(const vtkFFMPEGVideoSource&) = delete;
199 };
200 
201 #endif
void SetAudioCallback(AudioCallbackType cb, void *clientData)
mutual exclusion locking class
AudioCallbackType AudioCallback
vtkFFMPEGVideoSourceInternal * Internal
This is the structure that is passed to the thread that is created from the SingleMethodExecute, MultipleMethodExecute or the SpawnThread method.
vtkNew< vtkConditionVariable > FeedCondition
void SetFrameSize(int dim[3]) override
Request a particular frame size (set the third value to 1).
Superclass of video input devices for VTK.
vtkNew< vtkMutexLock > FeedAudioMutex
Reader for ffmpeg supported formats.
std::function< void(vtkFFMPEGVideoSourceAudioCallbackData &data)> AudioCallbackType
vtkNew< vtkConditionVariable > FeedAudioCondition
vtkNew< vtkMutexLock > FeedMutex
mutual exclusion locking class
Definition: vtkMutexLock.h:80