diff --git a/modules/rtp_rtcp/source/rtp_packet.cc b/modules/rtp_rtcp/source/rtp_packet.cc index 6c7dff322b..2a95a3a816 100644 --- a/modules/rtp_rtcp/source/rtp_packet.cc +++ b/modules/rtp_rtcp/source/rtp_packet.cc @@ -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_); diff --git a/modules/rtp_rtcp/source/rtp_packet.h b/modules/rtp_rtcp/source/rtp_packet.h index 1db4a13017..e91ec6368b 100644 --- a/modules/rtp_rtcp/source/rtp_packet.h +++ b/modules/rtp_rtcp/source/rtp_packet.h @@ -153,8 +153,11 @@ class RtpPacket { // Returns view of the raw extension or empty view on failure. rtc::ArrayView 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 8c0b2dda0a..967d38a8e0 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -506,15 +506,8 @@ size_t RTPSender::ExpectedPerPacketOverhead() const { std::unique_ptr 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( - &rtp_header_extension_map_, max_packet_size_ + kExtraCapacity); + auto packet = std::make_unique(&rtp_header_extension_map_, + max_packet_size_); packet->SetSsrc(ssrc_); packet->SetCsrcs(csrcs_); @@ -721,8 +714,7 @@ std::unique_ptr 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::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 47b7b7910b..a0f1af5243 100644 --- a/modules/rtp_rtcp/source/rtp_sender_audio.cc +++ b/modules/rtp_rtcp/source/rtp_sender_audio.cc @@ -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); {