blob: 960bad3102eb570c37445f37e5268025bac6f7b5 [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"
41#include "webrtc/base/gunit.h"
42#include "webrtc/base/stringutils.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000043#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000044#include "webrtc/video_engine/include/vie_network.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
henrike@webrtc.org79047f92014-03-06 23:46:59 +000087// Verify the header extension ID, if enabled, is within the bounds specified in
88// [RFC5285]: 1-14 inclusive.
89#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
90 do { \
91 if (enable && (id < 1 || id > 14)) { \
92 return -1; \
93 } \
94 } while (0);
95
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000096class FakeAudioProcessing : public webrtc::AudioProcessing {
97 public:
98 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
99
100 WEBRTC_STUB(Initialize, ())
101 WEBRTC_STUB(Initialize, (
102 int input_sample_rate_hz,
103 int output_sample_rate_hz,
104 int reverse_sample_rate_hz,
105 webrtc::AudioProcessing::ChannelLayout input_layout,
106 webrtc::AudioProcessing::ChannelLayout output_layout,
107 webrtc::AudioProcessing::ChannelLayout reverse_layout));
108
109 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
110 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
111 }
112
113 WEBRTC_STUB(set_sample_rate_hz, (int rate));
114 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
115 WEBRTC_STUB_CONST(sample_rate_hz, ());
116 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
117 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
118 WEBRTC_STUB_CONST(num_input_channels, ());
119 WEBRTC_STUB_CONST(num_output_channels, ());
120 WEBRTC_STUB_CONST(num_reverse_channels, ());
121 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
122 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
123 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
124 WEBRTC_STUB(ProcessStream, (
125 const float* const* src,
126 int samples_per_channel,
127 int input_sample_rate_hz,
128 webrtc::AudioProcessing::ChannelLayout input_layout,
129 int output_sample_rate_hz,
130 webrtc::AudioProcessing::ChannelLayout output_layout,
131 float* const* dest));
132 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
133 WEBRTC_STUB(AnalyzeReverseStream, (
134 const float* const* data,
135 int samples_per_channel,
136 int sample_rate_hz,
137 webrtc::AudioProcessing::ChannelLayout layout));
138 WEBRTC_STUB(set_stream_delay_ms, (int delay));
139 WEBRTC_STUB_CONST(stream_delay_ms, ());
140 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
141 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
142 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
143 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
144 WEBRTC_STUB_CONST(delay_offset_ms, ());
145 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
146 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
147 WEBRTC_STUB(StopDebugRecording, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000148 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
149 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000150 return NULL;
151 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000152 webrtc::GainControl* gain_control() const override { return NULL; }
153 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
154 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
155 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
156 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000157
158 bool experimental_ns_enabled() {
159 return experimental_ns_enabled_;
160 }
161
162 private:
163 bool experimental_ns_enabled_;
164};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000165
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166class FakeWebRtcVoiceEngine
167 : public webrtc::VoEAudioProcessing,
168 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
169 public webrtc::VoEFile, public webrtc::VoEHardware,
170 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
171 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
172 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
173 public:
174 struct DtmfInfo {
175 DtmfInfo()
176 : dtmf_event_code(-1),
177 dtmf_out_of_band(false),
178 dtmf_length_ms(-1) {}
179 int dtmf_event_code;
180 bool dtmf_out_of_band;
181 int dtmf_length_ms;
182 };
183 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000184 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 : external_transport(false),
186 send(false),
187 playout(false),
188 volume_scale(1.0),
189 volume_pan_left(1.0),
190 volume_pan_right(1.0),
191 file(false),
192 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000193 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000194 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000195 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000196 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 nack(false),
198 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000199 rx_agc_enabled(false),
200 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 cn8_type(13),
202 cn16_type(105),
203 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000204 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 nack_max_packets(0),
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000206 vie_network(NULL),
207 video_channel(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000209 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000210 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000211 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000212 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000214 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 }
216 bool external_transport;
217 bool send;
218 bool playout;
219 float volume_scale;
220 float volume_pan_left;
221 float volume_pan_right;
222 bool file;
223 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000224 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000225 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000226 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000227 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 bool nack;
229 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000230 bool rx_agc_enabled;
231 webrtc::AgcModes rx_agc_mode;
232 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 int cn8_type;
234 int cn16_type;
235 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000236 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 int nack_max_packets;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000238 webrtc::ViENetwork* vie_network;
239 int video_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000241 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000242 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000243 int send_absolute_sender_time_ext_;
244 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 DtmfInfo dtmf_info;
246 std::vector<webrtc::CodecInst> recv_codecs;
247 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000248 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 std::list<std::string> packets;
250 };
251
252 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
253 int num_codecs)
254 : inited_(false),
255 last_channel_(-1),
256 fail_create_channel_(false),
257 codecs_(codecs),
258 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000259 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 ec_enabled_(false),
261 ec_metrics_enabled_(false),
262 cng_enabled_(false),
263 ns_enabled_(false),
264 agc_enabled_(false),
265 highpass_filter_enabled_(false),
266 stereo_swapping_enabled_(false),
267 typing_detection_enabled_(false),
268 ec_mode_(webrtc::kEcDefault),
269 aecm_mode_(webrtc::kAecmSpeakerphone),
270 ns_mode_(webrtc::kNsDefault),
271 agc_mode_(webrtc::kAgcDefault),
272 observer_(NULL),
273 playout_fail_channel_(-1),
274 send_fail_channel_(-1),
275 fail_start_recording_microphone_(false),
276 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000277 recording_sample_rate_(-1),
278 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 media_processor_(NULL) {
280 memset(&agc_config_, 0, sizeof(agc_config_));
281 }
282 ~FakeWebRtcVoiceEngine() {
283 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
284 // destructors, but just in case ...
285 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
286 i != channels_.end(); ++i) {
287 delete i->second;
288 }
289 }
290
291 bool IsExternalMediaProcessorRegistered() const {
292 return media_processor_ != NULL;
293 }
294 bool IsInited() const { return inited_; }
295 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000296 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
297 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
298 iter != channels_.end(); ++iter) {
299 if (local_ssrc == iter->second->send_ssrc)
300 return iter->first;
301 }
302 return -1;
303 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000304 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 bool GetPlayout(int channel) {
306 return channels_[channel]->playout;
307 }
308 bool GetSend(int channel) {
309 return channels_[channel]->send;
310 }
311 bool GetRecordingMicrophone() {
312 return recording_microphone_;
313 }
314 bool GetVAD(int channel) {
315 return channels_[channel]->vad;
316 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000317 bool GetRED(int channel) {
318 return channels_[channel]->red;
319 }
320 bool GetCodecFEC(int channel) {
321 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000323 int GetMaxEncodingBandwidth(int channel) {
324 return channels_[channel]->max_encoding_bandwidth;
325 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 bool GetNACK(int channel) {
327 return channels_[channel]->nack;
328 }
329 int GetNACKMaxPackets(int channel) {
330 return channels_[channel]->nack_max_packets;
331 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000332 webrtc::ViENetwork* GetViENetwork(int channel) {
333 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000334 // WARNING: This pointer is for verification purposes only. Calling
335 // functions on it may result in undefined behavior!
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000336 return channels_[channel]->vie_network;
337 }
338 int GetVideoChannel(int channel) {
339 WEBRTC_ASSERT_CHANNEL(channel);
340 return channels_[channel]->video_channel;
341 }
342 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
343 WEBRTC_ASSERT_CHANNEL(channel);
344 return channels_[channel]->last_rtp_packet_time;
345 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 int GetSendCNPayloadType(int channel, bool wideband) {
347 return (wideband) ?
348 channels_[channel]->cn16_type :
349 channels_[channel]->cn8_type;
350 }
351 int GetSendTelephoneEventPayloadType(int channel) {
352 return channels_[channel]->dtmf_type;
353 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000354 int GetSendREDPayloadType(int channel) {
355 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 }
357 bool CheckPacket(int channel, const void* data, size_t len) {
358 bool result = !CheckNoPacket(channel);
359 if (result) {
360 std::string packet = channels_[channel]->packets.front();
361 result = (packet == std::string(static_cast<const char*>(data), len));
362 channels_[channel]->packets.pop_front();
363 }
364 return result;
365 }
366 bool CheckNoPacket(int channel) {
367 return channels_[channel]->packets.empty();
368 }
369 void TriggerCallbackOnError(int channel_num, int err_code) {
370 ASSERT(observer_ != NULL);
371 observer_->CallbackOnError(channel_num, err_code);
372 }
373 void set_playout_fail_channel(int channel) {
374 playout_fail_channel_ = channel;
375 }
376 void set_send_fail_channel(int channel) {
377 send_fail_channel_ = channel;
378 }
379 void set_fail_start_recording_microphone(
380 bool fail_start_recording_microphone) {
381 fail_start_recording_microphone_ = fail_start_recording_microphone;
382 }
383 void set_fail_create_channel(bool fail_create_channel) {
384 fail_create_channel_ = fail_create_channel;
385 }
386 void TriggerProcessPacket(MediaProcessorDirection direction) {
387 webrtc::ProcessingTypes pt =
388 (direction == cricket::MPD_TX) ?
389 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
390 if (media_processor_ != NULL) {
391 media_processor_->Process(0,
392 pt,
393 NULL,
394 0,
395 0,
396 true);
397 }
398 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000399 int AddChannel() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000400 if (fail_create_channel_) {
401 return -1;
402 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000403 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000404 for (int i = 0; i < NumOfCodecs(); ++i) {
405 webrtc::CodecInst codec;
406 GetCodec(i, codec);
407 ch->recv_codecs.push_back(codec);
408 }
409 channels_[++last_channel_] = ch;
410 return last_channel_;
411 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000412 int GetSendRtpExtensionId(int channel, const std::string& extension) {
413 WEBRTC_ASSERT_CHANNEL(channel);
414 if (extension == kRtpAudioLevelHeaderExtension) {
415 return channels_[channel]->send_audio_level_ext_;
416 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
417 return channels_[channel]->send_absolute_sender_time_ext_;
418 }
419 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000420 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000421 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
422 WEBRTC_ASSERT_CHANNEL(channel);
423 if (extension == kRtpAudioLevelHeaderExtension) {
424 return channels_[channel]->receive_audio_level_ext_;
425 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
426 return channels_[channel]->receive_absolute_sender_time_ext_;
427 }
428 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000429 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000431 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
432
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433 WEBRTC_STUB(Release, ());
434
435 // webrtc::VoEBase
436 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
437 webrtc::VoiceEngineObserver& observer)) {
438 observer_ = &observer;
439 return 0;
440 }
441 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
442 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
443 webrtc::AudioProcessing* audioproc)) {
444 inited_ = true;
445 return 0;
446 }
447 WEBRTC_FUNC(Terminate, ()) {
448 inited_ = false;
449 return 0;
450 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000451 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000452 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000455 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000457 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
458 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000459 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 WEBRTC_FUNC(DeleteChannel, (int channel)) {
461 WEBRTC_CHECK_CHANNEL(channel);
462 delete channels_[channel];
463 channels_.erase(channel);
464 return 0;
465 }
466 WEBRTC_STUB(StartReceive, (int channel));
467 WEBRTC_FUNC(StartPlayout, (int channel)) {
468 if (playout_fail_channel_ != channel) {
469 WEBRTC_CHECK_CHANNEL(channel);
470 channels_[channel]->playout = true;
471 return 0;
472 } else {
473 // When playout_fail_channel_ == channel, fail the StartPlayout on this
474 // channel.
475 return -1;
476 }
477 }
478 WEBRTC_FUNC(StartSend, (int channel)) {
479 if (send_fail_channel_ != channel) {
480 WEBRTC_CHECK_CHANNEL(channel);
481 channels_[channel]->send = true;
482 return 0;
483 } else {
484 // When send_fail_channel_ == channel, fail the StartSend on this
485 // channel.
486 return -1;
487 }
488 }
489 WEBRTC_STUB(StopReceive, (int channel));
490 WEBRTC_FUNC(StopPlayout, (int channel)) {
491 WEBRTC_CHECK_CHANNEL(channel);
492 channels_[channel]->playout = false;
493 return 0;
494 }
495 WEBRTC_FUNC(StopSend, (int channel)) {
496 WEBRTC_CHECK_CHANNEL(channel);
497 channels_[channel]->send = false;
498 return 0;
499 }
500 WEBRTC_STUB(GetVersion, (char version[1024]));
501 WEBRTC_STUB(LastError, ());
502 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
503 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504
505 // webrtc::VoECodec
506 WEBRTC_FUNC(NumOfCodecs, ()) {
507 return num_codecs_;
508 }
509 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
510 if (index < 0 || index >= NumOfCodecs()) {
511 return -1;
512 }
513 const cricket::AudioCodec& c(*codecs_[index]);
514 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000515 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000516 codec.plfreq = c.clockrate;
517 codec.pacsize = 0;
518 codec.channels = c.channels;
519 codec.rate = c.bitrate;
520 return 0;
521 }
522 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
523 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000524 // To match the behavior of the real implementation.
525 if (_stricmp(codec.plname, "telephone-event") == 0 ||
526 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
527 _stricmp(codec.plname, "CN") == 0 ||
528 _stricmp(codec.plname, "red") == 0 ) {
529 return -1;
530 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000532 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 return 0;
534 }
535 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
536 WEBRTC_CHECK_CHANNEL(channel);
537 codec = channels_[channel]->send_codec;
538 return 0;
539 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000540 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
541 WEBRTC_CHECK_CHANNEL(channel);
542 const Channel* c = channels_[channel];
543 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
544 it_packet != c->packets.end(); ++it_packet) {
545 int pltype;
546 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
547 continue;
548 }
549 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
550 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
551 ++it_codec) {
552 if (it_codec->pltype == pltype) {
553 codec = *it_codec;
554 return 0;
555 }
556 }
557 }
558 return -1;
559 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
561 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
562 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
563 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
564 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
565 bool useFixedFrameSize));
566 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
567 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
568 WEBRTC_FUNC(SetRecPayloadType, (int channel,
569 const webrtc::CodecInst& codec)) {
570 WEBRTC_CHECK_CHANNEL(channel);
571 Channel* ch = channels_[channel];
572 if (ch->playout)
573 return -1; // Channel is in use.
574 // Check if something else already has this slot.
575 if (codec.pltype != -1) {
576 for (std::vector<webrtc::CodecInst>::iterator it =
577 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
578 if (it->pltype == codec.pltype &&
579 _stricmp(it->plname, codec.plname) != 0) {
580 return -1;
581 }
582 }
583 }
584 // Otherwise try to find this codec and update its payload type.
585 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
586 it != ch->recv_codecs.end(); ++it) {
587 if (strcmp(it->plname, codec.plname) == 0 &&
588 it->plfreq == codec.plfreq) {
589 it->pltype = codec.pltype;
590 it->channels = codec.channels;
591 return 0;
592 }
593 }
594 return -1; // not found
595 }
596 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
597 webrtc::PayloadFrequencies frequency)) {
598 WEBRTC_CHECK_CHANNEL(channel);
599 if (frequency == webrtc::kFreq8000Hz) {
600 channels_[channel]->cn8_type = type;
601 } else if (frequency == webrtc::kFreq16000Hz) {
602 channels_[channel]->cn16_type = type;
603 }
604 return 0;
605 }
606 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
607 WEBRTC_CHECK_CHANNEL(channel);
608 Channel* ch = channels_[channel];
609 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
610 it != ch->recv_codecs.end(); ++it) {
611 if (strcmp(it->plname, codec.plname) == 0 &&
612 it->plfreq == codec.plfreq &&
613 it->channels == codec.channels &&
614 it->pltype != -1) {
615 codec.pltype = it->pltype;
616 return 0;
617 }
618 }
619 return -1; // not found
620 }
621 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
622 bool disableDTX)) {
623 WEBRTC_CHECK_CHANNEL(channel);
624 if (channels_[channel]->send_codec.channels == 2) {
625 // Replicating VoE behavior; VAD cannot be enabled for stereo.
626 return -1;
627 }
628 channels_[channel]->vad = enable;
629 return 0;
630 }
631 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
632 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000633
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000634 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
635 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000636 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000637 // Return -1 if current send codec is not Opus.
638 // TODO(minyue): Excludes other codecs if they support inband FEC.
639 return -1;
640 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000641 channels_[channel]->codec_fec = enable;
642 return 0;
643 }
644 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
645 WEBRTC_CHECK_CHANNEL(channel);
646 enable = channels_[channel]->codec_fec;
647 return 0;
648 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000649
650 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
651 WEBRTC_CHECK_CHANNEL(channel);
652 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
653 // Return -1 if current send codec is not Opus.
654 return -1;
655 }
656 if (frequency_hz <= 8000)
657 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
658 else if (frequency_hz <= 12000)
659 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
660 else if (frequency_hz <= 16000)
661 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
662 else if (frequency_hz <= 24000)
663 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
664 else
665 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
666 return 0;
667 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000669 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
670 WEBRTC_CHECK_CHANNEL(channel);
671 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
672 // Return -1 if current send codec is not Opus.
673 return -1;
674 }
675 channels_[channel]->opus_dtx = enable_dtx;
676 return 0;
677 }
678
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 // webrtc::VoEDtmf
680 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
681 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
682 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
683 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
684 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
685 return 0;
686 }
687
688 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
689 (int channel, unsigned char type)) {
690 channels_[channel]->dtmf_type = type;
691 return 0;
692 };
693 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
694 (int channel, unsigned char& type));
695
696 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
697 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 WEBRTC_FUNC(PlayDtmfTone,
700 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
701 dtmf_info_.dtmf_event_code = event_code;
702 dtmf_info_.dtmf_length_ms = length_ms;
703 return 0;
704 }
705 WEBRTC_STUB(StartPlayingDtmfTone,
706 (int eventCode, int attenuationDb = 10));
707 WEBRTC_STUB(StopPlayingDtmfTone, ());
708
709 // webrtc::VoEFile
710 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
711 bool loop, webrtc::FileFormats format,
712 float volumeScaling, int startPointMs,
713 int stopPointMs)) {
714 WEBRTC_CHECK_CHANNEL(channel);
715 channels_[channel]->file = true;
716 return 0;
717 }
718 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
719 webrtc::FileFormats format,
720 float volumeScaling, int startPointMs,
721 int stopPointMs)) {
722 WEBRTC_CHECK_CHANNEL(channel);
723 channels_[channel]->file = true;
724 return 0;
725 }
726 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
727 WEBRTC_CHECK_CHANNEL(channel);
728 channels_[channel]->file = false;
729 return 0;
730 }
731 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
732 WEBRTC_CHECK_CHANNEL(channel);
733 return (channels_[channel]->file) ? 1 : 0;
734 }
735 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
736 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
737 const char* fileNameUTF8,
738 bool loop,
739 bool mixWithMicrophone,
740 webrtc::FileFormats format,
741 float volumeScaling));
742 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
743 webrtc::InStream* stream,
744 bool mixWithMicrophone,
745 webrtc::FileFormats format,
746 float volumeScaling));
747 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
748 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
749 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
750 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
751 webrtc::CodecInst* compression,
752 int maxSizeBytes));
753 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
754 webrtc::CodecInst* compression));
755 WEBRTC_STUB(StopRecordingPlayout, (int channel));
756 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
757 webrtc::CodecInst* compression,
758 int maxSizeBytes)) {
759 if (fail_start_recording_microphone_) {
760 return -1;
761 }
762 recording_microphone_ = true;
763 return 0;
764 }
765 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
766 webrtc::CodecInst* compression)) {
767 if (fail_start_recording_microphone_) {
768 return -1;
769 }
770 recording_microphone_ = true;
771 return 0;
772 }
773 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
774 if (!recording_microphone_) {
775 return -1;
776 }
777 recording_microphone_ = false;
778 return 0;
779 }
780 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
781 const char* fileNameOutUTF8));
782 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
783 webrtc::OutStream* streamOut));
784 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
785 const char* fileNameOutUTF8));
786 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
787 webrtc::OutStream* streamOut));
788 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
789 const char* fileNameOutUTF8,
790 webrtc::CodecInst* compression));
791 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
792 webrtc::OutStream* streamOut,
793 webrtc::CodecInst* compression));
794 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
795 const char* fileNameOutUTF8));
796 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
797 webrtc::OutStream* streamOut));
798 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
799 webrtc::FileFormats format));
800 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
801
802 // webrtc::VoEHardware
803 WEBRTC_STUB(GetCPULoad, (int&));
804 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
805 return GetNumDevices(num);
806 }
807 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
808 return GetNumDevices(num);
809 }
810 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
811 return GetDeviceName(i, name, guid);
812 }
813 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
814 return GetDeviceName(i, name, guid);
815 }
816 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
817 WEBRTC_STUB(SetPlayoutDevice, (int));
818 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
819 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
820 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
821 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
822 WEBRTC_STUB(ResetAudioDevice, ());
823 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
824 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
825 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000826 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
827 recording_sample_rate_ = samples_per_sec;
828 return 0;
829 }
830 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
831 *samples_per_sec = recording_sample_rate_;
832 return 0;
833 }
834 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
835 playout_sample_rate_ = samples_per_sec;
836 return 0;
837 }
838 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
839 *samples_per_sec = playout_sample_rate_;
840 return 0;
841 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
843 virtual bool BuiltInAECIsEnabled() const { return true; }
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000844 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845
846 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000847 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
848 webrtc::NetworkStatistics& ns)) {
849 WEBRTC_CHECK_CHANNEL(channel);
850 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
851 return 0;
852 }
853
wu@webrtc.org24301a62013-12-13 19:17:43 +0000854 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
855 webrtc::AudioDecodingCallStats*)) {
856 WEBRTC_CHECK_CHANNEL(channel);
857 return 0;
858 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859
860 // webrtc::VoENetwork
861 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
862 webrtc::Transport& transport)) {
863 WEBRTC_CHECK_CHANNEL(channel);
864 channels_[channel]->external_transport = true;
865 return 0;
866 }
867 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
868 WEBRTC_CHECK_CHANNEL(channel);
869 channels_[channel]->external_transport = false;
870 return 0;
871 }
872 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000873 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 WEBRTC_CHECK_CHANNEL(channel);
875 if (!channels_[channel]->external_transport) return -1;
876 channels_[channel]->packets.push_back(
877 std::string(static_cast<const char*>(data), length));
878 return 0;
879 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000880 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000881 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000882 const webrtc::PacketTime& packet_time)) {
883 WEBRTC_CHECK_CHANNEL(channel);
884 if (ReceivedRTPPacket(channel, data, length) == -1) {
885 return -1;
886 }
887 channels_[channel]->last_rtp_packet_time = packet_time;
888 return 0;
889 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000890
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000892 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893
894 // webrtc::VoERTP_RTCP
895 WEBRTC_STUB(RegisterRTPObserver, (int channel,
896 webrtc::VoERTPObserver& observer));
897 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
899 WEBRTC_CHECK_CHANNEL(channel);
900 channels_[channel]->send_ssrc = ssrc;
901 return 0;
902 }
903 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
904 WEBRTC_CHECK_CHANNEL(channel);
905 ssrc = channels_[channel]->send_ssrc;
906 return 0;
907 }
908 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000909 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
910 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000912 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
913 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 return 0;
915 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000916 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
917 unsigned char id)) {
918 WEBRTC_CHECK_CHANNEL(channel);
919 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
920 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
921 return 0;
922 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000923 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
924 unsigned char id)) {
925 WEBRTC_CHECK_CHANNEL(channel);
926 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
927 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
928 return 0;
929 }
930 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
931 unsigned char id)) {
932 WEBRTC_CHECK_CHANNEL(channel);
933 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
934 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
935 return 0;
936 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000937
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
939 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
940 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
941 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
942 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
943 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
944 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
945 unsigned int& NTPLow,
946 unsigned int& timestamp,
947 unsigned int& playoutTimestamp,
948 unsigned int* jitter,
949 unsigned short* fractionLost));
950 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
951 webrtc::SenderInfo* sender_info));
952 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
953 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
954 WEBRTC_CHECK_CHANNEL(channel);
955 webrtc::ReportBlock block;
956 block.source_SSRC = channels_[channel]->send_ssrc;
957 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
958 if (send_codec.pltype >= 0) {
959 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
960 if (send_codec.plfreq / 1000 > 0) {
961 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
962 }
963 block.cumulative_num_packets_lost = kIntStatValue;
964 block.extended_highest_sequence_number = kIntStatValue;
965 receive_blocks->push_back(block);
966 }
967 return 0;
968 }
969 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
970 unsigned char subType,
971 unsigned int name,
972 const char* data,
973 unsigned short dataLength));
974 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
975 unsigned int& maxJitterMs,
976 unsigned int& discardedPackets));
977 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
978 WEBRTC_CHECK_CHANNEL(channel);
979 stats.fractionLost = static_cast<int16>(kIntStatValue);
980 stats.cumulativeLost = kIntStatValue;
981 stats.extendedMax = kIntStatValue;
982 stats.jitterSamples = kIntStatValue;
983 stats.rttMs = kIntStatValue;
984 stats.bytesSent = kIntStatValue;
985 stats.packetsSent = kIntStatValue;
986 stats.bytesReceived = kIntStatValue;
987 stats.packetsReceived = kIntStatValue;
988 return 0;
989 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000990 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000991 return SetFECStatus(channel, enable, redPayloadtype);
992 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000993 // TODO(minyue): remove the below function when transition to SetREDStatus
994 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
996 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000997 channels_[channel]->red = enable;
998 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 return 0;
1000 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001001 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +00001002 return GetFECStatus(channel, enable, redPayloadtype);
1003 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +00001004 // TODO(minyue): remove the below function when transition to GetREDStatus
1005 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
1007 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001008 enable = channels_[channel]->red;
1009 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 return 0;
1011 }
1012 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
1013 WEBRTC_CHECK_CHANNEL(channel);
1014 channels_[channel]->nack = enable;
1015 channels_[channel]->nack_max_packets = maxNoPackets;
1016 return 0;
1017 }
1018 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
1019 webrtc::RTPDirections direction));
1020 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
1021 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
1022 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
1023 bool markerBit, const char* payloadData,
1024 unsigned short payloadSize));
1025 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
1026 uint32_t* lastRemoteTimeStamp));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001027 WEBRTC_FUNC(SetVideoEngineBWETarget, (int channel,
1028 webrtc::ViENetwork* vie_network,
1029 int video_channel)) {
1030 WEBRTC_CHECK_CHANNEL(channel);
1031 channels_[channel]->vie_network = vie_network;
1032 channels_[channel]->video_channel = video_channel;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001033 if (vie_network) {
1034 // The interface is released here to avoid leaks. A test should not
1035 // attempt to call functions on the interface stored in the channel.
1036 vie_network->Release();
1037 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001038 return 0;
1039 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040
1041 // webrtc::VoEVideoSync
1042 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1043 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001044 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1046 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1047 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1048 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1049 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1050 int* playout_buffer_delay_ms));
1051 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1052
1053 // webrtc::VoEVolumeControl
1054 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1055 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1056 WEBRTC_STUB(SetSystemOutputMute, (bool));
1057 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1058 WEBRTC_STUB(SetMicVolume, (unsigned int));
1059 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1060 WEBRTC_STUB(SetInputMute, (int, bool));
1061 WEBRTC_STUB(GetInputMute, (int, bool&));
1062 WEBRTC_STUB(SetSystemInputMute, (bool));
1063 WEBRTC_STUB(GetSystemInputMute, (bool&));
1064 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1065 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1066 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1067 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1068 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1069 WEBRTC_CHECK_CHANNEL(channel);
1070 channels_[channel]->volume_scale= scale;
1071 return 0;
1072 }
1073 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1074 WEBRTC_CHECK_CHANNEL(channel);
1075 scale = channels_[channel]->volume_scale;
1076 return 0;
1077 }
1078 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1079 WEBRTC_CHECK_CHANNEL(channel);
1080 channels_[channel]->volume_pan_left = left;
1081 channels_[channel]->volume_pan_right = right;
1082 return 0;
1083 }
1084 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1085 WEBRTC_CHECK_CHANNEL(channel);
1086 left = channels_[channel]->volume_pan_left;
1087 right = channels_[channel]->volume_pan_right;
1088 return 0;
1089 }
1090
1091 // webrtc::VoEAudioProcessing
1092 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1093 ns_enabled_ = enable;
1094 ns_mode_ = mode;
1095 return 0;
1096 }
1097 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1098 enabled = ns_enabled_;
1099 mode = ns_mode_;
1100 return 0;
1101 }
1102
1103 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1104 agc_enabled_ = enable;
1105 agc_mode_ = mode;
1106 return 0;
1107 }
1108 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1109 enabled = agc_enabled_;
1110 mode = agc_mode_;
1111 return 0;
1112 }
1113
1114 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1115 agc_config_ = config;
1116 return 0;
1117 }
1118 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1119 config = agc_config_;
1120 return 0;
1121 }
1122 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1123 ec_enabled_ = enable;
1124 ec_mode_ = mode;
1125 return 0;
1126 }
1127 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1128 enabled = ec_enabled_;
1129 mode = ec_mode_;
1130 return 0;
1131 }
1132 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1133 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1134 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1135 WEBRTC_STUB(DelayOffsetMs, ());
1136 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1137 aecm_mode_ = mode;
1138 cng_enabled_ = enableCNG;
1139 return 0;
1140 }
1141 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1142 mode = aecm_mode_;
1143 enabledCNG = cng_enabled_;
1144 return 0;
1145 }
1146 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1147 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1148 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001149 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1150 webrtc::AgcModes mode)) {
1151 channels_[channel]->rx_agc_enabled = enable;
1152 channels_[channel]->rx_agc_mode = mode;
1153 return 0;
1154 }
1155 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1156 webrtc::AgcModes& mode)) {
1157 enabled = channels_[channel]->rx_agc_enabled;
1158 mode = channels_[channel]->rx_agc_mode;
1159 return 0;
1160 }
1161
1162 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1163 channels_[channel]->rx_agc_config = config;
1164 return 0;
1165 }
1166 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1167 config = channels_[channel]->rx_agc_config;
1168 return 0;
1169 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170
1171 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1172 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1173 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1174 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1175 ec_metrics_enabled_ = enable;
1176 return 0;
1177 }
1178 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1179 enabled = ec_metrics_enabled_;
1180 return 0;
1181 }
1182 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001183 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1184 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001185
1186 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001187 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001188 WEBRTC_STUB(StopDebugRecording, ());
1189
1190 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1191 typing_detection_enabled_ = enable;
1192 return 0;
1193 }
1194 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1195 enabled = typing_detection_enabled_;
1196 return 0;
1197 }
1198
1199 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1200 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1201 int costPerTyping,
1202 int reportingThreshold,
1203 int penaltyDecay,
1204 int typeEventDelay));
1205 int EnableHighPassFilter(bool enable) {
1206 highpass_filter_enabled_ = enable;
1207 return 0;
1208 }
1209 bool IsHighPassFilterEnabled() {
1210 return highpass_filter_enabled_;
1211 }
1212 bool IsStereoChannelSwappingEnabled() {
1213 return stereo_swapping_enabled_;
1214 }
1215 void EnableStereoChannelSwapping(bool enable) {
1216 stereo_swapping_enabled_ = enable;
1217 }
1218 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1219 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1220 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1221 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1222 }
1223 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1224 return (dtmf_info_.dtmf_event_code == event_code &&
1225 dtmf_info_.dtmf_length_ms == length_ms);
1226 }
1227 // webrtc::VoEExternalMedia
1228 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1229 (int channel, webrtc::ProcessingTypes type,
1230 webrtc::VoEMediaProcess& processObject)) {
1231 WEBRTC_CHECK_CHANNEL(channel);
1232 if (channels_[channel]->media_processor_registered) {
1233 return -1;
1234 }
1235 channels_[channel]->media_processor_registered = true;
1236 media_processor_ = &processObject;
1237 return 0;
1238 }
1239 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1240 (int channel, webrtc::ProcessingTypes type)) {
1241 WEBRTC_CHECK_CHANNEL(channel);
1242 if (!channels_[channel]->media_processor_registered) {
1243 return -1;
1244 }
1245 channels_[channel]->media_processor_registered = false;
1246 media_processor_ = NULL;
1247 return 0;
1248 }
1249 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1250 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1251 WEBRTC_STUB(ExternalRecordingInsertData,
1252 (const int16_t speechData10ms[], int lengthSamples,
1253 int samplingFreqHz, int current_delay_ms));
1254 WEBRTC_STUB(ExternalPlayoutGetData,
1255 (int16_t speechData10ms[], int samplingFreqHz,
1256 int current_delay_ms, int& lengthSamples));
1257 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1258 webrtc::AudioFrame* frame));
1259 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1260
1261 private:
1262 int GetNumDevices(int& num) {
1263#ifdef WIN32
1264 num = 1;
1265#else
1266 // On non-Windows platforms VE adds a special entry for the default device,
1267 // so if there is one physical device then there are two entries in the
1268 // list.
1269 num = 2;
1270#endif
1271 return 0;
1272 }
1273
1274 int GetDeviceName(int i, char* name, char* guid) {
1275 const char *s;
1276#ifdef WIN32
1277 if (0 == i) {
1278 s = kFakeDeviceName;
1279 } else {
1280 return -1;
1281 }
1282#else
1283 // See comment above.
1284 if (0 == i) {
1285 s = kFakeDefaultDeviceName;
1286 } else if (1 == i) {
1287 s = kFakeDeviceName;
1288 } else {
1289 return -1;
1290 }
1291#endif
1292 strcpy(name, s);
1293 guid[0] = '\0';
1294 return 0;
1295 }
1296
1297 bool inited_;
1298 int last_channel_;
1299 std::map<int, Channel*> channels_;
1300 bool fail_create_channel_;
1301 const cricket::AudioCodec* const* codecs_;
1302 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001303 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 bool ec_enabled_;
1305 bool ec_metrics_enabled_;
1306 bool cng_enabled_;
1307 bool ns_enabled_;
1308 bool agc_enabled_;
1309 bool highpass_filter_enabled_;
1310 bool stereo_swapping_enabled_;
1311 bool typing_detection_enabled_;
1312 webrtc::EcModes ec_mode_;
1313 webrtc::AecmModes aecm_mode_;
1314 webrtc::NsModes ns_mode_;
1315 webrtc::AgcModes agc_mode_;
1316 webrtc::AgcConfig agc_config_;
1317 webrtc::VoiceEngineObserver* observer_;
1318 int playout_fail_channel_;
1319 int send_fail_channel_;
1320 bool fail_start_recording_microphone_;
1321 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001322 int recording_sample_rate_;
1323 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 DtmfInfo dtmf_info_;
1325 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001326 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327};
1328
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001329#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1330
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331} // namespace cricket
1332
1333#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_