Home | History | Annotate | Download | only in util
      1 /* Copyright (c) 2016, The Linux Foundation. All rights reserved.
      2 *
      3 * Redistribution and use in source and binary forms, with or without
      4 * modification, are permitted provided that the following conditions are
      5 * met:
      6 *     * Redistributions of source code must retain the above copyright
      7 *       notice, this list of conditions and the following disclaimer.
      8 *     * Redistributions in binary form must reproduce the above
      9 *       copyright notice, this list of conditions and the following
     10 *       disclaimer in the documentation and/or other materials provided
     11 *       with the distribution.
     12 *     * Neither the name of The Linux Foundation nor the names of its
     13 *       contributors may be used to endorse or promote products derived
     14 *       from this software without specific prior written permission.
     15 *
     16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 *
     28 */
     29 
     30 #define LOG_TAG "QCameraCommon"
     31 
     32 // System dependencies
     33 #include <utils/Errors.h>
     34 #include <stdlib.h>
     35 #include <string.h>
     36 #include <utils/Log.h>
     37 
     38 // Camera dependencies
     39 #include "QCameraCommon.h"
     40 
     41 using namespace android;
     42 
     43 namespace qcamera {
     44 
     45 #ifndef TRUE
     46 #define TRUE 1
     47 #endif
     48 
     49 #ifndef FALSE
     50 #define FALSE 0
     51 #endif
     52 
     53 /*===========================================================================
     54  * FUNCTION   : QCameraCommon
     55  *
     56  * DESCRIPTION: default constructor of QCameraCommon
     57  *
     58  * PARAMETERS : None
     59  *
     60  * RETURN     : None
     61  *==========================================================================*/
     62 QCameraCommon::QCameraCommon() :
     63     m_pCapability(NULL)
     64 {
     65 }
     66 
     67 /*===========================================================================
     68  * FUNCTION   : ~QCameraCommon
     69  *
     70  * DESCRIPTION: destructor of QCameraCommon
     71  *
     72  * PARAMETERS : None
     73  *
     74  * RETURN     : None
     75  *==========================================================================*/
     76 QCameraCommon::~QCameraCommon()
     77 {
     78 }
     79 
     80 /*===========================================================================
     81  * FUNCTION   : init
     82  *
     83  * DESCRIPTION: Init function for QCameraCommon
     84  *
     85  * PARAMETERS :
     86  *   @pCapability : Capabilities
     87  *
     88  * RETURN     : int32_t type of status
     89  *              NO_ERROR  -- success
     90  *              none-zero failure code
     91  *==========================================================================*/
     92 int32_t QCameraCommon::init(cam_capability_t *pCapability)
     93 {
     94     m_pCapability = pCapability;
     95 
     96     return NO_ERROR;
     97 }
     98 
     99 /*===========================================================================
    100  * FUNCTION   : calculateLCM
    101  *
    102  * DESCRIPTION: Get the LCM of 2 numbers
    103  *
    104  * PARAMETERS :
    105  *   @num1   : First number
    106  *   @num2   : second number
    107  *
    108  * RETURN     : int32_t type (LCM)
    109  *
    110  *==========================================================================*/
    111 uint32_t QCameraCommon::calculateLCM(int32_t num1, int32_t num2)
    112 {
    113    uint32_t lcm = 0;
    114    uint32_t temp = 0;
    115 
    116    if ((num1 < 1) && (num2 < 1)) {
    117        return 0;
    118    } else if (num1 < 1) {
    119        return num2;
    120    } else if (num2 < 1) {
    121        return num1;
    122    }
    123 
    124    if (num1 > num2) {
    125        lcm = num1;
    126    } else {
    127        lcm = num2;
    128    }
    129    temp = lcm;
    130 
    131    while (1) {
    132        if (((lcm % num1) == 0) && ((lcm % num2) == 0)) {
    133            break;
    134        }
    135        lcm += temp;
    136    }
    137    return lcm;
    138 }
    139 
    140 /*===========================================================================
    141  * FUNCTION   : getAnalysisInfo
    142  *
    143  * DESCRIPTION: Get the Analysis information based on
    144  *     current mode and feature mask
    145  *
    146  * PARAMETERS :
    147  *   @fdVideoEnabled : Whether fdVideo enabled currently
    148  *   @hal3           : Whether hal3 or hal1
    149  *   @featureMask    : Feature mask
    150  *   @pAnalysis_info : Analysis info to be filled
    151  *
    152  * RETURN     : int32_t type of status
    153  *              NO_ERROR  -- success
    154  *              none-zero failure code
    155  *==========================================================================*/
    156 int32_t QCameraCommon::getAnalysisInfo(
    157         bool fdVideoEnabled,
    158         bool hal3,
    159         cam_feature_mask_t featureMask,
    160         cam_analysis_info_t *pAnalysisInfo)
    161 {
    162     if (!pAnalysisInfo) {
    163         return BAD_VALUE;
    164     }
    165 
    166     pAnalysisInfo->valid = 0;
    167 
    168     if ((fdVideoEnabled == TRUE) && (hal3 == FALSE) &&
    169             (m_pCapability->analysis_info[CAM_ANALYSIS_INFO_FD_VIDEO].hw_analysis_supported) &&
    170             (m_pCapability->analysis_info[CAM_ANALYSIS_INFO_FD_VIDEO].valid)) {
    171         *pAnalysisInfo =
    172                 m_pCapability->analysis_info[CAM_ANALYSIS_INFO_FD_VIDEO];
    173     } else if (m_pCapability->analysis_info[CAM_ANALYSIS_INFO_FD_STILL].valid) {
    174         *pAnalysisInfo =
    175                 m_pCapability->analysis_info[CAM_ANALYSIS_INFO_FD_STILL];
    176         if (hal3 == TRUE) {
    177             pAnalysisInfo->analysis_max_res = pAnalysisInfo->analysis_recommended_res;
    178         }
    179     }
    180 
    181     if ((featureMask & CAM_QCOM_FEATURE_PAAF) &&
    182       (m_pCapability->analysis_info[CAM_ANALYSIS_INFO_PAAF].valid)) {
    183         cam_analysis_info_t *pPaafInfo =
    184           &m_pCapability->analysis_info[CAM_ANALYSIS_INFO_PAAF];
    185 
    186         if (!pAnalysisInfo->valid) {
    187             *pAnalysisInfo = *pPaafInfo;
    188         } else {
    189             pAnalysisInfo->analysis_max_res.width =
    190                 MAX(pAnalysisInfo->analysis_max_res.width,
    191                 pPaafInfo->analysis_max_res.width);
    192             pAnalysisInfo->analysis_max_res.height =
    193                 MAX(pAnalysisInfo->analysis_max_res.height,
    194                 pPaafInfo->analysis_max_res.height);
    195             pAnalysisInfo->analysis_padding_info.height_padding =
    196                 calculateLCM(pAnalysisInfo->analysis_padding_info.height_padding,
    197                 pPaafInfo->analysis_padding_info.height_padding);
    198             pAnalysisInfo->analysis_padding_info.width_padding =
    199                 calculateLCM(pAnalysisInfo->analysis_padding_info.width_padding,
    200                 pPaafInfo->analysis_padding_info.width_padding);
    201             pAnalysisInfo->analysis_padding_info.plane_padding =
    202                 calculateLCM(pAnalysisInfo->analysis_padding_info.plane_padding,
    203                 pPaafInfo->analysis_padding_info.plane_padding);
    204             pAnalysisInfo->analysis_padding_info.min_stride =
    205                 MAX(pAnalysisInfo->analysis_padding_info.min_stride,
    206                 pPaafInfo->analysis_padding_info.min_stride);
    207             pAnalysisInfo->analysis_padding_info.min_stride =
    208                 ALIGN(pAnalysisInfo->analysis_padding_info.min_stride,
    209                 pAnalysisInfo->analysis_padding_info.width_padding);
    210 
    211             pAnalysisInfo->analysis_padding_info.min_scanline =
    212                 MAX(pAnalysisInfo->analysis_padding_info.min_scanline,
    213                 pPaafInfo->analysis_padding_info.min_scanline);
    214             pAnalysisInfo->analysis_padding_info.min_scanline =
    215                 ALIGN(pAnalysisInfo->analysis_padding_info.min_scanline,
    216                 pAnalysisInfo->analysis_padding_info.height_padding);
    217 
    218             pAnalysisInfo->hw_analysis_supported |=
    219                 pPaafInfo->hw_analysis_supported;
    220         }
    221     }
    222 
    223     return pAnalysisInfo->valid ? NO_ERROR : BAD_VALUE;
    224 }
    225 
    226 }; // namespace qcamera
    227