Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_call_call_gn0.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/libwebrtc/call/call_gn -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/libwebrtc/call/call_gn -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D ABSL_ALLOCATOR_NOTHROW=1 -D PROTOBUF_ENABLE_DEBUG_LOGGING_MAY_LEAK_PII=0 -D RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY -D RTC_ENABLE_VP9 -D WEBRTC_DEPRECATE_PLAN_B -D WEBRTC_ENABLE_PROTOBUF=0 -D WEBRTC_ENCODER_PSNR_STATS -D WEBRTC_LIBRARY_IMPL -D WEBRTC_MOZILLA_BUILD -D WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0 -D WEBRTC_STRICT_FIELD_TRIALS=0 -D DYNAMIC_ANNOTATIONS_ENABLED=1 -D USE_AURA=1 -D USE_GLIB=1 -D USE_OZONE=1 -D USE_UDEV -D WEBRTC_LINUX -D WEBRTC_POSIX -D _FILE_OFFSET_BITS=64 -D _LARGEFILE64_SOURCE -D _LARGEFILE_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D WEBRTC_ENABLE_AVX2 -D _DEBUG -D _GNU_SOURCE -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/third_party/libwebrtc/call/call_gn -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/libwebrtc/call/call_gn -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/libwebrtc_overrides -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/third_party/libwebrtc/gen -I /root/firefox-clang/ipc/chromium/src -I /root/firefox-clang/third_party/abseil-cpp -I /root/firefox-clang/third_party/libwebrtc -I /root/firefox-clang/tools/profiler/public -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c++ Unified_cpp_call_call_gn0.cpp
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
37namespace webrtc {
38
39class FrameEncryptorInterface;
40class RateLimiter;
41class RtpPacketToSend;
42
43// Maximum amount of padding in RFC 3550 is 255 bytes.
44constexpr size_t kMaxPaddingLength = 255;
45
46class 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_