blob: d95acb7b63893c007f78bfc87cc8e3c75c3bc01a [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
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000035#include "webrtc/base/basictypes.h"
36#include "webrtc/base/gunit.h"
37#include "webrtc/base/stringutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/media/base/codec.h"
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +000039#include "talk/media/base/rtputils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/media/base/voiceprocessor.h"
41#include "talk/media/webrtc/fakewebrtccommon.h"
42#include "talk/media/webrtc/webrtcvoe.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000043#ifdef USE_WEBRTC_DEV_BRANCH
44#include "webrtc/modules/audio_processing/include/audio_processing.h"
45#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000047namespace webrtc {
48class ViENetwork;
49}
50
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051namespace cricket {
52
53// Function returning stats will return these values
54// for all values based on type.
55const int kIntStatValue = 123;
56const float kFractionLostStatValue = 0.5;
57
58static const char kFakeDefaultDeviceName[] = "Fake Default";
59static const int kFakeDefaultDeviceId = -1;
60static const char kFakeDeviceName[] = "Fake Device";
61#ifdef WIN32
62static const int kFakeDeviceId = 0;
63#else
64static const int kFakeDeviceId = 1;
65#endif
66
henrike@webrtc.org79047f92014-03-06 23:46:59 +000067// Verify the header extension ID, if enabled, is within the bounds specified in
68// [RFC5285]: 1-14 inclusive.
69#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
70 do { \
71 if (enable && (id < 1 || id > 14)) { \
72 return -1; \
73 } \
74 } while (0);
75
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000076#ifdef USE_WEBRTC_DEV_BRANCH
77class FakeAudioProcessing : public webrtc::AudioProcessing {
78 public:
79 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
80
81 WEBRTC_STUB(Initialize, ())
82 WEBRTC_STUB(Initialize, (
83 int input_sample_rate_hz,
84 int output_sample_rate_hz,
85 int reverse_sample_rate_hz,
86 webrtc::AudioProcessing::ChannelLayout input_layout,
87 webrtc::AudioProcessing::ChannelLayout output_layout,
88 webrtc::AudioProcessing::ChannelLayout reverse_layout));
89
90 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
91 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
92 }
93
94 WEBRTC_STUB(set_sample_rate_hz, (int rate));
95 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
96 WEBRTC_STUB_CONST(sample_rate_hz, ());
97 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
98 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
99 WEBRTC_STUB_CONST(num_input_channels, ());
100 WEBRTC_STUB_CONST(num_output_channels, ());
101 WEBRTC_STUB_CONST(num_reverse_channels, ());
102 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
103 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
104 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
105 WEBRTC_STUB(ProcessStream, (
106 const float* const* src,
107 int samples_per_channel,
108 int input_sample_rate_hz,
109 webrtc::AudioProcessing::ChannelLayout input_layout,
110 int output_sample_rate_hz,
111 webrtc::AudioProcessing::ChannelLayout output_layout,
112 float* const* dest));
113 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
114 WEBRTC_STUB(AnalyzeReverseStream, (
115 const float* const* data,
116 int samples_per_channel,
117 int sample_rate_hz,
118 webrtc::AudioProcessing::ChannelLayout layout));
119 WEBRTC_STUB(set_stream_delay_ms, (int delay));
120 WEBRTC_STUB_CONST(stream_delay_ms, ());
121 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
122 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
123 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
124 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
125 WEBRTC_STUB_CONST(delay_offset_ms, ());
126 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
127 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
128 WEBRTC_STUB(StopDebugRecording, ());
129 virtual webrtc::EchoCancellation* echo_cancellation() const OVERRIDE {
130 return NULL;
131 }
132 virtual webrtc::EchoControlMobile* echo_control_mobile() const OVERRIDE {
133 return NULL;
134 }
135 virtual webrtc::GainControl* gain_control() const OVERRIDE { return NULL; }
136 virtual webrtc::HighPassFilter* high_pass_filter() const OVERRIDE {
137 return NULL;
138 }
139 virtual webrtc::LevelEstimator* level_estimator() const OVERRIDE {
140 return NULL;
141 }
142 virtual webrtc::NoiseSuppression* noise_suppression() const OVERRIDE {
143 return NULL;
144 }
145 virtual webrtc::VoiceDetection* voice_detection() const OVERRIDE {
146 return NULL;
147 }
148
149 bool experimental_ns_enabled() {
150 return experimental_ns_enabled_;
151 }
152
153 private:
154 bool experimental_ns_enabled_;
155};
156#endif
157
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158class FakeWebRtcVoiceEngine
159 : public webrtc::VoEAudioProcessing,
160 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
161 public webrtc::VoEFile, public webrtc::VoEHardware,
162 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
163 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
164 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
165 public:
166 struct DtmfInfo {
167 DtmfInfo()
168 : dtmf_event_code(-1),
169 dtmf_out_of_band(false),
170 dtmf_length_ms(-1) {}
171 int dtmf_event_code;
172 bool dtmf_out_of_band;
173 int dtmf_length_ms;
174 };
175 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000176 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 : external_transport(false),
178 send(false),
179 playout(false),
180 volume_scale(1.0),
181 volume_pan_left(1.0),
182 volume_pan_right(1.0),
183 file(false),
184 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000185 codec_fec(false),
186 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 nack(false),
188 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000189 rx_agc_enabled(false),
190 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 cn8_type(13),
192 cn16_type(105),
193 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000194 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 nack_max_packets(0),
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000196 vie_network(NULL),
197 video_channel(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000199 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000200 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000201 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000202 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000204 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 }
206 bool external_transport;
207 bool send;
208 bool playout;
209 float volume_scale;
210 float volume_pan_left;
211 float volume_pan_right;
212 bool file;
213 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000214 bool codec_fec;
215 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 bool nack;
217 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000218 bool rx_agc_enabled;
219 webrtc::AgcModes rx_agc_mode;
220 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 int cn8_type;
222 int cn16_type;
223 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000224 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 int nack_max_packets;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000226 webrtc::ViENetwork* vie_network;
227 int video_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000229 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000230 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000231 int send_absolute_sender_time_ext_;
232 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 DtmfInfo dtmf_info;
234 std::vector<webrtc::CodecInst> recv_codecs;
235 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000236 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 std::list<std::string> packets;
238 };
239
240 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
241 int num_codecs)
242 : inited_(false),
243 last_channel_(-1),
244 fail_create_channel_(false),
245 codecs_(codecs),
246 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000247 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 ec_enabled_(false),
249 ec_metrics_enabled_(false),
250 cng_enabled_(false),
251 ns_enabled_(false),
252 agc_enabled_(false),
253 highpass_filter_enabled_(false),
254 stereo_swapping_enabled_(false),
255 typing_detection_enabled_(false),
256 ec_mode_(webrtc::kEcDefault),
257 aecm_mode_(webrtc::kAecmSpeakerphone),
258 ns_mode_(webrtc::kNsDefault),
259 agc_mode_(webrtc::kAgcDefault),
260 observer_(NULL),
261 playout_fail_channel_(-1),
262 send_fail_channel_(-1),
263 fail_start_recording_microphone_(false),
264 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000265 recording_sample_rate_(-1),
266 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 media_processor_(NULL) {
268 memset(&agc_config_, 0, sizeof(agc_config_));
269 }
270 ~FakeWebRtcVoiceEngine() {
271 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
272 // destructors, but just in case ...
273 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
274 i != channels_.end(); ++i) {
275 delete i->second;
276 }
277 }
278
279 bool IsExternalMediaProcessorRegistered() const {
280 return media_processor_ != NULL;
281 }
282 bool IsInited() const { return inited_; }
283 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000284 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
285 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
286 iter != channels_.end(); ++iter) {
287 if (local_ssrc == iter->second->send_ssrc)
288 return iter->first;
289 }
290 return -1;
291 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000292 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293 bool GetPlayout(int channel) {
294 return channels_[channel]->playout;
295 }
296 bool GetSend(int channel) {
297 return channels_[channel]->send;
298 }
299 bool GetRecordingMicrophone() {
300 return recording_microphone_;
301 }
302 bool GetVAD(int channel) {
303 return channels_[channel]->vad;
304 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000305 bool GetRED(int channel) {
306 return channels_[channel]->red;
307 }
308 bool GetCodecFEC(int channel) {
309 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 }
311 bool GetNACK(int channel) {
312 return channels_[channel]->nack;
313 }
314 int GetNACKMaxPackets(int channel) {
315 return channels_[channel]->nack_max_packets;
316 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000317 webrtc::ViENetwork* GetViENetwork(int channel) {
318 WEBRTC_ASSERT_CHANNEL(channel);
319 return channels_[channel]->vie_network;
320 }
321 int GetVideoChannel(int channel) {
322 WEBRTC_ASSERT_CHANNEL(channel);
323 return channels_[channel]->video_channel;
324 }
325 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
326 WEBRTC_ASSERT_CHANNEL(channel);
327 return channels_[channel]->last_rtp_packet_time;
328 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 int GetSendCNPayloadType(int channel, bool wideband) {
330 return (wideband) ?
331 channels_[channel]->cn16_type :
332 channels_[channel]->cn8_type;
333 }
334 int GetSendTelephoneEventPayloadType(int channel) {
335 return channels_[channel]->dtmf_type;
336 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000337 int GetSendREDPayloadType(int channel) {
338 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 }
340 bool CheckPacket(int channel, const void* data, size_t len) {
341 bool result = !CheckNoPacket(channel);
342 if (result) {
343 std::string packet = channels_[channel]->packets.front();
344 result = (packet == std::string(static_cast<const char*>(data), len));
345 channels_[channel]->packets.pop_front();
346 }
347 return result;
348 }
349 bool CheckNoPacket(int channel) {
350 return channels_[channel]->packets.empty();
351 }
352 void TriggerCallbackOnError(int channel_num, int err_code) {
353 ASSERT(observer_ != NULL);
354 observer_->CallbackOnError(channel_num, err_code);
355 }
356 void set_playout_fail_channel(int channel) {
357 playout_fail_channel_ = channel;
358 }
359 void set_send_fail_channel(int channel) {
360 send_fail_channel_ = channel;
361 }
362 void set_fail_start_recording_microphone(
363 bool fail_start_recording_microphone) {
364 fail_start_recording_microphone_ = fail_start_recording_microphone;
365 }
366 void set_fail_create_channel(bool fail_create_channel) {
367 fail_create_channel_ = fail_create_channel;
368 }
369 void TriggerProcessPacket(MediaProcessorDirection direction) {
370 webrtc::ProcessingTypes pt =
371 (direction == cricket::MPD_TX) ?
372 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
373 if (media_processor_ != NULL) {
374 media_processor_->Process(0,
375 pt,
376 NULL,
377 0,
378 0,
379 true);
380 }
381 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000382 int AddChannel() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000383 if (fail_create_channel_) {
384 return -1;
385 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000386 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000387 for (int i = 0; i < NumOfCodecs(); ++i) {
388 webrtc::CodecInst codec;
389 GetCodec(i, codec);
390 ch->recv_codecs.push_back(codec);
391 }
392 channels_[++last_channel_] = ch;
393 return last_channel_;
394 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000395 int GetSendRtpExtensionId(int channel, const std::string& extension) {
396 WEBRTC_ASSERT_CHANNEL(channel);
397 if (extension == kRtpAudioLevelHeaderExtension) {
398 return channels_[channel]->send_audio_level_ext_;
399 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
400 return channels_[channel]->send_absolute_sender_time_ext_;
401 }
402 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000403 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000404 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
405 WEBRTC_ASSERT_CHANNEL(channel);
406 if (extension == kRtpAudioLevelHeaderExtension) {
407 return channels_[channel]->receive_audio_level_ext_;
408 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
409 return channels_[channel]->receive_absolute_sender_time_ext_;
410 }
411 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000412 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000414 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
415
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 WEBRTC_STUB(Release, ());
417
418 // webrtc::VoEBase
419 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
420 webrtc::VoiceEngineObserver& observer)) {
421 observer_ = &observer;
422 return 0;
423 }
424 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
425 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
426 webrtc::AudioProcessing* audioproc)) {
427 inited_ = true;
428 return 0;
429 }
430 WEBRTC_FUNC(Terminate, ()) {
431 inited_ = false;
432 return 0;
433 }
434 virtual webrtc::AudioProcessing* audio_processing() OVERRIDE {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000435#ifdef USE_WEBRTC_DEV_BRANCH
436 return &audio_processing_;
437#else
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 return NULL;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000439#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000442 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000444 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
445 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000446 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 WEBRTC_FUNC(DeleteChannel, (int channel)) {
448 WEBRTC_CHECK_CHANNEL(channel);
449 delete channels_[channel];
450 channels_.erase(channel);
451 return 0;
452 }
453 WEBRTC_STUB(StartReceive, (int channel));
454 WEBRTC_FUNC(StartPlayout, (int channel)) {
455 if (playout_fail_channel_ != channel) {
456 WEBRTC_CHECK_CHANNEL(channel);
457 channels_[channel]->playout = true;
458 return 0;
459 } else {
460 // When playout_fail_channel_ == channel, fail the StartPlayout on this
461 // channel.
462 return -1;
463 }
464 }
465 WEBRTC_FUNC(StartSend, (int channel)) {
466 if (send_fail_channel_ != channel) {
467 WEBRTC_CHECK_CHANNEL(channel);
468 channels_[channel]->send = true;
469 return 0;
470 } else {
471 // When send_fail_channel_ == channel, fail the StartSend on this
472 // channel.
473 return -1;
474 }
475 }
476 WEBRTC_STUB(StopReceive, (int channel));
477 WEBRTC_FUNC(StopPlayout, (int channel)) {
478 WEBRTC_CHECK_CHANNEL(channel);
479 channels_[channel]->playout = false;
480 return 0;
481 }
482 WEBRTC_FUNC(StopSend, (int channel)) {
483 WEBRTC_CHECK_CHANNEL(channel);
484 channels_[channel]->send = false;
485 return 0;
486 }
487 WEBRTC_STUB(GetVersion, (char version[1024]));
488 WEBRTC_STUB(LastError, ());
489 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
490 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
491 WEBRTC_STUB(SetNetEQPlayoutMode, (int, webrtc::NetEqModes));
492 WEBRTC_STUB(GetNetEQPlayoutMode, (int, webrtc::NetEqModes&));
493
494 // webrtc::VoECodec
495 WEBRTC_FUNC(NumOfCodecs, ()) {
496 return num_codecs_;
497 }
498 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
499 if (index < 0 || index >= NumOfCodecs()) {
500 return -1;
501 }
502 const cricket::AudioCodec& c(*codecs_[index]);
503 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000504 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505 codec.plfreq = c.clockrate;
506 codec.pacsize = 0;
507 codec.channels = c.channels;
508 codec.rate = c.bitrate;
509 return 0;
510 }
511 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
512 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000513 // To match the behavior of the real implementation.
514 if (_stricmp(codec.plname, "telephone-event") == 0 ||
515 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
516 _stricmp(codec.plname, "CN") == 0 ||
517 _stricmp(codec.plname, "red") == 0 ) {
518 return -1;
519 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000521 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 return 0;
523 }
524 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
525 WEBRTC_CHECK_CHANNEL(channel);
526 codec = channels_[channel]->send_codec;
527 return 0;
528 }
529 WEBRTC_STUB(SetSecondarySendCodec, (int channel,
530 const webrtc::CodecInst& codec,
531 int red_payload_type));
532 WEBRTC_STUB(RemoveSecondarySendCodec, (int channel));
533 WEBRTC_STUB(GetSecondarySendCodec, (int channel,
534 webrtc::CodecInst& codec));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000535 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
536 WEBRTC_CHECK_CHANNEL(channel);
537 const Channel* c = channels_[channel];
538 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
539 it_packet != c->packets.end(); ++it_packet) {
540 int pltype;
541 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
542 continue;
543 }
544 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
545 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
546 ++it_codec) {
547 if (it_codec->pltype == pltype) {
548 codec = *it_codec;
549 return 0;
550 }
551 }
552 }
553 return -1;
554 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
556 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
557 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
558 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
559 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
560 bool useFixedFrameSize));
561 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
562 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
563 WEBRTC_FUNC(SetRecPayloadType, (int channel,
564 const webrtc::CodecInst& codec)) {
565 WEBRTC_CHECK_CHANNEL(channel);
566 Channel* ch = channels_[channel];
567 if (ch->playout)
568 return -1; // Channel is in use.
569 // Check if something else already has this slot.
570 if (codec.pltype != -1) {
571 for (std::vector<webrtc::CodecInst>::iterator it =
572 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
573 if (it->pltype == codec.pltype &&
574 _stricmp(it->plname, codec.plname) != 0) {
575 return -1;
576 }
577 }
578 }
579 // Otherwise try to find this codec and update its payload type.
580 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
581 it != ch->recv_codecs.end(); ++it) {
582 if (strcmp(it->plname, codec.plname) == 0 &&
583 it->plfreq == codec.plfreq) {
584 it->pltype = codec.pltype;
585 it->channels = codec.channels;
586 return 0;
587 }
588 }
589 return -1; // not found
590 }
591 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
592 webrtc::PayloadFrequencies frequency)) {
593 WEBRTC_CHECK_CHANNEL(channel);
594 if (frequency == webrtc::kFreq8000Hz) {
595 channels_[channel]->cn8_type = type;
596 } else if (frequency == webrtc::kFreq16000Hz) {
597 channels_[channel]->cn16_type = type;
598 }
599 return 0;
600 }
601 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
602 WEBRTC_CHECK_CHANNEL(channel);
603 Channel* ch = channels_[channel];
604 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
605 it != ch->recv_codecs.end(); ++it) {
606 if (strcmp(it->plname, codec.plname) == 0 &&
607 it->plfreq == codec.plfreq &&
608 it->channels == codec.channels &&
609 it->pltype != -1) {
610 codec.pltype = it->pltype;
611 return 0;
612 }
613 }
614 return -1; // not found
615 }
616 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
617 bool disableDTX)) {
618 WEBRTC_CHECK_CHANNEL(channel);
619 if (channels_[channel]->send_codec.channels == 2) {
620 // Replicating VoE behavior; VAD cannot be enabled for stereo.
621 return -1;
622 }
623 channels_[channel]->vad = enable;
624 return 0;
625 }
626 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
627 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000628#ifdef USE_WEBRTC_DEV_BRANCH
629 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
630 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000631 if (strcmp(channels_[channel]->send_codec.plname, "opus")) {
632 // Return -1 if current send codec is not Opus.
633 // TODO(minyue): Excludes other codecs if they support inband FEC.
634 return -1;
635 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000636 channels_[channel]->codec_fec = enable;
637 return 0;
638 }
639 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
640 WEBRTC_CHECK_CHANNEL(channel);
641 enable = channels_[channel]->codec_fec;
642 return 0;
643 }
644#endif // USE_WEBRTC_DEV_BRANCH
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645
646 // webrtc::VoEDtmf
647 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
648 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
649 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
650 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
651 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
652 return 0;
653 }
654
655 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
656 (int channel, unsigned char type)) {
657 channels_[channel]->dtmf_type = type;
658 return 0;
659 };
660 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
661 (int channel, unsigned char& type));
662
663 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
664 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
665 WEBRTC_STUB(SetDtmfPlayoutStatus, (int channel, bool enable));
666 WEBRTC_STUB(GetDtmfPlayoutStatus, (int channel, bool& enabled));
667
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668 WEBRTC_FUNC(PlayDtmfTone,
669 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
670 dtmf_info_.dtmf_event_code = event_code;
671 dtmf_info_.dtmf_length_ms = length_ms;
672 return 0;
673 }
674 WEBRTC_STUB(StartPlayingDtmfTone,
675 (int eventCode, int attenuationDb = 10));
676 WEBRTC_STUB(StopPlayingDtmfTone, ());
677
678 // webrtc::VoEFile
679 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
680 bool loop, webrtc::FileFormats format,
681 float volumeScaling, int startPointMs,
682 int stopPointMs)) {
683 WEBRTC_CHECK_CHANNEL(channel);
684 channels_[channel]->file = true;
685 return 0;
686 }
687 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
688 webrtc::FileFormats format,
689 float volumeScaling, int startPointMs,
690 int stopPointMs)) {
691 WEBRTC_CHECK_CHANNEL(channel);
692 channels_[channel]->file = true;
693 return 0;
694 }
695 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
696 WEBRTC_CHECK_CHANNEL(channel);
697 channels_[channel]->file = false;
698 return 0;
699 }
700 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
701 WEBRTC_CHECK_CHANNEL(channel);
702 return (channels_[channel]->file) ? 1 : 0;
703 }
704 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
705 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
706 const char* fileNameUTF8,
707 bool loop,
708 bool mixWithMicrophone,
709 webrtc::FileFormats format,
710 float volumeScaling));
711 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
712 webrtc::InStream* stream,
713 bool mixWithMicrophone,
714 webrtc::FileFormats format,
715 float volumeScaling));
716 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
717 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
718 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
719 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
720 webrtc::CodecInst* compression,
721 int maxSizeBytes));
722 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
723 webrtc::CodecInst* compression));
724 WEBRTC_STUB(StopRecordingPlayout, (int channel));
725 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
726 webrtc::CodecInst* compression,
727 int maxSizeBytes)) {
728 if (fail_start_recording_microphone_) {
729 return -1;
730 }
731 recording_microphone_ = true;
732 return 0;
733 }
734 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
735 webrtc::CodecInst* compression)) {
736 if (fail_start_recording_microphone_) {
737 return -1;
738 }
739 recording_microphone_ = true;
740 return 0;
741 }
742 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
743 if (!recording_microphone_) {
744 return -1;
745 }
746 recording_microphone_ = false;
747 return 0;
748 }
749 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
750 const char* fileNameOutUTF8));
751 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
752 webrtc::OutStream* streamOut));
753 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
754 const char* fileNameOutUTF8));
755 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
756 webrtc::OutStream* streamOut));
757 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
758 const char* fileNameOutUTF8,
759 webrtc::CodecInst* compression));
760 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
761 webrtc::OutStream* streamOut,
762 webrtc::CodecInst* compression));
763 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
764 const char* fileNameOutUTF8));
765 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
766 webrtc::OutStream* streamOut));
767 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
768 webrtc::FileFormats format));
769 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
770
771 // webrtc::VoEHardware
772 WEBRTC_STUB(GetCPULoad, (int&));
773 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
774 return GetNumDevices(num);
775 }
776 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
777 return GetNumDevices(num);
778 }
779 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
780 return GetDeviceName(i, name, guid);
781 }
782 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
783 return GetDeviceName(i, name, guid);
784 }
785 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
786 WEBRTC_STUB(SetPlayoutDevice, (int));
787 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
788 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
789 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
790 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
791 WEBRTC_STUB(ResetAudioDevice, ());
792 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
793 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
794 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000795 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
796 recording_sample_rate_ = samples_per_sec;
797 return 0;
798 }
799 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
800 *samples_per_sec = recording_sample_rate_;
801 return 0;
802 }
803 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
804 playout_sample_rate_ = samples_per_sec;
805 return 0;
806 }
807 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
808 *samples_per_sec = playout_sample_rate_;
809 return 0;
810 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
812 virtual bool BuiltInAECIsEnabled() const { return true; }
813
814 // webrtc::VoENetEqStats
815 WEBRTC_STUB(GetNetworkStatistics, (int, webrtc::NetworkStatistics&));
wu@webrtc.org24301a62013-12-13 19:17:43 +0000816 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
817 webrtc::AudioDecodingCallStats*)) {
818 WEBRTC_CHECK_CHANNEL(channel);
819 return 0;
820 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821
822 // webrtc::VoENetwork
823 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
824 webrtc::Transport& transport)) {
825 WEBRTC_CHECK_CHANNEL(channel);
826 channels_[channel]->external_transport = true;
827 return 0;
828 }
829 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
830 WEBRTC_CHECK_CHANNEL(channel);
831 channels_[channel]->external_transport = false;
832 return 0;
833 }
834 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
835 unsigned int length)) {
836 WEBRTC_CHECK_CHANNEL(channel);
837 if (!channels_[channel]->external_transport) return -1;
838 channels_[channel]->packets.push_back(
839 std::string(static_cast<const char*>(data), length));
840 return 0;
841 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000842 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
843 unsigned int length,
844 const webrtc::PacketTime& packet_time)) {
845 WEBRTC_CHECK_CHANNEL(channel);
846 if (ReceivedRTPPacket(channel, data, length) == -1) {
847 return -1;
848 }
849 channels_[channel]->last_rtp_packet_time = packet_time;
850 return 0;
851 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000852
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
854 unsigned int length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855
856 // webrtc::VoERTP_RTCP
857 WEBRTC_STUB(RegisterRTPObserver, (int channel,
858 webrtc::VoERTPObserver& observer));
859 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
860 WEBRTC_STUB(RegisterRTCPObserver, (int channel,
861 webrtc::VoERTCPObserver& observer));
862 WEBRTC_STUB(DeRegisterRTCPObserver, (int channel));
863 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
864 WEBRTC_CHECK_CHANNEL(channel);
865 channels_[channel]->send_ssrc = ssrc;
866 return 0;
867 }
868 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
869 WEBRTC_CHECK_CHANNEL(channel);
870 ssrc = channels_[channel]->send_ssrc;
871 return 0;
872 }
873 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000874 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
875 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000877 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
878 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 return 0;
880 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000881 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
882 unsigned char id)) {
883 WEBRTC_CHECK_CHANNEL(channel);
884 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
885 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
886 return 0;
887 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000888 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
889 unsigned char id)) {
890 WEBRTC_CHECK_CHANNEL(channel);
891 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
892 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
893 return 0;
894 }
895 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
896 unsigned char id)) {
897 WEBRTC_CHECK_CHANNEL(channel);
898 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
899 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
900 return 0;
901 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000902
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
904 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
905 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
906 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
907 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
908 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
909 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
910 unsigned int& NTPLow,
911 unsigned int& timestamp,
912 unsigned int& playoutTimestamp,
913 unsigned int* jitter,
914 unsigned short* fractionLost));
915 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
916 webrtc::SenderInfo* sender_info));
917 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
918 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
919 WEBRTC_CHECK_CHANNEL(channel);
920 webrtc::ReportBlock block;
921 block.source_SSRC = channels_[channel]->send_ssrc;
922 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
923 if (send_codec.pltype >= 0) {
924 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
925 if (send_codec.plfreq / 1000 > 0) {
926 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
927 }
928 block.cumulative_num_packets_lost = kIntStatValue;
929 block.extended_highest_sequence_number = kIntStatValue;
930 receive_blocks->push_back(block);
931 }
932 return 0;
933 }
934 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
935 unsigned char subType,
936 unsigned int name,
937 const char* data,
938 unsigned short dataLength));
939 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
940 unsigned int& maxJitterMs,
941 unsigned int& discardedPackets));
942 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
943 WEBRTC_CHECK_CHANNEL(channel);
944 stats.fractionLost = static_cast<int16>(kIntStatValue);
945 stats.cumulativeLost = kIntStatValue;
946 stats.extendedMax = kIntStatValue;
947 stats.jitterSamples = kIntStatValue;
948 stats.rttMs = kIntStatValue;
949 stats.bytesSent = kIntStatValue;
950 stats.packetsSent = kIntStatValue;
951 stats.bytesReceived = kIntStatValue;
952 stats.packetsReceived = kIntStatValue;
953 return 0;
954 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000955#ifdef USE_WEBRTC_DEV_BRANCH
956 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000957 return SetFECStatus(channel, enable, redPayloadtype);
958 }
959#endif
960 // TODO(minyue): remove the below function when transition to SetREDStatus
961 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
963 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000964 channels_[channel]->red = enable;
965 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 return 0;
967 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000968#ifdef USE_WEBRTC_DEV_BRANCH
969 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000970 return GetFECStatus(channel, enable, redPayloadtype);
971 }
972#endif
973 // TODO(minyue): remove the below function when transition to GetREDStatus
974 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
976 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000977 enable = channels_[channel]->red;
978 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 return 0;
980 }
981 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
982 WEBRTC_CHECK_CHANNEL(channel);
983 channels_[channel]->nack = enable;
984 channels_[channel]->nack_max_packets = maxNoPackets;
985 return 0;
986 }
987 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
988 webrtc::RTPDirections direction));
989 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
990 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
991 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
992 bool markerBit, const char* payloadData,
993 unsigned short payloadSize));
994 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
995 uint32_t* lastRemoteTimeStamp));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000996 WEBRTC_FUNC(SetVideoEngineBWETarget, (int channel,
997 webrtc::ViENetwork* vie_network,
998 int video_channel)) {
999 WEBRTC_CHECK_CHANNEL(channel);
1000 channels_[channel]->vie_network = vie_network;
1001 channels_[channel]->video_channel = video_channel;
1002 return 0;
1003 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004
1005 // webrtc::VoEVideoSync
1006 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1007 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001008 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1010 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1011 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1012 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1013 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1014 int* playout_buffer_delay_ms));
1015 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1016
1017 // webrtc::VoEVolumeControl
1018 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1019 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1020 WEBRTC_STUB(SetSystemOutputMute, (bool));
1021 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1022 WEBRTC_STUB(SetMicVolume, (unsigned int));
1023 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1024 WEBRTC_STUB(SetInputMute, (int, bool));
1025 WEBRTC_STUB(GetInputMute, (int, bool&));
1026 WEBRTC_STUB(SetSystemInputMute, (bool));
1027 WEBRTC_STUB(GetSystemInputMute, (bool&));
1028 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1029 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1030 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1031 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1032 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1033 WEBRTC_CHECK_CHANNEL(channel);
1034 channels_[channel]->volume_scale= scale;
1035 return 0;
1036 }
1037 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1038 WEBRTC_CHECK_CHANNEL(channel);
1039 scale = channels_[channel]->volume_scale;
1040 return 0;
1041 }
1042 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1043 WEBRTC_CHECK_CHANNEL(channel);
1044 channels_[channel]->volume_pan_left = left;
1045 channels_[channel]->volume_pan_right = right;
1046 return 0;
1047 }
1048 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1049 WEBRTC_CHECK_CHANNEL(channel);
1050 left = channels_[channel]->volume_pan_left;
1051 right = channels_[channel]->volume_pan_right;
1052 return 0;
1053 }
1054
1055 // webrtc::VoEAudioProcessing
1056 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1057 ns_enabled_ = enable;
1058 ns_mode_ = mode;
1059 return 0;
1060 }
1061 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1062 enabled = ns_enabled_;
1063 mode = ns_mode_;
1064 return 0;
1065 }
1066
1067 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1068 agc_enabled_ = enable;
1069 agc_mode_ = mode;
1070 return 0;
1071 }
1072 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1073 enabled = agc_enabled_;
1074 mode = agc_mode_;
1075 return 0;
1076 }
1077
1078 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1079 agc_config_ = config;
1080 return 0;
1081 }
1082 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1083 config = agc_config_;
1084 return 0;
1085 }
1086 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1087 ec_enabled_ = enable;
1088 ec_mode_ = mode;
1089 return 0;
1090 }
1091 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1092 enabled = ec_enabled_;
1093 mode = ec_mode_;
1094 return 0;
1095 }
1096 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1097 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1098 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1099 WEBRTC_STUB(DelayOffsetMs, ());
1100 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1101 aecm_mode_ = mode;
1102 cng_enabled_ = enableCNG;
1103 return 0;
1104 }
1105 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1106 mode = aecm_mode_;
1107 enabledCNG = cng_enabled_;
1108 return 0;
1109 }
1110 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1111 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1112 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001113 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1114 webrtc::AgcModes mode)) {
1115 channels_[channel]->rx_agc_enabled = enable;
1116 channels_[channel]->rx_agc_mode = mode;
1117 return 0;
1118 }
1119 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1120 webrtc::AgcModes& mode)) {
1121 enabled = channels_[channel]->rx_agc_enabled;
1122 mode = channels_[channel]->rx_agc_mode;
1123 return 0;
1124 }
1125
1126 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1127 channels_[channel]->rx_agc_config = config;
1128 return 0;
1129 }
1130 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1131 config = channels_[channel]->rx_agc_config;
1132 return 0;
1133 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134
1135 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1136 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1137 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1138 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1139 ec_metrics_enabled_ = enable;
1140 return 0;
1141 }
1142 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1143 enabled = ec_metrics_enabled_;
1144 return 0;
1145 }
1146 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
1147 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std));
1148
1149 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001150 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 WEBRTC_STUB(StopDebugRecording, ());
1152
1153 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1154 typing_detection_enabled_ = enable;
1155 return 0;
1156 }
1157 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1158 enabled = typing_detection_enabled_;
1159 return 0;
1160 }
1161
1162 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1163 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1164 int costPerTyping,
1165 int reportingThreshold,
1166 int penaltyDecay,
1167 int typeEventDelay));
1168 int EnableHighPassFilter(bool enable) {
1169 highpass_filter_enabled_ = enable;
1170 return 0;
1171 }
1172 bool IsHighPassFilterEnabled() {
1173 return highpass_filter_enabled_;
1174 }
1175 bool IsStereoChannelSwappingEnabled() {
1176 return stereo_swapping_enabled_;
1177 }
1178 void EnableStereoChannelSwapping(bool enable) {
1179 stereo_swapping_enabled_ = enable;
1180 }
1181 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1182 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1183 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1184 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1185 }
1186 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1187 return (dtmf_info_.dtmf_event_code == event_code &&
1188 dtmf_info_.dtmf_length_ms == length_ms);
1189 }
1190 // webrtc::VoEExternalMedia
1191 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1192 (int channel, webrtc::ProcessingTypes type,
1193 webrtc::VoEMediaProcess& processObject)) {
1194 WEBRTC_CHECK_CHANNEL(channel);
1195 if (channels_[channel]->media_processor_registered) {
1196 return -1;
1197 }
1198 channels_[channel]->media_processor_registered = true;
1199 media_processor_ = &processObject;
1200 return 0;
1201 }
1202 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1203 (int channel, webrtc::ProcessingTypes type)) {
1204 WEBRTC_CHECK_CHANNEL(channel);
1205 if (!channels_[channel]->media_processor_registered) {
1206 return -1;
1207 }
1208 channels_[channel]->media_processor_registered = false;
1209 media_processor_ = NULL;
1210 return 0;
1211 }
1212 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1213 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1214 WEBRTC_STUB(ExternalRecordingInsertData,
1215 (const int16_t speechData10ms[], int lengthSamples,
1216 int samplingFreqHz, int current_delay_ms));
1217 WEBRTC_STUB(ExternalPlayoutGetData,
1218 (int16_t speechData10ms[], int samplingFreqHz,
1219 int current_delay_ms, int& lengthSamples));
1220 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1221 webrtc::AudioFrame* frame));
1222 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1223
1224 private:
1225 int GetNumDevices(int& num) {
1226#ifdef WIN32
1227 num = 1;
1228#else
1229 // On non-Windows platforms VE adds a special entry for the default device,
1230 // so if there is one physical device then there are two entries in the
1231 // list.
1232 num = 2;
1233#endif
1234 return 0;
1235 }
1236
1237 int GetDeviceName(int i, char* name, char* guid) {
1238 const char *s;
1239#ifdef WIN32
1240 if (0 == i) {
1241 s = kFakeDeviceName;
1242 } else {
1243 return -1;
1244 }
1245#else
1246 // See comment above.
1247 if (0 == i) {
1248 s = kFakeDefaultDeviceName;
1249 } else if (1 == i) {
1250 s = kFakeDeviceName;
1251 } else {
1252 return -1;
1253 }
1254#endif
1255 strcpy(name, s);
1256 guid[0] = '\0';
1257 return 0;
1258 }
1259
1260 bool inited_;
1261 int last_channel_;
1262 std::map<int, Channel*> channels_;
1263 bool fail_create_channel_;
1264 const cricket::AudioCodec* const* codecs_;
1265 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001266 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267 bool ec_enabled_;
1268 bool ec_metrics_enabled_;
1269 bool cng_enabled_;
1270 bool ns_enabled_;
1271 bool agc_enabled_;
1272 bool highpass_filter_enabled_;
1273 bool stereo_swapping_enabled_;
1274 bool typing_detection_enabled_;
1275 webrtc::EcModes ec_mode_;
1276 webrtc::AecmModes aecm_mode_;
1277 webrtc::NsModes ns_mode_;
1278 webrtc::AgcModes agc_mode_;
1279 webrtc::AgcConfig agc_config_;
1280 webrtc::VoiceEngineObserver* observer_;
1281 int playout_fail_channel_;
1282 int send_fail_channel_;
1283 bool fail_start_recording_microphone_;
1284 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001285 int recording_sample_rate_;
1286 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287 DtmfInfo dtmf_info_;
1288 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001289#ifdef USE_WEBRTC_DEV_BRANCH
1290 FakeAudioProcessing audio_processing_;
1291#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292};
1293
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001294#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1295
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296} // namespace cricket
1297
1298#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_