Skip to content

Commit

Permalink
Add e2e test for seeking to beginning of chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihei committed Jan 30, 2024
1 parent 173dbc8 commit b5cc64e
Show file tree
Hide file tree
Showing 8 changed files with 590 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Cronet Extension:
* RTMP Extension:
* HLS Extension:
* Resolve seeks to beginning of a segment more efficiently
([#1031](https://github.com/androidx/media/pull/1031)).
* DASH Extension:
* Smooth Streaming Extension:
* RTSP Extension:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public TrackGroup getTrackGroup() {
return trackGroup;
}

/** Returns if the chunk source has independent segments. */
/** Returns whether the chunk source has independent segments. */
public boolean hasIndependentSegments() {
return independentSegments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import androidx.media3.common.Player;
import androidx.media3.datasource.DefaultDataSource;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.SeekParameters;
import androidx.media3.exoplayer.hls.HlsMediaSource;
import androidx.media3.test.utils.CapturingRenderersFactory;
import androidx.media3.test.utils.DumpFileAsserts;
Expand Down Expand Up @@ -153,4 +154,37 @@ public void cea608_parseDuringExtraction() throws Exception {
DumpFileAsserts.assertOutput(
applicationContext, playbackOutput, "playbackdumps/hls/cea608.dump");
}

@Test
public void multiSegment_withSeekToPrevSyncFrame_startsRenderingAtBeginningOfSegment()
throws Exception {
Context applicationContext = ApplicationProvider.getApplicationContext();
CapturingRenderersFactory capturingRenderersFactory =
new CapturingRenderersFactory(applicationContext);
ExoPlayer player =
new ExoPlayer.Builder(applicationContext, capturingRenderersFactory)
.setMediaSourceFactory(
new HlsMediaSource.Factory(new DefaultDataSource.Factory(applicationContext))
.experimentalParseSubtitlesDuringExtraction(true))
.setClock(new FakeClock(/* isAutoAdvancing= */ true))
.build();
// Prepare media fully to ensure we have all the segment data available.
player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */ 1)));
PlaybackOutput playbackOutput = PlaybackOutput.register(player, capturingRenderersFactory);
player.setMediaItem(MediaItem.fromUri("asset:///media/hls/multi-segment/playlist.m3u8"));
player.prepare();
TestPlayerRunHelper.runUntilIsLoading(player, true);
TestPlayerRunHelper.runUntilIsLoading(player, false);

// Seek to beginning of second segment (at 500ms according to playlist)
player.setSeekParameters(SeekParameters.PREVIOUS_SYNC);
player.seekTo(600);
player.play();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
player.release();

// Output only starts at 550ms (the first sample in the second segment)
DumpFileAsserts.assertOutput(
applicationContext, playbackOutput, "playbackdumps/hls/multi-segment-with-seek.dump");
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:1
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-MAP:URI="init.mp4"
#EXTINF:0.500,
playlist0.m4s
#EXTINF:0.550,
playlist1.m4s
#EXT-X-ENDLIST
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit b5cc64e

Please sign in to comment.