blob: d8fef09f04c0911722fbe73bf7cac2925dbedd91 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
Wu-cheng Li8de57d82009-09-23 14:37:52 -07005** 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 Project9066cfe2009-03-03 19:31:44 -08008**
Wu-cheng Li8de57d82009-09-23 14:37:52 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010**
Wu-cheng Li8de57d82009-09-23 14:37:52 -070011** 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 Project9066cfe2009-03-03 19:31:44 -080015** 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 Agopian000479f2010-02-09 17:46:37 -080023#include <camera/CameraParameters.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25namespace android {
Wu-cheng Li8de57d82009-09-23 14:37:52 -070026// Parameter keys to communicate between camera application and driver.
27const char CameraParameters::KEY_PREVIEW_SIZE[] = "preview-size";
28const char CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES[] = "preview-size-values";
29const char CameraParameters::KEY_PREVIEW_FORMAT[] = "preview-format";
30const char CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS[] = "preview-format-values";
31const char CameraParameters::KEY_PREVIEW_FRAME_RATE[] = "preview-frame-rate";
32const char CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES[] = "preview-frame-rate-values";
Wu-cheng Li454630f2010-08-11 16:48:05 -070033const char CameraParameters::KEY_PREVIEW_FPS_RANGE[] = "preview-fps-range";
34const char CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE[] = "preview-fps-range-values";
Wu-cheng Li8de57d82009-09-23 14:37:52 -070035const char CameraParameters::KEY_PICTURE_SIZE[] = "picture-size";
36const char CameraParameters::KEY_SUPPORTED_PICTURE_SIZES[] = "picture-size-values";
37const char CameraParameters::KEY_PICTURE_FORMAT[] = "picture-format";
38const char CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS[] = "picture-format-values";
39const char CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH[] = "jpeg-thumbnail-width";
40const char CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT[] = "jpeg-thumbnail-height";
Wu-cheng Liacf77032010-01-25 15:18:18 +080041const char CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES[] = "jpeg-thumbnail-size-values";
Wu-cheng Li8de57d82009-09-23 14:37:52 -070042const char CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY[] = "jpeg-thumbnail-quality";
43const char CameraParameters::KEY_JPEG_QUALITY[] = "jpeg-quality";
44const char CameraParameters::KEY_ROTATION[] = "rotation";
45const char CameraParameters::KEY_GPS_LATITUDE[] = "gps-latitude";
46const char CameraParameters::KEY_GPS_LONGITUDE[] = "gps-longitude";
47const char CameraParameters::KEY_GPS_ALTITUDE[] = "gps-altitude";
48const char CameraParameters::KEY_GPS_TIMESTAMP[] = "gps-timestamp";
Ray Chen055c9862010-02-23 10:45:42 +080049const char CameraParameters::KEY_GPS_PROCESSING_METHOD[] = "gps-processing-method";
Wu-cheng Li8de57d82009-09-23 14:37:52 -070050const char CameraParameters::KEY_WHITE_BALANCE[] = "whitebalance";
51const char CameraParameters::KEY_SUPPORTED_WHITE_BALANCE[] = "whitebalance-values";
52const char CameraParameters::KEY_EFFECT[] = "effect";
53const char CameraParameters::KEY_SUPPORTED_EFFECTS[] = "effect-values";
54const char CameraParameters::KEY_ANTIBANDING[] = "antibanding";
55const char CameraParameters::KEY_SUPPORTED_ANTIBANDING[] = "antibanding-values";
56const char CameraParameters::KEY_SCENE_MODE[] = "scene-mode";
57const char CameraParameters::KEY_SUPPORTED_SCENE_MODES[] = "scene-mode-values";
58const char CameraParameters::KEY_FLASH_MODE[] = "flash-mode";
59const char CameraParameters::KEY_SUPPORTED_FLASH_MODES[] = "flash-mode-values";
60const char CameraParameters::KEY_FOCUS_MODE[] = "focus-mode";
61const char CameraParameters::KEY_SUPPORTED_FOCUS_MODES[] = "focus-mode-values";
Wu-cheng Li30771b72011-04-02 06:19:46 +080062const char CameraParameters::KEY_MAX_NUM_FOCUS_AREAS[] = "max-num-focus-areas";
63const char CameraParameters::KEY_FOCUS_AREAS[] = "focus-areas";
Wu-cheng Li6c8d2762010-01-27 22:55:14 +080064const char CameraParameters::KEY_FOCAL_LENGTH[] = "focal-length";
65const char CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE[] = "horizontal-view-angle";
66const char CameraParameters::KEY_VERTICAL_VIEW_ANGLE[] = "vertical-view-angle";
Wu-cheng Liff723b62010-02-09 13:38:19 +080067const char CameraParameters::KEY_EXPOSURE_COMPENSATION[] = "exposure-compensation";
Wu-cheng Li24b326a2010-02-20 17:47:04 +080068const char CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION[] = "max-exposure-compensation";
69const char CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION[] = "min-exposure-compensation";
70const char CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP[] = "exposure-compensation-step";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -070071const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK[] = "auto-exposure-lock";
72const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED[] = "auto-exposure-lock-supported";
Eino-Ville Talvalad9c2601a2011-05-13 10:19:59 -070073const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK[] = "auto-whitebalance-lock";
74const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED[] = "auto-whitebalance-lock-supported";
Wu-cheng Lie98e4c82011-04-12 19:34:29 +080075const char CameraParameters::KEY_MAX_NUM_METERING_AREAS[] = "max-num-metering-areas";
76const char CameraParameters::KEY_METERING_AREAS[] = "metering-areas";
Wu-cheng Li8cbb8f52010-02-28 23:19:55 -080077const char CameraParameters::KEY_ZOOM[] = "zoom";
78const char CameraParameters::KEY_MAX_ZOOM[] = "max-zoom";
79const char CameraParameters::KEY_ZOOM_RATIOS[] = "zoom-ratios";
80const char CameraParameters::KEY_ZOOM_SUPPORTED[] = "zoom-supported";
81const char CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED[] = "smooth-zoom-supported";
Wu-cheng Lie339c5e2010-05-13 19:31:02 +080082const char CameraParameters::KEY_FOCUS_DISTANCES[] = "focus-distances";
Wu-cheng Lid2c29292010-05-28 17:32:41 +080083const char CameraParameters::KEY_VIDEO_FRAME_FORMAT[] = "video-frame-format";
James Dong4fd446f2010-09-30 10:50:51 -070084const char CameraParameters::KEY_VIDEO_SIZE[] = "video-size";
85const char CameraParameters::KEY_SUPPORTED_VIDEO_SIZES[] = "video-size-values";
James Dong4ddca9b2010-11-29 16:51:55 -080086const char CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[] = "preferred-preview-size-for-video";
Wu-cheng Li4c2292e2011-07-22 02:37:11 +080087const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW[] = "max-num-detected-faces-hw";
88const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW[] = "max-num-detected-faces-sw";
Wu-cheng Li8de57d82009-09-23 14:37:52 -070089
Wu-cheng Lid9ef5d72010-03-08 15:28:48 -080090const char CameraParameters::TRUE[] = "true";
Eino-Ville Talvala3773eef2011-04-15 13:51:42 -070091const char CameraParameters::FALSE[] = "false";
Wu-cheng Liae7ca4c2010-05-15 13:05:04 +080092const char CameraParameters::FOCUS_DISTANCE_INFINITY[] = "Infinity";
Wu-cheng Lid9ef5d72010-03-08 15:28:48 -080093
Wu-cheng Li8de57d82009-09-23 14:37:52 -070094// Values for white balance settings.
95const char CameraParameters::WHITE_BALANCE_AUTO[] = "auto";
96const char CameraParameters::WHITE_BALANCE_INCANDESCENT[] = "incandescent";
97const char CameraParameters::WHITE_BALANCE_FLUORESCENT[] = "fluorescent";
98const char CameraParameters::WHITE_BALANCE_WARM_FLUORESCENT[] = "warm-fluorescent";
99const char CameraParameters::WHITE_BALANCE_DAYLIGHT[] = "daylight";
100const char CameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT[] = "cloudy-daylight";
101const char CameraParameters::WHITE_BALANCE_TWILIGHT[] = "twilight";
102const char CameraParameters::WHITE_BALANCE_SHADE[] = "shade";
103
104// Values for effect settings.
105const char CameraParameters::EFFECT_NONE[] = "none";
106const char CameraParameters::EFFECT_MONO[] = "mono";
107const char CameraParameters::EFFECT_NEGATIVE[] = "negative";
108const char CameraParameters::EFFECT_SOLARIZE[] = "solarize";
109const char CameraParameters::EFFECT_SEPIA[] = "sepia";
110const char CameraParameters::EFFECT_POSTERIZE[] = "posterize";
111const char CameraParameters::EFFECT_WHITEBOARD[] = "whiteboard";
112const char CameraParameters::EFFECT_BLACKBOARD[] = "blackboard";
113const char CameraParameters::EFFECT_AQUA[] = "aqua";
114
115// Values for antibanding settings.
116const char CameraParameters::ANTIBANDING_AUTO[] = "auto";
117const char CameraParameters::ANTIBANDING_50HZ[] = "50hz";
118const char CameraParameters::ANTIBANDING_60HZ[] = "60hz";
119const char CameraParameters::ANTIBANDING_OFF[] = "off";
120
121// Values for flash mode settings.
122const char CameraParameters::FLASH_MODE_OFF[] = "off";
123const char CameraParameters::FLASH_MODE_AUTO[] = "auto";
124const char CameraParameters::FLASH_MODE_ON[] = "on";
125const char CameraParameters::FLASH_MODE_RED_EYE[] = "red-eye";
Wu-cheng Life1a86d2009-09-28 13:51:12 -0700126const char CameraParameters::FLASH_MODE_TORCH[] = "torch";
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700127
128// Values for scene mode settings.
129const char CameraParameters::SCENE_MODE_AUTO[] = "auto";
130const char CameraParameters::SCENE_MODE_ACTION[] = "action";
131const char CameraParameters::SCENE_MODE_PORTRAIT[] = "portrait";
132const char CameraParameters::SCENE_MODE_LANDSCAPE[] = "landscape";
133const char CameraParameters::SCENE_MODE_NIGHT[] = "night";
134const char CameraParameters::SCENE_MODE_NIGHT_PORTRAIT[] = "night-portrait";
135const char CameraParameters::SCENE_MODE_THEATRE[] = "theatre";
136const char CameraParameters::SCENE_MODE_BEACH[] = "beach";
137const char CameraParameters::SCENE_MODE_SNOW[] = "snow";
138const char CameraParameters::SCENE_MODE_SUNSET[] = "sunset";
139const char CameraParameters::SCENE_MODE_STEADYPHOTO[] = "steadyphoto";
140const char CameraParameters::SCENE_MODE_FIREWORKS[] = "fireworks";
141const char CameraParameters::SCENE_MODE_SPORTS[] = "sports";
142const char CameraParameters::SCENE_MODE_PARTY[] = "party";
143const char CameraParameters::SCENE_MODE_CANDLELIGHT[] = "candlelight";
Wu-cheng Lic58b4232010-03-29 17:21:28 +0800144const char CameraParameters::SCENE_MODE_BARCODE[] = "barcode";
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700145
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700146const char CameraParameters::PIXEL_FORMAT_YUV422SP[] = "yuv422sp";
147const char CameraParameters::PIXEL_FORMAT_YUV420SP[] = "yuv420sp";
148const char CameraParameters::PIXEL_FORMAT_YUV422I[] = "yuv422i-yuyv";
Wu-cheng Li10a1b302011-02-22 15:49:25 +0800149const char CameraParameters::PIXEL_FORMAT_YUV420P[] = "yuv420p";
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700150const char CameraParameters::PIXEL_FORMAT_RGB565[] = "rgb565";
Iliyan Malchev21945132011-06-06 16:36:05 -0700151const char CameraParameters::PIXEL_FORMAT_RGBA8888[] = "rgba8888";
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700152const char CameraParameters::PIXEL_FORMAT_JPEG[] = "jpeg";
153
154// Values for focus mode settings.
155const char CameraParameters::FOCUS_MODE_AUTO[] = "auto";
156const char CameraParameters::FOCUS_MODE_INFINITY[] = "infinity";
157const char CameraParameters::FOCUS_MODE_MACRO[] = "macro";
158const char CameraParameters::FOCUS_MODE_FIXED[] = "fixed";
Wu-cheng Lic58b4232010-03-29 17:21:28 +0800159const char CameraParameters::FOCUS_MODE_EDOF[] = "edof";
Wu-cheng Lid45cb722010-09-20 16:15:32 -0700160const char CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO[] = "continuous-video";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162CameraParameters::CameraParameters()
163 : mMap()
164{
165}
166
167CameraParameters::~CameraParameters()
168{
169}
170
171String8 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
191void CameraParameters::unflatten(const String8 &params)
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
224void CameraParameters::set(const char *key, const char *value)
225{
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700226 // XXX i think i can do this with strspn()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 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
240void 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 Li7eae31c2010-01-31 14:19:38 +0800247void 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 Project9066cfe2009-03-03 19:31:44 -0800254const 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
262int 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 Li7eae31c2010-01-31 14:19:38 +0800270float 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 Li78624e42010-05-11 12:11:56 +0800277void CameraParameters::remove(const char *key)
278{
279 mMap.removeItem(String8(key));
280}
281
Wu-cheng Li454630f2010-08-11 16:48:05 -0700282// Parse string like "640x480" or "10000,20000"
283static int parse_pair(const char *str, int *first, int *second, char delim,
284 char **endptr = NULL)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285{
Wu-cheng Li454630f2010-08-11 16:48:05 -0700286 // Find the first integer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 char *end;
288 int w = (int)strtol(str, &end, 10);
Wu-cheng Li454630f2010-08-11 16:48:05 -0700289 // 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 Project9066cfe2009-03-03 19:31:44 -0800292 return -1;
Wu-cheng Li454630f2010-08-11 16:48:05 -0700293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294
Wu-cheng Li454630f2010-08-11 16:48:05 -0700295 // Find the second integer, immediately after the delimeter.
Nipun Kwatra0de0c492010-07-30 13:40:14 -0700296 int h = (int)strtol(end+1, &end, 10);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297
Wu-cheng Li454630f2010-08-11 16:48:05 -0700298 *first = w;
299 *second = h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300
Nipun Kwatra0de0c492010-07-30 13:40:14 -0700301 if (endptr) {
302 *endptr = end;
303 }
304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 return 0;
306}
307
Nipun Kwatra6c008b82010-08-04 14:04:07 -0700308static 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 Li454630f2010-08-11 16:48:05 -0700318 int success = parse_pair(sizeStartPtr, &width, &height, 'x',
319 &sizeStartPtr);
Nipun Kwatra6c008b82010-08-04 14:04:07 -0700320 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 Project9066cfe2009-03-03 19:31:44 -0800333void CameraParameters::setPreviewSize(int width, int height)
334{
335 char str[32];
336 sprintf(str, "%dx%d", width, height);
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700337 set(KEY_PREVIEW_SIZE, str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338}
339
340void CameraParameters::getPreviewSize(int *width, int *height) const
341{
Wu-cheng Li454630f2010-08-11 16:48:05 -0700342 *width = *height = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 // Get the current string, if it doesn't exist, leave the -1x-1
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700344 const char *p = get(KEY_PREVIEW_SIZE);
Wu-cheng Li454630f2010-08-11 16:48:05 -0700345 if (p == 0) return;
346 parse_pair(p, width, height, 'x');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347}
348
James Dong4ddca9b2010-11-29 16:51:55 -0800349void 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 Kwatra6c008b82010-08-04 14:04:07 -0700357void CameraParameters::getSupportedPreviewSizes(Vector<Size> &sizes) const
358{
359 const char *previewSizesStr = get(KEY_SUPPORTED_PREVIEW_SIZES);
360 parseSizesList(previewSizesStr, sizes);
361}
362
James Dong4fd446f2010-09-30 10:50:51 -0700363void 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
370void 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
378void 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 Project9066cfe2009-03-03 19:31:44 -0800384void CameraParameters::setPreviewFrameRate(int fps)
385{
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700386 set(KEY_PREVIEW_FRAME_RATE, fps);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387}
388
389int CameraParameters::getPreviewFrameRate() const
390{
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700391 return getInt(KEY_PREVIEW_FRAME_RATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392}
393
Wu-cheng Li454630f2010-08-11 16:48:05 -0700394void 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 Project9066cfe2009-03-03 19:31:44 -0800402void CameraParameters::setPreviewFormat(const char *format)
403{
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700404 set(KEY_PREVIEW_FORMAT, format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405}
406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407const char *CameraParameters::getPreviewFormat() const
408{
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700409 return get(KEY_PREVIEW_FORMAT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410}
411
412void CameraParameters::setPictureSize(int width, int height)
413{
414 char str[32];
415 sprintf(str, "%dx%d", width, height);
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700416 set(KEY_PICTURE_SIZE, str);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417}
418
419void CameraParameters::getPictureSize(int *width, int *height) const
420{
Wu-cheng Li454630f2010-08-11 16:48:05 -0700421 *width = *height = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 // Get the current string, if it doesn't exist, leave the -1x-1
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700423 const char *p = get(KEY_PICTURE_SIZE);
Wu-cheng Li454630f2010-08-11 16:48:05 -0700424 if (p == 0) return;
425 parse_pair(p, width, height, 'x');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426}
427
Nipun Kwatra6c008b82010-08-04 14:04:07 -0700428void 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 Project9066cfe2009-03-03 19:31:44 -0800434void CameraParameters::setPictureFormat(const char *format)
435{
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700436 set(KEY_PICTURE_FORMAT, format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437}
438
439const char *CameraParameters::getPictureFormat() const
440{
Wu-cheng Li8de57d82009-09-23 14:37:52 -0700441 return get(KEY_PICTURE_FORMAT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442}
443
444void 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
455status_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