| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 18 | 18 |
| 19 using webrtc::RTCPUtility::kBtDlrr; | |
| 20 using webrtc::RTCPUtility::kBtReceiverReferenceTime; | |
| 21 using webrtc::RTCPUtility::kBtVoipMetric; | |
| 22 | |
| 23 using webrtc::RTCPUtility::PT_APP; | 19 using webrtc::RTCPUtility::PT_APP; |
| 24 using webrtc::RTCPUtility::PT_IJ; | 20 using webrtc::RTCPUtility::PT_IJ; |
| 25 using webrtc::RTCPUtility::PT_PSFB; | 21 using webrtc::RTCPUtility::PT_PSFB; |
| 26 using webrtc::RTCPUtility::PT_RTPFB; | 22 using webrtc::RTCPUtility::PT_RTPFB; |
| 27 using webrtc::RTCPUtility::PT_SDES; | 23 using webrtc::RTCPUtility::PT_SDES; |
| 28 using webrtc::RTCPUtility::PT_SR; | 24 using webrtc::RTCPUtility::PT_SR; |
| 29 using webrtc::RTCPUtility::PT_XR; | |
| 30 | 25 |
| 31 using webrtc::RTCPUtility::RTCPPacketAPP; | 26 using webrtc::RTCPUtility::RTCPPacketAPP; |
| 32 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; | 27 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; |
| 33 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; | 28 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; |
| 34 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; | 29 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; |
| 35 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; | 30 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; |
| 36 using webrtc::RTCPUtility::RTCPPacketSR; | 31 using webrtc::RTCPUtility::RTCPPacketSR; |
| 37 using webrtc::RTCPUtility::RTCPPacketXRDLRRReportBlockItem; | |
| 38 using webrtc::RTCPUtility::RTCPPacketXR; | |
| 39 | 32 |
| 40 namespace webrtc { | 33 namespace webrtc { |
| 41 namespace rtcp { | 34 namespace rtcp { |
| 42 namespace { | 35 namespace { |
| 43 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { | 36 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { |
| 44 buffer[(*offset)++] = value; | 37 buffer[(*offset)++] = value; |
| 45 } | 38 } |
| 46 void AssignUWord16(uint8_t* buffer, size_t* offset, uint16_t value) { | 39 void AssignUWord16(uint8_t* buffer, size_t* offset, uint16_t value) { |
| 47 ByteWriter<uint16_t>::WriteBigEndian(buffer + *offset, value); | 40 ByteWriter<uint16_t>::WriteBigEndian(buffer + *offset, value); |
| 48 *offset += 2; | 41 *offset += 2; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 assert(rpsi.NumberOfValidBits % 8 == 0); | 163 assert(rpsi.NumberOfValidBits % 8 == 0); |
| 171 AssignUWord32(buffer, pos, rpsi.SenderSSRC); | 164 AssignUWord32(buffer, pos, rpsi.SenderSSRC); |
| 172 AssignUWord32(buffer, pos, rpsi.MediaSSRC); | 165 AssignUWord32(buffer, pos, rpsi.MediaSSRC); |
| 173 AssignUWord8(buffer, pos, padding_bytes * 8); | 166 AssignUWord8(buffer, pos, padding_bytes * 8); |
| 174 AssignUWord8(buffer, pos, rpsi.PayloadType); | 167 AssignUWord8(buffer, pos, rpsi.PayloadType); |
| 175 memcpy(buffer + *pos, rpsi.NativeBitString, rpsi.NumberOfValidBits / 8); | 168 memcpy(buffer + *pos, rpsi.NativeBitString, rpsi.NumberOfValidBits / 8); |
| 176 *pos += rpsi.NumberOfValidBits / 8; | 169 *pos += rpsi.NumberOfValidBits / 8; |
| 177 memset(buffer + *pos, 0, padding_bytes); | 170 memset(buffer + *pos, 0, padding_bytes); |
| 178 *pos += padding_bytes; | 171 *pos += padding_bytes; |
| 179 } | 172 } |
| 180 | |
| 181 // From RFC 3611: RTP Control Protocol Extended Reports (RTCP XR). | |
| 182 // | |
| 183 // Format for XR packets: | |
| 184 // | |
| 185 // 0 1 2 3 | |
| 186 // 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 | |
| 187 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 188 // |V=2|P|reserved | PT=XR=207 | length | | |
| 189 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 190 // | SSRC | | |
| 191 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 192 // : report blocks : | |
| 193 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 194 | |
| 195 void CreateXrHeader(const RTCPPacketXR& header, | |
| 196 uint8_t* buffer, | |
| 197 size_t* pos) { | |
| 198 AssignUWord32(buffer, pos, header.OriginatorSSRC); | |
| 199 } | |
| 200 | |
| 201 } // namespace | 173 } // namespace |
| 202 | 174 |
| 203 void RtcpPacket::Append(RtcpPacket* packet) { | 175 void RtcpPacket::Append(RtcpPacket* packet) { |
| 204 assert(packet); | 176 assert(packet); |
| 205 appended_packets_.push_back(packet); | 177 appended_packets_.push_back(packet); |
| 206 } | 178 } |
| 207 | 179 |
| 208 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { | 180 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { |
| 209 size_t length = 0; | 181 size_t length = 0; |
| 210 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); | 182 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 rpsi_.NativeBitString[pos++] = static_cast<uint8_t>(picture_id & 0x7f); | 370 rpsi_.NativeBitString[pos++] = static_cast<uint8_t>(picture_id & 0x7f); |
| 399 rpsi_.NumberOfValidBits = pos * 8; | 371 rpsi_.NumberOfValidBits = pos * 8; |
| 400 | 372 |
| 401 // Calculate padding bytes (to reach next 32-bit boundary, 1, 2 or 3 bytes). | 373 // Calculate padding bytes (to reach next 32-bit boundary, 1, 2 or 3 bytes). |
| 402 padding_bytes_ = 4 - ((2 + required_bytes) % 4); | 374 padding_bytes_ = 4 - ((2 + required_bytes) % 4); |
| 403 if (padding_bytes_ == 4) { | 375 if (padding_bytes_ == 4) { |
| 404 padding_bytes_ = 0; | 376 padding_bytes_ = 0; |
| 405 } | 377 } |
| 406 } | 378 } |
| 407 | 379 |
| 408 bool Xr::Create(uint8_t* packet, | |
| 409 size_t* index, | |
| 410 size_t max_length, | |
| 411 RtcpPacket::PacketReadyCallback* callback) const { | |
| 412 while (*index + BlockLength() > max_length) { | |
| 413 if (!OnBufferFull(packet, index, callback)) | |
| 414 return false; | |
| 415 } | |
| 416 CreateHeader(0U, PT_XR, HeaderLength(), packet, index); | |
| 417 CreateXrHeader(xr_header_, packet, index); | |
| 418 for (const Rrtr& block : rrtr_blocks_) { | |
| 419 block.Create(packet + *index); | |
| 420 *index += Rrtr::kLength; | |
| 421 } | |
| 422 for (const Dlrr& block : dlrr_blocks_) { | |
| 423 block.Create(packet + *index); | |
| 424 *index += block.BlockLength(); | |
| 425 } | |
| 426 for (const VoipMetric& block : voip_metric_blocks_) { | |
| 427 block.Create(packet + *index); | |
| 428 *index += VoipMetric::kLength; | |
| 429 } | |
| 430 return true; | |
| 431 } | |
| 432 | |
| 433 bool Xr::WithRrtr(Rrtr* rrtr) { | |
| 434 RTC_DCHECK(rrtr); | |
| 435 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) { | |
| 436 LOG(LS_WARNING) << "Max RRTR blocks reached."; | |
| 437 return false; | |
| 438 } | |
| 439 rrtr_blocks_.push_back(*rrtr); | |
| 440 return true; | |
| 441 } | |
| 442 | |
| 443 bool Xr::WithDlrr(Dlrr* dlrr) { | |
| 444 RTC_DCHECK(dlrr); | |
| 445 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) { | |
| 446 LOG(LS_WARNING) << "Max DLRR blocks reached."; | |
| 447 return false; | |
| 448 } | |
| 449 dlrr_blocks_.push_back(*dlrr); | |
| 450 return true; | |
| 451 } | |
| 452 | |
| 453 bool Xr::WithVoipMetric(VoipMetric* voip_metric) { | |
| 454 assert(voip_metric); | |
| 455 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) { | |
| 456 LOG(LS_WARNING) << "Max Voip Metric blocks reached."; | |
| 457 return false; | |
| 458 } | |
| 459 voip_metric_blocks_.push_back(*voip_metric); | |
| 460 return true; | |
| 461 } | |
| 462 | |
| 463 size_t Xr::DlrrLength() const { | |
| 464 size_t length = 0; | |
| 465 for (const Dlrr& block : dlrr_blocks_) { | |
| 466 length += block.BlockLength(); | |
| 467 } | |
| 468 return length; | |
| 469 } | |
| 470 | |
| 471 RawPacket::RawPacket(size_t buffer_length) | 380 RawPacket::RawPacket(size_t buffer_length) |
| 472 : buffer_length_(buffer_length), length_(0) { | 381 : buffer_length_(buffer_length), length_(0) { |
| 473 buffer_.reset(new uint8_t[buffer_length]); | 382 buffer_.reset(new uint8_t[buffer_length]); |
| 474 } | 383 } |
| 475 | 384 |
| 476 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) | 385 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) |
| 477 : buffer_length_(packet_length), length_(packet_length) { | 386 : buffer_length_(packet_length), length_(packet_length) { |
| 478 buffer_.reset(new uint8_t[packet_length]); | 387 buffer_.reset(new uint8_t[packet_length]); |
| 479 memcpy(buffer_.get(), packet, packet_length); | 388 memcpy(buffer_.get(), packet, packet_length); |
| 480 } | 389 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 495 return length_; | 404 return length_; |
| 496 } | 405 } |
| 497 | 406 |
| 498 void RawPacket::SetLength(size_t length) { | 407 void RawPacket::SetLength(size_t length) { |
| 499 assert(length <= buffer_length_); | 408 assert(length <= buffer_length_); |
| 500 length_ = length; | 409 length_ = length; |
| 501 } | 410 } |
| 502 | 411 |
| 503 } // namespace rtcp | 412 } // namespace rtcp |
| 504 } // namespace webrtc | 413 } // namespace webrtc |
| OLD | NEW |