blob: 7202e1520c19f35f8ace7504e481be7b2b75815f [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
35
36#include "talk/base/basictypes.h"
37#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
43namespace cricket {
44
45// Function returning stats will return these values
46// for all values based on type.
47const int kIntStatValue = 123;
48const float kFractionLostStatValue = 0.5;
49
50static const char kFakeDefaultDeviceName[] = "Fake Default";
51static const int kFakeDefaultDeviceId = -1;
52static const char kFakeDeviceName[] = "Fake Device";
53#ifdef WIN32
54static const int kFakeDeviceId = 0;
55#else
56static const int kFakeDeviceId = 1;
57#endif
58
59
60class FakeWebRtcVoiceEngine
61 : public webrtc::VoEAudioProcessing,
62 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
63 public webrtc::VoEFile, public webrtc::VoEHardware,
64 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
65 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
66 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
67 public:
68 struct DtmfInfo {
69 DtmfInfo()
70 : dtmf_event_code(-1),
71 dtmf_out_of_band(false),
72 dtmf_length_ms(-1) {}
73 int dtmf_event_code;
74 bool dtmf_out_of_band;
75 int dtmf_length_ms;
76 };
77 struct Channel {
78 Channel()
79 : external_transport(false),
80 send(false),
81 playout(false),
82 volume_scale(1.0),
83 volume_pan_left(1.0),
84 volume_pan_right(1.0),
85 file(false),
86 vad(false),
87 fec(false),
88 nack(false),
89 media_processor_registered(false),
90 cn8_type(13),
91 cn16_type(105),
92 dtmf_type(106),
93 fec_type(117),
94 nack_max_packets(0),
95 send_ssrc(0),
96 level_header_ext_(-1) {
97 memset(&send_codec, 0, sizeof(send_codec));
98 }
99 bool external_transport;
100 bool send;
101 bool playout;
102 float volume_scale;
103 float volume_pan_left;
104 float volume_pan_right;
105 bool file;
106 bool vad;
107 bool fec;
108 bool nack;
109 bool media_processor_registered;
110 int cn8_type;
111 int cn16_type;
112 int dtmf_type;
113 int fec_type;
114 int nack_max_packets;
115 uint32 send_ssrc;
116 int level_header_ext_;
117 DtmfInfo dtmf_info;
118 std::vector<webrtc::CodecInst> recv_codecs;
119 webrtc::CodecInst send_codec;
120 std::list<std::string> packets;
121 };
122
123 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
124 int num_codecs)
125 : inited_(false),
126 last_channel_(-1),
127 fail_create_channel_(false),
128 codecs_(codecs),
129 num_codecs_(num_codecs),
130 ec_enabled_(false),
131 ec_metrics_enabled_(false),
132 cng_enabled_(false),
133 ns_enabled_(false),
134 agc_enabled_(false),
135 highpass_filter_enabled_(false),
136 stereo_swapping_enabled_(false),
137 typing_detection_enabled_(false),
138 ec_mode_(webrtc::kEcDefault),
139 aecm_mode_(webrtc::kAecmSpeakerphone),
140 ns_mode_(webrtc::kNsDefault),
141 agc_mode_(webrtc::kAgcDefault),
142 observer_(NULL),
143 playout_fail_channel_(-1),
144 send_fail_channel_(-1),
145 fail_start_recording_microphone_(false),
146 recording_microphone_(false),
147 media_processor_(NULL) {
148 memset(&agc_config_, 0, sizeof(agc_config_));
149 }
150 ~FakeWebRtcVoiceEngine() {
151 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
152 // destructors, but just in case ...
153 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
154 i != channels_.end(); ++i) {
155 delete i->second;
156 }
157 }
158
159 bool IsExternalMediaProcessorRegistered() const {
160 return media_processor_ != NULL;
161 }
162 bool IsInited() const { return inited_; }
163 int GetLastChannel() const { return last_channel_; }
164 int GetNumChannels() const { return channels_.size(); }
165 bool GetPlayout(int channel) {
166 return channels_[channel]->playout;
167 }
168 bool GetSend(int channel) {
169 return channels_[channel]->send;
170 }
171 bool GetRecordingMicrophone() {
172 return recording_microphone_;
173 }
174 bool GetVAD(int channel) {
175 return channels_[channel]->vad;
176 }
177 bool GetFEC(int channel) {
178 return channels_[channel]->fec;
179 }
180 bool GetNACK(int channel) {
181 return channels_[channel]->nack;
182 }
183 int GetNACKMaxPackets(int channel) {
184 return channels_[channel]->nack_max_packets;
185 }
186 int GetSendCNPayloadType(int channel, bool wideband) {
187 return (wideband) ?
188 channels_[channel]->cn16_type :
189 channels_[channel]->cn8_type;
190 }
191 int GetSendTelephoneEventPayloadType(int channel) {
192 return channels_[channel]->dtmf_type;
193 }
194 int GetSendFECPayloadType(int channel) {
195 return channels_[channel]->fec_type;
196 }
197 bool CheckPacket(int channel, const void* data, size_t len) {
198 bool result = !CheckNoPacket(channel);
199 if (result) {
200 std::string packet = channels_[channel]->packets.front();
201 result = (packet == std::string(static_cast<const char*>(data), len));
202 channels_[channel]->packets.pop_front();
203 }
204 return result;
205 }
206 bool CheckNoPacket(int channel) {
207 return channels_[channel]->packets.empty();
208 }
209 void TriggerCallbackOnError(int channel_num, int err_code) {
210 ASSERT(observer_ != NULL);
211 observer_->CallbackOnError(channel_num, err_code);
212 }
213 void set_playout_fail_channel(int channel) {
214 playout_fail_channel_ = channel;
215 }
216 void set_send_fail_channel(int channel) {
217 send_fail_channel_ = channel;
218 }
219 void set_fail_start_recording_microphone(
220 bool fail_start_recording_microphone) {
221 fail_start_recording_microphone_ = fail_start_recording_microphone;
222 }
223 void set_fail_create_channel(bool fail_create_channel) {
224 fail_create_channel_ = fail_create_channel;
225 }
226 void TriggerProcessPacket(MediaProcessorDirection direction) {
227 webrtc::ProcessingTypes pt =
228 (direction == cricket::MPD_TX) ?
229 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
230 if (media_processor_ != NULL) {
231 media_processor_->Process(0,
232 pt,
233 NULL,
234 0,
235 0,
236 true);
237 }
238 }
239
240 WEBRTC_STUB(Release, ());
241
242 // webrtc::VoEBase
243 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
244 webrtc::VoiceEngineObserver& observer)) {
245 observer_ = &observer;
246 return 0;
247 }
248 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
249 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
250 webrtc::AudioProcessing* audioproc)) {
251 inited_ = true;
252 return 0;
253 }
254 WEBRTC_FUNC(Terminate, ()) {
255 inited_ = false;
256 return 0;
257 }
258 virtual webrtc::AudioProcessing* audio_processing() OVERRIDE {
259 return NULL;
260 }
261 WEBRTC_STUB(MaxNumOfChannels, ());
262 WEBRTC_FUNC(CreateChannel, ()) {
263 if (fail_create_channel_) {
264 return -1;
265 }
266 Channel* ch = new Channel();
267 for (int i = 0; i < NumOfCodecs(); ++i) {
268 webrtc::CodecInst codec;
269 GetCodec(i, codec);
270 ch->recv_codecs.push_back(codec);
271 }
272 channels_[++last_channel_] = ch;
273 return last_channel_;
274 }
275 WEBRTC_FUNC(DeleteChannel, (int channel)) {
276 WEBRTC_CHECK_CHANNEL(channel);
277 delete channels_[channel];
278 channels_.erase(channel);
279 return 0;
280 }
281 WEBRTC_STUB(StartReceive, (int channel));
282 WEBRTC_FUNC(StartPlayout, (int channel)) {
283 if (playout_fail_channel_ != channel) {
284 WEBRTC_CHECK_CHANNEL(channel);
285 channels_[channel]->playout = true;
286 return 0;
287 } else {
288 // When playout_fail_channel_ == channel, fail the StartPlayout on this
289 // channel.
290 return -1;
291 }
292 }
293 WEBRTC_FUNC(StartSend, (int channel)) {
294 if (send_fail_channel_ != channel) {
295 WEBRTC_CHECK_CHANNEL(channel);
296 channels_[channel]->send = true;
297 return 0;
298 } else {
299 // When send_fail_channel_ == channel, fail the StartSend on this
300 // channel.
301 return -1;
302 }
303 }
304 WEBRTC_STUB(StopReceive, (int channel));
305 WEBRTC_FUNC(StopPlayout, (int channel)) {
306 WEBRTC_CHECK_CHANNEL(channel);
307 channels_[channel]->playout = false;
308 return 0;
309 }
310 WEBRTC_FUNC(StopSend, (int channel)) {
311 WEBRTC_CHECK_CHANNEL(channel);
312 channels_[channel]->send = false;
313 return 0;
314 }
315 WEBRTC_STUB(GetVersion, (char version[1024]));
316 WEBRTC_STUB(LastError, ());
317 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
318 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
319 WEBRTC_STUB(SetNetEQPlayoutMode, (int, webrtc::NetEqModes));
320 WEBRTC_STUB(GetNetEQPlayoutMode, (int, webrtc::NetEqModes&));
321
322 // webrtc::VoECodec
323 WEBRTC_FUNC(NumOfCodecs, ()) {
324 return num_codecs_;
325 }
326 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
327 if (index < 0 || index >= NumOfCodecs()) {
328 return -1;
329 }
330 const cricket::AudioCodec& c(*codecs_[index]);
331 codec.pltype = c.id;
332 talk_base::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
333 codec.plfreq = c.clockrate;
334 codec.pacsize = 0;
335 codec.channels = c.channels;
336 codec.rate = c.bitrate;
337 return 0;
338 }
339 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
340 WEBRTC_CHECK_CHANNEL(channel);
341 channels_[channel]->send_codec = codec;
342 return 0;
343 }
344 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
345 WEBRTC_CHECK_CHANNEL(channel);
346 codec = channels_[channel]->send_codec;
347 return 0;
348 }
349 WEBRTC_STUB(SetSecondarySendCodec, (int channel,
350 const webrtc::CodecInst& codec,
351 int red_payload_type));
352 WEBRTC_STUB(RemoveSecondarySendCodec, (int channel));
353 WEBRTC_STUB(GetSecondarySendCodec, (int channel,
354 webrtc::CodecInst& codec));
355 WEBRTC_STUB(GetRecCodec, (int channel, webrtc::CodecInst& codec));
356 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
357 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
358 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
359 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
360 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
361 bool useFixedFrameSize));
362 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
363 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
364 WEBRTC_FUNC(SetRecPayloadType, (int channel,
365 const webrtc::CodecInst& codec)) {
366 WEBRTC_CHECK_CHANNEL(channel);
367 Channel* ch = channels_[channel];
368 if (ch->playout)
369 return -1; // Channel is in use.
370 // Check if something else already has this slot.
371 if (codec.pltype != -1) {
372 for (std::vector<webrtc::CodecInst>::iterator it =
373 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
374 if (it->pltype == codec.pltype &&
375 _stricmp(it->plname, codec.plname) != 0) {
376 return -1;
377 }
378 }
379 }
380 // Otherwise try to find this codec and update its payload type.
381 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
382 it != ch->recv_codecs.end(); ++it) {
383 if (strcmp(it->plname, codec.plname) == 0 &&
384 it->plfreq == codec.plfreq) {
385 it->pltype = codec.pltype;
386 it->channels = codec.channels;
387 return 0;
388 }
389 }
390 return -1; // not found
391 }
392 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
393 webrtc::PayloadFrequencies frequency)) {
394 WEBRTC_CHECK_CHANNEL(channel);
395 if (frequency == webrtc::kFreq8000Hz) {
396 channels_[channel]->cn8_type = type;
397 } else if (frequency == webrtc::kFreq16000Hz) {
398 channels_[channel]->cn16_type = type;
399 }
400 return 0;
401 }
402 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
403 WEBRTC_CHECK_CHANNEL(channel);
404 Channel* ch = channels_[channel];
405 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
406 it != ch->recv_codecs.end(); ++it) {
407 if (strcmp(it->plname, codec.plname) == 0 &&
408 it->plfreq == codec.plfreq &&
409 it->channels == codec.channels &&
410 it->pltype != -1) {
411 codec.pltype = it->pltype;
412 return 0;
413 }
414 }
415 return -1; // not found
416 }
417 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
418 bool disableDTX)) {
419 WEBRTC_CHECK_CHANNEL(channel);
420 if (channels_[channel]->send_codec.channels == 2) {
421 // Replicating VoE behavior; VAD cannot be enabled for stereo.
422 return -1;
423 }
424 channels_[channel]->vad = enable;
425 return 0;
426 }
427 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
428 webrtc::VadModes& mode, bool& disabledDTX));
429
430 // webrtc::VoEDtmf
431 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
432 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
433 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
434 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
435 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
436 return 0;
437 }
438
439 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
440 (int channel, unsigned char type)) {
441 channels_[channel]->dtmf_type = type;
442 return 0;
443 };
444 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
445 (int channel, unsigned char& type));
446
447 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
448 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
449 WEBRTC_STUB(SetDtmfPlayoutStatus, (int channel, bool enable));
450 WEBRTC_STUB(GetDtmfPlayoutStatus, (int channel, bool& enabled));
451
452
453 WEBRTC_FUNC(PlayDtmfTone,
454 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
455 dtmf_info_.dtmf_event_code = event_code;
456 dtmf_info_.dtmf_length_ms = length_ms;
457 return 0;
458 }
459 WEBRTC_STUB(StartPlayingDtmfTone,
460 (int eventCode, int attenuationDb = 10));
461 WEBRTC_STUB(StopPlayingDtmfTone, ());
462
463 // webrtc::VoEFile
464 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
465 bool loop, webrtc::FileFormats format,
466 float volumeScaling, int startPointMs,
467 int stopPointMs)) {
468 WEBRTC_CHECK_CHANNEL(channel);
469 channels_[channel]->file = true;
470 return 0;
471 }
472 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
473 webrtc::FileFormats format,
474 float volumeScaling, int startPointMs,
475 int stopPointMs)) {
476 WEBRTC_CHECK_CHANNEL(channel);
477 channels_[channel]->file = true;
478 return 0;
479 }
480 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
481 WEBRTC_CHECK_CHANNEL(channel);
482 channels_[channel]->file = false;
483 return 0;
484 }
485 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
486 WEBRTC_CHECK_CHANNEL(channel);
487 return (channels_[channel]->file) ? 1 : 0;
488 }
489 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
490 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
491 const char* fileNameUTF8,
492 bool loop,
493 bool mixWithMicrophone,
494 webrtc::FileFormats format,
495 float volumeScaling));
496 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
497 webrtc::InStream* stream,
498 bool mixWithMicrophone,
499 webrtc::FileFormats format,
500 float volumeScaling));
501 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
502 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
503 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
504 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
505 webrtc::CodecInst* compression,
506 int maxSizeBytes));
507 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
508 webrtc::CodecInst* compression));
509 WEBRTC_STUB(StopRecordingPlayout, (int channel));
510 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
511 webrtc::CodecInst* compression,
512 int maxSizeBytes)) {
513 if (fail_start_recording_microphone_) {
514 return -1;
515 }
516 recording_microphone_ = true;
517 return 0;
518 }
519 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
520 webrtc::CodecInst* compression)) {
521 if (fail_start_recording_microphone_) {
522 return -1;
523 }
524 recording_microphone_ = true;
525 return 0;
526 }
527 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
528 if (!recording_microphone_) {
529 return -1;
530 }
531 recording_microphone_ = false;
532 return 0;
533 }
534 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
535 const char* fileNameOutUTF8));
536 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
537 webrtc::OutStream* streamOut));
538 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
539 const char* fileNameOutUTF8));
540 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
541 webrtc::OutStream* streamOut));
542 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
543 const char* fileNameOutUTF8,
544 webrtc::CodecInst* compression));
545 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
546 webrtc::OutStream* streamOut,
547 webrtc::CodecInst* compression));
548 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
549 const char* fileNameOutUTF8));
550 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
551 webrtc::OutStream* streamOut));
552 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
553 webrtc::FileFormats format));
554 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
555
556 // webrtc::VoEHardware
557 WEBRTC_STUB(GetCPULoad, (int&));
558 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
559 return GetNumDevices(num);
560 }
561 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
562 return GetNumDevices(num);
563 }
564 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
565 return GetDeviceName(i, name, guid);
566 }
567 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
568 return GetDeviceName(i, name, guid);
569 }
570 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
571 WEBRTC_STUB(SetPlayoutDevice, (int));
572 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
573 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
574 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
575 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
576 WEBRTC_STUB(ResetAudioDevice, ());
577 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
578 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
579 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
580 WEBRTC_STUB(SetRecordingSampleRate, (unsigned int samples_per_sec));
581 WEBRTC_STUB_CONST(RecordingSampleRate, (unsigned int* samples_per_sec));
582 WEBRTC_STUB(SetPlayoutSampleRate, (unsigned int samples_per_sec));
583 WEBRTC_STUB_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec));
584 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
585 virtual bool BuiltInAECIsEnabled() const { return true; }
586
587 // webrtc::VoENetEqStats
588 WEBRTC_STUB(GetNetworkStatistics, (int, webrtc::NetworkStatistics&));
589
590 // webrtc::VoENetwork
591 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
592 webrtc::Transport& transport)) {
593 WEBRTC_CHECK_CHANNEL(channel);
594 channels_[channel]->external_transport = true;
595 return 0;
596 }
597 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
598 WEBRTC_CHECK_CHANNEL(channel);
599 channels_[channel]->external_transport = false;
600 return 0;
601 }
602 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
603 unsigned int length)) {
604 WEBRTC_CHECK_CHANNEL(channel);
605 if (!channels_[channel]->external_transport) return -1;
606 channels_[channel]->packets.push_back(
607 std::string(static_cast<const char*>(data), length));
608 return 0;
609 }
610 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
611 unsigned int length));
612 // Not using WEBRTC_STUB due to bool return value
613 WEBRTC_STUB(SetPacketTimeoutNotification, (int channel, bool enable,
614 int timeoutSeconds));
615 WEBRTC_STUB(GetPacketTimeoutNotification, (int channel, bool& enable,
616 int& timeoutSeconds));
617 WEBRTC_STUB(RegisterDeadOrAliveObserver, (int channel,
618 webrtc::VoEConnectionObserver& observer));
619 WEBRTC_STUB(DeRegisterDeadOrAliveObserver, (int channel));
620 WEBRTC_STUB(GetPeriodicDeadOrAliveStatus, (int channel, bool& enabled,
621 int& sampleTimeSeconds));
622 WEBRTC_STUB(SetPeriodicDeadOrAliveStatus, (int channel, bool enable,
623 int sampleTimeSeconds));
624
625 // webrtc::VoERTP_RTCP
626 WEBRTC_STUB(RegisterRTPObserver, (int channel,
627 webrtc::VoERTPObserver& observer));
628 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
629 WEBRTC_STUB(RegisterRTCPObserver, (int channel,
630 webrtc::VoERTCPObserver& observer));
631 WEBRTC_STUB(DeRegisterRTCPObserver, (int channel));
632 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
633 WEBRTC_CHECK_CHANNEL(channel);
634 channels_[channel]->send_ssrc = ssrc;
635 return 0;
636 }
637 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
638 WEBRTC_CHECK_CHANNEL(channel);
639 ssrc = channels_[channel]->send_ssrc;
640 return 0;
641 }
642 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
643 WEBRTC_FUNC(SetRTPAudioLevelIndicationStatus, (int channel, bool enable,
644 unsigned char id)) {
645 WEBRTC_CHECK_CHANNEL(channel);
646 if (enable && (id < 1 || id > 14)) {
647 // [RFC5285] The 4-bit ID is the local identifier of this element in
648 // the range 1-14 inclusive.
649 return -1;
650 }
651 channels_[channel]->level_header_ext_ = (enable) ? id : -1;
652 return 0;
653 }
654 WEBRTC_FUNC(GetRTPAudioLevelIndicationStatus, (int channel, bool& enabled,
655 unsigned char& id)) {
656 WEBRTC_CHECK_CHANNEL(channel);
657 enabled = (channels_[channel]->level_header_ext_ != -1);
658 id = channels_[channel]->level_header_ext_;
659 return 0;
660 }
661 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
662 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
663 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
664 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
665 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
666 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
667 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
668 unsigned int& NTPLow,
669 unsigned int& timestamp,
670 unsigned int& playoutTimestamp,
671 unsigned int* jitter,
672 unsigned short* fractionLost));
673 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
674 webrtc::SenderInfo* sender_info));
675 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
676 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
677 WEBRTC_CHECK_CHANNEL(channel);
678 webrtc::ReportBlock block;
679 block.source_SSRC = channels_[channel]->send_ssrc;
680 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
681 if (send_codec.pltype >= 0) {
682 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
683 if (send_codec.plfreq / 1000 > 0) {
684 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
685 }
686 block.cumulative_num_packets_lost = kIntStatValue;
687 block.extended_highest_sequence_number = kIntStatValue;
688 receive_blocks->push_back(block);
689 }
690 return 0;
691 }
692 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
693 unsigned char subType,
694 unsigned int name,
695 const char* data,
696 unsigned short dataLength));
697 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
698 unsigned int& maxJitterMs,
699 unsigned int& discardedPackets));
700 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
701 WEBRTC_CHECK_CHANNEL(channel);
702 stats.fractionLost = static_cast<int16>(kIntStatValue);
703 stats.cumulativeLost = kIntStatValue;
704 stats.extendedMax = kIntStatValue;
705 stats.jitterSamples = kIntStatValue;
706 stats.rttMs = kIntStatValue;
707 stats.bytesSent = kIntStatValue;
708 stats.packetsSent = kIntStatValue;
709 stats.bytesReceived = kIntStatValue;
710 stats.packetsReceived = kIntStatValue;
711 return 0;
712 }
713 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
714 WEBRTC_CHECK_CHANNEL(channel);
715 channels_[channel]->fec = enable;
716 channels_[channel]->fec_type = redPayloadtype;
717 return 0;
718 }
719 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
720 WEBRTC_CHECK_CHANNEL(channel);
721 enable = channels_[channel]->fec;
722 redPayloadtype = channels_[channel]->fec_type;
723 return 0;
724 }
725 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
726 WEBRTC_CHECK_CHANNEL(channel);
727 channels_[channel]->nack = enable;
728 channels_[channel]->nack_max_packets = maxNoPackets;
729 return 0;
730 }
731 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
732 webrtc::RTPDirections direction));
733 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
734 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
735 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
736 bool markerBit, const char* payloadData,
737 unsigned short payloadSize));
738 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
739 uint32_t* lastRemoteTimeStamp));
740
741 // webrtc::VoEVideoSync
742 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
743 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
744 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp*&));
745 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
746 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
747 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
748 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
749 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
750 int* playout_buffer_delay_ms));
751 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
752
753 // webrtc::VoEVolumeControl
754 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
755 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
756 WEBRTC_STUB(SetSystemOutputMute, (bool));
757 WEBRTC_STUB(GetSystemOutputMute, (bool&));
758 WEBRTC_STUB(SetMicVolume, (unsigned int));
759 WEBRTC_STUB(GetMicVolume, (unsigned int&));
760 WEBRTC_STUB(SetInputMute, (int, bool));
761 WEBRTC_STUB(GetInputMute, (int, bool&));
762 WEBRTC_STUB(SetSystemInputMute, (bool));
763 WEBRTC_STUB(GetSystemInputMute, (bool&));
764 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
765 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
766 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
767 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
768 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
769 WEBRTC_CHECK_CHANNEL(channel);
770 channels_[channel]->volume_scale= scale;
771 return 0;
772 }
773 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
774 WEBRTC_CHECK_CHANNEL(channel);
775 scale = channels_[channel]->volume_scale;
776 return 0;
777 }
778 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
779 WEBRTC_CHECK_CHANNEL(channel);
780 channels_[channel]->volume_pan_left = left;
781 channels_[channel]->volume_pan_right = right;
782 return 0;
783 }
784 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
785 WEBRTC_CHECK_CHANNEL(channel);
786 left = channels_[channel]->volume_pan_left;
787 right = channels_[channel]->volume_pan_right;
788 return 0;
789 }
790
791 // webrtc::VoEAudioProcessing
792 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
793 ns_enabled_ = enable;
794 ns_mode_ = mode;
795 return 0;
796 }
797 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
798 enabled = ns_enabled_;
799 mode = ns_mode_;
800 return 0;
801 }
802
803 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
804 agc_enabled_ = enable;
805 agc_mode_ = mode;
806 return 0;
807 }
808 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
809 enabled = agc_enabled_;
810 mode = agc_mode_;
811 return 0;
812 }
813
814 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
815 agc_config_ = config;
816 return 0;
817 }
818 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
819 config = agc_config_;
820 return 0;
821 }
822 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
823 ec_enabled_ = enable;
824 ec_mode_ = mode;
825 return 0;
826 }
827 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
828 enabled = ec_enabled_;
829 mode = ec_mode_;
830 return 0;
831 }
832 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
833 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
834 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
835 WEBRTC_STUB(DelayOffsetMs, ());
836 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
837 aecm_mode_ = mode;
838 cng_enabled_ = enableCNG;
839 return 0;
840 }
841 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
842 mode = aecm_mode_;
843 enabledCNG = cng_enabled_;
844 return 0;
845 }
846 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
847 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
848 webrtc::NsModes& mode));
849 WEBRTC_STUB(SetRxAgcStatus, (int channel, bool enable,
850 webrtc::AgcModes mode));
851 WEBRTC_STUB(GetRxAgcStatus, (int channel, bool& enabled,
852 webrtc::AgcModes& mode));
853 WEBRTC_STUB(SetRxAgcConfig, (int channel, webrtc::AgcConfig config));
854 WEBRTC_STUB(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config));
855
856 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
857 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
858 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
859 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
860 ec_metrics_enabled_ = enable;
861 return 0;
862 }
863 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
864 enabled = ec_metrics_enabled_;
865 return 0;
866 }
867 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
868 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std));
869
870 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
871 WEBRTC_STUB(StopDebugRecording, ());
872
873 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
874 typing_detection_enabled_ = enable;
875 return 0;
876 }
877 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
878 enabled = typing_detection_enabled_;
879 return 0;
880 }
881
882 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
883 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
884 int costPerTyping,
885 int reportingThreshold,
886 int penaltyDecay,
887 int typeEventDelay));
888 int EnableHighPassFilter(bool enable) {
889 highpass_filter_enabled_ = enable;
890 return 0;
891 }
892 bool IsHighPassFilterEnabled() {
893 return highpass_filter_enabled_;
894 }
895 bool IsStereoChannelSwappingEnabled() {
896 return stereo_swapping_enabled_;
897 }
898 void EnableStereoChannelSwapping(bool enable) {
899 stereo_swapping_enabled_ = enable;
900 }
901 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
902 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
903 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
904 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
905 }
906 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
907 return (dtmf_info_.dtmf_event_code == event_code &&
908 dtmf_info_.dtmf_length_ms == length_ms);
909 }
910 // webrtc::VoEExternalMedia
911 WEBRTC_FUNC(RegisterExternalMediaProcessing,
912 (int channel, webrtc::ProcessingTypes type,
913 webrtc::VoEMediaProcess& processObject)) {
914 WEBRTC_CHECK_CHANNEL(channel);
915 if (channels_[channel]->media_processor_registered) {
916 return -1;
917 }
918 channels_[channel]->media_processor_registered = true;
919 media_processor_ = &processObject;
920 return 0;
921 }
922 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
923 (int channel, webrtc::ProcessingTypes type)) {
924 WEBRTC_CHECK_CHANNEL(channel);
925 if (!channels_[channel]->media_processor_registered) {
926 return -1;
927 }
928 channels_[channel]->media_processor_registered = false;
929 media_processor_ = NULL;
930 return 0;
931 }
932 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
933 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
934 WEBRTC_STUB(ExternalRecordingInsertData,
935 (const int16_t speechData10ms[], int lengthSamples,
936 int samplingFreqHz, int current_delay_ms));
937 WEBRTC_STUB(ExternalPlayoutGetData,
938 (int16_t speechData10ms[], int samplingFreqHz,
939 int current_delay_ms, int& lengthSamples));
940 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
941 webrtc::AudioFrame* frame));
942 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
943
944 private:
945 int GetNumDevices(int& num) {
946#ifdef WIN32
947 num = 1;
948#else
949 // On non-Windows platforms VE adds a special entry for the default device,
950 // so if there is one physical device then there are two entries in the
951 // list.
952 num = 2;
953#endif
954 return 0;
955 }
956
957 int GetDeviceName(int i, char* name, char* guid) {
958 const char *s;
959#ifdef WIN32
960 if (0 == i) {
961 s = kFakeDeviceName;
962 } else {
963 return -1;
964 }
965#else
966 // See comment above.
967 if (0 == i) {
968 s = kFakeDefaultDeviceName;
969 } else if (1 == i) {
970 s = kFakeDeviceName;
971 } else {
972 return -1;
973 }
974#endif
975 strcpy(name, s);
976 guid[0] = '\0';
977 return 0;
978 }
979
980 bool inited_;
981 int last_channel_;
982 std::map<int, Channel*> channels_;
983 bool fail_create_channel_;
984 const cricket::AudioCodec* const* codecs_;
985 int num_codecs_;
986 bool ec_enabled_;
987 bool ec_metrics_enabled_;
988 bool cng_enabled_;
989 bool ns_enabled_;
990 bool agc_enabled_;
991 bool highpass_filter_enabled_;
992 bool stereo_swapping_enabled_;
993 bool typing_detection_enabled_;
994 webrtc::EcModes ec_mode_;
995 webrtc::AecmModes aecm_mode_;
996 webrtc::NsModes ns_mode_;
997 webrtc::AgcModes agc_mode_;
998 webrtc::AgcConfig agc_config_;
999 webrtc::VoiceEngineObserver* observer_;
1000 int playout_fail_channel_;
1001 int send_fail_channel_;
1002 bool fail_start_recording_microphone_;
1003 bool recording_microphone_;
1004 DtmfInfo dtmf_info_;
1005 webrtc::VoEMediaProcess* media_processor_;
1006};
1007
1008} // namespace cricket
1009
1010#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_