Commit 9f625b0a authored by Max Kellermann's avatar Max Kellermann

mixer/Pulse: convert to a class

parent bc1b4131
...@@ -39,14 +39,17 @@ ...@@ -39,14 +39,17 @@
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pulse_mixer" #define G_LOG_DOMAIN "pulse_mixer"
struct pulse_mixer { struct PulseMixer : mixer {
struct mixer base;
PulseOutput *output; PulseOutput *output;
bool online; bool online;
struct pa_cvolume volume; struct pa_cvolume volume;
PulseMixer(PulseOutput *_output)
:output(_output), online(false)
{
mixer_init(this, &pulse_mixer_plugin);
}
}; };
/** /**
...@@ -59,7 +62,7 @@ pulse_mixer_quark(void) ...@@ -59,7 +62,7 @@ pulse_mixer_quark(void)
} }
static void static void
pulse_mixer_offline(struct pulse_mixer *pm) pulse_mixer_offline(PulseMixer *pm)
{ {
if (!pm->online) if (!pm->online)
return; return;
...@@ -77,7 +80,7 @@ static void ...@@ -77,7 +80,7 @@ static void
pulse_mixer_volume_cb(G_GNUC_UNUSED pa_context *context, const pa_sink_input_info *i, pulse_mixer_volume_cb(G_GNUC_UNUSED pa_context *context, const pa_sink_input_info *i,
int eol, void *userdata) int eol, void *userdata)
{ {
struct pulse_mixer *pm = (struct pulse_mixer *)userdata; PulseMixer *pm = (PulseMixer *)userdata;
if (eol) if (eol)
return; return;
...@@ -94,7 +97,7 @@ pulse_mixer_volume_cb(G_GNUC_UNUSED pa_context *context, const pa_sink_input_inf ...@@ -94,7 +97,7 @@ pulse_mixer_volume_cb(G_GNUC_UNUSED pa_context *context, const pa_sink_input_inf
} }
static void static void
pulse_mixer_update(struct pulse_mixer *pm, pulse_mixer_update(PulseMixer *pm,
struct pa_context *context, struct pa_stream *stream) struct pa_context *context, struct pa_stream *stream)
{ {
pa_operation *o; pa_operation *o;
...@@ -117,7 +120,7 @@ pulse_mixer_update(struct pulse_mixer *pm, ...@@ -117,7 +120,7 @@ pulse_mixer_update(struct pulse_mixer *pm,
} }
void void
pulse_mixer_on_connect(G_GNUC_UNUSED struct pulse_mixer *pm, pulse_mixer_on_connect(G_GNUC_UNUSED PulseMixer *pm,
struct pa_context *context) struct pa_context *context)
{ {
pa_operation *o; pa_operation *o;
...@@ -137,13 +140,13 @@ pulse_mixer_on_connect(G_GNUC_UNUSED struct pulse_mixer *pm, ...@@ -137,13 +140,13 @@ pulse_mixer_on_connect(G_GNUC_UNUSED struct pulse_mixer *pm,
} }
void void
pulse_mixer_on_disconnect(struct pulse_mixer *pm) pulse_mixer_on_disconnect(PulseMixer *pm)
{ {
pulse_mixer_offline(pm); pulse_mixer_offline(pm);
} }
void void
pulse_mixer_on_change(struct pulse_mixer *pm, pulse_mixer_on_change(PulseMixer *pm,
struct pa_context *context, struct pa_stream *stream) struct pa_context *context, struct pa_stream *stream)
{ {
pulse_mixer_update(pm, context, stream); pulse_mixer_update(pm, context, stream);
...@@ -161,33 +164,27 @@ pulse_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param, ...@@ -161,33 +164,27 @@ pulse_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param,
return nullptr; return nullptr;
} }
struct pulse_mixer *pm = g_new(struct pulse_mixer,1); PulseMixer *pm = new PulseMixer(po);
mixer_init(&pm->base, &pulse_mixer_plugin);
pm->online = false;
pm->output = po;
pulse_output_set_mixer(po, pm); pulse_output_set_mixer(po, pm);
return &pm->base; return pm;
} }
static void static void
pulse_mixer_finish(struct mixer *data) pulse_mixer_finish(struct mixer *data)
{ {
struct pulse_mixer *pm = (struct pulse_mixer *) data; PulseMixer *pm = (PulseMixer *) data;
pulse_output_clear_mixer(pm->output, pm); pulse_output_clear_mixer(pm->output, pm);
/* free resources */ delete pm;
g_free(pm);
} }
static int static int
pulse_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) pulse_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r)
{ {
struct pulse_mixer *pm = (struct pulse_mixer *) mixer; PulseMixer *pm = (PulseMixer *) mixer;
int ret; int ret;
pulse_output_lock(pm->output); pulse_output_lock(pm->output);
...@@ -204,7 +201,7 @@ pulse_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) ...@@ -204,7 +201,7 @@ pulse_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r)
static bool static bool
pulse_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r) pulse_mixer_set_volume(struct mixer *mixer, unsigned volume, GError **error_r)
{ {
struct pulse_mixer *pm = (struct pulse_mixer *) mixer; PulseMixer *pm = (PulseMixer *) mixer;
struct pa_cvolume cvolume; struct pa_cvolume cvolume;
bool success; bool success;
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <pulse/def.h> #include <pulse/def.h>
struct pulse_mixer; struct PulseMixer;
struct pa_context; struct pa_context;
struct pa_stream; struct pa_stream;
...@@ -31,13 +31,13 @@ extern "C" { ...@@ -31,13 +31,13 @@ extern "C" {
#endif #endif
void void
pulse_mixer_on_connect(struct pulse_mixer *pm, struct pa_context *context); pulse_mixer_on_connect(PulseMixer *pm, struct pa_context *context);
void void
pulse_mixer_on_disconnect(struct pulse_mixer *pm); pulse_mixer_on_disconnect(PulseMixer *pm);
void void
pulse_mixer_on_change(struct pulse_mixer *pm, pulse_mixer_on_change(PulseMixer *pm,
struct pa_context *context, struct pa_stream *stream); struct pa_context *context, struct pa_stream *stream);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -52,7 +52,7 @@ struct PulseOutput { ...@@ -52,7 +52,7 @@ struct PulseOutput {
const char *server; const char *server;
const char *sink; const char *sink;
struct pulse_mixer *mixer; PulseMixer *mixer;
struct pa_threaded_mainloop *mainloop; struct pa_threaded_mainloop *mainloop;
struct pa_context *context; struct pa_context *context;
...@@ -91,7 +91,7 @@ pulse_output_unlock(PulseOutput *po) ...@@ -91,7 +91,7 @@ pulse_output_unlock(PulseOutput *po)
} }
void void
pulse_output_set_mixer(PulseOutput *po, struct pulse_mixer *pm) pulse_output_set_mixer(PulseOutput *po, PulseMixer *pm)
{ {
assert(po != nullptr); assert(po != nullptr);
assert(po->mixer == nullptr); assert(po->mixer == nullptr);
...@@ -117,8 +117,7 @@ pulse_output_set_mixer(PulseOutput *po, struct pulse_mixer *pm) ...@@ -117,8 +117,7 @@ pulse_output_set_mixer(PulseOutput *po, struct pulse_mixer *pm)
} }
void void
pulse_output_clear_mixer(PulseOutput *po, pulse_output_clear_mixer(PulseOutput *po, gcc_unused PulseMixer *pm)
G_GNUC_UNUSED struct pulse_mixer *pm)
{ {
assert(po != nullptr); assert(po != nullptr);
assert(pm != nullptr); assert(pm != nullptr);
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <stdbool.h> #include <stdbool.h>
struct PulseOutput; struct PulseOutput;
struct pulse_mixer; struct PulseMixer;
struct pa_cvolume; struct pa_cvolume;
extern const struct audio_output_plugin pulse_output_plugin; extern const struct audio_output_plugin pulse_output_plugin;
...@@ -41,10 +41,10 @@ void ...@@ -41,10 +41,10 @@ void
pulse_output_unlock(PulseOutput *po); pulse_output_unlock(PulseOutput *po);
void void
pulse_output_set_mixer(PulseOutput *po, struct pulse_mixer *pm); pulse_output_set_mixer(PulseOutput *po, PulseMixer *pm);
void void
pulse_output_clear_mixer(PulseOutput *po, struct pulse_mixer *pm); pulse_output_clear_mixer(PulseOutput *po, PulseMixer *pm);
bool bool
pulse_output_set_volume(PulseOutput *po, pulse_output_set_volume(PulseOutput *po,
......
...@@ -49,13 +49,13 @@ pulse_output_unlock(G_GNUC_UNUSED PulseOutput *po) ...@@ -49,13 +49,13 @@ pulse_output_unlock(G_GNUC_UNUSED PulseOutput *po)
void void
pulse_output_set_mixer(G_GNUC_UNUSED PulseOutput *po, pulse_output_set_mixer(G_GNUC_UNUSED PulseOutput *po,
G_GNUC_UNUSED struct pulse_mixer *pm) G_GNUC_UNUSED PulseMixer *pm)
{ {
} }
void void
pulse_output_clear_mixer(G_GNUC_UNUSED PulseOutput *po, pulse_output_clear_mixer(G_GNUC_UNUSED PulseOutput *po,
G_GNUC_UNUSED struct pulse_mixer *pm) G_GNUC_UNUSED PulseMixer *pm)
{ {
} }
......
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