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