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 android {
30
31#undef LOG_TAG
32
33// Maintain a separate tag for OMXCameraAdapter logs to isolate issues OMX specific
34#define LOG_TAG "CameraHAL"
35
36/************************************
37 * global constants and variables
38 *************************************/
39
40#define ARRAY_SIZE(array) (sizeof((array)) / sizeof((array)[0]))
41#define FPS_MIN 5
42#define FPS_STEP 5
43#define FPS_RANGE_STEP 5
44
45static const char PARAM_SEP[] = ",";
46static const int PARAM_SEP_CHAR = ',';
47static const uint32_t VFR_OFFSET = 8;
48static const char VFR_BACKET_START[] = "(";
49static const char VFR_BRACKET_END[] = ")";
50static const char FRAMERATE_COUNT = 10;
51
52/**** look up tables to translate OMX Caps to Parameter ****/
53
54const CapResolution OMXCameraAdapter::mImageCapRes [] = {
55    { 4032, 3024, "4032x3024" },
56    { 4000, 3000, "4000x3000" },
57    { 3648, 2736, "3648x2736" },
58    { 3264, 2448, "3264x2448" },
59    { 2592, 1944, "2592x1944" },
60    { 2592, 1728, "2592x1728" },
61    { 2592, 1458, "2592x1458" },
62    { 2048, 1536, "2048x1536" },
63    { 1600, 1200, "1600x1200" },
64    { 1280, 1024, "1280x1024" },
65    { 1152, 864, "1152x864" },
66    { 1280, 960, "1280x960" },
67    { 640, 480, "640x480" },
68    { 320, 240, "320x240" },
69};
70
71const CapResolution OMXCameraAdapter::mPreviewRes [] = {
72    { 1920, 1080, "1920x1080" },
73    { 1280, 720, "1280x720" },
74    { 960, 720, "960x720" },
75    { 800, 480, "800x480" },
76    { 720, 576, "720x576" },
77    { 720, 480, "720x480" },
78    { 768, 576, "768x576" },
79    { 640, 480, "640x480" },
80    { 320, 240, "320x240" },
81    { 352, 288, "352x288" },
82    { 240, 160, "240x160" },
83    { 176, 144, "176x144" },
84    { 128, 96, "128x96" },
85};
86
87const CapResolution OMXCameraAdapter::mThumbRes [] = {
88    { 640, 480, "640x480" },
89    { 160, 120, "160x120" },
90    { 200, 120, "200x120" },
91    { 320, 240, "320x240" },
92    { 512, 384, "512x384" },
93    { 352, 144, "352x144" },
94    { 176, 144, "176x144" },
95    { 96, 96, "96x96" },
96};
97
98const CapPixelformat OMXCameraAdapter::mPixelformats [] = {
99    { OMX_COLOR_FormatCbYCrY, CameraParameters::PIXEL_FORMAT_YUV422I },
100    { OMX_COLOR_FormatYUV420SemiPlanar, CameraParameters::PIXEL_FORMAT_YUV420SP },
101    { OMX_COLOR_Format16bitRGB565, CameraParameters::PIXEL_FORMAT_RGB565 },
102    { OMX_COLOR_FormatRawBayer10bit, TICameraParameters::PIXEL_FORMAT_RAW },
103    { OMX_COLOR_FormatYUV420SemiPlanar, CameraParameters::PIXEL_FORMAT_YUV420P },
104};
105
106const CapFramerate OMXCameraAdapter::mFramerates [] = {
107    { 30, "30" },
108    { 15, "15" },
109};
110
111const CapZoom OMXCameraAdapter::mZoomStages [] = {
112    { 65536, "100" },
113    { 68157, "104" },
114    { 70124, "107" },
115    { 72745, "111" },
116    { 75366, "115" },
117    { 77988, "119" },
118    { 80609, "123" },
119    { 83231, "127" },
120    { 86508, "132" },
121    { 89784, "137" },
122    { 92406, "141" },
123    { 95683, "146" },
124    { 99615, "152" },
125    { 102892, "157" },
126    { 106168, "162" },
127    { 110100, "168" },
128    { 114033, "174" },
129    { 117965, "180" },
130    { 122552, "187" },
131    { 126484, "193" },
132    { 131072, "200" },
133    { 135660, "207" },
134    { 140247, "214" },
135    { 145490, "222" },
136    { 150733, "230" },
137    { 155976, "238" },
138    { 161219, "246" },
139    { 167117, "255" },
140    { 173015, "264" },
141    { 178913, "273" },
142    { 185467, "283" },
143    { 192020, "293" },
144    { 198574, "303" },
145    { 205783, "314" },
146    { 212992, "325" },
147    { 220201, "336" },
148    { 228065, "348" },
149    { 236585, "361" },
150    { 244449, "373" },
151    { 252969, "386" },
152    { 262144, "400" },
153    { 271319, "414" },
154    { 281149, "429" },
155    { 290980, "444" },
156    { 300810, "459" },
157    { 311951, "476" },
158    { 322437, "492" },
159    { 334234, "510" },
160    { 346030, "528" },
161    { 357827, "546" },
162    { 370934, "566" },
163    { 384041, "586" },
164    { 397148, "606" },
165    { 411566, "628" },
166    { 425984, "650" },
167    { 441057, "673" },
168    { 456131, "696" },
169    { 472515, "721" },
170    { 488899, "746" },
171    { 506593, "773" },
172    { 524288, "800" },
173};
174
175const CapISO OMXCameraAdapter::mISOStages [] = {
176    { 0, "auto" },
177    { 100, "100" },
178    { 200, "200"},
179    { 400, "400" },
180    { 800, "800" },
181    { 1000, "1000" },
182    { 1200, "1200" },
183    { 1600, "1600" },
184};
185
186// mapped values have to match with new_sensor_MSP.h
187const CapU32 OMXCameraAdapter::mSensorNames [] = {
188    { 300, "IMX060" },
189    { 301, "OV5650" },
190    { 305, "S5K4E1GA"},
191    { 306, "S5K6A1GX03" }
192    // TODO(XXX): need to account for S3D camera later
193};
194
195// values for supported variable framerates sorted in ascending order
196// CapU32Pair = (max fps, min fps, string representation)
197const CapU32Pair OMXCameraAdapter::mVarFramerates [] = {
198    { 15, 15, "(15000,15000)"},
199    { 30, 15, "(15000,30000)" },
200    { 30, 24, "(24000,30000)" },
201// TODO(XXX): Removing 30,30 range to limit 1080p at 24fps. Will put back soon.
202#if 0
203    { 30, 30, "(30000,30000)" },
204#endif
205};
206/************************************
207 * static helper functions
208 *************************************/
209
210// utility function to remove last seperator
211void remove_last_sep(char* buffer) {
212    char* last_sep = NULL;
213    last_sep = strrchr(buffer, PARAM_SEP_CHAR);
214    if (last_sep != NULL) {
215        last_sep[0] = '\0';
216    }
217}
218
219
220/*****************************************
221 * internal static function declarations
222 *****************************************/
223
224/**** Utility functions to help translate OMX Caps to Parameter ****/
225
226status_t OMXCameraAdapter::encodePixelformatCap(OMX_COLOR_FORMATTYPE format,
227                              const CapPixelformat *cap,
228                              size_t capCount,
229                              char * buffer,
230                              size_t bufferSize) {
231    status_t ret = NO_ERROR;
232
233    LOG_FUNCTION_NAME;
234
235    if ( ( NULL == buffer ) || ( NULL == cap ) ) {
236        CAMHAL_LOGEA("Invalid input arguments");
237        return -EINVAL;
238    }
239
240    for ( unsigned int i = 0; i < capCount; i++ ) {
241        if ( format == cap[i].pixelformat ) {
242            strncat(buffer, cap[i].param, bufferSize - 1);
243            strncat(buffer, PARAM_SEP, bufferSize - 1);
244        }
245    }
246
247    LOG_FUNCTION_NAME_EXIT;
248
249    return ret;
250}
251
252status_t OMXCameraAdapter::encodeFramerateCap(OMX_U32 framerateMax,
253                            OMX_U32 framerateMin,
254                            const CapFramerate *cap,
255                            size_t capCount,
256                            char * buffer,
257                            size_t bufferSize) {
258    status_t ret = NO_ERROR;
259    bool minInserted = false;
260    bool maxInserted = false;
261    char tmpBuffer[FRAMERATE_COUNT];
262
263    LOG_FUNCTION_NAME;
264
265    if ( ( NULL == buffer ) || ( NULL == cap ) ) {
266        CAMHAL_LOGEA("Invalid input arguments");
267        return -EINVAL;
268    }
269
270    for ( unsigned int i = 0; i < capCount; i++ ) {
271        if ( (framerateMax >= cap[i].num) && (framerateMin <= cap[i].num) ) {
272            strncat(buffer, cap[i].param, bufferSize - 1);
273            strncat(buffer, PARAM_SEP, bufferSize - 1);
274
275            if ( cap[i].num ==  framerateMin ) {
276                minInserted = true;
277            }
278        }
279        if ( cap[i].num ==  framerateMax ) {
280            maxInserted = true;
281        }
282    }
283
284    if ( !maxInserted ) {
285        memset(tmpBuffer, 0, FRAMERATE_COUNT);
286        snprintf(tmpBuffer, FRAMERATE_COUNT - 1, "%u,", ( unsigned int ) framerateMax);
287        strncat(buffer, tmpBuffer, bufferSize - 1);
288        strncat(buffer, PARAM_SEP, bufferSize - 1);
289    }
290
291    if ( !minInserted ) {
292        memset(tmpBuffer, 0, FRAMERATE_COUNT);
293        snprintf(tmpBuffer, FRAMERATE_COUNT - 1, "%u,", ( unsigned int ) framerateMin);
294        strncat(buffer, tmpBuffer, bufferSize - 1);
295        strncat(buffer, PARAM_SEP, bufferSize - 1);
296    }
297
298    remove_last_sep(buffer);
299
300    LOG_FUNCTION_NAME_EXIT;
301
302    return ret;
303}
304
305status_t OMXCameraAdapter::encodeVFramerateCap(OMX_TI_CAPTYPE &caps,
306                                               const CapU32Pair *cap,
307                                               size_t capCount,
308                                               char *buffer,
309                                               char *defaultRange,
310                                               size_t bufferSize) {
311    status_t ret = NO_ERROR;
312    uint32_t minVFR, maxVFR;
313    int default_index = -1;
314
315    LOG_FUNCTION_NAME;
316
317    if ( (NULL == buffer) || (NULL == cap) ) {
318        CAMHAL_LOGEA("Invalid input arguments");
319        return -EINVAL;
320    }
321
322    if(caps.ulPrvVarFPSModesCount < 1) {
323        return NO_ERROR;
324    }
325
326    // Assumption: last range in tPrvVarFPSModes will be for S30FPSHD mode
327    minVFR = caps.tPrvVarFPSModes[caps.ulPrvVarFPSModesCount-1].nVarFPSMin >> VFR_OFFSET;
328    maxVFR = caps.tPrvVarFPSModes[caps.ulPrvVarFPSModesCount-1].nVarFPSMax >> VFR_OFFSET;
329
330    if (minVFR < FPS_MIN) {
331        minVFR = FPS_MIN;
332    }
333
334    for (unsigned int i = 0; i < capCount; i++) {
335        // add cap[i] if it is in range and maxVFR != minVFR
336        if ((maxVFR >= cap[i].num1) && (minVFR <= cap[i].num2)) {
337            if (buffer[0] != '\0') {
338                strncat(buffer, PARAM_SEP, bufferSize - 1);
339            }
340            strncat(buffer, cap[i].param, bufferSize - 1);
341
342            // choose the max variable framerate as default
343            if (cap[i].num1 != cap[i].num2) {
344                default_index = i;
345            }
346        }
347    }
348
349    // if we haven't found any caps in the list to populate
350    // just use the min and max
351    if (buffer[0] == '\0') {
352        snprintf(buffer, bufferSize - 1,
353             "(%u,%u)",
354             minVFR * CameraHal::VFR_SCALE,
355             maxVFR * CameraHal::VFR_SCALE);
356    }
357
358    if (default_index != -1) {
359        snprintf(defaultRange, (MAX_PROP_VALUE_LENGTH - 1), "%lu,%lu",
360                 cap[default_index].num2 * CameraHal::VFR_SCALE,
361                 cap[default_index].num1 * CameraHal::VFR_SCALE);
362    } else {
363        snprintf(defaultRange, (MAX_PROP_VALUE_LENGTH - 1), "%u,%u",
364                 minVFR * CameraHal::VFR_SCALE, maxVFR * CameraHal::VFR_SCALE);
365    }
366
367    LOG_FUNCTION_NAME_EXIT;
368
369    return ret;
370}
371
372size_t OMXCameraAdapter::encodeZoomCap(OMX_S32 maxZoom,
373                     const CapZoom *cap,
374                     size_t capCount,
375                     char * buffer,
376                     size_t bufferSize) {
377    status_t res = NO_ERROR;
378    size_t ret = 0;
379
380    LOG_FUNCTION_NAME;
381
382    if ( (NULL == buffer) || (NULL == cap) ) {
383        CAMHAL_LOGEA("Invalid input arguments");
384        return -EINVAL;
385    }
386
387
388    for ( unsigned int i = 0; i < capCount; i++ ) {
389        if ( cap[i].num <= maxZoom ) {
390            strncat(buffer, cap[i].param, bufferSize - 1);
391            strncat(buffer, PARAM_SEP, bufferSize - 1);
392            ret++;
393        }
394    }
395    remove_last_sep(buffer);
396
397    LOG_FUNCTION_NAME_EXIT;
398
399    return ret;
400}
401
402status_t OMXCameraAdapter::encodeISOCap(OMX_U32 maxISO,
403                      const CapISO *cap,
404                      size_t capCount,
405                      char * buffer,
406                      size_t bufferSize) {
407    status_t ret = NO_ERROR;
408
409    LOG_FUNCTION_NAME;
410
411    if ( (NULL == buffer) || (NULL == cap) ) {
412        CAMHAL_LOGEA("Invalid input arguments");
413        return -EINVAL;
414    }
415
416    for ( unsigned int i = 0; i < capCount; i++ ) {
417        if ( cap[i].num <= maxISO) {
418            strncat(buffer, cap[i].param, bufferSize - 1);
419            strncat(buffer, PARAM_SEP, bufferSize - 1);
420        }
421    }
422    remove_last_sep(buffer);
423
424    LOG_FUNCTION_NAME_EXIT;
425
426    return ret;
427}
428
429status_t OMXCameraAdapter::encodeSizeCap(OMX_TI_CAPRESTYPE &res,
430                       const CapResolution *cap,
431                       size_t capCount,
432                       char * buffer,
433                       size_t bufferSize) {
434    status_t ret = NO_ERROR;
435
436    LOG_FUNCTION_NAME;
437
438    if ( (NULL == buffer) || (NULL == cap) ) {
439        CAMHAL_LOGEA("Invalid input arguments");
440        return -EINVAL;
441    }
442
443    for ( unsigned int i = 0 ; i < capCount ; i++ ) {
444        if ( (cap[i].width <= res.nWidthMax) &&
445             (cap[i].height <= res.nHeightMax) &&
446             (cap[i].width >= res.nWidthMin) &&
447             (cap[i].height >= res.nHeightMin) ) {
448                strncat(buffer, cap[i].param, bufferSize -1);
449                strncat(buffer, PARAM_SEP, bufferSize - 1);
450        }
451    }
452
453    LOG_FUNCTION_NAME_EXIT;
454
455    return ret;
456}
457
458status_t OMXCameraAdapter::insertImageSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
459    status_t ret = NO_ERROR;
460    char supported[MAX_PROP_VALUE_LENGTH];
461
462    LOG_FUNCTION_NAME;
463
464    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
465
466    ret = encodeSizeCap(caps.tImageResRange,
467                        mImageCapRes,
468                        ARRAY_SIZE(mImageCapRes),
469                        supported,
470                        MAX_PROP_VALUE_LENGTH);
471
472    if ( NO_ERROR != ret ) {
473        CAMHAL_LOGEB("Error inserting supported picture sizes 0x%x", ret);
474    } else {
475        remove_last_sep(supported);
476        params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, supported);
477    }
478
479    LOG_FUNCTION_NAME;
480
481    return ret;
482}
483
484status_t OMXCameraAdapter::insertPreviewSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
485    status_t ret = NO_ERROR;
486    char supported[MAX_PROP_VALUE_LENGTH];
487
488    LOG_FUNCTION_NAME;
489
490    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
491
492    ret = encodeSizeCap(caps.tPreviewResRange,
493                        mPreviewRes,
494                        ARRAY_SIZE(mPreviewRes),
495                        supported,
496                        MAX_PROP_VALUE_LENGTH);
497
498    if ( NO_ERROR != ret ) {
499        CAMHAL_LOGEB("Error inserting supported preview sizes 0x%x", ret);
500    } else {
501        remove_last_sep(supported);
502        params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, supported);
503    }
504
505    LOG_FUNCTION_NAME;
506
507    return ret;
508}
509
510status_t OMXCameraAdapter::insertVideoSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
511    status_t ret = NO_ERROR;
512    char supported[MAX_PROP_VALUE_LENGTH];
513
514    LOG_FUNCTION_NAME;
515
516    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
517
518    ret = encodeSizeCap(caps.tPreviewResRange,
519                        mPreviewRes,
520                        ARRAY_SIZE(mPreviewRes),
521                        supported,
522                        MAX_PROP_VALUE_LENGTH);
523
524    if ( NO_ERROR != ret ) {
525      CAMHAL_LOGEB("Error inserting supported video sizes 0x%x", ret);
526    } else {
527      remove_last_sep(supported);
528      params->set(CameraProperties::SUPPORTED_VIDEO_SIZES, supported);
529    }
530
531    LOG_FUNCTION_NAME;
532
533    return ret;
534}
535
536status_t OMXCameraAdapter::insertThumbSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
537    status_t ret = NO_ERROR;
538    char supported[MAX_PROP_VALUE_LENGTH];
539
540    LOG_FUNCTION_NAME;
541
542    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
543
544    ret = encodeSizeCap(caps.tThumbResRange,
545                        mThumbRes,
546                        ARRAY_SIZE(mThumbRes),
547                        supported,
548                        MAX_PROP_VALUE_LENGTH);
549
550    if ( NO_ERROR != ret ) {
551        CAMHAL_LOGEB("Error inserting supported thumbnail sizes 0x%x", ret);
552    } else {
553        //CTS Requirement: 0x0 should always be supported
554        strncat(supported, "0x0", MAX_PROP_NAME_LENGTH);
555        params->set(CameraProperties::SUPPORTED_THUMBNAIL_SIZES, supported);
556    }
557
558    LOG_FUNCTION_NAME;
559
560    return ret;
561}
562
563status_t OMXCameraAdapter::insertZoomStages(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
564{
565    status_t ret = NO_ERROR;
566    char supported[MAX_PROP_VALUE_LENGTH];
567    size_t zoomStageCount = 0;
568
569    LOG_FUNCTION_NAME;
570
571    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
572
573    zoomStageCount = encodeZoomCap(caps.xMaxWidthZoom,
574                                   mZoomStages,
575                                   ARRAY_SIZE(mZoomStages),
576                                   supported,
577                                   MAX_PROP_VALUE_LENGTH);
578
579    params->set(CameraProperties::SUPPORTED_ZOOM_RATIOS, supported);
580    params->set(CameraProperties::SUPPORTED_ZOOM_STAGES, zoomStageCount - 1); //As per CTS requirement
581
582    if ( 0 == zoomStageCount ) {
583        params->set(CameraProperties::ZOOM_SUPPORTED, TICameraParameters::ZOOM_UNSUPPORTED);
584        params->set(CameraProperties::SMOOTH_ZOOM_SUPPORTED, TICameraParameters::ZOOM_UNSUPPORTED);
585    } else {
586        params->set(CameraProperties::ZOOM_SUPPORTED, TICameraParameters::ZOOM_SUPPORTED);
587        params->set(CameraProperties::SMOOTH_ZOOM_SUPPORTED, TICameraParameters::ZOOM_SUPPORTED);
588    }
589
590    LOG_FUNCTION_NAME;
591
592    return ret;
593}
594
595status_t OMXCameraAdapter::insertImageFormats(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
596    status_t ret = NO_ERROR;
597    char supported[MAX_PROP_VALUE_LENGTH];
598
599    LOG_FUNCTION_NAME;
600
601    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
602
603    for ( int i = 0 ; i < caps.ulImageFormatCount ; i++ ) {
604        ret = encodePixelformatCap(caps.eImageFormats[i],
605                                   mPixelformats,
606                                   ARRAY_SIZE(mPixelformats),
607                                   supported,
608                                   MAX_PROP_VALUE_LENGTH);
609        if ( NO_ERROR != ret ) {
610            CAMHAL_LOGEB("Error inserting supported picture formats 0x%x", ret);
611            break;
612        }
613    }
614
615    if ( NO_ERROR == ret ) {
616        //jpeg is not supported in OMX capabilies yet
617        strncat(supported, CameraParameters::PIXEL_FORMAT_JPEG, MAX_PROP_VALUE_LENGTH - 1);
618        params->set(CameraProperties::SUPPORTED_PICTURE_FORMATS, supported);
619    }
620
621    LOG_FUNCTION_NAME;
622
623    return ret;
624}
625
626status_t OMXCameraAdapter::insertPreviewFormats(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
627    status_t ret = NO_ERROR;
628    char supported[MAX_PROP_VALUE_LENGTH];
629
630    LOG_FUNCTION_NAME;
631
632    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
633
634    for ( int i = 0 ; i < caps.ulPreviewFormatCount; i++ ) {
635        ret = encodePixelformatCap(caps.ePreviewFormats[i],
636                                   mPixelformats,
637                                   ARRAY_SIZE(mPixelformats),
638                                   supported,
639                                   MAX_PROP_VALUE_LENGTH);
640        if ( NO_ERROR != ret ) {
641            CAMHAL_LOGEB("Error inserting supported preview formats 0x%x", ret);
642            break;
643        }
644    }
645
646    if ( NO_ERROR == ret ) {
647        // need to advertise we support YV12 format
648        // We will program preview port with NV21 when we see application set YV12
649        strncat(supported, CameraParameters::PIXEL_FORMAT_YUV420P, MAX_PROP_VALUE_LENGTH - 1);
650        params->set(CameraProperties::SUPPORTED_PREVIEW_FORMATS, supported);
651    }
652
653    LOG_FUNCTION_NAME;
654
655    return ret;
656}
657
658status_t OMXCameraAdapter::insertFramerates(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
659    status_t ret = NO_ERROR;
660    char supported[MAX_PROP_VALUE_LENGTH];
661
662    LOG_FUNCTION_NAME;
663
664    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
665
666    ret = encodeFramerateCap(caps.xFramerateMax >> VFR_OFFSET,
667                             caps.xFramerateMin >> VFR_OFFSET,
668                             mFramerates,
669                             ARRAY_SIZE(mFramerates),
670                             supported,
671                             MAX_PROP_VALUE_LENGTH);
672
673    if ( NO_ERROR != ret ) {
674        CAMHAL_LOGEB("Error inserting supported preview framerates 0x%x", ret);
675    } else {
676        params->set(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES, supported);
677    }
678
679    LOG_FUNCTION_NAME;
680
681    return ret;
682}
683
684status_t OMXCameraAdapter::insertVFramerates(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
685    status_t ret = NO_ERROR;
686    char supported[MAX_PROP_VALUE_LENGTH];
687    char defaultRange[MAX_PROP_VALUE_LENGTH];
688
689    LOG_FUNCTION_NAME;
690
691    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
692
693    ret = encodeVFramerateCap(caps,
694                              mVarFramerates,
695                              ARRAY_SIZE(mVarFramerates),
696                              supported,
697                              defaultRange,
698                              MAX_PROP_VALUE_LENGTH);
699
700    if ( NO_ERROR != ret ) {
701        CAMHAL_LOGEB("Error inserting supported preview framerate ranges 0x%x", ret);
702    } else {
703        params->set(CameraProperties::FRAMERATE_RANGE_SUPPORTED, supported);
704        CAMHAL_LOGDB("framerate ranges %s", supported);
705        params->set(CameraProperties::FRAMERATE_RANGE, DEFAULT_FRAMERATE_RANGE_IMAGE);
706        params->set(CameraProperties::FRAMERATE_RANGE_VIDEO, DEFAULT_FRAMERATE_RANGE_VIDEO);
707        params->set(CameraProperties::FRAMERATE_RANGE_IMAGE, DEFAULT_FRAMERATE_RANGE_IMAGE);
708        CAMHAL_LOGDB("Default framerate range: [%s]", DEFAULT_FRAMERATE_RANGE_IMAGE);
709    }
710
711    LOG_FUNCTION_NAME;
712
713    return ret;
714}
715
716status_t OMXCameraAdapter::insertEVs(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
717    status_t ret = NO_ERROR;
718    char supported[MAX_PROP_VALUE_LENGTH];
719
720    LOG_FUNCTION_NAME;
721
722    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
723
724    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.xEVCompensationMin * 10 ));
725    params->set(CameraProperties::SUPPORTED_EV_MIN, supported);
726
727    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.xEVCompensationMax * 10 ));
728    params->set(CameraProperties::SUPPORTED_EV_MAX, supported);
729
730    LOG_FUNCTION_NAME;
731
732    return ret;
733}
734
735status_t OMXCameraAdapter::insertISOModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
736    status_t ret = NO_ERROR;
737    char supported[MAX_PROP_VALUE_LENGTH];
738
739    LOG_FUNCTION_NAME;
740
741    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
742
743    ret = encodeISOCap(caps.nSensitivityMax,
744                       mISOStages,
745                       ARRAY_SIZE(mISOStages),
746                       supported,
747                       MAX_PROP_VALUE_LENGTH);
748    if ( NO_ERROR != ret ) {
749        CAMHAL_LOGEB("Error inserting supported ISO modes 0x%x", ret);
750    } else {
751        params->set(CameraProperties::SUPPORTED_ISO_VALUES, supported);
752    }
753
754    LOG_FUNCTION_NAME;
755
756    return ret;
757}
758
759status_t OMXCameraAdapter::insertIPPModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
760    status_t ret = NO_ERROR;
761    char supported[MAX_PROP_VALUE_LENGTH];
762
763    LOG_FUNCTION_NAME;
764
765    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
766
767    //Off is always supported
768    strncat(supported, TICameraParameters::IPP_NONE, MAX_PROP_NAME_LENGTH);
769    strncat(supported, PARAM_SEP, 1);
770
771    if ( caps.bLensDistortionCorrectionSupported ) {
772        strncat(supported, TICameraParameters::IPP_LDC, MAX_PROP_NAME_LENGTH);
773        strncat(supported, PARAM_SEP, 1);
774    }
775
776    if ( caps.bISONoiseFilterSupported ) {
777        strncat(supported, TICameraParameters::IPP_NSF, MAX_PROP_NAME_LENGTH);
778        strncat(supported, PARAM_SEP, 1);
779    }
780
781    if ( caps.bISONoiseFilterSupported && caps.bLensDistortionCorrectionSupported ) {
782        strncat(supported, TICameraParameters::IPP_LDCNSF, MAX_PROP_NAME_LENGTH);
783        strncat(supported, PARAM_SEP, 1);
784    }
785
786    remove_last_sep(supported);
787    params->set(CameraProperties::SUPPORTED_IPP_MODES, supported);
788
789    LOG_FUNCTION_NAME;
790
791    return ret;
792}
793
794status_t OMXCameraAdapter::insertWBModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
795    status_t ret = NO_ERROR;
796    char supported[MAX_PROP_VALUE_LENGTH];
797    const char *p;
798
799    LOG_FUNCTION_NAME;
800
801    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
802
803    for ( unsigned int i = 0 ; i < caps.ulWhiteBalanceCount ; i++ ) {
804        p = getLUTvalue_OMXtoHAL(caps.eWhiteBalanceModes[i], WBalLUT);
805        if ( NULL != p ) {
806            strncat(supported, p, MAX_PROP_NAME_LENGTH);
807            strncat(supported, PARAM_SEP, 1);
808        }
809    }
810
811    params->set(CameraProperties::SUPPORTED_WHITE_BALANCE, supported);
812
813    LOG_FUNCTION_NAME;
814
815    return ret;
816}
817
818status_t OMXCameraAdapter::insertEffects(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
819    status_t ret = NO_ERROR;
820    char supported[MAX_PROP_VALUE_LENGTH];
821    const char *p;
822
823    LOG_FUNCTION_NAME;
824
825    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
826
827    for ( unsigned int i = 0 ; i < caps.ulColorEffectCount; i++ ) {
828        p = getLUTvalue_OMXtoHAL(caps.eColorEffects[i], EffLUT);
829        if ( NULL != p ) {
830            strncat(supported, p, MAX_PROP_NAME_LENGTH);
831            strncat(supported, PARAM_SEP, 1);
832        }
833    }
834    remove_last_sep(supported);
835    params->set(CameraProperties::SUPPORTED_EFFECTS, supported);
836
837    LOG_FUNCTION_NAME;
838
839    return ret;
840}
841
842status_t OMXCameraAdapter::insertExpModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
843    status_t ret = NO_ERROR;
844    char supported[MAX_PROP_VALUE_LENGTH];
845    const char *p;
846
847    LOG_FUNCTION_NAME;
848
849    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
850
851    for ( unsigned int i = 0 ; i < caps.ulExposureModeCount; i++ ) {
852        p = getLUTvalue_OMXtoHAL(caps.eExposureModes[i], ExpLUT);
853        if ( NULL != p ) {
854            strncat(supported, p, MAX_PROP_NAME_LENGTH);
855            strncat(supported, PARAM_SEP, 1);
856        }
857    }
858
859    params->set(CameraProperties::SUPPORTED_EXPOSURE_MODES, supported);
860
861    LOG_FUNCTION_NAME;
862
863    return ret;
864}
865
866status_t OMXCameraAdapter::insertFlashModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
867    status_t ret = NO_ERROR;
868    char supported[MAX_PROP_VALUE_LENGTH];
869    const char *p;
870
871    LOG_FUNCTION_NAME;
872
873    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
874
875    for ( unsigned int i = 0 ; i < caps.ulFlashCount; i++ ) {
876        p = getLUTvalue_OMXtoHAL(caps.eFlashModes[i], FlashLUT);
877        if ( NULL != p ) {
878            strncat(supported, p, MAX_PROP_NAME_LENGTH);
879            strncat(supported, PARAM_SEP, 1);
880        }
881    }
882
883    remove_last_sep(supported);
884    params->set(CameraProperties::SUPPORTED_FLASH_MODES, supported);
885
886    LOG_FUNCTION_NAME;
887
888    return ret;
889}
890
891status_t OMXCameraAdapter::insertSceneModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
892    status_t ret = NO_ERROR;
893    char supported[MAX_PROP_VALUE_LENGTH];
894    const char *p;
895
896    LOG_FUNCTION_NAME;
897
898    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
899
900    for ( unsigned int i = 0 ; i < caps.ulSceneCount; i++ ) {
901        p = getLUTvalue_OMXtoHAL(caps.eSceneModes[i], SceneLUT);
902        if ( NULL != p ) {
903            strncat(supported, p, MAX_PROP_NAME_LENGTH);
904            strncat(supported, PARAM_SEP, 1);
905        }
906    }
907
908    remove_last_sep(supported);
909    params->set(CameraProperties::SUPPORTED_SCENE_MODES, supported);
910
911    LOG_FUNCTION_NAME;
912
913    return ret;
914}
915
916status_t OMXCameraAdapter::insertFocusModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
917    status_t ret = NO_ERROR;
918    char supported[MAX_PROP_VALUE_LENGTH];
919    const char *p;
920
921    LOG_FUNCTION_NAME;
922
923    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
924
925    for ( unsigned int i = 0 ; i < caps.ulFocusModeCount; i++ ) {
926        p = getLUTvalue_OMXtoHAL(caps.eFocusModes[i], FocusLUT);
927        if ( NULL != p ) {
928            strncat(supported, p, MAX_PROP_NAME_LENGTH);
929            strncat(supported, PARAM_SEP, 1);
930        }
931    }
932
933    // Check if focus is supported by camera
934    if (caps.ulFocusModeCount == 1 &&
935        caps.eFocusModes[0] == OMX_IMAGE_FocusControlOff) {
936        // Focus is not supported by camera
937        // Advertise this to app as infinitiy focus mode
938        strncat(supported, CameraParameters::FOCUS_MODE_INFINITY, MAX_PROP_NAME_LENGTH);
939    } else {
940        // Focus is supported but these modes are not supported by the
941        // capability feature. Apply manually
942        strncat(supported, CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE, MAX_PROP_NAME_LENGTH);
943    }
944
945    params->set(CameraProperties::SUPPORTED_FOCUS_MODES, supported);
946
947    LOG_FUNCTION_NAME;
948
949    return ret;
950}
951
952status_t OMXCameraAdapter::insertFlickerModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
953    status_t ret = NO_ERROR;
954    char supported[MAX_PROP_VALUE_LENGTH];
955    const char *p;
956
957    LOG_FUNCTION_NAME;
958
959    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
960
961    for ( unsigned int i = 0 ; i < caps.ulFlickerCount; i++ ) {
962        p = getLUTvalue_OMXtoHAL(caps.eFlicker[i], FlickerLUT);
963        if ( NULL != p ) {
964            strncat(supported, p, MAX_PROP_NAME_LENGTH);
965            strncat(supported, PARAM_SEP, 1);
966        }
967    }
968    remove_last_sep(supported);
969    params->set(CameraProperties::SUPPORTED_ANTIBANDING, supported);
970
971    LOG_FUNCTION_NAME;
972
973    return ret;
974}
975
976status_t OMXCameraAdapter::insertAreas(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
977    status_t ret = NO_ERROR;
978    char supported[MAX_PROP_VALUE_LENGTH];
979    const char *p;
980
981    LOG_FUNCTION_NAME;
982
983    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
984
985    sprintf(supported, "%d", caps.ulAlgoAreasFocusCount);
986    params->set(CameraProperties::MAX_FOCUS_AREAS, supported);
987    CAMHAL_LOGDB("Maximum supported focus areas %s", supported);
988
989    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
990    sprintf(supported, "%d", caps.ulAlgoAreasExposureCount);
991    params->set(CameraProperties::MAX_NUM_METERING_AREAS, supported);
992    CAMHAL_LOGDB("Maximum supported exposure areas %s", supported);
993
994    LOG_FUNCTION_NAME;
995
996    return ret;
997}
998
999status_t OMXCameraAdapter::insertLocks(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1000    status_t ret = NO_ERROR;
1001
1002    LOG_FUNCTION_NAME
1003
1004    params->set(CameraProperties::AUTO_EXPOSURE_LOCK_SUPPORTED, DEFAULT_LOCK_SUPPORTED);
1005    params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK_SUPPORTED, DEFAULT_LOCK_SUPPORTED);
1006
1007    LOG_FUNCTION_NAME
1008
1009    return ret;
1010}
1011
1012status_t OMXCameraAdapter::insertDefaults(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1013    status_t ret = NO_ERROR;
1014    char supported[MAX_PROP_VALUE_LENGTH];
1015    const char *p;
1016
1017    LOG_FUNCTION_NAME;
1018
1019    params->set(CameraProperties::ANTIBANDING, DEFAULT_ANTIBANDING);
1020    params->set(CameraProperties::BRIGHTNESS, DEFAULT_BRIGHTNESS);
1021    params->set(CameraProperties::CONTRAST, DEFAULT_CONTRAST);
1022    params->set(CameraProperties::EFFECT, DEFAULT_EFFECT);
1023    params->set(CameraProperties::EV_COMPENSATION, DEFAULT_EV_COMPENSATION);
1024    params->set(CameraProperties::SUPPORTED_EV_STEP, DEFAULT_EV_STEP);
1025    params->set(CameraProperties::EXPOSURE_MODE, DEFAULT_EXPOSURE_MODE);
1026    params->set(CameraProperties::FLASH_MODE, DEFAULT_FLASH_MODE);
1027    char *pos = strstr(params->get(CameraProperties::SUPPORTED_FOCUS_MODES), DEFAULT_FOCUS_MODE_PREFERRED);
1028    if ( NULL != pos )
1029        {
1030        params->set(CameraProperties::FOCUS_MODE, DEFAULT_FOCUS_MODE_PREFERRED);
1031        }
1032    else
1033        {
1034        params->set(CameraProperties::FOCUS_MODE, DEFAULT_FOCUS_MODE);
1035        }
1036    params->set(CameraProperties::IPP, DEFAULT_IPP);
1037    params->set(CameraProperties::GBCE, DEFAULT_GBCE);
1038    params->set(CameraProperties::ISO_MODE, DEFAULT_ISO_MODE);
1039    params->set(CameraProperties::JPEG_QUALITY, DEFAULT_JPEG_QUALITY);
1040    params->set(CameraProperties::JPEG_THUMBNAIL_QUALITY, DEFAULT_THUMBNAIL_QUALITY);
1041    params->set(CameraProperties::JPEG_THUMBNAIL_SIZE, DEFAULT_THUMBNAIL_SIZE);
1042    params->set(CameraProperties::PICTURE_FORMAT, DEFAULT_PICTURE_FORMAT);
1043    params->set(CameraProperties::PICTURE_SIZE, DEFAULT_PICTURE_SIZE);
1044    params->set(CameraProperties::PREVIEW_FORMAT, DEFAULT_PREVIEW_FORMAT);
1045    params->set(CameraProperties::PREVIEW_FRAME_RATE, DEFAULT_FRAMERATE);
1046    params->set(CameraProperties::PREVIEW_SIZE, DEFAULT_PREVIEW_SIZE);
1047    params->set(CameraProperties::REQUIRED_PREVIEW_BUFS, DEFAULT_NUM_PREV_BUFS);
1048    params->set(CameraProperties::REQUIRED_IMAGE_BUFS, DEFAULT_NUM_PIC_BUFS);
1049    params->set(CameraProperties::SATURATION, DEFAULT_SATURATION);
1050    params->set(CameraProperties::SCENE_MODE, DEFAULT_SCENE_MODE);
1051    params->set(CameraProperties::SHARPNESS, DEFAULT_SHARPNESS);
1052    params->set(CameraProperties::VSTAB, DEFAULT_VSTAB);
1053    params->set(CameraProperties::VSTAB_SUPPORTED, DEFAULT_VSTAB_SUPPORTED);
1054    params->set(CameraProperties::WHITEBALANCE, DEFAULT_WB);
1055    params->set(CameraProperties::ZOOM, DEFAULT_ZOOM);
1056    params->set(CameraProperties::MAX_FD_HW_FACES, DEFAULT_MAX_FD_HW_FACES);
1057    params->set(CameraProperties::MAX_FD_SW_FACES, DEFAULT_MAX_FD_SW_FACES);
1058    params->set(CameraProperties::AUTO_EXPOSURE_LOCK, DEFAULT_AE_LOCK);
1059    params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK, DEFAULT_AWB_LOCK);
1060    if(caps.tSenMounting.nSenId == 305) {
1061        params->set(CameraProperties::FOCAL_LENGTH, DEFAULT_FOCAL_LENGTH_PRIMARY);
1062    } else {
1063        params->set(CameraProperties::FOCAL_LENGTH, DEFAULT_FOCAL_LENGTH_SECONDARY);
1064    }
1065    params->set(CameraProperties::HOR_ANGLE, DEFAULT_HOR_ANGLE);
1066    params->set(CameraProperties::VER_ANGLE, DEFAULT_VER_ANGLE);
1067    params->set(CameraProperties::VIDEO_SNAPSHOT_SUPPORTED, DEFAULT_VIDEO_SNAPSHOT_SUPPORTED);
1068    params->set(CameraProperties::VIDEO_SIZE, DEFAULT_VIDEO_SIZE);
1069    params->set(CameraProperties::PREFERRED_PREVIEW_SIZE_FOR_VIDEO, DEFAULT_PREFERRED_PREVIEW_SIZE_FOR_VIDEO);
1070
1071    LOG_FUNCTION_NAME;
1072
1073    return ret;
1074}
1075
1076status_t OMXCameraAdapter::insertSenMount(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1077    status_t ret = NO_ERROR;
1078    char supported[MAX_PROP_VALUE_LENGTH];
1079    const char *p;
1080    unsigned int i = 0;
1081
1082    LOG_FUNCTION_NAME;
1083
1084    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1085
1086    // 1) Look up and assign sensor name
1087    for (i = 0; i < ARRAY_SIZE(mSensorNames); i++) {
1088        if(mSensorNames[i].num == caps.tSenMounting.nSenId) {
1089            // sensor found
1090            break;
1091        }
1092    }
1093    if ( i == ARRAY_SIZE(mSensorNames) ) {
1094        p = "UNKNOWN_SENSOR";
1095    } else {
1096        p = mSensorNames[i].param;
1097    }
1098    strncat(supported, p, MAX_PROP_NAME_LENGTH);
1099    params->set(CameraProperties::CAMERA_NAME, supported);
1100
1101    // 2) Assign mounting rotation
1102    params->set(CameraProperties::ORIENTATION_INDEX, caps.tSenMounting.nRotation);
1103
1104    LOG_FUNCTION_NAME;
1105
1106    return ret;
1107}
1108
1109status_t OMXCameraAdapter::insertCapabilities(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1110    status_t ret = NO_ERROR;
1111    char supported[MAX_PROP_VALUE_LENGTH];
1112
1113    LOG_FUNCTION_NAME;
1114
1115    if ( NO_ERROR == ret ) {
1116        ret = insertImageSizes(params, caps);
1117    }
1118
1119    if ( NO_ERROR == ret ) {
1120        ret = insertPreviewSizes(params, caps);
1121    }
1122
1123    if ( NO_ERROR == ret ) {
1124        ret = insertThumbSizes(params, caps);
1125    }
1126
1127    if ( NO_ERROR == ret ) {
1128        ret = insertZoomStages(params, caps);
1129    }
1130
1131    if ( NO_ERROR == ret ) {
1132        ret = insertImageFormats(params, caps);
1133    }
1134
1135    if ( NO_ERROR == ret ) {
1136        ret = insertPreviewFormats(params, caps);
1137    }
1138
1139    if ( NO_ERROR == ret ) {
1140        ret = insertFramerates(params, caps);
1141    }
1142
1143    if ( NO_ERROR == ret ) {
1144        ret = insertVFramerates(params, caps);
1145    }
1146
1147    if ( NO_ERROR == ret ) {
1148        ret = insertEVs(params, caps);
1149    }
1150
1151    if ( NO_ERROR == ret ) {
1152        ret = insertISOModes(params, caps);
1153    }
1154
1155    if ( NO_ERROR == ret ) {
1156        ret = insertIPPModes(params, caps);
1157    }
1158
1159    if ( NO_ERROR == ret ) {
1160        ret = insertWBModes(params, caps);
1161    }
1162
1163    if ( NO_ERROR == ret ) {
1164        ret = insertEffects(params, caps);
1165    }
1166
1167    if ( NO_ERROR == ret ) {
1168        ret = insertExpModes(params, caps);
1169    }
1170
1171    if ( NO_ERROR == ret ) {
1172        ret = insertFlashModes(params, caps);
1173    }
1174
1175    if ( NO_ERROR == ret ) {
1176        ret = insertSceneModes(params, caps);
1177    }
1178
1179    if ( NO_ERROR == ret ) {
1180        ret = insertFocusModes(params, caps);
1181    }
1182
1183    if ( NO_ERROR == ret ) {
1184        ret = insertFlickerModes(params, caps);
1185    }
1186
1187    if ( NO_ERROR == ret ) {
1188        ret = insertSenMount(params, caps);
1189    }
1190
1191    if ( NO_ERROR == ret ) {
1192        ret = insertLocks(params, caps);
1193    }
1194    if ( NO_ERROR == ret) {
1195        ret = insertAreas(params, caps);
1196
1197    }
1198
1199    //NOTE: Ensure that we always call insertDefaults after inserting the supported capabilities
1200    //as there are checks inside insertDefaults to make sure a certain default is supported
1201    // or not
1202    if ( NO_ERROR == ret ) {
1203      ret = insertVideoSizes(params, caps);
1204    }
1205
1206    if ( NO_ERROR == ret ) {
1207        ret = insertDefaults(params, caps);
1208    }
1209
1210
1211
1212    LOG_FUNCTION_NAME_EXIT;
1213
1214    return ret;
1215}
1216
1217/*****************************************
1218 * public exposed function declarations
1219 *****************************************/
1220
1221status_t OMXCameraAdapter::getCaps(CameraProperties::Properties* params, OMX_HANDLETYPE handle) {
1222    status_t ret = NO_ERROR;
1223    int caps_size = 0;
1224    OMX_ERRORTYPE eError = OMX_ErrorNone;
1225    OMX_TI_CAPTYPE** caps = NULL;;
1226    OMX_TI_CONFIG_SHAREDBUFFER sharedBuffer;
1227    MemoryManager memMgr;
1228
1229    LOG_FUNCTION_NAME;
1230
1231    // allocate tiler (or ion) buffer for caps (size is always a multiple of 4K)
1232    caps_size = ((sizeof(OMX_TI_CAPTYPE)+4095)/4096)*4096;
1233    caps = (OMX_TI_CAPTYPE**) memMgr.allocateBuffer(0, 0, NULL, caps_size, 1);
1234
1235    if (!caps) {
1236        CAMHAL_LOGEB("Error allocating buffer for caps %d", eError);
1237        ret = -ENOMEM;
1238        goto EXIT;
1239    }
1240
1241    // initialize structures to be passed to OMX Camera
1242    OMX_INIT_STRUCT_PTR (caps[0], OMX_TI_CAPTYPE);
1243    caps[0]->nPortIndex = OMX_ALL;
1244
1245    OMX_INIT_STRUCT_PTR (&sharedBuffer, OMX_TI_CONFIG_SHAREDBUFFER);
1246    sharedBuffer.nPortIndex = OMX_ALL;
1247    sharedBuffer.nSharedBuffSize = caps_size;
1248    sharedBuffer.pSharedBuff = (OMX_U8 *) caps[0];
1249
1250    // Get capabilities from OMX Camera
1251    eError =  OMX_GetConfig(handle, (OMX_INDEXTYPE) OMX_TI_IndexConfigCamCapabilities, &sharedBuffer);
1252    if ( OMX_ErrorNone != eError ) {
1253        CAMHAL_LOGEB("Error during capabilities query 0x%x", eError);
1254        ret = UNKNOWN_ERROR;
1255        goto EXIT;
1256    } else {
1257        CAMHAL_LOGDA("OMX capability query success");
1258    }
1259
1260    // Translate and insert Ducati capabilities to CameraProperties
1261    if ( NO_ERROR == ret ) {
1262        ret = insertCapabilities(params, *caps[0]);
1263    }
1264
1265    CAMHAL_LOGDB("sen mount id=%u", (unsigned int)caps[0]->tSenMounting.nSenId);
1266
1267
1268 EXIT:
1269    if (caps) {
1270        memMgr.freeBuffer((void*) caps);
1271        caps = NULL;
1272    }
1273
1274    LOG_FUNCTION_NAME_EXIT;
1275    return ret;
1276}
1277
1278};
1279
1280