lin
2025-01-04 be45768b193281917003531c55e9ebda9d2c2f99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
/******************************************************************************
 *
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
/*!
******************************************************************************
* \file ihevce_ipe_structs.h
*
* \brief
*    This file contains strcutures of ipe pass
*
* \date
*    18/09/2012
*
* \author
*    Ittiam
*
******************************************************************************
*/
 
#ifndef _IHEVCE_IPE_STRUCTS_H_
#define _IHEVCE_IPE_STRUCTS_H_
 
/*****************************************************************************/
/* Constant Macros                                                           */
/*****************************************************************************/
#define MAX_FAST_IP_MODES 23
#define NUM_INTRA_RDOPT_MODES 1
#if 1  // FAST_PART_WITH_OPTION_4
#define MAX_TREE_NODES                                                                             \
    ((MAX_CTB_SIZE == MIN_TU_SIZE)                                                                 \
         ? 1                                                                                       \
         : (MAX_CTB_SIZE == (MIN_TU_SIZE << 1)                                                     \
                ? 5                                                                                \
                : (MAX_CTB_SIZE == (MIN_TU_SIZE << 2)                                              \
                       ? 21                                                                        \
                       : (MAX_CTB_SIZE == (MIN_TU_SIZE << 3) ? 37 : 53))))
#else  // FAST_PART_WITH_OPTION_4
#define MAX_TREE_NODES                                                                             \
    ((MAX_CTB_SIZE == MIN_TU_SIZE)                                                                 \
         ? 1                                                                                       \
         : (MAX_CTB_SIZE == (MIN_TU_SIZE << 1)                                                     \
                ? 5                                                                                \
                : (MAX_CTB_SIZE == (MIN_TU_SIZE << 2)                                              \
                       ? 9                                                                         \
                       : (MAX_CTB_SIZE == (MIN_TU_SIZE << 3) ? 13 : 17))))
#endif  // FAST_PART_WITH_OPTION_4
#define BOTTOM_LEFT_FLAG 0x0000000F
#define LEFT_FLAG 0x000000F0
#define TOP_LEFT_FLAG 0x00010000
#define TOP_FLAG 0x00000F00
#define TOP_RIGHT_FLAG 0x0000F000
#define MAX_UWORD8 0xFF
#define MAX_DOUBLE 1.7e+308  ///< max. value of double-type value
#define MAX_INTRA_COST_IPE 0x0F7F7F7F
 
#define MAX_TU_ROW_IN_CTB (MAX_CTB_SIZE >> 2)
#define MAX_TU_COL_IN_CTB (MAX_CTB_SIZE >> 2)
 
#define BIT_DEPTH 8
 
#define FAST_PARTITION_WITH_TRANSFORM 1
 
#define IHEVCE_INTRA_REF_FILTERING C
#define IHEVCE_INTRA_LUMA_REF_SUBSTITUTION C
/*****************************************************************************/
/* Constant Macros                                                           */
/*****************************************************************************/
/** /breif 4x4 DST, 4x4, 8x8, 16x16, 32x32 */
#define NUM_TRANS_TYPES 5
#define INTRA_PLANAR 0
#define INTRA_DC 1
 
/*****************************************************************************/
/* Function Macros                                                           */
/*****************************************************************************/
#define INTRA_ANGULAR(x) (x)
 
/** @breif max 30bit value */
#define MAX30 ((1 << 30) - 1)
 
/* @bried macro to clip a data to max of 30bits (assuming unsgined) */
#define CLIP30(x) ((x) > MAX30 ? MAX30 : (x))
 
/* @bried compute the (lambda * rate) with a qshift and clip result to 30bits */
#define COMPUTE_RATE_COST_CLIP30(r, l, qshift) ((WORD32)CLIP30((ULWORD64)((r) * (l)) >> (qshift)))
 
/*****************************************************************************/
/* Typedefs                                                                  */
/*****************************************************************************/
typedef UWORD32 (*pf_res_trans_luma_had)(
    UWORD8 *pu1_origin,
    WORD32 src_strd,
    UWORD8 *pu1_pred_buf,
    WORD32 pred_strd,
    WORD16 *pi2_dst,
    WORD32 dst_strd,
    WORD32 size);
 
typedef void (*pf_ipe_intra_pred)(
    UWORD8 *pu1_ref, WORD32 src_strd, UWORD8 *pu1_dst, WORD32 dst_strd, WORD32 nt, WORD32 mode);
 
