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 const std::vector<webrtc::SdpAudioFormat>& formats = | |
1087 decoder_factory_->GetSupportedFormats(); | |
1088 | |
1089 // Only generate CN payload types for these clockrates | |
1090 std::map<int, bool, std::greater<int>> generate_cn = {{ 8000, false }, | |
1091 { 16000, false }, | |
1092 { 32000, false }}; | |
1093 | |
1094 auto map_format = [&mapper, &out] (const webrtc::SdpAudioFormat& format) { | |
1095 rtc::Optional<AudioCodec> opt_codec = mapper.ToAudioCodec(format); | |
1096 if (!opt_codec) { | |
1097 LOG(LS_ERROR) << "Unable to assign payload type to format: " << format; | |
1098 return false; | |
1099 } | |
1100 | |
1101 auto& codec = *opt_codec; | |
1102 if (IsCodec(codec, kOpusCodecName)) { | |
1103 // TODO(ossu): Set this specifically for Opus for now, until we have a | |
1104 // better way of dealing with rtcp-fb parameters. | |
1105 codec.AddFeedbackParam( | |
1106 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); | |
1107 } | |
1108 out.push_back(codec); | |
1109 return true; | |
1110 }; | |
1111 | |
1112 for (const auto& format : formats) { | |
1113 if (map_format(format)) { | |
1114 // TODO(ossu): We should get more than just a format from the factory, so | |
1115 // we can determine if a format should be used with CN or not. For now, | |
1116 // generate a CN entry for each supported clock rate also used by a format | |
1117 // supported by the factory. | |
1118 auto cn = generate_cn.find(format.clockrate_hz); | |
1119 if (cn != generate_cn.end() /* && format.allow_comfort_noise */) { | |
1120 cn->second = true; | |
1121 } | |
1122 } | |
1123 } | |
1124 | |
1125 // Add CN codecs after "proper" audio codecs | |
ossu
2016/07/12 15:49:49
I put these back after all the regular codecs, and
| |
1126 for (const auto& cn : generate_cn) { | |
1127 if (cn.second) { | |
1128 map_format({kCnCodecName, cn.first, 1}); | |
1129 } | |
1130 } | |
1131 | |
1132 // Add telephone-event codec last | |
1133 map_format({kDtmfCodecName, 8000, 1}); | |
1134 | |
1135 return out; | |
1136 } | |
1137 | |
1075 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream | 1138 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
1076 : public AudioSource::Sink { | 1139 : public AudioSource::Sink { |
1077 public: | 1140 public: |
1078 WebRtcAudioSendStream(int ch, | 1141 WebRtcAudioSendStream(int ch, |
1079 webrtc::AudioTransport* voe_audio_transport, | 1142 webrtc::AudioTransport* voe_audio_transport, |
1080 uint32_t ssrc, | 1143 uint32_t ssrc, |
1081 const std::string& c_name, | 1144 const std::string& c_name, |
1082 const SendCodecSpec& send_codec_spec, | 1145 const SendCodecSpec& send_codec_spec, |
1083 const std::vector<webrtc::RtpExtension>& extensions, | 1146 const std::vector<webrtc::RtpExtension>& extensions, |
1084 webrtc::Call* call, | 1147 webrtc::Call* call, |
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2607 } | 2670 } |
2608 } else { | 2671 } else { |
2609 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2672 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
2610 engine()->voe()->base()->StopPlayout(channel); | 2673 engine()->voe()->base()->StopPlayout(channel); |
2611 } | 2674 } |
2612 return true; | 2675 return true; |
2613 } | 2676 } |
2614 } // namespace cricket | 2677 } // namespace cricket |
2615 | 2678 |
2616 #endif // HAVE_WEBRTC_VOICE | 2679 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |