Fix rtcp header parse

This commit is contained in:
dijunkun
2023-09-13 10:49:18 +08:00
parent c1d31790d4
commit ea74495b5a
7 changed files with 107 additions and 31 deletions

View File

@@ -1,7 +1,27 @@
#include "rtcp_header.h"
RtcpHeader::RtcpHeader()
: version_(0), padding_(0), count_or_format_(0), length_(0) {}
: version_(0),
padding_(0),
count_or_format_(0),
payload_type_(PAYLOAD_TYPE::UNKNOWN),
length_(0) {}
RtcpHeader::RtcpHeader(const uint8_t* buffer, uint32_t size) {
if (size < 4) {
version_ = 2;
padding_ = 0;
count_or_format_ = 0;
payload_type_ = PAYLOAD_TYPE::UNKNOWN;
length_ = 0;
} else {
version_ = buffer[0] >> 6;
padding_ = buffer[0] >> 5 & 0x01;
count_or_format_ = buffer[0] & 0x1F;
payload_type_ = PAYLOAD_TYPE(buffer[1]);
length_ = buffer[2] << 8 + buffer[3];
}
}
RtcpHeader::~RtcpHeader() {}

View File

@@ -3,6 +3,8 @@
#include <stdint.h>
#include "log.h"
// RTCP header
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -26,6 +28,7 @@ class RtcpHeader {
public:
RtcpHeader();
RtcpHeader(const uint8_t* buffer, uint32_t size);
~RtcpHeader();
public:
@@ -34,14 +37,18 @@ class RtcpHeader {
void SetCountOrFormat(uint8_t count_or_format) {
count_or_format_ = count_or_format;
}
void SetPayloadType(uint8_t payload_type) { payload_type_ = payload_type; }
void SetPayloadType(PAYLOAD_TYPE payload_type) {
payload_type_ = payload_type;
}
void SetLength(uint16_t length) { length_ = length; }
public:
uint8_t Verion() const { return version_; }
uint8_t Padding() const { return padding_; }
uint8_t CountOrFormat() const { return count_or_format_; }
PAYLOAD_TYPE PayloadType() const { return PAYLOAD_TYPE(payload_type_); }
PAYLOAD_TYPE PayloadType() const {
return PAYLOAD_TYPE((uint8_t)payload_type_);
}
uint16_t Length() const { return length_; }
int Encode(uint8_t version, uint8_t padding, uint8_t count_or_format,
@@ -51,7 +58,7 @@ class RtcpHeader {
uint8_t version_ : 2;
uint8_t padding_ : 1;
uint8_t count_or_format_ : 5;
uint8_t payload_type_ : 8;
PAYLOAD_TYPE payload_type_ : 8;
uint16_t length_ : 16;
};