Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: content/renderer/media/media_stream_audio_processor_options.cc

Issue 1275783003: Add a virtual beamforming audio device on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove audio_manager_openbsd. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Beamforming will only be enabled if we are also provided with a
69 // multi-microphone geometry.
68 { MediaAudioConstraints::kGoogBeamforming, false }, 70 { MediaAudioConstraints::kGoogBeamforming, false },
69 { kMediaStreamAudioHotword, 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,
(...skipping 14 matching lines...) Expand all
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 return webrtc_points;
115 }
116
102 } // namespace 117 } // namespace
103 118
104 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. 119 // TODO(xians): Remove this method after the APM in WebRtc is deprecated.
105 void MediaAudioConstraints::ApplyFixedAudioConstraints( 120 void MediaAudioConstraints::ApplyFixedAudioConstraints(
106 RTCMediaConstraints* constraints) { 121 RTCMediaConstraints* constraints) {
107 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { 122 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
108 bool already_set_value; 123 bool already_set_value;
109 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, 124 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key,
110 &already_set_value, NULL)) { 125 &already_set_value, NULL)) {
111 const std::string value = kDefaultAudioConstraints[i].value ? 126 const std::string value = kDefaultAudioConstraints[i].value ?
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 385
371 int median = 0, std = 0; 386 int median = 0, std = 0;
372 float dummy = 0; 387 float dummy = 0;
373 if (echo_cancellation->GetDelayMetrics(&median, &std, &dummy) == 388 if (echo_cancellation->GetDelayMetrics(&median, &std, &dummy) ==
374 webrtc::AudioProcessing::kNoError) { 389 webrtc::AudioProcessing::kNoError) {
375 stats->echo_delay_median_ms = median; 390 stats->echo_delay_median_ms = median;
376 stats->echo_delay_std_ms = std; 391 stats->echo_delay_std_ms = std;
377 } 392 }
378 } 393 }
379 394
380 CONTENT_EXPORT std::vector<webrtc::Point> ParseArrayGeometry( 395 std::vector<webrtc::Point> GetArrayGeometryPreferringConstraints(
381 const std::string& geometry_string) { 396 const MediaAudioConstraints& audio_constraints,
382 const auto& tokens = 397 const MediaStreamDevice::AudioDeviceParameters& input_params) {
383 base::SplitString(geometry_string, base::kWhitespaceASCII, 398 const std::string constraints_geometry =
384 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 399 audio_constraints.GetPropertyAsString(
385 std::vector<webrtc::Point> geometry; 400 MediaAudioConstraints::kGoogArrayGeometry);
386 if (tokens.size() < 3 || tokens.size() % 3 != 0) {
387 LOG(ERROR) << "Malformed geometry string: " << geometry_string;
388 return geometry;
389 }
390 401
391 std::vector<float> float_tokens; 402 // Give preference to the audio constraint over the device-supplied mic
392 float_tokens.reserve(tokens.size()); 403 // positions. This is mainly for testing purposes.
393 for (const auto& token : tokens) { 404 return WebrtcPointsFromMediaPoints(
394 double float_token; 405 constraints_geometry.empty()
395 if (!base::StringToDouble(token, &float_token)) { 406 ? input_params.mic_positions
396 LOG(ERROR) << "Unable to convert token=" << token 407 : 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 } 408 }
411 409
412 } // namespace content 410 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698