MPD  0.20.18
Public Member Functions | Data Fields
DecoderBridge Class Referencefinal

A bridge between the DecoderClient interface and the MPD core (DecoderControl, MusicPipe etc.). More...

#include <Bridge.hxx>

Inheritance diagram for DecoderBridge:
[legend]
Collaboration diagram for DecoderBridge:
[legend]

Public Member Functions

 DecoderBridge (DecoderControl &_dc, bool _initial_seek_pending, Tag *_tag)
 
 ~DecoderBridge ()
 
gcc_pure bool CheckCancelRead () const noexcept
 Should be read operation be cancelled? That is the case when the player thread has sent a command such as "STOP". More...
 
MusicChunkGetChunk () noexcept
 Returns the current chunk the decoder writes to, or allocates a new chunk if there is none. More...
 
void FlushChunk ()
 Flushes the current chunk. More...
 
void Ready (AudioFormat audio_format, bool seekable, SignedSongTime duration) override
 Notify the client that it has finished initialization and that it has read the song's meta data. More...
 
DecoderCommand GetCommand () noexceptoverride
 Determines the pending decoder command. More...
 
void CommandFinished () override
 Called by the decoder when it has performed the requested command (dc->command). More...
 
SongTime GetSeekTime () noexceptoverride
 Call this when you have received the DecoderCommand::SEEK command. More...
 
uint64_t GetSeekFrame () noexceptoverride
 Call this when you have received the DecoderCommand::SEEK command. More...
 
void SeekError () override
 Call this instead of CommandFinished() when seeking has failed. More...
 
InputStreamPtr OpenUri (const char *uri) override
 Open a new InputStream and wait until it's ready. More...
 
size_t Read (InputStream &is, void *buffer, size_t length) override
 Blocking read from the input stream. More...
 
void SubmitTimestamp (double t) override
 Sets the time stamp for the next data chunk [seconds]. More...
 
DecoderCommand SubmitData (InputStream *is, const void *data, size_t length, uint16_t kbit_rate) override
 This function is called by the decoder plugin when it has successfully decoded block of input data. More...
 
DecoderCommand SubmitTag (InputStream *is, Tag &&tag) override
 This function is called by the decoder plugin when it has successfully decoded a tag. More...
 
void SubmitReplayGain (const ReplayGainInfo *replay_gain_info) override
 Set replay gain values for the following chunks. More...
 
void SubmitMixRamp (MixRampInfo &&mix_ramp) override
 Store MixRamp tags. More...
 
- Public Member Functions inherited from DecoderClient
DecoderCommand SubmitData (InputStream &is, const void *data, size_t length, uint16_t kbit_rate)
 
DecoderCommand SubmitTag (InputStream &is, Tag &&tag)
 

Data Fields

DecoderControldc
 
PcmConvertconvert = nullptr
 For converting input data to the configured audio format. More...
 
double timestamp = 0
 The time stamp of the next data chunk, in seconds. More...
 
uint64_t absolute_frame = 0
 The time stamp of the next data chunk, in PCM frames. More...
 
bool initial_seek_pending
 Is the initial seek (to the start position of the sub-song) pending, or has it been performed already? More...
 
bool initial_seek_running = false
 Is the initial seek currently running? During this time, the decoder command is SEEK. More...
 
bool seeking = false
 This flag is set by GetSeekTime(), and checked by CommandFinished(). More...
 
Tagsong_tag
 The tag from the song object. More...
 
Tagstream_tag = nullptr
 the last tag received from the stream More...
 
Tagdecoder_tag = nullptr
 the last tag received from the decoder plugin More...
 
MusicChunkcurrent_chunk = nullptr
 the chunk currently being written to More...
 
ReplayGainInfo replay_gain_info
 
unsigned replay_gain_serial = 0
 A positive serial number for checking if replay gain info has changed since the last check. More...
 
std::exception_ptr error
 An error has occurred (in DecoderAPI.cxx), and the plugin will be asked to stop. More...
 

Detailed Description

A bridge between the DecoderClient interface and the MPD core (DecoderControl, MusicPipe etc.).

Definition at line 37 of file Bridge.hxx.

Constructor & Destructor Documentation

DecoderBridge::DecoderBridge ( DecoderControl _dc,
bool  _initial_seek_pending,
Tag _tag 
)
inline

Definition at line 107 of file Bridge.hxx.

DecoderBridge::~DecoderBridge ( )

Member Function Documentation

gcc_pure bool DecoderBridge::CheckCancelRead ( ) const
noexcept

Should be read operation be cancelled? That is the case when the player thread has sent a command such as "STOP".

Caller must lock the DecoderControl object.

void DecoderBridge::CommandFinished ( )
overridevirtual

Called by the decoder when it has performed the requested command (dc->command).

This function resets dc->command and wakes up the player thread.

Implements DecoderClient.

void DecoderBridge::FlushChunk ( )

Flushes the current chunk.

Caller must not lock the DecoderControl object.

MusicChunk* DecoderBridge::GetChunk ( )
noexcept

Returns the current chunk the decoder writes to, or allocates a new chunk if there is none.

Returns
the chunk, or NULL if we have received a decoder command
DecoderCommand DecoderBridge::GetCommand ( )
overridevirtualnoexcept

Determines the pending decoder command.

Returns
the current command, or DecoderCommand::NONE if there is no command pending

Implements DecoderClient.

uint64_t DecoderBridge::GetSeekFrame ( )
overridevirtualnoexcept

