MPD: PlayerControl Struct Reference

MPD 0.20.18

Public Member Functions | Data Fields
PlayerControl Struct Referencefinal

`#include <Control.hxx>`

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

## Public Member Functions
| PlayerControl (PlayerListener &_listener, MultipleOutputs &_outputs, unsigned buffer_chunks, unsigned buffered_before_play, AudioFormat _configured_audio_format, const ReplayGainConfig &_replay_gain_config)
| ~PlayerControl ()
void | Lock () const
| Locks the object. More...
void | Unlock () const
| Unlocks the object. More...
void | Signal ()
| Signals the object. More...
void | LockSignal ()
| Signals the object. More...
void | Wait ()
| Waits for a signal on the object. More...
void | ClientSignal ()
| Wake up the client waiting for command completion. More...
void | ClientWait ()
| The client calls this method to wait for command completion. More...
void | CommandFinished ()
| A command has been finished. More...
void | LockCommandFinished ()
bool | WaitOutputConsumed (unsigned threshold)
| Checks if the size of the MusicPipe is below the #threshold. More...
bool | LockWaitOutputConsumed (unsigned threshold)
void | Play (DetachedSong *song)
| Throws std::runtime_error or #Error on error. More...
void | LockCancel ()
| see PlayerCommand::CANCEL More...
void | LockSetPause (bool pause_flag)
void | LockPause ()
void | LockSetBorderPause (bool border_pause)
| Set the player's border_pause flag. More...
bool | ApplyBorderPause ()
bool | LockApplyBorderPause ()
void | Kill ()
gcc_pure player_status | LockGetStatus () noexcept
PlayerState | GetState () const
void | SetError (PlayerError type, std::exception_ptr &&_error)
| Set the error. More...
void | SetOutputError (std::exception_ptr &&_error)
| Set the error and set state to PlayerState::PAUSE. More...
void | LockSetOutputError (std::exception_ptr &&_error)
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 | LockClearError ()
PlayerError | GetErrorType () const
void | LockSetTaggedSong (const DetachedSong &song)
| Set the tagged_song attribute to a newly allocated copy of the given DetachedSong. More...
void | ClearTaggedSong ()
DetachedSong * | ReadTaggedSong ()
| Read and clear the tagged_song attribute. More...
DetachedSong * | LockReadTaggedSong ()
| Like ReadTaggedSong(), but locks and unlocks the object. More...
void | LockStop ()
void | LockUpdateAudio ()
void | LockEnqueueSong (DetachedSong *song)
void | LockSeek (DetachedSong *song, SongTime t)
| Makes the player thread seek the specified song to a position. More...
void | SetCrossFade (float cross_fade_seconds)
float | GetCrossFade () const
void | SetMixRampDb (float mixramp_db)
float | GetMixRampDb () const
void | SetMixRampDelay (float mixramp_delay_seconds)
float | GetMixRampDelay () const
void | LockSetReplayGainMode (ReplayGainMode _mode)
double | GetTotalPlayTime () const
void | ChunksConsumed () override
| Notify the client that we have consumed a few chunks. More...
void | ApplyEnabled () override
| The AudioOutput has modified the "enabled" flag, and the client shall make the AudioOutput apply this new setting. More...

## Data Fields
PlayerListener & | listener
MultipleOutputs & | outputs
const unsigned | buffer_chunks
const unsigned | buffered_before_play
const AudioFormat | configured_audio_format
| The "audio_output_format" setting. More...
Thread | thread
| The handle of the player thread. More...
Mutex | mutex
| This lock protects command, state, error, tagged_song. More...
Cond | cond
| Trigger this object after you have modified command. More...
Cond | client_cond
| This object gets signalled when the player thread has finished the command. More...
PlayerCommand | command = PlayerCommand::NONE
PlayerState | state = PlayerState::STOP
PlayerError | error_type = PlayerError::NONE
std::exception_ptr | error
| The error that occurred in the player thread. More...
DetachedSong * | tagged_song = nullptr
| A copy of the current DetachedSong after its tags have been updated by the decoder (for example, a radio stream that has sent a new tag after switching to the next song). More...
uint16_t | bit_rate
AudioFormat | audio_format
SignedSongTime | total_time
SongTime | elapsed_time
DetachedSong * | next_song = nullptr
| The next queued song. More...
SongTime | seek_time
CrossFadeSettings | cross_fade
const ReplayGainConfig | replay_gain_config
ReplayGainMode | replay_gain_mode = ReplayGainMode::OFF
double | total_play_time = 0
bool | border_pause = false
| If this flag is set, then the player will be auto-paused at the end of the song, before the next song starts to play. More...

