Coverage Report

Created: 2026-08-31 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/encoder/ihevce_enc_cu_recursion.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/**
22
******************************************************************************
23
* \file ihevce_enc_cu_recursion.c
24
*
25
* \brief
26
*    This file contains Encoder normative loop pass related functions
27
*
28
* \date
29
*    18/09/2012
30
*
31
* \author
32
*    Ittiam
33
*
34
*
35
* List of Functions
36
*
37
*
38
******************************************************************************
39
*/
40
41
/*****************************************************************************/
42
/* File Includes                                                             */
43
/*****************************************************************************/
44
/* System include files */
45
#include <stdio.h>
46
#include <string.h>
47
#include <stdlib.h>
48
#include <assert.h>
49
#include <stdarg.h>
50
#include <math.h>
51
52
/* User include files */
53
#include "ihevc_typedefs.h"
54
#include "itt_video_api.h"
55
#include "ihevce_api.h"
56
57
#include "rc_cntrl_param.h"
58
#include "rc_frame_info_collector.h"
59
#include "rc_look_ahead_params.h"
60
61
#include "ihevc_defs.h"
62
#include "ihevc_macros.h"
63
#include "ihevc_debug.h"
64
#include "ihevc_structs.h"
65
#include "ihevc_platform_macros.h"
66
#include "ihevc_deblk.h"
67
#include "ihevc_itrans_recon.h"
68
#include "ihevc_chroma_itrans_recon.h"
69
#include "ihevc_chroma_intra_pred.h"
70
#include "ihevc_intra_pred.h"
71
#include "ihevc_inter_pred.h"
72
#include "ihevc_mem_fns.h"
73
#include "ihevc_padding.h"
74
#include "ihevc_weighted_pred.h"
75
#include "ihevc_sao.h"
76
#include "ihevc_resi_trans.h"
77
#include "ihevc_quant_iquant_ssd.h"
78
#include "ihevc_cabac_tables.h"
79
80
#include "ihevce_defs.h"
81
#include "ihevce_hle_interface.h"
82
#include "ihevce_lap_enc_structs.h"
83
#include "ihevce_multi_thrd_structs.h"
84
#include "ihevce_multi_thrd_funcs.h"
85
#include "ihevce_me_common_defs.h"
86
#include "ihevce_had_satd.h"
87
#include "ihevce_error_codes.h"
88
#include "ihevce_bitstream.h"
89
#include "ihevce_cabac.h"
90
#include "ihevce_rdoq_macros.h"
91
#include "ihevce_function_selector.h"
92
#include "ihevce_enc_structs.h"
93
#include "ihevce_entropy_structs.h"
94
#include "ihevce_cmn_utils_instr_set_router.h"
95
#include "ihevce_ipe_instr_set_router.h"
96
#include "ihevce_decomp_pre_intra_structs.h"
97
#include "ihevce_decomp_pre_intra_pass.h"
98
#include "ihevce_enc_loop_structs.h"
99
#include "ihevce_global_tables.h"
100
#include "ihevce_nbr_avail.h"
101
#include "ihevce_enc_loop_utils.h"
102
#include "ihevce_bs_compute_ctb.h"
103
#include "ihevce_cabac_rdo.h"
104
#include "ihevce_dep_mngr_interface.h"
105
#include "ihevce_enc_loop_pass.h"
106
#include "ihevce_rc_enc_structs.h"
107
#include "ihevce_enc_cu_recursion.h"
108
#include "ihevce_stasino_helpers.h"
109
110
#include "cast_types.h"
111
#include "osal.h"
112
#include "osal_defaults.h"
113
114
/*****************************************************************************/
115
/* Macros                                                                    */
116
/*****************************************************************************/
117
0
#define NUM_CTB_QUANT_ROUNDING 6
118
119
/*****************************************************************************/
120
/* Function Definitions                                                      */
121
/*****************************************************************************/
122
123
/**
124
*********************************************************************************
125
* Function name : ihevce_store_cu_final
126
*
127
* \brief
128
*    This function store cu info to the enc loop cu context
129
*
130
* \param[in] ps_ctxt : pointer to enc loop context structure
131
* \param[in] ps_cu_final  : pointer to enc loop output CU structure
132
* \param[in] pu1_ecd_data : ecd data pointer
133
* \param[in] ps_enc_out_ctxt : pointer to CU information structure
134
* \param[in] ps_cu_prms : pointer to  cu level parameters for SATD / RDOPT
135
*
136
* \return
137
*    None
138
*
139
**********************************************************************************/
140
void ihevce_store_cu_final(
141
    ihevce_enc_loop_ctxt_t *ps_ctxt,
142
    cu_enc_loop_out_t *ps_cu_final,
143
    UWORD8 *pu1_ecd_data,
144
    ihevce_enc_cu_node_ctxt_t *ps_enc_out_ctxt,
145
    enc_loop_cu_prms_t *ps_cu_prms)
146
280k
{
147
280k
    enc_loop_cu_final_prms_t *ps_enc_loop_bestprms;
148
280k
    WORD32 i4_8x8_blks_in_cu;
149
280k
    WORD32 i4_br_id, i4_enc_frm_id;
150
151
280k
    WORD32 u4_tex_bits, u4_hdr_bits;
152
280k
    WORD32 i4_qscale, i4_qscale_ctb;
153
280k
    ps_enc_loop_bestprms = ps_enc_out_ctxt->ps_cu_prms;
154
280k
    i4_qscale = ((ps_ctxt->ps_rc_quant_ctxt->pi4_qp_to_qscale
155
280k
                      [ps_enc_out_ctxt->i1_cu_qp + ps_ctxt->ps_rc_quant_ctxt->i1_qp_offset]));
156
280k
    i4_qscale_ctb = ((
157
280k
        ps_ctxt->ps_rc_quant_ctxt
158
280k
            ->pi4_qp_to_qscale[ps_ctxt->i4_frame_mod_qp + ps_ctxt->ps_rc_quant_ctxt->i1_qp_offset]));
159
160
    /* All texture bits accumulated */
161
280k
    u4_tex_bits = ps_enc_loop_bestprms->u4_cu_luma_res_bits +
162
280k
                  ps_enc_loop_bestprms->u4_cu_chroma_res_bits +
163
280k
                  ps_enc_loop_bestprms->u4_cu_cbf_bits;
164
165
280k
    u4_hdr_bits = ps_enc_loop_bestprms->u4_cu_hdr_bits;
166
167
280k
    i4_br_id = ps_ctxt->i4_bitrate_instance_num;
168
280k
    i4_enc_frm_id = ps_ctxt->i4_enc_frm_id;
169
170
280k
    i4_8x8_blks_in_cu = ((ps_enc_out_ctxt->u1_cu_size >> 3) * (ps_enc_out_ctxt->u1_cu_size >> 3));
171
172
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->i8_frame_open_loop_ssd +=
173
280k
        ps_enc_loop_bestprms
174
280k
            ->i8_cu_ssd;  // + (((float)(ps_ctxt->i8_cl_ssd_lambda_qf/ (1<< LAMBDA_Q_SHIFT))) * ps_enc_loop_bestprms->u4_cu_hdr_bits);
175
176
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->u4_frame_open_loop_intra_sad +=
177
280k
        (UWORD32)(
178
280k
            ps_enc_loop_bestprms->u4_cu_open_intra_sad +
179
280k
            (((float)(ps_ctxt->i4_sad_lamda) / (1 << LAMBDA_Q_SHIFT)) *
180
280k
             ps_enc_loop_bestprms->u4_cu_hdr_bits));
181
182
280k
    if(1 == ps_enc_loop_bestprms->u1_intra_flag)
183
228k
    {
184
228k
        ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->u4_frame_intra_sad_acc +=
185
228k
            ps_enc_loop_bestprms->u4_cu_sad;
186
228k
        ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->i8_frame_intra_cost_acc +=
187
228k
            ps_enc_loop_bestprms->i8_best_rdopt_cost;
188
228k
    }
189
52.3k
    else
190
52.3k
    {
191
52.3k
        ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->u4_frame_inter_sad_acc +=
192
52.3k
            ps_enc_loop_bestprms->u4_cu_sad;
193
52.3k
        ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->i8_frame_inter_cost_acc +=
194
52.3k
            ps_enc_loop_bestprms->i8_best_rdopt_cost;
195
52.3k
    }
196
    /*accumulating the frame level stats across frame*/
197
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->u4_frame_sad_acc +=
198
280k
        ps_enc_loop_bestprms->u4_cu_sad;
199
200
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->i8_frame_cost_acc +=
201
280k
        ps_enc_loop_bestprms->i8_best_rdopt_cost;
202
203
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->u4_frame_rdopt_bits +=
204
280k
        (u4_tex_bits + u4_hdr_bits);
205
206
    /*Total bits and header bits accumalted here for CTB*/
207
280k
    ps_ctxt->u4_total_cu_bits += (u4_tex_bits + u4_hdr_bits);
208
280k
    ps_ctxt->u4_total_cu_bits_mul_qs +=
209
280k
        ((ULWORD64)((u4_tex_bits + u4_hdr_bits) * (i4_qscale_ctb)) + (1 << (QSCALE_Q_FAC_3 - 1))) >>
210
280k
        QSCALE_Q_FAC_3;
211
280k
    ps_ctxt->u4_total_cu_hdr_bits += u4_hdr_bits;
212
280k
    ps_ctxt->u4_cu_tot_bits_into_qscale +=
213
280k
        ((ULWORD64)((u4_tex_bits + u4_hdr_bits) * (i4_qscale)) + (1 << (QSCALE_Q_FAC_3 - 1))) >>
214
280k
        QSCALE_Q_FAC_3;
215
280k
    ps_ctxt->u4_cu_tot_bits += (u4_tex_bits + u4_hdr_bits);
216
217
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]->u4_frame_rdopt_header_bits +=
218
280k
        u4_hdr_bits;
219
220
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]
221
280k
        ->i8_sad_by_qscale[ps_enc_loop_bestprms->u1_intra_flag] +=
222
280k
        ((((LWORD64)ps_enc_loop_bestprms->u4_cu_sad) << SAD_BY_QSCALE_Q) / i4_qscale);
223
224
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]
225
280k
        ->i4_qp_normalized_8x8_cu_sum[ps_enc_loop_bestprms->u1_intra_flag] +=
226
280k
        (i4_8x8_blks_in_cu * i4_qscale);
227
228
280k
    ps_ctxt->aaps_enc_loop_rc_params[i4_enc_frm_id][i4_br_id]
229
280k
        ->i4_8x8_cu_sum[ps_enc_loop_bestprms->u1_intra_flag] += i4_8x8_blks_in_cu;
230
231
    /* PCM not supported */
232
280k
    ps_cu_final->b1_pcm_flag = 0;
233
280k
    ps_cu_final->b1_pred_mode_flag = ps_enc_loop_bestprms->u1_intra_flag;
234
235
280k
    ps_cu_final->b1_skip_flag = ps_enc_loop_bestprms->u1_skip_flag;
236
280k
    ps_cu_final->b1_tq_bypass_flag = 0;
237
280k
    ps_cu_final->b3_part_mode = ps_enc_loop_bestprms->u1_part_mode;
238
239
280k
    ps_cu_final->pv_coeff = pu1_ecd_data;
240
241
280k
    ps_cu_final->i1_cu_qp = ps_enc_out_ctxt->i1_cu_qp;
242
280k
    if(ps_enc_loop_bestprms->u1_is_cu_coded)
243
226k
    {
244
226k
        ps_ctxt->i4_last_cu_qp_from_prev_ctb = ps_enc_out_ctxt->i1_cu_qp;
245
226k
    }
246
54.1k
    else
247
54.1k
    {
248
54.1k
        ps_ctxt->i4_last_cu_qp_from_prev_ctb = ps_ctxt->i4_pred_qp;
249
54.1k
    }
250
280k
    ps_cu_final->b1_first_cu_in_qg = ps_enc_out_ctxt->b1_first_cu_in_qg;
251
252
    /* Update the no residue flag. Needed for inter cu. */
253
    /* Needed for deblocking inter/intra both           */
254
    //if(ps_cu_final->b1_pred_mode_flag == PRED_MODE_INTER)
255
280k
    {
256
280k
        ps_cu_final->b1_no_residual_syntax_flag = !ps_enc_loop_bestprms->u1_is_cu_coded;
257
280k
    }
258
259
    /* store the number of TUs */
260
280k
    ps_cu_final->u2_num_tus_in_cu = ps_enc_loop_bestprms->u2_num_tus_in_cu;
261
262
    /* ---- copy the TUs to final structure ----- */
263
280k
    memcpy(
264
280k
        ps_cu_final->ps_enc_tu,
265
280k
        &ps_enc_loop_bestprms->as_tu_enc_loop[0],
266
280k
        ps_enc_loop_bestprms->u2_num_tus_in_cu * sizeof(tu_enc_loop_out_t));
267
268
    /* ---- copy the PUs to final structure ----- */
269
280k
    memcpy(
270
280k
        ps_cu_final->ps_pu,
271
280k
        &ps_enc_loop_bestprms->as_pu_enc_loop[0],
272
280k
        ps_enc_loop_bestprms->u2_num_pus_in_cu * sizeof(pu_t));
273
274
    /* --- copy reminder and prev_flags ----- */
275
    /* only required for intra */
276
280k
    if(PRED_MODE_INTRA == ps_cu_final->b1_pred_mode_flag)
277
228k
    {
278
228k
        memcpy(
279
228k
            &ps_cu_final->as_prev_rem[0],
280
228k
            &ps_enc_loop_bestprms->as_intra_prev_rem[0],
281
228k
            ps_enc_loop_bestprms->u2_num_tus_in_cu * sizeof(intra_prev_rem_flags_t));
282
283
228k
        ps_cu_final->b3_chroma_intra_pred_mode = ps_enc_loop_bestprms->u1_chroma_intra_pred_mode;
284
228k
    }
285
286
    /* --------------------------------------------------- */
287
    /* ---- Boundary Strength Calculation at CU level ---- */
288
    /* --------------------------------------------------- */
289
280k
    if(ps_ctxt->i4_deblk_pad_hpel_cur_pic)
290
279k
    {
291
279k
        WORD32 num_4x4_in_ctb;
292
279k
        nbr_4x4_t *ps_left_nbr_4x4;
293
279k
        nbr_4x4_t *ps_top_nbr_4x4;
294
279k
        nbr_4x4_t *ps_curr_nbr_4x4;
295
279k
        WORD32 nbr_4x4_left_strd;
296
297
279k
        num_4x4_in_ctb = (ps_cu_prms->i4_ctb_size >> 2);
298
299
279k
        ps_curr_nbr_4x4 = &ps_ctxt->as_ctb_nbr_arr[0];
300
279k
        ps_curr_nbr_4x4 += (ps_enc_out_ctxt->b3_cu_pos_x << 1);
301
279k
        ps_curr_nbr_4x4 += ((ps_enc_out_ctxt->b3_cu_pos_y << 1) * num_4x4_in_ctb);
302
303
        /* CU left */
304
279k
        if(0 == ps_enc_out_ctxt->b3_cu_pos_x)
305
56.6k
        {
306
56.6k
            ps_left_nbr_4x4 = &ps_ctxt->as_left_col_nbr[0];
307
56.6k
            ps_left_nbr_4x4 += ps_enc_out_ctxt->b3_cu_pos_y << 1;
308
56.6k
            nbr_4x4_left_strd = 1;
309
56.6k
        }
310
223k
        else
311
223k
        {
312
            /* inside CTB */
313
223k
            ps_left_nbr_4x4 = ps_curr_nbr_4x4 - 1;
314
223k
            nbr_4x4_left_strd = num_4x4_in_ctb;
315
223k
        }
316
317
        /* CU top */
318
279k
        if(0 == ps_enc_out_ctxt->b3_cu_pos_y)
319
59.3k
        {
320
            /* CTB boundary */
321
59.3k
            ps_top_nbr_4x4 = ps_ctxt->ps_top_row_nbr;
322
59.3k
            ps_top_nbr_4x4 += (ps_cu_prms->i4_ctb_pos * (ps_cu_prms->i4_ctb_size >> 2));
323
59.3k
            ps_top_nbr_4x4 += (ps_enc_out_ctxt->b3_cu_pos_x << 1);
324
59.3k
        }
325
220k
        else
326
220k
        {
327
            /* inside CTB */
328
220k
            ps_top_nbr_4x4 = ps_curr_nbr_4x4 - num_4x4_in_ctb;
329
220k
        }
330
331
279k
        ihevce_bs_compute_cu(
332
279k
            ps_cu_final,
333
279k
            ps_top_nbr_4x4,
334
279k
            ps_left_nbr_4x4,
335
279k
            ps_curr_nbr_4x4,
336
279k
            nbr_4x4_left_strd,
337
279k
            num_4x4_in_ctb,
338
279k
            &ps_ctxt->s_deblk_bs_prms);
339
279k
    }
340
280k
}
341
342
/**
343
*********************************************************************************
344
* Function name : ihevce_store_cu_results
345
*
346
* \brief
347
*    This function store cu result to cu info context
348
*
349
* \param[in] ps_ctxt : pointer to enc loop context structure
350
* \param[out] ps_cu_prms : pointer to  cu level parameters for SATD / RDOPT
351
*
352
* \return
353
*    None
354
*
355
**********************************************************************************/
356
void ihevce_store_cu_results(
357
    ihevce_enc_loop_ctxt_t *ps_ctxt,
358
    enc_loop_cu_prms_t *ps_cu_prms,
359
    final_mode_state_t *ps_final_state)
