Commit e668521b by bachinger Committed by Ian Baker

Prevent adding multiple IMA SSAI media source instances to the playlist

Currently only a single instance of ImaServerSideAdInsertionMediaSource is
supported at the same time in a playlist. This change makes sure that an
attempt to add multiple instances is prevented by throwing a an exception.

#minor-release

PiperOrigin-RevId: 428743140
parent 9088256b
...@@ -377,6 +377,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou ...@@ -377,6 +377,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
@Override @Override
public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) { public void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
mainHandler.post(() -> assertSingleInstanceInPlaylist(checkNotNull(player)));
super.prepareSourceInternal(mediaTransferListener); super.prepareSourceInternal(mediaTransferListener);
if (loader == null) { if (loader == null) {
Loader loader = new Loader("ImaServerSideAdInsertionMediaSource"); Loader loader = new Loader("ImaServerSideAdInsertionMediaSource");
...@@ -1150,4 +1151,20 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou ...@@ -1150,4 +1151,20 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
overlayInfo.reasonDetail != null ? overlayInfo.reasonDetail : "Unknown reason")); overlayInfo.reasonDetail != null ? overlayInfo.reasonDetail : "Unknown reason"));
} }
} }
private static void assertSingleInstanceInPlaylist(Player player) {
int counter = 0;
for (int i = 0; i < player.getMediaItemCount(); i++) {
MediaItem mediaItem = player.getMediaItemAt(i);
if (mediaItem.localConfiguration != null
&& C.SSAI_SCHEME.equals(mediaItem.localConfiguration.uri.getScheme())
&& ImaServerSideAdInsertionUriBuilder.IMA_AUTHORITY.equals(
mediaItem.localConfiguration.uri.getAuthority())) {
if (++counter > 1) {
throw new IllegalStateException(
"Multiple IMA server side ad insertion sources not supported.");
}
}
}
}
} }
...@@ -41,7 +41,7 @@ public final class ImaServerSideAdInsertionUriBuilder { ...@@ -41,7 +41,7 @@ public final class ImaServerSideAdInsertionUriBuilder {
/** The default timeout for loading the video URI, in milliseconds. */ /** The default timeout for loading the video URI, in milliseconds. */
public static final int DEFAULT_LOAD_VIDEO_TIMEOUT_MS = 10_000; public static final int DEFAULT_LOAD_VIDEO_TIMEOUT_MS = 10_000;
private static final String IMA_AUTHORITY = "dai.google.com"; /* package */ static final String IMA_AUTHORITY = "dai.google.com";
private static final String ADS_ID = "adsId"; private static final String ADS_ID = "adsId";
private static final String ASSET_KEY = "assetKey"; private static final String ASSET_KEY = "assetKey";
private static final String API_KEY = "apiKey"; private static final String API_KEY = "apiKey";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment