|
| 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 | +//#define ALOG_NDEBUG 0 |
| 19 | +#define ALOG_NIDEBUG 0 |
| 20 | +#define LOG_TAG "QCameraHAL" |
| 21 | +#include <utils/Log.h> |
| 22 | +#include <utils/threads.h> |
| 23 | +#include <fcntl.h> |
| 24 | +#include <sys/mman.h> |
| 25 | + |
| 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 | + ALOGI("Handle base =0x%p",handle_base); |
| 61 | + ALOGI("getCameraInfo: numOfCameras = %d", HAL_numOfCameras); |
| 62 | + for(int i = 0; i < HAL_numOfCameras; i++) { |
| 63 | + ALOGI("Handle [%d]=0x%p",i,handle_base+i); |
| 64 | + HAL_camerahandle[i]=handle_base + i; |
| 65 | + p_camera_info = &(HAL_camerahandle[i]->camera_info); |
| 66 | + if (p_camera_info) { |
| 67 | + ALOGI("Camera sensor %d info:", i); |
| 68 | + ALOGI("camera_id: %d", p_camera_info->camera_id); |
| 69 | + ALOGI("modes_supported: %x", p_camera_info->modes_supported); |
| 70 | + ALOGI("position: %d", p_camera_info->position); |
| 71 | + ALOGI("sensor_mount_angle: %d", p_camera_info->sensor_mount_angle); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + ALOGV("%s: X", __func__); |
| 77 | + |
| 78 | + return HAL_numOfCameras; |
| 79 | +} |
| 80 | + |
| 81 | +extern "C" int HAL_isIn3DMode() |
| 82 | +{ |
| 83 | + return HAL_currentCameraMode == CAMERA_MODE_3D; |
| 84 | +} |
| 85 | + |
| 86 | +extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo) |
| 87 | +{ |
| 88 | + mm_camera_t *mm_camer_obj = 0; |
| 89 | + ALOGD("%s: E", __func__); |
| 90 | + |
| 91 | + if (!HAL_numOfCameras || HAL_numOfCameras < cameraId || !cameraInfo) |
| 92 | + return; |
| 93 | + else |
| 94 | + mm_camer_obj = HAL_camerahandle[cameraId]; |
| 95 | + |
| 96 | + if (!mm_camer_obj) |
| 97 | + return; |
| 98 | + else { |
| 99 | + cameraInfo->facing = |
| 100 | + (FRONT_CAMERA == mm_camer_obj->camera_info.position)? |
| 101 | + CAMERA_FACING_FRONT : CAMERA_FACING_BACK; |
| 102 | + |
| 103 | + cameraInfo->orientation = mm_camer_obj->camera_info.sensor_mount_angle; |
| 104 | +#if 0 |
| 105 | + // TODO: fix me |
| 106 | + /* We always supprot ZSL in our stack*/ |
| 107 | + cameraInfo->mode = CAMERA_SUPPORT_MODE_ZSL; |
| 108 | + if (mm_camer_obj->camera_info.modes_supported & CAMERA_MODE_2D) { |
| 109 | + cameraInfo->mode |= CAMERA_SUPPORT_MODE_2D; |
| 110 | + } |
| 111 | + if (mm_camer_obj->camera_info.modes_supported & CAMERA_MODE_3D) { |
| 112 | + cameraInfo->mode |= CAMERA_SUPPORT_MODE_3D; |
| 113 | + } |
| 114 | +#endif |
| 115 | + } |
| 116 | + ALOGV("%s: X", __func__); |
| 117 | + return; |
| 118 | +} |
| 119 | + |
| 120 | +/* HAL should return NULL if it fails to open camera hardware. */ |
| 121 | +extern "C" void * HAL_openCameraHardware(int cameraId, int mode) |
| 122 | +{ |
| 123 | + ALOGV("%s: E", __func__); |
| 124 | + if (!HAL_numOfCameras || HAL_numOfCameras < cameraId ||cameraId < 0) { |
| 125 | + return NULL; |
| 126 | + } |
| 127 | + return QCameraHAL_openCameraHardware(cameraId, mode); |
| 128 | +} |
| 129 | + |
| 130 | + |
| 131 | +}; // namespace android |
0 commit comments