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

View File

@ -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 <cassert> // assert
#include <string.h> // memcpy
#include <string.h> // memcpy
#include <cassert> // assert
namespace webrtc {
@ -40,9 +41,8 @@ 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)
{
part_info_ = fragmentation;
first_partition_in_packet_(0) {
part_info_ = fragmentation;
}
RtpFormatVp8::RtpFormatVp8(const WebRtc_UWord8* payload_data,
@ -60,312 +60,268 @@ 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)
{
return 0;
}
if (!split_payload)
{
return max_payload_len >= remaining_bytes ? remaining_bytes : 0;
}
bool split_payload) const {
if (max_payload_len == 0 || remaining_bytes == 0) {
return 0;
}
if (!split_payload) {
return max_payload_len >= remaining_bytes ? remaining_bytes : 0;
}
if (balance_)
{
// Balance payload sizes to produce (almost) equal size
// fragments.
// Number of fragments for remaining_bytes:
int num_frags = remaining_bytes / max_payload_len + 1;
// Number of bytes in this fragment:
return static_cast<int>(static_cast<double>(remaining_bytes)
/ num_frags + 0.5);
}
else
{
return max_payload_len >= remaining_bytes ? remaining_bytes
: max_payload_len;
}
if (balance_) {
// Balance payload sizes to produce (almost) equal size
// fragments.
// Number of fragments for remaining_bytes:
int num_frags = remaining_bytes / max_payload_len + 1;
// Number of bytes in this fragment:
return static_cast<int>(static_cast<double>(remaining_bytes)
/ num_frags + 0.5);
} 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)
{
if (max_payload_len < vp8_fixed_payload_descriptor_bytes_
+ PayloadDescriptorExtraLength() + 1)
{
// The provided payload length is not long enough for the payload
// descriptor and one payload byte. Return an error.
return -1;
}
const int num_partitions = part_info_.fragmentationVectorSize;
int send_bytes = 0; // How much data to send in this packet.
bool split_payload = true; // Splitting of partitions is initially allowed.
int remaining_in_partition = part_info_.fragmentationOffset[part_ix_] -
payload_bytes_sent_ + part_info_.fragmentationLength[part_ix_] +
PayloadDescriptorExtraLength();
int rem_payload_len = max_payload_len - vp8_fixed_payload_descriptor_bytes_;
first_partition_in_packet_ = part_ix_;
if (first_partition_in_packet_ > 8) return -1;
int* bytes_to_send, bool* last_packet) {
if (max_payload_len < vp8_fixed_payload_descriptor_bytes_
+ PayloadDescriptorExtraLength() + 1) {
// The provided payload length is not long enough for the payload
// descriptor and one payload byte. Return an error.
return -1;
}
const int num_partitions = part_info_.fragmentationVectorSize;
int send_bytes = 0; // How much data to send in this packet.
bool split_payload = true; // Splitting of partitions is initially allowed.
int remaining_in_partition = part_info_.fragmentationOffset[part_ix_] -
payload_bytes_sent_ + part_info_.fragmentationLength[part_ix_] +
PayloadDescriptorExtraLength();
int rem_payload_len = max_payload_len - vp8_fixed_payload_descriptor_bytes_;
first_partition_in_packet_ = part_ix_;
if (first_partition_in_packet_ > 8) return -1;
while (int next_size = CalcNextSize(rem_payload_len, remaining_in_partition,
split_payload))
{
send_bytes += next_size;
rem_payload_len -= next_size;
remaining_in_partition -= next_size;
while (int next_size = CalcNextSize(rem_payload_len, remaining_in_partition,
split_payload)) {
send_bytes += next_size;
rem_payload_len -= next_size;
remaining_in_partition -= next_size;
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
// aggregate intact partitions and that we started this packet
// with an intact partition (indicated by first_fragment_ == true).
if (part_ix_ + 1 < num_partitions &&
((aggr_mode_ == kAggrFragments) ||
(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)
{
break;
}
}
if (remaining_in_partition == 0)
{
++part_ix_; // Advance to next partition.
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
// aggregate intact partitions and that we started this packet
// with an intact partition (indicated by first_fragment_ == true).
if (part_ix_ + 1 < num_partitions &&
((aggr_mode_ == kAggrFragments) ||
(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) {
break;
}
}
if (remaining_in_partition == 0) {
++part_ix_; // Advance to next partition.
}
send_bytes -= PayloadDescriptorExtraLength(); // Remove extra length again.
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)
{
return -1;
}
send_bytes -= PayloadDescriptorExtraLength(); // Remove extra length again.
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) {
return -1;
}
beginning_ = false; // Next packet cannot be first packet in frame.
// Next packet starts new fragment if this ended one.
first_fragment_ = (remaining_in_partition == 0);
*last_packet = (payload_bytes_sent_ >= payload_size_);
assert(!*last_packet || (payload_bytes_sent_ == payload_size_));
return first_partition_in_packet_;
beginning_ = false; // Next packet cannot be first packet in frame.
// Next packet starts new fragment if this ended one.
first_fragment_ = (remaining_in_partition == 0);
*last_packet = (payload_bytes_sent_ >= payload_size_);
assert(!*last_packet || (payload_bytes_sent_ == payload_size_));
return first_partition_in_packet_;
}
int RtpFormatVp8::WriteHeaderAndPayload(int payload_bytes,
WebRtc_UWord8* buffer,
int buffer_length)
{
// Write the VP8 payload descriptor.
// 0
// 0 1 2 3 4 5 6 7 8
// +-+-+-+-+-+-+-+-+-+
// |X| |N|S| PART_ID |
// +-+-+-+-+-+-+-+-+-+
// X: |I|L|T|K| | (mandatory if any of the below are used)
// +-+-+-+-+-+-+-+-+-+
// I: |PictureID (8/16b)| (optional)
// +-+-+-+-+-+-+-+-+-+
// L: | TL0PIC_IDX | (optional)
// +-+-+-+-+-+-+-+-+-+
// T/K: | TID | KEYIDX | (optional)
// +-+-+-+-+-+-+-+-+-+
int buffer_length) {
// Write the VP8 payload descriptor.
// 0
// 0 1 2 3 4 5 6 7 8
// +-+-+-+-+-+-+-+-+-+
// |X| |N|S| PART_ID |
// +-+-+-+-+-+-+-+-+-+
// X: |I|L|T|K| | (mandatory if any of the below are used)
// +-+-+-+-+-+-+-+-+-+
// I: |PictureID (8/16b)| (optional)
// +-+-+-+-+-+-+-+-+-+
// L: | TL0PIC_IDX | (optional)
// +-+-+-+-+-+-+-+-+-+
// T/K: | TID | KEYIDX | (optional)
// +-+-+-+-+-+-+-+-+-+
assert(payload_bytes > 0);
assert(payload_bytes_sent_ + payload_bytes <= payload_size_);
assert(vp8_fixed_payload_descriptor_bytes_ + PayloadDescriptorExtraLength()
+ payload_bytes <= buffer_length);
assert(payload_bytes > 0);
assert(payload_bytes_sent_ + payload_bytes <= payload_size_);
assert(vp8_fixed_payload_descriptor_bytes_ + PayloadDescriptorExtraLength()
+ payload_bytes <= buffer_length);
buffer[0] = 0;
if (XFieldPresent()) buffer[0] |= kXBit;
if (hdr_info_.nonReference) buffer[0] |= kNBit;
if (first_fragment_) buffer[0] |= kSBit;
buffer[0] |= (first_partition_in_packet_ & kPartIdField);
buffer[0] = 0;
if (XFieldPresent()) buffer[0] |= kXBit;
if (hdr_info_.nonReference) buffer[0] |= kNBit;
if (first_fragment_) buffer[0] |= kSBit;
buffer[0] |= (first_partition_in_packet_ & kPartIdField);
const int extension_length = WriteExtensionFields(buffer, buffer_length);
const int extension_length = WriteExtensionFields(buffer, buffer_length);
memcpy(&buffer[vp8_fixed_payload_descriptor_bytes_ + extension_length],
&payload_data_[payload_bytes_sent_], payload_bytes);
memcpy(&buffer[vp8_fixed_payload_descriptor_bytes_ + extension_length],
&payload_data_[payload_bytes_sent_], payload_bytes);
payload_bytes_sent_ += payload_bytes;
payload_bytes_sent_ += payload_bytes;
// Return total length of written data.
return payload_bytes + vp8_fixed_payload_descriptor_bytes_
+ extension_length;
// Return total length of written data.
return payload_bytes + vp8_fixed_payload_descriptor_bytes_
+ extension_length;
}
int RtpFormatVp8::WriteExtensionFields(WebRtc_UWord8* buffer, int buffer_length)
const
{
int extension_length = 0;
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 (WritePictureIDFields(x_field, buffer, buffer_length,
&extension_length) < 0)
{
return -1;
}
}
if (TL0PicIdxFieldPresent())
{
if (WriteTl0PicIdxFields(x_field, buffer, buffer_length,
&extension_length) < 0)
{
return -1;
}
}
if (TIDFieldPresent() || KeyIdxFieldPresent())
{
if (WriteTIDAndKeyIdxFields(x_field, buffer, buffer_length,
&extension_length) < 0)
{
return -1;
}
}
assert(extension_length == PayloadDescriptorExtraLength());
int RtpFormatVp8::WriteExtensionFields(WebRtc_UWord8* buffer,
int buffer_length) const {
int extension_length = 0;
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 (WritePictureIDFields(x_field, buffer, buffer_length,
&extension_length) < 0) {
return -1;
}
}
return extension_length;
if (TL0PicIdxFieldPresent()) {
if (WriteTl0PicIdxFields(x_field, buffer, buffer_length,
&extension_length) < 0) {
return -1;
}
}
if (TIDFieldPresent() || KeyIdxFieldPresent()) {
if (WriteTIDAndKeyIdxFields(x_field, buffer, buffer_length,
&extension_length) < 0) {
return -1;
}
}
assert(extension_length == PayloadDescriptorExtraLength());
}
return extension_length;
}
int RtpFormatVp8::WritePictureIDFields(WebRtc_UWord8* x_field,
WebRtc_UWord8* buffer,
int buffer_length,
int* extension_length) const
{
*x_field |= kIBit;
const int pic_id_length = WritePictureID(
buffer + vp8_fixed_payload_descriptor_bytes_ + *extension_length,
buffer_length - vp8_fixed_payload_descriptor_bytes_
- *extension_length);
if (pic_id_length < 0) return -1;
*extension_length += pic_id_length;
return 0;
int* extension_length) const {
*x_field |= kIBit;
const int pic_id_length = WritePictureID(
buffer + vp8_fixed_payload_descriptor_bytes_ + *extension_length,
buffer_length - vp8_fixed_payload_descriptor_bytes_
- *extension_length);
if (pic_id_length < 0) return -1;
*extension_length += pic_id_length;
return 0;
}
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)
{
buffer[0] = 0x80 | ((pic_id >> 8) & 0x7F);
buffer[1] = pic_id & 0xFF;
}
else if (picture_id_len == 1)
{
buffer[0] = pic_id & 0x7F;
}
return picture_id_len;
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) {
buffer[0] = 0x80 | ((pic_id >> 8) & 0x7F);
buffer[1] = pic_id & 0xFF;
} else if (picture_id_len == 1) {
buffer[0] = pic_id & 0x7F;
}
return picture_id_len;
}
int RtpFormatVp8::WriteTl0PicIdxFields(WebRtc_UWord8* x_field,
WebRtc_UWord8* buffer,
int buffer_length,
int* extension_length) const
{
if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length
+ 1)
{
return -1;
}
*x_field |= kLBit;
buffer[vp8_fixed_payload_descriptor_bytes_
+ *extension_length] = hdr_info_.tl0PicIdx;
++*extension_length;
return 0;
int* extension_length) const {
if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length
+ 1) {
return -1;
}
*x_field |= kLBit;
buffer[vp8_fixed_payload_descriptor_bytes_
+ *extension_length] = hdr_info_.tl0PicIdx;
++*extension_length;
return 0;
}
int RtpFormatVp8::WriteTIDAndKeyIdxFields(WebRtc_UWord8* x_field,
WebRtc_UWord8* buffer,
int buffer_length,
int* extension_length) const
{
if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length
+ 1)
{
return -1;
}
WebRtc_UWord8* data_field =
&buffer[vp8_fixed_payload_descriptor_bytes_ + *extension_length];
*data_field = 0;
if (TIDFieldPresent())
{
*x_field |= kTBit;
*data_field |= hdr_info_.temporalIdx << 5;
}
if (KeyIdxFieldPresent())
{
*x_field |= kKBit;
*data_field |= (hdr_info_.keyIdx & kKeyIdxField);
}
++*extension_length;
int* extension_length) const {
if (buffer_length < vp8_fixed_payload_descriptor_bytes_ + *extension_length
+ 1) {
return -1;
}
WebRtc_UWord8* data_field =
&buffer[vp8_fixed_payload_descriptor_bytes_ + *extension_length];
*data_field = 0;
if (TIDFieldPresent()) {
*x_field |= kTBit;
*data_field |= hdr_info_.temporalIdx << 5;
}
if (KeyIdxFieldPresent()) {
*x_field |= kKBit;
*data_field |= (hdr_info_.keyIdx & kKeyIdxField);
}
++*extension_length;
return 0;
}
int RtpFormatVp8::PayloadDescriptorExtraLength() const {
int length_bytes = PictureIdLength();
if (TL0PicIdxFieldPresent()) ++length_bytes;
if (TIDFieldPresent() || KeyIdxFieldPresent()) ++length_bytes;
if (length_bytes > 0) ++length_bytes; // Include the extension field.
return length_bytes;
}
int RtpFormatVp8::PictureIdLength() const {
if (hdr_info_.pictureId == kNoPictureId) {
return 0;
}
if (hdr_info_.pictureId <= 0x7F) {
return 1;
}
return 2;
}
int RtpFormatVp8::PayloadDescriptorExtraLength() const
{
int length_bytes = PictureIdLength();
if (TL0PicIdxFieldPresent()) ++length_bytes;
if (TIDFieldPresent() || KeyIdxFieldPresent()) ++length_bytes;
if (length_bytes > 0) ++length_bytes; // Include the extension field.
return length_bytes;
bool RtpFormatVp8::XFieldPresent() const {
return (TIDFieldPresent() || TL0PicIdxFieldPresent() || PictureIdPresent()
|| KeyIdxFieldPresent());
}
int RtpFormatVp8::PictureIdLength() const
{
if (hdr_info_.pictureId == kNoPictureId)
{
return 0;
}
if (hdr_info_.pictureId <= 0x7F)
{
return 1;
}
return 2;
bool RtpFormatVp8::TIDFieldPresent() const {
return (hdr_info_.temporalIdx != kNoTemporalIdx);
}
bool RtpFormatVp8::XFieldPresent() const
{
return (TIDFieldPresent() || TL0PicIdxFieldPresent() || PictureIdPresent()
|| KeyIdxFieldPresent());
bool RtpFormatVp8::KeyIdxFieldPresent() const {
return (hdr_info_.keyIdx != kNoKeyIdx);
}
bool RtpFormatVp8::TIDFieldPresent() const
{
return (hdr_info_.temporalIdx != kNoTemporalIdx);
bool RtpFormatVp8::TL0PicIdxFieldPresent() const {
return (hdr_info_.tl0PicIdx != kNoTl0PicIdx);
}
bool RtpFormatVp8::KeyIdxFieldPresent() const
{
return (hdr_info_.keyIdx != kNoKeyIdx);
}
bool RtpFormatVp8::TL0PicIdxFieldPresent() const
{
return (hdr_info_.tl0PicIdx != kNoTl0PicIdx);
}
} // namespace webrtc
} // namespace webrtc

View File

@ -22,143 +22,140 @@
* 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
kNumModes,
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:
// Initialize with payload from encoder and fragmentation info.
// The payload_data must be exactly one encoded VP8 frame.
RtpFormatVp8(const WebRtc_UWord8* payload_data,
WebRtc_UWord32 payload_size,
const RTPVideoHeaderVP8& hdr_info,
const RTPFragmentationHeader& fragmentation,
VP8PacketizerMode mode);
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,
WebRtc_UWord32 payload_size,
const RTPVideoHeaderVP8& hdr_info,
const RTPFragmentationHeader& fragmentation,
VP8PacketizerMode mode);
// Initialize without fragmentation info. Mode kSloppy will be used.
// The payload_data must be exactly one encoded VP8 frame.
RtpFormatVp8(const WebRtc_UWord8* payload_data,
WebRtc_UWord32 payload_size,
const RTPVideoHeaderVP8& hdr_info);
// Initialize without fragmentation info. Mode kSloppy will be used.
// The payload_data must be exactly one encoded VP8 frame.
RtpFormatVp8(const WebRtc_UWord8* payload_data,
WebRtc_UWord32 payload_size,
const RTPVideoHeaderVP8& hdr_info);
// Get the next payload with VP8 payload header.
// max_payload_len limits the sum length of payload and VP8 payload header.
// buffer is a pointer to where the output will be written.
// bytes_to_send is an output variable that will contain number of bytes
// written to buffer. Parameter last_packet is true for the last packet of
// the frame, false otherwise (i.e., call the function again to get the
// next packet). Returns the partition index from which the first payload
// byte in the packet is taken, with the first partition having index 0;
// returns negative on error.
int NextPacket(int max_payload_len, WebRtc_UWord8* buffer,
int* bytes_to_send, bool* last_packet);
// Get the next payload with VP8 payload header.
// max_payload_len limits the sum length of payload and VP8 payload header.
// buffer is a pointer to where the output will be written.
// bytes_to_send is an output variable that will contain number of bytes
// written to buffer. Parameter last_packet is true for the last packet of
// the frame, false otherwise (i.e., call the function again to get the
// next packet). Returns the partition index from which the first payload
// byte in the packet is taken, with the first partition having index 0;
// returns negative on error.
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];
static const bool balance_modes_[kNumModes];
static const bool separate_first_modes_[kNumModes];
static const int kXBit = 0x80;
static const int kNBit = 0x20;
static const int kSBit = 0x10;
static const int kPartIdField = 0x0F;
static const int kKeyIdxField = 0x1F;
static const int kIBit = 0x80;
static const int kLBit = 0x40;
static const int kTBit = 0x20;
static const int kKBit = 0x10;
static const AggregationMode aggr_modes_[kNumModes];
static const bool balance_modes_[kNumModes];
static const bool separate_first_modes_[kNumModes];
static const int kXBit = 0x80;
static const int kNBit = 0x20;
static const int kSBit = 0x10;
static const int kPartIdField = 0x0F;
static const int kKeyIdxField = 0x1F;
static const int kIBit = 0x80;
static const int kLBit = 0x40;
static const int kTBit = 0x20;
static const int kKBit = 0x10;
// Calculate size of next chunk to send. Returns 0 if none can be sent.
int CalcNextSize(int max_payload_len, int remaining_bytes,
bool split_payload) const;
// Calculate size of next chunk to send. Returns 0 if none can be sent.
int CalcNextSize(int max_payload_len, int remaining_bytes,
bool split_payload) const;
// Write the payload header and copy the payload to the buffer.
// Will copy send_bytes bytes from the current position on the payload data.
// last_fragment indicates that this packet ends with the last byte of a
// partition.
int WriteHeaderAndPayload(int send_bytes, WebRtc_UWord8* buffer,
int buffer_length);
// Write the payload header and copy the payload to the buffer.
// Will copy send_bytes bytes from the current position on the payload data.
// last_fragment indicates that this packet ends with the last byte of a
// partition.
int WriteHeaderAndPayload(int send_bytes, WebRtc_UWord8* buffer,
int buffer_length);
// Write the X field and the appropriate extension fields to buffer.
// The function returns the extension length (including X field), or -1
// on error.
int WriteExtensionFields(WebRtc_UWord8* buffer, int buffer_length) const;
// Write the X field and the appropriate extension fields to buffer.
// The function returns the extension length (including X field), or -1
// on error.
int WriteExtensionFields(WebRtc_UWord8* buffer, int buffer_length) const;
// Set the I bit in the x_field, and write PictureID to the appropriate
// position in buffer. The function returns 0 on success, -1 otherwise.
int WritePictureIDFields(WebRtc_UWord8* x_field, WebRtc_UWord8* buffer,
int buffer_length, int* extension_length) const;
// Set the I bit in the x_field, and write PictureID to the appropriate
// position in buffer. The function returns 0 on success, -1 otherwise.
int WritePictureIDFields(WebRtc_UWord8* x_field, WebRtc_UWord8* buffer,
int buffer_length, int* extension_length) const;
// Set the L bit in the x_field, and write Tl0PicIdx to the appropriate
// position in buffer. The function returns 0 on success, -1 otherwise.
int WriteTl0PicIdxFields(WebRtc_UWord8* x_field, WebRtc_UWord8* buffer,
int buffer_length, int* extension_length) const;
// Set the L bit in the x_field, and write Tl0PicIdx to the appropriate
// position in buffer. The function returns 0 on success, -1 otherwise.
int WriteTl0PicIdxFields(WebRtc_UWord8* x_field, WebRtc_UWord8* buffer,
int buffer_length, int* extension_length) const;
// Set the T and K bits in the x_field, and write TID and KeyIdx to the
// appropriate position in buffer. The function returns 0 on success,
// -1 otherwise.
int WriteTIDAndKeyIdxFields(WebRtc_UWord8* x_field, WebRtc_UWord8* buffer,
int buffer_length, int* extension_length) const;
// Set the T and K bits in the x_field, and write TID and KeyIdx to the
// appropriate position in buffer. The function returns 0 on success,
// -1 otherwise.
int WriteTIDAndKeyIdxFields(WebRtc_UWord8* x_field, WebRtc_UWord8* buffer,
int buffer_length, int* extension_length) const;
// Write the PictureID from codec_specific_info_ to buffer. One or two
// bytes are written, depending on magnitude of PictureID. The function
// returns the number of bytes written.
int WritePictureID(WebRtc_UWord8* buffer, int buffer_length) const;
// Write the PictureID from codec_specific_info_ to buffer. One or two
// bytes are written, depending on magnitude of PictureID. The function
// returns the number of bytes written.
int WritePictureID(WebRtc_UWord8* buffer, int buffer_length) const;
// Calculate and return length (octets) of the variable header fields in
// the next header (i.e., header length in addition to vp8_header_bytes_).
int PayloadDescriptorExtraLength() const;
// Calculate and return length (octets) of the variable header fields in
// the next header (i.e., header length in addition to vp8_header_bytes_).
int PayloadDescriptorExtraLength() const;
// Calculate and return length (octets) of PictureID field in the next
// header. Can be 0, 1, or 2.
int PictureIdLength() const;
// Calculate and return length (octets) of PictureID field in the next
// header. Can be 0, 1, or 2.
int PictureIdLength() const;
// Check whether each of the optional fields will be included in the header.
bool XFieldPresent() const;
bool TIDFieldPresent() const;
bool KeyIdxFieldPresent() const;
bool TL0PicIdxFieldPresent() const;
bool PictureIdPresent() const { return (PictureIdLength() > 0); }
// Check whether each of the optional fields will be included in the header.
bool XFieldPresent() const;
bool TIDFieldPresent() const;
bool KeyIdxFieldPresent() const;
bool TL0PicIdxFieldPresent() const;
bool PictureIdPresent() const { return (PictureIdLength() > 0); }
const WebRtc_UWord8* payload_data_;
const int payload_size_;
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
AggregationMode aggr_mode_;
bool balance_;
bool separate_first_;
const RTPVideoHeaderVP8 hdr_info_;
int first_partition_in_packet_;
const WebRtc_UWord8* payload_data_;
const int payload_size_;
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.
AggregationMode aggr_mode_;
bool balance_;
bool separate_first_;
const RTPVideoHeaderVP8 hdr_info_;
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_

