Cleanup RtpPacketizerVP8 tests

Remove partition support for test helper and from tests.
Merge Init function into constructor
Replace extra macroses in favor of Bit helper function
Replace extra members in favor of local variables
Remove fixture

Bug: None
Change-Id: Ibf1600dda9f59abe5afd2bbe40c3e232a2d269ea
Reviewed-on: https://webrtc-review.googlesource.com/96940
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24508}
This commit is contained in:
Danil Chapovalov
2018-08-30 20:54:58 +02:00
committed by Commit Bot
parent d3b8c63b58
commit 8a3c166fff
4 changed files with 167 additions and 351 deletions

View File

@ -447,6 +447,7 @@ if (rtc_include_tests) {
"../../test:test_common", "../../test:test_common",
"../../test:test_support", "../../test:test_support",
"../audio_coding:audio_format_conversion", "../audio_coding:audio_format_conversion",
"../video_coding:codec_globals_headers",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]

View File

@ -10,68 +10,17 @@
#include "modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h" #include "modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h"
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
#include "test/gmock.h"
#include "test/gtest.h" #include "test/gtest.h"
namespace webrtc { namespace webrtc {
namespace {
namespace test { using ::testing::ElementsAreArray;
constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr; constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr;
RtpFormatVp8TestHelper::RtpFormatVp8TestHelper(const RTPVideoHeaderVP8* hdr)
: packet_(kNoExtensions),
payload_data_(NULL),
data_ptr_(NULL),
hdr_info_(hdr),
payload_start_(0),
payload_size_(0),
sloppy_partitioning_(false),
inited_(false) {}
RtpFormatVp8TestHelper::~RtpFormatVp8TestHelper() {
delete[] payload_data_;
}
bool RtpFormatVp8TestHelper::Init(const size_t* partition_sizes,
size_t num_partitions) {
if (inited_)
return false;
payload_size_ = 0;
// Calculate sum payload size.
for (size_t p = 0; p < num_partitions; ++p) {
payload_size_ += partition_sizes[p];
}
payload_data_ = new uint8_t[payload_size_];
size_t j = 0;
// Loop through the partitions again.
for (size_t p = 0; p < num_partitions; ++p) {
for (size_t i = 0; i < partition_sizes[p]; ++i) {
assert(j < payload_size_);
payload_data_[j++] = p; // Set the payload value to the partition index.
}
}
data_ptr_ = payload_data_;
inited_ = true;
return true;
}
void RtpFormatVp8TestHelper::GetAllPacketsAndCheck(
RtpPacketizerVp8* packetizer,
const size_t* expected_sizes,
const int* expected_part,
const bool* expected_frag_start,
size_t expected_num_packets) {
ASSERT_TRUE(inited_);
for (size_t i = 0; i < expected_num_packets; ++i) {
std::ostringstream ss;
ss << "Checking packet " << i;
SCOPED_TRACE(ss.str());
EXPECT_TRUE(packetizer->NextPacket(&packet_));
CheckPacket(expected_sizes[i], i + 1 == expected_num_packets,
expected_frag_start[i]);
}
}
// Payload descriptor // Payload descriptor
// 0 1 2 3 4 5 6 7 // 0 1 2 3 4 5 6 7
// +-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+
@ -79,159 +28,145 @@ void RtpFormatVp8TestHelper::GetAllPacketsAndCheck(
// +-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+
// X: |I|L|T|K| RSV | (OPTIONAL) // X: |I|L|T|K| RSV | (OPTIONAL)
// +-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+
// I: | PictureID | (OPTIONAL) // |M| PictureID |
// I: +-+-+-+-+-+-+-+-+ (OPTIONAL)
// | PictureID |
// +-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+
// L: | TL0PICIDX | (OPTIONAL) // L: | TL0PICIDX | (OPTIONAL)
// +-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+
// T/K: | TID | KEYIDX | (OPTIONAL) // T/K: |TID|Y| KEYIDX | (OPTIONAL)
// +-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+
// First octet tests. int Bit(uint8_t byte, int position) {
#define EXPECT_BIT_EQ(x, n, a) EXPECT_EQ((((x) >> (n)) & 0x1), a) return (byte >> position) & 0x01;
}
#define EXPECT_RSV_ZERO(x) EXPECT_EQ(((x)&0xE0), 0) } // namespace
#define EXPECT_BIT_X_EQ(x, a) EXPECT_BIT_EQ(x, 7, a) RtpFormatVp8TestHelper::RtpFormatVp8TestHelper(const RTPVideoHeaderVP8* hdr,
size_t payload_len)
: hdr_info_(hdr), payload_(payload_len) {
for (size_t i = 0; i < payload_.size(); ++i) {
payload_[i] = i;
}
}
#define EXPECT_BIT_N_EQ(x, a) EXPECT_BIT_EQ(x, 5, a) RtpFormatVp8TestHelper::~RtpFormatVp8TestHelper() = default;
#define EXPECT_BIT_S_EQ(x, a) EXPECT_BIT_EQ(x, 4, a) void RtpFormatVp8TestHelper::GetAllPacketsAndCheck(
RtpPacketizerVp8* packetizer,
rtc::ArrayView<const size_t> expected_sizes) {
EXPECT_EQ(packetizer->NumPackets(), expected_sizes.size());
const uint8_t* data_ptr = payload_.begin();
RtpPacketToSend packet(kNoExtensions);
for (size_t i = 0; i < expected_sizes.size(); ++i) {
EXPECT_TRUE(packetizer->NextPacket(&packet));
auto rtp_payload = packet.payload();
EXPECT_EQ(rtp_payload.size(), expected_sizes[i]);
#define EXPECT_PART_ID_EQ(x, a) EXPECT_EQ(((x)&0x0F), a) int payload_offset = CheckHeader(rtp_payload, /*first=*/i == 0);
// Verify that the payload (i.e., after the headers) of the packet is
// identical to the expected (as found in data_ptr).
auto vp8_payload = rtp_payload.subview(payload_offset);
ASSERT_GE(payload_.end() - data_ptr, static_cast<int>(vp8_payload.size()));
EXPECT_THAT(vp8_payload, ElementsAreArray(data_ptr, vp8_payload.size()));
data_ptr += vp8_payload.size();
}
EXPECT_EQ(payload_.end() - data_ptr, 0);
}
// Extension fields tests int RtpFormatVp8TestHelper::CheckHeader(rtc::ArrayView<const uint8_t> buffer,
#define EXPECT_BIT_I_EQ(x, a) EXPECT_BIT_EQ(x, 7, a) bool first) {
int x_bit = Bit(buffer[0], 7);
#define EXPECT_BIT_L_EQ(x, a) EXPECT_BIT_EQ(x, 6, a) EXPECT_EQ(Bit(buffer[0], 6), 0); // Reserved.
EXPECT_EQ(Bit(buffer[0], 5), hdr_info_->nonReference ? 1 : 0);
#define EXPECT_BIT_T_EQ(x, a) EXPECT_BIT_EQ(x, 5, a) EXPECT_EQ(Bit(buffer[0], 4), first ? 1 : 0);
EXPECT_EQ(buffer[0] & 0x0f, 0); // RtpPacketizerVp8 always uses partition 0.
#define EXPECT_BIT_K_EQ(x, a) EXPECT_BIT_EQ(x, 4, a)
#define EXPECT_TID_EQ(x, a) EXPECT_EQ((((x)&0xC0) >> 6), a)
#define EXPECT_BIT_Y_EQ(x, a) EXPECT_BIT_EQ(x, 5, a)
#define EXPECT_KEYIDX_EQ(x, a) EXPECT_EQ(((x)&0x1F), a)
void RtpFormatVp8TestHelper::CheckHeader(bool frag_start) {
payload_start_ = 1;
rtc::ArrayView<const uint8_t> buffer = packet_.payload();
EXPECT_BIT_EQ(buffer[0], 6, 0); // Check reserved bit.
EXPECT_PART_ID_EQ(buffer[0], 0); // In equal size mode, PartID is always 0.
int payload_offset = 1;
if (hdr_info_->pictureId != kNoPictureId || if (hdr_info_->pictureId != kNoPictureId ||
hdr_info_->temporalIdx != kNoTemporalIdx || hdr_info_->temporalIdx != kNoTemporalIdx ||
hdr_info_->tl0PicIdx != kNoTl0PicIdx || hdr_info_->keyIdx != kNoKeyIdx) { hdr_info_->tl0PicIdx != kNoTl0PicIdx || hdr_info_->keyIdx != kNoKeyIdx) {
EXPECT_BIT_X_EQ(buffer[0], 1); EXPECT_EQ(x_bit, 1);
++payload_start_; ++payload_offset;
CheckPictureID(); CheckPictureID(buffer, &payload_offset);
CheckTl0PicIdx(); CheckTl0PicIdx(buffer, &payload_offset);
CheckTIDAndKeyIdx(); CheckTIDAndKeyIdx(buffer, &payload_offset);
EXPECT_EQ(buffer[1] & 0x07, 0); // Reserved.
} else { } else {
EXPECT_BIT_X_EQ(buffer[0], 0); EXPECT_EQ(x_bit, 0);
} }
EXPECT_BIT_N_EQ(buffer[0], hdr_info_->nonReference ? 1 : 0); return payload_offset;
EXPECT_BIT_S_EQ(buffer[0], frag_start ? 1 : 0);
// Check partition index.
if (!sloppy_partitioning_) {
// The test payload data is constructed such that the payload value is the
// same as the partition index.
EXPECT_EQ(buffer[0] & 0x0F, buffer[payload_start_]);
} else {
// Partition should be set to 0.
EXPECT_EQ(buffer[0] & 0x0F, 0);
}
} }
// Verify that the I bit and the PictureID field are both set in accordance // Verify that the I bit and the PictureID field are both set in accordance
// with the information in hdr_info_->pictureId. // with the information in hdr_info_->pictureId.
void RtpFormatVp8TestHelper::CheckPictureID() { void RtpFormatVp8TestHelper::CheckPictureID(
auto buffer = packet_.payload(); rtc::ArrayView<const uint8_t> buffer,
int* offset) {
int i_bit = Bit(buffer[1], 7);
if (hdr_info_->pictureId != kNoPictureId) { if (hdr_info_->pictureId != kNoPictureId) {
EXPECT_BIT_I_EQ(buffer[1], 1); EXPECT_EQ(i_bit, 1);
EXPECT_BIT_EQ(buffer[payload_start_], 7, 1); int two_byte_picture_id = Bit(buffer[*offset], 7);
EXPECT_EQ(buffer[payload_start_] & 0x7F, EXPECT_EQ(two_byte_picture_id, 1);
(hdr_info_->pictureId >> 8) & 0x7F); EXPECT_EQ(buffer[*offset] & 0x7F, (hdr_info_->pictureId >> 8) & 0x7F);
EXPECT_EQ(buffer[payload_start_ + 1], hdr_info_->pictureId & 0xFF); EXPECT_EQ(buffer[(*offset) + 1], hdr_info_->pictureId & 0xFF);
payload_start_ += 2; (*offset) += 2;
} else { } else {
EXPECT_BIT_I_EQ(buffer[1], 0); EXPECT_EQ(i_bit, 0);
} }
} }
// Verify that the L bit and the TL0PICIDX field are both set in accordance // Verify that the L bit and the TL0PICIDX field are both set in accordance
// with the information in hdr_info_->tl0PicIdx. // with the information in hdr_info_->tl0PicIdx.
void RtpFormatVp8TestHelper::CheckTl0PicIdx() { void RtpFormatVp8TestHelper::CheckTl0PicIdx(
auto buffer = packet_.payload(); rtc::ArrayView<const uint8_t> buffer,
int* offset) {
int l_bit = Bit(buffer[1], 6);
if (hdr_info_->tl0PicIdx != kNoTl0PicIdx) { if (hdr_info_->tl0PicIdx != kNoTl0PicIdx) {
EXPECT_BIT_L_EQ(buffer[1], 1); EXPECT_EQ(l_bit, 1);
EXPECT_EQ(buffer[payload_start_], hdr_info_->tl0PicIdx); EXPECT_EQ(buffer[*offset], hdr_info_->tl0PicIdx);
++payload_start_; ++*offset;
} else { } else {
EXPECT_BIT_L_EQ(buffer[1], 0); EXPECT_EQ(l_bit, 0);
} }
} }
// Verify that the T bit and the TL0PICIDX field, and the K bit and KEYIDX // Verify that the T bit and the TL0PICIDX field, and the K bit and KEYIDX
// field are all set in accordance with the information in // field are all set in accordance with the information in
// hdr_info_->temporalIdx and hdr_info_->keyIdx, respectively. // hdr_info_->temporalIdx and hdr_info_->keyIdx, respectively.
void RtpFormatVp8TestHelper::CheckTIDAndKeyIdx() { void RtpFormatVp8TestHelper::CheckTIDAndKeyIdx(
auto buffer = packet_.payload(); rtc::ArrayView<const uint8_t> buffer,
int* offset) {
int t_bit = Bit(buffer[1], 5);
int k_bit = Bit(buffer[1], 4);
if (hdr_info_->temporalIdx == kNoTemporalIdx && if (hdr_info_->temporalIdx == kNoTemporalIdx &&
hdr_info_->keyIdx == kNoKeyIdx) { hdr_info_->keyIdx == kNoKeyIdx) {
EXPECT_BIT_T_EQ(buffer[1], 0); EXPECT_EQ(t_bit, 0);
EXPECT_BIT_K_EQ(buffer[1], 0); EXPECT_EQ(k_bit, 0);
return; return;
} }
int temporal_id = (buffer[*offset] & 0xC0) >> 6;
int y_bit = Bit(buffer[*offset], 5);
int key_idx = buffer[*offset] & 0x1f;
if (hdr_info_->temporalIdx != kNoTemporalIdx) { if (hdr_info_->temporalIdx != kNoTemporalIdx) {
EXPECT_BIT_T_EQ(buffer[1], 1); EXPECT_EQ(t_bit, 1);
EXPECT_TID_EQ(buffer[payload_start_], hdr_info_->temporalIdx); EXPECT_EQ(temporal_id, hdr_info_->temporalIdx);
EXPECT_BIT_Y_EQ(buffer[payload_start_], hdr_info_->layerSync ? 1 : 0); EXPECT_EQ(y_bit, hdr_info_->layerSync ? 1 : 0);
} else { } else {
EXPECT_BIT_T_EQ(buffer[1], 0); EXPECT_EQ(t_bit, 0);
EXPECT_TID_EQ(buffer[payload_start_], 0); EXPECT_EQ(temporal_id, 0);
EXPECT_BIT_Y_EQ(buffer[payload_start_], 0); EXPECT_EQ(y_bit, 0);
} }
if (hdr_info_->keyIdx != kNoKeyIdx) { if (hdr_info_->keyIdx != kNoKeyIdx) {
EXPECT_BIT_K_EQ(buffer[1], 1); EXPECT_EQ(k_bit, 1);
EXPECT_KEYIDX_EQ(buffer[payload_start_], hdr_info_->keyIdx); EXPECT_EQ(key_idx, hdr_info_->keyIdx);
} else { } else {
EXPECT_BIT_K_EQ(buffer[1], 0); EXPECT_EQ(k_bit, 0);
EXPECT_KEYIDX_EQ(buffer[payload_start_], 0); EXPECT_EQ(key_idx, 0);
} }
++payload_start_; ++*offset;
} }
// Verify that the payload (i.e., after the headers) of the packet stored in
// buffer_ is identical to the expected (as found in data_ptr_).
void RtpFormatVp8TestHelper::CheckPayload() {
auto buffer = packet_.payload();
size_t payload_end = buffer.size();
for (size_t i = payload_start_; i < payload_end; ++i, ++data_ptr_)
EXPECT_EQ(buffer[i], *data_ptr_);
}
// Verify that the input variable "last" agrees with the position of data_ptr_.
// If data_ptr_ has advanced payload_size_ bytes from the start (payload_data_)
// we are at the end and last should be true. Otherwise, it should be false.
void RtpFormatVp8TestHelper::CheckLast(bool last) const {
EXPECT_EQ(last, data_ptr_ == payload_data_ + payload_size_);
}
// Verify the contents of a packet. Check the length versus expected_bytes,
// the header, payload, and "last" flag.
void RtpFormatVp8TestHelper::CheckPacket(size_t expect_bytes,
bool last,
bool frag_start) {
EXPECT_EQ(expect_bytes, packet_.payload_size());
CheckHeader(frag_start);
CheckPayload();
CheckLast(last);
}
} // namespace test
} // namespace webrtc } // namespace webrtc

