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