[fix] fix video frame capture timestamp

This commit is contained in:
dijunkun
2025-03-19 14:35:48 +08:00
parent 257581e5e9
commit 1cd9ea1b0e
22 changed files with 45 additions and 50 deletions

View File

@@ -45,7 +45,7 @@ RtpVideoSender::~RtpVideoSender() {
void RtpVideoSender::Enqueue(
std::vector<std::unique_ptr<RtpPacket>>& rtp_packets,
int64_t capture_timestamp_ms) {
int64_t capture_timestamp_us) {
if (!rtp_statistics_) {
rtp_statistics_ = std::make_unique<RtpStatistics>();
rtp_statistics_->Start();

View File

@@ -24,7 +24,7 @@ class RtpVideoSender : public ThreadBase {
public:
void Enqueue(std::vector<std::unique_ptr<RtpPacket>> &rtp_packets,
int64_t capture_timestamp_ms);
int64_t capture_timestamp_us);
void SetSendDataFunc(std::function<int(const char *, size_t)> data_send_func);
void SetOnSentPacketFunc(
std::function<void(const webrtc::RtpPacketToSend &)> on_sent_packet_func);

View File

@@ -57,9 +57,9 @@ void VideoChannelSend::SetEnqueuePacketsFunc(
}
std::vector<std::unique_ptr<RtpPacket>> VideoChannelSend::GeneratePadding(
uint32_t payload_size, int64_t capture_timestamp_ms) {
uint32_t payload_size, int64_t capture_timestamp_us) {
if (rtp_packetizer_) {
return rtp_packetizer_->BuildPadding(payload_size, capture_timestamp_ms,
return rtp_packetizer_->BuildPadding(payload_size, capture_timestamp_us,
true);
}
return std::vector<std::unique_ptr<RtpPacket>>{};

View File

@@ -36,7 +36,7 @@ class VideoChannelSend {
enqueue_packets_func);
std::vector<std::unique_ptr<RtpPacket>> GeneratePadding(
uint32_t payload_size, int64_t capture_timestamp_ms);
uint32_t payload_size, int64_t capture_timestamp_us);
int64_t GetTransportSeqAndIncrement() {
int64_t transport_seq = rtp_video_sender_->GetTransportSequenceNumber();

View File

@@ -75,9 +75,9 @@ void IceTransportController::Create(
});
packet_sender_->SetGeneratePaddingFunc(
[this](uint32_t size, int64_t capture_timestamp_ms)
[this](uint32_t size, int64_t capture_timestamp_us)
-> std::vector<std::unique_ptr<RtpPacket>> {
return video_channel_send_->GeneratePadding(size, capture_timestamp_ms);
return video_channel_send_->GeneratePadding(size, capture_timestamp_us);
});
audio_channel_send_ = std::make_unique<AudioChannelSend>(
@@ -170,6 +170,7 @@ int IceTransportController::SendVideo(const XVideoFrame* video_frame) {
new_frame.width = video_frame->width;
new_frame.height = video_frame->height;
new_frame.size = video_frame->size;
new_frame.timestamp = video_frame->timestamp;
if (target_width_.has_value() && target_height_.has_value()) {
if (target_width_.value() < video_frame->width &&
target_height_.value() < video_frame->height) {

View File

@@ -20,7 +20,7 @@ class PacketSender {
virtual int Send() = 0;
virtual int EnqueueRtpPacket(
std::vector<std::unique_ptr<RtpPacket>> &rtp_packets,
int64_t capture_timestamp_ms) = 0;
int64_t capture_timestamp_us) = 0;
};
#endif

View File

@@ -250,13 +250,13 @@ PacketSenderImp::Stats PacketSenderImp::GetStats() const {
int PacketSenderImp::EnqueueRtpPacket(
std::vector<std::unique_ptr<RtpPacket>> &rtp_packets,
int64_t capture_timestamp_ms) {
int64_t capture_timestamp_us) {
std::vector<std::unique_ptr<webrtc::RtpPacketToSend>> to_send_rtp_packets;
for (auto &rtp_packet : rtp_packets) {
std::unique_ptr<webrtc::RtpPacketToSend> rtp_packet_to_send(
static_cast<webrtc::RtpPacketToSend *>(rtp_packet.release()));
rtp_packet_to_send->set_capture_time(
webrtc::Timestamp::Millis(capture_timestamp_ms));
webrtc::Timestamp::Micros(capture_timestamp_us));
rtp_packet_to_send->set_transport_sequence_number(transport_seq_++);
switch (rtp_packet_to_send->PayloadType()) {

View File

@@ -38,7 +38,7 @@ class PacketSenderImp : public PacketSender,
int Send() { return 0; }
int EnqueueRtpPacket(std::vector<std::unique_ptr<RtpPacket>>& rtp_packets,
int64_t capture_timestamp_ms);
int64_t capture_timestamp_us);
void SetOnSentPacketFunc(
std::function<void(const webrtc::RtpPacketToSend&)> on_sent_packet_func) {
@@ -61,12 +61,6 @@ class PacketSenderImp : public PacketSender,
packet->UpdateSequenceNumber(ssrc_seq_[packet->Ssrc()]++);
webrtc::Timestamp now = clock_->CurrentTime();
webrtc::TimeDelta interval = now - last_send_time_;
webrtc::TimeDelta delay = now - packet->capture_time();
LOG_WARN("interval: {}, delay: {}", interval.ms(), delay.seconds());
last_send_time_ = now;
on_sent_packet_func_(*packet);
}
}