Use Timestamp to represent packet receive timestamps
Before this CL, timestamps of received packets were rounded
to the nearest millisecond and stored as int64_t. Due to the
rounding it sometimes happened that timestamps later in the
pipeline that are not rounded seem to occur even before the
video frame was received.
Change-Id: I92d8f3540b23baae2d4a1dc6a7cb3f58bcdaad18
Bug: webrtc:12722
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/216398
Reviewed-by: Chen Xing <chxg@google.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33916}
diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn
index 94312bf..b28517e 100644
--- a/modules/video_coding/BUILD.gn
+++ b/modules/video_coding/BUILD.gn
@@ -274,6 +274,7 @@
"../../api:rtp_headers",
"../../api:rtp_packet_info",
"../../api:sequence_checker",
+ "../../api/units:timestamp",
"../../api/video:encoded_image",
"../../api/video:video_frame",
"../../api/video:video_frame_type",
diff --git a/modules/video_coding/jitter_buffer_unittest.cc b/modules/video_coding/jitter_buffer_unittest.cc
index acfee8c..752ceb8 100644
--- a/modules/video_coding/jitter_buffer_unittest.cc
+++ b/modules/video_coding/jitter_buffer_unittest.cc
@@ -67,8 +67,7 @@
video_header.is_first_packet_in_frame = true;
video_header.frame_type = VideoFrameType::kVideoFrameDelta;
packet_.reset(new VCMPacket(data_, size_, rtp_header, video_header,
- /*ntp_time_ms=*/0,
- clock_->TimeInMilliseconds()));
+ /*ntp_time_ms=*/0, clock_->CurrentTime()));
}
VCMEncodedFrame* DecodeCompleteFrame() {
@@ -541,7 +540,7 @@
video_header.codec = kVideoCodecGeneric;
video_header.frame_type = VideoFrameType::kEmptyFrame;
VCMPacket empty_packet(data_, 0, rtp_header, video_header,
- /*ntp_time_ms=*/0, clock_->TimeInMilliseconds());
+ /*ntp_time_ms=*/0, clock_->CurrentTime());
EXPECT_EQ(kOldPacket,
jitter_buffer_->InsertPacket(empty_packet, &retransmitted));
empty_packet.seqNum += 1;
diff --git a/modules/video_coding/packet.cc b/modules/video_coding/packet.cc
index 0c4a658..324248a 100644
--- a/modules/video_coding/packet.cc
+++ b/modules/video_coding/packet.cc
@@ -34,7 +34,7 @@
const RTPHeader& rtp_header,
const RTPVideoHeader& videoHeader,
int64_t ntp_time_ms,
- int64_t receive_time_ms)
+ Timestamp receive_time)
: payloadType(rtp_header.payloadType),
timestamp(rtp_header.timestamp),
ntp_time_ms_(ntp_time_ms),
@@ -47,7 +47,7 @@
insertStartCode(videoHeader.codec == kVideoCodecH264 &&
videoHeader.is_first_packet_in_frame),
video_header(videoHeader),
- packet_info(rtp_header, receive_time_ms) {
+ packet_info(rtp_header, receive_time) {
if (is_first_packet_in_frame() && markerBit) {
completeNALU = kNaluComplete;
} else if (is_first_packet_in_frame()) {
diff --git a/modules/video_coding/packet.h b/modules/video_coding/packet.h
index f157e10..9aa2d5c 100644
--- a/modules/video_coding/packet.h
+++ b/modules/video_coding/packet.h
@@ -17,6 +17,7 @@
#include "absl/types/optional.h"
#include "api/rtp_headers.h"
#include "api/rtp_packet_info.h"
+#include "api/units/timestamp.h"
#include "api/video/video_frame_type.h"
#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
#include "modules/rtp_rtcp/source/rtp_video_header.h"
@@ -41,7 +42,7 @@
const RTPHeader& rtp_header,
const RTPVideoHeader& video_header,
int64_t ntp_time_ms,
- int64_t receive_time_ms);
+ Timestamp receive_time);
~VCMPacket();
diff --git a/modules/video_coding/packet_buffer.cc b/modules/video_coding/packet_buffer.cc
index 1291f78..99f2891 100644
--- a/modules/video_coding/packet_buffer.cc
+++ b/modules/video_coding/packet_buffer.cc
@@ -36,7 +36,7 @@
PacketBuffer::Packet::Packet(const RtpPacketReceived& rtp_packet,
const RTPVideoHeader& video_header,
- int64_t receive_time_ms)
+ Timestamp receive_time)
: marker_bit(rtp_packet.Marker()),
payload_type(rtp_packet.PayloadType()),
seq_num(rtp_packet.SequenceNumber()),
@@ -48,7 +48,7 @@
rtp_packet.Timestamp(),
/*audio_level=*/absl::nullopt,
rtp_packet.GetExtension<AbsoluteCaptureTimeExtension>(),
- receive_time_ms) {}
+ receive_time) {}
PacketBuffer::PacketBuffer(size_t start_buffer_size, size_t max_buffer_size)
: max_size_(max_buffer_size),
diff --git a/modules/video_coding/packet_buffer.h b/modules/video_coding/packet_buffer.h
index c0cc752..e8d2446 100644
--- a/modules/video_coding/packet_buffer.h
+++ b/modules/video_coding/packet_buffer.h
@@ -18,6 +18,7 @@
#include "absl/base/attributes.h"
#include "api/rtp_packet_info.h"
+#include "api/units/timestamp.h"
#include "api/video/encoded_image.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "modules/rtp_rtcp/source/rtp_video_header.h"
@@ -34,7 +35,7 @@
Packet() = default;
Packet(const RtpPacketReceived& rtp_packet,
const RTPVideoHeader& video_header,
- int64_t receive_time_ms);
+ Timestamp receive_time);
Packet(const Packet&) = delete;
Packet(Packet&&) = delete;
Packet& operator=(const Packet&) = delete;
diff --git a/modules/video_coding/video_receiver.cc b/modules/video_coding/video_receiver.cc
index 74b04ac..43dbc9f 100644
--- a/modules/video_coding/video_receiver.cc
+++ b/modules/video_coding/video_receiver.cc
@@ -279,7 +279,7 @@
// Callers don't provide any ntp time.
const VCMPacket packet(incomingPayload, payloadLength, rtp_header,
video_header, /*ntp_time_ms=*/0,
- clock_->TimeInMilliseconds());
+ clock_->CurrentTime());
int32_t ret = _receiver.InsertPacket(packet);
// TODO(holmer): Investigate if this somehow should use the key frame