Merge "AudioTrack: 24 channel index masks, compressed formats"
This commit is contained in:
@@ -127,6 +127,9 @@ public class AudioSystem
|
|||||||
public static final int SAMPLE_RATE_HZ_MIN = native_getMinSampleRate();
|
public static final int SAMPLE_RATE_HZ_MIN = native_getMinSampleRate();
|
||||||
private static native int 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
|
// Expose only the getter method publicly so we can change it in the future
|
||||||
private static final int NUM_STREAM_TYPES = 12;
|
private static final int NUM_STREAM_TYPES = 12;
|
||||||
|
|
||||||
|
|||||||
@@ -1712,9 +1712,10 @@ public class AudioTrack extends PlayerBase
|
|||||||
mChannelCount = 0;
|
mChannelCount = 0;
|
||||||
break; // channel index configuration only
|
break; // channel index configuration only
|
||||||
}
|
}
|
||||||
if (!isMultichannelConfigSupported(channelConfig)) {
|
if (!isMultichannelConfigSupported(channelConfig, audioFormat)) {
|
||||||
// input channel configuration features unsupported channels
|
throw new IllegalArgumentException(
|
||||||
throw new IllegalArgumentException("Unsupported channel configuration.");
|
"Unsupported channel mask configuration " + channelConfig
|
||||||
|
+ " for encoding " + audioFormat);
|
||||||
}
|
}
|
||||||
mChannelMask = channelConfig;
|
mChannelMask = channelConfig;
|
||||||
mChannelCount = AudioFormat.channelCountFromOutChannelMask(channelConfig);
|
mChannelCount = AudioFormat.channelCountFromOutChannelMask(channelConfig);
|
||||||
@@ -1722,13 +1723,17 @@ public class AudioTrack extends PlayerBase
|
|||||||
// check the channel index configuration (if present)
|
// check the channel index configuration (if present)
|
||||||
mChannelIndexMask = channelIndexMask;
|
mChannelIndexMask = channelIndexMask;
|
||||||
if (mChannelIndexMask != 0) {
|
if (mChannelIndexMask != 0) {
|
||||||
// restrictive: indexMask could allow up to AUDIO_CHANNEL_BITS_LOG2
|
// As of S, we accept up to 24 channel index mask.
|
||||||
final int indexMask = (1 << AudioSystem.OUT_CHANNEL_COUNT_MAX) - 1;
|
final int fullIndexMask = (1 << AudioSystem.FCC_24) - 1;
|
||||||
if ((channelIndexMask & ~indexMask) != 0) {
|
final int channelIndexCount = Integer.bitCount(channelIndexMask);
|
||||||
throw new IllegalArgumentException("Unsupported channel index configuration "
|
final boolean accepted = (channelIndexMask & ~fullIndexMask) == 0
|
||||||
+ channelIndexMask);
|
&& (!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) {
|
if (mChannelCount == 0) {
|
||||||
mChannelCount = channelIndexCount;
|
mChannelCount = channelIndexCount;
|
||||||
} else if (mChannelCount != channelIndexCount) {
|
} else if (mChannelCount != channelIndexCount) {
|
||||||
@@ -1781,16 +1786,19 @@ public class AudioTrack extends PlayerBase
|
|||||||
* @param channelConfig the mask to validate
|
* @param channelConfig the mask to validate
|
||||||
* @return false if the AudioTrack can't be used with such a mask
|
* @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
|
// check for unsupported channels
|
||||||
if ((channelConfig & SUPPORTED_OUT_CHANNELS) != channelConfig) {
|
if ((channelConfig & SUPPORTED_OUT_CHANNELS) != channelConfig) {
|
||||||
loge("Channel configuration features unsupported channels");
|
loge("Channel configuration features unsupported channels");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int channelCount = AudioFormat.channelCountFromOutChannelMask(channelConfig);
|
final int channelCount = AudioFormat.channelCountFromOutChannelMask(channelConfig);
|
||||||
if (channelCount > AudioSystem.OUT_CHANNEL_COUNT_MAX) {
|
final int channelCountLimit = AudioFormat.isEncodingLinearFrames(encoding)
|
||||||
loge("Channel configuration contains too many channels " +
|
? AudioSystem.OUT_CHANNEL_COUNT_MAX // PCM limited to OUT_CHANNEL_COUNT_MAX
|
||||||
channelCount + ">" + AudioSystem.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;
|
return false;
|
||||||
}
|
}
|
||||||
// check for unsupported multichannel combinations:
|
// check for unsupported multichannel combinations:
|
||||||
@@ -2301,7 +2309,7 @@ public class AudioTrack extends PlayerBase
|
|||||||
channelCount = 2;
|
channelCount = 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!isMultichannelConfigSupported(channelConfig)) {
|
if (!isMultichannelConfigSupported(channelConfig, audioFormat)) {
|
||||||
loge("getMinBufferSize(): Invalid channel configuration.");
|
loge("getMinBufferSize(): Invalid channel configuration.");
|
||||||
return ERROR_BAD_VALUE;
|
return ERROR_BAD_VALUE;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user