VTK  9.1.0
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=========================================================================*/
27#ifndef vtkFFMPEGVideoSource_h
28#define vtkFFMPEGVideoSource_h
29
30#include "vtkIOFFMPEGModule.h" // For export macro
31#include "vtkMultiThreader.h" // for ivar
32#include "vtkNew.h" // for ivar
33#include "vtkVideoSource.h"
34#include <condition_variable> // for std::condition_variable_any
35#include <functional> // for audio callback
36#include <mutex> // for std::mutex
37
38class vtkFFMPEGVideoSourceInternal;
40
41// audio callback struct, outside the class so that we
42// can forward ref it
44{
50 bool Packed;
51 unsigned char** Data;
54};
55
56// video callback struct, outside the class so that we
57// can forward ref it
59{
60 int Height;
61 int LineSize[8];
62 unsigned char* Data[8]; // nullptr for empty planes
65};
66
67class VTKIOFFMPEG_EXPORT vtkFFMPEGVideoSource : public vtkVideoSource
68{
69public:
72 void PrintSelf(ostream& os, vtkIndent indent) override;
73
77 void Record() override;
78
82 void Play() override;
83
87 void Stop() override;
88
92 void Grab() override;
93
95
98 void SetFrameSize(int x, int y, int z) override;
99 void SetFrameSize(int dim[3]) override { this->SetFrameSize(dim[0], dim[1], dim[2]); }
101
105 void SetFrameRate(float rate) override;
106
110 void SetOutputFormat(int format) override;
111
116 void Initialize() override;
117
122 void ReleaseSystemResources() override;
123
125
131
137 void InternalGrab() override;
138
139 // is the video at the end of file?
140 // Useful for while loops
141 vtkGetMacro(EndOfFile, bool);
142
143 // Is the video stream stereo 3d
144 vtkGetMacro(Stereo3D, bool);
145
146 // we do not use Invoke Observers here because this callback
147 // will happen in a different thread that could conflict
148 // with events from other threads. In this function you should
149 // not block the thread (for example waiting for audio to play)
150 // instead you should have enough buffering that you can consume
151 // the provided data and return. Typically even 1 second of
152 // buffer storage is enough to prevent blocking.
153 typedef std::function<void(vtkFFMPEGVideoSourceAudioCallbackData const& data)> AudioCallbackType;
154 void SetAudioCallback(AudioCallbackType cb, void* clientData)
155 {
156 this->AudioCallback = cb;
157 this->AudioCallbackClientData = clientData;
158 }
159
160 // we do not use Invoke Observers here because this callback
161 // will happen in a different thread that could conflict
162 // with events from other threads. In this function you should
163 // not block the thread (for example waiting for video to play)
164 // instead you should have enough buffering that you can consume
165 // the provided data and return.
166 typedef std::function<void(vtkFFMPEGVideoSourceVideoCallbackData const& data)> VideoCallbackType;
167 void SetVideoCallback(VideoCallbackType cb, void* clientData)
168 {
169 this->VideoCallback = cb;
170 this->VideoCallbackClientData = clientData;
171 }
172
174
179 vtkSetMacro(DecodingThreads, int);
180 vtkGetMacro(DecodingThreads, int);
182
183protected:
186
189
191
195
199
201
202 std::condition_variable_any FeedCondition;
203 std::mutex FeedMutex;
204 std::condition_variable_any FeedAudioCondition;
205 std::mutex FeedAudioMutex;
209
210 char* FileName;
211
212 vtkFFMPEGVideoSourceInternal* Internal;
213
214 void ReadFrame();
215
217
220
221private:
223 void operator=(const vtkFFMPEGVideoSource&) = delete;
224};
225
226#endif
Reader for ffmpeg supported formats.
static void * DrainAudioThread(vtkMultiThreader::ThreadInfo *data)
std::function< void(vtkFFMPEGVideoSourceVideoCallbackData const &data)> VideoCallbackType
vtkFFMPEGVideoSourceInternal * Internal
std::function< void(vtkFFMPEGVideoSourceAudioCallbackData const &data)> AudioCallbackType
void * Drain(vtkMultiThreader::ThreadInfo *data)
void SetVideoCallback(VideoCallbackType cb, void *clientData)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetFrameSize(int dim[3]) override
Request a particular frame size (set the third value to 1).
std::condition_variable_any FeedAudioCondition
void Record() override
Standard VCR functionality: Record incoming video.
~vtkFFMPEGVideoSource() override
void Stop() override
Standard VCR functionality: Stop recording or playing.
void * DrainAudio(vtkMultiThreader::ThreadInfo *data)
void Play() override
Standard VCR functionality: Play recorded video.
void InternalGrab() override
The internal function which actually does the grab.
static void * FeedThread(vtkMultiThreader::ThreadInfo *data)
static void * DrainThread(vtkMultiThreader::ThreadInfo *data)
void SetFrameSize(int x, int y, int z) override
Request a particular frame size (set the third value to 1).
VideoCallbackType VideoCallback
void SetFrameRate(float rate) override
Request a particular frame rate (default 30 frames per second).
static vtkFFMPEGVideoSource * New()
void SetAudioCallback(AudioCallbackType cb, void *clientData)
std::condition_variable_any FeedCondition
void Grab() override
Grab a single video frame.
AudioCallbackType AudioCallback
void ReleaseSystemResources() override
Free the driver (this is called automatically inside the destructor).
void SetOutputFormat(int format) override
Request a particular output format (default: VTK_RGB).
vtkSetFilePathMacro(FileName)
Specify file name of the video.
vtkGetFilePathMacro(FileName)
Specify file name of the video.
void Initialize() override
Initialize the driver (this is called automatically when the first grab is done).
void * Feed(vtkMultiThreader::ThreadInfo *data)
a simple class to control print indentation
Definition: vtkIndent.h:113
This is the structure that is passed to the thread that is created from the SingleMethodExecute,...
Superclass of video input devices for VTK.