OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 #include "talk/media/base/codec.h" | 35 #include "talk/media/base/codec.h" |
36 #include "talk/media/base/rtputils.h" | 36 #include "talk/media/base/rtputils.h" |
37 #include "talk/media/webrtc/fakewebrtccommon.h" | 37 #include "talk/media/webrtc/fakewebrtccommon.h" |
38 #include "talk/media/webrtc/webrtcvoe.h" | 38 #include "talk/media/webrtc/webrtcvoe.h" |
39 #include "webrtc/base/basictypes.h" | 39 #include "webrtc/base/basictypes.h" |
40 #include "webrtc/base/checks.h" | 40 #include "webrtc/base/checks.h" |
41 #include "webrtc/base/gunit.h" | 41 #include "webrtc/base/gunit.h" |
42 #include "webrtc/base/stringutils.h" | 42 #include "webrtc/base/stringutils.h" |
43 #include "webrtc/config.h" | 43 #include "webrtc/config.h" |
44 #include "webrtc/modules/audio_coding/main/acm2/rent_a_codec.h" | |
44 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 45 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
45 | 46 |
46 namespace cricket { | 47 namespace cricket { |
47 | 48 |
48 static const char kFakeDefaultDeviceName[] = "Fake Default"; | 49 static const char kFakeDefaultDeviceName[] = "Fake Default"; |
49 static const int kFakeDefaultDeviceId = -1; | 50 static const int kFakeDefaultDeviceId = -1; |
50 static const char kFakeDeviceName[] = "Fake Device"; | 51 static const char kFakeDeviceName[] = "Fake Device"; |
51 #ifdef WIN32 | 52 #ifdef WIN32 |
52 static const int kFakeDeviceId = 0; | 53 static const int kFakeDeviceId = 0; |
53 #else | 54 #else |
54 static const int kFakeDeviceId = 1; | 55 static const int kFakeDeviceId = 1; |
55 #endif | 56 #endif |
56 | 57 |
57 static const int kOpusBandwidthNb = 4000; | 58 static const int kOpusBandwidthNb = 4000; |
58 static const int kOpusBandwidthMb = 6000; | 59 static const int kOpusBandwidthMb = 6000; |
59 static const int kOpusBandwidthWb = 8000; | 60 static const int kOpusBandwidthWb = 8000; |
60 static const int kOpusBandwidthSwb = 12000; | 61 static const int kOpusBandwidthSwb = 12000; |
61 static const int kOpusBandwidthFb = 20000; | 62 static const int kOpusBandwidthFb = 20000; |
62 | 63 |
63 #define WEBRTC_CHECK_CHANNEL(channel) \ | 64 #define WEBRTC_CHECK_CHANNEL(channel) \ |
64 if (channels_.find(channel) == channels_.end()) return -1; | 65 if (channels_.find(channel) == channels_.end()) return -1; |
65 | 66 |
66 #define WEBRTC_ASSERT_CHANNEL(channel) \ | |
67 RTC_DCHECK(channels_.find(channel) != channels_.end()); | |
68 | |
69 // Verify the header extension ID, if enabled, is within the bounds specified in | |
70 // [RFC5285]: 1-14 inclusive. | |
71 #define WEBRTC_CHECK_HEADER_EXTENSION_ID(enable, id) \ | |
72 do { \ | |
73 if (enable && (id < 1 || id > 14)) { \ | |
74 return -1; \ | |
75 } \ | |
76 } while (0); | |
77 | |
78 class FakeAudioProcessing : public webrtc::AudioProcessing { | 67 class FakeAudioProcessing : public webrtc::AudioProcessing { |
79 public: | 68 public: |
80 FakeAudioProcessing() : experimental_ns_enabled_(false) {} | 69 FakeAudioProcessing() : experimental_ns_enabled_(false) {} |
81 | 70 |
82 WEBRTC_STUB(Initialize, ()) | 71 WEBRTC_STUB(Initialize, ()) |
83 WEBRTC_STUB(Initialize, ( | 72 WEBRTC_STUB(Initialize, ( |
84 int input_sample_rate_hz, | 73 int input_sample_rate_hz, |
85 int output_sample_rate_hz, | 74 int output_sample_rate_hz, |
86 int reverse_sample_rate_hz, | 75 int reverse_sample_rate_hz, |
87 webrtc::AudioProcessing::ChannelLayout input_layout, | 76 webrtc::AudioProcessing::ChannelLayout input_layout, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 int associate_send_channel; | 201 int associate_send_channel; |
213 DtmfInfo dtmf_info; | 202 DtmfInfo dtmf_info; |
214 std::vector<webrtc::CodecInst> recv_codecs; | 203 std::vector<webrtc::CodecInst> recv_codecs; |
215 webrtc::CodecInst send_codec; | 204 webrtc::CodecInst send_codec; |
216 webrtc::PacketTime last_rtp_packet_time; | 205 webrtc::PacketTime last_rtp_packet_time; |
217 std::list<std::string> packets; | 206 std::list<std::string> packets; |
218 int neteq_capacity; | 207 int neteq_capacity; |
219 bool neteq_fast_accelerate; | 208 bool neteq_fast_accelerate; |
220 }; | 209 }; |
221 | 210 |
222 FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs, | 211 FakeWebRtcVoiceEngine() |
223 int num_codecs) | |
224 : inited_(false), | 212 : inited_(false), |
225 last_channel_(-1), | 213 last_channel_(-1), |
226 fail_create_channel_(false), | 214 fail_create_channel_(false), |
227 codecs_(codecs), | |
228 num_codecs_(num_codecs), | |
229 num_set_send_codecs_(0), | 215 num_set_send_codecs_(0), |
230 ec_enabled_(false), | 216 ec_enabled_(false), |
231 ec_metrics_enabled_(false), | 217 ec_metrics_enabled_(false), |
232 cng_enabled_(false), | 218 cng_enabled_(false), |
233 ns_enabled_(false), | 219 ns_enabled_(false), |
234 agc_enabled_(false), | 220 agc_enabled_(false), |
235 highpass_filter_enabled_(false), | 221 highpass_filter_enabled_(false), |
236 stereo_swapping_enabled_(false), | 222 stereo_swapping_enabled_(false), |
237 typing_detection_enabled_(false), | 223 typing_detection_enabled_(false), |
238 ec_mode_(webrtc::kEcDefault), | 224 ec_mode_(webrtc::kEcDefault), |
239 aecm_mode_(webrtc::kAecmSpeakerphone), | 225 aecm_mode_(webrtc::kAecmSpeakerphone), |
240 ns_mode_(webrtc::kNsDefault), | 226 ns_mode_(webrtc::kNsDefault), |
241 agc_mode_(webrtc::kAgcDefault), | 227 agc_mode_(webrtc::kAgcDefault), |
242 observer_(NULL), | 228 observer_(NULL), |
243 playout_fail_channel_(-1), | 229 playout_fail_channel_(-1), |
244 send_fail_channel_(-1), | 230 send_fail_channel_(-1), |
245 recording_sample_rate_(-1), | 231 recording_sample_rate_(-1), |
246 playout_sample_rate_(-1) { | 232 playout_sample_rate_(-1) { |
247 memset(&agc_config_, 0, sizeof(agc_config_)); | 233 memset(&agc_config_, 0, sizeof(agc_config_)); |
248 } | 234 } |
249 ~FakeWebRtcVoiceEngine() { | 235 ~FakeWebRtcVoiceEngine() { |
250 // Ought to have all been deleted by the WebRtcVoiceMediaChannel | 236 RTC_CHECK(channels_.empty()); |
251 // destructors, but just in case ... | |
252 for (std::map<int, Channel*>::const_iterator i = channels_.begin(); | |
253 i != channels_.end(); ++i) { | |
254 delete i->second; | |
255 } | |
256 } | 237 } |
257 | 238 |
258 bool ec_metrics_enabled() const { return ec_metrics_enabled_; } | 239 bool ec_metrics_enabled() const { return ec_metrics_enabled_; } |
259 | 240 |
260 bool IsInited() const { return inited_; } | 241 bool IsInited() const { return inited_; } |
261 int GetLastChannel() const { return last_channel_; } | 242 int GetLastChannel() const { return last_channel_; } |
262 int GetNumChannels() const { return static_cast<int>(channels_.size()); } | 243 int GetNumChannels() const { return static_cast<int>(channels_.size()); } |
263 uint32_t GetLocalSSRC(int channel) { | 244 uint32_t GetLocalSSRC(int channel) { |
264 return channels_[channel]->send_ssrc; | 245 return channels_[channel]->send_ssrc; |
265 } | 246 } |
(...skipping 18 matching lines...) Expand all Loading... | |
284 int GetMaxEncodingBandwidth(int channel) { | 265 int GetMaxEncodingBandwidth(int channel) { |
285 return channels_[channel]->max_encoding_bandwidth; | 266 return channels_[channel]->max_encoding_bandwidth; |
286 } | 267 } |
287 bool GetNACK(int channel) { | 268 bool GetNACK(int channel) { |
288 return channels_[channel]->nack; | 269 return channels_[channel]->nack; |
289 } | 270 } |
290 int GetNACKMaxPackets(int channel) { | 271 int GetNACKMaxPackets(int channel) { |
291 return channels_[channel]->nack_max_packets; | 272 return channels_[channel]->nack_max_packets; |
292 } | 273 } |
293 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) { | 274 const webrtc::PacketTime& GetLastRtpPacketTime(int channel) { |
294 WEBRTC_ASSERT_CHANNEL(channel); | 275 RTC_DCHECK(channels_.find(channel) != channels_.end()); |
295 return channels_[channel]->last_rtp_packet_time; | 276 return channels_[channel]->last_rtp_packet_time; |
296 } | 277 } |
297 int GetSendCNPayloadType(int channel, bool wideband) { | 278 int GetSendCNPayloadType(int channel, bool wideband) { |
298 return (wideband) ? | 279 return (wideband) ? |
299 channels_[channel]->cn16_type : | 280 channels_[channel]->cn16_type : |
300 channels_[channel]->cn8_type; | 281 channels_[channel]->cn8_type; |
301 } | 282 } |
302 int GetSendTelephoneEventPayloadType(int channel) { | 283 int GetSendTelephoneEventPayloadType(int channel) { |
303 return channels_[channel]->dtmf_type; | 284 return channels_[channel]->dtmf_type; |
304 } | 285 } |
(...skipping 23 matching lines...) Expand all Loading... | |
328 send_fail_channel_ = channel; | 309 send_fail_channel_ = channel; |
329 } | 310 } |
330 void set_fail_create_channel(bool fail_create_channel) { | 311 void set_fail_create_channel(bool fail_create_channel) { |
331 fail_create_channel_ = fail_create_channel; | 312 fail_create_channel_ = fail_create_channel; |
332 } | 313 } |
333 int AddChannel(const webrtc::Config& config) { | 314 int AddChannel(const webrtc::Config& config) { |
334 if (fail_create_channel_) { | 315 if (fail_create_channel_) { |
335 return -1; | 316 return -1; |
336 } | 317 } |
337 Channel* ch = new Channel(); | 318 Channel* ch = new Channel(); |
338 for (int i = 0; i < NumOfCodecs(); ++i) { | 319 for (const webrtc::CodecInst& c : webrtc::acm2::RentACodec::Database()) { |
339 webrtc::CodecInst codec; | 320 ch->recv_codecs.push_back(c); |
kwiberg-webrtc
2015/11/26 14:13:56
auto db = webrtc::acm2::RentACodec::Database();
ch
the sun
2015/11/26 14:27:20
Done.
| |
340 GetCodec(i, codec); | |
341 ch->recv_codecs.push_back(codec); | |
342 } | 321 } |
343 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) { | 322 if (config.Get<webrtc::NetEqCapacityConfig>().enabled) { |
344 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity; | 323 ch->neteq_capacity = config.Get<webrtc::NetEqCapacityConfig>().capacity; |
345 } | 324 } |
346 ch->neteq_fast_accelerate = | 325 ch->neteq_fast_accelerate = |
347 config.Get<webrtc::NetEqFastAccelerate>().enabled; | 326 config.Get<webrtc::NetEqFastAccelerate>().enabled; |
348 channels_[++last_channel_] = ch; | 327 channels_[++last_channel_] = ch; |
349 return last_channel_; | 328 return last_channel_; |
350 } | 329 } |
351 | 330 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 WEBRTC_STUB(LastError, ()); | 411 WEBRTC_STUB(LastError, ()); |
433 WEBRTC_FUNC(AssociateSendChannel, (int channel, | 412 WEBRTC_FUNC(AssociateSendChannel, (int channel, |
434 int accociate_send_channel)) { | 413 int accociate_send_channel)) { |
435 WEBRTC_CHECK_CHANNEL(channel); | 414 WEBRTC_CHECK_CHANNEL(channel); |
436 channels_[channel]->associate_send_channel = accociate_send_channel; | 415 channels_[channel]->associate_send_channel = accociate_send_channel; |
437 return 0; | 416 return 0; |
438 } | 417 } |
439 webrtc::RtcEventLog* GetEventLog() { return nullptr; } | 418 webrtc::RtcEventLog* GetEventLog() { return nullptr; } |
440 | 419 |
441 // webrtc::VoECodec | 420 // webrtc::VoECodec |
442 WEBRTC_FUNC(NumOfCodecs, ()) { | 421 WEBRTC_STUB(NumOfCodecs, ()); |
443 return num_codecs_; | 422 WEBRTC_STUB(GetCodec, (int index, webrtc::CodecInst& codec)); |
444 } | |
445 WEBRTC_FUNC(GetCodec, (int index, webrtc::CodecInst& codec)) { | |
446 if (index < 0 || index >= NumOfCodecs()) { | |
447 return -1; | |
448 } | |
449 const cricket::AudioCodec& c(*codecs_[index]); | |
450 codec.pltype = c.id; | |
451 rtc::strcpyn(codec.plname, sizeof(codec.plname), c.name.c_str()); | |
452 codec.plfreq = c.clockrate; | |
453 codec.pacsize = 0; | |
454 codec.channels = c.channels; | |
455 codec.rate = c.bitrate; | |
456 return 0; | |
457 } | |
458 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) { | 423 WEBRTC_FUNC(SetSendCodec, (int channel, const webrtc::CodecInst& codec)) { |
459 WEBRTC_CHECK_CHANNEL(channel); | 424 WEBRTC_CHECK_CHANNEL(channel); |
460 // To match the behavior of the real implementation. | 425 // To match the behavior of the real implementation. |
461 if (_stricmp(codec.plname, "telephone-event") == 0 || | 426 if (_stricmp(codec.plname, "telephone-event") == 0 || |
462 _stricmp(codec.plname, "audio/telephone-event") == 0 || | 427 _stricmp(codec.plname, "audio/telephone-event") == 0 || |
463 _stricmp(codec.plname, "CN") == 0 || | 428 _stricmp(codec.plname, "CN") == 0 || |
464 _stricmp(codec.plname, "red") == 0 ) { | 429 _stricmp(codec.plname, "red") == 0 ) { |
465 return -1; | 430 return -1; |
466 } | 431 } |
467 channels_[channel]->send_codec = codec; | 432 channels_[channel]->send_codec = codec; |
(...skipping 17 matching lines...) Expand all Loading... | |
485 if (codec.pltype != -1) { | 450 if (codec.pltype != -1) { |
486 for (std::vector<webrtc::CodecInst>::iterator it = | 451 for (std::vector<webrtc::CodecInst>::iterator it = |
487 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) { | 452 ch->recv_codecs.begin(); it != ch->recv_codecs.end(); ++it) { |
488 if (it->pltype == codec.pltype && | 453 if (it->pltype == codec.pltype && |
489 _stricmp(it->plname, codec.plname) != 0) { | 454 _stricmp(it->plname, codec.plname) != 0) { |
490 return -1; | 455 return -1; |
491 } | 456 } |
492 } | 457 } |
493 } | 458 } |
494 // Otherwise try to find this codec and update its payload type. | 459 // Otherwise try to find this codec and update its payload type. |
460 int result = -1; // not found | |
495 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin(); | 461 for (std::vector<webrtc::CodecInst>::iterator it = ch->recv_codecs.begin(); |
496 it != ch->recv_codecs.end(); ++it) { | 462 it != ch->recv_codecs.end(); ++it) { |
497 if (strcmp(it->plname, codec.plname) == 0 && | 463 if (strcmp(it->plname, codec.plname) == 0 && |
498 it->plfreq == codec.plfreq) { | 464 it->plfreq == codec.plfreq && |
465 it->channels == codec.channels) { | |
499 it->pltype = codec.pltype; | 466 it->pltype = codec.pltype; |
500 it->channels = codec.channels; | 467 result = 0; |
501 return 0; | |
502 } | 468 } |
503 } | 469 } |
504 return -1; // not found | 470 return result; |
505 } | 471 } |
506 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type, | 472 WEBRTC_FUNC(SetSendCNPayloadType, (int channel, int type, |
507 webrtc::PayloadFrequencies frequency)) { | 473 webrtc::PayloadFrequencies frequency)) { |
508 WEBRTC_CHECK_CHANNEL(channel); | 474 WEBRTC_CHECK_CHANNEL(channel); |
509 if (frequency == webrtc::kFreq8000Hz) { | 475 if (frequency == webrtc::kFreq8000Hz) { |
510 channels_[channel]->cn8_type = type; | 476 channels_[channel]->cn8_type = type; |
511 } else if (frequency == webrtc::kFreq16000Hz) { | 477 } else if (frequency == webrtc::kFreq16000Hz) { |
512 channels_[channel]->cn16_type = type; | 478 channels_[channel]->cn16_type = type; |
513 } | 479 } |
514 return 0; | 480 return 0; |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 #endif | 891 #endif |
926 strcpy(name, s); | 892 strcpy(name, s); |
927 guid[0] = '\0'; | 893 guid[0] = '\0'; |
928 return 0; | 894 return 0; |
929 } | 895 } |
930 | 896 |
931 bool inited_; | 897 bool inited_; |
932 int last_channel_; | 898 int last_channel_; |
933 std::map<int, Channel*> channels_; | 899 std::map<int, Channel*> channels_; |
934 bool fail_create_channel_; | 900 bool fail_create_channel_; |
935 const cricket::AudioCodec* const* codecs_; | |
936 int num_codecs_; | |
937 int num_set_send_codecs_; // how many times we call SetSendCodec(). | 901 int num_set_send_codecs_; // how many times we call SetSendCodec(). |
938 bool ec_enabled_; | 902 bool ec_enabled_; |
939 bool ec_metrics_enabled_; | 903 bool ec_metrics_enabled_; |
940 bool cng_enabled_; | 904 bool cng_enabled_; |
941 bool ns_enabled_; | 905 bool ns_enabled_; |
942 bool agc_enabled_; | 906 bool agc_enabled_; |
943 bool highpass_filter_enabled_; | 907 bool highpass_filter_enabled_; |
944 bool stereo_swapping_enabled_; | 908 bool stereo_swapping_enabled_; |
945 bool typing_detection_enabled_; | 909 bool typing_detection_enabled_; |
946 webrtc::EcModes ec_mode_; | 910 webrtc::EcModes ec_mode_; |
947 webrtc::AecmModes aecm_mode_; | 911 webrtc::AecmModes aecm_mode_; |
948 webrtc::NsModes ns_mode_; | 912 webrtc::NsModes ns_mode_; |
949 webrtc::AgcModes agc_mode_; | 913 webrtc::AgcModes agc_mode_; |
950 webrtc::AgcConfig agc_config_; | 914 webrtc::AgcConfig agc_config_; |
951 webrtc::VoiceEngineObserver* observer_; | 915 webrtc::VoiceEngineObserver* observer_; |
952 int playout_fail_channel_; | 916 int playout_fail_channel_; |
953 int send_fail_channel_; | 917 int send_fail_channel_; |
954 int recording_sample_rate_; | 918 int recording_sample_rate_; |
955 int playout_sample_rate_; | 919 int playout_sample_rate_; |
956 DtmfInfo dtmf_info_; | 920 DtmfInfo dtmf_info_; |
957 FakeAudioProcessing audio_processing_; | 921 FakeAudioProcessing audio_processing_; |
958 }; | 922 }; |
959 | 923 |
960 #undef WEBRTC_CHECK_HEADER_EXTENSION_ID | |
961 | |
962 } // namespace cricket | 924 } // namespace cricket |
963 | 925 |
964 #endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_ | 926 #endif // TALK_SESSION_PHONE_FAKEWEBRTCVOICEENGINE_H_ |
OLD | NEW |