AcmReceiver::InsertPacket and NetEq::InsertPacket: Take ArrayView arguments

Instead of separate pointer and size arguments.

Review URL: https://codereview.webrtc.org/1429943004

Cr-Commit-Position: refs/heads/master@{#10606}
This commit is contained in:
kwiberg
2015-11-11 10:34:00 -08:00
committed by Commit bot
parent 91d926038f
commit ee2bac26dd
17 changed files with 132 additions and 157 deletions

View File

@ -163,15 +163,14 @@ int AcmReceiver::current_sample_rate_hz() const {
}
int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header,
const uint8_t* incoming_payload,
size_t length_payload) {
rtc::ArrayView<const uint8_t> incoming_payload) {
uint32_t receive_timestamp = 0;
const RTPHeader* header = &rtp_header.header; // Just a shorthand.
{
CriticalSectionScoped lock(crit_sect_.get());
const Decoder* decoder = RtpHeaderToDecoder(*header, incoming_payload);
const Decoder* decoder = RtpHeaderToDecoder(*header, incoming_payload[0]);
if (!decoder) {
LOG_F(LS_ERROR) << "Payload-type "
<< static_cast<int>(header->payloadType)
@ -197,8 +196,8 @@ int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header,
} // |crit_sect_| is released.
if (neteq_->InsertPacket(rtp_header, incoming_payload, length_payload,
receive_timestamp) < 0) {
if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_timestamp) <
0) {
LOG(LERROR) << "AcmReceiver::InsertPacket "
<< static_cast<int>(header->payloadType)
<< " Failed to insert packet";
@ -512,14 +511,14 @@ void AcmReceiver::ResetInitialDelay() {
const AcmReceiver::Decoder* AcmReceiver::RtpHeaderToDecoder(
const RTPHeader& rtp_header,
const uint8_t* payload) const {
uint8_t payload_type) const {
auto it = decoders_.find(rtp_header.payloadType);
const auto red_index =
RentACodec::CodecIndexFromId(RentACodec::CodecId::kRED);
if (red_index && // This ensures that RED is defined in WebRTC.
it != decoders_.end() && it->second.acm_codec_id == *red_index) {
// This is a RED packet, get the payload of the audio codec.
it = decoders_.find(payload[0] & 0x7F);
it = decoders_.find(payload_type & 0x7F);
}
// Check if the payload is registered.

View File

@ -14,6 +14,7 @@
#include <map>
#include <vector>
#include "webrtc/base/array_view.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/common_audio/vad/include/webrtc_vad.h"
@ -65,8 +66,7 @@ class AcmReceiver {
// <0 if NetEq returned an error.
//
int InsertPacket(const WebRtcRTPHeader& rtp_header,
const uint8_t* incoming_payload,
size_t length_payload);
rtc::ArrayView<const uint8_t> incoming_payload);
//
// Asks NetEq for 10 milliseconds of decoded audio.
@ -278,7 +278,7 @@ class AcmReceiver {
private:
const Decoder* RtpHeaderToDecoder(const RTPHeader& rtp_header,
const uint8_t* payload) const
uint8_t payload_type) const
EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
uint32_t NowInTimestamp(int decoder_sampling_rate) const;

View File

@ -141,8 +141,9 @@ class AcmReceiverTestOldApi : public AudioPacketizationCallback,
rtp_header_.type.Audio.isCNG = true;
rtp_header_.header.timestamp = timestamp;
int ret_val = receiver_->InsertPacket(rtp_header_, payload_data,
payload_len_bytes);
int ret_val = receiver_->InsertPacket(
rtp_header_,
rtc::ArrayView<const uint8_t>(payload_data, payload_len_bytes));
if (ret_val < 0) {
assert(false);
return -1;

View File

@ -611,7 +611,9 @@ int AudioCodingModuleImpl::ReceiveCodec(CodecInst* current_codec) const {
int AudioCodingModuleImpl::IncomingPacket(const uint8_t* incoming_payload,
const size_t payload_length,
const WebRtcRTPHeader& rtp_header) {
return receiver_.InsertPacket(rtp_header, incoming_payload, payload_length);
return receiver_.InsertPacket(
rtp_header,
rtc::ArrayView<const uint8_t>(incoming_payload, payload_length));
}
// Minimum playout delay (Used for lip-sync).

View File

@ -147,8 +147,7 @@ class NetEq {
// the same tick rate as the RTP timestamp of the current payload.
// Returns 0 on success, -1 on failure.
virtual int InsertPacket(const WebRtcRTPHeader& rtp_header,
const uint8_t* payload,
size_t length_bytes,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp) = 0;
// Inserts a sync-packet into packet queue. Sync-packets are decoded to

View File

@ -105,7 +105,8 @@ class NetEqExternalDecoderUnitTest : public test::NetEqExternalDecoderTest {
uint32_t time_now = 0;
for (int k = 0; k < num_loops; ++k) {
while (time_now >= next_arrival_time) {
InsertPacket(rtp_header_, encoded_, payload_size_bytes_,
InsertPacket(rtp_header_, rtc::ArrayView<const uint8_t>(
encoded_, payload_size_bytes_),
next_arrival_time);
// Get next input packet.
do {
@ -124,17 +125,14 @@ class NetEqExternalDecoderUnitTest : public test::NetEqExternalDecoderTest {
}
}
void InsertPacket(WebRtcRTPHeader rtp_header, const uint8_t* payload,
size_t payload_size_bytes,
void InsertPacket(WebRtcRTPHeader rtp_header,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp) override {
EXPECT_CALL(*external_decoder_,
IncomingPacket(_,
payload_size_bytes,
rtp_header.header.sequenceNumber,
rtp_header.header.timestamp,
receive_timestamp));
EXPECT_CALL(
*external_decoder_,
IncomingPacket(_, payload.size(), rtp_header.header.sequenceNumber,
rtp_header.header.timestamp, receive_timestamp));
NetEqExternalDecoderTest::InsertPacket(rtp_header, payload,
payload_size_bytes,
receive_timestamp);
}
@ -210,18 +208,15 @@ class NetEqExternalVsInternalDecoderTest : public NetEqExternalDecoderUnitTest,
}
}
void InsertPacket(WebRtcRTPHeader rtp_header, const uint8_t* payload,
size_t payload_size_bytes,
void InsertPacket(WebRtcRTPHeader rtp_header,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp) override {
// Insert packet in internal decoder.
ASSERT_EQ(
NetEq::kOK,
neteq_internal_->InsertPacket(
rtp_header, payload, payload_size_bytes, receive_timestamp));
ASSERT_EQ(NetEq::kOK, neteq_internal_->InsertPacket(rtp_header, payload,
receive_timestamp));
// Insert packet in external decoder instance.
NetEqExternalDecoderUnitTest::InsertPacket(rtp_header, payload,
payload_size_bytes,
receive_timestamp);
}

View File

@ -121,17 +121,16 @@ NetEqImpl::NetEqImpl(const NetEq::Config& config,
NetEqImpl::~NetEqImpl() = default;
int NetEqImpl::InsertPacket(const WebRtcRTPHeader& rtp_header,
const uint8_t* payload,
size_t length_bytes,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp) {
CriticalSectionScoped lock(crit_sect_.get());
LOG(LS_VERBOSE) << "InsertPacket: ts=" << rtp_header.header.timestamp <<
", sn=" << rtp_header.header.sequenceNumber <<
", pt=" << static_cast<int>(rtp_header.header.payloadType) <<
", ssrc=" << rtp_header.header.ssrc <<
", len=" << length_bytes;
int error = InsertPacketInternal(rtp_header, payload, length_bytes,
receive_timestamp, false);
LOG(LS_VERBOSE) << "InsertPacket: ts=" << rtp_header.header.timestamp
<< ", sn=" << rtp_header.header.sequenceNumber
<< ", pt=" << static_cast<int>(rtp_header.header.payloadType)
<< ", ssrc=" << rtp_header.header.ssrc
<< ", len=" << payload.size();
int error =
InsertPacketInternal(rtp_header, payload, receive_timestamp, false);
if (error != 0) {
error_code_ = error;
return kFail;
@ -149,8 +148,8 @@ int NetEqImpl::InsertSyncPacket(const WebRtcRTPHeader& rtp_header,
", ssrc=" << rtp_header.header.ssrc;
const uint8_t kSyncPayload[] = { 's', 'y', 'n', 'c' };
int error = InsertPacketInternal(
rtp_header, kSyncPayload, sizeof(kSyncPayload), receive_timestamp, true);
int error =
InsertPacketInternal(rtp_header, kSyncPayload, receive_timestamp, true);
if (error != 0) {
error_code_ = error;
@ -445,12 +444,11 @@ const SyncBuffer* NetEqImpl::sync_buffer_for_test() const {
// Methods below this line are private.
int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
const uint8_t* payload,
size_t length_bytes,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp,
bool is_sync_packet) {
if (!payload) {
LOG_F(LS_ERROR) << "payload == NULL";
if (payload.empty()) {
LOG_F(LS_ERROR) << "payload is empty";
return kInvalidPointer;
}
// Sanity checks for sync-packets.
@ -486,7 +484,7 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
packet->header.timestamp = rtp_header.header.timestamp;
packet->header.ssrc = rtp_header.header.ssrc;
packet->header.numCSRCs = 0;
packet->payload_length = length_bytes;
packet->payload_length = payload.size();
packet->primary = true;
packet->waiting_time = 0;
packet->payload = new uint8_t[packet->payload_length];
@ -494,8 +492,8 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
if (!packet->payload) {
LOG_F(LS_ERROR) << "Payload pointer is NULL.";
}
assert(payload); // Already checked above.
memcpy(packet->payload, payload, packet->payload_length);
assert(!payload.empty()); // Already checked above.
memcpy(packet->payload, payload.data(), packet->payload_length);
// Insert packet in a packet list.
packet_list.push_back(packet);
// Save main payloads header for later.

View File

@ -79,8 +79,7 @@ class NetEqImpl : public webrtc::NetEq {
// the same tick rate as the RTP timestamp of the current payload.
// Returns 0 on success, -1 on failure.
int InsertPacket(const WebRtcRTPHeader& rtp_header,
const uint8_t* payload,
size_t length_bytes,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp) override;
// Inserts a sync-packet into packet queue. Sync-packets are decoded to
@ -207,8 +206,7 @@ class NetEqImpl : public webrtc::NetEq {
// above. Returns 0 on success, otherwise an error code.
// TODO(hlundin): Merge this with InsertPacket above?
int InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
const uint8_t* payload,
size_t length_bytes,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp,
bool is_sync_packet)
EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);

View File

@ -359,13 +359,12 @@ TEST_F(NetEqImplTest, InsertPacket) {
.WillRepeatedly(Return(PayloadSplitter::kOK));
// Insert first packet.
neteq_->InsertPacket(rtp_header, payload, kPayloadLength, kFirstReceiveTime);
neteq_->InsertPacket(rtp_header, payload, kFirstReceiveTime);
// Insert second packet.
rtp_header.header.timestamp += 160;
rtp_header.header.sequenceNumber += 1;
neteq_->InsertPacket(rtp_header, payload, kPayloadLength,
kFirstReceiveTime + 155);
neteq_->InsertPacket(rtp_header, payload, kFirstReceiveTime + 155);
}
TEST_F(NetEqImplTest, InsertPacketsUntilBufferIsFull) {
@ -389,8 +388,7 @@ TEST_F(NetEqImplTest, InsertPacketsUntilBufferIsFull) {
// Insert packets. The buffer should not flush.
for (size_t i = 1; i <= config_.max_packets_in_buffer; ++i) {
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
rtp_header.header.timestamp += kPayloadLengthSamples;
rtp_header.header.sequenceNumber += 1;
EXPECT_EQ(i, packet_buffer_->NumPacketsInBuffer());
@ -399,8 +397,7 @@ TEST_F(NetEqImplTest, InsertPacketsUntilBufferIsFull) {
// Insert one more packet and make sure the buffer got flushed. That is, it
// should only hold one single packet.
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
EXPECT_EQ(1u, packet_buffer_->NumPacketsInBuffer());
const RTPHeader* test_header = packet_buffer_->NextRtpHeader();
EXPECT_EQ(rtp_header.header.timestamp, test_header->timestamp);
@ -463,8 +460,7 @@ TEST_F(NetEqImplTest, VerifyTimestampPropagation) {
// Insert one packet.
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
// Pull audio once.
const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
@ -543,8 +539,7 @@ TEST_F(NetEqImplTest, ReorderedPacket) {
// Insert one packet.
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
// Pull audio once.
const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateHz / 1000);
@ -566,14 +561,12 @@ TEST_F(NetEqImplTest, ReorderedPacket) {
rtp_header.header.timestamp -= kPayloadLengthSamples;
payload[0] = 1;
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
rtp_header.header.sequenceNumber += 2;
rtp_header.header.timestamp += 2 * kPayloadLengthSamples;
payload[0] = 2;
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
// Expect only the second packet to be decoded (the one with "2" as the first
// payload byte).
@ -622,8 +615,7 @@ TEST_F(NetEqImplTest, FirstPacketUnknown) {
// Insert one packet. Note that we have not registered any payload type, so
// this packet will be rejected.
EXPECT_EQ(NetEq::kFail,
neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError());
// Pull audio once.
@ -649,8 +641,7 @@ TEST_F(NetEqImplTest, FirstPacketUnknown) {
rtp_header.header.sequenceNumber++;
rtp_header.header.timestamp += kPayloadLengthSamples;
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
EXPECT_EQ(i + 1, packet_buffer_->NumPacketsInBuffer());
}
@ -730,16 +721,14 @@ TEST_F(NetEqImplTest, CodecInternalCng) {
// Insert one packet (decoder will return speech).
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
// Insert second packet (decoder will return CNG).
payload[0] = 1;
rtp_header.header.sequenceNumber++;
rtp_header.header.timestamp += kPayloadLengthSamples;
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz);
int16_t output[kMaxOutputSize];
@ -785,8 +774,7 @@ TEST_F(NetEqImplTest, CodecInternalCng) {
rtp_header.header.sequenceNumber += 2;
rtp_header.header.timestamp += 2 * kPayloadLengthSamples;
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
for (size_t i = 6; i < 8; ++i) {
ASSERT_EQ(kMaxOutputSize, samples_per_channel);
@ -871,8 +859,7 @@ TEST_F(NetEqImplTest, UnsupportedDecoder) {
// Insert one packet.
payload[0] = kFirstPayloadValue; // This will make Decode() fail.
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
// Insert another packet.
payload[0] = kSecondPayloadValue; // This will make Decode() successful.
@ -881,8 +868,7 @@ TEST_F(NetEqImplTest, UnsupportedDecoder) {
// the second packet get decoded.
rtp_header.header.timestamp += 3 * kPayloadLengthSamples;
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, kPayloadLengthBytes, kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
const size_t kMaxOutputSize =
static_cast<size_t>(10 * kSampleRateHz / 1000 * kChannels);
@ -932,8 +918,7 @@ TEST_F(NetEqImplTest, FloodBufferAndGetNetworkStats) {
for (size_t i = 0; i <= config_.max_packets_in_buffer; ++i) {
EXPECT_EQ(i, packet_buffer_->NumPacketsInBuffer());
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
rtp_header.header.timestamp +=
rtc::checked_cast<uint32_t>(kPayloadLengthSamples);
++rtp_header.header.sequenceNumber;
@ -987,8 +972,7 @@ TEST_F(NetEqImplTest, DecodedPayloadTooShort) {
// Insert one packet.
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
EXPECT_EQ(5u, neteq_->sync_buffer_for_test()->FutureLength());
@ -1086,8 +1070,7 @@ TEST_F(NetEqImplTest, DecodingError) {
rtp_header.header.sequenceNumber += 1;
rtp_header.header.timestamp += kFrameLengthSamples;
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
}
// Pull audio.
@ -1208,8 +1191,7 @@ TEST_F(NetEqImplTest, DecodingErrorDuringInternalCng) {
rtp_header.header.sequenceNumber += 1;
rtp_header.header.timestamp += kFrameLengthSamples;
EXPECT_EQ(NetEq::kOK,
neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
kReceiveTime));
neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
}
// Pull audio.

View File

@ -191,8 +191,7 @@ struct NetEqNetworkStatsCheck {
frame_size_samples_,
&rtp_header_);
if (!Lost(next_send_time)) {
InsertPacket(rtp_header_, payload_, kPayloadSizeByte,
next_send_time);
InsertPacket(rtp_header_, payload_, next_send_time);
}
}
GetOutputAudio(kMaxOutputSize, output_, &output_type);

View File

@ -196,13 +196,15 @@ class NetEqStereoTest : public ::testing::TestWithParam<TestParameters> {
while (time_now >= next_arrival_time) {
// Insert packet in mono instance.
ASSERT_EQ(NetEq::kOK,
neteq_mono_->InsertPacket(rtp_header_mono_, encoded_,
payload_size_bytes_,
neteq_mono_->InsertPacket(rtp_header_mono_,
rtc::ArrayView<const uint8_t>(
encoded_, payload_size_bytes_),
next_arrival_time));
// Insert packet in multi-channel instance.
ASSERT_EQ(NetEq::kOK,
neteq_->InsertPacket(rtp_header_, encoded_multi_channel_,
multi_payload_size_bytes_,
ASSERT_EQ(NetEq::kOK, neteq_->InsertPacket(
rtp_header_, rtc::ArrayView<const uint8_t>(
encoded_multi_channel_,
multi_payload_size_bytes_),
next_arrival_time));
// Get next input packets (mono and multi-channel).
do {

View File

@ -343,10 +343,11 @@ void NetEqDecodingTest::Process(size_t* out_len) {
WebRtcRTPHeader rtp_header;
packet_->ConvertHeader(&rtp_header);
ASSERT_EQ(0, neteq_->InsertPacket(
rtp_header, packet_->payload(),
packet_->payload_length_bytes(),
static_cast<uint32_t>(
packet_->time_ms() * (output_sample_rate_ / 1000))));
rtp_header,
rtc::ArrayView<const uint8_t>(
packet_->payload(), packet_->payload_length_bytes()),
static_cast<uint32_t>(packet_->time_ms() *
(output_sample_rate_ / 1000))));
}
// Get next packet.
packet_.reset(rtp_source_->NextPacket());
@ -495,17 +496,14 @@ TEST_F(NetEqDecodingTestFaxMode, TestFrameWaitingTimeStatistics) {
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};
const uint8_t payload[kPayloadBytes] = {0};
WebRtcRTPHeader rtp_info;
rtp_info.header.sequenceNumber = i;
rtp_info.header.timestamp = i * kSamples;
rtp_info.header.ssrc = 0x1234; // Just an arbitrary SSRC.
rtp_info.header.payloadType = 94; // PCM16b WB codec.
rtp_info.header.markerBit = 0;
ASSERT_EQ(0, neteq_->InsertPacket(
rtp_info,
reinterpret_cast<uint8_t*>(payload),
kPayloadBytes, 0));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
}
// Pull out all data.
for (size_t i = 0; i < num_frames; ++i) {
@ -549,7 +547,7 @@ TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimeNegative) {
uint8_t payload[kPayloadBytes] = {0};
WebRtcRTPHeader rtp_info;
PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info);
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
++frame_index;
}
@ -580,7 +578,7 @@ TEST_F(NetEqDecodingTest, TestAverageInterArrivalTimePositive) {
uint8_t payload[kPayloadBytes] = {0};
WebRtcRTPHeader rtp_info;
PopulateRtpInfo(frame_index, frame_index * kSamples, &rtp_info);
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
++frame_index;
}
@ -623,7 +621,7 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
uint8_t payload[kPayloadBytes] = {0};
WebRtcRTPHeader rtp_info;
PopulateRtpInfo(seq_no, timestamp, &rtp_info);
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
++seq_no;
timestamp += kSamples;
next_input_time_ms += static_cast<double>(kFrameSizeMs) * drift_factor;
@ -649,7 +647,9 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
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));
ASSERT_EQ(0, neteq_->InsertPacket(
rtp_info,
rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
++seq_no;
timestamp += kCngPeriodSamples;
next_input_time_ms += static_cast<double>(kCngPeriodMs) * drift_factor;
@ -696,7 +696,9 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
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));
ASSERT_EQ(0, neteq_->InsertPacket(
rtp_info,
rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
++seq_no;
timestamp += kCngPeriodSamples;
next_input_time_ms += kCngPeriodMs * drift_factor;
@ -712,7 +714,7 @@ void NetEqDecodingTest::LongCngWithClockDrift(double drift_factor,
uint8_t payload[kPayloadBytes] = {0};
WebRtcRTPHeader rtp_info;
PopulateRtpInfo(seq_no, timestamp, &rtp_info);
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
++seq_no;
timestamp += kSamples;
next_input_time_ms += kFrameSizeMs * drift_factor;
@ -823,8 +825,7 @@ TEST_F(NetEqDecodingTest, UnknownPayloadType) {
WebRtcRTPHeader rtp_info;
PopulateRtpInfo(0, 0, &rtp_info);
rtp_info.header.payloadType = 1; // Not registered as a decoder.
EXPECT_EQ(NetEq::kFail,
neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
EXPECT_EQ(NetEq::kFail, neteq_->InsertPacket(rtp_info, payload, 0));
EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError());
}
@ -840,7 +841,7 @@ TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(IF_ISAC(DecoderError))) {
WebRtcRTPHeader rtp_info;
PopulateRtpInfo(0, 0, &rtp_info);
rtp_info.header.payloadType = 103; // iSAC, but the payload is invalid.
EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
NetEqOutputType type;
// Set all of |out_data_| to 1, and verify that it was set to 0 by the call
// to GetAudio.
@ -947,8 +948,8 @@ class NetEqBgnTest : public NetEqDecodingTest {
number_channels = 0;
samples_per_channel = 0;
ASSERT_EQ(0,
neteq_->InsertPacket(rtp_info, payload, enc_len_bytes,
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView<const uint8_t>(
payload, enc_len_bytes),
receive_timestamp));
ASSERT_EQ(0,
neteq_->GetAudio(kBlockSize32kHz,
@ -1108,8 +1109,7 @@ TEST_F(NetEqDecodingTest, IF_ISAC(SyncPacketInsert)) {
// Payload length of 10 ms PCM16 16 kHz.
const size_t kPayloadBytes = kBlockSize16kHz * sizeof(int16_t);
uint8_t payload[kPayloadBytes] = {0};
ASSERT_EQ(0, neteq_->InsertPacket(
rtp_info, payload, kPayloadBytes, receive_timestamp));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
// Next packet. Last packet contained 10 ms audio.
rtp_info.header.sequenceNumber++;
@ -1171,8 +1171,7 @@ TEST_F(NetEqDecodingTest, SyncPacketDecode) {
size_t samples_per_channel;
uint32_t receive_timestamp = 0;
for (int n = 0; n < 100; ++n) {
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes,
receive_timestamp));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded,
&samples_per_channel, &num_channels,
&output_type));
@ -1207,8 +1206,7 @@ TEST_F(NetEqDecodingTest, SyncPacketDecode) {
// We insert regular packets, if sync packet are not correctly buffered then
// network statistics would show some packet loss.
for (int n = 0; n <= algorithmic_frame_delay + 10; ++n) {
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes,
receive_timestamp));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded,
&samples_per_channel, &num_channels,
&output_type));
@ -1250,8 +1248,7 @@ TEST_F(NetEqDecodingTest, SyncPacketBufferSizeAndOverridenByNetworkPackets) {
uint32_t receive_timestamp = 0;
int algorithmic_frame_delay = algorithmic_delay_ms_ / 10 + 1;
for (int n = 0; n < algorithmic_frame_delay; ++n) {
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes,
receive_timestamp));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
ASSERT_EQ(0, neteq_->GetAudio(kBlockSize16kHz, decoded,
&samples_per_channel, &num_channels,
&output_type));
@ -1283,8 +1280,7 @@ TEST_F(NetEqDecodingTest, SyncPacketBufferSizeAndOverridenByNetworkPackets) {
// Insert.
for (int n = 0; n < kNumSyncPackets; ++n) {
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes,
receive_timestamp));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
rtp_info.header.sequenceNumber++;
rtp_info.header.timestamp += kBlockSize16kHz;
receive_timestamp += kBlockSize16kHz;
@ -1336,8 +1332,7 @@ void NetEqDecodingTest::WrapTest(uint16_t start_seq_no,
if (drop_seq_numbers.find(seq_no) == drop_seq_numbers.end()) {
// This sequence number was not in the set to drop. Insert it.
ASSERT_EQ(0,
neteq_->InsertPacket(rtp_info, payload, kPayloadBytes,
receive_timestamp));
neteq_->InsertPacket(rtp_info, payload, receive_timestamp));
++packets_inserted;
}
NetEqNetworkStatistics network_stats;
@ -1425,7 +1420,7 @@ void NetEqDecodingTest::DuplicateCng() {
WebRtcRTPHeader rtp_info;
for (int i = 0; i < 3; ++i) {
PopulateRtpInfo(seq_no, timestamp, &rtp_info);
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
++seq_no;
timestamp += kSamples;
@ -1444,7 +1439,9 @@ void NetEqDecodingTest::DuplicateCng() {
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));
ASSERT_EQ(
0, neteq_->InsertPacket(
rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
// Pull audio once and make sure CNG is played.
ASSERT_EQ(0,
@ -1456,7 +1453,9 @@ void NetEqDecodingTest::DuplicateCng() {
// Insert the same CNG packet again. Note that at this point it is old, since
// we have already decoded the first copy of it.
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, payload_len, 0));
ASSERT_EQ(
0, neteq_->InsertPacket(
rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
// Pull audio until we have played |kCngPeriodMs| of CNG. Start at 10 ms since
// we have already pulled out CNG once.
@ -1474,7 +1473,7 @@ void NetEqDecodingTest::DuplicateCng() {
++seq_no;
timestamp += kCngPeriodSamples;
PopulateRtpInfo(seq_no, timestamp, &rtp_info);
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
// Pull audio once and verify that the output is speech again.
ASSERT_EQ(0,
@ -1509,8 +1508,10 @@ TEST_F(NetEqDecodingTest, CngFirst) {
WebRtcRTPHeader rtp_info;
PopulateCng(seq_no, timestamp, &rtp_info, payload, &payload_len);
ASSERT_EQ(NetEq::kOK,
neteq_->InsertPacket(rtp_info, payload, payload_len, 0));
ASSERT_EQ(
NetEq::kOK,
neteq_->InsertPacket(
rtp_info, rtc::ArrayView<const uint8_t>(payload, payload_len), 0));
++seq_no;
timestamp += kCngPeriodSamples;
@ -1526,7 +1527,7 @@ TEST_F(NetEqDecodingTest, CngFirst) {
// Insert some speech packets.
for (int i = 0; i < 3; ++i) {
PopulateRtpInfo(seq_no, timestamp, &rtp_info);
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0));
ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
++seq_no;
timestamp += kSamples;

View File

@ -33,14 +33,12 @@ void NetEqExternalDecoderTest::Init() {
decoder_, codec_, kPayloadType, sample_rate_hz_));
}
void NetEqExternalDecoderTest::InsertPacket(WebRtcRTPHeader rtp_header,
const uint8_t* payload,
size_t payload_size_bytes,
void NetEqExternalDecoderTest::InsertPacket(
WebRtcRTPHeader rtp_header,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp) {
ASSERT_EQ(
NetEq::kOK,
neteq_->InsertPacket(
rtp_header, payload, payload_size_bytes, receive_timestamp));
ASSERT_EQ(NetEq::kOK,
neteq_->InsertPacket(rtp_header, payload, receive_timestamp));
}
size_t NetEqExternalDecoderTest::GetOutputAudio(size_t max_length,

View File

@ -36,8 +36,8 @@ class NetEqExternalDecoderTest {
// |payload_size_bytes| bytes. The |receive_timestamp| is an indication
// of the time when the packet was received, and should be measured with
// the same tick rate as the RTP timestamp of the current payload.
virtual void InsertPacket(WebRtcRTPHeader rtp_header, const uint8_t* payload,
size_t payload_size_bytes,
virtual void InsertPacket(WebRtcRTPHeader rtp_header,
rtc::ArrayView<const uint8_t> payload,
uint32_t receive_timestamp);
// Get 10 ms of audio data. The data is written to |output|, which can hold

View File

@ -68,7 +68,7 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms,
uint8_t input_payload[kInputBlockSizeSamples * sizeof(int16_t)];
size_t payload_len = WebRtcPcm16b_Encode(input_samples.data(),
input_samples.size(), input_payload);
assert(payload_len == kInputBlockSizeSamples * sizeof(int16_t));
RTC_CHECK_EQ(sizeof(input_payload), payload_len);
// Main loop.
webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock();
@ -82,8 +82,8 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms,
}
if (!lost) {
// Insert packet.
int error = neteq->InsertPacket(
rtp_header, input_payload, payload_len,
int error =
neteq->InsertPacket(rtp_header, input_payload,
packet_input_time_ms * kSampRateHz / 1000);
if (error != NetEq::kOK)
return -1;

View File

@ -377,8 +377,9 @@ int NetEqQualityTest::Transmit() {
<< " ms ";
if (payload_size_bytes_ > 0) {
if (!PacketLost()) {
int ret = neteq_->InsertPacket(rtp_header_, &payload_[0],
payload_size_bytes_,
int ret = neteq_->InsertPacket(
rtp_header_,
rtc::ArrayView<const uint8_t>(payload_.get(), payload_size_bytes_),
packet_input_time_ms * in_sampling_khz_);
if (ret != NetEq::kOK)
return -1;

View File

@ -547,7 +547,7 @@ int main(int argc, char* argv[]) {
payload_ptr = payload.get();
}
int error = neteq->InsertPacket(
rtp_header, payload_ptr, payload_len,
rtp_header, rtc::ArrayView<const uint8_t>(payload_ptr, payload_len),
static_cast<uint32_t>(packet->time_ms() * sample_rate_hz / 1000));
if (error != NetEq::kOK) {
if (neteq->LastError() == NetEq::kUnknownRtpPayloadType) {