OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
16 | 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
17 using webrtc::RTCPUtility::RtcpCommonHeader; | |
18 | 17 |
19 namespace webrtc { | 18 namespace webrtc { |
20 namespace rtcp { | 19 namespace rtcp { |
| 20 constexpr uint8_t ExtendedReports::kPacketType; |
21 // From RFC 3611: RTP Control Protocol Extended Reports (RTCP XR). | 21 // From RFC 3611: RTP Control Protocol Extended Reports (RTCP XR). |
22 // | 22 // |
23 // Format for XR packets: | 23 // Format for XR packets: |
24 // | 24 // |
25 // 0 1 2 3 | 25 // 0 1 2 3 |
26 // 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 | 26 // 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 |
27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
28 // |V=2|P|reserved | PT=XR=207 | length | | 28 // |V=2|P|reserved | PT=XR=207 | length | |
29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
30 // | SSRC | | 30 // | SSRC | |
31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
32 // : report blocks : | 32 // : report blocks : |
33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
34 // | 34 // |
35 // Extended report block: | 35 // Extended report block: |
36 // 0 1 2 3 | 36 // 0 1 2 3 |
37 // 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 | 37 // 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 |
38 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 38 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
39 // | Block Type | reserved | block length | | 39 // | Block Type | reserved | block length | |
40 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 40 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
41 // : type-specific block contents : | 41 // : type-specific block contents : |
42 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 42 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
43 ExtendedReports::ExtendedReports() : sender_ssrc_(0) {} | 43 ExtendedReports::ExtendedReports() : sender_ssrc_(0) {} |
44 ExtendedReports::~ExtendedReports() {} | 44 ExtendedReports::~ExtendedReports() {} |
45 | 45 |
46 bool ExtendedReports::Parse(const RtcpCommonHeader& header, | 46 bool ExtendedReports::Parse(const CommonHeader& packet) { |
47 const uint8_t* payload) { | 47 RTC_DCHECK_EQ(packet.type(), kPacketType); |
48 RTC_CHECK(header.packet_type == kPacketType); | |
49 | 48 |
50 if (header.payload_size_bytes < kXrBaseLength) { | 49 if (packet.payload_size_bytes() < kXrBaseLength) { |
51 LOG(LS_WARNING) << "Packet is too small to be an ExtendedReports packet."; | 50 LOG(LS_WARNING) << "Packet is too small to be an ExtendedReports packet."; |
52 return false; | 51 return false; |
53 } | 52 } |
54 | 53 |
55 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(payload); | 54 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(packet.payload()); |
56 rrtr_blocks_.clear(); | 55 rrtr_blocks_.clear(); |
57 dlrr_blocks_.clear(); | 56 dlrr_blocks_.clear(); |
58 voip_metric_blocks_.clear(); | 57 voip_metric_blocks_.clear(); |
59 | 58 |
60 const uint8_t* current_block = payload + kXrBaseLength; | 59 const uint8_t* current_block = packet.payload() + kXrBaseLength; |
61 const uint8_t* const packet_end = payload + header.payload_size_bytes; | 60 const uint8_t* const packet_end = |
62 const size_t kBlockHeaderSizeBytes = 4; | 61 packet.payload() + packet.payload_size_bytes(); |
| 62 constexpr size_t kBlockHeaderSizeBytes = 4; |
63 while (current_block + kBlockHeaderSizeBytes <= packet_end) { | 63 while (current_block + kBlockHeaderSizeBytes <= packet_end) { |
64 uint8_t block_type = ByteReader<uint8_t>::ReadBigEndian(current_block); | 64 uint8_t block_type = ByteReader<uint8_t>::ReadBigEndian(current_block); |
65 uint16_t block_length = | 65 uint16_t block_length = |
66 ByteReader<uint16_t>::ReadBigEndian(current_block + 2); | 66 ByteReader<uint16_t>::ReadBigEndian(current_block + 2); |
67 const uint8_t* next_block = | 67 const uint8_t* next_block = |
68 current_block + kBlockHeaderSizeBytes + block_length * 4; | 68 current_block + kBlockHeaderSizeBytes + block_length * 4; |
69 if (next_block > packet_end) { | 69 if (next_block > packet_end) { |
70 LOG(LS_WARNING) << "Report block in extended report packet is too big."; | 70 LOG(LS_WARNING) << "Report block in extended report packet is too big."; |
71 return false; | 71 return false; |
72 } | 72 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (block_length != VoipMetric::kBlockLength) { | 179 if (block_length != VoipMetric::kBlockLength) { |
180 LOG(LS_WARNING) << "Incorrect voip metric block size " << block_length | 180 LOG(LS_WARNING) << "Incorrect voip metric block size " << block_length |
181 << " Should be " << VoipMetric::kBlockLength; | 181 << " Should be " << VoipMetric::kBlockLength; |
182 return; | 182 return; |
183 } | 183 } |
184 voip_metric_blocks_.push_back(VoipMetric()); | 184 voip_metric_blocks_.push_back(VoipMetric()); |
185 voip_metric_blocks_.back().Parse(block); | 185 voip_metric_blocks_.back().Parse(block); |
186 } | 186 } |
187 } // namespace rtcp | 187 } // namespace rtcp |
188 } // namespace webrtc | 188 } // namespace webrtc |
OLD | NEW |