video_capture_impl.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
  11. #define MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
  12. /*
  13. * video_capture_impl.h
  14. */
  15. #include <stddef.h>
  16. #include <stdint.h>
  17. #include "api/scoped_refptr.h"
  18. #include "api/video/video_frame.h"
  19. #include "api/video/video_rotation.h"
  20. #include "api/video/video_sink_interface.h"
  21. #include "modules/video_capture/video_capture.h"
  22. #include "modules/video_capture/video_capture_config.h"
  23. #include "modules/video_capture/video_capture_defines.h"
  24. #include "rtc_base/synchronization/mutex.h"
  25. namespace webrtc {
  26. namespace videocapturemodule {
  27. // Class definitions
  28. class VideoCaptureImpl : public VideoCaptureModule {
  29. public:
  30. /*
  31. * Create a video capture module object
  32. *
  33. * id - unique identifier of this video capture module object
  34. * deviceUniqueIdUTF8 - name of the device. Available names can be found by
  35. * using GetDeviceName
  36. */
  37. static rtc::scoped_refptr<VideoCaptureModule> Create(
  38. const char* deviceUniqueIdUTF8);
  39. static DeviceInfo* CreateDeviceInfo();
  40. // Helpers for converting between (integral) degrees and
  41. // VideoRotation values. Return 0 on success.
  42. static int32_t RotationFromDegrees(int degrees, VideoRotation* rotation);
  43. static int32_t RotationInDegrees(VideoRotation rotation, int* degrees);
  44. // Call backs
  45. void RegisterCaptureDataCallback(
  46. rtc::VideoSinkInterface<VideoFrame>* dataCallback) override;
  47. void DeRegisterCaptureDataCallback() override;
  48. int32_t SetCaptureRotation(VideoRotation rotation) override;
  49. bool SetApplyRotation(bool enable) override;
  50. bool GetApplyRotation() override;
  51. const char* CurrentDeviceName() const override;
  52. // |capture_time| must be specified in NTP time format in milliseconds.
  53. int32_t IncomingFrame(uint8_t* videoFrame,
  54. size_t videoFrameLength,
  55. const VideoCaptureCapability& frameInfo,
  56. int64_t captureTime = 0);
  57. // Platform dependent
  58. int32_t StartCapture(const VideoCaptureCapability& capability) override;
  59. int32_t StopCapture() override;
  60. bool CaptureStarted() override;
  61. int32_t CaptureSettings(VideoCaptureCapability& /*settings*/) override;
  62. protected:
  63. VideoCaptureImpl();
  64. ~VideoCaptureImpl() override;
  65. char* _deviceUniqueId; // current Device unique name;
  66. Mutex api_lock_;
  67. VideoCaptureCapability _requestedCapability; // Should be set by platform
  68. // dependent code in
  69. // StartCapture.
  70. private:
  71. void UpdateFrameCount();
  72. uint32_t CalculateFrameRate(int64_t now_ns);
  73. int32_t DeliverCapturedFrame(VideoFrame& captureFrame);
  74. // last time the module process function was called.
  75. int64_t _lastProcessTimeNanos;
  76. // last time the frame rate callback function was called.
  77. int64_t _lastFrameRateCallbackTimeNanos;
  78. rtc::VideoSinkInterface<VideoFrame>* _dataCallBack;
  79. int64_t _lastProcessFrameTimeNanos;
  80. // timestamp for local captured frames
  81. int64_t _incomingFrameTimesNanos[kFrameRateCountHistorySize];
  82. VideoRotation _rotateFrame; // Set if the frame should be rotated by the
  83. // capture module.
  84. // Indicate whether rotation should be applied before delivered externally.
  85. bool apply_rotation_;
  86. };
  87. } // namespace videocapturemodule
  88. } // namespace webrtc
  89. #endif // MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_