All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
VideoDisplay::AVDecoder Class Referenceabstract

This class provices the actual audio/video decoder for the video player. More...

#include <VideoDisplay/AVDecoder.hpp>

Inheritance diagram for VideoDisplay::AVDecoder:
Radiant::Thread Patterns::NotCopyable VideoDisplay::LibavDecoder

Classes

class  Options
 Video and audio parameters for AVDecoder when opening a new media file. More...
 
class  SeekRequest
 Seeking request that can be sent to the decoder. More...
 

Public Types

typedef Valuable::State< StateDecoderState
 State class used in the decoder.
 
typedef Radiant::FlagsT
< ErrorFlagsEnum > 
ErrorFlags
 
enum  ErrorFlagsEnum { ERROR_VIDEO_FRAME_BUFFER_UNDERRUN = 1 << 0 }
 
enum  PlayMode { PAUSE, PLAY }
 Decoder playing state. More...
 
enum  SeekDirection { SEEK_ANY_DIRECTION = 0, SEEK_ONLY_FORWARD, SEEK_ONLY_BACKWARD }
 Seeking direction constraint for SeekRequest. More...
 
enum  SeekFlags { SEEK_FLAGS_NONE = 0, SEEK_REAL_TIME }
 Seeking flags. More...
 
enum  SeekType { SEEK_NONE = 0, SEEK_BY_SECONDS, SEEK_RELATIVE, SEEK_BY_BYTES }
 Describes the unit used in SeekRequest. More...
 
enum  State {
  STATE_LOADING = 1 << 1, STATE_HEADER_READY = 1 << 2, STATE_READY = 1 << 3, STATE_ERROR = 1 << 4,
  STATE_FINISHED = 1 << 5
}
 AVDecoder loading state. More...
 
- Public Types inherited from Radiant::Thread
typedef void * id_t
 Thread id type. More...
 

Public Member Functions

virtual void close ()=0
 Marks the decoder for shutting down, doesn't block.
 
virtual double duration () const =0
 First this value is based on stream headers, but might be fine-tuned after the stream reaches to the end / maybe starts a new loop cycle. More...
 
bool finished () const
 Checks if decoder has done running. More...
 
virtual VideoFrame * getFrame (const Timestamp &ts, ErrorFlags &errors) const =0
 Gets a video frame from buffer that should be visible at the given timestamp. More...
 
virtual Timestamp getTimestampAt (const Radiant::TimeStamp &ts) const =0
 Based on the current playback and audio state, converts an absolute wall-clock timestamp to video timestamp. More...
 
bool hasError () const
 Checks if there has been an unrecoverable error. More...
 
bool isHeaderReady () const
 Has the decoder opened the media file correctly. More...
 
virtual bool isLooping () const =0
 
virtual Timestamp latestDecodedVideoTimestamp () const =0
 Decoder might have many frames in a buffer, this is the video timestamp of the latest decoded frame in that buffer. More...
 
virtual void panAudioTo (Nimble::Vector2f location) const =0
 Sets audio panning to specific location. More...
 
virtual PlayMode playMode () const =0
 
virtual bool realTimeSeeking () const =0
 Special mode for low-latency seeking without buffering. More...
 
virtual int releaseOldVideoFrames (const Timestamp &ts, bool *eof=nullptr)=0
 Deletes older video frames from the buffer, this needs to be called after the frame has been consumed, otherwise the buffer will fill quickly. More...
 
virtual void seek (const SeekRequest &req)=0
 Schedules a seek. More...
 
void seek (double seconds)
 Shorthand for making absolute seeking request. More...
 
void seekRelative (double pos)
 Shorthand for making a relative seek request. More...
 
virtual void setAudioGain (float gain)=0
 Controls the gain (volume) of the video sound-track. More...
 
virtual void setLooping (bool doLoop)=0
 
virtual void setPlayMode (PlayMode mode)=0
 
void setPreviousDecoder (std::shared_ptr< AVDecoder > decoder)
 This decoder might require that the previous version of the decoder should be first deleted. More...
 
virtual void setRealTimeSeeking (bool value)=0
 
DecoderStatestate ()
 Current decoder state. More...
 
const DecoderStatestate () const
 Current decoder state. More...
 
virtual Nimble::Size videoSize () const =0
 Decoded video resolution. More...
 
virtual Nimble::Matrix4f yuvMatrix () const =0
 YUV to RGB conversion matrix using the active video color profile. More...
 
virtual ~AVDecoder ()
 Deletes the decoder, blocks until all decoder threads have died.
 
- Public Member Functions inherited from Radiant::Thread
bool isRunning () const
 Check if the thread is running. More...
 
void run ()
 Starts the thread.
 
