| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 var rtpStream = chrome.cast.streaming.rtpStream; | 5 var rtpStream = chrome.cast.streaming.rtpStream; |
| 6 var tabCapture = chrome.tabCapture; | 6 var tabCapture = chrome.tabCapture; |
| 7 var udpTransport = chrome.cast.streaming.udpTransport; | 7 var udpTransport = chrome.cast.streaming.udpTransport; |
| 8 var createSession = chrome.cast.streaming.session.create; | 8 var createSession = chrome.cast.streaming.session.create; |
| 9 var pass = chrome.test.callbackPass; | 9 var pass = chrome.test.callbackPass; |
| 10 | 10 |
| 11 function TestStateMachine(stream, audioId, videoId, udpId) { | 11 function TestStateMachine(stream, audioId, videoId, udpId) { |
| 12 this.stream = stream; | 12 this.stream = stream; |
| 13 this.audioId = audioId; | 13 this.audioId = audioId; |
| 14 this.videoId = videoId; | 14 this.videoId = videoId; |
| 15 this.udpId = udpId; | 15 this.udpId = udpId; |
| 16 this.audioStarted = false; | 16 this.audioStarted = false; |
| 17 this.videoStarted = false; | 17 this.videoStarted = false; |
| 18 this.audioStopped = false; | 18 this.audioStopped = false; |
| 19 this.videoStopped = false; | 19 this.videoStopped = false; |
| 20 this.gotAudioRawEvents = false; |
| 21 this.gotVideoRawEvents = false; |
| 20 } | 22 } |
| 21 | 23 |
| 22 TestStateMachine.prototype.onStarted = function(id) { | 24 TestStateMachine.prototype.onStarted = function(id) { |
| 23 if (id == this.audioId) | 25 if (id == this.audioId) |
| 24 this.audioStarted = true; | 26 this.audioStarted = true; |
| 25 if (id == this.videoId) | 27 if (id == this.videoId) |
| 26 this.videoStarted = true; | 28 this.videoStarted = true; |
| 27 if (this.audioStarted && this.videoStarted) | 29 if (this.audioStarted && this.videoStarted) |
| 28 this.onAllStarted(); | 30 this.onAllStarted(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 TestStateMachine.prototype.onStopped = function(id) { | 33 TestStateMachine.prototype.onStopped = function(id) { |
| 32 if (id == this.audioId) | 34 if (id == this.audioId) |
| 33 this.audioStopped = true; | 35 this.audioStopped = true; |
| 34 if (id == this.videoId) | 36 if (id == this.videoId) |
| 35 this.videoStopped = true; | 37 this.videoStopped = true; |
| 36 if (this.audioStopped && this.videoStopped) | 38 if (this.audioStopped && this.videoStopped) |
| 37 this.onAllStopped(); | 39 this.onAllStopped(); |
| 38 } | 40 } |
| 39 | 41 |
| 42 TestStateMachine.prototype.onGotRawEvents = function(id, rawEvents) { |
| 43 if (id == this.audioId) { |
| 44 this.gotAudioRawEvents = true; |
| 45 } |
| 46 if (id == this.videoId) { |
| 47 this.gotVideoRawEvents = true; |
| 48 } |
| 49 if (this.gotAudioRawEvents && this.gotVideoRawEvents) |
| 50 this.onGotAllRawEvents(); |
| 51 } |
| 52 |
| 40 chrome.test.runTests([ | 53 chrome.test.runTests([ |
| 41 function rtpStreamStart() { | 54 function rtpStreamStart() { |
| 42 console.log("[TEST] rtpStreamStart"); | 55 console.log("[TEST] rtpStreamStart"); |
| 43 tabCapture.capture({audio: true, video: true}, | 56 tabCapture.capture({audio: true, video: true}, |
| 44 pass(function(stream) { | 57 pass(function(stream) { |
| 45 console.log("Got MediaStream."); | 58 console.log("Got MediaStream."); |
| 46 chrome.test.assertTrue(!!stream); | 59 chrome.test.assertTrue(!!stream); |
| 47 createSession(stream.getAudioTracks()[0], | 60 createSession(stream.getAudioTracks()[0], |
| 48 stream.getVideoTracks()[0], | 61 stream.getVideoTracks()[0], |
| 49 pass(function(stream, audioId, videoId, udpId) { | 62 pass(function(stream, audioId, videoId, udpId) { |
| 50 console.log("Starting."); | 63 console.log("Starting."); |
| 51 var stateMachine = new TestStateMachine(stream, | 64 var stateMachine = new TestStateMachine(stream, |
| 52 audioId, | 65 audioId, |
| 53 videoId, | 66 videoId, |
| 54 udpId); | 67 udpId); |
| 55 var audioParams = rtpStream.getSupportedParams(audioId)[0]; | 68 var audioParams = rtpStream.getSupportedParams(audioId)[0]; |
| 56 var videoParams = rtpStream.getSupportedParams(videoId)[0]; | 69 var videoParams = rtpStream.getSupportedParams(videoId)[0]; |
| 57 chrome.test.assertEq(audioParams.payload.codecName, "OPUS"); | 70 chrome.test.assertEq(audioParams.payload.codecName, "OPUS"); |
| 58 chrome.test.assertEq(videoParams.payload.codecName, "VP8"); | 71 chrome.test.assertEq(videoParams.payload.codecName, "VP8"); |
| 59 udpTransport.setDestination(udpId, | 72 udpTransport.setDestination(udpId, |
| 60 {address: "127.0.0.1", port: 2344}); | 73 {address: "127.0.0.1", port: 2344}); |
| 61 rtpStream.onStarted.addListener( | 74 rtpStream.onStarted.addListener( |
| 62 stateMachine.onStarted.bind(stateMachine)); | 75 stateMachine.onStarted.bind(stateMachine)); |
| 63 stateMachine.onAllStarted = | 76 stateMachine.onAllStarted = |
| 64 pass(function(audioId, videoId) { | 77 pass(function(audioId, videoId) { |
| 78 console.log("Enabling logging."); |
| 79 rtpStream.toggleLogging(audioId, true); |
| 80 rtpStream.toggleLogging(videoId, true); |
| 65 console.log("Stopping."); | 81 console.log("Stopping."); |
| 66 rtpStream.stop(audioId); | 82 rtpStream.stop(audioId); |
| 67 rtpStream.stop(videoId); | 83 rtpStream.stop(videoId); |
| 68 }.bind(null, audioId, videoId)); | 84 }.bind(null, audioId, videoId)); |
| 69 rtpStream.onStopped.addListener( | 85 rtpStream.onStopped.addListener( |
| 70 stateMachine.onStopped.bind(stateMachine)); | 86 stateMachine.onStopped.bind(stateMachine)); |
| 71 stateMachine.onAllStopped = | 87 stateMachine.onAllStopped = |
| 88 pass(function(audioId, videoId) { |
| 89 rtpStream.getRawEvents(audioId, |
| 90 stateMachine.onGotRawEvents.bind(stateMachine, audioId)); |
| 91 rtpStream.getRawEvents(videoId, |
| 92 stateMachine.onGotRawEvents.bind(stateMachine, videoId)); |
| 93 }.bind(null, audioId, videoId)); |
| 94 stateMachine.onGotAllRawEvents = |
| 72 pass(function(stream, audioId, videoId, udpId) { | 95 pass(function(stream, audioId, videoId, udpId) { |
| 96 console.log("Disabling logging."); |
| 97 rtpStream.toggleLogging(audioId, false); |
| 98 rtpStream.toggleLogging(videoId, false); |
| 73 console.log("Destroying."); | 99 console.log("Destroying."); |
| 74 rtpStream.destroy(audioId); | 100 rtpStream.destroy(audioId); |
| 75 rtpStream.destroy(videoId); | 101 rtpStream.destroy(videoId); |
| 76 udpTransport.destroy(udpId); | 102 udpTransport.destroy(udpId); |
| 77 chrome.test.assertEq(audioParams.payload.codecName, "OPUS"); | 103 chrome.test.assertEq(audioParams.payload.codecName, "OPUS"); |
| 78 chrome.test.assertEq(videoParams.payload.codecName, "VP8"); | 104 chrome.test.assertEq(videoParams.payload.codecName, "VP8"); |
| 79 chrome.test.succeed(); | 105 chrome.test.succeed(); |
| 80 }.bind(null, stream, audioId, videoId, udpId)); | 106 }.bind(null, stream, audioId, videoId, udpId)); |
| 81 rtpStream.start(audioId, audioParams); | 107 rtpStream.start(audioId, audioParams); |
| 82 rtpStream.start(videoId, videoParams); | 108 rtpStream.start(videoId, videoParams); |
| 83 }.bind(null, stream))); | 109 }.bind(null, stream))); |
| 84 })); | 110 })); |
| 85 }, | 111 }, |
| 86 ]); | 112 ]); |
| OLD | NEW |