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> | |
15 | |
16 #include <list> | |
17 #include <map> | 14 #include <map> |
18 #include <vector> | 15 #include <vector> |
19 | 16 |
20 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/stringutils.h" | |
22 #include "webrtc/base/checks.h" | |
23 #include "webrtc/config.h" | |
24 #include "webrtc/media/base/codec.h" | |
25 #include "webrtc/media/base/rtputils.h" | |
26 #include "webrtc/media/engine/webrtcvoe.h" | 18 #include "webrtc/media/engine/webrtcvoe.h" |
27 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | |
28 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 19 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
29 | 20 |
30 namespace webrtc { | 21 namespace webrtc { |
31 namespace voe { | 22 namespace voe { |
32 class TransmitMixer; | 23 class TransmitMixer; |
33 } // namespace voe | 24 } // namespace voe |
34 } // namespace webrtc | 25 } // namespace webrtc |
35 | 26 |
36 namespace cricket { | 27 namespace cricket { |
37 | 28 |
38 static const int kOpusBandwidthNb = 4000; | |
39 static const int kOpusBandwidthMb = 6000; | |
40 static const int kOpusBandwidthWb = 8000; | |
41 static const int kOpusBandwidthSwb = 12000; | |
42 static const int kOpusBandwidthFb = 20000; | |
43 | |
44 #define WEBRTC_CHECK_CHANNEL(channel) \ | 29 #define WEBRTC_CHECK_CHANNEL(channel) \ |
45 if (channels_.find(channel) == channels_.end()) return -1; | 30 if (channels_.find(channel) == channels_.end()) return -1; |
46 | 31 |
47 #define WEBRTC_STUB(method, args) \ | 32 #define WEBRTC_STUB(method, args) \ |
48 int method args override { return 0; } | 33 int method args override { return 0; } |
49 | 34 |
50 #define WEBRTC_STUB_CONST(method, args) \ | |
51 int method args const override { return 0; } | |
52 | |
53 #define WEBRTC_BOOL_STUB(method, args) \ | |
54 bool method args override { return true; } | |
55 | |
56 #define WEBRTC_VOID_STUB(method, args) \ | |
57 void method args override {} | |
58 | |
59 #define WEBRTC_FUNC(method, args) int method args override | 35 #define WEBRTC_FUNC(method, args) int method args override |
60 | 36 |
61 class FakeWebRtcVoiceEngine | 37 class FakeWebRtcVoiceEngine : public webrtc::VoEBase { |
62 : public webrtc::VoEBase, public webrtc::VoECodec { | |
63 public: | 38 public: |
64 struct Channel { | 39 struct Channel { |
65 std::vector<webrtc::CodecInst> recv_codecs; | 40 std::vector<webrtc::CodecInst> recv_codecs; |
66 size_t neteq_capacity = 0; | 41 size_t neteq_capacity = 0; |
67 bool neteq_fast_accelerate = false; | 42 bool neteq_fast_accelerate = false; |
68 }; | 43 }; |
69 | 44 |
70 explicit FakeWebRtcVoiceEngine(webrtc::AudioProcessing* apm, | 45 explicit FakeWebRtcVoiceEngine(webrtc::AudioProcessing* apm, |
71 webrtc::voe::TransmitMixer* transmit_mixer) | 46 webrtc::voe::TransmitMixer* transmit_mixer) |
72 : apm_(apm), transmit_mixer_(transmit_mixer) { | 47 : apm_(apm), transmit_mixer_(transmit_mixer) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 WEBRTC_STUB(StartPlayout, (int channel)); | 108 WEBRTC_STUB(StartPlayout, (int channel)); |
134 WEBRTC_STUB(StartSend, (int channel)); | 109 WEBRTC_STUB(StartSend, (int channel)); |
135 WEBRTC_STUB(StopReceive, (int channel)); | 110 WEBRTC_STUB(StopReceive, (int channel)); |
136 WEBRTC_STUB(StopPlayout, (int channel)); | 111 WEBRTC_STUB(StopPlayout, (int channel)); |
137 WEBRTC_STUB(StopSend, (int channel)); | 112 WEBRTC_STUB(StopSend, (int channel)); |
138 WEBRTC_STUB(GetVersion, (char version[1024])); | 113 WEBRTC_STUB(GetVersion, (char version[1024])); |
139 WEBRTC_STUB(LastError, ()); | 114 WEBRTC_STUB(LastError, ()); |
140 WEBRTC_STUB(AssociateSendChannel, (int channel, | 115 WEBRTC_STUB(AssociateSendChannel, (int channel, |
141 int accociate_send_channel)); | 116 int accociate_send_channel)); |
142 | 117 |
143 // webrtc::VoECodec | |
144 WEBRTC_STUB(NumOfCodecs, ()); | |
145 WEBRTC_STUB(GetCodec, (int index, webrtc::CodecInst& codec)); | |
146 WEBRTC_STUB(SetSendCodec, (int channel, const webrtc::CodecInst& codec)); | |
147 WEBRTC_STUB(GetSendCodec, (int channel, webrtc::CodecInst& codec)); | |
148 WEBRTC_STUB(SetBitRate, (int channel, int bitrate_bps)); | |
149 WEBRTC_STUB(GetRecCodec, (int channel, webrtc::CodecInst& codec)); | |
150 WEBRTC_FUNC(SetRecPayloadType, (int channel, | |
151 const webrtc::CodecInst& codec)) { | |
152 WEBRTC_CHECK_CHANNEL(channel); | |
153 Channel* ch = channels_[channel]; | |
154 // Check if something else already has this slot. | |
155 if (codec.pltype != -1) { | |
156 for (std::vector<webrtc::CodecInst>::iterator it = | |
157 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) { | |
158 if (it->pltype == codec.pltype && | |
159 _stricmp(it->plname, codec.plname) != 0) { | |
160 return -1; | |
161 } | |
162 } | |
163 } | |
164 // Otherwise try to find this codec and update its payload type. | |
165 int result = -1; // not found | |
166 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin(); | |
167 it != ch->recv_codecs.end(); ++it) { | |
168 if (strcmp(it->plname, codec.plname) == 0 && | |
169 it->plfreq == codec.plfreq && | |
170 it->channels == codec.channels) { | |
171 it->pltype = codec.pltype; | |
172 result = 0; | |
173 } | |
174 } | |
175 return result; | |
176 } | |
177 WEBRTC_STUB(SetSendCNPayloadType, (int channel, int type, | |
178 webrtc::PayloadFrequencies frequency)); | |
179 WEBRTC_FUNC(GetRecPayloadType, (int channel, webrtc::CodecInst& codec)) { | |
180 WEBRTC_CHECK_CHANNEL(channel); | |
181 Channel* ch = channels_[channel]; | |
182 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin(); | |
183 it != ch->recv_codecs.end(); ++it) { | |
184 if (strcmp(it->plname, codec.plname) == 0 && | |
185 it->plfreq == codec.plfreq && | |
186 it->channels == codec.channels && | |
187 it->pltype != -1) { | |
188 codec.pltype = it->pltype; | |
189 return 0; | |
190 } | |
191 } | |
192 return -1; // not found | |
193 } | |
194 WEBRTC_STUB(SetVADStatus, (int channel, bool enable, webrtc::VadModes mode, | |
195 bool disableDTX)); | |
196 WEBRTC_STUB(GetVADStatus, (int channel, bool& enabled, | |
197 webrtc::VadModes& mode, bool& disabledDTX)); | |
198 WEBRTC_STUB(SetFECStatus, (int channel, bool enable)); | |
199 WEBRTC_STUB(GetFECStatus, (int channel, bool& enable)); | |
200 WEBRTC_STUB(SetOpusMaxPlaybackRate, (int channel, int frequency_hz)); | |
201 WEBRTC_STUB(SetOpusDtx, (int channel, bool enable_dtx)); | |
202 | |
203 size_t GetNetEqCapacity() const { | 118 size_t GetNetEqCapacity() const { |
204 auto ch = channels_.find(last_channel_); | 119 auto ch = channels_.find(last_channel_); |
205 RTC_DCHECK(ch != channels_.end()); | 120 RTC_DCHECK(ch != channels_.end()); |
206 return ch->second->neteq_capacity; | 121 return ch->second->neteq_capacity; |
207 } | 122 } |
208 bool GetNetEqFastAccelerate() const { | 123 bool GetNetEqFastAccelerate() const { |
209 auto ch = channels_.find(last_channel_); | 124 auto ch = channels_.find(last_channel_); |
210 RTC_CHECK(ch != channels_.end()); | 125 RTC_CHECK(ch != channels_.end()); |
211 return ch->second->neteq_fast_accelerate; | 126 return ch->second->neteq_fast_accelerate; |
212 } | 127 } |
213 | 128 |
214 private: | 129 private: |
215 bool inited_ = false; | 130 bool inited_ = false; |
216 int last_channel_ = -1; | 131 int last_channel_ = -1; |
217 std::map<int, Channel*> channels_; | 132 std::map<int, Channel*> channels_; |
218 bool fail_create_channel_ = false; | 133 bool fail_create_channel_ = false; |
219 webrtc::AudioProcessing* apm_ = nullptr; | 134 webrtc::AudioProcessing* apm_ = nullptr; |
220 webrtc::voe::TransmitMixer* transmit_mixer_ = nullptr; | 135 webrtc::voe::TransmitMixer* transmit_mixer_ = nullptr; |
221 | 136 |
222 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FakeWebRtcVoiceEngine); | 137 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FakeWebRtcVoiceEngine); |
223 }; | 138 }; |
224 | 139 |
225 } // namespace cricket | 140 } // namespace cricket |
226 | 141 |
227 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ | 142 #endif // WEBRTC_MEDIA_ENGINE_FAKEWEBRTCVOICEENGINE_H_ |
OLD | NEW |