Snapshot of TI's camera HAL development with adjustments to build in our tree

The head of TI's hardware/ti/omap4xxx/camera repository at the time of the snapshot was:
    commit 4447eaef6dc757aecab869054460ae87848e575e
    Author: Vladimir Petrov <[email protected]>
    Date:   Thu Aug 16 19:13:03 2012 +0300
        CameraHal: Add support to release tap in/outs

Change-Id: Ia6bfefb427fe171067eddcab6d896683ff2d149f
diff --git a/camera/CameraHal_Module.cpp b/camera/CameraHal_Module.cpp
index cb4e804..a9277a2 100644
--- a/camera/CameraHal_Module.cpp
+++ b/camera/CameraHal_Module.cpp
@@ -21,8 +21,6 @@
 *
 */
 
-#define LOG_TAG "CameraHAL"
-
 #include <utils/threads.h>
 
 #include "CameraHal.h"
@@ -30,8 +28,18 @@
 #include "TICameraParameters.h"
 
 
-static android::CameraProperties gCameraProperties;
-static android::CameraHal* gCameraHals[MAX_CAMERAS_SUPPORTED];
+#ifdef CAMERAHAL_DEBUG_VERBOSE
+#   define CAMHAL_LOG_MODULE_FUNCTION_NAME LOG_FUNCTION_NAME
+#else
+#   define CAMHAL_LOG_MODULE_FUNCTION_NAME
+#endif
+
+
+namespace Ti {
+namespace Camera {
+
+static CameraProperties gCameraProperties;
+static CameraHal* gCameraHals[MAX_CAMERAS_SUPPORTED];
 static unsigned int gCamerasOpen = 0;
 static android::Mutex gCameraHalDeviceLock;
 
@@ -45,6 +53,10 @@
         open: camera_device_open
 };
 
+} // namespace Camera
+} // namespace Ti
+
+
 camera_module_t HAL_MODULE_INFO_SYM = {
     common: {
          tag: HARDWARE_MODULE_TAG,
@@ -53,14 +65,18 @@
          id: CAMERA_HARDWARE_MODULE_ID,
          name: "TI OMAP CameraHal Module",
          author: "TI",
-         methods: &camera_module_methods,
+         methods: &Ti::Camera::camera_module_methods,
          dso: NULL, /* remove compilation warnings */
          reserved: {0}, /* remove compilation warnings */
     },
-    get_number_of_cameras: camera_get_number_of_cameras,
-    get_camera_info: camera_get_camera_info,
+    get_number_of_cameras: Ti::Camera::camera_get_number_of_cameras,
+    get_camera_info: Ti::Camera::camera_get_camera_info,
 };
 
