Implementation for rtcp sender report

This commit is contained in:
dijunkun
2023-09-12 17:30:08 +08:00
parent 8c545f7544
commit c1d31790d4
15 changed files with 470 additions and 204 deletions

20
src/rtcp/rtcp_header.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include "rtcp_header.h"
RtcpHeader::RtcpHeader()
: version_(0), padding_(0), count_or_format_(0), length_(0) {}
RtcpHeader::~RtcpHeader() {}
int RtcpHeader::Encode(uint8_t version, uint8_t padding,
uint8_t count_or_format, uint8_t payload_type,
uint16_t length, uint8_t* buffer) {
if (!buffer) {
return 0;
}
buffer[0] = (version << 6) | (padding << 5) | (count_or_format << 4);
buffer[1] = payload_type;
buffer[2] = length >> 8 & 0xFF;
buffer[3] = length & 0xFF;
return 4;
}

58
src/rtcp/rtcp_header.h Normal file
View File

@@ -0,0 +1,58 @@
#ifndef _RTCP_HEADER_H_
#define _RTCP_HEADER_H_
#include <stdint.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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| RC | PT=SR=200 | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#define DEFAULT_RTCP_VERSION 2
#define DEFAULT_RTCP_HEADER_SIZE 4
class RtcpHeader {
public:
typedef enum {
UNKNOWN = 0,
SR = 200,
RR = 201,
SDES = 202,
BYE = 203,
APP = 204
} PAYLOAD_TYPE;
public:
RtcpHeader();
~RtcpHeader();
public:
void SetVerion(uint8_t version) { version_ = version; }
void SetPadding(uint8_t padding) { padding_ = padding; }
void SetCountOrFormat(uint8_t count_or_format) {
count_or_format_ = count_or_format;
}
void SetPayloadType(uint8_t 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_); }
uint16_t Length() const { return length_; }
int Encode(uint8_t version, uint8_t padding, uint8_t count_or_format,
uint8_t payload_type, uint16_t length, uint8_t* buffer);
private:
uint8_t version_ : 2;
uint8_t padding_ : 1;
uint8_t count_or_format_ : 5;
uint8_t payload_type_ : 8;
uint16_t length_ : 16;
};
#endif

View File

@@ -1,74 +1,6 @@
#ifndef _RTCP_PACKET_H_
#define _RTCP_PACKET_H_
#include <stdint.h>
#include <vector>
// SR
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| RC | PT=SR=200 | length | header
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of sender |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | NTP timestamp, most significant word | sender
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ info
// | NTP timestamp, least significant word |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | RTP timestamp |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | sender's packet count |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | sender's octet count |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | SSRC_1 (SSRC of first source) | report
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
// | fraction lost | cumulative number of packets lost | 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | extended highest sequence number received |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | interarrival jitter |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | last SR (LSR) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | delay since last SR (DLSR) |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | SSRC_2 (SSRC of second source) | report
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
// : ... : 2
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | profile-specific extensions |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// RR
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| RC | PT=RR=201 | length | header
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of packet sender |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | SSRC_1 (SSRC of first source) | report
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
// | fraction lost | cumulative number of packets lost | 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | extended highest sequence number received |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | interarrival jitter |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | last SR (LSR) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | delay since last SR (DLSR) |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | SSRC_2 (SSRC of second source) | report
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
// : ... : 2
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | profile-specific extensions |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
class RtcpPacket {
public:
typedef enum {
@@ -78,108 +10,7 @@ class RtcpPacket {
SDES = 202,
BYE = 203,
APP = 204
} PAYLOAD_TYPE;
public:
RtcpPacket();
RtcpPacket(const uint8_t *buffer, size_t size);
RtcpPacket(const RtcpPacket &rtp_packet);
RtcpPacket(RtcpPacket &&rtp_packet);
RtcpPacket &operator=(const RtcpPacket &rtp_packet);
RtcpPacket &operator=(RtcpPacket &&rtp_packet);
~RtcpPacket();
public:
// Set Header
void SetVerion(uint8_t version) { version_ = version; }
void SetPadding(uint8_t padding) { padding_ = padding; }
void SetReceptionReportCount(uint8_t reception_report_count) {
reception_report_count_ = reception_report_count;
}
void SetPayloadType(PAYLOAD_TYPE payload_type) {
payload_type_ = payload_type;
}
void SetLength(uint16_t length) { length_ = length; }
public:
typedef struct {
uint8_t v : 2;
uint8_t p : 1;
uint8_t rc : 5;
uint8_t pt : 8;
uint16_t length : 16;
} RTCP_HEADER;
typedef struct {
uint32_t ssrc_of_sender : 32;
uint64_t ntp_timestamp : 64;
uint32_t rtp_timestamp : 32;
uint32_t total_sent_count : 32;
uint32_t total_payload_sent_count : 32;
} SENDER_INFO;
typedef struct {
uint32_t ssrc : 32;
uint8_t fraction_lost : 8;
uint32_t cumulative_packets_lost : 24;
uint32_t highest_sequence_number_received : 32;
uint32_t jitter : 32;
uint32_t lsr : 32;
uint32_t dlsr : 32;
} REPORT;
void SetRtcpHeader(RTCP_HEADER &rtcp_header) {
rtcp_header_.v = rtcp_header.v;
rtcp_header_.p = rtcp_header.p;
rtcp_header_.rc = rtcp_header.rc;
rtcp_header_.pt = rtcp_header.pt;
rtcp_header_.length = rtcp_header.length;
}
void SetSenderInfo(SENDER_INFO &sender_info) {
sender_info_.ssrc_of_sender = sender_info.ssrc_of_sender;
sender_info_.ntp_timestamp = sender_info.ntp_timestamp;
sender_info_.rtp_timestamp = sender_info.rtp_timestamp;
sender_info_.total_sent_count = sender_info.total_sent_count;
sender_info_.total_payload_sent_count =
sender_info.total_payload_sent_count;
}
void SetReport(REPORT &report) {
report_.ssrc = report.ssrc;
report_.fraction_lost = report.fraction_lost;
report_.cumulative_packets_lost = report.cumulative_packets_lost;
report_.highest_sequence_number_received =
report.highest_sequence_number_received;
report_.jitter = report.jitter;
report_.lsr = report.lsr;
report_.dlsr = report.dlsr;
}
public:
const uint8_t *Encode(uint8_t *payload, size_t payload_size);
size_t Decode(uint8_t *payload);
public:
// Get Header
const uint8_t Verion() { return version_; }
const uint8_t Padding() { return padding_; }
const uint8_t ReceptionReportCount() { return reception_report_count_; }
const PAYLOAD_TYPE PayloadType() { return PAYLOAD_TYPE(payload_type_); }
const uint16_t Length() { return length_; }
private:
// Header
uint8_t version_ = 0;
uint8_t padding_ = false;
uint8_t reception_report_count_ = 0;
uint8_t payload_type_ = 0;
uint16_t length_ = 0;
RTCP_HEADER rtcp_header_;
SENDER_INFO sender_info_;
REPORT report_;
} RTCP_TYPE;
};
#endif

