diff --git a/api/video/BUILD.gn b/api/video/BUILD.gn index 9fd28914b2..fcea278f82 100644 --- a/api/video/BUILD.gn +++ b/api/video/BUILD.gn @@ -31,6 +31,7 @@ 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 df1bc4857a..0483c20e66 100644 --- a/api/video/video_timing.cc +++ b/api/video/video_timing.cc @@ -11,6 +11,7 @@ #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" @@ -25,6 +26,14 @@ 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 dd8febb3db..698477a81a 100644 --- a/api/video/video_timing.h +++ b/api/video/video_timing.h @@ -16,6 +16,8 @@ #include #include +#include "api/units/time_delta.h" + namespace webrtc { // Video timing timestamps in ms counted from capture_time_ms of a frame. @@ -34,6 +36,7 @@ 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 acc492db92..2b2d064ef4 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_ms(), 0); + RTC_DCHECK_GE(packet->capture_time(), Timestamp::Zero()); pacing_controller_.EnqueuePacket(std::move(packet)); } } diff --git a/modules/pacing/pacing_controller_unittest.cc b/modules/pacing/pacing_controller_unittest.cc index e7634cd8d5..a24960d896 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_ms(capture_time_ms); + packet->set_capture_time(Timestamp::Millis(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 c58241fdd8..c392a88720 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_ms(), 0); + RTC_DCHECK_GE(packet->capture_time(), Timestamp::Zero()); 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 c5c06840d2..9cef33165c 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_ms(now_ms); + packet->set_network2_time(Timestamp::Millis(now_ms)); } else { - packet->set_pacer_exit_time_ms(now_ms); + packet->set_pacer_exit_time(Timestamp::Millis(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 071829f1c0..f6fe06e0e4 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_ms(clock_->TimeInMilliseconds()); + fec_packet_to_send->set_capture_time(clock_->CurrentTime()); 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 037542ddbd..55edd768a8 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_ms(last_capture_time_ms_); + packet.set_capture_time(Timestamp::Millis(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_ms(last_capture_time_ms_); + packet.set_capture_time(Timestamp::Millis(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,9 +129,10 @@ void PacketSequencer::PopulatePaddingFields(RtpPacketToSend& packet) { packet.SetTimestamp(packet.Timestamp() + (now_ms - last_timestamp_time_ms_) * kTimestampTicksPerMs); - if (packet.capture_time_ms() > 0) { - packet.set_capture_time_ms(packet.capture_time_ms() + - (now_ms - last_timestamp_time_ms_)); + if (packet.capture_time() > Timestamp::Zero()) { + packet.set_capture_time( + packet.capture_time() + + TimeDelta::Millis(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 b82e76541c..d892863768 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_ms(clock_.TimeInMilliseconds()); + packet.set_capture_time(clock_.CurrentTime()); 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_ms(), media_packet.capture_time_ms()); + EXPECT_EQ(padding_packet.capture_time(), media_packet.capture_time()); } 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_ms(), media_packet.capture_time_ms()); + EXPECT_EQ(padding_packet.capture_time(), media_packet.capture_time()); } 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_ms(kStartTime.ms() + 1); + padding_packet.set_capture_time(kStartTime + TimeDelta::Millis(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_ms(), kStartTime.ms() + 1); + EXPECT_EQ(padding_packet.capture_time(), kStartTime + TimeDelta::Millis(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_ms(), - media_packet.capture_time_ms() + kTimeDelta.ms()); + EXPECT_EQ(padding_packet.capture_time(), + media_packet.capture_time() + kTimeDelta); } } // namespace diff --git a/modules/rtp_rtcp/source/rtp_packet_history.cc b/modules/rtp_rtcp/source/rtp_packet_history.cc index fe5ccc708e..0bfb043448 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 90e984a78c..ef9ce593b5 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_ms(fake_clock_.TimeInMilliseconds()); + packet->set_capture_time(fake_clock_.CurrentTime()); packet->set_allow_retransmission(true); return packet; } @@ -122,9 +122,9 @@ TEST_P(RtpPacketHistoryTest, PutRtpPacket) { TEST_P(RtpPacketHistoryTest, GetRtpPacket) { hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10); - int64_t capture_time_ms = 1; + Timestamp capture_time = Timestamp::Millis(1); std::unique_ptr packet = CreateRtpPacket(kStartSeqNum); - packet->set_capture_time_ms(capture_time_ms); + packet->set_capture_time(capture_time); 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_ms, packet_out->capture_time_ms()); + EXPECT_EQ(capture_time, packet_out->capture_time()); } TEST_P(RtpPacketHistoryTest, PacketStateIsCorrect) { @@ -212,7 +212,7 @@ TEST_P(RtpPacketHistoryTest, MinResendTimeWithoutPacer) { hist_.SetStorePacketsStatus(StorageMode::kStoreAndCull, 10); hist_.SetRtt(kMinRetransmitIntervalMs); - int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); + Timestamp capture_time = fake_clock_.CurrentTime(); 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(capture_time_ms, packet->capture_time_ms()); + EXPECT_EQ(packet->capture_time(), capture_time); // 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 12341ef6cf..9b3bbf673a 100644 --- a/modules/rtp_rtcp/source/rtp_packet_to_send.h +++ b/modules/rtp_rtcp/source/rtp_packet_to_send.h @@ -15,10 +15,12 @@ #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" @@ -44,9 +46,15 @@ class RtpPacketToSend : public RtpPacket { ~RtpPacketToSend(); // Time in local time base as close as it can to frame capture time. - int64_t capture_time_ms() const { return capture_time_ms_; } + webrtc::Timestamp capture_time() const { return capture_time_; } + void set_capture_time(webrtc::Timestamp time) { capture_time_ = time; } - void set_capture_time_ms(int64_t time) { capture_time_ms_ = time; } + 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_packet_type(RtpPacketMediaType type) { packet_type_ = type; } absl::optional packet_type() const { @@ -77,27 +85,55 @@ class RtpPacketToSend : public RtpPacket { additional_data_ = std::move(data); } - void set_packetization_finish_time_ms(int64_t time) { + void set_packetization_finish_time(webrtc::Timestamp time) { SetExtension( - VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), + VideoSendTiming::GetDeltaCappedMs(time - capture_time_), VideoTimingExtension::kPacketizationFinishDeltaOffset); } - void set_pacer_exit_time_ms(int64_t time) { + void set_pacer_exit_time(webrtc::Timestamp time) { SetExtension( - VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), + VideoSendTiming::GetDeltaCappedMs(time - capture_time_), VideoTimingExtension::kPacerExitDeltaOffset); } - void set_network_time_ms(int64_t time) { + void set_network_time(webrtc::Timestamp time) { SetExtension( - VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), + 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), + 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), + 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), + VideoTimingExtension::kNetworkTimestampDeltaOffset); + } + + ABSL_DEPRECATED("Use set_network2_time() instead") void set_network2_time_ms(int64_t time) { SetExtension( - VideoSendTiming::GetDeltaCappedMs(capture_time_ms_, time), + VideoSendTiming::GetDeltaCappedMs(capture_time_.ms_or(0), time), VideoTimingExtension::kNetwork2TimestampDeltaOffset); } @@ -121,7 +157,7 @@ class RtpPacketToSend : public RtpPacket { bool is_red() const { return is_red_; } private: - int64_t capture_time_ms_ = 0; + webrtc::Timestamp capture_time_ = webrtc::Timestamp::Zero(); 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 c3321d8723..a9bc57f7ca 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -484,13 +484,11 @@ 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_ms() <= 0) { - packet->set_capture_time_ms(now_ms); + if (packet->capture_time() <= Timestamp::Zero()) { + packet->set_capture_time(clock_->CurrentTime()); } std::vector> packets; @@ -503,13 +501,13 @@ bool RTPSender::SendToNetwork(std::unique_ptr packet) { void RTPSender::EnqueuePackets( std::vector> packets) { RTC_DCHECK(!packets.empty()); - int64_t now_ms = clock_->TimeInMilliseconds(); + Timestamp now = clock_->CurrentTime(); 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_ms() <= 0) { - packet->set_capture_time_ms(now_ms); + if (packet->capture_time() <= Timestamp::Zero()) { + packet->set_capture_time(now); } } @@ -726,7 +724,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_ms(packet.capture_time_ms()); + rtx_packet->set_capture_time(packet.capture_time()); return rtx_packet; } diff --git a/modules/rtp_rtcp/source/rtp_sender_audio.cc b/modules/rtp_rtcp/source/rtp_sender_audio.cc index 207d1ca045..c0a8075306 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_ms(clock_->TimeInMilliseconds()); + packet->set_capture_time(clock_->CurrentTime()); // 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_ms(clock_->TimeInMilliseconds()); + packet->set_capture_time(clock_->CurrentTime()); // 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 eb55378083..b34b54c1fa 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_ms(now_ms); + packet->set_network2_time(Timestamp::Millis(now_ms)); } else { - packet->set_pacer_exit_time_ms(now_ms); + packet->set_pacer_exit_time(Timestamp::Millis(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 0f2a218ae4..3d345b1727 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_ms(capture_time_ms); + packet->set_capture_time(Timestamp::Millis(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_ms(clock_->TimeInMilliseconds()); + packet->set_packetization_finish_time(clock_->CurrentTime()); 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 99c2c8087a..0582d71453 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_ms(capture_time_ms); + packet->set_capture_time(Timestamp::Millis(capture_time_ms)); return packet; } @@ -354,13 +354,12 @@ TEST_F(RtpSenderTest, PaddingAlwaysAllowedOnAudio) { TEST_F(RtpSenderTest, SendToNetworkForwardsPacketsToPacer) { auto packet = BuildRtpPacket(kPayload, kMarkerBit, kTimestamp, 0); - int64_t now_ms = clock_->TimeInMilliseconds(); + Timestamp now = clock_->CurrentTime(); - EXPECT_CALL( - mock_paced_sender_, - EnqueuePackets(ElementsAre(AllOf( - Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)), - Pointee(Property(&RtpPacketToSend::capture_time_ms, now_ms)))))); + EXPECT_CALL(mock_paced_sender_, + EnqueuePackets(ElementsAre(AllOf( + Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)), + Pointee(Property(&RtpPacketToSend::capture_time, now)))))); EXPECT_TRUE( rtp_sender_->SendToNetwork(std::make_unique(*packet))); } @@ -378,7 +377,8 @@ TEST_F(RtpSenderTest, ReSendPacketForwardsPacketsToPacer) { EnqueuePackets(ElementsAre(AllOf( Pointee(Property(&RtpPacketToSend::Ssrc, kSsrc)), Pointee(Property(&RtpPacketToSend::SequenceNumber, kSeqNum)), - Pointee(Property(&RtpPacketToSend::capture_time_ms, now_ms)), + Pointee(Property(&RtpPacketToSend::capture_time, + Timestamp::Millis(now_ms))), Pointee(Property(&RtpPacketToSend::packet_type, RtpPacketMediaType::kRetransmission)))))); EXPECT_TRUE(rtp_sender_->ReSendPacket(kSeqNum)); @@ -527,10 +527,11 @@ 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_ms, start_time)))))); + EnqueuePackets(ElementsAre( + AllOf(Pointee(Property(&RtpPacketToSend::padding_size, 0u)), + Pointee(Property(&RtpPacketToSend::Timestamp, start_timestamp)), + Pointee(Property(&RtpPacketToSend::capture_time, + Timestamp::Millis(start_time))))))); std::unique_ptr media_packet = SendPacket(start_time, /*payload_size=*/600); sequencer_->Sequence(*media_packet); @@ -546,8 +547,8 @@ TEST_F(RtpSenderTest, UpdatesTimestampsOnPlainRtxPadding) { Property(&RtpPacketToSend::padding_size, kMaxPaddingLength), Property(&RtpPacketToSend::Timestamp, start_timestamp + (kTimestampTicksPerMs * kTimeDiff.ms())), - Property(&RtpPacketToSend::capture_time_ms, - start_time + kTimeDiff.ms()))))); + Property(&RtpPacketToSend::capture_time, + Timestamp::Millis(start_time) + kTimeDiff))))); } TEST_F(RtpSenderTest, KeepsTimestampsOnPayloadPadding) { @@ -563,10 +564,11 @@ 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_ms, start_time)))))); + EnqueuePackets(ElementsAre( + AllOf(Pointee(Property(&RtpPacketToSend::padding_size, 0u)), + Pointee(Property(&RtpPacketToSend::Timestamp, start_timestamp)), + Pointee(Property(&RtpPacketToSend::capture_time, + Timestamp::Millis(start_time))))))); std::unique_ptr media_packet = SendPacket(start_time, kPayloadSize); packet_history_->PutRtpPacket(std::move(media_packet), start_time); @@ -576,14 +578,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_ms, 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, + Timestamp::Millis(start_time)))))); } // Test that the MID header extension is included on sent packets when @@ -1273,9 +1275,10 @@ TEST_F(RtpSenderTest, SetsCaptureTimeOnRtxRetransmissions) { // preserved. time_controller_.AdvanceTime(TimeDelta::Millis(10)); - EXPECT_CALL(mock_paced_sender_, - EnqueuePackets(ElementsAre(Pointee(Property( - &RtpPacketToSend::capture_time_ms, start_time_ms))))); + EXPECT_CALL( + mock_paced_sender_, + EnqueuePackets(ElementsAre(Pointee(Property( + &RtpPacketToSend::capture_time, Timestamp::Millis(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 da5dad5839..6d6ba33600 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_ms(capture_time_ms); + single_packet->set_capture_time(Timestamp::Millis(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_ms(clock_->TimeInMilliseconds()); + packet->set_packetization_finish_time(clock_->CurrentTime()); } packet->set_fec_protect_packet(use_fec);