Move DAI MediaSource.Factory from constructor parameter to setter

This allows the same DefaultMediaSourceFactory instance to be used as
the contentMediaSourceFactory inside
ImaServerSideAdInsertionMediaSource.

PiperOrigin-RevId: 425846609
This commit is contained in:
ibaker 2022-02-02 12:05:07 +00:00 committed by Ian Baker
parent 57277a23da
commit 363c75b69c
2 changed files with 26 additions and 20 deletions

View File

@ -893,8 +893,7 @@ public final class DownloadHelper {
MediaItem mediaItem,
DataSource.Factory dataSourceFactory,
@Nullable DrmSessionManager drmSessionManager) {
return new DefaultMediaSourceFactory(
dataSourceFactory, ExtractorsFactory.EMPTY, /* serverSideDaiMediaSourceFactory= */ null)
return new DefaultMediaSourceFactory(dataSourceFactory, ExtractorsFactory.EMPTY)
.setDrmSessionManagerProvider(
drmSessionManager != null ? unusedMediaItem -> drmSessionManager : null)
.createMediaSource(mediaItem);

View File

@ -106,7 +106,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
private final DataSource.Factory dataSourceFactory;
private final DelegateFactoryLoader delegateFactoryLoader;
@Nullable private final MediaSource.Factory serverSideDaiMediaSourceFactory;
@Nullable private MediaSource.Factory imaServerSideAdInsertionMediaSourceFactory;
@Nullable private AdsLoader.Provider adsLoaderProvider;
@Nullable private AdViewProvider adViewProvider;
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
@ -135,10 +135,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
*/
@UnstableApi
public DefaultMediaSourceFactory(Context context, ExtractorsFactory extractorsFactory) {
this(
new DefaultDataSource.Factory(context),
extractorsFactory,
/* serverSideDaiMediaSourceFactory= */ null);
this(new DefaultDataSource.Factory(context), extractorsFactory);
}
/**
@ -149,10 +146,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
*/
@UnstableApi
public DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory) {
this(
dataSourceFactory,
new DefaultExtractorsFactory(),
/* serverSideDaiMediaSourceFactory= */ null);
this(dataSourceFactory, new DefaultExtractorsFactory());
}
/**
@ -162,18 +156,11 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
* for requesting media data.
* @param extractorsFactory An {@link ExtractorsFactory} used to extract progressive media from
* its container.
* @param serverSideDaiMediaSourceFactory A {@link MediaSource.Factory} for creating server side
* inserted ad media sources.
*/
@UnstableApi
public DefaultMediaSourceFactory(
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory,
@Nullable MediaSource.Factory serverSideDaiMediaSourceFactory) {
DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
this.dataSourceFactory = dataSourceFactory;
// Temporary until factory registration is agreed upon.
this.serverSideDaiMediaSourceFactory = serverSideDaiMediaSourceFactory;
delegateFactoryLoader = new DelegateFactoryLoader(dataSourceFactory, extractorsFactory);
liveTargetOffsetMs = C.TIME_UNSET;
liveMinOffsetMs = C.TIME_UNSET;
@ -224,6 +211,26 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
return this;
}
/**
* Sets the {@link MediaSource.Factory} used to handle {@link MediaItem} instances containing <a
* href="https://support.google.com/admanager/answer/6147120">IMA Dynamic Ad Insertion URIs</a>.
*
* <p>In most cases this will be an {@code ImaServerSideAdInsertionMediaSource.Factory} from the
* IMA extension.
*
* <p>IMA DAI URIs are those with a scheme of {@code "imadai"}.
*
* @param imaServerSideAdInsertionMediaSourceFactory The {@link MediaSource.Factory} for IMA DAI
* content, or {@code null} to remove a previously set {@link MediaSource.Factory}.
* @return This factory, for convenience.
*/
@UnstableApi
public DefaultMediaSourceFactory setImaServerSideAdInsertionMediaSourceFactory(
@Nullable MediaSource.Factory imaServerSideAdInsertionMediaSourceFactory) {
this.imaServerSideAdInsertionMediaSourceFactory = imaServerSideAdInsertionMediaSourceFactory;
return this;
}
/**
* Sets the target live offset for live streams, in milliseconds.
*
@ -318,7 +325,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
Assertions.checkNotNull(mediaItem.localConfiguration);
@Nullable String scheme = mediaItem.localConfiguration.uri.getScheme();
if (scheme != null && scheme.equals("imadai")) {
return checkNotNull(serverSideDaiMediaSourceFactory).createMediaSource(mediaItem);
return checkNotNull(imaServerSideAdInsertionMediaSourceFactory).createMediaSource(mediaItem);
}
@C.ContentType
int type =