summaryrefslogtreecommitdiffstats
path: root/audio_a2dp_hw
diff options
context:
space:
mode:
Diffstat (limited to 'audio_a2dp_hw')
-rwxr-xr-x[-rw-r--r--]audio_a2dp_hw/audio_a2dp_hw.c22
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)
{