MPD: AudioOutput Struct Reference

MPD 0.20.18

Data Structures | Public Types | Public Member Functions | Data Fields
AudioOutput Struct Reference

`#include <Internal.hxx>`

Collaboration diagram for AudioOutput:
[legend]

## Data Structures
struct | Request
| Additional data for command. More...

## Public Types
enum | Command { Command::NONE, Command::ENABLE, Command::DISABLE, Command::OPEN, Command::CLOSE, Command::PAUSE, Command::DRAIN, Command::CANCEL, Command::KILL }

## Public Member Functions
| AudioOutput (const AudioOutputPlugin &_plugin, const ConfigBlock &block)
| Throws #std::runtime_error on error. More...
| ~AudioOutput ()
void | Setup (EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, MixerListener &mixer_listener, const ConfigBlock &block)
void | StartThread ()
void | StopThread ()
void | BeginDestroy ()
void | FinishDestroy ()
const char * | GetName () const
bool | IsEnabled () const
| Caller must lock the mutex. More...
bool | IsOpen () const
| Caller must lock the mutex. More...
bool | IsCommandFinished () const
| Caller must lock the mutex. More...
const std::exception_ptr & | GetLastError () const
| Caller must lock the mutex. More...
void | WaitForCommand ()
| Waits for command completion. More...
void | CommandAsync (Command cmd)
| Sends a command, but does not wait for completion. More...
void | CommandWait (Command cmd)
| Sends a command to the AudioOutput object and waits for completion. More...
void | LockCommandWait (Command cmd)
| Lock the AudioOutput object and execute the command synchronously. More...
void | EnableAsync ()
| Enables the device, but don't wait for completion. More...
void | DisableAsync ()
| Disables the device, but don't wait for completion. More...
void | EnableDisableAsync ()
| Attempt to enable or disable the device as specified by the enabled attribute; attempt to sync it with really_enabled (wrapper for EnableAsync() or DisableAsync()). More...
void | LockPauseAsync ()
void | CloseWait ()
| Same LockCloseWait(), but expects the lock to be held by the caller. More...
void | LockCloseWait ()
void | LockRelease ()
| Closes the audio output, but if the "always_on" flag is set, put it into pause mode instead. More...
void | SetReplayGainMode (ReplayGainMode _mode)
bool | Open (const AudioFormat audio_format, const MusicPipe &mp)
| Caller must lock the mutex. More...
bool | LockUpdate (const AudioFormat audio_format, const MusicPipe &mp, bool force)
| Opens or closes the device, depending on the "enabled" flag. More...
void | LockPlay ()
void | LockDrainAsync ()
void | LockCancelAsync ()
| Clear the "allow_play" flag and send the "CANCEL" command asynchronously. More...
void | LockAllowPlay ()
| Set the "allow_play" and signal the thread. More...
gcc_pure bool | IsChunkConsumed (const MusicChunk &chunk) const noexcept
| Did we already consumed this chunk? More...
gcc_pure bool | LockIsChunkConsumed (const MusicChunk &chunk) noexcept
void | ClearTailChunk (const MusicChunk &chunk)

