Commit e8938b10 authored by Max Kellermann's avatar Max Kellermann

MixerPlugin: add EventLoop& init() parameter

parent 4a283330
...@@ -476,7 +476,8 @@ int mpd_main(int argc, char *argv[]) ...@@ -476,7 +476,8 @@ int mpd_main(int argc, char *argv[])
initialize_decoder_and_player(); initialize_decoder_and_player();
volume_init(); volume_init();
initAudioConfig(); initAudioConfig();
instance->partition->outputs.Configure(instance->partition->pc); instance->partition->outputs.Configure(*main_loop,
instance->partition->pc);
client_manager_init(); client_manager_init();
replay_gain_global_init(); replay_gain_global_init();
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
#include <assert.h> #include <assert.h>
Mixer * Mixer *
mixer_new(const struct mixer_plugin *plugin, void *ao, mixer_new(EventLoop &event_loop,
const mixer_plugin *plugin, void *ao,
const config_param &param, const config_param &param,
Error &error) Error &error)
{ {
...@@ -33,7 +34,7 @@ mixer_new(const struct mixer_plugin *plugin, void *ao, ...@@ -33,7 +34,7 @@ mixer_new(const struct mixer_plugin *plugin, void *ao,
assert(plugin != nullptr); assert(plugin != nullptr);
mixer = plugin->init(ao, param, error); mixer = plugin->init(event_loop, ao, param, error);
assert(mixer == nullptr || mixer->IsPlugin(*plugin)); assert(mixer == nullptr || mixer->IsPlugin(*plugin));
......
...@@ -27,11 +27,12 @@ ...@@ -27,11 +27,12 @@
class Error; class Error;
class Mixer; class Mixer;
class EventLoop;
struct mixer_plugin; struct mixer_plugin;
struct config_param; struct config_param;
Mixer * Mixer *
mixer_new(const mixer_plugin *plugin, void *ao, mixer_new(EventLoop &event_loop, const mixer_plugin *plugin, void *ao,
const config_param &param, const config_param &param,
Error &error); Error &error);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
struct config_param; struct config_param;
class Mixer; class Mixer;
class EventLoop;
class Error; class Error;
struct mixer_plugin { struct mixer_plugin {
...@@ -41,7 +42,8 @@ struct mixer_plugin { ...@@ -41,7 +42,8 @@ struct mixer_plugin {
* nullptr to ignore errors * nullptr to ignore errors
* @return a mixer object, or nullptr on error * @return a mixer object, or nullptr on error
*/ */
Mixer *(*init)(void *ao, const config_param &param, Mixer *(*init)(EventLoop &event_loop, void *ao,
const config_param &param,
Error &error); Error &error);
/** /**
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "mixer/MixerInternal.hxx" #include "mixer/MixerInternal.hxx"
#include "output/OutputAPI.hxx" #include "output/OutputAPI.hxx"
#include "GlobalEvents.hxx" #include "GlobalEvents.hxx"
#include "Main.hxx"
#include "event/MultiSocketMonitor.hxx" #include "event/MultiSocketMonitor.hxx"
#include "event/DeferredMonitor.hxx" #include "event/DeferredMonitor.hxx"
#include "event/Loop.hxx" #include "event/Loop.hxx"
...@@ -62,6 +61,8 @@ private: ...@@ -62,6 +61,8 @@ private:
}; };
class AlsaMixer final : public Mixer { class AlsaMixer final : public Mixer {
EventLoop &event_loop;
const char *device; const char *device;
const char *control; const char *control;
unsigned int index; unsigned int index;
...@@ -75,7 +76,8 @@ class AlsaMixer final : public Mixer { ...@@ -75,7 +76,8 @@ class AlsaMixer final : public Mixer {
AlsaMixerMonitor *monitor; AlsaMixerMonitor *monitor;
public: public:
AlsaMixer():Mixer(alsa_mixer_plugin) {} AlsaMixer(EventLoop &_event_loop)
:Mixer(alsa_mixer_plugin), event_loop(_event_loop) {}
void Configure(const config_param &param); void Configure(const config_param &param);
bool Setup(Error &error); bool Setup(Error &error);
...@@ -162,10 +164,11 @@ AlsaMixer::Configure(const config_param &param) ...@@ -162,10 +164,11 @@ AlsaMixer::Configure(const config_param &param)
} }
static Mixer * static Mixer *
alsa_mixer_init(gcc_unused void *ao, const config_param &param, alsa_mixer_init(EventLoop &event_loop, gcc_unused void *ao,
const config_param &param,
gcc_unused Error &error) gcc_unused Error &error)
{ {
AlsaMixer *am = new AlsaMixer(); AlsaMixer *am = new AlsaMixer(event_loop);
am->Configure(param); am->Configure(param);
return am; return am;
...@@ -237,7 +240,7 @@ AlsaMixer::Setup(Error &error) ...@@ -237,7 +240,7 @@ AlsaMixer::Setup(Error &error)
snd_mixer_elem_set_callback(elem, alsa_mixer_elem_callback); snd_mixer_elem_set_callback(elem, alsa_mixer_elem_callback);
monitor = new AlsaMixerMonitor(*main_loop, handle); monitor = new AlsaMixerMonitor(event_loop, handle);
return true; return true;
} }
......
...@@ -96,7 +96,8 @@ OssMixer::Configure(const config_param &param, Error &error) ...@@ -96,7 +96,8 @@ OssMixer::Configure(const config_param &param, Error &error)
} }
static Mixer * static Mixer *
oss_mixer_init(gcc_unused void *ao, const config_param &param, oss_mixer_init(gcc_unused EventLoop &event_loop, gcc_unused void *ao,
const config_param &param,
Error &error) Error &error)
{ {
OssMixer *om = new OssMixer(); OssMixer *om = new OssMixer();
......
...@@ -143,7 +143,8 @@ pulse_mixer_on_change(PulseMixer *pm, ...@@ -143,7 +143,8 @@ pulse_mixer_on_change(PulseMixer *pm,
} }
static Mixer * static Mixer *
pulse_mixer_init(void *ao, gcc_unused const config_param &param, pulse_mixer_init(gcc_unused EventLoop &event_loop, void *ao,
gcc_unused const config_param &param,
Error &error) Error &error)
{ {
PulseOutput *po = (PulseOutput *)ao; PulseOutput *po = (PulseOutput *)ao;
......
...@@ -34,7 +34,8 @@ struct RoarMixer final : public Mixer { ...@@ -34,7 +34,8 @@ struct RoarMixer final : public Mixer {
}; };
static Mixer * static Mixer *
roar_mixer_init(void *ao, gcc_unused const config_param &param, roar_mixer_init(gcc_unused EventLoop &event_loop, void *ao,
gcc_unused const config_param &param,
gcc_unused Error &error) gcc_unused Error &error)
{ {
return new RoarMixer((RoarOutput *)ao); return new RoarMixer((RoarOutput *)ao);
......
...@@ -67,7 +67,7 @@ struct SoftwareMixer final : public Mixer { ...@@ -67,7 +67,7 @@ struct SoftwareMixer final : public Mixer {
}; };
static Mixer * static Mixer *
software_mixer_init(gcc_unused void *ao, software_mixer_init(gcc_unused EventLoop &event_loop, gcc_unused void *ao,
gcc_unused const config_param &param, gcc_unused const config_param &param,
gcc_unused Error &error) gcc_unused Error &error)
{ {
......
...@@ -55,7 +55,8 @@ winmm_volume_encode(int volume) ...@@ -55,7 +55,8 @@ winmm_volume_encode(int volume)
} }
static Mixer * static Mixer *
winmm_mixer_init(void *ao, gcc_unused const config_param &param, winmm_mixer_init(gcc_unused EventLoop &event_loop, void *ao,
gcc_unused const config_param &param,
gcc_unused Error &error) gcc_unused Error &error)
{ {
assert(ao != nullptr); assert(ao != nullptr);
......
...@@ -112,7 +112,7 @@ audio_output_mixer_type(const config_param &param) ...@@ -112,7 +112,7 @@ audio_output_mixer_type(const config_param &param)
} }
static Mixer * static Mixer *
audio_output_load_mixer(AudioOutput *ao, audio_output_load_mixer(EventLoop &event_loop, AudioOutput *ao,
const config_param &param, const config_param &param,
const struct mixer_plugin *plugin, const struct mixer_plugin *plugin,
Filter &filter_chain, Filter &filter_chain,
...@@ -129,10 +129,10 @@ audio_output_load_mixer(AudioOutput *ao, ...@@ -129,10 +129,10 @@ audio_output_load_mixer(AudioOutput *ao,
if (plugin == nullptr) if (plugin == nullptr)
return nullptr; return nullptr;
return mixer_new(plugin, ao, param, error); return mixer_new(event_loop, plugin, ao, param, error);
case MIXER_TYPE_SOFTWARE: case MIXER_TYPE_SOFTWARE:
mixer = mixer_new(&software_mixer_plugin, nullptr, mixer = mixer_new(event_loop, &software_mixer_plugin, nullptr,
config_param(), config_param(),
IgnoreError()); IgnoreError());
assert(mixer != nullptr); assert(mixer != nullptr);
...@@ -211,7 +211,8 @@ AudioOutput::Configure(const config_param &param, Error &error) ...@@ -211,7 +211,8 @@ AudioOutput::Configure(const config_param &param, Error &error)
} }
static bool static bool
audio_output_setup(AudioOutput *ao, const config_param &param, audio_output_setup(EventLoop &event_loop, AudioOutput *ao,
const config_param &param,
Error &error) Error &error)
{ {
...@@ -241,7 +242,7 @@ audio_output_setup(AudioOutput *ao, const config_param &param, ...@@ -241,7 +242,7 @@ audio_output_setup(AudioOutput *ao, const config_param &param,
/* set up the mixer */ /* set up the mixer */
Error mixer_error; Error mixer_error;
ao->mixer = audio_output_load_mixer(ao, param, ao->mixer = audio_output_load_mixer(event_loop, ao, param,
ao->plugin.mixer_plugin, ao->plugin.mixer_plugin,
*ao->filter, mixer_error); *ao->filter, mixer_error);
if (ao->mixer == nullptr && mixer_error.IsDefined()) if (ao->mixer == nullptr && mixer_error.IsDefined())
...@@ -277,7 +278,7 @@ audio_output_setup(AudioOutput *ao, const config_param &param, ...@@ -277,7 +278,7 @@ audio_output_setup(AudioOutput *ao, const config_param &param,
} }
AudioOutput * AudioOutput *
audio_output_new(const config_param &param, audio_output_new(EventLoop &event_loop, const config_param &param,
PlayerControl &pc, PlayerControl &pc,
Error &error) Error &error)
{ {
...@@ -316,7 +317,7 @@ audio_output_new(const config_param &param, ...@@ -316,7 +317,7 @@ audio_output_new(const config_param &param,
if (ao == nullptr) if (ao == nullptr)
return nullptr; return nullptr;
if (!audio_output_setup(ao, param, error)) { if (!audio_output_setup(event_loop, ao, param, error)) {
ao_plugin_finish(ao); ao_plugin_finish(ao);
return nullptr; return nullptr;
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
class Error; class Error;
class Filter; class Filter;
class MusicPipe; class MusicPipe;
class EventLoop;
struct music_chunk; struct music_chunk;
struct config_param; struct config_param;
struct PlayerControl; struct PlayerControl;
...@@ -422,7 +423,7 @@ private: ...@@ -422,7 +423,7 @@ private:
extern struct notify audio_output_client_notify; extern struct notify audio_output_client_notify;
AudioOutput * AudioOutput *
audio_output_new(const config_param &param, audio_output_new(EventLoop &event_loop, const config_param &param,
PlayerControl &pc, PlayerControl &pc,
Error &error); Error &error);
......
...@@ -50,10 +50,10 @@ MultipleOutputs::~MultipleOutputs() ...@@ -50,10 +50,10 @@ MultipleOutputs::~MultipleOutputs()
} }
static AudioOutput * static AudioOutput *
LoadOutput(PlayerControl &pc, const config_param &param) LoadOutput(EventLoop &event_loop, PlayerControl &pc, const config_param &param)
{ {
Error error; Error error;
AudioOutput *output = audio_output_new(param, pc, error); AudioOutput *output = audio_output_new(event_loop, param, pc, error);
if (output == nullptr) { if (output == nullptr) {
if (param.line > 0) if (param.line > 0)
FormatFatalError("line %i: %s", FormatFatalError("line %i: %s",
...@@ -67,12 +67,12 @@ LoadOutput(PlayerControl &pc, const config_param &param) ...@@ -67,12 +67,12 @@ LoadOutput(PlayerControl &pc, const config_param &param)
} }
void void
MultipleOutputs::Configure(PlayerControl &pc) MultipleOutputs::Configure(EventLoop &event_loop, PlayerControl &pc)
{ {
const config_param *param = nullptr; const config_param *param = nullptr;
while ((param = config_get_next_param(CONF_AUDIO_OUTPUT, while ((param = config_get_next_param(CONF_AUDIO_OUTPUT,
param)) != nullptr) { param)) != nullptr) {
auto output = LoadOutput(pc, *param); auto output = LoadOutput(event_loop, pc, *param);
if (FindByName(output->name) != nullptr) if (FindByName(output->name) != nullptr)
FormatFatalError("output devices with identical " FormatFatalError("output devices with identical "
"names: %s", output->name); "names: %s", output->name);
...@@ -83,7 +83,7 @@ MultipleOutputs::Configure(PlayerControl &pc) ...@@ -83,7 +83,7 @@ MultipleOutputs::Configure(PlayerControl &pc)
if (outputs.empty()) { if (outputs.empty()) {
/* auto-detect device */ /* auto-detect device */
const config_param empty; const config_param empty;
auto output = LoadOutput(pc, empty); auto output = LoadOutput(event_loop, pc, empty);
outputs.push_back(output); outputs.push_back(output);
} }
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
struct AudioFormat; struct AudioFormat;
class MusicBuffer; class MusicBuffer;
class MusicPipe; class MusicPipe;
class EventLoop;
struct music_chunk; struct music_chunk;
struct PlayerControl; struct PlayerControl;
struct AudioOutput; struct AudioOutput;
...@@ -72,7 +73,7 @@ public: ...@@ -72,7 +73,7 @@ public:
MultipleOutputs(); MultipleOutputs();
~MultipleOutputs(); ~MultipleOutputs();
void Configure(PlayerControl &pc); void Configure(EventLoop &event_loop, PlayerControl &pc);
/** /**
* Returns the total number of audio output devices, including * Returns the total number of audio output devices, including
......
...@@ -35,8 +35,6 @@ ...@@ -35,8 +35,6 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
EventLoop *main_loop;
#ifdef HAVE_PULSE #ifdef HAVE_PULSE
#include "output/plugins/PulseOutputPlugin.hxx" #include "output/plugins/PulseOutputPlugin.hxx"
...@@ -115,10 +113,10 @@ int main(int argc, gcc_unused char **argv) ...@@ -115,10 +113,10 @@ int main(int argc, gcc_unused char **argv)
g_thread_init(NULL); g_thread_init(NULL);
#endif #endif
main_loop = new EventLoop; EventLoop event_loop;
Error error; Error error;
Mixer *mixer = mixer_new(&alsa_mixer_plugin, nullptr, Mixer *mixer = mixer_new(event_loop, &alsa_mixer_plugin, nullptr,
config_param(), error); config_param(), error);
if (mixer == NULL) { if (mixer == NULL) {
LogError(error, "mixer_new() failed"); LogError(error, "mixer_new() failed");
...@@ -135,8 +133,6 @@ int main(int argc, gcc_unused char **argv) ...@@ -135,8 +133,6 @@ int main(int argc, gcc_unused char **argv)
mixer_close(mixer); mixer_close(mixer);
mixer_free(mixer); mixer_free(mixer);
delete main_loop;
assert(volume >= -1 && volume <= 100); assert(volume >= -1 && volume <= 100);
if (volume < 0) { if (volume < 0) {
......
...@@ -45,8 +45,6 @@ ...@@ -45,8 +45,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
EventLoop *main_loop;
void void
GlobalEvents::Emit(gcc_unused Event event) GlobalEvents::Emit(gcc_unused Event event)
{ {
...@@ -80,7 +78,7 @@ PlayerControl::PlayerControl(gcc_unused MultipleOutputs &_outputs, ...@@ -80,7 +78,7 @@ PlayerControl::PlayerControl(gcc_unused MultipleOutputs &_outputs,
PlayerControl::~PlayerControl() {} PlayerControl::~PlayerControl() {}
static AudioOutput * static AudioOutput *
load_audio_output(const char *name) load_audio_output(EventLoop &event_loop, const char *name)
{ {
const struct config_param *param; const struct config_param *param;
...@@ -95,7 +93,8 @@ load_audio_output(const char *name) ...@@ -95,7 +93,8 @@ load_audio_output(const char *name)
Error error; Error error;
AudioOutput *ao = AudioOutput *ao =
audio_output_new(*param, dummy_player_control, error); audio_output_new(event_loop, *param, dummy_player_control,
error);
if (ao == nullptr) if (ao == nullptr)
LogError(error); LogError(error);
...@@ -189,14 +188,14 @@ int main(int argc, char **argv) ...@@ -189,14 +188,14 @@ int main(int argc, char **argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
main_loop = new EventLoop(); EventLoop event_loop;
io_thread_init(); io_thread_init();
io_thread_start(); io_thread_start();
/* initialize the audio output */ /* initialize the audio output */
AudioOutput *ao = load_audio_output(argv[2]); AudioOutput *ao = load_audio_output(event_loop, argv[2]);
if (ao == NULL) if (ao == NULL)
return 1; return 1;
...@@ -219,8 +218,6 @@ int main(int argc, char **argv) ...@@ -219,8 +218,6 @@ int main(int argc, char **argv)
io_thread_deinit(); io_thread_deinit();
delete main_loop;
config_global_finish(); config_global_finish();
return success ? EXIT_SUCCESS : EXIT_FAILURE; return success ? EXIT_SUCCESS : EXIT_FAILURE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment