| 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 "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 |
| 17 using webrtc::RTCPUtility::kBtDlrr; | 17 using webrtc::RTCPUtility::kBtDlrr; |
| 18 using webrtc::RTCPUtility::kBtReceiverReferenceTime; | 18 using webrtc::RTCPUtility::kBtReceiverReferenceTime; |
| 19 using webrtc::RTCPUtility::kBtVoipMetric; | 19 using webrtc::RTCPUtility::kBtVoipMetric; |
| 20 | 20 |
| 21 using webrtc::RTCPUtility::PT_APP; | 21 using webrtc::RTCPUtility::PT_APP; |
| 22 using webrtc::RTCPUtility::PT_BYE; | |
| 23 using webrtc::RTCPUtility::PT_IJ; | 22 using webrtc::RTCPUtility::PT_IJ; |
| 24 using webrtc::RTCPUtility::PT_PSFB; | 23 using webrtc::RTCPUtility::PT_PSFB; |
| 25 using webrtc::RTCPUtility::PT_RR; | 24 using webrtc::RTCPUtility::PT_RR; |
| 26 using webrtc::RTCPUtility::PT_RTPFB; | 25 using webrtc::RTCPUtility::PT_RTPFB; |
| 27 using webrtc::RTCPUtility::PT_SDES; | 26 using webrtc::RTCPUtility::PT_SDES; |
| 28 using webrtc::RTCPUtility::PT_SR; | 27 using webrtc::RTCPUtility::PT_SR; |
| 29 using webrtc::RTCPUtility::PT_XR; | 28 using webrtc::RTCPUtility::PT_XR; |
| 30 | 29 |
| 31 using webrtc::RTCPUtility::RTCPPacketAPP; | 30 using webrtc::RTCPUtility::RTCPPacketAPP; |
| 32 using webrtc::RTCPUtility::RTCPPacketBYE; | |
| 33 using webrtc::RTCPUtility::RTCPPacketPSFBAPP; | 31 using webrtc::RTCPUtility::RTCPPacketPSFBAPP; |
| 34 using webrtc::RTCPUtility::RTCPPacketPSFBFIR; | 32 using webrtc::RTCPUtility::RTCPPacketPSFBFIR; |
| 35 using webrtc::RTCPUtility::RTCPPacketPSFBFIRItem; | 33 using webrtc::RTCPUtility::RTCPPacketPSFBFIRItem; |
| 36 using webrtc::RTCPUtility::RTCPPacketPSFBPLI; | 34 using webrtc::RTCPUtility::RTCPPacketPSFBPLI; |
| 37 using webrtc::RTCPUtility::RTCPPacketPSFBREMBItem; | 35 using webrtc::RTCPUtility::RTCPPacketPSFBREMBItem; |
| 38 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; | 36 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; |
| 39 using webrtc::RTCPUtility::RTCPPacketPSFBSLI; | 37 using webrtc::RTCPUtility::RTCPPacketPSFBSLI; |
| 40 using webrtc::RTCPUtility::RTCPPacketPSFBSLIItem; | 38 using webrtc::RTCPUtility::RTCPPacketPSFBSLIItem; |
| 41 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; | 39 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; |
| 42 using webrtc::RTCPUtility::RTCPPacketRR; | 40 using webrtc::RTCPUtility::RTCPPacketRR; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 AssignUWord32(buffer, pos, (*it).ssrc); | 196 AssignUWord32(buffer, pos, (*it).ssrc); |
| 199 AssignUWord8(buffer, pos, kSdesItemType); | 197 AssignUWord8(buffer, pos, kSdesItemType); |
| 200 AssignUWord8(buffer, pos, (*it).name.length()); | 198 AssignUWord8(buffer, pos, (*it).name.length()); |
| 201 memcpy(buffer + *pos, (*it).name.data(), (*it).name.length()); | 199 memcpy(buffer + *pos, (*it).name.data(), (*it).name.length()); |
| 202 *pos += (*it).name.length(); | 200 *pos += (*it).name.length(); |
| 203 memset(buffer + *pos, 0, (*it).null_octets); | 201 memset(buffer + *pos, 0, (*it).null_octets); |
| 204 *pos += (*it).null_octets; | 202 *pos += (*it).null_octets; |
| 205 } | 203 } |
| 206 } | 204 } |
| 207 | 205 |
| 208 // Bye packet (BYE) (RFC 3550). | |
| 209 // | |
| 210 // 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 | |
| 211 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 212 // |V=2|P| SC | PT=BYE=203 | length | | |
| 213 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 214 // | SSRC/CSRC | | |
| 215 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 216 // : ... : | |
| 217 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | |
| 218 // (opt) | length | reason for leaving ... | |
| 219 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 220 | |
| 221 void CreateBye(const RTCPPacketBYE& bye, | |
| 222 const std::vector<uint32_t>& csrcs, | |
| 223 uint8_t* buffer, | |
| 224 size_t* pos) { | |
| 225 AssignUWord32(buffer, pos, bye.SenderSSRC); | |
| 226 for (uint32_t csrc : csrcs) | |
| 227 AssignUWord32(buffer, pos, csrc); | |
| 228 } | |
| 229 | |
| 230 // RFC 4585: Feedback format. | 206 // RFC 4585: Feedback format. |
| 231 // | 207 // |
| 232 // Common packet format: | 208 // Common packet format: |
| 233 // | 209 // |
| 234 // 0 1 2 3 | 210 // 0 1 2 3 |
| 235 // 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 | 211 // 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 |
| 236 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 212 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 237 // |V=2|P| FMT | PT | length | | 213 // |V=2|P| FMT | PT | length | |
| 238 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 214 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 239 // | SSRC of packet sender | | 215 // | SSRC of packet sender | |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // Header (4 bytes). | 770 // Header (4 bytes). |
| 795 // Chunk: | 771 // Chunk: |
| 796 // SSRC/CSRC (4 bytes) | CNAME (1 byte) | length (1 byte) | name | padding. | 772 // SSRC/CSRC (4 bytes) | CNAME (1 byte) | length (1 byte) | name | padding. |
| 797 size_t length = kHeaderLength; | 773 size_t length = kHeaderLength; |
| 798 for (const Chunk& chunk : chunks_) | 774 for (const Chunk& chunk : chunks_) |
| 799 length += 6 + chunk.name.length() + chunk.null_octets; | 775 length += 6 + chunk.name.length() + chunk.null_octets; |
| 800 assert(length % 4 == 0); | 776 assert(length % 4 == 0); |
| 801 return length; | 777 return length; |
| 802 } | 778 } |
| 803 | 779 |
| 804 bool Bye::Create(uint8_t* packet, | |
| 805 size_t* index, | |
| 806 size_t max_length, | |
| 807 RtcpPacket::PacketReadyCallback* callback) const { | |
| 808 while (*index + BlockLength() > max_length) { | |
| 809 if (!OnBufferFull(packet, index, callback)) | |
| 810 return false; | |
| 811 } | |
| 812 size_t length = HeaderLength(); | |
| 813 CreateHeader(length, PT_BYE, length, packet, index); | |
| 814 CreateBye(bye_, csrcs_, packet, index); | |
| 815 return true; | |
| 816 } | |
| 817 | |
| 818 bool Bye::WithCsrc(uint32_t csrc) { | |
| 819 if (csrcs_.size() >= kMaxNumberOfCsrcs) { | |
| 820 LOG(LS_WARNING) << "Max CSRC size reached."; | |
| 821 return false; | |
| 822 } | |
| 823 csrcs_.push_back(csrc); | |
| 824 return true; | |
| 825 } | |
| 826 | |
| 827 bool Pli::Create(uint8_t* packet, | 780 bool Pli::Create(uint8_t* packet, |
| 828 size_t* index, | 781 size_t* index, |
| 829 size_t max_length, | 782 size_t max_length, |
| 830 RtcpPacket::PacketReadyCallback* callback) const { | 783 RtcpPacket::PacketReadyCallback* callback) const { |
| 831 while (*index + BlockLength() > max_length) { | 784 while (*index + BlockLength() > max_length) { |
| 832 if (!OnBufferFull(packet, index, callback)) | 785 if (!OnBufferFull(packet, index, callback)) |
| 833 return false; | 786 return false; |
| 834 } | 787 } |
| 835 const uint8_t kFmt = 1; | 788 const uint8_t kFmt = 1; |
| 836 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index); | 789 CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 return length_; | 1085 return length_; |
| 1133 } | 1086 } |
| 1134 | 1087 |
| 1135 void RawPacket::SetLength(size_t length) { | 1088 void RawPacket::SetLength(size_t length) { |
| 1136 assert(length <= buffer_length_); | 1089 assert(length <= buffer_length_); |
| 1137 length_ = length; | 1090 length_ = length; |
| 1138 } | 1091 } |
| 1139 | 1092 |
| 1140 } // namespace rtcp | 1093 } // namespace rtcp |
| 1141 } // namespace webrtc | 1094 } // namespace webrtc |
| OLD | NEW |