My Project
Loading...
Searching...
No Matches
CVideo.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, CHAI3D
5 (www.chai3d.org)
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials provided
19 with the distribution.
20
21 * Neither the name of CHAI3D nor the names of its contributors may
22 be used to endorse or promote products derived from this software
23 without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37
38 \author <http://www.chai3d.org>
39 \author Sebastien Grange
40 \version 3.3.0
41*/
42//==============================================================================
43
44//------------------------------------------------------------------------------
45#ifndef CVideoH
46#define CVideoH
47//------------------------------------------------------------------------------
48#include "graphics/CImage.h"
50#include "system/CMutex.h"
51//------------------------------------------------------------------------------
52#include <memory>
53//------------------------------------------------------------------------------
54namespace chai3d {
55//------------------------------------------------------------------------------
56
57//==============================================================================
64//==============================================================================
65
66//------------------------------------------------------------------------------
67class cVideo;
68typedef std::shared_ptr<cVideo> cVideoPtr;
69//------------------------------------------------------------------------------
70
71//==============================================================================
83//==============================================================================
84class cVideo
85{
86 //--------------------------------------------------------------------------
87 // CONSTRUCTOR & DESTRUCTOR:
88 //--------------------------------------------------------------------------
89
90public:
91
93 cVideo();
94
96 virtual ~cVideo();
97
99 static cVideoPtr create() { return (std::make_shared<cVideo>()); }
100
101
102 //--------------------------------------------------------------------------
103 // PUBLIC METHODS - GENERAL COMMANDS:
104 //--------------------------------------------------------------------------
105
106public:
107
109 cVideoPtr copy();
110
112 void erase() { cleanup(); }
113
115 inline bool isInitialized() const { return (m_clip != NULL); }
116
118 inline unsigned int getWidth() const { return (m_width); }
119
121 inline unsigned int getHeight() const { return (m_height); }
122
124 inline unsigned int getFrameCount() const { return (m_frameCount); }
125
127 inline double getDuration() const { return (m_duration); }
128
130 inline double getFPS() const { return (m_fps); }
131
132
133 //-----------------------------------------------------------------------
134 // PUBLIC METHODS - MANIPULATING VIDEO:
135 //--------------------------------------------------------------------------
136
137public:
138
140 void play();
141
143 void setPlaybackSpeed(double a_speed);
144
146 double getPlaybackSpeed();
147
149 void pause();
150
152 void stop();
153
155 void setAutoReplay(bool a_replay = true);
156
158 bool isPaused();
159
161 bool seek(double a_time);
162
164 bool seekFrame(unsigned int a_index);
165
168
170 double getCurrentTimePosition();
171
173 bool getCurrentFramePointer(cImage &a_image);
174
176 bool getCurrentFrame(cImage &a_image);
177
179 bool getFramePointer(int a_index, cImage &a_image);
180
182 bool getFrame(int a_index, cImage &a_image);
183
184
185 //--------------------------------------------------------------------------
186 // PUBLIC METHODS - FILES:
187 //--------------------------------------------------------------------------
188
189public:
190
192 bool loadFromFile(const std::string& a_filename);
193
195 std::string getFilename() const { return (m_filename); }
196
198 std::string getName() const { return (m_name); }
199
200
201 //--------------------------------------------------------------------------
202 // PROTECTED METHODS:
203 //--------------------------------------------------------------------------
204
205protected:
206
208 void defaults();
209
211 void cleanup();
212
214 bool update();
215
217 void reset();
218
220 inline void storeFrame(void *frame);
221
222
223 //--------------------------------------------------------------------------
224 // PROTECTED MEMBERS:
225 //--------------------------------------------------------------------------
226
227protected:
228
230 std::string m_filename;
231
233 std::string m_name;
234
236 unsigned int m_width;
237
239 unsigned int m_height;
240
242 unsigned int m_frameCount;
243
245 unsigned int m_frameIndex;
246
249
252
255
258
260 double m_fps;
261
264
266 void *m_clip;
267
269 unsigned char *m_data;
270
272 static unsigned int m_clipCount;
273
276
278 static void *m_manager;
279
281 static void *m_audio;
282};
283
284//------------------------------------------------------------------------------
285} // namespace chai3d
286//------------------------------------------------------------------------------
287
288//------------------------------------------------------------------------------
289#endif
290//------------------------------------------------------------------------------
Implements a 2D image data structure.
Implements support for mutex objects.
Implements a high precision clock.
This class implements a 2D image data structure.
Definition CImage.h:84
This class implements a mutex.
Definition CMutex.h:86
This class implements a high precision clock.
Definition CPrecisionClock.h:86
This class implements support for video files of the OGG/Vorbis format.
Definition CVideo.h:85
double m_fps
Frame per seconds of the current video.
Definition CVideo.h:260
void * m_clip
Video clip object.
Definition CVideo.h:266
bool seekFrame(unsigned int a_index)
This method seeks a particular frame in the video.
Definition CVideo.cpp:435
bool getFrame(int a_index, cImage &a_image)
This method returns a copy of any frame.
Definition CVideo.cpp:675
void pause()
This method pauses the video.
Definition CVideo.cpp:315
static void * m_manager
Shared video manager.
Definition CVideo.h:278
std::string getFilename() const
This method returns the filename from which this video was last loaded or saved.
Definition CVideo.h:195
void reset()
This method reset the video to the first frame and make it ready to play again.
Definition CVideo.cpp:365
bool update()
This method updates the frame index and pointer to the current time.
Definition CVideo.cpp:466
static cMutex m_sharedLock
Shared members lock.
Definition CVideo.h:275
virtual ~cVideo()
Destructor of cVideo.
Definition CVideo.cpp:102
cVideoPtr copy()
This method creates a copy of this object.
Definition CVideo.cpp:524
void storeFrame(void *frame)
This method stores a frame locally (and flip horizontally).
Definition CVideo.cpp:710
cVideo()
Default constructor of cVideo.
Definition CVideo.cpp:71
double getDuration() const
This method returns the duration of this video in seconds.
Definition CVideo.h:127
void setAutoReplay(bool a_replay=true)
This method enables or disables the auto-replay mode.
Definition CVideo.cpp:349
static void * m_audio
Interface to audio control.
Definition CVideo.h:281
void setPlaybackSpeed(double a_speed)
This method control playback speed.
Definition CVideo.cpp:278
unsigned int m_frameIndex
Current frame index of the current video.
Definition CVideo.h:245
bool getCurrentFrame(cImage &a_image)
This method returns a copy of the current frame.
Definition CVideo.cpp:606
int getCurrentFrameIndex()
This method returns the index number of the current video frame.
Definition CVideo.h:167
void stop()
This method stops the video.
Definition CVideo.cpp:332
bool isInitialized() const
This method returns true if a video file has been loaded in memory, false otherwise.
Definition CVideo.h:115
void erase()
This method frees video from memory.
Definition CVideo.h:112
bool isPaused()
This method returns the video playing status.
Definition CVideo.cpp:396
void play()
This method starts playing the video.
Definition CVideo.cpp:261
void defaults()
This method initializes member variables.
Definition CVideo.cpp:138
static cVideoPtr create()
Shared cVideo allocator.
Definition CVideo.h:99
std::string m_filename
Video filename.
Definition CVideo.h:230
bool m_autoReplay
Auto replay flag.
Definition CVideo.h:257
bool m_firstFrame
First frame flag.
Definition CVideo.h:254
double m_duration
Duration in seconds of the current video.
Definition CVideo.h:248
unsigned int m_frameCount
Frame count of the current video.
Definition CVideo.h:242
unsigned int getHeight() const
This method returns the height of video image.
Definition CVideo.h:121
void cleanup()
This method deletes memory and removes any video that was previously loaded.
Definition CVideo.cpp:171
std::string getName() const
This method returns the video title.
Definition CVideo.h:198
bool getCurrentFramePointer(cImage &a_image)
This method returns a pointer to the current frame (does not allocate a copy).
Definition CVideo.cpp:576
unsigned int getFrameCount() const
This method returns the number of frames of this video stream.
Definition CVideo.h:124
double getPlaybackSpeed()
This method retrieves playback speed.
Definition CVideo.cpp:296
unsigned int m_width
Width in pixels of the current video.
Definition CVideo.h:236
double getCurrentTimePosition()
This method returns the time position of the current video frame.
Definition CVideo.cpp:558
std::string m_name
Video name.
Definition CVideo.h:233
double m_lastUpdate
Last time the frame index was updated.
Definition CVideo.h:251
bool seek(double a_time)
This method seeks a particular time in the video.
Definition CVideo.cpp:419
unsigned char * m_data
Video frame data.
Definition CVideo.h:269
bool getFramePointer(int a_index, cImage &a_image)
This method returns a pointer to any frame (does not allocate a copy).
Definition CVideo.cpp:646
bool loadFromFile(const std::string &a_filename)
This method loads the video file by passing image path and name as argument.
Definition CVideo.cpp:204
static unsigned int m_clipCount
Shared clip counter.
Definition CVideo.h:272
cPrecisionClock m_clock
Video manager time base.
Definition CVideo.h:263
unsigned int m_height
Height in pixels of the current video.
Definition CVideo.h:239
double getFPS() const
This method returns the rate of this video in frames per second.
Definition CVideo.h:130
unsigned int getWidth() const
This method returns the width of video image.
Definition CVideo.h:118
Definition CAudioBuffer.cpp:57
std::shared_ptr< cVideo > cVideoPtr
Definition CVideo.h:68