Home | History | Annotate | Download | only in encoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2018 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at:
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  *
     17  *****************************************************************************
     18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
     19 */
     20 
     21 /**
     22 ******************************************************************************
     23 * @file ihevce_common_utils.h
     24 *
     25 * @brief
     26 *  Contains the declarations and definitions of common utils for encoder
     27 *
     28 * @author
     29 *  ittiam
     30 *
     31 ******************************************************************************
     32 */
     33 
     34 #ifndef _IHEVCE_COMMON_UTILS_H_
     35 #define _IHEVCE_COMMON_UTILS_H_
     36 
     37 #include <math.h>
     38 #include <limits.h>
     39 
     40 /*****************************************************************************/
     41 /* Constant Macros                                                           */
     42 /*****************************************************************************/
     43 
     44 /*****************************************************************************/
     45 /* Function Macros                                                           */
     46 /*****************************************************************************/
     47 
     48 /**
     49 ******************************************************************************
     50 *  @macro  IHEVCE_WT_PRED
     51 *  @brief Implements wt pred formula as per spec
     52 ******************************************************************************
     53 */
     54 #define IHEVCE_WT_PRED(p0, p1, w0, w1, rnd, shift)                                                 \
     55     (((((WORD32)w0) * ((WORD32)p0) + ((WORD32)w1) * ((WORD32)p1)) >> shift) + rnd)
     56 
     57 #define SORT_PRIMARY_INTTYPE_ARRAY_AND_REORDER_GENERIC_COMPANION_ARRAY(                            \
     58     primary_array, companion_array, array_length, type_companion)                                  \
     59     {                                                                                              \
     60         WORD32 i, j;                                                                               \
     61                                                                                                    \
     62         for(i = 0; i < (array_length - 1); i++)                                                    \
     63         {                                                                                          \
     64             for(j = (i + 1); j < array_length; j++)                                                \
     65             {                                                                                      \
     66                 if(primary_array[i] > primary_array[j])                                            \
     67                 {                                                                                  \
     68                     type_companion t;                                                              \
     69                                                                                                    \
     70                     SWAP(primary_array[i], primary_array[j]);                                      \
     71                                                                                                    \
     72                     t = companion_array[i];                                                        \
     73                     companion_array[i] = companion_array[j];                                       \
     74                     companion_array[j] = t;                                                        \
     75                 }                                                                                  \
     76             }                                                                                      \
     77         }                                                                                          \
     78     }
     79 
     80 #define SORT_PRIMARY_INTTYPE_ARRAY_AND_REORDER_INTTYPE_COMPANION_ARRAY(                            \
     81     primary_array, companion_array, array_length)                                                  \
     82     {                                                                                              \
     83         WORD32 i, j;                                                                               \
     84                                                                                                    \
     85         for(i = 0; i < (array_length - 1); i++)                                                    \
     86         {                                                                                          \
     87             for(j = (i + 1); j < array_length; j++)                                                \
     88             {                                                                                      \
     89                 if(primary_array[i] > primary_array[j])                                            \
     90                 {                                                                                  \
     91                     type_companion t;                                                              \
     92                                                                                                    \
     93                     SWAP(primary_array[i], primary_array[j]);                                      \
     94                     SWAP(companion_array[i], companion_array[j]);                                  \
     95                 }                                                                                  \
     96             }                                                                                      \
     97         }                                                                                          \
     98     }
     99 
    100 #define SORT_INTTYPE_ARRAY(primary_array, array_length)                                            \
    101     {                                                                                              \
    102         WORD32 i, j;                                                                               \
    103                                                                                                    \
    104         for(i = 0; i < (array_length - 1); i++)                                                    \
    105         {                                                                                          \
    106             for(j = (i + 1); j < array_length; j++)                                                \
    107             {                                                                                      \
    108                 if(primary_array[i] > primary_array[j])                                            \
    109                 {                                                                                  \
    110                     SWAP(primary_array[i], primary_array[j]);                                      \
    111                 }                                                                                  \
    112             }                                                                                      \
    113         }                                                                                          \
    114     }
    115 
    116 #define SET_BIT(x, bitpos) ((x) | (1 << (bitpos)))
    117 
    118 #define CLEAR_BIT(x, bitpos) ((x) & (~(1 << (bitpos))))
    119 
    120 #define CU_TREE_NODE_FILL(ps_node, valid_flag, posx, posy, size, inter_eval_enable)                \
    121     {                                                                                              \
    122         ps_node->is_node_valid = valid_flag;                                                       \
    123         ps_node->u1_cu_size = size;                                                                \
    124         ps_node->u1_intra_eval_enable = 0;                                                         \
    125         ps_node->b3_cu_pos_x = posx;                                                               \
    126         ps_node->b3_cu_pos_y = posy;                                                               \
    127         ps_node->u1_inter_eval_enable = inter_eval_enable;                                         \
    128     }
    129 
    130 /*****************************************************************************/
    131 /* Extern Function Declarations                                              */
    132 /*****************************************************************************/
    133 
    134 void ihevce_copy_2d(
    135     UWORD8 *pu1_dst,
    136     WORD32 dst_stride,
    137     UWORD8 *pu1_src,
    138     WORD32 src_stride,
    139     WORD32 blk_wd,
    140     WORD32 blk_ht);
    141 
    142 void ihevce_2d_square_copy_luma(
    143     void *p_dst,
    144     WORD32 dst_strd,
    145     void *p_src,
    146     WORD32 src_strd,
    147     WORD32 num_cols_to_copy,
    148     WORD32 unit_size);
    149 
    150 void ihevce_wt_avg_2d(
    151     UWORD8 *pu1_pred0,
    152     UWORD8 *pu1_pred1,
    153     WORD32 pred0_strd,
    154     WORD32 pred1_strd,
    155     WORD32 wd,
    156     WORD32 ht,
    157     UWORD8 *pu1_dst,
    158     WORD32 dst_strd,
    159     WORD32 w0,
    160     WORD32 w1,
    161     WORD32 o0,
    162     WORD32 o1,
    163     WORD32 log_wdc);
    164 
    165 void ihevce_itrans_recon_dc(
    166     UWORD8 *pu1_pred,
    167     WORD32 pred_strd,
    168     UWORD8 *pu1_dst,
    169     WORD32 dst_strd,
    170     WORD32 trans_size,
    171     WORD16 i2_deq_value,
    172     CHROMA_PLANE_ID_T e_chroma_plane);
    173 
    174 WORD32 ihevce_find_num_clusters_of_identical_points_1D(
    175     UWORD8 *pu1_inp_array,
    176     UWORD8 *pu1_out_array,
    177     UWORD8 *pu1_freq_of_out_data_in_inp,
    178     WORD32 i4_num_inp_array_elements);
    179 
    180 void ihevce_scale_mv(mv_t *ps_mv, WORD32 i4_poc_to, WORD32 i4_poc_from, WORD32 i4_curr_poc);
    181 
    182 WORD32 ihevce_compare_pu_mv_t(
    183     pu_mv_t *ps_1, pu_mv_t *ps_2, WORD32 i4_pred_mode_1, WORD32 i4_pred_mode_2);
    184 
    185 void ihevce_set_pred_buf_as_free(UWORD32 *pu4_idx_array, UWORD8 u1_buf_id);
    186 
    187 UWORD8 ihevce_get_free_pred_buf_indices(
    188     UWORD8 *pu1_idx_array, UWORD32 *pu4_bitfield, UWORD8 u1_num_bufs_requested);
    189 
    190 WORD32 ihevce_osal_init(void *pv_hle_ctxt);
    191 
    192 WORD32 ihevce_osal_delete(void *pv_hle_ctxt);
    193 
    194 static INLINE UWORD32 ihevce_num_ones_generic(UWORD32 bitfield)
    195 {
    196     bitfield = bitfield - ((bitfield >> 1) & 0x55555555);
    197     bitfield = (bitfield & 0x33333333) + ((bitfield >> 2) & 0x33333333);
    198     return (((bitfield + (bitfield >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
    199 }
    200 
    201 static INLINE UWORD32 ihevce_num_ones_popcnt(UWORD32 bitfield)
    202 {
    203     return __builtin_popcount(bitfield);
    204 }
    205 
    206 WORD32 ihevce_compute_area_of_valid_cus_in_ctb(cur_ctb_cu_tree_t *ps_cu_tree);
    207 
    208 void ihevce_cu_tree_init(
    209     cur_ctb_cu_tree_t *ps_cu_tree,
    210     cur_ctb_cu_tree_t *ps_cu_tree_root,
    211     WORD32 *pi4_nodes_created_in_cu_tree,
    212     WORD32 tree_depth,
    213     CU_POS_T e_grandparent_blk_pos,
    214     CU_POS_T e_parent_blk_pos,
    215     CU_POS_T e_cur_blk_pos);
    216 
    217 #endif /* _IHEVCE_COMMON_UTILS_H_ */
    218