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 <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
18 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "content/public/renderer/render_frame.h" | 20 #include "content/public/renderer/render_frame.h" |
21 #include "content/renderer/media/local_media_stream_audio_source.h" | 21 #include "content/renderer/media/local_media_stream_audio_source.h" |
22 #include "content/renderer/media/media_stream.h" | 22 #include "content/renderer/media/media_stream.h" |
23 #include "content/renderer/media/media_stream_constraints_util.h" | 23 #include "content/renderer/media/media_stream_constraints_util.h" |
| 24 #include "content/renderer/media/media_stream_constraints_util_audio.h" |
24 #include "content/renderer/media/media_stream_constraints_util_video_content.h" | 25 #include "content/renderer/media/media_stream_constraints_util_video_content.h" |
25 #include "content/renderer/media/media_stream_constraints_util_video_device.h" | 26 #include "content/renderer/media/media_stream_constraints_util_video_device.h" |
26 #include "content/renderer/media/media_stream_dispatcher.h" | 27 #include "content/renderer/media/media_stream_dispatcher.h" |
27 #include "content/renderer/media/media_stream_video_capturer_source.h" | 28 #include "content/renderer/media/media_stream_video_capturer_source.h" |
28 #include "content/renderer/media/media_stream_video_track.h" | 29 #include "content/renderer/media/media_stream_video_track.h" |
29 #include "content/renderer/media/peer_connection_tracker.h" | 30 #include "content/renderer/media/peer_connection_tracker.h" |
30 #include "content/renderer/media/webrtc/processed_local_audio_source.h" | 31 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
31 #include "content/renderer/media/webrtc_logging.h" | 32 #include "content/renderer/media/webrtc_logging.h" |
32 #include "content/renderer/media/webrtc_uma_histograms.h" | 33 #include "content/renderer/media/webrtc_uma_histograms.h" |
33 #include "content/renderer/render_thread_impl.h" | 34 #include "content/renderer/render_thread_impl.h" |
34 #include "media/capture/video_capture_types.h" | 35 #include "media/capture/video_capture_types.h" |
35 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 36 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
36 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" | 37 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" |
37 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 38 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
38 #include "third_party/WebKit/public/platform/WebString.h" | 39 #include "third_party/WebKit/public/platform/WebString.h" |
39 #include "third_party/WebKit/public/web/WebDocument.h" | 40 #include "third_party/WebKit/public/web/WebDocument.h" |
40 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 41 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
41 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 42 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
42 | 43 |
43 namespace content { | 44 namespace content { |
44 namespace { | 45 namespace { |
45 | 46 |
46 void CopyFirstString(const blink::StringConstraint& constraint, | 47 void CopyFirstString(const blink::StringConstraint& constraint, |
47 std::string* destination) { | 48 std::string* destination) { |
48 if (!constraint.Exact().IsEmpty()) | 49 if (!constraint.Exact().IsEmpty()) |
49 *destination = constraint.Exact()[0].Utf8(); | 50 *destination = constraint.Exact()[0].Utf8(); |
50 } | 51 } |
51 | 52 |
| 53 // TODO(guidou): Remove this function. http://crbug.com/706408 |
52 bool FindDeviceId(const blink::WebVector<blink::WebString> candidates, | 54 bool FindDeviceId(const blink::WebVector<blink::WebString> candidates, |
53 const MediaDeviceInfoArray& device_infos, | 55 const MediaDeviceInfoArray& device_infos, |
54 std::string* device_id) { | 56 std::string* device_id) { |
55 for (const auto& candidate : candidates) { | 57 for (const auto& candidate : candidates) { |
56 auto it = std::find_if(device_infos.begin(), device_infos.end(), | 58 auto it = std::find_if(device_infos.begin(), device_infos.end(), |
57 [&candidate](const MediaDeviceInfo& info) { | 59 [&candidate](const MediaDeviceInfo& info) { |
58 return info.device_id == candidate.Utf8(); | 60 return info.device_id == candidate.Utf8(); |
59 }); | 61 }); |
60 | 62 |
61 if (it != device_infos.end()) { | 63 if (it != device_infos.end()) { |
(...skipping 10 matching lines...) Expand all Loading... |
72 // false. If such a device is not found in |device_infos|, the function returns | 74 // false. If such a device is not found in |device_infos|, the function returns |
73 // false and |*device_id| is left unmodified. | 75 // false and |*device_id| is left unmodified. |
74 // If more than one device ID is requested as an exact basic constraint in | 76 // If more than one device ID is requested as an exact basic constraint in |
75 // |constraint|, the function returns false and |*device_id| is left unmodified. | 77 // |constraint|, the function returns false and |*device_id| is left unmodified. |
76 // If no device ID is requested as an exact basic constraint, and at least one | 78 // If no device ID is requested as an exact basic constraint, and at least one |
77 // device ID requested as an ideal basic constraint or as an exact or ideal | 79 // device ID requested as an ideal basic constraint or as an exact or ideal |
78 // advanced constraint in |constraints| is found in |device_infos|, the first | 80 // advanced constraint in |constraints| is found in |device_infos|, the first |
79 // such device ID is copied to |*device_id| and the function returns true. | 81 // such device ID is copied to |*device_id| and the function returns true. |
80 // If no such device ID is found, |*device_id| is left unmodified and the | 82 // If no such device ID is found, |*device_id| is left unmodified and the |
81 // function returns true. | 83 // function returns true. |
82 // TODO(guidou): Replace with a spec-compliant selection algorithm. See | 84 // TODO(guidou): Remove this function. http://crbug.com/706408 |
83 // http://crbug.com/657733. | |
84 bool PickDeviceId(const blink::WebMediaConstraints& constraints, | 85 bool PickDeviceId(const blink::WebMediaConstraints& constraints, |
85 const MediaDeviceInfoArray& device_infos, | 86 const MediaDeviceInfoArray& device_infos, |
86 std::string* device_id) { | 87 std::string* device_id) { |
87 DCHECK(!constraints.IsNull()); | 88 DCHECK(!constraints.IsNull()); |
88 DCHECK(device_id->empty()); | 89 DCHECK(device_id->empty()); |
89 | 90 |
90 if (constraints.Basic().device_id.Exact().size() > 1) { | 91 if (constraints.Basic().device_id.Exact().size() > 1) { |
91 LOG(ERROR) << "Only one required device ID is supported"; | 92 LOG(ERROR) << "Only one required device ID is supported"; |
92 return false; | 93 return false; |
93 } | 94 } |
(...skipping 22 matching lines...) Expand all Loading... |
116 } | 117 } |
117 | 118 |
118 // No valid alternate device ID found. Select default device. | 119 // No valid alternate device ID found. Select default device. |
119 return true; | 120 return true; |
120 } | 121 } |
121 | 122 |
122 bool IsDeviceSource(const std::string& source) { | 123 bool IsDeviceSource(const std::string& source) { |
123 return source.empty(); | 124 return source.empty(); |
124 } | 125 } |
125 | 126 |
126 // TODO(guidou): Remove once audio constraints are processed with spec-compliant | 127 // TODO(guidou): Remove this function. http://crbug.com/706408 |
127 // algorithm. See http://crbug.com/657733. | |
128 void CopyConstraintsToTrackControls( | 128 void CopyConstraintsToTrackControls( |
129 const blink::WebMediaConstraints& constraints, | 129 const blink::WebMediaConstraints& constraints, |
130 TrackControls* track_controls, | 130 TrackControls* track_controls, |
131 bool* request_devices) { | 131 bool* request_devices) { |
132 DCHECK(!constraints.IsNull()); | 132 DCHECK(!constraints.IsNull()); |
133 track_controls->requested = true; | 133 track_controls->requested = true; |
134 CopyFirstString(constraints.Basic().media_stream_source, | 134 CopyFirstString(constraints.Basic().media_stream_source, |
135 &track_controls->stream_source); | 135 &track_controls->stream_source); |
136 if (IsDeviceSource(track_controls->stream_source)) { | 136 if (IsDeviceSource(track_controls->stream_source)) { |
137 bool request_devices_advanced = false; | 137 bool request_devices_advanced = false; |
(...skipping 12 matching lines...) Expand all Loading... |
150 } | 150 } |
151 | 151 |
152 void InitializeTrackControls(const blink::WebMediaConstraints& constraints, | 152 void InitializeTrackControls(const blink::WebMediaConstraints& constraints, |
153 TrackControls* track_controls) { | 153 TrackControls* track_controls) { |
154 DCHECK(!constraints.IsNull()); | 154 DCHECK(!constraints.IsNull()); |
155 track_controls->requested = true; | 155 track_controls->requested = true; |
156 CopyFirstString(constraints.Basic().media_stream_source, | 156 CopyFirstString(constraints.Basic().media_stream_source, |
157 &track_controls->stream_source); | 157 &track_controls->stream_source); |
158 } | 158 } |
159 | 159 |
| 160 // TODO(guidou): Remove this function. http://crbug.com/706408 |
160 void CopyHotwordAndLocalEchoToStreamControls( | 161 void CopyHotwordAndLocalEchoToStreamControls( |
161 const blink::WebMediaConstraints& audio_constraints, | 162 const blink::WebMediaConstraints& audio_constraints, |
162 StreamControls* controls) { | 163 StreamControls* controls) { |
163 if (audio_constraints.IsNull()) | 164 if (audio_constraints.IsNull()) |
164 return; | 165 return; |
165 | 166 |
166 if (audio_constraints.Basic().hotword_enabled.HasExact()) { | 167 if (audio_constraints.Basic().hotword_enabled.HasExact()) { |
167 controls->hotword_enabled = | 168 controls->hotword_enabled = |
168 audio_constraints.Basic().hotword_enabled.Exact(); | 169 audio_constraints.Basic().hotword_enabled.Exact(); |
169 } else { | 170 } else { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 case MEDIA_DEVICE_TYPE_VIDEO_INPUT: | 213 case MEDIA_DEVICE_TYPE_VIDEO_INPUT: |
213 return blink::WebMediaDeviceInfo::kMediaDeviceKindVideoInput; | 214 return blink::WebMediaDeviceInfo::kMediaDeviceKindVideoInput; |
214 case MEDIA_DEVICE_TYPE_AUDIO_OUTPUT: | 215 case MEDIA_DEVICE_TYPE_AUDIO_OUTPUT: |
215 return blink::WebMediaDeviceInfo::kMediaDeviceKindAudioOutput; | 216 return blink::WebMediaDeviceInfo::kMediaDeviceKindAudioOutput; |
216 default: | 217 default: |
217 NOTREACHED(); | 218 NOTREACHED(); |
218 return blink::WebMediaDeviceInfo::kMediaDeviceKindAudioInput; | 219 return blink::WebMediaDeviceInfo::kMediaDeviceKindAudioInput; |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
| 223 bool IsValidAudioContentSource(const std::string& source) { |
| 224 return source == kMediaStreamSourceTab || |
| 225 source == kMediaStreamSourceDesktop || |
| 226 source == kMediaStreamSourceSystem; |
| 227 } |
| 228 |
| 229 bool IsValidVideoContentSource(const std::string& source) { |
| 230 return source == kMediaStreamSourceTab || |
| 231 source == kMediaStreamSourceDesktop || |
| 232 source == kMediaStreamSourceScreen; |
| 233 } |
| 234 |
222 static int g_next_request_id = 0; | 235 static int g_next_request_id = 0; |
223 | 236 |
224 } // namespace | 237 } // namespace |
225 | 238 |
226 // Class for storing information about a Blink request to create a | 239 // Class for storing information about a Blink request to create a |
227 // MediaStream. | 240 // MediaStream. |
228 class UserMediaClientImpl::UserMediaRequestInfo | 241 class UserMediaClientImpl::UserMediaRequestInfo |
229 : public base::SupportsWeakPtr<UserMediaRequestInfo> { | 242 : public base::SupportsWeakPtr<UserMediaRequestInfo> { |
230 public: | 243 public: |
231 using ResourcesReady = | 244 using ResourcesReady = |
(...skipping 26 matching lines...) Expand all Loading... |
258 // Called when a local audio source has finished (or failed) initializing. | 271 // Called when a local audio source has finished (or failed) initializing. |
259 void OnAudioSourceStarted(MediaStreamSource* source, | 272 void OnAudioSourceStarted(MediaStreamSource* source, |
260 MediaStreamRequestResult result, | 273 MediaStreamRequestResult result, |
261 const blink::WebString& result_name); | 274 const blink::WebString& result_name); |
262 | 275 |
263 int request_id() const { return request_id_; } | 276 int request_id() const { return request_id_; } |
264 | 277 |
265 State state() const { return state_; } | 278 State state() const { return state_; } |
266 void set_state(State state) { state_ = state; } | 279 void set_state(State state) { state_ = state; } |
267 | 280 |
268 bool enable_automatic_output_device_selection() const { | 281 // TODO(guidou): Remove this function. http://crbug.com/706408 |
269 return enable_automatic_output_device_selection_; | 282 bool legacy_enable_automatic_output_device_selection() const { |
| 283 DCHECK(IsOldAudioConstraints()); |
| 284 return legacy_enable_automatic_output_device_selection_; |
270 } | 285 } |
271 void set_enable_automatic_output_device_selection(bool value) { | 286 // TODO(guidou): Remove this function. http://crbug.com/706408 |
272 enable_automatic_output_device_selection_ = value; | 287 void set_legacy_enable_automatic_output_device_selection(bool value) { |
| 288 DCHECK(IsOldAudioConstraints()); |
| 289 legacy_enable_automatic_output_device_selection_ = value; |
| 290 } |
| 291 const AudioCaptureSettings& audio_capture_settings() const { |
| 292 DCHECK(!IsOldAudioConstraints()); |
| 293 return audio_capture_settings_; |
| 294 } |
| 295 bool is_audio_content_capture() const { |
| 296 DCHECK(!IsOldAudioConstraints()); |
| 297 return audio_capture_settings_.HasValue() && is_audio_content_capture_; |
| 298 } |
| 299 bool is_audio_device_capture() const { |
| 300 DCHECK(!IsOldAudioConstraints()); |
| 301 return audio_capture_settings_.HasValue() && !is_audio_content_capture_; |
| 302 } |
| 303 void SetAudioCaptureSettings(const AudioCaptureSettings& settings, |
| 304 bool is_content_capture) { |
| 305 DCHECK(settings.HasValue()); |
| 306 is_audio_content_capture_ = is_content_capture; |
| 307 audio_capture_settings_ = settings; |
273 } | 308 } |
274 const VideoCaptureSettings& video_capture_settings() const { | 309 const VideoCaptureSettings& video_capture_settings() const { |
275 return video_capture_settings_; | 310 return video_capture_settings_; |
276 } | 311 } |
277 void SetVideoCaptureSettings(const VideoCaptureSettings& settings, | 312 void SetVideoCaptureSettings(const VideoCaptureSettings& settings, |
278 bool is_content_capture) { | 313 bool is_content_capture) { |
279 DCHECK(settings.HasValue()); | 314 DCHECK(settings.HasValue()); |
280 is_video_content_capture_ = is_content_capture; | 315 is_video_content_capture_ = is_content_capture; |
281 video_capture_settings_ = settings; | 316 video_capture_settings_ = settings; |
282 } | 317 } |
(...skipping 15 matching lines...) Expand all Loading... |
298 MediaStreamRequestResult result, | 333 MediaStreamRequestResult result, |
299 const blink::WebString& result_name); | 334 const blink::WebString& result_name); |
300 | 335 |
301 // Cheks if the sources for all tracks have been started and if so, | 336 // Cheks if the sources for all tracks have been started and if so, |
302 // invoke the |ready_callback_|. Note that the caller should expect | 337 // invoke the |ready_callback_|. Note that the caller should expect |
303 // that |this| might be deleted when the function returns. | 338 // that |this| might be deleted when the function returns. |
304 void CheckAllTracksStarted(); | 339 void CheckAllTracksStarted(); |
305 | 340 |
306 const int request_id_; | 341 const int request_id_; |
307 State state_; | 342 State state_; |
308 bool enable_automatic_output_device_selection_; | 343 // TODO(guidou): Remove this field. http://crbug.com/706408 |
| 344 bool legacy_enable_automatic_output_device_selection_; |
| 345 AudioCaptureSettings audio_capture_settings_; |
| 346 bool is_audio_content_capture_; |
309 VideoCaptureSettings video_capture_settings_; | 347 VideoCaptureSettings video_capture_settings_; |
310 bool is_video_content_capture_; | 348 bool is_video_content_capture_; |
311 blink::WebMediaStream web_stream_; | 349 blink::WebMediaStream web_stream_; |
312 const blink::WebUserMediaRequest request_; | 350 const blink::WebUserMediaRequest request_; |
313 StreamControls stream_controls_; | 351 StreamControls stream_controls_; |
314 const bool is_processing_user_gesture_; | 352 const bool is_processing_user_gesture_; |
315 const url::Origin security_origin_; | 353 const url::Origin security_origin_; |
316 ResourcesReady ready_callback_; | 354 ResourcesReady ready_callback_; |
317 MediaStreamRequestResult request_result_; | 355 MediaStreamRequestResult request_result_; |
318 blink::WebString request_result_name_; | 356 blink::WebString request_result_name_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 421 } |
384 | 422 |
385 void UserMediaClientImpl::MaybeProcessNextRequestInfo() { | 423 void UserMediaClientImpl::MaybeProcessNextRequestInfo() { |
386 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 424 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
387 if (current_request_info_ || pending_request_infos_.empty()) | 425 if (current_request_info_ || pending_request_infos_.empty()) |
388 return; | 426 return; |
389 | 427 |
390 current_request_info_ = std::move(pending_request_infos_.front()); | 428 current_request_info_ = std::move(pending_request_infos_.front()); |
391 pending_request_infos_.pop_front(); | 429 pending_request_infos_.pop_front(); |
392 | 430 |
393 // TODO(guidou): Request audio and video capabilities in parallel. | 431 // TODO(guidou): Set up audio and video in parallel. |
394 if (current_request_info_->request().Audio()) { | 432 if (current_request_info_->request().Audio()) { |
395 bool request_audio_input_devices = false; | 433 if (IsOldAudioConstraints()) |
396 // TODO(guidou): Implement spec-compliant device selection for audio. See | 434 LegacySetupAudioInput(); |
397 // http://crbug.com/623104. | 435 else |
398 CopyConstraintsToTrackControls( | 436 SetupAudioInput(); |
399 current_request_info_->request().AudioConstraints(), | 437 return; |
400 ¤t_request_info_->stream_controls()->audio, | 438 } |
401 &request_audio_input_devices); | 439 SetupVideoInput(); |
402 CopyHotwordAndLocalEchoToStreamControls( | 440 } |
403 current_request_info_->request().AudioConstraints(), | |
404 current_request_info_->stream_controls()); | |
405 // Check if this input device should be used to select a matching output | |
406 // device for audio rendering. | |
407 bool enable_automatic_output_device_selection = false; | |
408 GetConstraintValueAsBoolean( | |
409 current_request_info_->request().AudioConstraints(), | |
410 &blink::WebMediaTrackConstraintSet::render_to_associated_sink, | |
411 &enable_automatic_output_device_selection); | |
412 current_request_info_->set_enable_automatic_output_device_selection( | |
413 enable_automatic_output_device_selection); | |
414 | 441 |
415 if (request_audio_input_devices) { | 442 void UserMediaClientImpl::LegacySetupAudioInput() { |
416 GetMediaDevicesDispatcher()->EnumerateDevices( | 443 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
417 true /* audio_input */, false /* video_input */, | 444 DCHECK(IsOldAudioConstraints()); |
418 false /* audio_output */, | 445 DCHECK(current_request_info_); |
419 base::Bind(&UserMediaClientImpl::SelectAudioInputDevice, | 446 DCHECK(current_request_info_->request().Audio()); |
420 weak_factory_.GetWeakPtr(), | 447 |
421 current_request_info_->request())); | 448 bool request_audio_input_devices = false; |
422 return; | 449 CopyConstraintsToTrackControls( |
423 } | 450 current_request_info_->request().AudioConstraints(), |
| 451 ¤t_request_info_->stream_controls()->audio, |
| 452 &request_audio_input_devices); |
| 453 CopyHotwordAndLocalEchoToStreamControls( |
| 454 current_request_info_->request().AudioConstraints(), |
| 455 current_request_info_->stream_controls()); |
| 456 // Check if this input device should be used to select a matching output |
| 457 // device for audio rendering. |
| 458 bool enable_automatic_output_device_selection = false; |
| 459 GetConstraintValueAsBoolean( |
| 460 current_request_info_->request().AudioConstraints(), |
| 461 &blink::WebMediaTrackConstraintSet::render_to_associated_sink, |
| 462 &enable_automatic_output_device_selection); |
| 463 current_request_info_->set_legacy_enable_automatic_output_device_selection( |
| 464 enable_automatic_output_device_selection); |
| 465 |
| 466 if (request_audio_input_devices) { |
| 467 GetMediaDevicesDispatcher()->EnumerateDevices( |
| 468 true /* audio_input */, false /* video_input */, |
| 469 false /* audio_output */, |
| 470 base::Bind(&UserMediaClientImpl::LegacySelectAudioInputDevice, |
| 471 weak_factory_.GetWeakPtr(), |
| 472 current_request_info_->request())); |
| 473 return; |
424 } | 474 } |
425 | 475 |
426 SetupVideoInput(current_request_info_->request()); | 476 // No further audio setup required. Continue with video. |
| 477 SetupVideoInput(); |
427 } | 478 } |
428 | 479 |
429 void UserMediaClientImpl::SelectAudioInputDevice( | 480 void UserMediaClientImpl::LegacySelectAudioInputDevice( |
430 const blink::WebUserMediaRequest& user_media_request, | 481 const blink::WebUserMediaRequest& user_media_request, |
431 const EnumerationResult& device_enumeration) { | 482 const EnumerationResult& device_enumeration) { |
432 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 483 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 484 DCHECK(IsOldAudioConstraints()); |
| 485 // The frame might reload or |user_media_request| might be cancelled while |
| 486 // devices are enumerated. Do nothing if a different request is being |
| 487 // processed at this point. |
433 if (!IsCurrentRequestInfo(user_media_request)) | 488 if (!IsCurrentRequestInfo(user_media_request)) |
434 return; | 489 return; |
435 | 490 |
436 auto& audio_controls = current_request_info_->stream_controls()->audio; | 491 auto& audio_controls = current_request_info_->stream_controls()->audio; |
437 DCHECK(audio_controls.requested); | 492 DCHECK(audio_controls.requested); |
438 DCHECK(IsDeviceSource(audio_controls.stream_source)); | 493 DCHECK(IsDeviceSource(audio_controls.stream_source)); |
439 | 494 |
440 if (!PickDeviceId(user_media_request.AudioConstraints(), | 495 if (!PickDeviceId(user_media_request.AudioConstraints(), |
441 device_enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT], | 496 device_enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT], |
442 &audio_controls.device_id)) { | 497 &audio_controls.device_id)) { |
443 GetUserMediaRequestFailed(user_media_request, MEDIA_DEVICE_NO_HARDWARE, ""); | 498 GetUserMediaRequestFailed(MEDIA_DEVICE_NO_HARDWARE, ""); |
444 return; | 499 return; |
445 } | 500 } |
446 | 501 |
447 SetupVideoInput(user_media_request); | 502 // No further audio setup required. Continue with video. |
| 503 SetupVideoInput(); |
448 } | 504 } |
449 | 505 |
450 void UserMediaClientImpl::SetupVideoInput( | 506 void UserMediaClientImpl::SetupAudioInput() { |
451 const blink::WebUserMediaRequest& user_media_request) { | |
452 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 507 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 508 DCHECK(!IsOldAudioConstraints()); |
| 509 DCHECK(current_request_info_); |
| 510 DCHECK(current_request_info_->request().Audio()); |
| 511 |
| 512 auto& audio_controls = current_request_info_->stream_controls()->audio; |
| 513 InitializeTrackControls(current_request_info_->request().AudioConstraints(), |
| 514 &audio_controls); |
| 515 if (IsDeviceSource(audio_controls.stream_source)) { |
| 516 GetMediaDevicesDispatcher()->GetAudioInputCapabilities(base::Bind( |
| 517 &UserMediaClientImpl::SelectAudioSettings, weak_factory_.GetWeakPtr(), |
| 518 current_request_info_->request())); |
| 519 } else { |
| 520 if (!IsValidAudioContentSource(audio_controls.stream_source)) { |
| 521 blink::WebString failed_constraint_name = |
| 522 blink::WebString::FromASCII(current_request_info_->request() |
| 523 .AudioConstraints() |
| 524 .Basic() |
| 525 .media_stream_source.GetName()); |
| 526 MediaStreamRequestResult result = MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED; |
| 527 GetUserMediaRequestFailed(result, failed_constraint_name); |
| 528 return; |
| 529 } |
| 530 SelectAudioSettings(current_request_info_->request(), |
| 531 AudioDeviceCaptureCapabilities()); |
| 532 } |
| 533 } |
| 534 |
| 535 void UserMediaClientImpl::SelectAudioSettings( |
| 536 const blink::WebUserMediaRequest& user_media_request, |
| 537 std::vector<::mojom::AudioInputDeviceCapabilitiesPtr> |
| 538 audio_input_capabilities) { |
| 539 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 540 DCHECK(!IsOldAudioConstraints()); |
| 541 // The frame might reload or |user_media_request| might be cancelled while |
| 542 // capabilities are queried. Do nothing if a different request is being |
| 543 // processed at this point. |
453 if (!IsCurrentRequestInfo(user_media_request)) | 544 if (!IsCurrentRequestInfo(user_media_request)) |
454 return; | 545 return; |
455 | 546 |
456 if (!user_media_request.Video()) { | 547 DCHECK(current_request_info_->stream_controls()->audio.requested); |
| 548 auto settings = |
| 549 SelectSettingsAudioCapture(std::move(audio_input_capabilities), |
| 550 user_media_request.AudioConstraints()); |
| 551 if (!settings.HasValue()) { |
| 552 blink::WebString failed_constraint_name = |
| 553 blink::WebString::FromASCII(settings.failed_constraint_name()); |
| 554 MediaStreamRequestResult result = |
| 555 failed_constraint_name.IsEmpty() |
| 556 ? MEDIA_DEVICE_NO_HARDWARE |
| 557 : MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED; |
| 558 GetUserMediaRequestFailed(result, failed_constraint_name); |
| 559 return; |
| 560 } |
| 561 current_request_info_->stream_controls()->audio.device_id = |
| 562 settings.device_id(); |
| 563 current_request_info_->stream_controls()->disable_local_echo = |
| 564 settings.disable_local_echo(); |
| 565 current_request_info_->stream_controls()->hotword_enabled = |
| 566 settings.hotword_enabled(); |
| 567 current_request_info_->SetAudioCaptureSettings( |
| 568 settings, |
| 569 !IsDeviceSource( |
| 570 current_request_info_->stream_controls()->audio.stream_source)); |
| 571 |
| 572 // No further audio setup required. Continue with video. |
| 573 SetupVideoInput(); |
| 574 } |
| 575 |
| 576 void UserMediaClientImpl::SetupVideoInput() { |
| 577 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 578 DCHECK(current_request_info_); |
| 579 |
| 580 if (!current_request_info_->request().Video()) { |
457 GenerateStreamForCurrentRequestInfo(); | 581 GenerateStreamForCurrentRequestInfo(); |
458 return; | 582 return; |
459 } | 583 } |
460 auto& video_controls = current_request_info_->stream_controls()->video; | 584 auto& video_controls = current_request_info_->stream_controls()->video; |
461 InitializeTrackControls(user_media_request.VideoConstraints(), | 585 InitializeTrackControls(current_request_info_->request().VideoConstraints(), |
462 &video_controls); | 586 &video_controls); |
463 if (IsDeviceSource(video_controls.stream_source)) { | 587 if (IsDeviceSource(video_controls.stream_source)) { |
464 GetMediaDevicesDispatcher()->GetVideoInputCapabilities( | 588 GetMediaDevicesDispatcher()->GetVideoInputCapabilities(base::Bind( |
465 base::Bind(&UserMediaClientImpl::SelectVideoDeviceSettings, | 589 &UserMediaClientImpl::SelectVideoDeviceSettings, |
466 weak_factory_.GetWeakPtr(), user_media_request)); | 590 weak_factory_.GetWeakPtr(), current_request_info_->request())); |
467 } else { | 591 } else { |
| 592 if (!IsValidVideoContentSource(video_controls.stream_source)) { |
| 593 blink::WebString failed_constraint_name = |
| 594 blink::WebString::FromASCII(current_request_info_->request() |
| 595 .VideoConstraints() |
| 596 .Basic() |
| 597 .media_stream_source.GetName()); |
| 598 MediaStreamRequestResult result = MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED; |
| 599 GetUserMediaRequestFailed(result, failed_constraint_name); |
| 600 return; |
| 601 } |
468 base::PostTaskAndReplyWithResult( | 602 base::PostTaskAndReplyWithResult( |
469 worker_task_runner_.get(), FROM_HERE, | 603 worker_task_runner_.get(), FROM_HERE, |
470 base::Bind(&SelectSettingsVideoContentCapture, | 604 base::Bind(&SelectSettingsVideoContentCapture, |
471 user_media_request.VideoConstraints(), | 605 current_request_info_->request().VideoConstraints(), |
472 video_controls.stream_source), | 606 video_controls.stream_source), |
473 base::Bind(&UserMediaClientImpl::FinalizeSelectVideoContentSettings, | 607 base::Bind(&UserMediaClientImpl::FinalizeSelectVideoContentSettings, |
474 weak_factory_.GetWeakPtr(), user_media_request)); | 608 weak_factory_.GetWeakPtr(), |
| 609 current_request_info_->request())); |
475 } | 610 } |
476 } | 611 } |
477 | 612 |
478 void UserMediaClientImpl::SelectVideoDeviceSettings( | 613 void UserMediaClientImpl::SelectVideoDeviceSettings( |
479 const blink::WebUserMediaRequest& user_media_request, | 614 const blink::WebUserMediaRequest& user_media_request, |
480 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> | 615 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> |
481 video_input_capabilities) { | 616 video_input_capabilities) { |
482 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 617 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 618 // The frame might reload or |user_media_request| might be cancelled while |
| 619 // capabilities are queried. Do nothing if a different request is being |
| 620 // processed at this point. |
483 if (!IsCurrentRequestInfo(user_media_request)) | 621 if (!IsCurrentRequestInfo(user_media_request)) |
484 return; | 622 return; |
485 | 623 |
486 DCHECK(current_request_info_->stream_controls()->video.requested); | 624 DCHECK(current_request_info_->stream_controls()->video.requested); |
487 DCHECK(IsDeviceSource( | 625 DCHECK(IsDeviceSource( |
488 current_request_info_->stream_controls()->video.stream_source)); | 626 current_request_info_->stream_controls()->video.stream_source)); |
489 | 627 |
490 VideoDeviceCaptureCapabilities capabilities; | 628 VideoDeviceCaptureCapabilities capabilities; |
491 capabilities.device_capabilities = std::move(video_input_capabilities); | 629 capabilities.device_capabilities = std::move(video_input_capabilities); |
492 capabilities.power_line_capabilities = { | 630 capabilities.power_line_capabilities = { |
(...skipping 18 matching lines...) Expand all Loading... |
511 if (!IsCurrentRequestInfo(user_media_request)) | 649 if (!IsCurrentRequestInfo(user_media_request)) |
512 return; | 650 return; |
513 | 651 |
514 if (!settings.HasValue()) { | 652 if (!settings.HasValue()) { |
515 blink::WebString failed_constraint_name = | 653 blink::WebString failed_constraint_name = |
516 blink::WebString::FromASCII(settings.failed_constraint_name()); | 654 blink::WebString::FromASCII(settings.failed_constraint_name()); |
517 MediaStreamRequestResult result = | 655 MediaStreamRequestResult result = |
518 failed_constraint_name.IsEmpty() | 656 failed_constraint_name.IsEmpty() |
519 ? MEDIA_DEVICE_NO_HARDWARE | 657 ? MEDIA_DEVICE_NO_HARDWARE |
520 : MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED; | 658 : MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED; |
521 GetUserMediaRequestFailed(user_media_request, result, | 659 GetUserMediaRequestFailed(result, failed_constraint_name); |
522 failed_constraint_name); | |
523 return; | 660 return; |
524 } | 661 } |
525 current_request_info_->stream_controls()->video.device_id = | 662 current_request_info_->stream_controls()->video.device_id = |
526 settings.device_id(); | 663 settings.device_id(); |
527 current_request_info_->SetVideoCaptureSettings( | 664 current_request_info_->SetVideoCaptureSettings( |
528 settings, false /* is_content_capture */); | 665 settings, false /* is_content_capture */); |
529 GenerateStreamForCurrentRequestInfo(); | 666 GenerateStreamForCurrentRequestInfo(); |
530 } | 667 } |
531 | 668 |
532 void UserMediaClientImpl::FinalizeSelectVideoContentSettings( | 669 void UserMediaClientImpl::FinalizeSelectVideoContentSettings( |
533 const blink::WebUserMediaRequest& user_media_request, | 670 const blink::WebUserMediaRequest& user_media_request, |
534 const VideoCaptureSettings& settings) { | 671 const VideoCaptureSettings& settings) { |
535 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 672 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
536 if (!IsCurrentRequestInfo(user_media_request)) | 673 if (!IsCurrentRequestInfo(user_media_request)) |
537 return; | 674 return; |
538 | 675 |
539 if (!settings.HasValue()) { | 676 if (!settings.HasValue()) { |
540 blink::WebString failed_constraint_name = | 677 blink::WebString failed_constraint_name = |
541 blink::WebString::FromASCII(settings.failed_constraint_name()); | 678 blink::WebString::FromASCII(settings.failed_constraint_name()); |
542 DCHECK(!failed_constraint_name.IsEmpty()); | 679 DCHECK(!failed_constraint_name.IsEmpty()); |
543 blink::WebString device_id_constraint_name = blink::WebString::FromASCII( | 680 GetUserMediaRequestFailed(MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, |
544 user_media_request.VideoConstraints().Basic().device_id.GetName()); | |
545 GetUserMediaRequestFailed(user_media_request, | |
546 MEDIA_DEVICE_CONSTRAINT_NOT_SATISFIED, | |
547 failed_constraint_name); | 681 failed_constraint_name); |
548 return; | 682 return; |
549 } | 683 } |
550 current_request_info_->stream_controls()->video.device_id = | 684 current_request_info_->stream_controls()->video.device_id = |
551 settings.device_id(); | 685 settings.device_id(); |
552 current_request_info_->SetVideoCaptureSettings(settings, | 686 current_request_info_->SetVideoCaptureSettings(settings, |
553 true /* is_content_capture */); | 687 true /* is_content_capture */); |
554 GenerateStreamForCurrentRequestInfo(); | 688 GenerateStreamForCurrentRequestInfo(); |
555 } | 689 } |
556 | 690 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 void UserMediaClientImpl::OnStreamGenerationFailed( | 890 void UserMediaClientImpl::OnStreamGenerationFailed( |
757 int request_id, | 891 int request_id, |
758 MediaStreamRequestResult result) { | 892 MediaStreamRequestResult result) { |
759 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 893 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
760 if (!IsCurrentRequestInfo(request_id)) { | 894 if (!IsCurrentRequestInfo(request_id)) { |
761 // This can happen if the request is cancelled or the frame reloads while | 895 // This can happen if the request is cancelled or the frame reloads while |
762 // MediaStreamDispatcher is processing the request. | 896 // MediaStreamDispatcher is processing the request. |
763 return; | 897 return; |
764 } | 898 } |
765 | 899 |
766 GetUserMediaRequestFailed(current_request_info_->request(), result, ""); | 900 GetUserMediaRequestFailed(result, ""); |
767 DeleteRequestInfo(current_request_info_->request()); | 901 DeleteRequestInfo(current_request_info_->request()); |
768 } | 902 } |
769 | 903 |
770 // Callback from MediaStreamDispatcher. | 904 // Callback from MediaStreamDispatcher. |
771 // The browser process has stopped a device used by a MediaStream. | 905 // The browser process has stopped a device used by a MediaStream. |
772 void UserMediaClientImpl::OnDeviceStopped( | 906 void UserMediaClientImpl::OnDeviceStopped( |
773 const std::string& label, | 907 const std::string& label, |
774 const StreamDeviceInfo& device_info) { | 908 const StreamDeviceInfo& device_info) { |
775 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 909 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
776 DVLOG(1) << "UserMediaClientImpl::OnDeviceStopped(" | 910 DVLOG(1) << "UserMediaClientImpl::OnDeviceStopped(" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 &UserMediaClientImpl::OnLocalSourceStopped, weak_factory_.GetWeakPtr())); | 974 &UserMediaClientImpl::OnLocalSourceStopped, weak_factory_.GetWeakPtr())); |
841 source.SetExtraData(audio_source); // Takes ownership. | 975 source.SetExtraData(audio_source); // Takes ownership. |
842 return source; | 976 return source; |
843 } | 977 } |
844 | 978 |
845 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( | 979 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( |
846 const StreamDeviceInfo& device, | 980 const StreamDeviceInfo& device, |
847 const blink::WebMediaConstraints& constraints, | 981 const blink::WebMediaConstraints& constraints, |
848 const MediaStreamSource::ConstraintsCallback& source_ready) { | 982 const MediaStreamSource::ConstraintsCallback& source_ready) { |
849 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 983 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 984 DCHECK(current_request_info_); |
850 // If the audio device is a loopback device (for screen capture), or if the | 985 // If the audio device is a loopback device (for screen capture), or if the |
851 // constraints/effects parameters indicate no audio processing is needed, | 986 // constraints/effects parameters indicate no audio processing is needed, |
852 // create an efficient, direct-path MediaStreamAudioSource instance. | 987 // create an efficient, direct-path MediaStreamAudioSource instance. |
| 988 AudioProcessingProperties audio_processing_properties = |
| 989 IsOldAudioConstraints() ? AudioProcessingProperties::FromConstraints( |
| 990 constraints, device.device.input) |
| 991 : current_request_info_->audio_capture_settings() |
| 992 .audio_processing_properties(); |
853 if (IsScreenCaptureMediaType(device.device.type) || | 993 if (IsScreenCaptureMediaType(device.device.type) || |
854 !MediaStreamAudioProcessor::WouldModifyAudio( | 994 !MediaStreamAudioProcessor::WouldModifyAudio( |
855 constraints, device.device.input.effects)) { | 995 audio_processing_properties)) { |
856 return new LocalMediaStreamAudioSource(RenderFrameObserver::routing_id(), | 996 return new LocalMediaStreamAudioSource(RenderFrameObserver::routing_id(), |
857 device, source_ready); | 997 device, source_ready); |
858 } | 998 } |
859 | 999 |
860 // The audio device is not associated with screen capture and also requires | 1000 // The audio device is not associated with screen capture and also requires |
861 // processing. | 1001 // processing. |
862 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( | 1002 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( |
863 RenderFrameObserver::routing_id(), device, constraints, source_ready, | 1003 RenderFrameObserver::routing_id(), device, audio_processing_properties, |
864 dependency_factory_); | 1004 source_ready, dependency_factory_); |
865 return source; | 1005 return source; |
866 } | 1006 } |
867 | 1007 |
868 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( | 1008 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( |
869 const StreamDeviceInfo& device, | 1009 const StreamDeviceInfo& device, |
870 const MediaStreamSource::SourceStoppedCallback& stop_callback) { | 1010 const MediaStreamSource::SourceStoppedCallback& stop_callback) { |
871 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 1011 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
872 DCHECK(current_request_info_); | 1012 DCHECK(current_request_info_); |
873 if (IsOldVideoConstraints()) { | 1013 if (IsOldVideoConstraints()) { |
874 return new MediaStreamVideoCapturerSource(stop_callback, device, | 1014 return new MediaStreamVideoCapturerSource(stop_callback, device, |
(...skipping 24 matching lines...) Expand all Loading... |
899 | 1039 |
900 void UserMediaClientImpl::CreateAudioTracks( | 1040 void UserMediaClientImpl::CreateAudioTracks( |
901 const StreamDeviceInfoArray& devices, | 1041 const StreamDeviceInfoArray& devices, |
902 const blink::WebMediaConstraints& constraints, | 1042 const blink::WebMediaConstraints& constraints, |
903 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks) { | 1043 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks) { |
904 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 1044 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
905 DCHECK(current_request_info_); | 1045 DCHECK(current_request_info_); |
906 DCHECK_EQ(devices.size(), webkit_tracks->size()); | 1046 DCHECK_EQ(devices.size(), webkit_tracks->size()); |
907 | 1047 |
908 StreamDeviceInfoArray overridden_audio_array = devices; | 1048 StreamDeviceInfoArray overridden_audio_array = devices; |
909 if (!current_request_info_->enable_automatic_output_device_selection()) { | 1049 bool render_to_associated_sink = |
| 1050 IsOldAudioConstraints() |
| 1051 ? current_request_info_ |
| 1052 ->legacy_enable_automatic_output_device_selection() |
| 1053 : current_request_info_->audio_capture_settings().HasValue() && |
| 1054 current_request_info_->audio_capture_settings() |
| 1055 .render_to_associated_sink(); |
| 1056 if (!render_to_associated_sink) { |
910 // If the GetUserMedia request did not explicitly set the constraint | 1057 // If the GetUserMedia request did not explicitly set the constraint |
911 // kMediaStreamRenderToAssociatedSink, the output device parameters must | 1058 // kMediaStreamRenderToAssociatedSink, the output device parameters must |
912 // be removed. | 1059 // be removed. |
913 for (auto& device_info : overridden_audio_array) { | 1060 for (auto& device_info : overridden_audio_array) { |
914 device_info.device.matched_output_device_id = ""; | 1061 device_info.device.matched_output_device_id = ""; |
915 device_info.device.matched_output = | 1062 device_info.device.matched_output = |
916 MediaStreamDevice::AudioDeviceParameters(); | 1063 MediaStreamDevice::AudioDeviceParameters(); |
917 } | 1064 } |
918 } | 1065 } |
919 | 1066 |
(...skipping 10 matching lines...) Expand all Loading... |
930 const std::string& label, | 1077 const std::string& label, |
931 UserMediaRequestInfo* request_info, | 1078 UserMediaRequestInfo* request_info, |
932 MediaStreamRequestResult result, | 1079 MediaStreamRequestResult result, |
933 const blink::WebString& result_name) { | 1080 const blink::WebString& result_name) { |
934 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 1081 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
935 if (result == content::MEDIA_DEVICE_OK) { | 1082 if (result == content::MEDIA_DEVICE_OK) { |
936 GetUserMediaRequestSucceeded(*request_info->web_stream(), | 1083 GetUserMediaRequestSucceeded(*request_info->web_stream(), |
937 request_info->request()); | 1084 request_info->request()); |
938 media_stream_dispatcher_->OnStreamStarted(label); | 1085 media_stream_dispatcher_->OnStreamStarted(label); |
939 } else { | 1086 } else { |
940 GetUserMediaRequestFailed(request_info->request(), result, result_name); | 1087 GetUserMediaRequestFailed(result, result_name); |
941 | 1088 |
942 blink::WebVector<blink::WebMediaStreamTrack> tracks; | 1089 blink::WebVector<blink::WebMediaStreamTrack> tracks; |
943 request_info->web_stream()->AudioTracks(tracks); | 1090 request_info->web_stream()->AudioTracks(tracks); |
944 for (auto& web_track : tracks) { | 1091 for (auto& web_track : tracks) { |
945 MediaStreamTrack* track = MediaStreamTrack::GetTrack(web_track); | 1092 MediaStreamTrack* track = MediaStreamTrack::GetTrack(web_track); |
946 if (track) | 1093 if (track) |
947 track->Stop(); | 1094 track->Stop(); |
948 } | 1095 } |
949 request_info->web_stream()->VideoTracks(tracks); | 1096 request_info->web_stream()->VideoTracks(tracks); |
950 for (auto& web_track : tracks) { | 1097 for (auto& web_track : tracks) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 void UserMediaClientImpl::DelayedGetUserMediaRequestSucceeded( | 1142 void UserMediaClientImpl::DelayedGetUserMediaRequestSucceeded( |
996 const blink::WebMediaStream& stream, | 1143 const blink::WebMediaStream& stream, |
997 blink::WebUserMediaRequest request) { | 1144 blink::WebUserMediaRequest request) { |
998 DVLOG(1) << "UserMediaClientImpl::DelayedGetUserMediaRequestSucceeded"; | 1145 DVLOG(1) << "UserMediaClientImpl::DelayedGetUserMediaRequestSucceeded"; |
999 LogUserMediaRequestResult(MEDIA_DEVICE_OK); | 1146 LogUserMediaRequestResult(MEDIA_DEVICE_OK); |
1000 DeleteRequestInfo(request); | 1147 DeleteRequestInfo(request); |
1001 request.RequestSucceeded(stream); | 1148 request.RequestSucceeded(stream); |
1002 } | 1149 } |
1003 | 1150 |
1004 void UserMediaClientImpl::GetUserMediaRequestFailed( | 1151 void UserMediaClientImpl::GetUserMediaRequestFailed( |
1005 blink::WebUserMediaRequest request, | |
1006 MediaStreamRequestResult result, | 1152 MediaStreamRequestResult result, |
1007 const blink::WebString& result_name) { | 1153 const blink::WebString& result_name) { |
| 1154 DCHECK(current_request_info_); |
1008 // Completing the getUserMedia request can lead to that the RenderFrame and | 1155 // Completing the getUserMedia request can lead to that the RenderFrame and |
1009 // the UserMediaClientImpl is destroyed if the JavaScript code request the | 1156 // the UserMediaClientImpl is destroyed if the JavaScript code request the |
1010 // frame to be destroyed within the scope of the callback. Therefore, | 1157 // frame to be destroyed within the scope of the callback. Therefore, |
1011 // post a task to complete the request with a clean stack. | 1158 // post a task to complete the request with a clean stack. |
1012 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1159 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1013 FROM_HERE, | 1160 FROM_HERE, |
1014 base::Bind(&UserMediaClientImpl::DelayedGetUserMediaRequestFailed, | 1161 base::Bind(&UserMediaClientImpl::DelayedGetUserMediaRequestFailed, |
1015 weak_factory_.GetWeakPtr(), request, result, result_name)); | 1162 weak_factory_.GetWeakPtr(), current_request_info_->request(), |
| 1163 result, result_name)); |
1016 } | 1164 } |
1017 | 1165 |
1018 void UserMediaClientImpl::DelayedGetUserMediaRequestFailed( | 1166 void UserMediaClientImpl::DelayedGetUserMediaRequestFailed( |
1019 blink::WebUserMediaRequest request, | 1167 blink::WebUserMediaRequest request, |
1020 MediaStreamRequestResult result, | 1168 MediaStreamRequestResult result, |
1021 const blink::WebString& result_name) { | 1169 const blink::WebString& result_name) { |
1022 LogUserMediaRequestResult(result); | 1170 LogUserMediaRequestResult(result); |
1023 DeleteRequestInfo(request); | 1171 DeleteRequestInfo(request); |
1024 switch (result) { | 1172 switch (result) { |
1025 case MEDIA_DEVICE_OK: | 1173 case MEDIA_DEVICE_OK: |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 const ::mojom::MediaDevicesDispatcherHostPtr& | 1402 const ::mojom::MediaDevicesDispatcherHostPtr& |
1255 UserMediaClientImpl::GetMediaDevicesDispatcher() { | 1403 UserMediaClientImpl::GetMediaDevicesDispatcher() { |
1256 if (!media_devices_dispatcher_) { | 1404 if (!media_devices_dispatcher_) { |
1257 render_frame()->GetRemoteInterfaces()->GetInterface( | 1405 render_frame()->GetRemoteInterfaces()->GetInterface( |
1258 mojo::MakeRequest(&media_devices_dispatcher_)); | 1406 mojo::MakeRequest(&media_devices_dispatcher_)); |
1259 } | 1407 } |
1260 | 1408 |
1261 return media_devices_dispatcher_; | 1409 return media_devices_dispatcher_; |
1262 } | 1410 } |
1263 | 1411 |
| 1412 const AudioCaptureSettings& |
| 1413 UserMediaClientImpl::AudioCaptureSettingsForTesting() const { |
| 1414 DCHECK(current_request_info_); |
| 1415 return current_request_info_->audio_capture_settings(); |
| 1416 } |
| 1417 |
| 1418 const VideoCaptureSettings& |
| 1419 UserMediaClientImpl::VideoCaptureSettingsForTesting() const { |
| 1420 DCHECK(current_request_info_); |
| 1421 return current_request_info_->video_capture_settings(); |
| 1422 } |
| 1423 |
1264 base::Optional<bool> | 1424 base::Optional<bool> |
1265 UserMediaClientImpl::AutomaticOutputDeviceSelectionEnabledForCurrentRequest() { | 1425 UserMediaClientImpl::AutomaticOutputDeviceSelectionEnabledForCurrentRequest() { |
1266 if (!current_request_info_) | 1426 if (!current_request_info_) |
1267 return base::Optional<bool>(); | 1427 return base::Optional<bool>(); |
1268 | 1428 |
1269 return base::Optional<bool>( | 1429 return base::Optional<bool>( |
1270 current_request_info_->enable_automatic_output_device_selection()); | 1430 current_request_info_->legacy_enable_automatic_output_device_selection()); |
1271 } | 1431 } |
1272 | 1432 |
1273 void UserMediaClientImpl::OnDestruct() { | 1433 void UserMediaClientImpl::OnDestruct() { |
1274 delete this; | 1434 delete this; |
1275 } | 1435 } |
1276 | 1436 |
1277 UserMediaClientImpl::UserMediaRequestInfo::UserMediaRequestInfo( | 1437 UserMediaClientImpl::UserMediaRequestInfo::UserMediaRequestInfo( |
1278 int request_id, | 1438 int request_id, |
1279 const blink::WebUserMediaRequest& request, | 1439 const blink::WebUserMediaRequest& request, |
1280 bool is_processing_user_gesture, | 1440 bool is_processing_user_gesture, |
1281 const url::Origin& security_origin) | 1441 const url::Origin& security_origin) |
1282 : request_id_(request_id), | 1442 : request_id_(request_id), |
1283 state_(State::NOT_SENT_FOR_GENERATION), | 1443 state_(State::NOT_SENT_FOR_GENERATION), |
1284 enable_automatic_output_device_selection_(false), | 1444 legacy_enable_automatic_output_device_selection_(false), |
| 1445 is_audio_content_capture_(false), |
1285 is_video_content_capture_(false), | 1446 is_video_content_capture_(false), |
1286 request_(request), | 1447 request_(request), |
1287 is_processing_user_gesture_(is_processing_user_gesture), | 1448 is_processing_user_gesture_(is_processing_user_gesture), |
1288 security_origin_(security_origin), | 1449 security_origin_(security_origin), |
1289 request_result_(MEDIA_DEVICE_OK), | 1450 request_result_(MEDIA_DEVICE_OK), |
1290 request_result_name_("") {} | 1451 request_result_name_("") {} |
1291 | 1452 |
1292 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( | 1453 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( |
1293 const blink::WebMediaStreamTrack& track, | 1454 const blink::WebMediaStreamTrack& track, |
1294 bool is_pending) { | 1455 bool is_pending) { |
1295 DCHECK(track.Source().GetType() == blink::WebMediaStreamSource::kTypeAudio); | 1456 DCHECK(track.Source().GetType() == blink::WebMediaStreamSource::kTypeAudio); |
| 1457 DCHECK(request_.Audio()); |
| 1458 #if DCHECK_IS_ON() |
| 1459 if (!IsOldAudioConstraints()) |
| 1460 DCHECK(audio_capture_settings_.HasValue()); |
| 1461 #endif |
1296 MediaStreamAudioSource* native_source = | 1462 MediaStreamAudioSource* native_source = |
1297 MediaStreamAudioSource::From(track.Source()); | 1463 MediaStreamAudioSource::From(track.Source()); |
1298 // Add the source as pending since OnTrackStarted will expect it to be there. | 1464 // Add the source as pending since OnTrackStarted will expect it to be there. |
1299 sources_waiting_for_callback_.push_back(native_source); | 1465 sources_waiting_for_callback_.push_back(native_source); |
1300 | 1466 |
1301 sources_.push_back(track.Source()); | 1467 sources_.push_back(track.Source()); |
1302 bool connected = native_source->ConnectToTrack(track); | 1468 bool connected = native_source->ConnectToTrack(track); |
1303 if (!is_pending) { | 1469 if (!is_pending) { |
1304 OnTrackStarted( | 1470 OnTrackStarted( |
1305 native_source, | 1471 native_source, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 const blink::WebString& result_name) { | 1545 const blink::WebString& result_name) { |
1380 // Check if we're waiting to be notified of this source. If not, then we'll | 1546 // Check if we're waiting to be notified of this source. If not, then we'll |
1381 // ignore the notification. | 1547 // ignore the notification. |
1382 auto found = std::find(sources_waiting_for_callback_.begin(), | 1548 auto found = std::find(sources_waiting_for_callback_.begin(), |
1383 sources_waiting_for_callback_.end(), source); | 1549 sources_waiting_for_callback_.end(), source); |
1384 if (found != sources_waiting_for_callback_.end()) | 1550 if (found != sources_waiting_for_callback_.end()) |
1385 OnTrackStarted(source, result, result_name); | 1551 OnTrackStarted(source, result, result_name); |
1386 } | 1552 } |
1387 | 1553 |
1388 } // namespace content | 1554 } // namespace content |
OLD | NEW |