Coverage Report

Created: 2024-07-27 06:32

/src/libavc/decoder/ih264d_mvpred.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_mvpred.c
23
 *
24
 * \brief
25
 *    This file contains function specific to decoding Motion vector.
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    10-12-2002
31
 *
32
 * \author  Arvind Raman
33
 **************************************************************************
34
 */
35
#include <string.h>
36
#include "ih264d_parse_cavlc.h"
37
#include "ih264d_error_handler.h"
38
#include "ih264d_structs.h"
39
#include "ih264d_defs.h"
40
#include "ih264_typedefs.h"
41
#include "ih264_macros.h"
42
#include "ih264_platform_macros.h"
43
#include "ih264d_mb_utils.h"
44
#include "ih264d_defs.h"
45
#include "ih264d_debug.h"
46
#include "ih264d_tables.h"
47
#include "ih264d_process_bslice.h"
48
#include "ih264d_mvpred.h"
49
#include "ih264d_inter_pred.h"
50
#include "ih264d_tables.h"
51
52
/*!
53
 **************************************************************************
54
 * \if ih264d_get_motion_vector_predictor name : Name \endif
55
 *
56
 * \brief
57
 *    The routine calculates the motion vector predictor for a given block,
58
 *    given the candidate MV predictors.
59
 *
60
 * \param ps_mv_pred: Candidate predictors for the current block
61
 * \param ps_currMv: Pointer to the left top edge of the current block in
62
 *     the MV bank
63
 *
64
 * \return
65
 *    _mvPred: The x & y components of the MV predictor.
66
 *
67
 * \note
68
 *    The code implements the logic as described in sec 8.4.1.2.1. Given
69
 *    the candidate predictors and the pointer to the top left edge of the
70
 *    block in the MV bank.
71
 *
72
 **************************************************************************
73
 */
74
75
void ih264d_get_motion_vector_predictor(mv_pred_t * ps_result,
76
                                        mv_pred_t **ps_mv_pred,
77
                                        UWORD8 u1_ref_idx,
78
                                        UWORD8 u1_B,
79
                                        const UWORD8 *pu1_mv_pred_condition)
80
1.48M
{
81
1.48M
    WORD8 c_temp;
82
1.48M
    UWORD8 uc_B2 = (u1_B << 1);
83
84
    /* If only one of the candidate blocks has a reference frame equal to
85
     the current block then use the same block as the final predictor */
86
1.48M
    c_temp =
87
1.48M
                    (ps_mv_pred[LEFT]->i1_ref_frame[u1_B] == u1_ref_idx)
88
1.48M
                                    | ((ps_mv_pred[TOP]->i1_ref_frame[u1_B]
89
1.48M
                                                    == u1_ref_idx) << 1)
90
1.48M
                                    | ((ps_mv_pred[TOP_R]->i1_ref_frame[u1_B]
91
1.48M
                                                    == u1_ref_idx) << 2);
92
1.48M
    c_temp = pu1_mv_pred_condition[c_temp];
93
94
1.48M
    if(c_temp != -1)
95
108k
    {
96
        /* Case when only when one of the cadidate block has the same
97
         reference frame as the current block */
98
108k
        ps_result->i2_mv[uc_B2 + 0] = ps_mv_pred[c_temp]->i2_mv[uc_B2 + 0];
99
108k
        ps_result->i2_mv[uc_B2 + 1] = ps_mv_pred[c_temp]->i2_mv[uc_B2 + 1];
100
108k
    }
101
1.37M
    else
102
1.37M
    {
103
1.37M
        WORD32 D0, D1;
104
1.37M
        D0 = MIN(ps_mv_pred[0]->i2_mv[uc_B2 + 0],
105
1.37M
                 ps_mv_pred[1]->i2_mv[uc_B2 + 0]);
106
1.37M
        D1 = MAX(ps_mv_pred[0]->i2_mv[uc_B2 + 0],
107
1.37M
                 ps_mv_pred[1]->i2_mv[uc_B2 + 0]);
108
1.37M
        D1 = MIN(D1, ps_mv_pred[2]->i2_mv[uc_B2 + 0]);
109
1.37M
        ps_result->i2_mv[uc_B2 + 0] = (WORD16)(MAX(D0, D1));
110
111
1.37M
        D0 = MIN(ps_mv_pred[0]->i2_mv[uc_B2 + 1],
112
1.37M
                 ps_mv_pred[1]->i2_mv[uc_B2 + 1]);
113
1.37M
        D1 = MAX(ps_mv_pred[0]->i2_mv[uc_B2 + 1],
114
1.37M
                 ps_mv_pred[1]->i2_mv[uc_B2 + 1]);
115
1.37M
        D1 = MIN(D1, ps_mv_pred[2]->i2_mv[uc_B2 + 1]);
116
1.37M
        ps_result->i2_mv[uc_B2 + 1] = (WORD16)(MAX(D0, D1));
117
118
1.37M
    }
119
1.48M
}
120
121
/*!
122
 **************************************************************************
123
 * \if ih264d_mbaff_mv_pred name : Name \endif
124
 *
125
 * \brief
126
 *    The routine calculates the motion vector predictor for a given block,
127
 *    given the candidate MV predictors.
128
 *
129
 * \param ps_mv_pred: Candidate predictors for the current block
130
 * \param ps_currMv: Pointer to the left top edge of the current block in
131
 *     the MV bank
132
 *
133
 * \return
134
 *    _mvPred: The x & y components of the MV predictor.
135
 *
136
 * \note
137
 *    The code implements the logic as described in sec 8.4.1.2.1. Given
138
 *    the candidate predictors and the pointer to the top left edge of the
139
 *    block in the MV bank.
140
 *
141
 **************************************************************************
142
 */
143
144
void ih264d_mbaff_mv_pred(mv_pred_t **ps_mv_pred,
145
                          UWORD8 u1_sub_mb_num,
146
                          mv_pred_t *ps_mv_nmb,
147
                          mv_pred_t *ps_mv_ntop,
148
                          dec_struct_t *ps_dec,
149
                          UWORD8 uc_mb_part_width,
150
                          dec_mb_info_t *ps_cur_mb_info,
151
                          UWORD8* pu0_scale)