360
323k
{
361
323k
    ihevce_enc_cu_node_ctxt_t *ps_enc_tmp_out_ctxt;
362
323k
    nbr_4x4_t *ps_nbr_4x4, *ps_tmp_nbr_4x4, *ps_curr_nbr_4x4;
363
364
323k
    UWORD8 *pu1_recon, *pu1_final_recon;
365
323k
    WORD32 num_4x4_in_ctb, ctr;
366
323k
    WORD32 num_4x4_in_cu;
367
323k
    UWORD8 u1_is_422 = (ps_ctxt->u1_chroma_array_type == 2);
368
323k
    WORD32 cu_depth, log2_ctb_size, log2_cu_size;
369
370
323k
    ps_enc_tmp_out_ctxt = ps_ctxt->ps_enc_out_ctxt;
371
323k
    (void)ps_final_state;
372
#if PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS
373
    {
374
        /* ---- copy the child luma recon back to curr. recon -------- */
375
        pu1_recon = (UWORD8 *)ps_ctxt->pv_cu_luma_recon;
376
377
        /* based on CU position derive the luma pointers */
378
        pu1_final_recon = ps_cu_prms->pu1_luma_recon + (ps_enc_tmp_out_ctxt->b3_cu_pos_x << 3);
379
380
        pu1_final_recon +=
381
            ((ps_enc_tmp_out_ctxt->b3_cu_pos_y << 3) * ps_cu_prms->i4_luma_recon_stride);
382
383
        ps_ctxt->s_cmn_opt_func.pf_copy_2d(
384
            pu1_final_recon,
385
            ps_cu_prms->i4_luma_recon_stride,
386
            pu1_recon,
387
            ps_enc_tmp_out_ctxt->u1_cu_size,
388
            ps_enc_tmp_out_ctxt->u1_cu_size,
389
            ps_enc_tmp_out_ctxt->u1_cu_size);
390
391
        /* ---- copy the child chroma recon back to curr. recon -------- */
392
        pu1_recon = (UWORD8 *)ps_ctxt->pv_cu_chrma_recon;
393
394
        /* based on CU position derive the chroma pointers */
395
        pu1_final_recon = ps_cu_prms->pu1_chrm_recon + (ps_enc_tmp_out_ctxt->b3_cu_pos_x << 3);
396
397
        pu1_final_recon +=
398
            ((ps_enc_tmp_out_ctxt->b3_cu_pos_y << (u1_is_422 + 2)) *
399
             ps_cu_prms->i4_chrm_recon_stride);
400
401
        /* Cb and Cr pixel interleaved */
402
        ps_ctxt->s_cmn_opt_func.pf_copy_2d(
403
            pu1_final_recon,
404
            ps_cu_prms->i4_chrm_recon_stride,
405
            pu1_recon,
406
            ps_enc_tmp_out_ctxt->u1_cu_size,
407
            ps_enc_tmp_out_ctxt->u1_cu_size,
408
            (ps_enc_tmp_out_ctxt->u1_cu_size >> (0 == u1_is_422)));
409
    }
410
#else
411
323k
    if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
412
135k
    {
413
        /* ---- copy the child luma recon back to curr. recon -------- */
414
135k
        pu1_recon = (UWORD8 *)ps_ctxt->pv_cu_luma_recon;
415
416
        /* based on CU position derive the luma pointers */
417
135k
        pu1_final_recon = ps_cu_prms->pu1_luma_recon + (ps_enc_tmp_out_ctxt->b3_cu_pos_x << 3);
418
419
135k
        pu1_final_recon +=
420
135k
            ((ps_enc_tmp_out_ctxt->b3_cu_pos_y << 3) * ps_cu_prms->i4_luma_recon_stride);
421
422
135k
        ps_ctxt->s_cmn_opt_func.pf_copy_2d(
423
135k
            pu1_final_recon,
424
135k
            ps_cu_prms->i4_luma_recon_stride,
425
135k
            pu1_recon,
426
135k
            ps_enc_tmp_out_ctxt->u1_cu_size,
427
135k
            ps_enc_tmp_out_ctxt->u1_cu_size,
428
135k
            ps_enc_tmp_out_ctxt->u1_cu_size);
429
430
        /* ---- copy the child chroma recon back to curr. recon -------- */
431
135k
        pu1_recon = (UWORD8 *)ps_ctxt->pv_cu_chrma_recon;
432
433
        /* based on CU position derive the chroma pointers */
434
135k
        pu1_final_recon = ps_cu_prms->pu1_chrm_recon + (ps_enc_tmp_out_ctxt->b3_cu_pos_x << 3);
435
436
135k
        pu1_final_recon +=
437
135k
            ((ps_enc_tmp_out_ctxt->b3_cu_pos_y << (u1_is_422 + 2)) *
438
135k
             ps_cu_prms->i4_chrm_recon_stride);
439
440
135k
        ps_ctxt->s_cmn_opt_func.pf_copy_2d(
441
135k
            pu1_final_recon,
442
135k
            ps_cu_prms->i4_chrm_recon_stride,
443
135k
            pu1_recon,
444
135k
            ps_enc_tmp_out_ctxt->u1_cu_size,
445
135k
            ps_enc_tmp_out_ctxt->u1_cu_size,
446
135k
            (ps_enc_tmp_out_ctxt->u1_cu_size >> (0 == u1_is_422)));
447
135k
    }
448
323k
#endif
449
    /*copy qp for qg*/
450
323k
    {
451
323k
        WORD32 i4_num_8x8, i4_x, i4_y;
452
323k
        WORD32 i4_cu_pos_x, i4_cu_pox_y;
453
323k
        i4_num_8x8 = ps_enc_tmp_out_ctxt->u1_cu_size >> 3;
454
323k
        i4_cu_pos_x = ps_enc_tmp_out_ctxt->b3_cu_pos_x;
455
323k
        i4_cu_pox_y = ps_enc_tmp_out_ctxt->b3_cu_pos_y;
456
759k
        for(i4_y = 0; i4_y < i4_num_8x8; i4_y++)
457
435k
        {
458
1.26M
            for(i4_x = 0; i4_x < i4_num_8x8; i4_x++)
459
833k
            {
460
833k
                if(ps_enc_tmp_out_ctxt->ps_cu_prms->u1_is_cu_coded)
461
389k
                {
462
389k
                    ps_ctxt->ai4_qp_qg[((i4_cu_pox_y + i4_y) * 8) + (i4_cu_pos_x + i4_x)] =
463
389k
                        ps_ctxt->i4_cu_qp;
464
389k
                }
465
444k
                else
466
444k
                {
467
444k
                    ps_ctxt->ai4_qp_qg[((i4_cu_pox_y + i4_y) * 8) + (i4_cu_pos_x + i4_x)] =
468
444k
                        ps_ctxt->i4_pred_qp;
469
444k
                }
470
833k
            }
471
435k
        }
472
323k
    }
473
474
    /* ------ copy the nbr 4x4 to final output ------ */
475
323k
    num_4x4_in_cu = ps_enc_tmp_out_ctxt->u1_cu_size >> 2;
476
323k
    num_4x4_in_ctb = (ps_cu_prms->i4_ctb_size >> 2);
477
478
323k
    ps_curr_nbr_4x4 = &ps_ctxt->as_ctb_nbr_arr[0];
479
323k
    ps_curr_nbr_4x4 += (ps_enc_tmp_out_ctxt->b3_cu_pos_x << 1);
480
323k
    ps_curr_nbr_4x4 += ((ps_enc_tmp_out_ctxt->b3_cu_pos_y << 1) * num_4x4_in_ctb);
481
323k
    ps_tmp_nbr_4x4 = ps_curr_nbr_4x4;
482
483
323k
    ps_nbr_4x4 = ps_ctxt->ps_cu_recur_nbr;
484
485
323k
    GETRANGE(log2_ctb_size, ps_cu_prms->i4_ctb_size);
486
323k
    GETRANGE(log2_cu_size, ps_enc_tmp_out_ctxt->u1_cu_size);
487
323k
    cu_depth = log2_ctb_size - log2_cu_size;
488
489
323k
    ASSERT(cu_depth <= 3);
490
323k
    ASSERT(cu_depth >= 0);
491
492
    /*assign qp for all 4x4 nbr blocks*/
493
3.65M
    for(ctr = 0; ctr < num_4x4_in_cu * num_4x4_in_cu; ctr++, ps_nbr_4x4++)
494
3.33M
    {
495
3.33M
        ps_nbr_4x4->b1_skip_flag = ps_enc_tmp_out_ctxt->s_cu_prms.u1_skip_flag;
496
3.33M
        ps_nbr_4x4->b2_cu_depth = cu_depth;
497
3.33M
        ps_nbr_4x4->b8_qp = ps_ctxt->i4_cu_qp;
498
3.33M
    }
499
500
323k
    ps_nbr_4x4 = ps_ctxt->ps_cu_recur_nbr;
501
502
1.19M
    for(ctr = 0; ctr < num_4x4_in_cu; ctr++)
503
871k
    {
504
871k
        memcpy(ps_tmp_nbr_4x4, ps_nbr_4x4, num_4x4_in_cu * sizeof(nbr_4x4_t));
505
506
871k
        ps_tmp_nbr_4x4 += num_4x4_in_ctb;
507
871k
        ps_nbr_4x4 += num_4x4_in_cu;
508
871k
    }
509
323k
}
510
511
/**
512
*********************************************************************************
513
* Function name : ihevce_populate_cu_struct
514
*
515
* \brief
516
*    This function populate cu struct
517
*
518
* \param[in] ps_ctxt : pointer to enc loop context structure
519
* \param[in] ps_cur_ipe_ctb : pointer to  IPE L0 analyze structure
520
* \param[in] ps_cu_tree_analyse : pointer to  Structure for CU recursion
521
* \param[in] ps_best_results : pointer to  strcuture  contain result for partition type of CU
522
* \param[in] ps_cu_out : pointer to  structre contain  mode analysis info
523
* \param[in] i4_32x32_id : noise estimation id
524
* \param[in] u1_num_best_results : num best result value
525
*
526
* \return
527
*    None
528
*
529
**********************************************************************************/
530
void ihevce_populate_cu_struct(
531
    ihevce_enc_loop_ctxt_t *ps_ctxt,
532
    ipe_l0_ctb_analyse_for_me_t *ps_cur_ipe_ctb,
533
    cur_ctb_cu_tree_t *ps_cu_tree_analyse,
534
    part_type_results_t *ps_best_results,
535
    cu_analyse_t *ps_cu_out,
536
    WORD32 i4_32x32_id,
537
#if DISABLE_INTRA_WHEN_NOISY && USE_NOISE_TERM_IN_ENC_LOOP
538
    UWORD8 u1_is_cu_noisy,
539
#endif
540
    UWORD8 u1_num_best_results)
541
169k
{
542
169k
    cu_inter_cand_t *ps_cu_candt;
543
544
169k
    WORD32 j;
545
    /* open loop intra cost by IPE */
546
169k
    WORD32 intra_cost_ol;
547
    /* closed loop intra cost based on empirical coding noise estimate */
548
169k
    WORD32 intra_cost_cl_est = 0;
549
    /* closed loop intra coding noise estimate */
550
169k
    WORD32 intra_noise_cl_est;
551
169k
    WORD32 num_results_to_copy = 0;
552
553
169k
    WORD32 found_intra = 0;
554
169k
    WORD32 quality_preset = ps_ctxt->i4_quality_preset;
555
169k
    WORD32 frm_qp = ps_ctxt->i4_frame_qp;
556
169k
    WORD32 frm_qstep_multiplier = gau4_frame_qstep_multiplier[frm_qp - 1];
557
169k
    WORD32 frm_qstep = ps_ctxt->i4_frame_qstep;
558
169k
    UWORD8 u1_cu_size = ps_cu_tree_analyse->u1_cu_size;
559
169k
    UWORD8 u1_x_off = ps_cu_tree_analyse->b3_cu_pos_x << 3;
560
169k
    UWORD8 u1_y_off = ps_cu_tree_analyse->b3_cu_pos_y << 3;
561
169k
    UWORD8 u1_threshold_multi;
562
169k
    switch(quality_preset)
563
169k
    {
564
75.1k
    case IHEVCE_QUALITY_P0:
565
86.2k
    case IHEVCE_QUALITY_P2:
566
86.2k
    {
567
86.2k
        num_results_to_copy =
568
86.2k
            MIN(MAX_NUMBER_OF_INTER_RDOPT_CANDS_IN_PQ_AND_HQ, u1_num_best_results);
569
86.2k
        break;
570
75.1k
    }
571
30.7k
    case IHEVCE_QUALITY_P3:
572
30.7k
    {
573
30.7k
        num_results_to_copy = MIN(MAX_NUMBER_OF_INTER_RDOPT_CANDS_IN_MS, u1_num_best_results);
574
30.7k
        break;
575
75.1k
    }
576
24.5k
    case IHEVCE_QUALITY_P4:
577
30.1k
    case IHEVCE_QUALITY_P5:
578
52.2k
    case IHEVCE_QUALITY_P6:
579
52.2k
    {
580
52.2k
        num_results_to_copy =
581
52.2k
            MIN(MAX_NUMBER_OF_INTER_RDOPT_CANDS_IN_HS_AND_XS, u1_num_best_results);
582
52.2k
        break;
583
30.1k
    }
584
169k
    }
585
586
169k
    ps_cu_out->u1_num_inter_cands = 0;
587
588
    /***************************************************************/
589
    /* Depending CU size that has won in ME,                       */
590
    /*     Estimate the closed loop intra cost for enabling intra  */
591
    /*     evaluation in rdopt stage based on preset               */
592
    /***************************************************************/
593
169k
    switch(u1_cu_size)
594
169k
    {
595
637
    case 64:
596
637
    {
597
        /* coding noise estimate for intra closed loop cost */
598
637
        intra_cost_ol = ps_cur_ipe_ctb->i4_best64x64_intra_cost - frm_qstep * 256;
599
600
637
        intra_noise_cl_est = (frm_qstep * frm_qstep_multiplier) + (intra_cost_ol >> 4);
601
602
637
        intra_noise_cl_est = MIN(intra_noise_cl_est, (frm_qstep * 16)) * 16;
603
604
637
        intra_cost_cl_est = intra_cost_ol + intra_noise_cl_est;
605
637
        break;
606
0
    }
607
10.3k
    case 32:
608
10.3k
    {
609
        /* coding noise estimate for intra closed loop cost */
610
10.3k
        intra_cost_ol = ps_cur_ipe_ctb->ai4_best32x32_intra_cost[i4_32x32_id] - frm_qstep * 64;
611
612
10.3k
        intra_noise_cl_est = (frm_qstep * frm_qstep_multiplier) + (intra_cost_ol >> 4);
613
614
10.3k
        intra_noise_cl_est = MIN(intra_noise_cl_est, (frm_qstep * 16)) * 4;
615
616
10.3k
        intra_cost_cl_est = intra_cost_ol + intra_noise_cl_est;
617
10.3k
        break;
618
0
    }
619
42.0k
    case 16:
620
42.0k
    {
621
        /* coding noise estimate for intra closed loop cost */
622
42.0k
        intra_cost_ol =
623
42.0k
            ps_cur_ipe_ctb->ai4_best16x16_intra_cost[(u1_x_off >> 4) + ((u1_y_off >> 4) << 2)] -
624
42.0k
            frm_qstep * 16;
625
626
42.0k
        intra_noise_cl_est = (frm_qstep * frm_qstep_multiplier) + (intra_cost_ol >> 4);
627
628
42.0k
        intra_noise_cl_est = MIN(intra_noise_cl_est, (frm_qstep * 16));
629
630
42.0k
        intra_cost_cl_est = intra_cost_ol + intra_noise_cl_est;
631
42.0k
        break;
632
0
    }
633
116k
    case 8:
634
116k
    {
635
        /* coding noise estimate for intra closed loop cost */
636
116k
        intra_cost_ol =
637
116k
            ps_cur_ipe_ctb->ai4_best8x8_intra_cost[(u1_x_off >> 3) + u1_y_off] - frm_qstep * 4;
638
639
116k
        intra_noise_cl_est = (frm_qstep * frm_qstep_multiplier) + (intra_cost_ol >> 4);
640
641
116k
        intra_noise_cl_est = MIN(intra_noise_cl_est, (frm_qstep * 16)) >> 2;
642
643
116k
        intra_cost_cl_est = intra_cost_ol + intra_noise_cl_est;
644
116k
        break;
645
0
    }
646
169k
    }
647
#if DISABLE_INTER_CANDIDATES
648
    return;
649
#endif
650
651
169k
    u1_threshold_multi = 1;
652
#if DISABLE_INTRA_WHEN_NOISY && USE_NOISE_TERM_IN_ENC_LOOP
653
    if(u1_is_cu_noisy)
654
    {
655
        intra_cost_cl_est = INT_MAX;
656
    }
657
#endif
658
659
169k
    ps_cu_candt = ps_cu_out->as_cu_inter_cand;
660
661
    /* Check if the first best candidate is inter or intra */
662
169k
    if(ps_best_results[0].as_pu_results[0].pu.b1_intra_flag)
663
72.0k
    {
664
72.0k
        ps_cu_out->u1_best_is_intra = 1;
665
72.0k
    }
666
97.1k
    else
667
97.1k
    {
668
97.1k
        ps_cu_out->u1_best_is_intra = 0;
669
97.1k
    }
670
671
272k
    for(j = 0; j < u1_num_best_results; j++)
672
202k
    {
673
202k
        part_type_results_t *ps_best = &ps_best_results[j];
674
675
202k
        if(ps_best->as_pu_results[0].pu.b1_intra_flag)
676
72.3k
        {
677
72.3k
            found_intra = 1;
678
72.3k
        }
679
130k
        else
680
130k
        {
681
            /* populate the TU split flags, 4 flags copied as max cu can be 64 */
682
130k
            memcpy(ps_cu_candt->ai4_tu_split_flag, ps_best->ai4_tu_split_flag, 4 * sizeof(WORD32));
683
684
            /* populate the TU early CBF flags, 4 flags copied as max cu can be 64 */
685
130k
            memcpy(ps_cu_candt->ai4_tu_early_cbf, ps_best->ai4_tu_early_cbf, 4 * sizeof(WORD32));
686
687
            /* Note: the enums of part size and me part types shall match */
688
130k
            ps_cu_candt->b3_part_size = ps_best->u1_part_type;
689
690
            /* ME will always set the skip flag to 0            */
691
            /* in closed loop skip will be added as a candidate */
692
130k
            ps_cu_candt->b1_skip_flag = 0;
693
694
            /* copy the inter pus : Note: assuming NxN part type is not supported */
695
130k
            ps_cu_candt->as_inter_pu[0] = ps_best->as_pu_results[0].pu;
696
697
130k
            ps_cu_candt->as_inter_pu[0].b1_merge_flag = 0;
698
699
            /* Copy the total cost of the CU candt */
700
130k
            ps_cu_candt->i4_total_cost = ps_best->i4_tot_cost;
701
702
130k
            ps_cu_out->ai4_mv_cost[ps_cu_out->u1_num_inter_cands][0] =
703
130k
                ps_best->as_pu_results[0].i4_mv_cost;
704
705
#if REUSE_ME_COMPUTED_ERROR_FOR_INTER_CAND_SIFTING
706
            ps_cu_out->ai4_err_metric[ps_cu_out->u1_num_inter_cands][0] =
707
                ps_best->as_pu_results[0].i4_tot_cost - ps_best->as_pu_results[0].i4_mv_cost;
708
#endif
709
710
130k
            if(ps_best->u1_part_type)
711
34.3k
            {
712
34.3k
                ps_cu_candt->as_inter_pu[1] = ps_best->as_pu_results[1].pu;
713
34.3k
                ps_cu_out->ai4_mv_cost[ps_cu_out->u1_num_inter_cands][1] =
714
34.3k
                    ps_best->as_pu_results[1].i4_mv_cost;
715
#if REUSE_ME_COMPUTED_ERROR_FOR_INTER_CAND_SIFTING
716
                ps_cu_out->ai4_err_metric[ps_cu_out->u1_num_inter_cands][1] =
717
                    ps_best->as_pu_results[1].i4_tot_cost - ps_best->as_pu_results[1].i4_mv_cost;
718
#endif
719
720
34.3k
                ps_cu_candt->as_inter_pu[1].b1_merge_flag = 0;
721
34.3k
            }
722
723
130k
            ps_cu_candt++;
724
130k
            ps_cu_out->u1_num_inter_cands++;
725
130k
            if(intra_cost_cl_est < ((ps_best->i4_tot_cost * u1_threshold_multi) >> 0))
726
80.4k
            {
727
                /* The rationale - */
728
                /* Artefacts were being observed in some sequences, */
729
                /* Brooklyn_1080p in particular - where it was readily */
730
                /* apparent. The cause was coding of CU's as inter CU's */
731
                /* when they actually needed to be coded as intra CU's. */
732
                /* This was observed during either fade-outs aor flashes. */
733
                /* After tinkering with the magnitude of the coding noise */
734
                /* factor that was added to the intra cost to see when the */
735
                /* artefacts in Brooklyn vanished, it was observed that the */
736
                /* factor multiplied with the frame_qstep followed a pattern. */
737
                /* When the pattern was subjected to a regression analysis, the */
738
                /* formula seen below emerged. Also note the fact that the coding */
739
                /* noise factor is the product of the frame_qstep and a constant */
740
                /* multiplier */
741
742
                /*UWORD32 frm_qstep_multiplier =
743
                -3.346 * log((float)frm_qstep) + 15.925;*/
744
80.4k
                found_intra = 1;
745
80.4k
            }
746
747
130k
            if(ps_cu_out->u1_num_inter_cands >= num_results_to_copy)
748
98.7k
            {
749
98.7k
                break;
750
98.7k
            }
751
130k
        }
752
202k
    }
753
754
169k
    if(quality_preset < IHEVCE_QUALITY_P4)
755
116k
    {
756
116k
        found_intra = 1;
757
116k
    }
758
759
169k
    if(!found_intra)
760
15.9k
    {
761
        /* rdopt evaluation of intra disabled as inter is clear winner */
762
15.9k
        ps_cu_out->u1_num_intra_rdopt_cands = 0;
763
764
        /* all the modes invalidated */
765
15.9k
        ps_cu_out->s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu[0] = 255;
766
15.9k
        ps_cu_out->s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
767
15.9k
        ps_cu_out->s_cu_intra_cand.au1_intra_luma_modes_nxn[0][0] = 255;
768
15.9k
        ps_cu_out->u1_chroma_intra_pred_mode = 255;
769
770
        /* no intra candt to verify */
771
15.9k
        ps_cu_out->s_cu_intra_cand.b6_num_intra_cands = 0;
772
15.9k
    }
773
169k
}
774
775
/**
776
*********************************************************************************
777
* Function name : ihevce_create_child_nodes_cu_tree
778
*
779
* \brief
780
*    This function create child node from cu tree
781
*
782
* \param[in] ps_cu_tree_root : pointer to Structure for CU recursion
783
* \param[out] ps_cu_tree_cur_node : pointer to  Structure for CU recursion
784
* \param[in] ai4_child_node_enable : child node enable flag
785
* \param[in] nodes_already_created : already created node value
786
* \return
787
*    None
788
*
789
**********************************************************************************/
790
WORD32 ihevce_create_child_nodes_cu_tree(
791
    cur_ctb_cu_tree_t *ps_cu_tree_root,
792
    cur_ctb_cu_tree_t *ps_cu_tree_cur_node,
793
    WORD32 *ai4_child_node_enable,
794
    WORD32 nodes_already_created)
