diff options
Diffstat (limited to 'tools/mako/csd-daemon.c')
-rw-r--r-- | tools/mako/csd-daemon.c | 81 |
1 files changed, 81 insertions, 0 deletions
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; |