blob: 6cae7d224851224be0cbf668715dd4b1bd183b4d [file] [log] [blame]
Alex Ray7ee0b7a2012-11-06 00:12:49 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
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#include <cstdlib>
Alex Ray819cfd82013-02-20 17:46:41 -080018#include <hardware/camera_common.h>
19#include <hardware/hardware.h>
Alex Raya0ed4be2013-02-25 15:02:16 -080020#include "Camera.h"
Alex Ray7ee0b7a2012-11-06 00:12:49 -080021
22//#define LOG_NDEBUG 0
Alex Ray819cfd82013-02-20 17:46:41 -080023#define LOG_TAG "DefaultCameraHAL"
Alex Ray7ee0b7a2012-11-06 00:12:49 -080024#include <cutils/log.h>
25
Alex Ray819cfd82013-02-20 17:46:41 -080026#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
27#include <cutils/trace.h>
28
29#include "CameraHAL.h"
Alex Ray7ee0b7a2012-11-06 00:12:49 -080030
31/*
32 * This file serves as the entry point to the HAL. It contains the module
33 * structure and functions used by the framework to load and interface to this
34 * HAL, as well as the handles to the individual camera devices.
35 */
36
37namespace default_camera_hal {
38
Alex Ray819cfd82013-02-20 17:46:41 -080039// Default Camera HAL has 2 cameras, front and rear.
40static CameraHAL gCameraHAL(2);
Alex Ray7ee0b7a2012-11-06 00:12:49 -080041
Alex Ray819cfd82013-02-20 17:46:41 -080042CameraHAL::CameraHAL(int num_cameras)
43 : mNumberOfCameras(num_cameras),
44 mCallbacks(NULL)
45{
Alex Raya0ed4be2013-02-25 15:02:16 -080046 int i;
47
48 // Allocate camera array and instantiate camera devices
49 mCameras = new Camera*[mNumberOfCameras];
50 for (i = 0; i < mNumberOfCameras; i++) {
51 mCameras[i] = new Camera(i);
52 }
Alex Ray819cfd82013-02-20 17:46:41 -080053}
Alex Ray7ee0b7a2012-11-06 00:12:49 -080054
Alex Ray819cfd82013-02-20 17:46:41 -080055CameraHAL::~CameraHAL()
56{
Alex Raya0ed4be2013-02-25 15:02:16 -080057 int i;
58
59 for (i = 0; i < mNumberOfCameras; i++) {
60 delete mCameras[i];
61 }
62 delete [] mCameras;
Alex Ray819cfd82013-02-20 17:46:41 -080063}
64
65int CameraHAL::getNumberOfCameras()
66{
67 ALOGV("%s: %d", __func__, mNumberOfCameras);
68 return mNumberOfCameras;
69}
70
71int CameraHAL::getCameraInfo(int id, struct camera_info* info)
72{
73 ALOGV("%s: camera id %d: info=%p", __func__, id, info);
74 if (id < 0 || id >= mNumberOfCameras) {
75 ALOGE("%s: Invalid camera id %d", __func__, id);
76 return -ENODEV;
77 }
78 // TODO: return device-specific static metadata
79 return 0;
80}
81
82int CameraHAL::setCallbacks(const camera_module_callbacks_t *callbacks)
83{
84 ALOGV("%s : callbacks=%p", __func__, callbacks);
85 mCallbacks = callbacks;
86 return 0;
87}
88
89int CameraHAL::open(const hw_module_t* mod, const char* name, hw_device_t** dev)
90{
91 int id;
92 char *nameEnd;
Alex Raya0ed4be2013-02-25 15:02:16 -080093 Camera *cam;
Alex Ray819cfd82013-02-20 17:46:41 -080094
95 ALOGV("%s: module=%p, name=%s, device=%p", __func__, mod, name, dev);
96 id = strtol(name, &nameEnd, 10);
97 if (nameEnd != NULL) {
98 ALOGE("%s: Invalid camera id name %s", __func__, name);
99 return -EINVAL;
100 } else if (id < 0 || id >= mNumberOfCameras) {
101 ALOGE("%s: Invalid camera id %d", __func__, id);
102 return -ENODEV;
103 }
Alex Raya0ed4be2013-02-25 15:02:16 -0800104 return mCameras[id]->open(mod, dev);
Alex Ray819cfd82013-02-20 17:46:41 -0800105}
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800106
107extern "C" {
108
109static int get_number_of_cameras()
110{
Alex Ray819cfd82013-02-20 17:46:41 -0800111 return gCameraHAL.getNumberOfCameras();
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800112}
113
114static int get_camera_info(int id, struct camera_info* info)
115{
Alex Ray819cfd82013-02-20 17:46:41 -0800116 return gCameraHAL.getCameraInfo(id, info);
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800117}
118
Alex Ray819cfd82013-02-20 17:46:41 -0800119static int set_callbacks(const camera_module_callbacks_t *callbacks)
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800120{
Alex Ray819cfd82013-02-20 17:46:41 -0800121 return gCameraHAL.setCallbacks(callbacks);
122}
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800123
Alex Ray819cfd82013-02-20 17:46:41 -0800124static int open_dev(const hw_module_t* mod, const char* name, hw_device_t** dev)
125{
126 return gCameraHAL.open(mod, name, dev);
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800127}
128
129static hw_module_methods_t gCameraModuleMethods = {
Alex Ray819cfd82013-02-20 17:46:41 -0800130 open : open_dev
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800131};
132
Alex Raybb13a322013-02-18 15:38:05 -0800133camera_module_t HAL_MODULE_INFO_SYM __attribute__ ((visibility("default"))) = {
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800134 common : {
135 tag : HARDWARE_MODULE_TAG,
136 module_api_version : CAMERA_MODULE_API_VERSION_2_0,
137 hal_api_version : HARDWARE_HAL_API_VERSION,
138 id : CAMERA_HARDWARE_MODULE_ID,
Alex Ray819cfd82013-02-20 17:46:41 -0800139 name : "Default Camera HAL",
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800140 author : "The Android Open Source Project",
141 methods : &gCameraModuleMethods,
142 dso : NULL,
143 reserved : {0},
144 },
145 get_number_of_cameras : get_number_of_cameras,
Alex Ray819cfd82013-02-20 17:46:41 -0800146 get_camera_info : get_camera_info,
147 set_callbacks : set_callbacks
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800148};
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800149} // extern "C"
Alex Ray819cfd82013-02-20 17:46:41 -0800150
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800151} // namespace default_camera_hal