chai3d::cVideo Class Reference

This class implements support for video files of the OGG/Vorbis format. More...

#include <CVideo.h>

Public Member Functions

 cVideo ()
 Default constructor of cVideo. More...
 
virtual ~cVideo ()
 Destructor of cVideo. More...
 
cVideoPtr copy ()
 This method creates a copy of this object. More...
 
void erase ()
 This method frees video from memory. More...
 
bool isInitialized () const
 This method returns true if a video file has been loaded in memory, false otherwise. More...
 
unsigned int getWidth () const
 This method returns the width of video image. More...
 
unsigned int getHeight () const
 This method returns the height of video image. More...
 
unsigned int getFrameCount () const
 This method returns the number of frames of this video stream. More...
 
double getDuration () const
 This method returns the duration of this video in seconds. More...
 
double getFPS () const
 This method returns the rate of this video in frames per second. More...
 
void play ()
 This method starts playing the video. More...
 
void setPlaybackSpeed (double a_speed)
 This method control playback speed. More...
 
double getPlaybackSpeed ()
 This method retrieves playback speed. More...
 
void pause ()
 This method pauses the video. More...
 
void stop ()
 This method stops the video. More...
 
void setAutoReplay (bool a_replay=true)
 This method enables or disables the auto-replay mode. More...
 
bool isPaused ()
 This method returns the video playing status. More...
 
bool seek (double a_time)
 This method seeks a particular time in the video. More...
 
bool seekFrame (unsigned int a_index)
 This method seeks a particular frame in the video. More...
 
int getCurrentFrameIndex ()
 This method returns the index number of the current video frame. More...
 
double getCurrentTimePosition ()
 This method returns the time position of the current video frame. More...
 
bool getCurrentFramePointer (cImage &a_image)
 This method returns a pointer to the current frame (does not allocate a copy). More...
 
bool getCurrentFrame (cImage &a_image)
 This method returns a copy of the current frame. More...
 
bool getFramePointer (int a_index, cImage &a_image)
 This method returns a pointer to any frame (does not allocate a copy). More...
 
bool getFrame (int a_index, cImage &a_image)
 This method returns a copy of any frame. More...
 
bool loadFromFile (const std::string &a_filename)
 This method loads the video file by passing image path and name as argument. More...
 
std::string getFilename () const
 This method returns the filename from which this video was last loaded or saved. More...
 
std::string getName () const
 This method returns the video title. More...
 

Static Public Member Functions

static cVideoPtr create ()
 Shared cVideo allocator. More...
 

Protected Member Functions

void defaults ()
 This method initializes member variables. More...
 
void cleanup ()
 This method deletes memory and removes any video that was previously loaded. More...
 
bool update ()
 This method updates the frame index and pointer to the current time. More...
 
void reset ()
 This method reset the video to the first frame and make it ready to play again. More...
 
void storeFrame (void *frame)
 This method stores a frame locally (and flip horizontally). More...
 

Protected Attributes

std::string m_filename
 Video filename. More...
 
std::string m_name
 Video name. More...
 
unsigned int m_width
 Width in pixels of the current video. More...
 
unsigned int m_height
 Height in pixels of the current video. More...
 
unsigned int m_frameCount
 Frame count of the current video. More...
 
unsigned int m_frameIndex
 Current frame index of the current video. More...
 
double m_duration
 Duration in seconds of the current video. More...
 
double m_lastUpdate
 Last time the frame index was updated. More...
 
bool m_firstFrame
 First frame flag. More...
 
bool m_autoReplay
 Auto replay flag. More...
 
double m_fps
 Frame per seconds of the current video. More...
 
cPrecisionClock m_clock
 Video manager time base. More...
 
void * m_clip
 Video clip object. More...
 
unsigned char * m_data
 Video frame data. More...
 

Static Protected Attributes

static unsigned int m_clipCount = 0
 Shared clip counter. More...
 
static cMutex m_sharedLock
 Shared members lock. More...
 
static void * m_manager = NULL
 Shared video manager. More...
 
static void * m_audio = NULL
 Interface to audio control. More...
 

Detailed Description

This class implements support for video files of the OGG/Vorbis format. Audio is also supported.

Constructor & Destructor Documentation

chai3d::cVideo::cVideo ( )

Default constructor of cVideo.

chai3d::cVideo::~cVideo ( )
virtual

Destructor of cVideo.

Member Function Documentation

static cVideoPtr chai3d::cVideo::create ( )
inlinestatic
cVideoPtr chai3d::cVideo::copy ( )

This method creates a copy of itself.

Returns
Pointer to new object.
void chai3d::cVideo::erase ( )
inline
bool chai3d::cVideo::isInitialized ( ) const
inline
unsigned int chai3d::cVideo::getWidth ( ) const
inline
unsigned int chai3d::cVideo::getHeight ( ) const
inline
unsigned int chai3d::cVideo::getFrameCount ( ) const
inline
double chai3d::cVideo::getDuration ( ) const
inline
double chai3d::cVideo::getFPS ( ) const
inline
void chai3d::cVideo::play ( )

This method start playing the video, and also starts audio decoding if available. At any given moment, the correct frame can be retrieved by calling cVideo::getCurrentFramePointer() or cVideo::getCurrentFrame().

void chai3d::cVideo::setPlaybackSpeed ( double  a_speed)

This method sets the playback speed as a ratio of normal speed.

Parameters
a_speedRatio of normal speed to use for playback.
double chai3d::cVideo::getPlaybackSpeed ( )

This method retrieves the playback speed as a ratio of normal speed.

