[feat] congestion control feedback sending support

This commit is contained in:
dijunkun
2025-01-10 17:21:03 +08:00
parent 49b74ffcd6
commit 63ed77e43a
10 changed files with 159 additions and 342 deletions

View 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