summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <arun.raghavan@collabora.co.uk>2013-08-16 15:56:51 +0530
committerArun Raghavan <arun.raghavan@collabora.co.uk>2013-08-16 16:00:35 +0530
commit5ec99d48e489a7ae9db151ce7a5232d9a74f7cb4 (patch)
tree08c3badda1523596b5bd7fbc234e84eaf87390c5
parent324b86579f7b98365c7ac69f692574ddee612bc2 (diff)
Manage modem PCMs for mako in csd-daemon
Trying to manage them in PA while maintaining ordering with libcsd-client calls is too fragile and seems to not be worth the effort.
-rw-r--r--tools/mako/Android.mk6
-rw-r--r--tools/mako/csd-daemon.c81
2 files changed, 86 insertions, 1 deletions
diff --git a/tools/mako/Android.mk b/tools/mako/Android.mk
index 8d04f20..5f3505f 100644
--- a/tools/mako/Android.mk
+++ b/tools/mako/Android.mk
@@ -12,8 +12,12 @@ LOCAL_MODULE_TAGS:=eng debug
LOCAL_SRC_FILES := \
csd-daemon.c
+LOCAL_C_INCLUDES := \
+ external/pulseaudio/alsa-lib/include
+
LOCAL_SHARED_LIBRARIES:= \
- libdl
+ libdl \
+ libasound
LOCAL_PRELINK_MODULE := false
include $(BUILD_EXECUTABLE)
diff --git a/tools/mako/csd-daemon.c b/tools/mako/csd-daemon.c
index 955fd6e..61277ab 100644
--- a/tools/mako/csd-daemon.c
+++ b/tools/mako/csd-daemon.c
@@ -37,6 +37,8 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include <asoundlib.h>
+
#define DEBUG 1
#include "common.h"
@@ -48,6 +50,8 @@ struct state {
int rx_dev, tx_dev;
int start_voice;
int disable_device;
+
+ snd_pcm_t *play, *rec;
};
static struct state state;
@@ -161,6 +165,68 @@ static int init_daemon(void)
return 0;
}
+#define MODEM_PCM "hw:apq8064tablasnd,12"
+
+static int open_pcms(void)
+{
+ if (snd_pcm_open(&state.play, MODEM_PCM, SND_PCM_STREAM_PLAYBACK, 0) < 0) {
+ ERR("Could not open playback device\n");
+ return -1;
+ }
+
+ if (snd_pcm_open(&state.rec, MODEM_PCM, SND_PCM_STREAM_CAPTURE, 0) < 0) {
+ ERR("Could not open capture device\n");
+ return -1;
+ }
+
+ if (snd_pcm_set_params(state.play,
+ SND_PCM_FORMAT_S16_LE,
+ SND_PCM_ACCESS_RW_INTERLEAVED,
+ 1,
+ 8000,
+ 0,
+ 0) < 0) {
+ ERR("Could not set playback params\n");
+ return -1;
+ }
+
+ if (snd_pcm_set_params(state.rec,
+ SND_PCM_FORMAT_S16_LE,
+ SND_PCM_ACCESS_RW_INTERLEAVED,
+ 1,
+ 8000,
+ 0,
+ 0) < 0) {
+ ERR("Could not set capture params\n");
+ return -1;
+ }
+
+ if (snd_pcm_start(state.play) < 0) {
+ ERR("Could not start playback PCM\n");
+ return -1;
+ }
+
+ if (snd_pcm_start(state.rec) < 0) {
+ ERR("Could not start capture PCM\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static void close_pcms(void)
+{
+ if (state.play) {
+ snd_pcm_close(state.play);
+ state.play = NULL;
+ }
+
+ if (state.rec) {
+ snd_pcm_close(state.rec);
+ state.rec = NULL;
+ }
+}
+
/* Return negative value to signal death (currently only returns 0 */
static int process(const char *command)
{
@@ -180,6 +246,11 @@ static int process(const char *command)
if (ret == 0 && state.start_voice) {
state.start_voice = 0;
ret = csd_client_start_voice();
+
+ if (ret == 0) {
+ DBG("Opening PCMs\n");
+ ret = open_pcms();
+ }
}
}
@@ -206,6 +277,11 @@ static int process(const char *command)
if (ret == 0 && state.start_voice) {
state.start_voice = 0;
ret = csd_client_start_voice();
+
+ if (ret == 0) {
+ DBG("Opening PCMs\n");
+ ret = open_pcms();
+ }
}
}
@@ -247,6 +323,11 @@ static int process(const char *command)
} else if (strcmp(command, "stop-voice") == 0) {
ret = csd_client_stop_voice();
+ if (ret == 0) {
+ DBG("Closing PCMs\n");
+ close_pcms();
+ }
+
/* Reset all the things */
state.start_voice = 0;
state.disable_device = 0;