blob: c394d0cf773e21e168883191c6761ba0d1dac072 [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"
41#include "webrtc/base/gunit.h"
42#include "webrtc/base/stringutils.h"
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000043#include "webrtc/modules/audio_processing/include/audio_processing.h"
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000044#include "webrtc/video_engine/include/vie_network.h"
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +000045
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046namespace cricket {
47
48// Function returning stats will return these values
49// for all values based on type.
50const int kIntStatValue = 123;
51const float kFractionLostStatValue = 0.5;
52
53static const char kFakeDefaultDeviceName[] = "Fake Default";
54static const int kFakeDefaultDeviceId = -1;
55static const char kFakeDeviceName[] = "Fake Device";
56#ifdef WIN32
57static const int kFakeDeviceId = 0;
58#else
59static const int kFakeDeviceId = 1;
60#endif
61
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000062static const int kOpusBandwidthNb = 4000;
63static const int kOpusBandwidthMb = 6000;
64static const int kOpusBandwidthWb = 8000;
65static const int kOpusBandwidthSwb = 12000;
66static const int kOpusBandwidthFb = 20000;
67
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +000068static const webrtc::NetworkStatistics kNetStats = {
69 1, // uint16_t currentBufferSize;
70 2, // uint16_t preferredBufferSize;
71 true, // bool jitterPeaksFound;
72 1234, // uint16_t currentPacketLossRate;
73 567, // uint16_t currentDiscardRate;
74 8901, // uint16_t currentExpandRate;
75 234, // uint16_t currentSpeechExpandRate;
76 5678, // uint16_t currentPreemptiveRate;
77 9012, // uint16_t currentAccelerateRate;
78 3456, // uint16_t currentSecondaryDecodedRate;
79 7890, // int32_t clockDriftPPM;
80 54, // meanWaitingTimeMs;
81 32, // int medianWaitingTimeMs;
82 1, // int minWaitingTimeMs;
83 98, // int maxWaitingTimeMs;
84 7654, // int addedSamples;
85}; // These random but non-trivial numbers are used for testing.
86
henrike@webrtc.org79047f92014-03-06 23:46:59 +000087// Verify the header extension ID, if enabled, is within the bounds specified in
88// [RFC5285]: 1-14 inclusive.
89#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
90 do { \
91 if (enable && (id < 1 || id > 14)) { \
92 return -1; \
93 } \
94 } while (0);
95
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000096class FakeAudioProcessing : public webrtc::AudioProcessing {
97 public:
98 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
99
100 WEBRTC_STUB(Initialize, ())
101 WEBRTC_STUB(Initialize, (
102 int input_sample_rate_hz,
103 int output_sample_rate_hz,
104 int reverse_sample_rate_hz,
105 webrtc::AudioProcessing::ChannelLayout input_layout,
106 webrtc::AudioProcessing::ChannelLayout output_layout,
107 webrtc::AudioProcessing::ChannelLayout reverse_layout));
108
109 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
110 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
111 }
112
113 WEBRTC_STUB(set_sample_rate_hz, (int rate));
114 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
115 WEBRTC_STUB_CONST(sample_rate_hz, ());
116 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
117 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
118 WEBRTC_STUB_CONST(num_input_channels, ());
119 WEBRTC_STUB_CONST(num_output_channels, ());
120 WEBRTC_STUB_CONST(num_reverse_channels, ());
121 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
122 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
123 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
124 WEBRTC_STUB(ProcessStream, (
125 const float* const* src,
126 int samples_per_channel,
127 int input_sample_rate_hz,
128 webrtc::AudioProcessing::ChannelLayout input_layout,
129 int output_sample_rate_hz,
130 webrtc::AudioProcessing::ChannelLayout output_layout,
131 float* const* dest));
132 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
133 WEBRTC_STUB(AnalyzeReverseStream, (
134 const float* const* data,
135 int samples_per_channel,
136 int sample_rate_hz,
137 webrtc::AudioProcessing::ChannelLayout layout));
138 WEBRTC_STUB(set_stream_delay_ms, (int delay));
139 WEBRTC_STUB_CONST(stream_delay_ms, ());
140 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
141 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
142 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
143 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
144 WEBRTC_STUB_CONST(delay_offset_ms, ());
145 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
146 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
147 WEBRTC_STUB(StopDebugRecording, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000148 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
149 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000150 return NULL;
151 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000152 webrtc::GainControl* gain_control() const override { return NULL; }
153 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
154 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
155 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
156 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000157
158 bool experimental_ns_enabled() {
159 return experimental_ns_enabled_;
160 }
161
162 private:
163 bool experimental_ns_enabled_;
164};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000165
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166class FakeWebRtcVoiceEngine
167 : public webrtc::VoEAudioProcessing,
168 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
169 public webrtc::VoEFile, public webrtc::VoEHardware,
170 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
171 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
172 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
173 public:
174 struct DtmfInfo {
175 DtmfInfo()
176 : dtmf_event_code(-1),
177 dtmf_out_of_band(false),
178 dtmf_length_ms(-1) {}
179 int dtmf_event_code;
180 bool dtmf_out_of_band;
181 int dtmf_length_ms;
182 };
183 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000184 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 : external_transport(false),
186 send(false),
187 playout(false),
188 volume_scale(1.0),
189 volume_pan_left(1.0),
190 volume_pan_right(1.0),
191 file(false),
192 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000193 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000194 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000195 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000196 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 nack(false),
198 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000199 rx_agc_enabled(false),
200 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 cn8_type(13),
202 cn16_type(105),
203 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000204 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 nack_max_packets(0),
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000206 vie_network(NULL),
207 video_channel(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000209 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000210 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000211 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000212 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000214 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 }
216 bool external_transport;
217 bool send;
218 bool playout;
219 float volume_scale;
220 float volume_pan_left;
221 float volume_pan_right;
222 bool file;
223 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000224 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000225 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000226 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000227 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 bool nack;
229 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000230 bool rx_agc_enabled;
231 webrtc::AgcModes rx_agc_mode;
232 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 int cn8_type;
234 int cn16_type;
235 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000236 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 int nack_max_packets;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000238 webrtc::ViENetwork* vie_network;
239 int video_channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000241 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000242 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000243 int send_absolute_sender_time_ext_;
244 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 DtmfInfo dtmf_info;
246 std::vector<webrtc::CodecInst> recv_codecs;
247 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000248 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 std::list<std::string> packets;
250 };
251
252 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
253 int num_codecs)
254 : inited_(false),
255 last_channel_(-1),
256 fail_create_channel_(false),
257 codecs_(codecs),
258 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000259 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 ec_enabled_(false),
261 ec_metrics_enabled_(false),
262 cng_enabled_(false),
263 ns_enabled_(false),
264 agc_enabled_(false),
265 highpass_filter_enabled_(false),
266 stereo_swapping_enabled_(false),
267 typing_detection_enabled_(false),
268 ec_mode_(webrtc::kEcDefault),
269 aecm_mode_(webrtc::kAecmSpeakerphone),
270 ns_mode_(webrtc::kNsDefault),
271 agc_mode_(webrtc::kAgcDefault),
272 observer_(NULL),
273 playout_fail_channel_(-1),
274 send_fail_channel_(-1),
275 fail_start_recording_microphone_(false),
276 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000277 recording_sample_rate_(-1),
278 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 media_processor_(NULL) {
280 memset(&agc_config_, 0, sizeof(agc_config_));
281 }
282 ~FakeWebRtcVoiceEngine() {
283 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
284 // destructors, but just in case ...
285 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
286 i != channels_.end(); ++i) {
287 delete i->second;
288 }
289 }
290
291 bool IsExternalMediaProcessorRegistered() const {
292 return media_processor_ != NULL;
293 }
294 bool IsInited() const { return inited_; }
295 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000296 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
297 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
298 iter != channels_.end(); ++iter) {
299 if (local_ssrc == iter->second->send_ssrc)
300 return iter->first;
301 }
302 return -1;
303 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000304 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 bool GetPlayout(int channel) {
306 return channels_[channel]->playout;
307 }
308 bool GetSend(int channel) {
309 return channels_[channel]->send;
310 }
311 bool GetRecordingMicrophone() {
312 return recording_microphone_;
313 }
314 bool GetVAD(int channel) {
315 return channels_[channel]->vad;
316 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100317 bool GetOpusDtx(int channel) {
318 return channels_[channel]->opus_dtx;
319 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000320 bool GetRED(int channel) {
321 return channels_[channel]->red;
322 }
323 bool GetCodecFEC(int channel) {
324 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000326 int GetMaxEncodingBandwidth(int channel) {
327 return channels_[channel]->max_encoding_bandwidth;
328 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 bool GetNACK(int channel) {
330 return channels_[channel]->nack;
331 }
332 int GetNACKMaxPackets(int channel) {
333 return channels_[channel]->nack_max_packets;
334 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000335 webrtc::ViENetwork* GetViENetwork(int channel) {
336 WEBRTC_ASSERT_CHANNEL(channel);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000337 // WARNING: This pointer is for verification purposes only. Calling
338 // functions on it may result in undefined behavior!
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000339 return channels_[channel]->vie_network;
340 }
341 int GetVideoChannel(int channel) {
342 WEBRTC_ASSERT_CHANNEL(channel);
343 return channels_[channel]->video_channel;
344 }
345 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) {
373 ASSERT(observer_ != NULL);
374 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 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000402 int AddChannel() {
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 }
412 channels_[++last_channel_] = ch;
413 return last_channel_;
414 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000415 int GetSendRtpExtensionId(int channel, const std::string& extension) {
416 WEBRTC_ASSERT_CHANNEL(channel);
417 if (extension == kRtpAudioLevelHeaderExtension) {
418 return channels_[channel]->send_audio_level_ext_;
419 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
420 return channels_[channel]->send_absolute_sender_time_ext_;
421 }
422 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000423 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000424 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
425 WEBRTC_ASSERT_CHANNEL(channel);
426 if (extension == kRtpAudioLevelHeaderExtension) {
427 return channels_[channel]->receive_audio_level_ext_;
428 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
429 return channels_[channel]->receive_absolute_sender_time_ext_;
430 }
431 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000432 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000434 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
435
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436 WEBRTC_STUB(Release, ());
437
438 // webrtc::VoEBase
439 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
440 webrtc::VoiceEngineObserver& observer)) {
441 observer_ = &observer;
442 return 0;
443 }
444 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
445 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
446 webrtc::AudioProcessing* audioproc)) {
447 inited_ = true;
448 return 0;
449 }
450 WEBRTC_FUNC(Terminate, ()) {
451 inited_ = false;
452 return 0;
453 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000454 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000455 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000458 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000460 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
461 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000462 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 WEBRTC_FUNC(DeleteChannel, (int channel)) {
464 WEBRTC_CHECK_CHANNEL(channel);
465 delete channels_[channel];
466 channels_.erase(channel);
467 return 0;
468 }
469 WEBRTC_STUB(StartReceive, (int channel));
470 WEBRTC_FUNC(StartPlayout, (int channel)) {
471 if (playout_fail_channel_ != channel) {
472 WEBRTC_CHECK_CHANNEL(channel);
473 channels_[channel]->playout = true;
474 return 0;
475 } else {
476 // When playout_fail_channel_ == channel, fail the StartPlayout on this
477 // channel.
478 return -1;
479 }
480 }
481 WEBRTC_FUNC(StartSend, (int channel)) {
482 if (send_fail_channel_ != channel) {
483 WEBRTC_CHECK_CHANNEL(channel);
484 channels_[channel]->send = true;
485 return 0;
486 } else {
487 // When send_fail_channel_ == channel, fail the StartSend on this
488 // channel.
489 return -1;
490 }
491 }
492 WEBRTC_STUB(StopReceive, (int channel));
493 WEBRTC_FUNC(StopPlayout, (int channel)) {
494 WEBRTC_CHECK_CHANNEL(channel);
495 channels_[channel]->playout = false;
496 return 0;
497 }
498 WEBRTC_FUNC(StopSend, (int channel)) {
499 WEBRTC_CHECK_CHANNEL(channel);
500 channels_[channel]->send = false;
501 return 0;
502 }
503 WEBRTC_STUB(GetVersion, (char version[1024]));
504 WEBRTC_STUB(LastError, ());
505 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
506 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000507
508 // webrtc::VoECodec
509 WEBRTC_FUNC(NumOfCodecs, ()) {
510 return num_codecs_;
511 }
512 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
513 if (index < 0 || index >= NumOfCodecs()) {
514 return -1;
515 }
516 const cricket::AudioCodec& c(*codecs_[index]);
517 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000518 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 codec.plfreq = c.clockrate;
520 codec.pacsize = 0;
521 codec.channels = c.channels;
522 codec.rate = c.bitrate;
523 return 0;
524 }
525 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
526 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000527 // To match the behavior of the real implementation.
528 if (_stricmp(codec.plname, "telephone-event") == 0 ||
529 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
530 _stricmp(codec.plname, "CN") == 0 ||
531 _stricmp(codec.plname, "red") == 0 ) {
532 return -1;
533 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000535 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 return 0;
537 }
538 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
539 WEBRTC_CHECK_CHANNEL(channel);
540 codec = channels_[channel]->send_codec;
541 return 0;
542 }
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000543 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
544 WEBRTC_CHECK_CHANNEL(channel);
545 const Channel* c = channels_[channel];
546 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
547 it_packet != c->packets.end(); ++it_packet) {
548 int pltype;
549 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
550 continue;
551 }
552 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
553 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
554 ++it_codec) {
555 if (it_codec->pltype == pltype) {
556 codec = *it_codec;
557 return 0;
558 }
559 }
560 }
561 return -1;
562 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
564 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
565 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
566 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
567 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
568 bool useFixedFrameSize));
569 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
570 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
571 WEBRTC_FUNC(SetRecPayloadType, (int channel,
572 const webrtc::CodecInst& codec)) {
573 WEBRTC_CHECK_CHANNEL(channel);
574 Channel* ch = channels_[channel];
575 if (ch->playout)
576 return -1; // Channel is in use.
577 // Check if something else already has this slot.
578 if (codec.pltype != -1) {
579 for (std::vector<webrtc::CodecInst>::iterator it =
580 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
581 if (it->pltype == codec.pltype &&
582 _stricmp(it->plname, codec.plname) != 0) {
583 return -1;
584 }
585 }
586 }
587 // Otherwise try to find this codec and update its payload type.
588 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
589 it != ch->recv_codecs.end(); ++it) {
590 if (strcmp(it->plname, codec.plname) == 0 &&
591 it->plfreq == codec.plfreq) {
592 it->pltype = codec.pltype;
593 it->channels = codec.channels;
594 return 0;
595 }
596 }
597 return -1; // not found
598 }
599 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
600 webrtc::PayloadFrequencies frequency)) {
601 WEBRTC_CHECK_CHANNEL(channel);
602 if (frequency == webrtc::kFreq8000Hz) {
603 channels_[channel]->cn8_type = type;
604 } else if (frequency == webrtc::kFreq16000Hz) {
605 channels_[channel]->cn16_type = type;
606 }
607 return 0;
608 }
609 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
610 WEBRTC_CHECK_CHANNEL(channel);
611 Channel* ch = channels_[channel];
612 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
613 it != ch->recv_codecs.end(); ++it) {
614 if (strcmp(it->plname, codec.plname) == 0 &&
615 it->plfreq == codec.plfreq &&
616 it->channels == codec.channels &&
617 it->pltype != -1) {
618 codec.pltype = it->pltype;
619 return 0;
620 }
621 }
622 return -1; // not found
623 }
624 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
625 bool disableDTX)) {
626 WEBRTC_CHECK_CHANNEL(channel);
627 if (channels_[channel]->send_codec.channels == 2) {
628 // Replicating VoE behavior; VAD cannot be enabled for stereo.
629 return -1;
630 }
631 channels_[channel]->vad = enable;
632 return 0;
633 }
634 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
635 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000636
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000637 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
638 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000639 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000640 // Return -1 if current send codec is not Opus.
641 // TODO(minyue): Excludes other codecs if they support inband FEC.
642 return -1;
643 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000644 channels_[channel]->codec_fec = enable;
645 return 0;
646 }
647 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
648 WEBRTC_CHECK_CHANNEL(channel);
649 enable = channels_[channel]->codec_fec;
650 return 0;
651 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000652
653 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
654 WEBRTC_CHECK_CHANNEL(channel);
655 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
656 // Return -1 if current send codec is not Opus.
657 return -1;
658 }
659 if (frequency_hz <= 8000)
660 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
661 else if (frequency_hz <= 12000)
662 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
663 else if (frequency_hz <= 16000)
664 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
665 else if (frequency_hz <= 24000)
666 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
667 else
668 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
669 return 0;
670 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000672 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
673 WEBRTC_CHECK_CHANNEL(channel);
674 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
675 // Return -1 if current send codec is not Opus.
676 return -1;
677 }
678 channels_[channel]->opus_dtx = enable_dtx;
679 return 0;
680 }
681
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 // webrtc::VoEDtmf
683 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
684 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
685 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
686 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
687 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
688 return 0;
689 }
690
691 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
692 (int channel, unsigned char type)) {
693 channels_[channel]->dtmf_type = type;
694 return 0;
695 };
696 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
697 (int channel, unsigned char& type));
698
699 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
700 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 WEBRTC_FUNC(PlayDtmfTone,
703 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
704 dtmf_info_.dtmf_event_code = event_code;
705 dtmf_info_.dtmf_length_ms = length_ms;
706 return 0;
707 }
708 WEBRTC_STUB(StartPlayingDtmfTone,
709 (int eventCode, int attenuationDb = 10));
710 WEBRTC_STUB(StopPlayingDtmfTone, ());
711
712 // webrtc::VoEFile
713 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
714 bool loop, webrtc::FileFormats format,
715 float volumeScaling, int startPointMs,
716 int stopPointMs)) {
717 WEBRTC_CHECK_CHANNEL(channel);
718 channels_[channel]->file = true;
719 return 0;
720 }
721 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
722 webrtc::FileFormats format,
723 float volumeScaling, int startPointMs,
724 int stopPointMs)) {
725 WEBRTC_CHECK_CHANNEL(channel);
726 channels_[channel]->file = true;
727 return 0;
728 }
729 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
730 WEBRTC_CHECK_CHANNEL(channel);
731 channels_[channel]->file = false;
732 return 0;
733 }
734 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
735 WEBRTC_CHECK_CHANNEL(channel);
736 return (channels_[channel]->file) ? 1 : 0;
737 }
738 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
739 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
740 const char* fileNameUTF8,
741 bool loop,
742 bool mixWithMicrophone,
743 webrtc::FileFormats format,
744 float volumeScaling));
745 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
746 webrtc::InStream* stream,
747 bool mixWithMicrophone,
748 webrtc::FileFormats format,
749 float volumeScaling));
750 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
751 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
752 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
753 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
754 webrtc::CodecInst* compression,
755 int maxSizeBytes));
756 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
757 webrtc::CodecInst* compression));
758 WEBRTC_STUB(StopRecordingPlayout, (int channel));
759 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
760 webrtc::CodecInst* compression,
761 int maxSizeBytes)) {
762 if (fail_start_recording_microphone_) {
763 return -1;
764 }
765 recording_microphone_ = true;
766 return 0;
767 }
768 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
769 webrtc::CodecInst* compression)) {
770 if (fail_start_recording_microphone_) {
771 return -1;
772 }
773 recording_microphone_ = true;
774 return 0;
775 }
776 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
777 if (!recording_microphone_) {
778 return -1;
779 }
780 recording_microphone_ = false;
781 return 0;
782 }
783 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
784 const char* fileNameOutUTF8));
785 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
786 webrtc::OutStream* streamOut));
787 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
788 const char* fileNameOutUTF8));
789 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
790 webrtc::OutStream* streamOut));
791 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
792 const char* fileNameOutUTF8,
793 webrtc::CodecInst* compression));
794 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
795 webrtc::OutStream* streamOut,
796 webrtc::CodecInst* compression));
797 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
798 const char* fileNameOutUTF8));
799 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
800 webrtc::OutStream* streamOut));
801 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
802 webrtc::FileFormats format));
803 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
804
805 // webrtc::VoEHardware
806 WEBRTC_STUB(GetCPULoad, (int&));
807 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
808 return GetNumDevices(num);
809 }
810 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
811 return GetNumDevices(num);
812 }
813 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
814 return GetDeviceName(i, name, guid);
815 }
816 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
817 return GetDeviceName(i, name, guid);
818 }
819 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
820 WEBRTC_STUB(SetPlayoutDevice, (int));
821 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
822 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
823 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
824 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
825 WEBRTC_STUB(ResetAudioDevice, ());
826 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
827 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
828 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000829 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
830 recording_sample_rate_ = samples_per_sec;
831 return 0;
832 }
833 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
834 *samples_per_sec = recording_sample_rate_;
835 return 0;
836 }
837 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
838 playout_sample_rate_ = samples_per_sec;
839 return 0;
840 }
841 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
842 *samples_per_sec = playout_sample_rate_;
843 return 0;
844 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
846 virtual bool BuiltInAECIsEnabled() const { return true; }
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000847 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848
849 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000850 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
851 webrtc::NetworkStatistics& ns)) {
852 WEBRTC_CHECK_CHANNEL(channel);
853 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
854 return 0;
855 }
856
wu@webrtc.org24301a62013-12-13 19:17:43 +0000857 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
858 webrtc::AudioDecodingCallStats*)) {
859 WEBRTC_CHECK_CHANNEL(channel);
860 return 0;
861 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862
863 // webrtc::VoENetwork
864 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
865 webrtc::Transport& transport)) {
866 WEBRTC_CHECK_CHANNEL(channel);
867 channels_[channel]->external_transport = true;
868 return 0;
869 }
870 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
871 WEBRTC_CHECK_CHANNEL(channel);
872 channels_[channel]->external_transport = false;
873 return 0;
874 }
875 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000876 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 WEBRTC_CHECK_CHANNEL(channel);
878 if (!channels_[channel]->external_transport) return -1;
879 channels_[channel]->packets.push_back(
880 std::string(static_cast<const char*>(data), length));
881 return 0;
882 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000883 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000884 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000885 const webrtc::PacketTime& packet_time)) {
886 WEBRTC_CHECK_CHANNEL(channel);
887 if (ReceivedRTPPacket(channel, data, length) == -1) {
888 return -1;
889 }
890 channels_[channel]->last_rtp_packet_time = packet_time;
891 return 0;
892 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000893
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000895 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896
897 // webrtc::VoERTP_RTCP
898 WEBRTC_STUB(RegisterRTPObserver, (int channel,
899 webrtc::VoERTPObserver& observer));
900 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
902 WEBRTC_CHECK_CHANNEL(channel);
903 channels_[channel]->send_ssrc = ssrc;
904 return 0;
905 }
906 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
907 WEBRTC_CHECK_CHANNEL(channel);
908 ssrc = channels_[channel]->send_ssrc;
909 return 0;
910 }
911 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000912 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
913 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000915 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
916 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 return 0;
918 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000919 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
920 unsigned char id)) {
921 WEBRTC_CHECK_CHANNEL(channel);
922 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
923 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
924 return 0;
925 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000926 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
927 unsigned char id)) {
928 WEBRTC_CHECK_CHANNEL(channel);
929 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
930 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
931 return 0;
932 }
933 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
934 unsigned char id)) {
935 WEBRTC_CHECK_CHANNEL(channel);
936 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
937 channels_[channel]->receive_absolute_sender_time_ext_ = (enable) ? id : -1;
938 return 0;
939 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000940
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
942 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
943 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
944 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
945 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
946 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
947 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
948 unsigned int& NTPLow,
949 unsigned int& timestamp,
950 unsigned int& playoutTimestamp,
951 unsigned int* jitter,
952 unsigned short* fractionLost));
953 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
954 webrtc::SenderInfo* sender_info));
955 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
956 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
957 WEBRTC_CHECK_CHANNEL(channel);
958 webrtc::ReportBlock block;
959 block.source_SSRC = channels_[channel]->send_ssrc;
960 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
961 if (send_codec.pltype >= 0) {
962 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
963 if (send_codec.plfreq / 1000 > 0) {
964 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
965 }
966 block.cumulative_num_packets_lost = kIntStatValue;
967 block.extended_highest_sequence_number = kIntStatValue;
968 receive_blocks->push_back(block);
969 }
970 return 0;
971 }
972 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
973 unsigned char subType,
974 unsigned int name,
975 const char* data,
976 unsigned short dataLength));
977 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
978 unsigned int& maxJitterMs,
979 unsigned int& discardedPackets));
980 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
981 WEBRTC_CHECK_CHANNEL(channel);
982 stats.fractionLost = static_cast<int16>(kIntStatValue);
983 stats.cumulativeLost = kIntStatValue;
984 stats.extendedMax = kIntStatValue;
985 stats.jitterSamples = kIntStatValue;
986 stats.rttMs = kIntStatValue;
987 stats.bytesSent = kIntStatValue;
988 stats.packetsSent = kIntStatValue;
989 stats.bytesReceived = kIntStatValue;
990 stats.packetsReceived = kIntStatValue;
991 return 0;
992 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000993 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000994 return SetFECStatus(channel, enable, redPayloadtype);
995 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000996 // TODO(minyue): remove the below function when transition to SetREDStatus
997 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
999 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001000 channels_[channel]->red = enable;
1001 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 return 0;
1003 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001004 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +00001005 return GetFECStatus(channel, enable, redPayloadtype);
1006 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +00001007 // TODO(minyue): remove the below function when transition to GetREDStatus
1008 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
1010 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +00001011 enable = channels_[channel]->red;
1012 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 return 0;
1014 }
1015 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
1016 WEBRTC_CHECK_CHANNEL(channel);
1017 channels_[channel]->nack = enable;
1018 channels_[channel]->nack_max_packets = maxNoPackets;
1019 return 0;
1020 }
1021 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
1022 webrtc::RTPDirections direction));
1023 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
1024 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
1025 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
1026 bool markerBit, const char* payloadData,
1027 unsigned short payloadSize));
1028 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
1029 uint32_t* lastRemoteTimeStamp));
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001030 WEBRTC_FUNC(SetVideoEngineBWETarget, (int channel,
1031 webrtc::ViENetwork* vie_network,
1032 int video_channel)) {
1033 WEBRTC_CHECK_CHANNEL(channel);
1034 channels_[channel]->vie_network = vie_network;
1035 channels_[channel]->video_channel = video_channel;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001036 if (vie_network) {
1037 // The interface is released here to avoid leaks. A test should not
1038 // attempt to call functions on the interface stored in the channel.
1039 vie_network->Release();
1040 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001041 return 0;
1042 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043
1044 // webrtc::VoEVideoSync
1045 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1046 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001047 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1049 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1050 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1051 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1052 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1053 int* playout_buffer_delay_ms));
1054 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1055
1056 // webrtc::VoEVolumeControl
1057 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1058 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1059 WEBRTC_STUB(SetSystemOutputMute, (bool));
1060 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1061 WEBRTC_STUB(SetMicVolume, (unsigned int));
1062 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1063 WEBRTC_STUB(SetInputMute, (int, bool));
1064 WEBRTC_STUB(GetInputMute, (int, bool&));
1065 WEBRTC_STUB(SetSystemInputMute, (bool));
1066 WEBRTC_STUB(GetSystemInputMute, (bool&));
1067 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1068 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1069 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1070 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1071 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1072 WEBRTC_CHECK_CHANNEL(channel);
1073 channels_[channel]->volume_scale= scale;
1074 return 0;
1075 }
1076 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1077 WEBRTC_CHECK_CHANNEL(channel);
1078 scale = channels_[channel]->volume_scale;
1079 return 0;
1080 }
1081 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1082 WEBRTC_CHECK_CHANNEL(channel);
1083 channels_[channel]->volume_pan_left = left;
1084 channels_[channel]->volume_pan_right = right;
1085 return 0;
1086 }
1087 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1088 WEBRTC_CHECK_CHANNEL(channel);
1089 left = channels_[channel]->volume_pan_left;
1090 right = channels_[channel]->volume_pan_right;
1091 return 0;
1092 }
1093
1094 // webrtc::VoEAudioProcessing
1095 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1096 ns_enabled_ = enable;
1097 ns_mode_ = mode;
1098 return 0;
1099 }
1100 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1101 enabled = ns_enabled_;
1102 mode = ns_mode_;
1103 return 0;
1104 }
1105
1106 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1107 agc_enabled_ = enable;
1108 agc_mode_ = mode;
1109 return 0;
1110 }
1111 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1112 enabled = agc_enabled_;
1113 mode = agc_mode_;
1114 return 0;
1115 }
1116
1117 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1118 agc_config_ = config;
1119 return 0;
1120 }
1121 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1122 config = agc_config_;
1123 return 0;
1124 }
1125 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1126 ec_enabled_ = enable;
1127 ec_mode_ = mode;
1128 return 0;
1129 }
1130 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1131 enabled = ec_enabled_;
1132 mode = ec_mode_;
1133 return 0;
1134 }
1135 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1136 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1137 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1138 WEBRTC_STUB(DelayOffsetMs, ());
1139 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1140 aecm_mode_ = mode;
1141 cng_enabled_ = enableCNG;
1142 return 0;
1143 }
1144 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1145 mode = aecm_mode_;
1146 enabledCNG = cng_enabled_;
1147 return 0;
1148 }
1149 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1150 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1151 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001152 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1153 webrtc::AgcModes mode)) {
1154 channels_[channel]->rx_agc_enabled = enable;
1155 channels_[channel]->rx_agc_mode = mode;
1156 return 0;
1157 }
1158 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1159 webrtc::AgcModes& mode)) {
1160 enabled = channels_[channel]->rx_agc_enabled;
1161 mode = channels_[channel]->rx_agc_mode;
1162 return 0;
1163 }
1164
1165 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1166 channels_[channel]->rx_agc_config = config;
1167 return 0;
1168 }
1169 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1170 config = channels_[channel]->rx_agc_config;
1171 return 0;
1172 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173
1174 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1175 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1176 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1177 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1178 ec_metrics_enabled_ = enable;
1179 return 0;
1180 }
1181 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1182 enabled = ec_metrics_enabled_;
1183 return 0;
1184 }
1185 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001186 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1187 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001188
1189 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001190 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001191 WEBRTC_STUB(StopDebugRecording, ());
1192
1193 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1194 typing_detection_enabled_ = enable;
1195 return 0;
1196 }
1197 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1198 enabled = typing_detection_enabled_;
1199 return 0;
1200 }
1201
1202 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1203 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1204 int costPerTyping,
1205 int reportingThreshold,
1206 int penaltyDecay,
1207 int typeEventDelay));
1208 int EnableHighPassFilter(bool enable) {
1209 highpass_filter_enabled_ = enable;
1210 return 0;
1211 }
1212 bool IsHighPassFilterEnabled() {
1213 return highpass_filter_enabled_;
1214 }
1215 bool IsStereoChannelSwappingEnabled() {
1216 return stereo_swapping_enabled_;
1217 }
1218 void EnableStereoChannelSwapping(bool enable) {
1219 stereo_swapping_enabled_ = enable;
1220 }
1221 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1222 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1223 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1224 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1225 }
1226 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1227 return (dtmf_info_.dtmf_event_code == event_code &&
1228 dtmf_info_.dtmf_length_ms == length_ms);
1229 }
1230 // webrtc::VoEExternalMedia
1231 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1232 (int channel, webrtc::ProcessingTypes type,
1233 webrtc::VoEMediaProcess& processObject)) {
1234 WEBRTC_CHECK_CHANNEL(channel);
1235 if (channels_[channel]->media_processor_registered) {
1236 return -1;
1237 }
1238 channels_[channel]->media_processor_registered = true;
1239 media_processor_ = &processObject;
1240 return 0;
1241 }
1242 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1243 (int channel, webrtc::ProcessingTypes type)) {
1244 WEBRTC_CHECK_CHANNEL(channel);
1245 if (!channels_[channel]->media_processor_registered) {
1246 return -1;
1247 }
1248 channels_[channel]->media_processor_registered = false;
1249 media_processor_ = NULL;
1250 return 0;
1251 }
1252 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1253 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1254 WEBRTC_STUB(ExternalRecordingInsertData,
1255 (const int16_t speechData10ms[], int lengthSamples,
1256 int samplingFreqHz, int current_delay_ms));
1257 WEBRTC_STUB(ExternalPlayoutGetData,
1258 (int16_t speechData10ms[], int samplingFreqHz,
1259 int current_delay_ms, int& lengthSamples));
1260 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1261 webrtc::AudioFrame* frame));
1262 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1263
1264 private:
1265 int GetNumDevices(int& num) {
1266#ifdef WIN32
1267 num = 1;
1268#else
1269 // On non-Windows platforms VE adds a special entry for the default device,
1270 // so if there is one physical device then there are two entries in the
1271 // list.
1272 num = 2;
1273#endif
1274 return 0;
1275 }
1276
1277 int GetDeviceName(int i, char* name, char* guid) {
1278 const char *s;
1279#ifdef WIN32
1280 if (0 == i) {
1281 s = kFakeDeviceName;
1282 } else {
1283 return -1;
1284 }
1285#else
1286 // See comment above.
1287 if (0 == i) {
1288 s = kFakeDefaultDeviceName;
1289 } else if (1 == i) {
1290 s = kFakeDeviceName;
1291 } else {
1292 return -1;
1293 }
1294#endif
1295 strcpy(name, s);
1296 guid[0] = '\0';
1297 return 0;
1298 }
1299
1300 bool inited_;
1301 int last_channel_;
1302 std::map<int, Channel*> channels_;
1303 bool fail_create_channel_;
1304 const cricket::AudioCodec* const* codecs_;
1305 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001306 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 bool ec_enabled_;
1308 bool ec_metrics_enabled_;
1309 bool cng_enabled_;
1310 bool ns_enabled_;
1311 bool agc_enabled_;
1312 bool highpass_filter_enabled_;
1313 bool stereo_swapping_enabled_;
1314 bool typing_detection_enabled_;
1315 webrtc::EcModes ec_mode_;
1316 webrtc::AecmModes aecm_mode_;
1317 webrtc::NsModes ns_mode_;
1318 webrtc::AgcModes agc_mode_;
1319 webrtc::AgcConfig agc_config_;
1320 webrtc::VoiceEngineObserver* observer_;
1321 int playout_fail_channel_;
1322 int send_fail_channel_;
1323 bool fail_start_recording_microphone_;
1324 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001325 int recording_sample_rate_;
1326 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 DtmfInfo dtmf_info_;
1328 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001329 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330};
1331
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001332#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1333
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334} // namespace cricket
1335
1336#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_