• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright (c) 2012, The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above
10       copyright notice, this list of conditions and the following
11       disclaimer in the documentation and/or other materials provided
12       with the distribution.
13     * Neither the name of The Linux Foundation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 
31 #define LOG_TAG "QCameraParams"
32 #include <utils/Log.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #include <camera/QCameraParameters.h>
36 
37 namespace android {
38 // Parameter keys to communicate between camera application and driver.
39 const char QCameraParameters::KEY_QC_SUPPORTED_HFR_SIZES[] = "hfr-size-values";
40 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_MODE[] = "preview-frame-rate-mode";
41 const char QCameraParameters::KEY_QC_SUPPORTED_PREVIEW_FRAME_RATE_MODES[] = "preview-frame-rate-modes";
42 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_AUTO_MODE[] = "frame-rate-auto";
43 const char QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_FIXED_MODE[] = "frame-rate-fixed";
44 const char QCameraParameters::KEY_QC_TOUCH_AF_AEC[] = "touch-af-aec";
45 const char QCameraParameters::KEY_QC_SUPPORTED_TOUCH_AF_AEC[] = "touch-af-aec-values";
46 const char QCameraParameters::KEY_QC_TOUCH_INDEX_AEC[] = "touch-index-aec";
47 const char QCameraParameters::KEY_QC_TOUCH_INDEX_AF[] = "touch-index-af";
48 const char QCameraParameters::KEY_QC_SCENE_DETECT[] = "scene-detect";
49 const char QCameraParameters::KEY_QC_SUPPORTED_SCENE_DETECT[] = "scene-detect-values";
50 const char QCameraParameters::KEY_QC_ISO_MODE[] = "iso";
51 const char QCameraParameters::KEY_QC_SUPPORTED_ISO_MODES[] = "iso-values";
52 const char QCameraParameters::KEY_QC_LENSSHADE[] = "lensshade";
53 const char QCameraParameters::KEY_QC_SUPPORTED_LENSSHADE_MODES[] = "lensshade-values";
54 const char QCameraParameters::KEY_QC_AUTO_EXPOSURE[] = "auto-exposure";
55 const char QCameraParameters::KEY_QC_SUPPORTED_AUTO_EXPOSURE[] = "auto-exposure-values";
56 const char QCameraParameters::KEY_QC_DENOISE[] = "denoise";
57 const char QCameraParameters::KEY_QC_SUPPORTED_DENOISE[] = "denoise-values";
58 const char QCameraParameters::KEY_QC_SELECTABLE_ZONE_AF[] = "selectable-zone-af";
59 const char QCameraParameters::KEY_QC_SUPPORTED_SELECTABLE_ZONE_AF[] = "selectable-zone-af-values";
60 const char QCameraParameters::KEY_QC_FACE_DETECTION[] = "face-detection";
61 const char QCameraParameters::KEY_QC_SUPPORTED_FACE_DETECTION[] = "face-detection-values";
62 const char QCameraParameters::KEY_QC_MEMORY_COLOR_ENHANCEMENT[] = "mce";
63 const char QCameraParameters::KEY_QC_SUPPORTED_MEM_COLOR_ENHANCE_MODES[] = "mce-values";
64 const char QCameraParameters::KEY_QC_VIDEO_HIGH_FRAME_RATE[] = "video-hfr";
65 const char QCameraParameters::KEY_QC_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES[] = "video-hfr-values";
66 const char QCameraParameters::KEY_QC_REDEYE_REDUCTION[] = "redeye-reduction";
67 const char QCameraParameters::KEY_QC_SUPPORTED_REDEYE_REDUCTION[] = "redeye-reduction-values";
68 const char QCameraParameters::KEY_QC_HIGH_DYNAMIC_RANGE_IMAGING[] = "hdr";
69 const char QCameraParameters::KEY_QC_SUPPORTED_HDR_IMAGING_MODES[] = "hdr-values";
70 const char QCameraParameters::KEY_QC_POWER_MODE_SUPPORTED[] = "power-mode-supported";
71 const char QCameraParameters::KEY_QC_ZSL[] = "zsl";
72 const char QCameraParameters::KEY_QC_SUPPORTED_ZSL_MODES[] = "zsl-values";
73 const char QCameraParameters::KEY_QC_CAMERA_MODE[] = "camera-mode";
74 const char QCameraParameters::KEY_QC_AE_BRACKET_HDR[] = "ae-bracket-hdr";
75 const char QCameraParameters::KEY_QC_POWER_MODE[] = "power-mode";
76 /*only effective when KEY_QC_AE_BRACKET_HDR set to ae_bracketing*/
77 //const char QCameraParameters::KEY_QC_AE_BRACKET_SETTING_KEY[] = "ae-bracket-setting";
78 
79 // Values for effect settings.
80 const char QCameraParameters::EFFECT_EMBOSS[] = "emboss";
81 const char QCameraParameters::EFFECT_SKETCH[] = "sketch";
82 const char QCameraParameters::EFFECT_NEON[] = "neon";
83 
84 // Values for auto exposure settings.
85 const char QCameraParameters::TOUCH_AF_AEC_OFF[] = "touch-off";
86 const char QCameraParameters::TOUCH_AF_AEC_ON[] = "touch-on";
87 
88 // Values for scene mode settings.
89 const char QCameraParameters::SCENE_MODE_ASD[] = "asd";   // corresponds to CAMERA_BESTSHOT_AUTO in HAL
90 const char QCameraParameters::SCENE_MODE_BACKLIGHT[] = "backlight";
91 const char QCameraParameters::SCENE_MODE_FLOWERS[] = "flowers";
92 const char QCameraParameters::SCENE_MODE_AR[] = "AR";
93 
94 // Values for auto scene detection settings.
95 const char QCameraParameters::SCENE_DETECT_OFF[] = "off";
96 const char QCameraParameters::SCENE_DETECT_ON[] = "on";
97 
98 // Formats for setPreviewFormat and setPictureFormat.
99 const char QCameraParameters::PIXEL_FORMAT_YUV420SP_ADRENO[] = "yuv420sp-adreno";
100 const char QCameraParameters::PIXEL_FORMAT_RAW[] = "raw";
101 const char QCameraParameters::PIXEL_FORMAT_YV12[] = "yuv420p";
102 const char QCameraParameters::PIXEL_FORMAT_NV12[] = "nv12";
103 
104 // Values for focus mode settings.
105 const char QCameraParameters::FOCUS_MODE_NORMAL[] = "normal";
106 const char QCameraParameters::KEY_QC_SKIN_TONE_ENHANCEMENT[] = "skinToneEnhancement";
107 const char QCameraParameters::KEY_QC_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES[] = "skinToneEnhancement-values";
108 
109 // Values for ISO Settings
110 const char QCameraParameters::ISO_AUTO[] = "auto";
111 const char QCameraParameters::ISO_HJR[] = "ISO_HJR";
112 const char QCameraParameters::ISO_100[] = "ISO100";
113 const char QCameraParameters::ISO_200[] = "ISO200";
114 const char QCameraParameters::ISO_400[] = "ISO400";
115 const char QCameraParameters::ISO_800[] = "ISO800";
116 const char QCameraParameters::ISO_1600[] = "ISO1600";
117 
118  //Values for Lens Shading
119 const char QCameraParameters::LENSSHADE_ENABLE[] = "enable";
120 const char QCameraParameters::LENSSHADE_DISABLE[] = "disable";
121 
122 // Values for auto exposure settings.
123 const char QCameraParameters::AUTO_EXPOSURE_FRAME_AVG[] = "frame-average";
124 const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED[] = "center-weighted";
125 const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING[] = "spot-metering";
126 
127 const char QCameraParameters::KEY_QC_GPS_LATITUDE_REF[] = "gps-latitude-ref";
128 const char QCameraParameters::KEY_QC_GPS_LONGITUDE_REF[] = "gps-longitude-ref";
129 const char QCameraParameters::KEY_QC_GPS_ALTITUDE_REF[] = "gps-altitude-ref";
130 const char QCameraParameters::KEY_QC_GPS_STATUS[] = "gps-status";
131 const char QCameraParameters::KEY_QC_EXIF_DATETIME[] = "exif-datetime";
132 
133 const char QCameraParameters::KEY_QC_HISTOGRAM[] = "histogram";
134 const char QCameraParameters::KEY_QC_SUPPORTED_HISTOGRAM_MODES[] = "histogram-values";
135 
136 //Values for Histogram Shading
137 const char QCameraParameters::HISTOGRAM_ENABLE[] = "enable";
138 const char QCameraParameters::HISTOGRAM_DISABLE[] = "disable";
139 
140 //Values for Skin Tone Enhancement Modes
141 const char QCameraParameters::SKIN_TONE_ENHANCEMENT_ENABLE[] = "enable";
142 const char QCameraParameters::SKIN_TONE_ENHANCEMENT_DISABLE[] = "disable";
143 
144 const char QCameraParameters::KEY_QC_SHARPNESS[] = "sharpness";
145 const char QCameraParameters::KEY_QC_MAX_SHARPNESS[] = "max-sharpness";
146 const char QCameraParameters::KEY_QC_CONTRAST[] = "contrast";
147 const char QCameraParameters::KEY_QC_MAX_CONTRAST[] = "max-contrast";
148 const char QCameraParameters::KEY_QC_SATURATION[] = "saturation";
149 const char QCameraParameters::KEY_QC_MAX_SATURATION[] = "max-saturation";
150 
151 const char QCameraParameters::KEY_QC_SINGLE_ISP_OUTPUT_ENABLED[] = "single-isp-output-enabled";
152 const char QCameraParameters::KEY_QC_SUPPORTED_CAMERA_FEATURES[] = "qc-camera-features";
153 const char QCameraParameters::KEY_QC_MAX_NUM_REQUESTED_FACES[] = "qc-max-num-requested-faces";
154 
155 //Values for DENOISE
156 const char QCameraParameters::DENOISE_OFF[] = "denoise-off";
157 const char QCameraParameters::DENOISE_ON[] = "denoise-on";
158 
159 // Values for selectable zone af Settings
160 const char QCameraParameters::SELECTABLE_ZONE_AF_AUTO[] = "auto";
161 const char QCameraParameters::SELECTABLE_ZONE_AF_SPOT_METERING[] = "spot-metering";
162 const char QCameraParameters::SELECTABLE_ZONE_AF_CENTER_WEIGHTED[] = "center-weighted";
163 const char QCameraParameters::SELECTABLE_ZONE_AF_FRAME_AVERAGE[] = "frame-average";
164 
165 // Values for Face Detection settings.
166 const char QCameraParameters::FACE_DETECTION_OFF[] = "off";
167 const char QCameraParameters::FACE_DETECTION_ON[] = "on";
168 
169 // Values for MCE settings.
170 const char QCameraParameters::MCE_ENABLE[] = "enable";
171 const char QCameraParameters::MCE_DISABLE[] = "disable";
172 
173 // Values for HFR settings.
174 const char QCameraParameters::VIDEO_HFR_OFF[] = "off";
175 const char QCameraParameters::VIDEO_HFR_2X[] = "60";
176 const char QCameraParameters::VIDEO_HFR_3X[] = "90";
177 const char QCameraParameters::VIDEO_HFR_4X[] = "120";
178 
179 // Values for Redeye Reduction settings.
180 const char QCameraParameters::REDEYE_REDUCTION_ENABLE[] = "enable";
181 const char QCameraParameters::REDEYE_REDUCTION_DISABLE[] = "disable";
182 
183 // Values for HDR settings.
184 const char QCameraParameters::HDR_ENABLE[] = "enable";
185 const char QCameraParameters::HDR_DISABLE[] = "disable";
186 
187 // Values for ZSL settings.
188 const char QCameraParameters::ZSL_OFF[] = "off";
189 const char QCameraParameters::ZSL_ON[] = "on";
190 
191 // Values for HDR Bracketing settings.
192 const char QCameraParameters::AE_BRACKET_HDR_OFF[] = "Off";
193 const char QCameraParameters::AE_BRACKET_HDR[] = "HDR";
194 const char QCameraParameters::AE_BRACKET[] = "AE-Bracket";
195 
196 const char QCameraParameters::LOW_POWER[] = "Low_Power";
197 const char QCameraParameters::NORMAL_POWER[] = "Normal_Power";
198 
199 static const char* portrait = "portrait";
200 static const char* landscape = "landscape";
201 
202 //QCameraParameters::QCameraParameters()
203 //                : mMap()
204 //{
205 //}
206 
~QCameraParameters()207 QCameraParameters::~QCameraParameters()
208 {
209 }
210 
getOrientation() const211 int QCameraParameters::getOrientation() const
212 {
213     const char* orientation = get("orientation");
214     if (orientation && !strcmp(orientation, portrait))
215         return CAMERA_ORIENTATION_PORTRAIT;
216     return CAMERA_ORIENTATION_LANDSCAPE;
217 }
setOrientation(int orientation)218 void QCameraParameters::setOrientation(int orientation)
219 {
220     if (orientation == CAMERA_ORIENTATION_PORTRAIT) {
221         set("orientation", portrait);
222     } else {
223          set("orientation", landscape);
224     }
225 }
226 
227         //XXX ALOGE("Key \"%s\"contains invalid character (= or ;)", key);
228         //XXX ALOGE("Value \"%s\"contains invalid character (= or ;)", value);
229     //snprintf(str, sizeof(str), "%d", value);
230         //ALOGE("Cannot find delimeter (%c) in str=%s", delim, str);
231 
232 
233 // Parse string like "(1, 2, 3, 4, ..., N)"
234 // num is pointer to an allocated array of size N
parseNDimVector(const char * str,int * num,int N,char delim=',')235 static int parseNDimVector(const char *str, int *num, int N, char delim = ',')
236 {
237     char *start, *end;
238     if(num == NULL) {
239         ALOGE("Invalid output array (num == NULL)");
240         return -1;
241     }
242     //check if string starts and ends with parantheses
243     if(str[0] != '(' || str[strlen(str)-1] != ')') {
244         ALOGE("Invalid format of string %s, valid format is (n1, n2, n3, n4 ...)", str);
245         return -1;
246     }
247     start = (char*) str;
248     start++;
249     for(int i=0; i<N; i++) {
250         *(num+i) = (int) strtol(start, &end, 10);
251         if(*end != delim && i < N-1) {
252             ALOGE("Cannot find delimeter '%c' in string \"%s\". end = %c", delim, str, *end);
253             return -1;
254         }
255         start = end+1;
256     }
257     return 0;
258 }
259 
260 
261             //ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
262     //snprintf(str, sizeof(str), "%dx%d", width, height);
263 
264 
265 
266 // Parse string like "640x480" or "10000,20000"
parse_pair(const char * str,int * first,int * second,char delim,char ** endptr=NULL)267 static int parse_pair(const char *str, int *first, int *second, char delim,
268                       char **endptr = NULL)
269 {
270     // Find the first integer.
271     char *end;
272     int w = (int)strtol(str, &end, 10);
273     // If a delimeter does not immediately follow, give up.
274     if (*end != delim) {
275         ALOGE("Cannot find delimeter (%c) in str=%s", delim, str);
276         return -1;
277     }
278 
279     // Find the second integer, immediately after the delimeter.
280     int h = (int)strtol(end+1, &end, 10);
281 
282     *first = w;
283     *second = h;
284 
285     if (endptr) {
286         *endptr = end;
287     }
288 
289     return 0;
290 }
291 
parseSizesList(const char * sizesStr,Vector<Size> & sizes)292 static void parseSizesList(const char *sizesStr, Vector<Size> &sizes)
293 {
294     if (sizesStr == 0) {
295         return;
296     }
297 
298     char *sizeStartPtr = (char *)sizesStr;
299 
300     while (true) {
301         int width, height;
302         int success = parse_pair(sizeStartPtr, &width, &height, 'x',
303                                  &sizeStartPtr);
304         if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
305             ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
306             return;
307         }
308         sizes.push(Size(width, height));
309 
310         if (*sizeStartPtr == '\0') {
311             return;
312         }
313         sizeStartPtr++;
314     }
315 }
316 
317 
getSupportedHfrSizes(Vector<Size> & sizes) const318 void QCameraParameters::getSupportedHfrSizes(Vector<Size> &sizes) const
319 {
320     const char *hfrSizesStr = get(KEY_QC_SUPPORTED_HFR_SIZES);
321     parseSizesList(hfrSizesStr, sizes);
322 }
323 
setPreviewFpsRange(int minFPS,int maxFPS)324 void QCameraParameters::setPreviewFpsRange(int minFPS, int maxFPS)
325 {
326     char str[32];
327     snprintf(str, sizeof(str), "%d,%d",minFPS,maxFPS);
328     set(KEY_PREVIEW_FPS_RANGE,str);
329 }
330 
setPreviewFrameRateMode(const char * mode)331 void QCameraParameters::setPreviewFrameRateMode(const char *mode)
332 {
333     set(KEY_QC_PREVIEW_FRAME_RATE_MODE, mode);
334 }
335 
getPreviewFrameRateMode() const336 const char *QCameraParameters::getPreviewFrameRateMode() const
337 {
338     return get(KEY_QC_PREVIEW_FRAME_RATE_MODE);
339 }
340 
341     //ALOGD("dump: mMap.size = %d", mMap.size());
342         //ALOGD("%s: %s\n", k.string(), v.string());
setTouchIndexAec(int x,int y)343 void QCameraParameters::setTouchIndexAec(int x, int y)
344 {
345     char str[32];
346     snprintf(str, sizeof(str), "%dx%d", x, y);
347     set(KEY_QC_TOUCH_INDEX_AEC, str);
348 }
349 
getTouchIndexAec(int * x,int * y) const350 void QCameraParameters::getTouchIndexAec(int *x, int *y) const
351 {
352     *x = -1;
353     *y = -1;
354 
355     // Get the current string, if it doesn't exist, leave the -1x-1
356     const char *p = get(KEY_QC_TOUCH_INDEX_AEC);
357     if (p == 0)
358         return;
359 
360     int tempX, tempY;
361     if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
362         *x = tempX;
363         *y = tempY;
364     }
365 }
366 
setTouchIndexAf(int x,int y)367 void QCameraParameters::setTouchIndexAf(int x, int y)
368 {
369     char str[32];
370     snprintf(str, sizeof(str), "%dx%d", x, y);
371     set(KEY_QC_TOUCH_INDEX_AF, str);
372 }
373 
getTouchIndexAf(int * x,int * y) const374 void QCameraParameters::getTouchIndexAf(int *x, int *y) const
375 {
376     *x = -1;
377     *y = -1;
378 
379     // Get the current string, if it doesn't exist, leave the -1x-1
380     const char *p = get(KEY_QC_TOUCH_INDEX_AF);
381     if (p == 0)
382         return;
383 
384     int tempX, tempY;
385     if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
386         *x = tempX;
387         *y = tempY;
388 	}
389 }
390 
getMeteringAreaCenter(int * x,int * y) const391 void QCameraParameters::getMeteringAreaCenter(int *x, int *y) const
392 {
393     //Default invalid values
394     *x = -2000;
395     *y = -2000;
396 
397     const char *p = get(KEY_METERING_AREAS);
398     if(p != NULL) {
399         int arr[5] = {-2000, -2000, -2000, -2000, 0};
400         parseNDimVector(p, arr, 5); //p = "(x1, y1, x2, y2, weight)"
401         *x = (arr[0] + arr[2])/2; //center_x = (x1+x2)/2
402         *y = (arr[1] + arr[3])/2; //center_y = (y1+y2)/2
403     }
404 }
405 
406 
407 }; // namespace android
408 
409