blob: 673e3e0acad5bdec16a6bd2dee7e3c7a2ba0fe1d [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"
Henrik Lundin64dad832015-05-11 12:44:23 +020044#include "webrtc/config.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000045#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000046
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047namespace cricket {
48
49// Function returning stats will return these values
50// for all values based on type.
51const int kIntStatValue = 123;
52const float kFractionLostStatValue = 0.5;
53
54static const char kFakeDefaultDeviceName[] = "Fake Default";
55static const int kFakeDefaultDeviceId = -1;
56static const char kFakeDeviceName[] = "Fake Device";
57#ifdef WIN32
58static const int kFakeDeviceId = 0;
59#else
60static const int kFakeDeviceId = 1;
61#endif
62
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000063static const int kOpusBandwidthNb = 4000;
64static const int kOpusBandwidthMb = 6000;
65static const int kOpusBandwidthWb = 8000;
66static const int kOpusBandwidthSwb = 12000;
67static const int kOpusBandwidthFb = 20000;
68
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +000069static const webrtc::NetworkStatistics kNetStats = {
70 1, // uint16_t currentBufferSize;
71 2, // uint16_t preferredBufferSize;
72 true, // bool jitterPeaksFound;
73 1234, // uint16_t currentPacketLossRate;
74 567, // uint16_t currentDiscardRate;
75 8901, // uint16_t currentExpandRate;
76 234, // uint16_t currentSpeechExpandRate;
77 5678, // uint16_t currentPreemptiveRate;
78 9012, // uint16_t currentAccelerateRate;
79 3456, // uint16_t currentSecondaryDecodedRate;
80 7890, // int32_t clockDriftPPM;
81 54, // meanWaitingTimeMs;
82 32, // int medianWaitingTimeMs;
83 1, // int minWaitingTimeMs;
84 98, // int maxWaitingTimeMs;
85 7654, // int addedSamples;
86}; // These random but non-trivial numbers are used for testing.
87
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020088#define WEBRTC_CHECK_CHANNEL(channel) \
89 if (channels_.find(channel) == channels_.end()) return -1;
90
91#define WEBRTC_ASSERT_CHANNEL(channel) \
92 DCHECK(channels_.find(channel) != channels_.end());
93
henrike@webrtc.org79047f92014-03-06 23:46:59 +000094// Verify the header extension ID, if enabled, is within the bounds specified in
95// [RFC5285]: 1-14 inclusive.
96#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
97 do { \
98 if (enable && (id < 1 || id > 14)) { \
99 return -1; \
100 } \
101 } while (0);
102
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000103class FakeAudioProcessing : public webrtc::AudioProcessing {
104 public:
105 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
106
107 WEBRTC_STUB(Initialize, ())
108 WEBRTC_STUB(Initialize, (
109 int input_sample_rate_hz,
110 int output_sample_rate_hz,
111 int reverse_sample_rate_hz,
112 webrtc::AudioProcessing::ChannelLayout input_layout,
113 webrtc::AudioProcessing::ChannelLayout output_layout,
114 webrtc::AudioProcessing::ChannelLayout reverse_layout));
115
116 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
117 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
118 }
119
120 WEBRTC_STUB(set_sample_rate_hz, (int rate));
121 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
122 WEBRTC_STUB_CONST(sample_rate_hz, ());
123 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
124 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
125 WEBRTC_STUB_CONST(num_input_channels, ());
126 WEBRTC_STUB_CONST(num_output_channels, ());
127 WEBRTC_STUB_CONST(num_reverse_channels, ());
128 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
129 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
130 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
131 WEBRTC_STUB(ProcessStream, (
132 const float* const* src,
133 int samples_per_channel,
134 int input_sample_rate_hz,
135 webrtc::AudioProcessing::ChannelLayout input_layout,
136 int output_sample_rate_hz,
137 webrtc::AudioProcessing::ChannelLayout output_layout,
138 float* const* dest));
139 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
140 WEBRTC_STUB(AnalyzeReverseStream, (
141 const float* const* data,
142 int samples_per_channel,
143 int sample_rate_hz,
144 webrtc::AudioProcessing::ChannelLayout layout));
145 WEBRTC_STUB(set_stream_delay_ms, (int delay));
146 WEBRTC_STUB_CONST(stream_delay_ms, ());
147 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
148 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
149 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
150 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
151 WEBRTC_STUB_CONST(delay_offset_ms, ());
152 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
153 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
154 WEBRTC_STUB(StopDebugRecording, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000155 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
156 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000157 return NULL;
158 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000159 webrtc::GainControl* gain_control() const override { return NULL; }
160 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
161 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
162 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
163 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000164
165 bool experimental_ns_enabled() {
166 return experimental_ns_enabled_;
167 }
168
169 private:
170 bool experimental_ns_enabled_;
171};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000172
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173class FakeWebRtcVoiceEngine
174 : public webrtc::VoEAudioProcessing,
175 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
176 public webrtc::VoEFile, public webrtc::VoEHardware,
177 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
178 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
179 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
180 public:
181 struct DtmfInfo {
182 DtmfInfo()
183 : dtmf_event_code(-1),
184 dtmf_out_of_band(false),
185 dtmf_length_ms(-1) {}
186 int dtmf_event_code;
187 bool dtmf_out_of_band;
188 int dtmf_length_ms;
189 };
190 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000191 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 : external_transport(false),
193 send(false),
194 playout(false),
195 volume_scale(1.0),
196 volume_pan_left(1.0),
197 volume_pan_right(1.0),
198 file(false),
199 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000200 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000201 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000202 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000203 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 nack(false),
205 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000206 rx_agc_enabled(false),
207 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 cn8_type(13),
209 cn16_type(105),
210 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000211 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 nack_max_packets(0),
213 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000214 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000215 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000216 send_absolute_sender_time_ext_(-1),
Henrik Lundin64dad832015-05-11 12:44:23 +0200217 receive_absolute_sender_time_ext_(-1),
Minyue2013aec2015-05-13 14:14:42 +0200218 associate_send_channel(-1),
Henrik Lundin64dad832015-05-11 12:44:23 +0200219 neteq_capacity(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000221 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 }
223 bool external_transport;
224 bool send;
225 bool playout;
226 float volume_scale;
227 float volume_pan_left;
228 float volume_pan_right;
229 bool file;
230 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000231 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000232 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000233 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000234 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 bool nack;
236 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000237 bool rx_agc_enabled;
238 webrtc::AgcModes rx_agc_mode;
239 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 int cn8_type;
241 int cn16_type;
242 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000243 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 int nack_max_packets;
245 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000246 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000247 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000248 int send_absolute_sender_time_ext_;
249 int receive_absolute_sender_time_ext_;
Minyue2013aec2015-05-13 14:14:42 +0200250 int associate_send_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 DtmfInfo dtmf_info;
252 std::vector<webrtc::CodecInst> recv_codecs;
253 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000254 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 std::list<std::string> packets;
Henrik Lundin64dad832015-05-11 12:44:23 +0200256 int neteq_capacity;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 };
258
259 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
260 int num_codecs)
261 : inited_(false),
262 last_channel_(-1),
263 fail_create_channel_(false),
264 codecs_(codecs),
265 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000266 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000267 ec_enabled_(false),
268 ec_metrics_enabled_(false),
269 cng_enabled_(false),
270 ns_enabled_(false),
271 agc_enabled_(false),
272 highpass_filter_enabled_(false),
273 stereo_swapping_enabled_(false),
274 typing_detection_enabled_(false),
275 ec_mode_(webrtc::kEcDefault),
276 aecm_mode_(webrtc::kAecmSpeakerphone),
277 ns_mode_(webrtc::kNsDefault),
278 agc_mode_(webrtc::kAgcDefault),
279 observer_(NULL),
280 playout_fail_channel_(-1),
281 send_fail_channel_(-1),
282 fail_start_recording_microphone_(false),
283 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000284 recording_sample_rate_(-1),
285 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 media_processor_(NULL) {
287 memset(&agc_config_, 0, sizeof(agc_config_));
288 }
289 ~FakeWebRtcVoiceEngine() {
290 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
291 // destructors, but just in case ...
292 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
293 i != channels_.end(); ++i) {
294 delete i->second;
295 }
296 }
297
298 bool IsExternalMediaProcessorRegistered() const {
299 return media_processor_ != NULL;
300 }
301 bool IsInited() const { return inited_; }
302 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000303 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
304 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
305 iter != channels_.end(); ++iter) {
306 if (local_ssrc == iter->second->send_ssrc)
307 return iter->first;
308 }
309 return -1;
310 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000311 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 bool GetPlayout(int channel) {
313 return channels_[channel]->playout;
314 }
315 bool GetSend(int channel) {
316 return channels_[channel]->send;
317 }
318 bool GetRecordingMicrophone() {
319 return recording_microphone_;
320 }
321 bool GetVAD(int channel) {
322 return channels_[channel]->vad;
323 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100324 bool GetOpusDtx(int channel) {
325 return channels_[channel]->opus_dtx;
326 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000327 bool GetRED(int channel) {
328 return channels_[channel]->red;
329 }
330 bool GetCodecFEC(int channel) {
331 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000333 int GetMaxEncodingBandwidth(int channel) {
334 return channels_[channel]->max_encoding_bandwidth;
335 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 bool GetNACK(int channel) {
337 return channels_[channel]->nack;
338 }
339 int GetNACKMaxPackets(int channel) {
340 return channels_[channel]->nack_max_packets;
341 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000342 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
343 WEBRTC_ASSERT_CHANNEL(channel);
344 return channels_[channel]->last_rtp_packet_time;
345 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 int GetSendCNPayloadType(int channel, bool wideband) {
347 return (wideband) ?
348 channels_[channel]->cn16_type :
349 channels_[channel]->cn8_type;
350 }
351 int GetSendTelephoneEventPayloadType(int channel) {
352 return channels_[channel]->dtmf_type;
353 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000354 int GetSendREDPayloadType(int channel) {
355 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 }
357 bool CheckPacket(int channel, const void* data, size_t len) {
358 bool result = !CheckNoPacket(channel);
359 if (result) {
360 std::string packet = channels_[channel]->packets.front();
361 result = (packet == std::string(static_cast<const char*>(data), len));
362 channels_[channel]->packets.pop_front();
363 }
364 return result;
365 }
366 bool CheckNoPacket(int channel) {
367 return channels_[channel]->packets.empty();
368 }
369 void TriggerCallbackOnError(int channel_num, int err_code) {
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +0200370 DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 observer_->CallbackOnError(channel_num, err_code);
372 }
373 void set_playout_fail_channel(int channel) {
374 playout_fail_channel_ = channel;
375 }
376 void set_send_fail_channel(int channel) {
377 send_fail_channel_ = channel;
378 }
379 void set_fail_start_recording_microphone(
380 bool fail_start_recording_microphone) {
381 fail_start_recording_microphone_ = fail_start_recording_microphone;
382 }
383 void set_fail_create_channel(bool fail_create_channel) {
384 fail_create_channel_ = fail_create_channel;
385 }
386 void TriggerProcessPacket(MediaProcessorDirection direction) {
387 webrtc::ProcessingTypes pt =
388 (direction == cricket::MPD_TX) ?
389 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
390 if (media_processor_ != NULL) {
391 media_processor_->Process(0,
392 pt,
393 NULL,
394 0,
395 0,
396 true);
397 }
398 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200399 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000400 if (fail_create_channel_) {
401 return -1;
402 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000403 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000404 for (int i = 0; i < NumOfCodecs(); ++i) {
405 webrtc::CodecInst codec;
406 GetCodec(i, codec);
407 ch->recv_codecs.push_back(codec);
408 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200409 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
410 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
411 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000412 channels_[++last_channel_] = ch;
413 return last_channel_;
414 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000415 int GetSendRtpExtensionId(int channel, const std::string& extension) {
416 WEBRTC_ASSERT_CHANNEL(channel);
417 if (extension == kRtpAudioLevelHeaderExtension) {
418 return channels_[channel]->send_audio_level_ext_;
419 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
420 return channels_[channel]->send_absolute_sender_time_ext_;
421 }
422 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000423 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000424 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
425 WEBRTC_ASSERT_CHANNEL(channel);
426 if (extension == kRtpAudioLevelHeaderExtension) {
427 return channels_[channel]->receive_audio_level_ext_;
428 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
429 return channels_[channel]->receive_absolute_sender_time_ext_;
430 }
431 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000432 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000434 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
435
Minyue2013aec2015-05-13 14:14:42 +0200436 int GetAssociateSendChannel(int channel) {
437 return channels_[channel]->associate_send_channel;
438 }
439
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 WEBRTC_STUB(Release, ());
441
442 // webrtc::VoEBase
443 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
444 webrtc::VoiceEngineObserver& observer)) {
445 observer_ = &observer;
446 return 0;
447 }
448 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
449 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
450 webrtc::AudioProcessing* audioproc)) {
451 inited_ = true;
452 return 0;
453 }
454 WEBRTC_FUNC(Terminate, ()) {
455 inited_ = false;
456 return 0;
457 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000458 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000459 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200462 webrtc::Config empty_config;
463 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200465 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
466 return AddChannel(config);
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);
Minyue2013aec2015-05-13 14:14:42 +0200470 for (const auto& ch : channels_) {
471 if (ch.second->associate_send_channel == channel) {
472 ch.second->associate_send_channel = -1;
473 }
474 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 delete channels_[channel];
476 channels_.erase(channel);
477 return 0;
478 }
479 WEBRTC_STUB(StartReceive, (int channel));
480 WEBRTC_FUNC(StartPlayout, (int channel)) {
481 if (playout_fail_channel_ != channel) {
482 WEBRTC_CHECK_CHANNEL(channel);
483 channels_[channel]->playout = true;
484 return 0;
485 } else {
486 // When playout_fail_channel_ == channel, fail the StartPlayout on this
487 // channel.
488 return -1;
489 }
490 }
491 WEBRTC_FUNC(StartSend, (int channel)) {
492 if (send_fail_channel_ != channel) {
493 WEBRTC_CHECK_CHANNEL(channel);
494 channels_[channel]->send = true;
495 return 0;
496 } else {
497 // When send_fail_channel_ == channel, fail the StartSend on this
498 // channel.
499 return -1;
500 }
501 }
502 WEBRTC_STUB(StopReceive, (int channel));
503 WEBRTC_FUNC(StopPlayout, (int channel)) {
504 WEBRTC_CHECK_CHANNEL(channel);
505 channels_[channel]->playout = false;
506 return 0;
507 }
508 WEBRTC_FUNC(StopSend, (int channel)) {
509 WEBRTC_CHECK_CHANNEL(channel);
510 channels_[channel]->send = false;
511 return 0;
512 }
513 WEBRTC_STUB(GetVersion, (char version[1024]));
514 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200515 WEBRTC_FUNC(AssociateSendChannel, (int channel,
516 int accociate_send_channel)) {
517 WEBRTC_CHECK_CHANNEL(channel);
518 channels_[channel]->associate_send_channel = accociate_send_channel;
519 return 0;
520 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521
522 // webrtc::VoECodec
523 WEBRTC_FUNC(NumOfCodecs, ()) {
524 return num_codecs_;
525 }
526 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
527 if (index < 0 || index >= NumOfCodecs()) {
528 return -1;
529 }
530 const cricket::AudioCodec& c(*codecs_[index]);
531 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000532 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 codec.plfreq = c.clockrate;
534 codec.pacsize = 0;
535 codec.channels = c.channels;
536 codec.rate = c.bitrate;
537 return 0;
538 }
539 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
540 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000541 // To match the behavior of the real implementation.
542 if (_stricmp(codec.plname, "telephone-event") == 0 ||
543 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
544 _stricmp(codec.plname, "CN") == 0 ||
545 _stricmp(codec.plname, "red") == 0 ) {
546 return -1;
547 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000549 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 return 0;
551 }
552 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
553 WEBRTC_CHECK_CHANNEL(channel);
554 codec = channels_[channel]->send_codec;
555 return 0;
556 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200557 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000558 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
559 WEBRTC_CHECK_CHANNEL(channel);
560 const Channel* c = channels_[channel];
561 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
562 it_packet != c->packets.end(); ++it_packet) {
563 int pltype;
564 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
565 continue;
566 }
567 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
568 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
569 ++it_codec) {
570 if (it_codec->pltype == pltype) {
571 codec = *it_codec;
572 return 0;
573 }
574 }
575 }
576 return -1;
577 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 WEBRTC_FUNC(SetRecPayloadType, (int channel,
579 const webrtc::CodecInst& codec)) {
580 WEBRTC_CHECK_CHANNEL(channel);
581 Channel* ch = channels_[channel];
582 if (ch->playout)
583 return -1; // Channel is in use.
584 // Check if something else already has this slot.
585 if (codec.pltype != -1) {
586 for (std::vector<webrtc::CodecInst>::iterator it =
587 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
588 if (it->pltype == codec.pltype &&
589 _stricmp(it->plname, codec.plname) != 0) {
590 return -1;
591 }
592 }
593 }
594 // Otherwise try to find this codec and update its payload type.
595 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
596 it != ch->recv_codecs.end(); ++it) {
597 if (strcmp(it->plname, codec.plname) == 0 &&
598 it->plfreq == codec.plfreq) {
599 it->pltype = codec.pltype;
600 it->channels = codec.channels;
601 return 0;
602 }
603 }
604 return -1; // not found
605 }
606 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
607 webrtc::PayloadFrequencies frequency)) {
608 WEBRTC_CHECK_CHANNEL(channel);
609 if (frequency == webrtc::kFreq8000Hz) {
610 channels_[channel]->cn8_type = type;
611 } else if (frequency == webrtc::kFreq16000Hz) {
612 channels_[channel]->cn16_type = type;
613 }
614 return 0;
615 }
616 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
617 WEBRTC_CHECK_CHANNEL(channel);
618 Channel* ch = channels_[channel];
619 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
620 it != ch->recv_codecs.end(); ++it) {
621 if (strcmp(it->plname, codec.plname) == 0 &&
622 it->plfreq == codec.plfreq &&
623 it->channels == codec.channels &&
624 it->pltype != -1) {
625 codec.pltype = it->pltype;
626 return 0;
627 }
628 }
629 return -1; // not found
630 }
631 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
632 bool disableDTX)) {
633 WEBRTC_CHECK_CHANNEL(channel);
634 if (channels_[channel]->send_codec.channels == 2) {
635 // Replicating VoE behavior; VAD cannot be enabled for stereo.
636 return -1;
637 }
638 channels_[channel]->vad = enable;
639 return 0;
640 }
641 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
642 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000643
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000644 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
645 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000646 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000647 // Return -1 if current send codec is not Opus.
648 // TODO(minyue): Excludes other codecs if they support inband FEC.
649 return -1;
650 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000651 channels_[channel]->codec_fec = enable;
652 return 0;
653 }
654 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
655 WEBRTC_CHECK_CHANNEL(channel);
656 enable = channels_[channel]->codec_fec;
657 return 0;
658 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000659
660 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
661 WEBRTC_CHECK_CHANNEL(channel);
662 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
663 // Return -1 if current send codec is not Opus.
664 return -1;
665 }
666 if (frequency_hz <= 8000)
667 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
668 else if (frequency_hz <= 12000)
669 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
670 else if (frequency_hz <= 16000)
671 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
672 else if (frequency_hz <= 24000)
673 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
674 else
675 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
676 return 0;
677 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000679 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
680 WEBRTC_CHECK_CHANNEL(channel);
681 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
682 // Return -1 if current send codec is not Opus.
683 return -1;
684 }
685 channels_[channel]->opus_dtx = enable_dtx;
686 return 0;
687 }
688
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 // webrtc::VoEDtmf
690 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
691 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
692 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
693 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
694 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
695 return 0;
696 }
697
698 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
699 (int channel, unsigned char type)) {
700 channels_[channel]->dtmf_type = type;
701 return 0;
702 };
703 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
704 (int channel, unsigned char& type));
705
706 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
707 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 WEBRTC_FUNC(PlayDtmfTone,
710 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
711 dtmf_info_.dtmf_event_code = event_code;
712 dtmf_info_.dtmf_length_ms = length_ms;
713 return 0;
714 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715
716 // webrtc::VoEFile
717 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
718 bool loop, webrtc::FileFormats format,
719 float volumeScaling, int startPointMs,
720 int stopPointMs)) {
721 WEBRTC_CHECK_CHANNEL(channel);
722 channels_[channel]->file = true;
723 return 0;
724 }
725 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
726 webrtc::FileFormats format,
727 float volumeScaling, int startPointMs,
728 int stopPointMs)) {
729 WEBRTC_CHECK_CHANNEL(channel);
730 channels_[channel]->file = true;
731 return 0;
732 }
733 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
734 WEBRTC_CHECK_CHANNEL(channel);
735 channels_[channel]->file = false;
736 return 0;
737 }
738 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
739 WEBRTC_CHECK_CHANNEL(channel);
740 return (channels_[channel]->file) ? 1 : 0;
741 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
743 const char* fileNameUTF8,
744 bool loop,
745 bool mixWithMicrophone,
746 webrtc::FileFormats format,
747 float volumeScaling));
748 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
749 webrtc::InStream* stream,
750 bool mixWithMicrophone,
751 webrtc::FileFormats format,
752 float volumeScaling));
753 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
754 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
756 webrtc::CodecInst* compression,
757 int maxSizeBytes));
758 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
759 webrtc::CodecInst* compression));
760 WEBRTC_STUB(StopRecordingPlayout, (int channel));
761 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
762 webrtc::CodecInst* compression,
763 int maxSizeBytes)) {
764 if (fail_start_recording_microphone_) {
765 return -1;
766 }
767 recording_microphone_ = true;
768 return 0;
769 }
770 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
771 webrtc::CodecInst* compression)) {
772 if (fail_start_recording_microphone_) {
773 return -1;
774 }
775 recording_microphone_ = true;
776 return 0;
777 }
778 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
779 if (!recording_microphone_) {
780 return -1;
781 }
782 recording_microphone_ = false;
783 return 0;
784 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785
786 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
788 return GetNumDevices(num);
789 }
790 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
791 return GetNumDevices(num);
792 }
793 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
794 return GetDeviceName(i, name, guid);
795 }
796 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
797 return GetDeviceName(i, name, guid);
798 }
799 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
800 WEBRTC_STUB(SetPlayoutDevice, (int));
801 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
802 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000803 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
804 recording_sample_rate_ = samples_per_sec;
805 return 0;
806 }
807 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
808 *samples_per_sec = recording_sample_rate_;
809 return 0;
810 }
811 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
812 playout_sample_rate_ = samples_per_sec;
813 return 0;
814 }
815 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
816 *samples_per_sec = playout_sample_rate_;
817 return 0;
818 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000820 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821
822 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000823 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
824 webrtc::NetworkStatistics& ns)) {
825 WEBRTC_CHECK_CHANNEL(channel);
826 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
827 return 0;
828 }
829
wu@webrtc.org24301a62013-12-13 19:17:43 +0000830 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
831 webrtc::AudioDecodingCallStats*)) {
832 WEBRTC_CHECK_CHANNEL(channel);
833 return 0;
834 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835
836 // webrtc::VoENetwork
837 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
838 webrtc::Transport& transport)) {
839 WEBRTC_CHECK_CHANNEL(channel);
840 channels_[channel]->external_transport = true;
841 return 0;
842 }
843 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
844 WEBRTC_CHECK_CHANNEL(channel);
845 channels_[channel]->external_transport = false;
846 return 0;
847 }
848 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000849 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 WEBRTC_CHECK_CHANNEL(channel);
851 if (!channels_[channel]->external_transport) return -1;
852 channels_[channel]->packets.push_back(
853 std::string(static_cast<const char*>(data), length));
854 return 0;
855 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000856 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000857 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000858 const webrtc::PacketTime& packet_time)) {
859 WEBRTC_CHECK_CHANNEL(channel);
860 if (ReceivedRTPPacket(channel, data, length) == -1) {
861 return -1;
862 }
863 channels_[channel]->last_rtp_packet_time = packet_time;
864 return 0;
865 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000866
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000868 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869
870 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
872 WEBRTC_CHECK_CHANNEL(channel);
873 channels_[channel]->send_ssrc = ssrc;
874 return 0;
875 }
876 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
877 WEBRTC_CHECK_CHANNEL(channel);
878 ssrc = channels_[channel]->send_ssrc;
879 return 0;
880 }
881 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000882 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
883 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000885 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
886 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 return 0;
888 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000889 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
890 unsigned char id)) {
891 WEBRTC_CHECK_CHANNEL(channel);
892 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
893 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
894 return 0;
895 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000896 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
897 unsigned char id)) {
898 WEBRTC_CHECK_CHANNEL(channel);
899 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
900 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
901 return 0;
902 }
903 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
904 unsigned char id)) {
905 WEBRTC_CHECK_CHANNEL(channel);
906 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
907 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
908 return 0;
909 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000910
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
912 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
913 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
914 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
915 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
916 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
917 unsigned int& NTPLow,
918 unsigned int& timestamp,
919 unsigned int& playoutTimestamp,
920 unsigned int* jitter,
921 unsigned short* fractionLost));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
923 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
924 WEBRTC_CHECK_CHANNEL(channel);
925 webrtc::ReportBlock block;
926 block.source_SSRC = channels_[channel]->send_ssrc;
927 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
928 if (send_codec.pltype >= 0) {
929 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
930 if (send_codec.plfreq / 1000 > 0) {
931 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
932 }
933 block.cumulative_num_packets_lost = kIntStatValue;
934 block.extended_highest_sequence_number = kIntStatValue;
935 receive_blocks->push_back(block);
936 }
937 return 0;
938 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
940 unsigned int& maxJitterMs,
941 unsigned int& discardedPackets));
942 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
943 WEBRTC_CHECK_CHANNEL(channel);
944 stats.fractionLost = static_cast<int16>(kIntStatValue);
945 stats.cumulativeLost = kIntStatValue;
946 stats.extendedMax = kIntStatValue;
947 stats.jitterSamples = kIntStatValue;
948 stats.rttMs = kIntStatValue;
949 stats.bytesSent = kIntStatValue;
950 stats.packetsSent = kIntStatValue;
951 stats.bytesReceived = kIntStatValue;
952 stats.packetsReceived = kIntStatValue;
953 return 0;
954 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000955 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000956 return SetFECStatus(channel, enable, redPayloadtype);
957 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000958 // TODO(minyue): remove the below function when transition to SetREDStatus
959 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
961 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000962 channels_[channel]->red = enable;
963 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 return 0;
965 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000966 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000967 return GetFECStatus(channel, enable, redPayloadtype);
968 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000969 // TODO(minyue): remove the below function when transition to GetREDStatus
970 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
972 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000973 enable = channels_[channel]->red;
974 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 return 0;
976 }
977 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
978 WEBRTC_CHECK_CHANNEL(channel);
979 channels_[channel]->nack = enable;
980 channels_[channel]->nack_max_packets = maxNoPackets;
981 return 0;
982 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983
984 // webrtc::VoEVideoSync
985 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
986 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000987 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
989 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
990 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
991 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
992 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
993 int* playout_buffer_delay_ms));
994 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
995
996 // webrtc::VoEVolumeControl
997 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
998 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 WEBRTC_STUB(SetMicVolume, (unsigned int));
1000 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1001 WEBRTC_STUB(SetInputMute, (int, bool));
1002 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1004 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1005 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1006 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1007 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1008 WEBRTC_CHECK_CHANNEL(channel);
1009 channels_[channel]->volume_scale= scale;
1010 return 0;
1011 }
1012 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1013 WEBRTC_CHECK_CHANNEL(channel);
1014 scale = channels_[channel]->volume_scale;
1015 return 0;
1016 }
1017 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1018 WEBRTC_CHECK_CHANNEL(channel);
1019 channels_[channel]->volume_pan_left = left;
1020 channels_[channel]->volume_pan_right = right;
1021 return 0;
1022 }
1023 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1024 WEBRTC_CHECK_CHANNEL(channel);
1025 left = channels_[channel]->volume_pan_left;
1026 right = channels_[channel]->volume_pan_right;
1027 return 0;
1028 }
1029
1030 // webrtc::VoEAudioProcessing
1031 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1032 ns_enabled_ = enable;
1033 ns_mode_ = mode;
1034 return 0;
1035 }
1036 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1037 enabled = ns_enabled_;
1038 mode = ns_mode_;
1039 return 0;
1040 }
1041
1042 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1043 agc_enabled_ = enable;
1044 agc_mode_ = mode;
1045 return 0;
1046 }
1047 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1048 enabled = agc_enabled_;
1049 mode = agc_mode_;
1050 return 0;
1051 }
1052
1053 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1054 agc_config_ = config;
1055 return 0;
1056 }
1057 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1058 config = agc_config_;
1059 return 0;
1060 }
1061 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1062 ec_enabled_ = enable;
1063 ec_mode_ = mode;
1064 return 0;
1065 }
1066 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1067 enabled = ec_enabled_;
1068 mode = ec_mode_;
1069 return 0;
1070 }
1071 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1072 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1073 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1074 WEBRTC_STUB(DelayOffsetMs, ());
1075 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1076 aecm_mode_ = mode;
1077 cng_enabled_ = enableCNG;
1078 return 0;
1079 }
1080 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1081 mode = aecm_mode_;
1082 enabledCNG = cng_enabled_;
1083 return 0;
1084 }
1085 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1086 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1087 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001088 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1089 webrtc::AgcModes mode)) {
1090 channels_[channel]->rx_agc_enabled = enable;
1091 channels_[channel]->rx_agc_mode = mode;
1092 return 0;
1093 }
1094 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1095 webrtc::AgcModes& mode)) {
1096 enabled = channels_[channel]->rx_agc_enabled;
1097 mode = channels_[channel]->rx_agc_mode;
1098 return 0;
1099 }
1100
1101 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1102 channels_[channel]->rx_agc_config = config;
1103 return 0;
1104 }
1105 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1106 config = channels_[channel]->rx_agc_config;
1107 return 0;
1108 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109
1110 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1111 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1112 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1113 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1114 ec_metrics_enabled_ = enable;
1115 return 0;
1116 }
1117 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1118 enabled = ec_metrics_enabled_;
1119 return 0;
1120 }
1121 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001122 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1123 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124
1125 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001126 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 WEBRTC_STUB(StopDebugRecording, ());
1128
1129 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1130 typing_detection_enabled_ = enable;
1131 return 0;
1132 }
1133 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1134 enabled = typing_detection_enabled_;
1135 return 0;
1136 }
1137
1138 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1139 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1140 int costPerTyping,
1141 int reportingThreshold,
1142 int penaltyDecay,
1143 int typeEventDelay));
1144 int EnableHighPassFilter(bool enable) {
1145 highpass_filter_enabled_ = enable;
1146 return 0;
1147 }
1148 bool IsHighPassFilterEnabled() {
1149 return highpass_filter_enabled_;
1150 }
1151 bool IsStereoChannelSwappingEnabled() {
1152 return stereo_swapping_enabled_;
1153 }
1154 void EnableStereoChannelSwapping(bool enable) {
1155 stereo_swapping_enabled_ = enable;
1156 }
1157 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1158 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1159 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1160 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1161 }
1162 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1163 return (dtmf_info_.dtmf_event_code == event_code &&
1164 dtmf_info_.dtmf_length_ms == length_ms);
1165 }
1166 // webrtc::VoEExternalMedia
1167 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1168 (int channel, webrtc::ProcessingTypes type,
1169 webrtc::VoEMediaProcess& processObject)) {
1170 WEBRTC_CHECK_CHANNEL(channel);
1171 if (channels_[channel]->media_processor_registered) {
1172 return -1;
1173 }
1174 channels_[channel]->media_processor_registered = true;
1175 media_processor_ = &processObject;
1176 return 0;
1177 }
1178 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1179 (int channel, webrtc::ProcessingTypes type)) {
1180 WEBRTC_CHECK_CHANNEL(channel);
1181 if (!channels_[channel]->media_processor_registered) {
1182 return -1;
1183 }
1184 channels_[channel]->media_processor_registered = false;
1185 media_processor_ = NULL;
1186 return 0;
1187 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001188 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1189 webrtc::AudioFrame* frame));
1190 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
Henrik Lundin64dad832015-05-11 12:44:23 +02001191 int GetNetEqCapacity() const {
1192 auto ch = channels_.find(last_channel_);
1193 ASSERT(ch != channels_.end());
1194 return ch->second->neteq_capacity;
1195 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001196
1197 private:
1198 int GetNumDevices(int& num) {
1199#ifdef WIN32
1200 num = 1;
1201#else
1202 // On non-Windows platforms VE adds a special entry for the default device,
1203 // so if there is one physical device then there are two entries in the
1204 // list.
1205 num = 2;
1206#endif
1207 return 0;
1208 }
1209
1210 int GetDeviceName(int i, char* name, char* guid) {
1211 const char *s;
1212#ifdef WIN32
1213 if (0 == i) {
1214 s = kFakeDeviceName;
1215 } else {
1216 return -1;
1217 }
1218#else
1219 // See comment above.
1220 if (0 == i) {
1221 s = kFakeDefaultDeviceName;
1222 } else if (1 == i) {
1223 s = kFakeDeviceName;
1224 } else {
1225 return -1;
1226 }
1227#endif
1228 strcpy(name, s);
1229 guid[0] = '\0';
1230 return 0;
1231 }
1232
1233 bool inited_;
1234 int last_channel_;
1235 std::map<int, Channel*> channels_;
1236 bool fail_create_channel_;
1237 const cricket::AudioCodec* const* codecs_;
1238 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001239 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 bool ec_enabled_;
1241 bool ec_metrics_enabled_;
1242 bool cng_enabled_;
1243 bool ns_enabled_;
1244 bool agc_enabled_;
1245 bool highpass_filter_enabled_;
1246 bool stereo_swapping_enabled_;
1247 bool typing_detection_enabled_;
1248 webrtc::EcModes ec_mode_;
1249 webrtc::AecmModes aecm_mode_;
1250 webrtc::NsModes ns_mode_;
1251 webrtc::AgcModes agc_mode_;
1252 webrtc::AgcConfig agc_config_;
1253 webrtc::VoiceEngineObserver* observer_;
1254 int playout_fail_channel_;
1255 int send_fail_channel_;
1256 bool fail_start_recording_microphone_;
1257 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001258 int recording_sample_rate_;
1259 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 DtmfInfo dtmf_info_;
1261 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001262 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263};
1264
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001265#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1266
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267} // namespace cricket
1268
1269#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_