pianod2
multisource multiuser scriptable networked music player
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Audio::LavPlayer Class Reference

ffmpeg audio player More...

#include <ffmpegplayer.h>

Inheritance diagram for Audio::LavPlayer:
Inheritance graph
[legend]
Collaboration diagram for Audio::LavPlayer:
Collaboration graph
[legend]

Public Member Functions

 LavPlayer (const AudioSettings &AudioSettings, const std::string &media_url, float audio_gain=0)
 Play a media file or URL using ffmpeg. More...
 
- Public Member Functions inherited from Media::ThreadedPlayer
 ThreadedPlayer (void)
 
virtual ~ThreadedPlayer (void)
 
- Public Member Functions inherited from Media::Player
virtual ~Player (void)
 
virtual float playRemaining (void) const
 Seconds left in playback, or a negative number if unknown. More...
 
bool ready (void) const
 Indicate if player has finished initializing. More...
 
bool playbackComplete (void) const
 Indicate if playback is complete and ready for cleanup. More...
 
virtual time_t getPauseTimeout (void)
 When paused, get the time at which the song will expire. More...
 
- Public Member Functions inherited from Audio::LibavMediaReader
 LibavMediaReader (const std::string &media_url, int timeout=15)
 Base abstract class for reading a media file or URL using ffmpeg. More...
 
virtual ~LibavMediaReader (void)
 

Private Member Functions

bool playPacket (AVFrame *frame, AVCodecContext *codec, AVPacket *packet)
 
RESPONSE_CODE playStream (AVFormatContext *format, AVCodecContext *codec, const int audio_stream)
 
virtual void setGain (float gain) override
 
virtual void setVolume (float volume) override
 Adjust volume in decibels. More...
 
virtual State currentState (void) const override
 
virtual float trackDuration (void) const override
 Length of track in seconds, or a negative number if unknown. More...
 
virtual float playPoint (void) const override
 Seconds from start, or a negative value if unknown. More...
 
virtual RESPONSE_CODE playerThread (void) override
 
virtual void pausing (void) override
 Called when the playback thread is pausing. More...
 
virtual void resuming (void) override
 Called when the playback thread is resuming playback. More...
 

Private Attributes

AudioSettings audio
 Output settings. More...
 
float gain = 0
 Replay gain from track. More...
 
volatile float duration = -1
 Length of song, in seconds. More...
 
volatile float playpoint = 0
 Current point in song, in seconds. More...
 
volatile Media::Player::State state = Initializing
 
std::unique_ptr< Audio::LavAdapteroutput
 

Additional Inherited Members

- Public Types inherited from Media::Player
enum  State {
  DoesNotExist , Initializing , Cueing , Playing ,
  Done
}
 
- Static Public Member Functions inherited from Media::Player
static Media::PlayergetPlayer (const AudioSettings &settings, const std::string &media_url, float initial_gain)
 Get the a media player currently compiled in the code. More...
 
- Protected Member Functions inherited from Media::ThreadedPlayer
bool checkForPauseOrQuit (void)
 
- Protected Member Functions inherited from Audio::LibavMediaReader
int initializeStream (std::unique_ptr< AVCodecContext, CodecDeleter > &codec_context)
 Prepare a ffmpeg source for playing its audio stream. More...
 
void processReplayGain (AVReplayGain *gain, int size)
 Process a replaygain packet by extracting the track gain, or if not found then then the album gain. More...
 
- Protected Attributes inherited from Audio::LibavMediaReader
const std::string url
 Media URL or filename. More...
 
bool is_network = false
 True if media is network streaming. More...
 
AVFormatContext * transport = nullptr
 

Detailed Description

ffmpeg audio player

Constructor & Destructor Documentation

◆ LavPlayer()

Audio::LavPlayer::LavPlayer ( const AudioSettings AudioSettings,
const std::string &  media_url,
float  audio_gain = 0 
)

Play a media file or URL using ffmpeg.

Parameters
AudioSettingsDescribe the output device.
media_urlThe filename or URL of the media.
audio_gainGain to apply when playing file, in decibels. If ReplayGain is encountered during playback, that is preferred over this value.

Member Function Documentation

◆ currentState()

Media::Player::State Audio::LavPlayer::currentState ( void  ) const
overrideprivatevirtual

Implements Media::Player.

◆ pausing()

void Audio::LavPlayer::pausing ( void  )
overrideprivatevirtual

Called when the playback thread is pausing.

Reimplemented from Media::ThreadedPlayer.

◆ playerThread()

RESPONSE_CODE Audio::LavPlayer::playerThread ( void  )
overrideprivatevirtual

Implements Media::ThreadedPlayer.

Here is the call graph for this function:

◆ playPacket()

bool Audio::LavPlayer::playPacket ( AVFrame *  frame,
AVCodecContext *  codec,
AVPacket *  packet 
)
private

Decode and play an audio frame from ffmpeg.

Parameters
frameOne frame from the media stream.
codecThe codec state for decoding the stream.
packetA packet from the stream, undecoded.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ playPoint()

float Audio::LavPlayer::playPoint ( void  ) const
overrideprivatevirtual

Seconds from start, or a negative value if unknown.

Implements Media::Player.

◆ playStream()

RESPONSE_CODE Audio::LavPlayer::playStream ( AVFormatContext *  format,
AVCodecContext *  codec,
const int  audio_stream 
)
private

Play a media stream from ffmpeg.

Parameters
formatThe multiplexed media thing.
codecThe codec context for the audio stream.
audio_streamThe index of the audio stream.
Returns
Pianod S_OK or a F_* error code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resuming()

void Audio::LavPlayer::resuming ( void  )
overrideprivatevirtual

Called when the playback thread is resuming playback.

Reimplemented from Media::ThreadedPlayer.

◆ setGain()

void Audio::LavPlayer::setGain ( float  gain)
overrideprivatevirtual

Implements Audio::LibavMediaReader.

Here is the call graph for this function:

◆ setVolume()

void Audio::LavPlayer::setVolume ( float  volume)
overrideprivatevirtual

Adjust volume in decibels.

Implements Media::Player.

◆ trackDuration()

float Audio::LavPlayer::trackDuration ( void  ) const
overrideprivatevirtual

Length of track in seconds, or a negative number if unknown.

Implements Media::Player.

Member Data Documentation

◆ audio

AudioSettings Audio::LavPlayer::audio
private

Output settings.

◆ duration

volatile float Audio::LavPlayer::duration = -1
private

Length of song, in seconds.

◆ gain

float Audio::LavPlayer::gain = 0
private

Replay gain from track.

◆ output

std::unique_ptr<Audio::LavAdapter> Audio::LavPlayer::output
private

◆ playpoint

volatile float Audio::LavPlayer::playpoint = 0
private

Current point in song, in seconds.

◆ state

volatile Media::Player::State Audio::LavPlayer::state = Initializing
private

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