Home | History | Annotate | Download | only in camera
      1 /*
      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 
     31 namespace default_camera_hal {
     32 
     33 ExampleCamera::ExampleCamera(int id) : Camera(id)
     34 {
     35 }
     36 
     37 ExampleCamera::~ExampleCamera()
     38 {
     39 }
     40 
     41 camera_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[] = {/*AE*/ 1,/*AWB*/ 1,/*AF*/ 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_RAW16,
     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.get());
    178 }
    179 
    180 int ExampleCamera::initDevice()
    181 {
    182     int res;
    183     Metadata base;
    184 
    185     // Create standard settings templates from copies of base metadata
    186     // TODO: use vendor tags in base metadata
    187     res = base.add1UInt8(ANDROID_CONTROL_MODE, ANDROID_CONTROL_MODE_OFF);
    188     if (res)
    189         return res;
    190 
    191     // Use base settings to create all other templates and set them
    192     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;
    207 
    208     return 0;
    209 }
    210 
    211 int ExampleCamera::setPreviewTemplate(Metadata m)
    212 {
    213     // Setup default preview controls
    214     int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
    215                             ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW);
    216 
    217     if (res)
    218         return res;
    219     // TODO: set fast auto-focus, auto-whitebalance, auto-exposure, auto flash
    220     return setTemplate(CAMERA3_TEMPLATE_PREVIEW, m.get());
    221 }
    222 
    223 int ExampleCamera::setStillTemplate(Metadata m)
    224 {
    225     int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
    226                             ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
    227     // Setup default still capture controls
    228     if (res)
    229         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 
    234 int ExampleCamera::setRecordTemplate(Metadata m)
    235 {
    236     int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
    237                             ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
    238     // Setup default video record controls
    239     if (res)
    240         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 
    245 int ExampleCamera::setSnapshotTemplate(Metadata m)
    246 {
    247     int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
    248                             ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT);
    249     // Setup default video snapshot controls
    250     if (res)
    251         return res;
    252     // TODO: set slow auto-focus, auto-whitebalance, auto-exposure, flash off
    253     return setTemplate(CAMERA3_TEMPLATE_VIDEO_SNAPSHOT, m.get());
    254 }
    255 
    256 int ExampleCamera::setZslTemplate(Metadata m)
    257 {
    258     int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
    259                             ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG);
    260     // Setup default zero shutter lag controls
    261     if (res)
    262         return res;
    263     // TODO: set reprocessing parameters for zsl input queue
    264     return setTemplate(CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG, m.get());
    265 }
    266 
    267 bool 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
    274