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_audio_track.h" | |
23 #include "content/renderer/media/media_stream_constraints_util.h" | 24 #include "content/renderer/media/media_stream_constraints_util.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" |
35 #include "media/base/bind_to_current_loop.h" | |
34 #include "media/capture/video_capture_types.h" | 36 #include "media/capture/video_capture_types.h" |
35 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 37 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
36 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" | 38 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" |
37 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 39 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
38 #include "third_party/WebKit/public/platform/WebString.h" | 40 #include "third_party/WebKit/public/platform/WebString.h" |
39 #include "third_party/WebKit/public/web/WebDocument.h" | 41 #include "third_party/WebKit/public/web/WebDocument.h" |
40 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 42 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
41 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 43 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
42 | 44 |
43 namespace content { | 45 namespace content { |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 | 705 |
704 for (auto it = pending_local_sources_.begin(); | 706 for (auto it = pending_local_sources_.begin(); |
705 it != pending_local_sources_.end(); ++it) { | 707 it != pending_local_sources_.end(); ++it) { |
706 MediaStreamSource* const source_extra_data = | 708 MediaStreamSource* const source_extra_data = |
707 static_cast<MediaStreamSource*>((*it).getExtraData()); | 709 static_cast<MediaStreamSource*>((*it).getExtraData()); |
708 if (source_extra_data != source) | 710 if (source_extra_data != source) |
709 continue; | 711 continue; |
710 if (result == MEDIA_DEVICE_OK) | 712 if (result == MEDIA_DEVICE_OK) |
711 local_sources_.push_back((*it)); | 713 local_sources_.push_back((*it)); |
712 pending_local_sources_.erase(it); | 714 pending_local_sources_.erase(it); |
713 | |
714 NotifyCurrentRequestInfoOfAudioSourceStarted(source, result, result_name); | |
715 return; | 715 return; |
716 } | 716 } |
717 NOTREACHED(); | 717 NOTREACHED(); |
718 } | 718 } |
719 | 719 |
720 void UserMediaClientImpl::NotifyCurrentRequestInfoOfAudioSourceStarted( | 720 void UserMediaClientImpl::NotifyCurrentRequestInfoOfAudioSourceStarted( |
721 MediaStreamSource* source, | 721 MediaStreamSource* source, |
722 MediaStreamRequestResult result, | 722 MediaStreamRequestResult result, |
723 const blink::WebString& result_name) { | 723 const blink::WebString& result_name) { |
724 // The only request possibly being processed is |current_request_info_|. | 724 // The only request possibly being processed is |current_request_info_|. |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 const blink::WebMediaStreamTrack& track, | 1285 const blink::WebMediaStreamTrack& track, |
1286 bool is_pending) { | 1286 bool is_pending) { |
1287 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio); | 1287 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio); |
1288 MediaStreamAudioSource* native_source = | 1288 MediaStreamAudioSource* native_source = |
1289 MediaStreamAudioSource::From(track.source()); | 1289 MediaStreamAudioSource::From(track.source()); |
1290 // Add the source as pending since OnTrackStarted will expect it to be there. | 1290 // Add the source as pending since OnTrackStarted will expect it to be there. |
1291 sources_waiting_for_callback_.push_back(native_source); | 1291 sources_waiting_for_callback_.push_back(native_source); |
1292 | 1292 |
1293 sources_.push_back(track.source()); | 1293 sources_.push_back(track.source()); |
1294 bool connected = native_source->ConnectToTrack(track); | 1294 bool connected = native_source->ConnectToTrack(track); |
1295 if (!is_pending) { | 1295 if (!is_pending && !connected) { |
Guido Urdaneta
2017/04/06 15:48:40
Shouldn't it fail if is_pending, but !connected?
| |
1296 OnTrackStarted( | 1296 // It's a failure, and it's final. |
1297 native_source, | 1297 OnTrackStarted(native_source, MEDIA_DEVICE_TRACK_START_FAILURE, ""); |
1298 connected ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE, ""); | 1298 } else { |
1299 // The request may succeed later. | |
1300 // The track will be marked as connected once the configuration has | |
1301 // propagated. | |
1302 MediaStreamAudioTrack::From(track)->SetFormatConfiguredCallback( | |
1303 media::BindToCurrentLoop(base::Bind( | |
1304 &UserMediaClientImpl::UserMediaRequestInfo::OnTrackStarted, | |
1305 AsWeakPtr(), native_source, content::MEDIA_DEVICE_OK, | |
1306 blink::WebString()))); | |
1299 } | 1307 } |
1300 } | 1308 } |
1301 | 1309 |
1302 blink::WebMediaStreamTrack | 1310 blink::WebMediaStreamTrack |
1303 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( | 1311 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( |
1304 const blink::WebMediaStreamSource& source, | 1312 const blink::WebMediaStreamSource& source, |
1305 const blink::WebMediaConstraints& constraints) { | 1313 const blink::WebMediaConstraints& constraints) { |
1306 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); | 1314 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); |
1307 MediaStreamVideoSource* native_source = | 1315 MediaStreamVideoSource* native_source = |
1308 MediaStreamVideoSource::GetVideoSource(source); | 1316 MediaStreamVideoSource::GetVideoSource(source); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1356 } | 1364 } |
1357 | 1365 |
1358 void UserMediaClientImpl::UserMediaRequestInfo::OnAudioSourceStarted( | 1366 void UserMediaClientImpl::UserMediaRequestInfo::OnAudioSourceStarted( |
1359 MediaStreamSource* source, | 1367 MediaStreamSource* source, |
1360 MediaStreamRequestResult result, | 1368 MediaStreamRequestResult result, |
1361 const blink::WebString& result_name) { | 1369 const blink::WebString& result_name) { |
1362 // Check if we're waiting to be notified of this source. If not, then we'll | 1370 // Check if we're waiting to be notified of this source. If not, then we'll |
1363 // ignore the notification. | 1371 // ignore the notification. |
1364 auto found = std::find(sources_waiting_for_callback_.begin(), | 1372 auto found = std::find(sources_waiting_for_callback_.begin(), |
1365 sources_waiting_for_callback_.end(), source); | 1373 sources_waiting_for_callback_.end(), source); |
1366 if (found != sources_waiting_for_callback_.end()) | 1374 // If the start failed, inform the request here. |
1375 if (found != sources_waiting_for_callback_.end() && | |
1376 result != content::MEDIA_DEVICE_OK) | |
1367 OnTrackStarted(source, result, result_name); | 1377 OnTrackStarted(source, result, result_name); |
1368 } | 1378 } |
1369 | 1379 |
1370 } // namespace content | 1380 } // namespace content |
OLD | NEW |