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

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

Issue 1453973005: [rtp_rtcp] rtcp::Dlrr block moved into own file and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: made Dlrr block copyable instead of movable Created 5 years 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) 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
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 400 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
401 // : report blocks : 401 // : report blocks :
402 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 402 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
403 403
404 void CreateXrHeader(const RTCPPacketXR& header, 404 void CreateXrHeader(const RTCPPacketXR& header,
405 uint8_t* buffer, 405 uint8_t* buffer,
406 size_t* pos) { 406 size_t* pos) {
407 AssignUWord32(buffer, pos, header.OriginatorSSRC); 407 AssignUWord32(buffer, pos, header.OriginatorSSRC);
408 } 408 }
409 409
410 void CreateXrBlockHeader(uint8_t block_type,
411 uint16_t block_length,
412 uint8_t* buffer,
413 size_t* pos) {
414 AssignUWord8(buffer, pos, block_type);
415 AssignUWord8(buffer, pos, 0);
416 AssignUWord16(buffer, pos, block_length);
417 }
418
419 // DLRR Report Block (RFC 3611).
420 //
421 // 0 1 2 3
422 // 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
423 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
424 // | BT=5 | reserved | block length |
425 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
426 // | SSRC_1 (SSRC of first receiver) | sub-
427 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
428 // | last RR (LRR) | 1
429 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
430 // | delay since last RR (DLRR) |
431 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
432 // | SSRC_2 (SSRC of second receiver) | sub-
433 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
434 // : ... : 2
435
436 void CreateDlrr(const std::vector<Xr::DlrrBlock>& dlrrs,
437 uint8_t* buffer,
438 size_t* pos) {
439 for (std::vector<Xr::DlrrBlock>::const_iterator it = dlrrs.begin();
440 it != dlrrs.end(); ++it) {
441 if ((*it).empty()) {
442 continue;
443 }
444 uint16_t block_length = 3 * (*it).size();
445 CreateXrBlockHeader(kBtDlrr, block_length, buffer, pos);
446 for (Xr::DlrrBlock::const_iterator it_block = (*it).begin();
447 it_block != (*it).end(); ++it_block) {
448 AssignUWord32(buffer, pos, (*it_block).SSRC);
449 AssignUWord32(buffer, pos, (*it_block).LastRR);
450 AssignUWord32(buffer, pos, (*it_block).DelayLastRR);
451 }
452 }
453 }
454 } // namespace 410 } // namespace
455 411
456 void RtcpPacket::Append(RtcpPacket* packet) { 412 void RtcpPacket::Append(RtcpPacket* packet) {
457 assert(packet); 413 assert(packet);
458 appended_packets_.push_back(packet); 414 appended_packets_.push_back(packet);
459 } 415 }
460 416
461 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { 417 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const {
462 size_t length = 0; 418 size_t length = 0;
463 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); 419 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE));
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 while (*index + BlockLength() > max_length) { 783 while (*index + BlockLength() > max_length) {
828 if (!OnBufferFull(packet, index, callback)) 784 if (!OnBufferFull(packet, index, callback))
829 return false; 785 return false;
830 } 786 }
831 CreateHeader(0U, PT_XR, HeaderLength(), packet, index); 787 CreateHeader(0U, PT_XR, HeaderLength(), packet, index);
832 CreateXrHeader(xr_header_, packet, index); 788 CreateXrHeader(xr_header_, packet, index);
833 for (const Rrtr& block : rrtr_blocks_) { 789 for (const Rrtr& block : rrtr_blocks_) {
834 block.Create(packet + *index); 790 block.Create(packet + *index);
835 *index += Rrtr::kLength; 791 *index += Rrtr::kLength;
836 } 792 }
837 CreateDlrr(dlrr_blocks_, packet, index); 793 for (const Dlrr& block : dlrr_blocks_) {
794 block.Create(packet + *index);
795 *index += block.BlockLength();
796 }
838 for (const VoipMetric& block : voip_metric_blocks_) { 797 for (const VoipMetric& block : voip_metric_blocks_) {
839 block.Create(packet + *index); 798 block.Create(packet + *index);
840 *index += VoipMetric::kLength; 799 *index += VoipMetric::kLength;
841 } 800 }
842 return true; 801 return true;
843 } 802 }
844 803
845 bool Xr::WithRrtr(Rrtr* rrtr) { 804 bool Xr::WithRrtr(Rrtr* rrtr) {
846 RTC_DCHECK(rrtr); 805 RTC_DCHECK(rrtr);
847 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) { 806 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) {
848 LOG(LS_WARNING) << "Max RRTR blocks reached."; 807 LOG(LS_WARNING) << "Max RRTR blocks reached.";
849 return false; 808 return false;
850 } 809 }
851 rrtr_blocks_.push_back(*rrtr); 810 rrtr_blocks_.push_back(*rrtr);
852 return true; 811 return true;
853 } 812 }
854 813
855 bool Xr::WithDlrr(Dlrr* dlrr) { 814 bool Xr::WithDlrr(Dlrr* dlrr) {
856 assert(dlrr); 815 RTC_DCHECK(dlrr);
857 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) { 816 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) {
858 LOG(LS_WARNING) << "Max DLRR blocks reached."; 817 LOG(LS_WARNING) << "Max DLRR blocks reached.";
859 return false; 818 return false;
860 } 819 }
861 dlrr_blocks_.push_back(dlrr->dlrr_block_); 820 dlrr_blocks_.push_back(*dlrr);
862 return true; 821 return true;
863 } 822 }
864 823
865 bool Xr::WithVoipMetric(VoipMetric* voip_metric) { 824 bool Xr::WithVoipMetric(VoipMetric* voip_metric) {
866 assert(voip_metric); 825 assert(voip_metric);
867 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) { 826 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) {
868 LOG(LS_WARNING) << "Max Voip Metric blocks reached."; 827 LOG(LS_WARNING) << "Max Voip Metric blocks reached.";
869 return false; 828 return false;
870 } 829 }
871 voip_metric_blocks_.push_back(*voip_metric); 830 voip_metric_blocks_.push_back(*voip_metric);
872 return true; 831 return true;
873 } 832 }
874 833
875 size_t Xr::DlrrLength() const { 834 size_t Xr::DlrrLength() const {
876 const size_t kBlockHeaderLen = 4;
877 const size_t kSubBlockLen = 12;
878 size_t length = 0; 835 size_t length = 0;
879 for (std::vector<DlrrBlock>::const_iterator it = dlrr_blocks_.begin(); 836 for (const Dlrr& block : dlrr_blocks_) {
880 it != dlrr_blocks_.end(); ++it) { 837 length += block.BlockLength();
881 if (!(*it).empty()) {
882 length += kBlockHeaderLen + kSubBlockLen * (*it).size();
883 }
884 } 838 }
885 return length; 839 return length;
886 } 840 }
887 841
888 bool Dlrr::WithDlrrItem(uint32_t ssrc,
889 uint32_t last_rr,
890 uint32_t delay_last_rr) {
891 if (dlrr_block_.size() >= kMaxNumberOfDlrrItems) {
892 LOG(LS_WARNING) << "Max DLRR items reached.";
893 return false;
894 }
895 RTCPPacketXRDLRRReportBlockItem dlrr;
896 dlrr.SSRC = ssrc;
897 dlrr.LastRR = last_rr;
898 dlrr.DelayLastRR = delay_last_rr;
899 dlrr_block_.push_back(dlrr);
900 return true;
901 }
902
903 RawPacket::RawPacket(size_t buffer_length) 842 RawPacket::RawPacket(size_t buffer_length)
904 : buffer_length_(buffer_length), length_(0) { 843 : buffer_length_(buffer_length), length_(0) {
905 buffer_.reset(new uint8_t[buffer_length]); 844 buffer_.reset(new uint8_t[buffer_length]);
906 } 845 }
907 846
908 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) 847 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length)
909 : buffer_length_(packet_length), length_(packet_length) { 848 : buffer_length_(packet_length), length_(packet_length) {
910 buffer_.reset(new uint8_t[packet_length]); 849 buffer_.reset(new uint8_t[packet_length]);
911 memcpy(buffer_.get(), packet, packet_length); 850 memcpy(buffer_.get(), packet, packet_length);
912 } 851 }
(...skipping 14 matching lines...) Expand all
927 return length_; 866 return length_;
928 } 867 }
929 868
930 void RawPacket::SetLength(size_t length) { 869 void RawPacket::SetLength(size_t length) {
931 assert(length <= buffer_length_); 870 assert(length <= buffer_length_);
932 length_ = length; 871 length_ = length;
933 } 872 }
934 873
935 } // namespace rtcp 874 } // namespace rtcp
936 } // namespace webrtc 875 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/dlrr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698