From 8f17ab84f8132d3fda8f407164b789b6dbe41144 Mon Sep 17 00:00:00 2001 From: dancho Date: Tue, 14 Jan 2025 07:24:00 -0800 Subject: [PATCH] Add API for sample dependency reading to DefaultMediaSourceFactory PiperOrigin-RevId: 715372196 --- .../source/DefaultMediaSourceFactory.java | 20 +++++++++++++++++ .../media3/exoplayer/source/MediaSource.java | 22 +++++++++++++++++++ .../exoplayer/dash/DashChunkSource.java | 20 +++++++++++++++++ .../exoplayer/dash/DashMediaSource.java | 9 ++++++++ .../dash/DefaultDashChunkSource.java | 9 ++++++++ 5 files changed, 80 insertions(+) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/DefaultMediaSourceFactory.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/DefaultMediaSourceFactory.java index 1902a98e64..b56f6d8a93 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/DefaultMediaSourceFactory.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/DefaultMediaSourceFactory.java @@ -211,6 +211,16 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { return this; } + @CanIgnoreReturnValue + @Override + @UnstableApi + public DefaultMediaSourceFactory experimentalSetCodecsToParseWithinGopSampleDependencies( + @C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies) { + delegateFactoryLoader.setCodecsToParseWithinGopSampleDependencies( + codecsToParseWithinGopSampleDependencies); + return this; + } + /** * Sets the {@link AdsLoader.Provider} that provides {@link AdsLoader} instances for media items * that have {@link MediaItem.LocalConfiguration#adsConfiguration ads configurations}. @@ -625,6 +635,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { private DataSource.@MonotonicNonNull Factory dataSourceFactory; private boolean parseSubtitlesDuringExtraction; private SubtitleParser.Factory subtitleParserFactory; + private @C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies; @Nullable private CmcdConfiguration.Factory cmcdConfigurationFactory; @Nullable private DrmSessionManagerProvider drmSessionManagerProvider; @Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy; @@ -664,6 +675,8 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { } mediaSourceFactory.setSubtitleParserFactory(subtitleParserFactory); mediaSourceFactory.experimentalParseSubtitlesDuringExtraction(parseSubtitlesDuringExtraction); + mediaSourceFactory.experimentalSetCodecsToParseWithinGopSampleDependencies( + codecsToParseWithinGopSampleDependencies); mediaSourceFactories.put(contentType, mediaSourceFactory); return mediaSourceFactory; } @@ -695,6 +708,13 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { } } + public void setCodecsToParseWithinGopSampleDependencies( + @C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies) { + this.codecsToParseWithinGopSampleDependencies = codecsToParseWithinGopSampleDependencies; + extractorsFactory.experimentalSetCodecsToParseWithinGopSampleDependencies( + codecsToParseWithinGopSampleDependencies); + } + public void setCmcdConfigurationFactory(CmcdConfiguration.Factory cmcdConfigurationFactory) { this.cmcdConfigurationFactory = cmcdConfigurationFactory; for (MediaSource.Factory mediaSourceFactory : mediaSourceFactories.values()) { diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/MediaSource.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/MediaSource.java index 6bf749d83a..f099bc01d6 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/MediaSource.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/MediaSource.java @@ -30,7 +30,9 @@ import androidx.media3.exoplayer.drm.DrmSessionManagerProvider; import androidx.media3.exoplayer.upstream.Allocator; import androidx.media3.exoplayer.upstream.CmcdConfiguration; import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy; +import androidx.media3.extractor.mp4.Mp4Extractor; import androidx.media3.extractor.text.SubtitleParser; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; /** @@ -131,6 +133,26 @@ public interface MediaSource { return this; } + /** + * Sets the set of video codecs for which within GOP sample dependency information should be + * parsed as part of extraction. Defaults to {@code 0} - empty set of codecs. + * + *

Having access to additional sample dependency information can speed up seeking. See {@link + * Mp4Extractor#FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES}. + * + *

This method is experimental and will be renamed or removed in a future release. + * + * @param codecsToParseWithinGopSampleDependencies The set of codecs for which to parse within + * GOP sample dependency information. + * @return This factory, for convenience. + */ + @UnstableApi + @CanIgnoreReturnValue + default Factory experimentalSetCodecsToParseWithinGopSampleDependencies( + @C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies) { + return this; + } + /** * Returns the {@link C.ContentType content types} supported by media sources created by this * factory. diff --git a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashChunkSource.java b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashChunkSource.java index 7f48712dfa..8a74ee10a0 100644 --- a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashChunkSource.java +++ b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashChunkSource.java @@ -30,6 +30,7 @@ import androidx.media3.exoplayer.trackselection.ExoTrackSelection; import androidx.media3.exoplayer.upstream.CmcdConfiguration; import androidx.media3.exoplayer.upstream.LoaderErrorThrower; import androidx.media3.extractor.Extractor; +import androidx.media3.extractor.mp4.Mp4Extractor; import androidx.media3.extractor.text.SubtitleParser; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.List; @@ -71,6 +72,25 @@ public interface DashChunkSource extends ChunkSource { return this; } + /** + * Sets the set of video codecs for which within GOP sample dependency information should be + * parsed as part of extraction. Defaults to {@code 0} - empty set of codecs. + * + *

Having access to additional sample dependency information can speed up seeking. See {@link + * Mp4Extractor#FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES}. + * + *

This method is experimental and will be renamed or removed in a future release. + * + * @param codecsToParseWithinGopSampleDependencies The set of codecs for which to parse within + * GOP sample dependency information. + * @return This factory, for convenience. + */ + @CanIgnoreReturnValue + default Factory experimentalSetCodecsToParseWithinGopSampleDependencies( + @C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies) { + return this; + } + /** * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests. * @param manifest The initial manifest. diff --git a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java index fc5370e08d..3eef6f26a4 100644 --- a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java +++ b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaSource.java @@ -217,6 +217,15 @@ public final class DashMediaSource extends BaseMediaSource { return this; } + @Override + @CanIgnoreReturnValue + public Factory experimentalSetCodecsToParseWithinGopSampleDependencies( + @C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies) { + chunkSourceFactory.experimentalSetCodecsToParseWithinGopSampleDependencies( + codecsToParseWithinGopSampleDependencies); + return this; + } + /** * Sets the target {@link Player#getCurrentLiveOffset() offset for live streams} that is used if * no value is defined in the {@link MediaItem} or the manifest. diff --git a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DefaultDashChunkSource.java b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DefaultDashChunkSource.java index dea952c404..a38c2f5c12 100644 --- a/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DefaultDashChunkSource.java +++ b/libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DefaultDashChunkSource.java @@ -130,6 +130,15 @@ public class DefaultDashChunkSource implements DashChunkSource { return this; } + @CanIgnoreReturnValue + @Override + public Factory experimentalSetCodecsToParseWithinGopSampleDependencies( + @C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies) { + chunkExtractorFactory.experimentalSetCodecsToParseWithinGopSampleDependencies( + codecsToParseWithinGopSampleDependencies); + return this; + } + @Override public DashChunkSource createDashChunkSource( LoaderErrorThrower manifestLoaderErrorThrower,