View File

@ -15,17 +15,17 @@
#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 {
const int kPayloadSize = 30;
const int kBufferSize = kPayloadSize + 6; // Add space for payload descriptor.
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);
@ -35,7 +35,7 @@ class RtpFormatVp8Test : public ::testing::Test {
void CheckPayload(int payload_end);
void CheckLast(bool last) const;
void CheckPacket(int send_bytes, int expect_bytes, bool last,
bool first_in_frame, bool frag_start);
bool first_in_frame, bool frag_start);
void CheckPacketZeroPartId(int send_bytes, int expect_bytes, bool last,
bool first_in_frame, bool frag_start);
WebRtc_UWord8 payload_data_[kPayloadSize];
@ -47,455 +47,420 @@ class RtpFormatVp8Test : public ::testing::Test {
};
void RtpFormatVp8Test::SetUp() {
for (int i = 0; i < kPayloadSize; i++)
{
payload_data_[i] = i / 10; // integer division
}
data_ptr_ = payload_data_;
for (int i = 0; i < kPayloadSize; i++) {
payload_data_[i] = i / 10; // Integer division.
}
data_ptr_ = payload_data_;
fragmentation_ = new RTPFragmentationHeader;
fragmentation_->VerifyAndAllocateFragmentationHeader(3);
fragmentation_->fragmentationLength[0] = 10;
fragmentation_->fragmentationLength[1] = 10;
fragmentation_->fragmentationLength[2] = 10;
fragmentation_->fragmentationOffset[0] = 0;
fragmentation_->fragmentationOffset[1] = 10;
fragmentation_->fragmentationOffset[2] = 20;
fragmentation_ = new RTPFragmentationHeader;
fragmentation_->VerifyAndAllocateFragmentationHeader(3);
fragmentation_->fragmentationLength[0] = 10;
fragmentation_->fragmentationLength[1] = 10;
fragmentation_->fragmentationLength[2] = 10;
fragmentation_->fragmentationOffset[0] = 0;
fragmentation_->fragmentationOffset[1] = 10;
fragmentation_->fragmentationOffset[2] = 20;
hdr_info_.pictureId = kNoPictureId;
hdr_info_.nonReference = false;
hdr_info_.temporalIdx = kNoTemporalIdx;
hdr_info_.tl0PicIdx = kNoTl0PicIdx;
hdr_info_.keyIdx = kNoKeyIdx;
hdr_info_.pictureId = kNoPictureId;
hdr_info_.nonReference = false;
hdr_info_.temporalIdx = kNoTemporalIdx;
hdr_info_.tl0PicIdx = kNoTl0PicIdx;
hdr_info_.keyIdx = kNoKeyIdx;
}
void RtpFormatVp8Test::TearDown() {
delete fragmentation_;
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)
{
payload_start_ = 1;
EXPECT_BIT_EQ(buffer_[0], 6, 0); // check reserved bit
int part_id) {
payload_start_ = 1;
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)
{
EXPECT_BIT_X_EQ(buffer_[0], 1);
++payload_start_;
CheckPictureID();
CheckTl0PicIdx();
CheckTIDAndKeyIdx();
}
else
{
EXPECT_BIT_X_EQ(buffer_[0], 0);
}
EXPECT_BIT_N_EQ(buffer_[0], 0);
EXPECT_BIT_S_EQ(buffer_[0], frag_start);
// Check partition index.
if (part_id < 0)
{
// (Payload data is the same as the partition index.)
EXPECT_EQ(buffer_[0] & 0x0F, buffer_[payload_start_]);
}
else
{
EXPECT_EQ(buffer_[0] & 0x0F, part_id);
}
}
void RtpFormatVp8Test::CheckPictureID()
{
if (hdr_info_.pictureId != kNoPictureId)
{
EXPECT_BIT_I_EQ(buffer_[1], 1);
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
{
EXPECT_BIT_EQ(buffer_[payload_start_], 7, 0);
EXPECT_EQ(buffer_[payload_start_] & 0x7F,
(hdr_info_.pictureId) & 0x7F);
payload_start_ += 1;
}
}
else
{
EXPECT_BIT_I_EQ(buffer_[1], 0);
}
}
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
{
EXPECT_BIT_L_EQ(buffer_[1], 0);
}
}
void RtpFormatVp8Test::CheckTIDAndKeyIdx()
{
if (hdr_info_.temporalIdx == kNoTemporalIdx &&
hdr_info_.keyIdx == kNoKeyIdx)
{
EXPECT_BIT_T_EQ(buffer_[1], 0);
EXPECT_BIT_K_EQ(buffer_[1], 0);
return;
}
if (hdr_info_.temporalIdx != kNoTemporalIdx)
{
EXPECT_BIT_T_EQ(buffer_[1], 1);
EXPECT_TID_EQ(buffer_[payload_start_], hdr_info_.temporalIdx);
}
else
{
EXPECT_BIT_T_EQ(buffer_[1], 0);
EXPECT_TID_EQ(buffer_[payload_start_], 0);
}
if (hdr_info_.keyIdx != kNoKeyIdx)
{
EXPECT_BIT_K_EQ(buffer_[1], 1);
EXPECT_KEYIDX_EQ(buffer_[payload_start_], hdr_info_.keyIdx);
}
else
{
EXPECT_BIT_K_EQ(buffer_[1], 0);
EXPECT_KEYIDX_EQ(buffer_[payload_start_], 0);
}
if (hdr_info_.pictureId != kNoPictureId ||
hdr_info_.temporalIdx != kNoTemporalIdx ||
hdr_info_.tl0PicIdx != kNoTl0PicIdx ||
hdr_info_.keyIdx != kNoKeyIdx) {
EXPECT_BIT_X_EQ(buffer_[0], 1);
++payload_start_;
CheckPictureID();
CheckTl0PicIdx();
CheckTIDAndKeyIdx();
} else {
EXPECT_BIT_X_EQ(buffer_[0], 0);
}
EXPECT_BIT_N_EQ(buffer_[0], 0);
EXPECT_BIT_S_EQ(buffer_[0], frag_start);
// Check partition index.
if (part_id < 0) {
// (Payload data is the same as the partition index.)
EXPECT_EQ(buffer_[0] & 0x0F, buffer_[payload_start_]);
} else {
EXPECT_EQ(buffer_[0] & 0x0F, part_id);
}
}
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::CheckPictureID() {
if (hdr_info_.pictureId != kNoPictureId) {
EXPECT_BIT_I_EQ(buffer_[1], 1);
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 {
EXPECT_BIT_EQ(buffer_[payload_start_], 7, 0);
EXPECT_EQ(buffer_[payload_start_] & 0x7F,
(hdr_info_.pictureId) & 0x7F);
payload_start_ += 1;
}
} else {
EXPECT_BIT_I_EQ(buffer_[1], 0);
}
}
void RtpFormatVp8Test::CheckLast(bool last) const
{
EXPECT_EQ(last, data_ptr_ == payload_data_ + kPayloadSize);
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 {
EXPECT_BIT_L_EQ(buffer_[1], 0);
}
}
void RtpFormatVp8Test::CheckTIDAndKeyIdx() {
if (hdr_info_.temporalIdx == kNoTemporalIdx &&
hdr_info_.keyIdx == kNoKeyIdx) {
EXPECT_BIT_T_EQ(buffer_[1], 0);
EXPECT_BIT_K_EQ(buffer_[1], 0);
return;
}
if (hdr_info_.temporalIdx != kNoTemporalIdx) {
EXPECT_BIT_T_EQ(buffer_[1], 1);
EXPECT_TID_EQ(buffer_[payload_start_], hdr_info_.temporalIdx);
} else {
EXPECT_BIT_T_EQ(buffer_[1], 0);
EXPECT_TID_EQ(buffer_[payload_start_], 0);
}
if (hdr_info_.keyIdx != kNoKeyIdx) {
EXPECT_BIT_K_EQ(buffer_[1], 1);
EXPECT_KEYIDX_EQ(buffer_[payload_start_], hdr_info_.keyIdx);
} else {
EXPECT_BIT_K_EQ(buffer_[1], 0);
EXPECT_KEYIDX_EQ(buffer_[payload_start_], 0);
}
++payload_start_;
}
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 {
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)
{
EXPECT_EQ(send_bytes, expect_bytes);
CheckHeader(first_in_frame, frag_start, -1);
CheckPayload(send_bytes);
CheckLast(last);
bool first_in_frame, bool frag_start) {
EXPECT_EQ(send_bytes, expect_bytes);
CheckHeader(first_in_frame, frag_start, -1);
CheckPayload(send_bytes);
CheckLast(last);
}
void RtpFormatVp8Test::CheckPacketZeroPartId(int send_bytes,
int expect_bytes,
bool last,
bool first_in_frame,
bool frag_start)
{
EXPECT_EQ(send_bytes, expect_bytes);
CheckHeader(first_in_frame, frag_start, 0);
CheckPayload(send_bytes);
CheckLast(last);
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)
{
int send_bytes = 0;
bool last;
bool first_in_frame = true;
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
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kStrict);
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
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 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
EXPECT_EQ(0, packetizer.NextPacket(13, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 10, last,
first_in_frame,
/* frag_start */ false);
// 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
EXPECT_EQ(1, packetizer.NextPacket(20, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 14, last,
first_in_frame,
/* frag_start */ true);
// 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)
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 5, last,
first_in_frame,
/* frag_start */ true);
// 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)
EXPECT_EQ(2, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 5, last,
first_in_frame,
/* frag_start */ false);
// 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)
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
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).
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.
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)
{
int send_bytes = 0;
bool last;
bool first_in_frame = true;
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
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kAggregate);
hdr_info_.pictureId = 20; // <= 0x7F should produce 1-byte PictureID.
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_,
kAggregate);
// 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 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
EXPECT_EQ(0, packetizer.NextPacket(8, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 5, last,
first_in_frame,
/* frag_start */ false);
// 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
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
EXPECT_EQ(1, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 23, last,
first_in_frame,
/* frag_start */ true);
// 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.
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)
{
int send_bytes = 0;
bool last;
bool first_in_frame = true;
TEST_F(RtpFormatVp8Test, TestSloppyMode) {
int send_bytes = 0;
bool last;
bool first_in_frame = true;
hdr_info_.pictureId = kNoPictureId; // no PictureID
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kSloppy);
hdr_info_.pictureId = kNoPictureId; // No PictureID.
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kSloppy);
// 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 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
EXPECT_EQ(0, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 9, last,
first_in_frame,
/* frag_start */ false);
// 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
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
EXPECT_EQ(2, packetizer.NextPacket(9, buffer_, &send_bytes, &last));
CheckPacket(send_bytes, 7, last,
first_in_frame,
/* frag_start */ false);
// 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.
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)
{
int send_bytes = 0;
bool last;
bool first_in_frame = true;
TEST_F(RtpFormatVp8Test, TestSloppyModeFallback) {
int send_bytes = 0;
bool last;
bool first_in_frame = true;
hdr_info_.pictureId = 200; // > 0x7F should produce 2-byte PictureID
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_);
hdr_info_.pictureId = 200; // > 0x7F should produce 2-byte PictureID
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_);
// 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 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
EXPECT_EQ(0, packetizer.NextPacket(10, buffer_, &send_bytes, &last));
CheckPacketZeroPartId(send_bytes, 10, last,
first_in_frame,
/* frag_start */ false);
// 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
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
EXPECT_EQ(0, packetizer.NextPacket(7, buffer_, &send_bytes, &last));
CheckPacketZeroPartId(send_bytes, 7, last,
first_in_frame,
/* frag_start */ false);
// 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.
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.
TEST_F(RtpFormatVp8Test, TestNonReferenceBit) {
int send_bytes = 0;
bool last;
int send_bytes = 0;
bool last;
hdr_info_.nonReference = true;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_);
hdr_info_.nonReference = true;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_);
// get first packet
ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
ASSERT_FALSE(last);
EXPECT_BIT_N_EQ(buffer_[0], 1);
// 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
ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
ASSERT_TRUE(last);
EXPECT_BIT_N_EQ(buffer_[0], 1);
// Get second packet.
ASSERT_EQ(0, packetizer.NextPacket(25, buffer_, &send_bytes, &last));
ASSERT_TRUE(last);
EXPECT_BIT_N_EQ(buffer_[0], 1);
}
// Verify Tl0PicIdx and TID fields
TEST_F(RtpFormatVp8Test, TestTl0PicIdxAndTID) {
int send_bytes = 0;
bool last;
int send_bytes = 0;
bool last;
hdr_info_.tl0PicIdx = 117;
hdr_info_.temporalIdx = 2;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kAggregate);
hdr_info_.tl0PicIdx = 117;
hdr_info_.temporalIdx = 2;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_,
kAggregate);
// get first and only packet
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last));
bool first_in_frame = true;
CheckPacket(send_bytes, kPayloadSize + 4, last,
first_in_frame,
/* frag_start */ true);
// Get first and only packet.
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last));
bool first_in_frame = true;
CheckPacket(send_bytes, kPayloadSize + 4, last,
first_in_frame,
/* frag_start */ true);
}
// Verify KeyIdx field
// Verify KeyIdx field.
TEST_F(RtpFormatVp8Test, TestKeyIdx) {
int send_bytes = 0;
bool last;
int send_bytes = 0;
bool last;
hdr_info_.keyIdx = 17;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kAggregate);
hdr_info_.keyIdx = 17;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_,
kAggregate);
// get first and only packet
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last));
bool first_in_frame = true;
CheckPacket(send_bytes, kPayloadSize + 3, last,
first_in_frame,
/* frag_start */ true);
// Get first and only packet.
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last));
bool first_in_frame = true;
CheckPacket(send_bytes, kPayloadSize + 3, last,
first_in_frame,
/* 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;
int send_bytes = 0;
bool last;
hdr_info_.temporalIdx = 1;
hdr_info_.keyIdx = 5;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_, kAggregate);
hdr_info_.temporalIdx = 1;
hdr_info_.keyIdx = 5;
RtpFormatVp8 packetizer = RtpFormatVp8(payload_data_, kPayloadSize,
hdr_info_, *fragmentation_,
kAggregate);
// get first and only packet
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last));
bool first_in_frame = true;
CheckPacket(send_bytes, kPayloadSize + 3, last,
first_in_frame,
/* frag_start */ true);
// Get first and only packet.
EXPECT_EQ(0, packetizer.NextPacket(kBufferSize, buffer_, &send_bytes,
&last));
bool first_in_frame = true;
CheckPacket(send_bytes, kPayloadSize + 3, last,
first_in_frame,
/* frag_start */ true);
}
} // namespace
} // namespace