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