summaryrefslogtreecommitdiffstats
path: root/mobile/android/exoplayer2/src/main/java/org/mozilla/thirdparty/com/google/android/exoplayer2/extractor/mp4/Track.java
blob: b7a1555a767596fba05dba54a31f9fa152a269e6 (plain)
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
/*
 * 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 org.mozilla.thirdparty.com.google.android.exoplayer2.extractor.mp4;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import org.mozilla.thirdparty.com.google.android.exoplayer2.C;
import org.mozilla.thirdparty.com.google.android.exoplayer2.Format;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Encapsulates information describing an MP4 track.
 */
public final class Track {

  /**
   * The transformation to apply to samples in the track, if any. One of {@link
   * #TRANSFORMATION_NONE} or {@link #TRANSFORMATION_CEA608_CDAT}.
   */
  @Documented
  @Retention(RetentionPolicy.SOURCE)
  @IntDef({TRANSFORMATION_NONE, TRANSFORMATION_CEA608_CDAT})
  public @interface Transformation {}
  /**
   * A no-op sample transformation.
   */
  public static final int TRANSFORMATION_NONE = 0;
  /**
   * A transformation for caption samples in cdat atoms.
   */
  public static final int TRANSFORMATION_CEA608_CDAT = 1;

  /**
   * The track identifier.
   */
  public final int id;

  /**
   * One of {@link C#TRACK_TYPE_AUDIO}, {@link C#TRACK_TYPE_VIDEO} and {@link C#TRACK_TYPE_TEXT}.
   */
  public final int type;

  /**
   * The track timescale, defined as the number of time units that pass in one second.
   */
  public final long timescale;

  /**
   * The movie timescale.
   */
  public final long movieTimescale;

  /**
   * The duration of the track in microseconds, or {@link C#TIME_UNSET} if unknown.
   */
  public final long durationUs;

  /**
   * The format.
   */
  public final Format format;

  /**
   * One of {@code TRANSFORMATION_*}. Defines the transformation to apply before outputting each
   * sample.
   */
  @Transformation public final int sampleTransformation;

  /**
   * Durations of edit list segments in the movie timescale. Null if there is no edit list.
   */
  @Nullable public final long[] editListDurations;

  /**
   * Media times for edit list segments in the track timescale. Null if there is no edit list.
   */
  @Nullable public final long[] editListMediaTimes;

  /**
   * For H264 video tracks, the length in bytes of the NALUnitLength field in each sample. 0 for
   * other track types.
   */
  public final int nalUnitLengthFieldLength;

  @Nullable private final TrackEncryptionBox[] sampleDescriptionEncryptionBoxes;

  public Track(int id, int type, long timescale, long movieTimescale, long durationUs,
      Format format, @Transformation int sampleTransformation,
      @Nullable TrackEncryptionBox[] sampleDescriptionEncryptionBoxes, int nalUnitLengthFieldLength,
      @Nullable long[] editListDurations, @Nullable long[] editListMediaTimes) {
    this.id = id;
    this.type = type;
    this.timescale = timescale;
    this.movieTimescale = movieTimescale;
    this.durationUs = durationUs;
    this.format = format;
    this.sampleTransformation = sampleTransformation;
    this.sampleDescriptionEncryptionBoxes = sampleDescriptionEncryptionBoxes;
    this.nalUnitLengthFieldLength = nalUnitLengthFieldLength;
    this.editListDurations = editListDurations;
    this.editListMediaTimes = editListMediaTimes;
  }

  /**
   * Returns the {@link TrackEncryptionBox} for the given sample description index.
   *
   * @param sampleDescriptionIndex The given sample description index
   * @return The {@link TrackEncryptionBox} for the given sample description index. Maybe null if no
   *     such entry exists.
   */
  @Nullable
  public TrackEncryptionBox getSampleDescriptionEncryptionBox(int sampleDescriptionIndex) {
    return sampleDescriptionEncryptionBoxes == null ? null
        : sampleDescriptionEncryptionBoxes[sampleDescriptionIndex];
  }

  // incompatible types in argument.
  @SuppressWarnings("nullness:argument.type.incompatible")
  public Track copyWithFormat(Format format) {
    return new Track(
        id,
        type,
        timescale,
        movieTimescale,
        durationUs,
        format,
        sampleTransformation,
        sampleDescriptionEncryptionBoxes,
        nalUnitLengthFieldLength,
        editListDurations,
        editListMediaTimes);
  }
}