2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
12 #define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
15 * video_capture_impl.h
18 #include "webrtc/common_video/interface/i420_video_frame.h"
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
20 #include "webrtc/modules/video_capture/include/video_capture.h"
21 #include "webrtc/modules/video_capture/video_capture_config.h"
22 #include "webrtc/system_wrappers/interface/tick_util.h"
26 class CriticalSectionWrapper;
28 namespace videocapturemodule {
30 class VideoCaptureImpl: public VideoCaptureModule, public VideoCaptureExternal
35 * Create a video capture module object
37 * id - unique identifier of this video capture module object
38 * deviceUniqueIdUTF8 - name of the device. Available names can be found by using GetDeviceName
40 static VideoCaptureModule* Create(const int32_t id,
41 const char* deviceUniqueIdUTF8);
44 * Create a video capture module object used for external capture.
46 * id - unique identifier of this video capture module object
47 * externalCapture - [out] interface to call when a new frame is captured.
49 static VideoCaptureModule* Create(const int32_t id,
50 VideoCaptureExternal*& externalCapture);
52 static DeviceInfo* CreateDeviceInfo(const int32_t id);
54 // Helpers for converting between (integral) degrees and
55 // VideoCaptureRotation values. Return 0 on success.
56 static int32_t RotationFromDegrees(int degrees,
57 VideoCaptureRotation* rotation);
58 static int32_t RotationInDegrees(VideoCaptureRotation rotation,
61 // Implements Module declared functions.
62 virtual int32_t ChangeUniqueId(const int32_t id);
65 virtual void RegisterCaptureDataCallback(
66 VideoCaptureDataCallback& dataCallback);
67 virtual void DeRegisterCaptureDataCallback();
68 virtual void RegisterCaptureCallback(VideoCaptureFeedBack& callBack);
69 virtual void DeRegisterCaptureCallback();
71 virtual void SetCaptureDelay(int32_t delayMS);
72 virtual int32_t CaptureDelay();
73 virtual int32_t SetCaptureRotation(VideoCaptureRotation rotation);
75 virtual void EnableFrameRateCallback(const bool enable);
76 virtual void EnableNoPictureAlarm(const bool enable);
78 virtual const char* CurrentDeviceName() const;
81 virtual int32_t TimeUntilNextProcess();
82 virtual int32_t Process();
84 // Implement VideoCaptureExternal
85 // |capture_time| must be specified in the NTP time format in milliseconds.
86 virtual int32_t IncomingFrame(uint8_t* videoFrame,
87 int32_t videoFrameLength,
88 const VideoCaptureCapability& frameInfo,
89 int64_t captureTime = 0);
91 virtual int32_t IncomingI420VideoFrame(I420VideoFrame* video_frame,
92 int64_t captureTime = 0);
95 virtual int32_t StartCapture(const VideoCaptureCapability& capability)
97 _requestedCapability = capability;
100 virtual int32_t StopCapture() { return -1; }
101 virtual bool CaptureStarted() {return false; }
102 virtual int32_t CaptureSettings(VideoCaptureCapability& /*settings*/)
104 VideoCaptureEncodeInterface* GetEncodeInterface(const VideoCodec& /*codec*/)
108 VideoCaptureImpl(const int32_t id);
109 virtual ~VideoCaptureImpl();
110 int32_t DeliverCapturedFrame(I420VideoFrame& captureFrame,
111 int64_t capture_time);
113 int32_t _id; // Module ID
114 char* _deviceUniqueId; // current Device unique name;
115 CriticalSectionWrapper& _apiCs;
116 int32_t _captureDelay; // Current capture delay. May be changed of platform dependent parts.
117 VideoCaptureCapability _requestedCapability; // Should be set by platform dependent code in StartCapture.
119 void UpdateFrameCount();
120 uint32_t CalculateFrameRate(const TickTime& now);
122 CriticalSectionWrapper& _callBackCs;
124 TickTime _lastProcessTime; // last time the module process function was called.
125 TickTime _lastFrameRateCallbackTime; // last time the frame rate callback function was called.
126 bool _frameRateCallBack; // true if EnableFrameRateCallback
127 bool _noPictureAlarmCallBack; //true if EnableNoPictureAlarm
128 VideoCaptureAlarm _captureAlarm; // current value of the noPictureAlarm
130 int32_t _setCaptureDelay; // The currently used capture delay
131 VideoCaptureDataCallback* _dataCallBack;
132 VideoCaptureFeedBack* _captureCallBack;
134 TickTime _lastProcessFrameCount;
135 TickTime _incomingFrameTimes[kFrameRateCountHistorySize];// timestamp for local captured frames
136 VideoRotationMode _rotateFrame; //Set if the frame should be rotated by the capture module.
138 I420VideoFrame _captureFrame;
139 VideoFrame _capture_encoded_frame;
141 // Used to make sure incoming timestamp is increasing for every frame.
142 int64_t last_capture_time_;
144 // Delta used for translating between NTP and internal timestamps.
145 const int64_t delta_ntp_internal_ms_;
147 } // namespace videocapturemodule
148 } // namespace webrtc
149 #endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_