Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: content/renderer/media/user_media_client_impl.cc

Issue 1834323002: MediaStream audio: Refactor 3 separate "glue" implementations into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WebRtcLocalAudioTrackAdapter-->WebRtcAudioSink, MediaStreamAudioDeliverer; and PS3 comments address… Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 << ", name = " << webkit_source->name().utf8(); 600 << ", name = " << webkit_source->name().utf8();
602 601
603 if (type == blink::WebMediaStreamSource::TypeVideo) { 602 if (type == blink::WebMediaStreamSource::TypeVideo) {
604 webkit_source->setExtraData( 603 webkit_source->setExtraData(
605 CreateVideoSource( 604 CreateVideoSource(
606 device, 605 device,
607 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, 606 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped,
608 weak_factory_.GetWeakPtr()))); 607 weak_factory_.GetWeakPtr())));
609 } else { 608 } else {
610 DCHECK_EQ(blink::WebMediaStreamSource::TypeAudio, type); 609 DCHECK_EQ(blink::WebMediaStreamSource::TypeAudio, type);
611 MediaStreamAudioSource* audio_source( 610 MediaStreamAudioSource* const audio_source =
612 new MediaStreamAudioSource( 611 CreateAudioSource(device, constraints);
613 RenderFrameObserver::routing_id(), 612 audio_source->SetStopCallback(
614 device, 613 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped,
615 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, 614 weak_factory_.GetWeakPtr()));
616 weak_factory_.GetWeakPtr()), 615 webkit_source->setExtraData(audio_source); // Takes ownership.
617 dependency_factory_));
618 webkit_source->setExtraData(audio_source);
619 } 616 }
620 local_sources_.push_back(*webkit_source); 617 local_sources_.push_back(*webkit_source);
621 } 618 }
622 619
620 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource(
621 const StreamDeviceInfo& device,
622 const blink::WebMediaConstraints& constraints) {
623 // TODO(miu): In a soon-upcoming change, I'll be providing an alternative
624 // MediaStreamAudioSource that bypasses audio processing for the non-WebRTC
625 // use cases. http://crbug.com/577881
626 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource(
627 RenderFrameObserver::routing_id(), device, dependency_factory_);
628 source->SetSourceConstraints(constraints);
629 return source;
630 }
631
623 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( 632 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource(
624 const StreamDeviceInfo& device, 633 const StreamDeviceInfo& device,
625 const MediaStreamSource::SourceStoppedCallback& stop_callback) { 634 const MediaStreamSource::SourceStoppedCallback& stop_callback) {
626 content::MediaStreamVideoCapturerSource* ret = 635 content::MediaStreamVideoCapturerSource* ret =
627 new content::MediaStreamVideoCapturerSource(stop_callback, device); 636 new content::MediaStreamVideoCapturerSource(stop_callback, device);
628 return ret; 637 return ret;
629 } 638 }
630 639
631 void UserMediaClientImpl::CreateVideoTracks( 640 void UserMediaClientImpl::CreateVideoTracks(
632 const StreamDeviceInfoArray& devices, 641 const StreamDeviceInfoArray& devices,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 684 }
676 } 685 }
677 686
678 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { 687 for (size_t i = 0; i < overridden_audio_array.size(); ++i) {
679 blink::WebMediaStreamSource webkit_source; 688 blink::WebMediaStreamSource webkit_source;
680 InitializeSourceObject(overridden_audio_array[i], 689 InitializeSourceObject(overridden_audio_array[i],
681 blink::WebMediaStreamSource::TypeAudio, 690 blink::WebMediaStreamSource::TypeAudio,
682 constraints, 691 constraints,
683 &webkit_source); 692 &webkit_source);
684 (*webkit_tracks)[i].initialize(webkit_source); 693 (*webkit_tracks)[i].initialize(webkit_source);
685 request->StartAudioTrack((*webkit_tracks)[i], constraints); 694 request->StartAudioTrack((*webkit_tracks)[i]);
686 } 695 }
687 } 696 }
688 697
689 void UserMediaClientImpl::OnCreateNativeTracksCompleted( 698 void UserMediaClientImpl::OnCreateNativeTracksCompleted(
690 UserMediaRequestInfo* request, 699 UserMediaRequestInfo* request,
691 MediaStreamRequestResult result, 700 MediaStreamRequestResult result,
692 const blink::WebString& result_name) { 701 const blink::WebString& result_name) {
693 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" 702 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete("
694 << "{request_id = " << request->request_id << "} " 703 << "{request_id = " << request->request_id << "} "
695 << "{result = " << result << "})"; 704 << "{result = " << result << "})";
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 request(request), 1058 request(request),
1050 request_result_(MEDIA_DEVICE_OK), 1059 request_result_(MEDIA_DEVICE_OK),
1051 request_result_name_("") { 1060 request_result_name_("") {
1052 } 1061 }
1053 1062
1054 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { 1063 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() {
1055 DVLOG(1) << "~UserMediaRequestInfo"; 1064 DVLOG(1) << "~UserMediaRequestInfo";
1056 } 1065 }
1057 1066
1058 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( 1067 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack(
1059 const blink::WebMediaStreamTrack& track, 1068 const blink::WebMediaStreamTrack& track) {
1060 const blink::WebMediaConstraints& constraints) {
1061 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio); 1069 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio);
1062 MediaStreamAudioSource* native_source = 1070 MediaStreamAudioSource* native_source =
1063 MediaStreamAudioSource::From(track.source()); 1071 MediaStreamAudioSource::From(track.source());
1064 DCHECK(native_source); 1072 DCHECK(native_source);
1065 1073
1066 sources_.push_back(track.source()); 1074 sources_.push_back(track.source());
1067 sources_waiting_for_callback_.push_back(native_source); 1075 sources_waiting_for_callback_.push_back(native_source);
1068 native_source->AddTrack( 1076 if (native_source->ConnectToTrack(track))
1069 track, constraints, base::Bind( 1077 OnTrackStarted(native_source, MEDIA_DEVICE_OK, "");
1070 &UserMediaClientImpl::UserMediaRequestInfo::OnTrackStarted, 1078 else
1071 AsWeakPtr())); 1079 OnTrackStarted(native_source, MEDIA_DEVICE_TRACK_START_FAILURE, "");
1072 } 1080 }
1073 1081
1074 blink::WebMediaStreamTrack 1082 blink::WebMediaStreamTrack
1075 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( 1083 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack(
1076 const blink::WebMediaStreamSource& source, 1084 const blink::WebMediaStreamSource& source,
1077 const blink::WebMediaConstraints& constraints) { 1085 const blink::WebMediaConstraints& constraints) {
1078 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); 1086 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo);
1079 MediaStreamVideoSource* native_source = 1087 MediaStreamVideoSource* native_source =
1080 MediaStreamVideoSource::GetVideoSource(source); 1088 MediaStreamVideoSource::GetVideoSource(source);
1081 DCHECK(native_source); 1089 DCHECK(native_source);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 return; 1151 return;
1144 } 1152 }
1145 } 1153 }
1146 } 1154 }
1147 1155
1148 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { 1156 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const {
1149 return !sources_waiting_for_callback_.empty(); 1157 return !sources_waiting_for_callback_.empty();
1150 } 1158 }
1151 1159
1152 } // namespace content 1160 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698