Refactor NetEq rtp dump input.

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 <henrik.lundin@webrtc.org>
Commit-Queue: Jakob Ivarsson‎ <jakobi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39810}
This commit is contained in:
Jakob Ivarsson 2023-04-06 15:49:37 +02:00 committed by WebRTC LUCI CQ
parent e25c1229c5
commit d5ebc33562
7 changed files with 151 additions and 174 deletions

View File

@ -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",

View File

@ -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<int, RTPExtensionType> rtp_ext_map = {
{1, kRtpExtensionAudioLevel},
{3, kRtpExtensionAbsoluteSendTime},
{5, kRtpExtensionTransportSequenceNumber},
{7, kRtpExtensionVideoContentType},
{8, kRtpExtensionVideoTiming}};
std::unique_ptr<NetEqInput> input(new NetEqRtpDumpInput(
std::unique_ptr<NetEqInput> 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<TimeLimitedNetEqInput> input_time_limit(
new TimeLimitedNetEqInput(std::move(input), 20000));
std::unique_ptr<AudioSink> output(new VoidAudioSink);

View File

@ -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 <algorithm>
#include <limits>
#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<int64_t> NetEqPacketSourceInput::NextPacketTime() const {
return packet_
? absl::optional<int64_t>(static_cast<int64_t>(packet_->time_ms()))
: absl::nullopt;
}
absl::optional<RTPHeader> NetEqPacketSourceInput::NextHeader() const {
return packet_ ? absl::optional<RTPHeader>(packet_->header()) : absl::nullopt;
}
void NetEqPacketSourceInput::LoadNextPacket() {
packet_ = source()->NextPacket();
}
std::unique_ptr<NetEqInput::PacketData> NetEqPacketSourceInput::PopPacket() {
if (!packet_) {
return std::unique_ptr<PacketData>();
}
std::unique_ptr<PacketData> 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<uint32_t> 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<int64_t> 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

View File

@ -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 <map>
#include <memory>
#include <string>
#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<int, webrtc::RTPExtensionType>;
NetEqPacketSourceInput();
absl::optional<int64_t> NextPacketTime() const override;
std::unique_ptr<PacketData> PopPacket() override;
absl::optional<RTPHeader> NextHeader() const override;
bool ended() const override { return !next_output_event_ms_; }
protected:
virtual PacketSource* source() = 0;
void LoadNextPacket();
absl::optional<int64_t> next_output_event_ms_;
private:
std::unique_ptr<Packet> 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<uint32_t> ssrc_filter);
absl::optional<int64_t> NextOutputEventTime() const override;
absl::optional<SetMinimumDelayInfo> 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<RtpFileSource> source_;
};
} // namespace test
} // namespace webrtc
#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_PACKET_SOURCE_INPUT_H_

View File

@ -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<int, RTPExtensionType>& hdr_ext_map,
absl::optional<uint32_t> 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<int64_t> NextOutputEventTime() const override {
return next_output_event_ms_;
}
absl::optional<SetMinimumDelayInfo> 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<int64_t> NextPacketTime() const override {
return packet_ ? absl::optional<int64_t>(
static_cast<int64_t>(packet_->time_ms()))
: absl::nullopt;
}
std::unique_ptr<PacketData> PopPacket() override {
if (!packet_) {
return std::unique_ptr<PacketData>();
}
std::unique_ptr<PacketData> 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<RTPHeader> NextHeader() const override {
return packet_ ? absl::optional<RTPHeader>(packet_->header())
: absl::nullopt;
}
bool ended() const override { return !next_output_event_ms_; }
private:
void LoadNextPacket() { packet_ = source_->NextPacket(); }
absl::optional<int64_t> next_output_event_ms_ = 0;
static constexpr int64_t kOutputPeriodMs = 10;
std::unique_ptr<RtpFileSource> source_;
std::unique_ptr<Packet> packet_;
};
} // namespace
std::unique_ptr<NetEqInput> CreateNetEqRtpDumpInput(
absl::string_view file_name,
const std::map<int, RTPExtensionType>& hdr_ext_map,
absl::optional<uint32_t> ssrc_filter) {
return std::make_unique<NetEqRtpDumpInput>(file_name, hdr_ext_map,
ssrc_filter);
}
} // namespace test
} // namespace webrtc

View File

@ -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 <map>
#include <memory>
#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<NetEqInput> CreateNetEqRtpDumpInput(
absl::string_view file_name,
const std::map<int, RTPExtensionType>& hdr_ext_map,
absl::optional<uint32_t> ssrc_filter);
} // namespace test
} // namespace webrtc
#endif // MODULES_AUDIO_CODING_NETEQ_TOOLS_NETEQ_RTP_DUMP_INPUT_H_

View File

@ -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<NetEqTest> NetEqTestFactory::InitializeTestFromFile(
NetEqFactory* factory,
const Config& config) {
// Gather RTP header extensions in a map.
NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = {
std::map<int, RTPExtensionType> rtp_ext_map = {
{config.audio_level, kRtpExtensionAudioLevel},
{config.abs_send_time, kRtpExtensionAbsoluteSendTime},
{config.transport_seq_no, kRtpExtensionTransportSequenceNumber},
@ -142,8 +142,8 @@ std::unique_ptr<NetEqTest> NetEqTestFactory::InitializeTestFromFile(
std::unique_ptr<NetEqInput> 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);