Validate gap at start when building sequence

PiperOrigin-RevId: 742710209
This commit is contained in:
sheenachhabra 2025-04-01 08:28:27 -07:00 committed by Copybara-Service
parent 812e078310
commit cf3faf9cff
2 changed files with 13 additions and 42 deletions

View File

@ -135,29 +135,6 @@ public class TransformerGapsTest {
.isEqualTo(2 * MP4_ASSET.videoFrameCount + expectedBlankFrames); .isEqualTo(2 * MP4_ASSET.videoFrameCount + expectedBlankFrames);
} }
// TODO: b/391111085 - Change test when gaps at the start of the sequence are supported.
@Test
public void export_withTwoVideoOnlyMediaItemsAndGapAtStart_throws() {
Transformer transformer = new Transformer.Builder(context).build();
Composition composition =
new Composition.Builder(
new EditedMediaItemSequence.Builder()
.addGap(/* durationUs= */ 1_000_000)
.addItem(VIDEO_ONLY_MEDIA_ITEM)
.addItem(VIDEO_ONLY_MEDIA_ITEM)
.build())
.build();
TransformerAndroidTestRunner transformerAndroidTestRunner =
new TransformerAndroidTestRunner.Builder(context, transformer).build();
// An IllegalStateException is thrown instead of an ExportException because the exception is
// thrown very early in the setup phase and its not caught.
// TODO: b/391111085 - Throw exception when the sequence without force audio/video flag is
// built.
assertThrows(
IllegalStateException.class, () -> transformerAndroidTestRunner.run(testId, composition));
}
@Test @Test
public void export_withTwoVideoOnlyMediaItemsAndGapInMiddle_insertsBlankFramesForGap() public void export_withTwoVideoOnlyMediaItemsAndGapInMiddle_insertsBlankFramesForGap()
throws Exception { throws Exception {
@ -224,27 +201,15 @@ public class TransformerGapsTest {
.isEqualTo(2 * MP4_ASSET.videoFrameCount + expectedBlankFrames); .isEqualTo(2 * MP4_ASSET.videoFrameCount + expectedBlankFrames);
} }
// TODO: b/391111085 - Change test when gaps at the start of the sequence are supported.
@Test @Test
public void export_withTwoMediaItemsAndGapAtStart_throws() { public void buildSequence_withTwoMediaItemsAndGapAtStart_throws() {
Transformer transformer = new Transformer.Builder(context).build(); EditedMediaItemSequence.Builder sequenceBuilder =
Composition composition = new EditedMediaItemSequence.Builder()
new Composition.Builder( .addGap(/* durationUs= */ 1_000_000)
new EditedMediaItemSequence.Builder() .addItem(AUDIO_VIDEO_MEDIA_ITEM)
.addGap(/* durationUs= */ 1_000_000) .addItem(AUDIO_VIDEO_MEDIA_ITEM);
.addItem(AUDIO_VIDEO_MEDIA_ITEM)
.addItem(AUDIO_VIDEO_MEDIA_ITEM)
.build())
.build();
TransformerAndroidTestRunner transformerAndroidTestRunner =
new TransformerAndroidTestRunner.Builder(context, transformer).build();
// An IllegalStateException is thrown instead of an ExportException because the exception is assertThrows(IllegalArgumentException.class, sequenceBuilder::build);
// thrown very early in the setup phase and its not caught.
// TODO: b/391111085 - Throw exception when the sequence without force audio/video flag is
// built.
assertThrows(
IllegalStateException.class, () -> transformerAndroidTestRunner.run(testId, composition));
} }
@Test @Test

View File

@ -98,6 +98,9 @@ public final class EditedMediaItemSequence {
* *
* <p>A gap is a period of time with no media. * <p>A gap is a period of time with no media.
* *
* <p>If the gap is at the start of the sequence then {@linkplain #setForceAudioTrack(boolean)
* force audio track} flag must be set to force silent audio.
*
* <p>Gaps at the start of the sequence are not supported if the sequence has video. * <p>Gaps at the start of the sequence are not supported if the sequence has video.
* *
* @param durationUs The duration of the gap, in milliseconds. * @param durationUs The duration of the gap, in milliseconds.
@ -230,6 +233,9 @@ public final class EditedMediaItemSequence {
this.editedMediaItems = builder.items.build(); this.editedMediaItems = builder.items.build();
checkArgument( checkArgument(
!editedMediaItems.isEmpty(), "The sequence must contain at least one EditedMediaItem."); !editedMediaItems.isEmpty(), "The sequence must contain at least one EditedMediaItem.");
checkArgument(
!editedMediaItems.get(0).isGap() || builder.forceAudioTrack,
"If the first item in the sequence is a Gap, then forceAudioTrack flag must be set");
this.isLooping = builder.isLooping; this.isLooping = builder.isLooping;
this.forceAudioTrack = builder.forceAudioTrack; this.forceAudioTrack = builder.forceAudioTrack;
} }