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