Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Side by Side Diff: talk/media/webrtc/fakewebrtcvoiceengine.h

Issue 1587193006: Move talk/media to webrtc/media (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased to b647aca12a884a13c1728118586245399b55fa3d (#11493) Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/media/webrtc/fakewebrtcvideoengine.h ('k') | talk/media/webrtc/nullwebrtcvideoengine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
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
35 #include "talk/media/base/codec.h"
36 #include "talk/media/base/rtputils.h"
37 #include "talk/media/webrtc/fakewebrtccommon.h"
38 #include "talk/media/webrtc/webrtcvoe.h"
39 #include "webrtc/base/basictypes.h"
40 #include "webrtc/base/checks.h"
41 #include "webrtc/base/gunit.h"
42 #include "webrtc/base/stringutils.h"
43 #include "webrtc/config.h"
44 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
45 #include "webrtc/modules/audio_processing/include/audio_processing.h"
46
47 namespace cricket {
48
49 static const int kOpusBandwidthNb = 4000;
50 static const int kOpusBandwidthMb = 6000;
51 static const int kOpusBandwidthWb = 8000;
52 static const int kOpusBandwidthSwb = 12000;
53 static const int kOpusBandwidthFb = 20000;
54
55 #define WEBRTC_CHECK_CHANNEL(channel) \
56 if (channels_.find(channel) == channels_.end()) return -1;
57
58 class FakeAudioProcessing : public webrtc::AudioProcessing {
59 public:
60 FakeAudioProcessing() : experimental_ns_enabled_(false) {}
61
62 WEBRTC_STUB(Initialize, ())
63 WEBRTC_STUB(Initialize, (
64 int input_sample_rate_hz,
65 int output_sample_rate_hz,
66 int reverse_sample_rate_hz,
67 webrtc::AudioProcessing::ChannelLayout input_layout,
68 webrtc::AudioProcessing::ChannelLayout output_layout,
69 webrtc::AudioProcessing::ChannelLayout reverse_layout));
70 WEBRTC_STUB(Initialize, (
71 const webrtc::ProcessingConfig& processing_config));
72
73 WEBRTC_VOID_FUNC(SetExtraOptions, (const webrtc::Config& config)) {
74 experimental_ns_enabled_ = config.Get<webrtc::ExperimentalNs>().enabled;
75 }
76
77 WEBRTC_STUB_CONST(input_sample_rate_hz, ());
78 WEBRTC_STUB_CONST(proc_sample_rate_hz, ());
79 WEBRTC_STUB_CONST(proc_split_sample_rate_hz, ());
80 size_t num_input_channels() const override { return 0; }
81 size_t num_proc_channels() const override { return 0; }
82 size_t num_output_channels() const override { return 0; }
83 size_t num_reverse_channels() const override { return 0; }
84 WEBRTC_VOID_STUB(set_output_will_be_muted, (bool muted));
85 WEBRTC_STUB(ProcessStream, (webrtc::AudioFrame* frame));
86 WEBRTC_STUB(ProcessStream, (
87 const float* const* src,
88 size_t samples_per_channel,
89 int input_sample_rate_hz,
90 webrtc::AudioProcessing::ChannelLayout input_layout,
91 int output_sample_rate_hz,
92 webrtc::AudioProcessing::ChannelLayout output_layout,
93 float* const* dest));
94 WEBRTC_STUB(ProcessStream,
95 (const float* const* src,
96 const webrtc::StreamConfig& input_config,
97 const webrtc::StreamConfig& output_config,
98 float* const* dest));
99 WEBRTC_STUB(AnalyzeReverseStream, (webrtc::AudioFrame* frame));
100 WEBRTC_STUB(ProcessReverseStream, (webrtc::AudioFrame * frame));
101 WEBRTC_STUB(AnalyzeReverseStream, (
102 const float* const* data,
103 size_t samples_per_channel,
104 int sample_rate_hz,
105 webrtc::AudioProcessing::ChannelLayout layout));
106 WEBRTC_STUB(ProcessReverseStream,
107 (const float* const* src,
108 const webrtc::StreamConfig& reverse_input_config,
109 const webrtc::StreamConfig& reverse_output_config,
110 float* const* dest));
111 WEBRTC_STUB(set_stream_delay_ms, (int delay));
112 WEBRTC_STUB_CONST(stream_delay_ms, ());
113 WEBRTC_BOOL_STUB_CONST(was_stream_delay_set, ());
114 WEBRTC_VOID_STUB(set_stream_key_pressed, (bool key_pressed));
115 WEBRTC_VOID_STUB(set_delay_offset_ms, (int offset));
116 WEBRTC_STUB_CONST(delay_offset_ms, ());
117 WEBRTC_STUB(StartDebugRecording,
118 (const char filename[kMaxFilenameSize], int64_t max_size_bytes));
119 WEBRTC_STUB(StartDebugRecording, (FILE * handle, int64_t max_size_bytes));
120 WEBRTC_STUB(StopDebugRecording, ());
121 WEBRTC_VOID_STUB(UpdateHistogramsOnCallEnd, ());
122 webrtc::EchoCancellation* echo_cancellation() const override { return NULL; }
123 webrtc::EchoControlMobile* echo_control_mobile() const override {
124 return NULL;
125 }
126 webrtc::GainControl* gain_control() const override { return NULL; }
127 webrtc::HighPassFilter* high_pass_filter() const override { return NULL; }
128 webrtc::LevelEstimator* level_estimator() const override { return NULL; }
129 webrtc::NoiseSuppression* noise_suppression() const override { return NULL; }
130 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
131
132 bool experimental_ns_enabled() {
133 return experimental_ns_enabled_;
134 }
135
136 private:
137 bool experimental_ns_enabled_;
138 };
139
140 class FakeWebRtcVoiceEngine
141 : public webrtc::VoEAudioProcessing,
142 public webrtc::VoEBase, public webrtc::VoECodec,
143 public webrtc::VoEHardware,
144 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
145 public webrtc::VoEVolumeControl {
146 public:
147 struct Channel {
148 explicit Channel()
149 : external_transport(false),
150 send(false),
151 playout(false),
152 volume_scale(1.0),
153 vad(false),
154 codec_fec(false),
155 max_encoding_bandwidth(0),
156 opus_dtx(false),
157 red(false),
158 nack(false),
159 cn8_type(13),
160 cn16_type(105),
161 red_type(117),
162 nack_max_packets(0),
163 send_ssrc(0),
164 associate_send_channel(-1),
165 recv_codecs(),
166 neteq_capacity(-1),
167 neteq_fast_accelerate(false) {
168 memset(&send_codec, 0, sizeof(send_codec));
169 }
170 bool external_transport;
171 bool send;
172 bool playout;
173 float volume_scale;
174 bool vad;
175 bool codec_fec;
176 int max_encoding_bandwidth;
177 bool opus_dtx;
178 bool red;
179 bool nack;
180 int cn8_type;
181 int cn16_type;
182 int red_type;
183 int nack_max_packets;
184 uint32_t send_ssrc;
185 int associate_send_channel;
186 std::vector<webrtc::CodecInst> recv_codecs;
187 webrtc::CodecInst send_codec;
188 webrtc::PacketTime last_rtp_packet_time;
189 std::list<std::string> packets;
190 int neteq_capacity;
191 bool neteq_fast_accelerate;
192 };
193
194 FakeWebRtcVoiceEngine()
195 : inited_(false),
196 last_channel_(-1),
197 fail_create_channel_(false),
198 num_set_send_codecs_(0),
199 ec_enabled_(false),
200 ec_metrics_enabled_(false),
201 cng_enabled_(false),
202 ns_enabled_(false),
203 agc_enabled_(false),
204 highpass_filter_enabled_(false),
205 stereo_swapping_enabled_(false),
206 typing_detection_enabled_(false),
207 ec_mode_(webrtc::kEcDefault),
208 aecm_mode_(webrtc::kAecmSpeakerphone),
209 ns_mode_(webrtc::kNsDefault),
210 agc_mode_(webrtc::kAgcDefault),
211 observer_(NULL),
212 playout_fail_channel_(-1),
213 send_fail_channel_(-1),
214 recording_sample_rate_(-1),
215 playout_sample_rate_(-1) {
216 memset(&agc_config_, 0, sizeof(agc_config_));
217 }
218 ~FakeWebRtcVoiceEngine() {
219 RTC_CHECK(channels_.empty());
220 }
221
222 bool ec_metrics_enabled() const { return ec_metrics_enabled_; }
223
224 bool IsInited() const { return inited_; }
225 int GetLastChannel() const { return last_channel_; }
226 int GetNumChannels() const { return static_cast<int>(channels_.size()); }
227 uint32_t GetLocalSSRC(int channel) {
228 return channels_[channel]->send_ssrc;
229 }
230 bool GetPlayout(int channel) {
231 return channels_[channel]->playout;
232 }
233 bool GetSend(int channel) {
234 return channels_[channel]->send;
235 }
236 bool GetVAD(int channel) {
237 return channels_[channel]->vad;
238 }
239 bool GetOpusDtx(int channel) {
240 return channels_[channel]->opus_dtx;
241 }
242 bool GetRED(int channel) {
243 return channels_[channel]->red;
244 }
245 bool GetCodecFEC(int channel) {
246 return channels_[channel]->codec_fec;
247 }
248 int GetMaxEncodingBandwidth(int channel) {
249 return channels_[channel]->max_encoding_bandwidth;
250 }
251 bool GetNACK(int channel) {
252 return channels_[channel]->nack;
253 }
254 int GetNACKMaxPackets(int channel) {
255 return channels_[channel]->nack_max_packets;
256 }
257 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) {
258 RTC_DCHECK(channels_.find(channel) != channels_.end());
259 return channels_[channel]->last_rtp_packet_time;
260 }
261 int GetSendCNPayloadType(int channel, bool wideband) {
262 return (wideband) ?
263 channels_[channel]->cn16_type :
264 channels_[channel]->cn8_type;
265 }
266 int GetSendREDPayloadType(int channel) {
267 return channels_[channel]->red_type;
268 }
269 bool CheckPacket(int channel, const void* data, size_t len) {
270 bool result = !CheckNoPacket(channel);
271 if (result) {
272 std::string packet = channels_[channel]->packets.front();
273 result = (packet == std::string(static_cast<const char*>(data), len));
274 channels_[channel]->packets.pop_front();
275 }
276 return result;
277 }
278 bool CheckNoPacket(int channel) {
279 return channels_[channel]->packets.empty();
280 }
281 void TriggerCallbackOnError(int channel_num, int err_code) {
282 RTC_DCHECK(observer_ != NULL);
283 observer_->CallbackOnError(channel_num, err_code);
284 }
285 void set_playout_fail_channel(int channel) {
286 playout_fail_channel_ = channel;
287 }
288 void set_send_fail_channel(int channel) {
289 send_fail_channel_ = channel;
290 }
291 void set_fail_create_channel(bool fail_create_channel) {
292 fail_create_channel_ = fail_create_channel;
293 }
294 int AddChannel(const webrtc::Config& config) {
295 if (fail_create_channel_) {
296 return -1;
297 }
298 Channel* ch = new Channel();
299 auto db = webrtc::acm2::RentACodec::Database();
300 ch->recv_codecs.assign(db.begin(), db.end());
301 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) {
302 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity;
303 }
304 ch->neteq_fast_accelerate =
305 config.Get<webrtc::NetEqFastAccelerate>().enabled;
306 channels_[++last_channel_] = ch;
307 return last_channel_;
308 }
309
310 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
311
312 int GetAssociateSendChannel(int channel) {
313 return channels_[channel]->associate_send_channel;
314 }
315
316 WEBRTC_STUB(Release, ());
317
318 // webrtc::VoEBase
319 WEBRTC_FUNC(RegisterVoiceEngineObserver, (
320 webrtc::VoiceEngineObserver& observer)) {
321 observer_ = &observer;
322 return 0;
323 }
324 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
325 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
326 webrtc::AudioProcessing* audioproc)) {
327 inited_ = true;
328 return 0;
329 }
330 WEBRTC_FUNC(Terminate, ()) {
331 inited_ = false;
332 return 0;
333 }
334 webrtc::AudioProcessing* audio_processing() override {
335 return &audio_processing_;
336 }
337 WEBRTC_FUNC(CreateChannel, ()) {
338 webrtc::Config empty_config;
339 return AddChannel(empty_config);
340 }
341 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
342 return AddChannel(config);
343 }
344 WEBRTC_FUNC(DeleteChannel, (int channel)) {
345 WEBRTC_CHECK_CHANNEL(channel);
346 for (const auto& ch : channels_) {
347 if (ch.second->associate_send_channel == channel) {
348 ch.second->associate_send_channel = -1;
349 }
350 }
351 delete channels_[channel];
352 channels_.erase(channel);
353 return 0;
354 }
355 WEBRTC_STUB(StartReceive, (int channel));
356 WEBRTC_FUNC(StartPlayout, (int channel)) {
357 if (playout_fail_channel_ != channel) {
358 WEBRTC_CHECK_CHANNEL(channel);
359 channels_[channel]->playout = true;
360 return 0;
361 } else {
362 // When playout_fail_channel_ == channel, fail the StartPlayout on this
363 // channel.
364 return -1;
365 }
366 }
367 WEBRTC_FUNC(StartSend, (int channel)) {
368 if (send_fail_channel_ != channel) {
369 WEBRTC_CHECK_CHANNEL(channel);
370 channels_[channel]->send = true;
371 return 0;
372 } else {
373 // When send_fail_channel_ == channel, fail the StartSend on this
374 // channel.
375 return -1;
376 }
377 }
378 WEBRTC_STUB(StopReceive, (int channel));
379 WEBRTC_FUNC(StopPlayout, (int channel)) {
380 WEBRTC_CHECK_CHANNEL(channel);
381 channels_[channel]->playout = false;
382 return 0;
383 }
384 WEBRTC_FUNC(StopSend, (int channel)) {
385 WEBRTC_CHECK_CHANNEL(channel);
386 channels_[channel]->send = false;
387 return 0;
388 }
389 WEBRTC_STUB(GetVersion, (char version[1024]));
390 WEBRTC_STUB(LastError, ());
391 WEBRTC_FUNC(AssociateSendChannel, (int channel,
392 int accociate_send_channel)) {
393 WEBRTC_CHECK_CHANNEL(channel);
394 channels_[channel]->associate_send_channel = accociate_send_channel;
395 return 0;
396 }
397 webrtc::RtcEventLog* GetEventLog() { return nullptr; }
398
399 // webrtc::VoECodec
400 WEBRTC_STUB(NumOfCodecs, ());
401 WEBRTC_STUB(GetCodec, (int index, webrtc::CodecInst& codec));
402 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) {
403 WEBRTC_CHECK_CHANNEL(channel);
404 // To match the behavior of the real implementation.
405 if (_stricmp(codec.plname, "telephone-event") == 0 ||
406 _stricmp(codec.plname, "audio/telephone-event") == 0 ||
407 _stricmp(codec.plname, "CN") == 0 ||
408 _stricmp(codec.plname, "red") == 0 ) {
409 return -1;
410 }
411 channels_[channel]->send_codec = codec;
412 ++num_set_send_codecs_;
413 return 0;
414 }
415 WEBRTC_FUNC(GetSendCodec, (int channel, webrtc::CodecInst& codec)) {
416 WEBRTC_CHECK_CHANNEL(channel);
417 codec = channels_[channel]->send_codec;
418 return 0;
419 }
420 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps));
421 WEBRTC_STUB(GetRecCodec, (int channel, webrtc::CodecInst& codec));
422 WEBRTC_FUNC(SetRecPayloadType, (int channel,
423 const webrtc::CodecInst& codec)) {
424 WEBRTC_CHECK_CHANNEL(channel);
425 Channel* ch = channels_[channel];
426 if (ch->playout)
427 return -1; // Channel is in use.
428 // Check if something else already has this slot.
429 if (codec.pltype != -1) {
430 for (std::vector<webrtc::CodecInst>::iterator it =
431 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) {
432 if (it->pltype == codec.pltype &&
433 _stricmp(it->plname, codec.plname) != 0) {
434 return -1;
435 }
436 }
437 }
438 // Otherwise try to find this codec and update its payload type.
439 int result = -1; // not found
440 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
441 it != ch->recv_codecs.end(); ++it) {
442 if (strcmp(it->plname, codec.plname) == 0 &&
443 it->plfreq == codec.plfreq &&
444 it->channels == codec.channels) {
445 it->pltype = codec.pltype;
446 result = 0;
447 }
448 }
449 return result;
450 }
451 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type,
452 webrtc::PayloadFrequencies frequency)) {
453 WEBRTC_CHECK_CHANNEL(channel);
454 if (frequency == webrtc::kFreq8000Hz) {
455 channels_[channel]->cn8_type = type;
456 } else if (frequency == webrtc::kFreq16000Hz) {
457 channels_[channel]->cn16_type = type;
458 }
459 return 0;
460 }
461 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) {
462 WEBRTC_CHECK_CHANNEL(channel);
463 Channel* ch = channels_[channel];
464 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin();
465 it != ch->recv_codecs.end(); ++it) {
466 if (strcmp(it->plname, codec.plname) == 0 &&
467 it->plfreq == codec.plfreq &&
468 it->channels == codec.channels &&
469 it->pltype != -1) {
470 codec.pltype = it->pltype;
471 return 0;
472 }
473 }
474 return -1; // not found
475 }
476 WEBRTC_FUNC(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode,
477 bool disableDTX)) {
478 WEBRTC_CHECK_CHANNEL(channel);
479 if (channels_[channel]->send_codec.channels == 2) {
480 // Replicating VoE behavior; VAD cannot be enabled for stereo.
481 return -1;
482 }
483 channels_[channel]->vad = enable;
484 return 0;
485 }
486 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled,
487 webrtc::VadModes& mode, bool& disabledDTX));
488
489 WEBRTC_FUNC(SetFECStatus, (int channel, bool enable)) {
490 WEBRTC_CHECK_CHANNEL(channel);
491 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
492 // Return -1 if current send codec is not Opus.
493 // TODO(minyue): Excludes other codecs if they support inband FEC.
494 return -1;
495 }
496 channels_[channel]->codec_fec = enable;
497 return 0;
498 }
499 WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable)) {
500 WEBRTC_CHECK_CHANNEL(channel);
501 enable = channels_[channel]->codec_fec;
502 return 0;
503 }
504
505 WEBRTC_FUNC(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)) {
506 WEBRTC_CHECK_CHANNEL(channel);
507 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
508 // Return -1 if current send codec is not Opus.
509 return -1;
510 }
511 if (frequency_hz <= 8000)
512 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthNb;
513 else if (frequency_hz <= 12000)
514 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthMb;
515 else if (frequency_hz <= 16000)
516 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthWb;
517 else if (frequency_hz <= 24000)
518 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthSwb;
519 else
520 channels_[channel]->max_encoding_bandwidth = kOpusBandwidthFb;
521 return 0;
522 }
523
524 WEBRTC_FUNC(SetOpusDtx, (int channel, bool enable_dtx)) {
525 WEBRTC_CHECK_CHANNEL(channel);
526 if (_stricmp(channels_[channel]->send_codec.plname, "opus") != 0) {
527 // Return -1 if current send codec is not Opus.
528 return -1;
529 }
530 channels_[channel]->opus_dtx = enable_dtx;
531 return 0;
532 }
533
534 // webrtc::VoEHardware
535 WEBRTC_STUB(GetNumOfRecordingDevices, (int& num));
536 WEBRTC_STUB(GetNumOfPlayoutDevices, (int& num));
537 WEBRTC_STUB(GetRecordingDeviceName, (int i, char* name, char* guid));
538 WEBRTC_STUB(GetPlayoutDeviceName, (int i, char* name, char* guid));
539 WEBRTC_STUB(SetRecordingDevice, (int, webrtc::StereoChannel));
540 WEBRTC_STUB(SetPlayoutDevice, (int));
541 WEBRTC_STUB(SetAudioDeviceLayer, (webrtc::AudioLayers));
542 WEBRTC_STUB(GetAudioDeviceLayer, (webrtc::AudioLayers&));
543 WEBRTC_FUNC(SetRecordingSampleRate, (unsigned int samples_per_sec)) {
544 recording_sample_rate_ = samples_per_sec;
545 return 0;
546 }
547 WEBRTC_FUNC_CONST(RecordingSampleRate, (unsigned int* samples_per_sec)) {
548 *samples_per_sec = recording_sample_rate_;
549 return 0;
550 }
551 WEBRTC_FUNC(SetPlayoutSampleRate, (unsigned int samples_per_sec)) {
552 playout_sample_rate_ = samples_per_sec;
553 return 0;
554 }
555 WEBRTC_FUNC_CONST(PlayoutSampleRate, (unsigned int* samples_per_sec)) {
556 *samples_per_sec = playout_sample_rate_;
557 return 0;
558 }
559 WEBRTC_STUB(EnableBuiltInAEC, (bool enable));
560 virtual bool BuiltInAECIsAvailable() const { return false; }
561 WEBRTC_STUB(EnableBuiltInAGC, (bool enable));
562 virtual bool BuiltInAGCIsAvailable() const { return false; }
563 WEBRTC_STUB(EnableBuiltInNS, (bool enable));
564 virtual bool BuiltInNSIsAvailable() const { return false; }
565
566 // webrtc::VoENetwork
567 WEBRTC_FUNC(RegisterExternalTransport, (int channel,
568 webrtc::Transport& transport)) {
569 WEBRTC_CHECK_CHANNEL(channel);
570 channels_[channel]->external_transport = true;
571 return 0;
572 }
573 WEBRTC_FUNC(DeRegisterExternalTransport, (int channel)) {
574 WEBRTC_CHECK_CHANNEL(channel);
575 channels_[channel]->external_transport = false;
576 return 0;
577 }
578 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
579 size_t length)) {
580 WEBRTC_CHECK_CHANNEL(channel);
581 if (!channels_[channel]->external_transport) return -1;
582 channels_[channel]->packets.push_back(
583 std::string(static_cast<const char*>(data), length));
584 return 0;
585 }
586 WEBRTC_FUNC(ReceivedRTPPacket, (int channel, const void* data,
587 size_t length,
588 const webrtc::PacketTime& packet_time)) {
589 WEBRTC_CHECK_CHANNEL(channel);
590 if (ReceivedRTPPacket(channel, data, length) == -1) {
591 return -1;
592 }
593 channels_[channel]->last_rtp_packet_time = packet_time;
594 return 0;
595 }
596
597 WEBRTC_STUB(ReceivedRTCPPacket, (int channel, const void* data,
598 size_t length));
599
600 // webrtc::VoERTP_RTCP
601 WEBRTC_FUNC(SetLocalSSRC, (int channel, unsigned int ssrc)) {
602 WEBRTC_CHECK_CHANNEL(channel);
603 channels_[channel]->send_ssrc = ssrc;
604 return 0;
605 }
606 WEBRTC_STUB(GetLocalSSRC, (int channel, unsigned int& ssrc));
607 WEBRTC_STUB(GetRemoteSSRC, (int channel, unsigned int& ssrc));
608 WEBRTC_STUB(SetSendAudioLevelIndicationStatus, (int channel, bool enable,
609 unsigned char id));
610 WEBRTC_STUB(SetReceiveAudioLevelIndicationStatus, (int channel, bool enable,
611 unsigned char id));
612 WEBRTC_STUB(SetSendAbsoluteSenderTimeStatus, (int channel, bool enable,
613 unsigned char id));
614 WEBRTC_STUB(SetReceiveAbsoluteSenderTimeStatus, (int channel, bool enable,
615 unsigned char id));
616 WEBRTC_STUB(SetRTCPStatus, (int channel, bool enable));
617 WEBRTC_STUB(GetRTCPStatus, (int channel, bool& enabled));
618 WEBRTC_STUB(SetRTCP_CNAME, (int channel, const char cname[256]));
619 WEBRTC_STUB(GetRTCP_CNAME, (int channel, char cname[256]));
620 WEBRTC_STUB(GetRemoteRTCP_CNAME, (int channel, char* cname));
621 WEBRTC_STUB(GetRemoteRTCPData, (int channel, unsigned int& NTPHigh,
622 unsigned int& NTPLow,
623 unsigned int& timestamp,
624 unsigned int& playoutTimestamp,
625 unsigned int* jitter,
626 unsigned short* fractionLost));
627 WEBRTC_STUB(GetRemoteRTCPReportBlocks,
628 (int channel, std::vector<webrtc::ReportBlock>* receive_blocks));
629 WEBRTC_STUB(GetRTPStatistics, (int channel, unsigned int& averageJitterMs,
630 unsigned int& maxJitterMs,
631 unsigned int& discardedPackets));
632 WEBRTC_STUB(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats));
633 WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) {
634 WEBRTC_CHECK_CHANNEL(channel);
635 channels_[channel]->red = enable;
636 channels_[channel]->red_type = redPayloadtype;
637 return 0;
638 }
639 WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) {
640 WEBRTC_CHECK_CHANNEL(channel);
641 enable = channels_[channel]->red;
642 redPayloadtype = channels_[channel]->red_type;
643 return 0;
644 }
645 WEBRTC_FUNC(SetNACKStatus, (int channel, bool enable, int maxNoPackets)) {
646 WEBRTC_CHECK_CHANNEL(channel);
647 channels_[channel]->nack = enable;
648 channels_[channel]->nack_max_packets = maxNoPackets;
649 return 0;
650 }
651
652 // webrtc::VoEVolumeControl
653 WEBRTC_STUB(SetSpeakerVolume, (unsigned int));
654 WEBRTC_STUB(GetSpeakerVolume, (unsigned int&));
655 WEBRTC_STUB(SetMicVolume, (unsigned int));
656 WEBRTC_STUB(GetMicVolume, (unsigned int&));
657 WEBRTC_STUB(SetInputMute, (int, bool));
658 WEBRTC_STUB(GetInputMute, (int, bool&));
659 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&));
660 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&));
661 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&));
662 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&));
663 WEBRTC_FUNC(SetChannelOutputVolumeScaling, (int channel, float scale)) {
664 WEBRTC_CHECK_CHANNEL(channel);
665 channels_[channel]->volume_scale= scale;
666 return 0;
667 }
668 WEBRTC_FUNC(GetChannelOutputVolumeScaling, (int channel, float& scale)) {
669 WEBRTC_CHECK_CHANNEL(channel);
670 scale = channels_[channel]->volume_scale;
671 return 0;
672 }
673 WEBRTC_STUB(SetOutputVolumePan, (int channel, float left, float right));
674 WEBRTC_STUB(GetOutputVolumePan, (int channel, float& left, float& right));
675
676 // webrtc::VoEAudioProcessing
677 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) {
678 ns_enabled_ = enable;
679 ns_mode_ = mode;
680 return 0;
681 }
682 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) {
683 enabled = ns_enabled_;
684 mode = ns_mode_;
685 return 0;
686 }
687
688 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) {
689 agc_enabled_ = enable;
690 agc_mode_ = mode;
691 return 0;
692 }
693 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) {
694 enabled = agc_enabled_;
695 mode = agc_mode_;
696 return 0;
697 }
698
699 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) {
700 agc_config_ = config;
701 return 0;
702 }
703 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) {
704 config = agc_config_;
705 return 0;
706 }
707 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) {
708 ec_enabled_ = enable;
709 ec_mode_ = mode;
710 return 0;
711 }
712 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) {
713 enabled = ec_enabled_;
714 mode = ec_mode_;
715 return 0;
716 }
717 WEBRTC_STUB(EnableDriftCompensation, (bool enable))
718 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ())
719 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset))
720 WEBRTC_STUB(DelayOffsetMs, ());
721 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) {
722 aecm_mode_ = mode;
723 cng_enabled_ = enableCNG;
724 return 0;
725 }
726 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) {
727 mode = aecm_mode_;
728 enabledCNG = cng_enabled_;
729 return 0;
730 }
731 WEBRTC_STUB(SetRxNsStatus, (int channel, bool enable, webrtc::NsModes mode));
732 WEBRTC_STUB(GetRxNsStatus, (int channel, bool& enabled,
733 webrtc::NsModes& mode));
734 WEBRTC_STUB(SetRxAgcStatus, (int channel, bool enable,
735 webrtc::AgcModes mode));
736 WEBRTC_STUB(GetRxAgcStatus, (int channel, bool& enabled,
737 webrtc::AgcModes& mode));
738 WEBRTC_STUB(SetRxAgcConfig, (int channel, webrtc::AgcConfig config));
739 WEBRTC_STUB(GetRxAgcConfig, (int channel, webrtc::AgcConfig& config));
740
741 WEBRTC_STUB(RegisterRxVadObserver, (int, webrtc::VoERxVadCallback&));
742 WEBRTC_STUB(DeRegisterRxVadObserver, (int channel));
743 WEBRTC_STUB(VoiceActivityIndicator, (int channel));
744 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) {
745 ec_metrics_enabled_ = enable;
746 return 0;
747 }
748 WEBRTC_STUB(GetEcMetricsStatus, (bool& enabled));
749 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP));
750 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std,
751 float& fraction_poor_delays));
752
753 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8));
754 WEBRTC_STUB(StartDebugRecording, (FILE* handle));
755 WEBRTC_STUB(StopDebugRecording, ());
756
757 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) {
758 typing_detection_enabled_ = enable;
759 return 0;
760 }
761 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) {
762 enabled = typing_detection_enabled_;
763 return 0;
764 }
765
766 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds));
767 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow,
768 int costPerTyping,
769 int reportingThreshold,
770 int penaltyDecay,
771 int typeEventDelay));
772 int EnableHighPassFilter(bool enable) {
773 highpass_filter_enabled_ = enable;
774 return 0;
775 }
776 bool IsHighPassFilterEnabled() {
777 return highpass_filter_enabled_;
778 }
779 bool IsStereoChannelSwappingEnabled() {
780 return stereo_swapping_enabled_;
781 }
782 void EnableStereoChannelSwapping(bool enable) {
783 stereo_swapping_enabled_ = enable;
784 }
785 int GetNetEqCapacity() const {
786 auto ch = channels_.find(last_channel_);
787 ASSERT(ch != channels_.end());
788 return ch->second->neteq_capacity;
789 }
790 bool GetNetEqFastAccelerate() const {
791 auto ch = channels_.find(last_channel_);
792 ASSERT(ch != channels_.end());
793 return ch->second->neteq_fast_accelerate;
794 }
795
796 private:
797 bool inited_;
798 int last_channel_;
799 std::map<int, Channel*> channels_;
800 bool fail_create_channel_;
801 int num_set_send_codecs_; // how many times we call SetSendCodec().
802 bool ec_enabled_;
803 bool ec_metrics_enabled_;
804 bool cng_enabled_;
805 bool ns_enabled_;
806 bool agc_enabled_;
807 bool highpass_filter_enabled_;
808 bool stereo_swapping_enabled_;
809 bool typing_detection_enabled_;
810 webrtc::EcModes ec_mode_;
811 webrtc::AecmModes aecm_mode_;
812 webrtc::NsModes ns_mode_;
813 webrtc::AgcModes agc_mode_;
814 webrtc::AgcConfig agc_config_;
815 webrtc::VoiceEngineObserver* observer_;
816 int playout_fail_channel_;
817 int send_fail_channel_;
818 int recording_sample_rate_;
819 int playout_sample_rate_;
820 FakeAudioProcessing audio_processing_;
821 };
822
823 } // namespace cricket
824
825 #endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_
OLDNEW
« no previous file with comments | « talk/media/webrtc/fakewebrtcvideoengine.h ('k') | talk/media/webrtc/nullwebrtcvideoengine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698