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 { kMediaStreamAudioHotword, false }, | 69 // multi-microphone geometry. |
| 70 {MediaAudioConstraints::kGoogBeamforming, false}, |
| 71 {kMediaStreamAudioHotword, false}, |
70 }; | 72 }; |
71 | 73 |
72 // Used to log echo quality based on delay estimates. | 74 // Used to log echo quality based on delay estimates. |
73 enum DelayBasedEchoQuality { | 75 enum DelayBasedEchoQuality { |
74 DELAY_BASED_ECHO_QUALITY_GOOD = 0, | 76 DELAY_BASED_ECHO_QUALITY_GOOD = 0, |
75 DELAY_BASED_ECHO_QUALITY_SPURIOUS, | 77 DELAY_BASED_ECHO_QUALITY_SPURIOUS, |
76 DELAY_BASED_ECHO_QUALITY_BAD, | 78 DELAY_BASED_ECHO_QUALITY_BAD, |
77 DELAY_BASED_ECHO_QUALITY_INVALID, | 79 DELAY_BASED_ECHO_QUALITY_INVALID, |
78 DELAY_BASED_ECHO_QUALITY_MAX | 80 DELAY_BASED_ECHO_QUALITY_MAX |
79 }; | 81 }; |
(...skipping 12 matching lines...) Expand all Loading... |
92 if (delay_frequency < 0) | 94 if (delay_frequency < 0) |
93 return DELAY_BASED_ECHO_QUALITY_INVALID; | 95 return DELAY_BASED_ECHO_QUALITY_INVALID; |
94 else if (delay_frequency <= kEchoDelayFrequencyLowerLimit) | 96 else if (delay_frequency <= kEchoDelayFrequencyLowerLimit) |
95 return DELAY_BASED_ECHO_QUALITY_GOOD; | 97 return DELAY_BASED_ECHO_QUALITY_GOOD; |
96 else if (delay_frequency < kEchoDelayFrequencyUpperLimit) | 98 else if (delay_frequency < kEchoDelayFrequencyUpperLimit) |
97 return DELAY_BASED_ECHO_QUALITY_SPURIOUS; | 99 return DELAY_BASED_ECHO_QUALITY_SPURIOUS; |
98 else | 100 else |
99 return DELAY_BASED_ECHO_QUALITY_BAD; | 101 return DELAY_BASED_ECHO_QUALITY_BAD; |
100 } | 102 } |
101 | 103 |
| 104 webrtc::Point WebrtcPointFromMediaPoint(const media::Point& point) { |
| 105 return webrtc::Point(point.x(), point.y(), point.z()); |
| 106 } |
| 107 |
| 108 std::vector<webrtc::Point> WebrtcPointsFromMediaPoints( |
| 109 const std::vector<media::Point>& points) { |
| 110 std::vector<webrtc::Point> webrtc_points; |
| 111 webrtc_points.reserve(webrtc_points.size()); |
| 112 for (const auto& point : points) { |
| 113 webrtc_points.push_back(WebrtcPointFromMediaPoint(point)); |
| 114 } |
| 115 return webrtc_points; |
| 116 } |
| 117 |
102 } // namespace | 118 } // namespace |
103 | 119 |
104 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | 120 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
105 void MediaAudioConstraints::ApplyFixedAudioConstraints( | 121 void MediaAudioConstraints::ApplyFixedAudioConstraints( |
106 RTCMediaConstraints* constraints) { | 122 RTCMediaConstraints* constraints) { |
107 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { | 123 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { |
108 bool already_set_value; | 124 bool already_set_value; |
109 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, | 125 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, |
110 &already_set_value, NULL)) { | 126 &already_set_value, NULL)) { |
111 const std::string value = kDefaultAudioConstraints[i].value ? | 127 const std::string value = kDefaultAudioConstraints[i].value ? |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 386 |
371 int median = 0, std = 0; | 387 int median = 0, std = 0; |
372 float dummy = 0; | 388 float dummy = 0; |
373 if (echo_cancellation->GetDelayMetrics(&median, &std, &dummy) == | 389 if (echo_cancellation->GetDelayMetrics(&median, &std, &dummy) == |
374 webrtc::AudioProcessing::kNoError) { | 390 webrtc::AudioProcessing::kNoError) { |
375 stats->echo_delay_median_ms = median; | 391 stats->echo_delay_median_ms = median; |
376 stats->echo_delay_std_ms = std; | 392 stats->echo_delay_std_ms = std; |
377 } | 393 } |
378 } | 394 } |
379 | 395 |
380 CONTENT_EXPORT std::vector<webrtc::Point> ParseArrayGeometry( | 396 std::vector<webrtc::Point> GetArrayGeometryPreferringConstraints( |
381 const std::string& geometry_string) { | 397 const MediaAudioConstraints& audio_constraints, |
382 const auto& tokens = | 398 const MediaStreamDevice::AudioDeviceParameters& input_params) { |
383 base::SplitString(geometry_string, base::kWhitespaceASCII, | 399 const std::string& constraints_geometry = |
384 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 400 audio_constraints.GetPropertyAsString( |
385 std::vector<webrtc::Point> geometry; | 401 MediaAudioConstraints::kGoogArrayGeometry); |
386 if (tokens.size() < 3 || tokens.size() % 3 != 0) { | |
387 LOG(ERROR) << "Malformed geometry string: " << geometry_string; | |
388 return geometry; | |
389 } | |
390 | 402 |
391 std::vector<float> float_tokens; | 403 // Give preference to the audio constraint over the device-supplied mic |
392 float_tokens.reserve(tokens.size()); | 404 // positions. This is mainly for testing purposes. |
393 for (const auto& token : tokens) { | 405 return WebrtcPointsFromMediaPoints( |
394 double float_token; | 406 constraints_geometry.empty() |
395 if (!base::StringToDouble(token, &float_token)) { | 407 ? input_params.mic_positions |
396 LOG(ERROR) << "Unable to convert token=" << token | 408 : media::ParsePointsFromString(constraints_geometry)); |
397 << " to double from geometry string: " << geometry_string; | |
398 return geometry; | |
399 } | |
400 float_tokens.push_back(float_token); | |
401 } | |
402 | |
403 geometry.reserve(float_tokens.size() / 3); | |
404 for (size_t i = 0; i < float_tokens.size(); i += 3) { | |
405 geometry.push_back(webrtc::Point(float_tokens[i + 0], float_tokens[i + 1], | |
406 float_tokens[i + 2])); | |
407 } | |
408 | |
409 return geometry; | |
410 } | 409 } |
411 | 410 |
412 } // namespace content | 411 } // namespace content |
OLD | NEW |