blob: bb529e2c8092595a43cf899d83954510da80ea70 [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#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000044#include "webrtc/video_engine/include/vie_network.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000045
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046namespace cricket {
47
48// Function returning stats will return these values
49// for all values based on type.
50const int kIntStatValue = 123;
51const float kFractionLostStatValue = 0.5;
52
53static const char kFakeDefaultDeviceName[] = "Fake Default";
54static const int kFakeDefaultDeviceId = -1;
55static const char kFakeDeviceName[] = "Fake Device";
56#ifdef WIN32
57static const int kFakeDeviceId = 0;
58#else
59static const int kFakeDeviceId = 1;
60#endif
61
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000062static const int kOpusBandwidthNb = 4000;
63static const int kOpusBandwidthMb = 6000;
64static const int kOpusBandwidthWb = 8000;
65static const int kOpusBandwidthSwb = 12000;
66static const int kOpusBandwidthFb = 20000;
67
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +000068static const webrtc::NetworkStatistics kNetStats = {
69 1, // uint16_t currentBufferSize;
70 2, // uint16_t preferredBufferSize;
71 true, // bool jitterPeaksFound;
72 1234, // uint16_t currentPacketLossRate;
73 567, // uint16_t currentDiscardRate;
74 8901, // uint16_t currentExpandRate;
75 234, // uint16_t currentSpeechExpandRate;
76 5678, // uint16_t currentPreemptiveRate;
77 9012, // uint16_t currentAccelerateRate;
78 3456, // uint16_t currentSecondaryDecodedRate;
79 7890, // int32_t clockDriftPPM;
80 54, // meanWaitingTimeMs;
81 32, // int medianWaitingTimeMs;
82 1, // int minWaitingTimeMs;
83 98, // int maxWaitingTimeMs;
84 7654, // int addedSamples;
85}; // These random but non-trivial numbers are used for testing.
86
henrike@webrtc.org79047f92014-03-06 23:46:59 +000087// Verify the header extension ID, if enabled, is within the bounds specified in
88// [RFC5285]: 1-14 inclusive.
89#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
90 do { \
91 if (enable && (id < 1 || id > 14)) { \
92 return -1; \
93 } \
94 } while (0);
95
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000096class FakeAudioProcessing : public webrtc::AudioProcessing {
97 public:
98 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
99
100 WEBRTC_STUB(Initialize, ())
101 WEBRTC_STUB(Initialize, (
102 int input_sample_rate_hz,
103 int output_sample_rate_hz,
104 int reverse_sample_rate_hz,
105 webrtc::AudioProcessing::ChannelLayout input_layout,
106 webrtc::AudioProcessing::ChannelLayout output_layout,
107 webrtc::AudioProcessing::ChannelLayout reverse_layout));
108
109 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
110 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
111 }
112
113 WEBRTC_STUB(set_sample_rate_hz, (int rate));
114 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
115 WEBRTC_STUB_CONST(sample_rate_hz, ());
116 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
117 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
118 WEBRTC_STUB_CONST(num_input_channels, ());
119 WEBRTC_STUB_CONST(num_output_channels, ());
120 WEBRTC_STUB_CONST(num_reverse_channels, ());
121 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
122 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
123 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
124 WEBRTC_STUB(ProcessStream, (
125 const float* const* src,
126 int samples_per_channel,
127 int input_sample_rate_hz,
128 webrtc::AudioProcessing::ChannelLayout input_layout,
129 int output_sample_rate_hz,
130 webrtc::AudioProcessing::ChannelLayout output_layout,
131 float* const* dest));
132 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
133 WEBRTC_STUB(AnalyzeReverseStream, (
134 const float* const* data,
135 int samples_per_channel,
136 int sample_rate_hz,
137 webrtc::AudioProcessing::ChannelLayout layout));
138 WEBRTC_STUB(set_stream_delay_ms, (int delay));
139 WEBRTC_STUB_CONST(stream_delay_ms, ());
140 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
141 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
142 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
143 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
144 WEBRTC_STUB_CONST(delay_offset_ms, ());
145 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
146 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
147 WEBRTC_STUB(StopDebugRecording, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000148 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
149 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000150 return NULL;
151 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000152 webrtc::GainControl* gain_control() const override { return NULL; }
153 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
154 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
155 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
156 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000157
158 bool experimental_ns_enabled() {
159 return experimental_ns_enabled_;
160 }
161
162 private:
163 bool experimental_ns_enabled_;
164};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000165
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166class FakeWebRtcVoiceEngine
167 : public webrtc::VoEAudioProcessing,
168 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
169 public webrtc::VoEFile, public webrtc::VoEHardware,
170 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
171 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
172 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
173 public:
174 struct DtmfInfo {
175 DtmfInfo()
176 : dtmf_event_code(-1),
177 dtmf_out_of_band(false),
178 dtmf_length_ms(-1) {}
179 int dtmf_event_code;
180 bool dtmf_out_of_band;
181 int dtmf_length_ms;
182 };
183 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000184 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 : external_transport(false),
186 send(false),
187 playout(false),
188 volume_scale(1.0),
189 volume_pan_left(1.0),
190 volume_pan_right(1.0),
191 file(false),
192 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000193 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000194 max_encoding_bandwidth(0),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000195 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 nack(false),
197 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000198 rx_agc_enabled(false),
199 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 cn8_type(13),
201 cn16_type(105),
202 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000203 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 nack_max_packets(0),
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000205 vie_network(NULL),
206 video_channel(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000208 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000209 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000210 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000211 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000213 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 }
215 bool external_transport;
216 bool send;
217 bool playout;
218 float volume_scale;
219 float volume_pan_left;
220 float volume_pan_right;
221 bool file;
222 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000223 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000224 int max_encoding_bandwidth;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000225 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 bool nack;
227 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000228 bool rx_agc_enabled;
229 webrtc::AgcModes rx_agc_mode;
230 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 int cn8_type;
232 int cn16_type;
233 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000234 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 int nack_max_packets;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000236 webrtc::ViENetwork* vie_network;
237 int video_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000239 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000240 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000241 int send_absolute_sender_time_ext_;
242 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 DtmfInfo dtmf_info;
244 std::vector<webrtc::CodecInst> recv_codecs;
245 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000246 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 std::list<std::string> packets;
248 };
249
250 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
251 int num_codecs)
252 : inited_(false),
253 last_channel_(-1),
254 fail_create_channel_(false),
255 codecs_(codecs),
256 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000257 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 ec_enabled_(false),
259 ec_metrics_enabled_(false),
260 cng_enabled_(false),
261 ns_enabled_(false),
262 agc_enabled_(false),
263 highpass_filter_enabled_(false),
264 stereo_swapping_enabled_(false),
265 typing_detection_enabled_(false),
266 ec_mode_(webrtc::kEcDefault),
267 aecm_mode_(webrtc::kAecmSpeakerphone),
268 ns_mode_(webrtc::kNsDefault),
269 agc_mode_(webrtc::kAgcDefault),
270 observer_(NULL),
271 playout_fail_channel_(-1),
272 send_fail_channel_(-1),
273 fail_start_recording_microphone_(false),
274 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000275 recording_sample_rate_(-1),
276 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 media_processor_(NULL) {
278 memset(&agc_config_, 0, sizeof(agc_config_));
279 }
280 ~FakeWebRtcVoiceEngine() {
281 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
282 // destructors, but just in case ...
283 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
284 i != channels_.end(); ++i) {
285 delete i->second;
286 }
287 }
288
289 bool IsExternalMediaProcessorRegistered() const {
290 return media_processor_ != NULL;
291 }
292 bool IsInited() const { return inited_; }
293 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000294 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
295 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
296 iter != channels_.end(); ++iter) {
297 if (local_ssrc == iter->second->send_ssrc)
298 return iter->first;
299 }
300 return -1;
301 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000302 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 bool GetPlayout(int channel) {
304 return channels_[channel]->playout;
305 }
306 bool GetSend(int channel) {
307 return channels_[channel]->send;
308 }
309 bool GetRecordingMicrophone() {
310 return recording_microphone_;
311 }
312 bool GetVAD(int channel) {
313 return channels_[channel]->vad;
314 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000315 bool GetRED(int channel) {
316 return channels_[channel]->red;
317 }
318 bool GetCodecFEC(int channel) {
319 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000321 int GetMaxEncodingBandwidth(int channel) {
322 return channels_[channel]->max_encoding_bandwidth;
323 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 bool GetNACK(int channel) {
325 return channels_[channel]->nack;
326 }
327 int GetNACKMaxPackets(int channel) {
328 return channels_[channel]->nack_max_packets;
329 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000330 webrtc::ViENetwork* GetViENetwork(int channel) {
331 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000332 // WARNING: This pointer is for verification purposes only. Calling
333 // functions on it may result in undefined behavior!
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000334 return channels_[channel]->vie_network;
335 }
336 int GetVideoChannel(int channel) {
337 WEBRTC_ASSERT_CHANNEL(channel);
338 return channels_[channel]->video_channel;
339 }
340 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
341 WEBRTC_ASSERT_CHANNEL(channel);
342 return channels_[channel]->last_rtp_packet_time;
343 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 int GetSendCNPayloadType(int channel, bool wideband) {
345 return (wideband) ?
346 channels_[channel]->cn16_type :
347 channels_[channel]->cn8_type;
348 }
349 int GetSendTelephoneEventPayloadType(int channel) {
350 return channels_[channel]->dtmf_type;
351 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000352 int GetSendREDPayloadType(int channel) {
353 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 }
355 bool CheckPacket(int channel, const void* data, size_t len) {
356 bool result = !CheckNoPacket(channel);
357 if (result) {
358 std::string packet = channels_[channel]->packets.front();
359 result = (packet == std::string(static_cast<const char*>(data), len));
360 channels_[channel]->packets.pop_front();
361 }
362 return result;
363 }
364 bool CheckNoPacket(int channel) {
365 return channels_[channel]->packets.empty();
366 }
367 void TriggerCallbackOnError(int channel_num, int err_code) {
368 ASSERT(observer_ != NULL);
369 observer_->CallbackOnError(channel_num, err_code);
370 }
371 void set_playout_fail_channel(int channel) {
372 playout_fail_channel_ = channel;
373 }
374 void set_send_fail_channel(int channel) {
375 send_fail_channel_ = channel;
376 }
377 void set_fail_start_recording_microphone(
378 bool fail_start_recording_microphone) {
379 fail_start_recording_microphone_ = fail_start_recording_microphone;
380 }
381 void set_fail_create_channel(bool fail_create_channel) {
382 fail_create_channel_ = fail_create_channel;
383 }
384 void TriggerProcessPacket(MediaProcessorDirection direction) {
385 webrtc::ProcessingTypes pt =
386 (direction == cricket::MPD_TX) ?
387 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
388 if (media_processor_ != NULL) {
389 media_processor_->Process(0,
390 pt,
391 NULL,
392 0,
393 0,
394 true);
395 }
396 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000397 int AddChannel() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000398 if (fail_create_channel_) {
399 return -1;
400 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000401 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000402 for (int i = 0; i < NumOfCodecs(); ++i) {
403 webrtc::CodecInst codec;
404 GetCodec(i, codec);
405 ch->recv_codecs.push_back(codec);
406 }
407 channels_[++last_channel_] = ch;
408 return last_channel_;
409 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000410 int GetSendRtpExtensionId(int channel, const std::string& extension) {
411 WEBRTC_ASSERT_CHANNEL(channel);
412 if (extension == kRtpAudioLevelHeaderExtension) {
413 return channels_[channel]->send_audio_level_ext_;
414 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
415 return channels_[channel]->send_absolute_sender_time_ext_;
416 }
417 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000418 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000419 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
420 WEBRTC_ASSERT_CHANNEL(channel);
421 if (extension == kRtpAudioLevelHeaderExtension) {
422 return channels_[channel]->receive_audio_level_ext_;
423 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
424 return channels_[channel]->receive_absolute_sender_time_ext_;
425 }
426 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000427 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000429 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
430
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 WEBRTC_STUB(Release, ());
432
433 // webrtc::VoEBase
434 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
435 webrtc::VoiceEngineObserver& observer)) {
436 observer_ = &observer;
437 return 0;
438 }
439 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
440 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
441 webrtc::AudioProcessing* audioproc)) {
442 inited_ = true;
443 return 0;
444 }
445 WEBRTC_FUNC(Terminate, ()) {
446 inited_ = false;
447 return 0;
448 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000449 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000450 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000453 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000455 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
456 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000457 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 WEBRTC_FUNC(DeleteChannel, (int channel)) {
459 WEBRTC_CHECK_CHANNEL(channel);
460 delete channels_[channel];
461 channels_.erase(channel);
462 return 0;
463 }
464 WEBRTC_STUB(StartReceive, (int channel));
465 WEBRTC_FUNC(StartPlayout, (int channel)) {
466 if (playout_fail_channel_ != channel) {
467 WEBRTC_CHECK_CHANNEL(channel);
468 channels_[channel]->playout = true;
469 return 0;
470 } else {
471 // When playout_fail_channel_ == channel, fail the StartPlayout on this
472 // channel.
473 return -1;
474 }
475 }
476 WEBRTC_FUNC(StartSend, (int channel)) {
477 if (send_fail_channel_ != channel) {
478 WEBRTC_CHECK_CHANNEL(channel);
479 channels_[channel]->send = true;
480 return 0;
481 } else {
482 // When send_fail_channel_ == channel, fail the StartSend on this
483 // channel.
484 return -1;
485 }
486 }
487 WEBRTC_STUB(StopReceive, (int channel));
488 WEBRTC_FUNC(StopPlayout, (int channel)) {
489 WEBRTC_CHECK_CHANNEL(channel);
490 channels_[channel]->playout = false;
491 return 0;
492 }
493 WEBRTC_FUNC(StopSend, (int channel)) {
494 WEBRTC_CHECK_CHANNEL(channel);
495 channels_[channel]->send = false;
496 return 0;
497 }
498 WEBRTC_STUB(GetVersion, (char version[1024]));
499 WEBRTC_STUB(LastError, ());
500 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
501 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502
503 // webrtc::VoECodec
504 WEBRTC_FUNC(NumOfCodecs, ()) {
505 return num_codecs_;
506 }
507 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
508 if (index < 0 || index >= NumOfCodecs()) {
509 return -1;
510 }
511 const cricket::AudioCodec& c(*codecs_[index]);
512 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000513 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 codec.plfreq = c.clockrate;
515 codec.pacsize = 0;
516 codec.channels = c.channels;
517 codec.rate = c.bitrate;
518 return 0;
519 }
520 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
521 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000522 // To match the behavior of the real implementation.
523 if (_stricmp(codec.plname, "telephone-event") == 0 ||
524 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
525 _stricmp(codec.plname, "CN") == 0 ||
526 _stricmp(codec.plname, "red") == 0 ) {
527 return -1;
528 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000530 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531 return 0;
532 }
533 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
534 WEBRTC_CHECK_CHANNEL(channel);
535 codec = channels_[channel]->send_codec;
536 return 0;
537 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000538 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
539 WEBRTC_CHECK_CHANNEL(channel);
540 const Channel* c = channels_[channel];
541 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
542 it_packet != c->packets.end(); ++it_packet) {
543 int pltype;
544 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
545 continue;
546 }
547 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
548 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
549 ++it_codec) {
550 if (it_codec->pltype == pltype) {
551 codec = *it_codec;
552 return 0;
553 }
554 }
555 }
556 return -1;
557 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
559 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
560 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
561 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
562 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
563 bool useFixedFrameSize));
564 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
565 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
566 WEBRTC_FUNC(SetRecPayloadType, (int channel,
567 const webrtc::CodecInst& codec)) {
568 WEBRTC_CHECK_CHANNEL(channel);
569 Channel* ch = channels_[channel];
570 if (ch->playout)
571 return -1; // Channel is in use.
572 // Check if something else already has this slot.
573 if (codec.pltype != -1) {
574 for (std::vector<webrtc::CodecInst>::iterator it =
575 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
576 if (it->pltype == codec.pltype &&
577 _stricmp(it->plname, codec.plname) != 0) {
578 return -1;
579 }
580 }
581 }
582 // Otherwise try to find this codec and update its payload type.
583 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
584 it != ch->recv_codecs.end(); ++it) {
585 if (strcmp(it->plname, codec.plname) == 0 &&
586 it->plfreq == codec.plfreq) {
587 it->pltype = codec.pltype;
588 it->channels = codec.channels;
589 return 0;
590 }
591 }
592 return -1; // not found
593 }
594 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
595 webrtc::PayloadFrequencies frequency)) {
596 WEBRTC_CHECK_CHANNEL(channel);
597 if (frequency == webrtc::kFreq8000Hz) {
598 channels_[channel]->cn8_type = type;
599 } else if (frequency == webrtc::kFreq16000Hz) {
600 channels_[channel]->cn16_type = type;
601 }
602 return 0;
603 }
604 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
605 WEBRTC_CHECK_CHANNEL(channel);
606 Channel* ch = channels_[channel];
607 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
608 it != ch->recv_codecs.end(); ++it) {
609 if (strcmp(it->plname, codec.plname) == 0 &&
610 it->plfreq == codec.plfreq &&
611 it->channels == codec.channels &&
612 it->pltype != -1) {
613 codec.pltype = it->pltype;
614 return 0;
615 }
616 }
617 return -1; // not found
618 }
619 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
620 bool disableDTX)) {
621 WEBRTC_CHECK_CHANNEL(channel);
622 if (channels_[channel]->send_codec.channels == 2) {
623 // Replicating VoE behavior; VAD cannot be enabled for stereo.
624 return -1;
625 }
626 channels_[channel]->vad = enable;
627 return 0;
628 }
629 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
630 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000631
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000632 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 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666
667 // webrtc::VoEDtmf
668 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
669 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
670 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
671 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
672 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
673 return 0;
674 }
675
676 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
677 (int channel, unsigned char type)) {
678 channels_[channel]->dtmf_type = type;
679 return 0;
680 };
681 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
682 (int channel, unsigned char& type));
683
684 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
685 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 WEBRTC_FUNC(PlayDtmfTone,
688 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
689 dtmf_info_.dtmf_event_code = event_code;
690 dtmf_info_.dtmf_length_ms = length_ms;
691 return 0;
692 }
693 WEBRTC_STUB(StartPlayingDtmfTone,
694 (int eventCode, int attenuationDb = 10));
695 WEBRTC_STUB(StopPlayingDtmfTone, ());
696
697 // webrtc::VoEFile
698 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
699 bool loop, webrtc::FileFormats format,
700 float volumeScaling, int startPointMs,
701 int stopPointMs)) {
702 WEBRTC_CHECK_CHANNEL(channel);
703 channels_[channel]->file = true;
704 return 0;
705 }
706 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
707 webrtc::FileFormats format,
708 float volumeScaling, int startPointMs,
709 int stopPointMs)) {
710 WEBRTC_CHECK_CHANNEL(channel);
711 channels_[channel]->file = true;
712 return 0;
713 }
714 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
715 WEBRTC_CHECK_CHANNEL(channel);
716 channels_[channel]->file = false;
717 return 0;
718 }
719 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
720 WEBRTC_CHECK_CHANNEL(channel);
721 return (channels_[channel]->file) ? 1 : 0;
722 }
723 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
724 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
725 const char* fileNameUTF8,
726 bool loop,
727 bool mixWithMicrophone,
728 webrtc::FileFormats format,
729 float volumeScaling));
730 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
731 webrtc::InStream* stream,
732 bool mixWithMicrophone,
733 webrtc::FileFormats format,
734 float volumeScaling));
735 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
736 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
737 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
738 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
739 webrtc::CodecInst* compression,
740 int maxSizeBytes));
741 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
742 webrtc::CodecInst* compression));
743 WEBRTC_STUB(StopRecordingPlayout, (int channel));
744 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
745 webrtc::CodecInst* compression,
746 int maxSizeBytes)) {
747 if (fail_start_recording_microphone_) {
748 return -1;
749 }
750 recording_microphone_ = true;
751 return 0;
752 }
753 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
754 webrtc::CodecInst* compression)) {
755 if (fail_start_recording_microphone_) {
756 return -1;
757 }
758 recording_microphone_ = true;
759 return 0;
760 }
761 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
762 if (!recording_microphone_) {
763 return -1;
764 }
765 recording_microphone_ = false;
766 return 0;
767 }
768 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
769 const char* fileNameOutUTF8));
770 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
771 webrtc::OutStream* streamOut));
772 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
773 const char* fileNameOutUTF8));
774 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
775 webrtc::OutStream* streamOut));
776 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
777 const char* fileNameOutUTF8,
778 webrtc::CodecInst* compression));
779 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
780 webrtc::OutStream* streamOut,
781 webrtc::CodecInst* compression));
782 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
783 const char* fileNameOutUTF8));
784 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
785 webrtc::OutStream* streamOut));
786 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
787 webrtc::FileFormats format));
788 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
789
790 // webrtc::VoEHardware
791 WEBRTC_STUB(GetCPULoad, (int&));
792 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
793 return GetNumDevices(num);
794 }
795 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
796 return GetNumDevices(num);
797 }
798 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
799 return GetDeviceName(i, name, guid);
800 }
801 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
802 return GetDeviceName(i, name, guid);
803 }
804 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
805 WEBRTC_STUB(SetPlayoutDevice, (int));
806 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
807 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
808 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
809 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
810 WEBRTC_STUB(ResetAudioDevice, ());
811 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
812 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
813 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000814 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
815 recording_sample_rate_ = samples_per_sec;
816 return 0;
817 }
818 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
819 *samples_per_sec = recording_sample_rate_;
820 return 0;
821 }
822 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
823 playout_sample_rate_ = samples_per_sec;
824 return 0;
825 }
826 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
827 *samples_per_sec = playout_sample_rate_;
828 return 0;
829 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
831 virtual bool BuiltInAECIsEnabled() const { return true; }
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000832 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833
834 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000835 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
836 webrtc::NetworkStatistics& ns)) {
837 WEBRTC_CHECK_CHANNEL(channel);
838 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
839 return 0;
840 }
841
wu@webrtc.org24301a62013-12-13 19:17:43 +0000842 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
843 webrtc::AudioDecodingCallStats*)) {
844 WEBRTC_CHECK_CHANNEL(channel);
845 return 0;
846 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847
848 // webrtc::VoENetwork
849 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
850 webrtc::Transport& transport)) {
851 WEBRTC_CHECK_CHANNEL(channel);
852 channels_[channel]->external_transport = true;
853 return 0;
854 }
855 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
856 WEBRTC_CHECK_CHANNEL(channel);
857 channels_[channel]->external_transport = false;
858 return 0;
859 }
860 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000861 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 WEBRTC_CHECK_CHANNEL(channel);
863 if (!channels_[channel]->external_transport) return -1;
864 channels_[channel]->packets.push_back(
865 std::string(static_cast<const char*>(data), length));
866 return 0;
867 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000868 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000869 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000870 const webrtc::PacketTime& packet_time)) {
871 WEBRTC_CHECK_CHANNEL(channel);
872 if (ReceivedRTPPacket(channel, data, length) == -1) {
873 return -1;
874 }
875 channels_[channel]->last_rtp_packet_time = packet_time;
876 return 0;
877 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000878
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000880 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881
882 // webrtc::VoERTP_RTCP
883 WEBRTC_STUB(RegisterRTPObserver, (int channel,
884 webrtc::VoERTPObserver& observer));
885 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
887 WEBRTC_CHECK_CHANNEL(channel);
888 channels_[channel]->send_ssrc = ssrc;
889 return 0;
890 }
891 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
892 WEBRTC_CHECK_CHANNEL(channel);
893 ssrc = channels_[channel]->send_ssrc;
894 return 0;
895 }
896 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000897 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
898 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000900 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
901 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 return 0;
903 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000904 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
905 unsigned char id)) {
906 WEBRTC_CHECK_CHANNEL(channel);
907 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
908 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
909 return 0;
910 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000911 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
912 unsigned char id)) {
913 WEBRTC_CHECK_CHANNEL(channel);
914 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
915 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
916 return 0;
917 }
918 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
919 unsigned char id)) {
920 WEBRTC_CHECK_CHANNEL(channel);
921 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
922 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
923 return 0;
924 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000925
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
927 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
928 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
929 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
930 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
931 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
932 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
933 unsigned int& NTPLow,
934 unsigned int& timestamp,
935 unsigned int& playoutTimestamp,
936 unsigned int* jitter,
937 unsigned short* fractionLost));
938 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
939 webrtc::SenderInfo* sender_info));
940 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
941 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
942 WEBRTC_CHECK_CHANNEL(channel);
943 webrtc::ReportBlock block;
944 block.source_SSRC = channels_[channel]->send_ssrc;
945 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
946 if (send_codec.pltype >= 0) {
947 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
948 if (send_codec.plfreq / 1000 > 0) {
949 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
950 }
951 block.cumulative_num_packets_lost = kIntStatValue;
952 block.extended_highest_sequence_number = kIntStatValue;
953 receive_blocks->push_back(block);
954 }
955 return 0;
956 }
957 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
958 unsigned char subType,
959 unsigned int name,
960 const char* data,
961 unsigned short dataLength));
962 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
963 unsigned int& maxJitterMs,
964 unsigned int& discardedPackets));
965 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
966 WEBRTC_CHECK_CHANNEL(channel);
967 stats.fractionLost = static_cast<int16>(kIntStatValue);
968 stats.cumulativeLost = kIntStatValue;
969 stats.extendedMax = kIntStatValue;
970 stats.jitterSamples = kIntStatValue;
971 stats.rttMs = kIntStatValue;
972 stats.bytesSent = kIntStatValue;
973 stats.packetsSent = kIntStatValue;
974 stats.bytesReceived = kIntStatValue;
975 stats.packetsReceived = kIntStatValue;
976 return 0;
977 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000978 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000979 return SetFECStatus(channel, enable, redPayloadtype);
980 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000981 // TODO(minyue): remove the below function when transition to SetREDStatus
982 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
984 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000985 channels_[channel]->red = enable;
986 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 return 0;
988 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000989 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000990 return GetFECStatus(channel, enable, redPayloadtype);
991 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000992 // TODO(minyue): remove the below function when transition to GetREDStatus
993 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
995 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000996 enable = channels_[channel]->red;
997 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 return 0;
999 }
1000 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
1001 WEBRTC_CHECK_CHANNEL(channel);
1002 channels_[channel]->nack = enable;
1003 channels_[channel]->nack_max_packets = maxNoPackets;
1004 return 0;
1005 }
1006 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
1007 webrtc::RTPDirections direction));
1008 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
1009 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
1010 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
1011 bool markerBit, const char* payloadData,
1012 unsigned short payloadSize));
1013 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
1014 uint32_t* lastRemoteTimeStamp));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001015 WEBRTC_FUNC(SetVideoEngineBWETarget, (int channel,
1016 webrtc::ViENetwork* vie_network,
1017 int video_channel)) {
1018 WEBRTC_CHECK_CHANNEL(channel);
1019 channels_[channel]->vie_network = vie_network;
1020 channels_[channel]->video_channel = video_channel;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001021 if (vie_network) {
1022 // The interface is released here to avoid leaks. A test should not
1023 // attempt to call functions on the interface stored in the channel.
1024 vie_network->Release();
1025 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001026 return 0;
1027 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028
1029 // webrtc::VoEVideoSync
1030 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1031 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001032 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1034 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1035 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1036 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1037 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1038 int* playout_buffer_delay_ms));
1039 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1040
1041 // webrtc::VoEVolumeControl
1042 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1043 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1044 WEBRTC_STUB(SetSystemOutputMute, (bool));
1045 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1046 WEBRTC_STUB(SetMicVolume, (unsigned int));
1047 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1048 WEBRTC_STUB(SetInputMute, (int, bool));
1049 WEBRTC_STUB(GetInputMute, (int, bool&));
1050 WEBRTC_STUB(SetSystemInputMute, (bool));
1051 WEBRTC_STUB(GetSystemInputMute, (bool&));
1052 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1053 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1054 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1055 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1056 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1057 WEBRTC_CHECK_CHANNEL(channel);
1058 channels_[channel]->volume_scale= scale;
1059 return 0;
1060 }
1061 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1062 WEBRTC_CHECK_CHANNEL(channel);
1063 scale = channels_[channel]->volume_scale;
1064 return 0;
1065 }
1066 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1067 WEBRTC_CHECK_CHANNEL(channel);
1068 channels_[channel]->volume_pan_left = left;
1069 channels_[channel]->volume_pan_right = right;
1070 return 0;
1071 }
1072 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1073 WEBRTC_CHECK_CHANNEL(channel);
1074 left = channels_[channel]->volume_pan_left;
1075 right = channels_[channel]->volume_pan_right;
1076 return 0;
1077 }
1078
1079 // webrtc::VoEAudioProcessing
1080 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1081 ns_enabled_ = enable;
1082 ns_mode_ = mode;
1083 return 0;
1084 }
1085 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1086 enabled = ns_enabled_;
1087 mode = ns_mode_;
1088 return 0;
1089 }
1090
1091 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1092 agc_enabled_ = enable;
1093 agc_mode_ = mode;
1094 return 0;
1095 }
1096 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1097 enabled = agc_enabled_;
1098 mode = agc_mode_;
1099 return 0;
1100 }
1101
1102 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1103 agc_config_ = config;
1104 return 0;
1105 }
1106 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1107 config = agc_config_;
1108 return 0;
1109 }
1110 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1111 ec_enabled_ = enable;
1112 ec_mode_ = mode;
1113 return 0;
1114 }
1115 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1116 enabled = ec_enabled_;
1117 mode = ec_mode_;
1118 return 0;
1119 }
1120 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1121 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1122 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1123 WEBRTC_STUB(DelayOffsetMs, ());
1124 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1125 aecm_mode_ = mode;
1126 cng_enabled_ = enableCNG;
1127 return 0;
1128 }
1129 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1130 mode = aecm_mode_;
1131 enabledCNG = cng_enabled_;
1132 return 0;
1133 }
1134 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1135 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1136 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001137 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1138 webrtc::AgcModes mode)) {
1139 channels_[channel]->rx_agc_enabled = enable;
1140 channels_[channel]->rx_agc_mode = mode;
1141 return 0;
1142 }
1143 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1144 webrtc::AgcModes& mode)) {
1145 enabled = channels_[channel]->rx_agc_enabled;
1146 mode = channels_[channel]->rx_agc_mode;
1147 return 0;
1148 }
1149
1150 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1151 channels_[channel]->rx_agc_config = config;
1152 return 0;
1153 }
1154 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1155 config = channels_[channel]->rx_agc_config;
1156 return 0;
1157 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158
1159 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1160 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1161 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1162 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1163 ec_metrics_enabled_ = enable;
1164 return 0;
1165 }
1166 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1167 enabled = ec_metrics_enabled_;
1168 return 0;
1169 }
1170 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001171 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1172 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173
1174 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001175 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176 WEBRTC_STUB(StopDebugRecording, ());
1177
1178 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1179 typing_detection_enabled_ = enable;
1180 return 0;
1181 }
1182 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1183 enabled = typing_detection_enabled_;
1184 return 0;
1185 }
1186
1187 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1188 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1189 int costPerTyping,
1190 int reportingThreshold,
1191 int penaltyDecay,
1192 int typeEventDelay));
1193 int EnableHighPassFilter(bool enable) {
1194 highpass_filter_enabled_ = enable;
1195 return 0;
1196 }
1197 bool IsHighPassFilterEnabled() {
1198 return highpass_filter_enabled_;
1199 }
1200 bool IsStereoChannelSwappingEnabled() {
1201 return stereo_swapping_enabled_;
1202 }
1203 void EnableStereoChannelSwapping(bool enable) {
1204 stereo_swapping_enabled_ = enable;
1205 }
1206 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1207 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1208 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1209 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1210 }
1211 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1212 return (dtmf_info_.dtmf_event_code == event_code &&
1213 dtmf_info_.dtmf_length_ms == length_ms);
1214 }
1215 // webrtc::VoEExternalMedia
1216 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1217 (int channel, webrtc::ProcessingTypes type,
1218 webrtc::VoEMediaProcess& processObject)) {
1219 WEBRTC_CHECK_CHANNEL(channel);
1220 if (channels_[channel]->media_processor_registered) {
1221 return -1;
1222 }
1223 channels_[channel]->media_processor_registered = true;
1224 media_processor_ = &processObject;
1225 return 0;
1226 }
1227 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1228 (int channel, webrtc::ProcessingTypes type)) {
1229 WEBRTC_CHECK_CHANNEL(channel);
1230 if (!channels_[channel]->media_processor_registered) {
1231 return -1;
1232 }
1233 channels_[channel]->media_processor_registered = false;
1234 media_processor_ = NULL;
1235 return 0;
1236 }
1237 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1238 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1239 WEBRTC_STUB(ExternalRecordingInsertData,
1240 (const int16_t speechData10ms[], int lengthSamples,
1241 int samplingFreqHz, int current_delay_ms));
1242 WEBRTC_STUB(ExternalPlayoutGetData,
1243 (int16_t speechData10ms[], int samplingFreqHz,
1244 int current_delay_ms, int& lengthSamples));
1245 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1246 webrtc::AudioFrame* frame));
1247 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1248
1249 private:
1250 int GetNumDevices(int& num) {
1251#ifdef WIN32
1252 num = 1;
1253#else
1254 // On non-Windows platforms VE adds a special entry for the default device,
1255 // so if there is one physical device then there are two entries in the
1256 // list.
1257 num = 2;
1258#endif
1259 return 0;
1260 }
1261
1262 int GetDeviceName(int i, char* name, char* guid) {
1263 const char *s;
1264#ifdef WIN32
1265 if (0 == i) {
1266 s = kFakeDeviceName;
1267 } else {
1268 return -1;
1269 }
1270#else
1271 // See comment above.
1272 if (0 == i) {
1273 s = kFakeDefaultDeviceName;
1274 } else if (1 == i) {
1275 s = kFakeDeviceName;
1276 } else {
1277 return -1;
1278 }
1279#endif
1280 strcpy(name, s);
1281 guid[0] = '\0';
1282 return 0;
1283 }
1284
1285 bool inited_;
1286 int last_channel_;
1287 std::map<int, Channel*> channels_;
1288 bool fail_create_channel_;
1289 const cricket::AudioCodec* const* codecs_;
1290 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001291 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 bool ec_enabled_;
1293 bool ec_metrics_enabled_;
1294 bool cng_enabled_;
1295 bool ns_enabled_;
1296 bool agc_enabled_;
1297 bool highpass_filter_enabled_;
1298 bool stereo_swapping_enabled_;
1299 bool typing_detection_enabled_;
1300 webrtc::EcModes ec_mode_;
1301 webrtc::AecmModes aecm_mode_;
1302 webrtc::NsModes ns_mode_;
1303 webrtc::AgcModes agc_mode_;
1304 webrtc::AgcConfig agc_config_;
1305 webrtc::VoiceEngineObserver* observer_;
1306 int playout_fail_channel_;
1307 int send_fail_channel_;
1308 bool fail_start_recording_microphone_;
1309 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001310 int recording_sample_rate_;
1311 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 DtmfInfo dtmf_info_;
1313 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001314 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315};
1316
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001317#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1318
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319} // namespace cricket
1320
1321#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_