Remove rtcp_utility as mostly unused.

Since the only used class is RTCPUtilitiy::NackStats,
rename it to RtcpNackStats and move it into dedicated file.

BUG=webrtc:5565

Review-Url: https://codereview.webrtc.org/2680183004
Cr-Commit-Position: refs/heads/master@{#16515}
This commit is contained in:
danilchap 2017-02-09 05:21:42 -08:00 committed by Commit bot
parent 9def800b70
commit 8443238e26
11 changed files with 143 additions and 2412 deletions

View File

@ -40,6 +40,8 @@ rtc_static_library("rtp_rtcp") {
"source/receive_statistics_impl.cc",
"source/receive_statistics_impl.h",
"source/remote_ntp_time_estimator.cc",
"source/rtcp_nack_stats.cc",
"source/rtcp_nack_stats.h",
"source/rtcp_packet.cc",
"source/rtcp_packet.h",
"source/rtcp_packet/app.cc",
@ -100,8 +102,6 @@ rtc_static_library("rtp_rtcp") {
"source/rtcp_receiver.h",
"source/rtcp_sender.cc",
"source/rtcp_sender.h",
"source/rtcp_utility.cc",
"source/rtcp_utility.h",
"source/rtp_format.cc",
"source/rtp_format.h",
"source/rtp_format_h264.cc",
@ -242,6 +242,7 @@ if (rtc_include_tests) {
"source/playout_delay_oracle_unittest.cc",
"source/receive_statistics_unittest.cc",
"source/remote_ntp_time_estimator_unittest.cc",
"source/rtcp_nack_stats_unittest.cc",
"source/rtcp_packet/app_unittest.cc",
"source/rtcp_packet/bye_unittest.cc",
"source/rtcp_packet/common_header_unittest.cc",
@ -269,7 +270,6 @@ if (rtc_include_tests) {
"source/rtcp_packet_unittest.cc",
"source/rtcp_receiver_unittest.cc",
"source/rtcp_sender_unittest.cc",
"source/rtcp_utility_unittest.cc",
"source/rtp_fec_unittest.cc",
"source/rtp_format_h264_unittest.cc",
"source/rtp_format_vp8_test_helper.cc",

View File

@ -1,3 +0,0 @@
#rtcp_utility planned to be removed when webrtc:5260 will be finished.
exclude_files=rtcp_utility.*

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2017 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_nack_stats.h"
#include "webrtc/modules/include/module_common_types.h"
namespace webrtc {
RtcpNackStats::RtcpNackStats()
: max_sequence_number_(0),
requests_(0),
unique_requests_(0) {}
void RtcpNackStats::ReportRequest(uint16_t sequence_number) {
if (requests_ == 0 ||
IsNewerSequenceNumber(sequence_number, max_sequence_number_)) {
max_sequence_number_ = sequence_number;
++unique_requests_;
}
++requests_;
}
} // namespace webrtc

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2017 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_NACK_STATS_H_
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_NACK_STATS_H_
#include <stdint.h>
namespace webrtc {
class RtcpNackStats {
public:
RtcpNackStats();
// Updates stats with requested sequence number.
// This function should be called for each NACK request to calculate the
// number of unique NACKed RTP packets.
void ReportRequest(uint16_t sequence_number);
// Gets the number of NACKed RTP packets.
uint32_t requests() const { return requests_; }
// Gets the number of unique NACKed RTP packets.
uint32_t unique_requests() const { return unique_requests_; }
private:
uint16_t max_sequence_number_;
uint32_t requests_;
uint32_t unique_requests_;
};
} // namespace webrtc
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_NACK_STATS_H_

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2017 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_nack_stats.h"
#include "webrtc/test/gtest.h"
namespace webrtc {
TEST(RtcpNackStatsTest, Requests) {
RtcpNackStats stats;
EXPECT_EQ(0U, stats.unique_requests());
EXPECT_EQ(0U, stats.requests());
stats.ReportRequest(10);
EXPECT_EQ(1U, stats.unique_requests());
EXPECT_EQ(1U, stats.requests());
stats.ReportRequest(10);
EXPECT_EQ(1U, stats.unique_requests());
stats.ReportRequest(11);
EXPECT_EQ(2U, stats.unique_requests());
stats.ReportRequest(11);
EXPECT_EQ(2U, stats.unique_requests());
stats.ReportRequest(13);
EXPECT_EQ(3U, stats.unique_requests());
stats.ReportRequest(11);
EXPECT_EQ(3U, stats.unique_requests());
EXPECT_EQ(6U, stats.requests());
}
TEST(RtcpNackStatsTest, RequestsWithWrap) {
RtcpNackStats stats;
stats.ReportRequest(65534);
EXPECT_EQ(1U, stats.unique_requests());
stats.ReportRequest(65534);
EXPECT_EQ(1U, stats.unique_requests());
stats.ReportRequest(65535);
EXPECT_EQ(2U, stats.unique_requests());
stats.ReportRequest(65535);
EXPECT_EQ(2U, stats.unique_requests());
stats.ReportRequest(0);
EXPECT_EQ(3U, stats.unique_requests());
stats.ReportRequest(65535);
EXPECT_EQ(3U, stats.unique_requests());
stats.ReportRequest(0);
EXPECT_EQ(3U, stats.unique_requests());
stats.ReportRequest(1);
EXPECT_EQ(4U, stats.unique_requests());
EXPECT_EQ(8U, stats.requests());
}
} // namespace webrtc

View File

@ -40,6 +40,7 @@
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
#include "webrtc/modules/rtp_rtcp/source/time_util.h"
#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
#include "webrtc/system_wrappers/include/ntp_time.h"

View File

@ -19,8 +19,8 @@
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_nack_stats.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
#include "webrtc/system_wrappers/include/ntp_time.h"
#include "webrtc/typedefs.h"
@ -260,7 +260,7 @@ class RTCPReceiver {
RtcpPacketTypeCounterObserver* const packet_type_counter_observer_;
RtcpPacketTypeCounter packet_type_counter_;
RTCPUtility::NackStats nack_stats_;
RtcpNackStats nack_stats_;
size_t num_skipped_packets_;
int64_t last_skipped_packets_warning_ms_;

View File

@ -28,11 +28,11 @@
#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_nack_stats.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/report_block.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
#include "webrtc/typedefs.h"
namespace webrtc {
@ -259,7 +259,7 @@ class RTCPSender {
RtcpPacketTypeCounter packet_type_counter_
GUARDED_BY(critical_section_rtcp_sender_);
RTCPUtility::NackStats nack_stats_ GUARDED_BY(critical_section_rtcp_sender_);
RtcpNackStats nack_stats_ GUARDED_BY(critical_section_rtcp_sender_);
rtc::Optional<BitrateAllocation> video_bitrate_allocation_
GUARDED_BY(critical_section_rtcp_sender_);

File diff suppressed because it is too large Load Diff

View File

@ -1,490 +0,0 @@
/*
* Copyright (c) 2012 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_UTILITY_H_
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_UTILITY_H_
#include <stddef.h> // size_t, ptrdiff_t
#include <memory>
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace rtcp {
class RtcpPacket;
}
namespace RTCPUtility {
class NackStats {
public:
NackStats();
~NackStats();
// Updates stats with requested sequence number.
// This function should be called for each NACK request to calculate the
// number of unique NACKed RTP packets.
void ReportRequest(uint16_t sequence_number);
// Gets the number of NACKed RTP packets.
uint32_t requests() const { return requests_; }
// Gets the number of unique NACKed RTP packets.
uint32_t unique_requests() const { return unique_requests_; }
private:
uint16_t max_sequence_number_;
uint32_t requests_;
uint32_t unique_requests_;
};
uint32_t MidNtp(uint32_t ntp_sec, uint32_t ntp_frac);
struct RTCPPacketRR {
uint32_t SenderSSRC;
uint8_t NumberOfReportBlocks;
};
struct RTCPPacketSR {
uint32_t SenderSSRC;
uint8_t NumberOfReportBlocks;
// sender info
uint32_t NTPMostSignificant;
uint32_t NTPLeastSignificant;
uint32_t RTPTimestamp;
uint32_t SenderPacketCount;
uint32_t SenderOctetCount;
};
struct RTCPPacketReportBlockItem {
// report block
uint32_t SSRC;
uint8_t FractionLost;
uint32_t CumulativeNumOfPacketsLost;
uint32_t ExtendedHighestSequenceNumber;
uint32_t Jitter;
uint32_t LastSR;
uint32_t DelayLastSR;
};
struct RTCPPacketSDESCName {
// RFC3550
uint32_t SenderSSRC;
char CName[RTCP_CNAME_SIZE];
};
struct RTCPPacketExtendedJitterReportItem {
// RFC 5450
uint32_t Jitter;
};
struct RTCPPacketBYE {
uint32_t SenderSSRC;
};
struct RTCPPacketXR {
// RFC 3611
uint32_t OriginatorSSRC;
};
struct RTCPPacketXRReceiverReferenceTimeItem {
// RFC 3611 4.4
uint32_t NTPMostSignificant;
uint32_t NTPLeastSignificant;
};
struct RTCPPacketXRDLRRReportBlockItem {
// RFC 3611 4.5
uint32_t SSRC;
uint32_t LastRR;
uint32_t DelayLastRR;
};
struct RTCPPacketXRVOIPMetricItem {
// RFC 3611 4.7
uint32_t SSRC;
uint8_t lossRate;
uint8_t discardRate;
uint8_t burstDensity;
uint8_t gapDensity;
uint16_t burstDuration;
uint16_t gapDuration;
uint16_t roundTripDelay;
uint16_t endSystemDelay;
uint8_t signalLevel;
uint8_t noiseLevel;
uint8_t RERL;
uint8_t Gmin;
uint8_t Rfactor;
uint8_t extRfactor;
uint8_t MOSLQ;
uint8_t MOSCQ;
uint8_t RXconfig;
uint16_t JBnominal;
uint16_t JBmax;
uint16_t JBabsMax;
};
struct RTCPPacketRTPFBNACK {
uint32_t SenderSSRC;
uint32_t MediaSSRC;
};
struct RTCPPacketRTPFBNACKItem {
// RFC4585
uint16_t PacketID;
uint16_t BitMask;
};
struct RTCPPacketRTPFBTMMBR {
uint32_t SenderSSRC;
uint32_t MediaSSRC; // zero!
};
struct RTCPPacketRTPFBTMMBRItem {
// RFC5104
uint32_t SSRC;
uint32_t MaxTotalMediaBitRate; // In Kbit/s
uint32_t MeasuredOverhead;
};
struct RTCPPacketRTPFBTMMBN {
uint32_t SenderSSRC;
uint32_t MediaSSRC; // zero!
};
struct RTCPPacketRTPFBTMMBNItem {
// RFC5104
uint32_t SSRC; // "Owner"
uint32_t MaxTotalMediaBitRate;
uint32_t MeasuredOverhead;
};
struct RTCPPacketPSFBFIR {
uint32_t SenderSSRC;
uint32_t MediaSSRC; // zero!
};
struct RTCPPacketPSFBFIRItem {
// RFC5104
uint32_t SSRC;
uint8_t CommandSequenceNumber;
};
struct RTCPPacketPSFBPLI {
// RFC4585
uint32_t SenderSSRC;
uint32_t MediaSSRC;
};
struct RTCPPacketPSFBSLI {
// RFC4585
uint32_t SenderSSRC;
uint32_t MediaSSRC;
};
struct RTCPPacketPSFBSLIItem {
// RFC4585
uint16_t FirstMB;
uint16_t NumberOfMB;
uint8_t PictureId;
};
struct RTCPPacketPSFBRPSI {
// RFC4585
uint32_t SenderSSRC;
uint32_t MediaSSRC;
uint8_t PayloadType;
uint16_t NumberOfValidBits;
uint8_t NativeBitString[RTCP_RPSI_DATA_SIZE];
};
struct RTCPPacketPSFBAPP {
uint32_t SenderSSRC;
uint32_t MediaSSRC;
};
struct RTCPPacketPSFBREMBItem {
uint32_t BitRate;
uint8_t NumberOfSSRCs;
uint32_t SSRCs[MAX_NUMBER_OF_REMB_FEEDBACK_SSRCS];
};
// generic name APP
struct RTCPPacketAPP {
uint8_t SubType;
uint32_t Name;
uint8_t Data[kRtcpAppCode_DATA_SIZE];
uint16_t Size;
};
union RTCPPacket {
RTCPPacketRR RR;
RTCPPacketSR SR;
RTCPPacketReportBlockItem ReportBlockItem;
RTCPPacketSDESCName CName;
RTCPPacketBYE BYE;
RTCPPacketExtendedJitterReportItem ExtendedJitterReportItem;
RTCPPacketRTPFBNACK NACK;
RTCPPacketRTPFBNACKItem NACKItem;
RTCPPacketPSFBPLI PLI;
RTCPPacketPSFBSLI SLI;
RTCPPacketPSFBSLIItem SLIItem;
RTCPPacketPSFBRPSI RPSI;
RTCPPacketPSFBAPP PSFBAPP;
RTCPPacketPSFBREMBItem REMBItem;
RTCPPacketRTPFBTMMBR TMMBR;
RTCPPacketRTPFBTMMBRItem TMMBRItem;
RTCPPacketRTPFBTMMBN TMMBN;
RTCPPacketRTPFBTMMBNItem TMMBNItem;
RTCPPacketPSFBFIR FIR;
RTCPPacketPSFBFIRItem FIRItem;
RTCPPacketXR XR;
RTCPPacketXRReceiverReferenceTimeItem XRReceiverReferenceTimeItem;
RTCPPacketXRDLRRReportBlockItem XRDLRRReportBlockItem;
RTCPPacketXRVOIPMetricItem XRVOIPMetricItem;
RTCPPacketAPP APP;
};
enum class RTCPPacketTypes {
kInvalid,
// RFC3550
kRr,
kSr,
kReportBlockItem,
kSdes,
kSdesChunk,
kBye,
// RFC5450
kExtendedIj,
kExtendedIjItem,
// RFC4585
kRtpfbNack,
kRtpfbNackItem,
kPsfbPli,
kPsfbRpsi,
kPsfbRpsiItem,
kPsfbSli,
kPsfbSliItem,
kPsfbApp,
kPsfbRemb,
kPsfbRembItem,
// RFC5104
kRtpfbTmmbr,
kRtpfbTmmbrItem,
kRtpfbTmmbn,
kRtpfbTmmbnItem,
kPsfbFir,
kPsfbFirItem,
// draft-perkins-avt-rapid-rtp-sync
kRtpfbSrReq,
// RFC 3611
kXrHeader,
kXrReceiverReferenceTime,
kXrDlrrReportBlock,
kXrDlrrReportBlockItem,
kXrVoipMetric,
kApp,
kAppItem,
// draft-holmer-rmcat-transport-wide-cc-extensions
kTransportFeedback,
};
struct RTCPRawPacket {
const uint8_t* _ptrPacketBegin;
const uint8_t* _ptrPacketEnd;
};
struct RTCPModRawPacket {
uint8_t* _ptrPacketBegin;
uint8_t* _ptrPacketEnd;
};
struct RtcpCommonHeader {
static const uint8_t kHeaderSizeBytes = 4;
RtcpCommonHeader()
: version(2),
count_or_format(0),
packet_type(0),
payload_size_bytes(0),
padding_bytes(0) {}
uint32_t BlockSize() const {
return kHeaderSizeBytes + payload_size_bytes + padding_bytes;
}
uint8_t version;
uint8_t count_or_format;
uint8_t packet_type;
uint32_t payload_size_bytes;
uint8_t padding_bytes;
};
enum RTCPPT : uint8_t {
PT_IJ = 195,
PT_SR = 200,
PT_RR = 201,
PT_SDES = 202,
PT_BYE = 203,
PT_APP = 204,
PT_RTPFB = 205,
PT_PSFB = 206,
PT_XR = 207
};
// Extended report blocks, RFC 3611.
enum RtcpXrBlockType : uint8_t {
kBtReceiverReferenceTime = 4,
kBtDlrr = 5,
kBtVoipMetric = 7
};
bool RtcpParseCommonHeader(const uint8_t* buffer,
size_t size_bytes,
RtcpCommonHeader* parsed_header);
class RTCPParserV2 {
public:
RTCPParserV2(
const uint8_t* rtcpData,
size_t rtcpDataLength,
bool rtcpReducedSizeEnable); // Set to true, to allow non-compound RTCP!
~RTCPParserV2();
RTCPPacketTypes PacketType() const;
const RTCPPacket& Packet() const;
rtcp::RtcpPacket* ReleaseRtcpPacket();
const RTCPRawPacket& RawPacket() const;
ptrdiff_t LengthLeft() const;
bool IsValid() const;
size_t NumSkippedBlocks() const;
RTCPPacketTypes Begin();
RTCPPacketTypes Iterate();
private:
enum class ParseState {
State_TopLevel, // Top level packet
State_ReportBlockItem, // SR/RR report block
State_SDESChunk, // SDES chunk
State_BYEItem, // BYE item
State_ExtendedJitterItem, // Extended jitter report item
State_RTPFB_NACKItem, // NACK FCI item
State_RTPFB_TMMBRItem, // TMMBR FCI item
State_RTPFB_TMMBNItem, // TMMBN FCI item
State_PSFB_SLIItem, // SLI FCI item
State_PSFB_RPSIItem, // RPSI FCI item
State_PSFB_FIRItem, // FIR FCI item
State_PSFB_AppItem, // Application specific FCI item
State_PSFB_REMBItem, // Application specific REMB item
State_XRItem,
State_XR_DLLRItem,
State_AppItem
};
private:
void IterateTopLevel();
void IterateReportBlockItem();
void IterateSDESChunk();
void IterateBYEItem();
void IterateExtendedJitterItem();
void IterateNACKItem();
void IterateTMMBRItem();
void IterateTMMBNItem();
void IterateSLIItem();
void IterateRPSIItem();
void IterateFIRItem();
void IteratePsfbAppItem();
void IteratePsfbREMBItem();
void IterateAppItem();
void IterateXrItem();
void IterateXrDlrrItem();
void Validate();
void EndCurrentBlock();
bool ParseRR();
bool ParseSR();
bool ParseReportBlockItem();
bool ParseSDES();
bool ParseSDESChunk();
bool ParseSDESItem();
bool ParseBYE();
bool ParseBYEItem();
bool ParseIJ();
bool ParseIJItem();
bool ParseXr();
bool ParseXrItem();
bool ParseXrReceiverReferenceTimeItem(int block_length_4bytes);
bool ParseXrDlrr(int block_length_4bytes);
bool ParseXrDlrrItem();
bool ParseXrVoipMetricItem(int block_length_4bytes);
bool ParseXrUnsupportedBlockType(int block_length_4bytes);
bool ParseFBCommon(const RtcpCommonHeader& header);
bool ParseNACKItem();
bool ParseTMMBRItem();
bool ParseTMMBNItem();
bool ParseSLIItem();
bool ParseRPSIItem();
bool ParseFIRItem();
bool ParsePsfbAppItem();
bool ParsePsfbREMBItem();
bool ParseAPP(const RtcpCommonHeader& header);
bool ParseAPPItem();
private:
const uint8_t* const _ptrRTCPDataBegin;
const bool _RTCPReducedSizeEnable;
const uint8_t* const _ptrRTCPDataEnd;
bool _validPacket;
const uint8_t* _ptrRTCPData;
const uint8_t* _ptrRTCPBlockEnd;
ParseState _state;
uint8_t _numberOfBlocks;
size_t num_skipped_blocks_;
RTCPPacketTypes _packetType;
RTCPPacket _packet;
std::unique_ptr<webrtc::rtcp::RtcpPacket> rtcp_packet_;
};
class RTCPPacketIterator {
public:
RTCPPacketIterator(uint8_t* rtcpData, size_t rtcpDataLength);
~RTCPPacketIterator();
const RtcpCommonHeader* Begin();
const RtcpCommonHeader* Iterate();
const RtcpCommonHeader* Current();
private:
uint8_t* const _ptrBegin;
uint8_t* const _ptrEnd;
uint8_t* _ptrBlock;
RtcpCommonHeader _header;
};
} // namespace RTCPUtility
} // namespace webrtc
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_UTILITY_H_

View File

@ -1,160 +0,0 @@
/*
* Copyright (c) 2014 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/base/checks.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
#include "webrtc/test/gtest.h"
namespace webrtc {
using RTCPUtility::RtcpCommonHeader;
namespace rtcp {
TEST(RtcpUtilityTest, MidNtp) {
const uint32_t kNtpSec = 0x12345678;
const uint32_t kNtpFrac = 0x23456789;
const uint32_t kNtpMid = 0x56782345;
EXPECT_EQ(kNtpMid, RTCPUtility::MidNtp(kNtpSec, kNtpFrac));
}
TEST(RtcpUtilityTest, NackRequests) {
RTCPUtility::NackStats stats;
EXPECT_EQ(0U, stats.unique_requests());
EXPECT_EQ(0U, stats.requests());
stats.ReportRequest(10);
EXPECT_EQ(1U, stats.unique_requests());
EXPECT_EQ(1U, stats.requests());
stats.ReportRequest(10);
EXPECT_EQ(1U, stats.unique_requests());
stats.ReportRequest(11);
EXPECT_EQ(2U, stats.unique_requests());
stats.ReportRequest(11);
EXPECT_EQ(2U, stats.unique_requests());
stats.ReportRequest(13);
EXPECT_EQ(3U, stats.unique_requests());
stats.ReportRequest(11);
EXPECT_EQ(3U, stats.unique_requests());
EXPECT_EQ(6U, stats.requests());
}
TEST(RtcpUtilityTest, NackRequestsWithWrap) {
RTCPUtility::NackStats stats;
stats.ReportRequest(65534);
EXPECT_EQ(1U, stats.unique_requests());
stats.ReportRequest(65534);
EXPECT_EQ(1U, stats.unique_requests());
stats.ReportRequest(65535);
EXPECT_EQ(2U, stats.unique_requests());
stats.ReportRequest(65535);
EXPECT_EQ(2U, stats.unique_requests());
stats.ReportRequest(0);
EXPECT_EQ(3U, stats.unique_requests());
stats.ReportRequest(65535);
EXPECT_EQ(3U, stats.unique_requests());
stats.ReportRequest(0);
EXPECT_EQ(3U, stats.unique_requests());
stats.ReportRequest(1);
EXPECT_EQ(4U, stats.unique_requests());
EXPECT_EQ(8U, stats.requests());
}
class RtcpParseCommonHeaderTest : public ::testing::Test {
public:
RtcpParseCommonHeaderTest() { memset(buffer, 0, kBufferCapacityBytes); }
virtual ~RtcpParseCommonHeaderTest() {}
protected:
static const size_t kBufferCapacityBytes = 40;
uint8_t buffer[kBufferCapacityBytes];
RtcpCommonHeader header;
};
TEST_F(RtcpParseCommonHeaderTest, TooSmallBuffer) {
// Buffer needs to be able to hold the header.
for (size_t i = 0; i < RtcpCommonHeader::kHeaderSizeBytes; ++i)
EXPECT_FALSE(RtcpParseCommonHeader(buffer, i, &header));
}
TEST_F(RtcpParseCommonHeaderTest, Version) {
// Version 2 is the only allowed for now.
for (int v = 0; v < 4; ++v) {
buffer[0] = v << 6;
EXPECT_EQ(v == 2, RtcpParseCommonHeader(
buffer, RtcpCommonHeader::kHeaderSizeBytes, &header));
}
}
TEST_F(RtcpParseCommonHeaderTest, PacketSize) {
// Set v = 2, leave p, fmt, pt as 0.
buffer[0] = 2 << 6;
const size_t kBlockSize = 3;
ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockSize);
const size_t kSizeInBytes = (kBlockSize + 1) * 4;
EXPECT_FALSE(RtcpParseCommonHeader(buffer, kSizeInBytes - 1, &header));
EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header));
}
TEST_F(RtcpParseCommonHeaderTest, PayloadSize) {
// Set v = 2, p = 1, but leave fmt, pt as 0.
buffer[0] = (2 << 6) | (1 << 5);
// Padding bit set, but no byte for padding (can't specify padding length).
EXPECT_FALSE(RtcpParseCommonHeader(buffer, 4, &header));
const size_t kBlockSize = 3;
ByteWriter<uint16_t>::WriteBigEndian(&buffer[2], kBlockSize);
const size_t kSizeInBytes = (kBlockSize + 1) * 4;
const size_t kPayloadSizeBytes =
kSizeInBytes - RtcpCommonHeader::kHeaderSizeBytes;
// Padding one byte larger than possible.
buffer[kSizeInBytes - 1] = kPayloadSizeBytes + 1;
EXPECT_FALSE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header));
// Pure padding packet?
buffer[kSizeInBytes - 1] = kPayloadSizeBytes;
EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header));
EXPECT_EQ(kPayloadSizeBytes, header.padding_bytes);
EXPECT_EQ(0u, header.payload_size_bytes);
// Single byte of actual data.
buffer[kSizeInBytes - 1] = kPayloadSizeBytes - 1;
EXPECT_TRUE(RtcpParseCommonHeader(buffer, kSizeInBytes, &header));
EXPECT_EQ(kPayloadSizeBytes - 1, header.padding_bytes);
EXPECT_EQ(1u, header.payload_size_bytes);
}
TEST_F(RtcpParseCommonHeaderTest, FormatAndPayloadType) {
// Format/count and packet type both set to max values.
const uint8_t kCountOrFormat = 0x1F;
const uint8_t kPacketType = 0xFF;
buffer[0] = 2 << 6; // V = 2.
buffer[0] |= kCountOrFormat;
buffer[1] = kPacketType;
EXPECT_TRUE(RtcpParseCommonHeader(buffer, RtcpCommonHeader::kHeaderSizeBytes,
&header));
EXPECT_EQ(kCountOrFormat, header.count_or_format);
EXPECT_EQ(kPacketType, header.packet_type);
}
} // namespace rtcp
} // namespace webrtc