Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; | 218 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; |
| 219 | 219 |
| 220 protected: | 220 protected: |
| 221 // OnSinkWantsChanged can be overridden to change the default behavior | 221 // OnSinkWantsChanged can be overridden to change the default behavior |
| 222 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink. | 222 // when a sink changes its VideoSinkWants by calling AddOrUpdateSink. |
| 223 virtual void OnSinkWantsChanged(const rtc::VideoSinkWants& wants); | 223 virtual void OnSinkWantsChanged(const rtc::VideoSinkWants& wants); |
| 224 | 224 |
| 225 // Reports the appropriate frame size after adaptation. Returns true | 225 // Reports the appropriate frame size after adaptation. Returns true |
| 226 // if a frame is wanted. Returns false if there are no interested | 226 // if a frame is wanted. Returns false if there are no interested |
| 227 // sinks, or if the VideoAdapter decides to drop the frame. | 227 // sinks, or if the VideoAdapter decides to drop the frame. |
| 228 | |
| 229 // This function also implements timestamp translation/filtering. | |
| 230 // |camera_time_ns| is the camera's timestamp for the captured | |
| 231 // frame; it is expected to have good accuracy, but it may use an | |
| 232 // arbitrary epoch and a small possibly free-running with a frequency | |
| 233 // slightly different from the system clock. |system_time_us| is the | |
| 234 // monotonic system time (in the same scale as rtc::TimeMicros) when | |
| 235 // the frame was captured; the application is expected to read the | |
| 236 // system time as soon as possible after frame capture, but it may | |
| 237 // suffer scheduling jitter or poor system clock resolution. The | |
| 238 // output |translated_camera_time_us| is a combined timestamp, | |
| 239 // taking advantage of the supposedly higher accuracy in the camera | |
| 240 // timestamp, but using the same epoch and frequency as system time. | |
| 228 bool AdaptFrame(int width, | 241 bool AdaptFrame(int width, |
| 229 int height, | 242 int height, |
| 230 int64_t capture_time_ns, | 243 int64_t camera_time_us, |
| 244 int64_t system_time_us, | |
| 231 int* out_width, | 245 int* out_width, |
| 232 int* out_height, | 246 int* out_height, |
| 233 int* crop_width, | 247 int* crop_width, |
| 234 int* crop_height, | 248 int* crop_height, |
| 235 int* crop_x, | 249 int* crop_x, |
| 236 int* crop_y); | 250 int* crop_y, |
| 251 int64_t* translated_camera_time_us); | |
| 237 | 252 |
| 238 // Callback attached to SignalFrameCaptured where SignalVideoFrames is called. | 253 // Callback attached to SignalFrameCaptured where SignalVideoFrames is called. |
| 239 void OnFrameCaptured(VideoCapturer* video_capturer, | 254 void OnFrameCaptured(VideoCapturer* video_capturer, |
| 240 const CapturedFrame* captured_frame); | 255 const CapturedFrame* captured_frame); |
| 241 | 256 |
| 242 // Called when a frame has been captured and converted to a | 257 // Called when a frame has been captured and converted to a |
| 243 // VideoFrame. OnFrame can be called directly by an implementation | 258 // VideoFrame. OnFrame can be called directly by an implementation |
| 244 // that does not use SignalFrameCaptured or OnFrameCaptured. The | 259 // that does not use SignalFrameCaptured or OnFrameCaptured. The |
| 245 // orig_width and orig_height are used only to produce stats. | 260 // orig_width and orig_height are used only to produce stats. |
| 246 void OnFrame(const VideoFrame& frame, int orig_width, int orig_height); | 261 void OnFrame(const VideoFrame& frame, int orig_width, int orig_height); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 258 id_ = id; | 273 id_ = id; |
| 259 } | 274 } |
| 260 | 275 |
| 261 void SetCaptureFormat(const VideoFormat* format) { | 276 void SetCaptureFormat(const VideoFormat* format) { |
| 262 capture_format_.reset(format ? new VideoFormat(*format) : NULL); | 277 capture_format_.reset(format ? new VideoFormat(*format) : NULL); |
| 263 } | 278 } |
| 264 | 279 |
| 265 void SetSupportedFormats(const std::vector<VideoFormat>& formats); | 280 void SetSupportedFormats(const std::vector<VideoFormat>& formats); |
| 266 VideoFrameFactory* frame_factory() { return frame_factory_.get(); } | 281 VideoFrameFactory* frame_factory() { return frame_factory_.get(); } |
| 267 | 282 |
| 283 protected: | |
| 284 // 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
| |
| 285 int64_t clip_bias_us() { return clip_bias_us_; } | |
| 286 | |
| 268 private: | 287 private: |
| 269 void Construct(); | 288 void Construct(); |
| 270 // Get the distance between the desired format and the supported format. | 289 // Get the distance between the desired format and the supported format. |
| 271 // Return the max distance if they mismatch. See the implementation for | 290 // Return the max distance if they mismatch. See the implementation for |
| 272 // details. | 291 // details. |
| 273 int64_t GetFormatDistance(const VideoFormat& desired, | 292 int64_t GetFormatDistance(const VideoFormat& desired, |
| 274 const VideoFormat& supported); | 293 const VideoFormat& supported); |
| 275 | 294 |
| 276 // Convert captured frame to readable string for LOG messages. | 295 // Convert captured frame to readable string for LOG messages. |
| 277 std::string ToString(const CapturedFrame* frame) const; | 296 std::string ToString(const CapturedFrame* frame) const; |
| 278 | 297 |
| 279 // Updates filtered_supported_formats_ so that it contains the formats in | 298 // Updates filtered_supported_formats_ so that it contains the formats in |
| 280 // supported_formats_ that fulfill all applied restrictions. | 299 // supported_formats_ that fulfill all applied restrictions. |
| 281 void UpdateFilteredSupportedFormats(); | 300 void UpdateFilteredSupportedFormats(); |
| 282 // Returns true if format doesn't fulfill all applied restrictions. | 301 // Returns true if format doesn't fulfill all applied restrictions. |
| 283 bool ShouldFilterFormat(const VideoFormat& format) const; | 302 bool ShouldFilterFormat(const VideoFormat& format) const; |
| 284 | 303 |
| 285 void UpdateInputSize(int width, int height); | 304 void UpdateInputSize(int width, int height); |
| 286 | 305 |
| 306 // Update the estimated offset between camera time and system monotonic time. | |
| 307 void UpdateOffset(int64_t camera_time_us, int64_t system_time_us); | |
| 308 | |
| 309 int64_t ClipTimestamp(int64_t filtered_time_us, int64_t system_time_us); | |
| 310 | |
| 287 rtc::ThreadChecker thread_checker_; | 311 rtc::ThreadChecker thread_checker_; |
| 288 std::string id_; | 312 std::string id_; |
| 289 CaptureState capture_state_; | 313 CaptureState capture_state_; |
| 290 std::unique_ptr<VideoFrameFactory> frame_factory_; | 314 std::unique_ptr<VideoFrameFactory> frame_factory_; |
| 291 std::unique_ptr<VideoFormat> capture_format_; | 315 std::unique_ptr<VideoFormat> capture_format_; |
| 292 std::vector<VideoFormat> supported_formats_; | 316 std::vector<VideoFormat> supported_formats_; |
| 293 std::unique_ptr<VideoFormat> max_format_; | 317 std::unique_ptr<VideoFormat> max_format_; |
| 294 std::vector<VideoFormat> filtered_supported_formats_; | 318 std::vector<VideoFormat> filtered_supported_formats_; |
| 295 | 319 |
| 296 bool enable_camera_list_; | 320 bool enable_camera_list_; |
| 297 int scaled_width_; // Current output size from ComputeScale. | 321 int scaled_width_; // Current output size from ComputeScale. |
| 298 int scaled_height_; | 322 int scaled_height_; |
| 299 | 323 |
| 300 rtc::VideoBroadcaster broadcaster_; | 324 rtc::VideoBroadcaster broadcaster_; |
| 301 bool enable_video_adapter_; | 325 bool enable_video_adapter_; |
| 302 VideoAdapter video_adapter_; | 326 VideoAdapter video_adapter_; |
| 303 | 327 |
| 304 rtc::CriticalSection frame_stats_crit_; | 328 rtc::CriticalSection frame_stats_crit_; |
| 305 // The captured frame size before potential adapation. | 329 // The captured frame size before potential adapation. |
| 306 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false; | 330 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false; |
| 307 int input_width_ GUARDED_BY(frame_stats_crit_); | 331 int input_width_ GUARDED_BY(frame_stats_crit_); |
| 308 int input_height_ GUARDED_BY(frame_stats_crit_); | 332 int input_height_ GUARDED_BY(frame_stats_crit_); |
| 309 | 333 |
| 310 // Whether capturer should apply rotation to the frame before signaling it. | 334 // Whether capturer should apply rotation to the frame before signaling it. |
| 311 bool apply_rotation_; | 335 bool apply_rotation_; |
| 312 | 336 |
| 337 // State for the timestamp translation. | |
| 338 int frames_seen_; | |
| 339 // Estimated offset between camera time and system monotonic time. | |
| 340 int64_t offset_us_; | |
| 341 | |
| 342 // State for timestamp clipping, applied after the filter, to ensure | |
| 343 // that translated timestamps are monotonic and not in the future. | |
| 344 // Subtracted from the translated timestamps. | |
| 345 int64_t clip_bias_us_; | |
| 346 rtc::Optional<int64_t> prev_translated_time_us_; | |
| 313 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); | 347 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); |
| 314 }; | 348 }; |
| 315 | 349 |
| 316 } // namespace cricket | 350 } // namespace cricket |
| 317 | 351 |
| 318 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ | 352 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ |
| OLD | NEW |