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:
parent
c7e2bffb66
commit
b6e58eb5a1
@ -8,10 +8,11 @@
|
||||
* 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 <string.h> // memcpy
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -40,8 +41,7 @@ RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
|
||||
balance_(balance_modes_[mode]),
|
||||
separate_first_(separate_first_modes_[mode]),
|
||||
hdr_info_(hdr_info),
|
||||
first_partition_in_packet_(0)
|
||||
{
|
||||
first_partition_in_packet_(0) {
|
||||
part_info_ = fragmentation;
|
||||
}
|
||||
|
||||
@ -60,27 +60,22 @@ RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
|
||||
balance_(balance_modes_[kSloppy]),
|
||||
separate_first_(separate_first_modes_[kSloppy]),
|
||||
hdr_info_(hdr_info),
|
||||
first_partition_in_packet_(0)
|
||||
{
|
||||
first_partition_in_packet_(0) {
|
||||
part_info_.VerifyAndAllocateFragmentationHeader(1);
|
||||
part_info_.fragmentationLength[0] = payload_size;
|
||||
part_info_.fragmentationOffset[0] = 0;
|
||||
}
|
||||
|
||||
int RtpFormatVp8::CalcNextSize(int max_payload_len, int remaining_bytes,
|
||||
bool split_payload) const
|
||||
{
|
||||
if (max_payload_len == 0 || remaining_bytes == 0)
|
||||
{
|
||||
bool split_payload) const {
|
||||
if (max_payload_len == 0 || remaining_bytes == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (!split_payload)
|
||||
{
|
||||
if (!split_payload) {
|
||||
return max_payload_len >= remaining_bytes ? remaining_bytes : 0;
|
||||
}
|
||||
|
||||
if (balance_)
|
||||
{
|
||||
if (balance_) {
|
||||
// Balance payload sizes to produce (almost) equal size
|
||||
// fragments.
|
||||
// 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:
|
||||
return static_cast<int>(static_cast<double>(remaining_bytes)
|
||||
/ num_frags + 0.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return max_payload_len >= remaining_bytes ? remaining_bytes
|
||||
: max_payload_len;
|
||||
}
|
||||
}
|
||||
|
||||
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_
|
||||
+ PayloadDescriptorExtraLength() + 1)
|
||||
{
|
||||
+ PayloadDescriptorExtraLength() + 1) {
|
||||
// The provided payload length is not long enough for the payload
|
||||
// descriptor and one payload byte. Return an error.
|
||||
return -1;
|
||||
@ -117,14 +108,12 @@ int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
|
||||
if (first_partition_in_packet_ > 8) return -1;
|
||||
|
||||
while (int next_size = CalcNextSize(rem_payload_len, remaining_in_partition,
|
||||
split_payload))
|
||||
{
|
||||
split_payload)) {
|
||||
send_bytes += next_size;
|
||||
rem_payload_len -= 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?
|
||||
// Check that there are more partitions; verify that we are either
|
||||
// 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).
|
||||
if (part_ix_ + 1 < num_partitions &&
|
||||
((aggr_mode_ == kAggrFragments) ||
|
||||
(aggr_mode_ == kAggrPartitions && first_fragment_)))
|
||||
{
|
||||
(aggr_mode_ == kAggrPartitions && first_fragment_))) {
|
||||
remaining_in_partition
|
||||
= part_info_.fragmentationLength[++part_ix_];
|
||||
// Disallow splitting unless kAggrFragments. In kAggrPartitions,
|
||||
// we can only aggregate intact partitions.
|
||||
split_payload = (aggr_mode_ == kAggrFragments);
|
||||
}
|
||||
}
|
||||
else if (balance_ && remaining_in_partition > 0)
|
||||
{
|
||||
} else if (balance_ && remaining_in_partition > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (remaining_in_partition == 0)
|
||||
{
|
||||
if (remaining_in_partition == 0) {
|
||||
++part_ix_; // Advance to next partition.
|
||||
}
|
||||
|
||||
@ -155,8 +140,7 @@ int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
|
||||
assert(send_bytes > 0);
|
||||
// Write the payload header and the payload to buffer.
|
||||
*bytes_to_send = WriteHeaderAndPayload(send_bytes, buffer, max_payload_len);
|
||||
if (*bytes_to_send < 0)
|
||||
{
|
||||
if (*bytes_to_send < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -170,8 +154,7 @@ int RtpFormatVp8::NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
|
||||
|
||||
int RtpFormatVp8::WriteHeaderAndPayload(int payload_bytes,
|
||||
WebRtc_UWord8* buffer,
|
||||
int buffer_length)
|
||||
{
|
||||
int buffer_length) {
|
||||
// Write the VP8 payload descriptor.
|
||||
// 0
|
||||
// 0 1 2 3 4 5 6 7 8
|
||||
@ -210,36 +193,28 @@ int RtpFormatVp8::WriteHeaderAndPayload(int payload_bytes,
|
||||
+ extension_length;
|
||||
}
|
||||
|
||||
int RtpFormatVp8::WriteExtensionFields(WebRtc_UWord8* buffer, int buffer_length)
|
||||
const
|
||||
{
|
||||
int RtpFormatVp8::WriteExtensionFields(WebRtc_UWord8* buffer,
|
||||
int buffer_length) const {
|
||||
int extension_length = 0;
|
||||
if (XFieldPresent())
|
||||
{
|
||||
if (XFieldPresent()) {
|
||||
WebRtc_UWord8* x_field = buffer + vp8_fixed_payload_descriptor_bytes_;
|
||||
*x_field = 0;
|
||||
extension_length = 1; // One octet for the X field.
|
||||
if (PictureIdPresent())
|
||||
{
|
||||
if (PictureIdPresent()) {
|
||||
if (WritePictureIDFields(x_field, buffer, buffer_length,
|
||||
&extension_length) < 0)
|
||||
{
|
||||
&extension_length) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (TL0PicIdxFieldPresent())
|
||||
{
|
||||
if (TL0PicIdxFieldPresent()) {
|
||||
if (WriteTl0PicIdxFields(x_field, buffer, buffer_length,
|
||||
&extension_length) < 0)
|
||||
{
|
||||
&extension_length) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (TIDFieldPresent() || KeyIdxFieldPresent())
|
||||
{
|
||||
if (TIDFieldPresent() || KeyIdxFieldPresent()) {
|
||||
if (WriteTIDAndKeyIdxFields(x_field, buffer, buffer_length,
|
||||
&extension_length) < 0)
|
||||
{
|
||||
&extension_length) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -248,12 +223,10 @@ const
|
||||
return extension_length;
|
||||
}
|
||||
|
||||
|
||||
int RtpFormatVp8::WritePictureIDFields(WebRtc_UWord8* x_field,
|
||||
WebRtc_UWord8* buffer,
|
||||
int buffer_length,
|
||||
int* extension_length) const
|
||||
{
|
||||
int* extension_length) const {
|
||||
*x_field |= kIBit;
|
||||
const int pic_id_length = WritePictureID(
|
||||
buffer + vp8_fixed_payload_descriptor_bytes_ + *extension_length,
|
||||
@ -264,19 +237,16 @@ int RtpFormatVp8::WritePictureIDFields(WebRtc_UWord8* x_field,
|
||||
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 =
|
||||
static_cast<WebRtc_UWord16> (hdr_info_.pictureId);
|
||||
int picture_id_len = PictureIdLength();
|
||||
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[1] = pic_id & 0xFF;
|
||||
}
|
||||
else if (picture_id_len == 1)
|
||||
{
|
||||
} else if (picture_id_len == 1) {
|
||||
buffer[0] = pic_id & 0x7F;
|
||||
}
|
||||
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,
|
||||
WebRtc_UWord8* buffer,
|
||||
int buffer_length,
|
||||
int* extension_length) const
|
||||
{
|
||||
int* extension_length) const {
|
||||
if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length
|
||||
+ 1)
|
||||
{
|
||||
+ 1) {
|
||||
return -1;
|
||||
}
|
||||
*x_field |= kLBit;
|
||||
@ -302,23 +270,19 @@ int RtpFormatVp8::WriteTl0PicIdxFields(WebRtc_UWord8* x_field,
|
||||
int RtpFormatVp8::WriteTIDAndKeyIdxFields(WebRtc_UWord8* x_field,
|
||||
WebRtc_UWord8* buffer,
|
||||
int buffer_length,
|
||||
int* extension_length) const
|
||||
{
|
||||
int* extension_length) const {
|
||||
if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length
|
||||
+ 1)
|
||||
{
|
||||
+ 1) {
|
||||
return -1;
|
||||
}
|
||||
WebRtc_UWord8* data_field =
|
||||
&buffer[vp8_fixed_payload_descriptor_bytes_ + *extension_length];
|
||||
*data_field = 0;
|
||||
if (TIDFieldPresent())
|
||||
{
|
||||
if (TIDFieldPresent()) {
|
||||
*x_field |= kTBit;
|
||||
*data_field |= hdr_info_.temporalIdx << 5;
|
||||
}
|
||||
if (KeyIdxFieldPresent())
|
||||
{
|
||||
if (KeyIdxFieldPresent()) {
|
||||
*x_field |= kKBit;
|
||||
*data_field |= (hdr_info_.keyIdx & kKeyIdxField);
|
||||
}
|
||||
@ -326,8 +290,7 @@ int RtpFormatVp8::WriteTIDAndKeyIdxFields(WebRtc_UWord8* x_field,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RtpFormatVp8::PayloadDescriptorExtraLength() const
|
||||
{
|
||||
int RtpFormatVp8::PayloadDescriptorExtraLength() const {
|
||||
int length_bytes = PictureIdLength();
|
||||
if (TL0PicIdxFieldPresent()) ++length_bytes;
|
||||
if (TIDFieldPresent() || KeyIdxFieldPresent()) ++length_bytes;
|
||||
@ -335,37 +298,30 @@ int RtpFormatVp8::PayloadDescriptorExtraLength() const
|
||||
return length_bytes;
|
||||
}
|
||||
|
||||
int RtpFormatVp8::PictureIdLength() const
|
||||
{
|
||||
if (hdr_info_.pictureId == kNoPictureId)
|
||||
{
|
||||
int RtpFormatVp8::PictureIdLength() const {
|
||||
if (hdr_info_.pictureId == kNoPictureId) {
|
||||
return 0;
|
||||
}
|
||||
if (hdr_info_.pictureId <= 0x7F)
|
||||
{
|
||||
if (hdr_info_.pictureId <= 0x7F) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool RtpFormatVp8::XFieldPresent() const
|
||||
{
|
||||
bool RtpFormatVp8::XFieldPresent() const {
|
||||
return (TIDFieldPresent() || TL0PicIdxFieldPresent() || PictureIdPresent()
|
||||
|| KeyIdxFieldPresent());
|
||||
}
|
||||
|
||||
bool RtpFormatVp8::TIDFieldPresent() const
|
||||
{
|
||||
bool RtpFormatVp8::TIDFieldPresent() const {
|
||||
return (hdr_info_.temporalIdx != kNoTemporalIdx);
|
||||
}
|
||||
|
||||
bool RtpFormatVp8::KeyIdxFieldPresent() const
|
||||
{
|
||||
bool RtpFormatVp8::KeyIdxFieldPresent() const {
|
||||
return (hdr_info_.keyIdx != kNoKeyIdx);
|
||||
}
|
||||
|
||||
bool RtpFormatVp8::TL0PicIdxFieldPresent() const
|
||||
{
|
||||
bool RtpFormatVp8::TL0PicIdxFieldPresent() const {
|
||||
return (hdr_info_.tl0PicIdx != kNoTl0PicIdx);
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
@ -22,27 +22,25 @@
|
||||
* false as long as there are more packets left to fetch.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_MODULES_RTP_RTCP_RTP_FORMAT_VP8_H_
|
||||
#define WEBRTC_MODULES_RTP_RTCP_RTP_FORMAT_VP8_H_
|
||||
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
|
||||
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_FORMAT_VP8_H_
|
||||
|
||||
#include "module_common_types.h"
|
||||
#include "typedefs.h"
|
||||
#include "modules/interface/module_common_types.h"
|
||||
#include "typedefs.h" // NOLINT(build/include)
|
||||
|
||||
namespace webrtc
|
||||
{
|
||||
namespace webrtc {
|
||||
|
||||
enum VP8PacketizerMode
|
||||
{
|
||||
kStrict = 0, // split partitions if too large; never aggregate, balance size
|
||||
kAggregate, // split partitions if too large; aggregate whole partitions
|
||||
kSloppy, // split entire payload without considering partition limits
|
||||
enum VP8PacketizerMode {
|
||||
kStrict = 0, // Split partitions if too large;
|
||||
// never aggregate, balance size.
|
||||
kAggregate, // Split partitions if too large; aggregate whole partitions.
|
||||
kSloppy, // Split entire payload without considering partition limits.
|
||||
kNumModes,
|
||||
};
|
||||
|
||||
// Packetizer for VP8.
|
||||
class RtpFormatVp8
|
||||
{
|
||||
public:
|
||||
class RtpFormatVp8 {
|
||||
public:
|
||||
// Initialize with payload from encoder and fragmentation info.
|
||||
// The payload_data must be exactly one encoded VP8 frame.
|
||||
RtpFormatVp8(const WebRtc_UWord8* payload_data,
|
||||
@ -69,12 +67,11 @@ public:
|
||||
int NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
|
||||
int* bytes_to_send, bool* last_packet);
|
||||
|
||||
private:
|
||||
enum AggregationMode
|
||||
{
|
||||
kAggrNone = 0, // no aggregation
|
||||
kAggrPartitions, // aggregate intact partitions
|
||||
kAggrFragments // aggregate intact and fragmented partitions
|
||||
private:
|
||||
enum AggregationMode {
|
||||
kAggrNone = 0, // No aggregation.
|
||||
kAggrPartitions, // Aggregate intact partitions.
|
||||
kAggrFragments // Aggregate intact and fragmented partitions.
|
||||
};
|
||||
|
||||
static const AggregationMode aggr_modes_[kNumModes];
|
||||
@ -148,10 +145,10 @@ private:
|
||||
RTPFragmentationHeader part_info_;
|
||||
int payload_bytes_sent_;
|
||||
int part_ix_;
|
||||
bool beginning_; // first partition in this frame
|
||||
bool first_fragment_; // first fragment of a partition
|
||||
const int vp8_fixed_payload_descriptor_bytes_; // length of VP8 payload
|
||||
// descriptors's fixed part
|
||||
bool beginning_; // First partition in this frame.
|
||||
bool first_fragment_; // First fragment of a partition.
|
||||
const int vp8_fixed_payload_descriptor_bytes_; // Length of VP8 payload
|
||||
// descriptors's fixed part.
|
||||
AggregationMode aggr_mode_;
|
||||
bool balance_;
|
||||
bool separate_first_;
|
||||
@ -159,6 +156,6 @@ private:
|
||||
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 "typedefs.h"
|
||||
#include "rtp_format_vp8.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_format_vp8.h"
|
||||
#include "typedefs.h" // NOLINT(build/include)
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -25,7 +25,7 @@ const int kBufferSize = kPayloadSize + 6; // Add space for payload descriptor.
|
||||
|
||||
class RtpFormatVp8Test : public ::testing::Test {
|
||||
protected:
|
||||
RtpFormatVp8Test() {};
|
||||
RtpFormatVp8Test() {}
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
void CheckHeader(bool first_in_frame, bool frag_start, int part_id);
|
||||
@ -47,9 +47,8 @@ class RtpFormatVp8Test : public ::testing::Test {
|
||||
};
|
||||
|
||||
void RtpFormatVp8Test::SetUp() {
|
||||
for (int i = 0; i < kPayloadSize; i++)
|
||||
{
|
||||
payload_data_[i] = i / 10; // integer division
|
||||
for (int i = 0; i < kPayloadSize; i++) {
|
||||
payload_data_[i] = i / 10; // Integer division.
|
||||
}
|
||||
data_ptr_ = payload_data_;
|
||||
|
||||
@ -73,52 +72,48 @@ void RtpFormatVp8Test::TearDown() {
|
||||
delete fragmentation_;
|
||||
}
|
||||
|
||||
// First octet tests
|
||||
#define EXPECT_BIT_EQ(x,n,a) EXPECT_EQ((((x)>>n)&0x1), a)
|
||||
// First octet tests.
|
||||
#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)
|
||||
|
||||
#define EXPECT_BIT_X_EQ(x,a) EXPECT_BIT_EQ(x, 7, a)
|
||||
#define EXPECT_BIT_X_EQ(x, a) EXPECT_BIT_EQ(x, 7, a)
|
||||
|
||||
#define EXPECT_BIT_N_EQ(x,a) EXPECT_BIT_EQ(x, 5, a)
|
||||
#define EXPECT_BIT_N_EQ(x, a) EXPECT_BIT_EQ(x, 5, a)
|
||||
|
||||
#define EXPECT_BIT_S_EQ(x,a) EXPECT_BIT_EQ(x, 4, a)
|
||||
#define EXPECT_BIT_S_EQ(x, a) EXPECT_BIT_EQ(x, 4, a)
|
||||
|
||||
#define EXPECT_PART_ID_EQ(x, a) EXPECT_EQ(((x)&0x0F), a)
|
||||
#define EXPECT_PART_ID_EQ(x, a) EXPECT_EQ(((x) & 0x0F), a)
|
||||
|
||||
// Extension fields tests
|
||||
#define EXPECT_BIT_I_EQ(x,a) EXPECT_BIT_EQ(x, 7, a)
|
||||
#define EXPECT_BIT_I_EQ(x, a) EXPECT_BIT_EQ(x, 7, a)
|
||||
|
||||
#define EXPECT_BIT_L_EQ(x,a) EXPECT_BIT_EQ(x, 6, a)
|
||||
#define EXPECT_BIT_L_EQ(x, a) EXPECT_BIT_EQ(x, 6, a)
|
||||
|
||||
#define EXPECT_BIT_T_EQ(x,a) EXPECT_BIT_EQ(x, 5, a)
|
||||
#define EXPECT_BIT_T_EQ(x, a) EXPECT_BIT_EQ(x, 5, a)
|
||||
|
||||
#define EXPECT_BIT_K_EQ(x,a) EXPECT_BIT_EQ(x, 4, a)
|
||||
#define EXPECT_BIT_K_EQ(x, a) EXPECT_BIT_EQ(x, 4, a)
|
||||
|
||||
#define EXPECT_TID_EQ(x,a) EXPECT_EQ((((x) & 0xE0) >> 5), a)
|
||||
#define EXPECT_TID_EQ(x, a) EXPECT_EQ((((x) & 0xE0) >> 5), a)
|
||||
|
||||
#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,
|
||||
int part_id)
|
||||
{
|
||||
int part_id) {
|
||||
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 ||
|
||||
hdr_info_.temporalIdx != kNoTemporalIdx ||
|
||||
hdr_info_.tl0PicIdx != kNoTl0PicIdx ||
|
||||
hdr_info_.keyIdx != kNoKeyIdx)
|
||||
{
|
||||
hdr_info_.keyIdx != kNoKeyIdx) {
|
||||
EXPECT_BIT_X_EQ(buffer_[0], 1);
|
||||
++payload_start_;
|
||||
CheckPictureID();
|
||||
CheckTl0PicIdx();
|
||||
CheckTIDAndKeyIdx();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
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);
|
||||
|
||||
// Check partition index.
|
||||
if (part_id < 0)
|
||||
{
|
||||
if (part_id < 0) {
|
||||
// (Payload data is the same as the partition index.)
|
||||
EXPECT_EQ(buffer_[0] & 0x0F, buffer_[payload_start_]);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
EXPECT_EQ(buffer_[0] & 0x0F, part_id);
|
||||
}
|
||||
}
|
||||
|
||||
void RtpFormatVp8Test::CheckPictureID()
|
||||
{
|
||||
if (hdr_info_.pictureId != kNoPictureId)
|
||||
{
|
||||
void RtpFormatVp8Test::CheckPictureID() {
|
||||
if (hdr_info_.pictureId != kNoPictureId) {
|
||||
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_EQ(buffer_[payload_start_] & 0x7F,
|
||||
(hdr_info_.pictureId >> 8) & 0x7F);
|
||||
EXPECT_EQ(buffer_[payload_start_ + 1],
|
||||
hdr_info_.pictureId & 0xFF);
|
||||
payload_start_ += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
EXPECT_BIT_EQ(buffer_[payload_start_], 7, 0);
|
||||
EXPECT_EQ(buffer_[payload_start_] & 0x7F,
|
||||
(hdr_info_.pictureId) & 0x7F);
|
||||
payload_start_ += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
EXPECT_BIT_I_EQ(buffer_[1], 0);
|
||||
}
|
||||
}
|
||||
|
||||
void RtpFormatVp8Test::CheckTl0PicIdx()
|
||||
{
|
||||
if (hdr_info_.tl0PicIdx != kNoTl0PicIdx)
|
||||
{
|
||||
void RtpFormatVp8Test::CheckTl0PicIdx() {
|
||||
if (hdr_info_.tl0PicIdx != kNoTl0PicIdx) {
|
||||
EXPECT_BIT_L_EQ(buffer_[1], 1);
|
||||
EXPECT_EQ(buffer_[payload_start_], hdr_info_.tl0PicIdx);
|
||||
++payload_start_;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
EXPECT_BIT_L_EQ(buffer_[1], 0);
|
||||
}
|
||||
}
|
||||
|
||||
void RtpFormatVp8Test::CheckTIDAndKeyIdx()
|
||||
{
|
||||
void RtpFormatVp8Test::CheckTIDAndKeyIdx() {
|
||||
if (hdr_info_.temporalIdx == kNoTemporalIdx &&
|
||||
hdr_info_.keyIdx == kNoKeyIdx)
|
||||
{
|
||||
hdr_info_.keyIdx == kNoKeyIdx) {
|
||||
EXPECT_BIT_T_EQ(buffer_[1], 0);
|
||||
EXPECT_BIT_K_EQ(buffer_[1], 0);
|
||||
return;
|
||||
}
|
||||
if (hdr_info_.temporalIdx != kNoTemporalIdx)
|
||||
{
|
||||
if (hdr_info_.temporalIdx != kNoTemporalIdx) {
|
||||
EXPECT_BIT_T_EQ(buffer_[1], 1);
|
||||
EXPECT_TID_EQ(buffer_[payload_start_], hdr_info_.temporalIdx);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
EXPECT_BIT_T_EQ(buffer_[1], 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_KEYIDX_EQ(buffer_[payload_start_], hdr_info_.keyIdx);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
EXPECT_BIT_K_EQ(buffer_[1], 0);
|
||||
EXPECT_KEYIDX_EQ(buffer_[payload_start_], 0);
|
||||
}
|
||||
++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_++)
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
CheckHeader(first_in_frame, frag_start, -1);
|
||||
CheckPayload(send_bytes);
|
||||
@ -235,155 +205,148 @@ void RtpFormatVp8Test::CheckPacketZeroPartId(int send_bytes,
|
||||
int expect_bytes,
|
||||
bool last,
|
||||
bool first_in_frame,
|
||||
bool frag_start)
|
||||
{
|
||||
bool frag_start) {
|
||||
EXPECT_EQ(send_bytes, expect_bytes);
|
||||
CheckHeader(first_in_frame, frag_start, 0);
|
||||
CheckPayload(send_bytes);
|
||||
CheckLast(last);
|
||||
}
|
||||
|
||||
TEST_F(RtpFormatVp8Test, TestStrictMode)
|
||||
{
|
||||
TEST_F(RtpFormatVp8Test, TestStrictMode) {
|
||||
int send_bytes = 0;
|
||||
bool last;
|
||||
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,
|
||||
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));
|
||||
CheckPacket(send_bytes, 8, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ true);
|
||||
first_in_frame = false;
|
||||
|
||||
// get second packet
|
||||
// Get second packet.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(13, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 10, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// Second partition
|
||||
// Get first (and only) packet
|
||||
// Second partition.
|
||||
// Get first (and only) packet.
|
||||
EXPECT_EQ(1, packetizer.NextPacket(20, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 14, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ true);
|
||||
|
||||
// Third partition
|
||||
// Get first packet (of four)
|
||||
// Third partition.
|
||||
// Get first packet (of four).
|
||||
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 5, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ true);
|
||||
|
||||
// Get second packet (of four)
|
||||
// Get second packet (of four).
|
||||
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 5, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// Get third packet (of four)
|
||||
// Get third packet (of four).
|
||||
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 7, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// Get fourth and last packet
|
||||
// Get fourth and last packet.
|
||||
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 5, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(RtpFormatVp8Test, TestAggregateMode)
|
||||
{
|
||||
TEST_F(RtpFormatVp8Test, TestAggregateMode) {
|
||||
int send_bytes = 0;
|
||||
bool last;
|
||||
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,
|
||||
hdr_info_, *fragmentation_, kAggregate);
|
||||
hdr_info_, *fragmentation_,
|
||||
kAggregate);
|
||||
|
||||
// get first packet
|
||||
// first part of first partition (balanced fragments are expected)
|
||||
// Get first packet.
|
||||
// First part of first partition (balanced fragments are expected).
|
||||
EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 7, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ true);
|
||||
first_in_frame = false;
|
||||
|
||||
// get second packet
|
||||
// second fragment of first partition
|
||||
// Get second packet.
|
||||
// Second fragment of first partition.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 5, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// get third packet
|
||||
// third fragment of first partition
|
||||
// Get third packet.
|
||||
// Third fragment of first partition.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 7, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// get fourth packet
|
||||
// last two partitions aggregated
|
||||
// Get fourth packet.
|
||||
// Last two partitions aggregated.
|
||||
EXPECT_EQ(1, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 23, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ true);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(RtpFormatVp8Test, TestSloppyMode)
|
||||
{
|
||||
TEST_F(RtpFormatVp8Test, TestSloppyMode) {
|
||||
int send_bytes = 0;
|
||||
bool last;
|
||||
bool first_in_frame = true;
|
||||
|
||||
hdr_info_.pictureId = kNoPictureId; // no PictureID
|
||||
hdr_info_.pictureId = kNoPictureId; // No PictureID.
|
||||
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
|
||||
hdr_info_, *fragmentation_, kSloppy);
|
||||
|
||||
// get first packet
|
||||
// Get first packet.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 9, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ true);
|
||||
first_in_frame = false;
|
||||
|
||||
// get second packet
|
||||
// fragments of first and second partitions
|
||||
// Get second packet.
|
||||
// Fragments of first and second partitions.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 9, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// get third packet
|
||||
// fragments of second and third partitions
|
||||
// Get third packet.
|
||||
// Fragments of second and third partitions.
|
||||
EXPECT_EQ(1, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 9, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// get fourth packet
|
||||
// second half of last partition
|
||||
// Get fourth packet.
|
||||
// Second half of last partition.
|
||||
EXPECT_EQ(2, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
|
||||
CheckPacket(send_bytes, 7, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
}
|
||||
|
||||
// Verify that sloppy mode is forced if fragmentation info is missing.
|
||||
TEST_F(RtpFormatVp8Test, TestSloppyModeFallback)
|
||||
{
|
||||
TEST_F(RtpFormatVp8Test, TestSloppyModeFallback) {
|
||||
int send_bytes = 0;
|
||||
bool last;
|
||||
bool first_in_frame = true;
|
||||
@ -392,34 +355,33 @@ TEST_F(RtpFormatVp8Test, TestSloppyModeFallback)
|
||||
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
|
||||
hdr_info_);
|
||||
|
||||
// get first packet
|
||||
// Get first packet.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last));
|
||||
CheckPacketZeroPartId(send_bytes, 10, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ true);
|
||||
first_in_frame = false;
|
||||
|
||||
// get second packet
|
||||
// fragments of first and second partitions
|
||||
// Get second packet.
|
||||
// Fragments of first and second partitions.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last));
|
||||
CheckPacketZeroPartId(send_bytes, 10, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// get third packet
|
||||
// fragments of second and third partitions
|
||||
// Get third packet.
|
||||
// Fragments of second and third partitions.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last));
|
||||
CheckPacketZeroPartId(send_bytes, 10, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
// get fourth packet
|
||||
// second half of last partition
|
||||
// Get fourth packet.
|
||||
// Second half of last partition.
|
||||
EXPECT_EQ(0, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
|
||||
CheckPacketZeroPartId(send_bytes, 7, last,
|
||||
first_in_frame,
|
||||
/* frag_start */ false);
|
||||
|
||||
}
|
||||
|
||||
// Verify that non-reference bit is set.
|
||||
@ -431,12 +393,12 @@ TEST_F(RtpFormatVp8Test, TestNonReferenceBit) {
|
||||
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
|
||||
hdr_info_);
|
||||
|
||||
// get first packet
|
||||
// Get first packet.
|
||||
ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
|
||||
ASSERT_FALSE(last);
|
||||
EXPECT_BIT_N_EQ(buffer_[0], 1);
|
||||
|
||||
// get second packet
|
||||
// Get second packet.
|
||||
ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
|
||||
ASSERT_TRUE(last);
|
||||
EXPECT_BIT_N_EQ(buffer_[0], 1);
|
||||
@ -450,9 +412,10 @@ TEST_F(RtpFormatVp8Test, TestTl0PicIdxAndTID) {
|
||||
hdr_info_.tl0PicIdx = 117;
|
||||
hdr_info_.temporalIdx = 2;
|
||||
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,
|
||||
&last));
|
||||
bool first_in_frame = true;
|
||||
@ -461,16 +424,17 @@ TEST_F(RtpFormatVp8Test, TestTl0PicIdxAndTID) {
|
||||
/* frag_start */ true);
|
||||
}
|
||||
|
||||
// Verify KeyIdx field
|
||||
// Verify KeyIdx field.
|
||||
TEST_F(RtpFormatVp8Test, TestKeyIdx) {
|
||||
int send_bytes = 0;
|
||||
bool last;
|
||||
|
||||
hdr_info_.keyIdx = 17;
|
||||
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,
|
||||
&last));
|
||||
bool first_in_frame = true;
|
||||
@ -479,7 +443,7 @@ TEST_F(RtpFormatVp8Test, TestKeyIdx) {
|
||||
/* frag_start */ true);
|
||||
}
|
||||
|
||||
// Verify TID field and KeyIdx field in combination
|
||||
// Verify TID field and KeyIdx field in combination.
|
||||
TEST_F(RtpFormatVp8Test, TestTIDAndKeyIdx) {
|
||||
int send_bytes = 0;
|
||||
bool last;
|
||||
@ -487,9 +451,10 @@ TEST_F(RtpFormatVp8Test, TestTIDAndKeyIdx) {
|
||||
hdr_info_.temporalIdx = 1;
|
||||
hdr_info_.keyIdx = 5;
|
||||
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,
|
||||
&last));
|
||||
bool first_in_frame = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user