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.assertEq(audioParams.payload.codecName, "OPUS");
32 chrome.test.assertEq(videoParams.payload.codecName, "VP8");
33 udpTransport.setDestination(udpId,
34 {address: "127.0.0.1", port: 2344});
35 rtpStream.onStarted.addListener(
36 stateMachine.onStarted.bind(stateMachine));
37 stateMachine.onAllStarted =
38 pass(function(audioId, videoId) {
39 console.log("Enabling logging.");
40 rtpStream.toggleLogging(audioId, true);
41 rtpStream.toggleLogging(videoId, true);
42 console.log("Stopping.");
43 rtpStream.stop(audioId);
44 rtpStream.stop(videoId);
45 }.bind(null, audioId, videoId));
46 rtpStream.onStopped.addListener(
47 stateMachine.onStopped.bind(stateMachine));
48 stateMachine.onAllStopped =
49 pass(function(audioId, videoId) {
50 rtpStream.getRawEvents(audioId,
51 stateMachine.onGotRawEvents.bind(stateMachine, audioId));
52 rtpStream.getRawEvents(videoId,
53 stateMachine.onGotRawEvents.bind(stateMachine, videoId));
54 }.bind(null, audioId, videoId));
55 stateMachine.onGotAllLogs =
56 pass(function(stream, audioId, videoId, udpId) {
57 console.log("Disabling logging.");
58 rtpStream.toggleLogging(audioId, false);
59 rtpStream.toggleLogging(videoId, false);
60 console.log("Destroying.");
61 rtpStream.destroy(audioId);
62 rtpStream.destroy(videoId);
63 udpTransport.destroy(udpId);
64 chrome.test.assertEq(audioParams.payload.codecName, "OPUS");
65 chrome.test.assertEq(videoParams.payload.codecName, "VP8");
66 chrome.test.succeed();
67 }.bind(null, stream, audioId, videoId, udpId));
68 rtpStream.start(audioId, audioParams);
69 rtpStream.start(videoId, videoParams);
70 }.bind(null, stream)));