1 /* 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ 12 #define MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ 13 14 #include <map> 15 #include <vector> 16 17 #include "media/engine/webrtcvoe.h" 18 #include "rtc_base/checks.h" 19 20 namespace webrtc { 21 namespace voe { 22 class TransmitMixer; 23 } // namespace voe 24 } // namespace webrtc 25 26 namespace cricket { 27 28 #define WEBRTC_CHECK_CHANNEL(channel) \ 29 if (channels_.find(channel) == channels_.end()) return -1; 30 31 #define WEBRTC_STUB(method, args) \ 32 int method args override { return 0; } 33 34 #define WEBRTC_FUNC(method, args) int method args override 35 36 class FakeWebRtcVoiceEngine : public webrtc::VoEBase { 37 public: 38 struct Channel { 39 std::vector<webrtc::CodecInst> recv_codecs; 40 size_t neteq_capacity = 0; 41 bool neteq_fast_accelerate = false; 42 }; 43 FakeWebRtcVoiceEngine(webrtc::voe::TransmitMixer * transmit_mixer)44 explicit FakeWebRtcVoiceEngine(webrtc::voe::TransmitMixer* transmit_mixer) 45 : transmit_mixer_(transmit_mixer) {} ~FakeWebRtcVoiceEngine()46 ~FakeWebRtcVoiceEngine() override { 47 RTC_CHECK(channels_.empty()); 48 } 49 IsInited()50 bool IsInited() const { return inited_; } GetLastChannel()51 int GetLastChannel() const { return last_channel_; } GetNumChannels()52 int GetNumChannels() const { return static_cast<int>(channels_.size()); } set_fail_create_channel(bool fail_create_channel)53 void set_fail_create_channel(bool fail_create_channel) { 54 fail_create_channel_ = fail_create_channel; 55 } 56 57 WEBRTC_STUB(Release, ()); 58 59 // webrtc::VoEBase 60 WEBRTC_FUNC(Init, 61 (webrtc::AudioDeviceModule* adm, 62 webrtc::AudioProcessing* audioproc, 63 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& 64 decoder_factory)) { 65 inited_ = true; 66 return 0; 67 } Terminate()68 void Terminate() override { 69 inited_ = false; 70 } transmit_mixer()71 webrtc::voe::TransmitMixer* transmit_mixer() override { 72 return transmit_mixer_; 73 } 74 WEBRTC_FUNC(CreateChannel, ()) { 75 return CreateChannel(webrtc::VoEBase::ChannelConfig()); 76 } 77 WEBRTC_FUNC(CreateChannel, (const webrtc::VoEBase::ChannelConfig& config)) { 78 if (fail_create_channel_) { 79 return -1; 80 } 81 Channel* ch = new Channel(); 82 ch->neteq_capacity = config.acm_config.neteq_config.max_packets_in_buffer; 83 ch->neteq_fast_accelerate = 84 config.acm_config.neteq_config.enable_fast_accelerate; 85 channels_[++last_channel_] = ch; 86 return last_channel_; 87 } 88 WEBRTC_FUNC(DeleteChannel, (int channel)) { 89 WEBRTC_CHECK_CHANNEL(channel); 90 delete channels_[channel]; 91 channels_.erase(channel); 92 return 0; 93 } 94 WEBRTC_STUB(StartPlayout, (int channel)); 95 WEBRTC_STUB(StartSend, (int channel)); 96 WEBRTC_STUB(StopPlayout, (int channel)); 97 WEBRTC_STUB(StopSend, (int channel)); 98 WEBRTC_STUB(SetPlayout, (bool enable)); 99 WEBRTC_STUB(SetRecording, (bool enable)); 100 GetNetEqCapacity()101 size_t GetNetEqCapacity() const { 102 auto ch = channels_.find(last_channel_); 103 RTC_DCHECK(ch != channels_.end()); 104 return ch->second->neteq_capacity; 105 } GetNetEqFastAccelerate()106 bool GetNetEqFastAccelerate() const { 107 auto ch = channels_.find(last_channel_); 108 RTC_CHECK(ch != channels_.end()); 109 return ch->second->neteq_fast_accelerate; 110 } 111 112 private: 113 bool inited_ = false; 114 int last_channel_ = -1; 115 std::map<int, Channel*> channels_; 116 bool fail_create_channel_ = false; 117 webrtc::voe::TransmitMixer* transmit_mixer_ = nullptr; 118 119 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FakeWebRtcVoiceEngine); 120 }; 121 122 } // namespace cricket 123 124 #endif // MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ 125