mirror of
https://github.com/androidx/media.git
synced 2025-05-12 10:09:55 +08:00
Split PlaybackInfo into its own file
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=174030901
This commit is contained in:
parent
f150856567
commit
199b983d42
@ -21,7 +21,6 @@ import android.os.Looper;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.google.android.exoplayer2.ExoPlayerImplInternal.PlaybackInfo;
|
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
@ -57,8 +56,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
private int pendingSeekAcks;
|
private int pendingSeekAcks;
|
||||||
private int pendingPrepareAcks;
|
private int pendingPrepareAcks;
|
||||||
private boolean isLoading;
|
private boolean isLoading;
|
||||||
private Timeline timeline;
|
|
||||||
private Object manifest;
|
|
||||||
private TrackGroupArray trackGroups;
|
private TrackGroupArray trackGroups;
|
||||||
private TrackSelectionArray trackSelections;
|
private TrackSelectionArray trackSelections;
|
||||||
private PlaybackParameters playbackParameters;
|
private PlaybackParameters playbackParameters;
|
||||||
@ -91,7 +88,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
this.playbackState = Player.STATE_IDLE;
|
this.playbackState = Player.STATE_IDLE;
|
||||||
this.listeners = new CopyOnWriteArraySet<>();
|
this.listeners = new CopyOnWriteArraySet<>();
|
||||||
emptyTrackSelections = new TrackSelectionArray(new TrackSelection[renderers.length]);
|
emptyTrackSelections = new TrackSelectionArray(new TrackSelection[renderers.length]);
|
||||||
timeline = Timeline.EMPTY;
|
|
||||||
window = new Timeline.Window();
|
window = new Timeline.Window();
|
||||||
period = new Timeline.Period();
|
period = new Timeline.Period();
|
||||||
trackGroups = TrackGroupArray.EMPTY;
|
trackGroups = TrackGroupArray.EMPTY;
|
||||||
@ -104,7 +100,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
ExoPlayerImpl.this.handleEvent(msg);
|
ExoPlayerImpl.this.handleEvent(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
playbackInfo = new ExoPlayerImplInternal.PlaybackInfo(timeline, manifest, 0, 0);
|
playbackInfo = new PlaybackInfo(Timeline.EMPTY, null, 0, 0);
|
||||||
internalPlayer = new ExoPlayerImplInternal(renderers, trackSelector, loadControl, playWhenReady,
|
internalPlayer = new ExoPlayerImplInternal(renderers, trackSelector, loadControl, playWhenReady,
|
||||||
repeatMode, shuffleModeEnabled, eventHandler, this);
|
repeatMode, shuffleModeEnabled, eventHandler, this);
|
||||||
}
|
}
|
||||||
@ -146,11 +142,10 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
maskingWindowPositionMs = 0;
|
maskingWindowPositionMs = 0;
|
||||||
}
|
}
|
||||||
if (resetState) {
|
if (resetState) {
|
||||||
if (!timeline.isEmpty() || manifest != null) {
|
if (!playbackInfo.timeline.isEmpty() || playbackInfo.manifest != null) {
|
||||||
timeline = Timeline.EMPTY;
|
playbackInfo = playbackInfo.copyWithTimeline(Timeline.EMPTY, null);
|
||||||
manifest = null;
|
|
||||||
for (Player.EventListener listener : listeners) {
|
for (Player.EventListener listener : listeners) {
|
||||||
listener.onTimelineChanged(timeline, manifest);
|
listener.onTimelineChanged(playbackInfo.timeline, playbackInfo.manifest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tracksSelected) {
|
if (tracksSelected) {
|
||||||
@ -237,6 +232,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seekTo(int windowIndex, long positionMs) {
|
public void seekTo(int windowIndex, long positionMs) {
|
||||||
|
Timeline timeline = playbackInfo.timeline;
|
||||||
if (windowIndex < 0 || (!timeline.isEmpty() && windowIndex >= timeline.getWindowCount())) {
|
if (windowIndex < 0 || (!timeline.isEmpty() && windowIndex >= timeline.getWindowCount())) {
|
||||||
throw new IllegalSeekPositionException(timeline, windowIndex, positionMs);
|
throw new IllegalSeekPositionException(timeline, windowIndex, positionMs);
|
||||||
}
|
}
|
||||||
@ -334,24 +330,27 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
if (shouldMaskPosition()) {
|
if (shouldMaskPosition()) {
|
||||||
return maskingWindowIndex;
|
return maskingWindowIndex;
|
||||||
} else {
|
} else {
|
||||||
return timeline.getPeriod(playbackInfo.periodId.periodIndex, period).windowIndex;
|
return playbackInfo.timeline.getPeriod(playbackInfo.periodId.periodIndex, period).windowIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNextWindowIndex() {
|
public int getNextWindowIndex() {
|
||||||
|
Timeline timeline = playbackInfo.timeline;
|
||||||
return timeline.isEmpty() ? C.INDEX_UNSET
|
return timeline.isEmpty() ? C.INDEX_UNSET
|
||||||
: timeline.getNextWindowIndex(getCurrentWindowIndex(), repeatMode, shuffleModeEnabled);
|
: timeline.getNextWindowIndex(getCurrentWindowIndex(), repeatMode, shuffleModeEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPreviousWindowIndex() {
|
public int getPreviousWindowIndex() {
|
||||||
|
Timeline timeline = playbackInfo.timeline;
|
||||||
return timeline.isEmpty() ? C.INDEX_UNSET
|
return timeline.isEmpty() ? C.INDEX_UNSET
|
||||||
: timeline.getPreviousWindowIndex(getCurrentWindowIndex(), repeatMode, shuffleModeEnabled);
|
: timeline.getPreviousWindowIndex(getCurrentWindowIndex(), repeatMode, shuffleModeEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getDuration() {
|
public long getDuration() {
|
||||||
|
Timeline timeline = playbackInfo.timeline;
|
||||||
if (timeline.isEmpty()) {
|
if (timeline.isEmpty()) {
|
||||||
return C.TIME_UNSET;
|
return C.TIME_UNSET;
|
||||||
}
|
}
|
||||||
@ -386,9 +385,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBufferedPercentage() {
|
public int getBufferedPercentage() {
|
||||||
if (timeline.isEmpty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
long position = getBufferedPosition();
|
long position = getBufferedPosition();
|
||||||
long duration = getDuration();
|
long duration = getDuration();
|
||||||
return position == C.TIME_UNSET || duration == C.TIME_UNSET ? 0
|
return position == C.TIME_UNSET || duration == C.TIME_UNSET ? 0
|
||||||
@ -397,11 +393,13 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCurrentWindowDynamic() {
|
public boolean isCurrentWindowDynamic() {
|
||||||
|
Timeline timeline = playbackInfo.timeline;
|
||||||
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), window).isDynamic;
|
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), window).isDynamic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCurrentWindowSeekable() {
|
public boolean isCurrentWindowSeekable() {
|
||||||
|
Timeline timeline = playbackInfo.timeline;
|
||||||
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), window).isSeekable;
|
return !timeline.isEmpty() && timeline.getWindow(getCurrentWindowIndex(), window).isSeekable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +421,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
@Override
|
@Override
|
||||||
public long getContentPosition() {
|
public long getContentPosition() {
|
||||||
if (isPlayingAd()) {
|
if (isPlayingAd()) {
|
||||||
timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
|
playbackInfo.timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
|
||||||
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.contentPositionUs);
|
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.contentPositionUs);
|
||||||
} else {
|
} else {
|
||||||
return getCurrentPosition();
|
return getCurrentPosition();
|
||||||
@ -452,12 +450,12 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Timeline getCurrentTimeline() {
|
public Timeline getCurrentTimeline() {
|
||||||
return timeline;
|
return playbackInfo.timeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getCurrentManifest() {
|
public Object getCurrentManifest() {
|
||||||
return manifest;
|
return playbackInfo.manifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not private so it can be called from an inner class without going through a thunk method.
|
// Not private so it can be called from an inner class without going through a thunk method.
|
||||||
@ -533,12 +531,10 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
pendingPrepareAcks -= prepareAcks;
|
pendingPrepareAcks -= prepareAcks;
|
||||||
pendingSeekAcks -= seekAcks;
|
pendingSeekAcks -= seekAcks;
|
||||||
if (pendingPrepareAcks == 0 && pendingSeekAcks == 0) {
|
if (pendingPrepareAcks == 0 && pendingSeekAcks == 0) {
|
||||||
|
boolean timelineOrManifestChanged = this.playbackInfo.timeline != playbackInfo.timeline
|
||||||
|
|| this.playbackInfo.manifest != playbackInfo.manifest;
|
||||||
this.playbackInfo = playbackInfo;
|
this.playbackInfo = playbackInfo;
|
||||||
boolean timelineOrManifestChanged = timeline != playbackInfo.timeline
|
if (playbackInfo.timeline.isEmpty()) {
|
||||||
|| manifest != playbackInfo.manifest;
|
|
||||||
timeline = playbackInfo.timeline;
|
|
||||||
manifest = playbackInfo.manifest;
|
|
||||||
if (timeline.isEmpty()) {
|
|
||||||
// Update the masking variables, which are used when the timeline is empty.
|
// Update the masking variables, which are used when the timeline is empty.
|
||||||
maskingPeriodIndex = 0;
|
maskingPeriodIndex = 0;
|
||||||
maskingWindowIndex = 0;
|
maskingWindowIndex = 0;
|
||||||
@ -546,7 +542,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
}
|
}
|
||||||
if (timelineOrManifestChanged) {
|
if (timelineOrManifestChanged) {
|
||||||
for (Player.EventListener listener : listeners) {
|
for (Player.EventListener listener : listeners) {
|
||||||
listener.onTimelineChanged(timeline, manifest);
|
listener.onTimelineChanged(playbackInfo.timeline, playbackInfo.manifest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (positionDiscontinuity) {
|
if (positionDiscontinuity) {
|
||||||
@ -567,14 +563,14 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
private long playbackInfoPositionUsToWindowPositionMs(long positionUs) {
|
private long playbackInfoPositionUsToWindowPositionMs(long positionUs) {
|
||||||
long positionMs = C.usToMs(positionUs);
|
long positionMs = C.usToMs(positionUs);
|
||||||
if (!playbackInfo.periodId.isAd()) {
|
if (!playbackInfo.periodId.isAd()) {
|
||||||
timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
|
playbackInfo.timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
|
||||||
positionMs += period.getPositionInWindowMs();
|
positionMs += period.getPositionInWindowMs();
|
||||||
}
|
}
|
||||||
return positionMs;
|
return positionMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldMaskPosition() {
|
private boolean shouldMaskPosition() {
|
||||||
return timeline.isEmpty() || pendingSeekAcks > 0 || pendingPrepareAcks > 0;
|
return playbackInfo.timeline.isEmpty() || pendingSeekAcks > 0 || pendingPrepareAcks > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,67 +48,6 @@ import java.io.IOException;
|
|||||||
/* package */ final class ExoPlayerImplInternal implements Handler.Callback,
|
/* package */ final class ExoPlayerImplInternal implements Handler.Callback,
|
||||||
MediaPeriod.Callback, TrackSelector.InvalidationListener, MediaSource.Listener {
|
MediaPeriod.Callback, TrackSelector.InvalidationListener, MediaSource.Listener {
|
||||||
|
|
||||||
/**
|
|
||||||
* Playback position information which is read on the application's thread by
|
|
||||||
* {@link ExoPlayerImpl} and read/written internally on the player's thread.
|
|
||||||
*/
|
|
||||||
public static final class PlaybackInfo {
|
|
||||||
|
|
||||||
public final Timeline timeline;
|
|
||||||
public final Object manifest;
|
|
||||||
public final MediaPeriodId periodId;
|
|
||||||
public final long startPositionUs;
|
|
||||||
public final long contentPositionUs;
|
|
||||||
|
|
||||||
public volatile long positionUs;
|
|
||||||
public volatile long bufferedPositionUs;
|
|
||||||
|
|
||||||
public PlaybackInfo(Timeline timeline, Object manifest, int periodIndex, long startPositionUs) {
|
|
||||||
this(timeline, manifest, new MediaPeriodId(periodIndex), startPositionUs, C.TIME_UNSET);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaybackInfo(Timeline timeline, Object manifest, MediaPeriodId periodId,
|
|
||||||
long startPositionUs, long contentPositionUs) {
|
|
||||||
this.timeline = timeline;
|
|
||||||
this.manifest = manifest;
|
|
||||||
this.periodId = periodId;
|
|
||||||
this.startPositionUs = startPositionUs;
|
|
||||||
this.contentPositionUs = contentPositionUs;
|
|
||||||
positionUs = startPositionUs;
|
|
||||||
bufferedPositionUs = startPositionUs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaybackInfo fromNewPosition(int periodIndex, long startPositionUs,
|
|
||||||
long contentPositionUs) {
|
|
||||||
return fromNewPosition(new MediaPeriodId(periodIndex), startPositionUs, contentPositionUs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaybackInfo fromNewPosition(MediaPeriodId periodId, long startPositionUs,
|
|
||||||
long contentPositionUs) {
|
|
||||||
return new PlaybackInfo(timeline, manifest, periodId, startPositionUs, contentPositionUs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaybackInfo copyWithPeriodIndex(int periodIndex) {
|
|
||||||
PlaybackInfo playbackInfo = new PlaybackInfo(timeline, manifest,
|
|
||||||
periodId.copyWithPeriodIndex(periodIndex), startPositionUs, contentPositionUs);
|
|
||||||
copyMutablePositions(this, playbackInfo);
|
|
||||||
return playbackInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaybackInfo copyWithTimeline(Timeline timeline, Object manifest) {
|
|
||||||
PlaybackInfo playbackInfo = new PlaybackInfo(timeline, manifest, periodId, startPositionUs,
|
|
||||||
contentPositionUs);
|
|
||||||
copyMutablePositions(this, playbackInfo);
|
|
||||||
return playbackInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void copyMutablePositions(PlaybackInfo from, PlaybackInfo to) {
|
|
||||||
to.positionUs = from.positionUs;
|
|
||||||
to.bufferedPositionUs = from.bufferedPositionUs;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String TAG = "ExoPlayerImplInternal";
|
private static final String TAG = "ExoPlayerImplInternal";
|
||||||
|
|
||||||
// External messages
|
// External messages
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
package com.google.android.exoplayer2;
|
package com.google.android.exoplayer2;
|
||||||
|
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import com.google.android.exoplayer2.ExoPlayerImplInternal.PlaybackInfo;
|
|
||||||
import com.google.android.exoplayer2.Player.RepeatMode;
|
import com.google.android.exoplayer2.Player.RepeatMode;
|
||||||
import com.google.android.exoplayer2.source.MediaPeriod;
|
import com.google.android.exoplayer2.source.MediaPeriod;
|
||||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.exoplayer2;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information about an ongoing playback.
|
||||||
|
*/
|
||||||
|
/* package */ final class PlaybackInfo {
|
||||||
|
|
||||||
|
public final Timeline timeline;
|
||||||
|
public final Object manifest;
|
||||||
|
public final MediaPeriodId periodId;
|
||||||
|
public final long startPositionUs;
|
||||||
|
public final long contentPositionUs;
|
||||||
|
|
||||||
|
public volatile long positionUs;
|
||||||
|
public volatile long bufferedPositionUs;
|
||||||
|
|
||||||
|
public PlaybackInfo(Timeline timeline, Object manifest, int periodIndex, long startPositionUs) {
|
||||||
|
this(timeline, manifest, new MediaPeriodId(periodIndex), startPositionUs, C.TIME_UNSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlaybackInfo(Timeline timeline, Object manifest, MediaPeriodId periodId,
|
||||||
|
long startPositionUs, long contentPositionUs) {
|
||||||
|
this.timeline = timeline;
|
||||||
|
this.manifest = manifest;
|
||||||
|
this.periodId = periodId;
|
||||||
|
this.startPositionUs = startPositionUs;
|
||||||
|
this.contentPositionUs = contentPositionUs;
|
||||||
|
positionUs = startPositionUs;
|
||||||
|
bufferedPositionUs = startPositionUs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlaybackInfo fromNewPosition(int periodIndex, long startPositionUs,
|
||||||
|
long contentPositionUs) {
|
||||||
|
return fromNewPosition(new MediaPeriodId(periodIndex), startPositionUs, contentPositionUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlaybackInfo fromNewPosition(MediaPeriodId periodId, long startPositionUs,
|
||||||
|
long contentPositionUs) {
|
||||||
|
return new PlaybackInfo(timeline, manifest, periodId, startPositionUs, contentPositionUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlaybackInfo copyWithPeriodIndex(int periodIndex) {
|
||||||
|
PlaybackInfo playbackInfo = new PlaybackInfo(timeline, manifest,
|
||||||
|
periodId.copyWithPeriodIndex(periodIndex), startPositionUs, contentPositionUs);
|
||||||
|
copyMutablePositions(this, playbackInfo);
|
||||||
|
return playbackInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlaybackInfo copyWithTimeline(Timeline timeline, Object manifest) {
|
||||||
|
PlaybackInfo playbackInfo = new PlaybackInfo(timeline, manifest, periodId, startPositionUs,
|
||||||
|
contentPositionUs);
|
||||||
|
copyMutablePositions(this, playbackInfo);
|
||||||
|
return playbackInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void copyMutablePositions(PlaybackInfo from, PlaybackInfo to) {
|
||||||
|
to.positionUs = from.positionUs;
|
||||||
|
to.bufferedPositionUs = from.bufferedPositionUs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user