typedef UWORD32 (*pf_ipe_res_trans)(
    UWORD8 *pu1_src,
    UWORD8 *pu1_pred,
    WORD16 *pi2_tmp,
    WORD16 *pi2_dst,
    WORD32 src_strd,
    WORD32 pred_strd,
    WORD32 dst_strd,
    WORD32 chroma_flag);
 
typedef FT_CALC_HAD_SATD_8BIT *pf_ipe_res_trans_had;
/*****************************************************************************/
/* Enums                                                                     */
/*****************************************************************************/
 
typedef enum
{
 
    IPE_CTXT = 0,
    IPE_THRDS_CTXT,
 
    /* should be last entry */
    NUM_IPE_MEM_RECS
 
} IPE_MEM_TABS_T;
 
typedef enum
{
    IPE_FUNC_MODE_0 = 0,
    IPE_FUNC_MODE_1,
    IPE_FUNC_MODE_2,
    IPE_FUNC_MODE_3TO9,
    IPE_FUNC_MODE_10,
    IPE_FUNC_MODE_11TO17,
    IPE_FUNC_MODE_18_34,
    IPE_FUNC_MODE_19TO25,
    IPE_FUNC_MODE_26,
    IPE_FUNC_MODE_27TO33,
 
    NUM_IPE_FUNCS
 
} IPE_FUNCS_T;
 
/*****************************************************************************/
/* Structure                                                                 */
/*****************************************************************************/
/**
******************************************************************************
 *  @brief    IPE CTB to CU and TU Quadtree Recursive Structure
******************************************************************************
 */
 
typedef struct ihevce_ipe_cu_tree_t ihevce_ipe_cu_tree_t;
 
typedef struct ihevce_ipe_cu_tree_t
{
    /**
     * Origin of current coding unit relative to top-left of CTB
     */
    UWORD16 u2_x0;
 
    UWORD16 u2_y0;
 
    /**
     * Origin of current coding unit relative to top-left of Picture
     */
    UWORD16 u2_orig_x;
 
    UWORD16 u2_orig_y;
 
    /**
     * Size of current coding unit in luma pixels
     */
    UWORD8 u1_cu_size;
 
    UWORD8 u1_width;
 
    UWORD8 u1_height;
 
    UWORD8 u1_depth;
 
    UWORD8 u1_part_flag_pos;
 
    UWORD8 u1_log2_nt;
 
    WORD32 i4_nbr_flag;
 
    /**
     * Recursive Bracketing Parameters
     */
    UWORD8 best_mode;
 
    WORD32 best_satd;
 
    WORD32 best_cost;
 
    /**
     * Number of pixels available in these neighbors
     */
    UWORD8 u1_num_left_avail;
 
    UWORD8 u1_num_top_avail;
 
    UWORD8 u1_num_top_right_avail;
 
    UWORD8 u1_num_bottom_left_avail;
 
    UWORD8 au1_best_mode_1tu[NUM_BEST_MODES];
 
    WORD32 au4_best_cost_1tu[NUM_BEST_MODES];
 
    UWORD8 au1_best_mode_4tu[NUM_BEST_MODES];
 
    WORD32 au4_best_cost_4tu[NUM_BEST_MODES];
 
    ihevce_ipe_cu_tree_t *ps_parent;
 
    ihevce_ipe_cu_tree_t *ps_sub_cu[4];
 
    /* best mode bits cost */
    UWORD16 u2_mode_bits_cost;
 
} ihevce_ipe_cu_tree_node_t;
 
/**
******************************************************************************
 *  @brief    IPE module context memory
******************************************************************************
 */
