Commit 2469f631 by olly Committed by Oliver Woodman

Restore SampleSource.disable API

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117701759
parent 14c51140
......@@ -613,7 +613,8 @@ import java.util.concurrent.atomic.AtomicInteger;
private void ensureDisabled(TrackRenderer renderer) throws ExoPlaybackException {
ensureStopped(renderer);
if (renderer.getState() == TrackRenderer.STATE_ENABLED) {
renderer.disable();
TrackStream trackStream = renderer.disable();
source.disable(trackStream);
if (renderer == rendererMediaClockSource) {
rendererMediaClock = null;
rendererMediaClockSource = null;
......
......@@ -217,8 +217,10 @@ public final class FrameworkSampleSource implements SampleSource {
}
}
/* package */ void disable(int track) {
@Override
public void disable(TrackStream trackStream) {
Assertions.checkState(prepared);
int track = ((TrackStreamImpl) trackStream).track;
Assertions.checkState(trackStates[track] != TRACK_STATE_DISABLED);
extractor.unselectTrack(track);
trackStates[track] = TRACK_STATE_DISABLED;
......@@ -372,11 +374,6 @@ public final class FrameworkSampleSource implements SampleSource {
return FrameworkSampleSource.this.readData(track, formatHolder, sampleHolder);
}
@Override
public void disable() {
FrameworkSampleSource.this.disable(track);
}
}
}
......@@ -309,7 +309,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
}
@Override
protected void onDisabled() throws ExoPlaybackException {
protected void onDisabled() {
audioSessionId = AudioTrack.SESSION_ID_NOT_SET;
try {
audioTrack.release();
......
......@@ -410,7 +410,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
}
@Override
protected void onDisabled() throws ExoPlaybackException {
protected void onDisabled() {
format = null;
drmInitData = null;
try {
......
......@@ -326,7 +326,7 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
}
@Override
protected void onDisabled() throws ExoPlaybackException {
protected void onDisabled() {
currentWidth = -1;
currentHeight = -1;
currentPixelWidthHeightRatio = -1;
......
......@@ -18,13 +18,15 @@ package com.google.android.exoplayer;
import android.util.Pair;
import java.io.IOException;
import java.util.IdentityHashMap;
/**
* Combines multiple {@link SampleSource} instances.
*/
public class MultiSampleSource implements SampleSource {
public final class MultiSampleSource implements SampleSource {
private final SampleSource[] sources;
private final IdentityHashMap<TrackStream, Integer> trackStreamSourceIndices;
private boolean prepared;
private long durationUs;
......@@ -32,6 +34,7 @@ public class MultiSampleSource implements SampleSource {
public MultiSampleSource(SampleSource... sources) {
this.sources = sources;
trackStreamSourceIndices = new IdentityHashMap<>();
}
@Override
......@@ -74,8 +77,16 @@ public class MultiSampleSource implements SampleSource {
@Override
public TrackStream enable(TrackSelection selection, long positionUs) {
Pair<Integer, Integer> sourceAndGroup = getSourceAndTrackGroupIndices(selection.group);
return sources[sourceAndGroup.first].enable(
TrackStream trackStream = sources[sourceAndGroup.first].enable(
new TrackSelection(sourceAndGroup.second, selection.getTracks()), positionUs);
trackStreamSourceIndices.put(trackStream, sourceAndGroup.first);
return trackStream;
}
@Override
public void disable(TrackStream trackStream) {
int sourceIndex = trackStreamSourceIndices.remove(trackStream);
sources[sourceIndex].disable(trackStream);
}
@Override
......
......@@ -99,6 +99,13 @@ public interface SampleSource {
TrackStream enable(TrackSelection selection, long positionUs);
/**
* Disables a {@link TrackStream} previously obtained from {@link #enable(TrackSelection, long)}.
*
* @param trackStream The {@link TrackStream} to disable.
*/
void disable(TrackStream trackStream);
/**
* Releases the source.
* <p>
* This method should be called when the source is no longer required.
......
......@@ -55,8 +55,7 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
}
@Override
protected void onDisabled() throws ExoPlaybackException {
trackStream.disable();
protected void onDisabled() {
trackStream = null;
}
......
......@@ -169,7 +169,7 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
}
@Override
public void disable() {
public void disable(TrackStream trackStream) {
state = STATE_END_OF_STREAM;
}
......
......@@ -107,6 +107,7 @@ public abstract class TrackRenderer implements ExoPlayerComponent {
private int index;
private int state;
private TrackStream stream;
/**
* Sets the index of this renderer within the player.
......@@ -194,6 +195,7 @@ public abstract class TrackRenderer implements ExoPlayerComponent {
boolean joining) throws ExoPlaybackException {
Assertions.checkState(state == STATE_DISABLED);
state = STATE_ENABLED;
stream = trackStream;
onEnabled(formats, trackStream, positionUs, joining);
}
......@@ -260,23 +262,22 @@ public abstract class TrackRenderer implements ExoPlayerComponent {
/**
* Disable the renderer.
*
* @throws ExoPlaybackException If an error occurs.
*/
/* package */ final void disable() throws ExoPlaybackException {
/* package */ final TrackStream disable() {
Assertions.checkState(state == STATE_ENABLED);
state = STATE_DISABLED;
onDisabled();
TrackStream trackStream = stream;
stream = null;
return trackStream;
}
/**
* Called when the renderer is disabled.
* <p>
* The default implementation is a no-op.
*
* @throws ExoPlaybackException If an error occurs.
*/
protected void onDisabled() throws ExoPlaybackException {
protected void onDisabled() {
// Do nothing.
}
......
......@@ -83,9 +83,4 @@ public interface TrackStream {
*/
int readData(FormatHolder formatHolder, SampleHolder sampleHolder);
/**
* Disables the track.
*/
void disable();
}
......@@ -195,7 +195,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
}
@Override
public void disable() {
public void disable(TrackStream trackStream) {
Assertions.checkState(state == STATE_ENABLED);
Assertions.checkState(--enabledTrackCount == 0);
state = STATE_PREPARED;
......
......@@ -382,8 +382,10 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
return new TrackStreamImpl(track);
}
/* package */ void disable(int track) {
@Override
public void disable(TrackStream trackStream) {
Assertions.checkState(prepared);
int track = ((TrackStreamImpl) trackStream).track;
Assertions.checkState(trackEnabledStates[track]);
enabledTrackCount--;
trackEnabledStates[track] = false;
......@@ -748,11 +750,6 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
return ExtractorSampleSource.this.readData(track, formatHolder, sampleHolder);
}
@Override
public void disable() {
ExtractorSampleSource.this.disable(track);
}
}
/**
......
......@@ -227,8 +227,10 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
return new TrackStreamImpl(group);
}
/* package */ void disable(int group) {
@Override
public void disable(TrackStream trackStream) {
Assertions.checkState(prepared);
int group = ((TrackStreamImpl) trackStream).group;
setTrackGroupEnabledState(group, false);
if (enabledTrackCount == 0) {
chunkSource.reset();
......@@ -837,11 +839,6 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
return HlsSampleSource.this.readData(group, formatHolder, sampleHolder);
}
@Override
public void disable() {
HlsSampleSource.this.disable(group);
}
}
}
......@@ -122,7 +122,7 @@ public final class MetadataTrackRenderer<T> extends SampleSourceTrackRenderer im
}
@Override
protected void onDisabled() throws ExoPlaybackException {
protected void onDisabled() {
pendingMetadata = null;
super.onDisabled();
}
......
......@@ -192,7 +192,7 @@ public final class TextTrackRenderer extends SampleSourceTrackRenderer implement
}
@Override
protected void onDisabled() throws ExoPlaybackException {
protected void onDisabled() {
if (subtitle != null) {
subtitle.release();
subtitle = null;
......
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