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 // Application-Defined packet (APP) (RFC 3550). | 206 // Application-Defined packet (APP) (RFC 3550). |
231 // | 207 // |
232 // 0 1 2 3 | 208 // 0 1 2 3 |
233 // 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 | 209 // 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 |
234 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 210 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
235 // |V=2|P| subtype | PT=APP=204 | length | | 211 // |V=2|P| subtype | PT=APP=204 | length | |
236 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 212 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
237 // | SSRC/CSRC | | 213 // | SSRC/CSRC | |
238 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 214 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
239 // | name (ASCII) | | 215 // | name (ASCII) | |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 // Header (4 bytes). | 794 // Header (4 bytes). |
819 // Chunk: | 795 // Chunk: |
820 // SSRC/CSRC (4 bytes) | CNAME (1 byte) | length (1 byte) | name | padding. | 796 // SSRC/CSRC (4 bytes) | CNAME (1 byte) | length (1 byte) | name | padding. |
821 size_t length = kHeaderLength; | 797 size_t length = kHeaderLength; |
822 for (const Chunk& chunk : chunks_) | 798 for (const Chunk& chunk : chunks_) |
823 length += 6 + chunk.name.length() + chunk.null_octets; | 799 length += 6 + chunk.name.length() + chunk.null_octets; |
824 assert(length % 4 == 0); | 800 assert(length % 4 == 0); |
825 return length; | 801 return length; |
826 } | 802 } |
827 | 803 |
828 bool Bye::Create(uint8_t* packet, | |
829 size_t* index, | |
830 size_t max_length, | |
831 RtcpPacket::PacketReadyCallback* callback) const { | |
832 while (*index + BlockLength() > max_length) { | |
833 if (!OnBufferFull(packet, index, callback)) | |
834 return false; | |
835 } | |
836 size_t length = HeaderLength(); | |
837 CreateHeader(length, PT_BYE, length, packet, index); | |
838 CreateBye(bye_, csrcs_, packet, index); | |
839 return true; | |
840 } | |
841 | |
842 bool Bye::WithCsrc(uint32_t csrc) { | |
843 if (csrcs_.size() >= kMaxNumberOfCsrcs) { | |
844 LOG(LS_WARNING) << "Max CSRC size reached."; | |
845 return false; | |
846 } | |
847 csrcs_.push_back(csrc); | |
848 return true; | |
849 } | |
850 | |
851 bool App::Create(uint8_t* packet, | 804 bool App::Create(uint8_t* packet, |
852 size_t* index, | 805 size_t* index, |
853 size_t max_length, | 806 size_t max_length, |
854 RtcpPacket::PacketReadyCallback* callback) const { | 807 RtcpPacket::PacketReadyCallback* callback) const { |
855 while (*index + BlockLength() > max_length) { | 808 while (*index + BlockLength() > max_length) { |
856 if (!OnBufferFull(packet, index, callback)) | 809 if (!OnBufferFull(packet, index, callback)) |
857 return false; | 810 return false; |
858 } | 811 } |
859 CreateHeader(app_.SubType, PT_APP, HeaderLength(), packet, index); | 812 CreateHeader(app_.SubType, PT_APP, HeaderLength(), packet, index); |
860 CreateApp(app_, ssrc_, packet, index); | 813 CreateApp(app_, ssrc_, packet, index); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 return length_; | 1122 return length_; |
1170 } | 1123 } |
1171 | 1124 |
1172 void RawPacket::SetLength(size_t length) { | 1125 void RawPacket::SetLength(size_t length) { |
1173 assert(length <= buffer_length_); | 1126 assert(length <= buffer_length_); |
1174 length_ = length; | 1127 length_ = length; |
1175 } | 1128 } |
1176 | 1129 |
1177 } // namespace rtcp | 1130 } // namespace rtcp |
1178 } // namespace webrtc | 1131 } // namespace webrtc |
OLD | NEW |