typedef struct
{
    ihevce_ipe_cu_tree_t *ps_ipe_cu_tree;
 
    /* one parent and four children */
    ihevce_ipe_cu_tree_t as_ipe_cu_tree[5];
 
    UWORD8 au1_ctb_mode_map[MAX_TU_ROW_IN_CTB + 1][MAX_TU_COL_IN_CTB + 1];
 
    UWORD8 au1_cand_mode_list[3];
 
    /** Pointer to structure containing function pointers of common*/
    func_selector_t *ps_func_selector;
 
    /**
     * CU level Qp / 6
     */
    WORD32 i4_cu_qp_div6;
 
    /**
     * CU level Qp % 6
     */
    WORD32 i4_cu_qp_mod6;
 
    /** array of luma intra prediction function pointers */
    pf_ipe_intra_pred apf_ipe_lum_ip[NUM_IPE_FUNCS];
 
    /** array of function pointers for residual and
     *  forward transform for all transform sizes
     */
    pf_res_trans_luma apf_resd_trns[NUM_TRANS_TYPES];
 
    /** array of function pointers for residual and
     *  forward transform for all transform sizes
     */
    pf_res_trans_luma_had apf_resd_trns_had[NUM_TRANS_TYPES];
 
    /** array of pointer to store the scaling matrices for
     *  all transform sizes and qp % 6 (pre computed)
     */
    WORD16 *api2_scal_mat[NUM_TRANS_TYPES * 2];
 
    /** array of pointer to store the re-scaling matrices for
     *  all transform sizes and qp % 6 (pre computed)
     */
    WORD16 *api2_rescal_mat[NUM_TRANS_TYPES * 2];
 
    /** Qunatization rounding factor for inter and intra CUs */
    WORD32 i4_quant_rnd_factor[2];
 
    UWORD8 u1_ctb_size;
 
    UWORD8 u1_min_cu_size;
 
    UWORD8 u1_min_tu_size;
 
    UWORD16 u2_ctb_row_num;
 
    UWORD16 u2_ctb_num_in_row;
 
    WORD8 i1_QP;
 
    UWORD8 u1_num_b_frames;
 
    UWORD8 b_sad_type;
 
    UWORD8 u1_ipe_step_size;
 
    WORD32 i4_ol_satd_lambda;
 
    WORD32 i4_ol_sad_lambda;
 
    UWORD8 au1_nbr_ctb_map[MAX_PU_IN_CTB_ROW + 1 + 8][MAX_PU_IN_CTB_ROW + 1 + 8];
 
    /**
     * Pointer to (1,1) location in au1_nbr_ctb_map
     */
    UWORD8 *pu1_ctb_nbr_map;
 
    /**
     * neigbour map buffer stride;
     */
    WORD32 i4_nbr_map_strd;
 
    /** CTB neighbour availability flags */
    nbr_avail_flags_t s_ctb_nbr_avail_flags;
 
    /** Slice Type of the current picture being processed */
    WORD32 i4_slice_type;
 
    /** Temporal ID of the current picture being processed */
    WORD32 i4_temporal_lyr_id;
 
    WORD32 i4_ol_sad_lambda_qf_array[MAX_HEVC_QP_10bit + 1];
    WORD32 i4_ol_satd_lambda_qf_array[MAX_HEVC_QP_10bit + 1];
 
    /************************************************************************/
    /* The fields with the string 'type2' in their names are required */
    /* when both 8bit and hbd lambdas are needed. The lambdas corresponding */
    /* to the bit_depth != internal_bit_depth are stored in these fields */
    /************************************************************************/
    WORD32 i4_ol_sad_type2_lambda_qf_array[MAX_HEVC_QP_10bit + 1];
    WORD32 i4_ol_satd_type2_lambda_qf_array[MAX_HEVC_QP_10bit + 1];
 
    /*Store the HEVC frame level qp for level modulation*/
    WORD32 i4_hevc_qp;
    /*Store the frame level qscale for level modulation*/
    WORD32 i4_qscale;
#if POW_OPT
    /* Averge activity of 8x8 blocks from previous frame
    *  If L1, maps to 16*16 in L0
    */
    long double ld_curr_frame_8x8_log_avg[2];
 
    /* Averge activity of 16x16 blocks from previous frame
    *  If L1, maps to 32*32 in L0
    */
    long double ld_curr_frame_16x16_log_avg[3];
 
    /* Averge activity of 32x32 blocks from previous frame
    *  If L1, maps to 64*64 in L0
    */
    long double ld_curr_frame_32x32_log_avg[3];
#else
    /* Averge activity of 8x8 blocks from previous frame
    *  If L1, maps to 16*16 in L0
    */
    LWORD64 i8_curr_frame_8x8_avg_act[2];
 
    /* Averge activity of 16x16 blocks from previous frame
    *  If L1, maps to 32*32 in L0
    */
    LWORD64 i8_curr_frame_16x16_avg_act[3];
 
    /* Averge activity of 32x32 blocks from previous frame
    *  If L1, maps to 64*64 in L0
    */
    LWORD64 i8_curr_frame_32x32_avg_act[3];
#endif
    /** Frame-levelSATD cost accumalator */
    LWORD64 i8_frame_acc_satd_cost;
 
    /** Frame-levelSATD accumalator */
    LWORD64 i8_frame_acc_satd;
 
    /** Frame-level activity factor for CU 8x8 accumalator */
    LWORD64 i8_frame_acc_act_factor;
 
    /** Frame-level Mode Bits cost accumalator */
    LWORD64 i8_frame_acc_mode_bits_cost;
 
    /** Encoder quality preset : See IHEVCE_QUALITY_CONFIG_T for presets */
    WORD32 i4_quality_preset;
 
    /** Frame-level SATD/qp accumulator in q10 format*/
    LWORD64 i8_frame_acc_satd_by_modqp_q10;
 
    /** For testing EIID only. */
    UWORD32 u4_num_16x16_skips_at_L0_IPE;
 
    /** Reference sample array. Used as local variable in mode_eval_filtering  */
    UWORD8 au1_ref_samples[1028];
    /** filtered reference sample array. Used as local variable in mode_eval_filtering */
    UWORD8 au1_filt_ref_samples[1028];
    /** array for the modes to be evaluated. Used as local variable in mode_eval_filtering */
    UWORD8 au1_modes_to_eval[MAX_NUM_IP_MODES];
    /** temp array for the modes to be evaluated. Used as local variable in mode_eval_filtering */
    UWORD8 au1_modes_to_eval_temp[MAX_NUM_IP_MODES];
    /** pred samples array. Used as local variable in mode_eval_filtering */
    MEM_ALIGN32 UWORD8 au1_pred_samples[4096];
    /** array for storing satd cost. Used as local variable in mode_eval_filtering*/
    UWORD16 au2_mode_bits_satd_cost[MAX_NUM_IP_MODES];
    /** array for storing satd values. used as local variable in mode_eval_filtering */
    UWORD16 au2_mode_bits_satd[MAX_NUM_IP_MODES];
 
    /** reference data, local for pu_calc_8x8 */
    UWORD8 au1_ref_8x8pu[4][18];
    /** mode_bits_cost, local for pu_calc_8x8 */
    UWORD16 au2_mode_bits_cost_8x8pu[4][MAX_NUM_IP_MODES];
    /** mode_bits, local for pu_calc_8x8 */
    UWORD16 au2_mode_bits_8x8_pu[MAX_NUM_IP_MODES];
 
    /** tranform coeff temp, local to ihevce_pu_calc_4x4_blk */
    WORD16 *pi2_trans_tmp;  //this memory is overlayed with au1_pred_samples[4096]. First half.
 
    /** tranform coeff out, local to ihevce_pu_calc_4x4_blk */
    WORD16 *pi2_trans_out;  //this memory is overlayed with au1_pred_samples[4096]. Second half.
 
    UWORD8 u1_use_lambda_derived_from_min_8x8_act_in_ctb;
 
    UWORD8 u1_bit_depth;
 
    rc_quant_t *ps_rc_quant_ctxt;
    /** Flag that specifies whether to use SATD or SAD in L0 IPE */
    UWORD8 u1_use_satd;
 
    /** Flag that specifies level of refinement */
    UWORD8 u1_level_1_refine_on;
 
    /** Flag indicates that child mode decision is disabled in L0 IPE recur bracketing */
    UWORD8 u1_disable_child_cu_decide;
 
    /*Modulation factor*/
    WORD32 ai4_mod_factor_derived_by_variance[2];
    float f_strength;
    WORD32 i4_l0ipe_qp_mod;
 
    WORD32 i4_frm_qp;
    WORD32 i4_temporal_layer;
    WORD32 i4_pass;
 
    double f_i_pic_lamda_modifier;
    WORD32 i4_use_const_lamda_modifier;
    WORD32 i4_is_ref_pic;
    LWORD64 i8_curr_frame_avg_mean_act;
    WORD32 i4_enable_noise_detection;
 
    ihevce_ipe_optimised_function_list_t s_ipe_optimised_function_list;
 
    ihevce_cmn_opt_func_t s_cmn_opt_func;
 
} ihevce_ipe_ctxt_t;
 
/**
******************************************************************************
 *  @brief    IPE module overall context
******************************************************************************
 */
typedef struct
{
    /*array of ipe ctxt */
    ihevce_ipe_ctxt_t *aps_ipe_thrd_ctxt[MAX_NUM_FRM_PROC_THRDS_PRE_ENC];
 
    /** Number of processing threads created run time */
    WORD32 i4_num_proc_thrds;
 
} ihevce_ipe_master_ctxt_t;
 
/*****************************************************************************/
/* Extern Variable Declarations                                              */
/*****************************************************************************/
 
/*****************************************************************************/
/* Extern Function Declarations                                              */
/*****************************************************************************/
void ihevce_ipe_analyse_update_cost(
    ihevce_ipe_cu_tree_t *ps_cu_node, UWORD8 u1_mode, DOUBLE lf_cost);
#endif /* _IHEVCE_IPE_STRUCTS_H_ */