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/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/include/rtp_header_parser.h b/modules/rtp_rtcp/include/rtp_header_parser.h
deleted file mode 100644
index 0afcb71..0000000
--- a/modules/rtp_rtcp/include/rtp_header_parser.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *  Copyright (c) 2013 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_RTP_RTCP_INCLUDE_RTP_HEADER_PARSER_H_
-#define MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_PARSER_H_
-
-#include "api/rtp_parameters.h"
-#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
-
-namespace webrtc {
-
-struct RTPHeader;
-
-class RtpHeaderParser {
- public:
-  static RtpHeaderParser* Create();
-  virtual ~RtpHeaderParser() {}
-
-  // Returns true if the packet is an RTCP packet, false otherwise.
-  static bool IsRtcp(const uint8_t* packet, size_t length);
-  static absl::optional<uint32_t> GetSsrc(const uint8_t* packet, size_t length);
-
-  // Parses the packet and stores the parsed packet in |header|. Returns true on
-  // success, false otherwise.
-  // This method is thread-safe in the sense that it can parse multiple packets
-  // at once.
-  virtual bool Parse(const uint8_t* packet,
-                     size_t length,
-                     RTPHeader* header) const = 0;
-
-  // Registers an RTP header extension and binds it to |id|.
-  virtual bool RegisterRtpHeaderExtension(RTPExtensionType type,
-                                          uint8_t id) = 0;
-
-  // Registers an RTP header extension.
-  virtual bool RegisterRtpHeaderExtension(RtpExtension extension) = 0;
-
-  // De-registers an RTP header extension.
-  virtual bool DeregisterRtpHeaderExtension(RTPExtensionType type) = 0;
-
-  // De-registers an RTP header extension.
-  virtual bool DeregisterRtpHeaderExtension(RtpExtension extension) = 0;
-};
-}  // namespace webrtc
-#endif  // MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_PARSER_H_
diff --git a/modules/rtp_rtcp/source/rtp_header_parser.cc b/modules/rtp_rtcp/source/rtp_header_parser.cc
deleted file mode 100644
index 65431d1..0000000
--- a/modules/rtp_rtcp/source/rtp_header_parser.cc
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *  Copyright (c) 2013 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/rtp_rtcp/include/rtp_header_parser.h"
-
-#include <string.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"
-#include "rtc_base/thread_annotations.h"
-
-namespace webrtc {
-
-class RtpHeaderParserImpl : public RtpHeaderParser {
- public:
-  RtpHeaderParserImpl();
-  ~RtpHeaderParserImpl() override = default;
-
-  bool Parse(const uint8_t* packet,
-             size_t length,
-             RTPHeader* header) const override;
-
-  bool RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id) override;
-  bool RegisterRtpHeaderExtension(RtpExtension extension) override;
-
-  bool DeregisterRtpHeaderExtension(RTPExtensionType type) override;
-  bool DeregisterRtpHeaderExtension(RtpExtension extension) override;
-
- private:
-  rtc::CriticalSection critical_section_;
-  RtpHeaderExtensionMap rtp_header_extension_map_
-      RTC_GUARDED_BY(critical_section_);
-};
-
-RtpHeaderParser* RtpHeaderParser::Create() {
-  return new RtpHeaderParserImpl;
-}
-
-RtpHeaderParserImpl::RtpHeaderParserImpl() {}
-
-bool RtpHeaderParser::IsRtcp(const uint8_t* packet, size_t length) {
-  RtpUtility::RtpHeaderParser rtp_parser(packet, length);
-  return rtp_parser.RTCP();
-}
-
-absl::optional<uint32_t> RtpHeaderParser::GetSsrc(const uint8_t* packet,
-                                                  size_t length) {
-  RtpUtility::RtpHeaderParser rtp_parser(packet, length);
-  RTPHeader header;
-  if (rtp_parser.Parse(&header, nullptr)) {
-    return header.ssrc;
-  }
-  return absl::nullopt;
-}
-
-bool RtpHeaderParserImpl::Parse(const uint8_t* packet,
-                                size_t length,
-                                RTPHeader* header) const {
-  RtpUtility::RtpHeaderParser rtp_parser(packet, length);
-  *header = RTPHeader();
-
-  RtpHeaderExtensionMap map;
-  {
-    rtc::CritScope cs(&critical_section_);
-    map = rtp_header_extension_map_;
-  }
-
-  const bool valid_rtpheader = rtp_parser.Parse(header, &map);
-  if (!valid_rtpheader) {
-    return false;
-  }
-  return true;
-}
-bool RtpHeaderParserImpl::RegisterRtpHeaderExtension(RtpExtension extension) {
-  rtc::CritScope cs(&critical_section_);
-  return rtp_header_extension_map_.RegisterByUri(extension.id, extension.uri);
-}
-
-bool RtpHeaderParserImpl::RegisterRtpHeaderExtension(RTPExtensionType type,
-                                                     uint8_t id) {
-  rtc::CritScope cs(&critical_section_);
-  return rtp_header_extension_map_.RegisterByType(id, type);
-}
-
-bool RtpHeaderParserImpl::DeregisterRtpHeaderExtension(RtpExtension extension) {
-  rtc::CritScope cs(&critical_section_);
-  return rtp_header_extension_map_.Deregister(
-      rtp_header_extension_map_.GetType(extension.id));
-}
-
-bool RtpHeaderParserImpl::DeregisterRtpHeaderExtension(RTPExtensionType type) {
-  rtc::CritScope cs(&critical_section_);
-  return rtp_header_extension_map_.Deregister(type) == 0;
-}
-}  // namespace webrtc
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;