decoder/Control: add attribute configured_audio_format

Obsoletes the same variable from AudioConfig.cxx.
This commit is contained in:
Max Kellermann 2016-12-03 14:12:08 +01:00
parent 3472208c05
commit 9fb7cc796b
13 changed files with 41 additions and 91 deletions

View File

@ -76,7 +76,6 @@ libmpd_a_SOURCES = \
src/open.h \
src/poison.h \
src/notify.cxx src/notify.hxx \
src/AudioConfig.cxx src/AudioConfig.hxx \
src/protocol/Ack.cxx src/protocol/Ack.hxx \
src/protocol/ArgParser.cxx src/protocol/ArgParser.hxx \
src/protocol/Result.cxx src/protocol/Result.hxx \

View File

@ -1,52 +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 "AudioConfig.hxx"
#include "AudioFormat.hxx"
#include "AudioParser.hxx"
#include "config/Param.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx"
#include "util/RuntimeError.hxx"
static AudioFormat configured_audio_format;
AudioFormat
getOutputAudioFormat(AudioFormat inAudioFormat)
{
AudioFormat out_audio_format = inAudioFormat;
out_audio_format.ApplyMask(configured_audio_format);
return out_audio_format;
}
void initAudioConfig(void)
{
const auto *param = config_get_param(ConfigOption::AUDIO_OUTPUT_FORMAT);
if (param == nullptr)
return;
try {
configured_audio_format = ParseAudioFormat(param->value.c_str(), true);
} catch (const std::runtime_error &) {
std::throw_with_nested(FormatRuntimeError("error parsing line %i",
param->line));
}
}

View File

@ -1,32 +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.
*/
#ifndef MPD_AUDIO_CONFIG_HXX
#define MPD_AUDIO_CONFIG_HXX
struct AudioFormat;
AudioFormat
getOutputAudioFormat(AudioFormat inFormat);
/* make sure initPlayerData is called before this function!! */
void
initAudioConfig();
#endif

View File

