From 4502a464dd416923fdf648d93ff4a67360a13e86 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 10 Aug 2016 08:22:51 -0700 Subject: [PATCH] Use ms for SeekWindow, for consistency with Timeline ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=129868070 --- .../android/exoplayer2/source/SeekWindow.java | 77 ++++++++++--------- .../source/SinglePeriodTimeline.java | 3 +- .../source/dash/DashMediaSource.java | 18 ++--- .../source/smoothstreaming/SsMediaSource.java | 10 +-- 4 files changed, 57 insertions(+), 51 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/source/SeekWindow.java b/library/src/main/java/com/google/android/exoplayer2/source/SeekWindow.java index 14ce0f9529..61a5207498 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/SeekWindow.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/SeekWindow.java @@ -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 + "]"; } } diff --git a/library/src/main/java/com/google/android/exoplayer2/source/SinglePeriodTimeline.java b/library/src/main/java/com/google/android/exoplayer2/source/SinglePeriodTimeline.java index 42c4109ddb..b5c4571d3e 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/SinglePeriodTimeline.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/SinglePeriodTimeline.java @@ -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; diff --git a/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java b/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java index 1399172384..95d4a70aa7 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java @@ -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()]); diff --git a/library/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java b/library/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java index 614cc1b6c2..af36757761 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/SsMediaSource.java @@ -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);