2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 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
|
|
|
*/
|
|
|
|
|
2017-08-07 21:50:13 +02:00
|
|
|
#ifndef MPD_FILTERED_AUDIO_OUTPUT_HXX
|
|
|
|
#define MPD_FILTERED_AUDIO_OUTPUT_HXX
|
2008-09-24 07:20:55 +02:00
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2016-06-22 11:15:49 +02:00
|
|
|
#include "filter/Observer.hxx"
|
2016-12-27 07:36:12 +01:00
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
#include <memory>
|
2017-08-08 14:02:58 +02:00
|
|
|
#include <string>
|
2017-12-19 08:45:34 +01:00
|
|
|
#include <map>
|
2017-08-08 14:27:19 +02:00
|
|
|
#include <chrono>
|
2017-08-08 14:02:58 +02:00
|
|
|
|
2018-08-18 20:57:02 +02:00
|
|
|
class FilterFactory;
|
2016-06-22 11:15:49 +02:00
|
|
|
class PreparedFilter;
|
2014-02-05 00:02:02 +01:00
|
|
|
class EventLoop;
|
2014-02-05 23:20:33 +01:00
|
|
|
class Mixer;
|
|
|
|
class MixerListener;
|
2017-08-09 16:58:44 +02:00
|
|
|
struct MixerPlugin;
|
2015-01-21 22:13:44 +01:00
|
|
|
struct ConfigBlock;
|
2017-08-09 16:58:59 +02:00
|
|
|
class AudioOutput;
|
2018-08-19 07:43:47 +02:00
|
|
|
struct AudioOutputDefaults;
|
2016-11-25 13:54:55 +01:00
|
|
|
struct ReplayGainConfig;
|
2017-08-08 14:27:19 +02:00
|
|
|
struct Tag;
|
2011-09-16 23:31:48 +02:00
|
|
|
|
2017-08-07 18:47:39 +02:00
|
|
|
struct FilteredAudioOutput {
|
2017-08-09 16:58:44 +02:00
|
|
|
const char *const plugin_name;
|
|
|
|
|
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;
|
|
|
|
|
2017-08-08 14:02:58 +02:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* A string describing this devicee in log messages. It is
|
|
|
|
* usually in the form "NAME (PLUGIN)".
|
|
|
|
*/
|
|
|
|
std::string log_name;
|
|
|
|
|
|
|
|
public:
|
2008-09-24 07:21:46 +02:00
|
|
|
/**
|
|
|
|
* The plugin which implements this output device.
|
|
|
|
*/
|
2017-08-09 16:58:44 +02:00
|
|
|
std::unique_ptr<AudioOutput> output;
|
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
|
|
|
|
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.
|
|
|
|
*/
|
2017-12-27 09:17:15 +01:00
|
|
|
std::unique_ptr<PreparedFilter> prepared_filter;
|
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.
|
|
|
|
*/
|
2017-12-27 09:17:15 +01:00
|
|
|
std::unique_ptr<PreparedFilter> prepared_replay_gain_filter;
|
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.
|
|
|
|
*/
|
2017-12-27 09:17:15 +01:00
|
|
|
std::unique_ptr<PreparedFilter> prepared_other_replay_gain_filter;
|
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
|
|
|
|
2016-10-28 22:41:07 +02:00
|
|
|
/**
|
2019-07-03 22:10:26 +02:00
|
|
|
* Throws on error.
|
2016-10-28 22:41:07 +02:00
|
|
|
*/
|
2017-08-09 16:58:44 +02:00
|
|
|
FilteredAudioOutput(const char *_plugin_name,
|
|
|
|
std::unique_ptr<AudioOutput> &&_output,
|
2018-08-18 20:57:02 +02:00
|
|
|
const ConfigBlock &block,
|
2018-08-19 07:43:47 +02:00
|
|
|
const AudioOutputDefaults &defaults,
|
2018-08-18 20:57:02 +02:00
|
|
|
FilterFactory *filter_factory);
|
2016-10-28 22:41:07 +02:00
|
|
|
|
2017-08-07 18:47:39 +02:00
|
|
|
~FilteredAudioOutput();
|
2014-01-28 11:39:12 +01:00
|
|
|
|
2016-11-09 12:04:54 +01:00
|
|
|
private:
|
2018-08-18 20:57:02 +02:00
|
|
|
void Configure(const ConfigBlock &block,
|
2018-08-19 07:43:47 +02:00
|
|
|
const AudioOutputDefaults &defaults,
|
2018-08-18 20:57:02 +02:00
|
|
|
FilterFactory *filter_factory);
|
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,
|
2017-08-09 16:58:44 +02:00
|
|
|
const MixerPlugin *mixer_plugin,
|
2016-12-29 22:59:03 +01:00
|
|
|
MixerListener &mixer_listener,
|
2018-08-19 07:43:47 +02:00
|
|
|
const ConfigBlock &block,
|
|
|
|
const AudioOutputDefaults &defaults);
|
2016-12-29 22:59:03 +01:00
|
|
|
|
2016-12-29 23:23:28 +01:00
|
|
|
const char *GetName() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2017-12-19 10:36:32 +01:00
|
|
|
const char *GetPluginName() const noexcept {
|
|
|
|
return plugin_name;
|
|
|
|
}
|
|
|
|
|
2017-08-08 14:02:58 +02:00
|
|
|
const char *GetLogName() const noexcept {
|
|
|
|
return log_name.c_str();
|
|
|
|
}
|
|
|
|
|
2017-08-08 15:54:49 +02:00
|
|
|
/**
|
|
|
|
* Does the plugin support enabling/disabling a device?
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
bool SupportsEnableDisable() const noexcept;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the plugin support pausing a device?
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
bool SupportsPause() const noexcept;
|
|
|
|
|
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);
|
|
|
|
|
2016-12-27 14:55:56 +01:00
|
|
|
/**
|
2019-07-03 22:10:26 +02:00
|
|
|
* Throws on error.
|
2016-12-27 14:55:56 +01:00
|
|
|
*/
|
|
|
|
void Enable();
|
|
|
|
|
2017-05-23 00:17:23 +02:00
|
|
|
void Disable() noexcept;
|
2014-01-29 09:12:41 +01:00
|
|
|
|
2017-08-07 16:25:23 +02:00
|
|
|
/**
|
|
|
|
* Invoke OutputPlugin::close().
|
|
|
|
*
|
|
|
|
* Caller must not lock the mutex.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void Close(bool drain) noexcept;
|
2016-12-13 21:46:27 +01:00
|
|
|
|
2017-08-07 18:39:12 +02:00
|
|
|
void ConfigureConvertFilter();
|
|
|
|
|
2016-12-13 21:46:27 +01:00
|
|
|
/**
|
|
|
|
* Invoke OutputPlugin::open() and configure the
|
|
|
|
* #ConvertFilter.
|
|
|
|
*
|
2019-07-03 22:10:26 +02:00
|
|
|
* Throws 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-10-23 23:24:01 +02:00
|
|
|
/**
|
|
|
|
* Close the output plugin.
|
|
|
|
*
|
|
|
|
* Mutex must not be locked.
|
|
|
|
*/
|
2017-05-23 00:17:23 +02:00
|
|
|
void CloseOutput(bool drain) noexcept;
|
2014-10-23 23:24:01 +02:00
|
|
|
|
2017-08-07 18:33:07 +02:00
|
|
|
/**
|
|
|
|
* Mutex must not be locked.
|
|
|
|
*/
|
|
|
|
void OpenSoftwareMixer() noexcept;
|
|
|
|
|
2014-10-24 00:28:58 +02:00
|
|
|
/**
|
|
|
|
* Mutex must not be locked.
|
|
|
|
*/
|
2017-08-07 18:32:43 +02:00
|
|
|
void CloseSoftwareMixer() noexcept;
|
2014-10-24 00:28:58 +02:00
|
|
|
|
2017-08-08 14:27:19 +02:00
|
|
|
gcc_pure
|
|
|
|
std::chrono::steady_clock::duration Delay() noexcept;
|
|
|
|
|
|
|
|
void SendTag(const Tag &tag);
|
|
|
|
|
|
|
|
size_t Play(const void *data, size_t size);
|
|
|
|
|
|
|
|
void Drain();
|
|
|
|
void Cancel() noexcept;
|
|
|
|
|
2017-05-23 00:17:23 +02:00
|
|
|
void BeginPause() noexcept;
|
|
|
|
bool IteratePause() noexcept;
|
2017-04-28 22:01:20 +02:00
|
|
|
|
2017-05-23 00:17:23 +02:00
|
|
|
void EndPause() noexcept{
|
2017-04-28 21:45:47 +02:00
|
|
|
}
|
2008-09-24 07:20:55 +02:00
|
|
|
};
|
|
|
|
|
2016-10-28 21:11:52 +02:00
|
|
|
/**
|
2019-07-03 22:10:26 +02:00
|
|
|
* Throws on error.
|
2016-10-28 21:11:52 +02:00
|
|
|
*/
|
2018-01-04 10:14:26 +01:00
|
|
|
std::unique_ptr<FilteredAudioOutput>
|
2016-11-25 13:54:55 +01:00
|
|
|
audio_output_new(EventLoop &event_loop,
|
|
|
|
const ReplayGainConfig &replay_gain_config,
|
|
|
|
const ConfigBlock &block,
|
2018-08-19 07:43:47 +02:00
|
|
|
const AudioOutputDefaults &defaults,
|
2018-08-18 20:57:02 +02:00
|
|
|
FilterFactory *filter_factory,
|
2017-05-23 00:31:13 +02:00
|
|
|
MixerListener &mixer_listener);
|
2011-09-16 23:31:48 +02:00
|
|
|
|
2008-09-24 07:20:55 +02:00
|
|
|
#endif
|