[fix] fix h264 rtp packet parse

This commit is contained in:
dijunkun
2025-01-24 17:54:54 +08:00
parent 7b839ab773
commit 2d5749f93a
10 changed files with 253 additions and 54 deletions

View File

@@ -4,6 +4,8 @@
#include "log.h"
#include "rtcp_sender.h"
#define SAVE_RTP_RECV_STREAM 1
#define NV12_BUFFER_SIZE (1280 * 720 * 3 / 2)
#define RTCP_RR_INTERVAL 1000
@@ -33,6 +35,13 @@ RtpVideoReceiver::RtpVideoReceiver(std::shared_ptr<IOStatistics> io_statistics)
}),
clock_(Clock::GetRealTimeClock()) {
rtcp_thread_ = std::thread(&RtpVideoReceiver::RtcpThread, this);
#ifdef SAVE_RTP_RECV_STREAM
file_rtp_recv_ = fopen("rtp_recv_stream.h264", "w+b");
if (!file_rtp_recv_) {
LOG_WARN("Fail to open rtp_recv_stream.h264");
}
#endif
}
RtpVideoReceiver::~RtpVideoReceiver() {
@@ -48,6 +57,14 @@ RtpVideoReceiver::~RtpVideoReceiver() {
}
SSRCManager::Instance().DeleteSsrc(feedback_ssrc_);
#ifdef SAVE_RTP_RECV_STREAM
if (file_rtp_recv_) {
fflush(file_rtp_recv_);
fclose(file_rtp_recv_);
file_rtp_recv_ = nullptr;
}
#endif
}
void RtpVideoReceiver::InsertRtpPacket(RtpPacket& rtp_packet) {
@@ -56,6 +73,14 @@ void RtpVideoReceiver::InsertRtpPacket(RtpPacket& rtp_packet) {
rtp_statistics_->Start();
}
// #ifdef SAVE_RTP_RECV_STREAM
// // fwrite((unsigned char*)rtp_packet.Buffer().data(), 1,
// rtp_packet.Size(),
// // file_rtp_recv_);
// fwrite((unsigned char*)rtp_packet.Payload(), 1, rtp_packet.PayloadSize(),
// file_rtp_recv_);
// #endif
webrtc::RtpPacketReceived rtp_packet_received;
rtp_packet_received.Build(rtp_packet.Buffer().data(), rtp_packet.Size());
@@ -437,6 +462,10 @@ bool RtpVideoReceiver::Process() {
// last_complete_frame_ts_ = now_complete_frame_ts;
on_receive_complete_frame_(video_frame);
#ifdef SAVE_RTP_RECV_STREAM
fwrite((unsigned char*)video_frame.Buffer(), 1, video_frame.Size(),
file_rtp_recv_);
#endif
}
}

View File

@@ -102,6 +102,9 @@ class RtpVideoReceiver : public ThreadBase {
ReceiveSideCongestionController receive_side_congestion_controller_;
RtcpFeedbackSenderInterface* active_remb_module_;
uint32_t feedback_ssrc_ = 0;
private:
FILE* file_rtp_recv_ = nullptr;
};
#endif

View File

@@ -4,17 +4,34 @@
#include "log.h"
#define SAVE_RTP_SENT_STREAM 1
#define RTCP_SR_INTERVAL 1000
RtpVideoSender::RtpVideoSender() {}
RtpVideoSender::RtpVideoSender(std::shared_ptr<IOStatistics> io_statistics)
: io_statistics_(io_statistics) {}
: io_statistics_(io_statistics) {
#ifdef SAVE_RTP_SENT_STREAM
file_rtp_sent_ = fopen("rtp_sent_stream.h264", "w+b");
if (!file_rtp_sent_) {
LOG_WARN("Fail to open rtp_sent_stream.h264");
}
#endif
}
RtpVideoSender::~RtpVideoSender() {
if (rtp_statistics_) {
rtp_statistics_->Stop();
}
#ifdef SAVE_RTP_SENT_STREAM
if (file_rtp_sent_) {
fflush(file_rtp_sent_);
fclose(file_rtp_sent_);
file_rtp_sent_ = nullptr;
}
#endif
}
void RtpVideoSender::Enqueue(std::vector<RtpPacket>& rtp_packets) {
@@ -45,6 +62,13 @@ int RtpVideoSender::SendRtpPacket(RtpPacket& rtp_packet) {
return -1;
}
#ifdef SAVE_RTP_SENT_STREAM
// fwrite((unsigned char*)rtp_packet.Buffer().data(), 1, rtp_packet.Size(),
// file_rtp_sent_);
fwrite((unsigned char*)rtp_packet.Payload(), 1, rtp_packet.PayloadSize(),
file_rtp_sent_);
#endif
last_send_bytes_ += (uint32_t)rtp_packet.Size();
total_rtp_payload_sent_ += (uint32_t)rtp_packet.PayloadSize();
total_rtp_packets_sent_++;

View File

@@ -40,6 +40,9 @@ class RtpVideoSender : public ThreadBase {
uint32_t last_send_rtcp_sr_packet_ts_ = 0;
uint32_t total_rtp_payload_sent_ = 0;
uint32_t total_rtp_packets_sent_ = 0;
private:
FILE *file_rtp_sent_ = nullptr;
};
#endif