test_peerConnection_captureStream_canvas_2d_noSSRC.html (2676B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="pc.js"></script> 5 <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script> 6 </head> 7 <body> 8 <pre id="test"> 9 <script type="application/javascript"> 10 createHTML({ 11 title: "Canvas(2D)::CaptureStream as video-only input to peerconnection with no a=ssrc", 12 visible: true 13 }); 14 15 var test; 16 runNetworkTest(async (options) => { 17 // [TODO] re-enable HW decoder after bug 1526207 is fixed. 18 if (navigator.userAgent.includes("Android")) { 19 await pushPrefs(["media.navigator.mediadatadecoder_vpx_enabled", false], 20 ["media.webrtc.hw.h264.enabled", false]); 21 } 22 23 options = options || { }; 24 options.ssrc = false; 25 test = new PeerConnectionTest(options); 26 var mediaElement; 27 var h = new CaptureStreamTestHelper2D(); 28 var canvas = document.createElement('canvas'); 29 var stream; 30 canvas.id = 'source_canvas'; 31 canvas.width = canvas.height = 16; 32 document.getElementById('content').appendChild(canvas); 33 34 test.setMediaConstraints([{video: true}], []); 35 test.chain.replace("PC_LOCAL_GUM", [ 36 function PC_LOCAL_CANVAS_CAPTURESTREAM(test) { 37 h.drawColor(canvas, h.green); 38 stream = canvas.captureStream(0); 39 test.pcLocal.attachLocalStream(stream); 40 stream.requestFrame(); 41 var i = 0; 42 return setInterval(function() { 43 try { 44 info("draw " + i ? "green" : "red"); 45 h.drawColor(canvas, i ? h.green : h.red); 46 i = 1 - i; 47 stream.requestFrame(); 48 } catch (e) { 49 // ignore; stream might have shut down, and we don't bother clearing 50 // the setInterval. 51 } 52 }, 500); 53 } 54 ]); 55 test.chain.append([ 56 function PC_REMOTE_WAIT_FOR_REMOTE_GREEN() { 57 mediaElement = test.pcRemote.remoteMediaElements[0]; 58 ok(!!mediaElement, "Should have remote video element for pcRemote"); 59 return h.pixelMustBecome(mediaElement, h.green, { 60 threshold: 128, 61 infoString: "pcRemote's remote should become green", 62 }); 63 }, 64 function PC_LOCAL_DRAW_LOCAL_RED() { 65 // After requesting a frame it will be captured at the time of next render. 66 // Next render will happen at next stable state, at the earliest, 67 // i.e., this order of `requestFrame(); draw();` should work. 68 stream.requestFrame(); 69 h.drawColor(canvas, h.red); 70 }, 71 function PC_REMOTE_WAIT_FOR_REMOTE_RED() { 72 return h.pixelMustBecome(mediaElement, h.red, { 73 threshold: 128, 74 infoString: "pcRemote's remote should become red", 75 }); 76 } 77 ]); 78 await test.run(); 79 }); 80 </script> 81 </pre> 82 </body> 83 </html>