OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ | 11 #ifndef WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ |
12 #define WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ | 12 #define WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ |
13 | 13 |
14 #include <stddef.h> | 14 #include <stddef.h> |
15 | 15 |
16 #include <list> | 16 #include <list> |
17 #include <map> | 17 #include <map> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/stringutils.h" | 21 #include "webrtc/base/stringutils.h" |
22 #include "webrtc/base/checks.h" | 22 #include "webrtc/base/checks.h" |
23 #include "webrtc/config.h" | 23 #include "webrtc/config.h" |
24 #include "webrtc/media/base/codec.h" | 24 #include "webrtc/media/base/codec.h" |
25 #include "webrtc/media/base/rtputils.h" | 25 #include "webrtc/media/base/rtputils.h" |
26 #include "webrtc/media/engine/webrtcvoe.h" | 26 #include "webrtc/media/engine/webrtcvoe.h" |
27 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | 27 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" |
28 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 28 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
29 | 29 |
| 30 namespace webrtc { |
| 31 namespace voe { |
| 32 class TransmitMixer; |
| 33 } // namespace voe |
| 34 } // namespace webrtc |
| 35 |
30 namespace cricket { | 36 namespace cricket { |
31 | 37 |
32 static const int kOpusBandwidthNb = 4000; | 38 static const int kOpusBandwidthNb = 4000; |
33 static const int kOpusBandwidthMb = 6000; | 39 static const int kOpusBandwidthMb = 6000; |
34 static const int kOpusBandwidthWb = 8000; | 40 static const int kOpusBandwidthWb = 8000; |
35 static const int kOpusBandwidthSwb = 12000; | 41 static const int kOpusBandwidthSwb = 12000; |
36 static const int kOpusBandwidthFb = 20000; | 42 static const int kOpusBandwidthFb = 20000; |
37 | 43 |
38 #define WEBRTC_CHECK_CHANNEL(channel) \ | 44 #define WEBRTC_CHECK_CHANNEL(channel) \ |
39 if (channels_.find(channel) == channels_.end()) return -1; | 45 if (channels_.find(channel) == channels_.end()) return -1; |
40 | 46 |
41 #define WEBRTC_STUB(method, args) \ | 47 #define WEBRTC_STUB(method, args) \ |
42 int method args override { return 0; } | 48 int method args override { return 0; } |
43 | 49 |
44 #define WEBRTC_STUB_CONST(method, args) \ | 50 #define WEBRTC_STUB_CONST(method, args) \ |
45 int method args const override { return 0; } | 51 int method args const override { return 0; } |
46 | 52 |
47 #define WEBRTC_BOOL_STUB(method, args) \ | 53 #define WEBRTC_BOOL_STUB(method, args) \ |
48 bool method args override { return true; } | 54 bool method args override { return true; } |
49 | 55 |
50 #define WEBRTC_VOID_STUB(method, args) \ | 56 #define WEBRTC_VOID_STUB(method, args) \ |
51 void method args override {} | 57 void method args override {} |
52 | 58 |
53 #define WEBRTC_FUNC(method, args) int method args override | 59 #define WEBRTC_FUNC(method, args) int method args override |
54 | 60 |
55 class FakeWebRtcVoiceEngine | 61 class FakeWebRtcVoiceEngine |
56 : public webrtc::VoEAudioProcessing, | 62 : public webrtc::VoEBase, public webrtc::VoECodec, |
57 public webrtc::VoEBase, public webrtc::VoECodec, | |
58 public webrtc::VoEHardware, | 63 public webrtc::VoEHardware, |
59 public webrtc::VoEVolumeControl { | 64 public webrtc::VoEVolumeControl { |
60 public: | 65 public: |
61 struct Channel { | 66 struct Channel { |
62 std::vector<webrtc::CodecInst> recv_codecs; | 67 std::vector<webrtc::CodecInst> recv_codecs; |
63 size_t neteq_capacity = 0; | 68 size_t neteq_capacity = 0; |
64 bool neteq_fast_accelerate = false; | 69 bool neteq_fast_accelerate = false; |
65 }; | 70 }; |
66 | 71 |
67 explicit FakeWebRtcVoiceEngine(webrtc::AudioProcessing* apm) : apm_(apm) { | 72 explicit FakeWebRtcVoiceEngine(webrtc::AudioProcessing* apm, |
68 memset(&agc_config_, 0, sizeof(agc_config_)); | 73 webrtc::voe::TransmitMixer* transmit_mixer) |
| 74 : apm_(apm), transmit_mixer_(transmit_mixer) { |
69 } | 75 } |
70 ~FakeWebRtcVoiceEngine() override { | 76 ~FakeWebRtcVoiceEngine() override { |
71 RTC_CHECK(channels_.empty()); | 77 RTC_CHECK(channels_.empty()); |
72 } | 78 } |
73 | 79 |
74 bool ec_metrics_enabled() const { return ec_metrics_enabled_; } | |
75 | |
76 bool IsInited() const { return inited_; } | 80 bool IsInited() const { return inited_; } |
77 int GetLastChannel() const { return last_channel_; } | 81 int GetLastChannel() const { return last_channel_; } |
78 int GetNumChannels() const { return static_cast<int>(channels_.size()); } | 82 int GetNumChannels() const { return static_cast<int>(channels_.size()); } |
79 void set_fail_create_channel(bool fail_create_channel) { | 83 void set_fail_create_channel(bool fail_create_channel) { |
80 fail_create_channel_ = fail_create_channel; | 84 fail_create_channel_ = fail_create_channel; |
81 } | 85 } |
82 | 86 |
83 WEBRTC_STUB(Release, ()); | 87 WEBRTC_STUB(Release, ()); |
84 | 88 |
85 // webrtc::VoEBase | 89 // webrtc::VoEBase |
(...skipping 11 matching lines...) Expand all Loading... |
97 WEBRTC_FUNC(Terminate, ()) { | 101 WEBRTC_FUNC(Terminate, ()) { |
98 inited_ = false; | 102 inited_ = false; |
99 return 0; | 103 return 0; |
100 } | 104 } |
101 webrtc::AudioProcessing* audio_processing() override { | 105 webrtc::AudioProcessing* audio_processing() override { |
102 return apm_; | 106 return apm_; |
103 } | 107 } |
104 webrtc::AudioDeviceModule* audio_device_module() override { | 108 webrtc::AudioDeviceModule* audio_device_module() override { |
105 return nullptr; | 109 return nullptr; |
106 } | 110 } |
| 111 webrtc::voe::TransmitMixer* transmit_mixer() override { |
| 112 return transmit_mixer_; |
| 113 } |
107 WEBRTC_FUNC(CreateChannel, ()) { | 114 WEBRTC_FUNC(CreateChannel, ()) { |
108 return CreateChannel(webrtc::VoEBase::ChannelConfig()); | 115 return CreateChannel(webrtc::VoEBase::ChannelConfig()); |
109 } | 116 } |
110 WEBRTC_FUNC(CreateChannel, (const webrtc::VoEBase::ChannelConfig& config)) { | 117 WEBRTC_FUNC(CreateChannel, (const webrtc::VoEBase::ChannelConfig& config)) { |
111 if (fail_create_channel_) { | 118 if (fail_create_channel_) { |
112 return -1; | 119 return -1; |
113 } | 120 } |
114 Channel* ch = new Channel(); | 121 Channel* ch = new Channel(); |
115 auto db = webrtc::acm2::RentACodec::Database(); | 122 auto db = webrtc::acm2::RentACodec::Database(); |
116 ch->recv_codecs.assign(db.begin(), db.end()); | 123 ch->recv_codecs.assign(db.begin(), db.end()); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 WEBRTC_STUB(GetInputMute, (int, bool&)); | 233 WEBRTC_STUB(GetInputMute, (int, bool&)); |
227 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&)); | 234 WEBRTC_STUB(GetSpeechInputLevel, (unsigned int&)); |
228 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&)); | 235 WEBRTC_STUB(GetSpeechOutputLevel, (int, unsigned int&)); |
229 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&)); | 236 WEBRTC_STUB(GetSpeechInputLevelFullRange, (unsigned int&)); |
230 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&)); | 237 WEBRTC_STUB(GetSpeechOutputLevelFullRange, (int, unsigned int&)); |
231 WEBRTC_STUB(SetChannelOutputVolumeScaling, (int channel, float scale)); | 238 WEBRTC_STUB(SetChannelOutputVolumeScaling, (int channel, float scale)); |
232 WEBRTC_STUB(GetChannelOutputVolumeScaling, (int channel, float& scale)); | 239 WEBRTC_STUB(GetChannelOutputVolumeScaling, (int channel, float& scale)); |
233 WEBRTC_STUB(SetOutputVolumePan, (int channel, float left, float right)); | 240 WEBRTC_STUB(SetOutputVolumePan, (int channel, float left, float right)); |
234 WEBRTC_STUB(GetOutputVolumePan, (int channel, float& left, float& right)); | 241 WEBRTC_STUB(GetOutputVolumePan, (int channel, float& left, float& right)); |
235 | 242 |
236 // webrtc::VoEAudioProcessing | |
237 WEBRTC_FUNC(SetNsStatus, (bool enable, webrtc::NsModes mode)) { | |
238 ns_enabled_ = enable; | |
239 ns_mode_ = mode; | |
240 return 0; | |
241 } | |
242 WEBRTC_FUNC(GetNsStatus, (bool& enabled, webrtc::NsModes& mode)) { | |
243 enabled = ns_enabled_; | |
244 mode = ns_mode_; | |
245 return 0; | |
246 } | |
247 WEBRTC_FUNC(SetAgcStatus, (bool enable, webrtc::AgcModes mode)) { | |
248 agc_enabled_ = enable; | |
249 agc_mode_ = mode; | |
250 return 0; | |
251 } | |
252 WEBRTC_FUNC(GetAgcStatus, (bool& enabled, webrtc::AgcModes& mode)) { | |
253 enabled = agc_enabled_; | |
254 mode = agc_mode_; | |
255 return 0; | |
256 } | |
257 WEBRTC_FUNC(SetAgcConfig, (webrtc::AgcConfig config)) { | |
258 agc_config_ = config; | |
259 return 0; | |
260 } | |
261 WEBRTC_FUNC(GetAgcConfig, (webrtc::AgcConfig& config)) { | |
262 config = agc_config_; | |
263 return 0; | |
264 } | |
265 WEBRTC_FUNC(SetEcStatus, (bool enable, webrtc::EcModes mode)) { | |
266 ec_enabled_ = enable; | |
267 ec_mode_ = mode; | |
268 return 0; | |
269 } | |
270 WEBRTC_FUNC(GetEcStatus, (bool& enabled, webrtc::EcModes& mode)) { | |
271 enabled = ec_enabled_; | |
272 mode = ec_mode_; | |
273 return 0; | |
274 } | |
275 WEBRTC_STUB(EnableDriftCompensation, (bool enable)) | |
276 WEBRTC_BOOL_STUB(DriftCompensationEnabled, ()) | |
277 WEBRTC_VOID_STUB(SetDelayOffsetMs, (int offset)) | |
278 WEBRTC_STUB(DelayOffsetMs, ()); | |
279 WEBRTC_FUNC(SetAecmMode, (webrtc::AecmModes mode, bool enableCNG)) { | |
280 aecm_mode_ = mode; | |
281 cng_enabled_ = enableCNG; | |
282 return 0; | |
283 } | |
284 WEBRTC_FUNC(GetAecmMode, (webrtc::AecmModes& mode, bool& enabledCNG)) { | |
285 mode = aecm_mode_; | |
286 enabledCNG = cng_enabled_; | |
287 return 0; | |
288 } | |
289 WEBRTC_STUB(VoiceActivityIndicator, (int channel)); | |
290 WEBRTC_FUNC(SetEcMetricsStatus, (bool enable)) { | |
291 ec_metrics_enabled_ = enable; | |
292 return 0; | |
293 } | |
294 WEBRTC_STUB(GetEcMetricsStatus, (bool& enabled)); | |
295 WEBRTC_STUB(GetEchoMetrics, (int& ERL, int& ERLE, int& RERL, int& A_NLP)); | |
296 WEBRTC_STUB(GetEcDelayMetrics, (int& delay_median, int& delay_std, | |
297 float& fraction_poor_delays)); | |
298 WEBRTC_STUB(StartDebugRecording, (const char* fileNameUTF8)); | |
299 WEBRTC_STUB(StartDebugRecording, (FILE* handle)); | |
300 WEBRTC_STUB(StopDebugRecording, ()); | |
301 WEBRTC_FUNC(SetTypingDetectionStatus, (bool enable)) { | |
302 typing_detection_enabled_ = enable; | |
303 return 0; | |
304 } | |
305 WEBRTC_FUNC(GetTypingDetectionStatus, (bool& enabled)) { | |
306 enabled = typing_detection_enabled_; | |
307 return 0; | |
308 } | |
309 WEBRTC_STUB(TimeSinceLastTyping, (int& seconds)); | |
310 WEBRTC_STUB(SetTypingDetectionParameters, (int timeWindow, | |
311 int costPerTyping, | |
312 int reportingThreshold, | |
313 int penaltyDecay, | |
314 int typeEventDelay)); | |
315 int EnableHighPassFilter(bool enable) override { | |
316 highpass_filter_enabled_ = enable; | |
317 return 0; | |
318 } | |
319 bool IsHighPassFilterEnabled() override { | |
320 return highpass_filter_enabled_; | |
321 } | |
322 bool IsStereoChannelSwappingEnabled() override { | |
323 return stereo_swapping_enabled_; | |
324 } | |
325 void EnableStereoChannelSwapping(bool enable) override { | |
326 stereo_swapping_enabled_ = enable; | |
327 } | |
328 size_t GetNetEqCapacity() const { | 243 size_t GetNetEqCapacity() const { |
329 auto ch = channels_.find(last_channel_); | 244 auto ch = channels_.find(last_channel_); |
330 RTC_DCHECK(ch != channels_.end()); | 245 RTC_DCHECK(ch != channels_.end()); |
331 return ch->second->neteq_capacity; | 246 return ch->second->neteq_capacity; |
332 } | 247 } |
333 bool GetNetEqFastAccelerate() const { | 248 bool GetNetEqFastAccelerate() const { |
334 auto ch = channels_.find(last_channel_); | 249 auto ch = channels_.find(last_channel_); |
335 RTC_CHECK(ch != channels_.end()); | 250 RTC_CHECK(ch != channels_.end()); |
336 return ch->second->neteq_fast_accelerate; | 251 return ch->second->neteq_fast_accelerate; |
337 } | 252 } |
338 | 253 |
339 private: | 254 private: |
340 bool inited_ = false; | 255 bool inited_ = false; |
341 int last_channel_ = -1; | 256 int last_channel_ = -1; |
342 std::map<int, Channel*> channels_; | 257 std::map<int, Channel*> channels_; |
343 bool fail_create_channel_ = false; | 258 bool fail_create_channel_ = false; |
344 bool ec_enabled_ = false; | |
345 bool ec_metrics_enabled_ = false; | |
346 bool cng_enabled_ = false; | |
347 bool ns_enabled_ = false; | |
348 bool agc_enabled_ = false; | |
349 bool highpass_filter_enabled_ = false; | |
350 bool stereo_swapping_enabled_ = false; | |
351 bool typing_detection_enabled_ = false; | |
352 webrtc::EcModes ec_mode_ = webrtc::kEcDefault; | |
353 webrtc::AecmModes aecm_mode_ = webrtc::kAecmSpeakerphone; | |
354 webrtc::NsModes ns_mode_ = webrtc::kNsDefault; | |
355 webrtc::AgcModes agc_mode_ = webrtc::kAgcDefault; | |
356 webrtc::AgcConfig agc_config_; | |
357 webrtc::AudioProcessing* apm_ = nullptr; | 259 webrtc::AudioProcessing* apm_ = nullptr; |
| 260 webrtc::voe::TransmitMixer* transmit_mixer_ = nullptr; |
358 | 261 |
359 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FakeWebRtcVoiceEngine); | 262 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FakeWebRtcVoiceEngine); |
360 }; | 263 }; |
361 | 264 |
362 } // namespace cricket | 265 } // namespace cricket |
363 | 266 |
364 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ | 267 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ |
OLD | NEW |