[feat] use an adapter layer to convert SystemClock into webrtc Clock

This commit is contained in:
dijunkun
2025-02-20 15:31:58 +08:00
parent 899ab05cda
commit f797cc3f91
18 changed files with 96 additions and 66 deletions

View File

@@ -10,47 +10,47 @@
#define NV12_BUFFER_SIZE (1280 * 720 * 3 / 2)
#define RTCP_RR_INTERVAL 1000
RtpVideoReceiver::RtpVideoReceiver(std::shared_ptr<Clock> clock)
RtpVideoReceiver::RtpVideoReceiver(std::shared_ptr<SystemClock> clock)
: feedback_ssrc_(GenerateUniqueSsrc()),
active_remb_module_(nullptr),
receive_side_congestion_controller_(
clock,
clock_,
[this](std::vector<std::unique_ptr<RtcpPacket>> packets) {
SendCombinedRtcpPacket(std::move(packets));
},
[this](int64_t bitrate_bps, std::vector<uint32_t> ssrcs) {
SendRemb(bitrate_bps, ssrcs);
}),
clock_(clock),
rtcp_sender_(std::make_unique<RtcpSender>(
[this](const uint8_t* buffer, size_t size) -> int {
return data_send_func_((const char*)buffer, size);
},
1200)),
nack_(std::make_unique<NackRequester>(clock, this, this)) {
nack_(std::make_unique<NackRequester>(clock_, this, this)),
clock_(webrtc::Clock::GetWebrtcClockShared(clock)) {
SetPeriod(std::chrono::milliseconds(5));
// rtcp_thread_ = std::thread(&RtpVideoReceiver::RtcpThread, this);
}
RtpVideoReceiver::RtpVideoReceiver(std::shared_ptr<Clock> clock,
RtpVideoReceiver::RtpVideoReceiver(std::shared_ptr<SystemClock> clock,
std::shared_ptr<IOStatistics> io_statistics)
: io_statistics_(io_statistics),
feedback_ssrc_(GenerateUniqueSsrc()),
receive_side_congestion_controller_(
clock,
clock_,
[this](std::vector<std::unique_ptr<RtcpPacket>> packets) {
SendCombinedRtcpPacket(std::move(packets));
},
[this](int64_t bitrate_bps, std::vector<uint32_t> ssrcs) {
SendRemb(bitrate_bps, ssrcs);
}),
clock_(clock),
rtcp_sender_(std::make_unique<RtcpSender>(
[this](const uint8_t* buffer, size_t size) -> int {
return data_send_func_((const char*)buffer, size);
},
1200)),
nack_(std::make_unique<NackRequester>(clock, this, this)) {
nack_(std::make_unique<NackRequester>(clock_, this, this)),
clock_(webrtc::Clock::GetWebrtcClockShared(clock)) {
SetPeriod(std::chrono::milliseconds(5));
// rtcp_thread_ = std::thread(&RtpVideoReceiver::RtcpThread, this);

View File

@@ -7,6 +7,7 @@
#include <set>
#include "api/clock/clock.h"
#include "clock/system_clock.h"
#include "fec_decoder.h"
#include "io_statistics.h"
#include "nack_requester.h"
@@ -28,8 +29,8 @@ class RtpVideoReceiver : public ThreadBase,
public KeyFrameRequestSender,
public NackSender {
public:
RtpVideoReceiver(std::shared_ptr<Clock> clock);
RtpVideoReceiver(std::shared_ptr<Clock> clock,
RtpVideoReceiver(std::shared_ptr<SystemClock> clock);
RtpVideoReceiver(std::shared_ptr<SystemClock> clock,
std::shared_ptr<IOStatistics> io_statistics);
virtual ~RtpVideoReceiver();
@@ -113,7 +114,7 @@ class RtpVideoReceiver : public ThreadBase,
int rtcp_tcc_interval_ms_ = 200;
private:
std::shared_ptr<Clock> clock_;
std::shared_ptr<webrtc::Clock> clock_;
ReceiveSideCongestionController receive_side_congestion_controller_;
RtcpFeedbackSenderInterface* active_remb_module_;
uint32_t feedback_ssrc_ = 0;

View File

@@ -2,6 +2,7 @@
#include <chrono>
#include "api/clock/clock.h"
#include "common.h"
#include "log.h"
@@ -11,12 +12,12 @@
RtpVideoSender::RtpVideoSender() {}
RtpVideoSender::RtpVideoSender(std::shared_ptr<webrtc::Clock> clock,
RtpVideoSender::RtpVideoSender(std::shared_ptr<SystemClock> clock,
std::shared_ptr<IOStatistics> io_statistics)
: ssrc_(GenerateUniqueSsrc()),
clock_(clock),
io_statistics_(io_statistics),
rtp_packet_history_(std::make_unique<RtpPacketHistory>(clock)) {
rtp_packet_history_(std::make_unique<RtpPacketHistory>(clock_)),
clock_(webrtc::Clock::GetWebrtcClockShared(clock)) {
SetPeriod(std::chrono::milliseconds(5));
#ifdef SAVE_RTP_SENT_STREAM
file_rtp_sent_ = fopen("rtp_sent_stream.h264", "w+b");

View File

@@ -3,6 +3,8 @@
#include <functional>
#include "api/clock/clock.h"
#include "clock/system_clock.h"
#include "io_statistics.h"
#include "ringbuffer.h"
#include "rtp_packet.h"
@@ -15,7 +17,7 @@
class RtpVideoSender : public ThreadBase {
public:
RtpVideoSender();
RtpVideoSender(std::shared_ptr<webrtc::Clock> clock,
RtpVideoSender(std::shared_ptr<SystemClock> clock,
std::shared_ptr<IOStatistics> io_statistics);
virtual ~RtpVideoSender();