mirror of
https://github.com/samsonjs/media.git
synced 2026-03-27 09:45:47 +00:00
Use ms for SeekWindow, for consistency with Timeline
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=129868070
This commit is contained in:
parent
c5a2f9b010
commit
4502a464dd
4 changed files with 57 additions and 51 deletions
|
|
@ -20,7 +20,32 @@ package com.google.android.exoplayer2.source;
|
|||
*/
|
||||
public final class SeekWindow {
|
||||
|
||||
public static final SeekWindow UNSEEKABLE = new SeekWindow(0);
|
||||
public static final SeekWindow UNSEEKABLE = createWindowFromZero(0);
|
||||
|
||||
/**
|
||||
* Creates a new {@link SeekWindow} containing times from zero up to {@code durationUs} in the
|
||||
* first period.
|
||||
*
|
||||
* @param durationUs The duration of the window, in microseconds.
|
||||
*/
|
||||
public static SeekWindow createWindowFromZero(long durationUs) {
|
||||
return createWindow(0, 0, 0, durationUs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link SeekWindow} representing the specified time range.
|
||||
*
|
||||
* @param startPeriodIndex The index of the period containing the start of the window.
|
||||
* @param startTimeUs The start time of the window in microseconds, relative to the start of the
|
||||
* specified start period.
|
||||
* @param endPeriodIndex The index of the period containing the end of the window.
|
||||
* @param endTimeUs = The end time of the window in microseconds, relative to the start of the
|
||||
* specified end period.
|
||||
*/
|
||||
public static SeekWindow createWindow(int startPeriodIndex, long startTimeUs,
|
||||
int endPeriodIndex, long endTimeUs) {
|
||||
return new SeekWindow(startPeriodIndex, startTimeUs / 1000, endPeriodIndex, endTimeUs / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* The period index at the start of the window.
|
||||
|
|
@ -28,44 +53,24 @@ public final class SeekWindow {
|
|||
public final int startPeriodIndex;
|
||||
/**
|
||||
* The time at the start of the window relative to the start of the period at
|
||||
* {@link #startPeriodIndex}, in microseconds.
|
||||
* {@link #startPeriodIndex}, in milliseconds.
|
||||
*/
|
||||
public final long startTimeUs;
|
||||
public final long startTimeMs;
|
||||
/**
|
||||
* The period index at the end of the window.
|
||||
*/
|
||||
public final int endPeriodIndex;
|
||||
/**
|
||||
* The time at the end of the window relative to the start of the period at
|
||||
* {@link #endPeriodIndex}, in microseconds.
|
||||
* {@link #endPeriodIndex}, in milliseconds.
|
||||
*/
|
||||
public final long endTimeUs;
|
||||
public final long endTimeMs;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link SeekWindow} containing times from zero up to {@code durationUs} in the
|
||||
* first period.
|
||||
*
|
||||
* @param durationUs The duration of the window, in microseconds.
|
||||
*/
|
||||
public SeekWindow(long durationUs) {
|
||||
this(0, 0, 0, durationUs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link SeekWindow} representing the specified time range.
|
||||
*
|
||||
* @param startPeriodIndex The index of the period containing the start of the window.
|
||||
* @param startTimeUs The start time of the window in microseconds, relative to the start of the
|
||||
* specified start period.
|
||||
* @param endPeriodIndex The index of the period containing the end of the window.
|
||||
* @param endTimeUs The end time of the window in microseconds, relative to the start of the
|
||||
* specified end period.
|
||||
*/
|
||||
public SeekWindow(int startPeriodIndex, long startTimeUs, int endPeriodIndex, long endTimeUs) {
|
||||
private SeekWindow(int startPeriodIndex, long startTimeMs, int endPeriodIndex, long endTimeMs) {
|
||||
this.startPeriodIndex = startPeriodIndex;
|
||||
this.startTimeUs = startTimeUs;
|
||||
this.startTimeMs = startTimeMs;
|
||||
this.endPeriodIndex = endPeriodIndex;
|
||||
this.endTimeUs = endTimeUs;
|
||||
this.endTimeMs = endTimeMs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -76,17 +81,17 @@ public final class SeekWindow {
|
|||
* @return A new seek window that is offset by the specified number of periods.
|
||||
*/
|
||||
public SeekWindow copyOffsetByPeriodCount(int periodCount) {
|
||||
return new SeekWindow(startPeriodIndex + periodCount, startTimeUs, endPeriodIndex + periodCount,
|
||||
endTimeUs);
|
||||
return new SeekWindow(startPeriodIndex + periodCount, startTimeMs, endPeriodIndex + periodCount,
|
||||
endTimeMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 17;
|
||||
result = 31 * result + startPeriodIndex;
|
||||
result = 31 * result + (int) startTimeUs;
|
||||
result = 31 * result + (int) startTimeMs;
|
||||
result = 31 * result + endPeriodIndex;
|
||||
result = 31 * result + (int) endTimeUs;
|
||||
result = 31 * result + (int) endTimeMs;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -100,15 +105,15 @@ public final class SeekWindow {
|
|||
}
|
||||
SeekWindow other = (SeekWindow) obj;
|
||||
return other.startPeriodIndex == startPeriodIndex
|
||||
&& other.startTimeUs == startTimeUs
|
||||
&& other.startTimeMs == startTimeMs
|
||||
&& other.endPeriodIndex == endPeriodIndex
|
||||
&& other.endTimeUs == endTimeUs;
|
||||
&& other.endTimeMs == endTimeMs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SeekWindow[" + startPeriodIndex + ", " + startTimeUs + ", " + endPeriodIndex + ", "
|
||||
+ endTimeUs + "]";
|
||||
return "SeekWindow[" + startPeriodIndex + ", " + startTimeMs + ", " + endPeriodIndex + ", "
|
||||
+ endTimeMs + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ public final class SinglePeriodTimeline implements Timeline {
|
|||
* @return A new, seekable, final timeline with one period.
|
||||
*/
|
||||
public static Timeline createSeekableFinalTimeline(Object id, long durationUs) {
|
||||
return new SinglePeriodTimeline(id, true, durationUs / 1000, new SeekWindow(durationUs));
|
||||
return new SinglePeriodTimeline(id, true, durationUs / 1000,
|
||||
SeekWindow.createWindowFromZero(durationUs));
|
||||
}
|
||||
|
||||
private final Object id;
|
||||
|
|
|
|||
|
|
@ -61,10 +61,10 @@ public final class DashMediaSource implements MediaSource {
|
|||
*/
|
||||
private static final int NOTIFY_MANIFEST_INTERVAL_MS = 5000;
|
||||
/**
|
||||
* The offset in microseconds subtracted from the live edge position when calculating the default
|
||||
* The offset in milliseconds subtracted from the live edge position when calculating the default
|
||||
* position returned by {@link #getDefaultStartPosition(int)}.
|
||||
*/
|
||||
private static final long LIVE_EDGE_OFFSET_US = 30000000;
|
||||
private static final long LIVE_EDGE_OFFSET_MS = 30000;
|
||||
|
||||
private static final String TAG = "DashMediaSource";
|
||||
|
||||
|
|
@ -165,14 +165,14 @@ public final class DashMediaSource implements MediaSource {
|
|||
if (index == 0 && manifest.dynamic) {
|
||||
// The stream is live, so return a position a position offset from the live edge.
|
||||
int periodIndex = seekWindow.endPeriodIndex;
|
||||
long positionUs = seekWindow.endTimeUs - LIVE_EDGE_OFFSET_US;
|
||||
while (positionUs < 0 && periodIndex > seekWindow.startPeriodIndex) {
|
||||
long positionMs = seekWindow.endTimeMs - LIVE_EDGE_OFFSET_MS;
|
||||
while (positionMs < 0 && periodIndex > seekWindow.startPeriodIndex) {
|
||||
periodIndex--;
|
||||
positionUs += manifest.getPeriodDurationUs(periodIndex);
|
||||
positionMs += manifest.getPeriodDurationMs(periodIndex);
|
||||
}
|
||||
positionUs = Math.max(positionUs,
|
||||
periodIndex == seekWindow.startPeriodIndex ? seekWindow.startTimeUs : 0);
|
||||
return new Position(periodIndex, positionUs);
|
||||
positionMs = Math.max(positionMs,
|
||||
periodIndex == seekWindow.startPeriodIndex ? seekWindow.startTimeMs : 0);
|
||||
return new Position(periodIndex, positionMs * 1000);
|
||||
}
|
||||
return new Position(index, 0);
|
||||
}
|
||||
|
|
@ -396,7 +396,7 @@ public final class DashMediaSource implements MediaSource {
|
|||
currentStartTimeUs = firstPeriodSeekInfo.availableStartTimeUs;
|
||||
currentEndTimeUs = lastPeriodSeekInfo.availableEndTimeUs;
|
||||
}
|
||||
seekWindow = new SeekWindow(0, currentStartTimeUs, lastPeriodIndex, currentEndTimeUs);
|
||||
seekWindow = SeekWindow.createWindow(0, currentStartTimeUs, lastPeriodIndex, currentEndTimeUs);
|
||||
|
||||
DashMediaPeriod[] mediaPeriods =
|
||||
periods.toArray(new DashMediaPeriod[manifest.getPeriodCount()]);
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@ public final class SsMediaSource implements MediaSource,
|
|||
*/
|
||||
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3;
|
||||
/**
|
||||
* The offset in microseconds subtracted from the live edge position when calculating the default
|
||||
* The offset in milliseconds subtracted from the live edge position when calculating the default
|
||||
* position returned by {@link #getDefaultStartPosition(int)}.
|
||||
*/
|
||||
private static final long LIVE_EDGE_OFFSET_US = 30000000;
|
||||
private static final long LIVE_EDGE_OFFSET_MS = 30000;
|
||||
|
||||
private static final int MINIMUM_MANIFEST_REFRESH_PERIOD_MS = 5000;
|
||||
|
||||
|
|
@ -114,8 +114,8 @@ public final class SsMediaSource implements MediaSource,
|
|||
return null;
|
||||
}
|
||||
if (manifest.isLive) {
|
||||
long startPositionUs = Math.max(seekWindow.startTimeUs,
|
||||
seekWindow.endTimeUs - LIVE_EDGE_OFFSET_US);
|
||||
long startPositionUs = Math.max(seekWindow.startTimeMs,
|
||||
seekWindow.endTimeMs - LIVE_EDGE_OFFSET_MS) * 1000;
|
||||
return new Position(0, startPositionUs);
|
||||
}
|
||||
return Position.DEFAULT;
|
||||
|
|
@ -172,7 +172,7 @@ public final class SsMediaSource implements MediaSource,
|
|||
timeline = SinglePeriodTimeline.createNonFinalTimeline(this);
|
||||
} else {
|
||||
timeline = SinglePeriodTimeline.createNonFinalTimeline(this,
|
||||
new SeekWindow(0, startTimeUs, 0, startTimeUs + manifest.dvrWindowLengthUs));
|
||||
SeekWindow.createWindow(0, startTimeUs, 0, startTimeUs + manifest.dvrWindowLengthUs));
|
||||
}
|
||||
} else if (manifest.durationUs == C.UNSET_TIME_US) {
|
||||
timeline = SinglePeriodTimeline.createUnseekableFinalTimeline(this, C.UNSET_TIME_US);
|
||||
|
|
|
|||
Loading…
Reference in a new issue