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/base/thread_annotations.h"
17 #include "webrtc/common_types.h"
18 #include "webrtc/engine_configurations.h"
19 #include "webrtc/modules/video_capture/include/video_capture.h"
20 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
21 #include "webrtc/modules/video_coding/main/interface/video_coding.h"
22 #include "webrtc/modules/video_processing/main/interface/video_processing.h"
23 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
24 #include "webrtc/typedefs.h"
25 #include "webrtc/video_engine/include/vie_base.h"
26 #include "webrtc/video_engine/include/vie_capture.h"
27 #include "webrtc/video_engine/vie_defines.h"
28 #include "webrtc/video_engine/vie_frame_provider_base.h"
33 class CriticalSectionWrapper;
35 class CpuOveruseObserver;
36 class OveruseFrameDetector;
39 class ViEEffectFilter;
44 : public ViEFrameProviderBase,
45 public ViEExternalCapture,
46 protected VideoCaptureDataCallback,
47 protected VideoCaptureFeedBack {
49 static ViECapturer* CreateViECapture(int capture_id,
52 VideoCaptureModule* capture_module,
53 ProcessThread& module_process_thread);
55 static ViECapturer* CreateViECapture(
59 const char* device_unique_idUTF8,
60 uint32_t device_unique_idUTF8Length,
61 ProcessThread& module_process_thread);
65 // Implements ViEFrameProviderBase.
66 int FrameCallbackChanged();
67 virtual int DeregisterFrameCallback(const ViEFrameCallback* callbackObject);
68 bool IsFrameCallbackRegistered(const ViEFrameCallback* callbackObject);
70 // Implements ExternalCapture.
71 virtual int IncomingFrame(unsigned char* video_frame,
72 unsigned int video_frame_length,
75 RawVideoType video_type,
76 unsigned long long capture_time = 0); // NOLINT
78 virtual int IncomingFrameI420(const ViEVideoFrameI420& video_frame,
79 unsigned long long capture_time = 0); // NOLINT
81 virtual void SwapFrame(I420VideoFrame* frame) OVERRIDE;
85 const CaptureCapability& capture_capability = CaptureCapability());
89 // Overrides the capture delay.
90 int32_t SetCaptureDelay(int32_t delay_ms);
92 // Sets rotation of the incoming captured frame.
93 int32_t SetRotateCapturedFrames(const RotateCapturedFrame rotation);
96 int32_t RegisterEffectFilter(ViEEffectFilter* effect_filter);
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);
109 void SetCpuOveruseOptions(const CpuOveruseOptions& options);
110 void GetCpuOveruseMetrics(CpuOveruseMetrics* metrics) const;
113 ViECapturer(int capture_id,
115 const Config& config,
116 ProcessThread& module_process_thread);
118 int32_t Init(VideoCaptureModule* capture_module);
119 int32_t Init(const char* device_unique_idUTF8,
120 uint32_t device_unique_idUTF8Length);
122 // Implements VideoCaptureDataCallback.
123 virtual void OnIncomingCapturedFrame(const int32_t id,
124 I420VideoFrame& video_frame);
125 virtual void OnCaptureDelayChanged(const int32_t id,
126 const int32_t delay);
128 // Returns true if the capture capability has been set in |StartCapture|
129 // function and may not be changed.
130 bool CaptureCapabilityFixed();
132 // Help function used for keeping track of VideoImageProcesingModule.
133 // Creates the module if it is needed, returns 0 on success and guarantees
134 // that the image proc module exist.
135 int32_t IncImageProcRefCount();
136 int32_t DecImageProcRefCount();
138 // Implements VideoCaptureFeedBack
139 virtual void OnCaptureFrameRate(const int32_t id,
140 const uint32_t frame_rate);
141 virtual void OnNoPictureAlarm(const int32_t id,
142 const VideoCaptureAlarm alarm);
144 // Thread functions for deliver captured frames to receivers.
145 static bool ViECaptureThreadFunction(void* obj);
146 bool ViECaptureProcess();
148 void DeliverI420Frame(I420VideoFrame* video_frame);
149 void DeliverCodedFrame(VideoFrame* video_frame);
152 bool SwapCapturedAndDeliverFrameIfAvailable();
154 // Never take capture_cs_ before deliver_cs_!
155 scoped_ptr<CriticalSectionWrapper> capture_cs_;
156 scoped_ptr<CriticalSectionWrapper> deliver_cs_;
157 VideoCaptureModule* capture_module_;
158 VideoCaptureExternal* external_capture_module_;
159 ProcessThread& module_process_thread_;
160 const int capture_id_;
162 // Frame used in IncomingFrameI420.
163 scoped_ptr<CriticalSectionWrapper> incoming_frame_cs_;
164 I420VideoFrame incoming_frame_;
167 ThreadWrapper& capture_thread_;
168 EventWrapper& capture_event_;
169 EventWrapper& deliver_event_;
171 scoped_ptr<I420VideoFrame> captured_frame_;
172 scoped_ptr<I420VideoFrame> deliver_frame_;
175 ViEEffectFilter* effect_filter_;
176 VideoProcessingModule* image_proc_module_;
177 int image_proc_module_ref_counter_;
178 VideoProcessingModule::FrameStats* deflicker_frame_stats_;
179 VideoProcessingModule::FrameStats* brightness_frame_stats_;
180 Brightness current_brightness_level_;
181 Brightness reported_brightness_level_;
183 // Statistics observer.
184 scoped_ptr<CriticalSectionWrapper> observer_cs_;
185 ViECaptureObserver* observer_ GUARDED_BY(observer_cs_.get());
187 CaptureCapability requested_capability_;
189 scoped_ptr<OveruseFrameDetector> overuse_detector_;
192 } // namespace webrtc
194 #endif // WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_