Coverage Report

Created: 2026-03-20 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/encoder/ihevce_mv_pred.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
 * @file
23
 *  ihevcd_mv_pred.c
24
 *
25
 * @brief
26
 *  Contains functions for motion vector prediction
27
 *
28
 * @author
29
 *  Ittiam
30
 *
31
 * @par List of Functions:
32
 * - ihevcd_mvp_spatial_cand()
33
 *
34
 * @remarks
35
 *  None
36
 *
37
 *******************************************************************************
38
 */
39
/*****************************************************************************/
40
/* File Includes                                                             */
41
/*****************************************************************************/
42
/* System include files */
43
#include <stdio.h>
44
#include <string.h>
45
#include <stdlib.h>
46
#include <assert.h>
47
#include <stdarg.h>
48
#include <math.h>
49
50
/* User include files */
51
#include "ihevc_typedefs.h"
52
#include "itt_video_api.h"
53
#include "ihevce_api.h"
54
55
#include "rc_cntrl_param.h"
56
#include "rc_frame_info_collector.h"
57
#include "rc_look_ahead_params.h"
58
59
#include "ihevc_defs.h"
60
#include "ihevc_macros.h"
61
#include "ihevc_debug.h"
62
#include "ihevc_structs.h"
63
#include "ihevc_platform_macros.h"
64
#include "ihevc_deblk.h"
65
#include "ihevc_itrans_recon.h"
66
#include "ihevc_chroma_itrans_recon.h"
67
#include "ihevc_chroma_intra_pred.h"
68
#include "ihevc_intra_pred.h"
69
#include "ihevc_inter_pred.h"
70
#include "ihevc_mem_fns.h"
71
#include "ihevc_padding.h"
72
#include "ihevc_weighted_pred.h"
73
#include "ihevc_sao.h"
74
#include "ihevc_resi_trans.h"
75
#include "ihevc_quant_iquant_ssd.h"
76
#include "ihevc_cabac_tables.h"
77
#include "ihevc_common_tables.h"
78
79
#include "ihevce_defs.h"
80
#include "ihevce_hle_interface.h"
81
#include "ihevce_lap_enc_structs.h"
82
#include "ihevce_multi_thrd_structs.h"
83
#include "ihevce_me_common_defs.h"
84
#include "ihevce_had_satd.h"
85
#include "ihevce_error_codes.h"
86
#include "ihevce_bitstream.h"
87
#include "ihevce_cabac.h"
88
#include "ihevce_rdoq_macros.h"
89
#include "ihevce_function_selector.h"
90
#include "ihevce_enc_structs.h"
91
#include "ihevce_entropy_structs.h"
92
#include "ihevce_cmn_utils_instr_set_router.h"
93
#include "ihevce_enc_loop_structs.h"
94
#include "hme_datatype.h"
95
#include "hme_interface.h"
96
#include "hme_common_defs.h"
97
#include "hme_defs.h"
98
#include "ihevce_mv_pred.h"
99
#include "ihevce_mv_pred_merge.h"
100
#include "ihevce_common_utils.h"
101
102
/*****************************************************************************/
103
/* Function Definitions                                                      */
104
/*****************************************************************************/
105
106
/**
107
 *******************************************************************************
108
 *
109
 * @brief
110
 * This function performs Motion Vector prediction and return a list of mv
111
 *
112
 * @par Description:
113
 *  MV predictor list is computed using neighbor mvs and colocated mv
114
 *
115
 * @param[in] ps_ctxt
116
 * pointer to mv predictor context
117
 *
118
 * @param[in] ps_top_nbr_4x4
119
 * pointer to top 4x4 nbr structure
120
 *
121
 * @param[in] ps_left_nbr_4x4
122
 * pointer to left 4x4 nbr structure
123
 *
124
 * @param[in] ps_top_left_nbr_4x4
125
 * pointer to top left 4x4 nbr structure
126
 *
127
 * @param[in] left_nbr_4x4_strd
128
 * left nbr buffer stride in terms of 4x4 units
129
 *
130
 * @param[in] ps_avail_flags
131
 * Neighbor availability flags container
132
 *
133
 * @param[in] ps_col_mv
134
 * Colocated MV pointer
135
 *
136
 * @param[in] ps_pu
137
 * Current Partition PU strucrture pointer
138
 *
139
 * @param[inout] ps_pred_mv
140
 * pointer to store predicted MV list
141
 *
142
 * @returns
143
 * None
144
 * @remarks
145
 *
146
 *
147
 *******************************************************************************
148
 */
149
void ihevce_mv_pred(
150
    mv_pred_ctxt_t *ps_ctxt,
151
    nbr_4x4_t *ps_top_nbr_4x4,
152
    nbr_4x4_t *ps_left_nbr_4x4,
153
    nbr_4x4_t *ps_top_left_nbr_4x4,
154
    WORD32 left_nbr_4x4_strd,
155
    nbr_avail_flags_t *ps_avail_flags,
156
    pu_mv_t *ps_col_mv,
157
    pu_t *ps_pu,
158
    pu_mv_t *ps_pred_mv,
159
    UWORD8 (*pau1_is_top_used)[MAX_MVP_LIST_CAND])
