Home | History | Annotate | Download | only in encoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2015 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
     24 *  ih264e_structs.h
     25 *
     26 * @brief
     27 *  Structure definitions used in the encoder
     28 *
     29 * @author
     30 *  Harish
     31 *
     32 * @remarks
     33 *  None
     34 *
     35 *******************************************************************************
     36 */
     37 
     38 #ifndef IH264E_STRUCTS_H_
     39 #define IH264E_STRUCTS_H_
     40 
     41 /*****************************************************************************/
     42 /* Structure definitions                                                    */
     43 /*****************************************************************************/
     44 
     45 /* Early declaration of structs */
     46 typedef struct _codec_t codec_t;
     47 typedef struct _proc_t process_ctxt_t;
     48 
     49 
     50 /*****************************************************************************/
     51 /* Extern Function type definitions                                          */
     52 /*****************************************************************************/
     53 
     54 /**
     55 ******************************************************************************
     56  *  @brief      intra prediction filters leaf level
     57 ******************************************************************************
     58  */
     59 typedef void (*pf_intra_pred)(UWORD8 *pu1_src, UWORD8 *pu1_dst,
     60                               WORD32 src_strd, WORD32 dst_strd,
     61                               WORD32 ui_neighboravailability);
     62 
     63 /**
     64 ******************************************************************************
     65  *  @brief      inter prediction filters leaf level
     66 ******************************************************************************
     67  */
     68 
     69 typedef void (*pf_inter_pred_luma_bilinear)(UWORD8 *pu1_src1, UWORD8 *pu1_src2, UWORD8 *pu1_dst,
     70                                             WORD32 src_strd1, WORD32 src_strd2, WORD32 dst_strd,
     71                                             WORD32 height, WORD32 width);
     72 
     73 /**
     74 ******************************************************************************
     75  *  @brief      fwd transform leaf level
     76 ******************************************************************************
     77  */
     78 typedef void (*pf_trans_quant)(UWORD8*pu1_src, UWORD8 *pu1_pred, WORD16 *pi2_out,
     79                                WORD32 i4_src_stride, UWORD32 u4_pred_stride, UWORD32 u4_dst_stride,
     80                                const UWORD16 *pu2_scale_mat, const UWORD16 *pu2_thresh_mat,
     81                                UWORD32 u4_qbit, UWORD32 u4_round_fact, UWORD8 *pu1_nnz);
     82 
     83 typedef void (*pf_iquant_itrans)(WORD16 *pi2_src, UWORD8 *pu1_pred, UWORD8 *pu1_out,
     84                                  WORD32 i4_src_stride, UWORD32 u4_pred_stride, UWORD32 u4_out_stride,
     85                                  const UWORD16 *pu2_iscale_mat, const UWORD16 *pu2_weigh_mat,
     86                                  UWORD32 qp_div, WORD32 *pi4_tmp);
     87 
     88 /**
     89 ******************************************************************************
     90  *  @brief      Padding leaf level
     91 ******************************************************************************
     92  */
     93 typedef void (*pf_pad)(UWORD8 *pu1_src, WORD32 src_strd, WORD32 wd, WORD32 pad_size);
     94 
     95 /**
     96 ******************************************************************************
     97  *  @brief      memory handling leaf level
     98 ******************************************************************************
     99  */
    100 typedef void (*pf_memcpy)(UWORD8 *pu1_dst, UWORD8 *pu1_src, UWORD32 num_bytes);
    101 
    102 typedef void (*pf_memset)(UWORD8 *pu1_dst, UWORD8 value, UWORD32 num_bytes);
    103 
    104 typedef void (*pf_memcpy_mul8)(UWORD8 *pu1_dst, UWORD8 *pu1_src, UWORD32 num_bytes);
    105 
    106 typedef void (*pf_memset_mul8)(UWORD8 *pu1_dst, UWORD8 value, UWORD32 num_bytes);
    107 
    108 /**
    109 ******************************************************************************
    110  *  @brief      Sad computation
    111 ******************************************************************************
    112  */
    113 typedef void (*pf_compute_sad)(UWORD8 *pu1_src, UWORD8 *pu1_est,
    114                                UWORD32 src_strd, UWORD32 est_strd,
    115                                WORD32 i4_max_sad, WORD32 *pi4_mb_distortion);
    116 
    117 /**
    118 ******************************************************************************
    119  *  @brief     Intra mode eval:encoder level
    120 ******************************************************************************
    121  */
    122 typedef void (*pf_evaluate_intra_modes)(UWORD8 *pu1_src, UWORD8 *pu1_ngbr_pels_i16, UWORD8 *pu1_dst,
    123                                         UWORD32 src_strd, UWORD32 dst_strd,
    124                                         WORD32 u4_n_avblty, UWORD32 *u4_intra_mode,
    125                                         WORD32 *pu4_sadmin,
    126                                         UWORD32 u4_valid_intra_modes);
    127 
    128 typedef void (*pf_evaluate_intra_4x4_modes)(UWORD8 *pu1_src, UWORD8 *pu1_ngbr_pels, UWORD8 *pu1_dst,
    129                                             UWORD32 src_strd, UWORD32 dst_strd,
    130                                             WORD32 u4_n_avblty, UWORD32 *u4_intra_mode,
    131                                             WORD32 *pu4_sadmin,
    132                                             UWORD32 u4_valid_intra_modes, UWORD32 u4_lambda,
    133                                             UWORD32 u4_predictd_mode);
    134 
    135 /**
    136 ******************************************************************************
    137  *  @brief     half_pel generation :encoder level
    138 ******************************************************************************
    139  */
    140 typedef void (*pf_sixtapfilter_horz)(UWORD8 *pu1_src, UWORD8 *pu1_dst,
    141                                      WORD32 src_strd, WORD32 dst_strd);
    142 
    143 typedef void (*pf_sixtap_filter_2dvh_vert)(UWORD8 *pu1_src, UWORD8 *pu1_dst1, UWORD8 *pu1_dst2,
    144                                            WORD32 src_strd, WORD32 dst_strd,
    145                                            WORD32 *pi16_pred1,
    146                                            WORD32 pi16_pred1_strd);
    147 /**
    148 ******************************************************************************
    149  *  @brief     color space conversion
    150 ******************************************************************************
    151  */
    152 typedef void (*pf_fmt_conv_420p_to_420sp)(UWORD8 *pu1_y_src, UWORD8 *pu1_u_src, UWORD8 *pu1_v_src,
    153                                           UWORD8 *pu1_y_dst, UWORD8 *pu1_uv_dst,
    154                                           UWORD16 u2_height, UWORD16 u2_width,
    155                                           UWORD16 src_y_strd, UWORD16 src_u_strd, UWORD16 src_v_strd,
    156                                           UWORD16 dst_y_strd, UWORD16 dst_uv_strd,
    157                                           UWORD32 convert_uv_only);
    158 
    159 typedef void (*pf_fmt_conv_422ile_to_420sp)(UWORD8 *pu1_y_buf, UWORD8 *pu1_u_buf, UWORD8 *pu1_v_buf,
    160                                             UWORD8 *pu1_422i_buf,
    161                                             WORD32 u4_y_width, WORD32 u4_y_height, WORD32 u4_y_stride,
    162                                             WORD32 u4_u_stride, WORD32 u4_v_stride,
    163                                             WORD32 u4_422i_stride);
    164 
    165 
    166 
    167 /**
    168 ******************************************************************************
    169  *  @brief     ME evaluation
    170 ******************************************************************************
    171  */
    172 typedef void ih264e_compute_me_ft(process_ctxt_t *);
    173 
    174 /**
    175 ******************************************************************************
    176  *  @brief     SKIP decision
    177 ******************************************************************************
    178  */
    179 typedef WORD32 ih264e_skip_params_ft(process_ctxt_t *, WORD32);
    180 
    181 
    182 /*****************************************************************************/
    183 /* Enums                                                                     */
    184 /*****************************************************************************/
    185 
    186 /**
    187  ******************************************************************************
    188  *  @enum  CODEC_STATE_T
    189  *  @brief codec state
    190  ******************************************************************************
    191  */
    192 typedef enum
    193 {
    194     INIT_DONE,
    195     HEADER_DONE,
    196     FIRST_FRAME_DONE,
    197 } CODEC_STATE_T;
    198 
    199 
    200 /**
    201  ******************************************************************************
    202  *  @enum  JOBQ_CMD_T
    203  *  @brief list of job commands (used during job instantiation)
    204  ******************************************************************************
    205  */
    206 typedef enum
    207 {
    208     CMD_PROCESS,
    209     CMD_ENTROPY,
    210     CMD_FMTCONV,
    211     CMD_ME,
    212 }JOBQ_CMD_T;
    213 
    214 
    215 /*****************************************************************************/
    216 /* Structures                                                                */
    217 /*****************************************************************************/
    218 
    219 /**
    220  * PU information
    221  */
    222 typedef struct
    223 {
    224     /**
    225      *  Motion Vector
    226      */
    227     mv_t s_mv;
    228 
    229     /**
    230      *  Ref index
    231      */
    232     WORD8   i1_ref_idx;
    233 
    234 } enc_pu_mv_t;
    235 
    236 
    237 /*
    238  * Total Pu info for an MB
    239  */
    240 typedef struct
    241 {
    242 
    243     /* Array with ME info for all lists */
    244     enc_pu_mv_t  s_me_info[2];
    245 
    246     /**
    247      *  PU X position in terms of min PU (4x4) units
    248      */
    249     UWORD32     b4_pos_x        : 4;
    250 
    251     /**
    252      *  PU Y position in terms of min PU (4x4) units
    253      */
    254     UWORD32     b4_pos_y        : 4;
    255 
    256     /**
    257      *  PU width in pixels = (b4_wd + 1) << 2
    258      */
    259     UWORD32     b4_wd           : 2;
    260 
    261     /**
    262      *  PU height in pixels = (b4_ht + 1) << 2
    263      */
    264     UWORD32     b4_ht           : 2;
    265 
    266     /**
    267      *  Intra or Inter flag for each partition - 0 or 1
    268      */
    269     UWORD32     b1_intra_flag   : 1;
    270 
    271     /**
    272      *  PRED_L0, PRED_L1, PRED_BI
    273      */
    274     UWORD32     b2_pred_mode    : 2;
    275 
    276 
    277 } enc_pu_t;
    278 
    279 
    280 typedef struct
    281 {
    282     /** Descriptor of raw buffer                                     */
    283     iv_raw_buf_t                            s_raw_buf;
    284 
    285     /** Lower 32bits of time stamp corresponding to the above buffer */
    286     UWORD32                                 u4_timestamp_low;
    287 
    288     /** Upper 32bits of time stamp corresponding to the above buffer */
    289     UWORD32                                 u4_timestamp_high;
    290 
    291     /** Flag to indicate if the current buffer is last buffer */
    292     UWORD32                                 u4_is_last;
    293 
    294     /** Flag to indicate if mb info is sent along with input buffer     */
    295     UWORD32                                 u4_mb_info_type;
    296 
    297     /** Flag to indicate the size of mb info structure                  */
    298     UWORD32                                 u4_mb_info_size;
    299 
    300     /** Buffer containing mb info if mb_info_type is non-zero           */
    301     void                                    *pv_mb_info;
    302 
    303     /** Flag to indicate if pic info is sent along with input buffer     */
    304     UWORD32                                 u4_pic_info_type;
    305 
    306     /** Buffer containing pic info if mb_info_type is non-zero           */
    307     void                                    *pv_pic_info;
    308 
    309 }inp_buf_t;
    310 
    311 typedef struct
    312 {
    313     /** Descriptor of bitstream buffer                                     */
    314     iv_bits_buf_t                           s_bits_buf;
    315 
    316     /** Lower 32bits of time stamp corresponding to the above buffer */
    317     UWORD32                                 u4_timestamp_low;
    318 
    319     /** Upper 32bits of time stamp corresponding to the above buffer */
    320     UWORD32                                 u4_timestamp_high;
    321 
    322     /** Flag to indicate if the current buffer is last buffer */
    323     UWORD32                                 u4_is_last;
    324 
    325 }out_buf_t;
    326 
    327 typedef struct
    328 {
    329     /** Descriptor of picture buffer                                     */
    330     pic_buf_t                               s_pic_buf;
    331 
    332     /** Lower 32bits of time stamp corresponding to the above buffer */
    333     UWORD32                                 u4_timestamp_low;
    334 
    335     /** Upper 32bits of time stamp corresponding to the above buffer */
    336     UWORD32                                 u4_timestamp_high;
    337 
    338     /** Flag to indicate if the current buffer is last buffer */
    339     UWORD32                                 u4_is_last;
    340 
    341     /** Picture count corresponding to current picture */
    342     WORD32                                  i4_pic_cnt;
    343 
    344 }rec_buf_t;
    345 
    346 typedef struct
    347 {
    348     /** maximum width for which codec should request memory requirements    */
    349     UWORD32                                     u4_max_wd;
    350 
    351     /** maximum height for which codec should request memory requirements   */
    352     UWORD32                                     u4_max_ht;
    353 
    354     /** Maximum number of reference frames                                  */
    355     UWORD32                                     u4_max_ref_cnt;
    356 
    357     /** Maximum number of reorder frames                                    */
    358     UWORD32                                     u4_max_reorder_cnt;
    359 
    360     /** Maximum level supported                                             */
    361     UWORD32                                     u4_max_level;
    362 
    363     /** Input color format                                                  */
    364     IV_COLOR_FORMAT_T                           e_inp_color_fmt;
    365 
    366     /** Flag to enable/disable - To be used only for debugging/testing      */
    367     UWORD32                                     u4_enable_recon;
    368 
    369     /** Recon color format                                                  */
    370     IV_COLOR_FORMAT_T                           e_recon_color_fmt;
    371 
    372     /** Encoder Speed preset - Value between 0 (slowest) and 100 (fastest)  */
    373     IVE_SPEED_CONFIG                            u4_enc_speed_preset;
    374 
    375     /** Rate control mode                                                   */
    376     IVE_RC_MODE_T                               e_rc_mode;
    377 
    378     /** Maximum frame rate to be supported                                  */
    379     UWORD32                                     u4_max_framerate;
    380 
    381     /** Maximum bitrate to be supported                                     */
    382     UWORD32                                     u4_max_bitrate;
    383 
    384     /** Maximum number of consecutive  B frames                             */
    385     UWORD32                                     u4_num_bframes;
    386 
    387     /** Content type Interlaced/Progressive                                 */
    388     IV_CONTENT_TYPE_T                           e_content_type;
    389 
    390     /** Maximum search range to be used in X direction                      */
    391     UWORD32                                     u4_max_srch_rng_x;
    392 
    393     /** Maximum search range to be used in Y direction                      */
    394     UWORD32                                     u4_max_srch_rng_y;
    395 
    396     /** Slice Mode                                                          */
    397     IVE_SLICE_MODE_T                            e_slice_mode;
    398 
    399     /** Slice parameter                                                     */
    400     UWORD32                                     u4_slice_param;
    401 
    402     /** Processor architecture                                          */
    403     IV_ARCH_T                                   e_arch;
    404 
    405     /** SOC details                                                     */
    406     IV_SOC_T                                    e_soc;
    407 
    408     /** Input width to be sent in bitstream                                */
    409     UWORD32                                     u4_disp_wd;
    410 
    411     /** Input height to be sent in bitstream                               */
    412     UWORD32                                     u4_disp_ht;
    413 
    414     /** Input width                                                     */
    415     UWORD32                                     u4_wd;
    416 
    417     /** Input height                                                    */
    418     UWORD32                                     u4_ht;
    419 
    420     /** Input stride                                                    */
    421     UWORD32                                     u4_strd;
    422 
    423     /** Source frame rate                                               */
    424     UWORD32                                     u4_src_frame_rate;
    425 
    426     /** Target frame rate                                               */
    427     UWORD32                                     u4_tgt_frame_rate;
    428 
    429     /** Target bitrate in kilobits per second                           */
    430     UWORD32                                     u4_target_bitrate;
    431 
    432     /** Force current frame type                                        */
    433     IV_PICTURE_CODING_TYPE_T                    e_frame_type;
    434 
    435     /** Encoder mode                                                    */
    436     IVE_ENC_MODE_T                              e_enc_mode;
    437 
    438     /** Set initial Qp for I pictures                                   */
    439     UWORD32                                     u4_i_qp;
    440 
    441     /** Set initial Qp for P pictures                                   */
    442     UWORD32                                     u4_p_qp;
    443 
    444     /** Set initial Qp for B pictures                                   */
    445     UWORD32                                     u4_b_qp;
    446 
    447     /** Set minimum Qp for I pictures                                   */
    448     UWORD32                                     u4_i_qp_min;
    449 
    450     /** Set maximum Qp for I pictures                                   */
    451     UWORD32                                     u4_i_qp_max;
    452 
    453     /** Set minimum Qp for P pictures                                   */
    454     UWORD32                                     u4_p_qp_min;
    455 
    456     /** Set maximum Qp for P pictures                                   */
    457     UWORD32                                     u4_p_qp_max;
    458 
    459     /** Set minimum Qp for B pictures                                   */
    460     UWORD32                                     u4_b_qp_min;
    461 
    462     /** Set maximum Qp for B pictures                                   */
    463     UWORD32                                     u4_b_qp_max;
    464 
    465     /** Adaptive intra refresh mode                                     */
    466     IVE_AIR_MODE_T                              e_air_mode;
    467 
    468     /** Adaptive intra refresh period in frames                         */
    469     UWORD32                                     u4_air_refresh_period;
    470 
    471     /** VBV buffer delay                                                */
    472     UWORD32                                     u4_vbv_buffer_delay;
    473 
    474     /** VBV buffer size                                                 */
    475     UWORD32                                     u4_vbv_buf_size;
    476 
    477     /** Number of cores to be used                                      */
    478     UWORD32                                     u4_num_cores;
    479 
    480     /** ME speed preset - Value between 0 (slowest) and 100 (fastest)      */
    481     UWORD32                                     u4_me_speed_preset;
    482 
    483     /** Flag to enable/disable half pel motion estimation               */
    484     UWORD32                                     u4_enable_hpel;
    485 
    486     /** Flag to enable/disable quarter pel motion estimation            */
    487     UWORD32                                     u4_enable_qpel;
    488 
    489     /** Flag to enable/disable intra 4x4 analysis                       */
    490     UWORD32                                     u4_enable_intra_4x4;
    491 
    492     /** Flag to enable/disable intra 8x8 analysis                       */
    493     UWORD32                                     u4_enable_intra_8x8;
    494 
    495     /** Flag to enable/disable intra 16x16 analysis                     */
    496     UWORD32                                     u4_enable_intra_16x16;
    497 
    498     /** Flag to enable/disable fast SAD approximation                   */
    499     UWORD32                                     u4_enable_fast_sad;
    500 
    501     /*flag to enable/disable alternate reference frames                 */
    502     UWORD32                                     u4_enable_alt_ref;
    503 
    504     /*Flag to enable/disable computation of SATDQ in ME*/
    505     UWORD32                                     u4_enable_satqd;
    506 
    507     /*Minimum SAD to search for*/
    508     WORD32                                     i4_min_sad;
    509 
    510     /** Maximum search range in X direction for farthest reference      */
    511     UWORD32                                     u4_srch_rng_x;
    512 
    513     /** Maximum search range in Y direction for farthest reference      */
    514     UWORD32                                     u4_srch_rng_y;
    515 
    516     /** I frame interval                                                */
    517     UWORD32                                     u4_i_frm_interval;
    518 
    519     /** IDR frame interval                                              */
    520     UWORD32                                     u4_idr_frm_interval;
    521 
    522     /** Disable deblock level (0: Enable completely, 3: Disable completely */
    523     UWORD32                                     u4_disable_deblock_level;
    524 
    525     /** Profile                                                         */
    526     IV_PROFILE_T                                e_profile;
    527 
    528     /** Lower 32bits of time stamp corresponding to input buffer,
    529      * from which this command takes effect                             */
    530     UWORD32                                     u4_timestamp_low;
    531 
    532     /** Upper 32bits of time stamp corresponding to input buffer,
    533      * from which this command takes effect                             */
    534     UWORD32                                     u4_timestamp_high;
    535 
    536     /** Flag to say if the current config parameter set is valid
    537      * Will be zero to start with and will be set to 1, when configured
    538      * Once encoder uses the parameter set, this will be set to zero */
    539     UWORD32                                     u4_is_valid;
    540 
    541     /** Command associated with this config param set */
    542     IVE_CONTROL_API_COMMAND_TYPE_T              e_cmd;
    543 
    544     /** Input width in mbs                                                    */
    545     UWORD32                                     i4_wd_mbs;
    546 
    547     /** Input height in mbs                                                   */
    548     UWORD32                                     i4_ht_mbs;
    549 
    550     /** entropy coding mode flag                                              */
    551     UWORD32                                     u4_entropy_coding_mode;
    552 
    553     /** enable weighted prediction                                            */
    554     UWORD32                                     u4_weighted_prediction;
    555 
    556     /** enable constrained intra prediction                                   */
    557     UWORD32                                     u4_constrained_intra_pred;
    558 
    559     /** Pic info type */
    560     UWORD32                                     u4_pic_info_type;
    561     /**
    562      * MB info type
    563      */
    564     UWORD32                                     u4_mb_info_type;
    565 
    566 }cfg_params_t;
    567 
    568 
    569 
    570 /** Structure to hold format conversion context */
    571 typedef struct
    572 {
    573     /** Current row for which format conversion should be done */
    574     WORD32 i4_cur_row;
    575 
    576     /** Number of rows for which format conversion should be done */
    577     WORD32 i4_num_rows;
    578 
    579 }fmt_conv_t;
    580 
    581 
    582 /**
    583  * Structure to represent a processing job entry
    584  */
    585 typedef struct
    586 {
    587     /**
    588      * Command
    589      */
    590     WORD32 i4_cmd;
    591 
    592     /**
    593      * MB x of the starting MB
    594      */
    595     WORD16 i2_mb_x;
    596 
    597     /**
    598      * MB y of the starting MB
    599      */
    600 
    601     WORD16 i2_mb_y;
    602 
    603     /**
    604      * Number of MBs that need to be processed in this job
    605      */
    606     WORD16 i2_mb_cnt;
    607 
    608     /**
    609      * Process contexts base index
    610      * Will toggle between 0 and MAX_PROCESS_THREADS
    611      */
    612     WORD16 i2_proc_base_idx;
    613 
    614 } job_t;
    615 
    616 
    617 /**
    618  * Structure to represent a MV Bank buffer
    619  */
    620 typedef struct
    621 {
    622     /**
    623      *  Pointer to hold num PUs each MB in a picture
    624      */
    625     UWORD32 *pu4_mb_pu_cnt;
    626 
    627     /**
    628      * Pointer to hold enc_pu_t for each PU in a picture
    629      */
    630     enc_pu_t *ps_pic_pu;
    631 
    632     /**
    633      * Pointer to hold PU map for each MB in a picture
    634      */
    635     UWORD8 *pu1_pic_pu_map;
    636 
    637     /**
    638      * Pointer to hold the Slice map
    639      */
    640     UWORD16 *pu1_pic_slice_map;
    641 
    642     /**
    643      * Absolute POC for the current MV Bank
    644      */
    645     WORD32 i4_abs_poc;
    646 
    647     /**
    648      * Buffer Id
    649      */
    650     WORD32     i4_buf_id;
    651 
    652 } mv_buf_t;
    653 
    654 
    655 /**
    656  * Reference set containing pointers to MV buf and pic buf
    657  */
    658 typedef struct
    659 {
    660     /** Picture count */
    661     WORD32    i4_pic_cnt;
    662 
    663     /** POC */
    664     WORD32    i4_poc;
    665 
    666     /** picture buffer */
    667     pic_buf_t *ps_pic_buf;
    668 
    669     /** mv buffer */
    670     mv_buf_t  *ps_mv_buf;
    671 
    672 }ref_set_t;
    673 
    674 typedef struct
    675 {
    676 
    677     /**
    678      * Pointer to current PPS
    679      */
    680     pps_t *ps_pps;
    681 
    682     /**
    683      * Pointer to current SPS
    684      */
    685     sps_t *ps_sps;
    686 
    687     /**
    688      * Pointer to current slice header structure
    689      */
    690     slice_header_t *ps_slice_hdr;
    691 
    692     /**
    693      * MB's x position within a picture in raster scan in MB units
    694      */
    695     WORD32 i4_mb_x;
    696 
    697     /**
    698      * MB's y position within a picture in raster scan in MB units
    699      */
    700 
    701     WORD32 i4_mb_y;
    702 
    703     /**
    704      * Current PU structure - set to MB enc_pu_t pointer at the start of MB processing and incremented
    705      * for every TU
    706      */
    707     enc_pu_t *ps_pu;
    708 
    709     /**
    710      * Pointer to frame level enc_pu_t for the current frame being parsed
    711      * where MVs and Intra pred modes will be updated
    712      */
    713     enc_pu_t *ps_pic_pu;
    714 
    715     /**
    716      *  Pointer to hold num PUs each MB in a picture
    717      */
    718     UWORD32 *pu4_mb_pu_cnt;
    719 
    720     /** PU Index map per MB. The indices in this map are w.r.t picture pu array and not
    721      * w.r.t MB pu array.
    722      * This will be used during mv prediction and since neighbors will have different MB pu map
    723      * it will be easier if they all have indices w.r.t picture level PU array rather than MB level
    724      * PU array.
    725      * pu1_pic_pu_map is map w.r.t MB's enc_pu_t array
    726      */
    727     UWORD32 *pu4_pic_pu_idx_map;
    728 
    729     /**
    730       * Pointer to pu_map for the current frame being parsed
    731       * where MVs and Intra pred modes will be updated
    732       */
    733      UWORD8 *pu1_pic_pu_map;
    734 
    735      /**
    736       *  PU count in current MB
    737       */
    738      WORD32 i4_mb_pu_cnt;
    739 
    740      /**
    741       *  PU count in current MB
    742       */
    743      WORD32 i4_mb_start_pu_idx;
    744 
    745      /**
    746       *  Top availability for current MB level
    747       */
    748      UWORD8 u1_top_mb_avail;
    749 
    750      /**
    751       *  Top right availability for current MB level
    752       */
    753      UWORD8 u1_top_rt_mb_avail;
    754      /**
    755       *  Top left availability for current MB level
    756       */
    757      UWORD8 u1_top_lt_mb_avail;
    758      /**
    759       *  left availability for current MB level
    760       */
    761      UWORD8 u1_left_mb_avail;
    762 
    763 }mv_ctxt_t;
    764 
    765 typedef struct
    766 {
    767     /**
    768      * MB's x position within a picture in raster scan in MB units
    769      */
    770     WORD32 i4_mb_x;
    771 
    772     /**
    773      * MB's y position within a picture in raster scan in MB units
    774      */
    775     WORD32 i4_mb_y;
    776 
    777     /**
    778      * MB's x position within a Slice in raster scan in MB units
    779      */
    780     WORD32 i4_mb_slice_x;
    781 
    782     /**
    783      * MB's y position within a Slice in raster scan in MB units
    784      */
    785     WORD32 i4_mb_slice_y;
    786 
    787     /**
    788      * Vertical strength, Two bits per edge.
    789      * Stored in format. BS[15] | BS[14] | .. |BS[0]
    790      */
    791     UWORD32 *pu4_pic_vert_bs;
    792 
    793     /**
    794      * Boundary strength, Two bits per edge.
    795      * Stored in format. BS[15] | BS[14] | .. |BS[0]
    796      */
    797     UWORD32 *pu4_pic_horz_bs;
    798 
    799     /**
    800      *  Qp array stored for each mb
    801      */
    802     UWORD8  *pu1_pic_qp;
    803 
    804 }bs_ctxt_t;
    805 
    806 typedef struct
    807 {
    808     /**
    809      * MB's x position within a picture in raster scan in MB units
    810      */
    811     WORD32 i4_mb_x;
    812 
    813     /**
    814      * MB's y position within a picture in raster scan in MB units
    815      */
    816     WORD32 i4_mb_y;
    817 
    818     /**
    819      * structure that contains BS and QP frame level arrays
    820      */
    821     bs_ctxt_t s_bs_ctxt;
    822 
    823     /**
    824      * Pointer to 0th luma pixel in current pic
    825      */
    826     UWORD8 *pu1_cur_pic_luma;
    827 
    828     /**
    829      * Pointer to 0th chroma pixel in current pic
    830      */
    831     UWORD8 *pu1_cur_pic_chroma;
    832 
    833     /**
    834      *  Points to the array of slice indices which is used to identify the slice
    835      *  to which each MB in a frame belongs.
    836      */
    837     UWORD8 *pu1_slice_idx;
    838 
    839 }deblk_ctxt_t;
    840 
    841 
    842 /**
    843  ******************************************************************************
    844  *  @brief      Structure to hold data and flags for 'n' mb processing for
    845  *                deblocking , padding and half pel generation.
    846  ******************************************************************************
    847  */
    848 typedef struct
    849 {
    850     /**
    851      * MB's x position last processed + 1
    852      */
    853     WORD32 i4_mb_x;
    854 
    855     /**
    856      * MB's y position ,current processing.
    857      */
    858     WORD32 i4_mb_y;
    859 
    860     /**
    861      * Number of MBs processed in a stretch
    862      */
    863     WORD32 i4_n_mbs;
    864 
    865 }n_mb_process_ctxt_t;
    866 
    867 
    868 /**
    869 ******************************************************************************
    870  *  @brief      Structure to hold coefficient info for a 4x4 subblock.
    871  *  The following can be used to type-cast coefficient data that is stored
    872  *  per subblock. Note that though i2_level is shown as an array that
    873  *  holds 16 coefficients, only the first few entries will be valid. Next
    874  *  subblocks data starts after the valid number of coefficients. Number
    875  *  of non-zero coefficients will be derived using number of non-zero bits
    876  *  in sig coeff map
    877 ******************************************************************************
    878  */
    879 typedef struct
    880 {
    881     /**
    882      * significant coefficient map and nnz are packed in
    883      * to msb (2 bytes) and lsb (2 bytes) respectively
    884      */
    885     WORD32  i4_sig_map_nnz;
    886 
    887     /**
    888      * array of non zero residue coefficients
    889      */
    890     WORD16  ai2_residue[16];
    891 
    892 }tu_sblk_coeff_data_t;
    893 
    894 /**
    895 ******************************************************************************
    896  *  @brief      Structure contains few common state variables such as MB indices,
    897  *  current SPS, PPS etc which are to be used in the entropy thread. By keeping
    898  *  it a different structure it is being explicitly signaled that these
    899  * variables are specific to entropy threads context and other threads should
    900  * not update these elements
    901 ******************************************************************************
    902  */
    903 typedef struct
    904 {
    905     /**
    906      * Pointer to the cabac context
    907      */
    908     cabac_ctxt_t *ps_cabac;
    909 
    910     /**
    911      * start of frame / start of slice flag
    912      */
    913     WORD32 i4_sof;
    914 
    915     /**
    916      * end of frame / end of slice flag
    917      */
    918     WORD32 i4_eof;
    919 
    920     /**
    921      * generate header upon request
    922      */
    923     WORD32 i4_gen_header;
    924 
    925     /**
    926      *  seq_parameter_set_id
    927      */
    928     UWORD32 u4_sps_id;
    929 
    930     /**
    931      * Pointer to base of sequence parameter set structure array
    932      */
    933     sps_t *ps_sps_base;
    934 
    935     /**
    936      *  pic_parameter_set_id
    937      */
    938     UWORD32 u4_pps_id;
    939 
    940     /**
    941      * Pointer to base of Picture parameter set structure array
    942      */
    943     pps_t *ps_pps_base;
    944 
    945     /**
    946      * Current slice idx
    947      */
    948     WORD32 i4_cur_slice_idx;
    949 
    950     /**
    951      * Points to the array of slice indices which is used to identify the independent slice
    952      * to which each MB in a frame belongs.
    953      */
    954     UWORD8 *pu1_slice_idx;
    955 
    956     /**
    957      * Pointer to base of slice header structure array
    958      */
    959     slice_header_t *ps_slice_hdr_base;
    960 
    961     /**
    962      * entropy status
    963      */
    964     UWORD8  *pu1_entropy_map;
    965 
    966     /**
    967      * MB's x position within a picture in raster scan in MB units
    968      */
    969     WORD32 i4_mb_x;
    970 
    971     /**
    972      * MB's y position within a picture in raster scan in MB units
    973      */
    974     WORD32 i4_mb_y;
    975 
    976     /**
    977      * MB start address
    978      */
    979     WORD32 i4_mb_cnt;
    980 
    981     /**
    982      * MB start address
    983      */
    984     WORD32 i4_mb_start_add;
    985 
    986     /**
    987      * MB end address
    988      */
    989     WORD32 i4_mb_end_add;
    990 
    991     /**
    992      * Input width in mbs
    993      */
    994     WORD32 i4_wd_mbs;
    995 
    996     /**
    997      * Input height in mbs
    998      */
    999     WORD32 i4_ht_mbs;
   1000 
   1001     /**
   1002      * Bitstream structure
   1003      */
   1004     bitstrm_t *ps_bitstrm;
   1005 
   1006     /**
   1007      *  transform_8x8_mode_flag
   1008      */
   1009     WORD8 i1_transform_8x8_mode_flag;
   1010 
   1011     /**
   1012      *  entropy_coding_mode_flag
   1013      */
   1014     WORD8 u1_entropy_coding_mode_flag;
   1015 
   1016     /**
   1017      * Pointer to the top row nnz for luma
   1018      */
   1019     UWORD8 (*pu1_top_nnz_luma)[4];
   1020 
   1021     /**
   1022      * left nnz for luma
   1023      */
   1024     UWORD32 u4_left_nnz_luma;
   1025 
   1026     /**
   1027      * Pointer to zero runs before for the mb
   1028      */
   1029     UWORD8  au1_zero_run[16];
   1030 
   1031     /**
   1032      * Pointer to the top row nnz for chroma
   1033      */
   1034     UWORD8 (*pu1_top_nnz_cbcr)[4];
   1035 
   1036     /**
   1037      * left nnz for chroma
   1038      */
   1039     UWORD8 u4_left_nnz_cbcr;
   1040 
   1041     /**
   1042      * Pointer frame level mb subblock coeff data
   1043      */
   1044     void *pv_pic_mb_coeff_data;
   1045 
   1046     /**
   1047      * Pointer to mb subblock coeff data and number of subblocks and scan idx
   1048      * Incremented each time a coded subblock is processed
   1049      */
   1050     void *pv_mb_coeff_data;
   1051 
   1052     /**
   1053      * Pointer frame level mb header data
   1054      */
   1055     void *pv_pic_mb_header_data;
   1056 
   1057     /**
   1058      * Pointer to mb header data and
   1059      * incremented each time a coded mb is encoded
   1060      */
   1061     void *pv_mb_header_data;
   1062 
   1063     /**
   1064      * Error code during parse stage
   1065      */
   1066     IH264E_ERROR_T i4_error_code;
   1067 
   1068     /**
   1069      * Void pointer to job context
   1070      */
   1071     void *pv_proc_jobq, *pv_entropy_jobq;
   1072 
   1073     /**
   1074      * Flag to signal end of frame
   1075      */
   1076     WORD32 i4_end_of_frame;
   1077 
   1078     /**
   1079      * Abs POC count of the frame
   1080      */
   1081      WORD32 i4_abs_pic_order_cnt;
   1082 
   1083      /**
   1084       * mb skip run
   1085       */
   1086      WORD32 *pi4_mb_skip_run;
   1087 
   1088      /**
   1089       * Flag to signal end of sequence
   1090       */
   1091      UWORD32 u4_is_last;
   1092 
   1093      /**
   1094       * Lower 32bits of time-stamp corresponding to the buffer being encoded
   1095       */
   1096      UWORD32 u4_timestamp_low;
   1097 
   1098      /**
   1099       * Upper 32bits of time-stamp corresponding to the buffer being encoded
   1100       */
   1101      UWORD32 u4_timestamp_high;
   1102 
   1103      /**
   1104       * Current Picture count - used for synchronization
   1105       */
   1106      WORD32  i4_pic_cnt;
   1107 
   1108      /**
   1109       * Number of bits consumed by header for I and P mb types
   1110       */
   1111      UWORD32 u4_header_bits[MAX_MB_TYPE];
   1112 
   1113      /**
   1114       * Number of bits consumed by residue for I and P mb types
   1115       */
   1116      UWORD32 u4_residue_bits[MAX_MB_TYPE];
   1117 
   1118 } entropy_ctxt_t;
   1119 
   1120 /**
   1121 ******************************************************************************
   1122 *  @brief      macro block info.
   1123 ******************************************************************************
   1124 */
   1125 typedef struct
   1126 {
   1127     /**
   1128      * mb type
   1129      */
   1130     UWORD16 u2_is_intra;
   1131 
   1132     /**
   1133      * mb type
   1134      */
   1135     UWORD16 u2_mb_type;
   1136 
   1137     /**
   1138      * csbp
   1139      */
   1140     UWORD32 u4_csbp;
   1141 
   1142     /**
   1143      * mb distortion
   1144      */
   1145     WORD32 i4_mb_distortion;
   1146 
   1147 }mb_info_t;
   1148 
   1149 /**
   1150 ******************************************************************************
   1151 *  @brief      structure presenting the neighbor availability of a mb
   1152 *  or subblk or any other partition
   1153 ******************************************************************************
   1154 */
   1155 typedef struct
   1156 {
   1157     /**
   1158      * left blk/subblk/partition
   1159      */
   1160     UWORD8 u1_mb_a;
   1161 
   1162     /**
   1163      * top blk/subblk/partition
   1164      */
   1165     UWORD8 u1_mb_b;
   1166 
   1167     /**
   1168      * topright blk/subblk/partition
   1169      */
   1170     UWORD8 u1_mb_c;
   1171 
   1172     /**
   1173      * topleft blk/subblk/partition
   1174      */
   1175     UWORD8 u1_mb_d;
   1176 
   1177 }block_neighbors_t;
   1178 
   1179 /**
   1180  ******************************************************************************
   1181  *  @brief      MB info  related variables used during NMB processing
   1182  ******************************************************************************
   1183  */
   1184 typedef struct
   1185 {
   1186     UWORD32 u4_mb_type;
   1187     UWORD32 u4_min_sad;
   1188     UWORD32 u4_min_sad_reached;
   1189     WORD32  i4_mb_cost;
   1190     WORD32  i4_mb_distortion;
   1191 
   1192     enc_pu_mv_t as_skip_mv[4];
   1193 
   1194     enc_pu_mv_t as_pred_mv[2];
   1195 
   1196     block_neighbors_t s_ngbr_avbl;
   1197 
   1198     /*
   1199      * Buffer to hold best subpel buffer in each MB of NMB
   1200      */
   1201     UWORD8 *pu1_best_sub_pel_buf;
   1202 
   1203     /*
   1204      * Stride for subpel buffer
   1205      */
   1206     UWORD32 u4_bst_spel_buf_strd;
   1207 
   1208 }mb_info_nmb_t;
   1209 
   1210 /**
   1211  ******************************************************************************
   1212  *  @brief      Pixel processing thread context
   1213  ******************************************************************************
   1214  */
   1215 struct _proc_t
   1216 {
   1217     /**
   1218      * entropy context
   1219      */
   1220     entropy_ctxt_t s_entropy;
   1221 
   1222     /**
   1223      * me context
   1224      */
   1225     me_ctxt_t s_me_ctxt;
   1226 
   1227     /**
   1228      * Pointer to codec context
   1229      */
   1230     codec_t *ps_codec;
   1231 
   1232     /**
   1233      * N mb process contest
   1234      */
   1235     n_mb_process_ctxt_t s_n_mb_ctxt;
   1236 
   1237     /**
   1238      * Source pointer to current MB luma
   1239      */
   1240     UWORD8 *pu1_src_buf_luma;
   1241 
   1242     /**
   1243      * Source pointer to current MB chroma
   1244      */
   1245     UWORD8 *pu1_src_buf_chroma;
   1246 
   1247     /**
   1248      * Recon pointer to current MB luma
   1249      */
   1250     UWORD8 *pu1_rec_buf_luma;
   1251 
   1252     /**
   1253      * Recon pointer to current MB chroma
   1254      */
   1255     UWORD8 *pu1_rec_buf_chroma;
   1256 
   1257     /**
   1258      * Ref pointer to current MB luma
   1259      */
   1260     UWORD8 *apu1_ref_buf_luma[MAX_REF_PIC_CNT];
   1261 
   1262     /**
   1263      * Ref pointer to current MB chroma
   1264      */
   1265     UWORD8 *apu1_ref_buf_chroma[MAX_REF_PIC_CNT];
   1266 
   1267     /**
   1268      * pointer to luma plane of input buffer (base :: mb (0,0))
   1269      */
   1270     UWORD8 *pu1_src_buf_luma_base;
   1271 
   1272     /**
   1273      * pointer to luma plane of reconstructed buffer (base :: mb (0,0))
   1274      */
   1275     UWORD8 *pu1_rec_buf_luma_base;
   1276 
   1277     /**
   1278      * pointer to luma plane of ref buffer (base :: mb (0,0))
   1279      */
   1280     UWORD8 *apu1_ref_buf_luma_base[MAX_REF_PIC_CNT];
   1281 
   1282     /**
   1283      * pointer to  chroma plane of input buffer (base :: mb (0,0))
   1284      */
   1285     UWORD8 *pu1_src_buf_chroma_base;
   1286 
   1287     /*
   1288      * Buffer for color space conversion of luma
   1289      */
   1290     UWORD8 *pu1_y_csc_buf;
   1291 
   1292     /*
   1293      * Buffer for color space conversion of luma
   1294      */
   1295 
   1296     UWORD8 *pu1_uv_csc_buf;
   1297 
   1298     /**
   1299      * pointer to  chroma plane of reconstructed buffer (base :: mb (0,0))
   1300      */
   1301     UWORD8 *pu1_rec_buf_chroma_base;
   1302 
   1303     /**
   1304      * pointer to  chroma plane of reconstructed buffer (base :: mb (0,0))
   1305      */
   1306     UWORD8 *apu1_ref_buf_chroma_base[MAX_REF_PIC_CNT];
   1307 
   1308     /**
   1309      * Pointer to ME NMB info
   1310      */
   1311     mb_info_nmb_t *ps_nmb_info;
   1312 
   1313     mb_info_nmb_t *ps_cur_mb;
   1314 
   1315     /**
   1316      * source luma stride
   1317      */
   1318     WORD32 i4_src_strd;
   1319 
   1320     /**
   1321      * source chroma stride
   1322      */
   1323     WORD32 i4_src_chroma_strd;
   1324 
   1325     /**
   1326      * recon stride & ref stride
   1327      * (strides for luma and chroma are the same)
   1328      */
   1329     WORD32 i4_rec_strd;
   1330 
   1331     /**
   1332      * Offset for half pel x plane from the pic buf
   1333      */
   1334     UWORD32 u4_half_x_offset;
   1335 
   1336     /**
   1337      * Offset for half pel y plane from half x plane
   1338      */
   1339     UWORD32 u4_half_y_offset;
   1340 
   1341     /**
   1342      * Offset for half pel xy plane from half y plane
   1343      */
   1344     UWORD32 u4_half_xy_offset;
   1345 
   1346     /**
   1347      * pred buffer pointer (temp buffer 1)
   1348      */
   1349     UWORD8 *pu1_pred_mb;
   1350 
   1351     /**
   1352      * pred buffer pointer (prediction buffer for intra 16x16
   1353      */
   1354     UWORD8 *pu1_pred_mb_intra_16x16;
   1355 
   1356     /**
   1357      * pred buffer pointer (prediction buffer for intra 16x16_plane
   1358      */
   1359     UWORD8 *pu1_pred_mb_intra_16x16_plane;
   1360 
   1361     /**
   1362      * pred buffer pointer (prediction buffer for intra chroma
   1363      */
   1364     UWORD8 *pu1_pred_mb_intra_chroma;
   1365 
   1366     /**
   1367      * pred buffer pointer (prediction buffer for intra chroma plane
   1368      */
   1369     UWORD8 *pu1_pred_mb_intra_chroma_plane;
   1370 
   1371     /**
   1372      * temp. reference buffer ptr for intra 4x4 when rdopt is on
   1373      */
   1374     UWORD8 *pu1_ref_mb_intra_4x4;
   1375 
   1376     /**
   1377      * prediction buffer stride
   1378      */
   1379     WORD32 i4_pred_strd;
   1380 
   1381     /**
   1382      * transform buffer pointer (temp buffer 2)
   1383      */
   1384     WORD16 *pi2_res_buf;
   1385 
   1386     /**
   1387      * temp. transform buffer ptr for intra 4x4 when rdopt is on
   1388      */
   1389     WORD16 *pi2_res_buf_intra_4x4;
   1390 
   1391     /**
   1392      * transform buffer stride
   1393      */
   1394     WORD32 i4_res_strd;
   1395 
   1396     /**
   1397      * scratch buffer for inverse transform (temp buffer 3)
   1398      */
   1399     void *pv_scratch_buff;
   1400 
   1401     /**
   1402      * frame num
   1403      */
   1404     WORD32 i4_frame_num;
   1405 
   1406     /**
   1407      * start address of frame / sub-frame
   1408      */
   1409     WORD32 i4_frame_strt_add;
   1410 
   1411     /**
   1412      *  IDR pic
   1413      */
   1414     UWORD32 u4_is_idr;
   1415 
   1416     /**
   1417      *  idr_pic_id
   1418      */
   1419     UWORD32 u4_idr_pic_id;
   1420 
   1421     /**
   1422      * Input width in mbs
   1423      */
   1424     WORD32 i4_wd_mbs;
   1425 
   1426     /**
   1427      * Input height in mbs
   1428      */
   1429     WORD32 i4_ht_mbs;
   1430 
   1431     /**
   1432      *  slice_type
   1433      */
   1434     WORD32  i4_slice_type;
   1435 
   1436     /**
   1437      * Current slice idx
   1438      */
   1439     WORD32 i4_cur_slice_idx;
   1440 
   1441     /**
   1442      * MB's x position within a picture in raster scan in MB units
   1443      */
   1444     WORD32 i4_mb_x;
   1445 
   1446     /**
   1447      * MB's y position within a picture in raster scan in MB units
   1448      */
   1449     WORD32 i4_mb_y;
   1450 
   1451     /**
   1452      * MB's x position within a Slice in raster scan in MB units
   1453      */
   1454     WORD32 i4_mb_slice_x;
   1455 
   1456     /**
   1457      * MB's y position within a Slice in raster scan in MB units
   1458      */
   1459     WORD32 i4_mb_slice_y;
   1460 
   1461     /**
   1462      *  mb type
   1463      */
   1464     UWORD32 u4_mb_type;
   1465 
   1466     /**
   1467      *  is intra
   1468      */
   1469     UWORD32 u4_is_intra;
   1470 
   1471     /**
   1472      * mb neighbor availability pointer
   1473      */
   1474     block_neighbors_t *ps_ngbr_avbl;
   1475 
   1476     /**
   1477      * lambda (lagrange multiplier for cost computation)
   1478      */
   1479     UWORD32 u4_lambda;
   1480 
   1481     /**
   1482      * mb distortion
   1483      */
   1484     WORD32 i4_mb_distortion;
   1485 
   1486     /**
   1487      * mb cost
   1488      */
   1489     WORD32 i4_mb_cost;
   1490 
   1491     /********************************************************************/
   1492     /* i4_ngbr_avbl_mb_16 - ngbr avbl of curr mb                        */
   1493     /* i4_ngbr_avbl_sb_8 - ngbr avbl of all 8x8 sub blocks of curr mb   */
   1494     /* i4_ngbr_avbl_sb_4 - ngbr avbl of all 4x4 sub blocks of curr mb   */
   1495     /* i4_ngbr_avbl_mb_c - chroma ngbr avbl of curr mb                  */
   1496     /********************************************************************/
   1497     WORD32  i4_ngbr_avbl_16x16_mb;
   1498     WORD32  ai4_neighbor_avail_8x8_subblks[4];
   1499     UWORD8  au1_ngbr_avbl_4x4_subblks[16];
   1500     WORD32  i4_chroma_neighbor_avail_8x8_mb;
   1501 
   1502     /**
   1503      * array to store the mode of mb sub blocks
   1504      */
   1505     UWORD8  au1_intra_luma_mb_4x4_modes[16];
   1506 
   1507     /**
   1508      * array to store the predicted mode of mb sub blks
   1509      */
   1510     UWORD8  au1_predicted_intra_luma_mb_4x4_modes[16];
   1511 
   1512     /**
   1513      * macro block intra 16x16 mode
   1514      */
   1515     UWORD8  u1_l_i16_mode;
   1516 
   1517     /**
   1518      * array to store the mode of the macro block intra 8x8 4 modes
   1519      */
   1520     UWORD8  au1_intra_luma_mb_8x8_modes[4];
   1521 
   1522     /**
   1523      * intra chroma mb mode
   1524      */
   1525     UWORD8  u1_c_i8_mode;
   1526 
   1527     /********************************************************************/
   1528     /* array to store pixels from the neighborhood for intra prediction */
   1529     /* i16 - 16 left pels + 1 top left pel + 16 top pels = 33 pels      */
   1530     /* i8 - 8 lpels + 1 tlpels + 8 tpels + 8 tr pels = 25 pels          */
   1531     /* i4 - 4 lpels + 1 tlpels + 4 tpels + 4 tr pels = 13 pels          */
   1532     /* ic - 8 left pels + 1 top left pel + 8 top pels )*2               */
   1533     /********************************************************************/
   1534     UWORD8 au1_ngbr_pels[34];
   1535 
   1536     /**
   1537      * array for 8x8 intra pels filtering (temp buff 4)
   1538      */
   1539     UWORD8 au1_neighbor_pels_i8x8_unfiltered[25];
   1540 
   1541     /**
   1542      * Number of sub partitons in the inter pred MB
   1543      */
   1544     UWORD32 u4_num_sub_partitions;
   1545 
   1546     /**
   1547      *  Pointer to hold num PUs each MB in a picture
   1548      */
   1549     UWORD32 *pu4_mb_pu_cnt;
   1550 
   1551     /**
   1552      * Pointer to the array of structures having motion vectors, size
   1553      *  and position of sub partitions
   1554      */
   1555     enc_pu_t *ps_pu;
   1556 
   1557     /**
   1558      * Pointer to the pu of current co-located MB in list 1
   1559      */
   1560     enc_pu_t *ps_colpu;
   1561 
   1562     /**
   1563      * predicted motion vector
   1564      */
   1565     enc_pu_mv_t *ps_skip_mv;
   1566 
   1567     /**
   1568      * predicted motion vector
   1569      */
   1570     enc_pu_mv_t *ps_pred_mv;
   1571 
   1572     /**
   1573      * top row mb syntax information base
   1574      * In normal working scenarios, for a given context set,
   1575      * the mb syntax info pointer is identical across all process threads.
   1576      * But when the hard bound on slices are enabled, in multi core, frame
   1577      * is partitioned in to sections equal to set number of cores and each
   1578      * partition is run independently. In this scenario, a ctxt set will alone
   1579      * appear to run multiple frames at a time. For this to occur, the common
   1580      * pointers across the proc ctxt should disappear.
   1581      *
   1582      * This is done by allocating MAX_PROCESS_THREADS memory and distributing
   1583      * across individual ctxts when byte bnd per slice is enabled.
   1584      */
   1585     mb_info_t *ps_top_row_mb_syntax_ele_base;
   1586 
   1587     /**
   1588      * top row mb syntax information
   1589      */
   1590     mb_info_t *ps_top_row_mb_syntax_ele;
   1591 
   1592     /**
   1593      * left mb syntax information
   1594      */
   1595     mb_info_t s_left_mb_syntax_ele;
   1596 
   1597     /**
   1598      * top left mb syntax information
   1599      */
   1600     mb_info_t s_top_left_mb_syntax_ele;
   1601 
   1602     /**
   1603      * top left mb syntax information
   1604      */
   1605 
   1606     mb_info_t s_top_left_mb_syntax_ME;
   1607 
   1608     /**
   1609      * left mb motion vector
   1610      */
   1611     enc_pu_t s_left_mb_pu_ME;
   1612 
   1613     /**
   1614      * top left mb motion vector
   1615      */
   1616     enc_pu_t s_top_left_mb_pu_ME;
   1617 
   1618     /**
   1619      * mb neighbor availability pointer
   1620      */
   1621     block_neighbors_t s_ngbr_avbl;
   1622 
   1623     /**
   1624      * In case the macroblock type is intra, the intra modes of all
   1625      * partitions for the left mb are stored in the array below
   1626      */
   1627     UWORD8 au1_left_mb_intra_modes[16];
   1628 
   1629     /**
   1630      * In case the macroblock type is intra, the intra modes of all
   1631      * partitions for the top mb are stored in the array below
   1632      *
   1633      * In normal working scenarios, for a given context set,
   1634      * the mb syntax info pointer is identical across all process threads.
   1635      * But when the hard bound on slices are enabled, in multi core, frame
   1636      * is partitioned in to sections equal to set number of cores and each
   1637      * partition is run independently. In this scenario, a ctxt set will alone
   1638      * appear to run multiple frames at a time. For this to occur, the common
   1639      * pointers across the proc ctxt should disappear.
   1640      *
   1641      * This is done by allocating MAX_PROCESS_THREADS memory and distributing
   1642      * across individual ctxts when byte bnd per slice is enabled.
   1643      */
   1644     UWORD8 *pu1_top_mb_intra_modes_base;
   1645 
   1646     /**
   1647      * In case the macroblock type is intra, the intra modes of all
   1648      * partitions for the top mb are stored in the array below
   1649      */
   1650     UWORD8 *pu1_top_mb_intra_modes;
   1651 
   1652     /**
   1653      * left mb motion vector
   1654      */
   1655     enc_pu_t s_left_mb_pu;
   1656 
   1657     /**
   1658      * top left mb motion vector
   1659      */
   1660     enc_pu_t s_top_left_mb_pu;
   1661 
   1662     /**
   1663      * top row motion vector info
   1664      *
   1665      * In normal working scenarios, for a given context set,
   1666      * the top row pu pointer is identical across all process threads.
   1667      * But when the hard bound on slices are enabled, in multi core, frame
   1668      * is partitioned in to sections equal to set number of cores and each
   1669      * partition is run independently. In this scenario, a ctxt set will alone
   1670      * appear to run multiple frames at a time. For this to occur, the common
   1671      * pointers across the proc ctxt should disappear.
   1672      *
   1673      * This is done by allocating MAX_PROCESS_THREADS memory and distributing
   1674      * across individual ctxts when byte bnd per slice is enabled.
   1675      */
   1676     enc_pu_t *ps_top_row_pu_base;
   1677 
   1678     /**
   1679      * top row motion vector info
   1680      */
   1681     enc_pu_t *ps_top_row_pu;
   1682 
   1683     enc_pu_t *ps_top_row_pu_ME;
   1684 
   1685     /**
   1686      * coded block pattern
   1687      */
   1688     UWORD32 u4_cbp;
   1689 
   1690     /**
   1691      * csbp
   1692      */
   1693     UWORD32 u4_csbp;
   1694 
   1695     /**
   1696      *  number of non zero coeffs
   1697      */
   1698     UWORD32 au4_nnz[5];
   1699 
   1700     /**
   1701      *  number of non zero coeffs for intra 4x4 when rdopt is on
   1702      */
   1703     UWORD32 au4_nnz_intra_4x4[4];
   1704 
   1705     /**
   1706      * frame qp & mb qp
   1707      */
   1708     UWORD32 u4_frame_qp, u4_mb_qp;
   1709 
   1710     /**
   1711      * mb qp previous
   1712      */
   1713     UWORD32 u4_mb_qp_prev;
   1714 
   1715     /**
   1716      * quantization parameters for luma & chroma planes
   1717      */
   1718     quant_params_t *ps_qp_params[3];
   1719 
   1720     /**
   1721      * Pointer frame level mb subblock coeff data
   1722      */
   1723     void *pv_pic_mb_coeff_data;
   1724 
   1725     /**
   1726      * Pointer to mb subblock coeff data and number of subblocks and scan idx
   1727      * Incremented each time a coded subblock is processed
   1728      */
   1729     void *pv_mb_coeff_data;
   1730 
   1731     /**
   1732      * Pointer frame level mb header data
   1733      */
   1734     void *pv_pic_mb_header_data;
   1735 
   1736     /**
   1737      * Pointer to mb header data and
   1738      * incremented each time a coded mb is encoded
   1739      */
   1740     void *pv_mb_header_data;
   1741 
   1742     /**
   1743      * Signal that pic_init is called first time
   1744      */
   1745     WORD32 i4_first_pic_init;
   1746 
   1747     /**
   1748      * Current MV Bank's buffer ID
   1749      */
   1750     WORD32 i4_cur_mv_bank_buf_id;
   1751 
   1752     /**
   1753      * Void pointer to job context
   1754      */
   1755     void *pv_proc_jobq, *pv_entropy_jobq;
   1756 
   1757     /**
   1758      * Number of MBs to be processed in the current Job
   1759      */
   1760     WORD32 i4_mb_cnt;
   1761 
   1762     /**
   1763      * ID for the current context - Used for debugging
   1764      */
   1765     WORD32 i4_id;
   1766 
   1767     /**
   1768      * Pointer to current picture buffer structure
   1769      */
   1770     pic_buf_t *ps_cur_pic;
   1771 
   1772     /**
   1773      * Pointer to current picture's mv buffer structure
   1774      */
   1775     mv_buf_t *ps_cur_mv_buf;
   1776 
   1777     /**
   1778      * Flag to indicate if ps_proc was initialized at least once in a frame.
   1779      * This is needed to handle cases where a core starts to handle format
   1780      * conversion jobs directly
   1781      */
   1782     WORD32 i4_init_done;
   1783 
   1784     /**
   1785      * Process status: one byte per MB
   1786      */
   1787     UWORD8 *pu1_proc_map;
   1788 
   1789     /**
   1790      * Deblk status: one byte per MB
   1791      */
   1792     UWORD8 *pu1_deblk_map;
   1793 
   1794     /**
   1795      * Process status: one byte per MB
   1796      */
   1797     UWORD8 *pu1_me_map;
   1798 
   1799     /*
   1800      * Intra refresh mask.
   1801      * Indicates if an Mb is coded in intra mode within the current AIR interval
   1802      * NOTE Refreshes after each AIR period
   1803      * NOTE The map is shared between process
   1804      */
   1805     UWORD8 *pu1_is_intra_coded;
   1806 
   1807     /**
   1808      * Disable deblock level (0: Enable completely, 3: Disable completely
   1809      */
   1810     UWORD32 u4_disable_deblock_level;
   1811 
   1812     /**
   1813      * Pointer to the structure that contains deblock context
   1814      */
   1815     deblk_ctxt_t s_deblk_ctxt;
   1816 
   1817     /**
   1818      * Points to the array of slice indices which is used to identify the independent
   1819      * slice to which each MB in a frame belongs.
   1820      */
   1821     UWORD8 *pu1_slice_idx;
   1822 
   1823     /**
   1824      * Pointer to base of slice header structure array
   1825      */
   1826     slice_header_t *ps_slice_hdr_base;
   1827 
   1828     /**
   1829      * Number of mb's to process in one loop
   1830      */
   1831     WORD32 i4_nmb_ntrpy;
   1832 
   1833     /**
   1834      * Number of mb's to process in one loop
   1835      */
   1836     UWORD32 u4_nmb_me;
   1837 
   1838     /**
   1839      * Structure for current input buffer
   1840      */
   1841     inp_buf_t s_inp_buf;
   1842 
   1843     /**
   1844      * api call cnt
   1845      */
   1846     WORD32 i4_encode_api_call_cnt;
   1847 
   1848     /**
   1849      * Current Picture count - used for synchronization
   1850      */
   1851     WORD32 i4_pic_cnt;
   1852 
   1853     /**
   1854       * Intermediate buffer for interpred leaf level functions
   1855       */
   1856     WORD32 ai16_pred1[HP_BUFF_WD * HP_BUFF_HT];
   1857 
   1858     /**
   1859      * Reference picture for the current picture
   1860      * TODO: Only 2 reference assumed currently
   1861      */
   1862     pic_buf_t *aps_ref_pic[MAX_REF_PIC_CNT];
   1863 
   1864     /**
   1865      * Reference MV buff for the current picture
   1866      */
   1867     mv_buf_t *aps_mv_buf[MAX_REF_PIC_CNT];
   1868 
   1869     /**
   1870      * frame info used by RC
   1871      */
   1872     frame_info_t s_frame_info;
   1873 
   1874     /*
   1875      * NOTE NOT PERSISTANT INSIDE FUNCTIONS
   1876      * Min sad for current MB
   1877      * will be populated initially
   1878      * Once a sad less than eq to u4_min_sad is reached, the value will be copied to the cariable
   1879      */
   1880     UWORD32  u4_min_sad;
   1881 
   1882     /*
   1883      * indicates weather we have rached minimum sa or not
   1884      */
   1885     UWORD32 u4_min_sad_reached;
   1886 
   1887     /**
   1888      * Current error code
   1889      */
   1890     WORD32 i4_error_code;
   1891 
   1892     /*
   1893      * Enables or disables computation of recon
   1894      */
   1895     UWORD32 u4_compute_recon;
   1896 
   1897     /*
   1898      * Temporary buffers to be used for subpel computation
   1899      */
   1900     UWORD8 *apu1_subpel_buffs[SUBPEL_BUFF_CNT];
   1901 
   1902     /*
   1903      * Buffer holding best sub pel values
   1904      */
   1905     UWORD8 *pu1_best_subpel_buf;
   1906 
   1907     /*
   1908      * Stride for buffer holding best sub pel
   1909      */
   1910     UWORD32 u4_bst_spel_buf_strd;
   1911 
   1912 };
   1913 
   1914 /**
   1915  ******************************************************************************
   1916  *  @brief      Rate control related variables
   1917  ******************************************************************************
   1918  */
   1919 typedef struct
   1920 {
   1921     void *pps_rate_control_api;
   1922 
   1923     void *pps_frame_time;
   1924 
   1925     void *pps_time_stamp;
   1926 
   1927     void *pps_pd_frm_rate;
   1928 
   1929     /**
   1930      * frame rate pull down
   1931      */
   1932     WORD32 pre_encode_skip[MAX_CTXT_SETS];
   1933 
   1934     /**
   1935      * skip frame (cbr)
   1936      */
   1937     WORD32 post_encode_skip[MAX_CTXT_SETS];
   1938 
   1939     /**
   1940      * rate control type
   1941      */
   1942     rc_type_e e_rc_type;
   1943 
   1944     /**
   1945      * pic type
   1946      */
   1947     picture_type_e e_pic_type;
   1948 
   1949     /**
   1950      * intra cnt in previous frame
   1951      */
   1952     WORD32 num_intra_in_prev_frame;
   1953 
   1954     /**
   1955      * avg activity of prev frame
   1956      */
   1957     WORD32 i4_avg_activity;
   1958 
   1959 }rate_control_ctxt_t;
   1960 
   1961 /**
   1962  * Codec context
   1963  */
   1964 struct _codec_t
   1965 {
   1966     /**
   1967      * Id of current pic (input order)
   1968      */
   1969     WORD32 i4_poc;
   1970 
   1971     /**
   1972      * Number of encode frame API calls made
   1973      * This variable must only be used for context selection [Read only]
   1974      */
   1975     WORD32 i4_encode_api_call_cnt;
   1976 
   1977     /**
   1978      * Number of pictures encoded
   1979      */
   1980     WORD32 i4_pic_cnt;
   1981 
   1982     /**
   1983      * Number of threads created
   1984      */
   1985     WORD32 i4_proc_thread_cnt;
   1986 
   1987     /**
   1988      * Mutex used to keep the control calls thread-safe
   1989      */
   1990     void *pv_ctl_mutex;
   1991 
   1992     /**
   1993      * Current active config parameters
   1994      */
   1995     cfg_params_t s_cfg;
   1996 
   1997     /**
   1998      * Array containing the config parameter sets
   1999      */
   2000     cfg_params_t as_cfg[MAX_ACTIVE_CONFIG_PARAMS];
   2001 
   2002     /**
   2003      * Color format used by encoder internally
   2004      */
   2005     IV_COLOR_FORMAT_T e_codec_color_format;
   2006 
   2007     /**
   2008      * recon stride
   2009      * (strides for luma and chroma are the same)
   2010      */
   2011     WORD32 i4_rec_strd;
   2012 
   2013     /**
   2014      * Flag to enable/disable deblocking of a frame
   2015      */
   2016     WORD32 i4_disable_deblk_pic;
   2017 
   2018     /**
   2019      * Number of continuous frames where deblocking was disabled
   2020      */
   2021     WORD32 i4_disable_deblk_pic_cnt;
   2022 
   2023     /**
   2024      * frame type
   2025      */
   2026     PIC_TYPE_T pic_type;
   2027 
   2028     /**
   2029      * frame qp
   2030      */
   2031     UWORD32 u4_frame_qp;
   2032 
   2033     /**
   2034      * frame num
   2035      */
   2036     WORD32 i4_frame_num;
   2037 
   2038     /**
   2039      *  slice_type
   2040      */
   2041     WORD32  i4_slice_type;
   2042 
   2043     /*
   2044      * Force current frame to specific type
   2045      */
   2046     IV_PICTURE_CODING_TYPE_T force_curr_frame_type;
   2047 
   2048     /**
   2049      *  IDR pic
   2050      */
   2051     UWORD32 u4_is_idr;
   2052 
   2053     /**
   2054      *  idr_pic_id
   2055      */
   2056     WORD32 i4_idr_pic_id;
   2057 
   2058     /**
   2059      * Flush mode
   2060      */
   2061     WORD32 i4_flush_mode;
   2062 
   2063     /**
   2064      * Encode header mode
   2065      */
   2066     WORD32 i4_header_mode;
   2067 
   2068     /**
   2069      * Flag to indicate if header has already
   2070      * been generated when i4_api_call_cnt 0
   2071      */
   2072     UWORD32 u4_header_generated;
   2073 
   2074     /**
   2075      * Encode generate header
   2076      */
   2077     WORD32 i4_gen_header;
   2078 
   2079     /**
   2080      * To signal successful completion of init
   2081      */
   2082     WORD32 i4_init_done;
   2083 
   2084     /**
   2085      * To signal that at least one picture was decoded
   2086      */
   2087     WORD32 i4_first_pic_done;
   2088 
   2089     /**
   2090      * Reset flag - Codec is reset if this flag is set
   2091      */
   2092     WORD32 i4_reset_flag;
   2093 
   2094     /**
   2095      * Current error code
   2096      */
   2097     WORD32 i4_error_code;
   2098 
   2099     /**
   2100      * threshold residue
   2101      */
   2102     WORD32 u4_thres_resi;
   2103 
   2104     /**
   2105      * disable intra inter gating
   2106      */
   2107     UWORD32 u4_inter_gate;
   2108 
   2109     /**
   2110      * Holds mem records passed during init.
   2111      * This will be used to return the mem records during retrieve call
   2112      */
   2113     iv_mem_rec_t *ps_mem_rec_backup;
   2114 
   2115     /**
   2116      * Flag to determine if the entropy thread is active
   2117      */
   2118     volatile UWORD32 au4_entropy_thread_active[MAX_CTXT_SETS];
   2119 
   2120     /**
   2121      * Mutex used to keep the entropy calls thread-safe
   2122      */
   2123     void *pv_entropy_mutex;
   2124 
   2125     /**
   2126      * Job queue buffer base
   2127      */
   2128     void *pv_proc_jobq_buf, *pv_entropy_jobq_buf;
   2129 
   2130     /**
   2131      * Job Queue mem tab size
   2132      */
   2133     WORD32 i4_proc_jobq_buf_size, i4_entropy_jobq_buf_size;
   2134 
   2135     /**
   2136      * Memory for MV Bank buffer manager
   2137      */
   2138     void *pv_mv_buf_mgr_base;
   2139 
   2140     /**
   2141      * MV Bank buffer manager
   2142      */
   2143     void *pv_mv_buf_mgr;
   2144 
   2145     /**
   2146      * Pointer to MV Buf structure array
   2147      */
   2148     void *ps_mv_buf;
   2149 
   2150     /**
   2151      * Base address for Motion Vector bank buffer
   2152      */
   2153     void *pv_mv_bank_buf_base;
   2154 
   2155     /**
   2156      * MV Bank size allocated
   2157      */
   2158     WORD32 i4_total_mv_bank_size;
   2159 
   2160     /**
   2161      * Memory for Picture buffer manager for reference pictures
   2162      */
   2163     void *pv_ref_buf_mgr_base;
   2164 
   2165     /**
   2166      * Picture buffer manager for reference pictures
   2167      */
   2168     void *pv_ref_buf_mgr;
   2169 
   2170     /**
   2171      * Number of reference buffers added to the buffer manager
   2172      */
   2173     WORD32 i4_ref_buf_cnt;
   2174 
   2175     /**
   2176      * Pointer to Pic Buf structure array
   2177      */
   2178     void *ps_pic_buf;
   2179 
   2180     /**
   2181      * Base address for Picture buffer
   2182      */
   2183     void *pv_pic_buf_base;
   2184 
   2185     /**
   2186      * Total pic buffer size allocated
   2187      */
   2188     WORD32 i4_total_pic_buf_size;
   2189 
   2190     /**
   2191      * Memory for Buffer manager for output buffers
   2192      */
   2193      void *pv_out_buf_mgr_base;
   2194 
   2195     /**
   2196      * Buffer manager for output buffers
   2197      */
   2198      void *pv_out_buf_mgr;
   2199 
   2200     /**
   2201      * Current output buffer's buffer ID
   2202      */
   2203     WORD32 i4_out_buf_id;
   2204 
   2205     /**
   2206      * Number of output buffers added to the buffer manager
   2207      */
   2208     WORD32 i4_out_buf_cnt;
   2209 
   2210     /**
   2211      * Memory for Picture buffer manager for input buffers
   2212      */
   2213      void *pv_inp_buf_mgr_base;
   2214 
   2215     /**
   2216      * Picture buffer manager for input buffers
   2217      */
   2218      void *pv_inp_buf_mgr;
   2219 
   2220     /**
   2221      * Current input buffer's buffer ID
   2222      */
   2223     WORD32 i4_inp_buf_id;
   2224 
   2225     /**
   2226      * Number of input buffers added to the buffer manager
   2227      */
   2228     WORD32 i4_inp_buf_cnt;
   2229 
   2230     /**
   2231      * Current input buffer
   2232      */
   2233     pic_buf_t *ps_inp_buf;
   2234 
   2235     /**
   2236      * Pointer to dpb manager structure
   2237      */
   2238     void *pv_dpb_mgr;
   2239 
   2240     /**
   2241      * Pointer to base of Sequence parameter set structure array
   2242      */
   2243     sps_t *ps_sps_base;
   2244 
   2245     /**
   2246      * Pointer to base of Picture parameter set structure array
   2247      */
   2248     pps_t *ps_pps_base;
   2249 
   2250     /**
   2251      *  seq_parameter_set_id
   2252      */
   2253     WORD32 i4_sps_id;
   2254 
   2255     /**
   2256      *  pic_parameter_set_id
   2257      */
   2258     WORD32 i4_pps_id;
   2259 
   2260     /**
   2261      * Pointer to base of slice header structure array
   2262      */
   2263     slice_header_t *ps_slice_hdr_base;
   2264 
   2265     /**
   2266      * packed residue coeff data size for 1 row of mbs
   2267      */
   2268     UWORD32 u4_size_coeff_data;
   2269 
   2270     /**
   2271      * packed header data size for 1 row of mbs
   2272      */
   2273     UWORD32 u4_size_header_data;
   2274 
   2275     /**
   2276      * Processing context - One for each processing thread
   2277      * Create two sets, each set used for alternate frames
   2278      */
   2279     process_ctxt_t as_process[MAX_PROCESS_CTXT];
   2280 
   2281     /**
   2282      * Thread handle for each of the processing threads
   2283      */
   2284     void *apv_proc_thread_handle[MAX_PROCESS_THREADS];
   2285 
   2286     /**
   2287      * Thread created flag for each of the processing threads
   2288      */
   2289     WORD32 ai4_process_thread_created[MAX_PROCESS_THREADS];
   2290 
   2291     /**
   2292      * Void pointer to process job context
   2293      */
   2294     void *pv_proc_jobq, *pv_entropy_jobq;
   2295 
   2296     /**
   2297      * Number of MBs processed together for better instruction cache handling
   2298      */
   2299     WORD32 i4_proc_nmb;
   2300 
   2301     /**
   2302      * Previous POC lsb
   2303      */
   2304     WORD32 i4_prev_poc_lsb;
   2305 
   2306     /**
   2307      * Previous POC msb
   2308      */
   2309     WORD32 i4_prev_poc_msb;
   2310 
   2311     /**
   2312      * Max POC lsb that has arrived till now
   2313      */
   2314     WORD32 i4_max_prev_poc_lsb;
   2315 
   2316     /**
   2317      * Context for format conversion
   2318      */
   2319     fmt_conv_t s_fmt_conv;
   2320 
   2321     /**
   2322      * Absolute pic order count
   2323      */
   2324     WORD32 i4_abs_pic_order_cnt;
   2325 
   2326     /**
   2327      *  Pic order count of lsb
   2328      */
   2329     WORD32 i4_pic_order_cnt_lsb;
   2330 
   2331     /**
   2332      * Array giving current picture being processed in each context set
   2333      */
   2334     WORD32 ai4_pic_cnt[MAX_CTXT_SETS];
   2335 
   2336     /*
   2337      * Min sad to search for
   2338      */
   2339     UWORD32 u4_min_sad;
   2340 
   2341     /**
   2342      * Reference picture set
   2343      */
   2344     ref_set_t as_ref_set[MAX_DPB_SIZE + MAX_CTXT_SETS];
   2345 
   2346 
   2347     /*
   2348      * Air pic cnt
   2349      * Contains the number of pictures that have been encoded with air
   2350      * This value is moudulo air refresh period
   2351      */
   2352     WORD32 i4_air_pic_cnt;
   2353 
   2354     /*
   2355      * Intra refresh map
   2356      * Stores the frames at which intra refresh should occur for a MB
   2357      */
   2358     UWORD16 *pu2_intr_rfrsh_map;
   2359 
   2360     /*
   2361      * Indicates if the current frame is used as a reference frame
   2362      */
   2363     UWORD32 u4_is_curr_frm_ref;
   2364 
   2365     /*
   2366      * Indicates if there can be non reference frames in the stream
   2367      */
   2368     WORD32 i4_non_ref_frames_in_stream;
   2369 
   2370     /*
   2371      * Memory for color space conversion for luma plane
   2372      */
   2373     UWORD8 *pu1_y_csc_buf_base;
   2374 
   2375     /*
   2376      * Memory for color space conversion foe chroma plane
   2377      */
   2378     UWORD8 *pu1_uv_csc_buf_base;
   2379 
   2380     /**
   2381      * Function pointers for intra pred leaf level functions luma
   2382      */
   2383     pf_intra_pred apf_intra_pred_16_l[MAX_I16x16];
   2384     pf_intra_pred apf_intra_pred_8_l[MAX_I8x8];
   2385     pf_intra_pred apf_intra_pred_4_l[MAX_I4x4];
   2386 
   2387     /**
   2388      * Function pointers for intra pred leaf level functions chroma
   2389      */
   2390     pf_intra_pred apf_intra_pred_c[MAX_CH_I8x8];
   2391 
   2392     /**
   2393      * luma core coding function pointer
   2394      */
   2395     UWORD8 (*luma_energy_compaction[4])(process_ctxt_t *ps_proc);
   2396 
   2397     /**
   2398      * chroma core coding function pointer
   2399      */
   2400     UWORD8 (*chroma_energy_compaction[2])(process_ctxt_t *ps_proc);
   2401 
   2402     /**
   2403      * forward transform for intra blk of mb type 16x16
   2404      */
   2405     ih264_luma_16x16_resi_trans_dctrans_quant_ft *pf_resi_trans_dctrans_quant_16x16;
   2406 
   2407     /**
   2408      * inverse transform for intra blk of mb type 16x16
   2409      */
   2410     ih264_luma_16x16_idctrans_iquant_itrans_recon_ft *pf_idctrans_iquant_itrans_recon_16x16;
   2411 
   2412     /**
   2413      * forward transform for 4x4 blk luma
   2414      */
   2415     ih264_resi_trans_quant_ft *pf_resi_trans_quant_4x4;
   2416 
   2417     /**
   2418      * forward transform for 4x4 blk luma
   2419      */
   2420     ih264_resi_trans_quant_ft *pf_resi_trans_quant_chroma_4x4;
   2421 
   2422     /*
   2423      * hadamard transform and quant for a 4x4 block
   2424      */
   2425     ih264_hadamard_quant_ft *pf_hadamard_quant_4x4;
   2426 
   2427     /*
   2428      *  hadamard transform and quant for a 4x4 block
   2429      */
   2430     ih264_hadamard_quant_ft *pf_hadamard_quant_2x2_uv;
   2431 
   2432     /**
   2433      * inverse transform for 4x4 blk
   2434      */
   2435     ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_4x4;
   2436 
   2437     /**
   2438      * inverse transform for chroma 4x4 blk
   2439      */
   2440     ih264_iquant_itrans_recon_chroma_ft *pf_iquant_itrans_recon_chroma_4x4;
   2441 
   2442     /**
   2443      * inverse transform for 4x4 blk with only single dc coeff
   2444      */
   2445     ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_4x4_dc;
   2446 
   2447     /**
   2448      * inverse transform for chroma 4x4 blk with only single dc coeff
   2449      */
   2450     ih264_iquant_itrans_recon_chroma_ft *pf_iquant_itrans_recon_chroma_4x4_dc;
   2451 
   2452     /*
   2453      * Inverse hadamard transform and iquant for a 4x4 block
   2454      */
   2455     ih264_ihadamard_scaling_ft *pf_ihadamard_scaling_4x4;
   2456 
   2457     /*
   2458      * Inverse hadamard transform and iquant for a 4x4 block
   2459      */
   2460     ih264_ihadamard_scaling_ft *pf_ihadamard_scaling_2x2_uv;
   2461 
   2462     /*
   2463      * Function for interleave copy*
   2464      */
   2465     ih264_interleave_copy_ft *pf_interleave_copy;
   2466 
   2467     /**
   2468      * forward transform for 8x8 blk
   2469      */
   2470     ih264_resi_trans_quant_ft *pf_resi_trans_quant_8x8;
   2471 
   2472     /**
   2473      * inverse transform for 8x8 blk
   2474      */
   2475     /**
   2476      * inverse transform for 4x4 blk
   2477      */
   2478     ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_8x8;
   2479 
   2480     /**
   2481      * forward transform for chroma MB
   2482      */
   2483     ih264_chroma_8x8_resi_trans_dctrans_quant_ft *pf_resi_trans_dctrans_quant_8x8_chroma;
   2484 
   2485     /**
   2486      * inverse transform for chroma MB
   2487      */
   2488     ih264_idctrans_iquant_itrans_recon_ft *pf_idctrans_iquant_itrans_recon_8x8_chroma;
   2489 
   2490     /**
   2491      * deblock vertical luma edge with blocking strength 4
   2492      */
   2493     ih264_deblk_edge_bs4_ft *pf_deblk_luma_vert_bs4;
   2494 
   2495     /**
   2496      * deblock vertical chroma edge with blocking strength 4
   2497      */
   2498     ih264_deblk_chroma_edge_bs4_ft *pf_deblk_chroma_vert_bs4;
   2499 
   2500     /**
   2501      * deblock vertical luma edge with blocking strength less than 4
   2502      */
   2503     ih264_deblk_edge_bslt4_ft *pf_deblk_luma_vert_bslt4;
   2504 
   2505     /**
   2506      * deblock vertical chroma edge with blocking strength less than 4
   2507      */
   2508     ih264_deblk_chroma_edge_bslt4_ft *pf_deblk_chroma_vert_bslt4;
   2509 
   2510     /**
   2511      * deblock horizontal luma edge with blocking strength 4
   2512      */
   2513     ih264_deblk_edge_bs4_ft *pf_deblk_luma_horz_bs4;
   2514 
   2515     /**
   2516      * deblock horizontal chroma edge with blocking strength 4
   2517      */
   2518     ih264_deblk_chroma_edge_bs4_ft *pf_deblk_chroma_horz_bs4;
   2519 
   2520     /**
   2521      * deblock horizontal luma edge with blocking strength less than 4
   2522      */
   2523     ih264_deblk_edge_bslt4_ft *pf_deblk_luma_horz_bslt4;
   2524 
   2525     /**
   2526      * deblock horizontal chroma edge with blocking strength less than 4
   2527      */
   2528     ih264_deblk_chroma_edge_bslt4_ft *pf_deblk_chroma_horz_bslt4;
   2529 
   2530 
   2531     /**
   2532      * functions for padding
   2533      */
   2534     pf_pad pf_pad_top;
   2535     pf_pad pf_pad_bottom;
   2536     pf_pad pf_pad_left_luma;
   2537     pf_pad pf_pad_left_chroma;
   2538     pf_pad pf_pad_right_luma;
   2539     pf_pad pf_pad_right_chroma;
   2540 
   2541     /**
   2542      * Inter pred leaf level functions
   2543      */
   2544     ih264_inter_pred_luma_ft    *pf_inter_pred_luma_copy;
   2545     ih264_inter_pred_luma_ft    *pf_inter_pred_luma_horz;
   2546     ih264_inter_pred_luma_ft    *pf_inter_pred_luma_vert;
   2547     pf_inter_pred_luma_bilinear  pf_inter_pred_luma_bilinear;
   2548     ih264_inter_pred_chroma_ft  *pf_inter_pred_chroma;
   2549 
   2550     /**
   2551      * fn ptrs for compute sad routines
   2552      */
   2553     ime_compute_sad_ft *apf_compute_sad_16x16[2];
   2554     ime_compute_sad_ft *pf_compute_sad_16x8;
   2555 
   2556 
   2557     /**
   2558      * Function pointer for computing ME
   2559      * 1 for PSLICE and 1 for BSLICE
   2560      */
   2561     ih264e_compute_me_ft *apf_compute_me[2];
   2562 
   2563     /**
   2564      * Function pointers for computing SKIP parameters
   2565      */
   2566     ih264e_skip_params_ft *apf_find_skip_params_me[2];
   2567 
   2568     /**
   2569      * fn ptrs for memory handling operations
   2570      */
   2571     pf_memcpy pf_mem_cpy;
   2572     pf_memset pf_mem_set;
   2573     pf_memcpy_mul8 pf_mem_cpy_mul8;
   2574     pf_memset_mul8 pf_mem_set_mul8;
   2575 
   2576     /**
   2577      * intra mode eval -encoder level function
   2578      */
   2579     pf_evaluate_intra_modes pf_ih264e_evaluate_intra16x16_modes;
   2580     pf_evaluate_intra_modes pf_ih264e_evaluate_intra_chroma_modes;
   2581     pf_evaluate_intra_4x4_modes pf_ih264e_evaluate_intra_4x4_modes;
   2582 
   2583     /* Half pel generation function - encoder level
   2584      *
   2585      */
   2586     pf_sixtapfilter_horz pf_ih264e_sixtapfilter_horz;
   2587     pf_sixtap_filter_2dvh_vert pf_ih264e_sixtap_filter_2dvh_vert;
   2588 
   2589     /**
   2590      * color space conversion form YUV 420P to YUV 420Sp
   2591      */
   2592     pf_fmt_conv_420p_to_420sp pf_ih264e_conv_420p_to_420sp;
   2593 
   2594 
   2595     /**
   2596      * color space conversion form YUV 420P to YUV 420Sp
   2597      */
   2598     pf_fmt_conv_422ile_to_420sp pf_ih264e_fmt_conv_422i_to_420sp;
   2599 
   2600     /**
   2601      * write mb layer for a given slice I, P, B
   2602      */
   2603     IH264E_ERROR_T (*pf_write_mb_syntax_layer[2][3]) ( entropy_ctxt_t *ps_ent_ctxt );
   2604 
   2605     /**
   2606      * Output buffer
   2607      */
   2608     out_buf_t as_out_buf[MAX_CTXT_SETS];
   2609 
   2610     /**
   2611      * recon buffer
   2612      */
   2613     rec_buf_t as_rec_buf[MAX_CTXT_SETS];
   2614 
   2615     /**
   2616      * rate control context
   2617      */
   2618     rate_control_ctxt_t s_rate_control;
   2619 
   2620     /**
   2621      * input buffer queue
   2622      */
   2623     inp_buf_t as_inp_list[MAX_NUM_BFRAMES];
   2624 
   2625     /**
   2626      * Flag to indicate if any IDR requests are pending
   2627      */
   2628     WORD32 i4_pending_idr_flag;
   2629 
   2630     /*
   2631     *Flag to indicate if we have recived the last input frame
   2632     */
   2633     WORD32 i4_last_inp_buff_received;
   2634 
   2635 };
   2636 
   2637 #endif /* IH264E_STRUCTS_H_ */
   2638