pianod2
multisource multiuser scriptable networked music player
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Audio::LavAdapter Class Referenceabstract

Adapter to feed a ffmpeg stream to an audio output. More...

#include <ffmpegplayer.h>

Inheritance diagram for Audio::LavAdapter:
Inheritance graph
[legend]

Classes

struct  FilterGraphDeleter
 
struct  FrameDeleter
 

Public Member Functions

virtual ~LavAdapter ()
 
bool play (AVFrame *frame)
 Play a frame from a ffmpeg decoder. More...
 
void setVolume (float level)
 

Static Public Member Functions

static LavAdaptergetOutput (const AudioSettings &settings, const AVCodecContext *context, const AVStream *stream)
 Choose an output, then get an adapter for libav and set it up to match the output's format. More...
 

Protected Member Functions

 LavAdapter (const AVCodecContext *codec, const AVStream *stream, const AVSampleFormat output_format)
 Adapt whatever output for input from ffmpeg. More...
 
virtual bool playFrame (AVFrame *frame)=0
 
bool playFilteredPackets (const bool eof_return_value=true)
 Read all the resulting frames coming out of the filter stack, and push them to the outputter. More...
 
void flush ()
 Play any frames buffered in the filter. More...
 

Private Member Functions

AVFilterContext * pushFilter (AVFilterContext *prior_filter, const char *name, const char *optionformat=nullptr,...)
 Add a filter to the filter stack. More...
 

Private Attributes

AVFilterContext * buffer_filter = nullptr
 
AVFilterContext * volume_filter = nullptr
 
AVFilterContext * format_filter = nullptr
 
AVFilterContext * endpoint_filter = nullptr
 
std::unique_ptr< AVFilterGraph, FilterGraphDeleterfilter_stack
 
std::unique_ptr< AVFrame, FrameDeleteroutput_frame = nullptr
 
std::mutex adapter_mutex
 

Detailed Description

Adapter to feed a ffmpeg stream to an audio output.

Constructor & Destructor Documentation

◆ LavAdapter()

Audio::LavAdapter::LavAdapter ( const AVCodecContext *  codec,
const AVStream *  stream,
const AVSampleFormat  output_format 
)
protected

Adapt whatever output for input from ffmpeg.

Parameters
codecThe ffmpeg codec context.
streamThe stream from whence audio will arrive.
output_formatThe format required by the outputter.
Here is the call graph for this function:

◆ ~LavAdapter()

Audio::LavAdapter::~LavAdapter ( )
virtual

Member Function Documentation

◆ flush()

void Audio::LavAdapter::flush ( )
protected

Play any frames buffered in the filter.

This must be invoked by subclasses during their destruction, as their specializations are gone by the time this class's destructor is called.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOutput()

LavAdapter * Audio::LavAdapter::getOutput ( const AudioSettings settings,
const AVCodecContext *  codec,
const AVStream *  stream 
)
static

Choose an output, then get an adapter for libav and set it up to match the output's format.

Parameters
settingsWhere to send the audio output.
codecAudio format details.
streamThe stream from which audio will arrive.
Returns
A ready-to-go output stack.
Exceptions
AudioExceptionor a derivative if a suitable output was not located, opening/setting up the device failed, or the adapter setup failed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ play()

bool Audio::LavAdapter::play ( AVFrame *  frame)

Play a frame from a ffmpeg decoder.

This involves passing it through the filter stack to adjust volume and format in accordance with the output's needs.

Parameters
frameThe audio frame to play.
Returns
True on success, false on error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ playFilteredPackets()

bool Audio::LavAdapter::playFilteredPackets ( const bool  eof_return_value = true)
protected

Read all the resulting frames coming out of the filter stack, and push them to the outputter.

Parameters
eof_return_valueValue to return if EOF is encountered.
Returns
On error, false. On eof, up to caller. Otherwise true.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ playFrame()

virtual bool Audio::LavAdapter::playFrame ( AVFrame *  frame)
protectedpure virtual

Implemented in Audio::LavGenericAdapter.

Here is the caller graph for this function:

◆ pushFilter()

AVFilterContext * Audio::LavAdapter::pushFilter ( AVFilterContext *  prior_filter,
const char *  name,
const char *  options_format = nullptr,
  ... 
)
private

Add a filter to the filter stack.

Parameters
prior_filterThe prior filter, or nullptr if it is the first. (used to wire the filters into sequence).
nameThe ffmpeg name of the filter.
options_formatA printf-style format string (and values to follow) to create an options string for the filter.
Returns
The new filter.
Exceptions
AudioExceptionif anything goes wrong.
Here is the caller graph for this function:

◆ setVolume()

void Audio::LavAdapter::setVolume ( float  level)
Here is the call graph for this function:

Member Data Documentation

◆ adapter_mutex

std::mutex Audio::LavAdapter::adapter_mutex
private

◆ buffer_filter

AVFilterContext* Audio::LavAdapter::buffer_filter = nullptr
private

◆ endpoint_filter

AVFilterContext* Audio::LavAdapter::endpoint_filter = nullptr
private

◆ filter_stack

std::unique_ptr<AVFilterGraph, FilterGraphDeleter> Audio::LavAdapter::filter_stack
private

◆ format_filter

AVFilterContext* Audio::LavAdapter::format_filter = nullptr
private

◆ output_frame

std::unique_ptr<AVFrame, FrameDeleter> Audio::LavAdapter::output_frame = nullptr
private

◆ volume_filter

AVFilterContext* Audio::LavAdapter::volume_filter = nullptr
private

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