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> |
11 | 11 |
12 #include "base/hash.h" | 12 #include "base/hash.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
21 #include "content/public/renderer/render_frame.h" | 21 #include "content/public/renderer/render_frame.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_source.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_dispatcher.h" | 24 #include "content/renderer/media/media_stream_dispatcher.h" |
26 #include "content/renderer/media/media_stream_video_capturer_source.h" | 25 #include "content/renderer/media/media_stream_video_capturer_source.h" |
27 #include "content/renderer/media/media_stream_video_track.h" | 26 #include "content/renderer/media/media_stream_video_track.h" |
28 #include "content/renderer/media/peer_connection_tracker.h" | 27 #include "content/renderer/media/peer_connection_tracker.h" |
| 28 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
29 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" | 29 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
30 #include "content/renderer/media/webrtc_audio_capturer.h" | |
31 #include "content/renderer/media/webrtc_logging.h" | 30 #include "content/renderer/media/webrtc_logging.h" |
32 #include "content/renderer/media/webrtc_uma_histograms.h" | 31 #include "content/renderer/media/webrtc_uma_histograms.h" |
33 #include "content/renderer/render_thread_impl.h" | 32 #include "content/renderer/render_thread_impl.h" |
34 #include "third_party/WebKit/public/platform/URLConversion.h" | 33 #include "third_party/WebKit/public/platform/URLConversion.h" |
35 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 34 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
36 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" | 35 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" |
37 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 36 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
38 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h
" | 37 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h
" |
39 #include "third_party/WebKit/public/web/WebDocument.h" | 38 #include "third_party/WebKit/public/web/WebDocument.h" |
40 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 39 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 << ", name = " << webkit_source->name().utf8(); | 620 << ", name = " << webkit_source->name().utf8(); |
622 | 621 |
623 if (type == blink::WebMediaStreamSource::TypeVideo) { | 622 if (type == blink::WebMediaStreamSource::TypeVideo) { |
624 webkit_source->setExtraData( | 623 webkit_source->setExtraData( |
625 CreateVideoSource( | 624 CreateVideoSource( |
626 device, | 625 device, |
627 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, | 626 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, |
628 weak_factory_.GetWeakPtr()))); | 627 weak_factory_.GetWeakPtr()))); |
629 } else { | 628 } else { |
630 DCHECK_EQ(blink::WebMediaStreamSource::TypeAudio, type); | 629 DCHECK_EQ(blink::WebMediaStreamSource::TypeAudio, type); |
631 MediaStreamAudioSource* audio_source( | 630 MediaStreamAudioSource* const audio_source = |
632 new MediaStreamAudioSource( | 631 CreateAudioSource(device, constraints); |
633 RenderFrameObserver::routing_id(), | 632 audio_source->SetStopCallback( |
634 device, | 633 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, |
635 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, | 634 weak_factory_.GetWeakPtr())); |
636 weak_factory_.GetWeakPtr()), | 635 webkit_source->setExtraData(audio_source); // Takes ownership. |
637 dependency_factory_)); | |
638 webkit_source->setExtraData(audio_source); | |
639 } | 636 } |
640 local_sources_.push_back(*webkit_source); | 637 local_sources_.push_back(*webkit_source); |
641 } | 638 } |
642 | 639 |
| 640 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( |
| 641 const StreamDeviceInfo& device, |
| 642 const blink::WebMediaConstraints& constraints) { |
| 643 // TODO(miu): In a soon-upcoming change, I'll be providing an alternative |
| 644 // MediaStreamAudioSource that bypasses audio processing for the non-WebRTC |
| 645 // use cases. http://crbug.com/577881 |
| 646 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( |
| 647 RenderFrameObserver::routing_id(), device, dependency_factory_); |
| 648 source->SetSourceConstraints(constraints); |
| 649 return source; |
| 650 } |
| 651 |
643 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( | 652 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( |
644 const StreamDeviceInfo& device, | 653 const StreamDeviceInfo& device, |
645 const MediaStreamSource::SourceStoppedCallback& stop_callback) { | 654 const MediaStreamSource::SourceStoppedCallback& stop_callback) { |
646 content::MediaStreamVideoCapturerSource* ret = | 655 content::MediaStreamVideoCapturerSource* ret = |
647 new content::MediaStreamVideoCapturerSource(stop_callback, device); | 656 new content::MediaStreamVideoCapturerSource(stop_callback, device); |
648 return ret; | 657 return ret; |
649 } | 658 } |
650 | 659 |
651 void UserMediaClientImpl::CreateVideoTracks( | 660 void UserMediaClientImpl::CreateVideoTracks( |
652 const StreamDeviceInfoArray& devices, | 661 const StreamDeviceInfoArray& devices, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 } | 704 } |
696 } | 705 } |
697 | 706 |
698 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { | 707 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { |
699 blink::WebMediaStreamSource webkit_source; | 708 blink::WebMediaStreamSource webkit_source; |
700 InitializeSourceObject(overridden_audio_array[i], | 709 InitializeSourceObject(overridden_audio_array[i], |
701 blink::WebMediaStreamSource::TypeAudio, | 710 blink::WebMediaStreamSource::TypeAudio, |
702 constraints, | 711 constraints, |
703 &webkit_source); | 712 &webkit_source); |
704 (*webkit_tracks)[i].initialize(webkit_source); | 713 (*webkit_tracks)[i].initialize(webkit_source); |
705 request->StartAudioTrack((*webkit_tracks)[i], constraints); | 714 request->StartAudioTrack((*webkit_tracks)[i]); |
706 } | 715 } |
707 } | 716 } |
708 | 717 |
709 void UserMediaClientImpl::OnCreateNativeTracksCompleted( | 718 void UserMediaClientImpl::OnCreateNativeTracksCompleted( |
710 UserMediaRequestInfo* request, | 719 UserMediaRequestInfo* request, |
711 MediaStreamRequestResult result, | 720 MediaStreamRequestResult result, |
712 const blink::WebString& result_name) { | 721 const blink::WebString& result_name) { |
713 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" | 722 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" |
714 << "{request_id = " << request->request_id << "} " | 723 << "{request_id = " << request->request_id << "} " |
715 << "{result = " << result << "})"; | 724 << "{result = " << result << "})"; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 request(request), | 1085 request(request), |
1077 request_result_(MEDIA_DEVICE_OK), | 1086 request_result_(MEDIA_DEVICE_OK), |
1078 request_result_name_("") { | 1087 request_result_name_("") { |
1079 } | 1088 } |
1080 | 1089 |
1081 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { | 1090 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { |
1082 DVLOG(1) << "~UserMediaRequestInfo"; | 1091 DVLOG(1) << "~UserMediaRequestInfo"; |
1083 } | 1092 } |
1084 | 1093 |
1085 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( | 1094 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( |
1086 const blink::WebMediaStreamTrack& track, | 1095 const blink::WebMediaStreamTrack& track) { |
1087 const blink::WebMediaConstraints& constraints) { | |
1088 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio); | 1096 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio); |
1089 MediaStreamAudioSource* native_source = | 1097 MediaStreamAudioSource* native_source = |
1090 MediaStreamAudioSource::From(track.source()); | 1098 MediaStreamAudioSource::From(track.source()); |
1091 DCHECK(native_source); | 1099 DCHECK(native_source); |
1092 | 1100 |
1093 sources_.push_back(track.source()); | 1101 sources_.push_back(track.source()); |
1094 sources_waiting_for_callback_.push_back(native_source); | 1102 sources_waiting_for_callback_.push_back(native_source); |
1095 native_source->AddTrack( | 1103 if (native_source->ConnectToTrack(track)) |
1096 track, constraints, base::Bind( | 1104 OnTrackStarted(native_source, MEDIA_DEVICE_OK, ""); |
1097 &UserMediaClientImpl::UserMediaRequestInfo::OnTrackStarted, | 1105 else |
1098 AsWeakPtr())); | 1106 OnTrackStarted(native_source, MEDIA_DEVICE_TRACK_START_FAILURE, ""); |
1099 } | 1107 } |
1100 | 1108 |
1101 blink::WebMediaStreamTrack | 1109 blink::WebMediaStreamTrack |
1102 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( | 1110 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( |
1103 const blink::WebMediaStreamSource& source, | 1111 const blink::WebMediaStreamSource& source, |
1104 const blink::WebMediaConstraints& constraints) { | 1112 const blink::WebMediaConstraints& constraints) { |
1105 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); | 1113 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); |
1106 MediaStreamVideoSource* native_source = | 1114 MediaStreamVideoSource* native_source = |
1107 MediaStreamVideoSource::GetVideoSource(source); | 1115 MediaStreamVideoSource::GetVideoSource(source); |
1108 DCHECK(native_source); | 1116 DCHECK(native_source); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 return; | 1178 return; |
1171 } | 1179 } |
1172 } | 1180 } |
1173 } | 1181 } |
1174 | 1182 |
1175 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { | 1183 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { |
1176 return !sources_waiting_for_callback_.empty(); | 1184 return !sources_waiting_for_callback_.empty(); |
1177 } | 1185 } |
1178 | 1186 |
1179 } // namespace content | 1187 } // namespace content |
OLD | NEW |