Call this when you have received the DecoderCommand::SEEK command.

Returns
the destination position for the seek in frames

Implements DecoderClient.

SongTime DecoderBridge::GetSeekTime ( )
overridevirtualnoexcept

Call this when you have received the DecoderCommand::SEEK command.

Returns
the destination position for the seek in milliseconds

Implements DecoderClient.

InputStreamPtr DecoderBridge::OpenUri ( const char *  uri)
overridevirtual

Open a new InputStream and wait until it's ready.

Throws StopDecoder if DecoderCommand::STOP was received.

Throws std::runtime_error on error.

Implements DecoderClient.

size_t DecoderBridge::Read ( InputStream is,
void *  buffer,
size_t  length 
)
overridevirtual

Blocking read from the input stream.

Parameters
isthe input stream to read from
bufferthe destination buffer
lengththe maximum number of bytes to read
Returns
the number of bytes read, or 0 if one of the following occurs: end of file; error; command (like SEEK or STOP).

Implements DecoderClient.

void DecoderBridge::Ready ( AudioFormat  audio_format,
bool  seekable,
SignedSongTime  duration 
)
overridevirtual

Notify the client that it has finished initialization and that it has read the song's meta data.

Parameters
audio_formatthe audio format which is going to be sent to SubmitData()
seekabletrue if the song is seekable
durationthe total duration of this song; negative if unknown

Implements DecoderClient.

void DecoderBridge::SeekError ( )
overridevirtual

Call this instead of CommandFinished() when seeking has failed.

Implements DecoderClient.

DecoderCommand DecoderBridge::SubmitData ( InputStream is,
const void *  data,
size_t  length,
uint16_t  kbit_rate 
)
overridevirtual

This function is called by the decoder plugin when it has successfully decoded block of input data.

Parameters
isan input stream which is buffering while we are waiting for the player
datathe source buffer
lengththe number of bytes in the buffer
Returns
the current command, or DecoderCommand::NONE if there is no command pending

Implements DecoderClient.

void DecoderBridge::SubmitMixRamp ( MixRampInfo &&  mix_ramp)
overridevirtual

Store MixRamp tags.

Implements DecoderClient.

void DecoderBridge::SubmitReplayGain ( const ReplayGainInfo replay_gain_info)
overridevirtual

Set replay gain values for the following chunks.

Parameters
replay_gain_infothe replay_gain_info object; may be nullptr to invalidate the previous replay gain values

Implements DecoderClient.

DecoderCommand DecoderBridge::SubmitTag ( InputStream is,
Tag &&  tag 
)
overridevirtual

This function is called by the decoder plugin when it has successfully decoded a tag.

Parameters
isan input stream which is buffering while we are waiting for the player
tagthe tag to send
Returns
the current command, or DecoderCommand::NONE if there is no command pending

Implements DecoderClient.

void DecoderBridge::SubmitTimestamp ( double  t)
overridevirtual

Sets the time stamp for the next data chunk [seconds].

The MPD core automatically counts it up, and a decoder plugin only needs to use this function if it thinks that adding to the time stamp based on the buffer size won't work.

Implements DecoderClient.

Field Documentation

uint64_t DecoderBridge::absolute_frame = 0

The time stamp of the next data chunk, in PCM frames.

Definition at line 55 of file Bridge.hxx.

PcmConvert* DecoderBridge::convert = nullptr

For converting input data to the configured audio format.

nullptr means no conversion necessary.

Definition at line 45 of file Bridge.hxx.

MusicChunk* DecoderBridge::current_chunk = nullptr

the chunk currently being written to

Definition at line 91 of file Bridge.hxx.

DecoderControl& DecoderBridge::dc

Definition at line 39 of file Bridge.hxx.

Tag* DecoderBridge::decoder_tag = nullptr

the last tag received from the decoder plugin

Definition at line 88 of file Bridge.hxx.

std::exception_ptr DecoderBridge::error

An error has occurred (in DecoderAPI.cxx), and the plugin will be asked to stop.

Definition at line 105 of file Bridge.hxx.

bool DecoderBridge::initial_seek_pending

Is the initial seek (to the start position of the sub-song) pending, or has it been performed already?

Definition at line 61 of file Bridge.hxx.

bool DecoderBridge::initial_seek_running = false

Is the initial seek currently running? During this time, the decoder command is SEEK.

This flag is set by decoder_get_virtual_command(), when the virtual SEEK command is generated for the first time.

Definition at line 69 of file Bridge.hxx.

ReplayGainInfo DecoderBridge::replay_gain_info

Definition at line 93 of file Bridge.hxx.

unsigned DecoderBridge::replay_gain_serial = 0

A positive serial number for checking if replay gain info has changed since the last check.

Definition at line 99 of file Bridge.hxx.

bool DecoderBridge::seeking = false

This flag is set by GetSeekTime(), and checked by CommandFinished().

It is used to clean up after seeking.

Definition at line 75 of file Bridge.hxx.

Tag* DecoderBridge::song_tag

The tag from the song object.

This is only used for local files, because we expect the stream server to send us a new tag each time we play it.

Definition at line 82 of file Bridge.hxx.

Tag* DecoderBridge::stream_tag = nullptr

the last tag received from the stream

Definition at line 85 of file Bridge.hxx.

double DecoderBridge::timestamp = 0

The time stamp of the next data chunk, in seconds.

Definition at line 50 of file Bridge.hxx.


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