OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/media_stream_audio_processor_options.h" | 5 #include "content/renderer/media/media_stream_audio_processor_options.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/string_number_conversions.h" | |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "content/common/media/media_stream_options.h" | 12 #include "content/common/media/media_stream_options.h" |
13 #include "content/renderer/media/media_stream_constraints_util.h" | |
12 #include "content/renderer/media/rtc_media_constraints.h" | 14 #include "content/renderer/media/rtc_media_constraints.h" |
13 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 16 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
15 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h" | |
16 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h " | 17 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h " |
17 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" | 18 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
22 const char kEchoCancellation[] = "echoCancellation"; | |
23 const char kGoogEchoCancellation[] = "googEchoCancellation"; | |
24 const char kGoogExperimentalEchoCancellation[] = "googEchoCancellation2"; | |
25 const char kGoogAutoGainControl[] = "googAutoGainControl"; | |
26 const char kGoogExperimentalAutoGainControl[] = "googAutoGainControl2"; | |
27 const char kGoogNoiseSuppression[] = "googNoiseSuppression"; | |
28 const char kGoogExperimentalNoiseSuppression[] = "googNoiseSuppression2"; | |
29 const char kGoogHighpassFilter[] = "googHighpassFilter"; | |
30 const char kGoogTypingNoiseDetection[] = "googTypingNoiseDetection"; | |
31 const char kGoogAudioMirroring[] = "googAudioMirroring"; | |
32 | |
21 namespace { | 33 namespace { |
22 | 34 |
23 // Constant constraint keys which enables default audio constraints on | 35 // Constant constraint keys which enables default audio constraints on |
24 // mediastreams with audio. | 36 // mediastreams with audio. |
25 struct { | 37 struct { |
26 const char* key; | 38 const char* key; |
27 const char* value; | 39 bool value; |
28 } const kDefaultAudioConstraints[] = { | 40 } const kDefaultAudioConstraints[] = { |
29 { webrtc::MediaConstraintsInterface::kEchoCancellation, | 41 { kEchoCancellation, true }, |
30 webrtc::MediaConstraintsInterface::kValueTrue }, | 42 { kGoogEchoCancellation, true }, |
31 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) | 43 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) |
32 // Enable the extended filter mode AEC on platforms with known echo issues. | 44 // Enable the extended filter mode AEC on platforms with known echo issues. |
33 { webrtc::MediaConstraintsInterface::kExperimentalEchoCancellation, | 45 { kGoogExperimentalEchoCancellation, true }, |
34 webrtc::MediaConstraintsInterface::kValueTrue }, | 46 #else |
47 { kGoogExperimentalEchoCancellation, false }, | |
35 #endif | 48 #endif |
36 { webrtc::MediaConstraintsInterface::kAutoGainControl, | 49 { kGoogAutoGainControl, true }, |
37 webrtc::MediaConstraintsInterface::kValueTrue }, | 50 { kGoogExperimentalAutoGainControl, true }, |
38 { webrtc::MediaConstraintsInterface::kExperimentalAutoGainControl, | 51 { kGoogNoiseSuppression, true }, |
39 webrtc::MediaConstraintsInterface::kValueTrue }, | 52 { kGoogHighpassFilter, true }, |
40 { webrtc::MediaConstraintsInterface::kNoiseSuppression, | 53 { kGoogTypingNoiseDetection, true }, |
41 webrtc::MediaConstraintsInterface::kValueTrue }, | |
42 { webrtc::MediaConstraintsInterface::kHighpassFilter, | |
43 webrtc::MediaConstraintsInterface::kValueTrue }, | |
44 { webrtc::MediaConstraintsInterface::kTypingNoiseDetection, | |
45 webrtc::MediaConstraintsInterface::kValueTrue }, | |
46 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
47 { content::kMediaStreamAudioDucking, | 55 { content::kMediaStreamAudioDucking, true }, |
tommi (sloooow) - chröme
2014/04/08 10:49:30
remove content:: prefix here and in the line below
no longer working on chromium
2014/04/11 08:56:30
Done.
| |
48 webrtc::MediaConstraintsInterface::kValueTrue }, | 56 #else |
57 { content::kMediaStreamAudioDucking, false }, | |
tommi (sloooow) - chröme
2014/04/08 10:49:30
why adding this?
no longer working on chromium
2014/04/11 08:56:30
I think it is good to explicitly define the defaul
| |
49 #endif | 58 #endif |
50 }; | 59 }; |
51 | 60 |
61 bool GetDefaultValueForConstraint(const std::string& key, | |
62 MediaStreamType type) { | |
perkj_chrome
2014/04/08 10:28:12
You can read the type from the original constrains
no longer working on chromium
2014/04/11 08:56:30
Done.
| |
63 // Audio processing is false for gUM of non-MEDIA_DEVICE_AUDIO_CAPTURE. | |
64 if (type != MEDIA_DEVICE_AUDIO_CAPTURE) | |
tommi (sloooow) - chröme
2014/04/08 10:49:30
the name of the function is GetDefaultValueForCons
no longer working on chromium
2014/04/11 08:56:30
Per pointed out that we should be able to get the
| |
65 return false; | |
66 | |
67 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | |
68 if (kDefaultAudioConstraints[i].key == key) | |
69 return kDefaultAudioConstraints[i].value; | |
70 } | |
71 | |
72 return false; | |
tommi (sloooow) - chröme
2014/04/08 10:49:30
I'm a bit wary of this sort of implementation. I'
no longer working on chromium
2014/04/11 08:56:30
Done.
| |
73 } | |
74 | |
52 } // namespace | 75 } // namespace |
53 | 76 |
77 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | |
54 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { | 78 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
no longer working on chromium
2014/04/08 10:02:53
These two methods are still used in WebRtcAudioCap
| |
55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 79 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
56 bool already_set_value; | 80 bool already_set_value; |
57 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, | 81 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, |
58 &already_set_value, NULL)) { | 82 &already_set_value, NULL)) { |
59 constraints->AddOptional(kDefaultAudioConstraints[i].key, | 83 constraints->AddOptional(kDefaultAudioConstraints[i].key, |
60 kDefaultAudioConstraints[i].value, false); | 84 base::IntToString(kDefaultAudioConstraints[i].value), false); |
tommi (sloooow) - chröme
2014/04/08 10:49:30
ugh, isn't this is a big change in functionality?
no longer working on chromium
2014/04/11 08:56:30
Right, we have to keep using the webrtc::MediaCons
tommi (sloooow) - chröme
2014/04/11 12:51:16
I don't think you understand my comments. You're
| |
61 } else { | 85 } else { |
62 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key | 86 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key |
63 << " already set to " << already_set_value; | 87 << " already set to " << already_set_value; |
64 } | 88 } |
65 } | 89 } |
66 } | 90 } |
67 | 91 |
92 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | |
68 bool NeedsAudioProcessing(const blink::WebMediaConstraints& constraints, | 93 bool NeedsAudioProcessing(const blink::WebMediaConstraints& constraints, |
69 int effects) { | 94 int effects, MediaStreamType type) { |
70 RTCMediaConstraints native_constraints(constraints); | |
71 ApplyFixedAudioConstraints(&native_constraints); | |
72 if (effects & media::AudioParameters::ECHO_CANCELLER) { | |
73 // If platform echo canceller is enabled, disable the software AEC. | |
74 native_constraints.AddOptional( | |
75 MediaConstraintsInterface::kEchoCancellation, | |
76 MediaConstraintsInterface::kValueFalse, true); | |
77 } | |
78 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 95 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
79 bool value = false; | 96 if (GetPropertyFromConstraints(constraints, |
80 if (webrtc::FindConstraint(&native_constraints, | 97 kDefaultAudioConstraints[i].key, |
81 kDefaultAudioConstraints[i].key, &value, NULL) && | 98 effects, type)) { |
82 value) { | |
83 return true; | 99 return true; |
84 } | 100 } |
85 } | 101 } |
86 | 102 |
87 return false; | 103 return false; |
88 } | 104 } |
89 | 105 |
90 bool GetPropertyFromConstraints(const MediaConstraintsInterface* constraints, | 106 bool GetPropertyFromConstraints(const blink::WebMediaConstraints& constraints, |
91 const std::string& key) { | 107 const std::string& key, |
92 bool value = false; | 108 int effects, |
93 return webrtc::FindConstraint(constraints, key, &value, NULL) && value; | 109 MediaStreamType type) { |
110 if (effects & media::AudioParameters::ECHO_CANCELLER && | |
tommi (sloooow) - chröme
2014/04/08 10:49:30
Please get Andrew to review this.
The name of thi
no longer working on chromium
2014/04/11 08:56:30
Will do.
| |
111 key == kGoogEchoCancellation) { | |
112 // If platform echo canceller is enabled, disable the software AEC. | |
113 return false; | |
perkj_chrome
2014/04/08 10:28:12
What does this mean? Can echo cancellation on/off
no longer working on chromium
2014/04/11 08:56:30
Yes, when the effect is on, we need to disable the
| |
114 } | |
115 | |
116 // Return the value if the constraint is specified in |constraints|, | |
117 // otherwise return the default value. | |
118 bool value = GetDefaultValueForConstraint(key, type); | |
tommi (sloooow) - chröme
2014/04/08 10:49:30
better to do:
if (!GetConstraintValue(constraints
no longer working on chromium
2014/04/11 08:56:30
Done.
| |
119 GetConstraintValue(constraints, key, &value); | |
120 return value; | |
94 } | 121 } |
95 | 122 |
96 void EnableEchoCancellation(AudioProcessing* audio_processing) { | 123 void EnableEchoCancellation(AudioProcessing* audio_processing) { |
97 #if defined(OS_ANDROID) | 124 #if defined(OS_ANDROID) |
98 // Mobile devices are using AECM. | 125 // Mobile devices are using AECM. |
99 int err = audio_processing->echo_control_mobile()->set_routing_mode( | 126 int err = audio_processing->echo_control_mobile()->set_routing_mode( |
100 webrtc::EchoControlMobile::kSpeakerphone); | 127 webrtc::EchoControlMobile::kSpeakerphone); |
101 err |= audio_processing->echo_control_mobile()->Enable(true); | 128 err |= audio_processing->echo_control_mobile()->Enable(true); |
102 CHECK_EQ(err, 0); | 129 CHECK_EQ(err, 0); |
103 #else | 130 #else |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 } | 234 } |
208 | 235 |
209 int median = 0, std = 0; | 236 int median = 0, std = 0; |
210 if (!audio_processing->echo_cancellation()->GetDelayMetrics(&median, &std)) { | 237 if (!audio_processing->echo_cancellation()->GetDelayMetrics(&median, &std)) { |
211 stats->echo_delay_median_ms = median; | 238 stats->echo_delay_median_ms = median; |
212 stats->echo_delay_std_ms = std; | 239 stats->echo_delay_std_ms = std; |
213 } | 240 } |
214 } | 241 } |
215 | 242 |
216 } // namespace content | 243 } // namespace content |
OLD | NEW |