View File

@@ -0,0 +1,5 @@
#include "rtcp_receiver_report.h"
RtcpReceiverReport::RtcpReceiverReport() {}
RtcpReceiverReport::~RtcpReceiverReport() {}

View File

@@ -0,0 +1,52 @@
#ifndef _RTCP_RECEIVER_REPORT_H_
#define _RTCP_RECEIVER_REPORT_H_
// RR
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| RC | PT=SR=200 | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of packet sender |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | SSRC_1 (SSRC of first source) | report
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
// | fraction lost | cumulative number of packets lost | 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | extended highest sequence number received |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | interarrival jitter |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | last SR (LSR) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | delay since last SR (DLSR) |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | SSRC_2 (SSRC of second source) | report
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
// : ... : 2
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | profile-specific extensions |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#include <vector>
#include "rtcp_header.h"
#include "rtcp_report_block.h"
#define DEFAULT_SR_SIZE 32
class RtcpReceiverReport {
public:
RtcpReceiverReport();
~RtcpReceiverReport();
public:
const uint8_t *Encode(uint8_t *payload, size_t payload_size);
size_t Decode(uint8_t *payload);
private:
RtcpHeader rtcp_header_;
std::vector<RtcpReportBlock> reports_;
};
#endif

View File

@@ -0,0 +1,5 @@
#include "rtcp_report_block.h"
RtcpReportBlock::RtcpReportBlock() {}
RtcpReportBlock::~RtcpReportBlock() {}

View File

@@ -0,0 +1,53 @@
#ifndef _RTCP_REPORT_BLOCK_H_
#define _RTCP_REPORT_BLOCK_H_
// Report block 1
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC_1 (SSRC of first source) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | fraction lost | cumulative number of packets lost |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | extended highest sequence number received |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | interarrival jitter |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | last SR (LSR) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | delay since last SR (DLSR) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#include <stdint.h>
class RtcpReportBlock {
public:
RtcpReportBlock();
~RtcpReportBlock();
public:
typedef struct {
uint32_t source_ssrc : 32;
uint8_t fraction_lost : 8;
uint32_t cumulative_lost : 24;
uint32_t extended_high_seq_num : 32;
uint32_t jitter : 32;
uint32_t lsr : 32;
uint32_t dlsr : 32;
} REPORT;
void SetReport(REPORT &report) {
report_.source_ssrc = report.source_ssrc;
report_.fraction_lost = report.fraction_lost;
report_.cumulative_lost = report.cumulative_lost;
report_.extended_high_seq_num = report.extended_high_seq_num;
report_.jitter = report.jitter;
report_.lsr = report.lsr;
report_.dlsr = report.dlsr;
}
private:
REPORT report_;
};
#endif

View File