795
62.4k
{
796
62.4k
    cur_ctb_cu_tree_t *ps_tl;
797
62.4k
    cur_ctb_cu_tree_t *ps_tr;
798
62.4k
    cur_ctb_cu_tree_t *ps_bl;
799
62.4k
    cur_ctb_cu_tree_t *ps_br;
800
801
62.4k
    ps_tl = ps_cu_tree_root + nodes_already_created;
802
62.4k
    ps_tr = ps_tl + 1;
803
62.4k
    ps_bl = ps_tr + 1;
804
62.4k
    ps_br = ps_bl + 1;
805
806
62.4k
    if(1 == ps_cu_tree_cur_node->is_node_valid)
807
15.8k
    {
808
15.8k
        ps_tl = (ai4_child_node_enable[0]) ? ps_tl : NULL;
809
15.8k
        ps_tr = (ai4_child_node_enable[1]) ? ps_tr : NULL;
810
15.8k
        ps_bl = (ai4_child_node_enable[2]) ? ps_bl : NULL;
811
15.8k
        ps_br = (ai4_child_node_enable[3]) ? ps_br : NULL;
812
813
        /* In incomplete CTB, if any of the child nodes are assigned to NULL */
814
        /* then parent node ceases to be valid */
815
15.8k
        if((ps_tl == NULL) || (ps_tr == NULL) || (ps_br == NULL) || (ps_bl == NULL))
816
0
        {
817
0
            ps_cu_tree_cur_node->is_node_valid = 0;
818
0
        }
819
15.8k
    }
820
62.4k
    ps_cu_tree_cur_node->ps_child_node_tl = ps_tl;
821
62.4k
    ps_cu_tree_cur_node->ps_child_node_tr = ps_tr;
822
62.4k
    ps_cu_tree_cur_node->ps_child_node_bl = ps_bl;
823
62.4k
    ps_cu_tree_cur_node->ps_child_node_br = ps_br;
824
825
62.4k
    return 4;
826
62.4k
}
827
828
/**
829
*********************************************************************************
830
* Function name : ihevce_populate_cu_tree
831
*
832
* \brief
833
*    This function create child node from cu tree
834
*
835
* \param[in] ps_cur_ipe_ctb : pointer to Structure for CU recursion
836
* \param[out] ps_cu_tree : pointer to  Structure for CU recursion
837
* \param[in] tree_depth : child node enable flag
838
* \param[in] e_quality_preset : already created node value
839
* \param[in] e_grandparent_blk_pos : already created node value
840
* \param[in] e_parent_blk_pos : already created node value
841
* \param[in] e_cur_blk_pos : already created node value
842
*
843
* \return
844
*    None
845
*
846
**********************************************************************************/
847
void ihevce_populate_cu_tree(
848
    ipe_l0_ctb_analyse_for_me_t *ps_cur_ipe_ctb,
849
    cur_ctb_cu_tree_t *ps_cu_tree,
850
    WORD32 tree_depth,
851
    IHEVCE_QUALITY_CONFIG_T e_quality_preset,
852
    CU_POS_T e_grandparent_blk_pos,
853
    CU_POS_T e_parent_blk_pos,
854
    CU_POS_T e_cur_blk_pos)
855
255k
{
856
255k
    WORD32 ai4_child_enable[4];
857
255k
    WORD32 children_nodes_required = 0;
858
255k
    WORD32 cu_pos_x = 0;
859
255k
    WORD32 cu_pos_y = 0;
860
255k
    WORD32 cu_size = 0;
861
255k
    WORD32 i;
862
255k
    WORD32 node_validity = 0;
863
864
255k
    if(NULL == ps_cu_tree)
865
0
    {
866
0
        return;
867
0
    }
868
869
255k
    switch(tree_depth)
870
255k
    {
871
6.02k
    case 0:
872
6.02k
    {
873
        /* 64x64 block */
874
6.02k
        intra32_analyse_t *ps_intra32_analyse = ps_cur_ipe_ctb->as_intra32_analyse;
875
876
6.02k
        children_nodes_required = 1;
877
6.02k
        cu_size = 64;
878
6.02k
        cu_pos_x = 0;
879
6.02k
        cu_pos_y = 0;
880
881
6.02k
        node_validity = !ps_cur_ipe_ctb->u1_split_flag;
882
883
6.02k
        if(e_quality_preset >= IHEVCE_QUALITY_P2)
884
3.51k
        {
885
3.51k
            if(node_validity == 1)
886
644
            {
887
644
                children_nodes_required = 0;
888
644
            }
889
3.51k
        }
890
891
30.1k
        for(i = 0; i < 4; i++)
892
24.1k
        {
893
24.1k
            ai4_child_enable[i] = ps_intra32_analyse[i].b1_valid_cu;
894
24.1k
        }
895
896
6.02k
        break;
897
0
    }
898
21.5k
    case 1:
899
21.5k
    {
900
        /* 32x32 block */
901
21.5k
        WORD32 valid_flag_32 = (ps_cur_ipe_ctb->as_intra32_analyse[e_cur_blk_pos].b1_valid_cu);
902
903
21.5k
        intra16_analyse_t *ps_intra16_analyse =
904
21.5k
            ps_cur_ipe_ctb->as_intra32_analyse[e_cur_blk_pos].as_intra16_analyse;
905
906
21.5k
        cu_size = 32;
907
908
        /* Explanation for logic below - */
909
        /* * pos_x and pos_y are in units of 8x8 CU's */
910
        /* * pos_x = 0 for TL and BL children */
911
        /* * pos_x = 4 for TR and BR children */
912
        /* * pos_y = 0 for TL and TR children */
913
        /* * pos_y = 4 for BL and BR children */
914
21.5k
        cu_pos_x = (e_cur_blk_pos & 1) << 2;
915
21.5k
        cu_pos_y = (e_cur_blk_pos & 2) << 1;
916
917
21.5k
        {
918
21.5k
            node_validity = (ps_cur_ipe_ctb->as_intra32_analyse[e_cur_blk_pos].b1_merge_flag);
919
920
21.5k
            if(e_quality_preset >= IHEVCE_QUALITY_P2)
921
11.5k
            {
922
11.5k
                node_validity = (!ps_cur_ipe_ctb->as_intra32_analyse[e_cur_blk_pos].b1_split_flag);
923
11.5k
            }
924
925
21.5k
            node_validity = node_validity && valid_flag_32;
926
21.5k
            children_nodes_required = !node_validity || ps_cur_ipe_ctb->u1_split_flag;
927
21.5k
        }
928
929
21.5k
        if(e_quality_preset >= IHEVCE_QUALITY_P2)
930
11.5k
        {
931
11.5k
            if(node_validity == 1)
932
2.44k
            {
933
2.44k
                children_nodes_required = 0;
934
2.44k
            }
935
9.05k
            else
936
9.05k
            {
937
9.05k
                children_nodes_required =
938
9.05k
                    (ps_cur_ipe_ctb->as_intra32_analyse[e_cur_blk_pos].b1_split_flag);
939
9.05k
            }
940
11.5k
        }
941
942
107k
        for(i = 0; i < 4; i++)
943
86.0k
        {
944
86.0k
            ai4_child_enable[i] = ps_intra16_analyse[i].b1_valid_cu;
945
86.0k
        }
946
947
21.5k
        break;
948
0
    }
949
57.8k
    case 2:
950
57.8k
    {
951
        /* 16x16 block */
952
57.8k
        WORD32 cu_pos_x_parent;
953
57.8k
        WORD32 cu_pos_y_parent;
954
57.8k
        WORD32 merge_flag_16;
955
57.8k
        WORD32 merge_flag_32;
956
957
57.8k
        intra8_analyse_t *ps_intra8_analyse = ps_cur_ipe_ctb->as_intra32_analyse[e_parent_blk_pos]
958
57.8k
                                                  .as_intra16_analyse[e_cur_blk_pos]
959
57.8k
                                                  .as_intra8_analyse;
960
961
57.8k
        WORD32 valid_flag_16 = (ps_cur_ipe_ctb->as_intra32_analyse[e_parent_blk_pos]
962
57.8k
                                    .as_intra16_analyse[e_cur_blk_pos]
963
57.8k
                                    .b1_valid_cu);
964
965
57.8k
        cu_size = 16;
966
967
        /* Explanation for logic below - */
968
        /* See similar explanation above */
969
57.8k
        cu_pos_x_parent = (e_parent_blk_pos & 1) << 2;
970
57.8k
        cu_pos_y_parent = (e_parent_blk_pos & 2) << 1;
971
57.8k
        cu_pos_x = cu_pos_x_parent + ((e_cur_blk_pos & 1) << 1);
972
57.8k
        cu_pos_y = cu_pos_y_parent + (e_cur_blk_pos & 2);
973
974
57.8k
        merge_flag_16 = (ps_cur_ipe_ctb->as_intra32_analyse[e_parent_blk_pos]
975
57.8k
                             .as_intra16_analyse[e_cur_blk_pos]
976
57.8k
                             .b1_merge_flag);
977
57.8k
        merge_flag_32 = (ps_cur_ipe_ctb->as_intra32_analyse[e_parent_blk_pos].b1_merge_flag);
978
979
57.8k
#if !ENABLE_UNIFORM_CU_SIZE_8x8
980
57.8k
        node_validity = (merge_flag_16) || ((ps_cur_ipe_ctb->u1_split_flag) && (!merge_flag_32));
981
#else
982
        node_validity = 0;
983
#endif
984
985
57.8k
        node_validity = (merge_flag_16) || ((ps_cur_ipe_ctb->u1_split_flag) && (!merge_flag_32));
986
987
57.8k
        if(e_quality_preset >= IHEVCE_QUALITY_P2)
988
32.0k
        {
989
32.0k
            node_validity = (!ps_cur_ipe_ctb->as_intra32_analyse[e_parent_blk_pos]
990
32.0k
                                  .as_intra16_analyse[e_cur_blk_pos]
991
32.0k
                                  .b1_split_flag);
992
32.0k
        }
993
994
57.8k
        node_validity = node_validity && valid_flag_16;
995
996
57.8k
        children_nodes_required = ((ps_cur_ipe_ctb->u1_split_flag) && (!merge_flag_32)) ||
997
10.5k
                                  !merge_flag_16;
998
999
57.8k
        if(e_quality_preset >= IHEVCE_QUALITY_P2)
1000
32.0k
        {
1001
32.0k
            children_nodes_required = !node_validity;
1002
32.0k
        }
1003
1004
289k
        for(i = 0; i < 4; i++)
1005
231k
        {
1006
231k
            ai4_child_enable[i] = ps_intra8_analyse[i].b1_valid_cu;
1007
231k
        }
1008
57.8k
        break;
1009
0
    }
1010
170k
    case 3:
1011
170k
    {
1012
        /* 8x8 block */
1013
170k
        WORD32 cu_pos_x_grandparent;
1014
170k
        WORD32 cu_pos_y_grandparent;
1015
1016
170k
        WORD32 cu_pos_x_parent;
1017
170k
        WORD32 cu_pos_y_parent;
1018
1019
170k
        WORD32 valid_flag_8 = (ps_cur_ipe_ctb->as_intra32_analyse[e_grandparent_blk_pos]
1020
170k
                                   .as_intra16_analyse[e_parent_blk_pos]
1021
170k
                                   .as_intra8_analyse[e_cur_blk_pos]
1022
170k
                                   .b1_valid_cu);
1023
1024
170k
        cu_size = 8;
1025
1026
170k
        cu_pos_x_grandparent = (e_grandparent_blk_pos & 1) << 2;
1027
170k
        cu_pos_y_grandparent = (e_grandparent_blk_pos & 2) << 1;
1028
170k
        cu_pos_x_parent = cu_pos_x_grandparent + ((e_parent_blk_pos & 1) << 1);
1029
170k
        cu_pos_y_parent = cu_pos_y_grandparent + (e_parent_blk_pos & 2);
1030
170k
        cu_pos_x = cu_pos_x_parent + (e_cur_blk_pos & 1);
1031
170k
        cu_pos_y = cu_pos_y_parent + ((e_cur_blk_pos & 2) >> 1);
1032
1033
170k
        node_validity = 1 && valid_flag_8;
1034
1035
170k
        children_nodes_required = 0;
1036
1037
170k
        break;
1038
0
    }
1039
255k
    }
1040
1041
    /* Fill the current cu_tree node */
1042
255k
    ps_cu_tree->is_node_valid = node_validity;
1043
255k
    ps_cu_tree->u1_cu_size = cu_size;
1044
255k
    ps_cu_tree->b3_cu_pos_x = cu_pos_x;
1045
255k
    ps_cu_tree->b3_cu_pos_y = cu_pos_y;
1046
1047
255k
    if(children_nodes_required)
1048
62.4k
    {
1049
62.4k
        tree_depth++;
1050
1051
62.4k
        ps_cur_ipe_ctb->nodes_created_in_cu_tree += ihevce_create_child_nodes_cu_tree(
1052
62.4k
            ps_cur_ipe_ctb->ps_cu_tree_root,
1053
62.4k
            ps_cu_tree,
1054
62.4k
            ai4_child_enable,
1055
62.4k
            ps_cur_ipe_ctb->nodes_created_in_cu_tree);
1056
1057
62.4k
        ihevce_populate_cu_tree(
1058
62.4k
            ps_cur_ipe_ctb,
1059
62.4k
            ps_cu_tree->ps_child_node_tl,
1060
62.4k
            tree_depth,
1061
62.4k
            e_quality_preset,
1062
62.4k
            e_parent_blk_pos,
1063
62.4k
            e_cur_blk_pos,
1064
62.4k
            POS_TL);
1065
1066
62.4k
        ihevce_populate_cu_tree(
1067
62.4k
            ps_cur_ipe_ctb,
1068
62.4k
            ps_cu_tree->ps_child_node_tr,
1069
62.4k
            tree_depth,
1070
62.4k
            e_quality_preset,
1071
62.4k
            e_parent_blk_pos,
1072
62.4k
            e_cur_blk_pos,
1073
62.4k
            POS_TR);
1074
1075
62.4k
        ihevce_populate_cu_tree(
1076
62.4k
            ps_cur_ipe_ctb,
1077
62.4k
            ps_cu_tree->ps_child_node_bl,
1078
62.4k
            tree_depth,
1079
62.4k
            e_quality_preset,
1080
62.4k
            e_parent_blk_pos,
1081
62.4k
            e_cur_blk_pos,
1082
62.4k
            POS_BL);
1083
1084
62.4k
        ihevce_populate_cu_tree(
1085
62.4k
            ps_cur_ipe_ctb,
1086
62.4k
            ps_cu_tree->ps_child_node_br,
1087
62.4k
            tree_depth,
1088
62.4k
            e_quality_preset,
1089
62.4k
            e_parent_blk_pos,
1090
62.4k
            e_cur_blk_pos,
1091
62.4k
            POS_BR);
1092
62.4k
    }
1093
193k
    else
1094
193k
    {
1095
193k
        ps_cu_tree->ps_child_node_tl = NULL;
1096
193k
        ps_cu_tree->ps_child_node_tr = NULL;
1097
193k
        ps_cu_tree->ps_child_node_bl = NULL;
1098
193k
        ps_cu_tree->ps_child_node_br = NULL;
1099
193k
    }
1100
255k
}
1101
1102
/**
1103
*********************************************************************************
1104
* Function name : ihevce_intra_mode_populator
1105
*
1106
* \brief
1107
*    This function populate intra mode info to strcut
1108
*
1109
* \param[in] ps_cu_intra_cand : pointer to Structure contain cu intra candidate info
1110
* \param[out] ps_ipe_data : pointer to  IPE L0 analyze structure
1111
* \param[in] ps_cu_tree_data : poniter to cu recursive struct
1112
* \param[in] i1_slice_type : contain slice type value
1113
* \param[in] i4_quality_preset : contain quality preset value
1114
*
1115
* \return
1116
*    None
1117
*
1118
**********************************************************************************/
1119
static void ihevce_intra_mode_populator(
1120
    cu_intra_cand_t *ps_cu_intra_cand,
1121
    ipe_l0_ctb_analyse_for_me_t *ps_ipe_data,
1122
    cur_ctb_cu_tree_t *ps_cu_tree_data,
1123
    WORD8 i1_slice_type,
1124
    WORD32 i4_quality_preset)
