| 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> | |
| 18 #include <string> | 17 #include <string> |
| 19 #include <vector> | 18 #include <vector> |
| 20 | 19 |
| 21 #include "webrtc/audio_sink.h" | 20 #include "webrtc/audio_sink.h" |
| 22 #include "webrtc/base/arraysize.h" | 21 #include "webrtc/base/arraysize.h" |
| 23 #include "webrtc/base/base64.h" | 22 #include "webrtc/base/base64.h" |
| 24 #include "webrtc/base/byteorder.h" | 23 #include "webrtc/base/byteorder.h" |
| 25 #include "webrtc/base/common.h" | 24 #include "webrtc/base/common.h" |
| 26 #include "webrtc/base/constructormagic.h" | 25 #include "webrtc/base/constructormagic.h" |
| 27 #include "webrtc/base/helpers.h" | 26 #include "webrtc/base/helpers.h" |
| 28 #include "webrtc/base/logging.h" | 27 #include "webrtc/base/logging.h" |
| 29 #include "webrtc/base/stringencode.h" | 28 #include "webrtc/base/stringencode.h" |
| 30 #include "webrtc/base/stringutils.h" | 29 #include "webrtc/base/stringutils.h" |
| 31 #include "webrtc/base/trace_event.h" | 30 #include "webrtc/base/trace_event.h" |
| 32 #include "webrtc/common.h" | 31 #include "webrtc/common.h" |
| 33 #include "webrtc/media/base/audiosource.h" | 32 #include "webrtc/media/base/audiosource.h" |
| 34 #include "webrtc/media/base/mediaconstants.h" | 33 #include "webrtc/media/base/mediaconstants.h" |
| 35 #include "webrtc/media/base/streamparams.h" | 34 #include "webrtc/media/base/streamparams.h" |
| 36 #include "webrtc/media/engine/payload_type_mapper.h" | |
| 37 #include "webrtc/media/engine/webrtcmediaengine.h" | 35 #include "webrtc/media/engine/webrtcmediaengine.h" |
| 38 #include "webrtc/media/engine/webrtcvoe.h" | 36 #include "webrtc/media/engine/webrtcvoe.h" |
| 39 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | 37 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" |
| 40 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 38 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 41 #include "webrtc/system_wrappers/include/field_trial.h" | 39 #include "webrtc/system_wrappers/include/field_trial.h" |
| 42 #include "webrtc/system_wrappers/include/trace.h" | 40 #include "webrtc/system_wrappers/include/trace.h" |
| 43 | 41 |
| 44 namespace cricket { | 42 namespace cricket { |
| 45 namespace { | 43 namespace { |
| 46 | 44 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { | 241 webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { |
| 244 webrtc::AudioState::Config config; | 242 webrtc::AudioState::Config config; |
| 245 config.voice_engine = voe_wrapper->engine(); | 243 config.voice_engine = voe_wrapper->engine(); |
| 246 return config; | 244 return config; |
| 247 } | 245 } |
| 248 | 246 |
| 249 class WebRtcVoiceCodecs final { | 247 class WebRtcVoiceCodecs final { |
| 250 public: | 248 public: |
| 251 // TODO(solenberg): Do this filtering once off-line, add a simple AudioCodec | 249 // TODO(solenberg): Do this filtering once off-line, add a simple AudioCodec |
| 252 // list and add a test which verifies VoE supports the listed codecs. | 250 // list and add a test which verifies VoE supports the listed codecs. |
| 253 static std::vector<AudioCodec> SupportedSendCodecs() { | 251 static std::vector<AudioCodec> SupportedCodecs() { |
| 254 std::vector<AudioCodec> result; | 252 std::vector<AudioCodec> result; |
| 255 // Iterate first over our preferred codecs list, so that the results are | 253 // Iterate first over our preferred codecs list, so that the results are |
| 256 // added in order of preference. | 254 // added in order of preference. |
| 257 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { | 255 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { |
| 258 const CodecPref* pref = &kCodecPrefs[i]; | 256 const CodecPref* pref = &kCodecPrefs[i]; |
| 259 for (webrtc::CodecInst voe_codec : webrtc::acm2::RentACodec::Database()) { | 257 for (webrtc::CodecInst voe_codec : webrtc::acm2::RentACodec::Database()) { |
| 260 // Change the sample rate of G722 to 8000 to match SDP. | 258 // Change the sample rate of G722 to 8000 to match SDP. |
| 261 MaybeFixupG722(&voe_codec, 8000); | 259 MaybeFixupG722(&voe_codec, 8000); |
| 262 // Skip uncompressed formats. | 260 // Skip uncompressed formats. |
| 263 if (IsCodec(voe_codec, kL16CodecName)) { | 261 if (IsCodec(voe_codec, kL16CodecName)) { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 } | 504 } |
| 507 | 505 |
| 508 WebRtcVoiceEngine::WebRtcVoiceEngine( | 506 WebRtcVoiceEngine::WebRtcVoiceEngine( |
| 509 webrtc::AudioDeviceModule* adm, | 507 webrtc::AudioDeviceModule* adm, |
| 510 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory, | 508 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory, |
| 511 VoEWrapper* voe_wrapper) | 509 VoEWrapper* voe_wrapper) |
| 512 : adm_(adm), decoder_factory_(decoder_factory), voe_wrapper_(voe_wrapper) { | 510 : adm_(adm), decoder_factory_(decoder_factory), voe_wrapper_(voe_wrapper) { |
| 513 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 511 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 514 LOG(LS_INFO) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; | 512 LOG(LS_INFO) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; |
| 515 RTC_DCHECK(voe_wrapper); | 513 RTC_DCHECK(voe_wrapper); |
| 516 RTC_DCHECK(decoder_factory); | |
| 517 | 514 |
| 518 signal_thread_checker_.DetachFromThread(); | 515 signal_thread_checker_.DetachFromThread(); |
| 519 | 516 |
| 520 // Load our audio codec list. | 517 // Load our audio codec list. |
| 521 LOG(LS_INFO) << "Supported send codecs in order of preference:"; | 518 LOG(LS_INFO) << "Supported codecs in order of preference:"; |
| 522 send_codecs_ = WebRtcVoiceCodecs::SupportedSendCodecs(); | 519 codecs_ = WebRtcVoiceCodecs::SupportedCodecs(); |
| 523 for (const AudioCodec& codec : send_codecs_) { | 520 for (const AudioCodec& codec : codecs_) { |
| 524 LOG(LS_INFO) << ToString(codec); | 521 LOG(LS_INFO) << ToString(codec); |
| 525 } | 522 } |
| 526 | 523 |
| 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 | |
| 533 voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true)); | 524 voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true)); |
| 534 | 525 |
| 535 // Temporarily turn logging level up for the Init() call. | 526 // Temporarily turn logging level up for the Init() call. |
| 536 webrtc::Trace::SetTraceCallback(this); | 527 webrtc::Trace::SetTraceCallback(this); |
| 537 webrtc::Trace::set_level_filter(kElevatedTraceFilter); | 528 webrtc::Trace::set_level_filter(kElevatedTraceFilter); |
| 538 LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString(); | 529 LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString(); |
| 539 RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get(), nullptr, | 530 RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get(), nullptr, |
| 540 decoder_factory_)); | 531 decoder_factory_)); |
| 541 webrtc::Trace::set_level_filter(kDefaultTraceFilter); | 532 webrtc::Trace::set_level_filter(kDefaultTraceFilter); |
| 542 | 533 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 | 929 |
| 939 int WebRtcVoiceEngine::GetInputLevel() { | 930 int WebRtcVoiceEngine::GetInputLevel() { |
| 940 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 931 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 941 unsigned int ulevel; | 932 unsigned int ulevel; |
| 942 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? | 933 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? |
| 943 static_cast<int>(ulevel) : -1; | 934 static_cast<int>(ulevel) : -1; |
| 944 } | 935 } |
| 945 | 936 |
| 946 const std::vector<AudioCodec>& WebRtcVoiceEngine::send_codecs() const { | 937 const std::vector<AudioCodec>& WebRtcVoiceEngine::send_codecs() const { |
| 947 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 938 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
| 948 return send_codecs_; | 939 return codecs_; |
| 949 } | 940 } |
| 950 | 941 |
| 951 const std::vector<AudioCodec>& WebRtcVoiceEngine::recv_codecs() const { | 942 const std::vector<AudioCodec>& WebRtcVoiceEngine::recv_codecs() const { |
| 952 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 943 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
| 953 return recv_codecs_; | 944 return codecs_; |
| 954 } | 945 } |
| 955 | 946 |
| 956 RtpCapabilities WebRtcVoiceEngine::GetCapabilities() const { | 947 RtpCapabilities WebRtcVoiceEngine::GetCapabilities() const { |
| 957 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 948 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
| 958 RtpCapabilities capabilities; | 949 RtpCapabilities capabilities; |
| 959 capabilities.header_extensions.push_back( | 950 capabilities.header_extensions.push_back( |
| 960 webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri, | 951 webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri, |
| 961 webrtc::RtpExtension::kAudioLevelDefaultId)); | 952 webrtc::RtpExtension::kAudioLevelDefaultId)); |
| 962 capabilities.header_extensions.push_back( | 953 capabilities.header_extensions.push_back( |
| 963 webrtc::RtpExtension(webrtc::RtpExtension::kAbsSendTimeUri, | 954 webrtc::RtpExtension(webrtc::RtpExtension::kAbsSendTimeUri, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1074 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1084 return voe_wrapper_->base()->CreateChannel(voe_config_); | 1075 return voe_wrapper_->base()->CreateChannel(voe_config_); |
| 1085 } | 1076 } |
| 1086 | 1077 |
| 1087 webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { | 1078 webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { |
| 1088 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1079 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1089 RTC_DCHECK(adm_); | 1080 RTC_DCHECK(adm_); |
| 1090 return adm_; | 1081 return adm_; |
| 1091 } | 1082 } |
| 1092 | 1083 |
| 1093 AudioCodecs WebRtcVoiceEngine::CollectRecvCodecs() const { | |
| 1094 PayloadTypeMapper mapper; | |
| 1095 AudioCodecs out; | |
| 1096 const std::vector<webrtc::SdpAudioFormat>& formats = | |
| 1097 decoder_factory_->GetSupportedFormats(); | |
| 1098 | |
| 1099 // Only generate CN payload types for these clockrates | |
| 1100 std::map<int, bool, std::greater<int>> generate_cn = {{ 8000, false }, | |
| 1101 { 16000, false }, | |
| 1102 { 32000, false }}; | |
| 1103 | |
| 1104 auto map_format = [&mapper, &out] (const webrtc::SdpAudioFormat& format) { | |
| 1105 rtc::Optional<AudioCodec> opt_codec = mapper.ToAudioCodec(format); | |
| 1106 if (!opt_codec) { | |
| 1107 LOG(LS_ERROR) << "Unable to assign payload type to format: " << format; | |
| 1108 return false; | |
| 1109 } | |
| 1110 | |
| 1111 auto& codec = *opt_codec; | |
| 1112 if (IsCodec(codec, kOpusCodecName)) { | |
| 1113 // TODO(ossu): Set this specifically for Opus for now, until we have a | |
| 1114 // better way of dealing with rtcp-fb parameters. | |
| 1115 codec.AddFeedbackParam( | |
| 1116 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); | |
| 1117 } | |
| 1118 out.push_back(codec); | |
| 1119 return true; | |
| 1120 }; | |
| 1121 | |
| 1122 for (const auto& format : formats) { | |
| 1123 if (map_format(format)) { | |
| 1124 // TODO(ossu): We should get more than just a format from the factory, so | |
| 1125 // we can determine if a format should be used with CN or not. For now, | |
| 1126 // generate a CN entry for each supported clock rate also used by a format | |
| 1127 // supported by the factory. | |
| 1128 auto cn = generate_cn.find(format.clockrate_hz); | |
| 1129 if (cn != generate_cn.end() /* && format.allow_comfort_noise */) { | |
| 1130 cn->second = true; | |
| 1131 } | |
| 1132 } | |
| 1133 } | |
| 1134 | |
| 1135 // Add CN codecs after "proper" audio codecs | |
| 1136 for (const auto& cn : generate_cn) { | |
| 1137 if (cn.second) { | |
| 1138 map_format({kCnCodecName, cn.first, 1}); | |
| 1139 } | |
| 1140 } | |
| 1141 | |
| 1142 // Add telephone-event codec last | |
| 1143 map_format({kDtmfCodecName, 8000, 1}); | |
| 1144 | |
| 1145 return out; | |
| 1146 } | |
| 1147 | |
| 1148 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream | 1084 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
| 1149 : public AudioSource::Sink { | 1085 : public AudioSource::Sink { |
| 1150 public: | 1086 public: |
| 1151 WebRtcAudioSendStream(int ch, | 1087 WebRtcAudioSendStream(int ch, |
| 1152 webrtc::AudioTransport* voe_audio_transport, | 1088 webrtc::AudioTransport* voe_audio_transport, |
| 1153 uint32_t ssrc, | 1089 uint32_t ssrc, |
| 1154 const std::string& c_name, | 1090 const std::string& c_name, |
| 1155 const SendCodecSpec& send_codec_spec, | 1091 const SendCodecSpec& send_codec_spec, |
| 1156 const std::vector<webrtc::RtpExtension>& extensions, | 1092 const std::vector<webrtc::RtpExtension>& extensions, |
| 1157 webrtc::Call* call, | 1093 webrtc::Call* call, |
| (...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2680 } | 2616 } |
| 2681 } else { | 2617 } else { |
| 2682 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2618 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
| 2683 engine()->voe()->base()->StopPlayout(channel); | 2619 engine()->voe()->base()->StopPlayout(channel); |
| 2684 } | 2620 } |
| 2685 return true; | 2621 return true; |
| 2686 } | 2622 } |
| 2687 } // namespace cricket | 2623 } // namespace cricket |
| 2688 | 2624 |
| 2689 #endif // HAVE_WEBRTC_VOICE | 2625 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |