MPD  0.20.18
Public Member Functions | Data Fields
DecoderControl Struct Reference

#include <DecoderControl.hxx>

Collaboration diagram for DecoderControl:
[legend]

Public Member Functions

 DecoderControl (Mutex &_mutex, Cond &_client_cond, const AudioFormat _configured_audio_format, const ReplayGainConfig &_replay_gain_config)
 
 ~DecoderControl ()
 
void Lock () const
 Locks the object. More...
 
void Unlock () const
 Unlocks the object. More...
 
void Signal ()
 Signals the object. More...
 
void Wait ()
 Waits for a signal on the DecoderControl object. More...
 
void WaitForDecoder ()
 Waits for a signal from the decoder thread. More...
 
bool IsIdle () const
 
gcc_pure bool LockIsIdle () const noexcept
 
bool IsStarting () const noexcept
 
gcc_pure bool LockIsStarting () const noexcept
 
bool HasFailed () const noexcept
 
gcc_pure bool LockHasFailed () const noexcept
 
void SetReady (const AudioFormat audio_format, bool _seekable, SignedSongTime _duration)
 Transition this obejct from DecoderState::START to DecoderState::DECODE. More...
 
void CheckRethrowError () const
 Checks whether an error has occurred, and if so, rethrows it. More...
 
void LockCheckRethrowError () const
 Like CheckRethrowError(), but locks and unlocks the object. More...
 
void ClearError ()
 Clear the error condition and free the #Error object (if any). More...
 
gcc_pure bool IsCurrentSong (const DetachedSong &_song) const noexcept
 Check if the specified song is currently being decoded. More...
 
gcc_pure bool LockIsCurrentSong (const DetachedSong &_song) const noexcept
 
void CommandFinishedLocked ()
 Marks the current command as "finished" and notifies the client (= player thread). More...
 
void Start (DetachedSong *song, SongTime start_time, SongTime end_time, MusicBuffer &buffer, MusicPipe &pipe)
 Start the decoder. More...
 
void Stop ()
 
void Seek (SongTime t)
 Throws #std::runtime_error on error. More...
 
void Quit ()
 
const char * GetMixRampStart () const
 
const char * GetMixRampEnd () const
 
const char * GetMixRampPreviousEnd () const
 
void SetMixRamp (MixRampInfo &&new_value)
 
void CycleMixRamp ()
 Move mixramp_end to mixramp_prev_end and clear mixramp_start/mixramp_end. More...
 

Data Fields

Thread thread
 The handle of the decoder thread. More...
 
Mutexmutex
 This lock protects state and command. More...
 
Cond cond
 Trigger this object after you have modified command. More...
 
Condclient_cond
 The trigger of this object's client. More...
 
DecoderState state = DecoderState::STOP
 
DecoderCommand command = DecoderCommand::NONE
 
std::exception_ptr error
 The error that occurred in the decoder thread. More...
 
bool quit
 
bool client_is_waiting = false
 Is the client currently waiting for the DecoderThread? If false, the DecoderThread may omit invoking Cond::signal(), reducing the number of system calls. More...
 
bool seek_error
 
bool seekable
 
SongTime seek_time
 
const AudioFormat configured_audio_format
 The "audio_output_format" setting. More...
 
AudioFormat in_audio_format
 the format of the song file More...
 
AudioFormat out_audio_format
 the format being sent to the music pipe More...
 
DetachedSongsong = nullptr
 The song currently being decoded. More...
 
SongTime start_time
 The initial seek position, e.g. More...
 
SongTime end_time
 The decoder will stop when it reaches this position. More...
 
SignedSongTime total_time
 
MusicBufferbuffer
 the MusicChunk allocator More...
 
MusicPipepipe
 The destination pipe for decoded chunks. More...
 
const ReplayGainConfig replay_gain_config
 
ReplayGainMode replay_gain_mode = ReplayGainMode::OFF
 
float replay_gain_db = 0
 
float replay_gain_prev_db = 0
 
MixRampInfo mix_ramp
 
MixRampInfo previous_mix_ramp
 

Detailed Description

Definition at line 63 of file DecoderControl.hxx.

Constructor & Destructor Documentation

◆ DecoderControl()

DecoderControl::DecoderControl ( Mutex _mutex,
Cond _client_cond,
const AudioFormat  _configured_audio_format,
const ReplayGainConfig _replay_gain_config 
)
Parameters
_mutexsee mutex
_client_condsee client_cond

◆ ~DecoderControl()

DecoderControl::~DecoderControl ( )

Member Function Documentation

◆ CheckRethrowError()

void DecoderControl::CheckRethrowError ( ) const
inline

Checks whether an error has occurred, and if so, rethrows it.

Caller must lock the object.

Definition at line 272 of file DecoderControl.hxx.

