All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
VideoDisplay::LibavDecoder Class Reference

Audio/Video decoder implementation that uses Libav as a backend. More...

#include <VideoDisplay/LibavDecoder.hpp>

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

Public Member Functions

virtual void close ()
 Marks the decoder for shutting down, doesn't block.
 
virtual double duration () const
 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...
 
virtual VideoFrame * getFrame (const Timestamp &ts, ErrorFlags &errors) const
 Gets a video frame from buffer that should be visible at the given timestamp. More...
 
virtual Timestamp getTimestampAt (const Radiant::TimeStamp &ts) const
 Based on the current playback and audio state, converts an absolute wall-clock timestamp to video timestamp. More...
 
virtual bool isLooping () const
 
virtual Timestamp latestDecodedVideoTimestamp () const
 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
 Sets audio panning to specific location. More...
 
virtual PlayMode playMode () const
 
virtual bool realTimeSeeking () const
 Special mode for low-latency seeking without buffering. More...
 
virtual int releaseOldVideoFrames (const Timestamp &ts, bool *eof=nullptr)
 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)
 Schedules a seek. More...
 
virtual void setAudioGain (float gain)
 Controls the gain (volume) of the video sound-track. More...
 
virtual void setLooping (bool doLoop)
 
virtual void setPlayMode (PlayMode mode)
 
virtual void setRealTimeSeeking (bool value)
 
virtual Nimble::Size videoSize () const
 Decoded video resolution. More...
 
virtual Nimble::Matrix4f yuvMatrix () const
 YUV to RGB conversion matrix using the active video color profile. More...
 
- Public Member Functions inherited from VideoDisplay::AVDecoder
bool finished () const
 Checks if decoder has done running. 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...
 
void seek (double seconds)
 Shorthand for making absolute seeking request. More...
 
void seekRelative (double pos)
 Shorthand for making a relative seek request. More...
 
void setPreviousDecoder (std::shared_ptr< AVDecoder > decoder)
 This decoder might require that the previous version of the decoder should be first deleted. More...
 
DecoderStatestate ()
 Current decoder state. More...
 
const DecoderStatestate () const
 Current decoder state. 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...
 

Protected Member Functions

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

Additional Inherited Members

- Public Types inherited from VideoDisplay::AVDecoder
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...
 
- Static Public Member Functions inherited from VideoDisplay::AVDecoder
static std::shared_ptr< AVDecodercreate (const Options &options, const QString &backend="")
 Creates a new decoder and loads it with given options. More...
 

Detailed Description

Audio/Video decoder implementation that uses Libav as a backend.

Member Function Documentation

virtual double VideoDisplay::LibavDecoder::duration ( ) const
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.

Implements VideoDisplay::AVDecoder.

virtual VideoFrame* VideoDisplay::LibavDecoder::getFrame ( const Timestamp &  ts,
ErrorFlags errors 
) const
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

Implements VideoDisplay::AVDecoder.

virtual Timestamp VideoDisplay::LibavDecoder::getTimestampAt ( const Radiant::TimeStamp ts) const
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

Implements VideoDisplay::AVDecoder.

virtual bool VideoDisplay::LibavDecoder::isLooping ( ) const
virtual
Returns
looping mode

Implements VideoDisplay::AVDecoder.

virtual Timestamp VideoDisplay::LibavDecoder::latestDecodedVideoTimestamp ( ) const
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

Implements VideoDisplay::AVDecoder.

virtual void VideoDisplay::LibavDecoder::load ( const Options options)
protectedvirtual

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

Parameters
optionsopening options

Implements VideoDisplay::AVDecoder.

virtual void VideoDisplay::LibavDecoder::panAudioTo ( Nimble::Vector2f  location) const
virtual

Sets audio panning to specific location.

Parameters
location2D location of the audio

Implements VideoDisplay::AVDecoder.

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

Implements VideoDisplay::AVDecoder.

virtual bool VideoDisplay::LibavDecoder::realTimeSeeking ( ) const
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

Implements VideoDisplay::AVDecoder.

virtual int VideoDisplay::LibavDecoder::releaseOldVideoFrames ( const Timestamp &  ts,
bool *  eof = nullptr 
)
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

Implements VideoDisplay::AVDecoder.

virtual void VideoDisplay::LibavDecoder::seek ( const SeekRequest req)
virtual

Schedules a seek.

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

Parameters
reqnew seek request

Implements VideoDisplay::AVDecoder.

virtual void VideoDisplay::LibavDecoder::setAudioGain ( float  gain)
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.

Implements VideoDisplay::AVDecoder.

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

Implements VideoDisplay::AVDecoder.

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

Implements VideoDisplay::AVDecoder.

virtual void VideoDisplay::LibavDecoder::setRealTimeSeeking ( bool  value)
virtual
See Also
realTimeSeeking
Parameters
valuetrue if real-time seeking is asked

Implements VideoDisplay::AVDecoder.

virtual Nimble::Size VideoDisplay::LibavDecoder::videoSize ( ) const
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

Implements VideoDisplay::AVDecoder.

virtual Nimble::Matrix4f VideoDisplay::LibavDecoder::yuvMatrix ( ) const
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

Implements VideoDisplay::AVDecoder.