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 28 matching lines...) Expand all Loading... |
39 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; | 39 using webrtc::RTCPUtility::RTCPPacketReportBlockItem; |
40 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; | 40 using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; |
41 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; | 41 using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; |
42 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBN; | 42 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBN; |
43 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBNItem; | 43 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBNItem; |
44 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBR; | 44 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBR; |
45 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBRItem; | 45 using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBRItem; |
46 using webrtc::RTCPUtility::RTCPPacketSR; | 46 using webrtc::RTCPUtility::RTCPPacketSR; |
47 using webrtc::RTCPUtility::RTCPPacketXRDLRRReportBlockItem; | 47 using webrtc::RTCPUtility::RTCPPacketXRDLRRReportBlockItem; |
48 using webrtc::RTCPUtility::RTCPPacketXR; | 48 using webrtc::RTCPUtility::RTCPPacketXR; |
49 using webrtc::RTCPUtility::RTCPPacketXRVOIPMetricItem; | |
50 | 49 |
51 namespace webrtc { | 50 namespace webrtc { |
52 namespace rtcp { | 51 namespace rtcp { |
53 namespace { | 52 namespace { |
54 // Unused SSRC of media source, set to 0. | 53 // Unused SSRC of media source, set to 0. |
55 const uint32_t kUnusedMediaSourceSsrc0 = 0; | 54 const uint32_t kUnusedMediaSourceSsrc0 = 0; |
56 | 55 |
57 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { | 56 void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { |
58 buffer[(*offset)++] = value; | 57 buffer[(*offset)++] = value; |
59 } | 58 } |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 uint16_t block_length = 3 * (*it).size(); | 444 uint16_t block_length = 3 * (*it).size(); |
446 CreateXrBlockHeader(kBtDlrr, block_length, buffer, pos); | 445 CreateXrBlockHeader(kBtDlrr, block_length, buffer, pos); |
447 for (Xr::DlrrBlock::const_iterator it_block = (*it).begin(); | 446 for (Xr::DlrrBlock::const_iterator it_block = (*it).begin(); |
448 it_block != (*it).end(); ++it_block) { | 447 it_block != (*it).end(); ++it_block) { |
449 AssignUWord32(buffer, pos, (*it_block).SSRC); | 448 AssignUWord32(buffer, pos, (*it_block).SSRC); |
450 AssignUWord32(buffer, pos, (*it_block).LastRR); | 449 AssignUWord32(buffer, pos, (*it_block).LastRR); |
451 AssignUWord32(buffer, pos, (*it_block).DelayLastRR); | 450 AssignUWord32(buffer, pos, (*it_block).DelayLastRR); |
452 } | 451 } |
453 } | 452 } |
454 } | 453 } |
455 | |
456 // VoIP Metrics Report Block (RFC 3611). | |
457 // | |
458 // 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 | |
460 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
461 // | BT=7 | reserved | block length = 8 | | |
462 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
463 // | SSRC of source | | |
464 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
465 // | loss rate | discard rate | burst density | gap density | | |
466 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
467 // | burst duration | gap duration | | |
468 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
469 // | round trip delay | end system delay | | |
470 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
471 // | signal level | noise level | RERL | Gmin | | |
472 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
473 // | R factor | ext. R factor | MOS-LQ | MOS-CQ | | |
474 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
475 // | RX config | reserved | JB nominal | | |
476 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
477 // | JB maximum | JB abs max | | |
478 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
479 | |
480 void CreateVoipMetric(const std::vector<RTCPPacketXRVOIPMetricItem>& metrics, | |
481 uint8_t* buffer, | |
482 size_t* pos) { | |
483 const uint16_t kBlockLength = 8; | |
484 for (std::vector<RTCPPacketXRVOIPMetricItem>::const_iterator it = | |
485 metrics.begin(); it != metrics.end(); ++it) { | |
486 CreateXrBlockHeader(kBtVoipMetric, kBlockLength, buffer, pos); | |
487 AssignUWord32(buffer, pos, (*it).SSRC); | |
488 AssignUWord8(buffer, pos, (*it).lossRate); | |
489 AssignUWord8(buffer, pos, (*it).discardRate); | |
490 AssignUWord8(buffer, pos, (*it).burstDensity); | |
491 AssignUWord8(buffer, pos, (*it).gapDensity); | |
492 AssignUWord16(buffer, pos, (*it).burstDuration); | |
493 AssignUWord16(buffer, pos, (*it).gapDuration); | |
494 AssignUWord16(buffer, pos, (*it).roundTripDelay); | |
495 AssignUWord16(buffer, pos, (*it).endSystemDelay); | |
496 AssignUWord8(buffer, pos, (*it).signalLevel); | |
497 AssignUWord8(buffer, pos, (*it).noiseLevel); | |
498 AssignUWord8(buffer, pos, (*it).RERL); | |
499 AssignUWord8(buffer, pos, (*it).Gmin); | |
500 AssignUWord8(buffer, pos, (*it).Rfactor); | |
501 AssignUWord8(buffer, pos, (*it).extRfactor); | |
502 AssignUWord8(buffer, pos, (*it).MOSLQ); | |
503 AssignUWord8(buffer, pos, (*it).MOSCQ); | |
504 AssignUWord8(buffer, pos, (*it).RXconfig); | |
505 AssignUWord8(buffer, pos, 0); | |
506 AssignUWord16(buffer, pos, (*it).JBnominal); | |
507 AssignUWord16(buffer, pos, (*it).JBmax); | |
508 AssignUWord16(buffer, pos, (*it).JBabsMax); | |
509 } | |
510 } | |
511 } // namespace | 454 } // namespace |
512 | 455 |
513 void RtcpPacket::Append(RtcpPacket* packet) { | 456 void RtcpPacket::Append(RtcpPacket* packet) { |
514 assert(packet); | 457 assert(packet); |
515 appended_packets_.push_back(packet); | 458 appended_packets_.push_back(packet); |
516 } | 459 } |
517 | 460 |
518 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { | 461 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { |
519 size_t length = 0; | 462 size_t length = 0; |
520 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); | 463 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 if (!OnBufferFull(packet, index, callback)) | 828 if (!OnBufferFull(packet, index, callback)) |
886 return false; | 829 return false; |
887 } | 830 } |
888 CreateHeader(0U, PT_XR, HeaderLength(), packet, index); | 831 CreateHeader(0U, PT_XR, HeaderLength(), packet, index); |
889 CreateXrHeader(xr_header_, packet, index); | 832 CreateXrHeader(xr_header_, packet, index); |
890 for (const Rrtr& block : rrtr_blocks_) { | 833 for (const Rrtr& block : rrtr_blocks_) { |
891 block.Create(packet + *index); | 834 block.Create(packet + *index); |
892 *index += Rrtr::kLength; | 835 *index += Rrtr::kLength; |
893 } | 836 } |
894 CreateDlrr(dlrr_blocks_, packet, index); | 837 CreateDlrr(dlrr_blocks_, packet, index); |
895 CreateVoipMetric(voip_metric_blocks_, packet, index); | 838 for (const VoipMetric& block : voip_metric_blocks_) { |
| 839 block.Create(packet + *index); |
| 840 *index += VoipMetric::kLength; |
| 841 } |
896 return true; | 842 return true; |
897 } | 843 } |
898 | 844 |
899 bool Xr::WithRrtr(Rrtr* rrtr) { | 845 bool Xr::WithRrtr(Rrtr* rrtr) { |
900 RTC_DCHECK(rrtr); | 846 RTC_DCHECK(rrtr); |
901 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) { | 847 if (rrtr_blocks_.size() >= kMaxNumberOfRrtrBlocks) { |
902 LOG(LS_WARNING) << "Max RRTR blocks reached."; | 848 LOG(LS_WARNING) << "Max RRTR blocks reached."; |
903 return false; | 849 return false; |
904 } | 850 } |
905 rrtr_blocks_.push_back(*rrtr); | 851 rrtr_blocks_.push_back(*rrtr); |
906 return true; | 852 return true; |
907 } | 853 } |
908 | 854 |
909 bool Xr::WithDlrr(Dlrr* dlrr) { | 855 bool Xr::WithDlrr(Dlrr* dlrr) { |
910 assert(dlrr); | 856 assert(dlrr); |
911 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) { | 857 if (dlrr_blocks_.size() >= kMaxNumberOfDlrrBlocks) { |
912 LOG(LS_WARNING) << "Max DLRR blocks reached."; | 858 LOG(LS_WARNING) << "Max DLRR blocks reached."; |
913 return false; | 859 return false; |
914 } | 860 } |
915 dlrr_blocks_.push_back(dlrr->dlrr_block_); | 861 dlrr_blocks_.push_back(dlrr->dlrr_block_); |
916 return true; | 862 return true; |
917 } | 863 } |
918 | 864 |
919 bool Xr::WithVoipMetric(VoipMetric* voip_metric) { | 865 bool Xr::WithVoipMetric(VoipMetric* voip_metric) { |
920 assert(voip_metric); | 866 assert(voip_metric); |
921 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) { | 867 if (voip_metric_blocks_.size() >= kMaxNumberOfVoipMetricBlocks) { |
922 LOG(LS_WARNING) << "Max Voip Metric blocks reached."; | 868 LOG(LS_WARNING) << "Max Voip Metric blocks reached."; |
923 return false; | 869 return false; |
924 } | 870 } |
925 voip_metric_blocks_.push_back(voip_metric->metric_); | 871 voip_metric_blocks_.push_back(*voip_metric); |
926 return true; | 872 return true; |
927 } | 873 } |
928 | 874 |
929 size_t Xr::DlrrLength() const { | 875 size_t Xr::DlrrLength() const { |
930 const size_t kBlockHeaderLen = 4; | 876 const size_t kBlockHeaderLen = 4; |
931 const size_t kSubBlockLen = 12; | 877 const size_t kSubBlockLen = 12; |
932 size_t length = 0; | 878 size_t length = 0; |
933 for (std::vector<DlrrBlock>::const_iterator it = dlrr_blocks_.begin(); | 879 for (std::vector<DlrrBlock>::const_iterator it = dlrr_blocks_.begin(); |
934 it != dlrr_blocks_.end(); ++it) { | 880 it != dlrr_blocks_.end(); ++it) { |
935 if (!(*it).empty()) { | 881 if (!(*it).empty()) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 return length_; | 927 return length_; |
982 } | 928 } |
983 | 929 |
984 void RawPacket::SetLength(size_t length) { | 930 void RawPacket::SetLength(size_t length) { |
985 assert(length <= buffer_length_); | 931 assert(length <= buffer_length_); |
986 length_ = length; | 932 length_ = length; |
987 } | 933 } |
988 | 934 |
989 } // namespace rtcp | 935 } // namespace rtcp |
990 } // namespace webrtc | 936 } // namespace webrtc |
OLD | NEW |