| 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 30 matching lines...) Expand all Loading... |
| 277 std::string ToString(const CapturedFrame* frame) const; | 292 std::string ToString(const CapturedFrame* frame) const; |
| 278 | 293 |
| 279 // Updates filtered_supported_formats_ so that it contains the formats in | 294 // Updates filtered_supported_formats_ so that it contains the formats in |
| 280 // supported_formats_ that fulfill all applied restrictions. | 295 // supported_formats_ that fulfill all applied restrictions. |
| 281 void UpdateFilteredSupportedFormats(); | 296 void UpdateFilteredSupportedFormats(); |
| 282 // Returns true if format doesn't fulfill all applied restrictions. | 297 // Returns true if format doesn't fulfill all applied restrictions. |
| 283 bool ShouldFilterFormat(const VideoFormat& format) const; | 298 bool ShouldFilterFormat(const VideoFormat& format) const; |
| 284 | 299 |
| 285 void UpdateInputSize(int width, int height); | 300 void UpdateInputSize(int width, int height); |
| 286 | 301 |
| 302 // Update the estimated offset between camera time and system monotonic time. |
| 303 void UpdateOffset(int64_t camera_time_us, int64_t system_time_us); |
| 304 |
| 287 rtc::ThreadChecker thread_checker_; | 305 rtc::ThreadChecker thread_checker_; |
| 288 std::string id_; | 306 std::string id_; |
| 289 CaptureState capture_state_; | 307 CaptureState capture_state_; |
| 290 std::unique_ptr<VideoFrameFactory> frame_factory_; | 308 std::unique_ptr<VideoFrameFactory> frame_factory_; |
| 291 std::unique_ptr<VideoFormat> capture_format_; | 309 std::unique_ptr<VideoFormat> capture_format_; |
| 292 std::vector<VideoFormat> supported_formats_; | 310 std::vector<VideoFormat> supported_formats_; |
| 293 std::unique_ptr<VideoFormat> max_format_; | 311 std::unique_ptr<VideoFormat> max_format_; |
| 294 std::vector<VideoFormat> filtered_supported_formats_; | 312 std::vector<VideoFormat> filtered_supported_formats_; |
| 295 | 313 |
| 296 bool enable_camera_list_; | 314 bool enable_camera_list_; |
| 297 int scaled_width_; // Current output size from ComputeScale. | 315 int scaled_width_; // Current output size from ComputeScale. |
| 298 int scaled_height_; | 316 int scaled_height_; |
| 299 | 317 |
| 300 rtc::VideoBroadcaster broadcaster_; | 318 rtc::VideoBroadcaster broadcaster_; |
| 301 bool enable_video_adapter_; | 319 bool enable_video_adapter_; |
| 302 VideoAdapter video_adapter_; | 320 VideoAdapter video_adapter_; |
| 303 | 321 |
| 304 rtc::CriticalSection frame_stats_crit_; | 322 rtc::CriticalSection frame_stats_crit_; |
| 305 // The captured frame size before potential adapation. | 323 // The captured frame size before potential adapation. |
| 306 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false; | 324 bool input_size_valid_ GUARDED_BY(frame_stats_crit_) = false; |
| 307 int input_width_ GUARDED_BY(frame_stats_crit_); | 325 int input_width_ GUARDED_BY(frame_stats_crit_); |
| 308 int input_height_ GUARDED_BY(frame_stats_crit_); | 326 int input_height_ GUARDED_BY(frame_stats_crit_); |
| 309 | 327 |
| 310 // Whether capturer should apply rotation to the frame before signaling it. | 328 // Whether capturer should apply rotation to the frame before signaling it. |
| 311 bool apply_rotation_; | 329 bool apply_rotation_; |
| 312 | 330 |
| 331 // State for the timestamp translation. |
| 332 int frames_seen_; |
| 333 // Previous camera time seen, used to detect jumps in camera time. |
| 334 int64_t prev_camera_time_us_; |
| 335 // Estimated offset between camera time and system monotonic time. |
| 336 int64_t offset_us_; |
| 337 |
| 313 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); | 338 RTC_DISALLOW_COPY_AND_ASSIGN(VideoCapturer); |
| 314 }; | 339 }; |
| 315 | 340 |
| 316 } // namespace cricket | 341 } // namespace cricket |
| 317 | 342 |
| 318 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ | 343 #endif // WEBRTC_MEDIA_BASE_VIDEOCAPTURER_H_ |
| OLD | NEW |