From 3e3397ad682a0296bb007fac899b0eeaa3e058c4 Mon Sep 17 00:00:00 2001 From: Alex Andres Date: Wed, 4 Nov 2026 19:11:40 +0100 Subject: [PATCH] test: send the VP9 stream a frame at a time The test needs every frame of a stream it sends once, and on macOS arm64 some decoded frames never reached the sink, with none counted as dropped. After decoding only the render queue drops frames, so the next one now waits for the one before. --- .../HardwareVideoDecoderIntegrationTest.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoDecoderIntegrationTest.java b/webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoDecoderIntegrationTest.java index b92cf1218..f58066f6c 100644 --- a/webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoDecoderIntegrationTest.java +++ b/webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoDecoderIntegrationTest.java @@ -51,6 +51,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import java.util.function.IntSupplier; import java.util.function.Predicate; import org.junit.jupiter.api.Test; @@ -542,21 +543,26 @@ void hardwareDecodesVp9FixedInterpolationFilter() throws Exception { /** * Sends the recorded VP9 frames through a call whose receiver decodes - * with the given factory, and returns the luma of the last frame. + * with the given factory, and returns the luma of the last frame. Each + * frame goes out once the one before reached the sink: the stream is sent + * once, and the render queue may drop a decoded frame while others wait, + * which no statistic counts. */ private byte[] lastVp9Frame(VideoDecoderFactory decoders, List stream, Consumer expectHardware) throws Exception { final int width = 320; final int height = 180; + CountDownLatch received = new CountDownLatch(stream.size()); + AtomicReference last = new AtomicReference<>(); + PeerConnectionFactory factory = PeerConnectionFactory.builder() .setAudioDeviceModule(audioDevModule) - .setVideoEncoderFactory(new ReplayEncoderFactory(stream, width, height)) + .setVideoEncoderFactory(new ReplayEncoderFactory(stream, width, height, + () -> stream.size() - (int) received.getCount())) .setVideoDecoderFactory(decoders) .build(); - CountDownLatch received = new CountDownLatch(stream.size()); - AtomicReference last = new AtomicReference<>(); String implementation; try (TestMediaCall call = new TestMediaCall(factory, true, false, VP9)) { @@ -587,7 +593,8 @@ private byte[] lastVp9Frame(VideoDecoderFactory decoders, List strea call.awaitConnected(); call.startMedia(); - if (!received.await(TIMEOUT_SECONDS, TimeUnit.SECONDS)) { + // A frame at a time takes longer than the stream's 1.5 seconds. + if (!received.await(3 * TIMEOUT_SECONDS, TimeUnit.SECONDS)) { // Tells whether the frames were lost before or after decoding. Map inbound = call.getInboundVideoStats(); @@ -662,11 +669,15 @@ private static final class ReplayEncoderFactory implements VideoEncoderFactory { private final int height; + /** How many frames reached the sink. */ + private final IntSupplier arrived; + - ReplayEncoderFactory(List stream, int width, int height) { + ReplayEncoderFactory(List stream, int width, int height, IntSupplier arrived) { this.stream = stream; this.width = width; this.height = height; + this.arrived = arrived; } @Override @@ -699,7 +710,7 @@ public VideoCodecStatus release() { @Override public VideoCodecStatus encode(VideoFrame frame, EncodeInfo info) { - if (next < stream.size()) { + if (next < stream.size() && next == arrived.getAsInt()) { ByteBuffer payload = ByteBuffer.allocateDirect(stream.get(next).remaining()); payload.put(stream.get(next).duplicate()).flip();