From 95cbb7d41394eec4f74ff67d97e53f023b396416 Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Wed, 22 Jan 2014 11:34:49 +0100 Subject: [PATCH] android/hal-audio: Add resume to codec callbacks Once stream is resumed it may be required to reset some state of codec, i.e. in case of SBC we need to reset monotonic clock and frames count which are used for synchronization. --- android/hal-audio.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/android/hal-audio.c b/android/hal-audio.c index 64afcf664..bd1e7d162 100644 --- a/android/hal-audio.c +++ b/android/hal-audio.c @@ -125,6 +125,9 @@ struct sbc_data { uint8_t *out_buf; unsigned frame_duration; + + struct timespec start; + unsigned frames_sent; }; static int sbc_get_presets(struct audio_preset *preset, size_t *len); @@ -133,6 +136,7 @@ static int sbc_codec_init(struct audio_preset *preset, uint16_t mtu, static int sbc_cleanup(void *codec_data); static int sbc_get_config(void *codec_data, struct audio_input_config *config); +static void sbc_resume(void *codec_data); struct audio_codec { uint8_t type; @@ -144,6 +148,7 @@ struct audio_codec { int (*cleanup) (void *codec_data); int (*get_config) (void *codec_data, struct audio_input_config *config); + void (*resume) (void *codec_data); ssize_t (*write_data) (void *codec_data, const void *buffer, size_t bytes); }; @@ -157,6 +162,7 @@ static const struct audio_codec audio_codecs[] = { .init = sbc_codec_init, .cleanup = sbc_cleanup, .get_config = sbc_get_config, + .resume = sbc_resume, } }; @@ -352,6 +358,17 @@ static int sbc_get_config(void *codec_data, return AUDIO_STATUS_SUCCESS; } +static void sbc_resume(void *codec_data) +{ + struct sbc_data *sbc_data = (struct sbc_data *) codec_data; + + DBG(""); + + clock_gettime(CLOCK_MONOTONIC, &sbc_data->start); + + sbc_data->frames_sent = 0; +} + static void audio_ipc_cleanup(void) { if (audio_sk >= 0) { @@ -674,6 +691,8 @@ static ssize_t out_write(struct audio_stream_out *stream, const void *buffer, if (ipc_resume_stream_cmd(out->ep->id) != AUDIO_STATUS_SUCCESS) return -1; + out->ep->codec->resume(out->ep->codec_data); + out->audio_state = AUDIO_A2DP_STATE_STARTED; } -- 2.47.3