Fix circular dependencies in webrtc_common.

One reason for the circular deps is that common_types.h is a
historical dumping ground for various structs and defines that
are believed to be generally useful. I tried moving things out
that did not appear to be used downstream (StreamCounters,
RtpCounters etc) and moved the things that seemed used
(RtpHeader + supporting structs) to a new file api/rtp_headers.h.
This makes their place in the api more clear while moving out
the things that don't belong in the API in the first place.

I had to extract out typedefs.h from webrtc_common to resolve
another circular dependency. I believe checks includes typedefs,
but common depends on checks.

Bug: webrtc:7745
Change-Id: I725d49616b1ec0cdc8b74be7c078f7a4d46f084b
Reviewed-on: https://webrtc-review.googlesource.com/33001
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21295}
diff --git a/.gn b/.gn
index ac4ef80..5e3c6ca 100644
--- a/.gn
+++ b/.gn
@@ -21,6 +21,7 @@
 # their includes checked for proper dependencies when you run either
 # "gn check" or "gn gen --check".
 check_targets = [
+  ":webrtc_common",
   "//api/*",
   "//audio/*",
   "//backup/*",
diff --git a/BUILD.gn b/BUILD.gn
index 6153e4f..9b4248b 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -350,11 +350,24 @@
   }
 }
 
+rtc_source_set("typedefs") {
+  sources = [
+    "typedefs.h",
+  ]
+}
+
 rtc_static_library("webrtc_common") {
   sources = [
     "common_types.cc",
     "common_types.h",
-    "typedefs.h",
+  ]
+  deps = [
+    ":typedefs",
+    "api:array_view",
+    "api:optional",
+    "rtc_base:checks",
+    "rtc_base:deprecation",
+    "rtc_base:stringutils",
   ]
 
   if (!build_with_chromium && is_clang) {
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 592039f..94dd865 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -59,6 +59,8 @@
     "proxy.h",
     "rtcerror.cc",
     "rtcerror.h",
+    "rtp_headers.cc",
+    "rtp_headers.h",
     "rtpparameters.cc",
     "rtpparameters.h",
     "rtpreceiverinterface.h",
@@ -84,6 +86,7 @@
   ]
 
   deps = [
+    ":array_view",
     ":optional",
     ":rtc_stats_api",
     ":video_frame_api",
@@ -93,10 +96,14 @@
     # Basically, don't add stuff here. You might break sensitive downstream
     # targets like pnacl. API should not depend on anything outside of this
     # file, really. All these should arguably go away in time.
+    "..:typedefs",
     "..:webrtc_common",
     "../modules/audio_processing:audio_processing_statistics",
+    "../rtc_base:checks",
+    "../rtc_base:deprecation",
     "../rtc_base:rtc_base",
     "../rtc_base:rtc_base_approved",
+    "../rtc_base:stringutils",
   ]
 
   # This is needed until bugs.webrtc.org/7504 is removed so this target can
diff --git a/api/audio_codecs/BUILD.gn b/api/audio_codecs/BUILD.gn
index d2c074d..01dc124 100644
--- a/api/audio_codecs/BUILD.gn
+++ b/api/audio_codecs/BUILD.gn
@@ -29,7 +29,9 @@
     "..:array_view",
     "..:optional",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../rtc_base:checks",
+    "../../rtc_base:deprecation",
     "../../rtc_base:rtc_base_approved",
     "../../rtc_base:sanitizer",
   ]
diff --git a/api/ortc/rtptransportinterface.h b/api/ortc/rtptransportinterface.h
index 3c58fad..716a297 100644
--- a/api/ortc/rtptransportinterface.h
+++ b/api/ortc/rtptransportinterface.h
@@ -16,6 +16,7 @@
 #include "api/optional.h"
 #include "api/ortc/packettransportinterface.h"
 #include "api/rtcerror.h"
