mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Initialize sample streams in FakeAdaptiveMediaPeriod.
This prevents NPE when release or stop is called before tracks have been selected. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=179911907
This commit is contained in:
parent
ec71c05e8b
commit
7fb296dab9
1 changed files with 13 additions and 5 deletions
|
|
@ -44,13 +44,18 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
||||||
private ChunkSampleStream<FakeChunkSource>[] sampleStreams;
|
private ChunkSampleStream<FakeChunkSource>[] sampleStreams;
|
||||||
private SequenceableLoader sequenceableLoader;
|
private SequenceableLoader sequenceableLoader;
|
||||||
|
|
||||||
public FakeAdaptiveMediaPeriod(TrackGroupArray trackGroupArray, EventDispatcher eventDispatcher,
|
public FakeAdaptiveMediaPeriod(
|
||||||
Allocator allocator, FakeChunkSource.Factory chunkSourceFactory, long durationUs) {
|
TrackGroupArray trackGroupArray,
|
||||||
|
EventDispatcher eventDispatcher,
|
||||||
|
Allocator allocator,
|
||||||
|
FakeChunkSource.Factory chunkSourceFactory,
|
||||||
|
long durationUs) {
|
||||||
super(trackGroupArray);
|
super(trackGroupArray);
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.allocator = allocator;
|
this.allocator = allocator;
|
||||||
this.chunkSourceFactory = chunkSourceFactory;
|
this.chunkSourceFactory = chunkSourceFactory;
|
||||||
this.durationUs = durationUs;
|
this.durationUs = durationUs;
|
||||||
|
this.sampleStreams = newSampleStreamArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -62,13 +67,12 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(Callback callback, long positionUs) {
|
public synchronized void prepare(Callback callback, long positionUs) {
|
||||||
super.prepare(callback, positionUs);
|
super.prepare(callback, positionUs);
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
|
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
|
||||||
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
|
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
|
||||||
long returnPositionUs = super.selectTracks(selections, mayRetainStreamFlags, streams,
|
long returnPositionUs = super.selectTracks(selections, mayRetainStreamFlags, streams,
|
||||||
|
|
@ -79,7 +83,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
||||||
validStreams.add((ChunkSampleStream<FakeChunkSource>) stream);
|
validStreams.add((ChunkSampleStream<FakeChunkSource>) stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.sampleStreams = validStreams.toArray(new ChunkSampleStream[validStreams.size()]);
|
this.sampleStreams = validStreams.toArray(newSampleStreamArray(validStreams.size()));
|
||||||
this.sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
|
this.sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
|
||||||
return returnPositionUs;
|
return returnPositionUs;
|
||||||
}
|
}
|
||||||
|
|
@ -131,4 +135,8 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
||||||
callback.onContinueLoadingRequested(this);
|
callback.onContinueLoadingRequested(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static ChunkSampleStream<FakeChunkSource>[] newSampleStreamArray(int length) {
|
||||||
|
return new ChunkSampleStream[length];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue