Skip to content

Commit

Permalink
Fix CMCD data assignment for init segment
Browse files Browse the repository at this point in the history
The CMCD data was incorrectly added to the `dataSpec` of the media segment instead of the init segment.

Also relaxed the condition for playbackRate to be C.RATE_UNSET when creating an instance of CmcdData.Factory as there was nothing enforcing this check.

#minor-release

PiperOrigin-RevId: 639046080
  • Loading branch information
rohitjoins authored and Copybara-Service committed May 31, 2024
1 parent dbeb412 commit 387153f
Show file tree
Hide file tree
Showing 5 changed files with 716 additions and 2 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
callbacks and if `ExoPlayer` is set with
`experimentalSetDynamicSchedulingEnabled`, then `ExoPlayer` will
schedule its work loop as renderers can make progress.
* Fix bug where enabling CMCD for HLS with initialization segments
resulted in `Source Error` and `IllegalArgumentException`.
* Transformer:
* Work around a decoder bug where the number of audio channels was capped
at stereo when handling PCM input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Factory(
boolean didRebuffer,
boolean isBufferEmpty) {
checkArgument(bufferedDurationUs >= 0);
checkArgument(playbackRate > 0);
checkArgument(playbackRate == C.RATE_UNSET || playbackRate > 0);
this.cmcdConfiguration = cmcdConfiguration;
this.trackSelection = trackSelection;
this.bufferedDurationUs = bufferedDurationUs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static HlsMediaChunk createInstance(
cmcdDataFactory
.setObjectType(CmcdData.Factory.OBJECT_TYPE_INIT_SEGMENT)
.createCmcdData();
initDataSpec = cmcdData.addToDataSpec(dataSpec);
initDataSpec = cmcdData.addToDataSpec(initDataSpec);
}

initDataSource = buildDataSource(dataSource, initSegmentKey, initSegmentIv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.SeekParameters;
import androidx.media3.exoplayer.hls.HlsMediaSource;
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
import androidx.media3.exoplayer.upstream.CmcdConfiguration;
import androidx.media3.test.utils.CapturingRenderersFactory;
import androidx.media3.test.utils.DumpFileAsserts;
import androidx.media3.test.utils.FakeClock;
Expand Down Expand Up @@ -190,4 +192,30 @@ public void multiSegment_withSeekToPrevSyncFrame_startsRenderingAtBeginningOfSeg
DumpFileAsserts.assertOutput(
applicationContext, playbackOutput, "playbackdumps/hls/multi-segment-with-seek.dump");
}

@Test
public void cmcdEnabled_withInitSegment() throws Exception {
Context applicationContext = ApplicationProvider.getApplicationContext();
CapturingRenderersFactory capturingRenderersFactory =
new CapturingRenderersFactory(applicationContext);
ExoPlayer player =
new ExoPlayer.Builder(applicationContext, capturingRenderersFactory)
.setClock(new FakeClock(/* isAutoAdvancing= */ true))
.setMediaSourceFactory(
new DefaultMediaSourceFactory(applicationContext)
.setCmcdConfigurationFactory(CmcdConfiguration.Factory.DEFAULT))
.build();

PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
player.setMediaItem(MediaItem.fromUri("asset:///media/hls/multi-segment/playlist.m3u8"));
player.prepare();
player.play();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
player.release();

DumpFileAsserts.assertOutput(
applicationContext,
playbackOutput,
"playbackdumps/hls/cmcd-enabled-with-init-segment.dump");
}
}
Loading

0 comments on commit 387153f

Please sign in to comment.