Commit 1c8a9d5e authored by Anirudh Tadakamala's avatar Anirudh Tadakamala Committed by Commit Bot

Add a retry logic with number of retries set to 1 for AudioTrack creation....

Add a retry logic with number of retries set to 1 for AudioTrack creation. This is to prevent the intermittent issue of alarm sound not going off from occuring.

From stack traces it looked like getOutputForDevice in AudioPolicyManager couldn't find an output at that time. We couldn`t repro this consistently and there was no pattern leading to the conclusion that it`s transient in use case. In the cases we saw, it seemed to happen during some race with other output.  From digging in to the Android source this is totally possible from the HW layer.  Adding a single retry to try to break this case so the user experience is improved.  There are other (leak) cases with the number of system audio tracks possible as well, but that wasn't this use case (and owners releasing shared resources correctly is the only true fix there anyhow).

Bug: 130373632
Change-Id: If5f3a2fcd2f3e50dd86d864638546e839913f6d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1747028Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Commit-Queue: Anirudh Tadakamala <antadaka@google.com>
Cr-Commit-Position: refs/heads/master@{#690772}
parent 2ebb8aff
......@@ -137,6 +137,9 @@ class AudioSinkAudioTrackImpl {
// Additional padding for minimum buffer time, determined experimentally.
private static final long MIN_BUFFERED_TIME_PADDING_USEC = 120000;
// Max retries for AudioTrackBuilder
private static final int MAX_RETRIES_FOR_AUDIO_TRACKS = 1;
private static AudioManager sAudioManager;
private static int sSessionIdMedia = AudioManager.ERROR;
......@@ -344,20 +347,24 @@ class AudioSinkAudioTrackImpl {
+ " with session-id=" + sessionId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
AudioTrack.Builder builder = new AudioTrack.Builder();
builder.setBufferSizeInBytes(bufferSizeInBytes)
.setTransferMode(AUDIO_MODE)
.setAudioAttributes(new AudioAttributes.Builder()
.setUsage(usageType)
.setContentType(contentType)
.build())
.setAudioFormat(new AudioFormat.Builder()
.setEncoding(AUDIO_FORMAT)
.setSampleRate(mSampleRateInHz)
.setChannelMask(CHANNEL_CONFIG)
.build());
if (sessionId != AudioManager.ERROR) builder.setSessionId(sessionId);
mAudioTrack = builder.build();
// Retry if AudioTrack creation fails.
int retries = 0;
do {
AudioTrack.Builder builder = new AudioTrack.Builder();
builder.setBufferSizeInBytes(bufferSizeInBytes)
.setTransferMode(AUDIO_MODE)
.setAudioAttributes(new AudioAttributes.Builder()
.setUsage(usageType)
.setContentType(contentType)
.build())
.setAudioFormat(new AudioFormat.Builder()
.setEncoding(AUDIO_FORMAT)
.setSampleRate(mSampleRateInHz)
.setChannelMask(CHANNEL_CONFIG)
.build());
if (sessionId != AudioManager.ERROR) builder.setSessionId(sessionId);
mAudioTrack = builder.build();
} while (mAudioTrack == null && retries++ < MAX_RETRIES_FOR_AUDIO_TRACKS);
} else {
// Using pre-M API.
if (sessionId == AudioManager.ERROR) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment