diff --git a/audio/transport_feedback_packet_loss_tracker_unittest.cc b/audio/transport_feedback_packet_loss_tracker_unittest.cc index 2f9bf68444..f522635300 100644 --- a/audio/transport_feedback_packet_loss_tracker_unittest.cc +++ b/audio/transport_feedback_packet_loss_tracker_unittest.cc @@ -116,8 +116,6 @@ class TransportFeedbackPacketLossTrackerTest private: int64_t time_ms_{0}; - - RTC_DISALLOW_COPY_AND_ASSIGN(TransportFeedbackPacketLossTrackerTest); }; } // namespace diff --git a/modules/BUILD.gn b/modules/BUILD.gn index e1c1f3a3e6..8127244462 100644 --- a/modules/BUILD.gn +++ b/modules/BUILD.gn @@ -44,6 +44,7 @@ rtc_source_set("module_api") { visibility = [ "*" ] sources = [ "include/module.h", + "include/module_common_types.cc", "include/module_common_types.h", ] deps = [ @@ -51,14 +52,8 @@ rtc_source_set("module_api") { ":module_fec_api", "..:webrtc_common", "../api:libjingle_peerconnection_api", - "../api/transport:network_control", - "../api/video:video_frame", - "../api/video:video_frame_i420", "../modules/rtp_rtcp:rtp_video_header", - "../rtc_base:deprecation", - "../rtc_base:rtc_base_approved", - "video_coding:codec_globals_headers", - "//third_party/abseil-cpp/absl/types:optional", + "../rtc_base:safe_conversions", ] } diff --git a/modules/audio_coding/test/iSACTest.cc b/modules/audio_coding/test/iSACTest.cc index 6a52042a45..95af4d461a 100644 --- a/modules/audio_coding/test/iSACTest.cc +++ b/modules/audio_coding/test/iSACTest.cc @@ -27,6 +27,7 @@ #include "modules/audio_coding/codecs/audio_format_conversion.h" #include "modules/audio_coding/test/utility.h" #include "rtc_base/strings/string_builder.h" +#include "rtc_base/timeutils.h" #include "system_wrappers/include/sleep.h" #include "test/testsupport/fileutils.h" diff --git a/modules/congestion_controller/BUILD.gn b/modules/congestion_controller/BUILD.gn index de57e5b08f..5381a1d90d 100644 --- a/modules/congestion_controller/BUILD.gn +++ b/modules/congestion_controller/BUILD.gn @@ -70,6 +70,7 @@ rtc_static_library("transport_feedback") { ] deps = [ + "../../api/transport:network_control", "../../modules:module_api", "../../rtc_base:checks", "../../rtc_base:rtc_base_approved", diff --git a/modules/congestion_controller/rtp/BUILD.gn b/modules/congestion_controller/rtp/BUILD.gn index ddfe8139ac..0f2a64ecc3 100644 --- a/modules/congestion_controller/rtp/BUILD.gn +++ b/modules/congestion_controller/rtp/BUILD.gn @@ -70,6 +70,7 @@ rtc_static_library("transport_feedback") { deps = [ "../..:module_api", + "../../../api/transport:network_control", "../../../rtc_base:checks", "../../../rtc_base:rtc_base_approved", "../../../system_wrappers", diff --git a/modules/congestion_controller/rtp/transport_feedback_adapter.h b/modules/congestion_controller/rtp/transport_feedback_adapter.h index ae38b846fc..e2477ca31f 100644 --- a/modules/congestion_controller/rtp/transport_feedback_adapter.h +++ b/modules/congestion_controller/rtp/transport_feedback_adapter.h @@ -14,6 +14,7 @@ #include #include +#include "api/transport/network_types.h" #include "modules/congestion_controller/rtp/send_time_history.h" #include "rtc_base/criticalsection.h" #include "rtc_base/thread_annotations.h" diff --git a/modules/congestion_controller/transport_feedback_adapter.h b/modules/congestion_controller/transport_feedback_adapter.h index b411c26bd3..206236ce8b 100644 --- a/modules/congestion_controller/transport_feedback_adapter.h +++ b/modules/congestion_controller/transport_feedback_adapter.h @@ -14,6 +14,7 @@ #include #include +#include "api/transport/network_types.h" #include "modules/congestion_controller/rtp/send_time_history.h" #include "rtc_base/criticalsection.h" #include "rtc_base/thread_annotations.h" diff --git a/modules/include/module_common_types.cc b/modules/include/module_common_types.cc new file mode 100644 index 0000000000..4ad5d1444e --- /dev/null +++ b/modules/include/module_common_types.cc @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "modules/include/module_common_types.h" + +#include +#include + +#include "rtc_base/numerics/safe_conversions.h" + +namespace webrtc { + +RTPFragmentationHeader::RTPFragmentationHeader() + : fragmentationVectorSize(0), + fragmentationOffset(nullptr), + fragmentationLength(nullptr), + fragmentationTimeDiff(nullptr), + fragmentationPlType(nullptr) {} + +RTPFragmentationHeader::RTPFragmentationHeader(RTPFragmentationHeader&& other) + : RTPFragmentationHeader() { + swap(*this, other); +} + +RTPFragmentationHeader& RTPFragmentationHeader::operator=( + RTPFragmentationHeader&& other) { + swap(*this, other); + return *this; +} + +RTPFragmentationHeader::~RTPFragmentationHeader() { + delete[] fragmentationOffset; + delete[] fragmentationLength; + delete[] fragmentationTimeDiff; + delete[] fragmentationPlType; +} + +void swap(RTPFragmentationHeader& a, RTPFragmentationHeader& b) { + using std::swap; + swap(a.fragmentationVectorSize, b.fragmentationVectorSize); + swap(a.fragmentationOffset, b.fragmentationOffset); + swap(a.fragmentationLength, b.fragmentationLength); + swap(a.fragmentationTimeDiff, b.fragmentationTimeDiff); + swap(a.fragmentationPlType, b.fragmentationPlType); +} + +void RTPFragmentationHeader::CopyFrom(const RTPFragmentationHeader& src) { + if (this == &src) { + return; + } + + if (src.fragmentationVectorSize != fragmentationVectorSize) { + // new size of vectors + + // delete old + delete[] fragmentationOffset; + fragmentationOffset = nullptr; + delete[] fragmentationLength; + fragmentationLength = nullptr; + delete[] fragmentationTimeDiff; + fragmentationTimeDiff = nullptr; + delete[] fragmentationPlType; + fragmentationPlType = nullptr; + + if (src.fragmentationVectorSize > 0) { + // allocate new + if (src.fragmentationOffset) { + fragmentationOffset = new size_t[src.fragmentationVectorSize]; + } + if (src.fragmentationLength) { + fragmentationLength = new size_t[src.fragmentationVectorSize]; + } + if (src.fragmentationTimeDiff) { + fragmentationTimeDiff = new uint16_t[src.fragmentationVectorSize]; + } + if (src.fragmentationPlType) { + fragmentationPlType = new uint8_t[src.fragmentationVectorSize]; + } + } + // set new size + fragmentationVectorSize = src.fragmentationVectorSize; + } + + if (src.fragmentationVectorSize > 0) { + // copy values + if (src.fragmentationOffset) { + memcpy(fragmentationOffset, src.fragmentationOffset, + src.fragmentationVectorSize * sizeof(size_t)); + } + if (src.fragmentationLength) { + memcpy(fragmentationLength, src.fragmentationLength, + src.fragmentationVectorSize * sizeof(size_t)); + } + if (src.fragmentationTimeDiff) { + memcpy(fragmentationTimeDiff, src.fragmentationTimeDiff, + src.fragmentationVectorSize * sizeof(uint16_t)); + } + if (src.fragmentationPlType) { + memcpy(fragmentationPlType, src.fragmentationPlType, + src.fragmentationVectorSize * sizeof(uint8_t)); + } + } +} + +void RTPFragmentationHeader::Resize(size_t size) { + const uint16_t size16 = rtc::dchecked_cast(size); + if (fragmentationVectorSize < size16) { + uint16_t oldVectorSize = fragmentationVectorSize; + { + // offset + size_t* oldOffsets = fragmentationOffset; + fragmentationOffset = new size_t[size16]; + memset(fragmentationOffset + oldVectorSize, 0, + sizeof(size_t) * (size16 - oldVectorSize)); + // copy old values + memcpy(fragmentationOffset, oldOffsets, sizeof(size_t) * oldVectorSize); + delete[] oldOffsets; + } + // length + { + size_t* oldLengths = fragmentationLength; + fragmentationLength = new size_t[size16]; + memset(fragmentationLength + oldVectorSize, 0, + sizeof(size_t) * (size16 - oldVectorSize)); + memcpy(fragmentationLength, oldLengths, sizeof(size_t) * oldVectorSize); + delete[] oldLengths; + } + // time diff + { + uint16_t* oldTimeDiffs = fragmentationTimeDiff; + fragmentationTimeDiff = new uint16_t[size16]; + memset(fragmentationTimeDiff + oldVectorSize, 0, + sizeof(uint16_t) * (size16 - oldVectorSize)); + memcpy(fragmentationTimeDiff, oldTimeDiffs, + sizeof(uint16_t) * oldVectorSize); + delete[] oldTimeDiffs; + } + // payload type + { + uint8_t* oldTimePlTypes = fragmentationPlType; + fragmentationPlType = new uint8_t[size16]; + memset(fragmentationPlType + oldVectorSize, 0, + sizeof(uint8_t) * (size16 - oldVectorSize)); + memcpy(fragmentationPlType, oldTimePlTypes, + sizeof(uint8_t) * oldVectorSize); + delete[] oldTimePlTypes; + } + fragmentationVectorSize = size16; + } +} + +} // namespace webrtc diff --git a/modules/include/module_common_types.h b/modules/include/module_common_types.h index 8ee2369e15..4b4fd10346 100644 --- a/modules/include/module_common_types.h +++ b/modules/include/module_common_types.h @@ -11,24 +11,14 @@ #ifndef MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ #define MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ -#include -#include // memcpy +#include +#include -#include -#include - -#include "absl/types/optional.h" #include "api/rtp_headers.h" -#include "api/transport/network_types.h" -#include "api/video/video_rotation.h" #include "common_types.h" // NOLINT(build/include) #include "modules/include/module_common_types_public.h" #include "modules/include/module_fec_types.h" #include "modules/rtp_rtcp/source/rtp_video_header.h" -#include "rtc_base/constructormagic.h" -#include "rtc_base/deprecation.h" -#include "rtc_base/numerics/safe_conversions.h" -#include "rtc_base/timeutils.h" namespace webrtc { @@ -45,142 +35,29 @@ struct WebRtcRTPHeader { class RTPFragmentationHeader { public: - RTPFragmentationHeader() - : fragmentationVectorSize(0), - fragmentationOffset(NULL), - fragmentationLength(NULL), - fragmentationTimeDiff(NULL), - fragmentationPlType(NULL) {} + RTPFragmentationHeader(); + RTPFragmentationHeader(const RTPFragmentationHeader&) = delete; + RTPFragmentationHeader(RTPFragmentationHeader&& other); + RTPFragmentationHeader& operator=(const RTPFragmentationHeader& other) = + delete; + RTPFragmentationHeader& operator=(RTPFragmentationHeader&& other); + ~RTPFragmentationHeader(); - RTPFragmentationHeader(RTPFragmentationHeader&& other) - : RTPFragmentationHeader() { - std::swap(*this, other); - } + friend void swap(RTPFragmentationHeader& a, RTPFragmentationHeader& b); - ~RTPFragmentationHeader() { - delete[] fragmentationOffset; - delete[] fragmentationLength; - delete[] fragmentationTimeDiff; - delete[] fragmentationPlType; - } + void CopyFrom(const RTPFragmentationHeader& src); + void VerifyAndAllocateFragmentationHeader(size_t size) { Resize(size); } - void operator=(RTPFragmentationHeader&& other) { std::swap(*this, other); } + void Resize(size_t size); + size_t Size() const { return fragmentationVectorSize; } - friend void swap(RTPFragmentationHeader& a, RTPFragmentationHeader& b) { - using std::swap; - swap(a.fragmentationVectorSize, b.fragmentationVectorSize); - swap(a.fragmentationOffset, b.fragmentationOffset); - swap(a.fragmentationLength, b.fragmentationLength); - swap(a.fragmentationTimeDiff, b.fragmentationTimeDiff); - swap(a.fragmentationPlType, b.fragmentationPlType); - } - - void CopyFrom(const RTPFragmentationHeader& src) { - if (this == &src) { - return; - } - - if (src.fragmentationVectorSize != fragmentationVectorSize) { - // new size of vectors - - // delete old - delete[] fragmentationOffset; - fragmentationOffset = NULL; - delete[] fragmentationLength; - fragmentationLength = NULL; - delete[] fragmentationTimeDiff; - fragmentationTimeDiff = NULL; - delete[] fragmentationPlType; - fragmentationPlType = NULL; - - if (src.fragmentationVectorSize > 0) { - // allocate new - if (src.fragmentationOffset) { - fragmentationOffset = new size_t[src.fragmentationVectorSize]; - } - if (src.fragmentationLength) { - fragmentationLength = new size_t[src.fragmentationVectorSize]; - } - if (src.fragmentationTimeDiff) { - fragmentationTimeDiff = new uint16_t[src.fragmentationVectorSize]; - } - if (src.fragmentationPlType) { - fragmentationPlType = new uint8_t[src.fragmentationVectorSize]; - } - } - // set new size - fragmentationVectorSize = src.fragmentationVectorSize; - } - - if (src.fragmentationVectorSize > 0) { - // copy values - if (src.fragmentationOffset) { - memcpy(fragmentationOffset, src.fragmentationOffset, - src.fragmentationVectorSize * sizeof(size_t)); - } - if (src.fragmentationLength) { - memcpy(fragmentationLength, src.fragmentationLength, - src.fragmentationVectorSize * sizeof(size_t)); - } - if (src.fragmentationTimeDiff) { - memcpy(fragmentationTimeDiff, src.fragmentationTimeDiff, - src.fragmentationVectorSize * sizeof(uint16_t)); - } - if (src.fragmentationPlType) { - memcpy(fragmentationPlType, src.fragmentationPlType, - src.fragmentationVectorSize * sizeof(uint8_t)); - } - } - } - - void VerifyAndAllocateFragmentationHeader(const size_t size) { - assert(size <= std::numeric_limits::max()); - const uint16_t size16 = static_cast(size); - if (fragmentationVectorSize < size16) { - uint16_t oldVectorSize = fragmentationVectorSize; - { - // offset - size_t* oldOffsets = fragmentationOffset; - fragmentationOffset = new size_t[size16]; - memset(fragmentationOffset + oldVectorSize, 0, - sizeof(size_t) * (size16 - oldVectorSize)); - // copy old values - memcpy(fragmentationOffset, oldOffsets, sizeof(size_t) * oldVectorSize); - delete[] oldOffsets; - } - // length - { - size_t* oldLengths = fragmentationLength; - fragmentationLength = new size_t[size16]; - memset(fragmentationLength + oldVectorSize, 0, - sizeof(size_t) * (size16 - oldVectorSize)); - memcpy(fragmentationLength, oldLengths, sizeof(size_t) * oldVectorSize); - delete[] oldLengths; - } - // time diff - { - uint16_t* oldTimeDiffs = fragmentationTimeDiff; - fragmentationTimeDiff = new uint16_t[size16]; - memset(fragmentationTimeDiff + oldVectorSize, 0, - sizeof(uint16_t) * (size16 - oldVectorSize)); - memcpy(fragmentationTimeDiff, oldTimeDiffs, - sizeof(uint16_t) * oldVectorSize); - delete[] oldTimeDiffs; - } - // payload type - { - uint8_t* oldTimePlTypes = fragmentationPlType; - fragmentationPlType = new uint8_t[size16]; - memset(fragmentationPlType + oldVectorSize, 0, - sizeof(uint8_t) * (size16 - oldVectorSize)); - memcpy(fragmentationPlType, oldTimePlTypes, - sizeof(uint8_t) * oldVectorSize); - delete[] oldTimePlTypes; - } - fragmentationVectorSize = size16; - } - } + size_t Offset(size_t index) const { return fragmentationOffset[index]; } + size_t Length(size_t index) const { return fragmentationLength[index]; } + uint16_t TimeDiff(size_t index) const { return fragmentationTimeDiff[index]; } + int PayloadType(size_t index) const { return fragmentationPlType[index]; } + // TODO(danilchap): Move all members to private section, + // simplify by replacing 4 raw arrays with single std::vector uint16_t fragmentationVectorSize; // Number of fragmentations size_t* fragmentationOffset; // Offset of pointer to data for each // fragmentation @@ -188,9 +65,6 @@ class RTPFragmentationHeader { uint16_t* fragmentationTimeDiff; // Timestamp difference relative "now" for // each fragmentation uint8_t* fragmentationPlType; // Payload type of each fragmentation - - private: - RTC_DISALLOW_COPY_AND_ASSIGN(RTPFragmentationHeader); }; struct RTCPVoIPMetric { diff --git a/modules/pacing/BUILD.gn b/modules/pacing/BUILD.gn index c9689d929b..602f396b88 100644 --- a/modules/pacing/BUILD.gn +++ b/modules/pacing/BUILD.gn @@ -25,6 +25,7 @@ rtc_static_library("pacing") { ":interval_budget", "..:module_api", "../../:webrtc_common", + "../../api/transport:network_control", "../../logging:rtc_event_bwe", "../../logging:rtc_event_log_api", "../../logging:rtc_event_pacing", diff --git a/modules/pacing/bitrate_prober.h b/modules/pacing/bitrate_prober.h index f0ceab27a0..b2548c006d 100644 --- a/modules/pacing/bitrate_prober.h +++ b/modules/pacing/bitrate_prober.h @@ -13,6 +13,7 @@ #include +#include "api/transport/network_types.h" #include "modules/include/module_common_types.h" namespace webrtc { diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index 50204d396c..e470869794 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -90,6 +90,7 @@ rtc_source_set("rtp_rtcp_format") { "../../api:array_view", "../../api:libjingle_peerconnection_api", "../../api/audio_codecs:audio_codecs_api", + "../../api/transport:network_control", "../../api/video:video_frame", "../../common_video", "../../rtc_base:checks", diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.h b/modules/rtp_rtcp/include/rtp_rtcp_defines.h index 51e6337583..0b2a23800a 100644 --- a/modules/rtp_rtcp/include/rtp_rtcp_defines.h +++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.h @@ -18,6 +18,7 @@ #include "absl/types/variant.h" #include "api/audio_codecs/audio_format.h" #include "api/rtp_headers.h" +#include "api/transport/network_types.h" #include "common_types.h" // NOLINT(build/include) #include "modules/include/module_common_types.h" #include "system_wrappers/include/clock.h" diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc index c94b2f498e..2251df793c 100644 --- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc +++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc @@ -11,6 +11,7 @@ #include "modules/video_coding/codecs/test/videocodec_test_fixture_impl.h" #include +#include #include #include diff --git a/sdk/android/src/jni/videodecoderwrapper.cc b/sdk/android/src/jni/videodecoderwrapper.cc index d5812cde40..6c1423cf72 100644 --- a/sdk/android/src/jni/videodecoderwrapper.cc +++ b/sdk/android/src/jni/videodecoderwrapper.cc @@ -15,6 +15,7 @@ #include "modules/video_coding/utility/vp8_header_parser.h" #include "modules/video_coding/utility/vp9_uncompressed_header_parser.h" #include "rtc_base/logging.h" +#include "rtc_base/timeutils.h" #include "sdk/android/generated_video_jni/jni/VideoDecoderWrapper_jni.h" #include "sdk/android/generated_video_jni/jni/VideoDecoder_jni.h" #include "sdk/android/native_api/jni/java_types.h" diff --git a/sdk/android/src/jni/videoencoderwrapper.cc b/sdk/android/src/jni/videoencoderwrapper.cc index c50e9f6ef9..1d0f0bbc03 100644 --- a/sdk/android/src/jni/videoencoderwrapper.cc +++ b/sdk/android/src/jni/videoencoderwrapper.cc @@ -19,6 +19,7 @@ #include "modules/video_coding/utility/vp8_header_parser.h" #include "modules/video_coding/utility/vp9_uncompressed_header_parser.h" #include "rtc_base/logging.h" +#include "rtc_base/timeutils.h" #include "sdk/android/generated_video_jni/jni/VideoEncoderWrapper_jni.h" #include "sdk/android/generated_video_jni/jni/VideoEncoder_jni.h" #include "sdk/android/native_api/jni/class_loader.h" diff --git a/video/video_stream_decoder_impl.cc b/video/video_stream_decoder_impl.cc index 3e67e5c47c..2e8fc1a135 100644 --- a/video/video_stream_decoder_impl.cc +++ b/video/video_stream_decoder_impl.cc @@ -13,6 +13,7 @@ #include "absl/memory/memory.h" #include "rtc_base/logging.h" #include "rtc_base/numerics/mod_ops.h" +#include "rtc_base/timeutils.h" namespace webrtc {