Adds reference time to webrt::VideoFrame

The new reference time contains a monotonically increasing clock time and represents the time when the frame was captured. Not all platforms provide the "true" sample capture time in |reference_time| but might instead use a somewhat delayed (by the time it took to capture the frame) version of it.

Bug: webrtc:15539
Change-Id: I95eff8b0f7bff8d3ae65798bf82046e1ac2b0cf2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/325261
Reviewed-by: Markus Handell <handellm@webrtc.org>
Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Markus Handell <handellm@google.com>
Cr-Commit-Position: refs/heads/main@{#41036}
This commit is contained in:
henrika 2023-10-30 11:33:23 +01:00 committed by WebRTC LUCI CQ
parent 2ea77ca557
commit 7b6f996318
2 changed files with 27 additions and 3 deletions

View File

@ -164,9 +164,9 @@ VideoFrame::Builder::~Builder() = default;
VideoFrame VideoFrame::Builder::build() {
RTC_CHECK(video_frame_buffer_ != nullptr);
return VideoFrame(id_, video_frame_buffer_, timestamp_us_,
capture_time_identifier_, timestamp_rtp_, ntp_time_ms_,
rotation_, color_space_, render_parameters_, update_rect_,
packet_infos_);
capture_time_identifier_, reference_time_, timestamp_rtp_,
ntp_time_ms_, rotation_, color_space_, render_parameters_,
update_rect_, packet_infos_);
}
VideoFrame::Builder& VideoFrame::Builder::set_video_frame_buffer(
@ -193,6 +193,12 @@ VideoFrame::Builder& VideoFrame::Builder::set_capture_time_identifier(
return *this;
}
VideoFrame::Builder& VideoFrame::Builder::set_reference_time(
const absl::optional<Timestamp>& reference_time) {
reference_time_ = reference_time;
return *this;
}
VideoFrame::Builder& VideoFrame::Builder::set_timestamp_rtp(
uint32_t timestamp_rtp) {
timestamp_rtp_ = timestamp_rtp;
@ -264,6 +270,7 @@ VideoFrame::VideoFrame(uint16_t id,
const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
int64_t timestamp_us,
const absl::optional<Timestamp>& capture_time_identifier,
const absl::optional<Timestamp>& reference_time,
uint32_t timestamp_rtp,
int64_t ntp_time_ms,
VideoRotation rotation,
@ -277,6 +284,7 @@ VideoFrame::VideoFrame(uint16_t id,
ntp_time_ms_(ntp_time_ms),
timestamp_us_(timestamp_us),
capture_time_identifier_(capture_time_identifier),
reference_time_(reference_time),
rotation_(rotation),
color_space_(color_space),
render_parameters_(render_parameters),

View File

@ -109,6 +109,8 @@ class RTC_EXPORT VideoFrame {
Builder& set_timestamp_us(int64_t timestamp_us);
Builder& set_capture_time_identifier(
const absl::optional<Timestamp>& capture_time_identifier);
Builder& set_reference_time(
const absl::optional<Timestamp>& reference_time);
Builder& set_timestamp_rtp(uint32_t timestamp_rtp);
Builder& set_ntp_time_ms(int64_t ntp_time_ms);
Builder& set_rotation(VideoRotation rotation);
@ -123,6 +125,7 @@ class RTC_EXPORT VideoFrame {
rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_;
int64_t timestamp_us_ = 0;
absl::optional<Timestamp> capture_time_identifier_;
absl::optional<Timestamp> reference_time_;
uint32_t timestamp_rtp_ = 0;
int64_t ntp_time_ms_ = 0;
VideoRotation rotation_ = kVideoRotation_0;
@ -177,6 +180,13 @@ class RTC_EXPORT VideoFrame {
capture_time_identifier_ = capture_time_identifier;
}
const absl::optional<Timestamp>& reference_time() const {
return reference_time_;
}
void set_reference_time(const absl::optional<Timestamp>& reference_time) {
reference_time_ = reference_time;
}
// Set frame timestamp (90kHz).
void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; }
@ -274,6 +284,7 @@ class RTC_EXPORT VideoFrame {
const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
int64_t timestamp_us,
const absl::optional<Timestamp>& capture_time_identifier,
const absl::optional<Timestamp>& reference_time,
uint32_t timestamp_rtp,
int64_t ntp_time_ms,
VideoRotation rotation,
@ -289,6 +300,11 @@ class RTC_EXPORT VideoFrame {
int64_t ntp_time_ms_;
int64_t timestamp_us_;
absl::optional<Timestamp> capture_time_identifier_;
// Contains a monotonically increasing clock time and represents the time
// when the frame was captured. Not all platforms provide the "true" sample
// capture time in |reference_time| but might instead use a somewhat delayed
// (by the time it took to capture the frame) version of it.
absl::optional<Timestamp> reference_time_;
VideoRotation rotation_;
absl::optional<ColorSpace> color_space_;
// Contains parameters that affect have the frame should be rendered.