Add a clever way to find preview size from video size
authorPaul Kocialkowski <contact@paulk.fr>
Sat, 2 Feb 2013 10:34:43 +0000 (11:34 +0100)
committerPaul Kocialkowski <contact@paulk.fr>
Sat, 2 Feb 2013 10:34:43 +0000 (11:34 +0100)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
exynos_camera.c
exynos_camera.h

index 1c32dc2..e24255a 100644 (file)
@@ -53,7 +53,7 @@ struct exynos_camera_preset exynos_camera_presets_galaxys2[] = {
                .picture_format = V4L2_PIX_FMT_JPEG,
                .focal_length = 400,
                .params = {
-                       .preview_size_values = "640x480,720x480,800x480,800x450,352x288,320x240,176x144",
+                       .preview_size_values = "1280x720,640x480,720x480,800x480,800x450,352x288,320x240,176x144",
                        .preview_size = "640x480",
                        .preview_format_values = "yuv420sp,yuv420p,rgb565",
                        .preview_format = "yuv420sp",
@@ -72,9 +72,8 @@ struct exynos_camera_preset exynos_camera_presets_galaxys2[] = {
                        .jpeg_thumbnail_quality = 100,
                        .jpeg_quality = 90,
 
-                       .recording_preview_size = NULL,
                        .recording_size = "720x480",
-                       .recording_size_values = "1280x720,720x480",
+                       .recording_size_values = "1920x1080,1280x720,720x480,640x480",
                        .recording_format = "yuv420sp",
 
                        .zoom_supported = 1,
@@ -113,7 +112,6 @@ struct exynos_camera_preset exynos_camera_presets_galaxys2[] = {
                        .jpeg_thumbnail_quality = 100,
                        .jpeg_quality = 90,
 
-                       .recording_preview_size = NULL,
                        .recording_size = "640x480",
                        .recording_size_values = "640x480",
                        .recording_format = "yuv420sp",
@@ -266,7 +264,7 @@ int exynos_camera_params_init(struct exynos_camera *exynos_camera, int id)
 
        // Recording preview
        exynos_param_string_set(exynos_camera, "preferred-preview-size-for-video",
-               exynos_camera->config->presets[id].params.recording_preview_size);
+               exynos_camera->config->presets[id].params.preview_size);
 
        // Preview
        exynos_param_string_set(exynos_camera, "preview-size-values",
@@ -382,6 +380,8 @@ int exynos_camera_params_apply(struct exynos_camera *exynos_camera)
        char *zoom_supported_string;
        int zoom, max_zoom;
 
+       int w, h;
+       char *k;
        int rc;
 
        if (exynos_camera == NULL)
@@ -394,18 +394,8 @@ int exynos_camera_params_apply(struct exynos_camera *exynos_camera)
         * original state when preview restarts.
         */
 
-       // Recording hint
-       recording_hint_string = exynos_param_string_get(exynos_camera, "recording-hint");
-
        // Preview
-       if (recording_hint_string != NULL && strcmp(recording_hint_string, "true") == 0)
-               preview_size_string = exynos_param_string_get(exynos_camera, "preferred-preview-size-for-video");
-       else
-               preview_size_string = NULL;
-
-       if (preview_size_string == NULL)
-               preview_size_string = exynos_param_string_get(exynos_camera, "preview-size");
-
+       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);
 
@@ -528,23 +518,50 @@ int exynos_camera_params_apply(struct exynos_camera *exynos_camera)
        }
 
        recording_hint_string = exynos_param_string_get(exynos_camera, "recording-hint");
-       if (recording_hint_string != NULL && strcmp(recording_hint_string, "true") == 0)
+       if (recording_hint_string != NULL && strcmp(recording_hint_string, "true") == 0) {
                camera_sensor_mode = SENSOR_MOVIE;
-       else
-               camera_sensor_mode = SENSOR_CAMERA;
 
-       // Entering recording mode
-       if (camera_sensor_mode != exynos_camera->camera_sensor_mode) {
-               exynos_camera->camera_sensor_mode = camera_sensor_mode;
-               rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_SENSOR_MODE, camera_sensor_mode);
-               if (rc < 0)
-                       LOGE("%s: s ctrl failed!", __func__);
+               k = exynos_param_string_get(exynos_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 != 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;
 
                camera_sensor_output_size = ((recording_width & 0xffff) << 16) | (recording_height & 0xffff);
                rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_SENSOR_OUTPUT_SIZE,
                        camera_sensor_output_size);
                if (rc < 0)
                        LOGE("%s: s ctrl failed!", __func__);
+       } else {
+               camera_sensor_mode = SENSOR_CAMERA;
+       }
+
+       // Switching modes
+       if (camera_sensor_mode != exynos_camera->camera_sensor_mode) {
+               exynos_camera->camera_sensor_mode = camera_sensor_mode;
+               rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_SENSOR_MODE, camera_sensor_mode);
+               if (rc < 0)
+                       LOGE("%s: s ctrl failed!", __func__);
        }
 
        // Zoom
@@ -605,6 +622,10 @@ int SecCamera::setObjectPosition(int x, int y)
 }
 */
 
+       LOGD("%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;
 }
 
index d4c33f3..c99caab 100644 (file)
@@ -90,7 +90,6 @@ struct exynos_camera_params {
        int jpeg_thumbnail_quality;
        int jpeg_quality;
 
-       char *recording_preview_size;
        char *recording_size;
        char *recording_size_values;
        char *recording_format;