| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/user_media_client_impl.h" | 5 #include "content/renderer/media/user_media_client_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); | 198 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
| 199 DCHECK(CalledOnValidThread()); | 199 DCHECK(CalledOnValidThread()); |
| 200 | 200 |
| 201 if (RenderThreadImpl::current()) { | 201 if (RenderThreadImpl::current()) { |
| 202 RenderThreadImpl::current()->peer_connection_tracker()->TrackGetUserMedia( | 202 RenderThreadImpl::current()->peer_connection_tracker()->TrackGetUserMedia( |
| 203 user_media_request); | 203 user_media_request); |
| 204 } | 204 } |
| 205 | 205 |
| 206 int request_id = g_next_request_id++; | 206 int request_id = g_next_request_id++; |
| 207 StreamControls controls; | 207 StreamControls controls; |
| 208 GURL security_origin; | 208 url::Origin security_origin; |
| 209 bool enable_automatic_output_device_selection = false; | 209 bool enable_automatic_output_device_selection = false; |
| 210 | 210 |
| 211 // |user_media_request| can't be mocked. So in order to test at all we check | 211 // |user_media_request| can't be mocked. So in order to test at all we check |
| 212 // if it isNull. | 212 // if it isNull. |
| 213 if (user_media_request.isNull()) { | 213 if (user_media_request.isNull()) { |
| 214 // We are in a test. | 214 // We are in a test. |
| 215 controls.audio.requested = true; | 215 controls.audio.requested = true; |
| 216 controls.video.requested = true; | 216 controls.video.requested = true; |
| 217 } else { | 217 } else { |
| 218 if (user_media_request.audio()) { | 218 if (user_media_request.audio()) { |
| 219 controls.audio.requested = true; | 219 controls.audio.requested = true; |
| 220 // Check if this input device should be used to select a matching output | 220 // Check if this input device should be used to select a matching output |
| 221 // device for audio rendering. | 221 // device for audio rendering. |
| 222 enable_automatic_output_device_selection = true; // On by default. | 222 enable_automatic_output_device_selection = true; // On by default. |
| 223 GetConstraintValueAsBoolean( | 223 GetConstraintValueAsBoolean( |
| 224 user_media_request.audioConstraints(), | 224 user_media_request.audioConstraints(), |
| 225 &blink::WebMediaTrackConstraintSet::renderToAssociatedSink, | 225 &blink::WebMediaTrackConstraintSet::renderToAssociatedSink, |
| 226 &enable_automatic_output_device_selection); | 226 &enable_automatic_output_device_selection); |
| 227 } | 227 } |
| 228 if (user_media_request.video()) { | 228 if (user_media_request.video()) { |
| 229 controls.video.requested = true; | 229 controls.video.requested = true; |
| 230 } | 230 } |
| 231 CopyBlinkRequestToStreamControls(user_media_request, &controls); | 231 CopyBlinkRequestToStreamControls(user_media_request, &controls); |
| 232 security_origin = blink::WebStringToGURL( | 232 security_origin = user_media_request.getSecurityOrigin(); |
| 233 user_media_request.getSecurityOrigin().toString()); | |
| 234 // ownerDocument may be null if we are in a test. | 233 // ownerDocument may be null if we are in a test. |
| 235 // In that case, it's OK to not check frame(). | 234 // In that case, it's OK to not check frame(). |
| 236 DCHECK(user_media_request.ownerDocument().isNull() || | 235 DCHECK(user_media_request.ownerDocument().isNull() || |
| 237 render_frame()->GetWebFrame() == | 236 render_frame()->GetWebFrame() == |
| 238 static_cast<blink::WebFrame*>( | 237 static_cast<blink::WebFrame*>( |
| 239 user_media_request.ownerDocument().frame())); | 238 user_media_request.ownerDocument().frame())); |
| 240 } | 239 } |
| 241 | 240 |
| 242 DVLOG(1) << "UserMediaClientImpl::requestUserMedia(" << request_id << ", [ " | 241 DVLOG(1) << "UserMediaClientImpl::requestUserMedia(" << request_id << ", [ " |
| 243 << "audio=" << (controls.audio.requested) | 242 << "audio=" << (controls.audio.requested) |
| 244 << " select associated sink: " | 243 << " select associated sink: " |
| 245 << enable_automatic_output_device_selection | 244 << enable_automatic_output_device_selection |
| 246 << ", video=" << (controls.video.requested) << " ], " | 245 << ", video=" << (controls.video.requested) << " ], " |
| 247 << security_origin.spec() << ")"; | 246 << security_origin << ")"; |
| 248 | 247 |
| 249 std::string audio_device_id; | 248 std::string audio_device_id; |
| 250 if (!user_media_request.isNull() && user_media_request.audio()) { | 249 if (!user_media_request.isNull() && user_media_request.audio()) { |
| 251 GetConstraintValueAsString(user_media_request.audioConstraints(), | 250 GetConstraintValueAsString(user_media_request.audioConstraints(), |
| 252 &blink::WebMediaTrackConstraintSet::deviceId, | 251 &blink::WebMediaTrackConstraintSet::deviceId, |
| 253 &audio_device_id); | 252 &audio_device_id); |
| 254 } | 253 } |
| 255 | 254 |
| 256 std::string video_device_id; | 255 std::string video_device_id; |
| 257 if (!user_media_request.isNull() && user_media_request.video()) { | 256 if (!user_media_request.isNull() && user_media_request.video()) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); | 291 UpdateWebRTCMethodCount(WEBKIT_GET_MEDIA_DEVICES); |
| 293 DCHECK(CalledOnValidThread()); | 292 DCHECK(CalledOnValidThread()); |
| 294 | 293 |
| 295 int audio_input_request_id = g_next_request_id++; | 294 int audio_input_request_id = g_next_request_id++; |
| 296 int video_input_request_id = g_next_request_id++; | 295 int video_input_request_id = g_next_request_id++; |
| 297 int audio_output_request_id = g_next_request_id++; | 296 int audio_output_request_id = g_next_request_id++; |
| 298 | 297 |
| 299 // |media_devices_request| can't be mocked, so in tests it will be empty (the | 298 // |media_devices_request| can't be mocked, so in tests it will be empty (the |
| 300 // underlying pointer is null). In order to use this function in a test we | 299 // underlying pointer is null). In order to use this function in a test we |
| 301 // need to check if it isNull. | 300 // need to check if it isNull. |
| 302 GURL security_origin; | 301 url::Origin security_origin; |
| 303 if (!media_devices_request.isNull()) { | 302 if (!media_devices_request.isNull()) |
| 304 security_origin = blink::WebStringToGURL( | 303 security_origin = media_devices_request.getSecurityOrigin(); |
| 305 media_devices_request.getSecurityOrigin().toString()); | |
| 306 } | |
| 307 | 304 |
| 308 DVLOG(1) << "UserMediaClientImpl::requestMediaDevices(" | 305 DVLOG(1) << "UserMediaClientImpl::requestMediaDevices(" |
| 309 << audio_input_request_id | 306 << audio_input_request_id << ", " << video_input_request_id << ", " |
| 310 << ", " << video_input_request_id << ", " << audio_output_request_id | 307 << audio_output_request_id << ", " << security_origin << ")"; |
| 311 << ", " << security_origin.spec() << ")"; | |
| 312 | 308 |
| 313 media_devices_requests_.push_back(new MediaDevicesRequestInfo( | 309 media_devices_requests_.push_back(new MediaDevicesRequestInfo( |
| 314 media_devices_request, | 310 media_devices_request, |
| 315 audio_input_request_id, | 311 audio_input_request_id, |
| 316 video_input_request_id, | 312 video_input_request_id, |
| 317 audio_output_request_id)); | 313 audio_output_request_id)); |
| 318 | 314 |
| 319 media_stream_dispatcher_->EnumerateDevices( | 315 media_stream_dispatcher_->EnumerateDevices( |
| 320 audio_input_request_id, | 316 audio_input_request_id, |
| 321 weak_factory_.GetWeakPtr(), | 317 weak_factory_.GetWeakPtr(), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 350 // We don't call UpdateWebRTCMethodCount() here to track the API count in UMA | 346 // We don't call UpdateWebRTCMethodCount() here to track the API count in UMA |
| 351 // stats. This is instead counted in MediaStreamTrack::getSources in blink. | 347 // stats. This is instead counted in MediaStreamTrack::getSources in blink. |
| 352 DCHECK(CalledOnValidThread()); | 348 DCHECK(CalledOnValidThread()); |
| 353 | 349 |
| 354 int audio_input_request_id = g_next_request_id++; | 350 int audio_input_request_id = g_next_request_id++; |
| 355 int video_input_request_id = g_next_request_id++; | 351 int video_input_request_id = g_next_request_id++; |
| 356 | 352 |
| 357 // |sources_request| can't be mocked, so in tests it will be empty (the | 353 // |sources_request| can't be mocked, so in tests it will be empty (the |
| 358 // underlying pointer is null). In order to use this function in a test we | 354 // underlying pointer is null). In order to use this function in a test we |
| 359 // need to check if it isNull. | 355 // need to check if it isNull. |
| 360 GURL security_origin; | 356 url::Origin security_origin; |
| 361 if (!sources_request.isNull()) | 357 if (!sources_request.isNull()) |
| 362 security_origin = GURL(sources_request.origin().utf8()); | 358 security_origin = sources_request.origin(); |
| 363 | 359 |
| 364 DVLOG(1) << "UserMediaClientImpl::requestSources(" | 360 DVLOG(1) << "UserMediaClientImpl::requestSources(" << audio_input_request_id |
| 365 << audio_input_request_id | 361 << ", " << video_input_request_id << ", " << security_origin << ")"; |
| 366 << ", " << video_input_request_id | |
| 367 << ", " << security_origin.spec() << ")"; | |
| 368 | 362 |
| 369 media_devices_requests_.push_back(new MediaDevicesRequestInfo( | 363 media_devices_requests_.push_back(new MediaDevicesRequestInfo( |
| 370 sources_request, | 364 sources_request, |
| 371 audio_input_request_id, | 365 audio_input_request_id, |
| 372 video_input_request_id)); | 366 video_input_request_id)); |
| 373 | 367 |
| 374 media_stream_dispatcher_->EnumerateDevices( | 368 media_stream_dispatcher_->EnumerateDevices( |
| 375 audio_input_request_id, | 369 audio_input_request_id, |
| 376 weak_factory_.GetWeakPtr(), | 370 weak_factory_.GetWeakPtr(), |
| 377 MEDIA_DEVICE_AUDIO_CAPTURE, | 371 MEDIA_DEVICE_AUDIO_CAPTURE, |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 return; | 1151 return; |
| 1158 } | 1152 } |
| 1159 } | 1153 } |
| 1160 } | 1154 } |
| 1161 | 1155 |
| 1162 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { | 1156 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { |
| 1163 return !sources_waiting_for_callback_.empty(); | 1157 return !sources_waiting_for_callback_.empty(); |
| 1164 } | 1158 } |
| 1165 | 1159 |
| 1166 } // namespace content | 1160 } // namespace content |
| OLD | NEW |