diff options
author | sheu@chromium.org <sheu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-08 06:15:43 +0000 |
---|---|---|
committer | sheu@chromium.org <sheu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-08 06:15:43 +0000 |
commit | ee74aa5e23bddc14fa5c8b00036acf897f2b3861 (patch) | |
tree | b6d03d25367dd04d4b0b6069df19a6121a3f4fbb | |
parent | f19a42a5b8158e5d3c4910227552b3d43e164b62 (diff) | |
download | chromium_src-ee74aa5e23bddc14fa5c8b00036acf897f2b3861.zip chromium_src-ee74aa5e23bddc14fa5c8b00036acf897f2b3861.tar.gz chromium_src-ee74aa5e23bddc14fa5c8b00036acf897f2b3861.tar.bz2 |
Convert video capture pipline to base::TimeTicks
base::TimeTicks is a monotonic clock, unlike base::Time, which may change if
the system time is changed. Switch over the video capture pipeline to use this
clock.
BUG=249215
TEST=local build, run on CrOS snow, desktop Linux
Review URL: https://codereview.chromium.org/101843005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243493 0039d316-1c4b-4281-b951-d872f2087c98
41 files changed, 184 insertions, 169 deletions
diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc index 67edcda..9e5861e 100644 --- a/content/browser/gpu/gpu_process_host.cc +++ b/content/browser/gpu/gpu_process_host.cc @@ -981,7 +981,7 @@ void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( FrameSubscriberMap::iterator it = frame_subscribers_.find(params.surface_id); if (it != frame_subscribers_.end() && it->second) { - const base::Time present_time = base::Time::Now(); + const base::TimeTicks present_time = base::TimeTicks::Now(); scoped_refptr<media::VideoFrame> target_frame; RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback copy_callback; if (it->second->ShouldCaptureFrame(present_time, diff --git a/content/browser/renderer_host/compositing_iosurface_mac.mm b/content/browser/renderer_host/compositing_iosurface_mac.mm index b5759ed..606ffe5 100644 --- a/content/browser/renderer_host/compositing_iosurface_mac.mm +++ b/content/browser/renderer_host/compositing_iosurface_mac.mm @@ -469,7 +469,7 @@ bool CompositingIOSurfaceMac::DrawIOSurface( base::Closure copy_done_callback; if (frame_subscriber) { - const base::Time present_time = base::Time::Now(); + const base::TimeTicks present_time = base::TimeTicks::Now(); scoped_refptr<media::VideoFrame> frame; RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; if (frame_subscriber->ShouldCaptureFrame(present_time, &frame, &callback)) { diff --git a/content/browser/renderer_host/media/desktop_capture_device.cc b/content/browser/renderer_host/media/desktop_capture_device.cc index e82b96f..6d655b9 100644 --- a/content/browser/renderer_host/media/desktop_capture_device.cc +++ b/content/browser/renderer_host/media/desktop_capture_device.cc @@ -231,8 +231,8 @@ void DesktopCaptureDevice::Core::OnCaptureCompleted( output_data = output_frame_->data(); } - client_->OnIncomingCapturedFrame(output_data, output_bytes, base::Time::Now(), - 0, capture_format_); + client_->OnIncomingCapturedFrame( + output_data, output_bytes, base::TimeTicks::Now(), 0, capture_format_); } void DesktopCaptureDevice::Core::DoAllocateAndStart( diff --git a/content/browser/renderer_host/media/desktop_capture_device_aura.cc b/content/browser/renderer_host/media/desktop_capture_device_aura.cc index 15e86f0..3783a2a 100644 --- a/content/browser/renderer_host/media/desktop_capture_device_aura.cc +++ b/content/browser/renderer_host/media/desktop_capture_device_aura.cc @@ -128,7 +128,7 @@ class DesktopVideoCaptureMachine // Response callback for cc::Layer::RequestCopyOfOutput(). void DidCopyOutput( scoped_refptr<media::VideoFrame> video_frame, - base::Time start_time, + base::TimeTicks start_time, const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, scoped_ptr<cc::CopyOutputResult> result); @@ -255,7 +255,7 @@ void DesktopVideoCaptureMachine::Capture(bool dirty) { scoped_refptr<media::VideoFrame> frame; ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; - const base::Time start_time = base::Time::Now(); + const base::TimeTicks start_time = base::TimeTicks::Now(); const VideoCaptureOracle::Event event = dirty ? VideoCaptureOracle::kCompositorUpdate : VideoCaptureOracle::kTimerPoll; @@ -275,7 +275,7 @@ void DesktopVideoCaptureMachine::Capture(bool dirty) { } void CopyOutputFinishedForVideo( - base::Time start_time, + base::TimeTicks start_time, const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, const scoped_refptr<media::VideoFrame>& target, const SkBitmap& cursor_bitmap, @@ -290,7 +290,7 @@ void CopyOutputFinishedForVideo( void DesktopVideoCaptureMachine::DidCopyOutput( scoped_refptr<media::VideoFrame> video_frame, - base::Time start_time, + base::TimeTicks start_time, const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, scoped_ptr<cc::CopyOutputResult> result) { if (result->IsEmpty() || result->size().IsEmpty() || !desktop_layer_) diff --git a/content/browser/renderer_host/media/desktop_capture_device_aura_unittest.cc b/content/browser/renderer_host/media/desktop_capture_device_aura_unittest.cc index 8ad1495..d581817 100644 --- a/content/browser/renderer_host/media/desktop_capture_device_aura_unittest.cc +++ b/content/browser/renderer_host/media/desktop_capture_device_aura_unittest.cc @@ -36,14 +36,14 @@ class MockDeviceClient : public media::VideoCaptureDevice::Client { MOCK_METHOD5(OnIncomingCapturedFrame, void(const uint8* data, int length, - base::Time timestamp, + base::TimeTicks timestamp, int rotation, const media::VideoCaptureFormat& frame_format)); MOCK_METHOD5(OnIncomingCapturedBuffer, void(const scoped_refptr<Buffer>& buffer, media::VideoFrame::Format format, const gfx::Size& dimensions, - base::Time timestamp, + base::TimeTicks timestamp, int frame_rate)); }; diff --git a/content/browser/renderer_host/media/desktop_capture_device_unittest.cc b/content/browser/renderer_host/media/desktop_capture_device_unittest.cc index 03dbd53..9ae5469 100644 --- a/content/browser/renderer_host/media/desktop_capture_device_unittest.cc +++ b/content/browser/renderer_host/media/desktop_capture_device_unittest.cc @@ -47,14 +47,14 @@ class MockDeviceClient : public media::VideoCaptureDevice::Client { MOCK_METHOD5(OnIncomingCapturedFrame, void(const uint8* data, int length, - base::Time timestamp, + base::TimeTicks timestamp, int rotation, const media::VideoCaptureFormat& frame_format)); MOCK_METHOD5(OnIncomingCapturedBuffer, void(const scoped_refptr<Buffer>& buffer, media::VideoFrame::Format format, const gfx::Size& dimensions, - base::Time timestamp, + base::TimeTicks timestamp, int frame_rate)); }; diff --git a/content/browser/renderer_host/media/video_capture_controller.cc b/content/browser/renderer_host/media/video_capture_controller.cc index 88fd72a..f23f50f 100644 --- a/content/browser/renderer_host/media/video_capture_controller.cc +++ b/content/browser/renderer_host/media/video_capture_controller.cc @@ -112,14 +112,14 @@ class VideoCaptureController::VideoCaptureDeviceClient const gfx::Size& size) OVERRIDE; virtual void OnIncomingCapturedFrame(const uint8* data, int length, - base::Time timestamp, + base::TimeTicks timestamp, int rotation, const VideoCaptureFormat& frame_format) OVERRIDE; virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, media::VideoFrame::Format format, const gfx::Size& dimensions, - base::Time timestamp, + base::TimeTicks timestamp, int frame_rate) OVERRIDE; virtual void OnError() OVERRIDE; @@ -267,7 +267,7 @@ VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( void VideoCaptureController::VideoCaptureDeviceClient::OnIncomingCapturedFrame( const uint8* data, int length, - base::Time timestamp, + base::TimeTicks timestamp, int rotation, const VideoCaptureFormat& frame_format) { TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedFrame"); @@ -410,7 +410,7 @@ void VideoCaptureController::VideoCaptureDeviceClient::OnIncomingCapturedBuffer( const scoped_refptr<Buffer>& buffer, media::VideoFrame::Format format, const gfx::Size& dimensions, - base::Time timestamp, + base::TimeTicks timestamp, int frame_rate) { // The capture pipeline expects I420 for now. DCHECK_EQ(format, media::VideoFrame::I420) @@ -476,7 +476,7 @@ void VideoCaptureController::DoIncomingCapturedI420BufferOnIOThread( scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer, const gfx::Size& dimensions, int frame_rate, - base::Time timestamp) { + base::TimeTicks timestamp) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK_NE(buffer->id(), VideoCaptureBufferPool::kInvalidId); diff --git a/content/browser/renderer_host/media/video_capture_controller.h b/content/browser/renderer_host/media/video_capture_controller.h index 8658cde..9eed94d 100644 --- a/content/browser/renderer_host/media/video_capture_controller.h +++ b/content/browser/renderer_host/media/video_capture_controller.h @@ -117,7 +117,7 @@ class CONTENT_EXPORT VideoCaptureController { scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer, const gfx::Size& dimensions, int frame_rate, - base::Time timestamp); + base::TimeTicks timestamp); void DoErrorOnIOThread(); void DoDeviceStoppedOnIOThread(); void DoBufferDestroyedOnIOThread(int buffer_id_to_drop); diff --git a/content/browser/renderer_host/media/video_capture_controller_event_handler.h b/content/browser/renderer_host/media/video_capture_controller_event_handler.h index 6559a53..7eecc09 100644 --- a/content/browser/renderer_host/media/video_capture_controller_event_handler.h +++ b/content/browser/renderer_host/media/video_capture_controller_event_handler.h @@ -41,11 +41,10 @@ class CONTENT_EXPORT VideoCaptureControllerEventHandler { int buffer_id) = 0; // A buffer has been filled with I420 video. - virtual void OnBufferReady( - const VideoCaptureControllerID& id, - int buffer_id, - base::Time timestamp, - const media::VideoCaptureFormat& format) = 0; + virtual void OnBufferReady(const VideoCaptureControllerID& id, + int buffer_id, + base::TimeTicks timestamp, + const media::VideoCaptureFormat& format) = 0; // The capture session has ended and no more frames will be sent. virtual void OnEnded(const VideoCaptureControllerID& id) = 0; diff --git a/content/browser/renderer_host/media/video_capture_controller_unittest.cc b/content/browser/renderer_host/media/video_capture_controller_unittest.cc index 20cc4e4..1852a71 100644 --- a/content/browser/renderer_host/media/video_capture_controller_unittest.cc +++ b/content/browser/renderer_host/media/video_capture_controller_unittest.cc @@ -59,7 +59,7 @@ class MockVideoCaptureControllerEventHandler } virtual void OnBufferReady(const VideoCaptureControllerID& id, int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format) OVERRIDE { DoBufferReady(id); base::MessageLoop::current()->PostTask(FROM_HERE, @@ -279,7 +279,7 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { device_->OnIncomingCapturedBuffer(buffer, media::VideoFrame::I420, capture_resolution, - base::Time(), + base::TimeTicks(), device_format.frame_rate); buffer = NULL; @@ -297,7 +297,7 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { device_->OnIncomingCapturedBuffer(buffer, media::VideoFrame::I420, capture_resolution, - base::Time(), + base::TimeTicks(), device_format.frame_rate); buffer = NULL; @@ -326,7 +326,7 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { device_->OnIncomingCapturedBuffer(buffer, media::VideoFrame::I420, capture_resolution, - base::Time(), + base::TimeTicks(), device_format.frame_rate); buffer = NULL; } @@ -364,7 +364,7 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { device_->OnIncomingCapturedBuffer(buffer, media::VideoFrame::I420, capture_resolution, - base::Time(), + base::TimeTicks(), device_format.frame_rate); buffer = NULL; buffer = @@ -380,7 +380,7 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { device_->OnIncomingCapturedBuffer(buffer, media::VideoFrame::I420, capture_resolution, - base::Time(), + base::TimeTicks(), device_format.frame_rate); buffer = NULL; // B2 is the only client left, and is the only one that should @@ -424,8 +424,11 @@ TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); ASSERT_TRUE(buffer); - device_->OnIncomingCapturedBuffer( - buffer, media::VideoFrame::I420, capture_resolution, base::Time(), 30); + device_->OnIncomingCapturedBuffer(buffer, + media::VideoFrame::I420, + capture_resolution, + base::TimeTicks(), + 30); buffer = NULL; base::RunLoop().RunUntilIdle(); @@ -463,7 +466,7 @@ TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { device_->OnIncomingCapturedBuffer(buffer, media::VideoFrame::I420, dims, - base::Time(), + base::TimeTicks(), device_format.frame_rate); buffer = NULL; diff --git a/content/browser/renderer_host/media/video_capture_device_impl.cc b/content/browser/renderer_host/media/video_capture_device_impl.cc index 9b37b29..3a94d50 100644 --- a/content/browser/renderer_host/media/video_capture_device_impl.cc +++ b/content/browser/renderer_host/media/video_capture_device_impl.cc @@ -62,7 +62,7 @@ ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {} bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( VideoCaptureOracle::Event event, - base::Time event_time, + base::TimeTicks event_time, scoped_refptr<media::VideoFrame>* storage, CaptureFrameCallback* callback) { base::AutoLock guard(lock_); @@ -166,7 +166,7 @@ void ThreadSafeCaptureOracle::ReportError() { void ThreadSafeCaptureOracle::DidCaptureFrame( scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer, int frame_number, - base::Time timestamp, + base::TimeTicks timestamp, bool success) { base::AutoLock guard(lock_); TRACE_EVENT_ASYNC_END2("mirroring", "Capture", buffer.get(), diff --git a/content/browser/renderer_host/media/video_capture_device_impl.h b/content/browser/renderer_host/media/video_capture_device_impl.h index d9329b6..d2c03f5 100644 --- a/content/browser/renderer_host/media/video_capture_device_impl.h +++ b/content/browser/renderer_host/media/video_capture_device_impl.h @@ -51,11 +51,11 @@ class ThreadSafeCaptureOracle // If |success| is true then the frame provided is valid and |timestamp| // indicates when the frame was painted. // If |success| is false, both the frame provided and |timestamp| are invalid. - typedef base::Callback<void(base::Time timestamp, bool success)> + typedef base::Callback<void(base::TimeTicks timestamp, bool success)> CaptureFrameCallback; bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event, - base::Time event_time, + base::TimeTicks event_time, scoped_refptr<media::VideoFrame>* storage, CaptureFrameCallback* callback); @@ -81,7 +81,7 @@ class ThreadSafeCaptureOracle void DidCaptureFrame( scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer, int frame_number, - base::Time timestamp, + base::TimeTicks timestamp, bool success); // Protects everything below it. base::Lock lock_; diff --git a/content/browser/renderer_host/media/video_capture_host.cc b/content/browser/renderer_host/media/video_capture_host.cc index 039d981..292ecb7 100644 --- a/content/browser/renderer_host/media/video_capture_host.cc +++ b/content/browser/renderer_host/media/video_capture_host.cc @@ -69,7 +69,7 @@ void VideoCaptureHost::OnBufferDestroyed( void VideoCaptureHost::OnBufferReady( const VideoCaptureControllerID& controller_id, int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& frame_format) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, @@ -112,7 +112,8 @@ void VideoCaptureHost::DoSendFreeBufferOnIOThread( void VideoCaptureHost::DoSendFilledBufferOnIOThread( const VideoCaptureControllerID& controller_id, - int buffer_id, base::Time timestamp, + int buffer_id, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); diff --git a/content/browser/renderer_host/media/video_capture_host.h b/content/browser/renderer_host/media/video_capture_host.h index b71aac37..bd1db0a 100644 --- a/content/browser/renderer_host/media/video_capture_host.h +++ b/content/browser/renderer_host/media/video_capture_host.h @@ -84,11 +84,10 @@ class CONTENT_EXPORT VideoCaptureHost int buffer_id) OVERRIDE; virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, int buffer_id) OVERRIDE; - virtual void OnBufferReady( - const VideoCaptureControllerID& id, - int buffer_id, - base::Time timestamp, - const media::VideoCaptureFormat& format) OVERRIDE; + virtual void OnBufferReady(const VideoCaptureControllerID& id, + int buffer_id, + base::TimeTicks timestamp, + const media::VideoCaptureFormat& format) OVERRIDE; virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE; private: @@ -138,7 +137,7 @@ class CONTENT_EXPORT VideoCaptureHost void DoSendFilledBufferOnIOThread( const VideoCaptureControllerID& controller_id, int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format); // Handle error coming from VideoCaptureDevice. diff --git a/content/browser/renderer_host/media/video_capture_host_unittest.cc b/content/browser/renderer_host/media/video_capture_host_unittest.cc index 551b0c2..01545db 100644 --- a/content/browser/renderer_host/media/video_capture_host_unittest.cc +++ b/content/browser/renderer_host/media/video_capture_host_unittest.cc @@ -119,7 +119,9 @@ class MockVideoCaptureHost : public VideoCaptureHost { MOCK_METHOD2(OnBufferFreed, void(int device_id, int buffer_id)); MOCK_METHOD4(OnBufferFilled, - void(int device_id, int buffer_id, base::Time timestamp, + void(int device_id, + int buffer_id, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format)); MOCK_METHOD2(OnStateChanged, void(int device_id, VideoCaptureState state)); @@ -203,7 +205,7 @@ class MockVideoCaptureHost : public VideoCaptureHost { void OnBufferFilledDispatch(int device_id, int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& frame_format) { base::SharedMemory* dib = filled_dib_[buffer_id]; ASSERT_TRUE(dib != NULL); diff --git a/content/browser/renderer_host/media/video_capture_manager_unittest.cc b/content/browser/renderer_host/media/video_capture_manager_unittest.cc index bc89159..1dfad2d 100644 --- a/content/browser/renderer_host/media/video_capture_manager_unittest.cc +++ b/content/browser/renderer_host/media/video_capture_manager_unittest.cc @@ -53,11 +53,11 @@ class MockFrameObserver : public VideoCaptureControllerEventHandler { int length, int buffer_id) OVERRIDE {} virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, int buffer_id) OVERRIDE {} - virtual void OnBufferReady( - const VideoCaptureControllerID& id, - int buffer_id, - base::Time timestamp, - const media::VideoCaptureFormat& format) OVERRIDE {} + virtual void OnBufferReady(const VideoCaptureControllerID& id, + int buffer_id, + base::TimeTicks timestamp, + const media::VideoCaptureFormat& format) + OVERRIDE {} virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE {} void OnGotControllerCallback(VideoCaptureControllerID) {} diff --git a/content/browser/renderer_host/media/video_capture_oracle.cc b/content/browser/renderer_host/media/video_capture_oracle.cc index fb41ec2..499bde4 100644 --- a/content/browser/renderer_host/media/video_capture_oracle.cc +++ b/content/browser/renderer_host/media/video_capture_oracle.cc @@ -33,8 +33,8 @@ VideoCaptureOracle::VideoCaptureOracle(base::TimeDelta capture_period, kNumRedundantCapturesOfStaticContent) {} bool VideoCaptureOracle::ObserveEventAndDecideCapture( - Event event, - base::Time event_time) { + Event event, + base::TimeTicks event_time) { // Record |event| and decide whether it's a good time to capture. const bool content_is_dirty = (event == kCompositorUpdate || event == kSoftwarePaint); @@ -54,7 +54,7 @@ int VideoCaptureOracle::RecordCapture() { } bool VideoCaptureOracle::CompleteCapture(int frame_number, - base::Time timestamp) { + base::TimeTicks timestamp) { // Drop frame if previous frame number is higher or we're trying to deliver // a frame with the same timestamp. if (last_delivered_frame_number_ > frame_number || @@ -88,7 +88,8 @@ SmoothEventSampler::SmoothEventSampler(base::TimeDelta capture_period, DCHECK_GT(capture_period_.InMicroseconds(), 0); } -bool SmoothEventSampler::AddEventAndConsiderSampling(base::Time event_time) { +bool SmoothEventSampler::AddEventAndConsiderSampling( + base::TimeTicks event_time) { DCHECK(!event_time.is_null()); // Add tokens to the bucket based on advancement in time. Then, re-bound the @@ -137,7 +138,8 @@ void SmoothEventSampler::RecordSample() { << "Content changed; capture will resume."; } -bool SmoothEventSampler::IsOverdueForSamplingAt(base::Time event_time) const { +bool SmoothEventSampler::IsOverdueForSamplingAt(base::TimeTicks event_time) + const { DCHECK(!event_time.is_null()); // If we don't get events on compositor updates on this platform, then we @@ -149,6 +151,9 @@ bool SmoothEventSampler::IsOverdueForSamplingAt(base::Time event_time) const { } } + if (last_sample_.is_null()) + return true; + // If we're dirty but not yet old, then we've recently gotten updates, so we // won't request a sample just yet. base::TimeDelta dirty_interval = event_time - last_sample_; diff --git a/content/browser/renderer_host/media/video_capture_oracle.h b/content/browser/renderer_host/media/video_capture_oracle.h index 739b569..c14d16f 100644 --- a/content/browser/renderer_host/media/video_capture_oracle.h +++ b/content/browser/renderer_host/media/video_capture_oracle.h @@ -22,7 +22,7 @@ class CONTENT_EXPORT SmoothEventSampler { // Add a new event to the event history, and return whether it ought to be // sampled based on the desired |capture_period|. The event is not recorded as // a sample until RecordSample() is called. - bool AddEventAndConsiderSampling(base::Time event_time); + bool AddEventAndConsiderSampling(base::TimeTicks event_time); // Operates on the last event added by AddEventAndConsiderSampling(), marking // it as sampled. After this point we are current in the stream of events, as @@ -31,7 +31,7 @@ class CONTENT_EXPORT SmoothEventSampler { // Returns true if, at time |event_time|, sampling should occur because too // much time will have passed relative to the last event and/or sample. - bool IsOverdueForSamplingAt(base::Time event_time) const; + bool IsOverdueForSamplingAt(base::TimeTicks event_time) const; // Returns true if AddEventAndConsiderSampling() has been called since the // last call to RecordSample(). @@ -43,8 +43,8 @@ class CONTENT_EXPORT SmoothEventSampler { const int redundant_capture_goal_; const base::TimeDelta token_bucket_capacity_; - base::Time current_event_; - base::Time last_sample_; + base::TimeTicks current_event_; + base::TimeTicks last_sample_; int overdue_sample_count_; base::TimeDelta token_bucket_; @@ -70,9 +70,7 @@ class CONTENT_EXPORT VideoCaptureOracle { // Record an event of type |event|, and decide whether the caller should do a // frame capture immediately. Decisions of the oracle are final: the caller // must do what it is told. - bool ObserveEventAndDecideCapture( - Event event, - base::Time event_time); + bool ObserveEventAndDecideCapture(Event event, base::TimeTicks event_time); // Record the start of a capture. Returns a frame_number to be used with // CompleteCapture(). @@ -80,7 +78,7 @@ class CONTENT_EXPORT VideoCaptureOracle { // Record the completion of a capture. Returns true iff the captured frame // should be delivered. - bool CompleteCapture(int frame_number, base::Time timestamp); + bool CompleteCapture(int frame_number, base::TimeTicks timestamp); base::TimeDelta capture_period() const { return capture_period_; } @@ -96,7 +94,7 @@ class CONTENT_EXPORT VideoCaptureOracle { int last_delivered_frame_number_; // Stores the timestamp of the last delivered frame. - base::Time last_delivered_frame_timestamp_; + base::TimeTicks last_delivered_frame_timestamp_; // Tracks present/paint history. SmoothEventSampler sampler_; diff --git a/content/browser/renderer_host/media/video_capture_oracle_unittest.cc b/content/browser/renderer_host/media/video_capture_oracle_unittest.cc index 40c1826..22e2dda 100644 --- a/content/browser/renderer_host/media/video_capture_oracle_unittest.cc +++ b/content/browser/renderer_host/media/video_capture_oracle_unittest.cc @@ -12,7 +12,8 @@ namespace content { namespace { void SteadyStateSampleAndAdvance(base::TimeDelta vsync, - SmoothEventSampler* sampler, base::Time* t) { + SmoothEventSampler* sampler, + base::TimeTicks* t) { ASSERT_TRUE(sampler->AddEventAndConsiderSampling(*t)); ASSERT_TRUE(sampler->HasUnrecordedEvent()); sampler->RecordSample(); @@ -23,7 +24,8 @@ void SteadyStateSampleAndAdvance(base::TimeDelta vsync, } void SteadyStateNoSampleAndAdvance(base::TimeDelta vsync, - SmoothEventSampler* sampler, base::Time* t) { + SmoothEventSampler* sampler, + base::TimeTicks* t) { ASSERT_FALSE(sampler->AddEventAndConsiderSampling(*t)); ASSERT_TRUE(sampler->HasUnrecordedEvent()); ASSERT_FALSE(sampler->IsOverdueForSamplingAt(*t)); @@ -31,9 +33,16 @@ void SteadyStateNoSampleAndAdvance(base::TimeDelta vsync, ASSERT_FALSE(sampler->IsOverdueForSamplingAt(*t)); } +void TimeTicksFromString(const char* string, base::TimeTicks* t) { + base::Time time; + ASSERT_TRUE(base::Time::FromString(string, &time)); + *t = base::TimeTicks::UnixEpoch() + (time - base::Time::UnixEpoch()); +} + void TestRedundantCaptureStrategy(base::TimeDelta capture_period, int redundant_capture_goal, - SmoothEventSampler* sampler, base::Time* t) { + SmoothEventSampler* sampler, + base::TimeTicks* t) { // Before any events have been considered, we're overdue for sampling. ASSERT_TRUE(sampler->IsOverdueForSamplingAt(*t)); @@ -68,8 +77,8 @@ TEST(SmoothEventSamplerTest, Sample60HertzAt30Hertz) { const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 60; SmoothEventSampler sampler(capture_period, true, redundant_capture_goal); - base::Time t; - ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); + base::TimeTicks t; + TimeTicksFromString("Sat, 23 Mar 2013 1:21:08 GMT", &t); TestRedundantCaptureStrategy(capture_period, redundant_capture_goal, &sampler, &t); @@ -108,8 +117,8 @@ TEST(SmoothEventSamplerTest, Sample50HertzAt30Hertz) { const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 50; SmoothEventSampler sampler(capture_period, true, redundant_capture_goal); - base::Time t; - ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); + base::TimeTicks t; + TimeTicksFromString("Sat, 23 Mar 2013 1:21:08 GMT", &t); TestRedundantCaptureStrategy(capture_period, redundant_capture_goal, &sampler, &t); @@ -154,8 +163,8 @@ TEST(SmoothEventSamplerTest, Sample75HertzAt30Hertz) { const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 75; SmoothEventSampler sampler(capture_period, true, redundant_capture_goal); - base::Time t; - ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); + base::TimeTicks t; + TimeTicksFromString("Sat, 23 Mar 2013 1:21:08 GMT", &t); TestRedundantCaptureStrategy(capture_period, redundant_capture_goal, &sampler, &t); @@ -204,8 +213,8 @@ TEST(SmoothEventSamplerTest, Sample30HertzAt30Hertz) { const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 30; SmoothEventSampler sampler(capture_period, true, redundant_capture_goal); - base::Time t; - ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); + base::TimeTicks t; + TimeTicksFromString("Sat, 23 Mar 2013 1:21:08 GMT", &t); TestRedundantCaptureStrategy(capture_period, redundant_capture_goal, &sampler, &t); @@ -240,8 +249,8 @@ TEST(SmoothEventSamplerTest, Sample24HertzAt30Hertz) { const base::TimeDelta vsync = base::TimeDelta::FromSeconds(1) / 24; SmoothEventSampler sampler(capture_period, true, redundant_capture_goal); - base::Time t; - ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); + base::TimeTicks t; + TimeTicksFromString("Sat, 23 Mar 2013 1:21:08 GMT", &t); TestRedundantCaptureStrategy(capture_period, redundant_capture_goal, &sampler, &t); @@ -274,8 +283,8 @@ TEST(SmoothEventSamplerTest, DoubleDrawAtOneTimeStillDirties) { const base::TimeDelta overdue_period = base::TimeDelta::FromSeconds(1); SmoothEventSampler sampler(capture_period, true, 1); - base::Time t; - ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); + base::TimeTicks t; + TimeTicksFromString("Sat, 23 Mar 2013 1:21:08 GMT", &t); ASSERT_TRUE(sampler.AddEventAndConsiderSampling(t)); sampler.RecordSample(); @@ -299,8 +308,8 @@ TEST(SmoothEventSamplerTest, FallbackToPollingIfUpdatesUnreliable) { SmoothEventSampler should_not_poll(timer_interval, true, 1); SmoothEventSampler should_poll(timer_interval, false, 1); - base::Time t; - ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); + base::TimeTicks t; + TimeTicksFromString("Sat, 23 Mar 2013 1:21:08 GMT", &t); // Do one round of the "happy case" where an event was received and // RecordSample() was called by the client. @@ -355,8 +364,8 @@ struct DataPoint { void ReplayCheckingSamplerDecisions(const DataPoint* data_points, size_t num_data_points, SmoothEventSampler* sampler) { - base::Time t; - ASSERT_TRUE(base::Time::FromString("Sat, 23 Mar 2013 1:21:08 GMT", &t)); + base::TimeTicks t; + TimeTicksFromString("Sat, 23 Mar 2013 1:21:08 GMT", &t); for (size_t i = 0; i < num_data_points; ++i) { t += base::TimeDelta::FromMicroseconds( static_cast<int64>(data_points[i].increment_ms * 1000)); diff --git a/content/browser/renderer_host/media/web_contents_video_capture_device.cc b/content/browser/renderer_host/media/web_contents_video_capture_device.cc index 15258a0..4f21539 100644 --- a/content/browser/renderer_host/media/web_contents_video_capture_device.cc +++ b/content/browser/renderer_host/media/web_contents_video_capture_device.cc @@ -103,7 +103,7 @@ gfx::Rect ComputeYV12LetterboxRegion(const gfx::Size& frame_size, // compatible with RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback. void InvokeCaptureFrameCallback( const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, - base::Time timestamp, + base::TimeTicks timestamp, bool frame_captured) { capture_frame_cb.Run(timestamp, frame_captured); } @@ -118,7 +118,7 @@ class FrameSubscriber : public RenderWidgetHostViewFrameSubscriber { oracle_proxy_(oracle) {} virtual bool ShouldCaptureFrame( - base::Time present_time, + base::TimeTicks present_time, scoped_refptr<media::VideoFrame>* storage, RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback* deliver_frame_cb) OVERRIDE; @@ -145,11 +145,11 @@ class FrameSubscriber : public RenderWidgetHostViewFrameSubscriber { // autonomously on some other thread. class ContentCaptureSubscription : public content::NotificationObserver { public: - typedef base::Callback<void( - const base::Time&, - const scoped_refptr<media::VideoFrame>&, - const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback&)> - CaptureCallback; + typedef base::Callback< + void(const base::TimeTicks&, + const scoped_refptr<media::VideoFrame>&, + const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback&)> + CaptureCallback; // Create a subscription. Whenever a manual capture is required, the // subscription will invoke |capture_callback| on the UI thread to do the @@ -218,11 +218,10 @@ class WebContentsCaptureMachine // completes. The copy will occur to |target|. // // This may be used as a ContentCaptureSubscription::CaptureCallback. - void Capture( - const base::Time& start_time, - const scoped_refptr<media::VideoFrame>& target, - const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& - deliver_frame_cb); + void Capture(const base::TimeTicks& start_time, + const scoped_refptr<media::VideoFrame>& target, + const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& + deliver_frame_cb); // content::WebContentsObserver implementation. virtual void DidShowFullscreenWidget(int routing_id) OVERRIDE { @@ -261,7 +260,7 @@ class WebContentsCaptureMachine // Response callback for RenderWidgetHost::CopyFromBackingStore(). void DidCopyFromBackingStore( - const base::Time& start_time, + const base::TimeTicks& start_time, const scoped_refptr<media::VideoFrame>& target, const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& deliver_frame_cb, @@ -270,7 +269,7 @@ class WebContentsCaptureMachine // Response callback for RWHVP::CopyFromCompositingSurfaceToVideoFrame(). void DidCopyFromCompositingSurfaceToVideoFrame( - const base::Time& start_time, + const base::TimeTicks& start_time, const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& deliver_frame_cb, bool success); @@ -318,7 +317,7 @@ class VideoFrameDeliveryLog { private: // The following keep track of and log the effective frame rate whenever // verbose logging is turned on. - base::Time last_frame_rate_log_time_; + base::TimeTicks last_frame_rate_log_time_; int count_frames_rendered_; int last_frame_number_; @@ -326,7 +325,7 @@ class VideoFrameDeliveryLog { }; bool FrameSubscriber::ShouldCaptureFrame( - base::Time present_time, + base::TimeTicks present_time, scoped_refptr<media::VideoFrame>* storage, DeliverFrameCallback* deliver_frame_cb) { TRACE_EVENT1("mirroring", "FrameSubscriber::ShouldCaptureFrame", @@ -413,7 +412,7 @@ void ContentCaptureSubscription::Observe( base::Closure copy_done_callback; scoped_refptr<media::VideoFrame> frame; RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback deliver_frame_cb; - const base::Time start_time = base::Time::Now(); + const base::TimeTicks start_time = base::TimeTicks::Now(); if (paint_subscriber_.ShouldCaptureFrame(start_time, &frame, &deliver_frame_cb)) { @@ -432,7 +431,7 @@ void ContentCaptureSubscription::OnTimer() { scoped_refptr<media::VideoFrame> frame; RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback deliver_frame_cb; - const base::Time start_time = base::Time::Now(); + const base::TimeTicks start_time = base::TimeTicks::Now(); if (timer_subscriber_.ShouldCaptureFrame(start_time, &frame, &deliver_frame_cb)) { @@ -519,7 +518,7 @@ void VideoFrameDeliveryLog::ChronicleFrameDelivery(int frame_number) { // Log frame rate, if verbose logging is turned on. static const base::TimeDelta kFrameRateLogInterval = base::TimeDelta::FromSeconds(10); - const base::Time now = base::Time::Now(); + const base::TimeTicks now = base::TimeTicks::Now(); if (last_frame_rate_log_time_.is_null()) { last_frame_rate_log_time_ = now; count_frames_rendered_ = 0; @@ -589,7 +588,7 @@ void WebContentsCaptureMachine::Stop() { } void WebContentsCaptureMachine::Capture( - const base::Time& start_time, + const base::TimeTicks& start_time, const scoped_refptr<media::VideoFrame>& target, const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& deliver_frame_cb) { @@ -599,7 +598,7 @@ void WebContentsCaptureMachine::Capture( RenderWidgetHostViewPort* view = rwh ? RenderWidgetHostViewPort::FromRWHV(rwh->GetView()) : NULL; if (!view || !rwh) { - deliver_frame_cb.Run(base::Time(), false); + deliver_frame_cb.Run(base::TimeTicks(), false); return; } @@ -698,7 +697,7 @@ RenderWidgetHost* WebContentsCaptureMachine::GetTarget() { } void WebContentsCaptureMachine::DidCopyFromBackingStore( - const base::Time& start_time, + const base::TimeTicks& start_time, const scoped_refptr<media::VideoFrame>& target, const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& deliver_frame_cb, @@ -706,7 +705,7 @@ void WebContentsCaptureMachine::DidCopyFromBackingStore( const SkBitmap& bitmap) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - base::Time now = base::Time::Now(); + base::TimeTicks now = base::TimeTicks::Now(); if (success) { UMA_HISTOGRAM_TIMES("TabCapture.CopyTimeBitmap", now - start_time); TRACE_EVENT_ASYNC_STEP_INTO0("mirroring", "Capture", target.get(), @@ -722,12 +721,12 @@ void WebContentsCaptureMachine::DidCopyFromBackingStore( } void WebContentsCaptureMachine::DidCopyFromCompositingSurfaceToVideoFrame( - const base::Time& start_time, + const base::TimeTicks& start_time, const RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback& deliver_frame_cb, bool success) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - base::Time now = base::Time::Now(); + base::TimeTicks now = base::TimeTicks::Now(); if (success) { UMA_HISTOGRAM_TIMES("TabCapture.CopyTimeVideoFrame", now - start_time); diff --git a/content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc b/content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc index 6abb183..39b427b 100644 --- a/content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc +++ b/content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc @@ -192,7 +192,7 @@ class CaptureTestView : public TestRenderWidgetHostView { // Simulate a compositor paint event for our subscriber. void SimulateUpdate() { - const base::Time present_time = base::Time::Now(); + const base::TimeTicks present_time = base::TimeTicks::Now(); RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; scoped_refptr<media::VideoFrame> target; if (subscriber_ && subscriber_->ShouldCaptureFrame(present_time, @@ -335,7 +335,7 @@ class StubClient : public media::VideoCaptureDevice::Client { virtual void OnIncomingCapturedFrame( const uint8* data, int length, - base::Time timestamp, + base::TimeTicks timestamp, int rotation, const media::VideoCaptureFormat& frame_format) OVERRIDE { FAIL(); @@ -344,7 +344,7 @@ class StubClient : public media::VideoCaptureDevice::Client { virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, media::VideoFrame::Format format, const gfx::Size& dimensions, - base::Time timestamp, + base::TimeTicks timestamp, int frame_rate) OVERRIDE { EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), dimensions); EXPECT_EQ(media::VideoFrame::I420, format); diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 9a38126..1c54253 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -1297,7 +1297,7 @@ void RenderWidgetHostViewAura::SwapBuffersCompleted( void RenderWidgetHostViewAura::DidReceiveFrameFromRenderer() { if (frame_subscriber() && CanCopyToVideoFrame()) { - const base::Time present_time = base::Time::Now(); + const base::TimeTicks present_time = base::TimeTicks::Now(); scoped_refptr<media::VideoFrame> frame; RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; if (frame_subscriber()->ShouldCaptureFrame(present_time, diff --git a/content/browser/renderer_host/render_widget_host_view_browsertest.cc b/content/browser/renderer_host/render_widget_host_view_browsertest.cc index 3f1d760..22bc6f2 100644 --- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc +++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc @@ -147,7 +147,7 @@ class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { // Callback when using frame subscriber API. void FrameDelivered(const scoped_refptr<base::MessageLoopProxy>& loop, base::Closure quit_closure, - base::Time timestamp, + base::TimeTicks timestamp, bool frame_captured) { ++callback_invoke_count_; if (frame_captured) @@ -338,10 +338,9 @@ class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { : callback_(callback) { } - virtual bool ShouldCaptureFrame( - base::Time present_time, - scoped_refptr<media::VideoFrame>* storage, - DeliverFrameCallback* callback) OVERRIDE { + virtual bool ShouldCaptureFrame(base::TimeTicks present_time, + scoped_refptr<media::VideoFrame>* storage, + DeliverFrameCallback* callback) OVERRIDE { // Only allow one frame capture to be made. Otherwise, the compositor could // start multiple captures, unbounded, and eventually its own limiter logic // will begin invoking |callback| with a |false| result. This flakes out @@ -494,14 +493,15 @@ IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTest, CopyTwice) { base::Unretained(this), base::MessageLoopProxy::current(), base::Closure(), - base::Time::Now())); + base::TimeTicks::Now())); view->CopyFromCompositingSurfaceToVideoFrame( - gfx::Rect(view->GetViewBounds().size()), second_output, + gfx::Rect(view->GetViewBounds().size()), + second_output, base::Bind(&RenderWidgetHostViewBrowserTest::FrameDelivered, base::Unretained(this), base::MessageLoopProxy::current(), run_loop.QuitClosure(), - base::Time::Now())); + base::TimeTicks::Now())); run_loop.Run(); EXPECT_EQ(2, callback_invoke_count()); diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index d5825c8..43b0086 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -1294,7 +1294,7 @@ void RenderWidgetHostViewMac::CompositorSwapBuffers( // There is no window to present so capturing during present won't work. // We check if frame subscriber wants this frame and capture manually. if (compositing_iosurface_ && frame_subscriber_) { - const base::Time present_time = base::Time::Now(); + const base::TimeTicks present_time = base::TimeTicks::Now(); scoped_refptr<media::VideoFrame> frame; RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; if (frame_subscriber_->ShouldCaptureFrame(present_time, diff --git a/content/common/media/video_capture_messages.h b/content/common/media/video_capture_messages.h index 55cbb38..a1e913f 100644 --- a/content/common/media/video_capture_messages.h +++ b/content/common/media/video_capture_messages.h @@ -46,7 +46,7 @@ IPC_MESSAGE_CONTROL2(VideoCaptureMsg_FreeBuffer, IPC_MESSAGE_CONTROL4(VideoCaptureMsg_BufferReady, int /* device id */, int /* buffer_id */, - base::Time /* timestamp */, + base::TimeTicks /* timestamp */, media::VideoCaptureFormat /* resolution */) // Start a video capture as |device_id|, a new id picked by the renderer diff --git a/content/port/browser/render_widget_host_view_frame_subscriber.h b/content/port/browser/render_widget_host_view_frame_subscriber.h index c99624f..76fd4b1 100644 --- a/content/port/browser/render_widget_host_view_frame_subscriber.h +++ b/content/port/browser/render_widget_host_view_frame_subscriber.h @@ -40,9 +40,8 @@ class RenderWidgetHostViewFrameSubscriber { // If |frame_captured| is false then the content in frame provided is // invalid. There was an error during the process of frame capture or the // platform layer is shutting down. |timestamp| is also invalid in this case. - typedef base::Callback<void( - base::Time /* timestamp */, - bool /* frame_captured */)> DeliverFrameCallback; + typedef base::Callback<void(base::TimeTicks /* timestamp */, + bool /* frame_captured */)> DeliverFrameCallback; // Called when a new frame is going to be presented at time // |present_time|. Implementation can decide whether the current frame should @@ -61,10 +60,9 @@ class RenderWidgetHostViewFrameSubscriber { // platform layer to decide when to deliver a captured frame. // // Return false if the current frame should not be captured. - virtual bool ShouldCaptureFrame( - base::Time present_time, - scoped_refptr<media::VideoFrame>* storage, - DeliverFrameCallback* callback) = 0; + virtual bool ShouldCaptureFrame(base::TimeTicks present_time, + scoped_refptr<media::VideoFrame>* storage, + DeliverFrameCallback* callback) = 0; }; } // namespace content diff --git a/content/renderer/media/video_capture_impl.cc b/content/renderer/media/video_capture_impl.cc index 30b43dd..066daf2 100644 --- a/content/renderer/media/video_capture_impl.cc +++ b/content/renderer/media/video_capture_impl.cc @@ -104,7 +104,7 @@ void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { void VideoCaptureImpl::OnBufferReceived( int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format) { capture_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(&VideoCaptureImpl::DoBufferReceivedOnCaptureThread, @@ -177,7 +177,7 @@ void VideoCaptureImpl::DoStartCaptureOnCaptureThread( } DVLOG(1) << "StartCapture: starting with first resolution " << params_.requested_format.frame_size.ToString(); - + first_frame_timestamp_ = base::TimeTicks(); StartCaptureInternal(); } } @@ -242,7 +242,7 @@ void VideoCaptureImpl::DoBufferDestroyedOnCaptureThread(int buffer_id) { void VideoCaptureImpl::DoBufferReceivedOnCaptureThread( int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format) { DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); @@ -252,6 +252,8 @@ void VideoCaptureImpl::DoBufferReceivedOnCaptureThread( } last_frame_format_ = format; + if (first_frame_timestamp_.is_null()) + first_frame_timestamp_ = timestamp; ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); DCHECK(iter != client_buffers_.end()); @@ -265,9 +267,7 @@ void VideoCaptureImpl::DoBufferReceivedOnCaptureThread( reinterpret_cast<uint8*>(buffer->buffer->memory()), buffer->buffer_size, buffer->buffer->handle(), - // TODO(sheu): convert VideoCaptureMessageFilter::Delegate to use - // base::TimeTicks instead of base::Time. http://crbug.com/249215 - timestamp - base::Time::UnixEpoch(), + timestamp - first_frame_timestamp_, media::BindToLoop( capture_message_loop_proxy_, base::Bind( diff --git a/content/renderer/media/video_capture_impl.h b/content/renderer/media/video_capture_impl.h index 2215cef..55a2eef 100644 --- a/content/renderer/media/video_capture_impl.h +++ b/content/renderer/media/video_capture_impl.h @@ -62,10 +62,10 @@ class CONTENT_EXPORT VideoCaptureImpl int length, int buffer_id) OVERRIDE; virtual void OnBufferDestroyed(int buffer_id) OVERRIDE; - virtual void OnBufferReceived( - int buffer_id, - base::Time timestamp, - const media::VideoCaptureFormat& format) OVERRIDE; + virtual void OnBufferReceived(int buffer_id, + base::TimeTicks timestamp, + const media::VideoCaptureFormat& format) + OVERRIDE; virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; virtual void OnDelegateAdded(int32 device_id) OVERRIDE; @@ -94,10 +94,9 @@ class CONTENT_EXPORT VideoCaptureImpl int length, int buffer_id); void DoBufferDestroyedOnCaptureThread(int buffer_id); - void DoBufferReceivedOnCaptureThread( - int buffer_id, - base::Time timestamp, - const media::VideoCaptureFormat& format); + void DoBufferReceivedOnCaptureThread(int buffer_id, + base::TimeTicks timestamp, + const media::VideoCaptureFormat& format); void DoClientBufferFinishedOnCaptureThread( int buffer_id, const scoped_refptr<ClientBuffer>& buffer); @@ -141,6 +140,9 @@ class CONTENT_EXPORT VideoCaptureImpl // The device's video capture format sent from browser process side. media::VideoCaptureFormat last_frame_format_; + // The device's first captured frame timestamp sent from browser process side. + base::TimeTicks first_frame_timestamp_; + bool suspended_; VideoCaptureState state_; diff --git a/content/renderer/media/video_capture_message_filter.cc b/content/renderer/media/video_capture_message_filter.cc index 52847d9..98b2e4e 100644 --- a/content/renderer/media/video_capture_message_filter.cc +++ b/content/renderer/media/video_capture_message_filter.cc @@ -117,7 +117,7 @@ void VideoCaptureMessageFilter::OnBufferCreated( void VideoCaptureMessageFilter::OnBufferReceived( int device_id, int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format) { Delegate* delegate = find_delegate(device_id); if (!delegate) { diff --git a/content/renderer/media/video_capture_message_filter.h b/content/renderer/media/video_capture_message_filter.h index 024c1bd..2c71efa 100644 --- a/content/renderer/media/video_capture_message_filter.h +++ b/content/renderer/media/video_capture_message_filter.h @@ -34,7 +34,7 @@ class CONTENT_EXPORT VideoCaptureMessageFilter // Called when a video frame buffer is received from the browser process. virtual void OnBufferReceived(int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format) = 0; // Called when state of a video capture device has changed in the browser @@ -85,7 +85,7 @@ class CONTENT_EXPORT VideoCaptureMessageFilter // Receive a filled buffer from browser process. void OnBufferReceived(int device_id, int buffer_id, - base::Time timestamp, + base::TimeTicks timestamp, const media::VideoCaptureFormat& format); // State of browser process' video capture device has changed. diff --git a/content/renderer/media/video_capture_message_filter_unittest.cc b/content/renderer/media/video_capture_message_filter_unittest.cc index 366bcb0..985aebe 100644 --- a/content/renderer/media/video_capture_message_filter_unittest.cc +++ b/content/renderer/media/video_capture_message_filter_unittest.cc @@ -29,9 +29,10 @@ class MockVideoCaptureDelegate : public VideoCaptureMessageFilter::Delegate { int length, int buffer_id)); MOCK_METHOD1(OnBufferDestroyed, void(int buffer_id)); - MOCK_METHOD3(OnBufferReceived, void(int buffer_id, - base::Time timestamp, - const media::VideoCaptureFormat& format)); + MOCK_METHOD3(OnBufferReceived, + void(int buffer_id, + base::TimeTicks timestamp, + const media::VideoCaptureFormat& format)); MOCK_METHOD1(OnStateChanged, void(VideoCaptureState state)); virtual void OnDelegateAdded(int32 device_id) OVERRIDE { @@ -79,7 +80,7 @@ TEST(VideoCaptureMessageFilterTest, Basic) { // VideoCaptureMsg_BufferReady int buffer_id = 22; - base::Time timestamp = base::Time::FromInternalValue(1); + base::TimeTicks timestamp = base::TimeTicks::FromInternalValue(1); media::VideoCaptureFormat format( gfx::Size(234, 512), 30, media::PIXEL_FORMAT_I420); diff --git a/media/video/capture/android/video_capture_device_android.cc b/media/video/capture/android/video_capture_device_android.cc index adfa9a3..0149562 100644 --- a/media/video/capture/android/video_capture_device_android.cc +++ b/media/video/capture/android/video_capture_device_android.cc @@ -222,7 +222,7 @@ void VideoCaptureDeviceAndroid::OnFrameAvailable( client_->OnIncomingCapturedFrame(reinterpret_cast<uint8*>(buffer), length, - base::Time::Now(), + base::TimeTicks::Now(), rotation, capture_format_); } diff --git a/media/video/capture/fake_video_capture_device.cc b/media/video/capture/fake_video_capture_device.cc index a87514d..852a480 100644 --- a/media/video/capture/fake_video_capture_device.cc +++ b/media/video/capture/fake_video_capture_device.cc @@ -216,7 +216,7 @@ void FakeVideoCaptureDevice::OnCaptureTask() { // Give the captured frame to the client. client_->OnIncomingCapturedFrame(fake_frame_.get(), frame_size, - base::Time::Now(), + base::TimeTicks::Now(), 0, capture_format_); if (!(frame_count_ % kFakeCaptureCapabilityChangePeriod) && diff --git a/media/video/capture/file_video_capture_device.cc b/media/video/capture/file_video_capture_device.cc index 6f118d2..e1c4f52 100644 --- a/media/video/capture/file_video_capture_device.cc +++ b/media/video/capture/file_video_capture_device.cc @@ -286,7 +286,7 @@ void FileVideoCaptureDevice::OnCaptureTask() { // Give the captured frame to the client. client_->OnIncomingCapturedFrame(video_frame_.get(), frame_size_, - base::Time::Now(), + base::TimeTicks::Now(), 0, capture_format_); // Reschedule next CaptureTask. diff --git a/media/video/capture/linux/video_capture_device_linux.cc b/media/video/capture/linux/video_capture_device_linux.cc index 6dfe56f..a6f85d5 100644 --- a/media/video/capture/linux/video_capture_device_linux.cc +++ b/media/video/capture/linux/video_capture_device_linux.cc @@ -510,7 +510,7 @@ void VideoCaptureDeviceLinux::OnCaptureTask() { client_->OnIncomingCapturedFrame( static_cast<uint8*>(buffer_pool_[buffer.index].start), buffer.bytesused, - base::Time::Now(), + base::TimeTicks::Now(), 0, capture_format_); diff --git a/media/video/capture/mac/video_capture_device_mac.mm b/media/video/capture/mac/video_capture_device_mac.mm index 0880667..97e4363 100644 --- a/media/video/capture/mac/video_capture_device_mac.mm +++ b/media/video/capture/mac/video_capture_device_mac.mm @@ -307,7 +307,7 @@ void VideoCaptureDeviceMac::ReceiveFrame( client_->OnIncomingCapturedFrame(video_frame, video_frame_length, - base::Time::Now(), + base::TimeTicks::Now(), 0, capture_format_); } diff --git a/media/video/capture/video_capture_device.h b/media/video/capture/video_capture_device.h index 295401c..c02dcc1 100644 --- a/media/video/capture/video_capture_device.h +++ b/media/video/capture/video_capture_device.h @@ -162,7 +162,7 @@ class MEDIA_EXPORT VideoCaptureDevice { virtual void OnIncomingCapturedFrame( const uint8* data, int length, - base::Time timestamp, + base::TimeTicks timestamp, int rotation, // Clockwise. const VideoCaptureFormat& frame_format) = 0; @@ -176,7 +176,7 @@ class MEDIA_EXPORT VideoCaptureDevice { virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, media::VideoFrame::Format format, const gfx::Size& dimensions, - base::Time timestamp, + base::TimeTicks timestamp, int frame_rate) = 0; // An error has occurred that cannot be handled and VideoCaptureDevice must diff --git a/media/video/capture/video_capture_device_unittest.cc b/media/video/capture/video_capture_device_unittest.cc index cfb0e96..6a765e1 100644 --- a/media/video/capture/video_capture_device_unittest.cc +++ b/media/video/capture/video_capture_device_unittest.cc @@ -75,7 +75,7 @@ class MockClient : public media::VideoCaptureDevice::Client { virtual void OnIncomingCapturedFrame(const uint8* data, int length, - base::Time timestamp, + base::TimeTicks timestamp, int rotation, const VideoCaptureFormat& format) OVERRIDE { @@ -85,7 +85,7 @@ class MockClient : public media::VideoCaptureDevice::Client { virtual void OnIncomingCapturedBuffer(const scoped_refptr<Buffer>& buffer, media::VideoFrame::Format format, const gfx::Size& dimensions, - base::Time timestamp, + base::TimeTicks timestamp, int frame_rate) OVERRIDE { NOTREACHED(); } diff --git a/media/video/capture/win/video_capture_device_mf_win.cc b/media/video/capture/win/video_capture_device_mf_win.cc index cc1e750..f4007fa 100644 --- a/media/video/capture/win/video_capture_device_mf_win.cc +++ b/media/video/capture/win/video_capture_device_mf_win.cc @@ -204,7 +204,7 @@ class MFReaderCallback STDMETHOD(OnReadSample)(HRESULT status, DWORD stream_index, DWORD stream_flags, LONGLONG time_stamp, IMFSample* sample) { - base::Time stamp(base::Time::Now()); + base::TimeTicks stamp(base::TimeTicks::Now()); if (!sample) { observer_->OnIncomingCapturedFrame(NULL, 0, stamp, 0); return S_OK; @@ -407,7 +407,7 @@ void VideoCaptureDeviceMFWin::StopAndDeAllocate() { void VideoCaptureDeviceMFWin::OnIncomingCapturedFrame( const uint8* data, int length, - const base::Time& time_stamp, + const base::TimeTicks& time_stamp, int rotation) { base::AutoLock lock(lock_); if (data && client_.get()) diff --git a/media/video/capture/win/video_capture_device_mf_win.h b/media/video/capture/win/video_capture_device_mf_win.h index 8f7fc75..e0dfb8c 100644 --- a/media/video/capture/win/video_capture_device_mf_win.h +++ b/media/video/capture/win/video_capture_device_mf_win.h @@ -53,11 +53,10 @@ class MEDIA_EXPORT VideoCaptureDeviceMFWin static void GetDeviceNames(Names* device_names); // Captured a new video frame. - void OnIncomingCapturedFrame( - const uint8* data, - int length, - const base::Time& time_stamp, - int rotation); + void OnIncomingCapturedFrame(const uint8* data, + int length, + const base::TimeTicks& time_stamp, + int rotation); private: void OnError(HRESULT hr); diff --git a/media/video/capture/win/video_capture_device_win.cc b/media/video/capture/win/video_capture_device_win.cc index 00056a70..48dd3da 100644 --- a/media/video/capture/win/video_capture_device_win.cc +++ b/media/video/capture/win/video_capture_device_win.cc @@ -478,7 +478,7 @@ void VideoCaptureDeviceWin::StopAndDeAllocate() { void VideoCaptureDeviceWin::FrameReceived(const uint8* buffer, int length) { client_->OnIncomingCapturedFrame( - buffer, length, base::Time::Now(), 0, capture_format_); + buffer, length, base::TimeTicks::Now(), 0, capture_format_); } bool VideoCaptureDeviceWin::CreateCapabilityMap() { |