1 /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 //#define ALOG_NDEBUG 0
30 #define ALOG_NIDEBUG 0
31 #define LOG_TAG "QCameraUsbParm"
32 #include <utils/Log.h>
33 
34 #include <utils/Errors.h>
35 #include <utils/threads.h>
36 #include <utils/String16.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <unistd.h>
40 #include <fcntl.h>
41 #include <cutils/properties.h>
42 #include <math.h>
43 #if HAVE_ANDROID_OS
44 #include <linux/android_pmem.h>
45 #endif
46 #include <linux/ioctl.h>
47 #include <camera/QCameraParameters.h>
48 #include <media/mediarecorder.h>
49 #include <gralloc_priv.h>
50 
51 #include "linux/msm_mdp.h"
52 #include <linux/fb.h>
53 #include <limits.h>
54 
55 
56 extern "C" {
57 #include <fcntl.h>
58 #include <time.h>
59 #include <pthread.h>
60 #include <stdio.h>
61 #include <string.h>
62 #include <unistd.h>
63 #include <termios.h>
64 #include <assert.h>
65 #include <stdlib.h>
66 #include <ctype.h>
67 #include <signal.h>
68 #include <errno.h>
69 #include <sys/mman.h>
70 #include <sys/system_properties.h>
71 #include <sys/time.h>
72 #include <stdlib.h>
73 #include <linux/msm_ion.h>
74 #include <camera.h>
75 #include <cam_fifo.h>
76 #include <jpege.h>
77 
78 } // extern "C"
79 
80 #include "QCameraHWI.h"
81 #include "QualcommUsbCamera.h"
82 #include "QCameraUsbPriv.h"
83 #include "QCameraUsbParm.h"
84 
85 namespace android {
86 
87 /********************************************************************/
88 static const str_map preview_formats[] = {
89     {QCameraParameters::PIXEL_FORMAT_YUV420SP, HAL_PIXEL_FORMAT_YCrCb_420_SP},
90 };
91 
92 static const preview_format_info_t preview_format_info_list[] = {
93     {HAL_PIXEL_FORMAT_YV12, CAMERA_YUV_420_YV12, CAMERA_PAD_TO_WORD, 3}
94 };
95 
96 static struct camera_size_type previewSizes[] = {
97     { 1920, 1088}, //1080p
98     { 1280, 720}, // 720P,
99     { 640, 480}, // VGA
100     { 512, 384},
101     { 480, 320},
102     { 320, 240}, // QVGA
103 };
104 
105 // All fps ranges which can be supported. This list will be filtered according
106 // to the min and max fps supported by hardware
107 // this list must be sorted first by max_fps and then min_fps
108 // fps values are multiplied by 1000
109 static android::FPSRange prevFpsRanges[] = {
110     android::FPSRange(5000, 121000),
111 };
112 
113 /* TBR: Is frame rate mode mandatory */
114 static const str_map frame_rate_modes[] = {
115     {QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_AUTO_MODE, FPS_MODE_AUTO},
116     {QCameraParameters::KEY_QC_PREVIEW_FRAME_RATE_FIXED_MODE, FPS_MODE_FIXED}
117 };
118 
119 static const str_map picture_formats[] = {
120     {QCameraParameters::PIXEL_FORMAT_JPEG, PICTURE_FORMAT_JPEG},
121     //{QCameraParameters::PIXEL_FORMAT_RAW, PICTURE_FORMAT_RAW}
122 };
123 
124 static camera_size_type picture_sizes[] = {
125     { 1920, 1088}, //HD1080
126     { 1280, 720}, //HD720
127     { 640, 480}, // VGA
128     { 320, 240}, // QVGA
129 };
130 
131 /* aspect ratio removed */
132 static camera_size_type thumbnail_sizes[] = {
133     { 512, 288 }, //1.777778
134     { 480, 288 }, //1.666667
135     { 256, 154 }, //1.66233
136     { 432, 288 }, //1.5
137     { 512, 384 }, //1.333333
138     { 352, 288 }, //1.222222
139     { 320, 240 }, //1.33333
140     { 176, 144 }, //1.222222
141 };
142 
143 static const str_map recording_Hints[] = {
144     {"false", FALSE},
145     {"true",  TRUE}
146 };
147 
148 /* Static functions list */
149 static String8 create_sizes_str(const camera_size_type *sizes, int len);
150 static String8 create_values_str(const str_map *values, int len);
151 static String8 create_fps_str(const android:: FPSRange* fps, int len);
152 static String8 create_values_range_str(int min, int max);
153 static int usbCamSetPrvwSize(   camera_hardware_t           *camHal,
154                                 const QCameraParameters&    params);
155 static int usbCamSetPictSize(   camera_hardware_t           *camHal,
156                                 const QCameraParameters&    params);
157 static int usbCamSetThumbnailSize(  camera_hardware_t           *camHal,
158                                     const QCameraParameters&    params);
159 static int usbCamSetJpegQlty(   camera_hardware_t           *camHal,
160                                 const QCameraParameters&    params);
161 
162 /******************************************************************************
163  * Function: usbCamInitDefaultParameters
164  * Description: This function sets default parameters to camera HAL context
165  *
166  * Input parameters:
167  *   camHal              - camera HAL handle
168  *
169  * Return values:
170  *      None
171  *
172  * Notes: none
173  *****************************************************************************/
usbCamInitDefaultParameters(camera_hardware_t * camHal)174 int usbCamInitDefaultParameters(camera_hardware_t *camHal)
175 {
176     ALOGD("%s: E", __func__);
177     int rc = 0;
178     char tempStr[FILENAME_LENGTH];
179 
180     /* Default initializations */
181     camHal->prevFormat          = DEFAULT_USBCAM_PRVW_FMT;
182     camHal->prevWidth           = DEFAULT_USBCAM_PRVW_WD;
183     camHal->prevHeight          = DEFAULT_USBCAM_PRVW_HT;
184     camHal->dispFormat          = camHal->prevFormat;
185     camHal->dispWidth           = camHal->prevWidth;
186     camHal->dispHeight          = camHal->prevHeight;
187     camHal->pictFormat          = DEFAULT_USBCAM_PICT_FMT;
188     camHal->pictWidth           = DEFAULT_USBCAM_PICT_WD;
189     camHal->pictHeight          = DEFAULT_USBCAM_PICT_HT;
190     camHal->pictJpegQlty        = DEFAULT_USBCAM_PICT_QLTY;
191     camHal->thumbnailWidth      = DEFAULT_USBCAM_THUMBNAIL_WD;
192     camHal->thumbnailHeight     = DEFAULT_USBCAM_THUMBNAIL_HT;
193     camHal->thumbnailJpegQlty   = DEFAULT_USBCAM_THUMBNAIL_QLTY;
194     camHal->previewEnabledFlag  = 0;
195     camHal->prvwStoppedForPicture = 0;
196     camHal->prvwCmdPending      = 0;
197     camHal->takePictInProgress  = 0;
198 
199     //Set picture size values
200     camHal->pictSizeValues = create_sizes_str(
201         picture_sizes, sizeof(picture_sizes) / sizeof(camera_size_type));
202     camHal->qCamParams.set(QCameraParameters::KEY_SUPPORTED_PICTURE_SIZES,
203         camHal->pictSizeValues.string());
204     camHal->qCamParams.setPictureSize(camHal->pictWidth, camHal->pictHeight);
205 
206     //Set picture format
207     camHal->pictFormatValues = create_values_str(
208         picture_formats, sizeof(picture_formats) / sizeof(str_map));
209     camHal->qCamParams.set(QCameraParameters::KEY_SUPPORTED_PICTURE_FORMATS,
210                     camHal->pictFormatValues.string());
211     if(PICTURE_FORMAT_JPEG == camHal->pictFormat)
212         camHal->qCamParams.setPictureFormat(QCameraParameters::PIXEL_FORMAT_JPEG);
213 
214     //Set picture quality
215     sprintf(tempStr, "%d", camHal->pictJpegQlty);
216     camHal->qCamParams.set(QCameraParameters::KEY_JPEG_QUALITY, tempStr);
217 
218     //Set Thumbnail size
219     camHal->thumbnailSizeValues = create_sizes_str(
220         thumbnail_sizes, sizeof(thumbnail_sizes) /sizeof(camera_size_type));
221     camHal->qCamParams.set(QCameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES,
222                     camHal->thumbnailSizeValues.string());
223     sprintf(tempStr, "%d", camHal->thumbnailWidth);
224     camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_WIDTH,
225                                                 tempStr);
226     sprintf(tempStr, "%d", camHal->thumbnailHeight);
227     camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT,
228                                                 tempStr);
229 
230     //Set Thumbnail quality
231     sprintf(tempStr, "%d", camHal->thumbnailJpegQlty);
232     camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_QUALITY,
233                                                 tempStr);
234 
235     //Set Preview Format
236     camHal->prevFormatValues = create_values_str(
237         preview_formats, sizeof(preview_formats) / sizeof(str_map));
238     camHal->qCamParams.set(QCameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS,
239         camHal->prevFormatValues.string());
240     if(HAL_PIXEL_FORMAT_YCrCb_420_SP == camHal->prevFormat)
241         camHal->qCamParams.setPreviewFormat(QCameraParameters::PIXEL_FORMAT_YUV420SP);
242 
243     //Set Preview size
244     camHal->prevSizeValues = create_sizes_str(
245         previewSizes,  sizeof(previewSizes) / sizeof(camera_size_type));
246     camHal->qCamParams.set(QCameraParameters::KEY_SUPPORTED_PREVIEW_SIZES,
247                     camHal->prevSizeValues.string());
248     camHal->qCamParams.setPreviewSize(camHal->prevWidth, camHal->prevHeight);
249 
250     //Set Preivew fps range
251     camHal->prevFpsRangesValues = create_fps_str(
252         prevFpsRanges, sizeof(prevFpsRanges) / sizeof(android::FPSRange));
253 
254     camHal->qCamParams.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE,
255                         camHal->prevFpsRangesValues);
256     camHal->qCamParams.setPreviewFpsRange(MIN_PREV_FPS, MAX_PREV_FPS);
257 
258     ALOGD("%s: X", __func__);
259 
260     return rc;
261 } /* usbCamInitDefaultParameters */
262 
263 /******************************************************************************
264  * Function: usbCamSetParameters
265  * Description: This function parses the parameter string and stores the
266  *              parameters in the camera HAL handle
267  *
268  * Input parameters:
269  *  camHal              - camera HAL handle
270  *  params              - pointer to parameter string
271  *
272  * Return values:
273  *      0   Success
274  *      -1  Error
275  * Notes: none
276  *****************************************************************************/
usbCamSetParameters(camera_hardware_t * camHal,const char * params)277 int usbCamSetParameters(camera_hardware_t *camHal, const char *params)
278 {
279     int             rc      = 0;
280     String8         str     = String8(params);
281     QCameraParameters qParam;
282 
283     ALOGD("%s: E", __func__);
284 
285     if(params)
286         PRINT_PARAM_STR(params);
287 
288     qParam.unflatten(str);
289 
290     if(usbCamSetPrvwSize(camHal, qParam))
291         rc = -1;
292     if(usbCamSetPictSize(camHal, qParam))
293         rc = -1;
294     if(usbCamSetThumbnailSize(camHal, qParam))
295         rc = -1;
296     if(usbCamSetJpegQlty(camHal, qParam))
297         rc = -1;
298 
299     ALOGD("%s: X", __func__);
300     return rc;
301 } /* usbCamSetParameters */
302 
303 /******************************************************************************
304  * Function: usbCamGetParameters
305  * Description: This function allocates memory for parameter string,
306  *              composes and returns the parameter string
307  *
308  * Input parameters:
309  *   camHal             - camera HAL handle
310  *
311  * Return values:
312  *      Address to the parameter string
313  *
314  * Notes: none
315  *****************************************************************************/
usbCamGetParameters(camera_hardware_t * camHal)316 char* usbCamGetParameters(camera_hardware_t *camHal)
317 {
318     ALOGD("%s: E", __func__);
319     char *parms = NULL;
320     char* rc = NULL;
321     String8 str;
322 
323     QCameraParameters qParam = camHal->qCamParams;
324     //qParam.dump();
325     str = qParam.flatten( );
326     rc = (char *)malloc(sizeof(char)*(str.length()+1));
327     if(rc != NULL){
328         memset(rc, 0, sizeof(char)*(str.length()+1));
329         strncpy(rc, str.string(), str.length());
330     rc[str.length()] = 0;
331     parms = rc;
332     }
333 
334     PRINT_PARAM_STR(parms);
335 
336     ALOGD("%s: X", __func__);
337     return (parms);
338 } /* usbCamGetParameters */
339 
340 /******************************************************************************
341  * Function: usbCamPutParameters
342  * Description: This function frees the memory allocated for parameter string
343  *
344  * Input parameters:
345  *  camHal              - camera HAL handle
346  *  parms               - Parameter string
347  *
348  * Return values:
349  *      None
350  *
351  * Notes: none
352  *****************************************************************************/
usbCamPutParameters(camera_hardware_t * camHal,char * parms)353 void usbCamPutParameters(camera_hardware_t *camHal, char *parms)
354 {
355     ALOGD("%s: E", __func__);
356     if(parms)
357         free(parms);
358     parms = NULL;
359     ALOGD("%s: X", __func__);
360 } /* usbCamPutParameters */
361 
362 /******************************************************************************
363  * Function: create_sizes_str
364  * Description: This function loops through /dev/video entries and probes with
365  *              UVCIOC query. If the device responds to the query, then it is
366  *              detected as UVC webcam
367  * Input parameters:
368  *   devname             - String pointer. The function return dev entry
369  *                          name in this string
370  * Return values:
371  *      0   Success
372  *      -1  Error
373  * Notes: none
374  *****************************************************************************/
create_sizes_str(const camera_size_type * sizes,int len)375 static String8 create_sizes_str(const camera_size_type *sizes, int len) {
376     String8 str;
377     char buffer[32];
378 
379     if (len > 0) {
380         snprintf(buffer, sizeof(buffer), "%dx%d", sizes[0].width, sizes[0].height);
381         str.append(buffer);
382     }
383     for (int i = 1; i < len; i++) {
384         snprintf(buffer, sizeof(buffer), ",%dx%d", sizes[i].width, sizes[i].height);
385         str.append(buffer);
386     }
387     return str;
388 }
389 
390 /******************************************************************************
391  * Function: create_values_str
392  * Description: This function loops through /dev/video entries and probes with
393  *              UVCIOC query. If the device responds to the query, then it is
394  *              detected as UVC webcam
395  * Input parameters:
396  *   devname             - String pointer. The function return dev entry
397  *                          name in this string
398  * Return values:
399  *      0   Success
400  *      -1  Error
401  * Notes: none
402  *****************************************************************************/
create_values_str(const str_map * values,int len)403 static String8 create_values_str(const str_map *values, int len) {
404     String8 str;
405 
406     if (len > 0) {
407         str.append(values[0].desc);
408     }
409     for (int i = 1; i < len; i++) {
410         str.append(",");
411         str.append(values[i].desc);
412     }
413     return str;
414 }
415 
416 /******************************************************************************
417  * Function: create_fps_str
418  * Description: This function loops through /dev/video entries and probes with
419  *              UVCIOC query. If the device responds to the query, then it is
420  *              detected as UVC webcam
421  * Input parameters:
422  *   devname             - String pointer. The function return dev entry
423  *                          name in this string
424  * Return values:
425  *      0   Success
426  *      -1  Error
427  * Notes: none
428  *****************************************************************************/
create_fps_str(const android::FPSRange * fps,int len)429 static String8 create_fps_str(const android:: FPSRange* fps, int len) {
430     String8 str;
431     char buffer[32];
432 
433     if (len > 0) {
434         snprintf(buffer, sizeof(buffer), "(%d,%d)", fps[0].minFPS, fps[0].maxFPS);
435         str.append(buffer);
436     }
437     for (int i = 1; i < len; i++) {
438         snprintf(buffer, sizeof(buffer), ",(%d,%d)", fps[i].minFPS, fps[i].maxFPS);
439         str.append(buffer);
440     }
441     return str;
442 }
443 
444 /******************************************************************************
445  * Function: create_values_range_str
446  * Description: This function loops through /dev/video entries and probes with
447  *              UVCIOC query. If the device responds to the query, then it is
448  *              detected as UVC webcam
449  * Input parameters:
450  *   devname             - String pointer. The function return dev entry
451  *                          name in this string
452  * Return values:
453  *      0   Success
454  *      -1  Error
455  * Notes: none
456  *****************************************************************************/
create_values_range_str(int min,int max)457 static String8 create_values_range_str(int min, int max){
458     String8 str;
459     char buffer[32];
460 
461     if(min <= max){
462         snprintf(buffer, sizeof(buffer), "%d", min);
463         str.append(buffer);
464 
465         for (int i = min + 1; i <= max; i++) {
466             snprintf(buffer, sizeof(buffer), ",%d", i);
467             str.append(buffer);
468         }
469     }
470     return str;
471 }
472 
473 /******************************************************************************
474  * Function: usbCamSetPrvwSize
475  * Description: This function parses preview width and height from the input
476  *              parameters and stores into the context
477  *
478  * Input parameters:
479  *  camHal              - camera HAL handle
480  *  params              - QCameraParameters reference
481  *
482  * Return values:
483  *      0   If parameters are valid
484  *      -1  If parameters are invalid
485  *
486  * Notes: none
487  *****************************************************************************/
usbCamSetPrvwSize(camera_hardware_t * camHal,const QCameraParameters & params)488 static int usbCamSetPrvwSize(   camera_hardware_t           *camHal,
489                                 const QCameraParameters&    params)
490 {
491     int rc = 0, width, height, i, numPrvwSizes, validSize;
492     ALOGD("%s: E", __func__);
493 
494     params.getPreviewSize(&width, &height);
495     ALOGI("%s: Requested preview size %d x %d", __func__, width, height);
496 
497     // Validate the preview size
498     numPrvwSizes = sizeof(previewSizes) / sizeof(camera_size_type);
499     for (i = 0, validSize = 0; i <  numPrvwSizes; i++) {
500         if (width ==  previewSizes[i].width
501            && height ==  previewSizes[i].height) {
502             validSize = 1;
503 
504             camHal->qCamParams.setPreviewSize(width, height);
505             ALOGD("%s: setPreviewSize:  width: %d   height: %d",
506                 __func__, width, height);
507 
508             camHal->prevWidth   = width;
509             camHal->prevHeight  = height;
510             camHal->dispWidth   = width;
511             camHal->dispHeight  = height;
512 
513             /* TBD: restrict pictures size and video to preview size */
514         }
515     }
516     if(!validSize)
517         ALOGE("%s: Invalid preview size %dx%d requested", __func__,
518             width, height);
519 
520     rc = (validSize == 0)? -1:0;
521     ALOGD("%s: X", __func__);
522 
523     return rc;
524 } /* usbCamSetPrvwSize */
525 
526 /******************************************************************************
527  * Function: usbCamSetPictSize
528  * Description: This function parses picture width and height from the input
529  *              parameters and stores into the context
530  *
531  * Input parameters:
532  *  camHal              - camera HAL handle
533  *  params              - QCameraParameters reference
534  *
535  * Return values:
536  *      0   If parameters are valid
537  *      -1  If parameters are invalid
538  *
539  * Notes: none
540  *****************************************************************************/
usbCamSetPictSize(camera_hardware_t * camHal,const QCameraParameters & params)541 static int usbCamSetPictSize(   camera_hardware_t           *camHal,
542                                 const QCameraParameters&    params)
543 {
544     int rc = 0, width, height, i, numPictSizes, validSize;
545     ALOGD("%s: E", __func__);
546 
547     /* parse for picture width and height */
548     params.getPictureSize(&width, &height);
549     ALOGI("%s: Requested picture size %d x %d", __func__, width, height);
550 
551     // Validate the picture size
552     numPictSizes = sizeof(picture_sizes) / sizeof(camera_size_type);
553     for (i = 0, validSize = 0; i <  numPictSizes; i++) {
554         if (width ==  picture_sizes[i].width
555            && height ==  picture_sizes[i].height) {
556             validSize = 1;
557 
558             camHal->qCamParams.setPictureSize(width, height);
559             ALOGD("%s: setPictureSize:  width: %d   height: %d",
560                 __func__, width, height);
561 
562             /* TBD: If new pictSize is different from old size, restart prvw */
563             camHal->pictWidth   = width;
564             camHal->pictHeight  = height;
565         }
566     }
567     if(!validSize)
568         ALOGE("%s: Invalid picture size %dx%d requested", __func__,
569             width, height);
570     rc = (validSize == 0)? -1:0;
571     ALOGD("%s: X", __func__);
572 
573     return rc;
574 } /* usbCamSetPictSize */
575 
576 /******************************************************************************
577  * Function: usbCamSetThumbnailSize
578  * Description: This function parses picture width and height from the input
579  *              parameters and stores into the context
580  *
581  * Input parameters:
582  *  camHal              - camera HAL handle
583  *  params              - QCameraParameters reference
584  *
585  * Return values:
586  *      0   If parameters are valid
587  *      -1  If parameters are invalid
588  *
589  * Notes: none
590  *****************************************************************************/
usbCamSetThumbnailSize(camera_hardware_t * camHal,const QCameraParameters & params)591 static int usbCamSetThumbnailSize(  camera_hardware_t           *camHal,
592                                     const QCameraParameters&    params)
593 {
594     int rc = 0, width, height, i, numThumbnailSizes, validSize;
595     char tempStr[FILENAME_LENGTH];
596     ALOGD("%s: E", __func__);
597 
598     /* parse for thumbnail width and height */
599     width = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_WIDTH);
600     height = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT);
601     ALOGI("%s: Requested thumbnail size %d x %d", __func__, width, height);
602 
603     // Validate the thumbnail size
604     numThumbnailSizes = sizeof(thumbnail_sizes) / sizeof(camera_size_type);
605     for (i = 0, validSize = 0; i <  numThumbnailSizes; i++) {
606         if (width ==  thumbnail_sizes[i].width
607            && height ==  thumbnail_sizes[i].height) {
608             validSize = 1;
609 
610             camHal->thumbnailWidth   = width;
611             camHal->thumbnailHeight  = height;
612             sprintf(tempStr, "%d", camHal->thumbnailWidth);
613             camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_WIDTH,
614                                                         width);
615             sprintf(tempStr, "%d", camHal->thumbnailHeight);
616             camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT,
617                                                         height);
618 
619         }
620     }
621     if(!validSize)
622         ALOGE("%s: Invalid picture size %dx%d requested", __func__,
623             width, height);
624     rc = (validSize == 0)? -1:0;
625     ALOGD("%s: X", __func__);
626 
627     return rc;
628 } /* usbCamSetThumbnailSize */
629 
630 /******************************************************************************
631  * Function: usbCamSetJpegQlty
632  * Description: This function parses picture and thumbnail JPEG quality and
633  *              validates before storing in the context
634  *
635  * Input parameters:
636  *  camHal              - camera HAL handle
637  *  params              - QCameraParameters reference
638  *
639  * Return values:
640  *      0   If parameters are valid
641  *      -1  If parameters are invalid
642  *
643  * Notes: none
644  *****************************************************************************/
usbCamSetJpegQlty(camera_hardware_t * camHal,const QCameraParameters & params)645 static int usbCamSetJpegQlty(   camera_hardware_t           *camHal,
646                                 const QCameraParameters&    params)
647 {
648     int rc = 0, quality = 0;
649     char tempStr[FILENAME_LENGTH];
650     ALOGD("%s: E", __func__);
651 
652     /**/
653     quality = params.getInt(QCameraParameters::KEY_JPEG_QUALITY);
654     ALOGI("%s: Requested picture qlty %d", __func__, quality);
655 
656     if (quality >= 0 && quality <= 100) {
657         camHal->pictJpegQlty = quality;
658         sprintf(tempStr, "%d", camHal->pictJpegQlty);
659         camHal->qCamParams.set(QCameraParameters::KEY_JPEG_QUALITY, quality);
660     } else {
661         ALOGE("Invalid jpeg quality=%d", quality);
662         rc = -1;
663     }
664 
665     quality = params.getInt(QCameraParameters::KEY_JPEG_THUMBNAIL_QUALITY);
666     ALOGI("%s: Requested thumbnail qlty %d", __func__, quality);
667 
668     if (quality >= 0 && quality <= 100) {
669         camHal->thumbnailJpegQlty = quality;
670         sprintf(tempStr, "%d", camHal->thumbnailJpegQlty);
671         camHal->qCamParams.set(QCameraParameters::KEY_JPEG_THUMBNAIL_QUALITY,
672                                     tempStr);
673     } else {
674         ALOGE("Invalid jpeg thumbnail quality=%d", quality);
675         rc = -1;
676     }
677 
678     ALOGD("%s: X rc:%d", __func__, rc);
679 
680     return rc;
681 }
682 
683 }; /*namespace android */
684