mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Add rtp video statistics module
This commit is contained in:
18
src/rtp/rtp_video_receive_statistics.cpp
Normal file
18
src/rtp/rtp_video_receive_statistics.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "rtp_video_receive_statistics.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
RtpVideoReceiveStatistics::RtpVideoReceiveStatistics() {}
|
||||
|
||||
RtpVideoReceiveStatistics::~RtpVideoReceiveStatistics() {}
|
||||
|
||||
void RtpVideoReceiveStatistics::UpdateReceiveBytes(uint32_t received_bytes) {
|
||||
received_bytes_ += received_bytes;
|
||||
}
|
||||
|
||||
bool RtpVideoReceiveStatistics::Process() {
|
||||
LOG_INFO("rtp statistics: Receive [{} bps]", received_bytes_);
|
||||
received_bytes_ = 0;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
return true;
|
||||
}
|
||||
21
src/rtp/rtp_video_receive_statistics.h
Normal file
21
src/rtp/rtp_video_receive_statistics.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _RTP_VIDEO_RECEIVE_STATISTICS_H_
|
||||
#define _RTP_VIDEO_RECEIVE_STATISTICS_H_
|
||||
|
||||
#include "thread_base.h"
|
||||
|
||||
class RtpVideoReceiveStatistics : public ThreadBase {
|
||||
public:
|
||||
RtpVideoReceiveStatistics();
|
||||
~RtpVideoReceiveStatistics();
|
||||
|
||||
public:
|
||||
void UpdateReceiveBytes(uint32_t received_bytes);
|
||||
|
||||
private:
|
||||
bool Process();
|
||||
|
||||
private:
|
||||
uint32_t received_bytes_ = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,16 @@ RtpVideoReceiver::RtpVideoReceiver() {}
|
||||
RtpVideoReceiver::~RtpVideoReceiver() {}
|
||||
|
||||
void RtpVideoReceiver::InsertRtpPacket(RtpPacket& rtp_packet) {
|
||||
if (!rtp_video_receive_statistics_) {
|
||||
rtp_video_receive_statistics_ =
|
||||
std::make_unique<RtpVideoReceiveStatistics>();
|
||||
rtp_video_receive_statistics_->Start();
|
||||
}
|
||||
|
||||
if (rtp_video_receive_statistics_) {
|
||||
rtp_video_receive_statistics_->UpdateReceiveBytes(rtp_packet.Size());
|
||||
}
|
||||
|
||||
if (NAL_UNIT_TYPE::NALU == rtp_packet.NalUnitType()) {
|
||||
compelete_video_frame_queue_.push(
|
||||
VideoFrame(rtp_packet.Payload(), rtp_packet.Size()));
|
||||
@@ -93,12 +103,13 @@ bool RtpVideoReceiver::Process() {
|
||||
VideoFrame video_frame;
|
||||
compelete_video_frame_queue_.pop(video_frame);
|
||||
if (on_receive_complete_frame_) {
|
||||
auto now_complete_frame_ts =
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch().count() /
|
||||
1000000;
|
||||
uint32_t duration = now_complete_frame_ts - last_complete_frame_ts_;
|
||||
LOG_ERROR("Duration {}", 1000 / duration);
|
||||
last_complete_frame_ts_ = now_complete_frame_ts;
|
||||
// auto now_complete_frame_ts =
|
||||
// std::chrono::high_resolution_clock::now().time_since_epoch().count()
|
||||
// / 1000000;
|
||||
// uint32_t duration = now_complete_frame_ts - last_complete_frame_ts_;
|
||||
// LOG_ERROR("Duration {}", 1000 / duration);
|
||||
// last_complete_frame_ts_ = now_complete_frame_ts;
|
||||
|
||||
on_receive_complete_frame_(video_frame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "frame.h"
|
||||
#include "ringbuffer.h"
|
||||
#include "rtp_codec.h"
|
||||
#include "rtp_video_receive_statistics.h"
|
||||
#include "thread_base.h"
|
||||
|
||||
class RtpVideoReceiver : public ThreadBase {
|
||||
@@ -35,8 +36,11 @@ class RtpVideoReceiver : public ThreadBase {
|
||||
uint8_t* nv12_data_ = nullptr;
|
||||
std::function<void(VideoFrame&)> on_receive_complete_frame_ = nullptr;
|
||||
uint32_t last_complete_frame_ts_ = 0;
|
||||
|
||||
RingBuffer<VideoFrame> compelete_video_frame_queue_;
|
||||
|
||||
private:
|
||||
std::unique_ptr<RtpVideoReceiveStatistics> rtp_video_receive_statistics_ =
|
||||
nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
18
src/rtp/rtp_video_send_statistics.cpp
Normal file
18
src/rtp/rtp_video_send_statistics.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "rtp_video_send_statistics.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
RtpVideoSendStatistics::RtpVideoSendStatistics() {}
|
||||
|
||||
RtpVideoSendStatistics::~RtpVideoSendStatistics() {}
|
||||
|
||||
void RtpVideoSendStatistics::UpdateSentBytes(uint32_t sent_bytes) {
|
||||
sent_bytes_ += sent_bytes;
|
||||
}
|
||||
|
||||
bool RtpVideoSendStatistics::Process() {
|
||||
LOG_INFO("rtp statistics: Send [{} bps]", sent_bytes_);
|
||||
sent_bytes_ = 0;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
return true;
|
||||
}
|
||||
21
src/rtp/rtp_video_send_statistics.h
Normal file
21
src/rtp/rtp_video_send_statistics.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _RTP_VIDEO_SEND_STATISTICS_H_
|
||||
#define _RTP_VIDEO_SEND_STATISTICS_H_
|
||||
|
||||
#include "thread_base.h"
|
||||
|
||||
class RtpVideoSendStatistics : public ThreadBase {
|
||||
public:
|
||||
RtpVideoSendStatistics();
|
||||
~RtpVideoSendStatistics();
|
||||
|
||||
public:
|
||||
void UpdateSentBytes(uint32_t sent_bytes);
|
||||
|
||||
private:
|
||||
bool Process();
|
||||
|
||||
private:
|
||||
uint32_t sent_bytes_ = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -6,23 +6,36 @@
|
||||
|
||||
RtpVideoSender::RtpVideoSender() {}
|
||||
|
||||
RtpVideoSender::~RtpVideoSender() {}
|
||||
RtpVideoSender::~RtpVideoSender() { rtp_video_send_statistics_->Stop(); }
|
||||
|
||||
void RtpVideoSender::Enqueue(std::vector<RtpPacket>& rtp_packets) {
|
||||
if (!rtp_video_send_statistics_) {
|
||||
rtp_video_send_statistics_ = std::make_unique<RtpVideoSendStatistics>();
|
||||
rtp_video_send_statistics_->Start();
|
||||
}
|
||||
|
||||
for (auto& rtp_packet : rtp_packets) {
|
||||
rtp_packe_queue_.push(rtp_packet);
|
||||
}
|
||||
}
|
||||
|
||||
bool RtpVideoSender::Process() {
|
||||
for (size_t i = 0; i < 50; i++)
|
||||
last_send_bytes_ = 0;
|
||||
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
if (!rtp_packe_queue_.isEmpty()) {
|
||||
RtpPacket rtp_packet;
|
||||
rtp_packe_queue_.pop(rtp_packet);
|
||||
if (rtp_packet_send_func_) {
|
||||
rtp_packet_send_func_(rtp_packet);
|
||||
last_send_bytes_ += rtp_packet.Size();
|
||||
}
|
||||
}
|
||||
|
||||
if (rtp_video_send_statistics_) {
|
||||
rtp_video_send_statistics_->UpdateSentBytes(last_send_bytes_);
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
return true;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "ringbuffer.h"
|
||||
#include "rtp_packet.h"
|
||||
#include "rtp_video_send_statistics.h"
|
||||
#include "thread_base.h"
|
||||
|
||||
class RtpVideoSender : public ThreadBase {
|
||||
@@ -27,6 +28,10 @@ class RtpVideoSender : public ThreadBase {
|
||||
private:
|
||||
std::function<void(RtpPacket &)> rtp_packet_send_func_ = nullptr;
|
||||
RingBuffer<RtpPacket> rtp_packe_queue_;
|
||||
|
||||
private:
|
||||
std::unique_ptr<RtpVideoSendStatistics> rtp_video_send_statistics_ = nullptr;
|
||||
uint32_t last_send_bytes_ = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user