1 /*
2 ** Copyright (c) 2011 Code Aurora Forum. 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 LOG_NDEBUG 0
20 #define LOG_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
28 /* include QCamera Hardware Interface Header*/
29 #include "QCameraHAL.h"
30
31 int HAL_numOfCameras = 0;
32 camera_info_t HAL_cameraInfo[MSM_MAX_CAMERA_SENSORS];
33 mm_camera_t * HAL_camerahandle[MSM_MAX_CAMERA_SENSORS];
34 int HAL_currentCameraMode;
35
36 namespace android {
37 /* HAL function implementation goes here*/
38
39 /**
40 * The functions need to be provided by the camera HAL.
41 *
42 * If getNumberOfCameras() returns N, the valid cameraId for getCameraInfo()
43 * and openCameraHardware() is 0 to N-1.
44 */
HAL_getNumberOfCameras()45 extern "C" int HAL_getNumberOfCameras()
46 {
47 /* try to query every time we get the call!*/
48 uint8_t num_camera = 0;
49 mm_camera_t * handle_base = 0;
50 LOGV("%s: E", __func__);
51
52 handle_base= mm_camera_query(&num_camera);
53
54 if (!handle_base) {
55 HAL_numOfCameras = 0;
56 }
57 else
58 {
59 camera_info_t* p_camera_info = 0;
60 HAL_numOfCameras=num_camera;
61
62 LOGI("Handle base =0x%p",handle_base);
63 LOGI("getCameraInfo: numOfCameras = %d", HAL_numOfCameras);
64 for(int i = 0; i < HAL_numOfCameras; i++) {
65 LOGI("Handle [%d]=0x%p",i,handle_base+i);
66 HAL_camerahandle[i]=handle_base + i;
67 p_camera_info = &(HAL_camerahandle[i]->camera_info);
68 if (p_camera_info) {
69 LOGI("Camera sensor %d info:", i);
70 LOGI("camera_id: %d", p_camera_info->camera_id);
71 LOGI("modes_supported: %x", p_camera_info->modes_supported);
72 LOGI("position: %d", p_camera_info->position);
73 LOGI("sensor_mount_angle: %d", p_camera_info->sensor_mount_angle);
74 }
75 }
76 }
77
78 LOGV("%s: X", __func__);
79
80 return HAL_numOfCameras;
81 }
82
HAL_isIn3DMode()83 extern "C" int HAL_isIn3DMode()
84 {
85 return HAL_currentCameraMode == CAMERA_MODE_3D;
86 }
87
HAL_getCameraInfo(int cameraId,struct CameraInfo * cameraInfo)88 extern "C" void HAL_getCameraInfo(int cameraId, struct CameraInfo* cameraInfo)
89 {
90 mm_camera_t *mm_camer_obj = 0;
91 LOGV("%s: E", __func__);
92
93 if (!HAL_numOfCameras || HAL_numOfCameras < cameraId || !cameraInfo)
94 return;
95 else
96 mm_camer_obj = HAL_camerahandle[cameraId];
97
98 if (!mm_camer_obj)
99 return;
100 else {
101 cameraInfo->facing =
102 (FRONT_CAMERA == mm_camer_obj->camera_info.position)?
103 CAMERA_FACING_FRONT : CAMERA_FACING_BACK;
104
105 cameraInfo->orientation = mm_camer_obj->camera_info.sensor_mount_angle;
106 #if 0
107 // TODO: fix me
108 /* We always supprot ZSL in our stack*/
109 cameraInfo->mode = CAMERA_SUPPORT_MODE_ZSL;
110 if (mm_camer_obj->camera_info.modes_supported & CAMERA_MODE_2D) {
111 cameraInfo->mode |= CAMERA_SUPPORT_MODE_2D;
112 }
113 if (mm_camer_obj->camera_info.modes_supported & CAMERA_MODE_3D) {
114 cameraInfo->mode |= CAMERA_SUPPORT_MODE_3D;
115 }
116 #endif
117 }
118 LOGV("%s: X", __func__);
119 return;
120 }
121
122 /* HAL should return NULL if it fails to open camera hardware. */
HAL_openCameraHardware(int cameraId,int mode)123 extern "C" void * HAL_openCameraHardware(int cameraId, int mode)
124 {
125 LOGV("%s: E", __func__);
126 if (!HAL_numOfCameras || HAL_numOfCameras < cameraId ||cameraId < 0) {
127 return NULL;
128 }
129 return QCameraHAL_openCameraHardware(cameraId, mode);
130 }
131
132
133 }; // namespace android
134