blob: 4ce5a38a09a74e97a9a0974473b5a62d9bc68584 [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) \
henrikg91d6ede2015-09-17 00:24:34 -070092 RTC_DCHECK(channels_.find(channel) != channels_.end());
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020093
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,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700135 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000136 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,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700150 size_t samples_per_channel,
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000151 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) {
henrikg91d6ede2015-09-17 00:24:34 -0700386 RTC_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 }
ivocb04965c2015-09-09 00:09:43 -0700539 webrtc::RtcEventLog* GetEventLog() { return nullptr; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540
541 // webrtc::VoECodec
542 WEBRTC_FUNC(NumOfCodecs, ()) {
543 return num_codecs_;
544 }
545 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
546 if (index < 0 || index >= NumOfCodecs()) {
547 return -1;
548 }
549 const cricket::AudioCodec& c(*codecs_[index]);
550 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000551 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 codec.plfreq = c.clockrate;
553 codec.pacsize = 0;
554 codec.channels = c.channels;
555 codec.rate = c.bitrate;
556 return 0;
557 }
558 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
559 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000560 // To match the behavior of the real implementation.
561 if (_stricmp(codec.plname, "telephone-event") == 0 ||
562 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
563 _stricmp(codec.plname, "CN") == 0 ||
564 _stricmp(codec.plname, "red") == 0 ) {
565 return -1;
566 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000568 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 return 0;
570 }
571 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
572 WEBRTC_CHECK_CHANNEL(channel);
573 codec = channels_[channel]->send_codec;
574 return 0;
575 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200576 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000577 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
578 WEBRTC_CHECK_CHANNEL(channel);
579 const Channel* c = channels_[channel];
580 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
581 it_packet != c->packets.end(); ++it_packet) {
582 int pltype;
583 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
584 continue;
585 }
586 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
587 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
588 ++it_codec) {
589 if (it_codec->pltype == pltype) {
590 codec = *it_codec;
591 return 0;
592 }
593 }
594 }
595 return -1;
596 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597 WEBRTC_FUNC(SetRecPayloadType, (int channel,
598 const webrtc::CodecInst& codec)) {
599 WEBRTC_CHECK_CHANNEL(channel);
600 Channel* ch = channels_[channel];
601 if (ch->playout)
602 return -1; // Channel is in use.
603 // Check if something else already has this slot.
604 if (codec.pltype != -1) {
605 for (std::vector<webrtc::CodecInst>::iterator it =
606 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
607 if (it->pltype == codec.pltype &&
608 _stricmp(it->plname, codec.plname) != 0) {
609 return -1;
610 }
611 }
612 }
613 // Otherwise try to find this codec and update its payload type.
614 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
615 it != ch->recv_codecs.end(); ++it) {
616 if (strcmp(it->plname, codec.plname) == 0 &&
617 it->plfreq == codec.plfreq) {
618 it->pltype = codec.pltype;
619 it->channels = codec.channels;
620 return 0;
621 }
622 }
623 return -1; // not found
624 }
625 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
626 webrtc::PayloadFrequencies frequency)) {
627 WEBRTC_CHECK_CHANNEL(channel);
628 if (frequency == webrtc::kFreq8000Hz) {
629 channels_[channel]->cn8_type = type;
630 } else if (frequency == webrtc::kFreq16000Hz) {
631 channels_[channel]->cn16_type = type;
632 }
633 return 0;
634 }
635 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
636 WEBRTC_CHECK_CHANNEL(channel);
637 Channel* ch = channels_[channel];
638 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
639 it != ch->recv_codecs.end(); ++it) {
640 if (strcmp(it->plname, codec.plname) == 0 &&
641 it->plfreq == codec.plfreq &&
642 it->channels == codec.channels &&
643 it->pltype != -1) {
644 codec.pltype = it->pltype;
645 return 0;
646 }
647 }
648 return -1; // not found
649 }
650 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
651 bool disableDTX)) {
652 WEBRTC_CHECK_CHANNEL(channel);
653 if (channels_[channel]->send_codec.channels == 2) {
654 // Replicating VoE behavior; VAD cannot be enabled for stereo.
655 return -1;
656 }
657 channels_[channel]->vad = enable;
658 return 0;
659 }
660 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
661 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000662
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000663 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
664 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000665 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000666 // Return -1 if current send codec is not Opus.
667 // TODO(minyue): Excludes other codecs if they support inband FEC.
668 return -1;
669 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000670 channels_[channel]->codec_fec = enable;
671 return 0;
672 }
673 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
674 WEBRTC_CHECK_CHANNEL(channel);
675 enable = channels_[channel]->codec_fec;
676 return 0;
677 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000678
679 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
680 WEBRTC_CHECK_CHANNEL(channel);
681 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
682 // Return -1 if current send codec is not Opus.
683 return -1;
684 }
685 if (frequency_hz <= 8000)
686 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
687 else if (frequency_hz <= 12000)
688 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
689 else if (frequency_hz <= 16000)
690 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
691 else if (frequency_hz <= 24000)
692 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
693 else
694 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
695 return 0;
696 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000698 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
699 WEBRTC_CHECK_CHANNEL(channel);
700 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
701 // Return -1 if current send codec is not Opus.
702 return -1;
703 }
704 channels_[channel]->opus_dtx = enable_dtx;
705 return 0;
706 }
707
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 // webrtc::VoEDtmf
709 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
710 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
711 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
712 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
713 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
714 return 0;
715 }
716
717 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
718 (int channel, unsigned char type)) {
719 channels_[channel]->dtmf_type = type;
720 return 0;
721 };
722 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
723 (int channel, unsigned char& type));
724
725 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
726 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 WEBRTC_FUNC(PlayDtmfTone,
729 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
730 dtmf_info_.dtmf_event_code = event_code;
731 dtmf_info_.dtmf_length_ms = length_ms;
732 return 0;
733 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734
735 // webrtc::VoEFile
736 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
737 bool loop, webrtc::FileFormats format,
738 float volumeScaling, int startPointMs,
739 int stopPointMs)) {
740 WEBRTC_CHECK_CHANNEL(channel);
741 channels_[channel]->file = true;
742 return 0;
743 }
744 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
745 webrtc::FileFormats format,
746 float volumeScaling, int startPointMs,
747 int stopPointMs)) {
748 WEBRTC_CHECK_CHANNEL(channel);
749 channels_[channel]->file = true;
750 return 0;
751 }
752 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
753 WEBRTC_CHECK_CHANNEL(channel);
754 channels_[channel]->file = false;
755 return 0;
756 }
757 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
758 WEBRTC_CHECK_CHANNEL(channel);
759 return (channels_[channel]->file) ? 1 : 0;
760 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
762 const char* fileNameUTF8,
763 bool loop,
764 bool mixWithMicrophone,
765 webrtc::FileFormats format,
766 float volumeScaling));
767 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
768 webrtc::InStream* stream,
769 bool mixWithMicrophone,
770 webrtc::FileFormats format,
771 float volumeScaling));
772 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
773 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
775 webrtc::CodecInst* compression,
776 int maxSizeBytes));
777 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
778 webrtc::CodecInst* compression));
779 WEBRTC_STUB(StopRecordingPlayout, (int channel));
780 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
781 webrtc::CodecInst* compression,
782 int maxSizeBytes)) {
783 if (fail_start_recording_microphone_) {
784 return -1;
785 }
786 recording_microphone_ = true;
787 return 0;
788 }
789 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
790 webrtc::CodecInst* compression)) {
791 if (fail_start_recording_microphone_) {
792 return -1;
793 }
794 recording_microphone_ = true;
795 return 0;
796 }
797 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
798 if (!recording_microphone_) {
799 return -1;
800 }
801 recording_microphone_ = false;
802 return 0;
803 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804
805 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
807 return GetNumDevices(num);
808 }
809 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
810 return GetNumDevices(num);
811 }
812 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
813 return GetDeviceName(i, name, guid);
814 }
815 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
816 return GetDeviceName(i, name, guid);
817 }
818 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
819 WEBRTC_STUB(SetPlayoutDevice, (int));
820 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
821 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000822 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
823 recording_sample_rate_ = samples_per_sec;
824 return 0;
825 }
826 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
827 *samples_per_sec = recording_sample_rate_;
828 return 0;
829 }
830 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
831 playout_sample_rate_ = samples_per_sec;
832 return 0;
833 }
834 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
835 *samples_per_sec = playout_sample_rate_;
836 return 0;
837 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000839 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840
841 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000842 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
843 webrtc::NetworkStatistics& ns)) {
844 WEBRTC_CHECK_CHANNEL(channel);
845 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
846 return 0;
847 }
848
wu@webrtc.org24301a62013-12-13 19:17:43 +0000849 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
850 webrtc::AudioDecodingCallStats*)) {
851 WEBRTC_CHECK_CHANNEL(channel);
852 return 0;
853 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854
855 // webrtc::VoENetwork
856 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
857 webrtc::Transport& transport)) {
858 WEBRTC_CHECK_CHANNEL(channel);
859 channels_[channel]->external_transport = true;
860 return 0;
861 }
862 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
863 WEBRTC_CHECK_CHANNEL(channel);
864 channels_[channel]->external_transport = false;
865 return 0;
866 }
867 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000868 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 WEBRTC_CHECK_CHANNEL(channel);
870 if (!channels_[channel]->external_transport) return -1;
871 channels_[channel]->packets.push_back(
872 std::string(static_cast<const char*>(data), length));
873 return 0;
874 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000875 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000876 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000877 const webrtc::PacketTime& packet_time)) {
878 WEBRTC_CHECK_CHANNEL(channel);
879 if (ReceivedRTPPacket(channel, data, length) == -1) {
880 return -1;
881 }
882 channels_[channel]->last_rtp_packet_time = packet_time;
883 return 0;
884 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000885
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000887 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888
889 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
891 WEBRTC_CHECK_CHANNEL(channel);
892 channels_[channel]->send_ssrc = ssrc;
893 return 0;
894 }
895 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
896 WEBRTC_CHECK_CHANNEL(channel);
897 ssrc = channels_[channel]->send_ssrc;
898 return 0;
899 }
900 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000901 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
902 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000904 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
905 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 return 0;
907 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000908 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
909 unsigned char id)) {
910 WEBRTC_CHECK_CHANNEL(channel);
911 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
912 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
913 return 0;
914 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000915 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
916 unsigned char id)) {
917 WEBRTC_CHECK_CHANNEL(channel);
918 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
919 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
920 return 0;
921 }
922 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
923 unsigned char id)) {
924 WEBRTC_CHECK_CHANNEL(channel);
925 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
926 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
927 return 0;
928 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000929
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
931 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
932 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
933 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
934 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
935 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
936 unsigned int& NTPLow,
937 unsigned int& timestamp,
938 unsigned int& playoutTimestamp,
939 unsigned int* jitter,
940 unsigned short* fractionLost));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
942 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
943 WEBRTC_CHECK_CHANNEL(channel);
944 webrtc::ReportBlock block;
945 block.source_SSRC = channels_[channel]->send_ssrc;
946 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
947 if (send_codec.pltype >= 0) {
948 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
949 if (send_codec.plfreq / 1000 > 0) {
950 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
951 }
952 block.cumulative_num_packets_lost = kIntStatValue;
953 block.extended_highest_sequence_number = kIntStatValue;
954 receive_blocks->push_back(block);
955 }
956 return 0;
957 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
959 unsigned int& maxJitterMs,
960 unsigned int& discardedPackets));
961 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
962 WEBRTC_CHECK_CHANNEL(channel);
963 stats.fractionLost = static_cast<int16>(kIntStatValue);
964 stats.cumulativeLost = kIntStatValue;
965 stats.extendedMax = kIntStatValue;
966 stats.jitterSamples = kIntStatValue;
967 stats.rttMs = kIntStatValue;
968 stats.bytesSent = kIntStatValue;
969 stats.packetsSent = kIntStatValue;
970 stats.bytesReceived = kIntStatValue;
971 stats.packetsReceived = kIntStatValue;
972 return 0;
973 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000974 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000975 return SetFECStatus(channel, enable, redPayloadtype);
976 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000977 // TODO(minyue): remove the below function when transition to SetREDStatus
978 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
980 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000981 channels_[channel]->red = enable;
982 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 return 0;
984 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000985 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000986 return GetFECStatus(channel, enable, redPayloadtype);
987 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000988 // TODO(minyue): remove the below function when transition to GetREDStatus
989 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
991 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000992 enable = channels_[channel]->red;
993 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 return 0;
995 }
996 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
997 WEBRTC_CHECK_CHANNEL(channel);
998 channels_[channel]->nack = enable;
999 channels_[channel]->nack_max_packets = maxNoPackets;
1000 return 0;
1001 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002
1003 // webrtc::VoEVideoSync
1004 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1005 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001006 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1008 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1009 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1010 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1011 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1012 int* playout_buffer_delay_ms));
1013 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1014
1015 // webrtc::VoEVolumeControl
1016 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1017 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 WEBRTC_STUB(SetMicVolume, (unsigned int));
1019 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1020 WEBRTC_STUB(SetInputMute, (int, bool));
1021 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1023 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1024 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1025 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1026 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1027 WEBRTC_CHECK_CHANNEL(channel);
1028 channels_[channel]->volume_scale= scale;
1029 return 0;
1030 }
1031 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1032 WEBRTC_CHECK_CHANNEL(channel);
1033 scale = channels_[channel]->volume_scale;
1034 return 0;
1035 }
1036 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1037 WEBRTC_CHECK_CHANNEL(channel);
1038 channels_[channel]->volume_pan_left = left;
1039 channels_[channel]->volume_pan_right = right;
1040 return 0;
1041 }
1042 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1043 WEBRTC_CHECK_CHANNEL(channel);
1044 left = channels_[channel]->volume_pan_left;
1045 right = channels_[channel]->volume_pan_right;
1046 return 0;
1047 }
1048
1049 // webrtc::VoEAudioProcessing
1050 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1051 ns_enabled_ = enable;
1052 ns_mode_ = mode;
1053 return 0;
1054 }
1055 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1056 enabled = ns_enabled_;
1057 mode = ns_mode_;
1058 return 0;
1059 }
1060
1061 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1062 agc_enabled_ = enable;
1063 agc_mode_ = mode;
1064 return 0;
1065 }
1066 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1067 enabled = agc_enabled_;
1068 mode = agc_mode_;
1069 return 0;
1070 }
1071
1072 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1073 agc_config_ = config;
1074 return 0;
1075 }
1076 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1077 config = agc_config_;
1078 return 0;
1079 }
1080 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1081 ec_enabled_ = enable;
1082 ec_mode_ = mode;
1083 return 0;
1084 }
1085 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1086 enabled = ec_enabled_;
1087 mode = ec_mode_;
1088 return 0;
1089 }
1090 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1091 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1092 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1093 WEBRTC_STUB(DelayOffsetMs, ());
1094 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1095 aecm_mode_ = mode;
1096 cng_enabled_ = enableCNG;
1097 return 0;
1098 }
1099 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1100 mode = aecm_mode_;
1101 enabledCNG = cng_enabled_;
1102 return 0;
1103 }
1104 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1105 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1106 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001107 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1108 webrtc::AgcModes mode)) {
1109 channels_[channel]->rx_agc_enabled = enable;
1110 channels_[channel]->rx_agc_mode = mode;
1111 return 0;
1112 }
1113 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1114 webrtc::AgcModes& mode)) {
1115 enabled = channels_[channel]->rx_agc_enabled;
1116 mode = channels_[channel]->rx_agc_mode;
1117 return 0;
1118 }
1119
1120 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1121 channels_[channel]->rx_agc_config = config;
1122 return 0;
1123 }
1124 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1125 config = channels_[channel]->rx_agc_config;
1126 return 0;
1127 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128
1129 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1130 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1131 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1132 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1133 ec_metrics_enabled_ = enable;
1134 return 0;
1135 }
1136 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1137 enabled = ec_metrics_enabled_;
1138 return 0;
1139 }
1140 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001141 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1142 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001143
1144 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001145 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 WEBRTC_STUB(StopDebugRecording, ());
1147
1148 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1149 typing_detection_enabled_ = enable;
1150 return 0;
1151 }
1152 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1153 enabled = typing_detection_enabled_;
1154 return 0;
1155 }
1156
1157 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1158 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1159 int costPerTyping,
1160 int reportingThreshold,
1161 int penaltyDecay,
1162 int typeEventDelay));
1163 int EnableHighPassFilter(bool enable) {
1164 highpass_filter_enabled_ = enable;
1165 return 0;
1166 }
1167 bool IsHighPassFilterEnabled() {
1168 return highpass_filter_enabled_;
1169 }
1170 bool IsStereoChannelSwappingEnabled() {
1171 return stereo_swapping_enabled_;
1172 }
1173 void EnableStereoChannelSwapping(bool enable) {
1174 stereo_swapping_enabled_ = enable;
1175 }
1176 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1177 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1178 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1179 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1180 }
1181 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1182 return (dtmf_info_.dtmf_event_code == event_code &&
1183 dtmf_info_.dtmf_length_ms == length_ms);
1184 }
1185 // webrtc::VoEExternalMedia
1186 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1187 (int channel, webrtc::ProcessingTypes type,
1188 webrtc::VoEMediaProcess& processObject)) {
1189 WEBRTC_CHECK_CHANNEL(channel);
1190 if (channels_[channel]->media_processor_registered) {
1191 return -1;
1192 }
1193 channels_[channel]->media_processor_registered = true;
1194 media_processor_ = &processObject;
1195 return 0;
1196 }
1197 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1198 (int channel, webrtc::ProcessingTypes type)) {
1199 WEBRTC_CHECK_CHANNEL(channel);
1200 if (!channels_[channel]->media_processor_registered) {
1201 return -1;
1202 }
1203 channels_[channel]->media_processor_registered = false;
1204 media_processor_ = NULL;
1205 return 0;
1206 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1208 webrtc::AudioFrame* frame));
1209 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
Henrik Lundin64dad832015-05-11 12:44:23 +02001210 int GetNetEqCapacity() const {
1211 auto ch = channels_.find(last_channel_);
1212 ASSERT(ch != channels_.end());
1213 return ch->second->neteq_capacity;
1214 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +02001215 bool GetNetEqFastAccelerate() const {
1216 auto ch = channels_.find(last_channel_);
1217 ASSERT(ch != channels_.end());
1218 return ch->second->neteq_fast_accelerate;
1219 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220
1221 private:
1222 int GetNumDevices(int& num) {
1223#ifdef WIN32
1224 num = 1;
1225#else
1226 // On non-Windows platforms VE adds a special entry for the default device,
1227 // so if there is one physical device then there are two entries in the
1228 // list.
1229 num = 2;
1230#endif
1231 return 0;
1232 }
1233
1234 int GetDeviceName(int i, char* name, char* guid) {
1235 const char *s;
1236#ifdef WIN32
1237 if (0 == i) {
1238 s = kFakeDeviceName;
1239 } else {
1240 return -1;
1241 }
1242#else
1243 // See comment above.
1244 if (0 == i) {
1245 s = kFakeDefaultDeviceName;
1246 } else if (1 == i) {
1247 s = kFakeDeviceName;
1248 } else {
1249 return -1;
1250 }
1251#endif
1252 strcpy(name, s);
1253 guid[0] = '\0';
1254 return 0;
1255 }
1256
1257 bool inited_;
1258 int last_channel_;
1259 std::map<int, Channel*> channels_;
1260 bool fail_create_channel_;
1261 const cricket::AudioCodec* const* codecs_;
1262 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001263 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 bool ec_enabled_;
1265 bool ec_metrics_enabled_;
1266 bool cng_enabled_;
1267 bool ns_enabled_;
1268 bool agc_enabled_;
1269 bool highpass_filter_enabled_;
1270 bool stereo_swapping_enabled_;
1271 bool typing_detection_enabled_;
1272 webrtc::EcModes ec_mode_;
1273 webrtc::AecmModes aecm_mode_;
1274 webrtc::NsModes ns_mode_;
1275 webrtc::AgcModes agc_mode_;
1276 webrtc::AgcConfig agc_config_;
1277 webrtc::VoiceEngineObserver* observer_;
1278 int playout_fail_channel_;
1279 int send_fail_channel_;
1280 bool fail_start_recording_microphone_;
1281 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001282 int recording_sample_rate_;
1283 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 DtmfInfo dtmf_info_;
1285 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001286 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001287};
1288
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001289#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291} // namespace cricket
1292
1293#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_