blob: 6ca334169cc0184f42afd18a5348f16f0990f14a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2010 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_
29#define TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_
30
31#include <list>
32#include <map>
33#include <vector>
34
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/codec.h"
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +000036#include "talk/media/base/rtputils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/media/webrtc/fakewebrtccommon.h"
38#include "talk/media/webrtc/webrtcvoe.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "webrtc/base/basictypes.h"
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020040#include "webrtc/base/checks.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000041#include "webrtc/base/gunit.h"
42#include "webrtc/base/stringutils.h"
Henrik Lundin64dad832015-05-11 12:44:23 +020043#include "webrtc/config.h"
solenberg26c8c912015-11-27 04:00:25 -080044#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000045#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000046
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047namespace cricket {
48
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049static const char kFakeDefaultDeviceName[] = "Fake Default";
50static const int kFakeDefaultDeviceId = -1;
51static const char kFakeDeviceName[] = "Fake Device";
52#ifdef WIN32
53static const int kFakeDeviceId = 0;
54#else
55static const int kFakeDeviceId = 1;
56#endif
57
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000058static const int kOpusBandwidthNb = 4000;
59static const int kOpusBandwidthMb = 6000;
60static const int kOpusBandwidthWb = 8000;
61static const int kOpusBandwidthSwb = 12000;
62static const int kOpusBandwidthFb = 20000;
63
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020064#define WEBRTC_CHECK_CHANNEL(channel) \
65 if (channels_.find(channel) == channels_.end()) return -1;
66
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000067class FakeAudioProcessing : public webrtc::AudioProcessing {
68 public:
69 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
70
71 WEBRTC_STUB(Initialize, ())
72 WEBRTC_STUB(Initialize, (
73 int input_sample_rate_hz,
74 int output_sample_rate_hz,
75 int reverse_sample_rate_hz,
76 webrtc::AudioProcessing::ChannelLayout input_layout,
77 webrtc::AudioProcessing::ChannelLayout output_layout,
78 webrtc::AudioProcessing::ChannelLayout reverse_layout));
Michael Graczyk86c6d332015-07-23 11:41:39 -070079 WEBRTC_STUB(Initialize, (
80 const webrtc::ProcessingConfig& processing_config));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000081
82 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
83 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
84 }
85
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000086 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
87 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
88 WEBRTC_STUB_CONST(num_input_channels, ());
89 WEBRTC_STUB_CONST(num_output_channels, ());
90 WEBRTC_STUB_CONST(num_reverse_channels, ());
91 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000092 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
93 WEBRTC_STUB(ProcessStream, (
94 const float* const* src,
Peter Kastingdce40cf2015-08-24 14:52:23 -070095 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000096 int input_sample_rate_hz,
97 webrtc::AudioProcessing::ChannelLayout input_layout,
98 int output_sample_rate_hz,
99 webrtc::AudioProcessing::ChannelLayout output_layout,
100 float* const* dest));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700101 WEBRTC_STUB(ProcessStream,
102 (const float* const* src,
103 const webrtc::StreamConfig& input_config,
104 const webrtc::StreamConfig& output_config,
105 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000106 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
ekmeyerson60d9b332015-08-14 10:35:55 -0700107 WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000108 WEBRTC_STUB(AnalyzeReverseStream, (
109 const float* const* data,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700110 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000111 int sample_rate_hz,
112 webrtc::AudioProcessing::ChannelLayout layout));
ekmeyerson60d9b332015-08-14 10:35:55 -0700113 WEBRTC_STUB(ProcessReverseStream,
114 (const float* const* src,
115 const webrtc::StreamConfig& reverse_input_config,
116 const webrtc::StreamConfig& reverse_output_config,
117 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000118 WEBRTC_STUB(set_stream_delay_ms, (int delay));
119 WEBRTC_STUB_CONST(stream_delay_ms, ());
120 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
121 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000122 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
123 WEBRTC_STUB_CONST(delay_offset_ms, ());
124 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
125 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
126 WEBRTC_STUB(StopDebugRecording, ());
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200127 WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000128 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
129 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000130 return NULL;
131 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000132 webrtc::GainControl* gain_control() const override { return NULL; }
133 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
134 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
135 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
136 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000137
138 bool experimental_ns_enabled() {
139 return experimental_ns_enabled_;
140 }
141
142 private:
143 bool experimental_ns_enabled_;
144};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000145
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146class FakeWebRtcVoiceEngine
147 : public webrtc::VoEAudioProcessing,
148 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200149 public webrtc::VoEHardware,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200151 public webrtc::VoEVolumeControl {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 public:
153 struct DtmfInfo {
154 DtmfInfo()
155 : dtmf_event_code(-1),
156 dtmf_out_of_band(false),
157 dtmf_length_ms(-1) {}
158 int dtmf_event_code;
159 bool dtmf_out_of_band;
160 int dtmf_length_ms;
161 };
162 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000163 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 : external_transport(false),
165 send(false),
166 playout(false),
167 volume_scale(1.0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000169 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000170 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000171 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000172 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 nack(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 cn8_type(13),
175 cn16_type(105),
176 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000177 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 nack_max_packets(0),
179 send_ssrc(0),
Minyue2013aec2015-05-13 14:14:42 +0200180 associate_send_channel(-1),
solenberg26c8c912015-11-27 04:00:25 -0800181 recv_codecs(),
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200182 neteq_capacity(-1),
183 neteq_fast_accelerate(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 memset(&send_codec, 0, sizeof(send_codec));
185 }
186 bool external_transport;
187 bool send;
188 bool playout;
189 float volume_scale;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000191 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000192 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000193 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000194 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 bool nack;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 int cn8_type;
197 int cn16_type;
198 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000199 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 int nack_max_packets;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200201 uint32_t send_ssrc;
Minyue2013aec2015-05-13 14:14:42 +0200202 int associate_send_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 DtmfInfo dtmf_info;
204 std::vector<webrtc::CodecInst> recv_codecs;
205 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000206 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 std::list<std::string> packets;
Henrik Lundin64dad832015-05-11 12:44:23 +0200208 int neteq_capacity;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200209 bool neteq_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 };
211
solenberg26c8c912015-11-27 04:00:25 -0800212 FakeWebRtcVoiceEngine()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 : inited_(false),
214 last_channel_(-1),
215 fail_create_channel_(false),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000216 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 ec_enabled_(false),
218 ec_metrics_enabled_(false),
219 cng_enabled_(false),
220 ns_enabled_(false),
221 agc_enabled_(false),
222 highpass_filter_enabled_(false),
223 stereo_swapping_enabled_(false),
224 typing_detection_enabled_(false),
225 ec_mode_(webrtc::kEcDefault),
226 aecm_mode_(webrtc::kAecmSpeakerphone),
227 ns_mode_(webrtc::kNsDefault),
228 agc_mode_(webrtc::kAgcDefault),
229 observer_(NULL),
230 playout_fail_channel_(-1),
231 send_fail_channel_(-1),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000232 recording_sample_rate_(-1),
Fredrik Solenberg7d173362015-09-23 12:23:21 +0200233 playout_sample_rate_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 memset(&agc_config_, 0, sizeof(agc_config_));
235 }
236 ~FakeWebRtcVoiceEngine() {
solenberg26c8c912015-11-27 04:00:25 -0800237 RTC_CHECK(channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 }
239
solenberg85a04962015-10-27 03:35:21 -0700240 bool ec_metrics_enabled() const { return ec_metrics_enabled_; }
241
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 bool IsInited() const { return inited_; }
243 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000244 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
solenberg85a04962015-10-27 03:35:21 -0700245 uint32_t GetLocalSSRC(int channel) {
246 return channels_[channel]->send_ssrc;
247 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 bool GetPlayout(int channel) {
249 return channels_[channel]->playout;
250 }
251 bool GetSend(int channel) {
252 return channels_[channel]->send;
253 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 bool GetVAD(int channel) {
255 return channels_[channel]->vad;
256 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100257 bool GetOpusDtx(int channel) {
258 return channels_[channel]->opus_dtx;
259 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000260 bool GetRED(int channel) {
261 return channels_[channel]->red;
262 }
263 bool GetCodecFEC(int channel) {
264 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000266 int GetMaxEncodingBandwidth(int channel) {
267 return channels_[channel]->max_encoding_bandwidth;
268 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 bool GetNACK(int channel) {
270 return channels_[channel]->nack;
271 }
272 int GetNACKMaxPackets(int channel) {
273 return channels_[channel]->nack_max_packets;
274 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000275 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
solenberg26c8c912015-11-27 04:00:25 -0800276 RTC_DCHECK(channels_.find(channel) != channels_.end());
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000277 return channels_[channel]->last_rtp_packet_time;
278 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 int GetSendCNPayloadType(int channel, bool wideband) {
280 return (wideband) ?
281 channels_[channel]->cn16_type :
282 channels_[channel]->cn8_type;
283 }
284 int GetSendTelephoneEventPayloadType(int channel) {
285 return channels_[channel]->dtmf_type;
286 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000287 int GetSendREDPayloadType(int channel) {
288 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 }
290 bool CheckPacket(int channel, const void* data, size_t len) {
291 bool result = !CheckNoPacket(channel);
292 if (result) {
293 std::string packet = channels_[channel]->packets.front();
294 result = (packet == std::string(static_cast<const char*>(data), len));
295 channels_[channel]->packets.pop_front();
296 }
297 return result;
298 }
299 bool CheckNoPacket(int channel) {
300 return channels_[channel]->packets.empty();
301 }
302 void TriggerCallbackOnError(int channel_num, int err_code) {
henrikg91d6ede2015-09-17 00:24:34 -0700303 RTC_DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 observer_->CallbackOnError(channel_num, err_code);
305 }
306 void set_playout_fail_channel(int channel) {
307 playout_fail_channel_ = channel;
308 }
309 void set_send_fail_channel(int channel) {
310 send_fail_channel_ = channel;
311 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 void set_fail_create_channel(bool fail_create_channel) {
313 fail_create_channel_ = fail_create_channel;
314 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200315 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000316 if (fail_create_channel_) {
317 return -1;
318 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000319 Channel* ch = new Channel();
solenberg26c8c912015-11-27 04:00:25 -0800320 auto db = webrtc::acm2::RentACodec::Database();
321 ch->recv_codecs.assign(db.begin(), db.end());
Henrik Lundin64dad832015-05-11 12:44:23 +0200322 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
323 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
324 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200325 ch->neteq_fast_accelerate =
326 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000327 channels_[++last_channel_] = ch;
328 return last_channel_;
329 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000331 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
332
Minyue2013aec2015-05-13 14:14:42 +0200333 int GetAssociateSendChannel(int channel) {
334 return channels_[channel]->associate_send_channel;
335 }
336
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 WEBRTC_STUB(Release, ());
338
339 // webrtc::VoEBase
340 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
341 webrtc::VoiceEngineObserver& observer)) {
342 observer_ = &observer;
343 return 0;
344 }
345 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
346 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
347 webrtc::AudioProcessing* audioproc)) {
348 inited_ = true;
349 return 0;
350 }
351 WEBRTC_FUNC(Terminate, ()) {
352 inited_ = false;
353 return 0;
354 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000355 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000356 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200359 webrtc::Config empty_config;
360 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200362 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
363 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000364 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 WEBRTC_FUNC(DeleteChannel, (int channel)) {
366 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200367 for (const auto& ch : channels_) {
368 if (ch.second->associate_send_channel == channel) {
369 ch.second->associate_send_channel = -1;
370 }
371 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 delete channels_[channel];
373 channels_.erase(channel);
374 return 0;
375 }
376 WEBRTC_STUB(StartReceive, (int channel));
377 WEBRTC_FUNC(StartPlayout, (int channel)) {
378 if (playout_fail_channel_ != channel) {
379 WEBRTC_CHECK_CHANNEL(channel);
380 channels_[channel]->playout = true;
381 return 0;
382 } else {
383 // When playout_fail_channel_ == channel, fail the StartPlayout on this
384 // channel.
385 return -1;
386 }
387 }
388 WEBRTC_FUNC(StartSend, (int channel)) {
389 if (send_fail_channel_ != channel) {
390 WEBRTC_CHECK_CHANNEL(channel);
391 channels_[channel]->send = true;
392 return 0;
393 } else {
394 // When send_fail_channel_ == channel, fail the StartSend on this
395 // channel.
396 return -1;
397 }
398 }
399 WEBRTC_STUB(StopReceive, (int channel));
400 WEBRTC_FUNC(StopPlayout, (int channel)) {
401 WEBRTC_CHECK_CHANNEL(channel);
402 channels_[channel]->playout = false;
403 return 0;
404 }
405 WEBRTC_FUNC(StopSend, (int channel)) {
406 WEBRTC_CHECK_CHANNEL(channel);
407 channels_[channel]->send = false;
408 return 0;
409 }
410 WEBRTC_STUB(GetVersion, (char version[1024]));
411 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200412 WEBRTC_FUNC(AssociateSendChannel, (int channel,
413 int accociate_send_channel)) {
414 WEBRTC_CHECK_CHANNEL(channel);
415 channels_[channel]->associate_send_channel = accociate_send_channel;
416 return 0;
417 }
ivocb04965c2015-09-09 00:09:43 -0700418 webrtc::RtcEventLog* GetEventLog() { return nullptr; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419
420 // webrtc::VoECodec
solenberg26c8c912015-11-27 04:00:25 -0800421 WEBRTC_STUB(NumOfCodecs, ());
422 WEBRTC_STUB(GetCodec, (int index, webrtc::CodecInst& codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
424 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000425 // To match the behavior of the real implementation.
426 if (_stricmp(codec.plname, "telephone-event") == 0 ||
427 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
428 _stricmp(codec.plname, "CN") == 0 ||
429 _stricmp(codec.plname, "red") == 0 ) {
430 return -1;
431 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000433 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 return 0;
435 }
436 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
437 WEBRTC_CHECK_CHANNEL(channel);
438 codec = channels_[channel]->send_codec;
439 return 0;
440 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200441 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200442 WEBRTC_STUB(GetRecCodec, (int channel, webrtc::CodecInst& codec));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 WEBRTC_FUNC(SetRecPayloadType, (int channel,
444 const webrtc::CodecInst& codec)) {
445 WEBRTC_CHECK_CHANNEL(channel);
446 Channel* ch = channels_[channel];
447 if (ch->playout)
448 return -1; // Channel is in use.
449 // Check if something else already has this slot.
450 if (codec.pltype != -1) {
451 for (std::vector<webrtc::CodecInst>::iterator it =
452 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
453 if (it->pltype == codec.pltype &&
454 _stricmp(it->plname, codec.plname) != 0) {
455 return -1;
456 }
457 }
458 }
459 // Otherwise try to find this codec and update its payload type.
solenberg26c8c912015-11-27 04:00:25 -0800460 int result = -1; // not found
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
462 it != ch->recv_codecs.end(); ++it) {
463 if (strcmp(it->plname, codec.plname) == 0 &&
solenberg26c8c912015-11-27 04:00:25 -0800464 it->plfreq == codec.plfreq &&
465 it->channels == codec.channels) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 it->pltype = codec.pltype;
solenberg26c8c912015-11-27 04:00:25 -0800467 result = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 }
469 }
solenberg26c8c912015-11-27 04:00:25 -0800470 return result;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471 }
472 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
473 webrtc::PayloadFrequencies frequency)) {
474 WEBRTC_CHECK_CHANNEL(channel);
475 if (frequency == webrtc::kFreq8000Hz) {
476 channels_[channel]->cn8_type = type;
477 } else if (frequency == webrtc::kFreq16000Hz) {
478 channels_[channel]->cn16_type = type;
479 }
480 return 0;
481 }
482 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
483 WEBRTC_CHECK_CHANNEL(channel);
484 Channel* ch = channels_[channel];
485 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
486 it != ch->recv_codecs.end(); ++it) {
487 if (strcmp(it->plname, codec.plname) == 0 &&
488 it->plfreq == codec.plfreq &&
489 it->channels == codec.channels &&
490 it->pltype != -1) {
491 codec.pltype = it->pltype;
492 return 0;
493 }
494 }
495 return -1; // not found
496 }
497 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
498 bool disableDTX)) {
499 WEBRTC_CHECK_CHANNEL(channel);
500 if (channels_[channel]->send_codec.channels == 2) {
501 // Replicating VoE behavior; VAD cannot be enabled for stereo.
502 return -1;
503 }
504 channels_[channel]->vad = enable;
505 return 0;
506 }
507 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
508 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000509
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000510 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
511 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000512 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000513 // Return -1 if current send codec is not Opus.
514 // TODO(minyue): Excludes other codecs if they support inband FEC.
515 return -1;
516 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000517 channels_[channel]->codec_fec = enable;
518 return 0;
519 }
520 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
521 WEBRTC_CHECK_CHANNEL(channel);
522 enable = channels_[channel]->codec_fec;
523 return 0;
524 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000525
526 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
527 WEBRTC_CHECK_CHANNEL(channel);
528 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
529 // Return -1 if current send codec is not Opus.
530 return -1;
531 }
532 if (frequency_hz <= 8000)
533 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
534 else if (frequency_hz <= 12000)
535 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
536 else if (frequency_hz <= 16000)
537 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
538 else if (frequency_hz <= 24000)
539 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
540 else
541 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
542 return 0;
543 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000545 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
546 WEBRTC_CHECK_CHANNEL(channel);
547 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
548 // Return -1 if current send codec is not Opus.
549 return -1;
550 }
551 channels_[channel]->opus_dtx = enable_dtx;
552 return 0;
553 }
554
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 // webrtc::VoEDtmf
556 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
557 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
558 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
559 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
560 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
561 return 0;
562 }
563
564 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
565 (int channel, unsigned char type)) {
566 channels_[channel]->dtmf_type = type;
567 return 0;
568 };
569 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
570 (int channel, unsigned char& type));
571
572 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
573 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 WEBRTC_FUNC(PlayDtmfTone,
576 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
577 dtmf_info_.dtmf_event_code = event_code;
578 dtmf_info_.dtmf_length_ms = length_ms;
579 return 0;
580 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
584 return GetNumDevices(num);
585 }
586 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
587 return GetNumDevices(num);
588 }
589 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
590 return GetDeviceName(i, name, guid);
591 }
592 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
593 return GetDeviceName(i, name, guid);
594 }
595 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
596 WEBRTC_STUB(SetPlayoutDevice, (int));
597 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
598 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000599 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
600 recording_sample_rate_ = samples_per_sec;
601 return 0;
602 }
603 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
604 *samples_per_sec = recording_sample_rate_;
605 return 0;
606 }
607 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
608 playout_sample_rate_ = samples_per_sec;
609 return 0;
610 }
611 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
612 *samples_per_sec = playout_sample_rate_;
613 return 0;
614 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000615 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000616 virtual bool BuiltInAECIsAvailable() const { return false; }
henrikac14f5ff2015-09-23 14:08:33 +0200617 WEBRTC_STUB(EnableBuiltInAGC, (bool enable));
618 virtual bool BuiltInAGCIsAvailable() const { return false; }
619 WEBRTC_STUB(EnableBuiltInNS, (bool enable));
620 virtual bool BuiltInNSIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 // webrtc::VoENetwork
623 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
624 webrtc::Transport& transport)) {
625 WEBRTC_CHECK_CHANNEL(channel);
626 channels_[channel]->external_transport = true;
627 return 0;
628 }
629 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
630 WEBRTC_CHECK_CHANNEL(channel);
631 channels_[channel]->external_transport = false;
632 return 0;
633 }
634 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000635 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636 WEBRTC_CHECK_CHANNEL(channel);
637 if (!channels_[channel]->external_transport) return -1;
638 channels_[channel]->packets.push_back(
639 std::string(static_cast<const char*>(data), length));
640 return 0;
641 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000642 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000643 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000644 const webrtc::PacketTime& packet_time)) {
645 WEBRTC_CHECK_CHANNEL(channel);
646 if (ReceivedRTPPacket(channel, data, length) == -1) {
647 return -1;
648 }
649 channels_[channel]->last_rtp_packet_time = packet_time;
650 return 0;
651 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000652
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000654 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655
656 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
658 WEBRTC_CHECK_CHANNEL(channel);
659 channels_[channel]->send_ssrc = ssrc;
660 return 0;
661 }
solenberg85a04962015-10-27 03:35:21 -0700662 WEBRTC_STUB(GetLocalSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
solenberg3a941542015-11-16 07:34:50 -0800664 WEBRTC_STUB(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
665 unsigned char id));
solenberg7add0582015-11-20 09:59:34 -0800666 WEBRTC_STUB(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
667 unsigned char id));
solenberg3a941542015-11-16 07:34:50 -0800668 WEBRTC_STUB(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
669 unsigned char id));
solenberg7add0582015-11-20 09:59:34 -0800670 WEBRTC_STUB(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
671 unsigned char id));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
673 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
674 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
675 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
676 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
677 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
678 unsigned int& NTPLow,
679 unsigned int& timestamp,
680 unsigned int& playoutTimestamp,
681 unsigned int* jitter,
682 unsigned short* fractionLost));
solenberg85a04962015-10-27 03:35:21 -0700683 WEBRTC_STUB(GetRemoteRTCPReportBlocks,
684 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
686 unsigned int& maxJitterMs,
687 unsigned int& discardedPackets));
solenberg85a04962015-10-27 03:35:21 -0700688 WEBRTC_STUB(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000689 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000691 channels_[channel]->red = enable;
692 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 return 0;
694 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000695 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000697 enable = channels_[channel]->red;
698 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 return 0;
700 }
701 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
702 WEBRTC_CHECK_CHANNEL(channel);
703 channels_[channel]->nack = enable;
704 channels_[channel]->nack_max_packets = maxNoPackets;
705 return 0;
706 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 // webrtc::VoEVolumeControl
709 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
710 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711 WEBRTC_STUB(SetMicVolume, (unsigned int));
712 WEBRTC_STUB(GetMicVolume, (unsigned int&));
713 WEBRTC_STUB(SetInputMute, (int, bool));
714 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
716 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
717 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
718 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
719 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
720 WEBRTC_CHECK_CHANNEL(channel);
721 channels_[channel]->volume_scale= scale;
722 return 0;
723 }
724 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
725 WEBRTC_CHECK_CHANNEL(channel);
726 scale = channels_[channel]->volume_scale;
727 return 0;
728 }
solenberg4bac9c52015-10-09 02:32:53 -0700729 WEBRTC_STUB(SetOutputVolumePan, (int channel, float left, float right));
730 WEBRTC_STUB(GetOutputVolumePan, (int channel, float& left, float& right));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731
732 // webrtc::VoEAudioProcessing
733 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
734 ns_enabled_ = enable;
735 ns_mode_ = mode;
736 return 0;
737 }
738 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
739 enabled = ns_enabled_;
740 mode = ns_mode_;
741 return 0;
742 }
743
744 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
745 agc_enabled_ = enable;
746 agc_mode_ = mode;
747 return 0;
748 }
749 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
750 enabled = agc_enabled_;
751 mode = agc_mode_;
752 return 0;
753 }
754
755 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
756 agc_config_ = config;
757 return 0;
758 }
759 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
760 config = agc_config_;
761 return 0;
762 }
763 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
764 ec_enabled_ = enable;
765 ec_mode_ = mode;
766 return 0;
767 }
768 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
769 enabled = ec_enabled_;
770 mode = ec_mode_;
771 return 0;
772 }
773 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
774 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
775 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
776 WEBRTC_STUB(DelayOffsetMs, ());
777 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
778 aecm_mode_ = mode;
779 cng_enabled_ = enableCNG;
780 return 0;
781 }
782 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
783 mode = aecm_mode_;
784 enabledCNG = cng_enabled_;
785 return 0;
786 }
787 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
788 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
789 webrtc::NsModes& mode));
solenberg0b675462015-10-09 01:37:09 -0700790 WEBRTC_STUB(SetRxAgcStatus, (int channel, bool enable,
791 webrtc::AgcModes mode));
792 WEBRTC_STUB(GetRxAgcStatus, (int channel, bool& enabled,
793 webrtc::AgcModes& mode));
794 WEBRTC_STUB(SetRxAgcConfig, (int channel, webrtc::AgcConfig config));
795 WEBRTC_STUB(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796
797 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
798 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
799 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
800 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
801 ec_metrics_enabled_ = enable;
802 return 0;
803 }
solenberg85a04962015-10-27 03:35:21 -0700804 WEBRTC_STUB(GetEcMetricsStatus, (bool& enabled));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +0000806 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
807 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808
809 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000810 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 WEBRTC_STUB(StopDebugRecording, ());
812
813 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
814 typing_detection_enabled_ = enable;
815 return 0;
816 }
817 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
818 enabled = typing_detection_enabled_;
819 return 0;
820 }
821
822 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
823 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
824 int costPerTyping,
825 int reportingThreshold,
826 int penaltyDecay,
827 int typeEventDelay));
828 int EnableHighPassFilter(bool enable) {
829 highpass_filter_enabled_ = enable;
830 return 0;
831 }
832 bool IsHighPassFilterEnabled() {
833 return highpass_filter_enabled_;
834 }
835 bool IsStereoChannelSwappingEnabled() {
836 return stereo_swapping_enabled_;
837 }
838 void EnableStereoChannelSwapping(bool enable) {
839 stereo_swapping_enabled_ = enable;
840 }
841 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
842 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
843 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
844 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
845 }
846 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
847 return (dtmf_info_.dtmf_event_code == event_code &&
848 dtmf_info_.dtmf_length_ms == length_ms);
849 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200850 int GetNetEqCapacity() const {
851 auto ch = channels_.find(last_channel_);
852 ASSERT(ch != channels_.end());
853 return ch->second->neteq_capacity;
854 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200855 bool GetNetEqFastAccelerate() const {
856 auto ch = channels_.find(last_channel_);
857 ASSERT(ch != channels_.end());
858 return ch->second->neteq_fast_accelerate;
859 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860
861 private:
862 int GetNumDevices(int& num) {
863#ifdef WIN32
864 num = 1;
865#else
866 // On non-Windows platforms VE adds a special entry for the default device,
867 // so if there is one physical device then there are two entries in the
868 // list.
869 num = 2;
870#endif
871 return 0;
872 }
873
874 int GetDeviceName(int i, char* name, char* guid) {
875 const char *s;
876#ifdef WIN32
877 if (0 == i) {
878 s = kFakeDeviceName;
879 } else {
880 return -1;
881 }
882#else
883 // See comment above.
884 if (0 == i) {
885 s = kFakeDefaultDeviceName;
886 } else if (1 == i) {
887 s = kFakeDeviceName;
888 } else {
889 return -1;
890 }
891#endif
892 strcpy(name, s);
893 guid[0] = '\0';
894 return 0;
895 }
896
897 bool inited_;
898 int last_channel_;
899 std::map<int, Channel*> channels_;
900 bool fail_create_channel_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000901 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 bool ec_enabled_;
903 bool ec_metrics_enabled_;
904 bool cng_enabled_;
905 bool ns_enabled_;
906 bool agc_enabled_;
907 bool highpass_filter_enabled_;
908 bool stereo_swapping_enabled_;
909 bool typing_detection_enabled_;
910 webrtc::EcModes ec_mode_;
911 webrtc::AecmModes aecm_mode_;
912 webrtc::NsModes ns_mode_;
913 webrtc::AgcModes agc_mode_;
914 webrtc::AgcConfig agc_config_;
915 webrtc::VoiceEngineObserver* observer_;
916 int playout_fail_channel_;
917 int send_fail_channel_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000918 int recording_sample_rate_;
919 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 DtmfInfo dtmf_info_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000921 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922};
923
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924} // namespace cricket
925
926#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_