Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information. This CL was reviewed and approved in pieces in the following CLs: https://webrtc-codereview.appspot.com/24209004/ https://webrtc-codereview.appspot.com/24229004/ https://webrtc-codereview.appspot.com/24259004/ https://webrtc-codereview.appspot.com/25109004/ https://webrtc-codereview.appspot.com/26099004/ https://webrtc-codereview.appspot.com/27069004/ https://webrtc-codereview.appspot.com/27969004/ https://webrtc-codereview.appspot.com/27989004/ https://webrtc-codereview.appspot.com/29009004/ https://webrtc-codereview.appspot.com/30929004/ https://webrtc-codereview.appspot.com/30939004/ https://webrtc-codereview.appspot.com/31999004/ Committing as TBR to the original reviewers. BUG=chromium:81439 TEST=none TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom Review URL: https://webrtc-codereview.appspot.com/23129004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -55,7 +55,7 @@ namespace webrtc {
|
||||
//
|
||||
int DtmfBuffer::ParseEvent(uint32_t rtp_timestamp,
|
||||
const uint8_t* payload,
|
||||
int payload_length_bytes,
|
||||
size_t payload_length_bytes,
|
||||
DtmfEvent* event) {
|
||||
if (!payload || !event) {
|
||||
return kInvalidPointer;
|
||||
|
||||
@ -69,7 +69,7 @@ class DtmfBuffer {
|
||||
// |rtp_timestamp| is simply copied into the struct.
|
||||
static int ParseEvent(uint32_t rtp_timestamp,
|
||||
const uint8_t* payload,
|
||||
int payload_length_bytes,
|
||||
size_t payload_length_bytes,
|
||||
DtmfEvent* event);
|
||||
|
||||
// Inserts |event| into the buffer. The method looks for a matching event and
|
||||
|
||||
@ -132,7 +132,7 @@ class NetEq {
|
||||
// Returns 0 on success, -1 on failure.
|
||||
virtual int InsertPacket(const WebRtcRTPHeader& rtp_header,
|
||||
const uint8_t* payload,
|
||||
int length_bytes,
|
||||
size_t length_bytes,
|
||||
uint32_t receive_timestamp) = 0;
|
||||
|
||||
// Inserts a sync-packet into packet queue. Sync-packets are decoded to
|
||||
|
||||
@ -28,11 +28,11 @@ class MockPayloadSplitter : public PayloadSplitter {
|
||||
MOCK_METHOD2(SplitAudio,
|
||||
int(PacketList* packet_list, const DecoderDatabase& decoder_database));
|
||||
MOCK_METHOD4(SplitBySamples,
|
||||
void(const Packet* packet, int bytes_per_ms, int timestamps_per_ms,
|
||||
PacketList* new_packets));
|
||||
void(const Packet* packet, size_t bytes_per_ms,
|
||||
uint32_t timestamps_per_ms, PacketList* new_packets));
|
||||
MOCK_METHOD4(SplitByFrames,
|
||||
int(const Packet* packet, int bytes_per_frame, int timestamps_per_frame,
|
||||
PacketList* new_packets));
|
||||
int(const Packet* packet, size_t bytes_per_frame,
|
||||
uint32_t timestamps_per_frame, PacketList* new_packets));
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -203,7 +203,7 @@ class NetEqExternalDecoderTest : public ::testing::Test {
|
||||
int sample_rate_hz_;
|
||||
int samples_per_ms_;
|
||||
const int frame_size_ms_;
|
||||
int frame_size_samples_;
|
||||
size_t frame_size_samples_;
|
||||
int output_size_samples_;
|
||||
NetEq* neteq_external_;
|
||||
NetEq* neteq_;
|
||||
@ -214,7 +214,7 @@ class NetEqExternalDecoderTest : public ::testing::Test {
|
||||
int16_t output_[kMaxBlockSize];
|
||||
int16_t output_external_[kMaxBlockSize];
|
||||
WebRtcRTPHeader rtp_header_;
|
||||
int payload_size_bytes_;
|
||||
size_t payload_size_bytes_;
|
||||
int last_send_time_;
|
||||
int last_arrival_time_;
|
||||
scoped_ptr<test::InputAudioFile> input_file_;
|
||||
|
||||
@ -117,7 +117,7 @@ NetEqImpl::~NetEqImpl() {
|
||||
|
||||
int NetEqImpl::InsertPacket(const WebRtcRTPHeader& rtp_header,
|
||||
const uint8_t* payload,
|
||||
int length_bytes,
|
||||
size_t length_bytes,
|
||||
uint32_t receive_timestamp) {
|
||||
CriticalSectionScoped lock(crit_sect_.get());
|
||||
LOG(LS_VERBOSE) << "InsertPacket: ts=" << rtp_header.header.timestamp <<
|
||||
@ -399,7 +399,7 @@ const SyncBuffer* NetEqImpl::sync_buffer_for_test() const {
|
||||
|
||||
int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
|
||||
const uint8_t* payload,
|
||||
int length_bytes,
|
||||
size_t length_bytes,
|
||||
uint32_t receive_timestamp,
|
||||
bool is_sync_packet) {
|
||||
if (!payload) {
|
||||
@ -1241,7 +1241,7 @@ int NetEqImpl::DecodeLoop(PacketList* packet_list, Operations* operation,
|
||||
assert(*operation == kNormal || *operation == kAccelerate ||
|
||||
*operation == kMerge || *operation == kPreemptiveExpand);
|
||||
packet_list->pop_front();
|
||||
int payload_length = packet->payload_length;
|
||||
size_t payload_length = packet->payload_length;
|
||||
int16_t decode_length;
|
||||
if (packet->sync_packet) {
|
||||
// Decode to silence with the same frame size as the last decode.
|
||||
|
||||
@ -81,7 +81,7 @@ class NetEqImpl : public webrtc::NetEq {
|
||||
// Returns 0 on success, -1 on failure.
|
||||
virtual int InsertPacket(const WebRtcRTPHeader& rtp_header,
|
||||
const uint8_t* payload,
|
||||
int length_bytes,
|
||||
size_t length_bytes,
|
||||
uint32_t receive_timestamp) OVERRIDE;
|
||||
|
||||
// Inserts a sync-packet into packet queue. Sync-packets are decoded to
|
||||
@ -210,7 +210,7 @@ class NetEqImpl : public webrtc::NetEq {
|
||||
// TODO(hlundin): Merge this with InsertPacket above?
|
||||
int InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
|
||||
const uint8_t* payload,
|
||||
int length_bytes,
|
||||
size_t length_bytes,
|
||||
uint32_t receive_timestamp,
|
||||
bool is_sync_packet)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
|
||||
|
||||
@ -253,7 +253,7 @@ TEST_F(NetEqImplTest, RemovePayloadType) {
|
||||
|
||||
TEST_F(NetEqImplTest, InsertPacket) {
|
||||
CreateInstance();
|
||||
const int kPayloadLength = 100;
|
||||
const size_t kPayloadLength = 100;
|
||||
const uint8_t kPayloadType = 0;
|
||||
const uint16_t kFirstSequenceNumber = 0x1234;
|
||||
const uint32_t kFirstTimestamp = 0x12345678;
|
||||
|
||||
@ -192,7 +192,7 @@ class NetEqDecodingTest : public ::testing::Test {
|
||||
static const int kBlockSize8kHz = kTimeStepMs * 8;
|
||||
static const int kBlockSize16kHz = kTimeStepMs * 16;
|
||||
static const int kBlockSize32kHz = kTimeStepMs * 32;
|
||||
static const int kMaxBlockSize = kBlockSize32kHz;
|
||||
static const size_t kMaxBlockSize = kBlockSize32kHz;
|
||||
static const int kInitSampleRateHz = 8000;
|
||||
|
||||
NetEqDecodingTest();
|
||||
@ -213,7 +213,7 @@ class NetEqDecodingTest : public ::testing::Test {
|
||||
int timestamp,
|
||||
WebRtcRTPHeader* rtp_info,
|
||||
uint8_t* payload,
|
||||
int* payload_len);
|
||||
size_t* payload_len);
|
||||
|
||||
void WrapTest(uint16_t start_seq_no, uint32_t start_timestamp,
|
||||
const std::set<uint16_t>& drop_seq_numbers,
|
||||
@ -244,7 +244,7 @@ const int NetEqDecodingTest::kTimeStepMs;
|
||||
const int NetEqDecodingTest::kBlockSize8kHz;
|
||||
const int NetEqDecodingTest::kBlockSize16kHz;
|
||||
const int NetEqDecodingTest::kBlockSize32kHz;
|
||||
const int NetEqDecodingTest::kMaxBlockSize;
|
||||
const size_t NetEqDecodingTest::kMaxBlockSize;
|
||||
const int NetEqDecodingTest::kInitSampleRateHz;
|
||||
|
||||
NetEqDecodingTest::NetEqDecodingTest()
|
||||
@ -396,7 +396,7 @@ void NetEqDecodingTest::PopulateCng(int frame_index,
|
||||
int timestamp,
|
||||
WebRtcRTPHeader* rtp_info,
|
||||
uint8_t* payload,
|
||||
int* payload_len) {
|
||||
size_t* payload_len) {
|
||||
rtp_info->header.sequenceNumber = frame_index;
|
||||
rtp_info->header.timestamp = timestamp;
|
||||
rtp_info->header.ssrc = 0x1234; // Just an arbitrary SSRC.
|
||||
@ -448,8 +448,8 @@ class NetEqDecodingTestFaxMode : public NetEqDecodingTest {
|
||||
TEST_F(NetEqDecodingTestFaxMode, TestFrameWaitingTimeStatistics) {
|
||||
// Insert 30 dummy packets at once. Each packet contains 10 ms 16 kHz audio.
|
||||
size_t num_frames = 30;
|
||||
const int kSamples = 10 * 16;
|
||||
const int kPayloadBytes = kSamples * 2;
|
||||
const size_t kSamples = 10 * 16;
|
||||
const size_t kPayloadBytes = kSamples * 2;
|
||||
for (size_t i = 0; i < num_frames; ++i) {
|
||||
uint16_t payload[kSamples] = {0};
|
||||
WebRtcRTPHeader rtp_info;
|
||||
@ -518,8 +518,8 @@ TEST_F(NetEqDecodingTestFaxMode, TestFrameWaitingTimeStatistics) {
|
||||
TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimeNegative) {
|
||||
const int kNumFrames = 3000; // Needed for convergence.
|
||||
int frame_index = 0;
|
||||
const int kSamples = 10 * 16;
|
||||
const int kPayloadBytes = kSamples * 2;
|
||||
const size_t kSamples = 10 * 16;
|
||||
const size_t kPayloadBytes = kSamples * 2;
|
||||
while (frame_index < kNumFrames) {
|
||||
// Insert one packet each time, except every 10th time where we insert two
|
||||
// packets at once. This will create a negative clock-drift of approx. 10%.
|
||||
@ -549,8 +549,8 @@ TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimeNegative) {
|
||||
TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimePositive) {
|
||||
const int kNumFrames = 5000; // Needed for convergence.
|
||||
int frame_index = 0;
|
||||
const int kSamples = 10 * 16;
|
||||
const int kPayloadBytes = kSamples * 2;
|
||||
const size_t kSamples = 10 * 16;
|
||||
const size_t kPayloadBytes = kSamples * 2;
|
||||
for (int i = 0; i < kNumFrames; ++i) {
|
||||
// Insert one packet each time, except every 10th time where we don't insert
|
||||
// any packet. This will create a positive clock-drift of approx. 11%.
|
||||
@ -585,8 +585,8 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
|
||||
uint16_t seq_no = 0;
|
||||
uint32_t timestamp = 0;
|
||||
const int kFrameSizeMs = 30;
|
||||
const int kSamples = kFrameSizeMs * 16;
|
||||
const int kPayloadBytes = kSamples * 2;
|
||||
const size_t kSamples = kFrameSizeMs * 16;
|
||||
const size_t kPayloadBytes = kSamples * 2;
|
||||
double next_input_time_ms = 0.0;
|
||||
double t_ms;
|
||||
int out_len;
|
||||
@ -625,7 +625,7 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
|
||||
while (next_input_time_ms <= t_ms) {
|
||||
// Insert one CNG frame each 100 ms.
|
||||
uint8_t payload[kPayloadBytes];
|
||||
int payload_len;
|
||||
size_t payload_len;
|
||||
WebRtcRTPHeader rtp_info;
|
||||
PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
|
||||
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, payload_len, 0));
|
||||
@ -672,7 +672,7 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
|
||||
}
|
||||
// Insert one CNG frame each 100 ms.
|
||||
uint8_t payload[kPayloadBytes];
|
||||
int payload_len;
|
||||
size_t payload_len;
|
||||
WebRtcRTPHeader rtp_info;
|
||||
PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
|
||||
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, payload_len, 0));
|
||||
@ -797,7 +797,7 @@ TEST_F(NetEqDecodingTest, LongCngWithoutClockDrift) {
|
||||
}
|
||||
|
||||
TEST_F(NetEqDecodingTest, UnknownPayloadType) {
|
||||
const int kPayloadBytes = 100;
|
||||
const size_t kPayloadBytes = 100;
|
||||
uint8_t payload[kPayloadBytes] = {0};
|
||||
WebRtcRTPHeader rtp_info;
|
||||
PopulateRtpInfo(0, 0, &rtp_info);
|
||||
@ -808,7 +808,7 @@ TEST_F(NetEqDecodingTest, UnknownPayloadType) {
|
||||
}
|
||||
|
||||
TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(DecoderError)) {
|
||||
const int kPayloadBytes = 100;
|
||||
const size_t kPayloadBytes = 100;
|
||||
uint8_t payload[kPayloadBytes] = {0};
|
||||
WebRtcRTPHeader rtp_info;
|
||||
PopulateRtpInfo(0, 0, &rtp_info);
|
||||
@ -817,7 +817,7 @@ TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(DecoderError)) {
|
||||
NetEqOutputType type;
|
||||
// Set all of |out_data_| to 1, and verify that it was set to 0 by the call
|
||||
// to GetAudio.
|
||||
for (int i = 0; i < kMaxBlockSize; ++i) {
|
||||
for (size_t i = 0; i < kMaxBlockSize; ++i) {
|
||||
out_data_[i] = 1;
|
||||
}
|
||||
int num_channels;
|
||||
@ -838,7 +838,7 @@ TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(DecoderError)) {
|
||||
SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
|
||||
EXPECT_EQ(0, out_data_[i]);
|
||||
}
|
||||
for (int i = kExpectedOutputLength; i < kMaxBlockSize; ++i) {
|
||||
for (size_t i = kExpectedOutputLength; i < kMaxBlockSize; ++i) {
|
||||
std::ostringstream ss;
|
||||
ss << "i = " << i;
|
||||
SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
|
||||
@ -850,7 +850,7 @@ TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) {
|
||||
NetEqOutputType type;
|
||||
// Set all of |out_data_| to 1, and verify that it was set to 0 by the call
|
||||
// to GetAudio.
|
||||
for (int i = 0; i < kMaxBlockSize; ++i) {
|
||||
for (size_t i = 0; i < kMaxBlockSize; ++i) {
|
||||
out_data_[i] = 1;
|
||||
}
|
||||
int num_channels;
|
||||
@ -875,7 +875,7 @@ class NetEqBgnTest : public NetEqDecodingTest {
|
||||
bool should_be_faded) = 0;
|
||||
|
||||
void CheckBgn(int sampling_rate_hz) {
|
||||
int expected_samples_per_channel = 0;
|
||||
int16_t expected_samples_per_channel = 0;
|
||||
uint8_t payload_type = 0xFF; // Invalid.
|
||||
if (sampling_rate_hz == 8000) {
|
||||
expected_samples_per_channel = kBlockSize8kHz;
|
||||
@ -899,7 +899,7 @@ class NetEqBgnTest : public NetEqDecodingTest {
|
||||
ASSERT_TRUE(input.Init(
|
||||
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"),
|
||||
10 * sampling_rate_hz, // Max 10 seconds loop length.
|
||||
expected_samples_per_channel));
|
||||
static_cast<size_t>(expected_samples_per_channel)));
|
||||
|
||||
// Payload of 10 ms of PCM16 32 kHz.
|
||||
uint8_t payload[kBlockSize32kHz * sizeof(int16_t)];
|
||||
@ -912,7 +912,7 @@ class NetEqBgnTest : public NetEqDecodingTest {
|
||||
|
||||
uint32_t receive_timestamp = 0;
|
||||
for (int n = 0; n < 10; ++n) { // Insert few packets and get audio.
|
||||
int enc_len_bytes =
|
||||
int16_t enc_len_bytes =
|
||||
WebRtcPcm16b_EncodeW16(input.GetNextBlock(),
|
||||
expected_samples_per_channel,
|
||||
reinterpret_cast<int16_t*>(payload));
|
||||
@ -921,8 +921,9 @@ class NetEqBgnTest : public NetEqDecodingTest {
|
||||
number_channels = 0;
|
||||
samples_per_channel = 0;
|
||||
ASSERT_EQ(0,
|
||||
neteq_->InsertPacket(
|
||||
rtp_info, payload, enc_len_bytes, receive_timestamp));
|
||||
neteq_->InsertPacket(rtp_info, payload,
|
||||
static_cast<size_t>(enc_len_bytes),
|
||||
receive_timestamp));
|
||||
ASSERT_EQ(0,
|
||||
neteq_->GetAudio(kBlockSize32kHz,
|
||||
output,
|
||||
@ -1074,7 +1075,7 @@ TEST_F(NetEqDecodingTest, SyncPacketInsert) {
|
||||
EXPECT_EQ(-1, neteq_->InsertSyncPacket(rtp_info, receive_timestamp));
|
||||
|
||||
// Payload length of 10 ms PCM16 16 kHz.
|
||||
const int kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
|
||||
const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
|
||||
uint8_t payload[kPayloadBytes] = {0};
|
||||
ASSERT_EQ(0, neteq_->InsertPacket(
|
||||
rtp_info, payload, kPayloadBytes, receive_timestamp));
|
||||
@ -1125,11 +1126,11 @@ TEST_F(NetEqDecodingTest, SyncPacketInsert) {
|
||||
TEST_F(NetEqDecodingTest, SyncPacketDecode) {
|
||||
WebRtcRTPHeader rtp_info;
|
||||
PopulateRtpInfo(0, 0, &rtp_info);
|
||||
const int kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
|
||||
const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
|
||||
uint8_t payload[kPayloadBytes];
|
||||
int16_t decoded[kBlockSize16kHz];
|
||||
int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1;
|
||||
for (int n = 0; n < kPayloadBytes; ++n) {
|
||||
for (size_t n = 0; n < kPayloadBytes; ++n) {
|
||||
payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence.
|
||||
}
|
||||
// Insert some packets which decode to noise. We are not interested in
|
||||
@ -1204,10 +1205,10 @@ TEST_F(NetEqDecodingTest, SyncPacketDecode) {
|
||||
TEST_F(NetEqDecodingTest, SyncPacketBufferSizeAndOverridenByNetworkPackets) {
|
||||
WebRtcRTPHeader rtp_info;
|
||||
PopulateRtpInfo(0, 0, &rtp_info);
|
||||
const int kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
|
||||
const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
|
||||
uint8_t payload[kPayloadBytes];
|
||||
int16_t decoded[kBlockSize16kHz];
|
||||
for (int n = 0; n < kPayloadBytes; ++n) {
|
||||
for (size_t n = 0; n < kPayloadBytes; ++n) {
|
||||
payload[n] = (rand() & 0xF0) + 1; // Non-zero random sequence.
|
||||
}
|
||||
// Insert some packets which decode to noise. We are not interested in
|
||||
@ -1279,7 +1280,7 @@ void NetEqDecodingTest::WrapTest(uint16_t start_seq_no,
|
||||
const int kBlocksPerFrame = 3; // Number of 10 ms blocks per frame.
|
||||
const int kFrameSizeMs = kBlocksPerFrame * kTimeStepMs;
|
||||
const int kSamples = kBlockSize16kHz * kBlocksPerFrame;
|
||||
const int kPayloadBytes = kSamples * sizeof(int16_t);
|
||||
const size_t kPayloadBytes = kSamples * sizeof(int16_t);
|
||||
double next_input_time_ms = 0.0;
|
||||
int16_t decoded[kBlockSize16kHz];
|
||||
int num_channels;
|
||||
@ -1380,7 +1381,7 @@ void NetEqDecodingTest::DuplicateCng() {
|
||||
const int kFrameSizeMs = 10;
|
||||
const int kSampleRateKhz = 16;
|
||||
const int kSamples = kFrameSizeMs * kSampleRateKhz;
|
||||
const int kPayloadBytes = kSamples * 2;
|
||||
const size_t kPayloadBytes = kSamples * 2;
|
||||
|
||||
const int algorithmic_delay_samples = std::max(
|
||||
algorithmic_delay_ms_ * kSampleRateKhz, 5 * kSampleRateKhz / 8);
|
||||
@ -1409,7 +1410,7 @@ void NetEqDecodingTest::DuplicateCng() {
|
||||
// Insert same CNG packet twice.
|
||||
const int kCngPeriodMs = 100;
|
||||
const int kCngPeriodSamples = kCngPeriodMs * kSampleRateKhz;
|
||||
int payload_len;
|
||||
size_t payload_len;
|
||||
PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
|
||||
// This is the first time this CNG packet is inserted.
|
||||
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, payload_len, 0));
|
||||
|
||||
@ -22,7 +22,7 @@ namespace webrtc {
|
||||
struct Packet {
|
||||
RTPHeader header;
|
||||
uint8_t* payload; // Datagram excluding RTP header and header extension.
|
||||
int payload_length;
|
||||
size_t payload_length;
|
||||
bool primary; // Primary, i.e., not redundant payload.
|
||||
int waiting_time;
|
||||
bool sync_packet;
|
||||
|
||||
@ -46,7 +46,7 @@ int PayloadSplitter::SplitRed(PacketList* packet_list) {
|
||||
// +-+-+-+-+-+-+-+-+
|
||||
|
||||
bool last_block = false;
|
||||
int sum_length = 0;
|
||||
size_t sum_length = 0;
|
||||
while (!last_block) {
|
||||
Packet* new_packet = new Packet;
|
||||
new_packet->header = red_packet->header;
|
||||
@ -82,7 +82,7 @@ int PayloadSplitter::SplitRed(PacketList* packet_list) {
|
||||
// |payload_ptr| now points at the first payload byte.
|
||||
PacketList::iterator new_it;
|
||||
for (new_it = new_packets.begin(); new_it != new_packets.end(); ++new_it) {
|
||||
int payload_length = (*new_it)->payload_length;
|
||||
size_t payload_length = (*new_it)->payload_length;
|
||||
if (payload_ptr + payload_length >
|
||||
red_packet->payload + red_packet->payload_length) {
|
||||
// The block lengths in the RED headers do not match the overall packet
|
||||
@ -291,11 +291,12 @@ int PayloadSplitter::SplitAudio(PacketList* packet_list,
|
||||
break;
|
||||
}
|
||||
case kDecoderILBC: {
|
||||
int bytes_per_frame;
|
||||
size_t bytes_per_frame;
|
||||
int timestamps_per_frame;
|
||||
if (packet->payload_length >= 950) {
|
||||
return kTooLargePayload;
|
||||
} else if (packet->payload_length % 38 == 0) {
|
||||
}
|
||||
if (packet->payload_length % 38 == 0) {
|
||||
// 20 ms frames.
|
||||
bytes_per_frame = 38;
|
||||
timestamps_per_frame = 160;
|
||||
@ -345,28 +346,28 @@ int PayloadSplitter::SplitAudio(PacketList* packet_list,
|
||||
}
|
||||
|
||||
void PayloadSplitter::SplitBySamples(const Packet* packet,
|
||||
int bytes_per_ms,
|
||||
int timestamps_per_ms,
|
||||
size_t bytes_per_ms,
|
||||
uint32_t timestamps_per_ms,
|
||||
PacketList* new_packets) {
|
||||
assert(packet);
|
||||
assert(new_packets);
|
||||
|
||||
int split_size_bytes = packet->payload_length;
|
||||
size_t split_size_bytes = packet->payload_length;
|
||||
|
||||
// Find a "chunk size" >= 20 ms and < 40 ms.
|
||||
int min_chunk_size = bytes_per_ms * 20;
|
||||
size_t min_chunk_size = bytes_per_ms * 20;
|
||||
// Reduce the split size by half as long as |split_size_bytes| is at least
|
||||
// twice the minimum chunk size (so that the resulting size is at least as
|
||||
// large as the minimum chunk size).
|
||||
while (split_size_bytes >= 2 * min_chunk_size) {
|
||||
split_size_bytes >>= 1;
|
||||
}
|
||||
int timestamps_per_chunk =
|
||||
split_size_bytes * timestamps_per_ms / bytes_per_ms;
|
||||
uint32_t timestamps_per_chunk = static_cast<uint32_t>(
|
||||
split_size_bytes * timestamps_per_ms / bytes_per_ms);
|
||||
uint32_t timestamp = packet->header.timestamp;
|
||||
|
||||
uint8_t* payload_ptr = packet->payload;
|
||||
int len = packet->payload_length;
|
||||
size_t len = packet->payload_length;
|
||||
while (len >= (2 * split_size_bytes)) {
|
||||
Packet* new_packet = new Packet;
|
||||
new_packet->payload_length = split_size_bytes;
|
||||
@ -394,22 +395,21 @@ void PayloadSplitter::SplitBySamples(const Packet* packet,
|
||||
}
|
||||
|
||||
int PayloadSplitter::SplitByFrames(const Packet* packet,
|
||||
int bytes_per_frame,
|
||||
int timestamps_per_frame,
|
||||
size_t bytes_per_frame,
|
||||
uint32_t timestamps_per_frame,
|
||||
PacketList* new_packets) {
|
||||
if (packet->payload_length % bytes_per_frame != 0) {
|
||||
return kFrameSplitError;
|
||||
}
|
||||
|
||||
int num_frames = packet->payload_length / bytes_per_frame;
|
||||
if (num_frames == 1) {
|
||||
if (packet->payload_length == bytes_per_frame) {
|
||||
// Special case. Do not split the payload.
|
||||
return kNoSplit;
|
||||
}
|
||||
|
||||
uint32_t timestamp = packet->header.timestamp;
|
||||
uint8_t* payload_ptr = packet->payload;
|
||||
int len = packet->payload_length;
|
||||
size_t len = packet->payload_length;
|
||||
while (len > 0) {
|
||||
assert(len >= bytes_per_frame);
|
||||
Packet* new_packet = new Packet;
|
||||
|
||||
@ -71,16 +71,16 @@ class PayloadSplitter {
|
||||
// Splits the payload in |packet|. The payload is assumed to be from a
|
||||
// sample-based codec.
|
||||
virtual void SplitBySamples(const Packet* packet,
|
||||
int bytes_per_ms,
|
||||
int timestamps_per_ms,
|
||||
size_t bytes_per_ms,
|
||||
uint32_t timestamps_per_ms,
|
||||
PacketList* new_packets);
|
||||
|
||||
// Splits the payload in |packet|. The payload will be split into chunks of
|
||||
// size |bytes_per_frame|, corresponding to a |timestamps_per_frame|
|
||||
// RTP timestamps.
|
||||
virtual int SplitByFrames(const Packet* packet,
|
||||
int bytes_per_frame,
|
||||
int timestamps_per_frame,
|
||||
size_t bytes_per_frame,
|
||||
uint32_t timestamps_per_frame,
|
||||
PacketList* new_packets);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PayloadSplitter);
|
||||
|
||||
@ -27,8 +27,8 @@ using ::testing::ReturnNull;
|
||||
namespace webrtc {
|
||||
|
||||
static const int kRedPayloadType = 100;
|
||||
static const int kPayloadLength = 10;
|
||||
static const int kRedHeaderLength = 4; // 4 bytes RED header.
|
||||
static const size_t kPayloadLength = 10;
|
||||
static const size_t kRedHeaderLength = 4; // 4 bytes RED header.
|
||||
static const uint16_t kSequenceNumber = 0;
|
||||
static const uint32_t kBaseTimestamp = 0x12345678;
|
||||
|
||||
@ -50,7 +50,7 @@ static const uint32_t kBaseTimestamp = 0x12345678;
|
||||
// by the values in array |payload_types| (which must be of length
|
||||
// |num_payloads|). Each redundant payload is |timestamp_offset| samples
|
||||
// "behind" the the previous payload.
|
||||
Packet* CreateRedPayload(int num_payloads,
|
||||
Packet* CreateRedPayload(size_t num_payloads,
|
||||
uint8_t* payload_types,
|
||||
int timestamp_offset) {
|
||||
Packet* packet = new Packet;
|
||||
@ -61,7 +61,7 @@ Packet* CreateRedPayload(int num_payloads,
|
||||
(num_payloads - 1) * (kPayloadLength + kRedHeaderLength);
|
||||
uint8_t* payload = new uint8_t[packet->payload_length];
|
||||
uint8_t* payload_ptr = payload;
|
||||
for (int i = 0; i < num_payloads; ++i) {
|
||||
for (size_t i = 0; i < num_payloads; ++i) {
|
||||
// Write the RED headers.
|
||||
if (i == num_payloads - 1) {
|
||||
// Special case for last payload.
|
||||
@ -82,9 +82,9 @@ Packet* CreateRedPayload(int num_payloads,
|
||||
*payload_ptr = kPayloadLength & 0xFF;
|
||||
++payload_ptr;
|
||||
}
|
||||
for (int i = 0; i < num_payloads; ++i) {
|
||||
for (size_t i = 0; i < num_payloads; ++i) {
|
||||
// Write |i| to all bytes in each payload.
|
||||
memset(payload_ptr, i, kPayloadLength);
|
||||
memset(payload_ptr, static_cast<int>(i), kPayloadLength);
|
||||
payload_ptr += kPayloadLength;
|
||||
}
|
||||
packet->payload = payload;
|
||||
@ -104,7 +104,7 @@ Packet* CreateRedPayload(int num_payloads,
|
||||
// : |
|
||||
// | |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
Packet* CreateOpusFecPacket(uint8_t payload_type, int payload_length,
|
||||
Packet* CreateOpusFecPacket(uint8_t payload_type, size_t payload_length,
|
||||
uint8_t payload_value) {
|
||||
Packet* packet = new Packet;
|
||||
packet->header.payloadType = payload_type;
|
||||
@ -120,7 +120,7 @@ Packet* CreateOpusFecPacket(uint8_t payload_type, int payload_length,
|
||||
}
|
||||
|
||||
// Create a packet with all payload bytes set to |payload_value|.
|
||||
Packet* CreatePacket(uint8_t payload_type, int payload_length,
|
||||
Packet* CreatePacket(uint8_t payload_type, size_t payload_length,
|
||||
uint8_t payload_value) {
|
||||
Packet* packet = new Packet;
|
||||
packet->header.payloadType = payload_type;
|
||||
@ -135,7 +135,7 @@ Packet* CreatePacket(uint8_t payload_type, int payload_length,
|
||||
|
||||
// Checks that |packet| has the attributes given in the remaining parameters.
|
||||
void VerifyPacket(const Packet* packet,
|
||||
int payload_length,
|
||||
size_t payload_length,
|
||||
uint8_t payload_type,
|
||||
uint16_t sequence_number,
|
||||
uint32_t timestamp,
|
||||
@ -147,7 +147,7 @@ void VerifyPacket(const Packet* packet,
|
||||
EXPECT_EQ(timestamp, packet->header.timestamp);
|
||||
EXPECT_EQ(primary, packet->primary);
|
||||
ASSERT_FALSE(packet->payload == NULL);
|
||||
for (int i = 0; i < packet->payload_length; ++i) {
|
||||
for (size_t i = 0; i < packet->payload_length; ++i) {
|
||||
EXPECT_EQ(payload_value, packet->payload[i]);
|
||||
}
|
||||
}
|
||||
@ -295,7 +295,7 @@ TEST(RedPayloadSplitter, TwoPacketsThreePayloads) {
|
||||
// found in the list (which is PCMu).
|
||||
TEST(RedPayloadSplitter, CheckRedPayloads) {
|
||||
PacketList packet_list;
|
||||
for (int i = 0; i <= 3; ++i) {
|
||||
for (uint8_t i = 0; i <= 3; ++i) {
|
||||
// Create packet with payload type |i|, payload length 10 bytes, all 0.
|
||||
Packet* packet = CreatePacket(i, 10, 0);
|
||||
packet_list.push_back(packet);
|
||||
@ -357,7 +357,7 @@ TEST(AudioPayloadSplitter, NonSplittable) {
|
||||
// Set up packets with different RTP payload types. The actual values do not
|
||||
// matter, since we are mocking the decoder database anyway.
|
||||
PacketList packet_list;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
for (uint8_t i = 0; i < 6; ++i) {
|
||||
// Let the payload type be |i|, and the payload value 10 * |i|.
|
||||
packet_list.push_back(CreatePacket(i, kPayloadLength, 10 * i));
|
||||
}
|
||||
@ -415,7 +415,7 @@ TEST(AudioPayloadSplitter, NonSplittable) {
|
||||
TEST(AudioPayloadSplitter, UnknownPayloadType) {
|
||||
PacketList packet_list;
|
||||
static const uint8_t kPayloadType = 17; // Just a random number.
|
||||
int kPayloadLengthBytes = 4711; // Random number.
|
||||
size_t kPayloadLengthBytes = 4711; // Random number.
|
||||
packet_list.push_back(CreatePacket(kPayloadType, kPayloadLengthBytes, 0));
|
||||
|
||||
MockDecoderDatabase decoder_database;
|
||||
@ -502,7 +502,7 @@ class SplitBySamplesTest : public ::testing::TestWithParam<NetEqDecoder> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int bytes_per_ms_;
|
||||
size_t bytes_per_ms_;
|
||||
int samples_per_ms_;
|
||||
NetEqDecoder decoder_type_;
|
||||
};
|
||||
@ -514,7 +514,7 @@ TEST_P(SplitBySamplesTest, PayloadSizes) {
|
||||
for (int payload_size_ms = 10; payload_size_ms <= 60; payload_size_ms += 10) {
|
||||
// The payload values are set to be the same as the payload_size, so that
|
||||
// one can distinguish from which packet the split payloads come from.
|
||||
int payload_size_bytes = payload_size_ms * bytes_per_ms_;
|
||||
size_t payload_size_bytes = payload_size_ms * bytes_per_ms_;
|
||||
packet_list.push_back(CreatePacket(kPayloadType, payload_size_bytes,
|
||||
payload_size_ms));
|
||||
}
|
||||
@ -548,7 +548,7 @@ TEST_P(SplitBySamplesTest, PayloadSizes) {
|
||||
PacketList::iterator it = packet_list.begin();
|
||||
int i = 0;
|
||||
while (it != packet_list.end()) {
|
||||
int length_bytes = expected_size_ms[i] * bytes_per_ms_;
|
||||
size_t length_bytes = expected_size_ms[i] * bytes_per_ms_;
|
||||
uint32_t expected_timestamp = kBaseTimestamp +
|
||||
expected_timestamp_offset_ms[i] * samples_per_ms_;
|
||||
VerifyPacket((*it), length_bytes, kPayloadType, kSequenceNumber,
|
||||
@ -583,7 +583,7 @@ class SplitIlbcTest : public ::testing::TestWithParam<std::pair<int, int> > {
|
||||
}
|
||||
size_t num_frames_;
|
||||
int frame_length_ms_;
|
||||
int frame_length_bytes_;
|
||||
size_t frame_length_bytes_;
|
||||
};
|
||||
|
||||
// Test splitting sample-based payloads.
|
||||
@ -591,10 +591,10 @@ TEST_P(SplitIlbcTest, NumFrames) {
|
||||
PacketList packet_list;
|
||||
static const uint8_t kPayloadType = 17; // Just a random number.
|
||||
const int frame_length_samples = frame_length_ms_ * 8;
|
||||
int payload_length_bytes = frame_length_bytes_ * num_frames_;
|
||||
size_t payload_length_bytes = frame_length_bytes_ * num_frames_;
|
||||
Packet* packet = CreatePacket(kPayloadType, payload_length_bytes, 0);
|
||||
// Fill payload with increasing integers {0, 1, 2, ...}.
|
||||
for (int i = 0; i < packet->payload_length; ++i) {
|
||||
for (size_t i = 0; i < packet->payload_length; ++i) {
|
||||
packet->payload[i] = static_cast<uint8_t>(i);
|
||||
}
|
||||
packet_list.push_back(packet);
|
||||
@ -624,7 +624,7 @@ TEST_P(SplitIlbcTest, NumFrames) {
|
||||
EXPECT_EQ(kSequenceNumber, packet->header.sequenceNumber);
|
||||
EXPECT_EQ(true, packet->primary);
|
||||
ASSERT_FALSE(packet->payload == NULL);
|
||||
for (int i = 0; i < packet->payload_length; ++i) {
|
||||
for (size_t i = 0; i < packet->payload_length; ++i) {
|
||||
EXPECT_EQ(payload_value, packet->payload[i]);
|
||||
++payload_value;
|
||||
}
|
||||
@ -661,7 +661,7 @@ INSTANTIATE_TEST_CASE_P(
|
||||
TEST(IlbcPayloadSplitter, TooLargePayload) {
|
||||
PacketList packet_list;
|
||||
static const uint8_t kPayloadType = 17; // Just a random number.
|
||||
int kPayloadLengthBytes = 950;
|
||||
size_t kPayloadLengthBytes = 950;
|
||||
Packet* packet = CreatePacket(kPayloadType, kPayloadLengthBytes, 0);
|
||||
packet_list.push_back(packet);
|
||||
|
||||
@ -692,7 +692,7 @@ TEST(IlbcPayloadSplitter, TooLargePayload) {
|
||||
TEST(IlbcPayloadSplitter, UnevenPayload) {
|
||||
PacketList packet_list;
|
||||
static const uint8_t kPayloadType = 17; // Just a random number.
|
||||
int kPayloadLengthBytes = 39; // Not an even number of frames.
|
||||
size_t kPayloadLengthBytes = 39; // Not an even number of frames.
|
||||
Packet* packet = CreatePacket(kPayloadType, kPayloadLengthBytes, 0);
|
||||
packet_list.push_back(packet);
|
||||
|
||||
@ -744,7 +744,7 @@ TEST(FecPayloadSplitter, MixedPayload) {
|
||||
packet = packet_list.front();
|
||||
EXPECT_EQ(0, packet->header.payloadType);
|
||||
EXPECT_EQ(kBaseTimestamp - 20 * 48, packet->header.timestamp);
|
||||
EXPECT_EQ(10, packet->payload_length);
|
||||
EXPECT_EQ(10U, packet->payload_length);
|
||||
EXPECT_FALSE(packet->primary);
|
||||
delete [] packet->payload;
|
||||
delete packet;
|
||||
@ -754,7 +754,7 @@ TEST(FecPayloadSplitter, MixedPayload) {
|
||||
packet = packet_list.front();
|
||||
EXPECT_EQ(0, packet->header.payloadType);
|
||||
EXPECT_EQ(kBaseTimestamp, packet->header.timestamp);
|
||||
EXPECT_EQ(10, packet->payload_length);
|
||||
EXPECT_EQ(10U, packet->payload_length);
|
||||
EXPECT_TRUE(packet->primary);
|
||||
delete [] packet->payload;
|
||||
delete packet;
|
||||
|
||||
@ -329,7 +329,7 @@ uint8_t * NETEQTEST_RTPpacket::payload() const
|
||||
}
|
||||
}
|
||||
|
||||
int16_t NETEQTEST_RTPpacket::payloadLen()
|
||||
size_t NETEQTEST_RTPpacket::payloadLen()
|
||||
{
|
||||
parseHeader();
|
||||
return _payloadLen;
|
||||
@ -752,7 +752,7 @@ void NETEQTEST_RTPpacket::splitStereoSample(NETEQTEST_RTPpacket* slaveRtp,
|
||||
int stride)
|
||||
{
|
||||
if(!_payloadPtr || !slaveRtp || !slaveRtp->_payloadPtr
|
||||
|| _payloadLen <= 0 || slaveRtp->_memSize < _memSize)
|
||||
|| _payloadLen == 0 || slaveRtp->_memSize < _memSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -761,7 +761,7 @@ void NETEQTEST_RTPpacket::splitStereoSample(NETEQTEST_RTPpacket* slaveRtp,
|
||||
uint8_t *writeDataPtr = _payloadPtr;
|
||||
uint8_t *slaveData = slaveRtp->_payloadPtr;
|
||||
|
||||
while (readDataPtr - _payloadPtr < _payloadLen)
|
||||
while (readDataPtr - _payloadPtr < static_cast<ptrdiff_t>(_payloadLen))
|
||||
{
|
||||
// master data
|
||||
for (int ix = 0; ix < stride; ix++) {
|
||||
@ -786,7 +786,7 @@ void NETEQTEST_RTPpacket::splitStereoSample(NETEQTEST_RTPpacket* slaveRtp,
|
||||
void NETEQTEST_RTPpacket::splitStereoFrame(NETEQTEST_RTPpacket* slaveRtp)
|
||||
{
|
||||
if(!_payloadPtr || !slaveRtp || !slaveRtp->_payloadPtr
|
||||
|| _payloadLen <= 0 || slaveRtp->_memSize < _memSize)
|
||||
|| _payloadLen == 0 || slaveRtp->_memSize < _memSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -799,7 +799,7 @@ void NETEQTEST_RTPpacket::splitStereoFrame(NETEQTEST_RTPpacket* slaveRtp)
|
||||
void NETEQTEST_RTPpacket::splitStereoDouble(NETEQTEST_RTPpacket* slaveRtp)
|
||||
{
|
||||
if(!_payloadPtr || !slaveRtp || !slaveRtp->_payloadPtr
|
||||
|| _payloadLen <= 0 || slaveRtp->_memSize < _memSize)
|
||||
|| _payloadLen == 0 || slaveRtp->_memSize < _memSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -868,7 +868,7 @@ void NETEQTEST_RTPpacket::scramblePayload(void)
|
||||
{
|
||||
parseHeader();
|
||||
|
||||
for (int i = 0; i < _payloadLen; ++i)
|
||||
for (size_t i = 0; i < _payloadLen; ++i)
|
||||
{
|
||||
_payloadPtr[i] = static_cast<uint8_t>(rand());
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public:
|
||||
const webrtc::WebRtcRTPHeader* RTPinfo() const;
|
||||
uint8_t * datagram() const;
|
||||
uint8_t * payload() const;
|
||||
int16_t payloadLen();
|
||||
size_t payloadLen();
|
||||
int16_t dataLen() const;
|
||||
bool isParsed() const;
|
||||
bool isLost() const;
|
||||
@ -73,7 +73,7 @@ public:
|
||||
uint8_t * _payloadPtr;
|
||||
int _memSize;
|
||||
int16_t _datagramLen;
|
||||
int16_t _payloadLen;
|
||||
size_t _payloadLen;
|
||||
webrtc::WebRtcRTPHeader _rtpInfo;
|
||||
bool _rtpParsed;
|
||||
uint32_t _receiveTime;
|
||||
|
||||
@ -64,9 +64,9 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms,
|
||||
const int16_t* input_samples = audio_loop.GetNextBlock();
|
||||
if (!input_samples) exit(1);
|
||||
uint8_t input_payload[kInputBlockSizeSamples * sizeof(int16_t)];
|
||||
int payload_len = WebRtcPcm16b_Encode(const_cast<int16_t*>(input_samples),
|
||||
kInputBlockSizeSamples,
|
||||
input_payload);
|
||||
size_t payload_len = WebRtcPcm16b_Encode(const_cast<int16_t*>(input_samples),
|
||||
kInputBlockSizeSamples,
|
||||
input_payload);
|
||||
assert(payload_len == kInputBlockSizeSamples * sizeof(int16_t));
|
||||
|
||||
// Main loop.
|
||||
|
||||
@ -118,7 +118,7 @@ class NetEqQualityTest : public ::testing::Test {
|
||||
// Expected output number of samples per channel in a frame.
|
||||
const int out_size_samples_;
|
||||
|
||||
int payload_size_bytes_;
|
||||
size_t payload_size_bytes_;
|
||||
int max_payload_bytes_;
|
||||
|
||||
scoped_ptr<InputAudioFile> in_file_;
|
||||
@ -134,7 +134,7 @@ class NetEqQualityTest : public ::testing::Test {
|
||||
scoped_ptr<int16_t[]> out_data_;
|
||||
WebRtcRTPHeader rtp_header_;
|
||||
|
||||
long total_payload_size_bytes_;
|
||||
size_t total_payload_size_bytes_;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
|
||||
@ -286,7 +286,7 @@ int main(int argc, char* argv[]) {
|
||||
int error =
|
||||
neteq->InsertPacket(rtp_header,
|
||||
payload_ptr,
|
||||
static_cast<int>(payload_len),
|
||||
payload_len,
|
||||
packet->time_ms() * sample_rate_hz / 1000);
|
||||
if (error != NetEq::kOK) {
|
||||
if (neteq->LastError() == NetEq::kUnknownRtpPayloadType) {
|
||||
|
||||
Reference in New Issue
Block a user