RTCPeerConnection-capture-video.https.html (2218B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset=utf-8> 5 <meta name="timeout" content="long"> 6 <script src=/resources/testharness.js></script> 7 <script src=/resources/testharnessreport.js></script> 8 <script src="RTCPeerConnection-helper.js"></script> 9 </head> 10 <body> 11 <script> 12 'use strict'; 13 14 // This test checks that <video> capture works via PeerConnection. 15 16 promise_test(async t => { 17 const sourceVideo = document.createElement('video'); 18 sourceVideo.src = "/media/test-v-128k-320x240-24fps-8kfr.webm"; 19 sourceVideo.loop = true; 20 21 const onCanPlay = new Promise(r => sourceVideo.oncanplay = r); 22 await onCanPlay; 23 24 const pc1 = new RTCPeerConnection(); 25 t.add_cleanup(() => pc1.close()); 26 const pc2 = new RTCPeerConnection(); 27 t.add_cleanup(() => pc2.close()); 28 29 // Attach video to pc1. 30 const stream = sourceVideo.captureStream(); 31 const tracks = stream.getTracks(); 32 pc1.addTrack(tracks[0]); 33 34 const destVideo = document.createElement('video'); 35 destVideo.autoplay = true; 36 37 // Setup pc1->pc2. 38 const haveTrackEvent1 = new Promise(r => pc2.ontrack = r); 39 exchangeIceCandidates(pc1, pc2); 40 await pc1.setLocalDescription(); 41 await pc2.setRemoteDescription(pc1.localDescription); 42 await pc2.setLocalDescription(); 43 await pc1.setRemoteDescription(pc2.localDescription); 44 45 // Display pc2 received track in video element. 46 const onLoadedMetadata = new Promise(r => destVideo.onloadedmetadata = r); 47 destVideo.srcObject = new MediaStream([(await haveTrackEvent1).track]); 48 49 // Start playback and wait for video on the other side. 50 sourceVideo.play(); 51 await onLoadedMetadata; 52 53 // Wait until the video has non-zero resolution and some non-black pixels. 54 await new Promise(p => { 55 function checkColor() { 56 if (destVideo.videoWidth > 0 && getVideoSignal(destVideo) > 0.0) 57 p(); 58 else 59 t.step_timeout(checkColor, 0); 60 } 61 checkColor(); 62 }); 63 64 // Uses Helper.js GetVideoSignal to query |destVideo| pixel value at a certain position. 65 const pixelValue = getVideoSignal(destVideo); 66 67 // Anything non-black means that capture works. 68 assert_not_equals(pixelValue, 0); 69 }, "Capturing a video element and sending it via PeerConnection"); 70 </script> 71 </body> 72 </html>