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/webrtc/processed_local_audio_source.h" | 5 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
6 | 6 |
7 #include <algorithm> | |
8 #include <utility> | |
9 | |
7 #include "base/logging.h" | 10 #include "base/logging.h" |
8 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
10 #include "content/renderer/media/audio_device_factory.h" | 13 #include "content/renderer/media/audio_device_factory.h" |
11 #include "content/renderer/media/media_stream_audio_processor_options.h" | 14 #include "content/renderer/media/media_stream_audio_processor_options.h" |
12 #include "content/renderer/media/media_stream_constraints_util.h" | 15 #include "content/renderer/media/media_stream_constraints_util.h" |
13 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 16 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
14 #include "content/renderer/media/webrtc_audio_device_impl.h" | 17 #include "content/renderer/media/webrtc_audio_device_impl.h" |
15 #include "content/renderer/media/webrtc_logging.h" | 18 #include "content/renderer/media/webrtc_logging.h" |
16 #include "content/renderer/render_frame_impl.h" | 19 #include "content/renderer/render_frame_impl.h" |
17 #include "media/audio/sample_rates.h" | 20 #include "media/audio/sample_rates.h" |
18 #include "media/base/channel_layout.h" | 21 #include "media/base/channel_layout.h" |
19 #include "third_party/webrtc/api/mediaconstraintsinterface.h" | 22 #include "third_party/webrtc/api/mediaconstraintsinterface.h" |
20 #include "third_party/webrtc/media/base/mediachannel.h" | 23 #include "third_party/webrtc/media/base/mediachannel.h" |
21 | 24 |
22 namespace content { | 25 namespace content { |
23 | 26 |
24 namespace { | 27 namespace { |
25 // Used as an identifier for ProcessedLocalAudioSource::From(). | 28 // Used as an identifier for ProcessedLocalAudioSource::From(). |
26 void* const kClassIdentifier = const_cast<void**>(&kClassIdentifier); | 29 void* const kClassIdentifier = const_cast<void**>(&kClassIdentifier); |
27 } // namespace | 30 } // namespace |
28 | 31 |
29 ProcessedLocalAudioSource::ProcessedLocalAudioSource( | 32 ProcessedLocalAudioSource::ProcessedLocalAudioSource( |
30 int consumer_render_frame_id, | 33 int consumer_render_frame_id, |
31 const StreamDeviceInfo& device_info, | 34 const StreamDeviceInfo& device_info, |
32 const blink::WebMediaConstraints& constraints, | 35 const AudioProcessingProperties& audio_processing_properties, |
33 const ConstraintsCallback& started_callback, | 36 const ConstraintsCallback& started_callback, |
34 PeerConnectionDependencyFactory* factory) | 37 PeerConnectionDependencyFactory* factory) |
35 : MediaStreamAudioSource(true /* is_local_source */), | 38 : MediaStreamAudioSource(true /* is_local_source */), |
36 consumer_render_frame_id_(consumer_render_frame_id), | 39 consumer_render_frame_id_(consumer_render_frame_id), |
37 pc_factory_(factory), | 40 pc_factory_(factory), |
38 constraints_(constraints), | 41 audio_processing_properties_(audio_processing_properties), |
39 started_callback_(started_callback), | 42 started_callback_(started_callback), |
40 volume_(0), | 43 volume_(0), |
41 allow_invalid_render_frame_id_for_testing_(false) { | 44 allow_invalid_render_frame_id_for_testing_(false) { |
42 DCHECK(pc_factory_); | 45 DCHECK(pc_factory_); |
43 DVLOG(1) << "ProcessedLocalAudioSource::ProcessedLocalAudioSource()"; | 46 DVLOG(1) << "ProcessedLocalAudioSource::ProcessedLocalAudioSource()"; |
44 MediaStreamSource::SetDeviceInfo(device_info); | 47 MediaStreamSource::SetDeviceInfo(device_info); |
45 } | 48 } |
46 | 49 |
47 ProcessedLocalAudioSource::~ProcessedLocalAudioSource() { | 50 ProcessedLocalAudioSource::~ProcessedLocalAudioSource() { |
48 DVLOG(1) << "ProcessedLocalAudioSource::~ProcessedLocalAudioSource()"; | 51 DVLOG(1) << "ProcessedLocalAudioSource::~ProcessedLocalAudioSource()"; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 ", channel_layout=%d, sample_rate=%d, buffer_size=%d" | 87 ", channel_layout=%d, sample_rate=%d, buffer_size=%d" |
85 ", session_id=%d, paired_output_sample_rate=%d" | 88 ", session_id=%d, paired_output_sample_rate=%d" |
86 ", paired_output_frames_per_buffer=%d, effects=%d. ", | 89 ", paired_output_frames_per_buffer=%d, effects=%d. ", |
87 consumer_render_frame_id_, device_info().device.input.channel_layout, | 90 consumer_render_frame_id_, device_info().device.input.channel_layout, |
88 device_info().device.input.sample_rate, | 91 device_info().device.input.sample_rate, |
89 device_info().device.input.frames_per_buffer, device_info().session_id, | 92 device_info().device.input.frames_per_buffer, device_info().session_id, |
90 device_info().device.matched_output.sample_rate, | 93 device_info().device.matched_output.sample_rate, |
91 device_info().device.matched_output.frames_per_buffer, | 94 device_info().device.matched_output.frames_per_buffer, |
92 device_info().device.input.effects)); | 95 device_info().device.input.effects)); |
93 | 96 |
94 // Sanity-check that the constraints, plus the additional input effects are | 97 // Disable HW echo cancellation if constraints explicitly specified no |
95 // valid when combined. | 98 // echo cancellation. |
96 const MediaAudioConstraints audio_constraints( | 99 if (audio_processing_properties_.disable_hw_echo_cancellation && |
97 constraints_, device_info().device.input.effects); | 100 (device_info().device.input.effects & |
98 if (!audio_constraints.IsValid()) { | 101 media::AudioParameters::ECHO_CANCELLER)) { |
hbos_chromium
2017/06/16 17:27:14
Is the concept of "not valid" not applicable to pr
Guido Urdaneta
2017/06/19 11:56:49
No, it's not.
| |
99 WebRtcLogMessage("ProcessedLocalAudioSource::EnsureSourceIsStarted() fails " | 102 StreamDeviceInfo modified_device_info(device_info()); |
100 " because MediaAudioConstraints are not valid."); | 103 modified_device_info.device.input.effects &= |
101 return false; | 104 ~media::AudioParameters::ECHO_CANCELLER; |
102 } | 105 SetDeviceInfo(modified_device_info); |
103 | |
104 if (device_info().device.input.effects & | |
105 media::AudioParameters::ECHO_CANCELLER) { | |
106 // TODO(hta): Figure out if we should be looking at echoCancellation. | |
107 // Previous code had googEchoCancellation only. | |
108 const blink::BooleanConstraint& echoCancellation = | |
109 constraints_.Basic().goog_echo_cancellation; | |
110 if (echoCancellation.HasExact() && !echoCancellation.Exact()) { | |
111 StreamDeviceInfo modified_device_info(device_info()); | |
112 modified_device_info.device.input.effects &= | |
113 ~media::AudioParameters::ECHO_CANCELLER; | |
114 SetDeviceInfo(modified_device_info); | |
115 } | |
116 } | 106 } |
117 | 107 |
118 // Create the MediaStreamAudioProcessor, bound to the WebRTC audio device | 108 // Create the MediaStreamAudioProcessor, bound to the WebRTC audio device |
119 // module. | 109 // module. |
120 WebRtcAudioDeviceImpl* const rtc_audio_device = | 110 WebRtcAudioDeviceImpl* const rtc_audio_device = |
121 pc_factory_->GetWebRtcAudioDevice(); | 111 pc_factory_->GetWebRtcAudioDevice(); |
122 if (!rtc_audio_device) { | 112 if (!rtc_audio_device) { |
123 WebRtcLogMessage("ProcessedLocalAudioSource::EnsureSourceIsStarted() fails " | 113 WebRtcLogMessage("ProcessedLocalAudioSource::EnsureSourceIsStarted() fails " |
124 " because there is no WebRtcAudioDeviceImpl instance."); | 114 " because there is no WebRtcAudioDeviceImpl instance."); |
125 return false; | 115 return false; |
126 } | 116 } |
127 audio_processor_ = new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 117 audio_processor_ = new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
128 constraints_, device_info().device.input, rtc_audio_device); | 118 audio_processing_properties_, rtc_audio_device); |
129 | 119 |
130 // If KEYBOARD_MIC effect is set, change the layout to the corresponding | 120 // If KEYBOARD_MIC effect is set, change the layout to the corresponding |
131 // layout that includes the keyboard mic. | 121 // layout that includes the keyboard mic. |
132 media::ChannelLayout channel_layout = static_cast<media::ChannelLayout>( | 122 media::ChannelLayout channel_layout = static_cast<media::ChannelLayout>( |
133 device_info().device.input.channel_layout); | 123 device_info().device.input.channel_layout); |
134 if ((device_info().device.input.effects & | 124 if ((device_info().device.input.effects & |
135 media::AudioParameters::KEYBOARD_MIC) && | 125 media::AudioParameters::KEYBOARD_MIC) && |
136 audio_constraints.GetGoogExperimentalNoiseSuppression()) { | 126 audio_processing_properties_.goog_experimental_noise_suppression) { |
137 if (channel_layout == media::CHANNEL_LAYOUT_STEREO) { | 127 if (channel_layout == media::CHANNEL_LAYOUT_STEREO) { |
138 channel_layout = media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC; | 128 channel_layout = media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC; |
139 DVLOG(1) << "Changed stereo layout to stereo + keyboard mic layout due " | 129 DVLOG(1) << "Changed stereo layout to stereo + keyboard mic layout due " |
140 << "to KEYBOARD_MIC effect."; | 130 << "to KEYBOARD_MIC effect."; |
141 } else { | 131 } else { |
142 DVLOG(1) << "KEYBOARD_MIC effect ignored, not compatible with layout " | 132 DVLOG(1) << "KEYBOARD_MIC effect ignored, not compatible with layout " |
143 << channel_layout; | 133 << channel_layout; |
144 } | 134 } |
145 } | 135 } |
146 | 136 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 | 357 |
368 // If the buffer size is missing from the StreamDeviceInfo, provide 10ms as a | 358 // If the buffer size is missing from the StreamDeviceInfo, provide 10ms as a |
369 // fall-back. | 359 // fall-back. |
370 // | 360 // |
371 // TODO(miu): Identify where/why the buffer size might be missing, fix the | 361 // TODO(miu): Identify where/why the buffer size might be missing, fix the |
372 // code, and then require it here. http://crbug.com/638081 | 362 // code, and then require it here. http://crbug.com/638081 |
373 return (sample_rate / 100); | 363 return (sample_rate / 100); |
374 } | 364 } |
375 | 365 |
376 } // namespace content | 366 } // namespace content |
OLD | NEW |