rtp-clockrate.html (1694B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <!-- This file contains a test that waits for two seconds. --> 4 <meta name="timeout" content="long"> 5 <title>RTP clockrate</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="../RTCPeerConnection-helper.js"></script> 9 <script> 10 'use strict'; 11 12 async function initiateSingleTrackCallAndReturnReceiver(t, kind) { 13 const pc1 = new RTCPeerConnection(); 14 t.add_cleanup(() => pc1.close()); 15 const pc2 = new RTCPeerConnection(); 16 t.add_cleanup(() => pc2.close()); 17 18 const stream = await getNoiseStream({[kind]:true}); 19 const [track] = stream.getTracks(); 20 t.add_cleanup(() => track.stop()); 21 pc1.addTrack(track, stream); 22 23 exchangeIceCandidates(pc1, pc2); 24 const trackEvent = await exchangeOfferAndListenToOntrack(t, pc1, pc2); 25 await exchangeAnswer(pc1, pc2); 26 await waitForConnectionStateChange(pc2, ['connected']); 27 return trackEvent.receiver; 28 } 29 30 promise_test(async t => { 31 // the getSynchronizationSources API exposes the rtp timestamp. 32 const receiver = await initiateSingleTrackCallAndReturnReceiver(t, 'video'); 33 const first = await listenForSSRCs(t, receiver); 34 await new Promise(resolve => t.step_timeout(resolve, 2000)); 35 const second = await listenForSSRCs(t, receiver); 36 // rtpTimestamp may wrap at 0xffffffff, take care of that. 37 const actualClockRate = ((second[0].rtpTimestamp - first[0].rtpTimestamp + 0xffffffff) % 0xffffffff) / (second[0].timestamp - first[0].timestamp) * 1000; 38 assert_approx_equals(actualClockRate, 90000, 9000, 'Video clockrate is approximately 90000'); 39 }, 'video rtp timestamps increase by approximately 90000 per second'); 40 </script>