CHAI3D  3.0.0
CVideo.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2015, 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.0.0 $Rev: 1765 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CVideoH
46 #define CVideoH
47 //------------------------------------------------------------------------------
48 #include "graphics/CImage.h"
49 #include "timers/CPrecisionClock.h"
50 #include "system/CMutex.h"
51 //------------------------------------------------------------------------------
52 #include <memory>
53 //------------------------------------------------------------------------------
54 namespace chai3d {
55 //------------------------------------------------------------------------------
56 
57 //==============================================================================
64 //==============================================================================
65 
66 //------------------------------------------------------------------------------
67 class cVideo;
68 typedef std::shared_ptr<cVideo> cVideoPtr;
69 //------------------------------------------------------------------------------
70 
71 //==============================================================================
83 //==============================================================================
84 class cVideo
85 {
86  //--------------------------------------------------------------------------
87  // CONSTRUCTOR & DESTRUCTOR:
88  //--------------------------------------------------------------------------
89 
90 public:
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 
106 public:
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 
137 public:
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 
167  int getCurrentFrameIndex() { return (m_frameIndex); }
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 
189 public:
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 
205 protected:
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 
227 protected:
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 
248  double m_duration;
249 
251  double m_lastUpdate;
252 
255 
257  double m_fps;
258 
261 
263  void *m_clip;
264 
266  unsigned char *m_data;
267 
269  static unsigned int m_clipCount;
270 
273 
275  static void *m_manager;
276 
278  static void *m_audio;
279 };
280 
281 //------------------------------------------------------------------------------
282 } // namespace chai3d
283 //------------------------------------------------------------------------------
284 
285 //------------------------------------------------------------------------------
286 #endif
287 //------------------------------------------------------------------------------
This class implements support for video files of the OGG/Vorbis format.
Definition: CVideo.h:84
static cMutex m_sharedLock
Shared members lock.
Definition: CVideo.h:272
double m_lastUpdate
Last time the frame index was updated.
Definition: CVideo.h:251
Implements a high precision clock.
bool loadFromFile(const std::string &a_filename)
This method loads the video file by passing image path and name as argument.
Definition: CVideo.cpp:199
void * m_clip
Video clip object.
Definition: CVideo.h:263
unsigned char * m_data
Video frame data.
Definition: CVideo.h:266
bool isInitialized() const
This method returns true if a video file has been loaded in memory, false otherwise.
Definition: CVideo.h:115
void storeFrame(void *frame)
This method stores a frame locally (and flip horizontally).
Definition: CVideo.cpp:699
unsigned int getHeight() const
This method returns the height of video image.
Definition: CVideo.h:121
bool m_firstFrame
First frame flag.
Definition: CVideo.h:254
unsigned int getWidth() const
This method returns the width of video image.
Definition: CVideo.h:118
static unsigned int m_clipCount
Shared clip counter.
Definition: CVideo.h:269
static void * m_audio
Interface to audio control.
Definition: CVideo.h:278
This class implements a high precision clock.
Definition: CPrecisionClock.h:85
unsigned int m_height
Height in pixels of the current video.
Definition: CVideo.h:239
virtual ~cVideo()
Destructor of cVideo.
Definition: CVideo.cpp:102
bool seekFrame(unsigned int a_index)
This method seeks a particular frame in the video.
Definition: CVideo.cpp:430
bool isPaused()
This method returns the video playing status.
Definition: CVideo.cpp:391
std::string m_filename
Video filename.
Definition: CVideo.h:230
double getCurrentTimePosition()
This method returns the time position of the current video frame.
Definition: CVideo.cpp:547
unsigned int m_frameIndex
Current frame index of the current video.
Definition: CVideo.h:245
void setPlaybackSpeed(double a_speed)
This method control playback speed.
Definition: CVideo.cpp:273
void setAutoReplay(bool a_replay=true)
This method enables or disables the auto-replay mode.
Definition: CVideo.cpp:344
static void * m_manager
Shared video manager.
Definition: CVideo.h:275
int getCurrentFrameIndex()
This method returns the index number of the current video frame.
Definition: CVideo.h:167
This class implements a mutex.
Definition: CMutex.h:85
bool seek(double a_time)
This method seeks a particular time in the video.
Definition: CVideo.cpp:414
std::shared_ptr< cVideo > cVideoPtr
Definition: CVideo.h:67
void erase()
This method frees video from memory.
Definition: CVideo.h:112
std::string m_name
Video name.
Definition: CVideo.h:233
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:360
unsigned int m_width
Width in pixels of the current video.
Definition: CVideo.h:236
cVideoPtr copy()
This method creates a copy of this object.
Definition: CVideo.cpp:513
double m_duration
Duration in seconds of the current video.
Definition: CVideo.h:248
bool getFramePointer(int a_index, cImage &a_image)
This method returns a pointer to any frame (does not allocate a copy).
Definition: CVideo.cpp:635
bool getCurrentFramePointer(cImage &a_image)
This method returns a pointer to the current frame (does not allocate a copy).
Definition: CVideo.cpp:565
std::string getName() const
This method returns the video title.
Definition: CVideo.h:198
bool getFrame(int a_index, cImage &a_image)
This method returns a copy of any frame.
Definition: CVideo.cpp:664
void play()
This method starts playing the video.
Definition: CVideo.cpp:256
double getPlaybackSpeed()
This method retrieves playback speed.
Definition: CVideo.cpp:291
bool update()
This method updates the frame index and pointer to the current time.
Definition: CVideo.cpp:461
cVideo()
Default constructor of cVideo.
Definition: CVideo.cpp:71
void defaults()
This method initializes member variables.
Definition: CVideo.cpp:136
static cVideoPtr create()
Shared cVideo allocator.
Definition: CVideo.h:99
bool getCurrentFrame(cImage &a_image)
This method returns a copy of the current frame.
Definition: CVideo.cpp:595
Definition: CAudioBuffer.cpp:56
double getFPS() const
This method returns the rate of this video in frames per second.
Definition: CVideo.h:130
cPrecisionClock m_clock
Video manager time base.
Definition: CVideo.h:260
double m_fps
Frame per seconds of the current video.
Definition: CVideo.h:257
void cleanup()
This method deletes memory and removes any video that was previously loaded.
Definition: CVideo.cpp:166
void pause()
This method pauses the video.
Definition: CVideo.cpp:310
Implements support for mutex objects.
Implements a 2D image data structure.
void stop()
This method stops the video.
Definition: CVideo.cpp:327
This class implements a 2D image data structure.
Definition: CImage.h:83
unsigned int m_frameCount
Frame count of the current video.
Definition: CVideo.h:242
double getDuration() const
This method returns the duration of this video in seconds.
Definition: CVideo.h:127
unsigned int getFrameCount() const
This method returns the number of frames of this video stream.
Definition: CVideo.h:124

CHAI3D 3.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2015 - CHAI3D
All Rights Reserved.