Make the RtpHeaderParserImpl available to tests and tools only.
There are a few reasons for making this test only:
* The code is only used by tests and utilities.
* The pure interface has only a single implementation so an interface isn't really needed.
(a followup change could remove it altogether)
* The implementation always incorporates locking regardless of how the class gets used.
See e.g. previous use in the Packet class.
* The implementation is a layer on top of RtpUtility::RtpHeaderParser which is
sufficient for most production cases.
Change-Id: Ide6d50567cf8ae5127a2eb04cceeb10cf317ec36
Bug: none
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150658
Commit-Queue: Tommi <tommi@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29010}
diff --git a/BUILD.gn b/BUILD.gn
index 95d02f7..9207a1d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -504,6 +504,7 @@
"rtc_base/synchronization:sequence_checker_unittests",
"rtc_base/task_utils:to_queued_task_unittests",
"sdk:sdk_tests",
+ "test:rtp_test_utils",
"test:test_main",
"test/network:network_emulation_unittests",
]
diff --git a/call/BUILD.gn b/call/BUILD.gn
index dc545cd..c044a80 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -460,6 +460,7 @@
"../test:fileutils",
"../test:null_transport",
"../test:perf_test",
+ "../test:rtp_test_utils",
"../test:test_common",
"../test:test_support",
"../test:video_test_common",
diff --git a/call/call.cc b/call/call.cc
index 8771380..62a4378 100644
--- a/call/call.cc
+++ b/call/call.cc
@@ -40,9 +40,9 @@
#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
#include "modules/rtp_rtcp/include/flexfec_receiver.h"
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "modules/rtp_rtcp/source/byte_io.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
+#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "modules/utility/include/process_thread.h"
#include "modules/video_coding/fec_controller_default.h"
#include "rtc_base/checks.h"
@@ -155,6 +155,11 @@
return rtclog_config;
}
+bool IsRtcp(const uint8_t* packet, size_t length) {
+ RtpUtility::RtpHeaderParser rtp_parser(packet, length);
+ return rtp_parser.RTCP();
+}
+
} // namespace
namespace internal {
@@ -1322,7 +1327,7 @@
rtc::CopyOnWriteBuffer packet,
int64_t packet_time_us) {
RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
- if (RtpHeaderParser::IsRtcp(packet.cdata(), packet.size()))
+ if (IsRtcp(packet.cdata(), packet.size()))
return DeliverRtcp(media_type, packet.cdata(), packet.size());
return DeliverRtp(media_type, std::move(packet), packet_time_us);
diff --git a/call/call_perf_tests.cc b/call/call_perf_tests.cc
index 321f69c..5da1fae 100644
--- a/call/call_perf_tests.cc
+++ b/call/call_perf_tests.cc
@@ -27,7 +27,6 @@
#include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_device/include/test_audio_device.h"
#include "modules/audio_mixer/audio_mixer_impl.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/checks.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/metrics.h"
@@ -41,6 +40,7 @@
#include "test/frame_generator_capturer.h"
#include "test/gtest.h"
#include "test/null_transport.h"
+#include "test/rtp_header_parser.h"
#include "test/rtp_rtcp_observer.h"
#include "test/single_threaded_task_queue.h"
#include "test/testsupport/file_utils.h"
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index ce60643..0d54d30 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -665,6 +665,7 @@
"../system_wrappers:field_trial",
"../test:field_trial",
"../test:platform_video_capturer",
+ "../test:rtp_test_utils",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional",
]
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 4635175..426b2a0 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -558,6 +558,7 @@
"../rtc_base/third_party/sigslot",
"../test:audio_codec_mocks",
"../test:field_trial",
+ "../test:rtp_test_utils",
"../test:test_main",
"../test:test_support",
"../test:video_test_common",
diff --git a/media/engine/webrtc_video_engine_unittest.cc b/media/engine/webrtc_video_engine_unittest.cc
index 48e90f5..ba1f671 100644
--- a/media/engine/webrtc_video_engine_unittest.cc
+++ b/media/engine/webrtc_video_engine_unittest.cc
@@ -51,7 +51,6 @@
#include "media/engine/fake_webrtc_video_engine.h"
#include "media/engine/simulcast.h"
#include "media/engine/webrtc_voice_engine.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/fake_clock.h"
#include "rtc_base/gunit.h"
@@ -60,6 +59,7 @@
#include "test/field_trial.h"
#include "test/frame_generator.h"
#include "test/gmock.h"
+#include "test/rtp_header_parser.h"
using ::testing::Field;
using ::testing::IsEmpty;
@@ -1417,7 +1417,7 @@
static bool ParseRtpPacket(const rtc::CopyOnWriteBuffer* p,
webrtc::RTPHeader* header) {
std::unique_ptr<webrtc::RtpHeaderParser> parser(
- webrtc::RtpHeaderParser::Create());
+ webrtc::RtpHeaderParser::CreateForTest());
return parser->Parse(p->cdata(), p->size(), header);
}
diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn
index e28964d..7d72a43 100644
--- a/modules/audio_coding/BUILD.gn
+++ b/modules/audio_coding/BUILD.gn
@@ -1099,6 +1099,7 @@
"../../test:rtp_test_utils",
"../rtp_rtcp",
"../rtp_rtcp:rtp_rtcp_format",
+ "//third_party/abseil-cpp/absl/memory:memory",
"//third_party/abseil-cpp/absl/types:optional",
]
diff --git a/modules/audio_coding/acm2/audio_coding_module_unittest.cc b/modules/audio_coding/acm2/audio_coding_module_unittest.cc
index 8545f7a..d029c60 100644
--- a/modules/audio_coding/acm2/audio_coding_module_unittest.cc
+++ b/modules/audio_coding/acm2/audio_coding_module_unittest.cc
@@ -71,12 +71,12 @@
const uint8_t kPayloadType = 111;
} // namespace
-class RtpUtility {
+class RtpData {
public:
- RtpUtility(int samples_per_packet, uint8_t payload_type)
+ RtpData(int samples_per_packet, uint8_t payload_type)
: samples_per_packet_(samples_per_packet), payload_type_(payload_type) {}
- virtual ~RtpUtility() {}
+ virtual ~RtpData() {}
void Populate(RTPHeader* rtp_header) {
rtp_header->sequenceNumber = 0xABCD;
@@ -163,7 +163,7 @@
class AudioCodingModuleTestOldApi : public ::testing::Test {
protected:
AudioCodingModuleTestOldApi()
- : rtp_utility_(new RtpUtility(kFrameSizeSamples, kPayloadType)),
+ : rtp_utility_(new RtpData(kFrameSizeSamples, kPayloadType)),
clock_(Clock::GetRealTimeClock()) {}
~AudioCodingModuleTestOldApi() {}
@@ -239,7 +239,7 @@
VerifyEncoding();
}
- std::unique_ptr<RtpUtility> rtp_utility_;
+ std::unique_ptr<RtpData> rtp_utility_;
std::unique_ptr<AudioCodingModule> acm_;
PacketizationCallbackStubOldApi packet_cb_;
RTPHeader rtp_header_;
diff --git a/modules/audio_coding/neteq/tools/packet.cc b/modules/audio_coding/neteq/tools/packet.cc
index 4e2102d..6ed6f98 100644
--- a/modules/audio_coding/neteq/tools/packet.cc
+++ b/modules/audio_coding/neteq/tools/packet.cc
@@ -14,81 +14,53 @@
#include <memory>
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
+#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "rtc_base/checks.h"
namespace webrtc {
namespace test {
-Packet::Packet(uint8_t* packet_memory,
- size_t allocated_bytes,
- double time_ms,
- const RtpHeaderParser& parser)
- : payload_memory_(packet_memory),
- payload_(NULL),
- packet_length_bytes_(allocated_bytes),
- payload_length_bytes_(0),
- virtual_packet_length_bytes_(allocated_bytes),
- virtual_payload_length_bytes_(0),
- time_ms_(time_ms) {
- valid_header_ = ParseHeader(parser);
-}
+using webrtc::RtpUtility::RtpHeaderParser;
Packet::Packet(uint8_t* packet_memory,
size_t allocated_bytes,
size_t virtual_packet_length_bytes,
double time_ms,
- const RtpHeaderParser& parser)
+ const RtpUtility::RtpHeaderParser& parser,
+ const RtpHeaderExtensionMap* extension_map /*= nullptr*/)
: payload_memory_(packet_memory),
- payload_(NULL),
packet_length_bytes_(allocated_bytes),
- payload_length_bytes_(0),
virtual_packet_length_bytes_(virtual_packet_length_bytes),
virtual_payload_length_bytes_(0),
- time_ms_(time_ms) {
- valid_header_ = ParseHeader(parser);
-}
+ time_ms_(time_ms),
+ valid_header_(ParseHeader(parser, extension_map)) {}
Packet::Packet(const RTPHeader& header,
size_t virtual_packet_length_bytes,
size_t virtual_payload_length_bytes,
double time_ms)
: header_(header),
- payload_memory_(),
- payload_(NULL),
- packet_length_bytes_(0),
- payload_length_bytes_(0),
virtual_packet_length_bytes_(virtual_packet_length_bytes),
virtual_payload_length_bytes_(virtual_payload_length_bytes),
time_ms_(time_ms),
valid_header_(true) {}
Packet::Packet(uint8_t* packet_memory, size_t allocated_bytes, double time_ms)
- : payload_memory_(packet_memory),
- payload_(NULL),
- packet_length_bytes_(allocated_bytes),
- payload_length_bytes_(0),
- virtual_packet_length_bytes_(allocated_bytes),
- virtual_payload_length_bytes_(0),
- time_ms_(time_ms) {
- std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
- valid_header_ = ParseHeader(*parser);
-}
+ : Packet(packet_memory,
+ allocated_bytes,
+ allocated_bytes,
+ time_ms,
+ RtpUtility::RtpHeaderParser(packet_memory, allocated_bytes)) {}
Packet::Packet(uint8_t* packet_memory,
size_t allocated_bytes,
size_t virtual_packet_length_bytes,
double time_ms)
- : payload_memory_(packet_memory),
- payload_(NULL),
- packet_length_bytes_(allocated_bytes),
- payload_length_bytes_(0),
- virtual_packet_length_bytes_(virtual_packet_length_bytes),
- virtual_payload_length_bytes_(0),
- time_ms_(time_ms) {
- std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
- valid_header_ = ParseHeader(*parser);
-}
+ : Packet(packet_memory,
+ allocated_bytes,
+ virtual_packet_length_bytes,
+ time_ms,
+ RtpUtility::RtpHeaderParser(packet_memory, allocated_bytes)) {}
Packet::~Packet() = default;
@@ -139,9 +111,10 @@
}
}
-bool Packet::ParseHeader(const RtpHeaderParser& parser) {
- bool valid_header = parser.Parse(
- payload_memory_.get(), static_cast<int>(packet_length_bytes_), &header_);
+bool Packet::ParseHeader(const RtpHeaderParser& parser,
+ const RtpHeaderExtensionMap* extension_map) {
+ bool valid_header = parser.Parse(&header_, extension_map);
+
// Special case for dummy packets that have padding marked in the RTP header.
// This causes the RTP header parser to report failure, but is fine in this
// context.
diff --git a/modules/audio_coding/neteq/tools/packet.h b/modules/audio_coding/neteq/tools/packet.h
index 5748ba2..f4189aa 100644
--- a/modules/audio_coding/neteq/tools/packet.h
+++ b/modules/audio_coding/neteq/tools/packet.h
@@ -15,11 +15,14 @@
#include <memory>
#include "api/rtp_headers.h" // NOLINT(build/include)
+#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
#include "rtc_base/constructor_magic.h"
namespace webrtc {
+namespace RtpUtility {
class RtpHeaderParser;
+} // namespace RtpUtility
namespace test {
@@ -32,22 +35,17 @@
// when the Packet object is deleted. The |time_ms| is an extra time
// associated with this packet, typically used to denote arrival time.
// The first bytes in |packet_memory| will be parsed using |parser|.
- Packet(uint8_t* packet_memory,
- size_t allocated_bytes,
- double time_ms,
- const RtpHeaderParser& parser);
-
- // Same as above, but with the extra argument |virtual_packet_length_bytes|.
- // This is typically used when reading RTP dump files that only contain the
- // RTP headers, and no payload (a.k.a RTP dummy files or RTP light). The
- // |virtual_packet_length_bytes| tells what size the packet had on wire,
- // including the now discarded payload, whereas |allocated_bytes| is the
- // length of the remaining payload (typically only the RTP header).
+ // |virtual_packet_length_bytes| is typically used when reading RTP dump files
+ // that only contain the RTP headers, and no payload (a.k.a RTP dummy files or
+ // RTP light). The |virtual_packet_length_bytes| tells what size the packet
+ // had on wire, including the now discarded payload, whereas |allocated_bytes|
+ // is the length of the remaining payload (typically only the RTP header).
Packet(uint8_t* packet_memory,
size_t allocated_bytes,
size_t virtual_packet_length_bytes,
double time_ms,
- const RtpHeaderParser& parser);
+ const RtpUtility::RtpHeaderParser& parser,
+ const RtpHeaderExtensionMap* extension_map = nullptr);
// Same as above, but creates the packet from an already parsed RTPHeader.
// This is typically used when reading RTP dump files that only contain the
@@ -98,25 +96,25 @@
const RTPHeader& header() const { return header_; }
- void set_time_ms(double time) { time_ms_ = time; }
double time_ms() const { return time_ms_; }
bool valid_header() const { return valid_header_; }
private:
- bool ParseHeader(const RtpHeaderParser& parser);
+ bool ParseHeader(const webrtc::RtpUtility::RtpHeaderParser& parser,
+ const RtpHeaderExtensionMap* extension_map);
void CopyToHeader(RTPHeader* destination) const;
RTPHeader header_;
- std::unique_ptr<uint8_t[]> payload_memory_;
- const uint8_t* payload_; // First byte after header.
- const size_t packet_length_bytes_; // Total length of packet.
- size_t payload_length_bytes_; // Length of the payload, after RTP header.
- // Zero for dummy RTP packets.
+ const std::unique_ptr<uint8_t[]> payload_memory_;
+ const uint8_t* payload_ = nullptr; // First byte after header.
+ const size_t packet_length_bytes_ = 0; // Total length of packet.
+ size_t payload_length_bytes_ = 0; // Length of the payload, after RTP header.
+ // Zero for dummy RTP packets.
// Virtual lengths are used when parsing RTP header files (dummy RTP files).
const size_t virtual_packet_length_bytes_;
- size_t virtual_payload_length_bytes_;
- double time_ms_; // Used to denote a packet's arrival time.
- bool valid_header_; // Set by the RtpHeaderParser.
+ size_t virtual_payload_length_bytes_ = 0;
+ const double time_ms_; // Used to denote a packet's arrival time.
+ const bool valid_header_; // Set by the RtpHeaderParser.
RTC_DISALLOW_COPY_AND_ASSIGN(Packet);
};
diff --git a/modules/audio_coding/neteq/tools/rtp_file_source.cc b/modules/audio_coding/neteq/tools/rtp_file_source.cc
index eda2b3e..410af27 100644
--- a/modules/audio_coding/neteq/tools/rtp_file_source.cc
+++ b/modules/audio_coding/neteq/tools/rtp_file_source.cc
@@ -18,8 +18,8 @@
#include <memory>
+#include "absl/memory/memory.h"
#include "modules/audio_coding/neteq/tools/packet.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/checks.h"
#include "test/rtp_file_reader.h"
@@ -49,8 +49,7 @@
bool RtpFileSource::RegisterRtpHeaderExtension(RTPExtensionType type,
uint8_t id) {
- assert(parser_.get());
- return parser_->RegisterRtpHeaderExtension(type, id);
+ return rtp_header_extension_map_.RegisterByType(id, type);
}
std::unique_ptr<Packet> RtpFileSource::NextPacket() {
@@ -66,9 +65,11 @@
}
std::unique_ptr<uint8_t[]> packet_memory(new uint8_t[temp_packet.length]);
memcpy(packet_memory.get(), temp_packet.data, temp_packet.length);
- std::unique_ptr<Packet> packet(new Packet(
+ RtpUtility::RtpHeaderParser parser(packet_memory.get(), temp_packet.length);
+ auto packet = absl::make_unique<Packet>(
packet_memory.release(), temp_packet.length,
- temp_packet.original_length, temp_packet.time_ms, *parser_.get()));
+ temp_packet.original_length, temp_packet.time_ms, parser,
+ &rtp_header_extension_map_);
if (!packet->valid_header()) {
continue;
}
@@ -83,7 +84,6 @@
RtpFileSource::RtpFileSource(absl::optional<uint32_t> ssrc_filter)
: PacketSource(),
- parser_(RtpHeaderParser::Create()),
ssrc_filter_(ssrc_filter) {}
bool RtpFileSource::OpenFile(const std::string& file_name) {
diff --git a/modules/audio_coding/neteq/tools/rtp_file_source.h b/modules/audio_coding/neteq/tools/rtp_file_source.h
index 77e435a..953e2fa 100644
--- a/modules/audio_coding/neteq/tools/rtp_file_source.h
+++ b/modules/audio_coding/neteq/tools/rtp_file_source.h
@@ -19,12 +19,11 @@
#include "absl/types/optional.h"
#include "modules/audio_coding/neteq/tools/packet_source.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
+#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "rtc_base/constructor_magic.h"
namespace webrtc {
-class RtpHeaderParser;
-
namespace test {
class RtpFileReader;
@@ -58,8 +57,8 @@
bool OpenFile(const std::string& file_name);
std::unique_ptr<RtpFileReader> rtp_reader_;
- std::unique_ptr<RtpHeaderParser> parser_;
const absl::optional<uint32_t> ssrc_filter_;
+ RtpHeaderExtensionMap rtp_header_extension_map_;
RTC_DISALLOW_COPY_AND_ASSIGN(RtpFileSource);
};
diff --git a/modules/remote_bitrate_estimator/tools/bwe_rtp.cc b/modules/remote_bitrate_estimator/tools/bwe_rtp.cc
index aa60b15..c0b3a37 100644
--- a/modules/remote_bitrate_estimator/tools/bwe_rtp.cc
+++ b/modules/remote_bitrate_estimator/tools/bwe_rtp.cc
@@ -20,8 +20,8 @@
#include "absl/flags/parse.h"
#include "modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
#include "modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "test/rtp_file_reader.h"
+#include "test/rtp_header_parser.h"
ABSL_FLAG(std::string,
extension_type,
@@ -65,14 +65,14 @@
return ssrcs;
}
-bool ParseArgsAndSetupEstimator(int argc,
- char** argv,
- webrtc::Clock* clock,
- webrtc::RemoteBitrateObserver* observer,
- webrtc::test::RtpFileReader** rtp_reader,
- webrtc::RtpHeaderParser** parser,
- webrtc::RemoteBitrateEstimator** estimator,
- std::string* estimator_used) {
+std::unique_ptr<webrtc::RtpHeaderParser> ParseArgsAndSetupEstimator(
+ int argc,
+ char** argv,
+ webrtc::Clock* clock,
+ webrtc::RemoteBitrateObserver* observer,
+ std::unique_ptr<webrtc::test::RtpFileReader>* rtp_reader,
+ std::unique_ptr<webrtc::RemoteBitrateEstimator>* estimator,
+ std::string* estimator_used) {
absl::ParseCommandLine(argc, argv);
std::string filename = InputFile();
@@ -84,16 +84,16 @@
fprintf(stderr, "\n");
if (filename.substr(filename.find_last_of('.')) == ".pcap") {
fprintf(stderr, "Opening as pcap\n");
- *rtp_reader = webrtc::test::RtpFileReader::Create(
- webrtc::test::RtpFileReader::kPcap, filename.c_str(), SsrcFilter());
+ rtp_reader->reset(webrtc::test::RtpFileReader::Create(
+ webrtc::test::RtpFileReader::kPcap, filename.c_str(), SsrcFilter()));
} else {
fprintf(stderr, "Opening as rtp\n");
- *rtp_reader = webrtc::test::RtpFileReader::Create(
- webrtc::test::RtpFileReader::kRtpDump, filename.c_str());
+ rtp_reader->reset(webrtc::test::RtpFileReader::Create(
+ webrtc::test::RtpFileReader::kRtpDump, filename.c_str()));
}
if (!*rtp_reader) {
fprintf(stderr, "Cannot open input file %s\n", filename.c_str());
- return false;
+ return nullptr;
}
fprintf(stderr, "Input file: %s\n\n", filename.c_str());
@@ -105,29 +105,31 @@
fprintf(stderr, "Extension: abs\n");
} else {
fprintf(stderr, "Unknown extension type\n");
- return false;
+ return nullptr;
}
// Setup the RTP header parser and the bitrate estimator.
- *parser = webrtc::RtpHeaderParser::Create();
- (*parser)->RegisterRtpHeaderExtension(extension, ExtensionId());
+ auto parser = webrtc::RtpHeaderParser::CreateForTest();
+ parser->RegisterRtpHeaderExtension(extension, ExtensionId());
if (estimator) {
switch (extension) {
case webrtc::kRtpExtensionAbsoluteSendTime: {
- *estimator =
- new webrtc::RemoteBitrateEstimatorAbsSendTime(observer, clock);
+ estimator->reset(
+ new webrtc::RemoteBitrateEstimatorAbsSendTime(observer, clock));
*estimator_used = "AbsoluteSendTimeRemoteBitrateEstimator";
break;
}
case webrtc::kRtpExtensionTransmissionTimeOffset: {
- *estimator =
- new webrtc::RemoteBitrateEstimatorSingleStream(observer, clock);
+ estimator->reset(
+ new webrtc::RemoteBitrateEstimatorSingleStream(observer, clock));
*estimator_used = "RemoteBitrateEstimator";
break;
}
default:
assert(false);
+ return nullptr;
}
}
- return true;
+
+ return parser;
}
diff --git a/modules/remote_bitrate_estimator/tools/bwe_rtp.h b/modules/remote_bitrate_estimator/tools/bwe_rtp.h
index 57484fd..4285f92 100644
--- a/modules/remote_bitrate_estimator/tools/bwe_rtp.h
+++ b/modules/remote_bitrate_estimator/tools/bwe_rtp.h
@@ -11,6 +11,7 @@
#ifndef MODULES_REMOTE_BITRATE_ESTIMATOR_TOOLS_BWE_RTP_H_
#define MODULES_REMOTE_BITRATE_ESTIMATOR_TOOLS_BWE_RTP_H_
+#include <memory>
#include <string>
namespace webrtc {
@@ -23,13 +24,13 @@
}
} // namespace webrtc
-bool ParseArgsAndSetupEstimator(int argc,
- char** argv,
- webrtc::Clock* clock,
- webrtc::RemoteBitrateObserver* observer,
- webrtc::test::RtpFileReader** rtp_reader,
- webrtc::RtpHeaderParser** parser,
- webrtc::RemoteBitrateEstimator** estimator,
- std::string* estimator_used);
+std::unique_ptr<webrtc::RtpHeaderParser> ParseArgsAndSetupEstimator(
+ int argc,
+ char** argv,
+ webrtc::Clock* clock,
+ webrtc::RemoteBitrateObserver* observer,
+ std::unique_ptr<webrtc::test::RtpFileReader>* rtp_reader,
+ std::unique_ptr<webrtc::RemoteBitrateEstimator>* estimator,
+ std::string* estimator_used);
#endif // MODULES_REMOTE_BITRATE_ESTIMATOR_TOOLS_BWE_RTP_H_
diff --git a/modules/remote_bitrate_estimator/tools/rtp_to_text.cc b/modules/remote_bitrate_estimator/tools/rtp_to_text.cc
index c362623..7f1e009 100644
--- a/modules/remote_bitrate_estimator/tools/rtp_to_text.cc
+++ b/modules/remote_bitrate_estimator/tools/rtp_to_text.cc
@@ -13,21 +13,20 @@
#include <memory>
#include "modules/remote_bitrate_estimator/tools/bwe_rtp.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/format_macros.h"
#include "rtc_base/strings/string_builder.h"
#include "test/rtp_file_reader.h"
+#include "test/rtp_header_parser.h"
int main(int argc, char* argv[]) {
- webrtc::test::RtpFileReader* reader;
- webrtc::RtpHeaderParser* parser;
- if (!ParseArgsAndSetupEstimator(argc, argv, NULL, NULL, &reader, &parser,
- NULL, NULL)) {
+ std::unique_ptr<webrtc::test::RtpFileReader> reader;
+ std::unique_ptr<webrtc::RtpHeaderParser> parser(ParseArgsAndSetupEstimator(
+ argc, argv, nullptr, nullptr, &reader, nullptr, nullptr));
+ if (!parser)
return -1;
- }
+
bool arrival_time_only = (argc >= 5 && strncmp(argv[4], "-t", 2) == 0);
- std::unique_ptr<webrtc::test::RtpFileReader> rtp_reader(reader);
- std::unique_ptr<webrtc::RtpHeaderParser> rtp_parser(parser);
+
fprintf(stdout,
"seqnum timestamp ts_offset abs_sendtime recvtime "
"markerbit ssrc size original_size\n");
@@ -35,7 +34,7 @@
int non_zero_abs_send_time = 0;
int non_zero_ts_offsets = 0;
webrtc::test::RtpPacket packet;
- while (rtp_reader->NextPacket(&packet)) {
+ while (reader->NextPacket(&packet)) {
webrtc::RTPHeader header;
parser->Parse(packet.data, packet.length, &header);
if (header.extension.absoluteSendTime != 0)
diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn
index 06ed9bd..24ed0d2 100644
--- a/modules/rtp_rtcp/BUILD.gn
+++ b/modules/rtp_rtcp/BUILD.gn
@@ -129,7 +129,6 @@
"include/flexfec_sender.h",
"include/receive_statistics.h",
"include/remote_ntp_time_estimator.h",
- "include/rtp_header_parser.h",
"include/rtp_rtcp.h",
"include/ulpfec_receiver.h",
"source/absolute_capture_time_receiver.cc",
@@ -175,7 +174,6 @@
"source/rtp_format_vp9.h",
"source/rtp_header_extension_size.cc",
"source/rtp_header_extension_size.h",
- "source/rtp_header_parser.cc",
"source/rtp_packet_history.cc",
"source/rtp_packet_history.h",
"source/rtp_rtcp_config.h",
diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
index e6f8db1..f55e4f8 100644
--- a/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
+++ b/modules/rtp_rtcp/source/rtp_rtcp_impl_unittest.cc
@@ -17,7 +17,6 @@
#include "absl/memory/memory.h"
#include "api/transport/field_trial_based_config.h"
#include "api/video_codecs/video_codec.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/rtp_rtcp/source/playout_delay_oracle.h"
#include "modules/rtp_rtcp/source/rtcp_packet.h"
@@ -28,6 +27,7 @@
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/rtcp_packet_parser.h"
+#include "test/rtp_header_parser.h"
using ::testing::_;
using ::testing::ElementsAre;
@@ -72,7 +72,7 @@
size_t len,
const PacketOptions& options) override {
RTPHeader header;
- std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
+ std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::CreateForTest());
EXPECT_TRUE(parser->Parse(static_cast<const uint8_t*>(data), len, &header));
++rtp_packets_sent_;
last_rtp_header_ = header;
diff --git a/modules/rtp_rtcp/source/rtp_sender_unittest.cc b/modules/rtp_rtcp/source/rtp_sender_unittest.cc
index 125a0b8..ad501df 100644
--- a/modules/rtp_rtcp/source/rtp_sender_unittest.cc
+++ b/modules/rtp_rtcp/source/rtp_sender_unittest.cc
@@ -21,7 +21,6 @@
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
#include "modules/rtp_rtcp/include/rtp_cvo.h"
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "modules/rtp_rtcp/include/rtp_packet_sender.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
@@ -39,6 +38,7 @@
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/mock_transport.h"
+#include "test/rtp_header_parser.h"
namespace webrtc {
diff --git a/modules/rtp_rtcp/source/ulpfec_receiver_unittest.cc b/modules/rtp_rtcp/source/ulpfec_receiver_unittest.cc
index cd1798b..32f3bbb 100644
--- a/modules/rtp_rtcp/source/ulpfec_receiver_unittest.cc
+++ b/modules/rtp_rtcp/source/ulpfec_receiver_unittest.cc
@@ -15,7 +15,6 @@
#include <list>
#include <memory>
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h"
#include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
#include "modules/rtp_rtcp/source/byte_io.h"
@@ -23,6 +22,7 @@
#include "modules/rtp_rtcp/source/forward_error_correction.h"
#include "test/gmock.h"
#include "test/gtest.h"
+#include "test/rtp_header_parser.h"
namespace webrtc {
@@ -177,7 +177,7 @@
size_t length,
uint8_t ulpfec_payload_type) {
RTPHeader header;
- std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
+ std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::CreateForTest());
ASSERT_TRUE(parser->Parse(data, length, &header));
NullRecoveredPacketReceiver null_callback;
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index 814720f..64706c1 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -558,6 +558,7 @@
"../system_wrappers:metrics",
"../test:field_trial",
"../test:fileutils",
+ "../test:rtp_test_utils",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings",
diff --git a/pc/datagram_rtp_transport.cc b/pc/datagram_rtp_transport.cc
index ebf82a7..02e7a6f 100644
--- a/pc/datagram_rtp_transport.cc
+++ b/pc/datagram_rtp_transport.cc
@@ -20,7 +20,6 @@
#include "api/array_view.h"
#include "api/rtc_error.h"
#include "media/base/rtp_utils.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
#include "modules/rtp_rtcp/source/rtp_packet.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
diff --git a/test/BUILD.gn b/test/BUILD.gn
index bc56d89..74c5268 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -131,15 +131,19 @@
"rtp_file_reader.h",
"rtp_file_writer.cc",
"rtp_file_writer.h",
+ "rtp_header_parser.cc",
+ "rtp_header_parser.h",
]
deps = [
"../api:array_view",
+ "../api:rtp_parameters",
"../modules/rtp_rtcp",
"../modules/rtp_rtcp:rtp_rtcp_format",
"../rtc_base:checks",
"../rtc_base:rtc_base_approved",
"../rtc_base/system:arch",
+ "//third_party/abseil-cpp/absl/memory",
]
}
@@ -597,6 +601,7 @@
"direct_transport.h",
]
deps = [
+ ":rtp_test_utils",
"../api:simulated_network_api",
"../api:transport_api",
"../call:call_interfaces",
diff --git a/test/direct_transport.cc b/test/direct_transport.cc
index 4638652..7ca5bb1 100644
--- a/test/direct_transport.cc
+++ b/test/direct_transport.cc
@@ -12,8 +12,8 @@
#include "absl/memory/memory.h"
#include "call/call.h"
#include "call/fake_network_pipe.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/time_utils.h"
+#include "test/rtp_header_parser.h"
#include "test/single_threaded_task_queue.h"
namespace webrtc {
diff --git a/test/fuzzers/BUILD.gn b/test/fuzzers/BUILD.gn
index cd8e217..3618303 100644
--- a/test/fuzzers/BUILD.gn
+++ b/test/fuzzers/BUILD.gn
@@ -616,7 +616,7 @@
"rtp_header_parser_fuzzer.cc",
]
deps = [
- "../../modules/rtp_rtcp",
+ "../:rtp_test_utils",
]
}
@@ -625,7 +625,7 @@
"rtp_header_parser_fuzzer.cc",
]
deps = [
- "../../modules/rtp_rtcp",
+ "../:rtp_test_utils",
]
}
diff --git a/test/fuzzers/rtp_header_parser_fuzzer.cc b/test/fuzzers/rtp_header_parser_fuzzer.cc
index 6d95fdc..d6af5ca 100644
--- a/test/fuzzers/rtp_header_parser_fuzzer.cc
+++ b/test/fuzzers/rtp_header_parser_fuzzer.cc
@@ -15,7 +15,7 @@
#include <memory>
#include <string>
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
+#include "test/rtp_header_parser.h"
namespace webrtc {
@@ -24,7 +24,8 @@
RtpHeaderParser::GetSsrc(data, size);
RTPHeader rtp_header;
- std::unique_ptr<RtpHeaderParser> rtp_header_parser(RtpHeaderParser::Create());
+ std::unique_ptr<RtpHeaderParser> rtp_header_parser(
+ RtpHeaderParser::CreateForTest());
rtp_header_parser->Parse(data, size, &rtp_header);
for (int i = 1; i < kRtpExtensionNumberOfExtensions; ++i) {
diff --git a/test/fuzzers/utils/BUILD.gn b/test/fuzzers/utils/BUILD.gn
index 307cbe1..007c750 100644
--- a/test/fuzzers/utils/BUILD.gn
+++ b/test/fuzzers/utils/BUILD.gn
@@ -23,7 +23,6 @@
"../../../call:call_interfaces",
"../../../common_video",
"../../../media:rtc_internal_video_codecs",
- "../../../modules/rtp_rtcp",
"../../../rtc_base:checks",
"../../../rtc_base:rtc_base_approved",
"../../../rtc_base:rtc_json",
diff --git a/test/fuzzers/utils/rtp_replayer.cc b/test/fuzzers/utils/rtp_replayer.cc
index e430d40..0656f4c 100644
--- a/test/fuzzers/utils/rtp_replayer.cc
+++ b/test/fuzzers/utils/rtp_replayer.cc
@@ -16,7 +16,6 @@
#include "absl/memory/memory.h"
#include "api/task_queue/default_task_queue_factory.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/strings/json.h"
#include "system_wrappers/include/clock.h"
#include "system_wrappers/include/sleep.h"
@@ -24,6 +23,7 @@
#include "test/encoder_settings.h"
#include "test/fake_decoder.h"
#include "test/rtp_file_reader.h"
+#include "test/rtp_header_parser.h"
namespace webrtc {
namespace test {
@@ -158,7 +158,8 @@
break;
case PacketReceiver::DELIVERY_UNKNOWN_SSRC: {
RTPHeader header;
- std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
+ std::unique_ptr<RtpHeaderParser> parser(
+ RtpHeaderParser::CreateForTest());
parser->Parse(packet.data, packet.length, &header);
if (unknown_packets[header.ssrc] == 0) {
@@ -171,7 +172,8 @@
RTC_LOG(LS_ERROR)
<< "Packet error, corrupt packets or incorrect setup?";
RTPHeader header;
- std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
+ std::unique_ptr<RtpHeaderParser> parser(
+ RtpHeaderParser::CreateForTest());
parser->Parse(packet.data, packet.length, &header);
RTC_LOG(LS_ERROR) << "Packet packet_length=" << packet.length
<< " payload_type=" << header.payloadType
diff --git a/modules/rtp_rtcp/source/rtp_header_parser.cc b/test/rtp_header_parser.cc
similarity index 93%
rename from modules/rtp_rtcp/source/rtp_header_parser.cc
rename to test/rtp_header_parser.cc
index 65431d1..1a4ba42 100644
--- a/modules/rtp_rtcp/source/rtp_header_parser.cc
+++ b/test/rtp_header_parser.cc
@@ -7,10 +7,11 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
+#include "test/rtp_header_parser.h"
-#include <string.h>
+#include <memory>
+#include "absl/memory/memory.h"
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "rtc_base/critical_section.h"
@@ -39,8 +40,8 @@
RTC_GUARDED_BY(critical_section_);
};
-RtpHeaderParser* RtpHeaderParser::Create() {
- return new RtpHeaderParserImpl;
+std::unique_ptr<RtpHeaderParser> RtpHeaderParser::CreateForTest() {
+ return absl::make_unique<RtpHeaderParserImpl>();
}
RtpHeaderParserImpl::RtpHeaderParserImpl() {}
diff --git a/modules/rtp_rtcp/include/rtp_header_parser.h b/test/rtp_header_parser.h
similarity index 89%
rename from modules/rtp_rtcp/include/rtp_header_parser.h
rename to test/rtp_header_parser.h
index 0afcb71..851ccf3 100644
--- a/modules/rtp_rtcp/include/rtp_header_parser.h
+++ b/test/rtp_header_parser.h
@@ -7,8 +7,10 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_PARSER_H_
-#define MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_PARSER_H_
+#ifndef TEST_RTP_HEADER_PARSER_H_
+#define TEST_RTP_HEADER_PARSER_H_
+
+#include <memory>
#include "api/rtp_parameters.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@@ -19,7 +21,7 @@
class RtpHeaderParser {
public:
- static RtpHeaderParser* Create();
+ static std::unique_ptr<RtpHeaderParser> CreateForTest();
virtual ~RtpHeaderParser() {}
// Returns true if the packet is an RTCP packet, false otherwise.
@@ -48,4 +50,4 @@
virtual bool DeregisterRtpHeaderExtension(RtpExtension extension) = 0;
};
} // namespace webrtc
-#endif // MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_PARSER_H_
+#endif // TEST_RTP_HEADER_PARSER_H_
diff --git a/test/rtp_rtcp_observer.h b/test/rtp_rtcp_observer.h
index 830c2f1..5763039 100644
--- a/test/rtp_rtcp_observer.h
+++ b/test/rtp_rtcp_observer.h
@@ -18,12 +18,12 @@
#include "api/test/simulated_network.h"
#include "call/simulated_packet_receiver.h"
#include "call/video_send_stream.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "system_wrappers/include/field_trial.h"
#include "test/direct_transport.h"
#include "test/gtest.h"
+#include "test/rtp_header_parser.h"
namespace {
const int kShortTimeoutMs = 500;
@@ -71,7 +71,8 @@
protected:
RtpRtcpObserver() : RtpRtcpObserver(0) {}
explicit RtpRtcpObserver(int event_timeout_ms)
- : parser_(RtpHeaderParser::Create()), timeout_ms_(event_timeout_ms) {}
+ : parser_(RtpHeaderParser::CreateForTest()),
+ timeout_ms_(event_timeout_ms) {}
rtc::Event observation_complete_;
const std::unique_ptr<RtpHeaderParser> parser_;
diff --git a/test/scenario/BUILD.gn b/test/scenario/BUILD.gn
index 9792271..dce7775 100644
--- a/test/scenario/BUILD.gn
+++ b/test/scenario/BUILD.gn
@@ -76,6 +76,7 @@
":column_printer",
"../:fake_video_codecs",
"../:fileutils",
+ "../:rtp_test_utils",
"../:test_common",
"../:test_support",
"../:video_test_common",
diff --git a/test/scenario/call_client.cc b/test/scenario/call_client.cc
index 31435bb..1654afc 100644
--- a/test/scenario/call_client.cc
+++ b/test/scenario/call_client.cc
@@ -203,7 +203,7 @@
clock_(time_controller->GetClock()),
log_writer_factory_(std::move(log_writer_factory)),
network_controller_factory_(log_writer_factory_.get(), config.transport),
- header_parser_(RtpHeaderParser::Create()),
+ header_parser_(RtpHeaderParser::CreateForTest()),
task_queue_(time_controller->GetTaskQueueFactory()->CreateTaskQueue(
"CallClient",
TaskQueueFactory::Priority::NORMAL)) {
diff --git a/test/scenario/call_client.h b/test/scenario/call_client.h
index d2603a8..78c302d 100644
--- a/test/scenario/call_client.h
+++ b/test/scenario/call_client.h
@@ -20,11 +20,11 @@
#include "call/call.h"
#include "modules/audio_device/include/test_audio_device.h"
#include "modules/congestion_controller/goog_cc/test/goog_cc_printer.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/task_queue_for_test.h"
#include "test/logging/log_writer.h"
#include "test/network/network_emulation.h"
+#include "test/rtp_header_parser.h"
#include "test/scenario/column_printer.h"
#include "test/scenario/network_node.h"
#include "test/scenario/scenario_config.h"
diff --git a/video/end_to_end_tests/stats_tests.cc b/video/end_to_end_tests/stats_tests.cc
index e3ba87a..ce1d867 100644
--- a/video/end_to_end_tests/stats_tests.cc
+++ b/video/end_to_end_tests/stats_tests.cc
@@ -611,7 +611,8 @@
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
if (++sent_rtp_packets_ == kPacketNumberToDrop) {
- std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
+ std::unique_ptr<RtpHeaderParser> parser(
+ RtpHeaderParser::CreateForTest());
RTPHeader header;
EXPECT_TRUE(parser->Parse(packet, length, &header));
dropped_rtp_packet_ = header.sequenceNumber;
diff --git a/video/end_to_end_tests/transport_feedback_tests.cc b/video/end_to_end_tests/transport_feedback_tests.cc
index d8ae230..da59405 100644
--- a/video/end_to_end_tests/transport_feedback_tests.cc
+++ b/video/end_to_end_tests/transport_feedback_tests.cc
@@ -50,7 +50,7 @@
BuiltInNetworkBehaviorConfig())),
sender_call,
payload_type_map),
- parser_(RtpHeaderParser::Create()),
+ parser_(RtpHeaderParser::CreateForTest()),
first_media_ssrc_(first_media_ssrc),
rtx_to_media_ssrcs_(ssrc_map),
padding_observed_(false),
diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc
index a1a91b4..33f9898 100644
--- a/video/video_send_stream_tests.cc
+++ b/video/video_send_stream_tests.cc
@@ -24,7 +24,6 @@
#include "call/rtp_transport_controller_send.h"
#include "call/simulated_network.h"
#include "call/video_send_stream.h"
-#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "modules/rtp_rtcp/include/rtp_rtcp.h"
#include "modules/rtp_rtcp/source/rtcp_sender.h"
#include "modules/rtp_rtcp/source/rtp_format_vp9.h"
@@ -53,6 +52,7 @@
#include "test/gtest.h"
#include "test/null_transport.h"
#include "test/rtcp_packet_parser.h"
+#include "test/rtp_header_parser.h"
#include "test/testsupport/perf_test.h"
#include "test/video_encoder_proxy_factory.h"
#include "video/send_statistics_proxy.h"