## Detailed Description

Definition at line 100 of file Control.hxx.

## Constructor & Destructor Documentation

## ◆ PlayerControl()

PlayerControl::PlayerControl | ( | PlayerListener & | _listener,
|  | MultipleOutputs & | _outputs,
|  | unsigned | buffer_chunks,
|  | unsigned | buffered_before_play,
|  | AudioFormat | _configured_audio_format,
|  | const ReplayGainConfig & | _replay_gain_config
| ) |  |

## ◆ ~PlayerControl()

PlayerControl::~PlayerControl | ( |  | ) |

## Member Function Documentation

## ◆ ApplyBorderPause()

bool PlayerControl::ApplyBorderPause | ( |  | ) |
| inline

Definition at line 372 of file Control.hxx.

## ◆ ApplyEnabled()

void PlayerControl::ApplyEnabled | ( |  | ) |
| inlineoverridevirtual

The AudioOutput has modified the "enabled" flag, and the client shall make the AudioOutput apply this new setting.

This is called from any thread, one which can't send an AudioOutput::Command to the output thread; only the client can do that safely.

Implements AudioOutputClient.

Definition at line 537 of file Control.hxx.

## ◆ CheckRethrowError()

void PlayerControl::CheckRethrowError | ( |  | ) | const
| inline

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

Caller must lock the object.

Definition at line 423 of file Control.hxx.

## ◆ ChunksConsumed()

void PlayerControl::ChunksConsumed | ( |  | ) |
| inlineoverridevirtual

Notify the client that we have consumed a few chunks.

This is called from within the output thread. The client may perform actions to refill the MusicPipe.

Implements AudioOutputClient.

Definition at line 533 of file Control.hxx.

## ◆ ClearTaggedSong()

void PlayerControl::ClearTaggedSong | ( |  | ) |

## ◆ ClientSignal()

void PlayerControl::ClientSignal | ( |  | ) |
| inline

Wake up the client waiting for command completion.

Caller must lock the object.

Definition at line 247 of file Control.hxx.

## ◆ ClientWait()

void PlayerControl::ClientWait | ( |  | ) |
| inline

The client calls this method to wait for command completion.

Caller must lock the object.

Definition at line 259 of file Control.hxx.

## ◆ CommandFinished()

void PlayerControl::CommandFinished | ( |  | ) |
| inline

A command has been finished.

This method clears the command and signals the client.

To be called from the player thread. Caller must lock the object.

Definition at line 272 of file Control.hxx.

## ◆ GetCrossFade()

float PlayerControl::GetCrossFade | ( |  | ) | const
| inline

Definition at line 507 of file Control.hxx.

## ◆ GetErrorType()

PlayerError PlayerControl::GetErrorType | ( |  | ) | const
| inline

Definition at line 438 of file Control.hxx.

## ◆ GetMixRampDb()

float PlayerControl::GetMixRampDb | ( |  | ) | const
| inline

Definition at line 513 of file Control.hxx.

## ◆ GetMixRampDelay()

float PlayerControl::GetMixRampDelay | ( |  | ) | const
| inline

Definition at line 519 of file Control.hxx.

## ◆ GetState()

PlayerState PlayerControl::GetState | ( |  | ) | const
| inline

Definition at line 388 of file Control.hxx.

## ◆ GetTotalPlayTime()

double PlayerControl::GetTotalPlayTime | ( |  | ) | const
| inline

Definition at line 528 of file Control.hxx.

## ◆ Kill()

void PlayerControl::Kill | ( |  | ) |

## ◆ Lock()

void PlayerControl::Lock | ( |  | ) | const
| inline

Locks the object.

Definition at line 203 of file Control.hxx.

## ◆ LockApplyBorderPause()

bool PlayerControl::LockApplyBorderPause | ( |  | ) |
| inline

Definition at line 378 of file Control.hxx.

## ◆ LockCancel()

void PlayerControl::LockCancel | ( |  | ) |

see PlayerCommand::CANCEL

## ◆ LockCheckRethrowError()

void PlayerControl::LockCheckRethrowError | ( |  | ) | const
| inline

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

Definition at line 431 of file Control.hxx.

## ◆ LockClearError()

void PlayerControl::LockClearError | ( |  | ) |

