[feat] update sr and rr implementation

This commit is contained in:
dijunkun
2025-02-17 17:32:20 +08:00
parent 71b9c78dd5
commit 4aa9925e56
15 changed files with 577 additions and 17 deletions

View File

@@ -0,0 +1,5 @@
#include "rtcp_receiver.h"
RtcpReceiver::RtcpReceiver() {}
RtcpReceiver::~RtcpReceiver() {}

View File

@@ -0,0 +1,19 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-02-17
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _RTCP_RECEIVER_H_
#define _RTCP_RECEIVER_H_
class RtcpReceiver {
public:
RtcpReceiver();
~RtcpReceiver();
public:
private:
}
#endif

View File

@@ -0,0 +1,43 @@
#include "rtcp_sender.h"
RtcpSender::RtcpSender(std::shared_ptr<webrtc::Clock> clock, uint32_t ssrc)
: clock_(clock), ssrc_(ssrc) {}
RtcpSender::~RtcpSender() {}
void RtcpSender::BuildSR(const RtcpContext& ctx, PacketSender& sender) {
// The timestamp of this RTCP packet should be estimated as the timestamp of
// the frame being captured at this moment. We are calculating that
// timestamp as the last frame's timestamp + the time since the last frame
// was captured.
int rtp_rate = rtp_clock_rates_khz_[last_payload_type_];
if (rtp_rate <= 0) {
rtp_rate =
(audio_ ? kBogusRtpRateForAudioRtcp : kVideoPayloadTypeFrequency) /
1000;
}
// Round now_us_ to the closest millisecond, because Ntp time is rounded
// when converted to milliseconds,
uint32_t rtp_timestamp =
timestamp_offset_ + last_rtp_timestamp_ +
((ctx.now_.us() + 500) / 1000 - last_frame_capture_time_->ms()) *
rtp_rate;
rtcp::SenderReport report;
report.SetSenderSsrc(ssrc_);
report.SetNtp(env_.clock().ConvertTimestampToNtpTime(ctx.now_));
report.SetRtpTimestamp(rtp_timestamp);
report.SetPacketCount(ctx.feedback_state_.packets_sent);
report.SetOctetCount(ctx.feedback_state_.media_bytes_sent);
report.SetReportBlocks(CreateReportBlocks(ctx.feedback_state_));
sender.AppendPacket(report);
}
void RtcpSender::BuildRR(const RtcpContext& ctx, PacketSender& sender) {
rtcp::ReceiverReport report;
report.SetSenderSsrc(ssrc_);
report.SetReportBlocks(CreateReportBlocks(ctx.feedback_state_));
if (method_ == RtcpMode::kCompound || !report.report_blocks().empty()) {
sender.AppendPacket(report);
}
}

View File

@@ -0,0 +1,26 @@
/*
* @Author: DI JUNKUN
* @Date: 2025-02-17
* Copyright (c) 2025 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _RTCP_SENDER_H_
#define _RTCP_SENDER_H_
#include <memory>
#include "api/clock/clock.h"
#include "rtcp/rtcp_packet/rtcp_packet.h"
class RtcpSender {
public:
RtcpSender(std::shared_ptr<webrtc::Clock> clock, uint32_t ssrc);
~RtcpSender();
public:
private:
std::shared_ptr<webrtc::Clock> clock_;
uint32_t ssrc_;
}
#endif