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