diff options
author | Mattias Agren <magren@broadcom.com> | 2012-05-31 15:52:45 +0200 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:22 -0700 |
commit | f476c7d052409d27d60cbe8d17c9ed14c663518e (patch) | |
tree | 0ded62e77efe929e37935f7ed9588bebd1b5c50f /audio_a2dp_hw | |
parent | 00f5bc43b14beb053a462b48e100378d34b75e19 (diff) | |
download | external_bluetooth_bluedroid-f476c7d052409d27d60cbe8d17c9ed14c663518e.zip external_bluetooth_bluedroid-f476c7d052409d27d60cbe8d17c9ed14c663518e.tar.gz external_bluetooth_bluedroid-f476c7d052409d27d60cbe8d17c9ed14c663518e.tar.bz2 |
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
Diffstat (limited to 'audio_a2dp_hw')
-rwxr-xr-x[-rw-r--r--] | audio_a2dp_hw/audio_a2dp_hw.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/audio_a2dp_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c index 2441f35..f253663 100644..100755 --- 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) { |