RTCRtpSynchronizationSource-captureTimestamp.html (3717B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <!-- This file contains a test that waits for 2 seconds. --> 4 <meta name="timeout" content="long"> 5 <title>captureTimestamp attribute in RTCRtpSynchronizationSource</title> 6 <div><video id="remote" width="124" height="124" autoplay></video></div> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/webrtc/RTCPeerConnection-helper.js"></script> 10 <script src="/webrtc-extensions/RTCRtpSynchronizationSource-helper.js"></script> 11 <script> 12 'use strict'; 13 14 function listenForCaptureTimestamp(t, receiver) { 15 return new Promise((resolve) => { 16 function listen() { 17 const ssrcs = receiver.getSynchronizationSources(); 18 assert_true(ssrcs != undefined); 19 if (ssrcs.length > 0) { 20 assert_equals(ssrcs.length, 1); 21 if (ssrcs[0].captureTimestamp != undefined) { 22 resolve(ssrcs[0].captureTimestamp); 23 return true; 24 } 25 } 26 return false; 27 }; 28 t.step_wait(listen, 'No abs-capture-time capture time header extension.'); 29 }); 30 } 31 32 // Passes if `getSynchronizationSources()` contains `captureTimestamp` if and 33 // only if expected. 34 for (const kind of ['audio', 'video']) { 35 promise_test(async t => { 36 const [caller, callee] = await initiateSingleTrackCall( 37 t, /* caps= */{[kind]: true}, /* absCaptureTimeOffered= */false, 38 /* absCaptureTimeAnswered= */false); 39 const receiver = callee.getReceivers()[0]; 40 41 for (const ssrc of await listenForSSRCs(t, receiver)) { 42 assert_equals(typeof ssrc.captureTimestamp, 'undefined'); 43 } 44 }, '[' + kind + '] getSynchronizationSources() should not contain ' + 45 'captureTimestamp if absolute capture time RTP header extension is not ' + 46 'offered'); 47 48 promise_test(async t => { 49 const [caller, callee] = await initiateSingleTrackCall( 50 t, /* caps= */{[kind]: true}, /* absCaptureTimeOffered= */false, 51 /* absCaptureTimeAnswered= */false); 52 const receiver = callee.getReceivers()[0]; 53 54 for (const ssrc of await listenForSSRCs(t, receiver)) { 55 assert_equals(typeof ssrc.captureTimestamp, 'undefined'); 56 } 57 }, '[' + kind + '] getSynchronizationSources() should not contain ' + 58 'captureTimestamp if absolute capture time RTP header extension is ' + 59 'offered, but not answered'); 60 61 promise_test(async t => { 62 const [caller, callee] = await initiateSingleTrackCall( 63 t, /* caps= */{[kind]: true}, /* absCaptureTimeOffered= */true, 64 /* absCaptureTimeAnswered= */true); 65 const receiver = callee.getReceivers()[0]; 66 await listenForCaptureTimestamp(t, receiver); 67 }, '[' + kind + '] getSynchronizationSources() should contain ' + 68 'captureTimestamp if absolute capture time RTP header extension is ' + 69 'negotiated'); 70 } 71 72 // Passes if `captureTimestamp` for audio and video are comparable, which is 73 // expected since the test creates a local peer connection between `caller` and 74 // `callee`. 75 promise_test(async t => { 76 const [caller, callee] = await initiateSingleTrackCall( 77 t, /* caps= */{audio: true, video: true}, 78 /* absCaptureTimeOffered= */true, /* absCaptureTimeAnswered= */true); 79 const receivers = callee.getReceivers(); 80 assert_equals(receivers.length, 2); 81 82 let captureTimestamps = [undefined, undefined]; 83 const t0 = performance.now(); 84 for (let i = 0; i < 2; ++i) { 85 captureTimestamps[i] = await listenForCaptureTimestamp(t, receivers[i]); 86 } 87 const t1 = performance.now(); 88 assert_less_than(Math.abs(captureTimestamps[0] - captureTimestamps[1]), 89 t1 - t0); 90 }, 'Audio and video RTCRtpSynchronizationSource.captureTimestamp are ' + 91 'comparable'); 92 93 </script>