use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class HlsDownloaderTest method createWithDefaultDownloaderFactory.
@Test
public void createWithDefaultDownloaderFactory() {
CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(Mockito.mock(Cache.class)).setUpstreamDataSourceFactory(DummyDataSource.FACTORY);
DownloaderFactory factory = new DefaultDownloaderFactory(cacheDataSourceFactory, /* executor= */
Runnable::run);
Downloader downloader = factory.createDownloader(new DownloadRequest.Builder(/* id= */
"id", Uri.parse("https://www.test.com/download")).setMimeType(MimeTypes.APPLICATION_M3U8).setStreamKeys(Collections.singletonList(new StreamKey(/* groupIndex= */
0, /* trackIndex= */
0))).build());
assertThat(downloader).isInstanceOf(HlsDownloader.class);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class MediaPeriodAsserts method assertGetStreamKeysAndManifestFilterIntegration.
/**
* Asserts that the values returns by {@link MediaPeriod#getStreamKeys(List)} are compatible with
* a {@link FilterableManifest} using these stream keys.
*
* @param mediaPeriodFactory A factory to create a {@link MediaPeriod} based on a manifest.
* @param manifest The manifest which is to be tested.
* @param periodIndex The index of period in the manifest.
* @param ignoredMimeType Optional mime type whose existence in the filtered track groups is not
* asserted.
*/
public static <T extends FilterableManifest<T>> void assertGetStreamKeysAndManifestFilterIntegration(FilterableManifestMediaPeriodFactory<T> mediaPeriodFactory, T manifest, int periodIndex, @Nullable String ignoredMimeType) {
MediaPeriod mediaPeriod = mediaPeriodFactory.createMediaPeriod(manifest, periodIndex);
TrackGroupArray trackGroupArray = prepareAndGetTrackGroups(mediaPeriod);
// Create test vector of query test selections:
// - One selection with one track per group, two tracks or all tracks.
// - Two selections with tracks from multiple groups, or tracks from a single group.
// - Multiple selections with tracks from all groups.
List<List<ExoTrackSelection>> testSelections = new ArrayList<>();
for (int i = 0; i < trackGroupArray.length; i++) {
TrackGroup trackGroup = trackGroupArray.get(i);
for (int j = 0; j < trackGroup.length; j++) {
testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, j)));
}
if (trackGroup.length > 1) {
testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, 0, 1)));
testSelections.add(Arrays.asList(new ExoTrackSelection[] { new TestTrackSelection(trackGroup, 0), new TestTrackSelection(trackGroup, 1) }));
}
if (trackGroup.length > 2) {
int[] allTracks = new int[trackGroup.length];
for (int j = 0; j < trackGroup.length; j++) {
allTracks[j] = j;
}
testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, allTracks)));
}
}
if (trackGroupArray.length > 1) {
for (int i = 0; i < trackGroupArray.length - 1; i++) {
for (int j = i + 1; j < trackGroupArray.length; j++) {
testSelections.add(Arrays.asList(new ExoTrackSelection[] { new TestTrackSelection(trackGroupArray.get(i), 0), new TestTrackSelection(trackGroupArray.get(j), 0) }));
}
}
}
if (trackGroupArray.length > 2) {
List<ExoTrackSelection> selectionsFromAllGroups = new ArrayList<>();
for (int i = 0; i < trackGroupArray.length; i++) {
selectionsFromAllGroups.add(new TestTrackSelection(trackGroupArray.get(i), 0));
}
testSelections.add(selectionsFromAllGroups);
}
// contain at least all requested formats.
for (List<ExoTrackSelection> testSelection : testSelections) {
List<StreamKey> streamKeys = mediaPeriod.getStreamKeys(testSelection);
if (streamKeys.isEmpty()) {
// Manifests won't be filtered if stream key is empty.
continue;
}
T filteredManifest = manifest.copy(streamKeys);
// The filtered manifest should only have one period left.
MediaPeriod filteredMediaPeriod = mediaPeriodFactory.createMediaPeriod(filteredManifest, /* periodIndex= */
0);
TrackGroupArray filteredTrackGroupArray = prepareAndGetTrackGroups(filteredMediaPeriod);
for (ExoTrackSelection trackSelection : testSelection) {
if (ignoredMimeType != null && ignoredMimeType.equals(trackSelection.getFormat(0).sampleMimeType)) {
continue;
}
Format[] expectedFormats = new Format[trackSelection.length()];
for (int k = 0; k < trackSelection.length(); k++) {
expectedFormats[k] = trackSelection.getFormat(k);
}
assertOneTrackGroupContainsFormats(filteredTrackGroupArray, expectedFormats);
}
}
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class TrackSelectionHelper method setOverride.
private void setOverride(int group, int[] tracks, boolean enableRandomAdaptation) {
TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveTrackSelectionFactory);
override = new SelectionOverride(factory, group, tracks);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class TsExtractorTest method testCustomPesReader.
public void testCustomPesReader() throws Exception {
CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(true, false);
TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_NORMAL, new TimestampAdjuster(0), factory);
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
FakeExtractorOutput output = new FakeExtractorOutput();
tsExtractor.init(output);
PositionHolder seekPositionHolder = new PositionHolder();
int readResult = Extractor.RESULT_CONTINUE;
while (readResult != Extractor.RESULT_END_OF_INPUT) {
readResult = tsExtractor.read(input, seekPositionHolder);
}
CustomEsReader reader = factory.esReader;
assertEquals(2, reader.packetsRead);
TrackOutput trackOutput = reader.getTrackOutput();
assertTrue(trackOutput == output.trackOutputs.get(257));
assertEquals(Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0), ((FakeTrackOutput) trackOutput).format);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project react-native-track-player by react-native-kit.
the class ExoPlayback method load.
@Override
public void load(Track track, Promise callback) {
loadCallback = callback;
Uri url = track.url;
String userAgent = Util.getUserAgent(context, "react-native-track-player");
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, null, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
DataSource.Factory factory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory);
MediaSource source;
if (cacheMaxSize > 0 && !track.urlLocal) {
File cacheDir = new File(context.getCacheDir(), "TrackPlayer");
Cache cache = new SimpleCache(cacheDir, new LeastRecentlyUsedCacheEvictor(cacheMaxSize));
factory = new CacheDataSourceFactory(cache, factory, 0, cacheMaxSize);
}
if (track.type == TrackType.DASH) {
source = new DashMediaSource(url, factory, new DefaultDashChunkSource.Factory(factory), null, null);
} else if (track.type == TrackType.HLS) {
source = new HlsMediaSource(url, factory, null, null);
} else if (track.type == TrackType.SMOOTH_STREAMING) {
source = new SsMediaSource(url, factory, new DefaultSsChunkSource.Factory(factory), null, null);
} else {
source = new ExtractorMediaSource(url, factory, new DefaultExtractorsFactory(), null, null);
}
player.prepare(source);
}
Aggregations