OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 #include "webrtc/voice_engine/channel.h" | 11 #include "webrtc/voice_engine/channel.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
18 #include "webrtc/base/format_macros.h" | 18 #include "webrtc/base/format_macros.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 20 #include "webrtc/base/rate_limiter.h" |
20 #include "webrtc/base/thread_checker.h" | 21 #include "webrtc/base/thread_checker.h" |
21 #include "webrtc/base/timeutils.h" | 22 #include "webrtc/base/timeutils.h" |
22 #include "webrtc/call/rtc_event_log.h" | 23 #include "webrtc/call/rtc_event_log.h" |
23 #include "webrtc/common.h" | 24 #include "webrtc/common.h" |
24 #include "webrtc/config.h" | 25 #include "webrtc/config.h" |
25 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" | 26 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" |
26 #include "webrtc/modules/audio_device/include/audio_device.h" | 27 #include "webrtc/modules/audio_device/include/audio_device.h" |
27 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 28 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
28 #include "webrtc/modules/include/module_common_types.h" | 29 #include "webrtc/modules/include/module_common_types.h" |
29 #include "webrtc/modules/pacing/packet_router.h" | 30 #include "webrtc/modules/pacing/packet_router.h" |
(...skipping 10 matching lines...) Expand all Loading... |
40 #include "webrtc/voice_engine/output_mixer.h" | 41 #include "webrtc/voice_engine/output_mixer.h" |
41 #include "webrtc/voice_engine/statistics.h" | 42 #include "webrtc/voice_engine/statistics.h" |
42 #include "webrtc/voice_engine/transmit_mixer.h" | 43 #include "webrtc/voice_engine/transmit_mixer.h" |
43 #include "webrtc/voice_engine/utility.h" | 44 #include "webrtc/voice_engine/utility.h" |
44 | 45 |
45 namespace webrtc { | 46 namespace webrtc { |
46 namespace voe { | 47 namespace voe { |
47 | 48 |
48 namespace { | 49 namespace { |
49 | 50 |
| 51 constexpr int64_t kMaxRetransmissionWindowMs = 1000; |
| 52 constexpr int64_t kMinRetransmissionWindowMs = 30; |
| 53 |
50 bool RegisterReceiveCodec(std::unique_ptr<AudioCodingModule>* acm, | 54 bool RegisterReceiveCodec(std::unique_ptr<AudioCodingModule>* acm, |
51 acm2::RentACodec* rac, | 55 acm2::RentACodec* rac, |
52 const CodecInst& ci) { | 56 const CodecInst& ci) { |
53 const int result = (*acm)->RegisterReceiveCodec( | 57 const int result = (*acm)->RegisterReceiveCodec( |
54 ci, [&] { return rac->RentIsacDecoder(ci.plfreq); }); | 58 ci, [&] { return rac->RentIsacDecoder(ci.plfreq); }); |
55 return result == 0; | 59 return result == 0; |
56 } | 60 } |
57 | 61 |
58 } // namespace | 62 } // namespace |
59 | 63 |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 _rxAgcIsEnabled(false), | 899 _rxAgcIsEnabled(false), |
896 _rxNsIsEnabled(false), | 900 _rxNsIsEnabled(false), |
897 restored_packet_in_use_(false), | 901 restored_packet_in_use_(false), |
898 rtcp_observer_(new VoERtcpObserver(this)), | 902 rtcp_observer_(new VoERtcpObserver(this)), |
899 network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), | 903 network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), |
900 associate_send_channel_(ChannelOwner(nullptr)), | 904 associate_send_channel_(ChannelOwner(nullptr)), |
901 pacing_enabled_(config.Get<VoicePacing>().enabled), | 905 pacing_enabled_(config.Get<VoicePacing>().enabled), |
902 feedback_observer_proxy_(new TransportFeedbackProxy()), | 906 feedback_observer_proxy_(new TransportFeedbackProxy()), |
903 seq_num_allocator_proxy_(new TransportSequenceNumberProxy()), | 907 seq_num_allocator_proxy_(new TransportSequenceNumberProxy()), |
904 rtp_packet_sender_proxy_(new RtpPacketSenderProxy()), | 908 rtp_packet_sender_proxy_(new RtpPacketSenderProxy()), |
| 909 retransmission_rate_limiter_(new RateLimiter(Clock::GetRealTimeClock(), |
| 910 kMaxRetransmissionWindowMs)), |
905 decoder_factory_(decoder_factory) { | 911 decoder_factory_(decoder_factory) { |
906 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), | 912 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), |
907 "Channel::Channel() - ctor"); | 913 "Channel::Channel() - ctor"); |
908 AudioCodingModule::Config acm_config; | 914 AudioCodingModule::Config acm_config; |
909 acm_config.id = VoEModuleId(instanceId, channelId); | 915 acm_config.id = VoEModuleId(instanceId, channelId); |
910 if (config.Get<NetEqCapacityConfig>().enabled) { | 916 if (config.Get<NetEqCapacityConfig>().enabled) { |
911 // Clamping the buffer capacity at 20 packets. While going lower will | 917 // Clamping the buffer capacity at 20 packets. While going lower will |
912 // probably work, it makes little sense. | 918 // probably work, it makes little sense. |
913 acm_config.neteq_config.max_packets_in_buffer = | 919 acm_config.neteq_config.max_packets_in_buffer = |
914 std::max(20, config.Get<NetEqCapacityConfig>().capacity); | 920 std::max(20, config.Get<NetEqCapacityConfig>().capacity); |
(...skipping 11 matching lines...) Expand all Loading... |
926 configuration.outgoing_transport = this; | 932 configuration.outgoing_transport = this; |
927 configuration.receive_statistics = rtp_receive_statistics_.get(); | 933 configuration.receive_statistics = rtp_receive_statistics_.get(); |
928 configuration.bandwidth_callback = rtcp_observer_.get(); | 934 configuration.bandwidth_callback = rtcp_observer_.get(); |
929 if (pacing_enabled_) { | 935 if (pacing_enabled_) { |
930 configuration.paced_sender = rtp_packet_sender_proxy_.get(); | 936 configuration.paced_sender = rtp_packet_sender_proxy_.get(); |
931 configuration.transport_sequence_number_allocator = | 937 configuration.transport_sequence_number_allocator = |
932 seq_num_allocator_proxy_.get(); | 938 seq_num_allocator_proxy_.get(); |
933 configuration.transport_feedback_callback = feedback_observer_proxy_.get(); | 939 configuration.transport_feedback_callback = feedback_observer_proxy_.get(); |
934 } | 940 } |
935 configuration.event_log = &(*event_log_proxy_); | 941 configuration.event_log = &(*event_log_proxy_); |
| 942 configuration.retransmission_rate_limiter = |
| 943 retransmission_rate_limiter_.get(); |
936 | 944 |
937 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); | 945 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
938 _rtpRtcpModule->SetSendingMediaStatus(false); | 946 _rtpRtcpModule->SetSendingMediaStatus(false); |
939 | 947 |
940 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); | 948 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); |
941 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( | 949 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( |
942 statistics_proxy_.get()); | 950 statistics_proxy_.get()); |
943 | 951 |
944 Config audioproc_config; | 952 Config audioproc_config; |
945 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); | 953 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 return -1; | 1353 return -1; |
1346 } | 1354 } |
1347 | 1355 |
1348 return 0; | 1356 return 0; |
1349 } | 1357 } |
1350 | 1358 |
1351 void Channel::SetBitRate(int bitrate_bps) { | 1359 void Channel::SetBitRate(int bitrate_bps) { |
1352 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), | 1360 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), |
1353 "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); | 1361 "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); |
1354 audio_coding_->SetBitRate(bitrate_bps); | 1362 audio_coding_->SetBitRate(bitrate_bps); |
| 1363 retransmission_rate_limiter_->SetMaxRate(bitrate_bps); |
1355 } | 1364 } |
1356 | 1365 |
1357 void Channel::OnIncomingFractionLoss(int fraction_lost) { | 1366 void Channel::OnIncomingFractionLoss(int fraction_lost) { |
1358 network_predictor_->UpdatePacketLossRate(fraction_lost); | 1367 network_predictor_->UpdatePacketLossRate(fraction_lost); |
1359 uint8_t average_fraction_loss = network_predictor_->GetLossRate(); | 1368 uint8_t average_fraction_loss = network_predictor_->GetLossRate(); |
1360 | 1369 |
1361 // Normalizes rate to 0 - 100. | 1370 // Normalizes rate to 0 - 100. |
1362 if (audio_coding_->SetPacketLossRate(100 * average_fraction_loss / 255) != | 1371 if (audio_coding_->SetPacketLossRate(100 * average_fraction_loss / 255) != |
1363 0) { | 1372 0) { |
1364 assert(false); // This should not happen. | 1373 assert(false); // This should not happen. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 _engineStatisticsPtr->SetLastError( | 1712 _engineStatisticsPtr->SetLastError( |
1704 VE_SOCKET_TRANSPORT_MODULE_ERROR, kTraceWarning, | 1713 VE_SOCKET_TRANSPORT_MODULE_ERROR, kTraceWarning, |
1705 "Channel::IncomingRTPPacket() RTCP packet is invalid"); | 1714 "Channel::IncomingRTPPacket() RTCP packet is invalid"); |
1706 } | 1715 } |
1707 | 1716 |
1708 int64_t rtt = GetRTT(true); | 1717 int64_t rtt = GetRTT(true); |
1709 if (rtt == 0) { | 1718 if (rtt == 0) { |
1710 // Waiting for valid RTT. | 1719 // Waiting for valid RTT. |
1711 return 0; | 1720 return 0; |
1712 } | 1721 } |
| 1722 |
| 1723 int64_t nack_window_ms = rtt; |
| 1724 if (nack_window_ms < kMinRetransmissionWindowMs) { |
| 1725 nack_window_ms = kMinRetransmissionWindowMs; |
| 1726 } else if (nack_window_ms > kMaxRetransmissionWindowMs) { |
| 1727 nack_window_ms = kMaxRetransmissionWindowMs; |
| 1728 } |
| 1729 retransmission_rate_limiter_->SetWindowSize(nack_window_ms); |
| 1730 |
1713 uint32_t ntp_secs = 0; | 1731 uint32_t ntp_secs = 0; |
1714 uint32_t ntp_frac = 0; | 1732 uint32_t ntp_frac = 0; |
1715 uint32_t rtp_timestamp = 0; | 1733 uint32_t rtp_timestamp = 0; |
1716 if (0 != | 1734 if (0 != |
1717 _rtpRtcpModule->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL, | 1735 _rtpRtcpModule->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL, |
1718 &rtp_timestamp)) { | 1736 &rtp_timestamp)) { |
1719 // Waiting for RTCP. | 1737 // Waiting for RTCP. |
1720 return 0; | 1738 return 0; |
1721 } | 1739 } |
1722 | 1740 |
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3573 int64_t min_rtt = 0; | 3591 int64_t min_rtt = 0; |
3574 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != | 3592 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != |
3575 0) { | 3593 0) { |
3576 return 0; | 3594 return 0; |
3577 } | 3595 } |
3578 return rtt; | 3596 return rtt; |
3579 } | 3597 } |
3580 | 3598 |
3581 } // namespace voe | 3599 } // namespace voe |
3582 } // namespace webrtc | 3600 } // namespace webrtc |
OLD | NEW |