Make VideoFrameProcessor.flush() more resilient
Allow flush to be called before registerInputStream. It's less error prone to allow methods to be called in any order. PiperOrigin-RevId: 624873772
This commit is contained in:
parent
b7a92ce47a
commit
71e7e0f2cf
@ -319,8 +319,6 @@ public interface VideoFrameProcessor {
|
||||
*
|
||||
* @throws UnsupportedOperationException If the {@code VideoFrameProcessor} does not accept
|
||||
* {@linkplain #INPUT_TYPE_SURFACE surface input}.
|
||||
* @throws IllegalStateException If {@link #registerInputStream} is not called before calling this
|
||||
* method.
|
||||
*/
|
||||
void flush();
|
||||
|
||||
|
@ -18,7 +18,6 @@ package androidx.media3.effect;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.test.utils.BitmapPixelTestUtil.readBitmapUnpremultipliedAlpha;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import androidx.media3.common.C;
|
||||
@ -54,13 +53,6 @@ public class DefaultVideoFrameProcessorFlushTest {
|
||||
checkNotNull(videoFrameProcessorTestRunner).release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imageInput_flushBeforeInput_throwsException() throws Exception {
|
||||
videoFrameProcessorTestRunner = createDefaultVideoFrameProcessorTestRunner(testId);
|
||||
|
||||
assertThrows(IllegalStateException.class, videoFrameProcessorTestRunner::flush);
|
||||
}
|
||||
|
||||
// This tests a condition that is difficult to synchronize, and is subject to a race condition. It
|
||||
// may flake/fail if any queued frames are processed in the VideoFrameProcessor thread, before
|
||||
// flush begins and cancels these pending frames. However, this is better than not testing this
|
||||
|
@ -604,6 +604,9 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
|
||||
*/
|
||||
@Override
|
||||
public void flush() {
|
||||
if (!inputSwitcher.hasActiveInput()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
videoFrameProcessingTaskExecutor.flush();
|
||||
|
||||
@ -612,7 +615,6 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
|
||||
inputSwitcher.activeTextureManager().setOnFlushCompleteListener(latch::countDown);
|
||||
videoFrameProcessingTaskExecutor.submit(finalShaderProgramWrapper::flush);
|
||||
latch.await();
|
||||
|
||||
inputSwitcher.activeTextureManager().setOnFlushCompleteListener(null);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
|
Loading…
x
Reference in New Issue
Block a user