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, |
| 55 getUserMediaOkCallback_, | 55 getUserMediaOkCallback_, |
|
kjellander_chromium
2013/03/15 09:14:06
Fix indentation.
elham1
2013/03/21 22:36:27
Done.
| |
| 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 doGetUserMedia. Returns not-called-yet if we hav e |
|
kjellander_chromium
2013/03/15 09:14:06
80 chars line limit.
elham1
2013/03/21 22:36:27
Done.
| |
| 62 * not yet been called back by WebRTC. Otherwise it returns either ok-got-stream | 62 * 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) | 63 * or failed-with-error-x (where x is the error code from the error callback) |
| 64 * depending on which callback got called by WebRTC. | 64 * depending on which callback got called by WebRTC. |
| 65 */ | 65 */ |
| 66 function obtainGetUserMediaResult() { | 66 function obtainGetUserMediaResult() { |
| 67 returnToTest(gRequestWebcamAndMicrophoneResult); | 67 returnToTest(gRequestWebcamAndMicrophoneResult); |
| 68 return gRequestWebcamAndMicrophoneResult; | 68 return gRequestWebcamAndMicrophoneResult; |
| 69 } | 69 } |
| 70 | 70 |
| 71 /** | 71 /** |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 | 124 |
| 125 // Internals. | 125 // Internals. |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * @private | 128 * @private |
| 129 * @param {MediaStream} stream Media stream. | 129 * @param {MediaStream} stream Media stream. |
| 130 */ | 130 */ |
| 131 function getUserMediaOkCallback_(stream) { | 131 function getUserMediaOkCallback_(stream) { |
| 132 gLocalStream = stream; | 132 gLocalStream = stream; |
| 133 var videoTag = $('local-view'); | 133 var videoTag = $('local-view'); |
| 134 videoTag.src = webkitURL.createObjectURL(stream); | 134 attachMediaStream(videoTag, stream); |
| 135 | |
| 136 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. | 135 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. |
| 137 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view'); | 136 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view'); |
| 138 // Use setTimeout as a workaround for now. | 137 // Use setTimeout as a workaround for now. |
| 139 setTimeout(function() {updateVideoTagSize_('local-view')}, 500); | 138 setTimeout(function() {updateVideoTagSize_('local-view')}, 500); |
| 140 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; | 139 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; |
| 141 } | 140 } |
| 142 | 141 |
| 143 /** | 142 /** |
| 144 * @private | 143 * @private |
| 145 * @param {string} videoTagId The ID of the video tag to update. | 144 * @param {string} videoTagId The ID of the video tag to update. |
| 146 */ | 145 */ |
| 147 function updateVideoTagSize_(videoTagId) { | 146 function updateVideoTagSize_(videoTagId) { |
| 148 var videoTag = $(videoTagId); | 147 var videoTag = $(videoTagId); |
| 149 // Don't update if sizes are 0 (happens for Chrome M23). | 148 // Don't update if sizes are 0 (happens for Chrome M23). |
| 150 if (videoTag.videoWidth > 0 && videoTag.videoHeight > 0) { | 149 if (videoTag.videoWidth > 0 && videoTag.videoHeight > 0) { |
| 151 debug('Set video tag "' + videoTagId + '" width and height to ' + | 150 debug('Set video tag "' + videoTagId + '" width and height to ' + |
| 152 videoTag.videoWidth + 'x' + videoTag.videoHeight); | 151 videoTag.videoWidth + 'x' + videoTag.videoHeight); |
| 153 videoTag.width = videoTag.videoWidth; | 152 videoTag.width = videoTag.videoWidth; |
| 154 videoTag.height = videoTag.videoHeight; | 153 videoTag.height = videoTag.videoHeight; |
| 155 } | 154 } |
| 156 } | 155 } |
| 157 | 156 |
| 158 /** | 157 /** |
| 159 * @private | 158 * @private |
| 160 * @param {NavigatorUserMediaError} error Error containing details. | 159 * @param {NavigatorUserMediaError} error Error containing details. |
| 161 */ | 160 */ |
| 162 function getUserMediaFailedCallback_(error) { | 161 function getUserMediaFailedCallback_(error) { |
| 163 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); | 162 debug('doGetUserMedia FAILED: Maybe the camera is in use by another process?') ; |
| 164 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code; | 163 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code; |
| 165 } | 164 } |
| 166 | 165 |
| 167 $ = function(id) { | 166 $ = function(id) { |
| 168 return document.getElementById(id); | 167 return document.getElementById(id); |
| 169 }; | 168 }; |
| OLD | NEW |