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

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

Issue 2378113002: Allow max 1 block per type in RTCP Extended Reports (Closed)
Patch Set: use operator==(T, Optional<T>) for slightly cleaner tests Created 4 years, 2 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
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
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 bool ExtendedReports::Parse(const CommonHeader& packet) { 46 bool ExtendedReports::Parse(const CommonHeader& packet) {
47 RTC_DCHECK_EQ(packet.type(), kPacketType); 47 RTC_DCHECK_EQ(packet.type(), kPacketType);
48 48
49 if (packet.payload_size_bytes() < kXrBaseLength) { 49 if (packet.payload_size_bytes() < kXrBaseLength) {
50 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.";
51 return false; 51 return false;
52 } 52 }
53 53
54 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(packet.payload()); 54 sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(packet.payload());
55 rrtr_blocks_.clear(); 55 rrtr_block_.reset();
56 dlrr_blocks_.clear(); 56 dlrr_block_.ClearItems();
57 voip_metric_blocks_.clear(); 57 voip_metric_block_.reset();
58 58
59 const uint8_t* current_block = packet.payload() + kXrBaseLength; 59 const uint8_t* current_block = packet.payload() + kXrBaseLength;
60 const uint8_t* const packet_end = 60 const uint8_t* const packet_end =
61 packet.payload() + packet.payload_size_bytes(); 61 packet.payload() + packet.payload_size_bytes();
62 constexpr size_t kBlockHeaderSizeBytes = 4; 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 =
(...skipping 16 matching lines...) Expand all
84 // Unknown block, ignore. 84 // Unknown block, ignore.
85 LOG(LS_WARNING) << "Unknown extended report block type " << block_type; 85 LOG(LS_WARNING) << "Unknown extended report block type " << block_type;
86 break; 86 break;
87 } 87 }
88 current_block = next_block; 88 current_block = next_block;
89 } 89 }
90 90
91 return true; 91 return true;
92 } 92 }
93 93
94 bool ExtendedReports::AddRrtr(const Rrtr& rrtr) { 94 void ExtendedReports::SetRrtr(const Rrtr& rrtr) {
95 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) { 95 if (rrtr_block_)
96 LOG(LS_WARNING) << "Max RRTR blocks reached."; 96 LOG(LS_WARNING) << "Rrtr already set, overwriting.";
97 return false; 97 rrtr_block_.emplace(rrtr);
98 }
99 rrtr_blocks_.push_back(rrtr);
100 return true;
101 } 98 }
102 99
103 bool ExtendedReports::AddDlrr(const Dlrr& dlrr) { 100 void ExtendedReports::AddDlrrItem(const ReceiveTimeInfo& time_info) {
104 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) { 101 dlrr_block_.AddDlrrItem(time_info);
105 LOG(LS_WARNING) << "Max DLRR blocks reached.";
106 return false;
107 }
108 dlrr_blocks_.push_back(dlrr);
109 return true;
110 } 102 }
111 103
112 bool ExtendedReports::AddVoipMetric(const VoipMetric& voip_metric) { 104 void ExtendedReports::SetVoipMetric(const VoipMetric& voip_metric) {
113 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) { 105 if (voip_metric_block_)
114 LOG(LS_WARNING) << "Max Voip Metric blocks reached."; 106 LOG(LS_WARNING) << "Voip metric already set, overwriting.";
115 return false; 107 voip_metric_block_.emplace(voip_metric);
116 }
117 voip_metric_blocks_.push_back(voip_metric);
118 return true;
119 } 108 }
120 109
121 bool ExtendedReports::Create(uint8_t* packet, 110 bool ExtendedReports::Create(uint8_t* packet,
122 size_t* index, 111 size_t* index,
123 size_t max_length, 112 size_t max_length,
124 RtcpPacket::PacketReadyCallback* callback) const { 113 RtcpPacket::PacketReadyCallback* callback) const {
125 while (*index + BlockLength() > max_length) { 114 while (*index + BlockLength() > max_length) {
126 if (!OnBufferFull(packet, index, callback)) 115 if (!OnBufferFull(packet, index, callback))
127 return false; 116 return false;
128 } 117 }
129 size_t index_end = *index + BlockLength(); 118 size_t index_end = *index + BlockLength();
130 const uint8_t kReserved = 0; 119 const uint8_t kReserved = 0;
131 CreateHeader(kReserved, kPacketType, HeaderLength(), packet, index); 120 CreateHeader(kReserved, kPacketType, HeaderLength(), packet, index);
132 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, sender_ssrc_); 121 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, sender_ssrc_);
133 *index += sizeof(uint32_t); 122 *index += sizeof(uint32_t);
134 for (const Rrtr& block : rrtr_blocks_) { 123 if (rrtr_block_) {
135 block.Create(packet + *index); 124 rrtr_block_->Create(packet + *index);
136 *index += Rrtr::kLength; 125 *index += Rrtr::kLength;
137 } 126 }
138 for (const Dlrr& block : dlrr_blocks_) { 127 if (dlrr_block_) {
139 block.Create(packet + *index); 128 dlrr_block_.Create(packet + *index);
140 *index += block.BlockLength(); 129 *index += dlrr_block_.BlockLength();
141 } 130 }
142 for (const VoipMetric& block : voip_metric_blocks_) { 131 if (voip_metric_block_) {
143 block.Create(packet + *index); 132 voip_metric_block_->Create(packet + *index);
144 *index += VoipMetric::kLength; 133 *index += VoipMetric::kLength;
145 } 134 }
146 RTC_CHECK_EQ(*index, index_end); 135 RTC_CHECK_EQ(*index, index_end);
147 return true; 136 return true;
148 } 137 }
149 138
150 size_t ExtendedReports::DlrrLength() const {
151 size_t length = 0;
152 for (const Dlrr& block : dlrr_blocks_) {
153 length += block.BlockLength();
154 }
155 return length;
156 }
157
158 void ExtendedReports::ParseRrtrBlock(const uint8_t* block, 139 void ExtendedReports::ParseRrtrBlock(const uint8_t* block,
159 uint16_t block_length) { 140 uint16_t block_length) {
160 if (block_length != Rrtr::kBlockLength) { 141 if (block_length != Rrtr::kBlockLength) {
161 LOG(LS_WARNING) << "Incorrect rrtr block size " << block_length 142 LOG(LS_WARNING) << "Incorrect rrtr block size " << block_length
162 << " Should be " << Rrtr::kBlockLength; 143 << " Should be " << Rrtr::kBlockLength;
163 return; 144 return;
164 } 145 }
165 rrtr_blocks_.push_back(Rrtr()); 146 if (rrtr_block_) {
166 rrtr_blocks_.back().Parse(block); 147 LOG(LS_WARNING) << "Two rrtr blocks found in same Extended Report packet";
148 return;
149 }
150 rrtr_block_.emplace();
151 rrtr_block_->Parse(block);
167 } 152 }
168 153
169 void ExtendedReports::ParseDlrrBlock(const uint8_t* block, 154 void ExtendedReports::ParseDlrrBlock(const uint8_t* block,
170 uint16_t block_length) { 155 uint16_t block_length) {
171 dlrr_blocks_.push_back(Dlrr()); 156 if (dlrr_block_) {
172 if (!dlrr_blocks_.back().Parse(block, block_length)) { 157 LOG(LS_WARNING) << "Two Dlrr blocks found in same Extended Report packet";
173 dlrr_blocks_.pop_back(); 158 return;
174 } 159 }
160 dlrr_block_.Parse(block, block_length);
175 } 161 }
176 162
177 void ExtendedReports::ParseVoipMetricBlock(const uint8_t* block, 163 void ExtendedReports::ParseVoipMetricBlock(const uint8_t* block,
178 uint16_t block_length) { 164 uint16_t block_length) {
179 if (block_length != VoipMetric::kBlockLength) { 165 if (block_length != VoipMetric::kBlockLength) {
180 LOG(LS_WARNING) << "Incorrect voip metric block size " << block_length 166 LOG(LS_WARNING) << "Incorrect voip metric block size " << block_length
181 << " Should be " << VoipMetric::kBlockLength; 167 << " Should be " << VoipMetric::kBlockLength;
182 return; 168 return;
183 } 169 }
184 voip_metric_blocks_.push_back(VoipMetric()); 170 if (voip_metric_block_) {
185 voip_metric_blocks_.back().Parse(block); 171 LOG(LS_WARNING)
172 << "Two Voip Metric blocks found in same Extended Report packet";
173 return;
174 }
175 voip_metric_block_.emplace();
176 voip_metric_block_->Parse(block);
186 } 177 }
187 } // namespace rtcp 178 } // namespace rtcp
188 } // namespace webrtc 179 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698