From ee2bac26dd3eb4463126098f87701ff66098b288 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Wed, 11 Nov 2015 10:34:00 -0800 Subject: [PATCH] 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} --- .../audio_coding/main/acm2/acm_receiver.cc | 13 ++- .../audio_coding/main/acm2/acm_receiver.h | 6 +- .../main/acm2/acm_receiver_unittest_oldapi.cc | 5 +- .../main/acm2/audio_coding_module_impl.cc | 4 +- .../audio_coding/neteq/include/neteq.h | 3 +- .../neteq/neteq_external_decoder_unittest.cc | 29 +++---- .../modules/audio_coding/neteq/neteq_impl.cc | 34 ++++---- .../modules/audio_coding/neteq/neteq_impl.h | 6 +- .../audio_coding/neteq/neteq_impl_unittest.cc | 56 +++++-------- .../neteq/neteq_network_stats_unittest.cc | 3 +- .../neteq/neteq_stereo_unittest.cc | 14 ++-- .../audio_coding/neteq/neteq_unittest.cc | 81 ++++++++++--------- .../tools/neteq_external_decoder_test.cc | 14 ++-- .../neteq/tools/neteq_external_decoder_test.h | 4 +- .../neteq/tools/neteq_performance_test.cc | 8 +- .../neteq/tools/neteq_quality_test.cc | 7 +- .../audio_coding/neteq/tools/neteq_rtpplay.cc | 2 +- 17 files changed, 132 insertions(+), 157 deletions(-) diff --git a/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc index 4e1977636a..b4dfe3ad93 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc @@ -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 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(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(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. diff --git a/webrtc/modules/audio_coding/main/acm2/acm_receiver.h b/webrtc/modules/audio_coding/main/acm2/acm_receiver.h index 071510a5f1..7dc851a1ba 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_receiver.h +++ b/webrtc/modules/audio_coding/main/acm2/acm_receiver.h @@ -14,6 +14,7 @@ #include #include +#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 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; diff --git a/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc b/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc index 59e6460d3b..37bb131f03 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc @@ -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(payload_data, payload_len_bytes)); if (ret_val < 0) { assert(false); return -1; diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc index aaf204b6a8..d4d5853e71 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc @@ -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(incoming_payload, payload_length)); } // Minimum playout delay (Used for lip-sync). diff --git a/webrtc/modules/audio_coding/neteq/include/neteq.h b/webrtc/modules/audio_coding/neteq/include/neteq.h index d6c359b0eb..9a1bc17b8b 100644 --- a/webrtc/modules/audio_coding/neteq/include/neteq.h +++ b/webrtc/modules/audio_coding/neteq/include/neteq.h @@ -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 payload, uint32_t receive_timestamp) = 0; // Inserts a sync-packet into packet queue. Sync-packets are decoded to diff --git a/webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc index 09eb5614fe..cf22953962 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc @@ -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( + 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 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 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); } diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc index d9ae15e7fa..bbd3220c00 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc @@ -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 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(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(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 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. diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.h b/webrtc/modules/audio_coding/neteq/neteq_impl.h index c001e53b81..60c846d619 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl.h +++ b/webrtc/modules/audio_coding/neteq/neteq_impl.h @@ -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 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 payload, uint32_t receive_timestamp, bool is_sync_packet) EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc index 90640ca1d2..11fdfe9a45 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc @@ -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(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(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(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(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(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. diff --git a/webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc index 16fa04c234..34ca9ea856 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_network_stats_unittest.cc @@ -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); diff --git a/webrtc/modules/audio_coding/neteq/neteq_stereo_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_stereo_unittest.cc index 66874b8a50..be021676f1 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_stereo_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_stereo_unittest.cc @@ -196,14 +196,16 @@ class NetEqStereoTest : public ::testing::TestWithParam { 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( + 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_, - next_arrival_time)); + ASSERT_EQ(NetEq::kOK, neteq_->InsertPacket( + rtp_header_, rtc::ArrayView( + encoded_multi_channel_, + multi_payload_size_bytes_), + next_arrival_time)); // Get next input packets (mono and multi-channel). do { next_send_time = GetNewPackets(); diff --git a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc index 6f47dd1c06..d7312d0931 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc @@ -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( - packet_->time_ms() * (output_sample_rate_ / 1000)))); + rtp_header, + rtc::ArrayView( + packet_->payload(), packet_->payload_length_bytes()), + static_cast(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(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(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(payload, payload_len), 0)); ++seq_no; timestamp += kCngPeriodSamples; next_input_time_ms += static_cast(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(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,9 +948,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)); + ASSERT_EQ(0, neteq_->InsertPacket(rtp_info, rtc::ArrayView( + payload, enc_len_bytes), + receive_timestamp)); ASSERT_EQ(0, neteq_->GetAudio(kBlockSize32kHz, output, @@ -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(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(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(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; diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.cc b/webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.cc index 49750c26c8..dcf5f616d9 100644 --- a/webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.cc +++ b/webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.cc @@ -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, - uint32_t receive_timestamp) { - ASSERT_EQ( - NetEq::kOK, - neteq_->InsertPacket( - rtp_header, payload, payload_size_bytes, receive_timestamp)); +void NetEqExternalDecoderTest::InsertPacket( + WebRtcRTPHeader rtp_header, + rtc::ArrayView payload, + uint32_t receive_timestamp) { + ASSERT_EQ(NetEq::kOK, + neteq_->InsertPacket(rtp_header, payload, receive_timestamp)); } size_t NetEqExternalDecoderTest::GetOutputAudio(size_t max_length, diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.h b/webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.h index c9fe11f656..0f71e5df06 100644 --- a/webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.h +++ b/webrtc/modules/audio_coding/neteq/tools/neteq_external_decoder_test.h @@ -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 payload, uint32_t receive_timestamp); // Get 10 ms of audio data. The data is written to |output|, which can hold diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.cc b/webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.cc index dbea1c62a2..88077fe45a 100644 --- a/webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.cc +++ b/webrtc/modules/audio_coding/neteq/tools/neteq_performance_test.cc @@ -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,9 +82,9 @@ int64_t NetEqPerformanceTest::Run(int runtime_ms, } if (!lost) { // Insert packet. - int error = neteq->InsertPacket( - rtp_header, input_payload, payload_len, - packet_input_time_ms * kSampRateHz / 1000); + int error = + neteq->InsertPacket(rtp_header, input_payload, + packet_input_time_ms * kSampRateHz / 1000); if (error != NetEq::kOK) return -1; } diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.cc b/webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.cc index 6826d1be74..1c560c5d4a 100644 --- a/webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.cc +++ b/webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.cc @@ -377,9 +377,10 @@ int NetEqQualityTest::Transmit() { << " ms "; if (payload_size_bytes_ > 0) { if (!PacketLost()) { - int ret = neteq_->InsertPacket(rtp_header_, &payload_[0], - payload_size_bytes_, - packet_input_time_ms * in_sampling_khz_); + int ret = neteq_->InsertPacket( + rtp_header_, + rtc::ArrayView(payload_.get(), payload_size_bytes_), + packet_input_time_ms * in_sampling_khz_); if (ret != NetEq::kOK) return -1; Log() << "was sent."; diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc index 7a52408705..f9e8658ac4 100644 --- a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc +++ b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc @@ -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(payload_ptr, payload_len), static_cast(packet->time_ms() * sample_rate_hz / 1000)); if (error != NetEq::kOK) { if (neteq->LastError() == NetEq::kUnknownRtpPayloadType) {