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