+
+namespace Ti {
+namespace Camera {
+
 typedef struct ti_camera_device {
     camera_device_t base;
     /* TI specific "private" data can go here (base.priv) */
@@ -75,11 +91,11 @@
 int camera_set_preview_window(struct camera_device * device,
         struct preview_stream_ops *window)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
@@ -90,6 +106,61 @@
     return rv;
 }
 
+#ifdef OMAP_ENHANCEMENT_CPCAM
+int camera_set_extended_preview_ops(struct camera_device * device,
+        preview_stream_extended_ops_t * extendedOps)
+{
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
+    if (!device) {
+        return BAD_VALUE;
+    }
+
+    ti_camera_device_t * const tiDevice = reinterpret_cast<ti_camera_device_t*>(device);
+    gCameraHals[tiDevice->cameraid]->setExtendedPreviewStreamOps(extendedOps);
+
+    return OK;
+}
+
+int camera_set_buffer_source(struct camera_device * device,
+        struct preview_stream_ops *tapin,
+        struct preview_stream_ops *tapout)
+{
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
+    int rv = -EINVAL;
+    ti_camera_device_t* ti_dev = NULL;
+
+    if(!device)
+        return rv;
+
+    ti_dev = (ti_camera_device_t*) device;
+
+    rv = gCameraHals[ti_dev->cameraid]->setBufferSource(tapin, tapout);
+
+    return rv;
+}
+
+int camera_release_buffer_source(struct camera_device * device,
+                                 struct preview_stream_ops *tapin,
+                                 struct preview_stream_ops *tapout)
+{
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
+    int rv = -EINVAL;
+    ti_camera_device_t* ti_dev = NULL;
+
+    if(!device)
+        return rv;
+
+    ti_dev = (ti_camera_device_t*) device;
+
+    rv = gCameraHals[ti_dev->cameraid]->releaseBufferSource(tapin, tapout);
+
+    return rv;
+}
+#endif
+
 void camera_set_callbacks(struct camera_device * device,
         camera_notify_callback notify_cb,
         camera_data_callback data_cb,
@@ -97,9 +168,9 @@
         camera_request_memory get_memory,
         void *user)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return;
@@ -111,9 +182,9 @@
 
 void camera_enable_msg_type(struct camera_device * device, int32_t msg_type)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return;
@@ -125,9 +196,9 @@
 
 void camera_disable_msg_type(struct camera_device * device, int32_t msg_type)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return;
@@ -139,9 +210,9 @@
 
 int camera_msg_type_enabled(struct camera_device * device, int32_t msg_type)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return 0;
@@ -153,11 +224,11 @@
 
 int camera_start_preview(struct camera_device * device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
@@ -170,9 +241,9 @@
 
 void camera_stop_preview(struct camera_device * device)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return;
@@ -184,11 +255,11 @@
 
 int camera_preview_enabled(struct camera_device * device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
@@ -200,11 +271,11 @@
 
 int camera_store_meta_data_in_buffers(struct camera_device * device, int enable)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
@@ -218,11 +289,11 @@
 
 int camera_start_recording(struct camera_device * device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
@@ -234,9 +305,9 @@
 
 void camera_stop_recording(struct camera_device * device)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return;
@@ -248,11 +319,11 @@
 
 int camera_recording_enabled(struct camera_device * device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
@@ -265,9 +336,9 @@
 void camera_release_recording_frame(struct camera_device * device,
                 const void *opaque)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return;
@@ -279,11 +350,11 @@
 
 int camera_auto_focus(struct camera_device * device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
@@ -295,11 +366,11 @@
 
 int camera_cancel_auto_focus(struct camera_device * device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
@@ -311,26 +382,44 @@
 
 int camera_take_picture(struct camera_device * device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
     ti_dev = (ti_camera_device_t*) device;
 
-    rv = gCameraHals[ti_dev->cameraid]->takePicture();
+    rv = gCameraHals[ti_dev->cameraid]->takePicture(0);
     return rv;
 }
 
-int camera_cancel_picture(struct camera_device * device)
+#ifdef OMAP_ENHANCEMENT_CPCAM
+int camera_take_picture_with_parameters(struct camera_device * device, const char *params)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
+    if(!device)
+        return rv;
+
+    ti_dev = (ti_camera_device_t*) device;
+
+    rv = gCameraHals[ti_dev->cameraid]->takePicture(params);
+    return rv;
+}
+#endif
+
+int camera_cancel_picture(struct camera_device * device)
+{
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
+    int rv = -EINVAL;
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return rv;
@@ -341,12 +430,46 @@
     return rv;
 }
 
-int camera_set_parameters(struct camera_device * device, const char *params)
+#ifdef OMAP_ENHANCEMENT_CPCAM
+int camera_reprocess(struct camera_device * device, const char *params)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
+    if(!device)
+        return rv;
+
+    ti_dev = (ti_camera_device_t*) device;
+
+    rv = gCameraHals[ti_dev->cameraid]->reprocess(params);
+    return rv;
+}
+
+int camera_cancel_reprocess(struct camera_device * device)
+{
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
+    int rv = -EINVAL;
+    ti_camera_device_t* ti_dev = NULL;
+
+    if(!device)
+        return rv;
+
+    ti_dev = (ti_camera_device_t*) device;
+
+    rv = gCameraHals[ti_dev->cameraid]->cancel_reprocess();
+    return rv;
+}
+#endif
+
+int camera_set_parameters(struct camera_device * device, const char *params)
+{
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
+    int rv = -EINVAL;
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return rv;
@@ -359,11 +482,11 @@
 
 char* camera_get_parameters(struct camera_device * device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     char* param = NULL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return NULL;
 
@@ -376,9 +499,9 @@
 
 static void camera_put_parameters(struct camera_device *device, char *parms)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return;
@@ -391,25 +514,43 @@
 int camera_send_command(struct camera_device * device,
             int32_t cmd, int32_t arg1, int32_t arg2)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
     if(!device)
         return rv;
 
     ti_dev = (ti_camera_device_t*) device;
 
+#ifdef OMAP_ENHANCEMENT
+    if ( cmd == CAMERA_CMD_SETUP_EXTENDED_OPERATIONS ) {
+        camera_device_extended_ops_t * const ops = static_cast<camera_device_extended_ops_t*>(
+                camera_cmd_send_command_args_to_pointer(arg1, arg2));
+
+#ifdef OMAP_ENHANCEMENT_CPCAM
+        ops->set_extended_preview_ops = camera_set_extended_preview_ops;
+        ops->set_buffer_source = camera_set_buffer_source;
+        ops->release_buffer_source = camera_release_buffer_source;
+        ops->take_picture_with_parameters = camera_take_picture_with_parameters;
+        ops->reprocess = camera_reprocess;
+        ops->cancel_reprocess = camera_cancel_reprocess;
+#endif
+
+        return OK;
+    }
+#endif
+
     rv = gCameraHals[ti_dev->cameraid]->sendCommand(cmd, arg1, arg2);
     return rv;
 }
 
 void camera_release(struct camera_device * device)
 {
-    ti_camera_device_t* ti_dev = NULL;
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
 
-    ALOGV("%s", __FUNCTION__);
+    ti_camera_device_t* ti_dev = NULL;
 
     if(!device)
         return;
@@ -421,6 +562,8 @@
 
 int camera_dump(struct camera_device * device, int fd)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int rv = -EINVAL;
     ti_camera_device_t* ti_dev = NULL;
 
@@ -437,12 +580,12 @@
 
 int camera_device_close(hw_device_t* device)
 {
+    CAMHAL_LOG_MODULE_FUNCTION_NAME;
+
     int ret = 0;
     ti_camera_device_t* ti_dev = NULL;
 
-    ALOGV("%s", __FUNCTION__);
-
-    android::Mutex::Autolock lock(gCameraHalDeviceLock);
+    android::AutoMutex lock(gCameraHalDeviceLock);
 
     if (!device) {
         ret = -EINVAL;
@@ -488,10 +631,10 @@
     int cameraid;
     ti_camera_device_t* camera_device = NULL;
     camera_device_ops_t* camera_ops = NULL;
-    android::CameraHal* camera = NULL;
-    android::CameraProperties::Properties* properties = NULL;
+    CameraHal* camera = NULL;
+    CameraProperties::Properties* properties = NULL;
 
-    android::Mutex::Autolock lock(gCameraHalDeviceLock);
+    android::AutoMutex lock(gCameraHalDeviceLock);
 
     CAMHAL_LOGI("camera_device open");
 
@@ -501,7 +644,7 @@
 
         if(cameraid > num_cameras)
         {
-            ALOGE("camera service provided cameraid out of bounds, "
+            CAMHAL_LOGE("camera service provided cameraid out of bounds, "
                     "cameraid = %d, num supported = %d",
                     cameraid, num_cameras);
             rv = -EINVAL;
@@ -510,7 +653,7 @@
 
         if(gCamerasOpen >= MAX_SIMUL_CAMERAS_SUPPORTED)
         {
-            ALOGE("maximum number of cameras already open");
+            CAMHAL_LOGE("maximum number of cameras already open");
             rv = -ENOMEM;
             goto fail;
         }
@@ -518,7 +661,7 @@
         camera_device = (ti_camera_device_t*)malloc(sizeof(*camera_device));
         if(!camera_device)
         {
-            ALOGE("camera_device allocation fail");
+            CAMHAL_LOGE("camera_device allocation fail");
             rv = -ENOMEM;
             goto fail;
         }
@@ -526,7 +669,7 @@
         camera_ops = (camera_device_ops_t*)malloc(sizeof(*camera_ops));
         if(!camera_ops)
         {
-            ALOGE("camera_ops allocation fail");
+            CAMHAL_LOGE("camera_ops allocation fail");
             rv = -ENOMEM;
             goto fail;
         }
@@ -572,23 +715,23 @@
 
         if(gCameraProperties.getProperties(cameraid, &properties) < 0)
         {
-            ALOGE("Couldn't get camera properties");
+            CAMHAL_LOGE("Couldn't get camera properties");
             rv = -ENOMEM;
             goto fail;
         }
 
-        camera = new android::CameraHal(cameraid);
+        camera = new CameraHal(cameraid);
 
         if(!camera)
         {
-            ALOGE("Couldn't create instance of CameraHal class");
+            CAMHAL_LOGE("Couldn't create instance of CameraHal class");
             rv = -ENOMEM;
             goto fail;
         }
 
-        if(properties && (camera->initialize(properties) != android::NO_ERROR))
+        if(properties && (camera->initialize(properties) != NO_ERROR))
         {
-            ALOGE("Couldn't initialize camera instance");
+            CAMHAL_LOGE("Couldn't initialize camera instance");
             rv = -ENODEV;
             goto fail;
         }
@@ -620,19 +763,15 @@
 {
     int num_cameras = MAX_CAMERAS_SUPPORTED;
 
-    // TODO(XXX): Ducati is not loaded yet when camera service gets here
-    //  Lets revisit this later to see if we can somehow get this working
-#if 0
     // this going to be the first call from camera service
     // initialize camera properties here...
-    if(gCameraProperties.initialize() != android::NO_ERROR)
+    if(gCameraProperties.initialize() != NO_ERROR)
     {
         CAMHAL_LOGEA("Unable to create or initialize CameraProperties");
         return NULL;
     }
 
     num_cameras = gCameraProperties.camerasSupported();
-#endif
 
     return num_cameras;
 }
@@ -643,40 +782,41 @@
     int face_value = CAMERA_FACING_BACK;
     int orientation = 0;
     const char *valstr = NULL;
-    android::CameraProperties::Properties* properties = NULL;
+    CameraProperties::Properties* properties = NULL;
 
     // this going to be the first call from camera service
     // initialize camera properties here...
-    if(gCameraProperties.initialize() != android::NO_ERROR)
+    if(gCameraProperties.initialize() != NO_ERROR)
     {
         CAMHAL_LOGEA("Unable to create or initialize CameraProperties");
-        return NULL;
+        rv = -EINVAL;
+        goto end;
     }
 
     //Get camera properties for camera index
     if(gCameraProperties.getProperties(camera_id, &properties) < 0)
     {
-        ALOGE("Couldn't get camera properties");
+        CAMHAL_LOGE("Couldn't get camera properties");
         rv = -EINVAL;
         goto end;
     }
 
     if(properties)
     {
-        valstr = properties->get(android::CameraProperties::FACING_INDEX);
+        valstr = properties->get(CameraProperties::FACING_INDEX);
         if(valstr != NULL)
         {
-            if (strcmp(valstr, (const char *) android::TICameraParameters::FACING_FRONT) == 0)
+            if (strcmp(valstr, TICameraParameters::FACING_FRONT) == 0)
             {
                 face_value = CAMERA_FACING_FRONT;
             }
-            else if (strcmp(valstr, (const char *) android::TICameraParameters::FACING_BACK) == 0)
+            else if (strcmp(valstr, TICameraParameters::FACING_BACK) == 0)
             {
                 face_value = CAMERA_FACING_BACK;
             }
          }
 
-         valstr = properties->get(android::CameraProperties::ORIENTATION_INDEX);
+         valstr = properties->get(CameraProperties::ORIENTATION_INDEX);
          if(valstr != NULL)
          {
              orientation = atoi(valstr);
@@ -695,6 +835,5 @@
 }
 
 
-
-
-
+} // namespace Camera
+} // namespace Ti