blob: 419170b24dc471bdb2c1a8c2ec9ee7fe6fde6a5c [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2010 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_
29#define TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_
30
31#include <list>
32#include <map>
33#include <vector>
34
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/codec.h"
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +000036#include "talk/media/base/rtputils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/media/base/voiceprocessor.h"
38#include "talk/media/webrtc/fakewebrtccommon.h"
39#include "talk/media/webrtc/webrtcvoe.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "webrtc/base/basictypes.h"
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020041#include "webrtc/base/checks.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "webrtc/base/gunit.h"
43#include "webrtc/base/stringutils.h"
Henrik Lundin64dad832015-05-11 12:44:23 +020044#include "webrtc/config.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000045#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000046
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047namespace cricket {
48
49// Function returning stats will return these values
50// for all values based on type.
51const int kIntStatValue = 123;
52const float kFractionLostStatValue = 0.5;
53
54static const char kFakeDefaultDeviceName[] = "Fake Default";
55static const int kFakeDefaultDeviceId = -1;
56static const char kFakeDeviceName[] = "Fake Device";
57#ifdef WIN32
58static const int kFakeDeviceId = 0;
59#else
60static const int kFakeDeviceId = 1;
61#endif
62
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000063static const int kOpusBandwidthNb = 4000;
64static const int kOpusBandwidthMb = 6000;
65static const int kOpusBandwidthWb = 8000;
66static const int kOpusBandwidthSwb = 12000;
67static const int kOpusBandwidthFb = 20000;
68
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +000069static const webrtc::NetworkStatistics kNetStats = {
70 1, // uint16_t currentBufferSize;
71 2, // uint16_t preferredBufferSize;
72 true, // bool jitterPeaksFound;
73 1234, // uint16_t currentPacketLossRate;
74 567, // uint16_t currentDiscardRate;
75 8901, // uint16_t currentExpandRate;
76 234, // uint16_t currentSpeechExpandRate;
77 5678, // uint16_t currentPreemptiveRate;
78 9012, // uint16_t currentAccelerateRate;
79 3456, // uint16_t currentSecondaryDecodedRate;
80 7890, // int32_t clockDriftPPM;
81 54, // meanWaitingTimeMs;
82 32, // int medianWaitingTimeMs;
83 1, // int minWaitingTimeMs;
84 98, // int maxWaitingTimeMs;
85 7654, // int addedSamples;
86}; // These random but non-trivial numbers are used for testing.
87
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +020088#define WEBRTC_CHECK_CHANNEL(channel) \
89 if (channels_.find(channel) == channels_.end()) return -1;
90
91#define WEBRTC_ASSERT_CHANNEL(channel) \
92 DCHECK(channels_.find(channel) != channels_.end());
93
henrike@webrtc.org79047f92014-03-06 23:46:59 +000094// Verify the header extension ID, if enabled, is within the bounds specified in
95// [RFC5285]: 1-14 inclusive.
96#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
97 do { \
98 if (enable && (id < 1 || id > 14)) { \
99 return -1; \
100 } \
101 } while (0);
102
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000103class FakeAudioProcessing : public webrtc::AudioProcessing {
104 public:
105 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
106
107 WEBRTC_STUB(Initialize, ())
108 WEBRTC_STUB(Initialize, (
109 int input_sample_rate_hz,
110 int output_sample_rate_hz,
111 int reverse_sample_rate_hz,
112 webrtc::AudioProcessing::ChannelLayout input_layout,
113 webrtc::AudioProcessing::ChannelLayout output_layout,
114 webrtc::AudioProcessing::ChannelLayout reverse_layout));
115
116 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
117 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
118 }
119
120 WEBRTC_STUB(set_sample_rate_hz, (int rate));
121 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
122 WEBRTC_STUB_CONST(sample_rate_hz, ());
123 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
124 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
125 WEBRTC_STUB_CONST(num_input_channels, ());
126 WEBRTC_STUB_CONST(num_output_channels, ());
127 WEBRTC_STUB_CONST(num_reverse_channels, ());
128 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
129 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
130 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
131 WEBRTC_STUB(ProcessStream, (
132 const float* const* src,
133 int samples_per_channel,
134 int input_sample_rate_hz,
135 webrtc::AudioProcessing::ChannelLayout input_layout,
136 int output_sample_rate_hz,
137 webrtc::AudioProcessing::ChannelLayout output_layout,
138 float* const* dest));
139 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
140 WEBRTC_STUB(AnalyzeReverseStream, (
141 const float* const* data,
142 int samples_per_channel,
143 int sample_rate_hz,
144 webrtc::AudioProcessing::ChannelLayout layout));
145 WEBRTC_STUB(set_stream_delay_ms, (int delay));
146 WEBRTC_STUB_CONST(stream_delay_ms, ());
147 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
148 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
149 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
150 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
151 WEBRTC_STUB_CONST(delay_offset_ms, ());
152 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
153 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
154 WEBRTC_STUB(StopDebugRecording, ());
Bjorn Volcker4e7aa432015-07-07 11:50:05 +0200155 WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000156 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
157 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000158 return NULL;
159 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000160 webrtc::GainControl* gain_control() const override { return NULL; }
161 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
162 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
163 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
164 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000165
166 bool experimental_ns_enabled() {
167 return experimental_ns_enabled_;
168 }
169
170 private:
171 bool experimental_ns_enabled_;
172};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000173
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174class FakeWebRtcVoiceEngine
175 : public webrtc::VoEAudioProcessing,
176 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
177 public webrtc::VoEFile, public webrtc::VoEHardware,
178 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
179 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
180 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
181 public:
182 struct DtmfInfo {
183 DtmfInfo()
184 : dtmf_event_code(-1),
185 dtmf_out_of_band(false),
186 dtmf_length_ms(-1) {}
187 int dtmf_event_code;
188 bool dtmf_out_of_band;
189 int dtmf_length_ms;
190 };
191 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000192 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 : external_transport(false),
194 send(false),
195 playout(false),
196 volume_scale(1.0),
197 volume_pan_left(1.0),
198 volume_pan_right(1.0),
199 file(false),
200 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000201 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000202 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000203 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000204 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 nack(false),
206 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000207 rx_agc_enabled(false),
208 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 cn8_type(13),
210 cn16_type(105),
211 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000212 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 nack_max_packets(0),
214 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000215 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000216 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000217 send_absolute_sender_time_ext_(-1),
Henrik Lundin64dad832015-05-11 12:44:23 +0200218 receive_absolute_sender_time_ext_(-1),
Minyue2013aec2015-05-13 14:14:42 +0200219 associate_send_channel(-1),
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200220 neteq_capacity(-1),
221 neteq_fast_accelerate(false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000223 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 }
225 bool external_transport;
226 bool send;
227 bool playout;
228 float volume_scale;
229 float volume_pan_left;
230 float volume_pan_right;
231 bool file;
232 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000233 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000234 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000235 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000236 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 bool nack;
238 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000239 bool rx_agc_enabled;
240 webrtc::AgcModes rx_agc_mode;
241 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 int cn8_type;
243 int cn16_type;
244 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000245 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 int nack_max_packets;
247 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000248 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000249 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000250 int send_absolute_sender_time_ext_;
251 int receive_absolute_sender_time_ext_;
Minyue2013aec2015-05-13 14:14:42 +0200252 int associate_send_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 DtmfInfo dtmf_info;
254 std::vector<webrtc::CodecInst> recv_codecs;
255 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000256 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 std::list<std::string> packets;
Henrik Lundin64dad832015-05-11 12:44:23 +0200258 int neteq_capacity;
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200259 bool neteq_fast_accelerate;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 };
261
262 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
263 int num_codecs)
264 : inited_(false),
265 last_channel_(-1),
266 fail_create_channel_(false),
267 codecs_(codecs),
268 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000269 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 ec_enabled_(false),
271 ec_metrics_enabled_(false),
272 cng_enabled_(false),
273 ns_enabled_(false),
274 agc_enabled_(false),
275 highpass_filter_enabled_(false),
276 stereo_swapping_enabled_(false),
277 typing_detection_enabled_(false),
278 ec_mode_(webrtc::kEcDefault),
279 aecm_mode_(webrtc::kAecmSpeakerphone),
280 ns_mode_(webrtc::kNsDefault),
281 agc_mode_(webrtc::kAgcDefault),
282 observer_(NULL),
283 playout_fail_channel_(-1),
284 send_fail_channel_(-1),
285 fail_start_recording_microphone_(false),
286 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000287 recording_sample_rate_(-1),
288 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 media_processor_(NULL) {
290 memset(&agc_config_, 0, sizeof(agc_config_));
291 }
292 ~FakeWebRtcVoiceEngine() {
293 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
294 // destructors, but just in case ...
295 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
296 i != channels_.end(); ++i) {
297 delete i->second;
298 }
299 }
300
301 bool IsExternalMediaProcessorRegistered() const {
302 return media_processor_ != NULL;
303 }
304 bool IsInited() const { return inited_; }
305 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000306 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
307 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
308 iter != channels_.end(); ++iter) {
309 if (local_ssrc == iter->second->send_ssrc)
310 return iter->first;
311 }
312 return -1;
313 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000314 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 bool GetPlayout(int channel) {
316 return channels_[channel]->playout;
317 }
318 bool GetSend(int channel) {
319 return channels_[channel]->send;
320 }
321 bool GetRecordingMicrophone() {
322 return recording_microphone_;
323 }
324 bool GetVAD(int channel) {
325 return channels_[channel]->vad;
326 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100327 bool GetOpusDtx(int channel) {
328 return channels_[channel]->opus_dtx;
329 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000330 bool GetRED(int channel) {
331 return channels_[channel]->red;
332 }
333 bool GetCodecFEC(int channel) {
334 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000336 int GetMaxEncodingBandwidth(int channel) {
337 return channels_[channel]->max_encoding_bandwidth;
338 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 bool GetNACK(int channel) {
340 return channels_[channel]->nack;
341 }
342 int GetNACKMaxPackets(int channel) {
343 return channels_[channel]->nack_max_packets;
344 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000345 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
346 WEBRTC_ASSERT_CHANNEL(channel);
347 return channels_[channel]->last_rtp_packet_time;
348 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 int GetSendCNPayloadType(int channel, bool wideband) {
350 return (wideband) ?
351 channels_[channel]->cn16_type :
352 channels_[channel]->cn8_type;
353 }
354 int GetSendTelephoneEventPayloadType(int channel) {
355 return channels_[channel]->dtmf_type;
356 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000357 int GetSendREDPayloadType(int channel) {
358 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 }
360 bool CheckPacket(int channel, const void* data, size_t len) {
361 bool result = !CheckNoPacket(channel);
362 if (result) {
363 std::string packet = channels_[channel]->packets.front();
364 result = (packet == std::string(static_cast<const char*>(data), len));
365 channels_[channel]->packets.pop_front();
366 }
367 return result;
368 }
369 bool CheckNoPacket(int channel) {
370 return channels_[channel]->packets.empty();
371 }
372 void TriggerCallbackOnError(int channel_num, int err_code) {
Fredrik Solenbergd3ddc1b2015-05-07 17:07:34 +0200373 DCHECK(observer_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 observer_->CallbackOnError(channel_num, err_code);
375 }
376 void set_playout_fail_channel(int channel) {
377 playout_fail_channel_ = channel;
378 }
379 void set_send_fail_channel(int channel) {
380 send_fail_channel_ = channel;
381 }
382 void set_fail_start_recording_microphone(
383 bool fail_start_recording_microphone) {
384 fail_start_recording_microphone_ = fail_start_recording_microphone;
385 }
386 void set_fail_create_channel(bool fail_create_channel) {
387 fail_create_channel_ = fail_create_channel;
388 }
389 void TriggerProcessPacket(MediaProcessorDirection direction) {
390 webrtc::ProcessingTypes pt =
391 (direction == cricket::MPD_TX) ?
392 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
393 if (media_processor_ != NULL) {
394 media_processor_->Process(0,
395 pt,
396 NULL,
397 0,
398 0,
399 true);
400 }
401 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200402 int AddChannel(const webrtc::Config& config) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000403 if (fail_create_channel_) {
404 return -1;
405 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000406 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000407 for (int i = 0; i < NumOfCodecs(); ++i) {
408 webrtc::CodecInst codec;
409 GetCodec(i, codec);
410 ch->recv_codecs.push_back(codec);
411 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200412 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
413 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
414 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +0200415 ch->neteq_fast_accelerate =
416 config.Get<webrtc::NetEqFastAccelerate>().enabled;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000417 channels_[++last_channel_] = ch;
418 return last_channel_;
419 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000420 int GetSendRtpExtensionId(int channel, const std::string& extension) {
421 WEBRTC_ASSERT_CHANNEL(channel);
422 if (extension == kRtpAudioLevelHeaderExtension) {
423 return channels_[channel]->send_audio_level_ext_;
424 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
425 return channels_[channel]->send_absolute_sender_time_ext_;
426 }
427 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000428 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000429 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
430 WEBRTC_ASSERT_CHANNEL(channel);
431 if (extension == kRtpAudioLevelHeaderExtension) {
432 return channels_[channel]->receive_audio_level_ext_;
433 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
434 return channels_[channel]->receive_absolute_sender_time_ext_;
435 }
436 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000437 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000439 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
440
Minyue2013aec2015-05-13 14:14:42 +0200441 int GetAssociateSendChannel(int channel) {
442 return channels_[channel]->associate_send_channel;
443 }
444
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 WEBRTC_STUB(Release, ());
446
447 // webrtc::VoEBase
448 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
449 webrtc::VoiceEngineObserver& observer)) {
450 observer_ = &observer;
451 return 0;
452 }
453 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
454 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
455 webrtc::AudioProcessing* audioproc)) {
456 inited_ = true;
457 return 0;
458 }
459 WEBRTC_FUNC(Terminate, ()) {
460 inited_ = false;
461 return 0;
462 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000463 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000464 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 WEBRTC_FUNC(CreateChannel, ()) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200467 webrtc::Config empty_config;
468 return AddChannel(empty_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 }
Henrik Lundin64dad832015-05-11 12:44:23 +0200470 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
471 return AddChannel(config);
wu@webrtc.org364f2042013-11-20 21:49:41 +0000472 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 WEBRTC_FUNC(DeleteChannel, (int channel)) {
474 WEBRTC_CHECK_CHANNEL(channel);
Minyue2013aec2015-05-13 14:14:42 +0200475 for (const auto& ch : channels_) {
476 if (ch.second->associate_send_channel == channel) {
477 ch.second->associate_send_channel = -1;
478 }
479 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 delete channels_[channel];
481 channels_.erase(channel);
482 return 0;
483 }
484 WEBRTC_STUB(StartReceive, (int channel));
485 WEBRTC_FUNC(StartPlayout, (int channel)) {
486 if (playout_fail_channel_ != channel) {
487 WEBRTC_CHECK_CHANNEL(channel);
488 channels_[channel]->playout = true;
489 return 0;
490 } else {
491 // When playout_fail_channel_ == channel, fail the StartPlayout on this
492 // channel.
493 return -1;
494 }
495 }
496 WEBRTC_FUNC(StartSend, (int channel)) {
497 if (send_fail_channel_ != channel) {
498 WEBRTC_CHECK_CHANNEL(channel);
499 channels_[channel]->send = true;
500 return 0;
501 } else {
502 // When send_fail_channel_ == channel, fail the StartSend on this
503 // channel.
504 return -1;
505 }
506 }
507 WEBRTC_STUB(StopReceive, (int channel));
508 WEBRTC_FUNC(StopPlayout, (int channel)) {
509 WEBRTC_CHECK_CHANNEL(channel);
510 channels_[channel]->playout = false;
511 return 0;
512 }
513 WEBRTC_FUNC(StopSend, (int channel)) {
514 WEBRTC_CHECK_CHANNEL(channel);
515 channels_[channel]->send = false;
516 return 0;
517 }
518 WEBRTC_STUB(GetVersion, (char version[1024]));
519 WEBRTC_STUB(LastError, ());
Minyue2013aec2015-05-13 14:14:42 +0200520 WEBRTC_FUNC(AssociateSendChannel, (int channel,
521 int accociate_send_channel)) {
522 WEBRTC_CHECK_CHANNEL(channel);
523 channels_[channel]->associate_send_channel = accociate_send_channel;
524 return 0;
525 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526
527 // webrtc::VoECodec
528 WEBRTC_FUNC(NumOfCodecs, ()) {
529 return num_codecs_;
530 }
531 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
532 if (index < 0 || index >= NumOfCodecs()) {
533 return -1;
534 }
535 const cricket::AudioCodec& c(*codecs_[index]);
536 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000537 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 codec.plfreq = c.clockrate;
539 codec.pacsize = 0;
540 codec.channels = c.channels;
541 codec.rate = c.bitrate;
542 return 0;
543 }
544 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
545 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000546 // To match the behavior of the real implementation.
547 if (_stricmp(codec.plname, "telephone-event") == 0 ||
548 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
549 _stricmp(codec.plname, "CN") == 0 ||
550 _stricmp(codec.plname, "red") == 0 ) {
551 return -1;
552 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000554 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 return 0;
556 }
557 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
558 WEBRTC_CHECK_CHANNEL(channel);
559 codec = channels_[channel]->send_codec;
560 return 0;
561 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200562 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000563 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
564 WEBRTC_CHECK_CHANNEL(channel);
565 const Channel* c = channels_[channel];
566 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
567 it_packet != c->packets.end(); ++it_packet) {
568 int pltype;
569 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
570 continue;
571 }
572 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
573 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
574 ++it_codec) {
575 if (it_codec->pltype == pltype) {
576 codec = *it_codec;
577 return 0;
578 }
579 }
580 }
581 return -1;
582 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 WEBRTC_FUNC(SetRecPayloadType, (int channel,
584 const webrtc::CodecInst& codec)) {
585 WEBRTC_CHECK_CHANNEL(channel);
586 Channel* ch = channels_[channel];
587 if (ch->playout)
588 return -1; // Channel is in use.
589 // Check if something else already has this slot.
590 if (codec.pltype != -1) {
591 for (std::vector<webrtc::CodecInst>::iterator it =
592 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
593 if (it->pltype == codec.pltype &&
594 _stricmp(it->plname, codec.plname) != 0) {
595 return -1;
596 }
597 }
598 }
599 // Otherwise try to find this codec and update its payload type.
600 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
601 it != ch->recv_codecs.end(); ++it) {
602 if (strcmp(it->plname, codec.plname) == 0 &&
603 it->plfreq == codec.plfreq) {
604 it->pltype = codec.pltype;
605 it->channels = codec.channels;
606 return 0;
607 }
608 }
609 return -1; // not found
610 }
611 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
612 webrtc::PayloadFrequencies frequency)) {
613 WEBRTC_CHECK_CHANNEL(channel);
614 if (frequency == webrtc::kFreq8000Hz) {
615 channels_[channel]->cn8_type = type;
616 } else if (frequency == webrtc::kFreq16000Hz) {
617 channels_[channel]->cn16_type = type;
618 }
619 return 0;
620 }
621 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
622 WEBRTC_CHECK_CHANNEL(channel);
623 Channel* ch = channels_[channel];
624 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
625 it != ch->recv_codecs.end(); ++it) {
626 if (strcmp(it->plname, codec.plname) == 0 &&
627 it->plfreq == codec.plfreq &&
628 it->channels == codec.channels &&
629 it->pltype != -1) {
630 codec.pltype = it->pltype;
631 return 0;
632 }
633 }
634 return -1; // not found
635 }
636 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
637 bool disableDTX)) {
638 WEBRTC_CHECK_CHANNEL(channel);
639 if (channels_[channel]->send_codec.channels == 2) {
640 // Replicating VoE behavior; VAD cannot be enabled for stereo.
641 return -1;
642 }
643 channels_[channel]->vad = enable;
644 return 0;
645 }
646 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
647 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000648
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000649 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
650 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000651 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000652 // Return -1 if current send codec is not Opus.
653 // TODO(minyue): Excludes other codecs if they support inband FEC.
654 return -1;
655 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000656 channels_[channel]->codec_fec = enable;
657 return 0;
658 }
659 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
660 WEBRTC_CHECK_CHANNEL(channel);
661 enable = channels_[channel]->codec_fec;
662 return 0;
663 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000664
665 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
666 WEBRTC_CHECK_CHANNEL(channel);
667 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
668 // Return -1 if current send codec is not Opus.
669 return -1;
670 }
671 if (frequency_hz <= 8000)
672 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
673 else if (frequency_hz <= 12000)
674 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
675 else if (frequency_hz <= 16000)
676 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
677 else if (frequency_hz <= 24000)
678 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
679 else
680 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
681 return 0;
682 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000684 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
685 WEBRTC_CHECK_CHANNEL(channel);
686 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
687 // Return -1 if current send codec is not Opus.
688 return -1;
689 }
690 channels_[channel]->opus_dtx = enable_dtx;
691 return 0;
692 }
693
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 // webrtc::VoEDtmf
695 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
696 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
697 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
698 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
699 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
700 return 0;
701 }
702
703 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
704 (int channel, unsigned char type)) {
705 channels_[channel]->dtmf_type = type;
706 return 0;
707 };
708 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
709 (int channel, unsigned char& type));
710
711 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
712 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 WEBRTC_FUNC(PlayDtmfTone,
715 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
716 dtmf_info_.dtmf_event_code = event_code;
717 dtmf_info_.dtmf_length_ms = length_ms;
718 return 0;
719 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720
721 // webrtc::VoEFile
722 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
723 bool loop, webrtc::FileFormats format,
724 float volumeScaling, int startPointMs,
725 int stopPointMs)) {
726 WEBRTC_CHECK_CHANNEL(channel);
727 channels_[channel]->file = true;
728 return 0;
729 }
730 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
731 webrtc::FileFormats format,
732 float volumeScaling, int startPointMs,
733 int stopPointMs)) {
734 WEBRTC_CHECK_CHANNEL(channel);
735 channels_[channel]->file = true;
736 return 0;
737 }
738 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
739 WEBRTC_CHECK_CHANNEL(channel);
740 channels_[channel]->file = false;
741 return 0;
742 }
743 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
744 WEBRTC_CHECK_CHANNEL(channel);
745 return (channels_[channel]->file) ? 1 : 0;
746 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
748 const char* fileNameUTF8,
749 bool loop,
750 bool mixWithMicrophone,
751 webrtc::FileFormats format,
752 float volumeScaling));
753 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
754 webrtc::InStream* stream,
755 bool mixWithMicrophone,
756 webrtc::FileFormats format,
757 float volumeScaling));
758 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
759 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
761 webrtc::CodecInst* compression,
762 int maxSizeBytes));
763 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
764 webrtc::CodecInst* compression));
765 WEBRTC_STUB(StopRecordingPlayout, (int channel));
766 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
767 webrtc::CodecInst* compression,
768 int maxSizeBytes)) {
769 if (fail_start_recording_microphone_) {
770 return -1;
771 }
772 recording_microphone_ = true;
773 return 0;
774 }
775 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
776 webrtc::CodecInst* compression)) {
777 if (fail_start_recording_microphone_) {
778 return -1;
779 }
780 recording_microphone_ = true;
781 return 0;
782 }
783 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
784 if (!recording_microphone_) {
785 return -1;
786 }
787 recording_microphone_ = false;
788 return 0;
789 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790
791 // webrtc::VoEHardware
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
793 return GetNumDevices(num);
794 }
795 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
796 return GetNumDevices(num);
797 }
798 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
799 return GetDeviceName(i, name, guid);
800 }
801 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
802 return GetDeviceName(i, name, guid);
803 }
804 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
805 WEBRTC_STUB(SetPlayoutDevice, (int));
806 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
807 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000808 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
809 recording_sample_rate_ = samples_per_sec;
810 return 0;
811 }
812 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
813 *samples_per_sec = recording_sample_rate_;
814 return 0;
815 }
816 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
817 playout_sample_rate_ = samples_per_sec;
818 return 0;
819 }
820 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
821 *samples_per_sec = playout_sample_rate_;
822 return 0;
823 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000825 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826
827 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000828 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
829 webrtc::NetworkStatistics& ns)) {
830 WEBRTC_CHECK_CHANNEL(channel);
831 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
832 return 0;
833 }
834
wu@webrtc.org24301a62013-12-13 19:17:43 +0000835 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
836 webrtc::AudioDecodingCallStats*)) {
837 WEBRTC_CHECK_CHANNEL(channel);
838 return 0;
839 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840
841 // webrtc::VoENetwork
842 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
843 webrtc::Transport& transport)) {
844 WEBRTC_CHECK_CHANNEL(channel);
845 channels_[channel]->external_transport = true;
846 return 0;
847 }
848 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
849 WEBRTC_CHECK_CHANNEL(channel);
850 channels_[channel]->external_transport = false;
851 return 0;
852 }
853 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000854 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 WEBRTC_CHECK_CHANNEL(channel);
856 if (!channels_[channel]->external_transport) return -1;
857 channels_[channel]->packets.push_back(
858 std::string(static_cast<const char*>(data), length));
859 return 0;
860 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000861 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000862 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000863 const webrtc::PacketTime& packet_time)) {
864 WEBRTC_CHECK_CHANNEL(channel);
865 if (ReceivedRTPPacket(channel, data, length) == -1) {
866 return -1;
867 }
868 channels_[channel]->last_rtp_packet_time = packet_time;
869 return 0;
870 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000871
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000873 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874
875 // webrtc::VoERTP_RTCP
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
877 WEBRTC_CHECK_CHANNEL(channel);
878 channels_[channel]->send_ssrc = ssrc;
879 return 0;
880 }
881 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
882 WEBRTC_CHECK_CHANNEL(channel);
883 ssrc = channels_[channel]->send_ssrc;
884 return 0;
885 }
886 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000887 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
888 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000890 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
891 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 return 0;
893 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000894 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
895 unsigned char id)) {
896 WEBRTC_CHECK_CHANNEL(channel);
897 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
898 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
899 return 0;
900 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000901 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
902 unsigned char id)) {
903 WEBRTC_CHECK_CHANNEL(channel);
904 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
905 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
906 return 0;
907 }
908 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (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_absolute_sender_time_ext_ = (enable) ? id : -1;
913 return 0;
914 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000915
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
917 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
918 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
919 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
920 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
921 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
922 unsigned int& NTPLow,
923 unsigned int& timestamp,
924 unsigned int& playoutTimestamp,
925 unsigned int* jitter,
926 unsigned short* fractionLost));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
928 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
929 WEBRTC_CHECK_CHANNEL(channel);
930 webrtc::ReportBlock block;
931 block.source_SSRC = channels_[channel]->send_ssrc;
932 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
933 if (send_codec.pltype >= 0) {
934 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
935 if (send_codec.plfreq / 1000 > 0) {
936 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
937 }
938 block.cumulative_num_packets_lost = kIntStatValue;
939 block.extended_highest_sequence_number = kIntStatValue;
940 receive_blocks->push_back(block);
941 }
942 return 0;
943 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
945 unsigned int& maxJitterMs,
946 unsigned int& discardedPackets));
947 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
948 WEBRTC_CHECK_CHANNEL(channel);
949 stats.fractionLost = static_cast<int16>(kIntStatValue);
950 stats.cumulativeLost = kIntStatValue;
951 stats.extendedMax = kIntStatValue;
952 stats.jitterSamples = kIntStatValue;
953 stats.rttMs = kIntStatValue;
954 stats.bytesSent = kIntStatValue;
955 stats.packetsSent = kIntStatValue;
956 stats.bytesReceived = kIntStatValue;
957 stats.packetsReceived = kIntStatValue;
958 return 0;
959 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000960 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000961 return SetFECStatus(channel, enable, redPayloadtype);
962 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000963 // TODO(minyue): remove the below function when transition to SetREDStatus
964 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
966 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000967 channels_[channel]->red = enable;
968 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 return 0;
970 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000971 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000972 return GetFECStatus(channel, enable, redPayloadtype);
973 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000974 // TODO(minyue): remove the below function when transition to GetREDStatus
975 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
977 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000978 enable = channels_[channel]->red;
979 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 return 0;
981 }
982 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
983 WEBRTC_CHECK_CHANNEL(channel);
984 channels_[channel]->nack = enable;
985 channels_[channel]->nack_max_packets = maxNoPackets;
986 return 0;
987 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988
989 // webrtc::VoEVideoSync
990 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
991 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000992 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
994 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
995 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
996 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
997 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
998 int* playout_buffer_delay_ms));
999 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1000
1001 // webrtc::VoEVolumeControl
1002 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1003 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 WEBRTC_STUB(SetMicVolume, (unsigned int));
1005 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1006 WEBRTC_STUB(SetInputMute, (int, bool));
1007 WEBRTC_STUB(GetInputMute, (int, bool&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1009 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1010 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1011 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1012 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1013 WEBRTC_CHECK_CHANNEL(channel);
1014 channels_[channel]->volume_scale= scale;
1015 return 0;
1016 }
1017 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1018 WEBRTC_CHECK_CHANNEL(channel);
1019 scale = channels_[channel]->volume_scale;
1020 return 0;
1021 }
1022 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1023 WEBRTC_CHECK_CHANNEL(channel);
1024 channels_[channel]->volume_pan_left = left;
1025 channels_[channel]->volume_pan_right = right;
1026 return 0;
1027 }
1028 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1029 WEBRTC_CHECK_CHANNEL(channel);
1030 left = channels_[channel]->volume_pan_left;
1031 right = channels_[channel]->volume_pan_right;
1032 return 0;
1033 }
1034
1035 // webrtc::VoEAudioProcessing
1036 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1037 ns_enabled_ = enable;
1038 ns_mode_ = mode;
1039 return 0;
1040 }
1041 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1042 enabled = ns_enabled_;
1043 mode = ns_mode_;
1044 return 0;
1045 }
1046
1047 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1048 agc_enabled_ = enable;
1049 agc_mode_ = mode;
1050 return 0;
1051 }
1052 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1053 enabled = agc_enabled_;
1054 mode = agc_mode_;
1055 return 0;
1056 }
1057
1058 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1059 agc_config_ = config;
1060 return 0;
1061 }
1062 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1063 config = agc_config_;
1064 return 0;
1065 }
1066 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1067 ec_enabled_ = enable;
1068 ec_mode_ = mode;
1069 return 0;
1070 }
1071 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1072 enabled = ec_enabled_;
1073 mode = ec_mode_;
1074 return 0;
1075 }
1076 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1077 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1078 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1079 WEBRTC_STUB(DelayOffsetMs, ());
1080 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1081 aecm_mode_ = mode;
1082 cng_enabled_ = enableCNG;
1083 return 0;
1084 }
1085 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1086 mode = aecm_mode_;
1087 enabledCNG = cng_enabled_;
1088 return 0;
1089 }
1090 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1091 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1092 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001093 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1094 webrtc::AgcModes mode)) {
1095 channels_[channel]->rx_agc_enabled = enable;
1096 channels_[channel]->rx_agc_mode = mode;
1097 return 0;
1098 }
1099 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1100 webrtc::AgcModes& mode)) {
1101 enabled = channels_[channel]->rx_agc_enabled;
1102 mode = channels_[channel]->rx_agc_mode;
1103 return 0;
1104 }
1105
1106 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1107 channels_[channel]->rx_agc_config = config;
1108 return 0;
1109 }
1110 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1111 config = channels_[channel]->rx_agc_config;
1112 return 0;
1113 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114
1115 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1116 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1117 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1118 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1119 ec_metrics_enabled_ = enable;
1120 return 0;
1121 }
1122 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1123 enabled = ec_metrics_enabled_;
1124 return 0;
1125 }
1126 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001127 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1128 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129
1130 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001131 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 WEBRTC_STUB(StopDebugRecording, ());
1133
1134 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1135 typing_detection_enabled_ = enable;
1136 return 0;
1137 }
1138 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1139 enabled = typing_detection_enabled_;
1140 return 0;
1141 }
1142
1143 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1144 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1145 int costPerTyping,
1146 int reportingThreshold,
1147 int penaltyDecay,
1148 int typeEventDelay));
1149 int EnableHighPassFilter(bool enable) {
1150 highpass_filter_enabled_ = enable;
1151 return 0;
1152 }
1153 bool IsHighPassFilterEnabled() {
1154 return highpass_filter_enabled_;
1155 }
1156 bool IsStereoChannelSwappingEnabled() {
1157 return stereo_swapping_enabled_;
1158 }
1159 void EnableStereoChannelSwapping(bool enable) {
1160 stereo_swapping_enabled_ = enable;
1161 }
1162 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1163 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1164 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1165 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1166 }
1167 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1168 return (dtmf_info_.dtmf_event_code == event_code &&
1169 dtmf_info_.dtmf_length_ms == length_ms);
1170 }
1171 // webrtc::VoEExternalMedia
1172 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1173 (int channel, webrtc::ProcessingTypes type,
1174 webrtc::VoEMediaProcess& processObject)) {
1175 WEBRTC_CHECK_CHANNEL(channel);
1176 if (channels_[channel]->media_processor_registered) {
1177 return -1;
1178 }
1179 channels_[channel]->media_processor_registered = true;
1180 media_processor_ = &processObject;
1181 return 0;
1182 }
1183 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1184 (int channel, webrtc::ProcessingTypes type)) {
1185 WEBRTC_CHECK_CHANNEL(channel);
1186 if (!channels_[channel]->media_processor_registered) {
1187 return -1;
1188 }
1189 channels_[channel]->media_processor_registered = false;
1190 media_processor_ = NULL;
1191 return 0;
1192 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1194 webrtc::AudioFrame* frame));
1195 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
Henrik Lundin64dad832015-05-11 12:44:23 +02001196 int GetNetEqCapacity() const {
1197 auto ch = channels_.find(last_channel_);
1198 ASSERT(ch != channels_.end());
1199 return ch->second->neteq_capacity;
1200 }
Henrik Lundin5263b3c2015-06-01 10:29:41 +02001201 bool GetNetEqFastAccelerate() const {
1202 auto ch = channels_.find(last_channel_);
1203 ASSERT(ch != channels_.end());
1204 return ch->second->neteq_fast_accelerate;
1205 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206
1207 private:
1208 int GetNumDevices(int& num) {
1209#ifdef WIN32
1210 num = 1;
1211#else
1212 // On non-Windows platforms VE adds a special entry for the default device,
1213 // so if there is one physical device then there are two entries in the
1214 // list.
1215 num = 2;
1216#endif
1217 return 0;
1218 }
1219
1220 int GetDeviceName(int i, char* name, char* guid) {
1221 const char *s;
1222#ifdef WIN32
1223 if (0 == i) {
1224 s = kFakeDeviceName;
1225 } else {
1226 return -1;
1227 }
1228#else
1229 // See comment above.
1230 if (0 == i) {
1231 s = kFakeDefaultDeviceName;
1232 } else if (1 == i) {
1233 s = kFakeDeviceName;
1234 } else {
1235 return -1;
1236 }
1237#endif
1238 strcpy(name, s);
1239 guid[0] = '\0';
1240 return 0;
1241 }
1242
1243 bool inited_;
1244 int last_channel_;
1245 std::map<int, Channel*> channels_;
1246 bool fail_create_channel_;
1247 const cricket::AudioCodec* const* codecs_;
1248 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001249 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 bool ec_enabled_;
1251 bool ec_metrics_enabled_;
1252 bool cng_enabled_;
1253 bool ns_enabled_;
1254 bool agc_enabled_;
1255 bool highpass_filter_enabled_;
1256 bool stereo_swapping_enabled_;
1257 bool typing_detection_enabled_;
1258 webrtc::EcModes ec_mode_;
1259 webrtc::AecmModes aecm_mode_;
1260 webrtc::NsModes ns_mode_;
1261 webrtc::AgcModes agc_mode_;
1262 webrtc::AgcConfig agc_config_;
1263 webrtc::VoiceEngineObserver* observer_;
1264 int playout_fail_channel_;
1265 int send_fail_channel_;
1266 bool fail_start_recording_microphone_;
1267 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001268 int recording_sample_rate_;
1269 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 DtmfInfo dtmf_info_;
1271 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001272 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273};
1274
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001275#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1276
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277} // namespace cricket
1278
1279#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_