Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: webrtc/voice_engine/channel.cc

Issue 2181383002: Add NACK rate throttling for audio channels. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 kMaxRetranmissionWindowMs = 1000;
52 constexpr int64_t kMinRetranmissionWindowMs = 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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 return -1; 531 return -1;
528 } 532 }
529 533
530 // Update the packet delay. 534 // Update the packet delay.
531 UpdatePacketDelay(rtpHeader->header.timestamp, 535 UpdatePacketDelay(rtpHeader->header.timestamp,
532 rtpHeader->header.sequenceNumber); 536 rtpHeader->header.sequenceNumber);
533 537
534 int64_t round_trip_time = 0; 538 int64_t round_trip_time = 0;
535 _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, NULL, NULL, 539 _rtpRtcpModule->RTT(rtp_receiver_->SSRC(), &round_trip_time, NULL, NULL,
536 NULL); 540 NULL);
541 int64_t nack_window_ms = round_trip_time;
542 if (nack_window_ms < kMinRetranmissionWindowMs) {
543 nack_window_ms = kMinRetranmissionWindowMs;
544 } else if (nack_window_ms > kMaxRetranmissionWindowMs) {
545 nack_window_ms = kMaxRetranmissionWindowMs;
546 }
547 nack_rate_limiter_->SetWindowSize(nack_window_ms);
stefan-webrtc 2016/07/28 07:27:38 This seems like a slightly odd place for this. Wou
minyue-webrtc 2016/07/28 08:17:27 It might be good to put in VoERtcpObserver
sprang_webrtc 2016/07/28 13:00:58 Done.
537 548
538 std::vector<uint16_t> nack_list = audio_coding_->GetNackList(round_trip_time); 549 std::vector<uint16_t> nack_list = audio_coding_->GetNackList(round_trip_time);
539 if (!nack_list.empty()) { 550 if (!nack_list.empty()) {
540 // Can't use nack_list.data() since it's not supported by all 551 // Can't use nack_list.data() since it's not supported by all
541 // compilers. 552 // compilers.
542 ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size())); 553 ResendPackets(&(nack_list[0]), static_cast<int>(nack_list.size()));
543 } 554 }
544 return 0; 555 return 0;
545 } 556 }
546 557
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 _rxAgcIsEnabled(false), 906 _rxAgcIsEnabled(false),
896 _rxNsIsEnabled(false), 907 _rxNsIsEnabled(false),
897 restored_packet_in_use_(false), 908 restored_packet_in_use_(false),
898 rtcp_observer_(new VoERtcpObserver(this)), 909 rtcp_observer_(new VoERtcpObserver(this)),
899 network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), 910 network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())),
900 associate_send_channel_(ChannelOwner(nullptr)), 911 associate_send_channel_(ChannelOwner(nullptr)),
901 pacing_enabled_(config.Get<VoicePacing>().enabled), 912 pacing_enabled_(config.Get<VoicePacing>().enabled),
902 feedback_observer_proxy_(new TransportFeedbackProxy()), 913 feedback_observer_proxy_(new TransportFeedbackProxy()),
903 seq_num_allocator_proxy_(new TransportSequenceNumberProxy()), 914 seq_num_allocator_proxy_(new TransportSequenceNumberProxy()),
904 rtp_packet_sender_proxy_(new RtpPacketSenderProxy()), 915 rtp_packet_sender_proxy_(new RtpPacketSenderProxy()),
916 nack_rate_limiter_(new RateLimiter(Clock::GetRealTimeClock(),
917 kMaxRetranmissionWindowMs)),
905 decoder_factory_(decoder_factory) { 918 decoder_factory_(decoder_factory) {
906 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId), 919 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId),
907 "Channel::Channel() - ctor"); 920 "Channel::Channel() - ctor");
908 AudioCodingModule::Config acm_config; 921 AudioCodingModule::Config acm_config;
909 acm_config.id = VoEModuleId(instanceId, channelId); 922 acm_config.id = VoEModuleId(instanceId, channelId);
910 if (config.Get<NetEqCapacityConfig>().enabled) { 923 if (config.Get<NetEqCapacityConfig>().enabled) {
911 // Clamping the buffer capacity at 20 packets. While going lower will 924 // Clamping the buffer capacity at 20 packets. While going lower will
912 // probably work, it makes little sense. 925 // probably work, it makes little sense.
913 acm_config.neteq_config.max_packets_in_buffer = 926 acm_config.neteq_config.max_packets_in_buffer =
914 std::max(20, config.Get<NetEqCapacityConfig>().capacity); 927 std::max(20, config.Get<NetEqCapacityConfig>().capacity);
(...skipping 11 matching lines...) Expand all
926 configuration.outgoing_transport = this; 939 configuration.outgoing_transport = this;
927 configuration.receive_statistics = rtp_receive_statistics_.get(); 940 configuration.receive_statistics = rtp_receive_statistics_.get();
928 configuration.bandwidth_callback = rtcp_observer_.get(); 941 configuration.bandwidth_callback = rtcp_observer_.get();
929 if (pacing_enabled_) { 942 if (pacing_enabled_) {
930 configuration.paced_sender = rtp_packet_sender_proxy_.get(); 943 configuration.paced_sender = rtp_packet_sender_proxy_.get();
931 configuration.transport_sequence_number_allocator = 944 configuration.transport_sequence_number_allocator =
932 seq_num_allocator_proxy_.get(); 945 seq_num_allocator_proxy_.get();
933 configuration.transport_feedback_callback = feedback_observer_proxy_.get(); 946 configuration.transport_feedback_callback = feedback_observer_proxy_.get();
934 } 947 }
935 configuration.event_log = &(*event_log_proxy_); 948 configuration.event_log = &(*event_log_proxy_);
949 configuration.retransmission_rate_limiter = nack_rate_limiter_.get();
stefan-webrtc 2016/07/28 07:27:38 should we rename it retransmission_rate_limiter_ i
sprang_webrtc 2016/07/28 13:00:58 Done.
936 950
937 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); 951 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration));
938 _rtpRtcpModule->SetSendingMediaStatus(false); 952 _rtpRtcpModule->SetSendingMediaStatus(false);
939 953
940 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); 954 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC()));
941 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( 955 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(
942 statistics_proxy_.get()); 956 statistics_proxy_.get());
943 957
944 Config audioproc_config; 958 Config audioproc_config;
945 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); 959 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 return -1; 1359 return -1;
1346 } 1360 }
1347 1361
1348 return 0; 1362 return 0;
1349 } 1363 }
1350 1364
1351 void Channel::SetBitRate(int bitrate_bps) { 1365 void Channel::SetBitRate(int bitrate_bps) {
1352 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), 1366 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
1353 "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps); 1367 "Channel::SetBitRate(bitrate_bps=%d)", bitrate_bps);
1354 audio_coding_->SetBitRate(bitrate_bps); 1368 audio_coding_->SetBitRate(bitrate_bps);
1369 nack_rate_limiter_->SetMaxRate(bitrate_bps);
stefan-webrtc 2016/07/28 07:27:38 What will the default be if this is never called?
sprang_webrtc 2016/07/28 13:00:58 Rate limit defaults to maxint, so always allows re
stefan-webrtc 2016/07/28 15:06:15 Acknowledged.
1355 } 1370 }
1356 1371
1357 void Channel::OnIncomingFractionLoss(int fraction_lost) { 1372 void Channel::OnIncomingFractionLoss(int fraction_lost) {
1358 network_predictor_->UpdatePacketLossRate(fraction_lost); 1373 network_predictor_->UpdatePacketLossRate(fraction_lost);
1359 uint8_t average_fraction_loss = network_predictor_->GetLossRate(); 1374 uint8_t average_fraction_loss = network_predictor_->GetLossRate();
1360 1375
1361 // Normalizes rate to 0 - 100. 1376 // Normalizes rate to 0 - 100.
1362 if (audio_coding_->SetPacketLossRate(100 * average_fraction_loss / 255) != 1377 if (audio_coding_->SetPacketLossRate(100 * average_fraction_loss / 255) !=
1363 0) { 1378 0) {
1364 assert(false); // This should not happen. 1379 assert(false); // This should not happen.
(...skipping 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after
3562 int64_t min_rtt = 0; 3577 int64_t min_rtt = 0;
3563 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != 3578 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) !=
3564 0) { 3579 0) {
3565 return 0; 3580 return 0;
3566 } 3581 }
3567 return rtt; 3582 return rtt;
3568 } 3583 }
3569 3584
3570 } // namespace voe 3585 } // namespace voe
3571 } // namespace webrtc 3586 } // namespace webrtc
OLDNEW
« webrtc/video/end_to_end_tests.cc ('K') | « webrtc/voice_engine/channel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698