mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Implementation for rtcp receiver report
This commit is contained in:
@@ -12,8 +12,7 @@
|
||||
// |V=2|P| RC | PT=SR=200 | length |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
#define DEFAULT_RTCP_VERSION 2
|
||||
#define DEFAULT_RTCP_HEADER_SIZE 4
|
||||
#include "rtcp_typedef.h"
|
||||
|
||||
class RtcpHeader {
|
||||
public:
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef _RTCP_PACKET_H_
|
||||
#define _RTCP_PACKET_H_
|
||||
|
||||
class RtcpPacket {
|
||||
public:
|
||||
typedef enum {
|
||||
UNKNOWN = 0,
|
||||
SR = 200,
|
||||
RR = 201,
|
||||
SDES = 202,
|
||||
BYE = 203,
|
||||
APP = 204
|
||||
} RTCP_TYPE;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,31 @@
|
||||
#include "rtcp_receiver_report.h"
|
||||
|
||||
RtcpReceiverReport::RtcpReceiverReport() {}
|
||||
RtcpReceiverReport::RtcpReceiverReport() {
|
||||
buffer_ = new uint8_t[DEFAULT_RR_SIZE];
|
||||
size_ = DEFAULT_RR_SIZE;
|
||||
}
|
||||
|
||||
RtcpReceiverReport::~RtcpReceiverReport() {}
|
||||
RtcpReceiverReport::~RtcpReceiverReport() {
|
||||
if (buffer_) {
|
||||
delete buffer_;
|
||||
buffer_ = nullptr;
|
||||
}
|
||||
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
void RtcpReceiverReport::SetReportBlock(RtcpReportBlock &rtcp_report_block) {
|
||||
reports_.push_back(rtcp_report_block);
|
||||
}
|
||||
|
||||
void RtcpReceiverReport::SetReportBlock(
|
||||
std::vector<RtcpReportBlock> &rtcp_report_blocks) {
|
||||
reports_ = rtcp_report_blocks;
|
||||
}
|
||||
|
||||
const uint8_t *RtcpReceiverReport::Encode() {
|
||||
int pos = rtcp_header_.Encode(DEFAULT_RTCP_VERSION, 0, DEFAULT_RR_BLOCK_NUM,
|
||||
RTCP_TYPE::RR, DEFAULT_RR_SIZE, buffer_);
|
||||
|
||||
return buffer_;
|
||||
}
|
||||
@@ -31,9 +31,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "rtcp_header.h"
|
||||
#include "rtcp_report_block.h"
|
||||
|
||||
#define DEFAULT_SR_SIZE 32
|
||||
#include "rtcp_typedef.h"
|
||||
|
||||
class RtcpReceiverReport {
|
||||
public:
|
||||
@@ -41,12 +39,24 @@ class RtcpReceiverReport {
|
||||
~RtcpReceiverReport();
|
||||
|
||||
public:
|
||||
const uint8_t *Encode(uint8_t *payload, size_t payload_size);
|
||||
size_t Decode(uint8_t *payload);
|
||||
void SetReportBlock(RtcpReportBlock &rtcp_report_block);
|
||||
void SetReportBlock(std::vector<RtcpReportBlock> &rtcp_report_blocks);
|
||||
|
||||
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_;
|
||||
std::vector<RtcpReportBlock> reports_;
|
||||
|
||||
// Entire RTCP buffer
|
||||
uint8_t *buffer_ = nullptr;
|
||||
size_t size_ = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "rtcp_report_block.h"
|
||||
|
||||
RtcpReportBlock::RtcpReportBlock() {}
|
||||
|
||||
RtcpReportBlock::~RtcpReportBlock() {}
|
||||
@@ -1,53 +0,0 @@
|
||||
#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
|
||||
@@ -14,24 +14,41 @@ RtcpSenderReport::~RtcpSenderReport() {
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
void RtcpSenderReport::SetSenderInfo(SenderInfo &sender_info) {
|
||||
sender_info_.sender_ssrc = sender_info.sender_ssrc;
|
||||
sender_info_.ntp_ts_msw = sender_info.ntp_ts_msw;
|
||||
sender_info_.ntp_ts_lsw = sender_info.ntp_ts_lsw;
|
||||
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;
|
||||
}
|
||||
|
||||
void RtcpSenderReport::SetReportBlock(RtcpReportBlock &rtcp_report_block) {
|
||||
reports_.push_back(rtcp_report_block);
|
||||
}
|
||||
|
||||
void RtcpSenderReport::SetReportBlock(
|
||||
std::vector<RtcpReportBlock> &rtcp_report_blocks) {
|
||||
reports_ = rtcp_report_blocks;
|
||||
}
|
||||
|
||||
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_);
|
||||
int pos = rtcp_header_.Encode(DEFAULT_RTCP_VERSION, 0, DEFAULT_SR_BLOCK_NUM,
|
||||
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 + 4] = sender_info_.ntp_ts_msw >> 56 & 0xFF;
|
||||
buffer_[pos + 5] = sender_info_.ntp_ts_msw >> 48 & 0xFF;
|
||||
buffer_[pos + 6] = sender_info_.ntp_ts_msw >> 40 & 0xFF;
|
||||
buffer_[pos + 7] = sender_info_.ntp_ts_msw >> 32 & 0xFF;
|
||||
buffer_[pos + 8] = sender_info_.ntp_ts_lsw >> 24 & 0xFF;
|
||||
buffer_[pos + 9] = sender_info_.ntp_ts_lsw >> 16 & 0xFF;
|
||||
buffer_[pos + 10] = sender_info_.ntp_ts_lsw >> 8 & 0xFF;
|
||||
buffer_[pos + 11] = sender_info_.ntp_ts_lsw & 0xFF;
|
||||
|
||||
buffer_[pos + 12] = sender_info_.rtp_ts >> 24 & 0xFF;
|
||||
buffer_[pos + 13] = sender_info_.rtp_ts >> 16 & 0xFF;
|
||||
|
||||
@@ -39,11 +39,7 @@
|
||||
#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
|
||||
#include "rtcp_typedef.h"
|
||||
|
||||
class RtcpSenderReport {
|
||||
public:
|
||||
@@ -51,21 +47,9 @@ class 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;
|
||||
}
|
||||
void SetSenderInfo(SenderInfo &sender_info);
|
||||
void SetReportBlock(RtcpReportBlock &rtcp_report_block);
|
||||
void SetReportBlock(std::vector<RtcpReportBlock> &rtcp_report_blocks);
|
||||
|
||||
public:
|
||||
const uint8_t *Encode();
|
||||
@@ -77,7 +61,7 @@ class RtcpSenderReport {
|
||||
|
||||
private:
|
||||
RtcpHeader rtcp_header_;
|
||||
SENDER_INFO sender_info_;
|
||||
SenderInfo sender_info_;
|
||||
std::vector<RtcpReportBlock> reports_;
|
||||
|
||||
// Entire RTCP buffer
|
||||
|
||||
42
src/rtcp/rtcp_typedef.h
Normal file
42
src/rtcp/rtcp_typedef.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef _RTCP_TYPEDEF_H_
|
||||
#define _RTCP_TYPEDEF_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define DEFAULT_RTCP_VERSION 2
|
||||
#define DEFAULT_RTCP_HEADER_SIZE 4
|
||||
|
||||
#define DEFAULT_SR_BLOCK_NUM 1
|
||||
#define DEFAULT_SR_SIZE 52
|
||||
#define DEFAULT_RR_BLOCK_NUM 1
|
||||
#define DEFAULT_RR_SIZE 32
|
||||
|
||||
typedef enum {
|
||||
UNKNOWN = 0,
|
||||
SR = 200,
|
||||
RR = 201,
|
||||
SDES = 202,
|
||||
BYE = 203,
|
||||
APP = 204
|
||||
} RTCP_TYPE;
|
||||
|
||||
typedef struct {
|
||||
uint32_t sender_ssrc : 32;
|
||||
uint64_t ntp_ts_msw : 64;
|
||||
uint64_t ntp_ts_lsw : 64;
|
||||
uint32_t rtp_ts : 32;
|
||||
uint32_t sender_packet_count : 32;
|
||||
uint32_t sender_octet_count : 32;
|
||||
} SenderInfo;
|
||||
|
||||
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;
|
||||
} RtcpReportBlock;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user