use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class CronetDataSourceTest method factory_noFallbackFactoryCronetNotAvailable_delegateDefaultRequestPropertiesToInternalFallbackFactoryAfterCreation.
// Tests deprecated fallback functionality.
@SuppressWarnings("deprecation")
@Test
public void factory_noFallbackFactoryCronetNotAvailable_delegateDefaultRequestPropertiesToInternalFallbackFactoryAfterCreation() throws HttpDataSourceException, InterruptedException {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.enqueue(new MockResponse());
CronetEngineWrapper cronetEngineWrapper = new CronetEngineWrapper((CronetEngine) null);
Map<String, String> defaultRequestProperties = new HashMap<>();
defaultRequestProperties.put("0", "defaultRequestProperty0");
CronetDataSource.Factory factory = new CronetDataSource.Factory(cronetEngineWrapper, executorService);
HttpDataSource dataSourceUnderTest = factory.setDefaultRequestProperties(defaultRequestProperties).createDataSource();
defaultRequestProperties.clear();
defaultRequestProperties.put("1", "defaultRequestPropertyAfterCreation");
factory.setDefaultRequestProperties(defaultRequestProperties);
dataSourceUnderTest.open(new DataSpec.Builder().setUri(mockWebServer.url("/test-path").toString()).build());
Headers headers = mockWebServer.takeRequest(10, SECONDS).getHeaders();
assertThat(headers.get("0")).isNull();
assertThat(headers.get("1")).isEqualTo("defaultRequestPropertyAfterCreation");
assertThat(dataSourceUnderTest).isInstanceOf(DefaultHttpDataSource.class);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class ExtractorAsserts method assertAllBehaviors.
/**
* Asserts that an extractor behaves correctly given valid input data:
*
* <ul>
* <li>Calls {@link Extractor#seek(long, long)} and {@link Extractor#release()} without calling
* {@link Extractor#init(ExtractorOutput)} to check these calls do not fail.
* <li>Calls {@link #assertOutput(Extractor, String, byte[], Context, boolean, boolean, boolean,
* boolean, boolean)} with all possible combinations of "simulate" parameters.
* </ul>
*
* @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
* class which is to be tested.
* @param file The path to the input sample.
* @param dumpFilesPrefix The dump files prefix appended to the dump files path.
* @throws IOException If reading from the input fails.
*/
public static void assertAllBehaviors(ExtractorFactory factory, String file, String dumpFilesPrefix) throws IOException {
// Check behavior prior to initialization.
Extractor extractor = factory.create();
extractor.seek(0, 0);
extractor.release();
// Assert output.
Context context = ApplicationProvider.getApplicationContext();
byte[] fileData = TestUtil.getByteArray(context, file);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, false, false);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, false, true);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, true, false);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, true, true);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, false, false);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, false, true);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, true, false);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, true, true);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, false, false, false, false);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class ExtractorAsserts method assertBehavior.
/**
* Asserts that an extractor consumes valid input data successfully successfully under the
* conditions specified by {@code simulationConfig}.
*
* <p>The output of the extractor is compared against prerecorded dump files.
*
* @param assertionConfig Details of how to read and process the source and dump files.
* @param simulationConfig Details on the environment to simulate and behaviours to assert.
* @throws IOException If reading from the input fails.
*/
public static void assertBehavior(ExtractorFactory factory, String file, AssertionConfig assertionConfig, SimulationConfig simulationConfig) throws IOException {
// Check behavior prior to initialization.
Extractor extractor = factory.create();
extractor.seek(0, 0);
extractor.release();
// Assert output.
Context context = ApplicationProvider.getApplicationContext();
byte[] fileData = TestUtil.getByteArray(context, file);
String dumpFilesPrefix;
if (assertionConfig.dumpFilesPrefix != null) {
dumpFilesPrefix = assertionConfig.dumpFilesPrefix;
} else {
String[] path = file.split("/");
checkState(path.length > 0 && path[0].equals("media"), "AssertionConfig.dumpFilesPrefix == null but file isn't in a media/ sub-directory.\n" + "Expected : 'media/<path-to-file>'\n" + "Found : '" + file + "'\n" + "You need to set AssertionConfig.dumpFilesPrefix explicitly if your media and dump" + " file aren't located in the expected structure (see docs on" + " AssertionConfig.dumpFilesPrefix)");
path[0] = "extractordumps";
dumpFilesPrefix = Joiner.on('/').join(path);
}
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, assertionConfig.deduplicateConsecutiveFormats, simulationConfig.sniffFirst, simulationConfig.simulateIOErrors, simulationConfig.simulateUnknownLength, simulationConfig.simulatePartialReads);
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class TsExtractorTest method customPesReader.
@Test
public void customPesReader() throws Exception {
CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(true, false);
TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_MULTI_PMT, new TimestampAdjuster(0), factory);
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), "media/ts/sample_h262_mpeg_audio.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);
if (readResult == Extractor.RESULT_SEEK) {
input.setPosition((int) seekPositionHolder.position);
}
}
CustomEsReader reader = factory.esReader;
assertThat(reader.packetsRead).isEqualTo(2);
TrackOutput trackOutput = reader.getTrackOutput();
assertThat(trackOutput == output.trackOutputs.get(257)).isTrue();
assertThat(((FakeTrackOutput) trackOutput).lastFormat).isEqualTo(new Format.Builder().setId("1/257").setSampleMimeType("mime").setLanguage("und").build());
}
use of com.google.android.exoplayer2.upstream.DataSource.Factory in project ExoPlayer by google.
the class DownloadManagerDashTest method createDownloadManager.
private void createDownloadManager() {
runOnMainThread(() -> {
Factory fakeDataSourceFactory = new FakeDataSource.Factory().setFakeDataSet(fakeDataSet);
DefaultDownloaderFactory downloaderFactory = new DefaultDownloaderFactory(new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(fakeDataSourceFactory), /* executor= */
Runnable::run);
downloadManager = new DownloadManager(ApplicationProvider.getApplicationContext(), downloadIndex, downloaderFactory);
downloadManager.setRequirements(new Requirements(0));
downloadManagerListener = new TestDownloadManagerListener(downloadManager);
downloadManager.resumeDownloads();
});
}
Aggregations