From 56db8d09529d5ba92d24954a1d78a90c8ea2cd85 Mon Sep 17 00:00:00 2001 From: Tomas Gunnarsson Date: Sat, 26 Feb 2022 10:32:51 +0000 Subject: [PATCH] Revert "Represent RtpPacketToSend::capture_time with Timestamp" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 385eb9714daa80306d2f92d36678c42892dab555. Reason for revert: Causes problems downstream: # # Fatal error in: rtc_base/units/unit_base.h, line 122 # last system error: 0 # Check failed: value >= 0 (-234 vs. 0) Original change's description: > Represent RtpPacketToSend::capture_time with Timestamp > > Bug: webrtc:13757 > Change-Id: I0ede22cd34e3a59afe1477d8edd495dce64e3242 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/252586 > Reviewed-by: Erik Språng > Reviewed-by: Rasmus Brandt > Commit-Queue: Danil Chapovalov > Cr-Commit-Position: refs/heads/main@{#36083} Bug: webrtc:13757 Change-Id: I8442abd438be8726cf671d0f372d50ecfac6847e No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/252720 Auto-Submit: Tomas Gunnarsson Bot-Commit: rubber-stamper@appspot.gserviceaccount.com Commit-Queue: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#36087} --- api/video/BUILD.gn | 1 - api/video/video_timing.cc | 9 --- api/video/video_timing.h | 3 - modules/pacing/paced_sender.cc | 2 +- modules/pacing/pacing_controller_unittest.cc | 4 +- modules/pacing/task_queue_paced_sender.cc | 2 +- .../deprecated_rtp_sender_egress.cc | 10 +-- modules/rtp_rtcp/source/flexfec_sender.cc | 2 +- modules/rtp_rtcp/source/packet_sequencer.cc | 13 ++-- .../source/packet_sequencer_unittest.cc | 16 ++--- modules/rtp_rtcp/source/rtp_packet_history.cc | 2 +- .../source/rtp_packet_history_unittest.cc | 12 ++-- modules/rtp_rtcp/source/rtp_packet_to_send.h | 50 +++------------ modules/rtp_rtcp/source/rtp_sender.cc | 14 +++-- modules/rtp_rtcp/source/rtp_sender_audio.cc | 4 +- modules/rtp_rtcp/source/rtp_sender_egress.cc | 10 +-- .../source/rtp_sender_egress_unittest.cc | 4 +- .../rtp_rtcp/source/rtp_sender_unittest.cc | 61 +++++++++---------- modules/rtp_rtcp/source/rtp_sender_video.cc | 4 +- 19 files changed, 86 insertions(+), 137 deletions(-) diff --git a/api/video/BUILD.gn b/api/video/BUILD.gn index fcea278f82..9fd28914b2 100644 --- a/api/video/BUILD.gn +++ b/api/video/BUILD.gn @@ -31,7 +31,6 @@ rtc_library("video_rtp_headers") { "../../rtc_base:rtc_base_approved", "../../rtc_base/system:rtc_export", "../units:data_rate", - "../units:time_delta", ] absl_deps = [ "//third_party/abseil-cpp/absl/container:inlined_vector", diff --git a/api/video/video_timing.cc b/api/video/video_timing.cc index 0483c20e66..df1bc4857a 100644 --- a/api/video/video_timing.cc +++ b/api/video/video_timing.cc @@ -11,7 +11,6 @@ #include "api/video/video_timing.h" #include "api/array_view.h" -#include "api/units/time_delta.h" #include "rtc_base/logging.h" #include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/strings/string_builder.h" @@ -26,14 +25,6 @@ uint16_t VideoSendTiming::GetDeltaCappedMs(int64_t base_ms, int64_t time_ms) { return rtc::saturated_cast(time_ms - base_ms); } -uint16_t VideoSendTiming::GetDeltaCappedMs(TimeDelta delta) { - if (delta < TimeDelta::Zero()) { - RTC_DLOG(LS_ERROR) << "Delta " << delta.ms() - << "ms expected to be positive"; - } - return rtc::saturated_cast(delta.ms()); -} - TimingFrameInfo::TimingFrameInfo() : rtp_timestamp(0), capture_time_ms(-1), diff --git a/api/video/video_timing.h b/api/video/video_timing.h index 698477a81a..dd8febb3db 100644 --- a/api/video/video_timing.h +++ b/api/video/video_timing.h @@ -16,8 +16,6 @@ #include #include -#include "api/units/time_delta.h" - namespace webrtc { // Video timing timestamps in ms counted from capture_time_ms of a frame. @@ -36,7 +34,6 @@ struct VideoSendTiming { // https://webrtc.org/experiments/rtp-hdrext/video-timing/ extension stores // 16-bit deltas of timestamps from packet capture time. static uint16_t GetDeltaCappedMs(int64_t base_ms, int64_t time_ms); - static uint16_t GetDeltaCappedMs(TimeDelta delta); uint16_t encode_start_delta_ms; uint16_t encode_finish_delta_ms; diff --git a/modules/pacing/paced_sender.cc b/modules/pacing/paced_sender.cc index 2b2d064ef4..acc492db92 100644 --- a/modules/pacing/paced_sender.cc +++ b/modules/pacing/paced_sender.cc @@ -124,7 +124,7 @@ void PacedSender::EnqueuePackets( packet->SequenceNumber(), "rtp_timestamp", packet->Timestamp()); - RTC_DCHECK_GE(packet->capture_time(), Timestamp::Zero()); + RTC_DCHECK_GE(packet->capture_time_ms(), 0); pacing_controller_.EnqueuePacket(std::move(packet)); } } diff --git a/modules/pacing/pacing_controller_unittest.cc b/modules/pacing/pacing_controller_unittest.cc index a24960d896..e7634cd8d5 100644 --- a/modules/pacing/pacing_controller_unittest.cc +++ b/modules/pacing/pacing_controller_unittest.cc @@ -60,7 +60,7 @@ std::unique_ptr BuildPacket(RtpPacketMediaType type, packet->set_packet_type(type); packet->SetSsrc(ssrc); packet->SetSequenceNumber(sequence_number); - packet->set_capture_time(Timestamp::Millis(capture_time_ms)); + packet->set_capture_time_ms(capture_time_ms); packet->SetPayloadSize(size); return packet; } @@ -73,7 +73,7 @@ class MockPacingControllerCallback : public PacingController::PacketSender { void SendPacket(std::unique_ptr packet, const PacedPacketInfo& cluster_info) override { SendPacket(packet->Ssrc(), packet->SequenceNumber(), - packet->capture_time().ms(), + packet->capture_time_ms(), packet->packet_type() == RtpPacketMediaType::kRetransmission, packet->packet_type() == RtpPacketMediaType::kPadding); } diff --git a/modules/pacing/task_queue_paced_sender.cc b/modules/pacing/task_queue_paced_sender.cc index c392a88720..c58241fdd8 100644 --- a/modules/pacing/task_queue_paced_sender.cc +++ b/modules/pacing/task_queue_paced_sender.cc @@ -141,7 +141,7 @@ void TaskQueuePacedSender::EnqueuePackets( RTC_DCHECK_RUN_ON(&task_queue_); for (auto& packet : packets_) { packet_size_.Apply(1, packet->size()); - RTC_DCHECK_GE(packet->capture_time(), Timestamp::Zero()); + RTC_DCHECK_GE(packet->capture_time_ms(), 0); pacing_controller_.EnqueuePacket(std::move(packet)); } MaybeProcessPackets(Timestamp::MinusInfinity()); diff --git a/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc b/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc index 9cef33165c..c5c06840d2 100644 --- a/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc +++ b/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc @@ -156,7 +156,7 @@ void DEPRECATED_RtpSenderEgress::SendPacket( // In case of VideoTimingExtension, since it's present not in every packet, // data after rtp header may be corrupted if these packets are protected by // the FEC. - int64_t diff_ms = now_ms - packet->capture_time().ms(); + int64_t diff_ms = now_ms - packet->capture_time_ms(); if (packet->HasExtension()) { packet->SetExtension(kTimestampTicksPerMs * diff_ms); } @@ -167,9 +167,9 @@ void DEPRECATED_RtpSenderEgress::SendPacket( if (packet->HasExtension()) { if (populate_network2_timestamp_) { - packet->set_network2_time(Timestamp::Millis(now_ms)); + packet->set_network2_time_ms(now_ms); } else { - packet->set_pacer_exit_time(Timestamp::Millis(now_ms)); + packet->set_pacer_exit_time_ms(now_ms); } } @@ -190,8 +190,8 @@ void DEPRECATED_RtpSenderEgress::SendPacket( if (packet->packet_type() != RtpPacketMediaType::kPadding && packet->packet_type() != RtpPacketMediaType::kRetransmission) { - UpdateDelayStatistics(packet->capture_time().ms(), now_ms, packet_ssrc); - UpdateOnSendPacket(options.packet_id, packet->capture_time().ms(), + UpdateDelayStatistics(packet->capture_time_ms(), now_ms, packet_ssrc); + UpdateOnSendPacket(options.packet_id, packet->capture_time_ms(), packet_ssrc); } diff --git a/modules/rtp_rtcp/source/flexfec_sender.cc b/modules/rtp_rtcp/source/flexfec_sender.cc index f6fe06e0e4..071829f1c0 100644 --- a/modules/rtp_rtcp/source/flexfec_sender.cc +++ b/modules/rtp_rtcp/source/flexfec_sender.cc @@ -142,7 +142,7 @@ std::vector> FlexfecSender::GetFecPackets() { clock_->TimeInMilliseconds())); // Set "capture time" so that the TransmissionOffset header extension // can be set by the RTPSender. - fec_packet_to_send->set_capture_time(clock_->CurrentTime()); + fec_packet_to_send->set_capture_time_ms(clock_->TimeInMilliseconds()); fec_packet_to_send->SetSsrc(ssrc_); // Reserve extensions, if registered. These will be set by the RTPSender. fec_packet_to_send->ReserveExtension(); diff --git a/modules/rtp_rtcp/source/packet_sequencer.cc b/modules/rtp_rtcp/source/packet_sequencer.cc index 55edd768a8..037542ddbd 100644 --- a/modules/rtp_rtcp/source/packet_sequencer.cc +++ b/modules/rtp_rtcp/source/packet_sequencer.cc @@ -99,7 +99,7 @@ void PacketSequencer::UpdateLastPacketState(const RtpPacketToSend& packet) { // Save timestamps to generate timestamp field and extensions for the padding. last_rtp_timestamp_ = packet.Timestamp(); last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); - last_capture_time_ms_ = packet.capture_time().ms(); + last_capture_time_ms_ = packet.capture_time_ms(); } void PacketSequencer::PopulatePaddingFields(RtpPacketToSend& packet) { @@ -107,7 +107,7 @@ void PacketSequencer::PopulatePaddingFields(RtpPacketToSend& packet) { RTC_DCHECK(CanSendPaddingOnMediaSsrc()); packet.SetTimestamp(last_rtp_timestamp_); - packet.set_capture_time(Timestamp::Millis(last_capture_time_ms_)); + packet.set_capture_time_ms(last_capture_time_ms_); packet.SetPayloadType(last_payload_type_); return; } @@ -119,7 +119,7 @@ void PacketSequencer::PopulatePaddingFields(RtpPacketToSend& packet) { } packet.SetTimestamp(last_rtp_timestamp_); - packet.set_capture_time(Timestamp::Millis(last_capture_time_ms_)); + packet.set_capture_time_ms(last_capture_time_ms_); // Only change the timestamp of padding packets sent over RTX. // Padding only packets over RTP has to be sent as part of a media @@ -129,10 +129,9 @@ void PacketSequencer::PopulatePaddingFields(RtpPacketToSend& packet) { packet.SetTimestamp(packet.Timestamp() + (now_ms - last_timestamp_time_ms_) * kTimestampTicksPerMs); - if (packet.capture_time() > Timestamp::Zero()) { - packet.set_capture_time( - packet.capture_time() + - TimeDelta::Millis(now_ms - last_timestamp_time_ms_)); + if (packet.capture_time_ms() > 0) { + packet.set_capture_time_ms(packet.capture_time_ms() + + (now_ms - last_timestamp_time_ms_)); } } } diff --git a/modules/rtp_rtcp/source/packet_sequencer_unittest.cc b/modules/rtp_rtcp/source/packet_sequencer_unittest.cc index d892863768..b82e76541c 100644 --- a/modules/rtp_rtcp/source/packet_sequencer_unittest.cc +++ b/modules/rtp_rtcp/source/packet_sequencer_unittest.cc @@ -41,10 +41,10 @@ class PacketSequencerTest : public ::testing::Test { packet.set_packet_type(type); packet.SetSsrc(ssrc); packet.SetSequenceNumber(kDefaultSequenceNumber); - packet.set_capture_time(clock_.CurrentTime()); + packet.set_capture_time_ms(clock_.TimeInMilliseconds()); packet.SetTimestamp( kStartRtpTimestamp + - static_cast(packet.capture_time().ms() - kStartTime.ms())); + static_cast(packet.capture_time_ms() - kStartTime.ms())); return packet; } @@ -152,7 +152,7 @@ TEST_F(PacketSequencerTest, UpdatesPaddingBasedOnLastMediaPacket) { EXPECT_EQ(padding_packet.SequenceNumber(), kMediaStartSequenceNumber + 1); EXPECT_EQ(padding_packet.PayloadType(), kMediaPayloadType); EXPECT_EQ(padding_packet.Timestamp(), media_packet.Timestamp()); - EXPECT_EQ(padding_packet.capture_time(), media_packet.capture_time()); + EXPECT_EQ(padding_packet.capture_time_ms(), media_packet.capture_time_ms()); } TEST_F(PacketSequencerTest, UpdatesPaddingBasedOnLastRedPacket) { @@ -181,7 +181,7 @@ TEST_F(PacketSequencerTest, UpdatesPaddingBasedOnLastRedPacket) { EXPECT_EQ(padding_packet.SequenceNumber(), kMediaStartSequenceNumber + 1); EXPECT_EQ(padding_packet.PayloadType(), kMediaPayloadType + 1); EXPECT_EQ(padding_packet.Timestamp(), media_packet.Timestamp()); - EXPECT_EQ(padding_packet.capture_time(), media_packet.capture_time()); + EXPECT_EQ(padding_packet.capture_time_ms(), media_packet.capture_time_ms()); } TEST_F(PacketSequencerTest, DoesNotUpdateFieldsOnPayloadPadding) { @@ -201,7 +201,7 @@ TEST_F(PacketSequencerTest, DoesNotUpdateFieldsOnPayloadPadding) { padding_packet.SetPayloadSize(100); padding_packet.SetPayloadType(kMediaPayloadType + 1); padding_packet.SetTimestamp(kStartRtpTimestamp + 1); - padding_packet.set_capture_time(kStartTime + TimeDelta::Millis(1)); + padding_packet.set_capture_time_ms(kStartTime.ms() + 1); sequencer_.set_rtx_sequence_number(kRtxStartSequenceNumber); sequencer_.Sequence(padding_packet); @@ -209,7 +209,7 @@ TEST_F(PacketSequencerTest, DoesNotUpdateFieldsOnPayloadPadding) { EXPECT_EQ(padding_packet.SequenceNumber(), kRtxStartSequenceNumber); EXPECT_EQ(padding_packet.PayloadType(), kMediaPayloadType + 1); EXPECT_EQ(padding_packet.Timestamp(), kStartRtpTimestamp + 1); - EXPECT_EQ(padding_packet.capture_time(), kStartTime + TimeDelta::Millis(1)); + EXPECT_EQ(padding_packet.capture_time_ms(), kStartTime.ms() + 1); } TEST_F(PacketSequencerTest, UpdatesRtxPaddingBasedOnLastMediaPacket) { @@ -242,8 +242,8 @@ TEST_F(PacketSequencerTest, UpdatesRtxPaddingBasedOnLastMediaPacket) { EXPECT_EQ( padding_packet.Timestamp(), media_packet.Timestamp() + (kTimeDelta.ms() * kTimestampTicksPerMs)); - EXPECT_EQ(padding_packet.capture_time(), - media_packet.capture_time() + kTimeDelta); + EXPECT_EQ(padding_packet.capture_time_ms(), + media_packet.capture_time_ms() + kTimeDelta.ms()); } } // namespace diff --git a/modules/rtp_rtcp/source/rtp_packet_history.cc b/modules/rtp_rtcp/source/rtp_packet_history.cc index 0bfb043448..fe5ccc708e 100644 --- a/modules/rtp_rtcp/source/rtp_packet_history.cc +++ b/modules/rtp_rtcp/source/rtp_packet_history.cc @@ -492,7 +492,7 @@ RtpPacketHistory::PacketState RtpPacketHistory::StoredPacketToPacketState( RtpPacketHistory::PacketState state; state.rtp_sequence_number = stored_packet.packet_->SequenceNumber(); state.send_time_ms = stored_packet.send_time_ms_; - state.capture_time_ms = stored_packet.packet_->capture_time().ms(); + state.capture_time_ms = stored_packet.packet_->capture_time_ms(); state.ssrc = stored_packet.packet_->Ssrc(); state.packet_size = stored_packet.packet_->size(); state.times_retransmitted = stored_packet.times_retransmitted(); diff --git a/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc b/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc index ef9ce593b5..90e984a78c 100644 --- a/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_packet_history_unittest.cc @@ -45,7 +45,7 @@ class RtpPacketHistoryTest : public ::testing::TestWithParam { // Payload, ssrc, timestamp and extensions are irrelevant for this tests. std::unique_ptr packet(new RtpPacketToSend(nullptr)); packet->SetSequenceNumber(seq_num); - packet->set_capture_time(fake_clock_.CurrentTime()); + packet->set_capture_time_ms(fake_clock_.TimeInMilliseconds()); packet->set_allow_retransmission(true); return packet; } @@ -122,9 +122,9 @@ TEST_P(RtpPacketHistoryTest, PutRtpPacket) { TEST_P(RtpPacketHistoryTest, GetRtpPacket) { hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10); - Timestamp capture_time = Timestamp::Millis(1); + int64_t capture_time_ms = 1; std::unique_ptr packet = CreateRtpPacket(kStartSeqNum); - packet->set_capture_time(capture_time); + packet->set_capture_time_ms(capture_time_ms); rtc::CopyOnWriteBuffer buffer = packet->Buffer(); hist_.PutRtpPacket(std::move(packet), absl::nullopt); @@ -132,7 +132,7 @@ TEST_P(RtpPacketHistoryTest, GetRtpPacket) { hist_.GetPacketAndSetSendTime(kStartSeqNum); EXPECT_TRUE(packet_out); EXPECT_EQ(buffer, packet_out->Buffer()); - EXPECT_EQ(capture_time, packet_out->capture_time()); + EXPECT_EQ(capture_time_ms, packet_out->capture_time_ms()); } TEST_P(RtpPacketHistoryTest, PacketStateIsCorrect) { @@ -212,7 +212,7 @@ TEST_P(RtpPacketHistoryTest, MinResendTimeWithoutPacer) { hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10); hist_.SetRtt(kMinRetransmitIntervalMs); - Timestamp capture_time = fake_clock_.CurrentTime(); + int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); std::unique_ptr packet = CreateRtpPacket(kStartSeqNum); size_t len = packet->size(); hist_.PutRtpPacket(std::move(packet), fake_clock_.TimeInMilliseconds()); @@ -222,7 +222,7 @@ TEST_P(RtpPacketHistoryTest, MinResendTimeWithoutPacer) { packet = hist_.GetPacketAndSetSendTime(kStartSeqNum); EXPECT_TRUE(packet); EXPECT_EQ(len, packet->size()); - EXPECT_EQ(packet->capture_time(), capture_time); + EXPECT_EQ(capture_time_ms, packet->capture_time_ms()); // Second retransmission - advance time to just before retransmission OK. fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); diff --git a/modules/rtp_rtcp/source/rtp_packet_to_send.h b/modules/rtp_rtcp/source/rtp_packet_to_send.h index 9b3bbf673a..12341ef6cf 100644 --- a/modules/rtp_rtcp/source/rtp_packet_to_send.h +++ b/modules/rtp_rtcp/source/rtp_packet_to_send.h @@ -15,12 +15,10 @@ #include -#include "absl/base/attributes.h" #include "absl/types/optional.h" #include "api/array_view.h" #include "api/ref_counted_base.h" #include "api/scoped_refptr.h" -#include "api/units/timestamp.h" #include "api/video/video_timing.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "modules/rtp_rtcp/source/rtp_header_extensions.h" @@ -46,15 +44,9 @@ class RtpPacketToSend : public RtpPacket { ~RtpPacketToSend(); // Time in local time base as close as it can to frame capture time. - webrtc::Timestamp capture_time() const { return capture_time_; } - void set_capture_time(webrtc::Timestamp time) { capture_time_ = time; } + int64_t capture_time_ms() const { return capture_time_ms_; } - ABSL_DEPRECATED("Use capture_time() instead") - int64_t capture_time_ms() const { return capture_time_.ms_or(-1); } - ABSL_DEPRECATED("Use set_capture_time() instead") - void set_capture_time_ms(int64_t time) { - capture_time_ = webrtc::Timestamp::Millis(time); - } + void set_capture_time_ms(int64_t time) { capture_time_ms_ = time; } void set_packet_type(RtpPacketMediaType type) { packet_type_ = type; } absl::optional packet_type() const { @@ -85,55 +77,27 @@ class RtpPacketToSend : public RtpPacket { additional_data_ = std::move(data); } - void set_packetization_finish_time(webrtc::Timestamp time) { - SetExtension( - VideoSendTiming::GetDeltaCappedMs(time - capture_time_), - VideoTimingExtension::kPacketizationFinishDeltaOffset); - } - - void set_pacer_exit_time(webrtc::Timestamp time) { - SetExtension( - VideoSendTiming::GetDeltaCappedMs(time - capture_time_), - VideoTimingExtension::kPacerExitDeltaOffset); - } - - void set_network_time(webrtc::Timestamp time) { - SetExtension( - VideoSendTiming::GetDeltaCappedMs(time - capture_time_), - VideoTimingExtension::kNetworkTimestampDeltaOffset); - } - - void set_network2_time(webrtc::Timestamp time) { - SetExtension( - VideoSendTiming::GetDeltaCappedMs(time - capture_time_), - VideoTimingExtension::kNetwork2TimestampDeltaOffset); - } - - ABSL_DEPRECATED("Use set_packetization_finish_time() instead") void set_packetization_finish_time_ms(int64_t time) { SetExtension( - VideoSendTiming::GetDeltaCappedMs(capture_time_.ms_or(0), time), + VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), VideoTimingExtension::kPacketizationFinishDeltaOffset); } - ABSL_DEPRECATED("Use set_pacer_exit_time() instead") void set_pacer_exit_time_ms(int64_t time) { SetExtension( - VideoSendTiming::GetDeltaCappedMs(capture_time_.ms_or(0), time), + VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), VideoTimingExtension::kPacerExitDeltaOffset); } - ABSL_DEPRECATED("Use set_network_time() instead") void set_network_time_ms(int64_t time) { SetExtension( - VideoSendTiming::GetDeltaCappedMs(capture_time_.ms_or(0), time), + VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), VideoTimingExtension::kNetworkTimestampDeltaOffset); } - ABSL_DEPRECATED("Use set_network2_time() instead") void set_network2_time_ms(int64_t time) { SetExtension( - VideoSendTiming::GetDeltaCappedMs(capture_time_.ms_or(0), time), + VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), VideoTimingExtension::kNetwork2TimestampDeltaOffset); } @@ -157,7 +121,7 @@ class RtpPacketToSend : public RtpPacket { bool is_red() const { return is_red_; } private: - webrtc::Timestamp capture_time_ = webrtc::Timestamp::Zero(); + int64_t capture_time_ms_ = 0; absl::optional packet_type_; bool allow_retransmission_ = false; absl::optional retransmitted_sequence_number_; diff --git a/modules/rtp_rtcp/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc index a9bc57f7ca..c3321d8723 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -484,11 +484,13 @@ std::vector> RTPSender::GeneratePadding( bool RTPSender::SendToNetwork(std::unique_ptr packet) { RTC_DCHECK(packet); + int64_t now_ms = clock_->TimeInMilliseconds(); + auto packet_type = packet->packet_type(); RTC_CHECK(packet_type) << "Packet type must be set before sending."; - if (packet->capture_time() <= Timestamp::Zero()) { - packet->set_capture_time(clock_->CurrentTime()); + if (packet->capture_time_ms() <= 0) { + packet->set_capture_time_ms(now_ms); } std::vector> packets; @@ -501,13 +503,13 @@ bool RTPSender::SendToNetwork(std::unique_ptr packet) { void RTPSender::EnqueuePackets( std::vector> packets) { RTC_DCHECK(!packets.empty()); - Timestamp now = clock_->CurrentTime(); + int64_t now_ms = clock_->TimeInMilliseconds(); for (auto& packet : packets) { RTC_DCHECK(packet); RTC_CHECK(packet->packet_type().has_value()) << "Packet type must be set before sending."; - if (packet->capture_time() <= Timestamp::Zero()) { - packet->set_capture_time(now); + if (packet->capture_time_ms() <= 0) { + packet->set_capture_time_ms(now_ms); } } @@ -724,7 +726,7 @@ std::unique_ptr RTPSender::BuildRtxPacket( rtx_packet->set_additional_data(packet.additional_data()); // Copy capture time so e.g. TransmissionOffset is correctly set. - rtx_packet->set_capture_time(packet.capture_time()); + rtx_packet->set_capture_time_ms(packet.capture_time_ms()); return rtx_packet; } diff --git a/modules/rtp_rtcp/source/rtp_sender_audio.cc b/modules/rtp_rtcp/source/rtp_sender_audio.cc index c0a8075306..207d1ca045 100644 --- a/modules/rtp_rtcp/source/rtp_sender_audio.cc +++ b/modules/rtp_rtcp/source/rtp_sender_audio.cc @@ -272,7 +272,7 @@ bool RTPSenderAudio::SendAudio(AudioFrameType frame_type, packet->SetMarker(MarkerBit(frame_type, payload_type)); packet->SetPayloadType(payload_type); packet->SetTimestamp(rtp_timestamp); - packet->set_capture_time(clock_->CurrentTime()); + packet->set_capture_time_ms(clock_->TimeInMilliseconds()); // Update audio level extension, if included. packet->SetExtension( frame_type == AudioFrameType::kAudioFrameSpeech, audio_level_dbov); @@ -370,7 +370,7 @@ bool RTPSenderAudio::SendTelephoneEventPacket(bool ended, packet->SetMarker(marker_bit); packet->SetSsrc(rtp_sender_->SSRC()); packet->SetTimestamp(dtmf_timestamp); - packet->set_capture_time(clock_->CurrentTime()); + packet->set_capture_time_ms(clock_->TimeInMilliseconds()); // Create DTMF data. uint8_t* dtmfbuffer = packet->AllocatePayload(kDtmfSize); diff --git a/modules/rtp_rtcp/source/rtp_sender_egress.cc b/modules/rtp_rtcp/source/rtp_sender_egress.cc index b34b54c1fa..eb55378083 100644 --- a/modules/rtp_rtcp/source/rtp_sender_egress.cc +++ b/modules/rtp_rtcp/source/rtp_sender_egress.cc @@ -225,7 +225,7 @@ void RtpSenderEgress::SendPacket(RtpPacketToSend* packet, // In case of VideoTimingExtension, since it's present not in every packet, // data after rtp header may be corrupted if these packets are protected by // the FEC. - int64_t diff_ms = now_ms - packet->capture_time().ms(); + int64_t diff_ms = now_ms - packet->capture_time_ms(); if (packet->HasExtension()) { packet->SetExtension(kTimestampTicksPerMs * diff_ms); } @@ -236,9 +236,9 @@ void RtpSenderEgress::SendPacket(RtpPacketToSend* packet, if (packet->HasExtension()) { if (populate_network2_timestamp_) { - packet->set_network2_time(Timestamp::Millis(now_ms)); + packet->set_network2_time_ms(now_ms); } else { - packet->set_pacer_exit_time(Timestamp::Millis(now_ms)); + packet->set_pacer_exit_time_ms(now_ms); } } @@ -265,8 +265,8 @@ void RtpSenderEgress::SendPacket(RtpPacketToSend* packet, if (packet->packet_type() != RtpPacketMediaType::kPadding && packet->packet_type() != RtpPacketMediaType::kRetransmission) { - UpdateDelayStatistics(packet->capture_time().ms(), now_ms, packet_ssrc); - UpdateOnSendPacket(options.packet_id, packet->capture_time().ms(), + UpdateDelayStatistics(packet->capture_time_ms(), now_ms, packet_ssrc); + UpdateOnSendPacket(options.packet_id, packet->capture_time_ms(), packet_ssrc); } diff --git a/modules/rtp_rtcp/source/rtp_sender_egress_unittest.cc b/modules/rtp_rtcp/source/rtp_sender_egress_unittest.cc index 3d345b1727..0f2a218ae4 100644 --- a/modules/rtp_rtcp/source/rtp_sender_egress_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_sender_egress_unittest.cc @@ -184,7 +184,7 @@ class RtpSenderEgressTest : public ::testing::TestWithParam { packet->set_packet_type(RtpPacketMediaType::kVideo); packet->SetMarker(marker_bit); packet->SetTimestamp(capture_time_ms * 90); - packet->set_capture_time(Timestamp::Millis(capture_time_ms)); + packet->set_capture_time_ms(capture_time_ms); packet->SetSequenceNumber(sequence_number_++); return packet; } @@ -756,7 +756,7 @@ TEST_P(RtpSenderEgressTest, SendPacketUpdatesExtensions) { std::unique_ptr sender = CreateRtpSenderEgress(); std::unique_ptr packet = BuildRtpPacket(); - packet->set_packetization_finish_time(clock_->CurrentTime()); + packet->set_packetization_finish_time_ms(clock_->TimeInMilliseconds()); const int32_t kDiffMs = 10; time_controller_.AdvanceTime(TimeDelta::Millis(kDiffMs)); diff --git a/modules/rtp_rtcp/source/rtp_sender_unittest.cc b/modules/rtp_rtcp/source/rtp_sender_unittest.cc index 0582d71453..99c2c8087a 100644 --- a/modules/rtp_rtcp/source/rtp_sender_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_sender_unittest.cc @@ -198,7 +198,7 @@ class RtpSenderTest : public ::testing::Test { packet->set_packet_type(RtpPacketMediaType::kVideo); packet->SetMarker(marker_bit); packet->SetTimestamp(timestamp); - packet->set_capture_time(Timestamp::Millis(capture_time_ms)); + packet->set_capture_time_ms(capture_time_ms); return packet; } @@ -354,12 +354,13 @@ TEST_F(RtpSenderTest, PaddingAlwaysAllowedOnAudio) { TEST_F(RtpSenderTest, SendToNetworkForwardsPacketsToPacer) { auto packet = BuildRtpPacket(kPayload, kMarkerBit, kTimestamp, 0); - Timestamp now = clock_->CurrentTime(); + int64_t now_ms = clock_->TimeInMilliseconds(); - EXPECT_CALL(mock_paced_sender_, - EnqueuePackets(ElementsAre(AllOf( - Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)), - Pointee(Property(&RtpPacketToSend::capture_time, now)))))); + EXPECT_CALL( + mock_paced_sender_, + EnqueuePackets(ElementsAre(AllOf( + Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)), + Pointee(Property(&RtpPacketToSend::capture_time_ms, now_ms)))))); EXPECT_TRUE( rtp_sender_->SendToNetwork(std::make_unique(*packet))); } @@ -377,8 +378,7 @@ TEST_F(RtpSenderTest, ReSendPacketForwardsPacketsToPacer) { EnqueuePackets(ElementsAre(AllOf( Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)), Pointee(Property(&RtpPacketToSend::SequenceNumber, kSeqNum)), - Pointee(Property(&RtpPacketToSend::capture_time, - Timestamp::Millis(now_ms))), + Pointee(Property(&RtpPacketToSend::capture_time_ms, now_ms)), Pointee(Property(&RtpPacketToSend::packet_type, RtpPacketMediaType::kRetransmission)))))); EXPECT_TRUE(rtp_sender_->ReSendPacket(kSeqNum)); @@ -527,11 +527,10 @@ TEST_F(RtpSenderTest, UpdatesTimestampsOnPlainRtxPadding) { // Start by sending one media packet. EXPECT_CALL( mock_paced_sender_, - EnqueuePackets(ElementsAre( - AllOf(Pointee(Property(&RtpPacketToSend::padding_size, 0u)), - Pointee(Property(&RtpPacketToSend::Timestamp, start_timestamp)), - Pointee(Property(&RtpPacketToSend::capture_time, - Timestamp::Millis(start_time))))))); + EnqueuePackets(ElementsAre(AllOf( + Pointee(Property(&RtpPacketToSend::padding_size, 0u)), + Pointee(Property(&RtpPacketToSend::Timestamp, start_timestamp)), + Pointee(Property(&RtpPacketToSend::capture_time_ms, start_time)))))); std::unique_ptr media_packet = SendPacket(start_time, /*payload_size=*/600); sequencer_->Sequence(*media_packet); @@ -547,8 +546,8 @@ TEST_F(RtpSenderTest, UpdatesTimestampsOnPlainRtxPadding) { Property(&RtpPacketToSend::padding_size, kMaxPaddingLength), Property(&RtpPacketToSend::Timestamp, start_timestamp + (kTimestampTicksPerMs * kTimeDiff.ms())), - Property(&RtpPacketToSend::capture_time, - Timestamp::Millis(start_time) + kTimeDiff))))); + Property(&RtpPacketToSend::capture_time_ms, + start_time + kTimeDiff.ms()))))); } TEST_F(RtpSenderTest, KeepsTimestampsOnPayloadPadding) { @@ -564,11 +563,10 @@ TEST_F(RtpSenderTest, KeepsTimestampsOnPayloadPadding) { // Start by sending one media packet and putting in the packet history. EXPECT_CALL( mock_paced_sender_, - EnqueuePackets(ElementsAre( - AllOf(Pointee(Property(&RtpPacketToSend::padding_size, 0u)), - Pointee(Property(&RtpPacketToSend::Timestamp, start_timestamp)), - Pointee(Property(&RtpPacketToSend::capture_time, - Timestamp::Millis(start_time))))))); + EnqueuePackets(ElementsAre(AllOf( + Pointee(Property(&RtpPacketToSend::padding_size, 0u)), + Pointee(Property(&RtpPacketToSend::Timestamp, start_timestamp)), + Pointee(Property(&RtpPacketToSend::capture_time_ms, start_time)))))); std::unique_ptr media_packet = SendPacket(start_time, kPayloadSize); packet_history_->PutRtpPacket(std::move(media_packet), start_time); @@ -578,14 +576,14 @@ TEST_F(RtpSenderTest, KeepsTimestampsOnPayloadPadding) { time_controller_.AdvanceTime(kTimeDiff); // Timestamps on payload padding should be set to original. - EXPECT_THAT(GeneratePadding(/*target_size_bytes=*/100), - Each(AllOf(Pointee(Property(&RtpPacketToSend::padding_size, 0u)), - Pointee(Property(&RtpPacketToSend::payload_size, - kPayloadSize + kRtxHeaderSize)), - Pointee(Property(&RtpPacketToSend::Timestamp, - start_timestamp)), - Pointee(Property(&RtpPacketToSend::capture_time, - Timestamp::Millis(start_time)))))); + EXPECT_THAT( + GeneratePadding(/*target_size_bytes=*/100), + Each(AllOf( + Pointee(Property(&RtpPacketToSend::padding_size, 0u)), + Pointee(Property(&RtpPacketToSend::payload_size, + kPayloadSize + kRtxHeaderSize)), + Pointee(Property(&RtpPacketToSend::Timestamp, start_timestamp)), + Pointee(Property(&RtpPacketToSend::capture_time_ms, start_time))))); } // Test that the MID header extension is included on sent packets when @@ -1275,10 +1273,9 @@ TEST_F(RtpSenderTest, SetsCaptureTimeOnRtxRetransmissions) { // preserved. time_controller_.AdvanceTime(TimeDelta::Millis(10)); - EXPECT_CALL( - mock_paced_sender_, - EnqueuePackets(ElementsAre(Pointee(Property( - &RtpPacketToSend::capture_time, Timestamp::Millis(start_time_ms)))))); + EXPECT_CALL(mock_paced_sender_, + EnqueuePackets(ElementsAre(Pointee(Property( + &RtpPacketToSend::capture_time_ms, start_time_ms))))); EXPECT_GT(rtp_sender_->ReSendPacket(kSeqNum), 0); } diff --git a/modules/rtp_rtcp/source/rtp_sender_video.cc b/modules/rtp_rtcp/source/rtp_sender_video.cc index 6d6ba33600..da5dad5839 100644 --- a/modules/rtp_rtcp/source/rtp_sender_video.cc +++ b/modules/rtp_rtcp/source/rtp_sender_video.cc @@ -534,7 +534,7 @@ bool RTPSenderVideo::SendVideo( RTC_DCHECK_LE(packet_capacity, single_packet->capacity()); single_packet->SetPayloadType(payload_type); single_packet->SetTimestamp(rtp_timestamp); - single_packet->set_capture_time(Timestamp::Millis(capture_time_ms)); + single_packet->set_capture_time_ms(capture_time_ms); // Construct the absolute capture time extension if not provided. if (!video_header.absolute_capture_time.has_value()) { @@ -695,7 +695,7 @@ bool RTPSenderVideo::SendVideo( // Put packetization finish timestamp into extension. if (packet->HasExtension()) { - packet->set_packetization_finish_time(clock_->CurrentTime()); + packet->set_packetization_finish_time_ms(clock_->TimeInMilliseconds()); } packet->set_fec_protect_packet(use_fec);