Init pulseaudio at startup 07/8507/3
authorJimmy Huang <jimmy.huang@intel.com>
Wed, 21 Aug 2013 23:53:21 +0000 (16:53 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 23 Aug 2013 20:19:08 +0000 (13:19 -0700)
- Working around for fixing incoming call has no audio, dialer will spawn the pulseaudio daemon
by connecting to it at startup

Change-Id: I8bf89b7d87174367bdddf40cbb1bcd56d2b7264e
Signed-off-by: Jimmy Huang <jimmy.huang@intel.com>
Makefile.am
configure.ac
dialer/main.c
packaging/lemolo.spec
utils/pulseaudio.c [new file with mode: 0644]
utils/pulseaudio.h [new file with mode: 0644]

index a627f54..8957662 100644 (file)
@@ -6,6 +6,7 @@ AM_CFLAGS = \
        -DPACKAGE_LIB_DIR=\"$(libdir)\" \
        -I$(top_srcdir)/utils \
        @EFL_CFLAGS@ \
+       @PULSEAUDIO_CFLAGS@ \
        @TIZEN_CFLAGS@
 
 MAINTAINERCLEANFILES = \
@@ -32,12 +33,15 @@ utils_libofono_efl_utils_la_SOURCES = \
        utils/log.h \
        utils/ofono.c \
        utils/ofono.h \
+       utils/pulseaudio.c \
+       utils/pulseaudio.h \
        utils/simple-popup.c \
        utils/simple-popup.h \
        utils/util.c \
        utils/util.h
 utils_libofono_efl_utils_la_LIBADD = \
        @EFL_LIBS@ \
+       @PULSEAUDIO_LIBS@ \
        @TIZEN_LIBS@
 
 if HAVE_TIZEN
@@ -53,6 +57,7 @@ bin_PROGRAMS = \
 
 dialer_dialer_LDADD = \
        @EFL_LIBS@ \
+       @PULSEAUDIO_LIBS@ \
        @TIZEN_LIBS@ \
        utils/libofono-efl-utils.la
 
index e823a4d..cb78dd6 100644 (file)
@@ -32,6 +32,12 @@ PKG_CHECK_MODULES([EFL],
                dbus-1
         ])
 
+PKG_CHECK_MODULES([PULSEAUDIO],
+       [
+               libpulse
+               libpulse-mainloop-glib
+        ])
+
 EFL_WITH_BIN([edje], [edje-cc], [edje_cc])
 
 want_tizen="auto"
index 3d4a55f..bf82e49 100644 (file)
@@ -15,6 +15,7 @@
 #include "gui.h"
 #include "log.h"
 #include "ofono.h"
+#include "pulseaudio.h"
 #include "rc.h"
 #include "util.h"
 
@@ -216,6 +217,12 @@ EAPI int elm_main(int argc, char **argv)
        }
 #endif
 
+       if (!pa_init()) {
+               CRITICAL("Could not setup pulseaudio");
+               _app_exit_code = EXIT_FAILURE;
+               goto end_pulseaudio;
+       }
+
        if (!gui_init()) {
                CRITICAL("Could not setup graphical user interface");
                _app_exit_code = EXIT_FAILURE;
@@ -244,6 +251,8 @@ EAPI int elm_main(int argc, char **argv)
 
 end_util:
        util_shutdown();
+end_pulseaudio:
+       pa_shutdown();
 #ifdef HAVE_TIZEN
 end_amb:
        amb_shutdown();
index a55dafe..5a5aaf8 100644 (file)
@@ -18,6 +18,7 @@ BuildRequires:  pkgconfig(capi-system-power)
 BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgconfig(appsvc)
 BuildRequires:  pkgconfig(notification)
+BuildRequires:  pkgconfig(libpulse)
 BuildRequires:  edje-tools
 Requires: ofono
 Requires: automotive-message-broker
diff --git a/utils/pulseaudio.c b/utils/pulseaudio.c
new file mode 100644 (file)
index 0000000..294d1e5
--- /dev/null
@@ -0,0 +1,48 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <Elementary.h>
+#include <pulse/context.h>
+#include <pulse/pulseaudio.h>
+#include <pulse/glib-mainloop.h>
+
+#include "pulseaudio.h"
+#include "log.h"
+
+static pa_glib_mainloop *mainloop = NULL;
+static pa_context *pa_ctx = NULL;
+
+Eina_Bool pa_init(void)
+{
+       if (!mainloop)
+               mainloop = pa_glib_mainloop_new(NULL);
+
+       pa_ctx = pa_context_new(pa_glib_mainloop_get_api(mainloop),
+                                "lemolo");
+
+       // connects to the pulse server
+       if (pa_context_connect(pa_ctx,
+                               NULL,
+                               PA_CONTEXT_NOFAIL, NULL) < 0)
+       {
+               ERR("Failed to connect to pulseaudio daemon");
+                pa_glib_mainloop_free(mainloop);
+                mainloop = NULL;
+               return EINA_FALSE;
+       }
+
+       return EINA_TRUE;
+}
+
+void pa_shutdown(void)
+{
+       if (pa_ctx) {
+               pa_context_disconnect(pa_ctx);
+               pa_context_unref(pa_ctx);
+       }
+
+       if (mainloop) {
+               pa_glib_mainloop_free(mainloop);
+               mainloop = NULL;
+       }
+}
diff --git a/utils/pulseaudio.h b/utils/pulseaudio.h
new file mode 100644 (file)
index 0000000..5dca36b
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _PULSEAUDIO_H__
+#define _PULSEAUDIO_H__
+
+Eina_Bool pa_init(void);
+
+void pa_shutdown(void);
+
+#endif