andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_ |
| 12 | #define WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_ |
| 13 | |
| 14 | #include <vector> |
| 15 | |
pbos@webrtc.org | 281cff8 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 16 | #include "webrtc/common_types.h" |
| 17 | #include "webrtc/engine_configurations.h" |
andrew@webrtc.org | 5e8ee6f | 2012-10-30 21:58:00 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/video_capture/include/video_capture.h" |
pbos@webrtc.org | 281cff8 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 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/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.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
| 29 | |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 30 | class Config; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 31 | class CriticalSectionWrapper; |
| 32 | class EventWrapper; |
| 33 | class ProcessThread; |
| 34 | class ThreadWrapper; |
| 35 | class ViEEffectFilter; |
| 36 | class ViEEncoder; |
| 37 | struct ViEPicture; |
| 38 | |
| 39 | class ViECapturer |
| 40 | : public ViEFrameProviderBase, |
| 41 | public ViEExternalCapture, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 42 | protected VideoCaptureDataCallback, |
mflodman@webrtc.org | a18c6e5 | 2013-06-07 13:57:57 +0000 | [diff] [blame] | 43 | protected VideoCaptureFeedBack { |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 44 | public: |
| 45 | static ViECapturer* CreateViECapture(int capture_id, |
| 46 | int engine_id, |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 47 | const Config& config, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 48 | VideoCaptureModule* capture_module, |
| 49 | ProcessThread& module_process_thread); |
| 50 | |
| 51 | static ViECapturer* CreateViECapture( |
| 52 | int capture_id, |
| 53 | int engine_id, |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 54 | const Config& config, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 55 | const char* device_unique_idUTF8, |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 56 | uint32_t device_unique_idUTF8Length, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 57 | 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.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 77 | // Start/Stop. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 78 | int32_t Start( |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 79 | const CaptureCapability& capture_capability = CaptureCapability()); |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 80 | int32_t Stop(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 81 | bool Started(); |
| 82 | |
| 83 | // Overrides the capture delay. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 84 | int32_t SetCaptureDelay(int32_t delay_ms); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 85 | |
| 86 | // Sets rotation of the incoming captured frame. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 87 | int32_t SetRotateCapturedFrames(const RotateCapturedFrame rotation); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 88 | |
| 89 | // Effect filter. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 90 | 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.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 94 | |
| 95 | // Statistics observer. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 96 | int32_t RegisterObserver(ViECaptureObserver* observer); |
| 97 | int32_t DeRegisterObserver(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 98 | bool IsObserverRegistered(); |
| 99 | |
| 100 | // Information. |
| 101 | const char* CurrentDeviceName() const; |
| 102 | |
| 103 | protected: |
| 104 | ViECapturer(int capture_id, |
| 105 | int engine_id, |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 106 | const Config& config, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 107 | ProcessThread& module_process_thread); |
| 108 | |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 109 | int32_t Init(VideoCaptureModule* capture_module); |
| 110 | int32_t Init(const char* device_unique_idUTF8, |
mflodman@webrtc.org | a18c6e5 | 2013-06-07 13:57:57 +0000 | [diff] [blame] | 111 | uint32_t device_unique_idUTF8Length); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 112 | |
| 113 | // Implements VideoCaptureDataCallback. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 114 | virtual void OnIncomingCapturedFrame(const int32_t id, |
mikhal@webrtc.org | 43b2182 | 2012-10-29 15:59:40 +0000 | [diff] [blame] | 115 | I420VideoFrame& video_frame); |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 116 | virtual void OnCaptureDelayChanged(const int32_t id, |
| 117 | const int32_t delay); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 118 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 119 | // 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.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 126 | int32_t IncImageProcRefCount(); |
| 127 | int32_t DecImageProcRefCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 128 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 129 | // Implements VideoCaptureFeedBack |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 130 | virtual void OnCaptureFrameRate(const int32_t id, |
| 131 | const uint32_t frame_rate); |
| 132 | virtual void OnNoPictureAlarm(const int32_t id, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 133 | 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.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 139 | void DeliverI420Frame(I420VideoFrame* video_frame); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 140 | 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.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 156 | I420VideoFrame captured_frame_; |
| 157 | I420VideoFrame deliver_frame_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 158 | |
| 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.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 173 | CaptureCapability requested_capability_; |
| 174 | |
mikhal@webrtc.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 175 | I420VideoFrame capture_device_image_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | } // namespace webrtc |
| 179 | |
| 180 | #endif // WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_ |