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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.cc

Issue 1575413002: [rtp_rtcp] rtcp header structure copied from RTCPUtility and extended (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 9 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
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
12
13 #include "webrtc/base/logging.h"
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
15
16 namespace webrtc {
17 namespace rtcp {
18 // 0 1 1 2 3
19 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
20 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21 // 0 |V=2|P| C/F |
22 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
23 // 1 | Packet Type |
24 // ----------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25 // 2 | length |
26 // --------------------------------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27 //
28 // Common header for all RTCP packets, 4 octets.
29 bool CommonHeader::Parse(const uint8_t* buffer, size_t size_bytes) {
30 const size_t kHeaderSizeBytes = 4;
31 const uint8_t kVersion = 2;
32
33 if (size_bytes < kHeaderSizeBytes) {
34 LOG(LS_WARNING) << "Too little data (" << size_bytes << " byte"
35 << (size_bytes != 1 ? "s" : "")
36 << ") remaining in buffer to parse RTCP header (4 bytes).";
37 return false;
38 }
39
40 uint8_t version = buffer[0] >> 6;
41 if (version != kVersion) {
42 LOG(LS_WARNING) << "Invalid RTCP header: Version must be "
43 << static_cast<int>(kVersion) << " but was "
44 << static_cast<int>(version);
45 return false;
46 }
47
48 bool has_padding = (buffer[0] & 0x20) != 0;
49 count_or_format_ = buffer[0] & 0x1F;
50 packet_type_ = buffer[1];
51 payload_size_ = ByteReader<uint16_t>::ReadBigEndian(&buffer[2]) * 4;
52 payload_ = buffer + kHeaderSizeBytes;
53 padding_size_ = 0;
54
55 if (size_bytes < kHeaderSizeBytes + payload_size_) {
56 LOG(LS_WARNING) << "Buffer too small (" << size_bytes
57 << " bytes) to fit an RtcpPacket with a header and "
58 << payload_size_ << " bytes.";
59 return false;
60 }
61
62 if (has_padding) {
63 if (payload_size_ == 0) {
64 LOG(LS_WARNING) << "Invalid RTCP header: Padding bit set but 0 payload "
65 "size specified.";
66 return false;
67 }
68
69 padding_size_ = payload_[payload_size_ - 1];
70 if (padding_size_ > payload_size_) {
71 LOG(LS_WARNING) << "Invalid RTCP header: Too many padding bytes ("
72 << padding_size_ << ") for a packet payload size of "
73 << payload_size_ << " bytes.";
74 return false;
75 }
76 payload_size_ -= padding_size_;
77 }
78 return true;
79 }
80 } // namespace rtcp
81 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698