Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/api/localaudiosource.h" | 11 #include "webrtc/api/localaudiosource.h" |
| 12 | 12 |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "webrtc/api/mediaconstraintsinterface.h" | 15 #include "webrtc/api/mediaconstraintsinterface.h" |
| 16 #include "webrtc/media/base/mediaengine.h" | 16 #include "webrtc/media/base/mediaengine.h" |
| 17 | 17 |
| 18 using webrtc::MediaConstraintsInterface; | 18 using webrtc::MediaConstraintsInterface; |
| 19 using webrtc::MediaSourceInterface; | 19 using webrtc::MediaSourceInterface; |
| 20 | 20 |
| 21 namespace webrtc { | 21 namespace webrtc { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Convert constraints to audio options. Return false if constraints are | 25 // Convert constraints to audio options. Return false if constraints are |
| 26 // invalid. | 26 // invalid. |
| 27 void FromConstraints(const MediaConstraintsInterface::Constraints& constraints, | 27 void FromConstraints(const MediaConstraintsInterface::Constraints& constraints, |
| 28 cricket::AudioOptions* options) { | 28 cricket::AudioOptions* options) { |
| 29 // This design relies on the fact that all the audio constraints are actually | 29 // Set boolean constarints first. |
|
tommi
2016/10/19 11:25:50
Fix typo
aleloi
2016/10/19 13:59:21
Done.
| |
| 30 // "options", i.e. boolean-valued and always satisfiable. If the constraints | |
| 31 // are extended to include non-boolean values or actual format constraints, | |
| 32 // a different algorithm will be required. | |
| 33 struct { | 30 struct { |
| 34 const char* name; | 31 const char* name; |
| 35 rtc::Optional<bool>& value; | 32 rtc::Optional<bool>& value; |
| 36 } key_to_value[] = { | 33 } boolean_constraint_key_to_value[] = { |
|
tommi
2016/10/19 11:25:50
Are these changes relevant to the cl?
Maybe it's j
aleloi
2016/10/19 13:59:21
I agree, lets leave it as is.
| |
| 37 {MediaConstraintsInterface::kGoogEchoCancellation, | 34 {MediaConstraintsInterface::kGoogEchoCancellation, |
| 38 options->echo_cancellation}, | 35 options->echo_cancellation}, |
| 39 {MediaConstraintsInterface::kExtendedFilterEchoCancellation, | 36 {MediaConstraintsInterface::kExtendedFilterEchoCancellation, |
| 40 options->extended_filter_aec}, | 37 options->extended_filter_aec}, |
| 41 {MediaConstraintsInterface::kDAEchoCancellation, | 38 {MediaConstraintsInterface::kDAEchoCancellation, |
| 42 options->delay_agnostic_aec}, | 39 options->delay_agnostic_aec}, |
| 43 {MediaConstraintsInterface::kAutoGainControl, options->auto_gain_control}, | 40 {MediaConstraintsInterface::kAutoGainControl, options->auto_gain_control}, |
| 44 {MediaConstraintsInterface::kExperimentalAutoGainControl, | 41 {MediaConstraintsInterface::kExperimentalAutoGainControl, |
| 45 options->experimental_agc}, | 42 options->experimental_agc}, |
| 46 {MediaConstraintsInterface::kNoiseSuppression, | 43 {MediaConstraintsInterface::kNoiseSuppression, |
| 47 options->noise_suppression}, | 44 options->noise_suppression}, |
| 48 {MediaConstraintsInterface::kExperimentalNoiseSuppression, | 45 {MediaConstraintsInterface::kExperimentalNoiseSuppression, |
| 49 options->experimental_ns}, | 46 options->experimental_ns}, |
| 50 {MediaConstraintsInterface::kIntelligibilityEnhancer, | 47 {MediaConstraintsInterface::kIntelligibilityEnhancer, |
| 51 options->intelligibility_enhancer}, | 48 options->intelligibility_enhancer}, |
| 52 {MediaConstraintsInterface::kLevelControl, options->level_control}, | 49 {MediaConstraintsInterface::kLevelControl, options->level_control}, |
| 53 {MediaConstraintsInterface::kHighpassFilter, options->highpass_filter}, | 50 {MediaConstraintsInterface::kHighpassFilter, options->highpass_filter}, |
| 54 {MediaConstraintsInterface::kTypingNoiseDetection, | 51 {MediaConstraintsInterface::kTypingNoiseDetection, |
| 55 options->typing_detection}, | 52 options->typing_detection}, |
| 56 {MediaConstraintsInterface::kAudioMirroring, options->stereo_swapping} | 53 {MediaConstraintsInterface::kAudioMirroring, options->stereo_swapping}}; |
| 57 }; | |
| 58 | 54 |
| 59 for (const auto& constraint : constraints) { | 55 for (const auto& constraint : constraints) { |
| 60 bool value = false; | 56 bool value = false; |
| 61 if (!rtc::FromString(constraint.value, &value)) | 57 if (!rtc::FromString(constraint.value, &value)) |
| 62 continue; | 58 continue; |
| 63 | 59 |
| 64 for (auto& entry : key_to_value) { | 60 for (auto& entry : boolean_constraint_key_to_value) { |
| 65 if (constraint.key.compare(entry.name) == 0) | 61 if (constraint.key.compare(entry.name) == 0) |
| 66 entry.value = rtc::Optional<bool>(value); | 62 entry.value = rtc::Optional<bool>(value); |
| 67 } | 63 } |
| 68 } | 64 } |
| 65 | |
| 66 // Set non-boolean constraints. | |
| 67 std::string value; | |
| 68 if (constraints.FindFirst( | |
| 69 MediaConstraintsInterface::kLevelControlInitialPeakLevelDBFS, | |
| 70 &value)) { | |
| 71 float level_control_initial_peak_level_dbfs; | |
| 72 if (rtc::FromString(value, &level_control_initial_peak_level_dbfs)) { | |
| 73 options->level_control_initial_peak_level_dbfs = | |
| 74 rtc::Optional<float>(level_control_initial_peak_level_dbfs); | |
| 75 } | |
| 76 } | |
| 69 } | 77 } |
| 70 | 78 |
| 71 } // namespace | 79 } // namespace |
| 72 | 80 |
| 73 rtc::scoped_refptr<LocalAudioSource> LocalAudioSource::Create( | 81 rtc::scoped_refptr<LocalAudioSource> LocalAudioSource::Create( |
| 74 const PeerConnectionFactoryInterface::Options& options, | 82 const PeerConnectionFactoryInterface::Options& options, |
| 75 const MediaConstraintsInterface* constraints) { | 83 const MediaConstraintsInterface* constraints) { |
| 76 rtc::scoped_refptr<LocalAudioSource> source( | 84 rtc::scoped_refptr<LocalAudioSource> source( |
| 77 new rtc::RefCountedObject<LocalAudioSource>()); | 85 new rtc::RefCountedObject<LocalAudioSource>()); |
| 78 source->Initialize(options, constraints); | 86 source->Initialize(options, constraints); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 106 void LocalAudioSource::Initialize( | 114 void LocalAudioSource::Initialize( |
| 107 const PeerConnectionFactoryInterface::Options& options, | 115 const PeerConnectionFactoryInterface::Options& options, |
| 108 const cricket::AudioOptions* audio_options) { | 116 const cricket::AudioOptions* audio_options) { |
| 109 if (!audio_options) | 117 if (!audio_options) |
| 110 return; | 118 return; |
| 111 | 119 |
| 112 options_ = *audio_options; | 120 options_ = *audio_options; |
| 113 } | 121 } |
| 114 | 122 |
| 115 } // namespace webrtc | 123 } // namespace webrtc |
| OLD | NEW |