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" | |
24 #include "content/renderer/media/media_stream_constraints_util.h" | 23 #include "content/renderer/media/media_stream_constraints_util.h" |
25 #include "content/renderer/media/media_stream_constraints_util_video_content.h" | 24 #include "content/renderer/media/media_stream_constraints_util_video_content.h" |
26 #include "content/renderer/media/media_stream_constraints_util_video_device.h" | 25 #include "content/renderer/media/media_stream_constraints_util_video_device.h" |
27 #include "content/renderer/media/media_stream_dispatcher.h" | 26 #include "content/renderer/media/media_stream_dispatcher.h" |
28 #include "content/renderer/media/media_stream_video_capturer_source.h" | 27 #include "content/renderer/media/media_stream_video_capturer_source.h" |
29 #include "content/renderer/media/media_stream_video_track.h" | 28 #include "content/renderer/media/media_stream_video_track.h" |
30 #include "content/renderer/media/peer_connection_tracker.h" | 29 #include "content/renderer/media/peer_connection_tracker.h" |
31 #include "content/renderer/media/webrtc/processed_local_audio_source.h" | 30 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
32 #include "content/renderer/media/webrtc_logging.h" | 31 #include "content/renderer/media/webrtc_logging.h" |
33 #include "content/renderer/media/webrtc_uma_histograms.h" | 32 #include "content/renderer/media/webrtc_uma_histograms.h" |
34 #include "content/renderer/render_thread_impl.h" | 33 #include "content/renderer/render_thread_impl.h" |
35 #include "media/base/bind_to_current_loop.h" | |
36 #include "media/capture/video_capture_types.h" | 34 #include "media/capture/video_capture_types.h" |
37 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 35 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
38 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" | 36 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" |
39 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 37 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
40 #include "third_party/WebKit/public/platform/WebString.h" | 38 #include "third_party/WebKit/public/platform/WebString.h" |
41 #include "third_party/WebKit/public/web/WebDocument.h" | 39 #include "third_party/WebKit/public/web/WebDocument.h" |
42 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 40 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
43 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 41 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
44 | 42 |
45 namespace content { | 43 namespace content { |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 | 703 |
706 for (auto it = pending_local_sources_.begin(); | 704 for (auto it = pending_local_sources_.begin(); |
707 it != pending_local_sources_.end(); ++it) { | 705 it != pending_local_sources_.end(); ++it) { |
708 MediaStreamSource* const source_extra_data = | 706 MediaStreamSource* const source_extra_data = |
709 static_cast<MediaStreamSource*>((*it).getExtraData()); | 707 static_cast<MediaStreamSource*>((*it).getExtraData()); |
710 if (source_extra_data != source) | 708 if (source_extra_data != source) |
711 continue; | 709 continue; |
712 if (result == MEDIA_DEVICE_OK) | 710 if (result == MEDIA_DEVICE_OK) |
713 local_sources_.push_back((*it)); | 711 local_sources_.push_back((*it)); |
714 pending_local_sources_.erase(it); | 712 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 && !connected) { | 1295 if (!is_pending) { |
1296 // It's a failure, and it's final. | 1296 OnTrackStarted( |
1297 OnTrackStarted(native_source, MEDIA_DEVICE_TRACK_START_FAILURE, ""); | 1297 native_source, |
1298 } else { | 1298 connected ? MEDIA_DEVICE_OK : MEDIA_DEVICE_TRACK_START_FAILURE, ""); |
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()))); | |
1307 } | 1299 } |
1308 } | 1300 } |
1309 | 1301 |
1310 blink::WebMediaStreamTrack | 1302 blink::WebMediaStreamTrack |
1311 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( | 1303 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( |
1312 const blink::WebMediaStreamSource& source, | 1304 const blink::WebMediaStreamSource& source, |
1313 const blink::WebMediaConstraints& constraints) { | 1305 const blink::WebMediaConstraints& constraints) { |
1314 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); | 1306 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); |
1315 MediaStreamVideoSource* native_source = | 1307 MediaStreamVideoSource* native_source = |
1316 MediaStreamVideoSource::GetVideoSource(source); | 1308 MediaStreamVideoSource::GetVideoSource(source); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 } | 1356 } |
1365 | 1357 |
1366 void UserMediaClientImpl::UserMediaRequestInfo::OnAudioSourceStarted( | 1358 void UserMediaClientImpl::UserMediaRequestInfo::OnAudioSourceStarted( |
1367 MediaStreamSource* source, | 1359 MediaStreamSource* source, |
1368 MediaStreamRequestResult result, | 1360 MediaStreamRequestResult result, |
1369 const blink::WebString& result_name) { | 1361 const blink::WebString& result_name) { |
1370 // Check if we're waiting to be notified of this source. If not, then we'll | 1362 // Check if we're waiting to be notified of this source. If not, then we'll |
1371 // ignore the notification. | 1363 // ignore the notification. |
1372 auto found = std::find(sources_waiting_for_callback_.begin(), | 1364 auto found = std::find(sources_waiting_for_callback_.begin(), |
1373 sources_waiting_for_callback_.end(), source); | 1365 sources_waiting_for_callback_.end(), source); |
1374 // If the start failed, inform the request here. | 1366 if (found != sources_waiting_for_callback_.end()) |
1375 if (found != sources_waiting_for_callback_.end() && | |
1376 result != content::MEDIA_DEVICE_OK) | |
1377 OnTrackStarted(source, result, result_name); | 1367 OnTrackStarted(source, result, result_name); |
1378 } | 1368 } |
1379 | 1369 |
1380 } // namespace content | 1370 } // namespace content |
OLD | NEW |