[feat] use encode thread to encode frame

This commit is contained in:
dijunkun
2025-03-25 17:18:52 +08:00
parent 160ee9feef
commit bcf01791f7
42 changed files with 269 additions and 492 deletions

View File

@@ -6,6 +6,9 @@ RtpPacket::RtpPacket() {}
RtpPacket::RtpPacket(size_t size) : buffer_(size) {}
RtpPacket::RtpPacket(const uint8_t *buffer, uint32_t size)
: buffer_(buffer, size) {}
RtpPacket::RtpPacket(const RtpPacket &rtp_packet) = default;
RtpPacket::RtpPacket(RtpPacket &&rtp_packet) = default;
@@ -14,7 +17,7 @@ RtpPacket &RtpPacket::operator=(const RtpPacket &rtp_packet) = default;
RtpPacket &RtpPacket::operator=(RtpPacket &&rtp_packet) = default;
RtpPacket::~RtpPacket() {}
RtpPacket::~RtpPacket() = default;
bool RtpPacket::Build(const uint8_t *buffer, uint32_t size) {
if (!Parse(buffer, size)) {

View File

@@ -179,6 +179,7 @@ class RtpPacket {
public:
RtpPacket();
RtpPacket(size_t size);
RtpPacket(const uint8_t *buffer, uint32_t size);
RtpPacket(const RtpPacket &rtp_packet);
RtpPacket(RtpPacket &&rtp_packet);
RtpPacket &operator=(const RtpPacket &rtp_packet);

View File

@@ -1,50 +0,0 @@
#include "rtp_statistics.h"
#include "log.h"
RtpStatistics::RtpStatistics() {
SetPeriod(std::chrono::milliseconds(1000));
SetThreadName("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

@@ -1,29 +0,0 @@
#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