Remove artifical extra RTP packet capacity
Instead allow RtpPacket to exceed configured capacity when setting payload
Bug: None
Change-Id: I02fc080ffa3127ffbe0dade1f200dd7456a6a128
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/312880
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40471}
diff --git a/modules/rtp_rtcp/source/rtp_packet.cc b/modules/rtp_rtcp/source/rtp_packet.cc
index 6c7dff3..2a95a3a 100644
--- a/modules/rtp_rtcp/source/rtp_packet.cc
+++ b/modules/rtp_rtcp/source/rtp_packet.cc
@@ -398,10 +398,6 @@
uint8_t* RtpPacket::SetPayloadSize(size_t size_bytes) {
RTC_DCHECK_EQ(padding_size_, 0);
- if (payload_offset_ + size_bytes > capacity()) {
- RTC_LOG(LS_WARNING) << "Cannot set payload, not enough space in buffer.";
- return nullptr;
- }
payload_size_ = size_bytes;
buffer_.SetSize(payload_offset_ + payload_size_);
return WriteAt(payload_offset_);
diff --git a/modules/rtp_rtcp/source/rtp_packet.h b/modules/rtp_rtcp/source/rtp_packet.h
index 1db4a13..e91ec63 100644
--- a/modules/rtp_rtcp/source/rtp_packet.h
+++ b/modules/rtp_rtcp/source/rtp_packet.h
@@ -153,8 +153,11 @@
// Returns view of the raw extension or empty view on failure.
rtc::ArrayView<const uint8_t> FindExtension(ExtensionType type) const;
- // Reserve size_bytes for payload. Returns nullptr on failure.
+ // Returns pointer to the payload of size at least `size_bytes`.
+ // Keeps original payload, if any. If `size_bytes` is larger than current
+ // `payload_size()`, remaining bytes are uninitialized.
uint8_t* SetPayloadSize(size_t size_bytes);
+
// Same as SetPayloadSize but doesn't guarantee to keep current payload.
uint8_t* AllocatePayload(size_t size_bytes);
diff --git a/modules/rtp_rtcp/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc
index 8c0b2dd..967d38a 100644
--- a/modules/rtp_rtcp/source/rtp_sender.cc
+++ b/modules/rtp_rtcp/source/rtp_sender.cc
@@ -506,15 +506,8 @@
std::unique_ptr<RtpPacketToSend> RTPSender::AllocatePacket() const {
MutexLock lock(&send_mutex_);
- // TODO(danilchap): Find better motivator and value for extra capacity.
- // RtpPacketizer might slightly miscalulate needed size,
- // SRTP may benefit from extra space in the buffer and do encryption in place
- // saving reallocation.
- // While sending slightly oversized packet increase chance of dropped packet,
- // it is better than crash on drop packet without trying to send it.
- static constexpr int kExtraCapacity = 16;
- auto packet = std::make_unique<RtpPacketToSend>(
- &rtp_header_extension_map_, max_packet_size_ + kExtraCapacity);
+ auto packet = std::make_unique<RtpPacketToSend>(&rtp_header_extension_map_,
+ max_packet_size_);
packet->SetSsrc(ssrc_);
packet->SetCsrcs(csrcs_);
@@ -721,8 +714,7 @@
uint8_t* rtx_payload =
rtx_packet->AllocatePayload(packet.payload_size() + kRtxHeaderSize);
- if (rtx_payload == nullptr)
- return nullptr;
+ RTC_CHECK(rtx_payload);
// Add OSN (original sequence number).
ByteWriter<uint16_t>::WriteBigEndian(rtx_payload, packet.SequenceNumber());
diff --git a/modules/rtp_rtcp/source/rtp_sender_audio.cc b/modules/rtp_rtcp/source/rtp_sender_audio.cc
index 47b7b79..a0f1af5 100644
--- a/modules/rtp_rtcp/source/rtp_sender_audio.cc
+++ b/modules/rtp_rtcp/source/rtp_sender_audio.cc
@@ -288,8 +288,7 @@
}
uint8_t* payload = packet->AllocatePayload(payload_size);
- if (!payload) // Too large payload buffer.
- return false;
+ RTC_CHECK(payload);
memcpy(payload, payload_data, payload_size);
{