View File

@ -18,59 +18,39 @@
#ifndef MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_TEST_HELPER_H_ #ifndef MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_TEST_HELPER_H_
#define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_TEST_HELPER_H_ #define MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_TEST_HELPER_H_
#include "modules/include/module_common_types.h" #include "api/array_view.h"
#include "modules/rtp_rtcp/source/rtp_format_vp8.h" #include "modules/rtp_rtcp/source/rtp_format_vp8.h"
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h" #include "modules/video_coding/codecs/vp8/include/vp8_globals.h"
#include "rtc_base/buffer.h"
#include "rtc_base/constructormagic.h" #include "rtc_base/constructormagic.h"
namespace webrtc { namespace webrtc {
namespace test {
class RtpFormatVp8TestHelper { class RtpFormatVp8TestHelper {
public: public:
explicit RtpFormatVp8TestHelper(const RTPVideoHeaderVP8* hdr); RtpFormatVp8TestHelper(const RTPVideoHeaderVP8* hdr, size_t payload_len);
~RtpFormatVp8TestHelper(); ~RtpFormatVp8TestHelper();
bool Init(const size_t* partition_sizes, size_t num_partitions);
void GetAllPacketsAndCheck(RtpPacketizerVp8* packetizer, void GetAllPacketsAndCheck(RtpPacketizerVp8* packetizer,
const size_t* expected_sizes, rtc::ArrayView<const size_t> expected_sizes);
const int* expected_part,
const bool* expected_frag_start,
size_t expected_num_packets);
rtc::ArrayView<const uint8_t> payload() const { rtc::ArrayView<const uint8_t> payload() const { return payload_; }
return rtc::ArrayView<const uint8_t>(payload_data_, payload_size_); size_t payload_size() const { return payload_.size(); }
}
size_t payload_size() const { return payload_size_; }
size_t buffer_size() const {
static constexpr size_t kVp8PayloadDescriptorMaxSize = 6;
return payload_size_ + kVp8PayloadDescriptorMaxSize;
}
void set_sloppy_partitioning(bool value) { sloppy_partitioning_ = value; }
private: private:
void CheckHeader(bool frag_start); // Returns header size, i.e. payload offset.
void CheckPictureID(); int CheckHeader(rtc::ArrayView<const uint8_t> rtp_payload, bool first);
void CheckTl0PicIdx(); void CheckPictureID(rtc::ArrayView<const uint8_t> rtp_payload, int* offset);
void CheckTIDAndKeyIdx(); void CheckTl0PicIdx(rtc::ArrayView<const uint8_t> rtp_payload, int* offset);
void CheckPayload(); void CheckTIDAndKeyIdx(rtc::ArrayView<const uint8_t> rtp_payload,
void CheckLast(bool last) const; int* offset);
void CheckPacket(size_t expect_bytes, bool last, bool frag_start); void CheckPayload(const uint8_t* data_ptr);
RtpPacketToSend packet_; const RTPVideoHeaderVP8* const hdr_info_;
uint8_t* payload_data_; rtc::Buffer payload_;
uint8_t* data_ptr_;
const RTPVideoHeaderVP8* hdr_info_;
int payload_start_;
size_t payload_size_;
bool sloppy_partitioning_;
bool inited_;
RTC_DISALLOW_COPY_AND_ASSIGN(RtpFormatVp8TestHelper); RTC_DISALLOW_COPY_AND_ASSIGN(RtpFormatVp8TestHelper);
}; };
} // namespace test
} // namespace webrtc } // namespace webrtc
#endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_TEST_HELPER_H_ #endif // MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_TEST_HELPER_H_

View File

@ -16,10 +16,6 @@
#include "test/gmock.h" #include "test/gmock.h"
#include "test/gtest.h" #include "test/gtest.h"
#define CHECK_ARRAY_SIZE(expected_size, array) \
static_assert(expected_size == sizeof(array) / sizeof(array[0]), \
"check array size");
namespace webrtc { namespace webrtc {
namespace { namespace {
@ -27,6 +23,7 @@ using ::testing::ElementsAreArray;
using ::testing::make_tuple; using ::testing::make_tuple;
constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr; constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr;
constexpr RtpPacketizer::PayloadSizeLimits kNoSizeLimits;
// Payload descriptor // Payload descriptor
// 0 1 2 3 4 5 6 7 // 0 1 2 3 4 5 6 7
// +-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+
@ -76,67 +73,33 @@ void VerifyExtensions(RTPVideoHeader* header,
EXPECT_EQ(temporal_idx, header->vp8().temporalIdx); EXPECT_EQ(temporal_idx, header->vp8().temporalIdx);
EXPECT_EQ(key_idx, header->vp8().keyIdx); EXPECT_EQ(key_idx, header->vp8().keyIdx);
} }
} // namespace } // namespace
class RtpPacketizerVp8Test : public ::testing::Test { TEST(RtpPacketizerVp8Test, ResultPacketsAreAlmostEqualSize) {
protected: RTPVideoHeaderVP8 hdr_info;
RtpPacketizerVp8Test() : helper_(NULL) {} hdr_info.InitRTPVideoHeaderVP8();
void TearDown() override { delete helper_; } hdr_info.pictureId = 200;
bool Init(const size_t* partition_sizes, size_t num_partitions) { RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
hdr_info_.pictureId = kNoPictureId;
hdr_info_.nonReference = false;
hdr_info_.temporalIdx = kNoTemporalIdx;
hdr_info_.layerSync = false;
hdr_info_.tl0PicIdx = kNoTl0PicIdx;
hdr_info_.keyIdx = kNoKeyIdx;
if (helper_ != NULL)
return false;
helper_ = new test::RtpFormatVp8TestHelper(&hdr_info_);
return helper_->Init(partition_sizes, num_partitions);
}
RTPVideoHeaderVP8 hdr_info_;
test::RtpFormatVp8TestHelper* helper_;
};
// Verify that EqualSize mode is forced if fragmentation info is missing.
TEST_F(RtpPacketizerVp8Test, TestEqualSizeModeFallback) {
const size_t kSizeVector[] = {10, 10, 10};
const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector);
ASSERT_TRUE(Init(kSizeVector, kNumPartitions));
hdr_info_.pictureId = 200; // > 0x7F should produce 2-byte PictureID
RtpPacketizer::PayloadSizeLimits limits; RtpPacketizer::PayloadSizeLimits limits;
limits.max_payload_len = 12; // Small enough to produce 4 packets. limits.max_payload_len = 12; // Small enough to produce 4 packets.
RtpPacketizerVp8 packetizer(helper_->payload(), limits, hdr_info_); RtpPacketizerVp8 packetizer(helper.payload(), limits, hdr_info);
size_t num_packets = packetizer.NumPackets();
// Expecting three full packets, and one with the remainder.
const size_t kExpectedSizes[] = {11, 11, 12, 12}; const size_t kExpectedSizes[] = {11, 11, 12, 12};
const int kExpectedPart[] = {0, 0, 0, 0}; // Always 0 for equal size mode. helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
// Frag start only true for first packet in equal size mode.
const bool kExpectedFragStart[] = {true, false, false, false};
const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
ASSERT_EQ(num_packets, kExpectedNum);
helper_->set_sloppy_partitioning(true);
helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart,
kExpectedFragStart, kExpectedNum);
} }
TEST_F(RtpPacketizerVp8Test, TestEqualSizeWithLastPacketReduction) { TEST(RtpPacketizerVp8Test, EqualSizeWithLastPacketReduction) {
const size_t kSizeVector[] = {30, 10, 3}; RTPVideoHeaderVP8 hdr_info;
const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); hdr_info.InitRTPVideoHeaderVP8();
ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); hdr_info.pictureId = 200;
RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/43);
hdr_info_.pictureId = 200;
RtpPacketizer::PayloadSizeLimits limits; RtpPacketizer::PayloadSizeLimits limits;
limits.max_payload_len = 15; // Small enough to produce 5 packets. limits.max_payload_len = 15; // Small enough to produce 5 packets.
limits.last_packet_reduction_len = 5; limits.last_packet_reduction_len = 5;
RtpPacketizerVp8 packetizer(helper_->payload(), limits, hdr_info_); RtpPacketizerVp8 packetizer(helper.payload(), limits, hdr_info);
size_t num_packets = packetizer.NumPackets();
// Calculated by hand. VP8 payload descriptors are 4 byte each. 5 packets is // Calculated by hand. VP8 payload descriptors are 4 byte each. 5 packets is
// minimum possible to fit 43 payload bytes into packets with capacity of // minimum possible to fit 43 payload bytes into packets with capacity of
@ -144,125 +107,63 @@ TEST_F(RtpPacketizerVp8Test, TestEqualSizeWithLastPacketReduction) {
// almost equal in size, even last packet if counted with free space (which // almost equal in size, even last packet if counted with free space (which
// will be filled up the stack by extra long RTP header). // will be filled up the stack by extra long RTP header).
const size_t kExpectedSizes[] = {13, 13, 14, 14, 9}; const size_t kExpectedSizes[] = {13, 13, 14, 14, 9};
const int kExpectedPart[] = {0, 0, 0, 0, 0}; // Always 0 for equal size mode. helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
// Frag start only true for first packet in equal size mode.
const bool kExpectedFragStart[] = {true, false, false, false, false};
const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
ASSERT_EQ(num_packets, kExpectedNum);
helper_->set_sloppy_partitioning(true);
helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart,
kExpectedFragStart, kExpectedNum);
} }
// Verify that non-reference bit is set. EqualSize mode fallback is expected. // Verify that non-reference bit is set.
TEST_F(RtpPacketizerVp8Test, TestNonReferenceBit) { TEST(RtpPacketizerVp8Test, NonReferenceBit) {
const size_t kSizeVector[] = {10, 10, 10}; RTPVideoHeaderVP8 hdr_info;
const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); hdr_info.InitRTPVideoHeaderVP8();
ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); hdr_info.nonReference = true;
RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
hdr_info_.nonReference = true;
RtpPacketizer::PayloadSizeLimits limits; RtpPacketizer::PayloadSizeLimits limits;
limits.max_payload_len = 25; // Small enough to produce two packets. limits.max_payload_len = 25; // Small enough to produce two packets.
RtpPacketizerVp8 packetizer(helper_->payload(), limits, hdr_info_); RtpPacketizerVp8 packetizer(helper.payload(), limits, hdr_info);
size_t num_packets = packetizer.NumPackets();
// EqualSize mode => First packet full; other not.
const size_t kExpectedSizes[] = {16, 16}; const size_t kExpectedSizes[] = {16, 16};
const int kExpectedPart[] = {0, 0}; // Always 0 for equal size mode. helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
// Frag start only true for first packet in equal size mode.
const bool kExpectedFragStart[] = {true, false};
const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
ASSERT_EQ(num_packets, kExpectedNum);
helper_->set_sloppy_partitioning(true);
helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart,
kExpectedFragStart, kExpectedNum);
} }
// Verify Tl0PicIdx and TID fields, and layerSync bit. // Verify Tl0PicIdx and TID fields, and layerSync bit.
TEST_F(RtpPacketizerVp8Test, TestTl0PicIdxAndTID) { TEST(RtpPacketizerVp8Test, Tl0PicIdxAndTID) {
const size_t kSizeVector[] = {10, 10, 10}; RTPVideoHeaderVP8 hdr_info;
const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); hdr_info.InitRTPVideoHeaderVP8();
ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); hdr_info.tl0PicIdx = 117;
hdr_info.temporalIdx = 2;
hdr_info.layerSync = true;
RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
hdr_info_.tl0PicIdx = 117; RtpPacketizerVp8 packetizer(helper.payload(), kNoSizeLimits, hdr_info);
hdr_info_.temporalIdx = 2;
hdr_info_.layerSync = true;
RtpPacketizer::PayloadSizeLimits limits;
// max_payload_len is only limited by allocated buffer size.
limits.max_payload_len = helper_->buffer_size();
RtpPacketizerVp8 packetizer(helper_->payload(), limits, hdr_info_);
size_t num_packets = packetizer.NumPackets();
// Expect one single packet of payload_size() + 4 bytes header. const size_t kExpectedSizes[1] = {helper.payload_size() + 4};
const size_t kExpectedSizes[1] = {helper_->payload_size() + 4}; helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
const int kExpectedPart[1] = {0}; // Packet starts with partition 0.
const bool kExpectedFragStart[1] = {true};
const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
ASSERT_EQ(num_packets, kExpectedNum);
helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart,
kExpectedFragStart, kExpectedNum);
} }
// Verify KeyIdx field. TEST(RtpPacketizerVp8Test, KeyIdx) {
TEST_F(RtpPacketizerVp8Test, TestKeyIdx) { RTPVideoHeaderVP8 hdr_info;
const size_t kSizeVector[] = {10, 10, 10}; hdr_info.InitRTPVideoHeaderVP8();
const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); hdr_info.keyIdx = 17;
ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
hdr_info_.keyIdx = 17; RtpPacketizerVp8 packetizer(helper.payload(), kNoSizeLimits, hdr_info);
RtpPacketizer::PayloadSizeLimits limits;
// max payload len is only limited by allocated buffer size.
limits.max_payload_len = helper_->buffer_size();
RtpPacketizerVp8 packetizer(helper_->payload(), limits, hdr_info_);
size_t num_packets = packetizer.NumPackets();
// Expect one single packet of payload_size() + 3 bytes header. const size_t kExpectedSizes[1] = {helper.payload_size() + 3};
const size_t kExpectedSizes[1] = {helper_->payload_size() + 3}; helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
const int kExpectedPart[1] = {0}; // Packet starts with partition 0.
const bool kExpectedFragStart[1] = {true};
const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
ASSERT_EQ(num_packets, kExpectedNum);
helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart,
kExpectedFragStart, kExpectedNum);
} }
// Verify TID field and KeyIdx field in combination. // Verify TID field and KeyIdx field in combination.
TEST_F(RtpPacketizerVp8Test, TestTIDAndKeyIdx) { TEST(RtpPacketizerVp8Test, TIDAndKeyIdx) {
const size_t kSizeVector[] = {10, 10, 10}; RTPVideoHeaderVP8 hdr_info;
const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); hdr_info.InitRTPVideoHeaderVP8();
ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); hdr_info.temporalIdx = 1;
hdr_info.keyIdx = 5;
RtpFormatVp8TestHelper helper(&hdr_info, /*payload_len=*/30);
hdr_info_.temporalIdx = 1; RtpPacketizerVp8 packetizer(helper.payload(), kNoSizeLimits, hdr_info);
hdr_info_.keyIdx = 5;
RtpPacketizer::PayloadSizeLimits limits;
// max_payload_len is only limited by allocated buffer size.
limits.max_payload_len = helper_->buffer_size();
RtpPacketizerVp8 packetizer(helper_->payload(), limits, hdr_info_);
size_t num_packets = packetizer.NumPackets();
// Expect one single packet of payload_size() + 3 bytes header. const size_t kExpectedSizes[1] = {helper.payload_size() + 3};
const size_t kExpectedSizes[1] = {helper_->payload_size() + 3}; helper.GetAllPacketsAndCheck(&packetizer, kExpectedSizes);
const int kExpectedPart[1] = {0}; // Packet starts with partition 0.
const bool kExpectedFragStart[1] = {true};
const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart);
CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart);
ASSERT_EQ(num_packets, kExpectedNum);
helper_->GetAllPacketsAndCheck(&packetizer, kExpectedSizes, kExpectedPart,
kExpectedFragStart, kExpectedNum);
} }
class RtpDepacketizerVp8Test : public ::testing::Test { class RtpDepacketizerVp8Test : public ::testing::Test {
@ -274,10 +175,9 @@ class RtpDepacketizerVp8Test : public ::testing::Test {
const uint8_t* data, const uint8_t* data,
size_t length) { size_t length) {
ASSERT_TRUE(parsed_payload != NULL); ASSERT_TRUE(parsed_payload != NULL);
EXPECT_THAT(std::vector<uint8_t>( EXPECT_THAT(
parsed_payload->payload, make_tuple(parsed_payload->payload, parsed_payload->payload_length),
parsed_payload->payload + parsed_payload->payload_length), ElementsAreArray(data, length));
::testing::ElementsAreArray(data, length));
} }
std::unique_ptr<RtpDepacketizer> depacketizer_; std::unique_ptr<RtpDepacketizer> depacketizer_;