ScummVM API documentation
Video::VideoDecoder Class Referenceabstract

#include <video_decoder.h>

Inheritance diagram for Video::VideoDecoder:
Access::AccessVIDMovieDecoder Grim::SmushDecoder Kyra::VQADecoder Nancy::AVFDecoder Sci::SEQDecoder Video::AVIDecoder Video::DXADecoder Video::FlicDecoder Video::HNMDecoder Video::MPEGPSDecoder Video::MveDecoder Video::PacoDecoder Video::PSXStreamDecoder Video::QuickTimeDecoder Video::SmackerDecoder Video::ThreeDOMovieDecoder Voyeur::RL2Decoder ZVision::RLFDecoder

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
 
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
 
uint32 getTimeToNextFrame () const
 
bool needsUpdate () const
 
virtual const Graphics::SurfacedecodeNextFrame ()
 
bool setReverse (bool reverse)
 
bool setDitheringPalette (const byte *palette)
 
bool setOutputPixelFormat (const Graphics::PixelFormat &format)
 
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
 
TrackgetTrack (uint track)
 
const TrackgetTrack (uint track) const
 
bool endOfVideoTracks () const
 
VideoTrackfindNextVideoTrack ()
 
TrackListIterator getTrackListBegin ()
 
TrackListIterator getTrackListEnd ()
 
void eraseTrack (Track *track)
 
virtual bool seekIntern (const Audio::Timestamp &time)
 
virtual bool supportsAudioTrackSwitching () const
 
virtual AudioTrackgetAudioTrack (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
 

Detailed Description

Generic interface for video decoder classes.

Member Typedef Documentation

◆ TrackList

Typedef helpers for accessing tracks

Member Function Documentation

◆ loadFile()

virtual bool Video::VideoDecoder::loadFile ( const Common::Path filename)
virtual

Load a video from a file with the given name.

A default implementation using Common::File and loadStream is provided.

Parameters
filenamethe filename to load
Returns
whether loading the file succeeded

Reimplemented in Video::QuickTimeDecoder.

◆ loadStream()

virtual bool Video::VideoDecoder::loadStream ( Common::SeekableReadStream stream)
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.

Parameters
streamthe stream to load
Returns
whether loading the stream succeeded

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.

◆ close()

virtual void Video::VideoDecoder::close ( )
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.

◆ isVideoLoaded()

bool Video::VideoDecoder::isVideoLoaded ( ) const

Returns if a video stream is currently loaded or not.

◆ start()

void Video::VideoDecoder::start ( )

Begin playback of the video at normal speed.

Note
This has no effect if the video is already playing.

◆ stop()

void Video::VideoDecoder::stop ( )

Stop playback of the video.

Note
This has no effect if the video is not playing.

◆ setRate()

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.

◆ getRate()

Common::Rational Video::VideoDecoder::getRate ( ) const
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.

◆ isPlaying()

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.

◆ isRewindable()

virtual bool Video::VideoDecoder::isRewindable ( ) const
virtual

Returns if a video is rewindable or not. The default implementation polls each track for rewindability.

Reimplemented in Video::AVIDecoder, and Grim::SmushDecoder.

◆ rewind()

virtual bool Video::VideoDecoder::rewind ( )
virtual

Rewind a video to its beginning.

If the video is playing, it will continue to play. The default implementation will rewind each track.

Returns
true on success, false otherwise

Reimplemented in Video::SmackerDecoder, Video::AVIDecoder, and Grim::SmushDecoder.

◆ isSeekable()

virtual bool Video::VideoDecoder::isSeekable ( ) const
virtual

Returns if a video is seekable or not. The default implementation polls each track for seekability.

Reimplemented in Video::AVIDecoder, and Grim::SmushDecoder.

◆ seek()

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.

Parameters
timeThe time to seek to
Returns
true on success, false otherwise

◆ seekToFrame()

virtual bool Video::VideoDecoder::seekToFrame ( uint  frame)
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.

◆ pauseVideo()

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.

Parameters
pausetrue to pause the video, false to resume it

◆ isPaused()

bool Video::VideoDecoder::isPaused ( ) const
inline

Return whether the video is currently paused or not.

◆ setEndTime()

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.

◆ setEndFrame()

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.

◆ getEndTime()

Audio::Timestamp Video::VideoDecoder::getEndTime ( ) const
inline

Get the stop time of the video (if not set, zero)

◆ endOfVideo()

bool Video::VideoDecoder::endOfVideo ( ) const

Returns if the video has reached the end or not.

Returns
true if the video has finished playing or if none is loaded, false otherwise

◆ getCurFrame()

int Video::VideoDecoder::getCurFrame ( ) const

Returns the current frame number of the video.

Returns
the last frame decoded by the video

◆ getFrameCount()

uint32 Video::VideoDecoder::getFrameCount ( ) const

Returns the number of frames in the video.

Returns
the number of frames in the video

◆ getTime()

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).

◆ getWidth()

virtual uint16 Video::VideoDecoder::getWidth ( ) const
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.

Returns
the width of the video's frames

Reimplemented in Video::AVIDecoder, and Video::QuickTimeDecoder.

◆ getHeight()

virtual uint16 Video::VideoDecoder::getHeight ( ) const
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.

Returns
the height of the video's frames

Reimplemented in Video::AVIDecoder, and Video::QuickTimeDecoder.

◆ getPixelFormat()

Graphics::PixelFormat Video::VideoDecoder::getPixelFormat ( ) const

Get the pixel format of the currently loaded video.

◆ getDuration()

virtual Audio::Timestamp Video::VideoDecoder::getDuration ( ) const
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.

◆ getPalette()

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).

