blob: 0d5e6c406ced797469e8fbe2bd841c64f7705b13 [file] [log] [blame]
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -08001/*
2 * Copyright (C) 2015 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
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070017/**
18 * @addtogroup Camera
19 * @{
20 */
21
22/**
23 * @file NdkCameraMetadata.h
24 */
25
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080026/*
27 * This file defines an NDK API.
28 * Do not remove methods.
29 * Do not change method signatures.
30 * Do not change the value of constants.
31 * Do not change the size of any of the classes defined in here.
32 * Do not reference types that are not part of the NDK.
33 * Do not #include files that aren't part of the NDK.
34 */
35
36#ifndef _NDK_CAMERA_METADATA_H
37#define _NDK_CAMERA_METADATA_H
38
Elliott Hughes9dafdd62020-06-12 09:46:18 -070039#include <stdbool.h>
Yin-Chia Yeh7842b642018-03-06 10:41:19 -080040#include <stdint.h>
Dan Albertd7973ba2016-09-14 12:35:50 -070041#include <sys/cdefs.h>
42
Jiawen Chen9f713e82020-01-15 11:06:13 -050043#ifndef __ANDROID_VNDK__
Jiawen Chen9f713e82020-01-15 11:06:13 -050044#include "jni.h"
Jiawen Chen9f713e82020-01-15 11:06:13 -050045#endif /* __ANDROID_VNDK__ */
46
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080047#include "NdkCameraError.h"
48#include "NdkCameraMetadataTags.h"
49
Dan Albertd7973ba2016-09-14 12:35:50 -070050__BEGIN_DECLS
51
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070052/**
53 * ACameraMetadata is opaque type that provides access to read-only camera metadata like camera
54 * characteristics (via {@link ACameraManager_getCameraCharacteristics}) or capture results (via
55 * {@link ACameraCaptureSession_captureCallback_result}).
56 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080057typedef struct ACameraMetadata ACameraMetadata;
58
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070059/**
60 * Possible data types of a metadata entry.
61 *
62 * Keep in sync with system/media/include/system/camera_metadata.h
63 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080064enum {
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070065 /// Unsigned 8-bit integer (uint8_t)
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080066 ACAMERA_TYPE_BYTE = 0,
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070067 /// Signed 32-bit integer (int32_t)
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080068 ACAMERA_TYPE_INT32 = 1,
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070069 /// 32-bit float (float)
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080070 ACAMERA_TYPE_FLOAT = 2,
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070071 /// Signed 64-bit integer (int64_t)
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080072 ACAMERA_TYPE_INT64 = 3,
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070073 /// 64-bit float (double)
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080074 ACAMERA_TYPE_DOUBLE = 4,
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070075 /// A 64-bit fraction (ACameraMetadata_rational)
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080076 ACAMERA_TYPE_RATIONAL = 5,
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070077 /// Number of type fields
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080078 ACAMERA_NUM_TYPES
79};
80
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070081/**
82 * Definition of rational data type in {@link ACameraMetadata}.
83 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080084typedef struct ACameraMetadata_rational {
85 int32_t numerator;
86 int32_t denominator;
87} ACameraMetadata_rational;
88
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070089/**
90 * A single camera metadata entry.
91 *
92 * <p>Each entry is an array of values, though many metadata fields may only have 1 entry in the
93 * array.</p>
94 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080095typedef struct ACameraMetadata_entry {
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070096 /**
97 * The tag identifying the entry.
98 *
99 * <p> It is one of the values defined in {@link NdkCameraMetadataTags.h}, and defines how the
100 * entry should be interpreted and which parts of the API provide it.
101 * See {@link NdkCameraMetadataTags.h} for more details. </p>
102 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800103 uint32_t tag;
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700104
105 /**
106 * The data type of this metadata entry.
107 *
108 * <p>Must be one of ACAMERA_TYPE_* enum values defined above. A particular tag always has the
109 * same type.</p>
110 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800111 uint8_t type;
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700112
113 /**
114 * Count of elements (NOT count of bytes) in this metadata entry.
115 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800116 uint32_t count;
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700117
118 /**
119 * Pointer to the data held in this metadata entry.
120 *
121 * <p>The type field above defines which union member pointer is valid. The count field above
122 * defines the length of the data in number of elements.</p>
123 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800124 union {
125 uint8_t *u8;
126 int32_t *i32;
127 float *f;
128 int64_t *i64;
129 double *d;
130 ACameraMetadata_rational* r;
131 } data;
132} ACameraMetadata_entry;
133
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700134/**
135 * A single read-only camera metadata entry.
136 *
137 * <p>Each entry is an array of values, though many metadata fields may only have 1 entry in the
138 * array.</p>
139 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800140typedef struct ACameraMetadata_const_entry {
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700141 /**
142 * The tag identifying the entry.
143 *
144 * <p> It is one of the values defined in {@link NdkCameraMetadataTags.h}, and defines how the
145 * entry should be interpreted and which parts of the API provide it.
146 * See {@link NdkCameraMetadataTags.h} for more details. </p>
147 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800148 uint32_t tag;
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700149
150 /**
151 * The data type of this metadata entry.
152 *
153 * <p>Must be one of ACAMERA_TYPE_* enum values defined above. A particular tag always has the
154 * same type.</p>
155 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800156 uint8_t type;
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700157
158 /**
159 * Count of elements (NOT count of bytes) in this metadata entry.
160 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800161 uint32_t count;
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700162
163 /**
164 * Pointer to the data held in this metadata entry.
165 *
166 * <p>The type field above defines which union member pointer is valid. The count field above
167 * defines the length of the data in number of elements.</p>
168 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800169 union {
170 const uint8_t *u8;
171 const int32_t *i32;
172 const float *f;
173 const int64_t *i64;
174 const double *d;
175 const ACameraMetadata_rational* r;
176 } data;
177} ACameraMetadata_const_entry;
178
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700179/**
180 * Get a metadata entry from an input {@link ACameraMetadata}.
181 *
182 * <p>The memory of the data field in the returned entry is managed by camera framework. Do not
183 * attempt to free it.</p>
184 *
185 * @param metadata the {@link ACameraMetadata} of interest.
186 * @param tag the tag value of the camera metadata entry to be get.
187 * @param entry the output {@link ACameraMetadata_const_entry} will be filled here if the method
188 * call succeeeds.
189 *
190 * @return <ul>
191 * <li>{@link ACAMERA_OK} if the method call succeeds.</li>
192 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if metadata or entry is NULL.</li>
193 * <li>{@link ACAMERA_ERROR_METADATA_NOT_FOUND} if input metadata does not contain an entry
194 * of input tag value.</li></ul>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800195 */
196camera_status_t ACameraMetadata_getConstEntry(
Elliott Hughes85a41532018-06-18 13:17:24 -0700197 const ACameraMetadata* metadata,
198 uint32_t tag, /*out*/ACameraMetadata_const_entry* entry) __INTRODUCED_IN(24);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800199
200/**
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700201 * List all the entry tags in input {@link ACameraMetadata}.
202 *
203 * @param metadata the {@link ACameraMetadata} of interest.
204 * @param numEntries number of metadata entries in input {@link ACameraMetadata}
205 * @param tags the tag values of the metadata entries. Length of tags is returned in numEntries
206 * argument. The memory is managed by ACameraMetadata itself and must NOT be free/delete
207 * by application. Do NOT access tags after calling ACameraMetadata_free.
208 *
209 * @return <ul>
210 * <li>{@link ACAMERA_OK} if the method call succeeds.</li>
211 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if metadata, numEntries or tags is NULL.</li>
212 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons.</li></ul>
213 */
214camera_status_t ACameraMetadata_getAllTags(
Elliott Hughes85a41532018-06-18 13:17:24 -0700215 const ACameraMetadata* metadata,
216 /*out*/int32_t* numEntries, /*out*/const uint32_t** tags) __INTRODUCED_IN(24);
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700217
218/**
219 * Create a copy of input {@link ACameraMetadata}.
220 *
221 * <p>The returned ACameraMetadata must be freed by the application by {@link ACameraMetadata_free}
222 * after application is done using it.</p>
223 *
224 * @param src the input {@link ACameraMetadata} to be copied.
225 *
226 * @return a valid ACameraMetadata pointer or NULL if the input metadata cannot be copied.
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800227 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700228ACameraMetadata* ACameraMetadata_copy(const ACameraMetadata* src) __INTRODUCED_IN(24);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800229
230/**
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700231 * Free a {@link ACameraMetadata} structure.
232 *
233 * @param metadata the {@link ACameraMetadata} to be freed.
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800234 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700235void ACameraMetadata_free(ACameraMetadata* metadata) __INTRODUCED_IN(24);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800236
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800237/**
238 * Helper function to check if a camera is logical multi-camera.
239 *
240 * <p> Check whether a camera device is a logical multi-camera based on its
241 * static metadata. If it is, also returns its physical sub camera Ids.</p>
242 *
243 * @param staticMetadata the static metadata of the camera being checked.
244 * @param numPhysicalCameras returns the number of physical cameras.
245 * @param physicalCameraIds returns the array of physical camera Ids backing this logical
246 * camera device. Note that this pointer is only valid
247 * during the lifetime of the staticMetadata object.
248 *
249 * @return true if this is a logical multi-camera, false otherwise.
250 */
251bool ACameraMetadata_isLogicalMultiCamera(const ACameraMetadata* staticMetadata,
252 /*out*/size_t* numPhysicalCameras, /*out*/const char* const** physicalCameraIds)
253 __INTRODUCED_IN(29);
254
Jiawen Chen9f713e82020-01-15 11:06:13 -0500255#ifndef __ANDROID_VNDK__
Jiawen Chen9f713e82020-01-15 11:06:13 -0500256
257/**
258 * Return a {@link ACameraMetadata} that references the same data as
259 * {@link cameraMetadata}, which is an instance of
260 * {@link android.hardware.camera2.CameraMetadata} (e.g., a
261 * {@link android.hardware.camera2.CameraCharacteristics} or
262 * {@link android.hardware.camera2.CaptureResult}).
263 *
264 * <p>The returned ACameraMetadata must be freed by the application by {@link ACameraMetadata_free}
265 * after application is done using it.</p>
266 *
Eino-Ville Talvalab949b612020-02-06 11:08:41 -0800267 * <p>The ACameraMetadata maintains a reference count to the underlying data, so
268 * it can be used independently of the Java object, and it remains valid even if
269 * the Java metadata is garbage collected.
Jiawen Chen9f713e82020-01-15 11:06:13 -0500270 *
271 * @param env the JNI environment.
272 * @param cameraMetadata the source {@link android.hardware.camera2.CameraMetadata} from which the
273 * returned {@link ACameraMetadata} is a view.
274 *
275 * @return a valid ACameraMetadata pointer or NULL if {@link cameraMetadata} is null or not a valid
276 * instance of {@link android.hardware.camera2.CameraMetadata}.
277 *
278 */
279ACameraMetadata* ACameraMetadata_fromCameraMetadata(JNIEnv* env, jobject cameraMetadata)
280 __INTRODUCED_IN(30);
281
Jiawen Chen9f713e82020-01-15 11:06:13 -0500282#endif /* __ANDROID_VNDK__ */
283
Dan Albertd7973ba2016-09-14 12:35:50 -0700284__END_DECLS
285
286#endif /* _NDK_CAMERA_METADATA_H */
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700287
Eino-Ville Talvalab949b612020-02-06 11:08:41 -0800288/** @} */