@@ -0,0 +1,52 @@
#include "rtcp_sender_report.h"
RtcpSenderReport::RtcpSenderReport() {
buffer_ = new uint8_t[DEFAULT_SR_SIZE];
size_ = DEFAULT_SR_SIZE;
}
RtcpSenderReport::~RtcpSenderReport() {
if (buffer_) {
delete buffer_;
buffer_ = nullptr;
}
size_ = 0;
}
const uint8_t *RtcpSenderReport::Encode() {
int pos =
rtcp_header_.Encode(DEFAULT_RTCP_VERSION, 0, DEFAULT_SR_BLOCK_NUM,
RtcpPacket::RTCP_TYPE::SR, DEFAULT_SR_SIZE, buffer_);
buffer_[pos] = sender_info_.sender_ssrc >> 24 & 0xFF;
buffer_[pos + 1] = sender_info_.sender_ssrc >> 16 & 0xFF;
buffer_[pos + 2] = sender_info_.sender_ssrc >> 8 & 0xFF;
buffer_[pos + 3] = sender_info_.sender_ssrc & 0xFF;
buffer_[pos + 4] = sender_info_.ntp_ts >> 56 & 0xFF;
buffer_[pos + 5] = sender_info_.ntp_ts >> 48 & 0xFF;
buffer_[pos + 6] = sender_info_.ntp_ts >> 40 & 0xFF;
buffer_[pos + 7] = sender_info_.ntp_ts >> 32 & 0xFF;
buffer_[pos + 8] = sender_info_.ntp_ts >> 24 & 0xFF;
buffer_[pos + 9] = sender_info_.ntp_ts >> 16 & 0xFF;
buffer_[pos + 10] = sender_info_.ntp_ts >> 8 & 0xFF;
buffer_[pos + 11] = sender_info_.ntp_ts & 0xFF;
buffer_[pos + 12] = sender_info_.rtp_ts >> 24 & 0xFF;
buffer_[pos + 13] = sender_info_.rtp_ts >> 16 & 0xFF;
buffer_[pos + 14] = sender_info_.rtp_ts >> 8 & 0xFF;
buffer_[pos + 15] = sender_info_.rtp_ts & 0xFF;
buffer_[pos + 16] = sender_info_.sender_packet_count >> 24 & 0xFF;
buffer_[pos + 17] = sender_info_.sender_packet_count >> 16 & 0xFF;
buffer_[pos + 18] = sender_info_.sender_packet_count >> 8 & 0xFF;
buffer_[pos + 19] = sender_info_.sender_packet_count & 0xFF;
buffer_[pos + 20] = sender_info_.sender_octet_count >> 24 & 0xFF;
buffer_[pos + 21] = sender_info_.sender_octet_count >> 16 & 0xFF;
buffer_[pos + 22] = sender_info_.sender_octet_count >> 8 & 0xFF;
buffer_[pos + 23] = sender_info_.sender_octet_count & 0xFF;
return buffer_;
}

View File

@@ -0,0 +1,88 @@
#ifndef _RTCP_SENDER_REPORT_H_
#define _RTCP_SENDER_REPORT_H_
// SR
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |V=2|P| RC | PT=SR=200 | length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | SSRC of sender |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | NTP timestamp, most significant word | sender
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ info
// | NTP timestamp, least significant word |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | RTP timestamp |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | sender's packet count |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | sender's octet count |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | SSRC_1 (SSRC of first source) | report
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
// | fraction lost | cumulative number of packets lost | 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | extended highest sequence number received |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | interarrival jitter |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | last SR (LSR) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | delay since last SR (DLSR) |
// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
// | SSRC_2 (SSRC of second source) | report
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
// : ... : 2
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#include <vector>
#include "rtcp_header.h"
#include "rtcp_packet.h"
#include "rtcp_report_block.h"
#define DEFAULT_SR_BLOCK_NUM 1
#define DEFAULT_SR_SIZE 52
class RtcpSenderReport {
public:
RtcpSenderReport();
~RtcpSenderReport();
public:
typedef struct {
uint32_t sender_ssrc : 32;
uint64_t ntp_ts : 64;
uint32_t rtp_ts : 32;
uint32_t sender_packet_count : 32;
uint32_t sender_octet_count : 32;
} SENDER_INFO;
void SetSenderInfo(SENDER_INFO &sender_info) {
sender_info_.sender_ssrc = sender_info.sender_ssrc;
sender_info_.ntp_ts = sender_info.ntp_ts;
sender_info_.rtp_ts = sender_info.rtp_ts;
sender_info_.sender_packet_count = sender_info.sender_packet_count;
sender_info_.sender_octet_count = sender_info.sender_octet_count;
}
public:
const uint8_t *Encode();
size_t Decode();
// Entire RTP buffer
const uint8_t *Buffer() const { return buffer_; }
size_t Size() const { return size_; }
private:
RtcpHeader rtcp_header_;
SENDER_INFO sender_info_;
std::vector<RtcpReportBlock> reports_;
// Entire RTCP buffer
uint8_t *buffer_ = nullptr;
size_t size_ = 0;
};
#endif