| File: | root/firefox-clang/third_party/libwebrtc/modules/rtp_rtcp/source/rtp_sender.h |
| Warning: | line 46, column 7 Excessive padding in 'class webrtc::RTPSender' (34 padding bytes, where 2 is optimal). Optimal fields order: clock_, random_, packet_history_, paced_sender_, max_packet_size_, max_media_packet_header_, max_padding_fec_packet_header_, max_num_csrcs_, retransmission_rate_limiter_, rid_, mid_, rtx_payload_type_map_, send_mutex_, ssrc_, timestamp_offset_, rtx_, rtx_ssrc_, flexfec_ssrc_, rtp_header_extension_map_, audio_configured_, sending_media_, always_send_mid_and_rid_, ssrc_has_acked_, rtx_ssrc_has_acked_, supports_bwe_extension_, consider reordering the fields or adding explicit padding members |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
| 12 | #define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |
| 13 | |
| 14 | #include <cstddef> |
| 15 | #include <cstdint> |
| 16 | #include <map> |
| 17 | #include <memory> |
| 18 | #include <optional> |
| 19 | #include <span> |
| 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include "absl/strings/string_view.h" |
| 24 | #include "api/environment/environment.h" |
| 25 | #include "api/rtp_header_extension_id.h" |
| 26 | #include "api/rtp_packet_sender.h" |
| 27 | #include "modules/rtp_rtcp/include/flexfec_sender.h" |
| 28 | #include "modules/rtp_rtcp/include/rtp_header_extension_map.h" |
| 29 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 30 | #include "modules/rtp_rtcp/source/rtp_header_extension_size.h" |
| 31 | #include "modules/rtp_rtcp/source/rtp_packet_history.h" |
| 32 | #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" |
| 33 | #include "rtc_base/random.h" |
| 34 | #include "rtc_base/synchronization/mutex.h" |
| 35 | #include "rtc_base/thread_annotations.h" |
| 36 | |
| 37 | namespace webrtc { |
| 38 | |
| 39 | class FrameEncryptorInterface; |
| 40 | class RateLimiter; |
| 41 | class RtpPacketToSend; |
| 42 | |
| 43 | // Maximum amount of padding in RFC 3550 is 255 bytes. |
| 44 | constexpr size_t kMaxPaddingLength = 255; |
| 45 | |
| 46 | class RTPSender { |
Excessive padding in 'class webrtc::RTPSender' (34 padding bytes, where 2 is optimal). Optimal fields order: clock_, random_, packet_history_, paced_sender_, max_packet_size_, max_media_packet_header_, max_padding_fec_packet_header_, max_num_csrcs_, retransmission_rate_limiter_, rid_, mid_, rtx_payload_type_map_, send_mutex_, ssrc_, timestamp_offset_, rtx_, rtx_ssrc_, flexfec_ssrc_, rtp_header_extension_map_, audio_configured_, sending_media_, always_send_mid_and_rid_, ssrc_has_acked_, rtx_ssrc_has_acked_, supports_bwe_extension_, consider reordering the fields or adding explicit padding members | |
| 47 | public: |
| 48 | RTPSender(const Environment& env, |
| 49 | const RtpRtcpInterface::Configuration& config, |
| 50 | RtpPacketHistory* packet_history, |
| 51 | RtpPacketSender* packet_sender); |
| 52 | |
| 53 | RTPSender(const RTPSender&) = delete; |
| 54 | RTPSender& operator=(const RTPSender&) = delete; |
| 55 | |
| 56 | ~RTPSender(); |
| 57 | |
| 58 | void SetSendingMediaStatus(bool enabled) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 59 | bool SendingMedia() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 60 | bool IsAudioConfigured() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 61 | |
| 62 | uint32_t TimestampOffset() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 63 | void SetTimestampOffset(uint32_t timestamp) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 64 | |
| 65 | void SetMid(absl::string_view mid) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 66 | |
| 67 | uint16_t SequenceNumber() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 68 | void SetSequenceNumber(uint16_t seq) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 69 | |
| 70 | void SetMaxRtpPacketSize(size_t max_packet_size) |
| 71 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 72 | |
| 73 | void SetExtmapAllowMixed(bool extmap_allow_mixed) |
| 74 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 75 | |
| 76 | // RTP header extension |
| 77 | bool RegisterRtpHeaderExtension(absl::string_view uri, |
| 78 | RtpHeaderExtensionId id) |
| 79 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 80 | bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) const |
| 81 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 82 | void DeregisterRtpHeaderExtension(absl::string_view uri) |
| 83 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 84 | |
| 85 | bool SupportsPadding() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 86 | bool SupportsRtxPayloadPadding() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 87 | |
| 88 | std::vector<std::unique_ptr<RtpPacketToSend>> GeneratePadding( |
| 89 | size_t target_size_bytes, |
| 90 | bool media_has_been_sent, |
| 91 | bool can_send_padding_on_media_ssrc) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 92 | |
| 93 | // NACK. |
| 94 | void OnReceivedNack(const std::vector<uint16_t>& nack_sequence_numbers, |
| 95 | int64_t avg_rtt) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 96 | |
| 97 | int32_t ReSendPacket(uint16_t packet_id) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 98 | |
| 99 | // ACK. |
| 100 | void OnReceivedAckOnSsrc(int64_t extended_highest_sequence_number) |
| 101 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 102 | void OnReceivedAckOnRtxSsrc(int64_t extended_highest_sequence_number) |
| 103 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 104 | |
| 105 | // RTX. |
| 106 | void SetRtxStatus(int mode) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 107 | int RtxStatus() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 108 | std::optional<uint32_t> RtxSsrc() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))) { |
| 109 | return rtx_ssrc_; |
| 110 | } |
| 111 | // Returns expected size difference between an RTX packet and media packet |
| 112 | // that RTX packet is created from. Returns 0 if RTX is disabled. |
| 113 | size_t RtxPacketOverhead() const; |
| 114 | |
| 115 | void SetRtxPayloadType(int payload_type, int associated_payload_type) |
| 116 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 117 | |
| 118 | // Size info for header extensions used by FEC packets. |
| 119 | static std::span<const RtpExtensionSize> FecExtensionSizes() |
| 120 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 121 | |
| 122 | // Size info for header extensions used by video packets. |
| 123 | static std::span<const RtpExtensionSize> VideoExtensionSizes() |
| 124 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 125 | |
| 126 | // Size info for header extensions used by audio packets. |
| 127 | static std::span<const RtpExtensionSize> AudioExtensionSizes() |
| 128 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 129 | |
| 130 | // Create empty packet, fills ssrc, csrcs and reserve place for header |
| 131 | // extensions RtpSender updates before sending. |
| 132 | std::unique_ptr<RtpPacketToSend> AllocatePacket( |
| 133 | std::span<const uint32_t> csrcs = {}) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 134 | |
| 135 | // Maximum header overhead per fec/padding packet. |
| 136 | size_t FecOrPaddingPacketMaxRtpHeaderLength() const |
| 137 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 138 | // Expected header overhead per media packet. |
| 139 | size_t ExpectedPerPacketOverhead() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 140 | // Including RTP headers. |
| 141 | size_t MaxRtpPacketSize() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 142 | |
| 143 | uint32_t SSRC() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))) { return ssrc_; } |
| 144 | |
| 145 | std::string Rid() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))) { return rid_; } |
| 146 | |
| 147 | std::optional<uint32_t> FlexfecSsrc() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))) { |
| 148 | return flexfec_ssrc_; |
| 149 | } |
| 150 | |
| 151 | // Pass a set of packets to RtpPacketSender instance, for paced or immediate |
| 152 | // sending to the network. |
| 153 | void EnqueuePackets(std::vector<std::unique_ptr<RtpPacketToSend>> packets) |
| 154 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 155 | |
| 156 | void SetRtpState(const RtpState& rtp_state) RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 157 | RtpState GetRtpState() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 158 | void SetRtxRtpState(const RtpState& rtp_state) |
| 159 | RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 160 | RtpState GetRtxRtpState() const RTC_LOCKS_EXCLUDED(send_mutex_)__attribute__((locks_excluded(send_mutex_))); |
| 161 | |
| 162 | private: |
| 163 | std::unique_ptr<RtpPacketToSend> BuildRtxPacket( |
| 164 | const RtpPacketToSend& packet); |
| 165 | |
| 166 | bool IsFecPacket(const RtpPacketToSend& packet) const; |
| 167 | |
| 168 | void UpdateHeaderSizes() RTC_EXCLUSIVE_LOCKS_REQUIRED(send_mutex_)__attribute__((exclusive_locks_required(send_mutex_))); |
| 169 | |
| 170 | void UpdateLastPacketState(const RtpPacketToSend& packet) |
| 171 | RTC_EXCLUSIVE_LOCKS_REQUIRED(send_mutex_)__attribute__((exclusive_locks_required(send_mutex_))); |
| 172 | |
| 173 | Clock* const clock_; |
| 174 | Random random_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 175 | |
| 176 | const bool audio_configured_; |
| 177 | |
| 178 | const uint32_t ssrc_; |
| 179 | const std::optional<uint32_t> rtx_ssrc_; |
| 180 | const std::optional<uint32_t> flexfec_ssrc_; |
| 181 | |
| 182 | RtpPacketHistory* const packet_history_; |
| 183 | RtpPacketSender* const paced_sender_; |
| 184 | |
| 185 | mutable Mutex send_mutex_; |
| 186 | |
| 187 | bool sending_media_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 188 | size_t max_packet_size_; |
| 189 | |
| 190 | RtpHeaderExtensionMap rtp_header_extension_map_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 191 | size_t max_media_packet_header_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 192 | size_t max_padding_fec_packet_header_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 193 | |
| 194 | // RTP variables |
| 195 | uint32_t timestamp_offset_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 196 | // RID value to send in the RID or RepairedRID header extension. |
| 197 | const std::string rid_; |
| 198 | // MID value to send in the MID header extension. |
| 199 | std::string mid_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 200 | // Should we send MID/RID even when ACKed? (see below). |
| 201 | const bool always_send_mid_and_rid_; |
| 202 | // Track if any ACK has been received on the SSRC and RTX SSRC to indicate |
| 203 | // when to stop sending the MID and RID header extensions. |
| 204 | bool ssrc_has_acked_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 205 | bool rtx_ssrc_has_acked_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 206 | // Maximum number of csrcs this sender is used with. |
| 207 | size_t max_num_csrcs_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))) = 0; |
| 208 | int rtx_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 209 | // Mapping rtx_payload_type_map_[associated] = rtx. |
| 210 | std::map<int8_t, int8_t> rtx_payload_type_map_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 211 | bool supports_bwe_extension_ RTC_GUARDED_BY(send_mutex_)__attribute__((guarded_by(send_mutex_))); |
| 212 | |
| 213 | RateLimiter* const retransmission_rate_limiter_; |
| 214 | }; |
| 215 | |
| 216 | } // namespace webrtc |
| 217 | |
| 218 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_ |