1/*
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// FIXME: add well-defined names for cameras
18
19#ifndef ANDROID_INCLUDE_CAMERA_COMMON_H
20#define ANDROID_INCLUDE_CAMERA_COMMON_H
21
22#include <stdint.h>
23#include <sys/cdefs.h>
24#include <sys/types.h>
25#include <cutils/native_handle.h>
26#include <system/camera.h>
27#include <hardware/hardware.h>
28#include <hardware/gralloc.h>
29
30__BEGIN_DECLS
31
32/**
33 * The id of this module
34 */
35#define CAMERA_HARDWARE_MODULE_ID "camera"
36
37/**
38 * Module versioning information for the Camera hardware module, based on
39 * camera_module_t.common.module_api_version. The two most significant hex
40 * digits represent the major version, and the two least significant represent
41 * the minor version.
42 *
43 *******************************************************************************
44 * Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
45 *
46 *   Camera modules that report these version numbers implement the initial
47 *   camera module HAL interface. All camera devices openable through this
48 *   module support only version 1 of the camera device HAL. The device_version
49 *   and static_camera_characteristics fields of camera_info are not valid. Only
50 *   the android.hardware.Camera API can be supported by this module and its
51 *   devices.
52 *
53 *******************************************************************************
54 * Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
55 *
56 *   Camera modules that report this version number implement the second version
57 *   of the camera module HAL interface. Camera devices openable through this
58 *   module may support either version 1.0 or version 2.0 of the camera device
59 *   HAL interface. The device_version field of camera_info is always valid; the
60 *   static_camera_characteristics field of camera_info is valid if the
61 *   device_version field is 2.0 or higher.
62 */
63
64/**
65 * Predefined macros for currently-defined version numbers
66 */
67
68/**
69 * All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
70 * as CAMERA_MODULE_API_VERSION_1_0
71 */
72#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
73#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
74
75#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_0
76
77/**
78 * All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
79 * as CAMERA_DEVICE_API_VERSION_1_0
80 */
81#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
82#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
83
84// Device version 2.0 is experimental
85#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_1_0
86
87/**
88 * Defined in /system/media/camera/include/system/camera_metadata.h
89 */
90typedef struct camera_metadata camera_metadata_t;
91
92struct camera_info {
93    /**
94     * The direction that the camera faces to. It should be CAMERA_FACING_BACK
95     * or CAMERA_FACING_FRONT.
96     *
97     * Version information:
98     *   Valid in all camera_module versions
99     */
100    int facing;
101
102    /**
103     * The orientation of the camera image. The value is the angle that the
104     * camera image needs to be rotated clockwise so it shows correctly on the
105     * display in its natural orientation. It should be 0, 90, 180, or 270.
106     *
107     * For example, suppose a device has a naturally tall screen. The
108     * back-facing camera sensor is mounted in landscape. You are looking at
109     * the screen. If the top side of the camera sensor is aligned with the
110     * right edge of the screen in natural orientation, the value should be
111     * 90. If the top side of a front-facing camera sensor is aligned with the
112     * right of the screen, the value should be 270.
113     *
114     * Version information:
115     *   Valid in all camera_module versions
116     */
117    int orientation;
118
119    /**
120     * The value of camera_device_t.common.version.
121     *
122     * Version information (based on camera_module_t.common.module_api_version):
123     *
124     *  CAMERA_MODULE_API_VERSION_1_0:
125     *
126     *    Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
127     *    not read this field.
128     *
129     *  CAMERA_MODULE_API_VERSION_2_0:
130     *
131     *    Always valid
132     *
133     */
134    uint32_t device_version;
135
136    /**
137     * The camera's fixed characteristics, which include all camera metadata in
138     * the android.*.info.* sections. This should be a sorted metadata buffer,
139     * and may not be modified or freed by the caller. The pointer should remain
140     * valid for the lifetime of the camera module.
141     *
142     * Version information (based on camera_module_t.common.module_api_version):
143     *
144     *  CAMERA_MODULE_API_VERSION_1_0:
145     *
146     *    Not valid. Extra characteristics are not available. Do not read this
147     *    field.
148     *
149     *  CAMERA_MODULE_API_VERSION_2_0:
150     *
151     *    Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
152     *    otherwise.
153     *
154     */
155    const camera_metadata_t *static_camera_characteristics;
156};
157
158typedef struct camera_module {
159    hw_module_t common;
160    int (*get_number_of_cameras)(void);
161    int (*get_camera_info)(int camera_id, struct camera_info *info);
162} camera_module_t;
163
164__END_DECLS
165
166#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */
167