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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 // | 22 // |
23 // 0 1 2 3 | 23 // 0 1 2 3 |
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 | 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 |
25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
26 // |V=2|P| RC | PT=RR=201 | length | | 26 // |V=2|P| RC | PT=RR=201 | length | |
27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
28 // | SSRC of packet sender | | 28 // | SSRC of packet sender | |
29 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | 29 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ |
30 // | report block(s) | | 30 // | report block(s) | |
31 // | .... | | 31 // | .... | |
| 32 |
| 33 ReceiverReport::ReceiverReport() : sender_ssrc_(0) {} |
| 34 |
| 35 ReceiverReport::~ReceiverReport() = default; |
| 36 |
32 bool ReceiverReport::Parse(const CommonHeader& packet) { | 37 bool ReceiverReport::Parse(const CommonHeader& packet) { |
33 RTC_DCHECK_EQ(packet.type(), kPacketType); | 38 RTC_DCHECK_EQ(packet.type(), kPacketType); |
34 | 39 |
35 const uint8_t report_blocks_count = packet.count(); | 40 const uint8_t report_blocks_count = packet.count(); |
36 | 41 |
37 if (packet.payload_size_bytes() < | 42 if (packet.payload_size_bytes() < |
38 kRrBaseLength + report_blocks_count * ReportBlock::kLength) { | 43 kRrBaseLength + report_blocks_count * ReportBlock::kLength) { |
39 LOG(LS_WARNING) << "Packet is too small to contain all the data."; | 44 LOG(LS_WARNING) << "Packet is too small to contain all the data."; |
40 return false; | 45 return false; |
41 } | 46 } |
42 | 47 |
43 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(packet.payload()); | 48 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(packet.payload()); |
44 | 49 |
45 const uint8_t* next_report_block = packet.payload() + kRrBaseLength; | 50 const uint8_t* next_report_block = packet.payload() + kRrBaseLength; |
46 | 51 |
47 report_blocks_.resize(report_blocks_count); | 52 report_blocks_.resize(report_blocks_count); |
48 for (ReportBlock& block : report_blocks_) { | 53 for (ReportBlock& block : report_blocks_) { |
49 block.Parse(next_report_block, ReportBlock::kLength); | 54 block.Parse(next_report_block, ReportBlock::kLength); |
50 next_report_block += ReportBlock::kLength; | 55 next_report_block += ReportBlock::kLength; |
51 } | 56 } |
52 | 57 |
53 RTC_DCHECK_LE(next_report_block - packet.payload(), | 58 RTC_DCHECK_LE(next_report_block - packet.payload(), |
54 static_cast<ptrdiff_t>(packet.payload_size_bytes())); | 59 static_cast<ptrdiff_t>(packet.payload_size_bytes())); |
55 return true; | 60 return true; |
56 } | 61 } |
57 | 62 |
| 63 size_t ReceiverReport::BlockLength() const { |
| 64 return kHeaderLength + kRrBaseLength + |
| 65 report_blocks_.size() * ReportBlock::kLength; |
| 66 } |
| 67 |
58 bool ReceiverReport::Create(uint8_t* packet, | 68 bool ReceiverReport::Create(uint8_t* packet, |
59 size_t* index, | 69 size_t* index, |
60 size_t max_length, | 70 size_t max_length, |
61 RtcpPacket::PacketReadyCallback* callback) const { | 71 RtcpPacket::PacketReadyCallback* callback) const { |
62 while (*index + BlockLength() > max_length) { | 72 while (*index + BlockLength() > max_length) { |
63 if (!OnBufferFull(packet, index, callback)) | 73 if (!OnBufferFull(packet, index, callback)) |
64 return false; | 74 return false; |
65 } | 75 } |
66 CreateHeader(report_blocks_.size(), kPacketType, HeaderLength(), packet, | 76 CreateHeader(report_blocks_.size(), kPacketType, HeaderLength(), packet, |
67 index); | 77 index); |
(...skipping 10 matching lines...) Expand all Loading... |
78 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) { | 88 if (report_blocks_.size() >= kMaxNumberOfReportBlocks) { |
79 LOG(LS_WARNING) << "Max report blocks reached."; | 89 LOG(LS_WARNING) << "Max report blocks reached."; |
80 return false; | 90 return false; |
81 } | 91 } |
82 report_blocks_.push_back(block); | 92 report_blocks_.push_back(block); |
83 return true; | 93 return true; |
84 } | 94 } |
85 | 95 |
86 } // namespace rtcp | 96 } // namespace rtcp |
87 } // namespace webrtc | 97 } // namespace webrtc |
OLD | NEW |