152
2.48M
{
153
2.48M
    UWORD16 u2_a_in = 0, u2_b_in = 0, u2_c_in = 0, u2_d_in = 0;
154
2.48M
    mv_pred_t *ps_mvpred_l, *ps_mvpred_tmp;
155
2.48M
    UWORD8 u1_sub_mb_x = (u1_sub_mb_num & 3), uc_sub_mb_y = (u1_sub_mb_num >> 2);
156
2.48M
    UWORD8 u1_is_cur_mb_fld, u1_is_left_mb_fld, u1_is_top_mb_fld;
157
2.48M
    UWORD8 u1_is_cur_mb_top;
158
159
2.48M
    u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag;
160
2.48M
    u1_is_cur_mb_top = ps_cur_mb_info->u1_topmb;
161
162
2.48M
    u1_is_left_mb_fld = ps_cur_mb_info->ps_left_mb->u1_mb_fld;
163
2.48M
    u1_is_top_mb_fld = ps_cur_mb_info->ps_top_mb->u1_mb_fld;
164
165
    /* Checking in the subMB exists, calculating their motion vectors to be
166
     used as predictors and the reference frames of those subMBs */
167
2.48M
    ps_mv_pred[LEFT] = &ps_dec->s_default_mv_pred;
168
2.48M
    ps_mv_pred[TOP] = &(ps_dec->s_default_mv_pred);
169
2.48M
    ps_mv_pred[TOP_R] = &(ps_dec->s_default_mv_pred);
170
171
    /* Check if the left subMb is available */
172
2.48M
    if(u1_sub_mb_x)
173
175k
    {
174
175k
        u2_a_in = 1;
175
175k
        ps_mv_pred[LEFT] = (ps_mv_nmb - 1);
176
175k
    }
177
2.30M
    else
178
2.30M
    {
179
2.30M
        UWORD8 uc_temp;
180
2.30M
        u2_a_in = (ps_cur_mb_info->u1_mb_ngbr_availablity & LEFT_MB_AVAILABLE_MASK);
181
2.30M
        if(u2_a_in)
182
2.16M
        {
183
2.16M
            ps_mvpred_l = (ps_dec->u4_num_pmbair) ?
184
2.16M
                            ps_mv_nmb :
185
2.16M
                            (ps_dec->ps_mv_left + (uc_sub_mb_y << 2) + 48
186
10
                                            - (u1_is_cur_mb_top << 4));
187
2.16M
            uc_temp = 29;
188
2.16M
            if(u1_is_cur_mb_fld ^ u1_is_left_mb_fld)
189
50.7k
            {
190
50.7k
                if(u1_is_left_mb_fld)
191
24.2k
                {
192
24.2k
                    uc_temp +=
193
24.2k
                                    (((uc_sub_mb_y & 1) << 2)
194
24.2k
                                                    + ((uc_sub_mb_y & 2) << 1));
195
24.2k
                    uc_temp += ((u1_is_cur_mb_top) ? 0 : 8);
196
24.2k
                }
197
26.5k
                else
198
26.5k
                {
199
26.5k
                    uc_temp = uc_temp - (uc_sub_mb_y << 2);
200
26.5k
                    uc_temp += ((u1_is_cur_mb_top) ? 0 : 16);
201
26.5k
                }
202
50.7k
            }
203
2.16M
            ps_mv_pred[LEFT] = (ps_mvpred_l - uc_temp);
204
2.16M
            pu0_scale[LEFT] = u1_is_cur_mb_fld - u1_is_left_mb_fld;
205
2.16M
        }
206
2.30M
    }
207
208
    /* Check if the top subMB is available */
209
2.48M
    if((uc_sub_mb_y > 0) || ((u1_is_cur_mb_top | u1_is_cur_mb_fld) == 0))
210
1.27M
    {
211
1.27M
        u2_b_in = 1;
212
1.27M
        ps_mv_pred[TOP] = ps_mv_nmb - 4;
213
1.27M
    }
214
1.20M
    else
215
1.20M
    {
216
1.20M
        u2_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity & TOP_MB_AVAILABLE_MASK);
217
1.20M
        if(u2_b_in)
218
1.15M
        {
219
            /* CHANGED CODE */
220
221
1.15M
            if(u1_is_top_mb_fld && u1_is_cur_mb_fld)
222
98.1k
                ps_mvpred_tmp = ps_mv_ntop;
223
1.05M
            else
224
1.05M
            {
225
1.05M
                ps_mvpred_tmp = ps_mv_ntop;
226
1.05M
                if(u1_is_cur_mb_top)
227
1.04M
                    ps_mvpred_tmp += 16;
228
1.05M
            }
229
230
1.15M
            ps_mv_pred[TOP] = ps_mvpred_tmp;
231
1.15M
            pu0_scale[TOP] = u1_is_cur_mb_fld - u1_is_top_mb_fld;
232
1.15M
        }
233
1.20M
    }
234
235
    /* Check if the top right subMb is available. The top right subMb is
236
     defined as the top right subMb at the top right corner of the MB
237
     partition. The top right subMb index starting from the top left
238
     corner of the MB partition is given by
239
     TopRightSubMbIndx = TopLeftSubMbIndx + (WidthOfMbPartition - 6) / 2
240
     */
241
2.48M
    u2_c_in = CHECKBIT(ps_cur_mb_info->u2_top_right_avail_mask,
242
2.48M
                        (u1_sub_mb_num + uc_mb_part_width - 1));
243
2.48M
    if(u2_c_in)
244
1.16M
    {
245
1.16M
        ps_mv_pred[TOP_R] = ps_mv_pred[TOP] + uc_mb_part_width;
246
1.16M
        pu0_scale[TOP_R] = pu0_scale[TOP];
247
1.16M
        if((uc_sub_mb_y == 0) && ((u1_sub_mb_x + uc_mb_part_width) > 3))
248
1.02M
        {
249
1.02M
            UWORD8 uc_isTopRtMbFld;
250
1.02M
            uc_isTopRtMbFld = ps_cur_mb_info->ps_top_right_mb->u1_mb_fld;
251
            /* CHANGED CODE */
252
1.02M
            ps_mvpred_tmp = ps_mv_ntop + uc_mb_part_width + 12;
253
1.02M
            ps_mvpred_tmp += (u1_is_cur_mb_top) ? 16 : 0;
254
1.02M
            ps_mvpred_tmp += (u1_is_cur_mb_fld && u1_is_cur_mb_top && uc_isTopRtMbFld) ?
255
1.00M
                            0 : 16;
256
1.02M
            ps_mv_pred[TOP_R] = ps_mvpred_tmp;
257
1.02M
            pu0_scale[TOP_R] = u1_is_cur_mb_fld - uc_isTopRtMbFld;
258
1.02M
        }
259
1.16M
    }
260
1.31M
    else
261
1.31M
    {
262
1.31M
        u2_d_in = CHECKBIT(ps_cur_mb_info->u2_top_left_avail_mask, u1_sub_mb_num);
263
264
        /* Check if the the top left subMB is available */
265
1.31M
        if(u2_d_in)
266
1.19M
        {
267
1.19M
            UWORD8 uc_isTopLtMbFld;
268
269
1.19M
            ps_mv_pred[TOP_R] = ps_mv_pred[TOP] - 1;
270
1.19M
            pu0_scale[TOP_R] = pu0_scale[TOP];
271
272
1.19M
            if(u1_sub_mb_x == 0)
273
1.09M
            {
274
1.09M
                if((uc_sub_mb_y > 0) || ((u1_is_cur_mb_top | u1_is_cur_mb_fld) == 0))
275
1.03M
                {
276
1.03M
                    uc_isTopLtMbFld = u1_is_left_mb_fld;
277
1.03M
                    ps_mvpred_tmp = ps_mv_pred[LEFT] - 4;
278
279
1.03M
                    if((u1_is_cur_mb_fld == 0) && uc_isTopLtMbFld)
280
9.84k
                    {
281
9.84k
                        ps_mvpred_tmp = ps_mv_pred[LEFT] + 16;
282
9.84k
                        ps_mvpred_tmp -= (uc_sub_mb_y & 1) ? 0 : 4;
283
9.84k
                    }
284
1.03M
                }
285
62.8k
                else
286
62.8k
                {
287
62.8k
                    UWORD32 u4_cond = ps_dec->u4_num_pmbair;
288
62.8k
                    uc_isTopLtMbFld = ps_cur_mb_info->u1_topleft_mb_fld;
289
290
                    /* CHANGED CODE */
291
62.8k
                    ps_mvpred_tmp = ps_mv_ntop - 29;
292
62.8k
                    ps_mvpred_tmp += (u1_is_cur_mb_top) ? 16 : 0;
293
62.8k
                    if(u1_is_cur_mb_fld && u1_is_cur_mb_top)
294
1.77k
                        ps_mvpred_tmp -= (uc_isTopLtMbFld) ? 16 : 0;
295
62.8k
                }
296
1.09M
                ps_mv_pred[TOP_R] = ps_mvpred_tmp;
297
1.09M
                pu0_scale[TOP_R] = u1_is_cur_mb_fld - uc_isTopLtMbFld;
298
1.09M
            }
299
1.19M
        }
300
122k
        else if(u2_b_in == 0)
301
53.4k
        {
302
            /* If all the subMBs B, C, D are all out of the frame then their MV
303
             and their reference picture is equal to that of A */
304
53.4k
            ps_mv_pred[TOP] = ps_mv_pred[LEFT];
305
53.4k
            ps_mv_pred[TOP_R] = ps_mv_pred[LEFT];
306
53.4k
            pu0_scale[TOP] = pu0_scale[LEFT];
307
53.4k
            pu0_scale[TOP_R] = pu0_scale[LEFT];
308
53.4k
        }
309
1.31M
    }
