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     /** VUI structure                                                         */
    567     vui_t                                       s_vui;
    568 
    569 }cfg_params_t;
    570 
    571 
    572 
    573 /** Structure to hold format conversion context */
    574 typedef struct
    575 {
    576     /** Current row for which format conversion should be done */
    577     WORD32 i4_cur_row;
    578 
    579     /** Number of rows for which format conversion should be done */
    580     WORD32 i4_num_rows;
    581 
    582 }fmt_conv_t;
    583 
    584 
    585 /**
    586  * Structure to represent a processing job entry
    587  */
    588 typedef struct
    589 {
    590     /**
    591      * Command
    592      */
    593     WORD32 i4_cmd;
    594 
    595     /**
    596      * MB x of the starting MB
    597      */
    598     WORD16 i2_mb_x;
    599 
    600     /**
    601      * MB y of the starting MB
    602      */
    603 
    604     WORD16 i2_mb_y;
    605 
    606     /**
    607      * Number of MBs that need to be processed in this job
    608      */
    609     WORD16 i2_mb_cnt;
    610 
    611     /**
    612      * Process contexts base index
    613      * Will toggle between 0 and MAX_PROCESS_THREADS
    614      */
    615     WORD16 i2_proc_base_idx;
    616 
    617 } job_t;
    618 
    619 
    620 /**
    621  * Structure to represent a MV Bank buffer
    622  */
    623 typedef struct
    624 {
    625     /**
    626      *  Pointer to hold num PUs each MB in a picture
    627      */
    628     UWORD32 *pu4_mb_pu_cnt;
    629 
    630     /**
    631      * Pointer to hold enc_pu_t for each PU in a picture
    632      */
    633     enc_pu_t *ps_pic_pu;
    634 
    635     /**
    636      * Pointer to hold PU map for each MB in a picture
    637      */
    638     UWORD8 *pu1_pic_pu_map;
    639 
    640     /**
    641      * Pointer to hold the Slice map
    642      */
    643     UWORD16 *pu1_pic_slice_map;
    644 
    645     /**
    646      * Absolute POC for the current MV Bank
    647      */
    648     WORD32 i4_abs_poc;
    649 
    650     /**
    651      * Buffer Id
    652      */
    653     WORD32     i4_buf_id;
    654 
    655 } mv_buf_t;
    656 
    657 
    658 /**
    659  * Reference set containing pointers to MV buf and pic buf
    660  */
    661 typedef struct
    662 {
    663     /** Picture count */
    664     WORD32    i4_pic_cnt;
    665 
    666     /** POC */
    667     WORD32    i4_poc;
    668 
    669     /** picture buffer */
    670     pic_buf_t *ps_pic_buf;
    671 
    672     /** mv buffer */
    673     mv_buf_t  *ps_mv_buf;
    674 
    675 }ref_set_t;
    676 
    677 typedef struct
    678 {
    679 
    680     /**
    681      * Pointer to current PPS
    682      */
    683     pps_t *ps_pps;
    684 
    685     /**
    686      * Pointer to current SPS
    687      */
    688     sps_t *ps_sps;
    689 
    690     /**
    691      * Pointer to current slice header structure
    692      */
    693     slice_header_t *ps_slice_hdr;
    694 
    695     /**
    696      * MB's x position within a picture in raster scan in MB units
    697      */
    698     WORD32 i4_mb_x;
    699 
    700     /**
    701      * MB's y position within a picture in raster scan in MB units
    702      */
    703 
    704     WORD32 i4_mb_y;
    705 
    706     /**
    707      * Current PU structure - set to MB enc_pu_t pointer at the start of MB processing and incremented
    708      * for every TU
    709      */
    710     enc_pu_t *ps_pu;
    711 
    712     /**
    713      * Pointer to frame level enc_pu_t for the current frame being parsed
    714      * where MVs and Intra pred modes will be updated
    715      */
    716     enc_pu_t *ps_pic_pu;
    717 
    718     /**
    719      *  Pointer to hold num PUs each MB in a picture
    720      */
    721     UWORD32 *pu4_mb_pu_cnt;
    722 
    723     /** PU Index map per MB. The indices in this map are w.r.t picture pu array and not
    724      * w.r.t MB pu array.
    725      * This will be used during mv prediction and since neighbors will have different MB pu map
    726      * it will be easier if they all have indices w.r.t picture level PU array rather than MB level
    727      * PU array.
    728      * pu1_pic_pu_map is map w.r.t MB's enc_pu_t array
    729      */
    730     UWORD32 *pu4_pic_pu_idx_map;
    731 
    732     /**
    733       * Pointer to pu_map for the current frame being parsed
    734       * where MVs and Intra pred modes will be updated
    735       */
    736      UWORD8 *pu1_pic_pu_map;
    737 
    738      /**
    739       *  PU count in current MB
    740       */
    741      WORD32 i4_mb_pu_cnt;
    742 
    743      /**
    744       *  PU count in current MB
    745       */
    746      WORD32 i4_mb_start_pu_idx;
    747 
    748      /**
    749       *  Top availability for current MB level
    750       */
    751      UWORD8 u1_top_mb_avail;
    752 
    753      /**
    754       *  Top right availability for current MB level
    755       */
    756      UWORD8 u1_top_rt_mb_avail;
    757      /**
    758       *  Top left availability for current MB level
    759       */
    760      UWORD8 u1_top_lt_mb_avail;
    761      /**
    762       *  left availability for current MB level
    763       */
    764      UWORD8 u1_left_mb_avail;
    765 
    766 }mv_ctxt_t;
    767 
    768 typedef struct
    769 {
    770     /**
    771      * MB's x position within a picture in raster scan in MB units
    772      */
    773     WORD32 i4_mb_x;
    774 
    775     /**
    776      * MB's y position within a picture in raster scan in MB units
    777      */
    778     WORD32 i4_mb_y;
    779 
    780     /**
    781      * MB's x position within a Slice in raster scan in MB units
    782      */
    783     WORD32 i4_mb_slice_x;
    784 
    785     /**
    786      * MB's y position within a Slice in raster scan in MB units
    787      */
    788     WORD32 i4_mb_slice_y;
    789 
    790     /**
    791      * Vertical strength, Two bits per edge.
    792      * Stored in format. BS[15] | BS[14] | .. |BS[0]
    793      */
    794     UWORD32 *pu4_pic_vert_bs;
    795 
    796     /**
    797      * Boundary strength, Two bits per edge.
    798      * Stored in format. BS[15] | BS[14] | .. |BS[0]
    799      */
    800     UWORD32 *pu4_pic_horz_bs;
    801 
    802     /**
    803      *  Qp array stored for each mb
    804      */
    805     UWORD8  *pu1_pic_qp;
    806 
    807 }bs_ctxt_t;
    808 
    809 typedef struct
    810 {
    811     /**
    812      * MB's x position within a picture in raster scan in MB units
    813      */
    814     WORD32 i4_mb_x;
    815 
    816     /**
    817      * MB's y position within a picture in raster scan in MB units
    818      */
    819     WORD32 i4_mb_y;
    820 
    821     /**
    822      * structure that contains BS and QP frame level arrays
    823      */
    824     bs_ctxt_t s_bs_ctxt;
    825 
    826     /**
    827      * Pointer to 0th luma pixel in current pic
    828      */
    829     UWORD8 *pu1_cur_pic_luma;
    830 
    831     /**
    832      * Pointer to 0th chroma pixel in current pic
    833      */
    834     UWORD8 *pu1_cur_pic_chroma;
    835 
    836     /**
    837      *  Points to the array of slice indices which is used to identify the slice
    838      *  to which each MB in a frame belongs.
    839      */
    840     UWORD8 *pu1_slice_idx;
    841 
    842 }deblk_ctxt_t;
    843 
    844 
    845 /**
    846  ******************************************************************************
    847  *  @brief      Structure to hold data and flags for 'n' mb processing for
    848  *                deblocking , padding and half pel generation.
    849  ******************************************************************************
    850  */
    851 typedef struct
    852 {
    853     /**
    854      * MB's x position last processed + 1
    855      */
    856     WORD32 i4_mb_x;
    857 
    858     /**
    859      * MB's y position ,current processing.
    860      */
    861     WORD32 i4_mb_y;
    862 
    863     /**
    864      * Number of MBs processed in a stretch
    865      */
    866     WORD32 i4_n_mbs;
    867 
    868 }n_mb_process_ctxt_t;
    869 
    870 
    871 /**
    872 ******************************************************************************
    873  *  @brief      Structure to hold coefficient info for a 4x4 subblock.
    874  *  The following can be used to type-cast coefficient data that is stored
    875  *  per subblock. Note that though i2_level is shown as an array that
    876  *  holds 16 coefficients, only the first few entries will be valid. Next
    877  *  subblocks data starts after the valid number of coefficients. Number
    878  *  of non-zero coefficients will be derived using number of non-zero bits
    879  *  in sig coeff map
    880 ******************************************************************************
    881  */
    882 typedef struct
    883 {
    884     /**
    885      * significant coefficient map and nnz are packed in
    886      * to msb (2 bytes) and lsb (2 bytes) respectively
    887      */
    888     WORD32  i4_sig_map_nnz;
    889 
    890     /**
    891      * array of non zero residue coefficients
    892      */
    893     WORD16  ai2_residue[16];
    894 
    895 }tu_sblk_coeff_data_t;
    896 
    897 /**
    898 ******************************************************************************
    899  *  @brief      Structure contains few common state variables such as MB indices,
    900  *  current SPS, PPS etc which are to be used in the entropy thread. By keeping
    901  *  it a different structure it is being explicitly signaled that these
    902  * variables are specific to entropy threads context and other threads should
    903  * not update these elements
    904 ******************************************************************************
    905  */
    906 typedef struct
    907 {
    908     /**
    909      * Pointer to the cabac context
    910      */
    911     cabac_ctxt_t *ps_cabac;
    912 
    913     /**
    914      * start of frame / start of slice flag
    915      */
    916     WORD32 i4_sof;
    917 
    918     /**
    919      * end of frame / end of slice flag
    920      */
    921     WORD32 i4_eof;
    922 
    923     /**
    924      * generate header upon request
    925      */
    926     WORD32 i4_gen_header;
    927 
    928     /**
    929      *  seq_parameter_set_id
    930      */
    931     UWORD32 u4_sps_id;
    932 
    933     /**
    934      * Pointer to base of sequence parameter set structure array
    935      */
    936     sps_t *ps_sps_base;
    937 
    938     /**
    939      *  pic_parameter_set_id
    940      */
    941     UWORD32 u4_pps_id;
    942 
    943     /**
    944      * Pointer to base of Picture parameter set structure array
    945      */
    946     pps_t *ps_pps_base;
    947 
    948     /**
    949      * Current slice idx
    950      */
    951     WORD32 i4_cur_slice_idx;
    952 
    953     /**
    954      * Points to the array of slice indices which is used to identify the independent slice
    955      * to which each MB in a frame belongs.
    956      */
    957     UWORD8 *pu1_slice_idx;
    958 
    959     /**
    960      * Pointer to base of slice header structure array
    961      */
    962     slice_header_t *ps_slice_hdr_base;
    963 
    964     /**
    965      * entropy status
    966      */
    967     UWORD8  *pu1_entropy_map;
    968 
    969     /**
    970      * MB's x position within a picture in raster scan in MB units
    971      */
    972     WORD32 i4_mb_x;
    973 
    974     /**
    975      * MB's y position within a picture in raster scan in MB units
    976      */
    977     WORD32 i4_mb_y;
    978 
    979     /**
    980      * MB start address
    981      */
    982     WORD32 i4_mb_cnt;
    983 
    984     /**
    985      * MB start address
    986      */
    987     WORD32 i4_mb_start_add;
    988 
    989     /**
    990      * MB end address
    991      */
    992     WORD32 i4_mb_end_add;
    993 
    994     /**
    995      * Input width in mbs
    996      */
    997     WORD32 i4_wd_mbs;
    998 
    999     /**
   1000      * Input height in mbs
   1001      */
   1002     WORD32 i4_ht_mbs;
   1003 
   1004     /**
   1005      * Bitstream structure
   1006      */
   1007     bitstrm_t *ps_bitstrm;
   1008 
   1009     /**
   1010      *  transform_8x8_mode_flag
   1011      */
   1012     WORD8 i1_transform_8x8_mode_flag;
   1013 
   1014     /**
   1015      *  entropy_coding_mode_flag
   1016      */
   1017     WORD8 u1_entropy_coding_mode_flag;
   1018 
   1019     /**
   1020      * Pointer to the top row nnz for luma
   1021      */
   1022     UWORD8 (*pu1_top_nnz_luma)[4];
   1023 
   1024     /**
   1025      * left nnz for luma
   1026      */
   1027     UWORD32 u4_left_nnz_luma;
   1028 
   1029     /**
   1030      * Pointer to zero runs before for the mb
   1031      */
   1032     UWORD8  au1_zero_run[16];
   1033 
   1034     /**
   1035      * Pointer to the top row nnz for chroma
   1036      */
   1037     UWORD8 (*pu1_top_nnz_cbcr)[4];
   1038 
   1039     /**
   1040      * left nnz for chroma
   1041      */
   1042     UWORD8 u4_left_nnz_cbcr;
   1043 
   1044     /**
   1045      * Pointer frame level mb subblock coeff data
   1046      */
   1047     void *pv_pic_mb_coeff_data;
   1048 
   1049     /**
   1050      * Pointer to mb subblock coeff data and number of subblocks and scan idx
   1051      * Incremented each time a coded subblock is processed
   1052      */
   1053     void *pv_mb_coeff_data;
   1054 
   1055     /**
   1056      * Pointer frame level mb header data
   1057      */
   1058     void *pv_pic_mb_header_data;
   1059 
   1060     /**
   1061      * Pointer to mb header data and
   1062      * incremented each time a coded mb is encoded
   1063      */
   1064     void *pv_mb_header_data;
   1065 
   1066     /**
   1067      * Error code during parse stage
   1068      */
   1069     IH264E_ERROR_T i4_error_code;
   1070 
   1071     /**
   1072      * Void pointer to job context
   1073      */
   1074     void *pv_proc_jobq, *pv_entropy_jobq;
   1075 
   1076     /**
   1077      * Flag to signal end of frame
   1078      */
   1079     WORD32 i4_end_of_frame;
   1080 
   1081     /**
   1082      * Abs POC count of the frame
   1083      */
   1084      WORD32 i4_abs_pic_order_cnt;
   1085 
   1086      /**
   1087       * mb skip run
   1088       */
   1089      WORD32 *pi4_mb_skip_run;
   1090 
   1091      /**
   1092       * Flag to signal end of sequence
   1093       */
   1094      UWORD32 u4_is_last;
   1095 
   1096      /**
   1097       * Lower 32bits of time-stamp corresponding to the buffer being encoded
   1098       */
   1099      UWORD32 u4_timestamp_low;
   1100 
   1101      /**
   1102       * Upper 32bits of time-stamp corresponding to the buffer being encoded
   1103       */
   1104      UWORD32 u4_timestamp_high;
   1105 
   1106      /**
   1107       * Current Picture count - used for synchronization
   1108       */
   1109      WORD32  i4_pic_cnt;
   1110 
   1111      /**
   1112       * Number of bits consumed by header for I and P mb types
   1113       */
   1114      UWORD32 u4_header_bits[MAX_MB_TYPE];
   1115 
   1116      /**
   1117       * Number of bits consumed by residue for I and P mb types
   1118       */
   1119      UWORD32 u4_residue_bits[MAX_MB_TYPE];
   1120 
   1121 } entropy_ctxt_t;
   1122 
   1123 /**
   1124 ******************************************************************************
   1125 *  @brief      macro block info.
   1126 ******************************************************************************
   1127 */
   1128 typedef struct
   1129 {
   1130     /**
   1131      * mb type
   1132      */
   1133     UWORD16 u2_is_intra;
   1134 
   1135     /**
   1136      * mb type
   1137      */
   1138     UWORD16 u2_mb_type;
   1139 
   1140     /**
   1141      * csbp
   1142      */
   1143     UWORD32 u4_csbp;
   1144 
   1145     /**
   1146      * mb distortion
   1147      */
   1148     WORD32 i4_mb_distortion;
   1149 
   1150 }mb_info_t;
   1151 
   1152 /**
   1153 ******************************************************************************
   1154 *  @brief     mb_hdr structures to access first few common elements of above
   1155 * structures
   1156 ******************************************************************************
   1157 */
   1158 
   1159 typedef struct
   1160 {
   1161     /**
   1162      * mb type and mode
   1163      */
   1164     UWORD8 u1_mb_type_mode;
   1165 
   1166     /**
   1167      * CBP
   1168      */
   1169     UWORD8 u1_cbp;
   1170 
   1171     /**
   1172      * MB qp delta
   1173      */
   1174     UWORD8 u1_mb_qp_delta;
   1175 
   1176     /**
   1177      * Element to align structure to 2 byte boundary
   1178      */
   1179     UWORD8 u1_pad;
   1180 }mb_hdr_common_t;
   1181 
   1182 /**
   1183 ******************************************************************************
   1184 *  @brief      macro block info for I4x4 MB
   1185 ******************************************************************************
   1186 */
   1187 typedef struct
   1188 {
   1189     /**
   1190      * Common MB header params
   1191      */
   1192     mb_hdr_common_t common;
   1193 
   1194     /**
   1195      * Sub block modes, 2 modes per byte
   1196      */
   1197     UWORD8 au1_sub_blk_modes[8];
   1198 }mb_hdr_i4x4_t;
   1199 
   1200 /**
   1201 ******************************************************************************
   1202 *  @brief      macro block info for I8x8 MB
   1203 ******************************************************************************
   1204 */
   1205 typedef struct
   1206 {
   1207     /**
   1208      * Common MB header params
   1209      */
   1210     mb_hdr_common_t common;
   1211 
   1212 
   1213     /**
   1214      * Sub block modes, 2 modes per byte
   1215      */
   1216     UWORD8 au1_sub_blk_modes[2];
   1217 }mb_hdr_i8x8_t;
   1218 
   1219 /**
   1220 ******************************************************************************
   1221 *  @brief      macro block info for I16x16 MB
   1222 ******************************************************************************
   1223 */
   1224 typedef struct
   1225 {
   1226     /**
   1227      * Common MB header params
   1228      */
   1229     mb_hdr_common_t common;
   1230 
   1231 }mb_hdr_i16x16_t;
   1232 
   1233 /**
   1234 ******************************************************************************
   1235 *  @brief      macro block info for P16x16 MB
   1236 ******************************************************************************
   1237 */
   1238 typedef struct
   1239 {
   1240     /**
   1241      * Common MB header params
   1242      */
   1243     mb_hdr_common_t common;
   1244 
   1245     /**
   1246      * MV
   1247      */
   1248     WORD16 ai2_mv[2];
   1249 }mb_hdr_p16x16_t;
   1250 
   1251 /**
   1252 ******************************************************************************
   1253 *  @brief      macro block info for PSKIP MB
   1254 ******************************************************************************
   1255 */
   1256 typedef struct
   1257 {
   1258     /**
   1259      * Common MB header params
   1260      */
   1261     mb_hdr_common_t common;
   1262 
   1263 }mb_hdr_pskip_t;
   1264 
   1265 /**
   1266 ******************************************************************************
   1267 *  @brief      macro block info for B16x16 MB
   1268 ******************************************************************************
   1269 */
   1270 typedef struct
   1271 {
   1272     /**
   1273      * Common MB header params
   1274      */
   1275     mb_hdr_common_t common;
   1276 
   1277 
   1278     /**
   1279      * MV
   1280      */
   1281     WORD16 ai2_mv[2][2];
   1282 }mb_hdr_b16x16_t;
   1283 
   1284 /**
   1285 ******************************************************************************
   1286 *  @brief      macro block info for BDIRECT MB
   1287 ******************************************************************************
   1288 */
   1289 typedef struct
   1290 {
   1291     /**
   1292      * Common MB header params
   1293      */
   1294     mb_hdr_common_t common;
   1295 
   1296 }mb_hdr_bdirect_t;
   1297 
   1298 /**
   1299 ******************************************************************************
   1300 *  @brief      macro block info for PSKIP MB
   1301 ******************************************************************************
   1302 */
   1303 typedef struct
   1304 {
   1305     /**
   1306      * Common MB header params
   1307      */
   1308     mb_hdr_common_t common;
   1309 
   1310 }mb_hdr_bskip_t;
   1311 
   1312 /**
   1313 ******************************************************************************
   1314 *  @brief      Union of mb_hdr structures for size calculation
   1315 *  and to access first few common elements
   1316 ******************************************************************************
   1317 */
   1318 
   1319 typedef union
   1320 {
   1321     mb_hdr_i4x4_t       mb_hdr_i4x4;
   1322     mb_hdr_i8x8_t       mb_hdr_i8x8;
   1323     mb_hdr_i16x16_t     mb_hdr_i16x16;
   1324     mb_hdr_p16x16_t     mb_hdr_p16x16;
   1325     mb_hdr_pskip_t      mb_hdr_pskip;
   1326     mb_hdr_b16x16_t     mb_hdr_b16x16;
   1327     mb_hdr_bdirect_t    mb_hdr_bdirect;
   1328     mb_hdr_bskip_t      mb_hdr_bskip;
   1329 }mb_hdr_t;
   1330 /**
   1331 ******************************************************************************
   1332 *  @brief      structure presenting the neighbor availability of a mb
   1333 *  or subblk or any other partition
   1334 ******************************************************************************
   1335 */
   1336 typedef struct
   1337 {
   1338     /**
   1339      * left blk/subblk/partition
   1340      */
   1341     UWORD8 u1_mb_a;
   1342 
   1343     /**
   1344      * top blk/subblk/partition
   1345      */
   1346     UWORD8 u1_mb_b;
   1347 
   1348     /**
   1349      * topright blk/subblk/partition
   1350      */
   1351     UWORD8 u1_mb_c;
   1352 
   1353     /**
   1354      * topleft blk/subblk/partition
   1355      */
   1356     UWORD8 u1_mb_d;
   1357 
   1358 }block_neighbors_t;
   1359 
   1360 /**
   1361  ******************************************************************************
   1362  *  @brief      MB info  related variables used during NMB processing
   1363  ******************************************************************************
   1364  */
   1365 typedef struct
   1366 {
   1367     UWORD32 u4_mb_type;
   1368     UWORD32 u4_min_sad;
   1369     UWORD32 u4_min_sad_reached;
   1370     WORD32  i4_mb_cost;
   1371     WORD32  i4_mb_distortion;
   1372 
   1373     enc_pu_mv_t as_skip_mv[4];
   1374 
   1375     enc_pu_mv_t as_pred_mv[2];
   1376 
   1377     block_neighbors_t s_ngbr_avbl;
   1378 
   1379     /*
   1380      * Buffer to hold best subpel buffer in each MB of NMB
   1381      */
   1382     UWORD8 *pu1_best_sub_pel_buf;
   1383 
   1384     /*
   1385      * Stride for subpel buffer
   1386      */
   1387     UWORD32 u4_bst_spel_buf_strd;
   1388 
   1389 }mb_info_nmb_t;
   1390 
   1391 /**
   1392  ******************************************************************************
   1393  *  @brief      Pixel processing thread context
   1394  ******************************************************************************
   1395  */
   1396 struct _proc_t
   1397 {
   1398     /**
   1399      * entropy context
   1400      */
   1401     entropy_ctxt_t s_entropy;
   1402 
   1403     /**
   1404      * me context
   1405      */
   1406     me_ctxt_t s_me_ctxt;
   1407 
   1408     /**
   1409      * Pointer to codec context
   1410      */
   1411     codec_t *ps_codec;
   1412 
   1413     /**
   1414      * N mb process contest
   1415      */
   1416     n_mb_process_ctxt_t s_n_mb_ctxt;
   1417 
   1418     /**
   1419      * Source pointer to current MB luma
   1420      */
   1421     UWORD8 *pu1_src_buf_luma;
   1422 
   1423     /**
   1424      * Source pointer to current MB chroma
   1425      */
   1426     UWORD8 *pu1_src_buf_chroma;
   1427 
   1428     /**
   1429      * Recon pointer to current MB luma
   1430      */
   1431     UWORD8 *pu1_rec_buf_luma;
   1432 
   1433     /**
   1434      * Recon pointer to current MB chroma
   1435      */
   1436     UWORD8 *pu1_rec_buf_chroma;
   1437 
   1438     /**
   1439      * Ref pointer to current MB luma
   1440      */
   1441     UWORD8 *apu1_ref_buf_luma[MAX_REF_PIC_CNT];
   1442 
   1443     /**
   1444      * Ref pointer to current MB chroma
   1445      */
   1446     UWORD8 *apu1_ref_buf_chroma[MAX_REF_PIC_CNT];
   1447 
   1448     /**
   1449      * pointer to luma plane of input buffer (base :: mb (0,0))
   1450      */
   1451     UWORD8 *pu1_src_buf_luma_base;
   1452 
   1453     /**
   1454      * pointer to luma plane of reconstructed buffer (base :: mb (0,0))
   1455      */
   1456     UWORD8 *pu1_rec_buf_luma_base;
   1457 
   1458     /**
   1459      * pointer to luma plane of ref buffer (base :: mb (0,0))
   1460      */
   1461     UWORD8 *apu1_ref_buf_luma_base[MAX_REF_PIC_CNT];
   1462 
   1463     /**
   1464      * pointer to  chroma plane of input buffer (base :: mb (0,0))
   1465      */
   1466     UWORD8 *pu1_src_buf_chroma_base;
   1467 
   1468     /*
   1469      * Buffer for color space conversion of luma
   1470      */
   1471     UWORD8 *pu1_y_csc_buf;
   1472 
   1473     /*
   1474      * Buffer for color space conversion of luma
   1475      */
   1476 
   1477     UWORD8 *pu1_uv_csc_buf;
   1478 
   1479     /**
   1480      * pointer to  chroma plane of reconstructed buffer (base :: mb (0,0))
   1481      */
   1482     UWORD8 *pu1_rec_buf_chroma_base;
   1483 
   1484     /**
   1485      * pointer to  chroma plane of reconstructed buffer (base :: mb (0,0))
   1486      */
   1487     UWORD8 *apu1_ref_buf_chroma_base[MAX_REF_PIC_CNT];
   1488 
   1489     /**
   1490      * Pointer to ME NMB info
   1491      */
   1492     mb_info_nmb_t *ps_nmb_info;
   1493 
   1494     mb_info_nmb_t *ps_cur_mb;
   1495 
   1496     /**
   1497      * source luma stride
   1498      */
   1499     WORD32 i4_src_strd;
   1500 
   1501     /**
   1502      * source chroma stride
   1503      */
   1504     WORD32 i4_src_chroma_strd;
   1505 
   1506     /**
   1507      * recon stride & ref stride
   1508      * (strides for luma and chroma are the same)
   1509      */
   1510     WORD32 i4_rec_strd;
   1511 
   1512     /**
   1513      * Offset for half pel x plane from the pic buf
   1514      */
   1515     UWORD32 u4_half_x_offset;
   1516 
   1517     /**
   1518      * Offset for half pel y plane from half x plane
   1519      */
   1520     UWORD32 u4_half_y_offset;
   1521 
   1522     /**
   1523      * Offset for half pel xy plane from half y plane
   1524      */
   1525     UWORD32 u4_half_xy_offset;
   1526 
   1527     /**
   1528      * pred buffer pointer (temp buffer 1)
   1529      */
   1530     UWORD8 *pu1_pred_mb;
   1531 
   1532     /**
   1533      * pred buffer pointer (prediction buffer for intra 16x16
   1534      */
   1535     UWORD8 *pu1_pred_mb_intra_16x16;
   1536 
   1537     /**
   1538      * pred buffer pointer (prediction buffer for intra 16x16_plane
   1539      */
   1540     UWORD8 *pu1_pred_mb_intra_16x16_plane;
   1541 
   1542     /**
   1543      * pred buffer pointer (prediction buffer for intra chroma
   1544      */
   1545     UWORD8 *pu1_pred_mb_intra_chroma;
   1546 
   1547     /**
   1548      * pred buffer pointer (prediction buffer for intra chroma plane
   1549      */
   1550     UWORD8 *pu1_pred_mb_intra_chroma_plane;
   1551 
   1552     /**
   1553      * temp. reference buffer ptr for intra 4x4 when rdopt is on
   1554      */
   1555     UWORD8 *pu1_ref_mb_intra_4x4;
   1556 
   1557     /**
   1558      * prediction buffer stride
   1559      */
   1560     WORD32 i4_pred_strd;
   1561 
   1562     /**
   1563      * transform buffer pointer (temp buffer 2)
   1564      */
   1565     WORD16 *pi2_res_buf;
   1566 
   1567     /**
   1568      * temp. transform buffer ptr for intra 4x4 when rdopt is on
   1569      */
   1570     WORD16 *pi2_res_buf_intra_4x4;
   1571 
   1572     /**
   1573      * transform buffer stride
   1574      */
   1575     WORD32 i4_res_strd;
   1576 
   1577     /**
   1578      * scratch buffer for inverse transform (temp buffer 3)
   1579      */
   1580     void *pv_scratch_buff;
   1581 
   1582     /**
   1583      * frame num
   1584      */
   1585     WORD32 i4_frame_num;
   1586 
   1587     /**
   1588      * start address of frame / sub-frame
   1589      */
   1590     WORD32 i4_frame_strt_add;
   1591 
   1592     /**
   1593      *  IDR pic
   1594      */
   1595     UWORD32 u4_is_idr;
   1596 
   1597     /**
   1598      *  idr_pic_id
   1599      */
   1600     UWORD32 u4_idr_pic_id;
   1601 
   1602     /**
   1603      * Input width in mbs
   1604      */
   1605     WORD32 i4_wd_mbs;
   1606 
   1607     /**
   1608      * Input height in mbs
   1609      */
   1610     WORD32 i4_ht_mbs;
   1611 
   1612     /**
   1613      *  slice_type
   1614      */
   1615     WORD32  i4_slice_type;
   1616 
   1617     /**
   1618      * Current slice idx
   1619      */
   1620     WORD32 i4_cur_slice_idx;
   1621 
   1622     /**
   1623      * MB's x position within a picture in raster scan in MB units
   1624      */
   1625     WORD32 i4_mb_x;
   1626 
   1627     /**
   1628      * MB's y position within a picture in raster scan in MB units
   1629      */
   1630     WORD32 i4_mb_y;
   1631 
   1632     /**
   1633      * MB's x position within a Slice in raster scan in MB units
   1634      */
   1635     WORD32 i4_mb_slice_x;
   1636 
   1637     /**
   1638      * MB's y position within a Slice in raster scan in MB units
   1639      */
   1640     WORD32 i4_mb_slice_y;
   1641 
   1642     /**
   1643      *  mb type
   1644      */
   1645     UWORD32 u4_mb_type;
   1646 
   1647     /**
   1648      *  is intra
   1649      */
   1650     UWORD32 u4_is_intra;
   1651 
   1652     /**
   1653      * mb neighbor availability pointer
   1654      */
   1655     block_neighbors_t *ps_ngbr_avbl;
   1656 
   1657     /**
   1658      * lambda (lagrange multiplier for cost computation)
   1659      */
   1660     UWORD32 u4_lambda;
   1661 
   1662     /**
   1663      * mb distortion
   1664      */
   1665     WORD32 i4_mb_distortion;
   1666 
   1667     /**
   1668      * mb cost
   1669      */
   1670     WORD32 i4_mb_cost;
   1671 
   1672     /********************************************************************/
   1673     /* i4_ngbr_avbl_mb_16 - ngbr avbl of curr mb                        */
   1674     /* i4_ngbr_avbl_sb_8 - ngbr avbl of all 8x8 sub blocks of curr mb   */
   1675     /* i4_ngbr_avbl_sb_4 - ngbr avbl of all 4x4 sub blocks of curr mb   */
   1676     /* i4_ngbr_avbl_mb_c - chroma ngbr avbl of curr mb                  */
   1677     /********************************************************************/
   1678     WORD32  i4_ngbr_avbl_16x16_mb;
   1679     WORD32  ai4_neighbor_avail_8x8_subblks[4];
   1680     UWORD8  au1_ngbr_avbl_4x4_subblks[16];
   1681     WORD32  i4_chroma_neighbor_avail_8x8_mb;
   1682 
   1683     /**
   1684      * array to store the mode of mb sub blocks
   1685      */
   1686     UWORD8  au1_intra_luma_mb_4x4_modes[16];
   1687 
   1688     /**
   1689      * array to store the predicted mode of mb sub blks
   1690      */
   1691     UWORD8  au1_predicted_intra_luma_mb_4x4_modes[16];
   1692 
   1693     /**
   1694      * macro block intra 16x16 mode
   1695      */
   1696     UWORD8  u1_l_i16_mode;
   1697 
   1698     /**
   1699      * array to store the mode of the macro block intra 8x8 4 modes
   1700      */
   1701     UWORD8  au1_intra_luma_mb_8x8_modes[4];
   1702 
   1703     /**
   1704      * intra chroma mb mode
   1705      */
   1706     UWORD8  u1_c_i8_mode;
   1707 
   1708     /********************************************************************/
   1709     /* array to store pixels from the neighborhood for intra prediction */
   1710     /* i16 - 16 left pels + 1 top left pel + 16 top pels = 33 pels      */
   1711     /* i8 - 8 lpels + 1 tlpels + 8 tpels + 8 tr pels = 25 pels          */
   1712     /* i4 - 4 lpels + 1 tlpels + 4 tpels + 4 tr pels = 13 pels          */
   1713     /* ic - 8 left pels + 1 top left pel + 8 top pels )*2               */
   1714     /********************************************************************/
   1715     UWORD8 au1_ngbr_pels[34];
   1716 
   1717     /**
   1718      * array for 8x8 intra pels filtering (temp buff 4)
   1719      */
   1720     UWORD8 au1_neighbor_pels_i8x8_unfiltered[25];
   1721 
   1722     /**
   1723      * Number of sub partitons in the inter pred MB
   1724      */
   1725     UWORD32 u4_num_sub_partitions;
   1726 
   1727     /**
   1728      *  Pointer to hold num PUs each MB in a picture
   1729      */
   1730     UWORD32 *pu4_mb_pu_cnt;
   1731 
   1732     /**
   1733      * Pointer to the array of structures having motion vectors, size
   1734      *  and position of sub partitions
   1735      */
   1736     enc_pu_t *ps_pu;
   1737 
   1738     /**
   1739      * Pointer to the pu of current co-located MB in list 1
   1740      */
   1741     enc_pu_t *ps_colpu;
   1742 
   1743     /**
   1744      * predicted motion vector
   1745      */
   1746     enc_pu_mv_t *ps_skip_mv;
   1747 
   1748     /**
   1749      * predicted motion vector
   1750      */
   1751     enc_pu_mv_t *ps_pred_mv;
   1752 
   1753     /**
   1754      * top row mb syntax information base
   1755      * In normal working scenarios, for a given context set,
   1756      * the mb syntax info pointer is identical across all process threads.
   1757      * But when the hard bound on slices are enabled, in multi core, frame
   1758      * is partitioned in to sections equal to set number of cores and each
   1759      * partition is run independently. In this scenario, a ctxt set will alone
   1760      * appear to run multiple frames at a time. For this to occur, the common
   1761      * pointers across the proc ctxt should disappear.
   1762      *
   1763      * This is done by allocating MAX_PROCESS_THREADS memory and distributing
   1764      * across individual ctxts when byte bnd per slice is enabled.
   1765      */
   1766     mb_info_t *ps_top_row_mb_syntax_ele_base;
   1767 
   1768     /**
   1769      * top row mb syntax information
   1770      */
   1771     mb_info_t *ps_top_row_mb_syntax_ele;
   1772 
   1773     /**
   1774      * left mb syntax information
   1775      */
   1776     mb_info_t s_left_mb_syntax_ele;
   1777 
   1778     /**
   1779      * top left mb syntax information
   1780      */
   1781     mb_info_t s_top_left_mb_syntax_ele;
   1782 
   1783     /**
   1784      * top left mb syntax information
   1785      */
   1786 
   1787     mb_info_t s_top_left_mb_syntax_ME;
   1788 
   1789     /**
   1790      * left mb motion vector
   1791      */
   1792     enc_pu_t s_left_mb_pu_ME;
   1793 
   1794     /**
   1795      * top left mb motion vector
   1796      */
   1797     enc_pu_t s_top_left_mb_pu_ME;
   1798 
   1799     /**
   1800      * mb neighbor availability pointer
   1801      */
   1802     block_neighbors_t s_ngbr_avbl;
   1803 
   1804     /**
   1805      * In case the macroblock type is intra, the intra modes of all
   1806      * partitions for the left mb are stored in the array below
   1807      */
   1808     UWORD8 au1_left_mb_intra_modes[16];
   1809 
   1810     /**
   1811      * In case the macroblock type is intra, the intra modes of all
   1812      * partitions for the top mb are stored in the array below
   1813      *
   1814      * In normal working scenarios, for a given context set,
   1815      * the mb syntax info pointer is identical across all process threads.
   1816      * But when the hard bound on slices are enabled, in multi core, frame
   1817      * is partitioned in to sections equal to set number of cores and each
   1818      * partition is run independently. In this scenario, a ctxt set will alone
   1819      * appear to run multiple frames at a time. For this to occur, the common
   1820      * pointers across the proc ctxt should disappear.
   1821      *
   1822      * This is done by allocating MAX_PROCESS_THREADS memory and distributing
   1823      * across individual ctxts when byte bnd per slice is enabled.
   1824      */
   1825     UWORD8 *pu1_top_mb_intra_modes_base;
   1826 
   1827     /**
   1828      * In case the macroblock type is intra, the intra modes of all
   1829      * partitions for the top mb are stored in the array below
   1830      */
   1831     UWORD8 *pu1_top_mb_intra_modes;
   1832 
   1833     /**
   1834      * left mb motion vector
   1835      */
   1836     enc_pu_t s_left_mb_pu;
   1837 
   1838     /**
   1839      * top left mb motion vector
   1840      */
   1841     enc_pu_t s_top_left_mb_pu;
   1842 
   1843     /**
   1844      * top row motion vector info
   1845      *
   1846      * In normal working scenarios, for a given context set,
   1847      * the top row pu pointer is identical across all process threads.
   1848      * But when the hard bound on slices are enabled, in multi core, frame
   1849      * is partitioned in to sections equal to set number of cores and each
   1850      * partition is run independently. In this scenario, a ctxt set will alone
   1851      * appear to run multiple frames at a time. For this to occur, the common
   1852      * pointers across the proc ctxt should disappear.
   1853      *
   1854      * This is done by allocating MAX_PROCESS_THREADS memory and distributing
   1855      * across individual ctxts when byte bnd per slice is enabled.
   1856      */
   1857     enc_pu_t *ps_top_row_pu_base;
   1858 
   1859     /**
   1860      * top row motion vector info
   1861      */
   1862     enc_pu_t *ps_top_row_pu;
   1863 
   1864     enc_pu_t *ps_top_row_pu_ME;
   1865 
   1866     /**
   1867      * coded block pattern
   1868      */
   1869     UWORD32 u4_cbp;
   1870 
   1871     /**
   1872      * csbp
   1873      */
   1874     UWORD32 u4_csbp;
   1875 
   1876     /**
   1877      *  number of non zero coeffs
   1878      */
   1879     UWORD32 au4_nnz[5];
   1880 
   1881     /**
   1882      *  number of non zero coeffs for intra 4x4 when rdopt is on
   1883      */
   1884     UWORD32 au4_nnz_intra_4x4[4];
   1885 
   1886     /**
   1887      * frame qp & mb qp
   1888      */
   1889     UWORD32 u4_frame_qp, u4_mb_qp;
   1890 
   1891     /**
   1892      * mb qp previous
   1893      */
   1894     UWORD32 u4_mb_qp_prev;
   1895 
   1896     /**
   1897      * quantization parameters for luma & chroma planes
   1898      */
   1899     quant_params_t *ps_qp_params[3];
   1900 
   1901     /**
   1902      * Pointer frame level mb subblock coeff data
   1903      */
   1904     void *pv_pic_mb_coeff_data;
   1905 
   1906     /**
   1907      * Pointer to mb subblock coeff data and number of subblocks and scan idx
   1908      * Incremented each time a coded subblock is processed
   1909      */
   1910     void *pv_mb_coeff_data;
   1911 
   1912     /**
   1913      * Pointer frame level mb header data
   1914      */
   1915     void *pv_pic_mb_header_data;
   1916 
   1917     /**
   1918      * Pointer to mb header data and
   1919      * incremented each time a coded mb is encoded
   1920      */
   1921     void *pv_mb_header_data;
   1922 
   1923     /**
   1924      * Signal that pic_init is called first time
   1925      */
   1926     WORD32 i4_first_pic_init;
   1927 
   1928     /**
   1929      * Current MV Bank's buffer ID
   1930      */
   1931     WORD32 i4_cur_mv_bank_buf_id;
   1932 
   1933     /**
   1934      * Void pointer to job context
   1935      */
   1936     void *pv_proc_jobq, *pv_entropy_jobq;
   1937 
   1938     /**
   1939      * Number of MBs to be processed in the current Job
   1940      */
   1941     WORD32 i4_mb_cnt;
   1942 
   1943     /**
   1944      * ID for the current context - Used for debugging
   1945      */
   1946     WORD32 i4_id;
   1947 
   1948     /**
   1949      * Pointer to current picture buffer structure
   1950      */
   1951     pic_buf_t *ps_cur_pic;
   1952 
   1953     /**
   1954      * Pointer to current picture's mv buffer structure
   1955      */
   1956     mv_buf_t *ps_cur_mv_buf;
   1957 
   1958     /**
   1959      * Flag to indicate if ps_proc was initialized at least once in a frame.
   1960      * This is needed to handle cases where a core starts to handle format
   1961      * conversion jobs directly
   1962      */
   1963     WORD32 i4_init_done;
   1964 
   1965     /**
   1966      * Process status: one byte per MB
   1967      */
   1968     UWORD8 *pu1_proc_map;
   1969 
   1970     /**
   1971      * Deblk status: one byte per MB
   1972      */
   1973     UWORD8 *pu1_deblk_map;
   1974 
   1975     /**
   1976      * Process status: one byte per MB
   1977      */
   1978     UWORD8 *pu1_me_map;
   1979 
   1980     /*
   1981      * Intra refresh mask.
   1982      * Indicates if an Mb is coded in intra mode within the current AIR interval
   1983      * NOTE Refreshes after each AIR period
   1984      * NOTE The map is shared between process
   1985      */
   1986     UWORD8 *pu1_is_intra_coded;
   1987 
   1988     /**
   1989      * Disable deblock level (0: Enable completely, 3: Disable completely
   1990      */
   1991     UWORD32 u4_disable_deblock_level;
   1992 
   1993     /**
   1994      * Pointer to the structure that contains deblock context
   1995      */
   1996     deblk_ctxt_t s_deblk_ctxt;
   1997 
   1998     /**
   1999      * Points to the array of slice indices which is used to identify the independent
   2000      * slice to which each MB in a frame belongs.
   2001      */
   2002     UWORD8 *pu1_slice_idx;
   2003 
   2004     /**
   2005      * Pointer to base of slice header structure array
   2006      */
   2007     slice_header_t *ps_slice_hdr_base;
   2008 
   2009     /**
   2010      * Number of mb's to process in one loop
   2011      */
   2012     WORD32 i4_nmb_ntrpy;
   2013 
   2014     /**
   2015      * Number of mb's to process in one loop
   2016      */
   2017     UWORD32 u4_nmb_me;
   2018 
   2019     /**
   2020      * Structure for current input buffer
   2021      */
   2022     inp_buf_t s_inp_buf;
   2023 
   2024     /**
   2025      * api call cnt
   2026      */
   2027     WORD32 i4_encode_api_call_cnt;
   2028 
   2029     /**
   2030      * Current Picture count - used for synchronization
   2031      */
   2032     WORD32 i4_pic_cnt;
   2033 
   2034     /**
   2035       * Intermediate buffer for interpred leaf level functions
   2036       */
   2037     WORD32 ai16_pred1[HP_BUFF_WD * HP_BUFF_HT];
   2038 
   2039     /**
   2040      * Reference picture for the current picture
   2041      * TODO: Only 2 reference assumed currently
   2042      */
   2043     pic_buf_t *aps_ref_pic[MAX_REF_PIC_CNT];
   2044 
   2045     /**
   2046      * Reference MV buff for the current picture
   2047      */
   2048     mv_buf_t *aps_mv_buf[MAX_REF_PIC_CNT];
   2049 
   2050     /**
   2051      * frame info used by RC
   2052      */
   2053     frame_info_t s_frame_info;
   2054 
   2055     /*
   2056      * NOTE NOT PERSISTANT INSIDE FUNCTIONS
   2057      * Min sad for current MB
   2058      * will be populated initially
   2059      * Once a sad less than eq to u4_min_sad is reached, the value will be copied to the cariable
   2060      */
   2061     UWORD32  u4_min_sad;
   2062 
   2063     /*
   2064      * indicates weather we have rached minimum sa or not
   2065      */
   2066     UWORD32 u4_min_sad_reached;
   2067 
   2068     /**
   2069      * Current error code
   2070      */
   2071     WORD32 i4_error_code;
   2072 
   2073     /*
   2074      * Enables or disables computation of recon
   2075      */
   2076     UWORD32 u4_compute_recon;
   2077 
   2078     /*
   2079      * Temporary buffers to be used for subpel computation
   2080      */
   2081     UWORD8 *apu1_subpel_buffs[SUBPEL_BUFF_CNT];
   2082 
   2083     /*
   2084      * Buffer holding best sub pel values
   2085      */
   2086     UWORD8 *pu1_best_subpel_buf;
   2087 
   2088     /*
   2089      * Stride for buffer holding best sub pel
   2090      */
   2091     UWORD32 u4_bst_spel_buf_strd;
   2092 
   2093 };
   2094 
   2095 /**
   2096  ******************************************************************************
   2097  *  @brief      Rate control related variables
   2098  ******************************************************************************
   2099  */
   2100 typedef struct
   2101 {
   2102     void *pps_rate_control_api;
   2103 
   2104     void *pps_frame_time;
   2105 
   2106     void *pps_time_stamp;
   2107 
   2108     void *pps_pd_frm_rate;
   2109 
   2110     /**
   2111      * frame rate pull down
   2112      */
   2113     WORD32 pre_encode_skip[MAX_CTXT_SETS];
   2114 
   2115     /**
   2116      * skip frame (cbr)
   2117      */
   2118     WORD32 post_encode_skip[MAX_CTXT_SETS];
   2119 
   2120     /**
   2121      * rate control type
   2122      */
   2123     rc_type_e e_rc_type;
   2124 
   2125     /**
   2126      * pic type
   2127      */
   2128     picture_type_e e_pic_type;
   2129 
   2130     /**
   2131      * intra cnt in previous frame
   2132      */
   2133     WORD32 num_intra_in_prev_frame;
   2134 
   2135     /**
   2136      * avg activity of prev frame
   2137      */
   2138     WORD32 i4_avg_activity;
   2139 
   2140 }rate_control_ctxt_t;
   2141 
   2142 /**
   2143  * Codec context
   2144  */
   2145 struct _codec_t
   2146 {
   2147     /**
   2148      * Id of current pic (input order)
   2149      */
   2150     WORD32 i4_poc;
   2151 
   2152     /**
   2153      * Number of encode frame API calls made
   2154      * This variable must only be used for context selection [Read only]
   2155      */
   2156     WORD32 i4_encode_api_call_cnt;
   2157 
   2158     /**
   2159      * Number of pictures encoded
   2160      */
   2161     WORD32 i4_pic_cnt;
   2162 
   2163     /**
   2164      * Number of threads created
   2165      */
   2166     WORD32 i4_proc_thread_cnt;
   2167 
   2168     /**
   2169      * Mutex used to keep the control calls thread-safe
   2170      */
   2171     void *pv_ctl_mutex;
   2172 
   2173     /**
   2174      * Current active config parameters
   2175      */
   2176     cfg_params_t s_cfg;
   2177 
   2178     /**
   2179      * Array containing the config parameter sets
   2180      */
   2181     cfg_params_t as_cfg[MAX_ACTIVE_CONFIG_PARAMS];
   2182 
   2183     /**
   2184      * Color format used by encoder internally
   2185      */
   2186     IV_COLOR_FORMAT_T e_codec_color_format;
   2187 
   2188     /**
   2189      * recon stride
   2190      * (strides for luma and chroma are the same)
   2191      */
   2192     WORD32 i4_rec_strd;
   2193 
   2194     /**
   2195      * Flag to enable/disable deblocking of a frame
   2196      */
   2197     WORD32 i4_disable_deblk_pic;
   2198 
   2199     /**
   2200      * Number of continuous frames where deblocking was disabled
   2201      */
   2202     WORD32 i4_disable_deblk_pic_cnt;
   2203 
   2204     /**
   2205      * frame type
   2206      */
   2207     PIC_TYPE_T pic_type;
   2208 
   2209     /**
   2210      * frame qp
   2211      */
   2212     UWORD32 u4_frame_qp;
   2213 
   2214     /**
   2215      * frame num
   2216      */
   2217     WORD32 i4_frame_num;
   2218 
   2219     /**
   2220      *  slice_type
   2221      */
   2222     WORD32  i4_slice_type;
   2223 
   2224     /*
   2225      * Force current frame to specific type
   2226      */
   2227     IV_PICTURE_CODING_TYPE_T force_curr_frame_type;
   2228 
   2229     /**
   2230      *  IDR pic
   2231      */
   2232     UWORD32 u4_is_idr;
   2233 
   2234     /**
   2235      *  idr_pic_id
   2236      */
   2237     WORD32 i4_idr_pic_id;
   2238 
   2239     /**
   2240      * Flush mode
   2241      */
   2242     WORD32 i4_flush_mode;
   2243 
   2244     /**
   2245      * Encode header mode
   2246      */
   2247     WORD32 i4_header_mode;
   2248 
   2249     /**
   2250      * Flag to indicate if header has already
   2251      * been generated when i4_api_call_cnt 0
   2252      */
   2253     UWORD32 u4_header_generated;
   2254 
   2255     /**
   2256      * Encode generate header
   2257      */
   2258     WORD32 i4_gen_header;
   2259 
   2260     /**
   2261      * To signal successful completion of init
   2262      */
   2263     WORD32 i4_init_done;
   2264 
   2265     /**
   2266      * To signal that at least one picture was decoded
   2267      */
   2268     WORD32 i4_first_pic_done;
   2269 
   2270     /**
   2271      * Reset flag - Codec is reset if this flag is set
   2272      */
   2273     WORD32 i4_reset_flag;
   2274 
   2275     /**
   2276      * Current error code
   2277      */
   2278     WORD32 i4_error_code;
   2279 
   2280     /**
   2281      * threshold residue
   2282      */
   2283     WORD32 u4_thres_resi;
   2284 
   2285     /**
   2286      * disable intra inter gating
   2287      */
   2288     UWORD32 u4_inter_gate;
   2289 
   2290     /**
   2291      * Holds mem records passed during init.
   2292      * This will be used to return the mem records during retrieve call
   2293      */
   2294     iv_mem_rec_t *ps_mem_rec_backup;
   2295 
   2296     /**
   2297      * Flag to determine if the entropy thread is active
   2298      */
   2299     volatile UWORD32 au4_entropy_thread_active[MAX_CTXT_SETS];
   2300 
   2301     /**
   2302      * Mutex used to keep the entropy calls thread-safe
   2303      */
   2304     void *pv_entropy_mutex;
   2305 
   2306     /**
   2307      * Job queue buffer base
   2308      */
   2309     void *pv_proc_jobq_buf, *pv_entropy_jobq_buf;
   2310 
   2311     /**
   2312      * Job Queue mem tab size
   2313      */
   2314     WORD32 i4_proc_jobq_buf_size, i4_entropy_jobq_buf_size;
   2315 
   2316     /**
   2317      * Memory for MV Bank buffer manager
   2318      */
   2319     void *pv_mv_buf_mgr_base;
   2320 
   2321     /**
   2322      * MV Bank buffer manager
   2323      */
   2324     void *pv_mv_buf_mgr;
   2325 
   2326     /**
   2327      * Pointer to MV Buf structure array
   2328      */
   2329     void *ps_mv_buf;
   2330 
   2331     /**
   2332      * Base address for Motion Vector bank buffer
   2333      */
   2334     void *pv_mv_bank_buf_base;
   2335 
   2336     /**
   2337      * MV Bank size allocated
   2338      */
   2339     WORD32 i4_total_mv_bank_size;
   2340 
   2341     /**
   2342      * Memory for Picture buffer manager for reference pictures
   2343      */
   2344     void *pv_ref_buf_mgr_base;
   2345 
   2346     /**
   2347      * Picture buffer manager for reference pictures
   2348      */
   2349     void *pv_ref_buf_mgr;
   2350 
   2351     /**
   2352      * Number of reference buffers added to the buffer manager
   2353      */
   2354     WORD32 i4_ref_buf_cnt;
   2355 
   2356     /**
   2357      * Pointer to Pic Buf structure array
   2358      */
   2359     void *ps_pic_buf;
   2360 
   2361     /**
   2362      * Base address for Picture buffer
   2363      */
   2364     void *pv_pic_buf_base;
   2365 
   2366     /**
   2367      * Total pic buffer size allocated
   2368      */
   2369     WORD32 i4_total_pic_buf_size;
   2370 
   2371     /**
   2372      * Memory for Buffer manager for output buffers
   2373      */
   2374      void *pv_out_buf_mgr_base;
   2375 
   2376     /**
   2377      * Buffer manager for output buffers
   2378      */
   2379      void *pv_out_buf_mgr;
   2380 
   2381     /**
   2382      * Current output buffer's buffer ID
   2383      */
   2384     WORD32 i4_out_buf_id;
   2385 
   2386     /**
   2387      * Number of output buffers added to the buffer manager
   2388      */
   2389     WORD32 i4_out_buf_cnt;
   2390 
   2391     /**
   2392      * Memory for Picture buffer manager for input buffers
   2393      */
   2394      void *pv_inp_buf_mgr_base;
   2395 
   2396     /**
   2397      * Picture buffer manager for input buffers
   2398      */
   2399      void *pv_inp_buf_mgr;
   2400 
   2401     /**
   2402      * Current input buffer's buffer ID
   2403      */
   2404     WORD32 i4_inp_buf_id;
   2405 
   2406     /**
   2407      * Number of input buffers added to the buffer manager
   2408      */
   2409     WORD32 i4_inp_buf_cnt;
   2410 
   2411     /**
   2412      * Current input buffer
   2413      */
   2414     pic_buf_t *ps_inp_buf;
   2415 
   2416     /**
   2417      * Pointer to dpb manager structure
   2418      */
   2419     void *pv_dpb_mgr;
   2420 
   2421     /**
   2422      * Pointer to base of Sequence parameter set structure array
   2423      */
   2424     sps_t *ps_sps_base;
   2425 
   2426     /**
   2427      * Pointer to base of Picture parameter set structure array
   2428      */
   2429     pps_t *ps_pps_base;
   2430 
   2431     /**
   2432      *  seq_parameter_set_id
   2433      */
   2434     WORD32 i4_sps_id;
   2435 
   2436     /**
   2437      *  pic_parameter_set_id
   2438      */
   2439     WORD32 i4_pps_id;
   2440 
   2441     /**
   2442      * Pointer to base of slice header structure array
   2443      */
   2444     slice_header_t *ps_slice_hdr_base;
   2445 
   2446     /**
   2447      * packed residue coeff data size for 1 row of mbs
   2448      */
   2449     UWORD32 u4_size_coeff_data;
   2450 
   2451     /**
   2452      * packed header data size for 1 row of mbs
   2453      */
   2454     UWORD32 u4_size_header_data;
   2455 
   2456     /**
   2457      * Processing context - One for each processing thread
   2458      * Create two sets, each set used for alternate frames
   2459      */
   2460     process_ctxt_t as_process[MAX_PROCESS_CTXT];
   2461 
   2462     /**
   2463      * Thread handle for each of the processing threads
   2464      */
   2465     void *apv_proc_thread_handle[MAX_PROCESS_THREADS];
   2466 
   2467     /**
   2468      * Thread created flag for each of the processing threads
   2469      */
   2470     WORD32 ai4_process_thread_created[MAX_PROCESS_THREADS];
   2471 
   2472     /**
   2473      * Void pointer to process job context
   2474      */
   2475     void *pv_proc_jobq, *pv_entropy_jobq;
   2476 
   2477     /**
   2478      * Number of MBs processed together for better instruction cache handling
   2479      */
   2480     WORD32 i4_proc_nmb;
   2481 
   2482     /**
   2483      * Previous POC lsb
   2484      */
   2485     WORD32 i4_prev_poc_lsb;
   2486 
   2487     /**
   2488      * Previous POC msb
   2489      */
   2490     WORD32 i4_prev_poc_msb;
   2491 
   2492     /**
   2493      * Max POC lsb that has arrived till now
   2494      */
   2495     WORD32 i4_max_prev_poc_lsb;
   2496 
   2497     /**
   2498      * Context for format conversion
   2499      */
   2500     fmt_conv_t s_fmt_conv;
   2501 
   2502     /**
   2503      * Absolute pic order count
   2504      */
   2505     WORD32 i4_abs_pic_order_cnt;
   2506 
   2507     /**
   2508      *  Pic order count of lsb
   2509      */
   2510     WORD32 i4_pic_order_cnt_lsb;
   2511 
   2512     /**
   2513      * Array giving current picture being processed in each context set
   2514      */
   2515     WORD32 ai4_pic_cnt[MAX_CTXT_SETS];
   2516 
   2517     /*
   2518      * Min sad to search for
   2519      */
   2520     UWORD32 u4_min_sad;
   2521 
   2522     /**
   2523      * Reference picture set
   2524      */
   2525     ref_set_t as_ref_set[MAX_DPB_SIZE + MAX_CTXT_SETS];
   2526 
   2527 
   2528     /*
   2529      * Air pic cnt
   2530      * Contains the number of pictures that have been encoded with air
   2531      * This value is moudulo air refresh period
   2532      */
   2533     WORD32 i4_air_pic_cnt;
   2534 
   2535     /*
   2536      * Intra refresh map
   2537      * Stores the frames at which intra refresh should occur for a MB
   2538      */
   2539     UWORD16 *pu2_intr_rfrsh_map;
   2540 
   2541     /*
   2542      * Indicates if the current frame is used as a reference frame
   2543      */
   2544     UWORD32 u4_is_curr_frm_ref;
   2545 
   2546     /*
   2547      * Indicates if there can be non reference frames in the stream
   2548      */
   2549     WORD32 i4_non_ref_frames_in_stream;
   2550 
   2551     /*
   2552      * Memory for color space conversion for luma plane
   2553      */
   2554     UWORD8 *pu1_y_csc_buf_base;
   2555 
   2556     /*
   2557      * Memory for color space conversion foe chroma plane
   2558      */
   2559     UWORD8 *pu1_uv_csc_buf_base;
   2560 
   2561     /**
   2562      * Function pointers for intra pred leaf level functions luma
   2563      */
   2564     pf_intra_pred apf_intra_pred_16_l[MAX_I16x16];
   2565     pf_intra_pred apf_intra_pred_8_l[MAX_I8x8];
   2566     pf_intra_pred apf_intra_pred_4_l[MAX_I4x4];
   2567 
   2568     /**
   2569      * Function pointers for intra pred leaf level functions chroma
   2570      */
   2571     pf_intra_pred apf_intra_pred_c[MAX_CH_I8x8];
   2572 
   2573     /**
   2574      * luma core coding function pointer
   2575      */
   2576     UWORD8 (*luma_energy_compaction[4])(process_ctxt_t *ps_proc);
   2577 
   2578     /**
   2579      * chroma core coding function pointer
   2580      */
   2581     UWORD8 (*chroma_energy_compaction[2])(process_ctxt_t *ps_proc);
   2582 
   2583     /**
   2584      * forward transform for intra blk of mb type 16x16
   2585      */
   2586     ih264_luma_16x16_resi_trans_dctrans_quant_ft *pf_resi_trans_dctrans_quant_16x16;
   2587 
   2588     /**
   2589      * inverse transform for intra blk of mb type 16x16
   2590      */
   2591     ih264_luma_16x16_idctrans_iquant_itrans_recon_ft *pf_idctrans_iquant_itrans_recon_16x16;
   2592 
   2593     /**
   2594      * forward transform for 4x4 blk luma
   2595      */
   2596     ih264_resi_trans_quant_ft *pf_resi_trans_quant_4x4;
   2597 
   2598     /**
   2599      * forward transform for 4x4 blk luma
   2600      */
   2601     ih264_resi_trans_quant_ft *pf_resi_trans_quant_chroma_4x4;
   2602 
   2603     /*
   2604      * hadamard transform and quant for a 4x4 block
   2605      */
   2606     ih264_hadamard_quant_ft *pf_hadamard_quant_4x4;
   2607 
   2608     /*
   2609      *  hadamard transform and quant for a 4x4 block
   2610      */
   2611     ih264_hadamard_quant_ft *pf_hadamard_quant_2x2_uv;
   2612 
   2613     /**
   2614      * inverse transform for 4x4 blk
   2615      */
   2616     ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_4x4;
   2617 
   2618     /**
   2619      * inverse transform for chroma 4x4 blk
   2620      */
   2621     ih264_iquant_itrans_recon_chroma_ft *pf_iquant_itrans_recon_chroma_4x4;
   2622 
   2623     /**
   2624      * inverse transform for 4x4 blk with only single dc coeff
   2625      */
   2626     ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_4x4_dc;
   2627 
   2628     /**
   2629      * inverse transform for chroma 4x4 blk with only single dc coeff
   2630      */
   2631     ih264_iquant_itrans_recon_chroma_ft *pf_iquant_itrans_recon_chroma_4x4_dc;
   2632 
   2633     /*
   2634      * Inverse hadamard transform and iquant for a 4x4 block
   2635      */
   2636     ih264_ihadamard_scaling_ft *pf_ihadamard_scaling_4x4;
   2637 
   2638     /*
   2639      * Inverse hadamard transform and iquant for a 4x4 block
   2640      */
   2641     ih264_ihadamard_scaling_ft *pf_ihadamard_scaling_2x2_uv;
   2642 
   2643     /*
   2644      * Function for interleave copy*
   2645      */
   2646     ih264_interleave_copy_ft *pf_interleave_copy;
   2647 
   2648     /**
   2649      * forward transform for 8x8 blk
   2650      */
   2651     ih264_resi_trans_quant_ft *pf_resi_trans_quant_8x8;
   2652 
   2653     /**
   2654      * inverse transform for 8x8 blk
   2655      */
   2656     /**
   2657      * inverse transform for 4x4 blk
   2658      */
   2659     ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_8x8;
   2660 
   2661     /**
   2662      * forward transform for chroma MB
   2663      */
   2664     ih264_chroma_8x8_resi_trans_dctrans_quant_ft *pf_resi_trans_dctrans_quant_8x8_chroma;
   2665 
   2666     /**
   2667      * inverse transform for chroma MB
   2668      */
   2669     ih264_idctrans_iquant_itrans_recon_ft *pf_idctrans_iquant_itrans_recon_8x8_chroma;
   2670 
   2671     /**
   2672      * deblock vertical luma edge with blocking strength 4
   2673      */
   2674     ih264_deblk_edge_bs4_ft *pf_deblk_luma_vert_bs4;
   2675 
   2676     /**
   2677      * deblock vertical chroma edge with blocking strength 4
   2678      */
   2679     ih264_deblk_chroma_edge_bs4_ft *pf_deblk_chroma_vert_bs4;
   2680 
   2681     /**
   2682      * deblock vertical luma edge with blocking strength less than 4
   2683      */
   2684     ih264_deblk_edge_bslt4_ft *pf_deblk_luma_vert_bslt4;
   2685 
   2686     /**
   2687      * deblock vertical chroma edge with blocking strength less than 4
   2688      */
   2689     ih264_deblk_chroma_edge_bslt4_ft *pf_deblk_chroma_vert_bslt4;
   2690 
   2691     /**
   2692      * deblock horizontal luma edge with blocking strength 4
   2693      */
   2694     ih264_deblk_edge_bs4_ft *pf_deblk_luma_horz_bs4;
   2695 
   2696     /**
   2697      * deblock horizontal chroma edge with blocking strength 4
   2698      */
   2699     ih264_deblk_chroma_edge_bs4_ft *pf_deblk_chroma_horz_bs4;
   2700 
   2701     /**
   2702      * deblock horizontal luma edge with blocking strength less than 4
   2703      */
   2704     ih264_deblk_edge_bslt4_ft *pf_deblk_luma_horz_bslt4;
   2705 
   2706     /**
   2707      * deblock horizontal chroma edge with blocking strength less than 4
   2708      */
   2709     ih264_deblk_chroma_edge_bslt4_ft *pf_deblk_chroma_horz_bslt4;
   2710 
   2711 
   2712     /**
   2713      * functions for padding
   2714      */
   2715     pf_pad pf_pad_top;
   2716     pf_pad pf_pad_bottom;
   2717     pf_pad pf_pad_left_luma;
   2718     pf_pad pf_pad_left_chroma;
   2719     pf_pad pf_pad_right_luma;
   2720     pf_pad pf_pad_right_chroma;
   2721 
   2722     /**
   2723      * Inter pred leaf level functions
   2724      */
   2725     ih264_inter_pred_luma_ft    *pf_inter_pred_luma_copy;
   2726     ih264_inter_pred_luma_ft    *pf_inter_pred_luma_horz;
   2727     ih264_inter_pred_luma_ft    *pf_inter_pred_luma_vert;
   2728     pf_inter_pred_luma_bilinear  pf_inter_pred_luma_bilinear;
   2729     ih264_inter_pred_chroma_ft  *pf_inter_pred_chroma;
   2730 
   2731     /**
   2732      * fn ptrs for compute sad routines
   2733      */
   2734     ime_compute_sad_ft *apf_compute_sad_16x16[2];
   2735     ime_compute_sad_ft *pf_compute_sad_16x8;
   2736 
   2737 
   2738     /**
   2739      * Function pointer for computing ME
   2740      * 1 for PSLICE and 1 for BSLICE
   2741      */
   2742     ih264e_compute_me_ft *apf_compute_me[2];
   2743 
   2744     /**
   2745      * Function pointers for computing SKIP parameters
   2746      */
   2747     ih264e_skip_params_ft *apf_find_skip_params_me[2];
   2748 
   2749     /**
   2750      * fn ptrs for memory handling operations
   2751      */
   2752     pf_memcpy pf_mem_cpy;
   2753     pf_memset pf_mem_set;
   2754     pf_memcpy_mul8 pf_mem_cpy_mul8;
   2755     pf_memset_mul8 pf_mem_set_mul8;
   2756 
   2757     /**
   2758      * intra mode eval -encoder level function
   2759      */
   2760     pf_evaluate_intra_modes pf_ih264e_evaluate_intra16x16_modes;
   2761     pf_evaluate_intra_modes pf_ih264e_evaluate_intra_chroma_modes;
   2762     pf_evaluate_intra_4x4_modes pf_ih264e_evaluate_intra_4x4_modes;
   2763 
   2764     /* Half pel generation function - encoder level
   2765      *
   2766      */
   2767     pf_sixtapfilter_horz pf_ih264e_sixtapfilter_horz;
   2768     pf_sixtap_filter_2dvh_vert pf_ih264e_sixtap_filter_2dvh_vert;
   2769 
   2770     /**
   2771      * color space conversion form YUV 420P to YUV 420Sp
   2772      */
   2773     pf_fmt_conv_420p_to_420sp pf_ih264e_conv_420p_to_420sp;
   2774 
   2775 
   2776     /**
   2777      * color space conversion form YUV 420P to YUV 420Sp
   2778      */
   2779     pf_fmt_conv_422ile_to_420sp pf_ih264e_fmt_conv_422i_to_420sp;
   2780 
   2781     /**
   2782      * write mb layer for a given slice I, P, B
   2783      */
   2784     IH264E_ERROR_T (*pf_write_mb_syntax_layer[2][3]) ( entropy_ctxt_t *ps_ent_ctxt );
   2785 
   2786     /**
   2787      * Output buffer
   2788      */
   2789     out_buf_t as_out_buf[MAX_CTXT_SETS];
   2790 
   2791     /**
   2792      * recon buffer
   2793      */
   2794     rec_buf_t as_rec_buf[MAX_CTXT_SETS];
   2795 
   2796     /**
   2797      * rate control context
   2798      */
   2799     rate_control_ctxt_t s_rate_control;
   2800 
   2801     /**
   2802      * input buffer queue
   2803      */
   2804     inp_buf_t as_inp_list[MAX_NUM_BFRAMES];
   2805 
   2806     /**
   2807      * Flag to indicate if any IDR requests are pending
   2808      */
   2809     WORD32 i4_pending_idr_flag;
   2810 
   2811     /*
   2812     *Flag to indicate if we have recived the last input frame
   2813     */
   2814     WORD32 i4_last_inp_buff_received;
   2815 
   2816 };
   2817 
   2818 #endif /* IH264E_STRUCTS_H_ */
   2819