summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Wu-cheng Li <wuchengli@google.com> 2010-08-11 16:48:05 -0700
committer Wu-cheng Li <wuchengli@google.com> 2010-08-20 11:14:17 -0700
commit454630f23784afcf3dd6fc58becbb9fb6aa878a9 (patch)
treed5ee24d80d56a0532e23c9bf92a65103161390e9
parenteba1274978911ea188eead128645299669d02f60 (diff)
Add camera fps range API.
Original preview frame rate API assumes the frame rate is fixed. It does not not work with auto frame rate camera. Change-Id: I38f7122ac8ec844ffd63558dc0763ffa17b0926a
-rw-r--r--core/java/android/hardware/Camera.java127
-rw-r--r--include/camera/CameraParameters.h15
-rw-r--r--libs/camera/CameraParameters.cpp59
3 files changed, 160 insertions, 41 deletions
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index a0abc6c0da9e..e432a474b82d 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -960,6 +960,7 @@ public class Camera {
private static final String KEY_PREVIEW_SIZE = "preview-size";
private static final String KEY_PREVIEW_FORMAT = "preview-format";
private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate";
+ private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range";
private static final String KEY_PICTURE_SIZE = "picture-size";
private static final String KEY_PICTURE_FORMAT = "picture-format";
private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size";
@@ -1219,6 +1220,22 @@ public class Camera {
*/
public static final String METERING_MODE_SPOT = "spot";
+ /**
+ * The array index of minimum preview fps for use with {@link
+ * #getPreviewFpsRange(int[])} or {@link
+ * #getSupportedPreviewFpsRange()}.
+ * @hide
+ */
+ public static final int PREVIEW_FPS_MIN_INDEX = 0;
+
+ /**
+ * The array index of maximum preview fps for use with {@link
+ * #getPreviewFpsRange(int[])} or {@link
+ * #getSupportedPreviewFpsRange()}.
+ * @hide
+ */
+ public static final int PREVIEW_FPS_MAX_INDEX = 1;
+
// Formats for setPreviewFormat and setPictureFormat.
private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp";
private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp";
@@ -1482,6 +1499,64 @@ public class Camera {
}
/**
+ * Sets the maximum and maximum preview fps. This controls the rate of
+ * preview frames received in {@link #PreviewCallback}. The minimum and
+ * maximum preview fps must be one of the elements from {@link
+ * #getSupportedPreviewFpsRange}.
+ *
+ * @param min the minimum preview fps (scaled by 1000).
+ * @param max the maximum preview fps (scaled by 1000).
+ * @throws RuntimeException if fps range is invalid.
+ * @see #setPreviewCallbackWithBuffer(Camera.PreviewCallback)
+ * @see #getSupportedPreviewFpsRange()
+ * @hide
+ */
+ public void setPreviewFpsRange(int min, int max) {
+ set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max);
+ }
+
+ /**
+ * Returns the current minimum and maximum preview fps. The values are
+ * one of the elements returned by {@link #getSupportedPreviewFpsRange}.
+ *
+ * @return range the minimum and maximum preview fps (scaled by 1000).
+ * @see #PREVIEW_FPS_MIN_INDEX
+ * @see #PREVIEW_FPS_MAX_INDEX
+ * @see #getSupportedPreviewFpsRange()
+ * @hide
+ */
+ public void getPreviewFpsRange(int[] range) {
+ if (range == null || range.length != 2) {
+ throw new IllegalArgumentException(
+ "range must be an float array with two elements.");
+ }
+ splitInt(get(KEY_PREVIEW_FPS_RANGE), range);
+ }
+
+ /**
+ * Gets the supported preview fps (frame-per-second) ranges. Each range
+ * contains a minimum fps and maximum fps. If minimum fps equals to
+ * maximum fps, the camera outputs frames in fixed frame rate. If not,
+ * the camera outputs frames in auto frame rate. The actual frame rate
+ * fluctuates between the minimum and the maximum. The values are
+ * multiplied by 1000 and represented in integers. For example, if frame
+ * rate is 26.623 frames per second, the value is 26623.
+ *
+ * @return a list of supported preview fps ranges. This method returns a
+ * list with at least one element. Every element is an int array
+ * of two values - minimum fps and maximum fps. The list is
+ * sorted from small to large (first by maximum fps and then
+ * minimum fps).
+ * @see #PREVIEW_FPS_MIN_INDEX
+ * @see #PREVIEW_FPS_MAX_INDEX
+ * @hide
+ */
+ public List<int[]> getSupportedPreviewFpsRange() {
+ String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX);
+ return splitRange(str);
+ }
+
+ /**
* Sets the image format for preview pictures.
* <p>If this is never called, the default format will be
* {@link android.graphics.ImageFormat#NV21}, which
@@ -2184,10 +2259,7 @@ public class Camera {
throw new IllegalArgumentException(
"output must be an float array with three elements.");
}
- List<Float> distances = splitFloat(get(KEY_FOCUS_DISTANCES));
- output[0] = distances.get(0);
- output[1] = distances.get(1);
- output[2] = distances.get(2);
+ splitFloat(get(KEY_FOCUS_DISTANCES), output);
}
/**
@@ -2255,19 +2327,27 @@ public class Camera {
return substrings;
}
+ private void splitInt(String str, int[] output) {
+ if (str == null) return;
+
+ StringTokenizer tokenizer = new StringTokenizer(str, ",");
+ int index = 0;
+ while (tokenizer.hasMoreElements()) {
+ String token = tokenizer.nextToken();
+ output[index++] = Integer.parseInt(token);
+ }
+ }
+
// Splits a comma delimited string to an ArrayList of Float.
- // Return null if the passing string is null or the size is 0.
- private ArrayList<Float> splitFloat(String str) {
- if (str == null) return null;
+ private void splitFloat(String str, float[] output) {
+ if (str == null) return;
StringTokenizer tokenizer = new StringTokenizer(str, ",");
- ArrayList<Float> substrings = new ArrayList<Float>();
+ int index = 0;
while (tokenizer.hasMoreElements()) {
String token = tokenizer.nextToken();
- substrings.add(Float.parseFloat(token));
+ output[index++] = Float.parseFloat(token);
}
- if (substrings.size() == 0) return null;
- return substrings;
}
// Returns the value of a float parameter.
@@ -2318,5 +2398,30 @@ public class Camera {
Log.e(TAG, "Invalid size parameter string=" + str);
return null;
}
+
+ // Splits a comma delimited string to an ArrayList of int array.
+ // Example string: "(10000,26623),(10000,30000)". Return null if the
+ // passing string is null or the size is 0.
+ private ArrayList<int[]> splitRange(String str) {
+ if (str == null || str.charAt(0) != '('
+ || str.charAt(str.length() - 1) != ')') {
+ Log.e(TAG, "Invalid range list string=" + str);
+ return null;
+ }
+
+ ArrayList<int[]> rangeList = new ArrayList<int[]>();
+ int endIndex, fromIndex = 1;
+ do {
+ int[] range = new int[2];
+ endIndex = str.indexOf("),(", fromIndex);
+ if (endIndex == -1) endIndex = str.length() - 1;
+ splitInt(str.substring(fromIndex, endIndex), range);
+ rangeList.add(range);
+ fromIndex = endIndex + 3;
+ } while (endIndex != str.length() - 1);
+
+ if (rangeList.size() == 0) return null;
+ return rangeList;
+ }
};
}
diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h
index 4bc1799f2991..a5c7874e0add 100644
--- a/include/camera/CameraParameters.h
+++ b/include/camera/CameraParameters.h
@@ -61,6 +61,7 @@ public:
void getSupportedPreviewSizes(Vector<Size> &sizes) const;
void setPreviewFrameRate(int fps);
int getPreviewFrameRate() const;
+ void getPreviewFpsRange(int *min_fps, int *max_fps) const;
void setPreviewFormat(const char *format);
const char *getPreviewFormat() const;
void setPictureSize(int width, int height);
@@ -82,6 +83,20 @@ public:
// Supported preview frame sizes in pixels.
// Example value: "800x600,480x320". Read only.
static const char KEY_SUPPORTED_PREVIEW_SIZES[];
+ // The current minimum and maximum preview fps. This controls the rate of
+ // preview frames received (CAMERA_MSG_PREVIEW_FRAME). The minimum and
+ // maximum fps must be one of the elements from
+ // KEY_SUPPORTED_PREVIEW_FPS_RANGE parameter.
+ // Example value: "10500,26623"
+ static const char KEY_PREVIEW_FPS_RANGE[];
+ // The supported preview fps (frame-per-second) ranges. Each range contains
+ // a minimum fps and maximum fps. If minimum fps equals to maximum fps, the
+ // camera outputs frames in fixed frame rate. If not, the camera outputs
+ // frames in auto frame rate. The actual frame rate fluctuates between the
+ // minimum and the maximum. The list has at least one element. The list is
+ // sorted from small to large (first by maximum fps and then minimum fps).
+ // Example value: "(10500,26623),(15000,26623),(30000,30000)"
+ static const char KEY_SUPPORTED_PREVIEW_FPS_RANGE[];
// The image format for preview frames. See CAMERA_MSG_PREVIEW_FRAME in
// frameworks/base/include/camera/Camera.h.
// Example value: "yuv420sp" or PIXEL_FORMAT_XXX constants. Read/write.
diff --git a/libs/camera/CameraParameters.cpp b/libs/camera/CameraParameters.cpp
index abd418a4daef..d0ed7df59257 100644
--- a/libs/camera/CameraParameters.cpp
+++ b/libs/camera/CameraParameters.cpp
@@ -30,6 +30,8 @@ const char CameraParameters::KEY_PREVIEW_FORMAT[] = "preview-format";
const char CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS[] = "preview-format-values";
const char CameraParameters::KEY_PREVIEW_FRAME_RATE[] = "preview-frame-rate";
const char CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES[] = "preview-frame-rate-values";
+const char CameraParameters::KEY_PREVIEW_FPS_RANGE[] = "preview-fps-range";
+const char CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE[] = "preview-fps-range-values";
const char CameraParameters::KEY_PICTURE_SIZE[] = "picture-size";
const char CameraParameters::KEY_SUPPORTED_PICTURE_SIZES[] = "picture-size-values";
const char CameraParameters::KEY_PICTURE_FORMAT[] = "picture-format";
@@ -269,20 +271,24 @@ void CameraParameters::remove(const char *key)
mMap.removeItem(String8(key));
}
-static int parse_size(const char *str, int &width, int &height, char **endptr = NULL)
+// Parse string like "640x480" or "10000,20000"
+static int parse_pair(const char *str, int *first, int *second, char delim,
+ char **endptr = NULL)
{
- // Find the width.
+ // Find the first integer.
char *end;
int w = (int)strtol(str, &end, 10);
- // If an 'x' does not immediately follow, give up.
- if (*end != 'x')
+ // If a delimeter does not immediately follow, give up.
+ if (*end != delim) {
+ LOGE("Cannot find delimeter (%c) in str=%s", delim, str);
return -1;
+ }
- // Find the height, immediately after the 'x'.
+ // Find the second integer, immediately after the delimeter.
int h = (int)strtol(end+1, &end, 10);
- width = w;
- height = h;
+ *first = w;
+ *second = h;
if (endptr) {
*endptr = end;
@@ -301,7 +307,8 @@ static void parseSizesList(const char *sizesStr, Vector<Size> &sizes)
while (true) {
int width, height;
- int success = parse_size(sizeStartPtr, width, height, &sizeStartPtr);
+ int success = parse_pair(sizeStartPtr, &width, &height, 'x',
+ &sizeStartPtr);
if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
LOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
return;
@@ -324,19 +331,11 @@ void CameraParameters::setPreviewSize(int width, int height)
void CameraParameters::getPreviewSize(int *width, int *height) const
{
- *width = -1;
- *height = -1;
-
+ *width = *height = -1;
// Get the current string, if it doesn't exist, leave the -1x-1
const char *p = get(KEY_PREVIEW_SIZE);
- if (p == 0)
- return;
-
- int w, h;
- if (parse_size(p, w, h) == 0) {
- *width = w;
- *height = h;
- }
+ if (p == 0) return;
+ parse_pair(p, width, height, 'x');
}
void CameraParameters::getSupportedPreviewSizes(Vector<Size> &sizes) const
@@ -355,6 +354,14 @@ int CameraParameters::getPreviewFrameRate() const
return getInt(KEY_PREVIEW_FRAME_RATE);
}
+void CameraParameters::getPreviewFpsRange(int *min_fps, int *max_fps) const
+{
+ *min_fps = *max_fps = -1;
+ const char *p = get(KEY_PREVIEW_FPS_RANGE);
+ if (p == 0) return;
+ parse_pair(p, min_fps, max_fps, ',');
+}
+
void CameraParameters::setPreviewFormat(const char *format)
{
set(KEY_PREVIEW_FORMAT, format);
@@ -374,19 +381,11 @@ void CameraParameters::setPictureSize(int width, int height)
void CameraParameters::getPictureSize(int *width, int *height) const
{
- *width = -1;
- *height = -1;
-
+ *width = *height = -1;
// Get the current string, if it doesn't exist, leave the -1x-1
const char *p = get(KEY_PICTURE_SIZE);
- if (p == 0)
- return;
-
- int w, h;
- if (parse_size(p, w, h) == 0) {
- *width = w;
- *height = h;
- }
+ if (p == 0) return;
+ parse_pair(p, width, height, 'x');
}
void CameraParameters::getSupportedPictureSizes(Vector<Size> &sizes) const