310
2.48M
}
311
312
/*!
313
 **************************************************************************
314
 * \if ih264d_non_mbaff_mv_pred name : Name \endif
315
 *
316
 * \brief
317
 *    The routine calculates the motion vector predictor for a given block,
318
 *    given the candidate MV predictors.
319
 *
320
 * \param ps_mv_pred: Candidate predictors for the current block
321
 * \param ps_currMv: Pointer to the left top edge of the current block in
322
 *     the MV bank
323
 *
324
 * \return
325
 *    _mvPred: The x & y components of the MV predictor.
326
 *
327
 * \note
328
 *    The code implements the logic as described in sec 8.4.1.2.1. Given
329
 *    the candidate predictors and the pointer to the top left edge of the
330
 *    block in the MV bank.
331
 *
332
 **************************************************************************
333
 */
334
#if(!MVPRED_NONMBAFF)
335
void ih264d_non_mbaff_mv_pred(mv_pred_t **ps_mv_pred,
336
                              UWORD8 u1_sub_mb_num,
337
                              mv_pred_t *ps_mv_nmb,
338
                              mv_pred_t *ps_mv_ntop,
339
                              dec_struct_t *ps_dec,
340
                              UWORD8 uc_mb_part_width,
341
                              dec_mb_info_t *ps_cur_mb_info)
342
7.09M
{
343
7.09M
    UWORD16 u2_b_in = 0, u2_c_in = 0, u2_d_in = 0;
344
7.09M
    UWORD8 u1_sub_mb_x = (u1_sub_mb_num & 3), uc_sub_mb_y = (u1_sub_mb_num >> 2);
345
346
    /* Checking in the subMB exists, calculating their motion vectors to be
347
     used as predictors and the reference frames of those subMBs */
348
349
7.09M
    ps_mv_pred[LEFT] = &ps_dec->s_default_mv_pred;
350
7.09M
    ps_mv_pred[TOP] = &(ps_dec->s_default_mv_pred);
351
7.09M
    ps_mv_pred[TOP_R] = &(ps_dec->s_default_mv_pred);
352
    /* Check if the left subMb is available */
353
354
7.09M
    if(u1_sub_mb_x)
355
46.0k
    {
356
46.0k
        ps_mv_pred[LEFT] = (ps_mv_nmb - 1);
357
46.0k
    }
358
7.05M
    else
359
7.05M
    {
360
7.05M
        if(ps_cur_mb_info->u1_mb_ngbr_availablity & LEFT_MB_AVAILABLE_MASK)
361
6.92M
        {
362
6.92M
            ps_mv_pred[LEFT] = (ps_mv_nmb - 13);
363
6.92M
        }
364
7.05M
    }
365
366
    /* Check if the top subMB is available */
367
7.09M
    if(uc_sub_mb_y)
368
25.2k
    {
369
25.2k
        u2_b_in = 1;
370
25.2k
        ps_mv_ntop = ps_mv_nmb - 4;
371
25.2k
        ps_mv_pred[TOP] = ps_mv_ntop;
372
373
25.2k
    }
374
7.07M
    else
375
7.07M
    {
376
7.07M
        u2_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity & TOP_MB_AVAILABLE_MASK);
377
7.07M
        if(u2_b_in)
378
6.83M
        {
379
6.83M
            ps_mv_pred[TOP] = ps_mv_ntop;
380
6.83M
        }
381
7.07M
    }
382
383
    /* Check if the top right subMb is available. The top right subMb is
384
     defined as the top right subMb at the top right corner of the MB
385
     partition. The top right subMb index starting from the top left
386
     corner of the MB partition is given by
387
     TopRightSubMbIndx = TopLeftSubMbIndx + (WidthOfMbPartition - 6) / 2
388
     */
389
7.09M
    u2_c_in = CHECKBIT(ps_cur_mb_info->u2_top_right_avail_mask,
390
7.09M
                        (u1_sub_mb_num + uc_mb_part_width - 1));
391
7.09M
    if(u2_c_in)
392
6.73M
    {
393
6.73M
        ps_mv_pred[TOP_R] = (ps_mv_ntop + uc_mb_part_width);
394
395
6.73M
        if(uc_sub_mb_y == 0)
396
6.73M
        {
397
            /* CHANGED CODE */
398
6.73M
            if((u1_sub_mb_x + uc_mb_part_width) > 3)
399
6.69M
                ps_mv_pred[TOP_R] += 12;
400
6.73M
        }
401
6.73M
    }
402
362k
    else
403
362k
    {
404
362k
        u2_d_in = CHECKBIT(ps_cur_mb_info->u2_top_left_avail_mask, u1_sub_mb_num);
405
        /* Check if the the top left subMB is available */
406
362k
        if(u2_d_in)
407
112k
        {
408
            /* CHANGED CODE */
409
112k
            ps_mv_pred[TOP_R] = (ps_mv_ntop - 1);
410
112k
            if(u1_sub_mb_x == 0)
411
105k
            {
412
105k
                if(uc_sub_mb_y)
413
9.58k
                {
414
9.58k
                    ps_mv_pred[TOP_R] = (ps_mv_nmb - 17);
415
9.58k
                }
416
95.4k
                else
417
95.4k
                {
418
                    /* CHANGED CODE */
419
95.4k
                    ps_mv_pred[TOP_R] -= 12;
420
95.4k
                }
421
105k
            }
422
112k
        }
423
249k
        else if(u2_b_in == 0)
424
235k
        {
425
            /* If all the subMBs B, C, D are all out of the frame then their MV
426
             and their reference picture is equal to that of A */
427
235k
            ps_mv_pred[TOP] = ps_mv_pred[LEFT];
428
235k
            ps_mv_pred[TOP_R] = ps_mv_pred[LEFT];
429
235k
        }
430
362k
    }
431
7.09M
}
432
#endif
433
434
/*****************************************************************************/
435
/*                                                                           */
436
/*  Function Name : ih264d_mvpred_nonmbaffB                                         */
437
/*                                                                           */
438
/*  Description   : This function calculates the motion vector predictor,    */
439
/*                  for B-Slices                                             */
440
/*  Inputs        : <What inputs does the function take?>                    */
441
/*  Globals       : None                                                     */
442
/*  Processing    : The neighbours A(Left),B(Top),C(TopRight) are calculated */
443
/*                  and based on the type of Mb the prediction is            */
444
/*                  appropriately done                                       */
445
/*  Outputs       : populates ps_mv_final_pred structure                       */
446
/*  Returns       : u1_direct_zero_pred_flag which is used only in              */
447
/*                    decodeSpatialdirect()                                  */
448
/*                                                                           */
449
/*  Issues        : <List any issues or problems with this function>         */
450
/*                                                                           */
451
/*  Revision History:                                                        */
452
/*                                                                           */
453
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
454
/*         03 05 2005   TA              First Draft                          */
455
/*                                                                           */
456
/*****************************************************************************/
457
#if(!MVPRED_NONMBAFF)
458
UWORD8 ih264d_mvpred_nonmbaffB(dec_struct_t *ps_dec,
459
                               dec_mb_info_t *ps_cur_mb_info,
460
                               mv_pred_t *ps_mv_nmb,
461
                               mv_pred_t *ps_mv_ntop,
462
                               mv_pred_t *ps_mv_final_pred,
463
                               UWORD8 u1_sub_mb_num,
464
                               UWORD8 uc_mb_part_width,
465
                               UWORD8 u1_lx_start,
466
                               UWORD8 u1_lxend,
467
                               UWORD8 u1_mb_mc_mode)
