From 2c13297bf5db659c98d3f33a4753db672031768e Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Fri, 15 Jan 2016 15:21:21 +0100 Subject: [PATCH] [rtp_rtcp] rtcp::Rpsi moved into own file Cleaning/Parsing will be done in the https://codereview.webrtc.org/1550293003/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=webrtc:5260 R=asapersson@webrtc.org, åsapersson Review URL: https://codereview.webrtc.org/1583233007 . Cr-Commit-Position: refs/heads/master@{#11272} --- webrtc/modules/modules.gyp | 1 + webrtc/modules/rtp_rtcp/BUILD.gn | 2 + webrtc/modules/rtp_rtcp/rtp_rtcp.gypi | 2 + webrtc/modules/rtp_rtcp/source/rtcp_packet.cc | 72 ------------- webrtc/modules/rtp_rtcp/source/rtcp_packet.h | 52 --------- .../rtp_rtcp/source/rtcp_packet/rpsi.cc | 102 ++++++++++++++++++ .../rtp_rtcp/source/rtcp_packet/rpsi.h | 62 +++++++++++ .../source/rtcp_packet/rpsi_unittest.cc | 97 +++++++++++++++++ .../rtp_rtcp/source/rtcp_packet_unittest.cc | 73 ------------- webrtc/modules/rtp_rtcp/source/rtcp_sender.cc | 1 + 10 files changed, 267 insertions(+), 197 deletions(-) create mode 100644 webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.cc create mode 100644 webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h create mode 100644 webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi_unittest.cc diff --git a/webrtc/modules/modules.gyp b/webrtc/modules/modules.gyp index 82d2feda03..9ca0587fe3 100644 --- a/webrtc/modules/modules.gyp +++ b/webrtc/modules/modules.gyp @@ -317,6 +317,7 @@ 'rtp_rtcp/source/rtcp_packet/receiver_report_unittest.cc', 'rtp_rtcp/source/rtcp_packet/remb_unittest.cc', 'rtp_rtcp/source/rtcp_packet/report_block_unittest.cc', + 'rtp_rtcp/source/rtcp_packet/rpsi_unittest.cc', 'rtp_rtcp/source/rtcp_packet/rrtr_unittest.cc', 'rtp_rtcp/source/rtcp_packet/sli_unittest.cc', 'rtp_rtcp/source/rtcp_packet/tmmbn_unittest.cc', diff --git a/webrtc/modules/rtp_rtcp/BUILD.gn b/webrtc/modules/rtp_rtcp/BUILD.gn index e3039701ce..0e8f07e6b2 100644 --- a/webrtc/modules/rtp_rtcp/BUILD.gn +++ b/webrtc/modules/rtp_rtcp/BUILD.gn @@ -72,6 +72,8 @@ source_set("rtp_rtcp") { "source/rtcp_packet/remb.h", "source/rtcp_packet/report_block.cc", "source/rtcp_packet/report_block.h", + "source/rtcp_packet/rpsi.cc", + "source/rtcp_packet/rpsi.h", "source/rtcp_packet/rrtr.cc", "source/rtcp_packet/rrtr.h", "source/rtcp_packet/rtpfb.cc", diff --git a/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi b/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi index 4028719b89..0e9071be76 100644 --- a/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi +++ b/webrtc/modules/rtp_rtcp/rtp_rtcp.gypi @@ -67,6 +67,8 @@ 'source/rtcp_packet/remb.h', 'source/rtcp_packet/report_block.cc', 'source/rtcp_packet/report_block.h', + 'source/rtcp_packet/rpsi.cc', + 'source/rtcp_packet/rpsi.h', 'source/rtcp_packet/rrtr.cc', 'source/rtcp_packet/rrtr.h', 'source/rtcp_packet/rtpfb.cc', diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc index de5222c411..aa7a28669a 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet.cc @@ -18,13 +18,11 @@ using webrtc::RTCPUtility::PT_APP; using webrtc::RTCPUtility::PT_IJ; -using webrtc::RTCPUtility::PT_PSFB; using webrtc::RTCPUtility::PT_RTPFB; using webrtc::RTCPUtility::PT_SDES; using webrtc::RTCPUtility::PT_SR; using webrtc::RTCPUtility::RTCPPacketAPP; -using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; using webrtc::RTCPUtility::RTCPPacketReportBlockItem; using webrtc::RTCPUtility::RTCPPacketRTPFBNACK; using webrtc::RTCPUtility::RTCPPacketRTPFBNACKItem; @@ -142,34 +140,6 @@ void CreateSdes(const std::vector& chunks, *pos += (*it).null_octets; } } - -// Reference picture selection indication (RPSI) (RFC 4585). -// -// FCI: -// -// 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 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | PB |0| Payload Type| Native RPSI bit string | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | defined per codec ... | Padding (0) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - -void CreateRpsi(const RTCPPacketPSFBRPSI& rpsi, - uint8_t padding_bytes, - uint8_t* buffer, - size_t* pos) { - // Native bit string should be a multiple of 8 bits. - assert(rpsi.NumberOfValidBits % 8 == 0); - AssignUWord32(buffer, pos, rpsi.SenderSSRC); - AssignUWord32(buffer, pos, rpsi.MediaSSRC); - AssignUWord8(buffer, pos, padding_bytes * 8); - AssignUWord8(buffer, pos, rpsi.PayloadType); - memcpy(buffer + *pos, rpsi.NativeBitString, rpsi.NumberOfValidBits / 8); - *pos += rpsi.NumberOfValidBits / 8; - memset(buffer + *pos, 0, padding_bytes); - *pos += padding_bytes; -} } // namespace void RtcpPacket::Append(RtcpPacket* packet) { @@ -335,48 +305,6 @@ size_t Sdes::BlockLength() const { return length; } -bool Rpsi::Create(uint8_t* packet, - size_t* index, - size_t max_length, - RtcpPacket::PacketReadyCallback* callback) const { - assert(rpsi_.NumberOfValidBits > 0); - while (*index + BlockLength() > max_length) { - if (!OnBufferFull(packet, index, callback)) - return false; - } - const uint8_t kFmt = 3; - CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index); - CreateRpsi(rpsi_, padding_bytes_, packet, index); - return true; -} - -void Rpsi::WithPictureId(uint64_t picture_id) { - const uint32_t kPidBits = 7; - const uint64_t k7MsbZeroMask = 0x1ffffffffffffffULL; - uint8_t required_bytes = 0; - uint64_t shifted_pid = picture_id; - do { - ++required_bytes; - shifted_pid = (shifted_pid >> kPidBits) & k7MsbZeroMask; - } while (shifted_pid > 0); - - // Convert picture id to native bit string (natively defined by the video - // codec). - int pos = 0; - for (int i = required_bytes - 1; i > 0; i--) { - rpsi_.NativeBitString[pos++] = - 0x80 | static_cast(picture_id >> (i * kPidBits)); - } - rpsi_.NativeBitString[pos++] = static_cast(picture_id & 0x7f); - rpsi_.NumberOfValidBits = pos * 8; - - // Calculate padding bytes (to reach next 32-bit boundary, 1, 2 or 3 bytes). - padding_bytes_ = 4 - ((2 + required_bytes) % 4); - if (padding_bytes_ == 4) { - padding_bytes_ = 0; - } -} - RawPacket::RawPacket(size_t buffer_length) : buffer_length_(buffer_length), length_(0) { buffer_.reset(new uint8_t[buffer_length]); diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet.h b/webrtc/modules/rtp_rtcp/source/rtcp_packet.h index 949ea39fc7..9184ba88e2 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_packet.h +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet.h @@ -250,58 +250,6 @@ class Sdes : public RtcpPacket { RTC_DISALLOW_COPY_AND_ASSIGN(Sdes); }; -// Reference picture selection indication (RPSI) (RFC 4585). -// -// FCI: -// -// 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 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | PB |0| Payload Type| Native RPSI bit string | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | defined per codec ... | Padding (0) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - -class Rpsi : public RtcpPacket { - public: - Rpsi() - : RtcpPacket(), - padding_bytes_(0) { - memset(&rpsi_, 0, sizeof(rpsi_)); - } - - virtual ~Rpsi() {} - - void From(uint32_t ssrc) { - rpsi_.SenderSSRC = ssrc; - } - void To(uint32_t ssrc) { - rpsi_.MediaSSRC = ssrc; - } - void WithPayloadType(uint8_t payload) { - assert(payload <= 0x7f); - rpsi_.PayloadType = payload; - } - void WithPictureId(uint64_t picture_id); - - protected: - bool Create(uint8_t* packet, - size_t* index, - size_t max_length, - RtcpPacket::PacketReadyCallback* callback) const override; - - private: - size_t BlockLength() const { - size_t fci_length = 2 + (rpsi_.NumberOfValidBits / 8) + padding_bytes_; - return kCommonFbFmtLength + fci_length; - } - - uint8_t padding_bytes_; - RTCPUtility::RTCPPacketPSFBRPSI rpsi_; - - RTC_DISALLOW_COPY_AND_ASSIGN(Rpsi); -}; - // Class holding a RTCP packet. // // Takes a built rtcp packet. diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.cc new file mode 100644 index 0000000000..56766bff1b --- /dev/null +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.cc @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2016 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/rpsi.h" + +#include "webrtc/modules/rtp_rtcp/source/byte_io.h" + +using webrtc::RTCPUtility::PT_PSFB; +using webrtc::RTCPUtility::RTCPPacketPSFBRPSI; + +namespace webrtc { +namespace rtcp { +namespace { +void AssignUWord8(uint8_t* buffer, size_t* offset, uint8_t value) { + buffer[(*offset)++] = value; +} + +void AssignUWord32(uint8_t* buffer, size_t* offset, uint32_t value) { + ByteWriter::WriteBigEndian(buffer + *offset, value); + *offset += 4; +} + +// Reference picture selection indication (RPSI) (RFC 4585). +// +// FCI: +// +// 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 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | PB |0| Payload Type| Native RPSI bit string | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | defined per codec ... | Padding (0) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +void CreateRpsi(const RTCPPacketPSFBRPSI& rpsi, + uint8_t padding_bytes, + uint8_t* buffer, + size_t* pos) { + // Native bit string should be a multiple of 8 bits. + assert(rpsi.NumberOfValidBits % 8 == 0); + AssignUWord32(buffer, pos, rpsi.SenderSSRC); + AssignUWord32(buffer, pos, rpsi.MediaSSRC); + AssignUWord8(buffer, pos, padding_bytes * 8); + AssignUWord8(buffer, pos, rpsi.PayloadType); + memcpy(buffer + *pos, rpsi.NativeBitString, rpsi.NumberOfValidBits / 8); + *pos += rpsi.NumberOfValidBits / 8; + memset(buffer + *pos, 0, padding_bytes); + *pos += padding_bytes; +} +} // namespace + +bool Rpsi::Create(uint8_t* packet, + size_t* index, + size_t max_length, + RtcpPacket::PacketReadyCallback* callback) const { + assert(rpsi_.NumberOfValidBits > 0); + while (*index + BlockLength() > max_length) { + if (!OnBufferFull(packet, index, callback)) + return false; + } + const uint8_t kFmt = 3; + CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index); + CreateRpsi(rpsi_, padding_bytes_, packet, index); + return true; +} + +void Rpsi::WithPictureId(uint64_t picture_id) { + const uint32_t kPidBits = 7; + const uint64_t k7MsbZeroMask = 0x1ffffffffffffffULL; + uint8_t required_bytes = 0; + uint64_t shifted_pid = picture_id; + do { + ++required_bytes; + shifted_pid = (shifted_pid >> kPidBits) & k7MsbZeroMask; + } while (shifted_pid > 0); + + // Convert picture id to native bit string (natively defined by the video + // codec). + int pos = 0; + for (int i = required_bytes - 1; i > 0; i--) { + rpsi_.NativeBitString[pos++] = + 0x80 | static_cast(picture_id >> (i * kPidBits)); + } + rpsi_.NativeBitString[pos++] = static_cast(picture_id & 0x7f); + rpsi_.NumberOfValidBits = pos * 8; + + // Calculate padding bytes (to reach next 32-bit boundary, 1, 2 or 3 bytes). + padding_bytes_ = 4 - ((2 + required_bytes) % 4); + if (padding_bytes_ == 4) { + padding_bytes_ = 0; + } +} + + +} // namespace rtcp +} // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h new file mode 100644 index 0000000000..1882ca6488 --- /dev/null +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 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_RPSI_H_ +#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_RPSI_H_ + +#include "webrtc/base/basictypes.h" +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" +#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" + +namespace webrtc { +namespace rtcp { +// Reference picture selection indication (RPSI) (RFC 4585). +class Rpsi : public RtcpPacket { + public: + Rpsi() + : RtcpPacket(), + padding_bytes_(0) { + memset(&rpsi_, 0, sizeof(rpsi_)); + } + + virtual ~Rpsi() {} + + void From(uint32_t ssrc) { + rpsi_.SenderSSRC = ssrc; + } + void To(uint32_t ssrc) { + rpsi_.MediaSSRC = ssrc; + } + void WithPayloadType(uint8_t payload) { + assert(payload <= 0x7f); + rpsi_.PayloadType = payload; + } + void WithPictureId(uint64_t picture_id); + + protected: + bool Create(uint8_t* packet, + size_t* index, + size_t max_length, + RtcpPacket::PacketReadyCallback* callback) const override; + + private: + size_t BlockLength() const { + size_t fci_length = 2 + (rpsi_.NumberOfValidBits / 8) + padding_bytes_; + return kCommonFbFmtLength + fci_length; + } + + uint8_t padding_bytes_; + RTCPUtility::RTCPPacketPSFBRPSI rpsi_; + + RTC_DISALLOW_COPY_AND_ASSIGN(Rpsi); +}; +} // namespace rtcp +} // namespace webrtc +#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_RPSI_H_ diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi_unittest.cc new file mode 100644 index 0000000000..4857a2a0a9 --- /dev/null +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi_unittest.cc @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2016 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/rpsi.h" + +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +#include "webrtc/test/rtcp_packet_parser.h" + +using webrtc::rtcp::RawPacket; +using webrtc::rtcp::Rpsi; +using webrtc::test::RtcpPacketParser; + +namespace webrtc { + +TEST(RtcpPacketRpsiTest, WithOneByteNativeString) { + Rpsi rpsi; + // 1000001 (7 bits = 1 byte in native string). + const uint64_t kPictureId = 0x41; + const uint16_t kNumberOfValidBytes = 1; + rpsi.WithPayloadType(100); + rpsi.WithPictureId(kPictureId); + + rtc::scoped_ptr packet(rpsi.Build()); + RtcpPacketParser parser; + parser.Parse(packet->Buffer(), packet->Length()); + EXPECT_EQ(100, parser.rpsi()->PayloadType()); + EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); + EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); +} + +TEST(RtcpPacketRpsiTest, WithTwoByteNativeString) { + Rpsi rpsi; + // |1 0000001 (7 bits = 1 byte in native string). + const uint64_t kPictureId = 0x81; + const uint16_t kNumberOfValidBytes = 2; + rpsi.WithPictureId(kPictureId); + + rtc::scoped_ptr packet(rpsi.Build()); + RtcpPacketParser parser; + parser.Parse(packet->Buffer(), packet->Length()); + EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); + EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); +} + +TEST(RtcpPacketRpsiTest, WithThreeByteNativeString) { + Rpsi rpsi; + // 10000|00 100000|0 1000000 (7 bits = 1 byte in native string). + const uint64_t kPictureId = 0x102040; + const uint16_t kNumberOfValidBytes = 3; + rpsi.WithPictureId(kPictureId); + + rtc::scoped_ptr packet(rpsi.Build()); + RtcpPacketParser parser; + parser.Parse(packet->Buffer(), packet->Length()); + EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); + EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); +} + +TEST(RtcpPacketRpsiTest, WithFourByteNativeString) { + Rpsi rpsi; + // 1000|001 00001|01 100001|1 1000010 (7 bits = 1 byte in native string). + const uint64_t kPictureId = 0x84161C2; + const uint16_t kNumberOfValidBytes = 4; + rpsi.WithPictureId(kPictureId); + + rtc::scoped_ptr packet(rpsi.Build()); + RtcpPacketParser parser; + parser.Parse(packet->Buffer(), packet->Length()); + EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); + EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); +} + +TEST(RtcpPacketRpsiTest, WithMaxPictureId) { + Rpsi rpsi; + // 1 1111111| 1111111 1|111111 11|11111 111|1111 1111|111 11111| + // 11 111111|1 1111111 (7 bits = 1 byte in native string). + const uint64_t kPictureId = 0xffffffffffffffff; + const uint16_t kNumberOfValidBytes = 10; + rpsi.WithPictureId(kPictureId); + + rtc::scoped_ptr packet(rpsi.Build()); + RtcpPacketParser parser; + parser.Parse(packet->Buffer(), packet->Length()); + EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); + EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); +} + +} // 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 aeabf2e55c..7b942871e9 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_packet_unittest.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet_unittest.cc @@ -26,7 +26,6 @@ using webrtc::rtcp::Bye; using webrtc::rtcp::RawPacket; using webrtc::rtcp::ReceiverReport; using webrtc::rtcp::ReportBlock; -using webrtc::rtcp::Rpsi; using webrtc::rtcp::Sdes; using webrtc::rtcp::SenderReport; using webrtc::test::RtcpPacketParser; @@ -209,78 +208,6 @@ TEST(RtcpPacketTest, CnameItemWithEmptyString) { EXPECT_EQ("", parser.sdes_chunk()->Cname()); } -TEST(RtcpPacketTest, Rpsi) { - Rpsi rpsi; - // 1000001 (7 bits = 1 byte in native string). - const uint64_t kPictureId = 0x41; - const uint16_t kNumberOfValidBytes = 1; - rpsi.WithPayloadType(100); - rpsi.WithPictureId(kPictureId); - - rtc::scoped_ptr packet(rpsi.Build()); - RtcpPacketParser parser; - parser.Parse(packet->Buffer(), packet->Length()); - EXPECT_EQ(100, parser.rpsi()->PayloadType()); - EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); - EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); -} - -TEST(RtcpPacketTest, RpsiWithTwoByteNativeString) { - Rpsi rpsi; - // |1 0000001 (7 bits = 1 byte in native string). - const uint64_t kPictureId = 0x81; - const uint16_t kNumberOfValidBytes = 2; - rpsi.WithPictureId(kPictureId); - - rtc::scoped_ptr packet(rpsi.Build()); - RtcpPacketParser parser; - parser.Parse(packet->Buffer(), packet->Length()); - EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); - EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); -} - -TEST(RtcpPacketTest, RpsiWithThreeByteNativeString) { - Rpsi rpsi; - // 10000|00 100000|0 1000000 (7 bits = 1 byte in native string). - const uint64_t kPictureId = 0x102040; - const uint16_t kNumberOfValidBytes = 3; - rpsi.WithPictureId(kPictureId); - - rtc::scoped_ptr packet(rpsi.Build()); - RtcpPacketParser parser; - parser.Parse(packet->Buffer(), packet->Length()); - EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); - EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); -} - -TEST(RtcpPacketTest, RpsiWithFourByteNativeString) { - Rpsi rpsi; - // 1000|001 00001|01 100001|1 1000010 (7 bits = 1 byte in native string). - const uint64_t kPictureId = 0x84161C2; - const uint16_t kNumberOfValidBytes = 4; - rpsi.WithPictureId(kPictureId); - - rtc::scoped_ptr packet(rpsi.Build()); - RtcpPacketParser parser; - parser.Parse(packet->Buffer(), packet->Length()); - EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); - EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); -} - -TEST(RtcpPacketTest, RpsiWithMaxPictureId) { - Rpsi rpsi; - // 1 1111111| 1111111 1|111111 11|11111 111|1111 1111|111 11111| - // 11 111111|1 1111111 (7 bits = 1 byte in native string). - const uint64_t kPictureId = 0xffffffffffffffff; - const uint16_t kNumberOfValidBytes = 10; - rpsi.WithPictureId(kPictureId); - - rtc::scoped_ptr packet(rpsi.Build()); - RtcpPacketParser parser; - parser.Parse(packet->Buffer(), packet->Length()); - EXPECT_EQ(kNumberOfValidBytes * 8, parser.rpsi()->NumberOfValidBits()); - EXPECT_EQ(kPictureId, parser.rpsi()->PictureId()); -} TEST(RtcpPacketTest, BuildWithTooSmallBuffer) { ReportBlock rb; diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc index 9ff50fc811..bf7d24f320 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc @@ -31,6 +31,7 @@ #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h" +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h" #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"