+#include "api/rtp_headers.h"
 #include "common_types.h"  // NOLINT(build/include)
 
 namespace webrtc {
diff --git a/api/rtp_headers.cc b/api/rtp_headers.cc
new file mode 100644
index 0000000..a0b1a15
--- /dev/null
+++ b/api/rtp_headers.cc
@@ -0,0 +1,62 @@
+/*
+ *  Copyright (c) 2017 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 "api/rtp_headers.h"
+
+#include <string.h>
+#include <algorithm>
+#include <limits>
+#include <type_traits>
+
+#include "rtc_base/checks.h"
+#include "rtc_base/stringutils.h"
+
+namespace webrtc {
+
+RTPHeaderExtension::RTPHeaderExtension()
+    : hasTransmissionTimeOffset(false),
+      transmissionTimeOffset(0),
+      hasAbsoluteSendTime(false),
+      absoluteSendTime(0),
+      hasTransportSequenceNumber(false),
+      transportSequenceNumber(0),
+      hasAudioLevel(false),
+      voiceActivity(false),
+      audioLevel(0),
+      hasVideoRotation(false),
+      videoRotation(kVideoRotation_0),
+      hasVideoContentType(false),
+      videoContentType(VideoContentType::UNSPECIFIED),
+      has_video_timing(false) {}
+
+RTPHeaderExtension::RTPHeaderExtension(const RTPHeaderExtension& other) =
+    default;
+
+RTPHeaderExtension& RTPHeaderExtension::operator=(
+    const RTPHeaderExtension& other) = default;
+
+RTPHeader::RTPHeader()
+    : markerBit(false),
+      payloadType(0),
+      sequenceNumber(0),
+      timestamp(0),
+      ssrc(0),
+      numCSRCs(0),
+      arrOfCSRCs(),
+      paddingLength(0),
+      headerLength(0),
+      payload_type_frequency(0),
+      extension() {}
+
+RTPHeader::RTPHeader(const RTPHeader& other) = default;
+
+RTPHeader& RTPHeader::operator=(const RTPHeader& other) = default;
+
+}  // namespace webrtc
diff --git a/api/rtp_headers.h b/api/rtp_headers.h
new file mode 100644
index 0000000..2624a33
--- /dev/null
+++ b/api/rtp_headers.h
@@ -0,0 +1,178 @@
+/*
+ *  Copyright (c) 2017 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 API_RTP_HEADERS_H_
+#define API_RTP_HEADERS_H_
+
+#include <stddef.h>
+#include <string.h>
+#include <ostream>
+#include <string>
+#include <vector>
+
+#include "api/array_view.h"
+#include "api/optional.h"
+#include "api/video/video_content_type.h"
+#include "api/video/video_rotation.h"
+#include "api/video/video_timing.h"
+
+#include "rtc_base/checks.h"
+#include "rtc_base/deprecation.h"
+#include "common_types.h"  // NOLINT(build/include)
+#include "typedefs.h"  // NOLINT(build/include)
+
+namespace webrtc {
+
+// Class to represent the value of RTP header extensions that are
+// variable-length strings (e.g., RtpStreamId and RtpMid).
+// Unlike std::string, it can be copied with memcpy and cleared with memset.
+//
+// Empty value represents unset header extension (use empty() to query).
+class StringRtpHeaderExtension {
+ public:
+  // String RTP header extensions are limited to 16 bytes because it is the
+  // maximum length that can be encoded with one-byte header extensions.
+  static constexpr size_t kMaxSize = 16;
+
+  static bool IsLegalName(rtc::ArrayView<const char> name);
+
+  StringRtpHeaderExtension() { value_[0] = 0; }
+  explicit StringRtpHeaderExtension(rtc::ArrayView<const char> value) {
+    Set(value.data(), value.size());
+  }
+  StringRtpHeaderExtension(const StringRtpHeaderExtension&) = default;
+  StringRtpHeaderExtension& operator=(const StringRtpHeaderExtension&) =
+      default;
+
+  bool empty() const { return value_[0] == 0; }
+  const char* data() const { return value_; }
+  size_t size() const { return strnlen(value_, kMaxSize); }
+
+  void Set(rtc::ArrayView<const uint8_t> value) {
+    Set(reinterpret_cast<const char*>(value.data()), value.size());
+  }
+  void Set(const char* data, size_t size);
+
+  friend bool operator==(const StringRtpHeaderExtension& lhs,
+                         const StringRtpHeaderExtension& rhs) {
+    return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
+  }
+  friend bool operator!=(const StringRtpHeaderExtension& lhs,
+                         const StringRtpHeaderExtension& rhs) {
+    return !(lhs == rhs);
+  }
+
+ private:
+  char value_[kMaxSize];
+};
+
+// StreamId represents RtpStreamId which is a string.
+typedef StringRtpHeaderExtension StreamId;
+
+// Mid represents RtpMid which is a string.
+typedef StringRtpHeaderExtension Mid;
+
+struct RTPHeaderExtension {
+  RTPHeaderExtension();
+  RTPHeaderExtension(const RTPHeaderExtension& other);
+  RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
+
+  bool hasTransmissionTimeOffset;
+  int32_t transmissionTimeOffset;
+  bool hasAbsoluteSendTime;
+  uint32_t absoluteSendTime;
+  bool hasTransportSequenceNumber;
+  uint16_t transportSequenceNumber;
+
+  // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
+  // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
+  bool hasAudioLevel;
+  bool voiceActivity;
+  uint8_t audioLevel;
+
+  // For Coordination of Video Orientation. See
+  // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
+  // ts_126114v120700p.pdf
+  bool hasVideoRotation;
+  VideoRotation videoRotation;
+
+  // TODO(ilnik): Refactor this and one above to be rtc::Optional() and remove
+  // a corresponding bool flag.
+  bool hasVideoContentType;
+  VideoContentType videoContentType;
+
+  bool has_video_timing;
+  VideoSendTiming video_timing;
+
+  PlayoutDelay playout_delay = {-1, -1};
+
+  // For identification of a stream when ssrc is not signaled. See
+  // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
+  // TODO(danilchap): Update url from draft to release version.
+  StreamId stream_id;
+  StreamId repaired_stream_id;
+
+  // For identifying the media section used to interpret this RTP packet. See
+  // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
+  Mid mid;
+};
+
+struct RTPHeader {
+  RTPHeader();
+  RTPHeader(const RTPHeader& other);
+  RTPHeader& operator=(const RTPHeader& other);
+
+  bool markerBit;
+  uint8_t payloadType;
+  uint16_t sequenceNumber;
+  uint32_t timestamp;
+  uint32_t ssrc;
+  uint8_t numCSRCs;
+  uint32_t arrOfCSRCs[kRtpCsrcSize];
+  size_t paddingLength;
+  size_t headerLength;
+  int payload_type_frequency;
+  RTPHeaderExtension extension;
+};
+
+// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
+// RTCP mode is described by RFC 5506.
+enum class RtcpMode { kOff, kCompound, kReducedSize };
+
+enum NetworkState {
+  kNetworkUp,
+  kNetworkDown,
+};
+
+struct RtpKeepAliveConfig final {
+  // If no packet has been sent for |timeout_interval_ms|, send a keep-alive
+  // packet. The keep-alive packet is an empty (no payload) RTP packet with a
+  // payload type of 20 as long as the other end has not negotiated the use of
+  // this value. If this value has already been negotiated, then some other
+  // unused static payload type from table 5 of RFC 3551 shall be used and set
+  // in |payload_type|.
+  int64_t timeout_interval_ms = -1;
+  uint8_t payload_type = 20;
+
+  bool operator==(const RtpKeepAliveConfig& o) const {
+    return timeout_interval_ms == o.timeout_interval_ms &&
+           payload_type == o.payload_type;
+  }
+  bool operator!=(const RtpKeepAliveConfig& o) const { return !(*this == o); }
+};
+
+// Currently only VP8/VP9 specific.
+struct RtpPayloadState {
+  int16_t picture_id = -1;
+};
+
+}  // namespace webrtc
+
+#endif  // API_RTP_HEADERS_H_
diff --git a/api/video_codecs/BUILD.gn b/api/video_codecs/BUILD.gn
index f3cb7f1..6f3623d 100644
--- a/api/video_codecs/BUILD.gn
+++ b/api/video_codecs/BUILD.gn
@@ -26,6 +26,7 @@
     "..:optional",
     "..:video_frame_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../common_video",
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base_approved",
diff --git a/audio/utility/BUILD.gn b/audio/utility/BUILD.gn
index f38e0eb..4e01710 100644
--- a/audio/utility/BUILD.gn
+++ b/audio/utility/BUILD.gn
@@ -21,6 +21,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../modules:module_api",
     "../../modules/audio_coding:audio_format_conversion",
     "../../rtc_base:checks",
diff --git a/call/BUILD.gn b/call/BUILD.gn
index 82f6ca1..6f936b8 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -24,6 +24,7 @@
     ":rtp_interfaces",
     ":video_stream_api",
     "..:webrtc_common",
+    "../:typedefs",
     "../api:audio_mixer_api",
     "../api:libjingle_peerconnection_api",
     "../api:optional",
@@ -70,6 +71,7 @@
     ":rtp_interfaces",
     "..:webrtc_common",
     "../api:array_view",
+    "../api:libjingle_peerconnection_api",
     "../api:optional",
     "../modules/rtp_rtcp",
     "../modules/rtp_rtcp:rtp_rtcp_format",
@@ -176,6 +178,7 @@
     "../api:optional",
     "../api:transport_api",
     "../common_video:common_video",
+    "../modules/rtp_rtcp:rtp_rtcp_format",
     "../rtc_base:rtc_base_approved",
   ]
 }
@@ -204,6 +207,7 @@
       ":rtp_sender",
       "..:webrtc_common",
       "../api:array_view",
+      "../api:libjingle_peerconnection_api",
       "../api:mock_audio_mixer",
       "../api/audio_codecs:builtin_audio_decoder_factory",
       "../logging:rtc_event_log_api",
diff --git a/call/flexfec_receive_stream.h b/call/flexfec_receive_stream.h
index a0b7a11..98ce351 100644
--- a/call/flexfec_receive_stream.h
+++ b/call/flexfec_receive_stream.h
@@ -16,6 +16,7 @@
 #include <string>
 #include <vector>
 
+#include "api/rtp_headers.h"
 #include "api/call/transport.h"
 #include "api/rtpparameters.h"
 #include "call/rtp_packet_sink_interface.h"
diff --git a/call/rtcp_demuxer.cc b/call/rtcp_demuxer.cc
index 0adbdf3..0e78dde 100644
--- a/call/rtcp_demuxer.cc
+++ b/call/rtcp_demuxer.cc
@@ -10,6 +10,7 @@
 
 #include "call/rtcp_demuxer.h"
 
+#include "api/rtp_headers.h"
 #include "call/rtcp_packet_sink_interface.h"
 #include "call/rtp_rtcp_demuxer_helper.h"
 #include "common_types.h"  // NOLINT(build/include)
diff --git a/call/rtcp_demuxer_unittest.cc b/call/rtcp_demuxer_unittest.cc
index dd5aa55..0e1c95b 100644
--- a/call/rtcp_demuxer_unittest.cc
+++ b/call/rtcp_demuxer_unittest.cc
@@ -13,6 +13,7 @@
 #include <memory>
 #include <set>
 
+#include "api/rtp_headers.h"
 #include "call/rtcp_packet_sink_interface.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
diff --git a/call/video_receive_stream.h b/call/video_receive_stream.h
index de6f712..924d69a 100644
--- a/call/video_receive_stream.h
+++ b/call/video_receive_stream.h
@@ -16,12 +16,16 @@
 #include <string>
 #include <vector>
 
+#include "api/rtp_headers.h"
 #include "api/call/transport.h"
 #include "api/rtpparameters.h"
+#include "api/video/video_content_type.h"
+#include "api/video/video_timing.h"
 #include "call/rtp_config.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "common_video/include/frame_callback.h"
 #include "media/base/videosinkinterface.h"
+#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "rtc_base/platform_file.h"
 
 namespace webrtc {
diff --git a/call/video_send_stream.h b/call/video_send_stream.h
index e57307d..890a767 100644
--- a/call/video_send_stream.h
+++ b/call/video_send_stream.h
@@ -18,12 +18,14 @@
 
 #include "api/call/transport.h"
 #include "api/rtpparameters.h"
+#include "api/rtp_headers.h"
 #include "call/rtp_config.h"
 #include "call/video_config.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "common_video/include/frame_callback.h"
 #include "media/base/videosinkinterface.h"
 #include "media/base/videosourceinterface.h"
+#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "rtc_base/platform_file.h"
 
 namespace webrtc {
diff --git a/common_audio/BUILD.gn b/common_audio/BUILD.gn
index f601731..27287ec 100644
--- a/common_audio/BUILD.gn
+++ b/common_audio/BUILD.gn
@@ -62,6 +62,7 @@
   deps = [
     ":sinc_resampler",
     "..:webrtc_common",
+    "../:typedefs",
     "../api:optional",
     "../rtc_base:checks",
     "../rtc_base:gtest_prod",
@@ -223,6 +224,7 @@
     ":common_audio_c_arm_asm",
     ":common_audio_cc",
     "..:webrtc_common",
+    "../:typedefs",
     "../rtc_base:checks",
     "../rtc_base:compile_assert_c",
     "../rtc_base:rtc_base_approved",
@@ -241,6 +243,7 @@
   public_configs = [ ":common_audio_config" ]
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../rtc_base:rtc_base_approved",
     "../system_wrappers",
   ]
@@ -252,6 +255,7 @@
   ]
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../rtc_base:gtest_prod",
     "../rtc_base:rtc_base_approved",
     "../system_wrappers",
@@ -447,6 +451,7 @@
       ":fir_filter_factory",
       ":sinc_resampler",
       "..:webrtc_common",
+      "../:typedefs",
       "../rtc_base:checks",
       "../rtc_base:rtc_base_approved",
       "../rtc_base:rtc_base_tests_utils",
diff --git a/common_types.cc b/common_types.cc
index f1b2f1e..07f77b7 100644
--- a/common_types.cc
+++ b/common_types.cc
@@ -20,66 +20,6 @@
 
 namespace webrtc {
 
-StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
-
-constexpr size_t StreamId::kMaxSize;
-
-bool StreamId::IsLegalName(rtc::ArrayView<const char> name) {
-  return (name.size() <= kMaxSize && name.size() > 0 &&
-          std::all_of(name.data(), name.data() + name.size(), isalnum));
-}
-
-void StreamId::Set(const char* data, size_t size) {
-  // If |data| contains \0, the stream id size might become less than |size|.
-  RTC_CHECK_LE(size, kMaxSize);
-  memcpy(value_, data, size);
-  if (size < kMaxSize)
-    value_[size] = 0;
-}
-
-// StreamId is used as member of RTPHeader that is sometimes copied with memcpy
-// and thus assume trivial destructibility.
-static_assert(std::is_trivially_destructible<StreamId>::value, "");
-
-RTPHeaderExtension::RTPHeaderExtension()
-    : hasTransmissionTimeOffset(false),
-      transmissionTimeOffset(0),
-      hasAbsoluteSendTime(false),
-      absoluteSendTime(0),
-      hasTransportSequenceNumber(false),
-      transportSequenceNumber(0),
-      hasAudioLevel(false),
-      voiceActivity(false),
-      audioLevel(0),
-      hasVideoRotation(false),
-      videoRotation(kVideoRotation_0),
-      hasVideoContentType(false),
-      videoContentType(VideoContentType::UNSPECIFIED),
-      has_video_timing(false) {}
-
-RTPHeaderExtension::RTPHeaderExtension(const RTPHeaderExtension& other) =
-    default;
-
-RTPHeaderExtension& RTPHeaderExtension::operator=(
-    const RTPHeaderExtension& other) = default;
-
-RTPHeader::RTPHeader()
-    : markerBit(false),
-      payloadType(0),
-      sequenceNumber(0),
-      timestamp(0),
-      ssrc(0),
-      numCSRCs(0),
-      arrOfCSRCs(),
-      paddingLength(0),
-      headerLength(0),
-      payload_type_frequency(0),
-      extension() {}
-
-RTPHeader::RTPHeader(const RTPHeader& other) = default;
-
-RTPHeader& RTPHeader::operator=(const RTPHeader& other) = default;
-
 VideoCodec::VideoCodec()
     : codecType(kVideoCodecUnknown),
       plName(),
diff --git a/common_types.h b/common_types.h
index 21fdf56..9f1ad8f 100644
--- a/common_types.h
+++ b/common_types.h
@@ -19,9 +19,6 @@
 
 #include "api/array_view.h"
 #include "api/optional.h"
-#include "api/video/video_content_type.h"
-#include "api/video/video_rotation.h"
-#include "api/video/video_timing.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/deprecation.h"
 #include "typedefs.h"  // NOLINT(build/include)
@@ -685,244 +682,6 @@
   int max_ms;
 };
 
-// Class to represent the value of RTP header extensions that are
-// variable-length strings (e.g., RtpStreamId and RtpMid).
-// Unlike std::string, it can be copied with memcpy and cleared with memset.
-//
-// Empty value represents unset header extension (use empty() to query).
-class StringRtpHeaderExtension {
- public:
-  // String RTP header extensions are limited to 16 bytes because it is the
-  // maximum length that can be encoded with one-byte header extensions.
-  static constexpr size_t kMaxSize = 16;
-
-  static bool IsLegalName(rtc::ArrayView<const char> name);
-
-  StringRtpHeaderExtension() { value_[0] = 0; }
-  explicit StringRtpHeaderExtension(rtc::ArrayView<const char> value) {
-    Set(value.data(), value.size());
-  }
-  StringRtpHeaderExtension(const StringRtpHeaderExtension&) = default;
-  StringRtpHeaderExtension& operator=(const StringRtpHeaderExtension&) =
-      default;
-
-  bool empty() const { return value_[0] == 0; }
-  const char* data() const { return value_; }
-  size_t size() const { return strnlen(value_, kMaxSize); }
-
-  void Set(rtc::ArrayView<const uint8_t> value) {
-    Set(reinterpret_cast<const char*>(value.data()), value.size());
-  }
-  void Set(const char* data, size_t size);
-
-  friend bool operator==(const StringRtpHeaderExtension& lhs,
-                         const StringRtpHeaderExtension& rhs) {
-    return strncmp(lhs.value_, rhs.value_, kMaxSize) == 0;
-  }
-  friend bool operator!=(const StringRtpHeaderExtension& lhs,
-                         const StringRtpHeaderExtension& rhs) {
-    return !(lhs == rhs);
-  }
-
- private:
-  char value_[kMaxSize];
-};
-
-// StreamId represents RtpStreamId which is a string.
-typedef StringRtpHeaderExtension StreamId;
-
-// Mid represents RtpMid which is a string.
-typedef StringRtpHeaderExtension Mid;
-
-struct RTPHeaderExtension {
-  RTPHeaderExtension();
-  RTPHeaderExtension(const RTPHeaderExtension& other);
-  RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
-
-  bool hasTransmissionTimeOffset;
-  int32_t transmissionTimeOffset;
-  bool hasAbsoluteSendTime;
-  uint32_t absoluteSendTime;
-  bool hasTransportSequenceNumber;
-  uint16_t transportSequenceNumber;
-
-  // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
-  // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
-  bool hasAudioLevel;
-  bool voiceActivity;
-  uint8_t audioLevel;
-
-  // For Coordination of Video Orientation. See
-  // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
-  // ts_126114v120700p.pdf
-  bool hasVideoRotation;
-  VideoRotation videoRotation;
-
-  // TODO(ilnik): Refactor this and one above to be rtc::Optional() and remove
-  // a corresponding bool flag.
-  bool hasVideoContentType;
-  VideoContentType videoContentType;
-
-  bool has_video_timing;
-  VideoSendTiming video_timing;
-
-  PlayoutDelay playout_delay = {-1, -1};
-
-  // For identification of a stream when ssrc is not signaled. See
-  // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
-  // TODO(danilchap): Update url from draft to release version.
-  StreamId stream_id;
-  StreamId repaired_stream_id;
-
-  // For identifying the media section used to interpret this RTP packet. See
-  // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
-  Mid mid;
-};
-
-struct RTPHeader {
-  RTPHeader();
-  RTPHeader(const RTPHeader& other);
-  RTPHeader& operator=(const RTPHeader& other);
-
-  bool markerBit;
-  uint8_t payloadType;
-  uint16_t sequenceNumber;
-  uint32_t timestamp;
-  uint32_t ssrc;
-  uint8_t numCSRCs;
-  uint32_t arrOfCSRCs[kRtpCsrcSize];
-  size_t paddingLength;
-  size_t headerLength;
-  int payload_type_frequency;
-  RTPHeaderExtension extension;
-};
-
-struct RtpPacketCounter {
-  RtpPacketCounter()
-      : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
-
-  void Add(const RtpPacketCounter& other) {
-    header_bytes += other.header_bytes;
-    payload_bytes += other.payload_bytes;
-    padding_bytes += other.padding_bytes;
-    packets += other.packets;
-  }
-
-  void Subtract(const RtpPacketCounter& other) {
-    RTC_DCHECK_GE(header_bytes, other.header_bytes);
-    header_bytes -= other.header_bytes;
-    RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
-    payload_bytes -= other.payload_bytes;
-    RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
-    padding_bytes -= other.padding_bytes;
-    RTC_DCHECK_GE(packets, other.packets);
-    packets -= other.packets;
-  }
-
-  void AddPacket(size_t packet_length, const RTPHeader& header) {
-    ++packets;
-    header_bytes += header.headerLength;
-    padding_bytes += header.paddingLength;
-    payload_bytes +=
-        packet_length - (header.headerLength + header.paddingLength);
-  }
-
-  size_t TotalBytes() const {
-    return header_bytes + payload_bytes + padding_bytes;
-  }
-
-  size_t header_bytes;   // Number of bytes used by RTP headers.
-  size_t payload_bytes;  // Payload bytes, excluding RTP headers and padding.
-  size_t padding_bytes;  // Number of padding bytes.
-  uint32_t packets;      // Number of packets.
-};
-
-// Data usage statistics for a (rtp) stream.
-struct StreamDataCounters {
-  StreamDataCounters();
-
-  void Add(const StreamDataCounters& other) {
-    transmitted.Add(other.transmitted);
-    retransmitted.Add(other.retransmitted);
-    fec.Add(other.fec);
-    if (other.first_packet_time_ms != -1 &&
-        (other.first_packet_time_ms < first_packet_time_ms ||
-         first_packet_time_ms == -1)) {
-      // Use oldest time.
-      first_packet_time_ms = other.first_packet_time_ms;
-    }
-  }
-
-  void Subtract(const StreamDataCounters& other) {
-    transmitted.Subtract(other.transmitted);
-    retransmitted.Subtract(other.retransmitted);
-    fec.Subtract(other.fec);
-    if (other.first_packet_time_ms != -1 &&
-        (other.first_packet_time_ms > first_packet_time_ms ||
-         first_packet_time_ms == -1)) {
-      // Use youngest time.
-      first_packet_time_ms = other.first_packet_time_ms;
-    }
-  }
-
-  int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
-    return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
-  }
-
-  // Returns the number of bytes corresponding to the actual media payload (i.e.
-  // RTP headers, padding, retransmissions and fec packets are excluded).
-  // Note this function does not have meaning for an RTX stream.
-  size_t MediaPayloadBytes() const {
-    return transmitted.payload_bytes - retransmitted.payload_bytes -
-           fec.payload_bytes;
-  }
-
-  int64_t first_packet_time_ms;    // Time when first packet is sent/received.
-  RtpPacketCounter transmitted;    // Number of transmitted packets/bytes.
-  RtpPacketCounter retransmitted;  // Number of retransmitted packets/bytes.
-  RtpPacketCounter fec;            // Number of redundancy packets/bytes.
-};
-
-// Callback, called whenever byte/packet counts have been updated.
-class StreamDataCountersCallback {
- public:
-  virtual ~StreamDataCountersCallback() {}
-
-  virtual void DataCountersUpdated(const StreamDataCounters& counters,
-                                   uint32_t ssrc) = 0;
-};
-
-// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
-// RTCP mode is described by RFC 5506.
-enum class RtcpMode { kOff, kCompound, kReducedSize };
-
-enum NetworkState {
-  kNetworkUp,
-  kNetworkDown,
-};
-
-struct RtpKeepAliveConfig final {
-  // If no packet has been sent for |timeout_interval_ms|, send a keep-alive
-  // packet. The keep-alive packet is an empty (no payload) RTP packet with a
-  // payload type of 20 as long as the other end has not negotiated the use of
-  // this value. If this value has already been negotiated, then some other
-  // unused static payload type from table 5 of RFC 3551 shall be used and set
-  // in |payload_type|.
-  int64_t timeout_interval_ms = -1;
-  uint8_t payload_type = 20;
-
-  bool operator==(const RtpKeepAliveConfig& o) const {
-    return timeout_interval_ms == o.timeout_interval_ms &&
-           payload_type == o.payload_type;
-  }
-  bool operator!=(const RtpKeepAliveConfig& o) const { return !(*this == o); }
-};
-
-// Currently only VP8/VP9 specific.
-struct RtpPayloadState {
-  int16_t picture_id = -1;
-};
-
 }  // namespace webrtc
 
 #endif  // COMMON_TYPES_H_
diff --git a/common_video/include/video_frame.h b/common_video/include/video_frame.h
index 188d5e5..0c145fa 100644
--- a/common_video/include/video_frame.h
+++ b/common_video/include/video_frame.h
@@ -16,6 +16,7 @@
 // to refactor and clean up related interfaces, at which point it
 // should be moved to somewhere under api/.
 
+#include "api/rtp_headers.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "typedefs.h"  // NOLINT(build/include)
 
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index 0ab9bc8..4e733d0 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -509,6 +509,7 @@
     deps = [
       "../api:video_frame_api_i420",
       "../rtc_base:checks",
+      "../rtc_base:stringutils",
     ]
     if (is_win) {
       sources += [
@@ -569,6 +570,7 @@
     deps = [
       "..:webrtc_common",
       "../rtc_base:rtc_base_approved",
+      "../rtc_base:stringutils",
       "../rtc_tools:command_line_parser",
     ]
     if (!build_with_chromium && is_clang) {
@@ -727,6 +729,7 @@
       "../rtc_base:checks",
       "../rtc_base:rtc_base",
       "../rtc_base:rtc_base_approved",
+      "../rtc_base:stringutils",
       "../system_wrappers:field_trial_default",
     ]
   }
diff --git a/logging/BUILD.gn b/logging/BUILD.gn
index bfa20aa..981231b 100644
--- a/logging/BUILD.gn
+++ b/logging/BUILD.gn
@@ -71,6 +71,7 @@
 
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../api:array_view",
     "../api:libjingle_logging_api",
     "../api:libjingle_peerconnection_api",
diff --git a/logging/rtc_event_log/rtc_stream_config.h b/logging/rtc_event_log/rtc_stream_config.h
index e43ee7e..771ba66 100644
--- a/logging/rtc_event_log/rtc_stream_config.h
+++ b/logging/rtc_event_log/rtc_stream_config.h
@@ -14,6 +14,7 @@
 #include <string>
 #include <vector>
 
+#include "api/rtp_headers.h"
 #include "api/rtpparameters.h"
 #include "common_types.h"  // NOLINT(build/include)
 
diff --git a/media/BUILD.gn b/media/BUILD.gn
index ac03a7d..2271339 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -57,6 +57,7 @@
   deps = [
     "../rtc_base:checks",
     "../rtc_base:sanitizer",
+    "../rtc_base:stringutils",
   ]
   public_deps = []
   sources = [
@@ -133,6 +134,7 @@
     "../call:call_interfaces",
     "../modules/video_coding:video_coding_utility",
     "../rtc_base:checks",
+    "../rtc_base:stringutils",
     "../system_wrappers:field_trial_api",
     "../system_wrappers:metrics_api",
     "//third_party/libyuv",
@@ -347,6 +349,7 @@
       "../modules/video_coding:video_coding_utility",
       "../p2p:rtc_p2p",
       "../rtc_base:checks",
+      "../rtc_base:stringutils",
     ]
     sources = [
       "base/fakemediaengine.h",
@@ -438,6 +441,7 @@
       "../pc:rtc_pc",
       "../pc:rtc_pc_base",
       "../rtc_base:checks",
+      "../rtc_base:stringutils",
       "../test:field_trial",
     ]
     sources = [
diff --git a/media/base/mediachannel.h b/media/base/mediachannel.h
index 91fe33e..5768944 100644
--- a/media/base/mediachannel.h
+++ b/media/base/mediachannel.h
@@ -21,6 +21,7 @@
 #include "api/optional.h"
 #include "api/rtpparameters.h"
 #include "api/rtpreceiverinterface.h"
+#include "api/video/video_content_type.h"
 #include "api/video/video_timing.h"
 #include "call/video_config.h"
 #include "media/base/codec.h"
diff --git a/modules/BUILD.gn b/modules/BUILD.gn
index 2c1a042..33394f4 100644
--- a/modules/BUILD.gn
+++ b/modules/BUILD.gn
@@ -34,6 +34,7 @@
   ]
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../api:optional",
   ]
 }
@@ -46,9 +47,12 @@
   deps = [
     ":module_api_public",
     "..:webrtc_common",
+    "../:typedefs",
+    "../api:libjingle_peerconnection_api",
     "../api:optional",
     "../api:video_frame_api",
     "../api:video_frame_api_i420",
+    "../rtc_base:deprecation",
     "../rtc_base:rtc_base_approved",
     "video_coding:codec_globals_headers",
   ]
diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn
index 9c674d4..6365d56 100644
--- a/modules/audio_coding/BUILD.gn
+++ b/modules/audio_coding/BUILD.gn
@@ -65,6 +65,7 @@
     "acm2/rent_a_codec.h",
   ]
   deps = [
+           "../../:typedefs",
            "../../rtc_base:checks",
            "../../api:array_view",
            "../../api:optional",
@@ -96,6 +97,7 @@
   deps = [
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
   ]
 }
 
@@ -132,6 +134,8 @@
   }
 
   deps = audio_coding_deps + [
+           "../../rtc_base:deprecation",
+           "../../:typedefs",
            "../../rtc_base:checks",
            "../../system_wrappers:metrics_api",
            "..:module_api",
@@ -177,6 +181,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:array_view",
     "../../api/audio_codecs:audio_codecs_api",
     "../../common_audio",
@@ -241,6 +246,7 @@
   ]
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
   ]
 }
 
@@ -282,6 +288,7 @@
   ]
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
   ]
 }
 
@@ -461,6 +468,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api/audio_codecs:audio_codecs_api",
     "../../common_audio",
     "../../rtc_base:checks",
@@ -569,6 +577,7 @@
   deps = [
     ":isac_common",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../common_audio",
     "../../rtc_base:checks",
     "../../rtc_base:compile_assert_c",
@@ -675,6 +684,7 @@
   deps = [
     ":isac_common",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api/audio_codecs:audio_codecs_api",
     "../../common_audio",
     "../../rtc_base:checks",
@@ -799,6 +809,7 @@
   public_configs = [ ":pcm16b_config" ]
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
   ]
 }
 
@@ -856,6 +867,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base_approved",
   ]
@@ -1042,6 +1054,8 @@
     ":neteq_decoder_enum",
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
+    "../../api:libjingle_peerconnection_api",
     "../../api:optional",
     "../../api/audio_codecs:audio_codecs_api",
     "../../common_audio",
@@ -1084,6 +1098,8 @@
     ":neteq",
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
+    "../../api:libjingle_peerconnection_api",
     "../../api:optional",
     "../../api/audio_codecs:audio_codecs_api",
     "../../api/audio_codecs:builtin_audio_decoder_factory",
@@ -1121,7 +1137,9 @@
     ":pcm16b",
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:array_view",
+    "../../api:libjingle_peerconnection_api",
     "../../common_audio",
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base_approved",
@@ -1169,6 +1187,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:array_view",
     "../../api:optional",
     "../../api/audio_codecs:audio_codecs_api",
@@ -1195,6 +1214,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../common_audio",
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base_approved",
@@ -1308,6 +1328,7 @@
       ":pcm16b_c",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api:optional",
       "../../api/audio_codecs:builtin_audio_decoder_factory",
       "../../rtc_base:rtc_base_approved",
@@ -1339,6 +1360,7 @@
       ":neteq_test_support",
       ":neteq_test_tools",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api/audio_codecs/opus:audio_encoder_opus",
       "../../rtc_base:protobuf_utils",
       "../../rtc_base:rtc_base_approved",
@@ -1411,6 +1433,7 @@
       ":audio_coding_module_typedefs",
       ":audio_format_conversion",
       "..:module_api",
+      "../../:typedefs",
       "../../:webrtc_common",
       "../../api:optional",
       "../../rtc_base:rtc_base_approved",
@@ -1441,6 +1464,7 @@
       ":audio_coding",
       ":audio_format_conversion",
       "..:module_api",
+      "../../:typedefs",
       "../../:webrtc_common",
       "../../api:optional",
       "../../rtc_base:rtc_base_approved",
@@ -1519,6 +1543,7 @@
       defines = []
       deps = [
         "..:module_api",
+        "../../:typedefs",
         "../../rtc_base:checks",
       ]
       sources = [
@@ -1567,7 +1592,9 @@
   rtc_test("audio_codec_speed_tests") {
     testonly = true
     defines = []
-    deps = []
+    deps = [
+      "../../:typedefs",
+    ]
     sources = [
       "codecs/isac/fix/test/isac_speed_test.cc",
       "codecs/opus/opus_speed_test.cc",
@@ -1626,6 +1653,7 @@
       ":pcm16b",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api/audio_codecs:audio_codecs_api",
       "../../api/audio_codecs:builtin_audio_decoder_factory",
       "../../rtc_base:checks",
@@ -1653,6 +1681,7 @@
       ":neteq_test_tools",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api/audio_codecs:builtin_audio_decoder_factory",
       "../../rtc_base:checks",
       "../../rtc_base:rtc_base_approved",
@@ -1665,6 +1694,7 @@
     testonly = true
 
     deps = audio_coding_deps + [
+             "../../:typedefs",
              ":audio_coding",
              ":neteq_input_audio_tools",
              "../../api/audio_codecs/g711:audio_encoder_g711",
@@ -1688,6 +1718,7 @@
     testonly = true
 
     deps = audio_coding_deps + [
+             "../../:typedefs",
              "../../system_wrappers:system_wrappers_default",
              "../rtp_rtcp:rtp_rtcp_format",
              "../../api:array_view",
@@ -1768,6 +1799,7 @@
       ":neteq",
       ":neteq_test_support",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../rtc_base:rtc_base_approved",
       "../../system_wrappers:system_wrappers_default",
       "../../test:test_support",
@@ -1915,6 +1947,7 @@
     deps = [
       ":g722",
       "../..:webrtc_common",
+      "../../:typedefs",
     ]
   }
 
@@ -2098,6 +2131,7 @@
       ":webrtc_opus",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api/audio_codecs:audio_codecs_api",
       "../../api/audio_codecs:builtin_audio_decoder_factory",
       "../../api/audio_codecs:builtin_audio_encoder_factory",
diff --git a/modules/audio_coding/neteq/include/neteq.h b/modules/audio_coding/neteq/include/neteq.h
index 00ed7cd..0d47f21 100644
--- a/modules/audio_coding/neteq/include/neteq.h
+++ b/modules/audio_coding/neteq/include/neteq.h
@@ -18,6 +18,7 @@
 
 #include "api/audio_codecs/audio_decoder.h"
 #include "api/optional.h"
+#include "api/rtp_headers.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "modules/audio_coding/neteq/neteq_decoder_enum.h"
 #include "rtc_base/constructormagic.h"
diff --git a/modules/audio_coding/neteq/tools/packet.h b/modules/audio_coding/neteq/tools/packet.h
index a72f7d1..94d45c5 100644
--- a/modules/audio_coding/neteq/tools/packet.h
+++ b/modules/audio_coding/neteq/tools/packet.h
@@ -14,6 +14,7 @@
 #include <list>
 #include <memory>
 
+#include "api/rtp_headers.h"  // NOLINT(build/include)
 #include "common_types.h"  // NOLINT(build/include)
 #include "rtc_base/constructormagic.h"
 #include "typedefs.h"  // NOLINT(build/include)
diff --git a/modules/audio_coding/neteq/tools/rtp_generator.h b/modules/audio_coding/neteq/tools/rtp_generator.h
index b705f83..3b3cca9 100644
--- a/modules/audio_coding/neteq/tools/rtp_generator.h
+++ b/modules/audio_coding/neteq/tools/rtp_generator.h
@@ -11,6 +11,7 @@
 #ifndef MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_
 #define MODULES_AUDIO_CODING_NETEQ_TOOLS_RTP_GENERATOR_H_
 
+#include "api/rtp_headers.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "rtc_base/constructormagic.h"
 #include "typedefs.h"  // NOLINT(build/include)
diff --git a/modules/audio_device/BUILD.gn b/modules/audio_device/BUILD.gn
index 3174ee9..6c19146 100644
--- a/modules/audio_device/BUILD.gn
+++ b/modules/audio_device/BUILD.gn
@@ -100,6 +100,7 @@
   deps = [
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:array_view",
     "../../common_audio",
     "../../rtc_base:checks",
diff --git a/modules/audio_mixer/BUILD.gn b/modules/audio_mixer/BUILD.gn
index cffd1a8..1318398 100644
--- a/modules/audio_mixer/BUILD.gn
+++ b/modules/audio_mixer/BUILD.gn
@@ -36,6 +36,7 @@
     ":audio_frame_manipulator",
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:array_view",
     "../../api:audio_mixer_api",
     "../../audio/utility:audio_frame_operations",
diff --git a/modules/audio_processing/BUILD.gn b/modules/audio_processing/BUILD.gn
index b190f02..d879076 100644
--- a/modules/audio_processing/BUILD.gn
+++ b/modules/audio_processing/BUILD.gn
@@ -226,10 +226,12 @@
     ":audio_processing_statistics",
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:array_view",
     "../../api:optional",
     "../../audio/utility:audio_frame_operations",
     "../../rtc_base:checks",
+    "../../rtc_base:deprecation",
     "../../rtc_base:gtest_prod",
     "../../rtc_base:protobuf_utils",
     "../../rtc_base:sanitizer",
@@ -341,6 +343,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../common_audio",
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base_approved",
@@ -371,6 +374,7 @@
     "../../api:array_view",
     "../../common_audio:common_audio",
     "../../rtc_base:rtc_base_approved",
+    "../../rtc_base:stringutils",
   ]
   defines = []
   if (apm_debug_dump) {
@@ -404,6 +408,7 @@
     ":apm_logging",
     ":audio_processing_statistics",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../common_audio:common_audio",
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base_approved",
@@ -582,6 +587,7 @@
       ":audioproc_test_utils",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api:array_view",
       "../../api:optional",
       "../../common_audio:common_audio",
@@ -768,6 +774,7 @@
         "../../rtc_base:protobuf_utils",
         "../../rtc_base:rtc_base_approved",
         "../../rtc_base:rtc_task_queue",
+        "../../rtc_base:stringutils",
         "../../system_wrappers",
         "../../system_wrappers:system_wrappers_default",
         "../../test:test_support",
@@ -819,6 +826,7 @@
       ":audio_processing",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../common_audio:common_audio",
       "../../rtc_base:rtc_base_approved",
       "../../system_wrappers",
@@ -838,6 +846,7 @@
     deps = [
       ":audio_processing",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../system_wrappers",
       "../../system_wrappers:metrics_default",
     ]
@@ -892,6 +901,7 @@
       deps = [
         ":audioproc_debug_proto",
         "../..:webrtc_common",
+        "../../:typedefs",
         "../../rtc_base:protobuf_utils",
         "../../rtc_base:rtc_base_approved",
       ]
diff --git a/modules/audio_processing/test/conversational_speech/BUILD.gn b/modules/audio_processing/test/conversational_speech/BUILD.gn
index 9cedd6e..00e4730 100644
--- a/modules/audio_processing/test/conversational_speech/BUILD.gn
+++ b/modules/audio_processing/test/conversational_speech/BUILD.gn
@@ -45,6 +45,7 @@
   ]
   deps = [
     "../../../..:webrtc_common",
+    "../../../../:typedefs",
     "../../../../api:array_view",
     "../../../../common_audio",
     "../../../../rtc_base:checks",
@@ -65,6 +66,7 @@
   deps = [
     ":lib",
     "../../../..:webrtc_common",
+    "../../../../:typedefs",
     "../../../../api:array_view",
     "../../../../api:optional",
     "../../../../common_audio",
diff --git a/modules/congestion_controller/BUILD.gn b/modules/congestion_controller/BUILD.gn
index 58d2e25..c014934 100644
--- a/modules/congestion_controller/BUILD.gn
+++ b/modules/congestion_controller/BUILD.gn
@@ -49,6 +49,7 @@
   deps = [
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:optional",
     "../../logging:rtc_event_log_api",
     "../../rtc_base:checks",
diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn
index 277683a..8e8d92d 100644
--- a/modules/desktop_capture/BUILD.gn
+++ b/modules/desktop_capture/BUILD.gn
@@ -28,6 +28,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
   ]
@@ -89,6 +90,7 @@
       ":desktop_capture_mock",
       ":primitives",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../rtc_base:checks",
       "../../rtc_base:rtc_base_approved",
       "../../system_wrappers:cpu_features_api",
@@ -333,6 +335,7 @@
   deps = [
     ":primitives",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:refcountedbase",
     "../../rtc_base:checks",
     "../../rtc_base:rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
diff --git a/modules/include/module_common_types.h b/modules/include/module_common_types.h
index 1d89c7d..94ccbdc 100644
--- a/modules/include/module_common_types.h
+++ b/modules/include/module_common_types.h
@@ -18,6 +18,7 @@
 #include <limits>
 
 #include "api/optional.h"
+#include "api/rtp_headers.h"
 #include "api/video/video_rotation.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "modules/include/module_common_types_public.h"
diff --git a/modules/media_file/BUILD.gn b/modules/media_file/BUILD.gn
index a3f3312..589b281 100644
--- a/modules/media_file/BUILD.gn
+++ b/modules/media_file/BUILD.gn
@@ -35,6 +35,7 @@
   deps = [
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../common_audio",
     "../../rtc_base:rtc_base_approved",
   ]
diff --git a/modules/pacing/BUILD.gn b/modules/pacing/BUILD.gn
index 428a99e..6b76c64 100644
--- a/modules/pacing/BUILD.gn
+++ b/modules/pacing/BUILD.gn
@@ -34,6 +34,7 @@
 
   deps = [
     "..:module_api",
+    "../../:typedefs",
     "../../:webrtc_common",
     "../../api:optional",
     "../../logging:rtc_event_log_api",
diff --git a/modules/remote_bitrate_estimator/BUILD.gn b/modules/remote_bitrate_estimator/BUILD.gn
index f0fac54..a5dd014 100644
--- a/modules/remote_bitrate_estimator/BUILD.gn
+++ b/modules/remote_bitrate_estimator/BUILD.gn
@@ -46,6 +46,7 @@
 
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:optional",
     "../../modules:module_api",
     "../../modules/rtp_rtcp:rtp_rtcp_format",
@@ -140,6 +141,7 @@
       ":remote_bitrate_estimator",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api:optional",
       "../../rtc_base:checks",
       "../../rtc_base:gtest_prod",
diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn
index e3f35b8..4ae32cd 100644
--- a/modules/rtp_rtcp/BUILD.gn
+++ b/modules/rtp_rtcp/BUILD.gn
@@ -82,12 +82,14 @@
   deps = [
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:array_view",
     "../../api:libjingle_peerconnection_api",
     "../../api:optional",
     "../../api/audio_codecs:audio_codecs_api",
     "../../common_video",
     "../../rtc_base:checks",
+    "../../rtc_base:deprecation",
     "../../rtc_base:rtc_base_approved",
     "../../system_wrappers",
   ]
@@ -192,6 +194,7 @@
     ":rtp_rtcp_format",
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:array_view",
     "../../api:libjingle_peerconnection_api",
     "../../api:optional",
@@ -200,11 +203,13 @@
     "../../common_video",
     "../../logging:rtc_event_log_api",
     "../../rtc_base:checks",
+    "../../rtc_base:deprecation",
     "../../rtc_base:gtest_prod",
     "../../rtc_base:rate_limiter",
     "../../rtc_base:rtc_base_approved",
     "../../rtc_base:rtc_numerics",
     "../../rtc_base:sequenced_task_checker",
+    "../../rtc_base:stringutils",
     "../../system_wrappers",
     "../../system_wrappers:field_trial_api",
     "../../system_wrappers:metrics_api",
@@ -398,6 +403,7 @@
       ":rtp_rtcp_format",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api:array_view",
       "../../api:libjingle_peerconnection_api",
       "../../api:optional",
diff --git a/modules/rtp_rtcp/include/receive_statistics.h b/modules/rtp_rtcp/include/receive_statistics.h
index ee7dbbb..55c2c05 100644
--- a/modules/rtp_rtcp/include/receive_statistics.h
+++ b/modules/rtp_rtcp/include/receive_statistics.h
@@ -17,6 +17,7 @@
 #include "modules/include/module.h"
 #include "modules/include/module_common_types.h"
 #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
+#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "typedefs.h"  // NOLINT(build/include)
 
 namespace webrtc {
diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.cc b/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
index af3714b..d9b082b 100644
--- a/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
+++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
@@ -12,6 +12,27 @@
 
 namespace webrtc {
 
+StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
+
+constexpr size_t StreamId::kMaxSize;
+
+bool StreamId::IsLegalName(rtc::ArrayView<const char> name) {
+  return (name.size() <= kMaxSize && name.size() > 0 &&
+          std::all_of(name.data(), name.data() + name.size(), isalnum));
+}
+
+void StreamId::Set(const char* data, size_t size) {
+  // If |data| contains \0, the stream id size might become less than |size|.
+  RTC_CHECK_LE(size, kMaxSize);
+  memcpy(value_, data, size);
+  if (size < kMaxSize)
+    value_[size] = 0;
+}
+
+// StreamId is used as member of RTPHeader that is sometimes copied with memcpy
+// and thus assume trivial destructibility.
+static_assert(std::is_trivially_destructible<StreamId>::value, "");
+
 PayloadUnion::PayloadUnion(const AudioPayload& payload)
     : audio_payload_(payload) {}
 PayloadUnion::PayloadUnion(const VideoPayload& payload)
diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.h b/modules/rtp_rtcp/include/rtp_rtcp_defines.h
index 37ef332..97a2a98 100644
--- a/modules/rtp_rtcp/include/rtp_rtcp_defines.h
+++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.h
@@ -16,6 +16,7 @@
 #include <vector>
 
 #include "api/audio_codecs/audio_format.h"
+#include "api/rtp_headers.h"
 #include "common_types.h"  // NOLINT(build/include)
 #include "modules/include/module_common_types.h"
 #include "rtc_base/deprecation.h"
@@ -496,5 +497,100 @@
   virtual uint16_t AllocateSequenceNumber() = 0;
 };
 
+struct RtpPacketCounter {
+  RtpPacketCounter()
+      : header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
+
+  void Add(const RtpPacketCounter& other) {
+    header_bytes += other.header_bytes;
+    payload_bytes += other.payload_bytes;
+    padding_bytes += other.padding_bytes;
+    packets += other.packets;
+  }
+
+  void Subtract(const RtpPacketCounter& other) {
+    RTC_DCHECK_GE(header_bytes, other.header_bytes);
+    header_bytes -= other.header_bytes;
+    RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
+    payload_bytes -= other.payload_bytes;
+    RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
+    padding_bytes -= other.padding_bytes;
+    RTC_DCHECK_GE(packets, other.packets);
+    packets -= other.packets;
+  }
+
+  void AddPacket(size_t packet_length, const RTPHeader& header) {
+    ++packets;
+    header_bytes += header.headerLength;
+    padding_bytes += header.paddingLength;
+    payload_bytes +=
+        packet_length - (header.headerLength + header.paddingLength);
+  }
+
+  size_t TotalBytes() const {
+    return header_bytes + payload_bytes + padding_bytes;
+  }
+
+  size_t header_bytes;   // Number of bytes used by RTP headers.
+  size_t payload_bytes;  // Payload bytes, excluding RTP headers and padding.
+  size_t padding_bytes;  // Number of padding bytes.
+  uint32_t packets;      // Number of packets.
+};
+
+// Data usage statistics for a (rtp) stream.
+struct StreamDataCounters {
+  StreamDataCounters();
+
+  void Add(const StreamDataCounters& other) {
+    transmitted.Add(other.transmitted);
+    retransmitted.Add(other.retransmitted);
+    fec.Add(other.fec);
+    if (other.first_packet_time_ms != -1 &&
+        (other.first_packet_time_ms < first_packet_time_ms ||
+         first_packet_time_ms == -1)) {
+      // Use oldest time.
+      first_packet_time_ms = other.first_packet_time_ms;
+    }
+  }
+
+  void Subtract(const StreamDataCounters& other) {
+    transmitted.Subtract(other.transmitted);
+    retransmitted.Subtract(other.retransmitted);
+    fec.Subtract(other.fec);
+    if (other.first_packet_time_ms != -1 &&
+        (other.first_packet_time_ms > first_packet_time_ms ||
+         first_packet_time_ms == -1)) {
+      // Use youngest time.
+      first_packet_time_ms = other.first_packet_time_ms;
+    }
+  }
+
+  int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
+    return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
+  }
+
+  // Returns the number of bytes corresponding to the actual media payload (i.e.
+  // RTP headers, padding, retransmissions and fec packets are excluded).
+  // Note this function does not have meaning for an RTX stream.
+  size_t MediaPayloadBytes() const {
+    return transmitted.payload_bytes - retransmitted.payload_bytes -
+           fec.payload_bytes;
+  }
+
+  int64_t first_packet_time_ms;    // Time when first packet is sent/received.
+  RtpPacketCounter transmitted;    // Number of transmitted packets/bytes.
+  RtpPacketCounter retransmitted;  // Number of retransmitted packets/bytes.
+  RtpPacketCounter fec;            // Number of redundancy packets/bytes.
+};
+
+// Callback, called whenever byte/packet counts have been updated.
+class StreamDataCountersCallback {
+ public:
+  virtual ~StreamDataCountersCallback() {}
+
+  virtual void DataCountersUpdated(const StreamDataCounters& counters,
+                                   uint32_t ssrc) = 0;
+};
+
 }  // namespace webrtc
 #endif  // MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_DEFINES_H_
diff --git a/modules/utility/BUILD.gn b/modules/utility/BUILD.gn
index 7002fd2..e3de364 100644
--- a/modules/utility/BUILD.gn
+++ b/modules/utility/BUILD.gn
@@ -32,6 +32,7 @@
   deps = [
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../audio/utility:audio_frame_operations",
     "../../common_audio",
     "../../rtc_base:checks",
diff --git a/modules/video_capture/BUILD.gn b/modules/video_capture/BUILD.gn
index f5dfa05..2953053 100644
--- a/modules/video_capture/BUILD.gn
+++ b/modules/video_capture/BUILD.gn
@@ -28,10 +28,12 @@
   deps = [
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:video_frame_api_i420",
     "../../common_video",
     "../../media:rtc_media_base",
     "../../rtc_base:rtc_base_approved",
+    "../../rtc_base:stringutils",
     "../../system_wrappers",
     "//third_party/libyuv",
   ]
diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn
index 4e4ab75..02b0a1b 100644
--- a/modules/video_coding/BUILD.gn
+++ b/modules/video_coding/BUILD.gn
@@ -99,6 +99,7 @@
     "..:module_api",
     "..:module_api_public",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:optional",
     "../../api:video_frame_api_i420",
     "../../call:video_stream_api",
@@ -127,6 +128,7 @@
   deps = [
     ":video_coding_utility",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../test:test_support",
   ]
 }
@@ -169,6 +171,7 @@
   deps = [
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:optional",
     "../../api/video_codecs:video_codecs_api",
     "../../common_video",
@@ -239,6 +242,7 @@
   deps = [
     ":video_coding_utility",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:video_frame_api_i420",
     "../../common_video:common_video",
     "../../rtc_base:checks",
@@ -301,6 +305,7 @@
     ":video_coding_utility",
     "..:module_api",
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:optional",
     "../../api/video_codecs:video_codecs_api",
     "../../common_video",
@@ -431,6 +436,7 @@
       ":video_coding_utility",
       ":webrtc_vp8",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api:video_frame_api_i420",
       "../../api/video_codecs:video_codecs_api",
       "../../common_video:common_video",
@@ -599,6 +605,7 @@
       ":webrtc_vp9",
       "..:module_api",
       "../..:webrtc_common",
+      "../../:typedefs",
       "../../api:video_frame_api",
       "../../api:video_frame_api_i420",
       "../../api/video_codecs:video_codecs_api",
diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn
index e6b9156..cd54b7d 100644
--- a/p2p/BUILD.gn
+++ b/p2p/BUILD.gn
@@ -96,6 +96,7 @@
     "../api:ortc_api",
     "../rtc_base:checks",
     "../rtc_base:rtc_base",
+    "../rtc_base:stringutils",
     "../system_wrappers:field_trial_api",
   ]
 
@@ -183,6 +184,7 @@
       "../rtc_base:rtc_base",
       "../rtc_base:rtc_base_approved",
       "../rtc_base:rtc_base_tests_utils",
+      "../rtc_base:stringutils",
       "../test:test_support",
       "//testing/gmock",
       "//testing/gtest",
@@ -204,6 +206,7 @@
   deps = [
     ":rtc_p2p",
     "..:webrtc_common",
+    "../:typedefs",
     "../rtc_base:checks",
     "../rtc_base:rtc_base",
   ]
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index 225f7f4..536dd23 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -78,6 +78,7 @@
     "../rtc_base:checks",
     "../rtc_base:rtc_base",
     "../rtc_base:rtc_task_queue",
+    "../rtc_base:stringutils",
   ]
 
   if (rtc_build_libsrtp) {
@@ -186,6 +187,7 @@
     "../rtc_base:checks",
     "../rtc_base:rtc_base",
     "../rtc_base:rtc_base_approved",
+    "../rtc_base:stringutils",
     "../stats",
     "../system_wrappers",
     "../system_wrappers:field_trial_api",
@@ -441,6 +443,7 @@
       ":peerconnection",
       ":rtc_pc_base",
       "../rtc_base:checks",
+      "../rtc_base:stringutils",
     ]
     if (is_android) {
       deps += [ ":android_black_magic" ]
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index e64e444..0949f4e 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -96,13 +96,18 @@
   ]
   deps = [
     ":safe_compare",
-    "..:webrtc_common",
+    "..:typedefs",
   ]
 }
 
-rtc_source_set("type_traits") {
+rtc_source_set("rate_limiter") {
   sources = [
-    "type_traits.h",
+    "rate_limiter.cc",
+    "rate_limiter.h",
+  ]
+  deps = [
+    ":rtc_base_approved",
+    "../system_wrappers",
   ]
 }
 
@@ -121,14 +126,25 @@
   ]
 }
 
-rtc_source_set("rate_limiter") {
+rtc_source_set("stringutils") {
   sources = [
-    "rate_limiter.cc",
-    "rate_limiter.h",
+    "stringutils.cc",
+    "stringutils.h",
   ]
   deps = [
-    ":rtc_base_approved",
-    "../system_wrappers",
+    ":checks",
+  ]
+}
+
+rtc_source_set("type_traits") {
+  sources = [
+    "type_traits.h",
+  ]
+}
+
+rtc_source_set("deprecation") {
+  sources = [
+    "deprecation.h",
   ]
 }
 
@@ -146,7 +162,9 @@
   deps = [
     ":checks",
     ":safe_compare",
+    ":stringutils",
     ":type_traits",
+    "../:typedefs",
   ]
 
   sources = [
@@ -171,7 +189,6 @@
     "copyonwritebuffer.h",
     "criticalsection.cc",
     "criticalsection.h",
-    "deprecation.h",
     "event_tracer.cc",
     "event_tracer.h",
     "file.cc",
@@ -216,8 +233,6 @@
     "stringencode.cc",
     "stringencode.h",
     "stringize_macros.h",
-    "stringutils.cc",
-    "stringutils.h",
     "swap_queue.h",
     "template_util.h",
     "thread_annotations.h",
@@ -526,6 +541,7 @@
   defines = []
   deps = [
     ":checks",
+    ":stringutils",
     "..:webrtc_common",
     "../api:optional",
   ]
@@ -845,6 +861,7 @@
   deps = [
     ":checks",
     ":rtc_base",
+    ":stringutils",
     "../test:field_trial",
     "../test:test_support",
   ]
@@ -956,6 +973,7 @@
       ":rtc_base_tests_utils",
       ":rtc_task_queue",
       ":safe_compare",
+      ":stringutils",
       "../api:array_view",
       "../system_wrappers:system_wrappers",
       "../test:test_support",
@@ -1080,6 +1098,7 @@
       ":checks",
       ":rtc_base_tests_main",
       ":rtc_base_tests_utils",
+      ":stringutils",
       "../api:optional",
       "../test:test_support",
     ]
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index 2b6d850..771d6d9 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -157,6 +157,7 @@
 
     deps = [
       "..:webrtc_common",
+      "../:typedefs",
       "../common_video",
     ]
   }
@@ -379,6 +380,7 @@
 
       deps = [
         "..:webrtc_common",
+        "../:typedefs",
         "../common_audio",
         "../modules/audio_processing",
         "../modules/audio_processing:audioproc_debug_proto",
diff --git a/sdk/android/BUILD.gn b/sdk/android/BUILD.gn
index 8657203..3faca81 100644
--- a/sdk/android/BUILD.gn
+++ b/sdk/android/BUILD.gn
@@ -401,6 +401,7 @@
     "../../rtc_base:rtc_base",
     "../../rtc_base:rtc_base_approved",
     "../../rtc_base:rtc_task_queue",
+    "../../rtc_base:stringutils",
     "../../system_wrappers:field_trial_api",
   ]
 }
diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn
index dc2baf6..f999e21 100644
--- a/system_wrappers/BUILD.gn
+++ b/system_wrappers/BUILD.gn
@@ -54,6 +54,7 @@
     ":field_trial_api",
     ":metrics_api",
     "..:webrtc_common",
+    "../:typedefs",
     "../api:optional",
     "../modules:module_api_public",
     "../rtc_base:checks",
@@ -112,6 +113,7 @@
   ]
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
   ]
 }
 
@@ -215,6 +217,7 @@
       ":metrics_default",
       ":system_wrappers",
       "..:webrtc_common",
+      "../:typedefs",
       "../rtc_base:rtc_base_approved",
       "../test:test_main",
       "//testing/gtest",
diff --git a/system_wrappers/include/ntp_time.h b/system_wrappers/include/ntp_time.h
index e963ecf..1c32184 100644
--- a/system_wrappers/include/ntp_time.h
+++ b/system_wrappers/include/ntp_time.h
@@ -12,6 +12,8 @@
 
 #include <stdint.h>
 
+#include "rtc_base/numerics/safe_conversions.h"
+
 namespace webrtc {
 
 class NtpTime {
@@ -40,8 +42,12 @@
   // NTP standard (RFC1305, section 3.1) explicitly state value 0 is invalid.
   bool Valid() const { return value_ != 0; }
 
-  uint32_t seconds() const { return value_ / kFractionsPerSecond; }
-  uint32_t fractions() const { return value_ % kFractionsPerSecond; }
+  uint32_t seconds() const {
+    return rtc::dchecked_cast<uint32_t>(value_ / kFractionsPerSecond);
+  }
+  uint32_t fractions() const {
+    return rtc::dchecked_cast<uint32_t>(value_ % kFractionsPerSecond);
+  }
 
  private:
   uint64_t value_;
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 98c74e9..8841ae0 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -60,6 +60,7 @@
 
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../api:optional",
     "../api:video_frame_api_i420",
     "../api/video_codecs:video_codecs_api",
@@ -151,6 +152,7 @@
 
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../api:array_view",
     "../common_video",
     "../rtc_base:gtest_prod",
@@ -215,6 +217,7 @@
       ":test_support",
       ":video_test_common",
       "..:webrtc_common",
+      "../:typedefs",
       "../api:video_frame_api",
       "../api:video_frame_api_i420",
       "../common_video",
@@ -362,6 +365,7 @@
       "testsupport/iosfileutils.mm",
     ]
     deps = [
+      "..:typedefs",
       "..:webrtc_common",
       "../rtc_base:checks",
       "../rtc_base:rtc_base_approved",
@@ -384,6 +388,7 @@
   ]
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../api:optional",
     "../rtc_base:checks",
     "../rtc_base:rtc_base_approved",
@@ -470,6 +475,7 @@
   }
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../api:transport_api",
     "../call",
     "../call:call_interfaces",
@@ -507,6 +513,7 @@
   }
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../api:array_view",
     "../common_audio:common_audio",
     "../modules/audio_device:audio_device",
@@ -565,6 +572,7 @@
     ":test_support",
     ":video_test_common",
     "..:webrtc_common",
+    "../:typedefs",
     "../api:transport_api",
     "../api:video_frame_api",
     "../api:video_frame_api_i420",
@@ -668,6 +676,7 @@
   deps = [
     ":test_support",
     "..:webrtc_common",
+    "../:typedefs",
     "../common_video",
     "../media:rtc_media_base",
     "../modules/media_file",
diff --git a/test/fuzzers/BUILD.gn b/test/fuzzers/BUILD.gn
index 475aeaa..19d1302 100644
--- a/test/fuzzers/BUILD.gn
+++ b/test/fuzzers/BUILD.gn
@@ -245,6 +245,7 @@
   ]
   deps = [
     "../..:webrtc_common",
+    "../../:typedefs",
     "../../api:optional",
     "../../api/audio_codecs:audio_codecs_api",
     "../../modules/rtp_rtcp:rtp_rtcp_format",
diff --git a/video/BUILD.gn b/video/BUILD.gn
index 95b6e31..fe03c9a 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -55,6 +55,7 @@
 
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../api:optional",
     "../api:transport_api",
     "../api:video_frame_api_i420",
@@ -216,6 +217,7 @@
     ]
     deps = [
       "..:webrtc_common",
+      "../:typedefs",
       "../api/video_codecs:video_codecs_api",
       "../call:call_interfaces",
       "../common_video",
diff --git a/voice_engine/BUILD.gn b/voice_engine/BUILD.gn
index 31d95fd..e993931 100644
--- a/voice_engine/BUILD.gn
+++ b/voice_engine/BUILD.gn
@@ -52,6 +52,7 @@
   deps = [
     ":audio_level",
     "..:webrtc_common",
+    "../:typedefs",
     "../api:array_view",
     "../api:audio_mixer_api",
     "../api:call_api",
@@ -94,6 +95,7 @@
 
   deps = [
     "..:webrtc_common",
+    "../:typedefs",
     "../common_audio",
     "../modules:module_api",
     "../rtc_base:rtc_base_approved",