raster pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=35bb87529f701f0128a338b2313092c4876c6737

commit 35bb87529f701f0128a338b2313092c4876c6737
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Mon Feb 20 22:58:59 2017 +0900

    e mixer module - run pulseaudio if connect fails
    
    so i have a situatioon where pulse is not started automagically. if
    e's mixer it set to pulse... then stick to it, run pulse and keep
    trying to connect every 0.2 sec until connection works. this makes
    sound "just work" tm as it should...
    
    @fix
---
 src/modules/mixer/lib/backends/pulseaudio/pulse.c | 40 ++++++++++++++++++-----
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/modules/mixer/lib/backends/pulseaudio/pulse.c 
b/src/modules/mixer/lib/backends/pulseaudio/pulse.c
index 4773e35..5961410 100644
--- a/src/modules/mixer/lib/backends/pulseaudio/pulse.c
+++ b/src/modules/mixer/lib/backends/pulseaudio/pulse.c
@@ -764,7 +764,7 @@ _pulse_pa_state_cb(pa_context *context, void *data)
       case PA_CONTEXT_FAILED:
          WRN("PA_CONTEXT_FAILED");
          if (!ctx->connect)
-           ctx->connect = ecore_timer_loop_add(1.0, _pulse_connect, data);
+           ctx->connect = ecore_timer_loop_add(0.2, _pulse_connect, data);
          goto err;
       case PA_CONTEXT_TERMINATED:
          ERR("PA_CONTEXT_TERMINATE:");
@@ -841,9 +841,24 @@ _pulse_connect(void *data)
    return ECORE_CALLBACK_RENEW;
 }
 
+static Ecore_Exe           *_pulse_exe         = NULL;
+static Ecore_Event_Handler *_pulse_exe_handler = NULL;
+
 static void
 _shutdown(void)
 {
+   if (_pulse_exe)
+     {
+        ecore_exe_kill(_pulse_exe);
+        ecore_exe_free(_pulse_exe);
+        _pulse_exe = NULL;
+     }
+   if (_pulse_exe_handler)
+     {
+        ecore_event_handler_del(_pulse_exe_handler);
+        _pulse_exe_handler = NULL;
+     }
+
    if (!ctx)
       return;
 
@@ -861,6 +876,16 @@ _shutdown(void)
 }
 
 static Eina_Bool
+_pulse_exe_del(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
+{
+   Ecore_Exe_Event_Del *ev = event;
+
+   if (ev->exe != _pulse_exe) return ECORE_CALLBACK_PASS_ON;
+   _pulse_exe = NULL;
+   return ECORE_CALLBACK_DONE;
+}
+
+static Eina_Bool
 _init(Emix_Event_Cb cb, const void *data)
 {
    if (ctx)
@@ -876,14 +901,13 @@ _init(Emix_Event_Cb cb, const void *data)
    ctx->api = functable;
    ctx->api.userdata = ctx;
 
-   /* The reason of compares with EINA_TRUE is because ECORE_CALLBACK_RENEW
-      is EINA_TRUE. The function _pulse_connect returns ECORE_CALLBACK_RENEW
-      when could not connect to pulse.
-   */
-   if (_pulse_connect(ctx) == EINA_TRUE)
+   if (_pulse_connect(ctx) == EINA_TRUE) // true == failed and try again
      {
-        _shutdown();
-        return EINA_FALSE;
+        _pulse_exe_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
+                                                     _pulse_exe_del, NULL);
+        _pulse_exe = ecore_exe_pipe_run
+          ("pulseaudio", ECORE_EXE_NOT_LEADER | ECORE_EXE_TERM_WITH_PARENT,
+           NULL);
      }
 
    ctx->cb = cb;

-- 


Reply via email to