mirror of
https://github.com/samsonjs/media.git
synced 2026-04-07 11:35:46 +00:00
Make ExtractorSampleSource constructor consistent.
The allocator and buffering policy (e.g. how large the buffer is) is moving to the top level as part of playlist support, so it no longer makes sense to inject these parameters as args into ExtractorSampleSource's constructor. Instantiating the allocator and buffer size inside of the source is temporary and only until they're moved up. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=123968976
This commit is contained in:
parent
6fd610fc5f
commit
ff745ac444
5 changed files with 38 additions and 105 deletions
|
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
package com.google.android.exoplayer.demo;
|
||||
|
||||
import com.google.android.exoplayer.C;
|
||||
import com.google.android.exoplayer.SampleSource;
|
||||
import com.google.android.exoplayer.SampleSourceProvider;
|
||||
import com.google.android.exoplayer.SimpleExoPlayer;
|
||||
|
|
@ -23,10 +22,7 @@ import com.google.android.exoplayer.dash.DashSampleSource;
|
|||
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
|
||||
import com.google.android.exoplayer.hls.HlsSampleSource;
|
||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingSampleSource;
|
||||
import com.google.android.exoplayer.upstream.Allocator;
|
||||
import com.google.android.exoplayer.upstream.DataSource;
|
||||
import com.google.android.exoplayer.upstream.DataSourceFactory;
|
||||
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
|
||||
import android.net.Uri;
|
||||
|
|
@ -116,10 +112,8 @@ public final class UriSampleSourceProvider implements SampleSourceProvider {
|
|||
return new HlsSampleSource(uri, dataSourceFactory, player.getBandwidthMeter(), handler,
|
||||
eventLogger);
|
||||
case Util.TYPE_OTHER:
|
||||
Allocator allocator = new DefaultAllocator(C.DEFAULT_BUFFER_SEGMENT_SIZE);
|
||||
DataSource dataSource = dataSourceFactory.createDataSource(player.getBandwidthMeter());
|
||||
return new ExtractorSampleSource(uri, dataSource, allocator, C.DEFAULT_MUXED_BUFFER_SIZE,
|
||||
handler, eventLogger, 0, ExtractorSampleSource.newDefaultExtractors());
|
||||
return new ExtractorSampleSource(uri, dataSourceFactory, player.getBandwidthMeter(),
|
||||
ExtractorSampleSource.newDefaultExtractors(), handler, eventLogger, 0);
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported type: " + type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@ import com.google.android.exoplayer.TrackRenderer;
|
|||
import com.google.android.exoplayer.extractor.Extractor;
|
||||
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
|
||||
import com.google.android.exoplayer.extractor.mkv.MatroskaExtractor;
|
||||
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer.upstream.DefaultDataSource;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
import com.google.android.exoplayer.upstream.DefaultDataSourceFactory;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
|
@ -60,9 +58,6 @@ public class FlacPlaybackTest extends InstrumentationTestCase {
|
|||
|
||||
private static class TestPlaybackThread extends Thread implements ExoPlayer.EventListener {
|
||||
|
||||
private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
|
||||
private static final int BUFFER_SEGMENT_COUNT = 16;
|
||||
|
||||
private final Context context;
|
||||
private final Uri uri;
|
||||
|
||||
|
|
@ -84,10 +79,9 @@ public class FlacPlaybackTest extends InstrumentationTestCase {
|
|||
player.addListener(this);
|
||||
ExtractorSampleSource sampleSource = new ExtractorSampleSource(
|
||||
uri,
|
||||
new DefaultDataSource(context, null, Util.getUserAgent(context, "ExoPlayerExtFlacTest"),
|
||||
false),
|
||||
new DefaultAllocator(BUFFER_SEGMENT_SIZE), BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT,
|
||||
new Extractor[] {new MatroskaExtractor()});
|
||||
new DefaultDataSourceFactory(context, "ExoPlayerExtFlacTest"), null,
|
||||
new Extractor[] {new MatroskaExtractor()},
|
||||
null, null, 0);
|
||||
player.setSource(sampleSource);
|
||||
player.setPlayWhenReady(true);
|
||||
Looper.loop();
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@ import com.google.android.exoplayer.TrackRenderer;
|
|||
import com.google.android.exoplayer.extractor.Extractor;
|
||||
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
|
||||
import com.google.android.exoplayer.extractor.mkv.MatroskaExtractor;
|
||||
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer.upstream.DefaultDataSource;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
import com.google.android.exoplayer.upstream.DefaultDataSourceFactory;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
|
@ -60,9 +58,6 @@ public class OpusPlaybackTest extends InstrumentationTestCase {
|
|||
|
||||
private static class TestPlaybackThread extends Thread implements ExoPlayer.EventListener {
|
||||
|
||||
private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
|
||||
private static final int BUFFER_SEGMENT_COUNT = 16;
|
||||
|
||||
private final Context context;
|
||||
private final Uri uri;
|
||||
|
||||
|
|
@ -84,10 +79,9 @@ public class OpusPlaybackTest extends InstrumentationTestCase {
|
|||
player.addListener(this);
|
||||
ExtractorSampleSource sampleSource = new ExtractorSampleSource(
|
||||
uri,
|
||||
new DefaultDataSource(context, null, Util.getUserAgent(context, "ExoPlayerExtOpusTest"),
|
||||
false),
|
||||
new DefaultAllocator(BUFFER_SEGMENT_SIZE), BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT,
|
||||
new Extractor[] {new MatroskaExtractor()});
|
||||
new DefaultDataSourceFactory(context, "ExoPlayerExtOpusTest"), null,
|
||||
new Extractor[] {new MatroskaExtractor()},
|
||||
null, null, 0);
|
||||
player.setSource(sampleSource);
|
||||
player.setPlayWhenReady(true);
|
||||
Looper.loop();
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@ import com.google.android.exoplayer.TrackRenderer;
|
|||
import com.google.android.exoplayer.extractor.Extractor;
|
||||
import com.google.android.exoplayer.extractor.ExtractorSampleSource;
|
||||
import com.google.android.exoplayer.extractor.mkv.MatroskaExtractor;
|
||||
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer.upstream.DefaultDataSource;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
import com.google.android.exoplayer.upstream.DefaultDataSourceFactory;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
|
@ -76,9 +74,6 @@ public class VpxPlaybackTest extends InstrumentationTestCase {
|
|||
|
||||
private static class TestPlaybackThread extends Thread implements ExoPlayer.EventListener {
|
||||
|
||||
private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
|
||||
private static final int BUFFER_SEGMENT_COUNT = 16;
|
||||
|
||||
private final Context context;
|
||||
private final Uri uri;
|
||||
|
||||
|
|
@ -100,10 +95,9 @@ public class VpxPlaybackTest extends InstrumentationTestCase {
|
|||
player.addListener(this);
|
||||
ExtractorSampleSource sampleSource = new ExtractorSampleSource(
|
||||
uri,
|
||||
new DefaultDataSource(context, null, Util.getUserAgent(context, "ExoPlayerExtVP9Test"),
|
||||
false),
|
||||
new DefaultAllocator(BUFFER_SEGMENT_SIZE), BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT,
|
||||
new Extractor[] {new MatroskaExtractor()});
|
||||
new DefaultDataSourceFactory(context, "ExoPlayerExtVp9Test"), null,
|
||||
new Extractor[] {new MatroskaExtractor()},
|
||||
null, null, 0);
|
||||
player.sendMessages(new ExoPlayer.ExoPlayerMessage(videoRenderer,
|
||||
LibvpxVideoTrackRenderer.MSG_SET_OUTPUT_BUFFER_RENDERER,
|
||||
new VpxVideoSurfaceView(context)));
|
||||
|
|
|
|||
|
|
@ -25,8 +25,11 @@ import com.google.android.exoplayer.TrackGroupArray;
|
|||
import com.google.android.exoplayer.TrackSelection;
|
||||
import com.google.android.exoplayer.TrackStream;
|
||||
import com.google.android.exoplayer.upstream.Allocator;
|
||||
import com.google.android.exoplayer.upstream.BandwidthMeter;
|
||||
import com.google.android.exoplayer.upstream.DataSource;
|
||||
import com.google.android.exoplayer.upstream.DataSourceFactory;
|
||||
import com.google.android.exoplayer.upstream.DataSpec;
|
||||
import com.google.android.exoplayer.upstream.DefaultAllocator;
|
||||
import com.google.android.exoplayer.upstream.Loader;
|
||||
import com.google.android.exoplayer.upstream.Loader.Loadable;
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
|
|
@ -112,16 +115,15 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
// Lazily initialized default extractor classes in priority order.
|
||||
private static List<Class<? extends Extractor>> defaultExtractorClasses;
|
||||
|
||||
private final Loader loader;
|
||||
private final ExtractorHolder extractorHolder;
|
||||
private final Allocator allocator;
|
||||
private final int requestedBufferSize;
|
||||
private final int minLoadableRetryCount;
|
||||
private final Uri uri;
|
||||
private final DataSource dataSource;
|
||||
private final int minLoadableRetryCount;
|
||||
private final Handler eventHandler;
|
||||
private final EventListener eventListener;
|
||||
private final int eventSourceId;
|
||||
private final DataSource dataSource;
|
||||
private final Allocator allocator;
|
||||
private final Loader loader;
|
||||
private final ExtractorHolder extractorHolder;
|
||||
|
||||
private volatile boolean tracksBuilt;
|
||||
private volatile SeekMap seekMap;
|
||||
|
|
@ -144,91 +146,46 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
|
||||
/**
|
||||
* @param uri The {@link Uri} of the media stream.
|
||||
* @param dataSource A data source to read the media stream.
|
||||
* @param allocator An {@link Allocator} from which to obtain memory allocations.
|
||||
* @param requestedBufferSize The requested total buffer size for storing sample data, in bytes.
|
||||
* The actual allocated size may exceed the value passed in if the implementation requires it.
|
||||
* @param dataSourceFactory A factory for {@link DataSource}s to read the media.
|
||||
* @param bandwidthMeter A {@link BandwidthMeter} to notify of loads performed by the source.
|
||||
* @param extractors {@link Extractor}s to process the media stream. Where the possible formats
|
||||
* are known, instantiate and inject only instances of the corresponding {@link Extractor}s.
|
||||
* Where this is not possible, {@link #newDefaultExtractors()} can be used to construct an
|
||||
* array of default extractors.
|
||||
*/
|
||||
public ExtractorSampleSource(Uri uri, DataSource dataSource, Allocator allocator,
|
||||
int requestedBufferSize, Extractor[] extractors) {
|
||||
this(uri, dataSource, allocator, requestedBufferSize, MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA,
|
||||
extractors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The {@link Uri} of the media stream.
|
||||
* @param dataSource A data source to read the media stream.
|
||||
* @param allocator An {@link Allocator} from which to obtain memory allocations.
|
||||
* @param requestedBufferSize The requested total buffer size for storing sample data, in bytes.
|
||||
* The actual allocated size may exceed the value passed in if the implementation requires it.
|
||||
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
|
||||
* null if delivery of events is not required.
|
||||
* @param eventListener A listener of events. May be null if delivery of events is not required.
|
||||
* @param eventSourceId An identifier that gets passed to {@code eventListener} methods.
|
||||
* @param extractors {@link Extractor}s to process the media stream. Where the possible formats
|
||||
* are known, instantiate and inject only instances of the corresponding {@link Extractor}s.
|
||||
* Where this is not possible, {@link #newDefaultExtractors()} can be used to construct an
|
||||
* array of default extractors.
|
||||
*/
|
||||
public ExtractorSampleSource(Uri uri, DataSource dataSource, Allocator allocator,
|
||||
int requestedBufferSize, Handler eventHandler, EventListener eventListener,
|
||||
int eventSourceId, Extractor[] extractors) {
|
||||
this(uri, dataSource, allocator, requestedBufferSize, MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA,
|
||||
eventHandler, eventListener, eventSourceId, extractors);
|
||||
public ExtractorSampleSource(Uri uri, DataSourceFactory dataSourceFactory,
|
||||
BandwidthMeter bandwidthMeter, Extractor[] extractors, Handler eventHandler,
|
||||
EventListener eventListener, int eventSourceId) {
|
||||
this(uri, dataSourceFactory, bandwidthMeter, extractors, MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA,
|
||||
eventHandler, eventListener, eventSourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The {@link Uri} of the media stream.
|
||||
* @param dataSource A data source to read the media stream.
|
||||
* @param allocator An {@link Allocator} from which to obtain memory allocations.
|
||||
* @param requestedBufferSize The requested total buffer size for storing sample data, in bytes.
|
||||
* The actual allocated size may exceed the value passed in if the implementation requires it.
|
||||
* @param minLoadableRetryCount The minimum number of times that the sample source will retry
|
||||
* if a loading error occurs.
|
||||
* @param dataSourceFactory A factory for {@link DataSource}s to read the media.
|
||||
* @param bandwidthMeter A {@link BandwidthMeter} to notify of loads performed by the source.
|
||||
* @param extractors {@link Extractor}s to process the media stream. Where the possible formats
|
||||
* are known, instantiate and inject only instances of the corresponding {@link Extractor}s.
|
||||
* Where this is not possible, {@link #newDefaultExtractors()} can be used to construct an
|
||||
* array of default extractors.
|
||||
*/
|
||||
public ExtractorSampleSource(Uri uri, DataSource dataSource, Allocator allocator,
|
||||
int requestedBufferSize, int minLoadableRetryCount, Extractor[] extractors) {
|
||||
this(uri, dataSource, allocator, requestedBufferSize, minLoadableRetryCount, null, null, 0,
|
||||
extractors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The {@link Uri} of the media stream.
|
||||
* @param dataSource A data source to read the media stream.
|
||||
* @param allocator An {@link Allocator} from which to obtain memory allocations.
|
||||
* @param requestedBufferSize The requested total buffer size for storing sample data, in bytes.
|
||||
* The actual allocated size may exceed the value passed in if the implementation requires it.
|
||||
* @param minLoadableRetryCount The minimum number of times that the sample source will retry
|
||||
* if a loading error occurs.
|
||||
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
|
||||
* null if delivery of events is not required.
|
||||
* @param eventListener A listener of events. May be null if delivery of events is not required.
|
||||
* @param eventSourceId An identifier that gets passed to {@code eventListener} methods.
|
||||
* @param extractors {@link Extractor}s to process the media stream. Where the possible formats
|
||||
* are known, instantiate and inject only instances of the corresponding {@link Extractor}s.
|
||||
* Where this is not possible {@link #newDefaultExtractors()} can be used to construct an
|
||||
* array of default extractors.
|
||||
*/
|
||||
public ExtractorSampleSource(Uri uri, DataSource dataSource, Allocator allocator,
|
||||
int requestedBufferSize, int minLoadableRetryCount, Handler eventHandler,
|
||||
EventListener eventListener, int eventSourceId, Extractor[] extractors) {
|
||||
public ExtractorSampleSource(Uri uri, DataSourceFactory dataSourceFactory,
|
||||
BandwidthMeter bandwidthMeter, Extractor[] extractors, int minLoadableRetryCount,
|
||||
Handler eventHandler, EventListener eventListener, int eventSourceId) {
|
||||
Assertions.checkState(extractors != null && extractors.length > 0);
|
||||
this.uri = uri;
|
||||
this.dataSource = dataSource;
|
||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
||||
this.eventListener = eventListener;
|
||||
this.eventHandler = eventHandler;
|
||||
this.eventSourceId = eventSourceId;
|
||||
this.allocator = allocator;
|
||||
this.requestedBufferSize = requestedBufferSize;
|
||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
||||
dataSource = dataSourceFactory.createDataSource(bandwidthMeter);
|
||||
allocator = new DefaultAllocator(C.DEFAULT_BUFFER_SEGMENT_SIZE);
|
||||
loader = new Loader("Loader:ExtractorSampleSource");
|
||||
extractorHolder = new ExtractorHolder(extractors, this);
|
||||
pendingResetPositionUs = C.UNSET_TIME_US;
|
||||
|
|
@ -573,7 +530,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
|
|||
|
||||
private void startLoading() {
|
||||
ExtractingLoadable loadable = new ExtractingLoadable(uri, dataSource, extractorHolder,
|
||||
allocator, requestedBufferSize);
|
||||
allocator, C.DEFAULT_MUXED_BUFFER_SIZE);
|
||||
if (prepared) {
|
||||
Assertions.checkState(isPendingReset());
|
||||
if (durationUs != C.UNSET_TIME_US && pendingResetPositionUs >= durationUs) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue