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}
This commit is contained in:
Danil Chapovalov 2023-07-24 15:09:26 +02:00 committed by WebRTC LUCI CQ
parent 7ee2a38527
commit 7b42f35bcc
4 changed files with 8 additions and 18 deletions

View File

@ -398,10 +398,6 @@ uint8_t* RtpPacket::AllocatePayload(size_t size_bytes) {
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_);

View File

@ -153,8 +153,11 @@ class RtpPacket {
// 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);

View File

@ -506,15 +506,8 @@ size_t RTPSender::ExpectedPerPacketOverhead() const {
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 @@ std::unique_ptr<RtpPacketToSend> RTPSender::BuildRtxPacket(
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());

View File

@ -288,8 +288,7 @@ bool RTPSenderAudio::SendAudio(AudioFrameType frame_type,
}
uint8_t* payload = packet->AllocatePayload(payload_size);
if (!payload) // Too large payload buffer.
return false;
RTC_CHECK(payload);
memcpy(payload, payload_data, payload_size);
{