Returns
The playback speed ratio (1.0 means normal speed). A return value of 0.0 indicates an error.
void chai3d::cVideo::pause ( )

This method pauses the video if it is playing. The current (frozen) frame can still be retrieved with cVideo::getCurrentFramePointer() or cVideo::getCurrentFrame(), but will not be updated until cVideo::play() is called again.

void chai3d::cVideo::stop ( )

This method stops the video. This resets the current frame and the time position to the beginning of the video. cVideo::getCurrentFramePointer() or cVideo::getCurrentFrame() return the first video frame.

void chai3d::cVideo::setAutoReplay ( bool  a_replay = true)

This method controls the auto-replay setting. When auto-replay is enabled, the video will automatically start playing again after it reaches the last frame. If auto-replay is disabled, cVideo::play() must be called again to restart the video.

Parameters
a_replaySet to true to make the movie auto-replay, false to disable auto-replay.
bool chai3d::cVideo::isPaused ( )

This method checks if the video is paused, as opposed to playing. The paused state is entered after calling cVideo::pause() or cVideo::stop(), or after loading a new video using cVideo::loadFromFile().

bool chai3d::cVideo::seek ( double  a_time)

This method seeks a given time position in the video stream. If the video is playing, keep playing from the new position.

Parameters
a_timeThe desired time position to seek in the video.
Returns
true if the requested time position is valid, false otherwise.
bool chai3d::cVideo::seekFrame ( unsigned int  a_index)

This method seeks a given frame in the video stream. If the video is playing, keep playing from the new frame position.

Parameters
a_indexThe desired frame index to seek in the video.
Returns
true if the requested frame index is valid, false otherwise.
int chai3d::cVideo::getCurrentFrameIndex ( )
inline
double chai3d::cVideo::getCurrentTimePosition ( )

This method retrieves the video time position.

Returns
The current video time position in seconds.
bool chai3d::cVideo::getCurrentFramePointer ( cImage a_image)

This method fills a cImage object to point to the image data of the current video frame. The actual data buffer is still owned by the video, and may be destroyed when the video moves on to the next frame (if it is playing). To get a permanent copy of a frame buffer, use getCurrentFrame() instead.

Parameters
a_imageImage object to set to frame data.
Returns
true if the frame is new, false otherwise.
bool chai3d::cVideo::getCurrentFrame ( cImage a_image)

This method fills a cImage object with a copy of the image data of the current video frame. The actual data buffer is copied from the video frame. To get a temporary copy of the current frame buffer, use getCurrentFramePointer() instead.

Parameters
a_imageImage object to set to frame data.
Returns
true if the frame is new, false otherwise.
bool chai3d::cVideo::getFramePointer ( int  a_index,
cImage a_image 
)

Fill a cImage object with a copy of the image data of a given video frame. The actual data buffer is copied from the video frame.

Parameters
a_indexIndex of the video frame to copy.
a_imageImage object to set to frame data.
Returns
true if the frame is new, false otherwise.
bool chai3d::cVideo::getFrame ( int  a_index,
cImage a_image 
)

This method fills a cImage object with a copy of the image data of a given video frame. The actual data buffer is copied from the video frame.

Parameters
a_indexIndex of the video frame to copy.
a_imageImage object to set to frame data.
Returns
true if the frame is new, false otherwise.
bool chai3d::cVideo::loadFromFile ( const std::string &  a_filename)

This method loads this video from the specified file. Returns true if all goes well. Note that regardless of whether it succeeds, this overwrites any video that had previously been loaded by this object.

Parameters
a_filenameVideo filename.
Returns
true if file loaded successfully, false otherwise.
std::string chai3d::cVideo::getFilename ( ) const
inline
std::string chai3d::cVideo::getName ( ) const
inline
void chai3d::cVideo::defaults ( )
protected

This method initializes internal variables.

void chai3d::cVideo::cleanup ( )
protected

This method frees memory that was used for video data, and re-initialize internal variables.

bool chai3d::cVideo::update ( )
protected

This method updates the current frame pointer to the current time. This method is used internally by cVideo::getCurrentFramePointer() and cVideo::getCurrentFrame() to keep track of the correct frame over time.

Returns
true if a new frame is available for display, false otherwise.
void chai3d::cVideo::reset ( )
protected

This internal method is used to reset the video to its first frame, launch the background decoder thread, and wait until enough frames have been buffered so that we should be safe to start playing the video.

void chai3d::cVideo::storeFrame ( void *  frame)
inlineprotected

This method flips a new frame the right way around before making it available to the outside world.

Member Data Documentation

std::string chai3d::cVideo::m_filename
protected
std::string chai3d::cVideo::m_name
protected
unsigned int chai3d::cVideo::m_width
protected
unsigned int chai3d::cVideo::m_height
protected
unsigned int chai3d::cVideo::m_frameCount
protected
unsigned int chai3d::cVideo::m_frameIndex
protected
double chai3d::cVideo::m_duration
protected
double chai3d::cVideo::m_lastUpdate
protected
bool chai3d::cVideo::m_firstFrame
protected
bool chai3d::cVideo::m_autoReplay
protected
double chai3d::cVideo::m_fps
protected
cPrecisionClock chai3d::cVideo::m_clock
protected
void* chai3d::cVideo::m_clip
protected
unsigned char* chai3d::cVideo::m_data
protected
unsigned int chai3d::cVideo::m_clipCount = 0
staticprotected
cMutex chai3d::cVideo::m_sharedLock
staticprotected
void * chai3d::cVideo::m_manager = NULL
staticprotected
void * chai3d::cVideo::m_audio = NULL
staticprotected

The documentation for this class was generated from the following files: