Effect: Fix concurrent access null pointer exception

A list was being accessed from one thread when it wasn't guaranteed to be empty.

PiperOrigin-RevId: 529102141
This commit is contained in:
huangdarwin 2023-05-03 16:45:59 +01:00 committed by Marc Baechinger
parent bba760f6e5
commit 93e3fe418e

View File

@ -263,7 +263,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
// A queue of input streams that have not been fully processed identified by their input types. // A queue of input streams that have not been fully processed identified by their input types.
private final Queue<@InputType Integer> unprocessedInputStreams; private final Queue<@InputType Integer> unprocessedInputStreams;
@Nullable private volatile CountDownLatch latch; private volatile @MonotonicNonNull CountDownLatch latch;
private volatile @MonotonicNonNull FrameInfo nextInputFrameInfo; private volatile @MonotonicNonNull FrameInfo nextInputFrameInfo;
private volatile boolean inputStreamEnded; private volatile boolean inputStreamEnded;
@ -355,16 +355,18 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
@Override @Override
public void registerInputStream(@InputType int inputType) { public void registerInputStream(@InputType int inputType) {
if (!unprocessedInputStreams.isEmpty()) { if (!unprocessedInputStreams.isEmpty()) {
textureManager.signalEndOfCurrentInputStream();
// Wait until the current video is processed before continuing to the next input. // Wait until the current video is processed before continuing to the next input.
if (checkNotNull(unprocessedInputStreams.peek()) == INPUT_TYPE_SURFACE) { if (checkNotNull(unprocessedInputStreams.peek()) == INPUT_TYPE_SURFACE) {
latch = new CountDownLatch(1); latch = new CountDownLatch(1);
textureManager.signalEndOfCurrentInputStream();
try { try {
latch.await(); latch.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
Log.e(TAG, "Error waiting for end of stream " + e); Log.e(TAG, "Error waiting for end of stream " + e);
} }
} else {
textureManager.signalEndOfCurrentInputStream();
} }
} }
unprocessedInputStreams.add(inputType); unprocessedInputStreams.add(inputType);