transceiver-mline-recycling.html (3380B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>payload type handling (assuming rtcp-mux)</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="../third_party/sdp/sdp.js"></script> 7 <script> 8 promise_test(async t => { 9 const pc1 = new RTCPeerConnection(); 10 t.add_cleanup(() => pc1.close()); 11 const pc2 = new RTCPeerConnection(); 12 t.add_cleanup(() => pc2.close()); 13 const negotiate = async () => { 14 await pc1.setLocalDescription(); 15 await pc2.setRemoteDescription(pc1.localDescription); 16 await pc2.setLocalDescription(); 17 await pc1.setRemoteDescription(pc2.localDescription); 18 }; 19 20 // Add audio, negotiate, stop the transceiver, negotiate again, 21 // add another audio transceiver and negotiate. This should re-use the m-line. 22 pc1.addTransceiver('audio'); 23 await negotiate(); 24 pc1.getTransceivers()[0].stop(); 25 await negotiate(); 26 pc1.addTransceiver('audio'); 27 await negotiate(); 28 let numberOfMediaSections = SDPUtils.splitSections(pc1.localDescription.sdp).length - 1; 29 assert_equals(numberOfMediaSections, 1, 'Audio m-line gets reused for audio transceiver'); 30 31 // Stop the audio transceiver, negotiate, add a video transceiver, negotiate. 32 // This should reuse the m-line. 33 pc1.getTransceivers()[0].stop(); 34 await negotiate(); 35 pc1.addTransceiver('video'); 36 await negotiate(); 37 numberOfMediaSections = SDPUtils.splitSections(pc1.localDescription.sdp).length - 1; 38 assert_equals(numberOfMediaSections, 1, 'Audio m-line gets reused for video transceiver'); 39 40 // Add another video transceiver after stopping the current one. 41 // This should re-use the m-line. 42 pc1.getTransceivers()[0].stop(); 43 await negotiate(); 44 pc1.addTransceiver('video'); 45 await negotiate(); 46 numberOfMediaSections = SDPUtils.splitSections(pc1.localDescription.sdp).length - 1; 47 assert_equals(numberOfMediaSections, 1, 'Video m-line gets reused for video transceiver'); 48 }, 'Reuses m-lines in local negotiation'); 49 50 promise_test(async t => { 51 // SDP with a rejected video m-line. 52 const sdp = `v=0 53 o=- 0 3 IN IP4 127.0.0.1 54 s=- 55 t=0 0 56 a=fingerprint:sha-256 A7:24:72:CA:6E:02:55:39:BA:66:DF:6E:CC:4C:D8:B0:1A:BF:1A:56:65:7D:F4:03:AD:7E:77:43:2A:29:EC:93 57 m=video 0 UDP/TLS/RTP/SAVPF 100 58 c=IN IP4 0.0.0.0 59 a=rtcp-mux 60 a=sendonly 61 a=mid:video 62 a=rtpmap:100 VP8/90000 63 a=setup:actpass 64 a=ice-ufrag:ETEn 65 a=ice-pwd:OtSK0WpNtpUjkY4+86js7Z/l 66 `; 67 const pc1 = new RTCPeerConnection(); 68 t.add_cleanup(() => pc1.close()); 69 await pc1.setRemoteDescription({type: 'offer', sdp}); 70 await pc1.setLocalDescription(); 71 assert_equals(pc1.getTransceivers().length, 0); 72 pc1.addTransceiver('audio'); 73 let offer = await pc1.createOffer(); 74 let numberOfMediaSections = SDPUtils.splitSections(offer.sdp).length - 1; 75 assert_equals(numberOfMediaSections, 1, 'Remote video m-line gets reused for audio transceiver'); 76 77 const pc2 = new RTCPeerConnection(); 78 t.add_cleanup(() => pc2.close()); 79 await pc2.setRemoteDescription({type: 'offer', sdp}); 80 await pc2.setLocalDescription(); 81 assert_equals(pc2.getTransceivers().length, 0); 82 pc1.addTransceiver('video'); 83 offer = await pc2.createOffer(); 84 numberOfMediaSections = SDPUtils.splitSections(offer.sdp).length - 1; 85 assert_equals(numberOfMediaSections, 1, 'Remote video m-line gets reused for video transceiver'); 86 }, 'Reuses m-lines in remote negotiation'); 87 </script>