◆ ClearError()

void DecoderControl::ClearError ( )
inline

Clear the error condition and free the #Error object (if any).

Caller must lock the object.

Definition at line 293 of file DecoderControl.hxx.

◆ CommandFinishedLocked()

void DecoderControl::CommandFinishedLocked ( )
inline

Marks the current command as "finished" and notifies the client (= player thread).

To be called from the decoder thread. Caller must lock the mutex.

Definition at line 368 of file DecoderControl.hxx.

◆ CycleMixRamp()

void DecoderControl::CycleMixRamp ( )

Move mixramp_end to mixramp_prev_end and clear mixramp_start/mixramp_end.

◆ GetMixRampEnd()

const char* DecoderControl::GetMixRampEnd ( ) const
inline

Definition at line 401 of file DecoderControl.hxx.

◆ GetMixRampPreviousEnd()

const char* DecoderControl::GetMixRampPreviousEnd ( ) const
inline

Definition at line 405 of file DecoderControl.hxx.

◆ GetMixRampStart()

const char* DecoderControl::GetMixRampStart ( ) const
inline

Definition at line 397 of file DecoderControl.hxx.

◆ HasFailed()

bool DecoderControl::HasFailed ( ) const
inlinenoexcept

Definition at line 245 of file DecoderControl.hxx.

◆ IsCurrentSong()

gcc_pure bool DecoderControl::IsCurrentSong ( const DetachedSong _song) const
noexcept

Check if the specified song is currently being decoded.

If the decoder is not running currently (or being started), then this function returns false in any case.

Caller must lock the object.

◆ IsIdle()

bool DecoderControl::IsIdle ( ) const
inline

Definition at line 224 of file DecoderControl.hxx.

◆ IsStarting()

bool DecoderControl::IsStarting ( ) const
inlinenoexcept

Definition at line 235 of file DecoderControl.hxx.

◆ Lock()

void DecoderControl::Lock ( ) const
inline

Locks the object.

Definition at line 186 of file DecoderControl.hxx.

◆ LockCheckRethrowError()

void DecoderControl::LockCheckRethrowError ( ) const
inline

Like CheckRethrowError(), but locks and unlocks the object.

Definition at line 283 of file DecoderControl.hxx.

◆ LockHasFailed()

gcc_pure bool DecoderControl::LockHasFailed ( ) const
inlinenoexcept

Definition at line 252 of file DecoderControl.hxx.

◆ LockIsCurrentSong()

gcc_pure bool DecoderControl::LockIsCurrentSong ( const DetachedSong _song) const
inlinenoexcept

Definition at line 311 of file DecoderControl.hxx.

◆ LockIsIdle()

gcc_pure bool DecoderControl::LockIsIdle ( ) const
inlinenoexcept

Definition at line 230 of file DecoderControl.hxx.

◆ LockIsStarting()

gcc_pure bool DecoderControl::LockIsStarting ( ) const
inlinenoexcept

Definition at line 240 of file DecoderControl.hxx.

◆ Quit()

void DecoderControl::Quit ( )

◆ Seek()

void DecoderControl::Seek ( SongTime  t)

Throws #std::runtime_error on error.

◆ SetMixRamp()

void DecoderControl::SetMixRamp ( MixRampInfo &&  new_value)
inline

Definition at line 409 of file DecoderControl.hxx.

◆ SetReady()

void DecoderControl::SetReady ( const AudioFormat  audio_format,
bool  _seekable,
SignedSongTime  _duration 
)

Transition this obejct from DecoderState::START to DecoderState::DECODE.

Caller must lock the object.

◆ Signal()

void DecoderControl::Signal ( )
inline

Signals the object.

This function is only valid in the player thread. The object should be locked prior to calling this function.

Definition at line 202 of file DecoderControl.hxx.

◆ Start()

void DecoderControl::Start ( DetachedSong song,
SongTime  start_time,
SongTime  end_time,
MusicBuffer buffer,
MusicPipe pipe 
)

Start the decoder.

Parameters
songthe song to be decoded; the given instance will be owned and freed by the decoder
start_timesee DecoderControl
end_timesee DecoderControl
pipethe pipe which receives the decoded chunks (owned by the caller)

◆ Stop()

void DecoderControl::Stop ( )

◆ Unlock()

void DecoderControl::Unlock ( ) const
inline

Unlocks the object.

Definition at line 193 of file DecoderControl.hxx.

◆ Wait()

void DecoderControl::Wait ( )
inline

Waits for a signal on the DecoderControl object.

This function is only valid in the decoder thread. The object must be locked prior to calling this function.

Definition at line 211 of file DecoderControl.hxx.

◆ WaitForDecoder()

void DecoderControl::WaitForDecoder ( )

Waits for a signal from the decoder thread.

