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