|
25 | 25 | import java.nio.ByteBuffer; |
26 | 26 | import java.util.concurrent.Callable; |
27 | 27 | import java.util.concurrent.CompletableFuture; |
| 28 | +import java.util.concurrent.CountDownLatch; |
28 | 29 | import java.util.concurrent.Executors; |
29 | 30 | import java.util.concurrent.ScheduledExecutorService; |
30 | 31 | import java.util.concurrent.TimeUnit; |
|
41 | 42 | import dev.onvoid.webrtc.client.Signaling; |
42 | 43 | import dev.onvoid.webrtc.client.SignalingPair; |
43 | 44 | import dev.onvoid.webrtc.client.WebRtc; |
| 45 | +import dev.onvoid.webrtc.media.video.I420Buffer; |
44 | 46 | import dev.onvoid.webrtc.media.video.NativeI420Buffer; |
45 | 47 | import dev.onvoid.webrtc.media.video.VideoFrame; |
| 48 | +import dev.onvoid.webrtc.media.video.VideoFrameBuffer; |
46 | 49 |
|
47 | 50 | import org.junit.jupiter.api.AfterAll; |
48 | 51 | import org.junit.jupiter.api.BeforeAll; |
@@ -114,6 +117,72 @@ void showsFrame() throws Exception { |
114 | 117 | assertNull(onFx(view::snapshot)); |
115 | 118 | } |
116 | 119 |
|
| 120 | + @Test |
| 121 | + void clearDropsFrameInConversion() throws Exception { |
| 122 | + VideoView view = onFx(VideoView::new); |
| 123 | + CountDownLatch converting = new CountDownLatch(1); |
| 124 | + CountDownLatch cleared = new CountDownLatch(1); |
| 125 | + VideoFrame held = frame(64, 48, 128, 128); |
| 126 | + VideoFrameBuffer buffer = new VideoFrameBuffer() { |
| 127 | + |
| 128 | + @Override |
| 129 | + public int getWidth() { |
| 130 | + return held.buffer.getWidth(); |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public int getHeight() { |
| 135 | + return held.buffer.getHeight(); |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public I420Buffer toI420() { |
| 140 | + converting.countDown(); |
| 141 | + |
| 142 | + try { |
| 143 | + cleared.await(); |
| 144 | + } |
| 145 | + catch (InterruptedException e) { |
| 146 | + Thread.currentThread().interrupt(); |
| 147 | + } |
| 148 | + |
| 149 | + return held.buffer.toI420(); |
| 150 | + } |
| 151 | + |
| 152 | + @Override |
| 153 | + public VideoFrameBuffer cropAndScale(int cropX, int cropY, int cropWidth, int cropHeight, |
| 154 | + int scaleWidth, int scaleHeight) { |
| 155 | + throw new UnsupportedOperationException(); |
| 156 | + } |
| 157 | + |
| 158 | + @Override |
| 159 | + public void retain() { |
| 160 | + } |
| 161 | + |
| 162 | + @Override |
| 163 | + public void release() { |
| 164 | + } |
| 165 | + }; |
| 166 | + Thread delivery = new Thread(() -> view.accept(new VideoFrame(buffer, 0))); |
| 167 | + |
| 168 | + delivery.start(); |
| 169 | + assertTrue(converting.await(TIMEOUT_SECONDS, TimeUnit.SECONDS)); |
| 170 | + |
| 171 | + onFx(() -> { |
| 172 | + view.clear(); |
| 173 | + return null; |
| 174 | + }); |
| 175 | + cleared.countDown(); |
| 176 | + delivery.join(TimeUnit.SECONDS.toMillis(TIMEOUT_SECONDS)); |
| 177 | + |
| 178 | + // Runs after whatever the conversion handed to the JavaFX thread. |
| 179 | + assertNull(onFx(view::snapshot)); |
| 180 | + |
| 181 | + // The next frame shows as usual. |
| 182 | + view.accept(frame(32, 24, 128, 128)); |
| 183 | + assertEquals(32, (int) presented(view).getWidth()); |
| 184 | + } |
| 185 | + |
117 | 186 | @Test |
118 | 187 | void keepsAspectRatio() throws Exception { |
119 | 188 | VideoView view = sized(200, 100); |
|
0 commit comments