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 17 matching lines...) Expand all Loading... | |
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; |
(...skipping 28 matching lines...) Expand all Loading... | |
77 'but media access is not granted.'); | 77 'but media access is not granted.'); |
78 | 78 |
79 gLocalStream.stop(); | 79 gLocalStream.stop(); |
80 returnToTest('ok-stopped'); | 80 returnToTest('ok-stopped'); |
81 } | 81 } |
82 | 82 |
83 // Functions callable from other JavaScript modules. | 83 // Functions callable from other JavaScript modules. |
84 | 84 |
85 /** | 85 /** |
86 * Adds the current local media stream to a peer connection. | 86 * Adds the current local media stream to a peer connection. |
87 * @param{RTCPeerConnection} peerConnection | 87 * @param {RTCPeerConnection} peerConnection |
88 */ | 88 */ |
89 function addLocalStreamToPeerConnection(peerConnection) { | 89 function addLocalStreamToPeerConnection(peerConnection) { |
90 if (gLocalStream == null) | 90 if (gLocalStream == null) |
91 throw failTest('Tried to add local stream to peer connection, ' + | 91 throw failTest('Tried to add local stream to peer connection, ' + |
92 'but there is no stream yet.'); | 92 'but there is no stream yet.'); |
93 try { | 93 try { |
94 peerConnection.addStream(gLocalStream, gAddStreamConstraints); | 94 peerConnection.addStream(gLocalStream, gAddStreamConstraints); |
95 } catch (exception) { | 95 } catch (exception) { |
96 throw failTest('Failed to add stream with constraints ' + | 96 throw failTest('Failed to add stream with constraints ' + |
97 gAddStreamConstraints + ': ' + exception); | 97 gAddStreamConstraints + ': ' + exception); |
98 } | 98 } |
99 debug('Added local stream.'); | 99 debug('Added local stream.'); |
100 } | 100 } |
101 | 101 |
102 /** | 102 /** |
103 * Removes the local stream from the peer connection. | 103 * Removes the local stream from the peer connection. |
104 * @param{rtcpeerconnection} peerconnection | 104 * @param {rtcpeerconnection} peerConnection |
105 */ | 105 */ |
106 function removeLocalStreamFromPeerConnection(peerConnection) { | 106 function removeLocalStreamFromPeerConnection(peerConnection) { |
107 if (gLocalStream == null) | 107 if (gLocalStream == null) |
108 throw failTest('Tried to remove local stream from peer connection, ' + | 108 throw failTest('Tried to remove local stream from peer connection, ' + |
109 'but there is no stream yet.'); | 109 'but there is no stream yet.'); |
110 try { | 110 try { |
111 peerConnection.removeStream(gLocalStream); | 111 peerConnection.removeStream(gLocalStream); |
112 } catch (exception) { | 112 } catch (exception) { |
113 throw failTest('Could not remove stream: ' + exception); | 113 throw failTest('Could not remove stream: ' + exception); |
114 } | 114 } |
(...skipping 12 matching lines...) Expand all Loading... | |
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 videoTag.src = webkitURL.createObjectURL(stream); |
135 | 135 |
136 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. | 136 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. |
137 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view'); | 137 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view'); |
kjellander_chromium
2013/03/25 13:33:58
Update this line (meant to be the code used when 1
jansson
2013/04/05 10:29:42
Done.
kjellander_chromium
2013/04/08 14:19:51
You must have missed this, it's still not updated.
| |
138 // Use setTimeout as a workaround for now. | 138 // Use setTimeout as a workaround for now. |
139 setTimeout(function() {updateVideoTagSize_('local-view')}, 500); | 139 // setTimeout(function() {updateVideoTagSize_('local-view')}, 500); |
kjellander_chromium
2013/03/25 13:33:58
Clean out the old code instead of commenting it.
jansson
2013/04/05 10:29:42
Done.
| |
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 | |
kjellander_chromium
2013/03/25 13:33:58
The implementation is not exactly as documented, a
jansson
2013/04/05 10:29:42
Done.
| |
148 * tag, if 0 size will be taken from videoTag.videoWidth. | |
149 * @param {string} height The height of the video to update the video | |
150 * tag, if 0 size will be taken from the videoTag.videoHeight. | |
146 */ | 151 */ |
147 function updateVideoTagSize_(videoTagId) { | 152 function updateVideoTagSize_(videoTagId, width, height) { |
148 var videoTag = $(videoTagId); | 153 var videoTag = $(videoTagId); |
149 // Don't update if sizes are 0 (happens for Chrome M23). | 154 if (width && height > 0) { |
kjellander_chromium
2013/03/25 13:33:58
This is confusing since width is probably always t
jansson
2013/04/05 10:29:42
Done.
| |
150 if (videoTag.videoWidth > 0 && videoTag.videoHeight > 0) { | 155 videoTag.width = width; |
151 debug('Set video tag "' + videoTagId + '" width and height to ' + | 156 videoTag.height = height; |
152 videoTag.videoWidth + 'x' + videoTag.videoHeight); | 157 } |
158 else { | |
153 videoTag.width = videoTag.videoWidth; | 159 videoTag.width = videoTag.videoWidth; |
154 videoTag.height = videoTag.videoHeight; | 160 videoTag.height = videoTag.videoHeight; |
155 } | 161 } |
162 debug('Set video tag "' + videoTagId + '" width and height to ' + | |
kjellander_chromium
2013/03/25 13:33:58
I prefer replacing "width and height" with just "s
jansson
2013/04/05 10:29:42
Done.
| |
163 videoTag.width + 'x' + videoTag.height); | |
164 displayVideoSize(videoTag); | |
156 } | 165 } |
157 | 166 |
158 /** | 167 /** |
168 * @private | |
169 * @param {string} videoTag The ID of the video tag + stream to | |
170 * write the size to a HTML tag based on id. | |
171 */ | |
172 function displayVideoSize(videoTag) { | |
kjellander_chromium
2013/03/25 13:33:58
private functions shall end with underscore.
http:
jansson
2013/04/05 10:29:42
Done.
kjellander_chromium
2013/04/08 14:19:51
Move underscore to the end of the function name, n
jansson
2013/04/10 12:11:47
Done.
jansson
2013/04/10 12:11:47
Done.
| |
173 $(videoTag.id + '-stream-size').innerHTML = '(stream size: ' + | |
174 videoTag.videoWidth + 'x' + | |
175 videoTag.videoHeight + ' )'; | |
kjellander_chromium
2013/03/25 13:33:58
Skip the white space at the end of the string, bef
jansson
2013/04/05 10:29:42
Done.
| |
176 $(videoTag.id + '-size').innerHTML = videoTag.width + 'x' + videoTag.height; | |
177 } | |
178 | |
179 /** | |
159 * @private | 180 * @private |
160 * @param {NavigatorUserMediaError} error Error containing details. | 181 * @param {NavigatorUserMediaError} error Error containing details. |
161 */ | 182 */ |
162 function getUserMediaFailedCallback_(error) { | 183 function getUserMediaFailedCallback_(error) { |
163 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); | 184 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); |
164 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code; | 185 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code; |
165 } | 186 } |
166 | 187 |
167 $ = function(id) { | 188 $ = function(id) { |
168 return document.getElementById(id); | 189 return document.getElementById(id); |
169 }; | 190 }; |
OLD | NEW |