mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Store a MediaPeriodId in PlaybackInfo
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=160271631
This commit is contained in:
parent
675756d32d
commit
1dcad4d173
@ -281,7 +281,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
if (timeline.isEmpty() || pendingSeekAcks > 0) {
|
if (timeline.isEmpty() || pendingSeekAcks > 0) {
|
||||||
return maskingPeriodIndex;
|
return maskingPeriodIndex;
|
||||||
} else {
|
} else {
|
||||||
return playbackInfo.periodIndex;
|
return playbackInfo.periodId.periodIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
if (timeline.isEmpty() || pendingSeekAcks > 0) {
|
if (timeline.isEmpty() || pendingSeekAcks > 0) {
|
||||||
return maskingWindowIndex;
|
return maskingWindowIndex;
|
||||||
} else {
|
} else {
|
||||||
return timeline.getPeriod(playbackInfo.periodIndex, period).windowIndex;
|
return timeline.getPeriod(playbackInfo.periodId.periodIndex, period).windowIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
if (timeline.isEmpty() || pendingSeekAcks > 0) {
|
if (timeline.isEmpty() || pendingSeekAcks > 0) {
|
||||||
return maskingWindowPositionMs;
|
return maskingWindowPositionMs;
|
||||||
} else {
|
} else {
|
||||||
timeline.getPeriod(playbackInfo.periodIndex, period);
|
timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
|
||||||
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.positionUs);
|
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.positionUs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,7 +318,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
if (timeline.isEmpty() || pendingSeekAcks > 0) {
|
if (timeline.isEmpty() || pendingSeekAcks > 0) {
|
||||||
return maskingWindowPositionMs;
|
return maskingWindowPositionMs;
|
||||||
} else {
|
} else {
|
||||||
timeline.getPeriod(playbackInfo.periodIndex, period);
|
timeline.getPeriod(playbackInfo.periodId.periodIndex, period);
|
||||||
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.bufferedPositionUs);
|
return period.getPositionInWindowMs() + C.usToMs(playbackInfo.bufferedPositionUs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,21 +50,25 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public static final class PlaybackInfo {
|
public static final class PlaybackInfo {
|
||||||
|
|
||||||
public final int periodIndex;
|
public final MediaPeriodId periodId;
|
||||||
public final long startPositionUs;
|
public final long startPositionUs;
|
||||||
|
|
||||||
public volatile long positionUs;
|
public volatile long positionUs;
|
||||||
public volatile long bufferedPositionUs;
|
public volatile long bufferedPositionUs;
|
||||||
|
|
||||||
public PlaybackInfo(int periodIndex, long startPositionUs) {
|
public PlaybackInfo(int periodIndex, long startPositionUs) {
|
||||||
this.periodIndex = periodIndex;
|
this(new MediaPeriodId(periodIndex), startPositionUs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlaybackInfo(MediaPeriodId periodId, long startPositionUs) {
|
||||||
|
this.periodId = periodId;
|
||||||
this.startPositionUs = startPositionUs;
|
this.startPositionUs = startPositionUs;
|
||||||
positionUs = startPositionUs;
|
positionUs = startPositionUs;
|
||||||
bufferedPositionUs = startPositionUs;
|
bufferedPositionUs = startPositionUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaybackInfo copyWithPeriodIndex(int periodIndex) {
|
public PlaybackInfo copyWithPeriodId(MediaPeriodId periodId) {
|
||||||
PlaybackInfo playbackInfo = new PlaybackInfo(periodIndex, startPositionUs);
|
PlaybackInfo playbackInfo = new PlaybackInfo(periodId.periodIndex, startPositionUs);
|
||||||
playbackInfo.positionUs = positionUs;
|
playbackInfo.positionUs = positionUs;
|
||||||
playbackInfo.bufferedPositionUs = bufferedPositionUs;
|
playbackInfo.bufferedPositionUs = bufferedPositionUs;
|
||||||
return playbackInfo;
|
return playbackInfo;
|
||||||
@ -654,7 +658,7 @@ import java.io.IOException;
|
|||||||
long periodPositionUs = periodPosition.second;
|
long periodPositionUs = periodPosition.second;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (periodIndex == playbackInfo.periodIndex
|
if (periodIndex == playbackInfo.periodId.periodIndex
|
||||||
&& ((periodPositionUs / 1000) == (playbackInfo.positionUs / 1000))) {
|
&& ((periodPositionUs / 1000) == (playbackInfo.positionUs / 1000))) {
|
||||||
// Seek position equals the current position. Do nothing.
|
// Seek position equals the current position. Do nothing.
|
||||||
return;
|
return;
|
||||||
@ -1017,8 +1021,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
// The current period is in the new timeline. Update the holder and playbackInfo.
|
// The current period is in the new timeline. Update the holder and playbackInfo.
|
||||||
periodHolder.setPeriodIndex(periodIndex, isFinalPeriod(periodIndex));
|
periodHolder.setPeriodIndex(periodIndex, isFinalPeriod(periodIndex));
|
||||||
if (periodIndex != playbackInfo.periodIndex) {
|
if (periodIndex != playbackInfo.periodId.periodIndex) {
|
||||||
playbackInfo = playbackInfo.copyWithPeriodIndex(periodIndex);
|
playbackInfo = playbackInfo.copyWithPeriodId(new MediaPeriodId(periodIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are subsequent holders, update the index for each of them. If we find a holder
|
// If there are subsequent holders, update the index for each of them. If we find a holder
|
||||||
@ -1301,7 +1305,7 @@ import java.io.IOException;
|
|||||||
private void maybeUpdateLoadingPeriod() throws IOException {
|
private void maybeUpdateLoadingPeriod() throws IOException {
|
||||||
int newLoadingPeriodIndex;
|
int newLoadingPeriodIndex;
|
||||||
if (loadingPeriodHolder == null) {
|
if (loadingPeriodHolder == null) {
|
||||||
newLoadingPeriodIndex = playbackInfo.periodIndex;
|
newLoadingPeriodIndex = playbackInfo.periodId.periodIndex;
|
||||||
} else {
|
} else {
|
||||||
int loadingPeriodIndex = loadingPeriodHolder.periodIndex;
|
int loadingPeriodIndex = loadingPeriodHolder.periodIndex;
|
||||||
if (loadingPeriodHolder.isFinal || !loadingPeriodHolder.isFullyBuffered()
|
if (loadingPeriodHolder.isFinal || !loadingPeriodHolder.isFullyBuffered()
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package com.google.android.exoplayer2.source;
|
package com.google.android.exoplayer2.source;
|
||||||
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ExoPlayer;
|
import com.google.android.exoplayer2.ExoPlayer;
|
||||||
import com.google.android.exoplayer2.Timeline;
|
import com.google.android.exoplayer2.Timeline;
|
||||||
import com.google.android.exoplayer2.upstream.Allocator;
|
import com.google.android.exoplayer2.upstream.Allocator;
|
||||||
@ -51,13 +52,28 @@ public interface MediaSource {
|
|||||||
*/
|
*/
|
||||||
public final int periodIndex;
|
public final int periodIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the media period is in an ad break, the index of the ad break in the period.
|
||||||
|
* {@link C#INDEX_UNSET} otherwise.
|
||||||
|
*/
|
||||||
|
public final int adBreakIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the media period is in an ad break, the index of the ad in its ad break in the period.
|
||||||
|
* {@link C#INDEX_UNSET} otherwise.
|
||||||
|
*/
|
||||||
|
public final int adIndexInAdBreak;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a media period identifier for the specified period in the timeline.
|
* Creates a media period identifier for the specified period in the timeline.
|
||||||
*
|
*
|
||||||
* @param periodIndex The timeline period index.
|
* @param periodIndex The timeline period index.
|
||||||
*/
|
*/
|
||||||
public MediaPeriodId(int periodIndex) {
|
public MediaPeriodId(int periodIndex) {
|
||||||
|
// TODO: Allow creation of MediaPeriodIds for ad breaks.
|
||||||
this.periodIndex = periodIndex;
|
this.periodIndex = periodIndex;
|
||||||
|
adBreakIndex = C.INDEX_UNSET;
|
||||||
|
adIndexInAdBreak = C.INDEX_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user