author | sky.zhou <sky.zhou@droid04.amlogic.com> | 2012-01-11 08:19:27 (GMT) |
---|---|---|
committer | sky.zhou <sky.zhou@droid04.amlogic.com> | 2012-01-11 08:19:27 (GMT) |
commit | 54d2e75ffe9bd937b0915a9e16824644468d87f4 (patch) | |
tree | be272cd428231875d9b793395f6d25b82e9c6750 | |
parent | b49b9e5abd49415749803c0f2f9c7109d636acb0 (diff) | |
download | camera-54d2e75ffe9bd937b0915a9e16824644468d87f4.zip camera-54d2e75ffe9bd937b0915a9e16824644468d87f4.tar.gz camera-54d2e75ffe9bd937b0915a9e16824644468d87f4.tar.bz2 |
add auto decte cameras for board may have two camera or only one front camera. for this case, disable BOARD_HAVE_FRONT_CAM and BOARD_HAVE_BACK_CAM
-rwxr-xr-x[-rw-r--r--] | CameraHal_Module.cpp | 6 | ||||
-rwxr-xr-x[-rw-r--r--] | CameraProperties.cpp | 5 | ||||
-rwxr-xr-x | V4LCameraAdapter/V4LCameraAdapter.cpp | 58 | ||||
-rwxr-xr-x | inc/CameraProperties.h | 11 |
4 files changed, 62 insertions, 18 deletions
diff --git a/CameraHal_Module.cpp b/CameraHal_Module.cpp index 52b237c..675720b 100644..100755 --- a/CameraHal_Module.cpp +++ b/CameraHal_Module.cpp @@ -611,10 +611,10 @@ fail: return rv; } +extern "C" int CameraAdapter_CameraNum(); int camera_get_number_of_cameras(void) { - int num_cameras = MAX_CAMERAS_SUPPORTED; - + int num_cameras = CameraAdapter_CameraNum(); return num_cameras; } @@ -626,7 +626,7 @@ int camera_get_camera_info(int camera_id, struct camera_info *info) const char *valstr = NULL; android::CameraProperties::Properties* properties = NULL; -LOGD("camera_get_camera_info camera_id=%d", camera_id); + LOGD("camera_get_camera_info camera_id=%d", camera_id); // this going to be the first call from camera service // initialize camera properties here... if(gCameraProperties.initialize() != android::NO_ERROR) diff --git a/CameraProperties.cpp b/CameraProperties.cpp index 43ff15f..da3fd5d 100644..100755 --- a/CameraProperties.cpp +++ b/CameraProperties.cpp @@ -80,7 +80,8 @@ status_t CameraProperties::initialize() extern "C" int CameraAdapter_Capabilities(CameraProperties::Properties* properties_array, const unsigned int starting_camera, - const unsigned int max_camera); + const unsigned int camera_num); +extern "C" int CameraAdapter_CameraNum(); ///Loads all the Camera related properties status_t CameraProperties::loadProperties() @@ -90,7 +91,7 @@ status_t CameraProperties::loadProperties() status_t ret = NO_ERROR; // adapter updates capabilities and we update camera count - mCamerasSupported = CameraAdapter_Capabilities(mCameraProps, mCamerasSupported, MAX_CAMERAS_SUPPORTED); + mCamerasSupported = CameraAdapter_Capabilities(mCameraProps, mCamerasSupported, CameraAdapter_CameraNum()); if((int)mCamerasSupported < 0) { LOGE("error while getting capabilities"); diff --git a/V4LCameraAdapter/V4LCameraAdapter.cpp b/V4LCameraAdapter/V4LCameraAdapter.cpp index 1f7ca24..46f092b 100755 --- a/V4LCameraAdapter/V4LCameraAdapter.cpp +++ b/V4LCameraAdapter/V4LCameraAdapter.cpp @@ -1089,7 +1089,7 @@ extern "C" CameraAdapter* CameraAdapter_Factory(size_t sensor_index) extern "C" int CameraAdapter_Capabilities(CameraProperties::Properties* properties_array, const unsigned int starting_camera, - const unsigned int max_camera) { + const unsigned int camera_num) { int num_cameras_supported = 0; CameraProperties::Properties* properties = NULL; @@ -1100,7 +1100,7 @@ extern "C" int CameraAdapter_Capabilities(CameraProperties::Properties* properti return -EINVAL; } - while (starting_camera + num_cameras_supported < max_camera) + while (starting_camera + num_cameras_supported < camera_num) { properties = properties_array + starting_camera + num_cameras_supported; properties->set(CameraProperties::CAMERA_NAME, "Camera"); @@ -1114,6 +1114,32 @@ extern "C" int CameraAdapter_Capabilities(CameraProperties::Properties* properti return num_cameras_supported; } +static int iCamerasNum = -1; +extern "C" int CameraAdapter_CameraNum() +{ + LOGD("CameraAdapter_CameraNum %d",iCamerasNum); + +#if defined(AMLOGIC_FRONT_CAMERA_SUPPORT) || defined(AMLOGIC_BACK_CAMERA_SUPPORT) + return MAX_CAMERAS_SUPPORTED; +#else + if(iCamerasNum == -1) + { + iCamerasNum = 0; + for(int i = 0;i < MAX_CAMERAS_SUPPORTED;i++) + { + if( access(DEVICE_PATH(i), 0) == 0 ) + { + iCamerasNum++; + } + } + LOGD("GetCameraNums %d",iCamerasNum); + } + + return iCamerasNum; +#endif +} + + extern "C" int getValidFrameSize(int camera_id, int pixel_format, char *framesize) { struct v4l2_frmsizeenum frmsize; @@ -1183,26 +1209,36 @@ extern "C" void loadCaps(int camera_id, CameraProperties::Properties* params) { bool bFrontCam = false; if (camera_id == 0) { #ifdef AMLOGIC_BACK_CAMERA_SUPPORT - params->set(CameraProperties::FACING_INDEX, TICameraParameters::FACING_BACK); -#else - params->set(CameraProperties::FACING_INDEX, TICameraParameters::FACING_FRONT); + bFrontCam = false; +#elif defined(AMLOGIC_FRONT_CAMERA_SUPPORT) bFrontCam = true; +#else//defined nothing, we try by ourself + if(CameraAdapter_CameraNum() > 1) { //when have more than one cameras, this 0 is backcamera + bFrontCam = false; + } else { + bFrontCam = true; + } #endif } else if (camera_id == 1) { #if defined(AMLOGIC_BACK_CAMERA_SUPPORT) && defined(AMLOGIC_FRONT_CAMERA_SUPPORT) - params->set(CameraProperties::FACING_INDEX, TICameraParameters::FACING_FRONT); bFrontCam = true; -#else - //if support front camera only do we need to add a fake back camera for cts? - //params->set(CameraProperties::FACING_INDEX, TICameraParameters::FACING_BACK); +#else//defined nothing, we try by ourself + if(CameraAdapter_CameraNum() > 1) { //when have more than one cameras, this 1 is frontcamera + bFrontCam = true; + } else { + LOGE("Should not run to here when just have 1 camera"); + } #endif } //should changed while the screen orientation changed. - if(bFrontCam == true) + if(bFrontCam == true) { + params->set(CameraProperties::FACING_INDEX, TICameraParameters::FACING_FRONT); params->set(CameraProperties::ORIENTATION_INDEX,"270"); - else + } else { + params->set(CameraProperties::FACING_INDEX, TICameraParameters::FACING_BACK); params->set(CameraProperties::ORIENTATION_INDEX,"90"); + } params->set(CameraProperties::SUPPORTED_PREVIEW_FORMATS,DEFAULT_PREVIEW_FORMAT); params->set(CameraProperties::PREVIEW_FORMAT,DEFAULT_PREVIEW_FORMAT); diff --git a/inc/CameraProperties.h b/inc/CameraProperties.h index 973fe6c..70de98d 100755 --- a/inc/CameraProperties.h +++ b/inc/CameraProperties.h @@ -33,10 +33,17 @@ namespace android {
#if defined(AMLOGIC_FRONT_CAMERA_SUPPORT) && defined(AMLOGIC_BACK_CAMERA_SUPPORT)
- #define MAX_CAMERAS_SUPPORTED 2
+ #define MAX_CAMERAS_SUPPORTED 2
+#elif defined(AMLOGIC_FRONT_CAMERA_SUPPORT) || defined(AMLOGIC_BACK_CAMERA_SUPPORT)
+ #define MAX_CAMERAS_SUPPORTED 1
#else
- #define MAX_CAMERAS_SUPPORTED 1
+ //if didn't define AMLOGIC_FRONT_CAMERA_SUPPORT nor AMLOGIC_BACK_CAMERA_SUPPORT,
+ //we set the MAX_CAMERAS_SUPPORTED to the max nums we may support ,and
+ //will dectect the camera number in function CameraAdapter_CameraNum();
+ #define MAX_CAMERAS_SUPPORTED 2
#endif
+
+
#define MAX_SIMUL_CAMERAS_SUPPORTED 1
#define MAX_PROP_NAME_LENGTH 50
#define MAX_PROP_VALUE_LENGTH 2048
|