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

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

Issue 2270753002: Remove RtcpPacket dependency on rtcp_utility: (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: nits Created 4 years, 3 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
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/rtp_rtcp/source/rtcp_packet.cc
diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc
index 87b086de9dd4172d087b06b1442dbc16b8fa82bc..5339c656e5776d0ede8bb6d55d2a5a1cd2c6b62b 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc
@@ -11,50 +11,23 @@
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
#include "webrtc/base/checks.h"
-#include "webrtc/base/logging.h"
-#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
namespace webrtc {
namespace rtcp {
-namespace {
-void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) {
- buffer[(*offset)++] = value;
-}
-void AssignUWord16(uint8_t* buffer, size_t* offset, uint16_t value) {
- ByteWriter<uint16_t>::WriteBigEndian(buffer + *offset, value);
- *offset += 2;
-}
-} // namespace
+constexpr size_t RtcpPacket::kHeaderLength;
rtc::Buffer RtcpPacket::Build() const {
- size_t length = 0;
- rtc::Buffer packet(IP_PACKET_SIZE);
+ rtc::Buffer packet(BlockLength());
- class PacketVerifier : public PacketReadyCallback {
- public:
- explicit PacketVerifier(rtc::Buffer* packet)
- : called_(false), packet_(packet) {}
- virtual ~PacketVerifier() {}
- void OnPacketReady(uint8_t* data, size_t length) override {
- RTC_CHECK(!called_) << "Fragmentation not supported.";
- called_ = true;
- packet_->SetSize(length);
- }
+ size_t length = 0;
+ bool created = Create(packet.data(), &length, packet.capacity(), nullptr);
+ RTC_DCHECK(created) << "Invalid packet is not supported.";
+ RTC_DCHECK_EQ(length, packet.size())
+ << "BlockLength mispredicted size used by Create";
- private:
- bool called_;
- rtc::Buffer* const packet_;
- } verifier(&packet);
- Create(packet.data(), &length, packet.capacity(), &verifier);
- OnBufferFull(packet.data(), &length, &verifier);
return packet;
}
-bool RtcpPacket::Build(PacketReadyCallback* callback) const {
- uint8_t buffer[IP_PACKET_SIZE];
- return BuildExternalBuffer(buffer, IP_PACKET_SIZE, callback);
-}
-
bool RtcpPacket::BuildExternalBuffer(uint8_t* buffer,
size_t max_length,
PacketReadyCallback* callback) const {
@@ -66,9 +39,10 @@ bool RtcpPacket::BuildExternalBuffer(uint8_t* buffer,
bool RtcpPacket::OnBufferFull(uint8_t* packet,
size_t* index,
- RtcpPacket::PacketReadyCallback* callback) const {
+ PacketReadyCallback* callback) const {
if (*index == 0)
return false;
+ RTC_DCHECK(callback) << "Fragmentation not supported.";
callback->OnPacketReady(packet, *index);
*index = 0;
return true;
@@ -76,9 +50,10 @@ bool RtcpPacket::OnBufferFull(uint8_t* packet,
size_t RtcpPacket::HeaderLength() const {
size_t length_in_bytes = BlockLength();
- // Length in 32-bit words minus 1.
- assert(length_in_bytes > 0);
- return ((length_in_bytes + 3) / 4) - 1;
+ RTC_DCHECK_GT(length_in_bytes, 0u);
+ RTC_DCHECK_EQ(length_in_bytes % 4, 0u) << "Padding not supported";
+ // Length in 32-bit words without common header.
+ return (length_in_bytes - kHeaderLength) / 4;
}
// From RFC 3550, RTP: A Transport Protocol for Real-Time Applications.
@@ -89,18 +64,21 @@ size_t RtcpPacket::HeaderLength() const {
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| RC/FMT | PT | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
void RtcpPacket::CreateHeader(
uint8_t count_or_format, // Depends on packet type.
uint8_t packet_type,
size_t length,
uint8_t* buffer,
size_t* pos) {
- assert(length <= 0xffff);
- const uint8_t kVersion = 2;
- AssignUWord8(buffer, pos, (kVersion << 6) + count_or_format);
- AssignUWord8(buffer, pos, packet_type);
- AssignUWord16(buffer, pos, length);
+ RTC_DCHECK_LE(length, 0xffffU);
+ RTC_DCHECK_LE(count_or_format, 0x1f);
+ constexpr uint8_t kVersionBits = 2 << 6;
+ constexpr uint8_t kNoPaddingBit = 0 << 5;
+ buffer[*pos + 0] = kVersionBits | kNoPaddingBit | count_or_format;
+ buffer[*pos + 1] = packet_type;
+ buffer[*pos + 2] = (length >> 8) & 0xff;
+ buffer[*pos + 3] = length & 0xff;
+ *pos += kHeaderLength;
}
} // namespace rtcp
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698