OMXCapabilities.cpp revision e9ab1f4f653c21c2b526af02ceed12ecb935752c
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/************************************
201 * static helper functions
202 *************************************/
203
204// utility function to remove last seperator
205void remove_last_sep(char* buffer) {
206    char* last_sep = NULL;
207    last_sep = strrchr(buffer, PARAM_SEP_CHAR);
208    if (last_sep != NULL) {
209        last_sep[0] = '\0';
210    }
211}
212
213
214/*****************************************
215 * internal static function declarations
216 *****************************************/
217
218/**** Utility functions to help translate OMX Caps to Parameter ****/
219
220status_t OMXCameraAdapter::encodePixelformatCap(OMX_COLOR_FORMATTYPE format,
221                              const CapPixelformat *cap,
222                              size_t capCount,
223                              char * buffer,
224                              size_t bufferSize) {
225    status_t ret = NO_ERROR;
226
227    LOG_FUNCTION_NAME;
228
229    if ( ( NULL == buffer ) || ( NULL == cap ) ) {
230        CAMHAL_LOGEA("Invalid input arguments");
231        return -EINVAL;
232    }
233
234    for ( unsigned int i = 0; i < capCount; i++ ) {
235        if ( format == cap[i].pixelformat ) {
236            strncat(buffer, cap[i].param, bufferSize - 1);
237            strncat(buffer, PARAM_SEP, bufferSize - 1);
238        }
239    }
240
241    LOG_FUNCTION_NAME_EXIT;
242
243    return ret;
244}
245
246status_t OMXCameraAdapter::encodeFramerateCap(OMX_U32 framerateMax,
247                            OMX_U32 framerateMin,
248                            const CapFramerate *cap,
249                            size_t capCount,
250                            char * buffer,
251                            size_t bufferSize) {
252    status_t ret = NO_ERROR;
253    bool minInserted = false;
254    bool maxInserted = false;
255    char tmpBuffer[FRAMERATE_COUNT];
256
257    LOG_FUNCTION_NAME;
258
259    if ( ( NULL == buffer ) || ( NULL == cap ) ) {
260        CAMHAL_LOGEA("Invalid input arguments");
261        return -EINVAL;
262    }
263
264    for ( unsigned int i = 0; i < capCount; i++ ) {
265        if ( (framerateMax >= cap[i].num) && (framerateMin <= cap[i].num) ) {
266            strncat(buffer, cap[i].param, bufferSize - 1);
267            strncat(buffer, PARAM_SEP, bufferSize - 1);
268
269            if ( cap[i].num ==  framerateMin ) {
270                minInserted = true;
271            }
272        }
273        if ( cap[i].num ==  framerateMax ) {
274            maxInserted = true;
275        }
276    }
277
278    if ( !maxInserted ) {
279        memset(tmpBuffer, 0, FRAMERATE_COUNT);
280        snprintf(tmpBuffer, FRAMERATE_COUNT - 1, "%u,", ( unsigned int ) framerateMax);
281        strncat(buffer, tmpBuffer, bufferSize - 1);
282        strncat(buffer, PARAM_SEP, bufferSize - 1);
283    }
284
285    if ( !minInserted ) {
286        memset(tmpBuffer, 0, FRAMERATE_COUNT);
287        snprintf(tmpBuffer, FRAMERATE_COUNT - 1, "%u,", ( unsigned int ) framerateMin);
288        strncat(buffer, tmpBuffer, bufferSize - 1);
289        strncat(buffer, PARAM_SEP, bufferSize - 1);
290    }
291
292    remove_last_sep(buffer);
293
294    LOG_FUNCTION_NAME_EXIT;
295
296    return ret;
297}
298
299status_t OMXCameraAdapter::encodeVFramerateCap(OMX_TI_CAPTYPE &caps,
300                                               char *buffer,
301                                               char *defaultRange,
302                                               size_t bufferSize) {
303    status_t ret = NO_ERROR;
304    uint32_t minVFR, maxVFR;
305    char tmpBuffer[MAX_PROP_VALUE_LENGTH];
306    bool skipLast = false;
307    uint32_t min, max;
308
309    LOG_FUNCTION_NAME;
310
311    if ( NULL == buffer ) {
312        CAMHAL_LOGEA("Invalid input arguments");
313        return -EINVAL;
314    }
315
316    if(caps.ulPrvVarFPSModesCount < 1) {
317        return NO_ERROR;
318    }
319
320    // Assumption: last range in tPrvVarFPSModes will be for S30FPSHD mode
321    minVFR = caps.tPrvVarFPSModes[caps.ulPrvVarFPSModesCount-1].nVarFPSMin >> VFR_OFFSET;
322    maxVFR = caps.tPrvVarFPSModes[caps.ulPrvVarFPSModesCount-1].nVarFPSMax >> VFR_OFFSET;
323
324    if (minVFR < FPS_MIN) {
325        minVFR = FPS_MIN;
326    }
327
328    memset(tmpBuffer, '\0', MAX_PROP_VALUE_LENGTH);
329    min = max = 0;
330    for (unsigned int i = minVFR; i < maxVFR; i += FPS_STEP) {
331
332        min = i * CameraHal::VFR_SCALE;
333        max = (i + FPS_RANGE_STEP) * CameraHal::VFR_SCALE;
334
335        snprintf(tmpBuffer, ( MAX_PROP_VALUE_LENGTH - 1 ), "(%d,%d)", min, min);
336        strncat(buffer, tmpBuffer, ( bufferSize - 1 ));
337        strncat(buffer, PARAM_SEP, bufferSize - 1);
338
339        if (max <= maxVFR * CameraHal::VFR_SCALE) {
340            snprintf(tmpBuffer, ( MAX_PROP_VALUE_LENGTH - 1 ), "(%d,%d)", min, max);
341            strncat(buffer, tmpBuffer, ( bufferSize - 1 ));
342            strncat(buffer, PARAM_SEP, bufferSize - 1);
343        }
344    }
345    remove_last_sep(buffer);
346
347    if ( 1 < strlen(tmpBuffer) ) {
348        snprintf(defaultRange, ( MAX_PROP_VALUE_LENGTH - 1 ), "%d,%d", min, min);
349    }
350
351    LOG_FUNCTION_NAME_EXIT;
352
353    return ret;
354}
355
356size_t OMXCameraAdapter::encodeZoomCap(OMX_S32 maxZoom,
357                     const CapZoom *cap,
358                     size_t capCount,
359                     char * buffer,
360                     size_t bufferSize) {
361    status_t res = NO_ERROR;
362    size_t ret = 0;
363
364    LOG_FUNCTION_NAME;
365
366    if ( (NULL == buffer) || (NULL == cap) ) {
367        CAMHAL_LOGEA("Invalid input arguments");
368        return -EINVAL;
369    }
370
371
372    for ( unsigned int i = 0; i < capCount; i++ ) {
373        if ( cap[i].num <= maxZoom ) {
374            strncat(buffer, cap[i].param, bufferSize - 1);
375            strncat(buffer, PARAM_SEP, bufferSize - 1);
376            ret++;
377        }
378    }
379    remove_last_sep(buffer);
380
381    LOG_FUNCTION_NAME_EXIT;
382
383    return ret;
384}
385
386status_t OMXCameraAdapter::encodeISOCap(OMX_U32 maxISO,
387                      const CapISO *cap,
388                      size_t capCount,
389                      char * buffer,
390                      size_t bufferSize) {
391    status_t ret = NO_ERROR;
392
393    LOG_FUNCTION_NAME;
394
395    if ( (NULL == buffer) || (NULL == cap) ) {
396        CAMHAL_LOGEA("Invalid input arguments");
397        return -EINVAL;
398    }
399
400    for ( unsigned int i = 0; i < capCount; i++ ) {
401        if ( cap[i].num <= maxISO) {
402            strncat(buffer, cap[i].param, bufferSize - 1);
403            strncat(buffer, PARAM_SEP, bufferSize - 1);
404        }
405    }
406    remove_last_sep(buffer);
407
408    LOG_FUNCTION_NAME_EXIT;
409
410    return ret;
411}
412
413status_t OMXCameraAdapter::encodeSizeCap(OMX_TI_CAPRESTYPE &res,
414                       const CapResolution *cap,
415                       size_t capCount,
416                       char * buffer,
417                       size_t bufferSize) {
418    status_t ret = NO_ERROR;
419
420    LOG_FUNCTION_NAME;
421
422    if ( (NULL == buffer) || (NULL == cap) ) {
423        CAMHAL_LOGEA("Invalid input arguments");
424        return -EINVAL;
425    }
426
427    for ( unsigned int i = 0 ; i < capCount ; i++ ) {
428        if ( (cap[i].width <= res.nWidthMax) &&
429             (cap[i].height <= res.nHeightMax) &&
430             (cap[i].width >= res.nWidthMin) &&
431             (cap[i].height >= res.nHeightMin) ) {
432                strncat(buffer, cap[i].param, bufferSize -1);
433                strncat(buffer, PARAM_SEP, bufferSize - 1);
434        }
435    }
436
437    LOG_FUNCTION_NAME_EXIT;
438
439    return ret;
440}
441
442status_t OMXCameraAdapter::insertImageSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
443    status_t ret = NO_ERROR;
444    char supported[MAX_PROP_VALUE_LENGTH];
445
446    LOG_FUNCTION_NAME;
447
448    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
449
450    ret = encodeSizeCap(caps.tImageResRange,
451                        mImageCapRes,
452                        ARRAY_SIZE(mImageCapRes),
453                        supported,
454                        MAX_PROP_VALUE_LENGTH);
455
456    if ( NO_ERROR != ret ) {
457        CAMHAL_LOGEB("Error inserting supported picture sizes 0x%x", ret);
458    } else {
459        remove_last_sep(supported);
460        params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, supported);
461    }
462
463    LOG_FUNCTION_NAME;
464
465    return ret;
466}
467
468status_t OMXCameraAdapter::insertPreviewSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
469    status_t ret = NO_ERROR;
470    char supported[MAX_PROP_VALUE_LENGTH];
471
472    LOG_FUNCTION_NAME;
473
474    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
475
476    ret = encodeSizeCap(caps.tPreviewResRange,
477                        mPreviewRes,
478                        ARRAY_SIZE(mPreviewRes),
479                        supported,
480                        MAX_PROP_VALUE_LENGTH);
481
482    if ( NO_ERROR != ret ) {
483        CAMHAL_LOGEB("Error inserting supported preview sizes 0x%x", ret);
484    } else {
485        remove_last_sep(supported);
486        params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, supported);
487    }
488
489    LOG_FUNCTION_NAME;
490
491    return ret;
492}
493
494status_t OMXCameraAdapter::insertThumbSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
495    status_t ret = NO_ERROR;
496    char supported[MAX_PROP_VALUE_LENGTH];
497
498    LOG_FUNCTION_NAME;
499
500    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
501
502    ret = encodeSizeCap(caps.tThumbResRange,
503                        mThumbRes,
504                        ARRAY_SIZE(mThumbRes),
505                        supported,
506                        MAX_PROP_VALUE_LENGTH);
507
508    if ( NO_ERROR != ret ) {
509        CAMHAL_LOGEB("Error inserting supported thumbnail sizes 0x%x", ret);
510    } else {
511        //CTS Requirement: 0x0 should always be supported
512        strncat(supported, "0x0", MAX_PROP_NAME_LENGTH);
513        params->set(CameraProperties::SUPPORTED_THUMBNAIL_SIZES, supported);
514    }
515
516    LOG_FUNCTION_NAME;
517
518    return ret;
519}
520
521status_t OMXCameraAdapter::insertZoomStages(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps)
522{
523    status_t ret = NO_ERROR;
524    char supported[MAX_PROP_VALUE_LENGTH];
525    size_t zoomStageCount = 0;
526
527    LOG_FUNCTION_NAME;
528
529    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
530
531    zoomStageCount = encodeZoomCap(caps.xMaxWidthZoom,
532                                   mZoomStages,
533                                   ARRAY_SIZE(mZoomStages),
534                                   supported,
535                                   MAX_PROP_VALUE_LENGTH);
536
537    params->set(CameraProperties::SUPPORTED_ZOOM_RATIOS, supported);
538    params->set(CameraProperties::SUPPORTED_ZOOM_STAGES, zoomStageCount - 1); //As per CTS requirement
539
540    if ( 0 == zoomStageCount ) {
541        params->set(CameraProperties::ZOOM_SUPPORTED, TICameraParameters::ZOOM_UNSUPPORTED);
542        params->set(CameraProperties::SMOOTH_ZOOM_SUPPORTED, TICameraParameters::ZOOM_UNSUPPORTED);
543    } else {
544        params->set(CameraProperties::ZOOM_SUPPORTED, TICameraParameters::ZOOM_SUPPORTED);
545        params->set(CameraProperties::SMOOTH_ZOOM_SUPPORTED, TICameraParameters::ZOOM_SUPPORTED);
546    }
547
548    LOG_FUNCTION_NAME;
549
550    return ret;
551}
552
553status_t OMXCameraAdapter::insertImageFormats(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
554    status_t ret = NO_ERROR;
555    char supported[MAX_PROP_VALUE_LENGTH];
556
557    LOG_FUNCTION_NAME;
558
559    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
560
561    for ( int i = 0 ; i < caps.ulImageFormatCount ; i++ ) {
562        ret = encodePixelformatCap(caps.eImageFormats[i],
563                                   mPixelformats,
564                                   ARRAY_SIZE(mPixelformats),
565                                   supported,
566                                   MAX_PROP_VALUE_LENGTH);
567        if ( NO_ERROR != ret ) {
568            CAMHAL_LOGEB("Error inserting supported picture formats 0x%x", ret);
569            break;
570        }
571    }
572
573    if ( NO_ERROR == ret ) {
574        //jpeg is not supported in OMX capabilies yet
575        strncat(supported, CameraParameters::PIXEL_FORMAT_JPEG, MAX_PROP_VALUE_LENGTH - 1);
576        params->set(CameraProperties::SUPPORTED_PICTURE_FORMATS, supported);
577    }
578
579    LOG_FUNCTION_NAME;
580
581    return ret;
582}
583
584status_t OMXCameraAdapter::insertPreviewFormats(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
585    status_t ret = NO_ERROR;
586    char supported[MAX_PROP_VALUE_LENGTH];
587
588    LOG_FUNCTION_NAME;
589
590    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
591
592    for ( int i = 0 ; i < caps.ulPreviewFormatCount; i++ ) {
593        ret = encodePixelformatCap(caps.ePreviewFormats[i],
594                                   mPixelformats,
595                                   ARRAY_SIZE(mPixelformats),
596                                   supported,
597                                   MAX_PROP_VALUE_LENGTH);
598        if ( NO_ERROR != ret ) {
599            CAMHAL_LOGEB("Error inserting supported preview formats 0x%x", ret);
600            break;
601        }
602    }
603
604    if ( NO_ERROR == ret ) {
605        // need to advertise we support YV12 format
606        // We will program preview port with NV21 when we see application set YV12
607        strncat(supported, CameraParameters::PIXEL_FORMAT_YUV420P, MAX_PROP_VALUE_LENGTH - 1);
608        params->set(CameraProperties::SUPPORTED_PREVIEW_FORMATS, supported);
609    }
610
611    LOG_FUNCTION_NAME;
612
613    return ret;
614}
615
616status_t OMXCameraAdapter::insertFramerates(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
617    status_t ret = NO_ERROR;
618    char supported[MAX_PROP_VALUE_LENGTH];
619
620    LOG_FUNCTION_NAME;
621
622    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
623
624    ret = encodeFramerateCap(caps.xFramerateMax >> VFR_OFFSET,
625                             caps.xFramerateMin >> VFR_OFFSET,
626                             mFramerates,
627                             ARRAY_SIZE(mFramerates),
628                             supported,
629                             MAX_PROP_VALUE_LENGTH);
630
631    if ( NO_ERROR != ret ) {
632        CAMHAL_LOGEB("Error inserting supported preview framerates 0x%x", ret);
633    } else {
634        params->set(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES, supported);
635    }
636
637    LOG_FUNCTION_NAME;
638
639    return ret;
640}
641
642status_t OMXCameraAdapter::insertVFramerates(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
643    status_t ret = NO_ERROR;
644    char supported[MAX_PROP_VALUE_LENGTH];
645    char defaultRange[MAX_PROP_VALUE_LENGTH];
646
647    LOG_FUNCTION_NAME;
648
649    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
650
651    ret = encodeVFramerateCap(caps, supported, defaultRange, MAX_PROP_VALUE_LENGTH);
652
653    if ( NO_ERROR != ret ) {
654        CAMHAL_LOGEB("Error inserting supported preview framerate ranges 0x%x", ret);
655    } else {
656        params->set(CameraProperties::FRAMERATE_RANGE_SUPPORTED, supported);
657        CAMHAL_LOGDB("framerate ranges %s", supported);
658        params->set(CameraProperties::FRAMERATE_RANGE, defaultRange);
659        CAMHAL_LOGDB("Default framerate range: [%s]", defaultRange);
660    }
661
662    LOG_FUNCTION_NAME;
663
664    return ret;
665}
666
667status_t OMXCameraAdapter::insertEVs(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
668    status_t ret = NO_ERROR;
669    char supported[MAX_PROP_VALUE_LENGTH];
670
671    LOG_FUNCTION_NAME;
672
673    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
674
675    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.xEVCompensationMin * 10 ));
676    params->set(CameraProperties::SUPPORTED_EV_MIN, supported);
677
678    snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.xEVCompensationMax * 10 ));
679    params->set(CameraProperties::SUPPORTED_EV_MAX, supported);
680
681    LOG_FUNCTION_NAME;
682
683    return ret;
684}
685
686status_t OMXCameraAdapter::insertISOModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
687    status_t ret = NO_ERROR;
688    char supported[MAX_PROP_VALUE_LENGTH];
689
690    LOG_FUNCTION_NAME;
691
692    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
693
694    ret = encodeISOCap(caps.nSensitivityMax,
695                       mISOStages,
696                       ARRAY_SIZE(mISOStages),
697                       supported,
698                       MAX_PROP_VALUE_LENGTH);
699    if ( NO_ERROR != ret ) {
700        CAMHAL_LOGEB("Error inserting supported ISO modes 0x%x", ret);
701    } else {
702        params->set(CameraProperties::SUPPORTED_ISO_VALUES, supported);
703    }
704
705    LOG_FUNCTION_NAME;
706
707    return ret;
708}
709
710status_t OMXCameraAdapter::insertIPPModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
711    status_t ret = NO_ERROR;
712    char supported[MAX_PROP_VALUE_LENGTH];
713
714    LOG_FUNCTION_NAME;
715
716    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
717
718    //Off is always supported
719    strncat(supported, TICameraParameters::IPP_NONE, MAX_PROP_NAME_LENGTH);
720    strncat(supported, PARAM_SEP, 1);
721
722    if ( caps.bLensDistortionCorrectionSupported ) {
723        strncat(supported, TICameraParameters::IPP_LDC, MAX_PROP_NAME_LENGTH);
724        strncat(supported, PARAM_SEP, 1);
725    }
726
727    if ( caps.bISONoiseFilterSupported ) {
728        strncat(supported, TICameraParameters::IPP_NSF, MAX_PROP_NAME_LENGTH);
729        strncat(supported, PARAM_SEP, 1);
730    }
731
732    if ( caps.bISONoiseFilterSupported && caps.bLensDistortionCorrectionSupported ) {
733        strncat(supported, TICameraParameters::IPP_LDCNSF, MAX_PROP_NAME_LENGTH);
734        strncat(supported, PARAM_SEP, 1);
735    }
736
737    remove_last_sep(supported);
738    params->set(CameraProperties::SUPPORTED_IPP_MODES, supported);
739
740    LOG_FUNCTION_NAME;
741
742    return ret;
743}
744
745status_t OMXCameraAdapter::insertWBModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
746    status_t ret = NO_ERROR;
747    char supported[MAX_PROP_VALUE_LENGTH];
748    const char *p;
749
750    LOG_FUNCTION_NAME;
751
752    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
753
754    for ( unsigned int i = 0 ; i < caps.ulWhiteBalanceCount ; i++ ) {
755        p = getLUTvalue_OMXtoHAL(caps.eWhiteBalanceModes[i], WBalLUT);
756        if ( NULL != p ) {
757            strncat(supported, p, MAX_PROP_NAME_LENGTH);
758            strncat(supported, PARAM_SEP, 1);
759        }
760    }
761
762    //These modes are not supported by the capability feature
763    strncat(supported, TICameraParameters::WHITE_BALANCE_FACE, MAX_PROP_NAME_LENGTH);
764
765    params->set(CameraProperties::SUPPORTED_WHITE_BALANCE, supported);
766
767    LOG_FUNCTION_NAME;
768
769    return ret;
770}
771
772status_t OMXCameraAdapter::insertEffects(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
773    status_t ret = NO_ERROR;
774    char supported[MAX_PROP_VALUE_LENGTH];
775    const char *p;
776
777    LOG_FUNCTION_NAME;
778
779    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
780
781    for ( unsigned int i = 0 ; i < caps.ulColorEffectCount; i++ ) {
782        p = getLUTvalue_OMXtoHAL(caps.eColorEffects[i], EffLUT);
783        if ( NULL != p ) {
784            strncat(supported, p, MAX_PROP_NAME_LENGTH);
785            strncat(supported, PARAM_SEP, 1);
786        }
787    }
788    remove_last_sep(supported);
789    params->set(CameraProperties::SUPPORTED_EFFECTS, supported);
790
791    LOG_FUNCTION_NAME;
792
793    return ret;
794}
795
796status_t OMXCameraAdapter::insertExpModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
797    status_t ret = NO_ERROR;
798    char supported[MAX_PROP_VALUE_LENGTH];
799    const char *p;
800
801    LOG_FUNCTION_NAME;
802
803    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
804
805    for ( unsigned int i = 0 ; i < caps.ulExposureModeCount; i++ ) {
806        p = getLUTvalue_OMXtoHAL(caps.eExposureModes[i], ExpLUT);
807        if ( NULL != p ) {
808            strncat(supported, p, MAX_PROP_NAME_LENGTH);
809            strncat(supported, PARAM_SEP, 1);
810        }
811    }
812
813    //These modes are not supported by the capability feature
814    strncat(supported, TICameraParameters::EXPOSURE_MODE_FACE, MAX_PROP_NAME_LENGTH);
815
816    params->set(CameraProperties::SUPPORTED_EXPOSURE_MODES, supported);
817
818    LOG_FUNCTION_NAME;
819
820    return ret;
821}
822
823status_t OMXCameraAdapter::insertFlashModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
824    status_t ret = NO_ERROR;
825    char supported[MAX_PROP_VALUE_LENGTH];
826    const char *p;
827
828    LOG_FUNCTION_NAME;
829
830    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
831
832    for ( unsigned int i = 0 ; i < caps.ulFlashCount; i++ ) {
833        p = getLUTvalue_OMXtoHAL(caps.eFlashModes[i], FlashLUT);
834        if ( NULL != p ) {
835            strncat(supported, p, MAX_PROP_NAME_LENGTH);
836            strncat(supported, PARAM_SEP, 1);
837        }
838    }
839
840    remove_last_sep(supported);
841    params->set(CameraProperties::SUPPORTED_FLASH_MODES, supported);
842
843    LOG_FUNCTION_NAME;
844
845    return ret;
846}
847
848status_t OMXCameraAdapter::insertSceneModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
849    status_t ret = NO_ERROR;
850    char supported[MAX_PROP_VALUE_LENGTH];
851    const char *p;
852
853    LOG_FUNCTION_NAME;
854
855    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
856
857    for ( unsigned int i = 0 ; i < caps.ulSceneCount; i++ ) {
858        p = getLUTvalue_OMXtoHAL(caps.eSceneModes[i], SceneLUT);
859        if ( NULL != p ) {
860            strncat(supported, p, MAX_PROP_NAME_LENGTH);
861            strncat(supported, PARAM_SEP, 1);
862        }
863    }
864
865    remove_last_sep(supported);
866    params->set(CameraProperties::SUPPORTED_SCENE_MODES, supported);
867
868    LOG_FUNCTION_NAME;
869
870    return ret;
871}
872
873status_t OMXCameraAdapter::insertFocusModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
874    status_t ret = NO_ERROR;
875    char supported[MAX_PROP_VALUE_LENGTH];
876    const char *p;
877
878    LOG_FUNCTION_NAME;
879
880    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
881
882    for ( unsigned int i = 0 ; i < caps.ulFocusModeCount; i++ ) {
883        p = getLUTvalue_OMXtoHAL(caps.eFocusModes[i], FocusLUT);
884        if ( NULL != p ) {
885            strncat(supported, p, MAX_PROP_NAME_LENGTH);
886            strncat(supported, PARAM_SEP, 1);
887        }
888    }
889
890    // Check if focus is supported by camera
891    if (caps.ulFocusModeCount == 1 &&
892        caps.eFocusModes[0] == OMX_IMAGE_FocusControlOff) {
893        // Focus is not supported by camera
894        // Advertise this to app as infinitiy focus mode
895        strncat(supported, CameraParameters::FOCUS_MODE_INFINITY, MAX_PROP_NAME_LENGTH);
896    } else {
897        // Focus is supported but these modes are not supported by the
898        // capability feature. Apply manually
899        strncat(supported, TICameraParameters::FOCUS_MODE_FACE, MAX_PROP_NAME_LENGTH);
900        strncat(supported, PARAM_SEP, 1);
901        strncat(supported, CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE, MAX_PROP_NAME_LENGTH);
902    }
903
904    params->set(CameraProperties::SUPPORTED_FOCUS_MODES, supported);
905
906    LOG_FUNCTION_NAME;
907
908    return ret;
909}
910
911status_t OMXCameraAdapter::insertFlickerModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
912    status_t ret = NO_ERROR;
913    char supported[MAX_PROP_VALUE_LENGTH];
914    const char *p;
915
916    LOG_FUNCTION_NAME;
917
918    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
919
920    for ( unsigned int i = 0 ; i < caps.ulFlickerCount; i++ ) {
921        p = getLUTvalue_OMXtoHAL(caps.eFlicker[i], FlickerLUT);
922        if ( NULL != p ) {
923            strncat(supported, p, MAX_PROP_NAME_LENGTH);
924            strncat(supported, PARAM_SEP, 1);
925        }
926    }
927    remove_last_sep(supported);
928    params->set(CameraProperties::SUPPORTED_ANTIBANDING, supported);
929
930    LOG_FUNCTION_NAME;
931
932    return ret;
933}
934
935status_t OMXCameraAdapter::insertLocks(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
936    status_t ret = NO_ERROR;
937
938    LOG_FUNCTION_NAME
939
940    params->set(CameraProperties::AUTO_EXPOSURE_LOCK_SUPPORTED, DEFAULT_LOCK_SUPPORTED);
941    params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK_SUPPORTED, DEFAULT_LOCK_SUPPORTED);
942
943    LOG_FUNCTION_NAME
944
945    return ret;
946}
947
948status_t OMXCameraAdapter::insertDefaults(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
949    status_t ret = NO_ERROR;
950    char supported[MAX_PROP_VALUE_LENGTH];
951    const char *p;
952
953    LOG_FUNCTION_NAME;
954
955    params->set(CameraProperties::ANTIBANDING, DEFAULT_ANTIBANDING);
956    params->set(CameraProperties::BRIGHTNESS, DEFAULT_BRIGHTNESS);
957    params->set(CameraProperties::CONTRAST, DEFAULT_CONTRAST);
958    params->set(CameraProperties::EFFECT, DEFAULT_EFFECT);
959    params->set(CameraProperties::EV_COMPENSATION, DEFAULT_EV_COMPENSATION);
960    params->set(CameraProperties::SUPPORTED_EV_STEP, DEFAULT_EV_STEP);
961    params->set(CameraProperties::EXPOSURE_MODE, DEFAULT_EXPOSURE_MODE);
962    params->set(CameraProperties::FLASH_MODE, DEFAULT_FLASH_MODE);
963    params->set(CameraProperties::FOCUS_MODE, DEFAULT_FOCUS_MODE);
964    params->set(CameraProperties::IPP, DEFAULT_IPP);
965    params->set(CameraProperties::ISO_MODE, DEFAULT_ISO_MODE);
966    params->set(CameraProperties::JPEG_QUALITY, DEFAULT_JPEG_QUALITY);
967    params->set(CameraProperties::JPEG_THUMBNAIL_QUALITY, DEFAULT_THUMBNAIL_QUALITY);
968    params->set(CameraProperties::JPEG_THUMBNAIL_SIZE, DEFAULT_THUMBNAIL_SIZE);
969    params->set(CameraProperties::PICTURE_FORMAT, DEFAULT_PICTURE_FORMAT);
970    params->set(CameraProperties::PICTURE_SIZE, DEFAULT_PICTURE_SIZE);
971    params->set(CameraProperties::PREVIEW_FORMAT, DEFAULT_PREVIEW_FORMAT);
972    params->set(CameraProperties::PREVIEW_FRAME_RATE, DEFAULT_FRAMERATE);
973    params->set(CameraProperties::PREVIEW_SIZE, DEFAULT_PREVIEW_SIZE);
974    params->set(CameraProperties::REQUIRED_PREVIEW_BUFS, DEFAULT_NUM_PREV_BUFS);
975    params->set(CameraProperties::REQUIRED_IMAGE_BUFS, DEFAULT_NUM_PIC_BUFS);
976    params->set(CameraProperties::MAX_FOCUS_AREAS, DEFAULT_MAX_FOCUS_AREAS);
977    params->set(CameraProperties::SATURATION, DEFAULT_SATURATION);
978    params->set(CameraProperties::SCENE_MODE, DEFAULT_SCENE_MODE);
979    params->set(CameraProperties::SHARPNESS, DEFAULT_SHARPNESS);
980    params->set(CameraProperties::VSTAB, DEFAULT_VSTAB);
981    params->set(CameraProperties::WHITEBALANCE, DEFAULT_WB);
982    params->set(CameraProperties::ZOOM, DEFAULT_ZOOM);
983    params->set(CameraProperties::MAX_FD_HW_FACES, DEFAULT_MAX_FD_HW_FACES);
984    params->set(CameraProperties::MAX_FD_SW_FACES, DEFAULT_MAX_FD_SW_FACES);
985    params->set(CameraProperties::AUTO_EXPOSURE_LOCK, DEFAULT_AE_LOCK);
986    params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK, DEFAULT_AWB_LOCK);
987    params->set(CameraProperties::MAX_NUM_METERING_AREAS, DEFAULT_MAX_NUM_METERING_AREAS);
988    params->set(CameraProperties::FOCAL_LENGTH, DEFAULT_FOCAL_LENGTH);
989    params->set(CameraProperties::HOR_ANGLE, DEFAULT_HOR_ANGLE);
990    params->set(CameraProperties::VER_ANGLE, DEFAULT_VER_ANGLE);
991    LOG_FUNCTION_NAME;
992
993    return ret;
994}
995
996status_t OMXCameraAdapter::insertSenMount(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
997    status_t ret = NO_ERROR;
998    char supported[MAX_PROP_VALUE_LENGTH];
999    const char *p;
1000    int i = 0;
1001
1002    LOG_FUNCTION_NAME;
1003
1004    memset(supported, '\0', MAX_PROP_VALUE_LENGTH);
1005
1006    // 1) Look up and assign sensor name
1007    for (i = 0; i < ARRAY_SIZE(mSensorNames); i++) {
1008        if(mSensorNames[i].num == caps.tSenMounting.nSenId) {
1009            // sensor found
1010            break;
1011        }
1012    }
1013    if ( i == ARRAY_SIZE(mSensorNames) ) {
1014        p = "UNKNOWN_SENSOR";
1015    } else {
1016        p = mSensorNames[i].param;
1017    }
1018    strncat(supported, p, MAX_PROP_NAME_LENGTH);
1019    params->set(CameraProperties::CAMERA_NAME, supported);
1020
1021    // 2) Assign mounting rotation
1022    params->set(CameraProperties::ORIENTATION_INDEX, caps.tSenMounting.nRotation);
1023
1024    LOG_FUNCTION_NAME;
1025
1026    return ret;
1027}
1028
1029status_t OMXCameraAdapter::insertCapabilities(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) {
1030    status_t ret = NO_ERROR;
1031    char supported[MAX_PROP_VALUE_LENGTH];
1032
1033    LOG_FUNCTION_NAME;
1034
1035    if ( NO_ERROR == ret ) {
1036        ret = insertImageSizes(params, caps);
1037    }
1038
1039    if ( NO_ERROR == ret ) {
1040        ret = insertPreviewSizes(params, caps);
1041    }
1042
1043    if ( NO_ERROR == ret ) {
1044        ret = insertThumbSizes(params, caps);
1045    }
1046
1047    if ( NO_ERROR == ret ) {
1048        ret = insertZoomStages(params, caps);
1049    }
1050
1051    if ( NO_ERROR == ret ) {
1052        ret = insertImageFormats(params, caps);
1053    }
1054
1055    if ( NO_ERROR == ret ) {
1056        ret = insertPreviewFormats(params, caps);
1057    }
1058
1059    if ( NO_ERROR == ret ) {
1060        ret = insertFramerates(params, caps);
1061    }
1062
1063    if ( NO_ERROR == ret ) {
1064        ret = insertVFramerates(params, caps);
1065    }
1066
1067    if ( NO_ERROR == ret ) {
1068        ret = insertEVs(params, caps);
1069    }
1070
1071    if ( NO_ERROR == ret ) {
1072        ret = insertISOModes(params, caps);
1073    }
1074
1075    if ( NO_ERROR == ret ) {
1076        ret = insertIPPModes(params, caps);
1077    }
1078
1079    if ( NO_ERROR == ret ) {
1080        ret = insertWBModes(params, caps);
1081    }
1082
1083    if ( NO_ERROR == ret ) {
1084        ret = insertEffects(params, caps);
1085    }
1086
1087    if ( NO_ERROR == ret ) {
1088        ret = insertExpModes(params, caps);
1089    }
1090
1091    if ( NO_ERROR == ret ) {
1092        ret = insertFlashModes(params, caps);
1093    }
1094
1095    if ( NO_ERROR == ret ) {
1096        ret = insertSceneModes(params, caps);
1097    }
1098
1099    if ( NO_ERROR == ret ) {
1100        ret = insertFocusModes(params, caps);
1101    }
1102
1103    if ( NO_ERROR == ret ) {
1104        ret = insertFlickerModes(params, caps);
1105    }
1106
1107    if ( NO_ERROR == ret ) {
1108        ret = insertSenMount(params, caps);
1109    }
1110
1111    if ( NO_ERROR == ret ) {
1112        ret = insertLocks(params, caps);
1113    }
1114
1115    if ( NO_ERROR == ret ) {
1116        ret = insertDefaults(params, caps);
1117    }
1118
1119    LOG_FUNCTION_NAME_EXIT;
1120
1121    return ret;
1122}
1123
1124/*****************************************
1125 * public exposed function declarations
1126 *****************************************/
1127
1128status_t OMXCameraAdapter::getCaps(CameraProperties::Properties* params, OMX_HANDLETYPE handle) {
1129    status_t ret = NO_ERROR;
1130    int caps_size = 0;
1131    OMX_ERRORTYPE eError = OMX_ErrorNone;
1132    OMX_TI_CAPTYPE** caps = NULL;;
1133    OMX_TI_CONFIG_SHAREDBUFFER sharedBuffer;
1134    MemoryManager memMgr;
1135
1136    LOG_FUNCTION_NAME;
1137
1138    // allocate tiler (or ion) buffer for caps
1139    caps_size = sizeof(OMX_TI_CAPTYPE);
1140    caps = (OMX_TI_CAPTYPE**) memMgr.allocateBuffer(0, 0, NULL, caps_size, 1);
1141
1142    if (!caps) {
1143        CAMHAL_LOGEB("Error allocating buffer for caps %d", eError);
1144        ret = -ENOMEM;
1145        goto EXIT;
1146    }
1147
1148    // initialize structures to be passed to OMX Camera
1149    OMX_INIT_STRUCT_PTR (caps[0], OMX_TI_CAPTYPE);
1150    caps[0]->nPortIndex = OMX_ALL;
1151
1152    OMX_INIT_STRUCT_PTR (&sharedBuffer, OMX_TI_CONFIG_SHAREDBUFFER);
1153    sharedBuffer.nPortIndex = OMX_ALL;
1154    sharedBuffer.nSharedBuffSize = caps_size;
1155    sharedBuffer.pSharedBuff = (OMX_U8 *) caps[0];
1156
1157    // Get capabilities from OMX Camera
1158    eError =  OMX_GetConfig(handle, (OMX_INDEXTYPE) OMX_TI_IndexConfigCamCapabilities, &sharedBuffer);
1159    if ( OMX_ErrorNone != eError ) {
1160        CAMHAL_LOGEB("Error during capabilities query 0x%x", eError);
1161        ret = UNKNOWN_ERROR;
1162        goto EXIT;
1163    } else {
1164        CAMHAL_LOGDA("OMX capability query success");
1165    }
1166
1167    // Translate and insert Ducati capabilities to CameraProperties
1168    if ( NO_ERROR == ret ) {
1169        ret = insertCapabilities(params, *caps[0]);
1170    }
1171
1172    CAMHAL_LOGDB("sen mount id=%u", (unsigned int)caps[0]->tSenMounting.nSenId);
1173
1174
1175 EXIT:
1176    if (caps) {
1177        memMgr.freeBuffer((void*) caps);
1178        caps = NULL;
1179    }
1180
1181    LOG_FUNCTION_NAME_EXIT;
1182    return ret;
1183}
1184
1185};
1186
1187