1125
327k
{
1126
327k
    WORD32 i4_32x32_id, i4_16x16_id, i4_8x8_id;
1127
1128
327k
    UWORD8 u1_cu_pos_x = ps_cu_tree_data->b3_cu_pos_x;
1129
327k
    UWORD8 u1_cu_pos_y = ps_cu_tree_data->b3_cu_pos_y;
1130
1131
327k
    i4_32x32_id = ((u1_cu_pos_x & 4) >> 2) + ((u1_cu_pos_y & 4) >> 1);
1132
1133
327k
    i4_16x16_id = ((u1_cu_pos_x & 2) >> 1) + ((u1_cu_pos_y & 2));
1134
1135
327k
    i4_8x8_id = (u1_cu_pos_x & 1) + ((u1_cu_pos_y & 1) << 1);
1136
1137
327k
    if(i4_quality_preset < IHEVCE_QUALITY_P3)
1138
183k
    {
1139
183k
        switch(ps_cu_tree_data->u1_cu_size)
1140
183k
        {
1141
1.30k
        case 64:
1142
1.30k
        {
1143
1.30k
            memcpy(
1144
1.30k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1145
1.30k
                ps_ipe_data->au1_best_modes_32x32_tu,
1146
1.30k
                MAX_INTRA_CU_CANDIDATES + 1);
1147
1148
1.30k
            break;
1149
0
        }
1150
11.2k
        case 32:
1151
11.2k
        {
1152
11.2k
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1153
1154
11.2k
            memcpy(
1155
11.2k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1156
11.2k
                ps_32x32_ipe_analyze->au1_best_modes_32x32_tu,
1157
11.2k
                MAX_INTRA_CU_CANDIDATES + 1);
1158
1159
11.2k
            if((i1_slice_type != ISLICE) && (i4_quality_preset == IHEVCE_QUALITY_P0))
1160
4.63k
            {
1161
4.63k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1162
4.63k
            }
1163
6.56k
            else if((i1_slice_type == ISLICE) && (i4_quality_preset == IHEVCE_QUALITY_P0))
1164
5.32k
            {
1165
5.32k
                if((ps_cu_tree_data->ps_child_node_bl != NULL) &&
1166
1.74k
                   (ps_cu_tree_data->ps_child_node_bl->is_node_valid))
1167
1.74k
                {
1168
1.74k
                    ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1169
1.74k
                }
1170
3.57k
                else
1171
3.57k
                {
1172
3.57k
                    memcpy(
1173
3.57k
                        ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1174
3.57k
                        ps_32x32_ipe_analyze->au1_best_modes_16x16_tu,
1175
3.57k
                        MAX_INTRA_CU_CANDIDATES + 1);
1176
3.57k
                }
1177
5.32k
            }
1178
1.24k
            else
1179
1.24k
            {
1180
1.24k
                memcpy(
1181
1.24k
                    ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1182
1.24k
                    ps_32x32_ipe_analyze->au1_best_modes_16x16_tu,
1183
1.24k
                    MAX_INTRA_CU_CANDIDATES + 1);
1184
1.24k
            }
1185
1186
11.2k
            break;
1187
0
        }
1188
42.5k
        case 16:
1189
42.5k
        {
1190
            /* Copy best 16x16 CU modes */
1191
42.5k
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1192
1193
42.5k
            intra16_analyse_t *ps_16x16_ipe_analyze =
1194
42.5k
                &ps_32x32_ipe_analyze->as_intra16_analyse[i4_16x16_id];
1195
1196
42.5k
            memcpy(
1197
42.5k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1198
42.5k
                ps_16x16_ipe_analyze->au1_best_modes_16x16_tu,
1199
42.5k
                MAX_INTRA_CU_CANDIDATES + 1);
1200
1201
42.5k
            if((i1_slice_type != ISLICE) && (i4_quality_preset == IHEVCE_QUALITY_P0))
1202
19.3k
            {
1203
19.3k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1204
19.3k
            }
1205
23.2k
            else if((i1_slice_type == ISLICE) && (i4_quality_preset == IHEVCE_QUALITY_P0))
1206
20.1k
            {
1207
20.1k
                if((ps_cu_tree_data->ps_child_node_bl != NULL) &&
1208
13.1k
                   (ps_cu_tree_data->ps_child_node_bl->is_node_valid))
1209
13.1k
                {
1210
13.1k
                    ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1211
13.1k
                }
1212
6.99k
                else
1213
6.99k
                {
1214
6.99k
                    memcpy(
1215
6.99k
                        ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1216
6.99k
                        ps_16x16_ipe_analyze->au1_best_modes_8x8_tu,
1217
6.99k
                        MAX_INTRA_CU_CANDIDATES + 1);
1218
6.99k
                }
1219
20.1k
            }
1220
3.08k
            else
1221
3.08k
            {
1222
3.08k
                memcpy(
1223
3.08k
                    ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1224
3.08k
                    ps_16x16_ipe_analyze->au1_best_modes_8x8_tu,
1225
3.08k
                    MAX_INTRA_CU_CANDIDATES + 1);
1226
3.08k
            }
1227
1228
42.5k
            break;
1229
0
        }
1230
128k
        case 8:
1231
128k
        {
1232
128k
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1233
1234
128k
            intra16_analyse_t *ps_16x16_ipe_analyze =
1235
128k
                &ps_32x32_ipe_analyze->as_intra16_analyse[i4_16x16_id];
1236
1237
128k
            intra8_analyse_t *ps_8x8_ipe_analyze =
1238
128k
                &ps_16x16_ipe_analyze->as_intra8_analyse[i4_8x8_id];
1239
1240
128k
            memcpy(
1241
128k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1242
128k
                ps_8x8_ipe_analyze->au1_best_modes_8x8_tu,
1243
128k
                MAX_INTRA_CU_CANDIDATES + 1);
1244
1245
128k
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1246
1247
            /* Initialise the hash */
1248
128k
            {
1249
128k
                WORD32 i, j;
1250
1251
644k
                for(i = 0; i < NUM_PU_PARTS; i++)
1252
515k
                {
1253
515k
                    ps_cu_intra_cand->au1_num_modes_added[i] = 0;
1254
1255
18.5M
                    for(j = 0; j < MAX_INTRA_CANDIDATES; j++)
1256
18.0M
                    {
1257
18.0M
                        ps_cu_intra_cand->au1_intra_luma_mode_nxn_hash[i][j] = 0;
1258
18.0M
                    }
1259
515k
                }
1260
1261
644k
                for(i = 0; i < NUM_PU_PARTS; i++)
1262
515k
                {
1263
1.78M
                    for(j = 0; j < MAX_INTRA_CU_CANDIDATES; j++)
1264
1.36M
                    {
1265
1.36M
                        if(ps_8x8_ipe_analyze->au1_4x4_best_modes[i][j] == 255)
1266
92.6k
                        {
1267
92.6k
                            ps_cu_intra_cand->au1_intra_luma_modes_nxn[i][j] = 255;
1268
92.6k
                            break;
1269
92.6k
                        }
1270
1271
1.26M
                        ps_cu_intra_cand->au1_intra_luma_modes_nxn[i][j] =
1272
1.26M
                            ps_8x8_ipe_analyze->au1_4x4_best_modes[i][j];
1273
1274
1.26M
                        ps_cu_intra_cand->au1_intra_luma_mode_nxn_hash
1275
1.26M
                            [i][ps_8x8_ipe_analyze->au1_4x4_best_modes[i][j]] = 1;
1276
1277
1.26M
                        ps_cu_intra_cand->au1_num_modes_added[i]++;
1278
1.26M
                    }
1279
1280
515k
                    if(ps_cu_intra_cand->au1_num_modes_added[i] == MAX_INTRA_CU_CANDIDATES)
1281
422k
                    {
1282
422k
                        if(i1_slice_type != BSLICE)
1283
414k
                        {
1284
414k
                            ps_cu_intra_cand->au1_num_modes_added[i] =
1285
414k
                                ihevce_intra_mode_nxn_hash_updater(
1286
414k
                                    ps_cu_intra_cand->au1_intra_luma_modes_nxn[i],
1287
414k
                                    ps_cu_intra_cand->au1_intra_luma_mode_nxn_hash[i],
1288
414k
                                    ps_cu_intra_cand->au1_num_modes_added[i]);
1289
414k
                        }
1290
422k
                    }
1291
515k
                }
1292
128k
            }
1293
1294
128k
            break;
1295
0
        }
1296
183k
        }
1297
183k
    }
1298
143k
    else if(i4_quality_preset == IHEVCE_QUALITY_P6)
1299
42.9k
    {
1300
42.9k
        switch(ps_cu_tree_data->u1_cu_size)
1301
42.9k
        {
1302
367
        case 64:
1303
367
        {
1304
367
            memcpy(
1305
367
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1306
367
                ps_ipe_data->au1_best_modes_32x32_tu,
1307
367
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1308
1309
367
            ps_cu_intra_cand->b1_eval_tx_cusize = 0;
1310
367
            ps_cu_intra_cand->b1_eval_tx_cusize_by2 = 1;
1311
367
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu[0] = 255;
1312
1313
367
#if ENABLE_INTRA_MODE_FILTERING_IN_XS25
1314
367
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2
1315
367
                [MAX_NUM_INTRA_MODES_PER_TU_DISTRIBUTION_IN_XS25] = 255;
1316
367
#endif
1317
1318
367
            break;
1319
0
        }
1320
703
        case 32:
1321
703
        {
1322
703
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1323
1324
703
            memcpy(
1325
703
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1326
703
                ps_32x32_ipe_analyze->au1_best_modes_32x32_tu,
1327
703
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1328
1329
703
            memcpy(
1330
703
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1331
703
                ps_32x32_ipe_analyze->au1_best_modes_16x16_tu,
1332
703
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1333
1334
703
#if ENABLE_INTRA_MODE_FILTERING_IN_XS25
1335
703
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu
1336
703
                [MAX_NUM_INTRA_MODES_PER_TU_DISTRIBUTION_IN_XS25] = 255;
1337
703
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2
1338
703
                [MAX_NUM_INTRA_MODES_PER_TU_DISTRIBUTION_IN_XS25] = 255;
1339
703
#endif
1340
1341
703
            break;
1342
0
        }
1343
8.30k
        case 16:
1344
8.30k
        {
1345
            /* Copy best 16x16 CU modes */
1346
8.30k
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1347
1348
8.30k
            intra16_analyse_t *ps_16x16_ipe_analyze =
1349
8.30k
                &ps_32x32_ipe_analyze->as_intra16_analyse[i4_16x16_id];
1350
1351
8.30k
            memcpy(
1352
8.30k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1353
8.30k
                ps_16x16_ipe_analyze->au1_best_modes_16x16_tu,
1354
8.30k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1355
1356
8.30k
            memcpy(
1357
8.30k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1358
8.30k
                ps_16x16_ipe_analyze->au1_best_modes_8x8_tu,
1359
8.30k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1360
1361
8.30k
#if ENABLE_INTRA_MODE_FILTERING_IN_XS25
1362
8.30k
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu
1363
8.30k
                [MAX_NUM_INTRA_MODES_PER_TU_DISTRIBUTION_IN_XS25] = 255;
1364
8.30k
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2
1365
8.30k
                [MAX_NUM_INTRA_MODES_PER_TU_DISTRIBUTION_IN_XS25] = 255;
1366
8.30k
#endif
1367
1368
8.30k
            break;
1369
0
        }
1370
33.6k
        case 8:
1371
33.6k
        {
1372
33.6k
            WORD32 i;
1373
1374
33.6k
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1375
1376
33.6k
            intra16_analyse_t *ps_16x16_ipe_analyze =
1377
33.6k
                &ps_32x32_ipe_analyze->as_intra16_analyse[i4_16x16_id];
1378
1379
33.6k
            intra8_analyse_t *ps_8x8_ipe_analyze =
1380
33.6k
                &ps_16x16_ipe_analyze->as_intra8_analyse[i4_8x8_id];
1381
1382
33.6k
            memcpy(
1383
33.6k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1384
33.6k
                ps_8x8_ipe_analyze->au1_best_modes_8x8_tu,
1385
33.6k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1386
1387
#if !ENABLE_INTRA_MODE_FILTERING_IN_XS25
1388
            memcpy(
1389
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1390
                ps_8x8_ipe_analyze->au1_best_modes_4x4_tu,
1391
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1392
1393
            for(i = 0; i < 4; i++)
1394
            {
1395
                memcpy(
1396
                    ps_cu_intra_cand->au1_intra_luma_modes_nxn[i],
1397
                    ps_8x8_ipe_analyze->au1_4x4_best_modes[i],
1398
                    (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1399
1400
                ps_cu_intra_cand->au1_intra_luma_modes_nxn[i][MAX_INTRA_CU_CANDIDATES] = 255;
1401
            }
1402
#else
1403
33.6k
            if(255 == ps_8x8_ipe_analyze->au1_4x4_best_modes[0][0])
1404
7.44k
            {
1405
7.44k
                memcpy(
1406
7.44k
                    ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1407
7.44k
                    ps_8x8_ipe_analyze->au1_best_modes_4x4_tu,
1408
7.44k
                    (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1409
1410
7.44k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2
1411
7.44k
                    [MAX_NUM_INTRA_MODES_PER_TU_DISTRIBUTION_IN_XS25] = 255;
1412
7.44k
            }
1413
26.1k
            else
1414
26.1k
            {
1415
130k
                for(i = 0; i < 4; i++)
1416
104k
                {
1417
104k
                    memcpy(
1418
104k
                        ps_cu_intra_cand->au1_intra_luma_modes_nxn[i],
1419
104k
                        ps_8x8_ipe_analyze->au1_4x4_best_modes[i],
1420
104k
                        (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1421
1422
104k
                    ps_cu_intra_cand->au1_intra_luma_modes_nxn
1423
104k
                        [i][MAX_NUM_INTRA_MODES_PER_TU_DISTRIBUTION_IN_XS25] = 255;
1424
104k
                }
1425
26.1k
            }
1426
1427
33.6k
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu
1428
33.6k
                [MAX_NUM_INTRA_MODES_PER_TU_DISTRIBUTION_IN_XS25] = 255;
1429
33.6k
#endif
1430
1431
#if FORCE_NXN_MODE_BASED_ON_OL_IPE
1432
            if((i4_quality_preset == IHEVCE_QUALITY_P6) && (i1_slice_type != ISLICE))
1433
            {
1434
                /*Evaluate nxn mode for 8x8 if ol ipe wins for nxn over cu=tu and cu=4tu.*/
1435
                /*Disbale CU=TU and CU=4TU modes */
1436
                if(ps_8x8_ipe_analyze->b1_enable_nxn == 1)
1437
                {
1438
                    ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu[0] = 255;
1439
                    ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1440
                    ps_cu_intra_cand->au1_intra_luma_modes_nxn[0][1] = 255;
1441
                    ps_cu_intra_cand->au1_intra_luma_modes_nxn[1][1] = 255;
1442
                    ps_cu_intra_cand->au1_intra_luma_modes_nxn[2][1] = 255;
1443
                    ps_cu_intra_cand->au1_intra_luma_modes_nxn[3][1] = 255;
1444
                }
1445
            }
1446
#endif
1447
1448
33.6k
            break;
1449
0
        }
1450
42.9k
        }
1451
42.9k
    }
1452
101k
    else
1453
101k
    {
1454
101k
        switch(ps_cu_tree_data->u1_cu_size)
1455
101k
        {
1456
497
        case 64:
1457
497
        {
1458
497
            memcpy(
1459
497
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1460
497
                ps_ipe_data->au1_best_modes_32x32_tu,
1461
497
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1462
1463
497
            ps_cu_intra_cand->b1_eval_tx_cusize = 0;
1464
497
            ps_cu_intra_cand->b1_eval_tx_cusize_by2 = 1;
1465
497
            ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu[0] = 255;
1466
1467
497
            break;
1468
0
        }
1469
3.96k
        case 32:
1470
3.96k
        {
1471
3.96k
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1472
1473
3.96k
            memcpy(
1474
3.96k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1475
3.96k
                ps_32x32_ipe_analyze->au1_best_modes_32x32_tu,
1476
3.96k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1477
1478
3.96k
            memcpy(
1479
3.96k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1480
3.96k
                ps_32x32_ipe_analyze->au1_best_modes_16x16_tu,
1481
3.96k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1482
1483
3.96k
            break;
1484
0
        }
1485
13.4k
        case 16:
1486
13.4k
        {
1487
            /* Copy best 16x16 CU modes */
1488
13.4k
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1489
1490
13.4k
            intra16_analyse_t *ps_16x16_ipe_analyze =
1491
13.4k
                &ps_32x32_ipe_analyze->as_intra16_analyse[i4_16x16_id];
1492
1493
13.4k
            memcpy(
1494
13.4k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1495
13.4k
                ps_16x16_ipe_analyze->au1_best_modes_16x16_tu,
1496
13.4k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1497
1498
13.4k
            memcpy(
1499
13.4k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1500
13.4k
                ps_16x16_ipe_analyze->au1_best_modes_8x8_tu,
1501
13.4k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1502
1503
13.4k
            break;
1504
0
        }
1505
83.1k
        case 8:
1506
83.1k
        {
1507
83.1k
            WORD32 i;
1508
1509
83.1k
            intra32_analyse_t *ps_32x32_ipe_analyze = &ps_ipe_data->as_intra32_analyse[i4_32x32_id];
1510
1511
83.1k
            intra16_analyse_t *ps_16x16_ipe_analyze =
1512
83.1k
                &ps_32x32_ipe_analyze->as_intra16_analyse[i4_16x16_id];
1513
1514
83.1k
            intra8_analyse_t *ps_8x8_ipe_analyze =
1515
83.1k
                &ps_16x16_ipe_analyze->as_intra8_analyse[i4_8x8_id];
1516
1517
83.1k
            memcpy(
1518
83.1k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu,
1519
83.1k
                ps_8x8_ipe_analyze->au1_best_modes_8x8_tu,
1520
83.1k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1521
1522
83.1k
            memcpy(
1523
83.1k
                ps_cu_intra_cand->au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2,
1524
83.1k
                ps_8x8_ipe_analyze->au1_best_modes_4x4_tu,
1525
83.1k
                (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1526
1527
415k
            for(i = 0; i < 4; i++)
1528
332k
            {
1529
332k
                memcpy(
1530
332k
                    ps_cu_intra_cand->au1_intra_luma_modes_nxn[i],
1531
332k
                    ps_8x8_ipe_analyze->au1_4x4_best_modes[i],
1532
332k
                    (NUM_BEST_MODES + 1) * sizeof(UWORD8));
1533
1534
332k
                ps_cu_intra_cand->au1_intra_luma_modes_nxn[i][MAX_INTRA_CU_CANDIDATES] = 255;
1535
332k
            }
1536
1537
83.1k
            break;
1538
0
        }
1539
101k
        }
1540
101k
    }
1541
327k
}
1542
/**
1543
******************************************************************************
1544
* \if Function name : ihevce_compute_rdo \endif
1545
*
1546
* \brief
1547
*    Coding Unit mode decide function. Performs RD opt and decides the best mode
1548
*
1549
* \param[in] pv_ctxt : pointer to enc_loop module
1550
* \param[in] ps_cu_prms  : pointer to coding unit params (position, buffer pointers)
1551
* \param[in] ps_cu_analyse : pointer to cu analyse
1552
* \param[out] ps_cu_final : pointer to cu final
1553
* \param[out] pu1_ecd_data :pointer to store coeff data for ECD
1554
* \param[out]ps_row_col_pu; colocated pu buffer pointer
1555
* \param[out]pu1_row_pu_map; colocated pu map buffer pointer
1556
* \param[in]col_start_pu_idx : pu index start value
1557
*
1558
* \return
1559
*    None
1560
*
1561
*
1562
* \author
1563
*  Ittiam
1564
*
1565
*****************************************************************************
1566
*/
1567
LWORD64 ihevce_compute_rdo(
1568
    ihevce_enc_loop_ctxt_t *ps_ctxt,
1569
    enc_loop_cu_prms_t *ps_cu_prms,
1570
    cur_ctb_cu_tree_t *ps_cu_tree_analyse,
1571
    ipe_l0_ctb_analyse_for_me_t *ps_cur_ipe_ctb,
1572
    me_ctb_data_t *ps_cu_me_data,
1573
    pu_col_mv_t *ps_col_pu,
1574
    final_mode_state_t *ps_final_mode_state,
1575
    UWORD8 *pu1_col_pu_map,
1576
    UWORD8 *pu1_ecd_data,
1577
    WORD32 col_start_pu_idx,
1578
    WORD32 i4_ctb_x_off,
1579
    WORD32 i4_ctb_y_off)
1580
345k
{
1581
    /* Populate the rdo candiates to the structure */
1582
345k
    cu_analyse_t s_cu_analyse;
1583
345k
    LWORD64 rdopt_best_cost;
1584
    /* Populate candidates of child nodes to CU analyse struct for further evaluation */
1585
345k
    cu_analyse_t *ps_cu_analyse;
1586
345k
    WORD32 curr_cu_pos_in_row;
1587
345k
    WORD32 cu_top_right_offset, cu_top_right_dep_pos;
1588
345k
    WORD32 is_first_cu_in_ctb, is_ctb_level_quant_rounding, is_nctb_level_quant_rounding;
1589
1590
345k
    WORD32 cu_pos_x = ps_cu_tree_analyse->b3_cu_pos_x;
1591
345k
    WORD32 cu_pos_y = ps_cu_tree_analyse->b3_cu_pos_y;
1592
1593
    /*Derive the indices of 32*32, 16*16 and 8*8 blocks*/
1594
345k
    WORD32 i4_32x32_id = ((cu_pos_x & 4) >> 2) + ((cu_pos_y & 4) >> 1);
1595
1596
345k
    WORD32 i4_16x16_id = ((cu_pos_x & 2) >> 1) + ((cu_pos_y & 2));
1597
1598
345k
    WORD32 i4_8x8_id = (cu_pos_x & 1) + ((cu_pos_y & 1) << 1);
1599
345k
    if(i4_ctb_y_off == 0)
1600
175k
    {
1601
        /* No wait for 1st row */
1602
175k
        cu_top_right_offset = -(MAX_CTB_SIZE);
1603
175k
        {
1604
175k
            ihevce_tile_params_t *ps_col_tile_params =
1605
175k
                ((ihevce_tile_params_t *)ps_ctxt->pv_tile_params_base + ps_ctxt->i4_tile_col_idx);
1606
1607
175k
            cu_top_right_offset = -(ps_col_tile_params->i4_first_sample_x + (MAX_CTB_SIZE));
1608
175k
        }
1609
1610
175k
        cu_top_right_dep_pos = 0;
1611
175k
    }
1612
169k
    else
1613
169k
    {
1614
169k
        cu_top_right_offset = ps_cu_tree_analyse->u1_cu_size << 1;
1615
169k
        cu_top_right_dep_pos = (i4_ctb_y_off >> 6) - 1;
1616
169k
    }
1617
345k
    ps_cu_analyse = &s_cu_analyse;
1618
1619
345k
    ps_cu_analyse->b3_cu_pos_x = cu_pos_x;
1620
345k
    ps_cu_analyse->b3_cu_pos_y = cu_pos_y;
1621
345k
    ps_cu_analyse->u1_cu_size = ps_cu_tree_analyse->u1_cu_size;
1622
1623
    /* Default initializations */
1624
345k
    ps_cu_analyse->u1_num_intra_rdopt_cands = MAX_INTRA_CU_CANDIDATES;
1625
345k
    ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_nxn[0][0] = 255;
1626
345k
    ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu[0] = 255;
1627
345k
    ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1628
1629
345k
    ps_cu_analyse->s_cu_intra_cand.b1_eval_tx_cusize = 1;
1630
345k
    ps_cu_analyse->s_cu_intra_cand.b1_eval_tx_cusize_by2 = 1;
1631
1632
345k
    switch(ps_cu_tree_analyse->u1_cu_size)
1633
345k
    {
1634
2.23k
    case 64:
1635
2.23k
    {
1636
2.23k
        memcpy(
1637
2.23k
            ps_cu_analyse[0].i4_act_factor,
1638
2.23k
            ps_cur_ipe_ctb->i4_64x64_act_factor,
1639
2.23k
            4 * 2 * sizeof(WORD32));
1640
1641
2.23k
        ps_cu_analyse[0].s_cu_intra_cand.b1_eval_tx_cusize = 0;
1642
2.23k
        ps_cu_analyse[0].s_cu_intra_cand.b1_eval_tx_cusize_by2 = 1;
1643
2.23k
        ps_cu_analyse[0].s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu[0] = 255;
1644
1645
2.23k
        break;
1646
0
    }
1647
18.4k
    case 32:
1648
18.4k
    {
1649
18.4k
        memcpy(
1650
18.4k
            ps_cu_analyse[0].i4_act_factor,
1651
18.4k
            ps_cur_ipe_ctb->i4_32x32_act_factor[i4_32x32_id],
1652
18.4k
            3 * 2 * sizeof(WORD32));
1653
1654
18.4k
        break;
1655
0
    }
1656
70.4k
    case 16:
1657
70.4k
    {
1658
70.4k
        memcpy(
1659
70.4k
            ps_cu_analyse[0].i4_act_factor,
1660
70.4k
            ps_cur_ipe_ctb->i4_16x16_act_factor[(i4_32x32_id << 2) + i4_16x16_id],
1661
70.4k
            2 * 2 * sizeof(WORD32));
1662
1663
70.4k
        break;
1664
0
    }
1665
254k
    case 8:
1666
254k
    {
1667
254k
        memcpy(
1668
254k
            ps_cu_analyse[0].i4_act_factor,
1669
254k
            ps_cur_ipe_ctb->i4_16x16_act_factor[(i4_32x32_id << 2) + i4_16x16_id],
1670
254k
            2 * 2 * sizeof(WORD32));
1671
1672
254k
        break;
1673
0
    }
1674
345k
    }
1675
1676
    /* Populate the me data in cu_analyse struct */
1677
    /* For CU size 32 and 64, add me data to array of cu analyse struct */
1678
345k
    if(ISLICE != ps_ctxt->i1_slice_type)
1679
169k
    {
1680
169k
        if((ps_cu_tree_analyse->u1_cu_size >= 32) && (ps_cu_tree_analyse->u1_inter_eval_enable))
1681
10.9k
        {
1682
10.9k
            if(32 == ps_cu_tree_analyse->u1_cu_size)
1683
10.3k
            {
1684
10.3k
                ihevce_populate_cu_struct(
1685
10.3k
                    ps_ctxt,
1686
10.3k
                    ps_cur_ipe_ctb,
1687
10.3k
                    ps_cu_tree_analyse,
1688
10.3k
                    ps_cu_me_data->as_32x32_block_data[i4_32x32_id].as_best_results,
1689
10.3k
                    ps_cu_analyse,
1690
10.3k
                    i4_32x32_id,
1691
#if DISABLE_INTRA_WHEN_NOISY && USE_NOISE_TERM_IN_ENC_LOOP
1692
                    ps_cu_prms->u1_is_cu_noisy,
1693
#endif
1694
10.3k
                    ps_cu_me_data->as_32x32_block_data[i4_32x32_id].num_best_results);
1695
10.3k
            }
1696
637
            else
1697
637
            {
1698
637
                ihevce_populate_cu_struct(
1699
637
                    ps_ctxt,
1700
637
                    ps_cur_ipe_ctb,
1701
637
                    ps_cu_tree_analyse,
1702
637
                    ps_cu_me_data->s_64x64_block_data.as_best_results,
1703
637
                    ps_cu_analyse,
1704
637
                    i4_32x32_id,
1705
#if DISABLE_INTRA_WHEN_NOISY && USE_NOISE_TERM_IN_ENC_LOOP
1706
                    ps_cu_prms->u1_is_cu_noisy,
1707
#endif
1708
637
                    ps_cu_me_data->s_64x64_block_data.num_best_results);
1709
637
            }
1710
10.9k
        }
1711
158k
        else if(ps_cu_tree_analyse->u1_cu_size < 32)
1712
158k
        {
1713
158k
            i4_8x8_id += (i4_32x32_id << 4) + (i4_16x16_id << 2);
1714
158k
            i4_16x16_id += (i4_32x32_id << 2);
1715
1716
158k
            if(16 == ps_cu_tree_analyse->u1_cu_size)
1717
42.0k
            {
1718
42.0k
                block_data_16x16_t *ps_data = &ps_cu_me_data->as_block_data[i4_16x16_id];
1719
1720
42.0k
                if(ps_cu_tree_analyse->u1_inter_eval_enable)
1721
42.0k
                {
1722
42.0k
                    ihevce_populate_cu_struct(
1723
42.0k
                        ps_ctxt,
1724
42.0k
                        ps_cur_ipe_ctb,
1725
42.0k
                        ps_cu_tree_analyse,
1726
42.0k
                        ps_data->as_best_results,
1727
42.0k
                        ps_cu_analyse,
1728
42.0k
                        i4_32x32_id,
1729
#if DISABLE_INTRA_WHEN_NOISY && USE_NOISE_TERM_IN_ENC_LOOP
1730
                        ps_cu_prms->u1_is_cu_noisy,
1731
#endif
1732
42.0k
                        ps_data->num_best_results);
1733
42.0k
                }
1734
0
                else
1735
0
                {
1736
0
                    ps_cu_analyse->u1_num_inter_cands = 0;
1737
0
                    ps_cu_analyse->u1_best_is_intra = 1;
1738
0
                }
1739
42.0k
            }
1740
116k
            else /* If CU size is 8 */
1741
116k
            {
1742
116k
                block_data_8x8_t *ps_data = &ps_cu_me_data->as_8x8_block_data[i4_8x8_id];
1743
1744
116k
                if(ps_cu_tree_analyse->u1_inter_eval_enable)
1745
116k
                {
1746
116k
                    ihevce_populate_cu_struct(
1747
116k
                        ps_ctxt,
1748
116k
                        ps_cur_ipe_ctb,
1749
116k
                        ps_cu_tree_analyse,
1750
116k
                        ps_data->as_best_results,
1751
116k
                        ps_cu_analyse,
1752
116k
                        i4_32x32_id,
1753
#if DISABLE_INTRA_WHEN_NOISY && USE_NOISE_TERM_IN_ENC_LOOP
1754
                        ps_cu_prms->u1_is_cu_noisy,
1755
#endif
1756
116k
                        ps_data->num_best_results);
1757
116k
                }
1758
0
                else
1759
0
                {
1760
0
                    ps_cu_analyse->u1_num_inter_cands = 0;
1761
0
                    ps_cu_analyse->u1_best_is_intra = 1;
1762
0
                }
1763
116k
            }
1764
158k
        }
1765
410
        else
1766
410
        {
1767
410
            ps_cu_analyse->u1_num_inter_cands = 0;
1768
410
            ps_cu_analyse->u1_best_is_intra = 1;
1769
410
        }
1770
169k
    }
1771
176k
    else
1772
176k
    {
1773
176k
        ps_cu_analyse->u1_num_inter_cands = 0;
1774
176k
        ps_cu_analyse->u1_best_is_intra = 1;
1775
176k
    }
1776
1777
345k
    if(!ps_ctxt->i1_cu_qp_delta_enable)
1778
203k
    {
1779
203k
        ps_cu_analyse->i1_cu_qp = ps_ctxt->i4_frame_qp;
1780
1781
        /*cu qp must be populated in cu_analyse_t struct*/
1782
203k
        ps_ctxt->i4_cu_qp = ps_cu_analyse->i1_cu_qp;
1783
203k
    }
1784
142k
    else
1785
142k
    {
1786
142k
        ASSERT(ps_cu_analyse->i4_act_factor[0] > 0);
1787
142k
        ASSERT(
1788
142k
            ((ps_cu_analyse->i4_act_factor[1] > 0) && (ps_cu_analyse->u1_cu_size != 8)) ||
1789
142k
            ((ps_cu_analyse->u1_cu_size == 8)));
1790
142k
        ASSERT(
1791
142k
            ((ps_cu_analyse->i4_act_factor[2] > 0) && (ps_cu_analyse->u1_cu_size == 32)) ||
1792
142k
            ((ps_cu_analyse->u1_cu_size != 32)));
1793
142k
    }
1794
1795
345k
    if(ps_ctxt->u1_disable_intra_eval)
1796
324
    {
1797
        /* rdopt evaluation of intra disabled as inter is clear winner */
1798
324
        ps_cu_analyse->u1_num_intra_rdopt_cands = 0;
1799
1800
        /* all the modes invalidated */
1801
324
        ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu[0] = 255;
1802
324
        ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1803
324
        ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_nxn[0][0] = 255;
1804
324
        ps_cu_analyse->u1_chroma_intra_pred_mode = 255;
1805
1806
        /* no intra candt to verify */
1807
324
        ps_cu_analyse->s_cu_intra_cand.b6_num_intra_cands = 0;
1808
324
    }
1809
1810
345k
#if DISABLE_L2_IPE_IN_PB_L1_IN_B
1811
345k
    if((ps_ctxt->i4_quality_preset == IHEVCE_QUALITY_P6) && (ps_cu_analyse->u1_cu_size == 32) &&
1812
2.45k
       (ps_ctxt->i1_slice_type != ISLICE))
1813
1.75k
    {
1814
        /* rdopt evaluation of intra disabled as inter is clear winner */
1815
1.75k
        ps_cu_analyse->u1_num_intra_rdopt_cands = 0;
1816
1817
        /* all the modes invalidated */
1818
1.75k
        ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu[0] = 255;
1819
1.75k
        ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_2nx2n_tu_eq_cu_by_2[0] = 255;
1820
1.75k
        ps_cu_analyse->s_cu_intra_cand.au1_intra_luma_modes_nxn[0][0] = 255;
1821
1.75k
        ps_cu_analyse->u1_chroma_intra_pred_mode = 255;
1822
1823
        /* no intra candt to verify */
1824
1.75k
        ps_cu_analyse->s_cu_intra_cand.b6_num_intra_cands = 0;
1825
1.75k
    }
1826
345k
#endif
1827
1828
345k
    if(DISABLE_INTRA_WHEN_NOISY && ps_cu_prms->u1_is_cu_noisy)
1829
0
    {
1830
0
        ps_cu_analyse->u1_num_intra_rdopt_cands = 0;
1831
0
    }
1832
1833
345k
    if(ps_cu_analyse->u1_num_intra_rdopt_cands || ps_cu_tree_analyse->u1_intra_eval_enable)
1834
327k
    {
1835
327k
        ihevce_intra_mode_populator(
1836
327k
            &ps_cu_analyse->s_cu_intra_cand,
1837
327k
            ps_cur_ipe_ctb,
1838
327k
            ps_cu_tree_analyse,
1839
327k
            ps_ctxt->i1_slice_type,
1840
327k
            ps_ctxt->i4_quality_preset);
1841
1842
327k
        ps_cu_analyse->u1_num_intra_rdopt_cands = 1;
1843
327k
    }
1844
1845
345k
    ASSERT(!!ps_cu_analyse->u1_num_intra_rdopt_cands || ps_cu_analyse->u1_num_inter_cands);
1846
1847
345k
    if(ps_ctxt->u1_use_top_at_ctb_boundary)
1848
183k
    {
1849
        /* Wait till top data is ready          */
1850
        /* Currently checking till top right CU */
1851
183k
        curr_cu_pos_in_row = i4_ctb_x_off + (ps_cu_analyse->b3_cu_pos_x << 3);
1852
1853
183k
        if(0 == ps_cu_analyse->b3_cu_pos_y)
1854
39.4k
        {
1855
39.4k
            ihevce_dmgr_chk_row_row_sync(
1856
39.4k
                ps_ctxt->pv_dep_mngr_enc_loop_cu_top_right,
1857
39.4k
                curr_cu_pos_in_row,
1858
39.4k
                cu_top_right_offset,
1859
39.4k
                cu_top_right_dep_pos,
1860
39.4k
                ps_ctxt->i4_tile_col_idx, /* Col Tile No. */
1861
39.4k
                ps_ctxt->thrd_id);
1862
39.4k
        }
1863
183k
    }
1864
1865
345k
#if !DISABLE_TOP_SYNC
1866
345k
    {
1867
345k
        if(0 == ps_cu_analyse->b3_cu_pos_y)
1868
75.1k
        {
1869
75.1k
            if((0 == i4_ctb_x_off) && (i4_ctb_y_off != 0))
1870
17.9k
            {
1871
17.9k
                if(ps_cu_analyse->b3_cu_pos_x == 0)
1872
3.70k
                {
1873
3.70k
                    if(!ps_ctxt->u1_use_top_at_ctb_boundary)
1874
1.47k
                    {
1875
                        /* Wait till top data is ready          */
1876
                        /* Currently checking till top right CU */
1877
1.47k
                        curr_cu_pos_in_row = i4_ctb_x_off + (ps_cu_analyse->b3_cu_pos_x << 3);
1878
1879
1.47k
                        if(0 == ps_cu_analyse->b3_cu_pos_y)
1880
1.47k
                        {
1881
1.47k
                            ihevce_dmgr_chk_row_row_sync(
1882
1.47k
                                ps_ctxt->pv_dep_mngr_enc_loop_cu_top_right,
1883
1.47k
                                curr_cu_pos_in_row,
1884
1.47k
                                cu_top_right_offset,
1885
1.47k
                                cu_top_right_dep_pos,
1886
1.47k
                                ps_ctxt->i4_tile_col_idx, /* Col Tile No. */
1887
1.47k
                                ps_ctxt->thrd_id);
1888
1.47k
                        }
1889
1.47k
                    }
1890
1891
3.70k
                    ihevce_entropy_rdo_copy_states(
1892
3.70k
                        &ps_ctxt->s_rdopt_entropy_ctxt,
1893
3.70k
                        ps_ctxt->pu1_top_rt_cabac_state,
1894
3.70k
                        UPDATE_ENT_SYNC_RDO_STATE);
1895
3.70k
                }
1896
17.9k
            }
1897
75.1k
        }
1898
345k
    }
1899
#else
1900
    {
1901
        if((0 == ps_cu_analyse->b3_cu_pos_y) && (IHEVCE_QUALITY_P6 != ps_ctxt->i4_quality_preset))
1902
        {
1903
            if((0 == i4_ctb_x_off) && (i4_ctb_y_off != 0))
1904
            {
1905
                if(ps_cu_analyse->b3_cu_pos_x == 0)
1906
                {
1907
                    if(!ps_ctxt->u1_use_top_at_ctb_boundary)
1908
                    {
1909
                        /* Wait till top data is ready          */
1910
                        /* Currently checking till top right CU */
1911
                        curr_cu_pos_in_row = i4_ctb_x_off + (ps_cu_analyse->b3_cu_pos_x << 3);
1912
1913
                        if(0 == ps_cu_analyse->b3_cu_pos_y)
1914
                        {
1915
                            ihevce_dmgr_chk_row_row_sync(
1916
                                ps_ctxt->pv_dep_mngr_enc_loop_cu_top_right,
1917
                                curr_cu_pos_in_row,
1918
                                cu_top_right_offset,
1919
                                cu_top_right_dep_pos,
1920
                                ps_ctxt->i4_tile_col_idx, /* Col Tile No. */
1921
                                ps_ctxt->thrd_id);
1922
                        }
1923
                    }
1924
1925
                    ihevce_entropy_rdo_copy_states(
1926
                        &ps_ctxt->s_rdopt_entropy_ctxt,
1927
                        ps_ctxt->pu1_top_rt_cabac_state,
1928
                        UPDATE_ENT_SYNC_RDO_STATE);
1929
                }
1930
            }
1931
        }
1932
        else if((0 == ps_cu_analyse->b3_cu_pos_y) && (IHEVCE_QUALITY_P6 == ps_ctxt->i4_quality_preset))
1933
        {
1934
            UWORD8 u1_cabac_init_idc;
1935
            WORD8 i1_cabac_init_flag =
1936
                ps_ctxt->s_rdopt_entropy_ctxt.as_cu_entropy_ctxt->ps_slice_hdr->i1_cabac_init_flag;
1937
1938
            if(ps_ctxt->i1_slice_type == ISLICE)
1939
            {
1940
                u1_cabac_init_idc = 0;
1941
            }
1942
            else if(ps_ctxt->i1_slice_type == PSLICE)
1943
            {
1944
                u1_cabac_init_idc = i1_cabac_init_flag ? 2 : 1;
1945
            }
1946
            else
1947
            {
1948
                u1_cabac_init_idc = i1_cabac_init_flag ? 1 : 2;
1949
            }
1950
1951
            ihevce_entropy_rdo_copy_states(
1952
                &ps_ctxt->s_rdopt_entropy_ctxt,
1953
                (UWORD8 *)gau1_ihevc_cab_ctxts[u1_cabac_init_idc][ps_ctxt->i4_frame_qp],
1954
                UPDATE_ENT_SYNC_RDO_STATE);
1955
        }
1956
    }
1957
#endif
1958
1959
    /*2 Multi- dimensinal array based on trans size  of rounding factor to be added here */
1960
    /* arrays are for rounding factor corr. to 0-1 decision and 1-2 decision */
1961
    /* Currently the complete array will contain only single value*/
1962
    /*The rounding factor is calculated with the formula
1963
    Deadzone val = (((R1 - R0) * (2^(-8/3)) * lamMod) + 1)/2
1964
    rounding factor = (1 - DeadZone Val)
1965
1966
    Assumption: Cabac states of All the sub-blocks in the TU are considered independent
1967
    */
1968
1969
    /*As long as coef level rdoq is enabled perform this operation */
1970
345k
    is_first_cu_in_ctb = ((0 == ps_cu_analyse->b3_cu_pos_x) && (0 == ps_cu_analyse->b3_cu_pos_y));
1971
345k
    is_ctb_level_quant_rounding =
1972
345k
        ((ps_ctxt->i4_quant_rounding_level == CTB_LEVEL_QUANT_ROUNDING) &&
1973
0
         (1 == is_first_cu_in_ctb));
1974
345k
    is_nctb_level_quant_rounding =
1975
345k
        ((ps_ctxt->i4_quant_rounding_level == NCTB_LEVEL_QUANT_ROUNDING) &&
1976
0
         (1 == is_first_cu_in_ctb) && (((i4_ctb_x_off >> 6) % NUM_CTB_QUANT_ROUNDING) == 0));
1977
1978
345k
    if((ps_ctxt->i4_quant_rounding_level == CU_LEVEL_QUANT_ROUNDING) ||
1979
161k
       (ps_ctxt->i4_quant_rounding_level == TU_LEVEL_QUANT_ROUNDING) ||
1980
161k
       (1 == is_ctb_level_quant_rounding) || (1 == is_nctb_level_quant_rounding))
1981
183k
    {
1982
183k
        double i4_lamda_modifier, i4_lamda_modifier_uv;
1983
183k
        WORD32 trans_size, trans_size_cr;
1984
183k
        trans_size = ps_cu_analyse->u1_cu_size;
1985
1986
183k
        if((1 == is_ctb_level_quant_rounding) || (1 == is_nctb_level_quant_rounding))
1987
0
        {
1988
0
            trans_size = MAX_TU_SIZE;
1989
0
        }
1990
183k
        else
1991
183k
        {
1992
183k
            if(ps_cu_analyse->u1_cu_size == 64)
1993
1.30k
            {
1994
1.30k
                trans_size >>= 1;
1995
1.30k
            }
1996
183k
        }
1997
1998
        /*Chroma trans size = half of luma trans size */
1999
183k
        trans_size_cr = trans_size >> 1;
2000
2001
183k
        if((BSLICE == ps_ctxt->i1_slice_type) && (ps_ctxt->i4_temporal_layer_id))
2002
4.17k
        {
2003
4.17k
            i4_lamda_modifier = ps_ctxt->i4_lamda_modifier *
2004
4.17k
                                CLIP3((((double)(ps_ctxt->i4_cu_qp - 12)) / 6.0), 2.00, 4.00);
2005
4.17k
            i4_lamda_modifier_uv =
2006
4.17k
                ps_ctxt->i4_uv_lamda_modifier *
2007
4.17k
                CLIP3((((double)(ps_ctxt->i4_chrm_cu_qp - 12)) / 6.0), 2.00, 4.00);
2008
4.17k
        }
2009
179k
        else
2010
179k
        {
2011
179k
            i4_lamda_modifier = ps_ctxt->i4_lamda_modifier;
2012
179k
            i4_lamda_modifier_uv = ps_ctxt->i4_uv_lamda_modifier;
2013
179k
        }
2014
183k
        if(ps_ctxt->i4_use_const_lamda_modifier)
2015
0
        {
2016
0
            if(ISLICE == ps_ctxt->i1_slice_type)
2017
0
            {
2018
0
                i4_lamda_modifier = ps_ctxt->f_i_pic_lamda_modifier;
2019
0
                i4_lamda_modifier_uv = ps_ctxt->f_i_pic_lamda_modifier;
2020
0
            }
2021
0
            else
2022
0
            {
2023
0
                i4_lamda_modifier = CONST_LAMDA_MOD_VAL;
2024
0
                i4_lamda_modifier_uv = CONST_LAMDA_MOD_VAL;
2025
0
            }
2026
0
        }
2027
2028
183k
        do
2029
435k
        {
2030
435k
            memset(
2031
435k
                ps_ctxt->pi4_quant_round_factor_cu_ctb_0_1[trans_size >> 3],
2032
435k
                0,
2033
435k
                trans_size * trans_size * sizeof(WORD32));
2034
435k
            memset(
2035
435k
                ps_ctxt->pi4_quant_round_factor_cu_ctb_1_2[trans_size >> 3],
2036
435k
                0,
2037
435k
                trans_size * trans_size * sizeof(WORD32));
2038
2039
            /*ps_ctxt->i4_quant_rnd_factor[intra_flag], is currently not used */
2040
435k
            ihevce_quant_rounding_factor_gen(
2041
435k
                trans_size,
2042
435k
                1,  //is_luma = 1
2043
435k
                &ps_ctxt->s_rdopt_entropy_ctxt,
2044
435k
                ps_ctxt->pi4_quant_round_factor_cu_ctb_0_1[trans_size >> 3],
2045
435k
                ps_ctxt->pi4_quant_round_factor_cu_ctb_1_2[trans_size >> 3],
2046
435k
                i4_lamda_modifier,
2047
435k
                0);  //is_tu_level_quant rounding = 0
2048
2049
435k
            trans_size = trans_size >> 1;
2050
2051
435k
        } while(trans_size >= 4);
2052
2053
        /*CHROMA Quant Rounding is to be enabled with CU/TU/CTB/NCTB Luma rounding */
2054
        /*Please note chroma is calcualted only for 1st TU at TU level Rounding */
2055
183k
        if(ps_ctxt->i4_chroma_quant_rounding_level == CHROMA_QUANT_ROUNDING)
2056
183k
        {
2057
183k
            do
2058
251k
            {
2059
251k
                memset(
2060
251k
                    ps_ctxt->pi4_quant_round_factor_cr_cu_ctb_0_1[trans_size_cr >> 3],
2061
251k
                    0,
2062
251k
                    trans_size_cr * trans_size_cr * sizeof(WORD32));
2063
251k
                memset(
2064
251k
                    ps_ctxt->pi4_quant_round_factor_cr_cu_ctb_1_2[trans_size_cr >> 3],
2065
251k
                    0,
2066
251k
                    trans_size_cr * trans_size_cr * sizeof(WORD32));
2067
2068
251k
                ihevce_quant_rounding_factor_gen(
2069
251k
                    trans_size_cr,
2070
251k
                    0,  //is_luma = 0
2071
251k
                    &ps_ctxt->s_rdopt_entropy_ctxt,
2072
251k
                    ps_ctxt->pi4_quant_round_factor_cr_cu_ctb_0_1[trans_size_cr >> 3],
2073
251k
                    ps_ctxt->pi4_quant_round_factor_cr_cu_ctb_1_2[trans_size_cr >> 3],
2074
251k
                    i4_lamda_modifier_uv,
2075
251k
                    0);  //is_tu_level_quant rounding = 0
2076
2077
251k
                trans_size_cr = trans_size_cr >> 1;
2078
2079
251k
            } while(trans_size_cr >= 4);
2080
183k
        }
2081
183k
    }
2082
2083
#if DISABLE_INTRAS_IN_BPIC
2084
    if((ps_ctxt->i1_slice_type == BSLICE) && (ps_cu_analyse->u1_num_inter_cands))
2085
    {
2086
        ps_cu_analyse->u1_num_intra_rdopt_cands = 0;
2087
    }
2088
#endif
2089
2090
345k
    rdopt_best_cost = ihevce_cu_mode_decide(
2091
345k
        ps_ctxt,
2092
345k
        ps_cu_prms,
2093
345k
        ps_cu_analyse,
2094
345k
        ps_final_mode_state,
2095
345k
        pu1_ecd_data,
2096
345k
        ps_col_pu,
2097
345k
        pu1_col_pu_map,
2098
345k
        col_start_pu_idx);
2099
2100
345k
    return rdopt_best_cost;
2101
345k
}
2102
2103
/**
2104
******************************************************************************
2105
* \if Function name : ihevce_enc_loop_cu_bot_copy \endif
2106
*
2107
* \brief
2108
*    This function copy the bottom data at CU level to row buffers
2109
*
2110
* \date
2111
*    18/09/2012
2112
*
2113
* \author
2114
*    Ittiam
2115
*
2116
* \return
2117
*
2118
* List of Functions
2119
*
2120
*
2121
******************************************************************************
2122
*/
2123
void ihevce_enc_loop_cu_bot_copy(
2124
    ihevce_enc_loop_ctxt_t *ps_ctxt,
2125
    enc_loop_cu_prms_t *ps_cu_prms,
2126
    ihevce_enc_cu_node_ctxt_t *ps_enc_out_ctxt,
2127
    WORD32 curr_cu_pos_in_row,
2128
    WORD32 curr_cu_pos_in_ctb)
2129
52.5k
{
2130
    /* ---------------------------------------------- */
2131
    /* copy the bottom row  data to the row buffers   */
2132
    /* ---------------------------------------------- */
2133
52.5k
    nbr_4x4_t *ps_top_nbr;
2134
52.5k
    UWORD8 *pu1_buff;
2135
52.5k
    UWORD8 *pu1_luma_top, *pu1_chrm_top;
2136
52.5k
    WORD32 nbr_strd;
2137
2138
52.5k
    WORD32 u1_is_422 = (ps_ctxt->u1_chroma_array_type == 2);
2139
2140
    /* derive the appropraite pointers */
2141
52.5k
    pu1_luma_top = (UWORD8 *)ps_ctxt->pv_bot_row_luma + curr_cu_pos_in_row;
2142
52.5k
    pu1_chrm_top = (UWORD8 *)ps_ctxt->pv_bot_row_chroma + curr_cu_pos_in_row;
2143
52.5k
    ps_top_nbr = ps_ctxt->ps_bot_row_nbr + (curr_cu_pos_in_row >> 2);
2144
52.5k
    nbr_strd = ps_cu_prms->i4_ctb_size >> 2;
2145
2146
    /* copy bottom luma data */
2147
52.5k
    pu1_buff = ps_cu_prms->pu1_luma_recon +
2148
52.5k
               (ps_cu_prms->i4_luma_recon_stride * (ps_cu_prms->i4_ctb_size - 1));
2149
2150
52.5k
    pu1_buff += curr_cu_pos_in_ctb;
2151
2152
52.5k
    memcpy(pu1_luma_top, pu1_buff, ps_enc_out_ctxt->u1_cu_size);
2153
2154
    /* copy bottom chroma data cb and cr pixel interleaved */
2155
52.5k
    pu1_buff = ps_cu_prms->pu1_chrm_recon + (ps_cu_prms->i4_chrm_recon_stride *
2156
52.5k
                                             ((ps_cu_prms->i4_ctb_size >> (0 == u1_is_422)) - 1));
2157
2158
52.5k
    pu1_buff += curr_cu_pos_in_ctb;
2159
2160
52.5k
    memcpy(pu1_chrm_top, pu1_buff, ps_enc_out_ctxt->u1_cu_size);
2161
2162
    /* store the nbr 4x4 data at cu level */
2163
52.5k
    {
2164
52.5k
        nbr_4x4_t *ps_nbr;
2165
2166
        /* copy bottom nbr data */
2167
52.5k
        ps_nbr = &ps_ctxt->as_ctb_nbr_arr[0];
2168
52.5k
        ps_nbr += ((ps_cu_prms->i4_ctb_size >> 2) - 1) * nbr_strd;
2169
2170
52.5k
        ps_nbr += (curr_cu_pos_in_ctb >> 2);
2171
2172
52.5k
        memcpy(ps_top_nbr, ps_nbr, (ps_enc_out_ctxt->u1_cu_size >> 2) * sizeof(nbr_4x4_t));
2173
52.5k
    }
2174
52.5k
    return;
2175
52.5k
}
2176
2177
/**
2178
******************************************************************************
2179
* \if Function name : ihevce_update_final_cu_results \endif
2180
*
2181
* \brief
2182
*
2183
* \return
2184
*    None
2185
*
2186
* \author
2187
*  Ittiam
2188
*
2189
*****************************************************************************
2190
*/
2191
void ihevce_update_final_cu_results(
2192
    ihevce_enc_loop_ctxt_t *ps_ctxt,
2193
    ihevce_enc_cu_node_ctxt_t *ps_enc_out_ctxt,
2194
    enc_loop_cu_prms_t *ps_cu_prms,
2195
    pu_col_mv_t **pps_row_col_pu,
2196
    WORD32 *pi4_col_pu_map_idx,
2197
    cu_final_update_prms *ps_cu_update_prms,
2198
    WORD32 ctb_ctr,
2199
    WORD32 vert_ctb_ctr)
2200
280k
{
2201
280k
    WORD32 curr_cu_pos_in_row;
2202
2203
280k
    cu_enc_loop_out_t *ps_cu_final = *ps_cu_update_prms->pps_cu_final;
2204
280k
    pu_t **pps_row_pu = ps_cu_update_prms->pps_row_pu;
2205
280k
    tu_enc_loop_out_t **pps_row_tu = ps_cu_update_prms->pps_row_tu;
2206
280k
    UWORD8 **ppu1_row_ecd_data = ps_cu_update_prms->ppu1_row_ecd_data;
2207
280k
    WORD32 *pi4_num_pus_in_ctb = ps_cu_update_prms->pi4_num_pus_in_ctb;
2208
280k
    UWORD32 u4_cu_size = ps_enc_out_ctxt->u1_cu_size;
2209
280k
    ps_cu_final->b3_cu_pos_x = ps_enc_out_ctxt->b3_cu_pos_x;
2210
280k
    ps_cu_final->b3_cu_pos_y = ps_enc_out_ctxt->b3_cu_pos_y;
2211
2212
280k
    ps_cu_final->b4_cu_size = ps_enc_out_ctxt->u1_cu_size >> 3;
2213
2214
    /* store the current pu and tu pointes */
2215
280k
    ps_cu_final->ps_pu = *pps_row_pu;
2216
280k
    ps_cu_final->ps_enc_tu = *pps_row_tu;
2217
280k
    curr_cu_pos_in_row = ctb_ctr * ps_cu_prms->i4_ctb_size + (ps_cu_final->b3_cu_pos_x << 3);
2218
2219
280k
    ihevce_store_cu_final(ps_ctxt, ps_cu_final, *ppu1_row_ecd_data, ps_enc_out_ctxt, ps_cu_prms);
2220
2221
280k
    if(NULL != pps_row_col_pu)
2222
188k
    {
2223
188k
        (*pps_row_col_pu) += ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2224
188k
    }
2225
280k
    if(NULL != pi4_col_pu_map_idx)
2226
188k
    {
2227
188k
        (*pi4_col_pu_map_idx) += ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2228
188k
    }
2229
280k
    (*pi4_num_pus_in_ctb) += ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2230
280k
    (*pps_row_tu) += ps_cu_final->u2_num_tus_in_cu;
2231
280k
    (*pps_row_pu) += ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2232
280k
    (*ppu1_row_ecd_data) += ps_enc_out_ctxt->ps_cu_prms->i4_num_bytes_ecd_data;
2233
2234
280k
    (*ps_cu_update_prms->pps_cu_final)++;
2235
280k
    (*ps_cu_update_prms->pu1_num_cus_in_ctb_out)++;
2236
2237
    /* Updated for each CU in bottom row  of CTB */
2238
280k
    if(((ps_cu_final->b3_cu_pos_y << 3) + u4_cu_size) == ps_ctxt->u4_cur_ctb_ht)
2239
52.5k
    {
2240
        /* copy the bottom data to row buffers */
2241
52.5k
        ((pf_enc_loop_cu_bot_copy)ps_ctxt->pv_enc_loop_cu_bot_copy)(
2242
52.5k
            ps_ctxt,
2243
52.5k
            ps_cu_prms,
2244
52.5k
            ps_enc_out_ctxt,
2245
52.5k
            curr_cu_pos_in_row,
2246
52.5k
            (ps_enc_out_ctxt->b3_cu_pos_x << 3));
2247
2248
        /* Setting Dependency for CU TopRight */
2249
52.5k
        ihevce_dmgr_set_row_row_sync(
2250
52.5k
            ps_ctxt->pv_dep_mngr_enc_loop_cu_top_right,
2251
52.5k
            (curr_cu_pos_in_row + ps_enc_out_ctxt->u1_cu_size),
2252
52.5k
            vert_ctb_ctr,
2253
52.5k
            ps_ctxt->i4_tile_col_idx /* Col Tile No. */);
2254
2255
        /* Setting Dependency for Entropy to consume is made at CTB level */
2256
52.5k
    }
2257
280k
}
2258
2259
/**
2260
******************************************************************************
2261
* \if Function name : ihevce_cu_recurse_decide \endif
2262
*
2263
* \brief
2264
*    Coding Unit mode decide function. Performs RD opt and decides the best mode
2265
*
2266
* \param[in] pv_ctxt : pointer to enc_loop module
2267
* \param[in] ps_cu_prms  : pointer to coding unit params (position, buffer pointers)
2268
* \param[in] ps_cu_analyse : pointer to cu analyse
2269
* \param[out] ps_cu_final : pointer to cu final
2270
* \param[out] pu1_ecd_data :pointer to store coeff data for ECD
2271
* \param[out]ps_row_col_pu; colocated pu buffer pointer
2272
* \param[out]pu1_row_pu_map; colocated pu map buffer pointer
2273
* \param[in]col_start_pu_idx : pu index start value
2274
*
2275
* \return
2276
*    None
2277
*
2278
*
2279
* \author
2280
*  Ittiam
2281
*
2282
*****************************************************************************
2283
*/
2284
WORD32 ihevce_cu_recurse_decide(
2285
    ihevce_enc_loop_ctxt_t *ps_ctxt,
2286
    enc_loop_cu_prms_t *ps_cu_prms,
2287
    cur_ctb_cu_tree_t *ps_cu_tree_analyse,
2288
    cur_ctb_cu_tree_t *ps_cu_tree_analyse_parent,
2289
    ipe_l0_ctb_analyse_for_me_t *ps_cur_ipe_ctb,
2290
    me_ctb_data_t *ps_cu_me_data,
2291
    pu_col_mv_t **pps_col_pu,
2292
    cu_final_update_prms *ps_cu_update_prms,
2293
    UWORD8 *pu1_col_pu_map,
2294
    WORD32 *pi4_col_start_pu_idx,
2295
    WORD32 i4_tree_depth,
2296
    WORD32 i4_ctb_x_off,
2297
    WORD32 i4_ctb_y_off,
2298
    WORD32 cur_ctb_ht)
2299
696k
{
2300
696k
    cur_ctb_cu_tree_t *ps_cu_tree_analyse_child[4];
2301
696k
    final_mode_state_t s_final_mode_state;
2302
2303
696k
    WORD32 i;
2304
696k
    WORD32 child_nodes_null;
2305
696k
    LWORD64 i8_least_child_cost;
2306
2307
696k
    WORD32 num_children_encoded = 0;
2308
2309
    /* Take backup of collocated start PU index for parent node rdo for PQ */
2310
696k
    WORD32 i4_col_pu_idx_bkup = *pi4_col_start_pu_idx;
2311
696k
    pu_col_mv_t *ps_col_mv_bkup = *pps_col_pu;
2312
2313
696k
#if ENABLE_CU_SPLIT_FLAG_RATE_ESTIMATION
2314
696k
    WORD32 x0_frm = i4_ctb_x_off + (ps_cu_tree_analyse->b3_cu_pos_x << 3);
2315
696k
    WORD32 y0_frm = i4_ctb_y_off + (ps_cu_tree_analyse->b3_cu_pos_y << 3);
2316
696k
    WORD32 pic_wd = ps_ctxt->s_sao_ctxt_t.ps_sps->i2_pic_width_in_luma_samples;
2317
696k
    WORD32 pic_ht = ps_ctxt->s_sao_ctxt_t.ps_sps->i2_pic_height_in_luma_samples;
2318
696k
    WORD32 log2_min_cb_size = ps_ctxt->s_sao_ctxt_t.ps_sps->i1_log2_min_coding_block_size;
2319
696k
    WORD32 cu_size = ps_cu_tree_analyse->u1_cu_size;
2320
2321
    /* bits for coding split_cu_flag = 1 */
2322
696k
    WORD32 split_cu1_bits_q12 = 0;
2323
2324
    /* bits for coding split_cu_flag = 0 */
2325
696k
    WORD32 split_cu0_bits_q12 = 0;
2326
696k
#endif
2327
2328
696k
    UWORD8 u1_is_cu_noisy = ps_ctxt->u1_is_stasino_enabled
2329
696k
                                ? ihevce_determine_cu_noise_based_on_8x8Blk_data(
2330
0
                                      ps_cu_prms->pu1_is_8x8Blk_noisy,
2331
0
                                      ((ps_cu_tree_analyse->b3_cu_pos_x << 3) >> 4) << 4,
2332
0
                                      ((ps_cu_tree_analyse->b3_cu_pos_y << 3) >> 4) << 4,
2333
0
                                      MAX(16, ps_cu_tree_analyse->u1_cu_size))
2334
696k
                                : 0;
2335
2336
696k
#if ENABLE_CU_SPLIT_FLAG_RATE_ESTIMATION
2337
696k
    LWORD64 i8_lambda_qf = ps_ctxt->s_sao_ctxt_t.i8_cl_ssd_lambda_qf;
2338
696k
#endif
2339
2340
696k
    (void)ps_cu_tree_analyse_parent;
2341
2342
696k
#if USE_NOISE_TERM_IN_ENC_LOOP && RDOPT_LAMBDA_DISCOUNT_WHEN_NOISY
2343
696k
    if(!ps_ctxt->u1_enable_psyRDOPT && u1_is_cu_noisy)
2344
0
    {
2345
0
        ps_ctxt->i8_cl_ssd_lambda_qf = ps_ctxt->s_sao_ctxt_t.i8_cl_ssd_lambda_qf;
2346
0
        ps_ctxt->i8_cl_ssd_lambda_chroma_qf = ps_ctxt->s_sao_ctxt_t.i8_cl_ssd_lambda_chroma_qf;
2347
0
    }
2348
696k
#endif
2349
2350
696k
    if(u1_is_cu_noisy && !ps_ctxt->u1_enable_psyRDOPT)
2351
0
    {
2352
0
        i8_lambda_qf = ((float)i8_lambda_qf * (100.0f - RDOPT_LAMBDA_DISCOUNT_WHEN_NOISY) / 100.0f);
2353
0
    }
2354
2355
696k
    ps_cu_tree_analyse_child[0] = ps_cu_tree_analyse->ps_child_node_tl;
2356
696k
    ps_cu_tree_analyse_child[1] = ps_cu_tree_analyse->ps_child_node_tr;
2357
696k
    ps_cu_tree_analyse_child[2] = ps_cu_tree_analyse->ps_child_node_bl;
2358
696k
    ps_cu_tree_analyse_child[3] = ps_cu_tree_analyse->ps_child_node_br;
2359
2360
696k
    child_nodes_null =
2361
696k
        ((ps_cu_tree_analyse_child[0] == NULL) + (ps_cu_tree_analyse_child[1] == NULL) +
2362
696k
         (ps_cu_tree_analyse_child[2] == NULL) + (ps_cu_tree_analyse_child[3] == NULL));
2363
2364
696k
#if ENABLE_CU_SPLIT_FLAG_RATE_ESTIMATION
2365
696k
#if !PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS
2366
696k
    if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2367
299k
#endif
2368
299k
    {
2369
        /*----------------------------------------------*/
2370
        /* ---------- CU Depth Bit Estimation --------- */
2371
        /*----------------------------------------------*/
2372
2373
        /* Encode cu split flags based on following conditions; See section 7.3.8*/
2374
299k
        if(((x0_frm + cu_size) <= pic_wd) && ((y0_frm + cu_size) <= pic_ht) &&
2375
193k
           (cu_size > (1 << log2_min_cb_size))) /* &&(ps_entropy_ctxt->i1_ctb_num_pcm_blks == 0)) */
2376
55.8k
        {
2377
55.8k
            WORD32 left_cu_depth = 0;
2378
55.8k
            WORD32 top_cu_depth = 0;
2379
55.8k
            WORD32 pos_x_4x4 = ps_cu_tree_analyse->b3_cu_pos_x << 1;
2380
55.8k
            WORD32 pos_y_4x4 = ps_cu_tree_analyse->b3_cu_pos_y << 1;
2381
55.8k
            WORD32 num_4x4_in_ctb = (ps_cu_prms->i4_ctb_size >> 2);
2382
55.8k
            WORD32 cur_4x4_in_ctb = pos_x_4x4 + (pos_y_4x4 * num_4x4_in_ctb);
2383
55.8k
            UWORD8 u1_split_cu_flag_cab_model;
2384
55.8k
            WORD32 split_cu_ctxt_inc;
2385
2386
            /* Left and Top CU depth is required for cabac context */
2387
2388
            /* CU left */
2389
55.8k
            if(0 == pos_x_4x4)
2390
20.3k
            {
2391
                /* CTB boundary */
2392
20.3k
                if(i4_ctb_x_off)
2393
10.8k
                {
2394
10.8k
                    left_cu_depth = ps_ctxt->as_left_col_nbr[pos_y_4x4].b2_cu_depth;
2395
10.8k
                }
2396
20.3k
            }
2397
35.4k
            else
2398
35.4k
            {
2399
                /* inside CTB */
2400
35.4k
                left_cu_depth = ps_ctxt->as_ctb_nbr_arr[cur_4x4_in_ctb - 1].b2_cu_depth;
2401
35.4k
            }
2402
2403
            /* CU top */
2404
55.8k
            if(0 == pos_y_4x4)
2405
19.9k
            {
2406
                /* CTB boundary */
2407
19.9k
                if(i4_ctb_y_off)
2408
12.1k
                {
2409
                    /* Wait till top cu depth is available */
2410
12.1k
                    ihevce_dmgr_chk_row_row_sync(
2411
12.1k
                        ps_ctxt->pv_dep_mngr_enc_loop_cu_top_right,
2412
12.1k
                        (i4_ctb_x_off) + (pos_x_4x4 << 2),
2413
12.1k
                        4,
2414
12.1k
                        ((i4_ctb_y_off >> 6) - 1),
2415
12.1k
                        ps_ctxt->i4_tile_col_idx, /* Col Tile No. */
2416
12.1k
                        ps_ctxt->thrd_id);
2417
2418
12.1k
                    top_cu_depth =
2419
12.1k
                        ps_ctxt->ps_top_row_nbr[(i4_ctb_x_off >> 2) + pos_x_4x4].b2_cu_depth;
2420
12.1k
                }
2421
19.9k
            }
2422
35.8k
            else
2423
35.8k
            {
2424
                /* inside CTB */
2425
35.8k
                top_cu_depth = ps_ctxt->as_ctb_nbr_arr[cur_4x4_in_ctb - num_4x4_in_ctb].b2_cu_depth;
2426
35.8k
            }
2427
2428
55.8k
            split_cu_ctxt_inc = IHEVC_CAB_SPLIT_CU_FLAG + (left_cu_depth > i4_tree_depth) +
2429
55.8k
                                (top_cu_depth > i4_tree_depth);
2430
2431
55.8k
            u1_split_cu_flag_cab_model =
2432
55.8k
                ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][split_cu_ctxt_inc];
2433
2434
            /* bits for coding split_cu_flag = 1 */
2435
55.8k
            split_cu1_bits_q12 = gau2_ihevce_cabac_bin_to_bits[u1_split_cu_flag_cab_model ^ 1];
2436
2437
            /* bits for coding split_cu_flag = 0 */
2438
55.8k
            split_cu0_bits_q12 = gau2_ihevce_cabac_bin_to_bits[u1_split_cu_flag_cab_model ^ 0];
2439
2440
            /* update the cu split cabac context of all child nodes before evaluating child */
2441
131k
            for(i = (i4_tree_depth + 1); i < 4; i++)
2442
75.4k
            {
2443
75.4k
                ps_ctxt->au1_rdopt_recur_ctxt_models[i][split_cu_ctxt_inc] =
2444
75.4k
                    gau1_ihevc_next_state[(u1_split_cu_flag_cab_model << 1) | 1];
2445
75.4k
            }
2446
2447
            /* update the cu split cabac context of the parent node with split flag = 0 */
2448
55.8k
            ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][split_cu_ctxt_inc] =
2449
55.8k
                gau1_ihevc_next_state[(u1_split_cu_flag_cab_model << 1) | 0];
2450
55.8k
        }
2451
299k
    }
2452
696k
#endif
2453
2454
    /* If all the child nodes are null, then do rdo for this node and return the cost */
2455
696k
    if((1 == ps_cu_tree_analyse->is_node_valid) && (4 == child_nodes_null))
2456
305k
    {
2457
305k
        WORD32 i4_num_bytes_ecd_data;
2458
2459
#if(PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2460
        COPY_CABAC_STATES(
2461
            &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2462
            &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][0],
2463
            IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2464
#else
2465
305k
        if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2466
116k
        {
2467
116k
            COPY_CABAC_STATES(
2468
116k
                &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2469
116k
                &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][0],
2470
116k
                IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2471
116k
        }
2472
305k
#endif
2473
2474
305k
        ps_cu_prms->u1_is_cu_noisy = u1_is_cu_noisy;
2475
305k
        ihevce_update_pred_qp(
2476
305k
            ps_ctxt, ps_cu_tree_analyse->b3_cu_pos_x, ps_cu_tree_analyse->b3_cu_pos_y);
2477
        /* DO rdo for current node here */
2478
        /* return rdo cost for current node*/
2479
305k
        ps_cu_tree_analyse->i8_best_rdopt_cost = ihevce_compute_rdo(
2480
305k
            ps_ctxt,
2481
305k
            ps_cu_prms,
2482
305k
            ps_cu_tree_analyse,
2483
305k
            ps_cur_ipe_ctb,
2484
305k
            ps_cu_me_data,
2485
305k
            *pps_col_pu,
2486
305k
            &s_final_mode_state,
2487
305k
            pu1_col_pu_map,
2488
305k
            *ps_cu_update_prms->ppu1_row_ecd_data,
2489
305k
            *pi4_col_start_pu_idx,
2490
305k
            i4_ctb_x_off,
2491
305k
            i4_ctb_y_off);
2492
2493
305k
        if((((ps_cu_tree_analyse->b3_cu_pos_y << 3) + ps_cu_tree_analyse->u1_cu_size) ==
2494
305k
            cur_ctb_ht) &&
2495
55.0k
           (ps_cu_tree_analyse->b3_cu_pos_x == 0) && (i4_ctb_x_off == 0))
2496
5.23k
        {
2497
            /* copy the state to row level context after 1st Cu, in the Last CU row of CTB */
2498
            /* copy current ctb CU states into a entropy sync state */
2499
            /* to be used for next row                              */
2500
5.23k
            COPY_CABAC_STATES(
2501
5.23k
                ps_ctxt->pu1_curr_row_cabac_state,
2502
5.23k
                &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2503
5.23k
                IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2504
5.23k
        }
2505
2506
#if(PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2507
        {
2508
#if ENABLE_CU_SPLIT_FLAG_RATE_ESTIMATION
2509
            /* Add parent split cu = 0 cost signalling */
2510
            ps_cu_tree_analyse->i8_best_rdopt_cost += COMPUTE_RATE_COST_CLIP30(
2511
                split_cu0_bits_q12, i8_lambda_qf, (LAMBDA_Q_SHIFT + CABAC_FRAC_BITS_Q));
2512
#endif
2513
            for(i = (i4_tree_depth); i < 4; i++)
2514
            {
2515
                COPY_CABAC_STATES(
2516
                    &ps_ctxt->au1_rdopt_recur_ctxt_models[i][0],
2517
                    &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2518
                    IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2519
            }
2520
        }
2521
#else
2522
305k
        if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2523
116k
        {
2524
116k
#if ENABLE_CU_SPLIT_FLAG_RATE_ESTIMATION
2525
            /* Add parent split cu = 0 cost signalling */
2526
116k
            ps_cu_tree_analyse->i8_best_rdopt_cost += COMPUTE_RATE_COST_CLIP30(
2527
116k
                split_cu0_bits_q12, i8_lambda_qf, (LAMBDA_Q_SHIFT + CABAC_FRAC_BITS_Q));
2528
116k
#endif
2529
2530
247k
            for(i = (i4_tree_depth); i < 4; i++)
2531
130k
            {
2532
130k
                COPY_CABAC_STATES(
2533
130k
                    &ps_ctxt->au1_rdopt_recur_ctxt_models[i][0],
2534
130k
                    &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2535
130k
                    IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2536
130k
            }
2537
116k
        }
2538
305k
#endif
2539
2540
305k
        ((pf_store_cu_results)ps_ctxt->pv_store_cu_results)(
2541
305k
            ps_ctxt, ps_cu_prms, &s_final_mode_state);
2542
2543
305k
#if(!PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2544
305k
        if(ps_ctxt->i4_quality_preset >= IHEVCE_QUALITY_P2)
2545
188k
        {
2546
188k
            ihevce_update_final_cu_results(
2547
188k
                ps_ctxt,
2548
188k
                ps_ctxt->ps_enc_out_ctxt,
2549
188k
                ps_cu_prms,
2550
188k
                pps_col_pu,
2551
188k
                pi4_col_start_pu_idx,
2552
188k
                ps_cu_update_prms,
2553
188k
                i4_ctb_x_off >> 6,
2554
188k
                i4_ctb_y_off >> 6);
2555
188k
        }
2556
116k
        else
2557
116k
        {
2558
            /* ---- copy the luma & chroma coeffs to final output -------- */
2559
116k
            i4_num_bytes_ecd_data = ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->i4_num_bytes_ecd_data;
2560
2561
116k
            if(0 != i4_num_bytes_ecd_data)
2562
87.8k
            {
2563
87.8k
                memcpy(
2564
87.8k
                    ps_ctxt->pu1_ecd_data,
2565
87.8k
                    &ps_ctxt->pu1_cu_recur_coeffs[0],
2566
87.8k
                    i4_num_bytes_ecd_data * sizeof(UWORD8));
2567
2568
87.8k
                ps_ctxt->pu1_ecd_data += i4_num_bytes_ecd_data;
2569
87.8k
            }
2570
2571
            /* Collocated PU updates */
2572
116k
            *pps_col_pu += ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2573
116k
            *pi4_col_start_pu_idx += ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2574
116k
        }
2575
#else
2576
        /* ---- copy the luma & chroma coeffs to final output -------- */
2577
        i4_num_bytes_ecd_data = ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->i4_num_bytes_ecd_data;
2578
        if(0 != i4_num_bytes_ecd_data)
2579
        {
2580
            memcpy(
2581
                ps_ctxt->pu1_ecd_data,
2582
                &ps_ctxt->pu1_cu_recur_coeffs[0],
2583
                i4_num_bytes_ecd_data * sizeof(UWORD8));
2584
2585
            ps_ctxt->pu1_ecd_data += i4_num_bytes_ecd_data;
2586
        }
2587
2588
        /* Collocated PU updates */
2589
        *pps_col_pu += ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2590
        *pi4_col_start_pu_idx += ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2591
#endif
2592
2593
305k
        ps_ctxt->ps_enc_out_ctxt++;
2594
305k
        num_children_encoded++;
2595
305k
    }
2596
390k
    else
2597
390k
    {
2598
390k
        i8_least_child_cost = 0;
2599
2600
1.95M
        for(i = 0; i < 4; i++)
2601
1.56M
        {
2602
1.56M
            if(ps_cu_tree_analyse_child[i] != NULL)
2603
682k
            {
2604
682k
                num_children_encoded += ihevce_cu_recurse_decide(
2605
682k
                    ps_ctxt,
2606
682k
                    ps_cu_prms,
2607
682k
                    ps_cu_tree_analyse_child[i],
2608
682k
                    ps_cu_tree_analyse,
2609
682k
                    ps_cur_ipe_ctb,
2610
682k
                    ps_cu_me_data,
2611
682k
                    pps_col_pu,
2612
682k
                    ps_cu_update_prms,
2613
682k
                    pu1_col_pu_map,
2614
682k
                    pi4_col_start_pu_idx,
2615
682k
                    i4_tree_depth + 1,
2616
682k
                    i4_ctb_x_off,
2617
682k
                    i4_ctb_y_off,
2618
682k
                    cur_ctb_ht);
2619
2620
                /* In case of incomplete ctb, */
2621
                //if(MAX_COST != ps_cu_tree_analyse_child[i]->i4_best_rdopt_cost)
2622
682k
                if(((ULWORD64)(
2623
682k
                       i8_least_child_cost + ps_cu_tree_analyse_child[i]->i8_best_rdopt_cost)) >
2624
682k
                   MAX_COST_64)
2625
224k
                {
2626
224k
                    i8_least_child_cost = MAX_COST_64;
2627
224k
                }
2628
457k
                else
2629
457k
                {
2630
457k
                    i8_least_child_cost += ps_cu_tree_analyse_child[i]->i8_best_rdopt_cost;
2631
457k
                }
2632
682k
            }
2633
879k
            else
2634
879k
            {
2635
                /* If the child node is NULL, return MAX_COST*/
2636
879k
                i8_least_child_cost = MAX_COST_64;
2637
879k
            }
2638
1.56M
        }
2639
2640
390k
        if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2641
183k
        {
2642
#if !ENABLE_4CTB_EVALUATION
2643
            if((ps_cu_tree_analyse->u1_cu_size == 64) && (num_children_encoded > 10) &&
2644
               (ps_ctxt->i1_slice_type != ISLICE))
2645
            {
2646
                ps_cu_tree_analyse->is_node_valid = 0;
2647
            }
2648
#endif
2649
183k
        }
2650
2651
        /* If current CU node is valid, do rdo for the node and decide btwn child nodes and parent nodes  */
2652
390k
        if(ps_cu_tree_analyse->is_node_valid)
2653
40.1k
        {
2654
40.1k
            UWORD8 au1_cu_pu_map[(MAX_CTB_SIZE / MIN_PU_SIZE) * (MAX_CTB_SIZE / MIN_PU_SIZE)];
2655
40.1k
            pu_col_mv_t as_col_mv[2]; /* Max of 2 PUs only per CU */
2656
2657
40.1k
            WORD32 i4_col_pu_idx_start = i4_col_pu_idx_bkup;
2658
2659
            /* Copy the collocated PU map to the local array */
2660
40.1k
            memcpy(
2661
40.1k
                au1_cu_pu_map,
2662
40.1k
                pu1_col_pu_map,
2663
40.1k
                (MAX_CTB_SIZE / MIN_PU_SIZE) * (MAX_CTB_SIZE / MIN_PU_SIZE));
2664
2665
#if(PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2666
            COPY_CABAC_STATES(
2667
                &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2668
                &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][0],
2669
                IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2670
2671
            /* Reset the nbr maps while computing Parent CU node ()*/
2672
            /* set the neighbour map to 0 */
2673
            ihevce_set_nbr_map(
2674
                ps_ctxt->pu1_ctb_nbr_map,
2675
                ps_ctxt->i4_nbr_map_strd,
2676
                (ps_cu_tree_analyse->b3_cu_pos_x << 1),
2677
                (ps_cu_tree_analyse->b3_cu_pos_y << 1),
2678
                (ps_cu_tree_analyse->u1_cu_size >> 2),
2679
                0);
2680
#else
2681
40.1k
            if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2682
40.1k
            {
2683
40.1k
                COPY_CABAC_STATES(
2684
40.1k
                    &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2685
40.1k
                    &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][0],
2686
40.1k
                    IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2687
2688
                /* Reset the nbr maps while computing Parent CU node ()*/
2689
                /* set the neighbour map to 0 */
2690
40.1k
                ihevce_set_nbr_map(
2691
40.1k
                    ps_ctxt->pu1_ctb_nbr_map,
2692
40.1k
                    ps_ctxt->i4_nbr_map_strd,
2693
40.1k
                    (ps_cu_tree_analyse->b3_cu_pos_x << 1),
2694
40.1k
                    (ps_cu_tree_analyse->b3_cu_pos_y << 1),
2695
40.1k
                    (ps_cu_tree_analyse->u1_cu_size >> 2),
2696
40.1k
                    0);
2697
40.1k
            }
2698
40.1k
#endif
2699
2700
            /* Do rdo for the parent node */
2701
            /* Compare parent node cost vs child node costs */
2702
40.1k
            ps_ctxt->is_parent_cu_rdopt = 1;
2703
2704
40.1k
            ps_cu_prms->u1_is_cu_noisy = u1_is_cu_noisy;
2705
2706
40.1k
            ihevce_update_pred_qp(
2707
40.1k
                ps_ctxt, ps_cu_tree_analyse->b3_cu_pos_x, ps_cu_tree_analyse->b3_cu_pos_y);
2708
2709
40.1k
            ps_cu_tree_analyse->i8_best_rdopt_cost = ihevce_compute_rdo(
2710
40.1k
                ps_ctxt,
2711
40.1k
                ps_cu_prms,
2712
40.1k
                ps_cu_tree_analyse,
2713
40.1k
                ps_cur_ipe_ctb,
2714
40.1k
                ps_cu_me_data,
2715
40.1k
                as_col_mv,
2716
40.1k
                &s_final_mode_state,
2717
40.1k
                au1_cu_pu_map,
2718
40.1k
                *ps_cu_update_prms->ppu1_row_ecd_data,
2719
40.1k
                i4_col_pu_idx_start,
2720
40.1k
                i4_ctb_x_off,
2721
40.1k
                i4_ctb_y_off);
2722
2723
40.1k
            ps_ctxt->is_parent_cu_rdopt = 0;
2724
2725
#if(PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2726
            /* Add parent split cu cost signalling */
2727
            ps_cu_tree_analyse->i8_best_rdopt_cost += COMPUTE_RATE_COST_CLIP30(
2728
                split_cu0_bits_q12, i8_lambda_qf, (LAMBDA_Q_SHIFT + CABAC_FRAC_BITS_Q));
2729
2730
            COPY_CABAC_STATES(
2731
                &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][0],
2732
                &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2733
                IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2734
2735
            /* i8_least_child_cost += (num_children_encoded * ps_ctxt->i4_sad_lamda\
2736
            + ((1 << (LAMBDA_Q_SHIFT)))) >> (LAMBDA_Q_SHIFT + 1) */
2737
            ;
2738
            /* bits for coding cu split flag as  1 */
2739
            i8_least_child_cost += COMPUTE_RATE_COST_CLIP30(
2740
                split_cu1_bits_q12, i8_lambda_qf, (LAMBDA_Q_SHIFT + CABAC_FRAC_BITS_Q));
2741
#else
2742
40.1k
#if ENABLE_CU_SPLIT_FLAG_RATE_ESTIMATION
2743
40.1k
            if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2744
40.1k
            {
2745
                /* Add parent split cu cost signalling */
2746
40.1k
                ps_cu_tree_analyse->i8_best_rdopt_cost += COMPUTE_RATE_COST_CLIP30(
2747
40.1k
                    split_cu0_bits_q12, i8_lambda_qf, (LAMBDA_Q_SHIFT + CABAC_FRAC_BITS_Q));
2748
2749
40.1k
                COPY_CABAC_STATES(
2750
40.1k
                    &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][0],
2751
40.1k
                    &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2752
40.1k
                    IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2753
2754
                /* i8_least_child_cost += (num_children_encoded * ps_ctxt->i4_sad_lamda\
2755
                + ((1 << (LAMBDA_Q_SHIFT)))) >> (LAMBDA_Q_SHIFT + 1) */
2756
40.1k
                ;
2757
                /* bits for coding cu split flag as  1 */
2758
40.1k
                i8_least_child_cost += COMPUTE_RATE_COST_CLIP30(
2759
40.1k
                    split_cu1_bits_q12, i8_lambda_qf, (LAMBDA_Q_SHIFT + CABAC_FRAC_BITS_Q));
2760
40.1k
            }
2761
#else
2762
            i8_least_child_cost +=
2763
                (num_children_encoded * ps_ctxt->i4_sad_lamda + ((1 << (LAMBDA_Q_SHIFT)))) >>
2764
                (LAMBDA_Q_SHIFT + 1);
2765
#endif
2766
40.1k
#endif
2767
2768
            /* If child modes win over parent, discard parent enc ctxt */
2769
            /* else discard child ctxt */
2770
40.1k
            if(ps_cu_tree_analyse->i8_best_rdopt_cost > i8_least_child_cost)
2771
21.8k
            {
2772
#if(PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2773
                /* Store child node Models for evalution of next CU */
2774
                for(i = (i4_tree_depth); i < 4; i++)
2775
                {
2776
                    COPY_CABAC_STATES(
2777
                        &ps_ctxt->au1_rdopt_recur_ctxt_models[i][0],
2778
                        &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth + 1][0],
2779
                        IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2780
                }
2781
                /* Reset cabac states if child has won */
2782
                COPY_CABAC_STATES(
2783
                    &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2784
                    &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth + 1][0],
2785
                    IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2786
#else
2787
21.8k
                if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2788
21.8k
                {
2789
69.3k
                    for(i = i4_tree_depth; i < 4; i++)
2790
47.4k
                    {
2791
47.4k
                        COPY_CABAC_STATES(
2792
47.4k
                            &ps_ctxt->au1_rdopt_recur_ctxt_models[i][0],
2793
47.4k
                            &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth + 1][0],
2794
47.4k
                            IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2795
47.4k
                    }
2796
                    /* Reset cabac states if child has won */
2797
21.8k
                    COPY_CABAC_STATES(
2798
21.8k
                        &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2799
21.8k
                        &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth + 1][0],
2800
21.8k
                        IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2801
21.8k
                }
2802
21.8k
#endif
2803
21.8k
                ps_cu_tree_analyse->i8_best_rdopt_cost = i8_least_child_cost;
2804
21.8k
                ps_cu_tree_analyse->is_node_valid = 0;
2805
21.8k
            }
2806
18.2k
            else
2807
18.2k
            {
2808
                /* Parent node wins over child node */
2809
18.2k
                ihevce_enc_cu_node_ctxt_t *ps_enc_tmp_out_ctxt;
2810
18.2k
                WORD32 i4_num_bytes_ecd_data;
2811
18.2k
                WORD32 num_child_nodes = 0;
2812
18.2k
                WORD32 i4_num_pus_in_cu;
2813
2814
18.2k
                if((((ps_cu_tree_analyse->b3_cu_pos_y << 3) + ps_cu_tree_analyse->u1_cu_size) ==
2815
18.2k
                    cur_ctb_ht) &&
2816
6.51k
                   (ps_cu_tree_analyse->b3_cu_pos_x == 0) && (i4_ctb_x_off == 0))
2817
1.20k
                {
2818
                    /* copy the state to row level context after 1st Cu, in the Last CU row of CTB */
2819
                    /* copy current ctb CU states into a entropy sync state */
2820
                    /* to be used for next row                              */
2821
1.20k
                    COPY_CABAC_STATES(
2822
1.20k
                        ps_ctxt->pu1_curr_row_cabac_state,
2823
1.20k
                        &ps_ctxt->s_rdopt_entropy_ctxt.au1_init_cabac_ctxt_states[0],
2824
1.20k
                        IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2825
1.20k
                }
2826
2827
#if(PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2828
                /* Store parent node Models for evalution of next CU */
2829
                for(i = (i4_tree_depth + 1); i < 4; i++)
2830
                {
2831
                    COPY_CABAC_STATES(
2832
                        &ps_ctxt->au1_rdopt_recur_ctxt_models[i][0],
2833
                        &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][0],
2834
                        IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2835
                }
2836
#else
2837
18.2k
                if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2838
18.2k
                {
2839
41.7k
                    for(i = (i4_tree_depth + 1); i < 4; i++)
2840
23.5k
                    {
2841
23.5k
                        COPY_CABAC_STATES(
2842
23.5k
                            &ps_ctxt->au1_rdopt_recur_ctxt_models[i][0],
2843
23.5k
                            &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth][0],
2844
23.5k
                            IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2845
23.5k
                    }
2846
18.2k
                }
2847
18.2k
#endif
2848
18.2k
                ((pf_store_cu_results)ps_ctxt->pv_store_cu_results)(
2849
18.2k
                    ps_ctxt, ps_cu_prms, &s_final_mode_state);
2850
2851
18.2k
#if(!PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2852
18.2k
                if(ps_ctxt->i4_quality_preset >= IHEVCE_QUALITY_P2)
2853
0
                {
2854
0
                    ihevce_update_final_cu_results(
2855
0
                        ps_ctxt,
2856
0
                        ps_ctxt->ps_enc_out_ctxt,
2857
0
                        ps_cu_prms,
2858
0
                        pps_col_pu,
2859
0
                        pi4_col_start_pu_idx,
2860
0
                        ps_cu_update_prms,
2861
0
                        i4_ctb_x_off >> 6,
2862
0
                        i4_ctb_y_off >> 6);
2863
2864
0
                    ps_ctxt->ps_enc_out_ctxt++;
2865
0
                }
2866
18.2k
                else
2867
18.2k
                {
2868
18.2k
                    ps_enc_tmp_out_ctxt = ps_ctxt->ps_enc_out_ctxt;
2869
2870
18.2k
                    num_child_nodes = num_children_encoded;
2871
2872
                    /* ---- copy the luma & chroma coeffs to final output -------- */
2873
61.2k
                    for(i = 0; i < num_child_nodes; i++)
2874
42.9k
                    {
2875
42.9k
                        i4_num_bytes_ecd_data =
2876
42.9k
                            (ps_ctxt->ps_enc_out_ctxt - i - 1)->ps_cu_prms->i4_num_bytes_ecd_data;
2877
42.9k
                        ps_ctxt->pu1_ecd_data -= i4_num_bytes_ecd_data;
2878
42.9k
                    }
2879
2880
18.2k
                    i4_num_bytes_ecd_data =
2881
18.2k
                        ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->i4_num_bytes_ecd_data;
2882
18.2k
                    if(0 != i4_num_bytes_ecd_data)
2883
4.32k
                    {
2884
4.32k
                        memcpy(
2885
4.32k
                            ps_ctxt->pu1_ecd_data,
2886
4.32k
                            &ps_ctxt->pu1_cu_recur_coeffs[0],
2887
4.32k
                            i4_num_bytes_ecd_data);
2888
2889
4.32k
                        ps_ctxt->pu1_ecd_data += i4_num_bytes_ecd_data;
2890
4.32k
                    }
2891
2892
18.2k
                    ps_enc_tmp_out_ctxt = ps_ctxt->ps_enc_out_ctxt - num_child_nodes;
2893
2894
18.2k
                    memcpy(
2895
18.2k
                        ps_enc_tmp_out_ctxt,
2896
18.2k
                        ps_ctxt->ps_enc_out_ctxt,
2897
18.2k
                        sizeof(ihevce_enc_cu_node_ctxt_t));
2898
18.2k
                    ps_enc_tmp_out_ctxt->ps_cu_prms = &ps_enc_tmp_out_ctxt->s_cu_prms;
2899
2900
                    /* Collocated PU updates */
2901
18.2k
                    i4_num_pus_in_cu = ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2902
                    /* Copy the collocated MVs and the PU map to frame buffers */
2903
18.2k
                    memcpy(ps_col_mv_bkup, as_col_mv, sizeof(pu_col_mv_t) * i4_num_pus_in_cu);
2904
18.2k
                    memcpy(
2905
18.2k
                        pu1_col_pu_map,
2906
18.2k
                        au1_cu_pu_map,
2907
18.2k
                        (MAX_CTB_SIZE / MIN_PU_SIZE) * (MAX_CTB_SIZE / MIN_PU_SIZE));
2908
                    /* Update the frame buffer pointer and the map index */
2909
18.2k
                    *pps_col_pu = ps_col_mv_bkup + i4_num_pus_in_cu;
2910
18.2k
                    *pi4_col_start_pu_idx = i4_col_pu_idx_bkup + i4_num_pus_in_cu;
2911
2912
18.2k
                    ps_ctxt->ps_enc_out_ctxt = ps_enc_tmp_out_ctxt + 1;
2913
18.2k
                }
2914
#else
2915
2916
                ps_enc_tmp_out_ctxt = ps_ctxt->ps_enc_out_ctxt;
2917
2918
                num_child_nodes = num_children_encoded;
2919
2920
                /* ---- copy the luma & chroma coeffs to final output -------- */
2921
                for(i = 0; i < num_child_nodes; i++)
2922
                {
2923
                    i4_num_bytes_ecd_data =
2924
                        (ps_ctxt->ps_enc_out_ctxt - i - 1)->ps_cu_prms->i4_num_bytes_ecd_data;
2925
                    ps_ctxt->pu1_ecd_data -= i4_num_bytes_ecd_data;
2926
                }
2927
2928
                i4_num_bytes_ecd_data = ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->i4_num_bytes_ecd_data;
2929
                if(0 != i4_num_bytes_ecd_data)
2930
                {
2931
                    memcpy(
2932
                        ps_ctxt->pu1_ecd_data,
2933
                        &ps_ctxt->pu1_cu_recur_coeffs[0],
2934
                        i4_num_bytes_ecd_data * sizeof(UWORD8));
2935
2936
                    ps_ctxt->pu1_ecd_data += i4_num_bytes_ecd_data;
2937
                }
2938
2939
                ps_enc_tmp_out_ctxt = ps_ctxt->ps_enc_out_ctxt - num_child_nodes;
2940
2941
                memcpy(
2942
                    ps_enc_tmp_out_ctxt,
2943
                    ps_ctxt->ps_enc_out_ctxt,
2944
                    sizeof(ihevce_enc_cu_node_ctxt_t));
2945
2946
                ps_enc_tmp_out_ctxt->ps_cu_prms = &ps_enc_tmp_out_ctxt->s_cu_prms;
2947
2948
                /* Collocated PU updates */
2949
                i4_num_pus_in_cu = ps_ctxt->ps_enc_out_ctxt->ps_cu_prms->u2_num_pus_in_cu;
2950
                /* Copy the collocated MVs and the PU map to frame buffers */
2951
                memcpy(ps_col_mv_bkup, as_col_mv, sizeof(pu_col_mv_t) * i4_num_pus_in_cu);
2952
                memcpy(
2953
                    pu1_col_pu_map,
2954
                    au1_cu_pu_map,
2955
                    (MAX_CTB_SIZE / MIN_PU_SIZE) * (MAX_CTB_SIZE / MIN_PU_SIZE));
2956
                /* Update the frame buffer pointer and the map index */
2957
                *pps_col_pu = ps_col_mv_bkup + i4_num_pus_in_cu;
2958
                *pi4_col_start_pu_idx = i4_col_pu_idx_bkup + i4_num_pus_in_cu;
2959
2960
                ps_ctxt->ps_enc_out_ctxt = ps_enc_tmp_out_ctxt + 1;
2961
#endif
2962
2963
18.2k
                num_children_encoded = 1;
2964
18.2k
                DISABLE_THE_CHILDREN_NODES(ps_cu_tree_analyse);
2965
18.2k
            }
2966
40.1k
        }
2967
350k
        else /* if(ps_cu_tree_analyse->is_node_valid) */
2968
350k
        {
2969
350k
            ps_cu_tree_analyse->i8_best_rdopt_cost = i8_least_child_cost;
2970
2971
            /* Tree depth of four will occur for Incomplete CTB */
2972
350k
            if((i8_least_child_cost > 0) && (i4_tree_depth != 3))
2973
131k
            {
2974
#if(PROCESS_GT_1CTB_VIA_CU_RECUR_IN_FAST_PRESETS)
2975
                /* Store child node Models for evalution of next CU */
2976
                for(i = i4_tree_depth; i < 4; i++)
2977
                {
2978
                    COPY_CABAC_STATES(
2979
                        &ps_ctxt->au1_rdopt_recur_ctxt_models[i][0],
2980
                        &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth + 1][0],
2981
                        IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2982
                }
2983
#else
2984
131k
                if(ps_ctxt->i4_quality_preset < IHEVCE_QUALITY_P2)
2985
33.6k
                {
2986
116k
                    for(i = (i4_tree_depth); i < 4; i++)
2987
82.8k
                    {
2988
82.8k
                        COPY_CABAC_STATES(
2989
82.8k
                            &ps_ctxt->au1_rdopt_recur_ctxt_models[i][0],
2990
82.8k
                            &ps_ctxt->au1_rdopt_recur_ctxt_models[i4_tree_depth + 1][0],
2991
82.8k
                            IHEVC_CAB_CTXT_END * sizeof(UWORD8));
2992
82.8k
                    }
2993
33.6k
                }
2994
131k
#endif
2995
131k
            }
2996
350k
        }
2997
390k
    }
2998
2999
696k
    return num_children_encoded;
3000
696k
}
3001
3002
static UWORD8 ihevce_intraData_availability_extractor(
3003
    WORD8 *pi1_8x8CULevel_intraData_availability_indicator,
3004
    UWORD8 u1_cu_size,
3005
    UWORD8 u1_x_8x8CU_units,
3006
    UWORD8 u1_y_8x8CU_units)
3007
0
{
3008
0
    if(8 == u1_cu_size)
3009
0
    {
3010
0
        return (!pi1_8x8CULevel_intraData_availability_indicator
3011
0
                    [u1_x_8x8CU_units + MAX_CU_IN_CTB_ROW * u1_y_8x8CU_units]);
3012
0
    }
3013
0
    else
3014
0
    {
3015
0
        UWORD8 u1_data_availability = 0;
3016
0
        UWORD8 u1_child_cu_size = u1_cu_size / 2;
3017
3018
0
        u1_data_availability |= ihevce_intraData_availability_extractor(
3019
0
            pi1_8x8CULevel_intraData_availability_indicator,
3020
0
            u1_child_cu_size,
3021
0
            u1_x_8x8CU_units,
3022
0
            u1_y_8x8CU_units);
3023
3024
0
        u1_data_availability |= ihevce_intraData_availability_extractor(
3025
0
            pi1_8x8CULevel_intraData_availability_indicator,
3026
0
            u1_child_cu_size,
3027
0
            u1_x_8x8CU_units + u1_child_cu_size / 8,
3028
0
            u1_y_8x8CU_units);
3029
3030
0
        u1_data_availability |= ihevce_intraData_availability_extractor(
3031
0
            pi1_8x8CULevel_intraData_availability_indicator,
3032
0
            u1_child_cu_size,
3033
0
            u1_x_8x8CU_units,
3034
0
            u1_y_8x8CU_units + u1_child_cu_size / 8);
3035
3036
0
        u1_data_availability |= ihevce_intraData_availability_extractor(
3037
0
            pi1_8x8CULevel_intraData_availability_indicator,
3038
0
            u1_child_cu_size,
3039
0
            u1_x_8x8CU_units + u1_child_cu_size / 8,
3040
0
            u1_y_8x8CU_units + u1_child_cu_size / 8);
3041
3042
0
        return u1_data_availability;
3043
0
    }
3044
0
}
3045
3046
void ihevce_intra_and_inter_cuTree_merger(
3047
    cur_ctb_cu_tree_t *ps_merged_tree,
3048
    cur_ctb_cu_tree_t *ps_intra_tree,
3049
    cur_ctb_cu_tree_t *ps_inter_tree,
3050
    WORD8 *pi1_8x8CULevel_intraData_availability_indicator)
3051
0
{
3052
    /* 0 => Intra and inter children valid */
3053
    /* 1 => Only Intra valid */
3054
    /* 2 => Only Inter valid */
3055
    /* 3 => Neither */
3056
0
    UWORD8 au1_children_recursive_call_type[4];
3057
3058
0
    if(NULL != ps_intra_tree)
3059
0
    {
3060
0
        ps_intra_tree->is_node_valid =
3061
0
            ps_intra_tree->is_node_valid &
3062
0
            ihevce_intraData_availability_extractor(
3063
0
                pi1_8x8CULevel_intraData_availability_indicator,
3064
0
                ps_intra_tree->u1_cu_size,
3065
0
                ps_intra_tree->b3_cu_pos_x & ((8 == ps_intra_tree->u1_cu_size) ? 0xfe : 0xff),
3066
0
                ps_intra_tree->b3_cu_pos_y & ((8 == ps_intra_tree->u1_cu_size) ? 0xfe : 0xff));
3067
0
    }
3068
3069
0
    switch(((NULL == ps_intra_tree) << 1) | (NULL == ps_inter_tree))
3070
0
    {
3071
0
    case 0:
3072
0
    {
3073
0
        ps_merged_tree->is_node_valid = ps_intra_tree->is_node_valid ||
3074
0
                                        ps_inter_tree->is_node_valid;
3075
0
        ps_merged_tree->u1_inter_eval_enable = ps_inter_tree->is_node_valid;
3076
0
        ps_merged_tree->u1_intra_eval_enable = ps_intra_tree->is_node_valid;
3077
3078
0
        au1_children_recursive_call_type[POS_TL] =
3079
0
            ((NULL == ps_intra_tree->ps_child_node_tl) << 1) |
3080
0
            (NULL == ps_inter_tree->ps_child_node_tl);
3081
0
        au1_children_recursive_call_type[POS_TR] =
3082
0
            ((NULL == ps_intra_tree->ps_child_node_tr) << 1) |
3083
0
            (NULL == ps_inter_tree->ps_child_node_tr);
3084
0
        au1_children_recursive_call_type[POS_BL] =
3085
0
            ((NULL == ps_intra_tree->ps_child_node_bl) << 1) |
3086
0
            (NULL == ps_inter_tree->ps_child_node_bl);
3087
0
        au1_children_recursive_call_type[POS_BR] =
3088
0
            ((NULL == ps_intra_tree->ps_child_node_br) << 1) |
3089
0
            (NULL == ps_inter_tree->ps_child_node_br);
3090
3091
0
        break;
3092
0
    }
3093
0
    case 1:
3094
0
    {
3095
0
        ps_merged_tree->is_node_valid = ps_intra_tree->is_node_valid;
3096
0
        ps_merged_tree->u1_inter_eval_enable = 0;
3097
0
        ps_merged_tree->u1_intra_eval_enable = ps_intra_tree->is_node_valid;
3098
3099
0
        au1_children_recursive_call_type[POS_TL] =
3100
0
            ((NULL == ps_intra_tree->ps_child_node_tl) << 1) + 1;
3101
0
        au1_children_recursive_call_type[POS_TR] =
3102
0
            ((NULL == ps_intra_tree->ps_child_node_tr) << 1) + 1;
3103
0
        au1_children_recursive_call_type[POS_BL] =
3104
0
            ((NULL == ps_intra_tree->ps_child_node_bl) << 1) + 1;
3105
0
        au1_children_recursive_call_type[POS_BR] =
3106
0
            ((NULL == ps_intra_tree->ps_child_node_br) << 1) + 1;
3107
3108
0
        break;
3109
0
    }
3110
0
    case 2:
3111
0
    {
3112
0
        ps_merged_tree->is_node_valid = ps_inter_tree->is_node_valid;
3113
0
        ps_merged_tree->u1_inter_eval_enable = ps_inter_tree->is_node_valid;
3114
0
        ps_merged_tree->u1_intra_eval_enable = 0;
3115
3116
0
        au1_children_recursive_call_type[POS_TL] = 2 + (NULL == ps_inter_tree->ps_child_node_tl);
3117
0
        au1_children_recursive_call_type[POS_TR] = 2 + (NULL == ps_inter_tree->ps_child_node_tr);
3118
0
        au1_children_recursive_call_type[POS_BL] = 2 + (NULL == ps_inter_tree->ps_child_node_bl);
3119
0
        au1_children_recursive_call_type[POS_BR] = 2 + (NULL == ps_inter_tree->ps_child_node_br);
3120
3121
0
        break;
3122
0
    }
3123
0
    case 3:
3124
0
    {
3125
        /* The swamps of Dagobah! */
3126
0
        ASSERT(0);
3127
3128
0
        break;
3129
0
    }
3130
0
    }
3131
3132
0
    switch(au1_children_recursive_call_type[POS_TL])
3133
0
    {
3134
0
    case 0:
3135
0
    {
3136
0
        ihevce_intra_and_inter_cuTree_merger(
3137
0
            ps_merged_tree->ps_child_node_tl,
3138
0
            ps_intra_tree->ps_child_node_tl,
3139
0
            ps_inter_tree->ps_child_node_tl,
3140
0
            pi1_8x8CULevel_intraData_availability_indicator);
3141
3142
0
        break;
3143
0
    }
3144
0
    case 2:
3145
0
    {
3146
0
        ihevce_intra_and_inter_cuTree_merger(
3147
0
            ps_merged_tree->ps_child_node_tl,
3148
0
            NULL,
3149
0
            ps_inter_tree->ps_child_node_tl,
3150
0
            pi1_8x8CULevel_intraData_availability_indicator);
3151
3152
0
        break;
3153
0
    }
3154
0
    case 1:
3155
0
    {
3156
0
        ihevce_intra_and_inter_cuTree_merger(
3157
0
            ps_merged_tree->ps_child_node_tl,
3158
0
            ps_intra_tree->ps_child_node_tl,
3159
0
            NULL,
3160
0
            pi1_8x8CULevel_intraData_availability_indicator);
3161
3162
0
        break;
3163
0
    }
3164
0
    }
3165
3166
0
    switch(au1_children_recursive_call_type[POS_TR])
3167
0
    {
3168
0
    case 0:
3169
0
    {
3170
0
        ihevce_intra_and_inter_cuTree_merger(
3171
0
            ps_merged_tree->ps_child_node_tr,
3172
0
            ps_intra_tree->ps_child_node_tr,
3173
0
            ps_inter_tree->ps_child_node_tr,
3174
0
            pi1_8x8CULevel_intraData_availability_indicator);
3175
3176
0
        break;
3177
0
    }
3178
0
    case 2:
3179
0
    {
3180
0
        ihevce_intra_and_inter_cuTree_merger(
3181
0
            ps_merged_tree->ps_child_node_tr,
3182
0
            NULL,
3183
0
            ps_inter_tree->ps_child_node_tr,
3184
0
            pi1_8x8CULevel_intraData_availability_indicator);
3185
3186
0
        break;
3187
0
    }
3188
0
    case 1:
3189
0
    {
3190
0
        ihevce_intra_and_inter_cuTree_merger(
3191
0
            ps_merged_tree->ps_child_node_tr,
3192
0
            ps_intra_tree->ps_child_node_tr,
3193
0
            NULL,
3194
0
            pi1_8x8CULevel_intraData_availability_indicator);
3195
3196
0
        break;
3197
0
    }
3198
0
    }
3199
3200
0
    switch(au1_children_recursive_call_type[POS_BL])
3201
0
    {
3202
0
    case 0:
3203
0
    {
3204
0
        ihevce_intra_and_inter_cuTree_merger(
3205
0
            ps_merged_tree->ps_child_node_bl,
3206
0
            ps_intra_tree->ps_child_node_bl,
3207
0
            ps_inter_tree->ps_child_node_bl,
3208
0
            pi1_8x8CULevel_intraData_availability_indicator);
3209
3210
0
        break;
3211
0
    }
3212
0
    case 2:
3213
0
    {
3214
0
        ihevce_intra_and_inter_cuTree_merger(
3215
0
            ps_merged_tree->ps_child_node_bl,
3216
0
            NULL,
3217
0
            ps_inter_tree->ps_child_node_bl,
3218
0
            pi1_8x8CULevel_intraData_availability_indicator);
3219
3220
0
        break;
3221
0
    }
3222
0
    case 1:
3223
0
    {
3224
0
        ihevce_intra_and_inter_cuTree_merger(
3225
0
            ps_merged_tree->ps_child_node_bl,
3226
0
            ps_intra_tree->ps_child_node_bl,
3227
0
            NULL,
3228
0
            pi1_8x8CULevel_intraData_availability_indicator);
3229
3230
0
        break;
3231
0
    }
3232
0
    }
3233
3234
0
    switch(au1_children_recursive_call_type[POS_BR])
3235
0
    {
3236
0
    case 0:
3237
0
    {
3238
0
        ihevce_intra_and_inter_cuTree_merger(
3239
0
            ps_merged_tree->ps_child_node_br,
3240
0
            ps_intra_tree->ps_child_node_br,
3241
0
            ps_inter_tree->ps_child_node_br,
3242
0
            pi1_8x8CULevel_intraData_availability_indicator);
3243
3244
0
        break;
3245
0
    }
3246
0
    case 2:
3247
0
    {
3248
0
        ihevce_intra_and_inter_cuTree_merger(
3249
0
            ps_merged_tree->ps_child_node_br,
3250
0
            NULL,
3251
0
            ps_inter_tree->ps_child_node_br,
3252
0
            pi1_8x8CULevel_intraData_availability_indicator);
3253
3254
0
        break;
3255
0
    }
3256
0
    case 1:
3257
0
    {
3258
0
        ihevce_intra_and_inter_cuTree_merger(
3259
0
            ps_merged_tree->ps_child_node_br,
3260
0
            ps_intra_tree->ps_child_node_br,
3261
0
            NULL,
3262
0
            pi1_8x8CULevel_intraData_availability_indicator);
3263
3264
0
        break;
3265
0
    }
3266
0
    }
3267
0
}