OSDN Git Service

Camera: Allow larger preview resolutions in API1 for >= HALv2 devices
authorEino-Ville Talvala <etalvala@google.com>
Sat, 13 Sep 2014 00:15:24 +0000 (17:15 -0700)
committerEino-Ville Talvala <etalvala@google.com>
Sat, 13 Sep 2014 19:36:52 +0000 (12:36 -0700)
Limit preview resolutions to a max of 1920x1920 instead of 1920x1080p,
so that any aspect ratio with a 1920 as the larger dimension can be used.

Also improve the initial preview/video size selection logic, to ensure
that the selected size is both a valid preview and video size, and not
too large.

Bug: 17458832
Change-Id: Iea006fadb5fbf0f03d23c3c5babb5b3611469688

services/camera/libcameraservice/api1/client2/Parameters.cpp
services/camera/libcameraservice/api1/client2/Parameters.h

index 8d00590..ed9137f 100644 (file)
@@ -76,9 +76,29 @@ status_t Parameters::initialize(const CameraMetadata *info, int deviceVersion) {
     res = getFilteredSizes(MAX_VIDEO_SIZE, &availableVideoSizes);
     if (res != OK) return res;
 
-    // TODO: Pick more intelligently
-    previewWidth = availablePreviewSizes[0].width;
-    previewHeight = availablePreviewSizes[0].height;
+    // Select initial preview and video size that's under the initial bound and
+    // on the list of both preview and recording sizes
+    previewWidth = 0;
+    previewHeight = 0;
+    for (size_t i = 0 ; i < availablePreviewSizes.size(); i++) {
+        int newWidth = availablePreviewSizes[i].width;
+        int newHeight = availablePreviewSizes[i].height;
+        if (newWidth >= previewWidth && newHeight >= previewHeight &&
+                newWidth <= MAX_INITIAL_PREVIEW_WIDTH &&
+                newHeight <= MAX_INITIAL_PREVIEW_HEIGHT) {
+            for (size_t j = 0; j < availableVideoSizes.size(); j++) {
+                if (availableVideoSizes[j].width == newWidth &&
+                        availableVideoSizes[j].height == newHeight) {
+                    previewWidth = newWidth;
+                    previewHeight = newHeight;
+                }
+            }
+        }
+    }
+    if (previewWidth == 0) {
+        ALOGE("%s: No initial preview size can be found!", __FUNCTION__);
+        return BAD_VALUE;
+    }
     videoWidth = previewWidth;
     videoHeight = previewHeight;
 
index 5e6e6ab..815cc55 100644 (file)
@@ -179,8 +179,13 @@ struct Parameters {
     // Number of zoom steps to simulate
     static const unsigned int NUM_ZOOM_STEPS = 100;
     // Max preview size allowed
+    // This is set to a 1:1 value to allow for any aspect ratio that has
+    // a max long side of 1920 pixels
     static const unsigned int MAX_PREVIEW_WIDTH = 1920;
-    static const unsigned int MAX_PREVIEW_HEIGHT = 1080;
+    static const unsigned int MAX_PREVIEW_HEIGHT = 1920;
+    // Initial max preview/recording size bound
+    static const int MAX_INITIAL_PREVIEW_WIDTH = 1920;
+    static const int MAX_INITIAL_PREVIEW_HEIGHT = 1080;
     // Aspect ratio tolerance
     static const float ASPECT_RATIO_TOLERANCE = 0.001;