1/*
2 * Copyright (C) Texas Instruments - http://www.ti.com/
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18* @file OMXCap.cpp
19*
20* This file implements the OMX Capabilities feature.
21*
22*/
23
24#include "CameraHal.h"
25#include "OMXCameraAdapter.h"
26#include "ErrorUtils.h"
27#include "TICameraParameters.h"
28
29namespace Ti {
30namespace Camera {
31
32/************************************
33 * global constants and variables
34 *************************************/
35
36#define ARRAY_SIZE(array) (sizeof((array)) / sizeof((array)[0]))
37
38static const char PARAM_SEP[] = ",";
39static const uint32_t VFR_OFFSET = 8;
40static const char FPS_STR_MAX_LEN = 10;
41
42static const unsigned int MANUAL_EXPOSURE_STEP = 1;
43static const unsigned int MANUAL_GAIN_ISO_MIN = 100;
44static const unsigned int MANUAL_GAIN_ISO_STEP = 100;
45
46const int OMXCameraAdapter::SENSORID_IMX060 = 300;
47const int OMXCameraAdapter::SENSORID_OV5650 = 301;
48const int OMXCameraAdapter::SENSORID_OV5640 = 302;
49const int OMXCameraAdapter::SENSORID_OV14825 = 304;
50const int OMXCameraAdapter::SENSORID_S5K4E1GA = 305;
51const int OMXCameraAdapter::SENSORID_S5K6A1GX03 = 306;
52const int OMXCameraAdapter::SENSORID_OV8830 = 310;
53const int OMXCameraAdapter::SENSORID_OV2722 = 311;
54
55
56const int OMXCameraAdapter::FPS_MIN = 5;
57const int OMXCameraAdapter::FPS_MAX = 30;
58const int OMXCameraAdapter::FPS_MAX_EXTENDED = 60;
59
60inline static int androidFromDucatiFrameRate(OMX_U32 frameRate) {
61    return (frameRate >> VFR_OFFSET) * CameraHal::VFR_SCALE;
62}
63
64/**** look up tables to translate OMX Caps to Parameter ****/
65
66const CapResolution OMXCameraAdapter::mImageCapRes [] = {
67    { 4416, 3312, "4416x3312" },
68    { 4032, 3024, "4032x3024" },
69    { 4000, 3000, "4000x3000" },
70    { 3648, 2736, "3648x2736" },
71    { 3264, 2448, "3264x2448" },
72    { 2608, 1960, "2608x1960" },
73    { 2592, 1944, "2592x1944" },
74    { 2592, 1728, "2592x1728" },
75    { 2592, 1458, "2592x1458" },
76    { 2304, 1296, "2304x1296" },
77    { 2240, 1344, "2240x1344" },
78    { 2160, 1440, "2160x1440" },
79    { 2112, 1728, "2112x1728" },
80    { 2048, 1536, "2048x1536" },
81    { 2016, 1512, "2016x1512" },
82    { 2000, 1600, "2000x1600" },
83    { 1600, 1200, "1600x1200" },
84    { 1280, 1024, "1280x1024" },
85    { 1152,  864, "1152x864" },
86    { 1280,  960, "1280x960" },
87    { 1024,  768, "1024x768" },
88    {  640,  480, "640x480" },
89    {  320,  240, "320x240" },
90};
91
92const CapResolution OMXCameraAdapter::mImageCapResSS [] = {
93   { 4032*2, 3024, "8064x3024" },
94   { 3648*2, 2736, "7296x2736" },
95   { 3264*2, 2448, "6528x2448" },
96   { 2592*2, 1944, "5184x1944" },
97   { 2048*2, 1536, "4096x1536" },
98   { 1600*2, 1200, "3200x1200" },
99   { 1280*2,  960, "2560x960" },
100   { 1024*2,  768, "2048x768" },
101   {  640*2,  480, "1280x480" },
102   {  320*2,  240, "640x240" },
103};
104
105const CapResolution OMXCameraAdapter::mImageCapResTB [] = {
106   { 4032, 3024*2, "4032x6048" },
107   { 3648, 2736*2, "3648x5472" },
108   { 3264, 2448*2, "3264x4896" },
109   { 2592, 1944*2, "2592x3888" },
110   { 2048, 1536*2, "2048x3072" },
111   { 1600, 1200*2, "1600x2400" },
112   { 1280,  960*2, "1280x1920" },
113   { 1024,  768*2, "1024x1536" },
114   {  640,  480*2, "640x960" },
115   {  320,  240*2, "320x480" },
116};
117
118const CapResolution OMXCameraAdapter::mPreviewRes [] = {
119    { 1920, 1080, "1920x1080" },
120    { 1280, 720, "1280x720" },
121    { 960, 720, "960x720" },
122    { 800, 480, "800x480" },
123    { 720, 576, "720x576" },
124    { 720, 480, "720x480" },
125    { 768, 576, "768x576" },
126    { 640, 480, "640x480" },
127    { 320, 240, "320x240" },
128    { 352, 288, "352x288" },
129    { 240, 160, "240x160" },
130    { 176, 144, "176x144" },
131    { 160, 120, "160x120" },
132    { 128, 96, "128x96" },
133};
134
135const CapResolution OMXCameraAdapter::mPreviewPortraitRes [] = {
136    //Portrait resolutions
137    { 1088, 1920, "1088x1920" },
138    { 720, 1280, "720x1280" },
139    { 480, 800, "480x800" },
140    { 576, 720, "576x720" },
141    { 576, 768, "576x768" },
142    { 480, 720, "480x720" },
143    { 480, 640, "480x640" },
144    { 288, 352, "288x352" },
145    { 240, 320, "240x320" },
146    { 160, 240, "160x240" },
147    { 144, 176, "144x176" },
148    { 120, 160, "120x160"},
149    { 96, 128, "96x128" }
150};
151
152const CapResolution OMXCameraAdapter::mPreviewResSS [] = {
153   { 1920*2, 1080, "3840x1080" },
154   { 1280*2,  720, "2560x720" },
155   {  800*2,  480, "1600x480" },
156   {  720*2,  576, "1440x576" },
157   {  720*2,  480, "1440x480" },
158   {  768*2,  576, "1536x576" },
159   {  640*2,  480, "1280x480" },
160   {  320*2,  240, "640x240" },
161   {  352*2,  288, "704x288" },
162   {  240*2,  160, "480x160" },
163   {  176*2,  144, "352x144" },
164   {  128*2,   96, "256x96" }
165};
166
167const CapResolution OMXCameraAdapter::mPreviewResTB [] = {
168   { 1920, 1080*2, "1920x2160" },
169   { 1280,  720*2, "1280x1440" },
170   {  800,  480*2, "800x960" },
171   {  720,  576*2, "720x1152" },
172   {  720,  480*2, "720x960" },
173   {  768,  576*2, "768x1152" },
174   {  640,  480*2, "640x960" },
175   {  320,  240*2, "320x480" },
176   {  352,  288*2, "352x576" },
177   {  240,  160*2, "240x320" },
178   {  176,  144*2, "176x288" },
179   {  128,   96*2, "128x192" },
180};
181
182const CapResolution OMXCameraAdapter::mThumbRes [] = {
183    { 640, 480, "640x480" },
184    { 160, 120, "160x120" },
185    { 200, 120, "200x120" },
186    { 320, 240, "320x240" },
187    { 512, 384, "512x384" },
188    { 352, 144, "352x144" },
189    { 176, 144, "176x144" },
190    { 96, 96, "96x96" },
191};
192
193const CapPixelformat OMXCameraAdapter::mPixelformats [] = {
194    { OMX_COLOR_FormatCbYCrY, android::CameraParameters::PIXEL_FORMAT_YUV422I },
195    { OMX_COLOR_FormatYUV420SemiPlanar, android::CameraParameters::PIXEL_FORMAT_YUV420SP },
196    { OMX_COLOR_Format16bitRGB565, android::CameraParameters::PIXEL_FORMAT_RGB565 },
197    { OMX_COLOR_FormatYUV420SemiPlanar, android::CameraParameters::PIXEL_FORMAT_YUV420P },
198    { OMX_COLOR_FormatUnused, TICameraParameters::PIXEL_FORMAT_UNUSED },
199    { OMX_COLOR_FormatRawBayer10bit, android::CameraParameters::PIXEL_FORMAT_BAYER_RGGB },
200};
201
202const userToOMX_LUT OMXCameraAdapter::mFrameLayout [] = {
203   { TICameraParameters::S3D_NONE,          OMX_TI_StereoFrameLayout2D },
204   { TICameraParameters::S3D_TB_FULL,       OMX_TI_StereoFrameLayoutTopBottom },
205   { TICameraParameters::S3D_SS_FULL,       OMX_TI_StereoFrameLayoutLeftRight },
206   { TICameraParameters::S3D_TB_SUBSAMPLED, OMX_TI_StereoFrameLayoutTopBottomSubsample },
207   { TICameraParameters::S3D_SS_SUBSAMPLED, OMX_TI_StereoFrameLayoutLeftRightSubsample },
208};
209
210const LUTtype OMXCameraAdapter::mLayoutLUT = {
211   ARRAY_SIZE(mFrameLayout),
212   mFrameLayout
213};
214
215const CapCodingFormat OMXCameraAdapter::mImageCodingFormat [] = {
216      { OMX_IMAGE_CodingJPEG, android::CameraParameters::PIXEL_FORMAT_JPEG },
217      { (OMX_IMAGE_CODINGTYPE)OMX_TI_IMAGE_CodingJPS, TICameraParameters::PIXEL_FORMAT_JPS },
218      { (OMX_IMAGE_CODINGTYPE)OMX_TI_IMAGE_CodingMPO, TICameraParameters::PIXEL_FORMAT_MPO },
219};
220
221const CapFramerate OMXCameraAdapter::mFramerates [] = {
222    { 60, "60" },
223    { 30, "30" },
224    { 24, "24" },
225    { 20, "20" },
226    { 15, "15" },
227    { 10, "10" },
228};
229
230const CapZoom OMXCameraAdapter::mZoomStages [] = {
231    { 65536, "100" },
232    { 68157, "104" },
233    { 70124, "107" },
234    { 72745, "111" },
235    { 75366, "115" },
236    { 77988, "119" },
237    { 80609, "123" },
238    { 83231, "127" },
239    { 86508, "132" },
240    { 89784, "137" },
241    { 92406, "141" },
242    { 95683, "146" },
243    { 99615, "152" },
244    { 102892, "157" },
245    { 106168, "162" },
246    { 110100, "168" },
247    { 114033, "174" },
248    { 117965, "180" },
249    { 122552, "187" },
250    { 126484, "193" },
251    { 131072, "200" },
252    { 135660, "207" },
253    { 140247, "214" },
254    { 145490, "222" },
255    { 150733, "230" },
256    { 155976, "238" },
257    { 161219, "246" },
258    { 167117, "255" },
259    { 173015, "264" },
260    { 178913, "273" },
261    { 185467, "283" },
262    { 192020, "293" },
263    { 198574, "303" },
264    { 205783, "314" },
265    { 212992, "325" },
266    { 220201, "336" },
267    { 228065, "348" },
268    { 236585, "361" },
269    { 244449, "373" },
270    { 252969, "386" },
271    { 262144, "400" },
272    { 271319, "414" },
273    { 281149, "429" },
274    { 290980, "444" },
275    { 300810, "459" },
276    { 311951, "476" },
277    { 322437, "492" },
278    { 334234, "510" },
279    { 346030, "528" },
280    { 357827, "546" },
281    { 370934, "566" },
282    { 384041, "586" },
283    { 397148, "606" },
284    { 411566, "628" },
285    { 425984, "650" },
286    { 441057, "673" },
287    { 456131, "696" },
288    { 472515, "721" },
289    { 488899, "746" },
290    { 506593, "773" },
291    { 524288, "800" },
292};
293
294const CapISO OMXCameraAdapter::mISOStages [] = {
295    { 0, "auto" },
296    { 100, "100" },
297    { 200, "200"},
298    { 400, "400" },
299    { 800, "800" },
300    { 1000, "1000" },
301    { 1200, "1200" },
302    { 1600, "1600" },
303};
304
305// mapped values have to match with new_sensor_MSP.h
306const CapU32 OMXCameraAdapter::mSensorNames [] = {
307    { SENSORID_IMX060, "IMX060" },
308    { SENSORID_OV5650, "OV5650" },
309    { SENSORID_OV5640, "OV5640" },
310    { SENSORID_OV14825, "OV14825"},
311    { SENSORID_S5K4E1GA, "S5K4E1GA"},
312    { SENSORID_S5K6A1GX03, "S5K6A1GX03" },
313    { SENSORID_OV8830, "OV8830" },
314    { SENSORID_OV2722, "OV2722" }
315    // TODO(XXX): need to account for S3D camera later
316};
317
318const userToOMX_LUT OMXCameraAdapter::mAutoConvergence [] = {
319    { TICameraParameters::AUTOCONVERGENCE_MODE_DISABLE, OMX_TI_AutoConvergenceModeDisable },
320    { TICameraParameters::AUTOCONVERGENCE_MODE_FRAME,   OMX_TI_AutoConvergenceModeFrame },
321    { TICameraParameters::AUTOCONVERGENCE_MODE_CENTER,  OMX_TI_AutoConvergenceModeCenter },
322    { TICameraParameters::AUTOCONVERGENCE_MODE_TOUCH,   OMX_TI_AutoConvergenceModeFocusFaceTouch },
323    { TICameraParameters::AUTOCONVERGENCE_MODE_MANUAL,  OMX_TI_AutoConvergenceModeManual }
324};
325
326const LUTtype OMXCameraAdapter::mAutoConvergenceLUT = {
327    ARRAY_SIZE(mAutoConvergence),
328    mAutoConvergence
329};
330
331const userToOMX_LUT OMXCameraAdapter::mBracketingModes [] = {
332    { TICameraParameters::TEMP_BRACKETING       , OMX_BracketTemporal               },
333    { TICameraParameters::EXPOSURE_BRACKETING   , OMX_BracketExposureRelativeInEV   }
334};
335
336const LUTtype OMXCameraAdapter::mBracketingModesLUT = {
337    ARRAY_SIZE(mBracketingModes),
338    mBracketingModes
339};
340
341// values for supported camera facing direction
342const CapU32 OMXCameraAdapter::mFacing [] = {
343    { OMX_TI_SENFACING_BACK , TICameraParameters::FACING_BACK },
344    { OMX_TI_SENFACING_FRONT, TICameraParameters::FACING_FRONT},
345};
346
347/*****************************************
348 * internal static function declarations
349 *****************************************/
350
351/**** Utility functions to help translate OMX Caps to Parameter ****/
352
353status_t OMXCameraAdapter::encodeImageCodingFormatCap(OMX_IMAGE_CODINGTYPE format,
354        const CapCodingFormat *cap,
355        size_t capCount,
356        char * buffer) {
357
358    status_t ret = NO_ERROR;
359
360    LOG_FUNCTION_NAME;
361
362    if ( ( NULL == buffer ) || ( NULL == cap ) ) {
363        CAMHAL_LOGEA("Invalid input arguments");
364        ret = -EINVAL;
365    }
366
367    if ( NO_ERROR == ret ) {
368        for ( unsigned int i = 0 ; i < capCount ; i++ ) {
369            if ( format == cap[i].imageCodingFormat ) {
370                if (buffer[0] != '\0') {
371                    strncat(buffer, PARAM_SEP, ((((int)MAX_PROP_VALUE_LENGTH - 1 - (int)strlen(buffer)) < 0) ? 0 : (MAX_PROP_VALUE_LENGTH - 1 - strlen(buffer))));
372                }
373                strncat(buffer, cap[i].param,  ((((int)MAX_PROP_VALUE_LENGTH - 1 - (int)strlen(buffer)) < 0) ? 0 : (MAX_PROP_VALUE_LENGTH - 1 - strlen(buffer))));
374            }
375        }
376    }
377
378    LOG_FUNCTION_NAME_EXIT;
379
380    return ret;
381}
382
383status_t OMXCameraAdapter::encodePixelformatCap(OMX_COLOR_FORMATTYPE format,
384                              const CapPixelformat *cap,
385                              size_t capCount,
386                              char * buffer,
387                              size_t bufferSize)
388{
389    status_t ret = NO_ERROR;
390
391    LOG_FUNCTION_NAME;
392
393    if ( ( NULL == buffer ) || ( NULL == cap ) ) {
394        CAMHAL_LOGEA("Invalid input arguments");
395        return -EINVAL;
396    }
397
398
399    for ( unsigned int i = 0 ; i < capCount ; i++ )
400        {
401        if ( format == cap[i].pixelformat )
402            {
403            if (buffer[0] != '\0') {
404                strncat(buffer, PARAM_SEP, bufferSize - 1);
405            }
406            strncat(buffer, cap[i].param, bufferSize - 1);
407            }
408        }
409
410    LOG_FUNCTION_NAME_EXIT;
411
412    return ret;
413}
414
415void OMXCameraAdapter::encodeFrameRates(const int minFrameRate, const int maxFrameRate,
416        const OMX_TI_CAPTYPE & caps, const CapFramerate * const fixedFrameRates,
417        const int frameRateCount, android::Vector<FpsRange> & fpsRanges) {
418    LOG_FUNCTION_NAME;
419
420    if ( minFrameRate == maxFrameRate ) {
421        // single fixed frame rate supported
422        fpsRanges.add(FpsRange(minFrameRate, maxFrameRate));
423        return;
424    }
425
426    // insert min and max frame rates
427    fpsRanges.add(FpsRange(minFrameRate, minFrameRate));
428    fpsRanges.add(FpsRange(maxFrameRate, maxFrameRate));
429
430    // insert variable frame rates
431    for ( int i = 0; i < static_cast<int>(caps.ulPrvVarFPSModesCount); ++i ) {
432        const FpsRange fpsRange = FpsRange(
433                max(androidFromDucatiFrameRate(caps.tPrvVarFPSModes[i].nVarFPSMin), minFrameRate),
434                min(androidFromDucatiFrameRate(caps.tPrvVarFPSModes[i].nVarFPSMax), maxFrameRate));
435
436        if ( fpsRange.isFixed() ) {
437            // this range is either min or max fixed frame rate, already added above
438            continue;
439        }
440
441        fpsRanges.add(fpsRange);
442    }
443
444    // insert fixed frame rates
445    for ( int i = 0; i < frameRateCount; ++i ) {
446        const int fixedFrameRate = fixedFrameRates[i].num * CameraHal::VFR_SCALE;
447
448        if ( fixedFrameRate < minFrameRate || fixedFrameRate > maxFrameRate ) {
449            // not supported by hardware
450            continue;
451        }
452
453        const FpsRange fpsRange = FpsRange(fixedFrameRate, fixedFrameRate);
454        fpsRanges.add(fpsRange);
455    }
456
457    // sort first by max, then by min, according to Android API requirements
458    fpsRanges.sort(FpsRange::compare);
459
460    // remove duplicated frame rates
461    for ( int i = 0; i < static_cast<int>(fpsRanges.size()) - 1; ) {
462        const FpsRange & current = fpsRanges.itemAt(i);
463        const FpsRange & next = fpsRanges.itemAt(i + 1);
464        if ( current == next ) {
465            fpsRanges.removeAt(i + 1);
466        } else {
467            i++;
468        }
469    }
470}
471
472size_t OMXCameraAdapter::encodeZoomCap(OMX_S32 maxZoom,
473                     const CapZoom *cap,
474                     size_t capCount,
475                     char * buffer,
476                     size_t bufferSize)
477{
478    status_t res = NO_ERROR;
479    size_t ret = 0;
480
481    LOG_FUNCTION_NAME;
482
483    if ( (NULL == buffer) || (NULL == cap) ) {
484        CAMHAL_LOGEA("Invalid input arguments");
485        return -EINVAL;
486    }
487
488
489    for ( unsigned int i = 0; i < capCount; i++ ) {
490        if ( cap[i].num <= maxZoom ) {
491            if (buffer[0] != '\0') {
492                strncat(buffer, PARAM_SEP, bufferSize - 1);
493            }
494            strncat(buffer, cap[i].param, bufferSize - 1);
495            ret++;
496        }
497    }
498
499    LOG_FUNCTION_NAME_EXIT;
500
501    return ret;
502}
503
504status_t OMXCameraAdapter::encodeISOCap(OMX_U32 maxISO,
505                      const CapISO *cap,
506                      size_t capCount,
507                      char * buffer,
508                      size_t bufferSize)
509{
510    status_t ret = NO_ERROR;
511
512    LOG_FUNCTION_NAME;
513
514    if ( (NULL == buffer) || (NULL == cap) ) {
515        CAMHAL_LOGEA("Invalid input arguments");
516        return -EINVAL;
517    }
518
519    for ( unsigned int i = 0; i < capCount; i++ ) {
520        if ( cap[i].num <= maxISO) {
521            if (buffer[0] != '\0') {
522                strncat(buffer, PARAM_SEP, bufferSize - 1);
523            }
524            strncat(buffer, cap[i].param, bufferSize - 1);
525        }
526    }
527
528    LOG_FUNCTION_NAME_EXIT;
529
530    return ret;
531}
532
533status_t OMXCameraAdapter::encodeSizeCap(OMX_TI_CAPRESTYPE &res,
534                       const CapResolution *cap,
535                       size_t capCount,
536                       char * buffer,
537                       size_t bufferSize)
538{
539    status_t ret = NO_ERROR;
540
541    LOG_FUNCTION_NAME;
542
543    if ( (NULL == buffer) || (NULL == cap) ) {
544        CAMHAL_LOGEA("Invalid input arguments");
545        return -EINVAL;
546    }
547
548    for ( unsigned int i = 0 ; i < capCount ; i++ ) {
549        if ( (cap[i].width <= res.nWidthMax) &&
550             (cap[i].height <= res.nHeightMax) &&
551             (cap[i].width >= res.nWidthMin) &&
552             (cap[i].height >= res.nHeightMin) ) {
553                if (buffer[0] != '\0') {
554                    strncat(buffer, PARAM_SEP, bufferSize - 1);
555                }
556                strncat(buffer, cap[i].param, bufferSize -1);
557        }
558    }
559
560    LOG_FUNCTION_NAME_EXIT;
561
562    return ret;
563}
564
565status_t OMXCameraAdapter::encodeSizeCap3D(OMX_TI_CAPRESTYPE &res,
566                      const CapResolution *cap,
567                      size_t capCount,
568                      char * buffer,
569                      size_t bufferSize)
570{
571   status_t ret = NO_ERROR;
572
573   LOG_FUNCTION_NAME;
574
575   if ( (NULL == buffer) || (NULL == cap) ) {
576       CAMHAL_LOGEA("Invalid input arguments");
577       return -EINVAL;
578   }
579
580   for ( unsigned int i = 0 ; i < capCount ; i++ ) {
581       if ( (cap[i].width <= res.nWidthMax) &&
582            (cap[i].height <= res.nHeightMax) &&
583            (cap[i].width >= res.nWidthMin) &&
584            (cap[i].height >= res.nHeightMin)  &&
585            (cap[i].width * cap[i].height <= res.nMaxResInPixels))  {
586               if (buffer[0] != '\0') {
587                   strncat(buffer, PARAM_SEP, bufferSize - 1);
588               }
589               strncat(buffer, cap[i].param, bufferSize -1);
590       }
591   }
592
593   LOG_FUNCTION_NAME_EXIT;
594
595   return ret;
596}
597
598status_t OMXCameraAdapter::insertImageSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
599{
600    status_t ret = NO_ERROR;
601    char supported[MAX_PROP_VALUE_LENGTH];
602    int s3d_detected = 0;
603    int s3d_ss_detected = 0;
604    int s3d_tb_detected = 0;
605
606    LOG_FUNCTION_NAME;
607
608    for ( unsigned int i = 0 ; i < caps.ulCapFrameLayoutCount; i++ ) {
609        if (caps.eCapFrameLayout[i] == OMX_TI_StereoFrameLayoutTopBottom)
610        {
611            s3d_tb_detected = 1;
612        }
613        else if (caps.eCapFrameLayout[i] == OMX_TI_StereoFrameLayoutLeftRight)
614        {
615            s3d_ss_detected = 1;
616        }
617        else if ( (caps.eCapFrameLayout[i] == OMX_TI_StereoFrameLayoutTopBottomSubsample)
618                   || (caps.eCapFrameLayout[i] == OMX_TI_StereoFrameLayoutLeftRightSubsample) )
619        {
620            s3d_detected = 1;
621        }
622    }
623
624    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
625
626    // Check if we are in 2d mode
627    if (!s3d_ss_detected && !s3d_tb_detected && !s3d_detected)
628    {
629        ret = encodeSizeCap(caps.tImageResRange,
630                        mImageCapRes,
631                        ARRAY_SIZE(mImageCapRes),
632                        supported,
633                        MAX_PROP_VALUE_LENGTH);
634
635        if ( NO_ERROR != ret ) {
636            CAMHAL_LOGEB("Error inserting supported picture sizes 0x%x", ret);
637        } else {
638            params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, supported);
639        }
640        params->set(CameraProperties::MAX_PICTURE_WIDTH, caps.tImageResRange.nWidthMax);
641        params->set(CameraProperties::MAX_PICTURE_HEIGHT, caps.tImageResRange.nHeightMax);
642    }
643    else // 3d mode
644    {
645        if (s3d_tb_detected)
646        {
647            ret = encodeSizeCap3D(caps.tImageResRange,
648                            mImageCapResTB,
649                            ARRAY_SIZE(mImageCapResTB),
650                            supported,
651                            MAX_PROP_VALUE_LENGTH);
652
653            if ( NO_ERROR != ret ) {
654                CAMHAL_LOGEB("Error inserting supported picture sizes 0x%x", ret);
655            } else {
656                params->set(CameraProperties::SUPPORTED_PICTURE_TOPBOTTOM_SIZES, supported);
657            }
658        }
659        else
660        {
661            params->set(CameraProperties::SUPPORTED_PICTURE_TOPBOTTOM_SIZES, supported);
662        }
663
664        memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
665
666        if (s3d_ss_detected)
667        {
668            ret = encodeSizeCap3D(caps.tImageResRange,
669                            mImageCapResSS,
670                            ARRAY_SIZE(mImageCapResSS),
671                            supported,
672                            MAX_PROP_VALUE_LENGTH);
673
674            if ( NO_ERROR != ret ) {
675                CAMHAL_LOGEB("Error inserting supported picture sizes 0x%x", ret);
676            } else {
677                params->set(CameraProperties::SUPPORTED_PICTURE_SIDEBYSIDE_SIZES, supported);
678            }
679        }
680        else
681        {
682            params->set(CameraProperties::SUPPORTED_PICTURE_SIDEBYSIDE_SIZES, supported);
683        }
684
685        memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
686
687        if (s3d_detected)
688        {
689            ret = encodeSizeCap3D(caps.tImageResRange,
690                            mImageCapRes,
691                            ARRAY_SIZE(mImageCapRes),
692                            supported,
693                            MAX_PROP_VALUE_LENGTH);
694
695            if ( NO_ERROR != ret ) {
696                CAMHAL_LOGEB("Error inserting supported picture sizes 0x%x", ret);
697            } else {
698                params->set(CameraProperties::SUPPORTED_PICTURE_SUBSAMPLED_SIZES, supported);
699            }
700        } else {
701            params->set(CameraProperties::SUPPORTED_PICTURE_SUBSAMPLED_SIZES, supported);
702        }
703    }
704
705    LOG_FUNCTION_NAME_EXIT;
706
707    return ret;
708}
709
710status_t OMXCameraAdapter::insertPreviewSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
711{
712    status_t ret = NO_ERROR;
713    char supported[MAX_PROP_VALUE_LENGTH];
714    int s3d_detected = 0;
715    int s3d_ss_detected = 0;
716    int s3d_tb_detected = 0;
717
718    LOG_FUNCTION_NAME;
719
720    for ( unsigned int i = 0 ; i < caps.ulPrvFrameLayoutCount; i++ ) {
721        if (caps.ePrvFrameLayout[i] == OMX_TI_StereoFrameLayoutTopBottom)
722        {
723            s3d_tb_detected = 1;
724        }
725        else if (caps.ePrvFrameLayout[i] == OMX_TI_StereoFrameLayoutLeftRight)
726        {
727            s3d_ss_detected = 1;
728        }
729        else if ( (caps.ePrvFrameLayout[i] == OMX_TI_StereoFrameLayoutTopBottomSubsample)
730                    || (caps.ePrvFrameLayout[i] == OMX_TI_StereoFrameLayoutLeftRightSubsample) )
731        {
732            s3d_detected = 1;
733        }
734    }
735
736    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
737
738    // Check if we are in 2d mode
739    if (!s3d_ss_detected && !s3d_tb_detected && !s3d_detected)
740    {
741        ret = encodeSizeCap(caps.tPreviewResRange,
742                        mPreviewRes,
743                        ARRAY_SIZE(mPreviewRes),
744                        supported,
745                        MAX_PROP_VALUE_LENGTH);
746
747        if ( NO_ERROR != ret ) {
748            CAMHAL_LOGEB("Error inserting supported Landscape preview sizes 0x%x", ret);
749            return ret;
750        }
751
752        /* Insert Portait Resolutions by verifying Potrait Capability Support */
753        ret = encodeSizeCap(caps.tRotatedPreviewResRange,
754                            mPreviewPortraitRes,
755                            ARRAY_SIZE(mPreviewPortraitRes),
756                            supported,
757                            MAX_PROP_VALUE_LENGTH);
758
759        if ( NO_ERROR != ret ) {
760            CAMHAL_LOGEB("Error inserting supported Potrait preview sizes 0x%x", ret);
761        } else {
762            params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, supported);
763        }
764    }
765    else // 3d mode
766    {
767        if (s3d_tb_detected)
768        {
769            ret = encodeSizeCap3D(caps.tPreviewResRange,
770                            mPreviewResTB,
771                            ARRAY_SIZE(mPreviewResTB),
772                            supported,
773                            MAX_PROP_VALUE_LENGTH);
774            if ( NO_ERROR != ret ) {
775                CAMHAL_LOGEB("Error inserting supported 3D TB preview sizes 0x%x", ret);
776                return ret;
777            } else {
778                params->set(CameraProperties::SUPPORTED_PREVIEW_TOPBOTTOM_SIZES, supported);
779            }
780        }
781        else
782        {
783            params->set(CameraProperties::SUPPORTED_PREVIEW_TOPBOTTOM_SIZES, supported);
784        }
785
786        memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
787
788        if (s3d_ss_detected)
789        {
790            ret = encodeSizeCap3D(caps.tPreviewResRange,
791                            mPreviewResSS,
792                            ARRAY_SIZE(mPreviewResSS),
793                            supported,
794                            MAX_PROP_VALUE_LENGTH);
795            if ( NO_ERROR != ret ) {
796                CAMHAL_LOGEB("Error inserting supported 3D SS preview sizes 0x%x", ret);
797                return ret;
798            } else {
799                params->set(CameraProperties::SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES, supported);
800            }
801        }
802        else
803        {
804            params->set(CameraProperties::SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES, supported);
805        }
806
807        memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
808
809        if (s3d_detected)
810        {
811            ret = encodeSizeCap3D(caps.tPreviewResRange,
812                            mPreviewRes,
813                            ARRAY_SIZE(mPreviewRes),
814                            supported,
815                            MAX_PROP_VALUE_LENGTH);
816
817            if ( NO_ERROR != ret ) {
818                CAMHAL_LOGEB("Error inserting supported preview sizes 0x%x", ret);
819                return ret;
820            } else {
821                params->set(CameraProperties::SUPPORTED_PREVIEW_SUBSAMPLED_SIZES, supported);
822            }
823        }
824        else
825        {
826            params->set(CameraProperties::SUPPORTED_PREVIEW_SUBSAMPLED_SIZES, supported);
827        }
828     }
829
830    LOG_FUNCTION_NAME_EXIT;
831
832    return ret;
833}
834
835status_t OMXCameraAdapter::insertVideoSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
836{
837    status_t ret = NO_ERROR;
838    char supported[MAX_PROP_VALUE_LENGTH];
839
840    LOG_FUNCTION_NAME;
841
842    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
843
844    ret = encodeSizeCap(caps.tPreviewResRange,
845                        mPreviewRes,
846                        ARRAY_SIZE(mPreviewRes),
847                        supported,
848                        MAX_PROP_VALUE_LENGTH);
849
850    if ( NO_ERROR != ret ) {
851      CAMHAL_LOGEB("Error inserting supported video sizes 0x%x", ret);
852    } else {
853      params->set(CameraProperties::SUPPORTED_VIDEO_SIZES, supported);
854    }
855
856    LOG_FUNCTION_NAME_EXIT;
857
858    return ret;
859}
860
861status_t OMXCameraAdapter::insertThumbSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
862{
863    status_t ret = NO_ERROR;
864    char supported[MAX_PROP_VALUE_LENGTH];
865
866    LOG_FUNCTION_NAME;
867
868    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
869
870    ret = encodeSizeCap(caps.tThumbResRange,
871                        mThumbRes,
872                        ARRAY_SIZE(mThumbRes),
873                        supported,
874                        MAX_PROP_VALUE_LENGTH);
875
876    if ( NO_ERROR != ret ) {
877        CAMHAL_LOGEB("Error inserting supported thumbnail sizes 0x%x", ret);
878    } else {
879        //CTS Requirement: 0x0 should always be supported
880        if (supported[0] != '\0') {
881            strncat(supported, PARAM_SEP, 1);
882        }
883        strncat(supported, "0x0", MAX_PROP_NAME_LENGTH);
884        params->set(CameraProperties::SUPPORTED_THUMBNAIL_SIZES, supported);
885    }
886
887    LOG_FUNCTION_NAME_EXIT;
888
889    return ret;
890}
891
892status_t OMXCameraAdapter::insertZoomStages(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
893{
894    status_t ret = NO_ERROR;
895    char supported[MAX_PROP_VALUE_LENGTH];
896    size_t zoomStageCount = 0;
897
898    LOG_FUNCTION_NAME;
899
900    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
901
902    zoomStageCount = encodeZoomCap(caps.xMaxWidthZoom,
903                                   mZoomStages,
904                                   ARRAY_SIZE(mZoomStages),
905                                   supported,
906                                   MAX_PROP_VALUE_LENGTH);
907
908    params->set(CameraProperties::SUPPORTED_ZOOM_RATIOS, supported);
909    params->set(CameraProperties::SUPPORTED_ZOOM_STAGES, zoomStageCount - 1); //As per CTS requirement
910
911    if ( 0 == zoomStageCount ) {
912        params->set(CameraProperties::ZOOM_SUPPORTED, android::CameraParameters::FALSE);
913        params->set(CameraProperties::SMOOTH_ZOOM_SUPPORTED, android::CameraParameters::FALSE);
914    } else {
915        params->set(CameraProperties::ZOOM_SUPPORTED, android::CameraParameters::TRUE);
916        params->set(CameraProperties::SMOOTH_ZOOM_SUPPORTED, android::CameraParameters::TRUE);
917    }
918
919    LOG_FUNCTION_NAME_EXIT;
920
921    return ret;
922}
923
924status_t OMXCameraAdapter::insertImageFormats(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
925{
926    status_t ret = NO_ERROR;
927    char supported[MAX_PROP_VALUE_LENGTH];
928
929    LOG_FUNCTION_NAME;
930
931    memset(supported, '\0', sizeof(supported));
932
933    for ( int i = 0 ; i < caps.ulImageFormatCount ; i++ ) {
934        ret = encodePixelformatCap(caps.eImageFormats[i],
935                                   mPixelformats,
936                                   ARRAY_SIZE(mPixelformats),
937                                   supported,
938                                   MAX_PROP_VALUE_LENGTH);
939
940        if ( NO_ERROR != ret ) {
941            CAMHAL_LOGEB("Error inserting supported picture formats 0x%x", ret);
942            break;
943        }
944    }
945
946    for (int i = 0; i < caps.ulImageCodingFormatCount ; i++) {
947        ret = encodeImageCodingFormatCap(caps.eImageCodingFormat[i],
948                                        mImageCodingFormat,
949                                        ARRAY_SIZE(mImageCodingFormat),
950                                        supported);
951
952        if ( NO_ERROR != ret ) {
953            CAMHAL_LOGEB("Error inserting supported picture formats 0x%x", ret);
954            break;
955        }
956    }
957
958    if ( NO_ERROR == ret ) {
959        params->set(CameraProperties::SUPPORTED_PICTURE_FORMATS, supported);
960    }
961
962    LOG_FUNCTION_NAME_EXIT;
963
964    return ret;
965}
966
967status_t OMXCameraAdapter::insertPreviewFormats(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
968{
969    status_t ret = NO_ERROR;
970    char supported[MAX_PROP_VALUE_LENGTH];
971
972    LOG_FUNCTION_NAME;
973
974    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
975
976    for ( int i = 0 ; i < caps.ulPreviewFormatCount; i++ ) {
977        ret = encodePixelformatCap(caps.ePreviewFormats[i],
978                                   mPixelformats,
979                                   ARRAY_SIZE(mPixelformats),
980                                   supported,
981                                   MAX_PROP_VALUE_LENGTH);
982        if ( NO_ERROR != ret ) {
983            CAMHAL_LOGEB("Error inserting supported preview formats 0x%x", ret);
984            break;
985        }
986    }
987
988    if ( NO_ERROR == ret ) {
989        // need to advertise we support YV12 format
990        // We will program preview port with NV21 when we see application set YV12
991        if (supported[0] != '\0') {
992            strncat(supported, PARAM_SEP, 1);
993        }
994        strncat(supported, android::CameraParameters::PIXEL_FORMAT_YUV420P, MAX_PROP_VALUE_LENGTH - 1);
995        params->set(CameraProperties::SUPPORTED_PREVIEW_FORMATS, supported);
996    }
997
998    LOG_FUNCTION_NAME_EXIT;
999
1000    return ret;
1001}
1002
1003status_t OMXCameraAdapter::insertFramerates(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1004{
1005    // collect supported normal frame rates
1006    {
1007        android::Vector<FpsRange> fpsRanges;
1008
1009        const int minFrameRate = max<int>(FPS_MIN * CameraHal::VFR_SCALE,
1010                androidFromDucatiFrameRate(caps.xFramerateMin));
1011        const int maxFrameRate = min<int>(FPS_MAX * CameraHal::VFR_SCALE,
1012                androidFromDucatiFrameRate(caps.xFramerateMax));
1013
1014        if ( minFrameRate > maxFrameRate ) {
1015            CAMHAL_LOGE("Invalid frame rate range: [%d .. %d]", caps.xFramerateMin, caps.xFramerateMax);
1016            return BAD_VALUE;
1017        }
1018
1019        encodeFrameRates(minFrameRate, maxFrameRate, caps, mFramerates, ARRAY_SIZE(mFramerates), fpsRanges);
1020
1021        // populate variable frame rates
1022        char supported[MAX_PROP_VALUE_LENGTH];
1023        char defaultRange[MAX_PROP_VALUE_LENGTH];
1024
1025        memset(supported, 0, sizeof(supported));
1026        memset(defaultRange, 0, sizeof(defaultRange));
1027
1028        for ( int i = 0; i < static_cast<int>(fpsRanges.size()); ++i ) {
1029            const FpsRange & fpsRange = fpsRanges.itemAt(i);
1030            if ( supported[0] ) strncat(supported, PARAM_SEP, 1);
1031            char tmp[MAX_PROP_VALUE_LENGTH];
1032            snprintf(tmp, sizeof(tmp) - 1, "(%d,%d)", fpsRange.min(), fpsRange.max());
1033            strcat(supported, tmp);
1034        }
1035
1036        const FpsRange & defaultFpsRange = fpsRanges.itemAt(fpsRanges.size() - 1);
1037        snprintf(defaultRange, sizeof(defaultRange) - 1, "%d,%d", defaultFpsRange.min(), defaultFpsRange.max());
1038
1039        CAMHAL_LOGD("Supported framerate ranges: %s", supported);
1040        CAMHAL_LOGD("Default framerate range: [%s]", defaultRange);
1041
1042        params->set(CameraProperties::FRAMERATE_RANGE_SUPPORTED, supported);
1043        params->set(CameraProperties::FRAMERATE_RANGE, defaultRange);
1044
1045        // populate fixed frame rates
1046        memset(supported, 0, sizeof(supported));
1047        memset(defaultRange, 0, sizeof(defaultRange));
1048
1049        for ( int i = 0; i < static_cast<int>(fpsRanges.size()); ++i ) {
1050            const FpsRange & fpsRange = fpsRanges.itemAt(i);
1051            if ( fpsRange.isFixed() && (fpsRange.min()%CameraHal::VFR_SCALE) == 0 ) {
1052                if ( supported[0] ) strncat(supported, PARAM_SEP, 1);
1053                char tmp[MAX_PROP_VALUE_LENGTH];
1054                snprintf(tmp, sizeof(tmp) - 1, "%d", fpsRange.min()/CameraHal::VFR_SCALE);
1055                strcat(supported, tmp);
1056            }
1057        }
1058
1059        CAMHAL_LOGD("Supported preview framerates: %s", supported);
1060        params->set(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES, supported);
1061
1062        // insert default frame rate only if it is fixed
1063        if ( defaultFpsRange.isFixed() && (defaultFpsRange.min()%CameraHal::VFR_SCALE) == 0 ) {
1064            snprintf(defaultRange, sizeof(defaultRange) - 1, "%d", defaultFpsRange.min()/CameraHal::VFR_SCALE);
1065            params->set(CameraProperties::PREVIEW_FRAME_RATE, defaultRange);
1066        }
1067    }
1068
1069    // collect supported extended frame rates
1070    {
1071        android::Vector<FpsRange> fpsRanges;
1072
1073        const int minFrameRate = max<int>(FPS_MIN * CameraHal::VFR_SCALE,
1074                androidFromDucatiFrameRate(caps.xFramerateMin));
1075        const int maxFrameRate = min<int>(FPS_MAX_EXTENDED * CameraHal::VFR_SCALE,
1076                androidFromDucatiFrameRate(caps.xFramerateMax));
1077
1078        encodeFrameRates(minFrameRate, maxFrameRate, caps, mFramerates, ARRAY_SIZE(mFramerates), fpsRanges);
1079
1080        // populate variable frame rates
1081        char supported[MAX_PROP_VALUE_LENGTH];
1082        memset(supported, 0, sizeof(supported) - 1);
1083
1084        for ( int i = 0; i < static_cast<int>(fpsRanges.size()); ++i ) {
1085            const FpsRange & fpsRange = fpsRanges.itemAt(i);
1086            if ( supported[0] ) strncat(supported, PARAM_SEP, 1);
1087            char tmp[MAX_PROP_VALUE_LENGTH];
1088            snprintf(tmp, sizeof(tmp) - 1, "(%d,%d)", fpsRange.min(), fpsRange.max());
1089            strcat(supported, tmp);
1090        }
1091
1092        CAMHAL_LOGD("Supported framerate ranges extended: %s", supported);
1093        params->set(CameraProperties::FRAMERATE_RANGE_EXT_SUPPORTED, supported);
1094
1095        // populate fixed frame rates
1096        memset(supported, 0, sizeof(supported) - 1);
1097
1098        for ( int i = 0; i < static_cast<int>(fpsRanges.size()); ++i ) {
1099            const FpsRange & fpsRange = fpsRanges.itemAt(i);
1100            if ( fpsRange.isFixed() && (fpsRange.min()%CameraHal::VFR_SCALE) == 0 ) {
1101                if ( supported[0] ) strncat(supported, PARAM_SEP, 1);
1102                char tmp[MAX_PROP_VALUE_LENGTH];
1103                snprintf(tmp, sizeof(tmp) - 1, "%d", fpsRange.min()/CameraHal::VFR_SCALE);
1104                strcat(supported, tmp);
1105            }
1106        }
1107
1108        CAMHAL_LOGD("Supported extended preview framerates: %s", supported);
1109        params->set(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES_EXT, supported);
1110    }
1111
1112    return OK;
1113}
1114
1115status_t OMXCameraAdapter::insertEVs(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1116{
1117    status_t ret = NO_ERROR;
1118    char supported[MAX_PROP_VALUE_LENGTH];
1119
1120    LOG_FUNCTION_NAME;
1121
1122    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1123
1124    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.xEVCompensationMin * 10 ));
1125    params->set(CameraProperties::SUPPORTED_EV_MIN, supported);
1126
1127    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.xEVCompensationMax * 10 ));
1128    params->set(CameraProperties::SUPPORTED_EV_MAX, supported);
1129
1130    LOG_FUNCTION_NAME_EXIT;
1131
1132    return ret;
1133}
1134
1135status_t OMXCameraAdapter::insertISOModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1136{
1137    status_t ret = NO_ERROR;
1138    char supported[MAX_PROP_VALUE_LENGTH];
1139
1140    LOG_FUNCTION_NAME;
1141
1142    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1143
1144    ret = encodeISOCap(caps.nSensitivityMax,
1145                       mISOStages,
1146                       ARRAY_SIZE(mISOStages),
1147                       supported,
1148                       MAX_PROP_VALUE_LENGTH);
1149    if ( NO_ERROR != ret ) {
1150        CAMHAL_LOGEB("Error inserting supported ISO modes 0x%x", ret);
1151    } else {
1152        params->set(CameraProperties::SUPPORTED_ISO_VALUES, supported);
1153    }
1154
1155    LOG_FUNCTION_NAME_EXIT;
1156
1157    return ret;
1158}
1159
1160status_t OMXCameraAdapter::insertIPPModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1161{
1162    status_t ret = NO_ERROR;
1163    char supported[MAX_PROP_VALUE_LENGTH];
1164
1165    LOG_FUNCTION_NAME;
1166
1167    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1168
1169    //Off is always supported
1170    strncat(supported, TICameraParameters::IPP_NONE, MAX_PROP_NAME_LENGTH);
1171
1172    if ( caps.bLensDistortionCorrectionSupported ) {
1173        strncat(supported, PARAM_SEP, 1);
1174        strncat(supported, TICameraParameters::IPP_LDC, MAX_PROP_NAME_LENGTH);
1175    }
1176
1177    if ( caps.bISONoiseFilterSupported ) {
1178        strncat(supported, PARAM_SEP, 1);
1179        strncat(supported, TICameraParameters::IPP_NSF, MAX_PROP_NAME_LENGTH);
1180    }
1181
1182    if ( caps.bISONoiseFilterSupported && caps.bLensDistortionCorrectionSupported ) {
1183        strncat(supported, PARAM_SEP, 1);
1184        strncat(supported, TICameraParameters::IPP_LDCNSF, MAX_PROP_NAME_LENGTH);
1185    }
1186
1187    params->set(CameraProperties::SUPPORTED_IPP_MODES, supported);
1188
1189    LOG_FUNCTION_NAME_EXIT;
1190
1191    return ret;
1192}
1193
1194status_t OMXCameraAdapter::insertWBModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1195{
1196    status_t ret = NO_ERROR;
1197    char supported[MAX_PROP_VALUE_LENGTH];
1198    const char *p;
1199
1200    LOG_FUNCTION_NAME;
1201
1202    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1203
1204    for ( unsigned int i = 0 ; i < caps.ulWhiteBalanceCount ; i++ ) {
1205        p = getLUTvalue_OMXtoHAL(caps.eWhiteBalanceModes[i], WBalLUT);
1206        if ( NULL != p ) {
1207            if (supported[0] != '\0') {
1208                strncat(supported, PARAM_SEP, 1);
1209            }
1210            strncat(supported, p, MAX_PROP_NAME_LENGTH);
1211        }
1212    }
1213
1214    params->set(CameraProperties::SUPPORTED_WHITE_BALANCE, supported);
1215
1216    LOG_FUNCTION_NAME_EXIT;
1217
1218    return ret;
1219}
1220
1221status_t OMXCameraAdapter::insertEffects(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1222{
1223    status_t ret = NO_ERROR;
1224    char supported[MAX_PROP_VALUE_LENGTH];
1225    const char *p;
1226
1227    LOG_FUNCTION_NAME;
1228
1229    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1230
1231    for ( unsigned int i = 0 ; i < caps.ulColorEffectCount; i++ ) {
1232        p = getLUTvalue_OMXtoHAL(caps.eColorEffects[i], EffLUT);
1233        if ( NULL != p ) {
1234            if (supported[0] != '\0') {
1235                strncat(supported, PARAM_SEP, 1);
1236            }
1237            strncat(supported, p, MAX_PROP_NAME_LENGTH);
1238        }
1239    }
1240
1241    params->set(CameraProperties::SUPPORTED_EFFECTS, supported);
1242
1243    LOG_FUNCTION_NAME_EXIT;
1244
1245    return ret;
1246}
1247
1248status_t OMXCameraAdapter::insertExpModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1249{
1250    status_t ret = NO_ERROR;
1251    char supported[MAX_PROP_VALUE_LENGTH];
1252    const char *p;
1253
1254    LOG_FUNCTION_NAME;
1255
1256    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1257
1258    for ( unsigned int i = 0 ; i < caps.ulExposureModeCount; i++ ) {
1259        p = getLUTvalue_OMXtoHAL(caps.eExposureModes[i], ExpLUT);
1260        if ( NULL != p ) {
1261            if (supported[0] != '\0') {
1262                strncat(supported, PARAM_SEP, 1);
1263            }
1264            strncat(supported, p, MAX_PROP_NAME_LENGTH);
1265        }
1266    }
1267
1268    params->set(CameraProperties::SUPPORTED_EXPOSURE_MODES, supported);
1269
1270    LOG_FUNCTION_NAME_EXIT;
1271
1272    return ret;
1273}
1274
1275status_t OMXCameraAdapter::insertManualExpRanges(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1276    status_t ret = NO_ERROR;
1277    char supported[MAX_PROP_VALUE_LENGTH];
1278
1279    LOG_FUNCTION_NAME;
1280
1281    if (caps.nManualExpMin > caps.nManualExpMax) {
1282        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) 0);
1283        params->set(CameraProperties::SUPPORTED_MANUAL_EXPOSURE_MIN, supported);
1284
1285        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) 0);
1286        params->set(CameraProperties::SUPPORTED_MANUAL_EXPOSURE_MAX, supported);
1287
1288        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) 0);
1289        params->set(CameraProperties::SUPPORTED_MANUAL_EXPOSURE_STEP, supported);
1290    } else {
1291        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) caps.nManualExpMin);
1292        params->set(CameraProperties::SUPPORTED_MANUAL_EXPOSURE_MIN, supported);
1293
1294        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) caps.nManualExpMax);
1295        params->set(CameraProperties::SUPPORTED_MANUAL_EXPOSURE_MAX, supported);
1296
1297        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) MANUAL_EXPOSURE_STEP);
1298        params->set(CameraProperties::SUPPORTED_MANUAL_EXPOSURE_STEP, supported);
1299    }
1300
1301    if (MANUAL_GAIN_ISO_MIN > caps.nSensitivityMax) {
1302        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) 0);
1303        params->set(CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_MIN, supported);
1304
1305        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) 0);
1306        params->set(CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_MAX, supported);
1307
1308        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) 0);
1309        params->set(CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_STEP, supported);    }
1310    else {
1311        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) MANUAL_GAIN_ISO_MIN);
1312        params->set(CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_MIN, supported);
1313
1314        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) caps.nSensitivityMax);
1315        params->set(CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_MAX, supported);
1316
1317        snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", (int) MANUAL_GAIN_ISO_STEP);
1318        params->set(CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_STEP, supported);
1319    }
1320
1321    LOG_FUNCTION_NAME_EXIT;
1322
1323    return ret;
1324}
1325
1326status_t OMXCameraAdapter::insertFlashModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1327{
1328    status_t ret = NO_ERROR;
1329    char supported[MAX_PROP_VALUE_LENGTH];
1330    const char *p;
1331
1332    LOG_FUNCTION_NAME;
1333
1334    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1335
1336    for ( unsigned int i = 0 ; i < caps.ulFlashCount; i++ ) {
1337        p = getLUTvalue_OMXtoHAL(caps.eFlashModes[i], FlashLUT);
1338        if ( NULL != p ) {
1339            if (supported[0] != '\0') {
1340                strncat(supported, PARAM_SEP, 1);
1341            }
1342            strncat(supported, p, MAX_PROP_NAME_LENGTH);
1343        }
1344    }
1345
1346    if ( strlen(supported) == 0 ) {
1347        strncpy(supported, DEFAULT_FLASH_MODE, MAX_PROP_NAME_LENGTH);
1348    }
1349
1350    params->set(CameraProperties::SUPPORTED_FLASH_MODES, supported);
1351
1352    LOG_FUNCTION_NAME_EXIT;
1353
1354    return ret;
1355}
1356
1357status_t OMXCameraAdapter::insertSceneModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1358{
1359    status_t ret = NO_ERROR;
1360    char supported[MAX_PROP_VALUE_LENGTH];
1361    const char *p;
1362
1363    LOG_FUNCTION_NAME;
1364
1365    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1366
1367    for ( unsigned int i = 0 ; i < caps.ulSceneCount; i++ ) {
1368        p = getLUTvalue_OMXtoHAL(caps.eSceneModes[i], SceneLUT);
1369        if ( NULL != p ) {
1370            if (supported[0] != '\0') {
1371                strncat(supported, PARAM_SEP, 1);
1372            }
1373            strncat(supported, p, MAX_PROP_NAME_LENGTH);
1374        }
1375    }
1376
1377    params->set(CameraProperties::SUPPORTED_SCENE_MODES, supported);
1378
1379    LOG_FUNCTION_NAME_EXIT;
1380
1381    return ret;
1382}
1383
1384status_t OMXCameraAdapter::insertFocusModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1385{
1386    status_t ret = NO_ERROR;
1387    char supported[MAX_PROP_VALUE_LENGTH];
1388
1389    LOG_FUNCTION_NAME;
1390
1391    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1392
1393    for ( unsigned int i = 0 ; i < caps.ulFocusModeCount; i++ ) {
1394        getMultipleLUTvalue_OMXtoHAL(caps.eFocusModes[i], FocusLUT, supported);
1395    }
1396
1397    // Check if focus is supported by camera
1398    if (caps.ulFocusModeCount == 1 &&
1399        caps.eFocusModes[0] == OMX_IMAGE_FocusControlOff) {
1400        // Focus is not supported by camera
1401        // Advertise this to app as infinitiy focus mode
1402        if (supported[0] != '\0') {
1403            strncat(supported, PARAM_SEP, 1);
1404        }
1405        strncat(supported, android::CameraParameters::FOCUS_MODE_INFINITY, MAX_PROP_NAME_LENGTH);
1406    }
1407
1408    params->set(CameraProperties::SUPPORTED_FOCUS_MODES, supported);
1409
1410    LOG_FUNCTION_NAME_EXIT;
1411
1412    return ret;
1413}
1414
1415status_t OMXCameraAdapter::insertFlickerModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1416{
1417    status_t ret = NO_ERROR;
1418    char supported[MAX_PROP_VALUE_LENGTH];
1419    const char *p;
1420
1421    LOG_FUNCTION_NAME;
1422
1423    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1424
1425    for ( unsigned int i = 0 ; i < caps.ulFlickerCount; i++ ) {
1426        p = getLUTvalue_OMXtoHAL(caps.eFlicker[i], FlickerLUT);
1427        if ( NULL != p ) {
1428            if (supported[0] != '\0') {
1429                strncat(supported, PARAM_SEP, 1);
1430            }
1431            strncat(supported, p, MAX_PROP_NAME_LENGTH);
1432        }
1433    }
1434
1435    params->set(CameraProperties::SUPPORTED_ANTIBANDING, supported);
1436
1437    LOG_FUNCTION_NAME_EXIT;
1438
1439    return ret;
1440}
1441
1442status_t OMXCameraAdapter::insertAreas(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1443{
1444    status_t ret = NO_ERROR;
1445    char supported[MAX_PROP_VALUE_LENGTH];
1446    const char *p;
1447
1448    LOG_FUNCTION_NAME;
1449
1450    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1451
1452    sprintf(supported, "%d", caps.ulAlgoAreasFocusCount);
1453    params->set(CameraProperties::MAX_FOCUS_AREAS, supported);
1454    CAMHAL_LOGDB("Maximum supported focus areas %s", supported);
1455
1456    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1457    sprintf(supported, "%d", caps.ulAlgoAreasExposureCount);
1458    params->set(CameraProperties::MAX_NUM_METERING_AREAS, supported);
1459    CAMHAL_LOGDB("Maximum supported exposure areas %s", supported);
1460
1461    LOG_FUNCTION_NAME_EXIT;
1462
1463    return ret;
1464}
1465
1466status_t OMXCameraAdapter::insertVNFSupported(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1467    status_t ret = NO_ERROR;
1468
1469    LOG_FUNCTION_NAME;
1470
1471    if ( OMX_TRUE == caps.bVideoNoiseFilterSupported ) {
1472        params->set(CameraProperties::VNF_SUPPORTED, android::CameraParameters::TRUE);
1473    } else {
1474        params->set(CameraProperties::VNF_SUPPORTED, android::CameraParameters::FALSE);
1475    }
1476
1477    LOG_FUNCTION_NAME_EXIT;
1478
1479    return ret;
1480}
1481
1482status_t OMXCameraAdapter::insertVSTABSupported(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1483    status_t ret = NO_ERROR;
1484
1485    LOG_FUNCTION_NAME;
1486
1487    if ( OMX_TRUE == caps.bVideoStabilizationSupported ) {
1488        params->set(CameraProperties::VSTAB_SUPPORTED, android::CameraParameters::TRUE);
1489    } else {
1490        params->set(CameraProperties::VSTAB_SUPPORTED, android::CameraParameters::FALSE);
1491    }
1492
1493    LOG_FUNCTION_NAME_EXIT;
1494
1495    return ret;
1496}
1497
1498status_t OMXCameraAdapter::insertLocks(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1499{
1500    status_t ret = NO_ERROR;
1501
1502    LOG_FUNCTION_NAME
1503
1504    if ( caps.bAELockSupported ) {
1505        params->set(CameraProperties::AUTO_EXPOSURE_LOCK_SUPPORTED, android::CameraParameters::TRUE);
1506    } else {
1507        params->set(CameraProperties::AUTO_EXPOSURE_LOCK_SUPPORTED, android::CameraParameters::FALSE);
1508    }
1509
1510    if ( caps.bAWBLockSupported ) {
1511        params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK_SUPPORTED, android::CameraParameters::TRUE);
1512    } else {
1513        params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK_SUPPORTED, android::CameraParameters::FALSE);
1514    }
1515
1516    LOG_FUNCTION_NAME_EXIT
1517
1518    return ret;
1519}
1520
1521status_t OMXCameraAdapter::insertSenMount(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1522{
1523    status_t ret = NO_ERROR;
1524    char supported[MAX_PROP_VALUE_LENGTH];
1525    const char *p;
1526    unsigned int i = 0;
1527
1528    LOG_FUNCTION_NAME;
1529
1530    memset(supported, '\0', sizeof(supported));
1531
1532    // 1) Look up and assign sensor name
1533    for (i = 0; i < ARRAY_SIZE(mSensorNames); i++) {
1534        if(mSensorNames[i].num == caps.tSenMounting.nSenId) {
1535            // sensor found
1536            break;
1537        }
1538    }
1539    if ( i == ARRAY_SIZE(mSensorNames) ) {
1540        p = "UNKNOWN_SENSOR";
1541    } else {
1542        p = mSensorNames[i].param;
1543    }
1544    strncat(supported, p, REMAINING_BYTES(supported));
1545    params->set(CameraProperties::CAMERA_NAME, supported);
1546    params->set(CameraProperties::CAMERA_SENSOR_ID, caps.tSenMounting.nSenId);
1547
1548    // 2) Assign mounting rotation
1549    params->set(CameraProperties::ORIENTATION_INDEX, caps.tSenMounting.nRotation);
1550
1551    LOG_FUNCTION_NAME_EXIT;
1552
1553    return ret;
1554}
1555
1556status_t OMXCameraAdapter::insertRaw(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1557
1558    status_t ret = NO_ERROR;
1559    char supported[MAX_PROP_VALUE_LENGTH];
1560    unsigned int i = 0;
1561
1562    LOG_FUNCTION_NAME;
1563
1564    memset(supported, '\0', sizeof(supported));
1565    sprintf(supported,"%d",int(caps.uSenNativeResWidth));
1566    params->set(CameraProperties::RAW_WIDTH, supported);
1567
1568    memset(supported, '\0', sizeof(supported));
1569    if (caps.bMechanicalMisalignmentSupported) {
1570        sprintf(supported,"%d",int(caps.uSenNativeResHeight) * 2);
1571    } else {
1572        sprintf(supported,"%d",int(caps.uSenNativeResHeight));
1573    }
1574    params->set(CameraProperties::RAW_HEIGHT, supported);
1575
1576    LOG_FUNCTION_NAME_EXIT;
1577
1578    return ret;
1579}
1580
1581status_t OMXCameraAdapter::insertFacing(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1582{
1583    status_t ret = NO_ERROR;
1584    char supported[MAX_PROP_VALUE_LENGTH];
1585    const char *p;
1586    unsigned int i = 0;
1587
1588    LOG_FUNCTION_NAME;
1589
1590    memset(supported, '\0', sizeof(supported));
1591
1592    for (i = 0; i < ARRAY_SIZE(mFacing); i++) {
1593        if((OMX_TI_SENFACING_TYPE)mFacing[i].num == caps.tSenMounting.eFacing) {
1594            break;
1595        }
1596    }
1597    if ( i == ARRAY_SIZE(mFacing) ) {
1598        p = "UNKNOWN_FACING";
1599    } else {
1600        p = mFacing[i].param;
1601    }
1602    strncat(supported, p, REMAINING_BYTES(supported));
1603    params->set(CameraProperties::FACING_INDEX, supported);
1604
1605    LOG_FUNCTION_NAME_EXIT;
1606
1607    return ret;
1608}
1609
1610status_t OMXCameraAdapter::insertFocalLength(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1611{
1612    status_t ret = NO_ERROR;
1613    char supported[MAX_PROP_VALUE_LENGTH];
1614
1615    LOG_FUNCTION_NAME;
1616
1617    memset(supported, '\0', sizeof(supported));
1618
1619    sprintf(supported, "%d", caps.nFocalLength / 100);
1620    strncat(supported, ".", REMAINING_BYTES(supported));
1621    sprintf(supported+(strlen(supported)*sizeof(char)), "%d", caps.nFocalLength % 100);
1622
1623    params->set(CameraProperties::FOCAL_LENGTH, supported);
1624
1625    LOG_FUNCTION_NAME_EXIT
1626
1627    return ret;
1628}
1629
1630status_t OMXCameraAdapter::insertAutoConvergenceModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1631{
1632    status_t ret = NO_ERROR;
1633    char supported[MAX_PROP_VALUE_LENGTH];
1634    const char *p;
1635    unsigned int i = 0;
1636
1637    LOG_FUNCTION_NAME;
1638
1639    memset(supported, '\0', sizeof(supported));
1640
1641    for ( unsigned int i = 0 ; i < caps.ulAutoConvModesCount; i++ ) {
1642        p = getLUTvalue_OMXtoHAL(caps.eAutoConvModes[i], mAutoConvergenceLUT);
1643        if ( NULL != p ) {
1644            if (supported[0] != '\0') {
1645                strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1646            }
1647            strncat(supported, p, REMAINING_BYTES(supported));
1648        }
1649    }
1650    params->set(CameraProperties::AUTOCONVERGENCE_MODE_VALUES, supported);
1651
1652    LOG_FUNCTION_NAME_EXIT;
1653
1654    return ret;
1655}
1656
1657status_t OMXCameraAdapter::insertManualConvergenceRange(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1658{
1659    status_t ret = NO_ERROR;
1660    char supported[MAX_PROP_VALUE_LENGTH];
1661
1662    LOG_FUNCTION_NAME;
1663
1664    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.nManualConvMin ));
1665    params->set(CameraProperties::SUPPORTED_MANUAL_CONVERGENCE_MIN, supported);
1666
1667    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.nManualConvMax ));
1668    params->set(CameraProperties::SUPPORTED_MANUAL_CONVERGENCE_MAX, supported);
1669
1670    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.nManualConvMax != caps.nManualConvMin ));
1671    params->set(CameraProperties::SUPPORTED_MANUAL_CONVERGENCE_STEP, supported);
1672
1673    LOG_FUNCTION_NAME_EXIT;
1674
1675    return ret;
1676}
1677
1678status_t OMXCameraAdapter::insertMechanicalMisalignmentCorrection(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1679{
1680    LOG_FUNCTION_NAME;
1681
1682    params->set(CameraProperties::MECHANICAL_MISALIGNMENT_CORRECTION_SUPPORTED,
1683            caps.bMechanicalMisalignmentSupported == OMX_TRUE ?
1684            android::CameraParameters::TRUE : android::CameraParameters::FALSE);
1685
1686    return OK;
1687}
1688
1689status_t OMXCameraAdapter::insertCaptureModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1690{
1691    status_t ret = NO_ERROR;
1692    char supported[MAX_PROP_VALUE_LENGTH];
1693    const char *p;
1694
1695    LOG_FUNCTION_NAME;
1696
1697    memset(supported, '\0', sizeof(supported));
1698
1699    // 3D mode detect: Misalignment is present only in 3d mode
1700    if (caps.bMechanicalMisalignmentSupported)
1701    {
1702        strncat(supported, TICameraParameters::HIGH_QUALITY_MODE, REMAINING_BYTES(supported));
1703        strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1704        strncat(supported, TICameraParameters::VIDEO_MODE, REMAINING_BYTES(supported));
1705    }
1706    else // 2D mode detect: Misalignment is present only in 3d mode
1707    {
1708        strncat(supported, TICameraParameters::HIGH_QUALITY_MODE, REMAINING_BYTES(supported));
1709        strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1710        strncat(supported, TICameraParameters::VIDEO_MODE, REMAINING_BYTES(supported));
1711        strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1712        strncat(supported, TICameraParameters::HIGH_PERFORMANCE_MODE, REMAINING_BYTES(supported));
1713        strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1714        strncat(supported, TICameraParameters::HIGH_QUALITY_ZSL_MODE, REMAINING_BYTES(supported));
1715#ifdef OMAP_ENHANCEMENT_CPCAM
1716        strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1717        strncat(supported, TICameraParameters::CP_CAM_MODE, REMAINING_BYTES(supported));
1718#endif
1719#ifdef  CAMERAHAL_OMAP5_CAPTURE_MODES
1720        strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1721        strncat(supported, TICameraParameters::VIDEO_MODE_HQ, REMAINING_BYTES(supported));
1722#endif
1723        strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1724        strncat(supported, TICameraParameters::ZOOM_BRACKETING, REMAINING_BYTES(supported));
1725    }
1726
1727    for ( unsigned int i = 0 ; i < caps.ulBracketingModesCount; i++ ) {
1728        p = getLUTvalue_OMXtoHAL(caps.eBracketingModes[i], mBracketingModesLUT);
1729        if ( NULL != p ) {
1730            if (supported[0] != '\0') {
1731                strncat(supported, PARAM_SEP, REMAINING_BYTES(supported));
1732            }
1733            strncat(supported, p, REMAINING_BYTES(supported));
1734        }
1735    }
1736
1737    params->set(CameraProperties::CAP_MODE_VALUES, supported);
1738
1739    LOG_FUNCTION_NAME_EXIT;
1740
1741    return ret;
1742}
1743
1744status_t OMXCameraAdapter::insertLayout(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1745{
1746    status_t ret = NO_ERROR;
1747    char supported[MAX_PROP_VALUE_LENGTH];
1748    const char *p;
1749    unsigned int i = 0;
1750
1751    LOG_FUNCTION_NAME;
1752
1753    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1754    for ( unsigned int i = 0 ; i < caps.ulPrvFrameLayoutCount; i++ ) {
1755        p = getLUTvalue_OMXtoHAL(caps.ePrvFrameLayout[i], mLayoutLUT);
1756        if ( NULL != p ) {
1757            if (supported[0] != '\0') {
1758                strncat(supported, PARAM_SEP, 1);
1759            }
1760            strncat(supported, p, MAX_PROP_NAME_LENGTH);
1761        }
1762    }
1763    params->set(CameraProperties::S3D_PRV_FRAME_LAYOUT_VALUES, supported);
1764
1765    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1766    for ( unsigned int i = 0 ; i < caps.ulCapFrameLayoutCount; i++ ) {
1767        p = getLUTvalue_OMXtoHAL(caps.eCapFrameLayout[i], mLayoutLUT);
1768        if ( NULL != p ) {
1769            if (supported[0] != '\0') {
1770                strncat(supported, PARAM_SEP, 1);
1771            }
1772            strncat(supported, p, MAX_PROP_NAME_LENGTH);
1773        }
1774    }
1775    params->set(CameraProperties::S3D_CAP_FRAME_LAYOUT_VALUES, supported);
1776
1777    LOG_FUNCTION_NAME_EXIT;
1778
1779    return ret;
1780}
1781
1782status_t OMXCameraAdapter::insertVideoSnapshotSupported(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1783{
1784    status_t ret = NO_ERROR;
1785
1786    LOG_FUNCTION_NAME;
1787
1788    if (caps.bStillCapDuringVideoSupported)
1789    {
1790        params->set(CameraProperties::VIDEO_SNAPSHOT_SUPPORTED, android::CameraParameters::TRUE);
1791    }
1792    else
1793    {
1794        params->set(CameraProperties::VIDEO_SNAPSHOT_SUPPORTED, android::CameraParameters::FALSE);
1795    }
1796
1797    LOG_FUNCTION_NAME_EXIT;
1798
1799    return ret;
1800}
1801
1802status_t OMXCameraAdapter::insertGBCESupported(CameraProperties::Properties* params,
1803                                               const OMX_TI_CAPTYPE &caps)
1804{
1805    status_t ret = NO_ERROR;
1806
1807    LOG_FUNCTION_NAME;
1808
1809    if (caps.bGbceSupported) {
1810        params->set(CameraProperties::SUPPORTED_GBCE,
1811                    android::CameraParameters::TRUE);
1812    } else {
1813        params->set(CameraProperties::SUPPORTED_GBCE,
1814                    android::CameraParameters::FALSE);
1815    }
1816
1817    LOG_FUNCTION_NAME_EXIT;
1818
1819    return ret;
1820}
1821
1822status_t OMXCameraAdapter::insertGLBCESupported(CameraProperties::Properties* params,
1823                                                const OMX_TI_CAPTYPE &caps)
1824{
1825    status_t ret = NO_ERROR;
1826
1827    LOG_FUNCTION_NAME;
1828
1829    if (caps.bGlbceSupported) {
1830        params->set(CameraProperties::SUPPORTED_GLBCE,
1831                    android::CameraParameters::TRUE);
1832    } else {
1833        params->set(CameraProperties::SUPPORTED_GLBCE,
1834                    android::CameraParameters::FALSE);
1835    }
1836
1837    LOG_FUNCTION_NAME_EXIT;
1838
1839    return ret;
1840}
1841
1842status_t OMXCameraAdapter::insertDefaults(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
1843{
1844    status_t ret = NO_ERROR;
1845    char *pos, *str, *def;
1846    char temp[MAX_PROP_VALUE_LENGTH];
1847
1848    LOG_FUNCTION_NAME;
1849
1850    /* If default is supported - set it, else - set first supported */
1851    if (strstr(params->get(CameraProperties::S3D_PRV_FRAME_LAYOUT_VALUES), DEFAULT_S3D_PREVIEW_LAYOUT)) {
1852        strncpy(temp, DEFAULT_S3D_PREVIEW_LAYOUT, MAX_PROP_VALUE_LENGTH - 1);
1853    } else {
1854        strncpy(temp, params->get(CameraProperties::S3D_PRV_FRAME_LAYOUT_VALUES),
1855                    MAX_PROP_VALUE_LENGTH - 1);
1856        if ((pos = strstr(temp, PARAM_SEP))) {
1857            *pos = '\0';
1858        }
1859    }
1860    params->set(CameraProperties::S3D_PRV_FRAME_LAYOUT, temp);
1861
1862    if (!strcmp(TICameraParameters::S3D_TB_FULL, temp)) {
1863        params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, params->get(CameraProperties::SUPPORTED_PREVIEW_TOPBOTTOM_SIZES));
1864    } else if (!strcmp(TICameraParameters::S3D_SS_FULL, temp)) {
1865        params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, params->get(CameraProperties::SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES));
1866    } else if ((!strcmp(TICameraParameters::S3D_TB_SUBSAMPLED, temp))
1867              || (!strcmp(TICameraParameters::S3D_SS_SUBSAMPLED, temp))) {
1868        params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, params->get(CameraProperties::SUPPORTED_PREVIEW_SUBSAMPLED_SIZES));
1869    }
1870
1871    /* If default is supported - set it, else - set first supported */
1872    if (strstr(params->get(CameraProperties::S3D_CAP_FRAME_LAYOUT_VALUES), DEFAULT_S3D_PICTURE_LAYOUT)) {
1873        strncpy(temp, DEFAULT_S3D_PICTURE_LAYOUT, MAX_PROP_VALUE_LENGTH - 1);
1874    } else {
1875        strncpy(temp, params->get(CameraProperties::S3D_CAP_FRAME_LAYOUT_VALUES),
1876                    MAX_PROP_VALUE_LENGTH - 1);
1877        if ((pos = strstr(temp, PARAM_SEP))) {
1878            *pos = '\0';
1879        }
1880    }
1881    params->set(CameraProperties::S3D_CAP_FRAME_LAYOUT, temp);
1882
1883    if (!strcmp(TICameraParameters::S3D_TB_FULL, temp)) {
1884        params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, params->get(CameraProperties::SUPPORTED_PICTURE_TOPBOTTOM_SIZES));
1885    } else if (!strcmp(TICameraParameters::S3D_SS_FULL, temp)) {
1886        params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, params->get(CameraProperties::SUPPORTED_PICTURE_SIDEBYSIDE_SIZES));
1887    } else if ((!strcmp(TICameraParameters::S3D_TB_SUBSAMPLED, temp))
1888              || (!strcmp(TICameraParameters::S3D_SS_SUBSAMPLED, temp))) {
1889        params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, params->get(CameraProperties::SUPPORTED_PICTURE_SUBSAMPLED_SIZES));
1890    }
1891
1892    params->set(CameraProperties::ANTIBANDING, DEFAULT_ANTIBANDING);
1893    params->set(CameraProperties::BRIGHTNESS, DEFAULT_BRIGHTNESS);
1894    params->set(CameraProperties::CONTRAST, DEFAULT_CONTRAST);
1895    params->set(CameraProperties::EFFECT, DEFAULT_EFFECT);
1896    params->set(CameraProperties::EV_COMPENSATION, DEFAULT_EV_COMPENSATION);
1897    params->set(CameraProperties::SUPPORTED_EV_STEP, DEFAULT_EV_STEP);
1898    params->set(CameraProperties::EXPOSURE_MODE, DEFAULT_EXPOSURE_MODE);
1899    params->set(CameraProperties::FLASH_MODE, DEFAULT_FLASH_MODE);
1900    pos = strstr(params->get(CameraProperties::SUPPORTED_FOCUS_MODES), DEFAULT_FOCUS_MODE_PREFERRED);
1901    if ( NULL != pos )
1902        {
1903        params->set(CameraProperties::FOCUS_MODE, DEFAULT_FOCUS_MODE_PREFERRED);
1904        }
1905    else
1906        {
1907        params->set(CameraProperties::FOCUS_MODE, DEFAULT_FOCUS_MODE);
1908        }
1909    params->set(CameraProperties::IPP, DEFAULT_IPP);
1910    params->set(CameraProperties::GBCE, android::CameraParameters::FALSE);
1911    params->set(CameraProperties::GLBCE, android::CameraParameters::FALSE);
1912    params->set(CameraProperties::ISO_MODE, DEFAULT_ISO_MODE);
1913    params->set(CameraProperties::JPEG_QUALITY, DEFAULT_JPEG_QUALITY);
1914    params->set(CameraProperties::JPEG_THUMBNAIL_QUALITY, DEFAULT_THUMBNAIL_QUALITY);
1915    params->set(CameraProperties::JPEG_THUMBNAIL_SIZE, DEFAULT_THUMBNAIL_SIZE);
1916    params->set(CameraProperties::PICTURE_FORMAT, DEFAULT_PICTURE_FORMAT);
1917
1918    if (!strcmp(params->get(CameraProperties::S3D_CAP_FRAME_LAYOUT),
1919                TICameraParameters::S3D_TB_FULL)) {
1920        params->set(CameraProperties::PICTURE_SIZE, DEFAULT_PICTURE_TB_SIZE);
1921    } else if (!strcmp(params->get(CameraProperties::S3D_CAP_FRAME_LAYOUT),
1922                TICameraParameters::S3D_SS_FULL)) {
1923        params->set(CameraProperties::PICTURE_SIZE, DEFAULT_PICTURE_SS_SIZE);
1924    } else {
1925        params->set(CameraProperties::PICTURE_SIZE, DEFAULT_PICTURE_SIZE);
1926    }
1927
1928    if (!strcmp(params->get(CameraProperties::S3D_PRV_FRAME_LAYOUT),
1929                TICameraParameters::S3D_TB_FULL)) {
1930        params->set(CameraProperties::PREVIEW_SIZE, DEFAULT_PREVIEW_TB_SIZE);
1931    } else if (!strcmp(params->get(CameraProperties::S3D_PRV_FRAME_LAYOUT),
1932                TICameraParameters::S3D_SS_FULL)) {
1933        params->set(CameraProperties::PREVIEW_SIZE, DEFAULT_PREVIEW_SS_SIZE);
1934    } else {
1935        params->set(CameraProperties::PREVIEW_SIZE, DEFAULT_PREVIEW_SIZE);
1936    }
1937
1938    params->set(CameraProperties::PREVIEW_FORMAT, DEFAULT_PREVIEW_FORMAT);
1939
1940    /* Set default value if supported, otherwise set max supported value */
1941    strncpy(temp, params->get(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES),
1942            MAX_PROP_VALUE_LENGTH - 1);
1943    def = str = temp;
1944    while (1) {
1945        if ((pos = strstr(str, PARAM_SEP))) {
1946            *pos = '\0';
1947        }
1948        if (!strcmp(str, DEFAULT_FRAMERATE)) {
1949            def = str;
1950            break;
1951        }
1952        if (atoi(str) > atoi(def)) {
1953            def = str;
1954        }
1955        if (pos == NULL) {
1956            break;
1957        }
1958        str = pos + strlen(PARAM_SEP);
1959    }
1960    params->set(CameraProperties::PREVIEW_FRAME_RATE, def);
1961
1962    params->set(CameraProperties::REQUIRED_PREVIEW_BUFS, DEFAULT_NUM_PREV_BUFS);
1963    params->set(CameraProperties::REQUIRED_IMAGE_BUFS, DEFAULT_NUM_PIC_BUFS);
1964    params->set(CameraProperties::SATURATION, DEFAULT_SATURATION);
1965    params->set(CameraProperties::SCENE_MODE, DEFAULT_SCENE_MODE);
1966    params->set(CameraProperties::SHARPNESS, DEFAULT_SHARPNESS);
1967    params->set(CameraProperties::VSTAB, DEFAULT_VSTAB);
1968    params->set(CameraProperties::VNF, DEFAULT_VNF);
1969    params->set(CameraProperties::WHITEBALANCE, DEFAULT_WB);
1970    params->set(CameraProperties::ZOOM, DEFAULT_ZOOM);
1971    params->set(CameraProperties::MAX_FD_HW_FACES, DEFAULT_MAX_FD_HW_FACES);
1972    params->set(CameraProperties::MAX_FD_SW_FACES, DEFAULT_MAX_FD_SW_FACES);
1973    params->set(CameraProperties::AUTO_EXPOSURE_LOCK, DEFAULT_AE_LOCK);
1974    params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK, DEFAULT_AWB_LOCK);
1975    params->set(CameraProperties::HOR_ANGLE, DEFAULT_HOR_ANGLE);
1976    params->set(CameraProperties::VER_ANGLE, DEFAULT_VER_ANGLE);
1977    params->set(CameraProperties::VIDEO_SIZE, DEFAULT_VIDEO_SIZE);
1978    params->set(CameraProperties::SENSOR_ORIENTATION, DEFAULT_SENSOR_ORIENTATION);
1979    params->set(CameraProperties::AUTOCONVERGENCE_MODE, DEFAULT_AUTOCONVERGENCE_MODE);
1980    params->set(CameraProperties::MANUAL_CONVERGENCE, DEFAULT_MANUAL_CONVERGENCE);
1981    params->set(CameraProperties::MECHANICAL_MISALIGNMENT_CORRECTION, DEFAULT_MECHANICAL_MISALIGNMENT_CORRECTION_MODE);
1982
1983    char property[PROPERTY_VALUE_MAX];
1984    property_get("ro.product.manufacturer",
1985                 property,
1986                 DEFAULT_EXIF_MAKE);
1987    property[0] = toupper(property[0]);
1988    params->set(CameraProperties::EXIF_MAKE, property);
1989    property_get("ro.product.model",
1990                 property,
1991                 DEFAULT_EXIF_MODEL);
1992    property[0] = toupper(property[0]);
1993    params->set(CameraProperties::EXIF_MODEL, property);
1994
1995    LOG_FUNCTION_NAME_EXIT;
1996
1997    return ret;
1998}
1999
2000status_t OMXCameraAdapter::insertCapabilities(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
2001{
2002    status_t ret = NO_ERROR;
2003
2004    LOG_FUNCTION_NAME;
2005
2006    if ( NO_ERROR == ret ) {
2007        ret = insertImageSizes(params, caps);
2008    }
2009
2010    if ( NO_ERROR == ret ) {
2011        ret = insertPreviewSizes(params, caps);
2012    }
2013
2014    if ( NO_ERROR == ret ) {
2015        ret = insertThumbSizes(params, caps);
2016    }
2017
2018    if ( NO_ERROR == ret ) {
2019        ret = insertZoomStages(params, caps);
2020    }
2021
2022    if ( NO_ERROR == ret ) {
2023        ret = insertImageFormats(params, caps);
2024    }
2025
2026    if ( NO_ERROR == ret ) {
2027        ret = insertPreviewFormats(params, caps);
2028    }
2029
2030    if ( NO_ERROR == ret ) {
2031        ret = insertFramerates(params, caps);
2032    }
2033
2034    if ( NO_ERROR == ret ) {
2035        ret = insertEVs(params, caps);
2036    }
2037
2038    if ( NO_ERROR == ret ) {
2039        ret = insertISOModes(params, caps);
2040    }
2041
2042    if ( NO_ERROR == ret ) {
2043        ret = insertIPPModes(params, caps);
2044    }
2045
2046    if ( NO_ERROR == ret ) {
2047        ret = insertWBModes(params, caps);
2048    }
2049
2050    if ( NO_ERROR == ret ) {
2051        ret = insertEffects(params, caps);
2052    }
2053
2054    if ( NO_ERROR == ret ) {
2055        ret = insertExpModes(params, caps);
2056    }
2057
2058    if ( NO_ERROR == ret ) {
2059        ret = insertManualExpRanges(params, caps);
2060    }
2061
2062    if ( NO_ERROR == ret ) {
2063        ret = insertFlashModes(params, caps);
2064    }
2065
2066    if ( NO_ERROR == ret ) {
2067        ret = insertSceneModes(params, caps);
2068    }
2069
2070    if ( NO_ERROR == ret ) {
2071        ret = insertFocusModes(params, caps);
2072    }
2073
2074    if ( NO_ERROR == ret ) {
2075        ret = insertFlickerModes(params, caps);
2076    }
2077
2078    if ( NO_ERROR == ret ) {
2079        ret = insertSenMount(params, caps);
2080    }
2081
2082    if ( NO_ERROR == ret ) {
2083        ret = insertLocks(params, caps);
2084    }
2085
2086    if ( NO_ERROR == ret) {
2087        ret = insertAreas(params, caps);
2088    }
2089
2090    if ( NO_ERROR == ret) {
2091        ret = insertFacing(params, caps);
2092    }
2093
2094    if ( NO_ERROR == ret) {
2095        ret = insertFocalLength(params, caps);
2096    }
2097
2098    if ( NO_ERROR == ret) {
2099        ret = insertAutoConvergenceModes(params, caps);
2100    }
2101
2102    if ( NO_ERROR == ret) {
2103        ret = insertManualConvergenceRange(params, caps);
2104    }
2105
2106    if ( NO_ERROR == ret) {
2107        ret = insertMechanicalMisalignmentCorrection(params, caps);
2108    }
2109
2110    if ( NO_ERROR == ret) {
2111        ret = insertRaw(params, caps);
2112    }
2113
2114    if ( NO_ERROR == ret) {
2115        ret = insertCaptureModes(params, caps);
2116    }
2117
2118    if ( NO_ERROR == ret) {
2119        ret = insertLayout(params, caps);
2120    }
2121
2122    if ( NO_ERROR == ret) {
2123        ret = insertVideoSnapshotSupported(params, caps);
2124    }
2125
2126    if ( NO_ERROR == ret ) {
2127        ret = insertVSTABSupported(params, caps);
2128    }
2129
2130    if ( NO_ERROR == ret) {
2131        ret = insertVNFSupported(params, caps);
2132    }
2133
2134    //NOTE: Ensure that we always call insertDefaults after inserting the supported capabilities
2135    //as there are checks inside insertDefaults to make sure a certain default is supported
2136    // or not
2137    if ( NO_ERROR == ret ) {
2138        ret = insertVideoSizes(params, caps);
2139    }
2140
2141    if ( NO_ERROR == ret) {
2142        ret = insertGBCESupported(params, caps);
2143    }
2144
2145    if ( NO_ERROR == ret) {
2146        ret = insertGLBCESupported(params, caps);
2147    }
2148
2149    if ( NO_ERROR == ret ) {
2150        ret = insertDefaults(params, caps);
2151    }
2152
2153    LOG_FUNCTION_NAME_EXIT;
2154
2155    return ret;
2156}
2157
2158
2159bool OMXCameraAdapter::_checkOmxTiCap(const OMX_TI_CAPTYPE & caps)
2160{
2161#define CAMHAL_CHECK_OMX_TI_CAP(countVar, arrayVar)              \
2162    do {                                                         \
2163        const int count = static_cast<int>(caps.countVar);  \
2164        const int maxSize = CAMHAL_SIZE_OF_ARRAY(caps.arrayVar); \
2165        if ( count < 0 || count > maxSize )                      \
2166        {                                                        \
2167            CAMHAL_LOGE("OMX_TI_CAPTYPE verification failed");   \
2168            CAMHAL_LOGE("  variable: OMX_TI_CAPTYPE::" #countVar \
2169                    ", value: %d, max allowed: %d",              \
2170                    count, maxSize);                             \
2171            return false;                                        \
2172        }                                                        \
2173    } while (0)
2174
2175    CAMHAL_CHECK_OMX_TI_CAP(ulPreviewFormatCount, ePreviewFormats);
2176    CAMHAL_CHECK_OMX_TI_CAP(ulImageFormatCount, eImageFormats);
2177    CAMHAL_CHECK_OMX_TI_CAP(ulWhiteBalanceCount, eWhiteBalanceModes);
2178    CAMHAL_CHECK_OMX_TI_CAP(ulColorEffectCount, eColorEffects);
2179    CAMHAL_CHECK_OMX_TI_CAP(ulFlickerCount, eFlicker);
2180    CAMHAL_CHECK_OMX_TI_CAP(ulExposureModeCount, eExposureModes);
2181    CAMHAL_CHECK_OMX_TI_CAP(ulFocusModeCount, eFocusModes);
2182    CAMHAL_CHECK_OMX_TI_CAP(ulSceneCount, eSceneModes);
2183    CAMHAL_CHECK_OMX_TI_CAP(ulFlashCount, eFlashModes);
2184    CAMHAL_CHECK_OMX_TI_CAP(ulPrvVarFPSModesCount, tPrvVarFPSModes);
2185    CAMHAL_CHECK_OMX_TI_CAP(ulCapVarFPSModesCount, tCapVarFPSModes);
2186    CAMHAL_CHECK_OMX_TI_CAP(ulAutoConvModesCount, eAutoConvModes);
2187    CAMHAL_CHECK_OMX_TI_CAP(ulBracketingModesCount, eBracketingModes);
2188    CAMHAL_CHECK_OMX_TI_CAP(ulImageCodingFormatCount, eImageCodingFormat);
2189    CAMHAL_CHECK_OMX_TI_CAP(ulPrvFrameLayoutCount, ePrvFrameLayout);
2190    CAMHAL_CHECK_OMX_TI_CAP(ulCapFrameLayoutCount, eCapFrameLayout);
2191
2192#undef CAMHAL_CHECK_OMX_TI_CAP
2193
2194    return true;
2195}
2196
2197
2198bool OMXCameraAdapter::_dumpOmxTiCap(const int sensorId, const OMX_TI_CAPTYPE & caps)
2199{
2200    if ( !_checkOmxTiCap(caps) )
2201    {
2202        CAMHAL_LOGE("OMX_TI_CAPTYPE structure is invalid");
2203        return false;
2204    }
2205
2206    CAMHAL_LOGD("===================================================");
2207    CAMHAL_LOGD("---- Dumping OMX capabilities for sensor id: %d ----", sensorId);
2208
2209    CAMHAL_LOGD("");
2210    CAMHAL_LOGD("ulPreviewFormatCount = %d", int(caps.ulPreviewFormatCount));
2211    for ( int i = 0; i < int(caps.ulPreviewFormatCount); ++i )
2212        CAMHAL_LOGD("  ePreviewFormats[%2d] = %d", i, int(caps.ePreviewFormats[i]));
2213
2214    CAMHAL_LOGD("");
2215    CAMHAL_LOGD("ulImageFormatCount = %d", int(caps.ulImageFormatCount));
2216    for ( int i = 0; i < int(caps.ulImageFormatCount); ++i )
2217        CAMHAL_LOGD("  eImageFormats[%2d] = %d", i, int(caps.eImageFormats[i]));
2218
2219    CAMHAL_LOGD("");
2220    CAMHAL_LOGD("tPreviewResRange.nWidthMin  = %d", int(caps.tPreviewResRange.nWidthMin));
2221    CAMHAL_LOGD("tPreviewResRange.nHeightMin = %d", int(caps.tPreviewResRange.nHeightMin));
2222    CAMHAL_LOGD("tPreviewResRange.nWidthMax  = %d", int(caps.tPreviewResRange.nWidthMax));
2223    CAMHAL_LOGD("tPreviewResRange.nHeightMax = %d", int(caps.tPreviewResRange.nHeightMax));
2224    CAMHAL_LOGD("tPreviewResRange.nMaxResInPixels = %d", int(caps.tPreviewResRange.nMaxResInPixels));
2225
2226    CAMHAL_LOGD("");
2227    CAMHAL_LOGD("tRotatedPreviewResRange.nWidthMin  = %d", int(caps.tRotatedPreviewResRange.nWidthMin));
2228    CAMHAL_LOGD("tRotatedPreviewResRange.nHeightMin = %d", int(caps.tRotatedPreviewResRange.nHeightMin));
2229    CAMHAL_LOGD("tRotatedPreviewResRange.nWidthMax  = %d", int(caps.tRotatedPreviewResRange.nWidthMax));
2230    CAMHAL_LOGD("tRotatedPreviewResRange.nHeightMax = %d", int(caps.tRotatedPreviewResRange.nHeightMax));
2231    CAMHAL_LOGD("tRotatedPreviewResRange.nMaxResInPixels = %d", int(caps.tRotatedPreviewResRange.nMaxResInPixels));
2232
2233    CAMHAL_LOGD("");
2234    CAMHAL_LOGD("tImageResRange.nWidthMin  = %d", int(caps.tImageResRange.nWidthMin));
2235    CAMHAL_LOGD("tImageResRange.nHeightMin = %d", int(caps.tImageResRange.nHeightMin));
2236    CAMHAL_LOGD("tImageResRange.nWidthMax  = %d", int(caps.tImageResRange.nWidthMax));
2237    CAMHAL_LOGD("tImageResRange.nHeightMax = %d", int(caps.tImageResRange.nHeightMax));
2238    CAMHAL_LOGD("tImageResRange.nMaxResInPixels = %d", int(caps.tImageResRange.nMaxResInPixels));
2239
2240    CAMHAL_LOGD("");
2241    CAMHAL_LOGD("tThumbResRange.nWidthMin  = %d", int(caps.tThumbResRange.nWidthMin));
2242    CAMHAL_LOGD("tThumbResRange.nHeightMin = %d", int(caps.tThumbResRange.nHeightMin));
2243    CAMHAL_LOGD("tThumbResRange.nWidthMax  = %d", int(caps.tThumbResRange.nWidthMax));
2244    CAMHAL_LOGD("tThumbResRange.nHeightMax = %d", int(caps.tThumbResRange.nHeightMax));
2245    CAMHAL_LOGD("tThumbResRange.nMaxResInPixels = %d", int(caps.tThumbResRange.nMaxResInPixels));
2246
2247    CAMHAL_LOGD("");
2248    CAMHAL_LOGD("ulWhiteBalanceCount = %d", int(caps.ulWhiteBalanceCount));
2249    for ( int i = 0; i < int(caps.ulWhiteBalanceCount); ++i )
2250        CAMHAL_LOGD("  eWhiteBalanceModes[%2d] = 0x%08x", i, int(caps.eWhiteBalanceModes[i]));
2251
2252    CAMHAL_LOGD("");
2253    CAMHAL_LOGD("ulColorEffectCount = %d", int(caps.ulColorEffectCount));
2254    for ( int i = 0; i < int(caps.ulColorEffectCount); ++i )
2255        CAMHAL_LOGD("  eColorEffects[%2d] = 0x%08x", i, int(caps.eColorEffects[i]));
2256
2257    CAMHAL_LOGD("");
2258    CAMHAL_LOGD("xMaxWidthZoom  = %d", int(caps.xMaxWidthZoom));
2259    CAMHAL_LOGD("xMaxHeightZoom = %d", int(caps.xMaxHeightZoom));
2260
2261    CAMHAL_LOGD("");
2262    CAMHAL_LOGD("ulFlickerCount = %d", int(caps.ulFlickerCount));
2263    for ( int i = 0; i < int(caps.ulFlickerCount); ++i )
2264        CAMHAL_LOGD("  eFlicker[%2d] = %d", i, int(caps.eFlicker[i]));
2265
2266    CAMHAL_LOGD("");
2267    CAMHAL_LOGD("ulExposureModeCount = %d", int(caps.ulExposureModeCount));
2268    for ( int i = 0; i < int(caps.ulExposureModeCount); ++i )
2269        CAMHAL_LOGD("  eExposureModes[%2d] = 0x%08x", i, int(caps.eExposureModes[i]));
2270
2271    CAMHAL_LOGD("");
2272    CAMHAL_LOGD("bLensDistortionCorrectionSupported = %d", int(caps.bLensDistortionCorrectionSupported));
2273    CAMHAL_LOGD("bISONoiseFilterSupported = %d", int(caps.bISONoiseFilterSupported));
2274    CAMHAL_LOGD("xEVCompensationMin = %d", int(caps.xEVCompensationMin));
2275    CAMHAL_LOGD("xEVCompensationMax = %d", int(caps.xEVCompensationMax));
2276    CAMHAL_LOGD("nSensitivityMax = %d", int(caps.nSensitivityMax));
2277
2278    CAMHAL_LOGD("");
2279    CAMHAL_LOGD("ulFocusModeCount = %d", int(caps.ulFocusModeCount));
2280    for ( int i = 0; i < int(caps.ulFocusModeCount); ++i )
2281        CAMHAL_LOGD("  eFocusModes[%2d] = 0x%08x", i, int(caps.eFocusModes[i]));
2282
2283    CAMHAL_LOGD("");
2284    CAMHAL_LOGD("ulSceneCount = %d", int(caps.ulSceneCount));
2285    for ( int i = 0; i < int(caps.ulSceneCount); ++i )
2286        CAMHAL_LOGD("  eSceneModes[%2d] = %d", i, int(caps.eSceneModes[i]));
2287
2288    CAMHAL_LOGD("");
2289    CAMHAL_LOGD("ulFlashCount = %d", int(caps.ulFlashCount));
2290    for ( int i = 0; i < int(caps.ulFlashCount); ++i )
2291        CAMHAL_LOGD("  eFlashModes[%2d] = %d", i, int(caps.eFlashModes[i]));
2292
2293    CAMHAL_LOGD("xFramerateMin = %d", int(caps.xFramerateMin));
2294    CAMHAL_LOGD("xFramerateMax = %d", int(caps.xFramerateMax));
2295    CAMHAL_LOGD("bContrastSupported = %d", int(caps.bContrastSupported));
2296    CAMHAL_LOGD("bSaturationSupported = %d", int(caps.bSaturationSupported));
2297    CAMHAL_LOGD("bBrightnessSupported = %d", int(caps.bBrightnessSupported));
2298    CAMHAL_LOGD("bProcessingLevelSupported = %d", int(caps.bProcessingLevelSupported));
2299    CAMHAL_LOGD("bQFactorSupported = %d", int(caps.bQFactorSupported));
2300
2301    CAMHAL_LOGD("");
2302    CAMHAL_LOGD("ulPrvVarFPSModesCount = %d", int(caps.ulPrvVarFPSModesCount));
2303    for ( int i = 0; i < int(caps.ulPrvVarFPSModesCount); ++i )
2304    {
2305        CAMHAL_LOGD("  tPrvVarFPSModes[%d].nVarFPSMin = %d", i, int(caps.tPrvVarFPSModes[i].nVarFPSMin));
2306        CAMHAL_LOGD("  tPrvVarFPSModes[%d].nVarFPSMax = %d", i, int(caps.tPrvVarFPSModes[i].nVarFPSMax));
2307    }
2308
2309    CAMHAL_LOGD("");
2310    CAMHAL_LOGD("ulCapVarFPSModesCount = %d", int(caps.ulCapVarFPSModesCount));
2311    for ( int i = 0; i < int(caps.ulCapVarFPSModesCount); ++i )
2312    {
2313        CAMHAL_LOGD("  tCapVarFPSModes[%d].nVarFPSMin = %d", i, int(caps.tCapVarFPSModes[i].nVarFPSMin));
2314        CAMHAL_LOGD("  tCapVarFPSModes[%d].nVarFPSMax = %d", i, int(caps.tCapVarFPSModes[i].nVarFPSMax));
2315    }
2316
2317    CAMHAL_LOGD("");
2318    CAMHAL_LOGD("tSenMounting.nSenId    = %d", int(caps.tSenMounting.nSenId));
2319    CAMHAL_LOGD("tSenMounting.nRotation = %d", int(caps.tSenMounting.nRotation));
2320    CAMHAL_LOGD("tSenMounting.bMirror   = %d", int(caps.tSenMounting.bMirror));
2321    CAMHAL_LOGD("tSenMounting.bFlip     = %d", int(caps.tSenMounting.bFlip));
2322    CAMHAL_LOGD("tSenMounting.eFacing   = %d", int(caps.tSenMounting.eFacing));
2323
2324    CAMHAL_LOGD("");
2325    CAMHAL_LOGD("ulAutoConvModesCount = %d", int(caps.ulAutoConvModesCount));
2326    for ( int i = 0; i < int(caps.ulAutoConvModesCount); ++i )
2327        CAMHAL_LOGD("  eAutoConvModes[%2d] = %d", i, int(caps.eAutoConvModes[i]));
2328
2329    CAMHAL_LOGD("");
2330    CAMHAL_LOGD("ulBracketingModesCount = %d", int(caps.ulBracketingModesCount));
2331    for ( int i = 0; i < int(caps.ulBracketingModesCount); ++i )
2332        CAMHAL_LOGD("  eBracketingModes[%2d] = %d", i, int(caps.eBracketingModes[i]));
2333
2334    CAMHAL_LOGD("");
2335    CAMHAL_LOGD("bGbceSupported    = %d", int(caps.bGbceSupported));
2336    CAMHAL_LOGD("bRawJpegSupported = %d", int(caps.bRawJpegSupported));
2337
2338    CAMHAL_LOGD("");
2339    CAMHAL_LOGD("ulImageCodingFormatCount = %d", int(caps.ulImageCodingFormatCount));
2340    for ( int i = 0; i < int(caps.ulImageCodingFormatCount); ++i )
2341        CAMHAL_LOGD("  eImageCodingFormat[%2d] = %d", i, int(caps.eImageCodingFormat[i]));
2342
2343    CAMHAL_LOGD("");
2344    CAMHAL_LOGD("uSenNativeResWidth       = %d", int(caps.uSenNativeResWidth));
2345    CAMHAL_LOGD("uSenNativeResHeight      = %d", int(caps.uSenNativeResHeight));
2346    CAMHAL_LOGD("ulAlgoAreasFocusCount    = %d", int(caps.ulAlgoAreasFocusCount));
2347    CAMHAL_LOGD("ulAlgoAreasExposureCount = %d", int(caps.ulAlgoAreasExposureCount));
2348    CAMHAL_LOGD("bAELockSupported         = %d", int(caps.bAELockSupported));
2349    CAMHAL_LOGD("bAWBLockSupported        = %d", int(caps.bAWBLockSupported));
2350    CAMHAL_LOGD("bAFLockSupported         = %d", int(caps.bAFLockSupported));
2351    CAMHAL_LOGD("nFocalLength             = %d", int(caps.nFocalLength));
2352
2353    CAMHAL_LOGD("");
2354    CAMHAL_LOGD("ulPrvFrameLayoutCount = %d", int(caps.ulPrvFrameLayoutCount));
2355    for ( int i = 0; i < int(caps.ulPrvFrameLayoutCount); ++i )
2356        CAMHAL_LOGD("  ePrvFrameLayout[%2d] = %d", i, int(caps.ePrvFrameLayout[i]));
2357
2358    CAMHAL_LOGD("");
2359    CAMHAL_LOGD("ulCapFrameLayoutCount = %d", int(caps.ulCapFrameLayoutCount));
2360    for ( int i = 0; i < int(caps.ulCapFrameLayoutCount); ++i )
2361        CAMHAL_LOGD("  eCapFrameLayout[%2d] = %d", i, int(caps.eCapFrameLayout[i]));
2362
2363    CAMHAL_LOGD("");
2364    CAMHAL_LOGD("bVideoNoiseFilterSupported         = %d", int(caps.bVideoNoiseFilterSupported      ));
2365    CAMHAL_LOGD("bVideoStabilizationSupported       = %d", int(caps.bVideoStabilizationSupported    ));
2366    CAMHAL_LOGD("bStillCapDuringVideoSupported      = %d", int(caps.bStillCapDuringVideoSupported   ));
2367    CAMHAL_LOGD("bMechanicalMisalignmentSupported   = %d", int(caps.bMechanicalMisalignmentSupported));
2368    CAMHAL_LOGD("bFacePrioritySupported             = %d", int(caps.bFacePrioritySupported          ));
2369    CAMHAL_LOGD("bRegionPrioritySupported           = %d", int(caps.bRegionPrioritySupported        ));
2370    CAMHAL_LOGD("bGlbceSupported                    = %d", int(caps.bGlbceSupported));
2371
2372    CAMHAL_LOGD("");
2373    CAMHAL_LOGD("nManualConvMin     = %d", int(caps.nManualConvMin     ));
2374    CAMHAL_LOGD("nManualConvMax     = %d", int(caps.nManualConvMax     ));
2375    CAMHAL_LOGD("nManualExpMin      = %d", int(caps.nManualExpMin      ));
2376    CAMHAL_LOGD("nManualExpMax      = %d", int(caps.nManualExpMax      ));
2377    CAMHAL_LOGD("nBrightnessMin     = %d", int(caps.nBrightnessMin     ));
2378    CAMHAL_LOGD("nBrightnessMax     = %d", int(caps.nBrightnessMax     ));
2379    CAMHAL_LOGD("nContrastMin       = %d", int(caps.nContrastMin       ));
2380    CAMHAL_LOGD("nContrastMax       = %d", int(caps.nContrastMax       ));
2381    CAMHAL_LOGD("nSharpnessMin      = %d", int(caps.nSharpnessMin      ));
2382    CAMHAL_LOGD("nSharpnessMax      = %d", int(caps.nSharpnessMax      ));
2383    CAMHAL_LOGD("nSaturationMin     = %d", int(caps.nSaturationMin     ));
2384    CAMHAL_LOGD("nSaturationMax     = %d", int(caps.nSaturationMax     ));
2385
2386    CAMHAL_LOGD("");
2387    CAMHAL_LOGD("------------------- end of dump -------------------");
2388    CAMHAL_LOGD("===================================================");
2389
2390    return true;
2391}
2392
2393/*****************************************
2394 * public exposed function declarations
2395 *****************************************/
2396
2397status_t OMXCameraAdapter::getCaps(const int sensorId, CameraProperties::Properties* params, OMX_HANDLETYPE handle)
2398{
2399    status_t ret = NO_ERROR;
2400    int caps_size = 0;
2401    OMX_ERRORTYPE eError = OMX_ErrorNone;
2402    CameraBuffer *bufferlist;
2403    OMX_TI_CAPTYPE* caps;
2404    OMX_TI_CONFIG_SHAREDBUFFER sharedBuffer;
2405    MemoryManager memMgr;
2406
2407    LOG_FUNCTION_NAME;
2408
2409    ret = memMgr.initialize();
2410    if ( ret != OK ) {
2411        CAMHAL_LOGE("MemoryManager initialization failed, error: %d", ret);
2412        return ret;
2413    }
2414
2415    // allocate tiler (or ion) buffer for caps (size is always a multiple of 4K)
2416    caps_size = ((sizeof(OMX_TI_CAPTYPE)+4095)/4096)*4096;
2417    bufferlist = memMgr.allocateBufferList(0, 0, NULL, caps_size, 1);
2418    caps = (OMX_TI_CAPTYPE*) bufferlist[0].opaque;
2419
2420    if (!caps) {
2421        CAMHAL_LOGEB("Error allocating buffer for caps %d", eError);
2422        ret = -ENOMEM;
2423        goto EXIT;
2424    }
2425
2426    // initialize structures to be passed to OMX Camera
2427    OMX_INIT_STRUCT_PTR (caps, OMX_TI_CAPTYPE);
2428    caps->nPortIndex = OMX_ALL;
2429
2430    OMX_INIT_STRUCT_PTR (&sharedBuffer, OMX_TI_CONFIG_SHAREDBUFFER);
2431    sharedBuffer.nPortIndex = OMX_ALL;
2432    sharedBuffer.nSharedBuffSize = caps_size;
2433    sharedBuffer.pSharedBuff = (OMX_U8 *) camera_buffer_get_omx_ptr (&bufferlist[0]);
2434
2435    // Get capabilities from OMX Camera
2436    eError =  OMX_GetConfig(handle, (OMX_INDEXTYPE) OMX_TI_IndexConfigCamCapabilities, &sharedBuffer);
2437    if ( OMX_ErrorNone != eError ) {
2438        CAMHAL_LOGEB("Error during capabilities query 0x%x", eError);
2439        ret = UNKNOWN_ERROR;
2440        goto EXIT;
2441    } else {
2442        CAMHAL_LOGDA("OMX capability query success");
2443    }
2444
2445#ifdef CAMERAHAL_DEBUG
2446    _dumpOmxTiCap(sensorId, *caps);
2447#endif
2448
2449    // Translate and insert Ducati capabilities to CameraProperties
2450    if ( NO_ERROR == ret ) {
2451        ret = insertCapabilities(params, *caps);
2452    }
2453
2454    CAMHAL_LOGDB("sen mount id=%u", (unsigned int)caps->tSenMounting.nSenId);
2455    CAMHAL_LOGDB("facing id=%u", (unsigned int)caps->tSenMounting.eFacing);
2456
2457 EXIT:
2458    if (bufferlist) {
2459        memMgr.freeBufferList(bufferlist);
2460    }
2461
2462    LOG_FUNCTION_NAME_EXIT;
2463    return ret;
2464}
2465
2466} // namespace Camera
2467} // namespace Ti
2468