blob: df66d360c562359994adc03ef73d8ab8236aff88 [file] [log] [blame]
Niels Möllera6fe2612018-01-19 10:28:541/*
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 Chapovalov0bc58cf2018-06-21 11:32:5616#include "absl/types/optional.h"
Niels Möllera6fe2612018-01-19 10:28:5417#include "rtc_base/stringencode.h"
18
19namespace 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.
25struct AudioOptions {
Paulina Hensman11b34f42018-04-09 12:24:5226 AudioOptions();
27 ~AudioOptions();
Niels Möllera6fe2612018-01-19 10:28:5428 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öllera6fe2612018-01-19 10:28:5448 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öllera6fe2612018-01-19 10:28:5456 }
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öllera6fe2612018-01-19 10:28:5478 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 Zackrissonab1aee02018-03-05 14:59:0685 audio_network_adaptor_config == o.audio_network_adaptor_config;
Niels Möllera6fe2612018-01-19 10:28:5486 }
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öllera6fe2612018-01-19 10:28:54112 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 Gerey665174f2018-06-19 13:03:05115 tx_agc_digital_compression_gain);
Niels Möllera6fe2612018-01-19 10:28:54116 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 Chapovalov0bc58cf2018-06-21 11:32:56129 absl::optional<bool> echo_cancellation;
Niels Möllera6fe2612018-01-19 10:28:54130#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 Chapovalov0bc58cf2018-06-21 11:32:56135 absl::optional<bool> ios_force_software_aec_HACK;
Niels Möllera6fe2612018-01-19 10:28:54136#endif
137 // Audio processing to adjust the sensitivity of the local mic dynamically.
Danil Chapovalov0bc58cf2018-06-21 11:32:56138 absl::optional<bool> auto_gain_control;
Niels Möllera6fe2612018-01-19 10:28:54139 // Audio processing to filter out background noise.
Danil Chapovalov0bc58cf2018-06-21 11:32:56140 absl::optional<bool> noise_suppression;
Niels Möllera6fe2612018-01-19 10:28:54141 // Audio processing to remove background noise of lower frequencies.
Danil Chapovalov0bc58cf2018-06-21 11:32:56142 absl::optional<bool> highpass_filter;
Niels Möllera6fe2612018-01-19 10:28:54143 // Audio processing to swap the left and right channels.
Danil Chapovalov0bc58cf2018-06-21 11:32:56144 absl::optional<bool> stereo_swapping;
Niels Möllera6fe2612018-01-19 10:28:54145 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
Danil Chapovalov0bc58cf2018-06-21 11:32:56146 absl::optional<int> audio_jitter_buffer_max_packets;
Niels Möllera6fe2612018-01-19 10:28:54147 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
Danil Chapovalov0bc58cf2018-06-21 11:32:56148 absl::optional<bool> audio_jitter_buffer_fast_accelerate;
Niels Möllera6fe2612018-01-19 10:28:54149 // Audio processing to detect typing.
Danil Chapovalov0bc58cf2018-06-21 11:32:56150 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öllera6fe2612018-01-19 10:28:54157 // Note that tx_agc_* only applies to non-experimental AGC.
Danil Chapovalov0bc58cf2018-06-21 11:32:56158 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öllera6fe2612018-01-19 10:28:54162 // 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 Chapovalov0bc58cf2018-06-21 11:32:56166 absl::optional<bool> combined_audio_video_bwe;
Niels Möllera6fe2612018-01-19 10:28:54167 // Enable audio network adaptor.
Danil Chapovalov0bc58cf2018-06-21 11:32:56168 absl::optional<bool> audio_network_adaptor;
Niels Möllera6fe2612018-01-19 10:28:54169 // Config string for audio network adaptor.
Danil Chapovalov0bc58cf2018-06-21 11:32:56170 absl::optional<std::string> audio_network_adaptor_config;
Niels Möllera6fe2612018-01-19 10:28:54171
172 private:
173 template <class T>
174 static std::string ToStringIfSet(const char* key,
Danil Chapovalov0bc58cf2018-06-21 11:32:56175 const absl::optional<T>& val) {
Niels Möllera6fe2612018-01-19 10:28:54176 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 Chapovalov0bc58cf2018-06-21 11:32:56187 static void SetFrom(absl::optional<T>* s, const absl::optional<T>& o) {
Niels Möllera6fe2612018-01-19 10:28:54188 if (o) {
189 *s = o;
190 }
191 }
192};
193
194} // namespace cricket
195
196#endif // API_AUDIO_OPTIONS_H_