From 54fc8f0e8c4ba5bf3eca799eab03201fea099d14 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 24 Dec 2014 22:13:50 +0100 Subject: output/Internal: convert audio_output_command to strictly-typed enum --- src/output/Init.cxx | 2 +- src/output/Internal.hxx | 32 ++++++++++++++++---------------- src/output/OutputControl.cxx | 26 ++++++++++++++------------ src/output/OutputThread.cxx | 36 ++++++++++++++++++------------------ 4 files changed, 49 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/output/Init.cxx b/src/output/Init.cxx index 04fc421f3..fac6bb45e 100644 --- a/src/output/Init.cxx +++ b/src/output/Init.cxx @@ -58,7 +58,7 @@ AudioOutput::AudioOutput(const AudioOutputPlugin &_plugin) filter(nullptr), replay_gain_filter(nullptr), other_replay_gain_filter(nullptr), - command(AO_COMMAND_NONE) + command(AudioOutputCommand::NONE) { assert(plugin.finish != nullptr); assert(plugin.open != nullptr); diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index 6e6ffb442..19772b08a 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -40,29 +40,29 @@ struct config_param; struct PlayerControl; struct AudioOutputPlugin; -enum audio_output_command { - AO_COMMAND_NONE = 0, - AO_COMMAND_ENABLE, - AO_COMMAND_DISABLE, - AO_COMMAND_OPEN, +enum class AudioOutputCommand { + NONE, + ENABLE, + DISABLE, + OPEN, /** * This command is invoked when the input audio format * changes. */ - AO_COMMAND_REOPEN, + REOPEN, - AO_COMMAND_CLOSE, - AO_COMMAND_PAUSE, + CLOSE, + PAUSE, /** * Drains the internal (hardware) buffers of the device. This * operation may take a while to complete. */ - AO_COMMAND_DRAIN, + DRAIN, - AO_COMMAND_CANCEL, - AO_COMMAND_KILL + CANCEL, + KILL }; struct AudioOutput { @@ -231,7 +231,7 @@ struct AudioOutput { /** * The next command to be performed by the output thread. */ - enum audio_output_command command; + AudioOutputCommand command; /** * The music pipe which provides music chunks to be played. @@ -284,7 +284,7 @@ struct AudioOutput { } bool IsCommandFinished() const { - return command == AO_COMMAND_NONE; + return command == AudioOutputCommand::NONE; } /** @@ -299,7 +299,7 @@ struct AudioOutput { * * Caller must lock the mutex. */ - void CommandAsync(audio_output_command cmd); + void CommandAsync(AudioOutputCommand cmd); /** * Sends a command to the #AudioOutput object and waits for @@ -307,13 +307,13 @@ struct AudioOutput { * * Caller must lock the mutex. */ - void CommandWait(audio_output_command cmd); + void CommandWait(AudioOutputCommand cmd); /** * Lock the #AudioOutput object and execute the command * synchronously. */ - void LockCommandWait(audio_output_command cmd); + void LockCommandWait(AudioOutputCommand cmd); /** * Enables the device. diff --git a/src/output/OutputControl.cxx b/src/output/OutputControl.cxx index 89428fa87..473f47bdf 100644 --- a/src/output/OutputControl.cxx +++ b/src/output/OutputControl.cxx @@ -46,7 +46,7 @@ AudioOutput::WaitForCommand() } void -AudioOutput::CommandAsync(audio_output_command cmd) +AudioOutput::CommandAsync(AudioOutputCommand cmd) { assert(IsCommandFinished()); @@ -55,14 +55,14 @@ AudioOutput::CommandAsync(audio_output_command cmd) } void -AudioOutput::CommandWait(audio_output_command cmd) +AudioOutput::CommandWait(AudioOutputCommand cmd) { CommandAsync(cmd); WaitForCommand(); } void -AudioOutput::LockCommandWait(audio_output_command cmd) +AudioOutput::LockCommandWait(AudioOutputCommand cmd) { const ScopeLock protect(mutex); CommandWait(cmd); @@ -92,7 +92,7 @@ AudioOutput::LockEnableWait() StartThread(); } - LockCommandWait(AO_COMMAND_ENABLE); + LockCommandWait(AudioOutputCommand::ENABLE); } void @@ -109,7 +109,7 @@ AudioOutput::LockDisableWait() return; } - LockCommandWait(AO_COMMAND_DISABLE); + LockCommandWait(AudioOutputCommand::DISABLE); } inline bool @@ -134,7 +134,7 @@ AudioOutput::Open(const AudioFormat audio_format, const MusicPipe &mp) /* we're not using audio_output_cancel() here, because that function is asynchronous */ - CommandWait(AO_COMMAND_CANCEL); + CommandWait(AudioOutputCommand::CANCEL); } return true; @@ -148,7 +148,9 @@ AudioOutput::Open(const AudioFormat audio_format, const MusicPipe &mp) if (!thread.IsDefined()) StartThread(); - CommandWait(open ? AO_COMMAND_REOPEN : AO_COMMAND_OPEN); + CommandWait(open + ? AudioOutputCommand::REOPEN + : AudioOutputCommand::OPEN); const bool open2 = open; if (open2 && mixer != nullptr) { @@ -172,7 +174,7 @@ AudioOutput::CloseWait() assert(!open || !fail_timer.IsDefined()); if (open) - CommandWait(AO_COMMAND_CLOSE); + CommandWait(AudioOutputCommand::CLOSE); else fail_timer.Reset(); } @@ -219,7 +221,7 @@ AudioOutput::LockPauseAsync() assert(allow_play); if (IsOpen()) - CommandAsync(AO_COMMAND_PAUSE); + CommandAsync(AudioOutputCommand::PAUSE); } void @@ -229,7 +231,7 @@ AudioOutput::LockDrainAsync() assert(allow_play); if (IsOpen()) - CommandAsync(AO_COMMAND_DRAIN); + CommandAsync(AudioOutputCommand::DRAIN); } void @@ -239,7 +241,7 @@ AudioOutput::LockCancelAsync() if (IsOpen()) { allow_play = false; - CommandAsync(AO_COMMAND_CANCEL); + CommandAsync(AudioOutputCommand::CANCEL); } } @@ -277,7 +279,7 @@ AudioOutput::StopThread() assert(thread.IsDefined()); assert(allow_play); - LockCommandWait(AO_COMMAND_KILL); + LockCommandWait(AudioOutputCommand::KILL); thread.Join(); } diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index 2ec0670c1..c946ca9aa 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -45,8 +45,8 @@ void AudioOutput::CommandFinished() { - assert(command != AO_COMMAND_NONE); - command = AO_COMMAND_NONE; + assert(command != AudioOutputCommand::NONE); + command = AudioOutputCommand::NONE; mutex.unlock(); audio_output_client_notify.Signal(); @@ -342,7 +342,7 @@ AudioOutput::WaitForDelay() (void)cond.timed_wait(mutex, delay); - if (command != AO_COMMAND_NONE) + if (command != AudioOutputCommand::NONE) return false; } } @@ -471,7 +471,7 @@ AudioOutput::PlayChunk(const MusicChunk *chunk) Error error; - while (!data.IsEmpty() && command == AO_COMMAND_NONE) { + while (!data.IsEmpty() && command == AudioOutputCommand::NONE) { if (!WaitForDelay()) break; @@ -529,7 +529,7 @@ AudioOutput::Play() assert(!in_playback_loop); in_playback_loop = true; - while (chunk != nullptr && command == AO_COMMAND_NONE) { + while (chunk != nullptr && command == AudioOutputCommand::NONE) { assert(!current_chunk_finished); current_chunk = chunk; @@ -577,7 +577,7 @@ AudioOutput::Pause() Close(false); break; } - } while (command == AO_COMMAND_NONE); + } while (command == AudioOutputCommand::NONE); pause = false; } @@ -594,30 +594,30 @@ AudioOutput::Task() while (1) { switch (command) { - case AO_COMMAND_NONE: + case AudioOutputCommand::NONE: break; - case AO_COMMAND_ENABLE: + case AudioOutputCommand::ENABLE: Enable(); CommandFinished(); break; - case AO_COMMAND_DISABLE: + case AudioOutputCommand::DISABLE: Disable(); CommandFinished(); break; - case AO_COMMAND_OPEN: + case AudioOutputCommand::OPEN: Open(); CommandFinished(); break; - case AO_COMMAND_REOPEN: + case AudioOutputCommand::REOPEN: Reopen(); CommandFinished(); break; - case AO_COMMAND_CLOSE: + case AudioOutputCommand::CLOSE: assert(open); assert(pipe != nullptr); @@ -625,7 +625,7 @@ AudioOutput::Task() CommandFinished(); break; - case AO_COMMAND_PAUSE: + case AudioOutputCommand::PAUSE: if (!open) { /* the output has failed after audio_output_all_pause() has @@ -642,7 +642,7 @@ AudioOutput::Task() the new command first */ continue; - case AO_COMMAND_DRAIN: + case AudioOutputCommand::DRAIN: if (open) { assert(current_chunk == nullptr); assert(pipe->Peek() == nullptr); @@ -655,7 +655,7 @@ AudioOutput::Task() CommandFinished(); continue; - case AO_COMMAND_CANCEL: + case AudioOutputCommand::CANCEL: current_chunk = nullptr; if (open) { @@ -667,7 +667,7 @@ AudioOutput::Task() CommandFinished(); continue; - case AO_COMMAND_KILL: + case AudioOutputCommand::KILL: current_chunk = nullptr; CommandFinished(); mutex.unlock(); @@ -679,7 +679,7 @@ AudioOutput::Task() chunks in the pipe */ continue; - if (command == AO_COMMAND_NONE) { + if (command == AudioOutputCommand::NONE) { woken_for_play = false; cond.wait(mutex); } @@ -696,7 +696,7 @@ AudioOutput::Task(void *arg) void AudioOutput::StartThread() { - assert(command == AO_COMMAND_NONE); + assert(command == AudioOutputCommand::NONE); Error error; if (!thread.Start(Task, this, error)) -- cgit v1.2.3