blob: d81adfd98d3b75a528cf832791c7f549f5d22641 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
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 WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_
12#define WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_
13
14#include <vector>
15
pbos@webrtc.org281cff82013-05-17 13:44:48 +000016#include "webrtc/common_types.h"
17#include "webrtc/engine_configurations.h"
andrew@webrtc.org5e8ee6f2012-10-30 21:58:00 +000018#include "webrtc/modules/video_capture/include/video_capture.h"
pbos@webrtc.org281cff82013-05-17 13:44:48 +000019#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/typedefs.h"
24#include "webrtc/video_engine/include/vie_capture.h"
25#include "webrtc/video_engine/vie_defines.h"
26#include "webrtc/video_engine/vie_frame_provider_base.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000027
28namespace webrtc {
29
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000030class Config;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000031class CriticalSectionWrapper;
32class EventWrapper;
33class ProcessThread;
34class ThreadWrapper;
35class ViEEffectFilter;
36class ViEEncoder;
37struct ViEPicture;
38
39class ViECapturer
40 : public ViEFrameProviderBase,
41 public ViEExternalCapture,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000042 protected VideoCaptureDataCallback,
mflodman@webrtc.orga18c6e52013-06-07 13:57:57 +000043 protected VideoCaptureFeedBack {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000044 public:
45 static ViECapturer* CreateViECapture(int capture_id,
46 int engine_id,
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000047 const Config& config,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000048 VideoCaptureModule* capture_module,
49 ProcessThread& module_process_thread);
50
51 static ViECapturer* CreateViECapture(
52 int capture_id,
53 int engine_id,
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000054 const Config& config,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000055 const char* device_unique_idUTF8,
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000056 uint32_t device_unique_idUTF8Length,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000057 ProcessThread& module_process_thread);
58
59 ~ViECapturer();
60
61 // Implements ViEFrameProviderBase.
62 int FrameCallbackChanged();
63 virtual int DeregisterFrameCallback(const ViEFrameCallback* callbackObject);
64 bool IsFrameCallbackRegistered(const ViEFrameCallback* callbackObject);
65
66 // Implements ExternalCapture.
67 virtual int IncomingFrame(unsigned char* video_frame,
68 unsigned int video_frame_length,
69 uint16_t width,
70 uint16_t height,
71 RawVideoType video_type,
72 unsigned long long capture_time = 0); // NOLINT
73
74 virtual int IncomingFrameI420(const ViEVideoFrameI420& video_frame,
75 unsigned long long capture_time = 0); // NOLINT
76
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000077 // Start/Stop.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000078 int32_t Start(
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000079 const CaptureCapability& capture_capability = CaptureCapability());
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000080 int32_t Stop();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000081 bool Started();
82
83 // Overrides the capture delay.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000084 int32_t SetCaptureDelay(int32_t delay_ms);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000085
86 // Sets rotation of the incoming captured frame.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000087 int32_t SetRotateCapturedFrames(const RotateCapturedFrame rotation);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000088
89 // Effect filter.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000090 int32_t RegisterEffectFilter(ViEEffectFilter* effect_filter);
91 int32_t EnableDenoising(bool enable);
92 int32_t EnableDeflickering(bool enable);
93 int32_t EnableBrightnessAlarm(bool enable);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000094
95 // Statistics observer.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +000096 int32_t RegisterObserver(ViECaptureObserver* observer);
97 int32_t DeRegisterObserver();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000098 bool IsObserverRegistered();
99
100 // Information.
101 const char* CurrentDeviceName() const;
102
103 protected:
104 ViECapturer(int capture_id,
105 int engine_id,
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +0000106 const Config& config,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000107 ProcessThread& module_process_thread);
108
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000109 int32_t Init(VideoCaptureModule* capture_module);
110 int32_t Init(const char* device_unique_idUTF8,
mflodman@webrtc.orga18c6e52013-06-07 13:57:57 +0000111 uint32_t device_unique_idUTF8Length);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000112
113 // Implements VideoCaptureDataCallback.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000114 virtual void OnIncomingCapturedFrame(const int32_t id,
mikhal@webrtc.org43b21822012-10-29 15:59:40 +0000115 I420VideoFrame& video_frame);
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000116 virtual void OnCaptureDelayChanged(const int32_t id,
117 const int32_t delay);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000118
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000119 // Returns true if the capture capability has been set in |StartCapture|
120 // function and may not be changed.
121 bool CaptureCapabilityFixed();
122
123 // Help function used for keeping track of VideoImageProcesingModule.
124 // Creates the module if it is needed, returns 0 on success and guarantees
125 // that the image proc module exist.
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000126 int32_t IncImageProcRefCount();
127 int32_t DecImageProcRefCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000128
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000129 // Implements VideoCaptureFeedBack
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000130 virtual void OnCaptureFrameRate(const int32_t id,
131 const uint32_t frame_rate);
132 virtual void OnNoPictureAlarm(const int32_t id,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000133 const VideoCaptureAlarm alarm);
134
135 // Thread functions for deliver captured frames to receivers.
136 static bool ViECaptureThreadFunction(void* obj);
137 bool ViECaptureProcess();
138
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +0000139 void DeliverI420Frame(I420VideoFrame* video_frame);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000140 void DeliverCodedFrame(VideoFrame* video_frame);
141
142 private:
143 // Never take capture_cs_ before deliver_cs_!
144 scoped_ptr<CriticalSectionWrapper> capture_cs_;
145 scoped_ptr<CriticalSectionWrapper> deliver_cs_;
146 VideoCaptureModule* capture_module_;
147 VideoCaptureExternal* external_capture_module_;
148 ProcessThread& module_process_thread_;
149 const int capture_id_;
150
151 // Capture thread.
152 ThreadWrapper& capture_thread_;
153 EventWrapper& capture_event_;
154 EventWrapper& deliver_event_;
155
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +0000156 I420VideoFrame captured_frame_;
157 I420VideoFrame deliver_frame_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000158
159 // Image processing.
160 ViEEffectFilter* effect_filter_;
161 VideoProcessingModule* image_proc_module_;
162 int image_proc_module_ref_counter_;
163 VideoProcessingModule::FrameStats* deflicker_frame_stats_;
164 VideoProcessingModule::FrameStats* brightness_frame_stats_;
165 Brightness current_brightness_level_;
166 Brightness reported_brightness_level_;
167 bool denoising_enabled_;
168
169 // Statistics observer.
170 scoped_ptr<CriticalSectionWrapper> observer_cs_;
171 ViECaptureObserver* observer_;
172
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000173 CaptureCapability requested_capability_;
174
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +0000175 I420VideoFrame capture_device_image_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000176};
177
178} // namespace webrtc
179
180#endif // WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_