Flush: Disallow flushing when there's no active input.

Throws when calling flush when there's no active input, for example
before an input stream is registered or after all output streams have
ended.

PiperOrigin-RevId: 577165419
This commit is contained in:
huangdarwin 2023-10-27 05:21:26 -07:00 committed by Copybara-Service
parent dd6306e1ba
commit fed88cf6f5
2 changed files with 3 additions and 15 deletions

View File

@ -18,6 +18,7 @@ package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmapUnpremultipliedAlpha; import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmapUnpremultipliedAlpha;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import androidx.media3.common.C; import androidx.media3.common.C;
@ -60,20 +61,10 @@ public class DefaultVideoFrameProcessorFlushTest {
@Test @Test
@RequiresNonNull({"testId"}) @RequiresNonNull({"testId"})
public void imageInput_flushBeforeInput_outputsAllFrames() throws Exception { public void imageInput_flushBeforeInput_throwsException() throws Exception {
videoFrameProcessorTestRunner = createDefaultVideoFrameProcessorTestRunner(testId); videoFrameProcessorTestRunner = createDefaultVideoFrameProcessorTestRunner(testId);
Bitmap bitmap = readBitmapUnpremultipliedAlpha(ORIGINAL_PNG_ASSET_PATH);
int inputFrameCount = 3;
videoFrameProcessorTestRunner.flush(); assertThrows(IllegalStateException.class, videoFrameProcessorTestRunner::flush);
videoFrameProcessorTestRunner.queueInputBitmap(
bitmap,
/* durationUs= */ inputFrameCount * C.MICROS_PER_SECOND,
/* offsetToAddUs= */ 0L,
/* frameRate= */ 1);
videoFrameProcessorTestRunner.endFrameProcessing();
assertThat(outputFrameCount).isEqualTo(inputFrameCount);
} }
// This tests a condition that is difficult to synchronize, and is subject to a race condition. It // This tests a condition that is difficult to synchronize, and is subject to a race condition. It

View File

@ -559,9 +559,6 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
*/ */
@Override @Override
public void flush() { public void flush() {
if (!inputSwitcher.hasActiveInput()) {
return;
}
try { try {
videoFrameProcessingTaskExecutor.flush(); videoFrameProcessingTaskExecutor.flush();