## Data Fields
const char * | name
| The device's configured display name. More...
const AudioOutputPlugin & | plugin
| The plugin which implements this output device. More...
Mixer * | mixer = nullptr
| The mixer object associated with this audio output device. More...
bool | tags
| Will this output receive tags from the decoder? The default is true, but it may be configured to false to suppress sending tags to the output. More...
bool | always_on
| Shall this output always play something (i.e. More...
bool | enabled = true
| Has the user enabled this device? More...
bool | really_enabled = false
| Is this device actually enabled, i.e. More...
bool | open = false
| Is the device (already) open and functional? More...
bool | pause = false
| Is the device paused? i.e. More...
bool | allow_play = true
| When this flag is set, the output thread will not do any playback. More...
bool | in_playback_loop = false
| True while the OutputThread is inside ao_play(). More...
bool | woken_for_play = false
| Has the OutputThread been woken up to play more chunks? This is set by audio_output_play() and reset by ao_play() to reduce the number of duplicate wakeups. More...
PeriodClock | fail_timer
| If not nullptr, the device has failed, and this timer is used to estimate how long it should stay disabled (unless explicitly reopened with "play"). More...
AudioFormat | config_audio_format
| The configured audio format. More...
AudioFormat | filter_audio_format
| The AudioFormat which is emitted by the Filter, with config_audio_format already applied. More...
AudioFormat | out_audio_format
| The audio_format which is really sent to the device. More...
PreparedFilter * | prepared_filter = nullptr
| The filter object of this audio output. More...
FilterObserver | volume_filter
| The #VolumeFilter instance of this audio output. More...
PreparedFilter * | prepared_replay_gain_filter = nullptr
| The replay_gain_filter_plugin instance of this audio output. More...
PreparedFilter * | prepared_other_replay_gain_filter = nullptr
| The replay_gain_filter_plugin instance of this audio output, to be applied to the second chunk during cross-fading. More...
FilterObserver | convert_filter
| The convert_filter_plugin instance of this audio output. More...
Thread | thread
| The thread handle, or nullptr if the output thread isn't running. More...
Command | command = Command::NONE
| The next command to be performed by the output thread. More...
struct AudioOutput::Request | request
Mutex | mutex
| This mutex protects open, fail_timer, #pipe. More...
Cond | cond
| This condition object wakes up the output thread after command has been set. More...
AudioOutputClient * | client
| The PlayerControl object which "owns" this output. More...
AudioOutputSource | source
| Source of audio data. More...
std::exception_ptr | last_error
| The error that occurred in the output thread. More...

## Detailed Description

Definition at line 45 of file Internal.hxx.

## Member Enumeration Documentation

## ◆ Command

enum AudioOutput::Command
| strong

Enumerator
NONE |
ENABLE |
DISABLE |
OPEN | Open the output, or reopen it if it is already open, adjusting for input AudioFormat changes.
CLOSE |
PAUSE |
DRAIN | Drains the internal (hardware) buffers of the device. This operation may take a while to complete.
CANCEL |
KILL |

Definition at line 46 of file Internal.hxx.

## Constructor & Destructor Documentation

## ◆ AudioOutput()

AudioOutput::AudioOutput | ( | const AudioOutputPlugin & | _plugin,
|  | const ConfigBlock & | block
| ) |  |

Throws #std::runtime_error on error.

## ◆ ~AudioOutput()

AudioOutput::~AudioOutput | ( |  | ) |

## Member Function Documentation

## ◆ BeginDestroy()

void AudioOutput::BeginDestroy | ( |  | ) |

## ◆ ClearTailChunk()

void AudioOutput::ClearTailChunk | ( | const MusicChunk & | chunk | ) |
| inline

Definition at line 447 of file Internal.hxx.

## ◆ CloseWait()

void AudioOutput::CloseWait | ( |  | ) |

Same LockCloseWait(), but expects the lock to be held by the caller.

## ◆ CommandAsync()

void AudioOutput::CommandAsync | ( | Command | cmd | ) |

Sends a command, but does not wait for completion.

Caller must lock the mutex.

## ◆ CommandWait()

void AudioOutput::CommandWait | ( | Command | cmd | ) |

Sends a command to the AudioOutput object and waits for completion.

Caller must lock the mutex.

## ◆ DisableAsync()

void AudioOutput::DisableAsync | ( |  | ) |

Disables the device, but don't wait for completion.

Caller must lock the mutex.

## ◆ EnableAsync()

void AudioOutput::EnableAsync | ( |  | ) |

Enables the device, but don't wait for completion.

Caller must lock the mutex.

## ◆ EnableDisableAsync()

void AudioOutput::EnableDisableAsync | ( |  | ) |
| inline

Attempt to enable or disable the device as specified by the enabled attribute; attempt to sync it with really_enabled (wrapper for EnableAsync() or DisableAsync()).

Caller must lock the mutex.

Definition at line 372 of file Internal.hxx.

## ◆ FinishDestroy()

void AudioOutput::FinishDestroy | ( |  | ) |

## ◆ GetLastError()

const std::exception_ptr& AudioOutput::GetLastError | ( |  | ) | const
| inline

Caller must lock the mutex.

Definition at line 319 of file Internal.hxx.

## ◆ GetName()

const char* AudioOutput::GetName | ( |  | ) | const
| inline

Definition at line 291 of file Internal.hxx.

## ◆ IsChunkConsumed()

gcc_pure bool AudioOutput::IsChunkConsumed | ( | const MusicChunk & | chunk | ) | const
| noexcept

Did we already consumed this chunk?

Caller must lock the mutex.

## ◆ IsCommandFinished()

bool AudioOutput::IsCommandFinished | ( |  | ) | const
| inline

Caller must lock the mutex.

Definition at line 312 of file Internal.hxx.

## ◆ IsEnabled()

bool AudioOutput::IsEnabled | ( |  | ) | const
| inline

Caller must lock the mutex.

Definition at line 298 of file Internal.hxx.

## ◆ IsOpen()

bool AudioOutput::IsOpen | ( |  | ) | const
| inline

Caller must lock the mutex.

Definition at line 305 of file Internal.hxx.

## ◆ LockAllowPlay()

void AudioOutput::LockAllowPlay | ( |  | ) |

Set the "allow_play" and signal the thread.

## ◆ LockCancelAsync()

void AudioOutput::LockCancelAsync | ( |  | ) |

Clear the "allow_play" flag and send the "CANCEL" command asynchronously.

To finish the operation, the caller has to call LockAllowPlay().

## ◆ LockCloseWait()

void AudioOutput::LockCloseWait | ( |  | ) |

## ◆ LockCommandWait()

void AudioOutput::LockCommandWait | ( | Command | cmd | ) |

Lock the AudioOutput object and execute the command synchronously.

## ◆ LockDrainAsync()

void AudioOutput::LockDrainAsync | ( |  | ) |

## ◆ LockIsChunkConsumed()

gcc_pure bool AudioOutput::LockIsChunkConsumed | ( | const MusicChunk & | chunk | ) |
| inlinenoexcept

Definition at line 442 of file Internal.hxx.

## ◆ LockPauseAsync()

void AudioOutput::LockPauseAsync | ( |  | ) |

## ◆ LockPlay()

void AudioOutput::LockPlay | ( |  | ) |

## ◆ LockRelease()

void AudioOutput::LockRelease | ( |  | ) |

Closes the audio output, but if the "always_on" flag is set, put it into pause mode instead.

## ◆ LockUpdate()

bool AudioOutput::LockUpdate | ( | const AudioFormat | audio_format,
|  | const MusicPipe & | mp,
|  | bool | force
| ) |  |

Opens or closes the device, depending on the "enabled" flag.

Parameters

  force | true to ignore the fail_timer

Returns
  true if the device is open

## ◆ Open()

bool AudioOutput::Open | ( | const AudioFormat | audio_format,
|  | const MusicPipe & | mp
| ) |  |

Caller must lock the mutex.

## ◆ SetReplayGainMode()

void AudioOutput::SetReplayGainMode | ( | ReplayGainMode | _mode | ) |
| inline

Definition at line 397 of file Internal.hxx.

## ◆ Setup()

void AudioOutput::Setup | ( | EventLoop & | event_loop,
|  | const ReplayGainConfig & | replay_gain_config,
|  | MixerListener & | mixer_listener,
|  | const ConfigBlock & | block
| ) |  |

## ◆ StartThread()

void AudioOutput::StartThread | ( |  | ) |

## ◆ StopThread()

void AudioOutput::StopThread | ( |  | ) |

## ◆ WaitForCommand()

void AudioOutput::WaitForCommand | ( |  | ) |

Waits for command completion.

Caller must lock the mutex.

## Field Documentation

## ◆ allow_play

bool AudioOutput::allow_play = true

When this flag is set, the output thread will not do any playback.

It will wait until the flag is cleared.

This is used to synchronize the "clear" operation on the shared music pipe during the CANCEL command.

Definition at line 134 of file Internal.hxx.

## ◆ always_on

bool AudioOutput::always_on

Shall this output always play something (i.e.

silence), even when playback is stopped?

Definition at line 98 of file Internal.hxx.

## ◆ client

AudioOutputClient* AudioOutput::client

The PlayerControl object which "owns" this output.

This object is needed to signal command completion.

Definition at line 253 of file Internal.hxx.

## ◆ command

Command AudioOutput::command = Command::NONE

The next command to be performed by the output thread.

Definition at line 221 of file Internal.hxx.

## ◆ cond

Cond AudioOutput::cond

This condition object wakes up the output thread after command has been set.

Definition at line 247 of file Internal.hxx.

## ◆ config_audio_format

AudioFormat AudioOutput::config_audio_format

The configured audio format.

Definition at line 161 of file Internal.hxx.

## ◆ convert_filter

FilterObserver AudioOutput::convert_filter

The convert_filter_plugin instance of this audio output.

It is the last item in the filter chain, and is responsible for converting the input data into the appropriate format for this audio output.

Definition at line 210 of file Internal.hxx.

## ◆ enabled

bool AudioOutput::enabled = true

Has the user enabled this device?

Definition at line 103 of file Internal.hxx.

## ◆ fail_timer

PeriodClock AudioOutput::fail_timer

If not nullptr, the device has failed, and this timer is used to estimate how long it should stay disabled (unless explicitly reopened with "play").

Definition at line 156 of file Internal.hxx.

## ◆ filter_audio_format

AudioFormat AudioOutput::filter_audio_format

The AudioFormat which is emitted by the Filter, with config_audio_format already applied.

This is used to decide whether this object needs to be closed and reopened upon AudioFormat changes.

Definition at line 169 of file Internal.hxx.

## ◆ in_playback_loop

bool AudioOutput::in_playback_loop = false

True while the OutputThread is inside ao_play().

This means the PlayerThread does not need to wake up the OutputThread when new chunks are added to the MusicPipe, because the OutputThread is already watching that.

Definition at line 142 of file Internal.hxx.

## ◆ last_error

std::exception_ptr AudioOutput::last_error

The error that occurred in the output thread.

It is cleared whenever the output is opened successfully.

Protected by mutex.

Definition at line 266 of file Internal.hxx.

## ◆ mixer

Mixer* AudioOutput::mixer = nullptr

The mixer object associated with this audio output device.

May be nullptr if none is available, or if software volume is configured.

Definition at line 85 of file Internal.hxx.

## ◆ mutex

Mutex AudioOutput::mutex
| mutable

This mutex protects open, fail_timer, #pipe.

Definition at line 241 of file Internal.hxx.

## ◆ name

const char* AudioOutput::name

The device's configured display name.

Definition at line 73 of file Internal.hxx.

## ◆ open

bool AudioOutput::open = false

Is the device (already) open and functional?

This attribute may only be modified by the output thread. It is protected with mutex: write accesses inside the output thread and read accesses outside of it may only be performed while the lock is held.

Definition at line 119 of file Internal.hxx.

## ◆ out_audio_format

AudioFormat AudioOutput::out_audio_format

The audio_format which is really sent to the device.

This is basically config_audio_format (if configured) or in_audio_format, but may have been modified by plugin->open().

Definition at line 177 of file Internal.hxx.

## ◆ pause

bool AudioOutput::pause = false

Is the device paused? i.e.

the output thread is in the ao_pause() loop.

Definition at line 125 of file Internal.hxx.

## ◆ plugin

const AudioOutputPlugin& AudioOutput::plugin

The plugin which implements this output device.

Definition at line 78 of file Internal.hxx.

## ◆ prepared_filter

PreparedFilter* AudioOutput::prepared_filter = nullptr

The filter object of this audio output.

This is an instance of chain_filter_plugin.

Definition at line 183 of file Internal.hxx.

## ◆ prepared_other_replay_gain_filter

PreparedFilter* AudioOutput::prepared_other_replay_gain_filter = nullptr

The replay_gain_filter_plugin instance of this audio output, to be applied to the second chunk during cross-fading.

Definition at line 202 of file Internal.hxx.

## ◆ prepared_replay_gain_filter

PreparedFilter* AudioOutput::prepared_replay_gain_filter = nullptr

The replay_gain_filter_plugin instance of this audio output.

Definition at line 195 of file Internal.hxx.

## ◆ really_enabled

bool AudioOutput::really_enabled = false

Is this device actually enabled, i.e.

the "enable" method has succeeded?

Definition at line 109 of file Internal.hxx.

## ◆ request

struct AudioOutput::Request AudioOutput::request

## ◆ source

AudioOutputSource AudioOutput::source

Source of audio data.

Definition at line 258 of file Internal.hxx.

## ◆ tags

bool AudioOutput::tags

Will this output receive tags from the decoder? The default is true, but it may be configured to false to suppress sending tags to the output.

Definition at line 92 of file Internal.hxx.

## ◆ thread

Thread AudioOutput::thread

The thread handle, or nullptr if the output thread isn't running.

Definition at line 216 of file Internal.hxx.

## ◆ volume_filter

FilterObserver AudioOutput::volume_filter

The #VolumeFilter instance of this audio output.

It is used by the #SoftwareMixer.

Definition at line 189 of file Internal.hxx.

## ◆ woken_for_play

bool AudioOutput::woken_for_play = false

Has the OutputThread been woken up to play more chunks? This is set by audio_output_play() and reset by ao_play() to reduce the number of duplicate wakeups.

Definition at line 149 of file Internal.hxx.

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

- output/Internal.hxx