blob: 65807fc367caa14ffeb518f7e20c26a0c564df4b [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, ());
148 virtual webrtc::EchoCancellation* echo_cancellation() const OVERRIDE {
149 return NULL;
150 }
151 virtual webrtc::EchoControlMobile* echo_control_mobile() const OVERRIDE {
152 return NULL;
153 }
154 virtual webrtc::GainControl* gain_control() const OVERRIDE { return NULL; }
155 virtual webrtc::HighPassFilter* high_pass_filter() const OVERRIDE {
156 return NULL;
157 }
158 virtual webrtc::LevelEstimator* level_estimator() const OVERRIDE {
159 return NULL;
160 }
161 virtual webrtc::NoiseSuppression* noise_suppression() const OVERRIDE {
162 return NULL;
163 }
164 virtual webrtc::VoiceDetection* voice_detection() const OVERRIDE {
165 return NULL;
166 }
167
168 bool experimental_ns_enabled() {
169 return experimental_ns_enabled_;
170 }
171
172 private:
173 bool experimental_ns_enabled_;
174};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000175
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176class FakeWebRtcVoiceEngine
177 : public webrtc::VoEAudioProcessing,
178 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
179 public webrtc::VoEFile, public webrtc::VoEHardware,
180 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
181 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
182 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
183 public:
184 struct DtmfInfo {
185 DtmfInfo()
186 : dtmf_event_code(-1),
187 dtmf_out_of_band(false),
188 dtmf_length_ms(-1) {}
189 int dtmf_event_code;
190 bool dtmf_out_of_band;
191 int dtmf_length_ms;
192 };
193 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000194 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 : external_transport(false),
196 send(false),
197 playout(false),
198 volume_scale(1.0),
199 volume_pan_left(1.0),
200 volume_pan_right(1.0),
201 file(false),
202 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000203 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000204 max_encoding_bandwidth(0),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000205 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 nack(false),
207 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000208 rx_agc_enabled(false),
209 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 cn8_type(13),
211 cn16_type(105),
212 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000213 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 nack_max_packets(0),
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000215 vie_network(NULL),
216 video_channel(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000218 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000219 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000220 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000221 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000223 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 }
225 bool external_transport;
226 bool send;
227 bool playout;
228 float volume_scale;
229 float volume_pan_left;
230 float volume_pan_right;
231 bool file;
232 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000233 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000234 int max_encoding_bandwidth;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000235 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 bool nack;
237 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000238 bool rx_agc_enabled;
239 webrtc::AgcModes rx_agc_mode;
240 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 int cn8_type;
242 int cn16_type;
243 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000244 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 int nack_max_packets;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000246 webrtc::ViENetwork* vie_network;
247 int video_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000249 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000250 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000251 int send_absolute_sender_time_ext_;
252 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 DtmfInfo dtmf_info;
254 std::vector<webrtc::CodecInst> recv_codecs;
255 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000256 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 std::list<std::string> packets;
258 };
259
260 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
261 int num_codecs)
262 : inited_(false),
263 last_channel_(-1),
264 fail_create_channel_(false),
265 codecs_(codecs),
266 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000267 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 ec_enabled_(false),
269 ec_metrics_enabled_(false),
270 cng_enabled_(false),
271 ns_enabled_(false),
272 agc_enabled_(false),
273 highpass_filter_enabled_(false),
274 stereo_swapping_enabled_(false),
275 typing_detection_enabled_(false),
276 ec_mode_(webrtc::kEcDefault),
277 aecm_mode_(webrtc::kAecmSpeakerphone),
278 ns_mode_(webrtc::kNsDefault),
279 agc_mode_(webrtc::kAgcDefault),
280 observer_(NULL),
281 playout_fail_channel_(-1),
282 send_fail_channel_(-1),
283 fail_start_recording_microphone_(false),
284 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000285 recording_sample_rate_(-1),
286 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287 media_processor_(NULL) {
288 memset(&agc_config_, 0, sizeof(agc_config_));
289 }
290 ~FakeWebRtcVoiceEngine() {
291 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
292 // destructors, but just in case ...
293 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
294 i != channels_.end(); ++i) {
295 delete i->second;
296 }
297 }
298
299 bool IsExternalMediaProcessorRegistered() const {
300 return media_processor_ != NULL;
301 }
302 bool IsInited() const { return inited_; }
303 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000304 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
305 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
306 iter != channels_.end(); ++iter) {
307 if (local_ssrc == iter->second->send_ssrc)
308 return iter->first;
309 }
310 return -1;
311 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000312 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 bool GetPlayout(int channel) {
314 return channels_[channel]->playout;
315 }
316 bool GetSend(int channel) {
317 return channels_[channel]->send;
318 }
319 bool GetRecordingMicrophone() {
320 return recording_microphone_;
321 }
322 bool GetVAD(int channel) {
323 return channels_[channel]->vad;
324 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000325 bool GetRED(int channel) {
326 return channels_[channel]->red;
327 }
328 bool GetCodecFEC(int channel) {
329 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000331 int GetMaxEncodingBandwidth(int channel) {
332 return channels_[channel]->max_encoding_bandwidth;
333 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 bool GetNACK(int channel) {
335 return channels_[channel]->nack;
336 }
337 int GetNACKMaxPackets(int channel) {
338 return channels_[channel]->nack_max_packets;
339 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000340 webrtc::ViENetwork* GetViENetwork(int channel) {
341 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000342 // WARNING: This pointer is for verification purposes only. Calling
343 // functions on it may result in undefined behavior!
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000344 return channels_[channel]->vie_network;
345 }
346 int GetVideoChannel(int channel) {
347 WEBRTC_ASSERT_CHANNEL(channel);
348 return channels_[channel]->video_channel;
349 }
350 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
351 WEBRTC_ASSERT_CHANNEL(channel);
352 return channels_[channel]->last_rtp_packet_time;
353 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 int GetSendCNPayloadType(int channel, bool wideband) {
355 return (wideband) ?
356 channels_[channel]->cn16_type :
357 channels_[channel]->cn8_type;
358 }
359 int GetSendTelephoneEventPayloadType(int channel) {
360 return channels_[channel]->dtmf_type;
361 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000362 int GetSendREDPayloadType(int channel) {
363 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 }
365 bool CheckPacket(int channel, const void* data, size_t len) {
366 bool result = !CheckNoPacket(channel);
367 if (result) {
368 std::string packet = channels_[channel]->packets.front();
369 result = (packet == std::string(static_cast<const char*>(data), len));
370 channels_[channel]->packets.pop_front();
371 }
372 return result;
373 }
374 bool CheckNoPacket(int channel) {
375 return channels_[channel]->packets.empty();
376 }
377 void TriggerCallbackOnError(int channel_num, int err_code) {
378 ASSERT(observer_ != NULL);
379 observer_->CallbackOnError(channel_num, err_code);
380 }
381 void set_playout_fail_channel(int channel) {
382 playout_fail_channel_ = channel;
383 }
384 void set_send_fail_channel(int channel) {
385 send_fail_channel_ = channel;
386 }
387 void set_fail_start_recording_microphone(
388 bool fail_start_recording_microphone) {
389 fail_start_recording_microphone_ = fail_start_recording_microphone;
390 }
391 void set_fail_create_channel(bool fail_create_channel) {
392 fail_create_channel_ = fail_create_channel;
393 }
394 void TriggerProcessPacket(MediaProcessorDirection direction) {
395 webrtc::ProcessingTypes pt =
396 (direction == cricket::MPD_TX) ?
397 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
398 if (media_processor_ != NULL) {
399 media_processor_->Process(0,
400 pt,
401 NULL,
402 0,
403 0,
404 true);
405 }
406 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000407 int AddChannel() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000408 if (fail_create_channel_) {
409 return -1;
410 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000411 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000412 for (int i = 0; i < NumOfCodecs(); ++i) {
413 webrtc::CodecInst codec;
414 GetCodec(i, codec);
415 ch->recv_codecs.push_back(codec);
416 }
417 channels_[++last_channel_] = ch;
418 return last_channel_;
419 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000420 int GetSendRtpExtensionId(int channel, const std::string& extension) {
421 WEBRTC_ASSERT_CHANNEL(channel);
422 if (extension == kRtpAudioLevelHeaderExtension) {
423 return channels_[channel]->send_audio_level_ext_;
424 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
425 return channels_[channel]->send_absolute_sender_time_ext_;
426 }
427 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000428 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000429 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
430 WEBRTC_ASSERT_CHANNEL(channel);
431 if (extension == kRtpAudioLevelHeaderExtension) {
432 return channels_[channel]->receive_audio_level_ext_;
433 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
434 return channels_[channel]->receive_absolute_sender_time_ext_;
435 }
436 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000437 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000439 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
440
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 WEBRTC_STUB(Release, ());
442
443 // webrtc::VoEBase
444 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
445 webrtc::VoiceEngineObserver& observer)) {
446 observer_ = &observer;
447 return 0;
448 }
449 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
450 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
451 webrtc::AudioProcessing* audioproc)) {
452 inited_ = true;
453 return 0;
454 }
455 WEBRTC_FUNC(Terminate, ()) {
456 inited_ = false;
457 return 0;
458 }
459 virtual webrtc::AudioProcessing* audio_processing() OVERRIDE {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000460 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000463 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000465 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
466 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000467 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 WEBRTC_FUNC(DeleteChannel, (int channel)) {
469 WEBRTC_CHECK_CHANNEL(channel);
470 delete channels_[channel];
471 channels_.erase(channel);
472 return 0;
473 }
474 WEBRTC_STUB(StartReceive, (int channel));
475 WEBRTC_FUNC(StartPlayout, (int channel)) {
476 if (playout_fail_channel_ != channel) {
477 WEBRTC_CHECK_CHANNEL(channel);
478 channels_[channel]->playout = true;
479 return 0;
480 } else {
481 // When playout_fail_channel_ == channel, fail the StartPlayout on this
482 // channel.
483 return -1;
484 }
485 }
486 WEBRTC_FUNC(StartSend, (int channel)) {
487 if (send_fail_channel_ != channel) {
488 WEBRTC_CHECK_CHANNEL(channel);
489 channels_[channel]->send = true;
490 return 0;
491 } else {
492 // When send_fail_channel_ == channel, fail the StartSend on this
493 // channel.
494 return -1;
495 }
496 }
497 WEBRTC_STUB(StopReceive, (int channel));
498 WEBRTC_FUNC(StopPlayout, (int channel)) {
499 WEBRTC_CHECK_CHANNEL(channel);
500 channels_[channel]->playout = false;
501 return 0;
502 }
503 WEBRTC_FUNC(StopSend, (int channel)) {
504 WEBRTC_CHECK_CHANNEL(channel);
505 channels_[channel]->send = false;
506 return 0;
507 }
508 WEBRTC_STUB(GetVersion, (char version[1024]));
509 WEBRTC_STUB(LastError, ());
510 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
511 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512
513 // webrtc::VoECodec
514 WEBRTC_FUNC(NumOfCodecs, ()) {
515 return num_codecs_;
516 }
517 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
518 if (index < 0 || index >= NumOfCodecs()) {
519 return -1;
520 }
521 const cricket::AudioCodec& c(*codecs_[index]);
522 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000523 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 codec.plfreq = c.clockrate;
525 codec.pacsize = 0;
526 codec.channels = c.channels;
527 codec.rate = c.bitrate;
528 return 0;
529 }
530 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
531 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000532 // To match the behavior of the real implementation.
533 if (_stricmp(codec.plname, "telephone-event") == 0 ||
534 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
535 _stricmp(codec.plname, "CN") == 0 ||
536 _stricmp(codec.plname, "red") == 0 ) {
537 return -1;
538 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000540 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 return 0;
542 }
543 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
544 WEBRTC_CHECK_CHANNEL(channel);
545 codec = channels_[channel]->send_codec;
546 return 0;
547 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000548 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
549 WEBRTC_CHECK_CHANNEL(channel);
550 const Channel* c = channels_[channel];
551 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
552 it_packet != c->packets.end(); ++it_packet) {
553 int pltype;
554 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
555 continue;
556 }
557 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
558 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
559 ++it_codec) {
560 if (it_codec->pltype == pltype) {
561 codec = *it_codec;
562 return 0;
563 }
564 }
565 }
566 return -1;
567 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
569 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
570 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
571 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
572 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
573 bool useFixedFrameSize));
574 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
575 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
576 WEBRTC_FUNC(SetRecPayloadType, (int channel,
577 const webrtc::CodecInst& codec)) {
578 WEBRTC_CHECK_CHANNEL(channel);
579 Channel* ch = channels_[channel];
580 if (ch->playout)
581 return -1; // Channel is in use.
582 // Check if something else already has this slot.
583 if (codec.pltype != -1) {
584 for (std::vector<webrtc::CodecInst>::iterator it =
585 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
586 if (it->pltype == codec.pltype &&
587 _stricmp(it->plname, codec.plname) != 0) {
588 return -1;
589 }
590 }
591 }
592 // Otherwise try to find this codec and update its payload type.
593 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
594 it != ch->recv_codecs.end(); ++it) {
595 if (strcmp(it->plname, codec.plname) == 0 &&
596 it->plfreq == codec.plfreq) {
597 it->pltype = codec.pltype;
598 it->channels = codec.channels;
599 return 0;
600 }
601 }
602 return -1; // not found
603 }
604 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
605 webrtc::PayloadFrequencies frequency)) {
606 WEBRTC_CHECK_CHANNEL(channel);
607 if (frequency == webrtc::kFreq8000Hz) {
608 channels_[channel]->cn8_type = type;
609 } else if (frequency == webrtc::kFreq16000Hz) {
610 channels_[channel]->cn16_type = type;
611 }
612 return 0;
613 }
614 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
615 WEBRTC_CHECK_CHANNEL(channel);
616 Channel* ch = channels_[channel];
617 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
618 it != ch->recv_codecs.end(); ++it) {
619 if (strcmp(it->plname, codec.plname) == 0 &&
620 it->plfreq == codec.plfreq &&
621 it->channels == codec.channels &&
622 it->pltype != -1) {
623 codec.pltype = it->pltype;
624 return 0;
625 }
626 }
627 return -1; // not found
628 }
629 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
630 bool disableDTX)) {
631 WEBRTC_CHECK_CHANNEL(channel);
632 if (channels_[channel]->send_codec.channels == 2) {
633 // Replicating VoE behavior; VAD cannot be enabled for stereo.
634 return -1;
635 }
636 channels_[channel]->vad = enable;
637 return 0;
638 }
639 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
640 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000641
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000642 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
643 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000644 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000645 // Return -1 if current send codec is not Opus.
646 // TODO(minyue): Excludes other codecs if they support inband FEC.
647 return -1;
648 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000649 channels_[channel]->codec_fec = enable;
650 return 0;
651 }
652 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
653 WEBRTC_CHECK_CHANNEL(channel);
654 enable = channels_[channel]->codec_fec;
655 return 0;
656 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000657
658 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
659 WEBRTC_CHECK_CHANNEL(channel);
660 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
661 // Return -1 if current send codec is not Opus.
662 return -1;
663 }
664 if (frequency_hz <= 8000)
665 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
666 else if (frequency_hz <= 12000)
667 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
668 else if (frequency_hz <= 16000)
669 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
670 else if (frequency_hz <= 24000)
671 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
672 else
673 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
674 return 0;
675 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676
677 // webrtc::VoEDtmf
678 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
679 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
680 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
681 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
682 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
683 return 0;
684 }
685
686 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
687 (int channel, unsigned char type)) {
688 channels_[channel]->dtmf_type = type;
689 return 0;
690 };
691 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
692 (int channel, unsigned char& type));
693
694 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
695 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 WEBRTC_FUNC(PlayDtmfTone,
698 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
699 dtmf_info_.dtmf_event_code = event_code;
700 dtmf_info_.dtmf_length_ms = length_ms;
701 return 0;
702 }
703 WEBRTC_STUB(StartPlayingDtmfTone,
704 (int eventCode, int attenuationDb = 10));
705 WEBRTC_STUB(StopPlayingDtmfTone, ());
706
707 // webrtc::VoEFile
708 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
709 bool loop, webrtc::FileFormats format,
710 float volumeScaling, int startPointMs,
711 int stopPointMs)) {
712 WEBRTC_CHECK_CHANNEL(channel);
713 channels_[channel]->file = true;
714 return 0;
715 }
716 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
717 webrtc::FileFormats format,
718 float volumeScaling, int startPointMs,
719 int stopPointMs)) {
720 WEBRTC_CHECK_CHANNEL(channel);
721 channels_[channel]->file = true;
722 return 0;
723 }
724 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
725 WEBRTC_CHECK_CHANNEL(channel);
726 channels_[channel]->file = false;
727 return 0;
728 }
729 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
730 WEBRTC_CHECK_CHANNEL(channel);
731 return (channels_[channel]->file) ? 1 : 0;
732 }
733 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
734 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
735 const char* fileNameUTF8,
736 bool loop,
737 bool mixWithMicrophone,
738 webrtc::FileFormats format,
739 float volumeScaling));
740 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
741 webrtc::InStream* stream,
742 bool mixWithMicrophone,
743 webrtc::FileFormats format,
744 float volumeScaling));
745 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
746 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
747 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
748 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
749 webrtc::CodecInst* compression,
750 int maxSizeBytes));
751 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
752 webrtc::CodecInst* compression));
753 WEBRTC_STUB(StopRecordingPlayout, (int channel));
754 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
755 webrtc::CodecInst* compression,
756 int maxSizeBytes)) {
757 if (fail_start_recording_microphone_) {
758 return -1;
759 }
760 recording_microphone_ = true;
761 return 0;
762 }
763 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
764 webrtc::CodecInst* compression)) {
765 if (fail_start_recording_microphone_) {
766 return -1;
767 }
768 recording_microphone_ = true;
769 return 0;
770 }
771 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
772 if (!recording_microphone_) {
773 return -1;
774 }
775 recording_microphone_ = false;
776 return 0;
777 }
778 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
779 const char* fileNameOutUTF8));
780 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
781 webrtc::OutStream* streamOut));
782 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
783 const char* fileNameOutUTF8));
784 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
785 webrtc::OutStream* streamOut));
786 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
787 const char* fileNameOutUTF8,
788 webrtc::CodecInst* compression));
789 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
790 webrtc::OutStream* streamOut,
791 webrtc::CodecInst* compression));
792 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
793 const char* fileNameOutUTF8));
794 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
795 webrtc::OutStream* streamOut));
796 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
797 webrtc::FileFormats format));
798 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
799
800 // webrtc::VoEHardware
801 WEBRTC_STUB(GetCPULoad, (int&));
802 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
803 return GetNumDevices(num);
804 }
805 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
806 return GetNumDevices(num);
807 }
808 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
809 return GetDeviceName(i, name, guid);
810 }
811 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
812 return GetDeviceName(i, name, guid);
813 }
814 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
815 WEBRTC_STUB(SetPlayoutDevice, (int));
816 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
817 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
818 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
819 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
820 WEBRTC_STUB(ResetAudioDevice, ());
821 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
822 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
823 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000824 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
825 recording_sample_rate_ = samples_per_sec;
826 return 0;
827 }
828 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
829 *samples_per_sec = recording_sample_rate_;
830 return 0;
831 }
832 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
833 playout_sample_rate_ = samples_per_sec;
834 return 0;
835 }
836 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
837 *samples_per_sec = playout_sample_rate_;
838 return 0;
839 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
841 virtual bool BuiltInAECIsEnabled() const { return true; }
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000842 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843
844 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000845 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
846 webrtc::NetworkStatistics& ns)) {
847 WEBRTC_CHECK_CHANNEL(channel);
848 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
849 return 0;
850 }
851
wu@webrtc.org24301a62013-12-13 19:17:43 +0000852 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
853 webrtc::AudioDecodingCallStats*)) {
854 WEBRTC_CHECK_CHANNEL(channel);
855 return 0;
856 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857
858 // webrtc::VoENetwork
859 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
860 webrtc::Transport& transport)) {
861 WEBRTC_CHECK_CHANNEL(channel);
862 channels_[channel]->external_transport = true;
863 return 0;
864 }
865 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
866 WEBRTC_CHECK_CHANNEL(channel);
867 channels_[channel]->external_transport = false;
868 return 0;
869 }
870 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000871 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 WEBRTC_CHECK_CHANNEL(channel);
873 if (!channels_[channel]->external_transport) return -1;
874 channels_[channel]->packets.push_back(
875 std::string(static_cast<const char*>(data), length));
876 return 0;
877 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000878 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000879 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000880 const webrtc::PacketTime& packet_time)) {
881 WEBRTC_CHECK_CHANNEL(channel);
882 if (ReceivedRTPPacket(channel, data, length) == -1) {
883 return -1;
884 }
885 channels_[channel]->last_rtp_packet_time = packet_time;
886 return 0;
887 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000888
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000890 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891
892 // webrtc::VoERTP_RTCP
893 WEBRTC_STUB(RegisterRTPObserver, (int channel,
894 webrtc::VoERTPObserver& observer));
895 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
897 WEBRTC_CHECK_CHANNEL(channel);
898 channels_[channel]->send_ssrc = ssrc;
899 return 0;
900 }
901 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
902 WEBRTC_CHECK_CHANNEL(channel);
903 ssrc = channels_[channel]->send_ssrc;
904 return 0;
905 }
906 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000907 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
908 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000910 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
911 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 return 0;
913 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000914 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
915 unsigned char id)) {
916 WEBRTC_CHECK_CHANNEL(channel);
917 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
918 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
919 return 0;
920 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000921 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
922 unsigned char id)) {
923 WEBRTC_CHECK_CHANNEL(channel);
924 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
925 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
926 return 0;
927 }
928 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
929 unsigned char id)) {
930 WEBRTC_CHECK_CHANNEL(channel);
931 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
932 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
933 return 0;
934 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000935
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
937 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
938 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
939 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
940 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
941 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
942 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
943 unsigned int& NTPLow,
944 unsigned int& timestamp,
945 unsigned int& playoutTimestamp,
946 unsigned int* jitter,
947 unsigned short* fractionLost));
948 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
949 webrtc::SenderInfo* sender_info));
950 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
951 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
952 WEBRTC_CHECK_CHANNEL(channel);
953 webrtc::ReportBlock block;
954 block.source_SSRC = channels_[channel]->send_ssrc;
955 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
956 if (send_codec.pltype >= 0) {
957 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
958 if (send_codec.plfreq / 1000 > 0) {
959 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
960 }
961 block.cumulative_num_packets_lost = kIntStatValue;
962 block.extended_highest_sequence_number = kIntStatValue;
963 receive_blocks->push_back(block);
964 }
965 return 0;
966 }
967 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
968 unsigned char subType,
969 unsigned int name,
970 const char* data,
971 unsigned short dataLength));
972 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
973 unsigned int& maxJitterMs,
974 unsigned int& discardedPackets));
975 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
976 WEBRTC_CHECK_CHANNEL(channel);
977 stats.fractionLost = static_cast<int16>(kIntStatValue);
978 stats.cumulativeLost = kIntStatValue;
979 stats.extendedMax = kIntStatValue;
980 stats.jitterSamples = kIntStatValue;
981 stats.rttMs = kIntStatValue;
982 stats.bytesSent = kIntStatValue;
983 stats.packetsSent = kIntStatValue;
984 stats.bytesReceived = kIntStatValue;
985 stats.packetsReceived = kIntStatValue;
986 return 0;
987 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000988 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000989 return SetFECStatus(channel, enable, redPayloadtype);
990 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000991 // TODO(minyue): remove the below function when transition to SetREDStatus
992 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
994 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000995 channels_[channel]->red = enable;
996 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 return 0;
998 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000999 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +00001000 return GetFECStatus(channel, enable, redPayloadtype);
1001 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +00001002 // TODO(minyue): remove the below function when transition to GetREDStatus
1003 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
1005 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001006 enable = channels_[channel]->red;
1007 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 return 0;
1009 }
1010 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
1011 WEBRTC_CHECK_CHANNEL(channel);
1012 channels_[channel]->nack = enable;
1013 channels_[channel]->nack_max_packets = maxNoPackets;
1014 return 0;
1015 }
1016 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
1017 webrtc::RTPDirections direction));
1018 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
1019 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
1020 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
1021 bool markerBit, const char* payloadData,
1022 unsigned short payloadSize));
1023 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
1024 uint32_t* lastRemoteTimeStamp));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001025 WEBRTC_FUNC(SetVideoEngineBWETarget, (int channel,
1026 webrtc::ViENetwork* vie_network,
1027 int video_channel)) {
1028 WEBRTC_CHECK_CHANNEL(channel);
1029 channels_[channel]->vie_network = vie_network;
1030 channels_[channel]->video_channel = video_channel;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001031 if (vie_network) {
1032 // The interface is released here to avoid leaks. A test should not
1033 // attempt to call functions on the interface stored in the channel.
1034 vie_network->Release();
1035 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001036 return 0;
1037 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038
1039 // webrtc::VoEVideoSync
1040 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1041 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001042 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1044 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1045 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1046 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1047 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1048 int* playout_buffer_delay_ms));
1049 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1050
1051 // webrtc::VoEVolumeControl
1052 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1053 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1054 WEBRTC_STUB(SetSystemOutputMute, (bool));
1055 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1056 WEBRTC_STUB(SetMicVolume, (unsigned int));
1057 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1058 WEBRTC_STUB(SetInputMute, (int, bool));
1059 WEBRTC_STUB(GetInputMute, (int, bool&));
1060 WEBRTC_STUB(SetSystemInputMute, (bool));
1061 WEBRTC_STUB(GetSystemInputMute, (bool&));
1062 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1063 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1064 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1065 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1066 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1067 WEBRTC_CHECK_CHANNEL(channel);
1068 channels_[channel]->volume_scale= scale;
1069 return 0;
1070 }
1071 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1072 WEBRTC_CHECK_CHANNEL(channel);
1073 scale = channels_[channel]->volume_scale;
1074 return 0;
1075 }
1076 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1077 WEBRTC_CHECK_CHANNEL(channel);
1078 channels_[channel]->volume_pan_left = left;
1079 channels_[channel]->volume_pan_right = right;
1080 return 0;
1081 }
1082 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1083 WEBRTC_CHECK_CHANNEL(channel);
1084 left = channels_[channel]->volume_pan_left;
1085 right = channels_[channel]->volume_pan_right;
1086 return 0;
1087 }
1088
1089 // webrtc::VoEAudioProcessing
1090 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1091 ns_enabled_ = enable;
1092 ns_mode_ = mode;
1093 return 0;
1094 }
1095 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1096 enabled = ns_enabled_;
1097 mode = ns_mode_;
1098 return 0;
1099 }
1100
1101 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1102 agc_enabled_ = enable;
1103 agc_mode_ = mode;
1104 return 0;
1105 }
1106 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1107 enabled = agc_enabled_;
1108 mode = agc_mode_;
1109 return 0;
1110 }
1111
1112 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1113 agc_config_ = config;
1114 return 0;
1115 }
1116 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1117 config = agc_config_;
1118 return 0;
1119 }
1120 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1121 ec_enabled_ = enable;
1122 ec_mode_ = mode;
1123 return 0;
1124 }
1125 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1126 enabled = ec_enabled_;
1127 mode = ec_mode_;
1128 return 0;
1129 }
1130 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1131 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1132 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1133 WEBRTC_STUB(DelayOffsetMs, ());
1134 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1135 aecm_mode_ = mode;
1136 cng_enabled_ = enableCNG;
1137 return 0;
1138 }
1139 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1140 mode = aecm_mode_;
1141 enabledCNG = cng_enabled_;
1142 return 0;
1143 }
1144 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1145 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1146 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001147 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1148 webrtc::AgcModes mode)) {
1149 channels_[channel]->rx_agc_enabled = enable;
1150 channels_[channel]->rx_agc_mode = mode;
1151 return 0;
1152 }
1153 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1154 webrtc::AgcModes& mode)) {
1155 enabled = channels_[channel]->rx_agc_enabled;
1156 mode = channels_[channel]->rx_agc_mode;
1157 return 0;
1158 }
1159
1160 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1161 channels_[channel]->rx_agc_config = config;
1162 return 0;
1163 }
1164 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1165 config = channels_[channel]->rx_agc_config;
1166 return 0;
1167 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168
1169 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1170 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1171 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1172 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1173 ec_metrics_enabled_ = enable;
1174 return 0;
1175 }
1176 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1177 enabled = ec_metrics_enabled_;
1178 return 0;
1179 }
1180 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001181 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1182 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183
1184 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001185 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 WEBRTC_STUB(StopDebugRecording, ());
1187
1188 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1189 typing_detection_enabled_ = enable;
1190 return 0;
1191 }
1192 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1193 enabled = typing_detection_enabled_;
1194 return 0;
1195 }
1196
1197 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1198 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1199 int costPerTyping,
1200 int reportingThreshold,
1201 int penaltyDecay,
1202 int typeEventDelay));
1203 int EnableHighPassFilter(bool enable) {
1204 highpass_filter_enabled_ = enable;
1205 return 0;
1206 }
1207 bool IsHighPassFilterEnabled() {
1208 return highpass_filter_enabled_;
1209 }
1210 bool IsStereoChannelSwappingEnabled() {
1211 return stereo_swapping_enabled_;
1212 }
1213 void EnableStereoChannelSwapping(bool enable) {
1214 stereo_swapping_enabled_ = enable;
1215 }
1216 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1217 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1218 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1219 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1220 }
1221 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1222 return (dtmf_info_.dtmf_event_code == event_code &&
1223 dtmf_info_.dtmf_length_ms == length_ms);
1224 }
1225 // webrtc::VoEExternalMedia
1226 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1227 (int channel, webrtc::ProcessingTypes type,
1228 webrtc::VoEMediaProcess& processObject)) {
1229 WEBRTC_CHECK_CHANNEL(channel);
1230 if (channels_[channel]->media_processor_registered) {
1231 return -1;
1232 }
1233 channels_[channel]->media_processor_registered = true;
1234 media_processor_ = &processObject;
1235 return 0;
1236 }
1237 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1238 (int channel, webrtc::ProcessingTypes type)) {
1239 WEBRTC_CHECK_CHANNEL(channel);
1240 if (!channels_[channel]->media_processor_registered) {
1241 return -1;
1242 }
1243 channels_[channel]->media_processor_registered = false;
1244 media_processor_ = NULL;
1245 return 0;
1246 }
1247 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1248 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1249 WEBRTC_STUB(ExternalRecordingInsertData,
1250 (const int16_t speechData10ms[], int lengthSamples,
1251 int samplingFreqHz, int current_delay_ms));
1252 WEBRTC_STUB(ExternalPlayoutGetData,
1253 (int16_t speechData10ms[], int samplingFreqHz,
1254 int current_delay_ms, int& lengthSamples));
1255 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1256 webrtc::AudioFrame* frame));
1257 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1258
1259 private:
1260 int GetNumDevices(int& num) {
1261#ifdef WIN32
1262 num = 1;
1263#else
1264 // On non-Windows platforms VE adds a special entry for the default device,
1265 // so if there is one physical device then there are two entries in the
1266 // list.
1267 num = 2;
1268#endif
1269 return 0;
1270 }
1271
1272 int GetDeviceName(int i, char* name, char* guid) {
1273 const char *s;
1274#ifdef WIN32
1275 if (0 == i) {
1276 s = kFakeDeviceName;
1277 } else {
1278 return -1;
1279 }
1280#else
1281 // See comment above.
1282 if (0 == i) {
1283 s = kFakeDefaultDeviceName;
1284 } else if (1 == i) {
1285 s = kFakeDeviceName;
1286 } else {
1287 return -1;
1288 }
1289#endif
1290 strcpy(name, s);
1291 guid[0] = '\0';
1292 return 0;
1293 }
1294
1295 bool inited_;
1296 int last_channel_;
1297 std::map<int, Channel*> channels_;
1298 bool fail_create_channel_;
1299 const cricket::AudioCodec* const* codecs_;
1300 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001301 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 bool ec_enabled_;
1303 bool ec_metrics_enabled_;
1304 bool cng_enabled_;
1305 bool ns_enabled_;
1306 bool agc_enabled_;
1307 bool highpass_filter_enabled_;
1308 bool stereo_swapping_enabled_;
1309 bool typing_detection_enabled_;
1310 webrtc::EcModes ec_mode_;
1311 webrtc::AecmModes aecm_mode_;
1312 webrtc::NsModes ns_mode_;
1313 webrtc::AgcModes agc_mode_;
1314 webrtc::AgcConfig agc_config_;
1315 webrtc::VoiceEngineObserver* observer_;
1316 int playout_fail_channel_;
1317 int send_fail_channel_;
1318 bool fail_start_recording_microphone_;
1319 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001320 int recording_sample_rate_;
1321 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 DtmfInfo dtmf_info_;
1323 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001324 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325};
1326
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001327#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1328
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329} // namespace cricket
1330
1331#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_