blob: 22c7aef485eb71f837976140453a4c04bec288b5 [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
67static int open_device(const hw_module_t* module,
68 const char* name,
69 hw_device_t** device)
70{
71 ALOGV("%s: module=%p, name=%s, device=%p", __func__, module, name, device);
72 char *nameEnd;
73 int id;
74
75 id = strtol(name, &nameEnd, 10);
76 if (nameEnd != NULL) {
77 ALOGE("%s: Invalid camera id name %s", __func__, name);
78 return -EINVAL;
79 } else if (id < 0 || id >= NUM_CAMERAS) {
80 ALOGE("%s: Invalid camera id %d", __func__, id);
81 return -ENODEV;
82 }
83 *device = &gCameras[id].mDevice.common;
84 return gCameras[id].open();
85}
86
87static hw_module_methods_t gCameraModuleMethods = {
88 open : open_device
89};
90
91camera_module_t HAL_MODULE_INFO_SYM = {
92 common : {
93 tag : HARDWARE_MODULE_TAG,
94 module_api_version : CAMERA_MODULE_API_VERSION_2_0,
95 hal_api_version : HARDWARE_HAL_API_VERSION,
96 id : CAMERA_HARDWARE_MODULE_ID,
97 name : "Reference Camera v2 HAL",
98 author : "The Android Open Source Project",
99 methods : &gCameraModuleMethods,
100 dso : NULL,
101 reserved : {0},
102 },
103 get_number_of_cameras : get_number_of_cameras,
104 get_camera_info : get_camera_info
105};
106
107} // extern "C"
108} // namespace default_camera_hal