blob: 3ac2f3bff3808657594d85323534001cefb96d2a [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));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700115 WEBRTC_STUB(Initialize, (
116 const webrtc::ProcessingConfig& processing_config));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000117
118 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
119 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
120 }
121
122 WEBRTC_STUB(set_sample_rate_hz, (int rate));
123 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
124 WEBRTC_STUB_CONST(sample_rate_hz, ());
125 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
126 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
127 WEBRTC_STUB_CONST(num_input_channels, ());
128 WEBRTC_STUB_CONST(num_output_channels, ());
129 WEBRTC_STUB_CONST(num_reverse_channels, ());
130 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
131 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
132 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
133 WEBRTC_STUB(ProcessStream, (
134 const float* const* src,
135 int samples_per_channel,
136 int input_sample_rate_hz,
137 webrtc::AudioProcessing::ChannelLayout input_layout,
138 int output_sample_rate_hz,
139 webrtc::AudioProcessing::ChannelLayout output_layout,
140 float* const* dest));
Michael Graczyk86c6d332015-07-23 11:41:39 -0700141 WEBRTC_STUB(ProcessStream,
142 (const float* const* src,
143 const webrtc::StreamConfig& input_config,
144 const webrtc::StreamConfig& output_config,
145 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000146 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
ekmeyerson60d9b332015-08-14 10:35:55 -0700147 WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000148 WEBRTC_STUB(AnalyzeReverseStream, (
149 const float* const* data,
150 int samples_per_channel,
151 int sample_rate_hz,
152 webrtc::AudioProcessing::ChannelLayout layout));
ekmeyerson60d9b332015-08-14 10:35:55 -0700153 WEBRTC_STUB(ProcessReverseStream,
154 (const float* const* src,
155 const webrtc::StreamConfig& reverse_input_config,
156 const webrtc::StreamConfig& reverse_output_config,
157 float* const* dest));
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000158 WEBRTC_STUB(set_stream_delay_ms, (int delay));
159 WEBRTC_STUB_CONST(stream_delay_ms, ());
160 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
161 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
162 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
163 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
164 WEBRTC_STUB_CONST(delay_offset_ms, ());
165 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
166 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
167 WEBRTC_STUB(StopDebugRecording, ());
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200168 WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000169 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
170 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000171 return NULL;
172 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000173 webrtc::GainControl* gain_control() const override { return NULL; }
174 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
175 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
176 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
177 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000178
179 bool experimental_ns_enabled() {
180 return experimental_ns_enabled_;
181 }
182
183 private:
184 bool experimental_ns_enabled_;
185};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000186
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187class FakeWebRtcVoiceEngine
188 : public webrtc::VoEAudioProcessing,
189 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
190 public webrtc::VoEFile, public webrtc::VoEHardware,
191 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
192 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
193 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
194 public:
195 struct DtmfInfo {
196 DtmfInfo()
197 : dtmf_event_code(-1),
198 dtmf_out_of_band(false),
199 dtmf_length_ms(-1) {}
200 int dtmf_event_code;
201 bool dtmf_out_of_band;
202 int dtmf_length_ms;
203 };
204 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000205 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 : external_transport(false),
207 send(false),
208 playout(false),
209 volume_scale(1.0),
210 volume_pan_left(1.0),
211 volume_pan_right(1.0),
212 file(false),
213 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000214 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000215 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000216 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000217 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 nack(false),
219 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000220 rx_agc_enabled(false),
221 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 cn8_type(13),
223 cn16_type(105),
224 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000225 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 nack_max_packets(0),
227 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000228 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000229 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000230 send_absolute_sender_time_ext_(-1),
Henrik Lundin64dad832015-05-11 12:44:23 +0200231 receive_absolute_sender_time_ext_(-1),
Minyue2013aec2015-05-13 14:14:42 +0200232 associate_send_channel(-1),
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200233 neteq_capacity(-1),
234 neteq_fast_accelerate(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000236 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 }
238 bool external_transport;
239 bool send;
240 bool playout;
241 float volume_scale;
242 float volume_pan_left;
243 float volume_pan_right;
244 bool file;
245 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000246 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000247 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000248 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000249 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 bool nack;
251 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000252 bool rx_agc_enabled;
253 webrtc::AgcModes rx_agc_mode;
254 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 int cn8_type;
256 int cn16_type;
257 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000258 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 int nack_max_packets;
260 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000261 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000262 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000263 int send_absolute_sender_time_ext_;
264 int receive_absolute_sender_time_ext_;
Minyue2013aec2015-05-13 14:14:42 +0200265 int associate_send_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266 DtmfInfo dtmf_info;
267 std::vector<webrtc::CodecInst> recv_codecs;
268 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000269 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 std::list<std::string> packets;
Henrik Lundin64dad832015-05-11 12:44:23 +0200271 int neteq_capacity;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200272 bool neteq_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 };
274
275 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
276 int num_codecs)
277 : inited_(false),
278 last_channel_(-1),
279 fail_create_channel_(false),
280 codecs_(codecs),
281 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000282 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 ec_enabled_(false),
284 ec_metrics_enabled_(false),
285 cng_enabled_(false),
286 ns_enabled_(false),
287 agc_enabled_(false),
288 highpass_filter_enabled_(false),
289 stereo_swapping_enabled_(false),
290 typing_detection_enabled_(false),
291 ec_mode_(webrtc::kEcDefault),
292 aecm_mode_(webrtc::kAecmSpeakerphone),
293 ns_mode_(webrtc::kNsDefault),
294 agc_mode_(webrtc::kAgcDefault),
295 observer_(NULL),
296 playout_fail_channel_(-1),
297 send_fail_channel_(-1),
298 fail_start_recording_microphone_(false),
299 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000300 recording_sample_rate_(-1),
301 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 media_processor_(NULL) {
303 memset(&agc_config_, 0, sizeof(agc_config_));
304 }
305 ~FakeWebRtcVoiceEngine() {
306 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
307 // destructors, but just in case ...
308 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
309 i != channels_.end(); ++i) {
310 delete i->second;
311 }
312 }
313
314 bool IsExternalMediaProcessorRegistered() const {
315 return media_processor_ != NULL;
316 }
317 bool IsInited() const { return inited_; }
318 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000319 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
320 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
321 iter != channels_.end(); ++iter) {
322 if (local_ssrc == iter->second->send_ssrc)
323 return iter->first;
324 }
325 return -1;
326 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000327 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 bool GetPlayout(int channel) {
329 return channels_[channel]->playout;
330 }
331 bool GetSend(int channel) {
332 return channels_[channel]->send;
333 }
334 bool GetRecordingMicrophone() {
335 return recording_microphone_;
336 }
337 bool GetVAD(int channel) {
338 return channels_[channel]->vad;
339 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100340 bool GetOpusDtx(int channel) {
341 return channels_[channel]->opus_dtx;
342 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000343 bool GetRED(int channel) {
344 return channels_[channel]->red;
345 }
346 bool GetCodecFEC(int channel) {
347 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000349 int GetMaxEncodingBandwidth(int channel) {
350 return channels_[channel]->max_encoding_bandwidth;
351 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 bool GetNACK(int channel) {
353 return channels_[channel]->nack;
354 }
355 int GetNACKMaxPackets(int channel) {
356 return channels_[channel]->nack_max_packets;
357 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000358 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
359 WEBRTC_ASSERT_CHANNEL(channel);
360 return channels_[channel]->last_rtp_packet_time;
361 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 int GetSendCNPayloadType(int channel, bool wideband) {
363 return (wideband) ?
364 channels_[channel]->cn16_type :
365 channels_[channel]->cn8_type;
366 }
367 int GetSendTelephoneEventPayloadType(int channel) {
368 return channels_[channel]->dtmf_type;
369 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000370 int GetSendREDPayloadType(int channel) {
371 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 }
373 bool CheckPacket(int channel, const void* data, size_t len) {
374 bool result = !CheckNoPacket(channel);
375 if (result) {
376 std::string packet = channels_[channel]->packets.front();
377 result = (packet == std::string(static_cast<const char*>(data), len));
378 channels_[channel]->packets.pop_front();
379 }
380 return result;
381 }
382 bool CheckNoPacket(int channel) {
383 return channels_[channel]->packets.empty();
384 }
385 void TriggerCallbackOnError(int channel_num, int err_code) {
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +0200386 DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 observer_->CallbackOnError(channel_num, err_code);
388 }
389 void set_playout_fail_channel(int channel) {
390 playout_fail_channel_ = channel;
391 }
392 void set_send_fail_channel(int channel) {
393 send_fail_channel_ = channel;
394 }
395 void set_fail_start_recording_microphone(
396 bool fail_start_recording_microphone) {
397 fail_start_recording_microphone_ = fail_start_recording_microphone;
398 }
399 void set_fail_create_channel(bool fail_create_channel) {
400 fail_create_channel_ = fail_create_channel;
401 }
402 void TriggerProcessPacket(MediaProcessorDirection direction) {
403 webrtc::ProcessingTypes pt =
404 (direction == cricket::MPD_TX) ?
405 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
406 if (media_processor_ != NULL) {
407 media_processor_->Process(0,
408 pt,
409 NULL,
410 0,
411 0,
412 true);
413 }
414 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200415 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000416 if (fail_create_channel_) {
417 return -1;
418 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000419 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000420 for (int i = 0; i < NumOfCodecs(); ++i) {
421 webrtc::CodecInst codec;
422 GetCodec(i, codec);
423 ch->recv_codecs.push_back(codec);
424 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200425 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
426 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
427 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200428 ch->neteq_fast_accelerate =
429 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000430 channels_[++last_channel_] = ch;
431 return last_channel_;
432 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000433 int GetSendRtpExtensionId(int channel, const std::string& extension) {
434 WEBRTC_ASSERT_CHANNEL(channel);
435 if (extension == kRtpAudioLevelHeaderExtension) {
436 return channels_[channel]->send_audio_level_ext_;
437 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
438 return channels_[channel]->send_absolute_sender_time_ext_;
439 }
440 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000441 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000442 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
443 WEBRTC_ASSERT_CHANNEL(channel);
444 if (extension == kRtpAudioLevelHeaderExtension) {
445 return channels_[channel]->receive_audio_level_ext_;
446 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
447 return channels_[channel]->receive_absolute_sender_time_ext_;
448 }
449 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000450 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000452 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
453
Minyue2013aec2015-05-13 14:14:42 +0200454 int GetAssociateSendChannel(int channel) {
455 return channels_[channel]->associate_send_channel;
456 }
457
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 WEBRTC_STUB(Release, ());
459
460 // webrtc::VoEBase
461 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
462 webrtc::VoiceEngineObserver& observer)) {
463 observer_ = &observer;
464 return 0;
465 }
466 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
467 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
468 webrtc::AudioProcessing* audioproc)) {
469 inited_ = true;
470 return 0;
471 }
472 WEBRTC_FUNC(Terminate, ()) {
473 inited_ = false;
474 return 0;
475 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000476 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000477 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000478 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200480 webrtc::Config empty_config;
481 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200483 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
484 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000485 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486 WEBRTC_FUNC(DeleteChannel, (int channel)) {
487 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200488 for (const auto& ch : channels_) {
489 if (ch.second->associate_send_channel == channel) {
490 ch.second->associate_send_channel = -1;
491 }
492 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493 delete channels_[channel];
494 channels_.erase(channel);
495 return 0;
496 }
497 WEBRTC_STUB(StartReceive, (int channel));
498 WEBRTC_FUNC(StartPlayout, (int channel)) {
499 if (playout_fail_channel_ != channel) {
500 WEBRTC_CHECK_CHANNEL(channel);
501 channels_[channel]->playout = true;
502 return 0;
503 } else {
504 // When playout_fail_channel_ == channel, fail the StartPlayout on this
505 // channel.
506 return -1;
507 }
508 }
509 WEBRTC_FUNC(StartSend, (int channel)) {
510 if (send_fail_channel_ != channel) {
511 WEBRTC_CHECK_CHANNEL(channel);
512 channels_[channel]->send = true;
513 return 0;
514 } else {
515 // When send_fail_channel_ == channel, fail the StartSend on this
516 // channel.
517 return -1;
518 }
519 }
520 WEBRTC_STUB(StopReceive, (int channel));
521 WEBRTC_FUNC(StopPlayout, (int channel)) {
522 WEBRTC_CHECK_CHANNEL(channel);
523 channels_[channel]->playout = false;
524 return 0;
525 }
526 WEBRTC_FUNC(StopSend, (int channel)) {
527 WEBRTC_CHECK_CHANNEL(channel);
528 channels_[channel]->send = false;
529 return 0;
530 }
531 WEBRTC_STUB(GetVersion, (char version[1024]));
532 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200533 WEBRTC_FUNC(AssociateSendChannel, (int channel,
534 int accociate_send_channel)) {
535 WEBRTC_CHECK_CHANNEL(channel);
536 channels_[channel]->associate_send_channel = accociate_send_channel;
537 return 0;
538 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539
540 // webrtc::VoECodec
541 WEBRTC_FUNC(NumOfCodecs, ()) {
542 return num_codecs_;
543 }
544 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
545 if (index < 0 || index >= NumOfCodecs()) {
546 return -1;
547 }
548 const cricket::AudioCodec& c(*codecs_[index]);
549 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000550 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 codec.plfreq = c.clockrate;
552 codec.pacsize = 0;
553 codec.channels = c.channels;
554 codec.rate = c.bitrate;
555 return 0;
556 }
557 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
558 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000559 // To match the behavior of the real implementation.
560 if (_stricmp(codec.plname, "telephone-event") == 0 ||
561 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
562 _stricmp(codec.plname, "CN") == 0 ||
563 _stricmp(codec.plname, "red") == 0 ) {
564 return -1;
565 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000567 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 return 0;
569 }
570 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
571 WEBRTC_CHECK_CHANNEL(channel);
572 codec = channels_[channel]->send_codec;
573 return 0;
574 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200575 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000576 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
577 WEBRTC_CHECK_CHANNEL(channel);
578 const Channel* c = channels_[channel];
579 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
580 it_packet != c->packets.end(); ++it_packet) {
581 int pltype;
582 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
583 continue;
584 }
585 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
586 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
587 ++it_codec) {
588 if (it_codec->pltype == pltype) {
589 codec = *it_codec;
590 return 0;
591 }
592 }
593 }
594 return -1;
595 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 WEBRTC_FUNC(SetRecPayloadType, (int channel,
597 const webrtc::CodecInst& codec)) {
598 WEBRTC_CHECK_CHANNEL(channel);
599 Channel* ch = channels_[channel];
600 if (ch->playout)
601 return -1; // Channel is in use.
602 // Check if something else already has this slot.
603 if (codec.pltype != -1) {
604 for (std::vector<webrtc::CodecInst>::iterator it =
605 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
606 if (it->pltype == codec.pltype &&
607 _stricmp(it->plname, codec.plname) != 0) {
608 return -1;
609 }
610 }
611 }
612 // Otherwise try to find this codec and update its payload type.
613 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
614 it != ch->recv_codecs.end(); ++it) {
615 if (strcmp(it->plname, codec.plname) == 0 &&
616 it->plfreq == codec.plfreq) {
617 it->pltype = codec.pltype;
618 it->channels = codec.channels;
619 return 0;
620 }
621 }
622 return -1; // not found
623 }
624 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
625 webrtc::PayloadFrequencies frequency)) {
626 WEBRTC_CHECK_CHANNEL(channel);
627 if (frequency == webrtc::kFreq8000Hz) {
628 channels_[channel]->cn8_type = type;
629 } else if (frequency == webrtc::kFreq16000Hz) {
630 channels_[channel]->cn16_type = type;
631 }
632 return 0;
633 }
634 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
635 WEBRTC_CHECK_CHANNEL(channel);
636 Channel* ch = channels_[channel];
637 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
638 it != ch->recv_codecs.end(); ++it) {
639 if (strcmp(it->plname, codec.plname) == 0 &&
640 it->plfreq == codec.plfreq &&
641 it->channels == codec.channels &&
642 it->pltype != -1) {
643 codec.pltype = it->pltype;
644 return 0;
645 }
646 }
647 return -1; // not found
648 }
649 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
650 bool disableDTX)) {
651 WEBRTC_CHECK_CHANNEL(channel);
652 if (channels_[channel]->send_codec.channels == 2) {
653 // Replicating VoE behavior; VAD cannot be enabled for stereo.
654 return -1;
655 }
656 channels_[channel]->vad = enable;
657 return 0;
658 }
659 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
660 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000661
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000662 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
663 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000664 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000665 // Return -1 if current send codec is not Opus.
666 // TODO(minyue): Excludes other codecs if they support inband FEC.
667 return -1;
668 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000669 channels_[channel]->codec_fec = enable;
670 return 0;
671 }
672 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
673 WEBRTC_CHECK_CHANNEL(channel);
674 enable = channels_[channel]->codec_fec;
675 return 0;
676 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000677
678 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
679 WEBRTC_CHECK_CHANNEL(channel);
680 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
681 // Return -1 if current send codec is not Opus.
682 return -1;
683 }
684 if (frequency_hz <= 8000)
685 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
686 else if (frequency_hz <= 12000)
687 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
688 else if (frequency_hz <= 16000)
689 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
690 else if (frequency_hz <= 24000)
691 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
692 else
693 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
694 return 0;
695 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000697 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
698 WEBRTC_CHECK_CHANNEL(channel);
699 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
700 // Return -1 if current send codec is not Opus.
701 return -1;
702 }
703 channels_[channel]->opus_dtx = enable_dtx;
704 return 0;
705 }
706
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 // webrtc::VoEDtmf
708 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
709 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
710 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
711 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
712 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
713 return 0;
714 }
715
716 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
717 (int channel, unsigned char type)) {
718 channels_[channel]->dtmf_type = type;
719 return 0;
720 };
721 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
722 (int channel, unsigned char& type));
723
724 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
725 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 WEBRTC_FUNC(PlayDtmfTone,
728 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
729 dtmf_info_.dtmf_event_code = event_code;
730 dtmf_info_.dtmf_length_ms = length_ms;
731 return 0;
732 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733
734 // webrtc::VoEFile
735 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
736 bool loop, webrtc::FileFormats format,
737 float volumeScaling, int startPointMs,
738 int stopPointMs)) {
739 WEBRTC_CHECK_CHANNEL(channel);
740 channels_[channel]->file = true;
741 return 0;
742 }
743 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
744 webrtc::FileFormats format,
745 float volumeScaling, int startPointMs,
746 int stopPointMs)) {
747 WEBRTC_CHECK_CHANNEL(channel);
748 channels_[channel]->file = true;
749 return 0;
750 }
751 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
752 WEBRTC_CHECK_CHANNEL(channel);
753 channels_[channel]->file = false;
754 return 0;
755 }
756 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
757 WEBRTC_CHECK_CHANNEL(channel);
758 return (channels_[channel]->file) ? 1 : 0;
759 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
761 const char* fileNameUTF8,
762 bool loop,
763 bool mixWithMicrophone,
764 webrtc::FileFormats format,
765 float volumeScaling));
766 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
767 webrtc::InStream* stream,
768 bool mixWithMicrophone,
769 webrtc::FileFormats format,
770 float volumeScaling));
771 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
772 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
774 webrtc::CodecInst* compression,
775 int maxSizeBytes));
776 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
777 webrtc::CodecInst* compression));
778 WEBRTC_STUB(StopRecordingPlayout, (int channel));
779 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
780 webrtc::CodecInst* compression,
781 int maxSizeBytes)) {
782 if (fail_start_recording_microphone_) {
783 return -1;
784 }
785 recording_microphone_ = true;
786 return 0;
787 }
788 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
789 webrtc::CodecInst* compression)) {
790 if (fail_start_recording_microphone_) {
791 return -1;
792 }
793 recording_microphone_ = true;
794 return 0;
795 }
796 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
797 if (!recording_microphone_) {
798 return -1;
799 }
800 recording_microphone_ = false;
801 return 0;
802 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803
804 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
806 return GetNumDevices(num);
807 }
808 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
809 return GetNumDevices(num);
810 }
811 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
812 return GetDeviceName(i, name, guid);
813 }
814 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
815 return GetDeviceName(i, name, guid);
816 }
817 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
818 WEBRTC_STUB(SetPlayoutDevice, (int));
819 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
820 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000821 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
822 recording_sample_rate_ = samples_per_sec;
823 return 0;
824 }
825 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
826 *samples_per_sec = recording_sample_rate_;
827 return 0;
828 }
829 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
830 playout_sample_rate_ = samples_per_sec;
831 return 0;
832 }
833 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
834 *samples_per_sec = playout_sample_rate_;
835 return 0;
836 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000838 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839
840 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000841 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
842 webrtc::NetworkStatistics& ns)) {
843 WEBRTC_CHECK_CHANNEL(channel);
844 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
845 return 0;
846 }
847
wu@webrtc.org24301a62013-12-13 19:17:43 +0000848 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
849 webrtc::AudioDecodingCallStats*)) {
850 WEBRTC_CHECK_CHANNEL(channel);
851 return 0;
852 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853
854 // webrtc::VoENetwork
855 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
856 webrtc::Transport& transport)) {
857 WEBRTC_CHECK_CHANNEL(channel);
858 channels_[channel]->external_transport = true;
859 return 0;
860 }
861 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
862 WEBRTC_CHECK_CHANNEL(channel);
863 channels_[channel]->external_transport = false;
864 return 0;
865 }
866 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000867 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 WEBRTC_CHECK_CHANNEL(channel);
869 if (!channels_[channel]->external_transport) return -1;
870 channels_[channel]->packets.push_back(
871 std::string(static_cast<const char*>(data), length));
872 return 0;
873 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000874 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000875 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000876 const webrtc::PacketTime& packet_time)) {
877 WEBRTC_CHECK_CHANNEL(channel);
878 if (ReceivedRTPPacket(channel, data, length) == -1) {
879 return -1;
880 }
881 channels_[channel]->last_rtp_packet_time = packet_time;
882 return 0;
883 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000884
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000886 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887
888 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
890 WEBRTC_CHECK_CHANNEL(channel);
891 channels_[channel]->send_ssrc = ssrc;
892 return 0;
893 }
894 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
895 WEBRTC_CHECK_CHANNEL(channel);
896 ssrc = channels_[channel]->send_ssrc;
897 return 0;
898 }
899 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000900 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
901 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000903 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
904 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 return 0;
906 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000907 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (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_audio_level_ext_ = (enable) ? id : -1;
912 return 0;
913 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000914 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
915 unsigned char id)) {
916 WEBRTC_CHECK_CHANNEL(channel);
917 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
918 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
919 return 0;
920 }
921 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
922 unsigned char id)) {
923 WEBRTC_CHECK_CHANNEL(channel);
924 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
925 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
926 return 0;
927 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000928
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
930 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
931 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
932 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
933 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
934 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
935 unsigned int& NTPLow,
936 unsigned int& timestamp,
937 unsigned int& playoutTimestamp,
938 unsigned int* jitter,
939 unsigned short* fractionLost));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
941 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
942 WEBRTC_CHECK_CHANNEL(channel);
943 webrtc::ReportBlock block;
944 block.source_SSRC = channels_[channel]->send_ssrc;
945 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
946 if (send_codec.pltype >= 0) {
947 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
948 if (send_codec.plfreq / 1000 > 0) {
949 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
950 }
951 block.cumulative_num_packets_lost = kIntStatValue;
952 block.extended_highest_sequence_number = kIntStatValue;
953 receive_blocks->push_back(block);
954 }
955 return 0;
956 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
958 unsigned int& maxJitterMs,
959 unsigned int& discardedPackets));
960 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
961 WEBRTC_CHECK_CHANNEL(channel);
962 stats.fractionLost = static_cast<int16>(kIntStatValue);
963 stats.cumulativeLost = kIntStatValue;
964 stats.extendedMax = kIntStatValue;
965 stats.jitterSamples = kIntStatValue;
966 stats.rttMs = kIntStatValue;
967 stats.bytesSent = kIntStatValue;
968 stats.packetsSent = kIntStatValue;
969 stats.bytesReceived = kIntStatValue;
970 stats.packetsReceived = kIntStatValue;
971 return 0;
972 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000973 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000974 return SetFECStatus(channel, enable, redPayloadtype);
975 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000976 // TODO(minyue): remove the below function when transition to SetREDStatus
977 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
979 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000980 channels_[channel]->red = enable;
981 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 return 0;
983 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000984 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000985 return GetFECStatus(channel, enable, redPayloadtype);
986 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000987 // TODO(minyue): remove the below function when transition to GetREDStatus
988 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
990 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000991 enable = channels_[channel]->red;
992 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 return 0;
994 }
995 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
996 WEBRTC_CHECK_CHANNEL(channel);
997 channels_[channel]->nack = enable;
998 channels_[channel]->nack_max_packets = maxNoPackets;
999 return 0;
1000 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001
1002 // webrtc::VoEVideoSync
1003 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1004 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001005 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1007 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1008 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1009 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1010 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1011 int* playout_buffer_delay_ms));
1012 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1013
1014 // webrtc::VoEVolumeControl
1015 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1016 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 WEBRTC_STUB(SetMicVolume, (unsigned int));
1018 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1019 WEBRTC_STUB(SetInputMute, (int, bool));
1020 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1022 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1023 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1024 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1025 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1026 WEBRTC_CHECK_CHANNEL(channel);
1027 channels_[channel]->volume_scale= scale;
1028 return 0;
1029 }
1030 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1031 WEBRTC_CHECK_CHANNEL(channel);
1032 scale = channels_[channel]->volume_scale;
1033 return 0;
1034 }
1035 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1036 WEBRTC_CHECK_CHANNEL(channel);
1037 channels_[channel]->volume_pan_left = left;
1038 channels_[channel]->volume_pan_right = right;
1039 return 0;
1040 }
1041 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1042 WEBRTC_CHECK_CHANNEL(channel);
1043 left = channels_[channel]->volume_pan_left;
1044 right = channels_[channel]->volume_pan_right;
1045 return 0;
1046 }
1047
1048 // webrtc::VoEAudioProcessing
1049 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1050 ns_enabled_ = enable;
1051 ns_mode_ = mode;
1052 return 0;
1053 }
1054 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1055 enabled = ns_enabled_;
1056 mode = ns_mode_;
1057 return 0;
1058 }
1059
1060 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1061 agc_enabled_ = enable;
1062 agc_mode_ = mode;
1063 return 0;
1064 }
1065 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1066 enabled = agc_enabled_;
1067 mode = agc_mode_;
1068 return 0;
1069 }
1070
1071 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1072 agc_config_ = config;
1073 return 0;
1074 }
1075 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1076 config = agc_config_;
1077 return 0;
1078 }
1079 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1080 ec_enabled_ = enable;
1081 ec_mode_ = mode;
1082 return 0;
1083 }
1084 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1085 enabled = ec_enabled_;
1086 mode = ec_mode_;
1087 return 0;
1088 }
1089 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1090 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1091 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1092 WEBRTC_STUB(DelayOffsetMs, ());
1093 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1094 aecm_mode_ = mode;
1095 cng_enabled_ = enableCNG;
1096 return 0;
1097 }
1098 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1099 mode = aecm_mode_;
1100 enabledCNG = cng_enabled_;
1101 return 0;
1102 }
1103 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1104 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1105 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001106 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1107 webrtc::AgcModes mode)) {
1108 channels_[channel]->rx_agc_enabled = enable;
1109 channels_[channel]->rx_agc_mode = mode;
1110 return 0;
1111 }
1112 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1113 webrtc::AgcModes& mode)) {
1114 enabled = channels_[channel]->rx_agc_enabled;
1115 mode = channels_[channel]->rx_agc_mode;
1116 return 0;
1117 }
1118
1119 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1120 channels_[channel]->rx_agc_config = config;
1121 return 0;
1122 }
1123 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1124 config = channels_[channel]->rx_agc_config;
1125 return 0;
1126 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127
1128 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1129 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1130 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1131 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1132 ec_metrics_enabled_ = enable;
1133 return 0;
1134 }
1135 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1136 enabled = ec_metrics_enabled_;
1137 return 0;
1138 }
1139 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001140 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1141 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142
1143 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001144 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 WEBRTC_STUB(StopDebugRecording, ());
1146
1147 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1148 typing_detection_enabled_ = enable;
1149 return 0;
1150 }
1151 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1152 enabled = typing_detection_enabled_;
1153 return 0;
1154 }
1155
1156 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1157 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1158 int costPerTyping,
1159 int reportingThreshold,
1160 int penaltyDecay,
1161 int typeEventDelay));
1162 int EnableHighPassFilter(bool enable) {
1163 highpass_filter_enabled_ = enable;
1164 return 0;
1165 }
1166 bool IsHighPassFilterEnabled() {
1167 return highpass_filter_enabled_;
1168 }
1169 bool IsStereoChannelSwappingEnabled() {
1170 return stereo_swapping_enabled_;
1171 }
1172 void EnableStereoChannelSwapping(bool enable) {
1173 stereo_swapping_enabled_ = enable;
1174 }
1175 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1176 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1177 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1178 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1179 }
1180 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1181 return (dtmf_info_.dtmf_event_code == event_code &&
1182 dtmf_info_.dtmf_length_ms == length_ms);
1183 }
1184 // webrtc::VoEExternalMedia
1185 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1186 (int channel, webrtc::ProcessingTypes type,
1187 webrtc::VoEMediaProcess& processObject)) {
1188 WEBRTC_CHECK_CHANNEL(channel);
1189 if (channels_[channel]->media_processor_registered) {
1190 return -1;
1191 }
1192 channels_[channel]->media_processor_registered = true;
1193 media_processor_ = &processObject;
1194 return 0;
1195 }
1196 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1197 (int channel, webrtc::ProcessingTypes type)) {
1198 WEBRTC_CHECK_CHANNEL(channel);
1199 if (!channels_[channel]->media_processor_registered) {
1200 return -1;
1201 }
1202 channels_[channel]->media_processor_registered = false;
1203 media_processor_ = NULL;
1204 return 0;
1205 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1207 webrtc::AudioFrame* frame));
1208 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
Henrik Lundin64dad832015-05-11 12:44:23 +02001209 int GetNetEqCapacity() const {
1210 auto ch = channels_.find(last_channel_);
1211 ASSERT(ch != channels_.end());
1212 return ch->second->neteq_capacity;
1213 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +02001214 bool GetNetEqFastAccelerate() const {
1215 auto ch = channels_.find(last_channel_);
1216 ASSERT(ch != channels_.end());
1217 return ch->second->neteq_fast_accelerate;
1218 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219
1220 private:
1221 int GetNumDevices(int& num) {
1222#ifdef WIN32
1223 num = 1;
1224#else
1225 // On non-Windows platforms VE adds a special entry for the default device,
1226 // so if there is one physical device then there are two entries in the
1227 // list.
1228 num = 2;
1229#endif
1230 return 0;
1231 }
1232
1233 int GetDeviceName(int i, char* name, char* guid) {
1234 const char *s;
1235#ifdef WIN32
1236 if (0 == i) {
1237 s = kFakeDeviceName;
1238 } else {
1239 return -1;
1240 }
1241#else
1242 // See comment above.
1243 if (0 == i) {
1244 s = kFakeDefaultDeviceName;
1245 } else if (1 == i) {
1246 s = kFakeDeviceName;
1247 } else {
1248 return -1;
1249 }
1250#endif
1251 strcpy(name, s);
1252 guid[0] = '\0';
1253 return 0;
1254 }
1255
1256 bool inited_;
1257 int last_channel_;
1258 std::map<int, Channel*> channels_;
1259 bool fail_create_channel_;
1260 const cricket::AudioCodec* const* codecs_;
1261 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001262 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 bool ec_enabled_;
1264 bool ec_metrics_enabled_;
1265 bool cng_enabled_;
1266 bool ns_enabled_;
1267 bool agc_enabled_;
1268 bool highpass_filter_enabled_;
1269 bool stereo_swapping_enabled_;
1270 bool typing_detection_enabled_;
1271 webrtc::EcModes ec_mode_;
1272 webrtc::AecmModes aecm_mode_;
1273 webrtc::NsModes ns_mode_;
1274 webrtc::AgcModes agc_mode_;
1275 webrtc::AgcConfig agc_config_;
1276 webrtc::VoiceEngineObserver* observer_;
1277 int playout_fail_channel_;
1278 int send_fail_channel_;
1279 bool fail_start_recording_microphone_;
1280 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001281 int recording_sample_rate_;
1282 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 DtmfInfo dtmf_info_;
1284 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001285 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286};
1287
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001288#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1289
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290} // namespace cricket
1291
1292#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_