mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-03-30 05:25:30 +08:00
[feat] use encode thread to encode frame
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user