@ -45,7 +45,7 @@
#include "playlist/PlaylistRegistry.hxx"
#include "zeroconf/ZeroconfGlue.hxx"
#include "decoder/DecoderList.hxx"
#include "AudioConfig.hxx"
#include "AudioParser.hxx"
#include "pcm/PcmConvert.hxx"
#include "unix/SignalHandlers.hxx"
#include "system/FatalError.hxx"
@ -327,10 +327,23 @@ initialize_decoder_and_player(void)
config_get_positive(ConfigOption::MAX_PLAYLIST_LENGTH,
DEFAULT_PLAYLIST_MAX_LENGTH);
AudioFormat configured_audio_format = AudioFormat::Undefined();
param = config_get_param(ConfigOption::AUDIO_OUTPUT_FORMAT);
if (param != nullptr) {
try {
configured_audio_format = ParseAudioFormat(param->value.c_str(),
true);
} catch (const std::runtime_error &) {
std::throw_with_nested(FormatRuntimeError("error parsing line %i",
param->line));
}
}
instance->partition = new Partition(*instance,
max_length,
buffered_chunks,
buffered_before_play,
configured_audio_format,
replay_gain_config);
try {
@ -489,7 +502,6 @@ try {
glue_sticker_init();
command_init();
initAudioConfig();
instance->partition->outputs.Configure(instance->event_loop,
replay_gain_config,
instance->partition->pc);

View File

@ -28,13 +28,14 @@ Partition::Partition(Instance &_instance,
unsigned max_length,
unsigned buffer_chunks,
unsigned buffered_before_play,
AudioFormat configured_audio_format,
const ReplayGainConfig &replay_gain_config)
:instance(_instance),
global_events(instance.event_loop, BIND_THIS_METHOD(OnGlobalEvent)),
playlist(max_length, *this),
outputs(*this),
pc(*this, outputs, buffer_chunks, buffered_before_play,
replay_gain_config)
configured_audio_format, replay_gain_config)
{
UpdateEffectiveReplayGainMode();
}

View File

@ -59,6 +59,7 @@ struct Partition final : QueueListener, PlayerListener, MixerListener {
unsigned max_length,
unsigned buffer_chunks,
unsigned buffered_before_play,
AudioFormat configured_audio_format,
const ReplayGainConfig &replay_gain_config);
void EmitGlobalEvent(unsigned mask) {

View File

@ -29,7 +29,6 @@
#include "MusicChunk.hxx"
#include "pcm/PcmConvert.hxx"
#include "tag/Tag.hxx"
#include "AudioConfig.hxx"
#include "Log.hxx"
#include "input/InputStream.hxx"
#include "util/ConstBuffer.hxx"
@ -260,7 +259,8 @@ DecoderBridge::Ready(const AudioFormat audio_format,
assert(audio_format.IsValid());
dc.in_audio_format = audio_format;
dc.out_audio_format = getOutputAudioFormat(audio_format);
dc.out_audio_format = audio_format;
dc.out_audio_format.ApplyMask(dc.configured_audio_format);
dc.seekable = seekable;
dc.total_time = duration;

View File

@ -28,8 +28,10 @@
#include <assert.h>
DecoderControl::DecoderControl(Mutex &_mutex, Cond &_client_cond,
const AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config)
:mutex(_mutex), client_cond(_client_cond),
configured_audio_format(_configured_audio_format),
replay_gain_config(_replay_gain_config) {}
DecoderControl::~DecoderControl()

View File

@ -115,6 +115,11 @@ struct DecoderControl {
bool seekable;
SongTime seek_time;
/**
* The "audio_output_format" setting.
*/
const AudioFormat configured_audio_format;
/** the format of the song file */
AudioFormat in_audio_format;
@ -171,6 +176,7 @@ struct DecoderControl {
* @param _client_cond see #client_cond
*/
DecoderControl(Mutex &_mutex, Cond &_client_cond,
const AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config);
~DecoderControl();

View File

@ -30,10 +30,12 @@ PlayerControl::PlayerControl(PlayerListener &_listener,
MultipleOutputs &_outputs,
unsigned _buffer_chunks,
unsigned _buffered_before_play,
AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config)
:listener(_listener), outputs(_outputs),
buffer_chunks(_buffer_chunks),
buffered_before_play(_buffered_before_play),
configured_audio_format(_configured_audio_format),
replay_gain_config(_replay_gain_config)
{
}

View File

@ -105,6 +105,11 @@ struct PlayerControl {
const unsigned buffered_before_play;
/**
* The "audio_output_format" setting.
*/
const AudioFormat configured_audio_format;
/**
* The handle of the player thread.
*/
@ -187,6 +192,7 @@ struct PlayerControl {
MultipleOutputs &_outputs,
unsigned buffer_chunks,
unsigned buffered_before_play,
AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config);
~PlayerControl();

View File

@ -1163,7 +1163,9 @@ player_task(void *arg)
SetThreadName("player");
DecoderControl dc(pc.mutex, pc.cond, pc.replay_gain_config);
DecoderControl dc(pc.mutex, pc.cond,
pc.configured_audio_format,
pc.replay_gain_config);
decoder_thread_start(dc);
MusicBuffer buffer(pc.buffer_chunks);

View File

@ -54,10 +54,12 @@ PlayerControl::PlayerControl(PlayerListener &_listener,
MultipleOutputs &_outputs,
unsigned _buffer_chunks,
unsigned _buffered_before_play,
AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config)
:listener(_listener), outputs(_outputs),
buffer_chunks(_buffer_chunks),
buffered_before_play(_buffered_before_play),
configured_audio_format(_configured_audio_format),
replay_gain_config(_replay_gain_config) {}
PlayerControl::~PlayerControl() {}
@ -73,6 +75,7 @@ load_audio_output(EventLoop &event_loop, const char *name)
static struct PlayerControl dummy_player_control(*(PlayerListener *)nullptr,
*(MultipleOutputs *)nullptr,
32, 4,
AudioFormat::Undefined(),
ReplayGainConfig());
return audio_output_new(event_loop, ReplayGainConfig(), *param,