void setName (const QString &name)
 Set the thread name. More...
 
 Thread (const QString &name="Radiant::Thread")
 Construct a thread structure. More...
 
bool waitEnd (int timeoutms=0)
 Waits until thread is finished. More...
 
virtual ~Thread ()
 Destructor. More...
 

Static Public Member Functions

static std::shared_ptr< AVDecodercreate (const Options &options, const QString &backend="")
 Creates a new decoder and loads it with given options. More...
 
- Static Public Member Functions inherited from Radiant::Thread
static id_t myThreadId ()
 The id of the calling thread. More...
 

Protected Member Functions

 AVDecoder ()
 Constructs a new empty decoder, load() function will always be called after this.
 
virtual void load (const Options &options)=0
 Initializes the decoder, but doesn't start the decoder thread. More...
 
virtual void runDecoder ()=0
 Run the actual decoder, called from the decoder thread.
 

Detailed Description

This class provices the actual audio/video decoder for the video player.

To use this class, first make a new instance with create() and then start the decoder thread with run().

Member Enumeration Documentation

Decoder playing state.

Enumerator
PAUSE 

Media is playing.

PLAY 

Media is paused.

Seeking direction constraint for SeekRequest.

This eliminates twitching while seeking.

Enumerator
SEEK_ANY_DIRECTION 

No limitations on the seeking.

SEEK_ONLY_FORWARD 

Only seek forward in the stream.

SEEK_ONLY_BACKWARD 

Only seek backward in the stream.

Seeking flags.

Enumerator
SEEK_FLAGS_NONE 

No special seeking flags.

SEEK_REAL_TIME 

Low-latency seeking mode, no buffering, special audio handling Use this if you want to make continuous seek requests.

Describes the unit used in SeekRequest.

Not all of these might be supported by the demuxer or video / audio codecs.

Enumerator
SEEK_NONE 

No seeking requested.

SEEK_BY_SECONDS 

Timestamp is specified in seconds.

SEEK_RELATIVE 

Timestamp is between 0 and 1, 0 meaning the beginning of the video, 1 is the end of the video.

SEEK_BY_BYTES 

Raw byte seek in the data stream.

This is fast, but might cause rendering artifacts

AVDecoder loading state.

Enumerator
STATE_LOADING 

Decoder is opening the source.

STATE_HEADER_READY 

Decoder has opened the source and codecs, file meta info like video size is known.

STATE_READY 

First frame has been decoded successfully.

STATE_ERROR 

There was an error while opening/decoding the source.

STATE_FINISHED 

Playback was finished without errors.

Member Function Documentation

static std::shared_ptr<AVDecoder> VideoDisplay::AVDecoder::create ( const Options options,
const QString &  backend = "" 
)
static

Creates a new decoder and loads it with given options.

Parameters
optionsoptions given to load()
backenduse empty string for automatic backend
Returns
new decoder
virtual double VideoDisplay::AVDecoder::duration ( ) const
pure virtual

First this value is based on stream headers, but might be fine-tuned after the stream reaches to the end / maybe starts a new loop cycle.

Returns
media duration in seconds.

Implemented in VideoDisplay::LibavDecoder.

bool VideoDisplay::AVDecoder::finished ( ) const

Checks if decoder has done running.

Returns
true if the decoder in any of the final states (STATE_ERROR or STATE_FINISHED)
virtual VideoFrame* VideoDisplay::AVDecoder::getFrame ( const Timestamp &  ts,
ErrorFlags errors 
) const
pure virtual

Gets a video frame from buffer that should be visible at the given timestamp.

If this frame can't be found, then the closest frame will be used.

Parameters
tsvideo timestamp
[out]errorsErrorFlags
Returns
decoded video frame from a buffer, or null if the buffer is empty

Implemented in VideoDisplay::LibavDecoder.

virtual Timestamp VideoDisplay::AVDecoder::getTimestampAt ( const Radiant::TimeStamp ts) const
pure virtual

Based on the current playback and audio state, converts an absolute wall-clock timestamp to video timestamp.

This is most useful for video/audio synchronization

Parameters
tsreal (wall-clock) timestamp
Returns
video timestamp

Implemented in VideoDisplay::LibavDecoder.

bool VideoDisplay::AVDecoder::hasError ( ) const

Checks if there has been an unrecoverable error.

Returns
true if the decoder is in STATE_ERROR
bool VideoDisplay::AVDecoder::isHeaderReady ( ) const

Has the decoder opened the media file correctly.

When this is true, videoSize() will return valid size

Returns
true if the decoder is in STATE_HEADER_READY, STATE_READY or STATE_FINISHED
virtual bool VideoDisplay::AVDecoder::isLooping ( ) const
pure virtual
Returns
looping mode

