From d5ebc335625ad2ce0a6e7b85485d5efb11fc551d Mon Sep 17 00:00:00 2001 From: Jakob Ivarsson Date: Thu, 6 Apr 2023 15:49:37 +0200 Subject: [PATCH] Refactor NetEq rtp dump input. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NetEq packet source input doesn't have any other uses than rtp dump, so remove that layer. Bug: None Change-Id: I667bb4aead9f0f2fe8a1c0d6d911a4670ded67e7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300542 Reviewed-by: Henrik Lundin Commit-Queue: Jakob Ivarsson‎ Cr-Commit-Position: refs/heads/main@{#39810} --- modules/audio_coding/BUILD.gn | 4 +- modules/audio_coding/neteq/neteq_unittest.cc | 8 +- .../neteq/tools/neteq_packet_source_input.cc | 90 --------------- .../neteq/tools/neteq_packet_source_input.h | 74 ------------ .../neteq/tools/neteq_rtp_dump_input.cc | 109 ++++++++++++++++++ .../neteq/tools/neteq_rtp_dump_input.h | 32 +++++ .../neteq/tools/neteq_test_factory.cc | 8 +- 7 files changed, 151 insertions(+), 174 deletions(-) delete mode 100644 modules/audio_coding/neteq/tools/neteq_packet_source_input.cc delete mode 100644 modules/audio_coding/neteq/tools/neteq_packet_source_input.h create mode 100644 modules/audio_coding/neteq/tools/neteq_rtp_dump_input.cc create mode 100644 modules/audio_coding/neteq/tools/neteq_rtp_dump_input.h diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn index 4e95f04a94..1420aa6385 100644 --- a/modules/audio_coding/BUILD.gn +++ b/modules/audio_coding/BUILD.gn @@ -821,8 +821,8 @@ rtc_library("neteq_test_tools") { "neteq/tools/constant_pcm_packet_source.h", "neteq/tools/initial_packet_inserter_neteq_input.cc", "neteq/tools/initial_packet_inserter_neteq_input.h", - "neteq/tools/neteq_packet_source_input.cc", - "neteq/tools/neteq_packet_source_input.h", + "neteq/tools/neteq_rtp_dump_input.cc", + "neteq/tools/neteq_rtp_dump_input.h", "neteq/tools/output_audio_file.h", "neteq/tools/output_wav_file.h", "neteq/tools/rtp_file_source.cc", diff --git a/modules/audio_coding/neteq/neteq_unittest.cc b/modules/audio_coding/neteq/neteq_unittest.cc index fff14bf830..5317496a83 100644 --- a/modules/audio_coding/neteq/neteq_unittest.cc +++ b/modules/audio_coding/neteq/neteq_unittest.cc @@ -26,7 +26,7 @@ #include "modules/audio_coding/codecs/pcm16b/pcm16b.h" #include "modules/audio_coding/neteq/test/neteq_decoding_test.h" #include "modules/audio_coding/neteq/tools/audio_loop.h" -#include "modules/audio_coding/neteq/tools/neteq_packet_source_input.h" +#include "modules/audio_coding/neteq/tools/neteq_rtp_dump_input.h" #include "modules/audio_coding/neteq/tools/neteq_test.h" #include "modules/include/module_common_types_public.h" #include "modules/rtp_rtcp/include/rtcp_statistics.h" @@ -982,15 +982,15 @@ TEST(NetEqNoTimeStretchingMode, RunTest) { NetEq::Config config; config.for_test_no_time_stretching = true; auto codecs = NetEqTest::StandardDecoderMap(); - NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { + std::map rtp_ext_map = { {1, kRtpExtensionAudioLevel}, {3, kRtpExtensionAbsoluteSendTime}, {5, kRtpExtensionTransportSequenceNumber}, {7, kRtpExtensionVideoContentType}, {8, kRtpExtensionVideoTiming}}; - std::unique_ptr input(new NetEqRtpDumpInput( + std::unique_ptr input = CreateNetEqRtpDumpInput( webrtc::test::ResourcePath("audio_coding/neteq_universal_new", "rtp"), - rtp_ext_map, absl::nullopt /*No SSRC filter*/)); + rtp_ext_map, absl::nullopt /*No SSRC filter*/); std::unique_ptr input_time_limit( new TimeLimitedNetEqInput(std::move(input), 20000)); std::unique_ptr output(new VoidAudioSink); diff --git a/modules/audio_coding/neteq/tools/neteq_packet_source_input.cc b/modules/audio_coding/neteq/tools/neteq_packet_source_input.cc deleted file mode 100644 index 55a5653238..0000000000 --- a/modules/audio_coding/neteq/tools/neteq_packet_source_input.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/neteq/tools/neteq_packet_source_input.h" - -#include -#include - -#include "absl/strings/string_view.h" -#include "modules/audio_coding/neteq/tools/rtp_file_source.h" -#include "rtc_base/checks.h" - -namespace webrtc { -namespace test { - -NetEqPacketSourceInput::NetEqPacketSourceInput() : next_output_event_ms_(0) {} - -absl::optional NetEqPacketSourceInput::NextPacketTime() const { - return packet_ - ? absl::optional(static_cast(packet_->time_ms())) - : absl::nullopt; -} - -absl::optional NetEqPacketSourceInput::NextHeader() const { - return packet_ ? absl::optional(packet_->header()) : absl::nullopt; -} - -void NetEqPacketSourceInput::LoadNextPacket() { - packet_ = source()->NextPacket(); -} - -std::unique_ptr NetEqPacketSourceInput::PopPacket() { - if (!packet_) { - return std::unique_ptr(); - } - std::unique_ptr packet_data(new PacketData); - packet_data->header = packet_->header(); - if (packet_->payload_length_bytes() == 0 && - packet_->virtual_payload_length_bytes() > 0) { - // This is a header-only "dummy" packet. Set the payload to all zeros, with - // length according to the virtual length. - packet_data->payload.SetSize(packet_->virtual_payload_length_bytes()); - std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0); - } else { - packet_data->payload.SetData(packet_->payload(), - packet_->payload_length_bytes()); - } - packet_data->time_ms = packet_->time_ms(); - - LoadNextPacket(); - - return packet_data; -} - -NetEqRtpDumpInput::NetEqRtpDumpInput(absl::string_view file_name, - const RtpHeaderExtensionMap& hdr_ext_map, - absl::optional ssrc_filter) - : source_(RtpFileSource::Create(file_name, ssrc_filter)) { - for (const auto& ext_pair : hdr_ext_map) { - source_->RegisterRtpHeaderExtension(ext_pair.second, ext_pair.first); - } - LoadNextPacket(); -} - -absl::optional NetEqRtpDumpInput::NextOutputEventTime() const { - return next_output_event_ms_; -} - -void NetEqRtpDumpInput::AdvanceOutputEvent() { - if (next_output_event_ms_) { - *next_output_event_ms_ += kOutputPeriodMs; - } - if (!NextPacketTime()) { - next_output_event_ms_ = absl::nullopt; - } -} - -PacketSource* NetEqRtpDumpInput::source() { - return source_.get(); -} - -} // namespace test -} // namespace webrtc diff --git a/modules/audio_coding/neteq/tools/neteq_packet_source_input.h b/modules/audio_coding/neteq/tools/neteq_packet_source_input.h deleted file mode 100644 index 1b48b1f8cf..0000000000 --- a/modules/audio_coding/neteq/tools/neteq_packet_source_input.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_PACKET_SOURCE_INPUT_H_ -#define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_PACKET_SOURCE_INPUT_H_ - -#include -#include -#include - -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "modules/audio_coding/neteq/tools/neteq_input.h" -#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" - -namespace webrtc { -namespace test { - -class RtpFileSource; - -// An adapter class to dress up a PacketSource object as a NetEqInput. -class NetEqPacketSourceInput : public NetEqInput { - public: - using RtpHeaderExtensionMap = std::map; - - NetEqPacketSourceInput(); - absl::optional NextPacketTime() const override; - std::unique_ptr PopPacket() override; - absl::optional NextHeader() const override; - bool ended() const override { return !next_output_event_ms_; } - - protected: - virtual PacketSource* source() = 0; - void LoadNextPacket(); - - absl::optional next_output_event_ms_; - - private: - std::unique_ptr packet_; -}; - -// Implementation of NetEqPacketSourceInput to be used with an RtpFileSource. -class NetEqRtpDumpInput final : public NetEqPacketSourceInput { - public: - NetEqRtpDumpInput(absl::string_view file_name, - const RtpHeaderExtensionMap& hdr_ext_map, - absl::optional ssrc_filter); - - absl::optional NextOutputEventTime() const override; - absl::optional NextSetMinimumDelayInfo() const override { - return absl::nullopt; - } - void AdvanceOutputEvent() override; - void AdvanceSetMinimumDelay() override {} - - protected: - PacketSource* source() override; - - private: - static constexpr int64_t kOutputPeriodMs = 10; - - std::unique_ptr source_; -}; - -} // namespace test -} // namespace webrtc -#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_PACKET_SOURCE_INPUT_H_ diff --git a/modules/audio_coding/neteq/tools/neteq_rtp_dump_input.cc b/modules/audio_coding/neteq/tools/neteq_rtp_dump_input.cc new file mode 100644 index 0000000000..20e092b079 --- /dev/null +++ b/modules/audio_coding/neteq/tools/neteq_rtp_dump_input.cc @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "modules/audio_coding/neteq/tools/neteq_rtp_dump_input.h" + +#include "absl/strings/string_view.h" +#include "modules/audio_coding/neteq/tools/rtp_file_source.h" + +namespace webrtc { +namespace test { +namespace { + +// An adapter class to dress up a PacketSource object as a NetEqInput. +class NetEqRtpDumpInput : public NetEqInput { + public: + NetEqRtpDumpInput(absl::string_view file_name, + const std::map& hdr_ext_map, + absl::optional ssrc_filter) + : source_(RtpFileSource::Create(file_name, ssrc_filter)) { + for (const auto& ext_pair : hdr_ext_map) { + source_->RegisterRtpHeaderExtension(ext_pair.second, ext_pair.first); + } + LoadNextPacket(); + } + + absl::optional NextOutputEventTime() const override { + return next_output_event_ms_; + } + + absl::optional NextSetMinimumDelayInfo() const override { + return absl::nullopt; + } + + void AdvanceOutputEvent() override { + if (next_output_event_ms_) { + *next_output_event_ms_ += kOutputPeriodMs; + } + if (!NextPacketTime()) { + next_output_event_ms_ = absl::nullopt; + } + } + + void AdvanceSetMinimumDelay() override {} + + absl::optional NextPacketTime() const override { + return packet_ ? absl::optional( + static_cast(packet_->time_ms())) + : absl::nullopt; + } + + std::unique_ptr PopPacket() override { + if (!packet_) { + return std::unique_ptr(); + } + std::unique_ptr packet_data(new PacketData); + packet_data->header = packet_->header(); + if (packet_->payload_length_bytes() == 0 && + packet_->virtual_payload_length_bytes() > 0) { + // This is a header-only "dummy" packet. Set the payload to all zeros, + // with length according to the virtual length. + packet_data->payload.SetSize(packet_->virtual_payload_length_bytes()); + std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0); + } else { + packet_data->payload.SetData(packet_->payload(), + packet_->payload_length_bytes()); + } + packet_data->time_ms = packet_->time_ms(); + + LoadNextPacket(); + + return packet_data; + } + + absl::optional NextHeader() const override { + return packet_ ? absl::optional(packet_->header()) + : absl::nullopt; + } + + bool ended() const override { return !next_output_event_ms_; } + + private: + void LoadNextPacket() { packet_ = source_->NextPacket(); } + + absl::optional next_output_event_ms_ = 0; + static constexpr int64_t kOutputPeriodMs = 10; + + std::unique_ptr source_; + std::unique_ptr packet_; +}; + +} // namespace + +std::unique_ptr CreateNetEqRtpDumpInput( + absl::string_view file_name, + const std::map& hdr_ext_map, + absl::optional ssrc_filter) { + return std::make_unique(file_name, hdr_ext_map, + ssrc_filter); +} + +} // namespace test +} // namespace webrtc diff --git a/modules/audio_coding/neteq/tools/neteq_rtp_dump_input.h b/modules/audio_coding/neteq/tools/neteq_rtp_dump_input.h new file mode 100644 index 0000000000..e68ebb2c2c --- /dev/null +++ b/modules/audio_coding/neteq/tools/neteq_rtp_dump_input.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_RTP_DUMP_INPUT_H_ +#define MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_RTP_DUMP_INPUT_H_ + +#include +#include + +#include "absl/strings/string_view.h" +#include "absl/types/optional.h" +#include "modules/audio_coding/neteq/tools/neteq_input.h" +#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" + +namespace webrtc { +namespace test { + +std::unique_ptr CreateNetEqRtpDumpInput( + absl::string_view file_name, + const std::map& hdr_ext_map, + absl::optional ssrc_filter); + +} // namespace test +} // namespace webrtc +#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_RTP_DUMP_INPUT_H_ diff --git a/modules/audio_coding/neteq/tools/neteq_test_factory.cc b/modules/audio_coding/neteq/tools/neteq_test_factory.cc index 5f595d8b4e..981504b239 100644 --- a/modules/audio_coding/neteq/tools/neteq_test_factory.cc +++ b/modules/audio_coding/neteq/tools/neteq_test_factory.cc @@ -31,8 +31,8 @@ #include "modules/audio_coding/neteq/tools/input_audio_file.h" #include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h" #include "modules/audio_coding/neteq/tools/neteq_event_log_input.h" -#include "modules/audio_coding/neteq/tools/neteq_packet_source_input.h" #include "modules/audio_coding/neteq/tools/neteq_replacement_input.h" +#include "modules/audio_coding/neteq/tools/neteq_rtp_dump_input.h" #include "modules/audio_coding/neteq/tools/neteq_stats_getter.h" #include "modules/audio_coding/neteq/tools/neteq_stats_plotter.h" #include "modules/audio_coding/neteq/tools/neteq_test.h" @@ -132,7 +132,7 @@ std::unique_ptr NetEqTestFactory::InitializeTestFromFile( NetEqFactory* factory, const Config& config) { // Gather RTP header extensions in a map. - NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { + std::map rtp_ext_map = { {config.audio_level, kRtpExtensionAudioLevel}, {config.abs_send_time, kRtpExtensionAbsoluteSendTime}, {config.transport_seq_no, kRtpExtensionTransportSequenceNumber}, @@ -142,8 +142,8 @@ std::unique_ptr NetEqTestFactory::InitializeTestFromFile( std::unique_ptr input; if (RtpFileSource::ValidRtpDump(input_file_name) || RtpFileSource::ValidPcap(input_file_name)) { - input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map, - config.ssrc_filter)); + input = CreateNetEqRtpDumpInput(input_file_name, rtp_ext_map, + config.ssrc_filter); } else { ParsedRtcEventLog parsed_log; auto status = parsed_log.ParseFile(input_file_name);