Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Side by Side Diff: chrome/test/data/webrtc/getusermedia.js

Issue 12472032: Add screen capture constraints, video tag resize and removed auto video resize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testingscreen
Patch Set: gjslint issues + fixed if statement for constraints Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /** 1 /**
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /** 7 /**
8 * See http://dev.w3.org/2011/webrtc/editor/getusermedia.html for more 8 * See http://dev.w3.org/2011/webrtc/editor/getusermedia.html for more
9 * information on getUserMedia. 9 * information on getUserMedia.
10 */ 10 */
(...skipping 17 matching lines...) Expand all
28 */ 28 */
29 var gRequestWebcamAndMicrophoneResult = 'not-called-yet'; 29 var gRequestWebcamAndMicrophoneResult = 'not-called-yet';
30 30
31 /** 31 /**
32 * This function asks permission to use the webcam and mic from the browser. It 32 * This function asks permission to use the webcam and mic from the browser. It
33 * will return ok-requested to PyAuto. This does not mean the request was 33 * will return ok-requested to PyAuto. This does not mean the request was
34 * approved though. The test will then have to click past the dialog that 34 * approved though. The test will then have to click past the dialog that
35 * appears in Chrome, which will run either the OK or failed callback as a 35 * appears in Chrome, which will run either the OK or failed callback as a
36 * a result. To see which callback was called, use obtainGetUserMediaResult(). 36 * a result. To see which callback was called, use obtainGetUserMediaResult().
37 * 37 *
38 * @param{string} constraints Defines what to be requested, with mandatory 38 * @param {string} constraints Defines what to be requested, with mandatory
39 * and optional constraints defined. The contents of this parameter depends 39 * and optional constraints defined. The contents of this parameter depends
40 * on the WebRTC version. This should be JavaScript code that we eval(). 40 * on the WebRTC version. This should be JavaScript code that we eval().
41 */ 41 */
42 function getUserMedia(constraints) { 42 function getUserMedia(constraints) {
43 if (!navigator.webkitGetUserMedia) { 43 if (!navigator.webkitGetUserMedia) {
44 returnToTest('Browser does not support WebRTC.'); 44 returnToTest('Browser does not support WebRTC.');
45 return; 45 return;
46 } 46 }
47 try { 47 try {
48 var evaluatedConstraints; 48 var evaluatedConstraints;
49 eval('evaluatedConstraints = ' + constraints); 49 eval('evaluatedConstraints = ' + constraints);
50 } catch (exception) { 50 } catch (exception) {
51 throw failTest('Not valid JavaScript expression: ' + constraints); 51 throw failTest('Not valid JavaScript expression: ' + constraints);
52 } 52 }
53 debug('Requesting getUserMedia: constraints: ' + constraints); 53 debug('Requesting getUserMedia: constraints: ' + constraints);
54 navigator.webkitGetUserMedia(evaluatedConstraints, 54 navigator.webkitGetUserMedia(evaluatedConstraints,
55 getUserMediaOkCallback_, 55 getUserMediaOkCallback_,
56 getUserMediaFailedCallback_); 56 getUserMediaFailedCallback_);
57 returnToTest('ok-requested'); 57 returnToTest('ok-requested');
58 } 58 }
59 59
60 /** 60 /**
61 * Must be called after calling getUserMedia. Returns not-called-yet if we have 61 * Must be called after calling getUserMedia.
62 * @return {string} Returns not-called-yet if we have
kjellander_chromium 2013/04/08 14:19:52 More words can go on the same row as @return (i.e.
jansson 2013/04/10 12:11:48 Done.
62 * not yet been called back by WebRTC. Otherwise it returns either ok-got-stream 63 * not yet been called back by WebRTC. Otherwise it returns either ok-got-stream
63 * or failed-with-error-x (where x is the error code from the error callback) 64 * or failed-with-error-x (where x is the error code from the error callback)
64 * depending on which callback got called by WebRTC. 65 * depending on which callback got called by WebRTC.
65 */ 66 */
66 function obtainGetUserMediaResult() { 67 function obtainGetUserMediaResult() {
67 returnToTest(gRequestWebcamAndMicrophoneResult); 68 returnToTest(gRequestWebcamAndMicrophoneResult);
68 return gRequestWebcamAndMicrophoneResult; 69 return gRequestWebcamAndMicrophoneResult;
69 } 70 }
70 71
71 /** 72 /**
72 * Stops the local stream. 73 * Stops the local stream.
73 */ 74 */
74 function stopLocalStream() { 75 function stopLocalStream() {
75 if (gLocalStream == null) 76 if (gLocalStream == null)
76 throw failTest('Tried to stop local stream, ' + 77 throw failTest('Tried to stop local stream, ' +
77 'but media access is not granted.'); 78 'but media access is not granted.');
78 79
79 gLocalStream.stop(); 80 gLocalStream.stop();
80 returnToTest('ok-stopped'); 81 returnToTest('ok-stopped');
81 } 82 }
82 83
83 // Functions callable from other JavaScript modules. 84 // Functions callable from other JavaScript modules.
84 85
85 /** 86 /**
86 * Adds the current local media stream to a peer connection. 87 * Adds the current local media stream to a peer connection.
87 * @param{RTCPeerConnection} peerConnection 88 * @param {RTCPeerConnection} peerConnection
88 */ 89 */
89 function addLocalStreamToPeerConnection(peerConnection) { 90 function addLocalStreamToPeerConnection(peerConnection) {
90 if (gLocalStream == null) 91 if (gLocalStream == null)
91 throw failTest('Tried to add local stream to peer connection, ' + 92 throw failTest('Tried to add local stream to peer connection, ' +
92 'but there is no stream yet.'); 93 'but there is no stream yet.');
93 try { 94 try {
94 peerConnection.addStream(gLocalStream, gAddStreamConstraints); 95 peerConnection.addStream(gLocalStream, gAddStreamConstraints);
95 } catch (exception) { 96 } catch (exception) {
96 throw failTest('Failed to add stream with constraints ' + 97 throw failTest('Failed to add stream with constraints ' +
97 gAddStreamConstraints + ': ' + exception); 98 gAddStreamConstraints + ': ' + exception);
98 } 99 }
99 debug('Added local stream.'); 100 debug('Added local stream.');
100 } 101 }
101 102
102 /** 103 /**
103 * Removes the local stream from the peer connection. 104 * Removes the local stream from the peer connection.
104 * @param{rtcpeerconnection} peerconnection 105 * @param {rtcpeerconnection} peerConnection
105 */ 106 */
106 function removeLocalStreamFromPeerConnection(peerConnection) { 107 function removeLocalStreamFromPeerConnection(peerConnection) {
107 if (gLocalStream == null) 108 if (gLocalStream == null)
108 throw failTest('Tried to remove local stream from peer connection, ' + 109 throw failTest('Tried to remove local stream from peer connection, ' +
109 'but there is no stream yet.'); 110 'but there is no stream yet.');
110 try { 111 try {
111 peerConnection.removeStream(gLocalStream); 112 peerConnection.removeStream(gLocalStream);
112 } catch (exception) { 113 } catch (exception) {
113 throw failTest('Could not remove stream: ' + exception); 114 throw failTest('Could not remove stream: ' + exception);
114 } 115 }
115 debug('Removed local stream.'); 116 debug('Removed local stream.');
116 } 117 }
117 118
118 /** 119 /**
119 * Returns the current local stream - |gLocalStream|. 120 * @return {string} Returns the current local stream - |gLocalStream|.
120 */ 121 */
121 function getLocalStream() { 122 function getLocalStream() {
122 return gLocalStream; 123 return gLocalStream;
123 } 124 }
124 125
125 // Internals. 126 // Internals.
126 127
127 /** 128 /**
128 * @private 129 * @private
129 * @param {MediaStream} stream Media stream. 130 * @param {MediaStream} stream Media stream.
130 */ 131 */
131 function getUserMediaOkCallback_(stream) { 132 function getUserMediaOkCallback_(stream) {
132 gLocalStream = stream; 133 gLocalStream = stream;
133 var videoTag = $('local-view'); 134 var videoTag = $('local-view');
134 videoTag.src = webkitURL.createObjectURL(stream); 135 videoTag.src = webkitURL.createObjectURL(stream);
135 136
136 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. 137 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires.
137 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view'); 138 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view');
138 // Use setTimeout as a workaround for now. 139 // Use setTimeout as a workaround for now.
139 setTimeout(function() {updateVideoTagSize_('local-view')}, 500);
140 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; 140 gRequestWebcamAndMicrophoneResult = 'ok-got-stream';
141 setTimeout(function() {_displayVideoSize(videoTag);}, 500);
141 } 142 }
142 143
143 /** 144 /**
144 * @private 145 * @private
145 * @param {string} videoTagId The ID of the video tag to update. 146 * @param {string} videoTagId The ID of the video tag to update.
147 * @param {string} width The width of the video to update the video
148 * tag, if width or height is 0, size will be taken from
149 * videoTag.videoWidth.
150 * @param {string} height The height of the video to update the video
151 * tag, if width or height is 0 size will be taken from the
152 * videoTag.videoHeight.
146 */ 153 */
147 function updateVideoTagSize_(videoTagId) { 154 function updateVideoTagSize_(videoTagId, width, height) {
148 var videoTag = $(videoTagId); 155 var videoTag = $(videoTagId);
149 // Don't update if sizes are 0 (happens for Chrome M23). 156 if (width > 0 || height > 0) {
150 if (videoTag.videoWidth > 0 && videoTag.videoHeight > 0) { 157 videoTag.width = width;
151 debug('Set video tag "' + videoTagId + '" width and height to ' + 158 videoTag.height = height;
152 videoTag.videoWidth + 'x' + videoTag.videoHeight); 159 debug('Set video tag "' + videoTagId + '" size to ' +
153 videoTag.width = videoTag.videoWidth; 160 videoTag.width + 'x' + videoTag.height);
154 videoTag.height = videoTag.videoHeight;
155 } 161 }
162 else {
163 if (videoTag.videoWidth > 0 || videoTag.videoHeight > 0) {
164 videoTag.width = videoTag.videoWidth;
165 videoTag.height = videoTag.videoHeight;
166 }
167 else {
168 debug('"' + videoTagId + '" video stream size is 0, cannot resize');
kjellander_chromium 2013/04/08 14:19:52 change 'cannot resize' -> 'skipping resize' (since
jansson 2013/04/10 12:11:48 Done.
169 }
170 }
171 _displayVideoSize(videoTag);
156 } 172 }
157 173
158 /** 174 /**
175 * @private
176 * @param {string} videoTag The ID of the video tag + stream to
177 * write the size to a HTML tag based on id.
178 */
179 function _displayVideoSize(videoTag) {
180 if (videoTag.videoWidth || videoTag.videoHeight > 0) {
kjellander_chromium 2013/04/08 14:19:52 videoTag.videoWidth > 0 ?
jansson 2013/04/10 12:11:48 Done.
181 $(videoTag.id + '-stream-size').innerHTML = '(stream size: ' +
182 videoTag.videoWidth + 'x' +
183 videoTag.videoHeight + ')';
184 }
185 $(videoTag.id + '-size').innerHTML = videoTag.width + 'x' + videoTag.height;
186 }
187
188 /**
159 * @private 189 * @private
160 * @param {NavigatorUserMediaError} error Error containing details. 190 * @param {NavigatorUserMediaError} error Error containing details.
161 */ 191 */
162 function getUserMediaFailedCallback_(error) { 192 function getUserMediaFailedCallback_(error) {
163 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); 193 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?');
164 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code; 194 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code;
165 } 195 }
166 196
167 $ = function(id) { 197 $ = function(id) {
168 return document.getElementById(id); 198 return document.getElementById(id);
169 }; 199 };
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webrtc/jsep01_call.js » ('j') | chrome/test/data/webrtc/jsep01_call.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698