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