NAP
Public Types | Public Member Functions | List of all members
AVState Class Referencefinal

#include <video.h>

Public Types

using OnClearFrameQueueFunction = std::function< void()>
 

Public Member Functions

 AVState (Video &video)
 
 ~AVState ()
 
void init (int stream, AVCodec *codec, AVCodecContext *codecContext)
 
void close ()
 
bool isValid () const
 
int getStream () const
 
void startDecodeThread (const OnClearFrameQueueFunction &onClearFrameQueueFunction=OnClearFrameQueueFunction())
 
void exitDecodeThread (bool join)
 
bool isFinished () const
 
void clearFrameQueue ()
 
void clearPacketQueue ()
 
bool matchesStream (const AVPacket &packet) const
 
bool addSeekStartPacket (const bool &exitIOThreadSignalled)
 
bool addSeekEndPacket (const bool &exitIOThreadSignalled, double seekTargetSecs)
 
bool addEndOfFilePacket (const bool &exitIOThreadSignalled)
 
bool addIOFinishedPacket (const bool &exitIOThreadSignalled)
 
bool addPacket (AVPacket &packet, const bool &exitIOThreadSignalled)
 
bool waitForFrameQueueEmpty (bool &exitIOThreadSignalled)
 
void cancelWaitForFrameQueueEmpty ()
 
void resetWaitForFrameQueueEmpty ()
 
bool waitForEndOfFileProcessed ()
 
void cancelWaitForEndOfFileProcessed ()
 
void resetEndOfFileProcessed ()
 
void waitSeekStartPacketProcessed ()
 
int waitForReceiveFrame ()
 
void drainSeekFrameQueue ()
 
Frame popFrame ()
 
Frame tryPopFrame (double pts)
 
Frame peekFrame ()
 
Frame popSeekFrame ()
 
void notifyStartIOThread ()
 
void notifyExitIOThread ()
 
AVCodec & getCodec ()
 
AVCodecContext & getCodecContext ()
 

Description

Full state for either audio or video. Responsible for pulling packets from the packet queue and decoding them into frames.

Member Typedef Documentation

◆ OnClearFrameQueueFunction

using OnClearFrameQueueFunction = std::function<void()>

Constructor & Destructor Documentation

◆ AVState()

AVState ( Video video)

Constructor

Parameters
videovideo to play

◆ ~AVState()

~AVState ( )

Destructor

Member Function Documentation

◆ addEndOfFilePacket()

bool addEndOfFilePacket ( const bool &  exitIOThreadSignalled)

Adds the 'end of file' packet to the packet queue. The end of file packet is a special packet with a nullptr for data.

◆ addIOFinishedPacket()

bool addIOFinishedPacket ( const bool &  exitIOThreadSignalled)

Adds the 'I/O finished' packet to the packet queue. This functions as a command to the decode thread.

◆ addPacket()

bool addPacket ( AVPacket &  packet,
const bool &  exitIOThreadSignalled 
)

Adds a packet to the packet queue.

Parameters
packetThe packet to add.
exitIOThreadSignalledWhen I/O thread is in exit mode, this must be true.
Returns
if packet was added

◆ addSeekEndPacket()

bool addSeekEndPacket ( const bool &  exitIOThreadSignalled,
double  seekTargetSecs 
)

Adds the 'seek end' packet to the packet queue. This functions as a command to the decode thread.

◆ addSeekStartPacket()

bool addSeekStartPacket ( const bool &  exitIOThreadSignalled)

Adds the 'seek start' packet to the packet queue. This functions as a command to the decode thread.

◆ cancelWaitForEndOfFileProcessed()

void cancelWaitForEndOfFileProcessed ( )

Cancel any outstanding waits for end of file to be processed

◆ cancelWaitForFrameQueueEmpty()

void cancelWaitForFrameQueueEmpty ( )

Cancel any outstanding waits for the frame queue to be empty

◆ clearFrameQueue()

void clearFrameQueue ( )

Clears frame queue.

◆ clearPacketQueue()

void clearPacketQueue ( )

Clears packet queue.

◆ close()

void close ( )

Destroys codec.

◆ drainSeekFrameQueue()

void drainSeekFrameQueue ( )

Consumes all frames in the frame queue until the decode thread needs new packets.

◆ exitDecodeThread()

void exitDecodeThread ( bool  join)

Stops the decode thread and blocks waiting for it to exit if join is true.

Parameters
joinIf true, the function blocks until the thread is exited, otherwise false.

◆ getCodec()

AVCodec& getCodec ( )
Returns
audio or video codec used to decode packets into frames.

◆ getCodecContext()

AVCodecContext& getCodecContext ( )
Returns
audio or video codec context used to decode packets into frames.

◆ getStream()

int getStream ( ) const
Returns
Index of this stream.

◆ init()

void init ( int  stream,
AVCodec *  codec,
AVCodecContext *  codecContext 
)

Initializes stream and codec.

Parameters
streamVideo or audio stream index.
codeccodec to use
codecContextcontext associated with the codec

◆ isFinished()

bool isFinished ( ) const
Returns
True when there are no more frames to produce (there are no more packets to decode) and all frames have been consumed by the client.

◆ isValid()

bool isValid ( ) const
Returns
whether object is initialized.

◆ matchesStream()

bool matchesStream ( const AVPacket &  packet) const
Returns
true when the packet belongs to the stream for this AVState.

◆ notifyExitIOThread()

void notifyExitIOThread ( )

Unblocks synchronization primitives for succesful exit of I/O thread.

◆ notifyStartIOThread()

void notifyStartIOThread ( )

Prepares for start of I/O thread, reset synchronization primitives.

◆ peekFrame()

Frame peekFrame ( )
Returns
If there was a frame on the queue, returns it without removing it from the queue.

◆ popFrame()

Frame popFrame ( )

Block until a frame can be popped from the queue.

Returns
The next frame on the queue. If the thread was exited during this operation, an empty frame is returned.

◆ popSeekFrame()

Frame popSeekFrame ( )
Returns
If there was a frame on the 'seek' frame queue, returns it without removing it from the queue.

◆ resetEndOfFileProcessed()

void resetEndOfFileProcessed ( )

Reset the state of the end of file processed event so that subsequent waits will wait normally

◆ resetWaitForFrameQueueEmpty()

void resetWaitForFrameQueueEmpty ( )

Reset the state of the frame queue so that subsequent waits will wait normally

◆ startDecodeThread()

void startDecodeThread ( const OnClearFrameQueueFunction onClearFrameQueueFunction = OnClearFrameQueueFunction())

Spawns the decode thread.

Parameters
onClearFrameQueueFunctionAn optional function that can be used to perform additional work when the frame queue is cleared.

◆ tryPopFrame()

Frame tryPopFrame ( double  pts)

Non-blocking popping of the next frame. The pts is checked to see if the next frame is equal or greater than the pts passed. If so, the frame is popped. Otherwise, an empty frame is returned.

Parameters
ptsThe 'current time' that is tested against the frames' PTS.

◆ waitForEndOfFileProcessed()

bool waitForEndOfFileProcessed ( )

Blocks until the EOF packet that was added by addEndOfFilePacket is consumed by the decode thread.

◆ waitForFrameQueueEmpty()

bool waitForFrameQueueEmpty ( bool &  exitIOThreadSignalled)

Wait for the frame to be empty

Parameters
exitIOThreadSignalledWhen I/O thread is in exit mode, this must be true.
Returns
if the queue emptied.

◆ waitForReceiveFrame()

int waitForReceiveFrame ( )

Blocks until the decode thread has called avcoded_receive. This is used to perform lock-step production of packets and frames.

Returns
Result of avcoded_receive_frame

◆ waitSeekStartPacketProcessed()

void waitSeekStartPacketProcessed ( )

Blocks until the 'seek start' packet that was added by addSeekStartPacket is consumed by the decode thread.