Skip to content

Commit f8ffb25

Browse files
committed
test: start recording a client API call once its remote video decodes
A signaled track need not carry video yet, and on a slow runner the recorder then waited past its header timeout for a key frame. Warnings are now part of the failure message.
1 parent eca1493 commit f8ffb25

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

‎webrtc-media/src/test/java/dev/onvoid/webrtc/media/recorder/ClientApiRecorderTest.java‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import dev.onvoid.webrtc.client.Sender;
4343
import dev.onvoid.webrtc.client.Signaling;
4444
import dev.onvoid.webrtc.client.SignalingPair;
45+
import dev.onvoid.webrtc.client.Subscription;
4546
import dev.onvoid.webrtc.client.WebRtc;
4647
import dev.onvoid.webrtc.client.internal.EncodedFrames;
4748
import dev.onvoid.webrtc.media.player.MediaInfo;
@@ -124,6 +125,16 @@ void startCall() throws Exception {
124125
remoteVideo.get(15, TimeUnit.SECONDS);
125126
remoteAudio.get(15, TimeUnit.SECONDS);
126127

128+
// A track that is signaled need not carry video yet: on a slow machine
129+
// the receiver may still wait for its first key frame, and a recorder
130+
// started then waits for one too, longer than it holds the file back
131+
// for it. The call is up once the remote video decodes.
132+
CountDownLatch decoded = new CountDownLatch(15);
133+
134+
try (Subscription frames = remoteVideo.join().asVideo().onFrame(frame -> decoded.countDown())) {
135+
assertTrue(decoded.await(15, TimeUnit.SECONDS), "no remote video decoded");
136+
}
137+
127138
// Well into the call, so that the recorder has to ask for a key frame.
128139
Thread.sleep(1500);
129140
}
@@ -141,14 +152,14 @@ void endCall() throws Exception {
141152
void recordsRemoteTracks() throws Exception {
142153
Path file = tempDir.resolve("received.mkv");
143154

144-
record(file, recorder -> {
155+
List<String> warnings = record(file, recorder -> {
145156
recorder.addTrack(remoteVideo.join());
146157
recorder.addTrack(remoteAudio.join());
147158
});
148159

149160
MediaInfo info = readInfo(file);
150161

151-
assertTrue(info.hasVideo());
162+
assertTrue(info.hasVideo(), () -> "No video, warnings: " + warnings);
152163
assertEquals(WIDTH, info.getVideoWidth());
153164
assertEquals(HEIGHT, info.getVideoHeight());
154165
assertEquals("opus", info.getAudioCodec());
@@ -242,9 +253,14 @@ private interface Tracks {
242253

243254
}
244255

245-
private static void record(Path file, Tracks tracks) throws Exception {
256+
/**
257+
* Records the given tracks into the file, and returns what the recorder
258+
* warned of, such as a track it had to leave out.
259+
*/
260+
private static List<String> record(Path file, Tracks tracks) throws Exception {
246261
CountDownLatch started = new CountDownLatch(1);
247262
AtomicReference<String> error = new AtomicReference<>();
263+
List<String> warnings = new CopyOnWriteArrayList<>();
248264

249265
try (MediaRecorder recorder = new MediaRecorder(file)) {
250266
recorder.setListener(new MediaRecorderListener() {
@@ -254,6 +270,11 @@ public void onStarted() {
254270
started.countDown();
255271
}
256272

273+
@Override
274+
public void onWarning(String message) {
275+
warnings.add(message);
276+
}
277+
257278
@Override
258279
public void onError(String message) {
259280
error.set(message);
@@ -269,6 +290,8 @@ public void onError(String message) {
269290
}
270291

271292
assertNull(error.get());
293+
294+
return warnings;
272295
}
273296

274297
private static MediaInfo readInfo(Path file) throws Exception {

0 commit comments

Comments
 (0)