Refactor the methods and reword the comments

This commit is contained in:
Tianyi Feng 2023-05-19 21:56:07 +00:00
parent 9d147f2227
commit ea32f11292
2 changed files with 17 additions and 15 deletions

View file

@ -1885,11 +1885,12 @@ public final class Util {
case 8: case 8:
return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND;
case 10: case 10:
if (Util.SDK_INT > 31) { if (Util.SDK_INT >= 32) {
return AudioFormat.CHANNEL_OUT_5POINT1POINT4; return AudioFormat.CHANNEL_OUT_5POINT1POINT4;
} else { } else {
// This is used by DTS:X P2 with Direct Passthrough Playback. // Before API 32, height channel masks are not available. For those 10-channel streams
// Specifying the audio format as 7.1 for 10 channels does not affect the playback. // supported on the audio output devices (e.g. DTS:X P2), we will use 7.1-surround
// instead.
return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; return AudioFormat.CHANNEL_OUT_7POINT1_SURROUND;
} }
case 12: case 12:

View file

@ -56,10 +56,11 @@ public final class AudioCapabilities {
new AudioCapabilities(new int[] {AudioFormat.ENCODING_PCM_16BIT}, DEFAULT_MAX_CHANNEL_COUNT); new AudioCapabilities(new int[] {AudioFormat.ENCODING_PCM_16BIT}, DEFAULT_MAX_CHANNEL_COUNT);
/** Encodings supported when the device specifies external surround sound. */ /** Encodings supported when the device specifies external surround sound. */
private static final int[] EXTERNAL_SURROUND_SOUND_ENCODINGS = private static final ImmutableList<Integer> EXTERNAL_SURROUND_SOUND_ENCODINGS =
new int[] { ImmutableList.of(
AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_AC3, AudioFormat.ENCODING_E_AC3 AudioFormat.ENCODING_PCM_16BIT,
}; AudioFormat.ENCODING_AC3,
AudioFormat.ENCODING_E_AC3);
/** /**
* All surround sound encodings that a device may be capable of playing mapped to a maximum * All surround sound encodings that a device may be capable of playing mapped to a maximum
@ -105,14 +106,14 @@ public final class AudioCapabilities {
ImmutableSet.Builder<Integer> supportedEncodings = new ImmutableSet.Builder<>(); ImmutableSet.Builder<Integer> supportedEncodings = new ImmutableSet.Builder<>();
if (deviceMaySetExternalSurroundSoundGlobalSetting() if (deviceMaySetExternalSurroundSoundGlobalSetting()
&& Global.getInt(context.getContentResolver(), EXTERNAL_SURROUND_SOUND_KEY, 0) == 1) { && Global.getInt(context.getContentResolver(), EXTERNAL_SURROUND_SOUND_KEY, 0) == 1) {
supportedEncodings.addAll(Ints.asList(EXTERNAL_SURROUND_SOUND_ENCODINGS)); supportedEncodings.addAll(EXTERNAL_SURROUND_SOUND_ENCODINGS);
} }
// AudioTrack.isDirectPlaybackSupported returns true for encodings that are supported for audio // AudioTrack.isDirectPlaybackSupported returns true for encodings that are supported for audio
// offload, as well as for encodings we want to list for passthrough mode. Therefore we only use // offload, as well as for encodings we want to list for passthrough mode. Therefore we only use
// it on TV and automotive devices, which generally shouldn't support audio offload for surround // it on TV and automotive devices, which generally shouldn't support audio offload for surround
// encodings. // encodings.
if (Util.SDK_INT >= 29 && (Util.isTv(context) || Util.isAutomotive(context))) { if (Util.SDK_INT >= 29 && (Util.isTv(context) || Util.isAutomotive(context))) {
supportedEncodings.addAll(Ints.asList(Api29.getDirectPlaybackSupportedEncodings())); supportedEncodings.addAll(Api29.getDirectPlaybackSupportedEncodings());
} }
if (intent != null && intent.getIntExtra(AudioManager.EXTRA_AUDIO_PLUG_STATE, 0) == 1) { if (intent != null && intent.getIntExtra(AudioManager.EXTRA_AUDIO_PLUG_STATE, 0) == 1) {
@ -369,8 +370,8 @@ public final class AudioCapabilities {
private Api29() {} private Api29() {}
@DoNotInline @DoNotInline
public static int[] getDirectPlaybackSupportedEncodings() { public static ImmutableList<Integer> getDirectPlaybackSupportedEncodings() {
int[] encodings = Api29.getAllSurroundEncodingsMaybeSupported(); ImmutableList<Integer> encodings = Api29.getAllSurroundEncodingsMaybeSupported();
ImmutableList.Builder<Integer> supportedEncodingsListBuilder = ImmutableList.builder(); ImmutableList.Builder<Integer> supportedEncodingsListBuilder = ImmutableList.builder();
for (int encoding : encodings) { for (int encoding : encodings) {
if (AudioTrack.isDirectPlaybackSupported( if (AudioTrack.isDirectPlaybackSupported(
@ -384,7 +385,7 @@ public final class AudioCapabilities {
} }
} }
supportedEncodingsListBuilder.add(AudioFormat.ENCODING_PCM_16BIT); supportedEncodingsListBuilder.add(AudioFormat.ENCODING_PCM_16BIT);
return Ints.toArray(supportedEncodingsListBuilder.build()); return supportedEncodingsListBuilder.build();
} }
/** /**
@ -410,9 +411,9 @@ public final class AudioCapabilities {
return 0; return 0;
} }
/** Returns an array list of surround encodings that maybe supported. */ /** Returns a list of surround encodings that maybe supported. */
@DoNotInline @DoNotInline
private static int[] getAllSurroundEncodingsMaybeSupported() { private static ImmutableList<Integer> getAllSurroundEncodingsMaybeSupported() {
ImmutableList.Builder<Integer> encodings = new ImmutableList.Builder<>(); ImmutableList.Builder<Integer> encodings = new ImmutableList.Builder<>();
for (int encoding : ALL_SURROUND_ENCODINGS_AND_MAX_CHANNELS.keySet()) { for (int encoding : ALL_SURROUND_ENCODINGS_AND_MAX_CHANNELS.keySet()) {
// AudioFormat.ENCODING_DTS_UHD_P2 is supported from API 34. // AudioFormat.ENCODING_DTS_UHD_P2 is supported from API 34.
@ -421,7 +422,7 @@ public final class AudioCapabilities {
} }
encodings.add(encoding); encodings.add(encoding);
} }
return Ints.toArray(encodings.build()); return encodings.build();
} }
} }
} }