blob: bc95839392974a688b33896c3d64c53680bb1d12 [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,
Fredrik Solenberg09677342015-09-23 12:05:37 +0200190 public webrtc::VoEHardware,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 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),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000213 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000214 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000215 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000216 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 nack(false),
218 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000219 rx_agc_enabled(false),
220 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 cn8_type(13),
222 cn16_type(105),
223 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000224 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 nack_max_packets(0),
226 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000227 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000228 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000229 send_absolute_sender_time_ext_(-1),
Henrik Lundin64dad832015-05-11 12:44:23 +0200230 receive_absolute_sender_time_ext_(-1),
Minyue2013aec2015-05-13 14:14:42 +0200231 associate_send_channel(-1),
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200232 neteq_capacity(-1),
233 neteq_fast_accelerate(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000235 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 }
237 bool external_transport;
238 bool send;
239 bool playout;
240 float volume_scale;
241 float volume_pan_left;
242 float volume_pan_right;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000244 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000245 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000246 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000247 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 bool nack;
249 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000250 bool rx_agc_enabled;
251 webrtc::AgcModes rx_agc_mode;
252 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 int cn8_type;
254 int cn16_type;
255 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000256 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 int nack_max_packets;
258 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000259 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000260 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000261 int send_absolute_sender_time_ext_;
262 int receive_absolute_sender_time_ext_;
Minyue2013aec2015-05-13 14:14:42 +0200263 int associate_send_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 DtmfInfo dtmf_info;
265 std::vector<webrtc::CodecInst> recv_codecs;
266 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000267 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 std::list<std::string> packets;
Henrik Lundin64dad832015-05-11 12:44:23 +0200269 int neteq_capacity;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200270 bool neteq_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 };
272
273 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
274 int num_codecs)
275 : inited_(false),
276 last_channel_(-1),
277 fail_create_channel_(false),
278 codecs_(codecs),
279 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000280 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 ec_enabled_(false),
282 ec_metrics_enabled_(false),
283 cng_enabled_(false),
284 ns_enabled_(false),
285 agc_enabled_(false),
286 highpass_filter_enabled_(false),
287 stereo_swapping_enabled_(false),
288 typing_detection_enabled_(false),
289 ec_mode_(webrtc::kEcDefault),
290 aecm_mode_(webrtc::kAecmSpeakerphone),
291 ns_mode_(webrtc::kNsDefault),
292 agc_mode_(webrtc::kAgcDefault),
293 observer_(NULL),
294 playout_fail_channel_(-1),
295 send_fail_channel_(-1),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000296 recording_sample_rate_(-1),
297 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 media_processor_(NULL) {
299 memset(&agc_config_, 0, sizeof(agc_config_));
300 }
301 ~FakeWebRtcVoiceEngine() {
302 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
303 // destructors, but just in case ...
304 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
305 i != channels_.end(); ++i) {
306 delete i->second;
307 }
308 }
309
310 bool IsExternalMediaProcessorRegistered() const {
311 return media_processor_ != NULL;
312 }
313 bool IsInited() const { return inited_; }
314 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000315 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
316 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
317 iter != channels_.end(); ++iter) {
318 if (local_ssrc == iter->second->send_ssrc)
319 return iter->first;
320 }
321 return -1;
322 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000323 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 bool GetPlayout(int channel) {
325 return channels_[channel]->playout;
326 }
327 bool GetSend(int channel) {
328 return channels_[channel]->send;
329 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 bool GetVAD(int channel) {
331 return channels_[channel]->vad;
332 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100333 bool GetOpusDtx(int channel) {
334 return channels_[channel]->opus_dtx;
335 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000336 bool GetRED(int channel) {
337 return channels_[channel]->red;
338 }
339 bool GetCodecFEC(int channel) {
340 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000342 int GetMaxEncodingBandwidth(int channel) {
343 return channels_[channel]->max_encoding_bandwidth;
344 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 bool GetNACK(int channel) {
346 return channels_[channel]->nack;
347 }
348 int GetNACKMaxPackets(int channel) {
349 return channels_[channel]->nack_max_packets;
350 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000351 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
352 WEBRTC_ASSERT_CHANNEL(channel);
353 return channels_[channel]->last_rtp_packet_time;
354 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 int GetSendCNPayloadType(int channel, bool wideband) {
356 return (wideband) ?
357 channels_[channel]->cn16_type :
358 channels_[channel]->cn8_type;
359 }
360 int GetSendTelephoneEventPayloadType(int channel) {
361 return channels_[channel]->dtmf_type;
362 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000363 int GetSendREDPayloadType(int channel) {
364 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 }
366 bool CheckPacket(int channel, const void* data, size_t len) {
367 bool result = !CheckNoPacket(channel);
368 if (result) {
369 std::string packet = channels_[channel]->packets.front();
370 result = (packet == std::string(static_cast<const char*>(data), len));
371 channels_[channel]->packets.pop_front();
372 }
373 return result;
374 }
375 bool CheckNoPacket(int channel) {
376 return channels_[channel]->packets.empty();
377 }
378 void TriggerCallbackOnError(int channel_num, int err_code) {
henrikg91d6ede2015-09-17 00:24:34 -0700379 RTC_DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 observer_->CallbackOnError(channel_num, err_code);
381 }
382 void set_playout_fail_channel(int channel) {
383 playout_fail_channel_ = channel;
384 }
385 void set_send_fail_channel(int channel) {
386 send_fail_channel_ = channel;
387 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 void set_fail_create_channel(bool fail_create_channel) {
389 fail_create_channel_ = fail_create_channel;
390 }
391 void TriggerProcessPacket(MediaProcessorDirection direction) {
392 webrtc::ProcessingTypes pt =
393 (direction == cricket::MPD_TX) ?
394 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
395 if (media_processor_ != NULL) {
396 media_processor_->Process(0,
397 pt,
398 NULL,
399 0,
400 0,
401 true);
402 }
403 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200404 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000405 if (fail_create_channel_) {
406 return -1;
407 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000408 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000409 for (int i = 0; i < NumOfCodecs(); ++i) {
410 webrtc::CodecInst codec;
411 GetCodec(i, codec);
412 ch->recv_codecs.push_back(codec);
413 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200414 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
415 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
416 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200417 ch->neteq_fast_accelerate =
418 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000419 channels_[++last_channel_] = ch;
420 return last_channel_;
421 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000422 int GetSendRtpExtensionId(int channel, const std::string& extension) {
423 WEBRTC_ASSERT_CHANNEL(channel);
424 if (extension == kRtpAudioLevelHeaderExtension) {
425 return channels_[channel]->send_audio_level_ext_;
426 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
427 return channels_[channel]->send_absolute_sender_time_ext_;
428 }
429 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000430 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000431 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
432 WEBRTC_ASSERT_CHANNEL(channel);
433 if (extension == kRtpAudioLevelHeaderExtension) {
434 return channels_[channel]->receive_audio_level_ext_;
435 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
436 return channels_[channel]->receive_absolute_sender_time_ext_;
437 }
438 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000439 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000441 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
442
Minyue2013aec2015-05-13 14:14:42 +0200443 int GetAssociateSendChannel(int channel) {
444 return channels_[channel]->associate_send_channel;
445 }
446
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 WEBRTC_STUB(Release, ());
448
449 // webrtc::VoEBase
450 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
451 webrtc::VoiceEngineObserver& observer)) {
452 observer_ = &observer;
453 return 0;
454 }
455 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
456 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
457 webrtc::AudioProcessing* audioproc)) {
458 inited_ = true;
459 return 0;
460 }
461 WEBRTC_FUNC(Terminate, ()) {
462 inited_ = false;
463 return 0;
464 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000465 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000466 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200469 webrtc::Config empty_config;
470 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200472 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
473 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000474 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 WEBRTC_FUNC(DeleteChannel, (int channel)) {
476 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200477 for (const auto& ch : channels_) {
478 if (ch.second->associate_send_channel == channel) {
479 ch.second->associate_send_channel = -1;
480 }
481 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 delete channels_[channel];
483 channels_.erase(channel);
484 return 0;
485 }
486 WEBRTC_STUB(StartReceive, (int channel));
487 WEBRTC_FUNC(StartPlayout, (int channel)) {
488 if (playout_fail_channel_ != channel) {
489 WEBRTC_CHECK_CHANNEL(channel);
490 channels_[channel]->playout = true;
491 return 0;
492 } else {
493 // When playout_fail_channel_ == channel, fail the StartPlayout on this
494 // channel.
495 return -1;
496 }
497 }
498 WEBRTC_FUNC(StartSend, (int channel)) {
499 if (send_fail_channel_ != channel) {
500 WEBRTC_CHECK_CHANNEL(channel);
501 channels_[channel]->send = true;
502 return 0;
503 } else {
504 // When send_fail_channel_ == channel, fail the StartSend on this
505 // channel.
506 return -1;
507 }
508 }
509 WEBRTC_STUB(StopReceive, (int channel));
510 WEBRTC_FUNC(StopPlayout, (int channel)) {
511 WEBRTC_CHECK_CHANNEL(channel);
512 channels_[channel]->playout = false;
513 return 0;
514 }
515 WEBRTC_FUNC(StopSend, (int channel)) {
516 WEBRTC_CHECK_CHANNEL(channel);
517 channels_[channel]->send = false;
518 return 0;
519 }
520 WEBRTC_STUB(GetVersion, (char version[1024]));
521 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200522 WEBRTC_FUNC(AssociateSendChannel, (int channel,
523 int accociate_send_channel)) {
524 WEBRTC_CHECK_CHANNEL(channel);
525 channels_[channel]->associate_send_channel = accociate_send_channel;
526 return 0;
527 }
ivocb04965c2015-09-09 00:09:43 -0700528 webrtc::RtcEventLog* GetEventLog() { return nullptr; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529
530 // webrtc::VoECodec
531 WEBRTC_FUNC(NumOfCodecs, ()) {
532 return num_codecs_;
533 }
534 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
535 if (index < 0 || index >= NumOfCodecs()) {
536 return -1;
537 }
538 const cricket::AudioCodec& c(*codecs_[index]);
539 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000540 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 codec.plfreq = c.clockrate;
542 codec.pacsize = 0;
543 codec.channels = c.channels;
544 codec.rate = c.bitrate;
545 return 0;
546 }
547 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
548 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000549 // To match the behavior of the real implementation.
550 if (_stricmp(codec.plname, "telephone-event") == 0 ||
551 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
552 _stricmp(codec.plname, "CN") == 0 ||
553 _stricmp(codec.plname, "red") == 0 ) {
554 return -1;
555 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000557 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 return 0;
559 }
560 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
561 WEBRTC_CHECK_CHANNEL(channel);
562 codec = channels_[channel]->send_codec;
563 return 0;
564 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200565 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000566 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
567 WEBRTC_CHECK_CHANNEL(channel);
568 const Channel* c = channels_[channel];
569 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
570 it_packet != c->packets.end(); ++it_packet) {
571 int pltype;
572 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
573 continue;
574 }
575 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
576 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
577 ++it_codec) {
578 if (it_codec->pltype == pltype) {
579 codec = *it_codec;
580 return 0;
581 }
582 }
583 }
584 return -1;
585 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586 WEBRTC_FUNC(SetRecPayloadType, (int channel,
587 const webrtc::CodecInst& codec)) {
588 WEBRTC_CHECK_CHANNEL(channel);
589 Channel* ch = channels_[channel];
590 if (ch->playout)
591 return -1; // Channel is in use.
592 // Check if something else already has this slot.
593 if (codec.pltype != -1) {
594 for (std::vector<webrtc::CodecInst>::iterator it =
595 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
596 if (it->pltype == codec.pltype &&
597 _stricmp(it->plname, codec.plname) != 0) {
598 return -1;
599 }
600 }
601 }
602 // Otherwise try to find this codec and update its payload type.
603 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
604 it != ch->recv_codecs.end(); ++it) {
605 if (strcmp(it->plname, codec.plname) == 0 &&
606 it->plfreq == codec.plfreq) {
607 it->pltype = codec.pltype;
608 it->channels = codec.channels;
609 return 0;
610 }
611 }
612 return -1; // not found
613 }
614 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
615 webrtc::PayloadFrequencies frequency)) {
616 WEBRTC_CHECK_CHANNEL(channel);
617 if (frequency == webrtc::kFreq8000Hz) {
618 channels_[channel]->cn8_type = type;
619 } else if (frequency == webrtc::kFreq16000Hz) {
620 channels_[channel]->cn16_type = type;
621 }
622 return 0;
623 }
624 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
625 WEBRTC_CHECK_CHANNEL(channel);
626 Channel* ch = channels_[channel];
627 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
628 it != ch->recv_codecs.end(); ++it) {
629 if (strcmp(it->plname, codec.plname) == 0 &&
630 it->plfreq == codec.plfreq &&
631 it->channels == codec.channels &&
632 it->pltype != -1) {
633 codec.pltype = it->pltype;
634 return 0;
635 }
636 }
637 return -1; // not found
638 }
639 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
640 bool disableDTX)) {
641 WEBRTC_CHECK_CHANNEL(channel);
642 if (channels_[channel]->send_codec.channels == 2) {
643 // Replicating VoE behavior; VAD cannot be enabled for stereo.
644 return -1;
645 }
646 channels_[channel]->vad = enable;
647 return 0;
648 }
649 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
650 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000651
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000652 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
653 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000654 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000655 // Return -1 if current send codec is not Opus.
656 // TODO(minyue): Excludes other codecs if they support inband FEC.
657 return -1;
658 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000659 channels_[channel]->codec_fec = enable;
660 return 0;
661 }
662 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
663 WEBRTC_CHECK_CHANNEL(channel);
664 enable = channels_[channel]->codec_fec;
665 return 0;
666 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000667
668 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
669 WEBRTC_CHECK_CHANNEL(channel);
670 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
671 // Return -1 if current send codec is not Opus.
672 return -1;
673 }
674 if (frequency_hz <= 8000)
675 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
676 else if (frequency_hz <= 12000)
677 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
678 else if (frequency_hz <= 16000)
679 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
680 else if (frequency_hz <= 24000)
681 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
682 else
683 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
684 return 0;
685 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000687 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
688 WEBRTC_CHECK_CHANNEL(channel);
689 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
690 // Return -1 if current send codec is not Opus.
691 return -1;
692 }
693 channels_[channel]->opus_dtx = enable_dtx;
694 return 0;
695 }
696
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 // webrtc::VoEDtmf
698 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
699 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
700 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
701 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
702 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
703 return 0;
704 }
705
706 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
707 (int channel, unsigned char type)) {
708 channels_[channel]->dtmf_type = type;
709 return 0;
710 };
711 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
712 (int channel, unsigned char& type));
713
714 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
715 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 WEBRTC_FUNC(PlayDtmfTone,
718 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
719 dtmf_info_.dtmf_event_code = event_code;
720 dtmf_info_.dtmf_length_ms = length_ms;
721 return 0;
722 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
726 return GetNumDevices(num);
727 }
728 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
729 return GetNumDevices(num);
730 }
731 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
732 return GetDeviceName(i, name, guid);
733 }
734 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
735 return GetDeviceName(i, name, guid);
736 }
737 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
738 WEBRTC_STUB(SetPlayoutDevice, (int));
739 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
740 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000741 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
742 recording_sample_rate_ = samples_per_sec;
743 return 0;
744 }
745 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
746 *samples_per_sec = recording_sample_rate_;
747 return 0;
748 }
749 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
750 playout_sample_rate_ = samples_per_sec;
751 return 0;
752 }
753 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
754 *samples_per_sec = playout_sample_rate_;
755 return 0;
756 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000758 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759
760 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000761 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
762 webrtc::NetworkStatistics& ns)) {
763 WEBRTC_CHECK_CHANNEL(channel);
764 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
765 return 0;
766 }
767
wu@webrtc.org24301a62013-12-13 19:17:43 +0000768 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
769 webrtc::AudioDecodingCallStats*)) {
770 WEBRTC_CHECK_CHANNEL(channel);
771 return 0;
772 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773
774 // webrtc::VoENetwork
775 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
776 webrtc::Transport& transport)) {
777 WEBRTC_CHECK_CHANNEL(channel);
778 channels_[channel]->external_transport = true;
779 return 0;
780 }
781 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
782 WEBRTC_CHECK_CHANNEL(channel);
783 channels_[channel]->external_transport = false;
784 return 0;
785 }
786 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000787 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 WEBRTC_CHECK_CHANNEL(channel);
789 if (!channels_[channel]->external_transport) return -1;
790 channels_[channel]->packets.push_back(
791 std::string(static_cast<const char*>(data), length));
792 return 0;
793 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000794 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000795 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000796 const webrtc::PacketTime& packet_time)) {
797 WEBRTC_CHECK_CHANNEL(channel);
798 if (ReceivedRTPPacket(channel, data, length) == -1) {
799 return -1;
800 }
801 channels_[channel]->last_rtp_packet_time = packet_time;
802 return 0;
803 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000804
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000806 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807
808 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
810 WEBRTC_CHECK_CHANNEL(channel);
811 channels_[channel]->send_ssrc = ssrc;
812 return 0;
813 }
814 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
815 WEBRTC_CHECK_CHANNEL(channel);
816 ssrc = channels_[channel]->send_ssrc;
817 return 0;
818 }
819 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000820 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
821 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000823 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
824 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 return 0;
826 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000827 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
828 unsigned char id)) {
829 WEBRTC_CHECK_CHANNEL(channel);
830 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
831 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
832 return 0;
833 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000834 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
835 unsigned char id)) {
836 WEBRTC_CHECK_CHANNEL(channel);
837 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
838 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
839 return 0;
840 }
841 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
842 unsigned char id)) {
843 WEBRTC_CHECK_CHANNEL(channel);
844 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
845 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
846 return 0;
847 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000848
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
850 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
851 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
852 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
853 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
854 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
855 unsigned int& NTPLow,
856 unsigned int& timestamp,
857 unsigned int& playoutTimestamp,
858 unsigned int* jitter,
859 unsigned short* fractionLost));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
861 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
862 WEBRTC_CHECK_CHANNEL(channel);
863 webrtc::ReportBlock block;
864 block.source_SSRC = channels_[channel]->send_ssrc;
865 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
866 if (send_codec.pltype >= 0) {
867 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
868 if (send_codec.plfreq / 1000 > 0) {
869 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
870 }
871 block.cumulative_num_packets_lost = kIntStatValue;
872 block.extended_highest_sequence_number = kIntStatValue;
873 receive_blocks->push_back(block);
874 }
875 return 0;
876 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
878 unsigned int& maxJitterMs,
879 unsigned int& discardedPackets));
880 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
881 WEBRTC_CHECK_CHANNEL(channel);
882 stats.fractionLost = static_cast<int16>(kIntStatValue);
883 stats.cumulativeLost = kIntStatValue;
884 stats.extendedMax = kIntStatValue;
885 stats.jitterSamples = kIntStatValue;
886 stats.rttMs = kIntStatValue;
887 stats.bytesSent = kIntStatValue;
888 stats.packetsSent = kIntStatValue;
889 stats.bytesReceived = kIntStatValue;
890 stats.packetsReceived = kIntStatValue;
891 return 0;
892 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000893 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000894 return SetFECStatus(channel, enable, redPayloadtype);
895 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000896 // TODO(minyue): remove the below function when transition to SetREDStatus
897 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
899 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000900 channels_[channel]->red = enable;
901 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 return 0;
903 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000904 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000905 return GetFECStatus(channel, enable, redPayloadtype);
906 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000907 // TODO(minyue): remove the below function when transition to GetREDStatus
908 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
910 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000911 enable = channels_[channel]->red;
912 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 return 0;
914 }
915 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
916 WEBRTC_CHECK_CHANNEL(channel);
917 channels_[channel]->nack = enable;
918 channels_[channel]->nack_max_packets = maxNoPackets;
919 return 0;
920 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921
922 // webrtc::VoEVideoSync
923 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
924 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000925 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
927 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
928 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
929 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
930 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
931 int* playout_buffer_delay_ms));
932 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
933
934 // webrtc::VoEVolumeControl
935 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
936 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 WEBRTC_STUB(SetMicVolume, (unsigned int));
938 WEBRTC_STUB(GetMicVolume, (unsigned int&));
939 WEBRTC_STUB(SetInputMute, (int, bool));
940 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
942 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
943 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
944 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
945 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
946 WEBRTC_CHECK_CHANNEL(channel);
947 channels_[channel]->volume_scale= scale;
948 return 0;
949 }
950 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
951 WEBRTC_CHECK_CHANNEL(channel);
952 scale = channels_[channel]->volume_scale;
953 return 0;
954 }
955 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
956 WEBRTC_CHECK_CHANNEL(channel);
957 channels_[channel]->volume_pan_left = left;
958 channels_[channel]->volume_pan_right = right;
959 return 0;
960 }
961 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
962 WEBRTC_CHECK_CHANNEL(channel);
963 left = channels_[channel]->volume_pan_left;
964 right = channels_[channel]->volume_pan_right;
965 return 0;
966 }
967
968 // webrtc::VoEAudioProcessing
969 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
970 ns_enabled_ = enable;
971 ns_mode_ = mode;
972 return 0;
973 }
974 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
975 enabled = ns_enabled_;
976 mode = ns_mode_;
977 return 0;
978 }
979
980 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
981 agc_enabled_ = enable;
982 agc_mode_ = mode;
983 return 0;
984 }
985 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
986 enabled = agc_enabled_;
987 mode = agc_mode_;
988 return 0;
989 }
990
991 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
992 agc_config_ = config;
993 return 0;
994 }
995 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
996 config = agc_config_;
997 return 0;
998 }
999 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1000 ec_enabled_ = enable;
1001 ec_mode_ = mode;
1002 return 0;
1003 }
1004 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1005 enabled = ec_enabled_;
1006 mode = ec_mode_;
1007 return 0;
1008 }
1009 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1010 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1011 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1012 WEBRTC_STUB(DelayOffsetMs, ());
1013 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1014 aecm_mode_ = mode;
1015 cng_enabled_ = enableCNG;
1016 return 0;
1017 }
1018 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1019 mode = aecm_mode_;
1020 enabledCNG = cng_enabled_;
1021 return 0;
1022 }
1023 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1024 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1025 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001026 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1027 webrtc::AgcModes mode)) {
1028 channels_[channel]->rx_agc_enabled = enable;
1029 channels_[channel]->rx_agc_mode = mode;
1030 return 0;
1031 }
1032 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1033 webrtc::AgcModes& mode)) {
1034 enabled = channels_[channel]->rx_agc_enabled;
1035 mode = channels_[channel]->rx_agc_mode;
1036 return 0;
1037 }
1038
1039 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1040 channels_[channel]->rx_agc_config = config;
1041 return 0;
1042 }
1043 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1044 config = channels_[channel]->rx_agc_config;
1045 return 0;
1046 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047
1048 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1049 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1050 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1051 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1052 ec_metrics_enabled_ = enable;
1053 return 0;
1054 }
1055 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1056 enabled = ec_metrics_enabled_;
1057 return 0;
1058 }
1059 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001060 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1061 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062
1063 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001064 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 WEBRTC_STUB(StopDebugRecording, ());
1066
1067 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1068 typing_detection_enabled_ = enable;
1069 return 0;
1070 }
1071 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1072 enabled = typing_detection_enabled_;
1073 return 0;
1074 }
1075
1076 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1077 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1078 int costPerTyping,
1079 int reportingThreshold,
1080 int penaltyDecay,
1081 int typeEventDelay));
1082 int EnableHighPassFilter(bool enable) {
1083 highpass_filter_enabled_ = enable;
1084 return 0;
1085 }
1086 bool IsHighPassFilterEnabled() {
1087 return highpass_filter_enabled_;
1088 }
1089 bool IsStereoChannelSwappingEnabled() {
1090 return stereo_swapping_enabled_;
1091 }
1092 void EnableStereoChannelSwapping(bool enable) {
1093 stereo_swapping_enabled_ = enable;
1094 }
1095 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1096 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1097 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1098 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1099 }
1100 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1101 return (dtmf_info_.dtmf_event_code == event_code &&
1102 dtmf_info_.dtmf_length_ms == length_ms);
1103 }
1104 // webrtc::VoEExternalMedia
1105 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1106 (int channel, webrtc::ProcessingTypes type,
1107 webrtc::VoEMediaProcess& processObject)) {
1108 WEBRTC_CHECK_CHANNEL(channel);
1109 if (channels_[channel]->media_processor_registered) {
1110 return -1;
1111 }
1112 channels_[channel]->media_processor_registered = true;
1113 media_processor_ = &processObject;
1114 return 0;
1115 }
1116 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1117 (int channel, webrtc::ProcessingTypes type)) {
1118 WEBRTC_CHECK_CHANNEL(channel);
1119 if (!channels_[channel]->media_processor_registered) {
1120 return -1;
1121 }
1122 channels_[channel]->media_processor_registered = false;
1123 media_processor_ = NULL;
1124 return 0;
1125 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1127 webrtc::AudioFrame* frame));
1128 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
Henrik Lundin64dad832015-05-11 12:44:23 +02001129 int GetNetEqCapacity() const {
1130 auto ch = channels_.find(last_channel_);
1131 ASSERT(ch != channels_.end());
1132 return ch->second->neteq_capacity;
1133 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +02001134 bool GetNetEqFastAccelerate() const {
1135 auto ch = channels_.find(last_channel_);
1136 ASSERT(ch != channels_.end());
1137 return ch->second->neteq_fast_accelerate;
1138 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139
1140 private:
1141 int GetNumDevices(int& num) {
1142#ifdef WIN32
1143 num = 1;
1144#else
1145 // On non-Windows platforms VE adds a special entry for the default device,
1146 // so if there is one physical device then there are two entries in the
1147 // list.
1148 num = 2;
1149#endif
1150 return 0;
1151 }
1152
1153 int GetDeviceName(int i, char* name, char* guid) {
1154 const char *s;
1155#ifdef WIN32
1156 if (0 == i) {
1157 s = kFakeDeviceName;
1158 } else {
1159 return -1;
1160 }
1161#else
1162 // See comment above.
1163 if (0 == i) {
1164 s = kFakeDefaultDeviceName;
1165 } else if (1 == i) {
1166 s = kFakeDeviceName;
1167 } else {
1168 return -1;
1169 }
1170#endif
1171 strcpy(name, s);
1172 guid[0] = '\0';
1173 return 0;
1174 }
1175
1176 bool inited_;
1177 int last_channel_;
1178 std::map<int, Channel*> channels_;
1179 bool fail_create_channel_;
1180 const cricket::AudioCodec* const* codecs_;
1181 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001182 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183 bool ec_enabled_;
1184 bool ec_metrics_enabled_;
1185 bool cng_enabled_;
1186 bool ns_enabled_;
1187 bool agc_enabled_;
1188 bool highpass_filter_enabled_;
1189 bool stereo_swapping_enabled_;
1190 bool typing_detection_enabled_;
1191 webrtc::EcModes ec_mode_;
1192 webrtc::AecmModes aecm_mode_;
1193 webrtc::NsModes ns_mode_;
1194 webrtc::AgcModes agc_mode_;
1195 webrtc::AgcConfig agc_config_;
1196 webrtc::VoiceEngineObserver* observer_;
1197 int playout_fail_channel_;
1198 int send_fail_channel_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001199 int recording_sample_rate_;
1200 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001201 DtmfInfo dtmf_info_;
1202 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001203 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001204};
1205
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001206#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1207
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208} // namespace cricket
1209
1210#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_