summaryrefslogtreecommitdiffstats
path: root/mobile/android/exoplayer2/src/main/java/org/mozilla/thirdparty/com/google/android/exoplayer2/MediaPeriodInfo.java
blob: b240fe0f91e5a00189f95092bf62643591c201df (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
/*
 * Copyright (C) 2018 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;

import androidx.annotation.Nullable;
import org.mozilla.thirdparty.com.google.android.exoplayer2.source.MediaPeriod;
import org.mozilla.thirdparty.com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import org.mozilla.thirdparty.com.google.android.exoplayer2.util.Util;

/** Stores the information required to load and play a {@link MediaPeriod}. */
/* package */ final class MediaPeriodInfo {

  /** The media period's identifier. */
  public final MediaPeriodId id;
  /** The start position of the media to play within the media period, in microseconds. */
  public final long startPositionUs;
  /**
   * If this is an ad, the position to play in the next content media period. {@link C#TIME_UNSET}
   * if this is not an ad or the next content media period should be played from its default
   * position.
   */
  public final long contentPositionUs;
  /**
   * The end position to which the media period's content is clipped in order to play a following ad
   * group, in microseconds, or {@link C#TIME_UNSET} if there is no following ad group or if this
   * media period is an ad. The value {@link C#TIME_END_OF_SOURCE} indicates that a postroll ad
   * follows at the end of this content media period.
   */
  public final long endPositionUs;
  /**
   * The duration of the media period, like {@link #endPositionUs} but with {@link
   * C#TIME_END_OF_SOURCE} and {@link C#TIME_UNSET} resolved to the timeline period duration if
   * known.
   */
  public final long durationUs;
  /**
   * Whether this is the last media period in its timeline period (e.g., a postroll ad, or a media
   * period corresponding to a timeline period without ads).
   */
  public final boolean isLastInTimelinePeriod;
  /**
   * Whether this is the last media period in the entire timeline. If true, {@link
   * #isLastInTimelinePeriod} will also be true.
   */
  public final boolean isFinal;

  MediaPeriodInfo(
      MediaPeriodId id,
      long startPositionUs,
      long contentPositionUs,
      long endPositionUs,
      long durationUs,
      boolean isLastInTimelinePeriod,
      boolean isFinal) {
    this.id = id;
    this.startPositionUs = startPositionUs;
    this.contentPositionUs = contentPositionUs;
    this.endPositionUs = endPositionUs;
    this.durationUs = durationUs;
    this.isLastInTimelinePeriod = isLastInTimelinePeriod;
    this.isFinal = isFinal;
  }

  /**
   * Returns a copy of this instance with the start position set to the specified value. May return
   * the same instance if nothing changed.
   */
  public MediaPeriodInfo copyWithStartPositionUs(long startPositionUs) {
    return startPositionUs == this.startPositionUs
        ? this
        : new MediaPeriodInfo(
            id,
            startPositionUs,
            contentPositionUs,
            endPositionUs,
            durationUs,
            isLastInTimelinePeriod,
            isFinal);
  }

  /**
   * Returns a copy of this instance with the content position set to the specified value. May
   * return the same instance if nothing changed.
   */
  public MediaPeriodInfo copyWithContentPositionUs(long contentPositionUs) {
    return contentPositionUs == this.contentPositionUs
        ? this
        : new MediaPeriodInfo(
            id,
            startPositionUs,
            contentPositionUs,
            endPositionUs,
            durationUs,
            isLastInTimelinePeriod,
            isFinal);
  }

  @Override
  public boolean equals(@Nullable Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    MediaPeriodInfo that = (MediaPeriodInfo) o;
    return startPositionUs == that.startPositionUs
        && contentPositionUs == that.contentPositionUs
        && endPositionUs == that.endPositionUs
        && durationUs == that.durationUs
        && isLastInTimelinePeriod == that.isLastInTimelinePeriod
        && isFinal == that.isFinal
        && Util.areEqual(id, that.id);
  }

  @Override
  public int hashCode() {
    int result = 17;
    result = 31 * result + id.hashCode();
    result = 31 * result + (int) startPositionUs;
    result = 31 * result + (int) contentPositionUs;
    result = 31 * result + (int) endPositionUs;
    result = 31 * result + (int) durationUs;
    result = 31 * result + (isLastInTimelinePeriod ? 1 : 0);
    result = 31 * result + (isFinal ? 1 : 0);
    return result;
  }
}