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-24 07:20:55 +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-24 07:20:55 +02:00
|
|
|
*/
|
|
|
|
|
2013-04-17 01:12:05 +02:00
|
|
|
#ifndef MPD_OUTPUT_INTERNAL_HXX
|
|
|
|
#define MPD_OUTPUT_INTERNAL_HXX
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2016-12-20 16:37:36 +01:00
|
|
|
#include "Source.hxx"
|
2016-12-12 15:24:38 +01:00
|
|
|
#include "SharedPipeConsumer.hxx"
|
2013-08-03 21:00:50 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2016-06-22 11:15:49 +02:00
|
|
|
#include "filter/Observer.hxx"
|
2013-04-17 01:19:25 +02:00
|
|
|
#include "thread/Mutex.hxx"
|
|
|
|
#include "thread/Cond.hxx"
|
2013-10-17 18:42:14 +02:00
|
|
|
#include "thread/Thread.hxx"
|
2013-11-24 20:20:57 +01:00
|
|
|
#include "system/PeriodClock.hxx"
|
2008-10-29 22:32:50 +01:00
|
|
|
|
2016-12-27 07:36:12 +01:00
|
|
|
#include <exception>
|
|
|
|
|
2016-06-22 11:15:49 +02:00
|
|
|
class PreparedFilter;
|
2013-09-26 21:51:45 +02:00
|
|
|
class MusicPipe;
|
2014-02-05 00:02:02 +01:00
|
|
|
class EventLoop;
|
2014-02-05 23:20:33 +01:00
|
|
|
class Mixer;
|
|
|
|
class MixerListener;
|
2016-12-14 12:14:57 +01:00
|
|
|
class AudioOutputClient;
|
2014-08-12 15:56:41 +02:00
|
|
|
struct MusicChunk;
|
2015-01-21 22:13:44 +01:00
|
|
|
struct ConfigBlock;
|
2014-01-28 11:22:27 +01:00
|
|
|
struct AudioOutputPlugin;
|
2016-11-25 13:54:55 +01:00
|
|
|
struct ReplayGainConfig;
|
2011-09-16 23:31:48 +02:00
|
|
|
|
2014-12-24 22:11:57 +01:00
|
|
|
struct AudioOutput {
|
|
|
|
enum class Command {
|
|
|
|
NONE,
|
|
|
|
ENABLE,
|
|
|
|
DISABLE,
|
2009-07-06 10:01:02 +02:00
|
|
|
|
2014-12-24 22:11:57 +01:00
|
|
|
/**
|
2016-12-13 20:07:00 +01:00
|
|
|
* Open the output, or reopen it if it is already
|
|
|
|
* open, adjusting for input #AudioFormat changes.
|
2014-12-24 22:11:57 +01:00
|
|
|
*/
|
2016-12-13 20:07:00 +01:00
|
|
|
OPEN,
|
2009-07-06 10:01:02 +02:00
|
|
|
|
2014-12-24 22:11:57 +01:00
|
|
|
CLOSE,
|
|
|
|
PAUSE,
|
2009-11-09 22:16:26 +01:00
|
|
|
|
2014-12-24 22:11:57 +01:00
|
|
|
/**
|
|
|
|
* Drains the internal (hardware) buffers of the device. This
|
|
|
|
* operation may take a while to complete.
|
|
|
|
*/
|
|
|
|
DRAIN,
|
2009-11-09 22:16:26 +01:00
|
|
|
|
2014-12-24 22:11:57 +01:00
|
|
|
CANCEL,
|
|
|
|
KILL
|
|
|
|
};
|
2009-02-16 00:43:12 +01:00
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* The device's configured display name.
|
|
|
|
*/
|
2008-09-24 07:20:55 +02:00
|
|
|
const char *name;
|
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* The plugin which implements this output device.
|
|
|
|
*/
|
2014-01-29 00:53:49 +01:00
|
|
|
const AudioOutputPlugin &plugin;
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2009-03-26 18:23:23 +01:00
|
|
|
/**
|
|
|
|
* The #mixer object associated with this audio output device.
|
2013-10-19 18:19:03 +02:00
|
|
|
* May be nullptr if none is available, or if software volume is
|
2009-03-26 18:23:23 +01:00
|
|
|
* configured.
|
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
Mixer *mixer = nullptr;
|
2009-03-26 18:23:23 +01:00
|
|
|
|
2012-09-25 23:28:53 +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;
|
|
|
|
|
2010-03-03 20:29:33 +01:00
|
|
|
/**
|
|
|
|
* Shall this output always play something (i.e. silence),
|
|
|
|
* even when playback is stopped?
|
|
|
|
*/
|
|
|
|
bool always_on;
|
|
|
|
|
2008-10-29 20:49:51 +01:00
|
|
|
/**
|
|
|
|
* Has the user enabled this device?
|
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
bool enabled = true;
|
2008-10-29 20:49:51 +01:00
|
|
|
|
2009-10-23 10:55:52 +02:00
|
|
|
/**
|
|
|
|
* Is this device actually enabled, i.e. the "enable" method
|
|
|
|
* has succeeded?
|
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
bool really_enabled = false;
|
2009-10-23 10:55:52 +02:00
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* Is the device (already) open and functional?
|
2009-03-25 17:07:15 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-09-24 07:21:46 +02:00
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
bool open = false;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
2009-08-14 11:52:12 +02:00
|
|
|
/**
|
|
|
|
* Is the device paused? i.e. the output thread is in the
|
|
|
|
* ao_pause() loop.
|
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
bool pause = false;
|
2009-08-14 11:52:12 +02:00
|
|
|
|
2011-09-01 07:13:21 +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.
|
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
bool allow_play = true;
|
2011-09-01 07:13:21 +02:00
|
|
|
|
2013-11-06 23:47:30 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
bool in_playback_loop = false;
|
2013-11-06 23:47:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
bool woken_for_play = false;
|
2013-11-06 23:47:30 +01:00
|
|
|
|
2008-10-29 22:32:50 +01:00
|
|
|
/**
|
2013-10-19 18:19:03 +02:00
|
|
|
* If not nullptr, the device has failed, and this timer is used
|
2009-02-28 20:43:23 +01:00
|
|
|
* to estimate how long it should stay disabled (unless
|
|
|
|
* explicitly reopened with "play").
|
2008-10-29 22:32:50 +01:00
|
|
|
*/
|
2013-11-24 20:20:57 +01:00
|
|
|
PeriodClock fail_timer;
|
2008-10-29 22:32:50 +01:00
|
|
|
|
2009-10-21 22:37:28 +02:00
|
|
|
/**
|
|
|
|
* The configured audio format.
|
|
|
|
*/
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat config_audio_format;
|
2009-10-21 22:37:28 +02:00
|
|
|
|
2016-12-24 14:05:11 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
AudioFormat filter_audio_format;
|
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* The audio_format which is really sent to the device. This
|
2009-02-10 21:50:51 +01:00
|
|
|
* is basically config_audio_format (if configured) or
|
|
|
|
* in_audio_format, but may have been modified by
|
2008-09-24 07:21:46 +02:00
|
|
|
* plugin->open().
|
|
|
|
*/
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat out_audio_format;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
2009-07-06 10:01:47 +02:00
|
|
|
/**
|
|
|
|
* The filter object of this audio output. This is an
|
|
|
|
* instance of chain_filter_plugin.
|
|
|
|
*/
|
2016-06-22 11:15:49 +02:00
|
|
|
PreparedFilter *prepared_filter = nullptr;
|
2009-07-06 10:01:47 +02:00
|
|
|
|
2016-07-01 18:23:53 +02:00
|
|
|
/**
|
|
|
|
* The #VolumeFilter instance of this audio output. It is
|
|
|
|
* used by the #SoftwareMixer.
|
|
|
|
*/
|
2016-06-22 11:15:49 +02:00
|
|
|
FilterObserver volume_filter;
|
2016-07-01 18:23:53 +02:00
|
|
|
|
2010-02-14 17:04:39 +01:00
|
|
|
/**
|
|
|
|
* The replay_gain_filter_plugin instance of this audio
|
|
|
|
* output.
|
|
|
|
*/
|
2016-06-22 11:15:49 +02:00
|
|
|
PreparedFilter *prepared_replay_gain_filter = nullptr;
|
2010-02-14 17:04:39 +01:00
|
|
|
|
2010-05-02 15:57:59 +02:00
|
|
|
/**
|
|
|
|
* The replay_gain_filter_plugin instance of this audio
|
|
|
|
* output, to be applied to the second chunk during
|
|
|
|
* cross-fading.
|
|
|
|
*/
|
2016-06-22 11:15:49 +02:00
|
|
|
PreparedFilter *prepared_other_replay_gain_filter = nullptr;
|
2010-05-02 15:57:59 +02:00
|
|
|
|
2009-07-06 10:01:47 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-06-22 11:15:49 +02:00
|
|
|
FilterObserver convert_filter;
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
2013-10-19 18:19:03 +02:00
|
|
|
* The thread handle, or nullptr if the output thread isn't
|
2008-09-24 07:21:46 +02:00
|
|
|
* running.
|
|
|
|
*/
|
2013-10-17 18:42:14 +02:00
|
|
|
Thread thread;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The next command to be performed by the output thread.
|
|
|
|
*/
|
2016-06-22 17:52:52 +02:00
|
|
|
Command command = Command::NONE;
|
2008-09-24 07:21:46 +02:00
|
|
|
|
2016-12-21 17:00:29 +01:00
|
|
|
/**
|
|
|
|
* Additional data for #command. Protected by #mutex.
|
|
|
|
*/
|
|
|
|
struct Request {
|
|
|
|
/**
|
|
|
|
* The #AudioFormat requested by #Command::OPEN.
|
|
|
|
*/
|
|
|
|
AudioFormat audio_format;
|
2016-12-20 23:19:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The #MusicPipe passed to #Command::OPEN.
|
|
|
|
*/
|
|
|
|
const MusicPipe *pipe;
|
2016-12-21 17:00:29 +01:00
|
|
|
} request;
|
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
2016-12-12 15:24:38 +01:00
|
|
|
* This mutex protects #open, #fail_timer, #pipe.
|
2009-03-09 19:25:26 +01:00
|
|
|
*/
|
2016-12-29 23:28:37 +01:00
|
|
|
mutable Mutex mutex;
|
2009-03-09 19:25:26 +01:00
|
|
|
|
2009-10-29 17:06:40 +01:00
|
|
|
/**
|
|
|
|
* This condition object wakes up the output thread after
|
|
|
|
* #command has been set.
|
|
|
|
*/
|
2013-04-17 01:19:25 +02:00
|
|
|
Cond cond;
|
2009-10-29 17:06:40 +01:00
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
/**
|
2013-10-28 10:12:21 +01:00
|
|
|
* The PlayerControl object which "owns" this output. This
|
2009-11-03 21:08:48 +01:00
|
|
|
* object is needed to signal command completion.
|
|
|
|
*/
|
2016-12-14 12:14:57 +01:00
|
|
|
AudioOutputClient *client;
|
2009-11-03 21:08:48 +01:00
|
|
|
|
2009-03-09 19:25:26 +01:00
|
|
|
/**
|
2016-12-20 16:37:36 +01:00
|
|
|
* Source of audio data.
|
2009-03-09 19:25:26 +01:00
|
|
|
*/
|
2016-12-20 16:37:36 +01:00
|
|
|
AudioOutputSource source;
|
2014-01-28 12:24:48 +01:00
|
|
|
|
2016-12-27 07:36:12 +01: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;
|
|
|
|
|
2016-10-28 22:41:07 +02:00
|
|
|
/**
|
|
|
|
* Throws #std::runtime_error on error.
|
|
|
|
*/
|
|
|
|
AudioOutput(const AudioOutputPlugin &_plugin,
|
|
|
|
const ConfigBlock &block);
|
|
|
|
|
2014-01-28 12:24:48 +01:00
|
|
|
~AudioOutput();
|
2014-01-28 11:39:12 +01:00
|
|
|
|
2016-11-09 12:04:54 +01:00
|
|
|
private:
|
2016-11-09 12:06:54 +01:00
|
|
|
void Configure(const ConfigBlock &block);
|
2014-01-28 11:39:12 +01:00
|
|
|
|
2016-11-09 12:04:54 +01:00
|
|
|
public:
|
2016-12-29 22:59:03 +01:00
|
|
|
void Setup(EventLoop &event_loop,
|
|
|
|
const ReplayGainConfig &replay_gain_config,
|
|
|
|
MixerListener &mixer_listener,
|
|
|
|
const ConfigBlock &block);
|
|
|
|
|
2014-01-28 11:39:12 +01:00
|
|
|
void StartThread();
|
|
|
|
void StopThread();
|
|
|
|
|
2016-12-14 08:15:33 +01:00
|
|
|
void BeginDestroy();
|
|
|
|
void FinishDestroy();
|
2014-01-28 11:39:12 +01:00
|
|
|
|
2016-12-29 23:23:28 +01:00
|
|
|
const char *GetName() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
bool IsEnabled() const {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2014-01-28 11:39:12 +01:00
|
|
|
bool IsOpen() const {
|
|
|
|
return open;
|
|
|
|
}
|
|
|
|
|
2016-12-29 23:23:28 +01:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2014-01-28 11:39:12 +01:00
|
|
|
bool IsCommandFinished() const {
|
2014-12-24 22:11:57 +01:00
|
|
|
return command == Command::NONE;
|
2014-01-28 11:39:12 +01:00
|
|
|
}
|
|
|
|
|
2017-04-18 23:15:46 +02:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
bool IsBusy() const {
|
|
|
|
return IsOpen() && !IsCommandFinished();
|
|
|
|
}
|
|
|
|
|
2016-12-29 23:23:28 +01:00
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
const std::exception_ptr &GetLastError() const {
|
|
|
|
return last_error;
|
|
|
|
}
|
|
|
|
|
2014-01-28 11:39:12 +01:00
|
|
|
/**
|
|
|
|
* Waits for command completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
void WaitForCommand();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a command, but does not wait for completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2014-12-24 22:11:57 +01:00
|
|
|
void CommandAsync(Command cmd);
|
2014-01-28 11:39:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a command to the #AudioOutput object and waits for
|
|
|
|
* completion.
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2014-12-24 22:11:57 +01:00
|
|
|
void CommandWait(Command cmd);
|
2014-01-28 11:39:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock the #AudioOutput object and execute the command
|
|
|
|
* synchronously.
|
|
|
|
*/
|
2014-12-24 22:11:57 +01:00
|
|
|
void LockCommandWait(Command cmd);
|
2014-01-28 11:39:12 +01:00
|
|
|
|
|
|
|
/**
|
2016-12-14 08:41:22 +01:00
|
|
|
* Enables the device, but don't wait for completion.
|
2016-12-14 07:54:05 +01:00
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
2014-01-28 11:39:12 +01:00
|
|
|
*/
|
2016-12-14 08:41:22 +01:00
|
|
|
void EnableAsync();
|
2014-01-28 11:39:12 +01:00
|
|
|
|
|
|
|
/**
|
2016-12-14 08:41:22 +01:00
|
|
|
* Disables the device, but don't wait for completion.
|
2016-12-14 07:54:05 +01:00
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
2014-01-28 11:39:12 +01:00
|
|
|
*/
|
2016-12-14 08:41:22 +01:00
|
|
|
void DisableAsync();
|
2014-01-28 11:39:12 +01:00
|
|
|
|
2016-12-14 08:00:43 +01:00
|
|
|
/**
|
|
|
|
* Attempt to enable or disable the device as specified by the
|
|
|
|
* #enabled attribute; attempt to sync it with #really_enabled
|
2016-12-14 08:41:22 +01:00
|
|
|
* (wrapper for EnableAsync() or DisableAsync()).
|
2016-12-14 08:00:43 +01:00
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
2016-12-14 08:41:22 +01:00
|
|
|
void EnableDisableAsync() {
|
2016-12-14 08:00:43 +01:00
|
|
|
if (enabled == really_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (enabled)
|
2016-12-14 08:41:22 +01:00
|
|
|
EnableAsync();
|
2016-12-14 08:00:43 +01:00
|
|
|
else
|
2016-12-14 08:41:22 +01:00
|
|
|
DisableAsync();
|
2016-12-14 08:00:43 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 11:39:12 +01:00
|
|
|
void LockPauseAsync();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Same LockCloseWait(), but expects the lock to be
|
|
|
|
* held by the caller.
|
|
|
|
*/
|
|
|
|
void CloseWait();
|
|
|
|
void LockCloseWait();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the audio output, but if the "always_on" flag is set, put it
|
|
|
|
* into pause mode instead.
|
|
|
|
*/
|
|
|
|
void LockRelease();
|
|
|
|
|
2016-06-22 11:15:49 +02:00
|
|
|
void SetReplayGainMode(ReplayGainMode _mode) {
|
2016-12-20 16:37:36 +01:00
|
|
|
source.SetReplayGainMode(_mode);
|
2016-06-22 11:15:49 +02:00
|
|
|
}
|
2014-01-28 11:39:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
bool Open(const AudioFormat audio_format, const MusicPipe &mp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens or closes the device, depending on the "enabled"
|
|
|
|
* flag.
|
|
|
|
*
|
2016-12-29 23:20:26 +01:00
|
|
|
* @param force true to ignore the #fail_timer
|
2014-01-28 11:39:12 +01:00
|
|
|
* @return true if the device is open
|
|
|
|
*/
|
|
|
|
bool LockUpdate(const AudioFormat audio_format,
|
2016-12-29 23:20:26 +01:00
|
|
|
const MusicPipe &mp,
|
|
|
|
bool force);
|
2014-01-28 11:39:12 +01:00
|
|
|
|
|
|
|
void LockPlay();
|
|
|
|
|
|
|
|
void LockDrainAsync();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the "allow_play" flag and send the "CANCEL" command
|
|
|
|
* asynchronously. To finish the operation, the caller has to
|
|
|
|
* call LockAllowPlay().
|
|
|
|
*/
|
|
|
|
void LockCancelAsync();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the "allow_play" and signal the thread.
|
|
|
|
*/
|
|
|
|
void LockAllowPlay();
|
2014-01-29 09:12:41 +01:00
|
|
|
|
2016-12-11 21:59:28 +01:00
|
|
|
/**
|
|
|
|
* Did we already consumed this chunk?
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
bool IsChunkConsumed(const MusicChunk &chunk) const;
|
|
|
|
|
|
|
|
gcc_pure
|
|
|
|
bool LockIsChunkConsumed(const MusicChunk &chunk) {
|
2017-01-03 07:11:57 +01:00
|
|
|
const std::lock_guard<Mutex> protect(mutex);
|
2016-12-11 21:59:28 +01:00
|
|
|
return IsChunkConsumed(chunk);
|
|
|
|
}
|
|
|
|
|
2016-12-22 14:46:59 +01:00
|
|
|
void ClearTailChunk(const MusicChunk &chunk) {
|
2016-12-20 16:37:36 +01:00
|
|
|
source.ClearTailChunk(chunk);
|
2016-12-22 14:46:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-29 09:12:41 +01:00
|
|
|
private:
|
|
|
|
void CommandFinished();
|
|
|
|
|
2016-12-27 14:55:56 +01:00
|
|
|
/**
|
|
|
|
* Throws #std::runtime_error on error.
|
|
|
|
*/
|
|
|
|
void Enable();
|
|
|
|
|
2014-01-29 09:12:41 +01:00
|
|
|
void Disable();
|
|
|
|
|
2016-12-27 14:55:56 +01:00
|
|
|
/**
|
|
|
|
* Throws #std::runtime_error on error.
|
|
|
|
*/
|
2014-01-29 09:12:41 +01:00
|
|
|
void Open();
|
2016-12-13 21:46:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke OutputPlugin::open() and configure the
|
|
|
|
* #ConvertFilter.
|
|
|
|
*
|
2016-12-27 14:55:56 +01:00
|
|
|
* Throws #std::runtime_error on error.
|
2016-12-13 21:46:27 +01:00
|
|
|
*
|
2016-12-27 14:55:56 +01:00
|
|
|
* Caller must not lock the mutex.
|
2016-12-13 21:46:27 +01:00
|
|
|
*/
|
2016-12-27 14:55:56 +01:00
|
|
|
void OpenOutputAndConvert(AudioFormat audio_format);
|
2016-12-13 21:46:27 +01:00
|
|
|
|
2014-01-29 09:12:41 +01:00
|
|
|
void Close(bool drain);
|
|
|
|
|
2014-10-23 23:24:01 +02:00
|
|
|
/**
|
|
|
|
* Close the output plugin.
|
|
|
|
*
|
|
|
|
* Mutex must not be locked.
|
|
|
|
*/
|
|
|
|
void CloseOutput(bool drain);
|
|
|
|
|
2014-10-24 00:28:58 +02:00
|
|
|
/**
|
|
|
|
* Mutex must not be locked.
|
|
|
|
*/
|
2014-01-29 09:12:41 +01:00
|
|
|
void CloseFilter();
|
2014-10-24 00:28:58 +02:00
|
|
|
|
2014-01-29 09:12:41 +01:00
|
|
|
/**
|
|
|
|
* Wait until the output's delay reaches zero.
|
|
|
|
*
|
|
|
|
* @return true if playback should be continued, false if a
|
|
|
|
* command was issued
|
|
|
|
*/
|
|
|
|
bool WaitForDelay();
|
|
|
|
|
2016-12-26 13:53:22 +01:00
|
|
|
bool FillSourceOrClose();
|
|
|
|
|
|
|
|
bool PlayChunk();
|
2014-01-29 09:12:41 +01: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.
|
|
|
|
*
|
|
|
|
* @return true if at least one chunk has been available,
|
|
|
|
* false if the tail of the pipe was already reached
|
|
|
|
*/
|
|
|
|
bool Play();
|
|
|
|
|
|
|
|
void Pause();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The OutputThread.
|
|
|
|
*/
|
|
|
|
void Task();
|
2008-09-24 07:20:55 +02:00
|
|
|
};
|
|
|
|
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* Notify object used by the thread's client, i.e. we will send a
|
|
|
|
* notify signal to this object, expecting the caller to wait on it.
|
|
|
|
*/
|
2008-09-24 07:20:55 +02:00
|
|
|
extern struct notify audio_output_client_notify;
|
|
|
|
|
2016-10-28 21:11:52 +02:00
|
|
|
/**
|
|
|
|
* Throws #std::runtime_error on error.
|
|
|
|
*/
|
2014-01-28 11:34:09 +01:00
|
|
|
AudioOutput *
|
2016-11-25 13:54:55 +01:00
|
|
|
audio_output_new(EventLoop &event_loop,
|
|
|
|
const ReplayGainConfig &replay_gain_config,
|
|
|
|
const ConfigBlock &block,
|
2014-02-05 23:20:33 +01:00
|
|
|
MixerListener &mixer_listener,
|
2016-12-14 12:14:57 +01:00
|
|
|
AudioOutputClient &client);
|
2011-09-16 23:31:48 +02:00
|
|
|
|
2011-08-30 22:28:15 +02:00
|
|
|
void
|
2014-01-28 11:34:09 +01:00
|
|
|
audio_output_free(AudioOutput *ao);
|
2011-08-30 22:28:15 +02:00
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
#endif
|