[feat] add pacing controller module

This commit is contained in:
dijunkun
2025-03-12 18:18:19 +08:00
parent 2bf60a9c81
commit 23df1f3b60
15 changed files with 2320 additions and 9 deletions

View File

@@ -0,0 +1,47 @@
#include "rtp_statistics.h"
#include "log.h"
RtpStatistics::RtpStatistics() {}
RtpStatistics::~RtpStatistics() {}
void RtpStatistics::UpdateSentBytes(uint32_t sent_bytes) {
sent_bytes_ += sent_bytes;
}
void RtpStatistics::UpdateReceiveBytes(uint32_t received_bytes) {
received_bytes_ += received_bytes;
}
void RtpStatistics::UpdatePacketLossRate(uint16_t seq_num) {
if (last_received_seq_num_ != 0) {
if (last_received_seq_num_ < seq_num) {
// seq wrap
if (seq_num - last_received_seq_num_ > 0x8000) {
lost_packets_num_ += 0xffff - last_received_seq_num_ + seq_num + 1;
} else {
lost_packets_num_ += seq_num - last_received_seq_num_ - 1;
}
} else if (last_received_seq_num_ > seq_num) {
lost_packets_num_ += 0xffff - last_received_seq_num_ + seq_num + 1;
}
}
last_received_seq_num_ = seq_num;
}
bool RtpStatistics::Process() {
if (!sent_bytes_) {
// LOG_INFO("rtp statistics: Send [{} bps]", sent_bytes_);
}
if (!received_bytes_) {
// LOG_INFO("rtp statistics: Receive [{} bps]", received_bytes_);
}
sent_bytes_ = 0;
received_bytes_ = 0;
std::this_thread::sleep_for(std::chrono::seconds(1));
return true;
}

View File

@@ -0,0 +1,29 @@
#ifndef _RTP_STATISTICS_H_
#define _RTP_STATISTICS_H_
#include "thread_base.h"
class RtpStatistics : public ThreadBase {
public:
RtpStatistics();
virtual ~RtpStatistics();
public:
// send side
void UpdateSentBytes(uint32_t sent_bytes);
// receive side
void UpdateReceiveBytes(uint32_t received_bytes);
void UpdatePacketLossRate(uint16_t seq_num);
private:
bool Process();
private:
uint32_t sent_bytes_ = 0;
uint32_t received_bytes_ = 0;
uint16_t last_received_seq_num_ = 0;
uint32_t lost_packets_num_ = 0;
};
#endif