blob: 7285908a2d14b528028cb29f332eb3a2d4a40422 [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/base/basictypes.h"
wu@webrtc.org9caf2762013-12-11 18:25:07 +000036#include "talk/base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/base/stringutils.h"
38#include "talk/media/base/codec.h"
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +000039#include "talk/media/base/rtputils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/media/base/voiceprocessor.h"
41#include "talk/media/webrtc/fakewebrtccommon.h"
42#include "talk/media/webrtc/webrtcvoe.h"
43
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000044namespace webrtc {
45class ViENetwork;
46}
47
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048namespace cricket {
49
50// Function returning stats will return these values
51// for all values based on type.
52const int kIntStatValue = 123;
53const float kFractionLostStatValue = 0.5;
54
55static const char kFakeDefaultDeviceName[] = "Fake Default";
56static const int kFakeDefaultDeviceId = -1;
57static const char kFakeDeviceName[] = "Fake Device";
58#ifdef WIN32
59static const int kFakeDeviceId = 0;
60#else
61static const int kFakeDeviceId = 1;
62#endif
63
henrike@webrtc.org79047f92014-03-06 23:46:59 +000064// Verify the header extension ID, if enabled, is within the bounds specified in
65// [RFC5285]: 1-14 inclusive.
66#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
67 do { \
68 if (enable && (id < 1 || id > 14)) { \
69 return -1; \
70 } \
71 } while (0);
72
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073class FakeWebRtcVoiceEngine
74 : public webrtc::VoEAudioProcessing,
75 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
76 public webrtc::VoEFile, public webrtc::VoEHardware,
77 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
78 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
79 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
80 public:
81 struct DtmfInfo {
82 DtmfInfo()
83 : dtmf_event_code(-1),
84 dtmf_out_of_band(false),
85 dtmf_length_ms(-1) {}
86 int dtmf_event_code;
87 bool dtmf_out_of_band;
88 int dtmf_length_ms;
89 };
90 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +000091 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 : external_transport(false),
93 send(false),
94 playout(false),
95 volume_scale(1.0),
96 volume_pan_left(1.0),
97 volume_pan_right(1.0),
98 file(false),
99 vad(false),
buildbot@webrtc.org18dfa8d2014-06-12 18:11:02 +0000100 fec(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 nack(false),
102 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000103 rx_agc_enabled(false),
104 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 cn8_type(13),
106 cn16_type(105),
107 dtmf_type(106),
buildbot@webrtc.org18dfa8d2014-06-12 18:11:02 +0000108 fec_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 nack_max_packets(0),
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000110 vie_network(NULL),
111 video_channel(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000113 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000114 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000115 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000116 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000118 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119 }
120 bool external_transport;
121 bool send;
122 bool playout;
123 float volume_scale;
124 float volume_pan_left;
125 float volume_pan_right;
126 bool file;
127 bool vad;
buildbot@webrtc.org18dfa8d2014-06-12 18:11:02 +0000128 bool fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129 bool nack;
130 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000131 bool rx_agc_enabled;
132 webrtc::AgcModes rx_agc_mode;
133 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134 int cn8_type;
135 int cn16_type;
136 int dtmf_type;
buildbot@webrtc.org18dfa8d2014-06-12 18:11:02 +0000137 int fec_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 int nack_max_packets;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000139 webrtc::ViENetwork* vie_network;
140 int video_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000142 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000143 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000144 int send_absolute_sender_time_ext_;
145 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 DtmfInfo dtmf_info;
147 std::vector<webrtc::CodecInst> recv_codecs;
148 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000149 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 std::list<std::string> packets;
151 };
152
153 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
154 int num_codecs)
155 : inited_(false),
156 last_channel_(-1),
157 fail_create_channel_(false),
158 codecs_(codecs),
159 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000160 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 ec_enabled_(false),
162 ec_metrics_enabled_(false),
163 cng_enabled_(false),
164 ns_enabled_(false),
165 agc_enabled_(false),
166 highpass_filter_enabled_(false),
167 stereo_swapping_enabled_(false),
168 typing_detection_enabled_(false),
169 ec_mode_(webrtc::kEcDefault),
170 aecm_mode_(webrtc::kAecmSpeakerphone),
171 ns_mode_(webrtc::kNsDefault),
172 agc_mode_(webrtc::kAgcDefault),
173 observer_(NULL),
174 playout_fail_channel_(-1),
175 send_fail_channel_(-1),
176 fail_start_recording_microphone_(false),
177 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000178 recording_sample_rate_(-1),
179 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 media_processor_(NULL) {
181 memset(&agc_config_, 0, sizeof(agc_config_));
182 }
183 ~FakeWebRtcVoiceEngine() {
184 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
185 // destructors, but just in case ...
186 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
187 i != channels_.end(); ++i) {
188 delete i->second;
189 }
190 }
191
192 bool IsExternalMediaProcessorRegistered() const {
193 return media_processor_ != NULL;
194 }
195 bool IsInited() const { return inited_; }
196 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000197 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
198 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
199 iter != channels_.end(); ++iter) {
200 if (local_ssrc == iter->second->send_ssrc)
201 return iter->first;
202 }
203 return -1;
204 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000205 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 bool GetPlayout(int channel) {
207 return channels_[channel]->playout;
208 }
209 bool GetSend(int channel) {
210 return channels_[channel]->send;
211 }
212 bool GetRecordingMicrophone() {
213 return recording_microphone_;
214 }
215 bool GetVAD(int channel) {
216 return channels_[channel]->vad;
217 }
buildbot@webrtc.org18dfa8d2014-06-12 18:11:02 +0000218 bool GetFEC(int channel) {
219 return channels_[channel]->fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 }
221 bool GetNACK(int channel) {
222 return channels_[channel]->nack;
223 }
224 int GetNACKMaxPackets(int channel) {
225 return channels_[channel]->nack_max_packets;
226 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000227 webrtc::ViENetwork* GetViENetwork(int channel) {
228 WEBRTC_ASSERT_CHANNEL(channel);
229 return channels_[channel]->vie_network;
230 }
231 int GetVideoChannel(int channel) {
232 WEBRTC_ASSERT_CHANNEL(channel);
233 return channels_[channel]->video_channel;
234 }
235 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
236 WEBRTC_ASSERT_CHANNEL(channel);
237 return channels_[channel]->last_rtp_packet_time;
238 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239 int GetSendCNPayloadType(int channel, bool wideband) {
240 return (wideband) ?
241 channels_[channel]->cn16_type :
242 channels_[channel]->cn8_type;
243 }
244 int GetSendTelephoneEventPayloadType(int channel) {
245 return channels_[channel]->dtmf_type;
246 }
buildbot@webrtc.org18dfa8d2014-06-12 18:11:02 +0000247 int GetSendFECPayloadType(int channel) {
248 return channels_[channel]->fec_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 }
250 bool CheckPacket(int channel, const void* data, size_t len) {
251 bool result = !CheckNoPacket(channel);
252 if (result) {
253 std::string packet = channels_[channel]->packets.front();
254 result = (packet == std::string(static_cast<const char*>(data), len));
255 channels_[channel]->packets.pop_front();
256 }
257 return result;
258 }
259 bool CheckNoPacket(int channel) {
260 return channels_[channel]->packets.empty();
261 }
262 void TriggerCallbackOnError(int channel_num, int err_code) {
263 ASSERT(observer_ != NULL);
264 observer_->CallbackOnError(channel_num, err_code);
265 }
266 void set_playout_fail_channel(int channel) {
267 playout_fail_channel_ = channel;
268 }
269 void set_send_fail_channel(int channel) {
270 send_fail_channel_ = channel;
271 }
272 void set_fail_start_recording_microphone(
273 bool fail_start_recording_microphone) {
274 fail_start_recording_microphone_ = fail_start_recording_microphone;
275 }
276 void set_fail_create_channel(bool fail_create_channel) {
277 fail_create_channel_ = fail_create_channel;
278 }
279 void TriggerProcessPacket(MediaProcessorDirection direction) {
280 webrtc::ProcessingTypes pt =
281 (direction == cricket::MPD_TX) ?
282 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
283 if (media_processor_ != NULL) {
284 media_processor_->Process(0,
285 pt,
286 NULL,
287 0,
288 0,
289 true);
290 }
291 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000292 int AddChannel() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000293 if (fail_create_channel_) {
294 return -1;
295 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000296 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000297 for (int i = 0; i < NumOfCodecs(); ++i) {
298 webrtc::CodecInst codec;
299 GetCodec(i, codec);
300 ch->recv_codecs.push_back(codec);
301 }
302 channels_[++last_channel_] = ch;
303 return last_channel_;
304 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000305 int GetSendRtpExtensionId(int channel, const std::string& extension) {
306 WEBRTC_ASSERT_CHANNEL(channel);
307 if (extension == kRtpAudioLevelHeaderExtension) {
308 return channels_[channel]->send_audio_level_ext_;
309 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
310 return channels_[channel]->send_absolute_sender_time_ext_;
311 }
312 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000313 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000314 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
315 WEBRTC_ASSERT_CHANNEL(channel);
316 if (extension == kRtpAudioLevelHeaderExtension) {
317 return channels_[channel]->receive_audio_level_ext_;
318 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
319 return channels_[channel]->receive_absolute_sender_time_ext_;
320 }
321 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000322 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000324 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
325
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 WEBRTC_STUB(Release, ());
327
328 // webrtc::VoEBase
329 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
330 webrtc::VoiceEngineObserver& observer)) {
331 observer_ = &observer;
332 return 0;
333 }
334 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
335 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
336 webrtc::AudioProcessing* audioproc)) {
337 inited_ = true;
338 return 0;
339 }
340 WEBRTC_FUNC(Terminate, ()) {
341 inited_ = false;
342 return 0;
343 }
344 virtual webrtc::AudioProcessing* audio_processing() OVERRIDE {
345 return NULL;
346 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000348 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000350 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
351 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000352 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 WEBRTC_FUNC(DeleteChannel, (int channel)) {
354 WEBRTC_CHECK_CHANNEL(channel);
355 delete channels_[channel];
356 channels_.erase(channel);
357 return 0;
358 }
359 WEBRTC_STUB(StartReceive, (int channel));
360 WEBRTC_FUNC(StartPlayout, (int channel)) {
361 if (playout_fail_channel_ != channel) {
362 WEBRTC_CHECK_CHANNEL(channel);
363 channels_[channel]->playout = true;
364 return 0;
365 } else {
366 // When playout_fail_channel_ == channel, fail the StartPlayout on this
367 // channel.
368 return -1;
369 }
370 }
371 WEBRTC_FUNC(StartSend, (int channel)) {
372 if (send_fail_channel_ != channel) {
373 WEBRTC_CHECK_CHANNEL(channel);
374 channels_[channel]->send = true;
375 return 0;
376 } else {
377 // When send_fail_channel_ == channel, fail the StartSend on this
378 // channel.
379 return -1;
380 }
381 }
382 WEBRTC_STUB(StopReceive, (int channel));
383 WEBRTC_FUNC(StopPlayout, (int channel)) {
384 WEBRTC_CHECK_CHANNEL(channel);
385 channels_[channel]->playout = false;
386 return 0;
387 }
388 WEBRTC_FUNC(StopSend, (int channel)) {
389 WEBRTC_CHECK_CHANNEL(channel);
390 channels_[channel]->send = false;
391 return 0;
392 }
393 WEBRTC_STUB(GetVersion, (char version[1024]));
394 WEBRTC_STUB(LastError, ());
395 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
396 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
397 WEBRTC_STUB(SetNetEQPlayoutMode, (int, webrtc::NetEqModes));
398 WEBRTC_STUB(GetNetEQPlayoutMode, (int, webrtc::NetEqModes&));
399
400 // webrtc::VoECodec
401 WEBRTC_FUNC(NumOfCodecs, ()) {
402 return num_codecs_;
403 }
404 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
405 if (index < 0 || index >= NumOfCodecs()) {
406 return -1;
407 }
408 const cricket::AudioCodec& c(*codecs_[index]);
409 codec.pltype = c.id;
410 talk_base::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
411 codec.plfreq = c.clockrate;
412 codec.pacsize = 0;
413 codec.channels = c.channels;
414 codec.rate = c.bitrate;
415 return 0;
416 }
417 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
418 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000419 // To match the behavior of the real implementation.
420 if (_stricmp(codec.plname, "telephone-event") == 0 ||
421 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
422 _stricmp(codec.plname, "CN") == 0 ||
423 _stricmp(codec.plname, "red") == 0 ) {
424 return -1;
425 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000427 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 return 0;
429 }
430 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
431 WEBRTC_CHECK_CHANNEL(channel);
432 codec = channels_[channel]->send_codec;
433 return 0;
434 }
435 WEBRTC_STUB(SetSecondarySendCodec, (int channel,
436 const webrtc::CodecInst& codec,
437 int red_payload_type));
438 WEBRTC_STUB(RemoveSecondarySendCodec, (int channel));
439 WEBRTC_STUB(GetSecondarySendCodec, (int channel,
440 webrtc::CodecInst& codec));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000441 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
442 WEBRTC_CHECK_CHANNEL(channel);
443 const Channel* c = channels_[channel];
444 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
445 it_packet != c->packets.end(); ++it_packet) {
446 int pltype;
447 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
448 continue;
449 }
450 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
451 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
452 ++it_codec) {
453 if (it_codec->pltype == pltype) {
454 codec = *it_codec;
455 return 0;
456 }
457 }
458 }
459 return -1;
460 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
462 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
463 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
464 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
465 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
466 bool useFixedFrameSize));
467 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
468 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
469 WEBRTC_FUNC(SetRecPayloadType, (int channel,
470 const webrtc::CodecInst& codec)) {
471 WEBRTC_CHECK_CHANNEL(channel);
472 Channel* ch = channels_[channel];
473 if (ch->playout)
474 return -1; // Channel is in use.
475 // Check if something else already has this slot.
476 if (codec.pltype != -1) {
477 for (std::vector<webrtc::CodecInst>::iterator it =
478 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
479 if (it->pltype == codec.pltype &&
480 _stricmp(it->plname, codec.plname) != 0) {
481 return -1;
482 }
483 }
484 }
485 // Otherwise try to find this codec and update its payload type.
486 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
487 it != ch->recv_codecs.end(); ++it) {
488 if (strcmp(it->plname, codec.plname) == 0 &&
489 it->plfreq == codec.plfreq) {
490 it->pltype = codec.pltype;
491 it->channels = codec.channels;
492 return 0;
493 }
494 }
495 return -1; // not found
496 }
497 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
498 webrtc::PayloadFrequencies frequency)) {
499 WEBRTC_CHECK_CHANNEL(channel);
500 if (frequency == webrtc::kFreq8000Hz) {
501 channels_[channel]->cn8_type = type;
502 } else if (frequency == webrtc::kFreq16000Hz) {
503 channels_[channel]->cn16_type = type;
504 }
505 return 0;
506 }
507 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
508 WEBRTC_CHECK_CHANNEL(channel);
509 Channel* ch = channels_[channel];
510 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
511 it != ch->recv_codecs.end(); ++it) {
512 if (strcmp(it->plname, codec.plname) == 0 &&
513 it->plfreq == codec.plfreq &&
514 it->channels == codec.channels &&
515 it->pltype != -1) {
516 codec.pltype = it->pltype;
517 return 0;
518 }
519 }
520 return -1; // not found
521 }
522 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
523 bool disableDTX)) {
524 WEBRTC_CHECK_CHANNEL(channel);
525 if (channels_[channel]->send_codec.channels == 2) {
526 // Replicating VoE behavior; VAD cannot be enabled for stereo.
527 return -1;
528 }
529 channels_[channel]->vad = enable;
530 return 0;
531 }
532 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
533 webrtc::VadModes& mode, bool& disabledDTX));
534
535 // webrtc::VoEDtmf
536 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
537 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
538 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
539 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
540 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
541 return 0;
542 }
543
544 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
545 (int channel, unsigned char type)) {
546 channels_[channel]->dtmf_type = type;
547 return 0;
548 };
549 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
550 (int channel, unsigned char& type));
551
552 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
553 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
554 WEBRTC_STUB(SetDtmfPlayoutStatus, (int channel, bool enable));
555 WEBRTC_STUB(GetDtmfPlayoutStatus, (int channel, bool& enabled));
556
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 WEBRTC_FUNC(PlayDtmfTone,
558 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
559 dtmf_info_.dtmf_event_code = event_code;
560 dtmf_info_.dtmf_length_ms = length_ms;
561 return 0;
562 }
563 WEBRTC_STUB(StartPlayingDtmfTone,
564 (int eventCode, int attenuationDb = 10));
565 WEBRTC_STUB(StopPlayingDtmfTone, ());
566
567 // webrtc::VoEFile
568 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
569 bool loop, webrtc::FileFormats format,
570 float volumeScaling, int startPointMs,
571 int stopPointMs)) {
572 WEBRTC_CHECK_CHANNEL(channel);
573 channels_[channel]->file = true;
574 return 0;
575 }
576 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
577 webrtc::FileFormats format,
578 float volumeScaling, int startPointMs,
579 int stopPointMs)) {
580 WEBRTC_CHECK_CHANNEL(channel);
581 channels_[channel]->file = true;
582 return 0;
583 }
584 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
585 WEBRTC_CHECK_CHANNEL(channel);
586 channels_[channel]->file = false;
587 return 0;
588 }
589 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
590 WEBRTC_CHECK_CHANNEL(channel);
591 return (channels_[channel]->file) ? 1 : 0;
592 }
593 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
594 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
595 const char* fileNameUTF8,
596 bool loop,
597 bool mixWithMicrophone,
598 webrtc::FileFormats format,
599 float volumeScaling));
600 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
601 webrtc::InStream* stream,
602 bool mixWithMicrophone,
603 webrtc::FileFormats format,
604 float volumeScaling));
605 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
606 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
607 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
608 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
609 webrtc::CodecInst* compression,
610 int maxSizeBytes));
611 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
612 webrtc::CodecInst* compression));
613 WEBRTC_STUB(StopRecordingPlayout, (int channel));
614 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
615 webrtc::CodecInst* compression,
616 int maxSizeBytes)) {
617 if (fail_start_recording_microphone_) {
618 return -1;
619 }
620 recording_microphone_ = true;
621 return 0;
622 }
623 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
624 webrtc::CodecInst* compression)) {
625 if (fail_start_recording_microphone_) {
626 return -1;
627 }
628 recording_microphone_ = true;
629 return 0;
630 }
631 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
632 if (!recording_microphone_) {
633 return -1;
634 }
635 recording_microphone_ = false;
636 return 0;
637 }
638 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
639 const char* fileNameOutUTF8));
640 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
641 webrtc::OutStream* streamOut));
642 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
643 const char* fileNameOutUTF8));
644 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
645 webrtc::OutStream* streamOut));
646 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
647 const char* fileNameOutUTF8,
648 webrtc::CodecInst* compression));
649 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
650 webrtc::OutStream* streamOut,
651 webrtc::CodecInst* compression));
652 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
653 const char* fileNameOutUTF8));
654 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
655 webrtc::OutStream* streamOut));
656 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
657 webrtc::FileFormats format));
658 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
659
660 // webrtc::VoEHardware
661 WEBRTC_STUB(GetCPULoad, (int&));
662 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
663 return GetNumDevices(num);
664 }
665 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
666 return GetNumDevices(num);
667 }
668 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
669 return GetDeviceName(i, name, guid);
670 }
671 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
672 return GetDeviceName(i, name, guid);
673 }
674 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
675 WEBRTC_STUB(SetPlayoutDevice, (int));
676 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
677 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
678 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
679 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
680 WEBRTC_STUB(ResetAudioDevice, ());
681 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
682 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
683 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000684 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
685 recording_sample_rate_ = samples_per_sec;
686 return 0;
687 }
688 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
689 *samples_per_sec = recording_sample_rate_;
690 return 0;
691 }
692 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
693 playout_sample_rate_ = samples_per_sec;
694 return 0;
695 }
696 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
697 *samples_per_sec = playout_sample_rate_;
698 return 0;
699 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
701 virtual bool BuiltInAECIsEnabled() const { return true; }
702
703 // webrtc::VoENetEqStats
704 WEBRTC_STUB(GetNetworkStatistics, (int, webrtc::NetworkStatistics&));
wu@webrtc.org24301a62013-12-13 19:17:43 +0000705 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
706 webrtc::AudioDecodingCallStats*)) {
707 WEBRTC_CHECK_CHANNEL(channel);
708 return 0;
709 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710
711 // webrtc::VoENetwork
712 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
713 webrtc::Transport& transport)) {
714 WEBRTC_CHECK_CHANNEL(channel);
715 channels_[channel]->external_transport = true;
716 return 0;
717 }
718 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
719 WEBRTC_CHECK_CHANNEL(channel);
720 channels_[channel]->external_transport = false;
721 return 0;
722 }
723 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
724 unsigned int length)) {
725 WEBRTC_CHECK_CHANNEL(channel);
726 if (!channels_[channel]->external_transport) return -1;
727 channels_[channel]->packets.push_back(
728 std::string(static_cast<const char*>(data), length));
729 return 0;
730 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000731 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
732 unsigned int length,
733 const webrtc::PacketTime& packet_time)) {
734 WEBRTC_CHECK_CHANNEL(channel);
735 if (ReceivedRTPPacket(channel, data, length) == -1) {
736 return -1;
737 }
738 channels_[channel]->last_rtp_packet_time = packet_time;
739 return 0;
740 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000741
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
743 unsigned int length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744
745 // webrtc::VoERTP_RTCP
746 WEBRTC_STUB(RegisterRTPObserver, (int channel,
747 webrtc::VoERTPObserver& observer));
748 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
749 WEBRTC_STUB(RegisterRTCPObserver, (int channel,
750 webrtc::VoERTCPObserver& observer));
751 WEBRTC_STUB(DeRegisterRTCPObserver, (int channel));
752 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
753 WEBRTC_CHECK_CHANNEL(channel);
754 channels_[channel]->send_ssrc = ssrc;
755 return 0;
756 }
757 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
758 WEBRTC_CHECK_CHANNEL(channel);
759 ssrc = channels_[channel]->send_ssrc;
760 return 0;
761 }
762 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000763 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
764 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000766 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
767 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 return 0;
769 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000770#ifdef USE_WEBRTC_DEV_BRANCH
771 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
772 unsigned char id)) {
773 WEBRTC_CHECK_CHANNEL(channel);
774 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
775 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
776 return 0;
777 }
778#endif // USE_WEBRTC_DEV_BRANCH
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000779 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
780 unsigned char id)) {
781 WEBRTC_CHECK_CHANNEL(channel);
782 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
783 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
784 return 0;
785 }
786 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
787 unsigned char id)) {
788 WEBRTC_CHECK_CHANNEL(channel);
789 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
790 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
791 return 0;
792 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000793
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
795 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
796 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
797 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
798 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
799 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
800 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
801 unsigned int& NTPLow,
802 unsigned int& timestamp,
803 unsigned int& playoutTimestamp,
804 unsigned int* jitter,
805 unsigned short* fractionLost));
806 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
807 webrtc::SenderInfo* sender_info));
808 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
809 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
810 WEBRTC_CHECK_CHANNEL(channel);
811 webrtc::ReportBlock block;
812 block.source_SSRC = channels_[channel]->send_ssrc;
813 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
814 if (send_codec.pltype >= 0) {
815 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
816 if (send_codec.plfreq / 1000 > 0) {
817 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
818 }
819 block.cumulative_num_packets_lost = kIntStatValue;
820 block.extended_highest_sequence_number = kIntStatValue;
821 receive_blocks->push_back(block);
822 }
823 return 0;
824 }
825 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
826 unsigned char subType,
827 unsigned int name,
828 const char* data,
829 unsigned short dataLength));
830 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
831 unsigned int& maxJitterMs,
832 unsigned int& discardedPackets));
833 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
834 WEBRTC_CHECK_CHANNEL(channel);
835 stats.fractionLost = static_cast<int16>(kIntStatValue);
836 stats.cumulativeLost = kIntStatValue;
837 stats.extendedMax = kIntStatValue;
838 stats.jitterSamples = kIntStatValue;
839 stats.rttMs = kIntStatValue;
840 stats.bytesSent = kIntStatValue;
841 stats.packetsSent = kIntStatValue;
842 stats.bytesReceived = kIntStatValue;
843 stats.packetsReceived = kIntStatValue;
844 return 0;
845 }
846 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
847 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org18dfa8d2014-06-12 18:11:02 +0000848 channels_[channel]->fec = enable;
849 channels_[channel]->fec_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 return 0;
851 }
852 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
853 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org18dfa8d2014-06-12 18:11:02 +0000854 enable = channels_[channel]->fec;
855 redPayloadtype = channels_[channel]->fec_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 return 0;
857 }
858 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
859 WEBRTC_CHECK_CHANNEL(channel);
860 channels_[channel]->nack = enable;
861 channels_[channel]->nack_max_packets = maxNoPackets;
862 return 0;
863 }
864 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
865 webrtc::RTPDirections direction));
866 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
867 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
868 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
869 bool markerBit, const char* payloadData,
870 unsigned short payloadSize));
871 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
872 uint32_t* lastRemoteTimeStamp));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000873 WEBRTC_FUNC(SetVideoEngineBWETarget, (int channel,
874 webrtc::ViENetwork* vie_network,
875 int video_channel)) {
876 WEBRTC_CHECK_CHANNEL(channel);
877 channels_[channel]->vie_network = vie_network;
878 channels_[channel]->video_channel = video_channel;
879 return 0;
880 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881
882 // webrtc::VoEVideoSync
883 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
884 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000885 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
887 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
888 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
889 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
890 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
891 int* playout_buffer_delay_ms));
892 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
893
894 // webrtc::VoEVolumeControl
895 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
896 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
897 WEBRTC_STUB(SetSystemOutputMute, (bool));
898 WEBRTC_STUB(GetSystemOutputMute, (bool&));
899 WEBRTC_STUB(SetMicVolume, (unsigned int));
900 WEBRTC_STUB(GetMicVolume, (unsigned int&));
901 WEBRTC_STUB(SetInputMute, (int, bool));
902 WEBRTC_STUB(GetInputMute, (int, bool&));
903 WEBRTC_STUB(SetSystemInputMute, (bool));
904 WEBRTC_STUB(GetSystemInputMute, (bool&));
905 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
906 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
907 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
908 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
909 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
910 WEBRTC_CHECK_CHANNEL(channel);
911 channels_[channel]->volume_scale= scale;
912 return 0;
913 }
914 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
915 WEBRTC_CHECK_CHANNEL(channel);
916 scale = channels_[channel]->volume_scale;
917 return 0;
918 }
919 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
920 WEBRTC_CHECK_CHANNEL(channel);
921 channels_[channel]->volume_pan_left = left;
922 channels_[channel]->volume_pan_right = right;
923 return 0;
924 }
925 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
926 WEBRTC_CHECK_CHANNEL(channel);
927 left = channels_[channel]->volume_pan_left;
928 right = channels_[channel]->volume_pan_right;
929 return 0;
930 }
931
932 // webrtc::VoEAudioProcessing
933 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
934 ns_enabled_ = enable;
935 ns_mode_ = mode;
936 return 0;
937 }
938 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
939 enabled = ns_enabled_;
940 mode = ns_mode_;
941 return 0;
942 }
943
944 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
945 agc_enabled_ = enable;
946 agc_mode_ = mode;
947 return 0;
948 }
949 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
950 enabled = agc_enabled_;
951 mode = agc_mode_;
952 return 0;
953 }
954
955 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
956 agc_config_ = config;
957 return 0;
958 }
959 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
960 config = agc_config_;
961 return 0;
962 }
963 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
964 ec_enabled_ = enable;
965 ec_mode_ = mode;
966 return 0;
967 }
968 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
969 enabled = ec_enabled_;
970 mode = ec_mode_;
971 return 0;
972 }
973 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
974 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
975 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
976 WEBRTC_STUB(DelayOffsetMs, ());
977 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
978 aecm_mode_ = mode;
979 cng_enabled_ = enableCNG;
980 return 0;
981 }
982 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
983 mode = aecm_mode_;
984 enabledCNG = cng_enabled_;
985 return 0;
986 }
987 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
988 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
989 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000990 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
991 webrtc::AgcModes mode)) {
992 channels_[channel]->rx_agc_enabled = enable;
993 channels_[channel]->rx_agc_mode = mode;
994 return 0;
995 }
996 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
997 webrtc::AgcModes& mode)) {
998 enabled = channels_[channel]->rx_agc_enabled;
999 mode = channels_[channel]->rx_agc_mode;
1000 return 0;
1001 }
1002
1003 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1004 channels_[channel]->rx_agc_config = config;
1005 return 0;
1006 }
1007 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1008 config = channels_[channel]->rx_agc_config;
1009 return 0;
1010 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011
1012 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1013 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1014 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1015 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1016 ec_metrics_enabled_ = enable;
1017 return 0;
1018 }
1019 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1020 enabled = ec_metrics_enabled_;
1021 return 0;
1022 }
1023 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
1024 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std));
1025
1026 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001027 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 WEBRTC_STUB(StopDebugRecording, ());
1029
1030 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1031 typing_detection_enabled_ = enable;
1032 return 0;
1033 }
1034 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1035 enabled = typing_detection_enabled_;
1036 return 0;
1037 }
1038
1039 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1040 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1041 int costPerTyping,
1042 int reportingThreshold,
1043 int penaltyDecay,
1044 int typeEventDelay));
1045 int EnableHighPassFilter(bool enable) {
1046 highpass_filter_enabled_ = enable;
1047 return 0;
1048 }
1049 bool IsHighPassFilterEnabled() {
1050 return highpass_filter_enabled_;
1051 }
1052 bool IsStereoChannelSwappingEnabled() {
1053 return stereo_swapping_enabled_;
1054 }
1055 void EnableStereoChannelSwapping(bool enable) {
1056 stereo_swapping_enabled_ = enable;
1057 }
1058 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1059 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1060 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1061 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1062 }
1063 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1064 return (dtmf_info_.dtmf_event_code == event_code &&
1065 dtmf_info_.dtmf_length_ms == length_ms);
1066 }
1067 // webrtc::VoEExternalMedia
1068 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1069 (int channel, webrtc::ProcessingTypes type,
1070 webrtc::VoEMediaProcess& processObject)) {
1071 WEBRTC_CHECK_CHANNEL(channel);
1072 if (channels_[channel]->media_processor_registered) {
1073 return -1;
1074 }
1075 channels_[channel]->media_processor_registered = true;
1076 media_processor_ = &processObject;
1077 return 0;
1078 }
1079 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1080 (int channel, webrtc::ProcessingTypes type)) {
1081 WEBRTC_CHECK_CHANNEL(channel);
1082 if (!channels_[channel]->media_processor_registered) {
1083 return -1;
1084 }
1085 channels_[channel]->media_processor_registered = false;
1086 media_processor_ = NULL;
1087 return 0;
1088 }
1089 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1090 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1091 WEBRTC_STUB(ExternalRecordingInsertData,
1092 (const int16_t speechData10ms[], int lengthSamples,
1093 int samplingFreqHz, int current_delay_ms));
1094 WEBRTC_STUB(ExternalPlayoutGetData,
1095 (int16_t speechData10ms[], int samplingFreqHz,
1096 int current_delay_ms, int& lengthSamples));
1097 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1098 webrtc::AudioFrame* frame));
1099 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1100
1101 private:
1102 int GetNumDevices(int& num) {
1103#ifdef WIN32
1104 num = 1;
1105#else
1106 // On non-Windows platforms VE adds a special entry for the default device,
1107 // so if there is one physical device then there are two entries in the
1108 // list.
1109 num = 2;
1110#endif
1111 return 0;
1112 }
1113
1114 int GetDeviceName(int i, char* name, char* guid) {
1115 const char *s;
1116#ifdef WIN32
1117 if (0 == i) {
1118 s = kFakeDeviceName;
1119 } else {
1120 return -1;
1121 }
1122#else
1123 // See comment above.
1124 if (0 == i) {
1125 s = kFakeDefaultDeviceName;
1126 } else if (1 == i) {
1127 s = kFakeDeviceName;
1128 } else {
1129 return -1;
1130 }
1131#endif
1132 strcpy(name, s);
1133 guid[0] = '\0';
1134 return 0;
1135 }
1136
1137 bool inited_;
1138 int last_channel_;
1139 std::map<int, Channel*> channels_;
1140 bool fail_create_channel_;
1141 const cricket::AudioCodec* const* codecs_;
1142 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001143 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 bool ec_enabled_;
1145 bool ec_metrics_enabled_;
1146 bool cng_enabled_;
1147 bool ns_enabled_;
1148 bool agc_enabled_;
1149 bool highpass_filter_enabled_;
1150 bool stereo_swapping_enabled_;
1151 bool typing_detection_enabled_;
1152 webrtc::EcModes ec_mode_;
1153 webrtc::AecmModes aecm_mode_;
1154 webrtc::NsModes ns_mode_;
1155 webrtc::AgcModes agc_mode_;
1156 webrtc::AgcConfig agc_config_;
1157 webrtc::VoiceEngineObserver* observer_;
1158 int playout_fail_channel_;
1159 int send_fail_channel_;
1160 bool fail_start_recording_microphone_;
1161 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001162 int recording_sample_rate_;
1163 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 DtmfInfo dtmf_info_;
1165 webrtc::VoEMediaProcess* media_processor_;
1166};
1167
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001168#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170} // namespace cricket
1171
1172#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_