From ede3f24c8d6b56aee695ea3a05b5417b7d32cdf9 Mon Sep 17 00:00:00 2001 From: Dean Wheatley Date: Fri, 2 Oct 2020 15:31:27 +1000 Subject: Default compressed audio bytes per sample to 1 To support AudioTrack builder for compressed audio (e.g. AC3) without specifiying setBufferSizeInBytes, default the bytesPerSample to 1, and handle the possible getBytesPerSample exception. Test: atest AudioTrackTest#testAc3BuilderNoBufferSize Bug: 169875806 Change-Id: I1b28d94c4dbf3a72e807ef445163e1dd84e4553b --- media/java/android/media/AudioTrack.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java index 1c0a526f536c..eff56f3d8c19 100644 --- a/media/java/android/media/AudioTrack.java +++ b/media/java/android/media/AudioTrack.java @@ -1261,14 +1261,20 @@ public class AudioTrack extends PlayerBase // TODO: Check mEncapsulationMode compatibility with MODE_STATIC, etc? - try { - // If the buffer size is not specified in streaming mode, - // use a single frame for the buffer size and let the - // native code figure out the minimum buffer size. - if (mMode == MODE_STREAM && mBufferSizeInBytes == 0) { - mBufferSizeInBytes = mFormat.getChannelCount() - * mFormat.getBytesPerSample(mFormat.getEncoding()); + // If the buffer size is not specified in streaming mode, + // use a single frame for the buffer size and let the + // native code figure out the minimum buffer size. + if (mMode == MODE_STREAM && mBufferSizeInBytes == 0) { + int bytesPerSample = 1; + try { + bytesPerSample = mFormat.getBytesPerSample(mFormat.getEncoding()); + } catch (IllegalArgumentException e) { + // do nothing } + mBufferSizeInBytes = mFormat.getChannelCount() * bytesPerSample; + } + + try { final AudioTrack track = new AudioTrack( mAttributes, mFormat, mBufferSizeInBytes, mMode, mSessionId, mOffload, mEncapsulationMode, mTunerConfiguration); -- cgit v1.2.3-59-g8ed1b