| 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 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 410 |
| 411 void CreateXrBlockHeader(uint8_t block_type, | 411 void CreateXrBlockHeader(uint8_t block_type, |
| 412 uint16_t block_length, | 412 uint16_t block_length, |
| 413 uint8_t* buffer, | 413 uint8_t* buffer, |
| 414 size_t* pos) { | 414 size_t* pos) { |
| 415 AssignUWord8(buffer, pos, block_type); | 415 AssignUWord8(buffer, pos, block_type); |
| 416 AssignUWord8(buffer, pos, 0); | 416 AssignUWord8(buffer, pos, 0); |
| 417 AssignUWord16(buffer, pos, block_length); | 417 AssignUWord16(buffer, pos, block_length); |
| 418 } | 418 } |
| 419 | 419 |
| 420 // DLRR Report Block (RFC 3611). | |
| 421 // | |
| 422 // 0 1 2 3 | |
| 423 // 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 | |
| 424 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 425 // | BT=5 | reserved | block length | | |
| 426 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | |
| 427 // | SSRC_1 (SSRC of first receiver) | sub- | |
| 428 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block | |
| 429 // | last RR (LRR) | 1 | |
| 430 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 431 // | delay since last RR (DLRR) | | |
| 432 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | |
| 433 // | SSRC_2 (SSRC of second receiver) | sub- | |
| 434 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block | |
| 435 // : ... : 2 | |
| 436 | |
| 437 void CreateDlrr(const std::vector<Xr::DlrrBlock>& dlrrs, | |
| 438 uint8_t* buffer, | |
| 439 size_t* pos) { | |
| 440 for (std::vector<Xr::DlrrBlock>::const_iterator it = dlrrs.begin(); | |
| 441 it != dlrrs.end(); ++it) { | |
| 442 if ((*it).empty()) { | |
| 443 continue; | |
| 444 } | |
| 445 uint16_t block_length = 3 * (*it).size(); | |
| 446 CreateXrBlockHeader(kBtDlrr, block_length, buffer, pos); | |
| 447 for (Xr::DlrrBlock::const_iterator it_block = (*it).begin(); | |
| 448 it_block != (*it).end(); ++it_block) { | |
| 449 AssignUWord32(buffer, pos, (*it_block).SSRC); | |
| 450 AssignUWord32(buffer, pos, (*it_block).LastRR); | |
| 451 AssignUWord32(buffer, pos, (*it_block).DelayLastRR); | |
| 452 } | |
| 453 } | |
| 454 } | |
| 455 | |
| 456 // VoIP Metrics Report Block (RFC 3611). | 420 // VoIP Metrics Report Block (RFC 3611). |
| 457 // | 421 // |
| 458 // 0 1 2 3 | 422 // 0 1 2 3 |
| 459 // 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 // 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 |
| 460 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 424 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 461 // | BT=7 | reserved | block length = 8 | | 425 // | BT=7 | reserved | block length = 8 | |
| 462 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 426 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 463 // | SSRC of source | | 427 // | SSRC of source | |
| 464 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 428 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 465 // | loss rate | discard rate | burst density | gap density | | 429 // | loss rate | discard rate | burst density | gap density | |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 while (*index + BlockLength() > max_length) { | 848 while (*index + BlockLength() > max_length) { |
| 885 if (!OnBufferFull(packet, index, callback)) | 849 if (!OnBufferFull(packet, index, callback)) |
| 886 return false; | 850 return false; |
| 887 } | 851 } |
| 888 CreateHeader(0U, PT_XR, HeaderLength(), packet, index); | 852 CreateHeader(0U, PT_XR, HeaderLength(), packet, index); |
| 889 CreateXrHeader(xr_header_, packet, index); | 853 CreateXrHeader(xr_header_, packet, index); |
| 890 for (const Rrtr& block : rrtr_blocks_) { | 854 for (const Rrtr& block : rrtr_blocks_) { |
| 891 block.Create(packet + *index); | 855 block.Create(packet + *index); |
| 892 *index += Rrtr::kLength; | 856 *index += Rrtr::kLength; |
| 893 } | 857 } |
| 894 CreateDlrr(dlrr_blocks_, packet, index); | 858 for (const Dlrr& block : dlrr_blocks_) { |
| 859 block.Create(packet + *index); |
| 860 *index += block.BlockLength(); |
| 861 } |
| 895 CreateVoipMetric(voip_metric_blocks_, packet, index); | 862 CreateVoipMetric(voip_metric_blocks_, packet, index); |
| 896 return true; | 863 return true; |
| 897 } | 864 } |
| 898 | 865 |
| 899 bool Xr::WithRrtr(Rrtr* rrtr) { | 866 bool Xr::WithRrtr(Rrtr* rrtr) { |
| 900 RTC_DCHECK(rrtr); | 867 RTC_DCHECK(rrtr); |
| 901 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) { | 868 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) { |
| 902 LOG(LS_WARNING) << "Max RRTR blocks reached."; | 869 LOG(LS_WARNING) << "Max RRTR blocks reached."; |
| 903 return false; | 870 return false; |
| 904 } | 871 } |
| 905 rrtr_blocks_.push_back(*rrtr); | 872 rrtr_blocks_.push_back(*rrtr); |
| 906 return true; | 873 return true; |
| 907 } | 874 } |
| 908 | 875 |
| 909 bool Xr::WithDlrr(Dlrr* dlrr) { | 876 bool Xr::WithDlrr(Dlrr* dlrr) { |
| 910 assert(dlrr); | 877 RTC_DCHECK(dlrr); |
| 911 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) { | 878 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) { |
| 912 LOG(LS_WARNING) << "Max DLRR blocks reached."; | 879 LOG(LS_WARNING) << "Max DLRR blocks reached."; |
| 913 return false; | 880 return false; |
| 914 } | 881 } |
| 915 dlrr_blocks_.push_back(dlrr->dlrr_block_); | 882 dlrr_blocks_.push_back(std::move(*dlrr)); |
| 916 return true; | 883 return true; |
| 917 } | 884 } |
| 918 | 885 |
| 919 bool Xr::WithVoipMetric(VoipMetric* voip_metric) { | 886 bool Xr::WithVoipMetric(VoipMetric* voip_metric) { |
| 920 assert(voip_metric); | 887 assert(voip_metric); |
| 921 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) { | 888 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) { |
| 922 LOG(LS_WARNING) << "Max Voip Metric blocks reached."; | 889 LOG(LS_WARNING) << "Max Voip Metric blocks reached."; |
| 923 return false; | 890 return false; |
| 924 } | 891 } |
| 925 voip_metric_blocks_.push_back(voip_metric->metric_); | 892 voip_metric_blocks_.push_back(voip_metric->metric_); |
| 926 return true; | 893 return true; |
| 927 } | 894 } |
| 928 | 895 |
| 929 size_t Xr::DlrrLength() const { | 896 size_t Xr::DlrrLength() const { |
| 930 const size_t kBlockHeaderLen = 4; | |
| 931 const size_t kSubBlockLen = 12; | |
| 932 size_t length = 0; | 897 size_t length = 0; |
| 933 for (std::vector<DlrrBlock>::const_iterator it = dlrr_blocks_.begin(); | 898 for (const Dlrr& block : dlrr_blocks_) { |
| 934 it != dlrr_blocks_.end(); ++it) { | 899 length += block.BlockLength(); |
| 935 if (!(*it).empty()) { | |
| 936 length += kBlockHeaderLen + kSubBlockLen * (*it).size(); | |
| 937 } | |
| 938 } | 900 } |
| 939 return length; | 901 return length; |
| 940 } | 902 } |
| 941 | 903 |
| 942 bool Dlrr::WithDlrrItem(uint32_t ssrc, | |
| 943 uint32_t last_rr, | |
| 944 uint32_t delay_last_rr) { | |
| 945 if (dlrr_block_.size() >= kMaxNumberOfDlrrItems) { | |
| 946 LOG(LS_WARNING) << "Max DLRR items reached."; | |
| 947 return false; | |
| 948 } | |
| 949 RTCPPacketXRDLRRReportBlockItem dlrr; | |
| 950 dlrr.SSRC = ssrc; | |
| 951 dlrr.LastRR = last_rr; | |
| 952 dlrr.DelayLastRR = delay_last_rr; | |
| 953 dlrr_block_.push_back(dlrr); | |
| 954 return true; | |
| 955 } | |
| 956 | |
| 957 RawPacket::RawPacket(size_t buffer_length) | 904 RawPacket::RawPacket(size_t buffer_length) |
| 958 : buffer_length_(buffer_length), length_(0) { | 905 : buffer_length_(buffer_length), length_(0) { |
| 959 buffer_.reset(new uint8_t[buffer_length]); | 906 buffer_.reset(new uint8_t[buffer_length]); |
| 960 } | 907 } |
| 961 | 908 |
| 962 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) | 909 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) |
| 963 : buffer_length_(packet_length), length_(packet_length) { | 910 : buffer_length_(packet_length), length_(packet_length) { |
| 964 buffer_.reset(new uint8_t[packet_length]); | 911 buffer_.reset(new uint8_t[packet_length]); |
| 965 memcpy(buffer_.get(), packet, packet_length); | 912 memcpy(buffer_.get(), packet, packet_length); |
| 966 } | 913 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 981 return length_; | 928 return length_; |
| 982 } | 929 } |
| 983 | 930 |
| 984 void RawPacket::SetLength(size_t length) { | 931 void RawPacket::SetLength(size_t length) { |
| 985 assert(length <= buffer_length_); | 932 assert(length <= buffer_length_); |
| 986 length_ = length; | 933 length_ = length; |
| 987 } | 934 } |
| 988 | 935 |
| 989 } // namespace rtcp | 936 } // namespace rtcp |
| 990 } // namespace webrtc | 937 } // namespace webrtc |
| OLD | NEW |