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