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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 << ", name = " << webkit_source->name().utf8(); | 607 << ", name = " << webkit_source->name().utf8(); |
609 | 608 |
610 if (type == blink::WebMediaStreamSource::TypeVideo) { | 609 if (type == blink::WebMediaStreamSource::TypeVideo) { |
611 webkit_source->setExtraData( | 610 webkit_source->setExtraData( |
612 CreateVideoSource( | 611 CreateVideoSource( |
613 device, | 612 device, |
614 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, | 613 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, |
615 weak_factory_.GetWeakPtr()))); | 614 weak_factory_.GetWeakPtr()))); |
616 } else { | 615 } else { |
617 DCHECK_EQ(blink::WebMediaStreamSource::TypeAudio, type); | 616 DCHECK_EQ(blink::WebMediaStreamSource::TypeAudio, type); |
618 MediaStreamAudioSource* audio_source( | 617 MediaStreamAudioSource* const audio_source = |
619 new MediaStreamAudioSource( | 618 CreateAudioSource(device, constraints); |
620 RenderFrameObserver::routing_id(), | 619 audio_source->SetStopCallback( |
621 device, | 620 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, |
622 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, | 621 weak_factory_.GetWeakPtr())); |
623 weak_factory_.GetWeakPtr()), | 622 webkit_source->setExtraData(audio_source); // Takes ownership. |
624 dependency_factory_)); | |
625 webkit_source->setExtraData(audio_source); | |
626 } | 623 } |
627 local_sources_.push_back(*webkit_source); | 624 local_sources_.push_back(*webkit_source); |
628 } | 625 } |
629 | 626 |
| 627 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( |
| 628 const StreamDeviceInfo& device, |
| 629 const blink::WebMediaConstraints& constraints) { |
| 630 // TODO(miu): In a soon-upcoming change, I'll be providing an alternative |
| 631 // MediaStreamAudioSource that bypasses audio processing for the non-WebRTC |
| 632 // use cases. http://crbug.com/577881 |
| 633 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( |
| 634 RenderFrameObserver::routing_id(), device, dependency_factory_); |
| 635 source->SetSourceConstraints(constraints); |
| 636 return source; |
| 637 } |
| 638 |
630 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( | 639 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( |
631 const StreamDeviceInfo& device, | 640 const StreamDeviceInfo& device, |
632 const MediaStreamSource::SourceStoppedCallback& stop_callback) { | 641 const MediaStreamSource::SourceStoppedCallback& stop_callback) { |
633 content::MediaStreamVideoCapturerSource* ret = | 642 content::MediaStreamVideoCapturerSource* ret = |
634 new content::MediaStreamVideoCapturerSource(stop_callback, device); | 643 new content::MediaStreamVideoCapturerSource(stop_callback, device); |
635 return ret; | 644 return ret; |
636 } | 645 } |
637 | 646 |
638 void UserMediaClientImpl::CreateVideoTracks( | 647 void UserMediaClientImpl::CreateVideoTracks( |
639 const StreamDeviceInfoArray& devices, | 648 const StreamDeviceInfoArray& devices, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 } | 691 } |
683 } | 692 } |
684 | 693 |
685 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { | 694 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { |
686 blink::WebMediaStreamSource webkit_source; | 695 blink::WebMediaStreamSource webkit_source; |
687 InitializeSourceObject(overridden_audio_array[i], | 696 InitializeSourceObject(overridden_audio_array[i], |
688 blink::WebMediaStreamSource::TypeAudio, | 697 blink::WebMediaStreamSource::TypeAudio, |
689 constraints, | 698 constraints, |
690 &webkit_source); | 699 &webkit_source); |
691 (*webkit_tracks)[i].initialize(webkit_source); | 700 (*webkit_tracks)[i].initialize(webkit_source); |
692 request->StartAudioTrack((*webkit_tracks)[i], constraints); | 701 request->StartAudioTrack((*webkit_tracks)[i]); |
693 } | 702 } |
694 } | 703 } |
695 | 704 |
696 void UserMediaClientImpl::OnCreateNativeTracksCompleted( | 705 void UserMediaClientImpl::OnCreateNativeTracksCompleted( |
697 UserMediaRequestInfo* request, | 706 UserMediaRequestInfo* request, |
698 MediaStreamRequestResult result, | 707 MediaStreamRequestResult result, |
699 const blink::WebString& result_name) { | 708 const blink::WebString& result_name) { |
700 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" | 709 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" |
701 << "{request_id = " << request->request_id << "} " | 710 << "{request_id = " << request->request_id << "} " |
702 << "{result = " << result << "})"; | 711 << "{result = " << result << "})"; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 request(request), | 1066 request(request), |
1058 request_result_(MEDIA_DEVICE_OK), | 1067 request_result_(MEDIA_DEVICE_OK), |
1059 request_result_name_("") { | 1068 request_result_name_("") { |
1060 } | 1069 } |
1061 | 1070 |
1062 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { | 1071 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { |
1063 DVLOG(1) << "~UserMediaRequestInfo"; | 1072 DVLOG(1) << "~UserMediaRequestInfo"; |
1064 } | 1073 } |
1065 | 1074 |
1066 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( | 1075 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( |
1067 const blink::WebMediaStreamTrack& track, | 1076 const blink::WebMediaStreamTrack& track) { |
1068 const blink::WebMediaConstraints& constraints) { | |
1069 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio); | 1077 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio); |
1070 MediaStreamAudioSource* native_source = | 1078 MediaStreamAudioSource* native_source = |
1071 MediaStreamAudioSource::From(track.source()); | 1079 MediaStreamAudioSource::From(track.source()); |
1072 DCHECK(native_source); | 1080 DCHECK(native_source); |
1073 | 1081 |
1074 sources_.push_back(track.source()); | 1082 sources_.push_back(track.source()); |
1075 sources_waiting_for_callback_.push_back(native_source); | 1083 sources_waiting_for_callback_.push_back(native_source); |
1076 native_source->AddTrack( | 1084 if (native_source->ConnectToTrack(track)) |
1077 track, constraints, base::Bind( | 1085 OnTrackStarted(native_source, MEDIA_DEVICE_OK, ""); |
1078 &UserMediaClientImpl::UserMediaRequestInfo::OnTrackStarted, | 1086 else |
1079 AsWeakPtr())); | 1087 OnTrackStarted(native_source, MEDIA_DEVICE_TRACK_START_FAILURE, ""); |
1080 } | 1088 } |
1081 | 1089 |
1082 blink::WebMediaStreamTrack | 1090 blink::WebMediaStreamTrack |
1083 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( | 1091 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( |
1084 const blink::WebMediaStreamSource& source, | 1092 const blink::WebMediaStreamSource& source, |
1085 const blink::WebMediaConstraints& constraints) { | 1093 const blink::WebMediaConstraints& constraints) { |
1086 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); | 1094 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); |
1087 MediaStreamVideoSource* native_source = | 1095 MediaStreamVideoSource* native_source = |
1088 MediaStreamVideoSource::GetVideoSource(source); | 1096 MediaStreamVideoSource::GetVideoSource(source); |
1089 DCHECK(native_source); | 1097 DCHECK(native_source); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 return; | 1159 return; |
1152 } | 1160 } |
1153 } | 1161 } |
1154 } | 1162 } |
1155 | 1163 |
1156 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { | 1164 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { |
1157 return !sources_waiting_for_callback_.empty(); | 1165 return !sources_waiting_for_callback_.empty(); |
1158 } | 1166 } |
1159 | 1167 |
1160 } // namespace content | 1168 } // namespace content |
OLD | NEW |