output/Client: new interface to replace direct access to class PlayerControl
This commit is contained in:
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 ConfigBlock &block,
|
||||
MixerListener &mixer_listener,
|
||||
PlayerControl &pc)
|
||||
AudioOutputClient &client)
|
||||
{
|
||||
const AudioOutputPlugin *plugin;
|
||||
|
||||
@@ -311,6 +311,6 @@ audio_output_new(EventLoop &event_loop,
|
||||
throw;
|
||||
}
|
||||
|
||||
ao->player_control = &pc;
|
||||
ao->client = &client;
|
||||
return ao;
|
||||
}
|
||||
|
@@ -37,9 +37,9 @@ class MusicPipe;
|
||||
class EventLoop;
|
||||
class Mixer;
|
||||
class MixerListener;
|
||||
class AudioOutputClient;
|
||||
struct MusicChunk;
|
||||
struct ConfigBlock;
|
||||
struct PlayerControl;
|
||||
struct AudioOutputPlugin;
|
||||
struct ReplayGainConfig;
|
||||
|
||||
@@ -261,7 +261,7 @@ struct AudioOutput {
|
||||
* The PlayerControl object which "owns" this output. This
|
||||
* object is needed to signal command completion.
|
||||
*/
|
||||
PlayerControl *player_control;
|
||||
AudioOutputClient *client;
|
||||
|
||||
/**
|
||||
* 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 ConfigBlock &block,
|
||||
MixerListener &mixer_listener,
|
||||
PlayerControl &pc);
|
||||
AudioOutputClient &client);
|
||||
|
||||
void
|
||||
audio_output_free(AudioOutput *ao);
|
||||
|
@@ -53,11 +53,11 @@ static AudioOutput *
|
||||
LoadOutput(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
MixerListener &mixer_listener,
|
||||
PlayerControl &pc, const ConfigBlock &block)
|
||||
AudioOutputClient &client, const ConfigBlock &block)
|
||||
try {
|
||||
return audio_output_new(event_loop, replay_gain_config, block,
|
||||
mixer_listener,
|
||||
pc);
|
||||
client);
|
||||
} catch (const std::runtime_error &e) {
|
||||
if (block.line > 0)
|
||||
std::throw_with_nested(FormatRuntimeError("Failed to configure output in line %i",
|
||||
@@ -69,13 +69,13 @@ try {
|
||||
void
|
||||
MultipleOutputs::Configure(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
PlayerControl &pc)
|
||||
AudioOutputClient &client)
|
||||
{
|
||||
for (const auto *param = config_get_block(ConfigBlockOption::AUDIO_OUTPUT);
|
||||
param != nullptr; param = param->next) {
|
||||
auto output = LoadOutput(event_loop, replay_gain_config,
|
||||
mixer_listener,
|
||||
pc, *param);
|
||||
client, *param);
|
||||
if (FindByName(output->name) != nullptr)
|
||||
throw FormatRuntimeError("output devices with identical "
|
||||
"names: %s", output->name);
|
||||
@@ -88,7 +88,7 @@ MultipleOutputs::Configure(EventLoop &event_loop,
|
||||
const ConfigBlock empty;
|
||||
auto output = LoadOutput(event_loop, replay_gain_config,
|
||||
mixer_listener,
|
||||
pc, empty);
|
||||
client, empty);
|
||||
outputs.push_back(output);
|
||||
}
|
||||
}
|
||||
|
@@ -39,8 +39,8 @@ class MusicBuffer;
|
||||
class MusicPipe;
|
||||
class EventLoop;
|
||||
class MixerListener;
|
||||
class AudioOutputClient;
|
||||
struct MusicChunk;
|
||||
struct PlayerControl;
|
||||
struct AudioOutput;
|
||||
struct ReplayGainConfig;
|
||||
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
|
||||
void Configure(EventLoop &event_loop,
|
||||
const ReplayGainConfig &replay_gain_config,
|
||||
PlayerControl &pc);
|
||||
AudioOutputClient &client);
|
||||
|
||||
/**
|
||||
* Returns the total number of audio output devices, including
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "OutputCommand.hxx"
|
||||
#include "MultipleOutputs.hxx"
|
||||
#include "Internal.hxx"
|
||||
#include "Client.hxx"
|
||||
#include "player/Control.hxx"
|
||||
#include "mixer/MixerControl.hxx"
|
||||
#include "mixer/Volume.hxx"
|
||||
@@ -53,7 +54,7 @@ audio_output_enable_index(MultipleOutputs &outputs, unsigned idx)
|
||||
idle_add(IDLE_MIXER);
|
||||
}
|
||||
|
||||
ao.player_control->LockUpdateAudio();
|
||||
ao.client->ApplyEnabled();
|
||||
|
||||
++audio_output_state_version;
|
||||
|
||||
@@ -80,7 +81,7 @@ audio_output_disable_index(MultipleOutputs &outputs, unsigned idx)
|
||||
idle_add(IDLE_MIXER);
|
||||
}
|
||||
|
||||
ao.player_control->LockUpdateAudio();
|
||||
ao.client->ApplyEnabled();
|
||||
|
||||
++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;
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "Internal.hxx"
|
||||
#include "Client.hxx"
|
||||
#include "OutputAPI.hxx"
|
||||
#include "Domain.hxx"
|
||||
#include "pcm/PcmMix.hxx"
|
||||
@@ -28,7 +29,6 @@
|
||||
#include "filter/plugins/ReplayGainFilterPlugin.hxx"
|
||||
#include "mixer/MixerInternal.hxx"
|
||||
#include "mixer/plugins/SoftwareMixerPlugin.hxx"
|
||||
#include "player/Control.hxx"
|
||||
#include "MusicPipe.hxx"
|
||||
#include "MusicChunk.hxx"
|
||||
#include "thread/Util.hxx"
|
||||
@@ -504,7 +504,7 @@ AudioOutput::Play()
|
||||
give it a chance to refill the pipe before
|
||||
it runs empty */
|
||||
const ScopeUnlock unlock(mutex);
|
||||
player_control->LockSignal();
|
||||
client->ChunksConsumed();
|
||||
n = 0;
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ AudioOutput::Play()
|
||||
} while (chunk != nullptr);
|
||||
|
||||
const ScopeUnlock unlock(mutex);
|
||||
player_control->LockSignal();
|
||||
client->ChunksConsumed();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#ifndef MPD_PLAYER_CONTROL_HXX
|
||||
#define MPD_PLAYER_CONTROL_HXX
|
||||
|
||||
#include "output/Client.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "thread/Mutex.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
@@ -96,7 +97,7 @@ struct player_status {
|
||||
SongTime elapsed_time;
|
||||
};
|
||||
|
||||
struct PlayerControl {
|
||||
struct PlayerControl final : AudioOutputClient {
|
||||
PlayerListener &listener;
|
||||
|
||||
MultipleOutputs &outputs;
|
||||
@@ -527,6 +528,15 @@ public:
|
||||
double GetTotalPlayTime() const {
|
||||
return total_play_time;
|
||||
}
|
||||
|
||||
/* virtual methods from AudioOutputClient */
|
||||
void ChunksConsumed() override {
|
||||
LockSignal();
|
||||
}
|
||||
|
||||
void ApplyEnabled() override {
|
||||
LockUpdateAudio();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user