video_capture_input.h revision 7707d060bb2fcceae1ed4118ebac29de577e209b
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 16#include "common_types.h" // NOLINT 17#include "engine_configurations.h" // NOLINT 18#include "webrtc/modules/video_capture/include/video_capture.h" 19#include "modules/video_coding/codecs/interface/video_codec_interface.h" 20#include "modules/video_coding/main/interface/video_coding.h" 21#include "modules/video_processing/main/interface/video_processing.h" 22#include "system_wrappers/interface/scoped_ptr.h" 23#include "typedefs.h" // NOLINT 24#include "video_engine/include/vie_capture.h" 25#include "video_engine/vie_defines.h" 26#include "video_engine/vie_frame_provider_base.h" 27 28namespace webrtc { 29 30class Config; 31class CriticalSectionWrapper; 32class EventWrapper; 33class ProcessThread; 34class ThreadWrapper; 35class ViEEffectFilter; 36class ViEEncoder; 37struct ViEPicture; 38 39class ViECapturer 40 : public ViEFrameProviderBase, 41 public ViEExternalCapture, 42 protected VCMReceiveCallback, 43 protected VideoCaptureDataCallback, 44 protected VideoCaptureFeedBack, 45 protected VideoEncoder { 46 public: 47 static ViECapturer* CreateViECapture(int capture_id, 48 int engine_id, 49 const Config& config, 50 VideoCaptureModule* capture_module, 51 ProcessThread& module_process_thread); 52 53 static ViECapturer* CreateViECapture( 54 int capture_id, 55 int engine_id, 56 const Config& config, 57 const char* device_unique_idUTF8, 58 uint32_t device_unique_idUTF8Length, 59 ProcessThread& module_process_thread); 60 61 ~ViECapturer(); 62 63 // Implements ViEFrameProviderBase. 64 int FrameCallbackChanged(); 65 virtual int DeregisterFrameCallback(const ViEFrameCallback* callbackObject); 66 bool IsFrameCallbackRegistered(const ViEFrameCallback* callbackObject); 67 68 // Implements ExternalCapture. 69 virtual int IncomingFrame(unsigned char* video_frame, 70 unsigned int video_frame_length, 71 uint16_t width, 72 uint16_t height, 73 RawVideoType video_type, 74 unsigned long long capture_time = 0); // NOLINT 75 76 virtual int IncomingFrameI420(const ViEVideoFrameI420& video_frame, 77 unsigned long long capture_time = 0); // NOLINT 78 79 // Use this capture device as encoder. 80 // Returns 0 if the codec is supported by this capture device. 81 virtual int32_t PreEncodeToViEEncoder(const VideoCodec& codec, 82 ViEEncoder& vie_encoder, 83 int32_t vie_encoder_id); 84 85 // Start/Stop. 86 int32_t Start( 87 const CaptureCapability& capture_capability = CaptureCapability()); 88 int32_t Stop(); 89 bool Started(); 90 91 // Overrides the capture delay. 92 int32_t SetCaptureDelay(int32_t delay_ms); 93 94 // Sets rotation of the incoming captured frame. 95 int32_t SetRotateCapturedFrames(const RotateCapturedFrame rotation); 96 97 // Effect filter. 98 int32_t RegisterEffectFilter(ViEEffectFilter* effect_filter); 99 int32_t EnableDenoising(bool enable); 100 int32_t EnableDeflickering(bool enable); 101 int32_t EnableBrightnessAlarm(bool enable); 102 103 // Statistics observer. 104 int32_t RegisterObserver(ViECaptureObserver* observer); 105 int32_t DeRegisterObserver(); 106 bool IsObserverRegistered(); 107 108 // Information. 109 const char* CurrentDeviceName() const; 110 111 protected: 112 ViECapturer(int capture_id, 113 int engine_id, 114 const Config& config, 115 ProcessThread& module_process_thread); 116 117 int32_t Init(VideoCaptureModule* capture_module); 118 int32_t Init(const char* device_unique_idUTF8, 119 const uint32_t device_unique_idUTF8Length); 120 121 // Implements VideoCaptureDataCallback. 122 virtual void OnIncomingCapturedFrame(const int32_t id, 123 I420VideoFrame& video_frame); 124 virtual void OnIncomingCapturedEncodedFrame(const int32_t capture_id, 125 VideoFrame& video_frame, 126 VideoCodecType codec_type); 127 virtual void OnCaptureDelayChanged(const int32_t id, 128 const int32_t delay); 129 130 bool EncoderActive(); 131 132 // Returns true if the capture capability has been set in |StartCapture| 133 // function and may not be changed. 134 bool CaptureCapabilityFixed(); 135 136 // Help function used for keeping track of VideoImageProcesingModule. 137 // Creates the module if it is needed, returns 0 on success and guarantees 138 // that the image proc module exist. 139 int32_t IncImageProcRefCount(); 140 int32_t DecImageProcRefCount(); 141 142 // Implements VideoEncoder. 143 virtual int32_t Version(char* version, int32_t length) const; 144 virtual int32_t InitEncode(const VideoCodec* codec_settings, 145 int32_t number_of_cores, 146 uint32_t max_payload_size); 147 virtual int32_t Encode(const I420VideoFrame& input_image, 148 const CodecSpecificInfo* codec_specific_info, 149 const std::vector<VideoFrameType>* frame_types); 150 virtual int32_t RegisterEncodeCompleteCallback( 151 EncodedImageCallback* callback); 152 virtual int32_t Release(); 153 virtual int32_t Reset(); 154 virtual int32_t SetChannelParameters(uint32_t packet_loss, int rtt); 155 virtual int32_t SetRates(uint32_t new_bit_rate, uint32_t frame_rate); 156 157 // Implements VCMReceiveCallback. 158 // TODO(mflodman) Change input argument to pointer. 159 virtual int32_t FrameToRender(I420VideoFrame& video_frame); // NOLINT 160 161 // Implements VideoCaptureFeedBack 162 virtual void OnCaptureFrameRate(const int32_t id, 163 const uint32_t frame_rate); 164 virtual void OnNoPictureAlarm(const int32_t id, 165 const VideoCaptureAlarm alarm); 166 167 // Thread functions for deliver captured frames to receivers. 168 static bool ViECaptureThreadFunction(void* obj); 169 bool ViECaptureProcess(); 170 171 void DeliverI420Frame(I420VideoFrame* video_frame); 172 void DeliverCodedFrame(VideoFrame* video_frame); 173 174 private: 175 // Never take capture_cs_ before deliver_cs_! 176 scoped_ptr<CriticalSectionWrapper> capture_cs_; 177 scoped_ptr<CriticalSectionWrapper> deliver_cs_; 178 VideoCaptureModule* capture_module_; 179 VideoCaptureExternal* external_capture_module_; 180 ProcessThread& module_process_thread_; 181 const int capture_id_; 182 183 // Capture thread. 184 ThreadWrapper& capture_thread_; 185 EventWrapper& capture_event_; 186 EventWrapper& deliver_event_; 187 188 I420VideoFrame captured_frame_; 189 I420VideoFrame deliver_frame_; 190 VideoFrame deliver_encoded_frame_; 191 VideoFrame encoded_frame_; 192 193 // Image processing. 194 ViEEffectFilter* effect_filter_; 195 VideoProcessingModule* image_proc_module_; 196 int image_proc_module_ref_counter_; 197 VideoProcessingModule::FrameStats* deflicker_frame_stats_; 198 VideoProcessingModule::FrameStats* brightness_frame_stats_; 199 Brightness current_brightness_level_; 200 Brightness reported_brightness_level_; 201 bool denoising_enabled_; 202 203 // Statistics observer. 204 scoped_ptr<CriticalSectionWrapper> observer_cs_; 205 ViECaptureObserver* observer_; 206 207 // Encoding using encoding capable cameras. 208 scoped_ptr<CriticalSectionWrapper> encoding_cs_; 209 VideoCaptureModule::VideoCaptureEncodeInterface* capture_encoder_; 210 EncodedImageCallback* encode_complete_callback_; 211 VideoCodec codec_; 212 // The ViEEncoder we are encoding for. 213 ViEEncoder* vie_encoder_; 214 // ViEEncoder id we are encoding for. 215 int32_t vie_encoder_id_; 216 // Used for decoding preencoded frames. 217 VideoCodingModule* vcm_; 218 EncodedVideoData decode_buffer_; 219 bool decoder_initialized_; 220 CaptureCapability requested_capability_; 221 222 I420VideoFrame capture_device_image_; 223}; 224 225} // namespace webrtc 226 227#endif // WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_ 228