Skip to content

Commit

Permalink
Enable re-preparing the ImaSSAIMediaSource
Browse files Browse the repository at this point in the history
#minor-release

PiperOrigin-RevId: 538927855
  • Loading branch information
marcbaechinger authored and tof-tof committed Jun 9, 2023
1 parent 605af62 commit a67ce06
Showing 1 changed file with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;

/** MediaSource for IMA server side inserted ad streams. */
@UnstableApi
Expand Down Expand Up @@ -520,7 +518,7 @@ private MediaSourceResourceHolder(
@Nullable private StreamManager streamManager;
@Nullable private ServerSideAdInsertionMediaSource serverSideAdInsertionMediaSource;
@Nullable private IOException loadError;
private @MonotonicNonNull Timeline contentTimeline;
@Nullable private Timeline contentTimeline;
private AdPlaybackState adPlaybackState;

private ImaServerSideAdInsertionMediaSource(
Expand Down Expand Up @@ -635,6 +633,8 @@ protected void releaseSourceInternal() {
});
loader = null;
}
contentTimeline = null;
serverSideAdInsertionMediaSource = null;
}

// Internal methods (called on the main thread).
Expand Down Expand Up @@ -682,7 +682,6 @@ private void setAdPlaybackState(AdPlaybackState adPlaybackState) {
}

@MainThread
@EnsuresNonNull("this.contentTimeline")
private void setContentTimeline(Timeline contentTimeline) {
if (contentTimeline.equals(this.contentTimeline)) {
return;
Expand All @@ -700,6 +699,7 @@ private void setContentTimeline(Timeline contentTimeline) {
@MainThread
private void invalidateServerSideAdInsertionAdPlaybackState() {
if (!adPlaybackState.equals(AdPlaybackState.NONE) && contentTimeline != null) {
Timeline contentTimeline = checkNotNull(this.contentTimeline);
ImmutableMap<Object, AdPlaybackState> splitAdPlaybackStates;
if (Objects.equals(streamRequest.getFormat(), StreamFormat.DASH)) {
// DASH ad groups are always split by period.
Expand Down Expand Up @@ -727,27 +727,27 @@ private void invalidateServerSideAdInsertionAdPlaybackState() {
// Internal methods (called on the playback thread).

private void setContentUri(Uri contentUri) {
if (serverSideAdInsertionMediaSource != null) {
return;
}
MediaItem contentMediaItem =
new MediaItem.Builder()
.setUri(contentUri)
.setDrmConfiguration(checkNotNull(mediaItem.localConfiguration).drmConfiguration)
.setLiveConfiguration(mediaItem.liveConfiguration)
.setCustomCacheKey(mediaItem.localConfiguration.customCacheKey)
.setStreamKeys(mediaItem.localConfiguration.streamKeys)
.build();
ServerSideAdInsertionMediaSource serverSideAdInsertionMediaSource =
new ServerSideAdInsertionMediaSource(
contentMediaSourceFactory.createMediaSource(contentMediaItem), componentListener);
this.serverSideAdInsertionMediaSource = serverSideAdInsertionMediaSource;
if (isLiveStream) {
mainHandler.post(
() ->
setAdPlaybackState(new AdPlaybackState(adsId).withLivePostrollPlaceholderAppended()));
if (serverSideAdInsertionMediaSource == null) {
MediaItem contentMediaItem =
new MediaItem.Builder()
.setUri(contentUri)
.setDrmConfiguration(checkNotNull(mediaItem.localConfiguration).drmConfiguration)
.setLiveConfiguration(mediaItem.liveConfiguration)
.setCustomCacheKey(mediaItem.localConfiguration.customCacheKey)
.setStreamKeys(mediaItem.localConfiguration.streamKeys)
.build();
ServerSideAdInsertionMediaSource serverSideAdInsertionMediaSource =
new ServerSideAdInsertionMediaSource(
contentMediaSourceFactory.createMediaSource(contentMediaItem), componentListener);
this.serverSideAdInsertionMediaSource = serverSideAdInsertionMediaSource;
if (isLiveStream) {
mainHandler.post(
() ->
setAdPlaybackState(
new AdPlaybackState(adsId).withLivePostrollPlaceholderAppended()));
}
prepareChildSource(/* id= */ null, serverSideAdInsertionMediaSource);
}
prepareChildSource(/* id= */ null, serverSideAdInsertionMediaSource);
}

// Static methods.
Expand Down

0 comments on commit a67ce06

Please sign in to comment.