blob: 8d15f5249e0bbf3c4c0049b0d6a24c3736323f23 [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/gunit.h"
21#include "webrtc/base/stringutils.h"
Henrik Lundin64dad832015-05-11 12:44:23 +020022#include "webrtc/config.h"
kjellandera96e2d72016-02-04 23:52:28 -080023#include "webrtc/media/base/codec.h"
24#include "webrtc/media/base/rtputils.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010025#include "webrtc/media/engine/fakewebrtccommon.h"
26#include "webrtc/media/engine/webrtcvoe.h"
solenberg26c8c912015-11-27 04:00:25 -080027#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000028#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000029
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030namespace cricket {
31
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000032static const int kOpusBandwidthNb = 4000;
33static const int kOpusBandwidthMb = 6000;
34static const int kOpusBandwidthWb = 8000;
35static const int kOpusBandwidthSwb = 12000;
36static const int kOpusBandwidthFb = 20000;
37
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020038#define WEBRTC_CHECK_CHANNEL(channel) \
39 if (channels_.find(channel) == channels_.end()) return -1;
40
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000041class FakeAudioProcessing : public webrtc::AudioProcessing {
42 public:
43 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
44
45 WEBRTC_STUB(Initialize, ())
46 WEBRTC_STUB(Initialize, (
47 int input_sample_rate_hz,
48 int output_sample_rate_hz,
49 int reverse_sample_rate_hz,
50 webrtc::AudioProcessing::ChannelLayout input_layout,
51 webrtc::AudioProcessing::ChannelLayout output_layout,
52 webrtc::AudioProcessing::ChannelLayout reverse_layout));
Michael Graczyk86c6d332015-07-23 11:41:39 -070053 WEBRTC_STUB(Initialize, (
54 const webrtc::ProcessingConfig& processing_config));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000055
56 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
57 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
58 }
59
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000060 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
61 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
Peter Kasting69558702016-01-12 16:26:35 -080062 size_t num_input_channels() const override { return 0; }
63 size_t num_proc_channels() const override { return 0; }
64 size_t num_output_channels() const override { return 0; }
65 size_t num_reverse_channels() const override { return 0; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000066 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000067 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
68 WEBRTC_STUB(ProcessStream, (
69 const float* const* src,
Peter Kastingdce40cf2015-08-24 14:52:23 -070070 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000071 int input_sample_rate_hz,
72 webrtc::AudioProcessing::ChannelLayout input_layout,
73 int output_sample_rate_hz,
74 webrtc::AudioProcessing::ChannelLayout output_layout,
75 float* const* dest));
Michael Graczyk86c6d332015-07-23 11:41:39 -070076 WEBRTC_STUB(ProcessStream,
77 (const float* const* src,
78 const webrtc::StreamConfig& input_config,
79 const webrtc::StreamConfig& output_config,
80 float* const* dest));
ekmeyerson60d9b332015-08-14 10:35:55 -070081 WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000082 WEBRTC_STUB(AnalyzeReverseStream, (
83 const float* const* data,
Peter Kastingdce40cf2015-08-24 14:52:23 -070084 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000085 int sample_rate_hz,
86 webrtc::AudioProcessing::ChannelLayout layout));
ekmeyerson60d9b332015-08-14 10:35:55 -070087 WEBRTC_STUB(ProcessReverseStream,
88 (const float* const* src,
89 const webrtc::StreamConfig& reverse_input_config,
90 const webrtc::StreamConfig& reverse_output_config,
91 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000092 WEBRTC_STUB(set_stream_delay_ms, (int delay));
93 WEBRTC_STUB_CONST(stream_delay_ms, ());
94 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
95 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000096 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
97 WEBRTC_STUB_CONST(delay_offset_ms, ());
ivocd66b44d2016-01-15 03:06:36 -080098 WEBRTC_STUB(StartDebugRecording,
99 (const char filename[kMaxFilenameSize], int64_t max_size_bytes));
100 WEBRTC_STUB(StartDebugRecording, (FILE * handle, int64_t max_size_bytes));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000101 WEBRTC_STUB(StopDebugRecording, ());
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200102 WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000103 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
104 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000105 return NULL;
106 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000107 webrtc::GainControl* gain_control() const override { return NULL; }
108 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
109 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
110 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
111 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000112
113 bool experimental_ns_enabled() {
114 return experimental_ns_enabled_;
115 }
116
117 private:
118 bool experimental_ns_enabled_;
119};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121class FakeWebRtcVoiceEngine
122 : public webrtc::VoEAudioProcessing,
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100123 public webrtc::VoEBase, public webrtc::VoECodec,
solenberg4a0f7b52016-06-16 13:07:33 -0700124 public webrtc::VoEHardware,
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200125 public webrtc::VoEVolumeControl {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 struct Channel {
solenbergbc37fc82016-04-04 09:54:44 -0700128 Channel() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129 memset(&send_codec, 0, sizeof(send_codec));
130 }
solenbergbc37fc82016-04-04 09:54:44 -0700131 bool playout = false;
132 float volume_scale = 1.0f;
133 bool vad = false;
134 bool codec_fec = false;
135 int max_encoding_bandwidth = 0;
136 bool opus_dtx = false;
solenbergbc37fc82016-04-04 09:54:44 -0700137 int cn8_type = 13;
138 int cn16_type = 105;
solenbergbc37fc82016-04-04 09:54:44 -0700139 int associate_send_channel = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 std::vector<webrtc::CodecInst> recv_codecs;
141 webrtc::CodecInst send_codec;
solenbergbc37fc82016-04-04 09:54:44 -0700142 int neteq_capacity = -1;
143 bool neteq_fast_accelerate = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 };
145
solenbergbc37fc82016-04-04 09:54:44 -0700146 FakeWebRtcVoiceEngine() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 memset(&agc_config_, 0, sizeof(agc_config_));
148 }
solenbergff976312016-03-30 23:28:51 -0700149 ~FakeWebRtcVoiceEngine() override {
solenberg26c8c912015-11-27 04:00:25 -0800150 RTC_CHECK(channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 }
152
solenberg85a04962015-10-27 03:35:21 -0700153 bool ec_metrics_enabled() const { return ec_metrics_enabled_; }
154
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 bool IsInited() const { return inited_; }
156 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000157 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 bool GetPlayout(int channel) {
159 return channels_[channel]->playout;
160 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 bool GetVAD(int channel) {
162 return channels_[channel]->vad;
163 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100164 bool GetOpusDtx(int channel) {
165 return channels_[channel]->opus_dtx;
166 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000167 bool GetCodecFEC(int channel) {
168 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000170 int GetMaxEncodingBandwidth(int channel) {
171 return channels_[channel]->max_encoding_bandwidth;
172 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 int GetSendCNPayloadType(int channel, bool wideband) {
174 return (wideband) ?
175 channels_[channel]->cn16_type :
176 channels_[channel]->cn8_type;
177 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 void set_playout_fail_channel(int channel) {
179 playout_fail_channel_ = channel;
180 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 void set_fail_create_channel(bool fail_create_channel) {
182 fail_create_channel_ = fail_create_channel;
183 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200184 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000185 if (fail_create_channel_) {
186 return -1;
187 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000188 Channel* ch = new Channel();
solenberg26c8c912015-11-27 04:00:25 -0800189 auto db = webrtc::acm2::RentACodec::Database();
190 ch->recv_codecs.assign(db.begin(), db.end());
Henrik Lundin64dad832015-05-11 12:44:23 +0200191 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
192 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
193 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200194 ch->neteq_fast_accelerate =
195 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000196 channels_[++last_channel_] = ch;
197 return last_channel_;
198 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000200 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
201
Minyue2013aec2015-05-13 14:14:42 +0200202 int GetAssociateSendChannel(int channel) {
203 return channels_[channel]->associate_send_channel;
204 }
205
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 WEBRTC_STUB(Release, ());
207
208 // webrtc::VoEBase
solenbergbc37fc82016-04-04 09:54:44 -0700209 WEBRTC_STUB(RegisterVoiceEngineObserver, (
210 webrtc::VoiceEngineObserver& observer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
ossu5f7cfa52016-05-30 08:11:28 -0700212 WEBRTC_FUNC(Init,
213 (webrtc::AudioDeviceModule* adm,
214 webrtc::AudioProcessing* audioproc,
215 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>&
216 decoder_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 inited_ = true;
218 return 0;
219 }
220 WEBRTC_FUNC(Terminate, ()) {
221 inited_ = false;
222 return 0;
223 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000224 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000225 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 }
solenbergff976312016-03-30 23:28:51 -0700227 webrtc::AudioDeviceModule* audio_device_module() override {
solenbergbc37fc82016-04-04 09:54:44 -0700228 return nullptr;
solenbergff976312016-03-30 23:28:51 -0700229 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200231 webrtc::Config empty_config;
232 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200234 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
235 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000236 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 WEBRTC_FUNC(DeleteChannel, (int channel)) {
238 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200239 for (const auto& ch : channels_) {
240 if (ch.second->associate_send_channel == channel) {
241 ch.second->associate_send_channel = -1;
242 }
243 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 delete channels_[channel];
245 channels_.erase(channel);
246 return 0;
247 }
248 WEBRTC_STUB(StartReceive, (int channel));
249 WEBRTC_FUNC(StartPlayout, (int channel)) {
250 if (playout_fail_channel_ != channel) {
251 WEBRTC_CHECK_CHANNEL(channel);
252 channels_[channel]->playout = true;
253 return 0;
254 } else {
255 // When playout_fail_channel_ == channel, fail the StartPlayout on this
256 // channel.
257 return -1;
258 }
259 }
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800260 WEBRTC_STUB(StartSend, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 WEBRTC_STUB(StopReceive, (int channel));
262 WEBRTC_FUNC(StopPlayout, (int channel)) {
263 WEBRTC_CHECK_CHANNEL(channel);
264 channels_[channel]->playout = false;
265 return 0;
266 }
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800267 WEBRTC_STUB(StopSend, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 WEBRTC_STUB(GetVersion, (char version[1024]));
269 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200270 WEBRTC_FUNC(AssociateSendChannel, (int channel,
271 int accociate_send_channel)) {
272 WEBRTC_CHECK_CHANNEL(channel);
273 channels_[channel]->associate_send_channel = accociate_send_channel;
274 return 0;
275 }
nisseef8b61e2016-04-29 06:09:15 -0700276 webrtc::RtcEventLog* GetEventLog() override { return nullptr; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277
278 // webrtc::VoECodec
solenberg26c8c912015-11-27 04:00:25 -0800279 WEBRTC_STUB(NumOfCodecs, ());
280 WEBRTC_STUB(GetCodec, (int index, webrtc::CodecInst& codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
282 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000283 // To match the behavior of the real implementation.
284 if (_stricmp(codec.plname, "telephone-event") == 0 ||
285 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
286 _stricmp(codec.plname, "CN") == 0 ||
kwiberg68061362016-06-14 08:04:47 -0700287 _stricmp(codec.plname, "red") == 0) {
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000288 return -1;
289 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000291 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 return 0;
293 }
294 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
295 WEBRTC_CHECK_CHANNEL(channel);
296 codec = channels_[channel]->send_codec;
297 return 0;
298 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200299 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200300 WEBRTC_STUB(GetRecCodec, (int channel, webrtc::CodecInst& codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 WEBRTC_FUNC(SetRecPayloadType, (int channel,
302 const webrtc::CodecInst& codec)) {
303 WEBRTC_CHECK_CHANNEL(channel);
304 Channel* ch = channels_[channel];
305 if (ch->playout)
306 return -1; // Channel is in use.
307 // Check if something else already has this slot.
308 if (codec.pltype != -1) {
309 for (std::vector<webrtc::CodecInst>::iterator it =
310 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
311 if (it->pltype == codec.pltype &&
312 _stricmp(it->plname, codec.plname) != 0) {
313 return -1;
314 }
315 }
316 }
317 // Otherwise try to find this codec and update its payload type.
solenberg26c8c912015-11-27 04:00:25 -0800318 int result = -1; // not found
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
320 it != ch->recv_codecs.end(); ++it) {
321 if (strcmp(it->plname, codec.plname) == 0 &&
solenberg26c8c912015-11-27 04:00:25 -0800322 it->plfreq == codec.plfreq &&
323 it->channels == codec.channels) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 it->pltype = codec.pltype;
solenberg26c8c912015-11-27 04:00:25 -0800325 result = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 }
327 }
solenberg26c8c912015-11-27 04:00:25 -0800328 return result;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 }
330 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
331 webrtc::PayloadFrequencies frequency)) {
332 WEBRTC_CHECK_CHANNEL(channel);
333 if (frequency == webrtc::kFreq8000Hz) {
334 channels_[channel]->cn8_type = type;
335 } else if (frequency == webrtc::kFreq16000Hz) {
336 channels_[channel]->cn16_type = type;
337 }
338 return 0;
339 }
340 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
341 WEBRTC_CHECK_CHANNEL(channel);
342 Channel* ch = channels_[channel];
343 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
344 it != ch->recv_codecs.end(); ++it) {
345 if (strcmp(it->plname, codec.plname) == 0 &&
346 it->plfreq == codec.plfreq &&
347 it->channels == codec.channels &&
348 it->pltype != -1) {
349 codec.pltype = it->pltype;
350 return 0;
351 }
352 }
353 return -1; // not found
354 }
355 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
356 bool disableDTX)) {
357 WEBRTC_CHECK_CHANNEL(channel);
358 if (channels_[channel]->send_codec.channels == 2) {
359 // Replicating VoE behavior; VAD cannot be enabled for stereo.
360 return -1;
361 }
362 channels_[channel]->vad = enable;
363 return 0;
364 }
365 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
366 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000367
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000368 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
369 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000370 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000371 // Return -1 if current send codec is not Opus.
372 // TODO(minyue): Excludes other codecs if they support inband FEC.
373 return -1;
374 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000375 channels_[channel]->codec_fec = enable;
376 return 0;
377 }
378 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
379 WEBRTC_CHECK_CHANNEL(channel);
380 enable = channels_[channel]->codec_fec;
381 return 0;
382 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000383
384 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
385 WEBRTC_CHECK_CHANNEL(channel);
386 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
387 // Return -1 if current send codec is not Opus.
388 return -1;
389 }
390 if (frequency_hz <= 8000)
391 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
392 else if (frequency_hz <= 12000)
393 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
394 else if (frequency_hz <= 16000)
395 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
396 else if (frequency_hz <= 24000)
397 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
398 else
399 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
400 return 0;
401 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000403 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
404 WEBRTC_CHECK_CHANNEL(channel);
405 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
406 // Return -1 if current send codec is not Opus.
407 return -1;
408 }
409 channels_[channel]->opus_dtx = enable_dtx;
410 return 0;
411 }
412
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413 // webrtc::VoEHardware
solenberg246b8172015-12-08 09:50:23 -0800414 WEBRTC_STUB(GetNumOfRecordingDevices, (int& num));
415 WEBRTC_STUB(GetNumOfPlayoutDevices, (int& num));
416 WEBRTC_STUB(GetRecordingDeviceName, (int i, char* name, char* guid));
417 WEBRTC_STUB(GetPlayoutDeviceName, (int i, char* name, char* guid));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
419 WEBRTC_STUB(SetPlayoutDevice, (int));
420 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
421 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
solenberg5b5129a2016-04-08 05:35:48 -0700422 WEBRTC_STUB(SetRecordingSampleRate, (unsigned int samples_per_sec));
423 WEBRTC_STUB_CONST(RecordingSampleRate, (unsigned int* samples_per_sec));
424 WEBRTC_STUB(SetPlayoutSampleRate, (unsigned int samples_per_sec));
425 WEBRTC_STUB_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
nisseef8b61e2016-04-29 06:09:15 -0700427 bool BuiltInAECIsAvailable() const override { return false; }
henrikac14f5ff2015-09-23 14:08:33 +0200428 WEBRTC_STUB(EnableBuiltInAGC, (bool enable));
nisseef8b61e2016-04-29 06:09:15 -0700429 bool BuiltInAGCIsAvailable() const override { return false; }
henrikac14f5ff2015-09-23 14:08:33 +0200430 WEBRTC_STUB(EnableBuiltInNS, (bool enable));
nisseef8b61e2016-04-29 06:09:15 -0700431 bool BuiltInNSIsAvailable() const override { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433 // webrtc::VoEVolumeControl
434 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
435 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436 WEBRTC_STUB(SetMicVolume, (unsigned int));
437 WEBRTC_STUB(GetMicVolume, (unsigned int&));
438 WEBRTC_STUB(SetInputMute, (int, bool));
439 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
441 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
442 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
443 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
444 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
445 WEBRTC_CHECK_CHANNEL(channel);
446 channels_[channel]->volume_scale= scale;
447 return 0;
448 }
449 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
450 WEBRTC_CHECK_CHANNEL(channel);
451 scale = channels_[channel]->volume_scale;
452 return 0;
453 }
solenberg4bac9c52015-10-09 02:32:53 -0700454 WEBRTC_STUB(SetOutputVolumePan, (int channel, float left, float right));
455 WEBRTC_STUB(GetOutputVolumePan, (int channel, float& left, float& right));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456
457 // webrtc::VoEAudioProcessing
458 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
459 ns_enabled_ = enable;
460 ns_mode_ = mode;
461 return 0;
462 }
463 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
464 enabled = ns_enabled_;
465 mode = ns_mode_;
466 return 0;
467 }
468
469 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
470 agc_enabled_ = enable;
471 agc_mode_ = mode;
472 return 0;
473 }
474 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
475 enabled = agc_enabled_;
476 mode = agc_mode_;
477 return 0;
478 }
479
480 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
481 agc_config_ = config;
482 return 0;
483 }
484 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
485 config = agc_config_;
486 return 0;
487 }
488 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
489 ec_enabled_ = enable;
490 ec_mode_ = mode;
491 return 0;
492 }
493 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
494 enabled = ec_enabled_;
495 mode = ec_mode_;
496 return 0;
497 }
498 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
499 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
500 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
501 WEBRTC_STUB(DelayOffsetMs, ());
502 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
503 aecm_mode_ = mode;
504 cng_enabled_ = enableCNG;
505 return 0;
506 }
507 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
508 mode = aecm_mode_;
509 enabledCNG = cng_enabled_;
510 return 0;
511 }
512 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
513 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
514 webrtc::NsModes& mode));
solenberg0b675462015-10-09 01:37:09 -0700515 WEBRTC_STUB(SetRxAgcStatus, (int channel, bool enable,
516 webrtc::AgcModes mode));
517 WEBRTC_STUB(GetRxAgcStatus, (int channel, bool& enabled,
518 webrtc::AgcModes& mode));
519 WEBRTC_STUB(SetRxAgcConfig, (int channel, webrtc::AgcConfig config));
520 WEBRTC_STUB(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521
522 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
523 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
524 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
525 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
526 ec_metrics_enabled_ = enable;
527 return 0;
528 }
solenberg85a04962015-10-27 03:35:21 -0700529 WEBRTC_STUB(GetEcMetricsStatus, (bool& enabled));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +0000531 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
532 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533
534 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000535 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 WEBRTC_STUB(StopDebugRecording, ());
537
538 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
539 typing_detection_enabled_ = enable;
540 return 0;
541 }
542 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
543 enabled = typing_detection_enabled_;
544 return 0;
545 }
546
547 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
548 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
549 int costPerTyping,
550 int reportingThreshold,
551 int penaltyDecay,
552 int typeEventDelay));
nisseef8b61e2016-04-29 06:09:15 -0700553 int EnableHighPassFilter(bool enable) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 highpass_filter_enabled_ = enable;
555 return 0;
556 }
nisseef8b61e2016-04-29 06:09:15 -0700557 bool IsHighPassFilterEnabled() override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 return highpass_filter_enabled_;
559 }
nisseef8b61e2016-04-29 06:09:15 -0700560 bool IsStereoChannelSwappingEnabled() override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 return stereo_swapping_enabled_;
562 }
nisseef8b61e2016-04-29 06:09:15 -0700563 void EnableStereoChannelSwapping(bool enable) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 stereo_swapping_enabled_ = enable;
565 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200566 int GetNetEqCapacity() const {
567 auto ch = channels_.find(last_channel_);
568 ASSERT(ch != channels_.end());
569 return ch->second->neteq_capacity;
570 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200571 bool GetNetEqFastAccelerate() const {
572 auto ch = channels_.find(last_channel_);
573 ASSERT(ch != channels_.end());
574 return ch->second->neteq_fast_accelerate;
575 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576
577 private:
solenbergbc37fc82016-04-04 09:54:44 -0700578 bool inited_ = false;
579 int last_channel_ = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 std::map<int, Channel*> channels_;
solenbergbc37fc82016-04-04 09:54:44 -0700581 bool fail_create_channel_ = false;
582 int num_set_send_codecs_ = 0; // how many times we call SetSendCodec().
583 bool ec_enabled_ = false;
584 bool ec_metrics_enabled_ = false;
585 bool cng_enabled_ = false;
586 bool ns_enabled_ = false;
587 bool agc_enabled_ = false;
588 bool highpass_filter_enabled_ = false;
589 bool stereo_swapping_enabled_ = false;
590 bool typing_detection_enabled_ = false;
591 webrtc::EcModes ec_mode_ = webrtc::kEcDefault;
592 webrtc::AecmModes aecm_mode_ = webrtc::kAecmSpeakerphone;
593 webrtc::NsModes ns_mode_ = webrtc::kNsDefault;
594 webrtc::AgcModes agc_mode_ = webrtc::kAgcDefault;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 webrtc::AgcConfig agc_config_;
solenbergbc37fc82016-04-04 09:54:44 -0700596 int playout_fail_channel_ = -1;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000597 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598};
599
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600} // namespace cricket
601
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +0100602#endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_