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

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

Issue 1844843003: Add mock AudioDeviceModule. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@wvoe_adm_in_ctor
Patch Set: rebase Created 4 years, 8 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
OLDNEW
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 <list> 14 #include <list>
15 #include <map> 15 #include <map>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/basictypes.h" 18 #include "webrtc/base/basictypes.h"
19 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
20 #include "webrtc/base/gunit.h" 20 #include "webrtc/base/gunit.h"
21 #include "webrtc/base/stringutils.h" 21 #include "webrtc/base/stringutils.h"
22 #include "webrtc/config.h" 22 #include "webrtc/config.h"
23 #include "webrtc/media/base/codec.h" 23 #include "webrtc/media/base/codec.h"
24 #include "webrtc/media/base/rtputils.h" 24 #include "webrtc/media/base/rtputils.h"
25 #include "webrtc/media/engine/fakewebrtccommon.h" 25 #include "webrtc/media/engine/fakewebrtccommon.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_device/include/fake_audio_device.h"
29 #include "webrtc/modules/audio_processing/include/audio_processing.h" 28 #include "webrtc/modules/audio_processing/include/audio_processing.h"
30 29
31 namespace cricket { 30 namespace cricket {
32 31
33 static const int kOpusBandwidthNb = 4000; 32 static const int kOpusBandwidthNb = 4000;
34 static const int kOpusBandwidthMb = 6000; 33 static const int kOpusBandwidthMb = 6000;
35 static const int kOpusBandwidthWb = 8000; 34 static const int kOpusBandwidthWb = 8000;
36 static const int kOpusBandwidthSwb = 12000; 35 static const int kOpusBandwidthSwb = 12000;
37 static const int kOpusBandwidthFb = 20000; 36 static const int kOpusBandwidthFb = 20000;
38 37
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 webrtc::VoiceDetection* voice_detection() const override { return NULL; } 111 webrtc::VoiceDetection* voice_detection() const override { return NULL; }
113 112
114 bool experimental_ns_enabled() { 113 bool experimental_ns_enabled() {
115 return experimental_ns_enabled_; 114 return experimental_ns_enabled_;
116 } 115 }
117 116
118 private: 117 private:
119 bool experimental_ns_enabled_; 118 bool experimental_ns_enabled_;
120 }; 119 };
121 120
122 // TODO(solenberg): Swap this for a proper mock of the ADM.
123 class FakeAudioDeviceModule : public webrtc::FakeAudioDeviceModule {
124 public:
125 ~FakeAudioDeviceModule() override {
126 RTC_DCHECK_EQ(0, ref_count_);
127 }
128 int32_t AddRef() const override {
129 ref_count_++;
130 return ref_count_;
131 }
132 int32_t Release() const override {
133 RTC_DCHECK_LT(0, ref_count_);
134 ref_count_--;
135 return ref_count_;
136 }
137
138 private:
139 mutable int32_t ref_count_ = 0;
140 };
141
142 class FakeWebRtcVoiceEngine 121 class FakeWebRtcVoiceEngine
143 : public webrtc::VoEAudioProcessing, 122 : public webrtc::VoEAudioProcessing,
144 public webrtc::VoEBase, public webrtc::VoECodec, 123 public webrtc::VoEBase, public webrtc::VoECodec,
145 public webrtc::VoEHardware, 124 public webrtc::VoEHardware,
146 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP, 125 public webrtc::VoENetwork, public webrtc::VoERTP_RTCP,
147 public webrtc::VoEVolumeControl { 126 public webrtc::VoEVolumeControl {
148 public: 127 public:
149 struct Channel { 128 struct Channel {
150 explicit Channel() 129 Channel() {
151 : external_transport(false),
152 playout(false),
153 volume_scale(1.0),
154 vad(false),
155 codec_fec(false),
156 max_encoding_bandwidth(0),
157 opus_dtx(false),
158 red(false),
159 nack(false),
160 cn8_type(13),
161 cn16_type(105),
162 red_type(117),
163 nack_max_packets(0),
164 send_ssrc(0),
165 associate_send_channel(-1),
166 recv_codecs(),
167 neteq_capacity(-1),
168 neteq_fast_accelerate(false) {
169 memset(&send_codec, 0, sizeof(send_codec)); 130 memset(&send_codec, 0, sizeof(send_codec));
170 } 131 }
171 bool external_transport; 132 bool external_transport = false;
172 bool playout; 133 bool playout = false;
173 float volume_scale; 134 float volume_scale = 1.0f;
174 bool vad; 135 bool vad = false;
175 bool codec_fec; 136 bool codec_fec = false;
176 int max_encoding_bandwidth; 137 int max_encoding_bandwidth = 0;
177 bool opus_dtx; 138 bool opus_dtx = false;
178 bool red; 139 bool red = false;
179 bool nack; 140 bool nack = false;
180 int cn8_type; 141 int cn8_type = 13;
181 int cn16_type; 142 int cn16_type = 105;
182 int red_type; 143 int red_type = 117;
183 int nack_max_packets; 144 int nack_max_packets = 0;
184 uint32_t send_ssrc; 145 uint32_t send_ssrc = 0;
185 int associate_send_channel; 146 int associate_send_channel = -1;
186 std::vector<webrtc::CodecInst> recv_codecs; 147 std::vector<webrtc::CodecInst> recv_codecs;
187 webrtc::CodecInst send_codec; 148 webrtc::CodecInst send_codec;
188 webrtc::PacketTime last_rtp_packet_time; 149 webrtc::PacketTime last_rtp_packet_time;
189 std::list<std::string> packets; 150 std::list<std::string> packets;
190 int neteq_capacity; 151 int neteq_capacity = -1;
191 bool neteq_fast_accelerate; 152 bool neteq_fast_accelerate = false;
192 }; 153 };
193 154
194 FakeWebRtcVoiceEngine() 155 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 recording_sample_rate_(-1),
214 playout_sample_rate_(-1) {
215 memset(&agc_config_, 0, sizeof(agc_config_)); 156 memset(&agc_config_, 0, sizeof(agc_config_));
216 } 157 }
217 ~FakeWebRtcVoiceEngine() override { 158 ~FakeWebRtcVoiceEngine() override {
218 RTC_CHECK(channels_.empty()); 159 RTC_CHECK(channels_.empty());
219 } 160 }
220 161
221 bool ec_metrics_enabled() const { return ec_metrics_enabled_; } 162 bool ec_metrics_enabled() const { return ec_metrics_enabled_; }
222 163
223 bool IsInited() const { return inited_; } 164 bool IsInited() const { return inited_; }
224 int GetLastChannel() const { return last_channel_; } 165 int GetLastChannel() const { return last_channel_; }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 if (result) { 208 if (result) {
268 std::string packet = channels_[channel]->packets.front(); 209 std::string packet = channels_[channel]->packets.front();
269 result = (packet == std::string(static_cast<const char*>(data), len)); 210 result = (packet == std::string(static_cast<const char*>(data), len));
270 channels_[channel]->packets.pop_front(); 211 channels_[channel]->packets.pop_front();
271 } 212 }
272 return result; 213 return result;
273 } 214 }
274 bool CheckNoPacket(int channel) { 215 bool CheckNoPacket(int channel) {
275 return channels_[channel]->packets.empty(); 216 return channels_[channel]->packets.empty();
276 } 217 }
277 void TriggerCallbackOnError(int channel_num, int err_code) {
278 RTC_DCHECK(observer_ != NULL);
279 observer_->CallbackOnError(channel_num, err_code);
280 }
281 void set_playout_fail_channel(int channel) { 218 void set_playout_fail_channel(int channel) {
282 playout_fail_channel_ = channel; 219 playout_fail_channel_ = channel;
283 } 220 }
284 void set_fail_create_channel(bool fail_create_channel) { 221 void set_fail_create_channel(bool fail_create_channel) {
285 fail_create_channel_ = fail_create_channel; 222 fail_create_channel_ = fail_create_channel;
286 } 223 }
287 int AddChannel(const webrtc::Config& config) { 224 int AddChannel(const webrtc::Config& config) {
288 if (fail_create_channel_) { 225 if (fail_create_channel_) {
289 return -1; 226 return -1;
290 } 227 }
(...skipping 11 matching lines...) Expand all
302 239
303 int GetNumSetSendCodecs() const { return num_set_send_codecs_; } 240 int GetNumSetSendCodecs() const { return num_set_send_codecs_; }
304 241
305 int GetAssociateSendChannel(int channel) { 242 int GetAssociateSendChannel(int channel) {
306 return channels_[channel]->associate_send_channel; 243 return channels_[channel]->associate_send_channel;
307 } 244 }
308 245
309 WEBRTC_STUB(Release, ()); 246 WEBRTC_STUB(Release, ());
310 247
311 // webrtc::VoEBase 248 // webrtc::VoEBase
312 WEBRTC_FUNC(RegisterVoiceEngineObserver, ( 249 WEBRTC_STUB(RegisterVoiceEngineObserver, (
313 webrtc::VoiceEngineObserver& observer)) { 250 webrtc::VoiceEngineObserver& observer));
314 observer_ = &observer;
315 return 0;
316 }
317 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ()); 251 WEBRTC_STUB(DeRegisterVoiceEngineObserver, ());
318 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm, 252 WEBRTC_FUNC(Init, (webrtc::AudioDeviceModule* adm,
319 webrtc::AudioProcessing* audioproc)) { 253 webrtc::AudioProcessing* audioproc)) {
320 inited_ = true; 254 inited_ = true;
321 return 0; 255 return 0;
322 } 256 }
323 WEBRTC_FUNC(Terminate, ()) { 257 WEBRTC_FUNC(Terminate, ()) {
324 inited_ = false; 258 inited_ = false;
325 return 0; 259 return 0;
326 } 260 }
327 webrtc::AudioProcessing* audio_processing() override { 261 webrtc::AudioProcessing* audio_processing() override {
328 return &audio_processing_; 262 return &audio_processing_;
329 } 263 }
330 webrtc::AudioDeviceModule* audio_device_module() override { 264 webrtc::AudioDeviceModule* audio_device_module() override {
331 return &audio_device_module_; 265 return nullptr;
332 } 266 }
333 WEBRTC_FUNC(CreateChannel, ()) { 267 WEBRTC_FUNC(CreateChannel, ()) {
334 webrtc::Config empty_config; 268 webrtc::Config empty_config;
335 return AddChannel(empty_config); 269 return AddChannel(empty_config);
336 } 270 }
337 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) { 271 WEBRTC_FUNC(CreateChannel, (const webrtc::Config& config)) {
338 return AddChannel(config); 272 return AddChannel(config);
339 } 273 }
340 WEBRTC_FUNC(DeleteChannel, (int channel)) { 274 WEBRTC_FUNC(DeleteChannel, (int channel)) {
341 WEBRTC_CHECK_CHANNEL(channel); 275 WEBRTC_CHECK_CHANNEL(channel);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 ASSERT(ch != channels_.end()); 703 ASSERT(ch != channels_.end());
770 return ch->second->neteq_capacity; 704 return ch->second->neteq_capacity;
771 } 705 }
772 bool GetNetEqFastAccelerate() const { 706 bool GetNetEqFastAccelerate() const {
773 auto ch = channels_.find(last_channel_); 707 auto ch = channels_.find(last_channel_);
774 ASSERT(ch != channels_.end()); 708 ASSERT(ch != channels_.end());
775 return ch->second->neteq_fast_accelerate; 709 return ch->second->neteq_fast_accelerate;
776 } 710 }
777 711
778 private: 712 private:
779 bool inited_; 713 bool inited_ = false;
780 int last_channel_; 714 int last_channel_ = -1;
781 std::map<int, Channel*> channels_; 715 std::map<int, Channel*> channels_;
782 bool fail_create_channel_; 716 bool fail_create_channel_ = false;
783 int num_set_send_codecs_; // how many times we call SetSendCodec(). 717 int num_set_send_codecs_ = 0; // how many times we call SetSendCodec().
784 bool ec_enabled_; 718 bool ec_enabled_ = false;
785 bool ec_metrics_enabled_; 719 bool ec_metrics_enabled_ = false;
786 bool cng_enabled_; 720 bool cng_enabled_ = false;
787 bool ns_enabled_; 721 bool ns_enabled_ = false;
788 bool agc_enabled_; 722 bool agc_enabled_ = false;
789 bool highpass_filter_enabled_; 723 bool highpass_filter_enabled_ = false;
790 bool stereo_swapping_enabled_; 724 bool stereo_swapping_enabled_ = false;
791 bool typing_detection_enabled_; 725 bool typing_detection_enabled_ = false;
792 webrtc::EcModes ec_mode_; 726 webrtc::EcModes ec_mode_ = webrtc::kEcDefault;
793 webrtc::AecmModes aecm_mode_; 727 webrtc::AecmModes aecm_mode_ = webrtc::kAecmSpeakerphone;
794 webrtc::NsModes ns_mode_; 728 webrtc::NsModes ns_mode_ = webrtc::kNsDefault;
795 webrtc::AgcModes agc_mode_; 729 webrtc::AgcModes agc_mode_ = webrtc::kAgcDefault;
796 webrtc::AgcConfig agc_config_; 730 webrtc::AgcConfig agc_config_;
797 webrtc::VoiceEngineObserver* observer_; 731 int playout_fail_channel_ = -1;
798 int playout_fail_channel_; 732 int recording_sample_rate_ = -1;
799 int recording_sample_rate_; 733 int playout_sample_rate_ = -1;
800 int playout_sample_rate_;
801 FakeAudioProcessing audio_processing_; 734 FakeAudioProcessing audio_processing_;
802 FakeAudioDeviceModule audio_device_module_;
803 }; 735 };
804 736
805 } // namespace cricket 737 } // namespace cricket
806 738
807 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ 739 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_
OLDNEW
« no previous file with comments | « webrtc/media/engine/fakewebrtcvideoengine.h ('k') | webrtc/media/engine/webrtcvoiceengine_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698