| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Run a cast v2 mirroring session for 10 seconds. | 5 // Run a cast v2 mirroring session for 10 seconds. |
| 6 | 6 |
| 7 chrome.test.runTests([ | 7 chrome.test.runTests([ |
| 8 function sendTestPatterns() { | 8 function sendTestPatterns() { |
| 9 // The receive port changes between browser_test invocations, and is passed | 9 // The receive port changes between browser_test invocations, and is passed |
| 10 // as an query parameter in the URL. | 10 // as an query parameter in the URL. |
| 11 var recvPort; | 11 let recvPort; |
| 12 let autoThrottling; |
| 13 let aesKey; |
| 14 let aesIvMask; |
| 12 try { | 15 try { |
| 13 recvPort = parseInt(window.location.search.substring("?port=".length)); | 16 const params = window.location.search; |
| 17 recvPort = parseInt(params.match(/(\?|&)port=(\d+)/)[2]); |
| 14 chrome.test.assertTrue(recvPort > 0); | 18 chrome.test.assertTrue(recvPort > 0); |
| 19 autoThrottling = (params.match(/(\?|&)autoThrottling=(true|false)/)[2] == |
| 20 'true'); |
| 21 aesKey = params.match(/(\?|&)aesKey=([0-9A-F]{32})/)[2]; |
| 22 aesIvMask = params.match(/(\?|&)aesIvMask=([0-9A-F]{32})/)[2]; |
| 15 } catch (err) { | 23 } catch (err) { |
| 16 chrome.test.fail("Error parsing ?port=### -- " + err.message); | 24 chrome.test.fail("Error parsing params -- " + err.message); |
| 17 return; | 25 return; |
| 18 } | 26 } |
| 19 | 27 |
| 20 var width = 1920; | 28 const kMaxFrameRate = 30; |
| 21 var height = 1080; | |
| 22 var frameRate = 30; | |
| 23 | |
| 24 chrome.tabCapture.capture( | 29 chrome.tabCapture.capture( |
| 25 { video: true, | 30 { video: true, |
| 26 audio: true, | 31 audio: true, |
| 27 videoConstraints: { | 32 videoConstraints: { |
| 28 mandatory: { | 33 mandatory: autoThrottling ? ({ |
| 29 minWidth: width, | 34 minWidth: 320, |
| 30 minHeight: height, | 35 minHeight: 180, |
| 31 maxWidth: width, | 36 maxWidth: 1920, |
| 32 maxHeight: height, | 37 maxHeight: 1080, |
| 33 maxFrameRate: frameRate, | 38 maxFrameRate: kMaxFrameRate, |
| 34 } | 39 enableAutoThrottling: true |
| 40 }) : ({ |
| 41 minWidth: 1920, |
| 42 minHeight: 1080, |
| 43 maxWidth: 1920, |
| 44 maxHeight: 1080, |
| 45 maxFrameRate: kMaxFrameRate, |
| 46 }) |
| 35 } | 47 } |
| 36 }, | 48 }, |
| 37 function startStreamingTestPatterns(captureStream) { | 49 captureStream => { |
| 38 chrome.test.assertTrue(!!captureStream); | 50 if (!captureStream) { |
| 51 chrome.test.fail(chrome.runtime.lastError.message || 'null stream'); |
| 52 return; |
| 53 } |
| 54 |
| 39 chrome.cast.streaming.session.create( | 55 chrome.cast.streaming.session.create( |
| 40 captureStream.getAudioTracks()[0], | 56 captureStream.getAudioTracks()[0], |
| 41 captureStream.getVideoTracks()[0], | 57 captureStream.getVideoTracks()[0], |
| 42 function (audioId, videoId, udpId) { | 58 (audioId, videoId, udpId) => { |
| 43 chrome.cast.streaming.udpTransport.setDestination( | 59 chrome.cast.streaming.udpTransport.setDestination( |
| 44 udpId, { address: "127.0.0.1", port: recvPort } ); | 60 udpId, { address: "127.0.0.1", port: recvPort } ); |
| 45 var rtpStream = chrome.cast.streaming.rtpStream; | 61 const rtpStream = chrome.cast.streaming.rtpStream; |
| 46 rtpStream.start(audioId, | 62 rtpStream.onError.addListener(() => { |
| 47 rtpStream.getSupportedParams(audioId)[0]); | 63 chrome.test.fail('RTP stream error'); |
| 48 var videoParams = rtpStream.getSupportedParams(videoId)[0]; | 64 }); |
| 49 videoParams.payload.clockRate = frameRate; | 65 const audioParams = rtpStream.getSupportedParams(audioId)[0]; |
| 66 audioParams.payload.aesKey = aesKey; |
| 67 audioParams.payload.aesIvMask = aesIvMask; |
| 68 rtpStream.start(audioId, audioParams); |
| 69 const videoParams = rtpStream.getSupportedParams(videoId)[0]; |
| 70 videoParams.payload.clockRate = kMaxFrameRate; |
| 71 videoParams.payload.aesKey = aesKey; |
| 72 videoParams.payload.aesIvMask = aesIvMask; |
| 50 rtpStream.start(videoId, videoParams); | 73 rtpStream.start(videoId, videoParams); |
| 51 setTimeout(function () { | 74 setTimeout(() => { |
| 52 chrome.test.succeed(); | 75 chrome.test.succeed(); |
| 76 |
| 53 rtpStream.stop(audioId); | 77 rtpStream.stop(audioId); |
| 54 rtpStream.stop(videoId); | 78 rtpStream.stop(videoId); |
| 55 }, 20000); // 20 seconds | 79 rtpStream.destroy(audioId); |
| 80 rtpStream.destroy(videoId); |
| 81 |
| 82 const tracks = captureStream.getTracks(); |
| 83 for (let i = 0; i < tracks.length; ++i) { |
| 84 tracks[i].stop(); |
| 85 } |
| 86 chrome.test.assertFalse(captureStream.active); |
| 87 }, 15000); // 15 seconds |
| 56 }); | 88 }); |
| 57 }); | 89 }); |
| 58 } | 90 } |
| 59 ]); | 91 ]); |
| OLD | NEW |