rtcp::Pli moved into own file and got a Parse function

Created rtcp::Psfb abstract class between rtcp::Pli and rtcp::RtcpPacket to hold common data for Feedback Message.

BUG=webrtc:5260

Review URL: https://codereview.webrtc.org/1446513002

Cr-Commit-Position: refs/heads/master@{#10823}
This commit is contained in:
danilchap 2015-11-27 05:36:09 -08:00 committed by Commit bot
parent e997a7de14
commit f8385aded0
13 changed files with 289 additions and 108 deletions

View File

@ -307,6 +307,7 @@
'rtp_rtcp/source/rtcp_packet/app_unittest.cc',
'rtp_rtcp/source/rtcp_packet/bye_unittest.cc',
'rtp_rtcp/source/rtcp_packet/extended_jitter_report_unittest.cc',
'rtp_rtcp/source/rtcp_packet/pli_unittest.cc',
'rtp_rtcp/source/rtcp_packet/report_block_unittest.cc',
'rtp_rtcp/source/rtcp_packet/transport_feedback_unittest.cc',
'rtp_rtcp/source/rtcp_receiver_unittest.cc',

View File

@ -52,6 +52,10 @@ source_set("rtp_rtcp") {
"source/rtcp_packet/bye.h",
"source/rtcp_packet/extended_jitter_report.cc",
"source/rtcp_packet/extended_jitter_report.h",
"source/rtcp_packet/pli.cc",
"source/rtcp_packet/pli.h",
"source/rtcp_packet/psfb.cc",
"source/rtcp_packet/psfb.h",
"source/rtcp_packet/report_block.cc",
"source/rtcp_packet/report_block.h",
"source/rtcp_packet/transport_feedback.cc",

View File

@ -47,6 +47,10 @@
'source/rtcp_packet/bye.h',
'source/rtcp_packet/extended_jitter_report.cc',
'source/rtcp_packet/extended_jitter_report.h',
'source/rtcp_packet/pli.cc',
'source/rtcp_packet/pli.h',
'source/rtcp_packet/psfb.cc',
'source/rtcp_packet/psfb.h',
'source/rtcp_packet/report_block.cc',
'source/rtcp_packet/report_block.h',
'source/rtcp_packet/transport_feedback.cc',

View File

@ -31,7 +31,6 @@ using webrtc::RTCPUtility::RTCPPacketAPP;
using webrtc::RTCPUtility::RTCPPacketPSFBAPP;
using webrtc::RTCPUtility::RTCPPacketPSFBFIR;
using webrtc::RTCPUtility::RTCPPacketPSFBFIRItem;
using webrtc::RTCPUtility::RTCPPacketPSFBPLI;
using webrtc::RTCPUtility::RTCPPacketPSFBREMBItem;
using webrtc::RTCPUtility::RTCPPacketPSFBRPSI;
using webrtc::RTCPUtility::RTCPPacketPSFBSLI;
@ -203,34 +202,6 @@ void CreateSdes(const std::vector<Sdes::Chunk>& chunks,
}
}
// RFC 4585: Feedback format.
//
// Common packet format:
//
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| FMT | PT | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of packet sender |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of media source |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// : Feedback Control Information (FCI) :
// :
//
// Picture loss indication (PLI) (RFC 4585).
//
// FCI: no feedback control information.
void CreatePli(const RTCPPacketPSFBPLI& pli,
uint8_t* buffer,
size_t* pos) {
AssignUWord32(buffer, pos, pli.SenderSSRC);
AssignUWord32(buffer, pos, pli.MediaSSRC);
}
// Slice loss indication (SLI) (RFC 4585).
//
// FCI:
@ -777,20 +748,6 @@ size_t Sdes::BlockLength() const {
return length;
}
bool Pli::Create(uint8_t* packet,
size_t* index,
size_t max_length,
RtcpPacket::PacketReadyCallback* callback) const {
while (*index + BlockLength() > max_length) {
if (!OnBufferFull(packet, index, callback))
return false;
}
const uint8_t kFmt = 1;
CreateHeader(kFmt, PT_PSFB, HeaderLength(), packet, index);
CreatePli(pli_, packet, index);
return true;
}
bool Sli::Create(uint8_t* packet,
size_t* index,
size_t max_length,

View File

@ -319,57 +319,6 @@ class Sdes : public RtcpPacket {
RTC_DISALLOW_COPY_AND_ASSIGN(Sdes);
};
// RFC 4585: Feedback format.
//
// Common packet format:
//
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| FMT | PT | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of packet sender |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of media source |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// : Feedback Control Information (FCI) :
// :
// Picture loss indication (PLI) (RFC 4585).
//
// FCI: no feedback control information.
class Pli : public RtcpPacket {
public:
Pli() : RtcpPacket() {
memset(&pli_, 0, sizeof(pli_));
}
virtual ~Pli() {}
void From(uint32_t ssrc) {
pli_.SenderSSRC = ssrc;
}
void To(uint32_t ssrc) {
pli_.MediaSSRC = ssrc;
}
protected:
bool Create(uint8_t* packet,
size_t* index,
size_t max_length,
RtcpPacket::PacketReadyCallback* callback) const override;
private:
size_t BlockLength() const {
return kCommonFbFmtLength;
}
RTCPUtility::RTCPPacketPSFBPLI pli_;
RTC_DISALLOW_COPY_AND_ASSIGN(Pli);
};
// Slice loss indication (SLI) (RFC 4585).
//
// FCI:

View File

@ -0,0 +1,70 @@
/*
* 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/pli.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
using webrtc::RTCPUtility::RtcpCommonHeader;
namespace webrtc {
namespace rtcp {
// RFC 4585: Feedback format.
//
// Common packet format:
//
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| FMT | PT | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of packet sender |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of media source |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// : Feedback Control Information (FCI) :
// : :
//
// Picture loss indication (PLI) (RFC 4585).
// FCI: no feedback control information.
bool Pli::Parse(const RtcpCommonHeader& header, const uint8_t* payload) {
RTC_DCHECK(header.packet_type == kPacketType);
RTC_DCHECK(header.count_or_format == kFeedbackMessageType);
if (header.payload_size_bytes < kCommonFeedbackLength) {
LOG(LS_WARNING) << "Packet is too small to be a valid PLI packet";
return false;
}
ParseCommonFeedback(payload);
return true;
}
bool Pli::Create(uint8_t* packet,
size_t* index,
size_t max_length,
RtcpPacket::PacketReadyCallback* callback) const {
while (*index + BlockLength() > max_length) {
if (!OnBufferFull(packet, index, callback))
return false;
}
CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
index);
CreateCommonFeedback(packet + *index);
*index += kCommonFeedbackLength;
return true;
}
} // namespace rtcp
} // namespace webrtc

View File

@ -0,0 +1,49 @@
/*
* 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_PLI_H_
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PLI_H_
#include "webrtc/base/basictypes.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/psfb.h"
namespace webrtc {
namespace rtcp {
// Picture loss indication (PLI) (RFC 4585).
class Pli : public Psfb {
public:
static const uint8_t kFeedbackMessageType = 1;
Pli() {}
virtual ~Pli() {}
// Parse assumes header is already parsed and validated.
bool Parse(const RTCPUtility::RtcpCommonHeader& header,
const uint8_t* payload); // Size of the payload is in the header.
protected:
bool Create(uint8_t* packet,
size_t* index,
size_t max_length,
RtcpPacket::PacketReadyCallback* callback) const override;
private:
size_t BlockLength() const override {
return kHeaderLength + kCommonFeedbackLength;
}
RTC_DISALLOW_COPY_AND_ASSIGN(Pli);
};
} // namespace rtcp
} // namespace webrtc
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PLI_H_

View File

@ -0,0 +1,66 @@
/*
* 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/pli.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
using webrtc::rtcp::Pli;
using webrtc::rtcp::RawPacket;
using webrtc::RTCPUtility::RtcpCommonHeader;
using webrtc::RTCPUtility::RtcpParseCommonHeader;
namespace webrtc {
namespace {
const uint32_t kSenderSsrc = 0x12345678;
const uint32_t kRemoteSsrc = 0x23456789;
// Manually created Pli packet matching constants above.
const uint8_t kPacket[] = {0x81, 206, 0x00, 0x02,
0x12, 0x34, 0x56, 0x78,
0x23, 0x45, 0x67, 0x89};
const size_t kPacketLength = sizeof(kPacket);
TEST(RtcpPacketPliTest, Parse) {
RtcpCommonHeader header;
EXPECT_TRUE(RtcpParseCommonHeader(kPacket, kPacketLength, &header));
Pli mutable_parsed;
EXPECT_TRUE(mutable_parsed.Parse(
header, kPacket + RtcpCommonHeader::kHeaderSizeBytes));
const Pli& parsed = mutable_parsed; // Read values from constant object.
EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc());
}
TEST(RtcpPacketPliTest, Create) {
Pli pli;
pli.From(kSenderSsrc);
pli.To(kRemoteSsrc);
rtc::scoped_ptr<RawPacket> packet(pli.Build());
ASSERT_EQ(kPacketLength, packet->Length());
EXPECT_EQ(0, memcmp(kPacket, packet->Buffer(), kPacketLength));
}
TEST(RtcpPacketPliTest, ParseFailsOnTooSmallPacket) {
RtcpCommonHeader header;
EXPECT_TRUE(RtcpParseCommonHeader(kPacket, kPacketLength, &header));
header.payload_size_bytes--;
Pli parsed;
EXPECT_FALSE(
parsed.Parse(header, kPacket + RtcpCommonHeader::kHeaderSizeBytes));
}
} // namespace
} // namespace webrtc

View File

@ -0,0 +1,45 @@
/*
* 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/psfb.h"
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
namespace webrtc {
namespace rtcp {
// RFC 4585: Feedback format.
//
// Common packet format:
//
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| FMT | PT | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// 0 | SSRC of packet sender |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// 4 | SSRC of media source |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// : Feedback Control Information (FCI) :
// : :
void Psfb::ParseCommonFeedback(const uint8_t* payload) {
sender_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]);
media_ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[4]);
}
void Psfb::CreateCommonFeedback(uint8_t* payload) const {
ByteWriter<uint32_t>::WriteBigEndian(&payload[0], sender_ssrc_);
ByteWriter<uint32_t>::WriteBigEndian(&payload[4], media_ssrc_);
}
} // namespace rtcp
} // namespace webrtc

View File

@ -0,0 +1,48 @@
/*
* 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_PSFB_H_
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PSFB_H_
#include "webrtc/base/basictypes.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h"
namespace webrtc {
namespace rtcp {
// PSFB: Payload-specific feedback message.
// RFC 4585, Section 6.3.
class Psfb : public RtcpPacket {
public:
static const uint8_t kPacketType = 206;
Psfb() : sender_ssrc_(0), media_ssrc_(0) {}
virtual ~Psfb() {}
void From(uint32_t ssrc) { sender_ssrc_ = ssrc; }
void To(uint32_t ssrc) { media_ssrc_ = ssrc; }
uint32_t sender_ssrc() const { return sender_ssrc_; }
uint32_t media_ssrc() const { return media_ssrc_; }
protected:
static const size_t kCommonFeedbackLength = 8;
void ParseCommonFeedback(const uint8_t* payload);
void CreateCommonFeedback(uint8_t* payload) const;
private:
uint32_t sender_ssrc_;
uint32_t media_ssrc_;
};
} // namespace rtcp
} // namespace webrtc
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_PSFB_H_

View File

@ -26,7 +26,6 @@ using webrtc::rtcp::Dlrr;
using webrtc::rtcp::Empty;
using webrtc::rtcp::Fir;
using webrtc::rtcp::Nack;
using webrtc::rtcp::Pli;
using webrtc::rtcp::Sdes;
using webrtc::rtcp::SenderReport;
using webrtc::rtcp::Sli;
@ -296,19 +295,6 @@ TEST(RtcpPacketTest, CnameItemWithEmptyString) {
EXPECT_EQ("", parser.sdes_chunk()->Cname());
}
TEST(RtcpPacketTest, Pli) {
Pli pli;
pli.From(kSenderSsrc);
pli.To(kRemoteSsrc);
rtc::scoped_ptr<RawPacket> packet(pli.Build());
RtcpPacketParser parser;
parser.Parse(packet->Buffer(), packet->Length());
EXPECT_EQ(1, parser.pli()->num_packets());
EXPECT_EQ(kSenderSsrc, parser.pli()->Ssrc());
EXPECT_EQ(kRemoteSsrc, parser.pli()->MediaSsrc());
}
TEST(RtcpPacketTest, Sli) {
const uint16_t kFirstMb = 7777;
const uint16_t kNumberOfMb = 6666;

View File

@ -28,6 +28,7 @@
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_jitter_report.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
namespace webrtc {

View File

@ -24,6 +24,7 @@
#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h"
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"