diff options
author | danilchap <danilchap@webrtc.org> | 2015-12-15 07:06:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-15 15:06:44 +0000 |
commit | 91941ae493cb37a4e1250c7d3aad1c7394b5850e (patch) | |
tree | d85680a67d22a03e51a74812fd3061a8b1f636ef /webrtc/modules | |
parent | 32d989b3f2d168327ed43d0e4c493550ccee4179 (diff) | |
download | webrtc-91941ae493cb37a4e1250c7d3aad1c7394b5850e.tar.gz |
rtcp::VoipMetric block moved into own file and got Parse function
Review URL: https://codereview.webrtc.org/1452733002
Cr-Commit-Position: refs/heads/master@{#11030}
Diffstat (limited to 'webrtc/modules')
-rw-r--r-- | webrtc/modules/modules.gyp | 1 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/BUILD.gn | 2 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/rtp_rtcp.gypi | 2 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/rtcp_packet.cc | 64 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/rtcp_packet.h | 77 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.cc | 107 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.h | 53 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric_unittest.cc | 93 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/rtcp_packet_unittest.cc | 49 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc | 4 | ||||
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/rtcp_sender.cc | 21 |
11 files changed, 295 insertions, 178 deletions
diff --git a/webrtc/modules/modules.gyp b/webrtc/modules/modules.gyp index cac5f400ad..f58e0f4034 100644 --- a/webrtc/modules/modules.gyp +++ b/webrtc/modules/modules.gyp @@ -312,6 +312,7 @@ 'rtp_rtcp/source/rtcp_packet/report_block_unittest.cc', 'rtp_rtcp/source/rtcp_packet/rrtr_unittest.cc', 'rtp_rtcp/source/rtcp_packet/transport_feedback_unittest.cc', + 'rtp_rtcp/source/rtcp_packet/voip_metric_unittest.cc', 'rtp_rtcp/source/rtcp_receiver_unittest.cc', 'rtp_rtcp/source/rtcp_sender_unittest.cc', 'rtp_rtcp/source/rtcp_utility_unittest.cc', diff --git a/webrtc/modules/rtp_rtcp/BUILD.gn b/webrtc/modules/rtp_rtcp/BUILD.gn index 20b207547d..be6e2e4c7d 100644 --- a/webrtc/modules/rtp_rtcp/BUILD.gn +++ b/webrtc/modules/rtp_rtcp/BUILD.gn @@ -64,6 +64,8 @@ source_set("rtp_rtcp") { "source/rtcp_packet/rrtr.h", "source/rtcp_packet/transport_feedback.cc", "source/rtcp_packet/transport_feedback.h", + "source/rtcp_packet/voip_metric.cc", + "source/rtcp_packet/voip_metric.h", "source/rtcp_receiver.cc", "source/rtcp_receiver.h", "source/rtcp_receiver_help.cc", diff --git a/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi b/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi index 92821352ee..1b88055695 100644 --- a/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi +++ b/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi @@ -59,6 +59,8 @@ 'source/rtcp_packet/rrtr.h', 'source/rtcp_packet/transport_feedback.cc', 'source/rtcp_packet/transport_feedback.h', + 'source/rtcp_packet/voip_metric.cc', + 'source/rtcp_packet/voip_metric.h', 'source/rtcp_receiver.cc', 'source/rtcp_receiver.h', 'source/rtcp_receiver_help.cc', diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc index cae479e39d..28cb20eca2 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc @@ -46,7 +46,6 @@ using webrtc::RTCPUtility::RTCPPacketRTPFBTMMBRItem; using webrtc::RTCPUtility::RTCPPacketSR; using webrtc::RTCPUtility::RTCPPacketXRDLRRReportBlockItem; using webrtc::RTCPUtility::RTCPPacketXR; -using webrtc::RTCPUtility::RTCPPacketXRVOIPMetricItem; namespace webrtc { namespace rtcp { @@ -452,62 +451,6 @@ void CreateDlrr(const std::vector<Xr::DlrrBlock>& dlrrs, } } } - -// VoIP Metrics Report Block (RFC 3611). -// -// 0 1 2 3 -// 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 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | BT=7 | reserved | block length = 8 | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | SSRC of source | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | loss rate | discard rate | burst density | gap density | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | burst duration | gap duration | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | round trip delay | end system delay | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | signal level | noise level | RERL | Gmin | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | R factor | ext. R factor | MOS-LQ | MOS-CQ | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | RX config | reserved | JB nominal | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | JB maximum | JB abs max | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - -void CreateVoipMetric(const std::vector<RTCPPacketXRVOIPMetricItem>& metrics, - uint8_t* buffer, - size_t* pos) { - const uint16_t kBlockLength = 8; - for (std::vector<RTCPPacketXRVOIPMetricItem>::const_iterator it = - metrics.begin(); it != metrics.end(); ++it) { - CreateXrBlockHeader(kBtVoipMetric, kBlockLength, buffer, pos); - AssignUWord32(buffer, pos, (*it).SSRC); - AssignUWord8(buffer, pos, (*it).lossRate); - AssignUWord8(buffer, pos, (*it).discardRate); - AssignUWord8(buffer, pos, (*it).burstDensity); - AssignUWord8(buffer, pos, (*it).gapDensity); - AssignUWord16(buffer, pos, (*it).burstDuration); - AssignUWord16(buffer, pos, (*it).gapDuration); - AssignUWord16(buffer, pos, (*it).roundTripDelay); - AssignUWord16(buffer, pos, (*it).endSystemDelay); - AssignUWord8(buffer, pos, (*it).signalLevel); - AssignUWord8(buffer, pos, (*it).noiseLevel); - AssignUWord8(buffer, pos, (*it).RERL); - AssignUWord8(buffer, pos, (*it).Gmin); - AssignUWord8(buffer, pos, (*it).Rfactor); - AssignUWord8(buffer, pos, (*it).extRfactor); - AssignUWord8(buffer, pos, (*it).MOSLQ); - AssignUWord8(buffer, pos, (*it).MOSCQ); - AssignUWord8(buffer, pos, (*it).RXconfig); - AssignUWord8(buffer, pos, 0); - AssignUWord16(buffer, pos, (*it).JBnominal); - AssignUWord16(buffer, pos, (*it).JBmax); - AssignUWord16(buffer, pos, (*it).JBabsMax); - } -} } // namespace void RtcpPacket::Append(RtcpPacket* packet) { @@ -892,7 +835,10 @@ bool Xr::Create(uint8_t* packet, *index += Rrtr::kLength; } CreateDlrr(dlrr_blocks_, packet, index); - CreateVoipMetric(voip_metric_blocks_, packet, index); + for (const VoipMetric& block : voip_metric_blocks_) { + block.Create(packet + *index); + *index += VoipMetric::kLength; + } return true; } @@ -922,7 +868,7 @@ bool Xr::WithVoipMetric(VoipMetric* voip_metric) { LOG(LS_WARNING) << "Max Voip Metric blocks reached."; return false; } - voip_metric_blocks_.push_back(voip_metric->metric_); + voip_metric_blocks_.push_back(*voip_metric); return true; } diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet.h b/webrtc/modules/rtp_rtcp/source/rtcp_packet.h index 039d02d36b..dcbb1e72d3 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_packet.h +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet.h @@ -20,6 +20,7 @@ #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rrtr.h" +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" #include "webrtc/typedefs.h" @@ -31,7 +32,6 @@ static const int kReportBlockLength = 24; class Dlrr; class RawPacket; -class VoipMetric; // Class for building RTCP packets. // @@ -674,14 +674,13 @@ class Xr : public RtcpPacket { size_t DlrrLength() const; size_t VoipMetricLength() const { - const size_t kVoipMetricBlockLength = 36; - return kVoipMetricBlockLength * voip_metric_blocks_.size(); + return VoipMetric::kLength * voip_metric_blocks_.size(); } RTCPUtility::RTCPPacketXR xr_header_; std::vector<Rrtr> rrtr_blocks_; std::vector<DlrrBlock> dlrr_blocks_; - std::vector<RTCPUtility::RTCPPacketXRVOIPMetricItem> voip_metric_blocks_; + std::vector<VoipMetric> voip_metric_blocks_; RTC_DISALLOW_COPY_AND_ASSIGN(Xr); }; @@ -720,76 +719,6 @@ class Dlrr { RTC_DISALLOW_COPY_AND_ASSIGN(Dlrr); }; -// VoIP Metrics Report Block (RFC 3611). -// -// 0 1 2 3 -// 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 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | BT=7 | reserved | block length = 8 | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | SSRC of source | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | loss rate | discard rate | burst density | gap density | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | burst duration | gap duration | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | round trip delay | end system delay | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | signal level | noise level | RERL | Gmin | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | R factor | ext. R factor | MOS-LQ | MOS-CQ | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | RX config | reserved | JB nominal | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | JB maximum | JB abs max | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - -class VoipMetric { - public: - VoipMetric() { - memset(&metric_, 0, sizeof(metric_)); - } - ~VoipMetric() {} - - void To(uint32_t ssrc) { metric_.SSRC = ssrc; } - void LossRate(uint8_t loss_rate) { metric_.lossRate = loss_rate; } - void DiscardRate(uint8_t discard_rate) { metric_.discardRate = discard_rate; } - void BurstDensity(uint8_t burst_density) { - metric_.burstDensity = burst_density; - } - void GapDensity(uint8_t gap_density) { metric_.gapDensity = gap_density; } - void BurstDuration(uint16_t burst_duration) { - metric_.burstDuration = burst_duration; - } - void GapDuration(uint16_t gap_duration) { - metric_.gapDuration = gap_duration; - } - void RoundTripDelay(uint16_t round_trip_delay) { - metric_.roundTripDelay = round_trip_delay; - } - void EndSystemDelay(uint16_t end_system_delay) { - metric_.endSystemDelay = end_system_delay; - } - void SignalLevel(uint8_t signal_level) { metric_.signalLevel = signal_level; } - void NoiseLevel(uint8_t noise_level) { metric_.noiseLevel = noise_level; } - void Rerl(uint8_t rerl) { metric_.RERL = rerl; } - void Gmin(uint8_t gmin) { metric_.Gmin = gmin; } - void Rfactor(uint8_t rfactor) { metric_.Rfactor = rfactor; } - void ExtRfactor(uint8_t extrfactor) { metric_.extRfactor = extrfactor; } - void MosLq(uint8_t moslq) { metric_.MOSLQ = moslq; } - void MosCq(uint8_t moscq) { metric_.MOSCQ = moscq; } - void RxConfig(uint8_t rxconfig) { metric_.RXconfig = rxconfig; } - void JbNominal(uint16_t jbnominal) { metric_.JBnominal = jbnominal; } - void JbMax(uint16_t jbmax) { metric_.JBmax = jbmax; } - void JbAbsMax(uint16_t jbabsmax) { metric_.JBabsMax = jbabsmax; } - - private: - friend class Xr; - RTCPUtility::RTCPPacketXRVOIPMetricItem metric_; - - RTC_DISALLOW_COPY_AND_ASSIGN(VoipMetric); -}; - // Class holding a RTCP packet. // // Takes a built rtcp packet. diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.cc new file mode 100644 index 0000000000..a79d48e1ca --- /dev/null +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.cc @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.h" + +#include "webrtc/base/checks.h" +#include "webrtc/modules/rtp_rtcp/source/byte_io.h" + +namespace webrtc { +namespace rtcp { +// VoIP Metrics Report Block (RFC 3611). +// +// 0 1 2 3 +// 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 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 0 | BT=7 | reserved | block length = 8 | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 4 | SSRC of source | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 8 | loss rate | discard rate | burst density | gap density | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 12 | burst duration | gap duration | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 16 | round trip delay | end system delay | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 20 | signal level | noise level | RERL | Gmin | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 24 | R factor | ext. R factor | MOS-LQ | MOS-CQ | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 28 | RX config | reserved | JB nominal | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 32 | JB maximum | JB abs max | +// 36 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +VoipMetric::VoipMetric() : ssrc_(0) { + memset(&voip_metric_, 0, sizeof(voip_metric_)); +} + +void VoipMetric::Parse(const uint8_t* buffer) { + RTC_DCHECK(buffer[0] == kBlockType); + // reserved = buffer[1]; + RTC_DCHECK(ByteReader<uint16_t>::ReadBigEndian(&buffer[2]) == kBlockLength); + ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&buffer[4]); + voip_metric_.lossRate = buffer[8]; + voip_metric_.discardRate = buffer[9]; + voip_metric_.burstDensity = buffer[10]; + voip_metric_.gapDensity = buffer[11]; + voip_metric_.burstDuration = ByteReader<uint16_t>::ReadBigEndian(&buffer[12]); + voip_metric_.gapDuration = ByteReader<uint16_t>::ReadBigEndian(&buffer[14]); + voip_metric_.roundTripDelay = + ByteReader<uint16_t>::ReadBigEndian(&buffer[16]); + voip_metric_.endSystemDelay = + ByteReader<uint16_t>::ReadBigEndian(&buffer[18]); + voip_metric_.signalLevel = buffer[20]; + voip_metric_.noiseLevel = buffer[21]; + voip_metric_.RERL = buffer[22]; + voip_metric_.Gmin = buffer[23]; + voip_metric_.Rfactor = buffer[24]; + voip_metric_.extRfactor = buffer[25]; + voip_metric_.MOSLQ = buffer[26]; + voip_metric_.MOSCQ = buffer[27]; + voip_metric_.RXconfig = buffer[28]; + // reserved = buffer[29]; + voip_metric_.JBnominal = ByteReader<uint16_t>::ReadBigEndian(&buffer[30]); + voip_metric_.JBmax = ByteReader<uint16_t>::ReadBigEndian(&buffer[32]); + voip_metric_.JBabsMax = ByteReader<uint16_t>::ReadBigEndian(&buffer[34]); +} + +void VoipMetric::Create(uint8_t* buffer) const { + const uint8_t kReserved = 0; + buffer[0] = kBlockType; + buffer[1] = kReserved; + ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockLength); + ByteWriter<uint32_t>::WriteBigEndian(&buffer[4], ssrc_); + buffer[8] = voip_metric_.lossRate; + buffer[9] = voip_metric_.discardRate; + buffer[10] = voip_metric_.burstDensity; + buffer[11] = voip_metric_.gapDensity; + ByteWriter<uint16_t>::WriteBigEndian(&buffer[12], voip_metric_.burstDuration); + ByteWriter<uint16_t>::WriteBigEndian(&buffer[14], voip_metric_.gapDuration); + ByteWriter<uint16_t>::WriteBigEndian(&buffer[16], + voip_metric_.roundTripDelay); + ByteWriter<uint16_t>::WriteBigEndian(&buffer[18], + voip_metric_.endSystemDelay); + buffer[20] = voip_metric_.signalLevel; + buffer[21] = voip_metric_.noiseLevel; + buffer[22] = voip_metric_.RERL; + buffer[23] = voip_metric_.Gmin; + buffer[24] = voip_metric_.Rfactor; + buffer[25] = voip_metric_.extRfactor; + buffer[26] = voip_metric_.MOSLQ; + buffer[27] = voip_metric_.MOSCQ; + buffer[28] = voip_metric_.RXconfig; + buffer[29] = kReserved; + ByteWriter<uint16_t>::WriteBigEndian(&buffer[30], voip_metric_.JBnominal); + ByteWriter<uint16_t>::WriteBigEndian(&buffer[32], voip_metric_.JBmax); + ByteWriter<uint16_t>::WriteBigEndian(&buffer[34], voip_metric_.JBabsMax); +} + +} // namespace rtcp +} // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.h b/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.h new file mode 100644 index 0000000000..9e3e41995a --- /dev/null +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + * + */ + +#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_VOIP_METRIC_H_ +#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_VOIP_METRIC_H_ + +#include "webrtc/base/basictypes.h" +#include "webrtc/modules/include/module_common_types.h" + +namespace webrtc { +namespace rtcp { + +class VoipMetric { + public: + static const uint8_t kBlockType = 7; + static const uint16_t kBlockLength = 8; + static const size_t kLength = 4 * (kBlockLength + 1); // 36 + VoipMetric(); + VoipMetric(const VoipMetric&) = default; + ~VoipMetric() {} + + VoipMetric& operator=(const VoipMetric&) = default; + + void Parse(const uint8_t* buffer); + + // Fills buffer with the VoipMetric. + // Consumes VoipMetric::kLength bytes. + void Create(uint8_t* buffer) const; + + void To(uint32_t ssrc) { ssrc_ = ssrc; } + void WithVoipMetric(const RTCPVoIPMetric& voip_metric) { + voip_metric_ = voip_metric; + } + + uint32_t ssrc() const { return ssrc_; } + const RTCPVoIPMetric& voip_metric() const { return voip_metric_; } + + private: + uint32_t ssrc_; + RTCPVoIPMetric voip_metric_; +}; + +} // namespace rtcp +} // namespace webrtc +#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_VOIP_METRIC_H_ diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric_unittest.cc new file mode 100644 index 0000000000..44c82d67a9 --- /dev/null +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric_unittest.cc @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/voip_metric.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace webrtc { +namespace rtcp { +namespace { + +const uint32_t kRemoteSsrc = 0x23456789; +const uint8_t kBlock[] = {0x07, 0x00, 0x00, 0x08, 0x23, 0x45, 0x67, 0x89, + 0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x22, 0x23, + 0x33, 0x34, 0x44, 0x45, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x00, 0x55, 0x56, + 0x66, 0x67, 0x77, 0x78}; +const size_t kBlockSizeBytes = sizeof(kBlock); +static_assert( + kBlockSizeBytes == VoipMetric::kLength, + "Size of manually created Voip Metric block should match class constant"); + +TEST(RtcpPacketVoipMetricTest, Create) { + uint8_t buffer[VoipMetric::kLength]; + RTCPVoIPMetric metric; + metric.lossRate = 1; + metric.discardRate = 2; + metric.burstDensity = 3; + metric.gapDensity = 4; + metric.burstDuration = 0x1112; + metric.gapDuration = 0x2223; + metric.roundTripDelay = 0x3334; + metric.endSystemDelay = 0x4445; + metric.signalLevel = 5; + metric.noiseLevel = 6; + metric.RERL = 7; + metric.Gmin = 8; + metric.Rfactor = 9; + metric.extRfactor = 10; + metric.MOSLQ = 11; + metric.MOSCQ = 12; + metric.RXconfig = 13; + metric.JBnominal = 0x5556; + metric.JBmax = 0x6667; + metric.JBabsMax = 0x7778; + VoipMetric metric_block; + metric_block.To(kRemoteSsrc); + metric_block.WithVoipMetric(metric); + + metric_block.Create(buffer); + EXPECT_EQ(0, memcmp(buffer, kBlock, kBlockSizeBytes)); +} + +TEST(RtcpPacketVoipMetricTest, Parse) { + VoipMetric read_metric; + read_metric.Parse(kBlock); + + // Run checks on const object to ensure all accessors have const modifier. + const VoipMetric& parsed = read_metric; + + EXPECT_EQ(kRemoteSsrc, parsed.ssrc()); + EXPECT_EQ(1, parsed.voip_metric().lossRate); + EXPECT_EQ(2, parsed.voip_metric().discardRate); + EXPECT_EQ(3, parsed.voip_metric().burstDensity); + EXPECT_EQ(4, parsed.voip_metric().gapDensity); + EXPECT_EQ(0x1112, parsed.voip_metric().burstDuration); + EXPECT_EQ(0x2223, parsed.voip_metric().gapDuration); + EXPECT_EQ(0x3334, parsed.voip_metric().roundTripDelay); + EXPECT_EQ(0x4445, parsed.voip_metric().endSystemDelay); + EXPECT_EQ(5, parsed.voip_metric().signalLevel); + EXPECT_EQ(6, parsed.voip_metric().noiseLevel); + EXPECT_EQ(7, parsed.voip_metric().RERL); + EXPECT_EQ(8, parsed.voip_metric().Gmin); + EXPECT_EQ(9, parsed.voip_metric().Rfactor); + EXPECT_EQ(10, parsed.voip_metric().extRfactor); + EXPECT_EQ(11, parsed.voip_metric().MOSLQ); + EXPECT_EQ(12, parsed.voip_metric().MOSCQ); + EXPECT_EQ(13, parsed.voip_metric().RXconfig); + EXPECT_EQ(0x5556, parsed.voip_metric().JBnominal); + EXPECT_EQ(0x6667, parsed.voip_metric().JBmax); + EXPECT_EQ(0x7778, parsed.voip_metric().JBabsMax); +} + +} // namespace +} // namespace rtcp +} // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet_unittest.cc index eed56e249f..008bc63ef7 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_packet_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet_unittest.cc @@ -795,32 +795,33 @@ TEST(RtcpPacketTest, XrWithTwoDlrrBlocks) { } TEST(RtcpPacketTest, XrWithVoipMetric) { - VoipMetric metric; - metric.To(kRemoteSsrc); - metric.LossRate(1); - metric.DiscardRate(2); - metric.BurstDensity(3); - metric.GapDensity(4); - metric.BurstDuration(0x1111); - metric.GapDuration(0x2222); - metric.RoundTripDelay(0x3333); - metric.EndSystemDelay(0x4444); - metric.SignalLevel(5); - metric.NoiseLevel(6); - metric.Rerl(7); - metric.Gmin(8); - metric.Rfactor(9); - metric.ExtRfactor(10); - metric.MosLq(11); - metric.MosCq(12); - metric.RxConfig(13); - metric.JbNominal(0x5555); - metric.JbMax(0x6666); - metric.JbAbsMax(0x7777); - + RTCPVoIPMetric metric; + metric.lossRate = 1; + metric.discardRate = 2; + metric.burstDensity = 3; + metric.gapDensity = 4; + metric.burstDuration = 0x1111; + metric.gapDuration = 0x2222; + metric.roundTripDelay = 0x3333; + metric.endSystemDelay = 0x4444; + metric.signalLevel = 5; + metric.noiseLevel = 6; + metric.RERL = 7; + metric.Gmin = 8; + metric.Rfactor = 9; + metric.extRfactor = 10; + metric.MOSLQ = 11; + metric.MOSCQ = 12; + metric.RXconfig = 13; + metric.JBnominal = 0x5555; + metric.JBmax = 0x6666; + metric.JBabsMax = 0x7777; + VoipMetric metric_block; + metric_block.To(kRemoteSsrc); + metric_block.WithVoipMetric(metric); Xr xr; xr.From(kSenderSsrc); - EXPECT_TRUE(xr.WithVoipMetric(&metric)); + EXPECT_TRUE(xr.WithVoipMetric(&metric_block)); rtc::scoped_ptr<RawPacket> packet(xr.Build()); RtcpPacketParser parser; diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc index 4baf6f63c8..709a235bb3 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_receiver_unittest.cc @@ -590,7 +590,9 @@ TEST_F(RtcpReceiverTest, InjectXrVoipPacket) { const uint8_t kLossRate = 123; rtcp::VoipMetric voip_metric; voip_metric.To(kSourceSsrc); - voip_metric.LossRate(kLossRate); + RTCPVoIPMetric metric; + metric.lossRate = kLossRate; + voip_metric.WithVoipMetric(metric); rtcp::Xr xr; xr.From(0x2345); xr.WithVoipMetric(&voip_metric); diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc index 15f9388b57..ab3e0ef4eb 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc @@ -792,26 +792,7 @@ rtc::scoped_ptr<rtcp::RtcpPacket> RTCPSender::BuildVoIPMetric( rtcp::VoipMetric voip; voip.To(remote_ssrc_); - voip.LossRate(xr_voip_metric_.lossRate); - voip.DiscardRate(xr_voip_metric_.discardRate); - voip.BurstDensity(xr_voip_metric_.burstDensity); - voip.GapDensity(xr_voip_metric_.gapDensity); - voip.BurstDuration(xr_voip_metric_.burstDuration); - voip.GapDuration(xr_voip_metric_.gapDuration); - voip.RoundTripDelay(xr_voip_metric_.roundTripDelay); - voip.EndSystemDelay(xr_voip_metric_.endSystemDelay); - voip.SignalLevel(xr_voip_metric_.signalLevel); - voip.NoiseLevel(xr_voip_metric_.noiseLevel); - voip.Rerl(xr_voip_metric_.RERL); - voip.Gmin(xr_voip_metric_.Gmin); - voip.Rfactor(xr_voip_metric_.Rfactor); - voip.ExtRfactor(xr_voip_metric_.extRfactor); - voip.MosLq(xr_voip_metric_.MOSLQ); - voip.MosCq(xr_voip_metric_.MOSCQ); - voip.RxConfig(xr_voip_metric_.RXconfig); - voip.JbNominal(xr_voip_metric_.JBnominal); - voip.JbMax(xr_voip_metric_.JBmax); - voip.JbAbsMax(xr_voip_metric_.JBabsMax); + voip.WithVoipMetric(xr_voip_metric_); xr->WithVoipMetric(&voip); |