blob: dba7d634ad9d51bf25fd75d481147bbbae8be7e5 [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.orgf875f152014-04-14 16:06:21 +000044
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045namespace cricket {
46
47// Function returning stats will return these values
48// for all values based on type.
49const int kIntStatValue = 123;
50const float kFractionLostStatValue = 0.5;
51
52static const char kFakeDefaultDeviceName[] = "Fake Default";
53static const int kFakeDefaultDeviceId = -1;
54static const char kFakeDeviceName[] = "Fake Device";
55#ifdef WIN32
56static const int kFakeDeviceId = 0;
57#else
58static const int kFakeDeviceId = 1;
59#endif
60
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +000061static const int kOpusBandwidthNb = 4000;
62static const int kOpusBandwidthMb = 6000;
63static const int kOpusBandwidthWb = 8000;
64static const int kOpusBandwidthSwb = 12000;
65static const int kOpusBandwidthFb = 20000;
66
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +000067static const webrtc::NetworkStatistics kNetStats = {
68 1, // uint16_t currentBufferSize;
69 2, // uint16_t preferredBufferSize;
70 true, // bool jitterPeaksFound;
71 1234, // uint16_t currentPacketLossRate;
72 567, // uint16_t currentDiscardRate;
73 8901, // uint16_t currentExpandRate;
74 234, // uint16_t currentSpeechExpandRate;
75 5678, // uint16_t currentPreemptiveRate;
76 9012, // uint16_t currentAccelerateRate;
77 3456, // uint16_t currentSecondaryDecodedRate;
78 7890, // int32_t clockDriftPPM;
79 54, // meanWaitingTimeMs;
80 32, // int medianWaitingTimeMs;
81 1, // int minWaitingTimeMs;
82 98, // int maxWaitingTimeMs;
83 7654, // int addedSamples;
84}; // These random but non-trivial numbers are used for testing.
85
henrike@webrtc.org79047f92014-03-06 23:46:59 +000086// Verify the header extension ID, if enabled, is within the bounds specified in
87// [RFC5285]: 1-14 inclusive.
88#define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \
89 do { \
90 if (enable && (id < 1 || id > 14)) { \
91 return -1; \
92 } \
93 } while (0);
94
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +000095class FakeAudioProcessing : public webrtc::AudioProcessing {
96 public:
97 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
98
99 WEBRTC_STUB(Initialize, ())
100 WEBRTC_STUB(Initialize, (
101 int input_sample_rate_hz,
102 int output_sample_rate_hz,
103 int reverse_sample_rate_hz,
104 webrtc::AudioProcessing::ChannelLayout input_layout,
105 webrtc::AudioProcessing::ChannelLayout output_layout,
106 webrtc::AudioProcessing::ChannelLayout reverse_layout));
107
108 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
109 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
110 }
111
112 WEBRTC_STUB(set_sample_rate_hz, (int rate));
113 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
114 WEBRTC_STUB_CONST(sample_rate_hz, ());
115 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
116 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
117 WEBRTC_STUB_CONST(num_input_channels, ());
118 WEBRTC_STUB_CONST(num_output_channels, ());
119 WEBRTC_STUB_CONST(num_reverse_channels, ());
120 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
121 WEBRTC_BOOL_STUB_CONST(output_will_be_muted, ());
122 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
123 WEBRTC_STUB(ProcessStream, (
124 const float* const* src,
125 int samples_per_channel,
126 int input_sample_rate_hz,
127 webrtc::AudioProcessing::ChannelLayout input_layout,
128 int output_sample_rate_hz,
129 webrtc::AudioProcessing::ChannelLayout output_layout,
130 float* const* dest));
131 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
132 WEBRTC_STUB(AnalyzeReverseStream, (
133 const float* const* data,
134 int samples_per_channel,
135 int sample_rate_hz,
136 webrtc::AudioProcessing::ChannelLayout layout));
137 WEBRTC_STUB(set_stream_delay_ms, (int delay));
138 WEBRTC_STUB_CONST(stream_delay_ms, ());
139 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
140 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
141 WEBRTC_BOOL_STUB_CONST(stream_key_pressed, ());
142 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
143 WEBRTC_STUB_CONST(delay_offset_ms, ());
144 WEBRTC_STUB(StartDebugRecording, (const char filename[kMaxFilenameSize]));
145 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
146 WEBRTC_STUB(StopDebugRecording, ());
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000147 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
148 webrtc::EchoControlMobile* echo_control_mobile() const override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000149 return NULL;
150 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000151 webrtc::GainControl* gain_control() const override { return NULL; }
152 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
153 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
154 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
155 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000156
157 bool experimental_ns_enabled() {
158 return experimental_ns_enabled_;
159 }
160
161 private:
162 bool experimental_ns_enabled_;
163};
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000164
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165class FakeWebRtcVoiceEngine
166 : public webrtc::VoEAudioProcessing,
167 public webrtc::VoEBase, public webrtc::VoECodec, public webrtc::VoEDtmf,
168 public webrtc::VoEFile, public webrtc::VoEHardware,
169 public webrtc::VoEExternalMedia, public webrtc::VoENetEqStats,
170 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
171 public webrtc::VoEVideoSync, public webrtc::VoEVolumeControl {
172 public:
173 struct DtmfInfo {
174 DtmfInfo()
175 : dtmf_event_code(-1),
176 dtmf_out_of_band(false),
177 dtmf_length_ms(-1) {}
178 int dtmf_event_code;
179 bool dtmf_out_of_band;
180 int dtmf_length_ms;
181 };
182 struct Channel {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000183 explicit Channel()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 : external_transport(false),
185 send(false),
186 playout(false),
187 volume_scale(1.0),
188 volume_pan_left(1.0),
189 volume_pan_right(1.0),
190 file(false),
191 vad(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000192 codec_fec(false),
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000193 max_encoding_bandwidth(0),
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000194 opus_dtx(false),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000195 red(false),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 nack(false),
197 media_processor_registered(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000198 rx_agc_enabled(false),
199 rx_agc_mode(webrtc::kAgcDefault),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 cn8_type(13),
201 cn16_type(105),
202 dtmf_type(106),
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000203 red_type(117),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 nack_max_packets(0),
205 send_ssrc(0),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000206 send_audio_level_ext_(-1),
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000207 receive_audio_level_ext_(-1),
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000208 send_absolute_sender_time_ext_(-1),
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000209 receive_absolute_sender_time_ext_(-1) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 memset(&send_codec, 0, sizeof(send_codec));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000211 memset(&rx_agc_config, 0, sizeof(rx_agc_config));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 }
213 bool external_transport;
214 bool send;
215 bool playout;
216 float volume_scale;
217 float volume_pan_left;
218 float volume_pan_right;
219 bool file;
220 bool vad;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000221 bool codec_fec;
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000222 int max_encoding_bandwidth;
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000223 bool opus_dtx;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000224 bool red;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 bool nack;
226 bool media_processor_registered;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000227 bool rx_agc_enabled;
228 webrtc::AgcModes rx_agc_mode;
229 webrtc::AgcConfig rx_agc_config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 int cn8_type;
231 int cn16_type;
232 int dtmf_type;
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000233 int red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 int nack_max_packets;
235 uint32 send_ssrc;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000236 int send_audio_level_ext_;
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000237 int receive_audio_level_ext_;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000238 int send_absolute_sender_time_ext_;
239 int receive_absolute_sender_time_ext_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 DtmfInfo dtmf_info;
241 std::vector<webrtc::CodecInst> recv_codecs;
242 webrtc::CodecInst send_codec;
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000243 webrtc::PacketTime last_rtp_packet_time;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 std::list<std::string> packets;
245 };
246
247 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs,
248 int num_codecs)
249 : inited_(false),
250 last_channel_(-1),
251 fail_create_channel_(false),
252 codecs_(codecs),
253 num_codecs_(num_codecs),
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000254 num_set_send_codecs_(0),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 ec_enabled_(false),
256 ec_metrics_enabled_(false),
257 cng_enabled_(false),
258 ns_enabled_(false),
259 agc_enabled_(false),
260 highpass_filter_enabled_(false),
261 stereo_swapping_enabled_(false),
262 typing_detection_enabled_(false),
263 ec_mode_(webrtc::kEcDefault),
264 aecm_mode_(webrtc::kAecmSpeakerphone),
265 ns_mode_(webrtc::kNsDefault),
266 agc_mode_(webrtc::kAgcDefault),
267 observer_(NULL),
268 playout_fail_channel_(-1),
269 send_fail_channel_(-1),
270 fail_start_recording_microphone_(false),
271 recording_microphone_(false),
wu@webrtc.org97077a32013-10-25 21:18:33 +0000272 recording_sample_rate_(-1),
273 playout_sample_rate_(-1),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 media_processor_(NULL) {
275 memset(&agc_config_, 0, sizeof(agc_config_));
276 }
277 ~FakeWebRtcVoiceEngine() {
278 // Ought to have all been deleted by the WebRtcVoiceMediaChannel
279 // destructors, but just in case ...
280 for (std::map<int, Channel*>::const_iterator i = channels_.begin();
281 i != channels_.end(); ++i) {
282 delete i->second;
283 }
284 }
285
286 bool IsExternalMediaProcessorRegistered() const {
287 return media_processor_ != NULL;
288 }
289 bool IsInited() const { return inited_; }
290 int GetLastChannel() const { return last_channel_; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +0000291 int GetChannelFromLocalSsrc(uint32 local_ssrc) const {
292 for (std::map<int, Channel*>::const_iterator iter = channels_.begin();
293 iter != channels_.end(); ++iter) {
294 if (local_ssrc == iter->second->send_ssrc)
295 return iter->first;
296 }
297 return -1;
298 }
wu@webrtc.org9caf2762013-12-11 18:25:07 +0000299 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 bool GetPlayout(int channel) {
301 return channels_[channel]->playout;
302 }
303 bool GetSend(int channel) {
304 return channels_[channel]->send;
305 }
306 bool GetRecordingMicrophone() {
307 return recording_microphone_;
308 }
309 bool GetVAD(int channel) {
310 return channels_[channel]->vad;
311 }
Minyue Li7100dcd2015-03-27 05:05:59 +0100312 bool GetOpusDtx(int channel) {
313 return channels_[channel]->opus_dtx;
314 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000315 bool GetRED(int channel) {
316 return channels_[channel]->red;
317 }
318 bool GetCodecFEC(int channel) {
319 return channels_[channel]->codec_fec;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000321 int GetMaxEncodingBandwidth(int channel) {
322 return channels_[channel]->max_encoding_bandwidth;
323 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 bool GetNACK(int channel) {
325 return channels_[channel]->nack;
326 }
327 int GetNACKMaxPackets(int channel) {
328 return channels_[channel]->nack_max_packets;
329 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000330 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
331 WEBRTC_ASSERT_CHANNEL(channel);
332 return channels_[channel]->last_rtp_packet_time;
333 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 int GetSendCNPayloadType(int channel, bool wideband) {
335 return (wideband) ?
336 channels_[channel]->cn16_type :
337 channels_[channel]->cn8_type;
338 }
339 int GetSendTelephoneEventPayloadType(int channel) {
340 return channels_[channel]->dtmf_type;
341 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000342 int GetSendREDPayloadType(int channel) {
343 return channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 }
345 bool CheckPacket(int channel, const void* data, size_t len) {
346 bool result = !CheckNoPacket(channel);
347 if (result) {
348 std::string packet = channels_[channel]->packets.front();
349 result = (packet == std::string(static_cast<const char*>(data), len));
350 channels_[channel]->packets.pop_front();
351 }
352 return result;
353 }
354 bool CheckNoPacket(int channel) {
355 return channels_[channel]->packets.empty();
356 }
357 void TriggerCallbackOnError(int channel_num, int err_code) {
358 ASSERT(observer_ != NULL);
359 observer_->CallbackOnError(channel_num, err_code);
360 }
361 void set_playout_fail_channel(int channel) {
362 playout_fail_channel_ = channel;
363 }
364 void set_send_fail_channel(int channel) {
365 send_fail_channel_ = channel;
366 }
367 void set_fail_start_recording_microphone(
368 bool fail_start_recording_microphone) {
369 fail_start_recording_microphone_ = fail_start_recording_microphone;
370 }
371 void set_fail_create_channel(bool fail_create_channel) {
372 fail_create_channel_ = fail_create_channel;
373 }
374 void TriggerProcessPacket(MediaProcessorDirection direction) {
375 webrtc::ProcessingTypes pt =
376 (direction == cricket::MPD_TX) ?
377 webrtc::kRecordingPerChannel : webrtc::kPlaybackAllChannelsMixed;
378 if (media_processor_ != NULL) {
379 media_processor_->Process(0,
380 pt,
381 NULL,
382 0,
383 0,
384 true);
385 }
386 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000387 int AddChannel() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000388 if (fail_create_channel_) {
389 return -1;
390 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000391 Channel* ch = new Channel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000392 for (int i = 0; i < NumOfCodecs(); ++i) {
393 webrtc::CodecInst codec;
394 GetCodec(i, codec);
395 ch->recv_codecs.push_back(codec);
396 }
397 channels_[++last_channel_] = ch;
398 return last_channel_;
399 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000400 int GetSendRtpExtensionId(int channel, const std::string& extension) {
401 WEBRTC_ASSERT_CHANNEL(channel);
402 if (extension == kRtpAudioLevelHeaderExtension) {
403 return channels_[channel]->send_audio_level_ext_;
404 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
405 return channels_[channel]->send_absolute_sender_time_ext_;
406 }
407 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000408 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000409 int GetReceiveRtpExtensionId(int channel, const std::string& extension) {
410 WEBRTC_ASSERT_CHANNEL(channel);
411 if (extension == kRtpAudioLevelHeaderExtension) {
412 return channels_[channel]->receive_audio_level_ext_;
413 } else if (extension == kRtpAbsoluteSenderTimeHeaderExtension) {
414 return channels_[channel]->receive_absolute_sender_time_ext_;
415 }
416 return -1;
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000417 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000419 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
420
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 WEBRTC_STUB(Release, ());
422
423 // webrtc::VoEBase
424 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
425 webrtc::VoiceEngineObserver& observer)) {
426 observer_ = &observer;
427 return 0;
428 }
429 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
430 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
431 webrtc::AudioProcessing* audioproc)) {
432 inited_ = true;
433 return 0;
434 }
435 WEBRTC_FUNC(Terminate, ()) {
436 inited_ = false;
437 return 0;
438 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000439 webrtc::AudioProcessing* audio_processing() override {
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +0000440 return &audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442 WEBRTC_FUNC(CreateChannel, ()) {
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000443 return AddChannel();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 }
buildbot@webrtc.orgaf6640f2014-04-28 21:31:51 +0000445 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& /*config*/)) {
446 return AddChannel();
wu@webrtc.org364f2042013-11-20 21:49:41 +0000447 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 WEBRTC_FUNC(DeleteChannel, (int channel)) {
449 WEBRTC_CHECK_CHANNEL(channel);
450 delete channels_[channel];
451 channels_.erase(channel);
452 return 0;
453 }
454 WEBRTC_STUB(StartReceive, (int channel));
455 WEBRTC_FUNC(StartPlayout, (int channel)) {
456 if (playout_fail_channel_ != channel) {
457 WEBRTC_CHECK_CHANNEL(channel);
458 channels_[channel]->playout = true;
459 return 0;
460 } else {
461 // When playout_fail_channel_ == channel, fail the StartPlayout on this
462 // channel.
463 return -1;
464 }
465 }
466 WEBRTC_FUNC(StartSend, (int channel)) {
467 if (send_fail_channel_ != channel) {
468 WEBRTC_CHECK_CHANNEL(channel);
469 channels_[channel]->send = true;
470 return 0;
471 } else {
472 // When send_fail_channel_ == channel, fail the StartSend on this
473 // channel.
474 return -1;
475 }
476 }
477 WEBRTC_STUB(StopReceive, (int channel));
478 WEBRTC_FUNC(StopPlayout, (int channel)) {
479 WEBRTC_CHECK_CHANNEL(channel);
480 channels_[channel]->playout = false;
481 return 0;
482 }
483 WEBRTC_FUNC(StopSend, (int channel)) {
484 WEBRTC_CHECK_CHANNEL(channel);
485 channels_[channel]->send = false;
486 return 0;
487 }
488 WEBRTC_STUB(GetVersion, (char version[1024]));
489 WEBRTC_STUB(LastError, ());
490 WEBRTC_STUB(SetOnHoldStatus, (int, bool, webrtc::OnHoldModes));
491 WEBRTC_STUB(GetOnHoldStatus, (int, bool&, webrtc::OnHoldModes&));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492
493 // webrtc::VoECodec
494 WEBRTC_FUNC(NumOfCodecs, ()) {
495 return num_codecs_;
496 }
497 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) {
498 if (index < 0 || index >= NumOfCodecs()) {
499 return -1;
500 }
501 const cricket::AudioCodec& c(*codecs_[index]);
502 codec.pltype = c.id;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000503 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 codec.plfreq = c.clockrate;
505 codec.pacsize = 0;
506 codec.channels = c.channels;
507 codec.rate = c.bitrate;
508 return 0;
509 }
510 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
511 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org704bf9e2014-02-27 17:52:04 +0000512 // To match the behavior of the real implementation.
513 if (_stricmp(codec.plname, "telephone-event") == 0 ||
514 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
515 _stricmp(codec.plname, "CN") == 0 ||
516 _stricmp(codec.plname, "red") == 0 ) {
517 return -1;
518 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 channels_[channel]->send_codec = codec;
wu@webrtc.org05e7b442014-04-01 17:44:24 +0000520 ++num_set_send_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 return 0;
522 }
523 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
524 WEBRTC_CHECK_CHANNEL(channel);
525 codec = channels_[channel]->send_codec;
526 return 0;
527 }
Ivo Creusenadf89b72015-04-29 16:03:33 +0200528 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
buildbot@webrtc.org7e71b772014-06-13 01:14:01 +0000529 WEBRTC_FUNC(GetRecCodec, (int channel, webrtc::CodecInst& codec)) {
530 WEBRTC_CHECK_CHANNEL(channel);
531 const Channel* c = channels_[channel];
532 for (std::list<std::string>::const_iterator it_packet = c->packets.begin();
533 it_packet != c->packets.end(); ++it_packet) {
534 int pltype;
535 if (!GetRtpPayloadType(it_packet->data(), it_packet->length(), &pltype)) {
536 continue;
537 }
538 for (std::vector<webrtc::CodecInst>::const_iterator it_codec =
539 c->recv_codecs.begin(); it_codec != c->recv_codecs.end();
540 ++it_codec) {
541 if (it_codec->pltype == pltype) {
542 codec = *it_codec;
543 return 0;
544 }
545 }
546 }
547 return -1;
548 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 WEBRTC_STUB(SetAMREncFormat, (int channel, webrtc::AmrMode mode));
550 WEBRTC_STUB(SetAMRDecFormat, (int channel, webrtc::AmrMode mode));
551 WEBRTC_STUB(SetAMRWbEncFormat, (int channel, webrtc::AmrMode mode));
552 WEBRTC_STUB(SetAMRWbDecFormat, (int channel, webrtc::AmrMode mode));
553 WEBRTC_STUB(SetISACInitTargetRate, (int channel, int rateBps,
554 bool useFixedFrameSize));
555 WEBRTC_STUB(SetISACMaxRate, (int channel, int rateBps));
556 WEBRTC_STUB(SetISACMaxPayloadSize, (int channel, int sizeBytes));
557 WEBRTC_FUNC(SetRecPayloadType, (int channel,
558 const webrtc::CodecInst& codec)) {
559 WEBRTC_CHECK_CHANNEL(channel);
560 Channel* ch = channels_[channel];
561 if (ch->playout)
562 return -1; // Channel is in use.
563 // Check if something else already has this slot.
564 if (codec.pltype != -1) {
565 for (std::vector<webrtc::CodecInst>::iterator it =
566 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
567 if (it->pltype == codec.pltype &&
568 _stricmp(it->plname, codec.plname) != 0) {
569 return -1;
570 }
571 }
572 }
573 // Otherwise try to find this codec and update its payload type.
574 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
575 it != ch->recv_codecs.end(); ++it) {
576 if (strcmp(it->plname, codec.plname) == 0 &&
577 it->plfreq == codec.plfreq) {
578 it->pltype = codec.pltype;
579 it->channels = codec.channels;
580 return 0;
581 }
582 }
583 return -1; // not found
584 }
585 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
586 webrtc::PayloadFrequencies frequency)) {
587 WEBRTC_CHECK_CHANNEL(channel);
588 if (frequency == webrtc::kFreq8000Hz) {
589 channels_[channel]->cn8_type = type;
590 } else if (frequency == webrtc::kFreq16000Hz) {
591 channels_[channel]->cn16_type = type;
592 }
593 return 0;
594 }
595 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
596 WEBRTC_CHECK_CHANNEL(channel);
597 Channel* ch = channels_[channel];
598 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
599 it != ch->recv_codecs.end(); ++it) {
600 if (strcmp(it->plname, codec.plname) == 0 &&
601 it->plfreq == codec.plfreq &&
602 it->channels == codec.channels &&
603 it->pltype != -1) {
604 codec.pltype = it->pltype;
605 return 0;
606 }
607 }
608 return -1; // not found
609 }
610 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
611 bool disableDTX)) {
612 WEBRTC_CHECK_CHANNEL(channel);
613 if (channels_[channel]->send_codec.channels == 2) {
614 // Replicating VoE behavior; VAD cannot be enabled for stereo.
615 return -1;
616 }
617 channels_[channel]->vad = enable;
618 return 0;
619 }
620 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
621 webrtc::VadModes& mode, bool& disabledDTX));
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000622
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000623 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
624 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000625 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
buildbot@webrtc.org3ffa1f92014-07-02 19:51:26 +0000626 // Return -1 if current send codec is not Opus.
627 // TODO(minyue): Excludes other codecs if they support inband FEC.
628 return -1;
629 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000630 channels_[channel]->codec_fec = enable;
631 return 0;
632 }
633 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
634 WEBRTC_CHECK_CHANNEL(channel);
635 enable = channels_[channel]->codec_fec;
636 return 0;
637 }
buildbot@webrtc.org5d639b32014-09-10 07:57:12 +0000638
639 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
640 WEBRTC_CHECK_CHANNEL(channel);
641 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
642 // Return -1 if current send codec is not Opus.
643 return -1;
644 }
645 if (frequency_hz <= 8000)
646 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
647 else if (frequency_hz <= 12000)
648 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
649 else if (frequency_hz <= 16000)
650 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
651 else if (frequency_hz <= 24000)
652 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
653 else
654 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
655 return 0;
656 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657
minyue@webrtc.org9b2e1142015-03-13 09:38:07 +0000658 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
659 WEBRTC_CHECK_CHANNEL(channel);
660 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
661 // Return -1 if current send codec is not Opus.
662 return -1;
663 }
664 channels_[channel]->opus_dtx = enable_dtx;
665 return 0;
666 }
667
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668 // webrtc::VoEDtmf
669 WEBRTC_FUNC(SendTelephoneEvent, (int channel, int event_code,
670 bool out_of_band = true, int length_ms = 160, int attenuation_db = 10)) {
671 channels_[channel]->dtmf_info.dtmf_event_code = event_code;
672 channels_[channel]->dtmf_info.dtmf_out_of_band = out_of_band;
673 channels_[channel]->dtmf_info.dtmf_length_ms = length_ms;
674 return 0;
675 }
676
677 WEBRTC_FUNC(SetSendTelephoneEventPayloadType,
678 (int channel, unsigned char type)) {
679 channels_[channel]->dtmf_type = type;
680 return 0;
681 };
682 WEBRTC_STUB(GetSendTelephoneEventPayloadType,
683 (int channel, unsigned char& type));
684
685 WEBRTC_STUB(SetDtmfFeedbackStatus, (bool enable, bool directFeedback));
686 WEBRTC_STUB(GetDtmfFeedbackStatus, (bool& enabled, bool& directFeedback));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 WEBRTC_FUNC(PlayDtmfTone,
689 (int event_code, int length_ms = 200, int attenuation_db = 10)) {
690 dtmf_info_.dtmf_event_code = event_code;
691 dtmf_info_.dtmf_length_ms = length_ms;
692 return 0;
693 }
694 WEBRTC_STUB(StartPlayingDtmfTone,
695 (int eventCode, int attenuationDb = 10));
696 WEBRTC_STUB(StopPlayingDtmfTone, ());
697
698 // webrtc::VoEFile
699 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, const char* fileNameUTF8,
700 bool loop, webrtc::FileFormats format,
701 float volumeScaling, int startPointMs,
702 int stopPointMs)) {
703 WEBRTC_CHECK_CHANNEL(channel);
704 channels_[channel]->file = true;
705 return 0;
706 }
707 WEBRTC_FUNC(StartPlayingFileLocally, (int channel, webrtc::InStream* stream,
708 webrtc::FileFormats format,
709 float volumeScaling, int startPointMs,
710 int stopPointMs)) {
711 WEBRTC_CHECK_CHANNEL(channel);
712 channels_[channel]->file = true;
713 return 0;
714 }
715 WEBRTC_FUNC(StopPlayingFileLocally, (int channel)) {
716 WEBRTC_CHECK_CHANNEL(channel);
717 channels_[channel]->file = false;
718 return 0;
719 }
720 WEBRTC_FUNC(IsPlayingFileLocally, (int channel)) {
721 WEBRTC_CHECK_CHANNEL(channel);
722 return (channels_[channel]->file) ? 1 : 0;
723 }
724 WEBRTC_STUB(ScaleLocalFilePlayout, (int channel, float scale));
725 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
726 const char* fileNameUTF8,
727 bool loop,
728 bool mixWithMicrophone,
729 webrtc::FileFormats format,
730 float volumeScaling));
731 WEBRTC_STUB(StartPlayingFileAsMicrophone, (int channel,
732 webrtc::InStream* stream,
733 bool mixWithMicrophone,
734 webrtc::FileFormats format,
735 float volumeScaling));
736 WEBRTC_STUB(StopPlayingFileAsMicrophone, (int channel));
737 WEBRTC_STUB(IsPlayingFileAsMicrophone, (int channel));
738 WEBRTC_STUB(ScaleFileAsMicrophonePlayout, (int channel, float scale));
739 WEBRTC_STUB(StartRecordingPlayout, (int channel, const char* fileNameUTF8,
740 webrtc::CodecInst* compression,
741 int maxSizeBytes));
742 WEBRTC_STUB(StartRecordingPlayout, (int channel, webrtc::OutStream* stream,
743 webrtc::CodecInst* compression));
744 WEBRTC_STUB(StopRecordingPlayout, (int channel));
745 WEBRTC_FUNC(StartRecordingMicrophone, (const char* fileNameUTF8,
746 webrtc::CodecInst* compression,
747 int maxSizeBytes)) {
748 if (fail_start_recording_microphone_) {
749 return -1;
750 }
751 recording_microphone_ = true;
752 return 0;
753 }
754 WEBRTC_FUNC(StartRecordingMicrophone, (webrtc::OutStream* stream,
755 webrtc::CodecInst* compression)) {
756 if (fail_start_recording_microphone_) {
757 return -1;
758 }
759 recording_microphone_ = true;
760 return 0;
761 }
762 WEBRTC_FUNC(StopRecordingMicrophone, ()) {
763 if (!recording_microphone_) {
764 return -1;
765 }
766 recording_microphone_ = false;
767 return 0;
768 }
769 WEBRTC_STUB(ConvertPCMToWAV, (const char* fileNameInUTF8,
770 const char* fileNameOutUTF8));
771 WEBRTC_STUB(ConvertPCMToWAV, (webrtc::InStream* streamIn,
772 webrtc::OutStream* streamOut));
773 WEBRTC_STUB(ConvertWAVToPCM, (const char* fileNameInUTF8,
774 const char* fileNameOutUTF8));
775 WEBRTC_STUB(ConvertWAVToPCM, (webrtc::InStream* streamIn,
776 webrtc::OutStream* streamOut));
777 WEBRTC_STUB(ConvertPCMToCompressed, (const char* fileNameInUTF8,
778 const char* fileNameOutUTF8,
779 webrtc::CodecInst* compression));
780 WEBRTC_STUB(ConvertPCMToCompressed, (webrtc::InStream* streamIn,
781 webrtc::OutStream* streamOut,
782 webrtc::CodecInst* compression));
783 WEBRTC_STUB(ConvertCompressedToPCM, (const char* fileNameInUTF8,
784 const char* fileNameOutUTF8));
785 WEBRTC_STUB(ConvertCompressedToPCM, (webrtc::InStream* streamIn,
786 webrtc::OutStream* streamOut));
787 WEBRTC_STUB(GetFileDuration, (const char* fileNameUTF8, int& durationMs,
788 webrtc::FileFormats format));
789 WEBRTC_STUB(GetPlaybackPosition, (int channel, int& positionMs));
790
791 // webrtc::VoEHardware
792 WEBRTC_STUB(GetCPULoad, (int&));
793 WEBRTC_FUNC(GetNumOfRecordingDevices, (int& num)) {
794 return GetNumDevices(num);
795 }
796 WEBRTC_FUNC(GetNumOfPlayoutDevices, (int& num)) {
797 return GetNumDevices(num);
798 }
799 WEBRTC_FUNC(GetRecordingDeviceName, (int i, char* name, char* guid)) {
800 return GetDeviceName(i, name, guid);
801 }
802 WEBRTC_FUNC(GetPlayoutDeviceName, (int i, char* name, char* guid)) {
803 return GetDeviceName(i, name, guid);
804 }
805 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
806 WEBRTC_STUB(SetPlayoutDevice, (int));
807 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
808 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
809 WEBRTC_STUB(GetPlayoutDeviceStatus, (bool&));
810 WEBRTC_STUB(GetRecordingDeviceStatus, (bool&));
811 WEBRTC_STUB(ResetAudioDevice, ());
812 WEBRTC_STUB(AudioDeviceControl, (unsigned int, unsigned int, unsigned int));
813 WEBRTC_STUB(SetLoudspeakerStatus, (bool enable));
814 WEBRTC_STUB(GetLoudspeakerStatus, (bool& enabled));
wu@webrtc.org97077a32013-10-25 21:18:33 +0000815 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
816 recording_sample_rate_ = samples_per_sec;
817 return 0;
818 }
819 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
820 *samples_per_sec = recording_sample_rate_;
821 return 0;
822 }
823 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
824 playout_sample_rate_ = samples_per_sec;
825 return 0;
826 }
827 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
828 *samples_per_sec = playout_sample_rate_;
829 return 0;
830 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
832 virtual bool BuiltInAECIsEnabled() const { return true; }
henrika@webrtc.orga954c072014-12-09 16:22:09 +0000833 virtual bool BuiltInAECIsAvailable() const { return false; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834
835 // webrtc::VoENetEqStats
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000836 WEBRTC_FUNC(GetNetworkStatistics, (int channel,
837 webrtc::NetworkStatistics& ns)) {
838 WEBRTC_CHECK_CHANNEL(channel);
839 memcpy(&ns, &kNetStats, sizeof(webrtc::NetworkStatistics));
840 return 0;
841 }
842
wu@webrtc.org24301a62013-12-13 19:17:43 +0000843 WEBRTC_FUNC_CONST(GetDecodingCallStatistics, (int channel,
844 webrtc::AudioDecodingCallStats*)) {
845 WEBRTC_CHECK_CHANNEL(channel);
846 return 0;
847 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848
849 // webrtc::VoENetwork
850 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
851 webrtc::Transport& transport)) {
852 WEBRTC_CHECK_CHANNEL(channel);
853 channels_[channel]->external_transport = true;
854 return 0;
855 }
856 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
857 WEBRTC_CHECK_CHANNEL(channel);
858 channels_[channel]->external_transport = false;
859 return 0;
860 }
861 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000862 size_t length)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 WEBRTC_CHECK_CHANNEL(channel);
864 if (!channels_[channel]->external_transport) return -1;
865 channels_[channel]->packets.push_back(
866 std::string(static_cast<const char*>(data), length));
867 return 0;
868 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000869 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000870 size_t length,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000871 const webrtc::PacketTime& packet_time)) {
872 WEBRTC_CHECK_CHANNEL(channel);
873 if (ReceivedRTPPacket(channel, data, length) == -1) {
874 return -1;
875 }
876 channels_[channel]->last_rtp_packet_time = packet_time;
877 return 0;
878 }
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +0000879
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000881 size_t length));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882
883 // webrtc::VoERTP_RTCP
884 WEBRTC_STUB(RegisterRTPObserver, (int channel,
885 webrtc::VoERTPObserver& observer));
886 WEBRTC_STUB(DeRegisterRTPObserver, (int channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
888 WEBRTC_CHECK_CHANNEL(channel);
889 channels_[channel]->send_ssrc = ssrc;
890 return 0;
891 }
892 WEBRTC_FUNC(GetLocalSSRC, (int channel, unsigned int& ssrc)) {
893 WEBRTC_CHECK_CHANNEL(channel);
894 ssrc = channels_[channel]->send_ssrc;
895 return 0;
896 }
897 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000898 WEBRTC_FUNC(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
899 unsigned char id)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 WEBRTC_CHECK_CHANNEL(channel);
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000901 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
902 channels_[channel]->send_audio_level_ext_ = (enable) ? id : -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 return 0;
904 }
buildbot@webrtc.org150835e2014-05-06 15:54:38 +0000905 WEBRTC_FUNC(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
906 unsigned char id)) {
907 WEBRTC_CHECK_CHANNEL(channel);
908 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
909 channels_[channel]->receive_audio_level_ext_ = (enable) ? id : -1;
910 return 0;
911 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000912 WEBRTC_FUNC(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
913 unsigned char id)) {
914 WEBRTC_CHECK_CHANNEL(channel);
915 WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id);
916 channels_[channel]->send_absolute_sender_time_ext_ = (enable) ? id : -1;
917 return 0;
918 }
919 WEBRTC_FUNC(SetReceiveAbsoluteSenderTimeStatus, (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_absolute_sender_time_ext_ = (enable) ? id : -1;
924 return 0;
925 }
henrike@webrtc.org79047f92014-03-06 23:46:59 +0000926
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 WEBRTC_STUB(GetRemoteCSRCs, (int channel, unsigned int arrCSRC[15]));
928 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
929 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
930 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
931 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
932 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
933 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
934 unsigned int& NTPLow,
935 unsigned int& timestamp,
936 unsigned int& playoutTimestamp,
937 unsigned int* jitter,
938 unsigned short* fractionLost));
939 WEBRTC_STUB(GetRemoteRTCPSenderInfo, (int channel,
940 webrtc::SenderInfo* sender_info));
941 WEBRTC_FUNC(GetRemoteRTCPReportBlocks,
942 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks)) {
943 WEBRTC_CHECK_CHANNEL(channel);
944 webrtc::ReportBlock block;
945 block.source_SSRC = channels_[channel]->send_ssrc;
946 webrtc::CodecInst send_codec = channels_[channel]->send_codec;
947 if (send_codec.pltype >= 0) {
948 block.fraction_lost = (unsigned char)(kFractionLostStatValue * 256);
949 if (send_codec.plfreq / 1000 > 0) {
950 block.interarrival_jitter = kIntStatValue * (send_codec.plfreq / 1000);
951 }
952 block.cumulative_num_packets_lost = kIntStatValue;
953 block.extended_highest_sequence_number = kIntStatValue;
954 receive_blocks->push_back(block);
955 }
956 return 0;
957 }
958 WEBRTC_STUB(SendApplicationDefinedRTCPPacket, (int channel,
959 unsigned char subType,
960 unsigned int name,
961 const char* data,
962 unsigned short dataLength));
963 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
964 unsigned int& maxJitterMs,
965 unsigned int& discardedPackets));
966 WEBRTC_FUNC(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)) {
967 WEBRTC_CHECK_CHANNEL(channel);
968 stats.fractionLost = static_cast<int16>(kIntStatValue);
969 stats.cumulativeLost = kIntStatValue;
970 stats.extendedMax = kIntStatValue;
971 stats.jitterSamples = kIntStatValue;
972 stats.rttMs = kIntStatValue;
973 stats.bytesSent = kIntStatValue;
974 stats.packetsSent = kIntStatValue;
975 stats.bytesReceived = kIntStatValue;
976 stats.packetsReceived = kIntStatValue;
977 return 0;
978 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000979 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000980 return SetFECStatus(channel, enable, redPayloadtype);
981 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000982 // TODO(minyue): remove the below function when transition to SetREDStatus
983 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) {
985 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000986 channels_[channel]->red = enable;
987 channels_[channel]->red_type = redPayloadtype;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 return 0;
989 }
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000990 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000991 return GetFECStatus(channel, enable, redPayloadtype);
992 }
buildbot@webrtc.orgbfa758a2014-06-27 16:04:43 +0000993 // TODO(minyue): remove the below function when transition to GetREDStatus
994 // is finished.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) {
996 WEBRTC_CHECK_CHANNEL(channel);
buildbot@webrtc.orgae740dd2014-06-17 10:56:41 +0000997 enable = channels_[channel]->red;
998 redPayloadtype = channels_[channel]->red_type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 return 0;
1000 }
1001 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
1002 WEBRTC_CHECK_CHANNEL(channel);
1003 channels_[channel]->nack = enable;
1004 channels_[channel]->nack_max_packets = maxNoPackets;
1005 return 0;
1006 }
1007 WEBRTC_STUB(StartRTPDump, (int channel, const char* fileNameUTF8,
1008 webrtc::RTPDirections direction));
1009 WEBRTC_STUB(StopRTPDump, (int channel, webrtc::RTPDirections direction));
1010 WEBRTC_STUB(RTPDumpIsActive, (int channel, webrtc::RTPDirections direction));
1011 WEBRTC_STUB(InsertExtraRTPPacket, (int channel, unsigned char payloadType,
1012 bool markerBit, const char* payloadData,
1013 unsigned short payloadSize));
1014 WEBRTC_STUB(GetLastRemoteTimeStamp, (int channel,
1015 uint32_t* lastRemoteTimeStamp));
Fredrik Solenberg6179b892015-05-07 16:01:26 +02001016 WEBRTC_STUB(SetVideoEngineBWETarget, (int channel,
buildbot@webrtc.orgf875f152014-04-14 16:06:21 +00001017 webrtc::ViENetwork* vie_network,
Fredrik Solenberg6179b892015-05-07 16:01:26 +02001018 int video_channel));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019
1020 // webrtc::VoEVideoSync
1021 WEBRTC_STUB(GetPlayoutBufferSize, (int& bufferMs));
1022 WEBRTC_STUB(GetPlayoutTimestamp, (int channel, unsigned int& timestamp));
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001023 WEBRTC_STUB(GetRtpRtcp, (int, webrtc::RtpRtcp**, webrtc::RtpReceiver**));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 WEBRTC_STUB(SetInitTimestamp, (int channel, unsigned int timestamp));
1025 WEBRTC_STUB(SetInitSequenceNumber, (int channel, short sequenceNumber));
1026 WEBRTC_STUB(SetMinimumPlayoutDelay, (int channel, int delayMs));
1027 WEBRTC_STUB(SetInitialPlayoutDelay, (int channel, int delay_ms));
1028 WEBRTC_STUB(GetDelayEstimate, (int channel, int* jitter_buffer_delay_ms,
1029 int* playout_buffer_delay_ms));
1030 WEBRTC_STUB_CONST(GetLeastRequiredDelayMs, (int channel));
1031
1032 // webrtc::VoEVolumeControl
1033 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
1034 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
1035 WEBRTC_STUB(SetSystemOutputMute, (bool));
1036 WEBRTC_STUB(GetSystemOutputMute, (bool&));
1037 WEBRTC_STUB(SetMicVolume, (unsigned int));
1038 WEBRTC_STUB(GetMicVolume, (unsigned int&));
1039 WEBRTC_STUB(SetInputMute, (int, bool));
1040 WEBRTC_STUB(GetInputMute, (int, bool&));
1041 WEBRTC_STUB(SetSystemInputMute, (bool));
1042 WEBRTC_STUB(GetSystemInputMute, (bool&));
1043 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
1044 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
1045 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
1046 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
1047 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
1048 WEBRTC_CHECK_CHANNEL(channel);
1049 channels_[channel]->volume_scale= scale;
1050 return 0;
1051 }
1052 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
1053 WEBRTC_CHECK_CHANNEL(channel);
1054 scale = channels_[channel]->volume_scale;
1055 return 0;
1056 }
1057 WEBRTC_FUNC(SetOutputVolumePan, (int channel, float left, float right)) {
1058 WEBRTC_CHECK_CHANNEL(channel);
1059 channels_[channel]->volume_pan_left = left;
1060 channels_[channel]->volume_pan_right = right;
1061 return 0;
1062 }
1063 WEBRTC_FUNC(GetOutputVolumePan, (int channel, float& left, float& right)) {
1064 WEBRTC_CHECK_CHANNEL(channel);
1065 left = channels_[channel]->volume_pan_left;
1066 right = channels_[channel]->volume_pan_right;
1067 return 0;
1068 }
1069
1070 // webrtc::VoEAudioProcessing
1071 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
1072 ns_enabled_ = enable;
1073 ns_mode_ = mode;
1074 return 0;
1075 }
1076 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
1077 enabled = ns_enabled_;
1078 mode = ns_mode_;
1079 return 0;
1080 }
1081
1082 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
1083 agc_enabled_ = enable;
1084 agc_mode_ = mode;
1085 return 0;
1086 }
1087 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
1088 enabled = agc_enabled_;
1089 mode = agc_mode_;
1090 return 0;
1091 }
1092
1093 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
1094 agc_config_ = config;
1095 return 0;
1096 }
1097 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
1098 config = agc_config_;
1099 return 0;
1100 }
1101 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
1102 ec_enabled_ = enable;
1103 ec_mode_ = mode;
1104 return 0;
1105 }
1106 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
1107 enabled = ec_enabled_;
1108 mode = ec_mode_;
1109 return 0;
1110 }
1111 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
1112 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
1113 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
1114 WEBRTC_STUB(DelayOffsetMs, ());
1115 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
1116 aecm_mode_ = mode;
1117 cng_enabled_ = enableCNG;
1118 return 0;
1119 }
1120 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
1121 mode = aecm_mode_;
1122 enabledCNG = cng_enabled_;
1123 return 0;
1124 }
1125 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
1126 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
1127 webrtc::NsModes& mode));
wu@webrtc.org97077a32013-10-25 21:18:33 +00001128 WEBRTC_FUNC(SetRxAgcStatus, (int channel, bool enable,
1129 webrtc::AgcModes mode)) {
1130 channels_[channel]->rx_agc_enabled = enable;
1131 channels_[channel]->rx_agc_mode = mode;
1132 return 0;
1133 }
1134 WEBRTC_FUNC(GetRxAgcStatus, (int channel, bool& enabled,
1135 webrtc::AgcModes& mode)) {
1136 enabled = channels_[channel]->rx_agc_enabled;
1137 mode = channels_[channel]->rx_agc_mode;
1138 return 0;
1139 }
1140
1141 WEBRTC_FUNC(SetRxAgcConfig, (int channel, webrtc::AgcConfig config)) {
1142 channels_[channel]->rx_agc_config = config;
1143 return 0;
1144 }
1145 WEBRTC_FUNC(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config)) {
1146 config = channels_[channel]->rx_agc_config;
1147 return 0;
1148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149
1150 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
1151 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
1152 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
1153 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
1154 ec_metrics_enabled_ = enable;
1155 return 0;
1156 }
1157 WEBRTC_FUNC(GetEcMetricsStatus, (bool& enabled)) {
1158 enabled = ec_metrics_enabled_;
1159 return 0;
1160 }
1161 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
bjornv@webrtc.orgcc64a9c2015-02-05 12:52:44 +00001162 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
1163 float& fraction_poor_delays));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164
1165 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
wu@webrtc.org9caf2762013-12-11 18:25:07 +00001166 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 WEBRTC_STUB(StopDebugRecording, ());
1168
1169 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
1170 typing_detection_enabled_ = enable;
1171 return 0;
1172 }
1173 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
1174 enabled = typing_detection_enabled_;
1175 return 0;
1176 }
1177
1178 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
1179 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
1180 int costPerTyping,
1181 int reportingThreshold,
1182 int penaltyDecay,
1183 int typeEventDelay));
1184 int EnableHighPassFilter(bool enable) {
1185 highpass_filter_enabled_ = enable;
1186 return 0;
1187 }
1188 bool IsHighPassFilterEnabled() {
1189 return highpass_filter_enabled_;
1190 }
1191 bool IsStereoChannelSwappingEnabled() {
1192 return stereo_swapping_enabled_;
1193 }
1194 void EnableStereoChannelSwapping(bool enable) {
1195 stereo_swapping_enabled_ = enable;
1196 }
1197 bool WasSendTelephoneEventCalled(int channel, int event_code, int length_ms) {
1198 return (channels_[channel]->dtmf_info.dtmf_event_code == event_code &&
1199 channels_[channel]->dtmf_info.dtmf_out_of_band == true &&
1200 channels_[channel]->dtmf_info.dtmf_length_ms == length_ms);
1201 }
1202 bool WasPlayDtmfToneCalled(int event_code, int length_ms) {
1203 return (dtmf_info_.dtmf_event_code == event_code &&
1204 dtmf_info_.dtmf_length_ms == length_ms);
1205 }
1206 // webrtc::VoEExternalMedia
1207 WEBRTC_FUNC(RegisterExternalMediaProcessing,
1208 (int channel, webrtc::ProcessingTypes type,
1209 webrtc::VoEMediaProcess& processObject)) {
1210 WEBRTC_CHECK_CHANNEL(channel);
1211 if (channels_[channel]->media_processor_registered) {
1212 return -1;
1213 }
1214 channels_[channel]->media_processor_registered = true;
1215 media_processor_ = &processObject;
1216 return 0;
1217 }
1218 WEBRTC_FUNC(DeRegisterExternalMediaProcessing,
1219 (int channel, webrtc::ProcessingTypes type)) {
1220 WEBRTC_CHECK_CHANNEL(channel);
1221 if (!channels_[channel]->media_processor_registered) {
1222 return -1;
1223 }
1224 channels_[channel]->media_processor_registered = false;
1225 media_processor_ = NULL;
1226 return 0;
1227 }
1228 WEBRTC_STUB(SetExternalRecordingStatus, (bool enable));
1229 WEBRTC_STUB(SetExternalPlayoutStatus, (bool enable));
1230 WEBRTC_STUB(ExternalRecordingInsertData,
1231 (const int16_t speechData10ms[], int lengthSamples,
1232 int samplingFreqHz, int current_delay_ms));
1233 WEBRTC_STUB(ExternalPlayoutGetData,
1234 (int16_t speechData10ms[], int samplingFreqHz,
1235 int current_delay_ms, int& lengthSamples));
1236 WEBRTC_STUB(GetAudioFrame, (int channel, int desired_sample_rate_hz,
1237 webrtc::AudioFrame* frame));
1238 WEBRTC_STUB(SetExternalMixing, (int channel, bool enable));
1239
1240 private:
1241 int GetNumDevices(int& num) {
1242#ifdef WIN32
1243 num = 1;
1244#else
1245 // On non-Windows platforms VE adds a special entry for the default device,
1246 // so if there is one physical device then there are two entries in the
1247 // list.
1248 num = 2;
1249#endif
1250 return 0;
1251 }
1252
1253 int GetDeviceName(int i, char* name, char* guid) {
1254 const char *s;
1255#ifdef WIN32
1256 if (0 == i) {
1257 s = kFakeDeviceName;
1258 } else {
1259 return -1;
1260 }
1261#else
1262 // See comment above.
1263 if (0 == i) {
1264 s = kFakeDefaultDeviceName;
1265 } else if (1 == i) {
1266 s = kFakeDeviceName;
1267 } else {
1268 return -1;
1269 }
1270#endif
1271 strcpy(name, s);
1272 guid[0] = '\0';
1273 return 0;
1274 }
1275
1276 bool inited_;
1277 int last_channel_;
1278 std::map<int, Channel*> channels_;
1279 bool fail_create_channel_;
1280 const cricket::AudioCodec* const* codecs_;
1281 int num_codecs_;
wu@webrtc.org05e7b442014-04-01 17:44:24 +00001282 int num_set_send_codecs_; // how many times we call SetSendCodec().
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 bool ec_enabled_;
1284 bool ec_metrics_enabled_;
1285 bool cng_enabled_;
1286 bool ns_enabled_;
1287 bool agc_enabled_;
1288 bool highpass_filter_enabled_;
1289 bool stereo_swapping_enabled_;
1290 bool typing_detection_enabled_;
1291 webrtc::EcModes ec_mode_;
1292 webrtc::AecmModes aecm_mode_;
1293 webrtc::NsModes ns_mode_;
1294 webrtc::AgcModes agc_mode_;
1295 webrtc::AgcConfig agc_config_;
1296 webrtc::VoiceEngineObserver* observer_;
1297 int playout_fail_channel_;
1298 int send_fail_channel_;
1299 bool fail_start_recording_microphone_;
1300 bool recording_microphone_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001301 int recording_sample_rate_;
1302 int playout_sample_rate_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 DtmfInfo dtmf_info_;
1304 webrtc::VoEMediaProcess* media_processor_;
buildbot@webrtc.orga8d8ad22014-07-16 14:23:08 +00001305 FakeAudioProcessing audio_processing_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306};
1307
henrike@webrtc.org79047f92014-03-06 23:46:59 +00001308#undef WEBRTC_CHECK_HEADER_EXTENSION_ID
1309
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310} // namespace cricket
1311
1312#endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_