Implemented in VideoDisplay::LibavDecoder.

virtual Timestamp VideoDisplay::AVDecoder::latestDecodedVideoTimestamp ( ) const
pure virtual

Decoder might have many frames in a buffer, this is the video timestamp of the latest decoded frame in that buffer.

Returns
video timestamp

Implemented in VideoDisplay::LibavDecoder.

virtual void VideoDisplay::AVDecoder::load ( const Options options)
protectedpure virtual

Initializes the decoder, but doesn't start the decoder thread.

Parameters
optionsopening options

Implemented in VideoDisplay::LibavDecoder.

virtual void VideoDisplay::AVDecoder::panAudioTo ( Nimble::Vector2f  location) const
pure virtual

Sets audio panning to specific location.

Parameters
location2D location of the audio

Implemented in VideoDisplay::LibavDecoder.

virtual PlayMode VideoDisplay::AVDecoder::playMode ( ) const
pure virtual
Returns
decoder current playing mode

Implemented in VideoDisplay::LibavDecoder.

virtual bool VideoDisplay::AVDecoder::realTimeSeeking ( ) const
pure virtual

Special mode for low-latency seeking without buffering.

This should be used only with certain UI elements, where the seeking target might change in real-time. When in real-time seeking mode, the video acts like it's paused

Implemented in VideoDisplay::LibavDecoder.

virtual int VideoDisplay::AVDecoder::releaseOldVideoFrames ( const Timestamp &  ts,
bool *  eof = nullptr 
)
pure virtual

Deletes older video frames from the buffer, this needs to be called after the frame has been consumed, otherwise the buffer will fill quickly.

Parameters
tstimestamp of the previous consumed frame
eofnull or pointer to bool that will be set to true if the stream is at EOF

Implemented in VideoDisplay::LibavDecoder.

virtual void VideoDisplay::AVDecoder::seek ( const SeekRequest req)
pure virtual

Schedules a seek.

If the previous request is still waiting, new request will replace the old one

Parameters
reqnew seek request

Implemented in VideoDisplay::LibavDecoder.

void VideoDisplay::AVDecoder::seek ( double  seconds)
inline

Shorthand for making absolute seeking request.

Parameters
secondstimestamp in seconds
void VideoDisplay::AVDecoder::seekRelative ( double  pos)
inline

Shorthand for making a relative seek request.

Parameters
posrelative position, value should be between 0 and 1
virtual void VideoDisplay::AVDecoder::setAudioGain ( float  gain)
pure virtual

Controls the gain (volume) of the video sound-track.

Parameters
gainnew audio gain, typical range is 0-1, although larger values can be used as well. Default value is 1.

Implemented in VideoDisplay::LibavDecoder.

virtual void VideoDisplay::AVDecoder::setLooping ( bool  doLoop)
pure virtual
Parameters
doLoopnew looping mode

Implemented in VideoDisplay::LibavDecoder.

virtual void VideoDisplay::AVDecoder::setPlayMode ( PlayMode  mode)
pure virtual
Parameters
modenew play mode

Implemented in VideoDisplay::LibavDecoder.

void VideoDisplay::AVDecoder::setPreviousDecoder ( std::shared_ptr< AVDecoder decoder)

This decoder might require that the previous version of the decoder should be first deleted.

Since it might block take a long time, this decoder is deleted in the child loop of the new decoder

Parameters
decoderold decoder that will deleted before this decoder is started, assuming that there are no more references to the old decoder outside this class.
virtual void VideoDisplay::AVDecoder::setRealTimeSeeking ( bool  value)
pure virtual
See Also
realTimeSeeking
Parameters
valuetrue if real-time seeking is asked

Implemented in VideoDisplay::LibavDecoder.

DecoderState& VideoDisplay::AVDecoder::state ( )

Current decoder state.

Returns
the current state of the decoder
const DecoderState& VideoDisplay::AVDecoder::state ( ) const

Current decoder state.

Returns
the current state of the decoder
virtual Nimble::Size VideoDisplay::AVDecoder::videoSize ( ) const
pure virtual

Decoded video resolution.

Will return invalid Nimble::Size if isHeaderReady returns false, we are not decoding a video stream, or if video decoding is disabled.

Returns
video resolution

Implemented in VideoDisplay::LibavDecoder.

virtual Nimble::Matrix4f VideoDisplay::AVDecoder::yuvMatrix ( ) const
pure virtual

YUV to RGB conversion matrix using the active video color profile.

This can be used directly in GLSL: vec4 rgb = m * vec4(y, u, v, 1.0);

Returns
YUV to RGB conversion matrix

Implemented in VideoDisplay::LibavDecoder.