2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2008-09-09 10:02:34 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-09-09 10:02:34 +02:00
|
|
|
*/
|
|
|
|
|
2013-01-04 09:46:41 +01:00
|
|
|
#ifndef MPD_OUTPUT_CONTROL_HXX
|
|
|
|
#define MPD_OUTPUT_CONTROL_HXX
|
2008-09-09 10:02:34 +02:00
|
|
|
|
2017-05-23 00:03:06 +02:00
|
|
|
#include "Source.hxx"
|
2017-04-28 21:45:47 +02:00
|
|
|
#include "AudioFormat.hxx"
|
|
|
|
#include "thread/Thread.hxx"
|
2017-06-08 22:23:26 +02:00
|
|
|
#include "thread/Mutex.hxx"
|
2017-04-28 21:45:47 +02:00
|
|
|
#include "thread/Cond.hxx"
|
|
|
|
#include "system/PeriodClock.hxx"
|
2017-02-27 22:55:20 +01:00
|
|
|
#include "Compiler.h"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <exception>
|
2017-12-19 08:45:34 +01:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2017-02-27 22:55:20 +01:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
enum class ReplayGainMode : uint8_t;
|
2017-08-07 18:47:39 +02:00
|
|
|
struct FilteredAudioOutput;
|
2017-02-27 22:55:20 +01:00
|
|
|
struct MusicChunk;
|
2017-05-22 23:36:45 +02:00
|
|
|
struct ConfigBlock;
|
2017-02-27 22:55:20 +01:00
|
|
|
class MusicPipe;
|
|
|
|
class Mutex;
|
|
|
|
class Mixer;
|
|
|
|
class AudioOutputClient;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller for an #AudioOutput and its output thread.
|
|
|
|
*/
|
|
|
|
class AudioOutputControl {
|
2017-08-07 18:47:39 +02:00
|
|
|
FilteredAudioOutput *output;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-05-23 00:31:13 +02:00
|
|
|
/**
|
|
|
|
* The PlayerControl object which "owns" this output. This
|
|
|
|
* object is needed to signal command completion.
|
|
|
|
*/
|
|
|
|
AudioOutputClient &client;
|
|
|
|
|
2017-05-23 00:03:06 +02:00
|
|
|
/**
|
|
|
|
* Source of audio data.
|
|
|
|
*/
|
|
|
|
AudioOutputSource source;
|
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* The error that occurred in the output thread. It is
|
|
|
|
* cleared whenever the output is opened successfully.
|
|
|
|
*
|
|
|
|
* Protected by #mutex.
|
|
|
|
*/
|
|
|
|
std::exception_ptr last_error;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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").
|
|
|
|
*/
|
|
|
|
PeriodClock fail_timer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The thread handle, or nullptr if the output thread isn't
|
|
|
|
* running.
|
|
|
|
*/
|
|
|
|
Thread thread;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This condition object wakes up the output thread after
|
|
|
|
* #command has been set.
|
|
|
|
*/
|
|
|
|
Cond cond;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Additional data for #command. Protected by #mutex.
|
|
|
|
*/
|
|
|
|
struct Request {
|
|
|
|
/**
|
|
|
|
* The #AudioFormat requested by #Command::OPEN.
|
|
|
|
*/
|
|
|
|
AudioFormat audio_format;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The #MusicPipe passed to #Command::OPEN.
|
|
|
|
*/
|
|
|
|
const MusicPipe *pipe;
|
|
|
|
} request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The next command to be performed by the output thread.
|
|
|
|
*/
|
|
|
|
enum class Command {
|
|
|
|
NONE,
|
|
|
|
ENABLE,
|
|
|
|
DISABLE,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the output, or reopen it if it is already
|
|
|
|
* open, adjusting for input #AudioFormat changes.
|
|
|
|
*/
|
|
|
|
OPEN,
|
|
|
|
|
|
|
|
CLOSE,
|
|
|
|
PAUSE,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drains the internal (hardware) buffers of the device. This
|
|
|
|
* operation may take a while to complete.
|
|
|
|
*/
|
|
|
|
DRAIN,
|
|
|
|
|
|
|
|
CANCEL,
|
|
|
|
KILL
|
|
|
|
} command = Command::NONE;
|
|
|
|
|
2017-05-22 23:40:20 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
bool tags;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shall this output always play something (i.e. silence),
|
|
|
|
* even when playback is stopped?
|
|
|
|
*/
|
|
|
|
bool always_on;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Has the user enabled this device?
|
|
|
|
*/
|
|
|
|
bool enabled = true;
|
|
|
|
|
2017-06-08 09:49:30 +02:00
|
|
|
/**
|
|
|
|
* Is this device actually enabled, i.e. the "enable" method
|
|
|
|
* has succeeded?
|
|
|
|
*/
|
|
|
|
bool really_enabled = false;
|
|
|
|
|
2017-06-08 22:25:45 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
bool open = false;
|
|
|
|
|
2017-05-23 00:00:00 +02:00
|
|
|
/**
|
|
|
|
* Is the device paused? i.e. the output thread is in the
|
|
|
|
* ao_pause() loop.
|
|
|
|
*/
|
|
|
|
bool pause = false;
|
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
bool allow_play = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
bool in_playback_loop = 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.
|
|
|
|
*/
|
|
|
|
bool woken_for_play = false;
|
|
|
|
|
2017-05-23 10:58:30 +02:00
|
|
|
/**
|
|
|
|
* If this flag is set, then the next WaitForDelay() call is
|
|
|
|
* skipped. This is used to avoid delays after resuming
|
|
|
|
* playback.
|
|
|
|
*/
|
|
|
|
bool skip_delay;
|
|
|
|
|
2017-02-27 22:55:20 +01:00
|
|
|
public:
|
2017-06-08 22:23:26 +02:00
|
|
|
/**
|
|
|
|
* This mutex protects #open, #fail_timer, #pipe.
|
|
|
|
*/
|
|
|
|
mutable Mutex mutex;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-08-07 18:47:39 +02:00
|
|
|
AudioOutputControl(FilteredAudioOutput *_output,
|
|
|
|
AudioOutputClient &_client);
|
2017-02-27 22:55:20 +01:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
~AudioOutputControl() {
|
2017-04-28 21:45:47 +02:00
|
|
|
assert(!fail_timer.IsDefined());
|
|
|
|
assert(!thread.IsDefined());
|
2017-02-27 22:55:20 +01:00
|
|
|
assert(output == nullptr);
|
2017-06-08 22:25:45 +02:00
|
|
|
assert(!open);
|
2017-02-27 22:55:20 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
AudioOutputControl(const AudioOutputControl &) = delete;
|
|
|
|
AudioOutputControl &operator=(const AudioOutputControl &) = delete;
|
|
|
|
|
2017-05-22 23:36:45 +02:00
|
|
|
/**
|
|
|
|
* Throws #std::runtime_error on error.
|
|
|
|
*/
|
|
|
|
void Configure(const ConfigBlock &block);
|
|
|
|
|
2017-02-27 22:55:20 +01:00
|
|
|
gcc_pure
|
2017-05-23 00:17:23 +02:00
|
|
|
const char *GetName() const noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-12-19 10:36:32 +01:00
|
|
|
gcc_pure
|
|
|
|
const char *GetPluginName() const noexcept;
|
|
|
|
|
2017-08-08 14:02:58 +02:00
|
|
|
gcc_pure
|
|
|
|
const char *GetLogName() const noexcept;
|
|
|
|
|
2017-05-23 00:31:13 +02:00
|
|
|
AudioOutputClient &GetClient() noexcept {
|
|
|
|
return client;
|
|
|
|
}
|
2017-02-27 22:55:20 +01:00
|
|
|
|
|
|
|
gcc_pure
|
2017-05-23 00:17:23 +02:00
|
|
|
Mixer *GetMixer() const noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-05-22 23:40:20 +02:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
bool IsEnabled() const noexcept {
|
2017-05-22 23:40:20 +02:00
|
|
|
return enabled;
|
|
|
|
}
|
2017-02-27 22:55:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the value has been modified
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
bool LockSetEnabled(bool new_value) noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the new "enabled" value
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
bool LockToggleEnabled() noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-06-08 22:25:45 +02:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
bool IsOpen() const noexcept {
|
|
|
|
return open;
|
|
|
|
}
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
bool IsBusy() const noexcept {
|
2017-04-28 21:45:47 +02:00
|
|
|
return IsOpen() && !IsCommandFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
const std::exception_ptr &GetLastError() const noexcept {
|
2017-04-28 21:45:47 +02:00
|
|
|
return last_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartThread();
|
2017-02-27 22:55:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
bool IsCommandFinished() const noexcept {
|
2017-04-28 21:45:47 +02:00
|
|
|
return command == Command::NONE;
|
|
|
|
}
|
|
|
|
|
2017-05-23 00:17:23 +02:00
|
|
|
void CommandFinished() noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* Waits for command completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void WaitForCommand() noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* Sends a command, but does not wait for completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void CommandAsync(Command cmd) noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-07 18:47:39 +02:00
|
|
|
* Sends a command to the object and waits for completion.
|
2017-04-28 21:45:47 +02:00
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void CommandWait(Command cmd) noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
|
|
|
/**
|
2017-08-07 18:47:39 +02:00
|
|
|
* Lock the object and execute the command synchronously.
|
2017-04-28 21:45:47 +02:00
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void LockCommandWait(Command cmd) noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
2017-05-23 00:17:23 +02:00
|
|
|
void BeginDestroy() noexcept;
|
|
|
|
void FinishDestroy() noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-12-19 08:45:34 +01:00
|
|
|
const std::map<std::string, std::string> GetAttributes() const noexcept;
|
|
|
|
void SetAttribute(std::string &&name, std::string &&value);
|
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* Enables the device, but don't wait for completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
void EnableAsync();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables the device, but don't wait for completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void DisableAsync() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-02-27 22:55:20 +01:00
|
|
|
void EnableDisableAsync();
|
2017-05-23 00:17:23 +02:00
|
|
|
void LockPauseAsync() noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-05-23 00:17:23 +02:00
|
|
|
void CloseWait() noexcept;
|
|
|
|
void LockCloseWait() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the audio output, but if the "always_on" flag is set, put it
|
|
|
|
* into pause mode instead.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void LockRelease() noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-05-23 00:03:06 +02:00
|
|
|
void SetReplayGainMode(ReplayGainMode _mode) noexcept {
|
|
|
|
source.SetReplayGainMode(_mode);
|
|
|
|
}
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-06-08 22:25:45 +02:00
|
|
|
/**
|
2017-08-07 16:56:41 +02:00
|
|
|
* Caller must lock the mutex.
|
|
|
|
*
|
2017-06-08 22:25:45 +02:00
|
|
|
* Throws #std::runtime_error on error.
|
|
|
|
*/
|
|
|
|
void InternalOpen2(AudioFormat in_audio_format);
|
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
bool Open(AudioFormat audio_format, const MusicPipe &mp) noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
2017-02-27 22:55:20 +01:00
|
|
|
/**
|
|
|
|
* Opens or closes the device, depending on the "enabled"
|
|
|
|
* flag.
|
|
|
|
*
|
|
|
|
* @param force true to ignore the #fail_timer
|
|
|
|
* @return true if the device is open
|
|
|
|
*/
|
|
|
|
bool LockUpdate(const AudioFormat audio_format,
|
|
|
|
const MusicPipe &mp,
|
2017-05-23 00:17:23 +02:00
|
|
|
bool force) noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-05-23 00:03:06 +02:00
|
|
|
/**
|
|
|
|
* Did we already consumed this chunk?
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
bool IsChunkConsumed(const MusicChunk &chunk) const noexcept;
|
|
|
|
|
2017-02-27 22:55:20 +01:00
|
|
|
gcc_pure
|
2017-05-23 00:17:23 +02:00
|
|
|
bool LockIsChunkConsumed(const MusicChunk &chunk) const noexcept;
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-05-23 00:03:06 +02:00
|
|
|
void ClearTailChunk(const MusicChunk &chunk) {
|
|
|
|
source.ClearTailChunk(chunk);
|
|
|
|
}
|
2017-02-27 22:55:20 +01:00
|
|
|
|
2017-05-23 00:17:23 +02:00
|
|
|
void LockPlay() noexcept;
|
|
|
|
void LockDrainAsync() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the "allow_play" flag and send the "CANCEL" command
|
|
|
|
* asynchronously. To finish the operation, the caller has to
|
|
|
|
* call LockAllowPlay().
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void LockCancelAsync() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the "allow_play" and signal the thread.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void LockAllowPlay() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
|
|
|
private:
|
2018-01-02 17:15:59 +01:00
|
|
|
/**
|
|
|
|
* An error has occurred and this output is defunct.
|
|
|
|
*/
|
|
|
|
void Failure(std::exception_ptr e) noexcept {
|
|
|
|
last_error = e;
|
|
|
|
|
|
|
|
/* don't automatically reopen this device for 10
|
|
|
|
seconds */
|
|
|
|
fail_timer.Update();
|
|
|
|
}
|
|
|
|
|
2017-06-08 09:51:13 +02:00
|
|
|
/**
|
2017-08-07 16:56:41 +02:00
|
|
|
* Runs inside the OutputThread.
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
* Handles exceptions.
|
2017-06-08 09:51:13 +02:00
|
|
|
*
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
bool InternalEnable() noexcept;
|
|
|
|
|
2017-06-08 09:32:07 +02:00
|
|
|
/**
|
2017-08-07 16:56:41 +02:00
|
|
|
* Runs inside the OutputThread.
|
|
|
|
* Caller must lock the mutex.
|
2017-06-08 09:32:07 +02:00
|
|
|
*/
|
|
|
|
void InternalDisable() noexcept;
|
|
|
|
|
2017-05-23 00:08:36 +02:00
|
|
|
/**
|
2017-08-07 16:56:41 +02:00
|
|
|
* Runs inside the OutputThread.
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
* Handles exceptions.
|
2017-05-23 00:08:36 +02:00
|
|
|
*/
|
|
|
|
void InternalOpen(AudioFormat audio_format,
|
|
|
|
const MusicPipe &pipe) noexcept;
|
|
|
|
|
2017-08-07 17:35:43 +02:00
|
|
|
/**
|
|
|
|
* Runs inside the OutputThread.
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
void InternalCloseOutput(bool drain) noexcept;
|
|
|
|
|
2017-08-07 16:34:29 +02:00
|
|
|
/**
|
|
|
|
* Runs inside the OutputThread.
|
2017-08-07 16:56:41 +02:00
|
|
|
* Caller must lock the mutex.
|
2017-08-07 16:34:29 +02:00
|
|
|
*/
|
|
|
|
void InternalClose(bool drain) noexcept;
|
|
|
|
|
2018-01-02 17:15:10 +01:00
|
|
|
/**
|
|
|
|
* An error has occurred, and this output must be closed.
|
|
|
|
*/
|
|
|
|
void InternalCloseError(std::exception_ptr e) noexcept {
|
|
|
|
Failure(e);
|
|
|
|
InternalClose(false);
|
|
|
|
}
|
|
|
|
|
2017-06-08 21:59:48 +02:00
|
|
|
/**
|
|
|
|
* Runs inside the OutputThread.
|
2017-08-07 16:56:41 +02:00
|
|
|
* Caller must lock the mutex.
|
2017-06-08 21:59:48 +02:00
|
|
|
*/
|
2017-08-07 16:25:58 +02:00
|
|
|
void InternalCheckClose(bool drain) noexcept;
|
2017-06-08 21:59:48 +02:00
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* Wait until the output's delay reaches zero.
|
|
|
|
*
|
|
|
|
* @return true if playback should be continued, false if a
|
|
|
|
* command was issued
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
bool WaitForDelay() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
2017-08-07 16:56:41 +02:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-04-28 21:45:47 +02:00
|
|
|
bool FillSourceOrClose();
|
|
|
|
|
2017-08-07 16:56:41 +02:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
bool PlayChunk() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plays all remaining chunks, until the tail of the pipe has
|
|
|
|
* been reached (and no more chunks are queued), or until a
|
|
|
|
* command is received.
|
|
|
|
*
|
2017-08-07 16:56:41 +02:00
|
|
|
* Runs inside the OutputThread.
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
* Handles exceptions.
|
2017-05-23 10:59:16 +02:00
|
|
|
*
|
2017-04-28 21:45:47 +02:00
|
|
|
* @return true if at least one chunk has been available,
|
|
|
|
* false if the tail of the pipe was already reached
|
|
|
|
*/
|
2017-05-23 10:59:16 +02:00
|
|
|
bool InternalPlay() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
2017-05-23 10:59:16 +02:00
|
|
|
/**
|
2017-08-07 16:56:41 +02:00
|
|
|
* Runs inside the OutputThread.
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
* Handles exceptions.
|
2017-05-23 10:59:16 +02:00
|
|
|
*/
|
|
|
|
void InternalPause() noexcept;
|
2017-04-28 21:45:47 +02:00
|
|
|
|
2018-01-02 17:12:00 +01:00
|
|
|
/**
|
|
|
|
* Runs inside the OutputThread.
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
* Handles exceptions.
|
|
|
|
*/
|
|
|
|
void InternalDrain() noexcept;
|
|
|
|
|
2017-04-28 21:45:47 +02:00
|
|
|
/**
|
|
|
|
* The OutputThread.
|
|
|
|
*/
|
|
|
|
void Task();
|
2017-02-27 22:55:20 +01:00
|
|
|
};
|
2008-09-09 10:02:34 +02:00
|
|
|
|
|
|
|
#endif
|