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
This commit is contained in:
committed by
Jean-Michel Trivi
parent
34a1b9c951
commit
ede3f24c8d
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user