## ◆ LockCommandFinished()

void PlayerControl::LockCommandFinished | ( |  | ) |
| inline

Definition at line 279 of file Control.hxx.

## ◆ LockEnqueueSong()

void PlayerControl::LockEnqueueSong | ( | DetachedSong * | song | ) |

Parameters

  song | the song to be queued; the given instance will be owned and freed by the player

## ◆ LockGetStatus()

gcc_pure player_status PlayerControl::LockGetStatus | ( |  | ) |
| noexcept

## ◆ LockPause()

void PlayerControl::LockPause | ( |  | ) |

## ◆ LockReadTaggedSong()

DetachedSong* PlayerControl::LockReadTaggedSong | ( |  | ) |
| inline

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

Definition at line 464 of file Control.hxx.

## ◆ LockSeek()

void PlayerControl::LockSeek | ( | DetachedSong * | song,
|  | SongTime | t
| ) |  |

Makes the player thread seek the specified song to a position.

Throws std::runtime_error or #Error on error.

Parameters

  song | the song to be queued; the given instance will be owned and freed by the player

## ◆ LockSetBorderPause()

void PlayerControl::LockSetBorderPause | ( | bool | border_pause | ) |

Set the player's border_pause flag.

## ◆ LockSetOutputError()

void PlayerControl::LockSetOutputError | ( | std::exception_ptr && | _error | ) |
| inline

Definition at line 412 of file Control.hxx.

## ◆ LockSetPause()

void PlayerControl::LockSetPause | ( | bool | pause_flag | ) |

## ◆ LockSetReplayGainMode()

void PlayerControl::LockSetReplayGainMode | ( | ReplayGainMode | _mode | ) |
| inline

Definition at line 523 of file Control.hxx.

## ◆ LockSetTaggedSong()

void PlayerControl::LockSetTaggedSong | ( | const DetachedSong & | song | ) |

Set the tagged_song attribute to a newly allocated copy of the given DetachedSong.

Locks and unlocks the object.

## ◆ LockSignal()

void PlayerControl::LockSignal | ( |  | ) |
| inline

Signals the object.

The object is temporarily locked by this function.

Definition at line 226 of file Control.hxx.

## ◆ LockStop()

void PlayerControl::LockStop | ( |  | ) |

## ◆ LockUpdateAudio()

void PlayerControl::LockUpdateAudio | ( |  | ) |

## ◆ LockWaitOutputConsumed()

bool PlayerControl::LockWaitOutputConsumed | ( | unsigned | threshold | ) |
| inline

Definition at line 296 of file Control.hxx.

## ◆ Play()

void PlayerControl::Play | ( | DetachedSong * | song | ) |

Throws std::runtime_error or #Error on error.

Parameters

  song | the song to be queued; the given instance will be owned and freed by the player

## ◆ ReadTaggedSong()

DetachedSong* PlayerControl::ReadTaggedSong | ( |  | ) |
| inline

Read and clear the tagged_song attribute.

Caller must lock the object.

Definition at line 455 of file Control.hxx.

## ◆ SetCrossFade()

void PlayerControl::SetCrossFade | ( | float | cross_fade_seconds | ) |

## ◆ SetError()

void PlayerControl::SetError | ( | PlayerError | type,
|  | std::exception_ptr && | _error
| ) |  |

Set the error.

Discards any previous error condition.

Caller must lock the object.

Parameters

  type | the error type; must not be PlayerError::NONE

## ◆ SetMixRampDb()

void PlayerControl::SetMixRampDb | ( | float | mixramp_db | ) |

## ◆ SetMixRampDelay()

void PlayerControl::SetMixRampDelay | ( | float | mixramp_delay_seconds | ) |

## ◆ SetOutputError()

void PlayerControl::SetOutputError | ( | std::exception_ptr && | _error | ) |
| inline

Set the error and set state to PlayerState::PAUSE.

Definition at line 404 of file Control.hxx.

## ◆ Signal()

void PlayerControl::Signal | ( |  | ) |
| inline

Signals the object.

The object should be locked prior to calling this function.

Definition at line 218 of file Control.hxx.

## ◆ Unlock()

void PlayerControl::Unlock | ( |  | ) | const
| inline

Unlocks the object.

Definition at line 210 of file Control.hxx.

## ◆ Wait()

void PlayerControl::Wait | ( |  | ) |
| inline

Waits for a signal on the object.

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

