Index: webrtc/media/base/videocapturer.h |
diff --git a/webrtc/media/base/videocapturer.h b/webrtc/media/base/videocapturer.h |
index 329ba086b90dfe1139c6f83cdd41b291af38540f..5cc4d6b7c43cc2e146b9710894f029a8f899f533 100644 |
--- a/webrtc/media/base/videocapturer.h |
+++ b/webrtc/media/base/videocapturer.h |
@@ -225,15 +225,30 @@ class VideoCapturer : public sigslot::has_slots<>, |
// Reports the appropriate frame size after adaptation. Returns true |
// if a frame is wanted. Returns false if there are no interested |
// sinks, or if the VideoAdapter decides to drop the frame. |
+ |
+ // This function also implements timestamp translation/filtering. |
+ // |camera_time_ns| is the camera's timestamp for the captured |
+ // frame; it is expected to have good accuracy, but it may use an |
+ // arbitrary epoch and a small possibly free-running with a frequency |
+ // slightly different from the system clock. |system_time_us| is the |
+ // monotonic system time (in the same scale as rtc::TimeMicros) when |
+ // the frame was captured; the application is expected to read the |
+ // system time as soon as possible after frame capture, but it may |
+ // suffer scheduling jitter or poor system clock resolution. The |
+ // output |translated_camera_time_us| is a combined timestamp, |
+ // taking advantage of the supposedly higher accuracy in the camera |
+ // timestamp, but using the same epoch and frequency as system time. |
bool AdaptFrame(int width, |
int height, |
- int64_t capture_time_ns, |
+ int64_t camera_time_us, |
+ int64_t system_time_us, |
int* out_width, |
int* out_height, |
int* crop_width, |
int* crop_height, |
int* crop_x, |
- int* crop_y); |
+ int* crop_y, |
+ int64_t* translated_camera_time_us); |
// Callback attached to SignalFrameCaptured where SignalVideoFrames is called. |
void OnFrameCaptured(VideoCapturer* video_capturer, |
@@ -265,6 +280,10 @@ class VideoCapturer : public sigslot::has_slots<>, |
void SetSupportedFormats(const std::vector<VideoFormat>& formats); |
VideoFrameFactory* frame_factory() { return frame_factory_.get(); } |
+ protected: |
+ // Access intended only for testing. |
sprang_webrtc
2016/06/17 13:10:52
Can't we use friend class to expose this instead,
nisse-webrtc
2016/06/17 13:43:01
I have no strong opinion on that (and not much exp
sprang_webrtc
2016/06/17 14:35:38
Friend class isn't pretty, but exposing and commen
|
+ int64_t clip_bias_us() { return clip_bias_us_; } |
+ |
private: |
void Construct(); |
// Get the distance between the desired format and the supported format. |
@@ -284,6 +303,11 @@ class VideoCapturer : public sigslot::has_slots<>, |
void UpdateInputSize(int width, int height); |
+ // Update the estimated offset between camera time and system monotonic time. |
+ void UpdateOffset(int64_t camera_time_us, int64_t system_time_us); |
+ |
+ int64_t ClipTimestamp(int64_t filtered_time_us, int64_t system_time_us); |
+ |
rtc::ThreadChecker thread_checker_; |
std::string id_; |
CaptureState capture_state_; |
@@ -310,6 +334,16 @@ class VideoCapturer : public sigslot::has_slots<>, |
// Whether capturer should apply rotation to the frame before signaling it. |
bool apply_rotation_; |
+ // State for the timestamp translation. |
+ int frames_seen_; |
+ // Estimated offset between camera time and system monotonic time. |
+ int64_t offset_us_; |
+ |
+ // State for timestamp clipping, applied after the filter, to ensure |
+ // that translated timestamps are monotonic and not in the future. |
+ // Subtracted from the translated timestamps. |
+ int64_t clip_bias_us_; |
+ rtc::Optional<int64_t> prev_translated_time_us_; |
RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); |
}; |