Commit eb931527 authored by Johannes Kron's avatar Johannes Kron Committed by Commit Bot

[video-raf] Fix capture time for remote video sources

Set capture time to the NTP timestamp of the video frame
for remote video sources. Compensate for NTP offset.

Bug: 1011581
Change-Id: I75916d53503141bab7fd88cebe52c4aee83652fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095007Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Johannes Kron <kron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749133}
parent 4cd6d5de
......@@ -25,7 +25,8 @@
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
#include "third_party/webrtc/api/video/i420_buffer.h"
#include "third_party/webrtc/api/video/recordable_encoded_frame.h"
#include "third_party/webrtc/rtc_base/time_utils.h" // for TimeMicros
#include "third_party/webrtc/rtc_base/time_utils.h"
#include "third_party/webrtc/system_wrappers/include/clock.h"
namespace WTF {
......@@ -145,6 +146,12 @@ class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate
// WebRTC Chromium timestamp diff
const base::TimeDelta time_diff_encoded_;
// WebRTC real time clock, needed to determine NTP offset.
webrtc::Clock* clock_;
// Offset between NTP clock and WebRTC clock.
const int64_t ntp_offset_;
};
MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
......@@ -163,11 +170,13 @@ MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
base::TimeDelta::FromMicroseconds(rtc::TimeMicros())),
start_timestamp_encoded_(media::kNoTimestamp),
time_diff_encoded_(base::TimeTicks::Now() - base::TimeTicks() -
base::TimeDelta::FromMicroseconds(rtc::TimeMicros())) {
}
base::TimeDelta::FromMicroseconds(rtc::TimeMicros())),
clock_(webrtc::Clock::GetRealTimeClock()),
ntp_offset_(clock_->TimeInMilliseconds() -
clock_->CurrentNtpInMilliseconds()) {}
MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
~RemoteVideoSourceDelegate() {}
~RemoteVideoSourceDelegate() = default;
void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::OnFrame(
const webrtc::VideoFrame& incoming_frame) {
......@@ -301,10 +310,11 @@ void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::OnFrame(
// Set capture time to the NTP time, which is the estimated capture time
// converted to the local clock.
if (incoming_frame.ntp_time_ms() != 0) {
if (incoming_frame.ntp_time_ms() > 0) {
const base::TimeTicks capture_time =
base::TimeTicks() +
base::TimeDelta::FromMilliseconds(incoming_frame.ntp_time_ms()) +
base::TimeDelta::FromMilliseconds(incoming_frame.ntp_time_ms() +
ntp_offset_) +
time_diff_;
video_frame->metadata()->SetTimeTicks(
media::VideoFrameMetadata::CAPTURE_BEGIN_TIME, capture_time);
......
......@@ -28,6 +28,7 @@
#include "third_party/webrtc/api/rtp_packet_infos.h"
#include "third_party/webrtc/api/video/color_space.h"
#include "third_party/webrtc/api/video/i420_buffer.h"
#include "third_party/webrtc/system_wrappers/include/clock.h"
#include "ui/gfx/color_space.h"
namespace blink {
......@@ -327,6 +328,11 @@ TEST_F(MediaStreamRemoteVideoSourceTest,
kProcessingFinish - webrtc::TimeDelta::Millis(1.0e3 * kProcessingTime);
const webrtc::Timestamp kCaptureTime =
kProcessingStart - webrtc::TimeDelta::Millis(20.0);
webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock();
const int64_t ntp_offset =
clock->CurrentNtpInMilliseconds() - clock->TimeInMilliseconds();
const webrtc::Timestamp kCaptureTimeNtp =
kCaptureTime + webrtc::TimeDelta::Millis(ntp_offset);
// Expected capture time in Chromium epoch.
base::TimeTicks kExpectedCaptureTime =
base::TimeTicks() + base::TimeDelta::FromMilliseconds(kCaptureTime.ms()) +
......@@ -348,7 +354,7 @@ TEST_F(MediaStreamRemoteVideoSourceTest,
webrtc::VideoFrame::Builder()
.set_video_frame_buffer(buffer)
.set_timestamp_rtp(kRtpTimestamp)
.set_ntp_time_ms(kCaptureTime.ms())
.set_ntp_time_ms(kCaptureTimeNtp.ms())
.set_packet_infos(webrtc::RtpPacketInfos(packet_infos))
.build();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment