Use Timestamp type in RtpState struct

Bug: webrtc:13757
Change-Id: I7f8fc1a9c4cbf464b3969c4754ce5aa9c5b5f076
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/303500
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39960}
This commit is contained in:
Danil Chapovalov 2023-04-26 10:46:10 +02:00 committed by WebRTC LUCI CQ
parent f78d1f211a
commit 9ecc76e15b
5 changed files with 31 additions and 44 deletions

View File

@ -387,9 +387,8 @@ TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) {
EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number);
EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp);
EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp);
EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms);
EXPECT_EQ(rtp_state1.last_timestamp_time_ms,
rtp_state2.last_timestamp_time_ms);
EXPECT_EQ(rtp_state1.capture_time, rtp_state2.capture_time);
EXPECT_EQ(rtp_state1.last_timestamp_time, rtp_state2.last_timestamp_time);
}
}

View File

@ -164,19 +164,12 @@ struct RTCPReportBlock {
typedef std::list<RTCPReportBlock> ReportBlockList;
struct RtpState {
RtpState()
: sequence_number(0),
start_timestamp(0),
timestamp(0),
capture_time_ms(-1),
last_timestamp_time_ms(-1),
ssrc_has_acked(false) {}
uint16_t sequence_number;
uint32_t start_timestamp;
uint32_t timestamp;
int64_t capture_time_ms;
int64_t last_timestamp_time_ms;
bool ssrc_has_acked;
uint16_t sequence_number = 0;
uint32_t start_timestamp = 0;
uint32_t timestamp = 0;
Timestamp capture_time = Timestamp::MinusInfinity();
Timestamp last_timestamp_time = Timestamp::MinusInfinity();
bool ssrc_has_acked = false;
};
class RtcpIntraFrameObserver {

View File

@ -35,8 +35,6 @@ PacketSequencer::PacketSequencer(uint32_t media_ssrc,
rtx_sequence_number_(0),
last_payload_type_(-1),
last_rtp_timestamp_(0),
last_capture_time_ms_(0),
last_timestamp_time_ms_(0),
last_packet_marker_bit_(false) {
Random random(clock_->TimeInMicroseconds());
// Random start, 16 bits. Upper half of range is avoided in order to prevent
@ -73,15 +71,15 @@ void PacketSequencer::Sequence(RtpPacketToSend& packet) {
void PacketSequencer::SetRtpState(const RtpState& state) {
media_sequence_number_ = state.sequence_number;
last_rtp_timestamp_ = state.timestamp;
last_capture_time_ms_ = state.capture_time_ms;
last_timestamp_time_ms_ = state.last_timestamp_time_ms;
last_capture_time_ = state.capture_time;
last_timestamp_time_ = state.last_timestamp_time;
}
void PacketSequencer::PopulateRtpState(RtpState& state) const {
state.sequence_number = media_sequence_number_;
state.timestamp = last_rtp_timestamp_;
state.capture_time_ms = last_capture_time_ms_;
state.last_timestamp_time_ms = last_timestamp_time_ms_;
state.capture_time = last_capture_time_;
state.last_timestamp_time = last_timestamp_time_;
}
void PacketSequencer::UpdateLastPacketState(const RtpPacketToSend& packet) {
@ -98,8 +96,8 @@ 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_timestamp_time_ = clock_->CurrentTime();
last_capture_time_ = packet.capture_time();
}
void PacketSequencer::PopulatePaddingFields(RtpPacketToSend& packet) {
@ -107,7 +105,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(last_capture_time_);
packet.SetPayloadType(last_payload_type_);
return;
}
@ -119,20 +117,17 @@ void PacketSequencer::PopulatePaddingFields(RtpPacketToSend& packet) {
}
packet.SetTimestamp(last_rtp_timestamp_);
packet.set_capture_time(Timestamp::Millis(last_capture_time_ms_));
packet.set_capture_time(last_capture_time_);
// Only change the timestamp of padding packets sent over RTX.
// Padding only packets over RTP has to be sent as part of a media
// frame (and therefore the same timestamp).
int64_t now_ms = clock_->TimeInMilliseconds();
if (last_timestamp_time_ms_ > 0) {
if (last_timestamp_time_ > Timestamp::Zero()) {
TimeDelta since_last_media = clock_->CurrentTime() - last_timestamp_time_;
packet.SetTimestamp(packet.Timestamp() +
(now_ms - last_timestamp_time_ms_) *
kTimestampTicksPerMs);
since_last_media.ms() * kTimestampTicksPerMs);
if (packet.capture_time() > Timestamp::Zero()) {
packet.set_capture_time(
packet.capture_time() +
TimeDelta::Millis(now_ms - last_timestamp_time_ms_));
packet.set_capture_time(packet.capture_time() + since_last_media);
}
}
}

View File

@ -67,8 +67,8 @@ class PacketSequencer {
int8_t last_payload_type_;
uint32_t last_rtp_timestamp_;
int64_t last_capture_time_ms_;
int64_t last_timestamp_time_ms_;
Timestamp last_capture_time_ = Timestamp::MinusInfinity();
Timestamp last_timestamp_time_ = Timestamp::MinusInfinity();
bool last_packet_marker_bit_;
};

View File

@ -1065,16 +1065,16 @@ TEST_F(RtpRtcpImpl2Test, RtpStateReflectsCurrentState) {
// Verify that that each of the field of GetRtpState actually reflects
// the current state.
// Current time will be used for `timestamp`, `capture_time_ms` and
// `last_timestamp_time_ms`.
const int64_t time_ms = time_controller_.GetClock()->TimeInMilliseconds();
// Current time will be used for `timestamp`, `capture_time` and
// `last_timestamp_time`.
const Timestamp time = time_controller_.GetClock()->CurrentTime();
// Use different than default sequence number to test `sequence_number`.
const uint16_t kSeq = kSequenceNumber + 123;
// Hard-coded value for `start_timestamp`.
const uint32_t kStartTimestamp = 3456;
const int64_t capture_time_ms = time_ms;
const uint32_t timestamp = capture_time_ms * kCaptureTimeMsToRtpTimestamp;
const Timestamp capture_time = time;
const uint32_t timestamp = capture_time.ms() * kCaptureTimeMsToRtpTimestamp;
sender_.impl_->SetSequenceNumber(kSeq - 1);
sender_.impl_->SetStartTimestamp(kStartTimestamp);
@ -1090,8 +1090,8 @@ TEST_F(RtpRtcpImpl2Test, RtpStateReflectsCurrentState) {
EXPECT_EQ(state.sequence_number, kSeq);
EXPECT_EQ(state.start_timestamp, kStartTimestamp);
EXPECT_EQ(state.timestamp, timestamp);
EXPECT_EQ(state.capture_time_ms, capture_time_ms);
EXPECT_EQ(state.last_timestamp_time_ms, time_ms);
EXPECT_EQ(state.capture_time, capture_time);
EXPECT_EQ(state.last_timestamp_time, time);
EXPECT_EQ(state.ssrc_has_acked, true);
// Reset sender, advance time, restore state. Directly observing state
@ -1104,8 +1104,8 @@ TEST_F(RtpRtcpImpl2Test, RtpStateReflectsCurrentState) {
EXPECT_EQ(state.sequence_number, kSeq);
EXPECT_EQ(state.start_timestamp, kStartTimestamp);
EXPECT_EQ(state.timestamp, timestamp);
EXPECT_EQ(state.capture_time_ms, capture_time_ms);
EXPECT_EQ(state.last_timestamp_time_ms, time_ms);
EXPECT_EQ(state.capture_time, capture_time);
EXPECT_EQ(state.last_timestamp_time, time);
EXPECT_EQ(state.ssrc_has_acked, true);
}