mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[feat] congestion control feedback sending support
This commit is contained in:
53
src/rtcp/rtcp_sender/rtcp_sender.h
Normal file
53
src/rtcp/rtcp_sender/rtcp_sender.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* @Author: DI JUNKUN
|
||||
* @Date: 2025-01-10
|
||||
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _RTCP_SENDER_H_
|
||||
#define _RTCP_SENDER_H_
|
||||
|
||||
#define IP_PACKET_SIZE 1500
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
class RTCPSender {
|
||||
public:
|
||||
RTCPSender(std::function<int(const uint8_t*, size_t)> callback,
|
||||
size_t max_packet_size)
|
||||
: callback_(callback), max_packet_size_(max_packet_size) {
|
||||
if (max_packet_size > IP_PACKET_SIZE) {
|
||||
LOG_ERROR("max_packet_size must be less than IP_PACKET_SIZE");
|
||||
}
|
||||
}
|
||||
~RTCPSender() {
|
||||
if (index_ == 0) {
|
||||
LOG_ERROR("Unsent rtcp packet");
|
||||
}
|
||||
}
|
||||
|
||||
// Appends a packet to pending compound packet.
|
||||
// Sends rtcp packet if buffer is full and resets the buffer.
|
||||
void AppendPacket(const RtcpPacket& packet) {
|
||||
packet.Create(buffer_, &index_, max_packet_size_, callback_);
|
||||
}
|
||||
|
||||
// Sends pending rtcp packet.
|
||||
void Send() {
|
||||
if (index_ > 0 && callback_) {
|
||||
callback_(buffer_, index_);
|
||||
index_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<int(const uint8_t*, size_t)> callback_ = nullptr;
|
||||
const size_t max_packet_size_;
|
||||
size_t index_ = 0;
|
||||
uint8_t buffer_[IP_PACKET_SIZE];
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user