blob: 9b5440c17b1f5b421626987050478fd893568c85 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010011#ifndef WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_
12#define WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <list>
15#include <map>
16#include <vector>
17
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000018#include "webrtc/base/basictypes.h"
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020019#include "webrtc/base/checks.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000020#include "webrtc/base/stringutils.h"
Henrik Lundin64dad832015-05-11 12:44:23 +020021#include "webrtc/config.h"
kjellandera96e2d72016-02-04 23:52:28 -080022#include "webrtc/media/base/codec.h"
23#include "webrtc/media/base/rtputils.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010024#include "webrtc/media/engine/webrtcvoe.h"
solenberg26c8c912015-11-27 04:00:25 -080025#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000026#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000027
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028namespace cricket {
29
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000030static const int kOpusBandwidthNb = 4000;
31static const int kOpusBandwidthMb = 6000;
32static const int kOpusBandwidthWb = 8000;
33static const int kOpusBandwidthSwb = 12000;
34static const int kOpusBandwidthFb = 20000;
35
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020036#define WEBRTC_CHECK_CHANNEL(channel) \
37 if (channels_.find(channel) == channels_.end()) return -1;
38
solenbergf7a53352016-08-31 05:18:22 -070039#define WEBRTC_STUB(method, args) \
40 int method args override { return 0; }
41
42#define WEBRTC_STUB_CONST(method, args) \
43 int method args const override { return 0; }
44
45#define WEBRTC_BOOL_STUB(method, args) \
46 bool method args override { return true; }
47
48#define WEBRTC_BOOL_STUB_CONST(method, args) \
49 bool method args const override { return true; }
50
51#define WEBRTC_VOID_STUB(method, args) \
52 void method args override {}
53
54#define WEBRTC_FUNC(method, args) int method args override
55
56#define WEBRTC_VOID_FUNC(method, args) void method args override
57
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000058class FakeAudioProcessing : public webrtc::AudioProcessing {
59 public:
60 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
61
62 WEBRTC_STUB(Initialize, ())
63 WEBRTC_STUB(Initialize, (
64 int input_sample_rate_hz,
65 int output_sample_rate_hz,
66 int reverse_sample_rate_hz,
67 webrtc::AudioProcessing::ChannelLayout input_layout,
68 webrtc::AudioProcessing::ChannelLayout output_layout,
69 webrtc::AudioProcessing::ChannelLayout reverse_layout));
Michael Graczyk86c6d332015-07-23 11:41:39 -070070 WEBRTC_STUB(Initialize, (
71 const webrtc::ProcessingConfig& processing_config));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000072
73 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
74 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
75 }
76
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000077 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
78 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
Peter Kasting69558702016-01-12 16:26:35 -080079 size_t num_input_channels() const override { return 0; }
80 size_t num_proc_channels() const override { return 0; }
81 size_t num_output_channels() const override { return 0; }
82 size_t num_reverse_channels() const override { return 0; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000083 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000084 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
85 WEBRTC_STUB(ProcessStream, (
86 const float* const* src,
Peter Kastingdce40cf2015-08-24 14:52:23 -070087 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000088 int input_sample_rate_hz,
89 webrtc::AudioProcessing::ChannelLayout input_layout,
90 int output_sample_rate_hz,
91 webrtc::AudioProcessing::ChannelLayout output_layout,
92 float* const* dest));
Michael Graczyk86c6d332015-07-23 11:41:39 -070093 WEBRTC_STUB(ProcessStream,
94 (const float* const* src,
95 const webrtc::StreamConfig& input_config,
96 const webrtc::StreamConfig& output_config,
97 float* const* dest));
ekmeyerson60d9b332015-08-14 10:35:55 -070098 WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000099 WEBRTC_STUB(AnalyzeReverseStream, (
100 const float* const* data,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700101 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000102 int sample_rate_hz,
103 webrtc::AudioProcessing::ChannelLayout layout));
ekmeyerson60d9b332015-08-14 10:35:55 -0700104 WEBRTC_STUB(ProcessReverseStream,
105 (const float* const* src,
106 const webrtc::StreamConfig& reverse_input_config,
107 const webrtc::StreamConfig& reverse_output_config,
108 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000109 WEBRTC_STUB(set_stream_delay_ms, (int delay));
110 WEBRTC_STUB_CONST(stream_delay_ms, ());
111 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
112 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000113 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
114 WEBRTC_STUB_CONST(delay_offset_ms, ());
ivocd66b44d2016-01-15 03:06:36 -0800115 WEBRTC_STUB(StartDebugRecording,
116 (const char filename[kMaxFilenameSize], int64_t max_size_bytes));
117 WEBRTC_STUB(StartDebugRecording, (FILE * handle, int64_t max_size_bytes));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000118 WEBRTC_STUB(StopDebugRecording, ());
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200119 WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000120 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
121 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000122 return NULL;
123 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000124 webrtc::GainControl* gain_control() const override { return NULL; }
125 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
126 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
127 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
128 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000129
130 bool experimental_ns_enabled() {
131 return experimental_ns_enabled_;
132 }
133
134 private:
135 bool experimental_ns_enabled_;
136};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000137
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138class FakeWebRtcVoiceEngine
139 : public webrtc::VoEAudioProcessing,
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100140 public webrtc::VoEBase, public webrtc::VoECodec,
solenberg4a0f7b52016-06-16 13:07:33 -0700141 public webrtc::VoEHardware,
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200142 public webrtc::VoEVolumeControl {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 struct Channel {
solenbergbc37fc82016-04-04 09:54:44 -0700145 Channel() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 memset(&send_codec, 0, sizeof(send_codec));
147 }
solenbergbc37fc82016-04-04 09:54:44 -0700148 bool vad = false;
149 bool codec_fec = false;
150 int max_encoding_bandwidth = 0;
151 bool opus_dtx = false;
solenbergbc37fc82016-04-04 09:54:44 -0700152 int cn8_type = 13;
153 int cn16_type = 105;
solenbergbc37fc82016-04-04 09:54:44 -0700154 int associate_send_channel = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 std::vector<webrtc::CodecInst> recv_codecs;
156 webrtc::CodecInst send_codec;
solenbergbc37fc82016-04-04 09:54:44 -0700157 int neteq_capacity = -1;
158 bool neteq_fast_accelerate = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 };
160
solenbergbc37fc82016-04-04 09:54:44 -0700161 FakeWebRtcVoiceEngine() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 memset(&agc_config_, 0, sizeof(agc_config_));
163 }
solenbergff976312016-03-30 23:28:51 -0700164 ~FakeWebRtcVoiceEngine() override {
solenberg26c8c912015-11-27 04:00:25 -0800165 RTC_CHECK(channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 }
167
solenberg85a04962015-10-27 03:35:21 -0700168 bool ec_metrics_enabled() const { return ec_metrics_enabled_; }
169
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 bool IsInited() const { return inited_; }
171 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000172 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 bool GetVAD(int channel) {
174 return channels_[channel]->vad;
175 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100176 bool GetOpusDtx(int channel) {
177 return channels_[channel]->opus_dtx;
178 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000179 bool GetCodecFEC(int channel) {
180 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000182 int GetMaxEncodingBandwidth(int channel) {
183 return channels_[channel]->max_encoding_bandwidth;
184 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 int GetSendCNPayloadType(int channel, bool wideband) {
186 return (wideband) ?
187 channels_[channel]->cn16_type :
188 channels_[channel]->cn8_type;
189 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 void set_fail_create_channel(bool fail_create_channel) {
191 fail_create_channel_ = fail_create_channel;
192 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200193 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000194 if (fail_create_channel_) {
195 return -1;
196 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000197 Channel* ch = new Channel();
solenberg26c8c912015-11-27 04:00:25 -0800198 auto db = webrtc::acm2::RentACodec::Database();
199 ch->recv_codecs.assign(db.begin(), db.end());
Henrik Lundin64dad832015-05-11 12:44:23 +0200200 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
201 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
202 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200203 ch->neteq_fast_accelerate =
204 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000205 channels_[++last_channel_] = ch;
206 return last_channel_;
207 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000209 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
210
Minyue2013aec2015-05-13 14:14:42 +0200211 int GetAssociateSendChannel(int channel) {
212 return channels_[channel]->associate_send_channel;
213 }
214
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 WEBRTC_STUB(Release, ());
216
217 // webrtc::VoEBase
solenbergbc37fc82016-04-04 09:54:44 -0700218 WEBRTC_STUB(RegisterVoiceEngineObserver, (
219 webrtc::VoiceEngineObserver& observer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
ossu5f7cfa52016-05-30 08:11:28 -0700221 WEBRTC_FUNC(Init,
222 (webrtc::AudioDeviceModule* adm,
223 webrtc::AudioProcessing* audioproc,
224 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>&
225 decoder_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 inited_ = true;
227 return 0;
228 }
229 WEBRTC_FUNC(Terminate, ()) {
230 inited_ = false;
231 return 0;
232 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000233 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000234 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 }
solenbergff976312016-03-30 23:28:51 -0700236 webrtc::AudioDeviceModule* audio_device_module() override {
solenbergbc37fc82016-04-04 09:54:44 -0700237 return nullptr;
solenbergff976312016-03-30 23:28:51 -0700238 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200240 webrtc::Config empty_config;
241 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200243 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
244 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000245 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 WEBRTC_FUNC(DeleteChannel, (int channel)) {
247 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200248 for (const auto& ch : channels_) {
249 if (ch.second->associate_send_channel == channel) {
250 ch.second->associate_send_channel = -1;
251 }
252 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 delete channels_[channel];
254 channels_.erase(channel);
255 return 0;
256 }
257 WEBRTC_STUB(StartReceive, (int channel));
aleloi84ef6152016-08-04 05:28:21 -0700258 WEBRTC_STUB(StartPlayout, (int channel));
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800259 WEBRTC_STUB(StartSend, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 WEBRTC_STUB(StopReceive, (int channel));
aleloi84ef6152016-08-04 05:28:21 -0700261 WEBRTC_STUB(StopPlayout, (int channel));
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800262 WEBRTC_STUB(StopSend, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 WEBRTC_STUB(GetVersion, (char version[1024]));
264 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200265 WEBRTC_FUNC(AssociateSendChannel, (int channel,
266 int accociate_send_channel)) {
267 WEBRTC_CHECK_CHANNEL(channel);
268 channels_[channel]->associate_send_channel = accociate_send_channel;
269 return 0;
270 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271
272 // webrtc::VoECodec
solenberg26c8c912015-11-27 04:00:25 -0800273 WEBRTC_STUB(NumOfCodecs, ());
274 WEBRTC_STUB(GetCodec, (int index, webrtc::CodecInst& codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
276 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000277 // To match the behavior of the real implementation.
278 if (_stricmp(codec.plname, "telephone-event") == 0 ||
279 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
280 _stricmp(codec.plname, "CN") == 0 ||
kwiberg68061362016-06-14 08:04:47 -0700281 _stricmp(codec.plname, "red") == 0) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000282 return -1;
283 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000285 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 return 0;
287 }
288 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
289 WEBRTC_CHECK_CHANNEL(channel);
290 codec = channels_[channel]->send_codec;
291 return 0;
292 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200293 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200294 WEBRTC_STUB(GetRecCodec, (int channel, webrtc::CodecInst& codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 WEBRTC_FUNC(SetRecPayloadType, (int channel,
296 const webrtc::CodecInst& codec)) {
297 WEBRTC_CHECK_CHANNEL(channel);
298 Channel* ch = channels_[channel];
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 // Check if something else already has this slot.
300 if (codec.pltype != -1) {
301 for (std::vector<webrtc::CodecInst>::iterator it =
302 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
303 if (it->pltype == codec.pltype &&
304 _stricmp(it->plname, codec.plname) != 0) {
305 return -1;
306 }
307 }
308 }
309 // Otherwise try to find this codec and update its payload type.
solenberg26c8c912015-11-27 04:00:25 -0800310 int result = -1; // not found
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
312 it != ch->recv_codecs.end(); ++it) {
313 if (strcmp(it->plname, codec.plname) == 0 &&
solenberg26c8c912015-11-27 04:00:25 -0800314 it->plfreq == codec.plfreq &&
315 it->channels == codec.channels) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 it->pltype = codec.pltype;
solenberg26c8c912015-11-27 04:00:25 -0800317 result = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 }
319 }
solenberg26c8c912015-11-27 04:00:25 -0800320 return result;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 }
322 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
323 webrtc::PayloadFrequencies frequency)) {
324 WEBRTC_CHECK_CHANNEL(channel);
325 if (frequency == webrtc::kFreq8000Hz) {
326 channels_[channel]->cn8_type = type;
327 } else if (frequency == webrtc::kFreq16000Hz) {
328 channels_[channel]->cn16_type = type;
329 }
330 return 0;
331 }
332 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
333 WEBRTC_CHECK_CHANNEL(channel);
334 Channel* ch = channels_[channel];
335 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
336 it != ch->recv_codecs.end(); ++it) {
337 if (strcmp(it->plname, codec.plname) == 0 &&
338 it->plfreq == codec.plfreq &&
339 it->channels == codec.channels &&
340 it->pltype != -1) {
341 codec.pltype = it->pltype;
342 return 0;
343 }
344 }
345 return -1; // not found
346 }
347 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
348 bool disableDTX)) {
349 WEBRTC_CHECK_CHANNEL(channel);
350 if (channels_[channel]->send_codec.channels == 2) {
351 // Replicating VoE behavior; VAD cannot be enabled for stereo.
352 return -1;
353 }
354 channels_[channel]->vad = enable;
355 return 0;
356 }
357 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
358 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000359
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000360 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
361 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000362 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000363 // Return -1 if current send codec is not Opus.
364 // TODO(minyue): Excludes other codecs if they support inband FEC.
365 return -1;
366 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000367 channels_[channel]->codec_fec = enable;
368 return 0;
369 }
370 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
371 WEBRTC_CHECK_CHANNEL(channel);
372 enable = channels_[channel]->codec_fec;
373 return 0;
374 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000375
376 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
377 WEBRTC_CHECK_CHANNEL(channel);
378 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
379 // Return -1 if current send codec is not Opus.
380 return -1;
381 }
382 if (frequency_hz <= 8000)
383 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
384 else if (frequency_hz <= 12000)
385 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
386 else if (frequency_hz <= 16000)
387 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
388 else if (frequency_hz <= 24000)
389 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
390 else
391 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
392 return 0;
393 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000395 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
396 WEBRTC_CHECK_CHANNEL(channel);
397 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
398 // Return -1 if current send codec is not Opus.
399 return -1;
400 }
401 channels_[channel]->opus_dtx = enable_dtx;
402 return 0;
403 }
404
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 // webrtc::VoEHardware
solenberg246b8172015-12-08 09:50:23 -0800406 WEBRTC_STUB(GetNumOfRecordingDevices, (int& num));
407 WEBRTC_STUB(GetNumOfPlayoutDevices, (int& num));
408 WEBRTC_STUB(GetRecordingDeviceName, (int i, char* name, char* guid));
409 WEBRTC_STUB(GetPlayoutDeviceName, (int i, char* name, char* guid));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
411 WEBRTC_STUB(SetPlayoutDevice, (int));
412 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
413 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
solenberg5b5129a2016-04-08 05:35:48 -0700414 WEBRTC_STUB(SetRecordingSampleRate, (unsigned int samples_per_sec));
415 WEBRTC_STUB_CONST(RecordingSampleRate, (unsigned int* samples_per_sec));
416 WEBRTC_STUB(SetPlayoutSampleRate, (unsigned int samples_per_sec));
417 WEBRTC_STUB_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
nisseef8b61e2016-04-29 06:09:15 -0700419 bool BuiltInAECIsAvailable() const override { return false; }
henrikac14f5ff2015-09-23 14:08:33 +0200420 WEBRTC_STUB(EnableBuiltInAGC, (bool enable));
nisseef8b61e2016-04-29 06:09:15 -0700421 bool BuiltInAGCIsAvailable() const override { return false; }
henrikac14f5ff2015-09-23 14:08:33 +0200422 WEBRTC_STUB(EnableBuiltInNS, (bool enable));
nisseef8b61e2016-04-29 06:09:15 -0700423 bool BuiltInNSIsAvailable() const override { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 // webrtc::VoEVolumeControl
426 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
427 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 WEBRTC_STUB(SetMicVolume, (unsigned int));
429 WEBRTC_STUB(GetMicVolume, (unsigned int&));
430 WEBRTC_STUB(SetInputMute, (int, bool));
431 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
433 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
434 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
435 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
solenberg217fb662016-06-17 08:30:54 -0700436 WEBRTC_STUB(SetChannelOutputVolumeScaling, (int channel, float scale));
437 WEBRTC_STUB(GetChannelOutputVolumeScaling, (int channel, float& scale));
solenberg4bac9c52015-10-09 02:32:53 -0700438 WEBRTC_STUB(SetOutputVolumePan, (int channel, float left, float right));
439 WEBRTC_STUB(GetOutputVolumePan, (int channel, float& left, float& right));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440
441 // webrtc::VoEAudioProcessing
442 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
443 ns_enabled_ = enable;
444 ns_mode_ = mode;
445 return 0;
446 }
447 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
448 enabled = ns_enabled_;
449 mode = ns_mode_;
450 return 0;
451 }
452
453 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
454 agc_enabled_ = enable;
455 agc_mode_ = mode;
456 return 0;
457 }
458 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
459 enabled = agc_enabled_;
460 mode = agc_mode_;
461 return 0;
462 }
463
464 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
465 agc_config_ = config;
466 return 0;
467 }
468 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
469 config = agc_config_;
470 return 0;
471 }
472 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
473 ec_enabled_ = enable;
474 ec_mode_ = mode;
475 return 0;
476 }
477 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
478 enabled = ec_enabled_;
479 mode = ec_mode_;
480 return 0;
481 }
482 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
483 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
484 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
485 WEBRTC_STUB(DelayOffsetMs, ());
486 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
487 aecm_mode_ = mode;
488 cng_enabled_ = enableCNG;
489 return 0;
490 }
491 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
492 mode = aecm_mode_;
493 enabledCNG = cng_enabled_;
494 return 0;
495 }
496 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
497 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
498 webrtc::NsModes& mode));
solenberg0b675462015-10-09 01:37:09 -0700499 WEBRTC_STUB(SetRxAgcStatus, (int channel, bool enable,
500 webrtc::AgcModes mode));
501 WEBRTC_STUB(GetRxAgcStatus, (int channel, bool& enabled,
502 webrtc::AgcModes& mode));
503 WEBRTC_STUB(SetRxAgcConfig, (int channel, webrtc::AgcConfig config));
504 WEBRTC_STUB(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505
506 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
507 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
508 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
509 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
510 ec_metrics_enabled_ = enable;
511 return 0;
512 }
solenberg85a04962015-10-27 03:35:21 -0700513 WEBRTC_STUB(GetEcMetricsStatus, (bool& enabled));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +0000515 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
516 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000517
518 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000519 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 WEBRTC_STUB(StopDebugRecording, ());
521
522 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
523 typing_detection_enabled_ = enable;
524 return 0;
525 }
526 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
527 enabled = typing_detection_enabled_;
528 return 0;
529 }
530
531 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
532 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
533 int costPerTyping,
534 int reportingThreshold,
535 int penaltyDecay,
536 int typeEventDelay));
nisseef8b61e2016-04-29 06:09:15 -0700537 int EnableHighPassFilter(bool enable) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 highpass_filter_enabled_ = enable;
539 return 0;
540 }
nisseef8b61e2016-04-29 06:09:15 -0700541 bool IsHighPassFilterEnabled() override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542 return highpass_filter_enabled_;
543 }
nisseef8b61e2016-04-29 06:09:15 -0700544 bool IsStereoChannelSwappingEnabled() override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 return stereo_swapping_enabled_;
546 }
nisseef8b61e2016-04-29 06:09:15 -0700547 void EnableStereoChannelSwapping(bool enable) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548 stereo_swapping_enabled_ = enable;
549 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200550 int GetNetEqCapacity() const {
551 auto ch = channels_.find(last_channel_);
552 ASSERT(ch != channels_.end());
553 return ch->second->neteq_capacity;
554 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200555 bool GetNetEqFastAccelerate() const {
556 auto ch = channels_.find(last_channel_);
557 ASSERT(ch != channels_.end());
558 return ch->second->neteq_fast_accelerate;
559 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560
561 private:
solenbergbc37fc82016-04-04 09:54:44 -0700562 bool inited_ = false;
563 int last_channel_ = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 std::map<int, Channel*> channels_;
solenbergbc37fc82016-04-04 09:54:44 -0700565 bool fail_create_channel_ = false;
566 int num_set_send_codecs_ = 0; // how many times we call SetSendCodec().
567 bool ec_enabled_ = false;
568 bool ec_metrics_enabled_ = false;
569 bool cng_enabled_ = false;
570 bool ns_enabled_ = false;
571 bool agc_enabled_ = false;
572 bool highpass_filter_enabled_ = false;
573 bool stereo_swapping_enabled_ = false;
574 bool typing_detection_enabled_ = false;
575 webrtc::EcModes ec_mode_ = webrtc::kEcDefault;
576 webrtc::AecmModes aecm_mode_ = webrtc::kAecmSpeakerphone;
577 webrtc::NsModes ns_mode_ = webrtc::kNsDefault;
578 webrtc::AgcModes agc_mode_ = webrtc::kAgcDefault;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 webrtc::AgcConfig agc_config_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000580 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581};
582
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583} // namespace cricket
584
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +0100585#endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_