Rename some variables and change to use ImmutableList.Builder.

This commit is contained in:
Cedric T 2023-05-10 09:40:15 +08:00 committed by Tianyi Feng
parent f47930e587
commit abc46d4319

View File

@ -42,10 +42,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/** Represents the set of audio formats that a device is capable of playing. */ /** Represents the set of audio formats that a device is capable of playing. */
@UnstableApi @UnstableApi
@ -59,7 +56,7 @@ 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_CAPABILITIES = private static final int[] EXTERNAL_SURROUND_SOUND_ENCODINGS =
new int[]{ new int[]{
AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_AC3, AudioFormat.ENCODING_E_AC3 AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_AC3, AudioFormat.ENCODING_E_AC3
}; };
@ -98,13 +95,13 @@ public final class AudioCapabilities {
} }
private static AudioCapabilities getExternalSurroundCapabilities(@Nullable Intent intent) { private static AudioCapabilities getExternalSurroundCapabilities(@Nullable Intent intent) {
int[] supportedEncodings = EXTERNAL_SURROUND_SOUND_CAPABILITIES; int[] supportedEncodings = EXTERNAL_SURROUND_SOUND_ENCODINGS;
if (Util.SDK_INT >= 29) { if (Util.SDK_INT >= 29) {
// Check if DTS Encodings are supported via Direct Playback. // Check if DTS Encodings are supported via Direct Playback.
int[] dtsTypes = {AudioFormat.ENCODING_DTS, AudioFormat.ENCODING_DTS_HD}; int[] dtsEncodings = {AudioFormat.ENCODING_DTS, AudioFormat.ENCODING_DTS_HD};
supportedEncodings = Util.nullSafeIntegerArrayConcatenation(supportedEncodings, supportedEncodings = Util.nullSafeIntegerArrayConcatenation(supportedEncodings,
Api29.getDirectPlaybackSupportedEncodings(dtsTypes)); Api29.getDirectPlaybackSupportedEncodings(dtsEncodings));
} }
supportedEncodings = Arrays.stream(supportedEncodings).distinct().toArray(); supportedEncodings = Arrays.stream(supportedEncodings).distinct().toArray();
return new AudioCapabilities(supportedEncodings,/* defaultValue= */ DEFAULT_MAX_CHANNEL_COUNT); return new AudioCapabilities(supportedEncodings,/* defaultValue= */ DEFAULT_MAX_CHANNEL_COUNT);
@ -415,8 +412,8 @@ public final class AudioCapabilities {
/** /**
* Returns an array list of surround encodings that maybe supported. * Returns an array list of surround encodings that maybe supported.
*/ */
private static List<Integer> getAllSurroundEncodingsMaybeSupported() { private static ImmutableList<Integer> getAllSurroundEncodingsMaybeSupported() {
ArrayList<Integer> encodings = new ArrayList<>(); 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.
if (Util.SDK_INT < 34 && encoding == C.ENCODING_DTS_UHD_P2) { if (Util.SDK_INT < 34 && encoding == C.ENCODING_DTS_UHD_P2) {
@ -424,7 +421,7 @@ public final class AudioCapabilities {
} }
encodings.add(encoding); encodings.add(encoding);
} }
return Collections.unmodifiableList(encodings); return encodings.build();
} }
} }
} }