blob: 50cdd144ee248a1a468c7a9e7ab92064d7e29085 [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/base/voiceprocessor.h"
38#include "talk/media/webrtc/fakewebrtccommon.h"
39#include "talk/media/webrtc/webrtcvoe.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "webrtc/base/basictypes.h"
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020041#include "webrtc/base/checks.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "webrtc/base/gunit.h"
43#include "webrtc/base/stringutils.h"
Henrik Lundin64dad832015-05-11 12:44:23 +020044#include "webrtc/config.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
49// Function returning stats will return these values
50// for all values based on type.
51const int kIntStatValue = 123;
52const float kFractionLostStatValue = 0.5;
53
54static const char kFakeDefaultDeviceName[] = "Fake Default";
55static const int kFakeDefaultDeviceId = -1;
56static const char kFakeDeviceName[] = "Fake Device";
57#ifdef WIN32
58static const int kFakeDeviceId = 0;
59#else
60static const int kFakeDeviceId = 1;
61#endif
62
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000063static const int kOpusBandwidthNb = 4000;
64static const int kOpusBandwidthMb = 6000;
65static const int kOpusBandwidthWb = 8000;
66static const int kOpusBandwidthSwb = 12000;
67static const int kOpusBandwidthFb = 20000;
68
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +000069static const webrtc::NetworkStatistics kNetStats = {
70 1, // uint16_t currentBufferSize;
71 2, // uint16_t preferredBufferSize;
72 true, // bool jitterPeaksFound;
73 1234, // uint16_t currentPacketLossRate;
74 567, // uint16_t currentDiscardRate;
75 8901, // uint16_t currentExpandRate;
76 234, // uint16_t currentSpeechExpandRate;
77 5678, // uint16_t currentPreemptiveRate;
78 9012, // uint16_t currentAccelerateRate;
79 3456, // uint16_t currentSecondaryDecodedRate;
80 7890, // int32_t clockDriftPPM;
81 54, // meanWaitingTimeMs;
82 32, // int medianWaitingTimeMs;
83 1, // int minWaitingTimeMs;
84 98, // int maxWaitingTimeMs;
85 7654, // int addedSamples;
86}; // These random but non-trivial numbers are used for testing.
87
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020088#define WEBRTC_CHECK_CHANNEL(channel) \
89 if (channels_.find(channel) == channels_.end()) return -1;
90
91#define WEBRTC_ASSERT_CHANNEL(channel) \
92 DCHECK(channels_.find(channel) != channels_.end());
93
henrike@webrtc.org79047f92014-03-06 23:46:59 +000094// Verify the header extension ID, if enabled, is within the bounds specified in
95// [RFC5285]: 1-14 inclusive.
96#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
97 do { \
98 if (enable && (id < 1 || id > 14)) { \
99 return -1; \
100 } \
101 } while (0);
102
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000103class FakeAudioProcessing : public webrtc::AudioProcessing {
104 public:
105 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
106
107 WEBRTC_STUB(Initialize, ())
108 WEBRTC_STUB(Initialize, (
109 int input_sample_rate_hz,
110 int output_sample_rate_hz,
111 int reverse_sample_rate_hz,
112 webrtc::AudioProcessing::ChannelLayout input_layout,
113 webrtc::AudioProcessing::ChannelLayout output_layout,
114 webrtc::AudioProcessing::ChannelLayout reverse_layout));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700115 WEBRTC_STUB(Initialize, (
116 const webrtc::ProcessingConfig& processing_config));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000117
118 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
119 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
120 }
121
122 WEBRTC_STUB(set_sample_rate_hz, (int rate));
123 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
124 WEBRTC_STUB_CONST(sample_rate_hz, ());
125 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
126 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
127 WEBRTC_STUB_CONST(num_input_channels, ());
128 WEBRTC_STUB_CONST(num_output_channels, ());
129 WEBRTC_STUB_CONST(num_reverse_channels, ());
130 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
131 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
132 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
133 WEBRTC_STUB(ProcessStream, (
134 const float* const* src,
135 int samples_per_channel,
136 int input_sample_rate_hz,
137 webrtc::AudioProcessing::ChannelLayout input_layout,
138 int output_sample_rate_hz,
139 webrtc::AudioProcessing::ChannelLayout output_layout,
140 float* const* dest));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700141 WEBRTC_STUB(ProcessStream,
142 (const float* const* src,
143 const webrtc::StreamConfig& input_config,
144 const webrtc::StreamConfig& output_config,
145 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000146 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
147 WEBRTC_STUB(AnalyzeReverseStream, (
148 const float* const* data,
149 int samples_per_channel,
150 int sample_rate_hz,
151 webrtc::AudioProcessing::ChannelLayout layout));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700152 WEBRTC_STUB(AnalyzeReverseStream, (
153 const float* const* data,
154 const webrtc::StreamConfig& reverse_config));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000155 WEBRTC_STUB(set_stream_delay_ms, (int delay));
156 WEBRTC_STUB_CONST(stream_delay_ms, ());
157 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
158 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
159 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
160 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
161 WEBRTC_STUB_CONST(delay_offset_ms, ());
162 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
163 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
164 WEBRTC_STUB(StopDebugRecording, ());
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200165 WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000166 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
167 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000168 return NULL;
169 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000170 webrtc::GainControl* gain_control() const override { return NULL; }
171 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
172 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
173 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
174 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000175
176 bool experimental_ns_enabled() {
177 return experimental_ns_enabled_;
178 }
179
180 private:
181 bool experimental_ns_enabled_;
182};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000183
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184class FakeWebRtcVoiceEngine
185 : public webrtc::VoEAudioProcessing,
186 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
187 public webrtc::VoEFile, public webrtc::VoEHardware,
188 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
189 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
190 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
191 public:
192 struct DtmfInfo {
193 DtmfInfo()
194 : dtmf_event_code(-1),
195 dtmf_out_of_band(false),
196 dtmf_length_ms(-1) {}
197 int dtmf_event_code;
198 bool dtmf_out_of_band;
199 int dtmf_length_ms;
200 };
201 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000202 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 : external_transport(false),
204 send(false),
205 playout(false),
206 volume_scale(1.0),
207 volume_pan_left(1.0),
208 volume_pan_right(1.0),
209 file(false),
210 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),
216 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000217 rx_agc_enabled(false),
218 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 cn8_type(13),
220 cn16_type(105),
221 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000222 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 nack_max_packets(0),
224 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000225 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000226 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000227 send_absolute_sender_time_ext_(-1),
Henrik Lundin64dad832015-05-11 12:44:23 +0200228 receive_absolute_sender_time_ext_(-1),
Minyue2013aec2015-05-13 14:14:42 +0200229 associate_send_channel(-1),
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200230 neteq_capacity(-1),
231 neteq_fast_accelerate(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000233 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 }
235 bool external_transport;
236 bool send;
237 bool playout;
238 float volume_scale;
239 float volume_pan_left;
240 float volume_pan_right;
241 bool file;
242 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000243 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000244 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000245 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000246 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 bool nack;
248 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000249 bool rx_agc_enabled;
250 webrtc::AgcModes rx_agc_mode;
251 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 int cn8_type;
253 int cn16_type;
254 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000255 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 int nack_max_packets;
257 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000258 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000259 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000260 int send_absolute_sender_time_ext_;
261 int receive_absolute_sender_time_ext_;
Minyue2013aec2015-05-13 14:14:42 +0200262 int associate_send_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 DtmfInfo dtmf_info;
264 std::vector<webrtc::CodecInst> recv_codecs;
265 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000266 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 std::list<std::string> packets;
Henrik Lundin64dad832015-05-11 12:44:23 +0200268 int neteq_capacity;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200269 bool neteq_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 };
271
272 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
273 int num_codecs)
274 : inited_(false),
275 last_channel_(-1),
276 fail_create_channel_(false),
277 codecs_(codecs),
278 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000279 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 ec_enabled_(false),
281 ec_metrics_enabled_(false),
282 cng_enabled_(false),
283 ns_enabled_(false),
284 agc_enabled_(false),
285 highpass_filter_enabled_(false),
286 stereo_swapping_enabled_(false),
287 typing_detection_enabled_(false),
288 ec_mode_(webrtc::kEcDefault),
289 aecm_mode_(webrtc::kAecmSpeakerphone),
290 ns_mode_(webrtc::kNsDefault),
291 agc_mode_(webrtc::kAgcDefault),
292 observer_(NULL),
293 playout_fail_channel_(-1),
294 send_fail_channel_(-1),
295 fail_start_recording_microphone_(false),
296 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000297 recording_sample_rate_(-1),
298 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 media_processor_(NULL) {
300 memset(&agc_config_, 0, sizeof(agc_config_));
301 }
302 ~FakeWebRtcVoiceEngine() {
303 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
304 // destructors, but just in case ...
305 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
306 i != channels_.end(); ++i) {
307 delete i->second;
308 }
309 }
310
311 bool IsExternalMediaProcessorRegistered() const {
312 return media_processor_ != NULL;
313 }
314 bool IsInited() const { return inited_; }
315 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000316 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
317 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
318 iter != channels_.end(); ++iter) {
319 if (local_ssrc == iter->second->send_ssrc)
320 return iter->first;
321 }
322 return -1;
323 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000324 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 bool GetPlayout(int channel) {
326 return channels_[channel]->playout;
327 }
328 bool GetSend(int channel) {
329 return channels_[channel]->send;
330 }
331 bool GetRecordingMicrophone() {
332 return recording_microphone_;
333 }
334 bool GetVAD(int channel) {
335 return channels_[channel]->vad;
336 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100337 bool GetOpusDtx(int channel) {
338 return channels_[channel]->opus_dtx;
339 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000340 bool GetRED(int channel) {
341 return channels_[channel]->red;
342 }
343 bool GetCodecFEC(int channel) {
344 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000346 int GetMaxEncodingBandwidth(int channel) {
347 return channels_[channel]->max_encoding_bandwidth;
348 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 bool GetNACK(int channel) {
350 return channels_[channel]->nack;
351 }
352 int GetNACKMaxPackets(int channel) {
353 return channels_[channel]->nack_max_packets;
354 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000355 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
356 WEBRTC_ASSERT_CHANNEL(channel);
357 return channels_[channel]->last_rtp_packet_time;
358 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 int GetSendCNPayloadType(int channel, bool wideband) {
360 return (wideband) ?
361 channels_[channel]->cn16_type :
362 channels_[channel]->cn8_type;
363 }
364 int GetSendTelephoneEventPayloadType(int channel) {
365 return channels_[channel]->dtmf_type;
366 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000367 int GetSendREDPayloadType(int channel) {
368 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 }
370 bool CheckPacket(int channel, const void* data, size_t len) {
371 bool result = !CheckNoPacket(channel);
372 if (result) {
373 std::string packet = channels_[channel]->packets.front();
374 result = (packet == std::string(static_cast<const char*>(data), len));
375 channels_[channel]->packets.pop_front();
376 }
377 return result;
378 }
379 bool CheckNoPacket(int channel) {
380 return channels_[channel]->packets.empty();
381 }
382 void TriggerCallbackOnError(int channel_num, int err_code) {
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +0200383 DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 observer_->CallbackOnError(channel_num, err_code);
385 }
386 void set_playout_fail_channel(int channel) {
387 playout_fail_channel_ = channel;
388 }
389 void set_send_fail_channel(int channel) {
390 send_fail_channel_ = channel;
391 }
392 void set_fail_start_recording_microphone(
393 bool fail_start_recording_microphone) {
394 fail_start_recording_microphone_ = fail_start_recording_microphone;
395 }
396 void set_fail_create_channel(bool fail_create_channel) {
397 fail_create_channel_ = fail_create_channel;
398 }
399 void TriggerProcessPacket(MediaProcessorDirection direction) {
400 webrtc::ProcessingTypes pt =
401 (direction == cricket::MPD_TX) ?
402 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
403 if (media_processor_ != NULL) {
404 media_processor_->Process(0,
405 pt,
406 NULL,
407 0,
408 0,
409 true);
410 }
411 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200412 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000413 if (fail_create_channel_) {
414 return -1;
415 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000416 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000417 for (int i = 0; i < NumOfCodecs(); ++i) {
418 webrtc::CodecInst codec;
419 GetCodec(i, codec);
420 ch->recv_codecs.push_back(codec);
421 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200422 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
423 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
424 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200425 ch->neteq_fast_accelerate =
426 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000427 channels_[++last_channel_] = ch;
428 return last_channel_;
429 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000430 int GetSendRtpExtensionId(int channel, const std::string& extension) {
431 WEBRTC_ASSERT_CHANNEL(channel);
432 if (extension == kRtpAudioLevelHeaderExtension) {
433 return channels_[channel]->send_audio_level_ext_;
434 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
435 return channels_[channel]->send_absolute_sender_time_ext_;
436 }
437 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000438 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000439 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
440 WEBRTC_ASSERT_CHANNEL(channel);
441 if (extension == kRtpAudioLevelHeaderExtension) {
442 return channels_[channel]->receive_audio_level_ext_;
443 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
444 return channels_[channel]->receive_absolute_sender_time_ext_;
445 }
446 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000447 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000449 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
450
Minyue2013aec2015-05-13 14:14:42 +0200451 int GetAssociateSendChannel(int channel) {
452 return channels_[channel]->associate_send_channel;
453 }
454
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 WEBRTC_STUB(Release, ());
456
457 // webrtc::VoEBase
458 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
459 webrtc::VoiceEngineObserver& observer)) {
460 observer_ = &observer;
461 return 0;
462 }
463 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
464 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
465 webrtc::AudioProcessing* audioproc)) {
466 inited_ = true;
467 return 0;
468 }
469 WEBRTC_FUNC(Terminate, ()) {
470 inited_ = false;
471 return 0;
472 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000473 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000474 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200477 webrtc::Config empty_config;
478 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200480 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
481 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000482 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 WEBRTC_FUNC(DeleteChannel, (int channel)) {
484 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200485 for (const auto& ch : channels_) {
486 if (ch.second->associate_send_channel == channel) {
487 ch.second->associate_send_channel = -1;
488 }
489 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490 delete channels_[channel];
491 channels_.erase(channel);
492 return 0;
493 }
494 WEBRTC_STUB(StartReceive, (int channel));
495 WEBRTC_FUNC(StartPlayout, (int channel)) {
496 if (playout_fail_channel_ != channel) {
497 WEBRTC_CHECK_CHANNEL(channel);
498 channels_[channel]->playout = true;
499 return 0;
500 } else {
501 // When playout_fail_channel_ == channel, fail the StartPlayout on this
502 // channel.
503 return -1;
504 }
505 }
506 WEBRTC_FUNC(StartSend, (int channel)) {
507 if (send_fail_channel_ != channel) {
508 WEBRTC_CHECK_CHANNEL(channel);
509 channels_[channel]->send = true;
510 return 0;
511 } else {
512 // When send_fail_channel_ == channel, fail the StartSend on this
513 // channel.
514 return -1;
515 }
516 }
517 WEBRTC_STUB(StopReceive, (int channel));
518 WEBRTC_FUNC(StopPlayout, (int channel)) {
519 WEBRTC_CHECK_CHANNEL(channel);
520 channels_[channel]->playout = false;
521 return 0;
522 }
523 WEBRTC_FUNC(StopSend, (int channel)) {
524 WEBRTC_CHECK_CHANNEL(channel);
525 channels_[channel]->send = false;
526 return 0;
527 }
528 WEBRTC_STUB(GetVersion, (char version[1024]));
529 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200530 WEBRTC_FUNC(AssociateSendChannel, (int channel,
531 int accociate_send_channel)) {
532 WEBRTC_CHECK_CHANNEL(channel);
533 channels_[channel]->associate_send_channel = accociate_send_channel;
534 return 0;
535 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536
537 // webrtc::VoECodec
538 WEBRTC_FUNC(NumOfCodecs, ()) {
539 return num_codecs_;
540 }
541 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
542 if (index < 0 || index >= NumOfCodecs()) {
543 return -1;
544 }
545 const cricket::AudioCodec& c(*codecs_[index]);
546 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000547 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548 codec.plfreq = c.clockrate;
549 codec.pacsize = 0;
550 codec.channels = c.channels;
551 codec.rate = c.bitrate;
552 return 0;
553 }
554 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
555 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000556 // To match the behavior of the real implementation.
557 if (_stricmp(codec.plname, "telephone-event") == 0 ||
558 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
559 _stricmp(codec.plname, "CN") == 0 ||
560 _stricmp(codec.plname, "red") == 0 ) {
561 return -1;
562 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000564 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 return 0;
566 }
567 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
568 WEBRTC_CHECK_CHANNEL(channel);
569 codec = channels_[channel]->send_codec;
570 return 0;
571 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200572 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000573 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
574 WEBRTC_CHECK_CHANNEL(channel);
575 const Channel* c = channels_[channel];
576 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
577 it_packet != c->packets.end(); ++it_packet) {
578 int pltype;
579 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
580 continue;
581 }
582 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
583 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
584 ++it_codec) {
585 if (it_codec->pltype == pltype) {
586 codec = *it_codec;
587 return 0;
588 }
589 }
590 }
591 return -1;
592 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 WEBRTC_FUNC(SetRecPayloadType, (int channel,
594 const webrtc::CodecInst& codec)) {
595 WEBRTC_CHECK_CHANNEL(channel);
596 Channel* ch = channels_[channel];
597 if (ch->playout)
598 return -1; // Channel is in use.
599 // Check if something else already has this slot.
600 if (codec.pltype != -1) {
601 for (std::vector<webrtc::CodecInst>::iterator it =
602 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
603 if (it->pltype == codec.pltype &&
604 _stricmp(it->plname, codec.plname) != 0) {
605 return -1;
606 }
607 }
608 }
609 // Otherwise try to find this codec and update its payload type.
610 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
611 it != ch->recv_codecs.end(); ++it) {
612 if (strcmp(it->plname, codec.plname) == 0 &&
613 it->plfreq == codec.plfreq) {
614 it->pltype = codec.pltype;
615 it->channels = codec.channels;
616 return 0;
617 }
618 }
619 return -1; // not found
620 }
621 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
622 webrtc::PayloadFrequencies frequency)) {
623 WEBRTC_CHECK_CHANNEL(channel);
624 if (frequency == webrtc::kFreq8000Hz) {
625 channels_[channel]->cn8_type = type;
626 } else if (frequency == webrtc::kFreq16000Hz) {
627 channels_[channel]->cn16_type = type;
628 }
629 return 0;
630 }
631 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
632 WEBRTC_CHECK_CHANNEL(channel);
633 Channel* ch = channels_[channel];
634 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
635 it != ch->recv_codecs.end(); ++it) {
636 if (strcmp(it->plname, codec.plname) == 0 &&
637 it->plfreq == codec.plfreq &&
638 it->channels == codec.channels &&
639 it->pltype != -1) {
640 codec.pltype = it->pltype;
641 return 0;
642 }
643 }
644 return -1; // not found
645 }
646 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
647 bool disableDTX)) {
648 WEBRTC_CHECK_CHANNEL(channel);
649 if (channels_[channel]->send_codec.channels == 2) {
650 // Replicating VoE behavior; VAD cannot be enabled for stereo.
651 return -1;
652 }
653 channels_[channel]->vad = enable;
654 return 0;
655 }
656 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
657 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000658
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000659 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
660 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000661 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000662 // Return -1 if current send codec is not Opus.
663 // TODO(minyue): Excludes other codecs if they support inband FEC.
664 return -1;
665 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000666 channels_[channel]->codec_fec = enable;
667 return 0;
668 }
669 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
670 WEBRTC_CHECK_CHANNEL(channel);
671 enable = channels_[channel]->codec_fec;
672 return 0;
673 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000674
675 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
676 WEBRTC_CHECK_CHANNEL(channel);
677 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
678 // Return -1 if current send codec is not Opus.
679 return -1;
680 }
681 if (frequency_hz <= 8000)
682 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
683 else if (frequency_hz <= 12000)
684 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
685 else if (frequency_hz <= 16000)
686 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
687 else if (frequency_hz <= 24000)
688 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
689 else
690 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
691 return 0;
692 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000694 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
695 WEBRTC_CHECK_CHANNEL(channel);
696 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
697 // Return -1 if current send codec is not Opus.
698 return -1;
699 }
700 channels_[channel]->opus_dtx = enable_dtx;
701 return 0;
702 }
703
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 // webrtc::VoEDtmf
705 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
706 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
707 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
708 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
709 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
710 return 0;
711 }
712
713 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
714 (int channel, unsigned char type)) {
715 channels_[channel]->dtmf_type = type;
716 return 0;
717 };
718 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
719 (int channel, unsigned char& type));
720
721 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
722 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 WEBRTC_FUNC(PlayDtmfTone,
725 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
726 dtmf_info_.dtmf_event_code = event_code;
727 dtmf_info_.dtmf_length_ms = length_ms;
728 return 0;
729 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730
731 // webrtc::VoEFile
732 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
733 bool loop, webrtc::FileFormats format,
734 float volumeScaling, int startPointMs,
735 int stopPointMs)) {
736 WEBRTC_CHECK_CHANNEL(channel);
737 channels_[channel]->file = true;
738 return 0;
739 }
740 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
741 webrtc::FileFormats format,
742 float volumeScaling, int startPointMs,
743 int stopPointMs)) {
744 WEBRTC_CHECK_CHANNEL(channel);
745 channels_[channel]->file = true;
746 return 0;
747 }
748 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
749 WEBRTC_CHECK_CHANNEL(channel);
750 channels_[channel]->file = false;
751 return 0;
752 }
753 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
754 WEBRTC_CHECK_CHANNEL(channel);
755 return (channels_[channel]->file) ? 1 : 0;
756 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
758 const char* fileNameUTF8,
759 bool loop,
760 bool mixWithMicrophone,
761 webrtc::FileFormats format,
762 float volumeScaling));
763 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
764 webrtc::InStream* stream,
765 bool mixWithMicrophone,
766 webrtc::FileFormats format,
767 float volumeScaling));
768 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
769 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
771 webrtc::CodecInst* compression,
772 int maxSizeBytes));
773 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
774 webrtc::CodecInst* compression));
775 WEBRTC_STUB(StopRecordingPlayout, (int channel));
776 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
777 webrtc::CodecInst* compression,
778 int maxSizeBytes)) {
779 if (fail_start_recording_microphone_) {
780 return -1;
781 }
782 recording_microphone_ = true;
783 return 0;
784 }
785 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
786 webrtc::CodecInst* compression)) {
787 if (fail_start_recording_microphone_) {
788 return -1;
789 }
790 recording_microphone_ = true;
791 return 0;
792 }
793 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
794 if (!recording_microphone_) {
795 return -1;
796 }
797 recording_microphone_ = false;
798 return 0;
799 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800
801 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
803 return GetNumDevices(num);
804 }
805 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
806 return GetNumDevices(num);
807 }
808 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
809 return GetDeviceName(i, name, guid);
810 }
811 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
812 return GetDeviceName(i, name, guid);
813 }
814 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
815 WEBRTC_STUB(SetPlayoutDevice, (int));
816 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
817 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000818 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
819 recording_sample_rate_ = samples_per_sec;
820 return 0;
821 }
822 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
823 *samples_per_sec = recording_sample_rate_;
824 return 0;
825 }
826 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
827 playout_sample_rate_ = samples_per_sec;
828 return 0;
829 }
830 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
831 *samples_per_sec = playout_sample_rate_;
832 return 0;
833 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000835 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836
837 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000838 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
839 webrtc::NetworkStatistics& ns)) {
840 WEBRTC_CHECK_CHANNEL(channel);
841 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
842 return 0;
843 }
844
wu@webrtc.org24301a62013-12-13 19:17:43 +0000845 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
846 webrtc::AudioDecodingCallStats*)) {
847 WEBRTC_CHECK_CHANNEL(channel);
848 return 0;
849 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850
851 // webrtc::VoENetwork
852 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
853 webrtc::Transport& transport)) {
854 WEBRTC_CHECK_CHANNEL(channel);
855 channels_[channel]->external_transport = true;
856 return 0;
857 }
858 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
859 WEBRTC_CHECK_CHANNEL(channel);
860 channels_[channel]->external_transport = false;
861 return 0;
862 }
863 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000864 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 WEBRTC_CHECK_CHANNEL(channel);
866 if (!channels_[channel]->external_transport) return -1;
867 channels_[channel]->packets.push_back(
868 std::string(static_cast<const char*>(data), length));
869 return 0;
870 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000871 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000872 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000873 const webrtc::PacketTime& packet_time)) {
874 WEBRTC_CHECK_CHANNEL(channel);
875 if (ReceivedRTPPacket(channel, data, length) == -1) {
876 return -1;
877 }
878 channels_[channel]->last_rtp_packet_time = packet_time;
879 return 0;
880 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000881
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000883 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884
885 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
887 WEBRTC_CHECK_CHANNEL(channel);
888 channels_[channel]->send_ssrc = ssrc;
889 return 0;
890 }
891 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
892 WEBRTC_CHECK_CHANNEL(channel);
893 ssrc = channels_[channel]->send_ssrc;
894 return 0;
895 }
896 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000897 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
898 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000900 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
901 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 return 0;
903 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000904 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
905 unsigned char id)) {
906 WEBRTC_CHECK_CHANNEL(channel);
907 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
908 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
909 return 0;
910 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000911 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
912 unsigned char id)) {
913 WEBRTC_CHECK_CHANNEL(channel);
914 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
915 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
916 return 0;
917 }
918 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
919 unsigned char id)) {
920 WEBRTC_CHECK_CHANNEL(channel);
921 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
922 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
923 return 0;
924 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000925
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
927 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
928 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
929 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
930 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
931 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
932 unsigned int& NTPLow,
933 unsigned int& timestamp,
934 unsigned int& playoutTimestamp,
935 unsigned int* jitter,
936 unsigned short* fractionLost));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
938 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
939 WEBRTC_CHECK_CHANNEL(channel);
940 webrtc::ReportBlock block;
941 block.source_SSRC = channels_[channel]->send_ssrc;
942 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
943 if (send_codec.pltype >= 0) {
944 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
945 if (send_codec.plfreq / 1000 > 0) {
946 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
947 }
948 block.cumulative_num_packets_lost = kIntStatValue;
949 block.extended_highest_sequence_number = kIntStatValue;
950 receive_blocks->push_back(block);
951 }
952 return 0;
953 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
955 unsigned int& maxJitterMs,
956 unsigned int& discardedPackets));
957 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
958 WEBRTC_CHECK_CHANNEL(channel);
959 stats.fractionLost = static_cast<int16>(kIntStatValue);
960 stats.cumulativeLost = kIntStatValue;
961 stats.extendedMax = kIntStatValue;
962 stats.jitterSamples = kIntStatValue;
963 stats.rttMs = kIntStatValue;
964 stats.bytesSent = kIntStatValue;
965 stats.packetsSent = kIntStatValue;
966 stats.bytesReceived = kIntStatValue;
967 stats.packetsReceived = kIntStatValue;
968 return 0;
969 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000970 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000971 return SetFECStatus(channel, enable, redPayloadtype);
972 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000973 // TODO(minyue): remove the below function when transition to SetREDStatus
974 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
976 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000977 channels_[channel]->red = enable;
978 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 return 0;
980 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000981 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000982 return GetFECStatus(channel, enable, redPayloadtype);
983 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000984 // TODO(minyue): remove the below function when transition to GetREDStatus
985 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
987 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000988 enable = channels_[channel]->red;
989 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 return 0;
991 }
992 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
993 WEBRTC_CHECK_CHANNEL(channel);
994 channels_[channel]->nack = enable;
995 channels_[channel]->nack_max_packets = maxNoPackets;
996 return 0;
997 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998
999 // webrtc::VoEVideoSync
1000 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1001 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001002 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1004 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1005 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1006 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1007 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1008 int* playout_buffer_delay_ms));
1009 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1010
1011 // webrtc::VoEVolumeControl
1012 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1013 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 WEBRTC_STUB(SetMicVolume, (unsigned int));
1015 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1016 WEBRTC_STUB(SetInputMute, (int, bool));
1017 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1019 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1020 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1021 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1022 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1023 WEBRTC_CHECK_CHANNEL(channel);
1024 channels_[channel]->volume_scale= scale;
1025 return 0;
1026 }
1027 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1028 WEBRTC_CHECK_CHANNEL(channel);
1029 scale = channels_[channel]->volume_scale;
1030 return 0;
1031 }
1032 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1033 WEBRTC_CHECK_CHANNEL(channel);
1034 channels_[channel]->volume_pan_left = left;
1035 channels_[channel]->volume_pan_right = right;
1036 return 0;
1037 }
1038 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1039 WEBRTC_CHECK_CHANNEL(channel);
1040 left = channels_[channel]->volume_pan_left;
1041 right = channels_[channel]->volume_pan_right;
1042 return 0;
1043 }
1044
1045 // webrtc::VoEAudioProcessing
1046 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1047 ns_enabled_ = enable;
1048 ns_mode_ = mode;
1049 return 0;
1050 }
1051 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1052 enabled = ns_enabled_;
1053 mode = ns_mode_;
1054 return 0;
1055 }
1056
1057 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1058 agc_enabled_ = enable;
1059 agc_mode_ = mode;
1060 return 0;
1061 }
1062 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1063 enabled = agc_enabled_;
1064 mode = agc_mode_;
1065 return 0;
1066 }
1067
1068 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1069 agc_config_ = config;
1070 return 0;
1071 }
1072 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1073 config = agc_config_;
1074 return 0;
1075 }
1076 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1077 ec_enabled_ = enable;
1078 ec_mode_ = mode;
1079 return 0;
1080 }
1081 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1082 enabled = ec_enabled_;
1083 mode = ec_mode_;
1084 return 0;
1085 }
1086 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1087 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1088 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1089 WEBRTC_STUB(DelayOffsetMs, ());
1090 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1091 aecm_mode_ = mode;
1092 cng_enabled_ = enableCNG;
1093 return 0;
1094 }
1095 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1096 mode = aecm_mode_;
1097 enabledCNG = cng_enabled_;
1098 return 0;
1099 }
1100 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1101 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1102 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001103 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1104 webrtc::AgcModes mode)) {
1105 channels_[channel]->rx_agc_enabled = enable;
1106 channels_[channel]->rx_agc_mode = mode;
1107 return 0;
1108 }
1109 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1110 webrtc::AgcModes& mode)) {
1111 enabled = channels_[channel]->rx_agc_enabled;
1112 mode = channels_[channel]->rx_agc_mode;
1113 return 0;
1114 }
1115
1116 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1117 channels_[channel]->rx_agc_config = config;
1118 return 0;
1119 }
1120 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1121 config = channels_[channel]->rx_agc_config;
1122 return 0;
1123 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124
1125 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1126 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1127 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1128 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1129 ec_metrics_enabled_ = enable;
1130 return 0;
1131 }
1132 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1133 enabled = ec_metrics_enabled_;
1134 return 0;
1135 }
1136 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001137 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1138 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139
1140 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001141 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 WEBRTC_STUB(StopDebugRecording, ());
1143
1144 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1145 typing_detection_enabled_ = enable;
1146 return 0;
1147 }
1148 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1149 enabled = typing_detection_enabled_;
1150 return 0;
1151 }
1152
1153 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1154 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1155 int costPerTyping,
1156 int reportingThreshold,
1157 int penaltyDecay,
1158 int typeEventDelay));
1159 int EnableHighPassFilter(bool enable) {
1160 highpass_filter_enabled_ = enable;
1161 return 0;
1162 }
1163 bool IsHighPassFilterEnabled() {
1164 return highpass_filter_enabled_;
1165 }
1166 bool IsStereoChannelSwappingEnabled() {
1167 return stereo_swapping_enabled_;
1168 }
1169 void EnableStereoChannelSwapping(bool enable) {
1170 stereo_swapping_enabled_ = enable;
1171 }
1172 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1173 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1174 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1175 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1176 }
1177 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1178 return (dtmf_info_.dtmf_event_code == event_code &&
1179 dtmf_info_.dtmf_length_ms == length_ms);
1180 }
1181 // webrtc::VoEExternalMedia
1182 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1183 (int channel, webrtc::ProcessingTypes type,
1184 webrtc::VoEMediaProcess& processObject)) {
1185 WEBRTC_CHECK_CHANNEL(channel);
1186 if (channels_[channel]->media_processor_registered) {
1187 return -1;
1188 }
1189 channels_[channel]->media_processor_registered = true;
1190 media_processor_ = &processObject;
1191 return 0;
1192 }
1193 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1194 (int channel, webrtc::ProcessingTypes type)) {
1195 WEBRTC_CHECK_CHANNEL(channel);
1196 if (!channels_[channel]->media_processor_registered) {
1197 return -1;
1198 }
1199 channels_[channel]->media_processor_registered = false;
1200 media_processor_ = NULL;
1201 return 0;
1202 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1204 webrtc::AudioFrame* frame));
1205 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
Henrik Lundin64dad832015-05-11 12:44:23 +02001206 int GetNetEqCapacity() const {
1207 auto ch = channels_.find(last_channel_);
1208 ASSERT(ch != channels_.end());
1209 return ch->second->neteq_capacity;
1210 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +02001211 bool GetNetEqFastAccelerate() const {
1212 auto ch = channels_.find(last_channel_);
1213 ASSERT(ch != channels_.end());
1214 return ch->second->neteq_fast_accelerate;
1215 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001216
1217 private:
1218 int GetNumDevices(int& num) {
1219#ifdef WIN32
1220 num = 1;
1221#else
1222 // On non-Windows platforms VE adds a special entry for the default device,
1223 // so if there is one physical device then there are two entries in the
1224 // list.
1225 num = 2;
1226#endif
1227 return 0;
1228 }
1229
1230 int GetDeviceName(int i, char* name, char* guid) {
1231 const char *s;
1232#ifdef WIN32
1233 if (0 == i) {
1234 s = kFakeDeviceName;
1235 } else {
1236 return -1;
1237 }
1238#else
1239 // See comment above.
1240 if (0 == i) {
1241 s = kFakeDefaultDeviceName;
1242 } else if (1 == i) {
1243 s = kFakeDeviceName;
1244 } else {
1245 return -1;
1246 }
1247#endif
1248 strcpy(name, s);
1249 guid[0] = '\0';
1250 return 0;
1251 }
1252
1253 bool inited_;
1254 int last_channel_;
1255 std::map<int, Channel*> channels_;
1256 bool fail_create_channel_;
1257 const cricket::AudioCodec* const* codecs_;
1258 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001259 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 bool ec_enabled_;
1261 bool ec_metrics_enabled_;
1262 bool cng_enabled_;
1263 bool ns_enabled_;
1264 bool agc_enabled_;
1265 bool highpass_filter_enabled_;
1266 bool stereo_swapping_enabled_;
1267 bool typing_detection_enabled_;
1268 webrtc::EcModes ec_mode_;
1269 webrtc::AecmModes aecm_mode_;
1270 webrtc::NsModes ns_mode_;
1271 webrtc::AgcModes agc_mode_;
1272 webrtc::AgcConfig agc_config_;
1273 webrtc::VoiceEngineObserver* observer_;
1274 int playout_fail_channel_;
1275 int send_fail_channel_;
1276 bool fail_start_recording_microphone_;
1277 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001278 int recording_sample_rate_;
1279 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 DtmfInfo dtmf_info_;
1281 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001282 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283};
1284
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001285#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1286
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287} // namespace cricket
1288
1289#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_