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/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const char MediaAudioConstraints::kGoogAudioMirroring[] = "googAudioMirroring"; | 44 const char MediaAudioConstraints::kGoogAudioMirroring[] = "googAudioMirroring"; |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 // Constant constraint keys which enables default audio constraints on | 48 // Constant constraint keys which enables default audio constraints on |
49 // mediastreams with audio. | 49 // mediastreams with audio. |
50 struct { | 50 struct { |
51 const char* key; | 51 const char* key; |
52 bool value; | 52 bool value; |
53 } const kDefaultAudioConstraints[] = { | 53 } const kDefaultAudioConstraints[] = { |
54 { MediaAudioConstraints::kEchoCancellation, true }, | 54 {MediaAudioConstraints::kEchoCancellation, true}, |
55 { MediaAudioConstraints::kGoogEchoCancellation, true }, | 55 {MediaAudioConstraints::kGoogEchoCancellation, true}, |
56 #if defined(OS_ANDROID) || defined(OS_IOS) | 56 #if defined(OS_ANDROID) || defined(OS_IOS) |
57 { MediaAudioConstraints::kGoogExperimentalEchoCancellation, false }, | 57 {MediaAudioConstraints::kGoogExperimentalEchoCancellation, false}, |
58 #else | 58 #else |
59 // Enable the extended filter mode AEC on all non-mobile platforms. | 59 // Enable the extended filter mode AEC on all non-mobile platforms. |
60 { MediaAudioConstraints::kGoogExperimentalEchoCancellation, true }, | 60 {MediaAudioConstraints::kGoogExperimentalEchoCancellation, true}, |
61 #endif | 61 #endif |
62 { MediaAudioConstraints::kGoogAutoGainControl, true }, | 62 {MediaAudioConstraints::kGoogAutoGainControl, true}, |
63 { MediaAudioConstraints::kGoogExperimentalAutoGainControl, true }, | 63 {MediaAudioConstraints::kGoogExperimentalAutoGainControl, true}, |
64 { MediaAudioConstraints::kGoogNoiseSuppression, true }, | 64 {MediaAudioConstraints::kGoogNoiseSuppression, true}, |
65 { MediaAudioConstraints::kGoogHighpassFilter, true }, | 65 {MediaAudioConstraints::kGoogHighpassFilter, true}, |
66 { MediaAudioConstraints::kGoogTypingNoiseDetection, true }, | 66 {MediaAudioConstraints::kGoogTypingNoiseDetection, true}, |
67 { MediaAudioConstraints::kGoogExperimentalNoiseSuppression, false }, | 67 {MediaAudioConstraints::kGoogExperimentalNoiseSuppression, false}, |
68 { MediaAudioConstraints::kGoogBeamforming, false }, | 68 // Beamforming will only be enabled if we are also provided with a |
| 69 // multi-microphone geometry. |
| 70 {MediaAudioConstraints::kGoogBeamforming, false}, |
69 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
70 { kMediaStreamAudioDucking, true }, | 72 {kMediaStreamAudioDucking, true}, |
71 #else | 73 #else |
72 { kMediaStreamAudioDucking, false }, | 74 {kMediaStreamAudioDucking, false}, |
73 #endif | 75 #endif |
74 { kMediaStreamAudioHotword, false }, | 76 {kMediaStreamAudioHotword, false}, |
75 }; | 77 }; |
76 | 78 |
77 bool IsAudioProcessingConstraint(const std::string& key) { | 79 bool IsAudioProcessingConstraint(const std::string& key) { |
78 // |kMediaStreamAudioDucking| does not require audio processing. | 80 // |kMediaStreamAudioDucking| does not require audio processing. |
79 return key != kMediaStreamAudioDucking; | 81 return key != kMediaStreamAudioDucking; |
80 } | 82 } |
81 | 83 |
82 // Used to log echo quality based on delay estimates. | 84 // Used to log echo quality based on delay estimates. |
83 enum DelayBasedEchoQuality { | 85 enum DelayBasedEchoQuality { |
84 DELAY_BASED_ECHO_QUALITY_GOOD = 0, | 86 DELAY_BASED_ECHO_QUALITY_GOOD = 0, |
(...skipping 17 matching lines...) Expand all Loading... |
102 if (delay_frequency < 0) | 104 if (delay_frequency < 0) |
103 return DELAY_BASED_ECHO_QUALITY_INVALID; | 105 return DELAY_BASED_ECHO_QUALITY_INVALID; |
104 else if (delay_frequency <= kEchoDelayFrequencyLowerLimit) | 106 else if (delay_frequency <= kEchoDelayFrequencyLowerLimit) |
105 return DELAY_BASED_ECHO_QUALITY_GOOD; | 107 return DELAY_BASED_ECHO_QUALITY_GOOD; |
106 else if (delay_frequency < kEchoDelayFrequencyUpperLimit) | 108 else if (delay_frequency < kEchoDelayFrequencyUpperLimit) |
107 return DELAY_BASED_ECHO_QUALITY_SPURIOUS; | 109 return DELAY_BASED_ECHO_QUALITY_SPURIOUS; |
108 else | 110 else |
109 return DELAY_BASED_ECHO_QUALITY_BAD; | 111 return DELAY_BASED_ECHO_QUALITY_BAD; |
110 } | 112 } |
111 | 113 |
| 114 webrtc::Point WebrtcPointFromMediaPoint(const media::Point& point) { |
| 115 return webrtc::Point(point.x(), point.y(), point.z()); |
| 116 } |
| 117 |
| 118 std::vector<webrtc::Point> WebrtcPointsFromMediaPoints( |
| 119 const std::vector<media::Point>& points) { |
| 120 std::vector<webrtc::Point> webrtc_points; |
| 121 webrtc_points.reserve(webrtc_points.size()); |
| 122 for (const auto& point : points) { |
| 123 webrtc_points.push_back(WebrtcPointFromMediaPoint(point)); |
| 124 } |
| 125 return webrtc_points; |
| 126 } |
| 127 |
112 } // namespace | 128 } // namespace |
113 | 129 |
114 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | 130 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
115 void MediaAudioConstraints::ApplyFixedAudioConstraints( | 131 void MediaAudioConstraints::ApplyFixedAudioConstraints( |
116 RTCMediaConstraints* constraints) { | 132 RTCMediaConstraints* constraints) { |
117 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { | 133 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { |
118 bool already_set_value; | 134 bool already_set_value; |
119 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, | 135 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, |
120 &already_set_value, NULL)) { | 136 &already_set_value, NULL)) { |
121 const std::string value = kDefaultAudioConstraints[i].value ? | 137 const std::string value = kDefaultAudioConstraints[i].value ? |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 400 |
385 int median = 0, std = 0; | 401 int median = 0, std = 0; |
386 float dummy = 0; | 402 float dummy = 0; |
387 if (echo_cancellation->GetDelayMetrics(&median, &std, &dummy) == | 403 if (echo_cancellation->GetDelayMetrics(&median, &std, &dummy) == |
388 webrtc::AudioProcessing::kNoError) { | 404 webrtc::AudioProcessing::kNoError) { |
389 stats->echo_delay_median_ms = median; | 405 stats->echo_delay_median_ms = median; |
390 stats->echo_delay_std_ms = std; | 406 stats->echo_delay_std_ms = std; |
391 } | 407 } |
392 } | 408 } |
393 | 409 |
394 CONTENT_EXPORT std::vector<webrtc::Point> ParseArrayGeometry( | 410 std::vector<webrtc::Point> GetArrayGeometryPreferringConstraints( |
395 const std::string& geometry_string) { | 411 const MediaAudioConstraints& audio_constraints, |
396 const auto& tokens = | 412 const MediaStreamDevice::AudioDeviceParameters& input_params) { |
397 base::SplitString(geometry_string, base::kWhitespaceASCII, | 413 const std::string& constraints_geometry = |
398 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 414 audio_constraints.GetPropertyAsString( |
399 std::vector<webrtc::Point> geometry; | 415 MediaAudioConstraints::kGoogArrayGeometry); |
400 if (tokens.size() < 3 || tokens.size() % 3 != 0) { | |
401 LOG(ERROR) << "Malformed geometry string: " << geometry_string; | |
402 return geometry; | |
403 } | |
404 | 416 |
405 std::vector<float> float_tokens; | 417 // Give preference to the audio constraint over the device-supplied mic |
406 float_tokens.reserve(tokens.size()); | 418 // positions. This is mainly for testing purposes. |
407 for (const auto& token : tokens) { | 419 return WebrtcPointsFromMediaPoints( |
408 double float_token; | 420 constraints_geometry.empty() |
409 if (!base::StringToDouble(token, &float_token)) { | 421 ? input_params.mic_positions |
410 LOG(ERROR) << "Unable to convert token=" << token | 422 : media::ParsePointsFromString(constraints_geometry)); |
411 << " to double from geometry string: " << geometry_string; | |
412 return geometry; | |
413 } | |
414 float_tokens.push_back(float_token); | |
415 } | |
416 | |
417 geometry.reserve(float_tokens.size() / 3); | |
418 for (size_t i = 0; i < float_tokens.size(); i += 3) { | |
419 geometry.push_back(webrtc::Point(float_tokens[i + 0], float_tokens[i + 1], | |
420 float_tokens[i + 2])); | |
421 } | |
422 | |
423 return geometry; | |
424 } | 423 } |
425 | 424 |
426 } // namespace content | 425 } // namespace content |
OLD | NEW |