blob: 24ef84605898ddb796c0c2811a0750367ff2314e [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"
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020041#include "webrtc/base/checks.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "webrtc/base/gunit.h"
43#include "webrtc/base/stringutils.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000044#include "webrtc/modules/audio_processing/include/audio_processing.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
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020087#define WEBRTC_CHECK_CHANNEL(channel) \
88 if (channels_.find(channel) == channels_.end()) return -1;
89
90#define WEBRTC_ASSERT_CHANNEL(channel) \
91 DCHECK(channels_.find(channel) != channels_.end());
92
henrike@webrtc.org79047f92014-03-06 23:46:59 +000093// Verify the header extension ID, if enabled, is within the bounds specified in
94// [RFC5285]: 1-14 inclusive.
95#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
96 do { \
97 if (enable && (id < 1 || id > 14)) { \
98 return -1; \
99 } \
100 } while (0);
101
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000102class FakeAudioProcessing : public webrtc::AudioProcessing {
103 public:
104 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
105
106 WEBRTC_STUB(Initialize, ())
107 WEBRTC_STUB(Initialize, (
108 int input_sample_rate_hz,
109 int output_sample_rate_hz,
110 int reverse_sample_rate_hz,
111 webrtc::AudioProcessing::ChannelLayout input_layout,
112 webrtc::AudioProcessing::ChannelLayout output_layout,
113 webrtc::AudioProcessing::ChannelLayout reverse_layout));
114
115 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
116 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
117 }
118
119 WEBRTC_STUB(set_sample_rate_hz, (int rate));
120 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
121 WEBRTC_STUB_CONST(sample_rate_hz, ());
122 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
123 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
124 WEBRTC_STUB_CONST(num_input_channels, ());
125 WEBRTC_STUB_CONST(num_output_channels, ());
126 WEBRTC_STUB_CONST(num_reverse_channels, ());
127 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
128 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
129 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
130 WEBRTC_STUB(ProcessStream, (
131 const float* const* src,
132 int samples_per_channel,
133 int input_sample_rate_hz,
134 webrtc::AudioProcessing::ChannelLayout input_layout,
135 int output_sample_rate_hz,
136 webrtc::AudioProcessing::ChannelLayout output_layout,
137 float* const* dest));
138 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
139 WEBRTC_STUB(AnalyzeReverseStream, (
140 const float* const* data,
141 int samples_per_channel,
142 int sample_rate_hz,
143 webrtc::AudioProcessing::ChannelLayout layout));
144 WEBRTC_STUB(set_stream_delay_ms, (int delay));
145 WEBRTC_STUB_CONST(stream_delay_ms, ());
146 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
147 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
148 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
149 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
150 WEBRTC_STUB_CONST(delay_offset_ms, ());
151 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
152 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
153 WEBRTC_STUB(StopDebugRecording, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000154 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
155 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000156 return NULL;
157 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000158 webrtc::GainControl* gain_control() const override { return NULL; }
159 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
160 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
161 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
162 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000163
164 bool experimental_ns_enabled() {
165 return experimental_ns_enabled_;
166 }
167
168 private:
169 bool experimental_ns_enabled_;
170};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000171
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172class FakeWebRtcVoiceEngine
173 : public webrtc::VoEAudioProcessing,
174 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
175 public webrtc::VoEFile, public webrtc::VoEHardware,
176 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
177 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
178 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
179 public:
180 struct DtmfInfo {
181 DtmfInfo()
182 : dtmf_event_code(-1),
183 dtmf_out_of_band(false),
184 dtmf_length_ms(-1) {}
185 int dtmf_event_code;
186 bool dtmf_out_of_band;
187 int dtmf_length_ms;
188 };
189 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000190 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 : external_transport(false),
192 send(false),
193 playout(false),
194 volume_scale(1.0),
195 volume_pan_left(1.0),
196 volume_pan_right(1.0),
197 file(false),
198 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000199 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000200 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000201 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000202 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 nack(false),
204 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000205 rx_agc_enabled(false),
206 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 cn8_type(13),
208 cn16_type(105),
209 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000210 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 nack_max_packets(0),
212 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000213 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000214 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000215 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000216 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000218 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 }
220 bool external_transport;
221 bool send;
222 bool playout;
223 float volume_scale;
224 float volume_pan_left;
225 float volume_pan_right;
226 bool file;
227 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000228 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000229 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000230 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000231 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 bool nack;
233 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000234 bool rx_agc_enabled;
235 webrtc::AgcModes rx_agc_mode;
236 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 int cn8_type;
238 int cn16_type;
239 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000240 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 int nack_max_packets;
242 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000243 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000244 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000245 int send_absolute_sender_time_ext_;
246 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 DtmfInfo dtmf_info;
248 std::vector<webrtc::CodecInst> recv_codecs;
249 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000250 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 std::list<std::string> packets;
252 };
253
254 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
255 int num_codecs)
256 : inited_(false),
257 last_channel_(-1),
258 fail_create_channel_(false),
259 codecs_(codecs),
260 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000261 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 ec_enabled_(false),
263 ec_metrics_enabled_(false),
264 cng_enabled_(false),
265 ns_enabled_(false),
266 agc_enabled_(false),
267 highpass_filter_enabled_(false),
268 stereo_swapping_enabled_(false),
269 typing_detection_enabled_(false),
270 ec_mode_(webrtc::kEcDefault),
271 aecm_mode_(webrtc::kAecmSpeakerphone),
272 ns_mode_(webrtc::kNsDefault),
273 agc_mode_(webrtc::kAgcDefault),
274 observer_(NULL),
275 playout_fail_channel_(-1),
276 send_fail_channel_(-1),
277 fail_start_recording_microphone_(false),
278 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000279 recording_sample_rate_(-1),
280 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 media_processor_(NULL) {
282 memset(&agc_config_, 0, sizeof(agc_config_));
283 }
284 ~FakeWebRtcVoiceEngine() {
285 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
286 // destructors, but just in case ...
287 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
288 i != channels_.end(); ++i) {
289 delete i->second;
290 }
291 }
292
293 bool IsExternalMediaProcessorRegistered() const {
294 return media_processor_ != NULL;
295 }
296 bool IsInited() const { return inited_; }
297 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000298 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
299 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
300 iter != channels_.end(); ++iter) {
301 if (local_ssrc == iter->second->send_ssrc)
302 return iter->first;
303 }
304 return -1;
305 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000306 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 bool GetPlayout(int channel) {
308 return channels_[channel]->playout;
309 }
310 bool GetSend(int channel) {
311 return channels_[channel]->send;
312 }
313 bool GetRecordingMicrophone() {
314 return recording_microphone_;
315 }
316 bool GetVAD(int channel) {
317 return channels_[channel]->vad;
318 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100319 bool GetOpusDtx(int channel) {
320 return channels_[channel]->opus_dtx;
321 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000322 bool GetRED(int channel) {
323 return channels_[channel]->red;
324 }
325 bool GetCodecFEC(int channel) {
326 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000328 int GetMaxEncodingBandwidth(int channel) {
329 return channels_[channel]->max_encoding_bandwidth;
330 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 bool GetNACK(int channel) {
332 return channels_[channel]->nack;
333 }
334 int GetNACKMaxPackets(int channel) {
335 return channels_[channel]->nack_max_packets;
336 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000337 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
338 WEBRTC_ASSERT_CHANNEL(channel);
339 return channels_[channel]->last_rtp_packet_time;
340 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 int GetSendCNPayloadType(int channel, bool wideband) {
342 return (wideband) ?
343 channels_[channel]->cn16_type :
344 channels_[channel]->cn8_type;
345 }
346 int GetSendTelephoneEventPayloadType(int channel) {
347 return channels_[channel]->dtmf_type;
348 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000349 int GetSendREDPayloadType(int channel) {
350 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 }
352 bool CheckPacket(int channel, const void* data, size_t len) {
353 bool result = !CheckNoPacket(channel);
354 if (result) {
355 std::string packet = channels_[channel]->packets.front();
356 result = (packet == std::string(static_cast<const char*>(data), len));
357 channels_[channel]->packets.pop_front();
358 }
359 return result;
360 }
361 bool CheckNoPacket(int channel) {
362 return channels_[channel]->packets.empty();
363 }
364 void TriggerCallbackOnError(int channel_num, int err_code) {
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +0200365 DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 observer_->CallbackOnError(channel_num, err_code);
367 }
368 void set_playout_fail_channel(int channel) {
369 playout_fail_channel_ = channel;
370 }
371 void set_send_fail_channel(int channel) {
372 send_fail_channel_ = channel;
373 }
374 void set_fail_start_recording_microphone(
375 bool fail_start_recording_microphone) {
376 fail_start_recording_microphone_ = fail_start_recording_microphone;
377 }
378 void set_fail_create_channel(bool fail_create_channel) {
379 fail_create_channel_ = fail_create_channel;
380 }
381 void TriggerProcessPacket(MediaProcessorDirection direction) {
382 webrtc::ProcessingTypes pt =
383 (direction == cricket::MPD_TX) ?
384 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
385 if (media_processor_ != NULL) {
386 media_processor_->Process(0,
387 pt,
388 NULL,
389 0,
390 0,
391 true);
392 }
393 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000394 int AddChannel() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000395 if (fail_create_channel_) {
396 return -1;
397 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000398 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000399 for (int i = 0; i < NumOfCodecs(); ++i) {
400 webrtc::CodecInst codec;
401 GetCodec(i, codec);
402 ch->recv_codecs.push_back(codec);
403 }
404 channels_[++last_channel_] = ch;
405 return last_channel_;
406 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000407 int GetSendRtpExtensionId(int channel, const std::string& extension) {
408 WEBRTC_ASSERT_CHANNEL(channel);
409 if (extension == kRtpAudioLevelHeaderExtension) {
410 return channels_[channel]->send_audio_level_ext_;
411 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
412 return channels_[channel]->send_absolute_sender_time_ext_;
413 }
414 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000415 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000416 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
417 WEBRTC_ASSERT_CHANNEL(channel);
418 if (extension == kRtpAudioLevelHeaderExtension) {
419 return channels_[channel]->receive_audio_level_ext_;
420 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
421 return channels_[channel]->receive_absolute_sender_time_ext_;
422 }
423 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000426 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
427
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 WEBRTC_STUB(Release, ());
429
430 // webrtc::VoEBase
431 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
432 webrtc::VoiceEngineObserver& observer)) {
433 observer_ = &observer;
434 return 0;
435 }
436 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
437 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
438 webrtc::AudioProcessing* audioproc)) {
439 inited_ = true;
440 return 0;
441 }
442 WEBRTC_FUNC(Terminate, ()) {
443 inited_ = false;
444 return 0;
445 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000446 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000447 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000450 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000452 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
453 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000454 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 WEBRTC_FUNC(DeleteChannel, (int channel)) {
456 WEBRTC_CHECK_CHANNEL(channel);
457 delete channels_[channel];
458 channels_.erase(channel);
459 return 0;
460 }
461 WEBRTC_STUB(StartReceive, (int channel));
462 WEBRTC_FUNC(StartPlayout, (int channel)) {
463 if (playout_fail_channel_ != channel) {
464 WEBRTC_CHECK_CHANNEL(channel);
465 channels_[channel]->playout = true;
466 return 0;
467 } else {
468 // When playout_fail_channel_ == channel, fail the StartPlayout on this
469 // channel.
470 return -1;
471 }
472 }
473 WEBRTC_FUNC(StartSend, (int channel)) {
474 if (send_fail_channel_ != channel) {
475 WEBRTC_CHECK_CHANNEL(channel);
476 channels_[channel]->send = true;
477 return 0;
478 } else {
479 // When send_fail_channel_ == channel, fail the StartSend on this
480 // channel.
481 return -1;
482 }
483 }
484 WEBRTC_STUB(StopReceive, (int channel));
485 WEBRTC_FUNC(StopPlayout, (int channel)) {
486 WEBRTC_CHECK_CHANNEL(channel);
487 channels_[channel]->playout = false;
488 return 0;
489 }
490 WEBRTC_FUNC(StopSend, (int channel)) {
491 WEBRTC_CHECK_CHANNEL(channel);
492 channels_[channel]->send = false;
493 return 0;
494 }
495 WEBRTC_STUB(GetVersion, (char version[1024]));
496 WEBRTC_STUB(LastError, ());
497 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
498 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499
500 // webrtc::VoECodec
501 WEBRTC_FUNC(NumOfCodecs, ()) {
502 return num_codecs_;
503 }
504 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
505 if (index < 0 || index >= NumOfCodecs()) {
506 return -1;
507 }
508 const cricket::AudioCodec& c(*codecs_[index]);
509 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000510 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511 codec.plfreq = c.clockrate;
512 codec.pacsize = 0;
513 codec.channels = c.channels;
514 codec.rate = c.bitrate;
515 return 0;
516 }
517 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
518 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000519 // To match the behavior of the real implementation.
520 if (_stricmp(codec.plname, "telephone-event") == 0 ||
521 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
522 _stricmp(codec.plname, "CN") == 0 ||
523 _stricmp(codec.plname, "red") == 0 ) {
524 return -1;
525 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000527 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528 return 0;
529 }
530 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
531 WEBRTC_CHECK_CHANNEL(channel);
532 codec = channels_[channel]->send_codec;
533 return 0;
534 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200535 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000536 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
537 WEBRTC_CHECK_CHANNEL(channel);
538 const Channel* c = channels_[channel];
539 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
540 it_packet != c->packets.end(); ++it_packet) {
541 int pltype;
542 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
543 continue;
544 }
545 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
546 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
547 ++it_codec) {
548 if (it_codec->pltype == pltype) {
549 codec = *it_codec;
550 return 0;
551 }
552 }
553 }
554 return -1;
555 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
557 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
558 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
559 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
560 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
561 bool useFixedFrameSize));
562 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
563 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
564 WEBRTC_FUNC(SetRecPayloadType, (int channel,
565 const webrtc::CodecInst& codec)) {
566 WEBRTC_CHECK_CHANNEL(channel);
567 Channel* ch = channels_[channel];
568 if (ch->playout)
569 return -1; // Channel is in use.
570 // Check if something else already has this slot.
571 if (codec.pltype != -1) {
572 for (std::vector<webrtc::CodecInst>::iterator it =
573 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
574 if (it->pltype == codec.pltype &&
575 _stricmp(it->plname, codec.plname) != 0) {
576 return -1;
577 }
578 }
579 }
580 // Otherwise try to find this codec and update its payload type.
581 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
582 it != ch->recv_codecs.end(); ++it) {
583 if (strcmp(it->plname, codec.plname) == 0 &&
584 it->plfreq == codec.plfreq) {
585 it->pltype = codec.pltype;
586 it->channels = codec.channels;
587 return 0;
588 }
589 }
590 return -1; // not found
591 }
592 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
593 webrtc::PayloadFrequencies frequency)) {
594 WEBRTC_CHECK_CHANNEL(channel);
595 if (frequency == webrtc::kFreq8000Hz) {
596 channels_[channel]->cn8_type = type;
597 } else if (frequency == webrtc::kFreq16000Hz) {
598 channels_[channel]->cn16_type = type;
599 }
600 return 0;
601 }
602 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
603 WEBRTC_CHECK_CHANNEL(channel);
604 Channel* ch = channels_[channel];
605 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
606 it != ch->recv_codecs.end(); ++it) {
607 if (strcmp(it->plname, codec.plname) == 0 &&
608 it->plfreq == codec.plfreq &&
609 it->channels == codec.channels &&
610 it->pltype != -1) {
611 codec.pltype = it->pltype;
612 return 0;
613 }
614 }
615 return -1; // not found
616 }
617 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
618 bool disableDTX)) {
619 WEBRTC_CHECK_CHANNEL(channel);
620 if (channels_[channel]->send_codec.channels == 2) {
621 // Replicating VoE behavior; VAD cannot be enabled for stereo.
622 return -1;
623 }
624 channels_[channel]->vad = enable;
625 return 0;
626 }
627 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
628 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000629
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000630 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
631 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000632 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000633 // Return -1 if current send codec is not Opus.
634 // TODO(minyue): Excludes other codecs if they support inband FEC.
635 return -1;
636 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000637 channels_[channel]->codec_fec = enable;
638 return 0;
639 }
640 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
641 WEBRTC_CHECK_CHANNEL(channel);
642 enable = channels_[channel]->codec_fec;
643 return 0;
644 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000645
646 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
647 WEBRTC_CHECK_CHANNEL(channel);
648 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
649 // Return -1 if current send codec is not Opus.
650 return -1;
651 }
652 if (frequency_hz <= 8000)
653 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
654 else if (frequency_hz <= 12000)
655 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
656 else if (frequency_hz <= 16000)
657 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
658 else if (frequency_hz <= 24000)
659 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
660 else
661 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
662 return 0;
663 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000665 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
666 WEBRTC_CHECK_CHANNEL(channel);
667 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
668 // Return -1 if current send codec is not Opus.
669 return -1;
670 }
671 channels_[channel]->opus_dtx = enable_dtx;
672 return 0;
673 }
674
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 // webrtc::VoEDtmf
676 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
677 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
678 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
679 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
680 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
681 return 0;
682 }
683
684 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
685 (int channel, unsigned char type)) {
686 channels_[channel]->dtmf_type = type;
687 return 0;
688 };
689 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
690 (int channel, unsigned char& type));
691
692 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
693 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 WEBRTC_FUNC(PlayDtmfTone,
696 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
697 dtmf_info_.dtmf_event_code = event_code;
698 dtmf_info_.dtmf_length_ms = length_ms;
699 return 0;
700 }
701 WEBRTC_STUB(StartPlayingDtmfTone,
702 (int eventCode, int attenuationDb = 10));
703 WEBRTC_STUB(StopPlayingDtmfTone, ());
704
705 // webrtc::VoEFile
706 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
707 bool loop, 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(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
715 webrtc::FileFormats format,
716 float volumeScaling, int startPointMs,
717 int stopPointMs)) {
718 WEBRTC_CHECK_CHANNEL(channel);
719 channels_[channel]->file = true;
720 return 0;
721 }
722 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
723 WEBRTC_CHECK_CHANNEL(channel);
724 channels_[channel]->file = false;
725 return 0;
726 }
727 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
728 WEBRTC_CHECK_CHANNEL(channel);
729 return (channels_[channel]->file) ? 1 : 0;
730 }
731 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
732 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
733 const char* fileNameUTF8,
734 bool loop,
735 bool mixWithMicrophone,
736 webrtc::FileFormats format,
737 float volumeScaling));
738 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
739 webrtc::InStream* stream,
740 bool mixWithMicrophone,
741 webrtc::FileFormats format,
742 float volumeScaling));
743 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
744 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
745 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
746 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
747 webrtc::CodecInst* compression,
748 int maxSizeBytes));
749 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
750 webrtc::CodecInst* compression));
751 WEBRTC_STUB(StopRecordingPlayout, (int channel));
752 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
753 webrtc::CodecInst* compression,
754 int maxSizeBytes)) {
755 if (fail_start_recording_microphone_) {
756 return -1;
757 }
758 recording_microphone_ = true;
759 return 0;
760 }
761 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
762 webrtc::CodecInst* compression)) {
763 if (fail_start_recording_microphone_) {
764 return -1;
765 }
766 recording_microphone_ = true;
767 return 0;
768 }
769 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
770 if (!recording_microphone_) {
771 return -1;
772 }
773 recording_microphone_ = false;
774 return 0;
775 }
776 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
777 const char* fileNameOutUTF8));
778 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
779 webrtc::OutStream* streamOut));
780 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
781 const char* fileNameOutUTF8));
782 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
783 webrtc::OutStream* streamOut));
784 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
785 const char* fileNameOutUTF8,
786 webrtc::CodecInst* compression));
787 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
788 webrtc::OutStream* streamOut,
789 webrtc::CodecInst* compression));
790 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
791 const char* fileNameOutUTF8));
792 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
793 webrtc::OutStream* streamOut));
794 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
795 webrtc::FileFormats format));
796 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
797
798 // webrtc::VoEHardware
799 WEBRTC_STUB(GetCPULoad, (int&));
800 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
801 return GetNumDevices(num);
802 }
803 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
804 return GetNumDevices(num);
805 }
806 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
807 return GetDeviceName(i, name, guid);
808 }
809 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
810 return GetDeviceName(i, name, guid);
811 }
812 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
813 WEBRTC_STUB(SetPlayoutDevice, (int));
814 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
815 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
816 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
817 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
818 WEBRTC_STUB(ResetAudioDevice, ());
819 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
820 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
821 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000822 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
823 recording_sample_rate_ = samples_per_sec;
824 return 0;
825 }
826 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
827 *samples_per_sec = recording_sample_rate_;
828 return 0;
829 }
830 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
831 playout_sample_rate_ = samples_per_sec;
832 return 0;
833 }
834 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
835 *samples_per_sec = playout_sample_rate_;
836 return 0;
837 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
839 virtual bool BuiltInAECIsEnabled() const { return true; }
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000840 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841
842 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000843 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
844 webrtc::NetworkStatistics& ns)) {
845 WEBRTC_CHECK_CHANNEL(channel);
846 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
847 return 0;
848 }
849
wu@webrtc.org24301a62013-12-13 19:17:43 +0000850 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
851 webrtc::AudioDecodingCallStats*)) {
852 WEBRTC_CHECK_CHANNEL(channel);
853 return 0;
854 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855
856 // webrtc::VoENetwork
857 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
858 webrtc::Transport& transport)) {
859 WEBRTC_CHECK_CHANNEL(channel);
860 channels_[channel]->external_transport = true;
861 return 0;
862 }
863 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
864 WEBRTC_CHECK_CHANNEL(channel);
865 channels_[channel]->external_transport = false;
866 return 0;
867 }
868 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000869 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 WEBRTC_CHECK_CHANNEL(channel);
871 if (!channels_[channel]->external_transport) return -1;
872 channels_[channel]->packets.push_back(
873 std::string(static_cast<const char*>(data), length));
874 return 0;
875 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000876 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000877 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000878 const webrtc::PacketTime& packet_time)) {
879 WEBRTC_CHECK_CHANNEL(channel);
880 if (ReceivedRTPPacket(channel, data, length) == -1) {
881 return -1;
882 }
883 channels_[channel]->last_rtp_packet_time = packet_time;
884 return 0;
885 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000886
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000888 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889
890 // webrtc::VoERTP_RTCP
891 WEBRTC_STUB(RegisterRTPObserver, (int channel,
892 webrtc::VoERTPObserver& observer));
893 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
895 WEBRTC_CHECK_CHANNEL(channel);
896 channels_[channel]->send_ssrc = ssrc;
897 return 0;
898 }
899 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
900 WEBRTC_CHECK_CHANNEL(channel);
901 ssrc = channels_[channel]->send_ssrc;
902 return 0;
903 }
904 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000905 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
906 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000908 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
909 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 return 0;
911 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000912 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
913 unsigned char id)) {
914 WEBRTC_CHECK_CHANNEL(channel);
915 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
916 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
917 return 0;
918 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000919 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
920 unsigned char id)) {
921 WEBRTC_CHECK_CHANNEL(channel);
922 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
923 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
924 return 0;
925 }
926 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
927 unsigned char id)) {
928 WEBRTC_CHECK_CHANNEL(channel);
929 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
930 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
931 return 0;
932 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000933
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
935 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
936 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
937 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
938 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
939 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
940 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
941 unsigned int& NTPLow,
942 unsigned int& timestamp,
943 unsigned int& playoutTimestamp,
944 unsigned int* jitter,
945 unsigned short* fractionLost));
946 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
947 webrtc::SenderInfo* sender_info));
948 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
949 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
950 WEBRTC_CHECK_CHANNEL(channel);
951 webrtc::ReportBlock block;
952 block.source_SSRC = channels_[channel]->send_ssrc;
953 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
954 if (send_codec.pltype >= 0) {
955 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
956 if (send_codec.plfreq / 1000 > 0) {
957 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
958 }
959 block.cumulative_num_packets_lost = kIntStatValue;
960 block.extended_highest_sequence_number = kIntStatValue;
961 receive_blocks->push_back(block);
962 }
963 return 0;
964 }
965 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
966 unsigned char subType,
967 unsigned int name,
968 const char* data,
969 unsigned short dataLength));
970 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
971 unsigned int& maxJitterMs,
972 unsigned int& discardedPackets));
973 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
974 WEBRTC_CHECK_CHANNEL(channel);
975 stats.fractionLost = static_cast<int16>(kIntStatValue);
976 stats.cumulativeLost = kIntStatValue;
977 stats.extendedMax = kIntStatValue;
978 stats.jitterSamples = kIntStatValue;
979 stats.rttMs = kIntStatValue;
980 stats.bytesSent = kIntStatValue;
981 stats.packetsSent = kIntStatValue;
982 stats.bytesReceived = kIntStatValue;
983 stats.packetsReceived = kIntStatValue;
984 return 0;
985 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000986 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000987 return SetFECStatus(channel, enable, redPayloadtype);
988 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000989 // TODO(minyue): remove the below function when transition to SetREDStatus
990 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
992 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000993 channels_[channel]->red = enable;
994 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 return 0;
996 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000997 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000998 return GetFECStatus(channel, enable, redPayloadtype);
999 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +00001000 // TODO(minyue): remove the below function when transition to GetREDStatus
1001 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
1003 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001004 enable = channels_[channel]->red;
1005 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 return 0;
1007 }
1008 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
1009 WEBRTC_CHECK_CHANNEL(channel);
1010 channels_[channel]->nack = enable;
1011 channels_[channel]->nack_max_packets = maxNoPackets;
1012 return 0;
1013 }
1014 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
1015 webrtc::RTPDirections direction));
1016 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
1017 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
1018 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
1019 bool markerBit, const char* payloadData,
1020 unsigned short payloadSize));
1021 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
1022 uint32_t* lastRemoteTimeStamp));
Fredrik Solenberg6179b892015-05-07 16:01:26 +02001023 WEBRTC_STUB(SetVideoEngineBWETarget, (int channel,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001024 webrtc::ViENetwork* vie_network,
Fredrik Solenberg6179b892015-05-07 16:01:26 +02001025 int video_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026
1027 // webrtc::VoEVideoSync
1028 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1029 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001030 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1032 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1033 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1034 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1035 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1036 int* playout_buffer_delay_ms));
1037 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1038
1039 // webrtc::VoEVolumeControl
1040 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1041 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1042 WEBRTC_STUB(SetSystemOutputMute, (bool));
1043 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1044 WEBRTC_STUB(SetMicVolume, (unsigned int));
1045 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1046 WEBRTC_STUB(SetInputMute, (int, bool));
1047 WEBRTC_STUB(GetInputMute, (int, bool&));
1048 WEBRTC_STUB(SetSystemInputMute, (bool));
1049 WEBRTC_STUB(GetSystemInputMute, (bool&));
1050 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1051 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1052 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1053 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1054 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1055 WEBRTC_CHECK_CHANNEL(channel);
1056 channels_[channel]->volume_scale= scale;
1057 return 0;
1058 }
1059 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1060 WEBRTC_CHECK_CHANNEL(channel);
1061 scale = channels_[channel]->volume_scale;
1062 return 0;
1063 }
1064 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1065 WEBRTC_CHECK_CHANNEL(channel);
1066 channels_[channel]->volume_pan_left = left;
1067 channels_[channel]->volume_pan_right = right;
1068 return 0;
1069 }
1070 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1071 WEBRTC_CHECK_CHANNEL(channel);
1072 left = channels_[channel]->volume_pan_left;
1073 right = channels_[channel]->volume_pan_right;
1074 return 0;
1075 }
1076
1077 // webrtc::VoEAudioProcessing
1078 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1079 ns_enabled_ = enable;
1080 ns_mode_ = mode;
1081 return 0;
1082 }
1083 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1084 enabled = ns_enabled_;
1085 mode = ns_mode_;
1086 return 0;
1087 }
1088
1089 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1090 agc_enabled_ = enable;
1091 agc_mode_ = mode;
1092 return 0;
1093 }
1094 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1095 enabled = agc_enabled_;
1096 mode = agc_mode_;
1097 return 0;
1098 }
1099
1100 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1101 agc_config_ = config;
1102 return 0;
1103 }
1104 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1105 config = agc_config_;
1106 return 0;
1107 }
1108 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1109 ec_enabled_ = enable;
1110 ec_mode_ = mode;
1111 return 0;
1112 }
1113 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1114 enabled = ec_enabled_;
1115 mode = ec_mode_;
1116 return 0;
1117 }
1118 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1119 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1120 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1121 WEBRTC_STUB(DelayOffsetMs, ());
1122 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1123 aecm_mode_ = mode;
1124 cng_enabled_ = enableCNG;
1125 return 0;
1126 }
1127 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1128 mode = aecm_mode_;
1129 enabledCNG = cng_enabled_;
1130 return 0;
1131 }
1132 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1133 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1134 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001135 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1136 webrtc::AgcModes mode)) {
1137 channels_[channel]->rx_agc_enabled = enable;
1138 channels_[channel]->rx_agc_mode = mode;
1139 return 0;
1140 }
1141 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1142 webrtc::AgcModes& mode)) {
1143 enabled = channels_[channel]->rx_agc_enabled;
1144 mode = channels_[channel]->rx_agc_mode;
1145 return 0;
1146 }
1147
1148 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1149 channels_[channel]->rx_agc_config = config;
1150 return 0;
1151 }
1152 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1153 config = channels_[channel]->rx_agc_config;
1154 return 0;
1155 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156
1157 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1158 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1159 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1160 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1161 ec_metrics_enabled_ = enable;
1162 return 0;
1163 }
1164 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1165 enabled = ec_metrics_enabled_;
1166 return 0;
1167 }
1168 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001169 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1170 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001171
1172 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001173 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 WEBRTC_STUB(StopDebugRecording, ());
1175
1176 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1177 typing_detection_enabled_ = enable;
1178 return 0;
1179 }
1180 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1181 enabled = typing_detection_enabled_;
1182 return 0;
1183 }
1184
1185 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1186 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1187 int costPerTyping,
1188 int reportingThreshold,
1189 int penaltyDecay,
1190 int typeEventDelay));
1191 int EnableHighPassFilter(bool enable) {
1192 highpass_filter_enabled_ = enable;
1193 return 0;
1194 }
1195 bool IsHighPassFilterEnabled() {
1196 return highpass_filter_enabled_;
1197 }
1198 bool IsStereoChannelSwappingEnabled() {
1199 return stereo_swapping_enabled_;
1200 }
1201 void EnableStereoChannelSwapping(bool enable) {
1202 stereo_swapping_enabled_ = enable;
1203 }
1204 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1205 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1206 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1207 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1208 }
1209 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1210 return (dtmf_info_.dtmf_event_code == event_code &&
1211 dtmf_info_.dtmf_length_ms == length_ms);
1212 }
1213 // webrtc::VoEExternalMedia
1214 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1215 (int channel, webrtc::ProcessingTypes type,
1216 webrtc::VoEMediaProcess& processObject)) {
1217 WEBRTC_CHECK_CHANNEL(channel);
1218 if (channels_[channel]->media_processor_registered) {
1219 return -1;
1220 }
1221 channels_[channel]->media_processor_registered = true;
1222 media_processor_ = &processObject;
1223 return 0;
1224 }
1225 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1226 (int channel, webrtc::ProcessingTypes type)) {
1227 WEBRTC_CHECK_CHANNEL(channel);
1228 if (!channels_[channel]->media_processor_registered) {
1229 return -1;
1230 }
1231 channels_[channel]->media_processor_registered = false;
1232 media_processor_ = NULL;
1233 return 0;
1234 }
1235 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1236 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1237 WEBRTC_STUB(ExternalRecordingInsertData,
1238 (const int16_t speechData10ms[], int lengthSamples,
1239 int samplingFreqHz, int current_delay_ms));
1240 WEBRTC_STUB(ExternalPlayoutGetData,
1241 (int16_t speechData10ms[], int samplingFreqHz,
1242 int current_delay_ms, int& lengthSamples));
1243 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1244 webrtc::AudioFrame* frame));
1245 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1246
1247 private:
1248 int GetNumDevices(int& num) {
1249#ifdef WIN32
1250 num = 1;
1251#else
1252 // On non-Windows platforms VE adds a special entry for the default device,
1253 // so if there is one physical device then there are two entries in the
1254 // list.
1255 num = 2;
1256#endif
1257 return 0;
1258 }
1259
1260 int GetDeviceName(int i, char* name, char* guid) {
1261 const char *s;
1262#ifdef WIN32
1263 if (0 == i) {
1264 s = kFakeDeviceName;
1265 } else {
1266 return -1;
1267 }
1268#else
1269 // See comment above.
1270 if (0 == i) {
1271 s = kFakeDefaultDeviceName;
1272 } else if (1 == i) {
1273 s = kFakeDeviceName;
1274 } else {
1275 return -1;
1276 }
1277#endif
1278 strcpy(name, s);
1279 guid[0] = '\0';
1280 return 0;
1281 }
1282
1283 bool inited_;
1284 int last_channel_;
1285 std::map<int, Channel*> channels_;
1286 bool fail_create_channel_;
1287 const cricket::AudioCodec* const* codecs_;
1288 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001289 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 bool ec_enabled_;
1291 bool ec_metrics_enabled_;
1292 bool cng_enabled_;
1293 bool ns_enabled_;
1294 bool agc_enabled_;
1295 bool highpass_filter_enabled_;
1296 bool stereo_swapping_enabled_;
1297 bool typing_detection_enabled_;
1298 webrtc::EcModes ec_mode_;
1299 webrtc::AecmModes aecm_mode_;
1300 webrtc::NsModes ns_mode_;
1301 webrtc::AgcModes agc_mode_;
1302 webrtc::AgcConfig agc_config_;
1303 webrtc::VoiceEngineObserver* observer_;
1304 int playout_fail_channel_;
1305 int send_fail_channel_;
1306 bool fail_start_recording_microphone_;
1307 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001308 int recording_sample_rate_;
1309 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310 DtmfInfo dtmf_info_;
1311 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001312 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313};
1314
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001315#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1316
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317} // namespace cricket
1318
1319#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_