[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();

View File

@@ -5,7 +5,7 @@
VideoChannelReceive::VideoChannelReceive() {}
VideoChannelReceive::VideoChannelReceive(
std::shared_ptr<webrtc::Clock> clock, std::shared_ptr<IceAgent> ice_agent,
std::shared_ptr<SystemClock> clock, std::shared_ptr<IceAgent> ice_agent,
std::shared_ptr<IOStatistics> ice_io_statistics,
std::function<void(VideoFrame &)> on_receive_complete_frame)
: ice_agent_(ice_agent),

View File

@@ -7,7 +7,7 @@
#ifndef _VIDEO_CHANNEL_RECEIVE_H_
#define _VIDEO_CHANNEL_RECEIVE_H_
#include "api/clock/clock.h"
#include "clock/system_clock.h"
#include "ice_agent.h"
#include "rtp_video_receiver.h"
@@ -15,7 +15,7 @@ class VideoChannelReceive {
public:
VideoChannelReceive();
VideoChannelReceive(
std::shared_ptr<webrtc::Clock> clock, std::shared_ptr<IceAgent> ice_agent,
std::shared_ptr<SystemClock> clock, std::shared_ptr<IceAgent> ice_agent,
std::shared_ptr<IOStatistics> ice_io_statistics,
std::function<void(VideoFrame &)> on_receive_complete_frame);
@@ -34,7 +34,7 @@ class VideoChannelReceive {
std::function<void(VideoFrame &)> on_receive_complete_frame_ = nullptr;
private:
std::shared_ptr<Clock> clock_;
std::shared_ptr<SystemClock> clock_;
};
#endif

View File

@@ -8,7 +8,7 @@ VideoChannelSend::VideoChannelSend() {}
VideoChannelSend::~VideoChannelSend() {}
VideoChannelSend::VideoChannelSend(
std::shared_ptr<webrtc::Clock> clock, std::shared_ptr<IceAgent> ice_agent,
std::shared_ptr<SystemClock> clock, std::shared_ptr<IceAgent> ice_agent,
std::shared_ptr<IOStatistics> ice_io_statistics,
std::function<void(const webrtc::RtpPacketToSend& packet)>
on_sent_packet_func)

View File

@@ -7,9 +7,9 @@
#ifndef _VIDEO_CHANNEL_SEND_H_
#define _VIDEO_CHANNEL_SEND_H_
#include "api/clock/clock.h"
#include "api/transport/network_types.h"
#include "api/units/timestamp.h"
#include "clock/system_clock.h"
#include "congestion_control.h"
#include "congestion_control_feedback.h"
#include "ice_agent.h"
@@ -20,7 +20,7 @@
class VideoChannelSend {
public:
VideoChannelSend();
VideoChannelSend(std::shared_ptr<webrtc::Clock> clock,
VideoChannelSend(std::shared_ptr<SystemClock> clock,
std::shared_ptr<IceAgent> ice_agent,
std::shared_ptr<IOStatistics> ice_io_statistics,
std::function<void(const webrtc::RtpPacketToSend& packet)>
@@ -52,7 +52,7 @@ class VideoChannelSend {
on_sent_packet_func_ = nullptr;
private:
std::shared_ptr<Clock> clock_;
std::shared_ptr<SystemClock> clock_;
};
#endif