diff --git a/.gn b/.gn index ac4ef80551..5e3c6ca9af 100644 --- a/.gn +++ b/.gn @@ -21,6 +21,7 @@ secondary_source = "//build/secondary/" # 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 6153e4fd92..9b4248baab 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -350,11 +350,24 @@ if (!build_with_chromium) { } } +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 592039f68f..94dd86507f 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -59,6 +59,8 @@ rtc_static_library("libjingle_peerconnection_api") { "proxy.h", "rtcerror.cc", "rtcerror.h", + "rtp_headers.cc", + "rtp_headers.h", "rtpparameters.cc", "rtpparameters.h", "rtpreceiverinterface.h", @@ -84,6 +86,7 @@ rtc_static_library("libjingle_peerconnection_api") { ] deps = [ + ":array_view", ":optional", ":rtc_stats_api", ":video_frame_api", @@ -93,10 +96,14 @@ rtc_static_library("libjingle_peerconnection_api") { # 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 d2c074d8c5..01dc12459e 100644 --- a/api/audio_codecs/BUILD.gn +++ b/api/audio_codecs/BUILD.gn @@ -29,7 +29,9 @@ rtc_source_set("audio_codecs_api") { "..: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 3c58fad9fd..716a297c54 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 0000000000..a0b1a15cbb --- /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 +#include +#include +#include + +#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 0000000000..2624a33e5f --- /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 +#include +#include +#include +#include + +#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 name); + + StringRtpHeaderExtension() { value_[0] = 0; } + explicit StringRtpHeaderExtension(rtc::ArrayView 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 value) { + Set(reinterpret_cast(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 f3cb7f13fd..6f3623db56 100644 --- a/api/video_codecs/BUILD.gn +++ b/api/video_codecs/BUILD.gn @@ -26,6 +26,7 @@ rtc_source_set("video_codecs_api") { "..: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 f38e0ebb8d..4e017103c4 100644 --- a/audio/utility/BUILD.gn +++ b/audio/utility/BUILD.gn @@ -21,6 +21,7 @@ rtc_static_library("audio_frame_operations") { 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 82f6ca1dc1..6f936b853e 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -24,6 +24,7 @@ rtc_source_set("call_interfaces") { ":rtp_interfaces", ":video_stream_api", "..:webrtc_common", + "../:typedefs", "../api:audio_mixer_api", "../api:libjingle_peerconnection_api", "../api:optional", @@ -70,6 +71,7 @@ rtc_source_set("rtp_receiver") { ":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 @@ rtc_source_set("video_stream_api") { "../api:optional", "../api:transport_api", "../common_video:common_video", + "../modules/rtp_rtcp:rtp_rtcp_format", "../rtc_base:rtc_base_approved", ] } @@ -204,6 +207,7 @@ if (rtc_include_tests) { ":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 a0b7a11d3a..98ce351095 100644 --- a/call/flexfec_receive_stream.h +++ b/call/flexfec_receive_stream.h @@ -16,6 +16,7 @@ #include #include +#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 0adbdf3133..0e78ddea18 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 dd5aa55147..0e1c95b9f5 100644 --- a/call/rtcp_demuxer_unittest.cc +++ b/call/rtcp_demuxer_unittest.cc @@ -13,6 +13,7 @@ #include #include +#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 de6f712901..924d69a529 100644 --- a/call/video_receive_stream.h +++ b/call/video_receive_stream.h @@ -16,12 +16,16 @@ #include #include +#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 e57307d3a9..890a767dfe 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 f601731db3..27287ec966 100644 --- a/common_audio/BUILD.gn +++ b/common_audio/BUILD.gn @@ -62,6 +62,7 @@ rtc_static_library("common_audio") { deps = [ ":sinc_resampler", "..:webrtc_common", + "../:typedefs", "../api:optional", "../rtc_base:checks", "../rtc_base:gtest_prod", @@ -223,6 +224,7 @@ rtc_source_set("common_audio_c") { ":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 @@ rtc_source_set("common_audio_cc") { public_configs = [ ":common_audio_config" ] deps = [ "..:webrtc_common", + "../:typedefs", "../rtc_base:rtc_base_approved", "../system_wrappers", ] @@ -252,6 +255,7 @@ rtc_source_set("sinc_resampler") { ] deps = [ "..:webrtc_common", + "../:typedefs", "../rtc_base:gtest_prod", "../rtc_base:rtc_base_approved", "../system_wrappers", @@ -447,6 +451,7 @@ if (rtc_include_tests) { ":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 f1b2f1e13e..07f77b7777 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 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::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 21fdf56fe0..9f1ad8f9f7 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 @@ struct PlayoutDelay { 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 name); - - StringRtpHeaderExtension() { value_[0] = 0; } - explicit StringRtpHeaderExtension(rtc::ArrayView 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 value) { - Set(reinterpret_cast(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 188d5e5260..0c145fa322 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 0ab9bc8859..4e733d06bc 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -509,6 +509,7 @@ if (is_linux || is_win) { deps = [ "../api:video_frame_api_i420", "../rtc_base:checks", + "../rtc_base:stringutils", ] if (is_win) { sources += [ @@ -569,6 +570,7 @@ if (is_linux || is_win) { 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 @@ if (!build_with_chromium) { "../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 bfa20aa3e1..981231b09b 100644 --- a/logging/BUILD.gn +++ b/logging/BUILD.gn @@ -71,6 +71,7 @@ rtc_source_set("rtc_event_log_api") { 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 e43ee7e0de..771ba66c6a 100644 --- a/logging/rtc_event_log/rtc_stream_config.h +++ b/logging/rtc_event_log/rtc_stream_config.h @@ -14,6 +14,7 @@ #include #include +#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 ac03a7d082..227133913f 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -57,6 +57,7 @@ rtc_static_library("rtc_media_base") { deps = [ "../rtc_base:checks", "../rtc_base:sanitizer", + "../rtc_base:stringutils", ] public_deps = [] sources = [ @@ -133,6 +134,7 @@ rtc_static_library("rtc_audio_video") { "../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 @@ if (rtc_include_tests) { "../modules/video_coding:video_coding_utility", "../p2p:rtc_p2p", "../rtc_base:checks", + "../rtc_base:stringutils", ] sources = [ "base/fakemediaengine.h", @@ -438,6 +441,7 @@ if (rtc_include_tests) { "../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 91fe33e8ac..5768944122 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 2c1a0427a1..33394f4133 100644 --- a/modules/BUILD.gn +++ b/modules/BUILD.gn @@ -34,6 +34,7 @@ rtc_source_set("module_api_public") { ] deps = [ "..:webrtc_common", + "../:typedefs", "../api:optional", ] } @@ -46,9 +47,12 @@ rtc_source_set("module_api") { 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 9c674d4ead..6365d562c8 100644 --- a/modules/audio_coding/BUILD.gn +++ b/modules/audio_coding/BUILD.gn @@ -65,6 +65,7 @@ rtc_static_library("rent_a_codec") { "acm2/rent_a_codec.h", ] deps = [ + "../../:typedefs", "../../rtc_base:checks", "../../api:array_view", "../../api:optional", @@ -96,6 +97,7 @@ rtc_source_set("audio_coding_module_typedefs") { deps = [ "..:module_api", "../..:webrtc_common", + "../../:typedefs", ] } @@ -132,6 +134,8 @@ rtc_static_library("audio_coding") { } deps = audio_coding_deps + [ + "../../rtc_base:deprecation", + "../../:typedefs", "../../rtc_base:checks", "../../system_wrappers:metrics_api", "..:module_api", @@ -177,6 +181,7 @@ rtc_static_library("cng") { deps = [ "../..:webrtc_common", + "../../:typedefs", "../../api:array_view", "../../api/audio_codecs:audio_codecs_api", "../../common_audio", @@ -241,6 +246,7 @@ rtc_source_set("g711_c") { ] deps = [ "../..:webrtc_common", + "../../:typedefs", ] } @@ -282,6 +288,7 @@ rtc_source_set("g722_c") { ] deps = [ "../..:webrtc_common", + "../../:typedefs", ] } @@ -461,6 +468,7 @@ rtc_source_set("ilbc_c") { deps = [ "../..:webrtc_common", + "../../:typedefs", "../../api/audio_codecs:audio_codecs_api", "../../common_audio", "../../rtc_base:checks", @@ -569,6 +577,7 @@ rtc_static_library("isac_c") { deps = [ ":isac_common", "../..:webrtc_common", + "../../:typedefs", "../../common_audio", "../../rtc_base:checks", "../../rtc_base:compile_assert_c", @@ -675,6 +684,7 @@ rtc_source_set("isac_fix_c") { deps = [ ":isac_common", "../..:webrtc_common", + "../../:typedefs", "../../api/audio_codecs:audio_codecs_api", "../../common_audio", "../../rtc_base:checks", @@ -799,6 +809,7 @@ rtc_source_set("pcm16b_c") { public_configs = [ ":pcm16b_config" ] deps = [ "../..:webrtc_common", + "../../:typedefs", ] } @@ -856,6 +867,7 @@ rtc_source_set("webrtc_opus_c") { deps = [ "../..:webrtc_common", + "../../:typedefs", "../../rtc_base:checks", "../../rtc_base:rtc_base_approved", ] @@ -1042,6 +1054,8 @@ rtc_static_library("neteq") { ":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 @@ rtc_source_set("neteq_tools_minimal") { ":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 @@ rtc_source_set("neteq_test_tools") { ":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 @@ rtc_source_set("neteq_tools") { deps = [ "../..:webrtc_common", + "../../:typedefs", "../../api:array_view", "../../api:optional", "../../api/audio_codecs:audio_codecs_api", @@ -1195,6 +1214,7 @@ rtc_source_set("neteq_input_audio_tools") { deps = [ "../..:webrtc_common", + "../../:typedefs", "../../common_audio", "../../rtc_base:checks", "../../rtc_base:rtc_base_approved", @@ -1308,6 +1328,7 @@ if (rtc_include_tests) { ":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 @@ if (rtc_include_tests) { ":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 @@ if (rtc_include_tests) { ":audio_coding_module_typedefs", ":audio_format_conversion", "..:module_api", + "../../:typedefs", "../../:webrtc_common", "../../api:optional", "../../rtc_base:rtc_base_approved", @@ -1441,6 +1464,7 @@ if (rtc_include_tests) { ":audio_coding", ":audio_format_conversion", "..:module_api", + "../../:typedefs", "../../:webrtc_common", "../../api:optional", "../../rtc_base:rtc_base_approved", @@ -1519,6 +1543,7 @@ if (rtc_include_tests) { defines = [] deps = [ "..:module_api", + "../../:typedefs", "../../rtc_base:checks", ] sources = [ @@ -1567,7 +1592,9 @@ if (rtc_include_tests) { 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 @@ if (rtc_include_tests) { ":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 @@ if (rtc_include_tests) { ":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 @@ if (rtc_include_tests) { testonly = true deps = audio_coding_deps + [ + "../../:typedefs", ":audio_coding", ":neteq_input_audio_tools", "../../api/audio_codecs/g711:audio_encoder_g711", @@ -1688,6 +1718,7 @@ if (rtc_include_tests) { testonly = true deps = audio_coding_deps + [ + "../../:typedefs", "../../system_wrappers:system_wrappers_default", "../rtp_rtcp:rtp_rtcp_format", "../../api:array_view", @@ -1768,6 +1799,7 @@ if (rtc_include_tests) { ":neteq", ":neteq_test_support", "../..:webrtc_common", + "../../:typedefs", "../../rtc_base:rtc_base_approved", "../../system_wrappers:system_wrappers_default", "../../test:test_support", @@ -1915,6 +1947,7 @@ if (rtc_include_tests) { deps = [ ":g722", "../..:webrtc_common", + "../../:typedefs", ] } @@ -2098,6 +2131,7 @@ if (rtc_include_tests) { ":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 00ed7cdbfa..0d47f21a06 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 a72f7d1899..94d45c5b2d 100644 --- a/modules/audio_coding/neteq/tools/packet.h +++ b/modules/audio_coding/neteq/tools/packet.h @@ -14,6 +14,7 @@ #include #include +#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 b705f8346d..3b3cca939e 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 3174ee907b..6c1914619f 100644 --- a/modules/audio_device/BUILD.gn +++ b/modules/audio_device/BUILD.gn @@ -100,6 +100,7 @@ rtc_source_set("audio_device_generic") { 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 cffd1a8901..13183984d7 100644 --- a/modules/audio_mixer/BUILD.gn +++ b/modules/audio_mixer/BUILD.gn @@ -36,6 +36,7 @@ rtc_static_library("audio_mixer_impl") { ":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 b190f0222f..d8790760f9 100644 --- a/modules/audio_processing/BUILD.gn +++ b/modules/audio_processing/BUILD.gn @@ -226,10 +226,12 @@ rtc_static_library("audio_processing") { ":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 @@ rtc_source_set("audio_processing_c") { deps = [ "../..:webrtc_common", + "../../:typedefs", "../../common_audio", "../../rtc_base:checks", "../../rtc_base:rtc_base_approved", @@ -371,6 +374,7 @@ rtc_source_set("apm_logging") { "../../api:array_view", "../../common_audio:common_audio", "../../rtc_base:rtc_base_approved", + "../../rtc_base:stringutils", ] defines = [] if (apm_debug_dump) { @@ -404,6 +408,7 @@ rtc_source_set("aec_core") { ":apm_logging", ":audio_processing_statistics", "../..:webrtc_common", + "../../:typedefs", "../../common_audio:common_audio", "../../rtc_base:checks", "../../rtc_base:rtc_base_approved", @@ -582,6 +587,7 @@ if (rtc_include_tests) { ":audioproc_test_utils", "..:module_api", "../..:webrtc_common", + "../../:typedefs", "../../api:array_view", "../../api:optional", "../../common_audio:common_audio", @@ -768,6 +774,7 @@ if (rtc_include_tests) { "../../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 @@ if (rtc_include_tests) { ":audio_processing", "..:module_api", "../..:webrtc_common", + "../../:typedefs", "../../common_audio:common_audio", "../../rtc_base:rtc_base_approved", "../../system_wrappers", @@ -838,6 +846,7 @@ if (rtc_include_tests) { deps = [ ":audio_processing", "../..:webrtc_common", + "../../:typedefs", "../../system_wrappers", "../../system_wrappers:metrics_default", ] @@ -892,6 +901,7 @@ if (rtc_include_tests) { 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 9cedd6e8c2..00e4730abf 100644 --- a/modules/audio_processing/test/conversational_speech/BUILD.gn +++ b/modules/audio_processing/test/conversational_speech/BUILD.gn @@ -45,6 +45,7 @@ rtc_static_library("lib") { ] deps = [ "../../../..:webrtc_common", + "../../../../:typedefs", "../../../../api:array_view", "../../../../common_audio", "../../../../rtc_base:checks", @@ -65,6 +66,7 @@ rtc_source_set("unittest") { 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 58d2e253b4..c014934c0c 100644 --- a/modules/congestion_controller/BUILD.gn +++ b/modules/congestion_controller/BUILD.gn @@ -49,6 +49,7 @@ rtc_static_library("congestion_controller") { 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 277683a4db..8e8d92dc5c 100644 --- a/modules/desktop_capture/BUILD.gn +++ b/modules/desktop_capture/BUILD.gn @@ -28,6 +28,7 @@ rtc_static_library("primitives") { deps = [ "../..:webrtc_common", + "../../:typedefs", "../../rtc_base:checks", "../../rtc_base:rtc_base", # TODO(kjellander): Cleanup in bugs.webrtc.org/3806. ] @@ -89,6 +90,7 @@ if (rtc_include_tests) { ":desktop_capture_mock", ":primitives", "../..:webrtc_common", + "../../:typedefs", "../../rtc_base:checks", "../../rtc_base:rtc_base_approved", "../../system_wrappers:cpu_features_api", @@ -333,6 +335,7 @@ rtc_static_library("desktop_capture_generic") { 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 1d89c7d070..94ccbdc158 100644 --- a/modules/include/module_common_types.h +++ b/modules/include/module_common_types.h @@ -18,6 +18,7 @@ #include #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 a3f3312799..589b2818cc 100644 --- a/modules/media_file/BUILD.gn +++ b/modules/media_file/BUILD.gn @@ -35,6 +35,7 @@ rtc_static_library("media_file") { 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 428a99ec04..6b76c643bd 100644 --- a/modules/pacing/BUILD.gn +++ b/modules/pacing/BUILD.gn @@ -34,6 +34,7 @@ rtc_static_library("pacing") { 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 f0fac54376..a5dd014e24 100644 --- a/modules/remote_bitrate_estimator/BUILD.gn +++ b/modules/remote_bitrate_estimator/BUILD.gn @@ -46,6 +46,7 @@ rtc_static_library("remote_bitrate_estimator") { deps = [ "../..:webrtc_common", + "../../:typedefs", "../../api:optional", "../../modules:module_api", "../../modules/rtp_rtcp:rtp_rtcp_format", @@ -140,6 +141,7 @@ if (rtc_include_tests) { ":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 e3f35b8c4e..4ae32cd92c 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -82,12 +82,14 @@ rtc_source_set("rtp_rtcp_format") { 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 @@ rtc_static_library("rtp_rtcp") { ":rtp_rtcp_format", "..:module_api", "../..:webrtc_common", + "../../:typedefs", "../../api:array_view", "../../api:libjingle_peerconnection_api", "../../api:optional", @@ -200,11 +203,13 @@ rtc_static_library("rtp_rtcp") { "../../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 @@ if (rtc_include_tests) { ":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 ee7dbbbd8d..55c2c056e7 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 af3714b25e..d9b082bd90 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 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::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 37ef332e52..97a2a98ff7 100644 --- a/modules/rtp_rtcp/include/rtp_rtcp_defines.h +++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.h @@ -16,6 +16,7 @@ #include #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 @@ class TransportSequenceNumberAllocator { 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 7002fd284e..e3de364f16 100644 --- a/modules/utility/BUILD.gn +++ b/modules/utility/BUILD.gn @@ -32,6 +32,7 @@ rtc_static_library("utility") { 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 f5dfa05eba..2953053395 100644 --- a/modules/video_capture/BUILD.gn +++ b/modules/video_capture/BUILD.gn @@ -28,10 +28,12 @@ rtc_static_library("video_capture_module") { 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 4e4ab75a30..02b0a1be3b 100644 --- a/modules/video_coding/BUILD.gn +++ b/modules/video_coding/BUILD.gn @@ -99,6 +99,7 @@ rtc_static_library("video_coding") { "..:module_api", "..:module_api_public", "../..:webrtc_common", + "../../:typedefs", "../../api:optional", "../../api:video_frame_api_i420", "../../call:video_stream_api", @@ -127,6 +128,7 @@ rtc_source_set("mock_headers") { deps = [ ":video_coding_utility", "../..:webrtc_common", + "../../:typedefs", "../../test:test_support", ] } @@ -169,6 +171,7 @@ rtc_source_set("video_coding_utility") { deps = [ "..:module_api", "../..:webrtc_common", + "../../:typedefs", "../../api:optional", "../../api/video_codecs:video_codecs_api", "../../common_video", @@ -239,6 +242,7 @@ rtc_static_library("webrtc_i420") { deps = [ ":video_coding_utility", "../..:webrtc_common", + "../../:typedefs", "../../api:video_frame_api_i420", "../../common_video:common_video", "../../rtc_base:checks", @@ -301,6 +305,7 @@ rtc_static_library("webrtc_vp8") { ":video_coding_utility", "..:module_api", "../..:webrtc_common", + "../../:typedefs", "../../api:optional", "../../api/video_codecs:video_codecs_api", "../../common_video", @@ -431,6 +436,7 @@ if (rtc_include_tests) { ":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 @@ if (rtc_include_tests) { ":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 e6b91560c8..cd54b7d5cc 100644 --- a/p2p/BUILD.gn +++ b/p2p/BUILD.gn @@ -96,6 +96,7 @@ rtc_static_library("rtc_p2p") { "../api:ortc_api", "../rtc_base:checks", "../rtc_base:rtc_base", + "../rtc_base:stringutils", "../system_wrappers:field_trial_api", ] @@ -183,6 +184,7 @@ if (rtc_include_tests) { "../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 @@ rtc_static_library("libstunprober") { deps = [ ":rtc_p2p", "..:webrtc_common", + "../:typedefs", "../rtc_base:checks", "../rtc_base:rtc_base", ] diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 225f7f4742..536dd23a03 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -78,6 +78,7 @@ rtc_static_library("rtc_pc_base") { "../rtc_base:checks", "../rtc_base:rtc_base", "../rtc_base:rtc_task_queue", + "../rtc_base:stringutils", ] if (rtc_build_libsrtp) { @@ -186,6 +187,7 @@ rtc_static_library("peerconnection") { "../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 @@ if (rtc_include_tests) { ":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 e64e4442dd..0949f4e6c9 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -96,13 +96,18 @@ rtc_source_set("checks") { ] 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("safe_compare") { ] } -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 @@ rtc_source_set("rtc_base_approved_generic") { deps = [ ":checks", ":safe_compare", + ":stringutils", ":type_traits", + "../:typedefs", ] sources = [ @@ -171,7 +189,6 @@ rtc_source_set("rtc_base_approved_generic") { "copyonwritebuffer.h", "criticalsection.cc", "criticalsection.h", - "deprecation.h", "event_tracer.cc", "event_tracer.h", "file.cc", @@ -216,8 +233,6 @@ rtc_source_set("rtc_base_approved_generic") { "stringencode.cc", "stringencode.h", "stringize_macros.h", - "stringutils.cc", - "stringutils.h", "swap_queue.h", "template_util.h", "thread_annotations.h", @@ -526,6 +541,7 @@ rtc_static_library("rtc_base_generic") { defines = [] deps = [ ":checks", + ":stringutils", "..:webrtc_common", "../api:optional", ] @@ -845,6 +861,7 @@ rtc_source_set("rtc_base_tests_utils") { deps = [ ":checks", ":rtc_base", + ":stringutils", "../test:field_trial", "../test:test_support", ] @@ -956,6 +973,7 @@ if (rtc_include_tests) { ":rtc_base_tests_utils", ":rtc_task_queue", ":safe_compare", + ":stringutils", "../api:array_view", "../system_wrappers:system_wrappers", "../test:test_support", @@ -1080,6 +1098,7 @@ if (rtc_include_tests) { ":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 2b6d850f6f..771d6d90e4 100644 --- a/rtc_tools/BUILD.gn +++ b/rtc_tools/BUILD.gn @@ -157,6 +157,7 @@ if (!build_with_chromium) { deps = [ "..:webrtc_common", + "../:typedefs", "../common_video", ] } @@ -379,6 +380,7 @@ if (rtc_include_tests) { 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 8657203e23..3faca81f36 100644 --- a/sdk/android/BUILD.gn +++ b/sdk/android/BUILD.gn @@ -401,6 +401,7 @@ rtc_static_library("peerconnection_jni") { "../../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 dc2baf62da..f999e211b7 100644 --- a/system_wrappers/BUILD.gn +++ b/system_wrappers/BUILD.gn @@ -54,6 +54,7 @@ rtc_static_library("system_wrappers") { ":field_trial_api", ":metrics_api", "..:webrtc_common", + "../:typedefs", "../api:optional", "../modules:module_api_public", "../rtc_base:checks", @@ -112,6 +113,7 @@ rtc_source_set("cpu_features_api") { ] deps = [ "..:webrtc_common", + "../:typedefs", ] } @@ -215,6 +217,7 @@ if (rtc_include_tests) { ":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 e963ecf39c..1c321841bd 100644 --- a/system_wrappers/include/ntp_time.h +++ b/system_wrappers/include/ntp_time.h @@ -12,6 +12,8 @@ #include +#include "rtc_base/numerics/safe_conversions.h" + namespace webrtc { class NtpTime { @@ -40,8 +42,12 @@ class NtpTime { // 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(value_ / kFractionsPerSecond); + } + uint32_t fractions() const { + return rtc::dchecked_cast(value_ % kFractionsPerSecond); + } private: uint64_t value_; diff --git a/test/BUILD.gn b/test/BUILD.gn index 98c74e9ea2..8841ae0806 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -60,6 +60,7 @@ rtc_source_set("video_test_common") { deps = [ "..:webrtc_common", + "../:typedefs", "../api:optional", "../api:video_frame_api_i420", "../api/video_codecs:video_codecs_api", @@ -151,6 +152,7 @@ rtc_source_set("test_support") { deps = [ "..:webrtc_common", + "../:typedefs", "../api:array_view", "../common_video", "../rtc_base:gtest_prod", @@ -215,6 +217,7 @@ if (rtc_include_tests) { ":test_support", ":video_test_common", "..:webrtc_common", + "../:typedefs", "../api:video_frame_api", "../api:video_frame_api_i420", "../common_video", @@ -362,6 +365,7 @@ if (is_ios) { "testsupport/iosfileutils.mm", ] deps = [ + "..:typedefs", "..:webrtc_common", "../rtc_base:checks", "../rtc_base:rtc_base_approved", @@ -384,6 +388,7 @@ rtc_source_set("fileutils") { ] deps = [ "..:webrtc_common", + "../:typedefs", "../api:optional", "../rtc_base:checks", "../rtc_base:rtc_base_approved", @@ -470,6 +475,7 @@ rtc_source_set("direct_transport") { } deps = [ "..:webrtc_common", + "../:typedefs", "../api:transport_api", "../call", "../call:call_interfaces", @@ -507,6 +513,7 @@ rtc_source_set("fake_audio_device") { } deps = [ "..:webrtc_common", + "../:typedefs", "../api:array_view", "../common_audio:common_audio", "../modules/audio_device:audio_device", @@ -565,6 +572,7 @@ rtc_source_set("test_common") { ":test_support", ":video_test_common", "..:webrtc_common", + "../:typedefs", "../api:transport_api", "../api:video_frame_api", "../api:video_frame_api_i420", @@ -668,6 +676,7 @@ rtc_source_set("test_renderer_generic") { 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 475aeaa5bd..19d1302087 100644 --- a/test/fuzzers/BUILD.gn +++ b/test/fuzzers/BUILD.gn @@ -245,6 +245,7 @@ rtc_static_library("audio_decoder_fuzzer") { ] 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 95b6e31dae..fe03c9add4 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn @@ -55,6 +55,7 @@ rtc_static_library("video") { deps = [ "..:webrtc_common", + "../:typedefs", "../api:optional", "../api:transport_api", "../api:video_frame_api_i420", @@ -216,6 +217,7 @@ if (rtc_include_tests) { ] 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 31d95fdf6b..e99393172f 100644 --- a/voice_engine/BUILD.gn +++ b/voice_engine/BUILD.gn @@ -52,6 +52,7 @@ rtc_static_library("voice_engine") { deps = [ ":audio_level", "..:webrtc_common", + "../:typedefs", "../api:array_view", "../api:audio_mixer_api", "../api:call_api", @@ -94,6 +95,7 @@ rtc_static_library("audio_level") { deps = [ "..:webrtc_common", + "../:typedefs", "../common_audio", "../modules:module_api", "../rtc_base:rtc_base_approved",