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
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([
12 function rtpStreamStart() {
13 console.log("[TEST] rtpStreamStart");
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 chrome.test.assertTrue(audioId > 0);
22 chrome.test.assertTrue(videoId > 0);
23 chrome.test.assertTrue(udpId > 0);
24 console.log("Starting.");
25 var stateMachine = new TestStateMachine(stream,
29 var audioParams = rtpStream.getSupportedParams(audioId)[0];
30 var videoParams = rtpStream.getSupportedParams(videoId)[0];
31 chrome.test.assertTrue(!!audioParams.payload.codecName);
32 chrome.test.assertTrue(!!videoParams.payload.codecName);
33 udpTransport.setOptions(udpId, {DSCP: true});
34 udpTransport.setDestination(udpId,
35 {address: "127.0.0.1", port: 2344});
36 rtpStream.onStarted.addListener(
37 stateMachine.onStarted.bind(stateMachine));
38 stateMachine.onAllStarted =
39 pass(function(audioId, videoId) {
40 console.log("Enabling logging.");
41 rtpStream.toggleLogging(audioId, true);
42 rtpStream.toggleLogging(videoId, true);
43 console.log("Stopping.");
44 rtpStream.stop(audioId);
45 rtpStream.stop(videoId);
46 }.bind(null, audioId, videoId));
47 rtpStream.onStopped.addListener(
48 stateMachine.onStopped.bind(stateMachine));
49 stateMachine.onAllStopped =
50 pass(function(audioId, videoId) {
51 var videoExtraData = JSON.stringify({ "videoExtraData": "100" });
52 rtpStream.getRawEvents(audioId,
53 stateMachine.onGotRawEvents.bind(stateMachine, audioId));
54 rtpStream.getRawEvents(videoId,
56 stateMachine.onGotRawEvents.bind(stateMachine, videoId));
57 }.bind(null, audioId, videoId));
58 stateMachine.onGotAllLogs =
59 pass(function(stream, audioId, videoId, udpId) {
60 console.log("Disabling logging.");
61 rtpStream.toggleLogging(audioId, false);
62 rtpStream.toggleLogging(videoId, false);
63 console.log("Destroying.");
64 rtpStream.destroy(audioId);
65 rtpStream.destroy(videoId);
66 udpTransport.destroy(udpId);
67 chrome.test.assertTrue(!!audioParams.payload.codecName);
68 chrome.test.assertTrue(!!videoParams.payload.codecName);
69 chrome.test.succeed();
70 }.bind(null, stream, audioId, videoId, udpId));
71 rtpStream.start(audioId, audioParams);
72 rtpStream.start(videoId, videoParams);
73 }.bind(null, stream)));