◆ hasDirtyPalette()

bool Video::VideoDecoder::hasDirtyPalette ( ) const
inline

Returns if the palette is dirty or not.

◆ getTimeToNextFrame()

uint32 Video::VideoDecoder::getTimeToNextFrame ( ) const

Return the time (in ms) until the next frame should be displayed.

◆ needsUpdate()

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.

Returns
whether a new frame should be decoded or not

◆ decodeNextFrame()

virtual const Graphics::Surface* Video::VideoDecoder::decodeNextFrame ( )
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.

Returns
a surface containing the decoded frame, or 0
Note
Ownership of the returned surface stays with the VideoDecoder, hence the caller must not free it.
this may return 0, in which case the last frame should be kept on screen

Reimplemented in Video::AVIDecoder, Video::QuickTimeDecoder, and Grim::SmushDecoder.

◆ setReverse()

bool Video::VideoDecoder::setReverse ( bool  reverse)

Set the video to decode frames in reverse.

By default, VideoDecoder will decode forward.

Note
This is used by setRate()
This will not work if an audio track is present
Parameters
reversetrue for reverse, false for forward
Returns
true on success, false otherwise

◆ setDitheringPalette()

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.

Parameters
paletteThe palette to use for dithering
Returns
true on success, false otherwise

◆ setOutputPixelFormat()

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.

Parameters
formatThe preferred output pixel format
Returns
true on success, false otherwise

◆ getVolume()

byte Video::VideoDecoder::getVolume ( ) const
inline

Get the current volume at which the audio in the video is being played

Returns
the current volume at which the audio in the video is being played

◆ setVolume()

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.

Parameters
volumeThe volume at which to play the audio in the video

◆ getBalance()

int8 Video::VideoDecoder::getBalance ( ) const
inline

Get the current balance at which the audio in the video is being played

Returns
the current balance at which the audio in the video is being played

◆ setBalance()

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.

Parameters
balanceThe balance at which to play the audio in the video

◆ getSoundType()

Audio::Mixer::SoundType Video::VideoDecoder::getSoundType ( ) const

Get the mixer sound type audio is being played with.

◆ setSoundType()

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().

◆ addStreamTrack()

bool Video::VideoDecoder::addStreamTrack ( Audio::SeekableAudioStream stream)

Add an audio track from a stream.

◆ addStreamFileTrack()

bool Video::VideoDecoder::addStreamFileTrack ( const Common::Path baseName)

Add an audio track from a stream file.

This calls SeekableAudioStream::openStreamFile() internally

◆ setAudioTrack()

bool Video::VideoDecoder::setAudioTrack ( int  index)

Set the internal audio track.

Has no effect if the container does not support this.

See also
supportsAudioTrackSwitching()
Parameters
indexThe index of the track, whose meaning is dependent on the container

◆ getAudioTrackCount()

uint Video::VideoDecoder::getAudioTrackCount ( ) const

Get the number of internal audio tracks.

◆ resetPauseStartTime()

void Video::VideoDecoder::resetPauseStartTime ( )
protected

Reset the pause start time (which should be called when seeking)

◆ readNextPacket()

virtual void Video::VideoDecoder::readNextPacket ( )
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.

◆ addTrack()

void Video::VideoDecoder::addTrack ( Track track,
bool  isExternal = false 
)
protected

Define a track to be used by this class.

The pointer is then owned by this base class.

Parameters
trackThe track to add
isExternalIs this an external track not found by loadStream()?

◆ useAudioSync()

virtual bool Video::VideoDecoder::useAudioSync ( ) const
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.

◆ getTrack() [1/2]

Track* Video::VideoDecoder::getTrack ( uint  track)
protected

Get the given track based on its index.

Returns
A valid track pointer on success, 0 otherwise

◆ getTrack() [2/2]

const Track* Video::VideoDecoder::getTrack ( uint  track) const
protected

Get the given track based on its index

Returns
A valid track pointer on success, 0 otherwise

◆ endOfVideoTracks()

bool Video::VideoDecoder::endOfVideoTracks ( ) const
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.

◆ findNextVideoTrack()

VideoTrack* Video::VideoDecoder::findNextVideoTrack ( )
protected

Set _nextVideoTrack to the video track with the lowest start time for the next frame.

Returns
_nextVideoTrack

◆ getTrackListBegin()

TrackListIterator Video::VideoDecoder::getTrackListBegin ( )
inlineprotected

Get the begin iterator of the tracks

◆ getTrackListEnd()

TrackListIterator Video::VideoDecoder::getTrackListEnd ( )
inlineprotected

Get the end iterator of the tracks

◆ eraseTrack()

void Video::VideoDecoder::eraseTrack ( Track track)
protected

Removes a specified track

◆ seekIntern()

virtual bool Video::VideoDecoder::seekIntern ( const Audio::Timestamp time)
protectedvirtual

The internal seek function that does the actual seeking.

See also
seek()
Returns
true on success, false otherwise

Reimplemented in Video::AVIDecoder, and Grim::SmushDecoder.

◆ supportsAudioTrackSwitching()

virtual bool Video::VideoDecoder::supportsAudioTrackSwitching ( ) const
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.

◆ getAudioTrack()

virtual AudioTrack* Video::VideoDecoder::getAudioTrack ( int  index)
inlineprotectedvirtual

Get the audio track for the given index.

This is used only if supportsAudioTrackSwitching() returns true.

Parameters
indexThe index of the track, whose meaning is dependent on the container
Returns
The audio track for the index, or 0 if not found

Reimplemented in Video::AVIDecoder, Video::SmackerDecoder, and Video::ThreeDOMovieDecoder.


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