blob: 8d2880b0a0a9f33582cfda7b7ac86e2307484bc6 [file] [log] [blame]
Niels Möllera6fe2612018-01-19 11:28:54 +01001/*
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
16#include "api/optional.h"
17#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 {
26 void SetAll(const AudioOptions& change) {
27 SetFrom(&echo_cancellation, change.echo_cancellation);
28#if defined(WEBRTC_IOS)
29 SetFrom(&ios_force_software_aec_HACK, change.ios_force_software_aec_HACK);
30#endif
31 SetFrom(&auto_gain_control, change.auto_gain_control);
32 SetFrom(&noise_suppression, change.noise_suppression);
33 SetFrom(&highpass_filter, change.highpass_filter);
34 SetFrom(&stereo_swapping, change.stereo_swapping);
35 SetFrom(&audio_jitter_buffer_max_packets,
36 change.audio_jitter_buffer_max_packets);
37 SetFrom(&audio_jitter_buffer_fast_accelerate,
38 change.audio_jitter_buffer_fast_accelerate);
39 SetFrom(&typing_detection, change.typing_detection);
40 SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise);
41 SetFrom(&experimental_agc, change.experimental_agc);
42 SetFrom(&extended_filter_aec, change.extended_filter_aec);
43 SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec);
44 SetFrom(&experimental_ns, change.experimental_ns);
45 SetFrom(&intelligibility_enhancer, change.intelligibility_enhancer);
Niels Möllera6fe2612018-01-19 11:28:54 +010046 SetFrom(&residual_echo_detector, change.residual_echo_detector);
47 SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov);
48 SetFrom(&tx_agc_digital_compression_gain,
49 change.tx_agc_digital_compression_gain);
50 SetFrom(&tx_agc_limiter, change.tx_agc_limiter);
51 SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe);
52 SetFrom(&audio_network_adaptor, change.audio_network_adaptor);
53 SetFrom(&audio_network_adaptor_config, change.audio_network_adaptor_config);
Niels Möllera6fe2612018-01-19 11:28:54 +010054 }
55
56 bool operator==(const AudioOptions& o) const {
57 return echo_cancellation == o.echo_cancellation &&
58#if defined(WEBRTC_IOS)
59 ios_force_software_aec_HACK == o.ios_force_software_aec_HACK &&
60#endif
61 auto_gain_control == o.auto_gain_control &&
62 noise_suppression == o.noise_suppression &&
63 highpass_filter == o.highpass_filter &&
64 stereo_swapping == o.stereo_swapping &&
65 audio_jitter_buffer_max_packets ==
66 o.audio_jitter_buffer_max_packets &&
67 audio_jitter_buffer_fast_accelerate ==
68 o.audio_jitter_buffer_fast_accelerate &&
69 typing_detection == o.typing_detection &&
70 aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
71 experimental_agc == o.experimental_agc &&
72 extended_filter_aec == o.extended_filter_aec &&
73 delay_agnostic_aec == o.delay_agnostic_aec &&
74 experimental_ns == o.experimental_ns &&
75 intelligibility_enhancer == o.intelligibility_enhancer &&
Niels Möllera6fe2612018-01-19 11:28:54 +010076 residual_echo_detector == o.residual_echo_detector &&
77 tx_agc_target_dbov == o.tx_agc_target_dbov &&
78 tx_agc_digital_compression_gain ==
79 o.tx_agc_digital_compression_gain &&
80 tx_agc_limiter == o.tx_agc_limiter &&
81 combined_audio_video_bwe == o.combined_audio_video_bwe &&
82 audio_network_adaptor == o.audio_network_adaptor &&
Sam Zackrisson6f37ed72018-03-05 15:59:06 +010083 audio_network_adaptor_config == o.audio_network_adaptor_config;
Niels Möllera6fe2612018-01-19 11:28:54 +010084 }
85 bool operator!=(const AudioOptions& o) const { return !(*this == o); }
86
87 std::string ToString() const {
88 std::ostringstream ost;
89 ost << "AudioOptions {";
90 ost << ToStringIfSet("aec", echo_cancellation);
91#if defined(WEBRTC_IOS)
92 ost << ToStringIfSet("ios_force_software_aec_HACK",
93 ios_force_software_aec_HACK);
94#endif
95 ost << ToStringIfSet("agc", auto_gain_control);
96 ost << ToStringIfSet("ns", noise_suppression);
97 ost << ToStringIfSet("hf", highpass_filter);
98 ost << ToStringIfSet("swap", stereo_swapping);
99 ost << ToStringIfSet("audio_jitter_buffer_max_packets",
100 audio_jitter_buffer_max_packets);
101 ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate",
102 audio_jitter_buffer_fast_accelerate);
103 ost << ToStringIfSet("typing", typing_detection);
104 ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise);
105 ost << ToStringIfSet("experimental_agc", experimental_agc);
106 ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
107 ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
108 ost << ToStringIfSet("experimental_ns", experimental_ns);
109 ost << ToStringIfSet("intelligibility_enhancer", intelligibility_enhancer);
Niels Möllera6fe2612018-01-19 11:28:54 +0100110 ost << ToStringIfSet("residual_echo_detector", residual_echo_detector);
111 ost << ToStringIfSet("tx_agc_target_dbov", tx_agc_target_dbov);
112 ost << ToStringIfSet("tx_agc_digital_compression_gain",
113 tx_agc_digital_compression_gain);
114 ost << ToStringIfSet("tx_agc_limiter", tx_agc_limiter);
115 ost << ToStringIfSet("combined_audio_video_bwe", combined_audio_video_bwe);
116 ost << ToStringIfSet("audio_network_adaptor", audio_network_adaptor);
117 // The adaptor config is a serialized proto buffer and therefore not human
118 // readable. So we comment out the following line.
119 // ost << ToStringIfSet("audio_network_adaptor_config",
120 // audio_network_adaptor_config);
121 ost << "}";
122 return ost.str();
123 }
124
125 // Audio processing that attempts to filter away the output signal from
126 // later inbound pickup.
127 rtc::Optional<bool> echo_cancellation;
128#if defined(WEBRTC_IOS)
129 // Forces software echo cancellation on iOS. This is a temporary workaround
130 // (until Apple fixes the bug) for a device with non-functioning AEC. May
131 // improve performance on that particular device, but will cause unpredictable
132 // behavior in all other cases. See http://bugs.webrtc.org/8682.
133 rtc::Optional<bool> ios_force_software_aec_HACK;
134#endif
135 // Audio processing to adjust the sensitivity of the local mic dynamically.
136 rtc::Optional<bool> auto_gain_control;
137 // Audio processing to filter out background noise.
138 rtc::Optional<bool> noise_suppression;
139 // Audio processing to remove background noise of lower frequencies.
140 rtc::Optional<bool> highpass_filter;
141 // Audio processing to swap the left and right channels.
142 rtc::Optional<bool> stereo_swapping;
143 // Audio receiver jitter buffer (NetEq) max capacity in number of packets.
144 rtc::Optional<int> audio_jitter_buffer_max_packets;
145 // Audio receiver jitter buffer (NetEq) fast accelerate mode.
146 rtc::Optional<bool> audio_jitter_buffer_fast_accelerate;
147 // Audio processing to detect typing.
148 rtc::Optional<bool> typing_detection;
149 rtc::Optional<bool> aecm_generate_comfort_noise;
150 rtc::Optional<bool> experimental_agc;
151 rtc::Optional<bool> extended_filter_aec;
152 rtc::Optional<bool> delay_agnostic_aec;
153 rtc::Optional<bool> experimental_ns;
154 rtc::Optional<bool> intelligibility_enhancer;
Niels Möllera6fe2612018-01-19 11:28:54 +0100155 // Note that tx_agc_* only applies to non-experimental AGC.
156 rtc::Optional<bool> residual_echo_detector;
157 rtc::Optional<uint16_t> tx_agc_target_dbov;
158 rtc::Optional<uint16_t> tx_agc_digital_compression_gain;
159 rtc::Optional<bool> tx_agc_limiter;
160 // Enable combined audio+bandwidth BWE.
161 // TODO(pthatcher): This flag is set from the
162 // "googCombinedAudioVideoBwe", but not used anywhere. So delete it,
163 // and check if any other AudioOptions members are unused.
164 rtc::Optional<bool> combined_audio_video_bwe;
165 // Enable audio network adaptor.
166 rtc::Optional<bool> audio_network_adaptor;
167 // Config string for audio network adaptor.
168 rtc::Optional<std::string> audio_network_adaptor_config;
169
170 private:
171 template <class T>
172 static std::string ToStringIfSet(const char* key,
173 const rtc::Optional<T>& val) {
174 std::string str;
175 if (val) {
176 str = key;
177 str += ": ";
178 str += val ? rtc::ToString(*val) : "";
179 str += ", ";
180 }
181 return str;
182 }
183
184 template <typename T>
185 static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) {
186 if (o) {
187 *s = o;
188 }
189 }
190};
191
192} // namespace cricket
193
194#endif // API_AUDIO_OPTIONS_H_