Commit 073807ae by huangdarwin Committed by Marc Baechinger

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
parent 6c294ac8
...@@ -261,7 +261,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -261,7 +261,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;
...@@ -353,16 +353,18 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -353,16 +353,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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment