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
|
* @throws UnsupportedOperationException If the {@code VideoFrameProcessor} does not accept
|
||||||
* {@linkplain #INPUT_TYPE_SURFACE surface input}.
|
* {@linkplain #INPUT_TYPE_SURFACE surface input}.
|
||||||
* @throws IllegalStateException If {@link #registerInputStream} is not called before calling this
|
|
||||||
* method.
|
|
||||||
*/
|
*/
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ 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;
|
||||||
@ -54,13 +53,6 @@ public class DefaultVideoFrameProcessorFlushTest {
|
|||||||
checkNotNull(videoFrameProcessorTestRunner).release();
|
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
|
// 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
|
// 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
|
// 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
|
@Override
|
||||||
public void flush() {
|
public void flush() {
|
||||||
|
if (!inputSwitcher.hasActiveInput()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
videoFrameProcessingTaskExecutor.flush();
|
videoFrameProcessingTaskExecutor.flush();
|
||||||
|
|
||||||
@ -612,7 +615,6 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
|
|||||||
inputSwitcher.activeTextureManager().setOnFlushCompleteListener(latch::countDown);
|
inputSwitcher.activeTextureManager().setOnFlushCompleteListener(latch::countDown);
|
||||||
videoFrameProcessingTaskExecutor.submit(finalShaderProgramWrapper::flush);
|
videoFrameProcessingTaskExecutor.submit(finalShaderProgramWrapper::flush);
|
||||||
latch.await();
|
latch.await();
|
||||||
|
|
||||||
inputSwitcher.activeTextureManager().setOnFlushCompleteListener(null);
|
inputSwitcher.activeTextureManager().setOnFlushCompleteListener(null);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user