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_VIDEO_ENGINE_VIE_CAPTURER_H_
12 #define WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_
16 #include "webrtc/common_types.h"
17 #include "webrtc/engine_configurations.h"
18 #include "webrtc/modules/video_capture/include/video_capture.h"
19 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
20 #include "webrtc/modules/video_coding/main/interface/video_coding.h"
21 #include "webrtc/modules/video_processing/main/interface/video_processing.h"
22 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
23 #include "webrtc/system_wrappers/interface/thread_annotations.h"
24 #include "webrtc/typedefs.h"
25 #include "webrtc/video_engine/include/vie_capture.h"
26 #include "webrtc/video_engine/vie_defines.h"
27 #include "webrtc/video_engine/vie_frame_provider_base.h"
32 class CriticalSectionWrapper;
34 class CpuOveruseObserver;
35 class OveruseFrameDetector;
38 class ViEEffectFilter;
43 : public ViEFrameProviderBase,
44 public ViEExternalCapture,
45 protected VideoCaptureDataCallback,
46 protected VideoCaptureFeedBack {
48 static ViECapturer* CreateViECapture(int capture_id,
51 VideoCaptureModule* capture_module,
52 ProcessThread& module_process_thread);
54 static ViECapturer* CreateViECapture(
58 const char* device_unique_idUTF8,
59 uint32_t device_unique_idUTF8Length,
60 ProcessThread& module_process_thread);
64 // Implements ViEFrameProviderBase.
65 int FrameCallbackChanged();
66 virtual int DeregisterFrameCallback(const ViEFrameCallback* callbackObject);
67 bool IsFrameCallbackRegistered(const ViEFrameCallback* callbackObject);
69 // Implements ExternalCapture.
70 virtual int IncomingFrame(unsigned char* video_frame,
71 unsigned int video_frame_length,
74 RawVideoType video_type,
75 unsigned long long capture_time = 0); // NOLINT
77 virtual int IncomingFrameI420(const ViEVideoFrameI420& video_frame,
78 unsigned long long capture_time = 0); // NOLINT
80 virtual void SwapFrame(I420VideoFrame* frame) OVERRIDE;
84 const CaptureCapability& capture_capability = CaptureCapability());
88 // Overrides the capture delay.
89 int32_t SetCaptureDelay(int32_t delay_ms);
91 // Sets rotation of the incoming captured frame.
92 int32_t SetRotateCapturedFrames(const RotateCapturedFrame rotation);
95 int32_t RegisterEffectFilter(ViEEffectFilter* effect_filter);
96 int32_t EnableDenoising(bool enable);
97 int32_t EnableDeflickering(bool enable);
98 int32_t EnableBrightnessAlarm(bool enable);
100 // Statistics observer.
101 int32_t RegisterObserver(ViECaptureObserver* observer);
102 int32_t DeRegisterObserver();
103 bool IsObserverRegistered();
106 const char* CurrentDeviceName() const;
108 void RegisterCpuOveruseObserver(CpuOveruseObserver* observer);
110 void CpuOveruseMeasures(int* capture_jitter_ms,
111 int* avg_encode_time_ms,
112 int* encode_usage_percent,
113 int* capture_queue_delay_ms_per_s) const;
116 ViECapturer(int capture_id,
118 const Config& config,
119 ProcessThread& module_process_thread);
121 int32_t Init(VideoCaptureModule* capture_module);
122 int32_t Init(const char* device_unique_idUTF8,
123 uint32_t device_unique_idUTF8Length);
125 // Implements VideoCaptureDataCallback.
126 virtual void OnIncomingCapturedFrame(const int32_t id,
127 I420VideoFrame& video_frame);
128 virtual void OnCaptureDelayChanged(const int32_t id,
129 const int32_t delay);
131 // Returns true if the capture capability has been set in |StartCapture|
132 // function and may not be changed.
133 bool CaptureCapabilityFixed();
135 // Help function used for keeping track of VideoImageProcesingModule.
136 // Creates the module if it is needed, returns 0 on success and guarantees
137 // that the image proc module exist.
138 int32_t IncImageProcRefCount();
139 int32_t DecImageProcRefCount();
141 // Implements VideoCaptureFeedBack
142 virtual void OnCaptureFrameRate(const int32_t id,
143 const uint32_t frame_rate);
144 virtual void OnNoPictureAlarm(const int32_t id,
145 const VideoCaptureAlarm alarm);
147 // Thread functions for deliver captured frames to receivers.
148 static bool ViECaptureThreadFunction(void* obj);
149 bool ViECaptureProcess();
151 void DeliverI420Frame(I420VideoFrame* video_frame);
152 void DeliverCodedFrame(VideoFrame* video_frame);
155 bool SwapCapturedAndDeliverFrameIfAvailable();
157 // Never take capture_cs_ before deliver_cs_!
158 scoped_ptr<CriticalSectionWrapper> capture_cs_;
159 scoped_ptr<CriticalSectionWrapper> deliver_cs_;
160 VideoCaptureModule* capture_module_;
161 VideoCaptureExternal* external_capture_module_;
162 ProcessThread& module_process_thread_;
163 const int capture_id_;
165 // Frame used in IncomingFrameI420.
166 scoped_ptr<CriticalSectionWrapper> incoming_frame_cs_;
167 I420VideoFrame incoming_frame_;
170 ThreadWrapper& capture_thread_;
171 EventWrapper& capture_event_;
172 EventWrapper& deliver_event_;
174 I420VideoFrame captured_frame_;
175 I420VideoFrame deliver_frame_;
178 ViEEffectFilter* effect_filter_;
179 VideoProcessingModule* image_proc_module_;
180 int image_proc_module_ref_counter_;
181 VideoProcessingModule::FrameStats* deflicker_frame_stats_;
182 VideoProcessingModule::FrameStats* brightness_frame_stats_;
183 Brightness current_brightness_level_;
184 Brightness reported_brightness_level_;
185 bool denoising_enabled_;
187 // Statistics observer.
188 scoped_ptr<CriticalSectionWrapper> observer_cs_;
189 ViECaptureObserver* observer_ GUARDED_BY(observer_cs_.get());
191 CaptureCapability requested_capability_;
193 scoped_ptr<OveruseFrameDetector> overuse_detector_;
196 } // namespace webrtc
198 #endif // WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_