Fix formatting of rtp_format_vp8*

Sorting out all lint issues and fixing indentation.

Review URL: http://webrtc-codereview.appspot.com/301011

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1111 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org 2011-12-06 15:56:18 +00:00
parent c7e2bffb66
commit b6e58eb5a1
3 changed files with 656 additions and 738 deletions

@ -8,10 +8,11 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "rtp_format_vp8.h" #include "modules/rtp_rtcp/source/rtp_format_vp8.h"
#include <string.h> // memcpy
#include <cassert> // assert #include <cassert> // assert
#include <string.h> // memcpy
namespace webrtc { namespace webrtc {
@ -40,8 +41,7 @@ RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
balance_(balance_modes_[mode]), balance_(balance_modes_[mode]),
separate_first_(separate_first_modes_[mode]), separate_first_(separate_first_modes_[mode]),
hdr_info_(hdr_info), hdr_info_(hdr_info),
first_partition_in_packet_(0) first_partition_in_packet_(0) {
{
part_info_ = fragmentation; part_info_ = fragmentation;
} }
@ -60,27 +60,22 @@ RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
balance_(balance_modes_[kSloppy]), balance_(balance_modes_[kSloppy]),
separate_first_(separate_first_modes_[kSloppy]), separate_first_(separate_first_modes_[kSloppy]),
hdr_info_(hdr_info), hdr_info_(hdr_info),
first_partition_in_packet_(0) first_partition_in_packet_(0) {
{
part_info_.VerifyAndAllocateFragmentationHeader(1); part_info_.VerifyAndAllocateFragmentationHeader(1);
part_info_.fragmentationLength[0] = payload_size; part_info_.fragmentationLength[0] = payload_size;
part_info_.fragmentationOffset[0] = 0; part_info_.fragmentationOffset[0] = 0;
} }
int RtpFormatVp8::CalcNextSize(int max_payload_len, int remaining_bytes, int RtpFormatVp8::CalcNextSize(int max_payload_len, int remaining_bytes,
bool split_payload) const bool split_payload) const {
{ if (max_payload_len == 0 || remaining_bytes == 0) {
if (max_payload_len == 0 || remaining_bytes == 0)
{
return 0; return 0;
} }
if (!split_payload) if (!split_payload) {
{
return max_payload_len >= remaining_bytes ? remaining_bytes : 0; return max_payload_len >= remaining_bytes ? remaining_bytes : 0;
} }
if (balance_) if (balance_) {
{
// Balance payload sizes to produce (almost) equal size // Balance payload sizes to produce (almost) equal size
// fragments. // fragments.
// Number of fragments for remaining_bytes: // Number of fragments for remaining_bytes:
@ -88,20 +83,16 @@ int RtpFormatVp8::CalcNextSize(int max_payload_len, int remaining_bytes,
// Number of bytes in this fragment: // Number of bytes in this fragment:
return static_cast<int>(static_cast<double>(remaining_bytes) return static_cast<int>(static_cast<double>(remaining_bytes)
/ num_frags + 0.5); / num_frags + 0.5);
} } else {
else
{
return max_payload_len >= remaining_bytes ? remaining_bytes return max_payload_len >= remaining_bytes ? remaining_bytes
: max_payload_len; : max_payload_len;
} }
} }
int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer, int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
int* bytes_to_send, bool* last_packet) int* bytes_to_send, bool* last_packet) {
{
if (max_payload_len < vp8_fixed_payload_descriptor_bytes_ if (max_payload_len < vp8_fixed_payload_descriptor_bytes_
+ PayloadDescriptorExtraLength() + 1) + PayloadDescriptorExtraLength() + 1) {
{
// The provided payload length is not long enough for the payload // The provided payload length is not long enough for the payload
// descriptor and one payload byte. Return an error. // descriptor and one payload byte. Return an error.
return -1; return -1;
@ -117,14 +108,12 @@ int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
if (first_partition_in_packet_ > 8) return -1; if (first_partition_in_packet_ > 8) return -1;
while (int next_size = CalcNextSize(rem_payload_len, remaining_in_partition, while (int next_size = CalcNextSize(rem_payload_len, remaining_in_partition,
split_payload)) split_payload)) {
{
send_bytes += next_size; send_bytes += next_size;
rem_payload_len -= next_size; rem_payload_len -= next_size;
remaining_in_partition -= next_size; remaining_in_partition -= next_size;
if (remaining_in_partition == 0 && !(beginning_ && separate_first_)) if (remaining_in_partition == 0 && !(beginning_ && separate_first_)) {
{
// Advance to next partition? // Advance to next partition?
// Check that there are more partitions; verify that we are either // Check that there are more partitions; verify that we are either
// allowed to aggregate fragments, or that we are allowed to // allowed to aggregate fragments, or that we are allowed to
@ -132,22 +121,18 @@ int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
// with an intact partition (indicated by first_fragment_ == true). // with an intact partition (indicated by first_fragment_ == true).
if (part_ix_ + 1 < num_partitions && if (part_ix_ + 1 < num_partitions &&
((aggr_mode_ == kAggrFragments) || ((aggr_mode_ == kAggrFragments) ||
(aggr_mode_ == kAggrPartitions && first_fragment_))) (aggr_mode_ == kAggrPartitions && first_fragment_))) {
{
remaining_in_partition remaining_in_partition
= part_info_.fragmentationLength[++part_ix_]; = part_info_.fragmentationLength[++part_ix_];
// Disallow splitting unless kAggrFragments. In kAggrPartitions, // Disallow splitting unless kAggrFragments. In kAggrPartitions,
// we can only aggregate intact partitions. // we can only aggregate intact partitions.
split_payload = (aggr_mode_ == kAggrFragments); split_payload = (aggr_mode_ == kAggrFragments);
} }
} } else if (balance_ && remaining_in_partition > 0) {
else if (balance_ && remaining_in_partition > 0)
{
break; break;
} }
} }
if (remaining_in_partition == 0) if (remaining_in_partition == 0) {
{
++part_ix_; // Advance to next partition. ++part_ix_; // Advance to next partition.
} }
@ -155,8 +140,7 @@ int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
assert(send_bytes > 0); assert(send_bytes > 0);
// Write the payload header and the payload to buffer. // Write the payload header and the payload to buffer.
*bytes_to_send = WriteHeaderAndPayload(send_bytes, buffer, max_payload_len); *bytes_to_send = WriteHeaderAndPayload(send_bytes, buffer, max_payload_len);
if (*bytes_to_send < 0) if (*bytes_to_send < 0) {
{
return -1; return -1;
} }
@ -170,8 +154,7 @@ int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
int RtpFormatVp8::WriteHeaderAndPayload(int payload_bytes, int RtpFormatVp8::WriteHeaderAndPayload(int payload_bytes,
WebRtc_UWord8* buffer, WebRtc_UWord8* buffer,
int buffer_length) int buffer_length) {
{
// Write the VP8 payload descriptor. // Write the VP8 payload descriptor.
// 0 // 0
// 0 1 2 3 4 5 6 7 8 // 0 1 2 3 4 5 6 7 8
@ -210,36 +193,28 @@ int RtpFormatVp8::WriteHeaderAndPayload(int payload_bytes,
+ extension_length; + extension_length;
} }
int RtpFormatVp8::WriteExtensionFields(WebRtc_UWord8* buffer, int buffer_length) int RtpFormatVp8::WriteExtensionFields(WebRtc_UWord8* buffer,
const int buffer_length) const {
{
int extension_length = 0; int extension_length = 0;
if (XFieldPresent()) if (XFieldPresent()) {
{
WebRtc_UWord8* x_field = buffer + vp8_fixed_payload_descriptor_bytes_; WebRtc_UWord8* x_field = buffer + vp8_fixed_payload_descriptor_bytes_;
*x_field = 0; *x_field = 0;
extension_length = 1; // One octet for the X field. extension_length = 1; // One octet for the X field.
if (PictureIdPresent()) if (PictureIdPresent()) {
{
if (WritePictureIDFields(x_field, buffer, buffer_length, if (WritePictureIDFields(x_field, buffer, buffer_length,
&extension_length) < 0) &extension_length) < 0) {
{
return -1; return -1;
} }
} }
if (TL0PicIdxFieldPresent()) if (TL0PicIdxFieldPresent()) {
{
if (WriteTl0PicIdxFields(x_field, buffer, buffer_length, if (WriteTl0PicIdxFields(x_field, buffer, buffer_length,
&extension_length) < 0) &extension_length) < 0) {
{
return -1; return -1;
} }
} }
if (TIDFieldPresent() || KeyIdxFieldPresent()) if (TIDFieldPresent() || KeyIdxFieldPresent()) {
{
if (WriteTIDAndKeyIdxFields(x_field, buffer, buffer_length, if (WriteTIDAndKeyIdxFields(x_field, buffer, buffer_length,
&extension_length) < 0) &extension_length) < 0) {
{
return -1; return -1;
} }
} }
@ -248,12 +223,10 @@ const
return extension_length; return extension_length;
} }
int RtpFormatVp8::WritePictureIDFields(WebRtc_UWord8* x_field, int RtpFormatVp8::WritePictureIDFields(WebRtc_UWord8* x_field,
WebRtc_UWord8* buffer, WebRtc_UWord8* buffer,
int buffer_length, int buffer_length,
int* extension_length) const int* extension_length) const {
{
*x_field |= kIBit; *x_field |= kIBit;
const int pic_id_length = WritePictureID( const int pic_id_length = WritePictureID(
buffer + vp8_fixed_payload_descriptor_bytes_ + *extension_length, buffer + vp8_fixed_payload_descriptor_bytes_ + *extension_length,
@ -264,19 +237,16 @@ int RtpFormatVp8::WritePictureIDFields(WebRtc_UWord8* x_field,
return 0; return 0;
} }
int RtpFormatVp8::WritePictureID(WebRtc_UWord8* buffer, int buffer_length) const int RtpFormatVp8::WritePictureID(WebRtc_UWord8* buffer,
{ int buffer_length) const {
const WebRtc_UWord16 pic_id = const WebRtc_UWord16 pic_id =
static_cast<WebRtc_UWord16> (hdr_info_.pictureId); static_cast<WebRtc_UWord16> (hdr_info_.pictureId);
int picture_id_len = PictureIdLength(); int picture_id_len = PictureIdLength();
if (picture_id_len > buffer_length) return -1; if (picture_id_len > buffer_length) return -1;
if (picture_id_len == 2) if (picture_id_len == 2) {
{
buffer[0] = 0x80 | ((pic_id >> 8) & 0x7F); buffer[0] = 0x80 | ((pic_id >> 8) & 0x7F);
buffer[1] = pic_id & 0xFF; buffer[1] = pic_id & 0xFF;
} } else if (picture_id_len == 1) {
else if (picture_id_len == 1)
{
buffer[0] = pic_id & 0x7F; buffer[0] = pic_id & 0x7F;
} }
return picture_id_len; return picture_id_len;
@ -285,11 +255,9 @@ int RtpFormatVp8::WritePictureID(WebRtc_UWord8* buffer, int buffer_length) const
int RtpFormatVp8::WriteTl0PicIdxFields(WebRtc_UWord8* x_field, int RtpFormatVp8::WriteTl0PicIdxFields(WebRtc_UWord8* x_field,
WebRtc_UWord8* buffer, WebRtc_UWord8* buffer,
int buffer_length, int buffer_length,
int* extension_length) const int* extension_length) const {
{
if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length
+ 1) + 1) {
{
return -1; return -1;
} }
*x_field |= kLBit; *x_field |= kLBit;
@ -302,23 +270,19 @@ int RtpFormatVp8::WriteTl0PicIdxFields(WebRtc_UWord8* x_field,
int RtpFormatVp8::WriteTIDAndKeyIdxFields(WebRtc_UWord8* x_field, int RtpFormatVp8::WriteTIDAndKeyIdxFields(WebRtc_UWord8* x_field,
WebRtc_UWord8* buffer, WebRtc_UWord8* buffer,
int buffer_length, int buffer_length,
int* extension_length) const int* extension_length) const {
{
if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length
+ 1) + 1) {
{
return -1; return -1;
} }
WebRtc_UWord8* data_field = WebRtc_UWord8* data_field =
&buffer[vp8_fixed_payload_descriptor_bytes_ + *extension_length]; &buffer[vp8_fixed_payload_descriptor_bytes_ + *extension_length];
*data_field = 0; *data_field = 0;
if (TIDFieldPresent()) if (TIDFieldPresent()) {
{
*x_field |= kTBit; *x_field |= kTBit;
*data_field |= hdr_info_.temporalIdx << 5; *data_field |= hdr_info_.temporalIdx << 5;
} }
if (KeyIdxFieldPresent()) if (KeyIdxFieldPresent()) {
{
*x_field |= kKBit; *x_field |= kKBit;
*data_field |= (hdr_info_.keyIdx & kKeyIdxField); *data_field |= (hdr_info_.keyIdx & kKeyIdxField);
} }
@ -326,8 +290,7 @@ int RtpFormatVp8::WriteTIDAndKeyIdxFields(WebRtc_UWord8* x_field,
return 0; return 0;
} }
int RtpFormatVp8::PayloadDescriptorExtraLength() const int RtpFormatVp8::PayloadDescriptorExtraLength() const {
{
int length_bytes = PictureIdLength(); int length_bytes = PictureIdLength();
if (TL0PicIdxFieldPresent()) ++length_bytes; if (TL0PicIdxFieldPresent()) ++length_bytes;
if (TIDFieldPresent() || KeyIdxFieldPresent()) ++length_bytes; if (TIDFieldPresent() || KeyIdxFieldPresent()) ++length_bytes;
@ -335,37 +298,30 @@ int RtpFormatVp8::PayloadDescriptorExtraLength() const
return length_bytes; return length_bytes;
} }
int RtpFormatVp8::PictureIdLength() const int RtpFormatVp8::PictureIdLength() const {
{ if (hdr_info_.pictureId == kNoPictureId) {
if (hdr_info_.pictureId == kNoPictureId)
{
return 0; return 0;
} }
if (hdr_info_.pictureId <= 0x7F) if (hdr_info_.pictureId <= 0x7F) {
{
return 1; return 1;
} }
return 2; return 2;
} }
bool RtpFormatVp8::XFieldPresent() const bool RtpFormatVp8::XFieldPresent() const {
{
return (TIDFieldPresent() || TL0PicIdxFieldPresent() || PictureIdPresent() return (TIDFieldPresent() || TL0PicIdxFieldPresent() || PictureIdPresent()
|| KeyIdxFieldPresent()); || KeyIdxFieldPresent());
} }
bool RtpFormatVp8::TIDFieldPresent() const bool RtpFormatVp8::TIDFieldPresent() const {
{
return (hdr_info_.temporalIdx != kNoTemporalIdx); return (hdr_info_.temporalIdx != kNoTemporalIdx);
} }
bool RtpFormatVp8::KeyIdxFieldPresent() const bool RtpFormatVp8::KeyIdxFieldPresent() const {
{
return (hdr_info_.keyIdx != kNoKeyIdx); return (hdr_info_.keyIdx != kNoKeyIdx);
} }
bool RtpFormatVp8::TL0PicIdxFieldPresent() const bool RtpFormatVp8::TL0PicIdxFieldPresent() const {
{
return (hdr_info_.tl0PicIdx != kNoTl0PicIdx); return (hdr_info_.tl0PicIdx != kNoTl0PicIdx);
} }
} // namespace webrtc } // namespace webrtc

@ -22,26 +22,24 @@
* false as long as there are more packets left to fetch. * false as long as there are more packets left to fetch.
*/ */
#ifndef WEBRTC_MODULES_RTP_RTCP_RTP_FORMAT_VP8_H_ #ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
#define WEBRTC_MODULES_RTP_RTCP_RTP_FORMAT_VP8_H_ #define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
#include "module_common_types.h" #include "modules/interface/module_common_types.h"
#include "typedefs.h" #include "typedefs.h" // NOLINT(build/include)
namespace webrtc namespace webrtc {
{
enum VP8PacketizerMode enum VP8PacketizerMode {
{ kStrict = 0, // Split partitions if too large;
kStrict = 0, // split partitions if too large; never aggregate, balance size // never aggregate, balance size.
kAggregate, // split partitions if too large; aggregate whole partitions kAggregate, // Split partitions if too large; aggregate whole partitions.
kSloppy, // split entire payload without considering partition limits kSloppy, // Split entire payload without considering partition limits.
kNumModes, kNumModes,
}; };
// Packetizer for VP8. // Packetizer for VP8.
class RtpFormatVp8 class RtpFormatVp8 {
{
public: public:
// Initialize with payload from encoder and fragmentation info. // Initialize with payload from encoder and fragmentation info.
// The payload_data must be exactly one encoded VP8 frame. // The payload_data must be exactly one encoded VP8 frame.
@ -70,11 +68,10 @@ public:
int* bytes_to_send, bool* last_packet); int* bytes_to_send, bool* last_packet);
private: private:
enum AggregationMode enum AggregationMode {
{ kAggrNone = 0, // No aggregation.
kAggrNone = 0, // no aggregation kAggrPartitions, // Aggregate intact partitions.
kAggrPartitions, // aggregate intact partitions kAggrFragments // Aggregate intact and fragmented partitions.
kAggrFragments // aggregate intact and fragmented partitions
}; };
static const AggregationMode aggr_modes_[kNumModes]; static const AggregationMode aggr_modes_[kNumModes];
@ -148,10 +145,10 @@ private:
RTPFragmentationHeader part_info_; RTPFragmentationHeader part_info_;
int payload_bytes_sent_; int payload_bytes_sent_;
int part_ix_; int part_ix_;
bool beginning_; // first partition in this frame bool beginning_; // First partition in this frame.
bool first_fragment_; // first fragment of a partition bool first_fragment_; // First fragment of a partition.
const int vp8_fixed_payload_descriptor_bytes_; // length of VP8 payload const int vp8_fixed_payload_descriptor_bytes_; // Length of VP8 payload
// descriptors's fixed part // descriptors's fixed part.
AggregationMode aggr_mode_; AggregationMode aggr_mode_;
bool balance_; bool balance_;
bool separate_first_; bool separate_first_;
@ -159,6 +156,6 @@ private:
int first_partition_in_packet_; int first_partition_in_packet_;
}; };
} } // namespace
#endif /* WEBRTC_MODULES_RTP_RTCP_RTP_FORMAT_VP8_H_ */ #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_

@ -15,8 +15,8 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "typedefs.h" #include "modules/rtp_rtcp/source/rtp_format_vp8.h"
#include "rtp_format_vp8.h" #include "typedefs.h" // NOLINT(build/include)
namespace webrtc { namespace webrtc {
@ -25,7 +25,7 @@ const int kBufferSize = kPayloadSize + 6; // Add space for payload descriptor.
class RtpFormatVp8Test : public ::testing::Test { class RtpFormatVp8Test : public ::testing::Test {
protected: protected:
RtpFormatVp8Test() {}; RtpFormatVp8Test() {}
virtual void SetUp(); virtual void SetUp();
virtual void TearDown(); virtual void TearDown();
void CheckHeader(bool first_in_frame, bool frag_start, int part_id); void CheckHeader(bool first_in_frame, bool frag_start, int part_id);
@ -47,9 +47,8 @@ class RtpFormatVp8Test : public ::testing::Test {
}; };
void RtpFormatVp8Test::SetUp() { void RtpFormatVp8Test::SetUp() {
for (int i = 0; i < kPayloadSize; i++) for (int i = 0; i < kPayloadSize; i++) {
{ payload_data_[i] = i / 10; // Integer division.
payload_data_[i] = i / 10; // integer division
} }
data_ptr_ = payload_data_; data_ptr_ = payload_data_;
@ -73,8 +72,8 @@ void RtpFormatVp8Test::TearDown() {
delete fragmentation_; delete fragmentation_;
} }
// First octet tests // First octet tests.
#define EXPECT_BIT_EQ(x,n,a) EXPECT_EQ((((x)>>n)&0x1), a) #define EXPECT_BIT_EQ(x, n, a) EXPECT_EQ((((x) >> (n)) & 0x1), a)
#define EXPECT_RSV_ZERO(x) EXPECT_EQ(((x) & 0xE0), 0) #define EXPECT_RSV_ZERO(x) EXPECT_EQ(((x) & 0xE0), 0)
@ -100,25 +99,21 @@ void RtpFormatVp8Test::TearDown() {
#define EXPECT_KEYIDX_EQ(x, a) EXPECT_EQ(((x) & 0x1F), a) #define EXPECT_KEYIDX_EQ(x, a) EXPECT_EQ(((x) & 0x1F), a)
void RtpFormatVp8Test::CheckHeader(bool first_in_frame, bool frag_start, void RtpFormatVp8Test::CheckHeader(bool first_in_frame, bool frag_start,
int part_id) int part_id) {
{
payload_start_ = 1; payload_start_ = 1;
EXPECT_BIT_EQ(buffer_[0], 6, 0); // check reserved bit EXPECT_BIT_EQ(buffer_[0], 6, 0); // Check reserved bit.
if (hdr_info_.pictureId != kNoPictureId || if (hdr_info_.pictureId != kNoPictureId ||
hdr_info_.temporalIdx != kNoTemporalIdx || hdr_info_.temporalIdx != kNoTemporalIdx ||
hdr_info_.tl0PicIdx != kNoTl0PicIdx || hdr_info_.tl0PicIdx != kNoTl0PicIdx ||
hdr_info_.keyIdx != kNoKeyIdx) hdr_info_.keyIdx != kNoKeyIdx) {
{
EXPECT_BIT_X_EQ(buffer_[0], 1); EXPECT_BIT_X_EQ(buffer_[0], 1);
++payload_start_; ++payload_start_;
CheckPictureID(); CheckPictureID();
CheckTl0PicIdx(); CheckTl0PicIdx();
CheckTIDAndKeyIdx(); CheckTIDAndKeyIdx();
} } else {
else
{
EXPECT_BIT_X_EQ(buffer_[0], 0); EXPECT_BIT_X_EQ(buffer_[0], 0);
} }
@ -126,105 +121,80 @@ void RtpFormatVp8Test::CheckHeader(bool first_in_frame, bool frag_start,
EXPECT_BIT_S_EQ(buffer_[0], frag_start); EXPECT_BIT_S_EQ(buffer_[0], frag_start);
// Check partition index. // Check partition index.
if (part_id < 0) if (part_id < 0) {
{
// (Payload data is the same as the partition index.) // (Payload data is the same as the partition index.)
EXPECT_EQ(buffer_[0] & 0x0F, buffer_[payload_start_]); EXPECT_EQ(buffer_[0] & 0x0F, buffer_[payload_start_]);
} } else {
else
{
EXPECT_EQ(buffer_[0] & 0x0F, part_id); EXPECT_EQ(buffer_[0] & 0x0F, part_id);
} }
} }
void RtpFormatVp8Test::CheckPictureID() void RtpFormatVp8Test::CheckPictureID() {
{ if (hdr_info_.pictureId != kNoPictureId) {
if (hdr_info_.pictureId != kNoPictureId)
{
EXPECT_BIT_I_EQ(buffer_[1], 1); EXPECT_BIT_I_EQ(buffer_[1], 1);
if (hdr_info_.pictureId > 0x7F) if (hdr_info_.pictureId > 0x7F) {
{
EXPECT_BIT_EQ(buffer_[payload_start_], 7, 1); EXPECT_BIT_EQ(buffer_[payload_start_], 7, 1);
EXPECT_EQ(buffer_[payload_start_] & 0x7F, EXPECT_EQ(buffer_[payload_start_] & 0x7F,
(hdr_info_.pictureId >> 8) & 0x7F); (hdr_info_.pictureId >> 8) & 0x7F);
EXPECT_EQ(buffer_[payload_start_ + 1], EXPECT_EQ(buffer_[payload_start_ + 1],
hdr_info_.pictureId & 0xFF); hdr_info_.pictureId & 0xFF);
payload_start_ += 2; payload_start_ += 2;
} } else {
else
{
EXPECT_BIT_EQ(buffer_[payload_start_], 7, 0); EXPECT_BIT_EQ(buffer_[payload_start_], 7, 0);
EXPECT_EQ(buffer_[payload_start_] & 0x7F, EXPECT_EQ(buffer_[payload_start_] & 0x7F,
(hdr_info_.pictureId) & 0x7F); (hdr_info_.pictureId) & 0x7F);
payload_start_ += 1; payload_start_ += 1;
} }
} } else {
else
{
EXPECT_BIT_I_EQ(buffer_[1], 0); EXPECT_BIT_I_EQ(buffer_[1], 0);
} }
} }
void RtpFormatVp8Test::CheckTl0PicIdx() void RtpFormatVp8Test::CheckTl0PicIdx() {
{ if (hdr_info_.tl0PicIdx != kNoTl0PicIdx) {
if (hdr_info_.tl0PicIdx != kNoTl0PicIdx)
{
EXPECT_BIT_L_EQ(buffer_[1], 1); EXPECT_BIT_L_EQ(buffer_[1], 1);
EXPECT_EQ(buffer_[payload_start_], hdr_info_.tl0PicIdx); EXPECT_EQ(buffer_[payload_start_], hdr_info_.tl0PicIdx);
++payload_start_; ++payload_start_;
} } else {
else
{
EXPECT_BIT_L_EQ(buffer_[1], 0); EXPECT_BIT_L_EQ(buffer_[1], 0);
} }
} }
void RtpFormatVp8Test::CheckTIDAndKeyIdx() void RtpFormatVp8Test::CheckTIDAndKeyIdx() {
{
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_BIT_T_EQ(buffer_[1], 0);
EXPECT_BIT_K_EQ(buffer_[1], 0); EXPECT_BIT_K_EQ(buffer_[1], 0);
return; return;
} }
if (hdr_info_.temporalIdx != kNoTemporalIdx) if (hdr_info_.temporalIdx != kNoTemporalIdx) {
{
EXPECT_BIT_T_EQ(buffer_[1], 1); EXPECT_BIT_T_EQ(buffer_[1], 1);
EXPECT_TID_EQ(buffer_[payload_start_], hdr_info_.temporalIdx); EXPECT_TID_EQ(buffer_[payload_start_], hdr_info_.temporalIdx);
} } else {
else
{
EXPECT_BIT_T_EQ(buffer_[1], 0); EXPECT_BIT_T_EQ(buffer_[1], 0);
EXPECT_TID_EQ(buffer_[payload_start_], 0); EXPECT_TID_EQ(buffer_[payload_start_], 0);
} }
if (hdr_info_.keyIdx != kNoKeyIdx) if (hdr_info_.keyIdx != kNoKeyIdx) {
{
EXPECT_BIT_K_EQ(buffer_[1], 1); EXPECT_BIT_K_EQ(buffer_[1], 1);
EXPECT_KEYIDX_EQ(buffer_[payload_start_], hdr_info_.keyIdx); EXPECT_KEYIDX_EQ(buffer_[payload_start_], hdr_info_.keyIdx);
} } else {
else
{
EXPECT_BIT_K_EQ(buffer_[1], 0); EXPECT_BIT_K_EQ(buffer_[1], 0);
EXPECT_KEYIDX_EQ(buffer_[payload_start_], 0); EXPECT_KEYIDX_EQ(buffer_[payload_start_], 0);
} }
++payload_start_; ++payload_start_;
} }
void RtpFormatVp8Test::CheckPayload(int payload_end) void RtpFormatVp8Test::CheckPayload(int payload_end) {
{
for (int i = payload_start_; i < payload_end; i++, data_ptr_++) for (int i = payload_start_; i < payload_end; i++, data_ptr_++)
EXPECT_EQ(buffer_[i], *data_ptr_); EXPECT_EQ(buffer_[i], *data_ptr_);
} }
void RtpFormatVp8Test::CheckLast(bool last) const void RtpFormatVp8Test::CheckLast(bool last) const {
{
EXPECT_EQ(last, data_ptr_ == payload_data_ + kPayloadSize); EXPECT_EQ(last, data_ptr_ == payload_data_ + kPayloadSize);
} }
void RtpFormatVp8Test::CheckPacket(int send_bytes, int expect_bytes, bool last, void RtpFormatVp8Test::CheckPacket(int send_bytes, int expect_bytes, bool last,
bool first_in_frame, bool frag_start) bool first_in_frame, bool frag_start) {
{
EXPECT_EQ(send_bytes, expect_bytes); EXPECT_EQ(send_bytes, expect_bytes);
CheckHeader(first_in_frame, frag_start, -1); CheckHeader(first_in_frame, frag_start, -1);
CheckPayload(send_bytes); CheckPayload(send_bytes);
@ -235,155 +205,148 @@ void RtpFormatVp8Test::CheckPacketZeroPartId(int send_bytes,
int expect_bytes, int expect_bytes,
bool last, bool last,
bool first_in_frame, bool first_in_frame,
bool frag_start) bool frag_start) {
{
EXPECT_EQ(send_bytes, expect_bytes); EXPECT_EQ(send_bytes, expect_bytes);
CheckHeader(first_in_frame, frag_start, 0); CheckHeader(first_in_frame, frag_start, 0);
CheckPayload(send_bytes); CheckPayload(send_bytes);
CheckLast(last); CheckLast(last);
} }
TEST_F(RtpFormatVp8Test, TestStrictMode) TEST_F(RtpFormatVp8Test, TestStrictMode) {
{
int send_bytes = 0; int send_bytes = 0;
bool last; bool last;
bool first_in_frame = true; bool first_in_frame = true;
hdr_info_.pictureId = 200; // > 0x7F should produce 2-byte PictureID hdr_info_.pictureId = 200; // > 0x7F should produce 2-byte PictureID.
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize, RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kStrict); hdr_info_, *fragmentation_, kStrict);
// get first packet, expect balanced size ~= same as second packet // Get first packet, expect balanced size ~= same as second packet.
EXPECT_EQ(0, packetizer.NextPacket(13, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(13, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 8, last, CheckPacket(send_bytes, 8, last,
first_in_frame, first_in_frame,
/* frag_start */ true); /* frag_start */ true);
first_in_frame = false; first_in_frame = false;
// get second packet // Get second packet.
EXPECT_EQ(0, packetizer.NextPacket(13, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(13, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 10, last, CheckPacket(send_bytes, 10, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// Second partition // Second partition.
// Get first (and only) packet // Get first (and only) packet.
EXPECT_EQ(1, packetizer.NextPacket(20, buffer_, &send_bytes, &last)); EXPECT_EQ(1, packetizer.NextPacket(20, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 14, last, CheckPacket(send_bytes, 14, last,
first_in_frame, first_in_frame,
/* frag_start */ true); /* frag_start */ true);
// Third partition // Third partition.
// Get first packet (of four) // Get first packet (of four).
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last)); EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 5, last, CheckPacket(send_bytes, 5, last,
first_in_frame, first_in_frame,
/* frag_start */ true); /* frag_start */ true);
// Get second packet (of four) // Get second packet (of four).
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last)); EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 5, last, CheckPacket(send_bytes, 5, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// Get third packet (of four) // Get third packet (of four).
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last)); EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 7, last, CheckPacket(send_bytes, 7, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// Get fourth and last packet // Get fourth and last packet.
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last)); EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 5, last, CheckPacket(send_bytes, 5, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
} }
TEST_F(RtpFormatVp8Test, TestAggregateMode) TEST_F(RtpFormatVp8Test, TestAggregateMode) {
{
int send_bytes = 0; int send_bytes = 0;
bool last; bool last;
bool first_in_frame = true; bool first_in_frame = true;
hdr_info_.pictureId = 20; // <= 0x7F should produce 1-byte PictureID hdr_info_.pictureId = 20; // <= 0x7F should produce 1-byte PictureID.
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize, RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kAggregate); hdr_info_, *fragmentation_,
kAggregate);
// get first packet // Get first packet.
// first part of first partition (balanced fragments are expected) // First part of first partition (balanced fragments are expected).
EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 7, last, CheckPacket(send_bytes, 7, last,
first_in_frame, first_in_frame,
/* frag_start */ true); /* frag_start */ true);
first_in_frame = false; first_in_frame = false;
// get second packet // Get second packet.
// second fragment of first partition // Second fragment of first partition.
EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 5, last, CheckPacket(send_bytes, 5, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// get third packet // Get third packet.
// third fragment of first partition // Third fragment of first partition.
EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 7, last, CheckPacket(send_bytes, 7, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// get fourth packet // Get fourth packet.
// last two partitions aggregated // Last two partitions aggregated.
EXPECT_EQ(1, packetizer.NextPacket(25, buffer_, &send_bytes, &last)); EXPECT_EQ(1, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 23, last, CheckPacket(send_bytes, 23, last,
first_in_frame, first_in_frame,
/* frag_start */ true); /* frag_start */ true);
} }
TEST_F(RtpFormatVp8Test, TestSloppyMode) TEST_F(RtpFormatVp8Test, TestSloppyMode) {
{
int send_bytes = 0; int send_bytes = 0;
bool last; bool last;
bool first_in_frame = true; bool first_in_frame = true;
hdr_info_.pictureId = kNoPictureId; // no PictureID hdr_info_.pictureId = kNoPictureId; // No PictureID.
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize, RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kSloppy); hdr_info_, *fragmentation_, kSloppy);
// get first packet // Get first packet.
EXPECT_EQ(0, packetizer.NextPacket(9, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 9, last, CheckPacket(send_bytes, 9, last,
first_in_frame, first_in_frame,
/* frag_start */ true); /* frag_start */ true);
first_in_frame = false; first_in_frame = false;
// get second packet // Get second packet.
// fragments of first and second partitions // Fragments of first and second partitions.
EXPECT_EQ(0, packetizer.NextPacket(9, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 9, last, CheckPacket(send_bytes, 9, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// get third packet // Get third packet.
// fragments of second and third partitions // Fragments of second and third partitions.
EXPECT_EQ(1, packetizer.NextPacket(9, buffer_, &send_bytes, &last)); EXPECT_EQ(1, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 9, last, CheckPacket(send_bytes, 9, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// get fourth packet // Get fourth packet.
// second half of last partition // Second half of last partition.
EXPECT_EQ(2, packetizer.NextPacket(9, buffer_, &send_bytes, &last)); EXPECT_EQ(2, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 7, last, CheckPacket(send_bytes, 7, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
} }
// Verify that sloppy mode is forced if fragmentation info is missing. // Verify that sloppy mode is forced if fragmentation info is missing.
TEST_F(RtpFormatVp8Test, TestSloppyModeFallback) TEST_F(RtpFormatVp8Test, TestSloppyModeFallback) {
{
int send_bytes = 0; int send_bytes = 0;
bool last; bool last;
bool first_in_frame = true; bool first_in_frame = true;
@ -392,34 +355,33 @@ TEST_F(RtpFormatVp8Test, TestSloppyModeFallback)
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize, RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_); hdr_info_);
// get first packet // Get first packet.
EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last));
CheckPacketZeroPartId(send_bytes, 10, last, CheckPacketZeroPartId(send_bytes, 10, last,
first_in_frame, first_in_frame,
/* frag_start */ true); /* frag_start */ true);
first_in_frame = false; first_in_frame = false;
// get second packet // Get second packet.
// fragments of first and second partitions // Fragments of first and second partitions.
EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last));
CheckPacketZeroPartId(send_bytes, 10, last, CheckPacketZeroPartId(send_bytes, 10, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// get third packet // Get third packet.
// fragments of second and third partitions // Fragments of second and third partitions.
EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last));
CheckPacketZeroPartId(send_bytes, 10, last, CheckPacketZeroPartId(send_bytes, 10, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
// get fourth packet // Get fourth packet.
// second half of last partition // Second half of last partition.
EXPECT_EQ(0, packetizer.NextPacket(7, buffer_, &send_bytes, &last)); EXPECT_EQ(0, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
CheckPacketZeroPartId(send_bytes, 7, last, CheckPacketZeroPartId(send_bytes, 7, last,
first_in_frame, first_in_frame,
/* frag_start */ false); /* frag_start */ false);
} }
// Verify that non-reference bit is set. // Verify that non-reference bit is set.
@ -431,12 +393,12 @@ TEST_F(RtpFormatVp8Test, TestNonReferenceBit) {
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize, RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_); hdr_info_);
// get first packet // Get first packet.
ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last)); ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
ASSERT_FALSE(last); ASSERT_FALSE(last);
EXPECT_BIT_N_EQ(buffer_[0], 1); EXPECT_BIT_N_EQ(buffer_[0], 1);
// get second packet // Get second packet.
ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last)); ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
ASSERT_TRUE(last); ASSERT_TRUE(last);
EXPECT_BIT_N_EQ(buffer_[0], 1); EXPECT_BIT_N_EQ(buffer_[0], 1);
@ -450,9 +412,10 @@ TEST_F(RtpFormatVp8Test, TestTl0PicIdxAndTID) {
hdr_info_.tl0PicIdx = 117; hdr_info_.tl0PicIdx = 117;
hdr_info_.temporalIdx = 2; hdr_info_.temporalIdx = 2;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize, RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kAggregate); hdr_info_, *fragmentation_,
kAggregate);
// get first and only packet // Get first and only packet.
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes, EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last)); &last));
bool first_in_frame = true; bool first_in_frame = true;
@ -461,16 +424,17 @@ TEST_F(RtpFormatVp8Test, TestTl0PicIdxAndTID) {
/* frag_start */ true); /* frag_start */ true);
} }
// Verify KeyIdx field // Verify KeyIdx field.
TEST_F(RtpFormatVp8Test, TestKeyIdx) { TEST_F(RtpFormatVp8Test, TestKeyIdx) {
int send_bytes = 0; int send_bytes = 0;
bool last; bool last;
hdr_info_.keyIdx = 17; hdr_info_.keyIdx = 17;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize, RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kAggregate); hdr_info_, *fragmentation_,
kAggregate);
// get first and only packet // Get first and only packet.
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes, EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last)); &last));
bool first_in_frame = true; bool first_in_frame = true;
@ -479,7 +443,7 @@ TEST_F(RtpFormatVp8Test, TestKeyIdx) {
/* frag_start */ true); /* frag_start */ true);
} }
// Verify TID field and KeyIdx field in combination // Verify TID field and KeyIdx field in combination.
TEST_F(RtpFormatVp8Test, TestTIDAndKeyIdx) { TEST_F(RtpFormatVp8Test, TestTIDAndKeyIdx) {
int send_bytes = 0; int send_bytes = 0;
bool last; bool last;
@ -487,9 +451,10 @@ TEST_F(RtpFormatVp8Test, TestTIDAndKeyIdx) {
hdr_info_.temporalIdx = 1; hdr_info_.temporalIdx = 1;
hdr_info_.keyIdx = 5; hdr_info_.keyIdx = 5;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize, RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kAggregate); hdr_info_, *fragmentation_,
kAggregate);
// get first and only packet // Get first and only packet.
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes, EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last)); &last));
bool first_in_frame = true; bool first_in_frame = true;