Move updating nack bitrate inside UpdateNACKBitRate.

BUG=
R=pbos@webrtc.org, stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/32819004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7960 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org 2014-12-19 09:52:24 +00:00
parent 5647877b2d
commit 11d8176cb3
2 changed files with 13 additions and 25 deletions

View File

@ -726,7 +726,7 @@ void RTPSender::OnReceivedNACK(
TRACE_EVENT2("webrtc_rtp", "RTPSender::OnReceivedNACK", TRACE_EVENT2("webrtc_rtp", "RTPSender::OnReceivedNACK",
"num_seqnum", nack_sequence_numbers.size(), "avg_rtt", avg_rtt); "num_seqnum", nack_sequence_numbers.size(), "avg_rtt", avg_rtt);
const int64_t now = clock_->TimeInMilliseconds(); const int64_t now = clock_->TimeInMilliseconds();
size_t bytes_re_sent = 0; uint32_t bytes_re_sent = 0;
uint32_t target_bitrate = GetTargetBitrate(); uint32_t target_bitrate = GetTargetBitrate();
// Enough bandwidth to send NACK? // Enough bandwidth to send NACK?
@ -745,7 +745,7 @@ void RTPSender::OnReceivedNACK(
// The packet has previously been resent. // The packet has previously been resent.
// Try resending next packet in the list. // Try resending next packet in the list.
continue; continue;
} else if (bytes_sent < 0) { } else {
// Failed to send one Sequence number. Give up the rest in this nack. // Failed to send one Sequence number. Give up the rest in this nack.
LOG(LS_WARNING) << "Failed resending RTP packet " << *it LOG(LS_WARNING) << "Failed resending RTP packet " << *it
<< ", Discard rest of packets"; << ", Discard rest of packets";
@ -762,9 +762,7 @@ void RTPSender::OnReceivedNACK(
} }
} }
if (bytes_re_sent > 0) { if (bytes_re_sent > 0) {
// TODO(pwestin) consolidate these two methods.
UpdateNACKBitRate(bytes_re_sent, now); UpdateNACKBitRate(bytes_re_sent, now);
nack_bitrate_.Update(bytes_re_sent);
} }
} }
@ -798,29 +796,19 @@ bool RTPSender::ProcessNACKBitRate(const uint32_t now) {
return (byte_count * 8) < (target_bitrate / 1000 * time_interval); return (byte_count * 8) < (target_bitrate / 1000 * time_interval);
} }
void RTPSender::UpdateNACKBitRate(const size_t bytes, void RTPSender::UpdateNACKBitRate(uint32_t bytes, int64_t now) {
const uint32_t now) {
CriticalSectionScoped cs(send_critsect_); CriticalSectionScoped cs(send_critsect_);
if (bytes == 0)
return;
nack_bitrate_.Update(bytes);
// Save bitrate statistics. // Save bitrate statistics.
if (bytes > 0) { // Shift all but first time.
if (now == 0) { for (int i = NACK_BYTECOUNT_SIZE - 2; i >= 0; i--) {
// Add padding length. nack_byte_count_[i + 1] = nack_byte_count_[i];
nack_byte_count_[0] += bytes; nack_byte_count_times_[i + 1] = nack_byte_count_times_[i];
} else {
if (nack_byte_count_times_[0] == 0) {
// First no shift.
} else {
// Shift.
for (int i = (NACK_BYTECOUNT_SIZE - 2); i >= 0; i--) {
nack_byte_count_[i + 1] = nack_byte_count_[i];
nack_byte_count_times_[i + 1] = nack_byte_count_times_[i];
}
}
nack_byte_count_[0] = bytes;
nack_byte_count_times_[0] = now;
}
} }
nack_byte_count_[0] = bytes;
nack_byte_count_times_[0] = now;
} }
// Called from pacer when we can send the packet. // Called from pacer when we can send the packet.

View File

@ -295,7 +295,7 @@ class RTPSender : public RTPSenderInterface {
uint16_t sequence_number, uint16_t sequence_number,
const std::vector<uint32_t>& csrcs) const; const std::vector<uint32_t>& csrcs) const;
void UpdateNACKBitRate(const size_t bytes, const uint32_t now); void UpdateNACKBitRate(uint32_t bytes, int64_t now);
bool PrepareAndSendPacket(uint8_t* buffer, bool PrepareAndSendPacket(uint8_t* buffer,
size_t length, size_t length,