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 <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 source == kMediaStreamSourceDesktop || | 225 source == kMediaStreamSourceDesktop || |
226 source == kMediaStreamSourceSystem; | 226 source == kMediaStreamSourceSystem; |
227 } | 227 } |
228 | 228 |
229 bool IsValidVideoContentSource(const std::string& source) { | 229 bool IsValidVideoContentSource(const std::string& source) { |
230 return source == kMediaStreamSourceTab || | 230 return source == kMediaStreamSourceTab || |
231 source == kMediaStreamSourceDesktop || | 231 source == kMediaStreamSourceDesktop || |
232 source == kMediaStreamSourceScreen; | 232 source == kMediaStreamSourceScreen; |
233 } | 233 } |
234 | 234 |
| 235 void SurfaceHardwareEchoCancellationSetting( |
| 236 blink::WebMediaStreamSource* source) { |
| 237 MediaStreamAudioSource* source_impl = |
| 238 static_cast<MediaStreamAudioSource*>(source->GetExtraData()); |
| 239 media::AudioParameters params = source_impl->GetAudioParameters(); |
| 240 if (params.IsValid() && |
| 241 (params.effects() & media::AudioParameters::ECHO_CANCELLER)) |
| 242 source->SetEchoCancellation(true); |
| 243 } |
| 244 |
235 static int g_next_request_id = 0; | 245 static int g_next_request_id = 0; |
236 | 246 |
237 } // namespace | 247 } // namespace |
238 | 248 |
239 // Class for storing information about a Blink request to create a | 249 // Class for storing information about a Blink request to create a |
240 // MediaStream. | 250 // MediaStream. |
241 class UserMediaClientImpl::UserMediaRequestInfo | 251 class UserMediaClientImpl::UserMediaRequestInfo |
242 : public base::SupportsWeakPtr<UserMediaRequestInfo> { | 252 : public base::SupportsWeakPtr<UserMediaRequestInfo> { |
243 public: | 253 public: |
244 using ResourcesReady = | 254 using ResourcesReady = |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 971 |
962 // While sources are being initialized, keep them in a separate array. | 972 // While sources are being initialized, keep them in a separate array. |
963 // Once they've finished initialized, they'll be moved over to local_sources_. | 973 // Once they've finished initialized, they'll be moved over to local_sources_. |
964 // See OnAudioSourceStarted for more details. | 974 // See OnAudioSourceStarted for more details. |
965 pending_local_sources_.push_back(source); | 975 pending_local_sources_.push_back(source); |
966 | 976 |
967 MediaStreamSource::ConstraintsCallback source_ready = base::Bind( | 977 MediaStreamSource::ConstraintsCallback source_ready = base::Bind( |
968 &UserMediaClientImpl::OnAudioSourceStartedOnAudioThread, | 978 &UserMediaClientImpl::OnAudioSourceStartedOnAudioThread, |
969 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); | 979 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); |
970 | 980 |
971 MediaStreamAudioSource* const audio_source = | 981 bool has_sw_echo_cancellation = false; |
972 CreateAudioSource(device, constraints, source_ready); | 982 MediaStreamAudioSource* const audio_source = CreateAudioSource( |
| 983 device, constraints, source_ready, &has_sw_echo_cancellation); |
973 audio_source->SetStopCallback(base::Bind( | 984 audio_source->SetStopCallback(base::Bind( |
974 &UserMediaClientImpl::OnLocalSourceStopped, weak_factory_.GetWeakPtr())); | 985 &UserMediaClientImpl::OnLocalSourceStopped, weak_factory_.GetWeakPtr())); |
975 source.SetExtraData(audio_source); // Takes ownership. | 986 source.SetExtraData(audio_source); // Takes ownership. |
| 987 // At this point it is known if software echo cancellation will be used, but |
| 988 // final audio parameters for the source are not set yet, so it is not yet |
| 989 // known if hardware echo cancellation will actually be used. That information |
| 990 // is known and surfaced in CreateAudioTracks(), after the track is connected |
| 991 // to the source. |
| 992 source.SetEchoCancellation(has_sw_echo_cancellation); |
976 return source; | 993 return source; |
977 } | 994 } |
978 | 995 |
979 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( | 996 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( |
980 const StreamDeviceInfo& device, | 997 const StreamDeviceInfo& device, |
981 const blink::WebMediaConstraints& constraints, | 998 const blink::WebMediaConstraints& constraints, |
982 const MediaStreamSource::ConstraintsCallback& source_ready) { | 999 const MediaStreamSource::ConstraintsCallback& source_ready, |
| 1000 bool* has_sw_echo_cancellation) { |
983 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 1001 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
984 DCHECK(current_request_info_); | 1002 DCHECK(current_request_info_); |
985 // If the audio device is a loopback device (for screen capture), or if the | 1003 // If the audio device is a loopback device (for screen capture), or if the |
986 // constraints/effects parameters indicate no audio processing is needed, | 1004 // constraints/effects parameters indicate no audio processing is needed, |
987 // create an efficient, direct-path MediaStreamAudioSource instance. | 1005 // create an efficient, direct-path MediaStreamAudioSource instance. |
988 AudioProcessingProperties audio_processing_properties = | 1006 AudioProcessingProperties audio_processing_properties = |
989 IsOldAudioConstraints() ? AudioProcessingProperties::FromConstraints( | 1007 IsOldAudioConstraints() ? AudioProcessingProperties::FromConstraints( |
990 constraints, device.device.input) | 1008 constraints, device.device.input) |
991 : current_request_info_->audio_capture_settings() | 1009 : current_request_info_->audio_capture_settings() |
992 .audio_processing_properties(); | 1010 .audio_processing_properties(); |
993 if (IsScreenCaptureMediaType(device.device.type) || | 1011 if (IsScreenCaptureMediaType(device.device.type) || |
994 !MediaStreamAudioProcessor::WouldModifyAudio( | 1012 !MediaStreamAudioProcessor::WouldModifyAudio( |
995 audio_processing_properties)) { | 1013 audio_processing_properties)) { |
| 1014 *has_sw_echo_cancellation = false; |
996 return new LocalMediaStreamAudioSource(RenderFrameObserver::routing_id(), | 1015 return new LocalMediaStreamAudioSource(RenderFrameObserver::routing_id(), |
997 device, source_ready); | 1016 device, source_ready); |
998 } | 1017 } |
999 | 1018 |
1000 // The audio device is not associated with screen capture and also requires | 1019 // The audio device is not associated with screen capture and also requires |
1001 // processing. | 1020 // processing. |
1002 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( | 1021 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( |
1003 RenderFrameObserver::routing_id(), device, audio_processing_properties, | 1022 RenderFrameObserver::routing_id(), device, audio_processing_properties, |
1004 source_ready, dependency_factory_); | 1023 source_ready, dependency_factory_); |
| 1024 *has_sw_echo_cancellation = |
| 1025 audio_processing_properties.enable_sw_echo_cancellation; |
1005 return source; | 1026 return source; |
1006 } | 1027 } |
1007 | 1028 |
1008 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( | 1029 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( |
1009 const StreamDeviceInfo& device, | 1030 const StreamDeviceInfo& device, |
1010 const MediaStreamSource::SourceStoppedCallback& stop_callback) { | 1031 const MediaStreamSource::SourceStoppedCallback& stop_callback) { |
1011 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 1032 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
1012 DCHECK(current_request_info_); | 1033 DCHECK(current_request_info_); |
1013 DCHECK(current_request_info_->video_capture_settings().HasValue()); | 1034 DCHECK(current_request_info_->video_capture_settings().HasValue()); |
1014 return new MediaStreamVideoCapturerSource( | 1035 return new MediaStreamVideoCapturerSource( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 MediaStreamDevice::AudioDeviceParameters(); | 1079 MediaStreamDevice::AudioDeviceParameters(); |
1059 } | 1080 } |
1060 } | 1081 } |
1061 | 1082 |
1062 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { | 1083 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { |
1063 bool is_pending = false; | 1084 bool is_pending = false; |
1064 blink::WebMediaStreamSource source = InitializeAudioSourceObject( | 1085 blink::WebMediaStreamSource source = InitializeAudioSourceObject( |
1065 overridden_audio_array[i], constraints, &is_pending); | 1086 overridden_audio_array[i], constraints, &is_pending); |
1066 (*webkit_tracks)[i].Initialize(source); | 1087 (*webkit_tracks)[i].Initialize(source); |
1067 current_request_info_->StartAudioTrack((*webkit_tracks)[i], is_pending); | 1088 current_request_info_->StartAudioTrack((*webkit_tracks)[i], is_pending); |
| 1089 // At this point the source has started, and its audio parameters have been |
| 1090 // set. From the parameters, it is known if hardware echo cancellation is |
| 1091 // being used. If this is the case, let |source| know. |
| 1092 SurfaceHardwareEchoCancellationSetting(&source); |
1068 } | 1093 } |
1069 } | 1094 } |
1070 | 1095 |
1071 void UserMediaClientImpl::OnCreateNativeTracksCompleted( | 1096 void UserMediaClientImpl::OnCreateNativeTracksCompleted( |
1072 const std::string& label, | 1097 const std::string& label, |
1073 UserMediaRequestInfo* request_info, | 1098 UserMediaRequestInfo* request_info, |
1074 MediaStreamRequestResult result, | 1099 MediaStreamRequestResult result, |
1075 const blink::WebString& result_name) { | 1100 const blink::WebString& result_name) { |
1076 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 1101 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
1077 if (result == content::MEDIA_DEVICE_OK) { | 1102 if (result == content::MEDIA_DEVICE_OK) { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 const blink::WebString& result_name) { | 1558 const blink::WebString& result_name) { |
1534 // Check if we're waiting to be notified of this source. If not, then we'll | 1559 // Check if we're waiting to be notified of this source. If not, then we'll |
1535 // ignore the notification. | 1560 // ignore the notification. |
1536 auto found = std::find(sources_waiting_for_callback_.begin(), | 1561 auto found = std::find(sources_waiting_for_callback_.begin(), |
1537 sources_waiting_for_callback_.end(), source); | 1562 sources_waiting_for_callback_.end(), source); |
1538 if (found != sources_waiting_for_callback_.end()) | 1563 if (found != sources_waiting_for_callback_.end()) |
1539 OnTrackStarted(source, result, result_name); | 1564 OnTrackStarted(source, result, result_name); |
1540 } | 1565 } |
1541 | 1566 |
1542 } // namespace content | 1567 } // namespace content |
OLD | NEW |