blob: ca28b993d55bc54d8e803b6ec39186a7ccc26a20 [file] [log] [blame]
Alex Ray61f7a0c2013-07-03 17:54:19 -07001/*
2 * Copyright (C) 2013 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 <system/camera_metadata.h>
18#include "Camera.h"
19
20//#define LOG_NDEBUG 0
21#define LOG_TAG "ExampleCamera"
22#include <cutils/log.h>
23
24#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
25#include <utils/Trace.h>
26
27#include "ExampleCamera.h"
28
29#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
30
31namespace default_camera_hal {
32
33ExampleCamera::ExampleCamera(int id) : Camera(id)
34{
35}
36
37ExampleCamera::~ExampleCamera()
38{
39}
40
41camera_metadata_t *ExampleCamera::initStaticInfo()
42{
43 /*
44 * Setup static camera info. This will have to customized per camera
45 * device.
46 */
47 Metadata m;
48
49 /* android.control */
50 int32_t android_control_ae_available_target_fps_ranges[] = {30, 30};
51 m.addInt32(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,
52 ARRAY_SIZE(android_control_ae_available_target_fps_ranges),
53 android_control_ae_available_target_fps_ranges);
54
55 int32_t android_control_ae_compensation_range[] = {-4, 4};
56 m.addInt32(ANDROID_CONTROL_AE_COMPENSATION_RANGE,
57 ARRAY_SIZE(android_control_ae_compensation_range),
58 android_control_ae_compensation_range);
59
60 camera_metadata_rational_t android_control_ae_compensation_step[] = {{2,1}};
61 m.addRational(ANDROID_CONTROL_AE_COMPENSATION_STEP,
62 ARRAY_SIZE(android_control_ae_compensation_step),
63 android_control_ae_compensation_step);
64
Ruben Brunk80df5b52014-01-23 18:26:28 -080065 int32_t android_control_max_regions[] = {/*AE*/ 1,/*AWB*/ 1,/*AF*/ 1};
Alex Ray61f7a0c2013-07-03 17:54:19 -070066 m.addInt32(ANDROID_CONTROL_MAX_REGIONS,
67 ARRAY_SIZE(android_control_max_regions),
68 android_control_max_regions);
69
70 /* android.jpeg */
71 int32_t android_jpeg_available_thumbnail_sizes[] = {0, 0, 128, 96};
72 m.addInt32(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES,
73 ARRAY_SIZE(android_jpeg_available_thumbnail_sizes),
74 android_jpeg_available_thumbnail_sizes);
75
76 int32_t android_jpeg_max_size[] = {13 * 1024 * 1024}; // 13MB
77 m.addInt32(ANDROID_JPEG_MAX_SIZE,
78 ARRAY_SIZE(android_jpeg_max_size),
79 android_jpeg_max_size);
80
81 /* android.lens */
82 float android_lens_info_available_focal_lengths[] = {1.0};
83 m.addFloat(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS,
84 ARRAY_SIZE(android_lens_info_available_focal_lengths),
85 android_lens_info_available_focal_lengths);
86
87 /* android.request */
88 int32_t android_request_max_num_output_streams[] = {0, 3, 1};
89 m.addInt32(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS,
90 ARRAY_SIZE(android_request_max_num_output_streams),
91 android_request_max_num_output_streams);
92
93 /* android.scaler */
94 int32_t android_scaler_available_formats[] = {
95 HAL_PIXEL_FORMAT_RAW_SENSOR,
96 HAL_PIXEL_FORMAT_BLOB,
97 HAL_PIXEL_FORMAT_RGBA_8888,
98 HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
99 // These are handled by YCbCr_420_888
100 // HAL_PIXEL_FORMAT_YV12,
101 // HAL_PIXEL_FORMAT_YCrCb_420_SP,
102 HAL_PIXEL_FORMAT_YCbCr_420_888};
103 m.addInt32(ANDROID_SCALER_AVAILABLE_FORMATS,
104 ARRAY_SIZE(android_scaler_available_formats),
105 android_scaler_available_formats);
106
107 int64_t android_scaler_available_jpeg_min_durations[] = {1};
108 m.addInt64(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS,
109 ARRAY_SIZE(android_scaler_available_jpeg_min_durations),
110 android_scaler_available_jpeg_min_durations);
111
112 int32_t android_scaler_available_jpeg_sizes[] = {640, 480};
113 m.addInt32(ANDROID_SCALER_AVAILABLE_JPEG_SIZES,
114 ARRAY_SIZE(android_scaler_available_jpeg_sizes),
115 android_scaler_available_jpeg_sizes);
116
117 float android_scaler_available_max_digital_zoom[] = {1};
118 m.addFloat(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
119 ARRAY_SIZE(android_scaler_available_max_digital_zoom),
120 android_scaler_available_max_digital_zoom);
121
122 int64_t android_scaler_available_processed_min_durations[] = {1};
123 m.addInt64(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS,
124 ARRAY_SIZE(android_scaler_available_processed_min_durations),
125 android_scaler_available_processed_min_durations);
126
127 int32_t android_scaler_available_processed_sizes[] = {640, 480};
128 m.addInt32(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES,
129 ARRAY_SIZE(android_scaler_available_processed_sizes),
130 android_scaler_available_processed_sizes);
131
132 int64_t android_scaler_available_raw_min_durations[] = {1};
133 m.addInt64(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS,
134 ARRAY_SIZE(android_scaler_available_raw_min_durations),
135 android_scaler_available_raw_min_durations);
136
137 int32_t android_scaler_available_raw_sizes[] = {640, 480};
138 m.addInt32(ANDROID_SCALER_AVAILABLE_RAW_SIZES,
139 ARRAY_SIZE(android_scaler_available_raw_sizes),
140 android_scaler_available_raw_sizes);
141
142 /* android.sensor */
143
144 int32_t android_sensor_info_active_array_size[] = {0, 0, 640, 480};
145 m.addInt32(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE,
146 ARRAY_SIZE(android_sensor_info_active_array_size),
147 android_sensor_info_active_array_size);
148
149 int32_t android_sensor_info_sensitivity_range[] =
150 {100, 1600};
151 m.addInt32(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE,
152 ARRAY_SIZE(android_sensor_info_sensitivity_range),
153 android_sensor_info_sensitivity_range);
154
155 int64_t android_sensor_info_max_frame_duration[] = {30000000000};
156 m.addInt64(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,
157 ARRAY_SIZE(android_sensor_info_max_frame_duration),
158 android_sensor_info_max_frame_duration);
159
160 float android_sensor_info_physical_size[] = {3.2, 2.4};
161 m.addFloat(ANDROID_SENSOR_INFO_PHYSICAL_SIZE,
162 ARRAY_SIZE(android_sensor_info_physical_size),
163 android_sensor_info_physical_size);
164
165 int32_t android_sensor_info_pixel_array_size[] = {640, 480};
166 m.addInt32(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE,
167 ARRAY_SIZE(android_sensor_info_pixel_array_size),
168 android_sensor_info_pixel_array_size);
169
170 int32_t android_sensor_orientation[] = {0};
171 m.addInt32(ANDROID_SENSOR_ORIENTATION,
172 ARRAY_SIZE(android_sensor_orientation),
173 android_sensor_orientation);
174
175 /* End of static camera characteristics */
176
Alex Ray62735082013-10-21 12:55:24 -0700177 return clone_camera_metadata(m.get());
Alex Ray61f7a0c2013-07-03 17:54:19 -0700178}
179
180int ExampleCamera::initDevice()
181{
Alex Ray62735082013-10-21 12:55:24 -0700182 int res;
183 Metadata base;
184
185 // Create standard settings templates from copies of base metadata
186 // TODO: use vendor tags in base metadata
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700187 res = base.add1UInt8(ANDROID_CONTROL_MODE, ANDROID_CONTROL_MODE_OFF);
188 if (res)
Alex Ray62735082013-10-21 12:55:24 -0700189 return res;
190
191 // Use base settings to create all other templates and set them
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700192 res = setPreviewTemplate(base);
193 if (res)
194 return res;
195 res = setStillTemplate(base);
196 if (res)
197 return res;
198 res = setRecordTemplate(base);
199 if (res)
200 return res;
201 res = setSnapshotTemplate(base);
202 if (res)
203 return res;
204 res = setZslTemplate(base);
205 if (res)
206 return res;
Alex Ray61f7a0c2013-07-03 17:54:19 -0700207
208 return 0;
209}
210
Alex Ray62735082013-10-21 12:55:24 -0700211int ExampleCamera::setPreviewTemplate(Metadata m)
212{
Alex Ray62735082013-10-21 12:55:24 -0700213 // Setup default preview controls
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700214 int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
215 ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW);
216
217 if (res)
Alex Ray62735082013-10-21 12:55:24 -0700218 return res;
219 // TODO: set fast auto-focus, auto-whitebalance, auto-exposure, auto flash
220 return setTemplate(CAMERA3_TEMPLATE_PREVIEW, m.get());
221}
222
223int ExampleCamera::setStillTemplate(Metadata m)
224{
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700225 int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
226 ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
Alex Ray62735082013-10-21 12:55:24 -0700227 // Setup default still capture controls
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700228 if (res)
Alex Ray62735082013-10-21 12:55:24 -0700229 return res;
230 // TODO: set fast auto-focus, auto-whitebalance, auto-exposure, auto flash
231 return setTemplate(CAMERA3_TEMPLATE_STILL_CAPTURE, m.get());
232}
233
234int ExampleCamera::setRecordTemplate(Metadata m)
235{
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700236 int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
237 ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
Alex Ray62735082013-10-21 12:55:24 -0700238 // Setup default video record controls
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700239 if (res)
Alex Ray62735082013-10-21 12:55:24 -0700240 return res;
241 // TODO: set slow auto-focus, auto-whitebalance, auto-exposure, flash off
242 return setTemplate(CAMERA3_TEMPLATE_VIDEO_RECORD, m.get());
243}
244
245int ExampleCamera::setSnapshotTemplate(Metadata m)
246{
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700247 int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
248 ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT);
Alex Ray62735082013-10-21 12:55:24 -0700249 // Setup default video snapshot controls
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700250 if (res)
Alex Ray62735082013-10-21 12:55:24 -0700251 return res;
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700252 // TODO: set slow auto-focus, auto-whitebalance, auto-exposure, flash off
Alex Ray62735082013-10-21 12:55:24 -0700253 return setTemplate(CAMERA3_TEMPLATE_VIDEO_SNAPSHOT, m.get());
254}
255
256int ExampleCamera::setZslTemplate(Metadata m)
257{
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700258 int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
259 ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG);
Alex Ray62735082013-10-21 12:55:24 -0700260 // Setup default zero shutter lag controls
Sasha Levitskiya82f4562014-04-21 17:20:17 -0700261 if (res)
Alex Ray62735082013-10-21 12:55:24 -0700262 return res;
263 // TODO: set reprocessing parameters for zsl input queue
264 return setTemplate(CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG, m.get());
265}
266
Alex Ray61f7a0c2013-07-03 17:54:19 -0700267bool ExampleCamera::isValidCaptureSettings(const camera_metadata_t* settings)
268{
269 // TODO: reject settings that cannot be captured
270 return true;
271}
272
273} // namespace default_camera_hal