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