blob: 971f9f07c937c868e67925222589eb89148056cc [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 Lundin5263b3c2015-06-01 10:29:41 +0200219 neteq_capacity(-1),
220 neteq_fast_accelerate(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000222 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 }
224 bool external_transport;
225 bool send;
226 bool playout;
227 float volume_scale;
228 float volume_pan_left;
229 float volume_pan_right;
230 bool file;
231 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000232 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000233 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000234 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000235 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 bool nack;
237 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000238 bool rx_agc_enabled;
239 webrtc::AgcModes rx_agc_mode;
240 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 int cn8_type;
242 int cn16_type;
243 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000244 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 int nack_max_packets;
246 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000247 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000248 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000249 int send_absolute_sender_time_ext_;
250 int receive_absolute_sender_time_ext_;
Minyue2013aec2015-05-13 14:14:42 +0200251 int associate_send_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 DtmfInfo dtmf_info;
253 std::vector<webrtc::CodecInst> recv_codecs;
254 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000255 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 std::list<std::string> packets;
Henrik Lundin64dad832015-05-11 12:44:23 +0200257 int neteq_capacity;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200258 bool neteq_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 };
260
261 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
262 int num_codecs)
263 : inited_(false),
264 last_channel_(-1),
265 fail_create_channel_(false),
266 codecs_(codecs),
267 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000268 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 ec_enabled_(false),
270 ec_metrics_enabled_(false),
271 cng_enabled_(false),
272 ns_enabled_(false),
273 agc_enabled_(false),
274 highpass_filter_enabled_(false),
275 stereo_swapping_enabled_(false),
276 typing_detection_enabled_(false),
277 ec_mode_(webrtc::kEcDefault),
278 aecm_mode_(webrtc::kAecmSpeakerphone),
279 ns_mode_(webrtc::kNsDefault),
280 agc_mode_(webrtc::kAgcDefault),
281 observer_(NULL),
282 playout_fail_channel_(-1),
283 send_fail_channel_(-1),
284 fail_start_recording_microphone_(false),
285 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000286 recording_sample_rate_(-1),
287 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 media_processor_(NULL) {
289 memset(&agc_config_, 0, sizeof(agc_config_));
290 }
291 ~FakeWebRtcVoiceEngine() {
292 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
293 // destructors, but just in case ...
294 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
295 i != channels_.end(); ++i) {
296 delete i->second;
297 }
298 }
299
300 bool IsExternalMediaProcessorRegistered() const {
301 return media_processor_ != NULL;
302 }
303 bool IsInited() const { return inited_; }
304 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000305 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
306 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
307 iter != channels_.end(); ++iter) {
308 if (local_ssrc == iter->second->send_ssrc)
309 return iter->first;
310 }
311 return -1;
312 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000313 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 bool GetPlayout(int channel) {
315 return channels_[channel]->playout;
316 }
317 bool GetSend(int channel) {
318 return channels_[channel]->send;
319 }
320 bool GetRecordingMicrophone() {
321 return recording_microphone_;
322 }
323 bool GetVAD(int channel) {
324 return channels_[channel]->vad;
325 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100326 bool GetOpusDtx(int channel) {
327 return channels_[channel]->opus_dtx;
328 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000329 bool GetRED(int channel) {
330 return channels_[channel]->red;
331 }
332 bool GetCodecFEC(int channel) {
333 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000335 int GetMaxEncodingBandwidth(int channel) {
336 return channels_[channel]->max_encoding_bandwidth;
337 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 bool GetNACK(int channel) {
339 return channels_[channel]->nack;
340 }
341 int GetNACKMaxPackets(int channel) {
342 return channels_[channel]->nack_max_packets;
343 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000344 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
345 WEBRTC_ASSERT_CHANNEL(channel);
346 return channels_[channel]->last_rtp_packet_time;
347 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 int GetSendCNPayloadType(int channel, bool wideband) {
349 return (wideband) ?
350 channels_[channel]->cn16_type :
351 channels_[channel]->cn8_type;
352 }
353 int GetSendTelephoneEventPayloadType(int channel) {
354 return channels_[channel]->dtmf_type;
355 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000356 int GetSendREDPayloadType(int channel) {
357 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 }
359 bool CheckPacket(int channel, const void* data, size_t len) {
360 bool result = !CheckNoPacket(channel);
361 if (result) {
362 std::string packet = channels_[channel]->packets.front();
363 result = (packet == std::string(static_cast<const char*>(data), len));
364 channels_[channel]->packets.pop_front();
365 }
366 return result;
367 }
368 bool CheckNoPacket(int channel) {
369 return channels_[channel]->packets.empty();
370 }
371 void TriggerCallbackOnError(int channel_num, int err_code) {
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +0200372 DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 observer_->CallbackOnError(channel_num, err_code);
374 }
375 void set_playout_fail_channel(int channel) {
376 playout_fail_channel_ = channel;
377 }
378 void set_send_fail_channel(int channel) {
379 send_fail_channel_ = channel;
380 }
381 void set_fail_start_recording_microphone(
382 bool fail_start_recording_microphone) {
383 fail_start_recording_microphone_ = fail_start_recording_microphone;
384 }
385 void set_fail_create_channel(bool fail_create_channel) {
386 fail_create_channel_ = fail_create_channel;
387 }
388 void TriggerProcessPacket(MediaProcessorDirection direction) {
389 webrtc::ProcessingTypes pt =
390 (direction == cricket::MPD_TX) ?
391 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
392 if (media_processor_ != NULL) {
393 media_processor_->Process(0,
394 pt,
395 NULL,
396 0,
397 0,
398 true);
399 }
400 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200401 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000402 if (fail_create_channel_) {
403 return -1;
404 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000405 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000406 for (int i = 0; i < NumOfCodecs(); ++i) {
407 webrtc::CodecInst codec;
408 GetCodec(i, codec);
409 ch->recv_codecs.push_back(codec);
410 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200411 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
412 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
413 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200414 ch->neteq_fast_accelerate =
415 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000416 channels_[++last_channel_] = ch;
417 return last_channel_;
418 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000419 int GetSendRtpExtensionId(int channel, const std::string& extension) {
420 WEBRTC_ASSERT_CHANNEL(channel);
421 if (extension == kRtpAudioLevelHeaderExtension) {
422 return channels_[channel]->send_audio_level_ext_;
423 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
424 return channels_[channel]->send_absolute_sender_time_ext_;
425 }
426 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000427 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000428 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
429 WEBRTC_ASSERT_CHANNEL(channel);
430 if (extension == kRtpAudioLevelHeaderExtension) {
431 return channels_[channel]->receive_audio_level_ext_;
432 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
433 return channels_[channel]->receive_absolute_sender_time_ext_;
434 }
435 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000436 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000438 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
439
Minyue2013aec2015-05-13 14:14:42 +0200440 int GetAssociateSendChannel(int channel) {
441 return channels_[channel]->associate_send_channel;
442 }
443
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 WEBRTC_STUB(Release, ());
445
446 // webrtc::VoEBase
447 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
448 webrtc::VoiceEngineObserver& observer)) {
449 observer_ = &observer;
450 return 0;
451 }
452 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
453 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
454 webrtc::AudioProcessing* audioproc)) {
455 inited_ = true;
456 return 0;
457 }
458 WEBRTC_FUNC(Terminate, ()) {
459 inited_ = false;
460 return 0;
461 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000462 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000463 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200466 webrtc::Config empty_config;
467 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200469 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
470 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000471 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 WEBRTC_FUNC(DeleteChannel, (int channel)) {
473 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200474 for (const auto& ch : channels_) {
475 if (ch.second->associate_send_channel == channel) {
476 ch.second->associate_send_channel = -1;
477 }
478 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 delete channels_[channel];
480 channels_.erase(channel);
481 return 0;
482 }
483 WEBRTC_STUB(StartReceive, (int channel));
484 WEBRTC_FUNC(StartPlayout, (int channel)) {
485 if (playout_fail_channel_ != channel) {
486 WEBRTC_CHECK_CHANNEL(channel);
487 channels_[channel]->playout = true;
488 return 0;
489 } else {
490 // When playout_fail_channel_ == channel, fail the StartPlayout on this
491 // channel.
492 return -1;
493 }
494 }
495 WEBRTC_FUNC(StartSend, (int channel)) {
496 if (send_fail_channel_ != channel) {
497 WEBRTC_CHECK_CHANNEL(channel);
498 channels_[channel]->send = true;
499 return 0;
500 } else {
501 // When send_fail_channel_ == channel, fail the StartSend on this
502 // channel.
503 return -1;
504 }
505 }
506 WEBRTC_STUB(StopReceive, (int channel));
507 WEBRTC_FUNC(StopPlayout, (int channel)) {
508 WEBRTC_CHECK_CHANNEL(channel);
509 channels_[channel]->playout = false;
510 return 0;
511 }
512 WEBRTC_FUNC(StopSend, (int channel)) {
513 WEBRTC_CHECK_CHANNEL(channel);
514 channels_[channel]->send = false;
515 return 0;
516 }
517 WEBRTC_STUB(GetVersion, (char version[1024]));
518 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200519 WEBRTC_FUNC(AssociateSendChannel, (int channel,
520 int accociate_send_channel)) {
521 WEBRTC_CHECK_CHANNEL(channel);
522 channels_[channel]->associate_send_channel = accociate_send_channel;
523 return 0;
524 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000525
526 // webrtc::VoECodec
527 WEBRTC_FUNC(NumOfCodecs, ()) {
528 return num_codecs_;
529 }
530 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
531 if (index < 0 || index >= NumOfCodecs()) {
532 return -1;
533 }
534 const cricket::AudioCodec& c(*codecs_[index]);
535 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000536 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 codec.plfreq = c.clockrate;
538 codec.pacsize = 0;
539 codec.channels = c.channels;
540 codec.rate = c.bitrate;
541 return 0;
542 }
543 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
544 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000545 // To match the behavior of the real implementation.
546 if (_stricmp(codec.plname, "telephone-event") == 0 ||
547 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
548 _stricmp(codec.plname, "CN") == 0 ||
549 _stricmp(codec.plname, "red") == 0 ) {
550 return -1;
551 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000553 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 return 0;
555 }
556 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
557 WEBRTC_CHECK_CHANNEL(channel);
558 codec = channels_[channel]->send_codec;
559 return 0;
560 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200561 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000562 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
563 WEBRTC_CHECK_CHANNEL(channel);
564 const Channel* c = channels_[channel];
565 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
566 it_packet != c->packets.end(); ++it_packet) {
567 int pltype;
568 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
569 continue;
570 }
571 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
572 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
573 ++it_codec) {
574 if (it_codec->pltype == pltype) {
575 codec = *it_codec;
576 return 0;
577 }
578 }
579 }
580 return -1;
581 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 WEBRTC_FUNC(SetRecPayloadType, (int channel,
583 const webrtc::CodecInst& codec)) {
584 WEBRTC_CHECK_CHANNEL(channel);
585 Channel* ch = channels_[channel];
586 if (ch->playout)
587 return -1; // Channel is in use.
588 // Check if something else already has this slot.
589 if (codec.pltype != -1) {
590 for (std::vector<webrtc::CodecInst>::iterator it =
591 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
592 if (it->pltype == codec.pltype &&
593 _stricmp(it->plname, codec.plname) != 0) {
594 return -1;
595 }
596 }
597 }
598 // Otherwise try to find this codec and update its payload type.
599 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
600 it != ch->recv_codecs.end(); ++it) {
601 if (strcmp(it->plname, codec.plname) == 0 &&
602 it->plfreq == codec.plfreq) {
603 it->pltype = codec.pltype;
604 it->channels = codec.channels;
605 return 0;
606 }
607 }
608 return -1; // not found
609 }
610 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
611 webrtc::PayloadFrequencies frequency)) {
612 WEBRTC_CHECK_CHANNEL(channel);
613 if (frequency == webrtc::kFreq8000Hz) {
614 channels_[channel]->cn8_type = type;
615 } else if (frequency == webrtc::kFreq16000Hz) {
616 channels_[channel]->cn16_type = type;
617 }
618 return 0;
619 }
620 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
621 WEBRTC_CHECK_CHANNEL(channel);
622 Channel* ch = channels_[channel];
623 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
624 it != ch->recv_codecs.end(); ++it) {
625 if (strcmp(it->plname, codec.plname) == 0 &&
626 it->plfreq == codec.plfreq &&
627 it->channels == codec.channels &&
628 it->pltype != -1) {
629 codec.pltype = it->pltype;
630 return 0;
631 }
632 }
633 return -1; // not found
634 }
635 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
636 bool disableDTX)) {
637 WEBRTC_CHECK_CHANNEL(channel);
638 if (channels_[channel]->send_codec.channels == 2) {
639 // Replicating VoE behavior; VAD cannot be enabled for stereo.
640 return -1;
641 }
642 channels_[channel]->vad = enable;
643 return 0;
644 }
645 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
646 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000647
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000648 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
649 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000650 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000651 // Return -1 if current send codec is not Opus.
652 // TODO(minyue): Excludes other codecs if they support inband FEC.
653 return -1;
654 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000655 channels_[channel]->codec_fec = enable;
656 return 0;
657 }
658 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
659 WEBRTC_CHECK_CHANNEL(channel);
660 enable = channels_[channel]->codec_fec;
661 return 0;
662 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000663
664 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
665 WEBRTC_CHECK_CHANNEL(channel);
666 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
667 // Return -1 if current send codec is not Opus.
668 return -1;
669 }
670 if (frequency_hz <= 8000)
671 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
672 else if (frequency_hz <= 12000)
673 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
674 else if (frequency_hz <= 16000)
675 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
676 else if (frequency_hz <= 24000)
677 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
678 else
679 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
680 return 0;
681 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000683 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
684 WEBRTC_CHECK_CHANNEL(channel);
685 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
686 // Return -1 if current send codec is not Opus.
687 return -1;
688 }
689 channels_[channel]->opus_dtx = enable_dtx;
690 return 0;
691 }
692
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 // webrtc::VoEDtmf
694 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
695 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
696 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
697 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
698 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
699 return 0;
700 }
701
702 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
703 (int channel, unsigned char type)) {
704 channels_[channel]->dtmf_type = type;
705 return 0;
706 };
707 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
708 (int channel, unsigned char& type));
709
710 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
711 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 WEBRTC_FUNC(PlayDtmfTone,
714 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
715 dtmf_info_.dtmf_event_code = event_code;
716 dtmf_info_.dtmf_length_ms = length_ms;
717 return 0;
718 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719
720 // webrtc::VoEFile
721 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
722 bool loop, webrtc::FileFormats format,
723 float volumeScaling, int startPointMs,
724 int stopPointMs)) {
725 WEBRTC_CHECK_CHANNEL(channel);
726 channels_[channel]->file = true;
727 return 0;
728 }
729 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
730 webrtc::FileFormats format,
731 float volumeScaling, int startPointMs,
732 int stopPointMs)) {
733 WEBRTC_CHECK_CHANNEL(channel);
734 channels_[channel]->file = true;
735 return 0;
736 }
737 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
738 WEBRTC_CHECK_CHANNEL(channel);
739 channels_[channel]->file = false;
740 return 0;
741 }
742 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
743 WEBRTC_CHECK_CHANNEL(channel);
744 return (channels_[channel]->file) ? 1 : 0;
745 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
747 const char* fileNameUTF8,
748 bool loop,
749 bool mixWithMicrophone,
750 webrtc::FileFormats format,
751 float volumeScaling));
752 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
753 webrtc::InStream* stream,
754 bool mixWithMicrophone,
755 webrtc::FileFormats format,
756 float volumeScaling));
757 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
758 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
760 webrtc::CodecInst* compression,
761 int maxSizeBytes));
762 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
763 webrtc::CodecInst* compression));
764 WEBRTC_STUB(StopRecordingPlayout, (int channel));
765 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
766 webrtc::CodecInst* compression,
767 int maxSizeBytes)) {
768 if (fail_start_recording_microphone_) {
769 return -1;
770 }
771 recording_microphone_ = true;
772 return 0;
773 }
774 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
775 webrtc::CodecInst* compression)) {
776 if (fail_start_recording_microphone_) {
777 return -1;
778 }
779 recording_microphone_ = true;
780 return 0;
781 }
782 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
783 if (!recording_microphone_) {
784 return -1;
785 }
786 recording_microphone_ = false;
787 return 0;
788 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789
790 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
792 return GetNumDevices(num);
793 }
794 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
795 return GetNumDevices(num);
796 }
797 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
798 return GetDeviceName(i, name, guid);
799 }
800 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
801 return GetDeviceName(i, name, guid);
802 }
803 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
804 WEBRTC_STUB(SetPlayoutDevice, (int));
805 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
806 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000807 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
808 recording_sample_rate_ = samples_per_sec;
809 return 0;
810 }
811 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
812 *samples_per_sec = recording_sample_rate_;
813 return 0;
814 }
815 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
816 playout_sample_rate_ = samples_per_sec;
817 return 0;
818 }
819 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
820 *samples_per_sec = playout_sample_rate_;
821 return 0;
822 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000824 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825
826 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000827 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
828 webrtc::NetworkStatistics& ns)) {
829 WEBRTC_CHECK_CHANNEL(channel);
830 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
831 return 0;
832 }
833
wu@webrtc.org24301a62013-12-13 19:17:43 +0000834 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
835 webrtc::AudioDecodingCallStats*)) {
836 WEBRTC_CHECK_CHANNEL(channel);
837 return 0;
838 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839
840 // webrtc::VoENetwork
841 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
842 webrtc::Transport& transport)) {
843 WEBRTC_CHECK_CHANNEL(channel);
844 channels_[channel]->external_transport = true;
845 return 0;
846 }
847 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
848 WEBRTC_CHECK_CHANNEL(channel);
849 channels_[channel]->external_transport = false;
850 return 0;
851 }
852 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000853 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 WEBRTC_CHECK_CHANNEL(channel);
855 if (!channels_[channel]->external_transport) return -1;
856 channels_[channel]->packets.push_back(
857 std::string(static_cast<const char*>(data), length));
858 return 0;
859 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000860 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000861 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000862 const webrtc::PacketTime& packet_time)) {
863 WEBRTC_CHECK_CHANNEL(channel);
864 if (ReceivedRTPPacket(channel, data, length) == -1) {
865 return -1;
866 }
867 channels_[channel]->last_rtp_packet_time = packet_time;
868 return 0;
869 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000870
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000872 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873
874 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
876 WEBRTC_CHECK_CHANNEL(channel);
877 channels_[channel]->send_ssrc = ssrc;
878 return 0;
879 }
880 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
881 WEBRTC_CHECK_CHANNEL(channel);
882 ssrc = channels_[channel]->send_ssrc;
883 return 0;
884 }
885 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000886 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
887 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000889 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
890 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 return 0;
892 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000893 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
894 unsigned char id)) {
895 WEBRTC_CHECK_CHANNEL(channel);
896 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
897 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
898 return 0;
899 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000900 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
901 unsigned char id)) {
902 WEBRTC_CHECK_CHANNEL(channel);
903 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
904 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
905 return 0;
906 }
907 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
908 unsigned char id)) {
909 WEBRTC_CHECK_CHANNEL(channel);
910 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
911 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
912 return 0;
913 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000914
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
916 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
917 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
918 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
919 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
920 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
921 unsigned int& NTPLow,
922 unsigned int& timestamp,
923 unsigned int& playoutTimestamp,
924 unsigned int* jitter,
925 unsigned short* fractionLost));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
927 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
928 WEBRTC_CHECK_CHANNEL(channel);
929 webrtc::ReportBlock block;
930 block.source_SSRC = channels_[channel]->send_ssrc;
931 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
932 if (send_codec.pltype >= 0) {
933 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
934 if (send_codec.plfreq / 1000 > 0) {
935 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
936 }
937 block.cumulative_num_packets_lost = kIntStatValue;
938 block.extended_highest_sequence_number = kIntStatValue;
939 receive_blocks->push_back(block);
940 }
941 return 0;
942 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
944 unsigned int& maxJitterMs,
945 unsigned int& discardedPackets));
946 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
947 WEBRTC_CHECK_CHANNEL(channel);
948 stats.fractionLost = static_cast<int16>(kIntStatValue);
949 stats.cumulativeLost = kIntStatValue;
950 stats.extendedMax = kIntStatValue;
951 stats.jitterSamples = kIntStatValue;
952 stats.rttMs = kIntStatValue;
953 stats.bytesSent = kIntStatValue;
954 stats.packetsSent = kIntStatValue;
955 stats.bytesReceived = kIntStatValue;
956 stats.packetsReceived = kIntStatValue;
957 return 0;
958 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000959 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000960 return SetFECStatus(channel, enable, redPayloadtype);
961 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000962 // TODO(minyue): remove the below function when transition to SetREDStatus
963 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
965 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000966 channels_[channel]->red = enable;
967 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 return 0;
969 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000970 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000971 return GetFECStatus(channel, enable, redPayloadtype);
972 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000973 // TODO(minyue): remove the below function when transition to GetREDStatus
974 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
976 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000977 enable = channels_[channel]->red;
978 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 return 0;
980 }
981 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
982 WEBRTC_CHECK_CHANNEL(channel);
983 channels_[channel]->nack = enable;
984 channels_[channel]->nack_max_packets = maxNoPackets;
985 return 0;
986 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987
988 // webrtc::VoEVideoSync
989 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
990 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000991 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
993 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
994 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
995 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
996 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
997 int* playout_buffer_delay_ms));
998 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
999
1000 // webrtc::VoEVolumeControl
1001 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1002 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 WEBRTC_STUB(SetMicVolume, (unsigned int));
1004 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1005 WEBRTC_STUB(SetInputMute, (int, bool));
1006 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1008 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1009 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1010 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1011 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1012 WEBRTC_CHECK_CHANNEL(channel);
1013 channels_[channel]->volume_scale= scale;
1014 return 0;
1015 }
1016 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1017 WEBRTC_CHECK_CHANNEL(channel);
1018 scale = channels_[channel]->volume_scale;
1019 return 0;
1020 }
1021 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1022 WEBRTC_CHECK_CHANNEL(channel);
1023 channels_[channel]->volume_pan_left = left;
1024 channels_[channel]->volume_pan_right = right;
1025 return 0;
1026 }
1027 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1028 WEBRTC_CHECK_CHANNEL(channel);
1029 left = channels_[channel]->volume_pan_left;
1030 right = channels_[channel]->volume_pan_right;
1031 return 0;
1032 }
1033
1034 // webrtc::VoEAudioProcessing
1035 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1036 ns_enabled_ = enable;
1037 ns_mode_ = mode;
1038 return 0;
1039 }
1040 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1041 enabled = ns_enabled_;
1042 mode = ns_mode_;
1043 return 0;
1044 }
1045
1046 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1047 agc_enabled_ = enable;
1048 agc_mode_ = mode;
1049 return 0;
1050 }
1051 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1052 enabled = agc_enabled_;
1053 mode = agc_mode_;
1054 return 0;
1055 }
1056
1057 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1058 agc_config_ = config;
1059 return 0;
1060 }
1061 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1062 config = agc_config_;
1063 return 0;
1064 }
1065 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1066 ec_enabled_ = enable;
1067 ec_mode_ = mode;
1068 return 0;
1069 }
1070 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1071 enabled = ec_enabled_;
1072 mode = ec_mode_;
1073 return 0;
1074 }
1075 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1076 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1077 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1078 WEBRTC_STUB(DelayOffsetMs, ());
1079 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1080 aecm_mode_ = mode;
1081 cng_enabled_ = enableCNG;
1082 return 0;
1083 }
1084 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1085 mode = aecm_mode_;
1086 enabledCNG = cng_enabled_;
1087 return 0;
1088 }
1089 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1090 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1091 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001092 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1093 webrtc::AgcModes mode)) {
1094 channels_[channel]->rx_agc_enabled = enable;
1095 channels_[channel]->rx_agc_mode = mode;
1096 return 0;
1097 }
1098 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1099 webrtc::AgcModes& mode)) {
1100 enabled = channels_[channel]->rx_agc_enabled;
1101 mode = channels_[channel]->rx_agc_mode;
1102 return 0;
1103 }
1104
1105 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1106 channels_[channel]->rx_agc_config = config;
1107 return 0;
1108 }
1109 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1110 config = channels_[channel]->rx_agc_config;
1111 return 0;
1112 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113
1114 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1115 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1116 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1117 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1118 ec_metrics_enabled_ = enable;
1119 return 0;
1120 }
1121 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1122 enabled = ec_metrics_enabled_;
1123 return 0;
1124 }
1125 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001126 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1127 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128
1129 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001130 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 WEBRTC_STUB(StopDebugRecording, ());
1132
1133 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1134 typing_detection_enabled_ = enable;
1135 return 0;
1136 }
1137 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1138 enabled = typing_detection_enabled_;
1139 return 0;
1140 }
1141
1142 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1143 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1144 int costPerTyping,
1145 int reportingThreshold,
1146 int penaltyDecay,
1147 int typeEventDelay));
1148 int EnableHighPassFilter(bool enable) {
1149 highpass_filter_enabled_ = enable;
1150 return 0;
1151 }
1152 bool IsHighPassFilterEnabled() {
1153 return highpass_filter_enabled_;
1154 }
1155 bool IsStereoChannelSwappingEnabled() {
1156 return stereo_swapping_enabled_;
1157 }
1158 void EnableStereoChannelSwapping(bool enable) {
1159 stereo_swapping_enabled_ = enable;
1160 }
1161 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1162 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1163 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1164 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1165 }
1166 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1167 return (dtmf_info_.dtmf_event_code == event_code &&
1168 dtmf_info_.dtmf_length_ms == length_ms);
1169 }
1170 // webrtc::VoEExternalMedia
1171 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1172 (int channel, webrtc::ProcessingTypes type,
1173 webrtc::VoEMediaProcess& processObject)) {
1174 WEBRTC_CHECK_CHANNEL(channel);
1175 if (channels_[channel]->media_processor_registered) {
1176 return -1;
1177 }
1178 channels_[channel]->media_processor_registered = true;
1179 media_processor_ = &processObject;
1180 return 0;
1181 }
1182 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1183 (int channel, webrtc::ProcessingTypes type)) {
1184 WEBRTC_CHECK_CHANNEL(channel);
1185 if (!channels_[channel]->media_processor_registered) {
1186 return -1;
1187 }
1188 channels_[channel]->media_processor_registered = false;
1189 media_processor_ = NULL;
1190 return 0;
1191 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001192 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1193 webrtc::AudioFrame* frame));
1194 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
Henrik Lundin64dad832015-05-11 12:44:23 +02001195 int GetNetEqCapacity() const {
1196 auto ch = channels_.find(last_channel_);
1197 ASSERT(ch != channels_.end());
1198 return ch->second->neteq_capacity;
1199 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +02001200 bool GetNetEqFastAccelerate() const {
1201 auto ch = channels_.find(last_channel_);
1202 ASSERT(ch != channels_.end());
1203 return ch->second->neteq_fast_accelerate;
1204 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205
1206 private:
1207 int GetNumDevices(int& num) {
1208#ifdef WIN32
1209 num = 1;
1210#else
1211 // On non-Windows platforms VE adds a special entry for the default device,
1212 // so if there is one physical device then there are two entries in the
1213 // list.
1214 num = 2;
1215#endif
1216 return 0;
1217 }
1218
1219 int GetDeviceName(int i, char* name, char* guid) {
1220 const char *s;
1221#ifdef WIN32
1222 if (0 == i) {
1223 s = kFakeDeviceName;
1224 } else {
1225 return -1;
1226 }
1227#else
1228 // See comment above.
1229 if (0 == i) {
1230 s = kFakeDefaultDeviceName;
1231 } else if (1 == i) {
1232 s = kFakeDeviceName;
1233 } else {
1234 return -1;
1235 }
1236#endif
1237 strcpy(name, s);
1238 guid[0] = '\0';
1239 return 0;
1240 }
1241
1242 bool inited_;
1243 int last_channel_;
1244 std::map<int, Channel*> channels_;
1245 bool fail_create_channel_;
1246 const cricket::AudioCodec* const* codecs_;
1247 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001248 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 bool ec_enabled_;
1250 bool ec_metrics_enabled_;
1251 bool cng_enabled_;
1252 bool ns_enabled_;
1253 bool agc_enabled_;
1254 bool highpass_filter_enabled_;
1255 bool stereo_swapping_enabled_;
1256 bool typing_detection_enabled_;
1257 webrtc::EcModes ec_mode_;
1258 webrtc::AecmModes aecm_mode_;
1259 webrtc::NsModes ns_mode_;
1260 webrtc::AgcModes agc_mode_;
1261 webrtc::AgcConfig agc_config_;
1262 webrtc::VoiceEngineObserver* observer_;
1263 int playout_fail_channel_;
1264 int send_fail_channel_;
1265 bool fail_start_recording_microphone_;
1266 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001267 int recording_sample_rate_;
1268 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269 DtmfInfo dtmf_info_;
1270 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001271 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272};
1273
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001274#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1275
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276} // namespace cricket
1277
1278#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_