Call MediaSource prepare/release methods in ExoPlayerImplInternal.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=127436600
This commit is contained in:
parent
2d8b51a709
commit
bc77c3eb82
@ -314,6 +314,7 @@ import java.util.ArrayList;
|
||||
try {
|
||||
resetInternal();
|
||||
this.mediaSource = mediaSource;
|
||||
mediaSource.prepareSource();
|
||||
setState(ExoPlayer.STATE_BUFFERING);
|
||||
handler.sendEmptyMessage(MSG_DO_SOME_WORK);
|
||||
} finally {
|
||||
@ -538,7 +539,10 @@ import java.util.ArrayList;
|
||||
}
|
||||
}
|
||||
enabledRenderers = new Renderer[0];
|
||||
mediaSource = null;
|
||||
if (mediaSource != null) {
|
||||
mediaSource.releaseSource();
|
||||
mediaSource = null;
|
||||
}
|
||||
timeline.reset();
|
||||
loadControl.reset();
|
||||
setIsLoading(false);
|
||||
@ -654,7 +658,7 @@ import java.util.ArrayList;
|
||||
loadingPeriod = newPeriod;
|
||||
long startPositionUs = playingPeriod == null ? playbackInfo.positionUs : 0;
|
||||
setIsLoading(true);
|
||||
loadingPeriod.mediaPeriod.prepare(ExoPlayerImplInternal.this,
|
||||
loadingPeriod.mediaPeriod.preparePeriod(ExoPlayerImplInternal.this,
|
||||
loadControl.getAllocator(), startPositionUs);
|
||||
}
|
||||
}
|
||||
@ -1096,7 +1100,7 @@ import java.util.ArrayList;
|
||||
|
||||
public void release() {
|
||||
try {
|
||||
mediaPeriod.release();
|
||||
mediaPeriod.releasePeriod();
|
||||
} catch (RuntimeException e) {
|
||||
// There's nothing we can do.
|
||||
Log.e(TAG, "Period release failed.", e);
|
||||
|
@ -29,6 +29,13 @@ public final class ConcatenatingMediaSource implements MediaSource {
|
||||
this.mediaSources = mediaSources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource() {
|
||||
for (MediaSource mediaSource : mediaSources) {
|
||||
mediaSource.prepareSource();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPeriodCount() {
|
||||
int sourceCount = 0;
|
||||
@ -55,4 +62,11 @@ public final class ConcatenatingMediaSource implements MediaSource {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
for (MediaSource mediaSource : mediaSources) {
|
||||
mediaSource.releaseSource();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -186,6 +186,11 @@ public final class ExtractorMediaSource implements MediaPeriod, MediaSource,
|
||||
|
||||
// MediaSource implementation.
|
||||
|
||||
@Override
|
||||
public void prepareSource() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPeriodCount() {
|
||||
return 1;
|
||||
@ -197,10 +202,15 @@ public final class ExtractorMediaSource implements MediaPeriod, MediaSource,
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// MediaPeriod implementation.
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback, Allocator allocator, long positionUs) {
|
||||
public void preparePeriod(Callback callback, Allocator allocator, long positionUs) {
|
||||
this.callback = callback;
|
||||
this.allocator = allocator;
|
||||
|
||||
@ -345,7 +355,7 @@ public final class ExtractorMediaSource implements MediaPeriod, MediaSource,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
public void releasePeriod() {
|
||||
dataSource = null;
|
||||
if (loader != null) {
|
||||
final ExtractorHolder extractorHolder = this.extractorHolder;
|
||||
|
@ -55,7 +55,7 @@ public interface MediaPeriod extends SequenceableLoader {
|
||||
* @param allocator An {@link Allocator} from which to obtain media buffer allocations.
|
||||
* @param positionUs The player's current playback position.
|
||||
*/
|
||||
void prepare(Callback callback, Allocator allocator, long positionUs);
|
||||
void preparePeriod(Callback callback, Allocator allocator, long positionUs);
|
||||
|
||||
/**
|
||||
* Throws an error that's preventing the period from becoming prepared. Does nothing if no such
|
||||
@ -149,6 +149,6 @@ public interface MediaPeriod extends SequenceableLoader {
|
||||
* This method should be called when the period is no longer required. It may be called in any
|
||||
* state.
|
||||
*/
|
||||
void release();
|
||||
void releasePeriod();
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,13 @@ public interface MediaSource {
|
||||
*/
|
||||
int UNKNOWN_PERIOD_COUNT = -1;
|
||||
|
||||
/**
|
||||
* Starts preparation of the source.
|
||||
*/
|
||||
void prepareSource();
|
||||
|
||||
// TODO add void maybeThrowError() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the number of periods in the source, or {@link #UNKNOWN_PERIOD_COUNT} if the number
|
||||
* of periods is not yet known.
|
||||
@ -42,4 +49,12 @@ public interface MediaSource {
|
||||
*/
|
||||
MediaPeriod createPeriod(int index);
|
||||
|
||||
/**
|
||||
* Releases the source.
|
||||
* <p>
|
||||
* This method should be called when the source is no longer required. It may be called in any
|
||||
* state.
|
||||
*/
|
||||
void releaseSource();
|
||||
|
||||
}
|
||||
|
@ -52,10 +52,10 @@ public final class MergingMediaPeriod implements MediaPeriod, MediaPeriod.Callba
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback, Allocator allocator, long positionUs) {
|
||||
public void preparePeriod(Callback callback, Allocator allocator, long positionUs) {
|
||||
this.callback = callback;
|
||||
for (MediaPeriod period : periods) {
|
||||
period.prepare(this, allocator, positionUs);
|
||||
period.preparePeriod(this, allocator, positionUs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,9 +157,9 @@ public final class MergingMediaPeriod implements MediaPeriod, MediaPeriod.Callba
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
public void releasePeriod() {
|
||||
for (MediaPeriod period : periods) {
|
||||
period.release();
|
||||
period.releasePeriod();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,12 +36,19 @@ public final class MergingMediaSource implements MediaSource {
|
||||
periodCount = mediaSources[0].getPeriodCount();
|
||||
Assertions.checkState(periodCount != UNKNOWN_PERIOD_COUNT,
|
||||
"Child sources must have known period counts");
|
||||
for (int i = 1; i < mediaSources.length; i++) {
|
||||
Assertions.checkState(mediaSources[i].getPeriodCount() == periodCount,
|
||||
for (MediaSource mediaSource : mediaSources) {
|
||||
Assertions.checkState(mediaSource.getPeriodCount() == periodCount,
|
||||
"Child sources must have equal period counts");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareSource() {
|
||||
for (MediaSource mediaSource : mediaSources) {
|
||||
mediaSource.prepareSource();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPeriodCount() {
|
||||
return periodCount;
|
||||
@ -57,4 +64,11 @@ public final class MergingMediaSource implements MediaSource {
|
||||
return new MergingMediaPeriod(periods);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
for (MediaSource mediaSource : mediaSources) {
|
||||
mediaSource.releaseSource();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -115,6 +115,11 @@ public final class SingleSampleMediaSource implements MediaPeriod, MediaSource,
|
||||
|
||||
// MediaSource implementation.
|
||||
|
||||
@Override
|
||||
public void prepareSource() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPeriodCount() {
|
||||
return 1;
|
||||
@ -126,10 +131,15 @@ public final class SingleSampleMediaSource implements MediaPeriod, MediaSource,
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// MediaPeriod implementation.
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback, Allocator allocator, long positionUs) {
|
||||
public void preparePeriod(Callback callback, Allocator allocator, long positionUs) {
|
||||
loader = new Loader("Loader:SingleSampleMediaSource");
|
||||
callback.onPeriodPrepared(this);
|
||||
}
|
||||
@ -192,7 +202,7 @@ public final class SingleSampleMediaSource implements MediaPeriod, MediaSource,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
public void releasePeriod() {
|
||||
if (loader != null) {
|
||||
loader.release();
|
||||
loader = null;
|
||||
|
@ -96,7 +96,7 @@ import java.util.List;
|
||||
// MediaPeriod implementation.
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback, Allocator allocator, long positionUs) {
|
||||
public void preparePeriod(Callback callback, Allocator allocator, long positionUs) {
|
||||
this.callback = callback;
|
||||
this.allocator = allocator;
|
||||
sampleStreams = newSampleStreamArray(0);
|
||||
@ -188,7 +188,7 @@ import java.util.List;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
public void releasePeriod() {
|
||||
if (sampleStreams != null) {
|
||||
for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
|
||||
sampleStream.release();
|
||||
|
@ -92,14 +92,12 @@ public final class DashMediaSource implements MediaSource {
|
||||
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
|
||||
manifestParser = new MediaPresentationDescriptionParser();
|
||||
manifestCallback = new ManifestCallback();
|
||||
// TODO: Remove this call when prepare() is a part of MediaSource.
|
||||
prepare(dataSourceFactory);
|
||||
}
|
||||
|
||||
// MediaSource implementation.
|
||||
|
||||
// TODO @Override
|
||||
public void prepare(DataSourceFactory dataSourceFactory) {
|
||||
@Override
|
||||
public void prepareSource() {
|
||||
dataSource = dataSourceFactory.createDataSource();
|
||||
loader = new Loader("Loader:DashMediaSource");
|
||||
manifestRefreshHandler = new Handler();
|
||||
@ -122,8 +120,8 @@ public final class DashMediaSource implements MediaSource {
|
||||
return periods[index];
|
||||
}
|
||||
|
||||
// TODO @Override
|
||||
public void release() {
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
dataSource = null;
|
||||
if (loader != null) {
|
||||
loader.release();
|
||||
|
@ -112,6 +112,11 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
||||
|
||||
// MediaSource implementation.
|
||||
|
||||
@Override
|
||||
public void prepareSource() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPeriodCount() {
|
||||
return 1;
|
||||
@ -123,10 +128,15 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// MediaPeriod implementation.
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback, Allocator allocator, long positionUs) {
|
||||
public void preparePeriod(Callback callback, Allocator allocator, long positionUs) {
|
||||
this.callback = callback;
|
||||
this.allocator = allocator;
|
||||
preparePositionUs = positionUs;
|
||||
@ -228,7 +238,7 @@ public final class HlsMediaSource implements MediaPeriod, MediaSource,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
public void releasePeriod() {
|
||||
sampleStreamSources.clear();
|
||||
timestampAdjusterProvider.reset();
|
||||
manifestDataSource = null;
|
||||
|
@ -112,6 +112,11 @@ public final class SmoothStreamingMediaSource implements MediaPeriod, MediaSourc
|
||||
|
||||
// MediaSource implementation.
|
||||
|
||||
@Override
|
||||
public void prepareSource() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPeriodCount() {
|
||||
return 1;
|
||||
@ -123,10 +128,15 @@ public final class SmoothStreamingMediaSource implements MediaPeriod, MediaSourc
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// MediaPeriod implementation.
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback, Allocator allocator, long positionUs) {
|
||||
public void preparePeriod(Callback callback, Allocator allocator, long positionUs) {
|
||||
this.callback = callback;
|
||||
this.allocator = allocator;
|
||||
sampleStreams = newSampleStreamArray(0);
|
||||
@ -218,7 +228,7 @@ public final class SmoothStreamingMediaSource implements MediaPeriod, MediaSourc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
public void releasePeriod() {
|
||||
manifestDataSource = null;
|
||||
if (manifestLoader != null) {
|
||||
manifestLoader.release();
|
||||
|
Loading…
x
Reference in New Issue
Block a user