Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef API_AUDIO_OPTIONS_H_ |
| 12 | #define API_AUDIO_OPTIONS_H_ |
| 13 | |
| 14 | #include <string> |
| 15 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 16 | #include "absl/types/optional.h" |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 17 | #include "rtc_base/stringencode.h" |
| 18 | |
| 19 | namespace cricket { |
| 20 | |
| 21 | // Options that can be applied to a VoiceMediaChannel or a VoiceMediaEngine. |
| 22 | // Used to be flags, but that makes it hard to selectively apply options. |
| 23 | // We are moving all of the setting of options to structs like this, |
| 24 | // but some things currently still use flags. |
| 25 | struct AudioOptions { |
Paulina Hensman | 11b34f4 | 2018-04-09 12:24:52 | [diff] [blame] | 26 | AudioOptions(); |
| 27 | ~AudioOptions(); |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 28 | void SetAll(const AudioOptions& change) { |
| 29 | SetFrom(&echo_cancellation, change.echo_cancellation); |
| 30 | #if defined(WEBRTC_IOS) |
| 31 | SetFrom(&ios_force_software_aec_HACK, change.ios_force_software_aec_HACK); |
| 32 | #endif |
| 33 | SetFrom(&auto_gain_control, change.auto_gain_control); |
| 34 | SetFrom(&noise_suppression, change.noise_suppression); |
| 35 | SetFrom(&highpass_filter, change.highpass_filter); |
| 36 | SetFrom(&stereo_swapping, change.stereo_swapping); |
| 37 | SetFrom(&audio_jitter_buffer_max_packets, |
| 38 | change.audio_jitter_buffer_max_packets); |
| 39 | SetFrom(&audio_jitter_buffer_fast_accelerate, |
| 40 | change.audio_jitter_buffer_fast_accelerate); |
| 41 | SetFrom(&typing_detection, change.typing_detection); |
| 42 | SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise); |
| 43 | SetFrom(&experimental_agc, change.experimental_agc); |
| 44 | SetFrom(&extended_filter_aec, change.extended_filter_aec); |
| 45 | SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec); |
| 46 | SetFrom(&experimental_ns, change.experimental_ns); |
| 47 | SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer); |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 48 | SetFrom(&residual_echo_detector, change.residual_echo_detector); |
| 49 | SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov); |
| 50 | SetFrom(&tx_agc_digital_compression_gain, |
| 51 | change.tx_agc_digital_compression_gain); |
| 52 | SetFrom(&tx_agc_limiter, change.tx_agc_limiter); |
| 53 | SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe); |
| 54 | SetFrom(&audio_network_adaptor, change.audio_network_adaptor); |
| 55 | SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config); |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | bool operator==(const AudioOptions& o) const { |
| 59 | return echo_cancellation == o.echo_cancellation && |
| 60 | #if defined(WEBRTC_IOS) |
| 61 | ios_force_software_aec_HACK == o.ios_force_software_aec_HACK && |
| 62 | #endif |
| 63 | auto_gain_control == o.auto_gain_control && |
| 64 | noise_suppression == o.noise_suppression && |
| 65 | highpass_filter == o.highpass_filter && |
| 66 | stereo_swapping == o.stereo_swapping && |
| 67 | audio_jitter_buffer_max_packets == |
| 68 | o.audio_jitter_buffer_max_packets && |
| 69 | audio_jitter_buffer_fast_accelerate == |
| 70 | o.audio_jitter_buffer_fast_accelerate && |
| 71 | typing_detection == o.typing_detection && |
| 72 | aecm_generate_comfort_noise == o.aecm_generate_comfort_noise && |
| 73 | experimental_agc == o.experimental_agc && |
| 74 | extended_filter_aec == o.extended_filter_aec && |
| 75 | delay_agnostic_aec == o.delay_agnostic_aec && |
| 76 | experimental_ns == o.experimental_ns && |
| 77 | intelligibility_enhancer == o.intelligibility_enhancer && |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 78 | residual_echo_detector == o.residual_echo_detector && |
| 79 | tx_agc_target_dbov == o.tx_agc_target_dbov && |
| 80 | tx_agc_digital_compression_gain == |
| 81 | o.tx_agc_digital_compression_gain && |
| 82 | tx_agc_limiter == o.tx_agc_limiter && |
| 83 | combined_audio_video_bwe == o.combined_audio_video_bwe && |
| 84 | audio_network_adaptor == o.audio_network_adaptor && |
Sam Zackrisson | ab1aee0 | 2018-03-05 14:59:06 | [diff] [blame] | 85 | audio_network_adaptor_config == o.audio_network_adaptor_config; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 86 | } |
| 87 | bool operator!=(const AudioOptions& o) const { return !(*this == o); } |
| 88 | |
| 89 | std::string ToString() const { |
| 90 | std::ostringstream ost; |
| 91 | ost << "AudioOptions {"; |
| 92 | ost << ToStringIfSet("aec", echo_cancellation); |
| 93 | #if defined(WEBRTC_IOS) |
| 94 | ost << ToStringIfSet("ios_force_software_aec_HACK", |
| 95 | ios_force_software_aec_HACK); |
| 96 | #endif |
| 97 | ost << ToStringIfSet("agc", auto_gain_control); |
| 98 | ost << ToStringIfSet("ns", noise_suppression); |
| 99 | ost << ToStringIfSet("hf", highpass_filter); |
| 100 | ost << ToStringIfSet("swap", stereo_swapping); |
| 101 | ost << ToStringIfSet("audio_jitter_buffer_max_packets", |
| 102 | audio_jitter_buffer_max_packets); |
| 103 | ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate", |
| 104 | audio_jitter_buffer_fast_accelerate); |
| 105 | ost << ToStringIfSet("typing", typing_detection); |
| 106 | ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise); |
| 107 | ost << ToStringIfSet("experimental_agc", experimental_agc); |
| 108 | ost << ToStringIfSet("extended_filter_aec", extended_filter_aec); |
| 109 | ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec); |
| 110 | ost << ToStringIfSet("experimental_ns", experimental_ns); |
| 111 | ost << ToStringIfSet("intelligibility_enhancer", intelligibility_enhancer); |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 112 | ost << ToStringIfSet("residual_echo_detector", residual_echo_detector); |
| 113 | ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov); |
| 114 | ost << ToStringIfSet("tx_agc_digital_compression_gain", |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 115 | tx_agc_digital_compression_gain); |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 116 | ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter); |
| 117 | ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe); |
| 118 | ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor); |
| 119 | // The adaptor config is a serialized proto buffer and therefore not human |
| 120 | // readable. So we comment out the following line. |
| 121 | // ost << ToStringIfSet("audio_network_adaptor_config", |
| 122 | // audio_network_adaptor_config); |
| 123 | ost << "}"; |
| 124 | return ost.str(); |
| 125 | } |
| 126 | |
| 127 | // Audio processing that attempts to filter away the output signal from |
| 128 | // later inbound pickup. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 129 | absl::optional<bool> echo_cancellation; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 130 | #if defined(WEBRTC_IOS) |
| 131 | // Forces software echo cancellation on iOS. This is a temporary workaround |
| 132 | // (until Apple fixes the bug) for a device with non-functioning AEC. May |
| 133 | // improve performance on that particular device, but will cause unpredictable |
| 134 | // behavior in all other cases. See http://bugs.webrtc.org/8682. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 135 | absl::optional<bool> ios_force_software_aec_HACK; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 136 | #endif |
| 137 | // Audio processing to adjust the sensitivity of the local mic dynamically. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 138 | absl::optional<bool> auto_gain_control; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 139 | // Audio processing to filter out background noise. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 140 | absl::optional<bool> noise_suppression; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 141 | // Audio processing to remove background noise of lower frequencies. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 142 | absl::optional<bool> highpass_filter; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 143 | // Audio processing to swap the left and right channels. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 144 | absl::optional<bool> stereo_swapping; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 145 | // Audio receiver jitter buffer (NetEq) max capacity in number of packets. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 146 | absl::optional<int> audio_jitter_buffer_max_packets; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 147 | // Audio receiver jitter buffer (NetEq) fast accelerate mode. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 148 | absl::optional<bool> audio_jitter_buffer_fast_accelerate; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 149 | // Audio processing to detect typing. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 150 | absl::optional<bool> typing_detection; |
| 151 | absl::optional<bool> aecm_generate_comfort_noise; |
| 152 | absl::optional<bool> experimental_agc; |
| 153 | absl::optional<bool> extended_filter_aec; |
| 154 | absl::optional<bool> delay_agnostic_aec; |
| 155 | absl::optional<bool> experimental_ns; |
| 156 | absl::optional<bool> intelligibility_enhancer; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 157 | // Note that tx_agc_* only applies to non-experimental AGC. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 158 | absl::optional<bool> residual_echo_detector; |
| 159 | absl::optional<uint16_t> tx_agc_target_dbov; |
| 160 | absl::optional<uint16_t> tx_agc_digital_compression_gain; |
| 161 | absl::optional<bool> tx_agc_limiter; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 162 | // Enable combined audio+bandwidth BWE. |
| 163 | // TODO(pthatcher): This flag is set from the |
| 164 | // "googCombinedAudioVideoBwe", but not used anywhere. So delete it, |
| 165 | // and check if any other AudioOptions members are unused. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 166 | absl::optional<bool> combined_audio_video_bwe; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 167 | // Enable audio network adaptor. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 168 | absl::optional<bool> audio_network_adaptor; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 169 | // Config string for audio network adaptor. |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 170 | absl::optional<std::string> audio_network_adaptor_config; |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 171 | |
| 172 | private: |
| 173 | template <class T> |
| 174 | static std::string ToStringIfSet(const char* key, |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 175 | const absl::optional<T>& val) { |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 176 | std::string str; |
| 177 | if (val) { |
| 178 | str = key; |
| 179 | str += ": "; |
| 180 | str += val ? rtc::ToString(*val) : ""; |
| 181 | str += ", "; |
| 182 | } |
| 183 | return str; |
| 184 | } |
| 185 | |
| 186 | template <typename T> |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 187 | static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) { |
Niels Möller | a6fe261 | 2018-01-19 10:28:54 | [diff] [blame] | 188 | if (o) { |
| 189 | *s = o; |
| 190 | } |
| 191 | } |
| 192 | }; |
| 193 | |
| 194 | } // namespace cricket |
| 195 | |
| 196 | #endif // API_AUDIO_OPTIONS_H_ |