From 3000b9dcdecb73081cfc7064c805041fb41082c6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 25 Nov 2016 13:54:55 +0100 Subject: [PATCH] filter/ReplayGain: add ReplayGainConfig copy Remove dependency on ReplayGain global variables. --- Makefile.am | 2 -- src/Main.cxx | 3 ++- src/filter/plugins/ReplayGainFilterPlugin.cxx | 21 +++++++++++----- src/filter/plugins/ReplayGainFilterPlugin.hxx | 3 ++- src/output/Init.cxx | 17 +++++++++---- src/output/Internal.hxx | 5 +++- src/output/MultipleOutputs.cxx | 16 +++++++++---- src/output/MultipleOutputs.hxx | 5 +++- test/FakeReplayGainGlobal.cxx | 24 ------------------- test/run_output.cxx | 3 ++- 10 files changed, 52 insertions(+), 47 deletions(-) delete mode 100644 test/FakeReplayGainGlobal.cxx diff --git a/Makefile.am b/Makefile.am index b35c63347..16dc760d0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1979,7 +1979,6 @@ test_run_filter_LDADD = \ libsystem.a \ libutil.a test_run_filter_SOURCES = test/run_filter.cxx \ - test/FakeReplayGainGlobal.cxx \ src/Log.cxx src/LogBackend.cxx \ src/filter/FilterPlugin.cxx src/filter/FilterRegistry.cxx @@ -2074,7 +2073,6 @@ test_run_output_LDADD = $(MPD_LIBS) \ libthread.a \ libutil.a test_run_output_SOURCES = test/run_output.cxx \ - test/FakeReplayGainGlobal.cxx \ test/ScopeIOThread.hxx \ src/Log.cxx src/LogBackend.cxx \ src/IOThread.cxx \ diff --git a/src/Main.cxx b/src/Main.cxx index e157f7c46..4c82ba63c 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -477,10 +477,11 @@ try { command_init(); initAudioConfig(); + replay_gain_global_init(); instance->partition->outputs.Configure(instance->event_loop, + replay_gain_config, instance->partition->pc); client_manager_init(); - replay_gain_global_init(); input_stream_global_init(); playlist_list_global_init(); diff --git a/src/filter/plugins/ReplayGainFilterPlugin.cxx b/src/filter/plugins/ReplayGainFilterPlugin.cxx index 2adc01bdc..5edbf10fc 100644 --- a/src/filter/plugins/ReplayGainFilterPlugin.cxx +++ b/src/filter/plugins/ReplayGainFilterPlugin.cxx @@ -22,7 +22,7 @@ #include "filter/FilterInternal.hxx" #include "AudioFormat.hxx" #include "ReplayGainInfo.hxx" -#include "ReplayGainGlobal.hxx" +#include "ReplayGainConfig.hxx" #include "mixer/MixerControl.hxx" #include "pcm/Volume.hxx" #include "util/ConstBuffer.hxx" @@ -36,6 +36,8 @@ static constexpr Domain replay_gain_domain("replay_gain"); class ReplayGainFilter final : public Filter { + const ReplayGainConfig config; + /** * If set, then this hardware mixer is used for applying * replay gain, instead of the software volume library. @@ -67,9 +69,11 @@ class ReplayGainFilter final : public Filter { PcmVolume pv; public: - ReplayGainFilter(const AudioFormat &audio_format, + ReplayGainFilter(const ReplayGainConfig &_config, + const AudioFormat &audio_format, Mixer *_mixer, unsigned _base) :Filter(audio_format), + config(_config), mixer(_mixer), base(_base) { info.Clear(); @@ -108,6 +112,8 @@ public: }; class PreparedReplayGainFilter final : public PreparedFilter { + const ReplayGainConfig config; + /** * If set, then this hardware mixer is used for applying * replay gain, instead of the software volume library. @@ -121,6 +127,9 @@ class PreparedReplayGainFilter final : public PreparedFilter { unsigned base; public: + explicit PreparedReplayGainFilter(const ReplayGainConfig _config) + :config(_config) {} + void SetMixer(Mixer *_mixer, unsigned _base) { assert(_mixer == nullptr || (_base > 0 && _base <= 100)); @@ -138,7 +147,7 @@ ReplayGainFilter::Update() unsigned volume = PCM_VOLUME_1; if (mode != ReplayGainMode::OFF) { const auto &tuple = info.Get(mode); - float scale = tuple.CalculateScale(replay_gain_config); + float scale = tuple.CalculateScale(config); FormatDebug(replay_gain_domain, "scale=%f\n", (double)scale); @@ -162,15 +171,15 @@ ReplayGainFilter::Update() } PreparedFilter * -NewReplayGainFilter() +NewReplayGainFilter(const ReplayGainConfig &config) { - return new PreparedReplayGainFilter(); + return new PreparedReplayGainFilter(config); } Filter * PreparedReplayGainFilter::Open(AudioFormat &af) { - return new ReplayGainFilter(af, mixer, base); + return new ReplayGainFilter(config, af, mixer, base); } ConstBuffer diff --git a/src/filter/plugins/ReplayGainFilterPlugin.hxx b/src/filter/plugins/ReplayGainFilterPlugin.hxx index e06c4232b..56ddaf768 100644 --- a/src/filter/plugins/ReplayGainFilterPlugin.hxx +++ b/src/filter/plugins/ReplayGainFilterPlugin.hxx @@ -25,10 +25,11 @@ class Filter; class PreparedFilter; class Mixer; +struct ReplayGainConfig; struct ReplayGainInfo; PreparedFilter * -NewReplayGainFilter(); +NewReplayGainFilter(const ReplayGainConfig &config); /** * Enables or disables the hardware mixer for applying replay gain. diff --git a/src/output/Init.cxx b/src/output/Init.cxx index 9edefa958..5efebb492 100644 --- a/src/output/Init.cxx +++ b/src/output/Init.cxx @@ -205,7 +205,9 @@ AudioOutput::Configure(const ConfigBlock &block) } static void -audio_output_setup(EventLoop &event_loop, AudioOutput &ao, +audio_output_setup(EventLoop &event_loop, + const ReplayGainConfig &replay_gain_config, + AudioOutput &ao, MixerListener &mixer_listener, const ConfigBlock &block) { @@ -216,12 +218,14 @@ audio_output_setup(EventLoop &event_loop, AudioOutput &ao, block.GetBlockValue("replay_gain_handler", "software"); if (strcmp(replay_gain_handler, "none") != 0) { - ao.prepared_replay_gain_filter = NewReplayGainFilter(); + ao.prepared_replay_gain_filter = + NewReplayGainFilter(replay_gain_config); assert(ao.prepared_replay_gain_filter != nullptr); ao.replay_gain_serial = 0; - ao.prepared_other_replay_gain_filter = NewReplayGainFilter(); + ao.prepared_other_replay_gain_filter = + NewReplayGainFilter(replay_gain_config); assert(ao.prepared_other_replay_gain_filter != nullptr); ao.other_replay_gain_serial = 0; @@ -267,7 +271,9 @@ audio_output_setup(EventLoop &event_loop, AudioOutput &ao, } AudioOutput * -audio_output_new(EventLoop &event_loop, const ConfigBlock &block, +audio_output_new(EventLoop &event_loop, + const ReplayGainConfig &replay_gain_config, + const ConfigBlock &block, MixerListener &mixer_listener, PlayerControl &pc) { @@ -298,7 +304,8 @@ audio_output_new(EventLoop &event_loop, const ConfigBlock &block, assert(ao != nullptr); try { - audio_output_setup(event_loop, *ao, mixer_listener, block); + audio_output_setup(event_loop, replay_gain_config, + *ao, mixer_listener, block); } catch (...) { ao_plugin_finish(ao); throw; diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index 393269690..9426886c9 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -40,6 +40,7 @@ struct MusicChunk; struct ConfigBlock; struct PlayerControl; struct AudioOutputPlugin; +struct ReplayGainConfig; struct AudioOutput { enum class Command { @@ -464,7 +465,9 @@ extern struct notify audio_output_client_notify; * Throws #std::runtime_error on error. */ AudioOutput * -audio_output_new(EventLoop &event_loop, const ConfigBlock &block, +audio_output_new(EventLoop &event_loop, + const ReplayGainConfig &replay_gain_config, + const ConfigBlock &block, MixerListener &mixer_listener, PlayerControl &pc); diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index b0f562af5..9758eb87e 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -50,10 +50,12 @@ MultipleOutputs::~MultipleOutputs() } static AudioOutput * -LoadOutput(EventLoop &event_loop, MixerListener &mixer_listener, +LoadOutput(EventLoop &event_loop, + const ReplayGainConfig &replay_gain_config, + MixerListener &mixer_listener, PlayerControl &pc, const ConfigBlock &block) try { - return audio_output_new(event_loop, block, + return audio_output_new(event_loop, replay_gain_config, block, mixer_listener, pc); } catch (const std::runtime_error &e) { @@ -65,11 +67,14 @@ try { } void -MultipleOutputs::Configure(EventLoop &event_loop, PlayerControl &pc) +MultipleOutputs::Configure(EventLoop &event_loop, + const ReplayGainConfig &replay_gain_config, + PlayerControl &pc) { for (const auto *param = config_get_block(ConfigBlockOption::AUDIO_OUTPUT); param != nullptr; param = param->next) { - auto output = LoadOutput(event_loop, mixer_listener, + auto output = LoadOutput(event_loop, replay_gain_config, + mixer_listener, pc, *param); if (FindByName(output->name) != nullptr) throw FormatRuntimeError("output devices with identical " @@ -81,7 +86,8 @@ MultipleOutputs::Configure(EventLoop &event_loop, PlayerControl &pc) if (outputs.empty()) { /* auto-detect device */ const ConfigBlock empty; - auto output = LoadOutput(event_loop, mixer_listener, + auto output = LoadOutput(event_loop, replay_gain_config, + mixer_listener, pc, empty); outputs.push_back(output); } diff --git a/src/output/MultipleOutputs.hxx b/src/output/MultipleOutputs.hxx index be2a33e09..3bde1c697 100644 --- a/src/output/MultipleOutputs.hxx +++ b/src/output/MultipleOutputs.hxx @@ -42,6 +42,7 @@ class MixerListener; struct MusicChunk; struct PlayerControl; struct AudioOutput; +struct ReplayGainConfig; class MultipleOutputs { MixerListener &mixer_listener; @@ -75,7 +76,9 @@ public: MultipleOutputs(MixerListener &_mixer_listener); ~MultipleOutputs(); - void Configure(EventLoop &event_loop, PlayerControl &pc); + void Configure(EventLoop &event_loop, + const ReplayGainConfig &replay_gain_config, + PlayerControl &pc); /** * Returns the total number of audio output devices, including diff --git a/test/FakeReplayGainGlobal.cxx b/test/FakeReplayGainGlobal.cxx deleted file mode 100644 index 9726d67a1..000000000 --- a/test/FakeReplayGainGlobal.cxx +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2003-2016 The Music Player Daemon Project - * http://www.musicpd.org - * - * 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. - * - * 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. - */ - -#include "config.h" -#include "ReplayGainGlobal.hxx" -#include "ReplayGainConfig.hxx" - -ReplayGainConfig replay_gain_config; diff --git a/test/run_output.cxx b/test/run_output.cxx index 545648a0d..5c09ca057 100644 --- a/test/run_output.cxx +++ b/test/run_output.cxx @@ -29,6 +29,7 @@ #include "ScopeIOThread.hxx" #include "fs/Path.hxx" #include "AudioParser.hxx" +#include "ReplayGainConfig.hxx" #include "pcm/PcmConvert.hxx" #include "filter/FilterRegistry.hxx" #include "player/Control.hxx" @@ -71,7 +72,7 @@ load_audio_output(EventLoop &event_loop, const char *name) *(MultipleOutputs *)nullptr, 32, 4); - return audio_output_new(event_loop, *param, + return audio_output_new(event_loop, ReplayGainConfig(), *param, *(MixerListener *)nullptr, dummy_player_control); }