MPD: DecoderBridge Class Reference

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...
MusicChunk * | GetChunk () 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 () noexcept override
| 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 () noexcept override
| Call this when you have received the DecoderCommand::SEEK command. More...
uint64_t | GetSeekFrame () noexcept override
| 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
DecoderControl & | dc
PcmConvert * | convert = 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...
Tag * | song_tag
| The tag from the song object. More...
Tag * | stream_tag = nullptr
| the last tag received from the stream More...
Tag * | decoder_tag = nullptr
| the last tag received from the decoder plugin More...
MusicChunk * | current_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::DecoderBridge | ( | DecoderControl & | _dc,
|  | bool | _initial_seek_pending,
|  | Tag * | _tag
| ) |  |
| inline

Definition at line 107 of file Bridge.hxx.

## ◆ ~DecoderBridge()

DecoderBridge::~DecoderBridge | ( |  | ) |

## Member Function Documentation

## ◆ CheckCancelRead()

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.

## ◆ CommandFinished()

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.

## ◆ FlushChunk()

void DecoderBridge::FlushChunk | ( |  | ) |

Flushes the current chunk.

Caller must not lock the DecoderControl object.

## ◆ GetChunk()

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

## ◆ GetCommand()

DecoderCommand DecoderBridge::GetCommand | ( |  | ) |
| overridevirtualnoexcept

Determines the pending decoder command.

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

Implements DecoderClient.

## ◆ GetSeekFrame()

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.

## ◆ GetSeekTime()

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.

## ◆ OpenUri()

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.

## ◆ Read()

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

Blocking read from the input stream.

Parameters

  is | the input stream to read from
  buffer | the destination buffer
  length | the 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.

## ◆ Ready()

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_format | the audio format which is going to be sent to SubmitData()
  seekable | true if the song is seekable
  duration | the total duration of this song; negative if unknown

Implements DecoderClient.

## ◆ SeekError()

void DecoderBridge::SeekError | ( |  | ) |
| overridevirtual

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

Implements DecoderClient.

## ◆ SubmitData()

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

  is | an input stream which is buffering while we are waiting for the player
  data | the source buffer
  length | the number of bytes in the buffer

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

Implements DecoderClient.

## ◆ SubmitMixRamp()

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

Store MixRamp tags.

Implements DecoderClient.

## ◆ SubmitReplayGain()

void DecoderBridge::SubmitReplayGain | ( | const ReplayGainInfo * | replay_gain_info | ) |
| overridevirtual

Set replay gain values for the following chunks.

Parameters

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

Implements DecoderClient.

## ◆ SubmitTag()

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

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

Parameters

  is | an input stream which is buffering while we are waiting for the player
  tag | the tag to send

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

Implements DecoderClient.

## ◆ SubmitTimestamp()

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

## ◆ absolute_frame

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.

## ◆ convert

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.

## ◆ current_chunk

MusicChunk* DecoderBridge::current_chunk = nullptr

the chunk currently being written to

Definition at line 91 of file Bridge.hxx.

## ◆ dc

DecoderControl& DecoderBridge::dc

Definition at line 39 of file Bridge.hxx.

## ◆ decoder_tag

Tag* DecoderBridge::decoder_tag = nullptr

the last tag received from the decoder plugin

Definition at line 88 of file Bridge.hxx.

## ◆ error

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.

## ◆ initial_seek_pending

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.

## ◆ initial_seek_running

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.

## ◆ replay_gain_info

ReplayGainInfo DecoderBridge::replay_gain_info

Definition at line 93 of file Bridge.hxx.

## ◆ replay_gain_serial

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.

## ◆ seeking

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.

## ◆ song_tag

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.

## ◆ stream_tag

Tag* DecoderBridge::stream_tag = nullptr

the last tag received from the stream

Definition at line 85 of file Bridge.hxx.

## ◆ timestamp

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:

- decoder/Bridge.hxx