[fix] fix payload length for sender report and receiver report

This commit is contained in:
dijunkun
2025-03-05 17:49:17 +08:00
parent 02f00642e9
commit 84ba2d8339
6 changed files with 18 additions and 18 deletions

View File

@@ -22,7 +22,7 @@
namespace webrtc {
inline constexpr DataRate kCongestionControllerMinBitrate =
DataRate::BitsPerSec(5'000);
DataRate::BitsPerSec(500'000);
inline constexpr TimeDelta kBitrateWindow = TimeDelta::Seconds(1);
extern const char kBweTypeHistogram[];

View File

@@ -20,8 +20,8 @@ void ReceiverReport::SetReportBlocks(
}
const uint8_t *ReceiverReport::Build() {
size_t buffer_size =
DEFAULT_RR_SIZE + reports_.size() * RtcpReportBlock::kLength;
size_t buffer_size = DEFAULT_RTCP_HEADER_SIZE + DEFAULT_RR_SIZE +
reports_.size() * RtcpReportBlock::kLength;
if (!buffer_ || buffer_size != size_) {
delete[] buffer_;
buffer_ = nullptr;
@@ -30,9 +30,9 @@ const uint8_t *ReceiverReport::Build() {
buffer_ = new uint8_t[buffer_size];
size_ = buffer_size;
int pos =
rtcp_common_header_.Create(DEFAULT_RTCP_VERSION, 0, DEFAULT_RR_BLOCK_NUM,
RTCP_TYPE::RR, DEFAULT_RR_SIZE, buffer_);
int pos = rtcp_common_header_.Create(
DEFAULT_RTCP_VERSION, 0, DEFAULT_RR_BLOCK_NUM, RTCP_TYPE::RR,
(buffer_size - DEFAULT_RTCP_HEADER_SIZE) / 4, buffer_);
buffer_[pos] = sender_ssrc_ >> 24 & 0xFF;
buffer_[pos + 1] = sender_ssrc_ >> 16 & 0xFF;

View File

@@ -33,7 +33,8 @@ int RtcpCommonHeader::Create(uint8_t version, uint8_t has_padding,
}
uint16_t payload_size = length - kHeaderSizeBytes;
buffer[0] = (version << 6) | (has_padding << 5) | (count_or_format << 4);
buffer[0] = (version << 6) | (has_padding << 5) |
static_cast<uint8_t>(count_or_format);
buffer[1] = payload_type;
buffer[2] = payload_size >> 8 & 0xFF;
buffer[3] = payload_size & 0xFF;
@@ -61,7 +62,7 @@ bool RtcpCommonHeader::Parse(const uint8_t* buffer, size_t size_bytes) {
bool has_padding = (buffer[0] & 0x20) != 0;
count_or_format_ = buffer[0] & 0x1F;
packet_type_ = buffer[1];
payload_size_ = buffer[2] << 8 | buffer[3];
payload_size_ = ((static_cast<uint16_t>(buffer[2]) << 8) | buffer[3]) * 4;
payload_ = buffer + kHeaderSizeBytes;
padding_size_ = 0;

View File

@@ -8,9 +8,9 @@
#define DEFAULT_RTCP_HEADER_SIZE 4
#define DEFAULT_SR_BLOCK_NUM 1
#define DEFAULT_SR_SIZE 28
#define DEFAULT_SR_SIZE 24
#define DEFAULT_RR_BLOCK_NUM 1
#define DEFAULT_RR_SIZE 32
#define DEFAULT_RR_SIZE 4
typedef enum {
UNKNOWN = 0,

View File

@@ -21,8 +21,8 @@ void SenderReport::SetReportBlocks(
}
const uint8_t *SenderReport::Build() {
size_t buffer_size =
DEFAULT_SR_SIZE + reports_.size() * RtcpReportBlock::kLength;
size_t buffer_size = DEFAULT_RTCP_HEADER_SIZE + DEFAULT_SR_SIZE +
reports_.size() * RtcpReportBlock::kLength;
if (!buffer_ || buffer_size != size_) {
delete[] buffer_;
buffer_ = nullptr;
@@ -31,9 +31,9 @@ const uint8_t *SenderReport::Build() {
buffer_ = new uint8_t[buffer_size];
size_ = buffer_size;
int pos =
rtcp_common_header_.Create(DEFAULT_RTCP_VERSION, 0, DEFAULT_SR_BLOCK_NUM,
RTCP_TYPE::SR, buffer_size, buffer_);
int pos = rtcp_common_header_.Create(
DEFAULT_RTCP_VERSION, 0, DEFAULT_SR_BLOCK_NUM, RTCP_TYPE::SR,
(buffer_size - DEFAULT_RTCP_HEADER_SIZE) / 4, buffer_);
buffer_[pos++] = sender_info_.sender_ssrc >> 24 & 0xFF;
buffer_[pos++] = sender_info_.sender_ssrc >> 16 & 0xFF;

View File

@@ -222,6 +222,7 @@ bool IceTransport::ParseRtcpPacket(const uint8_t *buffer, size_t size,
bool valid = true;
if (!rtcp_block.Parse(buffer, size)) {
valid = false;
return valid;
}
switch (rtcp_block.type()) {
@@ -296,7 +297,7 @@ bool IceTransport::ParseRtcpPacket(const uint8_t *buffer, size_t size,
// local_media_ssrc(), packet_type_counter_);
// }
return true;
return valid;
}
void IceTransport::HandleReportBlock(const RtcpReportBlock &rtcp_report_block,
@@ -404,8 +405,6 @@ bool IceTransport::HandleNack(const RtcpCommonHeader &rtcp_block,
// }
// }
LOG_INFO("Nack [{}]", nack.packet_ids().size());
return true;
}