[fix] fix sender report building and parsing

This commit is contained in:
dijunkun
2025-02-27 17:30:41 +08:00
parent b7a5066c6b
commit 962d856946
12 changed files with 108 additions and 65 deletions

View File

@@ -13,6 +13,7 @@
#include "receiver_report.h"
#include "rtp_packet.h"
#include "rtp_statistics.h"
#include "sender_report.h"
class RtpAudioReceiver {
public:
@@ -32,7 +33,7 @@ class RtpAudioReceiver {
uint32_t GetSsrc() { return ssrc_; }
uint32_t GetRemoteSsrc() { return remote_ssrc_; }
void OnSenderReport(int64_t now_time, uint64_t ntp_time) {}
void OnSenderReport(const SenderReport& sender_report) {}
private:
bool CheckIsTimeSendRR();

View File

@@ -7,7 +7,7 @@
#include "receiver_report.h"
#include "rtp_packet.h"
#include "rtp_statistics.h"
#include "sender_report.h"
class RtpDataReceiver {
public:
RtpDataReceiver();
@@ -26,7 +26,7 @@ class RtpDataReceiver {
uint32_t GetSsrc() { return ssrc_; }
uint32_t GetRemoteSsrc() { return remote_ssrc_; }
void OnSenderReport(int64_t now_time, uint64_t ntp_time) {}
void OnSenderReport(const SenderReport& sender_report) {}
private:
bool CheckIsTimeSendRR();

View File

@@ -1,5 +1,6 @@
#include "rtp_video_receiver.h"
#include "api/ntp/ntp_time_util.h"
#include "common.h"
#include "log.h"
#include "nack.h"
@@ -566,11 +567,29 @@ inline uint32_t DivideRoundToNearest(int64_t dividend, int64_t divisor) {
return quotient;
}
void RtpVideoReceiver::OnSenderReport(int64_t now_time, uint64_t ntp_time) {
last_sr_ = ((uint32_t)(ntp_time / 0x100000000) << 16) |
((uint32_t)(ntp_time % 0x100000000) >> 16);
last_delay_ = DivideRoundToNearest(
(clock_->CurrentTime().us() - now_time) * 0x10000, 1000000);
void RtpVideoReceiver::OnSenderReport(const SenderReport& sender_report) {
remote_ssrc = sender_report.SenderSsrc();
last_remote_ntp_timestamp = sender_report.NtpTimestamp();
last_remote_rtp_timestamp = sender_report.Timestamp();
last_arrival_timestamp = clock_->CurrentTime().ms();
last_arrival_ntp_timestamp = webrtc::CompactNtp(clock_->CurrentNtpTime());
packets_sent = sender_report.SenderPacketCount();
bytes_sent = sender_report.SenderOctetCount();
reports_count++;
LOG_WARN("OnSenderReport [{}][{}]", last_sr_, last_delay_);
LOG_WARN(
"OnSenderReport remote_ssrc[{}], last_remote_ntp_timestamp[{}], "
"last_remote_rtp_timestamp[{}], last_arrival_timestamp[{}], "
"last_arrival_ntp_timestamp[{}], packets_sent[{}], bytes_sent[{}], "
"reports_count[{}]",
remote_ssrc, last_remote_ntp_timestamp, last_remote_rtp_timestamp,
last_arrival_timestamp, last_arrival_ntp_timestamp, packets_sent,
bytes_sent, reports_count);
// last_sr_ = ((uint32_t)(ntp_time / 0x100000000) << 16) |
// ((uint32_t)(ntp_time % 0x100000000) >> 16);
// last_delay_ = DivideRoundToNearest(
// (clock_->CurrentTime().us() - now_time) * 0x10000, 1000000);
// LOG_WARN("OnSenderReport [{}][{}] {}", last_sr_, last_delay_, now_time);
}

View File

@@ -19,6 +19,7 @@
#include "rtp_packet_h264.h"
#include "rtp_rtcp_defines.h"
#include "rtp_statistics.h"
#include "sender_report.h"
#include "thread_base.h"
#include "video_frame.h"
@@ -45,7 +46,7 @@ class RtpVideoReceiver : public ThreadBase,
}
uint32_t GetSsrc() { return ssrc_; }
uint32_t GetRemoteSsrc() { return remote_ssrc_; }
void OnSenderReport(int64_t now_time, uint64_t ntp_time);
void OnSenderReport(const SenderReport& sender_report);
private:
void ProcessAv1RtpPacket(RtpPacketAv1& rtp_packet_av1);
@@ -130,6 +131,15 @@ class RtpVideoReceiver : public ThreadBase,
uint32_t last_sr_ = 0;
uint32_t last_delay_ = 0;
uint32_t remote_ssrc = 0;
uint32_t last_remote_ntp_timestamp = 0;
uint32_t last_remote_rtp_timestamp = 0;
uint32_t last_arrival_timestamp = 0;
uint32_t last_arrival_ntp_timestamp = 0;
uint32_t packets_sent = 0;
uint32_t bytes_sent = 0;
uint32_t reports_count = 0;
private:
FILE* file_rtp_recv_ = nullptr;
};