CameraParameters.cpp 19 KB

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