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

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

Issue 1977553002: RELAND: MediaStream audio: Refactor 3 separate "glue" impls into one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Alternative approach to PLAS::SetVolume() thread-safety. Created 4 years, 7 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/threading/thread_task_runner_handle.h" 20 #include "base/threading/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
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 render_frame()); 657 render_frame());
649 return ret; 658 return ret;
650 } 659 }
651 660
652 void UserMediaClientImpl::CreateVideoTracks( 661 void UserMediaClientImpl::CreateVideoTracks(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } 705 }
697 } 706 }
698 707
699 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { 708 for (size_t i = 0; i < overridden_audio_array.size(); ++i) {
700 blink::WebMediaStreamSource webkit_source; 709 blink::WebMediaStreamSource webkit_source;
701 InitializeSourceObject(overridden_audio_array[i], 710 InitializeSourceObject(overridden_audio_array[i],
702 blink::WebMediaStreamSource::TypeAudio, 711 blink::WebMediaStreamSource::TypeAudio,
703 constraints, 712 constraints,
704 &webkit_source); 713 &webkit_source);
705 (*webkit_tracks)[i].initialize(webkit_source); 714 (*webkit_tracks)[i].initialize(webkit_source);
706 request->StartAudioTrack((*webkit_tracks)[i], constraints); 715 request->StartAudioTrack((*webkit_tracks)[i]);
707 } 716 }
708 } 717 }
709 718
710 void UserMediaClientImpl::OnCreateNativeTracksCompleted( 719 void UserMediaClientImpl::OnCreateNativeTracksCompleted(
711 UserMediaRequestInfo* request, 720 UserMediaRequestInfo* request,
712 MediaStreamRequestResult result, 721 MediaStreamRequestResult result,
713 const blink::WebString& result_name) { 722 const blink::WebString& result_name) {
714 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" 723 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete("
715 << "{request_id = " << request->request_id << "} " 724 << "{request_id = " << request->request_id << "} "
716 << "{result = " << result << "})"; 725 << "{result = " << result << "})";
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 request(request), 1086 request(request),
1078 request_result_(MEDIA_DEVICE_OK), 1087 request_result_(MEDIA_DEVICE_OK),
1079 request_result_name_("") { 1088 request_result_name_("") {
1080 } 1089 }
1081 1090
1082 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { 1091 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() {
1083 DVLOG(1) << "~UserMediaRequestInfo"; 1092 DVLOG(1) << "~UserMediaRequestInfo";
1084 } 1093 }
1085 1094
1086 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( 1095 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack(
1087 const blink::WebMediaStreamTrack& track, 1096 const blink::WebMediaStreamTrack& track) {
1088 const blink::WebMediaConstraints& constraints) {
1089 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio); 1097 DCHECK(track.source().getType() == blink::WebMediaStreamSource::TypeAudio);
1090 MediaStreamAudioSource* native_source = 1098 MediaStreamAudioSource* native_source =
1091 MediaStreamAudioSource::From(track.source()); 1099 MediaStreamAudioSource::From(track.source());
1092 DCHECK(native_source); 1100 DCHECK(native_source);
1093 1101
1094 sources_.push_back(track.source()); 1102 sources_.push_back(track.source());
1095 sources_waiting_for_callback_.push_back(native_source); 1103 sources_waiting_for_callback_.push_back(native_source);
1096 native_source->AddTrack( 1104 if (native_source->ConnectToTrack(track))
1097 track, constraints, base::Bind( 1105 OnTrackStarted(native_source, MEDIA_DEVICE_OK, "");
1098 &UserMediaClientImpl::UserMediaRequestInfo::OnTrackStarted, 1106 else
1099 AsWeakPtr())); 1107 OnTrackStarted(native_source, MEDIA_DEVICE_TRACK_START_FAILURE, "");
1100 } 1108 }
1101 1109
1102 blink::WebMediaStreamTrack 1110 blink::WebMediaStreamTrack
1103 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( 1111 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack(
1104 const blink::WebMediaStreamSource& source, 1112 const blink::WebMediaStreamSource& source,
1105 const blink::WebMediaConstraints& constraints) { 1113 const blink::WebMediaConstraints& constraints) {
1106 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo); 1114 DCHECK(source.getType() == blink::WebMediaStreamSource::TypeVideo);
1107 MediaStreamVideoSource* native_source = 1115 MediaStreamVideoSource* native_source =
1108 MediaStreamVideoSource::GetVideoSource(source); 1116 MediaStreamVideoSource::GetVideoSource(source);
1109 DCHECK(native_source); 1117 DCHECK(native_source);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 return; 1179 return;
1172 } 1180 }
1173 } 1181 }
1174 } 1182 }
1175 1183
1176 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { 1184 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const {
1177 return !sources_waiting_for_callback_.empty(); 1185 return !sources_waiting_for_callback_.empty();
1178 } 1186 }
1179 1187
1180 } // namespace content 1188 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/user_media_client_impl.h ('k') | content/renderer/media/user_media_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698