The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "CameraParams" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <string.h> |
| 22 | #include <stdlib.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 23 | #include <camera/CameraParameters.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | namespace android { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 26 | // Parameter keys to communicate between camera application and driver. |
| 27 | const char CameraParameters::KEY_PREVIEW_SIZE[] = "preview-size"; |
| 28 | const char CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES[] = "preview-size-values"; |
| 29 | const char CameraParameters::KEY_PREVIEW_FORMAT[] = "preview-format"; |
| 30 | const char CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS[] = "preview-format-values"; |
| 31 | const char CameraParameters::KEY_PREVIEW_FRAME_RATE[] = "preview-frame-rate"; |
| 32 | const char CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES[] = "preview-frame-rate-values"; |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 33 | const char CameraParameters::KEY_PREVIEW_FPS_RANGE[] = "preview-fps-range"; |
| 34 | const char CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE[] = "preview-fps-range-values"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 35 | const char CameraParameters::KEY_PICTURE_SIZE[] = "picture-size"; |
| 36 | const char CameraParameters::KEY_SUPPORTED_PICTURE_SIZES[] = "picture-size-values"; |
| 37 | const char CameraParameters::KEY_PICTURE_FORMAT[] = "picture-format"; |
| 38 | const char CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS[] = "picture-format-values"; |
| 39 | const char CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH[] = "jpeg-thumbnail-width"; |
| 40 | const char CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT[] = "jpeg-thumbnail-height"; |
Wu-cheng Li | acf7703 | 2010-01-25 15:18:18 +0800 | [diff] [blame] | 41 | const char CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES[] = "jpeg-thumbnail-size-values"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 42 | const char CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY[] = "jpeg-thumbnail-quality"; |
| 43 | const char CameraParameters::KEY_JPEG_QUALITY[] = "jpeg-quality"; |
| 44 | const char CameraParameters::KEY_ROTATION[] = "rotation"; |
| 45 | const char CameraParameters::KEY_GPS_LATITUDE[] = "gps-latitude"; |
| 46 | const char CameraParameters::KEY_GPS_LONGITUDE[] = "gps-longitude"; |
| 47 | const char CameraParameters::KEY_GPS_ALTITUDE[] = "gps-altitude"; |
| 48 | const char CameraParameters::KEY_GPS_TIMESTAMP[] = "gps-timestamp"; |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 49 | const char CameraParameters::KEY_GPS_PROCESSING_METHOD[] = "gps-processing-method"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 50 | const char CameraParameters::KEY_WHITE_BALANCE[] = "whitebalance"; |
| 51 | const char CameraParameters::KEY_SUPPORTED_WHITE_BALANCE[] = "whitebalance-values"; |
| 52 | const char CameraParameters::KEY_EFFECT[] = "effect"; |
| 53 | const char CameraParameters::KEY_SUPPORTED_EFFECTS[] = "effect-values"; |
| 54 | const char CameraParameters::KEY_ANTIBANDING[] = "antibanding"; |
| 55 | const char CameraParameters::KEY_SUPPORTED_ANTIBANDING[] = "antibanding-values"; |
| 56 | const char CameraParameters::KEY_SCENE_MODE[] = "scene-mode"; |
| 57 | const char CameraParameters::KEY_SUPPORTED_SCENE_MODES[] = "scene-mode-values"; |
| 58 | const char CameraParameters::KEY_FLASH_MODE[] = "flash-mode"; |
| 59 | const char CameraParameters::KEY_SUPPORTED_FLASH_MODES[] = "flash-mode-values"; |
| 60 | const char CameraParameters::KEY_FOCUS_MODE[] = "focus-mode"; |
| 61 | const char CameraParameters::KEY_SUPPORTED_FOCUS_MODES[] = "focus-mode-values"; |
Wu-cheng Li | 30771b7 | 2011-04-02 06:19:46 +0800 | [diff] [blame] | 62 | const char CameraParameters::KEY_MAX_NUM_FOCUS_AREAS[] = "max-num-focus-areas"; |
| 63 | const char CameraParameters::KEY_FOCUS_AREAS[] = "focus-areas"; |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 64 | const char CameraParameters::KEY_FOCAL_LENGTH[] = "focal-length"; |
| 65 | const char CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE[] = "horizontal-view-angle"; |
| 66 | const char CameraParameters::KEY_VERTICAL_VIEW_ANGLE[] = "vertical-view-angle"; |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 67 | const char CameraParameters::KEY_EXPOSURE_COMPENSATION[] = "exposure-compensation"; |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 68 | const char CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION[] = "max-exposure-compensation"; |
| 69 | const char CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION[] = "min-exposure-compensation"; |
| 70 | const char CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP[] = "exposure-compensation-step"; |
Wu-cheng Li | e98e4c8 | 2011-04-12 19:34:29 +0800 | [diff] [blame] | 71 | const char CameraParameters::KEY_MAX_NUM_METERING_AREAS[] = "max-num-metering-areas"; |
| 72 | const char CameraParameters::KEY_METERING_AREAS[] = "metering-areas"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 73 | const char CameraParameters::KEY_ZOOM[] = "zoom"; |
| 74 | const char CameraParameters::KEY_MAX_ZOOM[] = "max-zoom"; |
| 75 | const char CameraParameters::KEY_ZOOM_RATIOS[] = "zoom-ratios"; |
| 76 | const char CameraParameters::KEY_ZOOM_SUPPORTED[] = "zoom-supported"; |
| 77 | const char CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED[] = "smooth-zoom-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame] | 78 | const char CameraParameters::KEY_FOCUS_DISTANCES[] = "focus-distances"; |
Wu-cheng Li | d2c2929 | 2010-05-28 17:32:41 +0800 | [diff] [blame] | 79 | const char CameraParameters::KEY_VIDEO_FRAME_FORMAT[] = "video-frame-format"; |
James Dong | 4fd446f | 2010-09-30 10:50:51 -0700 | [diff] [blame] | 80 | const char CameraParameters::KEY_VIDEO_SIZE[] = "video-size"; |
| 81 | const char CameraParameters::KEY_SUPPORTED_VIDEO_SIZES[] = "video-size-values"; |
James Dong | 4ddca9b | 2010-11-29 16:51:55 -0800 | [diff] [blame] | 82 | const char CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[] = "preferred-preview-size-for-video"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 83 | |
Wu-cheng Li | d9ef5d7 | 2010-03-08 15:28:48 -0800 | [diff] [blame] | 84 | const char CameraParameters::TRUE[] = "true"; |
Wu-cheng Li | ae7ca4c | 2010-05-15 13:05:04 +0800 | [diff] [blame] | 85 | const char CameraParameters::FOCUS_DISTANCE_INFINITY[] = "Infinity"; |
Wu-cheng Li | d9ef5d7 | 2010-03-08 15:28:48 -0800 | [diff] [blame] | 86 | |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 87 | // Values for white balance settings. |
| 88 | const char CameraParameters::WHITE_BALANCE_AUTO[] = "auto"; |
| 89 | const char CameraParameters::WHITE_BALANCE_INCANDESCENT[] = "incandescent"; |
| 90 | const char CameraParameters::WHITE_BALANCE_FLUORESCENT[] = "fluorescent"; |
| 91 | const char CameraParameters::WHITE_BALANCE_WARM_FLUORESCENT[] = "warm-fluorescent"; |
| 92 | const char CameraParameters::WHITE_BALANCE_DAYLIGHT[] = "daylight"; |
| 93 | const char CameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT[] = "cloudy-daylight"; |
| 94 | const char CameraParameters::WHITE_BALANCE_TWILIGHT[] = "twilight"; |
| 95 | const char CameraParameters::WHITE_BALANCE_SHADE[] = "shade"; |
| 96 | |
| 97 | // Values for effect settings. |
| 98 | const char CameraParameters::EFFECT_NONE[] = "none"; |
| 99 | const char CameraParameters::EFFECT_MONO[] = "mono"; |
| 100 | const char CameraParameters::EFFECT_NEGATIVE[] = "negative"; |
| 101 | const char CameraParameters::EFFECT_SOLARIZE[] = "solarize"; |
| 102 | const char CameraParameters::EFFECT_SEPIA[] = "sepia"; |
| 103 | const char CameraParameters::EFFECT_POSTERIZE[] = "posterize"; |
| 104 | const char CameraParameters::EFFECT_WHITEBOARD[] = "whiteboard"; |
| 105 | const char CameraParameters::EFFECT_BLACKBOARD[] = "blackboard"; |
| 106 | const char CameraParameters::EFFECT_AQUA[] = "aqua"; |
| 107 | |
| 108 | // Values for antibanding settings. |
| 109 | const char CameraParameters::ANTIBANDING_AUTO[] = "auto"; |
| 110 | const char CameraParameters::ANTIBANDING_50HZ[] = "50hz"; |
| 111 | const char CameraParameters::ANTIBANDING_60HZ[] = "60hz"; |
| 112 | const char CameraParameters::ANTIBANDING_OFF[] = "off"; |
| 113 | |
| 114 | // Values for flash mode settings. |
| 115 | const char CameraParameters::FLASH_MODE_OFF[] = "off"; |
| 116 | const char CameraParameters::FLASH_MODE_AUTO[] = "auto"; |
| 117 | const char CameraParameters::FLASH_MODE_ON[] = "on"; |
| 118 | const char CameraParameters::FLASH_MODE_RED_EYE[] = "red-eye"; |
Wu-cheng Li | fe1a86d | 2009-09-28 13:51:12 -0700 | [diff] [blame] | 119 | const char CameraParameters::FLASH_MODE_TORCH[] = "torch"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 120 | |
| 121 | // Values for scene mode settings. |
| 122 | const char CameraParameters::SCENE_MODE_AUTO[] = "auto"; |
| 123 | const char CameraParameters::SCENE_MODE_ACTION[] = "action"; |
| 124 | const char CameraParameters::SCENE_MODE_PORTRAIT[] = "portrait"; |
| 125 | const char CameraParameters::SCENE_MODE_LANDSCAPE[] = "landscape"; |
| 126 | const char CameraParameters::SCENE_MODE_NIGHT[] = "night"; |
| 127 | const char CameraParameters::SCENE_MODE_NIGHT_PORTRAIT[] = "night-portrait"; |
| 128 | const char CameraParameters::SCENE_MODE_THEATRE[] = "theatre"; |
| 129 | const char CameraParameters::SCENE_MODE_BEACH[] = "beach"; |
| 130 | const char CameraParameters::SCENE_MODE_SNOW[] = "snow"; |
| 131 | const char CameraParameters::SCENE_MODE_SUNSET[] = "sunset"; |
| 132 | const char CameraParameters::SCENE_MODE_STEADYPHOTO[] = "steadyphoto"; |
| 133 | const char CameraParameters::SCENE_MODE_FIREWORKS[] = "fireworks"; |
| 134 | const char CameraParameters::SCENE_MODE_SPORTS[] = "sports"; |
| 135 | const char CameraParameters::SCENE_MODE_PARTY[] = "party"; |
| 136 | const char CameraParameters::SCENE_MODE_CANDLELIGHT[] = "candlelight"; |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 137 | const char CameraParameters::SCENE_MODE_BARCODE[] = "barcode"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 138 | |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 139 | const char CameraParameters::PIXEL_FORMAT_YUV422SP[] = "yuv422sp"; |
| 140 | const char CameraParameters::PIXEL_FORMAT_YUV420SP[] = "yuv420sp"; |
| 141 | const char CameraParameters::PIXEL_FORMAT_YUV422I[] = "yuv422i-yuyv"; |
Wu-cheng Li | 10a1b30 | 2011-02-22 15:49:25 +0800 | [diff] [blame] | 142 | const char CameraParameters::PIXEL_FORMAT_YUV420P[] = "yuv420p"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 143 | const char CameraParameters::PIXEL_FORMAT_RGB565[] = "rgb565"; |
| 144 | const char CameraParameters::PIXEL_FORMAT_JPEG[] = "jpeg"; |
| 145 | |
| 146 | // Values for focus mode settings. |
| 147 | const char CameraParameters::FOCUS_MODE_AUTO[] = "auto"; |
| 148 | const char CameraParameters::FOCUS_MODE_INFINITY[] = "infinity"; |
| 149 | const char CameraParameters::FOCUS_MODE_MACRO[] = "macro"; |
| 150 | const char CameraParameters::FOCUS_MODE_FIXED[] = "fixed"; |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 151 | const char CameraParameters::FOCUS_MODE_EDOF[] = "edof"; |
Wu-cheng Li | d45cb72 | 2010-09-20 16:15:32 -0700 | [diff] [blame] | 152 | const char CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO[] = "continuous-video"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | CameraParameters::CameraParameters() |
| 155 | : mMap() |
| 156 | { |
| 157 | } |
| 158 | |
| 159 | CameraParameters::~CameraParameters() |
| 160 | { |
| 161 | } |
| 162 | |
| 163 | String8 CameraParameters::flatten() const |
| 164 | { |
| 165 | String8 flattened(""); |
| 166 | size_t size = mMap.size(); |
| 167 | |
| 168 | for (size_t i = 0; i < size; i++) { |
| 169 | String8 k, v; |
| 170 | k = mMap.keyAt(i); |
| 171 | v = mMap.valueAt(i); |
| 172 | |
| 173 | flattened += k; |
| 174 | flattened += "="; |
| 175 | flattened += v; |
| 176 | if (i != size-1) |
| 177 | flattened += ";"; |
| 178 | } |
| 179 | |
| 180 | return flattened; |
| 181 | } |
| 182 | |
| 183 | void CameraParameters::unflatten(const String8 ¶ms) |
| 184 | { |
| 185 | const char *a = params.string(); |
| 186 | const char *b; |
| 187 | |
| 188 | mMap.clear(); |
| 189 | |
| 190 | for (;;) { |
| 191 | // Find the bounds of the key name. |
| 192 | b = strchr(a, '='); |
| 193 | if (b == 0) |
| 194 | break; |
| 195 | |
| 196 | // Create the key string. |
| 197 | String8 k(a, (size_t)(b-a)); |
| 198 | |
| 199 | // Find the value. |
| 200 | a = b+1; |
| 201 | b = strchr(a, ';'); |
| 202 | if (b == 0) { |
| 203 | // If there's no semicolon, this is the last item. |
| 204 | String8 v(a); |
| 205 | mMap.add(k, v); |
| 206 | break; |
| 207 | } |
| 208 | |
| 209 | String8 v(a, (size_t)(b-a)); |
| 210 | mMap.add(k, v); |
| 211 | a = b+1; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | |
| 216 | void CameraParameters::set(const char *key, const char *value) |
| 217 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 218 | // XXX i think i can do this with strspn() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | if (strchr(key, '=') || strchr(key, ';')) { |
| 220 | //XXX LOGE("Key \"%s\"contains invalid character (= or ;)", key); |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | if (strchr(value, '=') || strchr(key, ';')) { |
| 225 | //XXX LOGE("Value \"%s\"contains invalid character (= or ;)", value); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | mMap.replaceValueFor(String8(key), String8(value)); |
| 230 | } |
| 231 | |
| 232 | void CameraParameters::set(const char *key, int value) |
| 233 | { |
| 234 | char str[16]; |
| 235 | sprintf(str, "%d", value); |
| 236 | set(key, str); |
| 237 | } |
| 238 | |
Wu-cheng Li | 7eae31c | 2010-01-31 14:19:38 +0800 | [diff] [blame] | 239 | void CameraParameters::setFloat(const char *key, float value) |
| 240 | { |
| 241 | char str[16]; // 14 should be enough. We overestimate to be safe. |
| 242 | snprintf(str, sizeof(str), "%g", value); |
| 243 | set(key, str); |
| 244 | } |
| 245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | const char *CameraParameters::get(const char *key) const |
| 247 | { |
| 248 | String8 v = mMap.valueFor(String8(key)); |
| 249 | if (v.length() == 0) |
| 250 | return 0; |
| 251 | return v.string(); |
| 252 | } |
| 253 | |
| 254 | int CameraParameters::getInt(const char *key) const |
| 255 | { |
| 256 | const char *v = get(key); |
| 257 | if (v == 0) |
| 258 | return -1; |
| 259 | return strtol(v, 0, 0); |
| 260 | } |
| 261 | |
Wu-cheng Li | 7eae31c | 2010-01-31 14:19:38 +0800 | [diff] [blame] | 262 | float CameraParameters::getFloat(const char *key) const |
| 263 | { |
| 264 | const char *v = get(key); |
| 265 | if (v == 0) return -1; |
| 266 | return strtof(v, 0); |
| 267 | } |
| 268 | |
Wu-cheng Li | 78624e4 | 2010-05-11 12:11:56 +0800 | [diff] [blame] | 269 | void CameraParameters::remove(const char *key) |
| 270 | { |
| 271 | mMap.removeItem(String8(key)); |
| 272 | } |
| 273 | |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 274 | // Parse string like "640x480" or "10000,20000" |
| 275 | static int parse_pair(const char *str, int *first, int *second, char delim, |
| 276 | char **endptr = NULL) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | { |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 278 | // Find the first integer. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | char *end; |
| 280 | int w = (int)strtol(str, &end, 10); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 281 | // If a delimeter does not immediately follow, give up. |
| 282 | if (*end != delim) { |
| 283 | LOGE("Cannot find delimeter (%c) in str=%s", delim, str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | return -1; |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 285 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 287 | // Find the second integer, immediately after the delimeter. |
Nipun Kwatra | 0de0c49 | 2010-07-30 13:40:14 -0700 | [diff] [blame] | 288 | int h = (int)strtol(end+1, &end, 10); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 290 | *first = w; |
| 291 | *second = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
Nipun Kwatra | 0de0c49 | 2010-07-30 13:40:14 -0700 | [diff] [blame] | 293 | if (endptr) { |
| 294 | *endptr = end; |
| 295 | } |
| 296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
Nipun Kwatra | 6c008b8 | 2010-08-04 14:04:07 -0700 | [diff] [blame] | 300 | static void parseSizesList(const char *sizesStr, Vector<Size> &sizes) |
| 301 | { |
| 302 | if (sizesStr == 0) { |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | char *sizeStartPtr = (char *)sizesStr; |
| 307 | |
| 308 | while (true) { |
| 309 | int width, height; |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 310 | int success = parse_pair(sizeStartPtr, &width, &height, 'x', |
| 311 | &sizeStartPtr); |
Nipun Kwatra | 6c008b8 | 2010-08-04 14:04:07 -0700 | [diff] [blame] | 312 | if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) { |
| 313 | LOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr); |
| 314 | return; |
| 315 | } |
| 316 | sizes.push(Size(width, height)); |
| 317 | |
| 318 | if (*sizeStartPtr == '\0') { |
| 319 | return; |
| 320 | } |
| 321 | sizeStartPtr++; |
| 322 | } |
| 323 | } |
| 324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | void CameraParameters::setPreviewSize(int width, int height) |
| 326 | { |
| 327 | char str[32]; |
| 328 | sprintf(str, "%dx%d", width, height); |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 329 | set(KEY_PREVIEW_SIZE, str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | void CameraParameters::getPreviewSize(int *width, int *height) const |
| 333 | { |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 334 | *width = *height = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | // Get the current string, if it doesn't exist, leave the -1x-1 |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 336 | const char *p = get(KEY_PREVIEW_SIZE); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 337 | if (p == 0) return; |
| 338 | parse_pair(p, width, height, 'x'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | } |
| 340 | |
James Dong | 4ddca9b | 2010-11-29 16:51:55 -0800 | [diff] [blame] | 341 | void CameraParameters::getPreferredPreviewSizeForVideo(int *width, int *height) const |
| 342 | { |
| 343 | *width = *height = -1; |
| 344 | const char *p = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO); |
| 345 | if (p == 0) return; |
| 346 | parse_pair(p, width, height, 'x'); |
| 347 | } |
| 348 | |
Nipun Kwatra | 6c008b8 | 2010-08-04 14:04:07 -0700 | [diff] [blame] | 349 | void CameraParameters::getSupportedPreviewSizes(Vector<Size> &sizes) const |
| 350 | { |
| 351 | const char *previewSizesStr = get(KEY_SUPPORTED_PREVIEW_SIZES); |
| 352 | parseSizesList(previewSizesStr, sizes); |
| 353 | } |
| 354 | |
James Dong | 4fd446f | 2010-09-30 10:50:51 -0700 | [diff] [blame] | 355 | void CameraParameters::setVideoSize(int width, int height) |
| 356 | { |
| 357 | char str[32]; |
| 358 | sprintf(str, "%dx%d", width, height); |
| 359 | set(KEY_VIDEO_SIZE, str); |
| 360 | } |
| 361 | |
| 362 | void CameraParameters::getVideoSize(int *width, int *height) const |
| 363 | { |
| 364 | *width = *height = -1; |
| 365 | const char *p = get(KEY_VIDEO_SIZE); |
| 366 | if (p == 0) return; |
| 367 | parse_pair(p, width, height, 'x'); |
| 368 | } |
| 369 | |
| 370 | void CameraParameters::getSupportedVideoSizes(Vector<Size> &sizes) const |
| 371 | { |
| 372 | const char *videoSizesStr = get(KEY_SUPPORTED_VIDEO_SIZES); |
| 373 | parseSizesList(videoSizesStr, sizes); |
| 374 | } |
| 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | void CameraParameters::setPreviewFrameRate(int fps) |
| 377 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 378 | set(KEY_PREVIEW_FRAME_RATE, fps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | int CameraParameters::getPreviewFrameRate() const |
| 382 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 383 | return getInt(KEY_PREVIEW_FRAME_RATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 386 | void CameraParameters::getPreviewFpsRange(int *min_fps, int *max_fps) const |
| 387 | { |
| 388 | *min_fps = *max_fps = -1; |
| 389 | const char *p = get(KEY_PREVIEW_FPS_RANGE); |
| 390 | if (p == 0) return; |
| 391 | parse_pair(p, min_fps, max_fps, ','); |
| 392 | } |
| 393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | void CameraParameters::setPreviewFormat(const char *format) |
| 395 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 396 | set(KEY_PREVIEW_FORMAT, format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | } |
| 398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | const char *CameraParameters::getPreviewFormat() const |
| 400 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 401 | return get(KEY_PREVIEW_FORMAT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void CameraParameters::setPictureSize(int width, int height) |
| 405 | { |
| 406 | char str[32]; |
| 407 | sprintf(str, "%dx%d", width, height); |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 408 | set(KEY_PICTURE_SIZE, str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void CameraParameters::getPictureSize(int *width, int *height) const |
| 412 | { |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 413 | *width = *height = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | // Get the current string, if it doesn't exist, leave the -1x-1 |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 415 | const char *p = get(KEY_PICTURE_SIZE); |
Wu-cheng Li | 454630f | 2010-08-11 16:48:05 -0700 | [diff] [blame] | 416 | if (p == 0) return; |
| 417 | parse_pair(p, width, height, 'x'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Nipun Kwatra | 6c008b8 | 2010-08-04 14:04:07 -0700 | [diff] [blame] | 420 | void CameraParameters::getSupportedPictureSizes(Vector<Size> &sizes) const |
| 421 | { |
| 422 | const char *pictureSizesStr = get(KEY_SUPPORTED_PICTURE_SIZES); |
| 423 | parseSizesList(pictureSizesStr, sizes); |
| 424 | } |
| 425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | void CameraParameters::setPictureFormat(const char *format) |
| 427 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 428 | set(KEY_PICTURE_FORMAT, format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | const char *CameraParameters::getPictureFormat() const |
| 432 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 433 | return get(KEY_PICTURE_FORMAT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | void CameraParameters::dump() const |
| 437 | { |
| 438 | LOGD("dump: mMap.size = %d", mMap.size()); |
| 439 | for (size_t i = 0; i < mMap.size(); i++) { |
| 440 | String8 k, v; |
| 441 | k = mMap.keyAt(i); |
| 442 | v = mMap.valueAt(i); |
| 443 | LOGD("%s: %s\n", k.string(), v.string()); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | status_t CameraParameters::dump(int fd, const Vector<String16>& args) const |
| 448 | { |
| 449 | const size_t SIZE = 256; |
| 450 | char buffer[SIZE]; |
| 451 | String8 result; |
| 452 | snprintf(buffer, 255, "CameraParameters::dump: mMap.size = %d\n", mMap.size()); |
| 453 | result.append(buffer); |
| 454 | for (size_t i = 0; i < mMap.size(); i++) { |
| 455 | String8 k, v; |
| 456 | k = mMap.keyAt(i); |
| 457 | v = mMap.valueAt(i); |
| 458 | snprintf(buffer, 255, "\t%s: %s\n", k.string(), v.string()); |
| 459 | result.append(buffer); |
| 460 | } |
| 461 | write(fd, result.string(), result.size()); |
| 462 | return NO_ERROR; |
| 463 | } |
| 464 | |
| 465 | }; // namespace android |