468
4.58M
{
469
4.58M
    UWORD8 u1_a_in, u1_b_in, uc_temp1, uc_temp2, uc_temp3;
470
4.58M
    mv_pred_t *ps_mv_pred[3];
471
4.58M
    UWORD8 uc_B2, uc_lx, u1_ref_idx;
472
4.58M
    UWORD8 u1_direct_zero_pred_flag = 0;
473
474
4.58M
    ih264d_non_mbaff_mv_pred(ps_mv_pred, u1_sub_mb_num, ps_mv_nmb, ps_mv_ntop,
475
4.58M
                             ps_dec, uc_mb_part_width, ps_cur_mb_info);
476
477
9.17M
    for(uc_lx = u1_lx_start; uc_lx < u1_lxend; uc_lx++)
478
4.58M
    {
479
4.58M
        u1_ref_idx = ps_mv_final_pred->i1_ref_frame[uc_lx];
480
4.58M
        uc_B2 = (uc_lx << 1);
481
4.58M
        switch(u1_mb_mc_mode)
482
4.58M
        {
483
7.48k
            case PRED_16x8:
484
                /* Directional prediction for a 16x8 MB partition */
485
7.48k
                if(u1_sub_mb_num == 0)
486
3.27k
                {
487
                    /* Calculating the MV pred for the top 16x8 block */
488
3.27k
                    if(ps_mv_pred[TOP]->i1_ref_frame[uc_lx] == u1_ref_idx)
489
1.82k
                    {
490
                        /* If the reference frame used by the top subMB is same as the
491
                         reference frame used by the current block then MV predictor to
492
                         be used for the current block is same as the MV of the top
493
                         subMB */
494
1.82k
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
495
1.82k
                                        ps_mv_pred[TOP]->i2_mv[uc_B2 + 0];
496
1.82k
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
497
1.82k
                                        ps_mv_pred[TOP]->i2_mv[uc_B2 + 1];
498
1.82k
                    }
499
1.45k
                    else
500
1.45k
                    {
501
                        /* The MV predictor is calculated according to the process
502
                         defined in 8.4.1.2.1 */
503
1.45k
                        ih264d_get_motion_vector_predictor(
504
1.45k
                                        ps_mv_final_pred,
505
1.45k
                                        ps_mv_pred,
506
1.45k
                                        u1_ref_idx,
507
1.45k
                                        uc_lx,
508
1.45k
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
509
1.45k
                    }
510
3.27k
                }
511
4.20k
                else
512
4.20k
                {
513
4.20k
                    if(ps_mv_pred[LEFT]->i1_ref_frame[uc_lx] == u1_ref_idx)
514
2.14k
                    {
515
                        /* If the reference frame used by the left subMB is same as the
516
                         reference frame used by the current block then MV predictor to
517
                         be used for the current block is same as the MV of the left
518
                         subMB */
519
2.14k
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
520
2.14k
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 0];
521
2.14k
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
522
2.14k
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 1];
523
2.14k
                    }
524
2.05k
                    else
525
2.05k
                    {
526
                        /* The MV predictor is calculated according to the process
527
                         defined in 8.4.1.2.1 */
528
2.05k
                        ih264d_get_motion_vector_predictor(
529
2.05k
                                        ps_mv_final_pred,
530
2.05k
                                        ps_mv_pred,
531
2.05k
                                        u1_ref_idx,
532
2.05k
                                        uc_lx,
533
2.05k
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
534
2.05k
                    }
535
4.20k
                }
536
7.48k
                break;
537
7.75k
            case PRED_8x16:
538
                /* Directional prediction for a 8x16 MB partition */
539
7.75k
                if(u1_sub_mb_num == 0)
540
3.82k
                {
541
3.82k
                    if(ps_mv_pred[LEFT]->i1_ref_frame[uc_lx] == u1_ref_idx)
542
1.07k
                    {
543
                        /* If the reference frame used by the left subMB is same as the
544
                         reference frame used by the current block then MV predictor to
545
                         be used for the current block is same as the MV of the left
546
                         subMB */
547
1.07k
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
548
1.07k
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 0];
549
1.07k
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
550
1.07k
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 1];
551
1.07k
                    }
552
2.74k
                    else
553
2.74k
                    {
554
                        /* The MV predictor is calculated according to the process
555
                         defined in 8.4.1.2.1 */
556
2.74k
                        ih264d_get_motion_vector_predictor(
557
2.74k
                                        ps_mv_final_pred,
558
2.74k
                                        ps_mv_pred,
559
2.74k
                                        u1_ref_idx,
560
2.74k
                                        uc_lx,
561
2.74k
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
562
2.74k
                    }
563
3.82k
                }
564
3.92k
                else
565
3.92k
                {
566
3.92k
                    if(ps_mv_pred[TOP_R]->i1_ref_frame[uc_lx] == u1_ref_idx)
567
2.23k
                    {
568
                        /* If the reference frame used by the top right subMB is same as
569
                         the reference frame used by the current block then MV
570
                         predictor to be used for the current block is same as the MV
571
                         of the left subMB */
572
2.23k
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
573
2.23k
                                        ps_mv_pred[TOP_R]->i2_mv[uc_B2 + 0];
574
2.23k
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
575
2.23k
                                        ps_mv_pred[TOP_R]->i2_mv[uc_B2 + 1];
576
2.23k
                    }
577
1.69k
                    else
578
1.69k
                    {
579
                        /* The MV predictor is calculated according to the process
580
                         defined in 8.4.1.2.1 */
581
1.69k
                        ih264d_get_motion_vector_predictor(
582
1.69k
                                        ps_mv_final_pred,
583
1.69k
                                        ps_mv_pred,
584
1.69k
                                        u1_ref_idx,
585
1.69k
                                        uc_lx,
586
1.69k
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
587
1.69k
                    }
588
3.92k
                }
589
7.75k
                break;
590
479k
            case B_DIRECT_SPATIAL:
591
                /* Case when the MB has been skipped */
592
                /* If either of left or the top subMB is not present
593
                 OR
594
                 If both the MV components of either the left or the top subMB are
595
                 zero and their reference frame pointer pointing to 0
596
                 then MV for the skipped MB is zero
597
                 else the Median of the mv_pred_t is used */
598
479k
                uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[0];
599
479k
                uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[0];
600
479k
                uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[0];
601
602
479k
                ps_mv_final_pred->i1_ref_frame[0] = MIN(uc_temp1,
603
479k
                                                      MIN(uc_temp2, uc_temp3));
604
605
479k
                uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[1];
606
479k
                uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[1];
607
479k
                uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[1];
608
609
479k
                ps_mv_final_pred->i1_ref_frame[1] = MIN(uc_temp1,
610
479k
                                                      MIN(uc_temp2, uc_temp3));
611
612
479k
                if((ps_mv_final_pred->i1_ref_frame[0] < 0)
613
479k
                                && (ps_mv_final_pred->i1_ref_frame[1] < 0))
614
1.41k
                {
615
1.41k
                    u1_direct_zero_pred_flag = 1;
616
1.41k
                    ps_mv_final_pred->i1_ref_frame[0] = 0;
617
1.41k
                    ps_mv_final_pred->i1_ref_frame[1] = 0;
618
1.41k
                }
619
479k
                ih264d_get_motion_vector_predictor(
620
479k
                                ps_mv_final_pred, ps_mv_pred,
621
479k
                                ps_mv_final_pred->i1_ref_frame[0], 0,
622
479k
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
623
624
479k
                ih264d_get_motion_vector_predictor(
625
479k
                                ps_mv_final_pred, ps_mv_pred,
626
479k
                                ps_mv_final_pred->i1_ref_frame[1], 1,
627
479k
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
628
629
479k
                break;
630
4.05M
            case MB_SKIP:
631
                /* Case when the MB has been skipped */
632
                /* If either of left or the top subMB is not present
633
                 OR
634
                 If both the MV components of either the left or the top subMB are
635
                 zero and their reference frame pointer pointing to 0
636
                 then MV for the skipped MB is zero
637
                 else the Median of the mv_pred_t is used */
638
4.05M
                u1_a_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
639
4.05M
                LEFT_MB_AVAILABLE_MASK);
640
4.05M
                u1_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
641
4.05M
                TOP_MB_AVAILABLE_MASK);
642
4.05M
                if(((u1_a_in * u1_b_in) == 0)
643
4.05M
                                || ((ps_mv_pred[LEFT]->i2_mv[0]
644
3.94M
                                                | ps_mv_pred[LEFT]->i2_mv[1]
645
3.94M
                                                | ps_mv_pred[LEFT]->i1_ref_frame[0])
646
3.94M
                                                == 0)
647
4.05M
                                || ((ps_mv_pred[TOP]->i2_mv[0]
648
0
                                                | ps_mv_pred[TOP]->i2_mv[1]
649
0
                                                | ps_mv_pred[TOP]->i1_ref_frame[0])
650
0
                                                == 0))
651
4.05M
                {
652
4.05M
                    ps_mv_final_pred->i2_mv[0] = 0;
653
4.05M
                    ps_mv_final_pred->i2_mv[1] = 0;
654
4.05M
                    break;
655
4.05M
                }
656
                /* If the condition above is not true calculate the MV predictor
657
                 according to the process defined in sec 8.4.1.2.1 */
658
38.0k
            default:
659
38.0k
                ih264d_get_motion_vector_predictor(
660
38.0k
                                ps_mv_final_pred, ps_mv_pred, u1_ref_idx, uc_lx,
661
38.0k
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
662
38.0k
                break;
663
4.58M
        }
664
4.58M
    }
665
4.58M
    return (u1_direct_zero_pred_flag);
666
4.58M
}
667
#endif
668
669
/*****************************************************************************/
670
/*                                                                           */
671
/*  Function Name : ih264d_mvpred_nonmbaff                                          */
672
/*                                                                           */
673
/*  Description   : This function calculates the motion vector predictor,    */
674
/*                  for all the slice types other than B_SLICE               */
675
/*  Inputs        : <What inputs does the function take?>                    */
676
/*  Globals       : None                                                     */
677
/*  Processing    : The neighbours A(Left),B(Top),C(TopRight) are calculated */
678
/*                  and based on the type of Mb the prediction is            */
679
/*                  appropriately done                                       */
680
/*  Outputs       : populates ps_mv_final_pred structure                       */
681
/*  Returns       : u1_direct_zero_pred_flag which is used only in              */
682
/*                    decodeSpatialdirect()                                  */
683
/*                                                                           */
684
/*  Issues        : <List any issues or problems with this function>         */
685
/*                                                                           */
686
/*  Revision History:                                                        */
687
/*                                                                           */
688
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
689
/*         03 05 2005   TA              First Draft                          */
690
/*                                                                           */
691
/*****************************************************************************/
692
#if(!MVPRED_NONMBAFF)
693
UWORD8 ih264d_mvpred_nonmbaff(dec_struct_t *ps_dec,
694
                              dec_mb_info_t *ps_cur_mb_info,
695
                              mv_pred_t *ps_mv_nmb,
696
                              mv_pred_t *ps_mv_ntop,
697
                              mv_pred_t *ps_mv_final_pred,
698
                              UWORD8 u1_sub_mb_num,
699
                              UWORD8 uc_mb_part_width,
700
                              UWORD8 u1_lx_start,
701
                              UWORD8 u1_lxend,
702
                              UWORD8 u1_mb_mc_mode)
703
2.51M
{
704
2.51M
    UWORD8 u1_a_in, u1_b_in, uc_temp1, uc_temp2, uc_temp3;
705
2.51M
    mv_pred_t *ps_mv_pred[3];
706
2.51M
    UWORD8 u1_ref_idx;
707
2.51M
    UWORD8 u1_direct_zero_pred_flag = 0;
708
2.51M
    UNUSED(u1_lx_start);
709
2.51M
    UNUSED(u1_lxend);
710
2.51M
    ih264d_non_mbaff_mv_pred(ps_mv_pred, u1_sub_mb_num, ps_mv_nmb, ps_mv_ntop,
711
2.51M
                             ps_dec, uc_mb_part_width, ps_cur_mb_info);
712
713
2.51M
    u1_ref_idx = ps_mv_final_pred->i1_ref_frame[0];
714
715
2.51M
    switch(u1_mb_mc_mode)
716
2.51M
    {
717
22.8k
        case PRED_16x8:
718
            /* Directional prediction for a 16x8 MB partition */
719
22.8k
            if(u1_sub_mb_num == 0)
720
11.4k
            {
721
                /* Calculating the MV pred for the top 16x8 block */
722
11.4k
                if(ps_mv_pred[TOP]->i1_ref_frame[0] == u1_ref_idx)
723
6.40k
                {
724
                    /* If the reference frame used by the top subMB is same as the
725
                     reference frame used by the current block then MV predictor to
726
                     be used for the current block is same as the MV of the top
727
                     subMB */
728
729
6.40k
                    ps_mv_final_pred->i2_mv[0] = ps_mv_pred[TOP]->i2_mv[0];
730
6.40k
                    ps_mv_final_pred->i2_mv[1] = ps_mv_pred[TOP]->i2_mv[1];
731
6.40k
                }
732
5.01k
                else
733
5.01k
                {
734
                    /* The MV predictor is calculated according to the process
735
                     defined in 8.4.1.2.1 */
736
5.01k
                    ih264d_get_motion_vector_predictor(
737
5.01k
                                    ps_mv_final_pred,
738
5.01k
                                    ps_mv_pred,
739
5.01k
                                    u1_ref_idx,
740
5.01k
                                    0,
741
5.01k
                                    (const UWORD8 *)gau1_ih264d_mv_pred_condition);
742
5.01k
                }
743
11.4k
            }
744
11.4k
            else
745
11.4k
            {
746
11.4k
                if(ps_mv_pred[LEFT]->i1_ref_frame[0] == u1_ref_idx)
747
2.33k
                {
748
                    /* If the reference frame used by the left subMB is same as the
749
                     reference frame used by the current block then MV predictor to
750
                     be used for the current block is same as the MV of the left
751
                     subMB */
752
753
2.33k
                    ps_mv_final_pred->i2_mv[0] = ps_mv_pred[LEFT]->i2_mv[0];
754
2.33k
                    ps_mv_final_pred->i2_mv[1] = ps_mv_pred[LEFT]->i2_mv[1];
755
2.33k
                }
756
9.09k
                else
757
9.09k
                {
758
                    /* The MV predictor is calculated according to the process
759
                     defined in 8.4.1.2.1 */
760
9.09k
                    ih264d_get_motion_vector_predictor(
761
9.09k
                                    ps_mv_final_pred,
762
9.09k
                                    ps_mv_pred,
763
9.09k
                                    u1_ref_idx,
764
9.09k
                                    0,
765
9.09k
                                    (const UWORD8 *)gau1_ih264d_mv_pred_condition);
766
9.09k
                }
767
11.4k
            }
768
22.8k
            break;
769
62.9k
        case PRED_8x16:
770
            /* Directional prediction for a 8x16 MB partition */
771
62.9k
            if(u1_sub_mb_num == 0)
772
31.4k
            {
773
31.4k
                if(ps_mv_pred[LEFT]->i1_ref_frame[0] == u1_ref_idx)
774
30.3k
                {
775
                    /* If the reference frame used by the left subMB is same as the
776
                     reference frame used by the current block then MV predictor to
777
                     be used for the current block is same as the MV of the left
778
                     subMB */
779
780
30.3k
                    ps_mv_final_pred->i2_mv[0] = ps_mv_pred[LEFT]->i2_mv[0];
781
30.3k
                    ps_mv_final_pred->i2_mv[1] = ps_mv_pred[LEFT]->i2_mv[1];
782
30.3k
                }
783
1.14k
                else
784
1.14k
                {
785
                    /* The MV predictor is calculated according to the process
786
                     defined in 8.4.1.2.1 */
787
1.14k
                    ih264d_get_motion_vector_predictor(
788
1.14k
                                    ps_mv_final_pred,
789
1.14k
                                    ps_mv_pred,
790
1.14k
                                    u1_ref_idx,
791
1.14k
                                    0,
792
1.14k
                                    (const UWORD8 *)gau1_ih264d_mv_pred_condition);
793
1.14k
                }
794
31.4k
            }
795
31.4k
            else
796
31.4k
            {
797
31.4k
                if(ps_mv_pred[TOP_R]->i1_ref_frame[0] == u1_ref_idx)
798
30.2k
                {
799
                    /* If the reference frame used by the top right subMB is same as
800
                     the reference frame used by the current block then MV
801
                     predictor to be used for the current block is same as the MV
802
                     of the left subMB */
803
804
30.2k
                    ps_mv_final_pred->i2_mv[0] = ps_mv_pred[TOP_R]->i2_mv[0];
805
30.2k
                    ps_mv_final_pred->i2_mv[1] = ps_mv_pred[TOP_R]->i2_mv[1];
806
30.2k
                }
807
1.18k
                else
808
1.18k
                {
809
                    /* The MV predictor is calculated according to the process
810
                     defined in 8.4.1.2.1 */
811
1.18k
                    ih264d_get_motion_vector_predictor(
812
1.18k
                                    ps_mv_final_pred,
813
1.18k
                                    ps_mv_pred,
814
1.18k
                                    u1_ref_idx,
815
1.18k
                                    0,
816
1.18k
                                    (const UWORD8 *)gau1_ih264d_mv_pred_condition);
817
1.18k
                }
818
31.4k
            }
819
62.9k
            break;
820
0
        case B_DIRECT_SPATIAL:
821
            /* Case when the MB has been skipped */
822
            /* If either of left or the top subMB is not present
823
             OR
824
             If both the MV components of either the left or the top subMB are
825
             zero and their reference frame pointer pointing to 0
826
             then MV for the skipped MB is zero
827
             else the Median of the mv_pred_t is used */
828
0
            uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[0];
829
0
            uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[0];
830
0
            uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[0];
831
832
0
            ps_mv_final_pred->i1_ref_frame[0] = MIN(uc_temp1,
833
0
                                                  MIN(uc_temp2, uc_temp3));
834
835
0
            uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[1];
836
0
            uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[1];
837
0
            uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[1];
838
839
0
            ps_mv_final_pred->i1_ref_frame[1] = MIN(uc_temp1,
840
0
                                                  MIN(uc_temp2, uc_temp3));
841
842
0
            if((ps_mv_final_pred->i1_ref_frame[0] < 0)
843
0
                            && (ps_mv_final_pred->i1_ref_frame[1] < 0))
844
0
            {
845
0
                u1_direct_zero_pred_flag = 1;
846
0
                ps_mv_final_pred->i1_ref_frame[0] = 0;
847
0
                ps_mv_final_pred->i1_ref_frame[1] = 0;
848
0
            }
849
0
            ih264d_get_motion_vector_predictor(
850
0
                            ps_mv_final_pred, ps_mv_pred,
851
0
                            ps_mv_final_pred->i1_ref_frame[0], 0,
852
0
                            (const UWORD8 *)gau1_ih264d_mv_pred_condition);
853
854
0
            ih264d_get_motion_vector_predictor(
855
0
                            ps_mv_final_pred, ps_mv_pred,
856
0
                            ps_mv_final_pred->i1_ref_frame[1], 1,
857
0
                            (const UWORD8 *)gau1_ih264d_mv_pred_condition);
858
859
0
            break;
860
2.38M
        case MB_SKIP:
861
            /* Case when the MB has been skipped */
862
            /* If either of left or the top subMB is not present
863
             OR
864
             If both the MV components of either the left or the top subMB are
865
             zero and their reference frame pointer pointing to 0
866
             then MV for the skipped MB is zero
867
             else the Median of the mv_pred_t is used */
868
2.38M
            u1_a_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
869
2.38M
            LEFT_MB_AVAILABLE_MASK);
870
2.38M
            u1_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
871
2.38M
            TOP_MB_AVAILABLE_MASK);
872
2.38M
            if(((u1_a_in * u1_b_in) == 0)
873
2.38M
                            || ((ps_mv_pred[LEFT]->i2_mv[0]
874
2.18M
                                            | ps_mv_pred[LEFT]->i2_mv[1]
875
2.18M
                                            | ps_mv_pred[LEFT]->i1_ref_frame[0])
876
2.18M
                                            == 0)
877
2.38M
                            || ((ps_mv_pred[TOP]->i2_mv[0]
878
24.3k
                                            | ps_mv_pred[TOP]->i2_mv[1]
879
24.3k
                                            | ps_mv_pred[TOP]->i1_ref_frame[0])
880
24.3k
                                            == 0))
881
2.36M
            {
882
883
2.36M
                ps_mv_final_pred->i2_mv[0] = 0;
884
2.36M
                ps_mv_final_pred->i2_mv[1] = 0;
885
2.36M
                break;
886
2.36M
            }
887
            /* If the condition above is not true calculate the MV predictor
888
             according to the process defined in sec 8.4.1.2.1 */
889
56.7k
        default:
890
56.7k
            ih264d_get_motion_vector_predictor(
891
56.7k
                            ps_mv_final_pred, ps_mv_pred, u1_ref_idx, 0,
892
56.7k
                            (const UWORD8 *)gau1_ih264d_mv_pred_condition);
893
56.7k
            break;
894
2.51M
    }
