From f476c7d052409d27d60cbe8d17c9ed14c663518e Mon Sep 17 00:00:00 2001 From: Mattias Agren Date: Thu, 31 May 2012 15:52:45 +0200 Subject: Ensure we ack back suspend request if we are not ready for it Block audioflinger/a2dp hal from trying to restart stream while we are remotely suspended. Change-Id: I17577306f1be248857a8484a22a8a14cb956ec19 --- audio_a2dp_hw/audio_a2dp_hw.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) mode change 100644 => 100755 audio_a2dp_hw/audio_a2dp_hw.c (limited to 'audio_a2dp_hw') diff --git a/audio_a2dp_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c old mode 100644 new mode 100755 index 2441f35..f253663 --- a/audio_a2dp_hw/audio_a2dp_hw.c +++ b/audio_a2dp_hw/audio_a2dp_hw.c @@ -89,6 +89,8 @@ #define FNLOG() LOGV("%s", __FUNCTION__); #define DEBUG(fmt, ...) LOGD ("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) +#define ASSERTC(cond, msg, val) if (!(cond)) {LOGE("### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);} + /***************************************************************************** ** Local type definitions ******************************************************************************/ @@ -194,6 +196,16 @@ static void ts_log(char *tag, int val, struct timespec *pprev_opt) } } +static int calc_audiotime(struct a2dp_config cfg, int bytes) +{ + int chan_count = popcount(cfg.channel_flags); + + ASSERTC(cfg.format == AUDIO_FORMAT_PCM_16_BIT, + "unsupported sample sz", cfg.format); + + return bytes*(1000000/(chan_count*2))/cfg.rate; +} + /***************************************************************************** ** ** bluedroid stack adaptation @@ -467,7 +479,17 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, (out->state == AUDIO_A2DP_STATE_STANDBY)) { if (start_audio_datapath(out) < 0) + { + /* emulate time this write represents to avoid very fast write + failures during transition periods or remote suspend */ + + int us_delay = calc_audiotime(out->cfg, bytes); + + DEBUG("emulate a2dp write delay (%d us)", us_delay); + + usleep(us_delay); return -1; + } } else if (out->state != AUDIO_A2DP_STATE_STARTED) { -- cgit v1.1