1 /*
2 **
3 ** Copyright 2008, The Android Open Source Project
4 **
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
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
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
15 ** limitations under the License.
16 */
17
18 #define LOG_TAG "CameraParams"
19 #include <log/log.h>
20
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "CameraParameters.h"
25 #include <system/graphics.h>
26
27 namespace android {
28 namespace hardware {
29 namespace camera {
30 namespace common {
31 namespace V1_0 {
32 namespace helper {
33
34 // Parameter keys to communicate between camera application and driver.
35 const char CameraParameters::KEY_PREVIEW_SIZE[] = "preview-size";
36 const char CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES[] = "preview-size-values";
37 const char CameraParameters::KEY_PREVIEW_FORMAT[] = "preview-format";
38 const char CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS[] = "preview-format-values";
39 const char CameraParameters::KEY_PREVIEW_FRAME_RATE[] = "preview-frame-rate";
40 const char CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES[] = "preview-frame-rate-values";
41 const char CameraParameters::KEY_PREVIEW_FPS_RANGE[] = "preview-fps-range";
42 const char CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE[] = "preview-fps-range-values";
43 const char CameraParameters::KEY_PICTURE_SIZE[] = "picture-size";
44 const char CameraParameters::KEY_SUPPORTED_PICTURE_SIZES[] = "picture-size-values";
45 const char CameraParameters::KEY_PICTURE_FORMAT[] = "picture-format";
46 const char CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS[] = "picture-format-values";
47 const char CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH[] = "jpeg-thumbnail-width";
48 const char CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT[] = "jpeg-thumbnail-height";
49 const char CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES[] = "jpeg-thumbnail-size-values";
50 const char CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY[] = "jpeg-thumbnail-quality";
51 const char CameraParameters::KEY_JPEG_QUALITY[] = "jpeg-quality";
52 const char CameraParameters::KEY_ROTATION[] = "rotation";
53 const char CameraParameters::KEY_GPS_LATITUDE[] = "gps-latitude";
54 const char CameraParameters::KEY_GPS_LONGITUDE[] = "gps-longitude";
55 const char CameraParameters::KEY_GPS_ALTITUDE[] = "gps-altitude";
56 const char CameraParameters::KEY_GPS_TIMESTAMP[] = "gps-timestamp";
57 const char CameraParameters::KEY_GPS_PROCESSING_METHOD[] = "gps-processing-method";
58 const char CameraParameters::KEY_WHITE_BALANCE[] = "whitebalance";
59 const char CameraParameters::KEY_SUPPORTED_WHITE_BALANCE[] = "whitebalance-values";
60 const char CameraParameters::KEY_EFFECT[] = "effect";
61 const char CameraParameters::KEY_SUPPORTED_EFFECTS[] = "effect-values";
62 const char CameraParameters::KEY_ANTIBANDING[] = "antibanding";
63 const char CameraParameters::KEY_SUPPORTED_ANTIBANDING[] = "antibanding-values";
64 const char CameraParameters::KEY_SCENE_MODE[] = "scene-mode";
65 const char CameraParameters::KEY_SUPPORTED_SCENE_MODES[] = "scene-mode-values";
66 const char CameraParameters::KEY_FLASH_MODE[] = "flash-mode";
67 const char CameraParameters::KEY_SUPPORTED_FLASH_MODES[] = "flash-mode-values";
68 const char CameraParameters::KEY_FOCUS_MODE[] = "focus-mode";
69 const char CameraParameters::KEY_SUPPORTED_FOCUS_MODES[] = "focus-mode-values";
70 const char CameraParameters::KEY_MAX_NUM_FOCUS_AREAS[] = "max-num-focus-areas";
71 const char CameraParameters::KEY_FOCUS_AREAS[] = "focus-areas";
72 const char CameraParameters::KEY_FOCAL_LENGTH[] = "focal-length";
73 const char CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE[] = "horizontal-view-angle";
74 const char CameraParameters::KEY_VERTICAL_VIEW_ANGLE[] = "vertical-view-angle";
75 const char CameraParameters::KEY_EXPOSURE_COMPENSATION[] = "exposure-compensation";
76 const char CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION[] = "max-exposure-compensation";
77 const char CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION[] = "min-exposure-compensation";
78 const char CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP[] = "exposure-compensation-step";
79 const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK[] = "auto-exposure-lock";
80 const char CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED[] = "auto-exposure-lock-supported";
81 const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK[] = "auto-whitebalance-lock";
82 const char CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED[] = "auto-whitebalance-lock-supported";
83 const char CameraParameters::KEY_MAX_NUM_METERING_AREAS[] = "max-num-metering-areas";
84 const char CameraParameters::KEY_METERING_AREAS[] = "metering-areas";
85 const char CameraParameters::KEY_ZOOM[] = "zoom";
86 const char CameraParameters::KEY_MAX_ZOOM[] = "max-zoom";
87 const char CameraParameters::KEY_ZOOM_RATIOS[] = "zoom-ratios";
88 const char CameraParameters::KEY_ZOOM_SUPPORTED[] = "zoom-supported";
89 const char CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED[] = "smooth-zoom-supported";
90 const char CameraParameters::KEY_FOCUS_DISTANCES[] = "focus-distances";
91 const char CameraParameters::KEY_VIDEO_FRAME_FORMAT[] = "video-frame-format";
92 const char CameraParameters::KEY_VIDEO_SIZE[] = "video-size";
93 const char CameraParameters::KEY_SUPPORTED_VIDEO_SIZES[] = "video-size-values";
94 const char CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[] = "preferred-preview-size-for-video";
95 const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_HW[] = "max-num-detected-faces-hw";
96 const char CameraParameters::KEY_MAX_NUM_DETECTED_FACES_SW[] = "max-num-detected-faces-sw";
97 const char CameraParameters::KEY_RECORDING_HINT[] = "recording-hint";
98 const char CameraParameters::KEY_VIDEO_SNAPSHOT_SUPPORTED[] = "video-snapshot-supported";
99 const char CameraParameters::KEY_VIDEO_STABILIZATION[] = "video-stabilization";
100 const char CameraParameters::KEY_VIDEO_STABILIZATION_SUPPORTED[] = "video-stabilization-supported";
101 const char CameraParameters::KEY_LIGHTFX[] = "light-fx";
102
103 const char CameraParameters::TRUE[] = "true";
104 const char CameraParameters::FALSE[] = "false";
105 const char CameraParameters::FOCUS_DISTANCE_INFINITY[] = "Infinity";
106
107 // Values for white balance settings.
108 const char CameraParameters::WHITE_BALANCE_AUTO[] = "auto";
109 const char CameraParameters::WHITE_BALANCE_INCANDESCENT[] = "incandescent";
110 const char CameraParameters::WHITE_BALANCE_FLUORESCENT[] = "fluorescent";
111 const char CameraParameters::WHITE_BALANCE_WARM_FLUORESCENT[] = "warm-fluorescent";
112 const char CameraParameters::WHITE_BALANCE_DAYLIGHT[] = "daylight";
113 const char CameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT[] = "cloudy-daylight";
114 const char CameraParameters::WHITE_BALANCE_TWILIGHT[] = "twilight";
115 const char CameraParameters::WHITE_BALANCE_SHADE[] = "shade";
116
117 // Values for effect settings.
118 const char CameraParameters::EFFECT_NONE[] = "none";
119 const char CameraParameters::EFFECT_MONO[] = "mono";
120 const char CameraParameters::EFFECT_NEGATIVE[] = "negative";
121 const char CameraParameters::EFFECT_SOLARIZE[] = "solarize";
122 const char CameraParameters::EFFECT_SEPIA[] = "sepia";
123 const char CameraParameters::EFFECT_POSTERIZE[] = "posterize";
124 const char CameraParameters::EFFECT_WHITEBOARD[] = "whiteboard";
125 const char CameraParameters::EFFECT_BLACKBOARD[] = "blackboard";
126 const char CameraParameters::EFFECT_AQUA[] = "aqua";
127
128 // Values for antibanding settings.
129 const char CameraParameters::ANTIBANDING_AUTO[] = "auto";
130 const char CameraParameters::ANTIBANDING_50HZ[] = "50hz";
131 const char CameraParameters::ANTIBANDING_60HZ[] = "60hz";
132 const char CameraParameters::ANTIBANDING_OFF[] = "off";
133
134 // Values for flash mode settings.
135 const char CameraParameters::FLASH_MODE_OFF[] = "off";
136 const char CameraParameters::FLASH_MODE_AUTO[] = "auto";
137 const char CameraParameters::FLASH_MODE_ON[] = "on";
138 const char CameraParameters::FLASH_MODE_RED_EYE[] = "red-eye";
139 const char CameraParameters::FLASH_MODE_TORCH[] = "torch";
140
141 // Values for scene mode settings.
142 const char CameraParameters::SCENE_MODE_AUTO[] = "auto";
143 const char CameraParameters::SCENE_MODE_ACTION[] = "action";
144 const char CameraParameters::SCENE_MODE_PORTRAIT[] = "portrait";
145 const char CameraParameters::SCENE_MODE_LANDSCAPE[] = "landscape";
146 const char CameraParameters::SCENE_MODE_NIGHT[] = "night";
147 const char CameraParameters::SCENE_MODE_NIGHT_PORTRAIT[] = "night-portrait";
148 const char CameraParameters::SCENE_MODE_THEATRE[] = "theatre";
149 const char CameraParameters::SCENE_MODE_BEACH[] = "beach";
150 const char CameraParameters::SCENE_MODE_SNOW[] = "snow";
151 const char CameraParameters::SCENE_MODE_SUNSET[] = "sunset";
152 const char CameraParameters::SCENE_MODE_STEADYPHOTO[] = "steadyphoto";
153 const char CameraParameters::SCENE_MODE_FIREWORKS[] = "fireworks";
154 const char CameraParameters::SCENE_MODE_SPORTS[] = "sports";
155 const char CameraParameters::SCENE_MODE_PARTY[] = "party";
156 const char CameraParameters::SCENE_MODE_CANDLELIGHT[] = "candlelight";
157 const char CameraParameters::SCENE_MODE_BARCODE[] = "barcode";
158 const char CameraParameters::SCENE_MODE_HDR[] = "hdr";
159
160 const char CameraParameters::PIXEL_FORMAT_YUV422SP[] = "yuv422sp";
161 const char CameraParameters::PIXEL_FORMAT_YUV420SP[] = "yuv420sp";
162 const char CameraParameters::PIXEL_FORMAT_YUV422I[] = "yuv422i-yuyv";
163 const char CameraParameters::PIXEL_FORMAT_YUV420P[] = "yuv420p";
164 const char CameraParameters::PIXEL_FORMAT_RGB565[] = "rgb565";
165 const char CameraParameters::PIXEL_FORMAT_RGBA8888[] = "rgba8888";
166 const char CameraParameters::PIXEL_FORMAT_JPEG[] = "jpeg";
167 const char CameraParameters::PIXEL_FORMAT_BAYER_RGGB[] = "bayer-rggb";
168 const char CameraParameters::PIXEL_FORMAT_ANDROID_OPAQUE[] = "android-opaque";
169
170 // Values for focus mode settings.
171 const char CameraParameters::FOCUS_MODE_AUTO[] = "auto";
172 const char CameraParameters::FOCUS_MODE_INFINITY[] = "infinity";
173 const char CameraParameters::FOCUS_MODE_MACRO[] = "macro";
174 const char CameraParameters::FOCUS_MODE_FIXED[] = "fixed";
175 const char CameraParameters::FOCUS_MODE_EDOF[] = "edof";
176 const char CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO[] = "continuous-video";
177 const char CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE[] = "continuous-picture";
178
179 // Values for light fx settings
180 const char CameraParameters::LIGHTFX_LOWLIGHT[] = "low-light";
181 const char CameraParameters::LIGHTFX_HDR[] = "high-dynamic-range";
182
CameraParameters()183 CameraParameters::CameraParameters()
184 : mMap()
185 {
186 }
187
~CameraParameters()188 CameraParameters::~CameraParameters()
189 {
190 }
191
flatten() const192 String8 CameraParameters::flatten() const
193 {
194 String8 flattened("");
195 size_t size = mMap.size();
196
197 for (size_t i = 0; i < size; i++) {
198 String8 k, v;
199 k = mMap.keyAt(i);
200 v = mMap.valueAt(i);
201
202 flattened += k;
203 flattened += "=";
204 flattened += v;
205 if (i != size-1)
206 flattened += ";";
207 }
208
209 return flattened;
210 }
211
unflatten(const String8 & params)212 void CameraParameters::unflatten(const String8 ¶ms)
213 {
214 const char *a = params.string();
215 const char *b;
216
217 mMap.clear();
218
219 for (;;) {
220 // Find the bounds of the key name.
221 b = strchr(a, '=');
222 if (b == 0)
223 break;
224
225 // Create the key string.
226 String8 k(a, (size_t)(b-a));
227
228 // Find the value.
229 a = b+1;
230 b = strchr(a, ';');
231 if (b == 0) {
232 // If there's no semicolon, this is the last item.
233 String8 v(a);
234 mMap.add(k, v);
235 break;
236 }
237
238 String8 v(a, (size_t)(b-a));
239 mMap.add(k, v);
240 a = b+1;
241 }
242 }
243
244
set(const char * key,const char * value)245 void CameraParameters::set(const char *key, const char *value)
246 {
247 // i think i can do this with strspn()
248 if (strchr(key, '=') || strchr(key, ';')) {
249 // ALOGE("Key \"%s\"contains invalid character (= or ;)", key);
250 return;
251 }
252
253 if (strchr(value, '=') || strchr(value, ';')) {
254 // ALOGE("Value \"%s\"contains invalid character (= or ;)", value);
255 return;
256 }
257
258 mMap.replaceValueFor(String8(key), String8(value));
259 }
260
set(const char * key,int value)261 void CameraParameters::set(const char *key, int value)
262 {
263 char str[16];
264 sprintf(str, "%d", value);
265 set(key, str);
266 }
267
setFloat(const char * key,float value)268 void CameraParameters::setFloat(const char *key, float value)
269 {
270 char str[16]; // 14 should be enough. We overestimate to be safe.
271 snprintf(str, sizeof(str), "%g", value);
272 set(key, str);
273 }
274
get(const char * key) const275 const char *CameraParameters::get(const char *key) const
276 {
277 String8 v = mMap.valueFor(String8(key));
278 if (v.length() == 0)
279 return 0;
280 return v.string();
281 }
282
getInt(const char * key) const283 int CameraParameters::getInt(const char *key) const
284 {
285 const char *v = get(key);
286 if (v == 0)
287 return -1;
288 return strtol(v, 0, 0);
289 }
290
getFloat(const char * key) const291 float CameraParameters::getFloat(const char *key) const
292 {
293 const char *v = get(key);
294 if (v == 0) return -1;
295 return strtof(v, 0);
296 }
297
remove(const char * key)298 void CameraParameters::remove(const char *key)
299 {
300 mMap.removeItem(String8(key));
301 }
302
303 // Parse string like "640x480" or "10000,20000"
parse_pair(const char * str,int * first,int * second,char delim,char ** endptr=NULL)304 static int parse_pair(const char *str, int *first, int *second, char delim,
305 char **endptr = NULL)
306 {
307 // Find the first integer.
308 char *end;
309 int w = (int)strtol(str, &end, 10);
310 // If a delimeter does not immediately follow, give up.
311 if (*end != delim) {
312 ALOGE("Cannot find delimeter (%c) in str=%s", delim, str);
313 return -1;
314 }
315
316 // Find the second integer, immediately after the delimeter.
317 int h = (int)strtol(end+1, &end, 10);
318
319 *first = w;
320 *second = h;
321
322 if (endptr) {
323 *endptr = end;
324 }
325
326 return 0;
327 }
328
parseSizesList(const char * sizesStr,Vector<Size> & sizes)329 static void parseSizesList(const char *sizesStr, Vector<Size> &sizes)
330 {
331 if (sizesStr == 0) {
332 return;
333 }
334
335 char *sizeStartPtr = (char *)sizesStr;
336
337 while (true) {
338 int width, height;
339 int success = parse_pair(sizeStartPtr, &width, &height, 'x',
340 &sizeStartPtr);
341 if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
342 ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
343 return;
344 }
345 sizes.push(Size(width, height));
346
347 if (*sizeStartPtr == '\0') {
348 return;
349 }
350 sizeStartPtr++;
351 }
352 }
353
setPreviewSize(int width,int height)354 void CameraParameters::setPreviewSize(int width, int height)
355 {
356 char str[32];
357 sprintf(str, "%dx%d", width, height);
358 set(KEY_PREVIEW_SIZE, str);
359 }
360
getPreviewSize(int * width,int * height) const361 void CameraParameters::getPreviewSize(int *width, int *height) const
362 {
363 *width = *height = -1;
364 // Get the current string, if it doesn't exist, leave the -1x-1
365 const char *p = get(KEY_PREVIEW_SIZE);
366 if (p == 0) return;
367 parse_pair(p, width, height, 'x');
368 }
369
getPreferredPreviewSizeForVideo(int * width,int * height) const370 void CameraParameters::getPreferredPreviewSizeForVideo(int *width, int *height) const
371 {
372 *width = *height = -1;
373 const char *p = get(KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
374 if (p == 0) return;
375 parse_pair(p, width, height, 'x');
376 }
377
getSupportedPreviewSizes(Vector<Size> & sizes) const378 void CameraParameters::getSupportedPreviewSizes(Vector<Size> &sizes) const
379 {
380 const char *previewSizesStr = get(KEY_SUPPORTED_PREVIEW_SIZES);
381 parseSizesList(previewSizesStr, sizes);
382 }
383
setVideoSize(int width,int height)384 void CameraParameters::setVideoSize(int width, int height)
385 {
386 char str[32];
387 sprintf(str, "%dx%d", width, height);
388 set(KEY_VIDEO_SIZE, str);
389 }
390
getVideoSize(int * width,int * height) const391 void CameraParameters::getVideoSize(int *width, int *height) const
392 {
393 *width = *height = -1;
394 const char *p = get(KEY_VIDEO_SIZE);
395 if (p == 0) return;
396 parse_pair(p, width, height, 'x');
397 }
398
getSupportedVideoSizes(Vector<Size> & sizes) const399 void CameraParameters::getSupportedVideoSizes(Vector<Size> &sizes) const
400 {
401 const char *videoSizesStr = get(KEY_SUPPORTED_VIDEO_SIZES);
402 parseSizesList(videoSizesStr, sizes);
403 }
404
setPreviewFrameRate(int fps)405 void CameraParameters::setPreviewFrameRate(int fps)
406 {
407 set(KEY_PREVIEW_FRAME_RATE, fps);
408 }
409
getPreviewFrameRate() const410 int CameraParameters::getPreviewFrameRate() const
411 {
412 return getInt(KEY_PREVIEW_FRAME_RATE);
413 }
414
getPreviewFpsRange(int * min_fps,int * max_fps) const415 void CameraParameters::getPreviewFpsRange(int *min_fps, int *max_fps) const
416 {
417 *min_fps = *max_fps = -1;
418 const char *p = get(KEY_PREVIEW_FPS_RANGE);
419 if (p == 0) return;
420 parse_pair(p, min_fps, max_fps, ',');
421 }
422
setPreviewFormat(const char * format)423 void CameraParameters::setPreviewFormat(const char *format)
424 {
425 set(KEY_PREVIEW_FORMAT, format);
426 }
427
getPreviewFormat() const428 const char *CameraParameters::getPreviewFormat() const
429 {
430 return get(KEY_PREVIEW_FORMAT);
431 }
432
setPictureSize(int width,int height)433 void CameraParameters::setPictureSize(int width, int height)
434 {
435 char str[32];
436 sprintf(str, "%dx%d", width, height);
437 set(KEY_PICTURE_SIZE, str);
438 }
439
getPictureSize(int * width,int * height) const440 void CameraParameters::getPictureSize(int *width, int *height) const
441 {
442 *width = *height = -1;
443 // Get the current string, if it doesn't exist, leave the -1x-1
444 const char *p = get(KEY_PICTURE_SIZE);
445 if (p == 0) return;
446 parse_pair(p, width, height, 'x');
447 }
448
getSupportedPictureSizes(Vector<Size> & sizes) const449 void CameraParameters::getSupportedPictureSizes(Vector<Size> &sizes) const
450 {
451 const char *pictureSizesStr = get(KEY_SUPPORTED_PICTURE_SIZES);
452 parseSizesList(pictureSizesStr, sizes);
453 }
454
setPictureFormat(const char * format)455 void CameraParameters::setPictureFormat(const char *format)
456 {
457 set(KEY_PICTURE_FORMAT, format);
458 }
459
getPictureFormat() const460 const char *CameraParameters::getPictureFormat() const
461 {
462 return get(KEY_PICTURE_FORMAT);
463 }
464
dump() const465 void CameraParameters::dump() const
466 {
467 ALOGD("dump: mMap.size = %zu", mMap.size());
468 for (size_t i = 0; i < mMap.size(); i++) {
469 String8 k, v;
470 k = mMap.keyAt(i);
471 v = mMap.valueAt(i);
472 ALOGD("%s: %s\n", k.string(), v.string());
473 }
474 }
475
dump(int fd,const Vector<String16> &) const476 status_t CameraParameters::dump(int fd, const Vector<String16>& /*args*/) const
477 {
478 const size_t SIZE = 256;
479 char buffer[SIZE];
480 String8 result;
481 snprintf(buffer, 255, "CameraParameters::dump: mMap.size = %zu\n", mMap.size());
482 result.append(buffer);
483 for (size_t i = 0; i < mMap.size(); i++) {
484 String8 k, v;
485 k = mMap.keyAt(i);
486 v = mMap.valueAt(i);
487 snprintf(buffer, 255, "\t%s: %s\n", k.string(), v.string());
488 result.append(buffer);
489 }
490 write(fd, result.string(), result.size());
491 return NO_ERROR;
492 }
493
getSupportedPreviewFormats(Vector<int> & formats) const494 void CameraParameters::getSupportedPreviewFormats(Vector<int>& formats) const {
495 const char* supportedPreviewFormats =
496 get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS);
497
498 if (supportedPreviewFormats == NULL) {
499 ALOGW("%s: No supported preview formats.", __FUNCTION__);
500 return;
501 }
502
503 String8 fmtStr(supportedPreviewFormats);
504 char* prevFmts = fmtStr.lockBuffer(fmtStr.size());
505
506 char* savePtr;
507 char* fmt = strtok_r(prevFmts, ",", &savePtr);
508 while (fmt) {
509 int actual = previewFormatToEnum(fmt);
510 if (actual != -1) {
511 formats.add(actual);
512 }
513 fmt = strtok_r(NULL, ",", &savePtr);
514 }
515 fmtStr.unlockBuffer(fmtStr.size());
516 }
517
518
previewFormatToEnum(const char * format)519 int CameraParameters::previewFormatToEnum(const char* format) {
520 return
521 !format ?
522 HAL_PIXEL_FORMAT_YCrCb_420_SP :
523 !strcmp(format, PIXEL_FORMAT_YUV422SP) ?
524 HAL_PIXEL_FORMAT_YCbCr_422_SP : // NV16
525 !strcmp(format, PIXEL_FORMAT_YUV420SP) ?
526 HAL_PIXEL_FORMAT_YCrCb_420_SP : // NV21
527 !strcmp(format, PIXEL_FORMAT_YUV422I) ?
528 HAL_PIXEL_FORMAT_YCbCr_422_I : // YUY2
529 !strcmp(format, PIXEL_FORMAT_YUV420P) ?
530 HAL_PIXEL_FORMAT_YV12 : // YV12
531 !strcmp(format, PIXEL_FORMAT_RGB565) ?
532 HAL_PIXEL_FORMAT_RGB_565 : // RGB565
533 !strcmp(format, PIXEL_FORMAT_RGBA8888) ?
534 HAL_PIXEL_FORMAT_RGBA_8888 : // RGB8888
535 !strcmp(format, PIXEL_FORMAT_BAYER_RGGB) ?
536 HAL_PIXEL_FORMAT_RAW16 : // Raw sensor data
537 -1;
538 }
539
isEmpty() const540 bool CameraParameters::isEmpty() const {
541 return mMap.isEmpty();
542 }
543
544 };
545 };
546 };
547 };
548 };
549 }; // namespace android
550