895
896
2.51M
    return (u1_direct_zero_pred_flag);
897
2.51M
}
898
#endif
899
900
/*****************************************************************************/
901
/*                                                                           */
902
/*  Function Name : ih264d_mvpred_mbaff                                             */
903
/*                                                                           */
904
/*  Description   : This function calculates the motion vector predictor,    */
905
/*  Inputs        : <What inputs does the function take?>                    */
906
/*  Globals       : None                                                     */
907
/*  Processing    : The neighbours A(Left),B(Top),C(TopRight) are calculated */
908
/*                  and based on the type of Mb the prediction is            */
909
/*                  appropriately done                                       */
910
/*  Outputs       : populates ps_mv_final_pred structure                       */
911
/*  Returns       : u1_direct_zero_pred_flag which is used only in              */
912
/*                    decodeSpatialdirect()                                  */
913
/*                                                                           */
914
/*  Issues        : <List any issues or problems with this function>         */
915
/*                                                                           */
916
/*  Revision History:                                                        */
917
/*                                                                           */
918
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
919
/*         03 05 2005   TA              First Draft                          */
920
/*                                                                           */
921
/*****************************************************************************/
922
923
UWORD8 ih264d_mvpred_mbaff(dec_struct_t *ps_dec,
924
                           dec_mb_info_t *ps_cur_mb_info,
925
                           mv_pred_t *ps_mv_nmb,
926
                           mv_pred_t *ps_mv_ntop,
927
                           mv_pred_t *ps_mv_final_pred,
928
                           UWORD8 u1_sub_mb_num,
929
                           UWORD8 uc_mb_part_width,
930
                           UWORD8 u1_lx_start,
931
                           UWORD8 u1_lxend,
932
                           UWORD8 u1_mb_mc_mode)
