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