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

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

Issue 1647773002: MediaStream audio sourcing: Bypass audio processing for non-WebRTC cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NOT FOR REVIEW -- This will be broken-up across multiple CLs. Created 4 years, 10 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/local_media_stream_audio_source.h"
22 #include "content/renderer/media/media_stream.h" 23 #include "content/renderer/media/media_stream.h"
23 #include "content/renderer/media/media_stream_audio_source.h" 24 #include "content/renderer/media/media_stream_audio_processor.h"
24 #include "content/renderer/media/media_stream_dispatcher.h" 25 #include "content/renderer/media/media_stream_dispatcher.h"
25 #include "content/renderer/media/media_stream_video_capturer_source.h" 26 #include "content/renderer/media/media_stream_video_capturer_source.h"
26 #include "content/renderer/media/media_stream_video_track.h" 27 #include "content/renderer/media/media_stream_video_track.h"
27 #include "content/renderer/media/peer_connection_tracker.h" 28 #include "content/renderer/media/peer_connection_tracker.h"
29 #include "content/renderer/media/webrtc/processed_local_audio_source.h"
28 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" 30 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
29 #include "content/renderer/media/webrtc_audio_capturer.h"
30 #include "content/renderer/media/webrtc_logging.h" 31 #include "content/renderer/media/webrtc_logging.h"
31 #include "content/renderer/media/webrtc_uma_histograms.h" 32 #include "content/renderer/media/webrtc_uma_histograms.h"
32 #include "content/renderer/render_thread_impl.h" 33 #include "content/renderer/render_thread_impl.h"
33 #include "third_party/WebKit/public/platform/URLConversion.h" 34 #include "third_party/WebKit/public/platform/URLConversion.h"
34 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 35 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
35 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" 36 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h"
36 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 37 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
37 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h " 38 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h "
38 #include "third_party/WebKit/public/web/WebDocument.h" 39 #include "third_party/WebKit/public/web/WebDocument.h"
39 #include "third_party/WebKit/public/web/WebLocalFrame.h" 40 #include "third_party/WebKit/public/web/WebLocalFrame.h"
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 << ", name = " << webkit_source->name().utf8(); 592 << ", name = " << webkit_source->name().utf8();
592 593
593 if (type == blink::WebMediaStreamSource::TypeVideo) { 594 if (type == blink::WebMediaStreamSource::TypeVideo) {
594 webkit_source->setExtraData( 595 webkit_source->setExtraData(
595 CreateVideoSource( 596 CreateVideoSource(
596 device, 597 device,
597 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, 598 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped,
598 weak_factory_.GetWeakPtr()))); 599 weak_factory_.GetWeakPtr())));
599 } else { 600 } else {
600 DCHECK_EQ(blink::WebMediaStreamSource::TypeAudio, type); 601 DCHECK_EQ(blink::WebMediaStreamSource::TypeAudio, type);
601 MediaStreamAudioSource* audio_source( 602 MediaStreamAudioSource* audio_source;
602 new MediaStreamAudioSource( 603 if (!RenderFrameObserver::render_frame()) {
603 RenderFrameObserver::routing_id(), 604 // Special handling note: When no RenderFrame was provided, assume
604 device, 605 // UserMediaClientImpl is running in non-browser unit tests (e.g.,
605 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped, 606 // user_media_client_impl_unittest.cc) with the WebRTC audio pipeline
606 weak_factory_.GetWeakPtr()), 607 // mocked out.
607 dependency_factory_)); 608 CHECK(!RenderThreadImpl::current());
608 webkit_source->setExtraData(audio_source); 609 ProcessedLocalAudioSource* source =
610 new ProcessedLocalAudioSource(-1, device, dependency_factory_);
611 source->SetAllowInvalidRenderFrameIdForTesting(true);
612 source->SetSourceConstraints(constraints);
613 audio_source = source;
614 } else if (IsContentCaptureMediaType(device.device.type) ||
615 !MediaStreamAudioProcessor::ShouldRouteAudioThroughProcessor(
616 constraints, device.device.input.effects)) {
617 audio_source = new LocalMediaStreamAudioSource(
618 RenderFrameObserver::routing_id(), device);
619 } else {
620 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource(
621 RenderFrameObserver::routing_id(), device, dependency_factory_);
622 source->SetSourceConstraints(constraints);
623 audio_source = source;
624 }
625 audio_source->SetStopCallback(
626 base::Bind(&UserMediaClientImpl::OnLocalSourceStopped,
627 weak_factory_.GetWeakPtr()));
628 webkit_source->setExtraData(audio_source); // Takes ownership.
609 } 629 }
610 local_sources_.push_back(*webkit_source); 630 local_sources_.push_back(*webkit_source);
611 } 631 }
612 632
613 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( 633 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource(
614 const StreamDeviceInfo& device, 634 const StreamDeviceInfo& device,
615 const MediaStreamSource::SourceStoppedCallback& stop_callback) { 635 const MediaStreamSource::SourceStoppedCallback& stop_callback) {
616 content::MediaStreamVideoCapturerSource* ret = 636 content::MediaStreamVideoCapturerSource* ret =
617 new content::MediaStreamVideoCapturerSource(stop_callback, device); 637 new content::MediaStreamVideoCapturerSource(stop_callback, device);
618 return ret; 638 return ret;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } 685 }
666 } 686 }
667 687
668 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { 688 for (size_t i = 0; i < overridden_audio_array.size(); ++i) {
669 blink::WebMediaStreamSource webkit_source; 689 blink::WebMediaStreamSource webkit_source;
670 InitializeSourceObject(overridden_audio_array[i], 690 InitializeSourceObject(overridden_audio_array[i],
671 blink::WebMediaStreamSource::TypeAudio, 691 blink::WebMediaStreamSource::TypeAudio,
672 constraints, 692 constraints,
673 &webkit_source); 693 &webkit_source);
674 (*webkit_tracks)[i].initialize(webkit_source); 694 (*webkit_tracks)[i].initialize(webkit_source);
675 request->StartAudioTrack((*webkit_tracks)[i], constraints); 695 request->StartAudioTrack((*webkit_tracks)[i]);
676 } 696 }
677 } 697 }
678 698
679 void UserMediaClientImpl::OnCreateNativeTracksCompleted( 699 void UserMediaClientImpl::OnCreateNativeTracksCompleted(
680 UserMediaRequestInfo* request, 700 UserMediaRequestInfo* request,
681 MediaStreamRequestResult result, 701 MediaStreamRequestResult result,
682 const blink::WebString& result_name) { 702 const blink::WebString& result_name) {
683 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" 703 DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete("
684 << "{request_id = " << request->request_id << "} " 704 << "{request_id = " << request->request_id << "} "
685 << "{result = " << result << "})"; 705 << "{result = " << result << "})";
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 request(request), 1059 request(request),
1040 request_result_(MEDIA_DEVICE_OK), 1060 request_result_(MEDIA_DEVICE_OK),
1041 request_result_name_("") { 1061 request_result_name_("") {
1042 } 1062 }
1043 1063
1044 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() { 1064 UserMediaClientImpl::UserMediaRequestInfo::~UserMediaRequestInfo() {
1045 DVLOG(1) << "~UserMediaRequestInfo"; 1065 DVLOG(1) << "~UserMediaRequestInfo";
1046 } 1066 }
1047 1067
1048 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack( 1068 void UserMediaClientImpl::UserMediaRequestInfo::StartAudioTrack(
1049 const blink::WebMediaStreamTrack& track, 1069 const blink::WebMediaStreamTrack& track) {
1050 const blink::WebMediaConstraints& constraints) {
1051 DCHECK(track.source().type() == blink::WebMediaStreamSource::TypeAudio); 1070 DCHECK(track.source().type() == blink::WebMediaStreamSource::TypeAudio);
1052 MediaStreamAudioSource* native_source = 1071 MediaStreamAudioSource* native_source =
1053 static_cast <MediaStreamAudioSource*>(track.source().extraData()); 1072 static_cast <MediaStreamAudioSource*>(track.source().extraData());
1054 DCHECK(native_source); 1073 DCHECK(native_source);
1055 1074
1056 sources_.push_back(track.source()); 1075 sources_.push_back(track.source());
1057 sources_waiting_for_callback_.push_back(native_source); 1076 sources_waiting_for_callback_.push_back(native_source);
1058 native_source->AddTrack( 1077 if (native_source->ConnectToTrack(track))
1059 track, constraints, base::Bind( 1078 OnTrackStarted(native_source, MEDIA_DEVICE_OK, "");
1060 &UserMediaClientImpl::UserMediaRequestInfo::OnTrackStarted, 1079 else
1061 AsWeakPtr())); 1080 OnTrackStarted(native_source, MEDIA_DEVICE_TRACK_START_FAILURE, "");
1062 } 1081 }
1063 1082
1064 blink::WebMediaStreamTrack 1083 blink::WebMediaStreamTrack
1065 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack( 1084 UserMediaClientImpl::UserMediaRequestInfo::CreateAndStartVideoTrack(
1066 const blink::WebMediaStreamSource& source, 1085 const blink::WebMediaStreamSource& source,
1067 const blink::WebMediaConstraints& constraints) { 1086 const blink::WebMediaConstraints& constraints) {
1068 DCHECK(source.type() == blink::WebMediaStreamSource::TypeVideo); 1087 DCHECK(source.type() == blink::WebMediaStreamSource::TypeVideo);
1069 MediaStreamVideoSource* native_source = 1088 MediaStreamVideoSource* native_source =
1070 MediaStreamVideoSource::GetVideoSource(source); 1089 MediaStreamVideoSource::GetVideoSource(source);
1071 DCHECK(native_source); 1090 DCHECK(native_source);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 return; 1152 return;
1134 } 1153 }
1135 } 1154 }
1136 } 1155 }
1137 1156
1138 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { 1157 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const {
1139 return !sources_waiting_for_callback_.empty(); 1158 return !sources_waiting_for_callback_.empty();
1140 } 1159 }
1141 1160
1142 } // namespace content 1161 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/user_media_client_impl.h ('k') | content/renderer/media/webaudio_capturer_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698