一、纯虚类
hardware/amlogic/camera/inc/CameraHal.h
class CameraAdapter: public FrameNotifier, public virtual RefBase { //add by [email protected] virtual bool getPixelFormat(char* ResolutionList, bool bIsPictureMode) = 0; virtual int v4l2QueryControl(int control, struct v4l2_queryctrl *queryctrl) = 0; virtual int v4l2GetControl(int control) = 0; virtual int v4l2SetControl(int control, int value) = 0; int mInterpolationSize; //end [email protected] }hardware/amlogic/camera/inc/BaseCameraAdapter.h
class BaseCameraAdapter : public CameraAdapter { //add by [email protected] virtual bool getPixelFormat(char* ResolutionList, bool bIsPictureMode) = 0; virtual int v4l2QueryControl(int control, struct v4l2_queryctrl *queryctrl) = 0; virtual int v4l2GetControl(int control) = 0; virtual int v4l2SetControl(int control, int value) = 0; //end [email protected] }二、继承类
hardware/amlogic/camera/vircam/inc/V4LCamAdpt.h
class V4LCamAdpt : public BaseCameraAdapter { //add by [email protected] virtual bool getPixelFormat(char* ResolutionList, bool bIsPictureMode); virtual int v4l2QueryControl(int control, struct v4l2_queryctrl *queryctrl); virtual int v4l2GetControl(int control); virtual int v4l2SetControl(int control, int value); //end [email protected] }hardware/amlogic/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h
class V4LCameraAdapter : public BaseCameraAdapter { //add by [email protected] virtual bool getPixelFormat(char* ResolutionList, bool bIsPictureMode); virtual int v4l2QueryControl(int control, struct v4l2_queryctrl *queryctrl); virtual int v4l2GetControl(int control); virtual int v4l2SetControl(int control, int value); //end [email protected] }
三、使用
1.分别是虚拟和实际
hardware/amlogic/camera/CameraHal.cpp
status_t CameraHal::initialize(CameraProperties::Properties* properties) { mCameraAdapter = CameraAdapter_Factory(sensor_index); }hardware/amlogic/camera/vircam/VirtualCamHal.cpp
status_t VirtualCamHal::initialize(CameraProperties::Properties* properties) { mCameraAdapter = CameraAdapter_Factory(sensor_index); }2.工厂模式的定义
hardware/amlogic/camera/V4LCameraAdapter/V4LCameraAdapter.cpp
extern "C" CameraAdapter* CameraAdapter_Factory(size_t sensor_index) { if( sensor_index == (size_t)(iCamerasNum)){ adapter = new V4LCamAdpt(sensor_index); }else{ adapter = new V4LCameraAdapter(sensor_index); } }