Refactored ViECapturer.
Types and function arguments will come in a later CL. Review URL: http://webrtc-codereview.appspot.com/322011 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1179 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
9a8fa4e65d
commit
e6f64835a0
File diff suppressed because it is too large
Load Diff
@ -8,200 +8,214 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
#ifndef WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_
|
||||||
* vie_capturer.h
|
#define WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CAPTURER_H_
|
|
||||||
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CAPTURER_H_
|
|
||||||
|
|
||||||
// Defines
|
|
||||||
#include "engine_configurations.h"
|
|
||||||
#include "vie_defines.h"
|
|
||||||
#include "typedefs.h"
|
|
||||||
|
|
||||||
#include "video_capture.h"
|
|
||||||
#include "video_processing.h"
|
|
||||||
#include "vie_frame_provider_base.h"
|
|
||||||
#include "video_codec_interface.h"
|
|
||||||
#include "video_coding.h"
|
|
||||||
#include "vie_capture.h"
|
|
||||||
#include "common_types.h"
|
#include "common_types.h"
|
||||||
|
#include "engine_configurations.h"
|
||||||
// Forward declarations
|
#include "modules/video_capture/main/interface/video_capture.h"
|
||||||
struct ViEPicture;
|
#include "modules/video_coding/codecs/interface/video_codec_interface.h"
|
||||||
|
#include "modules/video_coding/main/interface/video_coding.h"
|
||||||
|
#include "modules/video_processing/main/interface/video_processing.h"
|
||||||
|
#include "typedefs.h"
|
||||||
|
#include "video_engine/main/interface/vie_capture.h"
|
||||||
|
#include "video_engine/vie_defines.h"
|
||||||
|
#include "video_engine/vie_frame_provider_base.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class CriticalSectionWrapper;
|
class CriticalSectionWrapper;
|
||||||
class EventWrapper;
|
class EventWrapper;
|
||||||
|
class ProcessThread;
|
||||||
class ThreadWrapper;
|
class ThreadWrapper;
|
||||||
class ViEEffectFilter;
|
class ViEEffectFilter;
|
||||||
class ViEEncoder;
|
class ViEEncoder;
|
||||||
class ProcessThread;
|
struct ViEPicture;
|
||||||
|
|
||||||
class ViECapturer: public ViEFrameProviderBase,
|
class ViECapturer
|
||||||
public ViEExternalCapture, // External capture
|
: public ViEFrameProviderBase,
|
||||||
protected VideoCaptureDataCallback,
|
public ViEExternalCapture,
|
||||||
protected VideoEncoder,
|
protected VCMReceiveCallback,
|
||||||
protected VCMReceiveCallback,
|
protected VideoCaptureDataCallback,
|
||||||
protected VideoCaptureFeedBack
|
protected VideoCaptureFeedBack,
|
||||||
{
|
protected VideoEncoder {
|
||||||
public:
|
public:
|
||||||
static ViECapturer* CreateViECapture(int captureId, int,
|
static ViECapturer* CreateViECapture(int capture_id,
|
||||||
VideoCaptureModule& captureModule,
|
int engine_id,
|
||||||
ProcessThread& moduleProcessThread);
|
VideoCaptureModule& capture_module,
|
||||||
|
ProcessThread& module_process_thread);
|
||||||
|
|
||||||
static ViECapturer* CreateViECapture(int captureId, int engineId,
|
static ViECapturer* CreateViECapture(
|
||||||
const WebRtc_UWord8* deviceUniqueIdUTF8,
|
int capture_id,
|
||||||
WebRtc_UWord32 deviceUniqueIdUTF8Length,
|
int engine_id,
|
||||||
ProcessThread& moduleProcessThread);
|
const WebRtc_UWord8* device_unique_idUTF8,
|
||||||
~ViECapturer();
|
WebRtc_UWord32 device_unique_idUTF8Length,
|
||||||
|
ProcessThread& module_process_thread);
|
||||||
|
|
||||||
//Override ViEFrameProviderBase
|
~ViECapturer();
|
||||||
int FrameCallbackChanged();
|
|
||||||
virtual int DeregisterFrameCallback(const ViEFrameCallback* callbackObject);
|
|
||||||
bool IsFrameCallbackRegistered(const ViEFrameCallback* callbackObject);
|
|
||||||
|
|
||||||
// Implements ExternalCapture
|
// Implements ViEFrameProviderBase.
|
||||||
virtual int IncomingFrame(unsigned char* videoFrame,
|
int FrameCallbackChanged();
|
||||||
unsigned int videoFrameLength,
|
virtual int DeregisterFrameCallback(const ViEFrameCallback* callbackObject);
|
||||||
unsigned short width, unsigned short height,
|
bool IsFrameCallbackRegistered(const ViEFrameCallback* callbackObject);
|
||||||
RawVideoType videoType,
|
|
||||||
unsigned long long captureTime = 0);
|
|
||||||
|
|
||||||
virtual int IncomingFrameI420(
|
// Implements ExternalCapture.
|
||||||
const ViEVideoFrameI420& video_frame,
|
virtual int IncomingFrame(unsigned char* video_frame,
|
||||||
unsigned long long captureTime = 0);
|
unsigned int video_frame_length,
|
||||||
|
unsigned short width, unsigned short height,
|
||||||
|
RawVideoType video_type,
|
||||||
|
unsigned long long capture_time = 0);
|
||||||
|
|
||||||
// Use this capture device as encoder.
|
virtual int IncomingFrameI420(const ViEVideoFrameI420& video_frame,
|
||||||
// Returns 0 if the codec is supported by this capture device.
|
unsigned long long capture_time = 0);
|
||||||
virtual WebRtc_Word32 PreEncodeToViEEncoder(const VideoCodec& codec,
|
|
||||||
ViEEncoder& vieEncoder,
|
|
||||||
WebRtc_Word32 vieEncoderId);
|
|
||||||
|
|
||||||
// Start/Stop
|
// Use this capture device as encoder.
|
||||||
WebRtc_Word32 Start(const CaptureCapability captureCapability =
|
// Returns 0 if the codec is supported by this capture device.
|
||||||
CaptureCapability());
|
virtual WebRtc_Word32 PreEncodeToViEEncoder(const VideoCodec& codec,
|
||||||
WebRtc_Word32 Stop();
|
ViEEncoder& vie_encoder,
|
||||||
bool Started();
|
WebRtc_Word32 vie_encoder_id);
|
||||||
|
|
||||||
WebRtc_Word32 SetCaptureDelay(WebRtc_Word32 delayMS);
|
// Start/Stop.
|
||||||
WebRtc_Word32 SetRotateCapturedFrames(const RotateCapturedFrame rotation);
|
WebRtc_Word32 Start(
|
||||||
|
const CaptureCapability capture_capability = CaptureCapability());
|
||||||
|
WebRtc_Word32 Stop();
|
||||||
|
bool Started();
|
||||||
|
|
||||||
// Effect filter
|
// Overrides the capture delay.
|
||||||
WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effectFilter);
|
WebRtc_Word32 SetCaptureDelay(WebRtc_Word32 delay_ms);
|
||||||
WebRtc_Word32 EnableDenoising(bool enable);
|
|
||||||
WebRtc_Word32 EnableDeflickering(bool enable);
|
|
||||||
WebRtc_Word32 EnableBrightnessAlarm(bool enable);
|
|
||||||
|
|
||||||
// Statistic observer
|
// Sets rotation of the incoming captured frame.
|
||||||
WebRtc_Word32 RegisterObserver(ViECaptureObserver& observer);
|
WebRtc_Word32 SetRotateCapturedFrames(const RotateCapturedFrame rotation);
|
||||||
WebRtc_Word32 DeRegisterObserver();
|
|
||||||
bool IsObserverRegistered();
|
|
||||||
|
|
||||||
//Information
|
// Effect filter.
|
||||||
const WebRtc_UWord8* CurrentDeviceName() const;
|
WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effect_filter);
|
||||||
|
WebRtc_Word32 EnableDenoising(bool enable);
|
||||||
|
WebRtc_Word32 EnableDeflickering(bool enable);
|
||||||
|
WebRtc_Word32 EnableBrightnessAlarm(bool enable);
|
||||||
|
|
||||||
// set device images
|
// Statistics observer.
|
||||||
WebRtc_Word32 SetCaptureDeviceImage(const VideoFrame& captureDeviceImage);
|
WebRtc_Word32 RegisterObserver(ViECaptureObserver& observer);
|
||||||
|
WebRtc_Word32 DeRegisterObserver();
|
||||||
|
bool IsObserverRegistered();
|
||||||
|
|
||||||
protected:
|
// Information.
|
||||||
ViECapturer(int captureId, int engineId,
|
const WebRtc_UWord8* CurrentDeviceName() const;
|
||||||
ProcessThread& moduleProcessThread);
|
|
||||||
|
|
||||||
WebRtc_Word32 Init(VideoCaptureModule& captureModule);
|
// Set device image.
|
||||||
WebRtc_Word32 Init(const WebRtc_UWord8* deviceUniqueIdUTF8,
|
WebRtc_Word32 SetCaptureDeviceImage(const VideoFrame& capture_device_image);
|
||||||
const WebRtc_UWord32 deviceUniqueIdUTF8Length);
|
|
||||||
|
|
||||||
// Implements VideoCaptureDataCallback
|
protected:
|
||||||
virtual void OnIncomingCapturedFrame(const WebRtc_Word32 id,
|
ViECapturer(int capture_id,
|
||||||
VideoFrame& videoFrame,
|
int engine_id,
|
||||||
VideoCodecType codecType);
|
ProcessThread& module_process_thread);
|
||||||
virtual void OnCaptureDelayChanged(const WebRtc_Word32 id,
|
|
||||||
const WebRtc_Word32 delay);
|
|
||||||
bool EncoderActive();
|
|
||||||
bool CaptureCapabilityFixed(); // Returns true if the capture capability has been set in the StartCapture function and may not be changed.
|
|
||||||
WebRtc_Word32 IncImageProcRefCount();
|
|
||||||
WebRtc_Word32 DecImageProcRefCount();
|
|
||||||
|
|
||||||
// Implements VideoEncoder
|
WebRtc_Word32 Init(VideoCaptureModule& capture_module);
|
||||||
virtual WebRtc_Word32 Version(WebRtc_Word8 *version, WebRtc_Word32 length) const;
|
WebRtc_Word32 Init(const WebRtc_UWord8* device_unique_idUTF8,
|
||||||
virtual WebRtc_Word32 InitEncode(const VideoCodec* codecSettings,
|
const WebRtc_UWord32 device_unique_idUTF8Length);
|
||||||
WebRtc_Word32 numberOfCores,
|
|
||||||
WebRtc_UWord32 maxPayloadSize);
|
|
||||||
virtual WebRtc_Word32 Encode(const RawImage& inputImage,
|
|
||||||
const CodecSpecificInfo* codecSpecificInfo,
|
|
||||||
const VideoFrameType* frameTypes);
|
|
||||||
virtual WebRtc_Word32 RegisterEncodeCompleteCallback(
|
|
||||||
EncodedImageCallback* callback);
|
|
||||||
virtual WebRtc_Word32 Release();
|
|
||||||
virtual WebRtc_Word32 Reset();
|
|
||||||
virtual WebRtc_Word32 SetChannelParameters(WebRtc_UWord32 packetLoss,
|
|
||||||
int rtt);
|
|
||||||
virtual WebRtc_Word32 SetRates(WebRtc_UWord32 newBitRate,
|
|
||||||
WebRtc_UWord32 frameRate);
|
|
||||||
|
|
||||||
// Implements VCMReceiveCallback
|
// Implements VideoCaptureDataCallback.
|
||||||
virtual WebRtc_Word32 FrameToRender(VideoFrame& videoFrame);
|
virtual void OnIncomingCapturedFrame(const WebRtc_Word32 id,
|
||||||
// Implements VideoCaptureFeedBack
|
VideoFrame& video_frame,
|
||||||
virtual void OnCaptureFrameRate(const WebRtc_Word32 id,
|
VideoCodecType codec_type);
|
||||||
const WebRtc_UWord32 frameRate);
|
virtual void OnCaptureDelayChanged(const WebRtc_Word32 id,
|
||||||
virtual void OnNoPictureAlarm(const WebRtc_Word32 id,
|
const WebRtc_Word32 delay);
|
||||||
const VideoCaptureAlarm alarm);
|
|
||||||
|
|
||||||
// Thread functions for deliver captured frames to receivers
|
bool EncoderActive();
|
||||||
static bool ViECaptureThreadFunction(void* obj);
|
|
||||||
bool ViECaptureProcess();
|
|
||||||
|
|
||||||
void DeliverI420Frame(VideoFrame& videoFrame);
|
// Returns true if the capture capability has been set in |StartCapture|
|
||||||
void DeliverCodedFrame(VideoFrame& videoFrame);
|
// function and may not be changed.
|
||||||
|
bool CaptureCapabilityFixed();
|
||||||
|
|
||||||
private:
|
// Help function used for keeping track of VideoImageProcesingModule.
|
||||||
enum {kThreadWaitTimeMs = 100};
|
// Creates the module if it is needed, returns 0 on success and guarantees
|
||||||
|
// that the image proc module exist.
|
||||||
|
WebRtc_Word32 IncImageProcRefCount();
|
||||||
|
WebRtc_Word32 DecImageProcRefCount();
|
||||||
|
|
||||||
CriticalSectionWrapper& _captureCritsect; // Never take this one before deliverCritsect!
|
// Implements VideoEncoder.
|
||||||
CriticalSectionWrapper& _deliverCritsect;
|
virtual WebRtc_Word32 Version(WebRtc_Word8* version,
|
||||||
VideoCaptureModule* _captureModule;
|
WebRtc_Word32 length) const;
|
||||||
VideoCaptureExternal* _externalCaptureModule;
|
virtual WebRtc_Word32 InitEncode(const VideoCodec* codec_settings,
|
||||||
ProcessThread& _moduleProcessThread;
|
WebRtc_Word32 number_of_cores,
|
||||||
const int _captureId;
|
WebRtc_UWord32 max_payload_size);
|
||||||
|
virtual WebRtc_Word32 Encode(const RawImage& input_image,
|
||||||
|
const CodecSpecificInfo* codec_specific_info,
|
||||||
|
const VideoFrameType* frame_types);
|
||||||
|
virtual WebRtc_Word32 RegisterEncodeCompleteCallback(
|
||||||
|
EncodedImageCallback* callback);
|
||||||
|
virtual WebRtc_Word32 Release();
|
||||||
|
virtual WebRtc_Word32 Reset();
|
||||||
|
virtual WebRtc_Word32 SetChannelParameters(WebRtc_UWord32 packet_loss,
|
||||||
|
int rtt);
|
||||||
|
virtual WebRtc_Word32 SetRates(WebRtc_UWord32 new_bit_rate,
|
||||||
|
WebRtc_UWord32 frame_rate);
|
||||||
|
|
||||||
// Capture thread
|
// Implements VCMReceiveCallback.
|
||||||
ThreadWrapper& _vieCaptureThread;
|
virtual WebRtc_Word32 FrameToRender(VideoFrame& video_frame);
|
||||||
EventWrapper& _vieCaptureEvent;
|
|
||||||
EventWrapper& _vieDeliverEvent;
|
|
||||||
|
|
||||||
VideoFrame _capturedFrame;
|
// Implements VideoCaptureFeedBack
|
||||||
VideoFrame _deliverFrame;
|
virtual void OnCaptureFrameRate(const WebRtc_Word32 id,
|
||||||
VideoFrame _encodedFrame;
|
const WebRtc_UWord32 frame_rate);
|
||||||
|
virtual void OnNoPictureAlarm(const WebRtc_Word32 id,
|
||||||
|
const VideoCaptureAlarm alarm);
|
||||||
|
|
||||||
// Image processing
|
// Thread functions for deliver captured frames to receivers.
|
||||||
ViEEffectFilter* _effectFilter;
|
static bool ViECaptureThreadFunction(void* obj);
|
||||||
VideoProcessingModule* _imageProcModule;
|
bool ViECaptureProcess();
|
||||||
int _imageProcModuleRefCounter;
|
|
||||||
VideoProcessingModule::FrameStats* _deflickerFrameStats;
|
|
||||||
VideoProcessingModule::FrameStats* _brightnessFrameStats;
|
|
||||||
Brightness _currentBrightnessLevel;
|
|
||||||
Brightness _reportedBrightnessLevel;
|
|
||||||
bool _denoisingEnabled;
|
|
||||||
|
|
||||||
//Statistic observer
|
void DeliverI420Frame(VideoFrame& video_frame);
|
||||||
CriticalSectionWrapper& _observerCritsect;
|
void DeliverCodedFrame(VideoFrame& video_frame);
|
||||||
ViECaptureObserver* _observer;
|
|
||||||
|
|
||||||
// Encoding using encoding capable cameras
|
private:
|
||||||
CriticalSectionWrapper& _encodingCritsect;
|
// Never take capture_cs_ before deliver_cs_!
|
||||||
VideoCaptureModule::VideoCaptureEncodeInterface* _captureEncoder;
|
CriticalSectionWrapper& capture_cs_;
|
||||||
EncodedImageCallback* _encodeCompleteCallback;
|
CriticalSectionWrapper& deliver_cs_;
|
||||||
VideoCodec _codec;
|
VideoCaptureModule* capture_module_;
|
||||||
ViEEncoder* _vieEncoder; //ViEEncoder we are encoding for.
|
VideoCaptureExternal* external_capture_module_;
|
||||||
WebRtc_Word32 _vieEncoderId; //ViEEncoder id we are encoding for.
|
ProcessThread& module_process_thread_;
|
||||||
VideoCodingModule* _vcm; // Used for decoding preencoded frames
|
const int capture_id_;
|
||||||
EncodedVideoData _decodeBuffer; // Used for decoding preencoded frames
|
|
||||||
bool _decoderInitialized;
|
|
||||||
CaptureCapability _requestedCapability;
|
|
||||||
|
|
||||||
VideoFrame _captureDeviceImage;
|
// Capture thread.
|
||||||
|
ThreadWrapper& capture_thread_;
|
||||||
|
EventWrapper& capture_event_;
|
||||||
|
EventWrapper& deliver_event_;
|
||||||
|
|
||||||
|
VideoFrame captured_frame_;
|
||||||
|
VideoFrame deliver_frame_;
|
||||||
|
VideoFrame encoded_frame_;
|
||||||
|
|
||||||
|
// Image processing.
|
||||||
|
ViEEffectFilter* effect_filter_;
|
||||||
|
VideoProcessingModule* image_proc_module_;
|
||||||
|
int image_proc_module_ref_counter_;
|
||||||
|
VideoProcessingModule::FrameStats* deflicker_frame_stats_;
|
||||||
|
VideoProcessingModule::FrameStats* brightness_frame_stats_;
|
||||||
|
Brightness current_brightness_level_;
|
||||||
|
Brightness reported_brightness_level_;
|
||||||
|
bool denoising_enabled_;
|
||||||
|
|
||||||
|
// Statistics observer.
|
||||||
|
CriticalSectionWrapper& observer_cs_;
|
||||||
|
ViECaptureObserver* observer_;
|
||||||
|
|
||||||
|
// Encoding using encoding capable cameras.
|
||||||
|
CriticalSectionWrapper& encoding_critsect_;
|
||||||
|
VideoCaptureModule::VideoCaptureEncodeInterface* capture_encoder_;
|
||||||
|
EncodedImageCallback* encode_complete_callback_;
|
||||||
|
VideoCodec codec_;
|
||||||
|
// The ViEEncoder we are encoding for.
|
||||||
|
ViEEncoder* vie_encoder_;
|
||||||
|
// ViEEncoder id we are encoding for.
|
||||||
|
WebRtc_Word32 vie_encoder_id_;
|
||||||
|
// Used for decoding preencoded frames.
|
||||||
|
VideoCodingModule* vcm_;
|
||||||
|
EncodedVideoData decode_buffer_;
|
||||||
|
bool decoder_initialized_;
|
||||||
|
CaptureCapability requested_capability_;
|
||||||
|
|
||||||
|
VideoFrame capture_device_image_;
|
||||||
};
|
};
|
||||||
} // namespace webrtc
|
|
||||||
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_CAPTURER_H_
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // WEBRTC_VIDEO_ENGINE_VIE_CAPTURER_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user