Chromium Code Reviews| 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 SetHardwareEchoCancellationSetting(blink::WebMediaStreamSource* source) { | |
|
hbos_chromium
2017/07/04 15:26:49
Should this be generalized and/or renamed, e.g. Su
Guido Urdaneta
2017/07/05 09:23:36
This would probably be the place for future settin
| |
| 236 MediaStreamAudioSource* source_impl = | |
| 237 static_cast<MediaStreamAudioSource*>(source->GetExtraData()); | |
| 238 media::AudioParameters params = source_impl->GetAudioParameters(); | |
| 239 if (params.IsValid() && | |
| 240 (params.effects() & media::AudioParameters::ECHO_CANCELLER)) | |
| 241 source->SetEchoCancellation(true); | |
| 242 } | |
| 243 | |
| 235 static int g_next_request_id = 0; | 244 static int g_next_request_id = 0; |
| 236 | 245 |
| 237 } // namespace | 246 } // namespace |
| 238 | 247 |
| 239 // Class for storing information about a Blink request to create a | 248 // Class for storing information about a Blink request to create a |
| 240 // MediaStream. | 249 // MediaStream. |
| 241 class UserMediaClientImpl::UserMediaRequestInfo | 250 class UserMediaClientImpl::UserMediaRequestInfo |
| 242 : public base::SupportsWeakPtr<UserMediaRequestInfo> { | 251 : public base::SupportsWeakPtr<UserMediaRequestInfo> { |
| 243 public: | 252 public: |
| 244 using ResourcesReady = | 253 using ResourcesReady = |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 | 970 |
| 962 // While sources are being initialized, keep them in a separate array. | 971 // 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_. | 972 // Once they've finished initialized, they'll be moved over to local_sources_. |
| 964 // See OnAudioSourceStarted for more details. | 973 // See OnAudioSourceStarted for more details. |
| 965 pending_local_sources_.push_back(source); | 974 pending_local_sources_.push_back(source); |
| 966 | 975 |
| 967 MediaStreamSource::ConstraintsCallback source_ready = base::Bind( | 976 MediaStreamSource::ConstraintsCallback source_ready = base::Bind( |
| 968 &UserMediaClientImpl::OnAudioSourceStartedOnAudioThread, | 977 &UserMediaClientImpl::OnAudioSourceStartedOnAudioThread, |
| 969 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); | 978 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); |
| 970 | 979 |
| 971 MediaStreamAudioSource* const audio_source = | 980 bool has_sw_echo_cancellation = false; |
| 972 CreateAudioSource(device, constraints, source_ready); | 981 MediaStreamAudioSource* const audio_source = CreateAudioSource( |
| 982 device, constraints, source_ready, &has_sw_echo_cancellation); | |
| 973 audio_source->SetStopCallback(base::Bind( | 983 audio_source->SetStopCallback(base::Bind( |
| 974 &UserMediaClientImpl::OnLocalSourceStopped, weak_factory_.GetWeakPtr())); | 984 &UserMediaClientImpl::OnLocalSourceStopped, weak_factory_.GetWeakPtr())); |
| 975 source.SetExtraData(audio_source); // Takes ownership. | 985 source.SetExtraData(audio_source); // Takes ownership. |
| 986 // If the hardware has echo cancellation, the value is updated in | |
| 987 // CreateAudioTracks(), after the track has started. | |
|
hbos_chromium
2017/07/04 15:26:48
Could you clarify that the reason we don't set it
Guido Urdaneta
2017/07/05 09:23:37
Done.
| |
| 988 source.SetEchoCancellation(has_sw_echo_cancellation); | |
| 976 return source; | 989 return source; |
| 977 } | 990 } |
| 978 | 991 |
| 979 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( | 992 MediaStreamAudioSource* UserMediaClientImpl::CreateAudioSource( |
| 980 const StreamDeviceInfo& device, | 993 const StreamDeviceInfo& device, |
| 981 const blink::WebMediaConstraints& constraints, | 994 const blink::WebMediaConstraints& constraints, |
| 982 const MediaStreamSource::ConstraintsCallback& source_ready) { | 995 const MediaStreamSource::ConstraintsCallback& source_ready, |
| 996 bool* has_sw_echo_cancellation) { | |
| 983 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 997 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 984 DCHECK(current_request_info_); | 998 DCHECK(current_request_info_); |
| 985 // If the audio device is a loopback device (for screen capture), or if the | 999 // If the audio device is a loopback device (for screen capture), or if the |
| 986 // constraints/effects parameters indicate no audio processing is needed, | 1000 // constraints/effects parameters indicate no audio processing is needed, |
| 987 // create an efficient, direct-path MediaStreamAudioSource instance. | 1001 // create an efficient, direct-path MediaStreamAudioSource instance. |
| 988 AudioProcessingProperties audio_processing_properties = | 1002 AudioProcessingProperties audio_processing_properties = |
| 989 IsOldAudioConstraints() ? AudioProcessingProperties::FromConstraints( | 1003 IsOldAudioConstraints() ? AudioProcessingProperties::FromConstraints( |
| 990 constraints, device.device.input) | 1004 constraints, device.device.input) |
| 991 : current_request_info_->audio_capture_settings() | 1005 : current_request_info_->audio_capture_settings() |
| 992 .audio_processing_properties(); | 1006 .audio_processing_properties(); |
| 993 if (IsScreenCaptureMediaType(device.device.type) || | 1007 if (IsScreenCaptureMediaType(device.device.type) || |
| 994 !MediaStreamAudioProcessor::WouldModifyAudio( | 1008 !MediaStreamAudioProcessor::WouldModifyAudio( |
| 995 audio_processing_properties)) { | 1009 audio_processing_properties)) { |
| 1010 *has_sw_echo_cancellation = false; | |
| 996 return new LocalMediaStreamAudioSource(RenderFrameObserver::routing_id(), | 1011 return new LocalMediaStreamAudioSource(RenderFrameObserver::routing_id(), |
| 997 device, source_ready); | 1012 device, source_ready); |
| 998 } | 1013 } |
| 999 | 1014 |
| 1000 // The audio device is not associated with screen capture and also requires | 1015 // The audio device is not associated with screen capture and also requires |
| 1001 // processing. | 1016 // processing. |
| 1002 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( | 1017 ProcessedLocalAudioSource* source = new ProcessedLocalAudioSource( |
| 1003 RenderFrameObserver::routing_id(), device, audio_processing_properties, | 1018 RenderFrameObserver::routing_id(), device, audio_processing_properties, |
| 1004 source_ready, dependency_factory_); | 1019 source_ready, dependency_factory_); |
| 1020 *has_sw_echo_cancellation = | |
| 1021 audio_processing_properties.enable_sw_echo_cancellation; | |
| 1005 return source; | 1022 return source; |
| 1006 } | 1023 } |
| 1007 | 1024 |
| 1008 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( | 1025 MediaStreamVideoSource* UserMediaClientImpl::CreateVideoSource( |
| 1009 const StreamDeviceInfo& device, | 1026 const StreamDeviceInfo& device, |
| 1010 const MediaStreamSource::SourceStoppedCallback& stop_callback) { | 1027 const MediaStreamSource::SourceStoppedCallback& stop_callback) { |
| 1011 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 1028 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1012 DCHECK(current_request_info_); | 1029 DCHECK(current_request_info_); |
| 1013 if (IsOldVideoConstraints()) { | 1030 if (IsOldVideoConstraints()) { |
| 1014 return new MediaStreamVideoCapturerSource(stop_callback, device, | 1031 return new MediaStreamVideoCapturerSource(stop_callback, device, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 MediaStreamDevice::AudioDeviceParameters(); | 1080 MediaStreamDevice::AudioDeviceParameters(); |
| 1064 } | 1081 } |
| 1065 } | 1082 } |
| 1066 | 1083 |
| 1067 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { | 1084 for (size_t i = 0; i < overridden_audio_array.size(); ++i) { |
| 1068 bool is_pending = false; | 1085 bool is_pending = false; |
| 1069 blink::WebMediaStreamSource source = InitializeAudioSourceObject( | 1086 blink::WebMediaStreamSource source = InitializeAudioSourceObject( |
| 1070 overridden_audio_array[i], constraints, &is_pending); | 1087 overridden_audio_array[i], constraints, &is_pending); |
| 1071 (*webkit_tracks)[i].Initialize(source); | 1088 (*webkit_tracks)[i].Initialize(source); |
| 1072 current_request_info_->StartAudioTrack((*webkit_tracks)[i], is_pending); | 1089 current_request_info_->StartAudioTrack((*webkit_tracks)[i], is_pending); |
| 1090 SetHardwareEchoCancellationSetting(&source); | |
|
hbos_chromium
2017/07/04 15:26:48
Add a comment saying the source's current value re
Guido Urdaneta
2017/07/05 09:23:36
Done.
| |
| 1073 } | 1091 } |
| 1074 } | 1092 } |
| 1075 | 1093 |
| 1076 void UserMediaClientImpl::OnCreateNativeTracksCompleted( | 1094 void UserMediaClientImpl::OnCreateNativeTracksCompleted( |
| 1077 const std::string& label, | 1095 const std::string& label, |
| 1078 UserMediaRequestInfo* request_info, | 1096 UserMediaRequestInfo* request_info, |
| 1079 MediaStreamRequestResult result, | 1097 MediaStreamRequestResult result, |
| 1080 const blink::WebString& result_name) { | 1098 const blink::WebString& result_name) { |
| 1081 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 1099 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1082 if (result == content::MEDIA_DEVICE_OK) { | 1100 if (result == content::MEDIA_DEVICE_OK) { |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1545 const blink::WebString& result_name) { | 1563 const blink::WebString& result_name) { |
| 1546 // Check if we're waiting to be notified of this source. If not, then we'll | 1564 // Check if we're waiting to be notified of this source. If not, then we'll |
| 1547 // ignore the notification. | 1565 // ignore the notification. |
| 1548 auto found = std::find(sources_waiting_for_callback_.begin(), | 1566 auto found = std::find(sources_waiting_for_callback_.begin(), |
| 1549 sources_waiting_for_callback_.end(), source); | 1567 sources_waiting_for_callback_.end(), source); |
| 1550 if (found != sources_waiting_for_callback_.end()) | 1568 if (found != sources_waiting_for_callback_.end()) |
| 1551 OnTrackStarted(source, result, result_name); | 1569 OnTrackStarted(source, result, result_name); |
| 1552 } | 1570 } |
| 1553 | 1571 |
| 1554 } // namespace content | 1572 } // namespace content |
| OLD | NEW |