160
110k
{
161
110k
    WORD32 is_scaled_flag_list[2] /* Indicates whether A0 or A1 is available */;
162
110k
    WORD32 lb_avail, l_avail, t_avail, tr_avail, tl_avail;
163
110k
    WORD32 avail_a_flag[2];
164
110k
    WORD32 avail_b_flag[2];
165
110k
    mv_t as_mv_a[2];
166
110k
    mv_t as_mv_b[2];
167
110k
    UWORD8 i1_cur_ref_idx_list[2];
168
110k
    WORD32 part_pos_x;
169
110k
    WORD32 part_pos_y;
170
110k
    WORD32 part_wd;
171
110k
    WORD32 part_ht;
172
173
    /*******************************************/
174
    /* Neighbor location: Graphical indication */
175
    /*                                         */
176
    /*          B2 _____________B1 B0          */
177
    /*            |               |            */
178
    /*            |               |            */
179
    /*            |               |            */
180
    /*            |      PU     ht|            */
181
    /*            |               |            */
182
    /*            |               |            */
183
    /*          A1|______wd_______|            */
184
    /*          A0                             */
185
    /*                                         */
186
    /*******************************************/
187
188
    /* Initialization */
189
110k
    avail_a_flag[0] = 0;
190
110k
    avail_a_flag[1] = 0;
191
110k
    avail_b_flag[0] = 0;
192
110k
    avail_b_flag[1] = 0;
193
194
110k
    as_mv_a[0].i2_mvx = 0;
195
110k
    as_mv_a[0].i2_mvy = 0;
196
110k
    as_mv_a[1].i2_mvx = 0;
197
110k
    as_mv_a[1].i2_mvy = 0;
198
110k
    as_mv_b[0].i2_mvx = 0;
199
110k
    as_mv_b[0].i2_mvy = 0;
200
110k
    as_mv_b[1].i2_mvx = 0;
201
110k
    as_mv_b[1].i2_mvy = 0;
202
203
110k
    lb_avail = ps_avail_flags->u1_bot_lt_avail;
204
110k
    l_avail = ps_avail_flags->u1_left_avail;
205
110k
    tr_avail = ps_avail_flags->u1_top_rt_avail;
206
110k
    t_avail = ps_avail_flags->u1_top_avail;
207
110k
    tl_avail = ps_avail_flags->u1_top_lt_avail;
208
209
110k
    is_scaled_flag_list[0] = 0;
210
110k
    is_scaled_flag_list[1] = 0;
211
212
110k
    part_pos_x = ps_pu->b4_pos_x << 2;
213
110k
    part_pos_y = ps_pu->b4_pos_y << 2;
214
110k
    part_wd = (ps_pu->b4_wd + 1) << 2;
215
110k
    part_ht = (ps_pu->b4_ht + 1) << 2;
216
217
    /* Initializing current PU reference index     */
218
    /* if -1 is set then that direction is invalid */
219
110k
    i1_cur_ref_idx_list[0] = (-1 == ps_pu->mv.i1_l0_ref_idx) ? 0 : ps_pu->mv.i1_l0_ref_idx;
220
110k
    i1_cur_ref_idx_list[1] = (-1 == ps_pu->mv.i1_l1_ref_idx) ? 0 : ps_pu->mv.i1_l1_ref_idx;
221
222
    /************************************************************/
223
    /* Calculating of motion vector A from neighbors A0 and A1  */
224
    /************************************************************/
225
110k
    {
226
110k
        WORD32 l_x, a;
227
110k
        WORD32 *pi4_avail_flag;
228
110k
        WORD32 nbr_avail[2]; /*[A0/A1] */
229
110k
        WORD8 i1_nbr_ref_idx_list[2][2]; /* [A0/A1][L0/L1] */
230
110k
        UWORD8 u1_nbr_intra_flag[2]; /*[A0/A1] */
231
110k
        UWORD8 u1_nbr_pred_flag[2][2]; /* [A0/A1][L0/L1] */
232
110k
        mv_t *ps_mv;
233
110k
        nbr_4x4_t *ps_a0, *ps_a1;
234
110k
        mv_t *ps_nbr_mv[2][2]; /* [A0/A1][L0/L1] */
235
236
        /* A0 and A1 initializations */
237
110k
        ps_mv = &as_mv_a[0];
238
110k
        pi4_avail_flag = avail_a_flag;
239
240
        /* Pointers to A0 and A1 */
241
110k
        {
242
110k
            WORD32 y_a0, y_a1;
243
            /* TODO: y_a0, y_a1 is coded assuming left nbr pointer starts at PU */
244
110k
            y_a0 = (part_ht >> 2);
245
110k
            y_a1 = ((part_ht - 1) >> 2);
246
247
110k
            ps_a0 = ps_left_nbr_4x4 + (y_a0 * left_nbr_4x4_strd);
248
110k
            ps_a1 = ps_left_nbr_4x4 + (y_a1 * left_nbr_4x4_strd);
249
110k
        }
250
251
110k
        nbr_avail[0] = lb_avail && (!ps_a0->b1_intra_flag);
252
110k
        nbr_avail[1] = l_avail && (!ps_a1->b1_intra_flag);
253
254
        /* Setting is scaled flag based on availability of A0 and A1 */
255
110k
        if((nbr_avail[0] == 1) || (nbr_avail[1]))
256
43.4k
        {
257
43.4k
            is_scaled_flag_list[0] = 1;
258
43.4k
            is_scaled_flag_list[1] = 1;
259
43.4k
        }
260
261
        /* Initializing A0 variables */
262
110k
        ps_nbr_mv[0][0] = &ps_a0->mv.s_l0_mv;
263
110k
        ps_nbr_mv[0][1] = &ps_a0->mv.s_l1_mv;
264
265
110k
        i1_nbr_ref_idx_list[0][0] = ps_a0->mv.i1_l0_ref_idx;
266
110k
        i1_nbr_ref_idx_list[0][1] = ps_a0->mv.i1_l1_ref_idx;
267
268
110k
        u1_nbr_pred_flag[0][0] = (UWORD8)ps_a0->b1_pred_l0_flag;
269
110k
        u1_nbr_pred_flag[0][1] = (UWORD8)ps_a0->b1_pred_l1_flag;
270
271
110k
        u1_nbr_intra_flag[0] = (UWORD8)ps_a0->b1_intra_flag;
272
273
        /* Initializing A1 variables */
274
110k
        ps_nbr_mv[1][0] = &ps_a1->mv.s_l0_mv;
275
110k
        ps_nbr_mv[1][1] = &ps_a1->mv.s_l1_mv;
276
277
110k
        i1_nbr_ref_idx_list[1][0] = ps_a1->mv.i1_l0_ref_idx;
278
110k
        i1_nbr_ref_idx_list[1][1] = ps_a1->mv.i1_l1_ref_idx;
279
280
110k
        u1_nbr_pred_flag[1][0] = (UWORD8)ps_a1->b1_pred_l0_flag;
281
110k
        u1_nbr_pred_flag[1][1] = (UWORD8)ps_a1->b1_pred_l1_flag;
282
283
110k
        u1_nbr_intra_flag[1] = (UWORD8)ps_a1->b1_intra_flag;
284
285
        /* Derivation of mvL0A and mvL1A from A0 and A1 */
286
332k
        for(l_x = 0; l_x < 2; l_x++) /* list 0 and list 1 */
287
221k
        {
288
221k
            WORD32 l_y;
289
290
221k
            l_y = !l_x; /* if i=0, y = L1 else y = L0 */
291
292
585k
            for(a = 0; a < 2; a++)
293
427k
            {
294
                /* MODE_INTRA check has been taken care in availability check */
295
427k
                if((nbr_avail[a] == 1) && (pi4_avail_flag[l_x] == 0))
296
91.9k
                {
297
91.9k
                    if(u1_nbr_pred_flag[a][l_x] == 1)
298
48.6k
                    {
299
48.6k
                        WORD32 nbr_ref_poc, cur_ref_poc;
300
48.6k
                        WORD8 i1_cur_ref_idx, i1_nbr_ref_idx;
301
302
48.6k
                        i1_cur_ref_idx = i1_cur_ref_idx_list[l_x];
303
48.6k
                        cur_ref_poc = ps_ctxt->ps_ref_list[l_x][i1_cur_ref_idx]->i4_poc;
304
48.6k
                        i1_nbr_ref_idx = i1_nbr_ref_idx_list[a][l_x];
305
48.6k
                        nbr_ref_poc = ps_ctxt->ps_ref_list[l_x][i1_nbr_ref_idx]->i4_poc;
306
307
48.6k
                        if(nbr_ref_poc == cur_ref_poc)
308
36.7k
                        {
309
36.7k
                            pi4_avail_flag[l_x] = 1;
310
36.7k
                            ps_mv[l_x] = *ps_nbr_mv[a][l_x];
311
36.7k
                            break;
312
36.7k
                        }
313
48.6k
                    }
314
55.1k
                    if(u1_nbr_pred_flag[a][l_y] == 1)
315
43.8k
                    {
316
43.8k
                        WORD32 nbr_ref_poc, cur_ref_poc;
317
43.8k
                        WORD8 i1_nbr_ref_idx, i1_cur_ref_idx;
318
319
43.8k
                        i1_cur_ref_idx = i1_cur_ref_idx_list[l_x];
320
43.8k
                        cur_ref_poc = ps_ctxt->ps_ref_list[l_x][i1_cur_ref_idx]->i4_poc;
321
322
43.8k
                        i1_nbr_ref_idx = i1_nbr_ref_idx_list[a][l_y];
323
43.8k
                        nbr_ref_poc = ps_ctxt->ps_ref_list[l_y][i1_nbr_ref_idx]->i4_poc;
324
43.8k
                        if(nbr_ref_poc == cur_ref_poc)
325
27.5k
                        {
326
27.5k
                            pi4_avail_flag[l_x] = 1;
327
27.5k
                            ps_mv[l_x] = *ps_nbr_mv[a][l_y];
328
27.5k
                            break;
329
27.5k
                        }
330
43.8k
                    }
331
55.1k
                }
332
427k
            }
333
221k
        }
334
335
332k
        for(l_x = 0; l_x < 2; l_x++) /* list 0 and list 1 */
336
221k
        {
337
221k
            if(pi4_avail_flag[l_x] == 0)
338
157k
            {
339
157k
                WORD8 i1_nbr_ref_list_idx, i1_nbr_ref_idx;
340
157k
                WORD32 l_y;
341
342
157k
                l_y = !l_x; /* if i=0, y = L1 else y = L0 */
343
344
444k
                for(a = 0; a < 2; a++)
345
309k
                {
346
                    /* MODE_INTRA check has been taken care in availability check */
347
309k
                    if((nbr_avail[a] == 1) && (pi4_avail_flag[l_x] == 0))
348
22.6k
                    {
349
                        /* Long term reference check Removed */
350
22.6k
                        if(u1_nbr_pred_flag[a][l_x] == 1)
351
9.79k
                        {
352
9.79k
                            pi4_avail_flag[l_x] = 1;
353
9.79k
                            ps_mv[l_x] = *ps_nbr_mv[a][l_x];
354
9.79k
                            i1_nbr_ref_idx = i1_nbr_ref_idx_list[a][l_x];
355
9.79k
                            i1_nbr_ref_list_idx = l_x;
356
9.79k
                            break;
357
9.79k
                        }
358
                        /* Long term reference check Removed */
359
12.8k
                        else if(u1_nbr_pred_flag[a][l_y] == 1)
360
12.8k
                        {
361
12.8k
                            pi4_avail_flag[l_x] = 1;
362
12.8k
                            ps_mv[l_x] = *ps_nbr_mv[a][l_y];
363
12.8k
                            i1_nbr_ref_idx = i1_nbr_ref_idx_list[a][l_y];
364
12.8k
                            i1_nbr_ref_list_idx = l_y;
365
12.8k
                            break;
366
12.8k
                        }
367
22.6k
                    }
368
309k
                }
369
370
                /* Long term reference check Removed */
371
157k
                if(pi4_avail_flag[l_x] == 1)
372
22.6k
                {
373
22.6k
                    WORD8 i1_cur_ref_idx;
374
22.6k
                    WORD32 cur_ref_poc, nbr_ref_poc;
375
22.6k
                    WORD32 cur_poc;
376
377
22.6k
                    i1_cur_ref_idx = i1_cur_ref_idx_list[l_x];
378
22.6k
                    cur_ref_poc = ps_ctxt->ps_ref_list[l_x][i1_cur_ref_idx]->i4_poc;
379
380
22.6k
                    nbr_ref_poc = ps_ctxt->ps_ref_list[i1_nbr_ref_list_idx][i1_nbr_ref_idx]->i4_poc;
381
382
22.6k
                    cur_poc = ps_ctxt->ps_slice_hdr->i4_abs_pic_order_cnt;
383
384
22.6k
                    ihevce_scale_mv(&ps_mv[l_x], cur_ref_poc, nbr_ref_poc, cur_poc);
385
22.6k
                }
386
157k
            }
387
221k
        }
388
110k
    }
389
390
    /************************************************************/
391
    /* Calculating of motion vector B from neighbors B0 and B1  */
392
    /************************************************************/
393
110k
    {
394
110k
        WORD32 l_x, b;
395
110k
        WORD32 *pi4_avail_flag;
396
110k
        WORD32 nbr_avail[3]; /* [B0/B1/B2] */
397
110k
        WORD8 i1_nbr_ref_idx_list[3][2]; /* [B0/B1/B2][L0/L1] */
398
110k
        UWORD8 u1_nbr_intra_flag[3]; /*[B0/B1/B2] */
399
110k
        UWORD8 u1_nbr_pred_flag[3][2]; /* [B0/B1/B2][L0/L1] */
400
110k
        mv_t *ps_mv;
401
110k
        nbr_4x4_t *ps_b0, *ps_b1, *ps_b2;
402
110k
        mv_t *ps_nbr_mv[3][2]; /* [B0/B1/B2][L0/L1] */
403
404
        /* B0, B1 and B2 initializations */
405
110k
        ps_mv = &as_mv_b[0];
406
110k
        pi4_avail_flag = avail_b_flag;
407
408
        /* Pointers to B0, B1 and B2 */
409
110k
        {
410
110k
            WORD32 x_b0, x_b1, x_b2;
411
412
            /* Relative co-ordiante of Xp,Yp w.r.t CTB start will work */
413
            /* as long as minCTB = 16                                  */
414
110k
            x_b0 = (part_pos_x + part_wd);
415
110k
            x_b1 = (part_pos_x + part_wd - 1);
416
110k
            x_b2 = (part_pos_x - 1);
417
418
            /* Getting offset back to given pointer */
419
110k
            x_b0 = x_b0 - part_pos_x;
420
110k
            x_b1 = x_b1 - part_pos_x;
421
110k
            x_b2 = x_b2 - part_pos_x;
422
423
            /* Below derivation are based on top pointer */
424
            /* is pointing first pixel of PU             */
425
110k
            ps_b0 = ps_top_nbr_4x4 + (x_b0 >> 2);
426
110k
            ps_b1 = ps_top_nbr_4x4 + (x_b1 >> 2);
427
428
            /* At CTB boundary, use top-left passed in */
429
110k
            if(part_pos_y)
430
83.6k
            {
431
83.6k
                ps_b2 = ps_top_left_nbr_4x4;
432
83.6k
            }
433
27.2k
            else
434
27.2k
            {
435
                /* Not at CTB boundary, use top and  */
436
                /* add correction to go to top-left */
437
27.2k
                ps_b2 = (ps_top_nbr_4x4) + (x_b2 >> 2);
438
27.2k
            }
439
110k
        }
440
110k
        nbr_avail[0] = tr_avail && (!ps_b0->b1_intra_flag);
441
110k
        nbr_avail[1] = t_avail && (!ps_b1->b1_intra_flag);
442
110k
        nbr_avail[2] = tl_avail && (!ps_b2->b1_intra_flag);
443
444
        /* Initializing B0 related variables */
445
110k
        ps_nbr_mv[0][0] = &ps_b0->mv.s_l0_mv;
446
110k
        ps_nbr_mv[0][1] = &ps_b0->mv.s_l1_mv;
447
448
110k
        i1_nbr_ref_idx_list[0][0] = ps_b0->mv.i1_l0_ref_idx;
449
110k
        i1_nbr_ref_idx_list[0][1] = ps_b0->mv.i1_l1_ref_idx;
450
451
110k
        u1_nbr_pred_flag[0][0] = (UWORD8)ps_b0->b1_pred_l0_flag;
452
110k
        u1_nbr_pred_flag[0][1] = (UWORD8)ps_b0->b1_pred_l1_flag;
453
454
110k
        u1_nbr_intra_flag[0] = (UWORD8)ps_b0->b1_intra_flag;
455
456
        /* Initializing B1 related variables */
457
110k
        ps_nbr_mv[1][0] = &ps_b1->mv.s_l0_mv;
458
110k
        ps_nbr_mv[1][1] = &ps_b1->mv.s_l1_mv;
459
460
110k
        i1_nbr_ref_idx_list[1][0] = ps_b1->mv.i1_l0_ref_idx;
461
110k
        i1_nbr_ref_idx_list[1][1] = ps_b1->mv.i1_l1_ref_idx;
462
463
110k
        u1_nbr_pred_flag[1][0] = (UWORD8)ps_b1->b1_pred_l0_flag;
464
110k
        u1_nbr_pred_flag[1][1] = (UWORD8)ps_b1->b1_pred_l1_flag;
465
466
110k
        u1_nbr_intra_flag[1] = (UWORD8)ps_b1->b1_intra_flag;
467
468
        /* Initializing B2 related variables */
469
110k
        ps_nbr_mv[2][0] = &ps_b2->mv.s_l0_mv;
470
110k
        ps_nbr_mv[2][1] = &ps_b2->mv.s_l1_mv;
471
472
110k
        i1_nbr_ref_idx_list[2][0] = ps_b2->mv.i1_l0_ref_idx;
473
110k
        i1_nbr_ref_idx_list[2][1] = ps_b2->mv.i1_l1_ref_idx;
474
475
110k
        u1_nbr_pred_flag[2][0] = (UWORD8)ps_b2->b1_pred_l0_flag;
476
110k
        u1_nbr_pred_flag[2][1] = (UWORD8)ps_b2->b1_pred_l1_flag;
477
478
110k
        u1_nbr_intra_flag[2] = (UWORD8)ps_b2->b1_intra_flag;
479
480
        /* Derivation of mvL0B and mvL1B from B0,B1 and B2 */
481
332k
        for(l_x = 0; l_x < 2; l_x++) /* list 0 and list 1 */
482
221k
        {
483
221k
            WORD32 l_y;
484
485
221k
            l_y = !l_x; /* if i=0, y = L1 else y = L0 */
486
487
694k
            for(b = 0; b < 3; b++)
488
557k
            {
489
557k
                if((nbr_avail[b] == 1) && (pi4_avail_flag[l_x] == 0))
490
132k
                {
491
132k
                    if(u1_nbr_pred_flag[b][l_x] == 1)
492
66.9k
                    {
493
66.9k
                        WORD32 nbr_ref_poc, cur_ref_poc;
494
66.9k
                        WORD8 i1_cur_ref_idx, i1_nbr_ref_idx;
495
496
66.9k
                        i1_cur_ref_idx = i1_cur_ref_idx_list[l_x];
497
66.9k
                        cur_ref_poc = ps_ctxt->ps_ref_list[l_x][i1_cur_ref_idx]->i4_poc;
498
66.9k
                        i1_nbr_ref_idx = i1_nbr_ref_idx_list[b][l_x];
499
66.9k
                        nbr_ref_poc = ps_ctxt->ps_ref_list[l_x][i1_nbr_ref_idx]->i4_poc;
500
501
66.9k
                        if(nbr_ref_poc == cur_ref_poc)
502
45.5k
                        {
503
45.5k
                            pi4_avail_flag[l_x] = 1;
504
45.5k
                            ps_mv[l_x] = *ps_nbr_mv[b][l_x];
505
45.5k
                            break;
506
45.5k
                        }
507
66.9k
                    }
508
87.2k
                    if(u1_nbr_pred_flag[b][l_y] == 1)
509
65.9k
                    {
510
65.9k
                        WORD32 nbr_ref_poc, cur_ref_poc;
511
65.9k
                        WORD8 i1_nbr_ref_idx, i1_cur_ref_idx;
512
513
65.9k
                        i1_cur_ref_idx = i1_cur_ref_idx_list[l_x];
514
65.9k
                        cur_ref_poc = ps_ctxt->ps_ref_list[l_x][i1_cur_ref_idx]->i4_poc;
515
516
65.9k
                        i1_nbr_ref_idx = i1_nbr_ref_idx_list[b][l_y];
517
65.9k
                        nbr_ref_poc = ps_ctxt->ps_ref_list[l_y][i1_nbr_ref_idx]->i4_poc;
518
519
65.9k
                        if(nbr_ref_poc == cur_ref_poc)
520
38.9k
                        {
521
38.9k
                            pi4_avail_flag[l_x] = 1;
522
38.9k
                            ps_mv[l_x] = *ps_nbr_mv[b][l_y];
523
38.9k
                            break;
524
38.9k
                        }
525
65.9k
                    }
526
87.2k
                }
527
557k
            }
528
221k
        }
529
530
110k
        if((is_scaled_flag_list[0] == 0) && (avail_b_flag[0] == 1))
531
21.7k
        {
532
21.7k
            avail_a_flag[0] = 1;
533
21.7k
            as_mv_a[0] = as_mv_b[0];
534
21.7k
        }
535
110k
        if((is_scaled_flag_list[1] == 0) && (avail_b_flag[1] == 1))
536
21.7k
        {
537
21.7k
            avail_a_flag[1] = 1;
538
21.7k
            as_mv_a[1] = as_mv_b[1];
539
21.7k
        }
540
541
332k
        for(l_x = 0; l_x < 2; l_x++) /* list 0 and list 1 */
542
221k
        {
543
221k
            if(is_scaled_flag_list[l_x] == 0)
544
134k
            {
545
                /* If isScaledFlagLX == 0, availFlagLXB flag is set to 0 */
546
134k
                pi4_avail_flag[l_x] = 0;
547
134k
                {
548
134k
                    WORD8 i1_nbr_ref_list_idx, i1_nbr_ref_idx;
549
134k
                    WORD32 l_y;
550
551
134k
                    l_y = !l_x; /* if i=0, y = L1 else y = L0 */
552
553
417k
                    for(b = 0; b < 3; b++)
554
336k
                    {
555
336k
                        if((nbr_avail[b] == 1) && (pi4_avail_flag[l_x] == 0))
556
54.6k
                        {
557
                            /* Long term reference check Removed */
558
54.6k
                            if(u1_nbr_pred_flag[b][l_x] == 1)
559
27.6k
                            {
560
27.6k
                                pi4_avail_flag[l_x] = 1;
561
27.6k
                                ps_mv[l_x] = *ps_nbr_mv[b][l_x];
562
27.6k
                                i1_nbr_ref_idx = i1_nbr_ref_idx_list[b][l_x];
563
27.6k
                                i1_nbr_ref_list_idx = l_x;
564
27.6k
                                break;
565
27.6k
                            }
566
                            /* Long term reference check Removed */
567
27.0k
                            else if(u1_nbr_pred_flag[b][l_y] == 1)
568
27.0k
                            {
569
27.0k
                                pi4_avail_flag[l_x] = 1;
570
27.0k
                                ps_mv[l_x] = *ps_nbr_mv[b][l_y];
571
27.0k
                                i1_nbr_ref_idx = i1_nbr_ref_idx_list[b][l_y];
572
27.0k
                                i1_nbr_ref_list_idx = l_y;
573
27.0k
                                break;
574
27.0k
                            }
575
54.6k
                        }
576
336k
                    }
577
                    /* Long term reference check Removed */
578
134k
                    if(pi4_avail_flag[l_x] == 1)
579
54.6k
                    {
580
54.6k
                        WORD8 i1_cur_ref_idx;
581
54.6k
                        WORD32 cur_ref_poc, nbr_ref_poc;
582
54.6k
                        WORD32 cur_poc;
583
584
54.6k
                        i1_cur_ref_idx = i1_cur_ref_idx_list[l_x];
585
54.6k
                        cur_ref_poc = ps_ctxt->ps_ref_list[l_x][i1_cur_ref_idx]->i4_poc;
586
587
54.6k
                        nbr_ref_poc =
588
54.6k
                            ps_ctxt->ps_ref_list[i1_nbr_ref_list_idx][i1_nbr_ref_idx]->i4_poc;
589
590
54.6k
                        cur_poc = ps_ctxt->ps_slice_hdr->i4_abs_pic_order_cnt;
591
592
54.6k
                        if(cur_ref_poc != nbr_ref_poc)
593
11.5k
                            ihevce_scale_mv(&ps_mv[l_x], cur_ref_poc, nbr_ref_poc, cur_poc);
594
54.6k
                    }
595
134k
                }
596
134k
            }
597
221k
        }
598
110k
    }
599
600
    /* Candidate list */
601
110k
    {
602
110k
        mv_t as_mvp_list_l0[MAX_MVP_LIST_CAND_MEM]; /*[Cand0/Cand1/Cand2] */
603
110k
        mv_t as_mvp_list_l1[MAX_MVP_LIST_CAND_MEM]; /*[Cand0/Cand1/Cand2] */
604
110k
        UWORD8 au1_is_top_used_l0[MAX_MVP_LIST_CAND_MEM];
605
110k
        UWORD8 au1_is_top_used_l1[MAX_MVP_LIST_CAND_MEM];
606
110k
        WORD32 num_mvp_cand_l0;
607
110k
        WORD32 num_mvp_cand_l1;
608
609
        /* L0 candidate list*/
610
110k
        num_mvp_cand_l0 = 0;
611
612
110k
        if(avail_a_flag[0] == 1)
613
65.1k
        {
614
65.1k
            as_mvp_list_l0[num_mvp_cand_l0] = as_mv_a[0];
615
65.1k
            au1_is_top_used_l0[num_mvp_cand_l0] = (is_scaled_flag_list[0] == 0);
616
65.1k
            num_mvp_cand_l0++;
617
65.1k
        }
618
110k
        if(avail_b_flag[0] == 1)
619
47.7k
        {
620
47.7k
            if(((as_mv_a[0].i2_mvx != as_mv_b[0].i2_mvx) ||
621
35.7k
                (as_mv_a[0].i2_mvy != as_mv_b[0].i2_mvy)) ||
622
33.3k
               (0 == num_mvp_cand_l0))
623
15.9k
            {
624
15.9k
                as_mvp_list_l0[num_mvp_cand_l0] = as_mv_b[0];
625
15.9k
                au1_is_top_used_l0[num_mvp_cand_l0] = 1;
626
15.9k
                num_mvp_cand_l0++;
627
15.9k
            }
628
47.7k
        }
629
630
        /* L1 candidate list*/
631
110k
        num_mvp_cand_l1 = 0;
632
633
110k
        if(avail_a_flag[1] == 1)
634
65.2k
        {
635
65.2k
            as_mvp_list_l1[num_mvp_cand_l1] = as_mv_a[1];
636
65.2k
            au1_is_top_used_l1[num_mvp_cand_l1] = (is_scaled_flag_list[1] == 0);
637
65.2k
            num_mvp_cand_l1++;
638
65.2k
        }
639
110k
        if(avail_b_flag[1] == 1)
640
47.8k
        {
641
47.8k
            if(((as_mv_a[1].i2_mvx != as_mv_b[1].i2_mvx) ||
642
35.4k
                (as_mv_a[1].i2_mvy != as_mv_b[1].i2_mvy)) ||
643
32.9k
               (0 == num_mvp_cand_l1))
644
16.1k
            {
645
16.1k
                as_mvp_list_l1[num_mvp_cand_l1] = as_mv_b[1];
646
16.1k
                au1_is_top_used_l1[num_mvp_cand_l1] = 1;
647
16.1k
                num_mvp_cand_l1++;
648
16.1k
            }
649
47.8k
        }
650
651
        /***********************************************************/
652
        /*          Collocated MV prediction                       */
653
        /***********************************************************/
654
110k
        if((MAX_MVP_LIST_CAND > num_mvp_cand_l0) || (MAX_MVP_LIST_CAND > num_mvp_cand_l1))
655
101k
        {
656
101k
            mv_t as_mv_col[2], s_mv_col_l0, s_mv_col_l1;
657
101k
            WORD32 avail_col_flag[2] = { 0 };
658
101k
            WORD32 x_col, y_col, avail_col_l0, avail_col_l1;
659
660
101k
            x_col = part_pos_x + part_wd;
661
101k
            y_col = part_pos_y + part_ht;
662
101k
            ihevce_collocated_mvp(ps_ctxt, ps_pu, as_mv_col, avail_col_flag, 1, x_col, y_col);
663
664
101k
            avail_col_l0 = avail_col_flag[0];
665
101k
            avail_col_l1 = avail_col_flag[1];
666
101k
            if(avail_col_l0 || avail_col_l1)
667
21.7k
            {
668
21.7k
                s_mv_col_l0 = as_mv_col[0];
669
21.7k
                s_mv_col_l1 = as_mv_col[1];
670
21.7k
            }
671
672
101k
            if(avail_col_l0 == 0 || avail_col_l1 == 0)
673
101k
            {
674
                /* Checking Collocated MV availability at Center of PU */
675
101k
                x_col = part_pos_x + (part_wd >> 1);
676
101k
                y_col = part_pos_y + (part_ht >> 1);
677
101k
                ihevce_collocated_mvp(ps_ctxt, ps_pu, as_mv_col, avail_col_flag, 1, x_col, y_col);
678
679
101k
                if(avail_col_l0 == 0)
680
81.8k
                {
681
81.8k
                    s_mv_col_l0 = as_mv_col[0];
682
81.8k
                }
683
101k
                if(avail_col_l1 == 0)
684
99.4k
                {
685
99.4k
                    s_mv_col_l1 = as_mv_col[1];
686
99.4k
                }
687
688
101k
                avail_col_l0 |= avail_col_flag[0];
689
101k
                avail_col_l1 |= avail_col_flag[1];
690
101k
            }
691
692
            /* Checking if mvp index matches collocated mv */
693
101k
            if(avail_col_l0)
694
30.8k
            {
695
30.8k
                if(MAX_MVP_LIST_CAND > num_mvp_cand_l0)
696
30.0k
                {
697
30.0k
                    as_mvp_list_l0[num_mvp_cand_l0] = s_mv_col_l0;
698
30.0k
                    au1_is_top_used_l0[num_mvp_cand_l0] = 0;
699
30.0k
                    num_mvp_cand_l0++;
700
30.0k
                }
701
30.8k
            }
702
101k
            if(avail_col_l1)
703
2.60k
            {
704
2.60k
                if(MAX_MVP_LIST_CAND > num_mvp_cand_l1)
705
2.49k
                {
706
2.49k
                    as_mvp_list_l1[num_mvp_cand_l1] = s_mv_col_l1;
707
2.49k
                    au1_is_top_used_l1[num_mvp_cand_l1] = 0;
708
2.49k
                    num_mvp_cand_l1++;
709
2.49k
                }
710
2.60k
            }
711
101k
        }
712
713
        /* Adding zero if mv candidates are less than 2 */
714
221k
        while(num_mvp_cand_l0 < MAX_MVP_LIST_CAND)
715
110k
        {
716
110k
            as_mvp_list_l0[num_mvp_cand_l0].i2_mvx = 0;
717
110k
            as_mvp_list_l0[num_mvp_cand_l0].i2_mvy = 0;
718
110k
            au1_is_top_used_l0[num_mvp_cand_l0] = 0;
719
110k
            num_mvp_cand_l0++;
720
110k
        };
721
248k
        while(num_mvp_cand_l1 < MAX_MVP_LIST_CAND)
722
137k
        {
723
137k
            as_mvp_list_l1[num_mvp_cand_l1].i2_mvx = 0;
724
137k
            as_mvp_list_l1[num_mvp_cand_l1].i2_mvy = 0;
725
137k
            au1_is_top_used_l1[num_mvp_cand_l1] = 0;
726
137k
            num_mvp_cand_l1++;
727
137k
        };
728
        /* Removing mvs if candidates are greater than 2 */
729
110k
        if(num_mvp_cand_l0 > MAX_MVP_LIST_CAND)
730
0
        {
731
0
            num_mvp_cand_l0 = MAX_MVP_LIST_CAND;
732
0
        };
733
110k
        if(num_mvp_cand_l1 > MAX_MVP_LIST_CAND)
734
0
        {
735
0
            num_mvp_cand_l1 = MAX_MVP_LIST_CAND;
736
0
        };
737
738
        /* Copying list to output */
739
110k
        {
740
110k
            WORD32 i;
741
332k
            for(i = 0; i < num_mvp_cand_l0; i++)
742
221k
            {
743
221k
                ps_pred_mv[i].s_l0_mv = as_mvp_list_l0[i];
744
221k
                pau1_is_top_used[0][i] = au1_is_top_used_l0[i];
745
221k
            }
746
747
332k
            for(i = 0; i < num_mvp_cand_l1; i++)
748
221k
            {
749
221k
                ps_pred_mv[i].s_l1_mv = as_mvp_list_l1[i];
750
221k
                pau1_is_top_used[1][i] = au1_is_top_used_l1[i];
751
221k
            }
752
110k
        }
753
110k
    }
754
110k
}