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

Unified Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.cc

Issue 2028543002: [rtcp] Nack::Parse updated not to use RTCPUtility (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase & nit Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.cc
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.cc
index 8b9b354a0601067d1c4811a9bd10e1dd97df60df..0c1f577f7b7ba062578af9dcd1d57a5f3f3e41f5 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.cc
@@ -15,12 +15,12 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
-
-using webrtc::RTCPUtility::RtcpCommonHeader;
+#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
namespace webrtc {
namespace rtcp {
-
+constexpr uint8_t Nack::kFeedbackMessageType;
+constexpr size_t Nack::kNackItemLength;
// RFC 4585: Feedback format.
//
// Common packet format:
@@ -45,20 +45,23 @@ namespace rtcp {
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | PID | BLP |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-bool Nack::Parse(const RtcpCommonHeader& header, const uint8_t* payload) {
- RTC_DCHECK(header.packet_type == kPacketType);
- RTC_DCHECK(header.count_or_format == kFeedbackMessageType);
+Nack::Nack() {}
+Nack::~Nack() {}
- if (header.payload_size_bytes < kCommonFeedbackLength + kNackItemLength) {
- LOG(LS_WARNING) << "Payload length " << header.payload_size_bytes
+bool Nack::Parse(const CommonHeader& packet) {
+ RTC_DCHECK_EQ(packet.type(), kPacketType);
+ RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
+
+ if (packet.payload_size_bytes() < kCommonFeedbackLength + kNackItemLength) {
+ LOG(LS_WARNING) << "Payload length " << packet.payload_size_bytes()
<< " is too small for a Nack.";
return false;
}
size_t nack_items =
- (header.payload_size_bytes - kCommonFeedbackLength) / kNackItemLength;
+ (packet.payload_size_bytes() - kCommonFeedbackLength) / kNackItemLength;
- ParseCommonFeedback(payload);
- const uint8_t* next_nack = payload + kCommonFeedbackLength;
+ ParseCommonFeedback(packet.payload());
+ const uint8_t* next_nack = packet.payload() + kCommonFeedbackLength;
packet_ids_.clear();
packed_.resize(nack_items);
@@ -78,42 +81,44 @@ bool Nack::Create(uint8_t* packet,
RtcpPacket::PacketReadyCallback* callback) const {
RTC_DCHECK(!packed_.empty());
// If nack list can't fit in packet, try to fragment.
- size_t nack_index = 0;
- const size_t kCommonFbFmtLength = kHeaderLength + kCommonFeedbackLength;
- do {
+ constexpr size_t kNackHeaderLength = kHeaderLength + kCommonFeedbackLength;
+ for (size_t nack_index = 0; nack_index < packed_.size();) {
size_t bytes_left_in_buffer = max_length - *index;
- if (bytes_left_in_buffer < kCommonFbFmtLength + kNackItemLength) {
+ if (bytes_left_in_buffer < kNackHeaderLength + kNackItemLength) {
if (!OnBufferFull(packet, index, callback))
return false;
continue;
}
size_t num_nack_fields =
- std::min((bytes_left_in_buffer - kCommonFbFmtLength) / kNackItemLength,
+ std::min((bytes_left_in_buffer - kNackHeaderLength) / kNackItemLength,
packed_.size() - nack_index);
- size_t size_bytes =
- (num_nack_fields * kNackItemLength) + kCommonFbFmtLength;
- size_t header_length = ((size_bytes + 3) / 4) - 1; // As 32bit words - 1
- CreateHeader(kFeedbackMessageType, kPacketType, header_length, packet,
+ size_t payload_size_bytes =
+ kCommonFeedbackLength + (num_nack_fields * kNackItemLength);
+ size_t payload_size_32bits =
+ rtc::CheckedDivExact<size_t>(payload_size_bytes, 4);
+ CreateHeader(kFeedbackMessageType, kPacketType, payload_size_32bits, packet,
index);
+
CreateCommonFeedback(packet + *index);
*index += kCommonFeedbackLength;
- size_t end_index = nack_index + num_nack_fields;
- for (; nack_index < end_index; ++nack_index) {
- const auto& item = packed_[nack_index];
+
+ size_t nack_end_index = nack_index + num_nack_fields;
+ for (; nack_index < nack_end_index; ++nack_index) {
+ const PackedNack& item = packed_[nack_index];
ByteWriter<uint16_t>::WriteBigEndian(packet + *index + 0, item.first_pid);
ByteWriter<uint16_t>::WriteBigEndian(packet + *index + 2, item.bitmask);
*index += kNackItemLength;
}
RTC_DCHECK_LE(*index, max_length);
- } while (nack_index < packed_.size());
+ }
return true;
}
size_t Nack::BlockLength() const {
- return (packed_.size() * kNackItemLength) + kCommonFeedbackLength +
- kHeaderLength;
+ return kHeaderLength + kCommonFeedbackLength +
+ packed_.size() * kNackItemLength;
}
void Nack::WithList(const uint16_t* nack_list, size_t length) {
@@ -153,9 +158,10 @@ void Nack::Unpack() {
for (const PackedNack& item : packed_) {
packet_ids_.push_back(item.first_pid);
uint16_t pid = item.first_pid + 1;
- for (uint16_t bitmask = item.bitmask; bitmask != 0; bitmask >>= 1, ++pid)
+ for (uint16_t bitmask = item.bitmask; bitmask != 0; bitmask >>= 1, ++pid) {
if (bitmask & 1)
packet_ids_.push_back(pid);
+ }
}
}
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/nack_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698