Skip to content

Commit

Permalink
Add two missing test cases in seeking
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 700284751
  • Loading branch information
claincly authored and copybara-github committed Nov 26, 2024
1 parent e357629 commit 2a4bae0
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ public void seekToZero_duringPlayingFirstVideoInSingleSequenceOfTwoVideos() thro
assertThat(actualTimestampsUs).isEqualTo(expectedTimestampsUs);
}

@Test
public void seekToFirstMedia_duringPlayingFirstVideoInSingleSequenceOfTwoVideos()
throws Exception {
ImmutableList<MediaItem> mediaItems = ImmutableList.of(VIDEO_MEDIA_ITEM, VIDEO_MEDIA_ITEM);
ImmutableList<Long> durationsUs = ImmutableList.of(VIDEO_DURATION_US, VIDEO_DURATION_US);
int numberOfFramesBeforeSeeking = 15;
// 100ms into the first video, should skip the first 3 frames.
long seekTimeMs = 100;
ImmutableList<Long> expectedTimestampsUs =
new ImmutableList.Builder<Long>()
// Plays the first 15 frames of the first video
.addAll(
Iterables.limit(VIDEO_TIMESTAMPS_US, /* limitSize= */ numberOfFramesBeforeSeeking))
// Seek, skipping the first 3 frames of the first video
.addAll(Iterables.skip(VIDEO_TIMESTAMPS_US, /* numberToSkip= */ 3))
// Plays the second video
.addAll(
Iterables.transform(
VIDEO_TIMESTAMPS_US, timestampUs -> (VIDEO_DURATION_US + timestampUs)))
.build();

ImmutableList<Long> actualTimestampsUs =
playSequenceAndGetTimestampsUs(
mediaItems, durationsUs, numberOfFramesBeforeSeeking, seekTimeMs);

assertThat(actualTimestampsUs).isEqualTo(expectedTimestampsUs);
}

@Test
public void seekToSecondMedia_duringPlayingFirstVideoInSingleSequenceOfTwoVideos()
throws Exception {
Expand Down Expand Up @@ -227,6 +255,37 @@ public void seekToFirstMedia_duringPlayingSecondVideoInSingleSequenceOfTwoVideos
assertThat(actualTimestampsUs).isEqualTo(expectedTimestampsUs);
}

@Test
public void seekToSecondMedia_duringPlayingSecondVideoInSingleSequenceOfTwoVideos()
throws Exception {
ImmutableList<MediaItem> mediaItems = ImmutableList.of(VIDEO_MEDIA_ITEM, VIDEO_MEDIA_ITEM);
ImmutableList<Long> durationsUs = ImmutableList.of(VIDEO_DURATION_US, VIDEO_DURATION_US);
int numberOfFramesBeforeSeeking = 45;
// 100ms into the second video, should skip the first 3 frames.
long seekTimeMs = 1124;
ImmutableList<Long> expectedTimestampsUs =
new ImmutableList.Builder<Long>()
// Play first video
.addAll(VIDEO_TIMESTAMPS_US)
// Play the first 15 frames of the seconds video
.addAll(
Iterables.transform(
Iterables.limit(VIDEO_TIMESTAMPS_US, /* limitSize= */ 15),
timestampUs -> (VIDEO_DURATION_US + timestampUs)))
// Seek to the second, skipping the first 3 frames.
.addAll(
Iterables.transform(
Iterables.skip(VIDEO_TIMESTAMPS_US, /* numberToSkip= */ 3),
timestampUs -> (VIDEO_DURATION_US + timestampUs)))
.build();

ImmutableList<Long> actualTimestampsUs =
playSequenceAndGetTimestampsUs(
mediaItems, durationsUs, numberOfFramesBeforeSeeking, seekTimeMs);

assertThat(actualTimestampsUs).isEqualTo(expectedTimestampsUs);
}

@Test
public void seekToEndOfFirstMedia_duringPlayingFirstVideoInSingleSequenceOfTwoVideos()
throws Exception {
Expand Down

0 comments on commit 2a4bae0

Please sign in to comment.