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);
}
// 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
public void export_withTwoVideoOnlyMediaItemsAndGapInMiddle_insertsBlankFramesForGap()
throws Exception {
@ -224,27 +201,15 @@ public class TransformerGapsTest {
.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_withTwoMediaItemsAndGapAtStart_throws() {
Transformer transformer = new Transformer.Builder(context).build();
Composition composition =
new Composition.Builder(
new EditedMediaItemSequence.Builder()
.addGap(/* durationUs= */ 1_000_000)
.addItem(AUDIO_VIDEO_MEDIA_ITEM)
.addItem(AUDIO_VIDEO_MEDIA_ITEM)
.build())
.build();
TransformerAndroidTestRunner transformerAndroidTestRunner =
new TransformerAndroidTestRunner.Builder(context, transformer).build();
public void buildSequence_withTwoMediaItemsAndGapAtStart_throws() {
EditedMediaItemSequence.Builder sequenceBuilder =
new EditedMediaItemSequence.Builder()
.addGap(/* durationUs= */ 1_000_000)
.addItem(AUDIO_VIDEO_MEDIA_ITEM)
.addItem(AUDIO_VIDEO_MEDIA_ITEM);
// 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));
assertThrows(IllegalArgumentException.class, sequenceBuilder::build);
}
@Test

View File

@ -98,6 +98,9 @@ public final class EditedMediaItemSequence {
*
* <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.
*
* @param durationUs The duration of the gap, in milliseconds.
@ -230,6 +233,9 @@ public final class EditedMediaItemSequence {
this.editedMediaItems = builder.items.build();
checkArgument(
!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.forceAudioTrack = builder.forceAudioTrack;
}