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

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

Issue 1307663004: Add a ParseHeader method to RtcpPacket, for parsing common RTCP header. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Refactorings, unit tests Created 5 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
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 8cb6fb0833644077c3aed6f60475b56e9f23b2cc..75f670d2fb58185fdc4f28bcc7b7bc0e1c66ac43 100644
--- a/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc
@@ -729,6 +729,8 @@ size_t RtcpPacket::HeaderLength() const {
return ((length_in_bytes + 3) / 4) - 1;
}
+RtcpPacket::CommonHeader::CommonHeader()
+ : count_or_format(0), payload_type(0), payload_size_bytes(0) {}
// From RFC 3550, RTP: A Transport Protocol for Real-Time Applications.
//
// RTP header format.
@@ -743,7 +745,7 @@ void RtcpPacket::CreateHeader(
uint8_t packet_type,
size_t length,
uint8_t* buffer,
- size_t* pos) const {
+ size_t* pos) {
assert(length <= 0xffff);
const uint8_t kVersion = 2;
AssignUWord8(buffer, pos, (kVersion << 6) + count_or_format);
@@ -751,6 +753,58 @@ void RtcpPacket::CreateHeader(
AssignUWord16(buffer, pos, length);
}
+bool RtcpPacket::ParseHeader(const uint8_t* packet,
+ size_t index,
+ size_t max_length,
+ CommonHeader* header) {
åsapersson 2015/09/03 08:57:20 Looks like RTCPUtility::RTCPParseCommonHeader can
sprang_webrtc 2015/09/04 14:12:50 I've merged this into RTCPUtility.
+ DCHECK(header != nullptr);
+ size_t length = max_length - index;
+ const size_t kHeaderLength = 4;
+ if (length < kHeaderLength) {
+ LOG(LS_WARNING) << "Too little data (" << length << " byte"
+ << (length != 1 ? "s" : "")
+ << ") remaining in buffer to parse RTCP header (4 bytes).";
+ return false;
+ }
+
+ const uint8_t kRtcpVersion = 2;
+ uint8_t version = packet[index] >> 6;
+ if (version != kRtcpVersion) {
+ LOG(LS_WARNING) << "Invalid RTCP header: Version must be " << kRtcpVersion
+ << " but was " << version;
+ return false;
+ }
+
+ size_t packet_size_words =
+ ByteReader<uint16_t>::ReadBigEndian(&packet[index + 2]) + 1;
+ if (length < packet_size_words * 4) {
+ LOG(LS_WARNING) << "Buffer too small (" << length
+ << " bytes) to fit a FeedbackPacket of "
+ << packet_size_words << " 32bit words.";
+ return false;
+ }
+
+ bool has_padding = (packet[index] & 0x20) != 0;
+ size_t payload_size = packet_size_words * 4;
+ if (has_padding) {
+ uint8_t padding_bytes = packet[index + payload_size - 1];
+ if (kHeaderLength + padding_bytes > payload_size) {
+ LOG(LS_WARNING) << "Invalid RTCP header: Too many padding bytes ("
+ << padding_bytes << ") for a packet size of "
+ << payload_size << "bytes.";
+ return false;
+ }
+ payload_size -= padding_bytes;
+ }
+ payload_size -= kHeaderLength;
+
+ header->payload_size_bytes = payload_size;
+ header->count_or_format = packet[index] & 0x1F;
+ header->payload_type = packet[index + 1];
+
+ return true;
+}
+
bool Empty::Create(uint8_t* packet,
size_t* index,
size_t max_length,
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698