blob: 988090833e0b9e8b39805cd01c108db0ef99f7f2 [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 Ray7ee0b7a2012-11-06 00:12:49 -080020
21//#define LOG_NDEBUG 0
Alex Ray819cfd82013-02-20 17:46:41 -080022#define LOG_TAG "DefaultCameraHAL"
Alex Ray7ee0b7a2012-11-06 00:12:49 -080023#include <cutils/log.h>
24
Alex Ray819cfd82013-02-20 17:46:41 -080025#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
26#include <cutils/trace.h>
27
28#include "CameraHAL.h"
Alex Ray7ee0b7a2012-11-06 00:12:49 -080029
30/*
31 * This file serves as the entry point to the HAL. It contains the module
32 * structure and functions used by the framework to load and interface to this
33 * HAL, as well as the handles to the individual camera devices.
34 */
35
36namespace default_camera_hal {
37
Alex Ray819cfd82013-02-20 17:46:41 -080038// Default Camera HAL has 2 cameras, front and rear.
39static CameraHAL gCameraHAL(2);
Alex Ray7ee0b7a2012-11-06 00:12:49 -080040
Alex Ray819cfd82013-02-20 17:46:41 -080041CameraHAL::CameraHAL(int num_cameras)
42 : mNumberOfCameras(num_cameras),
43 mCallbacks(NULL)
44{
45}
Alex Ray7ee0b7a2012-11-06 00:12:49 -080046
Alex Ray819cfd82013-02-20 17:46:41 -080047CameraHAL::~CameraHAL()
48{
49}
50
51int CameraHAL::getNumberOfCameras()
52{
53 ALOGV("%s: %d", __func__, mNumberOfCameras);
54 return mNumberOfCameras;
55}
56
57int CameraHAL::getCameraInfo(int id, struct camera_info* info)
58{
59 ALOGV("%s: camera id %d: info=%p", __func__, id, info);
60 if (id < 0 || id >= mNumberOfCameras) {
61 ALOGE("%s: Invalid camera id %d", __func__, id);
62 return -ENODEV;
63 }
64 // TODO: return device-specific static metadata
65 return 0;
66}
67
68int CameraHAL::setCallbacks(const camera_module_callbacks_t *callbacks)
69{
70 ALOGV("%s : callbacks=%p", __func__, callbacks);
71 mCallbacks = callbacks;
72 return 0;
73}
74
75int CameraHAL::open(const hw_module_t* mod, const char* name, hw_device_t** dev)
76{
77 int id;
78 char *nameEnd;
79
80 ALOGV("%s: module=%p, name=%s, device=%p", __func__, mod, name, dev);
81 id = strtol(name, &nameEnd, 10);
82 if (nameEnd != NULL) {
83 ALOGE("%s: Invalid camera id name %s", __func__, name);
84 return -EINVAL;
85 } else if (id < 0 || id >= mNumberOfCameras) {
86 ALOGE("%s: Invalid camera id %d", __func__, id);
87 return -ENODEV;
88 }
89 // TODO: check for existing use; allocate and return new camera device
90 return 0;
91}
Alex Ray7ee0b7a2012-11-06 00:12:49 -080092
93extern "C" {
94
95static int get_number_of_cameras()
96{
Alex Ray819cfd82013-02-20 17:46:41 -080097 return gCameraHAL.getNumberOfCameras();
Alex Ray7ee0b7a2012-11-06 00:12:49 -080098}
99
100static int get_camera_info(int id, struct camera_info* info)
101{
Alex Ray819cfd82013-02-20 17:46:41 -0800102 return gCameraHAL.getCameraInfo(id, info);
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800103}
104
Alex Ray819cfd82013-02-20 17:46:41 -0800105static int set_callbacks(const camera_module_callbacks_t *callbacks)
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800106{
Alex Ray819cfd82013-02-20 17:46:41 -0800107 return gCameraHAL.setCallbacks(callbacks);
108}
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800109
Alex Ray819cfd82013-02-20 17:46:41 -0800110static int open_dev(const hw_module_t* mod, const char* name, hw_device_t** dev)
111{
112 return gCameraHAL.open(mod, name, dev);
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800113}
114
115static hw_module_methods_t gCameraModuleMethods = {
Alex Ray819cfd82013-02-20 17:46:41 -0800116 open : open_dev
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800117};
118
Alex Raybb13a322013-02-18 15:38:05 -0800119camera_module_t HAL_MODULE_INFO_SYM __attribute__ ((visibility("default"))) = {
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800120 common : {
121 tag : HARDWARE_MODULE_TAG,
122 module_api_version : CAMERA_MODULE_API_VERSION_2_0,
123 hal_api_version : HARDWARE_HAL_API_VERSION,
124 id : CAMERA_HARDWARE_MODULE_ID,
Alex Ray819cfd82013-02-20 17:46:41 -0800125 name : "Default Camera HAL",
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800126 author : "The Android Open Source Project",
127 methods : &gCameraModuleMethods,
128 dso : NULL,
129 reserved : {0},
130 },
131 get_number_of_cameras : get_number_of_cameras,
Alex Ray819cfd82013-02-20 17:46:41 -0800132 get_camera_info : get_camera_info,
133 set_callbacks : set_callbacks
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800134};
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800135} // extern "C"
Alex Ray819cfd82013-02-20 17:46:41 -0800136
Alex Ray7ee0b7a2012-11-06 00:12:49 -0800137} // namespace default_camera_hal