-
Notifications
You must be signed in to change notification settings - Fork 301
/
DefaultTrackSelector.java
4272 lines (3930 loc) · 176 KB
/
DefaultTrackSelector.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.media3.exoplayer.trackselection;
import static androidx.media3.common.TrackSelectionParameters.AudioOffloadPreferences.AUDIO_OFFLOAD_MODE_DISABLED;
import static androidx.media3.common.TrackSelectionParameters.AudioOffloadPreferences.AUDIO_OFFLOAD_MODE_REQUIRED;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.common.util.Util.castNonNull;
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_GAPLESS_SUPPORTED;
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_NOT_SUPPORTED;
import static androidx.media3.exoplayer.RendererCapabilities.AUDIO_OFFLOAD_SPEED_CHANGE_SUPPORTED;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.util.Collections.max;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.Spatializer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import androidx.annotation.GuardedBy;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.Bundleable;
import androidx.media3.common.C;
import androidx.media3.common.C.FormatSupport;
import androidx.media3.common.C.RoleFlags;
import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.Timeline;
import androidx.media3.common.TrackGroup;
import androidx.media3.common.TrackSelectionOverride;
import androidx.media3.common.TrackSelectionParameters;
import androidx.media3.common.TrackSelectionParameters.AudioOffloadPreferences;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.BundleCollectionUtil;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.NullableType;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.ExoPlaybackException;
import androidx.media3.exoplayer.Renderer;
import androidx.media3.exoplayer.RendererCapabilities;
import androidx.media3.exoplayer.RendererCapabilities.AdaptiveSupport;
import androidx.media3.exoplayer.RendererCapabilities.Capabilities;
import androidx.media3.exoplayer.RendererConfiguration;
import androidx.media3.exoplayer.audio.AudioSink;
import androidx.media3.exoplayer.source.MediaSource.MediaPeriodId;
import androidx.media3.exoplayer.source.TrackGroupArray;
import com.google.common.base.Predicate;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
import com.google.common.primitives.Ints;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
// LINT.IfChange(javadoc)
/**
* A default {@link TrackSelector} suitable for most use cases.
*
* <h2>Modifying parameters</h2>
*
* Track selection parameters should be modified by obtaining a {@link
* TrackSelectionParameters.Builder} initialized with the current {@link TrackSelectionParameters}
* from the player. The desired modifications can be made on the builder, and the resulting {@link
* TrackSelectionParameters} can then be built and set on the player:
*
* <pre>{@code
* player.setTrackSelectionParameters(
* player.getTrackSelectionParameters()
* .buildUpon()
* .setMaxVideoSizeSd()
* .setPreferredAudioLanguage("de")
* .build());
* }</pre>
*
* Some specialized parameters are only available in the extended {@link Parameters} class, which
* can be retrieved and modified in a similar way by calling methods directly on this class:
*
* <pre>{@code
* defaultTrackSelector.setParameters(
* defaultTrackSelector.getParameters()
* .buildUpon()
* .setTunnelingEnabled(true)
* .build());
* }</pre>
*/
@UnstableApi
public class DefaultTrackSelector extends MappingTrackSelector
implements RendererCapabilities.Listener {
private static final String TAG = "DefaultTrackSelector";
private static final String AUDIO_CHANNEL_COUNT_CONSTRAINTS_WARN_MESSAGE =
"Audio channel count constraints cannot be applied without reference to Context. Build the"
+ " track selector instance with one of the non-deprecated constructors that take a"
+ " Context argument.";
/**
* @deprecated Use {@link Parameters.Builder} instead.
*/
@Deprecated
public static final class ParametersBuilder extends TrackSelectionParameters.Builder {
private final Parameters.Builder delegate;
/**
* @deprecated {@link Context} constraints will not be set using this constructor. Use {@link
* #ParametersBuilder(Context)} instead.
*/
@Deprecated
@SuppressWarnings({"deprecation"})
public ParametersBuilder() {
delegate = new Parameters.Builder();
}
/**
* Creates a builder with default initial values.
*
* @param context Any context.
*/
@SuppressWarnings({"deprecation"}) // Supporting deprecated builder pattern
public ParametersBuilder(Context context) {
delegate = new Parameters.Builder(context);
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
protected ParametersBuilder set(TrackSelectionParameters parameters) {
delegate.set(parameters);
return this;
}
// Video
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder setMaxVideoSizeSd() {
delegate.setMaxVideoSizeSd();
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder clearVideoSizeConstraints() {
delegate.clearVideoSizeConstraints();
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder setMaxVideoSize(
int maxVideoWidth, int maxVideoHeight) {
delegate.setMaxVideoSize(maxVideoWidth, maxVideoHeight);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder setMaxVideoFrameRate(int maxVideoFrameRate) {
delegate.setMaxVideoFrameRate(maxVideoFrameRate);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder setMaxVideoBitrate(int maxVideoBitrate) {
delegate.setMaxVideoBitrate(maxVideoBitrate);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder setMinVideoSize(
int minVideoWidth, int minVideoHeight) {
delegate.setMinVideoSize(minVideoWidth, minVideoHeight);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder setMinVideoFrameRate(int minVideoFrameRate) {
delegate.setMinVideoFrameRate(minVideoFrameRate);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder setMinVideoBitrate(int minVideoBitrate) {
delegate.setMinVideoBitrate(minVideoBitrate);
return this;
}
/**
* Sets whether to exceed the {@link #setMaxVideoBitrate}, {@link #setMaxVideoSize(int, int)}
* and {@link #setMaxVideoFrameRate} constraints when no selection can be made otherwise.
*
* @param exceedVideoConstraintsIfNecessary Whether to exceed video constraints when no
* selection can be made otherwise.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setExceedVideoConstraintsIfNecessary(
boolean exceedVideoConstraintsIfNecessary) {
delegate.setExceedVideoConstraintsIfNecessary(exceedVideoConstraintsIfNecessary);
return this;
}
/**
* Sets whether to allow adaptive video selections containing mixed MIME types.
*
* <p>Adaptations between different MIME types may not be completely seamless, in which case
* {@link #setAllowVideoNonSeamlessAdaptiveness(boolean)} also needs to be {@code true} for
* mixed MIME type selections to be made.
*
* @param allowVideoMixedMimeTypeAdaptiveness Whether to allow adaptive video selections
* containing mixed MIME types.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setAllowVideoMixedMimeTypeAdaptiveness(
boolean allowVideoMixedMimeTypeAdaptiveness) {
delegate.setAllowVideoMixedMimeTypeAdaptiveness(allowVideoMixedMimeTypeAdaptiveness);
return this;
}
/**
* Sets whether to allow adaptive video selections where adaptation may not be completely
* seamless.
*
* @param allowVideoNonSeamlessAdaptiveness Whether to allow adaptive video selections where
* adaptation may not be completely seamless.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setAllowVideoNonSeamlessAdaptiveness(
boolean allowVideoNonSeamlessAdaptiveness) {
delegate.setAllowVideoNonSeamlessAdaptiveness(allowVideoNonSeamlessAdaptiveness);
return this;
}
/**
* Sets whether to allow adaptive video selections with mixed levels of {@link
* RendererCapabilities.DecoderSupport} and {@link
* RendererCapabilities.HardwareAccelerationSupport}.
*
* @param allowVideoMixedDecoderSupportAdaptiveness Whether to allow adaptive video selections
* with mixed levels of decoder and hardware acceleration support.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setAllowVideoMixedDecoderSupportAdaptiveness(
boolean allowVideoMixedDecoderSupportAdaptiveness) {
delegate.setAllowVideoMixedDecoderSupportAdaptiveness(
allowVideoMixedDecoderSupportAdaptiveness);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setViewportSizeToPhysicalDisplaySize(
Context context, boolean viewportOrientationMayChange) {
delegate.setViewportSizeToPhysicalDisplaySize(context, viewportOrientationMayChange);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder clearViewportSizeConstraints() {
delegate.clearViewportSizeConstraints();
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setViewportSize(
int viewportWidth, int viewportHeight, boolean viewportOrientationMayChange) {
delegate.setViewportSize(viewportWidth, viewportHeight, viewportOrientationMayChange);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredVideoMimeType(@Nullable String mimeType) {
delegate.setPreferredVideoMimeType(mimeType);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredVideoMimeTypes(String... mimeTypes) {
delegate.setPreferredVideoMimeTypes(mimeTypes);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public DefaultTrackSelector.ParametersBuilder setPreferredVideoRoleFlags(
@RoleFlags int preferredVideoRoleFlags) {
delegate.setPreferredVideoRoleFlags(preferredVideoRoleFlags);
return this;
}
// Audio
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredAudioLanguage(@Nullable String preferredAudioLanguage) {
delegate.setPreferredAudioLanguage(preferredAudioLanguage);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredAudioLanguages(String... preferredAudioLanguages) {
delegate.setPreferredAudioLanguages(preferredAudioLanguages);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredAudioRoleFlags(@C.RoleFlags int preferredAudioRoleFlags) {
delegate.setPreferredAudioRoleFlags(preferredAudioRoleFlags);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setMaxAudioChannelCount(int maxAudioChannelCount) {
delegate.setMaxAudioChannelCount(maxAudioChannelCount);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setMaxAudioBitrate(int maxAudioBitrate) {
delegate.setMaxAudioBitrate(maxAudioBitrate);
return this;
}
/**
* Sets whether to exceed the {@link #setMaxAudioChannelCount(int)} and {@link
* #setMaxAudioBitrate(int)} constraints when no selection can be made otherwise.
*
* @param exceedAudioConstraintsIfNecessary Whether to exceed audio constraints when no
* selection can be made otherwise.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setExceedAudioConstraintsIfNecessary(
boolean exceedAudioConstraintsIfNecessary) {
delegate.setExceedAudioConstraintsIfNecessary(exceedAudioConstraintsIfNecessary);
return this;
}
/**
* Sets whether to allow adaptive audio selections containing mixed MIME types.
*
* <p>Adaptations between different MIME types may not be completely seamless, in which case
* {@link Parameters.Builder#setAllowAudioNonSeamlessAdaptiveness(boolean)} also needs to be
* {@code true} for mixed MIME type selections to be made.
*
* @param allowAudioMixedMimeTypeAdaptiveness Whether to allow adaptive audio selections
* containing mixed MIME types.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setAllowAudioMixedMimeTypeAdaptiveness(
boolean allowAudioMixedMimeTypeAdaptiveness) {
delegate.setAllowAudioMixedMimeTypeAdaptiveness(allowAudioMixedMimeTypeAdaptiveness);
return this;
}
/**
* Sets whether to allow adaptive audio selections containing mixed sample rates.
*
* <p>Adaptations between different sample rates may not be completely seamless.
*
* @param allowAudioMixedSampleRateAdaptiveness Whether to allow adaptive audio selections
* containing mixed sample rates.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setAllowAudioMixedSampleRateAdaptiveness(
boolean allowAudioMixedSampleRateAdaptiveness) {
delegate.setAllowAudioMixedSampleRateAdaptiveness(allowAudioMixedSampleRateAdaptiveness);
return this;
}
/**
* Sets whether to allow adaptive audio selections containing mixed channel counts.
*
* <p>Adaptations between different channel counts may not be completely seamless.
*
* @param allowAudioMixedChannelCountAdaptiveness Whether to allow adaptive audio selections
* containing mixed channel counts.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setAllowAudioMixedChannelCountAdaptiveness(
boolean allowAudioMixedChannelCountAdaptiveness) {
delegate.setAllowAudioMixedChannelCountAdaptiveness(allowAudioMixedChannelCountAdaptiveness);
return this;
}
/**
* Sets whether to allow adaptive audio selections with mixed levels of {@link
* RendererCapabilities.DecoderSupport} and {@link
* RendererCapabilities.HardwareAccelerationSupport}.
*
* @param allowAudioMixedDecoderSupportAdaptiveness Whether to allow adaptive audio selections
* with mixed levels of decoder and hardware acceleration support.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setAllowAudioMixedDecoderSupportAdaptiveness(
boolean allowAudioMixedDecoderSupportAdaptiveness) {
delegate.setAllowAudioMixedDecoderSupportAdaptiveness(
allowAudioMixedDecoderSupportAdaptiveness);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredAudioMimeType(@Nullable String mimeType) {
delegate.setPreferredAudioMimeType(mimeType);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredAudioMimeTypes(String... mimeTypes) {
delegate.setPreferredAudioMimeTypes(mimeTypes);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setAudioOffloadPreferences(
AudioOffloadPreferences audioOffloadPreferences) {
delegate.setAudioOffloadPreferences(audioOffloadPreferences);
return this;
}
// Text
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredTextLanguageAndRoleFlagsToCaptioningManagerSettings(
Context context) {
delegate.setPreferredTextLanguageAndRoleFlagsToCaptioningManagerSettings(context);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredTextLanguage(@Nullable String preferredTextLanguage) {
delegate.setPreferredTextLanguage(preferredTextLanguage);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredTextLanguages(String... preferredTextLanguages) {
delegate.setPreferredTextLanguages(preferredTextLanguages);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPreferredTextRoleFlags(@C.RoleFlags int preferredTextRoleFlags) {
delegate.setPreferredTextRoleFlags(preferredTextRoleFlags);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setIgnoredTextSelectionFlags(
@C.SelectionFlags int ignoredTextSelectionFlags) {
delegate.setIgnoredTextSelectionFlags(ignoredTextSelectionFlags);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setSelectUndeterminedTextLanguage(
boolean selectUndeterminedTextLanguage) {
delegate.setSelectUndeterminedTextLanguage(selectUndeterminedTextLanguage);
return this;
}
/**
* @deprecated Use {@link #setIgnoredTextSelectionFlags}.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Deprecated
public ParametersBuilder setDisabledTextTrackSelectionFlags(
@C.SelectionFlags int disabledTextTrackSelectionFlags) {
delegate.setDisabledTextTrackSelectionFlags(disabledTextTrackSelectionFlags);
return this;
}
// Image
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setPrioritizeImageOverVideoEnabled(
boolean isPrioritizeImageOverVideoEnabled) {
delegate.setPrioritizeImageOverVideoEnabled(isPrioritizeImageOverVideoEnabled);
return this;
}
// General
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setForceLowestBitrate(boolean forceLowestBitrate) {
delegate.setForceLowestBitrate(forceLowestBitrate);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setForceHighestSupportedBitrate(boolean forceHighestSupportedBitrate) {
delegate.setForceHighestSupportedBitrate(forceHighestSupportedBitrate);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder addOverride(TrackSelectionOverride override) {
delegate.addOverride(override);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder clearOverride(TrackGroup trackGroup) {
delegate.clearOverride(trackGroup);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setOverrideForType(TrackSelectionOverride override) {
delegate.setOverrideForType(override);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder clearOverridesOfType(@C.TrackType int trackType) {
delegate.clearOverridesOfType(trackType);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder clearOverrides() {
delegate.clearOverrides();
return this;
}
/**
* @deprecated Use {@link #setTrackTypeDisabled(int, boolean)}.
*/
@CanIgnoreReturnValue
@Override
@Deprecated
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
public ParametersBuilder setDisabledTrackTypes(Set<@C.TrackType Integer> disabledTrackTypes) {
delegate.setDisabledTrackTypes(disabledTrackTypes);
return this;
}
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Override
public ParametersBuilder setTrackTypeDisabled(@C.TrackType int trackType, boolean disabled) {
delegate.setTrackTypeDisabled(trackType, disabled);
return this;
}
/**
* Sets whether to exceed renderer capabilities when no selection can be made otherwise.
*
* <p>This parameter applies when all of the tracks available for a renderer exceed the
* renderer's reported capabilities. If the parameter is {@code true} then the lowest quality
* track will still be selected. Playback may succeed if the renderer has under-reported its
* true capabilities. If {@code false} then no track will be selected.
*
* @param exceedRendererCapabilitiesIfNecessary Whether to exceed renderer capabilities when no
* selection can be made otherwise.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setExceedRendererCapabilitiesIfNecessary(
boolean exceedRendererCapabilitiesIfNecessary) {
delegate.setExceedRendererCapabilitiesIfNecessary(exceedRendererCapabilitiesIfNecessary);
return this;
}
/**
* Sets whether to enable tunneling if possible. Tunneling will only be enabled if it's
* supported by the audio and video renderers for the selected tracks.
*
* <p>Tunneling is known to have many device specific issues and limitations. Manual testing is
* strongly recommended to check that the media plays correctly when this option is enabled. See
* [#9661](https://github.com/google/ExoPlayer/issues/9661),
* [#9133](https://github.com/google/ExoPlayer/issues/9133),
* [#9317](https://github.com/google/ExoPlayer/issues/9317),
* [#9502](https://github.com/google/ExoPlayer/issues/9502).
*
* @param tunnelingEnabled Whether to enable tunneling if possible.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setTunnelingEnabled(boolean tunnelingEnabled) {
delegate.setTunnelingEnabled(tunnelingEnabled);
return this;
}
/**
* Sets whether multiple adaptive selections with more than one track are allowed.
*
* @param allowMultipleAdaptiveSelections Whether multiple adaptive selections are allowed.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setAllowMultipleAdaptiveSelections(
boolean allowMultipleAdaptiveSelections) {
delegate.setAllowMultipleAdaptiveSelections(allowMultipleAdaptiveSelections);
return this;
}
// Overrides
/**
* Sets whether the renderer at the specified index is disabled. Disabling a renderer prevents
* the selector from selecting any tracks for it.
*
* @param rendererIndex The renderer index.
* @param disabled Whether the renderer is disabled.
* @return This builder.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
public ParametersBuilder setRendererDisabled(int rendererIndex, boolean disabled) {
delegate.setRendererDisabled(rendererIndex, disabled);
return this;
}
/**
* Overrides the track selection for the renderer at the specified index.
*
* <p>When the {@link TrackGroupArray} mapped to the renderer matches the one provided, the
* override is applied. When the {@link TrackGroupArray} does not match, the override has no
* effect. The override replaces any previous override for the specified {@link TrackGroupArray}
* for the specified {@link Renderer}.
*
* <p>Passing a {@code null} override will cause the renderer to be disabled when the {@link
* TrackGroupArray} mapped to it matches the one provided. When the {@link TrackGroupArray} does
* not match a {@code null} override has no effect. Hence a {@code null} override differs from
* disabling the renderer using {@link #setRendererDisabled(int, boolean)} because the renderer
* is disabled conditionally on the {@link TrackGroupArray} mapped to it, where-as {@link
* #setRendererDisabled(int, boolean)} disables the renderer unconditionally.
*
* <p>To remove overrides use {@link #clearSelectionOverride(int, TrackGroupArray)}, {@link
* #clearSelectionOverrides(int)} or {@link #clearSelectionOverrides()}.
*
* @param rendererIndex The renderer index.
* @param groups The {@link TrackGroupArray} for which the override should be applied.
* @param override The override.
* @return This builder.
* @deprecated Use {@link TrackSelectionParameters.Builder#addOverride(TrackSelectionOverride)}.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Deprecated
public ParametersBuilder setSelectionOverride(
int rendererIndex, TrackGroupArray groups, @Nullable SelectionOverride override) {
delegate.setSelectionOverride(rendererIndex, groups, override);
return this;
}
/**
* Clears a track selection override for the specified renderer and {@link TrackGroupArray}.
*
* @param rendererIndex The renderer index.
* @param groups The {@link TrackGroupArray} for which the override should be cleared.
* @return This builder.
* @deprecated Use {@link TrackSelectionParameters.Builder#clearOverride(TrackGroup)}.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Deprecated
public ParametersBuilder clearSelectionOverride(int rendererIndex, TrackGroupArray groups) {
delegate.clearSelectionOverride(rendererIndex, groups);
return this;
}
/**
* Clears all track selection overrides for the specified renderer.
*
* @param rendererIndex The renderer index.
* @return This builder.
* @deprecated Use {@link TrackSelectionParameters.Builder#clearOverridesOfType(int)}.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Deprecated
public ParametersBuilder clearSelectionOverrides(int rendererIndex) {
delegate.clearSelectionOverrides(rendererIndex);
return this;
}
/**
* Clears all track selection overrides for all renderers.
*
* @return This builder.
* @deprecated Use {@link TrackSelectionParameters.Builder#clearOverrides()}.
*/
@SuppressWarnings("deprecation") // Intentionally returning deprecated type
@CanIgnoreReturnValue
@Deprecated
public ParametersBuilder clearSelectionOverrides() {
delegate.clearSelectionOverrides();
return this;
}
/** Builds a {@link Parameters} instance with the selected values. */
@Override
public Parameters build() {
return delegate.build();
}
}
/**
* Extends {@link Parameters} by adding fields that are specific to {@link DefaultTrackSelector}.
*/
public static final class Parameters extends TrackSelectionParameters implements Bundleable {
/**
* A builder for {@link Parameters}. See the {@link Parameters} documentation for explanations
* of the parameters that can be configured using this builder.
*/
public static final class Builder extends TrackSelectionParameters.Builder {
// Video
private boolean exceedVideoConstraintsIfNecessary;
private boolean allowVideoMixedMimeTypeAdaptiveness;
private boolean allowVideoNonSeamlessAdaptiveness;
private boolean allowVideoMixedDecoderSupportAdaptiveness;
// Audio
private boolean exceedAudioConstraintsIfNecessary;
private boolean allowAudioMixedMimeTypeAdaptiveness;
private boolean allowAudioMixedSampleRateAdaptiveness;
private boolean allowAudioMixedChannelCountAdaptiveness;
private boolean allowAudioMixedDecoderSupportAdaptiveness;
private boolean allowAudioNonSeamlessAdaptiveness;
private boolean constrainAudioChannelCountToDeviceCapabilities;
// General
private boolean exceedRendererCapabilitiesIfNecessary;
private boolean tunnelingEnabled;
private boolean allowMultipleAdaptiveSelections;
private boolean allowInvalidateSelectionsOnRendererCapabilitiesChange;
// Overrides
private final SparseArray<Map<TrackGroupArray, @NullableType SelectionOverride>>
selectionOverrides;
private final SparseBooleanArray rendererDisabledFlags;
/**
* @deprecated {@link Context} constraints will not be set using this constructor. Use {@link
* #Builder(Context)} instead.
*/
@Deprecated
@SuppressWarnings({"deprecation"})
public Builder() {
super();
selectionOverrides = new SparseArray<>();
rendererDisabledFlags = new SparseBooleanArray();
init();
}
/**
* Creates a builder with default initial values.
*
* @param context Any context.
*/
public Builder(Context context) {
super(context);
selectionOverrides = new SparseArray<>();
rendererDisabledFlags = new SparseBooleanArray();
init();
}
/**
* @param initialValues The {@link Parameters} from which the initial values of the builder
* are obtained.
*/
private Builder(Parameters initialValues) {
super(initialValues);
// Video
exceedVideoConstraintsIfNecessary = initialValues.exceedVideoConstraintsIfNecessary;
allowVideoMixedMimeTypeAdaptiveness = initialValues.allowVideoMixedMimeTypeAdaptiveness;
allowVideoNonSeamlessAdaptiveness = initialValues.allowVideoNonSeamlessAdaptiveness;
allowVideoMixedDecoderSupportAdaptiveness =
initialValues.allowVideoMixedDecoderSupportAdaptiveness;
// Audio
exceedAudioConstraintsIfNecessary = initialValues.exceedAudioConstraintsIfNecessary;
allowAudioMixedMimeTypeAdaptiveness = initialValues.allowAudioMixedMimeTypeAdaptiveness;
allowAudioMixedSampleRateAdaptiveness = initialValues.allowAudioMixedSampleRateAdaptiveness;
allowAudioMixedChannelCountAdaptiveness =
initialValues.allowAudioMixedChannelCountAdaptiveness;
allowAudioMixedDecoderSupportAdaptiveness =
initialValues.allowAudioMixedDecoderSupportAdaptiveness;
allowAudioNonSeamlessAdaptiveness = initialValues.allowAudioNonSeamlessAdaptiveness;
constrainAudioChannelCountToDeviceCapabilities =
initialValues.constrainAudioChannelCountToDeviceCapabilities;
// General
exceedRendererCapabilitiesIfNecessary = initialValues.exceedRendererCapabilitiesIfNecessary;
tunnelingEnabled = initialValues.tunnelingEnabled;
allowMultipleAdaptiveSelections = initialValues.allowMultipleAdaptiveSelections;
allowInvalidateSelectionsOnRendererCapabilitiesChange =
initialValues.allowInvalidateSelectionsOnRendererCapabilitiesChange;
// Overrides
selectionOverrides = cloneSelectionOverrides(initialValues.selectionOverrides);
rendererDisabledFlags = initialValues.rendererDisabledFlags.clone();
}
@SuppressWarnings("method.invocation") // Only setter are invoked.
private Builder(Bundle bundle) {
super(bundle);
init();
Parameters defaultValue = Parameters.DEFAULT_WITHOUT_CONTEXT;
// Video
setExceedVideoConstraintsIfNecessary(
bundle.getBoolean(
Parameters.FIELD_EXCEED_VIDEO_CONSTRAINTS_IF_NECESSARY,
defaultValue.exceedVideoConstraintsIfNecessary));
setAllowVideoMixedMimeTypeAdaptiveness(
bundle.getBoolean(
Parameters.FIELD_ALLOW_VIDEO_MIXED_MIME_TYPE_ADAPTIVENESS,
defaultValue.allowVideoMixedMimeTypeAdaptiveness));
setAllowVideoNonSeamlessAdaptiveness(
bundle.getBoolean(
Parameters.FIELD_ALLOW_VIDEO_NON_SEAMLESS_ADAPTIVENESS,
defaultValue.allowVideoNonSeamlessAdaptiveness));
setAllowVideoMixedDecoderSupportAdaptiveness(
bundle.getBoolean(
Parameters.FIELD_ALLOW_VIDEO_MIXED_DECODER_SUPPORT_ADAPTIVENESS,
defaultValue.allowVideoMixedDecoderSupportAdaptiveness));
// Audio
setExceedAudioConstraintsIfNecessary(
bundle.getBoolean(
Parameters.FIELD_EXCEED_AUDIO_CONSTRAINTS_IF_NECESSARY,
defaultValue.exceedAudioConstraintsIfNecessary));
setAllowAudioMixedMimeTypeAdaptiveness(
bundle.getBoolean(
Parameters.FIELD_ALLOW_AUDIO_MIXED_MIME_TYPE_ADAPTIVENESS,
defaultValue.allowAudioMixedMimeTypeAdaptiveness));
setAllowAudioMixedSampleRateAdaptiveness(
bundle.getBoolean(
Parameters.FIELD_ALLOW_AUDIO_MIXED_SAMPLE_RATE_ADAPTIVENESS,
defaultValue.allowAudioMixedSampleRateAdaptiveness));
setAllowAudioMixedChannelCountAdaptiveness(
bundle.getBoolean(
Parameters.FIELD_ALLOW_AUDIO_MIXED_CHANNEL_COUNT_ADAPTIVENESS,
defaultValue.allowAudioMixedChannelCountAdaptiveness));
setAllowAudioMixedDecoderSupportAdaptiveness(
bundle.getBoolean(
Parameters.FIELD_ALLOW_AUDIO_MIXED_DECODER_SUPPORT_ADAPTIVENESS,
defaultValue.allowAudioMixedDecoderSupportAdaptiveness));
setAllowAudioNonSeamlessAdaptiveness(
bundle.getBoolean(
Parameters.FIELD_ALLOW_AUDIO_NON_SEAMLESS_ADAPTIVENESS,
defaultValue.allowAudioNonSeamlessAdaptiveness));
setConstrainAudioChannelCountToDeviceCapabilities(
bundle.getBoolean(
Parameters.FIELD_CONSTRAIN_AUDIO_CHANNEL_COUNT_TO_DEVICE_CAPABILITIES,
defaultValue.constrainAudioChannelCountToDeviceCapabilities));
// General
setExceedRendererCapabilitiesIfNecessary(
bundle.getBoolean(
Parameters.FIELD_EXCEED_RENDERER_CAPABILITIES_IF_NECESSARY,
defaultValue.exceedRendererCapabilitiesIfNecessary));
setTunnelingEnabled(
bundle.getBoolean(Parameters.FIELD_TUNNELING_ENABLED, defaultValue.tunnelingEnabled));
setAllowMultipleAdaptiveSelections(
bundle.getBoolean(
Parameters.FIELD_ALLOW_MULTIPLE_ADAPTIVE_SELECTIONS,
defaultValue.allowMultipleAdaptiveSelections));
setAllowInvalidateSelectionsOnRendererCapabilitiesChange(
bundle.getBoolean(
Parameters.FIELD_ALLOW_INVALIDATE_SELECTIONS_ON_RENDERER_CAPABILITIES_CHANGE,
defaultValue.allowInvalidateSelectionsOnRendererCapabilitiesChange));
// Overrides
selectionOverrides = new SparseArray<>();
setSelectionOverridesFromBundle(bundle);
rendererDisabledFlags =
makeSparseBooleanArrayFromTrueKeys(
bundle.getIntArray(Parameters.FIELD_RENDERER_DISABLED_INDICES));
}
@CanIgnoreReturnValue
@Override
protected Builder set(TrackSelectionParameters parameters) {
super.set(parameters);
return this;
}
// Video
@CanIgnoreReturnValue
@Override
public Builder setMaxVideoSizeSd() {
super.setMaxVideoSizeSd();
return this;
}