Commit 4a62b268 by andrewlewis Committed by Oliver Woodman

Post onPrepared so it runs after createPeriod has finished.

Issue: #1853

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=134409897
parent 85b61adb
...@@ -55,9 +55,9 @@ public interface MediaSource { ...@@ -55,9 +55,9 @@ public interface MediaSource {
/** /**
* Returns a {@link MediaPeriod} corresponding to the period at the specified index. * Returns a {@link MediaPeriod} corresponding to the period at the specified index.
* <p> * <p>
* {@link Callback#onPrepared(MediaPeriod)} is called when the new period is prepared. If * {@link Callback#onPrepared(MediaPeriod)} is called after this method has returned, when the new
* preparation fails, {@link MediaPeriod#maybeThrowPrepareError()} will throw an * period is prepared. If preparation fails, {@link MediaPeriod#maybeThrowPrepareError()} will
* {@link IOException} if called on the returned instance. * throw an {@link IOException} if called on the returned instance.
* *
* @param index The index of the period. * @param index The index of the period.
* @param callback A callback to receive updates from the period. * @param callback A callback to receive updates from the period.
......
...@@ -19,7 +19,6 @@ import android.support.annotation.IntDef; ...@@ -19,7 +19,6 @@ import android.support.annotation.IntDef;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaPeriod.Callback; import com.google.android.exoplayer2.source.MediaPeriod.Callback;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -125,7 +124,6 @@ public final class MergingMediaSource implements MediaSource { ...@@ -125,7 +124,6 @@ public final class MergingMediaSource implements MediaSource {
MergingMediaPeriod mergingPeriod = new MergingMediaPeriod(callback, periods); MergingMediaPeriod mergingPeriod = new MergingMediaPeriod(callback, periods);
for (int i = 0; i < periods.length; i++) { for (int i = 0; i < periods.length; i++) {
periods[i] = mediaSources[i].createPeriod(index, mergingPeriod, allocator, positionUs); periods[i] = mediaSources[i].createPeriod(index, mergingPeriod, allocator, positionUs);
Assertions.checkState(periods[i] != null, "Child source must not return null period");
} }
return mergingPeriod; return mergingPeriod;
} }
......
...@@ -51,6 +51,7 @@ import java.util.Arrays; ...@@ -51,6 +51,7 @@ import java.util.Arrays;
private final int eventSourceId; private final int eventSourceId;
private final TrackGroupArray tracks; private final TrackGroupArray tracks;
private final ArrayList<SampleStreamImpl> sampleStreams; private final ArrayList<SampleStreamImpl> sampleStreams;
private final Handler handler;
/* package */ final Loader loader; /* package */ final Loader loader;
/* package */ final Format format; /* package */ final Format format;
...@@ -60,7 +61,7 @@ import java.util.Arrays; ...@@ -60,7 +61,7 @@ import java.util.Arrays;
public SingleSampleMediaPeriod(Uri uri, DataSource.Factory dataSourceFactory, Format format, public SingleSampleMediaPeriod(Uri uri, DataSource.Factory dataSourceFactory, Format format,
int minLoadableRetryCount, Handler eventHandler, EventListener eventListener, int minLoadableRetryCount, Handler eventHandler, EventListener eventListener,
int eventSourceId) { int eventSourceId, final Callback callback) {
this.uri = uri; this.uri = uri;
this.dataSourceFactory = dataSourceFactory; this.dataSourceFactory = dataSourceFactory;
this.format = format; this.format = format;
...@@ -70,12 +71,20 @@ import java.util.Arrays; ...@@ -70,12 +71,20 @@ import java.util.Arrays;
this.eventSourceId = eventSourceId; this.eventSourceId = eventSourceId;
tracks = new TrackGroupArray(new TrackGroup(format)); tracks = new TrackGroupArray(new TrackGroup(format));
sampleStreams = new ArrayList<>(); sampleStreams = new ArrayList<>();
handler = new Handler();
loader = new Loader("Loader:SingleSampleMediaPeriod"); loader = new Loader("Loader:SingleSampleMediaPeriod");
sampleData = new byte[INITIAL_SAMPLE_SIZE]; sampleData = new byte[INITIAL_SAMPLE_SIZE];
handler.post(new Runnable() {
@Override
public void run() {
callback.onPrepared(SingleSampleMediaPeriod.this);
}
});
} }
public void release() { public void release() {
loader.release(); loader.release();
handler.removeCallbacksAndMessages(null);
} }
@Override @Override
......
...@@ -98,10 +98,8 @@ public final class SingleSampleMediaSource implements MediaSource { ...@@ -98,10 +98,8 @@ public final class SingleSampleMediaSource implements MediaSource {
public MediaPeriod createPeriod(int index, Callback callback, Allocator allocator, public MediaPeriod createPeriod(int index, Callback callback, Allocator allocator,
long positionUs) { long positionUs) {
Assertions.checkArgument(index == 0); Assertions.checkArgument(index == 0);
MediaPeriod mediaPeriod = new SingleSampleMediaPeriod(uri, dataSourceFactory, format, return new SingleSampleMediaPeriod(uri, dataSourceFactory, format, minLoadableRetryCount,
minLoadableRetryCount, eventHandler, eventListener, eventSourceId); eventHandler, eventListener, eventSourceId, callback);
callback.onPrepared(mediaPeriod);
return mediaPeriod;
} }
@Override @Override
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.source.dash; package com.google.android.exoplayer2.source.dash;
import android.os.Handler;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher; import com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher;
...@@ -51,6 +52,7 @@ import java.util.List; ...@@ -51,6 +52,7 @@ import java.util.List;
private final Callback callback; private final Callback callback;
private final Allocator allocator; private final Allocator allocator;
private final TrackGroupArray trackGroups; private final TrackGroupArray trackGroups;
private final Handler handler;
private ChunkSampleStream<DashChunkSource>[] sampleStreams; private ChunkSampleStream<DashChunkSource>[] sampleStreams;
private CompositeSequenceableLoader sequenceableLoader; private CompositeSequenceableLoader sequenceableLoader;
...@@ -76,7 +78,13 @@ import java.util.List; ...@@ -76,7 +78,13 @@ import java.util.List;
sequenceableLoader = new CompositeSequenceableLoader(sampleStreams); sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
period = manifest.getPeriod(index); period = manifest.getPeriod(index);
trackGroups = buildTrackGroups(period); trackGroups = buildTrackGroups(period);
callback.onPrepared(this); handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
DashMediaPeriod.this.callback.onPrepared(DashMediaPeriod.this);
}
});
} }
public void updateManifest(DashManifest manifest, int index) { public void updateManifest(DashManifest manifest, int index) {
...@@ -95,6 +103,7 @@ import java.util.List; ...@@ -95,6 +103,7 @@ import java.util.List;
for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) { for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
sampleStream.release(); sampleStream.release();
} }
handler.removeCallbacksAndMessages(null);
} }
@Override @Override
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.source.smoothstreaming; package com.google.android.exoplayer2.source.smoothstreaming;
import android.os.Handler;
import android.util.Base64; import android.util.Base64;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.mp4.TrackEncryptionBox; import com.google.android.exoplayer2.extractor.mp4.TrackEncryptionBox;
...@@ -50,6 +51,7 @@ import java.util.ArrayList; ...@@ -50,6 +51,7 @@ import java.util.ArrayList;
private final Allocator allocator; private final Allocator allocator;
private final TrackGroupArray trackGroups; private final TrackGroupArray trackGroups;
private final TrackEncryptionBox[] trackEncryptionBoxes; private final TrackEncryptionBox[] trackEncryptionBoxes;
private final Handler handler;
private SsManifest manifest; private SsManifest manifest;
private ChunkSampleStream<SsChunkSource>[] sampleStreams; private ChunkSampleStream<SsChunkSource>[] sampleStreams;
...@@ -74,10 +76,16 @@ import java.util.ArrayList; ...@@ -74,10 +76,16 @@ import java.util.ArrayList;
} else { } else {
trackEncryptionBoxes = null; trackEncryptionBoxes = null;
} }
handler = new Handler();
this.manifest = manifest; this.manifest = manifest;
sampleStreams = newSampleStreamArray(0); sampleStreams = newSampleStreamArray(0);
sequenceableLoader = new CompositeSequenceableLoader(sampleStreams); sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
callback.onPrepared(this); handler.post(new Runnable() {
@Override
public void run() {
SsMediaPeriod.this.callback.onPrepared(SsMediaPeriod.this);
}
});
} }
public void updateManifest(SsManifest manifest) { public void updateManifest(SsManifest manifest) {
...@@ -92,6 +100,7 @@ import java.util.ArrayList; ...@@ -92,6 +100,7 @@ import java.util.ArrayList;
for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) { for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
sampleStream.release(); sampleStream.release();
} }
handler.removeCallbacksAndMessages(null);
} }
@Override @Override
......
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