Home | History | Annotate | Download | only in camera
      1 /*
      2 ** Copyright (c) 2011 The Linux Foundation. All rights reserved.
      3 **
      4 ** Licensed under the Apache License, Version 2.0 (the "License");
      5 ** you may not use this file except in compliance with the License.
      6 ** You may obtain a copy of the License at
      7 **
      8 **     http://www.apache.org/licenses/LICENSE-2.0
      9 **
     10 ** Unless required by applicable law or agreed to in writing, software
     11 ** distributed under the License is distributed on an "AS IS" BASIS,
     12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 ** See the License for the specific language governing permissions and
     14 ** limitations under the License.
     15 */
     16 
     17 /*#error uncomment this for compiler test!*/
     18 
     19 //#define ALOG_NDEBUG 0
     20 #define ALOG_NIDEBUG 0
     21 #define LOG_TAG "QCameraHAL"
     22 #include <utils/Log.h>
     23 #include <utils/threads.h>
     24 #include <fcntl.h>
     25 #include <sys/mman.h>
     26 
     27 /* include QCamera Hardware Interface Header*/
     28 #include "QCameraHAL.h"
     29 
     30 int HAL_numOfCameras = 0;
     31 qcamera_info_t HAL_cameraInfo[MSM_MAX_CAMERA_SENSORS];
     32 mm_camera_t * HAL_camerahandle[MSM_MAX_CAMERA_SENSORS];
     33 int HAL_currentCameraMode;
     34 
     35 namespace android {
     36 /* HAL function implementation goes here*/
     37 
     38 /**
     39  * The functions need to be provided by the camera HAL.
     40  *
     41  * If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
     42  * and openCameraHardware() is 0 to N-1.
     43  */
     44 extern "C" int HAL_getNumberOfCameras()
     45 {
     46     /* try to query every time we get the call!*/
     47     uint8_t num_camera = 0;
     48     mm_camera_t * handle_base = 0;
     49     ALOGV("%s: E", __func__);
     50 
     51     handle_base= mm_camera_query(&num_camera);
     52 
     53     if (!handle_base) {
     54         HAL_numOfCameras = 0;
     55     }
     56     else
     57     {
     58         qcamera_info_t* p_camera_info = 0;
     59         HAL_numOfCameras=num_camera;
     60 
     61         ALOGI("Handle base =0x%p",handle_base);
     62         ALOGI("getCameraInfo: numOfCameras = %d", HAL_numOfCameras);
     63         for(int i = 0; i < HAL_numOfCameras; i++) {
     64             ALOGI("Handle [%d]=0x%p",i,handle_base+i);
     65             HAL_camerahandle[i]=handle_base + i;
     66             p_camera_info = &(HAL_camerahandle[i]->camera_info);
     67             if (p_camera_info) {
     68                 ALOGI("Camera sensor %d info:", i);
     69                 ALOGI("camera_id: %d", p_camera_info->camera_id);
     70                 ALOGI("modes_supported: %x", p_camera_info->modes_supported);
     71                 ALOGI("position: %d", p_camera_info->position);
     72                 ALOGI("sensor_mount_angle: %d", p_camera_info->sensor_mount_angle);
     73             }
     74         }
     75     }
     76 
     77     ALOGV("%s: X", __func__);
     78 
     79     return HAL_numOfCameras;
     80 }
     81 
     82 extern "C" int HAL_isIn3DMode()
     83 {
     84     return HAL_currentCameraMode == CAMERA_MODE_3D;
     85 }
     86 
     87 extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo)
     88 {
     89     mm_camera_t *mm_camer_obj = 0;
     90     ALOGV("%s: E", __func__);
     91 
     92     if (!HAL_numOfCameras || HAL_numOfCameras < cameraId || !cameraInfo)
     93         return;
     94     else
     95         mm_camer_obj = HAL_camerahandle[cameraId];
     96 
     97     if (!mm_camer_obj)
     98         return;
     99     else {
    100         cameraInfo->facing =
    101             (FRONT_CAMERA == mm_camer_obj->camera_info.position)?
    102             CAMERA_FACING_FRONT : CAMERA_FACING_BACK;
    103 
    104         cameraInfo->orientation = mm_camer_obj->camera_info.sensor_mount_angle;
    105 #if 0
    106         // TODO: fix me
    107         /* We always supprot ZSL in our stack*/
    108         cameraInfo->mode = CAMERA_SUPPORT_MODE_ZSL;
    109         if (mm_camer_obj->camera_info.modes_supported & CAMERA_MODE_2D) {
    110             cameraInfo->mode |= CAMERA_SUPPORT_MODE_2D;
    111         }
    112         if (mm_camer_obj->camera_info.modes_supported & CAMERA_MODE_3D) {
    113             cameraInfo->mode |= CAMERA_SUPPORT_MODE_3D;
    114         }
    115 #endif
    116     }
    117    ALOGV("%s: X", __func__);
    118    return;
    119 }
    120 
    121 /* HAL should return NULL if it fails to open camera hardware. */
    122 extern "C" void * HAL_openCameraHardware(int cameraId, int mode)
    123 {
    124     ALOGV("%s: E", __func__);
    125     if (!HAL_numOfCameras || HAL_numOfCameras < cameraId ||cameraId < 0) {
    126       return NULL;
    127     }
    128     return QCameraHAL_openCameraHardware(cameraId, mode);
    129 }
    130 
    131 
    132 }; // namespace android
    133