From 504af45a6f8f1c492a07065cd80c7648b89e49fe Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Tue, 2 Jul 2013 10:15:43 +0000 Subject: [PATCH] Diff NTP and internal once in VideoCaptureImpl. BUG= R=mflodman@webrtc.org, stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1754004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4285 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../video_capture/video_capture_impl.cc | 43 +++++++++++-------- .../video_capture/video_capture_impl.h | 5 ++- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/webrtc/modules/video_capture/video_capture_impl.cc b/webrtc/modules/video_capture/video_capture_impl.cc index 886cc97538..9192dd6c63 100644 --- a/webrtc/modules/video_capture/video_capture_impl.cc +++ b/webrtc/modules/video_capture/video_capture_impl.cc @@ -107,17 +107,26 @@ int32_t VideoCaptureImpl::Process() } VideoCaptureImpl::VideoCaptureImpl(const int32_t id) - : _id(id), _deviceUniqueId(NULL), _apiCs(*CriticalSectionWrapper::CreateCriticalSection()), - _captureDelay(0), _requestedCapability(), + : _id(id), + _deviceUniqueId(NULL), + _apiCs(*CriticalSectionWrapper::CreateCriticalSection()), + _captureDelay(0), + _requestedCapability(), _callBackCs(*CriticalSectionWrapper::CreateCriticalSection()), _lastProcessTime(TickTime::Now()), - _lastFrameRateCallbackTime(TickTime::Now()), _frameRateCallBack(false), - _noPictureAlarmCallBack(false), _captureAlarm(Cleared), _setCaptureDelay(0), - _dataCallBack(NULL), _captureCallBack(NULL), - _lastProcessFrameCount(TickTime::Now()), _rotateFrame(kRotateNone), - last_capture_time_(TickTime::MillisecondTimestamp()) - -{ + _lastFrameRateCallbackTime(TickTime::Now()), + _frameRateCallBack(false), + _noPictureAlarmCallBack(false), + _captureAlarm(Cleared), + _setCaptureDelay(0), + _dataCallBack(NULL), + _captureCallBack(NULL), + _lastProcessFrameCount(TickTime::Now()), + _rotateFrame(kRotateNone), + last_capture_time_(TickTime::MillisecondTimestamp()), + delta_ntp_internal_ms_( + Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() - + TickTime::MillisecondTimestamp()) { _requestedCapability.width = kDefaultWidth; _requestedCapability.height = kDefaultHeight; _requestedCapability.maxFPS = 30; @@ -194,16 +203,14 @@ int32_t VideoCaptureImpl::DeliverCapturedFrame(I420VideoFrame& captureFrame, } // Set the capture time - const int64_t ntp_time_ms = - Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); - int64_t internal_capture_time = TickTime::MillisecondTimestamp(); if (capture_time != 0) { - int64_t time_since_capture = ntp_time_ms - capture_time; - internal_capture_time -= time_since_capture; - captureFrame.set_render_time_ms(internal_capture_time); - } - else { - captureFrame.set_render_time_ms(internal_capture_time); + int64_t internal_capture_time = TickTime::MillisecondTimestamp(); + int64_t ntp_time_ms = internal_capture_time + delta_ntp_internal_ms_; + int64_t time_since_capture = ntp_time_ms - capture_time; + internal_capture_time -= time_since_capture; + captureFrame.set_render_time_ms(internal_capture_time); + } else { + captureFrame.set_render_time_ms(TickTime::MillisecondTimestamp()); } TRACE_EVENT1("webrtc", "VC::DeliverCapturedFrame", diff --git a/webrtc/modules/video_capture/video_capture_impl.h b/webrtc/modules/video_capture/video_capture_impl.h index 6ed65ae36a..6133f75156 100644 --- a/webrtc/modules/video_capture/video_capture_impl.h +++ b/webrtc/modules/video_capture/video_capture_impl.h @@ -132,7 +132,10 @@ private: // Used to make sure incoming timestamp is increasing for every frame. int64_t last_capture_time_; + + // Delta used for translating between NTP and internal timestamps. + const int64_t delta_ntp_internal_ms_; }; } // namespace videocapturemodule -} //namespace webrtc +} // namespace webrtc #endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_