From 6b0a236daa28e43a5f35052bbc56a1385b8415b5 Mon Sep 17 00:00:00 2001 From: Saravanan Solaiyappan Date: Tue, 21 Feb 2012 17:09:16 -0600 Subject: CameraHAL: V4LCameraAdapter co-exists with OMXCameraAdapter [Comment] Build flag is enabled to build both V4L and OMX adapters. Individual adapters can also be choosen for build by setting the appropriate build flag OMAP4_CAMERA_HAL_USES. The camera index will be in the following order while querying the capabilities during bootup: 0 - Primary camera 1 - Secondary camera 2 - USB camera If only USBcamera is connected, the camera index will be 0. [DR] - Change-Id: Ie7165f97b860c13aaa3ad71c8cc12d34baba4cbf Signed-off-by: Solaiyappan Saravanan --- camera/Android.mk | 64 ++++++++++++++++++++++++++-- camera/BaseCameraAdapter.cpp | 43 +++++++++++++++++++ camera/CameraHal.cpp | 27 +++++++++--- camera/OMXCameraAdapter/OMXCameraAdapter.cpp | 7 +-- camera/V4LCameraAdapter/V4LCameraAdapter.cpp | 58 ++++++++++++++++++------- camera/inc/CameraHal.h | 4 ++ 6 files changed, 176 insertions(+), 27 deletions(-) diff --git a/camera/Android.mk b/camera/Android.mk index 35d4435..f97b2a9 100644 --- a/camera/Android.mk +++ b/camera/Android.mk @@ -2,8 +2,9 @@ ifeq ($(TARGET_BOARD_PLATFORM),omap4) LOCAL_PATH:= $(call my-dir) -OMAP4_CAMERA_HAL_USES:= OMX -# OMAP4_CAMERA_HAL_USES:= USB +#OMAP4_CAMERA_HAL_USES:= OMX +#OMAP4_CAMERA_HAL_USES:= USB +OMAP4_CAMERA_HAL_USES:= ALL ifdef TI_CAMERAHAL_DEBUG_ENABLED # Enable CameraHAL debug logs @@ -39,6 +40,7 @@ OMAP4_CAMERA_HAL_SRC := \ AppCallbackNotifier.cpp \ ANativeWindowDisplayAdapter.cpp \ CameraProperties.cpp \ + BaseCameraAdapter.cpp \ MemoryManager.cpp \ Encoder_libjpeg.cpp \ SensorListener.cpp \ @@ -50,7 +52,6 @@ OMAP4_CAMERA_COMMON_SRC:= \ CameraHalCommon.cpp OMAP4_CAMERA_OMX_SRC:= \ - BaseCameraAdapter.cpp \ OMXCameraAdapter/OMX3A.cpp \ OMXCameraAdapter/OMXAlgo.cpp \ OMXCameraAdapter/OMXCameraAdapter.cpp \ @@ -64,7 +65,6 @@ OMAP4_CAMERA_OMX_SRC:= \ OMXCameraAdapter/OMXDccDataSave.cpp \ OMAP4_CAMERA_USB_SRC:= \ - BaseCameraAdapter.cpp \ V4LCameraAdapter/V4LCameraAdapter.cpp # @@ -112,6 +112,7 @@ LOCAL_SHARED_LIBRARIES:= \ libjpeg \ libexif +CAMERAHAL_CFLAGS += -DOMX_CAMERA_ADAPTER LOCAL_CFLAGS := -fno-short-enums -DCOPY_IMAGE_BUFFER $(CAMERAHAL_CFLAGS) LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw @@ -170,6 +171,61 @@ LOCAL_MODULE:= camera.$(TARGET_BOARD_PLATFORM) LOCAL_MODULE_TAGS:= optional include $(BUILD_HEAPTRACKED_SHARED_LIBRARY) + +else +ifeq ($(OMAP4_CAMERA_HAL_USES),ALL) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + $(OMAP4_CAMERA_HAL_SRC) \ + $(OMAP4_CAMERA_OMX_SRC) \ + $(OMAP4_CAMERA_USB_SRC) \ + $(OMAP4_CAMERA_COMMON_SRC) + +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH)/inc/ \ + $(LOCAL_PATH)/../hwc \ + $(LOCAL_PATH)/../include \ + $(LOCAL_PATH)/inc/OMXCameraAdapter \ + $(LOCAL_PATH)/inc/V4LCameraAdapter \ + $(LOCAL_PATH)/../libtiutils \ + hardware/ti/omap4xxx/tiler \ + hardware/ti/omap4xxx/ion \ + frameworks/base/include/ui \ + frameworks/base/include/utils \ + $(DOMX_PATH)/omx_core/inc \ + $(DOMX_PATH)/mm_osal/inc \ + frameworks/base/include/media/stagefright \ + frameworks/base/include/media/stagefright/openmax \ + external/jpeg \ + external/jhead + +LOCAL_SHARED_LIBRARIES:= \ + libui \ + libbinder \ + libutils \ + libcutils \ + libtiutils \ + libmm_osal \ + libOMX_Core \ + libcamera_client \ + libgui \ + libdomx \ + libion \ + libjpeg \ + libexif + +CAMERAHAL_CFLAGS += -DOMX_CAMERA_ADAPTER -DV4L_CAMERA_ADAPTER +LOCAL_CFLAGS := -fno-short-enums -DCOPY_IMAGE_BUFFER $(CAMERAHAL_CFLAGS) + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw +LOCAL_MODULE:= camera.$(TARGET_BOARD_PLATFORM) +LOCAL_MODULE_TAGS:= optional + +include $(BUILD_HEAPTRACKED_SHARED_LIBRARY) + +endif endif endif endif diff --git a/camera/BaseCameraAdapter.cpp b/camera/BaseCameraAdapter.cpp index c18efd6..e2ebee1 100644 --- a/camera/BaseCameraAdapter.cpp +++ b/camera/BaseCameraAdapter.cpp @@ -2351,6 +2351,49 @@ void BaseCameraAdapter::onOrientationEvent(uint32_t orientation, uint32_t tilt) } //----------------------------------------------------------------------------- +extern "C" status_t OMXCameraAdapter_Capabilities( + CameraProperties::Properties * const properties_array, + const int starting_camera, const int max_camera, int & supportedCameras); +extern "C" status_t V4LCameraAdapter_Capabilities( + CameraProperties::Properties * const properties_array, + const int starting_camera, const int max_camera, int & supportedCameras); + +extern "C" status_t CameraAdapter_Capabilities( + CameraProperties::Properties * const properties_array, + const int starting_camera, const int max_camera, int & supportedCameras) +{ + + status_t ret = NO_ERROR; + status_t err = NO_ERROR; + int num_cameras_supported = 0; + + LOG_FUNCTION_NAME; + + supportedCameras = 0; +#ifdef OMX_CAMERA_ADAPTER + //Query OMX cameras + err = OMXCameraAdapter_Capabilities( properties_array, starting_camera, + max_camera, supportedCameras); + if(err != NO_ERROR) { + CAMHAL_LOGEA("error while getting OMXCameraAdapter capabilities"); + ret = UNKNOWN_ERROR; + } +#endif +#ifdef V4L_CAMERA_ADAPTER + //Query V4L cameras + err = V4LCameraAdapter_Capabilities( properties_array, (const int) supportedCameras, + max_camera, num_cameras_supported); + if(err != NO_ERROR) { + CAMHAL_LOGEA("error while getting V4LCameraAdapter capabilities"); + ret = UNKNOWN_ERROR; + } +#endif + + supportedCameras += num_cameras_supported; + CAMHAL_LOGEB("supportedCameras= %d\n", supportedCameras); + LOG_FUNCTION_NAME_EXIT; + return ret; +} }; diff --git a/camera/CameraHal.cpp b/camera/CameraHal.cpp index 31b3c32..24ee709 100644 --- a/camera/CameraHal.cpp +++ b/camera/CameraHal.cpp @@ -32,7 +32,8 @@ namespace android { -extern "C" CameraAdapter* CameraAdapter_Factory(size_t); +extern "C" CameraAdapter* OMXCameraAdapter_Factory(size_t); +extern "C" CameraAdapter* V4LCameraAdapter_Factory(size_t); /*****************************************************************************/ @@ -263,8 +264,10 @@ int CameraHal::setParameters(const CameraParameters& params) CameraParameters oldParams(mParameters.flatten()); #ifdef V4L_CAMERA_ADAPTER - ret = mCameraAdapter->setParameters(params); - return ret; + if (strcmp (V4L_CAMERA_NAME_USB, mCameraProperties->get(CameraProperties::CAMERA_NAME)) == 0 ) { + ret = mCameraAdapter->setParameters(params); + return ret; + } #endif { @@ -3007,6 +3010,7 @@ status_t CameraHal::initialize(CameraProperties::Properties* properties) LOG_FUNCTION_NAME; int sensor_index = 0; + const char* sensor_name = NULL; ///Initialize the event mask used for registering an event provider for AppCallbackNotifier ///Currently, registering all events as to be coming from CameraAdapter @@ -3029,9 +3033,22 @@ status_t CameraHal::initialize(CameraProperties::Properties* properties) sensor_index = atoi(mCameraProperties->get(CameraProperties::CAMERA_SENSOR_INDEX)); } - CAMHAL_LOGDB("Sensor index %d", sensor_index); + if (strcmp(CameraProperties::DEFAULT_VALUE, mCameraProperties->get(CameraProperties::CAMERA_NAME)) != 0 ) { + sensor_name = mCameraProperties->get(CameraProperties::CAMERA_NAME); + } + CAMHAL_LOGDB("Sensor index= %d; Sensor name= %s", sensor_index, sensor_name); + + if (strcmp(sensor_name, V4L_CAMERA_NAME_USB) == 0) { +#ifdef V4L_CAMERA_ADAPTER + mCameraAdapter = V4LCameraAdapter_Factory(sensor_index); +#endif + } + else { +#ifdef OMX_CAMERA_ADAPTER + mCameraAdapter = OMXCameraAdapter_Factory(sensor_index); +#endif + } - mCameraAdapter = CameraAdapter_Factory(sensor_index); if ( ( NULL == mCameraAdapter ) || (mCameraAdapter->initialize(properties)!=NO_ERROR)) { CAMHAL_LOGEA("Unable to create or initialize CameraAdapter"); diff --git a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp index d07afd3..a10256b 100644 --- a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp +++ b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp @@ -3675,7 +3675,7 @@ OMXCameraAdapter::~OMXCameraAdapter() LOG_FUNCTION_NAME_EXIT; } -extern "C" CameraAdapter* CameraAdapter_Factory(size_t sensor_index) +extern "C" CameraAdapter* OMXCameraAdapter_Factory(size_t sensor_index) { CameraAdapter *adapter = NULL; Mutex::Autolock lock(gAdapterLock); @@ -3686,7 +3686,7 @@ extern "C" CameraAdapter* CameraAdapter_Factory(size_t sensor_index) if ( adapter ) { CAMHAL_LOGDB("New OMX Camera adapter instance created for sensor %d",sensor_index); } else { - CAMHAL_LOGEA("Camera adapter create failed!"); + CAMHAL_LOGEA("OMX Camera adapter create failed for sensor index = %d!",sensor_index); } LOG_FUNCTION_NAME_EXIT; @@ -4002,7 +4002,7 @@ private: int mPortsLeftToDisable; }; -extern "C" status_t CameraAdapter_Capabilities( +extern "C" status_t OMXCameraAdapter_Capabilities( CameraProperties::Properties * const properties_array, const int starting_camera, const int max_camera, int & supportedCameras) { @@ -4061,6 +4061,7 @@ extern "C" status_t CameraAdapter_Capabilities( break; num_cameras_supported++; + CAMHAL_LOGDB("Number of OMX Cameras detected = %d \n",num_cameras_supported); } EXIT: diff --git a/camera/V4LCameraAdapter/V4LCameraAdapter.cpp b/camera/V4LCameraAdapter/V4LCameraAdapter.cpp index 8affa2c..18ccf21 100644 --- a/camera/V4LCameraAdapter/V4LCameraAdapter.cpp +++ b/camera/V4LCameraAdapter/V4LCameraAdapter.cpp @@ -57,8 +57,7 @@ namespace android { //define this macro to save first few raw frames when starting the preview. //#define SAVE_RAW_FRAMES 1 -#define FPS_PERIOD 30 -Mutex gAdapterLock; +Mutex gV4LAdapterLock; const char *device = DEVICE; @@ -545,6 +544,7 @@ void saveFile(unsigned char* buff, int buff_size) { return; } //dump nv12 buffer + counter++; sprintf(fn, "/data/misc/camera/raw/nv12_dump_%03d.yuv", counter); CAMHAL_LOGEB("Dumping nv12 frame to a file : %s.", fn); @@ -554,7 +554,6 @@ void saveFile(unsigned char* buff, int buff_size) { return; } - counter++; write(fd, buff, buff_size ); close(fd); @@ -637,18 +636,18 @@ int V4LCameraAdapter::previewThread() return ret; } -extern "C" CameraAdapter* CameraAdapter_Factory(size_t sensor_index) +extern "C" CameraAdapter* V4LCameraAdapter_Factory(size_t sensor_index) { CameraAdapter *adapter = NULL; - Mutex::Autolock lock(gAdapterLock); + Mutex::Autolock lock(gV4LAdapterLock); LOG_FUNCTION_NAME; adapter = new V4LCameraAdapter(sensor_index); if ( adapter ) { - CAMHAL_LOGDB("New OMX Camera adapter instance created for sensor %d",sensor_index); + CAMHAL_LOGDB("New V4L Camera adapter instance created for sensor %d",sensor_index); } else { - CAMHAL_LOGEA("Camera adapter create failed!"); + CAMHAL_LOGEA("V4L Camera adapter create failed for sensor index = %d!",sensor_index); } LOG_FUNCTION_NAME_EXIT; @@ -656,16 +655,20 @@ extern "C" CameraAdapter* CameraAdapter_Factory(size_t sensor_index) return adapter; } -extern "C" status_t CameraAdapter_Capabilities( +extern "C" status_t V4LCameraAdapter_Capabilities( CameraProperties::Properties * const properties_array, const int starting_camera, const int max_camera, int & supportedCameras) { + status_t ret = NO_ERROR; + struct v4l2_capability cap; + int tempHandle = NULL; + int num_cameras_supported = 0; + CameraProperties::Properties* properties = NULL; + LOG_FUNCTION_NAME; supportedCameras = 0; - int num_cameras_supported = 0; - CameraProperties::Properties* properties = NULL; - CAMHAL_LOGEB("starting_camera+%d, max_camera=%d, supportedCameras=%d", starting_camera,max_camera,supportedCameras); + memset((void*)&cap, 0, sizeof(v4l2_capability)); if (!properties_array) { CAMHAL_LOGEB("invalid param: properties = 0x%p", properties_array); @@ -673,11 +676,33 @@ extern "C" status_t CameraAdapter_Capabilities( return BAD_VALUE; } - // TODO: Need to tell camera properties what other cameras we can support - if (starting_camera + num_cameras_supported < max_camera) { + //look for the connected video devices + if (ret == NO_ERROR && (starting_camera + num_cameras_supported) < max_camera) { + + if ((tempHandle = open(device, O_RDWR)) == -1) { + CAMHAL_LOGEB("Error while opening handle to V4L2 Camera: %s", strerror(errno)); + return NO_ERROR; + } + + ret = ioctl (tempHandle, VIDIOC_QUERYCAP, &cap); + if (ret < 0) + { + CAMHAL_LOGEA("Error when querying the capabilities of the V4L Camera"); + goto EXIT; + } + + //check for video capture devices + if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) + { + CAMHAL_LOGEA("Error while adapter initialization: video capture not supported."); + goto EXIT; + } + num_cameras_supported++; properties = properties_array + starting_camera; - properties->set(CameraProperties::CAMERA_NAME, "USBCamera"); + + // TODO: Need to tell camera properties what other cameras we can support + properties->set(CameraProperties::CAMERA_NAME, "USBCAMERA"); properties->set(CameraProperties::PREVIEW_SIZE, "640x480"); properties->set(CameraProperties::PREVIEW_FORMAT, "yuv420sp"); properties->set(CameraProperties::SUPPORTED_PREVIEW_FORMATS, "yuv420sp"); @@ -694,8 +719,11 @@ extern "C" status_t CameraAdapter_Capabilities( } supportedCameras = num_cameras_supported; - LOG_FUNCTION_NAME_EXIT; + CAMHAL_LOGDB("V4L cameras detected =%d", num_cameras_supported); +EXIT: + LOG_FUNCTION_NAME_EXIT; + close(tempHandle); return NO_ERROR; } diff --git a/camera/inc/CameraHal.h b/camera/inc/CameraHal.h index 805d828..9dcda2b 100644 --- a/camera/inc/CameraHal.h +++ b/camera/inc/CameraHal.h @@ -123,6 +123,10 @@ namespace android { #ifdef CAMERAHAL_USE_RAW_IMAGE_SAVING extern const char * const kRawImagesOutputDirPath; #endif +#define V4L_CAMERA_NAME_USB "USBCAMERA" +#define OMX_CAMERA_NAME_OV "OV5640" +#define OMX_CAMERA_NAME_SONY "IMX060" + ///Forward declarations class CameraHal; -- cgit v1.1