am 2411c336: Merge "Verify AudioTrack only uses a valid multichannel configuration" into jb-dev
* commit '2411c3361eb2c15b09a8bfadf5c7c4a3de092ea0': Verify AudioTrack only uses a valid multichannel configuration
This commit is contained in:
@@ -401,7 +401,7 @@ public class AudioTrack
|
|||||||
mChannels = AudioFormat.CHANNEL_OUT_STEREO;
|
mChannels = AudioFormat.CHANNEL_OUT_STEREO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ((channelConfig & SUPPORTED_OUT_CHANNELS) != channelConfig) {
|
if (!isMultichannelConfigSupported(channelConfig)) {
|
||||||
// input channel configuration features unsupported channels
|
// input channel configuration features unsupported channels
|
||||||
mChannelCount = 0;
|
mChannelCount = 0;
|
||||||
mChannels = AudioFormat.CHANNEL_INVALID;
|
mChannels = AudioFormat.CHANNEL_INVALID;
|
||||||
@@ -438,6 +438,37 @@ public class AudioTrack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to check that the channel configuration (a.k.a channel mask) is supported
|
||||||
|
* @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) {
|
||||||
|
// check for unsupported channels
|
||||||
|
if ((channelConfig & SUPPORTED_OUT_CHANNELS) != channelConfig) {
|
||||||
|
Log.e(TAG, "Channel configuration features unsupported channels");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// check for unsupported multichannel combinations:
|
||||||
|
// - FL/FR must be present
|
||||||
|
// - L/R channels must be paired (e.g. no single L channel)
|
||||||
|
final int frontPair =
|
||||||
|
AudioFormat.CHANNEL_OUT_FRONT_LEFT | AudioFormat.CHANNEL_OUT_FRONT_RIGHT;
|
||||||
|
if ((channelConfig & frontPair) != frontPair) {
|
||||||
|
Log.e(TAG, "Front channels must be present in multichannel configurations");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final int backPair =
|
||||||
|
AudioFormat.CHANNEL_OUT_BACK_LEFT | AudioFormat.CHANNEL_OUT_BACK_RIGHT;
|
||||||
|
if ((channelConfig & backPair) != 0) {
|
||||||
|
if ((channelConfig & backPair) != backPair) {
|
||||||
|
Log.e(TAG, "Rear channels can't be used independently");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Convenience method for the contructor's audio buffer size check.
|
// Convenience method for the contructor's audio buffer size check.
|
||||||
// preconditions:
|
// preconditions:
|
||||||
|
|||||||
Reference in New Issue
Block a user