mirror of
https://github.com/androidx/media.git
synced 2025-05-04 22:20:47 +08:00
Fix bug that caused failure when all renderers disabled.
Prior to this change, there was a bug where playback would fail with the following steps: 1. Start playback. 2. Pause playback. 3. Disable all renderers. 4. Enable at least one renderer. 5. Resume playback.
This commit is contained in:
parent
33d55631ed
commit
2b27137e9e
@ -163,6 +163,7 @@ public class ChunkSampleSource implements SampleSource, SampleSourceReader, Load
|
||||
downstreamMediaFormat = null;
|
||||
downstreamPositionUs = positionUs;
|
||||
lastSeekPositionUs = positionUs;
|
||||
pendingDiscontinuity = false;
|
||||
restartFrom(positionUs);
|
||||
}
|
||||
|
||||
@ -170,7 +171,6 @@ public class ChunkSampleSource implements SampleSource, SampleSourceReader, Load
|
||||
public void disable(int track) {
|
||||
Assertions.checkState(state == STATE_ENABLED);
|
||||
Assertions.checkState(track == 0);
|
||||
pendingDiscontinuity = false;
|
||||
state = STATE_PREPARED;
|
||||
try {
|
||||
chunkSource.disable(mediaChunks);
|
||||
@ -269,12 +269,14 @@ public class ChunkSampleSource implements SampleSource, SampleSourceReader, Load
|
||||
@Override
|
||||
public void seekToUs(long positionUs) {
|
||||
Assertions.checkState(state == STATE_ENABLED);
|
||||
|
||||
long currentPositionUs = isPendingReset() ? pendingResetPositionUs : downstreamPositionUs;
|
||||
downstreamPositionUs = positionUs;
|
||||
lastSeekPositionUs = positionUs;
|
||||
if ((isPendingReset() ? pendingResetPositionUs : downstreamPositionUs) == positionUs) {
|
||||
if (currentPositionUs == positionUs) {
|
||||
return;
|
||||
}
|
||||
|
||||
downstreamPositionUs = positionUs;
|
||||
// If we're not pending a reset, see if we can seek within the sample queue.
|
||||
boolean seekInsideBuffer = !isPendingReset() && sampleQueue.skipToKeyframeBefore(positionUs);
|
||||
if (seekInsideBuffer) {
|
||||
|
@ -194,6 +194,7 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
|
||||
if (enabledTrackCount == 1) {
|
||||
seekToUs(positionUs);
|
||||
}
|
||||
pendingDiscontinuities[track] = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -202,8 +203,8 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
|
||||
Assertions.checkState(trackEnabledStates[track]);
|
||||
enabledTrackCount--;
|
||||
trackEnabledStates[track] = false;
|
||||
pendingDiscontinuities[track] = false;
|
||||
if (enabledTrackCount == 0) {
|
||||
downstreamPositionUs = Long.MIN_VALUE;
|
||||
if (loader.isLoading()) {
|
||||
loader.cancelLoading();
|
||||
} else {
|
||||
@ -274,13 +275,13 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
|
||||
positionUs = 0;
|
||||
}
|
||||
|
||||
long currentPositionUs = isPendingReset() ? pendingResetPositionUs : downstreamPositionUs;
|
||||
downstreamPositionUs = positionUs;
|
||||
lastSeekPositionUs = positionUs;
|
||||
if ((isPendingReset() ? pendingResetPositionUs : downstreamPositionUs) == positionUs) {
|
||||
if (currentPositionUs == positionUs) {
|
||||
return;
|
||||
}
|
||||
|
||||
downstreamPositionUs = positionUs;
|
||||
|
||||
// If we're not pending a reset, see if we can seek within the sample queues.
|
||||
boolean seekInsideBuffer = !isPendingReset();
|
||||
for (int i = 0; seekInsideBuffer && i < sampleQueues.size(); i++) {
|
||||
|
@ -193,6 +193,7 @@ public class HlsSampleSource implements SampleSource, SampleSourceReader, Loader
|
||||
if (enabledTrackCount == 1) {
|
||||
seekToUs(positionUs);
|
||||
}
|
||||
pendingDiscontinuities[track] = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -201,8 +202,8 @@ public class HlsSampleSource implements SampleSource, SampleSourceReader, Loader
|
||||
Assertions.checkState(trackEnabledStates[track]);
|
||||
enabledTrackCount--;
|
||||
trackEnabledStates[track] = false;
|
||||
pendingDiscontinuities[track] = false;
|
||||
if (enabledTrackCount == 0) {
|
||||
downstreamPositionUs = Long.MIN_VALUE;
|
||||
if (loadControlRegistered) {
|
||||
loadControl.unregister(this);
|
||||
loadControlRegistered = false;
|
||||
@ -314,8 +315,11 @@ public class HlsSampleSource implements SampleSource, SampleSourceReader, Loader
|
||||
public void seekToUs(long positionUs) {
|
||||
Assertions.checkState(prepared);
|
||||
Assertions.checkState(enabledTrackCount > 0);
|
||||
|
||||
long currentPositionUs = isPendingReset() ? pendingResetPositionUs : downstreamPositionUs;
|
||||
downstreamPositionUs = positionUs;
|
||||
lastSeekPositionUs = positionUs;
|
||||
if ((isPendingReset() ? pendingResetPositionUs : downstreamPositionUs) == positionUs) {
|
||||
if (currentPositionUs == positionUs) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user