This object must be locked prior to calling this function. This method is only valid in the player thread.

Caller must hold the lock.

Field Documentation

◆ buffer

MusicBuffer* DecoderControl::buffer

the MusicChunk allocator

Definition at line 158 of file DecoderControl.hxx.

◆ client_cond

Cond& DecoderControl::client_cond

The trigger of this object's client.

It is signalled whenever an event occurs.

This is usually a reference to PlayerControl::cond.

Definition at line 92 of file DecoderControl.hxx.

◆ client_is_waiting

bool DecoderControl::client_is_waiting = false

Is the client currently waiting for the DecoderThread? If false, the DecoderThread may omit invoking Cond::signal(), reducing the number of system calls.

Definition at line 112 of file DecoderControl.hxx.

◆ command

DecoderCommand DecoderControl::command = DecoderCommand::NONE

Definition at line 95 of file DecoderControl.hxx.

◆ cond

Cond DecoderControl::cond

Trigger this object after you have modified command.

This is also used by the decoder thread to notify the caller when it has finished a command.

Definition at line 84 of file DecoderControl.hxx.

◆ configured_audio_format

const AudioFormat DecoderControl::configured_audio_format

The "audio_output_format" setting.

Definition at line 121 of file DecoderControl.hxx.

◆ end_time

SongTime DecoderControl::end_time

The decoder will stop when it reaches this position.

0 means don't stop before the end of the file.

This attribute is set by Start().

Definition at line 153 of file DecoderControl.hxx.

◆ error

std::exception_ptr DecoderControl::error

The error that occurred in the decoder thread.

This attribute is only valid if state is DecoderState::ERROR. The object must be freed when this object transitions to any other state (usually DecoderState::START).

Definition at line 103 of file DecoderControl.hxx.

◆ in_audio_format

AudioFormat DecoderControl::in_audio_format

the format of the song file

Definition at line 124 of file DecoderControl.hxx.

◆ mix_ramp

MixRampInfo DecoderControl::mix_ramp

Definition at line 172 of file DecoderControl.hxx.

◆ mutex

Mutex& DecoderControl::mutex

This lock protects state and command.

This is usually a reference to PlayerControl::mutex, so that both player thread and decoder thread share a mutex. This simplifies synchronization with cond and client_cond.

Definition at line 77 of file DecoderControl.hxx.

◆ out_audio_format

AudioFormat DecoderControl::out_audio_format

the format being sent to the music pipe

Definition at line 127 of file DecoderControl.hxx.

◆ pipe

MusicPipe* DecoderControl::pipe

The destination pipe for decoded chunks.

The caller thread owns this object, and is responsible for freeing it.

Definition at line 164 of file DecoderControl.hxx.

◆ previous_mix_ramp

MixRampInfo DecoderControl::previous_mix_ramp

Definition at line 172 of file DecoderControl.hxx.

◆ quit

bool DecoderControl::quit

Definition at line 105 of file DecoderControl.hxx.

◆ replay_gain_config

const ReplayGainConfig DecoderControl::replay_gain_config

Definition at line 166 of file DecoderControl.hxx.

◆ replay_gain_db

float DecoderControl::replay_gain_db = 0

Definition at line 169 of file DecoderControl.hxx.

◆ replay_gain_mode

ReplayGainMode DecoderControl::replay_gain_mode = ReplayGainMode::OFF

Definition at line 167 of file DecoderControl.hxx.

◆ replay_gain_prev_db

float DecoderControl::replay_gain_prev_db = 0

Definition at line 170 of file DecoderControl.hxx.

◆ seek_error

bool DecoderControl::seek_error

Definition at line 114 of file DecoderControl.hxx.

◆ seek_time

SongTime DecoderControl::seek_time

Definition at line 116 of file DecoderControl.hxx.

◆ seekable

bool DecoderControl::seekable

Definition at line 115 of file DecoderControl.hxx.

◆ song

DetachedSong* DecoderControl::song = nullptr

The song currently being decoded.

This attribute is set by the player thread, when it sends the DecoderCommand::START command.

This is a duplicate, and must be freed when this attribute is cleared.

Definition at line 137 of file DecoderControl.hxx.

◆ start_time

SongTime DecoderControl::start_time

The initial seek position, e.g.

to the start of a sub-track described by a CUE file.

This attribute is set by Start().

Definition at line 145 of file DecoderControl.hxx.

◆ state

DecoderState DecoderControl::state = DecoderState::STOP

Definition at line 94 of file DecoderControl.hxx.

◆ thread

Thread DecoderControl::thread

The handle of the decoder thread.

Definition at line 67 of file DecoderControl.hxx.

◆ total_time

SignedSongTime DecoderControl::total_time

Definition at line 155 of file DecoderControl.hxx.


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