test_peerConnection_scaleResolution_oldSetParameters.html (4611B)
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: "1244913", 11 title: "Scale resolution down on a PeerConnection", 12 visible: true 13 }); 14 15 let resolutionAlignment = 1; 16 17 var mustRejectWith = (msg, reason, f) => 18 f().then(() => ok(false, msg), 19 e => is(e.name, reason, msg)); 20 21 async function testScale(codec) { 22 var pc1 = new RTCPeerConnection(); 23 var pc2 = new RTCPeerConnection(); 24 25 var add = (pc, can, failed) => can && pc.addIceCandidate(can).catch(failed); 26 pc1.onicecandidate = e => add(pc2, e.candidate, generateErrorCallback()); 27 pc2.onicecandidate = e => add(pc1, e.candidate, generateErrorCallback()); 28 29 info("testing scaling with " + codec); 30 31 let stream = await navigator.mediaDevices.getUserMedia({ video: true }); 32 33 var v1 = createMediaElement('video', 'v1'); 34 var v2 = createMediaElement('video', 'v2'); 35 36 var ontrackfired = new Promise(resolve => pc2.ontrack = e => resolve(e)); 37 var v2loadedmetadata = new Promise(resolve => v2.onloadedmetadata = resolve); 38 39 is(v2.currentTime, 0, "v2.currentTime is zero at outset"); 40 41 v1.srcObject = stream; 42 var sender = pc1.addTrack(stream.getVideoTracks()[0], stream); 43 44 const otherErrorStart = await GleanTest.rtcrtpsenderSetparameters.failOther.testGetValue(); 45 const noTransactionIdWarningStart = await GleanTest.rtcrtpsenderSetparameters.warnNoTransactionid.testGetValue(); 46 47 await mustRejectWith( 48 "Invalid scaleResolutionDownBy must reject", "RangeError", 49 () => sender.setParameters( 50 { encodings:[{ scaleResolutionDownBy: 0.5 } ] }) 51 ); 52 53 const otherErrorEnd = await GleanTest.rtcrtpsenderSetparameters.failOther.testGetValue(); 54 const noTransactionIdWarningEnd = await GleanTest.rtcrtpsenderSetparameters.warnNoTransactionid.testGetValue(); 55 56 // Make sure Glean is recording these statistics 57 is(otherErrorEnd.denominator, otherErrorStart.denominator, "No new RTCRtpSenders were created during this time"); 58 is(otherErrorEnd.numerator, otherErrorStart.numerator + 1, "RTCRtpSender.setParameters reported a failure via Glean"); 59 is(noTransactionIdWarningEnd.denominator, noTransactionIdWarningStart.denominator, "No new RTCRtpSenders were created during this time"); 60 is(noTransactionIdWarningEnd.numerator, noTransactionIdWarningStart.numerator + 1, "Glean should have recorded a warning due to missing transactionId"); 61 62 await sender.setParameters({ encodings: [{ maxBitrate: 60000, 63 scaleResolutionDownBy: 2 }] }); 64 65 let offer = await pc1.createOffer(); 66 offer.sdp = sdputils.removeAllButCodec(offer.sdp, codec); 67 await pc1.setLocalDescription(offer); 68 await pc2.setRemoteDescription(pc1.localDescription); 69 70 let answer = await pc2.createAnswer(); 71 await pc2.setLocalDescription(answer); 72 await pc1.setRemoteDescription(pc2.localDescription); 73 let trackevent = await ontrackfired; 74 75 v2.srcObject = trackevent.streams[0]; 76 77 await v2loadedmetadata; 78 79 await waitUntil(() => v2.currentTime > 0); 80 ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")"); 81 82 ok(v1.videoWidth > 0, "source width is positive"); 83 ok(v1.videoHeight > 0, "source height is positive"); 84 const expectedWidth = 85 v1.videoWidth / 2 - (v1.videoWidth / 2 % resolutionAlignment); 86 const expectedHeight = 87 v1.videoHeight / 2 - (v1.videoHeight / 2 % resolutionAlignment); 88 is(v2.videoWidth, expectedWidth, 89 "sink is half the width of the source"); 90 is(v2.videoHeight, expectedHeight, 91 "sink is half the height of the source"); 92 stream.getTracks().forEach(track => track.stop()); 93 v1.srcObject = v2.srcObject = null; 94 pc1.close() 95 pc2.close() 96 } 97 98 runNetworkTest(async () => { 99 await pushPrefs( 100 ['media.peerconnection.video.lock_scaling', true], 101 // Disable h264 hardware support, to ensure it is not prioritized over VP8 102 ["media.webrtc.hw.h264.enabled", false], 103 // Use libwebrtc VP8 encoder to avoid unexpected resolution alignment on 104 // some devices. 105 ["media.webrtc.encoder_creation_strategy", 0], 106 ); 107 await testScale("VP8"); 108 109 const h264Support = checkPlatformH264CodecPrefs(); 110 if (!h264Support.webrtc) { 111 // MediaDataEncoder always uses 16-alignment. 112 resolutionAlignment = 16; 113 } 114 if (h264Support.any) { 115 await testScale("H264"); 116 } 117 }); 118 </script> 119 </pre> 120 </body> 121 </html>