Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: content/renderer/media/video_capture_impl.cc

Issue 2045813003: Decouple capture timestamp and reference time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/video_capture_impl.cc
diff --git a/content/renderer/media/video_capture_impl.cc b/content/renderer/media/video_capture_impl.cc
index 90026160a5e3b6aa5e8d3ba9180459836e2615d4..1ccd6c63fce441a6407db674e1a7754a12014ffb 100644
--- a/content/renderer/media/video_capture_impl.cc
+++ b/content/renderer/media/video_capture_impl.cc
@@ -191,7 +191,6 @@ void VideoCaptureImpl::StartCapture(
}
DVLOG(1) << "StartCapture: starting with first resolution "
<< params_.requested_format.frame_size.ToString();
- first_frame_timestamp_ = base::TimeTicks();
StartCaptureInternal();
}
}
@@ -304,7 +303,7 @@ void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) {
void VideoCaptureImpl::OnBufferReceived(
int buffer_id,
- base::TimeTicks timestamp,
+ base::TimeDelta timestamp,
const base::DictionaryValue& metadata,
media::VideoPixelFormat pixel_format,
media::VideoFrame::StorageType storage_type,
@@ -324,14 +323,31 @@ void VideoCaptureImpl::OnBufferReceived(
gpu::SyncToken(), -1.0));
return;
}
- if (first_frame_timestamp_.is_null())
- first_frame_timestamp_ = timestamp;
+ base::TimeTicks reference_time;
+ media::VideoFrameMetadata frame_metadata;
+ frame_metadata.MergeInternalValuesFrom(metadata);
+ const bool success = frame_metadata.GetTimeTicks(
+ media::VideoFrameMetadata::REFERENCE_TIME, &reference_time);
+ DCHECK(success);
+
+ if (first_frame_ref_time_.is_null())
+ first_frame_ref_time_ = reference_time;
+
+ // If the timestamp is not prepared, we use reference time to make a rough
+ // estimate. e.g. ThreadSafeCaptureOracle::DidCaptureFrame().
+ // TODO(miu): Fix upstream capturers to always set timestamp and reference
+ // time. See http://crbug/618407/ for tracking.
+ if (timestamp.is_zero())
+ timestamp = reference_time - first_frame_ref_time_;
+
+ // TODO(qiangchen): Change the metric name to "reference_time" and
+ // "timestamp", so that we have consistent naming everywhere.
// Used by chrome/browser/extension/api/cast_streaming/performance_test.cc
TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived",
TRACE_EVENT_SCOPE_THREAD, "timestamp",
- timestamp.ToInternalValue(), "time_delta",
- (timestamp - first_frame_timestamp_).ToInternalValue());
+ (reference_time - base::TimeTicks()).InMicroseconds(),
+ "time_delta", timestamp.InMicroseconds());
scoped_refptr<media::VideoFrame> frame;
BufferFinishedCallback buffer_finished_callback;
@@ -343,11 +359,8 @@ void VideoCaptureImpl::OnBufferReceived(
scoped_refptr<ClientBuffer2> buffer = iter->second;
const auto& handles = buffer->gpu_memory_buffer_handles();
frame = media::VideoFrame::WrapExternalYuvGpuMemoryBuffers(
- media::PIXEL_FORMAT_I420,
- coded_size,
- gfx::Rect(coded_size),
- coded_size,
- buffer->stride(media::VideoFrame::kYPlane),
+ media::PIXEL_FORMAT_I420, coded_size, gfx::Rect(coded_size),
+ coded_size, buffer->stride(media::VideoFrame::kYPlane),
buffer->stride(media::VideoFrame::kUPlane),
buffer->stride(media::VideoFrame::kVPlane),
buffer->data(media::VideoFrame::kYPlane),
@@ -355,8 +368,7 @@ void VideoCaptureImpl::OnBufferReceived(
buffer->data(media::VideoFrame::kVPlane),
handles[media::VideoFrame::kYPlane],
handles[media::VideoFrame::kUPlane],
- handles[media::VideoFrame::kVPlane],
- timestamp - first_frame_timestamp_);
+ handles[media::VideoFrame::kVPlane], timestamp);
buffer_finished_callback = media::BindToCurrentLoop(
base::Bind(&VideoCaptureImpl::OnClientBufferFinished2,
weak_factory_.GetWeakPtr(), buffer_id, buffer));
@@ -371,7 +383,7 @@ void VideoCaptureImpl::OnBufferReceived(
gfx::Size(visible_rect.width(), visible_rect.height()),
reinterpret_cast<uint8_t*>(buffer->buffer()->memory()),
buffer->buffer_size(), buffer->buffer()->handle(),
- 0 /* shared_memory_offset */, timestamp - first_frame_timestamp_);
+ 0 /* shared_memory_offset */, timestamp);
buffer_finished_callback = media::BindToCurrentLoop(
base::Bind(&VideoCaptureImpl::OnClientBufferFinished,
weak_factory_.GetWeakPtr(), buffer_id, buffer));
@@ -387,16 +399,16 @@ void VideoCaptureImpl::OnBufferReceived(
return;
}
- frame->metadata()->SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME,
- timestamp);
frame->AddDestructionObserver(
base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(),
base::Passed(&release_sync_token), buffer_finished_callback));
frame->metadata()->MergeInternalValuesFrom(metadata);
+ // TODO(qiangchen): Dive into the full code path to let frame metadata hold
+ // reference time rather than using an extra parameter.
for (const auto& client : clients_)
- client.second.deliver_frame_cb.Run(frame, timestamp);
+ client.second.deliver_frame_cb.Run(frame, reference_time);
}
void VideoCaptureImpl::OnClientBufferFinished(
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698