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/common.h" | 32 #include "webrtc/common.h" |
32 #include "webrtc/media/base/audiosource.h" | 33 #include "webrtc/media/base/audiosource.h" |
33 #include "webrtc/media/base/mediaconstants.h" | 34 #include "webrtc/media/base/mediaconstants.h" |
34 #include "webrtc/media/base/streamparams.h" | 35 #include "webrtc/media/base/streamparams.h" |
| 36 #include "webrtc/media/engine/payload_type_mapper.h" |
35 #include "webrtc/media/engine/webrtcmediaengine.h" | 37 #include "webrtc/media/engine/webrtcmediaengine.h" |
36 #include "webrtc/media/engine/webrtcvoe.h" | 38 #include "webrtc/media/engine/webrtcvoe.h" |
37 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | 39 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" |
38 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 40 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
39 #include "webrtc/system_wrappers/include/field_trial.h" | 41 #include "webrtc/system_wrappers/include/field_trial.h" |
40 #include "webrtc/system_wrappers/include/trace.h" | 42 #include "webrtc/system_wrappers/include/trace.h" |
41 | 43 |
42 namespace cricket { | 44 namespace cricket { |
43 namespace { | 45 namespace { |
44 | 46 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { | 243 webrtc::AudioState::Config MakeAudioStateConfig(VoEWrapper* voe_wrapper) { |
242 webrtc::AudioState::Config config; | 244 webrtc::AudioState::Config config; |
243 config.voice_engine = voe_wrapper->engine(); | 245 config.voice_engine = voe_wrapper->engine(); |
244 return config; | 246 return config; |
245 } | 247 } |
246 | 248 |
247 class WebRtcVoiceCodecs final { | 249 class WebRtcVoiceCodecs final { |
248 public: | 250 public: |
249 // 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 |
250 // 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. |
251 static std::vector<AudioCodec> SupportedCodecs() { | 253 static std::vector<AudioCodec> SupportedSendCodecs() { |
252 std::vector<AudioCodec> result; | 254 std::vector<AudioCodec> result; |
253 // 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 |
254 // added in order of preference. | 256 // added in order of preference. |
255 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { | 257 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { |
256 const CodecPref* pref = &kCodecPrefs[i]; | 258 const CodecPref* pref = &kCodecPrefs[i]; |
257 for (webrtc::CodecInst voe_codec : webrtc::acm2::RentACodec::Database()) { | 259 for (webrtc::CodecInst voe_codec : webrtc::acm2::RentACodec::Database()) { |
258 // Change the sample rate of G722 to 8000 to match SDP. | 260 // Change the sample rate of G722 to 8000 to match SDP. |
259 MaybeFixupG722(&voe_codec, 8000); | 261 MaybeFixupG722(&voe_codec, 8000); |
260 // Skip uncompressed formats. | 262 // Skip uncompressed formats. |
261 if (IsCodec(voe_codec, kL16CodecName)) { | 263 if (IsCodec(voe_codec, kL16CodecName)) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } | 506 } |
505 | 507 |
506 WebRtcVoiceEngine::WebRtcVoiceEngine( | 508 WebRtcVoiceEngine::WebRtcVoiceEngine( |
507 webrtc::AudioDeviceModule* adm, | 509 webrtc::AudioDeviceModule* adm, |
508 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory, | 510 const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory, |
509 VoEWrapper* voe_wrapper) | 511 VoEWrapper* voe_wrapper) |
510 : adm_(adm), decoder_factory_(decoder_factory), voe_wrapper_(voe_wrapper) { | 512 : adm_(adm), decoder_factory_(decoder_factory), voe_wrapper_(voe_wrapper) { |
511 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 513 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
512 LOG(LS_INFO) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; | 514 LOG(LS_INFO) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; |
513 RTC_DCHECK(voe_wrapper); | 515 RTC_DCHECK(voe_wrapper); |
| 516 RTC_DCHECK(decoder_factory); |
514 | 517 |
515 signal_thread_checker_.DetachFromThread(); | 518 signal_thread_checker_.DetachFromThread(); |
516 | 519 |
517 // Load our audio codec list. | 520 // Load our audio codec list. |
518 LOG(LS_INFO) << "Supported codecs in order of preference:"; | 521 LOG(LS_INFO) << "Supported send codecs in order of preference:"; |
519 codecs_ = WebRtcVoiceCodecs::SupportedCodecs(); | 522 send_codecs_ = WebRtcVoiceCodecs::SupportedSendCodecs(); |
520 for (const AudioCodec& codec : codecs_) { | 523 for (const AudioCodec& codec : send_codecs_) { |
521 LOG(LS_INFO) << ToString(codec); | 524 LOG(LS_INFO) << ToString(codec); |
522 } | 525 } |
523 | 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 |
524 voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true)); | 533 voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true)); |
525 | 534 |
526 // Temporarily turn logging level up for the Init() call. | 535 // Temporarily turn logging level up for the Init() call. |
527 webrtc::Trace::SetTraceCallback(this); | 536 webrtc::Trace::SetTraceCallback(this); |
528 webrtc::Trace::set_level_filter(kElevatedTraceFilter); | 537 webrtc::Trace::set_level_filter(kElevatedTraceFilter); |
529 LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString(); | 538 LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString(); |
530 RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get(), nullptr, | 539 RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get(), nullptr, |
531 decoder_factory_)); | 540 decoder_factory_)); |
532 webrtc::Trace::set_level_filter(kDefaultTraceFilter); | 541 webrtc::Trace::set_level_filter(kDefaultTraceFilter); |
533 | 542 |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 | 938 |
930 int WebRtcVoiceEngine::GetInputLevel() { | 939 int WebRtcVoiceEngine::GetInputLevel() { |
931 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 940 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
932 unsigned int ulevel; | 941 unsigned int ulevel; |
933 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? | 942 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? |
934 static_cast<int>(ulevel) : -1; | 943 static_cast<int>(ulevel) : -1; |
935 } | 944 } |
936 | 945 |
937 const std::vector<AudioCodec>& WebRtcVoiceEngine::send_codecs() const { | 946 const std::vector<AudioCodec>& WebRtcVoiceEngine::send_codecs() const { |
938 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 947 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
939 return codecs_; | 948 return send_codecs_; |
940 } | 949 } |
941 | 950 |
942 const std::vector<AudioCodec>& WebRtcVoiceEngine::recv_codecs() const { | 951 const std::vector<AudioCodec>& WebRtcVoiceEngine::recv_codecs() const { |
943 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 952 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
944 return codecs_; | 953 return recv_codecs_; |
945 } | 954 } |
946 | 955 |
947 RtpCapabilities WebRtcVoiceEngine::GetCapabilities() const { | 956 RtpCapabilities WebRtcVoiceEngine::GetCapabilities() const { |
948 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | 957 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); |
949 RtpCapabilities capabilities; | 958 RtpCapabilities capabilities; |
950 capabilities.header_extensions.push_back( | 959 capabilities.header_extensions.push_back( |
951 webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri, | 960 webrtc::RtpExtension(webrtc::RtpExtension::kAudioLevelUri, |
952 webrtc::RtpExtension::kAudioLevelDefaultId)); | 961 webrtc::RtpExtension::kAudioLevelDefaultId)); |
953 capabilities.header_extensions.push_back( | 962 capabilities.header_extensions.push_back( |
954 webrtc::RtpExtension(webrtc::RtpExtension::kAbsSendTimeUri, | 963 webrtc::RtpExtension(webrtc::RtpExtension::kAbsSendTimeUri, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1083 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1075 return voe_wrapper_->base()->CreateChannel(voe_config_); | 1084 return voe_wrapper_->base()->CreateChannel(voe_config_); |
1076 } | 1085 } |
1077 | 1086 |
1078 webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { | 1087 webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { |
1079 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1088 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1080 RTC_DCHECK(adm_); | 1089 RTC_DCHECK(adm_); |
1081 return adm_; | 1090 return adm_; |
1082 } | 1091 } |
1083 | 1092 |
| 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 |
1084 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream | 1148 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
1085 : public AudioSource::Sink { | 1149 : public AudioSource::Sink { |
1086 public: | 1150 public: |
1087 WebRtcAudioSendStream(int ch, | 1151 WebRtcAudioSendStream(int ch, |
1088 webrtc::AudioTransport* voe_audio_transport, | 1152 webrtc::AudioTransport* voe_audio_transport, |
1089 uint32_t ssrc, | 1153 uint32_t ssrc, |
1090 const std::string& c_name, | 1154 const std::string& c_name, |
1091 const SendCodecSpec& send_codec_spec, | 1155 const SendCodecSpec& send_codec_spec, |
1092 const std::vector<webrtc::RtpExtension>& extensions, | 1156 const std::vector<webrtc::RtpExtension>& extensions, |
1093 webrtc::Call* call, | 1157 webrtc::Call* call, |
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2616 } | 2680 } |
2617 } else { | 2681 } else { |
2618 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2682 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
2619 engine()->voe()->base()->StopPlayout(channel); | 2683 engine()->voe()->base()->StopPlayout(channel); |
2620 } | 2684 } |
2621 return true; | 2685 return true; |
2622 } | 2686 } |
2623 } // namespace cricket | 2687 } // namespace cricket |
2624 | 2688 |
2625 #endif // HAVE_WEBRTC_VOICE | 2689 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |