|
| 1 | +// Modifications by Signify, Copyright 2025, Signify Holding - SPDX-License-Identifier: MIT |
| 2 | + |
1 | 3 | package com.cloudwebrtc.webrtc.record;
|
2 | 4 |
|
3 | 5 | import android.media.MediaCodec;
|
|
19 | 21 |
|
20 | 22 | import java.io.IOException;
|
21 | 23 | import java.nio.ByteBuffer;
|
| 24 | +import java.util.concurrent.CountDownLatch; |
22 | 25 |
|
23 | 26 | class VideoFileRenderer implements VideoSink, SamplesReadyCallback {
|
24 | 27 | private static final String TAG = "VideoFileRenderer";
|
@@ -127,27 +130,47 @@ private void renderFrameOnRenderThread(VideoFrame frame) {
|
127 | 130 | /**
|
128 | 131 | * Release all resources. All already posted frames will be rendered first.
|
129 | 132 | */
|
| 133 | + // Start Signify modification |
130 | 134 | void release() {
|
131 | 135 | isRunning = false;
|
132 |
| - if (audioThreadHandler != null) |
| 136 | + CountDownLatch latch = new CountDownLatch(audioThreadHandler != null ? 2 : 1); |
| 137 | + if (audioThreadHandler != null) { |
133 | 138 | audioThreadHandler.post(() -> {
|
134 |
| - if (audioEncoder != null) { |
135 |
| - audioEncoder.stop(); |
136 |
| - audioEncoder.release(); |
| 139 | + try{ |
| 140 | + if (audioEncoder != null) { |
| 141 | + audioEncoder.stop(); |
| 142 | + audioEncoder.release(); |
| 143 | + } |
| 144 | + audioThread.quit(); |
| 145 | + } finally { |
| 146 | + latch.countDown(); |
137 | 147 | }
|
138 |
| - audioThread.quit(); |
139 | 148 | });
|
| 149 | + } |
| 150 | + |
140 | 151 | renderThreadHandler.post(() -> {
|
141 |
| - if (encoder != null) { |
142 |
| - encoder.stop(); |
143 |
| - encoder.release(); |
| 152 | + try { |
| 153 | + if (encoder != null) { |
| 154 | + encoder.stop(); |
| 155 | + encoder.release(); |
| 156 | + } |
| 157 | + eglBase.release(); |
| 158 | + mediaMuxer.stop(); |
| 159 | + mediaMuxer.release(); |
| 160 | + renderThread.quit(); |
| 161 | + } finally { |
| 162 | + latch.countDown(); |
144 | 163 | }
|
145 |
| - eglBase.release(); |
146 |
| - mediaMuxer.stop(); |
147 |
| - mediaMuxer.release(); |
148 |
| - renderThread.quit(); |
149 | 164 | });
|
| 165 | + |
| 166 | + try { |
| 167 | + latch.await(); |
| 168 | + } catch (InterruptedException e) { |
| 169 | + Log.e(TAG, "Release interrupted", e); |
| 170 | + Thread.currentThread().interrupt(); |
| 171 | + } |
150 | 172 | }
|
| 173 | + // End Signify modification |
151 | 174 |
|
152 | 175 | private boolean encoderStarted = false;
|
153 | 176 | private volatile boolean muxerStarted = false;
|
|
0 commit comments