933
2.48M
{
934
2.48M
    UWORD8 u1_a_in, u1_b_in, uc_temp1, uc_temp2, uc_temp3;
935
2.48M
    mv_pred_t *ps_mv_pred[3], s_mvPred[3];
936
2.48M
    UWORD8 uc_B2, pu0_scale[3], i, uc_lx, u1_ref_idx;
937
2.48M
    UWORD8 u1_direct_zero_pred_flag = 0;
938
939
2.48M
    pu0_scale[0] = pu0_scale[1] = pu0_scale[2] = 0;
940
2.48M
    ih264d_mbaff_mv_pred(ps_mv_pred, u1_sub_mb_num, ps_mv_nmb, ps_mv_ntop, ps_dec,
941
2.48M
                         uc_mb_part_width, ps_cur_mb_info, pu0_scale);
942
9.93M
    for(i = 0; i < 3; i++)
943
7.44M
    {
944
7.44M
        if(pu0_scale[i] != 0)
945
151k
        {
946
151k
            memcpy(&s_mvPred[i], ps_mv_pred[i], sizeof(mv_pred_t));
947
151k
            if(pu0_scale[i] == 1)
948
95.8k
            {
949
95.8k
                s_mvPred[i].i1_ref_frame[0] = s_mvPred[i].i1_ref_frame[0] << 1;
950
95.8k
                s_mvPred[i].i1_ref_frame[1] = s_mvPred[i].i1_ref_frame[1] << 1;
951
95.8k
                s_mvPred[i].i2_mv[1] = SIGN_POW2_DIV(s_mvPred[i].i2_mv[1], 1);
952
95.8k
                s_mvPred[i].i2_mv[3] = SIGN_POW2_DIV(s_mvPred[i].i2_mv[3], 1);
953
95.8k
            }
954
55.2k
            else
955
55.2k
            {
956
55.2k
                s_mvPred[i].i1_ref_frame[0] = s_mvPred[i].i1_ref_frame[0] >> 1;
957
55.2k
                s_mvPred[i].i1_ref_frame[1] = s_mvPred[i].i1_ref_frame[1] >> 1;
958
55.2k
                s_mvPred[i].i2_mv[1] = s_mvPred[i].i2_mv[1] << 1;
959
55.2k
                s_mvPred[i].i2_mv[3] = s_mvPred[i].i2_mv[3] << 1;
960
55.2k
            }
961
151k
            ps_mv_pred[i] = &s_mvPred[i];
962
151k
        }
963
7.44M
    }
964
965
4.96M
    for(uc_lx = u1_lx_start; uc_lx < u1_lxend; uc_lx++)
966
2.48M
    {
967
2.48M
        u1_ref_idx = ps_mv_final_pred->i1_ref_frame[uc_lx];
968
2.48M
        uc_B2 = (uc_lx << 1);
969
2.48M
        switch(u1_mb_mc_mode)
970
2.48M
        {
971
48.8k
            case PRED_16x8:
972
                /* Directional prediction for a 16x8 MB partition */
973
48.8k
                if(u1_sub_mb_num == 0)
974
24.4k
                {
975
                    /* Calculating the MV pred for the top 16x8 block */
976
24.4k
                    if(ps_mv_pred[TOP]->i1_ref_frame[uc_lx] == u1_ref_idx)
977
7.88k
                    {
978
                        /* If the reference frame used by the top subMB is same as the
979
                         reference frame used by the current block then MV predictor to
980
                         be used for the current block is same as the MV of the top
981
                         subMB */
982
7.88k
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
983
7.88k
                                        ps_mv_pred[TOP]->i2_mv[uc_B2 + 0];
984
7.88k
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
985
7.88k
                                        ps_mv_pred[TOP]->i2_mv[uc_B2 + 1];
986
7.88k
                    }
987
16.5k
                    else
988
16.5k
                    {
989
                        /* The MV predictor is calculated according to the process
990
                         defined in 8.4.1.2.1 */
991
16.5k
                        ih264d_get_motion_vector_predictor(
992
16.5k
                                        ps_mv_final_pred,
993
16.5k
                                        ps_mv_pred,
994
16.5k
                                        u1_ref_idx,
995
16.5k
                                        uc_lx,
996
16.5k
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
997
16.5k
                    }
998
24.4k
                }
999
24.4k
                else
1000
24.4k
                {
1001
24.4k
                    if(ps_mv_pred[LEFT]->i1_ref_frame[uc_lx] == u1_ref_idx)
1002
9.39k
                    {
1003
                        /* If the reference frame used by the left subMB is same as the
1004
                         reference frame used by the current block then MV predictor to
1005
                         be used for the current block is same as the MV of the left
1006
                         subMB */
1007
9.39k
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
1008
9.39k
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 0];
1009
9.39k
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
1010
9.39k
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 1];
1011
9.39k
                    }
1012
15.0k
                    else
1013
15.0k
                    {
1014
                        /* The MV predictor is calculated according to the process
1015
                         defined in 8.4.1.2.1 */
1016
15.0k
                        ih264d_get_motion_vector_predictor(
1017
15.0k
                                        ps_mv_final_pred,
1018
15.0k
                                        ps_mv_pred,
1019
15.0k
                                        u1_ref_idx,
1020
15.0k
                                        uc_lx,
1021
15.0k
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1022
15.0k
                    }
1023
24.4k
                }
1024
48.8k
                break;
1025
44.4k
            case PRED_8x16:
1026
                /* Directional prediction for a 8x16 MB partition */
1027
44.4k
                if(u1_sub_mb_num == 0)
1028
22.2k
                {
1029
22.2k
                    if(ps_mv_pred[LEFT]->i1_ref_frame[uc_lx] == u1_ref_idx)
1030
8.69k
                    {
1031
                        /* If the reference frame used by the left subMB is same as the
1032
                         reference frame used by the current block then MV predictor to
1033
                         be used for the current block is same as the MV of the left
1034
                         subMB */
1035
8.69k
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
1036
8.69k
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 0];
1037
8.69k
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
1038
8.69k
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 1];
1039
8.69k
                    }
1040
13.5k
                    else
1041
13.5k
                    {
1042
                        /* The MV predictor is calculated according to the process
1043
                         defined in 8.4.1.2.1 */
1044
13.5k
                        ih264d_get_motion_vector_predictor(
1045
13.5k
                                        ps_mv_final_pred,
1046
13.5k
                                        ps_mv_pred,
1047
13.5k
                                        u1_ref_idx,
1048
13.5k
                                        uc_lx,
1049
13.5k
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1050
13.5k
                    }
1051
22.2k
                }
1052
22.2k
                else
1053
22.2k
                {
1054
22.2k
                    if(ps_mv_pred[TOP_R]->i1_ref_frame[uc_lx] == u1_ref_idx)
1055
9.54k
                    {
1056
                        /* If the reference frame used by the top right subMB is same as
1057
                         the reference frame used by the current block then MV
1058
                         predictor to be used for the current block is same as the MV
1059
                         of the left subMB */
1060
9.54k
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
1061
9.54k
                                        ps_mv_pred[TOP_R]->i2_mv[uc_B2 + 0];
1062
9.54k
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
1063
9.54k
                                        ps_mv_pred[TOP_R]->i2_mv[uc_B2 + 1];
1064
9.54k
                    }
1065
12.6k
                    else
1066
12.6k
                    {
1067
                        /* The MV predictor is calculated according to the process
1068
                         defined in 8.4.1.2.1 */
1069
12.6k
                        ih264d_get_motion_vector_predictor(
1070
12.6k
                                        ps_mv_final_pred,
1071
12.6k
                                        ps_mv_pred,
1072
12.6k
                                        u1_ref_idx,
1073
12.6k
                                        uc_lx,
1074
12.6k
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1075
12.6k
                    }
1076
22.2k
                }
1077
44.4k
                break;
1078
8.73k
            case B_DIRECT_SPATIAL:
1079
                /* Case when the MB has been skipped */
1080
                /* If either of left or the top subMB is not present
1081
                 OR
1082
                 If both the MV components of either the left or the top subMB are
1083
                 zero and their reference frame pointer pointing to 0
1084
                 then MV for the skipped MB is zero
1085
                 else the Median of the mv_pred_t is used */
1086
8.73k
                uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[0];
1087
8.73k
                uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[0];
1088
8.73k
                uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[0];
1089
1090
8.73k
                ps_mv_final_pred->i1_ref_frame[0] = MIN(uc_temp1,
1091
8.73k
                                                      MIN(uc_temp2, uc_temp3));
1092
1093
8.73k
                uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[1];
1094
8.73k
                uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[1];
1095
8.73k
                uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[1];
1096
1097
8.73k
                ps_mv_final_pred->i1_ref_frame[1] = MIN(uc_temp1,
1098
8.73k
                                                      MIN(uc_temp2, uc_temp3));
1099
1100
                /* If the reference indices are negative clip the scaled reference indices to -1 */
1101
                /* i.e invalid reference index */
1102
1103
                /*if(ps_mv_final_pred->i1_ref_frame[0] < 0)
1104
                 ps_mv_final_pred->i1_ref_frame[0] = -1;
1105
1106
                 if(ps_mv_final_pred->i1_ref_frame[1] < 0)
1107
                 ps_mv_final_pred->i1_ref_frame[1] = -1; */
1108
1109
8.73k
                if((ps_mv_final_pred->i1_ref_frame[0] < 0)
1110
8.73k
                                && (ps_mv_final_pred->i1_ref_frame[1] < 0))
1111
148
                {
1112
148
                    u1_direct_zero_pred_flag = 1;
1113
148
                    ps_mv_final_pred->i1_ref_frame[0] = 0;
1114
148
                    ps_mv_final_pred->i1_ref_frame[1] = 0;
1115
148
                }
1116
8.73k
                ih264d_get_motion_vector_predictor(
1117
8.73k
                                ps_mv_final_pred, ps_mv_pred,
1118
8.73k
                                ps_mv_final_pred->i1_ref_frame[0], 0,
1119
8.73k
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1120
1121
8.73k
                ih264d_get_motion_vector_predictor(
1122
8.73k
                                ps_mv_final_pred, ps_mv_pred,
1123
8.73k
                                ps_mv_final_pred->i1_ref_frame[1], 1,
1124
8.73k
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1125
1126
8.73k
                break;
1127
2.06M
            case MB_SKIP:
1128
                /* Case when the MB has been skipped */
1129
                /* If either of left or the top subMB is not present
1130
                 OR
1131
                 If both the MV components of either the left or the top subMB are
1132
                 zero and their reference frame pointer pointing to 0
1133
                 then MV for the skipped MB is zero
1134
                 else the Median of the mv_pred_t is used */
1135
2.06M
                u1_a_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
1136
2.06M
                LEFT_MB_AVAILABLE_MASK);
1137
2.06M
                u1_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
1138
2.06M
                TOP_MB_AVAILABLE_MASK);
1139
2.06M
                if(((u1_a_in * u1_b_in) == 0)
1140
2.06M
                                || ((ps_mv_pred[LEFT]->i2_mv[0]
1141
1.89M
                                                | ps_mv_pred[LEFT]->i2_mv[1]
1142
1.89M
                                                | ps_mv_pred[LEFT]->i1_ref_frame[0])
1143
1.89M
                                                == 0)
1144
2.06M
                                || ((ps_mv_pred[TOP]->i2_mv[0]
1145
18.4k
                                                | ps_mv_pred[TOP]->i2_mv[1]
1146
18.4k
                                                | ps_mv_pred[TOP]->i1_ref_frame[0])
1147
18.4k
                                                == 0))
1148
2.04M
                {
1149
2.04M
                    ps_mv_final_pred->i2_mv[0] = 0;
1150
2.04M
                    ps_mv_final_pred->i2_mv[1] = 0;
1151
2.04M
                    break;
1152
2.04M
                }
1153
                /* If the condition above is not true calculate the MV predictor
1154
                 according to the process defined in sec 8.4.1.2.1 */
1155
334k
            default:
1156
334k
                ih264d_get_motion_vector_predictor(
1157
334k
                                ps_mv_final_pred, ps_mv_pred, u1_ref_idx, uc_lx,
1158
334k
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1159
334k
                break;
1160
2.48M
        }
1161
2.48M
    }
1162
2.48M
    return (u1_direct_zero_pred_flag);
1163
2.48M
}
1164
1165
1166
1167
1168
void ih264d_rep_mv_colz(dec_struct_t *ps_dec,
1169
                        mv_pred_t *ps_mv_pred_src,
1170
                        mv_pred_t *ps_mv_pred_dst,
1171
                        UWORD8 u1_sub_mb_num,
1172
                        UWORD8 u1_colz,
1173
                        UWORD8 u1_ht,
1174
                        UWORD8 u1_wd)
1175
9.97M
{
1176
1177
9.97M
    UWORD8 k, m;
1178
9.97M
    UWORD8 *pu1_colz = ps_dec->pu1_col_zero_flag + ps_dec->i4_submb_ofst
1179
9.97M
                    + u1_sub_mb_num;
1180
1181
48.9M
    for(k = 0; k < u1_ht; k++)
1182
38.9M
    {
1183
192M
        for(m = 0; m < u1_wd; m++)
1184
153M
        {
1185
153M
            *(ps_mv_pred_dst + m) = *(ps_mv_pred_src);
1186
153M
            *(pu1_colz + m) = u1_colz;
1187
1188
153M
        }
1189
38.9M
        pu1_colz += SUB_BLK_WIDTH;
1190
38.9M
        ps_mv_pred_dst += SUB_BLK_WIDTH;
1191
38.9M
    }
1192
9.97M
}
1193