#pragma once #include "ivideocaptureinterface.h" #include "videoutil.h" #include "common_video/videocommon.h" #include "videocapturedefines.h" #include #include "libyuv.h" #include "libyuv/convert_argb.h" #include "libyuv/rotate.h" static const int mode_width[VIDEOCAP_MAX_MODE] = { VIDEOCAP_SQCIF_WIDTH,VIDEOCAP_QQVGA_WIDTH, VIDEOCAP_QCIF_WIDTH,VIDEOCAP_QVGA_WIDTH, VIDEOCAP_CIF_WIDTH,VIDEOCAP_VGA_WIDTH, VIDEOCAP_4CIF_WIDTH,VIDEOCAP_SVGA_WIDTH, VIDEOCAP_NHD_WIDTH,VIDEOCAP_SXGA_WIDTH, VIDEOCAP_720P_WIDTH,VIDEOCAP_1080P_WIDTH, }; static const int mode_height[VIDEOCAP_MAX_MODE] = { VIDEOCAP_SQCIF_HEIGHT,VIDEOCAP_QQVGA_HEIGHT, VIDEOCAP_QCIF_HEIGHT,VIDEOCAP_QVGA_HEIGHT, VIDEOCAP_CIF_HEIGHT,VIDEOCAP_VGA_HEIGHT, VIDEOCAP_4CIF_HEIGHT,VIDEOCAP_SVGA_HEIGHT, VIDEOCAP_NHD_HEIGHT,VIDEOCAP_SXGA_HEIGHT, VIDEOCAP_720P_HEIGHT,VIDEOCAP_1080P_HEIGHT, }; typedef struct videocap_s { videocap_param_t param; int running; int cap_index; video_frame cap_frame; video_frame res_frame; struct SwsContext* sws_context; /* for image scaling and format converting */ } videocap_t; struct Buffer { void* start; size_t length; }; class VideoCaptureImpl : public IVideoCapture { public: VideoCaptureImpl(videocap_callback_t* pCallback); ~VideoCaptureImpl(); virtual int VideoCaptureSetParam(videocap_param_t* param); virtual int StartVideoCapture(); virtual int StopVideoCapture(); virtual void VideoCaptureDestroy(); int GetCamBrightness(int* ibright, bool bRawRange); int SetCamBrightness(int ibright, bool bRawRange); int SetCamAutoBrightness(); bool GetCamRawBrightnessRange(int* imin, int* imax); bool GetCamBrightnessInfo(); bool VideoCaptureStarted(); int GetCaptureVideoFd(); bool AllocateVideoBuffers(); bool DeAllocateVideoBuffers(); bool AlignedMallocVideoBuffer(); bool FreeAlignedMallocVideoBuffer(); bool AllocateVideoCapturebuffer(); VideoType GetCaptureVideoType(); int GetCapture_Width(); int GetCapture_Height(); bool GetStopCaptureFlag(); int32_t IncomingFrame(uint8_t* videoFrame, size_t videoFrameLength, const VideoCaptureCapability& frameInfo, int64_t captureTime = 0); Buffer* GetCaptureBuffer(); void CapLog(const char* fmt, ...); void CapLogEvent(int itype, const char* strmessage); private: int TransToRealBrightnessValue(int ibright); int TransFromRealBrightnessValue(int ibright); libyuv::RotationMode RotateTrans(int irotate); private: enum { kNoOfV4L2Bufffers = 4 }; videocap_callback_t m_callback; videocap_t* m_capture; bool m_bCaptureStarted; bool m_bStopCapture; pthread_t m_CaptureThreadId; int m_deviceId; int m_deviceFd; int m_frame_fmt; int m_in_cap_width; int m_in_cap_height; int m_real_cap_width; int m_real_cap_height; int m_out_cap_width; int m_out_cap_height; libyuv::RotationMode m_rotate; VideoType m_captureVideoType; int m_currentFrameRate; uint8_t* m_i420; uint8_t* m_opti420; uint8_t* m_rgb24; int m_iminbrightness; int m_imaxbrightness; int m_idefaultbrightness; int m_ilogcount; int32_t m_buffersAllocatedByDevice; Buffer* m_pool; };