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::RTCPPacketPSFBAPP; | 27 using webrtc::RTCPUtility::RTCPPacketPSFBAPP; |
33 using webrtc::RTCPUtility::RTCPPacketPSFBFIR; | 28 using webrtc::RTCPUtility::RTCPPacketPSFBFIR; |
34 using webrtc::RTCPUtility::RTCPPacketPSFBFIRItem; | 29 using webrtc::RTCPUtility::RTCPPacketPSFBFIRItem; |
35 using webrtc::RTCPUtility::RTCPPacketPSFBREMBItem; | 30 using webrtc::RTCPUtility::RTCPPacketPSFBREMBItem; |
36 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; | 31 using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; |
37 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; | 32 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; |
38 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; | 33 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; |
39 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; | 34 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; |
40 using webrtc::RTCPUtility::RTCPPacketSR; | 35 using webrtc::RTCPUtility::RTCPPacketSR; |
41 using webrtc::RTCPUtility::RTCPPacketXRDLRRReportBlockItem; | |
42 using webrtc::RTCPUtility::RTCPPacketXR; | |
43 | 36 |
44 namespace webrtc { | 37 namespace webrtc { |
45 namespace rtcp { | 38 namespace rtcp { |
46 namespace { | 39 namespace { |
47 // Unused SSRC of media source, set to 0. | 40 // Unused SSRC of media source, set to 0. |
48 const uint32_t kUnusedMediaSourceSsrc0 = 0; | 41 const uint32_t kUnusedMediaSourceSsrc0 = 0; |
49 | 42 |
50 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { | 43 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { |
51 buffer[(*offset)++] = value; | 44 buffer[(*offset)++] = value; |
52 } | 45 } |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 AssignUWord8(buffer, pos, 'M'); | 257 AssignUWord8(buffer, pos, 'M'); |
265 AssignUWord8(buffer, pos, 'B'); | 258 AssignUWord8(buffer, pos, 'B'); |
266 AssignUWord8(buffer, pos, remb_item.NumberOfSSRCs); | 259 AssignUWord8(buffer, pos, remb_item.NumberOfSSRCs); |
267 AssignUWord8(buffer, pos, (exp << 2) + ((mantissa >> 16) & 0x03)); | 260 AssignUWord8(buffer, pos, (exp << 2) + ((mantissa >> 16) & 0x03)); |
268 AssignUWord8(buffer, pos, mantissa >> 8); | 261 AssignUWord8(buffer, pos, mantissa >> 8); |
269 AssignUWord8(buffer, pos, mantissa); | 262 AssignUWord8(buffer, pos, mantissa); |
270 for (uint8_t i = 0; i < remb_item.NumberOfSSRCs; ++i) { | 263 for (uint8_t i = 0; i < remb_item.NumberOfSSRCs; ++i) { |
271 AssignUWord32(buffer, pos, remb_item.SSRCs[i]); | 264 AssignUWord32(buffer, pos, remb_item.SSRCs[i]); |
272 } | 265 } |
273 } | 266 } |
274 | |
275 // From RFC 3611: RTP Control Protocol Extended Reports (RTCP XR). | |
276 // | |
277 // Format for XR packets: | |
278 // | |
279 // 0 1 2 3 | |
280 // 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 | |
281 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
282 // |V=2|P|reserved | PT=XR=207 | length | | |
283 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
284 // | SSRC | | |
285 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
286 // : report blocks : | |
287 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
288 | |
289 void CreateXrHeader(const RTCPPacketXR& header, | |
290 uint8_t* buffer, | |
291 size_t* pos) { | |
292 AssignUWord32(buffer, pos, header.OriginatorSSRC); | |
293 } | |
294 | |
295 } // namespace | 267 } // namespace |
296 | 268 |
297 void RtcpPacket::Append(RtcpPacket* packet) { | 269 void RtcpPacket::Append(RtcpPacket* packet) { |
298 assert(packet); | 270 assert(packet); |
299 appended_packets_.push_back(packet); | 271 appended_packets_.push_back(packet); |
300 } | 272 } |
301 | 273 |
302 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { | 274 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { |
303 size_t length = 0; | 275 size_t length = 0; |
304 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); | 276 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } | 500 } |
529 | 501 |
530 void Remb::AppliesTo(uint32_t ssrc) { | 502 void Remb::AppliesTo(uint32_t ssrc) { |
531 if (remb_item_.NumberOfSSRCs >= kMaxNumberOfSsrcs) { | 503 if (remb_item_.NumberOfSSRCs >= kMaxNumberOfSsrcs) { |
532 LOG(LS_WARNING) << "Max number of REMB feedback SSRCs reached."; | 504 LOG(LS_WARNING) << "Max number of REMB feedback SSRCs reached."; |
533 return; | 505 return; |
534 } | 506 } |
535 remb_item_.SSRCs[remb_item_.NumberOfSSRCs++] = ssrc; | 507 remb_item_.SSRCs[remb_item_.NumberOfSSRCs++] = ssrc; |
536 } | 508 } |
537 | 509 |
538 bool Xr::Create(uint8_t* packet, | |
539 size_t* index, | |
540 size_t max_length, | |
541 RtcpPacket::PacketReadyCallback* callback) const { | |
542 while (*index + BlockLength() > max_length) { | |
543 if (!OnBufferFull(packet, index, callback)) | |
544 return false; | |
545 } | |
546 CreateHeader(0U, PT_XR, HeaderLength(), packet, index); | |
547 CreateXrHeader(xr_header_, packet, index); | |
548 for (const Rrtr& block : rrtr_blocks_) { | |
549 block.Create(packet + *index); | |
550 *index += Rrtr::kLength; | |
551 } | |
552 for (const Dlrr& block : dlrr_blocks_) { | |
553 block.Create(packet + *index); | |
554 *index += block.BlockLength(); | |
555 } | |
556 for (const VoipMetric& block : voip_metric_blocks_) { | |
557 block.Create(packet + *index); | |
558 *index += VoipMetric::kLength; | |
559 } | |
560 return true; | |
561 } | |
562 | |
563 bool Xr::WithRrtr(Rrtr* rrtr) { | |
564 RTC_DCHECK(rrtr); | |
565 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) { | |
566 LOG(LS_WARNING) << "Max RRTR blocks reached."; | |
567 return false; | |
568 } | |
569 rrtr_blocks_.push_back(*rrtr); | |
570 return true; | |
571 } | |
572 | |
573 bool Xr::WithDlrr(Dlrr* dlrr) { | |
574 RTC_DCHECK(dlrr); | |
575 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) { | |
576 LOG(LS_WARNING) << "Max DLRR blocks reached."; | |
577 return false; | |
578 } | |
579 dlrr_blocks_.push_back(*dlrr); | |
580 return true; | |
581 } | |
582 | |
583 bool Xr::WithVoipMetric(VoipMetric* voip_metric) { | |
584 assert(voip_metric); | |
585 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) { | |
586 LOG(LS_WARNING) << "Max Voip Metric blocks reached."; | |
587 return false; | |
588 } | |
589 voip_metric_blocks_.push_back(*voip_metric); | |
590 return true; | |
591 } | |
592 | |
593 size_t Xr::DlrrLength() const { | |
594 size_t length = 0; | |
595 for (const Dlrr& block : dlrr_blocks_) { | |
596 length += block.BlockLength(); | |
597 } | |
598 return length; | |
599 } | |
600 | |
601 RawPacket::RawPacket(size_t buffer_length) | 510 RawPacket::RawPacket(size_t buffer_length) |
602 : buffer_length_(buffer_length), length_(0) { | 511 : buffer_length_(buffer_length), length_(0) { |
603 buffer_.reset(new uint8_t[buffer_length]); | 512 buffer_.reset(new uint8_t[buffer_length]); |
604 } | 513 } |
605 | 514 |
606 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) | 515 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) |
607 : buffer_length_(packet_length), length_(packet_length) { | 516 : buffer_length_(packet_length), length_(packet_length) { |
608 buffer_.reset(new uint8_t[packet_length]); | 517 buffer_.reset(new uint8_t[packet_length]); |
609 memcpy(buffer_.get(), packet, packet_length); | 518 memcpy(buffer_.get(), packet, packet_length); |
610 } | 519 } |
(...skipping 14 matching lines...) Expand all Loading... |
625 return length_; | 534 return length_; |
626 } | 535 } |
627 | 536 |
628 void RawPacket::SetLength(size_t length) { | 537 void RawPacket::SetLength(size_t length) { |
629 assert(length <= buffer_length_); | 538 assert(length <= buffer_length_); |
630 length_ = length; | 539 length_ = length; |
631 } | 540 } |
632 | 541 |
633 } // namespace rtcp | 542 } // namespace rtcp |
634 } // namespace webrtc | 543 } // namespace webrtc |
OLD | NEW |