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
3 // found in the LICENSE file.
5 var rtpStream = chrome.cast.streaming.rtpStream;
6 var tabCapture = chrome.tabCapture;
7 var udpTransport = chrome.cast.streaming.udpTransport;
8 var createSession = chrome.cast.streaming.session.create;
9 var pass = chrome.test.callbackPass;
11 chrome.test.runTests([
13 console.log("[TEST] getStats");
14 tabCapture.capture({audio: true, video: true},
15 pass(function(stream) {
16 console.log("Got MediaStream.");
17 chrome.test.assertTrue(!!stream);
18 createSession(stream.getAudioTracks()[0],
19 stream.getVideoTracks()[0],
20 pass(function(stream, audioId, videoId, udpId) {
21 console.log("Starting.");
22 var stateMachine = new TestStateMachine(stream,
26 var audioParams = rtpStream.getSupportedParams(audioId)[0];
27 var videoParams = rtpStream.getSupportedParams(videoId)[0];
28 chrome.test.assertTrue(!!audioParams.payload.codecName);
29 chrome.test.assertTrue(!!videoParams.payload.codecName);
30 udpTransport.setDestination(udpId,
31 {address: "127.0.0.1", port: 2344});
32 rtpStream.onStarted.addListener(
33 stateMachine.onStarted.bind(stateMachine));
34 stateMachine.onAllStarted =
35 pass(function(audioId, videoId) {
36 console.log("Enabling logging.");
37 rtpStream.toggleLogging(audioId, true);
38 rtpStream.toggleLogging(videoId, true);
39 console.log("Stopping.");
40 rtpStream.stop(audioId);
41 rtpStream.stop(videoId);
42 }.bind(null, audioId, videoId));
43 rtpStream.onStopped.addListener(
44 stateMachine.onStopped.bind(stateMachine));
45 stateMachine.onAllStopped =
46 pass(function(audioId, videoId) {
47 rtpStream.getStats(audioId,
48 stateMachine.onGotStats.bind(stateMachine, audioId));
49 rtpStream.getStats(videoId,
50 stateMachine.onGotStats.bind(stateMachine, videoId));
51 }.bind(null, audioId, videoId));
52 stateMachine.onGotAllLogs =
53 pass(function(stream, audioId, videoId, udpId) {
54 console.log("Disabling logging.");
55 rtpStream.toggleLogging(audioId, false);
56 rtpStream.toggleLogging(videoId, false);
57 console.log("Destroying.");
58 rtpStream.destroy(audioId);
59 rtpStream.destroy(videoId);
60 udpTransport.destroy(udpId);
61 chrome.test.assertTrue(!!audioParams.payload.codecName);
62 chrome.test.assertTrue(!!videoParams.payload.codecName);
63 chrome.test.succeed();
64 }.bind(null, stream, audioId, videoId, udpId));
65 rtpStream.start(audioId, audioParams);
66 rtpStream.start(videoId, videoParams);
67 }.bind(null, stream)));