blob: dc27e969b8a9d4d7ccda4bb9decf46d856a9fc6a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2010 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_
29#define TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_
30
31#include <list>
32#include <map>
33#include <vector>
34
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/codec.h"
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +000036#include "talk/media/base/rtputils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/media/base/voiceprocessor.h"
38#include "talk/media/webrtc/fakewebrtccommon.h"
39#include "talk/media/webrtc/webrtcvoe.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "webrtc/base/basictypes.h"
41#include "webrtc/base/gunit.h"
42#include "webrtc/base/stringutils.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
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000046#include "webrtc/video_engine/include/vie_network.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000047
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048namespace cricket {
49
50// Function returning stats will return these values
51// for all values based on type.
52const int kIntStatValue = 123;
53const float kFractionLostStatValue = 0.5;
54
55static const char kFakeDefaultDeviceName[] = "Fake Default";
56static const int kFakeDefaultDeviceId = -1;
57static const char kFakeDeviceName[] = "Fake Device";
58#ifdef WIN32
59static const int kFakeDeviceId = 0;
60#else
61static const int kFakeDeviceId = 1;
62#endif
63
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000064static const int kOpusBandwidthNb = 4000;
65static const int kOpusBandwidthMb = 6000;
66static const int kOpusBandwidthWb = 8000;
67static const int kOpusBandwidthSwb = 12000;
68static const int kOpusBandwidthFb = 20000;
69
henrike@webrtc.org79047f92014-03-06 23:46:59 +000070// Verify the header extension ID, if enabled, is within the bounds specified in
71// [RFC5285]: 1-14 inclusive.
72#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
73 do { \
74 if (enable && (id < 1 || id > 14)) { \
75 return -1; \
76 } \
77 } while (0);
78
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000079#ifdef USE_WEBRTC_DEV_BRANCH
80class FakeAudioProcessing : public webrtc::AudioProcessing {
81 public:
82 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
83
84 WEBRTC_STUB(Initialize, ())
85 WEBRTC_STUB(Initialize, (
86 int input_sample_rate_hz,
87 int output_sample_rate_hz,
88 int reverse_sample_rate_hz,
89 webrtc::AudioProcessing::ChannelLayout input_layout,
90 webrtc::AudioProcessing::ChannelLayout output_layout,
91 webrtc::AudioProcessing::ChannelLayout reverse_layout));
92
93 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
94 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
95 }
96
97 WEBRTC_STUB(set_sample_rate_hz, (int rate));
98 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
99 WEBRTC_STUB_CONST(sample_rate_hz, ());
100 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
101 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
102 WEBRTC_STUB_CONST(num_input_channels, ());
103 WEBRTC_STUB_CONST(num_output_channels, ());
104 WEBRTC_STUB_CONST(num_reverse_channels, ());
105 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
106 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
107 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
108 WEBRTC_STUB(ProcessStream, (
109 const float* const* src,
110 int samples_per_channel,
111 int input_sample_rate_hz,
112 webrtc::AudioProcessing::ChannelLayout input_layout,
113 int output_sample_rate_hz,
114 webrtc::AudioProcessing::ChannelLayout output_layout,
115 float* const* dest));
116 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
117 WEBRTC_STUB(AnalyzeReverseStream, (
118 const float* const* data,
119 int samples_per_channel,
120 int sample_rate_hz,
121 webrtc::AudioProcessing::ChannelLayout layout));
122 WEBRTC_STUB(set_stream_delay_ms, (int delay));
123 WEBRTC_STUB_CONST(stream_delay_ms, ());
124 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
125 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
126 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
127 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
128 WEBRTC_STUB_CONST(delay_offset_ms, ());
129 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
130 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
131 WEBRTC_STUB(StopDebugRecording, ());
132 virtual webrtc::EchoCancellation* echo_cancellation() const OVERRIDE {
133 return NULL;
134 }
135 virtual webrtc::EchoControlMobile* echo_control_mobile() const OVERRIDE {
136 return NULL;
137 }
138 virtual webrtc::GainControl* gain_control() const OVERRIDE { return NULL; }
139 virtual webrtc::HighPassFilter* high_pass_filter() const OVERRIDE {
140 return NULL;
141 }
142 virtual webrtc::LevelEstimator* level_estimator() const OVERRIDE {
143 return NULL;
144 }
145 virtual webrtc::NoiseSuppression* noise_suppression() const OVERRIDE {
146 return NULL;
147 }
148 virtual webrtc::VoiceDetection* voice_detection() const OVERRIDE {
149 return NULL;
150 }
151
152 bool experimental_ns_enabled() {
153 return experimental_ns_enabled_;
154 }
155
156 private:
157 bool experimental_ns_enabled_;
158};
159#endif
160
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161class FakeWebRtcVoiceEngine
162 : public webrtc::VoEAudioProcessing,
163 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
164 public webrtc::VoEFile, public webrtc::VoEHardware,
165 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
166 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
167 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
168 public:
169 struct DtmfInfo {
170 DtmfInfo()
171 : dtmf_event_code(-1),
172 dtmf_out_of_band(false),
173 dtmf_length_ms(-1) {}
174 int dtmf_event_code;
175 bool dtmf_out_of_band;
176 int dtmf_length_ms;
177 };
178 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000179 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 : external_transport(false),
181 send(false),
182 playout(false),
183 volume_scale(1.0),
184 volume_pan_left(1.0),
185 volume_pan_right(1.0),
186 file(false),
187 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000188 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000189 max_encoding_bandwidth(0),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000190 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 nack(false),
192 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000193 rx_agc_enabled(false),
194 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 cn8_type(13),
196 cn16_type(105),
197 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000198 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 nack_max_packets(0),
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000200 vie_network(NULL),
201 video_channel(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000203 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000204 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000205 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000206 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000208 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 }
210 bool external_transport;
211 bool send;
212 bool playout;
213 float volume_scale;
214 float volume_pan_left;
215 float volume_pan_right;
216 bool file;
217 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000218 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000219 int max_encoding_bandwidth;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000220 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 bool nack;
222 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000223 bool rx_agc_enabled;
224 webrtc::AgcModes rx_agc_mode;
225 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 int cn8_type;
227 int cn16_type;
228 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000229 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 int nack_max_packets;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000231 webrtc::ViENetwork* vie_network;
232 int video_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000234 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000235 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000236 int send_absolute_sender_time_ext_;
237 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 DtmfInfo dtmf_info;
239 std::vector<webrtc::CodecInst> recv_codecs;
240 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000241 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 std::list<std::string> packets;
243 };
244
245 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
246 int num_codecs)
247 : inited_(false),
248 last_channel_(-1),
249 fail_create_channel_(false),
250 codecs_(codecs),
251 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000252 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 ec_enabled_(false),
254 ec_metrics_enabled_(false),
255 cng_enabled_(false),
256 ns_enabled_(false),
257 agc_enabled_(false),
258 highpass_filter_enabled_(false),
259 stereo_swapping_enabled_(false),
260 typing_detection_enabled_(false),
261 ec_mode_(webrtc::kEcDefault),
262 aecm_mode_(webrtc::kAecmSpeakerphone),
263 ns_mode_(webrtc::kNsDefault),
264 agc_mode_(webrtc::kAgcDefault),
265 observer_(NULL),
266 playout_fail_channel_(-1),
267 send_fail_channel_(-1),
268 fail_start_recording_microphone_(false),
269 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000270 recording_sample_rate_(-1),
271 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 media_processor_(NULL) {
273 memset(&agc_config_, 0, sizeof(agc_config_));
274 }
275 ~FakeWebRtcVoiceEngine() {
276 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
277 // destructors, but just in case ...
278 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
279 i != channels_.end(); ++i) {
280 delete i->second;
281 }
282 }
283
284 bool IsExternalMediaProcessorRegistered() const {
285 return media_processor_ != NULL;
286 }
287 bool IsInited() const { return inited_; }
288 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000289 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
290 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
291 iter != channels_.end(); ++iter) {
292 if (local_ssrc == iter->second->send_ssrc)
293 return iter->first;
294 }
295 return -1;
296 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000297 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 bool GetPlayout(int channel) {
299 return channels_[channel]->playout;
300 }
301 bool GetSend(int channel) {
302 return channels_[channel]->send;
303 }
304 bool GetRecordingMicrophone() {
305 return recording_microphone_;
306 }
307 bool GetVAD(int channel) {
308 return channels_[channel]->vad;
309 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000310 bool GetRED(int channel) {
311 return channels_[channel]->red;
312 }
313 bool GetCodecFEC(int channel) {
314 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000316 int GetMaxEncodingBandwidth(int channel) {
317 return channels_[channel]->max_encoding_bandwidth;
318 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 bool GetNACK(int channel) {
320 return channels_[channel]->nack;
321 }
322 int GetNACKMaxPackets(int channel) {
323 return channels_[channel]->nack_max_packets;
324 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000325 webrtc::ViENetwork* GetViENetwork(int channel) {
326 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000327 // WARNING: This pointer is for verification purposes only. Calling
328 // functions on it may result in undefined behavior!
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000329 return channels_[channel]->vie_network;
330 }
331 int GetVideoChannel(int channel) {
332 WEBRTC_ASSERT_CHANNEL(channel);
333 return channels_[channel]->video_channel;
334 }
335 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
336 WEBRTC_ASSERT_CHANNEL(channel);
337 return channels_[channel]->last_rtp_packet_time;
338 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 int GetSendCNPayloadType(int channel, bool wideband) {
340 return (wideband) ?
341 channels_[channel]->cn16_type :
342 channels_[channel]->cn8_type;
343 }
344 int GetSendTelephoneEventPayloadType(int channel) {
345 return channels_[channel]->dtmf_type;
346 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000347 int GetSendREDPayloadType(int channel) {
348 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350 bool CheckPacket(int channel, const void* data, size_t len) {
351 bool result = !CheckNoPacket(channel);
352 if (result) {
353 std::string packet = channels_[channel]->packets.front();
354 result = (packet == std::string(static_cast<const char*>(data), len));
355 channels_[channel]->packets.pop_front();
356 }
357 return result;
358 }
359 bool CheckNoPacket(int channel) {
360 return channels_[channel]->packets.empty();
361 }
362 void TriggerCallbackOnError(int channel_num, int err_code) {
363 ASSERT(observer_ != NULL);
364 observer_->CallbackOnError(channel_num, err_code);
365 }
366 void set_playout_fail_channel(int channel) {
367 playout_fail_channel_ = channel;
368 }
369 void set_send_fail_channel(int channel) {
370 send_fail_channel_ = channel;
371 }
372 void set_fail_start_recording_microphone(
373 bool fail_start_recording_microphone) {
374 fail_start_recording_microphone_ = fail_start_recording_microphone;
375 }
376 void set_fail_create_channel(bool fail_create_channel) {
377 fail_create_channel_ = fail_create_channel;
378 }
379 void TriggerProcessPacket(MediaProcessorDirection direction) {
380 webrtc::ProcessingTypes pt =
381 (direction == cricket::MPD_TX) ?
382 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
383 if (media_processor_ != NULL) {
384 media_processor_->Process(0,
385 pt,
386 NULL,
387 0,
388 0,
389 true);
390 }
391 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000392 int AddChannel() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000393 if (fail_create_channel_) {
394 return -1;
395 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000396 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000397 for (int i = 0; i < NumOfCodecs(); ++i) {
398 webrtc::CodecInst codec;
399 GetCodec(i, codec);
400 ch->recv_codecs.push_back(codec);
401 }
402 channels_[++last_channel_] = ch;
403 return last_channel_;
404 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000405 int GetSendRtpExtensionId(int channel, const std::string& extension) {
406 WEBRTC_ASSERT_CHANNEL(channel);
407 if (extension == kRtpAudioLevelHeaderExtension) {
408 return channels_[channel]->send_audio_level_ext_;
409 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
410 return channels_[channel]->send_absolute_sender_time_ext_;
411 }
412 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000413 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000414 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
415 WEBRTC_ASSERT_CHANNEL(channel);
416 if (extension == kRtpAudioLevelHeaderExtension) {
417 return channels_[channel]->receive_audio_level_ext_;
418 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
419 return channels_[channel]->receive_absolute_sender_time_ext_;
420 }
421 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000422 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000423
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000424 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
425
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 WEBRTC_STUB(Release, ());
427
428 // webrtc::VoEBase
429 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
430 webrtc::VoiceEngineObserver& observer)) {
431 observer_ = &observer;
432 return 0;
433 }
434 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
435 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
436 webrtc::AudioProcessing* audioproc)) {
437 inited_ = true;
438 return 0;
439 }
440 WEBRTC_FUNC(Terminate, ()) {
441 inited_ = false;
442 return 0;
443 }
444 virtual webrtc::AudioProcessing* audio_processing() OVERRIDE {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000445#ifdef USE_WEBRTC_DEV_BRANCH
446 return &audio_processing_;
447#else
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 return NULL;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000449#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000452 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000454 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
455 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000456 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 WEBRTC_FUNC(DeleteChannel, (int channel)) {
458 WEBRTC_CHECK_CHANNEL(channel);
459 delete channels_[channel];
460 channels_.erase(channel);
461 return 0;
462 }
463 WEBRTC_STUB(StartReceive, (int channel));
464 WEBRTC_FUNC(StartPlayout, (int channel)) {
465 if (playout_fail_channel_ != channel) {
466 WEBRTC_CHECK_CHANNEL(channel);
467 channels_[channel]->playout = true;
468 return 0;
469 } else {
470 // When playout_fail_channel_ == channel, fail the StartPlayout on this
471 // channel.
472 return -1;
473 }
474 }
475 WEBRTC_FUNC(StartSend, (int channel)) {
476 if (send_fail_channel_ != channel) {
477 WEBRTC_CHECK_CHANNEL(channel);
478 channels_[channel]->send = true;
479 return 0;
480 } else {
481 // When send_fail_channel_ == channel, fail the StartSend on this
482 // channel.
483 return -1;
484 }
485 }
486 WEBRTC_STUB(StopReceive, (int channel));
487 WEBRTC_FUNC(StopPlayout, (int channel)) {
488 WEBRTC_CHECK_CHANNEL(channel);
489 channels_[channel]->playout = false;
490 return 0;
491 }
492 WEBRTC_FUNC(StopSend, (int channel)) {
493 WEBRTC_CHECK_CHANNEL(channel);
494 channels_[channel]->send = false;
495 return 0;
496 }
497 WEBRTC_STUB(GetVersion, (char version[1024]));
498 WEBRTC_STUB(LastError, ());
499 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
500 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501
502 // webrtc::VoECodec
503 WEBRTC_FUNC(NumOfCodecs, ()) {
504 return num_codecs_;
505 }
506 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
507 if (index < 0 || index >= NumOfCodecs()) {
508 return -1;
509 }
510 const cricket::AudioCodec& c(*codecs_[index]);
511 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000512 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 codec.plfreq = c.clockrate;
514 codec.pacsize = 0;
515 codec.channels = c.channels;
516 codec.rate = c.bitrate;
517 return 0;
518 }
519 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
520 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000521 // To match the behavior of the real implementation.
522 if (_stricmp(codec.plname, "telephone-event") == 0 ||
523 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
524 _stricmp(codec.plname, "CN") == 0 ||
525 _stricmp(codec.plname, "red") == 0 ) {
526 return -1;
527 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000529 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 return 0;
531 }
532 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
533 WEBRTC_CHECK_CHANNEL(channel);
534 codec = channels_[channel]->send_codec;
535 return 0;
536 }
537 WEBRTC_STUB(SetSecondarySendCodec, (int channel,
538 const webrtc::CodecInst& codec,
539 int red_payload_type));
540 WEBRTC_STUB(RemoveSecondarySendCodec, (int channel));
541 WEBRTC_STUB(GetSecondarySendCodec, (int channel,
542 webrtc::CodecInst& codec));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000543 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
544 WEBRTC_CHECK_CHANNEL(channel);
545 const Channel* c = channels_[channel];
546 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
547 it_packet != c->packets.end(); ++it_packet) {
548 int pltype;
549 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
550 continue;
551 }
552 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
553 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
554 ++it_codec) {
555 if (it_codec->pltype == pltype) {
556 codec = *it_codec;
557 return 0;
558 }
559 }
560 }
561 return -1;
562 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
564 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
565 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
566 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
567 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
568 bool useFixedFrameSize));
569 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
570 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
571 WEBRTC_FUNC(SetRecPayloadType, (int channel,
572 const webrtc::CodecInst& codec)) {
573 WEBRTC_CHECK_CHANNEL(channel);
574 Channel* ch = channels_[channel];
575 if (ch->playout)
576 return -1; // Channel is in use.
577 // Check if something else already has this slot.
578 if (codec.pltype != -1) {
579 for (std::vector<webrtc::CodecInst>::iterator it =
580 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
581 if (it->pltype == codec.pltype &&
582 _stricmp(it->plname, codec.plname) != 0) {
583 return -1;
584 }
585 }
586 }
587 // Otherwise try to find this codec and update its payload type.
588 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
589 it != ch->recv_codecs.end(); ++it) {
590 if (strcmp(it->plname, codec.plname) == 0 &&
591 it->plfreq == codec.plfreq) {
592 it->pltype = codec.pltype;
593 it->channels = codec.channels;
594 return 0;
595 }
596 }
597 return -1; // not found
598 }
599 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
600 webrtc::PayloadFrequencies frequency)) {
601 WEBRTC_CHECK_CHANNEL(channel);
602 if (frequency == webrtc::kFreq8000Hz) {
603 channels_[channel]->cn8_type = type;
604 } else if (frequency == webrtc::kFreq16000Hz) {
605 channels_[channel]->cn16_type = type;
606 }
607 return 0;
608 }
609 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
610 WEBRTC_CHECK_CHANNEL(channel);
611 Channel* ch = channels_[channel];
612 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
613 it != ch->recv_codecs.end(); ++it) {
614 if (strcmp(it->plname, codec.plname) == 0 &&
615 it->plfreq == codec.plfreq &&
616 it->channels == codec.channels &&
617 it->pltype != -1) {
618 codec.pltype = it->pltype;
619 return 0;
620 }
621 }
622 return -1; // not found
623 }
624 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
625 bool disableDTX)) {
626 WEBRTC_CHECK_CHANNEL(channel);
627 if (channels_[channel]->send_codec.channels == 2) {
628 // Replicating VoE behavior; VAD cannot be enabled for stereo.
629 return -1;
630 }
631 channels_[channel]->vad = enable;
632 return 0;
633 }
634 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
635 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000636
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000637#ifdef USE_WEBRTC_DEV_BRANCH
638 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
639 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000640 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000641 // Return -1 if current send codec is not Opus.
642 // TODO(minyue): Excludes other codecs if they support inband FEC.
643 return -1;
644 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000645 channels_[channel]->codec_fec = enable;
646 return 0;
647 }
648 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
649 WEBRTC_CHECK_CHANNEL(channel);
650 enable = channels_[channel]->codec_fec;
651 return 0;
652 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000653
654 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
655 WEBRTC_CHECK_CHANNEL(channel);
656 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
657 // Return -1 if current send codec is not Opus.
658 return -1;
659 }
660 if (frequency_hz <= 8000)
661 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
662 else if (frequency_hz <= 12000)
663 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
664 else if (frequency_hz <= 16000)
665 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
666 else if (frequency_hz <= 24000)
667 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
668 else
669 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
670 return 0;
671 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000672#endif // USE_WEBRTC_DEV_BRANCH
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673
674 // webrtc::VoEDtmf
675 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
676 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
677 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
678 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
679 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
680 return 0;
681 }
682
683 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
684 (int channel, unsigned char type)) {
685 channels_[channel]->dtmf_type = type;
686 return 0;
687 };
688 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
689 (int channel, unsigned char& type));
690
691 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
692 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 WEBRTC_FUNC(PlayDtmfTone,
695 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
696 dtmf_info_.dtmf_event_code = event_code;
697 dtmf_info_.dtmf_length_ms = length_ms;
698 return 0;
699 }
700 WEBRTC_STUB(StartPlayingDtmfTone,
701 (int eventCode, int attenuationDb = 10));
702 WEBRTC_STUB(StopPlayingDtmfTone, ());
703
704 // webrtc::VoEFile
705 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
706 bool loop, webrtc::FileFormats format,
707 float volumeScaling, int startPointMs,
708 int stopPointMs)) {
709 WEBRTC_CHECK_CHANNEL(channel);
710 channels_[channel]->file = true;
711 return 0;
712 }
713 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
714 webrtc::FileFormats format,
715 float volumeScaling, int startPointMs,
716 int stopPointMs)) {
717 WEBRTC_CHECK_CHANNEL(channel);
718 channels_[channel]->file = true;
719 return 0;
720 }
721 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
722 WEBRTC_CHECK_CHANNEL(channel);
723 channels_[channel]->file = false;
724 return 0;
725 }
726 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
727 WEBRTC_CHECK_CHANNEL(channel);
728 return (channels_[channel]->file) ? 1 : 0;
729 }
730 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
731 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
732 const char* fileNameUTF8,
733 bool loop,
734 bool mixWithMicrophone,
735 webrtc::FileFormats format,
736 float volumeScaling));
737 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
738 webrtc::InStream* stream,
739 bool mixWithMicrophone,
740 webrtc::FileFormats format,
741 float volumeScaling));
742 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
743 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
744 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
745 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
746 webrtc::CodecInst* compression,
747 int maxSizeBytes));
748 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
749 webrtc::CodecInst* compression));
750 WEBRTC_STUB(StopRecordingPlayout, (int channel));
751 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
752 webrtc::CodecInst* compression,
753 int maxSizeBytes)) {
754 if (fail_start_recording_microphone_) {
755 return -1;
756 }
757 recording_microphone_ = true;
758 return 0;
759 }
760 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
761 webrtc::CodecInst* compression)) {
762 if (fail_start_recording_microphone_) {
763 return -1;
764 }
765 recording_microphone_ = true;
766 return 0;
767 }
768 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
769 if (!recording_microphone_) {
770 return -1;
771 }
772 recording_microphone_ = false;
773 return 0;
774 }
775 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
776 const char* fileNameOutUTF8));
777 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
778 webrtc::OutStream* streamOut));
779 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
780 const char* fileNameOutUTF8));
781 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
782 webrtc::OutStream* streamOut));
783 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
784 const char* fileNameOutUTF8,
785 webrtc::CodecInst* compression));
786 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
787 webrtc::OutStream* streamOut,
788 webrtc::CodecInst* compression));
789 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
790 const char* fileNameOutUTF8));
791 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
792 webrtc::OutStream* streamOut));
793 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
794 webrtc::FileFormats format));
795 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
796
797 // webrtc::VoEHardware
798 WEBRTC_STUB(GetCPULoad, (int&));
799 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
800 return GetNumDevices(num);
801 }
802 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
803 return GetNumDevices(num);
804 }
805 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
806 return GetDeviceName(i, name, guid);
807 }
808 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
809 return GetDeviceName(i, name, guid);
810 }
811 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
812 WEBRTC_STUB(SetPlayoutDevice, (int));
813 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
814 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
815 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
816 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
817 WEBRTC_STUB(ResetAudioDevice, ());
818 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
819 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
820 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000821 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
822 recording_sample_rate_ = samples_per_sec;
823 return 0;
824 }
825 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
826 *samples_per_sec = recording_sample_rate_;
827 return 0;
828 }
829 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
830 playout_sample_rate_ = samples_per_sec;
831 return 0;
832 }
833 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
834 *samples_per_sec = playout_sample_rate_;
835 return 0;
836 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
838 virtual bool BuiltInAECIsEnabled() const { return true; }
839
840 // webrtc::VoENetEqStats
841 WEBRTC_STUB(GetNetworkStatistics, (int, webrtc::NetworkStatistics&));
wu@webrtc.org24301a62013-12-13 19:17:43 +0000842 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
843 webrtc::AudioDecodingCallStats*)) {
844 WEBRTC_CHECK_CHANNEL(channel);
845 return 0;
846 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847
848 // webrtc::VoENetwork
849 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
850 webrtc::Transport& transport)) {
851 WEBRTC_CHECK_CHANNEL(channel);
852 channels_[channel]->external_transport = true;
853 return 0;
854 }
855 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
856 WEBRTC_CHECK_CHANNEL(channel);
857 channels_[channel]->external_transport = false;
858 return 0;
859 }
860 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000861 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 WEBRTC_CHECK_CHANNEL(channel);
863 if (!channels_[channel]->external_transport) return -1;
864 channels_[channel]->packets.push_back(
865 std::string(static_cast<const char*>(data), length));
866 return 0;
867 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000868 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000869 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000870 const webrtc::PacketTime& packet_time)) {
871 WEBRTC_CHECK_CHANNEL(channel);
872 if (ReceivedRTPPacket(channel, data, length) == -1) {
873 return -1;
874 }
875 channels_[channel]->last_rtp_packet_time = packet_time;
876 return 0;
877 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000878
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000880 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881
882 // webrtc::VoERTP_RTCP
883 WEBRTC_STUB(RegisterRTPObserver, (int channel,
884 webrtc::VoERTPObserver& observer));
885 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
887 WEBRTC_CHECK_CHANNEL(channel);
888 channels_[channel]->send_ssrc = ssrc;
889 return 0;
890 }
891 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
892 WEBRTC_CHECK_CHANNEL(channel);
893 ssrc = channels_[channel]->send_ssrc;
894 return 0;
895 }
896 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000897 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
898 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000900 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
901 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 return 0;
903 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000904 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
905 unsigned char id)) {
906 WEBRTC_CHECK_CHANNEL(channel);
907 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
908 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
909 return 0;
910 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000911 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
912 unsigned char id)) {
913 WEBRTC_CHECK_CHANNEL(channel);
914 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
915 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
916 return 0;
917 }
918 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
919 unsigned char id)) {
920 WEBRTC_CHECK_CHANNEL(channel);
921 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
922 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
923 return 0;
924 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000925
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
927 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
928 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
929 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
930 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
931 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
932 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
933 unsigned int& NTPLow,
934 unsigned int& timestamp,
935 unsigned int& playoutTimestamp,
936 unsigned int* jitter,
937 unsigned short* fractionLost));
938 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
939 webrtc::SenderInfo* sender_info));
940 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
941 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
942 WEBRTC_CHECK_CHANNEL(channel);
943 webrtc::ReportBlock block;
944 block.source_SSRC = channels_[channel]->send_ssrc;
945 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
946 if (send_codec.pltype >= 0) {
947 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
948 if (send_codec.plfreq / 1000 > 0) {
949 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
950 }
951 block.cumulative_num_packets_lost = kIntStatValue;
952 block.extended_highest_sequence_number = kIntStatValue;
953 receive_blocks->push_back(block);
954 }
955 return 0;
956 }
957 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
958 unsigned char subType,
959 unsigned int name,
960 const char* data,
961 unsigned short dataLength));
962 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
963 unsigned int& maxJitterMs,
964 unsigned int& discardedPackets));
965 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
966 WEBRTC_CHECK_CHANNEL(channel);
967 stats.fractionLost = static_cast<int16>(kIntStatValue);
968 stats.cumulativeLost = kIntStatValue;
969 stats.extendedMax = kIntStatValue;
970 stats.jitterSamples = kIntStatValue;
971 stats.rttMs = kIntStatValue;
972 stats.bytesSent = kIntStatValue;
973 stats.packetsSent = kIntStatValue;
974 stats.bytesReceived = kIntStatValue;
975 stats.packetsReceived = kIntStatValue;
976 return 0;
977 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000978#ifdef USE_WEBRTC_DEV_BRANCH
979 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000980 return SetFECStatus(channel, enable, redPayloadtype);
981 }
982#endif
983 // TODO(minyue): remove the below function when transition to SetREDStatus
984 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
986 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000987 channels_[channel]->red = enable;
988 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 return 0;
990 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000991#ifdef USE_WEBRTC_DEV_BRANCH
992 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000993 return GetFECStatus(channel, enable, redPayloadtype);
994 }
995#endif
996 // TODO(minyue): remove the below function when transition to GetREDStatus
997 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
999 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001000 enable = channels_[channel]->red;
1001 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 return 0;
1003 }
1004 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
1005 WEBRTC_CHECK_CHANNEL(channel);
1006 channels_[channel]->nack = enable;
1007 channels_[channel]->nack_max_packets = maxNoPackets;
1008 return 0;
1009 }
1010 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
1011 webrtc::RTPDirections direction));
1012 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
1013 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
1014 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
1015 bool markerBit, const char* payloadData,
1016 unsigned short payloadSize));
1017 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
1018 uint32_t* lastRemoteTimeStamp));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001019 WEBRTC_FUNC(SetVideoEngineBWETarget, (int channel,
1020 webrtc::ViENetwork* vie_network,
1021 int video_channel)) {
1022 WEBRTC_CHECK_CHANNEL(channel);
1023 channels_[channel]->vie_network = vie_network;
1024 channels_[channel]->video_channel = video_channel;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001025 if (vie_network) {
1026 // The interface is released here to avoid leaks. A test should not
1027 // attempt to call functions on the interface stored in the channel.
1028 vie_network->Release();
1029 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001030 return 0;
1031 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032
1033 // webrtc::VoEVideoSync
1034 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1035 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001036 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1038 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1039 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1040 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1041 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1042 int* playout_buffer_delay_ms));
1043 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1044
1045 // webrtc::VoEVolumeControl
1046 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1047 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1048 WEBRTC_STUB(SetSystemOutputMute, (bool));
1049 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1050 WEBRTC_STUB(SetMicVolume, (unsigned int));
1051 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1052 WEBRTC_STUB(SetInputMute, (int, bool));
1053 WEBRTC_STUB(GetInputMute, (int, bool&));
1054 WEBRTC_STUB(SetSystemInputMute, (bool));
1055 WEBRTC_STUB(GetSystemInputMute, (bool&));
1056 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1057 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1058 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1059 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1060 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1061 WEBRTC_CHECK_CHANNEL(channel);
1062 channels_[channel]->volume_scale= scale;
1063 return 0;
1064 }
1065 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1066 WEBRTC_CHECK_CHANNEL(channel);
1067 scale = channels_[channel]->volume_scale;
1068 return 0;
1069 }
1070 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1071 WEBRTC_CHECK_CHANNEL(channel);
1072 channels_[channel]->volume_pan_left = left;
1073 channels_[channel]->volume_pan_right = right;
1074 return 0;
1075 }
1076 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1077 WEBRTC_CHECK_CHANNEL(channel);
1078 left = channels_[channel]->volume_pan_left;
1079 right = channels_[channel]->volume_pan_right;
1080 return 0;
1081 }
1082
1083 // webrtc::VoEAudioProcessing
1084 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1085 ns_enabled_ = enable;
1086 ns_mode_ = mode;
1087 return 0;
1088 }
1089 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1090 enabled = ns_enabled_;
1091 mode = ns_mode_;
1092 return 0;
1093 }
1094
1095 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1096 agc_enabled_ = enable;
1097 agc_mode_ = mode;
1098 return 0;
1099 }
1100 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1101 enabled = agc_enabled_;
1102 mode = agc_mode_;
1103 return 0;
1104 }
1105
1106 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1107 agc_config_ = config;
1108 return 0;
1109 }
1110 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1111 config = agc_config_;
1112 return 0;
1113 }
1114 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1115 ec_enabled_ = enable;
1116 ec_mode_ = mode;
1117 return 0;
1118 }
1119 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1120 enabled = ec_enabled_;
1121 mode = ec_mode_;
1122 return 0;
1123 }
1124 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1125 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1126 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1127 WEBRTC_STUB(DelayOffsetMs, ());
1128 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1129 aecm_mode_ = mode;
1130 cng_enabled_ = enableCNG;
1131 return 0;
1132 }
1133 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1134 mode = aecm_mode_;
1135 enabledCNG = cng_enabled_;
1136 return 0;
1137 }
1138 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1139 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1140 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001141 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1142 webrtc::AgcModes mode)) {
1143 channels_[channel]->rx_agc_enabled = enable;
1144 channels_[channel]->rx_agc_mode = mode;
1145 return 0;
1146 }
1147 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1148 webrtc::AgcModes& mode)) {
1149 enabled = channels_[channel]->rx_agc_enabled;
1150 mode = channels_[channel]->rx_agc_mode;
1151 return 0;
1152 }
1153
1154 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1155 channels_[channel]->rx_agc_config = config;
1156 return 0;
1157 }
1158 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1159 config = channels_[channel]->rx_agc_config;
1160 return 0;
1161 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001162
1163 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1164 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1165 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1166 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1167 ec_metrics_enabled_ = enable;
1168 return 0;
1169 }
1170 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1171 enabled = ec_metrics_enabled_;
1172 return 0;
1173 }
1174 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
1175 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std));
1176
1177 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001178 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001179 WEBRTC_STUB(StopDebugRecording, ());
1180
1181 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1182 typing_detection_enabled_ = enable;
1183 return 0;
1184 }
1185 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1186 enabled = typing_detection_enabled_;
1187 return 0;
1188 }
1189
1190 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1191 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1192 int costPerTyping,
1193 int reportingThreshold,
1194 int penaltyDecay,
1195 int typeEventDelay));
1196 int EnableHighPassFilter(bool enable) {
1197 highpass_filter_enabled_ = enable;
1198 return 0;
1199 }
1200 bool IsHighPassFilterEnabled() {
1201 return highpass_filter_enabled_;
1202 }
1203 bool IsStereoChannelSwappingEnabled() {
1204 return stereo_swapping_enabled_;
1205 }
1206 void EnableStereoChannelSwapping(bool enable) {
1207 stereo_swapping_enabled_ = enable;
1208 }
1209 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1210 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1211 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1212 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1213 }
1214 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1215 return (dtmf_info_.dtmf_event_code == event_code &&
1216 dtmf_info_.dtmf_length_ms == length_ms);
1217 }
1218 // webrtc::VoEExternalMedia
1219 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1220 (int channel, webrtc::ProcessingTypes type,
1221 webrtc::VoEMediaProcess& processObject)) {
1222 WEBRTC_CHECK_CHANNEL(channel);
1223 if (channels_[channel]->media_processor_registered) {
1224 return -1;
1225 }
1226 channels_[channel]->media_processor_registered = true;
1227 media_processor_ = &processObject;
1228 return 0;
1229 }
1230 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1231 (int channel, webrtc::ProcessingTypes type)) {
1232 WEBRTC_CHECK_CHANNEL(channel);
1233 if (!channels_[channel]->media_processor_registered) {
1234 return -1;
1235 }
1236 channels_[channel]->media_processor_registered = false;
1237 media_processor_ = NULL;
1238 return 0;
1239 }
1240 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1241 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1242 WEBRTC_STUB(ExternalRecordingInsertData,
1243 (const int16_t speechData10ms[], int lengthSamples,
1244 int samplingFreqHz, int current_delay_ms));
1245 WEBRTC_STUB(ExternalPlayoutGetData,
1246 (int16_t speechData10ms[], int samplingFreqHz,
1247 int current_delay_ms, int& lengthSamples));
1248 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1249 webrtc::AudioFrame* frame));
1250 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1251
1252 private:
1253 int GetNumDevices(int& num) {
1254#ifdef WIN32
1255 num = 1;
1256#else
1257 // On non-Windows platforms VE adds a special entry for the default device,
1258 // so if there is one physical device then there are two entries in the
1259 // list.
1260 num = 2;
1261#endif
1262 return 0;
1263 }
1264
1265 int GetDeviceName(int i, char* name, char* guid) {
1266 const char *s;
1267#ifdef WIN32
1268 if (0 == i) {
1269 s = kFakeDeviceName;
1270 } else {
1271 return -1;
1272 }
1273#else
1274 // See comment above.
1275 if (0 == i) {
1276 s = kFakeDefaultDeviceName;
1277 } else if (1 == i) {
1278 s = kFakeDeviceName;
1279 } else {
1280 return -1;
1281 }
1282#endif
1283 strcpy(name, s);
1284 guid[0] = '\0';
1285 return 0;
1286 }
1287
1288 bool inited_;
1289 int last_channel_;
1290 std::map<int, Channel*> channels_;
1291 bool fail_create_channel_;
1292 const cricket::AudioCodec* const* codecs_;
1293 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001294 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 bool ec_enabled_;
1296 bool ec_metrics_enabled_;
1297 bool cng_enabled_;
1298 bool ns_enabled_;
1299 bool agc_enabled_;
1300 bool highpass_filter_enabled_;
1301 bool stereo_swapping_enabled_;
1302 bool typing_detection_enabled_;
1303 webrtc::EcModes ec_mode_;
1304 webrtc::AecmModes aecm_mode_;
1305 webrtc::NsModes ns_mode_;
1306 webrtc::AgcModes agc_mode_;
1307 webrtc::AgcConfig agc_config_;
1308 webrtc::VoiceEngineObserver* observer_;
1309 int playout_fail_channel_;
1310 int send_fail_channel_;
1311 bool fail_start_recording_microphone_;
1312 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001313 int recording_sample_rate_;
1314 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 DtmfInfo dtmf_info_;
1316 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001317#ifdef USE_WEBRTC_DEV_BRANCH
1318 FakeAudioProcessing audio_processing_;
1319#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320};
1321
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001322#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1323
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324} // namespace cricket
1325
1326#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_