Don't mess with hardcoded values
authorPaul Kocialkowski <contact@paulk.fr>
Sun, 27 Jan 2013 20:20:46 +0000 (21:20 +0100)
committerPaul Kocialkowski <contact@paulk.fr>
Sun, 27 Jan 2013 20:20:46 +0000 (21:20 +0100)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
exynos_camera.c
exynos_camera.h

index ea647b5..9562bee 100644 (file)
 struct exynos_camera_preset exynos_camera_presets_galaxys2[] = {
        {
                .name = "M5MO",
-               .facing = CAMERA_FACING_FRONT,
+               .facing = CAMERA_FACING_BACK,
                .orientation = 90,
                .rotation = 0,
-               .hflip = 1,
+               .hflip = 0,
                .vflip = 0,
                .params = {
+                       .preview_size_values = "640x480,720x480,800x480,800x450,352x288,320x240,176x144",
+                       .preview_size = "640x480",
+                       .preview_format_values = "yuv420sp,yuv420p,rgb565",
+                       .preview_format = "yuv420sp",
+                       .preview_frame_rate_values = "30,25,20,15,10,7",
+                       .preview_frame_rate = 30,
+                       .preview_fps_range_values = "(7000,30000)",
+                       .preview_fps_range = "7000,30000",
+
+                       .picture_size_values = "3264x2448,3264x1968,2048x1536,2048x1232,800x480,640x480",
+                       .picture_size = "3264x2448",
+                       .picture_format_values = "jpeg",
+                       .picture_format = "jpeg",
+                       .jpeg_thumbnail_size_values = "320x240,400x240,0x0",
+                       .jpeg_thumbnail_width = 320,
+                       .jpeg_thumbnail_height = 240,
+                       .jpeg_thumbnail_quality = 100,
+                       .jpeg_quality = 90,
+
                        .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",
@@ -57,12 +76,31 @@ struct exynos_camera_preset exynos_camera_presets_galaxys2[] = {
        },
        {
                .name = "S5K5BAFX",
-               .facing = CAMERA_FACING_BACK,
+               .facing = CAMERA_FACING_FRONT,
                .orientation = 90,
                .rotation = 0,
-               .hflip = 0,
+               .hflip = 1,
                .vflip = 1,
                .params = {
+                       .preview_size_values = "640x480,352x288,320x240,176x144",
+                       .preview_size = "640x480",
+                       .preview_format_values = "yuv420sp,yuv420p,rgb565",
+                       .preview_format = "yuv420sp",
+                       .preview_frame_rate_values = "30,25,20,15,10,7",
+                       .preview_frame_rate = 30,
+                       .preview_fps_range_values = "(7000,30000)",
+                       .preview_fps_range = "7000,30000",
+
+                       .picture_size_values = "1600x1200,640x480",
+                       .picture_size = "1600x1200",
+                       .picture_format_values = "jpeg",
+                       .picture_format = "jpeg",
+                       .jpeg_thumbnail_size_values = "160x120,0x0",
+                       .jpeg_thumbnail_width = 160,
+                       .jpeg_thumbnail_height = 120,
+                       .jpeg_thumbnail_quality = 100,
+                       .jpeg_quality = 90,
+
                        .zoom_supported = 0,
                },
        },
@@ -224,22 +262,43 @@ int exynos_camera_params_init(struct exynos_camera *exynos_camera, int id)
        if (exynos_camera == NULL || id >= exynos_camera->config->presets_count)
                return -EINVAL;
 
-       exynos_param_string_set(exynos_camera, "preview-format", "yuv420sp");
-       exynos_param_string_set(exynos_camera, "preview-format-values", "yuv420sp");
-       exynos_param_string_set(exynos_camera, "preview-fps-range", "15000,30000");
-       exynos_param_string_set(exynos_camera, "preview-fps-range-values", "(15000,30000)");
-       exynos_param_int_set(exynos_camera, "preview-frame-rate", 15);
-       exynos_param_int_set(exynos_camera, "preview-frame-rate-values", 15);
-       exynos_param_string_set(exynos_camera, "preview-size", "640x480");
+       // Preview
        exynos_param_string_set(exynos_camera, "preview-size-values",
-               "720x480,640x480,352x288,176x144");
-
-       exynos_param_string_set(exynos_camera, "picture-format", "jpeg");
-       exynos_param_string_set(exynos_camera, "picture-format-values", "jpeg");
-
-       exynos_param_string_set(exynos_camera, "picture-size", "2560x1920");
+               exynos_camera->config->presets[id].params.preview_size_values);
+       exynos_param_string_set(exynos_camera, "preview-size",
+               exynos_camera->config->presets[id].params.preview_size);
+       exynos_param_string_set(exynos_camera, "preview-format-values",
+               exynos_camera->config->presets[id].params.preview_format_values);
+       exynos_param_string_set(exynos_camera, "preview-format",
+               exynos_camera->config->presets[id].params.preview_format);
+       exynos_param_string_set(exynos_camera, "preview-frame-rate-values",
+               exynos_camera->config->presets[id].params.preview_frame_rate_values);
+       exynos_param_int_set(exynos_camera, "preview-frame-rate",
+               exynos_camera->config->presets[id].params.preview_frame_rate);
+       exynos_param_string_set(exynos_camera, "preview-fps-range-values",
+               exynos_camera->config->presets[id].params.preview_fps_range_values);
+       exynos_param_string_set(exynos_camera, "preview-fps-range",
+               exynos_camera->config->presets[id].params.preview_fps_range);
+
+       // Picture
        exynos_param_string_set(exynos_camera, "picture-size-values",
-               "2560x1920,2048x1536,1600x1200,1280x960,640x480");
+               exynos_camera->config->presets[id].params.picture_size_values);
+       exynos_param_string_set(exynos_camera, "picture-size",
+               exynos_camera->config->presets[id].params.picture_size);
+       exynos_param_string_set(exynos_camera, "picture-format-values",
+               exynos_camera->config->presets[id].params.picture_format_values);
+       exynos_param_string_set(exynos_camera, "picture-format",
+               exynos_camera->config->presets[id].params.picture_format);
+       exynos_param_string_set(exynos_camera, "jpeg-thumbnail-size-values",
+               exynos_camera->config->presets[id].params.jpeg_thumbnail_size_values);
+       exynos_param_int_set(exynos_camera, "jpeg-thumbnail-width",
+               exynos_camera->config->presets[id].params.jpeg_thumbnail_width);
+       exynos_param_int_set(exynos_camera, "jpeg-thumbnail-height",
+               exynos_camera->config->presets[id].params.jpeg_thumbnail_height);
+       exynos_param_int_set(exynos_camera, "jpeg-thumbnail-quality",
+               exynos_camera->config->presets[id].params.jpeg_thumbnail_quality);
+       exynos_param_int_set(exynos_camera, "jpeg-quality",
+               exynos_camera->config->presets[id].params.jpeg_quality);
 
        // Zoom
        if (exynos_camera->config->presets[id].params.zoom_supported == 1) {
@@ -273,12 +332,19 @@ int exynos_camera_params_init(struct exynos_camera *exynos_camera, int id)
 
 int exynos_camera_params_apply(struct exynos_camera *exynos_camera)
 {
-       char *preview_format_string;
        char *preview_size_string;
-       int preview_format;
        int preview_width = 0;
        int preview_height = 0;
-       float preview_bpp;
+       char *preview_format_string;
+       int preview_format;
+       float preview_format_bpp;
+       int preview_fps;
+
+       char *picture_size_string;
+       int picture_width = 0;
+       int picture_height = 0;
+       char *picture_format_string;
+       int picture_format;
 
        char *zoom_supported_string;
        int zoom, max_zoom;
@@ -289,44 +355,80 @@ int exynos_camera_params_apply(struct exynos_camera *exynos_camera)
                return -EINVAL;
 
        // Preview
+       preview_size_string = exynos_param_string_get(exynos_camera, "preview-size");
+       if (preview_size_string != NULL) {
+               sscanf(preview_size_string, "%dx%d", &preview_width, &preview_height);
+
+               if (preview_width != 0 && preview_width != exynos_camera->preview_width)
+                       exynos_camera->preview_width = preview_width;
+               if (preview_height != 0 && preview_height != exynos_camera->preview_height)
+                       exynos_camera->preview_height = preview_height;
+       }
+
        preview_format_string = exynos_param_string_get(exynos_camera, "preview-format");
        if (preview_format_string != NULL) {
                if (strcmp(preview_format_string, "yuv420sp") == 0) {
                        preview_format = V4L2_PIX_FMT_NV21;
-                       preview_bpp = 1.5f;
+                       preview_format_bpp = 1.5f;
                } else if (strcmp(preview_format_string, "yuv420p") == 0) {
                        preview_format = V4L2_PIX_FMT_YUV420;
-                       preview_bpp = 1.5f;
+                       preview_format_bpp = 1.5f;
                } else if (strcmp(preview_format_string, "rgb565") == 0) {
                        preview_format = V4L2_PIX_FMT_RGB565;
-                       preview_bpp = 2.0f;
+                       preview_format_bpp = 2.0f;
                } else if (strcmp(preview_format_string, "rgb8888") == 0) {
                        preview_format = V4L2_PIX_FMT_RGB32;
-                       preview_bpp = 4.0f;
+                       preview_format_bpp = 4.0f;
                } else {
                        preview_format = V4L2_PIX_FMT_NV21;
-                       preview_bpp = 1.5f;
+                       preview_format_bpp = 1.5f;
                }
 
                if (preview_format != exynos_camera->preview_format) {
                        exynos_camera->preview_format = preview_format;
-                       exynos_camera->preview_bpp = preview_bpp;
+                       exynos_camera->preview_format_bpp = preview_format_bpp;
                }
        }
 
-       preview_size_string = exynos_param_string_get(exynos_camera, "preview-size");
-       if (preview_size_string != NULL) {
-               sscanf(preview_size_string, "%dx%d", &preview_width, &preview_height);
+       preview_fps = exynos_param_int_get(exynos_camera, "preview-frame-rate");
+       if (preview_fps > 0)
+               exynos_camera->preview_fps = preview_fps;
+       else
+               exynos_camera->preview_fps = 0;
 
-               if (preview_width != 0 && preview_height != 0 &&
-                       preview_width != exynos_camera->preview_width &&
-                       preview_height != exynos_camera->preview_height) {
-                       exynos_camera->preview_width = preview_width;
-                       exynos_camera->preview_height = preview_height;
+       // Picture
+       picture_size_string = exynos_param_string_get(exynos_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 != exynos_camera->picture_width &&
+                       picture_height != exynos_camera->picture_height) {
+                       exynos_camera->picture_width = picture_width;
+                       exynos_camera->picture_height = picture_height;
                }
                
        }
 
+       picture_format_string = exynos_param_string_get(exynos_camera, "picture-format");
+       if (picture_format_string != NULL) {
+               if (strcmp(picture_format_string, "yuv420sp") == 0)
+                       picture_format = V4L2_PIX_FMT_YUV420;
+               else if (strcmp(picture_format_string, "yuv420p") == 0)
+                       picture_format = V4L2_PIX_FMT_YUV420;
+               else if (strcmp(picture_format_string, "rgb565") == 0)
+                       picture_format = V4L2_PIX_FMT_RGB565;
+               else if (strcmp(picture_format_string, "rgb8888") == 0)
+                       picture_format = V4L2_PIX_FMT_RGB32;
+               else if (strcmp(picture_format_string, "jpeg") == 0)
+                       picture_format = V4L2_PIX_FMT_JPEG;
+               else
+                       picture_format = V4L2_PIX_FMT_JPEG;
+
+               if (picture_format != exynos_camera->picture_format)
+                       exynos_camera->picture_format = picture_format;
+       }
+
        // Zoom
        zoom_supported_string = exynos_param_string_get(exynos_camera, "zoom-supported");
        if (zoom_supported_string != NULL && strcmp(zoom_supported_string, "true") == 0) {
@@ -373,16 +475,18 @@ int exynos_camera_preview(struct exynos_camera *exynos_camera)
        int stride;
 
        int width, height;
-       float bpp;
+       float format_bpp;
 
+       char *preview_format_string;
        int frame_size, offset;
        void *preview_data;
        void *window_data;
 
        int index;
        int rc;
+       int i;
 
-       if (exynos_camera == NULL)
+       if (exynos_camera == NULL || exynos_camera->preview_memory == NULL)
                return -EINVAL;
 
        // V4L2
@@ -413,7 +517,7 @@ int exynos_camera_preview(struct exynos_camera *exynos_camera)
 
        width = exynos_camera->preview_width;
        height = exynos_camera->preview_height;
-       bpp = exynos_camera->preview_bpp;
+       format_bpp = exynos_camera->preview_format_bpp;
 
        exynos_camera->preview_window->dequeue_buffer(exynos_camera->preview_window,
                &buffer, &stride);
@@ -425,18 +529,21 @@ int exynos_camera_preview(struct exynos_camera *exynos_camera)
                return -1;
        }
 
-       frame_size = (int) ((float) width * (float) height * bpp);
+       frame_size = (int) ((float) width * (float) height * format_bpp);
        offset = index * frame_size;
 
        preview_data = (void *) ((int) exynos_camera->preview_memory->data + offset);
        memcpy(window_data, preview_data, frame_size);
 
-       // TODO: callback
-
        exynos_camera->gralloc->unlock(exynos_camera->gralloc, *buffer);
        exynos_camera->preview_window->enqueue_buffer(exynos_camera->preview_window,
                buffer);
 
+       if (EXYNOS_CAMERA_MSG_ENABLED(CAMERA_MSG_PREVIEW_FRAME) && EXYNOS_CAMERA_CALLBACK_DEFINED(data)) {
+               exynos_camera->callbacks.data(CAMERA_MSG_PREVIEW_FRAME,
+                       exynos_camera->preview_memory, index, NULL, exynos_camera->callbacks.user);
+       }
+
        return 0;
 }
 
@@ -481,7 +588,7 @@ int exynos_camera_preview_start(struct exynos_camera *exynos_camera)
 {
        struct v4l2_streamparm streamparm;
        int width, height, format;
-       float bpp;
+       float format_bpp;
        int fps, frame_size;
        int fd;
 
@@ -512,7 +619,7 @@ int exynos_camera_preview_start(struct exynos_camera *exynos_camera)
 
        width = exynos_camera->preview_width;
        height = exynos_camera->preview_height;
-       bpp = exynos_camera->preview_bpp;
+       format_bpp = exynos_camera->preview_format_bpp;
 
        rc = exynos_v4l2_s_fmt_pix_cap(exynos_camera, 0, width, height, format, V4L2_PIX_FMT_MODE_PREVIEW);
        if (rc < 0) {
@@ -528,14 +635,14 @@ int exynos_camera_preview_start(struct exynos_camera *exynos_camera)
 
        rc = exynos_v4l2_reqbufs_cap(exynos_camera, 0, EXYNOS_CAMERA_MAX_BUFFERS_COUNT);
        if (rc < 0) {
-               LOGE("%s: s ctrl failed!", __func__);
+               LOGE("%s: reqbufs failed!", __func__);
                return -1;
        }
 
        exynos_camera->preview_buffers_count = rc;
        LOGD("Found %d buffers available!", exynos_camera->preview_buffers_count);
 
-       fps = 0;
+       fps = exynos_camera->preview_fps;
        memset(&streamparm, 0, sizeof(streamparm));
        streamparm.parm.capture.timeperframe.numerator = 1;
        streamparm.parm.capture.timeperframe.denominator = fps;
@@ -546,7 +653,7 @@ int exynos_camera_preview_start(struct exynos_camera *exynos_camera)
                return -1;
        }
 
-       frame_size = (int) ((float) width * (float) height * bpp);
+       frame_size = (int) ((float) width * (float) height * format_bpp);
        for (i=0 ; i < exynos_camera->preview_buffers_count ; i++) {
                rc = exynos_v4l2_querybuf_cap(exynos_camera, 0, i);
                if (rc < 0) {
@@ -1006,7 +1113,9 @@ int exynos_camera_picture_start(struct exynos_camera *exynos_camera)
 
        // V4L2
 
-       format = V4L2_PIX_FMT_JPEG;
+       width = exynos_camera->picture_width;
+       height = exynos_camera->picture_height;
+       format = exynos_camera->picture_format;
 
        rc = exynos_v4l2_enum_fmt_cap(exynos_camera, 0, format);
        if (rc < 0) {
@@ -1014,9 +1123,6 @@ int exynos_camera_picture_start(struct exynos_camera *exynos_camera)
                return -1;
        }
 
-       width = 3264;
-       height = 2448;
-
        rc = exynos_v4l2_s_fmt_pix_cap(exynos_camera, 0, width, height, format, V4L2_PIX_FMT_MODE_CAPTURE);
        if (rc < 0) {
                LOGE("%s: s fmt failed!", __func__);
@@ -1026,7 +1132,7 @@ int exynos_camera_picture_start(struct exynos_camera *exynos_camera)
        // Only use 1 buffer
        rc = exynos_v4l2_reqbufs_cap(exynos_camera, 0, 1);
        if (rc < 0) {
-               LOGE("%s: s ctrl failed!", __func__);
+               LOGE("%s: reqbufs failed!", __func__);
                return -1;
        }
 
@@ -1464,6 +1570,16 @@ void exynos_camera_release(struct camera_device *dev)
 
        exynos_camera = (struct exynos_camera *) dev->priv;
 
+       if (exynos_camera->preview_memory != NULL && exynos_camera->preview_memory->release != NULL) {
+               exynos_camera->preview_memory->release(exynos_camera->preview_memory);
+               exynos_camera->preview_memory = NULL;
+       }
+
+       if (exynos_camera->picture_memory != NULL && exynos_camera->picture_memory->release != NULL) {
+               exynos_camera->picture_memory->release(exynos_camera->picture_memory);
+               exynos_camera->picture_memory = NULL;
+       }
+
        exynos_camera_deinit(exynos_camera);
 }
 
index b2c02f5..ce00c35 100644 (file)
@@ -65,8 +65,24 @@ struct exynos_param {
 };
 
 struct exynos_camera_params {
-       char *preview_sizes;
-       char *picture_sizes;
+       char *preview_size_values;
+       char *preview_size;
+       char *preview_format_values;
+       char *preview_format;
+       char *preview_frame_rate_values;
+       int preview_frame_rate;
+       char *preview_fps_range_values;
+       char *preview_fps_range;
+
+       char *picture_size_values;
+       char *picture_size;
+       char *picture_format_values;
+       char *picture_format;
+       char *jpeg_thumbnail_size_values;
+       int jpeg_thumbnail_width;
+       int jpeg_thumbnail_height;
+       int jpeg_thumbnail_quality;
+       int jpeg_quality;
 
        int zoom_supported;
        int smooth_zoom_supported;
@@ -152,7 +168,11 @@ struct exynos_camera {
        int preview_width;
        int preview_height;
        int preview_format;
-       float preview_bpp;
+       float preview_format_bpp;
+       int preview_fps;
+       int picture_width;
+       int picture_height;
+       int picture_format;
        int zoom;
        int focus_object_x;
        int focus_object_y;