Add API for sample dependency reading to DefaultMediaSourceFactory

PiperOrigin-RevId: 715372196
This commit is contained in:
dancho 2025-01-14 07:24:00 -08:00 committed by Copybara-Service
parent 2eb8e53f8c
commit 8f17ab84f8
5 changed files with 80 additions and 0 deletions

View File

@ -211,6 +211,16 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
return this; 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 * Sets the {@link AdsLoader.Provider} that provides {@link AdsLoader} instances for media items
* that have {@link MediaItem.LocalConfiguration#adsConfiguration ads configurations}. * that have {@link MediaItem.LocalConfiguration#adsConfiguration ads configurations}.
@ -625,6 +635,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
private DataSource.@MonotonicNonNull Factory dataSourceFactory; private DataSource.@MonotonicNonNull Factory dataSourceFactory;
private boolean parseSubtitlesDuringExtraction; private boolean parseSubtitlesDuringExtraction;
private SubtitleParser.Factory subtitleParserFactory; private SubtitleParser.Factory subtitleParserFactory;
private @C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies;
@Nullable private CmcdConfiguration.Factory cmcdConfigurationFactory; @Nullable private CmcdConfiguration.Factory cmcdConfigurationFactory;
@Nullable private DrmSessionManagerProvider drmSessionManagerProvider; @Nullable private DrmSessionManagerProvider drmSessionManagerProvider;
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy; @Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
@ -664,6 +675,8 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
} }
mediaSourceFactory.setSubtitleParserFactory(subtitleParserFactory); mediaSourceFactory.setSubtitleParserFactory(subtitleParserFactory);
mediaSourceFactory.experimentalParseSubtitlesDuringExtraction(parseSubtitlesDuringExtraction); mediaSourceFactory.experimentalParseSubtitlesDuringExtraction(parseSubtitlesDuringExtraction);
mediaSourceFactory.experimentalSetCodecsToParseWithinGopSampleDependencies(
codecsToParseWithinGopSampleDependencies);
mediaSourceFactories.put(contentType, mediaSourceFactory); mediaSourceFactories.put(contentType, mediaSourceFactory);
return 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) { public void setCmcdConfigurationFactory(CmcdConfiguration.Factory cmcdConfigurationFactory) {
this.cmcdConfigurationFactory = cmcdConfigurationFactory; this.cmcdConfigurationFactory = cmcdConfigurationFactory;
for (MediaSource.Factory mediaSourceFactory : mediaSourceFactories.values()) { for (MediaSource.Factory mediaSourceFactory : mediaSourceFactories.values()) {

View File

@ -30,7 +30,9 @@ import androidx.media3.exoplayer.drm.DrmSessionManagerProvider;
import androidx.media3.exoplayer.upstream.Allocator; import androidx.media3.exoplayer.upstream.Allocator;
import androidx.media3.exoplayer.upstream.CmcdConfiguration; import androidx.media3.exoplayer.upstream.CmcdConfiguration;
import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy; import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy;
import androidx.media3.extractor.mp4.Mp4Extractor;
import androidx.media3.extractor.text.SubtitleParser; import androidx.media3.extractor.text.SubtitleParser;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException; import java.io.IOException;
/** /**
@ -131,6 +133,26 @@ public interface MediaSource {
return this; 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.
*
* <p>Having access to additional sample dependency information can speed up seeking. See {@link
* Mp4Extractor#FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES}.
*
* <p>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 * Returns the {@link C.ContentType content types} supported by media sources created by this
* factory. * factory.

View File

@ -30,6 +30,7 @@ import androidx.media3.exoplayer.trackselection.ExoTrackSelection;
import androidx.media3.exoplayer.upstream.CmcdConfiguration; import androidx.media3.exoplayer.upstream.CmcdConfiguration;
import androidx.media3.exoplayer.upstream.LoaderErrorThrower; import androidx.media3.exoplayer.upstream.LoaderErrorThrower;
import androidx.media3.extractor.Extractor; import androidx.media3.extractor.Extractor;
import androidx.media3.extractor.mp4.Mp4Extractor;
import androidx.media3.extractor.text.SubtitleParser; import androidx.media3.extractor.text.SubtitleParser;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List; import java.util.List;
@ -71,6 +72,25 @@ public interface DashChunkSource extends ChunkSource {
return this; 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.
*
* <p>Having access to additional sample dependency information can speed up seeking. See {@link
* Mp4Extractor#FLAG_READ_WITHIN_GOP_SAMPLE_DEPENDENCIES}.
*
* <p>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 manifestLoaderErrorThrower Throws errors affecting loading of manifests.
* @param manifest The initial manifest. * @param manifest The initial manifest.

View File

@ -217,6 +217,15 @@ public final class DashMediaSource extends BaseMediaSource {
return this; 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 * 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. * no value is defined in the {@link MediaItem} or the manifest.

View File

@ -130,6 +130,15 @@ public class DefaultDashChunkSource implements DashChunkSource {
return this; return this;
} }
@CanIgnoreReturnValue
@Override
public Factory experimentalSetCodecsToParseWithinGopSampleDependencies(
@C.VideoCodecFlags int codecsToParseWithinGopSampleDependencies) {
chunkExtractorFactory.experimentalSetCodecsToParseWithinGopSampleDependencies(
codecsToParseWithinGopSampleDependencies);
return this;
}
@Override @Override
public DashChunkSource createDashChunkSource( public DashChunkSource createDashChunkSource(
LoaderErrorThrower manifestLoaderErrorThrower, LoaderErrorThrower manifestLoaderErrorThrower,