Definition at line 236 of file Control.hxx.

## ◆ WaitOutputConsumed()

bool PlayerControl::WaitOutputConsumed | ( | unsigned | threshold | ) |

Checks if the size of the MusicPipe is below the #threshold.

If not, it attempts to synchronize with all output threads, and waits until another MusicChunk is finished.

Caller must lock the mutex.

Parameters

  threshold | the maximum number of chunks in the pipe

Returns
  true if there are less than #threshold chunks in the pipe

## Field Documentation

## ◆ audio_format

AudioFormat PlayerControl::audio_format

Definition at line 162 of file Control.hxx.

## ◆ bit_rate

uint16_t PlayerControl::bit_rate

Definition at line 161 of file Control.hxx.

## ◆ border_pause

bool PlayerControl::border_pause = false

If this flag is set, then the player will be auto-paused at the end of the song, before the next song starts to play.

This is a copy of the queue's "single" flag most of the time.

Definition at line 190 of file Control.hxx.

## ◆ buffer_chunks

const unsigned PlayerControl::buffer_chunks

Definition at line 105 of file Control.hxx.

## ◆ buffered_before_play

const unsigned PlayerControl::buffered_before_play

Definition at line 107 of file Control.hxx.

## ◆ client_cond

Cond PlayerControl::client_cond

This object gets signalled when the player thread has finished the command.

It wakes up the client that waits (i.e. the main thread).

Definition at line 134 of file Control.hxx.

## ◆ command

PlayerCommand PlayerControl::command = PlayerCommand::NONE

Definition at line 136 of file Control.hxx.

## ◆ cond

Cond PlayerControl::cond

Trigger this object after you have modified command.

Definition at line 127 of file Control.hxx.

## ◆ configured_audio_format

const AudioFormat PlayerControl::configured_audio_format

The "audio_output_format" setting.

Definition at line 112 of file Control.hxx.

## ◆ cross_fade

CrossFadeSettings PlayerControl::cross_fade

Definition at line 176 of file Control.hxx.

## ◆ elapsed_time

SongTime PlayerControl::elapsed_time

Definition at line 164 of file Control.hxx.

## ◆ error

std::exception_ptr PlayerControl::error

The error that occurred in the player thread.

This attribute is only valid if error_type is not PlayerError::NONE. The object must be freed when this object transitions back to PlayerError::NONE.

Definition at line 147 of file Control.hxx.

## ◆ error_type

PlayerError PlayerControl::error_type = PlayerError::NONE

Definition at line 139 of file Control.hxx.

## ◆ listener

PlayerListener& PlayerControl::listener

Definition at line 101 of file Control.hxx.

## ◆ mutex

Mutex PlayerControl::mutex
| mutable

This lock protects command, state, error, tagged_song.

Definition at line 122 of file Control.hxx.

## ◆ next_song

DetachedSong* PlayerControl::next_song = nullptr

The next queued song.

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

Definition at line 172 of file Control.hxx.

## ◆ outputs

MultipleOutputs& PlayerControl::outputs

Definition at line 103 of file Control.hxx.

## ◆ replay_gain_config

const ReplayGainConfig PlayerControl::replay_gain_config

Definition at line 178 of file Control.hxx.

## ◆ replay_gain_mode

ReplayGainMode PlayerControl::replay_gain_mode = ReplayGainMode::OFF

Definition at line 179 of file Control.hxx.

## ◆ seek_time

SongTime PlayerControl::seek_time

Definition at line 174 of file Control.hxx.

## ◆ state

PlayerState PlayerControl::state = PlayerState::STOP

Definition at line 137 of file Control.hxx.

## ◆ tagged_song

DetachedSong* PlayerControl::tagged_song = nullptr

A copy of the current DetachedSong after its tags have been updated by the decoder (for example, a radio stream that has sent a new tag after switching to the next song).

This shall be used by PlayerListener::OnPlayerTagModified() to update the current DetachedSong in the queue.

Protected by mutex. Set by the PlayerThread and consumed by the main thread.

Definition at line 159 of file Control.hxx.

## ◆ thread

Thread PlayerControl::thread

The handle of the player thread.

Definition at line 117 of file Control.hxx.

## ◆ total_play_time

double PlayerControl::total_play_time = 0

Definition at line 181 of file Control.hxx.

## ◆ total_time

SignedSongTime PlayerControl::total_time

Definition at line 163 of file Control.hxx.

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

- player/Control.hxx