blob: 6144f2db40db82f061a8571efb212dfd475b905f [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"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000044#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000045
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046namespace cricket {
47
48// Function returning stats will return these values
49// for all values based on type.
50const int kIntStatValue = 123;
51const float kFractionLostStatValue = 0.5;
52
53static const char kFakeDefaultDeviceName[] = "Fake Default";
54static const int kFakeDefaultDeviceId = -1;
55static const char kFakeDeviceName[] = "Fake Device";
56#ifdef WIN32
57static const int kFakeDeviceId = 0;
58#else
59static const int kFakeDeviceId = 1;
60#endif
61
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000062static const int kOpusBandwidthNb = 4000;
63static const int kOpusBandwidthMb = 6000;
64static const int kOpusBandwidthWb = 8000;
65static const int kOpusBandwidthSwb = 12000;
66static const int kOpusBandwidthFb = 20000;
67
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +000068static const webrtc::NetworkStatistics kNetStats = {
69 1, // uint16_t currentBufferSize;
70 2, // uint16_t preferredBufferSize;
71 true, // bool jitterPeaksFound;
72 1234, // uint16_t currentPacketLossRate;
73 567, // uint16_t currentDiscardRate;
74 8901, // uint16_t currentExpandRate;
75 234, // uint16_t currentSpeechExpandRate;
76 5678, // uint16_t currentPreemptiveRate;
77 9012, // uint16_t currentAccelerateRate;
78 3456, // uint16_t currentSecondaryDecodedRate;
79 7890, // int32_t clockDriftPPM;
80 54, // meanWaitingTimeMs;
81 32, // int medianWaitingTimeMs;
82 1, // int minWaitingTimeMs;
83 98, // int maxWaitingTimeMs;
84 7654, // int addedSamples;
85}; // These random but non-trivial numbers are used for testing.
86
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020087#define WEBRTC_CHECK_CHANNEL(channel) \
88 if (channels_.find(channel) == channels_.end()) return -1;
89
90#define WEBRTC_ASSERT_CHANNEL(channel) \
henrikg91d6ede2015-09-17 00:24:34 -070091 RTC_DCHECK(channels_.find(channel) != channels_.end());
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020092
henrike@webrtc.org79047f92014-03-06 23:46:59 +000093// Verify the header extension ID, if enabled, is within the bounds specified in
94// [RFC5285]: 1-14 inclusive.
95#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
96 do { \
97 if (enable && (id < 1 || id > 14)) { \
98 return -1; \
99 } \
100 } while (0);
101
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000102class FakeAudioProcessing : public webrtc::AudioProcessing {
103 public:
104 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
105
106 WEBRTC_STUB(Initialize, ())
107 WEBRTC_STUB(Initialize, (
108 int input_sample_rate_hz,
109 int output_sample_rate_hz,
110 int reverse_sample_rate_hz,
111 webrtc::AudioProcessing::ChannelLayout input_layout,
112 webrtc::AudioProcessing::ChannelLayout output_layout,
113 webrtc::AudioProcessing::ChannelLayout reverse_layout));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700114 WEBRTC_STUB(Initialize, (
115 const webrtc::ProcessingConfig& processing_config));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000116
117 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
118 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
119 }
120
121 WEBRTC_STUB(set_sample_rate_hz, (int rate));
122 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
123 WEBRTC_STUB_CONST(sample_rate_hz, ());
124 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
125 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
126 WEBRTC_STUB_CONST(num_input_channels, ());
127 WEBRTC_STUB_CONST(num_output_channels, ());
128 WEBRTC_STUB_CONST(num_reverse_channels, ());
129 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
130 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
131 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
132 WEBRTC_STUB(ProcessStream, (
133 const float* const* src,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700134 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000135 int input_sample_rate_hz,
136 webrtc::AudioProcessing::ChannelLayout input_layout,
137 int output_sample_rate_hz,
138 webrtc::AudioProcessing::ChannelLayout output_layout,
139 float* const* dest));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700140 WEBRTC_STUB(ProcessStream,
141 (const float* const* src,
142 const webrtc::StreamConfig& input_config,
143 const webrtc::StreamConfig& output_config,
144 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000145 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
ekmeyerson60d9b332015-08-14 10:35:55 -0700146 WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000147 WEBRTC_STUB(AnalyzeReverseStream, (
148 const float* const* data,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700149 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000150 int sample_rate_hz,
151 webrtc::AudioProcessing::ChannelLayout layout));
ekmeyerson60d9b332015-08-14 10:35:55 -0700152 WEBRTC_STUB(ProcessReverseStream,
153 (const float* const* src,
154 const webrtc::StreamConfig& reverse_input_config,
155 const webrtc::StreamConfig& reverse_output_config,
156 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000157 WEBRTC_STUB(set_stream_delay_ms, (int delay));
158 WEBRTC_STUB_CONST(stream_delay_ms, ());
159 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
160 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
161 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
162 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
163 WEBRTC_STUB_CONST(delay_offset_ms, ());
164 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
165 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
166 WEBRTC_STUB(StopDebugRecording, ());
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200167 WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000168 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
169 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000170 return NULL;
171 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000172 webrtc::GainControl* gain_control() const override { return NULL; }
173 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
174 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
175 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
176 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000177
178 bool experimental_ns_enabled() {
179 return experimental_ns_enabled_;
180 }
181
182 private:
183 bool experimental_ns_enabled_;
184};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000185
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186class FakeWebRtcVoiceEngine
187 : public webrtc::VoEAudioProcessing,
188 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
Fredrik Solenberg7d173362015-09-23 12:23:21 +0200189 public webrtc::VoEHardware, public webrtc::VoENetEqStats,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
191 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
192 public:
193 struct DtmfInfo {
194 DtmfInfo()
195 : dtmf_event_code(-1),
196 dtmf_out_of_band(false),
197 dtmf_length_ms(-1) {}
198 int dtmf_event_code;
199 bool dtmf_out_of_band;
200 int dtmf_length_ms;
201 };
202 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000203 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 : external_transport(false),
205 send(false),
206 playout(false),
207 volume_scale(1.0),
208 volume_pan_left(1.0),
209 volume_pan_right(1.0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000211 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000212 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000213 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000214 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 nack(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000216 rx_agc_enabled(false),
217 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 cn8_type(13),
219 cn16_type(105),
220 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000221 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 nack_max_packets(0),
223 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000224 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000225 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000226 send_absolute_sender_time_ext_(-1),
Henrik Lundin64dad832015-05-11 12:44:23 +0200227 receive_absolute_sender_time_ext_(-1),
Minyue2013aec2015-05-13 14:14:42 +0200228 associate_send_channel(-1),
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200229 neteq_capacity(-1),
230 neteq_fast_accelerate(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000232 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 }
234 bool external_transport;
235 bool send;
236 bool playout;
237 float volume_scale;
238 float volume_pan_left;
239 float volume_pan_right;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000241 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000242 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000243 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000244 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 bool nack;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000246 bool rx_agc_enabled;
247 webrtc::AgcModes rx_agc_mode;
248 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 int cn8_type;
250 int cn16_type;
251 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000252 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 int nack_max_packets;
254 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000255 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000256 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000257 int send_absolute_sender_time_ext_;
258 int receive_absolute_sender_time_ext_;
Minyue2013aec2015-05-13 14:14:42 +0200259 int associate_send_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 DtmfInfo dtmf_info;
261 std::vector<webrtc::CodecInst> recv_codecs;
262 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000263 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 std::list<std::string> packets;
Henrik Lundin64dad832015-05-11 12:44:23 +0200265 int neteq_capacity;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200266 bool neteq_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 };
268
269 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
270 int num_codecs)
271 : inited_(false),
272 last_channel_(-1),
273 fail_create_channel_(false),
274 codecs_(codecs),
275 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000276 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 ec_enabled_(false),
278 ec_metrics_enabled_(false),
279 cng_enabled_(false),
280 ns_enabled_(false),
281 agc_enabled_(false),
282 highpass_filter_enabled_(false),
283 stereo_swapping_enabled_(false),
284 typing_detection_enabled_(false),
285 ec_mode_(webrtc::kEcDefault),
286 aecm_mode_(webrtc::kAecmSpeakerphone),
287 ns_mode_(webrtc::kNsDefault),
288 agc_mode_(webrtc::kAgcDefault),
289 observer_(NULL),
290 playout_fail_channel_(-1),
291 send_fail_channel_(-1),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000292 recording_sample_rate_(-1),
Fredrik Solenberg7d173362015-09-23 12:23:21 +0200293 playout_sample_rate_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 memset(&agc_config_, 0, sizeof(agc_config_));
295 }
296 ~FakeWebRtcVoiceEngine() {
297 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
298 // destructors, but just in case ...
299 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
300 i != channels_.end(); ++i) {
301 delete i->second;
302 }
303 }
304
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 bool IsInited() const { return inited_; }
306 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000307 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
308 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
309 iter != channels_.end(); ++iter) {
310 if (local_ssrc == iter->second->send_ssrc)
311 return iter->first;
312 }
313 return -1;
314 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000315 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 bool GetPlayout(int channel) {
317 return channels_[channel]->playout;
318 }
319 bool GetSend(int channel) {
320 return channels_[channel]->send;
321 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 bool GetVAD(int channel) {
323 return channels_[channel]->vad;
324 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100325 bool GetOpusDtx(int channel) {
326 return channels_[channel]->opus_dtx;
327 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000328 bool GetRED(int channel) {
329 return channels_[channel]->red;
330 }
331 bool GetCodecFEC(int channel) {
332 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000334 int GetMaxEncodingBandwidth(int channel) {
335 return channels_[channel]->max_encoding_bandwidth;
336 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 bool GetNACK(int channel) {
338 return channels_[channel]->nack;
339 }
340 int GetNACKMaxPackets(int channel) {
341 return channels_[channel]->nack_max_packets;
342 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000343 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
344 WEBRTC_ASSERT_CHANNEL(channel);
345 return channels_[channel]->last_rtp_packet_time;
346 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 int GetSendCNPayloadType(int channel, bool wideband) {
348 return (wideband) ?
349 channels_[channel]->cn16_type :
350 channels_[channel]->cn8_type;
351 }
352 int GetSendTelephoneEventPayloadType(int channel) {
353 return channels_[channel]->dtmf_type;
354 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000355 int GetSendREDPayloadType(int channel) {
356 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 }
358 bool CheckPacket(int channel, const void* data, size_t len) {
359 bool result = !CheckNoPacket(channel);
360 if (result) {
361 std::string packet = channels_[channel]->packets.front();
362 result = (packet == std::string(static_cast<const char*>(data), len));
363 channels_[channel]->packets.pop_front();
364 }
365 return result;
366 }
367 bool CheckNoPacket(int channel) {
368 return channels_[channel]->packets.empty();
369 }
370 void TriggerCallbackOnError(int channel_num, int err_code) {
henrikg91d6ede2015-09-17 00:24:34 -0700371 RTC_DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 observer_->CallbackOnError(channel_num, err_code);
373 }
374 void set_playout_fail_channel(int channel) {
375 playout_fail_channel_ = channel;
376 }
377 void set_send_fail_channel(int channel) {
378 send_fail_channel_ = channel;
379 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 void set_fail_create_channel(bool fail_create_channel) {
381 fail_create_channel_ = fail_create_channel;
382 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200383 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000384 if (fail_create_channel_) {
385 return -1;
386 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000387 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000388 for (int i = 0; i < NumOfCodecs(); ++i) {
389 webrtc::CodecInst codec;
390 GetCodec(i, codec);
391 ch->recv_codecs.push_back(codec);
392 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200393 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
394 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
395 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200396 ch->neteq_fast_accelerate =
397 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000398 channels_[++last_channel_] = ch;
399 return last_channel_;
400 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000401 int GetSendRtpExtensionId(int channel, const std::string& extension) {
402 WEBRTC_ASSERT_CHANNEL(channel);
403 if (extension == kRtpAudioLevelHeaderExtension) {
404 return channels_[channel]->send_audio_level_ext_;
405 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
406 return channels_[channel]->send_absolute_sender_time_ext_;
407 }
408 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000409 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000410 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
411 WEBRTC_ASSERT_CHANNEL(channel);
412 if (extension == kRtpAudioLevelHeaderExtension) {
413 return channels_[channel]->receive_audio_level_ext_;
414 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
415 return channels_[channel]->receive_absolute_sender_time_ext_;
416 }
417 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000418 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000420 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
421
Minyue2013aec2015-05-13 14:14:42 +0200422 int GetAssociateSendChannel(int channel) {
423 return channels_[channel]->associate_send_channel;
424 }
425
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 WEBRTC_STUB(Release, ());
427
428 // webrtc::VoEBase
429 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
430 webrtc::VoiceEngineObserver& observer)) {
431 observer_ = &observer;
432 return 0;
433 }
434 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
435 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
436 webrtc::AudioProcessing* audioproc)) {
437 inited_ = true;
438 return 0;
439 }
440 WEBRTC_FUNC(Terminate, ()) {
441 inited_ = false;
442 return 0;
443 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000444 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000445 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200448 webrtc::Config empty_config;
449 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200451 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
452 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000453 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 WEBRTC_FUNC(DeleteChannel, (int channel)) {
455 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200456 for (const auto& ch : channels_) {
457 if (ch.second->associate_send_channel == channel) {
458 ch.second->associate_send_channel = -1;
459 }
460 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 delete channels_[channel];
462 channels_.erase(channel);
463 return 0;
464 }
465 WEBRTC_STUB(StartReceive, (int channel));
466 WEBRTC_FUNC(StartPlayout, (int channel)) {
467 if (playout_fail_channel_ != channel) {
468 WEBRTC_CHECK_CHANNEL(channel);
469 channels_[channel]->playout = true;
470 return 0;
471 } else {
472 // When playout_fail_channel_ == channel, fail the StartPlayout on this
473 // channel.
474 return -1;
475 }
476 }
477 WEBRTC_FUNC(StartSend, (int channel)) {
478 if (send_fail_channel_ != channel) {
479 WEBRTC_CHECK_CHANNEL(channel);
480 channels_[channel]->send = true;
481 return 0;
482 } else {
483 // When send_fail_channel_ == channel, fail the StartSend on this
484 // channel.
485 return -1;
486 }
487 }
488 WEBRTC_STUB(StopReceive, (int channel));
489 WEBRTC_FUNC(StopPlayout, (int channel)) {
490 WEBRTC_CHECK_CHANNEL(channel);
491 channels_[channel]->playout = false;
492 return 0;
493 }
494 WEBRTC_FUNC(StopSend, (int channel)) {
495 WEBRTC_CHECK_CHANNEL(channel);
496 channels_[channel]->send = false;
497 return 0;
498 }
499 WEBRTC_STUB(GetVersion, (char version[1024]));
500 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200501 WEBRTC_FUNC(AssociateSendChannel, (int channel,
502 int accociate_send_channel)) {
503 WEBRTC_CHECK_CHANNEL(channel);
504 channels_[channel]->associate_send_channel = accociate_send_channel;
505 return 0;
506 }
ivocb04965c2015-09-09 00:09:43 -0700507 webrtc::RtcEventLog* GetEventLog() { return nullptr; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000508
509 // webrtc::VoECodec
510 WEBRTC_FUNC(NumOfCodecs, ()) {
511 return num_codecs_;
512 }
513 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
514 if (index < 0 || index >= NumOfCodecs()) {
515 return -1;
516 }
517 const cricket::AudioCodec& c(*codecs_[index]);
518 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000519 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 codec.plfreq = c.clockrate;
521 codec.pacsize = 0;
522 codec.channels = c.channels;
523 codec.rate = c.bitrate;
524 return 0;
525 }
526 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
527 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000528 // To match the behavior of the real implementation.
529 if (_stricmp(codec.plname, "telephone-event") == 0 ||
530 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
531 _stricmp(codec.plname, "CN") == 0 ||
532 _stricmp(codec.plname, "red") == 0 ) {
533 return -1;
534 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000536 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 return 0;
538 }
539 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
540 WEBRTC_CHECK_CHANNEL(channel);
541 codec = channels_[channel]->send_codec;
542 return 0;
543 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200544 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000545 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
546 WEBRTC_CHECK_CHANNEL(channel);
547 const Channel* c = channels_[channel];
548 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
549 it_packet != c->packets.end(); ++it_packet) {
550 int pltype;
551 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
552 continue;
553 }
554 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
555 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
556 ++it_codec) {
557 if (it_codec->pltype == pltype) {
558 codec = *it_codec;
559 return 0;
560 }
561 }
562 }
563 return -1;
564 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 WEBRTC_FUNC(SetRecPayloadType, (int channel,
566 const webrtc::CodecInst& codec)) {
567 WEBRTC_CHECK_CHANNEL(channel);
568 Channel* ch = channels_[channel];
569 if (ch->playout)
570 return -1; // Channel is in use.
571 // Check if something else already has this slot.
572 if (codec.pltype != -1) {
573 for (std::vector<webrtc::CodecInst>::iterator it =
574 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
575 if (it->pltype == codec.pltype &&
576 _stricmp(it->plname, codec.plname) != 0) {
577 return -1;
578 }
579 }
580 }
581 // Otherwise try to find this codec and update its payload type.
582 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
583 it != ch->recv_codecs.end(); ++it) {
584 if (strcmp(it->plname, codec.plname) == 0 &&
585 it->plfreq == codec.plfreq) {
586 it->pltype = codec.pltype;
587 it->channels = codec.channels;
588 return 0;
589 }
590 }
591 return -1; // not found
592 }
593 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
594 webrtc::PayloadFrequencies frequency)) {
595 WEBRTC_CHECK_CHANNEL(channel);
596 if (frequency == webrtc::kFreq8000Hz) {
597 channels_[channel]->cn8_type = type;
598 } else if (frequency == webrtc::kFreq16000Hz) {
599 channels_[channel]->cn16_type = type;
600 }
601 return 0;
602 }
603 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
604 WEBRTC_CHECK_CHANNEL(channel);
605 Channel* ch = channels_[channel];
606 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
607 it != ch->recv_codecs.end(); ++it) {
608 if (strcmp(it->plname, codec.plname) == 0 &&
609 it->plfreq == codec.plfreq &&
610 it->channels == codec.channels &&
611 it->pltype != -1) {
612 codec.pltype = it->pltype;
613 return 0;
614 }
615 }
616 return -1; // not found
617 }
618 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
619 bool disableDTX)) {
620 WEBRTC_CHECK_CHANNEL(channel);
621 if (channels_[channel]->send_codec.channels == 2) {
622 // Replicating VoE behavior; VAD cannot be enabled for stereo.
623 return -1;
624 }
625 channels_[channel]->vad = enable;
626 return 0;
627 }
628 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
629 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000630
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000631 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
632 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000633 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000634 // Return -1 if current send codec is not Opus.
635 // TODO(minyue): Excludes other codecs if they support inband FEC.
636 return -1;
637 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000638 channels_[channel]->codec_fec = enable;
639 return 0;
640 }
641 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
642 WEBRTC_CHECK_CHANNEL(channel);
643 enable = channels_[channel]->codec_fec;
644 return 0;
645 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000646
647 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
648 WEBRTC_CHECK_CHANNEL(channel);
649 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
650 // Return -1 if current send codec is not Opus.
651 return -1;
652 }
653 if (frequency_hz <= 8000)
654 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
655 else if (frequency_hz <= 12000)
656 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
657 else if (frequency_hz <= 16000)
658 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
659 else if (frequency_hz <= 24000)
660 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
661 else
662 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
663 return 0;
664 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000666 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
667 WEBRTC_CHECK_CHANNEL(channel);
668 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
669 // Return -1 if current send codec is not Opus.
670 return -1;
671 }
672 channels_[channel]->opus_dtx = enable_dtx;
673 return 0;
674 }
675
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676 // webrtc::VoEDtmf
677 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
678 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
679 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
680 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
681 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
682 return 0;
683 }
684
685 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
686 (int channel, unsigned char type)) {
687 channels_[channel]->dtmf_type = type;
688 return 0;
689 };
690 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
691 (int channel, unsigned char& type));
692
693 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
694 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 WEBRTC_FUNC(PlayDtmfTone,
697 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
698 dtmf_info_.dtmf_event_code = event_code;
699 dtmf_info_.dtmf_length_ms = length_ms;
700 return 0;
701 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
705 return GetNumDevices(num);
706 }
707 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
708 return GetNumDevices(num);
709 }
710 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
711 return GetDeviceName(i, name, guid);
712 }
713 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
714 return GetDeviceName(i, name, guid);
715 }
716 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
717 WEBRTC_STUB(SetPlayoutDevice, (int));
718 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
719 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000720 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
721 recording_sample_rate_ = samples_per_sec;
722 return 0;
723 }
724 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
725 *samples_per_sec = recording_sample_rate_;
726 return 0;
727 }
728 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
729 playout_sample_rate_ = samples_per_sec;
730 return 0;
731 }
732 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
733 *samples_per_sec = playout_sample_rate_;
734 return 0;
735 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000737 virtual bool BuiltInAECIsAvailable() const { return false; }
henrikac14f5ff2015-09-23 14:08:33 +0200738 WEBRTC_STUB(EnableBuiltInAGC, (bool enable));
739 virtual bool BuiltInAGCIsAvailable() const { return false; }
740 WEBRTC_STUB(EnableBuiltInNS, (bool enable));
741 virtual bool BuiltInNSIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742
743 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000744 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
745 webrtc::NetworkStatistics& ns)) {
746 WEBRTC_CHECK_CHANNEL(channel);
747 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
748 return 0;
749 }
750
wu@webrtc.org24301a62013-12-13 19:17:43 +0000751 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
752 webrtc::AudioDecodingCallStats*)) {
753 WEBRTC_CHECK_CHANNEL(channel);
754 return 0;
755 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756
757 // webrtc::VoENetwork
758 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
759 webrtc::Transport& transport)) {
760 WEBRTC_CHECK_CHANNEL(channel);
761 channels_[channel]->external_transport = true;
762 return 0;
763 }
764 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
765 WEBRTC_CHECK_CHANNEL(channel);
766 channels_[channel]->external_transport = false;
767 return 0;
768 }
769 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000770 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 WEBRTC_CHECK_CHANNEL(channel);
772 if (!channels_[channel]->external_transport) return -1;
773 channels_[channel]->packets.push_back(
774 std::string(static_cast<const char*>(data), length));
775 return 0;
776 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000777 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000778 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000779 const webrtc::PacketTime& packet_time)) {
780 WEBRTC_CHECK_CHANNEL(channel);
781 if (ReceivedRTPPacket(channel, data, length) == -1) {
782 return -1;
783 }
784 channels_[channel]->last_rtp_packet_time = packet_time;
785 return 0;
786 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000787
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000789 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790
791 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
793 WEBRTC_CHECK_CHANNEL(channel);
794 channels_[channel]->send_ssrc = ssrc;
795 return 0;
796 }
797 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
798 WEBRTC_CHECK_CHANNEL(channel);
799 ssrc = channels_[channel]->send_ssrc;
800 return 0;
801 }
802 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000803 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
804 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000806 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
807 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 return 0;
809 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000810 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
811 unsigned char id)) {
812 WEBRTC_CHECK_CHANNEL(channel);
813 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
814 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
815 return 0;
816 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000817 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
818 unsigned char id)) {
819 WEBRTC_CHECK_CHANNEL(channel);
820 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
821 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
822 return 0;
823 }
824 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
825 unsigned char id)) {
826 WEBRTC_CHECK_CHANNEL(channel);
827 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
828 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
829 return 0;
830 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000831
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
833 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
834 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
835 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
836 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
837 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
838 unsigned int& NTPLow,
839 unsigned int& timestamp,
840 unsigned int& playoutTimestamp,
841 unsigned int* jitter,
842 unsigned short* fractionLost));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
844 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
845 WEBRTC_CHECK_CHANNEL(channel);
846 webrtc::ReportBlock block;
847 block.source_SSRC = channels_[channel]->send_ssrc;
848 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
849 if (send_codec.pltype >= 0) {
850 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
851 if (send_codec.plfreq / 1000 > 0) {
852 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
853 }
854 block.cumulative_num_packets_lost = kIntStatValue;
855 block.extended_highest_sequence_number = kIntStatValue;
856 receive_blocks->push_back(block);
857 }
858 return 0;
859 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
861 unsigned int& maxJitterMs,
862 unsigned int& discardedPackets));
863 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
864 WEBRTC_CHECK_CHANNEL(channel);
865 stats.fractionLost = static_cast<int16>(kIntStatValue);
866 stats.cumulativeLost = kIntStatValue;
867 stats.extendedMax = kIntStatValue;
868 stats.jitterSamples = kIntStatValue;
869 stats.rttMs = kIntStatValue;
870 stats.bytesSent = kIntStatValue;
871 stats.packetsSent = kIntStatValue;
872 stats.bytesReceived = kIntStatValue;
873 stats.packetsReceived = kIntStatValue;
874 return 0;
875 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000876 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000877 return SetFECStatus(channel, enable, redPayloadtype);
878 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000879 // TODO(minyue): remove the below function when transition to SetREDStatus
880 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
882 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000883 channels_[channel]->red = enable;
884 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 return 0;
886 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000887 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000888 return GetFECStatus(channel, enable, redPayloadtype);
889 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000890 // TODO(minyue): remove the below function when transition to GetREDStatus
891 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
893 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000894 enable = channels_[channel]->red;
895 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 return 0;
897 }
898 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
899 WEBRTC_CHECK_CHANNEL(channel);
900 channels_[channel]->nack = enable;
901 channels_[channel]->nack_max_packets = maxNoPackets;
902 return 0;
903 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
905 // webrtc::VoEVideoSync
906 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
907 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000908 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
910 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
911 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
912 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
913 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
914 int* playout_buffer_delay_ms));
915 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
916
917 // webrtc::VoEVolumeControl
918 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
919 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 WEBRTC_STUB(SetMicVolume, (unsigned int));
921 WEBRTC_STUB(GetMicVolume, (unsigned int&));
922 WEBRTC_STUB(SetInputMute, (int, bool));
923 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
925 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
926 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
927 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
928 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
929 WEBRTC_CHECK_CHANNEL(channel);
930 channels_[channel]->volume_scale= scale;
931 return 0;
932 }
933 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
934 WEBRTC_CHECK_CHANNEL(channel);
935 scale = channels_[channel]->volume_scale;
936 return 0;
937 }
938 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
939 WEBRTC_CHECK_CHANNEL(channel);
940 channels_[channel]->volume_pan_left = left;
941 channels_[channel]->volume_pan_right = right;
942 return 0;
943 }
944 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
945 WEBRTC_CHECK_CHANNEL(channel);
946 left = channels_[channel]->volume_pan_left;
947 right = channels_[channel]->volume_pan_right;
948 return 0;
949 }
950
951 // webrtc::VoEAudioProcessing
952 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
953 ns_enabled_ = enable;
954 ns_mode_ = mode;
955 return 0;
956 }
957 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
958 enabled = ns_enabled_;
959 mode = ns_mode_;
960 return 0;
961 }
962
963 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
964 agc_enabled_ = enable;
965 agc_mode_ = mode;
966 return 0;
967 }
968 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
969 enabled = agc_enabled_;
970 mode = agc_mode_;
971 return 0;
972 }
973
974 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
975 agc_config_ = config;
976 return 0;
977 }
978 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
979 config = agc_config_;
980 return 0;
981 }
982 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
983 ec_enabled_ = enable;
984 ec_mode_ = mode;
985 return 0;
986 }
987 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
988 enabled = ec_enabled_;
989 mode = ec_mode_;
990 return 0;
991 }
992 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
993 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
994 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
995 WEBRTC_STUB(DelayOffsetMs, ());
996 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
997 aecm_mode_ = mode;
998 cng_enabled_ = enableCNG;
999 return 0;
1000 }
1001 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1002 mode = aecm_mode_;
1003 enabledCNG = cng_enabled_;
1004 return 0;
1005 }
1006 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1007 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1008 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001009 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1010 webrtc::AgcModes mode)) {
1011 channels_[channel]->rx_agc_enabled = enable;
1012 channels_[channel]->rx_agc_mode = mode;
1013 return 0;
1014 }
1015 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1016 webrtc::AgcModes& mode)) {
1017 enabled = channels_[channel]->rx_agc_enabled;
1018 mode = channels_[channel]->rx_agc_mode;
1019 return 0;
1020 }
1021
1022 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1023 channels_[channel]->rx_agc_config = config;
1024 return 0;
1025 }
1026 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1027 config = channels_[channel]->rx_agc_config;
1028 return 0;
1029 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030
1031 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1032 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1033 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1034 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1035 ec_metrics_enabled_ = enable;
1036 return 0;
1037 }
1038 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1039 enabled = ec_metrics_enabled_;
1040 return 0;
1041 }
1042 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001043 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1044 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045
1046 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001047 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 WEBRTC_STUB(StopDebugRecording, ());
1049
1050 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1051 typing_detection_enabled_ = enable;
1052 return 0;
1053 }
1054 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1055 enabled = typing_detection_enabled_;
1056 return 0;
1057 }
1058
1059 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1060 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1061 int costPerTyping,
1062 int reportingThreshold,
1063 int penaltyDecay,
1064 int typeEventDelay));
1065 int EnableHighPassFilter(bool enable) {
1066 highpass_filter_enabled_ = enable;
1067 return 0;
1068 }
1069 bool IsHighPassFilterEnabled() {
1070 return highpass_filter_enabled_;
1071 }
1072 bool IsStereoChannelSwappingEnabled() {
1073 return stereo_swapping_enabled_;
1074 }
1075 void EnableStereoChannelSwapping(bool enable) {
1076 stereo_swapping_enabled_ = enable;
1077 }
1078 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1079 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1080 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1081 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1082 }
1083 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1084 return (dtmf_info_.dtmf_event_code == event_code &&
1085 dtmf_info_.dtmf_length_ms == length_ms);
1086 }
Henrik Lundin64dad832015-05-11 12:44:23 +02001087 int GetNetEqCapacity() const {
1088 auto ch = channels_.find(last_channel_);
1089 ASSERT(ch != channels_.end());
1090 return ch->second->neteq_capacity;
1091 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +02001092 bool GetNetEqFastAccelerate() const {
1093 auto ch = channels_.find(last_channel_);
1094 ASSERT(ch != channels_.end());
1095 return ch->second->neteq_fast_accelerate;
1096 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097
1098 private:
1099 int GetNumDevices(int& num) {
1100#ifdef WIN32
1101 num = 1;
1102#else
1103 // On non-Windows platforms VE adds a special entry for the default device,
1104 // so if there is one physical device then there are two entries in the
1105 // list.
1106 num = 2;
1107#endif
1108 return 0;
1109 }
1110
1111 int GetDeviceName(int i, char* name, char* guid) {
1112 const char *s;
1113#ifdef WIN32
1114 if (0 == i) {
1115 s = kFakeDeviceName;
1116 } else {
1117 return -1;
1118 }
1119#else
1120 // See comment above.
1121 if (0 == i) {
1122 s = kFakeDefaultDeviceName;
1123 } else if (1 == i) {
1124 s = kFakeDeviceName;
1125 } else {
1126 return -1;
1127 }
1128#endif
1129 strcpy(name, s);
1130 guid[0] = '\0';
1131 return 0;
1132 }
1133
1134 bool inited_;
1135 int last_channel_;
1136 std::map<int, Channel*> channels_;
1137 bool fail_create_channel_;
1138 const cricket::AudioCodec* const* codecs_;
1139 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001140 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 bool ec_enabled_;
1142 bool ec_metrics_enabled_;
1143 bool cng_enabled_;
1144 bool ns_enabled_;
1145 bool agc_enabled_;
1146 bool highpass_filter_enabled_;
1147 bool stereo_swapping_enabled_;
1148 bool typing_detection_enabled_;
1149 webrtc::EcModes ec_mode_;
1150 webrtc::AecmModes aecm_mode_;
1151 webrtc::NsModes ns_mode_;
1152 webrtc::AgcModes agc_mode_;
1153 webrtc::AgcConfig agc_config_;
1154 webrtc::VoiceEngineObserver* observer_;
1155 int playout_fail_channel_;
1156 int send_fail_channel_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001157 int recording_sample_rate_;
1158 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159 DtmfInfo dtmf_info_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001160 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161};
1162
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001163#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1164
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001165} // namespace cricket
1166
1167#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_