summaryrefslogtreecommitdiffstats
path: root/modules/camera/CameraHAL.cpp
blob: 22c7aef485eb71f837976140453a4c04bec288b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <cstdlib>
#include <hardware/camera2.h>

//#define LOG_NDEBUG 0
#define LOG_TAG "CameraHAL"
#include <cutils/log.h>

#include "Camera.h"

/*
 * This file serves as the entry point to the HAL.  It contains the module
 * structure and functions used by the framework to load and interface to this
 * HAL, as well as the handles to the individual camera devices.
 */

namespace default_camera_hal {

enum camera_id_t {
    CAMERA_A,
    CAMERA_B,
    NUM_CAMERAS
};

// Symbol used by the framework when loading the HAL, defined below.
extern "C" camera_module_t HAL_MODULE_INFO_SYM;

// Camera devices created when the module is loaded. See Camera.h
static Camera gCameras[NUM_CAMERAS] = {
    Camera(CAMERA_A, &HAL_MODULE_INFO_SYM.common),
    Camera(CAMERA_B, &HAL_MODULE_INFO_SYM.common)
};

extern "C" {

static int get_number_of_cameras()
{
    ALOGV("%s", __func__);
    return NUM_CAMERAS;
}

static int get_camera_info(int id, struct camera_info* info)
{
    ALOGV("%s: camera id %d: info=%p", __func__, id, info);
    if (id < 0 || id >= NUM_CAMERAS) {
        ALOGE("%s: Invalid camera id %d", __func__, id);
        return -ENODEV;
    }
    return gCameras[id].getCameraInfo(info);
}

static int open_device(const hw_module_t* module,
                       const char* name,
                       hw_device_t** device)
{
    ALOGV("%s: module=%p, name=%s, device=%p", __func__, module, name, device);
    char *nameEnd;
    int id;

    id = strtol(name, &nameEnd, 10);
    if (nameEnd != NULL) {
        ALOGE("%s: Invalid camera id name %s", __func__, name);
        return -EINVAL;
    } else if (id < 0 || id >= NUM_CAMERAS) {
        ALOGE("%s: Invalid camera id %d", __func__, id);
        return -ENODEV;
    }
    *device = &gCameras[id].mDevice.common;
    return gCameras[id].open();
}

static hw_module_methods_t gCameraModuleMethods = {
    open : open_device
};

camera_module_t HAL_MODULE_INFO_SYM = {
    common : {
        tag                : HARDWARE_MODULE_TAG,
        module_api_version : CAMERA_MODULE_API_VERSION_2_0,
        hal_api_version    : HARDWARE_HAL_API_VERSION,
        id                 : CAMERA_HARDWARE_MODULE_ID,
        name               : "Reference Camera v2 HAL",
        author             : "The Android Open Source Project",
        methods            : &gCameraModuleMethods,
        dso                : NULL,
        reserved           : {0},
    },
    get_number_of_cameras : get_number_of_cameras,
    get_camera_info       : get_camera_info
};

} // extern "C"
} // namespace default_camera_hal