#include <video_decoder.h>
Classes | |
class | AudioTrack |
class | FixedRateVideoTrack |
class | RewindableAudioTrack |
class | SeekableAudioTrack |
class | StreamFileAudioTrack |
class | Track |
class | VideoTrack |
Public Member Functions | |
virtual bool | loadFile (const Common::Path &filename) |
virtual bool | loadStream (Common::SeekableReadStream *stream)=0 |
virtual void | close () |
bool | isVideoLoaded () const |
void | start () |
void | stop () |
void | setRate (const Common::Rational &rate) |
Common::Rational | getRate () const |
bool | isPlaying () const |
virtual bool | isRewindable () const |
virtual bool | rewind () |
virtual bool | isSeekable () const |
bool | seek (const Audio::Timestamp &time) |
virtual bool | seekToFrame (uint frame) |
void | pauseVideo (bool pause) |
bool | isPaused () const |
void | setEndTime (const Audio::Timestamp &endTime) |
void | setEndFrame (uint frame) |
Audio::Timestamp | getEndTime () const |
void | resetStartTime () |
bool | endOfVideo () const |
int | getCurFrame () const |
uint32 | getFrameCount () const |
uint32 | getTime () const |
virtual uint16 | getWidth () const |
virtual uint16 | getHeight () const |
Graphics::PixelFormat | getPixelFormat () const |
virtual Audio::Timestamp | getDuration () const |
const byte * | getPalette () |
bool | hasDirtyPalette () const |
void | delayMillis (uint msecs) |
uint32 | getTimeToNextFrame () const |
bool | needsUpdate () const |
virtual const Graphics::Surface * | decodeNextFrame () |
bool | setReverse (bool reverse) |
bool | setDitheringPalette (const byte *palette) |
bool | setOutputPixelFormat (const Graphics::PixelFormat &format) |
virtual void | setVideoCodecAccuracy (Image::CodecAccuracy accuracy) |
byte | getVolume () const |
void | setVolume (byte volume) |
int8 | getBalance () const |
void | setBalance (int8 balance) |
Audio::Mixer::SoundType | getSoundType () const |
void | setSoundType (Audio::Mixer::SoundType soundType) |
bool | addStreamTrack (Audio::SeekableAudioStream *stream) |
bool | addStreamFileTrack (const Common::Path &baseName) |
bool | setAudioTrack (int index) |
uint | getAudioTrackCount () const |
Protected Types | |
typedef Common::Array< Track * > | TrackList |
typedef TrackList::iterator | TrackListIterator |
Protected Member Functions | |
void | resetPauseStartTime () |
virtual void | readNextPacket () |
void | addTrack (Track *track, bool isExternal=false) |
virtual bool | useAudioSync () const |
Track * | getTrack (uint track) |
const Track * | getTrack (uint track) const |
bool | endOfVideoTracks () const |
VideoTrack * | findNextVideoTrack () |
TrackListIterator | getTrackListBegin () |
TrackListIterator | getTrackListEnd () |
void | eraseTrack (Track *track) |
virtual bool | seekIntern (const Audio::Timestamp &time) |
virtual bool | supportsAudioTrackSwitching () const |
virtual AudioTrack * | getAudioTrack (int index) |
void | stopAudio () |
void | setAudioRate (Common::Rational rate) |
void | startAudio () |
void | startAudioLimit (const Audio::Timestamp &limit) |
bool | hasFramesLeft () const |
bool | hasAudio () const |
Protected Attributes | |
Audio::Timestamp | _lastTimeChange |
int32 | _startTime |
VideoTrack * | _nextVideoTrack |
Image::CodecAccuracy | _videoCodecAccuracy |
Generic interface for video decoder classes.
|
protected |
Typedef helpers for accessing tracks
|
virtual |
Load a video from a file with the given name.
A default implementation using Common::File and loadStream is provided.
filename | the filename to load |
Reimplemented in Video::QuickTimeDecoder.
|
pure virtual |
Load a video from a generic read stream. The ownership of the stream object transfers to this VideoDecoder instance, which is hence also responsible for eventually deleting it.
Implementations of this function are required to call addTrack() for each track in the video upon success.
stream | the stream to load |
Implemented in Voyeur::RL2Decoder, Video::MveDecoder, Video::SmackerDecoder, Video::AVIDecoder, Video::PSXStreamDecoder, Video::QuickTimeDecoder, Video::MPEGPSDecoder, Access::AccessVIDMovieDecoder, Video::HNMDecoder, Video::ThreeDOMovieDecoder, Video::FlicDecoder, Grim::SmushDecoder, Video::PacoDecoder, Trecision::NightlongAmigaDecoder, Nancy::AVFDecoder, Video::DXADecoder, Sci::SEQDecoder, Kyra::VQADecoder, Trecision::NightlongSmackerDecoder, Toon::ToonstruckSmackerDecoder, Hypno::HypnoSmackerDecoder, Chewy::CfoDecoder, ZVision::RLFDecoder, and Pink::CelDecoder.
|
virtual |
Close the active video stream and free any associated resources.
All subclasses that need to close their own resources should still call the base class' close() function at the start of their function.
Reimplemented in Voyeur::RL2Decoder, Video::SmackerDecoder, Video::AVIDecoder, Video::PSXStreamDecoder, Video::QuickTimeDecoder, Grim::SmushDecoder, Video::MPEGPSDecoder, Access::AccessVIDMovieDecoder, Video::HNMDecoder, Video::ThreeDOMovieDecoder, and Video::PacoDecoder.
bool Video::VideoDecoder::isVideoLoaded | ( | ) | const |
Returns if a video stream is currently loaded or not.
void Video::VideoDecoder::start | ( | ) |
Begin playback of the video at normal speed.
void Video::VideoDecoder::stop | ( | ) |
Stop playback of the video.
void Video::VideoDecoder::setRate | ( | const Common::Rational & | rate | ) |
Set the rate (speed multiplier) of playback.
For instance, a rate of 0 would stop the video, while a rate of 1 would play the video normally. Passing 2 to this function would play the video at twice the normal speed.
|
inline |
Returns the rate (speed multiplier, not frame rate) at which the video is being played. Defaults to 1.0 when a video is started.
bool Video::VideoDecoder::isPlaying | ( | ) | const |
Returns if the video is currently playing or not.
This is not equivalent to the inverse of endOfVideo(). A video keeps its playing status even after reaching the end of the video. This will return true after calling start() and will continue to return true until stop() (or close()) is called.
|
virtual |
Returns if a video is rewindable or not. The default implementation polls each track for rewindability.
Reimplemented in Video::AVIDecoder, and Grim::SmushDecoder.
|
virtual |
Rewind a video to its beginning.
If the video is playing, it will continue to play. The default implementation will rewind each track.
Reimplemented in Video::SmackerDecoder, Video::AVIDecoder, and Grim::SmushDecoder.
|
virtual |
Returns if a video is seekable or not. The default implementation polls each track for seekability.
Reimplemented in Video::AVIDecoder, and Grim::SmushDecoder.
bool Video::VideoDecoder::seek | ( | const Audio::Timestamp & | time | ) |
Seek to a given time in the video.
If the video is playing, it will continue to play. This calls seekIntern(), which can be overriden. By default, seekIntern() will call Track::seek() on all tracks with the time passed to this function.
time | The time to seek to |
|
virtual |
Seek to a given frame.
This only works when one video track is present, and that track supports getFrameTime(). This calls seek() internally.
Reimplemented in Video::AVIDecoder.
void Video::VideoDecoder::pauseVideo | ( | bool | pause | ) |
Pause or resume the video. This should stop/resume any audio playback and other stuff. The initial pause time is kept so that any timing variables can be updated appropriately.
This is a convenience method which automatically keeps track on how often the video has been paused, ensuring that after pausing a video e.g. twice, it has to be unpaused twice before actually resuming.
pause | true to pause the video, false to resume it |
|
inline |
Return whether the video is currently paused or not.
void Video::VideoDecoder::setEndTime | ( | const Audio::Timestamp & | endTime | ) |
Set the time for this video to end at. At this time in the video, all audio will stop and endOfVideo() will return true.
While the setting is stored even if a video is not playing, endOfVideo() is only affected when the video is playing.
void Video::VideoDecoder::setEndFrame | ( | uint | frame | ) |
Set the end frame.
The passed frame will be the last frame to show.
Like seekToFrame(), this only works when one video track is present, and that track supports getFrameTime(). This calls setEndTime() internally.
|
inline |
Get the stop time of the video (if not set, zero)
void Video::VideoDecoder::resetStartTime | ( | ) |
Reset the playback start time to the current frame.
bool Video::VideoDecoder::endOfVideo | ( | ) | const |
Returns if the video has reached the end or not.
int Video::VideoDecoder::getCurFrame | ( | ) | const |
Returns the current frame number of the video.
uint32 Video::VideoDecoder::getFrameCount | ( | ) | const |
Returns the number of frames in the video.
uint32 Video::VideoDecoder::getTime | ( | ) | const |
Returns the time position (in ms) of the current video. This can be based on the "wall clock" time as determined by OSystem::getMillis() or the current time of any audio track running in the video, and takes pausing the video into account.
As such, it will differ from what multiplying getCurFrame() by some constant would yield, e.g. for a video with non-constant frame rate.
Due to the nature of the timing, this value may not always be completely accurate (since our mixer does not have precise timing).
|
virtual |
Returns the width of the video's frames.
By default, this finds the largest width between all of the loaded tracks. However, a subclass may override this if it does any kind of post-processing on it.
Reimplemented in Video::AVIDecoder, and Video::QuickTimeDecoder.
|
virtual |
Returns the height of the video's frames.
By default, this finds the largest height between all of the loaded tracks. However, a subclass may override this if it does any kind of post-processing on it.
Reimplemented in Video::AVIDecoder, and Video::QuickTimeDecoder.
Graphics::PixelFormat Video::VideoDecoder::getPixelFormat | ( | ) | const |
Get the pixel format of the currently loaded video.
|
virtual |
Get the duration of the video.
If the duration is unknown, this will return 0. If this is not overriden, it will take the length of the longest track.
Reimplemented in Video::QuickTimeDecoder.
const byte* Video::VideoDecoder::getPalette | ( | ) |
Get the palette for the video in RGB format (if 8bpp or less).
The palette's format is the same as PaletteManager's palette (interleaved RGB values).
|
inline |
Returns if the palette is dirty or not.
void Video::VideoDecoder::delayMillis | ( | uint | msecs | ) |
Delay/sleep for the specified amount of milliseconds, or until the next frame should be displayed.
uint32 Video::VideoDecoder::getTimeToNextFrame | ( | ) | const |
Return the time (in ms) until the next frame should be displayed.
bool Video::VideoDecoder::needsUpdate | ( | ) | const |
Check whether a new frame should be decoded, i.e. because enough time has elapsed since the last frame was decoded.
|
virtual |
Decode the next frame into a surface and return the latter.
A subclass may override this, but must still call this function. As an example, a subclass may do this to apply some global video scale to individual track's frame.
Note that this will call readNextPacket() internally first before calling the next video track's decodeNextFrame() function.
Reimplemented in Video::AVIDecoder, Video::QuickTimeDecoder, and Grim::SmushDecoder.
bool Video::VideoDecoder::setReverse | ( | bool | reverse | ) |
Set the video to decode frames in reverse.
By default, VideoDecoder will decode forward.
reverse | true for reverse, false for forward |
bool Video::VideoDecoder::setDitheringPalette | ( | const byte * | palette | ) |
Tell the video to dither to a palette.
By default, VideoDecoder will return surfaces in native, or in the case of YUV-based videos, the format set by setOutputPixelFormat(). For video formats or codecs that support it, this will start outputting its surfaces in 8bpp with this palette.
This should be called after loadStream(), but before a decodeNextFrame() call. This is enforced.
The palette will be copied, so you do not need to worry about the pointer going out-of-scope.
palette | The palette to use for dithering |
bool Video::VideoDecoder::setOutputPixelFormat | ( | const Graphics::PixelFormat & | format | ) |
Set the default high color format for videos that convert from YUV.
This should be called after loadStream(), but before a decodeNextFrame() call. This is enforced.
format | The preferred output pixel format |
|
virtual |
Set the accuracy of the video decoder
|
inline |
Get the current volume at which the audio in the video is being played
void Video::VideoDecoder::setVolume | ( | byte | volume | ) |
Set the volume at which the audio in the video should be played. This setting remains until close() is called (which may be called from loadStream()). The default volume is the maximum.
volume | The volume at which to play the audio in the video |
|
inline |
Get the current balance at which the audio in the video is being played
void Video::VideoDecoder::setBalance | ( | int8 | balance | ) |
Set the balance at which the audio in the video should be played. This setting remains until close() is called (which may be called from loadStream()). The default balance is 0.
balance | The balance at which to play the audio in the video |
Audio::Mixer::SoundType Video::VideoDecoder::getSoundType | ( | ) | const |
Get the mixer sound type audio is being played with.
void Video::VideoDecoder::setSoundType | ( | Audio::Mixer::SoundType | soundType | ) |
Set the mixer sound type used to play the audio tracks.
This must be set before calling loadStream().
bool Video::VideoDecoder::addStreamTrack | ( | Audio::SeekableAudioStream * | stream | ) |
Add an audio track from a stream.
bool Video::VideoDecoder::addStreamFileTrack | ( | const Common::Path & | baseName | ) |
Add an audio track from a stream file.
This calls SeekableAudioStream::openStreamFile() internally
bool Video::VideoDecoder::setAudioTrack | ( | int | index | ) |
Set the internal audio track.
Has no effect if the container does not support this.
index | The index of the track, whose meaning is dependent on the container |
uint Video::VideoDecoder::getAudioTrackCount | ( | ) | const |
Get the number of internal audio tracks.
|
protected |
Reset the pause start time (which should be called when seeking)
|
inlineprotectedvirtual |
Decode enough data for the next frame and enough audio to last that long.
This function is used by this class' decodeNextFrame() function. A subclass of a Track may decide to just have its decodeNextFrame() function read and decode the frame, but only if it is the only track in the video.
Reimplemented in Video::MveDecoder, Video::AVIDecoder, Video::SmackerDecoder, Video::PSXStreamDecoder, Video::MPEGPSDecoder, Access::AccessVIDMovieDecoder, Video::ThreeDOMovieDecoder, Video::PacoDecoder, Video::HNMDecoder, and Kyra::VQADecoder.
|
protected |
Define a track to be used by this class.
The pointer is then owned by this base class.
track | The track to add |
isExternal | Is this an external track not found by loadStream()? |
|
inlineprotectedvirtual |
Whether or not getTime() will sync with a playing audio track.
A subclass can override this to disable this feature.
Reimplemented in Video::PSXStreamDecoder, and Video::MPEGPSDecoder.
|
protected |
Get the given track based on its index.
|
protected |
Get the given track based on its index
|
protected |
Find out if all video tracks have finished
This is useful if one wants to figure out if they need to buffer all remaining audio in a file.
|
protected |
Set _nextVideoTrack to the video track with the lowest start time for the next frame.
|
inlineprotected |
Get the begin iterator of the tracks
|
inlineprotected |
Get the end iterator of the tracks
|
protected |
Removes a specified track
|
protectedvirtual |
The internal seek function that does the actual seeking.
Reimplemented in Video::AVIDecoder, and Grim::SmushDecoder.
|
inlineprotectedvirtual |
Does this video format support switching between audio tracks?
Returning true implies this format supports multiple audio tracks, can switch tracks, and defaults to playing the first found audio track.
Reimplemented in Video::AVIDecoder, Video::SmackerDecoder, and Video::ThreeDOMovieDecoder.
|
inlineprotectedvirtual |
Get the audio track for the given index.
This is used only if supportsAudioTrackSwitching() returns true.
index | The index of the track, whose meaning is dependent on the container |
Reimplemented in Video::AVIDecoder, Video::SmackerDecoder, and Video::ThreeDOMovieDecoder.