-
Notifications
You must be signed in to change notification settings - Fork 306
/
Format.java
1570 lines (1426 loc) · 55.9 KB
/
Format.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.common;
import static androidx.media3.common.util.Assertions.checkState;
import static java.lang.annotation.ElementType.TYPE_USE;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.media3.common.util.BundleCollectionUtil;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
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.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* Represents a media format.
*
* <p>When building formats, populate all fields whose values are known and relevant to the type of
* format being constructed. For information about different types of format, see ExoPlayer's <a
* href="https://developer.android.com/media/media3/exoplayer/supported-formats">Supported formats
* page</a>.
*
* <h2>Fields commonly relevant to all formats</h2>
*
* <ul>
* <li>{@link #id}
* <li>{@link #label}
* <li>{@link #labels}
* <li>{@link #language}
* <li>{@link #selectionFlags}
* <li>{@link #roleFlags}
* <li>{@link #averageBitrate}
* <li>{@link #peakBitrate}
* <li>{@link #codecs}
* <li>{@link #metadata}
* </ul>
*
* <h2 id="container-formats">Fields relevant to container formats</h2>
*
* <ul>
* <li>{@link #containerMimeType}
* <li>If the container only contains a single media track, <a href="#sample-formats">fields
* relevant to sample formats</a> can are also be relevant and can be set to describe the
* sample format of that track.
* <li>If the container only contains one track of a given type (possibly alongside tracks of
* other types), then fields relevant to that track type can be set to describe the properties
* of the track. See the sections below for <a href="#video-formats">video</a>, <a
* href="#audio-formats">audio</a> and <a href="#text-formats">text</a> formats.
* </ul>
*
* <h2 id="sample-formats">Fields relevant to sample formats</h2>
*
* <ul>
* <li>{@link #sampleMimeType}
* <li>{@link #maxInputSize}
* <li>{@link #initializationData}
* <li>{@link #drmInitData}
* <li>{@link #subsampleOffsetUs}
* <li>Fields relevant to the sample format's track type are also relevant. See the sections below
* for <a href="#video-formats">video</a>, <a href="#audio-formats">audio</a> and <a
* href="#text-formats">text</a> formats.
* </ul>
*
* <h2 id="video-formats">Fields relevant to video formats</h2>
*
* <ul>
* <li>{@link #width}
* <li>{@link #height}
* <li>{@link #frameRate}
* <li>{@link #rotationDegrees}
* <li>{@link #pixelWidthHeightRatio}
* <li>{@link #projectionData}
* <li>{@link #stereoMode}
* <li>{@link #colorInfo}
* </ul>
*
* <h2 id="audio-formats">Fields relevant to audio formats</h2>
*
* <ul>
* <li>{@link #channelCount}
* <li>{@link #sampleRate}
* <li>{@link #pcmEncoding}
* <li>{@link #encoderDelay}
* <li>{@link #encoderPadding}
* </ul>
*
* <h2 id="text-formats">Fields relevant to text formats</h2>
*
* <ul>
* <li>{@link #accessibilityChannel}
* </ul>
*
* <h2 id="image-formats">Fields relevant to image formats</h2>
*
* <ul>
* <li>{@link #tileCountHorizontal}
* <li>{@link #tileCountVertical}
* </ul>
*/
public final class Format implements Bundleable {
/**
* Builds {@link Format} instances.
*
* <p>Use Format#buildUpon() to obtain a builder representing an existing {@link Format}.
*
* <p>When building formats, populate all fields whose values are known and relevant to the type
* of format being constructed. See the {@link Format} Javadoc for information about which fields
* should be set for different types of format.
*/
@UnstableApi
public static final class Builder {
@Nullable private String id;
@Nullable private String label;
private List<Label> labels;
@Nullable private String language;
private @C.SelectionFlags int selectionFlags;
private @C.RoleFlags int roleFlags;
private int averageBitrate;
private int peakBitrate;
@Nullable private String codecs;
@Nullable private Metadata metadata;
// Container specific.
@Nullable private String containerMimeType;
// Sample specific.
@Nullable private String sampleMimeType;
private int maxInputSize;
@Nullable private List<byte[]> initializationData;
@Nullable private DrmInitData drmInitData;
private long subsampleOffsetUs;
// Video specific.
private int width;
private int height;
private float frameRate;
private int rotationDegrees;
private float pixelWidthHeightRatio;
@Nullable private byte[] projectionData;
private @C.StereoMode int stereoMode;
@Nullable private ColorInfo colorInfo;
// Audio specific.
private int channelCount;
private int sampleRate;
private @C.PcmEncoding int pcmEncoding;
private int encoderDelay;
private int encoderPadding;
// Text specific.
private int accessibilityChannel;
@UnstableApi private @CueReplacementBehavior int cueReplacementBehavior;
// Image specific
private int tileCountHorizontal;
private int tileCountVertical;
// Provided by the source.
private @C.CryptoType int cryptoType;
/** Creates a new instance with default values. */
public Builder() {
labels = ImmutableList.of();
averageBitrate = NO_VALUE;
peakBitrate = NO_VALUE;
// Sample specific.
maxInputSize = NO_VALUE;
subsampleOffsetUs = OFFSET_SAMPLE_RELATIVE;
// Video specific.
width = NO_VALUE;
height = NO_VALUE;
frameRate = NO_VALUE;
pixelWidthHeightRatio = 1.0f;
stereoMode = NO_VALUE;
// Audio specific.
channelCount = NO_VALUE;
sampleRate = NO_VALUE;
pcmEncoding = NO_VALUE;
// Text specific.
accessibilityChannel = NO_VALUE;
cueReplacementBehavior = CUE_REPLACEMENT_BEHAVIOR_MERGE;
// Image specific.
tileCountHorizontal = NO_VALUE;
tileCountVertical = NO_VALUE;
// Provided by the source.
cryptoType = C.CRYPTO_TYPE_NONE;
}
/**
* Creates a new instance to build upon the provided {@link Format}.
*
* @param format The {@link Format} to build upon.
*/
private Builder(Format format) {
this.id = format.id;
this.label = format.label;
this.labels = format.labels;
this.language = format.language;
this.selectionFlags = format.selectionFlags;
this.roleFlags = format.roleFlags;
this.averageBitrate = format.averageBitrate;
this.peakBitrate = format.peakBitrate;
this.codecs = format.codecs;
this.metadata = format.metadata;
// Container specific.
this.containerMimeType = format.containerMimeType;
// Sample specific.
this.sampleMimeType = format.sampleMimeType;
this.maxInputSize = format.maxInputSize;
this.initializationData = format.initializationData;
this.drmInitData = format.drmInitData;
this.subsampleOffsetUs = format.subsampleOffsetUs;
// Video specific.
this.width = format.width;
this.height = format.height;
this.frameRate = format.frameRate;
this.rotationDegrees = format.rotationDegrees;
this.pixelWidthHeightRatio = format.pixelWidthHeightRatio;
this.projectionData = format.projectionData;
this.stereoMode = format.stereoMode;
this.colorInfo = format.colorInfo;
// Audio specific.
this.channelCount = format.channelCount;
this.sampleRate = format.sampleRate;
this.pcmEncoding = format.pcmEncoding;
this.encoderDelay = format.encoderDelay;
this.encoderPadding = format.encoderPadding;
// Text specific.
this.accessibilityChannel = format.accessibilityChannel;
this.cueReplacementBehavior = format.cueReplacementBehavior;
// Image specific.
this.tileCountHorizontal = format.tileCountHorizontal;
this.tileCountVertical = format.tileCountVertical;
// Provided by the source.
this.cryptoType = format.cryptoType;
}
/**
* Sets {@link Format#id}. The default value is {@code null}.
*
* @param id The {@link Format#id}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setId(@Nullable String id) {
this.id = id;
return this;
}
/**
* Sets {@link Format#id} to {@link Integer#toString() Integer.toString(id)}. The default value
* is {@code null}.
*
* @param id The {@link Format#id}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setId(int id) {
this.id = Integer.toString(id);
return this;
}
/**
* Sets {@link Format#label}. The default value is {@code null}.
*
* <p>If both this default label and a list of {@link #setLabels labels} are set, this default
* label must be part of label list.
*
* @param label The {@link Format#label}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setLabel(@Nullable String label) {
this.label = label;
return this;
}
/**
* Sets {@link Format#labels}. The default value is an empty list.
*
* <p>If both the default {@linkplain #setLabel label} and this list are set, the default label
* must be part of this list of labels.
*
* @param labels The {@link Format#labels}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setLabels(List<Label> labels) {
this.labels = ImmutableList.copyOf(labels);
return this;
}
/**
* Sets {@link Format#language}. The default value is {@code null}.
*
* @param language The {@link Format#language}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setLanguage(@Nullable String language) {
this.language = language;
return this;
}
/**
* Sets {@link Format#selectionFlags}. The default value is 0.
*
* @param selectionFlags The {@link Format#selectionFlags}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setSelectionFlags(@C.SelectionFlags int selectionFlags) {
this.selectionFlags = selectionFlags;
return this;
}
/**
* Sets {@link Format#roleFlags}. The default value is 0.
*
* @param roleFlags The {@link Format#roleFlags}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setRoleFlags(@C.RoleFlags int roleFlags) {
this.roleFlags = roleFlags;
return this;
}
/**
* Sets {@link Format#averageBitrate}. The default value is {@link #NO_VALUE}.
*
* @param averageBitrate The {@link Format#averageBitrate}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setAverageBitrate(int averageBitrate) {
this.averageBitrate = averageBitrate;
return this;
}
/**
* Sets {@link Format#peakBitrate}. The default value is {@link #NO_VALUE}.
*
* @param peakBitrate The {@link Format#peakBitrate}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setPeakBitrate(int peakBitrate) {
this.peakBitrate = peakBitrate;
return this;
}
/**
* Sets {@link Format#codecs}. The default value is {@code null}.
*
* @param codecs The {@link Format#codecs}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setCodecs(@Nullable String codecs) {
this.codecs = codecs;
return this;
}
/**
* Sets {@link Format#metadata}. The default value is {@code null}.
*
* @param metadata The {@link Format#metadata}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setMetadata(@Nullable Metadata metadata) {
this.metadata = metadata;
return this;
}
// Container specific.
/**
* Sets {@link Format#containerMimeType}. The default value is {@code null}.
*
* @param containerMimeType The {@link Format#containerMimeType}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setContainerMimeType(@Nullable String containerMimeType) {
this.containerMimeType = MimeTypes.normalizeMimeType(containerMimeType);
return this;
}
// Sample specific.
/**
* Sets {@link Format#sampleMimeType}. The default value is {@code null}.
*
* @param sampleMimeType {@link Format#sampleMimeType}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setSampleMimeType(@Nullable String sampleMimeType) {
this.sampleMimeType = MimeTypes.normalizeMimeType(sampleMimeType);
return this;
}
/**
* Sets {@link Format#maxInputSize}. The default value is {@link #NO_VALUE}.
*
* @param maxInputSize The {@link Format#maxInputSize}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setMaxInputSize(int maxInputSize) {
this.maxInputSize = maxInputSize;
return this;
}
/**
* Sets {@link Format#initializationData}. The default value is {@code null}.
*
* @param initializationData The {@link Format#initializationData}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setInitializationData(@Nullable List<byte[]> initializationData) {
this.initializationData = initializationData;
return this;
}
/**
* Sets {@link Format#drmInitData}. The default value is {@code null}.
*
* @param drmInitData The {@link Format#drmInitData}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setDrmInitData(@Nullable DrmInitData drmInitData) {
this.drmInitData = drmInitData;
return this;
}
/**
* Sets {@link Format#subsampleOffsetUs}. The default value is {@link #OFFSET_SAMPLE_RELATIVE}.
*
* @param subsampleOffsetUs The {@link Format#subsampleOffsetUs}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setSubsampleOffsetUs(long subsampleOffsetUs) {
this.subsampleOffsetUs = subsampleOffsetUs;
return this;
}
// Video specific.
/**
* Sets {@link Format#width}. The default value is {@link #NO_VALUE}.
*
* @param width The {@link Format#width}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setWidth(int width) {
this.width = width;
return this;
}
/**
* Sets {@link Format#height}. The default value is {@link #NO_VALUE}.
*
* @param height The {@link Format#height}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setHeight(int height) {
this.height = height;
return this;
}
/**
* Sets {@link Format#frameRate}. The default value is {@link #NO_VALUE}.
*
* @param frameRate The {@link Format#frameRate}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setFrameRate(float frameRate) {
this.frameRate = frameRate;
return this;
}
/**
* Sets {@link Format#rotationDegrees}. The default value is 0.
*
* @param rotationDegrees The {@link Format#rotationDegrees}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setRotationDegrees(int rotationDegrees) {
this.rotationDegrees = rotationDegrees;
return this;
}
/**
* Sets {@link Format#pixelWidthHeightRatio}. The default value is 1.0f.
*
* @param pixelWidthHeightRatio The {@link Format#pixelWidthHeightRatio}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setPixelWidthHeightRatio(float pixelWidthHeightRatio) {
this.pixelWidthHeightRatio = pixelWidthHeightRatio;
return this;
}
/**
* Sets {@link Format#projectionData}. The default value is {@code null}.
*
* @param projectionData The {@link Format#projectionData}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setProjectionData(@Nullable byte[] projectionData) {
this.projectionData = projectionData;
return this;
}
/**
* Sets {@link Format#stereoMode}. The default value is {@link #NO_VALUE}.
*
* @param stereoMode The {@link Format#stereoMode}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setStereoMode(@C.StereoMode int stereoMode) {
this.stereoMode = stereoMode;
return this;
}
/**
* Sets {@link Format#colorInfo}. The default value is {@code null}.
*
* @param colorInfo The {@link Format#colorInfo}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setColorInfo(@Nullable ColorInfo colorInfo) {
this.colorInfo = colorInfo;
return this;
}
// Audio specific.
/**
* Sets {@link Format#channelCount}. The default value is {@link #NO_VALUE}.
*
* @param channelCount The {@link Format#channelCount}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setChannelCount(int channelCount) {
this.channelCount = channelCount;
return this;
}
/**
* Sets {@link Format#sampleRate}. The default value is {@link #NO_VALUE}.
*
* @param sampleRate The {@link Format#sampleRate}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setSampleRate(int sampleRate) {
this.sampleRate = sampleRate;
return this;
}
/**
* Sets {@link Format#pcmEncoding}. The default value is {@link #NO_VALUE}.
*
* @param pcmEncoding The {@link Format#pcmEncoding}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setPcmEncoding(@C.PcmEncoding int pcmEncoding) {
this.pcmEncoding = pcmEncoding;
return this;
}
/**
* Sets {@link Format#encoderDelay}. The default value is 0.
*
* @param encoderDelay The {@link Format#encoderDelay}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setEncoderDelay(int encoderDelay) {
this.encoderDelay = encoderDelay;
return this;
}
/**
* Sets {@link Format#encoderPadding}. The default value is 0.
*
* @param encoderPadding The {@link Format#encoderPadding}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setEncoderPadding(int encoderPadding) {
this.encoderPadding = encoderPadding;
return this;
}
// Text specific.
/**
* Sets {@link Format#accessibilityChannel}. The default value is {@link #NO_VALUE}.
*
* @param accessibilityChannel The {@link Format#accessibilityChannel}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setAccessibilityChannel(int accessibilityChannel) {
this.accessibilityChannel = accessibilityChannel;
return this;
}
/**
* Sets {@link Format#cueReplacementBehavior}. The default value is {@link
* #CUE_REPLACEMENT_BEHAVIOR_MERGE}.
*
* @param cueReplacementBehavior The {@link Format.CueReplacementBehavior}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setCueReplacementBehavior(@CueReplacementBehavior int cueReplacementBehavior) {
this.cueReplacementBehavior = cueReplacementBehavior;
return this;
}
// Image specific.
/**
* Sets {@link Format#tileCountHorizontal}. The default value is {@link #NO_VALUE}.
*
* @param tileCountHorizontal The {@link Format#accessibilityChannel}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setTileCountHorizontal(int tileCountHorizontal) {
this.tileCountHorizontal = tileCountHorizontal;
return this;
}
/**
* Sets {@link Format#tileCountVertical}. The default value is {@link #NO_VALUE}.
*
* @param tileCountVertical The {@link Format#accessibilityChannel}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setTileCountVertical(int tileCountVertical) {
this.tileCountVertical = tileCountVertical;
return this;
}
// Provided by source.
/**
* Sets {@link Format#cryptoType}. The default value is {@link C#CRYPTO_TYPE_NONE}.
*
* @param cryptoType The {@link C.CryptoType}.
* @return The builder.
*/
@CanIgnoreReturnValue
public Builder setCryptoType(@C.CryptoType int cryptoType) {
this.cryptoType = cryptoType;
return this;
}
// Build.
public Format build() {
return new Format(/* builder= */ this);
}
}
/**
* The replacement behaviors for consecutive samples in a {@linkplain C#TRACK_TYPE_TEXT text
* track} of type {@link MimeTypes#APPLICATION_MEDIA3_CUES}.
*/
@UnstableApi
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(TYPE_USE)
@IntDef({
CUE_REPLACEMENT_BEHAVIOR_MERGE,
CUE_REPLACEMENT_BEHAVIOR_REPLACE,
})
public @interface CueReplacementBehavior {}
/**
* Subsequent cues should be merged with any previous cues that should still be shown on screen.
*
* <p>Tracks with this behavior must not contain samples with an {@linkplain C#TIME_UNSET unset}
* duration.
*/
@UnstableApi public static final int CUE_REPLACEMENT_BEHAVIOR_MERGE = 1;
/**
* Subsequent cues should replace all previous cues.
*
* <p>Tracks with this behavior may contain samples with an {@linkplain C#TIME_UNSET unset}
* duration (but the duration may also be set to a 'real' value).
*/
@UnstableApi public static final int CUE_REPLACEMENT_BEHAVIOR_REPLACE = 2;
/** A value for various fields to indicate that the field's value is unknown or not applicable. */
public static final int NO_VALUE = -1;
/**
* A value for {@link #subsampleOffsetUs} to indicate that subsample timestamps are relative to
* the timestamps of their parent samples.
*/
@UnstableApi public static final long OFFSET_SAMPLE_RELATIVE = Long.MAX_VALUE;
private static final Format DEFAULT = new Builder().build();
/** An identifier for the format, or null if unknown or not applicable. */
@Nullable public final String id;
/**
* The default human readable label, or null if unknown or not applicable.
*
* <p>If non-null, the same label will be part of {@link #labels} too. If null, {@link #labels}
* will be empty.
*/
@Nullable public final String label;
/**
* The human readable list of labels, or an empty list if unknown or not applicable.
*
* <p>If non-empty, the default {@link #label} will be part of this list. If empty, the default
* {@link #label} will be null.
*/
@UnstableApi public final List<Label> labels;
/** The language as an IETF BCP 47 conformant tag, or null if unknown or not applicable. */
@Nullable public final String language;
/** Track selection flags. */
public final @C.SelectionFlags int selectionFlags;
/** Track role flags. */
public final @C.RoleFlags int roleFlags;
/**
* The average bitrate in bits per second, or {@link #NO_VALUE} if unknown or not applicable. The
* way in which this field is populated depends on the type of media to which the format
* corresponds:
*
* <ul>
* <li>DASH representations: Always {@link Format#NO_VALUE}.
* <li>HLS variants: The {@code AVERAGE-BANDWIDTH} attribute defined on the corresponding {@code
* EXT-X-STREAM-INF} tag in the multivariant playlist, or {@link Format#NO_VALUE} if not
* present.
* <li>SmoothStreaming track elements: The {@code Bitrate} attribute defined on the
* corresponding {@code TrackElement} in the manifest, or {@link Format#NO_VALUE} if not
* present.
* <li>Progressive container formats: Often {@link Format#NO_VALUE}, but may be populated with
* the average bitrate of the container if known.
* <li>Sample formats: Often {@link Format#NO_VALUE}, but may be populated with the average
* bitrate of the stream of samples with type {@link #sampleMimeType} if known. Note that if
* {@link #sampleMimeType} is a compressed format (e.g., {@link MimeTypes#AUDIO_AAC}), then
* this bitrate is for the stream of still compressed samples.
* </ul>
*/
@UnstableApi public final int averageBitrate;
/**
* The peak bitrate in bits per second, or {@link #NO_VALUE} if unknown or not applicable. The way
* in which this field is populated depends on the type of media to which the format corresponds:
*
* <ul>
* <li>DASH representations: The {@code @bandwidth} attribute of the corresponding {@code
* Representation} element in the manifest.
* <li>HLS variants: The {@code BANDWIDTH} attribute defined on the corresponding {@code
* EXT-X-STREAM-INF} tag.
* <li>SmoothStreaming track elements: Always {@link Format#NO_VALUE}.
* <li>Progressive container formats: Often {@link Format#NO_VALUE}, but may be populated with
* the peak bitrate of the container if known.
* <li>Sample formats: Often {@link Format#NO_VALUE}, but may be populated with the peak bitrate
* of the stream of samples with type {@link #sampleMimeType} if known. Note that if {@link
* #sampleMimeType} is a compressed format (e.g., {@link MimeTypes#AUDIO_AAC}), then this
* bitrate is for the stream of still compressed samples.
* </ul>
*/
@UnstableApi public final int peakBitrate;
/**
* The bitrate in bits per second. This is the peak bitrate if known, or else the average bitrate
* if known, or else {@link Format#NO_VALUE}. Equivalent to: {@code peakBitrate != NO_VALUE ?
* peakBitrate : averageBitrate}.
*/
@UnstableApi public final int bitrate;
/** Codecs of the format as described in RFC 6381, or null if unknown or not applicable. */
@Nullable public final String codecs;
/** Metadata, or null if unknown or not applicable. */
@UnstableApi @Nullable public final Metadata metadata;
// Container specific.
/** The MIME type of the container, or null if unknown or not applicable. */
@Nullable public final String containerMimeType;
// Sample specific.
/** The sample MIME type, or null if unknown or not applicable. */
@Nullable public final String sampleMimeType;
/**
* The maximum size of a buffer of data (typically one sample), or {@link #NO_VALUE} if unknown or
* not applicable.
*/
@UnstableApi public final int maxInputSize;
/**
* Initialization data that must be provided to the decoder. Will not be null, but may be empty if
* initialization data is not required.
*/
@UnstableApi public final List<byte[]> initializationData;
/** DRM initialization data if the stream is protected, or null otherwise. */
@UnstableApi @Nullable public final DrmInitData drmInitData;
/**
* For samples that contain subsamples, this is an offset that should be added to subsample
* timestamps. A value of {@link #OFFSET_SAMPLE_RELATIVE} indicates that subsample timestamps are
* relative to the timestamps of their parent samples.
*/
@UnstableApi public final long subsampleOffsetUs;
// Video specific.
/** The width of the video in pixels, or {@link #NO_VALUE} if unknown or not applicable. */
public final int width;
/** The height of the video in pixels, or {@link #NO_VALUE} if unknown or not applicable. */
public final int height;
/** The frame rate in frames per second, or {@link #NO_VALUE} if unknown or not applicable. */
public final float frameRate;
/**
* The clockwise rotation that should be applied to the video for it to be rendered in the correct
* orientation, or 0 if unknown or not applicable. Only 0, 90, 180 and 270 are supported.
*/
@UnstableApi public final int rotationDegrees;
/** The width to height ratio of pixels in the video, or 1.0 if unknown or not applicable. */
public final float pixelWidthHeightRatio;
/** The projection data for 360/VR video, or null if not applicable. */
@UnstableApi @Nullable public final byte[] projectionData;
/**
* The stereo layout for 360/3D/VR video, or {@link #NO_VALUE} if not applicable. Valid stereo
* modes are {@link C#STEREO_MODE_MONO}, {@link C#STEREO_MODE_TOP_BOTTOM}, {@link
* C#STEREO_MODE_LEFT_RIGHT}, {@link C#STEREO_MODE_STEREO_MESH}.
*/
@UnstableApi public final @C.StereoMode int stereoMode;
/** The color metadata associated with the video, or null if not applicable. */
@UnstableApi @Nullable public final ColorInfo colorInfo;
// Audio specific.
/** The number of audio channels, or {@link #NO_VALUE} if unknown or not applicable. */
public final int channelCount;
/** The audio sampling rate in Hz, or {@link #NO_VALUE} if unknown or not applicable. */
public final int sampleRate;
/** The {@link C.PcmEncoding} for PCM audio. Set to {@link #NO_VALUE} for other media types. */
@UnstableApi public final @C.PcmEncoding int pcmEncoding;
/**
* The number of frames to trim from the start of the decoded audio stream, or 0 if not
* applicable.
*/
@UnstableApi public final int encoderDelay;
/**
* The number of frames to trim from the end of the decoded audio stream, or 0 if not applicable.
*/
@UnstableApi public final int encoderPadding;
// Text specific.
/** The Accessibility channel, or {@link #NO_VALUE} if not known or applicable. */
@UnstableApi public final int accessibilityChannel;
/**
* The replacement behavior that should be followed when handling consecutive samples in a
* {@linkplain C#TRACK_TYPE_TEXT text track} of type {@link MimeTypes#APPLICATION_MEDIA3_CUES}.
*/
@UnstableApi public final @CueReplacementBehavior int cueReplacementBehavior;
// Image specific.
/**
* The number of horizontal tiles in an image, or {@link #NO_VALUE} if not known or applicable.
*/
@UnstableApi public final int tileCountHorizontal;
/** The number of vertical tiles in an image, or {@link #NO_VALUE} if not known or applicable. */
@UnstableApi public final int tileCountVertical;
// Provided by source.
/**
* The type of crypto that must be used to decode samples associated with this format, or {@link
* C#CRYPTO_TYPE_NONE} if the content is not encrypted. Cannot be {@link C#CRYPTO_TYPE_NONE} if
* {@link #drmInitData} is non-null, but may be {@link C#CRYPTO_TYPE_UNSUPPORTED} to indicate that
* the samples are encrypted using an unsupported crypto type.
*/
@UnstableApi public final @C.CryptoType int cryptoType;
// Lazily initialized hashcode.
private int hashCode;
private Format(Builder builder) {
id = builder.id;
language = Util.normalizeLanguageCode(builder.language);
if (builder.labels.isEmpty() && builder.label != null) {
labels = ImmutableList.of(new Label(language, builder.label));
label = builder.label;
} else if (!builder.labels.isEmpty() && builder.label == null) {
labels = builder.labels;
label = getDefaultLabel(builder.labels, language);
} else {
checkState(
(builder.labels.isEmpty() && builder.label == null)
|| (builder.labels.stream().anyMatch(l -> l.value.equals(builder.label))));
labels = builder.labels;
label = builder.label;
}
selectionFlags = builder.selectionFlags;
roleFlags = builder.roleFlags;
averageBitrate = builder.averageBitrate;
peakBitrate = builder.peakBitrate;
bitrate = peakBitrate != NO_VALUE ? peakBitrate : averageBitrate;
codecs = builder.codecs;
metadata = builder.metadata;
// Container specific.
containerMimeType = builder.containerMimeType;
// Sample specific.
sampleMimeType = builder.sampleMimeType;
maxInputSize = builder.maxInputSize;
initializationData =
builder.initializationData == null ? Collections.emptyList() : builder.initializationData;
drmInitData = builder.drmInitData;