• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.google.android.exoplayer2;
17 
18 import androidx.annotation.Nullable;
19 import com.google.android.exoplayer2.source.MediaPeriod;
20 import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
21 import com.google.android.exoplayer2.util.Util;
22 
23 /** Stores the information required to load and play a {@link MediaPeriod}. */
24 /* package */ final class MediaPeriodInfo {
25 
26   /** The media period's identifier. */
27   public final MediaPeriodId id;
28   /** The start position of the media to play within the media period, in microseconds. */
29   public final long startPositionUs;
30   /**
31    * The requested next start position for the current timeline period, in microseconds, or {@link
32    * C#TIME_UNSET} if the period was requested to start at its default position.
33    *
34    * <p>Note that if {@link #id} refers to an ad, this is the requested start position for the
35    * suspended content.
36    */
37   public final long requestedContentPositionUs;
38   /**
39    * The end position to which the media period's content is clipped in order to play a following ad
40    * group, in microseconds, or {@link C#TIME_UNSET} if there is no following ad group or if this
41    * media period is an ad. The value {@link C#TIME_END_OF_SOURCE} indicates that a postroll ad
42    * follows at the end of this content media period.
43    */
44   public final long endPositionUs;
45   /**
46    * The duration of the media period, like {@link #endPositionUs} but with {@link
47    * C#TIME_END_OF_SOURCE} and {@link C#TIME_UNSET} resolved to the timeline period duration if
48    * known.
49    */
50   public final long durationUs;
51   /**
52    * Whether this is the last media period in its timeline period (e.g., a postroll ad, or a media
53    * period corresponding to a timeline period without ads).
54    */
55   public final boolean isLastInTimelinePeriod;
56   /** Whether this is the last media period in its timeline window. */
57   public final boolean isLastInTimelineWindow;
58   /**
59    * Whether this is the last media period in the entire timeline. If true, {@link
60    * #isLastInTimelinePeriod} will also be true.
61    */
62   public final boolean isFinal;
63 
MediaPeriodInfo( MediaPeriodId id, long startPositionUs, long requestedContentPositionUs, long endPositionUs, long durationUs, boolean isLastInTimelinePeriod, boolean isLastInTimelineWindow, boolean isFinal)64   MediaPeriodInfo(
65       MediaPeriodId id,
66       long startPositionUs,
67       long requestedContentPositionUs,
68       long endPositionUs,
69       long durationUs,
70       boolean isLastInTimelinePeriod,
71       boolean isLastInTimelineWindow,
72       boolean isFinal) {
73     this.id = id;
74     this.startPositionUs = startPositionUs;
75     this.requestedContentPositionUs = requestedContentPositionUs;
76     this.endPositionUs = endPositionUs;
77     this.durationUs = durationUs;
78     this.isLastInTimelinePeriod = isLastInTimelinePeriod;
79     this.isLastInTimelineWindow = isLastInTimelineWindow;
80     this.isFinal = isFinal;
81   }
82 
83   /**
84    * Returns a copy of this instance with the start position set to the specified value. May return
85    * the same instance if nothing changed.
86    */
copyWithStartPositionUs(long startPositionUs)87   public MediaPeriodInfo copyWithStartPositionUs(long startPositionUs) {
88     return startPositionUs == this.startPositionUs
89         ? this
90         : new MediaPeriodInfo(
91             id,
92             startPositionUs,
93             requestedContentPositionUs,
94             endPositionUs,
95             durationUs,
96             isLastInTimelinePeriod,
97             isLastInTimelineWindow,
98             isFinal);
99   }
100 
101   /**
102    * Returns a copy of this instance with the requested content position set to the specified value.
103    * May return the same instance if nothing changed.
104    */
copyWithRequestedContentPositionUs(long requestedContentPositionUs)105   public MediaPeriodInfo copyWithRequestedContentPositionUs(long requestedContentPositionUs) {
106     return requestedContentPositionUs == this.requestedContentPositionUs
107         ? this
108         : new MediaPeriodInfo(
109             id,
110             startPositionUs,
111             requestedContentPositionUs,
112             endPositionUs,
113             durationUs,
114             isLastInTimelinePeriod,
115             isLastInTimelineWindow,
116             isFinal);
117   }
118 
119   @Override
equals(@ullable Object o)120   public boolean equals(@Nullable Object o) {
121     if (this == o) {
122       return true;
123     }
124     if (o == null || getClass() != o.getClass()) {
125       return false;
126     }
127     MediaPeriodInfo that = (MediaPeriodInfo) o;
128     return startPositionUs == that.startPositionUs
129         && requestedContentPositionUs == that.requestedContentPositionUs
130         && endPositionUs == that.endPositionUs
131         && durationUs == that.durationUs
132         && isLastInTimelinePeriod == that.isLastInTimelinePeriod
133         && isLastInTimelineWindow == that.isLastInTimelineWindow
134         && isFinal == that.isFinal
135         && Util.areEqual(id, that.id);
136   }
137 
138   @Override
hashCode()139   public int hashCode() {
140     int result = 17;
141     result = 31 * result + id.hashCode();
142     result = 31 * result + (int) startPositionUs;
143     result = 31 * result + (int) requestedContentPositionUs;
144     result = 31 * result + (int) endPositionUs;
145     result = 31 * result + (int) durationUs;
146     result = 31 * result + (isLastInTimelinePeriod ? 1 : 0);
147     result = 31 * result + (isLastInTimelineWindow ? 1 : 0);
148     result = 31 * result + (isFinal ? 1 : 0);
149     return result;
150   }
151 }
152