OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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 #ifdef HAVE_WEBRTC_VOICE | 11 #ifdef HAVE_WEBRTC_VOICE |
12 | 12 |
13 #include "webrtc/media/engine/webrtcvoiceengine.h" | 13 #include "webrtc/media/engine/webrtcvoiceengine.h" |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 #include <cstdio> | 16 #include <cstdio> |
| 17 #include <functional> |
17 #include <string> | 18 #include <string> |
18 #include <vector> | 19 #include <vector> |
19 | 20 |
20 #include "webrtc/audio_sink.h" | 21 #include "webrtc/audio_sink.h" |
21 #include "webrtc/base/arraysize.h" | 22 #include "webrtc/base/arraysize.h" |
22 #include "webrtc/base/base64.h" | 23 #include "webrtc/base/base64.h" |
23 #include "webrtc/base/byteorder.h" | 24 #include "webrtc/base/byteorder.h" |
24 #include "webrtc/base/common.h" | 25 #include "webrtc/base/common.h" |
25 #include "webrtc/base/constructormagic.h" | 26 #include "webrtc/base/constructormagic.h" |
26 #include "webrtc/base/helpers.h" | 27 #include "webrtc/base/helpers.h" |
27 #include "webrtc/base/logging.h" | 28 #include "webrtc/base/logging.h" |
28 #include "webrtc/base/stringencode.h" | 29 #include "webrtc/base/stringencode.h" |
29 #include "webrtc/base/stringutils.h" | 30 #include "webrtc/base/stringutils.h" |
30 #include "webrtc/base/trace_event.h" | 31 #include "webrtc/base/trace_event.h" |
31 #include "webrtc/call/rtc_event_log.h" | 32 #include "webrtc/call/rtc_event_log.h" |
32 #include "webrtc/common.h" | 33 #include "webrtc/common.h" |
33 #include "webrtc/media/base/audiosource.h" | 34 #include "webrtc/media/base/audiosource.h" |
34 #include "webrtc/media/base/mediaconstants.h" | 35 #include "webrtc/media/base/mediaconstants.h" |
35 #include "webrtc/media/base/streamparams.h" | 36 #include "webrtc/media/base/streamparams.h" |
| 37 #include "webrtc/media/engine/payload_type_mapper.h" |
36 #include "webrtc/media/engine/webrtcmediaengine.h" | 38 #include "webrtc/media/engine/webrtcmediaengine.h" |
37 #include "webrtc/media/engine/webrtcvoe.h" | 39 #include "webrtc/media/engine/webrtcvoe.h" |
38 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | 40 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" |
39 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 41 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
40 #include "webrtc/system_wrappers/include/field_trial.h" | 42 #include "webrtc/system_wrappers/include/field_trial.h" |
41 #include "webrtc/system_wrappers/include/trace.h" | 43 #include "webrtc/system_wrappers/include/trace.h" |
42 | 44 |
43 namespace cricket { | 45 namespace cricket { |
44 namespace { | 46 namespace { |
45 | 47 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { | 244 webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { |
243 webrtc::AudioState::Config config; | 245 webrtc::AudioState::Config config; |
244 config.voice_engine = voe_wrapper->engine(); | 246 config.voice_engine = voe_wrapper->engine(); |
245 return config; | 247 return config; |
246 } | 248 } |
247 | 249 |
248 class WebRtcVoiceCodecs final { | 250 class WebRtcVoiceCodecs final { |
249 public: | 251 public: |
250 // TODO(solenberg): Do this filtering once off-line, add a simple AudioCodec | 252 // TODO(solenberg): Do this filtering once off-line, add a simple AudioCodec |
251 // list and add a test which verifies VoE supports the listed codecs. | 253 // list and add a test which verifies VoE supports the listed codecs. |
252 static std::vector<AudioCodec> SupportedCodecs() { | 254 static std::vector<AudioCodec> SupportedSendCodecs() { |
253 std::vector<AudioCodec> result; | 255 std::vector<AudioCodec> result; |
254 // Iterate first over our preferred codecs list, so that the results are | 256 // Iterate first over our preferred codecs list, so that the results are |
255 // added in order of preference. | 257 // added in order of preference. |
256 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { | 258 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { |
257 const CodecPref* pref = &kCodecPrefs[i]; | 259 const CodecPref* pref = &kCodecPrefs[i]; |
258 for (webrtc::CodecInst voe_codec : webrtc::acm2::RentACodec::Database()) { | 260 for (webrtc::CodecInst voe_codec : webrtc::acm2::RentACodec::Database()) { |
259 // Change the sample rate of G722 to 8000 to match SDP. | 261 // Change the sample rate of G722 to 8000 to match SDP. |
260 MaybeFixupG722(&voe_codec, 8000); | 262 MaybeFixupG722(&voe_codec, 8000); |
261 // Skip uncompressed formats. | 263 // Skip uncompressed formats. |
262 if (IsCodec(voe_codec, kL16CodecName)) { | 264 if (IsCodec(voe_codec, kL16CodecName)) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 507 } |
506 | 508 |
507 WebRtcVoiceEngine::WebRtcVoiceEngine( | 509 WebRtcVoiceEngine::WebRtcVoiceEngine( |
508 webrtc::AudioDeviceModule* adm, | 510 webrtc::AudioDeviceModule* adm, |
509 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory, | 511 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory, |
510 VoEWrapper* voe_wrapper) | 512 VoEWrapper* voe_wrapper) |
511 : adm_(adm), decoder_factory_(decoder_factory), voe_wrapper_(voe_wrapper) { | 513 : adm_(adm), decoder_factory_(decoder_factory), voe_wrapper_(voe_wrapper) { |
512 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 514 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
513 LOG(LS_INFO) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; | 515 LOG(LS_INFO) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; |
514 RTC_DCHECK(voe_wrapper); | 516 RTC_DCHECK(voe_wrapper); |
| 517 RTC_DCHECK(decoder_factory); |
515 | 518 |
516 signal_thread_checker_.DetachFromThread(); | 519 signal_thread_checker_.DetachFromThread(); |
517 | 520 |
518 // Load our audio codec list. | 521 // Load our audio codec list. |
519 LOG(LS_INFO) << "Supported codecs in order of preference:"; | 522 LOG(LS_INFO) << "Supported send codecs in order of preference:"; |
520 codecs_ = WebRtcVoiceCodecs::SupportedCodecs(); | 523 send_codecs_ = WebRtcVoiceCodecs::SupportedSendCodecs(); |
521 for (const AudioCodec& codec : codecs_) { | 524 for (const AudioCodec& codec : send_codecs_) { |
522 LOG(LS_INFO) << ToString(codec); | 525 LOG(LS_INFO) << ToString(codec); |
523 } | 526 } |
524 | 527 |
| 528 LOG(LS_INFO) << "Supported recv codecs in order of preference:"; |
| 529 recv_codecs_ = CollectRecvCodecs(); |
| 530 for (const AudioCodec& codec : recv_codecs_) { |
| 531 LOG(LS_INFO) << ToString(codec); |
| 532 } |
| 533 |
525 voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true)); | 534 voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true)); |
526 | 535 |
527 // Temporarily turn logging level up for the Init() call. | 536 // Temporarily turn logging level up for the Init() call. |
528 webrtc::Trace::SetTraceCallback(this); | 537 webrtc::Trace::SetTraceCallback(this); |
529 webrtc::Trace::set_level_filter(kElevatedTraceFilter); | 538 webrtc::Trace::set_level_filter(kElevatedTraceFilter); |
530 LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString(); | 539 LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString(); |
531 RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get(), nullptr, | 540 RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get(), nullptr, |
532 decoder_factory_)); | 541 decoder_factory_)); |
533 webrtc::Trace::set_level_filter(kDefaultTraceFilter); | 542 webrtc::Trace::set_level_filter(kDefaultTraceFilter); |
534 | 543 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 | 908 |
900 int WebRtcVoiceEngine::GetInputLevel() { | 909 int WebRtcVoiceEngine::GetInputLevel() { |
901 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 910 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
902 unsigned int ulevel; | 911 unsigned int ulevel; |
903 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? | 912 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? |
904 static_cast<int>(ulevel) : -1; | 913 static_cast<int>(ulevel) : -1; |
905 } | 914 } |
906 | 915 |
907 const std::vector<AudioCodec>& WebRtcVoiceEngine::send_codecs() const { | 916 const std::vector<AudioCodec>& WebRtcVoiceEngine::send_codecs() const { |
908 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 917 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
909 return codecs_; | 918 return send_codecs_; |
910 } | 919 } |
911 | 920 |
912 const std::vector<AudioCodec>& WebRtcVoiceEngine::recv_codecs() const { | 921 const std::vector<AudioCodec>& WebRtcVoiceEngine::recv_codecs() const { |
913 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 922 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
914 return codecs_; | 923 return recv_codecs_; |
915 } | 924 } |
916 | 925 |
917 RtpCapabilities WebRtcVoiceEngine::GetCapabilities() const { | 926 RtpCapabilities WebRtcVoiceEngine::GetCapabilities() const { |
918 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 927 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
919 RtpCapabilities capabilities; | 928 RtpCapabilities capabilities; |
920 capabilities.header_extensions.push_back( | 929 capabilities.header_extensions.push_back( |
921 webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri, | 930 webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri, |
922 webrtc::RtpExtension::kAudioLevelDefaultId)); | 931 webrtc::RtpExtension::kAudioLevelDefaultId)); |
923 capabilities.header_extensions.push_back( | 932 capabilities.header_extensions.push_back( |
924 webrtc::RtpExtension(webrtc::RtpExtension::kAbsSendTimeUri, | 933 webrtc::RtpExtension(webrtc::RtpExtension::kAbsSendTimeUri, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1074 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1066 return voe_wrapper_->base()->CreateChannel(voe_config_); | 1075 return voe_wrapper_->base()->CreateChannel(voe_config_); |
1067 } | 1076 } |
1068 | 1077 |
1069 webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { | 1078 webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { |
1070 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1079 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1071 RTC_DCHECK(adm_); | 1080 RTC_DCHECK(adm_); |
1072 return adm_; | 1081 return adm_; |
1073 } | 1082 } |
1074 | 1083 |
| 1084 AudioCodecs WebRtcVoiceEngine::CollectRecvCodecs() const { |
| 1085 PayloadTypeMapper mapper; |
| 1086 AudioCodecs out; |
| 1087 const std::vector<webrtc::SdpAudioFormat>& formats = |
| 1088 decoder_factory_->GetSupportedFormats(); |
| 1089 |
| 1090 // Only generate CN payload types for these clockrates |
| 1091 std::map<int, bool, std::greater<int>> generate_cn = {{ 8000, false }, |
| 1092 { 16000, false }, |
| 1093 { 32000, false }}; |
| 1094 |
| 1095 auto map_format = [&mapper, &out] (const webrtc::SdpAudioFormat& format) { |
| 1096 rtc::Optional<AudioCodec> opt_codec = mapper.ToAudioCodec(format); |
| 1097 if (!opt_codec) { |
| 1098 LOG(LS_ERROR) << "Unable to assign payload type to format: " << format; |
| 1099 return false; |
| 1100 } |
| 1101 |
| 1102 auto& codec = *opt_codec; |
| 1103 if (IsCodec(codec, kOpusCodecName)) { |
| 1104 // TODO(ossu): Set this specifically for Opus for now, until we have a |
| 1105 // better way of dealing with rtcp-fb parameters. |
| 1106 codec.AddFeedbackParam( |
| 1107 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); |
| 1108 } |
| 1109 out.push_back(codec); |
| 1110 return true; |
| 1111 }; |
| 1112 |
| 1113 for (const auto& format : formats) { |
| 1114 if (map_format(format)) { |
| 1115 // TODO(ossu): We should get more than just a format from the factory, so |
| 1116 // we can determine if a format should be used with CN or not. For now, |
| 1117 // generate a CN entry for each supported clock rate also used by a format |
| 1118 // supported by the factory. |
| 1119 auto cn = generate_cn.find(format.clockrate_hz); |
| 1120 if (cn != generate_cn.end() /* && format.allow_comfort_noise */) { |
| 1121 cn->second = true; |
| 1122 } |
| 1123 } |
| 1124 } |
| 1125 |
| 1126 // Add CN codecs after "proper" audio codecs |
| 1127 for (const auto& cn : generate_cn) { |
| 1128 if (cn.second) { |
| 1129 map_format({kCnCodecName, cn.first, 1}); |
| 1130 } |
| 1131 } |
| 1132 |
| 1133 // Add telephone-event codec last |
| 1134 map_format({kDtmfCodecName, 8000, 1}); |
| 1135 |
| 1136 return out; |
| 1137 } |
| 1138 |
1075 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream | 1139 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
1076 : public AudioSource::Sink { | 1140 : public AudioSource::Sink { |
1077 public: | 1141 public: |
1078 WebRtcAudioSendStream(int ch, | 1142 WebRtcAudioSendStream(int ch, |
1079 webrtc::AudioTransport* voe_audio_transport, | 1143 webrtc::AudioTransport* voe_audio_transport, |
1080 uint32_t ssrc, | 1144 uint32_t ssrc, |
1081 const std::string& c_name, | 1145 const std::string& c_name, |
1082 const SendCodecSpec& send_codec_spec, | 1146 const SendCodecSpec& send_codec_spec, |
1083 const std::vector<webrtc::RtpExtension>& extensions, | 1147 const std::vector<webrtc::RtpExtension>& extensions, |
1084 webrtc::Call* call, | 1148 webrtc::Call* call, |
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2607 } | 2671 } |
2608 } else { | 2672 } else { |
2609 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2673 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
2610 engine()->voe()->base()->StopPlayout(channel); | 2674 engine()->voe()->base()->StopPlayout(channel); |
2611 } | 2675 } |
2612 return true; | 2676 return true; |
2613 } | 2677 } |
2614 } // namespace cricket | 2678 } // namespace cricket |
2615 | 2679 |
2616 #endif // HAVE_WEBRTC_VOICE | 2680 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |