test_peerConnection_sillyCodecPriorities.html (3174B)
1 <!DOCTYPE HTML> 2 <html> 3 4 <head> 5 <script type="application/javascript" src="pc.js"></script> 6 <script type="application/javascript" src="sdpUtils.js"></script> 7 </head> 8 9 <body> 10 <pre id="test"> 11 <script type="application/javascript"> 12 createHTML({ 13 bug: "1873801", 14 title: "Test that weird codec priorities don't trip us up", 15 visible: true 16 }); 17 18 function makeCodecTopPriority({type, sdp}, codec) { 19 const ptToMove = sdputils.findCodecId(sdp, codec); 20 return {type, sdp: sdp.replace( 21 // m=video port type pts ptToMove more-pts? 22 new RegExp(`(m=video [^ ]+ [^ ]+)(.*)( ${ptToMove})( [^ ]+)?`, "g"), 23 '$1$3$2$4')}; 24 } 25 26 function isCodecFirst(sdp, codec) { 27 const pt = sdputils.findCodecId(sdp, codec); 28 return !!sdp.match(`m=video [^ ]+ [^ ]+ ${pt}\w`); 29 } 30 31 async function checkTopPriorityOffer(codec, isPseudoCodec) { 32 const pc1 = new RTCPeerConnection(); 33 const pc2 = new RTCPeerConnection(); 34 const stream = await navigator.mediaDevices.getUserMedia({ video: true }); 35 const sender = pc1.addTrack(stream.getTracks()[0]); 36 await pc1.setLocalDescription(); 37 const mungedOffer = makeCodecTopPriority(pc1.localDescription, codec); 38 await pc2.setRemoteDescription(mungedOffer); 39 await pc2.setLocalDescription(); 40 await pc1.setRemoteDescription(pc2.localDescription); 41 is(isCodecFirst((await pc2.createOffer()).sdp, codec), !isPseudoCodec, 42 "Top-priority codecs should come first in reoffers, unless they are pseudo codecs (eg; ulpfec)"); 43 } 44 45 async function checkTopPriorityAnswer(codec, isPseudoCodec) { 46 const pc1 = new RTCPeerConnection(); 47 const pc2 = new RTCPeerConnection(); 48 const stream = await navigator.mediaDevices.getUserMedia({ video: true }); 49 const sender = pc1.addTrack(stream.getTracks()[0]); 50 await pc1.setLocalDescription(); 51 await pc2.setRemoteDescription(pc1.localDescription); 52 await pc2.setLocalDescription(); 53 const mungedAnswer = makeCodecTopPriority(pc2.localDescription, codec); 54 await pc1.setRemoteDescription(mungedAnswer); 55 is(isCodecFirst((await pc1.createOffer()).sdp, codec), !isPseudoCodec, 56 "Top-priority codecs should come first in reoffers, unless they are pseudo codecs (eg; ulpfec)"); 57 } 58 59 const tests = [ 60 async function checkTopPriorityUlpfecInOffer() { 61 await checkTopPriorityOffer("ulpfec", true); 62 }, 63 64 async function checkTopPriorityUlpfecInAnswer() { 65 await checkTopPriorityAnswer("ulpfec", true); 66 }, 67 68 async function checkTopPriorityUlpfecInOffer() { 69 await checkTopPriorityOffer("red", true); 70 }, 71 72 async function checkTopPriorityUlpfecInAnswer() { 73 await checkTopPriorityAnswer("red", true); 74 }, 75 76 async function checkTopPriorityUlpfecInOffer() { 77 await checkTopPriorityOffer("rtx", true); 78 }, 79 80 async function checkTopPriorityUlpfecInAnswer() { 81 await checkTopPriorityAnswer("rtx", true); 82 }, 83 84 ]; 85 86 runNetworkTest(async () => { 87 for (const test of tests) { 88 info(`Running test: ${test.name}`); 89 await test(); 90 info(`Done running test: ${test.name}`); 91 } 92 }); 93 94 </script> 95 </pre> 96 </body> 97 </html>