From 129ea79dd79c74c088a147f48c01253da841d6df Mon Sep 17 00:00:00 2001 From: Jimmy Huang Date: Wed, 21 Aug 2013 16:53:21 -0700 Subject: [PATCH] Init pulseaudio at startup - 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 --- Makefile.am | 5 +++++ configure.ac | 6 ++++++ dialer/main.c | 9 +++++++++ packaging/lemolo.spec | 1 + utils/pulseaudio.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ utils/pulseaudio.h | 8 ++++++++ 6 files changed, 77 insertions(+) create mode 100644 utils/pulseaudio.c create mode 100644 utils/pulseaudio.h diff --git a/Makefile.am b/Makefile.am index a627f54..8957662 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.ac b/configure.ac index e823a4d..cb78dd6 100644 --- a/configure.ac +++ b/configure.ac @@ -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" diff --git a/dialer/main.c b/dialer/main.c index 3d4a55f..bf82e49 100644 --- a/dialer/main.c +++ b/dialer/main.c @@ -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(); diff --git a/packaging/lemolo.spec b/packaging/lemolo.spec index a55dafe..5a5aaf8 100644 --- a/packaging/lemolo.spec +++ b/packaging/lemolo.spec @@ -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 index 0000000..294d1e5 --- /dev/null +++ b/utils/pulseaudio.c @@ -0,0 +1,48 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include + +#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 index 0000000..5dca36b --- /dev/null +++ b/utils/pulseaudio.h @@ -0,0 +1,8 @@ +#ifndef _PULSEAUDIO_H__ +#define _PULSEAUDIO_H__ + +Eina_Bool pa_init(void); + +void pa_shutdown(void); + +#endif -- 2.7.4