blob: 8cf2ef08387727c96d0ed6a3f7efff3517ce8341 [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
65 int32_t android_control_max_regions[] = {1};
66 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
177 return clone_camera_metadata(m.generate());
178}
179
180int ExampleCamera::initDevice()
181{
182 // Create standard settings templates
183 Metadata preview = Metadata(ANDROID_CONTROL_MODE_OFF,
184 ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW);
185 setTemplate(CAMERA3_TEMPLATE_PREVIEW, preview.generate());
186 Metadata capture = Metadata(ANDROID_CONTROL_MODE_OFF,
187 ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
188 setTemplate(CAMERA3_TEMPLATE_STILL_CAPTURE, capture.generate());
189 Metadata record = Metadata(ANDROID_CONTROL_MODE_OFF,
190 ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
191 setTemplate(CAMERA3_TEMPLATE_VIDEO_RECORD, record.generate());
192 Metadata snapshot = Metadata(ANDROID_CONTROL_MODE_OFF,
193 ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT);
194 setTemplate(CAMERA3_TEMPLATE_VIDEO_SNAPSHOT, snapshot.generate());
195 Metadata zsl = Metadata(ANDROID_CONTROL_MODE_OFF,
196 ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG);
197 setTemplate(CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG, zsl.generate());
198
199 return 0;
200}
201
202bool ExampleCamera::isValidCaptureSettings(const camera_metadata_t* settings)
203{
204 // TODO: reject settings that cannot be captured
205 return true;
206}
207
208} // namespace default_camera_hal