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