test_peerConnection_audioCodecs.html (2531B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="pc.js"></script> 5 </head> 6 <body> 7 <pre id="test"> 8 <script type="application/javascript"> 9 createHTML({ 10 bug: "1395853", 11 title: "Verify audio content over WebRTC for every audio codec", 12 }); 13 14 // We match the format member against the sdp to figure out the payload type, 15 // So all other present codecs can be removed. 16 const codecs = [ "opus", "G722", "PCMU", "PCMA" ]; 17 const audioContext = new AudioContext(); 18 19 async function testAudioCodec(options = {}, codec) { 20 // sdputils checks for opus as part of its sdp sanity test 21 options.opus = codec == "opus"; 22 23 let test = new PeerConnectionTest(options); 24 test.setMediaConstraints([{audio: true}], []); 25 26 test.chain.insertBefore("PC_LOCAL_SET_LOCAL_DESCRIPTION", [ 27 function PC_LOCAL_FILTER_OUT_CODECS() { 28 let otherCodec = codecs.find(c => c != codec); 29 let id = sdputils.findCodecId(test.originalOffer.sdp, codec); 30 let otherId = sdputils.findCodecId(test.originalOffer.sdp, otherCodec); 31 32 test.originalOffer.sdp = 33 sdputils.removeAllButCodec(test.originalOffer.sdp, codec); 34 35 ok(!test.originalOffer.sdp.match(new RegExp(`m=.*UDP/TLS/RTP/SAVPF.* ${otherId}[^0-9]`, "gi")), 36 `Other codec ${otherId} should be removed after filtering`); 37 ok(test.originalOffer.sdp.match(new RegExp(`m=.*UDP/TLS/RTP/SAVPF.* ${id}[^0-9]`, "gi")), 38 `Tested codec ${id} should remain after filtering`); 39 }, 40 ]); 41 42 test.chain.append([ 43 async function CHECK_AUDIO_FLOW() { 44 try { 45 await test.pcRemote.checkReceivingToneFrom(audioContext, test.pcLocal); 46 ok(true, "input and output audio data matches"); 47 } catch(e) { 48 ok(false, `No audio flow: ${e}`); 49 } 50 }, 51 ]); 52 53 await test.run(); 54 } 55 56 runNetworkTest(async (options) => { 57 // Start a tone so that the gUM call will record something even with 58 // --use-test-media-devices. TEST_AUDIO_FREQ matches the frequency of the 59 // tone in fake microphone devices. 60 const tone = new LoopbackTone(audioContext, TEST_AUDIO_FREQ); 61 tone.start(); 62 63 for (let codec of codecs) { 64 info(`Testing audio for codec ${codec}`); 65 try { 66 await testAudioCodec(options, codec); 67 } catch(e) { 68 ok(false, `Error in test for codec ${codec}: ${e}\n${e.stack}`); 69 } 70 info(`Tested audio for codec ${codec}`); 71 } 72 73 tone.stop(); 74 }); 75 </script> 76 </pre> 77 </body> 78 </html>