OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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/receiver_report.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.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 { |
21 | |
22 // | 20 // |
23 // RTCP receiver report (RFC 3550). | 21 // RTCP receiver report (RFC 3550). |
24 // | 22 // |
25 // 0 1 2 3 | 23 // 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 | 24 // 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 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
28 // |V=2|P| RC | PT=RR=201 | length | | 26 // |V=2|P| RC | PT=RR=201 | length | |
29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
30 // | SSRC of packet sender | | 28 // | SSRC of packet sender | |
31 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | 29 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
32 // | report block(s) | | 30 // | report block(s) | |
33 // | .... | | 31 // | .... | |
34 bool ReceiverReport::Parse(const RTCPUtility::RtcpCommonHeader& header, | 32 bool ReceiverReport::Parse(const CommonHeader& packet) { |
35 const uint8_t* payload) { | 33 RTC_DCHECK(packet.type() == kPacketType); |
36 RTC_DCHECK(header.packet_type == kPacketType); | |
37 | 34 |
38 const uint8_t report_blocks_count = header.count_or_format; | 35 const uint8_t report_blocks_count = packet.count(); |
39 | 36 |
40 if (header.payload_size_bytes < | 37 if (packet.payload_size_bytes() < |
41 kRrBaseLength + report_blocks_count * ReportBlock::kLength) { | 38 kRrBaseLength + report_blocks_count * ReportBlock::kLength) { |
42 LOG(LS_WARNING) << "Packet is too small to contain all the data."; | 39 LOG(LS_WARNING) << "Packet is too small to contain all the data."; |
43 return false; | 40 return false; |
44 } | 41 } |
45 | 42 |
46 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(payload); | 43 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(packet.payload()); |
47 | 44 |
48 const uint8_t* next_report_block = payload + kRrBaseLength; | 45 const uint8_t* next_report_block = packet.payload() + kRrBaseLength; |
49 | 46 |
50 report_blocks_.resize(report_blocks_count); | 47 report_blocks_.resize(report_blocks_count); |
51 for (ReportBlock& block : report_blocks_) { | 48 for (ReportBlock& block : report_blocks_) { |
52 block.Parse(next_report_block, ReportBlock::kLength); | 49 block.Parse(next_report_block, ReportBlock::kLength); |
53 next_report_block += ReportBlock::kLength; | 50 next_report_block += ReportBlock::kLength; |
54 } | 51 } |
55 | 52 |
56 RTC_DCHECK_LE(next_report_block, payload + header.payload_size_bytes); | 53 RTC_DCHECK_EQ(next_report_block - packet.payload(), |
| 54 static_cast<ptrdiff_t>(packet.payload_size_bytes())); |
57 return true; | 55 return true; |
58 } | 56 } |
59 | 57 |
60 bool ReceiverReport::Create(uint8_t* packet, | 58 bool ReceiverReport::Create(uint8_t* packet, |
61 size_t* index, | 59 size_t* index, |
62 size_t max_length, | 60 size_t max_length, |
63 RtcpPacket::PacketReadyCallback* callback) const { | 61 RtcpPacket::PacketReadyCallback* callback) const { |
64 while (*index + BlockLength() > max_length) { | 62 while (*index + BlockLength() > max_length) { |
65 if (!OnBufferFull(packet, index, callback)) | 63 if (!OnBufferFull(packet, index, callback)) |
66 return false; | 64 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
80 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) { | 78 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) { |
81 LOG(LS_WARNING) << "Max report blocks reached."; | 79 LOG(LS_WARNING) << "Max report blocks reached."; |
82 return false; | 80 return false; |
83 } | 81 } |
84 report_blocks_.push_back(block); | 82 report_blocks_.push_back(block); |
85 return true; | 83 return true; |
86 } | 84 } |
87 | 85 |
88 } // namespace rtcp | 86 } // namespace rtcp |
89 } // namespace webrtc | 87 } // namespace webrtc |
OLD | NEW |