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