blob: abc32784466cc44baed579e9becd812ebf6ec9f1 [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>
18#include <hardware/camera2.h>
19
20//#define LOG_NDEBUG 0
21#define LOG_TAG "CameraHAL"
22#include <cutils/log.h>
23
24#include "Camera.h"
25
26/*
27 * This file serves as the entry point to the HAL. It contains the module
28 * structure and functions used by the framework to load and interface to this
29 * HAL, as well as the handles to the individual camera devices.
30 */
31
32namespace default_camera_hal {
33
34enum camera_id_t {
35 CAMERA_A,
36 CAMERA_B,
37 NUM_CAMERAS
38};
39
40// Symbol used by the framework when loading the HAL, defined below.
41extern "C" camera_module_t HAL_MODULE_INFO_SYM;
42
43// Camera devices created when the module is loaded. See Camera.h
44static Camera gCameras[NUM_CAMERAS] = {
45 Camera(CAMERA_A, &HAL_MODULE_INFO_SYM.common),
46 Camera(CAMERA_B, &HAL_MODULE_INFO_SYM.common)
47};
48
49extern "C" {
50
51static int get_number_of_cameras()
52{
53 ALOGV("%s", __func__);
54 return NUM_CAMERAS;
55}
56
57static int get_camera_info(int id, struct camera_info* info)
58{
59 ALOGV("%s: camera id %d: info=%p", __func__, id, info);
60 if (id < 0 || id >= NUM_CAMERAS) {
61 ALOGE("%s: Invalid camera id %d", __func__, id);
62 return -ENODEV;
63 }
64 return gCameras[id].getCameraInfo(info);
65}
66
Alex Raybb13a322013-02-18 15:38:05 -080067static int open_device(const hw_module_t* module, const char* name,
68 hw_device_t** device)
Alex Ray7ee0b7a2012-11-06 00:12:49 -080069{
70 ALOGV("%s: module=%p, name=%s, device=%p", __func__, module, name, device);
71 char *nameEnd;
72 int id;
73
74 id = strtol(name, &nameEnd, 10);
75 if (nameEnd != NULL) {
76 ALOGE("%s: Invalid camera id name %s", __func__, name);
77 return -EINVAL;
78 } else if (id < 0 || id >= NUM_CAMERAS) {
79 ALOGE("%s: Invalid camera id %d", __func__, id);
80 return -ENODEV;
81 }
82 *device = &gCameras[id].mDevice.common;
83 return gCameras[id].open();
84}
85
86static hw_module_methods_t gCameraModuleMethods = {
87 open : open_device
88};
89
Alex Raybb13a322013-02-18 15:38:05 -080090camera_module_t HAL_MODULE_INFO_SYM __attribute__ ((visibility("default"))) = {
Alex Ray7ee0b7a2012-11-06 00:12:49 -080091 common : {
92 tag : HARDWARE_MODULE_TAG,
93 module_api_version : CAMERA_MODULE_API_VERSION_2_0,
94 hal_api_version : HARDWARE_HAL_API_VERSION,
95 id : CAMERA_HARDWARE_MODULE_ID,
96 name : "Reference Camera v2 HAL",
97 author : "The Android Open Source Project",
98 methods : &gCameraModuleMethods,
99 dso : NULL,
100 reserved : {0},
101 },
102 get_number_of_cameras : get_number_of_cameras,
103 get_camera_info : get_camera_info
104};
105
106} // extern "C"
107} // namespace default_camera_hal