Index: content/renderer/media/webrtc/media_stream_remote_video_source.cc |
diff --git a/content/renderer/media/webrtc/media_stream_remote_video_source.cc b/content/renderer/media/webrtc/media_stream_remote_video_source.cc |
index e81b37701de15df10019bdf517c105cdc50cffef..e325f797f6dee470e8e9c5c5b84e194b5d43716d 100644 |
--- a/content/renderer/media/webrtc/media_stream_remote_video_source.cc |
+++ b/content/renderer/media/webrtc/media_stream_remote_video_source.cc |
@@ -14,6 +14,7 @@ |
#include "media/base/video_frame.h" |
#include "media/base/video_util.h" |
#include "third_party/libjingle/source/talk/media/base/videoframe.h" |
+#include "third_party/webrtc/system_wrappers/interface/tick_util.h" |
namespace content { |
@@ -47,6 +48,9 @@ class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate |
// |frame_callback_| is accessed on the IO thread. |
VideoCaptureDeliverFrameCB frame_callback_; |
+ |
+ // WebRTC Chromium timestamp diff |
+ int64_t time_diff_us_; |
}; |
MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate:: |
@@ -54,6 +58,12 @@ MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate:: |
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
const VideoCaptureDeliverFrameCB& new_frame_callback) |
: io_task_runner_(io_task_runner), frame_callback_(new_frame_callback) { |
+ // TODO(qiangchen): There can be two differences between clocks: 1) |
+ // the offset, 2) the rate (i.e., one clock runs faster than the other). |
+ // See http://crbug/516700 |
+ time_diff_us_ = |
+ (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - |
+ webrtc::TickTime::MicrosecondTimestamp(); |
} |
MediaStreamRemoteVideoSource:: |
@@ -62,7 +72,14 @@ RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { |
void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::RenderFrame( |
const cricket::VideoFrame* incoming_frame) { |
- TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::RenderFrame"); |
+ base::TimeTicks render_time = |
+ base::TimeTicks() + |
+ base::TimeDelta::FromMicroseconds(incoming_frame->GetTimeStamp() / 1000 + |
+ time_diff_us_); |
+ |
+ TRACE_EVENT1("webrtc", "RemoteVideoSourceDelegate::RenderFrame", |
+ "Ideal Render Instant", render_time.ToInternalValue()); |
+ |
base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( |
incoming_frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); |
@@ -96,6 +113,9 @@ void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::RenderFrame( |
base::Bind(&base::DeletePointer<cricket::VideoFrame>, frame->Copy())); |
} |
+ video_frame->metadata()->SetTimeTicks( |
+ media::VideoFrameMetadata::REFERENCE_TIME, render_time); |
+ |
io_task_runner_->PostTask( |
FROM_HERE, base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread, |
this, video_frame)); |