Prepare for adding ServerSideInsertedAdsMediaSource for IMA

PiperOrigin-RevId: 407274072
This commit is contained in:
olly 2021-11-03 07:57:55 +00:00 committed by Ian Baker
parent 3a5bf735fa
commit 8f88127b8e
4 changed files with 1057 additions and 5 deletions

View File

@ -894,7 +894,8 @@ public final class DownloadHelper {
MediaItem mediaItem,
DataSource.Factory dataSourceFactory,
@Nullable DrmSessionManager drmSessionManager) {
return new DefaultMediaSourceFactory(dataSourceFactory, ExtractorsFactory.EMPTY)
return new DefaultMediaSourceFactory(
dataSourceFactory, ExtractorsFactory.EMPTY, /* serverSideDaiMediaSourceFactory= */ null)
.setDrmSessionManager(drmSessionManager)
.createMediaSource(mediaItem);
}

View File

@ -27,6 +27,7 @@ import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.StreamKey;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
@ -121,6 +122,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
private final DataSource.Factory dataSourceFactory;
private final DelegateFactoryLoader delegateFactoryLoader;
@Nullable private final MediaSourceFactory serverSideDaiMediaSourceFactory;
@Nullable private AdsLoaderProvider adsLoaderProvider;
@Nullable private AdViewProvider adViewProvider;
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
@ -148,7 +150,10 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
* its container.
*/
public DefaultMediaSourceFactory(Context context, ExtractorsFactory extractorsFactory) {
this(new DefaultDataSource.Factory(context), extractorsFactory);
this(
new DefaultDataSource.Factory(context),
extractorsFactory,
/* serverSideDaiMediaSourceFactory= */ null);
}
/**
@ -158,7 +163,10 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
* for requesting media data.
*/
public DefaultMediaSourceFactory(DataSource.Factory dataSourceFactory) {
this(dataSourceFactory, new DefaultExtractorsFactory());
this(
dataSourceFactory,
new DefaultExtractorsFactory(),
/* serverSideDaiMediaSourceFactory= */ null);
}
/**
@ -168,10 +176,17 @@ 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 MediaSourceFactory} for creating server side
* inserted ad media sources.
*/
public DefaultMediaSourceFactory(
DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
DataSource.Factory dataSourceFactory,
ExtractorsFactory extractorsFactory,
@Nullable MediaSourceFactory serverSideDaiMediaSourceFactory) {
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;
@ -335,7 +350,11 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
@Override
public MediaSource createMediaSource(MediaItem mediaItem) {
checkNotNull(mediaItem.localConfiguration);
Assertions.checkNotNull(mediaItem.localConfiguration);
@Nullable String scheme = mediaItem.localConfiguration.uri.getScheme();
if (scheme != null && scheme.equals("imadai")) {
return checkNotNull(serverSideDaiMediaSourceFactory).createMediaSource(mediaItem);
}
@C.ContentType
int type =
Util.inferContentTypeForUriAndMimeType(

View File

@ -41,6 +41,7 @@ import com.google.ads.interactivemedia.v3.api.ImaSdkSettings;
import com.google.ads.interactivemedia.v3.api.UiElement;
import com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer;
import com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
@ -134,6 +135,35 @@ import java.util.Set;
}
}
/** Stores configuration for DAI ad playback. */
static final class DaiConfiguration {
public final AdErrorEvent.AdErrorListener applicationAdErrorListener;
public final boolean debugModeEnabled;
@Nullable public final List<CompanionAdSlot> companionAdSlots;
@Nullable public final AdEvent.AdEventListener applicationAdEventListener;
@Nullable public final VideoAdPlayer.VideoAdPlayerCallback applicationVideoAdPlayerCallback;
@Nullable public final ImaSdkSettings imaSdkSettings;
public DaiConfiguration(
AdErrorEvent.AdErrorListener applicationAdErrorListener,
@Nullable List<CompanionAdSlot> companionAdSlots,
@Nullable AdEvent.AdEventListener applicationAdEventListener,
@Nullable VideoAdPlayer.VideoAdPlayerCallback applicationVideoAdPlayerCallback,
@Nullable ImaSdkSettings imaSdkSettings,
boolean debugModeEnabled) {
this.applicationAdErrorListener = applicationAdErrorListener;
this.companionAdSlots =
companionAdSlots != null ? ImmutableList.copyOf(companionAdSlots) : null;
this.applicationAdEventListener = applicationAdEventListener;
this.applicationVideoAdPlayerCallback = applicationVideoAdPlayerCallback;
this.imaSdkSettings = imaSdkSettings;
this.debugModeEnabled = debugModeEnabled;
}
}
public static final int TIMEOUT_UNSET = -1;
public static final int BITRATE_UNSET = -1;