Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 21 matching lines...) Expand all Loading... | |
| 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 doGetUserMedia(constraints) { |
| 43 if (!navigator.webkitGetUserMedia) { | 43 if (!getUserMedia) { |
| 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 doGetUserMedia: constraints: ' + constraints); |
| 54 navigator.webkitGetUserMedia(evaluatedConstraints, | 54 getUserMedia(evaluatedConstraints, getUserMediaOkCallback_, |
| 55 getUserMediaOkCallback_, | 55 getUserMediaFailedCallback_); |
|
kjellander_chromium
2013/04/03 09:09:51
I'm sorry if I confused you a little in the previo
elham
2013/04/08 19:19:18
Done.
| |
| 56 getUserMediaFailedCallback_); | |
| 57 returnToTest('ok-requested'); | 56 returnToTest('ok-requested'); |
| 58 } | 57 } |
| 59 | 58 |
| 60 /** | 59 /** |
| 61 * Must be called after calling getUserMedia. Returns not-called-yet if we have | 60 * Must be called after calling doGetUserMedia. Returns not-called-yet if we |
| 62 * not yet been called back by WebRTC. Otherwise it returns either ok-got-stream | 61 * have not yet been called back by WebRTC. Otherwise it returns either |
| 63 * or failed-with-error-x (where x is the error code from the error callback) | 62 * ok-got-stream or failed-with-error-x (where x is the error code from the |
| 64 * depending on which callback got called by WebRTC. | 63 * error callback) depending on which callback got called by WebRTC. |
| 65 */ | 64 */ |
| 66 function obtainGetUserMediaResult() { | 65 function obtainGetUserMediaResult() { |
| 67 returnToTest(gRequestWebcamAndMicrophoneResult); | 66 returnToTest(gRequestWebcamAndMicrophoneResult); |
| 68 return gRequestWebcamAndMicrophoneResult; | 67 return gRequestWebcamAndMicrophoneResult; |
| 69 } | 68 } |
| 70 | 69 |
| 71 /** | 70 /** |
| 72 * Stops the local stream. | 71 * Stops the local stream. |
| 73 */ | 72 */ |
| 74 function stopLocalStream() { | 73 function stopLocalStream() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 | 123 |
| 125 // Internals. | 124 // Internals. |
| 126 | 125 |
| 127 /** | 126 /** |
| 128 * @private | 127 * @private |
| 129 * @param {MediaStream} stream Media stream. | 128 * @param {MediaStream} stream Media stream. |
| 130 */ | 129 */ |
| 131 function getUserMediaOkCallback_(stream) { | 130 function getUserMediaOkCallback_(stream) { |
| 132 gLocalStream = stream; | 131 gLocalStream = stream; |
| 133 var videoTag = $('local-view'); | 132 var videoTag = $('local-view'); |
| 134 videoTag.src = webkitURL.createObjectURL(stream); | 133 attachMediaStream(videoTag, stream); |
| 135 | |
| 136 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. | 134 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. |
| 137 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view'); | 135 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view'); |
| 138 // Use setTimeout as a workaround for now. | 136 // Use setTimeout as a workaround for now. |
| 139 setTimeout(function() {updateVideoTagSize_('local-view')}, 500); | 137 setTimeout(function() {updateVideoTagSize_('local-view')}, 500); |
| 140 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; | 138 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; |
| 141 } | 139 } |
| 142 | 140 |
| 143 /** | 141 /** |
| 144 * @private | 142 * @private |
| 145 * @param {string} videoTagId The ID of the video tag to update. | 143 * @param {string} videoTagId The ID of the video tag to update. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 160 * @param {NavigatorUserMediaError} error Error containing details. | 158 * @param {NavigatorUserMediaError} error Error containing details. |
| 161 */ | 159 */ |
| 162 function getUserMediaFailedCallback_(error) { | 160 function getUserMediaFailedCallback_(error) { |
| 163 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); | 161 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); |
| 164 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code; | 162 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code; |
| 165 } | 163 } |
| 166 | 164 |
| 167 $ = function(id) { | 165 $ = function(id) { |
| 168 return document.getElementById(id); | 166 return document.getElementById(id); |
| 169 }; | 167 }; |
| OLD | NEW |