additional-codecs.html (2002B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Send additional codec supported by the other side</title> 4 <meta name=timeout content=long> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="../RTCPeerConnection-helper.js"></script> 8 <script> 9 'use strict'; 10 // Tests behaviour from 11 // https://www.rfc-editor.org/rfc/rfc8829.html#section-5.3.1 12 // in particular "but MAY include formats that are locally 13 // supported but not present in the offer" 14 15 promise_test(async t => { 16 const pc1 = new RTCPeerConnection(); 17 t.add_cleanup(() => pc1.close()); 18 const pc2 = new RTCPeerConnection(); 19 t.add_cleanup(() => pc2.close()); 20 exchangeIceCandidates(pc1, pc2); 21 22 const stream = await getNoiseStream({video: true}); 23 t.add_cleanup(() => stream.getTracks().forEach(t => t.stop())); 24 pc1.addTrack(stream.getTracks()[0], stream); 25 pc2.addTrack(stream.getTracks()[0], stream); 26 // Only offer VP8. 27 pc1.getTransceivers()[0].setCodecPreferences([{ 28 clockRate: 90000, 29 mimeType: 'video/VP8' 30 }]); 31 await pc1.setLocalDescription(); 32 33 // Add H264 to the SDP. 34 const sdp = pc1.localDescription.sdp.split('\n') 35 .map(l => { 36 if (l.startsWith('m=')) { 37 return l.trim() + ' 63'; // 63 is the least-likely to be used PT. 38 } 39 return l.trim(); 40 }).join('\r\n') + 41 'a=rtpmap:63 H264/90000\r\n' + 42 'a=fmtp:63 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\n' 43 await pc2.setRemoteDescription({ 44 type: 'offer', 45 sdp: sdp.replaceAll('VP8', 'no-such-codec'), // Remove VP8 46 }); 47 await pc2.setLocalDescription(); 48 await pc1.setRemoteDescription(pc2.localDescription); 49 50 await listenToConnected(pc2); 51 const stats = await pc1.getStats(); 52 const rtp = [...stats.values()].find(({type}) => type === 'outbound-rtp'); 53 assert_true(!!rtp); 54 assert_equals(stats.get(rtp.codecId).mimeType, 'video/H264'); 55 }, 'Listing an additional codec in the answer causes it to be sent.'); 56 </script>