use of androidx.media3.datasource.DataSource.Factory in project media by androidx.
the class DownloadHelper method getRendererCapabilities.
/**
* Extracts renderer capabilities for the renderers created by the provided renderers factory.
*
* @param renderersFactory A {@link RenderersFactory}.
* @return The {@link RendererCapabilities} for each renderer created by the {@code
* renderersFactory}.
*/
public static RendererCapabilities[] getRendererCapabilities(RenderersFactory renderersFactory) {
Renderer[] renderers = renderersFactory.createRenderers(Util.createHandlerForCurrentOrMainLooper(), new VideoRendererEventListener() {
}, new AudioRendererEventListener() {
}, (cues) -> {
}, (metadata) -> {
});
RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
for (int i = 0; i < renderers.length; i++) {
capabilities[i] = renderers[i].getCapabilities();
}
return capabilities;
}
use of androidx.media3.datasource.DataSource.Factory in project media by androidx.
the class DefaultMediaSourceFactory method createMediaSource.
@UnstableApi
@Override
public MediaSource createMediaSource(MediaItem mediaItem) {
Assertions.checkNotNull(mediaItem.localConfiguration);
@Nullable String scheme = mediaItem.localConfiguration.uri.getScheme();
if (scheme != null && scheme.equals(C.SSAI_SCHEME)) {
return checkNotNull(serverSideAdInsertionMediaSourceFactory).createMediaSource(mediaItem);
}
@C.ContentType int type = Util.inferContentTypeForUriAndMimeType(mediaItem.localConfiguration.uri, mediaItem.localConfiguration.mimeType);
@Nullable MediaSource.Factory mediaSourceFactory = delegateFactoryLoader.getMediaSourceFactory(type);
checkStateNotNull(mediaSourceFactory, "No suitable media source factory found for content type: " + type);
MediaItem.LiveConfiguration.Builder liveConfigurationBuilder = mediaItem.liveConfiguration.buildUpon();
if (mediaItem.liveConfiguration.targetOffsetMs == C.TIME_UNSET) {
liveConfigurationBuilder.setTargetOffsetMs(liveTargetOffsetMs);
}
if (mediaItem.liveConfiguration.minPlaybackSpeed == C.RATE_UNSET) {
liveConfigurationBuilder.setMinPlaybackSpeed(liveMinSpeed);
}
if (mediaItem.liveConfiguration.maxPlaybackSpeed == C.RATE_UNSET) {
liveConfigurationBuilder.setMaxPlaybackSpeed(liveMaxSpeed);
}
if (mediaItem.liveConfiguration.minOffsetMs == C.TIME_UNSET) {
liveConfigurationBuilder.setMinOffsetMs(liveMinOffsetMs);
}
if (mediaItem.liveConfiguration.maxOffsetMs == C.TIME_UNSET) {
liveConfigurationBuilder.setMaxOffsetMs(liveMaxOffsetMs);
}
MediaItem.LiveConfiguration liveConfiguration = liveConfigurationBuilder.build();
// Make sure to retain the very same media item instance, if no value needs to be overridden.
if (!liveConfiguration.equals(mediaItem.liveConfiguration)) {
mediaItem = mediaItem.buildUpon().setLiveConfiguration(liveConfiguration).build();
}
MediaSource mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
List<MediaItem.SubtitleConfiguration> subtitleConfigurations = castNonNull(mediaItem.localConfiguration).subtitleConfigurations;
if (!subtitleConfigurations.isEmpty()) {
MediaSource[] mediaSources = new MediaSource[subtitleConfigurations.size() + 1];
mediaSources[0] = mediaSource;
for (int i = 0; i < subtitleConfigurations.size(); i++) {
if (useProgressiveMediaSourceForSubtitles) {
Format format = new Format.Builder().setSampleMimeType(subtitleConfigurations.get(i).mimeType).setLanguage(subtitleConfigurations.get(i).language).setSelectionFlags(subtitleConfigurations.get(i).selectionFlags).setRoleFlags(subtitleConfigurations.get(i).roleFlags).setLabel(subtitleConfigurations.get(i).label).setId(subtitleConfigurations.get(i).id).build();
ExtractorsFactory extractorsFactory = () -> new Extractor[] { SubtitleDecoderFactory.DEFAULT.supportsFormat(format) ? new SubtitleExtractor(SubtitleDecoderFactory.DEFAULT.createDecoder(format), format) : new UnknownSubtitlesExtractor(format) };
mediaSources[i + 1] = new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(MediaItem.fromUri(subtitleConfigurations.get(i).uri.toString()));
} else {
mediaSources[i + 1] = new SingleSampleMediaSource.Factory(dataSourceFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(subtitleConfigurations.get(i), /* durationUs= */
C.TIME_UNSET);
}
}
mediaSource = new MergingMediaSource(mediaSources);
}
return maybeWrapWithAdsMediaSource(mediaItem, maybeClipMediaSource(mediaItem, mediaSource));
}
use of androidx.media3.datasource.DataSource.Factory in project media by androidx.
the class DashMediaSourceTest method replaceManifestUri_doesNotChangeMediaItem.
@Test
public void replaceManifestUri_doesNotChangeMediaItem() {
DashMediaSource.Factory factory = new DashMediaSource.Factory(new FileDataSource.Factory());
MediaItem mediaItem = MediaItem.fromUri("http://www.google.com");
DashMediaSource mediaSource = factory.createMediaSource(mediaItem);
mediaSource.replaceManifestUri(Uri.EMPTY);
assertThat(mediaSource.getMediaItem()).isEqualTo(mediaItem);
}
use of androidx.media3.datasource.DataSource.Factory in project media by androidx.
the class DashDownloaderTest method progressiveDownloadSeparatePeriods.
@Test
public void progressiveDownloadSeparatePeriods() throws Exception {
FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("period_2_segment_1", 1).setRandomData("period_2_segment_2", 2).setRandomData("period_2_segment_3", 3);
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
FakeDataSource.Factory factory = mock(FakeDataSource.Factory.class);
when(factory.createDataSource()).thenReturn(fakeDataSource);
DashDownloader dashDownloader = getDashDownloader(factory, new StreamKey(0, 0, 0), new StreamKey(1, 0, 0));
dashDownloader.download(progressListener);
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
assertThat(openedDataSpecs.length).isEqualTo(8);
assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("audio_segment_2");
assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_3");
assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("period_2_segment_1");
assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("period_2_segment_2");
assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("period_2_segment_3");
}
use of androidx.media3.datasource.DataSource.Factory in project media by androidx.
the class DashDownloaderTest method progressiveDownload.
@Test
public void progressiveDownload() throws Exception {
FakeDataSet fakeDataSet = new FakeDataSet().setData(TEST_MPD_URI, TEST_MPD).setRandomData("audio_init_data", 10).setRandomData("audio_segment_1", 4).setRandomData("audio_segment_2", 5).setRandomData("audio_segment_3", 6).setRandomData("text_segment_1", 1).setRandomData("text_segment_2", 2).setRandomData("text_segment_3", 3);
FakeDataSource fakeDataSource = new FakeDataSource(fakeDataSet);
FakeDataSource.Factory factory = mock(FakeDataSource.Factory.class);
when(factory.createDataSource()).thenReturn(fakeDataSource);
DashDownloader dashDownloader = getDashDownloader(factory, new StreamKey(0, 0, 0), new StreamKey(0, 1, 0));
dashDownloader.download(progressListener);
DataSpec[] openedDataSpecs = fakeDataSource.getAndClearOpenedDataSpecs();
assertThat(openedDataSpecs.length).isEqualTo(8);
assertThat(openedDataSpecs[0].uri).isEqualTo(TEST_MPD_URI);
assertThat(openedDataSpecs[1].uri.getPath()).isEqualTo("audio_init_data");
assertThat(openedDataSpecs[2].uri.getPath()).isEqualTo("audio_segment_1");
assertThat(openedDataSpecs[3].uri.getPath()).isEqualTo("text_segment_1");
assertThat(openedDataSpecs[4].uri.getPath()).isEqualTo("audio_segment_2");
assertThat(openedDataSpecs[5].uri.getPath()).isEqualTo("text_segment_2");
assertThat(openedDataSpecs[6].uri.getPath()).isEqualTo("audio_segment_3");
assertThat(openedDataSpecs[7].uri.getPath()).isEqualTo("text_segment_3");
}
Aggregations