Commit 1c824561 by ibaker Committed by bachinger

Migrate callers of deprecated C.java methods to Util.java

#minor-release

PiperOrigin-RevId: 406166670
parent 689a92c9
Showing with 215 additions and 186 deletions
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.ext.cast; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.ext.cast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.Util;
import com.google.android.gms.cast.CastStatusCodes; import com.google.android.gms.cast.CastStatusCodes;
import com.google.android.gms.cast.MediaInfo; import com.google.android.gms.cast.MediaInfo;
import com.google.android.gms.cast.MediaTrack; import com.google.android.gms.cast.MediaTrack;
...@@ -42,7 +43,7 @@ import com.google.android.gms.cast.MediaTrack; ...@@ -42,7 +43,7 @@ import com.google.android.gms.cast.MediaTrack;
} }
long durationMs = mediaInfo.getStreamDuration(); long durationMs = mediaInfo.getStreamDuration();
return durationMs != MediaInfo.UNKNOWN_DURATION && durationMs != LIVE_STREAM_DURATION return durationMs != MediaInfo.UNKNOWN_DURATION && durationMs != LIVE_STREAM_DURATION
? C.msToUs(durationMs) ? Util.msToUs(durationMs)
: C.TIME_UNSET; : C.TIME_UNSET;
} }
......
...@@ -21,6 +21,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; ...@@ -21,6 +21,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.testutil.TimelineAsserts; import com.google.android.exoplayer2.testutil.TimelineAsserts;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import com.google.android.gms.cast.MediaInfo; import com.google.android.gms.cast.MediaInfo;
import com.google.android.gms.cast.MediaStatus; import com.google.android.gms.cast.MediaStatus;
import com.google.android.gms.cast.framework.media.MediaQueue; import com.google.android.gms.cast.framework.media.MediaQueue;
...@@ -52,7 +53,7 @@ public class CastTimelineTrackerTest { ...@@ -52,7 +53,7 @@ public class CastTimelineTrackerTest {
TimelineAsserts.assertPeriodDurations( TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(remoteMediaClient), tracker.getCastTimeline(remoteMediaClient),
C.TIME_UNSET, C.TIME_UNSET,
C.msToUs(DURATION_2_MS), Util.msToUs(DURATION_2_MS),
C.TIME_UNSET, C.TIME_UNSET,
C.TIME_UNSET, C.TIME_UNSET,
C.TIME_UNSET); C.TIME_UNSET);
...@@ -65,8 +66,8 @@ public class CastTimelineTrackerTest { ...@@ -65,8 +66,8 @@ public class CastTimelineTrackerTest {
TimelineAsserts.assertPeriodDurations( TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(remoteMediaClient), tracker.getCastTimeline(remoteMediaClient),
C.TIME_UNSET, C.TIME_UNSET,
C.msToUs(DURATION_2_MS), Util.msToUs(DURATION_2_MS),
C.msToUs(DURATION_3_MS)); Util.msToUs(DURATION_3_MS));
remoteMediaClient = remoteMediaClient =
mockRemoteMediaClient( mockRemoteMediaClient(
...@@ -74,7 +75,7 @@ public class CastTimelineTrackerTest { ...@@ -74,7 +75,7 @@ public class CastTimelineTrackerTest {
/* currentItemId= */ 3, /* currentItemId= */ 3,
/* currentDurationMs= */ DURATION_3_MS); /* currentDurationMs= */ DURATION_3_MS);
TimelineAsserts.assertPeriodDurations( TimelineAsserts.assertPeriodDurations(
tracker.getCastTimeline(remoteMediaClient), C.TIME_UNSET, C.msToUs(DURATION_3_MS)); tracker.getCastTimeline(remoteMediaClient), C.TIME_UNSET, Util.msToUs(DURATION_3_MS));
remoteMediaClient = remoteMediaClient =
mockRemoteMediaClient( mockRemoteMediaClient(
...@@ -85,8 +86,8 @@ public class CastTimelineTrackerTest { ...@@ -85,8 +86,8 @@ public class CastTimelineTrackerTest {
tracker.getCastTimeline(remoteMediaClient), tracker.getCastTimeline(remoteMediaClient),
C.TIME_UNSET, C.TIME_UNSET,
C.TIME_UNSET, C.TIME_UNSET,
C.msToUs(DURATION_3_MS), Util.msToUs(DURATION_3_MS),
C.msToUs(DURATION_4_MS), Util.msToUs(DURATION_4_MS),
C.TIME_UNSET); C.TIME_UNSET);
remoteMediaClient = remoteMediaClient =
...@@ -98,9 +99,9 @@ public class CastTimelineTrackerTest { ...@@ -98,9 +99,9 @@ public class CastTimelineTrackerTest {
tracker.getCastTimeline(remoteMediaClient), tracker.getCastTimeline(remoteMediaClient),
C.TIME_UNSET, C.TIME_UNSET,
C.TIME_UNSET, C.TIME_UNSET,
C.msToUs(DURATION_3_MS), Util.msToUs(DURATION_3_MS),
C.msToUs(DURATION_4_MS), Util.msToUs(DURATION_4_MS),
C.msToUs(DURATION_5_MS)); Util.msToUs(DURATION_5_MS));
} }
private static RemoteMediaClient mockRemoteMediaClient( private static RemoteMediaClient mockRemoteMediaClient(
......
...@@ -348,7 +348,7 @@ import java.util.Map; ...@@ -348,7 +348,7 @@ import java.util.Map;
long contentPositionMs = getContentPeriodPositionMs(player, timeline, period); long contentPositionMs = getContentPeriodPositionMs(player, timeline, period);
int adGroupForPositionIndex = int adGroupForPositionIndex =
adPlaybackState.getAdGroupIndexForPositionUs( adPlaybackState.getAdGroupIndexForPositionUs(
C.msToUs(contentPositionMs), C.msToUs(contentDurationMs)); Util.msToUs(contentPositionMs), Util.msToUs(contentDurationMs));
if (adGroupForPositionIndex != C.INDEX_UNSET if (adGroupForPositionIndex != C.INDEX_UNSET
&& imaAdInfo != null && imaAdInfo != null
&& imaAdInfo.adGroupIndex != adGroupForPositionIndex) { && imaAdInfo.adGroupIndex != adGroupForPositionIndex) {
...@@ -372,7 +372,7 @@ import java.util.Map; ...@@ -372,7 +372,7 @@ import java.util.Map;
} }
adPlaybackState = adPlaybackState =
adPlaybackState.withAdResumePositionUs( adPlaybackState.withAdResumePositionUs(
playingAd ? C.msToUs(player.getCurrentPosition()) : 0); playingAd ? Util.msToUs(player.getCurrentPosition()) : 0);
} }
lastVolumePercent = getPlayerVolumePercent(); lastVolumePercent = getPlayerVolumePercent();
lastAdProgress = getAdVideoProgressUpdate(); lastAdProgress = getAdVideoProgressUpdate();
...@@ -456,7 +456,7 @@ import java.util.Map; ...@@ -456,7 +456,7 @@ import java.util.Map;
this.timeline = timeline; this.timeline = timeline;
Player player = checkNotNull(this.player); Player player = checkNotNull(this.player);
long contentDurationUs = timeline.getPeriod(player.getCurrentPeriodIndex(), period).durationUs; long contentDurationUs = timeline.getPeriod(player.getCurrentPeriodIndex(), period).durationUs;
contentDurationMs = C.usToMs(contentDurationUs); contentDurationMs = Util.usToMs(contentDurationUs);
if (contentDurationUs != adPlaybackState.contentDurationUs) { if (contentDurationUs != adPlaybackState.contentDurationUs) {
adPlaybackState = adPlaybackState.withContentDurationUs(contentDurationUs); adPlaybackState = adPlaybackState.withContentDurationUs(contentDurationUs);
updateAdPlaybackState(); updateAdPlaybackState();
...@@ -602,10 +602,11 @@ import java.util.Map; ...@@ -602,10 +602,11 @@ import java.util.Map;
// Skip ads based on the start position as required. // Skip ads based on the start position as required.
int adGroupForPositionIndex = int adGroupForPositionIndex =
adPlaybackState.getAdGroupIndexForPositionUs( adPlaybackState.getAdGroupIndexForPositionUs(
C.msToUs(contentPositionMs), C.msToUs(contentDurationMs)); Util.msToUs(contentPositionMs), Util.msToUs(contentDurationMs));
if (adGroupForPositionIndex != C.INDEX_UNSET) { if (adGroupForPositionIndex != C.INDEX_UNSET) {
boolean playAdWhenStartingPlayback = boolean playAdWhenStartingPlayback =
adPlaybackState.getAdGroup(adGroupForPositionIndex).timeUs == C.msToUs(contentPositionMs) adPlaybackState.getAdGroup(adGroupForPositionIndex).timeUs
== Util.msToUs(contentPositionMs)
|| configuration.playAdBeforeStartPosition; || configuration.playAdBeforeStartPosition;
if (!playAdWhenStartingPlayback) { if (!playAdWhenStartingPlayback) {
adGroupForPositionIndex++; adGroupForPositionIndex++;
...@@ -790,7 +791,7 @@ import java.util.Map; ...@@ -790,7 +791,7 @@ import java.util.Map;
// An ad is available already. // An ad is available already.
return false; return false;
} }
long adGroupTimeMs = C.usToMs(adGroup.timeUs); long adGroupTimeMs = Util.usToMs(adGroup.timeUs);
long contentPositionMs = getContentPeriodPositionMs(player, timeline, period); long contentPositionMs = getContentPeriodPositionMs(player, timeline, period);
long timeUntilAdMs = adGroupTimeMs - contentPositionMs; long timeUntilAdMs = adGroupTimeMs - contentPositionMs;
return timeUntilAdMs < configuration.adPreloadTimeoutMs; return timeUntilAdMs < configuration.adPreloadTimeoutMs;
...@@ -840,7 +841,7 @@ import java.util.Map; ...@@ -840,7 +841,7 @@ import java.util.Map;
if (!sentContentComplete && !timeline.isEmpty()) { if (!sentContentComplete && !timeline.isEmpty()) {
long positionMs = getContentPeriodPositionMs(player, timeline, period); long positionMs = getContentPeriodPositionMs(player, timeline, period);
timeline.getPeriod(player.getCurrentPeriodIndex(), period); timeline.getPeriod(player.getCurrentPeriodIndex(), period);
int newAdGroupIndex = period.getAdGroupIndexForPositionUs(C.msToUs(positionMs)); int newAdGroupIndex = period.getAdGroupIndexForPositionUs(Util.msToUs(positionMs));
if (newAdGroupIndex != C.INDEX_UNSET) { if (newAdGroupIndex != C.INDEX_UNSET) {
sentPendingContentPositionMs = false; sentPendingContentPositionMs = false;
pendingContentPositionMs = positionMs; pendingContentPositionMs = positionMs;
...@@ -880,7 +881,7 @@ import java.util.Map; ...@@ -880,7 +881,7 @@ import java.util.Map;
} else { } else {
// IMA hasn't called playAd yet, so fake the content position. // IMA hasn't called playAd yet, so fake the content position.
fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime(); fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime();
fakeContentProgressOffsetMs = C.usToMs(adGroup.timeUs); fakeContentProgressOffsetMs = Util.usToMs(adGroup.timeUs);
if (fakeContentProgressOffsetMs == C.TIME_END_OF_SOURCE) { if (fakeContentProgressOffsetMs == C.TIME_END_OF_SOURCE) {
fakeContentProgressOffsetMs = contentDurationMs; fakeContentProgressOffsetMs = contentDurationMs;
} }
...@@ -1091,7 +1092,7 @@ import java.util.Map; ...@@ -1091,7 +1092,7 @@ import java.util.Map;
// Send IMA a content position at the ad group so that it will try to play it, at which point // Send IMA a content position at the ad group so that it will try to play it, at which point
// we can notify that it failed to load. // we can notify that it failed to load.
fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime(); fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime();
fakeContentProgressOffsetMs = C.usToMs(adPlaybackState.getAdGroup(adGroupIndex).timeUs); fakeContentProgressOffsetMs = Util.usToMs(adPlaybackState.getAdGroup(adGroupIndex).timeUs);
if (fakeContentProgressOffsetMs == C.TIME_END_OF_SOURCE) { if (fakeContentProgressOffsetMs == C.TIME_END_OF_SOURCE) {
fakeContentProgressOffsetMs = contentDurationMs; fakeContentProgressOffsetMs = contentDurationMs;
} }
...@@ -1192,13 +1193,14 @@ import java.util.Map; ...@@ -1192,13 +1193,14 @@ import java.util.Map;
if (player == null) { if (player == null) {
return C.INDEX_UNSET; return C.INDEX_UNSET;
} }
long playerPositionUs = C.msToUs(getContentPeriodPositionMs(player, timeline, period)); long playerPositionUs = Util.msToUs(getContentPeriodPositionMs(player, timeline, period));
int adGroupIndex = int adGroupIndex =
adPlaybackState.getAdGroupIndexForPositionUs(playerPositionUs, C.msToUs(contentDurationMs)); adPlaybackState.getAdGroupIndexForPositionUs(
playerPositionUs, Util.msToUs(contentDurationMs));
if (adGroupIndex == C.INDEX_UNSET) { if (adGroupIndex == C.INDEX_UNSET) {
adGroupIndex = adGroupIndex =
adPlaybackState.getAdGroupIndexAfterPositionUs( adPlaybackState.getAdGroupIndexAfterPositionUs(
playerPositionUs, C.msToUs(contentDurationMs)); playerPositionUs, Util.msToUs(contentDurationMs));
} }
return adGroupIndex; return adGroupIndex;
} }
......
...@@ -703,7 +703,7 @@ public final class ImaAdsLoader implements Player.Listener, AdsLoader { ...@@ -703,7 +703,7 @@ public final class ImaAdsLoader implements Player.Listener, AdsLoader {
timeline.getPeriodPosition( timeline.getPeriodPosition(
window, period, period.windowIndex, /* windowPositionUs= */ C.TIME_UNSET) window, period, period.windowIndex, /* windowPositionUs= */ C.TIME_UNSET)
.second; .second;
nextAdTagLoader.maybePreloadAds(C.usToMs(periodPositionUs), C.usToMs(period.durationUs)); nextAdTagLoader.maybePreloadAds(Util.usToMs(periodPositionUs), Util.usToMs(period.durationUs));
} }
/** /**
......
...@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray; ...@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.ListenerSet; import com.google.android.exoplayer2.util.ListenerSet;
import com.google.android.exoplayer2.util.Util;
/** A fake player for testing content/ad playback. */ /** A fake player for testing content/ad playback. */
/* package */ final class FakePlayer extends StubExoPlayer { /* package */ final class FakePlayer extends StubExoPlayer {
...@@ -277,7 +278,7 @@ import com.google.android.exoplayer2.util.ListenerSet; ...@@ -277,7 +278,7 @@ import com.google.android.exoplayer2.util.ListenerSet;
if (isPlayingAd()) { if (isPlayingAd()) {
long adDurationUs = long adDurationUs =
timeline.getPeriod(0, period).getAdDurationUs(adGroupIndex, adIndexInAdGroup); timeline.getPeriod(0, period).getAdDurationUs(adGroupIndex, adIndexInAdGroup);
return C.usToMs(adDurationUs); return Util.usToMs(adDurationUs);
} else { } else {
return timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); return timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs();
} }
......
...@@ -384,13 +384,13 @@ public final class ImaAdsLoaderTest { ...@@ -384,13 +384,13 @@ public final class ImaAdsLoaderTest {
playerPositionUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US; playerPositionUs + TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US;
long periodDurationUs = long periodDurationUs =
CONTENT_TIMELINE.getPeriod(/* periodIndex= */ 0, new Period()).durationUs; CONTENT_TIMELINE.getPeriod(/* periodIndex= */ 0, new Period()).durationUs;
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(playerPositionUs)); fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, Util.usToMs(playerPositionUs));
// Verify the content progress is updated to reflect the new player position. // Verify the content progress is updated to reflect the new player position.
assertThat(contentProgressProvider.getContentProgress()) assertThat(contentProgressProvider.getContentProgress())
.isEqualTo( .isEqualTo(
new VideoProgressUpdate( new VideoProgressUpdate(
C.usToMs(playerPositionInPeriodUs), C.usToMs(periodDurationUs))); Util.usToMs(playerPositionInPeriodUs), Util.usToMs(periodDurationUs)));
} }
@Test @Test
...@@ -428,7 +428,8 @@ public final class ImaAdsLoaderTest { ...@@ -428,7 +428,8 @@ public final class ImaAdsLoaderTest {
// Advance playback to just before the midroll and simulate buffering. // Advance playback to just before the midroll and simulate buffering.
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(adGroupPositionInWindowUs)); fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, Util.usToMs(adGroupPositionInWindowUs));
fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */ true); fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */ true);
// Advance before the timeout and simulating polling content progress. // Advance before the timeout and simulating polling content progress.
ShadowSystemClock.advanceBy(Duration.ofSeconds(1)); ShadowSystemClock.advanceBy(Duration.ofSeconds(1));
...@@ -453,7 +454,8 @@ public final class ImaAdsLoaderTest { ...@@ -453,7 +454,8 @@ public final class ImaAdsLoaderTest {
// Advance playback to just before the midroll and simulate buffering. // Advance playback to just before the midroll and simulate buffering.
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(adGroupPositionInWindowUs)); fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, Util.usToMs(adGroupPositionInWindowUs));
fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */ true); fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */ true);
// Advance past the timeout and simulate polling content progress. // Advance past the timeout and simulate polling content progress.
ShadowSystemClock.advanceBy(Duration.ofSeconds(5)); ShadowSystemClock.advanceBy(Duration.ofSeconds(5));
...@@ -478,7 +480,8 @@ public final class ImaAdsLoaderTest { ...@@ -478,7 +480,8 @@ public final class ImaAdsLoaderTest {
ImmutableList<Float> cuePoints = ImmutableList.of((float) adGroupTimeUs / C.MICROS_PER_SECOND); ImmutableList<Float> cuePoints = ImmutableList.of((float) adGroupTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */ true); fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */ true);
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(adGroupPositionInWindowUs)); fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, Util.usToMs(adGroupPositionInWindowUs));
// Start ad loading while still buffering and simulate the calls from the IMA SDK to resume then // Start ad loading while still buffering and simulate the calls from the IMA SDK to resume then
// immediately pause content playback. // immediately pause content playback.
...@@ -506,7 +509,8 @@ public final class ImaAdsLoaderTest { ...@@ -506,7 +509,8 @@ public final class ImaAdsLoaderTest {
ImmutableList<Float> cuePoints = ImmutableList.of((float) adGroupTimeUs / C.MICROS_PER_SECOND); ImmutableList<Float> cuePoints = ImmutableList.of((float) adGroupTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */ true); fakePlayer.setState(Player.STATE_BUFFERING, /* playWhenReady= */ true);
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(adGroupPositionInWindowUs)); fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, Util.usToMs(adGroupPositionInWindowUs));
// Start ad loading while still buffering and poll progress without the ad loading. // Start ad loading while still buffering and poll progress without the ad loading.
imaAdsLoader.start( imaAdsLoader.start(
...@@ -597,7 +601,7 @@ public final class ImaAdsLoaderTest { ...@@ -597,7 +601,7 @@ public final class ImaAdsLoaderTest {
verify(mockVideoAdPlayerCallback) verify(mockVideoAdPlayerCallback)
.onAdProgress( .onAdProgress(
TEST_AD_MEDIA_INFO, TEST_AD_MEDIA_INFO,
new VideoProgressUpdate(newPlayerPositionMs, C.usToMs(TEST_AD_DURATION_US))); new VideoProgressUpdate(newPlayerPositionMs, Util.usToMs(TEST_AD_DURATION_US)));
} }
@Test @Test
...@@ -610,7 +614,7 @@ public final class ImaAdsLoaderTest { ...@@ -610,7 +614,7 @@ public final class ImaAdsLoaderTest {
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition( fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, C.usToMs(midrollWindowTimeUs) - 1_000); /* periodIndex= */ 0, Util.usToMs(midrollWindowTimeUs) - 1_000);
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -630,7 +634,7 @@ public final class ImaAdsLoaderTest { ...@@ -630,7 +634,7 @@ public final class ImaAdsLoaderTest {
ImmutableList.of(0f, (float) midrollPeriodTimeUs / C.MICROS_PER_SECOND); ImmutableList.of(0f, (float) midrollPeriodTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(midrollWindowTimeUs)); fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, Util.usToMs(midrollWindowTimeUs));
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -657,7 +661,7 @@ public final class ImaAdsLoaderTest { ...@@ -657,7 +661,7 @@ public final class ImaAdsLoaderTest {
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition( fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, C.usToMs(midrollWindowTimeUs) + 1_000); /* periodIndex= */ 0, Util.usToMs(midrollWindowTimeUs) + 1_000);
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -691,7 +695,7 @@ public final class ImaAdsLoaderTest { ...@@ -691,7 +695,7 @@ public final class ImaAdsLoaderTest {
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition( fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, C.usToMs(secondMidrollWindowTimeUs) - 1_000); /* periodIndex= */ 0, Util.usToMs(secondMidrollWindowTimeUs) - 1_000);
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -718,7 +722,8 @@ public final class ImaAdsLoaderTest { ...@@ -718,7 +722,8 @@ public final class ImaAdsLoaderTest {
(float) secondMidrollPeriodTimeUs / C.MICROS_PER_SECOND); (float) secondMidrollPeriodTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(secondMidrollWindowTimeUs)); fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, Util.usToMs(secondMidrollWindowTimeUs));
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -760,7 +765,7 @@ public final class ImaAdsLoaderTest { ...@@ -760,7 +765,7 @@ public final class ImaAdsLoaderTest {
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition( fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, C.usToMs(midrollWindowTimeUs) - 1_000); /* periodIndex= */ 0, Util.usToMs(midrollWindowTimeUs) - 1_000);
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -801,7 +806,7 @@ public final class ImaAdsLoaderTest { ...@@ -801,7 +806,7 @@ public final class ImaAdsLoaderTest {
ImmutableList.of(0f, (float) midrollPeriodTimeUs / C.MICROS_PER_SECOND); ImmutableList.of(0f, (float) midrollPeriodTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(midrollWindowTimeUs)); fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, Util.usToMs(midrollWindowTimeUs));
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -843,7 +848,7 @@ public final class ImaAdsLoaderTest { ...@@ -843,7 +848,7 @@ public final class ImaAdsLoaderTest {
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition( fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, C.usToMs(midrollWindowTimeUs) + 1_000); /* periodIndex= */ 0, Util.usToMs(midrollWindowTimeUs) + 1_000);
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -889,7 +894,7 @@ public final class ImaAdsLoaderTest { ...@@ -889,7 +894,7 @@ public final class ImaAdsLoaderTest {
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition( fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, C.usToMs(secondMidrollWindowTimeUs) - 1_000); /* periodIndex= */ 0, Util.usToMs(secondMidrollWindowTimeUs) - 1_000);
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
...@@ -937,7 +942,8 @@ public final class ImaAdsLoaderTest { ...@@ -937,7 +942,8 @@ public final class ImaAdsLoaderTest {
(float) secondMidrollPeriodTimeUs / C.MICROS_PER_SECOND); (float) secondMidrollPeriodTimeUs / C.MICROS_PER_SECOND);
when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints); when(mockAdsManager.getAdCuePoints()).thenReturn(cuePoints);
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, C.usToMs(secondMidrollWindowTimeUs)); fakePlayer.setPlayingContentPosition(
/* periodIndex= */ 0, Util.usToMs(secondMidrollWindowTimeUs));
imaAdsLoader.start( imaAdsLoader.start(
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener); adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
......
...@@ -300,7 +300,7 @@ public abstract class Timeline implements Bundleable { ...@@ -300,7 +300,7 @@ public abstract class Timeline implements Bundleable {
* whilst remaining within the bounds of the window. * whilst remaining within the bounds of the window.
*/ */
public long getDefaultPositionMs() { public long getDefaultPositionMs() {
return C.usToMs(defaultPositionUs); return Util.usToMs(defaultPositionUs);
} }
/** /**
...@@ -315,7 +315,7 @@ public abstract class Timeline implements Bundleable { ...@@ -315,7 +315,7 @@ public abstract class Timeline implements Bundleable {
/** Returns the duration of the window in milliseconds, or {@link C#TIME_UNSET} if unknown. */ /** Returns the duration of the window in milliseconds, or {@link C#TIME_UNSET} if unknown. */
public long getDurationMs() { public long getDurationMs() {
return C.usToMs(durationUs); return Util.usToMs(durationUs);
} }
/** Returns the duration of this window in microseconds, or {@link C#TIME_UNSET} if unknown. */ /** Returns the duration of this window in microseconds, or {@link C#TIME_UNSET} if unknown. */
...@@ -328,7 +328,7 @@ public abstract class Timeline implements Bundleable { ...@@ -328,7 +328,7 @@ public abstract class Timeline implements Bundleable {
* belonging to it, in milliseconds. * belonging to it, in milliseconds.
*/ */
public long getPositionInFirstPeriodMs() { public long getPositionInFirstPeriodMs() {
return C.usToMs(positionInFirstPeriodUs); return Util.usToMs(positionInFirstPeriodUs);
} }
/** /**
...@@ -671,7 +671,7 @@ public abstract class Timeline implements Bundleable { ...@@ -671,7 +671,7 @@ public abstract class Timeline implements Bundleable {
/** Returns the duration of the period in milliseconds, or {@link C#TIME_UNSET} if unknown. */ /** Returns the duration of the period in milliseconds, or {@link C#TIME_UNSET} if unknown. */
public long getDurationMs() { public long getDurationMs() {
return C.usToMs(durationUs); return Util.usToMs(durationUs);
} }
/** Returns the duration of this period in microseconds, or {@link C#TIME_UNSET} if unknown. */ /** Returns the duration of this period in microseconds, or {@link C#TIME_UNSET} if unknown. */
...@@ -685,7 +685,7 @@ public abstract class Timeline implements Bundleable { ...@@ -685,7 +685,7 @@ public abstract class Timeline implements Bundleable {
* window. * window.
*/ */
public long getPositionInWindowMs() { public long getPositionInWindowMs() {
return C.usToMs(positionInWindowUs); return Util.usToMs(positionInWindowUs);
} }
/** /**
......
...@@ -106,9 +106,10 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC ...@@ -106,9 +106,10 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC
fallbackMaxPlaybackSpeed = DEFAULT_FALLBACK_MAX_PLAYBACK_SPEED; fallbackMaxPlaybackSpeed = DEFAULT_FALLBACK_MAX_PLAYBACK_SPEED;
minUpdateIntervalMs = DEFAULT_MIN_UPDATE_INTERVAL_MS; minUpdateIntervalMs = DEFAULT_MIN_UPDATE_INTERVAL_MS;
proportionalControlFactorUs = DEFAULT_PROPORTIONAL_CONTROL_FACTOR / C.MICROS_PER_SECOND; proportionalControlFactorUs = DEFAULT_PROPORTIONAL_CONTROL_FACTOR / C.MICROS_PER_SECOND;
maxLiveOffsetErrorUsForUnitSpeed = C.msToUs(DEFAULT_MAX_LIVE_OFFSET_ERROR_MS_FOR_UNIT_SPEED); maxLiveOffsetErrorUsForUnitSpeed =
Util.msToUs(DEFAULT_MAX_LIVE_OFFSET_ERROR_MS_FOR_UNIT_SPEED);
targetLiveOffsetIncrementOnRebufferUs = targetLiveOffsetIncrementOnRebufferUs =
C.msToUs(DEFAULT_TARGET_LIVE_OFFSET_INCREMENT_ON_REBUFFER_MS); Util.msToUs(DEFAULT_TARGET_LIVE_OFFSET_INCREMENT_ON_REBUFFER_MS);
minPossibleLiveOffsetSmoothingFactor = DEFAULT_MIN_POSSIBLE_LIVE_OFFSET_SMOOTHING_FACTOR; minPossibleLiveOffsetSmoothingFactor = DEFAULT_MIN_POSSIBLE_LIVE_OFFSET_SMOOTHING_FACTOR;
} }
...@@ -187,7 +188,7 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC ...@@ -187,7 +188,7 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC
*/ */
public Builder setMaxLiveOffsetErrorMsForUnitSpeed(long maxLiveOffsetErrorMsForUnitSpeed) { public Builder setMaxLiveOffsetErrorMsForUnitSpeed(long maxLiveOffsetErrorMsForUnitSpeed) {
Assertions.checkArgument(maxLiveOffsetErrorMsForUnitSpeed > 0); Assertions.checkArgument(maxLiveOffsetErrorMsForUnitSpeed > 0);
this.maxLiveOffsetErrorUsForUnitSpeed = C.msToUs(maxLiveOffsetErrorMsForUnitSpeed); this.maxLiveOffsetErrorUsForUnitSpeed = Util.msToUs(maxLiveOffsetErrorMsForUnitSpeed);
return this; return this;
} }
...@@ -202,7 +203,8 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC ...@@ -202,7 +203,8 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC
public Builder setTargetLiveOffsetIncrementOnRebufferMs( public Builder setTargetLiveOffsetIncrementOnRebufferMs(
long targetLiveOffsetIncrementOnRebufferMs) { long targetLiveOffsetIncrementOnRebufferMs) {
Assertions.checkArgument(targetLiveOffsetIncrementOnRebufferMs >= 0); Assertions.checkArgument(targetLiveOffsetIncrementOnRebufferMs >= 0);
this.targetLiveOffsetIncrementOnRebufferUs = C.msToUs(targetLiveOffsetIncrementOnRebufferMs); this.targetLiveOffsetIncrementOnRebufferUs =
Util.msToUs(targetLiveOffsetIncrementOnRebufferMs);
return this; return this;
} }
...@@ -295,9 +297,9 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC ...@@ -295,9 +297,9 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC
@Override @Override
public void setLiveConfiguration(LiveConfiguration liveConfiguration) { public void setLiveConfiguration(LiveConfiguration liveConfiguration) {
mediaConfigurationTargetLiveOffsetUs = C.msToUs(liveConfiguration.targetOffsetMs); mediaConfigurationTargetLiveOffsetUs = Util.msToUs(liveConfiguration.targetOffsetMs);
minTargetLiveOffsetUs = C.msToUs(liveConfiguration.minOffsetMs); minTargetLiveOffsetUs = Util.msToUs(liveConfiguration.minOffsetMs);
maxTargetLiveOffsetUs = C.msToUs(liveConfiguration.maxOffsetMs); maxTargetLiveOffsetUs = Util.msToUs(liveConfiguration.maxOffsetMs);
minPlaybackSpeed = minPlaybackSpeed =
liveConfiguration.minPlaybackSpeed != C.RATE_UNSET liveConfiguration.minPlaybackSpeed != C.RATE_UNSET
? liveConfiguration.minPlaybackSpeed ? liveConfiguration.minPlaybackSpeed
...@@ -416,7 +418,7 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC ...@@ -416,7 +418,7 @@ public final class DefaultLivePlaybackSpeedControl implements LivePlaybackSpeedC
// There is room for decreasing the target offset towards the ideal or safe offset (whichever // There is room for decreasing the target offset towards the ideal or safe offset (whichever
// is larger). We want to limit the decrease so that the playback speed delta we achieve is // is larger). We want to limit the decrease so that the playback speed delta we achieve is
// the same as the maximum delta when slowing down towards the target. // the same as the maximum delta when slowing down towards the target.
long minUpdateIntervalUs = C.msToUs(minUpdateIntervalMs); long minUpdateIntervalUs = Util.msToUs(minUpdateIntervalMs);
long decrementToOffsetCurrentSpeedUs = long decrementToOffsetCurrentSpeedUs =
(long) ((adjustedPlaybackSpeed - 1f) * minUpdateIntervalUs); (long) ((adjustedPlaybackSpeed - 1f) * minUpdateIntervalUs);
long decrementToIncreaseSpeedUs = (long) ((maxPlaybackSpeed - 1f) * minUpdateIntervalUs); long decrementToIncreaseSpeedUs = (long) ((maxPlaybackSpeed - 1f) * minUpdateIntervalUs);
......
...@@ -299,17 +299,17 @@ public class DefaultLoadControl implements LoadControl { ...@@ -299,17 +299,17 @@ public class DefaultLoadControl implements LoadControl {
assertGreaterOrEqual(backBufferDurationMs, 0, "backBufferDurationMs", "0"); assertGreaterOrEqual(backBufferDurationMs, 0, "backBufferDurationMs", "0");
this.allocator = allocator; this.allocator = allocator;
this.minBufferUs = C.msToUs(minBufferMs); this.minBufferUs = Util.msToUs(minBufferMs);
this.maxBufferUs = C.msToUs(maxBufferMs); this.maxBufferUs = Util.msToUs(maxBufferMs);
this.bufferForPlaybackUs = C.msToUs(bufferForPlaybackMs); this.bufferForPlaybackUs = Util.msToUs(bufferForPlaybackMs);
this.bufferForPlaybackAfterRebufferUs = C.msToUs(bufferForPlaybackAfterRebufferMs); this.bufferForPlaybackAfterRebufferUs = Util.msToUs(bufferForPlaybackAfterRebufferMs);
this.targetBufferBytesOverwrite = targetBufferBytes; this.targetBufferBytesOverwrite = targetBufferBytes;
this.targetBufferBytes = this.targetBufferBytes =
targetBufferBytesOverwrite != C.LENGTH_UNSET targetBufferBytesOverwrite != C.LENGTH_UNSET
? targetBufferBytesOverwrite ? targetBufferBytesOverwrite
: DEFAULT_MIN_BUFFER_SIZE; : DEFAULT_MIN_BUFFER_SIZE;
this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds; this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds;
this.backBufferDurationUs = C.msToUs(backBufferDurationMs); this.backBufferDurationUs = Util.msToUs(backBufferDurationMs);
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe; this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
} }
......
...@@ -359,7 +359,7 @@ public final class ExoPlaybackException extends PlaybackException { ...@@ -359,7 +359,7 @@ public final class ExoPlaybackException extends PlaybackException {
+ ", format=" + ", format="
+ rendererFormat + rendererFormat
+ ", format_supported=" + ", format_supported="
+ C.getFormatSupportString(rendererFormatSupport); + Util.getFormatSupportString(rendererFormatSupport);
break; break;
case TYPE_REMOTE: case TYPE_REMOTE:
message = "Remote error"; message = "Remote error";
......
...@@ -669,7 +669,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -669,7 +669,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
newPlaybackInfo, newPlaybackInfo,
timeline, timeline,
getPeriodPositionOrMaskWindowPosition(timeline, mediaItemIndex, positionMs)); getPeriodPositionOrMaskWindowPosition(timeline, mediaItemIndex, positionMs));
internalPlayer.seekTo(timeline, mediaItemIndex, C.msToUs(positionMs)); internalPlayer.seekTo(timeline, mediaItemIndex, Util.msToUs(positionMs));
updatePlaybackInfo( updatePlaybackInfo(
newPlaybackInfo, newPlaybackInfo,
/* ignored */ TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, /* ignored */ TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
...@@ -865,21 +865,21 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -865,21 +865,21 @@ import java.util.concurrent.CopyOnWriteArraySet;
MediaPeriodId periodId = playbackInfo.periodId; MediaPeriodId periodId = playbackInfo.periodId;
playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period); playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period);
long adDurationUs = period.getAdDurationUs(periodId.adGroupIndex, periodId.adIndexInAdGroup); long adDurationUs = period.getAdDurationUs(periodId.adGroupIndex, periodId.adIndexInAdGroup);
return C.usToMs(adDurationUs); return Util.usToMs(adDurationUs);
} }
return getContentDuration(); return getContentDuration();
} }
@Override @Override
public long getCurrentPosition() { public long getCurrentPosition() {
return C.usToMs(getCurrentPositionUsInternal(playbackInfo)); return Util.usToMs(getCurrentPositionUsInternal(playbackInfo));
} }
@Override @Override
public long getBufferedPosition() { public long getBufferedPosition() {
if (isPlayingAd()) { if (isPlayingAd()) {
return playbackInfo.loadingMediaPeriodId.equals(playbackInfo.periodId) return playbackInfo.loadingMediaPeriodId.equals(playbackInfo.periodId)
? C.usToMs(playbackInfo.bufferedPositionUs) ? Util.usToMs(playbackInfo.bufferedPositionUs)
: getDuration(); : getDuration();
} }
return getContentBufferedPosition(); return getContentBufferedPosition();
...@@ -887,7 +887,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -887,7 +887,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Override @Override
public long getTotalBufferedDuration() { public long getTotalBufferedDuration() {
return C.usToMs(playbackInfo.totalBufferedDurationUs); return Util.usToMs(playbackInfo.totalBufferedDurationUs);
} }
@Override @Override
...@@ -911,7 +911,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -911,7 +911,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period); playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period);
return playbackInfo.requestedContentPositionUs == C.TIME_UNSET return playbackInfo.requestedContentPositionUs == C.TIME_UNSET
? playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDefaultPositionMs() ? playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDefaultPositionMs()
: period.getPositionInWindowMs() + C.usToMs(playbackInfo.requestedContentPositionUs); : period.getPositionInWindowMs() + Util.usToMs(playbackInfo.requestedContentPositionUs);
} else { } else {
return getCurrentPosition(); return getCurrentPosition();
} }
...@@ -936,7 +936,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -936,7 +936,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
contentBufferedPositionUs = loadingPeriod.durationUs; contentBufferedPositionUs = loadingPeriod.durationUs;
} }
} }
return C.usToMs( return Util.usToMs(
periodPositionUsToWindowPositionUs( periodPositionUsToWindowPositionUs(
playbackInfo.timeline, playbackInfo.loadingMediaPeriodId, contentBufferedPositionUs)); playbackInfo.timeline, playbackInfo.loadingMediaPeriodId, contentBufferedPositionUs));
} }
...@@ -1136,7 +1136,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1136,7 +1136,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
private long getCurrentPositionUsInternal(PlaybackInfo playbackInfo) { private long getCurrentPositionUsInternal(PlaybackInfo playbackInfo) {
if (playbackInfo.timeline.isEmpty()) { if (playbackInfo.timeline.isEmpty()) {
return C.msToUs(maskingWindowPositionMs); return Util.msToUs(maskingWindowPositionMs);
} else if (playbackInfo.periodId.isAd()) { } else if (playbackInfo.periodId.isAd()) {
return playbackInfo.positionUs; return playbackInfo.positionUs;
} else { } else {
...@@ -1425,8 +1425,8 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1425,8 +1425,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
oldMediaItem, oldMediaItem,
oldPeriodUid, oldPeriodUid,
oldPeriodIndex, oldPeriodIndex,
C.usToMs(oldPositionUs), Util.usToMs(oldPositionUs),
C.usToMs(oldContentPositionUs), Util.usToMs(oldContentPositionUs),
oldPlaybackInfo.periodId.adGroupIndex, oldPlaybackInfo.periodId.adGroupIndex,
oldPlaybackInfo.periodId.adIndexInAdGroup); oldPlaybackInfo.periodId.adIndexInAdGroup);
} }
...@@ -1444,7 +1444,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1444,7 +1444,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
newWindowUid = playbackInfo.timeline.getWindow(newWindowIndex, window).uid; newWindowUid = playbackInfo.timeline.getWindow(newWindowIndex, window).uid;
newMediaItem = window.mediaItem; newMediaItem = window.mediaItem;
} }
long positionMs = C.usToMs(discontinuityWindowStartPositionUs); long positionMs = Util.usToMs(discontinuityWindowStartPositionUs);
return new PositionInfo( return new PositionInfo(
newWindowUid, newWindowUid,
newWindowIndex, newWindowIndex,
...@@ -1453,7 +1453,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1453,7 +1453,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
newPeriodIndex, newPeriodIndex,
positionMs, positionMs,
/* contentPositionMs= */ playbackInfo.periodId.isAd() /* contentPositionMs= */ playbackInfo.periodId.isAd()
? C.usToMs(getRequestedContentPositionUs(playbackInfo)) ? Util.usToMs(getRequestedContentPositionUs(playbackInfo))
: positionMs, : positionMs,
playbackInfo.periodId.adGroupIndex, playbackInfo.periodId.adGroupIndex,
playbackInfo.periodId.adIndexInAdGroup); playbackInfo.periodId.adIndexInAdGroup);
...@@ -1567,7 +1567,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1567,7 +1567,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
newPlaybackInfo = newPlaybackInfo.copyWithPlaybackState(maskingPlaybackState); newPlaybackInfo = newPlaybackInfo.copyWithPlaybackState(maskingPlaybackState);
internalPlayer.setMediaSources( internalPlayer.setMediaSources(
holders, startWindowIndex, C.msToUs(startPositionMs), shuffleOrder); holders, startWindowIndex, Util.msToUs(startPositionMs), shuffleOrder);
boolean positionDiscontinuity = boolean positionDiscontinuity =
!playbackInfo.periodId.periodUid.equals(newPlaybackInfo.periodId.periodUid) !playbackInfo.periodId.periodUid.equals(newPlaybackInfo.periodId.periodUid)
&& !playbackInfo.timeline.isEmpty(); && !playbackInfo.timeline.isEmpty();
...@@ -1647,7 +1647,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1647,7 +1647,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
if (timeline.isEmpty()) { if (timeline.isEmpty()) {
// Reset periodId and loadingPeriodId. // Reset periodId and loadingPeriodId.
MediaPeriodId dummyMediaPeriodId = PlaybackInfo.getDummyPeriodForEmptyTimeline(); MediaPeriodId dummyMediaPeriodId = PlaybackInfo.getDummyPeriodForEmptyTimeline();
long positionUs = C.msToUs(maskingWindowPositionMs); long positionUs = Util.msToUs(maskingWindowPositionMs);
playbackInfo = playbackInfo =
playbackInfo.copyWithNewPosition( playbackInfo.copyWithNewPosition(
dummyMediaPeriodId, dummyMediaPeriodId,
...@@ -1668,7 +1668,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1668,7 +1668,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
MediaPeriodId newPeriodId = MediaPeriodId newPeriodId =
playingPeriodChanged ? new MediaPeriodId(periodPosition.first) : playbackInfo.periodId; playingPeriodChanged ? new MediaPeriodId(periodPosition.first) : playbackInfo.periodId;
long newContentPositionUs = periodPosition.second; long newContentPositionUs = periodPosition.second;
long oldContentPositionUs = C.msToUs(getContentPosition()); long oldContentPositionUs = Util.msToUs(getContentPosition());
if (!oldTimeline.isEmpty()) { if (!oldTimeline.isEmpty()) {
oldContentPositionUs -= oldContentPositionUs -=
oldTimeline.getPeriodByUid(oldPeriodUid, period).getPositionInWindowUs(); oldTimeline.getPeriodByUid(oldPeriodUid, period).getPositionInWindowUs();
...@@ -1757,7 +1757,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1757,7 +1757,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Nullable @Nullable
Pair<Object, Long> oldPeriodPosition = Pair<Object, Long> oldPeriodPosition =
oldTimeline.getPeriodPosition( oldTimeline.getPeriodPosition(
window, period, currentWindowIndex, C.msToUs(currentPositionMs)); window, period, currentWindowIndex, Util.msToUs(currentPositionMs));
Object periodUid = castNonNull(oldPeriodPosition).first; Object periodUid = castNonNull(oldPeriodPosition).first;
if (newTimeline.getIndexOfPeriod(periodUid) != C.INDEX_UNSET) { if (newTimeline.getIndexOfPeriod(periodUid) != C.INDEX_UNSET) {
// The old period position is still available in the new timeline. // The old period position is still available in the new timeline.
...@@ -1798,7 +1798,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1798,7 +1798,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
windowIndex = timeline.getFirstWindowIndex(shuffleModeEnabled); windowIndex = timeline.getFirstWindowIndex(shuffleModeEnabled);
windowPositionMs = timeline.getWindow(windowIndex, window).getDefaultPositionMs(); windowPositionMs = timeline.getWindow(windowIndex, window).getDefaultPositionMs();
} }
return timeline.getPeriodPosition(window, period, windowIndex, C.msToUs(windowPositionMs)); return timeline.getPeriodPosition(window, period, windowIndex, Util.msToUs(windowPositionMs));
} }
private long periodPositionUsToWindowPositionUs( private long periodPositionUsToWindowPositionUs(
......
...@@ -1082,7 +1082,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -1082,7 +1082,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
if (window.windowStartTimeMs == C.TIME_UNSET || !window.isLive() || !window.isDynamic) { if (window.windowStartTimeMs == C.TIME_UNSET || !window.isLive() || !window.isDynamic) {
return C.TIME_UNSET; return C.TIME_UNSET;
} }
return C.msToUs(window.getCurrentUnixTimeMs() - window.windowStartTimeMs) return Util.msToUs(window.getCurrentUnixTimeMs() - window.windowStartTimeMs)
- (periodPositionUs + period.getPositionInWindowUs()); - (periodPositionUs + period.getPositionInWindowUs());
} }
...@@ -1184,7 +1184,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -1184,7 +1184,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
playingPeriodHolder.mediaPeriod.getAdjustedSeekPositionUs( playingPeriodHolder.mediaPeriod.getAdjustedSeekPositionUs(
newPeriodPositionUs, seekParameters); newPeriodPositionUs, seekParameters);
} }
if (C.usToMs(newPeriodPositionUs) == C.usToMs(playbackInfo.positionUs) if (Util.usToMs(newPeriodPositionUs) == Util.usToMs(playbackInfo.positionUs)
&& (playbackInfo.playbackState == Player.STATE_BUFFERING && (playbackInfo.playbackState == Player.STATE_BUFFERING
|| playbackInfo.playbackState == Player.STATE_READY)) { || playbackInfo.playbackState == Player.STATE_READY)) {
// Seek will be performed to the current position. Do nothing. // Seek will be performed to the current position. Do nothing.
...@@ -2710,7 +2710,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -2710,7 +2710,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
long requestPositionUs = long requestPositionUs =
pendingMessageInfo.message.getPositionMs() == C.TIME_END_OF_SOURCE pendingMessageInfo.message.getPositionMs() == C.TIME_END_OF_SOURCE
? C.TIME_UNSET ? C.TIME_UNSET
: C.msToUs(pendingMessageInfo.message.getPositionMs()); : Util.msToUs(pendingMessageInfo.message.getPositionMs());
@Nullable @Nullable
Pair<Object, Long> periodPosition = Pair<Object, Long> periodPosition =
resolveSeekPosition( resolveSeekPosition(
......
...@@ -455,7 +455,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -455,7 +455,7 @@ public class SimpleExoPlayer extends BasePlayer
if (Util.SDK_INT < 21) { if (Util.SDK_INT < 21) {
audioSessionId = initializeKeepSessionIdAudioTrack(C.AUDIO_SESSION_ID_UNSET); audioSessionId = initializeKeepSessionIdAudioTrack(C.AUDIO_SESSION_ID_UNSET);
} else { } else {
audioSessionId = C.generateAudioSessionIdV21(applicationContext); audioSessionId = Util.generateAudioSessionIdV21(applicationContext);
} }
currentCues = Collections.emptyList(); currentCues = Collections.emptyList();
throwsWhenUsingWrongThread = true; throwsWhenUsingWrongThread = true;
...@@ -770,7 +770,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -770,7 +770,7 @@ public class SimpleExoPlayer extends BasePlayer
if (Util.SDK_INT < 21) { if (Util.SDK_INT < 21) {
audioSessionId = initializeKeepSessionIdAudioTrack(C.AUDIO_SESSION_ID_UNSET); audioSessionId = initializeKeepSessionIdAudioTrack(C.AUDIO_SESSION_ID_UNSET);
} else { } else {
audioSessionId = C.generateAudioSessionIdV21(applicationContext); audioSessionId = Util.generateAudioSessionIdV21(applicationContext);
} }
} else if (Util.SDK_INT < 21) { } else if (Util.SDK_INT < 21) {
// We need to re-initialize keepSessionIdAudioTrack to make sure the session is kept alive for // We need to re-initialize keepSessionIdAudioTrack to make sure the session is kept alive for
......
...@@ -1157,7 +1157,7 @@ public class AnalyticsCollector ...@@ -1157,7 +1157,7 @@ public class AnalyticsCollector
: playerTimeline : playerTimeline
.getPeriod(playerPeriodIndex, period) .getPeriod(playerPeriodIndex, period)
.getAdGroupIndexAfterPositionUs( .getAdGroupIndexAfterPositionUs(
C.msToUs(player.getCurrentPosition()) - period.getPositionInWindowUs()); Util.msToUs(player.getCurrentPosition()) - period.getPositionInWindowUs());
for (int i = 0; i < mediaPeriodQueue.size(); i++) { for (int i = 0; i < mediaPeriodQueue.size(); i++) {
MediaPeriodId mediaPeriodId = mediaPeriodQueue.get(i); MediaPeriodId mediaPeriodId = mediaPeriodQueue.get(i);
if (isMatchingMediaPeriod( if (isMatchingMediaPeriod(
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.analytics; package com.google.android.exoplayer2.analytics;
import static com.google.android.exoplayer2.C.usToMs;
import static java.lang.Math.max; import static java.lang.Math.max;
import android.util.Base64; import android.util.Base64;
...@@ -141,7 +140,7 @@ public final class DefaultPlaybackSessionManager implements PlaybackSessionManag ...@@ -141,7 +140,7 @@ public final class DefaultPlaybackSessionManager implements PlaybackSessionManag
contentSession.isCreated = true; contentSession.isCreated = true;
eventTime.timeline.getPeriodByUid(eventTime.mediaPeriodId.periodUid, period); eventTime.timeline.getPeriodByUid(eventTime.mediaPeriodId.periodUid, period);
long adGroupPositionMs = long adGroupPositionMs =
usToMs(period.getAdGroupTimeUs(eventTime.mediaPeriodId.adGroupIndex)) Util.usToMs(period.getAdGroupTimeUs(eventTime.mediaPeriodId.adGroupIndex))
+ period.getPositionInWindowMs(); + period.getPositionInWindowMs();
// getAdGroupTimeUs may return 0 for prerolls despite period offset. // getAdGroupTimeUs may return 0 for prerolls despite period offset.
adGroupPositionMs = max(0, adGroupPositionMs); adGroupPositionMs = max(0, adGroupPositionMs);
......
...@@ -333,7 +333,7 @@ public final class PlaybackStatsListener ...@@ -333,7 +333,7 @@ public final class PlaybackStatsListener
eventTime.mediaPeriodId.periodUid, eventTime.mediaPeriodId.periodUid,
eventTime.mediaPeriodId.windowSequenceNumber, eventTime.mediaPeriodId.windowSequenceNumber,
eventTime.mediaPeriodId.adGroupIndex), eventTime.mediaPeriodId.adGroupIndex),
/* eventPlaybackPositionMs= */ C.usToMs(contentWindowPositionUs), /* eventPlaybackPositionMs= */ Util.usToMs(contentWindowPositionUs),
eventTime.timeline, eventTime.timeline,
eventTime.currentWindowIndex, eventTime.currentWindowIndex,
eventTime.currentMediaPeriodId, eventTime.currentMediaPeriodId,
......
...@@ -302,12 +302,12 @@ import java.lang.reflect.Method; ...@@ -302,12 +302,12 @@ import java.lang.reflect.Method;
if (!notifiedPositionIncreasing && positionUs > lastPositionUs) { if (!notifiedPositionIncreasing && positionUs > lastPositionUs) {
notifiedPositionIncreasing = true; notifiedPositionIncreasing = true;
long mediaDurationSinceLastPositionUs = C.usToMs(positionUs - lastPositionUs); long mediaDurationSinceLastPositionUs = Util.usToMs(positionUs - lastPositionUs);
long playoutDurationSinceLastPositionUs = long playoutDurationSinceLastPositionUs =
Util.getPlayoutDurationForMediaDuration( Util.getPlayoutDurationForMediaDuration(
mediaDurationSinceLastPositionUs, audioTrackPlaybackSpeed); mediaDurationSinceLastPositionUs, audioTrackPlaybackSpeed);
long playoutStartSystemTimeMs = long playoutStartSystemTimeMs =
System.currentTimeMillis() - C.usToMs(playoutDurationSinceLastPositionUs); System.currentTimeMillis() - Util.usToMs(playoutDurationSinceLastPositionUs);
listener.onPositionAdvancing(playoutStartSystemTimeMs); listener.onPositionAdvancing(playoutStartSystemTimeMs);
} }
...@@ -357,7 +357,7 @@ import java.lang.reflect.Method; ...@@ -357,7 +357,7 @@ import java.lang.reflect.Method;
boolean hadData = hasData; boolean hadData = hasData;
hasData = hasPendingData(writtenFrames); hasData = hasPendingData(writtenFrames);
if (hadData && !hasData && playState != PLAYSTATE_STOPPED) { if (hadData && !hasData && playState != PLAYSTATE_STOPPED) {
listener.onUnderrun(bufferSize, C.usToMs(bufferSizeUs)); listener.onUnderrun(bufferSize, Util.usToMs(bufferSizeUs));
} }
return true; return true;
...@@ -379,7 +379,7 @@ import java.lang.reflect.Method; ...@@ -379,7 +379,7 @@ import java.lang.reflect.Method;
/** Returns the duration of audio that is buffered but unplayed. */ /** Returns the duration of audio that is buffered but unplayed. */
public long getPendingBufferDurationMs(long writtenFrames) { public long getPendingBufferDurationMs(long writtenFrames) {
return C.usToMs(framesToDurationUs(writtenFrames - getPlaybackHeadPosition())); return Util.usToMs(framesToDurationUs(writtenFrames - getPlaybackHeadPosition()));
} }
/** Returns whether the track is in an invalid state and must be recreated. */ /** Returns whether the track is in an invalid state and must be recreated. */
......
...@@ -23,7 +23,6 @@ import androidx.annotation.DoNotInline; ...@@ -23,7 +23,6 @@ import androidx.annotation.DoNotInline;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
...@@ -122,7 +121,7 @@ public final class DrmUtil { ...@@ -122,7 +121,7 @@ public final class DrmUtil {
@Nullable @Nullable
String diagnosticsInfo = ((MediaDrm.MediaDrmStateException) throwable).getDiagnosticInfo(); String diagnosticsInfo = ((MediaDrm.MediaDrmStateException) throwable).getDiagnosticInfo();
int drmErrorCode = Util.getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo); int drmErrorCode = Util.getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo);
return C.getErrorCodeForMediaDrmErrorCode(drmErrorCode); return Util.getErrorCodeForMediaDrmErrorCode(drmErrorCode);
} }
} }
......
...@@ -1240,7 +1240,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1240,7 +1240,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
} catch (CryptoException e) { } catch (CryptoException e) {
throw createRendererException( throw createRendererException(
e, inputFormat, C.getErrorCodeForMediaDrmErrorCode(e.getErrorCode())); e, inputFormat, Util.getErrorCodeForMediaDrmErrorCode(e.getErrorCode()));
} }
return false; return false;
} }
...@@ -1312,7 +1312,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1312,7 +1312,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
} catch (CryptoException e) { } catch (CryptoException e) {
throw createRendererException( throw createRendererException(
e, inputFormat, C.getErrorCodeForMediaDrmErrorCode(e.getErrorCode())); e, inputFormat, Util.getErrorCodeForMediaDrmErrorCode(e.getErrorCode()));
} }
resetInputBuffer(); resetInputBuffer();
......
...@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.Timeline; ...@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -338,7 +339,7 @@ public final class ClippingMediaSource extends CompositeMediaSource<Void> { ...@@ -338,7 +339,7 @@ public final class ClippingMediaSource extends CompositeMediaSource<Void> {
endUs == C.TIME_UNSET ? window.defaultPositionUs : min(window.defaultPositionUs, endUs); endUs == C.TIME_UNSET ? window.defaultPositionUs : min(window.defaultPositionUs, endUs);
window.defaultPositionUs -= startUs; window.defaultPositionUs -= startUs;
} }
long startMs = C.usToMs(startUs); long startMs = Util.usToMs(startUs);
if (window.presentationStartTimeMs != C.TIME_UNSET) { if (window.presentationStartTimeMs != C.TIME_UNSET) {
window.presentationStartTimeMs += startMs; window.presentationStartTimeMs += startMs;
} }
......
...@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.Format; ...@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
...@@ -472,7 +473,7 @@ public interface MediaSourceEventListener { ...@@ -472,7 +473,7 @@ public interface MediaSourceEventListener {
} }
private long adjustMediaTime(long mediaTimeUs) { private long adjustMediaTime(long mediaTimeUs) {
long mediaTimeMs = C.usToMs(mediaTimeUs); long mediaTimeMs = Util.usToMs(mediaTimeUs);
return mediaTimeMs == C.TIME_UNSET ? C.TIME_UNSET : mediaTimeOffsetMs + mediaTimeMs; return mediaTimeMs == C.TIME_UNSET ? C.TIME_UNSET : mediaTimeOffsetMs + mediaTimeMs;
} }
......
...@@ -641,8 +641,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -641,8 +641,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/* trackFormat= */ null, /* trackFormat= */ null,
C.SELECTION_REASON_UNKNOWN, C.SELECTION_REASON_UNKNOWN,
/* trackSelectionData= */ null, /* trackSelectionData= */ null,
/* mediaStartTimeMs= */ C.usToMs(loadable.seekTimeUs), /* mediaStartTimeMs= */ Util.usToMs(loadable.seekTimeUs),
C.usToMs(durationUs)); Util.usToMs(durationUs));
LoadErrorAction loadErrorAction; LoadErrorAction loadErrorAction;
long retryDelayMs = long retryDelayMs =
loadErrorHandlingPolicy.getRetryDelayMsFor( loadErrorHandlingPolicy.getRetryDelayMsFor(
......
...@@ -36,6 +36,7 @@ import com.google.android.exoplayer2.upstream.TransferListener; ...@@ -36,6 +36,7 @@ import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -282,7 +283,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -282,7 +283,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
C.SELECTION_REASON_UNKNOWN, C.SELECTION_REASON_UNKNOWN,
/* trackSelectionData= */ null, /* trackSelectionData= */ null,
/* mediaStartTimeMs= */ 0, /* mediaStartTimeMs= */ 0,
C.usToMs(durationUs)); Util.usToMs(durationUs));
long retryDelay = long retryDelay =
loadErrorHandlingPolicy.getRetryDelayMsFor( loadErrorHandlingPolicy.getRetryDelayMsFor(
new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount)); new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount));
......
...@@ -512,7 +512,7 @@ public final class ServerSideInsertedAdsMediaSource extends BaseMediaSource ...@@ -512,7 +512,7 @@ public final class ServerSideInsertedAdsMediaSource extends BaseMediaSource
if (mediaPositionMs == C.TIME_UNSET) { if (mediaPositionMs == C.TIME_UNSET) {
return C.TIME_UNSET; return C.TIME_UNSET;
} }
long mediaPositionUs = C.msToUs(mediaPositionMs); long mediaPositionUs = Util.msToUs(mediaPositionMs);
MediaPeriodId id = mediaPeriod.mediaPeriodId; MediaPeriodId id = mediaPeriod.mediaPeriodId;
long correctedPositionUs = long correctedPositionUs =
id.isAd() id.isAd()
...@@ -522,7 +522,7 @@ public final class ServerSideInsertedAdsMediaSource extends BaseMediaSource ...@@ -522,7 +522,7 @@ public final class ServerSideInsertedAdsMediaSource extends BaseMediaSource
// content pieces (beyond nextAdGroupIndex). // content pieces (beyond nextAdGroupIndex).
: getMediaPeriodPositionUsForContent( : getMediaPeriodPositionUsForContent(
mediaPositionUs, /* nextAdGroupIndex= */ C.INDEX_UNSET, adPlaybackState); mediaPositionUs, /* nextAdGroupIndex= */ C.INDEX_UNSET, adPlaybackState);
return C.usToMs(correctedPositionUs); return Util.usToMs(correctedPositionUs);
} }
private static final class SharedMediaPeriod implements MediaPeriod.Callback { private static final class SharedMediaPeriod implements MediaPeriod.Callback {
...@@ -591,7 +591,7 @@ public final class ServerSideInsertedAdsMediaSource extends BaseMediaSource ...@@ -591,7 +591,7 @@ public final class ServerSideInsertedAdsMediaSource extends BaseMediaSource
MediaPeriodImpl mediaPeriod = mediaPeriods.get(i); MediaPeriodImpl mediaPeriod = mediaPeriods.get(i);
long startTimeInPeriodUs = long startTimeInPeriodUs =
getMediaPeriodPositionUs( getMediaPeriodPositionUs(
C.msToUs(mediaLoadData.mediaStartTimeMs), Util.msToUs(mediaLoadData.mediaStartTimeMs),
mediaPeriod.mediaPeriodId, mediaPeriod.mediaPeriodId,
adPlaybackState); adPlaybackState);
long mediaPeriodEndPositionUs = getMediaPeriodEndPositionUs(mediaPeriod, adPlaybackState); long mediaPeriodEndPositionUs = getMediaPeriodEndPositionUs(mediaPeriod, adPlaybackState);
......
...@@ -124,11 +124,12 @@ public final class ServerSideInsertedAdsUtil { ...@@ -124,11 +124,12 @@ public final class ServerSideInsertedAdsUtil {
if (player.isPlayingAd()) { if (player.isPlayingAd()) {
int adGroupIndex = player.getCurrentAdGroupIndex(); int adGroupIndex = player.getCurrentAdGroupIndex();
int adIndexInAdGroup = player.getCurrentAdIndexInAdGroup(); int adIndexInAdGroup = player.getCurrentAdIndexInAdGroup();
long adPositionUs = C.msToUs(player.getCurrentPosition()); long adPositionUs = Util.msToUs(player.getCurrentPosition());
return getStreamPositionUsForAd( return getStreamPositionUsForAd(
adPositionUs, adGroupIndex, adIndexInAdGroup, adPlaybackState); adPositionUs, adGroupIndex, adIndexInAdGroup, adPlaybackState);
} }
long periodPositionUs = C.msToUs(player.getCurrentPosition()) - period.getPositionInWindowUs(); long periodPositionUs =
Util.msToUs(player.getCurrentPosition()) - period.getPositionInWindowUs();
return getStreamPositionUsForContent( return getStreamPositionUsForContent(
periodPositionUs, /* nextAdGroupIndex= */ C.INDEX_UNSET, adPlaybackState); periodPositionUs, /* nextAdGroupIndex= */ C.INDEX_UNSET, adPlaybackState);
} }
......
...@@ -510,8 +510,8 @@ public class ChunkSampleStream<T extends ChunkSource> ...@@ -510,8 +510,8 @@ public class ChunkSampleStream<T extends ChunkSource>
loadable.trackFormat, loadable.trackFormat,
loadable.trackSelectionReason, loadable.trackSelectionReason,
loadable.trackSelectionData, loadable.trackSelectionData,
C.usToMs(loadable.startTimeUs), Util.usToMs(loadable.startTimeUs),
C.usToMs(loadable.endTimeUs)); Util.usToMs(loadable.endTimeUs));
LoadErrorInfo loadErrorInfo = LoadErrorInfo loadErrorInfo =
new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount); new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
......
...@@ -277,7 +277,7 @@ public class EventLogger implements AnalyticsListener { ...@@ -277,7 +277,7 @@ public class EventLogger implements AnalyticsListener {
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
String status = getTrackStatusString(trackSelection, trackGroup, trackIndex); String status = getTrackStatusString(trackSelection, trackGroup, trackIndex);
String formatSupport = String formatSupport =
C.getFormatSupportString( Util.getFormatSupportString(
mappedTrackInfo.getTrackSupport(rendererIndex, groupIndex, trackIndex)); mappedTrackInfo.getTrackSupport(rendererIndex, groupIndex, trackIndex));
logd( logd(
" " " "
...@@ -315,7 +315,7 @@ public class EventLogger implements AnalyticsListener { ...@@ -315,7 +315,7 @@ public class EventLogger implements AnalyticsListener {
TrackGroup trackGroup = unassociatedTrackGroups.get(groupIndex); TrackGroup trackGroup = unassociatedTrackGroups.get(groupIndex);
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) { for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
String status = getTrackStatusString(false); String status = getTrackStatusString(false);
String formatSupport = C.getFormatSupportString(C.FORMAT_UNSUPPORTED_TYPE); String formatSupport = Util.getFormatSupportString(C.FORMAT_UNSUPPORTED_TYPE);
logd( logd(
" " " "
+ status + status
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.util; package com.google.android.exoplayer2.util;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
/** /**
...@@ -75,7 +74,7 @@ public final class StandaloneMediaClock implements MediaClock { ...@@ -75,7 +74,7 @@ public final class StandaloneMediaClock implements MediaClock {
if (started) { if (started) {
long elapsedSinceBaseMs = clock.elapsedRealtime() - baseElapsedMs; long elapsedSinceBaseMs = clock.elapsedRealtime() - baseElapsedMs;
if (playbackParameters.speed == 1f) { if (playbackParameters.speed == 1f) {
positionUs += C.msToUs(elapsedSinceBaseMs); positionUs += Util.msToUs(elapsedSinceBaseMs);
} else { } else {
// Add the media time in microseconds that will elapse in elapsedSinceBaseMs milliseconds of // Add the media time in microseconds that will elapse in elapsedSinceBaseMs milliseconds of
// wallclock time // wallclock time
......
...@@ -50,6 +50,7 @@ import com.google.android.exoplayer2.util.Assertions; ...@@ -50,6 +50,7 @@ import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.TimedValueQueue; import com.google.android.exoplayer2.util.TimedValueQueue;
import com.google.android.exoplayer2.util.TraceUtil; import com.google.android.exoplayer2.util.TraceUtil;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener.EventDispatcher; import com.google.android.exoplayer2.video.VideoRendererEventListener.EventDispatcher;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -558,7 +559,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer { ...@@ -558,7 +559,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer {
frameMetadataListener.onVideoFrameAboutToBeRendered( frameMetadataListener.onVideoFrameAboutToBeRendered(
presentationTimeUs, System.nanoTime(), outputFormat, /* mediaFormat= */ null); presentationTimeUs, System.nanoTime(), outputFormat, /* mediaFormat= */ null);
} }
lastRenderTimeUs = C.msToUs(SystemClock.elapsedRealtime() * 1000); lastRenderTimeUs = Util.msToUs(SystemClock.elapsedRealtime() * 1000);
int bufferMode = outputBuffer.mode; int bufferMode = outputBuffer.mode;
boolean renderSurface = bufferMode == C.VIDEO_OUTPUT_MODE_SURFACE_YUV && outputSurface != null; boolean renderSurface = bufferMode == C.VIDEO_OUTPUT_MODE_SURFACE_YUV && outputSurface != null;
boolean renderYuv = bufferMode == C.VIDEO_OUTPUT_MODE_YUV && outputBufferRenderer != null; boolean renderYuv = bufferMode == C.VIDEO_OUTPUT_MODE_YUV && outputBufferRenderer != null;
......
...@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.DefaultLoadControl.Builder; ...@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.DefaultLoadControl.Builder;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.ExoTrackSelection; import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
import com.google.android.exoplayer2.upstream.DefaultAllocator; import com.google.android.exoplayer2.upstream.DefaultAllocator;
import com.google.android.exoplayer2.util.Util;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -31,7 +32,7 @@ import org.junit.runner.RunWith; ...@@ -31,7 +32,7 @@ import org.junit.runner.RunWith;
public class DefaultLoadControlTest { public class DefaultLoadControlTest {
private static final float SPEED = 1f; private static final float SPEED = 1f;
private static final long MAX_BUFFER_US = C.msToUs(DefaultLoadControl.DEFAULT_MAX_BUFFER_MS); private static final long MAX_BUFFER_US = Util.msToUs(DefaultLoadControl.DEFAULT_MAX_BUFFER_MS);
private static final long MIN_BUFFER_US = MAX_BUFFER_US / 2; private static final long MIN_BUFFER_US = MAX_BUFFER_US / 2;
private static final int TARGET_BUFFER_BYTES = C.DEFAULT_BUFFER_SEGMENT_SIZE * 2; private static final int TARGET_BUFFER_BYTES = C.DEFAULT_BUFFER_SEGMENT_SIZE * 2;
...@@ -64,8 +65,8 @@ public class DefaultLoadControlTest { ...@@ -64,8 +65,8 @@ public class DefaultLoadControlTest {
@Test @Test
public void shouldNotContinueLoadingOnceBufferingStopped_untilBelowMinBuffer() { public void shouldNotContinueLoadingOnceBufferingStopped_untilBelowMinBuffer() {
builder.setBufferDurationsMs( builder.setBufferDurationsMs(
/* minBufferMs= */ (int) C.usToMs(MIN_BUFFER_US), /* minBufferMs= */ (int) Util.usToMs(MIN_BUFFER_US),
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US), /* maxBufferMs= */ (int) Util.usToMs(MAX_BUFFER_US),
/* bufferForPlaybackMs= */ 0, /* bufferForPlaybackMs= */ 0,
/* bufferForPlaybackAfterRebufferMs= */ 0); /* bufferForPlaybackAfterRebufferMs= */ 0);
build(); build();
...@@ -88,7 +89,7 @@ public class DefaultLoadControlTest { ...@@ -88,7 +89,7 @@ public class DefaultLoadControlTest {
public void continueLoadingOnceBufferingStopped_andBufferAlmostEmpty_evenIfMinBufferNotReached() { public void continueLoadingOnceBufferingStopped_andBufferAlmostEmpty_evenIfMinBufferNotReached() {
builder.setBufferDurationsMs( builder.setBufferDurationsMs(
/* minBufferMs= */ 0, /* minBufferMs= */ 0,
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US), /* maxBufferMs= */ (int) Util.usToMs(MAX_BUFFER_US),
/* bufferForPlaybackMs= */ 0, /* bufferForPlaybackMs= */ 0,
/* bufferForPlaybackAfterRebufferMs= */ 0); /* bufferForPlaybackAfterRebufferMs= */ 0);
build(); build();
...@@ -107,8 +108,8 @@ public class DefaultLoadControlTest { ...@@ -107,8 +108,8 @@ public class DefaultLoadControlTest {
public void shouldContinueLoadingWithTargetBufferBytesReached_untilMinBufferReached() { public void shouldContinueLoadingWithTargetBufferBytesReached_untilMinBufferReached() {
builder.setPrioritizeTimeOverSizeThresholds(true); builder.setPrioritizeTimeOverSizeThresholds(true);
builder.setBufferDurationsMs( builder.setBufferDurationsMs(
/* minBufferMs= */ (int) C.usToMs(MIN_BUFFER_US), /* minBufferMs= */ (int) Util.usToMs(MIN_BUFFER_US),
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US), /* maxBufferMs= */ (int) Util.usToMs(MAX_BUFFER_US),
/* bufferForPlaybackMs= */ 0, /* bufferForPlaybackMs= */ 0,
/* bufferForPlaybackAfterRebufferMs= */ 0); /* bufferForPlaybackAfterRebufferMs= */ 0);
build(); build();
...@@ -158,8 +159,8 @@ public class DefaultLoadControlTest { ...@@ -158,8 +159,8 @@ public class DefaultLoadControlTest {
@Test @Test
public void shouldContinueLoadingWithMinBufferReached_inFastPlayback() { public void shouldContinueLoadingWithMinBufferReached_inFastPlayback() {
builder.setBufferDurationsMs( builder.setBufferDurationsMs(
/* minBufferMs= */ (int) C.usToMs(MIN_BUFFER_US), /* minBufferMs= */ (int) Util.usToMs(MIN_BUFFER_US),
/* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US), /* maxBufferMs= */ (int) Util.usToMs(MAX_BUFFER_US),
/* bufferForPlaybackMs= */ 0, /* bufferForPlaybackMs= */ 0,
/* bufferForPlaybackAfterRebufferMs= */ 0); /* bufferForPlaybackAfterRebufferMs= */ 0);
build(); build();
......
...@@ -25,6 +25,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; ...@@ -25,6 +25,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.DefaultMediaClock.PlaybackParametersListener; import com.google.android.exoplayer2.DefaultMediaClock.PlaybackParametersListener;
import com.google.android.exoplayer2.testutil.FakeClock; import com.google.android.exoplayer2.testutil.FakeClock;
import com.google.android.exoplayer2.testutil.FakeMediaClockRenderer; import com.google.android.exoplayer2.testutil.FakeMediaClockRenderer;
import com.google.android.exoplayer2.util.Util;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -263,7 +264,7 @@ public class DefaultMediaClockTest { ...@@ -263,7 +264,7 @@ public class DefaultMediaClockTest {
mediaClock.onRendererDisabled(mediaClockRenderer); mediaClock.onRendererDisabled(mediaClockRenderer);
fakeClock.advanceTime(SLEEP_TIME_MS); fakeClock.advanceTime(SLEEP_TIME_MS);
assertThat(mediaClock.syncAndGetPositionUs(/* isReadingAhead= */ false)) assertThat(mediaClock.syncAndGetPositionUs(/* isReadingAhead= */ false))
.isEqualTo(TEST_POSITION_US + C.msToUs(SLEEP_TIME_MS)); .isEqualTo(TEST_POSITION_US + Util.msToUs(SLEEP_TIME_MS));
assertClockIsRunning(/* isReadingAhead= */ false); assertClockIsRunning(/* isReadingAhead= */ false);
} }
...@@ -329,7 +330,7 @@ public class DefaultMediaClockTest { ...@@ -329,7 +330,7 @@ public class DefaultMediaClockTest {
mediaClockRenderer.positionUs = TEST_POSITION_US; mediaClockRenderer.positionUs = TEST_POSITION_US;
mediaClock.onRendererDisabled(mediaClockRenderer); mediaClock.onRendererDisabled(mediaClockRenderer);
assertThat(mediaClock.syncAndGetPositionUs(/* isReadingAhead= */ false)) assertThat(mediaClock.syncAndGetPositionUs(/* isReadingAhead= */ false))
.isEqualTo(C.msToUs(fakeClock.elapsedRealtime())); .isEqualTo(Util.msToUs(fakeClock.elapsedRealtime()));
} }
@Test @Test
......
...@@ -907,7 +907,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -907,7 +907,7 @@ public final class DashMediaSource extends BaseMediaSource {
int lastPeriodIndex = manifest.getPeriodCount() - 1; int lastPeriodIndex = manifest.getPeriodCount() - 1;
Period lastPeriod = manifest.getPeriod(lastPeriodIndex); Period lastPeriod = manifest.getPeriod(lastPeriodIndex);
long lastPeriodDurationUs = manifest.getPeriodDurationUs(lastPeriodIndex); long lastPeriodDurationUs = manifest.getPeriodDurationUs(lastPeriodIndex);
long nowUnixTimeUs = C.msToUs(Util.getNowUnixTimeMs(elapsedRealtimeOffsetMs)); long nowUnixTimeUs = Util.msToUs(Util.getNowUnixTimeMs(elapsedRealtimeOffsetMs));
long windowStartTimeInManifestUs = long windowStartTimeInManifestUs =
getAvailableStartTimeInManifestUs( getAvailableStartTimeInManifestUs(
firstPeriod, manifest.getPeriodDurationUs(0), nowUnixTimeUs); firstPeriod, manifest.getPeriodDurationUs(0), nowUnixTimeUs);
...@@ -917,7 +917,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -917,7 +917,7 @@ public final class DashMediaSource extends BaseMediaSource {
if (windowChangingImplicitly && manifest.timeShiftBufferDepthMs != C.TIME_UNSET) { if (windowChangingImplicitly && manifest.timeShiftBufferDepthMs != C.TIME_UNSET) {
// Update the available start time to reflect the manifest's time shift buffer depth. // Update the available start time to reflect the manifest's time shift buffer depth.
long timeShiftBufferStartTimeInManifestUs = long timeShiftBufferStartTimeInManifestUs =
windowEndTimeInManifestUs - C.msToUs(manifest.timeShiftBufferDepthMs); windowEndTimeInManifestUs - Util.msToUs(manifest.timeShiftBufferDepthMs);
windowStartTimeInManifestUs = windowStartTimeInManifestUs =
max(windowStartTimeInManifestUs, timeShiftBufferStartTimeInManifestUs); max(windowStartTimeInManifestUs, timeShiftBufferStartTimeInManifestUs);
} }
...@@ -927,11 +927,13 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -927,11 +927,13 @@ public final class DashMediaSource extends BaseMediaSource {
if (manifest.dynamic) { if (manifest.dynamic) {
checkState(manifest.availabilityStartTimeMs != C.TIME_UNSET); checkState(manifest.availabilityStartTimeMs != C.TIME_UNSET);
long nowInWindowUs = long nowInWindowUs =
nowUnixTimeUs - C.msToUs(manifest.availabilityStartTimeMs) - windowStartTimeInManifestUs; nowUnixTimeUs
- Util.msToUs(manifest.availabilityStartTimeMs)
- windowStartTimeInManifestUs;
updateMediaItemLiveConfiguration(nowInWindowUs, windowDurationUs); updateMediaItemLiveConfiguration(nowInWindowUs, windowDurationUs);
windowStartUnixTimeMs = windowStartUnixTimeMs =
manifest.availabilityStartTimeMs + C.usToMs(windowStartTimeInManifestUs); manifest.availabilityStartTimeMs + Util.usToMs(windowStartTimeInManifestUs);
windowDefaultPositionUs = nowInWindowUs - C.msToUs(liveConfiguration.targetOffsetMs); windowDefaultPositionUs = nowInWindowUs - Util.msToUs(liveConfiguration.targetOffsetMs);
long minimumWindowDefaultPositionUs = long minimumWindowDefaultPositionUs =
min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2); min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2);
if (windowDefaultPositionUs < minimumWindowDefaultPositionUs) { if (windowDefaultPositionUs < minimumWindowDefaultPositionUs) {
...@@ -941,7 +943,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -941,7 +943,7 @@ public final class DashMediaSource extends BaseMediaSource {
windowDefaultPositionUs = minimumWindowDefaultPositionUs; windowDefaultPositionUs = minimumWindowDefaultPositionUs;
} }
} }
long offsetInFirstPeriodUs = windowStartTimeInManifestUs - C.msToUs(firstPeriod.startMs); long offsetInFirstPeriodUs = windowStartTimeInManifestUs - Util.msToUs(firstPeriod.startMs);
DashTimeline timeline = DashTimeline timeline =
new DashTimeline( new DashTimeline(
manifest.availabilityStartTimeMs, manifest.availabilityStartTimeMs,
...@@ -995,7 +997,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -995,7 +997,7 @@ public final class DashMediaSource extends BaseMediaSource {
&& manifest.serviceDescription.maxOffsetMs != C.TIME_UNSET) { && manifest.serviceDescription.maxOffsetMs != C.TIME_UNSET) {
maxLiveOffsetMs = manifest.serviceDescription.maxOffsetMs; maxLiveOffsetMs = manifest.serviceDescription.maxOffsetMs;
} else { } else {
maxLiveOffsetMs = C.usToMs(nowInWindowUs); maxLiveOffsetMs = Util.usToMs(nowInWindowUs);
} }
long minLiveOffsetMs; long minLiveOffsetMs;
if (mediaItem.liveConfiguration.minOffsetMs != C.TIME_UNSET) { if (mediaItem.liveConfiguration.minOffsetMs != C.TIME_UNSET) {
...@@ -1004,7 +1006,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -1004,7 +1006,7 @@ public final class DashMediaSource extends BaseMediaSource {
&& manifest.serviceDescription.minOffsetMs != C.TIME_UNSET) { && manifest.serviceDescription.minOffsetMs != C.TIME_UNSET) {
minLiveOffsetMs = manifest.serviceDescription.minOffsetMs; minLiveOffsetMs = manifest.serviceDescription.minOffsetMs;
} else { } else {
minLiveOffsetMs = C.usToMs(nowInWindowUs - windowDurationUs); minLiveOffsetMs = Util.usToMs(nowInWindowUs - windowDurationUs);
if (minLiveOffsetMs < 0 && maxLiveOffsetMs > 0) { if (minLiveOffsetMs < 0 && maxLiveOffsetMs > 0) {
// The current time is in the window, so assume all clocks are synchronized and set the // The current time is in the window, so assume all clocks are synchronized and set the
// minimum to a live offset of zero. // minimum to a live offset of zero.
...@@ -1033,7 +1035,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -1033,7 +1035,7 @@ public final class DashMediaSource extends BaseMediaSource {
long safeDistanceFromWindowStartUs = long safeDistanceFromWindowStartUs =
min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2); min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2);
long maxTargetOffsetForSafeDistanceToWindowStartMs = long maxTargetOffsetForSafeDistanceToWindowStartMs =
C.usToMs(nowInWindowUs - safeDistanceFromWindowStartUs); Util.usToMs(nowInWindowUs - safeDistanceFromWindowStartUs);
targetOffsetMs = targetOffsetMs =
Util.constrainValue( Util.constrainValue(
maxTargetOffsetForSafeDistanceToWindowStartMs, minLiveOffsetMs, maxLiveOffsetMs); maxTargetOffsetForSafeDistanceToWindowStartMs, minLiveOffsetMs, maxLiveOffsetMs);
...@@ -1097,11 +1099,11 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -1097,11 +1099,11 @@ public final class DashMediaSource extends BaseMediaSource {
DashManifest manifest, long nowUnixTimeMs) { DashManifest manifest, long nowUnixTimeMs) {
int periodIndex = manifest.getPeriodCount() - 1; int periodIndex = manifest.getPeriodCount() - 1;
Period period = manifest.getPeriod(periodIndex); Period period = manifest.getPeriod(periodIndex);
long periodStartUs = C.msToUs(period.startMs); long periodStartUs = Util.msToUs(period.startMs);
long periodDurationUs = manifest.getPeriodDurationUs(periodIndex); long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
long nowUnixTimeUs = C.msToUs(nowUnixTimeMs); long nowUnixTimeUs = Util.msToUs(nowUnixTimeMs);
long availabilityStartTimeUs = C.msToUs(manifest.availabilityStartTimeMs); long availabilityStartTimeUs = Util.msToUs(manifest.availabilityStartTimeMs);
long intervalUs = C.msToUs(DEFAULT_NOTIFY_MANIFEST_INTERVAL_MS); long intervalUs = Util.msToUs(DEFAULT_NOTIFY_MANIFEST_INTERVAL_MS);
for (int i = 0; i < period.adaptationSets.size(); i++) { for (int i = 0; i < period.adaptationSets.size(); i++) {
List<Representation> representations = period.adaptationSets.get(i).representations; List<Representation> representations = period.adaptationSets.get(i).representations;
if (representations.isEmpty()) { if (representations.isEmpty()) {
...@@ -1127,7 +1129,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -1127,7 +1129,7 @@ public final class DashMediaSource extends BaseMediaSource {
private static long getAvailableStartTimeInManifestUs( private static long getAvailableStartTimeInManifestUs(
Period period, long periodDurationUs, long nowUnixTimeUs) { Period period, long periodDurationUs, long nowUnixTimeUs) {
long periodStartTimeInManifestUs = C.msToUs(period.startMs); long periodStartTimeInManifestUs = Util.msToUs(period.startMs);
long availableStartTimeInManifestUs = periodStartTimeInManifestUs; long availableStartTimeInManifestUs = periodStartTimeInManifestUs;
boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period); boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period);
for (int i = 0; i < period.adaptationSets.size(); i++) { for (int i = 0; i < period.adaptationSets.size(); i++) {
...@@ -1159,7 +1161,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -1159,7 +1161,7 @@ public final class DashMediaSource extends BaseMediaSource {
private static long getAvailableEndTimeInManifestUs( private static long getAvailableEndTimeInManifestUs(
Period period, long periodDurationUs, long nowUnixTimeUs) { Period period, long periodDurationUs, long nowUnixTimeUs) {
long periodStartTimeInManifestUs = C.msToUs(period.startMs); long periodStartTimeInManifestUs = Util.msToUs(period.startMs);
long availableEndTimeInManifestUs = Long.MAX_VALUE; long availableEndTimeInManifestUs = Long.MAX_VALUE;
boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period); boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period);
for (int i = 0; i < period.adaptationSets.size(); i++) { for (int i = 0; i < period.adaptationSets.size(); i++) {
...@@ -1266,7 +1268,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -1266,7 +1268,7 @@ public final class DashMediaSource extends BaseMediaSource {
uid, uid,
0, 0,
manifest.getPeriodDurationUs(periodIndex), manifest.getPeriodDurationUs(periodIndex),
C.msToUs(manifest.getPeriod(periodIndex).startMs - manifest.getPeriod(0).startMs) Util.msToUs(manifest.getPeriod(periodIndex).startMs - manifest.getPeriod(0).startMs)
- offsetInFirstPeriodUs); - offsetInFirstPeriodUs);
} }
......
...@@ -305,8 +305,8 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -305,8 +305,8 @@ public class DefaultDashChunkSource implements DashChunkSource {
long bufferedDurationUs = loadPositionUs - playbackPositionUs; long bufferedDurationUs = loadPositionUs - playbackPositionUs;
long presentationPositionUs = long presentationPositionUs =
C.msToUs(manifest.availabilityStartTimeMs) Util.msToUs(manifest.availabilityStartTimeMs)
+ C.msToUs(manifest.getPeriod(periodIndex).startMs) + Util.msToUs(manifest.getPeriod(periodIndex).startMs)
+ loadPositionUs; + loadPositionUs;
if (playerTrackEmsgHandler != null if (playerTrackEmsgHandler != null
...@@ -315,7 +315,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -315,7 +315,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
return; return;
} }
long nowUnixTimeUs = C.msToUs(Util.getNowUnixTimeMs(elapsedRealtimeOffsetMs)); long nowUnixTimeUs = Util.msToUs(Util.getNowUnixTimeMs(elapsedRealtimeOffsetMs));
long nowPeriodTimeUs = getNowPeriodTimeUs(nowUnixTimeUs); long nowPeriodTimeUs = getNowPeriodTimeUs(nowUnixTimeUs);
MediaChunk previous = queue.isEmpty() ? null : queue.get(queue.size() - 1); MediaChunk previous = queue.isEmpty() ? null : queue.get(queue.size() - 1);
MediaChunkIterator[] chunkIterators = new MediaChunkIterator[trackSelection.length()]; MediaChunkIterator[] chunkIterators = new MediaChunkIterator[trackSelection.length()];
...@@ -600,7 +600,8 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -600,7 +600,8 @@ public class DefaultDashChunkSource implements DashChunkSource {
return manifest.availabilityStartTimeMs == C.TIME_UNSET return manifest.availabilityStartTimeMs == C.TIME_UNSET
? C.TIME_UNSET ? C.TIME_UNSET
: nowUnixTimeUs : nowUnixTimeUs
- C.msToUs(manifest.availabilityStartTimeMs + manifest.getPeriod(periodIndex).startMs); - Util.msToUs(
manifest.availabilityStartTimeMs + manifest.getPeriod(periodIndex).startMs);
} }
protected Chunk newInitializationChunk( protected Chunk newInitializationChunk(
......
...@@ -20,6 +20,7 @@ import androidx.annotation.Nullable; ...@@ -20,6 +20,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.offline.FilterableManifest; import com.google.android.exoplayer2.offline.FilterableManifest;
import com.google.android.exoplayer2.offline.StreamKey; import com.google.android.exoplayer2.offline.StreamKey;
import com.google.android.exoplayer2.util.Util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -132,7 +133,7 @@ public class DashManifest implements FilterableManifest<DashManifest> { ...@@ -132,7 +133,7 @@ public class DashManifest implements FilterableManifest<DashManifest> {
} }
public final long getPeriodDurationUs(int index) { public final long getPeriodDurationUs(int index) {
return C.msToUs(getPeriodDurationMs(index)); return Util.msToUs(getPeriodDurationMs(index));
} }
@Override @Override
......
...@@ -967,8 +967,8 @@ public class DashManifestParser extends DefaultHandler ...@@ -967,8 +967,8 @@ public class DashManifestParser extends DefaultHandler
timeline, timeline,
availabilityTimeOffsetUs, availabilityTimeOffsetUs,
segments, segments,
C.msToUs(timeShiftBufferDepthMs), Util.msToUs(timeShiftBufferDepthMs),
C.msToUs(periodStartUnixTimeMs)); Util.msToUs(periodStartUnixTimeMs));
} }
protected SegmentTemplate parseSegmentTemplate( protected SegmentTemplate parseSegmentTemplate(
...@@ -1057,8 +1057,8 @@ public class DashManifestParser extends DefaultHandler ...@@ -1057,8 +1057,8 @@ public class DashManifestParser extends DefaultHandler
availabilityTimeOffsetUs, availabilityTimeOffsetUs,
initializationTemplate, initializationTemplate,
mediaTemplate, mediaTemplate,
C.msToUs(timeShiftBufferDepthMs), Util.msToUs(timeShiftBufferDepthMs),
C.msToUs(periodStartUnixTimeMs)); Util.msToUs(periodStartUnixTimeMs));
} }
/** /**
......
...@@ -18,7 +18,6 @@ package com.google.android.exoplayer2.source.dash.offline; ...@@ -18,7 +18,6 @@ package com.google.android.exoplayer2.source.dash.offline;
import static com.google.android.exoplayer2.util.Util.castNonNull; import static com.google.android.exoplayer2.util.Util.castNonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.extractor.ChunkIndex; import com.google.android.exoplayer2.extractor.ChunkIndex;
import com.google.android.exoplayer2.offline.DownloadException; import com.google.android.exoplayer2.offline.DownloadException;
...@@ -38,6 +37,7 @@ import com.google.android.exoplayer2.upstream.DataSpec; ...@@ -38,6 +37,7 @@ import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser; import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource; import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.util.RunnableFutureTask; import com.google.android.exoplayer2.util.RunnableFutureTask;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -128,7 +128,7 @@ public final class DashDownloader extends SegmentDownloader<DashManifest> { ...@@ -128,7 +128,7 @@ public final class DashDownloader extends SegmentDownloader<DashManifest> {
ArrayList<Segment> segments = new ArrayList<>(); ArrayList<Segment> segments = new ArrayList<>();
for (int i = 0; i < manifest.getPeriodCount(); i++) { for (int i = 0; i < manifest.getPeriodCount(); i++) {
Period period = manifest.getPeriod(i); Period period = manifest.getPeriod(i);
long periodStartUs = C.msToUs(period.startMs); long periodStartUs = Util.msToUs(period.startMs);
long periodDurationUs = manifest.getPeriodDurationUs(i); long periodDurationUs = manifest.getPeriodDurationUs(i);
List<AdaptationSet> adaptationSets = period.adaptationSets; List<AdaptationSet> adaptationSets = period.adaptationSets;
for (int j = 0; j < adaptationSets.size(); j++) { for (int j = 0; j < adaptationSets.size(); j++) {
......
...@@ -45,6 +45,7 @@ import com.google.android.exoplayer2.upstream.HttpDataSource; ...@@ -45,6 +45,7 @@ import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.LoaderErrorThrower; import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -96,7 +97,7 @@ public class DefaultDashChunkSourceTest { ...@@ -96,7 +97,7 @@ public class DefaultDashChunkSourceTest {
/* closedCaptionFormats */ ImmutableList.of(), /* closedCaptionFormats */ ImmutableList.of(),
/* playerTrackEmsgHandler= */ null); /* playerTrackEmsgHandler= */ null);
long nowInPeriodUs = C.msToUs(nowMs - manifest.availabilityStartTimeMs); long nowInPeriodUs = Util.msToUs(nowMs - manifest.availabilityStartTimeMs);
ChunkHolder output = new ChunkHolder(); ChunkHolder output = new ChunkHolder();
chunkSource.getNextChunk( chunkSource.getNextChunk(
......
...@@ -62,7 +62,7 @@ import com.google.android.exoplayer2.util.Util; ...@@ -62,7 +62,7 @@ import com.google.android.exoplayer2.util.Util;
this.durationUs = this.durationUs =
durationUs != C.TIME_UNSET durationUs != C.TIME_UNSET
? durationUs ? durationUs
: C.msToUs(referenceTimesMs[referenceTimesMs.length - 1]); : Util.msToUs(referenceTimesMs[referenceTimesMs.length - 1]);
} }
@Override @Override
...@@ -74,8 +74,8 @@ import com.google.android.exoplayer2.util.Util; ...@@ -74,8 +74,8 @@ import com.google.android.exoplayer2.util.Util;
public SeekPoints getSeekPoints(long timeUs) { public SeekPoints getSeekPoints(long timeUs) {
timeUs = Util.constrainValue(timeUs, 0, durationUs); timeUs = Util.constrainValue(timeUs, 0, durationUs);
Pair<Long, Long> timeMsAndPosition = Pair<Long, Long> timeMsAndPosition =
linearlyInterpolate(C.usToMs(timeUs), referenceTimesMs, referencePositions); linearlyInterpolate(Util.usToMs(timeUs), referenceTimesMs, referencePositions);
timeUs = C.msToUs(timeMsAndPosition.first); timeUs = Util.msToUs(timeMsAndPosition.first);
long position = timeMsAndPosition.second; long position = timeMsAndPosition.second;
return new SeekPoints(new SeekPoint(timeUs, position)); return new SeekPoints(new SeekPoint(timeUs, position));
} }
...@@ -84,7 +84,7 @@ import com.google.android.exoplayer2.util.Util; ...@@ -84,7 +84,7 @@ import com.google.android.exoplayer2.util.Util;
public long getTimeUs(long position) { public long getTimeUs(long position) {
Pair<Long, Long> positionAndTimeMs = Pair<Long, Long> positionAndTimeMs =
linearlyInterpolate(position, referencePositions, referenceTimesMs); linearlyInterpolate(position, referencePositions, referenceTimesMs);
return C.msToUs(positionAndTimeMs.second); return Util.msToUs(positionAndTimeMs.second);
} }
@Override @Override
......
...@@ -586,7 +586,7 @@ public final class Mp3Extractor implements Extractor { ...@@ -586,7 +586,7 @@ public final class Mp3Extractor implements Extractor {
Metadata.Entry entry = metadata.get(i); Metadata.Entry entry = metadata.get(i);
if (entry instanceof TextInformationFrame if (entry instanceof TextInformationFrame
&& ((TextInformationFrame) entry).id.equals("TLEN")) { && ((TextInformationFrame) entry).id.equals("TLEN")) {
return C.msToUs(Long.parseLong(((TextInformationFrame) entry).value)); return Util.msToUs(Long.parseLong(((TextInformationFrame) entry).value));
} }
} }
} }
......
...@@ -508,7 +508,7 @@ public final class HlsMediaSource extends BaseMediaSource ...@@ -508,7 +508,7 @@ public final class HlsMediaSource extends BaseMediaSource
@Override @Override
public void onPrimaryPlaylistRefreshed(HlsMediaPlaylist mediaPlaylist) { public void onPrimaryPlaylistRefreshed(HlsMediaPlaylist mediaPlaylist) {
long windowStartTimeMs = long windowStartTimeMs =
mediaPlaylist.hasProgramDateTime ? C.usToMs(mediaPlaylist.startTimeUs) : C.TIME_UNSET; mediaPlaylist.hasProgramDateTime ? Util.usToMs(mediaPlaylist.startTimeUs) : C.TIME_UNSET;
// For playlist types EVENT and VOD we know segments are never removed, so the presentation // For playlist types EVENT and VOD we know segments are never removed, so the presentation
// started at the same time as the window. Otherwise, we don't know the presentation start time. // started at the same time as the window. Otherwise, we don't know the presentation start time.
long presentationStartTimeMs = long presentationStartTimeMs =
...@@ -541,7 +541,7 @@ public final class HlsMediaSource extends BaseMediaSource ...@@ -541,7 +541,7 @@ public final class HlsMediaSource extends BaseMediaSource
long targetLiveOffsetUs; long targetLiveOffsetUs;
if (liveConfiguration.targetOffsetMs != C.TIME_UNSET) { if (liveConfiguration.targetOffsetMs != C.TIME_UNSET) {
// Media item has a defined target offset. // Media item has a defined target offset.
targetLiveOffsetUs = C.msToUs(liveConfiguration.targetOffsetMs); targetLiveOffsetUs = Util.msToUs(liveConfiguration.targetOffsetMs);
} else { } else {
// Decide target offset from playlist. // Decide target offset from playlist.
targetLiveOffsetUs = getTargetLiveOffsetUs(playlist, liveEdgeOffsetUs); targetLiveOffsetUs = getTargetLiveOffsetUs(playlist, liveEdgeOffsetUs);
...@@ -607,7 +607,7 @@ public final class HlsMediaSource extends BaseMediaSource ...@@ -607,7 +607,7 @@ public final class HlsMediaSource extends BaseMediaSource
private long getLiveEdgeOffsetUs(HlsMediaPlaylist playlist) { private long getLiveEdgeOffsetUs(HlsMediaPlaylist playlist) {
return playlist.hasProgramDateTime return playlist.hasProgramDateTime
? C.msToUs(Util.getNowUnixTimeMs(elapsedRealTimeOffsetMs)) - playlist.getEndTimeUs() ? Util.msToUs(Util.getNowUnixTimeMs(elapsedRealTimeOffsetMs)) - playlist.getEndTimeUs()
: 0; : 0;
} }
...@@ -616,7 +616,9 @@ public final class HlsMediaSource extends BaseMediaSource ...@@ -616,7 +616,9 @@ public final class HlsMediaSource extends BaseMediaSource
long startPositionUs = long startPositionUs =
playlist.startOffsetUs != C.TIME_UNSET playlist.startOffsetUs != C.TIME_UNSET
? playlist.startOffsetUs ? playlist.startOffsetUs
: playlist.durationUs + liveEdgeOffsetUs - C.msToUs(liveConfiguration.targetOffsetMs); : playlist.durationUs
+ liveEdgeOffsetUs
- Util.msToUs(liveConfiguration.targetOffsetMs);
if (playlist.preciseStart) { if (playlist.preciseStart) {
return startPositionUs; return startPositionUs;
} }
...@@ -639,7 +641,7 @@ public final class HlsMediaSource extends BaseMediaSource ...@@ -639,7 +641,7 @@ public final class HlsMediaSource extends BaseMediaSource
} }
private void maybeUpdateLiveConfiguration(long targetLiveOffsetUs) { private void maybeUpdateLiveConfiguration(long targetLiveOffsetUs) {
long targetLiveOffsetMs = C.usToMs(targetLiveOffsetUs); long targetLiveOffsetMs = Util.usToMs(targetLiveOffsetUs);
if (targetLiveOffsetMs != liveConfiguration.targetOffsetMs) { if (targetLiveOffsetMs != liveConfiguration.targetOffsetMs) {
liveConfiguration = liveConfiguration =
liveConfiguration.buildUpon().setTargetOffsetMs(targetLiveOffsetMs).build(); liveConfiguration.buildUpon().setTargetOffsetMs(targetLiveOffsetMs).build();
......
...@@ -916,8 +916,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -916,8 +916,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
loadable.trackFormat, loadable.trackFormat,
loadable.trackSelectionReason, loadable.trackSelectionReason,
loadable.trackSelectionData, loadable.trackSelectionData,
C.usToMs(loadable.startTimeUs), Util.usToMs(loadable.startTimeUs),
C.usToMs(loadable.endTimeUs)); Util.usToMs(loadable.endTimeUs));
LoadErrorInfo loadErrorInfo = LoadErrorInfo loadErrorInfo =
new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount); new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount);
LoadErrorAction loadErrorAction; LoadErrorAction loadErrorAction;
......
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source.hls; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source.hls;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.source.SampleQueue; import com.google.android.exoplayer2.source.SampleQueue;
import com.google.android.exoplayer2.source.chunk.MediaChunk; import com.google.android.exoplayer2.source.chunk.MediaChunk;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
/** /**
...@@ -52,7 +53,7 @@ import java.io.IOException; ...@@ -52,7 +53,7 @@ import java.io.IOException;
MediaChunk mediaChunk, long lastAcceptedSampleTimeUs, long rejectedSampleTimeUs) { MediaChunk mediaChunk, long lastAcceptedSampleTimeUs, long rejectedSampleTimeUs) {
super( super(
"Unexpected sample timestamp: " "Unexpected sample timestamp: "
+ C.usToMs(rejectedSampleTimeUs) + Util.usToMs(rejectedSampleTimeUs)
+ " in chunk [" + " in chunk ["
+ mediaChunk.startTimeUs + mediaChunk.startTimeUs
+ ", " + ", "
......
...@@ -536,7 +536,7 @@ public final class DefaultHlsPlaylistTracker ...@@ -536,7 +536,7 @@ public final class DefaultHlsPlaylistTracker
return false; return false;
} }
long currentTimeMs = SystemClock.elapsedRealtime(); long currentTimeMs = SystemClock.elapsedRealtime();
long snapshotValidityDurationMs = max(30000, C.usToMs(playlistSnapshot.durationUs)); long snapshotValidityDurationMs = max(30000, Util.usToMs(playlistSnapshot.durationUs));
return playlistSnapshot.hasEndTag return playlistSnapshot.hasEndTag
|| playlistSnapshot.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_EVENT || playlistSnapshot.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_EVENT
|| playlistSnapshot.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_VOD || playlistSnapshot.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_VOD
...@@ -726,7 +726,7 @@ public final class DefaultHlsPlaylistTracker ...@@ -726,7 +726,7 @@ public final class DefaultHlsPlaylistTracker
forceRetry = true; forceRetry = true;
playlistError = new PlaylistResetException(playlistUrl); playlistError = new PlaylistResetException(playlistUrl);
} else if (currentTimeMs - lastSnapshotChangeMs } else if (currentTimeMs - lastSnapshotChangeMs
> C.usToMs(playlistSnapshot.targetDurationUs) > Util.usToMs(playlistSnapshot.targetDurationUs)
* playlistStuckTargetDurationCoefficient) { * playlistStuckTargetDurationCoefficient) {
// TODO: Allow customization of stuck playlists handling. // TODO: Allow customization of stuck playlists handling.
playlistError = new PlaylistStuckException(playlistUrl); playlistError = new PlaylistStuckException(playlistUrl);
...@@ -752,7 +752,7 @@ public final class DefaultHlsPlaylistTracker ...@@ -752,7 +752,7 @@ public final class DefaultHlsPlaylistTracker
? playlistSnapshot.targetDurationUs ? playlistSnapshot.targetDurationUs
: (playlistSnapshot.targetDurationUs / 2); : (playlistSnapshot.targetDurationUs / 2);
} }
earliestNextLoadTimeMs = currentTimeMs + C.usToMs(durationUntilNextLoadUs); earliestNextLoadTimeMs = currentTimeMs + Util.usToMs(durationUntilNextLoadUs);
// Schedule a load if this is the primary playlist or a playlist of a low-latency stream and // Schedule a load if this is the primary playlist or a playlist of a low-latency stream and
// it doesn't have an end tag. Else the next load will be scheduled when refreshPlaylist is // it doesn't have an end tag. Else the next load will be scheduled when refreshPlaylist is
// called, or when this playlist becomes the primary. // called, or when this playlist becomes the primary.
......
...@@ -844,7 +844,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli ...@@ -844,7 +844,7 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
} else if (line.startsWith(TAG_PROGRAM_DATE_TIME)) { } else if (line.startsWith(TAG_PROGRAM_DATE_TIME)) {
if (playlistStartTimeUs == 0) { if (playlistStartTimeUs == 0) {
long programDatetimeUs = long programDatetimeUs =
C.msToUs(Util.parseXsDateTime(line.substring(line.indexOf(':') + 1))); Util.msToUs(Util.parseXsDateTime(line.substring(line.indexOf(':') + 1)));
playlistStartTimeUs = programDatetimeUs - segmentStartTimeUs; playlistStartTimeUs = programDatetimeUs - segmentStartTimeUs;
} }
} else if (line.equals(TAG_GAP)) { } else if (line.equals(TAG_GAP)) {
......
...@@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock; ...@@ -22,7 +22,6 @@ import static org.mockito.Mockito.mock;
import android.net.Uri; import android.net.Uri;
import android.os.SystemClock; import android.os.SystemClock;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
...@@ -525,7 +524,7 @@ public class HlsMediaSourceTest { ...@@ -525,7 +524,7 @@ public class HlsMediaSourceTest {
Timeline.Window window = timeline.getWindow(0, new Timeline.Window()); Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
assertThat(mediaItem.liveConfiguration.targetOffsetMs) assertThat(mediaItem.liveConfiguration.targetOffsetMs)
.isGreaterThan(C.usToMs(window.durationUs)); .isGreaterThan(Util.usToMs(window.durationUs));
assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(9000); assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(9000);
} }
......
...@@ -686,7 +686,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -686,7 +686,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
playbackEventListener.onPlaybackStarted( playbackEventListener.onPlaybackStarted(
C.msToUs(response.sessionTiming.startTimeMs), response.trackTimingList); Util.msToUs(response.sessionTiming.startTimeMs), response.trackTimingList);
pendingSeekPositionUs = C.TIME_UNSET; pendingSeekPositionUs = C.TIME_UNSET;
} }
...@@ -695,7 +695,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -695,7 +695,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
rtspState = RTSP_STATE_READY; rtspState = RTSP_STATE_READY;
if (pendingSeekPositionUs != C.TIME_UNSET) { if (pendingSeekPositionUs != C.TIME_UNSET) {
startPlayback(C.usToMs(pendingSeekPositionUs)); startPlayback(Util.usToMs(pendingSeekPositionUs));
} }
} }
} }
......
...@@ -39,6 +39,7 @@ import com.google.android.exoplayer2.upstream.Allocator; ...@@ -39,6 +39,7 @@ import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
/** An Rtsp {@link MediaSource} */ /** An Rtsp {@link MediaSource} */
...@@ -274,7 +275,7 @@ public final class RtspMediaSource extends BaseMediaSource { ...@@ -274,7 +275,7 @@ public final class RtspMediaSource extends BaseMediaSource {
rtpDataChannelFactory, rtpDataChannelFactory,
uri, uri,
/* listener= */ timing -> { /* listener= */ timing -> {
timelineDurationUs = C.msToUs(timing.getDurationMs()); timelineDurationUs = Util.msToUs(timing.getDurationMs());
timelineIsSeekable = !timing.isLive(); timelineIsSeekable = !timing.isLive();
timelineIsLive = timing.isLive(); timelineIsLive = timing.isLive();
timelineIsPlaceholder = false; timelineIsPlaceholder = false;
......
...@@ -604,7 +604,7 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -604,7 +604,7 @@ public final class SsMediaSource extends BaseMediaSource
startTimeUs = max(startTimeUs, endTimeUs - manifest.dvrWindowLengthUs); startTimeUs = max(startTimeUs, endTimeUs - manifest.dvrWindowLengthUs);
} }
long durationUs = endTimeUs - startTimeUs; long durationUs = endTimeUs - startTimeUs;
long defaultStartPositionUs = durationUs - C.msToUs(livePresentationDelayMs); long defaultStartPositionUs = durationUs - Util.msToUs(livePresentationDelayMs);
if (defaultStartPositionUs < MIN_LIVE_DEFAULT_START_POSITION_US) { if (defaultStartPositionUs < MIN_LIVE_DEFAULT_START_POSITION_US) {
// The default start position is too close to the start of the live window. Set it to the // The default start position is too close to the start of the live window. Set it to the
// minimum default start position provided the window is at least twice as big. Else set // minimum default start position provided the window is at least twice as big. Else set
......
...@@ -26,6 +26,7 @@ import androidx.annotation.RequiresApi; ...@@ -26,6 +26,7 @@ import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** /**
...@@ -42,7 +43,7 @@ import java.nio.ByteBuffer; ...@@ -42,7 +43,7 @@ import java.nio.ByteBuffer;
* <p>The value of this constant has been chosen based on the interleaving observed in a few media * <p>The value of this constant has been chosen based on the interleaving observed in a few media
* files, where continuous chunks of the same track were about 0.5 seconds long. * files, where continuous chunks of the same track were about 0.5 seconds long.
*/ */
private static final long MAX_TRACK_WRITE_AHEAD_US = C.msToUs(500); private static final long MAX_TRACK_WRITE_AHEAD_US = Util.msToUs(500);
private final Muxer muxer; private final Muxer muxer;
private final Muxer.Factory muxerFactory; private final Muxer.Factory muxerFactory;
......
...@@ -31,6 +31,7 @@ import com.google.android.exoplayer2.metadata.Metadata; ...@@ -31,6 +31,7 @@ import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.mp4.SlowMotionData; import com.google.android.exoplayer2.metadata.mp4.SlowMotionData;
import com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry; import com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
...@@ -366,8 +367,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -366,8 +367,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
public final int maxLayer; public final int maxLayer;
public SegmentInfo(SlowMotionData.Segment segment, int inputMaxLayer, int normalSpeedLayer) { public SegmentInfo(SlowMotionData.Segment segment, int inputMaxLayer, int normalSpeedLayer) {
this.startTimeUs = C.msToUs(segment.startTimeMs); this.startTimeUs = Util.msToUs(segment.startTimeMs);
this.endTimeUs = C.msToUs(segment.endTimeMs); this.endTimeUs = Util.msToUs(segment.endTimeMs);
this.speedDivisor = segment.speedDivisor; this.speedDivisor = segment.speedDivisor;
this.maxLayer = getSlowMotionMaxLayer(speedDivisor, inputMaxLayer, normalSpeedLayer); this.maxLayer = getSlowMotionMaxLayer(speedDivisor, inputMaxLayer, normalSpeedLayer);
} }
......
...@@ -25,6 +25,7 @@ import com.google.android.exoplayer2.metadata.Metadata; ...@@ -25,6 +25,7 @@ import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.mp4.SlowMotionData; import com.google.android.exoplayer2.metadata.mp4.SlowMotionData;
import com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment; import com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment;
import com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry; import com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry;
import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -72,7 +73,7 @@ import java.util.TreeMap; ...@@ -72,7 +73,7 @@ import java.util.TreeMap;
for (int i = 0; i < segments.size(); i++) { for (int i = 0; i < segments.size(); i++) {
Segment currentSegment = segments.get(i); Segment currentSegment = segments.get(i);
speedsByStartTimeUs.put( speedsByStartTimeUs.put(
C.msToUs(currentSegment.startTimeMs), baseSpeed / currentSegment.speedDivisor); Util.msToUs(currentSegment.startTimeMs), baseSpeed / currentSegment.speedDivisor);
} }
// If the map has an entry at endTime, this is the next segments start time. If no such entry // If the map has an entry at endTime, this is the next segments start time. If no such entry
...@@ -80,8 +81,8 @@ import java.util.TreeMap; ...@@ -80,8 +81,8 @@ import java.util.TreeMap;
// segment. // segment.
for (int i = 0; i < segments.size(); i++) { for (int i = 0; i < segments.size(); i++) {
Segment currentSegment = segments.get(i); Segment currentSegment = segments.get(i);
if (!speedsByStartTimeUs.containsKey(C.msToUs(currentSegment.endTimeMs))) { if (!speedsByStartTimeUs.containsKey(Util.msToUs(currentSegment.endTimeMs))) {
speedsByStartTimeUs.put(C.msToUs(currentSegment.endTimeMs), baseSpeed); speedsByStartTimeUs.put(Util.msToUs(currentSegment.endTimeMs), baseSpeed);
} }
} }
......
...@@ -955,7 +955,7 @@ public class PlayerControlView extends FrameLayout { ...@@ -955,7 +955,7 @@ public class PlayerControlView extends FrameLayout {
int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex; int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex;
for (int i = firstWindowIndex; i <= lastWindowIndex; i++) { for (int i = firstWindowIndex; i <= lastWindowIndex; i++) {
if (i == currentWindowIndex) { if (i == currentWindowIndex) {
currentWindowOffset = C.usToMs(durationUs); currentWindowOffset = Util.usToMs(durationUs);
} }
timeline.getWindow(i, window); timeline.getWindow(i, window);
if (window.durationUs == C.TIME_UNSET) { if (window.durationUs == C.TIME_UNSET) {
...@@ -982,7 +982,7 @@ public class PlayerControlView extends FrameLayout { ...@@ -982,7 +982,7 @@ public class PlayerControlView extends FrameLayout {
adGroupTimesMs = Arrays.copyOf(adGroupTimesMs, newLength); adGroupTimesMs = Arrays.copyOf(adGroupTimesMs, newLength);
playedAdGroups = Arrays.copyOf(playedAdGroups, newLength); playedAdGroups = Arrays.copyOf(playedAdGroups, newLength);
} }
adGroupTimesMs[adGroupCount] = C.usToMs(durationUs + adGroupTimeInWindowUs); adGroupTimesMs[adGroupCount] = Util.usToMs(durationUs + adGroupTimeInWindowUs);
playedAdGroups[adGroupCount] = period.hasPlayedAdGroup(adGroupIndex); playedAdGroups[adGroupCount] = period.hasPlayedAdGroup(adGroupIndex);
adGroupCount++; adGroupCount++;
} }
...@@ -991,7 +991,7 @@ public class PlayerControlView extends FrameLayout { ...@@ -991,7 +991,7 @@ public class PlayerControlView extends FrameLayout {
durationUs += window.durationUs; durationUs += window.durationUs;
} }
} }
long durationMs = C.usToMs(durationUs); long durationMs = Util.usToMs(durationUs);
if (durationView != null) { if (durationView != null) {
durationView.setText(Util.getStringForTime(formatBuilder, formatter, durationMs)); durationView.setText(Util.getStringForTime(formatBuilder, formatter, durationMs));
} }
......
...@@ -1274,7 +1274,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1274,7 +1274,7 @@ public class StyledPlayerControlView extends FrameLayout {
int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex; int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex;
for (int i = firstWindowIndex; i <= lastWindowIndex; i++) { for (int i = firstWindowIndex; i <= lastWindowIndex; i++) {
if (i == currentWindowIndex) { if (i == currentWindowIndex) {
currentWindowOffset = C.usToMs(durationUs); currentWindowOffset = Util.usToMs(durationUs);
} }
timeline.getWindow(i, window); timeline.getWindow(i, window);
if (window.durationUs == C.TIME_UNSET) { if (window.durationUs == C.TIME_UNSET) {
...@@ -1301,7 +1301,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1301,7 +1301,7 @@ public class StyledPlayerControlView extends FrameLayout {
adGroupTimesMs = Arrays.copyOf(adGroupTimesMs, newLength); adGroupTimesMs = Arrays.copyOf(adGroupTimesMs, newLength);
playedAdGroups = Arrays.copyOf(playedAdGroups, newLength); playedAdGroups = Arrays.copyOf(playedAdGroups, newLength);
} }
adGroupTimesMs[adGroupCount] = C.usToMs(durationUs + adGroupTimeInWindowUs); adGroupTimesMs[adGroupCount] = Util.usToMs(durationUs + adGroupTimeInWindowUs);
playedAdGroups[adGroupCount] = period.hasPlayedAdGroup(adGroupIndex); playedAdGroups[adGroupCount] = period.hasPlayedAdGroup(adGroupIndex);
adGroupCount++; adGroupCount++;
} }
...@@ -1310,7 +1310,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1310,7 +1310,7 @@ public class StyledPlayerControlView extends FrameLayout {
durationUs += window.durationUs; durationUs += window.durationUs;
} }
} }
long durationMs = C.usToMs(durationUs); long durationMs = Util.usToMs(durationUs);
if (durationView != null) { if (durationView != null) {
durationView.setText(Util.getStringForTime(formatBuilder, formatter, durationMs)); durationView.setText(Util.getStringForTime(formatBuilder, formatter, durationMs));
} }
......
...@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.source.ads.AdPlaybackState; ...@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.source.ads.AdPlaybackState;
import com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition; import com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition;
import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
import com.google.android.exoplayer2.util.Util;
/** Fake {@link MediaSourceFactory} that creates a {@link FakeMediaSource}. */ /** Fake {@link MediaSourceFactory} that creates a {@link FakeMediaSource}. */
public class FakeMediaSourceFactory implements MediaSourceFactory { public class FakeMediaSourceFactory implements MediaSourceFactory {
...@@ -81,7 +82,7 @@ public class FakeMediaSourceFactory implements MediaSourceFactory { ...@@ -81,7 +82,7 @@ public class FakeMediaSourceFactory implements MediaSourceFactory {
/* isPlaceholder= */ false, /* isPlaceholder= */ false,
/* durationUs= */ 1000 * C.MICROS_PER_SECOND, /* durationUs= */ 1000 * C.MICROS_PER_SECOND,
/* defaultPositionUs= */ 2 * C.MICROS_PER_SECOND, /* defaultPositionUs= */ 2 * C.MICROS_PER_SECOND,
/* windowOffsetInFirstPeriodUs= */ C.msToUs(123456789), /* windowOffsetInFirstPeriodUs= */ Util.msToUs(123456789),
AdPlaybackState.NONE, AdPlaybackState.NONE,
mediaItem); mediaItem);
return new FakeMediaSource(new FakeTimeline(timelineWindowDefinition)); return new FakeMediaSource(new FakeTimeline(timelineWindowDefinition));
......
...@@ -367,7 +367,7 @@ public final class FakeTimeline extends Timeline { ...@@ -367,7 +367,7 @@ public final class FakeTimeline extends Timeline {
manifests[windowIndex], manifests[windowIndex],
/* presentationStartTimeMs= */ C.TIME_UNSET, /* presentationStartTimeMs= */ C.TIME_UNSET,
/* windowStartTimeMs= */ windowDefinition.isLive /* windowStartTimeMs= */ windowDefinition.isLive
? C.usToMs(windowDefinition.windowOffsetInFirstPeriodUs) ? Util.usToMs(windowDefinition.windowOffsetInFirstPeriodUs)
: C.TIME_UNSET, : C.TIME_UNSET,
/* elapsedRealtimeEpochOffsetMs= */ windowDefinition.isLive ? 0 : C.TIME_UNSET, /* elapsedRealtimeEpochOffsetMs= */ windowDefinition.isLive ? 0 : C.TIME_UNSET,
windowDefinition.isSeekable, windowDefinition.isSeekable,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment