blob: c984a01dab1073b1c6341ccfb53a625890b0e3a5 [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&));
501 WEBRTC_STUB(SetNetEQPlayoutMode, (int, webrtc::NetEqModes));
502 WEBRTC_STUB(GetNetEQPlayoutMode, (int, webrtc::NetEqModes&));
503
504 // webrtc::VoECodec
505 WEBRTC_FUNC(NumOfCodecs, ()) {
506 return num_codecs_;
507 }
508 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
509 if (index < 0 || index >= NumOfCodecs()) {
510 return -1;
511 }
512 const cricket::AudioCodec& c(*codecs_[index]);
513 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000514 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 codec.plfreq = c.clockrate;
516 codec.pacsize = 0;
517 codec.channels = c.channels;
518 codec.rate = c.bitrate;
519 return 0;
520 }
521 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
522 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000523 // To match the behavior of the real implementation.
524 if (_stricmp(codec.plname, "telephone-event") == 0 ||
525 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
526 _stricmp(codec.plname, "CN") == 0 ||
527 _stricmp(codec.plname, "red") == 0 ) {
528 return -1;
529 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000531 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532 return 0;
533 }
534 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
535 WEBRTC_CHECK_CHANNEL(channel);
536 codec = channels_[channel]->send_codec;
537 return 0;
538 }
539 WEBRTC_STUB(SetSecondarySendCodec, (int channel,
540 const webrtc::CodecInst& codec,
541 int red_payload_type));
542 WEBRTC_STUB(RemoveSecondarySendCodec, (int channel));
543 WEBRTC_STUB(GetSecondarySendCodec, (int channel,
544 webrtc::CodecInst& codec));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000545 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
546 WEBRTC_CHECK_CHANNEL(channel);
547 const Channel* c = channels_[channel];
548 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
549 it_packet != c->packets.end(); ++it_packet) {
550 int pltype;
551 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
552 continue;
553 }
554 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
555 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
556 ++it_codec) {
557 if (it_codec->pltype == pltype) {
558 codec = *it_codec;
559 return 0;
560 }
561 }
562 }
563 return -1;
564 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
566 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
567 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
568 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
569 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
570 bool useFixedFrameSize));
571 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
572 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
573 WEBRTC_FUNC(SetRecPayloadType, (int channel,
574 const webrtc::CodecInst& codec)) {
575 WEBRTC_CHECK_CHANNEL(channel);
576 Channel* ch = channels_[channel];
577 if (ch->playout)
578 return -1; // Channel is in use.
579 // Check if something else already has this slot.
580 if (codec.pltype != -1) {
581 for (std::vector<webrtc::CodecInst>::iterator it =
582 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
583 if (it->pltype == codec.pltype &&
584 _stricmp(it->plname, codec.plname) != 0) {
585 return -1;
586 }
587 }
588 }
589 // Otherwise try to find this codec and update its payload type.
590 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
591 it != ch->recv_codecs.end(); ++it) {
592 if (strcmp(it->plname, codec.plname) == 0 &&
593 it->plfreq == codec.plfreq) {
594 it->pltype = codec.pltype;
595 it->channels = codec.channels;
596 return 0;
597 }
598 }
599 return -1; // not found
600 }
601 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
602 webrtc::PayloadFrequencies frequency)) {
603 WEBRTC_CHECK_CHANNEL(channel);
604 if (frequency == webrtc::kFreq8000Hz) {
605 channels_[channel]->cn8_type = type;
606 } else if (frequency == webrtc::kFreq16000Hz) {
607 channels_[channel]->cn16_type = type;
608 }
609 return 0;
610 }
611 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
612 WEBRTC_CHECK_CHANNEL(channel);
613 Channel* ch = channels_[channel];
614 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
615 it != ch->recv_codecs.end(); ++it) {
616 if (strcmp(it->plname, codec.plname) == 0 &&
617 it->plfreq == codec.plfreq &&
618 it->channels == codec.channels &&
619 it->pltype != -1) {
620 codec.pltype = it->pltype;
621 return 0;
622 }
623 }
624 return -1; // not found
625 }
626 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
627 bool disableDTX)) {
628 WEBRTC_CHECK_CHANNEL(channel);
629 if (channels_[channel]->send_codec.channels == 2) {
630 // Replicating VoE behavior; VAD cannot be enabled for stereo.
631 return -1;
632 }
633 channels_[channel]->vad = enable;
634 return 0;
635 }
636 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
637 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000638
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000639#ifdef USE_WEBRTC_DEV_BRANCH
640 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
641 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000642 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000643 // Return -1 if current send codec is not Opus.
644 // TODO(minyue): Excludes other codecs if they support inband FEC.
645 return -1;
646 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000647 channels_[channel]->codec_fec = enable;
648 return 0;
649 }
650 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
651 WEBRTC_CHECK_CHANNEL(channel);
652 enable = channels_[channel]->codec_fec;
653 return 0;
654 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000655
656 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
657 WEBRTC_CHECK_CHANNEL(channel);
658 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
659 // Return -1 if current send codec is not Opus.
660 return -1;
661 }
662 if (frequency_hz <= 8000)
663 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
664 else if (frequency_hz <= 12000)
665 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
666 else if (frequency_hz <= 16000)
667 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
668 else if (frequency_hz <= 24000)
669 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
670 else
671 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
672 return 0;
673 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000674#endif // USE_WEBRTC_DEV_BRANCH
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675
676 // webrtc::VoEDtmf
677 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
678 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
679 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
680 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
681 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
682 return 0;
683 }
684
685 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
686 (int channel, unsigned char type)) {
687 channels_[channel]->dtmf_type = type;
688 return 0;
689 };
690 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
691 (int channel, unsigned char& type));
692
693 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
694 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
695 WEBRTC_STUB(SetDtmfPlayoutStatus, (int channel, bool enable));
696 WEBRTC_STUB(GetDtmfPlayoutStatus, (int channel, bool& enabled));
697
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000698 WEBRTC_FUNC(PlayDtmfTone,
699 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
700 dtmf_info_.dtmf_event_code = event_code;
701 dtmf_info_.dtmf_length_ms = length_ms;
702 return 0;
703 }
704 WEBRTC_STUB(StartPlayingDtmfTone,
705 (int eventCode, int attenuationDb = 10));
706 WEBRTC_STUB(StopPlayingDtmfTone, ());
707
708 // webrtc::VoEFile
709 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
710 bool loop, webrtc::FileFormats format,
711 float volumeScaling, int startPointMs,
712 int stopPointMs)) {
713 WEBRTC_CHECK_CHANNEL(channel);
714 channels_[channel]->file = true;
715 return 0;
716 }
717 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
718 webrtc::FileFormats format,
719 float volumeScaling, int startPointMs,
720 int stopPointMs)) {
721 WEBRTC_CHECK_CHANNEL(channel);
722 channels_[channel]->file = true;
723 return 0;
724 }
725 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
726 WEBRTC_CHECK_CHANNEL(channel);
727 channels_[channel]->file = false;
728 return 0;
729 }
730 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
731 WEBRTC_CHECK_CHANNEL(channel);
732 return (channels_[channel]->file) ? 1 : 0;
733 }
734 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
735 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
736 const char* fileNameUTF8,
737 bool loop,
738 bool mixWithMicrophone,
739 webrtc::FileFormats format,
740 float volumeScaling));
741 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
742 webrtc::InStream* stream,
743 bool mixWithMicrophone,
744 webrtc::FileFormats format,
745 float volumeScaling));
746 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
747 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
748 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
749 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
750 webrtc::CodecInst* compression,
751 int maxSizeBytes));
752 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
753 webrtc::CodecInst* compression));
754 WEBRTC_STUB(StopRecordingPlayout, (int channel));
755 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
756 webrtc::CodecInst* compression,
757 int maxSizeBytes)) {
758 if (fail_start_recording_microphone_) {
759 return -1;
760 }
761 recording_microphone_ = true;
762 return 0;
763 }
764 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
765 webrtc::CodecInst* compression)) {
766 if (fail_start_recording_microphone_) {
767 return -1;
768 }
769 recording_microphone_ = true;
770 return 0;
771 }
772 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
773 if (!recording_microphone_) {
774 return -1;
775 }
776 recording_microphone_ = false;
777 return 0;
778 }
779 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
780 const char* fileNameOutUTF8));
781 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
782 webrtc::OutStream* streamOut));
783 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
784 const char* fileNameOutUTF8));
785 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
786 webrtc::OutStream* streamOut));
787 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
788 const char* fileNameOutUTF8,
789 webrtc::CodecInst* compression));
790 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
791 webrtc::OutStream* streamOut,
792 webrtc::CodecInst* compression));
793 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
794 const char* fileNameOutUTF8));
795 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
796 webrtc::OutStream* streamOut));
797 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
798 webrtc::FileFormats format));
799 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
800
801 // webrtc::VoEHardware
802 WEBRTC_STUB(GetCPULoad, (int&));
803 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
804 return GetNumDevices(num);
805 }
806 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
807 return GetNumDevices(num);
808 }
809 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
810 return GetDeviceName(i, name, guid);
811 }
812 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
813 return GetDeviceName(i, name, guid);
814 }
815 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
816 WEBRTC_STUB(SetPlayoutDevice, (int));
817 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
818 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
819 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
820 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
821 WEBRTC_STUB(ResetAudioDevice, ());
822 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
823 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
824 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000825 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
826 recording_sample_rate_ = samples_per_sec;
827 return 0;
828 }
829 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
830 *samples_per_sec = recording_sample_rate_;
831 return 0;
832 }
833 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
834 playout_sample_rate_ = samples_per_sec;
835 return 0;
836 }
837 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
838 *samples_per_sec = playout_sample_rate_;
839 return 0;
840 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
842 virtual bool BuiltInAECIsEnabled() const { return true; }
843
844 // webrtc::VoENetEqStats
845 WEBRTC_STUB(GetNetworkStatistics, (int, webrtc::NetworkStatistics&));
wu@webrtc.org24301a62013-12-13 19:17:43 +0000846 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
847 webrtc::AudioDecodingCallStats*)) {
848 WEBRTC_CHECK_CHANNEL(channel);
849 return 0;
850 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851
852 // webrtc::VoENetwork
853 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
854 webrtc::Transport& transport)) {
855 WEBRTC_CHECK_CHANNEL(channel);
856 channels_[channel]->external_transport = true;
857 return 0;
858 }
859 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
860 WEBRTC_CHECK_CHANNEL(channel);
861 channels_[channel]->external_transport = false;
862 return 0;
863 }
864 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
865 unsigned int length)) {
866 WEBRTC_CHECK_CHANNEL(channel);
867 if (!channels_[channel]->external_transport) return -1;
868 channels_[channel]->packets.push_back(
869 std::string(static_cast<const char*>(data), length));
870 return 0;
871 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000872 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
873 unsigned int length,
874 const webrtc::PacketTime& packet_time)) {
875 WEBRTC_CHECK_CHANNEL(channel);
876 if (ReceivedRTPPacket(channel, data, length) == -1) {
877 return -1;
878 }
879 channels_[channel]->last_rtp_packet_time = packet_time;
880 return 0;
881 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000882
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
884 unsigned int length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885
886 // webrtc::VoERTP_RTCP
887 WEBRTC_STUB(RegisterRTPObserver, (int channel,
888 webrtc::VoERTPObserver& observer));
889 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
890 WEBRTC_STUB(RegisterRTCPObserver, (int channel,
891 webrtc::VoERTCPObserver& observer));
892 WEBRTC_STUB(DeRegisterRTCPObserver, (int channel));
893 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
894 WEBRTC_CHECK_CHANNEL(channel);
895 channels_[channel]->send_ssrc = ssrc;
896 return 0;
897 }
898 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
899 WEBRTC_CHECK_CHANNEL(channel);
900 ssrc = channels_[channel]->send_ssrc;
901 return 0;
902 }
903 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000904 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
905 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000907 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
908 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 return 0;
910 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000911 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
912 unsigned char id)) {
913 WEBRTC_CHECK_CHANNEL(channel);
914 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
915 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
916 return 0;
917 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000918 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
919 unsigned char id)) {
920 WEBRTC_CHECK_CHANNEL(channel);
921 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
922 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
923 return 0;
924 }
925 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
926 unsigned char id)) {
927 WEBRTC_CHECK_CHANNEL(channel);
928 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
929 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
930 return 0;
931 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000932
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
934 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
935 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
936 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
937 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
938 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
939 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
940 unsigned int& NTPLow,
941 unsigned int& timestamp,
942 unsigned int& playoutTimestamp,
943 unsigned int* jitter,
944 unsigned short* fractionLost));
945 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
946 webrtc::SenderInfo* sender_info));
947 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
948 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
949 WEBRTC_CHECK_CHANNEL(channel);
950 webrtc::ReportBlock block;
951 block.source_SSRC = channels_[channel]->send_ssrc;
952 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
953 if (send_codec.pltype >= 0) {
954 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
955 if (send_codec.plfreq / 1000 > 0) {
956 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
957 }
958 block.cumulative_num_packets_lost = kIntStatValue;
959 block.extended_highest_sequence_number = kIntStatValue;
960 receive_blocks->push_back(block);
961 }
962 return 0;
963 }
964 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
965 unsigned char subType,
966 unsigned int name,
967 const char* data,
968 unsigned short dataLength));
969 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
970 unsigned int& maxJitterMs,
971 unsigned int& discardedPackets));
972 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
973 WEBRTC_CHECK_CHANNEL(channel);
974 stats.fractionLost = static_cast<int16>(kIntStatValue);
975 stats.cumulativeLost = kIntStatValue;
976 stats.extendedMax = kIntStatValue;
977 stats.jitterSamples = kIntStatValue;
978 stats.rttMs = kIntStatValue;
979 stats.bytesSent = kIntStatValue;
980 stats.packetsSent = kIntStatValue;
981 stats.bytesReceived = kIntStatValue;
982 stats.packetsReceived = kIntStatValue;
983 return 0;
984 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000985#ifdef USE_WEBRTC_DEV_BRANCH
986 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000987 return SetFECStatus(channel, enable, redPayloadtype);
988 }
989#endif
990 // TODO(minyue): remove the below function when transition to SetREDStatus
991 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
993 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000994 channels_[channel]->red = enable;
995 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 return 0;
997 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000998#ifdef USE_WEBRTC_DEV_BRANCH
999 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +00001000 return GetFECStatus(channel, enable, redPayloadtype);
1001 }
1002#endif
1003 // TODO(minyue): remove the below function when transition to GetREDStatus
1004 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
1006 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001007 enable = channels_[channel]->red;
1008 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 return 0;
1010 }
1011 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
1012 WEBRTC_CHECK_CHANNEL(channel);
1013 channels_[channel]->nack = enable;
1014 channels_[channel]->nack_max_packets = maxNoPackets;
1015 return 0;
1016 }
1017 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
1018 webrtc::RTPDirections direction));
1019 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
1020 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
1021 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
1022 bool markerBit, const char* payloadData,
1023 unsigned short payloadSize));
1024 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
1025 uint32_t* lastRemoteTimeStamp));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001026 WEBRTC_FUNC(SetVideoEngineBWETarget, (int channel,
1027 webrtc::ViENetwork* vie_network,
1028 int video_channel)) {
1029 WEBRTC_CHECK_CHANNEL(channel);
1030 channels_[channel]->vie_network = vie_network;
1031 channels_[channel]->video_channel = video_channel;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001032 if (vie_network) {
1033 // The interface is released here to avoid leaks. A test should not
1034 // attempt to call functions on the interface stored in the channel.
1035 vie_network->Release();
1036 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001037 return 0;
1038 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039
1040 // webrtc::VoEVideoSync
1041 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1042 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001043 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1045 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1046 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1047 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1048 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1049 int* playout_buffer_delay_ms));
1050 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1051
1052 // webrtc::VoEVolumeControl
1053 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1054 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1055 WEBRTC_STUB(SetSystemOutputMute, (bool));
1056 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1057 WEBRTC_STUB(SetMicVolume, (unsigned int));
1058 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1059 WEBRTC_STUB(SetInputMute, (int, bool));
1060 WEBRTC_STUB(GetInputMute, (int, bool&));
1061 WEBRTC_STUB(SetSystemInputMute, (bool));
1062 WEBRTC_STUB(GetSystemInputMute, (bool&));
1063 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1064 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1065 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1066 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1067 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1068 WEBRTC_CHECK_CHANNEL(channel);
1069 channels_[channel]->volume_scale= scale;
1070 return 0;
1071 }
1072 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1073 WEBRTC_CHECK_CHANNEL(channel);
1074 scale = channels_[channel]->volume_scale;
1075 return 0;
1076 }
1077 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1078 WEBRTC_CHECK_CHANNEL(channel);
1079 channels_[channel]->volume_pan_left = left;
1080 channels_[channel]->volume_pan_right = right;
1081 return 0;
1082 }
1083 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1084 WEBRTC_CHECK_CHANNEL(channel);
1085 left = channels_[channel]->volume_pan_left;
1086 right = channels_[channel]->volume_pan_right;
1087 return 0;
1088 }
1089
1090 // webrtc::VoEAudioProcessing
1091 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1092 ns_enabled_ = enable;
1093 ns_mode_ = mode;
1094 return 0;
1095 }
1096 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1097 enabled = ns_enabled_;
1098 mode = ns_mode_;
1099 return 0;
1100 }
1101
1102 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1103 agc_enabled_ = enable;
1104 agc_mode_ = mode;
1105 return 0;
1106 }
1107 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1108 enabled = agc_enabled_;
1109 mode = agc_mode_;
1110 return 0;
1111 }
1112
1113 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1114 agc_config_ = config;
1115 return 0;
1116 }
1117 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1118 config = agc_config_;
1119 return 0;
1120 }
1121 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1122 ec_enabled_ = enable;
1123 ec_mode_ = mode;
1124 return 0;
1125 }
1126 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1127 enabled = ec_enabled_;
1128 mode = ec_mode_;
1129 return 0;
1130 }
1131 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1132 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1133 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1134 WEBRTC_STUB(DelayOffsetMs, ());
1135 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1136 aecm_mode_ = mode;
1137 cng_enabled_ = enableCNG;
1138 return 0;
1139 }
1140 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1141 mode = aecm_mode_;
1142 enabledCNG = cng_enabled_;
1143 return 0;
1144 }
1145 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1146 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1147 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001148 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1149 webrtc::AgcModes mode)) {
1150 channels_[channel]->rx_agc_enabled = enable;
1151 channels_[channel]->rx_agc_mode = mode;
1152 return 0;
1153 }
1154 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1155 webrtc::AgcModes& mode)) {
1156 enabled = channels_[channel]->rx_agc_enabled;
1157 mode = channels_[channel]->rx_agc_mode;
1158 return 0;
1159 }
1160
1161 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1162 channels_[channel]->rx_agc_config = config;
1163 return 0;
1164 }
1165 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1166 config = channels_[channel]->rx_agc_config;
1167 return 0;
1168 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001169
1170 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1171 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1172 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1173 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1174 ec_metrics_enabled_ = enable;
1175 return 0;
1176 }
1177 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1178 enabled = ec_metrics_enabled_;
1179 return 0;
1180 }
1181 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
1182 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std));
1183
1184 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001185 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 WEBRTC_STUB(StopDebugRecording, ());
1187
1188 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1189 typing_detection_enabled_ = enable;
1190 return 0;
1191 }
1192 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1193 enabled = typing_detection_enabled_;
1194 return 0;
1195 }
1196
1197 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1198 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1199 int costPerTyping,
1200 int reportingThreshold,
1201 int penaltyDecay,
1202 int typeEventDelay));
1203 int EnableHighPassFilter(bool enable) {
1204 highpass_filter_enabled_ = enable;
1205 return 0;
1206 }
1207 bool IsHighPassFilterEnabled() {
1208 return highpass_filter_enabled_;
1209 }
1210 bool IsStereoChannelSwappingEnabled() {
1211 return stereo_swapping_enabled_;
1212 }
1213 void EnableStereoChannelSwapping(bool enable) {
1214 stereo_swapping_enabled_ = enable;
1215 }
1216 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1217 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1218 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1219 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1220 }
1221 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1222 return (dtmf_info_.dtmf_event_code == event_code &&
1223 dtmf_info_.dtmf_length_ms == length_ms);
1224 }
1225 // webrtc::VoEExternalMedia
1226 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1227 (int channel, webrtc::ProcessingTypes type,
1228 webrtc::VoEMediaProcess& processObject)) {
1229 WEBRTC_CHECK_CHANNEL(channel);
1230 if (channels_[channel]->media_processor_registered) {
1231 return -1;
1232 }
1233 channels_[channel]->media_processor_registered = true;
1234 media_processor_ = &processObject;
1235 return 0;
1236 }
1237 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1238 (int channel, webrtc::ProcessingTypes type)) {
1239 WEBRTC_CHECK_CHANNEL(channel);
1240 if (!channels_[channel]->media_processor_registered) {
1241 return -1;
1242 }
1243 channels_[channel]->media_processor_registered = false;
1244 media_processor_ = NULL;
1245 return 0;
1246 }
1247 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1248 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1249 WEBRTC_STUB(ExternalRecordingInsertData,
1250 (const int16_t speechData10ms[], int lengthSamples,
1251 int samplingFreqHz, int current_delay_ms));
1252 WEBRTC_STUB(ExternalPlayoutGetData,
1253 (int16_t speechData10ms[], int samplingFreqHz,
1254 int current_delay_ms, int& lengthSamples));
1255 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1256 webrtc::AudioFrame* frame));
1257 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1258
1259 private:
1260 int GetNumDevices(int& num) {
1261#ifdef WIN32
1262 num = 1;
1263#else
1264 // On non-Windows platforms VE adds a special entry for the default device,
1265 // so if there is one physical device then there are two entries in the
1266 // list.
1267 num = 2;
1268#endif
1269 return 0;
1270 }
1271
1272 int GetDeviceName(int i, char* name, char* guid) {
1273 const char *s;
1274#ifdef WIN32
1275 if (0 == i) {
1276 s = kFakeDeviceName;
1277 } else {
1278 return -1;
1279 }
1280#else
1281 // See comment above.
1282 if (0 == i) {
1283 s = kFakeDefaultDeviceName;
1284 } else if (1 == i) {
1285 s = kFakeDeviceName;
1286 } else {
1287 return -1;
1288 }
1289#endif
1290 strcpy(name, s);
1291 guid[0] = '\0';
1292 return 0;
1293 }
1294
1295 bool inited_;
1296 int last_channel_;
1297 std::map<int, Channel*> channels_;
1298 bool fail_create_channel_;
1299 const cricket::AudioCodec* const* codecs_;
1300 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001301 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 bool ec_enabled_;
1303 bool ec_metrics_enabled_;
1304 bool cng_enabled_;
1305 bool ns_enabled_;
1306 bool agc_enabled_;
1307 bool highpass_filter_enabled_;
1308 bool stereo_swapping_enabled_;
1309 bool typing_detection_enabled_;
1310 webrtc::EcModes ec_mode_;
1311 webrtc::AecmModes aecm_mode_;
1312 webrtc::NsModes ns_mode_;
1313 webrtc::AgcModes agc_mode_;
1314 webrtc::AgcConfig agc_config_;
1315 webrtc::VoiceEngineObserver* observer_;
1316 int playout_fail_channel_;
1317 int send_fail_channel_;
1318 bool fail_start_recording_microphone_;
1319 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001320 int recording_sample_rate_;
1321 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 DtmfInfo dtmf_info_;
1323 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001324#ifdef USE_WEBRTC_DEV_BRANCH
1325 FakeAudioProcessing audio_processing_;
1326#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327};
1328
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001329#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1330
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331} // namespace cricket
1332
1333#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_