This patch follows the commit 21bb10f4b. 

>From Max Kellermann:
> I removed the daemonization changes in main.c.  Please explain why you
> changed that.  If you need it for some reason, make that a separate
> patch with a good description of your rationale.

> That's the biggest flaw of your code: it opens the mixer device in the
> init() method, while the open() method is empty.  When the pulse
> daemon is not available (either during MPD startup or when it dies
> while MPD runs), the plugin will not even attempt to reconnect to
> pulse.  Please move the code to the open() method, to make that work.

I changed the daemonize call as the fork losts the connection to the
pulse server. According to your remark, the init() method should be
moved to the open() ones.

With the modification, mpd is able to reconnect the pulse mixer after
restarting the pulseaudio daemon.

Signed-off-by: David Guibert <david.guib...@gmail.com>

--- 
>The NULL pointer dereference which Avuton found was in fact a bug in
>the mixer API, following your plugin's failure to initialize.

These modifications remove this bug since the mixer structure is always
allocated. The open() method returns the status of the connection to the
pulse server.

 src/mixer/pulse_mixer.c |   53 +++++++++++++++++++++-------------------------
 1 files changed, 24 insertions(+), 29 deletions(-)

diff --git a/src/mixer/pulse_mixer.c b/src/mixer/pulse_mixer.c
index d042229..d00a36a 100644
--- a/src/mixer/pulse_mixer.c
+++ b/src/mixer/pulse_mixer.c
@@ -175,19 +175,35 @@ pulse_mixer_init(const struct config_param *param)
        pm->output_name = param != NULL
                ? config_dup_block_string(param, "name", NULL) : NULL;
 
-       g_debug("init");
+       return &pm->base;
+}
+
+static void
+pulse_mixer_finish(struct mixer *data)
+{
+       struct pulse_mixer *pm = (struct pulse_mixer *) data;
+       pm->context  = NULL;
+       pm->mainloop = NULL;
+       pm->volume   = NULL;
+       pm->online   = false;
+       g_free(pm);
+}
+
+static bool
+pulse_mixer_open(G_GNUC_UNUSED struct mixer *data)
+{
+       struct pulse_mixer *pm = (struct pulse_mixer *) data;
+       g_debug("pulse mixer open");
 
        if(!(pm->mainloop = pa_threaded_mainloop_new())) {
                g_debug("failed mainloop");
-               g_free(pm);
-               return NULL;
+               return false;
        }
 
        if(!(pm->context = 
pa_context_new(pa_threaded_mainloop_get_api(pm->mainloop),
                                          "Mixer mpd"))) {
                g_debug("failed context");
-               g_free(pm);
-               return NULL;
+               return false;
        }
 
        pa_context_set_state_callback(pm->context, context_state_cb, pm);
@@ -195,45 +211,24 @@ pulse_mixer_init(const struct config_param *param)
        if (pa_context_connect(pm->context, pm->server,
                               (pa_context_flags_t)0, NULL) < 0) {
                g_debug("context server fail");
-               g_free(pm);
-               return NULL;
+               return false;
        }
 
        pa_threaded_mainloop_lock(pm->mainloop);
        if (pa_threaded_mainloop_start(pm->mainloop) < 0) {
                g_debug("error start mainloop");
-               g_free(pm);
-               return NULL;
+               return false;
        }
 
        pa_threaded_mainloop_wait(pm->mainloop);
 
        if (pa_context_get_state(pm->context) != PA_CONTEXT_READY) {
                g_debug("error context not ready");
-               g_free(pm);
-               return NULL;
+               return false;
        }
 
        pa_threaded_mainloop_unlock(pm->mainloop);
-       return &pm->base ;
 
-}
-
-static void
-pulse_mixer_finish(struct mixer *data)
-{
-       struct pulse_mixer *pm = (struct pulse_mixer *) data;
-       pm->context  = NULL;
-       pm->mainloop = NULL;
-       pm->volume   = NULL;
-       pm->online   = false;
-       g_free(pm);
-}
-
-static bool
-pulse_mixer_open(G_GNUC_UNUSED struct mixer *data)
-{
-       g_debug("pulse mixer open");
        return true;
 }
 
-- 
tg: (a1534ba..) patch/move-init-open (depends on: master)

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to