summaryrefslogtreecommitdiffstats
path: root/camera/smdk4x12_camera.c
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2016-03-18 15:40:14 +0100
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2016-03-18 15:40:26 +0100
commit5fe9b2c621b08a16b00e7080c30b9875155fdc43 (patch)
tree91b3a5569c4300bff48e3ba935b9d8d9634a4593 /camera/smdk4x12_camera.c
parent062cf13b091d82edc08f3d8fa8bfa3961aae9ee2 (diff)
downloaddevice_samsung_smdk4412-common-5fe9b2c621b08a16b00e7080c30b9875155fdc43.zip
device_samsung_smdk4412-common-5fe9b2c621b08a16b00e7080c30b9875155fdc43.tar.gz
device_samsung_smdk4412-common-5fe9b2c621b08a16b00e7080c30b9875155fdc43.tar.bz2
camera: switch to CyanogenMod's version of the free software camera
Replicant's version locks up, sometimes already after taking only one picture. CyanogenMod's camera seems more stable. Only the preview format was changed to RGB565. TODO: Incorporate fixes from both version. Signed-off-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
Diffstat (limited to 'camera/smdk4x12_camera.c')
-rw-r--r--camera/smdk4x12_camera.c4530
1 files changed, 0 insertions, 4530 deletions
diff --git a/camera/smdk4x12_camera.c b/camera/smdk4x12_camera.c
deleted file mode 100644
index 53cc16f..0000000
--- a/camera/smdk4x12_camera.c
+++ /dev/null
@@ -1,4530 +0,0 @@
-/*
- * Copyright (C) 2013-2014 Paul Kocialkowski <contact@paulk.fr>
- *
- * Based on crespo libcamera and exynos4 hal libcamera:
- * Copyright 2008, The Android Open Source Project
- * Copyright 2010, Samsung Electronics Co. LTD
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <time.h>
-#include <errno.h>
-#include <malloc.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-
-#include <asm/types.h>
-
-#define LOG_TAG "smdk4x12_camera"
-#include <utils/Log.h>
-#include <utils/Timers.h>
-
-#include "smdk4x12_camera.h"
-
-#define BIG2LITTLE_ENDIAN(big) ((big & 0xff) << 24 | (big & 0xff00) << 8 | (big & 0xff0000) >> 8 | (big & 0xff000000) >> 24)
-
-/*
- * Devices configurations
- */
-
-struct smdk4x12_camera_mbus_resolution smdk4x12_camera_mbus_resolutions_s5k6a3_galaxys3[] = {
- // 16:9 ratio
- { 1280, 720, 1344, 756 },
- // 4:3 ratio
- { 1280, 960, 1392, 1044 },
- { 960, 720, 1392, 1044 },
- { 640, 480, 1392, 1044 },
- { 320, 240, 1392, 1044 },
- // 1:1 ratio
- { 1392, 1392, 1392, 1392 },
- { 704, 704, 1392, 1392 },
- { 320, 320, 1392, 1392 },
-};
-
-struct smdk4x12_camera_preset smdk4x12_camera_presets_galaxys3[] = {
- {
- .name = "S5C73M3",
- .facing = CAMERA_FACING_BACK,
- .orientation = 90,
- .rotation = 0,
- .hflip = 0,
- .vflip = 0,
- .capture_format = V4L2_PIX_FMT_INTERLEAVED,
- .picture_format = 0,
- .fimc_is = 0,
- .focal_length = 3.7f,
- .horizontal_view_angle = 63.0f,
- .vertical_view_angle = 49.3f,
- .metering = METERING_CENTER,
- .params = {
- .preview_size_values = "960x720,1280x720,1184x666,960x640,704x576,640x480,352x288,320x240",
- .preview_size = "960x720",
- .preview_format_values = "yuv420sp,yuv420p,rgb565",
- .preview_format = "rgb565",
- .preview_frame_rate_values = "30,20,15",
- .preview_frame_rate = 30,
- .preview_fps_range_values = "(15000,15000),(15000,30000),(30000,30000)",
- .preview_fps_range = "15000,30000",
-
- .picture_size_values = "640x480,1024x768,1280x720,1600x1200,2560x1920,3264x2448,2048x1536,3264x1836,2048x1152,3264x2176",
- .picture_size = "3264x2448",
- .picture_format_values = "jpeg",
- .picture_format = "jpeg",
- .jpeg_thumbnail_size_values = "160x120,160x90,144x96",
- .jpeg_thumbnail_width = 160,
- .jpeg_thumbnail_height = 120,
- .jpeg_thumbnail_quality = 100,
- .jpeg_quality = 90,
-
- .video_snapshot_supported = 0,
- .full_video_snap_supported = 0,
-
- .recording_size = "1280x720",
- .recording_size_values = "1280x720,1920x1080,720x480,640x480,352x288,320x240,176x144",
- .recording_format = "yuv420sp",
-
- .focus_mode = "continuous-picture",
- .focus_mode_values = "auto,infinity,macro,fixed,continuous-picture,continuous-video",
- .focus_distances = "0.15,1.20,Infinity",
- .focus_areas = NULL,
- .max_num_focus_areas = 1,
-
- .zoom_supported = 1,
- .smooth_zoom_supported = 0,
- .zoom_ratios = "100,102,104,109,111,113,119,121,124,131,134,138,146,150,155,159,165,170,182,189,200,213,222,232,243,255,283,300,319,364,400",
- .zoom = 0,
- .max_zoom = 30,
-
- .auto_exposure_lock_supported = 1,
- .auto_exposure_lock = 0,
-
- .auto_white_balance_lock_supported = 1,
- .auto_white_balance_lock = 0,
-
- .flash_mode = "auto",
- .flash_mode_values = "auto,on,torch,off",
-
- .exposure_compensation = 0,
- .exposure_compensation_step = 0.5,
- .min_exposure_compensation = -4,
- .max_exposure_compensation = 4,
-
- .whitebalance = "auto",
- .whitebalance_values = "auto,incandescent,fluorescent,daylight,cloudy-daylight",
-
- .antibanding = "auto",
- .antibanding_values = "auto,60hz,50hz,off",
-
- .scene_mode = "auto",
- .scene_mode_values = "auto,portrait,landscape,night,beach,snow,sunset,fireworks,sports,party,candlelight,dusk-dawn,fall-color,text,back-light",
-
- .effect = "none",
- .effect_values = "none,mono,negative,sepia,solarize,posterize,washed,vintage-warm,vintage-cold,point-blue,point-red-yellow,point-green",
-
- .iso = "auto",
- .iso_values = "auto,ISO100,ISO200,ISO400,ISO800",
-
- .image_stabilization = "off",
- .image_stabilization_values = "on,off",
- },
- .mbus_resolutions = NULL,
- .mbus_resolutions_count = 0,
- },
- {
- .name = "S5K6A3",
- .facing = CAMERA_FACING_FRONT,
- .orientation = 270,
- .rotation = 0,
- .hflip = 0,
- .vflip = 0,
- .capture_format = 0,
- .picture_format = V4L2_PIX_FMT_YUYV,
- .fimc_is = 1,
- .focal_length = 2.73f,
- .horizontal_view_angle = 52.58f,
- .vertical_view_angle = 52.58f,
- .metering = METERING_CENTER,
- .params = {
- .preview_size_values = "1280x720,960x720,640x480,320x240,704x704,320x320",
- .preview_size = "960x720",
- .preview_format_values = "yuv420sp,yuv420p,rgb565",
- .preview_format = "rgb565",
- .preview_frame_rate_values = "30,20,15,8",
- .preview_frame_rate = 30,
- .preview_fps_range_values = "(8000,8000),(15000,15000),(15000,30000),(30000,30000)",
- .preview_fps_range = "15000,30000",
-
- .picture_size_values = "1344x756,1280x720,1392x1044,1280x960,960x720,640x480,1392x1392",
- .picture_size = "1280x960",
- .picture_format_values = "jpeg",
- .picture_format = "jpeg",
- .jpeg_thumbnail_size_values = "160x120,160x160,160x90,144x96",
- .jpeg_thumbnail_width = 160,
- .jpeg_thumbnail_height = 120,
- .jpeg_thumbnail_quality = 100,
- .jpeg_quality = 90,
-
- .video_snapshot_supported = 0,
- .full_video_snap_supported = 0,
-
- .recording_size = "1280x720",
- .recording_size_values = "1280x720,720x480,640x480,352x288,320x320,320x240,176x144",
- .recording_format = "yuv420sp",
-
- .focus_mode = "fixed",
- .focus_mode_values = "infinity,fixed",
- .focus_distances = "0.20,0.25,Infinity",
- .focus_areas = NULL,
- .max_num_focus_areas = 0,
-
- .zoom_supported = 0,
-
- .auto_exposure_lock_supported = 0,
- .auto_exposure_lock = 0,
-
- .auto_white_balance_lock_supported = 0,
- .auto_white_balance_lock = 0,
-
- .flash_mode = NULL,
- .flash_mode_values = NULL,
-
- .exposure_compensation = 0,
- .exposure_compensation_step = 0.5,
- .min_exposure_compensation = -4,
- .max_exposure_compensation = 4,
-
- .whitebalance = "auto",
- .whitebalance_values = "auto,incandescent,fluorescent,daylight,cloudy-daylight",
-
- .antibanding = NULL,
- .antibanding_values = NULL,
-
- .scene_mode = NULL,
- .scene_mode_values = NULL,
-
- .effect = "none",
- .effect_values = "none,mono,negative,sepia,solarize,posterize,washed,vintage-warm,vintage-cold,point-blue,point-red-yellow,point-green",
-
- .iso = "auto",
- .iso_values = "auto",
-
- .image_stabilization = "off",
- .image_stabilization_values = "off",
- },
- .mbus_resolutions = (struct smdk4x12_camera_mbus_resolution *) &smdk4x12_camera_mbus_resolutions_s5k6a3_galaxys3,
- .mbus_resolutions_count = 8,
- },
-};
-
-struct smdk4x12_v4l2_node smdk4x12_v4l2_nodes_galaxys3[] = {
- { // FIMC0 is used for capture
- .id = 0,
- .node = "/dev/video0",
- },
- { // FIMC1 is used for preview output
- .id = 1,
- .node = "/dev/video1",
- },
- { // FIMC2 is used for picture output
- .id = 2,
- .node = "/dev/video2",
- },
- { // FIMC3 is used for recording output
- .id = 3,
- .node = "/dev/video3",
- },
-};
-
-struct exynox_camera_config smdk4x12_camera_config_galaxys3 = {
- .presets = (struct smdk4x12_camera_preset *) &smdk4x12_camera_presets_galaxys3,
- .presets_count = 2,
- .v4l2_nodes = (struct smdk4x12_v4l2_node *) &smdk4x12_v4l2_nodes_galaxys3,
- .v4l2_nodes_count = 4,
-};
-
-/*
- * SMDK4x12 Camera
- */
-
-struct exynox_camera_config *smdk4x12_camera_config =
- &smdk4x12_camera_config_galaxys3;
-
-int smdk4x12_camera_start(struct smdk4x12_camera *smdk4x12_camera, int id)
-{
- int rc;
-
- if (smdk4x12_camera == NULL || id >= smdk4x12_camera->config->presets_count)
- return -EINVAL;
-
- // ION
-
-#ifdef EXYNOS_ION
- rc = smdk4x12_ion_init(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to init ION", __func__);
- goto error;
- }
-
- rc = smdk4x12_ion_open(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to open ION", __func__);
- goto error;
- }
-#endif
-
- // V4L2
-
- rc = smdk4x12_v4l2_init(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to init v4l2", __func__);
- goto error;
- }
-
- // FIMC0
-
- rc = smdk4x12_v4l2_open(smdk4x12_camera, 0);
- if (rc < 0) {
- ALOGE("%s: Unable to open v4l2 device", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_querycap_cap(smdk4x12_camera, 0);
- if (rc < 0) {
- ALOGE("%s: Unable to query capabilities", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_enum_input(smdk4x12_camera, 0, id);
- if (rc < 0) {
- ALOGE("%s: Unable to enumerate input", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_s_input(smdk4x12_camera, 0, id);
- if (rc < 0) {
- ALOGE("%s: Unable to set inputs", __func__);
- goto error;
- }
-
- // Recording
-
- smdk4x12_camera->recording_metadata = 1;
-
- // Params
-
- rc = smdk4x12_camera_params_init(smdk4x12_camera, id);
- if (rc < 0) {
- ALOGE("%s: Unable to init params", __func__);
- goto error;
- }
-
- // Gralloc
-
- rc = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const struct hw_module_t **) &smdk4x12_camera->gralloc);
- if (rc)
- ALOGE("%s: Unable to get gralloc module", __func__);
-
- rc = 0;
- goto complete;
-
-error:
- smdk4x12_v4l2_close(smdk4x12_camera, 0);
-
-#ifdef EXYNOS_ION
- smdk4x12_ion_close(smdk4x12_camera);
-#endif
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- int i;
- int id;
-
- if (smdk4x12_camera == NULL || smdk4x12_camera->config == NULL)
- return;
-
- smdk4x12_v4l2_close(smdk4x12_camera, 0);
-
-#ifdef EXYNOS_ION
- smdk4x12_ion_close(smdk4x12_camera);
-#endif
-}
-
-// Params
-
-int smdk4x12_camera_params_init(struct smdk4x12_camera *smdk4x12_camera, int id)
-{
- int rc;
-
- if (smdk4x12_camera == NULL || id >= smdk4x12_camera->config->presets_count)
- return -EINVAL;
-
- // Camera params
-
- smdk4x12_camera->camera_rotation = smdk4x12_camera->config->presets[id].rotation;
- smdk4x12_camera->camera_hflip = smdk4x12_camera->config->presets[id].hflip;
- smdk4x12_camera->camera_vflip = smdk4x12_camera->config->presets[id].vflip;
- smdk4x12_camera->camera_capture_format = smdk4x12_camera->config->presets[id].capture_format;
- smdk4x12_camera->camera_picture_format = smdk4x12_camera->config->presets[id].picture_format;
- smdk4x12_camera->camera_fimc_is = smdk4x12_camera->config->presets[id].fimc_is;
- smdk4x12_camera->camera_focal_length = (int) (smdk4x12_camera->config->presets[id].focal_length * 100);
- smdk4x12_camera->camera_metering = smdk4x12_camera->config->presets[id].metering;
-
- smdk4x12_camera->camera_mbus_resolutions = smdk4x12_camera->config->presets[id].mbus_resolutions;
- smdk4x12_camera->camera_mbus_resolutions_count = smdk4x12_camera->config->presets[id].mbus_resolutions_count;
-
- // Recording preview
-
- smdk4x12_param_string_set(smdk4x12_camera, "preferred-preview-size-for-video",
- smdk4x12_camera->config->presets[id].params.preview_size);
-
- // Preview
-
- smdk4x12_param_string_set(smdk4x12_camera, "preview-size-values",
- smdk4x12_camera->config->presets[id].params.preview_size_values);
- smdk4x12_param_string_set(smdk4x12_camera, "preview-size",
- smdk4x12_camera->config->presets[id].params.preview_size);
- smdk4x12_param_string_set(smdk4x12_camera, "preview-format-values",
- smdk4x12_camera->config->presets[id].params.preview_format_values);
- smdk4x12_param_string_set(smdk4x12_camera, "preview-format",
- smdk4x12_camera->config->presets[id].params.preview_format);
- smdk4x12_param_string_set(smdk4x12_camera, "preview-frame-rate-values",
- smdk4x12_camera->config->presets[id].params.preview_frame_rate_values);
- smdk4x12_param_int_set(smdk4x12_camera, "preview-frame-rate",
- smdk4x12_camera->config->presets[id].params.preview_frame_rate);
- smdk4x12_param_string_set(smdk4x12_camera, "preview-fps-range-values",
- smdk4x12_camera->config->presets[id].params.preview_fps_range_values);
- smdk4x12_param_string_set(smdk4x12_camera, "preview-fps-range",
- smdk4x12_camera->config->presets[id].params.preview_fps_range);
-
- // Picture
-
- smdk4x12_param_string_set(smdk4x12_camera, "picture-size-values",
- smdk4x12_camera->config->presets[id].params.picture_size_values);
- smdk4x12_param_string_set(smdk4x12_camera, "picture-size",
- smdk4x12_camera->config->presets[id].params.picture_size);
- smdk4x12_param_string_set(smdk4x12_camera, "picture-format-values",
- smdk4x12_camera->config->presets[id].params.picture_format_values);
- smdk4x12_param_string_set(smdk4x12_camera, "picture-format",
- smdk4x12_camera->config->presets[id].params.picture_format);
- smdk4x12_param_string_set(smdk4x12_camera, "jpeg-thumbnail-size-values",
- smdk4x12_camera->config->presets[id].params.jpeg_thumbnail_size_values);
- smdk4x12_param_int_set(smdk4x12_camera, "jpeg-thumbnail-width",
- smdk4x12_camera->config->presets[id].params.jpeg_thumbnail_width);
- smdk4x12_param_int_set(smdk4x12_camera, "jpeg-thumbnail-height",
- smdk4x12_camera->config->presets[id].params.jpeg_thumbnail_height);
- smdk4x12_param_int_set(smdk4x12_camera, "jpeg-thumbnail-quality",
- smdk4x12_camera->config->presets[id].params.jpeg_thumbnail_quality);
- smdk4x12_param_int_set(smdk4x12_camera, "jpeg-quality",
- smdk4x12_camera->config->presets[id].params.jpeg_quality);
-
- if (smdk4x12_camera->config->presets[id].params.video_snapshot_supported == 1)
- smdk4x12_param_string_set(smdk4x12_camera, "video-snapshot-supported", "true");
- if (smdk4x12_camera->config->presets[id].params.full_video_snap_supported == 1)
- smdk4x12_param_string_set(smdk4x12_camera, "full-video-snap-supported", "true");
-
- // Recording
-
- smdk4x12_param_string_set(smdk4x12_camera, "video-size",
- smdk4x12_camera->config->presets[id].params.recording_size);
- smdk4x12_param_string_set(smdk4x12_camera, "video-size-values",
- smdk4x12_camera->config->presets[id].params.recording_size_values);
- smdk4x12_param_string_set(smdk4x12_camera, "video-frame-format",
- smdk4x12_camera->config->presets[id].params.recording_format);
-
- // Focus
-
- smdk4x12_param_string_set(smdk4x12_camera, "focus-mode",
- smdk4x12_camera->config->presets[id].params.focus_mode);
- smdk4x12_param_string_set(smdk4x12_camera, "focus-mode-values",
- smdk4x12_camera->config->presets[id].params.focus_mode_values);
- smdk4x12_param_string_set(smdk4x12_camera, "focus-distances",
- smdk4x12_camera->config->presets[id].params.focus_distances);
- if (smdk4x12_camera->config->presets[id].params.max_num_focus_areas > 0) {
- smdk4x12_param_string_set(smdk4x12_camera, "focus-areas",
- smdk4x12_camera->config->presets[id].params.focus_areas);
- smdk4x12_param_int_set(smdk4x12_camera, "max-num-focus-areas",
- smdk4x12_camera->config->presets[id].params.max_num_focus_areas);
- }
-
- // Zoom
-
- if (smdk4x12_camera->config->presets[id].params.zoom_supported == 1) {
- smdk4x12_param_string_set(smdk4x12_camera, "zoom-supported", "true");
-
- if (smdk4x12_camera->config->presets[id].params.smooth_zoom_supported == 1)
- smdk4x12_param_string_set(smdk4x12_camera, "smooth-zoom-supported", "true");
-
- if (smdk4x12_camera->config->presets[id].params.zoom_ratios != NULL)
- smdk4x12_param_string_set(smdk4x12_camera, "zoom-ratios", smdk4x12_camera->config->presets[id].params.zoom_ratios);
-
- smdk4x12_param_int_set(smdk4x12_camera, "zoom", smdk4x12_camera->config->presets[id].params.zoom);
- smdk4x12_param_int_set(smdk4x12_camera, "max-zoom", smdk4x12_camera->config->presets[id].params.max_zoom);
-
- } else {
- smdk4x12_param_string_set(smdk4x12_camera, "zoom-supported", "false");
- }
-
- // AE lock
-
- if (smdk4x12_camera->config->presets[id].params.auto_exposure_lock_supported == 1) {
- smdk4x12_param_string_set(smdk4x12_camera, "auto-exposure-lock-supported", "true");
-
- if (smdk4x12_camera->config->presets[id].params.auto_exposure_lock)
- smdk4x12_param_string_set(smdk4x12_camera, "auto-exposure-lock", "true");
- else
- smdk4x12_param_string_set(smdk4x12_camera, "auto-exposure-lock", "false");
- }
-
- // AWB lock
-
- if (smdk4x12_camera->config->presets[id].params.auto_white_balance_lock_supported == 1) {
- smdk4x12_param_string_set(smdk4x12_camera, "auto-whitebalance-lock-supported", "true");
-
- if (smdk4x12_camera->config->presets[id].params.auto_white_balance_lock)
- smdk4x12_param_string_set(smdk4x12_camera, "auto-whitebalance-lock", "true");
- else
- smdk4x12_param_string_set(smdk4x12_camera, "auto-whitebalance-lock", "false");
- }
-
- // Flash
-
- smdk4x12_param_string_set(smdk4x12_camera, "flash-mode",
- smdk4x12_camera->config->presets[id].params.flash_mode);
- smdk4x12_param_string_set(smdk4x12_camera, "flash-mode-values",
- smdk4x12_camera->config->presets[id].params.flash_mode_values);
-
- // Exposure
-
- smdk4x12_param_int_set(smdk4x12_camera, "exposure-compensation",
- smdk4x12_camera->config->presets[id].params.exposure_compensation);
- smdk4x12_param_float_set(smdk4x12_camera, "exposure-compensation-step",
- smdk4x12_camera->config->presets[id].params.exposure_compensation_step);
- smdk4x12_param_int_set(smdk4x12_camera, "min-exposure-compensation",
- smdk4x12_camera->config->presets[id].params.min_exposure_compensation);
- smdk4x12_param_int_set(smdk4x12_camera, "max-exposure-compensation",
- smdk4x12_camera->config->presets[id].params.max_exposure_compensation);
-
- // Antibanding
-
- smdk4x12_param_string_set(smdk4x12_camera, "antibanding",
- smdk4x12_camera->config->presets[id].params.antibanding);
- smdk4x12_param_string_set(smdk4x12_camera, "antibanding-values",
- smdk4x12_camera->config->presets[id].params.antibanding_values);
-
- // WB
-
- smdk4x12_param_string_set(smdk4x12_camera, "whitebalance",
- smdk4x12_camera->config->presets[id].params.whitebalance);
- smdk4x12_param_string_set(smdk4x12_camera, "whitebalance-values",
- smdk4x12_camera->config->presets[id].params.whitebalance_values);
-
- // Scene mode
-
- smdk4x12_param_string_set(smdk4x12_camera, "scene-mode",
- smdk4x12_camera->config->presets[id].params.scene_mode);
- smdk4x12_param_string_set(smdk4x12_camera, "scene-mode-values",
- smdk4x12_camera->config->presets[id].params.scene_mode_values);
-
- // Effect
-
- smdk4x12_param_string_set(smdk4x12_camera, "effect",
- smdk4x12_camera->config->presets[id].params.effect);
- smdk4x12_param_string_set(smdk4x12_camera, "effect-values",
- smdk4x12_camera->config->presets[id].params.effect_values);
-
- // ISO
-
- smdk4x12_param_string_set(smdk4x12_camera, "iso",
- smdk4x12_camera->config->presets[id].params.iso);
- smdk4x12_param_string_set(smdk4x12_camera, "iso-values",
- smdk4x12_camera->config->presets[id].params.iso_values);
-
- // Image stabilization
-
- smdk4x12_param_string_set(smdk4x12_camera, "image-stabilization",
- smdk4x12_camera->config->presets[id].params.image_stabilization);
- smdk4x12_param_string_set(smdk4x12_camera, "image-stabilization-values",
- smdk4x12_camera->config->presets[id].params.image_stabilization_values);
-
- // Camera
-
- smdk4x12_param_float_set(smdk4x12_camera, "focal-length",
- smdk4x12_camera->config->presets[id].focal_length);
- smdk4x12_param_float_set(smdk4x12_camera, "horizontal-view-angle",
- smdk4x12_camera->config->presets[id].horizontal_view_angle);
- smdk4x12_param_float_set(smdk4x12_camera, "vertical-view-angle",
- smdk4x12_camera->config->presets[id].vertical_view_angle);
-
- rc = smdk4x12_camera_params_apply(smdk4x12_camera, 1);
- if (rc < 0) {
- ALOGE("%s: Unable to apply params", __func__);
- return -1;
- }
-
- return 0;
-}
-
-int smdk4x12_camera_params_apply(struct smdk4x12_camera *smdk4x12_camera, int force)
-{
- char *recording_hint_string;
- char *recording_preview_size_string;
-
- char *preview_size_string;
- int preview_width = 0;
- int preview_height = 0;
- char *preview_format_string;
- int preview_format;
- int preview_fps;
-
- char *picture_size_string;
- int picture_width = 0;
- int picture_height = 0;
- char *picture_format_string;
- int picture_format;
-
- int jpeg_thumbnail_width;
- int jpeg_thumbnail_height;
- int jpeg_thumbnail_quality;
- int jpeg_quality;
-
- char *video_size_string;
- int recording_width = 0;
- int recording_height = 0;
- char *video_frame_format_string;
- int recording_format;
- int camera_sensor_mode;
- int fimc_is_mode = 0;
-
- char *focus_mode_string;
- int focus_mode = 0;
- char *focus_areas_string;
- int focus_left, focus_top, focus_right, focus_bottom, focus_weigth;
- int focus_x;
- int focus_y;
-
- char *zoom_supported_string;
- int zoom, max_zoom;
-
- char *ae_lock_supported_string;
- char *ae_lock_string;
- int ae_lock = 0;
-
- char *awb_lock_supported_string;
- char *awb_lock_string;
- int awb_lock = 0;
- int aeawb = 0;
-
- char *flash_mode_string;
- int flash_mode;
-
- int exposure_compensation;
- int min_exposure_compensation;
- int max_exposure_compensation;
-
- char *antibanding_string;
- int antibanding;
-
- char *whitebalance_string;
- int whitebalance;
-
- char *scene_mode_string;
- int scene_mode;
-
- char *effect_string;
- int effect;
-
- char *iso_string;
- int iso;
-
- char *image_stabilization_string;
- int image_stabilization;
-
- int w, h;
- char *k;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- // Preview
-
- preview_size_string = smdk4x12_param_string_get(smdk4x12_camera, "preview-size");
- if (preview_size_string != NULL) {
- sscanf(preview_size_string, "%dx%d", &preview_width, &preview_height);
-
- if (preview_width != 0 && preview_width != smdk4x12_camera->preview_width)
- smdk4x12_camera->preview_width = preview_width;
- if (preview_height != 0 && preview_height != smdk4x12_camera->preview_height)
- smdk4x12_camera->preview_height = preview_height;
- }
-
- preview_format_string = smdk4x12_param_string_get(smdk4x12_camera, "preview-format");
- if (preview_format_string != NULL) {
- if (strcmp(preview_format_string, "yuv420sp") == 0) {
- preview_format = V4L2_PIX_FMT_NV21;
- } else if (strcmp(preview_format_string, "yuv420p") == 0) {
- preview_format = V4L2_PIX_FMT_YUV420;
- } else if (strcmp(preview_format_string, "rgb565") == 0) {
- preview_format = V4L2_PIX_FMT_RGB565;
- } else if (strcmp(preview_format_string, "rgb8888") == 0) {
- preview_format = V4L2_PIX_FMT_RGB32;
- } else {
- ALOGE("%s: Unsupported preview format: %s", __func__, preview_format_string);
- preview_format = V4L2_PIX_FMT_NV21;
- }
-
- if (preview_format != smdk4x12_camera->preview_format)
- smdk4x12_camera->preview_format = preview_format;
- }
-
- preview_fps = smdk4x12_param_int_get(smdk4x12_camera, "preview-frame-rate");
- if (preview_fps > 0)
- smdk4x12_camera->preview_fps = preview_fps;
- else
- smdk4x12_camera->preview_fps = 0;
-
- // Picture
-
- picture_size_string = smdk4x12_param_string_get(smdk4x12_camera, "picture-size");
- if (picture_size_string != NULL) {
- sscanf(picture_size_string, "%dx%d", &picture_width, &picture_height);
-
- if (picture_width != 0 && picture_height != 0 && (picture_width != smdk4x12_camera->picture_width || picture_height != smdk4x12_camera->picture_height)) {
- smdk4x12_camera->picture_width = picture_width;
- smdk4x12_camera->picture_height = picture_height;
-
- if (smdk4x12_camera->camera_capture_format == V4L2_PIX_FMT_INTERLEAVED) {
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_JPEG_RESOLUTION, (picture_width & 0xffff) << 16 | (picture_height & 0xffff));
- if (rc < 0)
- ALOGE("%s: Unablet to set jpeg resolution", __func__);
- }
- }
- }
-
- picture_format_string = smdk4x12_param_string_get(smdk4x12_camera, "picture-format");
- if (picture_format_string != NULL) {
- if (strcmp(picture_format_string, "jpeg") == 0) {
- picture_format = V4L2_PIX_FMT_JPEG;
- } else {
- ALOGE("%s: Unsupported picture format: %s", __func__, picture_format_string);
- picture_format = V4L2_PIX_FMT_JPEG;
- }
-
- if (picture_format != smdk4x12_camera->picture_format)
- smdk4x12_camera->picture_format = picture_format;
- }
-
- jpeg_thumbnail_width = smdk4x12_param_int_get(smdk4x12_camera, "jpeg-thumbnail-width");
- if (jpeg_thumbnail_width > 0)
- smdk4x12_camera->jpeg_thumbnail_width = jpeg_thumbnail_width;
-
- jpeg_thumbnail_height = smdk4x12_param_int_get(smdk4x12_camera, "jpeg-thumbnail-height");
- if (jpeg_thumbnail_height > 0)
- smdk4x12_camera->jpeg_thumbnail_height = jpeg_thumbnail_height;
-
- jpeg_thumbnail_quality = smdk4x12_param_int_get(smdk4x12_camera, "jpeg-thumbnail-quality");
- if (jpeg_thumbnail_quality > 0)
- smdk4x12_camera->jpeg_thumbnail_quality = jpeg_thumbnail_quality;
-
- jpeg_quality = smdk4x12_param_int_get(smdk4x12_camera, "jpeg-quality");
- if (jpeg_quality <= 100 && jpeg_quality >= 0 && (jpeg_quality != smdk4x12_camera->jpeg_quality || force)) {
- smdk4x12_camera->jpeg_quality = jpeg_quality;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAM_JPEG_QUALITY, jpeg_quality);
- if (rc < 0)
- ALOGE("%s: Unable to set jpeg quality", __func__);
- }
-
- // Recording
-
- video_size_string = smdk4x12_param_string_get(smdk4x12_camera, "video-size");
- if (video_size_string == NULL)
- video_size_string = smdk4x12_param_string_get(smdk4x12_camera, "preview-size");
-
- if (video_size_string != NULL) {
- sscanf(video_size_string, "%dx%d", &recording_width, &recording_height);
-
- if (recording_width != 0 && recording_width != smdk4x12_camera->recording_width)
- smdk4x12_camera->recording_width = recording_width;
- if (recording_height != 0 && recording_height != smdk4x12_camera->recording_height)
- smdk4x12_camera->recording_height = recording_height;
- }
-
- video_frame_format_string = smdk4x12_param_string_get(smdk4x12_camera, "video-frame-format");
- if (video_frame_format_string != NULL) {
- if (strcmp(video_frame_format_string, "yuv420sp") == 0) {
- recording_format = V4L2_PIX_FMT_NV12;
- } else if (strcmp(video_frame_format_string, "yuv420p") == 0) {
- recording_format = V4L2_PIX_FMT_YUV420;
- } else if (strcmp(video_frame_format_string, "rgb565") == 0) {
- recording_format = V4L2_PIX_FMT_RGB565;
- } else if (strcmp(video_frame_format_string, "rgb8888") == 0) {
- recording_format = V4L2_PIX_FMT_RGB32;
- } else {
- ALOGE("%s: Unsupported recording format: %s", __func__, video_frame_format_string);
- recording_format = V4L2_PIX_FMT_NV12;
- }
-
- if (recording_format != smdk4x12_camera->recording_format)
- smdk4x12_camera->recording_format = recording_format;
- }
-
- recording_hint_string = smdk4x12_param_string_get(smdk4x12_camera, "recording-hint");
- if (recording_hint_string != NULL && strcmp(recording_hint_string, "true") == 0) {
- camera_sensor_mode = SENSOR_MOVIE;
-
- k = smdk4x12_param_string_get(smdk4x12_camera, "preview-size-values");
- while (recording_width != 0 && recording_height != 0) {
- if (k == NULL)
- break;
-
- sscanf(k, "%dx%d", &w, &h);
-
- // Look for same aspect ratio
- if ((recording_width * h) / recording_height == w) {
- preview_width = w;
- preview_height = h;
- break;
- }
-
- k = strchr(k, ',');
- if (k == NULL)
- break;
-
- k++;
- }
-
- if (preview_width != 0 && preview_width != smdk4x12_camera->preview_width)
- smdk4x12_camera->preview_width = preview_width;
- if (preview_height != 0 && preview_height != smdk4x12_camera->preview_height)
- smdk4x12_camera->preview_height = preview_height;
-
- if (smdk4x12_camera->camera_fimc_is)
- fimc_is_mode = IS_MODE_PREVIEW_VIDEO;
- } else {
- camera_sensor_mode = SENSOR_CAMERA;
-
- if (smdk4x12_camera->camera_fimc_is)
- fimc_is_mode = IS_MODE_PREVIEW_STILL;
- }
-
- // Switching modes
-
- if (camera_sensor_mode != smdk4x12_camera->camera_sensor_mode) {
- smdk4x12_camera->camera_sensor_mode = camera_sensor_mode;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_SENSOR_MODE, camera_sensor_mode);
- if (rc < 0)
- ALOGE("%s: Unable to set sensor mode", __func__);
- }
-
- if (smdk4x12_camera->camera_fimc_is && fimc_is_mode != smdk4x12_camera->fimc_is_mode) {
- smdk4x12_camera->fimc_is_mode = fimc_is_mode;
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_IS_S_FORMAT_SCENARIO, smdk4x12_camera->fimc_is_mode);
- if (rc < 0)
- ALOGE("%s: Unable to set FIMC-IS scenario", __func__);
- }
-
- // Focus
-
- focus_areas_string = smdk4x12_param_string_get(smdk4x12_camera, "focus-areas");
- if (focus_areas_string != NULL) {
- focus_left = focus_top = focus_right = focus_bottom = focus_weigth = 0;
-
- rc = sscanf(focus_areas_string, "(%d,%d,%d,%d,%d)",
- &focus_left, &focus_top, &focus_right, &focus_bottom, &focus_weigth);
- if (rc != 5) {
- ALOGE("%s: Unable to scan focus areas", __func__);
- } else if (focus_left != 0 && focus_top != 0 && focus_right != 0 && focus_bottom != 0) {
- focus_x = (((focus_left + focus_right) / 2) + 1000) * preview_width / 2000;
- focus_y = (((focus_top + focus_bottom) / 2) + 1000) * preview_height / 2000;
-
- if (focus_x != smdk4x12_camera->focus_x || force) {
- smdk4x12_camera->focus_x = focus_x;
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_OBJECT_POSITION_X, focus_x);
- if (rc < 0)
- ALOGE("%s: Unable to set object x position", __func__);
- }
-
- if (focus_y != smdk4x12_camera->focus_y || force) {
- smdk4x12_camera->focus_y = focus_y;
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_OBJECT_POSITION_Y, focus_y);
- if (rc < 0)
- ALOGE("%s: Unable to set object y position", __func__);
- }
-
- focus_mode = FOCUS_MODE_TOUCH;
- }
- }
-
- focus_mode_string = smdk4x12_param_string_get(smdk4x12_camera, "focus-mode");
- if (focus_mode_string != NULL) {
- if (focus_mode == 0) {
- if (strcmp(focus_mode_string, "auto") == 0)
- focus_mode = FOCUS_MODE_AUTO;
- else if (strcmp(focus_mode_string, "infinity") == 0)
- focus_mode = FOCUS_MODE_INFINITY;
- else if (strcmp(focus_mode_string, "macro") == 0)
- focus_mode = FOCUS_MODE_MACRO;
- else if (strcmp(focus_mode_string, "fixed") == 0)
- focus_mode = FOCUS_MODE_FIXED;
- else if (strcmp(focus_mode_string, "facedetect") == 0)
- focus_mode = FOCUS_MODE_FACEDETECT;
- else if (strcmp(focus_mode_string, "continuous-video") == 0)
- focus_mode = FOCUS_MODE_CONTINOUS_VIDEO;
- else if (strcmp(focus_mode_string, "continuous-picture") == 0)
- focus_mode = FOCUS_MODE_CONTINOUS_PICTURE;
- else
- focus_mode = FOCUS_MODE_AUTO;
- }
-
- if (focus_mode != smdk4x12_camera->focus_mode || force) {
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_FOCUS_MODE, focus_mode);
- if (rc < 0)
- ALOGE("%s: Unable to set focus mode", __func__);
- }
-
- smdk4x12_camera->focus_mode = focus_mode;
- }
-
- // Zoom
-
- zoom_supported_string = smdk4x12_param_string_get(smdk4x12_camera, "zoom-supported");
- if (zoom_supported_string != NULL && strcmp(zoom_supported_string, "true") == 0) {
- zoom = smdk4x12_param_int_get(smdk4x12_camera, "zoom");
- max_zoom = smdk4x12_param_int_get(smdk4x12_camera, "max-zoom");
- if (zoom <= max_zoom && zoom >= 0 && (zoom != smdk4x12_camera->zoom || force)) {
- smdk4x12_camera->zoom = zoom;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_ZOOM, zoom);
- if (rc < 0)
- ALOGE("%s: Unable to set camera zoom", __func__);
- }
-
- }
-
- // AE lock
-
- ae_lock_supported_string = smdk4x12_param_string_get(smdk4x12_camera, "auto-exposure-lock-supported");
- ae_lock_string = smdk4x12_param_string_get(smdk4x12_camera, "auto-exposure-lock");
- if (ae_lock_supported_string != NULL && ae_lock_string != NULL && strcmp(ae_lock_supported_string, "true") == 0 && strcmp(ae_lock_string, "true") == 0)
- ae_lock = 1;
- else
- ae_lock = 0;
-
- // AWB lock
-
- awb_lock_supported_string = smdk4x12_param_string_get(smdk4x12_camera, "auto-whitebalance-lock-supported");
- awb_lock_string = smdk4x12_param_string_get(smdk4x12_camera, "auto-whitebalance-lock");
- if (awb_lock_supported_string != NULL && awb_lock_string != NULL && strcmp(awb_lock_supported_string, "true") == 0 && strcmp(awb_lock_string, "true") == 0)
- awb_lock = 1;
- else
- awb_lock = 0;
-
- if (ae_lock != smdk4x12_camera->ae_lock || awb_lock != smdk4x12_camera->awb_lock || force) {
- smdk4x12_camera->ae_lock = ae_lock;
- smdk4x12_camera->awb_lock = awb_lock;
- aeawb = (ae_lock ? 0x1 : 0x0) | (awb_lock ? 0x2 : 0x0);
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_AEAWB_LOCK_UNLOCK, aeawb);
- if (rc < 0)
- ALOGE("%s: Unable to set AEAWB lock", __func__);
- }
-
- // Flash
-
- flash_mode_string = smdk4x12_param_string_get(smdk4x12_camera, "flash-mode");
- if (flash_mode_string != NULL) {
- if (strcmp(flash_mode_string, "off") == 0)
- flash_mode = FLASH_MODE_OFF;
- else if (strcmp(flash_mode_string, "auto") == 0)
- flash_mode = FLASH_MODE_AUTO;
- else if (strcmp(flash_mode_string, "on") == 0)
- flash_mode = FLASH_MODE_ON;
- else if (strcmp(flash_mode_string, "torch") == 0)
- flash_mode = FLASH_MODE_TORCH;
- else
- flash_mode = FLASH_MODE_AUTO;
-
- if (flash_mode != smdk4x12_camera->flash_mode || force) {
- smdk4x12_camera->flash_mode = flash_mode;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_FLASH_MODE, flash_mode);
- if (rc < 0)
- ALOGE("%s:Unable to set flash mode", __func__);
- }
- }
-
- // Exposure
-
- exposure_compensation = smdk4x12_param_int_get(smdk4x12_camera, "exposure-compensation");
- min_exposure_compensation = smdk4x12_param_int_get(smdk4x12_camera, "min-exposure-compensation");
- max_exposure_compensation = smdk4x12_param_int_get(smdk4x12_camera, "max-exposure-compensation");
-
- if (exposure_compensation <= max_exposure_compensation && exposure_compensation >= min_exposure_compensation &&
- (exposure_compensation != smdk4x12_camera->exposure_compensation || force)) {
- smdk4x12_camera->exposure_compensation = exposure_compensation;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_BRIGHTNESS, exposure_compensation);
- if (rc < 0)
- ALOGE("%s: Unable to set exposure", __func__);
- }
-
- // Antibanding
-
- antibanding_string = smdk4x12_param_string_get(smdk4x12_camera, "antibanding");
- if (antibanding_string != NULL) {
- if (strcmp(antibanding_string, "auto") == 0)
- antibanding = ANTI_BANDING_AUTO;
- else if (strcmp(antibanding_string, "50hz") == 0)
- antibanding = ANTI_BANDING_50HZ;
- else if (strcmp(antibanding_string, "60hz") == 0)
- antibanding = ANTI_BANDING_60HZ;
- else if (strcmp(antibanding_string, "off") == 0)
- antibanding = ANTI_BANDING_OFF;
- else
- antibanding = ANTI_BANDING_AUTO;
-
- if (antibanding != smdk4x12_camera->antibanding || force) {
- smdk4x12_camera->antibanding = antibanding;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_ANTI_BANDING, antibanding);
- if (rc < 0)
- ALOGE("%s: Unable to set antibanding", __func__);
- }
- }
-
- // WB
-
- whitebalance_string = smdk4x12_param_string_get(smdk4x12_camera, "whitebalance");
- if (whitebalance_string != NULL) {
- if (strcmp(whitebalance_string, "auto") == 0)
- whitebalance = WHITE_BALANCE_AUTO;
- else if (strcmp(whitebalance_string, "incandescent") == 0)
- whitebalance = WHITE_BALANCE_TUNGSTEN;
- else if (strcmp(whitebalance_string, "fluorescent") == 0)
- whitebalance = WHITE_BALANCE_FLUORESCENT;
- else if (strcmp(whitebalance_string, "daylight") == 0)
- whitebalance = WHITE_BALANCE_SUNNY;
- else if (strcmp(whitebalance_string, "cloudy-daylight") == 0)
- whitebalance = WHITE_BALANCE_CLOUDY;
- else
- whitebalance = WHITE_BALANCE_AUTO;
-
- if (whitebalance != smdk4x12_camera->whitebalance || force) {
- smdk4x12_camera->whitebalance = whitebalance;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_WHITE_BALANCE, whitebalance);
- if (rc < 0)
- ALOGE("%s: Unable to set whitebalance", __func__);
- }
- }
-
- // Scene mode
-
- scene_mode_string = smdk4x12_param_string_get(smdk4x12_camera, "scene-mode");
- if (scene_mode_string != NULL) {
- if (strcmp(scene_mode_string, "auto") == 0)
- scene_mode = SCENE_MODE_NONE;
- else if (strcmp(scene_mode_string, "portrait") == 0)
- scene_mode = SCENE_MODE_PORTRAIT;
- else if (strcmp(scene_mode_string, "landscape") == 0)
- scene_mode = SCENE_MODE_LANDSCAPE;
- else if (strcmp(scene_mode_string, "night") == 0)
- scene_mode = SCENE_MODE_NIGHTSHOT;
- else if (strcmp(scene_mode_string, "beach") == 0)
- scene_mode = SCENE_MODE_BEACH_SNOW;
- else if (strcmp(scene_mode_string, "snow") == 0)
- scene_mode = SCENE_MODE_BEACH_SNOW;
- else if (strcmp(scene_mode_string, "sunset") == 0)
- scene_mode = SCENE_MODE_SUNSET;
- else if (strcmp(scene_mode_string, "fireworks") == 0)
- scene_mode = SCENE_MODE_FIREWORKS;
- else if (strcmp(scene_mode_string, "sports") == 0)
- scene_mode = SCENE_MODE_SPORTS;
- else if (strcmp(scene_mode_string, "party") == 0)
- scene_mode = SCENE_MODE_PARTY_INDOOR;
- else if (strcmp(scene_mode_string, "candlelight") == 0)
- scene_mode = SCENE_MODE_CANDLE_LIGHT;
- else if (strcmp(scene_mode_string, "dusk-dawn") == 0)
- scene_mode = SCENE_MODE_DUSK_DAWN;
- else if (strcmp(scene_mode_string, "fall-color") == 0)
- scene_mode = SCENE_MODE_FALL_COLOR;
- else if (strcmp(scene_mode_string, "back-light") == 0)
- scene_mode = SCENE_MODE_BACK_LIGHT;
- else if (strcmp(scene_mode_string, "text") == 0)
- scene_mode = SCENE_MODE_TEXT;
- else
- scene_mode = SCENE_MODE_NONE;
-
- if (scene_mode != smdk4x12_camera->scene_mode || force) {
- smdk4x12_camera->scene_mode = scene_mode;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_SCENE_MODE, scene_mode);
- if (rc < 0)
- ALOGE("%s: Unable to set scene mode", __func__);
- }
- }
-
- // Effect
-
- effect_string = smdk4x12_param_string_get(smdk4x12_camera, "effect");
- if (effect_string != NULL) {
- if (strcmp(effect_string, "auto") == 0)
- effect = IMAGE_EFFECT_NONE;
- if (strcmp(effect_string, "none") == 0)
- effect = IMAGE_EFFECT_NONE;
- else if (strcmp(effect_string, "mono") == 0)
- effect = IMAGE_EFFECT_BNW;
- else if (strcmp(effect_string, "negative") == 0)
- effect = IMAGE_EFFECT_NEGATIVE;
- else if (strcmp(effect_string, "sepia") == 0)
- effect = IMAGE_EFFECT_SEPIA;
- else if (strcmp(effect_string, "aqua") == 0)
- effect = IMAGE_EFFECT_AQUA;
- else if (strcmp(effect_string, "solarize") == 0)
- effect = IMAGE_EFFECT_SOLARIZE;
- else if (strcmp(effect_string, "posterize") == 0)
- effect = IMAGE_EFFECT_POSTERIZE;
- else if (strcmp(effect_string, "washed") == 0)
- effect = IMAGE_EFFECT_WASHED;
- else if (strcmp(effect_string, "sketch") == 0)
- effect = IMAGE_EFFECT_SKETCH;
- else if (strcmp(effect_string, "vintage-warm") == 0)
- effect = IMAGE_EFFECT_VINTAGE_WARM;
- else if (strcmp(effect_string, "vintage-cold") == 0)
- effect = IMAGE_EFFECT_VINTAGE_COLD;
- else if (strcmp(effect_string, "point-blue") == 0)
- effect = IMAGE_EFFECT_POINT_BLUE;
- else if (strcmp(effect_string, "point-red-yellow") == 0)
- effect = IMAGE_EFFECT_POINT_RED_YELLOW;
- else if (strcmp(effect_string, "point-green") == 0)
- effect = IMAGE_EFFECT_POINT_GREEN;
- else
- effect = IMAGE_EFFECT_NONE;
-
- if (effect != smdk4x12_camera->effect || force) {
- smdk4x12_camera->effect = effect;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_EFFECT, effect);
- if (rc < 0)
- ALOGE("%s: Unable to set effect", __func__);
- }
- }
-
- // ISO
-
- iso_string = smdk4x12_param_string_get(smdk4x12_camera, "iso");
- if (iso_string != NULL) {
- if (strcmp(iso_string, "auto") == 0)
- iso = ISO_AUTO;
- else if (strcmp(iso_string, "ISO50") == 0)
- iso = ISO_50;
- else if (strcmp(iso_string, "ISO100") == 0)
- iso = ISO_100;
- else if (strcmp(iso_string, "ISO200") == 0)
- iso = ISO_200;
- else if (strcmp(iso_string, "ISO400") == 0)
- iso = ISO_400;
- else if (strcmp(iso_string, "ISO800") == 0)
- iso = ISO_800;
- else
- iso = ISO_AUTO;
-
- if (iso != smdk4x12_camera->iso || force) {
- smdk4x12_camera->iso = iso;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_ISO, iso);
- if (rc < 0)
- ALOGE("%s: Unable to set iso", __func__);
- }
- }
-
- // Image stabilization
-
- image_stabilization_string = smdk4x12_param_string_get(smdk4x12_camera, "image-stabilization");
- if (image_stabilization_string != NULL) {
- if (strcmp(image_stabilization_string, "on") == 0)
- image_stabilization = ANTI_SHAKE_STILL_ON;
- else
- image_stabilization = ANTI_SHAKE_OFF;
-
- if (image_stabilization != smdk4x12_camera->image_stabilization || force) {
- smdk4x12_camera->image_stabilization = image_stabilization;
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_ANTI_SHAKE, image_stabilization);
- if (rc < 0)
- ALOGE("%s: Unable to set image-stabilization", __func__);
- }
- }
-
- ALOGD("%s: Preview size: %dx%d, picture size: %dx%d, recording size: %dx%d", __func__, preview_width, preview_height, picture_width, picture_height, recording_width, recording_height);
-
- return 0;
-}
-
-// Capture
-
-int s5c73m3_interleaved_decode(void *data, int size,
- void *yuv_data, int *yuv_size, int yuv_width, int yuv_height,
- void *jpeg_data, int *jpeg_size, int *decoded, int *auto_focus_result,
- int *exif_flash, int *exif_iso, int *exif_exposure,
- int *exif_exposure_bias, int *exif_exposure_time)
-{
- int yuv_length;
- int jpeg_length;
- unsigned char *yuv_p;
- unsigned char *jpeg_p;
- unsigned char *data_p;
- unsigned int *offset_p;
- unsigned int pointers_array_offset;
- unsigned int pointers_array_size;
- unsigned int interleaved_size;
- unsigned char s5c73m3_auto_focus_result;
- unsigned int yuv_offset_last;
- unsigned int yuv_offset;
- unsigned int yuv_line_size;
- unsigned short *jpeg_start_p;
- int gap;
- unsigned int i;
-
- if (data == NULL || size <= 0 || yuv_data == NULL || yuv_size == NULL || yuv_width <= 0 || yuv_height <= 0 || jpeg_data == NULL || jpeg_size == NULL || decoded == NULL || auto_focus_result == NULL || exif_flash == NULL || exif_iso == NULL || exif_exposure == NULL || exif_exposure_bias == NULL || exif_exposure_time == NULL)
- return -EINVAL;
-
- yuv_length = 0;
- jpeg_length = 0;
-
- data_p = (unsigned char *) data;
- data_p += size - 0x1000; // End of the first plane (interleaved buffer)
- data_p += 4046; // Experimental offset for decoded
-
- *decoded = (int) *data_p;
-
- data_p = (unsigned char *) data;
- data_p += size - 0x1000; // End of the first plane (interleaved buffer)
- data_p += 50; // Experimental offset for auto-focus result
-
- s5c73m3_auto_focus_result = *data_p;
- switch (s5c73m3_auto_focus_result) {
- case S5C73M3_AF_STATUS_FOCUSING:
- case S5C73M3_CAF_STATUS_FOCUSING:
- *auto_focus_result = CAMERA_AF_STATUS_IN_PROGRESS;
- break;
- case S5C73M3_AF_STATUS_FOCUSED:
- case S5C73M3_CAF_STATUS_FOCUSED:
- *auto_focus_result = CAMERA_AF_STATUS_SUCCESS;
- break;
- case S5C73M3_AF_STATUS_INVALID:
- case S5C73M3_CAF_STATUS_FIND_SEARCHING_DIR:
- case S5C73M3_AF_STATUS_UNFOCUSED:
- case S5C73M3_CAF_STATUS_UNFOCUSED:
- default:
- *auto_focus_result = CAMERA_AF_STATUS_FAIL;
- break;
- }
-
- data_p = (unsigned char *) data;
- data_p += size - 0x1000; // End of the first plane (interleaved buffer)
- data_p += 4; // EXIF flash offset
- *exif_flash = (int) *data_p;
-
- data_p += 4; // EXIF ISO offset
- *exif_iso = (int) ((data_p[1] << 8) | (data_p[0] & 0xff));
-
- data_p += 4; // EXIF exposure offset
- *exif_exposure = (int) *data_p;
-
- data_p += 4; // EXIF exposure bias offset
- *exif_exposure_bias = (int) ((data_p[1] << 8) | (data_p[0] & 0xff));
-
- data_p += 8; // EXIF exposure time offset
- *exif_exposure_time = (int) ((data_p[1] << 8) | (data_p[0] & 0xff));
-
- data_p = (unsigned char *) data;
- data_p += size - 0x1000; // End of the first plane (interleaved buffer)
- data_p += 4084; // Experimental offset for interleaved size
-
- // Read the pointers array offset
- offset_p = (unsigned int *) data_p;
- pointers_array_offset = BIG2LITTLE_ENDIAN(*offset_p);
- interleaved_size = pointers_array_offset;
-
- // Read the pointers array size, it should be 4 * yuv_height
- data_p += sizeof(pointers_array_offset);
- offset_p = (unsigned int *) data_p;
- pointers_array_size = BIG2LITTLE_ENDIAN(*offset_p);
-
- if (!*decoded)
- return 0;
-
- ALOGD("%s: Interleaved pointers array is at offset 0x%x, 0x%x bytes long\n", __func__, pointers_array_offset, pointers_array_size);
-
- if ((int) pointers_array_offset > size || (int) pointers_array_size > size || (int) pointers_array_size < yuv_height * (int) sizeof(unsigned int)) {
- ALOGE("%s: Invalid informations", __func__);
- return -1;
- }
-
- data_p = (unsigned char *) data;
- data_p += pointers_array_offset;
- yuv_p = (unsigned char *) yuv_data;
- jpeg_p = (unsigned char *) jpeg_data;
- jpeg_start_p = NULL;
-
- yuv_line_size = yuv_width * 2;
- yuv_offset_last = 0;
- yuv_offset = 0;
- i = 0;
-
- while (i < pointers_array_size) {
- offset_p = (unsigned int *) data_p;
- yuv_offset = BIG2LITTLE_ENDIAN(*offset_p);
-
- if (yuv_offset > size - yuv_line_size)
- return -1;
-
- gap = yuv_offset - yuv_offset_last - yuv_line_size;
-
- if (gap > 0) {
- data_p = (unsigned char *) data + yuv_offset_last + yuv_line_size;
-
- if (jpeg_start_p == NULL) {
- jpeg_start_p = (unsigned short *) data_p;
- if (*jpeg_start_p != 0xd8ff) {
- ALOGE("%s: Invalid jpeg start", __func__);
- return -1;
- }
- }
-
- memcpy(jpeg_p, data_p, gap);
- jpeg_p += gap;
- jpeg_length += gap;
- }
-
- yuv_offset_last = yuv_offset;
-
- data_p = (unsigned char *) data + yuv_offset;
- memcpy(yuv_p, data_p, yuv_line_size);
- yuv_p += yuv_line_size;
- yuv_length += yuv_line_size;
-
- data_p = (unsigned char *) offset_p;
- data_p += sizeof(yuv_offset);
- i += sizeof(yuv_offset);
- }
-
- gap = interleaved_size - yuv_offset_last - yuv_line_size;
-
- if (gap > 0) {
- data_p = (unsigned char *) data + yuv_offset_last + yuv_line_size;
-
- memcpy(jpeg_p, data_p, gap);
- jpeg_p += gap;
- jpeg_length += gap;
- }
-
- *yuv_size = yuv_length;
- *jpeg_size = jpeg_length;
-
- return 0;
-}
-
-int smdk4x12_camera_capture(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_camera_capture_listener *listener;
- struct smdk4x12_camera_buffer *buffers = NULL;
- struct smdk4x12_camera_buffer *buffer;
- struct list_head *list;
- int width, height, format;
- int yuv_length, jpeg_length;
- int jpeg_offset, jpeg_size;
- int jpeg_thumbnail_offset, jpeg_thumbnail_size;
- int buffers_count;
- int buffer_length;
- int auto_focus_result;
- int decoded;
- int busy;
- void *pointer;
- int address;
- int offset;
- int index;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- width = smdk4x12_camera->capture_width;
- height = smdk4x12_camera->capture_height;
- format = smdk4x12_camera->capture_format;
-
- buffers_count = smdk4x12_camera->capture_buffers_count;
- buffer_length = smdk4x12_camera->capture_buffer_length;
-
- // V4L2
-
- index = smdk4x12_v4l2_dqbuf_cap(smdk4x12_camera, 0);
- if (index < 0 || index >= buffers_count) {
- rc = smdk4x12_v4l2_poll(smdk4x12_camera, 0);
- if (rc < 0) {
- ALOGE("%s Unable to poll", __func__);
- goto error;
- } else if (rc == 0) {
- // Timeout
- rc = 0;
- goto complete;
- }
-
- index = smdk4x12_v4l2_dqbuf_cap(smdk4x12_camera, 0);
- if (index < 0 || index >= buffers_count) {
- ALOGE("%s: Unable to dequeue buffer", __func__);
- goto error;
- }
- }
-
- smdk4x12_camera->capture_memory_index = index;
-
- address = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_PADDR_Y, index);
- if (address == 0 || address == (int) 0xffffffff) {
- ALOGE("%s: Unable to get address", __func__);
- goto error;
- }
-
- offset = address - smdk4x12_camera->capture_memory_address;
- if (offset != index * buffer_length)
- ALOGE("%s: Inconsistent memory offset (0x%x/0x%x)", __func__, offset, index * buffer_length);
-
- pointer = (void *) ((unsigned char *) smdk4x12_camera->capture_memory->data + offset);
-
- // Buffers
-
- switch (format) {
- case V4L2_PIX_FMT_INTERLEAVED:
- yuv_length = jpeg_length = 0;
- auto_focus_result = decoded = 0;
-
- rc = s5c73m3_interleaved_decode(pointer, buffer_length, smdk4x12_camera->capture_yuv_buffer, &yuv_length, width, height, smdk4x12_camera->capture_jpeg_buffer, &jpeg_length, &decoded, &auto_focus_result, &smdk4x12_camera->capture_exif_flash, &smdk4x12_camera->capture_exif_iso, &smdk4x12_camera->capture_exif_exposure, &smdk4x12_camera->capture_exif_exposure_bias, &smdk4x12_camera->capture_exif_exposure_time);
- if (rc < 0) {
- ALOGE("%s: Unable to decode S5C73M3 interleaved", __func__);
- goto error;
- }
-
- if (auto_focus_result != smdk4x12_camera->auto_focus_result) {
- if (!smdk4x12_camera->auto_focus_thread_enabled) {
- smdk4x12_camera->auto_focus_result = auto_focus_result;
-
- rc = smdk4x12_camera_auto_focus(smdk4x12_camera, auto_focus_result);
- if (rc < 0) {
- ALOGE("%s: Unable to auto focus", __func__);
- goto error;
- }
- }
- }
-
- if (!decoded) {
- buffers_count = 1;
- buffers = (struct smdk4x12_camera_buffer *) calloc(buffers_count, sizeof(struct smdk4x12_camera_buffer));
-
- buffer = buffers;
-
- buffer->pointer = pointer;
- buffer->address = address;
- buffer->length = smdk4x12_camera_buffer_length(width, height, V4L2_PIX_FMT_UYVY);
- buffer->width = width;
- buffer->height = height;
- buffer->format = V4L2_PIX_FMT_UYVY;
- } else {
- buffers_count = 2;
- buffers = (struct smdk4x12_camera_buffer *) calloc(buffers_count, sizeof(struct smdk4x12_camera_buffer));
-
- buffer = buffers;
-
- memcpy(pointer, smdk4x12_camera->capture_yuv_buffer, yuv_length);
-
- buffer->pointer = pointer;
- buffer->address = address;
- buffer->length = yuv_length;
- buffer->width = width;
- buffer->height = height;
- buffer->format = V4L2_PIX_FMT_UYVY;
-
- pointer = (void *) ((unsigned char *) pointer + yuv_length);
- address += yuv_length;
- buffer = (struct smdk4x12_camera_buffer *) ((unsigned char *) buffer + sizeof(struct smdk4x12_camera_buffer));
-
- memcpy(pointer, smdk4x12_camera->capture_jpeg_buffer, jpeg_length);
-
- buffer->pointer = pointer;
- buffer->address = address;
- buffer->length = jpeg_length;
- buffer->width = smdk4x12_camera->picture_width;
- buffer->height = smdk4x12_camera->picture_height;
- buffer->format = V4L2_PIX_FMT_JPEG;
-
- smdk4x12_camera->capture_hybrid = 0;
- }
- break;
- case V4L2_PIX_FMT_JPEG:
- jpeg_size = jpeg_offset = 0;
- jpeg_thumbnail_size = jpeg_thumbnail_offset = 0;
-
- rc = smdk4x12_v4l2_g_ctrl(smdk4x12_camera, 0, V4L2_CID_CAM_JPEG_MAIN_SIZE, &jpeg_size);
- if (rc < 0 || jpeg_size <= 0) {
- ALOGE("%s: Unable to get jpeg size", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_g_ctrl(smdk4x12_camera, 0, V4L2_CID_CAM_JPEG_MAIN_OFFSET, &jpeg_offset);
- if (rc < 0) {
- ALOGE("%s: Unable to get jpeg offset", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_g_ctrl(smdk4x12_camera, 0, V4L2_CID_CAM_JPEG_THUMB_SIZE, &jpeg_thumbnail_size);
- if (rc < 0 || jpeg_thumbnail_size <= 0) {
- ALOGE("%s: Unable to get jpeg thumbnail size", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_g_ctrl(smdk4x12_camera, 0, V4L2_CID_CAM_JPEG_THUMB_OFFSET, &jpeg_thumbnail_offset);
- if (rc < 0) {
- ALOGE("%s: Unable to get jpeg thumbnail offset", __func__);
- goto error;
- }
-
- buffers_count = 2;
- buffers = (struct smdk4x12_camera_buffer *) calloc(buffers_count, sizeof(struct smdk4x12_camera_buffer));
-
- buffer = buffers;
-
- buffer->pointer = (void *) ((unsigned char *) pointer + jpeg_offset);
- buffer->address = address + jpeg_offset;
- buffer->length = jpeg_size;
- buffer->width = smdk4x12_camera->picture_width;
- buffer->height = smdk4x12_camera->picture_height;
- buffer->format = V4L2_PIX_FMT_JPEG;
-
- buffer = (struct smdk4x12_camera_buffer *) ((unsigned char *) buffer + sizeof(struct smdk4x12_camera_buffer));
-
- buffer->pointer = (void *) ((unsigned char *) pointer + jpeg_thumbnail_offset);
- buffer->address = address + jpeg_thumbnail_offset;
- buffer->length = jpeg_thumbnail_size;
- buffer->width = smdk4x12_camera->jpeg_thumbnail_width;
- buffer->height = smdk4x12_camera->jpeg_thumbnail_height;
- buffer->format = V4L2_PIX_FMT_JPEG;
- break;
- default:
- buffers_count = 1;
- buffers = (struct smdk4x12_camera_buffer *) calloc(buffers_count, sizeof(struct smdk4x12_camera_buffer));
-
- buffer = buffers;
-
- buffer->pointer = pointer;
- buffer->address = address;
- buffer->length = buffer_length;
- buffer->width = width;
- buffer->height = height;
- buffer->format = format;
- break;
- }
-
- // Listeners
-
- list = (struct list_head *) smdk4x12_camera->capture_listeners;
- while (list != NULL) {
- listener = (struct smdk4x12_camera_capture_listener *) list;
-
- if (listener->callback == NULL)
- goto list_continue_callback;
-
- /*
- * Callback must never call a capture-locked function or it will
- * block. Hence, do not unregister the listener in callback.
- */
-
- listener->callback(smdk4x12_camera, buffers, buffers_count);
-
-list_continue_callback:
- list = list->next;
- }
-
- do {
- busy = 0;
-
- list = (struct list_head *) smdk4x12_camera->capture_listeners;
- while (list != NULL) {
- listener = (struct smdk4x12_camera_capture_listener *) list;
-
- if (listener->callback == NULL)
- goto list_continue_busy;
-
- busy |= listener->busy;
-
-list_continue_busy:
- list = list->next;
- }
-
- if (busy)
- usleep(1000);
- } while (busy);
-
- rc = smdk4x12_v4l2_qbuf_cap(smdk4x12_camera, 0, index);
- if (rc < 0) {
- ALOGE("%s: Unable to queue buffer", __func__);
- goto error;
- }
-
- rc = 0;
- goto complete;
-
-error:
- rc = -1;
-
-complete:
- if (buffers != NULL)
- free(buffers);
-
- return rc;
-}
-
-void *smdk4x12_camera_capture_thread(void *data)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int rc;
-
- if (data == NULL)
- return NULL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) data;
-
- ALOGE("%s: Starting thread", __func__);
- smdk4x12_camera->capture_thread_running = 1;
-
- while (smdk4x12_camera->capture_thread_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->capture_lock_mutex);
-
- while (smdk4x12_camera->capture_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->capture_mutex);
-
- if (!smdk4x12_camera->capture_enabled) {
- pthread_mutex_unlock(&smdk4x12_camera->capture_mutex);
- break;
- }
-
- rc = smdk4x12_camera_capture(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to capture", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->capture_mutex);
- break;
- }
-
- pthread_mutex_unlock(&smdk4x12_camera->capture_mutex);
-
- // Wait a bit to let others lock the mutex if they need to
- usleep(10);
- }
- }
-
- smdk4x12_camera->capture_thread_running = 0;
- ALOGE("%s: Exiting thread", __func__);
-
- return NULL;
-}
-
-int smdk4x12_camera_capture_thread_start(struct smdk4x12_camera *smdk4x12_camera)
-{
- pthread_attr_t thread_attr;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->capture_thread_enabled) {
- ALOGE("Capture thread was already started!");
- return -1;
- }
-
- pthread_mutex_init(&smdk4x12_camera->capture_mutex, NULL);
- pthread_mutex_init(&smdk4x12_camera->capture_lock_mutex, NULL);
-
- // Initial lock
- pthread_mutex_lock(&smdk4x12_camera->capture_lock_mutex);
-
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
-
- smdk4x12_camera->capture_thread_enabled = 1;
-
- rc = pthread_create(&smdk4x12_camera->capture_thread, &thread_attr, smdk4x12_camera_capture_thread, (void *) smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to create thread", __func__);
- goto error;
- }
-
- rc = 0;
- goto complete;
-
-error:
- pthread_mutex_destroy(&smdk4x12_camera->capture_mutex);
- pthread_mutex_destroy(&smdk4x12_camera->capture_lock_mutex);
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_capture_thread_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- int i;
-
- if (smdk4x12_camera == NULL)
- return;
-
- ALOGD("%s()", __func__);
-
- if (!smdk4x12_camera->capture_thread_enabled) {
- ALOGE("Capture thread was already stopped!");
- return;
- }
-
- smdk4x12_camera->capture_enabled = 0;
- smdk4x12_camera->capture_thread_enabled = 0;
-
- pthread_mutex_unlock(&smdk4x12_camera->capture_lock_mutex);
-
- // Wait for the thread to end
- i = 0;
- while (smdk4x12_camera->capture_thread_running) {
- if (i++ > 10000) {
- ALOGE("Capture thread is taking too long to end, something is going wrong");
- break;
- }
- usleep(100);
- }
-
- if (smdk4x12_camera->capture_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->capture_mutex);
- smdk4x12_camera_capture_stop(smdk4x12_camera);
- pthread_mutex_unlock(&smdk4x12_camera->capture_mutex);
- }
-
- pthread_mutex_destroy(&smdk4x12_camera->capture_mutex);
- pthread_mutex_destroy(&smdk4x12_camera->capture_lock_mutex);
-}
-
-int smdk4x12_camera_capture_start(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct v4l2_streamparm fps_param;
- int width, height, format;
- int mbus_width, mbus_height;
- int buffers_count, buffer_length;
- camera_memory_t *memory = NULL;
- int value;
- int fd;
- int rc;
- int i;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->capture_enabled) {
- ALOGE("Capture was already started!");
- return -1;
- }
-
- width = smdk4x12_camera->capture_width;
- height = smdk4x12_camera->capture_height;
- format = smdk4x12_camera->capture_format;
-
- // V4L2
-
- if (format == V4L2_PIX_FMT_INTERLEAVED) {
- ALOGD("Enabling hybrid capture");
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_HYBRID, 1);
- if (rc < 0) {
- ALOGE("%s: Unable to set hybrid", __func__);
- goto error;
- }
- }
-
- if (smdk4x12_camera->camera_fimc_is) {
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_IS_S_FORMAT_SCENARIO, smdk4x12_camera->fimc_is_mode);
- if (rc < 0) {
- ALOGE("%s: Unable to set FIMC-IS scenario", __func__);
- goto error;
- }
- }
-
- rc = smdk4x12_v4l2_enum_fmt_cap(smdk4x12_camera, 0, format);
- if (rc < 0) {
- ALOGE("%s: Unable to enumerate formats", __func__);
- goto error;
- }
-
- mbus_width = width;
- mbus_height = height;
-
- if (smdk4x12_camera->camera_mbus_resolutions != NULL) {
- for (i = 0; i < smdk4x12_camera->camera_mbus_resolutions_count; i++) {
- if (smdk4x12_camera->camera_mbus_resolutions[i].width == width && smdk4x12_camera->camera_mbus_resolutions[i].height == height) {
- mbus_width = smdk4x12_camera->camera_mbus_resolutions[i].mbus_width;
- mbus_height = smdk4x12_camera->camera_mbus_resolutions[i].mbus_height;
- break;
- }
- }
- }
-
- if (smdk4x12_camera->camera_fimc_is) {
- // Set MBUS width/height/format
- rc = smdk4x12_v4l2_s_fmt_pix(smdk4x12_camera, 0, V4L2_BUF_TYPE_PRIVATE, mbus_width, mbus_height, format, smdk4x12_camera->fimc_is_mode, V4L2_PIX_FMT_MODE_PREVIEW);
- if (rc < 0) {
- ALOGE("%s: Unable to set MBUS capture pixel format", __func__);
- goto error;
- }
- }
-
- rc = smdk4x12_v4l2_s_fmt_pix_cap(smdk4x12_camera, 0, width, height, format, V4L2_PIX_FMT_MODE_PREVIEW);
- if (rc < 0) {
- ALOGE("%s: Unable to set capture pixel format", __func__);
- goto error;
- }
-
- if (!smdk4x12_camera->camera_fimc_is) {
- // Set MBUS width/height/format
- rc = smdk4x12_v4l2_s_fmt_pix(smdk4x12_camera, 0, V4L2_BUF_TYPE_PRIVATE, mbus_width, mbus_height, format, V4L2_FIELD_NONE, V4L2_PIX_FMT_MODE_PREVIEW);
- if (rc < 0) {
- ALOGE("%s: Unable to set MBUS capture pixel format", __func__);
- goto error;
- }
- }
-
- if (format == V4L2_PIX_FMT_INTERLEAVED)
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CACHEABLE, 0);
- else
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CACHEABLE, 1);
- if (rc < 0) {
- ALOGE("%s: Unable to set cacheable", __func__);
- goto error;
- }
-
- if (smdk4x12_camera->camera_fimc_is) {
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_IS_S_SCENARIO_MODE, smdk4x12_camera->fimc_is_mode);
- if (rc < 0) {
- ALOGE("%s: Unable to set FIMC-IS scenario mode", __func__);
- goto error;
- }
- }
-
- if (format == V4L2_PIX_FMT_INTERLEAVED) {
- // This must be set to 1 for interleaved data decoding
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_EMBEDDEDDATA_ENABLE, 1);
- if (rc < 0) {
- ALOGE("%s: Unable to set embdedded data enable", __func__);
- goto error;
- }
- }
-
- // Let's assume FIMC0 has memory available through mmap
-
- for (i = SMDK4x12_CAMERA_CAPTURE_BUFFERS_COUNT; i > 0; i--) {
- rc = smdk4x12_v4l2_reqbufs_cap(smdk4x12_camera, 0, i);
- if (rc >= 0)
- break;
- }
-
- if (rc < 0) {
- ALOGE("%s: Unable to request buffers", __func__);
- goto error;
- }
-
- buffers_count = rc;
- ALOGD("Found %d buffers available for capture!", buffers_count);
-
- memset(&fps_param, 0, sizeof(fps_param));
- fps_param.parm.capture.timeperframe.numerator = 1;
- fps_param.parm.capture.timeperframe.denominator = smdk4x12_camera->preview_fps;
-
- rc = smdk4x12_v4l2_s_parm_cap(smdk4x12_camera, 0, &fps_param);
- if (rc < 0) {
- ALOGE("%s: Unable to set fps", __func__);
- goto error;
- }
-
- for (i = 0; i < buffers_count; i++) {
- rc = smdk4x12_v4l2_querybuf_cap(smdk4x12_camera, 0, i);
- if (rc < 0) {
- ALOGE("%s: Unable to query buffers", __func__);
- goto error;
- }
- }
-
- buffer_length = rc;
-
- value = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_PADDR_Y, 0);
- if (value == 0 || value == (int) 0xffffffff) {
- ALOGE("%s: Unable to get address", __func__);
- goto error;
- }
-
- smdk4x12_camera->capture_memory_address = value;
-
- if (SMDK4x12_CAMERA_CALLBACK_DEFINED(request_memory)) {
- fd = smdk4x12_v4l2_fd(smdk4x12_camera, 0);
- if (fd < 0) {
- ALOGE("%s: Unable to get v4l2 fd for id %d", __func__, 0);
- goto error;
- }
-
- smdk4x12_camera->capture_memory = NULL;
-
- memory = smdk4x12_camera->callbacks.request_memory(fd, buffer_length, buffers_count, smdk4x12_camera->callbacks.user);
- if (memory == NULL || memory->data == NULL || memory->data == MAP_FAILED) {
- ALOGE("%s: Unable to request memory", __func__);
- goto error;
- }
-
- smdk4x12_camera->capture_memory = memory;
- } else {
- ALOGE("%s: No memory request function!", __func__);
- goto error;
- }
-
- if (format == V4L2_PIX_FMT_INTERLEAVED) {
- smdk4x12_camera->capture_yuv_buffer = malloc(buffer_length);
- smdk4x12_camera->capture_jpeg_buffer = malloc(buffer_length);
- }
-
- for (i = 0; i < buffers_count; i++) {
- rc = smdk4x12_v4l2_qbuf_cap(smdk4x12_camera, 0, i);
- if (rc < 0) {
- ALOGE("%s: Unable to queue buffer", __func__);
- goto error;
- }
- }
-
- smdk4x12_camera->capture_buffers_count = buffers_count;
- smdk4x12_camera->capture_buffer_length = buffer_length;
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_ROTATION,
- smdk4x12_camera->camera_rotation);
- if (rc < 0) {
- ALOGE("%s: Unable to set rotation", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_HFLIP,
- smdk4x12_camera->camera_hflip);
- if (rc < 0) {
- ALOGE("%s: Unable to set hflip", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_VFLIP,
- smdk4x12_camera->camera_vflip);
- if (rc < 0) {
- ALOGE("%s: Unable to set vflip", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_streamon_cap(smdk4x12_camera, 0);
- if (rc < 0) {
- ALOGE("%s: Unable to start stream", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_SCENE_MODE, smdk4x12_camera->scene_mode);
- if (rc < 0) {
- ALOGE("%s: Unable to set scene mode", __func__);
- goto error;
- }
-
- smdk4x12_camera->capture_enabled = 1;
- pthread_mutex_unlock(&smdk4x12_camera->capture_lock_mutex);
-
- rc = 0;
- goto complete;
-
-error:
- if (smdk4x12_camera->capture_memory != NULL && smdk4x12_camera->capture_memory->release != NULL) {
- smdk4x12_camera->capture_memory->release(smdk4x12_camera->capture_memory);
- smdk4x12_camera->capture_memory = NULL;
- }
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_capture_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- int rc;
- int i;
-
- if (smdk4x12_camera == NULL)
- return;
-
- ALOGD("%s()", __func__);
-
- if (!smdk4x12_camera->capture_enabled) {
- ALOGE("Capture was already stopped!");
- return;
- }
-
- if (smdk4x12_camera->capture_format == V4L2_PIX_FMT_INTERLEAVED) {
- ALOGD("Disabling hybrid capture");
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_HYBRID, 0);
- if (rc < 0)
- ALOGE("%s: Unable to set hybrid", __func__);
- }
-
- rc = smdk4x12_v4l2_streamoff_cap(smdk4x12_camera, 0);
- if (rc < 0) {
- ALOGE("%s: Unable to stop stream", __func__);
- }
-
- if (smdk4x12_camera->capture_memory != NULL && smdk4x12_camera->capture_memory->release != NULL) {
- smdk4x12_camera->capture_memory->release(smdk4x12_camera->capture_memory);
- smdk4x12_camera->capture_memory = NULL;
- }
-
- if (smdk4x12_camera->capture_yuv_buffer != NULL) {
- free(smdk4x12_camera->capture_yuv_buffer);
- smdk4x12_camera->capture_yuv_buffer = NULL;
- }
-
- if (smdk4x12_camera->capture_jpeg_buffer != NULL) {
- free(smdk4x12_camera->capture_jpeg_buffer);
- smdk4x12_camera->capture_jpeg_buffer = NULL;
- }
-
- smdk4x12_camera->capture_enabled = 0;
-}
-
-int smdk4x12_camera_capture_setup(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_camera_capture_listener *listener;
- struct list_head *list;
- int width, height, format;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- // No listener left
- if (smdk4x12_camera->capture_listeners == NULL && smdk4x12_camera->capture_enabled) {
- smdk4x12_camera_capture_stop(smdk4x12_camera);
- return 0;
- }
-
- width = height = format = 0;
-
- list = (struct list_head *) smdk4x12_camera->capture_listeners;
- while (list != NULL) {
- listener = (struct smdk4x12_camera_capture_listener *) list;
-
- // Interleaved format already has the correct width and height for picture set through ioctl
- if (smdk4x12_camera->camera_capture_format == V4L2_PIX_FMT_INTERLEAVED)
- if (listener->format == V4L2_PIX_FMT_JPEG || listener->format == V4L2_PIX_FMT_INTERLEAVED)
- goto list_continue;
-
- if (listener->width >= width && listener->height >= height) {
- width = listener->width;
- height = listener->height;
- format = listener->format;
- }
-
-list_continue:
- list = list->next;
- }
-
- // Override the capture format
- if (smdk4x12_camera->camera_capture_format)
- format = smdk4x12_camera->camera_capture_format;
-
- // Only picture is listening, but we need some preview size anyway
- if (format == V4L2_PIX_FMT_INTERLEAVED && (width == 0 || height == 0)) {
- width = smdk4x12_camera->preview_width;
- height = smdk4x12_camera->preview_height;
- }
-
- ALOGD("%s: Selected width: %d, height: %d, format: 0x%x", __func__, width, height, format);
-
- if (!smdk4x12_camera->capture_enabled) {
- smdk4x12_camera->capture_width = width;
- smdk4x12_camera->capture_height = height;
- smdk4x12_camera->capture_format = format;
-
- rc = smdk4x12_camera_capture_start(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to start capture", __func__);
- return -1;
- }
- } else if (smdk4x12_camera->capture_width != width || smdk4x12_camera->capture_height != height || smdk4x12_camera->capture_format != format) {
- smdk4x12_camera_capture_stop(smdk4x12_camera);
-
- smdk4x12_camera->capture_width = width;
- smdk4x12_camera->capture_height = height;
- smdk4x12_camera->capture_format = format;
-
- rc = smdk4x12_camera_capture_start(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to start capture", __func__);
- return -1;
- }
- }
-
- return 0;
-}
-
-struct smdk4x12_camera_capture_listener *smdk4x12_camera_capture_listener_register(
- struct smdk4x12_camera *smdk4x12_camera, int width, int height, int format,
- int (*callback)(struct smdk4x12_camera *smdk4x12_camera, struct smdk4x12_camera_buffer *buffers, int buffers_count))
-{
- struct smdk4x12_camera_capture_listener *listener = NULL;
- struct list_head *list_end;
- struct list_head *list;
- int rc;
-
- if (smdk4x12_camera == NULL || callback == NULL)
- return NULL;
-
- pthread_mutex_lock(&smdk4x12_camera->capture_mutex);
-
- listener = calloc(1, sizeof(struct smdk4x12_camera_capture_listener));
- if (listener == NULL)
- goto error;
-
- listener->width = width;
- listener->height = height;
- listener->format = format;
- listener->callback = callback;
- listener->busy = 0;
-
- list_end = (struct list_head *) smdk4x12_camera->capture_listeners;
- while (list_end != NULL && list_end->next != NULL)
- list_end = list_end->next;
-
- list = (struct list_head *) listener;
- list_head_insert(list, list_end, NULL);
-
- if (smdk4x12_camera->capture_listeners == NULL)
- smdk4x12_camera->capture_listeners = listener;
-
- rc = smdk4x12_camera_capture_setup(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to setup capture", __func__);
- goto error;
- }
-
- rc = 0;
- goto complete;
-
-error:
- listener = NULL;
-
-complete:
- pthread_mutex_unlock(&smdk4x12_camera->capture_mutex);
-
- return listener;
-}
-
-void smdk4x12_camera_capture_listener_unregister(
- struct smdk4x12_camera *smdk4x12_camera,
- struct smdk4x12_camera_capture_listener *listener)
-{
- struct list_head *list;
- int rc;
-
- if (smdk4x12_camera == NULL || listener == NULL)
- return;
-
- pthread_mutex_lock(&smdk4x12_camera->capture_mutex);
-
- list = (struct list_head *) smdk4x12_camera->capture_listeners;
- while (list != NULL) {
- if ((void *) list == (void *) listener) {
- list_head_remove(list);
-
- if ((void *) list == (void *) smdk4x12_camera->capture_listeners)
- smdk4x12_camera->capture_listeners = (struct smdk4x12_camera_capture_listener *) list->next;
-
- memset(listener, 0, sizeof(struct smdk4x12_camera_capture_listener));
- free(listener);
-
- break;
- }
-list_continue:
- list = list->next;
- }
-
- rc = smdk4x12_camera_capture_setup(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to setup capture", __func__);
- goto complete;
- }
-
-complete:
- pthread_mutex_unlock(&smdk4x12_camera->capture_mutex);
-}
-
-// Preview
-
-int smdk4x12_camera_preview_output_start(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_v4l2_output *output;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->preview_output_enabled) {
- ALOGE("Preview was already started!");
- return -1;
- }
-
- output = &smdk4x12_camera->preview_output;
-
- memset(output, 0, sizeof(struct smdk4x12_v4l2_output));
- output->v4l2_id = 1;
- output->width = smdk4x12_camera->preview_width;
- output->height = smdk4x12_camera->preview_height;
- output->format = smdk4x12_camera->preview_format;
- output->buffer_width = smdk4x12_camera->preview_buffer.width;
- output->buffer_height = smdk4x12_camera->preview_buffer.height;
- output->buffer_format = smdk4x12_camera->preview_buffer.format;
- output->buffers_count = SMDK4x12_CAMERA_PREVIEW_BUFFERS_COUNT;
-
- rc = smdk4x12_v4l2_output_start(smdk4x12_camera, output);
- if (rc < 0) {
- ALOGE("%s: Unable to start preview output", __func__);
- goto error;
- }
-
- smdk4x12_camera->preview_output_enabled = 1;
-
- rc = 0;
- goto complete;
-
-error:
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_preview_output_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_v4l2_output *output;
-
- if (smdk4x12_camera == NULL)
- return;
-
- ALOGD("%s()", __func__);
-
- if (!smdk4x12_camera->preview_output_enabled) {
- ALOGE("Preview was already stopped!");
- return;
- }
-
- output = &smdk4x12_camera->preview_output;
-
- smdk4x12_v4l2_output_stop(smdk4x12_camera, output);
-
- smdk4x12_camera->preview_output_enabled = 0;
-}
-
-int smdk4x12_camera_preview_callback(struct smdk4x12_camera *smdk4x12_camera,
- struct smdk4x12_camera_buffer *buffers, int buffers_count)
-{
- struct smdk4x12_camera_buffer *buffer = NULL;
- int width, height, format;
- int buffer_width, buffer_height, buffer_format;
- int rc;
- int i;
-
- if (smdk4x12_camera == NULL || buffers == NULL || buffers_count <= 0)
- return -EINVAL;
-
-// ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->preview_listener == NULL)
- return -1;
-
- if (smdk4x12_camera->preview_listener->busy) {
- ALOGE("%s: Dropping buffer", __func__);
- return 0;
- }
-
- if (smdk4x12_camera->preview_listener->width != smdk4x12_camera->preview_width || smdk4x12_camera->preview_listener->height != smdk4x12_camera->preview_height || smdk4x12_camera->preview_listener->format != smdk4x12_camera->preview_format) {
- ALOGD("%s: Waiting for preview listener update", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->preview_lock_mutex);
- return 0;
- }
-
- smdk4x12_camera->preview_listener->busy = 1;
-
- width = smdk4x12_camera->preview_width;
- height = smdk4x12_camera->preview_height;
- format = smdk4x12_camera->preview_format;
-
- for (i = 0; i < buffers_count; i++) {
- if (buffers->format == V4L2_PIX_FMT_JPEG)
- goto buffers_continue;
-
- if (buffers->format == V4L2_PIX_FMT_INTERLEAVED)
- goto buffers_continue;
-
- // Optimal buffer
- if (buffers->width == width && buffers->height == height) {
- buffer = buffers;
- break;
- }
-
- // Might-work buffer, but not optimal
- buffer = buffers;
-
-buffers_continue:
- buffers = (struct smdk4x12_camera_buffer *) ((unsigned char *) buffers + sizeof(struct smdk4x12_camera_buffer));
- }
-
- if (buffer == NULL) {
- ALOGE("%s: Unable to find an appropriate buffer for preview", __func__);
- smdk4x12_camera->preview_listener->busy = 0;
- return 0;
- }
-
- buffer_width = buffer->width;
- buffer_height = buffer->height;
- buffer_format = buffer->format;
-
- pthread_mutex_lock(&smdk4x12_camera->preview_mutex);
-
- if (buffer_width != width || buffer_height != height || buffer_format != format) {
- if (!smdk4x12_camera->preview_output_enabled) {
- memcpy(&smdk4x12_camera->preview_buffer, buffer, sizeof(struct smdk4x12_camera_buffer));
-
- rc = smdk4x12_camera_preview_output_start(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to start preview", __func__);
- goto error;
- }
- } else if (smdk4x12_camera->preview_buffer.width != buffer_width || smdk4x12_camera->preview_buffer.height != buffer_height || smdk4x12_camera->preview_buffer.format != buffer_format) {
- smdk4x12_camera_preview_output_stop(smdk4x12_camera);
-
- memcpy(&smdk4x12_camera->preview_buffer, buffer, sizeof(struct smdk4x12_camera_buffer));
-
- rc = smdk4x12_camera_preview_output_start(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to start preview", __func__);
- goto error;
- }
- } else {
- memcpy(&smdk4x12_camera->preview_buffer, buffer, sizeof(struct smdk4x12_camera_buffer));
- }
- } else {
- // The buffer format exactly matches our expectations
-
- if (smdk4x12_camera->preview_output_enabled)
- smdk4x12_camera_preview_output_stop(smdk4x12_camera);
-
- memcpy(&smdk4x12_camera->preview_buffer, buffer, sizeof(struct smdk4x12_camera_buffer));
- }
-
- pthread_mutex_unlock(&smdk4x12_camera->preview_lock_mutex);
-
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
-
- rc = 0;
- goto complete;
-
-error:
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
-
- smdk4x12_camera->preview_listener->busy = 0;
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-int smdk4x12_camera_preview(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_v4l2_output *output;
- int width, height, format;
- buffer_handle_t *window_buffer;
- void *window_data;
- int window_stride;
- camera_memory_t *memory;
- void *memory_pointer;
- int memory_index;
- int memory_size;
- int rc;
-
- if (smdk4x12_camera == NULL)
- goto error;
-
-// ALOGD("%s()", __func__);
-
- width = smdk4x12_camera->preview_width;
- height = smdk4x12_camera->preview_height;
- format = smdk4x12_camera->preview_format;
-
- output = &smdk4x12_camera->preview_output;
-
- if (smdk4x12_camera->preview_output_enabled) {
- rc = smdk4x12_v4l2_output(smdk4x12_camera, output, smdk4x12_camera->preview_buffer.address);
- if (rc < 0) {
- ALOGE("%s: Unable to output preview", __func__);
- goto error;
- }
-
- memory = output->memory;
- memory_index = output->memory_index;
- memory_pointer = (void *) ((unsigned char *) memory->data + output->buffer_length * memory_index);
- memory_size = output->buffer_length;
- } else {
- // In that case, we can directly use the capture memory
- memory = smdk4x12_camera->capture_memory;
- memory_index = smdk4x12_camera->capture_memory_index;
- memory_pointer = smdk4x12_camera->preview_buffer.pointer;
- memory_size = smdk4x12_camera->preview_buffer.length;
- }
-
- if (smdk4x12_camera->preview_window != NULL && smdk4x12_camera->gralloc != NULL) {
- smdk4x12_camera->preview_window->dequeue_buffer(smdk4x12_camera->preview_window, &window_buffer, &window_stride);
- smdk4x12_camera->gralloc->lock(smdk4x12_camera->gralloc, *window_buffer, GRALLOC_USAGE_SW_WRITE_OFTEN, 0, 0, width, height, &window_data);
-
- if (window_data == NULL) {
- ALOGE("%s: Unable to lock gralloc", __func__);
- goto error;
- }
-
- memcpy(window_data, memory_pointer, memory_size);
-
- smdk4x12_camera->gralloc->unlock(smdk4x12_camera->gralloc, *window_buffer);
- smdk4x12_camera->preview_window->enqueue_buffer(smdk4x12_camera->preview_window, window_buffer);
- }
-
- if (SMDK4x12_CAMERA_MSG_ENABLED(CAMERA_MSG_PREVIEW_FRAME) && SMDK4x12_CAMERA_CALLBACK_DEFINED(data) && !smdk4x12_camera->callback_lock) {
- smdk4x12_camera->callbacks.data(CAMERA_MSG_PREVIEW_FRAME, memory, memory_index, NULL, smdk4x12_camera->callbacks.user);
- }
-
- if (smdk4x12_camera->preview_output_enabled) {
- rc = smdk4x12_v4l2_output_release(smdk4x12_camera, output);
- if (rc < 0) {
- ALOGE("%s: Unable to release preview output", __func__);
- goto error;
- }
- }
-
- rc = 0;
- goto complete;
-
-error:
- rc = -1;
-
-complete:
- smdk4x12_camera->preview_listener->busy = 0;
-
- return rc;
-}
-
-void *smdk4x12_camera_preview_thread(void *data)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- struct smdk4x12_camera_capture_listener *listener;
- int gralloc_format;
- int rc;
-
- if (data == NULL)
- return NULL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) data;
-
- ALOGE("%s: Starting thread", __func__);
- smdk4x12_camera->preview_thread_running = 1;
-
- while (smdk4x12_camera->preview_thread_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->preview_lock_mutex);
-
- pthread_mutex_lock(&smdk4x12_camera->preview_mutex);
-
- if (smdk4x12_camera->preview_listener == NULL) {
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
- break;
- }
-
- if (smdk4x12_camera->preview_listener->busy) {
- rc = smdk4x12_camera_preview(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to preview", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
- break;
- }
- }
-
- if (smdk4x12_camera->preview_listener->width != smdk4x12_camera->preview_width || smdk4x12_camera->preview_listener->height != smdk4x12_camera->preview_height || smdk4x12_camera->preview_listener->format != smdk4x12_camera->preview_format) {
- if (smdk4x12_camera->preview_output_enabled)
- smdk4x12_camera_preview_output_stop(smdk4x12_camera);
-
- smdk4x12_camera_capture_listener_unregister(smdk4x12_camera, smdk4x12_camera->preview_listener);
-
- smdk4x12_camera->preview_listener = NULL;
-
- listener = smdk4x12_camera_capture_listener_register(smdk4x12_camera, smdk4x12_camera->preview_width, smdk4x12_camera->preview_height, smdk4x12_camera->preview_format, smdk4x12_camera_preview_callback);
- if (listener == NULL) {
- ALOGE("%s: Unable to register preview capture listener", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
- break;
- }
-
- smdk4x12_camera->preview_listener = listener;
-
- gralloc_format = smdk4x12_gralloc_format(smdk4x12_camera->preview_format);
-
- rc = smdk4x12_camera->preview_window->set_buffers_geometry(smdk4x12_camera->preview_window, smdk4x12_camera->preview_width, smdk4x12_camera->preview_height, gralloc_format);
- if (rc) {
- ALOGE("%s: Unable to set buffers geometry", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
- break;
- }
- }
-
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
- }
-
- smdk4x12_camera->preview_thread_running = 0;
- ALOGE("%s: Exiting thread", __func__);
-
- return NULL;
-}
-
-int smdk4x12_camera_preview_thread_start(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_camera_capture_listener *listener;
- pthread_attr_t thread_attr;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->preview_thread_enabled) {
- ALOGE("Preview thread was already started!");
- return -1;
- }
-
- pthread_mutex_init(&smdk4x12_camera->preview_mutex, NULL);
- pthread_mutex_init(&smdk4x12_camera->preview_lock_mutex, NULL);
-
- // Initial lock
- pthread_mutex_lock(&smdk4x12_camera->preview_lock_mutex);
-
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
-
- smdk4x12_camera->preview_thread_enabled = 1;
-
- rc = pthread_create(&smdk4x12_camera->preview_thread, &thread_attr, smdk4x12_camera_preview_thread, (void *) smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to create thread", __func__);
- goto error;
- }
-
- listener = smdk4x12_camera_capture_listener_register(smdk4x12_camera, smdk4x12_camera->preview_width, smdk4x12_camera->preview_height, smdk4x12_camera->preview_format, smdk4x12_camera_preview_callback);
- if (listener == NULL) {
- ALOGE("%s: Unable to register preview capture listener", __func__);
- goto error;
- }
-
- smdk4x12_camera->preview_listener = listener;
-
- rc = 0;
- goto complete;
-
-error:
- pthread_mutex_destroy(&smdk4x12_camera->preview_mutex);
- pthread_mutex_destroy(&smdk4x12_camera->preview_lock_mutex);
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_preview_thread_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- int i;
-
- if (smdk4x12_camera == NULL)
- return;
-
- ALOGD("%s()", __func__);
-
- if (!smdk4x12_camera->preview_thread_enabled) {
- ALOGE("Preview thread was already stopped!");
- return;
- }
-
- if (smdk4x12_camera->preview_listener != NULL) {
- smdk4x12_camera_capture_listener_unregister(smdk4x12_camera, smdk4x12_camera->preview_listener);
- smdk4x12_camera->preview_listener = NULL;
- }
-
- smdk4x12_camera->preview_thread_enabled = 0;
-
- pthread_mutex_unlock(&smdk4x12_camera->preview_lock_mutex);
-
- // Wait for the thread to end
- i = 0;
- while (smdk4x12_camera->preview_thread_running) {
- if (i++ > 10000) {
- ALOGE("Preview thread is taking too long to end, something is going wrong");
- break;
- }
- usleep(100);
- }
-
- if (smdk4x12_camera->preview_output_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->preview_mutex);
- smdk4x12_camera_preview_output_stop(smdk4x12_camera);
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
- }
-
- pthread_mutex_destroy(&smdk4x12_camera->preview_mutex);
- pthread_mutex_destroy(&smdk4x12_camera->preview_lock_mutex);
-
- // Invalidate the preview window
- smdk4x12_camera->preview_window = NULL;
-}
-
-// Picture
-
-int smdk4x12_camera_picture_callback(struct smdk4x12_camera *smdk4x12_camera,
- struct smdk4x12_camera_buffer *buffers, int buffers_count)
-{
- struct smdk4x12_camera_buffer *jpeg_buffer = NULL;
- struct smdk4x12_camera_buffer *jpeg_thumbnail_buffer = NULL;
- struct smdk4x12_camera_buffer *yuv_buffer = NULL;
- struct smdk4x12_camera_buffer *yuv_thumbnail_buffer = NULL;
- int width, height;
- int thumbnail_width, thumbnail_height;
- time_t timestamp;
- int rc;
- int i;
-
- if (smdk4x12_camera == NULL || buffers == NULL || buffers_count <= 0)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- width = smdk4x12_camera->picture_width;
- height = smdk4x12_camera->picture_height;
- thumbnail_width = smdk4x12_camera->jpeg_thumbnail_width;
- thumbnail_height = smdk4x12_camera->jpeg_thumbnail_height;
-
- if (smdk4x12_camera->picture_completed)
- return -1;
-
- if (smdk4x12_camera->picture_listener == NULL)
- return -1;
-
- if (smdk4x12_camera->picture_listener->busy) {
- ALOGE("%s: Dropping buffer", __func__);
- return 0;
- }
-
- ALOGE("%s: locking picture_mutex", __func__);
- pthread_mutex_lock(&smdk4x12_camera->picture_mutex);
- ALOGE("%s: locked picture_mutex", __func__);
-
- if (!smdk4x12_camera->picture_enabled && !smdk4x12_camera->camera_fimc_is) {
- if (smdk4x12_camera->camera_capture_format == V4L2_PIX_FMT_INTERLEAVED && smdk4x12_camera->zoom == 0 && smdk4x12_camera->focus_mode == FOCUS_MODE_CONTINOUS_PICTURE) {
- if (smdk4x12_camera->auto_focus_result == CAMERA_AF_STATUS_FAIL) {
- // We don't want to take a picture out of focus, so wait a bit
- timestamp = time(NULL);
-
- if (smdk4x12_camera->picture_focus_timestamp > 0) {
- if ((timestamp - smdk4x12_camera->picture_focus_timestamp) > 2) {
- ALOGE("%s: Picture will be taken out of focus", __func__);
- } else {
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- return 0;
- }
- } else {
- smdk4x12_camera->picture_focus_timestamp = timestamp;
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- return 0;
- }
- } else if (smdk4x12_camera->auto_focus_result == CAMERA_AF_STATUS_IN_PROGRESS) {
- ALOGD("%s: Not asking for picture until auto focus is done", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- return 0;
- }
- }
-
- smdk4x12_camera->picture_focus_timestamp = 0;
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_CAPTURE, 0);
- if (rc < 0) {
- ALOGE("%s: Unable to set capture", __func__);
- goto error;
- }
-
- if (smdk4x12_camera->camera_capture_format == V4L2_PIX_FMT_INTERLEAVED && !smdk4x12_camera->capture_hybrid) {
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_HYBRID_CAPTURE, 1);
- if (rc < 0) {
- ALOGE("%s: Unable to set hybrid capture", __func__);
- goto error;
- }
-
- smdk4x12_camera->capture_hybrid = 1;
- }
-
- smdk4x12_camera->picture_enabled = 1;
-
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- return 0;
- }
-
- ALOGE("%s: unlocking picture_mutex", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- ALOGE("%s: unlocked picture_mutex", __func__);
-
- smdk4x12_camera->picture_listener->busy = 1;
-
- // Let's assume the picture format is JPEG
-
- for (i = 0; i < buffers_count; i++) {
- if (buffers->format == V4L2_PIX_FMT_JPEG) {
- if (buffers->width == width && buffers->height == height)
- jpeg_buffer = buffers;
- else if (buffers->width == thumbnail_width && buffers->height == thumbnail_height)
- jpeg_thumbnail_buffer = buffers;
- } else {
- if (buffers->width >= width && buffers->height >= height)
- yuv_buffer = buffers;
- if (buffers->width >= thumbnail_width && buffers->height >= thumbnail_height)
- yuv_thumbnail_buffer = buffers;
- }
-
-buffers_continue:
- buffers = (struct smdk4x12_camera_buffer *) ((unsigned char *) buffers + sizeof(struct smdk4x12_camera_buffer));
- }
-
- if (jpeg_buffer == NULL && yuv_buffer == NULL) {
- ALOGE("%s: Unable to find an appropriate buffer for picture", __func__);
- smdk4x12_camera->picture_listener->busy = 0;
- return 0;
- }
-
- // Interleaved must not use a preview frame as picture
- if (smdk4x12_camera->camera_capture_format == V4L2_PIX_FMT_INTERLEAVED && jpeg_buffer == NULL) {
- smdk4x12_camera->picture_listener->busy = 0;
- return 0;
- }
-
- pthread_mutex_lock(&smdk4x12_camera->picture_mutex);
-
- if (jpeg_buffer == NULL)
- memset(&smdk4x12_camera->picture_jpeg_buffer, 0, sizeof(smdk4x12_camera->picture_jpeg_buffer));
- else
- memcpy(&smdk4x12_camera->picture_jpeg_buffer, jpeg_buffer, sizeof(struct smdk4x12_camera_buffer));
-
- if (jpeg_thumbnail_buffer == NULL)
- memset(&smdk4x12_camera->picture_jpeg_thumbnail_buffer, 0, sizeof(smdk4x12_camera->picture_jpeg_thumbnail_buffer));
- else
- memcpy(&smdk4x12_camera->picture_jpeg_thumbnail_buffer, jpeg_thumbnail_buffer, sizeof(struct smdk4x12_camera_buffer));
-
- if (yuv_buffer == NULL)
- memset(&smdk4x12_camera->picture_yuv_buffer, 0, sizeof(smdk4x12_camera->picture_yuv_buffer));
- else
- memcpy(&smdk4x12_camera->picture_yuv_buffer, yuv_buffer, sizeof(struct smdk4x12_camera_buffer));
-
- if (yuv_thumbnail_buffer == NULL)
- memset(&smdk4x12_camera->picture_yuv_thumbnail_buffer, 0, sizeof(smdk4x12_camera->picture_yuv_thumbnail_buffer));
- else
- memcpy(&smdk4x12_camera->picture_yuv_thumbnail_buffer, yuv_thumbnail_buffer, sizeof(struct smdk4x12_camera_buffer));
-
- pthread_mutex_unlock(&smdk4x12_camera->picture_lock_mutex);
-
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
-
- rc = 0;
- goto complete;
-
-error:
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
-
- smdk4x12_camera->picture_listener->busy = 0;
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-int smdk4x12_camera_picture(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_camera_buffer *jpeg_buffer;
- struct smdk4x12_camera_buffer *jpeg_thumbnail_buffer;
- struct smdk4x12_camera_buffer *yuv_buffer;
- struct smdk4x12_camera_buffer *yuv_thumbnail_buffer;
- struct smdk4x12_v4l2_output output;
- struct smdk4x12_jpeg jpeg;
- struct smdk4x12_exif exif;
- int output_enabled = 0;
- int width, height, format;
- int buffer_width, buffer_height, buffer_format, buffer_address;
- camera_memory_t *memory = NULL;
- int memory_size;
- unsigned char *p;
- camera_memory_t *jpeg_memory = NULL;
- void *jpeg_data = NULL;
- int jpeg_size = 0;
- camera_memory_t *jpeg_thumbnail_memory = NULL;
- void *jpeg_thumbnail_data = NULL;
- int jpeg_thumbnail_size = 0;
- void *yuv_data = NULL;
- int yuv_address;
- int yuv_size = 0;
- void *yuv_thumbnail_data = NULL;
- int yuv_thumbnail_address;
- int yuv_thumbnail_size = 0;
- int rc;
-
- if (smdk4x12_camera == NULL)
- goto error;
-
-// ALOGD("%s()", __func__);
-
- jpeg_buffer = &smdk4x12_camera->picture_jpeg_buffer;
- jpeg_thumbnail_buffer = &smdk4x12_camera->picture_jpeg_thumbnail_buffer;
- yuv_buffer = &smdk4x12_camera->picture_yuv_buffer;
- yuv_thumbnail_buffer = &smdk4x12_camera->picture_yuv_thumbnail_buffer;
-
- if (jpeg_buffer->pointer != NULL && jpeg_buffer->length > 0) {
- jpeg_data = jpeg_buffer->pointer;
- jpeg_size = jpeg_buffer->length;
- }
-
- if (jpeg_thumbnail_buffer->pointer != NULL && jpeg_thumbnail_buffer->length > 0) {
- jpeg_thumbnail_data = jpeg_thumbnail_buffer->pointer;
- jpeg_thumbnail_size = jpeg_thumbnail_buffer->length;
- }
-
- if (yuv_buffer->pointer != NULL && yuv_buffer->length > 0) {
- yuv_data = yuv_buffer->pointer;
- yuv_address = yuv_buffer->address;
- yuv_size = yuv_buffer->length;
- }
-
- if (yuv_thumbnail_buffer->pointer != NULL && yuv_thumbnail_buffer->length > 0) {
- yuv_thumbnail_data = yuv_thumbnail_buffer->pointer;
- yuv_thumbnail_address = yuv_thumbnail_buffer->address;
- yuv_thumbnail_size = yuv_thumbnail_buffer->length;
- }
-
- // JPEG
-
- if (jpeg_data == NULL) {
- if (yuv_data == NULL || yuv_size <= 0) {
- ALOGE("%s: Unable to create jpeg without an YUV buffer", __func__);
- goto error;
- }
-
- width = smdk4x12_camera->picture_width;
- height = smdk4x12_camera->picture_height;
- format = yuv_buffer->format;
-
- buffer_width = yuv_buffer->width;
- buffer_height = yuv_buffer->height;
- buffer_format = yuv_buffer->format;
- buffer_address = yuv_buffer->address;
-
- if (width != buffer_width && height != buffer_height) {
- format = SMDK4x12_CAMERA_PICTURE_OUTPUT_FORMAT;
-
- memset(&output, 0, sizeof(output));
- output.v4l2_id = 2;
- output.width = width;
- output.height = height;
- output.format = format;
- output.buffer_width = buffer_width;
- output.buffer_height = buffer_height;
- output.buffer_format = buffer_format;
- output.buffers_count = 1;
-
- rc = smdk4x12_v4l2_output_start(smdk4x12_camera, &output);
- if (rc < 0) {
- ALOGE("%s: Unable to start picture output", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_output(smdk4x12_camera, &output, buffer_address);
- if (rc < 0) {
- ALOGE("%s: Unable to output picture", __func__);
- goto error;
- }
-
- output_enabled = 1;
-
- yuv_data = output.memory->data;
- yuv_address = output.memory_address;
- yuv_size = output.buffer_length;
- }
-
- memset(&jpeg, 0, sizeof(jpeg));
- jpeg.width = width;
- jpeg.height = height;
- jpeg.format = format;
- jpeg.quality = smdk4x12_camera->jpeg_quality;
-
- rc = smdk4x12_jpeg_start(smdk4x12_camera, &jpeg);
- if (rc < 0) {
- ALOGE("%s: Unable to start jpeg", __func__);
- goto error;
- }
-
- if (jpeg.memory_in_pointer == NULL) {
- ALOGE("%s: Invalid memory input pointer", __func__);
- goto error;
- }
-
- memcpy(jpeg.memory_in_pointer, yuv_data, yuv_size);
-
- rc = smdk4x12_jpeg(smdk4x12_camera, &jpeg);
- if (rc < 0) {
- ALOGE("%s: Unable to jpeg", __func__);
- goto error;
- }
-
- jpeg_size = jpeg.memory_out_size;
- if (jpeg_size <= 0) {
- ALOGE("%s: Invalid jpeg size", __func__);
- goto error;
- }
-
- if (SMDK4x12_CAMERA_CALLBACK_DEFINED(request_memory)) {
- jpeg_memory = smdk4x12_camera->callbacks.request_memory(-1, jpeg_size, 1, smdk4x12_camera->callbacks.user);
- if (jpeg_memory == NULL || jpeg_memory->data == NULL || jpeg_memory->data == MAP_FAILED) {
- ALOGE("%s: Unable to request memory", __func__);
- goto error;
- }
- } else {
- ALOGE("%s: No memory request function!", __func__);
- goto error;
- }
-
- jpeg_data = jpeg_memory->data;
-
- memcpy(jpeg_data, jpeg.memory_out_pointer, jpeg_size);
-
- smdk4x12_jpeg_stop(smdk4x12_camera, &jpeg);
-
- if (output_enabled) {
- smdk4x12_v4l2_output_stop(smdk4x12_camera, &output);
- output_enabled = 0;
- }
- }
-
- ALOGE("%s: finished jpeg", __func__);
-
- // Thumbnail
-
- if (jpeg_thumbnail_data == NULL) {
- if (yuv_thumbnail_data == NULL || yuv_thumbnail_size <= 0) {
- ALOGE("%s: Unable to create jpeg thumbnail without an YUV buffer", __func__);
- goto error;
- }
-
- width = smdk4x12_camera->jpeg_thumbnail_width;
- height = smdk4x12_camera->jpeg_thumbnail_height;
- format = yuv_thumbnail_buffer->format;
-
- buffer_width = yuv_thumbnail_buffer->width;
- buffer_height = yuv_thumbnail_buffer->height;
- buffer_format = yuv_thumbnail_buffer->format;
- buffer_address = yuv_thumbnail_buffer->address;
-
- if (width != buffer_width && height != buffer_height) {
- format = SMDK4x12_CAMERA_PICTURE_OUTPUT_FORMAT;
-
- memset(&output, 0, sizeof(output));
- output.v4l2_id = 2;
- output.width = width;
- output.height = height;
- output.format = format;
- output.buffer_width = buffer_width;
- output.buffer_height = buffer_height;
- output.buffer_format = buffer_format;
- output.buffers_count = 1;
-
- rc = smdk4x12_v4l2_output_start(smdk4x12_camera, &output);
- if (rc < 0) {
- ALOGE("%s: Unable to start thumbnail picture output", __func__);
- goto error;
- }
-
- output_enabled = 1;
-
- rc = smdk4x12_v4l2_output(smdk4x12_camera, &output, buffer_address);
- if (rc < 0) {
- ALOGE("%s: Unable to output thumbnail picture", __func__);
- goto error;
- }
-
- yuv_thumbnail_data = output.memory->data;
- yuv_thumbnail_address = output.memory_address;
- yuv_thumbnail_size = output.buffer_length;
- }
-
- memset(&jpeg, 0, sizeof(jpeg));
- jpeg.width = width;
- jpeg.height = height;
- jpeg.format = format;
- jpeg.quality = smdk4x12_camera->jpeg_thumbnail_quality;
-
- rc = smdk4x12_jpeg_start(smdk4x12_camera, &jpeg);
- if (rc < 0) {
- ALOGE("%s: Unable to start jpeg", __func__);
- goto error;
- }
-
- if (jpeg.memory_in_pointer == NULL) {
- ALOGE("%s: Invalid memory input pointer", __func__);
- goto error;
- }
-
- memcpy(jpeg.memory_in_pointer, yuv_thumbnail_data, yuv_thumbnail_size);
-
- rc = smdk4x12_jpeg(smdk4x12_camera, &jpeg);
- if (rc < 0) {
- ALOGE("%s: Unable to jpeg", __func__);
- goto error;
- }
-
- jpeg_thumbnail_size = jpeg.memory_out_size;
- if (jpeg_thumbnail_size <= 0) {
- ALOGE("%s: Invalid jpeg size", __func__);
- goto error;
- }
-
- if (SMDK4x12_CAMERA_CALLBACK_DEFINED(request_memory)) {
- jpeg_thumbnail_memory = smdk4x12_camera->callbacks.request_memory(-1, jpeg_thumbnail_size, 1, smdk4x12_camera->callbacks.user);
- if (jpeg_thumbnail_memory == NULL || jpeg_thumbnail_memory->data == NULL || jpeg_thumbnail_memory->data == MAP_FAILED) {
- ALOGE("%s: Unable to request memory", __func__);
- goto error;
- }
- } else {
- ALOGE("%s: No memory request function!", __func__);
- goto error;
- }
-
- jpeg_thumbnail_data = jpeg_thumbnail_memory->data;
-
- memcpy(jpeg_thumbnail_data, jpeg.memory_out_pointer, jpeg_thumbnail_size);
-
- smdk4x12_jpeg_stop(smdk4x12_camera, &jpeg);
-
- if (output_enabled) {
- smdk4x12_v4l2_output_stop(smdk4x12_camera, &output);
- output_enabled = 0;
- }
- }
-
- ALOGE("%s: Thumbnail finished", __func__);
-
- // EXIF
-
- memset(&exif, 0, sizeof(exif));
- exif.jpeg_thumbnail_data = jpeg_thumbnail_data;
- exif.jpeg_thumbnail_size = jpeg_thumbnail_size;
-
- rc = smdk4x12_exif_start(smdk4x12_camera, &exif);
- if (rc < 0) {
- ALOGE("%s: Unable to start exif", __func__);
- goto error;
- }
-
- rc = smdk4x12_exif(smdk4x12_camera, &exif);
- if (rc < 0) {
- ALOGE("%s: Unable to exif", __func__);
- goto error;
- }
-
- memory_size = exif.memory_size + jpeg_size;
-
- if (SMDK4x12_CAMERA_CALLBACK_DEFINED(request_memory)) {
- memory = smdk4x12_camera->callbacks.request_memory(-1, memory_size, 1, smdk4x12_camera->callbacks.user);
- if (memory == NULL || memory->data == NULL || memory->data == MAP_FAILED) {
- ALOGE("%s: Unable to request memory", __func__);
- goto error;
- }
- } else {
- ALOGE("%s: No memory request function!", __func__);
- goto error;
- }
-
- ALOGE("%s: exif finished", __func__);
-
- p = (unsigned char *) memory->data;
-
- // Copy the first two bytes of the JPEG picture
- memcpy(p, jpeg_data, 2);
- p += 2;
-
- // Copy the EXIF data
- memcpy(p, exif.memory->data, exif.memory_size);
- p += exif.memory_size;
-
- // Copy the JPEG picture
- memcpy(p, (void *) ((unsigned char *) jpeg_data + 2), jpeg_size - 2);
-
- smdk4x12_exif_stop(smdk4x12_camera, &exif);
-
- smdk4x12_camera->picture_memory = memory;
-
- rc = 0;
- goto complete;
-
-error:
- if (output_enabled)
- smdk4x12_v4l2_output_stop(smdk4x12_camera, &output);
-
- if (memory != NULL && memory->release != NULL) {
- memory->release(memory);
- smdk4x12_camera->picture_memory = NULL;
- }
-
- if (SMDK4x12_CAMERA_MSG_ENABLED(CAMERA_MSG_ERROR) && SMDK4x12_CAMERA_CALLBACK_DEFINED(notify) && !smdk4x12_camera->callback_lock)
- smdk4x12_camera->callbacks.notify(CAMERA_MSG_ERROR, -1, 0, smdk4x12_camera->callbacks.user);
-
- rc = -1;
-
-complete:
- if (jpeg_memory != NULL && jpeg_memory->release != NULL)
- jpeg_memory->release(jpeg_memory);
-
- if (jpeg_thumbnail_memory != NULL && jpeg_thumbnail_memory->release != NULL)
- jpeg_thumbnail_memory->release(jpeg_thumbnail_memory);
-
- smdk4x12_camera->picture_completed = 1;
- smdk4x12_camera->picture_listener->busy = 0;
-
- return rc;
-}
-
-void *smdk4x12_camera_picture_thread(void *data)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int rc;
-
- if (data == NULL)
- return NULL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) data;
-
- ALOGE("%s: Starting thread", __func__);
- smdk4x12_camera->picture_thread_running = 1;
-
- while (smdk4x12_camera->picture_thread_enabled) {
- ALOGE("%s: in while loop", __func__);
- pthread_mutex_lock(&smdk4x12_camera->picture_lock_mutex);
- ALOGE("%s: lock_mutex locked", __func__);
- pthread_mutex_lock(&smdk4x12_camera->picture_mutex);
- ALOGE("%s: picture_mutex locked", __func__);
-
- if (smdk4x12_camera->picture_listener == NULL) {
- ALOGE("%s: no listener", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- break;
- }
-
- if (smdk4x12_camera->picture_listener->busy) {
- ALOGE("%s: listener busy", __func__);
- rc = smdk4x12_camera_picture(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to take picture", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- break;
- }
- }
-
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- ALOGE("%s: picture_mutex unlocked", __func__);
-
- if (smdk4x12_camera->picture_completed) {
- ALOGE("%s: picture completed", __func__);
- smdk4x12_camera->picture_thread_running = 0;
- smdk4x12_camera_picture_thread_stop(smdk4x12_camera);
- break;
- }
- ALOGE("%s: still while loop", __func__);
- }
-
- smdk4x12_camera->picture_thread_running = 0;
- ALOGE("%s: Exiting thread", __func__);
-
- return NULL;
-}
-
-int smdk4x12_camera_picture_thread_start(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_camera_capture_listener *listener;
- pthread_attr_t thread_attr;
- int format;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->picture_thread_enabled) {
- ALOGE("Picture thread was already started!");
- return -1;
- }
-
- if (smdk4x12_camera->camera_picture_format)
- format = smdk4x12_camera->camera_picture_format;
- else
- format = smdk4x12_camera->picture_format;
-
- pthread_mutex_init(&smdk4x12_camera->picture_mutex, NULL);
- pthread_mutex_init(&smdk4x12_camera->picture_lock_mutex, NULL);
-
- // Initial lock
- pthread_mutex_lock(&smdk4x12_camera->picture_lock_mutex);
-
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
-
- smdk4x12_camera->picture_thread_enabled = 1;
-
- rc = pthread_create(&smdk4x12_camera->picture_thread, &thread_attr, smdk4x12_camera_picture_thread, (void *) smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to create thread", __func__);
- goto error;
- }
-
- smdk4x12_camera->picture_completed = 0;
-
- listener = smdk4x12_camera_capture_listener_register(smdk4x12_camera, smdk4x12_camera->picture_width, smdk4x12_camera->picture_height, format, smdk4x12_camera_picture_callback);
- if (listener == NULL) {
- ALOGE("%s: Unable to register picture capture listener", __func__);
- goto error;
- }
-
- smdk4x12_camera->picture_listener = listener;
-
- rc = 0;
- goto complete;
-
-error:
- pthread_mutex_destroy(&smdk4x12_camera->picture_mutex);
- pthread_mutex_destroy(&smdk4x12_camera->picture_lock_mutex);
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_picture_thread_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- camera_memory_t *memory;
- int i;
-
- if (smdk4x12_camera == NULL)
- return;
-
- ALOGD("%s()", __func__);
-
- if (!smdk4x12_camera->picture_thread_enabled) {
- ALOGE("Picture thread was already stopped!");
- return;
- }
-
- memory = smdk4x12_camera->picture_memory;
-
- if (smdk4x12_camera->picture_listener != NULL) {
- smdk4x12_camera_capture_listener_unregister(smdk4x12_camera, smdk4x12_camera->picture_listener);
- smdk4x12_camera->picture_listener = NULL;
- }
-
- smdk4x12_camera->picture_thread_enabled = 0;
-
- pthread_mutex_unlock(&smdk4x12_camera->picture_lock_mutex);
-
- // Wait for the thread to end
- i = 0;
- while (smdk4x12_camera->picture_thread_running) {
- if (i++ > 10000) {
- ALOGE("Picture thread is taking too long to end, something is going wrong");
- break;
- }
- usleep(100);
- }
-
- if (smdk4x12_camera->picture_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->picture_mutex);
- smdk4x12_camera->picture_enabled = 0;
- pthread_mutex_unlock(&smdk4x12_camera->picture_mutex);
- }
-
- pthread_mutex_destroy(&smdk4x12_camera->picture_mutex);
- pthread_mutex_destroy(&smdk4x12_camera->picture_lock_mutex);
-
- if (smdk4x12_camera->picture_completed && memory != NULL) {
- // It is important to return at this point (and not before) for burst
-
- if (SMDK4x12_CAMERA_MSG_ENABLED(CAMERA_MSG_SHUTTER) && SMDK4x12_CAMERA_CALLBACK_DEFINED(notify) && !smdk4x12_camera->callback_lock)
- smdk4x12_camera->callbacks.notify(CAMERA_MSG_SHUTTER, 0, 0, smdk4x12_camera->callbacks.user);
-
- if (SMDK4x12_CAMERA_MSG_ENABLED(CAMERA_MSG_COMPRESSED_IMAGE) && SMDK4x12_CAMERA_CALLBACK_DEFINED(data) && !smdk4x12_camera->callback_lock)
- smdk4x12_camera->callbacks.data(CAMERA_MSG_COMPRESSED_IMAGE, memory, 0, NULL, smdk4x12_camera->callbacks.user);
-
- if (memory->release != NULL) {
- memory->release(memory);
- smdk4x12_camera->picture_memory = NULL;
- }
- }
-}
-
-// Recording
-
-int smdk4x12_camera_recording_output_start(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_v4l2_output *output;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->recording_output_enabled) {
- ALOGE("Recording was already started!");
- return -1;
- }
-
- output = &smdk4x12_camera->recording_output;
-
- memset(output, 0, sizeof(struct smdk4x12_v4l2_output));
- output->v4l2_id = 3;
- output->width = smdk4x12_camera->recording_width;
- output->height = smdk4x12_camera->recording_height;
- output->format = smdk4x12_camera->recording_format;
- output->buffer_width = smdk4x12_camera->recording_buffer.width;
- output->buffer_height = smdk4x12_camera->recording_buffer.height;
- output->buffer_format = smdk4x12_camera->recording_buffer.format;
- output->buffers_count = SMDK4x12_CAMERA_RECORDING_BUFFERS_COUNT;
-
- rc = smdk4x12_v4l2_output_start(smdk4x12_camera, output);
- if (rc < 0) {
- ALOGE("%s: Unable to start recording output", __func__);
- goto error;
- }
-
- smdk4x12_camera->recording_output_enabled = 1;
-
- rc = 0;
- goto complete;
-
-error:
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_recording_output_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_v4l2_output *output;
-
- if (smdk4x12_camera == NULL)
- return;
-
- ALOGD("%s()", __func__);
-
- if (!smdk4x12_camera->recording_output_enabled) {
- ALOGE("Recording was already stopped!");
- return;
- }
-
- output = &smdk4x12_camera->recording_output;
-
- smdk4x12_v4l2_output_stop(smdk4x12_camera, output);
-
- smdk4x12_camera->recording_output_enabled = 0;
-}
-
-int smdk4x12_camera_recording_callback(struct smdk4x12_camera *smdk4x12_camera,
- struct smdk4x12_camera_buffer *buffers, int buffers_count)
-{
- struct smdk4x12_camera_buffer *buffer = NULL;
- int width, height, format;
- int buffer_width, buffer_height, buffer_format;
- int rc;
- int i;
-
- if (smdk4x12_camera == NULL || buffers == NULL || buffers_count <= 0)
- return -EINVAL;
-
-// ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->recording_listener == NULL)
- return -1;
-
- if (smdk4x12_camera->recording_listener->busy) {
- ALOGE("%s: Dropping buffer", __func__);
- return 0;
- }
-
- smdk4x12_camera->recording_listener->busy = 1;
-
- width = smdk4x12_camera->recording_width;
- height = smdk4x12_camera->recording_height;
- format = smdk4x12_camera->recording_format;
-
- for (i = 0; i < buffers_count; i++) {
- if (buffers->format == V4L2_PIX_FMT_JPEG)
- goto buffers_continue;
-
- if (buffers->format == V4L2_PIX_FMT_INTERLEAVED)
- goto buffers_continue;
-
- // Optimal buffer
- if (buffers->width == width && buffers->height == height) {
- buffer = buffers;
- break;
- }
-
- // Might-work buffer, but not optimal
- buffer = buffers;
-
-buffers_continue:
- buffers = (struct smdk4x12_camera_buffer *) ((unsigned char *) buffers + sizeof(struct smdk4x12_camera_buffer));
- }
-
- if (buffer == NULL) {
- ALOGE("%s: Unable to find an appropriate buffer for recording", __func__);
- smdk4x12_camera->recording_listener->busy = 0;
- return 0;
- }
-
- buffer_width = buffer->width;
- buffer_height = buffer->height;
- buffer_format = buffer->format;
-
- pthread_mutex_lock(&smdk4x12_camera->recording_mutex);
-
- if (!smdk4x12_camera->recording_output_enabled) {
- memcpy(&smdk4x12_camera->recording_buffer, buffer, sizeof(struct smdk4x12_camera_buffer));
-
- rc = smdk4x12_camera_recording_output_start(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to start recording", __func__);
- goto error;
- }
- } else if (smdk4x12_camera->recording_buffer.width != buffer_width || smdk4x12_camera->recording_buffer.height != buffer_height || smdk4x12_camera->recording_buffer.format != buffer_format) {
- smdk4x12_camera_recording_output_stop(smdk4x12_camera);
-
- memcpy(&smdk4x12_camera->recording_buffer, buffer, sizeof(struct smdk4x12_camera_buffer));
-
- rc = smdk4x12_camera_recording_output_start(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to start recording", __func__);
- goto error;
- }
- } else {
- memcpy(&smdk4x12_camera->recording_buffer, buffer, sizeof(struct smdk4x12_camera_buffer));
- }
-
- pthread_mutex_unlock(&smdk4x12_camera->recording_lock_mutex);
-
- pthread_mutex_unlock(&smdk4x12_camera->recording_mutex);
-
- rc = 0;
- goto complete;
-
-error:
- pthread_mutex_unlock(&smdk4x12_camera->recording_mutex);
-
- smdk4x12_camera->recording_listener->busy = 0;
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_recording_frame_release(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_v4l2_output *output;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return;
-
-// ALOGD("%s()", __func__);
-
- output = &smdk4x12_camera->recording_output;
-
- if (!smdk4x12_camera->recording_output_enabled) {
- ALOGE("%s: Recording output should always be enabled", __func__);
- return;
- }
-
- rc = smdk4x12_v4l2_output_release(smdk4x12_camera, output);
- if (rc < 0) {
- ALOGE("%s: Unable to release recording output", __func__);
- return;
- }
-}
-
-int smdk4x12_camera_recording(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_v4l2_output *output;
- struct smdk4x12_camera_addrs *addrs;
- int width, height, format;
- camera_memory_t *memory;
- int memory_address;
- int memory_index;
- int buffer_length;
- int buffers_count;
- nsecs_t timestamp;
- int rc;
-
- if (smdk4x12_camera == NULL)
- goto error;
-
-// ALOGD("%s()", __func__);
-
- width = smdk4x12_camera->recording_width;
- height = smdk4x12_camera->recording_height;
- format = smdk4x12_camera->recording_format;
-
- output = &smdk4x12_camera->recording_output;
-
- buffer_length = smdk4x12_camera->recording_buffer_length;
- buffers_count = smdk4x12_camera->recording_buffers_count;
-
- timestamp = systemTime(1);
-
- if (!smdk4x12_camera->recording_output_enabled) {
- ALOGE("%s: Recording output should always be enabled", __func__);
- goto error;
- }
-
- rc = smdk4x12_v4l2_output(smdk4x12_camera, output, smdk4x12_camera->recording_buffer.address);
- if (rc < 0) {
- ALOGE("%s: Unable to output recording", __func__);
- goto error;
- }
-
- if (smdk4x12_camera->recording_metadata) {
- memory = smdk4x12_camera->recording_memory;
- memory_index = smdk4x12_camera->recording_memory_index;
- memory_address = output->memory_address + output->buffer_length * output->memory_index;
-
- addrs = (struct smdk4x12_camera_addrs *) ((unsigned char *) memory->data + buffer_length * memory_index);
- memset(addrs, 0, sizeof(struct smdk4x12_camera_addrs));
- addrs->type = 0; // kMetadataBufferTypeCameraSource
- addrs->index = memory_index;
-
- smdk4x12_camera_yuv_planes(width, height, format, memory_address, (int *) &addrs->y, (int *) &addrs->cbcr, NULL);
- } else {
- memory = output->memory;
- memory_index = output->memory_index;
- }
-
- if (SMDK4x12_CAMERA_MSG_ENABLED(CAMERA_MSG_VIDEO_FRAME) && SMDK4x12_CAMERA_CALLBACK_DEFINED(data_timestamp) && !smdk4x12_camera->callback_lock)
- smdk4x12_camera->callbacks.data_timestamp(timestamp, CAMERA_MSG_VIDEO_FRAME, memory, memory_index, smdk4x12_camera->callbacks.user);
- else
- smdk4x12_camera_recording_frame_release(smdk4x12_camera);
-
- if (smdk4x12_camera->recording_metadata) {
- memory_index++;
- smdk4x12_camera->recording_memory_index = memory_index % buffers_count;
- }
-
- rc = 0;
- goto complete;
-
-error:
- rc = -1;
-
-complete:
- smdk4x12_camera->recording_listener->busy = 0;
-
- return rc;
-}
-
-void *smdk4x12_camera_recording_thread(void *data)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int rc;
-
- if (data == NULL)
- return NULL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) data;
-
- ALOGE("%s: Starting thread", __func__);
- smdk4x12_camera->recording_thread_running = 1;
-
- while (smdk4x12_camera->recording_thread_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->recording_lock_mutex);
-
- pthread_mutex_lock(&smdk4x12_camera->recording_mutex);
-
- if (smdk4x12_camera->recording_listener == NULL) {
- pthread_mutex_unlock(&smdk4x12_camera->recording_mutex);
- break;
- }
-
- if (smdk4x12_camera->recording_listener->busy) {
- rc = smdk4x12_camera_recording(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to record", __func__);
- pthread_mutex_unlock(&smdk4x12_camera->recording_mutex);
- break;
- }
- }
-
- pthread_mutex_unlock(&smdk4x12_camera->recording_mutex);
- }
-
- smdk4x12_camera->recording_thread_running = 0;
- ALOGE("%s: Exiting thread", __func__);
-
- return NULL;
-}
-
-int smdk4x12_camera_recording_thread_start(struct smdk4x12_camera *smdk4x12_camera)
-{
- struct smdk4x12_camera_capture_listener *listener;
- pthread_attr_t thread_attr;
- camera_memory_t *memory = NULL;
- int buffer_length;
- int buffers_count;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->recording_thread_enabled) {
- ALOGE("Recording thread was already started!");
- return -1;
- }
-
- pthread_mutex_init(&smdk4x12_camera->recording_mutex, NULL);
- pthread_mutex_init(&smdk4x12_camera->recording_lock_mutex, NULL);
-
- // Initial lock
- pthread_mutex_lock(&smdk4x12_camera->recording_lock_mutex);
-
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
-
- smdk4x12_camera->recording_thread_enabled = 1;
-
- rc = pthread_create(&smdk4x12_camera->recording_thread, &thread_attr, smdk4x12_camera_recording_thread, (void *) smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to create thread", __func__);
- goto error;
- }
-
- if (smdk4x12_camera->recording_metadata) {
- buffer_length = sizeof(struct smdk4x12_camera_addrs);
- buffers_count = SMDK4x12_CAMERA_RECORDING_BUFFERS_COUNT;
-
- if (SMDK4x12_CAMERA_CALLBACK_DEFINED(request_memory)) {
- memory = smdk4x12_camera->callbacks.request_memory(-1, buffer_length, buffers_count, smdk4x12_camera->callbacks.user);
- if (memory == NULL || memory->data == NULL || memory->data == MAP_FAILED) {
- ALOGE("%s: Unable to request memory", __func__);
- goto error;
- }
- } else {
- ALOGE("%s: No memory request function!", __func__);
- goto error;
- }
-
- smdk4x12_camera->recording_memory = memory;
- smdk4x12_camera->recording_buffer_length = buffer_length;
- smdk4x12_camera->recording_buffers_count = buffers_count;
- }
-
- listener = smdk4x12_camera_capture_listener_register(smdk4x12_camera, smdk4x12_camera->recording_width, smdk4x12_camera->recording_height, smdk4x12_camera->recording_format, smdk4x12_camera_recording_callback);
- if (listener == NULL) {
- ALOGE("%s: Unable to register recording capture listener", __func__);
- goto error;
- }
-
- smdk4x12_camera->recording_listener = listener;
-
- rc = 0;
- goto complete;
-
-error:
- if (memory != NULL && memory->release != NULL) {
- memory->release(memory);
- smdk4x12_camera->recording_memory = NULL;
- }
-
- pthread_mutex_destroy(&smdk4x12_camera->recording_mutex);
- pthread_mutex_destroy(&smdk4x12_camera->recording_lock_mutex);
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_recording_thread_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- camera_memory_t *memory;
- int i;
-
- if (smdk4x12_camera == NULL)
- return;
-
- ALOGD("%s()", __func__);
-
- if (!smdk4x12_camera->recording_thread_enabled) {
- ALOGE("Recording thread was already stopped!");
- return;
- }
-
- memory = smdk4x12_camera->recording_memory;
-
- if (smdk4x12_camera->recording_listener != NULL) {
- smdk4x12_camera_capture_listener_unregister(smdk4x12_camera, smdk4x12_camera->recording_listener);
- smdk4x12_camera->recording_listener = NULL;
- }
-
- smdk4x12_camera->recording_thread_enabled = 0;
-
- pthread_mutex_unlock(&smdk4x12_camera->recording_lock_mutex);
-
- // Wait for the thread to end
- i = 0;
- while (smdk4x12_camera->recording_thread_running) {
- if (i++ > 10000) {
- ALOGE("Recording thread is taking too long to end, something is going wrong");
- break;
- }
- usleep(100);
- }
-
- if (smdk4x12_camera->recording_output_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->recording_mutex);
- smdk4x12_camera_recording_output_stop(smdk4x12_camera);
- pthread_mutex_unlock(&smdk4x12_camera->recording_mutex);
- }
-
- pthread_mutex_destroy(&smdk4x12_camera->recording_mutex);
- pthread_mutex_destroy(&smdk4x12_camera->recording_lock_mutex);
-
- if (memory != NULL && memory->release != NULL) {
- memory->release(memory);
- smdk4x12_camera->recording_memory = NULL;
- }
-}
-
-// Auto-focus
-
-int smdk4x12_camera_auto_focus(struct smdk4x12_camera *smdk4x12_camera, int auto_focus_status)
-{
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
-// ALOGD("%s()", __func__);
-
- switch (auto_focus_status) {
- case CAMERA_AF_STATUS_IN_PROGRESS:
- if (SMDK4x12_CAMERA_MSG_ENABLED(CAMERA_MSG_FOCUS_MOVE) && SMDK4x12_CAMERA_CALLBACK_DEFINED(notify) && !smdk4x12_camera->callback_lock)
- smdk4x12_camera->callbacks.notify(CAMERA_MSG_FOCUS_MOVE, 1, 0, smdk4x12_camera->callbacks.user);
- break;
- case CAMERA_AF_STATUS_SUCCESS:
- if (SMDK4x12_CAMERA_MSG_ENABLED(CAMERA_MSG_FOCUS) && SMDK4x12_CAMERA_CALLBACK_DEFINED(notify) && !smdk4x12_camera->callback_lock)
- smdk4x12_camera->callbacks.notify(CAMERA_MSG_FOCUS, 1, 0, smdk4x12_camera->callbacks.user);
- break;
- case CAMERA_AF_STATUS_FAIL:
- default:
- if (SMDK4x12_CAMERA_MSG_ENABLED(CAMERA_MSG_FOCUS) && SMDK4x12_CAMERA_CALLBACK_DEFINED(notify) && !smdk4x12_camera->callback_lock)
- smdk4x12_camera->callbacks.notify(CAMERA_MSG_FOCUS, 0, 0, smdk4x12_camera->callbacks.user);
- break;
- }
-
- return 0;
-}
-
-void *smdk4x12_camera_auto_focus_thread(void *data)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int auto_focus_result = CAMERA_AF_STATUS_FAIL;
- int auto_focus_completed = 0;
- int rc;
-
- if (data == NULL)
- return NULL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) data;
-
- ALOGE("%s: Starting thread", __func__);
- smdk4x12_camera->auto_focus_thread_running = 1;
-
- if (smdk4x12_camera->focus_mode == FOCUS_MODE_CONTINOUS_PICTURE) {
- rc = smdk4x12_camera_auto_focus(smdk4x12_camera, smdk4x12_camera->auto_focus_result);
- if (rc < 0)
- ALOGE("%s: Unable to auto-focus", __func__);
-
- smdk4x12_camera->auto_focus_thread_enabled = 0;
- }
-
- while (smdk4x12_camera->auto_focus_thread_enabled) {
- pthread_mutex_lock(&smdk4x12_camera->auto_focus_mutex);
-
- rc = smdk4x12_v4l2_g_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_AUTO_FOCUS_RESULT, &auto_focus_result);
- if (rc < 0) {
- ALOGE("%s: Unable to get auto-focus result", __func__);
- auto_focus_result = CAMERA_AF_STATUS_FAIL;
- }
-
- smdk4x12_camera->auto_focus_result = auto_focus_result;
-
- rc = smdk4x12_camera_auto_focus(smdk4x12_camera, auto_focus_result);
- if (rc < 0) {
- ALOGE("%s: Unable to auto-focus", __func__);
- auto_focus_result = CAMERA_AF_STATUS_FAIL;
- }
-
- if (auto_focus_result == CAMERA_AF_STATUS_IN_PROGRESS)
- usleep(10000);
- else
- auto_focus_completed = 1;
-
- pthread_mutex_unlock(&smdk4x12_camera->auto_focus_mutex);
-
- if (auto_focus_completed) {
- smdk4x12_camera->auto_focus_thread_running = 0;
- smdk4x12_camera_auto_focus_thread_stop(smdk4x12_camera);
- }
- }
-
- smdk4x12_camera->auto_focus_thread_running = 0;
- ALOGE("%s: Exiting thread", __func__);
-
- return NULL;
-}
-
-int smdk4x12_camera_auto_focus_thread_start(struct smdk4x12_camera *smdk4x12_camera)
-{
- pthread_attr_t thread_attr;
- int auto_focus;
- int rc;
-
- if (smdk4x12_camera == NULL)
- return -EINVAL;
-
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera->auto_focus_thread_enabled) {
- ALOGE("Auto-focus thread was already started!");
- return -1;
- }
-
- pthread_mutex_init(&smdk4x12_camera->auto_focus_mutex, NULL);
-
- if (smdk4x12_camera->focus_mode != FOCUS_MODE_CONTINOUS_PICTURE) {
- auto_focus = AUTO_FOCUS_ON | (smdk4x12_camera->preview_width & 0xfff) << 20 | (smdk4x12_camera->preview_height & 0xfff) << 8;
-
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_SET_AUTO_FOCUS, auto_focus);
- if (rc < 0) {
- ALOGE("%s: Unable to set auto-focus on", __func__);
- goto error;
- }
- }
-
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
-
- smdk4x12_camera->auto_focus_thread_enabled = 1;
-
- rc = pthread_create(&smdk4x12_camera->auto_focus_thread, &thread_attr, smdk4x12_camera_auto_focus_thread, (void *) smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to create thread", __func__);
- goto error;
- }
-
- rc = 0;
- goto complete;
-
-error:
- pthread_mutex_destroy(&smdk4x12_camera->auto_focus_mutex);
-
- rc = -1;
-
-complete:
- return rc;
-}
-
-void smdk4x12_camera_auto_focus_thread_stop(struct smdk4x12_camera *smdk4x12_camera)
-{
- int rc;
- int i;
-
- if (smdk4x12_camera == NULL)
- return;
-
- ALOGD("%s()", __func__);
-
- if (!smdk4x12_camera->auto_focus_thread_enabled) {
- ALOGE("Auto-focus thread was already stopped!");
- return;
- }
-
- smdk4x12_camera->auto_focus_thread_enabled = 0;
-
- // Wait for the thread to end
- i = 0;
- while (smdk4x12_camera->auto_focus_thread_running) {
- if (i++ > 10000) {
- ALOGE("Auto-focus thread is taking too long to end, something is going wrong");
- break;
- }
- usleep(100);
- }
- if (smdk4x12_camera->focus_mode != FOCUS_MODE_CONTINOUS_PICTURE) {
- rc = smdk4x12_v4l2_s_ctrl(smdk4x12_camera, 0, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_OFF);
- if (rc < 0)
- ALOGE("%s: Unable to set auto-focus off", __func__);
- }
-
- pthread_mutex_destroy(&smdk4x12_camera->auto_focus_mutex);
-}
-
-/*
- * SMDK4x12 Camera OPS
- */
-
-int smdk4x12_camera_set_preview_window(struct camera_device *device,
- struct preview_stream_ops *w)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- int width, height, format, gralloc_format;
-
- buffer_handle_t *buffer;
- int stride;
- void *addr = NULL;
-
- int rc;
-
- ALOGD("%s(%p, %p)", __func__, device, w);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- if (smdk4x12_camera->preview_thread_enabled)
- pthread_mutex_lock(&smdk4x12_camera->preview_mutex);
-
- if (w == NULL) {
- smdk4x12_camera->preview_window = NULL;
- return 0;
- }
-
- if (w->set_buffer_count == NULL || w->set_usage == NULL || w->set_buffers_geometry == NULL)
- goto error;
-
- rc = w->set_buffer_count(w, SMDK4x12_CAMERA_GRALLOC_BUFFERS_COUNT);
- if (rc) {
- ALOGE("%s: Unable to set buffer count: %d", __func__, SMDK4x12_CAMERA_GRALLOC_BUFFERS_COUNT);
- goto error;
- }
-
- rc = w->set_usage(w, GRALLOC_USAGE_SW_WRITE_OFTEN);
- if (rc) {
- ALOGE("%s: Unable to set usage", __func__);
- goto error;
- }
-
- width = smdk4x12_camera->preview_width;
- height = smdk4x12_camera->preview_height;
- format = smdk4x12_camera->preview_format;
-
- gralloc_format = smdk4x12_gralloc_format(format);
-
- rc = w->set_buffers_geometry(w, width, height, gralloc_format);
- if (rc) {
- ALOGE("%s: Unable to set buffers geometry", __func__);
- goto error;
- }
-
- smdk4x12_camera->preview_window = w;
-
- rc = 0;
- goto complete;
-
-error:
- smdk4x12_camera->preview_window = NULL;
- rc = -1;
-
-complete:
- if (smdk4x12_camera->preview_thread_enabled)
- pthread_mutex_unlock(&smdk4x12_camera->preview_mutex);
-
- return rc;
-}
-
-void smdk4x12_camera_set_callbacks(struct camera_device *device,
- camera_notify_callback notify_cb,
- camera_data_callback data_cb,
- camera_data_timestamp_callback data_cb_timestamp,
- camera_request_memory get_memory,
- void *user)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p, %p)", __func__, device, user);
-
- if (device == NULL || device->priv == NULL)
- return;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->callbacks.notify = notify_cb;
- smdk4x12_camera->callbacks.data = data_cb;
- smdk4x12_camera->callbacks.data_timestamp = data_cb_timestamp;
- smdk4x12_camera->callbacks.request_memory = get_memory;
- smdk4x12_camera->callbacks.user = user;
-}
-
-void smdk4x12_camera_enable_msg_type(struct camera_device *device,
- int32_t msg_type)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p, %d)", __func__, device, msg_type);
-
- if (device == NULL || device->priv == NULL)
- return;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->messages_enabled |= msg_type;
-}
-
-void smdk4x12_camera_disable_msg_type(struct camera_device *device,
- int32_t msg_type)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p, %d)", __func__, device, msg_type);
-
- if (device == NULL || device->priv == NULL)
- return;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->messages_enabled &= ~msg_type;
-}
-
-int smdk4x12_camera_msg_type_enabled(struct camera_device *device,
- int32_t msg_type)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p, %d)", __func__, device, msg_type);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- return smdk4x12_camera->messages_enabled & msg_type;
-}
-
-int smdk4x12_camera_start_preview(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int rc;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->callback_lock = 1;
- rc = smdk4x12_camera_preview_thread_start(smdk4x12_camera);
- smdk4x12_camera->callback_lock = 0;
-
- return rc;
-}
-
-void smdk4x12_camera_stop_preview(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->callback_lock = 1;
- smdk4x12_camera_preview_thread_stop(smdk4x12_camera);
- smdk4x12_camera->callback_lock = 0;
-}
-
-int smdk4x12_camera_preview_enabled(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- return smdk4x12_camera->preview_thread_enabled;
-}
-
-int smdk4x12_camera_store_meta_data_in_buffers(struct camera_device *device,
- int enable)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p, %d)", __func__, device, enable);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- if (!smdk4x12_camera->recording_thread_enabled)
- smdk4x12_camera->recording_metadata = enable;
- else
- ALOGE("%s: Recording is running!", __func__);
-
- return 0;
-}
-
-int smdk4x12_camera_start_recording(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int rc;
-
- ALOGD("%s(%p)", __func__, device);
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->callback_lock = 1;
- rc = smdk4x12_camera_recording_thread_start(smdk4x12_camera);
- smdk4x12_camera->callback_lock = 0;
-
- return rc;
-}
-
-void smdk4x12_camera_stop_recording(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p)", __func__, device);
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->callback_lock = 1;
- smdk4x12_camera_recording_thread_stop(smdk4x12_camera);
- smdk4x12_camera->callback_lock = 0;
-}
-
-int smdk4x12_camera_recording_enabled(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- return smdk4x12_camera->recording_thread_enabled;
-}
-
-void smdk4x12_camera_release_recording_frame(struct camera_device *device,
- const void *opaque)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
-// ALOGD("%s(%p, %p)", __func__, device, opaque);
-
- if (device == NULL || device->priv == NULL)
- return;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera_recording_frame_release(smdk4x12_camera);
-}
-
-int smdk4x12_camera_start_auto_focus(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- return smdk4x12_camera_auto_focus_thread_start(smdk4x12_camera);
-}
-
-int smdk4x12_camera_cancel_auto_focus(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera_auto_focus_thread_stop(smdk4x12_camera);
-
- return 0;
-}
-
-int smdk4x12_camera_take_picture(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int rc;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->callback_lock = 1;
- rc = smdk4x12_camera_picture_thread_start(smdk4x12_camera);
- smdk4x12_camera->callback_lock = 0;
-
- return rc;
-}
-
-int smdk4x12_camera_cancel_picture(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int rc;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera->callback_lock = 1;
- smdk4x12_camera_picture_thread_stop(smdk4x12_camera);
- smdk4x12_camera->callback_lock = 0;
-
- return 0;
-}
-
-int smdk4x12_camera_set_parameters(struct camera_device *device,
- const char *params)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- int rc;
-
- ALOGD("%s(%p, %s)", __func__, device, params);
-
- if (device == NULL || device->priv == NULL || params == NULL)
- return -EINVAL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- rc = smdk4x12_params_string_set(smdk4x12_camera, (char *) params);
- if (rc < 0) {
- ALOGE("%s: Unable to set params string", __func__);
- return -1;
- }
-
- rc = smdk4x12_camera_params_apply(smdk4x12_camera, 0);
- if (rc < 0) {
- ALOGE("%s: Unable to apply params", __func__);
- return -1;
- }
-
- return 0;
-}
-
-char *smdk4x12_camera_get_parameters(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
- char *params;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return NULL;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- params = smdk4x12_params_string_get(smdk4x12_camera);
- if (params == NULL) {
- ALOGE("%s: Couldn't find any param", __func__);
- return strdup("");
- }
-
- return params;
-}
-
-void smdk4x12_camera_put_parameters(struct camera_device *device, char *params)
-{
- ALOGD("%s(%p)", __func__, device);
-
- if (params != NULL)
- free(params);
-}
-
-int smdk4x12_camera_send_command(struct camera_device *device,
- int32_t cmd, int32_t arg1, int32_t arg2)
-{
- ALOGD("%s(%p, %d, %d, %d)", __func__, device, cmd, arg1, arg2);
-
- return 0;
-}
-
-void smdk4x12_camera_release(struct camera_device *device)
-{
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL || device->priv == NULL)
- return;
-
- smdk4x12_camera = (struct smdk4x12_camera *) device->priv;
-
- smdk4x12_camera_capture_thread_stop(smdk4x12_camera);
-
- smdk4x12_camera_stop(smdk4x12_camera);
-}
-
-int smdk4x12_camera_dump(struct camera_device *device, int fd)
-{
- ALOGD("%s(%p, %d)", __func__, device, fd);
-
- return 0;
-}
-
-/*
- * Interface
- */
-
-struct camera_device_ops smdk4x12_camera_ops = {
- .set_preview_window = smdk4x12_camera_set_preview_window,
- .set_callbacks = smdk4x12_camera_set_callbacks,
- .enable_msg_type = smdk4x12_camera_enable_msg_type,
- .disable_msg_type = smdk4x12_camera_disable_msg_type,
- .msg_type_enabled = smdk4x12_camera_msg_type_enabled,
- .start_preview = smdk4x12_camera_start_preview,
- .stop_preview = smdk4x12_camera_stop_preview,
- .preview_enabled = smdk4x12_camera_preview_enabled,
- .store_meta_data_in_buffers = smdk4x12_camera_store_meta_data_in_buffers,
- .start_recording = smdk4x12_camera_start_recording,
- .stop_recording = smdk4x12_camera_stop_recording,
- .recording_enabled = smdk4x12_camera_recording_enabled,
- .release_recording_frame = smdk4x12_camera_release_recording_frame,
- .auto_focus = smdk4x12_camera_start_auto_focus,
- .cancel_auto_focus = smdk4x12_camera_cancel_auto_focus,
- .take_picture = smdk4x12_camera_take_picture,
- .cancel_picture = smdk4x12_camera_cancel_picture,
- .set_parameters = smdk4x12_camera_set_parameters,
- .get_parameters = smdk4x12_camera_get_parameters,
- .put_parameters = smdk4x12_camera_put_parameters,
- .send_command = smdk4x12_camera_send_command,
- .release = smdk4x12_camera_release,
- .dump = smdk4x12_camera_dump,
-};
-
-int smdk4x12_camera_close(hw_device_t *device)
-{
- struct camera_device *camera_device;
- struct smdk4x12_camera *smdk4x12_camera;
-
- ALOGD("%s(%p)", __func__, device);
-
- if (device == NULL)
- return -EINVAL;
-
- camera_device = (struct camera_device *) device;
-
- if (camera_device->priv != NULL) {
- free(camera_device->priv);
- }
-
- free(camera_device);
-
- return 0;
-}
-
-int smdk4x12_camera_open(const struct hw_module_t* module, const char *camera_id,
- struct hw_device_t** device)
-{
- struct camera_device *camera_device = NULL;
- struct smdk4x12_camera *smdk4x12_camera = NULL;
- int id;
- int rc;
-
- ALOGD("%s(%p, %s, %p)", __func__, module, camera_id, device);
-
- if (module == NULL || camera_id == NULL || device == NULL)
- return -EINVAL;
-
- id = atoi(camera_id);
- if (id < 0)
- return -EINVAL;
-
- smdk4x12_camera = calloc(1, sizeof(struct smdk4x12_camera));
- smdk4x12_camera->config = smdk4x12_camera_config;
-
- if (smdk4x12_camera->config->v4l2_nodes_count > SMDK4x12_CAMERA_MAX_V4L2_NODES_COUNT)
- goto error_preset;
-
- if (id >= smdk4x12_camera->config->presets_count)
- goto error_preset;
-
- rc = smdk4x12_camera_start(smdk4x12_camera, id);
- if (rc < 0) {
- ALOGE("%s: Unable to start camera", __func__);
- goto error;
- }
-
- rc = smdk4x12_camera_capture_thread_start(smdk4x12_camera);
- if (rc < 0) {
- ALOGE("%s: Unable to start capture thread", __func__);
- goto error;
- }
-
- camera_device = calloc(1, sizeof(struct camera_device));
- camera_device->common.tag = HARDWARE_DEVICE_TAG;
- camera_device->common.version = 0;
- camera_device->common.module = (struct hw_module_t *) module;
- camera_device->common.close = smdk4x12_camera_close;
-
- camera_device->ops = &smdk4x12_camera_ops;
- camera_device->priv = smdk4x12_camera;
-
- *device = (struct hw_device_t *) &(camera_device->common);
-
- return 0;
-
-error:
- smdk4x12_camera_stop(smdk4x12_camera);
-
-error_device:
- if (camera_device != NULL)
- free(camera_device);
-
-error_preset:
- if (smdk4x12_camera != NULL)
- free(smdk4x12_camera);
-
- return -1;
-}
-
-int smdk4x12_camera_get_number_of_cameras(void)
-{
- ALOGD("%s()", __func__);
-
- if (smdk4x12_camera_config == NULL || smdk4x12_camera_config->presets == NULL) {
- ALOGE("%s: Unable to find proper camera config", __func__);
- return -1;
- }
-
- return smdk4x12_camera_config->presets_count;
-}
-
-int smdk4x12_camera_get_camera_info(int id, struct camera_info *info)
-{
- ALOGD("%s(%d, %p)", __func__, id, info);
-
- if (id < 0 || info == NULL)
- return -EINVAL;
-
- if (smdk4x12_camera_config == NULL || smdk4x12_camera_config->presets == NULL) {
- ALOGE("%s: Unable to find proper camera config", __func__);
- return -1;
- }
-
- if (id >= smdk4x12_camera_config->presets_count)
- return -EINVAL;
-
- ALOGD("Selected camera: %s", smdk4x12_camera_config->presets[id].name);
-
- info->facing = smdk4x12_camera_config->presets[id].facing;
- info->orientation = smdk4x12_camera_config->presets[id].orientation;
-
- return 0;
-}
-
-struct hw_module_methods_t smdk4x12_camera_module_methods = {
- .open = smdk4x12_camera_open,
-};
-
-struct camera_module HAL_MODULE_INFO_SYM = {
- .common = {
- .tag = HARDWARE_MODULE_TAG,
- .version_major = 1,
- .version_minor = 0,
- .id = CAMERA_HARDWARE_MODULE_ID,
- .name = "SMDK4x12 Camera",
- .author = "Paul Kocialkowski",
- .methods = &smdk4x12_camera_module_methods,
- },
- .get_number_of_cameras = smdk4x12_camera_get_number_of_cameras,
- .get_camera_info = smdk4x12_camera_get_camera_info,
-};