Merge "AudioTrack: 24 channel index masks, compressed formats" am: e477e9686f am: dd8fa96c01 am: fde2ef0250

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1702808

Change-Id: I7b14b0c86e5ac1e089702e6a285bf58174fcd45c
This commit is contained in:
Andy Hung
2021-05-11 22:49:13 +00:00
committed by Automerger Merge Worker
2 changed files with 25 additions and 14 deletions

View File

@@ -131,6 +131,9 @@ public class AudioSystem
public static final int SAMPLE_RATE_HZ_MIN = native_getMinSampleRate();
private static native int native_getMinSampleRate();
/** @hide */
public static final int FCC_24 = 24; // fixed channel count 24; do not change.
// Expose only the getter method publicly so we can change it in the future
private static final int NUM_STREAM_TYPES = 12;

View File

@@ -1720,9 +1720,10 @@ public class AudioTrack extends PlayerBase
mChannelCount = 0;
break; // channel index configuration only
}
if (!isMultichannelConfigSupported(channelConfig)) {
// input channel configuration features unsupported channels
throw new IllegalArgumentException("Unsupported channel configuration.");
if (!isMultichannelConfigSupported(channelConfig, audioFormat)) {
throw new IllegalArgumentException(
"Unsupported channel mask configuration " + channelConfig
+ " for encoding " + audioFormat);
}
mChannelMask = channelConfig;
mChannelCount = AudioFormat.channelCountFromOutChannelMask(channelConfig);
@@ -1730,13 +1731,17 @@ public class AudioTrack extends PlayerBase
// check the channel index configuration (if present)
mChannelIndexMask = channelIndexMask;
if (mChannelIndexMask != 0) {
// restrictive: indexMask could allow up to AUDIO_CHANNEL_BITS_LOG2
final int indexMask = (1 << AudioSystem.OUT_CHANNEL_COUNT_MAX) - 1;
if ((channelIndexMask & ~indexMask) != 0) {
throw new IllegalArgumentException("Unsupported channel index configuration "
+ channelIndexMask);
// As of S, we accept up to 24 channel index mask.
final int fullIndexMask = (1 << AudioSystem.FCC_24) - 1;
final int channelIndexCount = Integer.bitCount(channelIndexMask);
final boolean accepted = (channelIndexMask & ~fullIndexMask) == 0
&& (!AudioFormat.isEncodingLinearFrames(audioFormat) // compressed OK
|| channelIndexCount <= AudioSystem.OUT_CHANNEL_COUNT_MAX); // PCM
if (!accepted) {
throw new IllegalArgumentException(
"Unsupported channel index mask configuration " + channelIndexMask
+ " for encoding " + audioFormat);
}
int channelIndexCount = Integer.bitCount(channelIndexMask);
if (mChannelCount == 0) {
mChannelCount = channelIndexCount;
} else if (mChannelCount != channelIndexCount) {
@@ -1789,16 +1794,19 @@ public class AudioTrack extends PlayerBase
* @param channelConfig the mask to validate
* @return false if the AudioTrack can't be used with such a mask
*/
private static boolean isMultichannelConfigSupported(int channelConfig) {
private static boolean isMultichannelConfigSupported(int channelConfig, int encoding) {
// check for unsupported channels
if ((channelConfig & SUPPORTED_OUT_CHANNELS) != channelConfig) {
loge("Channel configuration features unsupported channels");
return false;
}
final int channelCount = AudioFormat.channelCountFromOutChannelMask(channelConfig);
if (channelCount > AudioSystem.OUT_CHANNEL_COUNT_MAX) {
loge("Channel configuration contains too many channels " +
channelCount + ">" + AudioSystem.OUT_CHANNEL_COUNT_MAX);
final int channelCountLimit = AudioFormat.isEncodingLinearFrames(encoding)
? AudioSystem.OUT_CHANNEL_COUNT_MAX // PCM limited to OUT_CHANNEL_COUNT_MAX
: AudioSystem.FCC_24; // Compressed limited to 24 channels
if (channelCount > channelCountLimit) {
loge("Channel configuration contains too many channels for encoding "
+ encoding + "(" + channelCount + " > " + channelCountLimit + ")");
return false;
}
// check for unsupported multichannel combinations:
@@ -2310,7 +2318,7 @@ public class AudioTrack extends PlayerBase
channelCount = 2;
break;
default:
if (!isMultichannelConfigSupported(channelConfig)) {
if (!isMultichannelConfigSupported(channelConfig, audioFormat)) {
loge("getMinBufferSize(): Invalid channel configuration.");
return ERROR_BAD_VALUE;
} else {