output/Client: new interface to replace direct access to class PlayerControl
This commit is contained in:
parent
d2e47e014a
commit
ccb45b6f6e
47
src/output/Client.hxx
Normal file
47
src/output/Client.hxx
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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_OUTPUT_CLIENT_HXX
|
||||||
|
#define MPD_OUTPUT_CLIENT_HXX
|
||||||
|
|
||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface between the #AudioOutput and the #Player.
|
||||||
|
*/
|
||||||
|
class AudioOutputClient {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Notify the client that we have consumed a few chunks. This
|
||||||
|
* is called from within the output thread. The client may
|
||||||
|
* perform actions to refill the #MusicPipe.
|
||||||
|
*/
|
||||||
|
virtual void ChunksConsumed() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The #AudioOutput has modified the "enabled" flag, and the
|
||||||
|
* client shall make the #AudioOutput apply this new setting.
|
||||||
|
* This is called from any thread, one which can't send an
|
||||||
|
* AudioOutput::Command to the output thread; only the client
|
||||||
|
* can do that safely.
|
||||||
|
*/
|
||||||
|
virtual void ApplyEnabled() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -275,7 +275,7 @@ audio_output_new(EventLoop &event_loop,
|
|||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
const ConfigBlock &block,
|
const ConfigBlock &block,
|
||||||
MixerListener &mixer_listener,
|
MixerListener &mixer_listener,
|
||||||
PlayerControl &pc)
|
AudioOutputClient &client)
|
||||||
{
|
{
|
||||||
const AudioOutputPlugin *plugin;
|
const AudioOutputPlugin *plugin;
|
||||||
|
|
||||||
@ -311,6 +311,6 @@ audio_output_new(EventLoop &event_loop,
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
ao->player_control = &pc;
|
ao->client = &client;
|
||||||
return ao;
|
return ao;
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ class MusicPipe;
|
|||||||
class EventLoop;
|
class EventLoop;
|
||||||
class Mixer;
|
class Mixer;
|
||||||
class MixerListener;
|
class MixerListener;
|
||||||
|
class AudioOutputClient;
|
||||||
struct MusicChunk;
|
struct MusicChunk;
|
||||||
struct ConfigBlock;
|
struct ConfigBlock;
|
||||||
struct PlayerControl;
|
|
||||||
struct AudioOutputPlugin;
|
struct AudioOutputPlugin;
|
||||||
struct ReplayGainConfig;
|
struct ReplayGainConfig;
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ struct AudioOutput {
|
|||||||
* The PlayerControl object which "owns" this output. This
|
* The PlayerControl object which "owns" this output. This
|
||||||
* object is needed to signal command completion.
|
* object is needed to signal command completion.
|
||||||
*/
|
*/
|
||||||
PlayerControl *player_control;
|
AudioOutputClient *client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A reference to the #MusicPipe and the current position.
|
* A reference to the #MusicPipe and the current position.
|
||||||
@ -510,7 +510,7 @@ audio_output_new(EventLoop &event_loop,
|
|||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
const ConfigBlock &block,
|
const ConfigBlock &block,
|
||||||
MixerListener &mixer_listener,
|
MixerListener &mixer_listener,
|
||||||
PlayerControl &pc);
|
AudioOutputClient &client);
|
||||||
|
|
||||||
void
|
void
|
||||||
audio_output_free(AudioOutput *ao);
|
audio_output_free(AudioOutput *ao);
|
||||||
|
@ -53,11 +53,11 @@ static AudioOutput *
|
|||||||
LoadOutput(EventLoop &event_loop,
|
LoadOutput(EventLoop &event_loop,
|
||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
MixerListener &mixer_listener,
|
MixerListener &mixer_listener,
|
||||||
PlayerControl &pc, const ConfigBlock &block)
|
AudioOutputClient &client, const ConfigBlock &block)
|
||||||
try {
|
try {
|
||||||
return audio_output_new(event_loop, replay_gain_config, block,
|
return audio_output_new(event_loop, replay_gain_config, block,
|
||||||
mixer_listener,
|
mixer_listener,
|
||||||
pc);
|
client);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
if (block.line > 0)
|
if (block.line > 0)
|
||||||
std::throw_with_nested(FormatRuntimeError("Failed to configure output in line %i",
|
std::throw_with_nested(FormatRuntimeError("Failed to configure output in line %i",
|
||||||
@ -69,13 +69,13 @@ try {
|
|||||||
void
|
void
|
||||||
MultipleOutputs::Configure(EventLoop &event_loop,
|
MultipleOutputs::Configure(EventLoop &event_loop,
|
||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
PlayerControl &pc)
|
AudioOutputClient &client)
|
||||||
{
|
{
|
||||||
for (const auto *param = config_get_block(ConfigBlockOption::AUDIO_OUTPUT);
|
for (const auto *param = config_get_block(ConfigBlockOption::AUDIO_OUTPUT);
|
||||||
param != nullptr; param = param->next) {
|
param != nullptr; param = param->next) {
|
||||||
auto output = LoadOutput(event_loop, replay_gain_config,
|
auto output = LoadOutput(event_loop, replay_gain_config,
|
||||||
mixer_listener,
|
mixer_listener,
|
||||||
pc, *param);
|
client, *param);
|
||||||
if (FindByName(output->name) != nullptr)
|
if (FindByName(output->name) != nullptr)
|
||||||
throw FormatRuntimeError("output devices with identical "
|
throw FormatRuntimeError("output devices with identical "
|
||||||
"names: %s", output->name);
|
"names: %s", output->name);
|
||||||
@ -88,7 +88,7 @@ MultipleOutputs::Configure(EventLoop &event_loop,
|
|||||||
const ConfigBlock empty;
|
const ConfigBlock empty;
|
||||||
auto output = LoadOutput(event_loop, replay_gain_config,
|
auto output = LoadOutput(event_loop, replay_gain_config,
|
||||||
mixer_listener,
|
mixer_listener,
|
||||||
pc, empty);
|
client, empty);
|
||||||
outputs.push_back(output);
|
outputs.push_back(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ class MusicBuffer;
|
|||||||
class MusicPipe;
|
class MusicPipe;
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
class MixerListener;
|
class MixerListener;
|
||||||
|
class AudioOutputClient;
|
||||||
struct MusicChunk;
|
struct MusicChunk;
|
||||||
struct PlayerControl;
|
|
||||||
struct AudioOutput;
|
struct AudioOutput;
|
||||||
struct ReplayGainConfig;
|
struct ReplayGainConfig;
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ public:
|
|||||||
|
|
||||||
void Configure(EventLoop &event_loop,
|
void Configure(EventLoop &event_loop,
|
||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
PlayerControl &pc);
|
AudioOutputClient &client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the total number of audio output devices, including
|
* Returns the total number of audio output devices, including
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "OutputCommand.hxx"
|
#include "OutputCommand.hxx"
|
||||||
#include "MultipleOutputs.hxx"
|
#include "MultipleOutputs.hxx"
|
||||||
#include "Internal.hxx"
|
#include "Internal.hxx"
|
||||||
|
#include "Client.hxx"
|
||||||
#include "player/Control.hxx"
|
#include "player/Control.hxx"
|
||||||
#include "mixer/MixerControl.hxx"
|
#include "mixer/MixerControl.hxx"
|
||||||
#include "mixer/Volume.hxx"
|
#include "mixer/Volume.hxx"
|
||||||
@ -53,7 +54,7 @@ audio_output_enable_index(MultipleOutputs &outputs, unsigned idx)
|
|||||||
idle_add(IDLE_MIXER);
|
idle_add(IDLE_MIXER);
|
||||||
}
|
}
|
||||||
|
|
||||||
ao.player_control->LockUpdateAudio();
|
ao.client->ApplyEnabled();
|
||||||
|
|
||||||
++audio_output_state_version;
|
++audio_output_state_version;
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ audio_output_disable_index(MultipleOutputs &outputs, unsigned idx)
|
|||||||
idle_add(IDLE_MIXER);
|
idle_add(IDLE_MIXER);
|
||||||
}
|
}
|
||||||
|
|
||||||
ao.player_control->LockUpdateAudio();
|
ao.client->ApplyEnabled();
|
||||||
|
|
||||||
++audio_output_state_version;
|
++audio_output_state_version;
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ audio_output_toggle_index(MultipleOutputs &outputs, unsigned idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ao.player_control->LockUpdateAudio();
|
ao.client->ApplyEnabled();
|
||||||
|
|
||||||
++audio_output_state_version;
|
++audio_output_state_version;
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Internal.hxx"
|
#include "Internal.hxx"
|
||||||
|
#include "Client.hxx"
|
||||||
#include "OutputAPI.hxx"
|
#include "OutputAPI.hxx"
|
||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "pcm/PcmMix.hxx"
|
#include "pcm/PcmMix.hxx"
|
||||||
@ -28,7 +29,6 @@
|
|||||||
#include "filter/plugins/ReplayGainFilterPlugin.hxx"
|
#include "filter/plugins/ReplayGainFilterPlugin.hxx"
|
||||||
#include "mixer/MixerInternal.hxx"
|
#include "mixer/MixerInternal.hxx"
|
||||||
#include "mixer/plugins/SoftwareMixerPlugin.hxx"
|
#include "mixer/plugins/SoftwareMixerPlugin.hxx"
|
||||||
#include "player/Control.hxx"
|
|
||||||
#include "MusicPipe.hxx"
|
#include "MusicPipe.hxx"
|
||||||
#include "MusicChunk.hxx"
|
#include "MusicChunk.hxx"
|
||||||
#include "thread/Util.hxx"
|
#include "thread/Util.hxx"
|
||||||
@ -504,7 +504,7 @@ AudioOutput::Play()
|
|||||||
give it a chance to refill the pipe before
|
give it a chance to refill the pipe before
|
||||||
it runs empty */
|
it runs empty */
|
||||||
const ScopeUnlock unlock(mutex);
|
const ScopeUnlock unlock(mutex);
|
||||||
player_control->LockSignal();
|
client->ChunksConsumed();
|
||||||
n = 0;
|
n = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,7 +516,7 @@ AudioOutput::Play()
|
|||||||
} while (chunk != nullptr);
|
} while (chunk != nullptr);
|
||||||
|
|
||||||
const ScopeUnlock unlock(mutex);
|
const ScopeUnlock unlock(mutex);
|
||||||
player_control->LockSignal();
|
client->ChunksConsumed();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#ifndef MPD_PLAYER_CONTROL_HXX
|
#ifndef MPD_PLAYER_CONTROL_HXX
|
||||||
#define MPD_PLAYER_CONTROL_HXX
|
#define MPD_PLAYER_CONTROL_HXX
|
||||||
|
|
||||||
|
#include "output/Client.hxx"
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
#include "thread/Cond.hxx"
|
#include "thread/Cond.hxx"
|
||||||
@ -96,7 +97,7 @@ struct player_status {
|
|||||||
SongTime elapsed_time;
|
SongTime elapsed_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerControl {
|
struct PlayerControl final : AudioOutputClient {
|
||||||
PlayerListener &listener;
|
PlayerListener &listener;
|
||||||
|
|
||||||
MultipleOutputs &outputs;
|
MultipleOutputs &outputs;
|
||||||
@ -527,6 +528,15 @@ public:
|
|||||||
double GetTotalPlayTime() const {
|
double GetTotalPlayTime() const {
|
||||||
return total_play_time;
|
return total_play_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* virtual methods from AudioOutputClient */
|
||||||
|
void ChunksConsumed() override {
|
||||||
|
LockSignal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplyEnabled() override {
|
||||||
|
LockUpdateAudio();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "output/Internal.hxx"
|
#include "output/Internal.hxx"
|
||||||
#include "output/OutputPlugin.hxx"
|
#include "output/OutputPlugin.hxx"
|
||||||
|
#include "output/Client.hxx"
|
||||||
#include "config/Param.hxx"
|
#include "config/Param.hxx"
|
||||||
#include "config/ConfigGlobal.hxx"
|
#include "config/ConfigGlobal.hxx"
|
||||||
#include "config/ConfigOption.hxx"
|
#include "config/ConfigOption.hxx"
|
||||||
@ -32,7 +33,6 @@
|
|||||||
#include "ReplayGainConfig.hxx"
|
#include "ReplayGainConfig.hxx"
|
||||||
#include "pcm/PcmConvert.hxx"
|
#include "pcm/PcmConvert.hxx"
|
||||||
#include "filter/FilterRegistry.hxx"
|
#include "filter/FilterRegistry.hxx"
|
||||||
#include "player/Control.hxx"
|
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
@ -43,6 +43,16 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
class DummyAudioOutputClient final : public AudioOutputClient {
|
||||||
|
public:
|
||||||
|
/* virtual methods from AudioOutputClient */
|
||||||
|
void ChunksConsumed() override {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplyEnabled() override {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const FilterPlugin *
|
const FilterPlugin *
|
||||||
filter_plugin_by_name(gcc_unused const char *name)
|
filter_plugin_by_name(gcc_unused const char *name)
|
||||||
{
|
{
|
||||||
@ -50,21 +60,9 @@ filter_plugin_by_name(gcc_unused const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {}
|
|
||||||
|
|
||||||
static AudioOutput *
|
static AudioOutput *
|
||||||
load_audio_output(EventLoop &event_loop, const char *name)
|
load_audio_output(EventLoop &event_loop, AudioOutputClient &client,
|
||||||
|
const char *name)
|
||||||
{
|
{
|
||||||
const auto *param = config_find_block(ConfigBlockOption::AUDIO_OUTPUT,
|
const auto *param = config_find_block(ConfigBlockOption::AUDIO_OUTPUT,
|
||||||
"name", name);
|
"name", name);
|
||||||
@ -72,15 +70,9 @@ load_audio_output(EventLoop &event_loop, const char *name)
|
|||||||
throw FormatRuntimeError("No such configured audio output: %s\n",
|
throw FormatRuntimeError("No such configured audio output: %s\n",
|
||||||
name);
|
name);
|
||||||
|
|
||||||
static struct PlayerControl dummy_player_control(*(PlayerListener *)nullptr,
|
|
||||||
*(MultipleOutputs *)nullptr,
|
|
||||||
32, 4,
|
|
||||||
AudioFormat::Undefined(),
|
|
||||||
ReplayGainConfig());
|
|
||||||
|
|
||||||
return audio_output_new(event_loop, ReplayGainConfig(), *param,
|
return audio_output_new(event_loop, ReplayGainConfig(), *param,
|
||||||
*(MixerListener *)nullptr,
|
*(MixerListener *)nullptr,
|
||||||
dummy_player_control);
|
client);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -150,7 +142,8 @@ try {
|
|||||||
|
|
||||||
/* initialize the audio output */
|
/* initialize the audio output */
|
||||||
|
|
||||||
AudioOutput *ao = load_audio_output(event_loop, argv[2]);
|
DummyAudioOutputClient client;
|
||||||
|
AudioOutput *ao = load_audio_output(event_loop, client, argv[2]);
|
||||||
|
|
||||||
/* parse the audio format */
|
/* parse the audio format */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user