Coverage Report

Created: 2025-08-26 06:38

/src/libavc/decoder/svc/isvcd_mode_mv_resamp.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2022 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
 *  isvcd_mode_mv_resamp.c
24
 *
25
 * @brief
26
 *  Contains routines that resample for SVC resampling
27
 *
28
 * @author
29
 *  Kishore
30
 *
31
 * @par List of Functions:
32
 *  - isvcd_ref_lyr_part_idc()
33
 *  - isvcd_check_motion()
34
 *  - isvcd_get_min_positive()
35
 *  - isvcd_motion_scale_crop_wdw_change()
36
 *  - isvcd_interlyr_motion_scale()
37
 *  - isvcd_store_motion_map()
38
 *  - isvcd_check_mv_diff()
39
 *  - isvcd_interlyr_motion_submbmode_pred()
40
 *  - isvcd_interlyr_mbmode_pred_bmb()
41
 *  - isvcd_populate_ref_idx()
42
 *  - isvcd_interlyr_mbmode_pred()
43
 *  - isvcd_compute_interlyr_motion_mode()
44
 *  - isvcd_interlyr_motion_mode_pred_dyadic()
45
 *  - isvcd_compute_scaled_offsets()
46
 *  - isvcd_comp_mode_mv_res_init()
47
 *
48
 * @remarks
49
 *  None
50
 *
51
 *******************************************************************************
52
 */
53
54
#include <assert.h>
55
#include <string.h>
56
#include "ih264_typedefs.h"
57
#include "ih264_macros.h"
58
#include "ih264_platform_macros.h"
59
#include "ih264_defs.h"
60
#include "ih264d_bitstrm.h"
61
#include "ih264d_defs.h"
62
#include "ih264d_debug.h"
63
#include "isvcd_structs.h"
64
#include "ih264d_defs.h"
65
#include "ih264d_parse_cavlc.h"
66
#include "ih264d_mb_utils.h"
67
#include "ih264d_deblocking.h"
68
#include "ih264d_dpb_manager.h"
69
#include "ih264d_mvpred.h"
70
#include "ih264d_inter_pred.h"
71
#include "ih264d_process_pslice.h"
72
#include "ih264d_error_handler.h"
73
#include "ih264d_cabac.h"
74
#include "ih264d_debug.h"
75
#include "ih264d_tables.h"
76
#include "ih264d_parse_slice.h"
77
#include "ih264d_utils.h"
78
#include "ih264d_parse_islice.h"
79
#include "ih264d_process_bslice.h"
80
#include "ih264d_process_intra_mb.h"
81
#include "isvcd_mode_mv_resamp.h"
82
#include "ih264_debug.h"
83
84
const WORD32 g_i4_dpb_size[16] = {
85
    396,  396,   900,   2376,  2376,  2376,  4752,   8100,
86
    8100, 18000, 20480, 32768, 32768, 34816, 110400, 184320,
87
};
88
89
/*****************************************************************************/
90
/* total_coeff and trailing 1's decode table                                 */
91
/*****************************************************************************/
92
93
/*-----------------------------------------------------------------------*/
94
/* This table consists of info about the NNZ and t1 table                */
95
/*-----------------------------------------------------------------------*/
96
97
const UWORD16 g_au2_nnz_tbl_offsets[9] = {0, 0, 120, 120, 224, 224, 224, 224, 224};
98
99
/*-----------------------------------------------------------------------*/
100
/* For given bits in the bitstream, this table consists of 3 parts       */
101
/* | tcoeff(4) | t1s(2) | suffix(2)|                                     */
102
/*-----------------------------------------------------------------------*/
103
104
const UWORD8 g_au1_codegx_avc[312] = {
105
    0,   0,   0,   0,   0,   0,   0,   0,   4,   4,   4,   4,   4,   4,   4,   4,   24,  24,
106
    24,  24,  24,  24,  24,  24,  22,  22,  2,   2,   45,  45,  45,  45,  78,  78,  42,  42,
107
    61,  61,  61,  61,  94,  94,  58,  58,  38,  38,  18,  18,  110, 110, 74,  74,  54,  54,
108
    34,  34,  126, 126, 90,  90,  70,  70,  50,  50,  142, 142, 106, 106, 86,  86,  66,  66,
109
    115, 139, 119, 99,  159, 123, 103, 83,  191, 171, 151, 147, 175, 155, 135, 131, 223, 203,
110
    183, 179, 207, 187, 167, 163, 255, 235, 231, 211, 239, 219, 215, 195, 242, 242, 250, 250,
111
    246, 246, 226, 226, 196, 196, 196, 196, 196, 196, 196, 196,
112
113
    5,   5,   5,   5,   1,   1,   1,   1,   62,  62,  46,  46,  25,  25,  25,  25,  95,  43,
114
    39,  3,   78,  78,  22,  22,  110, 110, 58,  58,  54,  54,  18,  18,  126, 126, 74,  74,
115
    70,  70,  34,  34,  66,  66,  90,  90,  86,  86,  50,  50,  142, 142, 106, 106, 102, 102,
116
    82,  82,  175, 139, 135, 115, 159, 123, 119, 99,  163, 171, 167, 147, 191, 155, 151, 131,
117
    223, 203, 199, 195, 207, 187, 183, 179, 231, 227, 235, 215, 218, 218, 210, 210, 254, 254,
118
    250, 250, 246, 246, 242, 242, 236, 236, 236, 236, 236, 236, 236, 236,
119
120
    111, 95,  79,  63,  47,  27,  7,   0,   71,  75,  55,  59,  39,  127, 43,  23,  35,  107,
121
    103, 19,  143, 91,  87,  3,   99,  83,  139, 67,  159, 123, 119, 51,  191, 171, 151, 131,
122
    175, 155, 135, 115, 179, 203, 183, 163, 207, 187, 167, 147, 231, 211, 223, 219, 215, 195,
123
    198, 198, 246, 246, 226, 226, 238, 238, 234, 234, 253, 253, 253, 253, 249, 249, 249, 249,
124
    240, 240, 240, 240, 240, 240, 240, 240};
125
126
/*-----------------------------------------------------------------------*/
127
/* For given bits in the bitstream the decoded codeword consists of 2    */
128
/* fields:                                                               */
129
/* | targetcoefftokenidx(6) | suffix(2) |                                */
130
/*-----------------------------------------------------------------------*/
131
132
const UWORD8 g_au1_codegx_svc[312] = {
133
    16,  16,  16,  16,  16,  16,  16,  16,  4,   4,   4,   4,   4,   4,   4,   4,   8,   8,   8,
134
    8,   8,   8,   8,   8,   22,  22,  18,  18,  13,  13,  13,  13,  34,  34,  30,  30,  25,  25,
135
    25,  25,  50,  50,  46,  46,  42,  42,  38,  38,  66,  66,  62,  62,  58,  58,  54,  54,  82,
136
    82,  78,  78,  74,  74,  70,  70,  98,  98,  94,  94,  90,  90,  86,  86,  131, 127, 123, 119,
137
    115, 111, 107, 103, 163, 159, 155, 151, 147, 143, 139, 135, 195, 191, 187, 183, 179, 175, 171,
138
    167, 231, 227, 223, 219, 215, 211, 207, 203, 246, 246, 242, 242, 238, 238, 234, 234, 196, 196,
139
    196, 196, 196, 196, 196, 196, 5,   5,   5,   5,   29,  29,  29,  29,  18,  18,  14,  14,  9,
140
    9,   9,   9,   43,  39,  35,  31,  26,  26,  22,  22,  58,  58,  54,  54,  50,  50,  46,  46,
141
    74,  74,  70,  70,  66,  66,  62,  62,  90,  90,  86,  86,  82,  82,  78,  78,  106, 106, 102,
142
    102, 98,  98,  94,  94,  139, 135, 131, 127, 123, 119, 115, 111, 171, 167, 163, 159, 155, 151,
143
    147, 143, 203, 199, 195, 191, 187, 183, 179, 175, 227, 223, 231, 219, 210, 210, 206, 206, 234,
144
    234, 246, 246, 242, 242, 238, 238, 212, 212, 212, 212, 212, 212, 212, 212, 31,  27,  23,  19,
145
    15,  11,  7,   64,  63,  59,  55,  51,  47,  43,  39,  35,  95,  91,  87,  83,  79,  75,  71,
146
    67,  127, 123, 119, 115, 111, 107, 103, 99,  159, 155, 151, 147, 143, 139, 135, 131, 191, 187,
147
    183, 179, 175, 171, 167, 163, 219, 215, 211, 207, 203, 199, 194, 194, 234, 234, 230, 230, 226,
148
    226, 222, 222, 241, 241, 241, 241, 237, 237, 237, 237, 244, 244, 244, 244, 244, 244, 244, 244,
149
    64,  64,  64,  64,  64,  64,  64,  64
150
151
};
152
153
/*---------------------------------------------------------------------------*/
154
/* A lookup table, when nC>=8, to get the targetcoefftokenidx                */
155
/*---------------------------------------------------------------------------*/
156
157
const UWORD8 g_au1_target_coeff_token_idx[68] = {
158
    0,  0,  0,  0,  16, 1,  1,  1,  20, 8,  2,  2,  23, 11, 9,  3,  24, 13, 12, 4,  28, 15, 14,
159
    5,  30, 17, 18, 6,  31, 21, 22, 7,  32, 25, 26, 10, 36, 33, 29, 19, 40, 37, 34, 27, 44, 41,
160
    38, 35, 47, 45, 42, 39, 49, 48, 46, 43, 53, 50, 51, 52, 57, 54, 55, 56, 61, 58, 59, 60};
161
162
/*---------------------------------------------------------------------------*/
163
/* A lookup table for invTotalCoeff( coeffTokenIdx) and                      */
164
/*  invTrailingOnes( coeffTokenIdx )                                         */
165
/*---------------------------------------------------------------------------*/
166
167
const UWORD8 g_au1_inv_tcoeff_t1[186] = {
168
    0,  5,  10, 15, 4,  9,  19, 14, 23, 8,  13, 18, 27, 12, 17, 22, 31, 16, 21, 26, 35,
169
    20, 25, 30, 39, 24, 29, 34, 43, 28, 33, 38, 32, 36, 37, 42, 47, 40, 41, 46, 51, 44,
170
    45, 50, 55, 48, 49, 54, 59, 53, 52, 57, 58, 63, 56, 61, 62, 67, 60, 65, 66, 64,
171
172
    0,  5,  10, 15, 19, 9,  23, 4,  13, 14, 27, 8,  17, 18, 31, 12, 21, 22, 35, 16, 25,
173
    26, 20, 24, 29, 30, 39, 28, 33, 34, 43, 32, 37, 38, 47, 36, 41, 42, 51, 40, 45, 46,
174
    44, 48, 49, 50, 55, 52, 53, 54, 59, 56, 58, 63, 57, 60, 61, 62, 67, 64, 65, 66,
175
176
    0,  5,  10, 15, 19, 23, 27, 31, 9,  14, 35, 13, 18, 17, 22, 21, 4,  25, 26, 39, 8,
177
    29, 30, 12, 16, 33, 34, 43, 20, 38, 24, 28, 32, 37, 42, 47, 36, 41, 46, 51, 40, 45,
178
    50, 55, 44, 49, 54, 48, 53, 52, 57, 58, 59, 56, 61, 62, 63, 60, 65, 66, 67, 64};
179
180
/*---------------------------------------------------------------------------*/
181
/* A lookup table for decoding the chroma nnz's and trailing 1's             */
182
/*---------------------------------------------------------------------------*/
183
184
const UWORD8 g_au1_chroma_dc_nnz_t1[28] = {4,  4, 4,  4,  0,  0,  0,  0,  24, 24, 24, 24, 18, 46,
185
                                           22, 2, 49, 49, 33, 33, 41, 41, 37, 37, 57, 57, 53, 53};
186
187
/*****************************************************************************/
188
/* Total zeroes table                                                        */
189
/*****************************************************************************/
190
191
/*-----------------------------------------------------------------------*/
192
/* Contains information about tz table. Each entry consists of 3 fields  */
193
/* | table offset (8) | max zeroes(4) | bit offset(2) |                  */
194
/*-----------------------------------------------------------------------*/
195
196
const UWORD16 g_au2_tz_tbl_offsets[27] = {0,     37,    1178,  2778,  4374,  5718,  7066,
197
                                          8666,  10265, 11097, 11925, 12625, 13200, 13516,
198
                                          13768, 13956, 14092, 14344, 14532, 14677, 15374,
199
                                          16206, 17034, 17609, 17928, 18116, 18240};
200
201
/*-----------------------------------------------------------------------*/
202
/* Total zero table                                                      */
203
/*-----------------------------------------------------------------------*/
204
205
const UWORD8 g_au1_tz_tbl[285] = {
206
    0,  0,  9,  5,  17, 13, 25, 21, 33, 29, 41, 37, 49, 45, 57, 53, 60, 60,
207
208
    14, 10, 6,  2,  26, 22, 17, 17, 33, 33, 29, 29, 41, 41, 37, 37, 49, 49, 45, 45, 52, 52, 52,
209
    52, 56, 26, 14, 10, 6,  18, 2,  29, 29, 33, 33, 21, 21, 41, 41, 37, 37, 48, 48, 48, 48, 44,
210
    44, 44, 44, 52, 26, 22, 18, 6,  14, 10, 33, 33, 37, 37, 29, 29, 41, 41, 1,  1,  44, 44, 44,
211
    44, 48, 26, 22, 18, 14, 6,  2,  29, 29, 33, 33, 9,  9,  40, 40, 40, 40, 36, 36, 36, 36, 44,
212
    22, 18, 14, 10, 29, 29, 25, 25, 36, 36, 36, 36, 32, 32, 32, 32, 4,  4,  4,  4,  0,  0,  0,
213
    0,  40, 14, 10, 21, 21, 25, 25, 17, 17, 32, 32, 32, 32, 28, 28, 28, 28, 4,  4,  4,  4,  0,
214
    0,  0,  0,  36, 21, 17, 25, 13, 28, 28, 4,  4,  8,  8,  0,  0,  32,
215
216
    17, 13, 24, 24, 20, 20, 8,  8,  28, 28, 0,  0,  4,
217
218
    17, 13, 20, 20, 8,  8,  24, 24, 0,  0,  4,
219
220
    16, 16, 13, 21, 8,  8,  4,  4,  0,
221
222
    12, 8,  16, 4,  0,
223
224
    8,  12, 4,  0,
225
226
    8,  4,  0,
227
228
    4,  0,
229
230
    0,  4,  8,  12,
231
232
    0,  4,  8,
233
234
    0,  4,
235
236
    0,  0,  5,  9,  13, 17, 20, 20, 24, 24, 28,        /*11*/
237
238
    14, 18, 22, 26, 4,  4,  4,  4,  8,  8,  8,  8,  0, /*13*/
239
240
    13, 13, 18, 22, 8,  8,  8,  8,  4,  4,  4,  4,  0, /*13*/
241
242
    13, 13, 2,  18, 8,  8,  8,  8,  4,                 /*9*/
243
244
    9,  13, 4,  4,  0,                                 /*5*/
245
246
    8,  4,  0,                                         /*3*/
247
248
    4,  0                                              /*2*/
249
};
250
251
/*****************************************************************************/
252
/* Run before table                                                          */
253
/*****************************************************************************/
254
255
const UWORD8 g_au1_run_bef_tbl[64] = {0,  0,  0,  0,  0,  0,  0, 0, 5,  5,  5,  5,  1,  1,  1, 1,
256
                                      10, 10, 6,  6,  1,  1,  1, 1, 14, 14, 10, 10, 6,  6,  2, 2,
257
                                      19, 15, 10, 10, 6,  6,  2, 2, 23, 19, 15, 11, 6,  6,  2, 2,
258
                                      7,  11, 19, 15, 27, 23, 2, 2, 27, 27, 23, 19, 15, 11, 7, 3};
259
260
/*****************************************************************************/
261
/* CBP table                                                                 */
262
/*****************************************************************************/
263
264
/*-----------------------------------------------------------------------*/
265
/* Contains both inter and intra tables                                  */
266
/*-----------------------------------------------------------------------*/
267
268
const UWORD8 g_au1_intra_cbp[48] = {47, 31, 15, 0,  23, 27, 29, 30, 7,  11, 13, 14, 39, 43, 45, 46,
269
                                    16, 3,  5,  10, 12, 19, 21, 26, 28, 35, 37, 42, 44, 1,  2,  4,
270
                                    8,  17, 18, 20, 24, 6,  9,  22, 25, 32, 33, 34, 36, 40, 38, 41};
271
272
const UWORD8 g_au1_inter_cbp[48] = {0,  16, 1,  2,  4,  8,  32, 3,  5,  10, 12, 15, 47, 7,  11, 13,
273
                                    14, 6,  9,  31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46,
274
                                    17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41};
275
276
/*---------------------------------------------------------------------------*/
277
/* Contains the cbp table for intra16x16 mb type                             */
278
/*---------------------------------------------------------------------------*/
279
280
const UWORD8 g_au1_intra16x16_cbp[6] = {0, 16, 32, 15, 31, 47};
281
282
/*****************************************************************************/
283
/* Inverse scan table                                                        */
284
/*****************************************************************************/
285
286
/*-----------------------------------------------------------------------*/
287
/* Regular inverse scan tables                                           */
288
/*-----------------------------------------------------------------------*/
289
290
const UWORD8 g_au1_regular_inv_scan[16] = {0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15};
291
292
const UWORD8 g_au1_regular_inv_scan_field[16] = {0, 4, 1,  8,  12, 5, 9,  13,
293
                                                 2, 6, 10, 14, 3,  7, 11, 15};
294
295
const UWORD8 g_au1_regular_inv_scan8x8[64] = {
296
    0,  1,  8,  16, 9,  2,  3,  10, 17, 24, 32, 25, 18, 11, 4,  5,  12, 19, 26, 33, 40, 48,
297
    41, 34, 27, 20, 13, 6,  7,  14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23,
298
    30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63};
299
300
UWORD8 const g_au1_subblk_8x8_offsets[16] = {0,   0,   0,   0,   64,  64,  64,  64,
301
                                             128, 128, 128, 128, 192, 192, 192, 192};
302
303
/*---------------------------------------------------------------------------*/
304
/* 8x8 inverse scan tables                                               */
305
/*---------------------------------------------------------------------------*/
306
307
const UWORD8 g_au1_prog_deinter_inv_scan[4][16] = {
308
    {0, 9, 17, 18, 12, 40, 27, 7, 35, 57, 29, 30, 58, 38, 53, 47},  /* for First subblock  */
309
    {1, 2, 24, 11, 19, 48, 20, 14, 42, 50, 22, 37, 59, 31, 60, 55}, /* for second subblock */
310
    {8, 3, 32, 4, 26, 41, 13, 21, 49, 43, 15, 44, 52, 39, 61, 62},  /* for third subblock  */
311
    {16, 10, 25, 5, 33, 34, 6, 28, 56, 36, 23, 51, 45, 46, 54, 63}  /* for fourth subblock */
312
};
313
314
const UWORD8 g_au1_prog_8x8_inv_scan[64] = {
315
    0,  1,  8,  16, 9,  2,  3,  10, 17, 24, 32, 25, 18, 11, 4,  5,  12, 19, 26, 33, 40, 48,
316
    41, 34, 27, 20, 13, 6,  7,  14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23,
317
    30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63};
318
319
/*****************************************************************************/
320
/* SUBMB partition tables                                                    */
321
/*****************************************************************************/
322
323
/*---------------------------------------------------------------------------*/
324
/* Number of sub Mb's in 8x8 partition mode                              */
325
/*---------------------------------------------------------------------------*/
326
327
const UWORD8 g_au1_num_sub_mb_part[4] = {1, 2, 2, 4};
328
329
/*---------------------------------------------------------------------------*/
330
/* Width and height of submb's in terms of 4x4 (for 8x8 partition mode)  */
331
/*---------------------------------------------------------------------------*/
332
333
const UWORD8 g_au1_sub_mb_part_wd[4] = {2, 2, 1, 1};
334
335
const UWORD8 g_au1_sub_mb_part_ht[4] = {2, 1, 2, 1};
336
337
/*---------------------------------------------------------------------------*/
338
/* SubMB mc mode table                                                   */
339
/*---------------------------------------------------------------------------*/
340
341
const UWORD8 g_au1_sub_mb_mc_mode[20] = {SUBMB_8x8, SUBMB_8x4, SUBMB_4x8, SUBMB_4x4, SUBMB_8x8,
342
                                         SUBMB_8x8, SUBMB_8x8, SUBMB_8x8, SUBMB_8x4, SUBMB_4x8,
343
                                         SUBMB_8x4, SUBMB_4x8, SUBMB_8x4, SUBMB_4x8, SUBMB_4x4,
344
                                         SUBMB_4x4, SUBMB_4x4,
345
                                         /* Self defined modes B DIRECT8x8 */
346
                                         SUBMB_4x4, SUBMB_4x4, SUBMB_4x4};
347
348
/*---------------------------------------------------------------------------*/
349
/* SubMb prediciton mode table                                           */
350
/*---------------------------------------------------------------------------*/
351
352
const UWORD8 g_au1_sub_mb_pred_mode[20] = {
353
    PRED_L0,
354
    PRED_L0,
355
    PRED_L0,
356
    PRED_L0,
357
    B_DIRECT,
358
    PRED_L0,
359
    PRED_L1,
360
    BI_PRED,
361
    PRED_L0,
362
    PRED_L0,
363
    PRED_L1,
364
    PRED_L1,
365
    BI_PRED,
366
    BI_PRED,
367
    PRED_L0,
368
    PRED_L1,
369
    BI_PRED,
370
    /* Self defined modes for B DIRECT8x8 */
371
    BI_PRED,
372
    PRED_L0,
373
    PRED_L1,
374
};
375
376
/*****************************************************************************/
377
/* MB partition tables                                                       */
378
/*****************************************************************************/
379
380
/*---------------------------------------------------------------------------*/
381
/* Number of MB partitions                                               */
382
/*---------------------------------------------------------------------------*/
383
384
const UWORD8 g_au1_num_mb_part[5] = {1, 2, 2, 4, 4};
385
386
/*---------------------------------------------------------------------------*/
387
/* MB partitions width and height in terms of submbs                     */
388
/*---------------------------------------------------------------------------*/
389
390
const UWORD8 g_au1_mb_part_wd[5] = {4, 4, 2, 2, 2};
391
392
const UWORD8 g_au1_mb_part_ht[5] = {4, 2, 4, 2, 2};
393
394
/*---------------------------------------------------------------------------*/
395
/* MB MC mode of mb partitions                                               */
396
/*---------------------------------------------------------------------------*/
397
398
const UWORD8 g_au1_mb_mc_mode[31] = {
399
    PRED_16x16, PRED_16x8, PRED_8x16, PRED_8x8, PRED_8x8R0, PRED_16x16, PRED_16x16, PRED_16x16,
400
    PRED_16x16, PRED_16x8, PRED_8x16, PRED_16x8, PRED_8x16, PRED_16x8, PRED_8x16, PRED_16x8,
401
    PRED_8x16, PRED_16x8, PRED_8x16, PRED_16x8, PRED_8x16, PRED_16x8, PRED_8x16, PRED_16x8,
402
    PRED_8x16, PRED_16x8, PRED_8x16, PRED_8x8,
403
    /* Self defined modes for B_SKIP and DIRECT16x16 */
404
    PRED_8x8, PRED_8x8, PRED_8x8};
405
406
/*---------------------------------------------------------------------------*/
407
/* MB prediciton mode table                                                  */
408
/*---------------------------------------------------------------------------*/
409
410
const WORD8 g_au1_mb_pred_mode[2][32] = {
411
    {
412
        PRED_L0,
413
        PRED_L0,
414
        PRED_L0,
415
        PRED_INVALID,
416
        PRED_INVALID,
417
        B_DIRECT,
418
        PRED_L0,
419
        PRED_L1,
420
        BI_PRED,
421
        PRED_L0,
422
        PRED_L0,
423
        PRED_L1,
424
        PRED_L1,
425
        PRED_L0,
426
        PRED_L0,
427
        PRED_L1,
428
        PRED_L1,
429
        PRED_L0,
430
        PRED_L0,
431
        PRED_L1,
432
        PRED_L1,
433
        BI_PRED,
434
        BI_PRED,
435
        BI_PRED,
436
        BI_PRED,
437
        BI_PRED,
438
        BI_PRED,
439
        PRED_INVALID,
440
        /* Self defined modes for B_SKIP and DIRECT16x16 */
441
        BI_PRED,
442
        PRED_L0,
443
        PRED_L1,
444
    },
445
    {PRED_INVALID, PRED_L0, PRED_L0, PRED_INVALID, PRED_INVALID, PRED_INVALID, PRED_INVALID,
446
     PRED_INVALID, PRED_INVALID, PRED_L0, PRED_L0, PRED_L1, PRED_L1, PRED_L1, PRED_L1, PRED_L0,
447
     PRED_L0, BI_PRED, BI_PRED, BI_PRED, BI_PRED, PRED_L0, PRED_L0, PRED_L1, PRED_L1, BI_PRED,
448
     BI_PRED, PRED_INVALID,
449
     /* Self defined modes for B_SKIP and DIRECT16x16 */
450
     PRED_INVALID, PRED_INVALID, PRED_INVALID}};
451
452
/*---------------------------------------------------------------------------*/
453
/* Neighbour partition address offsets table                                 */
454
/*---------------------------------------------------------------------------*/
455
456
const UWORD8 g_au1_neighbors_addr_offset[2][16 * 4] = {
457
    /* Each row has current, left, top, top right */
458
    /* Each row corresponds to sub_mb_num */
459
460
    /* Partition width 4 */
461
    {
462
        0,  0,  0, 1, 1,  0, 1, 2, 2,  1,  2, 3, 3,  2,  3,  5,  4,  1,  0,  1,  5, 4,
463
        1,  0,  6, 5, 2,  3, 7, 6, 3,  2,  8, 2, 4,  5,  9,  8,  5,  6,  10, 9,  6, 7,
464
        11, 10, 7, 6, 12, 3, 8, 9, 13, 12, 9, 8, 14, 13, 10, 11, 15, 14, 11, 10,
465
    },
466
    /* Partition width 8 */
467
    {/* Only alternate rows are valid */
468
     0, 0, 0, 2, 0,  0, 0, 0,  2, 1, 2, 4, 0,  0,  0,  0, 4, 1, 0,  2, 0, 0,
469
     0, 0, 6, 5, 2,  1, 0, 0,  0, 0, 8, 2, 4,  6,  0,  0, 0, 0, 10, 9, 6, 5,
470
     0, 0, 0, 0, 12, 3, 8, 10, 0, 0, 0, 0, 14, 13, 10, 9, 0, 0, 0,  0}};
471
472
/*---------------------------------------------------------------------------*/
473
/* Reference index comparison map table                                      */
474
/*---------------------------------------------------------------------------*/
475
const UWORD8 g_au1_ref_idx_comp_map[16 * 2 * 16] = {
476
    /* SUB MB NUMBER 0 */
477
    0, 1, 6, 7, 0, 1, 6, 7, 0, 1, 6, 7, 4, 5, 6, 7, /* Partition width 4 */
478
    0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, /* Partition width 8 */
479
480
    /* SUB MB NUMBER 1 */
481
    1, 1, 7, 7, 5, 5, 7, 7, 1, 1, 3, 3, 1, 1, 7, 7, /* Partition width 4 */
482
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Partition width 8 */
483
484
    /* SUB MB NUMBER 2 */
485
    0, 1, 6, 7, 0, 1, 6, 7, 0, 1, 6, 7, 0, 1, 6, 7, /* Partition width 4 */
486
    0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, /* Partition width 8 */
487
488
    /* SUB MB NUMBER 3 */
489
    1, 1, 7, 7, 1, 1, 7, 7, 1, 1, 3, 3, 5, 5, 7, 7, /* Partition width 4 */
490
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Partition width 8 */
491
492
    /* SUB MB NUMBER 4 */
493
    6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, /* Partition width 4 */
494
    2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, /* Partition width 8 */
495
496
    /* SUB MB NUMBER 5 */
497
    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* Partition width 4 */
498
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Partition width 8 */
499
500
    /* SUB MB NUMBER 6 */
501
    6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, /* Partition width 4 */
502
    2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, /* Partition width 8 */
503
504
    /* SUB MB NUMBER 7 */
505
    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* Partition width 4 */
506
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Partition width 8 */
507
508
    /* SUB MB NUMBER 8 */
509
    0, 1, 6, 7, 0, 1, 6, 7, 0, 1, 6, 7, 0, 1, 6, 7, /* Partition width 4 */
510
    0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, /* Partition width 8 */
511
512
    /* SUB MB NUMBER 9 */
513
    1, 1, 3, 3, 5, 5, 7, 7, 1, 1, 3, 3, 5, 5, 7, 7, /* Partition width 4 */
514
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Partition width 8 */
515
516
    /* SUB MB NUMBER 10 */
517
    0, 1, 6, 7, 0, 1, 6, 7, 0, 1, 6, 7, 0, 1, 6, 7, /* Partition width 4 */
518
    0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, /* Partition width 8 */
519
520
    /* SUB MB NUMBER 11 */
521
    1, 1, 7, 7, 1, 1, 7, 7, 1, 1, 7, 7, 1, 1, 7, 7, /* Partition width 4 */
522
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Partition width 8 */
523
524
    /* SUB MB NUMBER 12 */
525
    6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, /* Partition width 4 */
526
    2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, /* Partition width 8 */
527
528
    /* SUB MB NUMBER 13 */
529
    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* Partition width 4 */
530
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Partition width 8 */
531
532
    /* SUB MB NUMBER 14 */
533
    6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, /* Partition width 4 */
534
    2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, /* Partition width 8 */
535
536
    /* SUB MB NUMBER 15 */
537
    7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* Partition width 4 */
538
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0  /* Partition width 8 */
539
540
};
541
542
/*-----------------------------------------------------------------------*/
543
/* SUB MB index                                                          */
544
/*-----------------------------------------------------------------------*/
545
546
const UWORD8 g_au1_sub_mb_idx_mod[16] = {
547
    0, 0,      /* 16x16 */
548
    0, 8,      /* 16x8 */
549
    0, 2,      /* 8x16 */
550
    0, 0,      /* 8x8 */
551
    0, 4,      /* 8x4 */
552
    0, 1,      /* 4x8 */
553
    0, 1, 3, 1 /* 4x4 */
554
};
555
556
/*****************************************************************************/
557
/* Raster scan offset table                                                  */
558
/*****************************************************************************/
559
560
const UWORD8 g_au1_sub_blk_rast_scan_offsets[16] = {0, 1, 4,  5,  2,  3,  6,  7,
561
                                                    8, 9, 12, 13, 10, 11, 14, 15};
562
563
/*****************************************************************************/
564
/*Motion and mode computation tables                                         */
565
/*****************************************************************************/
566
567
/* B MB TYPES */
568
const UWORD8 g_au1_eb_mb_type[36] = {
569
    B_L0_16x16,   B_L0_16x16,   B_L0_16x16,   B_L1_16x16,   B_L1_16x16,   B_L1_16x16,
570
    B_BI_16x16,   B_BI_16x16,   B_BI_16x16,   B_L0_L0_16x8, B_L0_L1_16x8, B_L0_BI_16x8,
571
    B_L1_L0_16x8, B_L1_L1_16x8, B_L1_BI_16x8, B_BI_L0_16x8, B_BI_L1_16x8, B_BI_BI_16x8,
572
    B_L0_L0_8x16, B_L0_L1_8x16, B_L0_BI_8x16, B_L1_L0_8x16, B_L1_L1_8x16, B_L1_BI_8x16,
573
    B_BI_L0_8x16, B_BI_L1_8x16, B_BI_BI_8x16, B_8x8,        B_8x8,        B_8x8,
574
    B_8x8,        B_8x8,        B_8x8,        B_8x8,        B_8x8,        B_8x8};
575
576
/* P MB TYPES */
577
const UWORD8 g_au1_ep_mb_type[4] = {P_L0_16x16, P_L0_L0_16x8, P_L0_L0_8x16, P_8x8};
578
579
/* P SUB MB TYPES */
580
const UWORD8 g_au1_ep_submb_type[4] = {P_L0_8x8, P_L0_8x4, P_L0_4x8, P_L0_4x4};
581
582
/* B SUB MB TYPES */
583
const UWORD8 g_au1_eb_submb_type[12] = {B_L0_8x8, B_L1_8x8, B_BI_8x8, B_L0_8x4, B_L1_8x4, B_BI_8x4,
584
                                        B_L0_4x8, B_L1_4x8, B_BI_4x8, B_L0_4x4, B_L1_4x4, B_BI_4x4};
585
586
/*****************************************************************************/
587
/* Deblocking related tables                                                 */
588
/*****************************************************************************/
589
590
/* chroma QP values luma Qp is used to index to this table */
591
const UWORD8 g_au1_qp_scale_chroma[52] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12,
592
                                          13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
593
                                          26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 34, 35,
594
                                          35, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 39};
595
596
/* alpha table used in deblocking */
597
const UWORD8 g_au1_alpha_table[52] = {0,  0,  0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
598
                                      0,  0,  0,  4,   4,   5,   6,   7,   8,   9,   10,  12,  13,
599
                                      15, 17, 20, 22,  25,  28,  32,  36,  40,  45,  50,  56,  63,
600
                                      71, 80, 90, 101, 113, 127, 144, 162, 182, 203, 226, 255, 255};
601
602
/* clip table used in deblcoking */
603
const UWORD8 g_au1_clip_table_deblk[75] = {
604
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  2,  3,  4,  5,  6,  7,
605
    8,  9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
606
    27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
607
    46, 47, 48, 49, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51};
608
609
/* Beta table used in deblocking*/
610
const UWORD8 g_au1_beta_table[52] = {
611
    0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  2,  2,  2,  3,  3,  3,  3,  4,  4,  4,
612
    6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18};
613
614
/* clip table used baed on index BS and other vakues */
615
const UWORD8 g_au1_clip_table[52][4] = {
616
    {0, 0, 0, 0},    {0, 0, 0, 0},   {0, 0, 0, 0},   {0, 0, 0, 0},   {0, 0, 0, 0},
617
    {0, 0, 0, 0},    {0, 0, 0, 0},   {0, 0, 0, 0},   {0, 0, 0, 0},   {0, 0, 0, 0},
618
    {0, 0, 0, 0},    {0, 0, 0, 0},   {0, 0, 0, 0},   {0, 0, 0, 0},   {0, 0, 0, 0},
619
    {0, 0, 0, 0},    {0, 0, 0, 0},   {0, 0, 0, 1},   {0, 0, 0, 1},   {0, 0, 0, 1},
620
    {0, 0, 0, 1},    {0, 0, 1, 1},   {0, 0, 1, 1},   {0, 1, 1, 1},   {0, 1, 1, 1},
621
    {0, 1, 1, 1},    {0, 1, 1, 1},   {0, 1, 1, 2},   {0, 1, 1, 2},   {0, 1, 1, 2},
622
    {0, 1, 1, 2},    {0, 1, 2, 3},   {0, 1, 2, 3},   {0, 2, 2, 3},   {0, 2, 2, 4},
623
    {0, 2, 3, 4},    {0, 2, 3, 4},   {0, 3, 3, 5},   {0, 3, 4, 6},   {0, 3, 4, 6},
624
    {0, 4, 5, 7},    {0, 4, 5, 8},   {0, 4, 6, 9},   {0, 5, 7, 10},  {0, 6, 8, 11},
625
    {0, 6, 8, 13},   {0, 7, 10, 14}, {0, 8, 11, 16}, {0, 9, 12, 18}, {0, 10, 13, 20},
626
    {0, 11, 15, 23}, {0, 13, 17, 25}};
627
628
/*****************************************************************************/
629
/* QUANTIZATION TABLES                                                       */
630
/*****************************************************************************/
631
632
const UWORD8 g_au1_luma_to_chroma_qp_map[52] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12,
633
                                                13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
634
                                                26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 34, 35,
635
                                                35, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, 39};
636
637
const UWORD8 g_au1_scale_factor_table[6] = {8, 9, 10, 11, 13, 14};
638
639
/*****************************************************************************/
640
/* SCALING MATRICIES TABLE                                                   */
641
/*****************************************************************************/
642
643
/* Default table used for INTRA 4x4 blocks */
644
const WORD16 g_ai2_default_intra4x4[16] = {6,  13, 13, 20, 20, 20, 28, 28,
645
                                           28, 28, 32, 32, 32, 37, 37, 42};
646
647
/* Default table used for INTER 4x4 blocks */
648
const WORD16 g_ai2_default_inter4x4[16] = {10, 14, 14, 20, 20, 20, 24, 24,
649
                                           24, 24, 27, 27, 27, 30, 30, 34};
650
651
/* Flat table used for 4x4 blocks */
652
const WORD16 g_ai2_flat_4x4[16] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
653
654
/* Flat table used for 4x4 blocks */
655
const WORD16 g_ai2_flat_8x8[64] = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
656
                                   16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
657
                                   16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
658
                                   16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
659
660
/* Default table used for INTRA 8x8 blocks */
661
const WORD16 g_ai2_default_intra8x8[64] = {
662
    6,  10, 10, 13, 11, 13, 16, 16, 16, 16, 18, 18, 18, 18, 18, 23, 23, 23, 23, 23, 23, 25,
663
    25, 25, 25, 25, 25, 25, 27, 27, 27, 27, 27, 27, 27, 27, 29, 29, 29, 29, 29, 29, 29, 31,
664
    31, 31, 31, 31, 31, 33, 33, 33, 33, 33, 36, 36, 36, 36, 38, 38, 38, 40, 40, 42};
665
666
/* Default table used for INTER 8x8 blocks */
667
const WORD16 g_ai2_default_inter8x8[64] = {
668
    9,  13, 13, 15, 13, 15, 17, 17, 17, 17, 19, 19, 19, 19, 19, 21, 21, 21, 21, 21, 21, 22,
669
    22, 22, 22, 22, 22, 22, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 27,
670
    27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 30, 30, 30, 30, 32, 32, 32, 33, 33, 35};
671
672
/* V(qp%6) table */
673
const WORD8 g_ai1_scale_quant_matrix[6][16] = {
674
    {10, 13, 13, 10, 16, 10, 13, 13, 13, 13, 16, 10, 16, 13, 13, 16},
675
    {11, 14, 14, 11, 18, 11, 14, 14, 14, 14, 18, 11, 18, 14, 14, 18},
676
    {13, 16, 16, 13, 20, 13, 16, 16, 16, 16, 20, 13, 20, 16, 16, 20},
677
    {14, 18, 18, 14, 23, 14, 18, 18, 18, 18, 23, 14, 23, 18, 18, 23},
678
    {16, 20, 20, 16, 25, 16, 20, 20, 20, 20, 25, 16, 25, 20, 20, 25},
679
    {18, 23, 23, 18, 29, 18, 23, 23, 23, 23, 29, 18, 29, 23, 23, 29}};
680
681
/* V(qp%6) table for 8x8 */
682
const UWORD8 g_ai1_8x8_scale_quant_matrix[6][64] = {
683
    {20, 19, 19, 25, 18, 25, 19, 24, 24, 19, 20, 18, 32, 18, 20, 19, 19, 24, 24, 19, 19, 25,
684
     18, 25, 18, 25, 18, 25, 19, 24, 24, 19, 19, 24, 24, 19, 18, 32, 18, 20, 18, 32, 18, 24,
685
     24, 19, 19, 24, 24, 18, 25, 18, 25, 18, 19, 24, 24, 19, 18, 32, 18, 24, 24, 18},
686
    {22, 21, 21, 28, 19, 28, 21, 26, 26, 21, 22, 19, 35, 19, 22, 21, 21, 26, 26, 21, 21, 28,
687
     19, 28, 19, 28, 19, 28, 21, 26, 26, 21, 21, 26, 26, 21, 19, 35, 19, 22, 19, 35, 19, 26,
688
     26, 21, 21, 26, 26, 19, 28, 19, 28, 19, 21, 26, 26, 21, 19, 35, 19, 26, 26, 19},
689
    {26, 24, 24, 33, 23, 33, 24, 31, 31, 24, 26, 23, 42, 23, 26, 24, 24, 31, 31, 24, 24, 33,
690
     23, 33, 23, 33, 23, 33, 24, 31, 31, 24, 24, 31, 31, 24, 23, 42, 23, 26, 23, 42, 23, 31,
691
     31, 24, 24, 31, 31, 23, 33, 23, 33, 23, 24, 31, 31, 24, 23, 42, 23, 31, 31, 23},
692
    {28, 26, 26, 35, 25, 35, 26, 33, 33, 26, 28, 25, 45, 25, 28, 26, 26, 33, 33, 26, 26, 35,
693
     25, 35, 25, 35, 25, 35, 26, 33, 33, 26, 26, 33, 33, 26, 25, 45, 25, 28, 25, 45, 25, 33,
694
     33, 26, 26, 33, 33, 25, 35, 25, 35, 25, 26, 33, 33, 26, 25, 45, 25, 33, 33, 25},
695
    {32, 30, 30, 40, 28, 40, 30, 38, 38, 30, 32, 28, 51, 28, 32, 30, 30, 38, 38, 30, 30, 40,
696
     28, 40, 28, 40, 28, 40, 30, 38, 38, 30, 30, 38, 38, 30, 28, 51, 28, 32, 28, 51, 28, 38,
697
     38, 30, 30, 38, 38, 28, 40, 28, 40, 28, 30, 38, 38, 30, 28, 51, 28, 38, 38, 28},
698
    {36, 34, 34, 46, 32, 46, 34, 43, 43, 34, 36, 32, 58, 32, 36, 34, 34, 43, 43, 34, 34, 46,
699
     32, 46, 32, 46, 32, 46, 34, 43, 43, 34, 34, 43, 43, 34, 32, 58, 32, 36, 32, 58, 32, 43,
700
     43, 34, 34, 43, 43, 32, 46, 32, 46, 32, 34, 43, 43, 34, 32, 58, 32, 43, 43, 32}
701
702
};
703
704
/*****************************************************************************/
705
/* CABAC engine tables                                                       */
706
/*****************************************************************************/
707
708
const UWORD8 g_au1_sig_coeff_ctxt_inc[64] = {
709
    0, 1, 2, 3,  4,  5,  5,  4, 4, 3,  3,  4, 4,  4,  5,  5,  4,  4,  4,  4,  3,  3,
710
    6, 7, 7, 7,  8,  9,  10, 9, 8, 7,  7,  6, 11, 12, 13, 11, 6,  7,  8,  9,  14, 10,
711
    9, 8, 6, 11, 12, 13, 11, 6, 9, 14, 10, 9, 11, 12, 13, 11, 14, 10, 12, 255};
712
713
const UWORD8 g_au1_last_coeff_ctxt_inc[64] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
714
                                              2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
715
                                              3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
716
                                              5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 255};
717
718
/*-----------------------------------------------------------------------*/
719
/* Range table                                                           */
720
/*-----------------------------------------------------------------------*/
721
722
const UWORD8 g_au1_cabac_rtab[64][4] = {
723
    {128, 176, 208, 240}, {128, 167, 197, 227}, {128, 158, 187, 216}, {123, 150, 178, 205},
724
    {116, 142, 169, 195}, {111, 135, 160, 185}, {105, 128, 152, 175}, {100, 122, 144, 166},
725
    {95, 116, 137, 158},  {90, 110, 130, 150},  {85, 104, 123, 142},  {81, 99, 117, 135},
726
    {77, 94, 111, 128},   {73, 89, 105, 122},   {69, 85, 100, 116},   {66, 80, 95, 110},
727
    {62, 76, 90, 104},    {59, 72, 86, 99},     {56, 69, 81, 94},     {53, 65, 77, 89},
728
    {51, 62, 73, 85},     {48, 59, 69, 80},     {46, 56, 66, 76},     {43, 53, 63, 72},
729
    {41, 50, 59, 69},     {39, 48, 56, 65},     {37, 45, 54, 62},     {35, 43, 51, 59},
730
    {33, 41, 48, 56},     {32, 39, 46, 53},     {30, 37, 43, 50},     {29, 35, 41, 48},
731
    {27, 33, 39, 45},     {26, 31, 37, 43},     {24, 30, 35, 41},     {23, 28, 33, 39},
732
    {22, 27, 32, 37},     {21, 26, 30, 35},     {20, 24, 29, 33},     {19, 23, 27, 31},
733
    {18, 22, 26, 30},     {17, 21, 25, 28},     {16, 20, 23, 27},     {15, 19, 22, 25},
734
    {14, 18, 21, 24},     {14, 17, 20, 23},     {13, 16, 19, 22},     {12, 15, 18, 21},
735
    {12, 14, 17, 20},     {11, 14, 16, 19},     {11, 13, 15, 18},     {10, 12, 15, 17},
736
    {10, 12, 14, 16},     {9, 11, 13, 15},      {9, 11, 12, 14},      {8, 10, 12, 14},
737
    {8, 9, 11, 13},       {7, 9, 11, 12},       {7, 9, 10, 12},       {7, 8, 10, 11},
738
    {6, 8, 9, 11},        {6, 7, 9, 10},        {6, 7, 8, 9},         {2, 2, 2, 2}};
739
740
/*-----------------------------------------------------------------------*/
741
/* Next state MPS_LPS table                                                  */
742
/*-----------------------------------------------------------------------*/
743
744
const UWORD16 g_au2_cabac_next_state_mps_lps[64] = {
745
    0x100,  0x200,  0x301,  0x402,  0x502,  0x604,  0x704,  0x805,  0x906,  0xa07,  0xb08,
746
    0xc09,  0xd09,  0xe0b,  0xf0b,  0x100c, 0x110d, 0x120d, 0x130f, 0x140f, 0x1510, 0x1610,
747
    0x1712, 0x1812, 0x1913, 0x1a13, 0x1b15, 0x1c15, 0x1d16, 0x1e16, 0x1f17, 0x2018, 0x2118,
748
    0x2219, 0x231a, 0x241a, 0x251b, 0x261b, 0x271c, 0x281d, 0x291d, 0x2a1e, 0x2b1e, 0x2c1e,
749
    0x2d1f, 0x2e20, 0x2f20, 0x3021, 0x3121, 0x3221, 0x3322, 0x3422, 0x3523, 0x3623, 0x3723,
750
    0x3824, 0x3924, 0x3a24, 0x3b25, 0x3c25, 0x3d25, 0x3e26, 0x3e26, 0x3f3f};
751
752
/*****************************************************************************/
753
/*                                                                           */
754
/*  Function Name :  isvcd_ref_lyr_part_idc                                   */
755
/*                                                                           */
756
/*  Description   : this function computes the reference layer partition map */
757
/*                  for all the 4x4 partitions of the current MB             */
758
/*                                                                           */
759
/*  Inputs        : pv_comp_mode_mv_ctxt : mode motion handle                */
760
/*                  ai4_ref_part_idc : pointer to reference layer partition  */
761
/*                    indentification                                        */
762
/*                  pi4_intra_flag  : pointer to store the intra flag        */
763
/*                  i4_mb_addr      : current MB address                     */
764
/*  Globals       : none                                                     */
765
/*  Processing    : it projects the each 4x4 block onto the refernce layer   */
766
/*                  and gets the co-located location. it checks the  MB mode */
767
/*                  of the reference layer MB for INTRA and performs actions */
768
/*                  appropriately. it modifies the intra declared partitions */
769
/*                  for non-dydaic cases                                     */
770
/*  Outputs       : packed offset x and offset y in the refernce layer array */
771
/*  Returns       : none                                                     */
772
/*                                                                           */
773
/*  Issues        : none                                                     */
774
/*                                                                           */
775
/*  Revision History:                                                        */
776
/*                                                                           */
777
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
778
/*         06 09 2021   vijayakumar          creation                        */
779
/*                                                                           */
780
/*****************************************************************************/
781
void isvcd_ref_lyr_part_idc(void *pv_comp_mode_mv_ctxt, WORD32 ai4_ref_part_idc[4][4],
782
                            WORD32 *pi4_intra_flag, void *pv_mb_params)
783
124k
{
784
    /*! Flow of the module is as follows                                   */
785
    /*! 1. runs loops over the 16 4x4 blocks and gets teh reference layer
786
    patition information by projecting the 1,1 locations of
787
    each block                                                      */
788
    /*! 2. if the projected partition is in INTRA MB then its stores -1
789
    to the partition idc array                                      */
790
    /*! 3. if projected partition is in INTER MB then it packs and stores
791
    the offsets form the starting pointer in the part_idc array     */
792
    /*! 4. IN non dyaydic cases. the part idc having -1 are replaced by
793
    neighbours if the current MB projected is not INTRA             */
794
    /*! 5. the -1 values are replaced first on a 4x4 inside an 8x8 basis   */
795
    /*! 6. in second iteration -1 are replaced at an 8x8 basis             */
796
    /*! 7. stores the intra MB status in the location given                */
797
798
124k
    mode_motion_ctxt_t *ps_ctxt;
799
124k
    mode_motion_lyr_ctxt *ps_lyr_mem;
800
124k
    inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
801
124k
    WORD32 i4_blk_y, i4_blk_x;
802
124k
    WORD32 i4_mb_x, i4_mb_y;
803
124k
    WORD32 i4_intra_mb_flag;
804
124k
    WORD32 i4_inter_lyr_mb_prms_stride;
805
124k
    dec_mb_info_t *ps_mb_params;
806
807
124k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
808
124k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
809
810
    /* get the current layer ctxt */
811
124k
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
812
813
    /* ref layer mb mode */
814
124k
    ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) ps_lyr_mem->s_ref_mb_mode.pv_buffer;
815
124k
    i4_inter_lyr_mb_prms_stride = ps_lyr_mem->s_ref_mb_mode.i4_num_element_stride;
816
817
    /* derive the MB_X and MB_Y for the current MB */
818
124k
    i4_mb_x = ps_mb_params->u2_mbx;
819
124k
    i4_mb_y = ps_mb_params->u2_mby;
820
821
    /* set the intra MB flag to default TRUE */
822
124k
    i4_intra_mb_flag = SVCD_TRUE;
823
824
    /*-----------------------------------------------------------------------*/
825
    /* derive the reference layer part idc for all 16 partitions             */
826
    /*-----------------------------------------------------------------------*/
827
623k
    for(i4_blk_y = 0; i4_blk_y < NUM_SUB_MB_PARTS; i4_blk_y++)
828
498k
    {
829
2.49M
        for(i4_blk_x = 0; i4_blk_x < NUM_SUB_MB_PARTS; i4_blk_x++)
830
1.99M
        {
831
1.99M
            WORD32 i4_curr_x, i4_curr_y;
832
1.99M
            WORD32 i4_ref_x, i4_ref_y;
833
1.99M
            WORD32 i4_ref_mb_x, i4_ref_mb_y;
834
1.99M
            WORD8 i1_ref_mb_mode;
835
1.99M
            inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms_temp;
836
837
1.99M
            i4_curr_x = (i4_mb_x << 4) + (i4_blk_x << 2) + 1;
838
1.99M
            i4_curr_y = (i4_mb_y << 4) + (i4_blk_y << 2) + 1;
839
840
            /* get the colocated position in the refernce layer */
841
1.99M
            i4_ref_x = ps_lyr_mem->pi2_ref_loc_x[i4_curr_x];
842
1.99M
            i4_ref_y = ps_lyr_mem->pi2_ref_loc_y[i4_curr_y];
843
844
1.99M
            i4_ref_x = CLIP3(0, ((ps_lyr_mem->i4_ref_width) - 1), i4_ref_x);
845
846
1.99M
            i4_ref_y = CLIP3(0, ((ps_lyr_mem->i4_ref_height) - 1), i4_ref_y);
847
848
            /* get the reference mb x and y */
849
1.99M
            i4_ref_mb_x = (i4_ref_x >> 4);
850
1.99M
            i4_ref_mb_y = (i4_ref_y >> 4);
851
852
            /* get the appropriate mb params in reference layer */
853
1.99M
            ps_inter_lyr_mb_prms_temp = ps_inter_lyr_mb_prms + i4_ref_mb_x;
854
1.99M
            ps_inter_lyr_mb_prms_temp += i4_ref_mb_y * i4_inter_lyr_mb_prms_stride;
855
856
1.99M
            i1_ref_mb_mode = ps_inter_lyr_mb_prms_temp->i1_mb_mode;
857
858
            /* check if the MB mode of the refernce MB is Intra*/
859
1.99M
            if(i1_ref_mb_mode > SVC_INTER_MB)
860
272k
            {
861
                /* store the -1 value */
862
272k
                ai4_ref_part_idc[i4_blk_y][i4_blk_x] = -1;
863
272k
            }
864
1.72M
            else
865
1.72M
            {
866
                /* pack and store the reference x and y */
867
1.72M
                ai4_ref_part_idc[i4_blk_y][i4_blk_x] = (i4_ref_y << 16) + i4_ref_x;
868
1.72M
                i4_intra_mb_flag = SVCD_FALSE;
869
1.72M
            }
870
871
1.99M
        } /* end of block x loop */
872
873
498k
    }     /* end of block y loop */
874
875
    /*************************************************************************/
876
    /* if the restricted spatial resolution change flag is 0                 */
877
    /* modify the part_idc for all the partitions                            */
878
    /*************************************************************************/
879
124k
    if(SVCD_FALSE == (ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag) &&
880
124k
       (SVCD_FALSE == i4_intra_mb_flag))
881
115k
    {
882
        /* replace values of "-1" on a 4x4 block basis */
883
115k
        WORD32 i4_xp, i4_yp;
884
115k
        WORD32 i4_indx_x, i4_indx_y;
885
115k
        WORD32 ai4_flag_8x8[2][2] = {SVCD_FALSE};
886
887
        /* loop over (4) 8x8 partitions */
888
345k
        for(i4_yp = 0; i4_yp < 2; i4_yp++)
889
230k
        {
890
691k
            for(i4_xp = 0; i4_xp < 2; i4_xp++)
891
461k
            {
892
461k
                WORD32 i4_xs, i4_ys;
893
461k
                WORD32 ai4_flag_4x4[2][2] = {SVCD_FALSE};
894
895
                /* loop over (4) 4x4 partitions */
896
1.38M
                for(i4_ys = 0; i4_ys < 2; i4_ys++)
897
922k
                {
898
2.76M
                    for(i4_xs = 0; i4_xs < 2; i4_xs++)
899
1.84M
                    {
900
                        /* index to the exact 4x4 block */
901
1.84M
                        i4_indx_y = (i4_yp << 1) + i4_ys;
902
1.84M
                        i4_indx_x = (i4_xp << 1) + i4_xs;
903
904
                        /* check if the current part idc is -1*/
905
1.84M
                        if(ai4_ref_part_idc[i4_indx_y][i4_indx_x] == -1)
906
122k
                        {
907
122k
                            WORD32 i4_temp_x = 1 - i4_xs;
908
122k
                            WORD32 i4_temp_y = 1 - i4_ys;
909
122k
                            WORD32 i4_temp_part_y = (i4_yp << 1) + i4_temp_y;
910
911
122k
                            WORD32 i4_temp_part_x = (i4_xp << 1) + i4_temp_x;
912
913
122k
                            ai4_flag_4x4[i4_ys][i4_xs] = SVCD_TRUE;
914
915
                            /* replace with appropriate values */
916
122k
                            if((SVCD_FALSE == ai4_flag_4x4[i4_ys][i4_temp_x]) &&
917
122k
                               (ai4_ref_part_idc[i4_indx_y][i4_temp_part_x] != -1))
918
0
                            {
919
0
                                ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
920
0
                                    ai4_ref_part_idc[i4_indx_y][i4_temp_part_x];
921
0
                            }
922
122k
                            else if((SVCD_FALSE == ai4_flag_4x4[i4_temp_y][i4_xs]) &&
923
122k
                                    (ai4_ref_part_idc[i4_temp_part_y][i4_indx_x] != -1))
924
0
                            {
925
0
                                ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
926
0
                                    ai4_ref_part_idc[i4_temp_part_y][i4_indx_x];
927
0
                            }
928
122k
                            else if((SVCD_FALSE == ai4_flag_4x4[i4_temp_y][i4_temp_x]) &&
929
122k
                                    (ai4_ref_part_idc[i4_temp_part_y][i4_temp_part_x] != -1))
930
0
                            {
931
0
                                ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
932
0
                                    ai4_ref_part_idc[i4_temp_part_y][i4_temp_part_x];
933
0
                            }
934
122k
                        } /* end of part idc equal to -1 check */
935
936
1.84M
                    }     /* end of sub partition xs loop */
937
938
922k
                }         /* end of sub partition ys loop */
939
940
461k
            }             /* end of partition xp loop */
941
942
230k
        }                 /* end of partition yp loop */
943
944
        /* replace values of "-1" on an 8x8 block basis */
945
946
        /* loop over (4) 8x8 partitions */
947
345k
        for(i4_yp = 0; i4_yp < 2; i4_yp++)
948
230k
        {
949
691k
            for(i4_xp = 0; i4_xp < 2; i4_xp++)
950
461k
            {
951
461k
                WORD32 i4_yp_inv = 1 - i4_yp;
952
461k
                WORD32 i4_xp_inv = 1 - i4_xp;
953
461k
                WORD32 i4_xo_inv = (2 - i4_xp);
954
461k
                WORD32 i4_yo_inv = (2 - i4_yp);
955
461k
                i4_indx_x = (i4_xp << 1);
956
461k
                i4_indx_y = (i4_yp << 1);
957
958
                /* check if the current part idc is -1*/
959
461k
                if(ai4_ref_part_idc[i4_indx_y][i4_indx_x] == -1)
960
30.5k
                {
961
30.5k
                    ai4_flag_8x8[i4_yp][i4_xp] = SVCD_TRUE;
962
963
                    /* replace the -1 with appropriate values */
964
30.5k
                    if(SVCD_FALSE == ai4_flag_8x8[i4_yp][i4_xp_inv] &&
965
30.5k
                       ai4_ref_part_idc[i4_indx_y][i4_xo_inv] != -1)
966
15.7k
                    {
967
15.7k
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
968
15.7k
                            ai4_ref_part_idc[i4_indx_y][i4_xo_inv];
969
970
15.7k
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x] =
971
15.7k
                            ai4_ref_part_idc[i4_indx_y + 1][i4_xo_inv];
972
973
15.7k
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x + 1] =
974
15.7k
                            ai4_ref_part_idc[i4_indx_y][i4_xo_inv];
975
976
15.7k
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x + 1] =
977
15.7k
                            ai4_ref_part_idc[i4_indx_y + 1][i4_xo_inv];
978
15.7k
                    }
979
14.8k
                    else if(SVCD_FALSE == ai4_flag_8x8[i4_yp_inv][i4_xp] &&
980
14.8k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x] != -1)
981
14.1k
                    {
982
14.1k
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
983
14.1k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x];
984
985
14.1k
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x] =
986
14.1k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x];
987
988
14.1k
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x + 1] =
989
14.1k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x + 1];
990
991
14.1k
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x + 1] =
992
14.1k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x + 1];
993
14.1k
                    }
994
680
                    else if(SVCD_FALSE == ai4_flag_8x8[i4_yp_inv][i4_xp_inv] &&
995
680
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv] != -1)
996
680
                    {
997
680
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
998
680
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv];
999
1000
680
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x] =
1001
680
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv];
1002
1003
680
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x + 1] =
1004
680
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv];
1005
1006
680
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x + 1] =
1007
680
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv];
1008
680
                    }
1009
30.5k
                } /* end of part idc equal to -1 check */
1010
1011
461k
            }     /* end of partition xp loop */
1012
1013
230k
        }         /* end of partition yp loop */
1014
1015
115k
    }             /* end of refinement of part idc for non dyadic case*/
1016
1017
    /* store the intra flag in the location provided */
1018
124k
    *pi4_intra_flag = i4_intra_mb_flag;
1019
1020
124k
    return;
1021
124k
}
1022
/*****************************************************************************/
1023
/*                                                                           */
1024
/*  Function Name : isvcd_check_motion                                        */
1025
/*                                                                           */
1026
/*  Description   :this function calculates the MV diff b/w to motion vectors*/
1027
/*                 and returns 1 if it is under threshold equal to 0         */
1028
/*                                                                           */
1029
/*  Inputs        : pv_motion_prm_mb_part_a : pointer to motion struct part A*/
1030
/*                  pv_motion_prm_mb_part_b : pointer to motion struct part B*/
1031
/*                  i4_listx        : lists to be checked                    */
1032
/*  Globals       : none                                                     */
1033
/*  Processing    : it compares reference indcies fo given number of lists   */
1034
/*                  it calculates the mv diff and compares it with 0         */
1035
/*                  it does the above for given number of lists              */
1036
/*  Outputs       : none                                                     */
1037
/*  Returns       : 1 if matching 0 if not matching                          */
1038
/*                                                                           */
1039
/*  Issues        : none                                                     */
1040
/*                                                                           */
1041
/*  Revision History:                                                        */
1042
/*                                                                           */
1043
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1044
/*         06 09 2021   vijayakumar          creation                        */
1045
/*                                                                           */
1046
/*****************************************************************************/
1047
WORD32 isvcd_check_motion(void *pv_motion_prm_mb_part_a, void *pv_motion_prm_mb_part_b,
1048
                          WORD32 i4_listx)
1049
533k
{
1050
533k
    mv_pred_t *ps_part_a;
1051
533k
    mv_pred_t *ps_part_b;
1052
533k
    WORD32 i4_cntr;
1053
533k
    WORD32 i4_mv_treshold;
1054
533k
    WORD32 i4_flag = 0;
1055
1056
533k
    ps_part_a = (mv_pred_t *) pv_motion_prm_mb_part_a;
1057
533k
    ps_part_b = (mv_pred_t *) pv_motion_prm_mb_part_b;
1058
1059
1.11M
    for(i4_cntr = 0; i4_cntr < i4_listx; i4_cntr++)
1060
627k
    {
1061
        /* calculate the absolute diff of both components */
1062
627k
        i4_mv_treshold = ABS((ps_part_a->i2_mv[2 * i4_cntr]) - (ps_part_b->i2_mv[2 * i4_cntr]));
1063
627k
        i4_mv_treshold +=
1064
627k
            ABS((ps_part_a->i2_mv[1 + 2 * i4_cntr]) - (ps_part_b->i2_mv[1 + 2 * i4_cntr]));
1065
1066
627k
        if((0 == i4_mv_treshold) &&
1067
627k
           (ps_part_a->i1_ref_frame[i4_cntr] == ps_part_b->i1_ref_frame[i4_cntr]))
1068
579k
        {
1069
579k
            i4_flag = 1;
1070
579k
        }
1071
47.5k
        else
1072
47.5k
        {
1073
47.5k
            i4_flag = 0;
1074
47.5k
            return (i4_flag);
1075
47.5k
        }
1076
1077
627k
    } /* end of loop over lists */
1078
1079
486k
    return (i4_flag);
1080
533k
}
1081
/*****************************************************************************/
1082
/*                                                                           */
1083
/*  Function Name : isvcd_get_min_positive                                    */
1084
/*                                                                           */
1085
/*  Description   : this utility return the minimum positive b/w the given   */
1086
/*                  inputs                                                   */
1087
/*                                                                           */
1088
/*  Inputs        :  i4_input_1: value A , i4_input_2: value B               */
1089
/*  Globals       :  none                                                    */
1090
/*  Processing    :  if A & B are greater than -1 thenit returns MIN(A<B)    */
1091
/*                   otherwise return MAX(A<B)                               */
1092
/*  Outputs       :  none                                                    */
1093
/*  Returns       :  minimum positive of the two inputs                      */
1094
/*                                                                           */
1095
/*  Issues        :  none                                                    */
1096
/*                                                                           */
1097
/*  Revision History:                                                        */
1098
/*                                                                           */
1099
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1100
/*         06 09 2021   vijayakumar          creation                        */
1101
/*                                                                           */
1102
/*****************************************************************************/
1103
WORD32 isvcd_get_min_positive(WORD32 i4_input_1, WORD32 i4_input_2)
1104
2.16M
{
1105
2.16M
    UWORD32 u4_x, u4_y;
1106
2.16M
    WORD32 i4_min_positive;
1107
1108
    /* get positive values */
1109
2.16M
    u4_x = (UWORD32) i4_input_1;
1110
2.16M
    u4_y = (UWORD32) i4_input_2;
1111
1112
    /* logic and desired output
1113
1114
    u4_x     magnitude compare    u4_y           o/p
1115
    +              >              +             u4_y
1116
    +              <              +             u4_x
1117
    +              =              +             u4_x
1118
    -              >              -             u4_y
1119
    -              <              -             u4_x
1120
    -              =              -             u4_x
1121
    0              =              0             u4_x
1122
    -              n/a            +             u4_y
1123
    +              n/a            -             u4_x
1124
1125
    */
1126
1127
2.16M
    if((u4_y < u4_x) && (0 <= i4_input_2))
1128
4.41k
    {
1129
4.41k
        i4_min_positive = i4_input_2;
1130
4.41k
    }
1131
2.15M
    else
1132
2.15M
    {
1133
2.15M
        i4_min_positive = i4_input_1;
1134
2.15M
    }
1135
2.16M
    return (i4_min_positive);
1136
2.16M
}
1137
/*****************************************************************************/
1138
/*                                                                           */
1139
/*  Function Name :  isvcd_motion_scale_crop_wdw_change                       */
1140
/*                                                                           */
1141
/*  Description   : This function does the up scaling of motion vectors and  */
1142
/*                  for crop window change cases                             */
1143
/*  Inputs        : pv_comp_mode_mv_ctxt : mode motion handle                */
1144
/*                  ps_lyr_mem   : pointer current layer memory              */
1145
/*                  ps_mb_params : pointer to mb params structure            */
1146
/*                  ps_ref_mv    : pointer to reference MVs                  */
1147
/*                  ps_motion_pred : pointer to current 4x4 part mv pred     */
1148
/*                  i4_listx : lists to be processed                         */
1149
/*                  i4_part_frm_x: horz location in the picture of the       */
1150
/*                                 current sub partition                     */
1151
/*                  i4_part_frm_y: vertical location in the picture of the   */
1152
/*                                 current sub partition                     */
1153
/*  Globals       :                                                          */
1154
/*  Processing    : it takes care of cropping                                */
1155
/*                  change flag                                              */
1156
/*  Outputs       : it stores the interlayer MV pred in the structure        */
1157
/*  Returns       : none                                                     */
1158
/*                                                                           */
1159
/*  Issues        : none                                                     */
1160
/*                                                                           */
1161
/*  Revision History:                                                        */
1162
/*                                                                           */
1163
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1164
/*         06 09 2021   vijayakumar          creation                        */
1165
/*                                                                           */
1166
/*****************************************************************************/
1167
void isvcd_motion_scale_crop_wdw_change(mode_motion_ctxt_t *ps_ctxt,
1168
                                        mode_motion_lyr_ctxt *ps_lyr_mem,
1169
                                        dec_mb_info_t *ps_mb_params, mv_pred_t *ps_ref_mv,
1170
                                        mv_pred_t *ps_motion_pred, WORD32 i4_lists,
1171
                                        WORD32 i4_part_frm_x, WORD32 i4_part_frm_y,
1172
                                        void **ppv_map_ref_idx_to_poc, UWORD8 u1_list_x)
1173
0
{
1174
0
    ref_lyr_scaled_offset_t *ps_curr_lyr_offset;
1175
0
    ref_lyr_scaled_offset_t *ps_ref_pic_lyr_offset;
1176
0
    WORD32 i4_ref_lyr_width, i4_ref_lyr_height;
1177
0
    WORD32 i4_curr_lyr_width, i4_curr_lyr_height;
1178
0
    WORD32 i4_ref_indx;
1179
0
    WORD32 i4_mv_x, i4_mv_y;
1180
0
    WORD32 i4_x, i4_y;
1181
0
    WORD32 i4_dox, i4_doy, i4_dsw, i4_dsh;
1182
0
    WORD32 i4_scale_x, i4_scale_y;
1183
0
    WORD8 *pi1_ref_idx_map;
1184
1185
0
    UNUSED(ps_ctxt);
1186
0
    UNUSED(ps_mb_params);
1187
1188
    /* get the reference index */
1189
0
    i4_ref_indx = ps_motion_pred->i1_ref_frame[u1_list_x];
1190
1191
0
    i4_mv_x = (WORD32) ps_ref_mv->i2_mv[2 * u1_list_x];
1192
0
    i4_mv_y = (WORD32) ps_ref_mv->i2_mv[1 + 2 * u1_list_x];
1193
1194
    /* get the Map buffer pointer */
1195
0
    if(0 == i4_lists)
1196
0
    {
1197
0
        pi1_ref_idx_map = (WORD8 *) ppv_map_ref_idx_to_poc;
1198
0
    }
1199
0
    else
1200
0
    {
1201
0
        pi1_ref_idx_map = (WORD8 *) (ppv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF);
1202
0
    }
1203
1204
    /* get the Ref layer width and height */
1205
0
    i4_ref_lyr_width = ps_lyr_mem->i4_ref_width;
1206
0
    i4_ref_lyr_height = ps_lyr_mem->i4_ref_height;
1207
1208
    /* get the Scaled ref layer width and height */
1209
0
    i4_curr_lyr_width = ps_lyr_mem->ps_curr_lyr_res_prms->u2_scaled_ref_width;
1210
0
    i4_curr_lyr_height = ps_lyr_mem->ps_curr_lyr_res_prms->u2_scaled_ref_height;
1211
1212
    /* get the offset stucture pointer */
1213
0
    ps_curr_lyr_offset = &ps_lyr_mem->ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset;
1214
1215
    /* get the reference offset structure pointer */
1216
0
    ps_ref_pic_lyr_offset = ps_lyr_mem->ps_ref_pic_lyr_offsets + pi1_ref_idx_map[i4_ref_indx];
1217
1218
    /* calculate the correction variables */
1219
0
    i4_dox = ps_curr_lyr_offset->i2_left - ps_ref_pic_lyr_offset->i2_left;
1220
0
    i4_doy = ps_curr_lyr_offset->i2_top - ps_ref_pic_lyr_offset->i2_top;
1221
0
    i4_dsw = ps_curr_lyr_offset->i2_rt - ps_ref_pic_lyr_offset->i2_rt + i4_dox;
1222
0
    i4_dsh = ps_curr_lyr_offset->i2_bot - ps_ref_pic_lyr_offset->i2_bot + i4_doy;
1223
1224
0
    i4_scale_x =
1225
0
        (((i4_curr_lyr_width + i4_dsw) << 16) + (i4_ref_lyr_width >> 1)) / i4_ref_lyr_width;
1226
1227
0
    i4_scale_y =
1228
0
        (((i4_curr_lyr_height + i4_dsh) << 16) + (i4_ref_lyr_height >> 1)) / i4_ref_lyr_height;
1229
1230
    /* scale the motion vectors */
1231
0
    i4_mv_x = (i4_mv_x * i4_scale_x + 32768) >> 16;
1232
0
    i4_mv_y = (i4_mv_y * i4_scale_y + 32768) >> 16;
1233
1234
    /* subtract the offsets */
1235
0
    i4_x = i4_part_frm_x - ps_lyr_mem->i4_offset_x;
1236
0
    i4_y = i4_part_frm_y - ps_lyr_mem->i4_offset_y;
1237
1238
    /* get the scale factors */
1239
0
    i4_scale_x = (((4 * i4_dsw) << 16) + (i4_curr_lyr_width >> 1)) / i4_curr_lyr_width;
1240
0
    i4_scale_y = (((4 * i4_dsh) << 16) + (i4_curr_lyr_height >> 1)) / i4_curr_lyr_height;
1241
1242
    /* add the correction */
1243
0
    i4_mv_x += ((i4_x * i4_scale_x + 32768) >> 16) - 4 * i4_dox;
1244
0
    i4_mv_y += ((i4_y * i4_scale_y + 32768) >> 16) - 4 * i4_doy;
1245
1246
    /* store the final motion vectors */
1247
0
    ps_motion_pred->i2_mv[2 * u1_list_x] = i4_mv_x;
1248
0
    ps_motion_pred->i2_mv[1 + 2 * u1_list_x] = i4_mv_y;
1249
0
}
1250
1251
/*****************************************************************************/
1252
/*                                                                           */
1253
/*  Function Name :  isvcd_interlayer_motion_scale                            */
1254
/*                                                                           */
1255
/*  Description   : This function does the up scaling of motion vectors and  */
1256
/*                  and stores the inter layer MV and reference indices      */
1257
/*                  in the mv prediction structure for a 4x4 part            */
1258
/*  Inputs        : pv_comp_mode_mv_ctxt : mode motion handle                */
1259
/*                  pi4_ref_part_idc   : pointer current 4x4 part ref_idc    */
1260
/*                  pv_motion_pred : pointer to current 4x4 part mv pred     */
1261
/*                  i4_listx : lists to be processed                         */
1262
/*                  i4_part_frm_x: horz location in the picture of the       */
1263
/*                                 current sub partition                     */
1264
/*                  i4_part_frm_y: vertical location in the picture of the   */
1265
/*                                 current sub partition                     */
1266
/*  Globals       :                                                          */
1267
/*  Processing    : it stores the default values if the refernce indx of     */
1268
/*                  ref lyr partiton is -1. if not it upscales the motion    */
1269
/*                  vectors based on scale factors. it takes care of cropping*/
1270
/*                  change flag                                              */
1271
/*  Outputs       : it stores the interlayer MV pred in the structure        */
1272
/*  Returns       : none                                                     */
1273
/*                                                                           */
1274
/*  Issues        : none                                                     */
1275
/*                                                                           */
1276
/*  Revision History:                                                        */
1277
/*                                                                           */
1278
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1279
/*         06 09 2021   vijayakumar          creation                        */
1280
/*                                                                           */
1281
/*****************************************************************************/
1282
WORD32 isvcd_interlyr_motion_scale(void *pv_comp_mode_mv_ctxt, WORD32 *pi4_ref_part_idc,
1283
                                   dec_mb_info_t *ps_mb_params, void *pv_motion_pred,
1284
                                   WORD32 i4_listx, WORD32 i4_part_frm_x, WORD32 i4_part_frm_y,
1285
                                   void **ppv_map_ref_idx_to_poc)
1286
2.05M
{
1287
    /*! Flow of the module is as follows                                   */
1288
    /*! 1. derive the offsets form part idc                                */
1289
    /*! 2. takes the motion vector and scales it based on scale factor     */
1290
    /*! 3. adds the correction factors for crop window change cases        */
1291
    /*! 4. store the default motion params for intra projected blocks      */
1292
1293
2.05M
    mode_motion_ctxt_t *ps_ctxt;
1294
2.05M
    mode_motion_lyr_ctxt *ps_lyr_mem;
1295
2.05M
    mv_pred_t *ps_motion_pred;
1296
2.05M
    mv_pred_t *ps_ref_mv;
1297
2.05M
    WORD32 i4_lists;
1298
2.05M
    WORD32 i4_ref_16x16_flag = 0;
1299
2.05M
    WORD32 i4_scale_x, i4_scale_y;
1300
2.05M
    WORD16 i2_max_mv_x, i2_max_mv_y;
1301
1302
2.05M
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
1303
1304
    /* get the current layer ctxt */
1305
2.05M
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
1306
1307
    /* ----------- Get the reference layer MV structure ---------- */
1308
2.05M
    {
1309
2.05M
        mv_pred_t *ps_ref_lyr_motion_prms;
1310
2.05M
        WORD32 i4_ref_x, i4_ref_y;
1311
2.05M
        WORD32 i4_ref_mb_x, i4_ref_mb_y;
1312
2.05M
        WORD32 i4_ref_width;
1313
1314
2.05M
        ps_ref_lyr_motion_prms = (mv_pred_t *) ps_lyr_mem->pv_ref_mv_bank_l0;
1315
2.05M
        i4_ref_width = ps_lyr_mem->i4_ref_width;
1316
2.05M
        i2_max_mv_x = i4_ref_width << 2;
1317
2.05M
        i2_max_mv_y = ps_lyr_mem->i4_ref_height << 2;
1318
1319
        /* extract the reference x and y positions */
1320
2.05M
        i4_ref_x = (*pi4_ref_part_idc) & 0xFFFF;
1321
2.05M
        i4_ref_y = (*pi4_ref_part_idc) >> 16;
1322
1323
        /* get the reference mb x and y */
1324
2.05M
        i4_ref_mb_x = (i4_ref_x >> 4);
1325
2.05M
        i4_ref_mb_y = (i4_ref_y >> 4);
1326
1327
        /* get the reference layer motion struct pointing  */
1328
        /* to first 4x4 partition of the refernce layer MB */
1329
2.05M
        ps_ref_mv = ps_ref_lyr_motion_prms + (i4_ref_mb_x << 4);
1330
2.05M
        ps_ref_mv += (i4_ref_mb_y * i4_ref_width);
1331
1332
        /* if reference layer mb type is non 16x16 */
1333
2.05M
        if(0 == i4_ref_16x16_flag)
1334
2.05M
        {
1335
            /* increment the pointer to appropaite 4x4 */
1336
2.05M
            ps_ref_mv += ((i4_ref_x >> 2) & 0x03);
1337
2.05M
            ps_ref_mv += (((i4_ref_y >> 2) & 0x03) << 2);
1338
2.05M
        }
1339
2.05M
    }
1340
1341
    /* motion pred structure */
1342
2.05M
    ps_motion_pred = pv_motion_pred;
1343
1344
    /* retrive the scale factors */
1345
2.05M
    i4_scale_x = ps_lyr_mem->i4_scale_mv_x;
1346
2.05M
    i4_scale_y = ps_lyr_mem->i4_scale_mv_y;
1347
1348
    /* loop on the lists given as input */
1349
4.52M
    for(i4_lists = 0; i4_lists < i4_listx; i4_lists++)
1350
2.46M
    {
1351
2.46M
        WORD32 i4_mv_x, i4_mv_y;
1352
2.46M
        WORD16 i2_mv_x, i2_mv_y;
1353
1354
        /* if the refernce index is -1 set the default values */
1355
2.46M
        if(-1 == ps_ref_mv->i1_ref_frame[i4_lists])
1356
287k
        {
1357
287k
            ps_motion_pred->i1_ref_frame[i4_lists] = -1;
1358
287k
            ps_motion_pred->i2_mv[2 * i4_lists] = 0;
1359
287k
            ps_motion_pred->i2_mv[1 + 2 * i4_lists] = 0;
1360
287k
        }
1361
2.17M
        else
1362
2.17M
        {
1363
            /* field MB and field pictures modification are present */
1364
            /* currently not implemented */
1365
2.17M
            ps_motion_pred->i1_ref_frame[i4_lists] = ps_ref_mv->i1_ref_frame[i4_lists];
1366
1367
2.17M
            i2_mv_x = ps_ref_mv->i2_mv[2 * i4_lists];
1368
2.17M
            i2_mv_y = ps_ref_mv->i2_mv[1 + 2 * i4_lists];
1369
2.17M
            i2_mv_x = CLIP3(-i2_max_mv_x, i2_max_mv_x, i2_mv_x);
1370
2.17M
            i2_mv_y = CLIP3(-i2_max_mv_y, i2_max_mv_y, i2_mv_y);
1371
            /* scale the motion vectors */
1372
2.17M
            i4_mv_x = (i2_mv_x * i4_scale_x + 32768) >> 16;
1373
2.17M
            i4_mv_y = (i2_mv_y * i4_scale_y + 32768) >> 16;
1374
1375
            /* store the final motion vectors */
1376
2.17M
            ps_motion_pred->i2_mv[2 * i4_lists] = i4_mv_x;
1377
2.17M
            ps_motion_pred->i2_mv[1 + 2 * i4_lists] = i4_mv_y;
1378
1379
            /* if cropping change flag is present */
1380
2.17M
            if(SVCD_TRUE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_cropping_change_flag)
1381
0
            {
1382
                /* over write the motion vectors x and y */
1383
0
                isvcd_motion_scale_crop_wdw_change(ps_ctxt, ps_lyr_mem, ps_mb_params, ps_ref_mv,
1384
0
                                                   ps_motion_pred, i4_listx, i4_part_frm_x,
1385
0
                                                   i4_part_frm_y, ppv_map_ref_idx_to_poc, i4_lists);
1386
0
            }
1387
2.17M
        }
1388
2.46M
    } /* end of lists loop */
1389
1390
2.05M
    return (i4_ref_16x16_flag);
1391
2.05M
}
1392
1393
/*****************************************************************************/
1394
/*                                                                           */
1395
/*  Function Name : isvcd_store_motion_map                                    */
1396
/*                                                                           */
1397
/*  Description   : this fucntion copies the  souce structure contents to    */
1398
/*                  destination entires of part width x part height          */
1399
/*                                                                           */
1400
/*  Inputs        : pv_motion_pred : pointer to the source structure         */
1401
/*                  ps_curr_lyr_motion_map : pointer to the destination      */
1402
/*                  in the map                                               */
1403
/*                  i4_src_stride : source stride                            */
1404
/*                  i4_dst_stride : destination stride                       */
1405
/*                  i4_part_width : width to be copied in terms of sub mbs   */
1406
/*                  i4_part_height : height to be copied                     */
1407
/*                  i4_src_update_flag : source update flag                  */
1408
/*  Globals       : none                                                     */
1409
/*  Processing    : it copies the src contents to destination                */
1410
/*                                                                           */
1411
/*  Outputs       : none                                                     */
1412
/*  Returns       : none                                                     */
1413
/*                                                                           */
1414
/*  Issues        : none                                                     */
1415
/*                                                                           */
1416
/*  Revision History:                                                        */
1417
/*                                                                           */
1418
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1419
/*         06 09 2021   vijayakumar          creation                        */
1420
/*                                                                           */
1421
/*****************************************************************************/
1422
void isvcd_store_motion_map(void *pv_motion_pred, void *pv_curr_lyr_motion_map,
1423
                            WORD32 i4_src_stride, WORD32 i4_dst_stride, WORD32 i4_part_width,
1424
                            WORD32 i4_part_height, WORD32 i4_src_update_flag)
1425
213k
{
1426
    /*! Flow of the module is as follows                                   */
1427
    /*! 1. loops over part_width and part_height                           */
1428
    /*! 2. copies the src params toi destination                           */
1429
    /*! 3. updates the source pointer if src_update flag is set to 1       */
1430
1431
213k
    WORD32 i4_i, i4_j;
1432
213k
    mv_pred_t *ps_mv_pred_src;
1433
213k
    mv_pred_t *ps_mv_map_dst;
1434
1435
213k
    ps_mv_pred_src = (mv_pred_t *) pv_motion_pred;
1436
213k
    ps_mv_map_dst = (mv_pred_t *) pv_curr_lyr_motion_map;
1437
1438
    /* store the current motion pred to all the motion map structures */
1439
641k
    for(i4_i = 0; i4_i < i4_part_height; i4_i++)
1440
427k
    {
1441
1.28M
        for(i4_j = 0; i4_j < i4_part_width; i4_j++)
1442
855k
        {
1443
            /* copy form source to destination */
1444
855k
            *(ps_mv_map_dst + i4_j) = *(ps_mv_pred_src + (i4_src_update_flag * i4_j));
1445
1446
855k
        } /* end of loop over partition width */
1447
1448
427k
        ps_mv_map_dst += i4_dst_stride;
1449
427k
        ps_mv_pred_src += (i4_src_stride * i4_src_update_flag);
1450
1451
427k
    } /* end of loop over partition height */
1452
213k
    return;
1453
213k
}
1454
/*****************************************************************************/
1455
/*                                                                           */
1456
/*  Function Name : isvcd_check_mv_diff                                       */
1457
/*                                                                           */
1458
/*  Description   :this function calculates the MV diff b/w to motion vectors*/
1459
/*                 and returns 1 if it is under threshold                    */
1460
/*                                                                           */
1461
/*  Inputs        : pv_motion_prm_a : pointer to motion struct part A        */
1462
/*                  pv_motion_prm_b : pointer to motion struct part B        */
1463
/*                  i4_listx        : lists to be checked                    */
1464
/*                  i4_actual_threshold : threshold with which the mv diff   */
1465
/*                   is to be compared with                                  */
1466
/*  Globals       : none                                                     */
1467
/*  Processing    : it calculates the mv diff and compares it with threshold */
1468
/*                  returns 1 if under threshold                              */
1469
/*  Outputs       : none                                                     */
1470
/*  Returns       : 1 if under threshold 0 if not under threshold            */
1471
/*                                                                           */
1472
/*  Issues        : none                                                     */
1473
/*                                                                           */
1474
/*  Revision History:                                                        */
1475
/*                                                                           */
1476
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1477
/*         06 09 2021   vijayakumar          creation                        */
1478
/*                                                                           */
1479
/*****************************************************************************/
1480
WORD32 isvcd_check_mv_diff(void *pv_motion_prm_a, void *pv_motion_prm_b, WORD32 i4_listx,
1481
                           WORD32 i4_actual_threshold)
1482
2.30M
{
1483
2.30M
    mv_pred_t *ps_part_a;
1484
2.30M
    mv_pred_t *ps_part_b;
1485
2.30M
    WORD32 i4_cntr;
1486
2.30M
    WORD32 i4_mv_treshold;
1487
2.30M
    WORD32 i4_flag;
1488
1489
2.30M
    ps_part_a = (mv_pred_t *) pv_motion_prm_a;
1490
2.30M
    ps_part_b = (mv_pred_t *) pv_motion_prm_b;
1491
1492
2.30M
    i4_flag = 1;
1493
4.96M
    for(i4_cntr = 0; i4_cntr < i4_listx; i4_cntr++)
1494
2.69M
    {
1495
        /* calculate the absolute diff of both components */
1496
2.69M
        i4_mv_treshold = ABS((ps_part_a->i2_mv[2 * i4_cntr]) - (ps_part_b->i2_mv[2 * i4_cntr]));
1497
2.69M
        i4_mv_treshold +=
1498
2.69M
            ABS((ps_part_a->i2_mv[1 + (2 * i4_cntr)]) - (ps_part_b->i2_mv[1 + (2 * i4_cntr)]));
1499
1500
2.69M
        if(i4_actual_threshold < i4_mv_treshold)
1501
41.9k
        {
1502
41.9k
            i4_flag = 0;
1503
41.9k
            break;
1504
41.9k
        }
1505
1506
2.69M
    } /* end of loop over lists */
1507
2.30M
    return (i4_flag);
1508
2.30M
}
1509
1510
/*****************************************************************************/
1511
/*                                                                           */
1512
/*  Function Name :  isvcd_interlayer_motion_submbmode_pred                   */
1513
/*                                                                           */
1514
/*  Description   : this function does the inter layer motion predcition for */
1515
/*                   all sub partitions of a macro block                     */
1516
/*                                                                           */
1517
/*  Inputs        : pv_comp_mode_mv_ctxt : motion mode handle                */
1518
/*                  pv_mb_params : pointer to MB params structure            */
1519
/*                  ai4_ref_part_idc : ref partitons idc of all 4x4 blocks   */
1520
/*                  pi4_sub_mb_mode  : pointer to store the sub mb modes     */
1521
/*                  i4_mb_addr       : current mb address                    */
1522
/*                  pi4_intra_flag   : location to store the intra status    */
1523
/*  Globals       : none                                                     */
1524
/*  Processing    : it computes the motion vectors and futher modifictaion is*/
1525
/*                  done for NON -DYAdic cases                               */
1526
/*  Outputs       : inter layer predicted motion vectors and ref indices     */
1527
/*                  sub mbmodes of the 4 mb partitions                       */
1528
/*  Returns       : none                                                     */
1529
/*                                                                           */
1530
/*  Issues        : none                                                     */
1531
/*                                                                           */
1532
/*  Revision History:                                                        */
1533
/*                                                                           */
1534
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1535
/*         06 09 2021   vijayakumar          creation                        */
1536
/*                                                                           */
1537
/*****************************************************************************/
1538
void isvcd_interlyr_motion_submbmode_pred(void *pv_comp_mode_mv_ctxt, void *pv_mb_params,
1539
                                          void *pv_svc_mb_params, WORD32 ai4_ref_part_idc[4][4],
1540
                                          WORD32 *pi4_sub_mb_mode, void *pv_dec)
1541
115k
{
1542
    /*! Flow of the module is as follows                                   */
1543
    /*! 1. if dyadic case it calculates the motion vectors based on dyadic
1544
           scale factor and loop counts calculated at layer level          */
1545
    /*! 2. if non dyadic then it calculates the motion vectors based on
1546
            reference layer part idc                                        */
1547
    /*! 3. does the motion vector modification for non dyayic cases, by
1548
           calculating the minimum positive of reference indices of 4 4x4
1549
           blocks and getiing a single reference index for 8x8             */
1550
    /*! 4. if direct 8x8 inference is present and current slice is
1551
           B OR EB, then it stores the corner motion vectors for each 8x8  */
1552
    /*! 5. does the sub mb mode prediction and merging of motion vectors
1553
           which are closely related by setting appropriate thresholds
1554
           for MVs                                                         */
1555
    /*! 6. stores the sub mb modes in the array given as input             */
1556
1557
115k
    mode_motion_ctxt_t *ps_ctxt;
1558
115k
    mode_motion_lyr_ctxt *ps_lyr_mem;
1559
115k
    mv_pred_t *ps_motion_pred;
1560
115k
    dec_mb_info_t *ps_mb_params;
1561
115k
    dec_svc_mb_info_t *ps_svc_mb_params;
1562
115k
    WORD32 i4_blk_y, i4_blk_x;
1563
115k
    WORD32 i4_i;
1564
115k
    WORD32 i4_listx;
1565
115k
    WORD32 i4_mv_treshold;
1566
115k
    WORD32 ai4_temp_ref_indx[NUM_REF_LISTS][NUM_MB_PARTS] = {0};
1567
115k
    WORD32 i4_mb_x, i4_mb_y;
1568
115k
    WORD32 i4_mb_pic_x, i4_mb_pic_y;
1569
115k
    dec_struct_t *ps_dec;
1570
1571
115k
    ps_dec = (dec_struct_t *) pv_dec;
1572
115k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
1573
1574
    /* get the current layer ctxt */
1575
115k
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
1576
1577
115k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
1578
115k
    ps_svc_mb_params = (dec_svc_mb_info_t *) pv_svc_mb_params;
1579
115k
    ps_motion_pred = ps_ctxt->ps_motion_pred_struct;
1580
1581
115k
    i4_listx = ps_ctxt->i4_listx;
1582
1583
    /* derive the MB_X and MB_Y for the current MB */
1584
115k
    i4_mb_x = ps_mb_params->u2_mbx;
1585
115k
    i4_mb_y = ps_mb_params->u2_mby;
1586
1587
    /* convert into picture units */
1588
115k
    i4_mb_pic_x = i4_mb_x << 4;
1589
115k
    i4_mb_pic_y = i4_mb_y << 4;
1590
1591
    /* compute the motion vectors and reference indices of all part */
1592
576k
    for(i4_blk_y = 0; i4_blk_y < NUM_SUB_MB_PARTS; i4_blk_y++)
1593
461k
    {
1594
2.30M
        for(i4_blk_x = 0; i4_blk_x < NUM_SUB_MB_PARTS; i4_blk_x++)
1595
1.84M
        {
1596
1.84M
            isvcd_interlyr_motion_scale(pv_comp_mode_mv_ctxt, &ai4_ref_part_idc[i4_blk_y][i4_blk_x],
1597
1.84M
                                        ps_mb_params, (ps_motion_pred + (4 * i4_blk_y) + i4_blk_x),
1598
1.84M
                                        i4_listx, (i4_mb_pic_x + (i4_blk_x << 2) + 1),
1599
1.84M
                                        (i4_mb_pic_y + (i4_blk_y << 2) + 1),
1600
1.84M
                                        ps_dec->ppv_map_ref_idx_to_poc);
1601
1602
1.84M
        } /* end of blk x loop */
1603
461k
    }     /* end of blk y loop */
1604
1605
    /********************************************************/
1606
    /* get the final reference index into a temparory array */
1607
    /********************************************************/
1608
1609
    /* set reference indices */
1610
250k
    for(i4_i = 0; i4_i < i4_listx; i4_i++)
1611
135k
    {
1612
135k
        ai4_temp_ref_indx[i4_i][0] = ps_motion_pred[0].i1_ref_frame[i4_i];
1613
135k
        ai4_temp_ref_indx[i4_i][1] = ps_motion_pred[2].i1_ref_frame[i4_i];
1614
135k
        ai4_temp_ref_indx[i4_i][2] = ps_motion_pred[8].i1_ref_frame[i4_i];
1615
135k
        ai4_temp_ref_indx[i4_i][3] = ps_motion_pred[10].i1_ref_frame[i4_i];
1616
1617
135k
    } /* end of loop over lists */
1618
1619
    /* if restricted spatial resolution change is not set */
1620
115k
    if(SVCD_FALSE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag)
1621
115k
    {
1622
115k
        WORD32 i4_xp, i4_yp;
1623
115k
        WORD32 i4_xs, i4_ys;
1624
1625
        /* merge reference indices and modify the motion vectors */
1626
250k
        for(i4_i = 0; i4_i < i4_listx; i4_i++)
1627
135k
        {
1628
405k
            for(i4_yp = 0; i4_yp < 2; i4_yp++)
1629
270k
            {
1630
810k
                for(i4_xp = 0; i4_xp < 2; i4_xp++)
1631
540k
                {
1632
                    /* get the minimum positive of the refernce index */
1633
1.62M
                    for(i4_ys = 0; i4_ys < 2; i4_ys++)
1634
1.08M
                    {
1635
3.24M
                        for(i4_xs = 0; i4_xs < 2; i4_xs++)
1636
2.16M
                        {
1637
2.16M
                            mv_pred_t *ps_temp;
1638
2.16M
                            ps_temp = ps_motion_pred + (i4_xp << 1) + i4_xs;
1639
2.16M
                            ps_temp += 4 * ((i4_yp << 1) + i4_ys);
1640
1641
                            /* get the minimum positive */
1642
2.16M
                            ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp] =
1643
2.16M
                                isvcd_get_min_positive(ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp],
1644
2.16M
                                                       ps_temp->i1_ref_frame[i4_i]);
1645
2.16M
                        }
1646
1.08M
                    }
1647
                    /* update motion vectors */
1648
1.62M
                    for(i4_ys = 0; i4_ys < 2; i4_ys++)
1649
1.08M
                    {
1650
3.24M
                        for(i4_xs = 0; i4_xs < 2; i4_xs++)
1651
2.16M
                        {
1652
2.16M
                            mv_pred_t *ps_temp;
1653
2.16M
                            ps_temp = ps_motion_pred + (i4_xp << 1) + i4_xs;
1654
2.16M
                            ps_temp += 4 * ((i4_yp << 1) + i4_ys);
1655
1656
                            /* check if the current part reference index is */
1657
                            /* not choosen as the final reference index */
1658
                            /* if not copy the neighbours MV */
1659
2.16M
                            if(ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp] !=
1660
2.16M
                               ps_temp->i1_ref_frame[i4_i])
1661
12.2k
                            {
1662
12.2k
                                mv_pred_t *ps_temp_1;
1663
12.2k
                                WORD32 i4_updated_flag = SVCD_FALSE;
1664
1665
12.2k
                                ps_temp_1 = ps_motion_pred + (i4_xp << 1) + (1 - i4_xs);
1666
12.2k
                                ps_temp_1 += 4 * ((i4_yp << 1) + i4_ys);
1667
1668
                                /* store the appropriate neighbours */
1669
12.2k
                                if(ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp] ==
1670
12.2k
                                   ps_temp_1->i1_ref_frame[i4_i])
1671
3.80k
                                {
1672
3.80k
                                    ps_temp->i2_mv[2 * i4_i] = ps_temp_1->i2_mv[2 * i4_i];
1673
1674
3.80k
                                    ps_temp->i2_mv[1 + (2 * i4_i)] =
1675
3.80k
                                        ps_temp_1->i2_mv[1 + (2 * i4_i)];
1676
3.80k
                                    i4_updated_flag = SVCD_TRUE;
1677
3.80k
                                }
1678
1679
12.2k
                                if(SVCD_FALSE == i4_updated_flag)
1680
8.41k
                                {
1681
8.41k
                                    ps_temp_1 = ps_motion_pred + (i4_xp << 1) + i4_xs;
1682
1683
8.41k
                                    ps_temp_1 += 4 * ((i4_yp << 1) + 1 - i4_ys);
1684
1685
8.41k
                                    if(ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp] ==
1686
8.41k
                                       ps_temp_1->i1_ref_frame[i4_i])
1687
8.19k
                                    {
1688
8.19k
                                        ps_temp->i2_mv[2 * i4_i] = ps_temp_1->i2_mv[2 * i4_i];
1689
1690
8.19k
                                        ps_temp->i2_mv[1 + (2 * i4_i)] =
1691
8.19k
                                            ps_temp_1->i2_mv[1 + (2 * i4_i)];
1692
8.19k
                                        i4_updated_flag = SVCD_TRUE;
1693
8.19k
                                    }
1694
8.41k
                                }
1695
12.2k
                                if(SVCD_FALSE == i4_updated_flag)
1696
218
                                {
1697
218
                                    ps_temp_1 = ps_motion_pred + (i4_xp << 1) + (1 - i4_xs);
1698
218
                                    ps_temp_1 += 4 * ((i4_yp << 1) + 1 - i4_ys);
1699
1700
218
                                    ps_temp->i2_mv[2 * i4_i] = ps_temp_1->i2_mv[2 * i4_i];
1701
1702
218
                                    ps_temp->i2_mv[1 + (2 * i4_i)] =
1703
218
                                        ps_temp_1->i2_mv[1 + (2 * i4_i)];
1704
1705
218
                                    i4_updated_flag = SVCD_TRUE;
1706
218
                                }
1707
12.2k
                            } /* end of replacement of mv based on ref indx */
1708
2.16M
                        }     /* end of loop over sub partition xs */
1709
1.08M
                    }         /* end of loop over sub partition ys */
1710
540k
                }             /* end of loop over partition xp */
1711
270k
            }                 /* end of loop over partition yp */
1712
135k
        }                     /* end of loop over lists */
1713
115k
    }
1714
1715
    /************************************************************************/
1716
    /* if restircted saptial resolution change flag is 0                    */
1717
    /* modify the reference indixes and motion vectors                      */
1718
    /************************************************************************/
1719
115k
    if((SVCD_FALSE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag) &&
1720
115k
       (2 == i4_listx) && (SVCD_TRUE == ps_ctxt->u1_direct_8x8_inference_flag))
1721
5.32k
    {
1722
        /* only applicable for EB Slice */
1723
        /* store the corner 4x4 motion vectors to the whole block */
1724
        /* 2 lists and 4 partitions */
1725
5.32k
        mot_vec_t s_temp_mv[2][4];
1726
5.32k
        WORD32 i4_xp, i4_yp;
1727
5.32k
        memset(&s_temp_mv[0][0], 0, sizeof(s_temp_mv));
1728
1729
15.9k
        for(i4_i = 0; i4_i < i4_listx; i4_i++)
1730
10.6k
        {
1731
10.6k
            s_temp_mv[i4_i][0].i2_mv_x = ps_motion_pred[0].i2_mv[2 * i4_i];
1732
10.6k
            s_temp_mv[i4_i][0].i2_mv_y = ps_motion_pred[0].i2_mv[1 + (2 * i4_i)];
1733
1734
10.6k
            s_temp_mv[i4_i][1].i2_mv_x = ps_motion_pred[3].i2_mv[2 * i4_i];
1735
10.6k
            s_temp_mv[i4_i][1].i2_mv_y = ps_motion_pred[3].i2_mv[1 + (2 * i4_i)];
1736
1737
10.6k
            s_temp_mv[i4_i][2].i2_mv_x = ps_motion_pred[12].i2_mv[2 * i4_i];
1738
10.6k
            s_temp_mv[i4_i][2].i2_mv_y = ps_motion_pred[12].i2_mv[1 + (2 * i4_i)];
1739
1740
10.6k
            s_temp_mv[i4_i][3].i2_mv_x = ps_motion_pred[15].i2_mv[2 * i4_i];
1741
10.6k
            s_temp_mv[i4_i][3].i2_mv_y = ps_motion_pred[15].i2_mv[1 + (2 * i4_i)];
1742
1743
10.6k
        } /* end of loop over lists */
1744
1745
        /* replace the motion vectors */
1746
15.9k
        for(i4_i = 0; i4_i < i4_listx; i4_i++)
1747
10.6k
        {
1748
53.2k
            for(i4_yp = 0; i4_yp < 4; i4_yp++)
1749
42.6k
            {
1750
213k
                for(i4_xp = 0; i4_xp < 4; i4_xp++)
1751
170k
                {
1752
170k
                    mv_pred_t *ps_temp;
1753
170k
                    ps_temp = ps_motion_pred + i4_xp;
1754
170k
                    ps_temp += 4 * i4_yp;
1755
1756
170k
                    ps_temp->i2_mv[2 * i4_i] =
1757
170k
                        s_temp_mv[i4_i][2 * (i4_yp >> 1) + (i4_xp >> 1)].i2_mv_x;
1758
1759
170k
                    ps_temp->i2_mv[1 + (2 * i4_i)] =
1760
170k
                        s_temp_mv[i4_i][2 * (i4_yp >> 1) + (i4_xp >> 1)].i2_mv_y;
1761
1762
170k
                } /* end of loop over sub partitions xp */
1763
42.6k
            }     /* end of loop over sub partitions yp */
1764
10.6k
        }         /* end of loop over lists */
1765
5.32k
    }
1766
1767
    /* store the final reference index for all sub partitions */
1768
    /* approporiate reference index is stored for each 4x4 belonging to 8x8 */
1769
115k
    {
1770
115k
        WORD32 i4_xp, i4_yp;
1771
1772
250k
        for(i4_i = 0; i4_i < i4_listx; i4_i++)
1773
135k
        {
1774
675k
            for(i4_yp = 0; i4_yp < 4; i4_yp++)
1775
540k
            {
1776
2.70M
                for(i4_xp = 0; i4_xp < 4; i4_xp++)
1777
2.16M
                {
1778
2.16M
                    mv_pred_t *ps_temp;
1779
2.16M
                    ps_temp = ps_motion_pred + i4_xp;
1780
2.16M
                    ps_temp += 4 * i4_yp;
1781
1782
2.16M
                    ps_temp->i1_ref_frame[i4_i] =
1783
2.16M
                        ai4_temp_ref_indx[i4_i][2 * (i4_yp >> 1) + (i4_xp >> 1)];
1784
1785
2.16M
                } /* end of loop over partition xp */
1786
540k
            }     /* end of loop over partition yp */
1787
135k
        }         /* end of loop over lists */
1788
115k
    }
1789
1790
    /********************************************************************/
1791
    /* modify the motion vectors for non dyadic cases, set the mv       */
1792
    /* threshold appropraitely to derive the sub MB type                */
1793
    /********************************************************************/
1794
115k
    if(SVCD_FALSE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag)
1795
115k
    {
1796
        /* non dyadic cases set the mv treshold to 1 */
1797
115k
        i4_mv_treshold = 1;
1798
115k
    }
1799
0
    else
1800
0
    {
1801
        /* dyadic cases set the mv treshold to 0 */
1802
0
        i4_mv_treshold = 0;
1803
0
    }
1804
1805
    /* modify the motion vectors and get sub mb mode if base mode flag is 1 */
1806
115k
    if((SVCD_FALSE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag) ||
1807
115k
       (1 == ps_svc_mb_params->u1_base_mode_flag))
1808
115k
    {
1809
115k
        WORD32 i4_xp, i4_yp;
1810
345k
        for(i4_yp = 0; i4_yp < 2; i4_yp++)
1811
230k
        {
1812
691k
            for(i4_xp = 0; i4_xp < 2; i4_xp++)
1813
461k
            {
1814
461k
                mv_pred_t *ps_temp;
1815
461k
                WORD32 i4_part_size = 0;
1816
461k
                WORD32 i4_horz1_match, i4_vert1_match;
1817
461k
                WORD32 i4_horz2_match, i4_vert2_match;
1818
461k
                WORD32 i4_diag_match;
1819
1820
461k
                WORD32 i4_8x8_match, i4_horz_match, i4_vert_match;
1821
461k
                WORD32 i4_mv_x, i4_mv_y;
1822
1823
461k
                ps_temp = ps_motion_pred + (i4_xp << 1);
1824
461k
                ps_temp += 4 * ((i4_yp << 1));
1825
1826
                /* default init */
1827
461k
                i4_8x8_match = i4_horz_match = i4_vert_match = SVCD_TRUE;
1828
1829
                /* check if the mv diff in horz direction is under threshold*/
1830
461k
                i4_horz1_match =
1831
461k
                    isvcd_check_mv_diff(ps_temp, (ps_temp + 1), i4_listx, i4_mv_treshold);
1832
1833
461k
                i4_horz2_match =
1834
461k
                    isvcd_check_mv_diff((ps_temp + 4), (ps_temp + 4 + 1), i4_listx, i4_mv_treshold);
1835
1836
                /* check if the mv diff in horz direction is under threshold*/
1837
461k
                i4_vert1_match =
1838
461k
                    isvcd_check_mv_diff(ps_temp, (ps_temp + 4), i4_listx, i4_mv_treshold);
1839
1840
461k
                i4_vert2_match =
1841
461k
                    isvcd_check_mv_diff((ps_temp + 1), (ps_temp + 4 + 1), i4_listx, i4_mv_treshold);
1842
1843
                /* check if in diagonal direction is under threshold*/
1844
461k
                i4_diag_match =
1845
461k
                    isvcd_check_mv_diff(ps_temp, (ps_temp + 4 + 1), i4_listx, i4_mv_treshold);
1846
1847
                /* calculate the excat matching points*/
1848
461k
                i4_8x8_match = i4_8x8_match && i4_horz1_match && i4_vert1_match && i4_diag_match;
1849
461k
                i4_horz_match = i4_horz_match && i4_horz1_match && i4_horz2_match;
1850
461k
                i4_vert_match = i4_vert_match && i4_vert1_match && i4_vert2_match;
1851
1852
                /* modify the motion vectors appropriately */
1853
1854
1.00M
                for(i4_i = 0; i4_i < i4_listx; i4_i++)
1855
540k
                {
1856
                    /* 8x8 mode all the 4 blocks are under threshold */
1857
540k
                    if(SVCD_TRUE == i4_8x8_match)
1858
524k
                    {
1859
                        /* calculate the avarage */
1860
524k
                        i4_mv_x =
1861
524k
                            ((ps_temp[0].i2_mv[2 * i4_i]) + (ps_temp[1].i2_mv[2 * i4_i]) +
1862
524k
                             (ps_temp[4].i2_mv[2 * i4_i]) + (ps_temp[5].i2_mv[2 * i4_i] + 2)) >>
1863
524k
                            2;
1864
1865
524k
                        i4_mv_y = ((ps_temp[0].i2_mv[1 + (2 * i4_i)]) +
1866
524k
                                   (ps_temp[1].i2_mv[1 + (2 * i4_i)]) +
1867
524k
                                   (ps_temp[4].i2_mv[1 + (2 * i4_i)]) +
1868
524k
                                   (ps_temp[5].i2_mv[1 + (2 * i4_i)] + 2)) >>
1869
524k
                                  2;
1870
1871
                        /* store the modified motion vectors */
1872
524k
                        ps_temp[0].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1873
524k
                        ps_temp[1].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1874
524k
                        ps_temp[4].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1875
524k
                        ps_temp[5].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1876
1877
524k
                        ps_temp[0].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1878
524k
                        ps_temp[1].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1879
524k
                        ps_temp[4].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1880
524k
                        ps_temp[5].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1881
1882
                        /* store the sub mb partition size */
1883
524k
                        i4_part_size = SUBMB_8x8;
1884
524k
                    }
1885
                    /* 8x4 mode  */
1886
16.0k
                    else if(SVCD_TRUE == i4_horz_match)
1887
7.37k
                    {
1888
                        /* horizontal directional merging */
1889
                        /* calculate the average of first two and store back*/
1890
7.37k
                        i4_mv_x =
1891
7.37k
                            ((ps_temp[0].i2_mv[2 * i4_i]) + (ps_temp[1].i2_mv[2 * i4_i] + 1)) >> 1;
1892
1893
7.37k
                        i4_mv_y = ((ps_temp[0].i2_mv[1 + (2 * i4_i)]) +
1894
7.37k
                                   (ps_temp[1].i2_mv[1 + (2 * i4_i)] + 1)) >>
1895
7.37k
                                  1;
1896
1897
7.37k
                        ps_temp[0].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1898
7.37k
                        ps_temp[1].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1899
1900
7.37k
                        ps_temp[0].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1901
7.37k
                        ps_temp[1].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1902
1903
                        /* calculate the average of next two and store back*/
1904
7.37k
                        i4_mv_x =
1905
7.37k
                            ((ps_temp[4].i2_mv[2 * i4_i]) + (ps_temp[5].i2_mv[2 * i4_i] + 1)) >> 1;
1906
1907
7.37k
                        i4_mv_y = ((ps_temp[4].i2_mv[1 + (2 * i4_i)]) +
1908
7.37k
                                   (ps_temp[5].i2_mv[1 + (2 * i4_i)] + 1)) >>
1909
7.37k
                                  1;
1910
1911
7.37k
                        ps_temp[4].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1912
7.37k
                        ps_temp[5].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1913
1914
7.37k
                        ps_temp[4].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1915
7.37k
                        ps_temp[5].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1916
                        /* store the sub mb partition size */
1917
7.37k
                        i4_part_size = SUBMB_8x4;
1918
7.37k
                    }
1919
                    /* 4x8 mode all the 4 blocks are under threshold */
1920
8.67k
                    else if(SVCD_TRUE == i4_vert_match)
1921
7.70k
                    {
1922
                        /* vertical directional merging */
1923
7.70k
                        i4_mv_x =
1924
7.70k
                            ((ps_temp[0].i2_mv[2 * i4_i]) + (ps_temp[4].i2_mv[2 * i4_i] + 1)) >> 1;
1925
1926
7.70k
                        i4_mv_y = ((ps_temp[0].i2_mv[1 + (2 * i4_i)]) +
1927
7.70k
                                   (ps_temp[4].i2_mv[1 + (2 * i4_i)] + 1)) >>
1928
7.70k
                                  1;
1929
1930
7.70k
                        ps_temp[0].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1931
7.70k
                        ps_temp[4].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1932
1933
7.70k
                        ps_temp[0].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1934
7.70k
                        ps_temp[4].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1935
1936
                        /* calculate the average of next two and store back*/
1937
7.70k
                        i4_mv_x =
1938
7.70k
                            ((ps_temp[1].i2_mv[2 * i4_i]) + (ps_temp[5].i2_mv[2 * i4_i] + 1)) >> 1;
1939
1940
7.70k
                        i4_mv_y = ((ps_temp[1].i2_mv[1 + (2 * i4_i)]) +
1941
7.70k
                                   (ps_temp[5].i2_mv[1 + (2 * i4_i)] + 1)) >>
1942
7.70k
                                  1;
1943
1944
7.70k
                        ps_temp[1].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1945
7.70k
                        ps_temp[5].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1946
1947
7.70k
                        ps_temp[1].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1948
7.70k
                        ps_temp[5].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1949
                        /* store the sub mb partition size */
1950
7.70k
                        i4_part_size = SUBMB_4x8;
1951
7.70k
                    }
1952
966
                    else
1953
966
                    {
1954
                        /* store the sub mb partition size */
1955
966
                        i4_part_size = SUBMB_4x4;
1956
966
                    }
1957
1958
540k
                } /* end of loop over lists */
1959
1960
                /* store the sub MB type B slice */
1961
461k
                if(2 == i4_listx)
1962
79.4k
                {
1963
79.4k
                    WORD32 i4_part_mode_a;
1964
79.4k
                    WORD32 i4_indx;
1965
1966
79.4k
                    i4_part_mode_a = 0;
1967
                    /* check the 0th partiton reference indices */
1968
79.4k
                    if(0 <= ps_temp[0].i1_ref_frame[0])
1969
68.5k
                    {
1970
68.5k
                        i4_part_mode_a += 1;
1971
68.5k
                    }
1972
79.4k
                    if(0 <= ps_temp[0].i1_ref_frame[1])
1973
33.5k
                    {
1974
33.5k
                        i4_part_mode_a += 2;
1975
33.5k
                    }
1976
79.4k
                    i4_indx = 3 * i4_part_size + (i4_part_mode_a - 1);
1977
1978
79.4k
                    pi4_sub_mb_mode[2 * i4_yp + i4_xp] = g_au1_eb_submb_type[i4_indx];
1979
79.4k
                }
1980
                /* P slice */
1981
381k
                else
1982
381k
                {
1983
381k
                    pi4_sub_mb_mode[2 * i4_yp + i4_xp] = g_au1_ep_submb_type[i4_part_size];
1984
381k
                }
1985
461k
            } /* end of loop over partition xp */
1986
1987
230k
        }     /* end of loop over partition yp */
1988
115k
    }
1989
1990
115k
    return;
1991
115k
}
1992
1993
/*****************************************************************************/
1994
/*                                                                           */
1995
/*  Function Name : isvcd_interlyr_mbmode_pred_bmb                          */
1996
/*                                                                           */
1997
/*  Description   : this module does the mode predcition for base mode B_MB  */
1998
/*                                                                           */
1999
/*                                                                           */
2000
/*  Inputs        : pv_comp_mode_mv_ctxt : motion mode hanldle               */
2001
/*  Globals       : none                                                     */
2002
/*  Processing    : it checks the sub MB type derived motion prediction. if  */
2003
/*                  all partitions are 8x8 then it goes further matching     */
2004
/*                  finally it stores the MB type using a look up table      */
2005
/*  Outputs       : none                                                     */
2006
/*  Returns       : none                                                     */
2007
/*                                                                           */
2008
/*  Issues        : none                                                     */
2009
/*                                                                           */
2010
/*  Revision History:                                                        */
2011
/*                                                                           */
2012
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2013
/*         06 09 2021   vijayakumar          creation                        */
2014
/*                                                                           */
2015
/*****************************************************************************/
2016
void isvcd_interlyr_mbmode_pred_bmb(mode_motion_ctxt_t *ps_ctxt, mv_pred_t *ps_motion_pred,
2017
                                    WORD32 i4_cur_mot_stride, WORD32 i4_part_size,
2018
                                    WORD32 *pi4_sub_mb_mode, void *pv_mb_params, void *pv_part,
2019
                                    UWORD8 *pu1_col_info)
2020
30.2k
{
2021
30.2k
    WORD32 i4_part_mode_a, i4_part_mode_b;
2022
30.2k
    WORD32 i4_idx;
2023
30.2k
    dec_mb_info_t *ps_mb_params = (dec_mb_info_t *) pv_mb_params;
2024
30.2k
    parse_part_params_t *ps_part = (parse_part_params_t *) pv_part;
2025
2026
30.2k
    UNUSED(ps_ctxt);
2027
2028
30.2k
    i4_part_mode_a = 0;
2029
2030
    /* check the 0th partiton reference indices */
2031
30.2k
    if(PRED_8x8 != i4_part_size)
2032
24.8k
    {
2033
24.8k
        if(0 <= ps_motion_pred[0].i1_ref_frame[0])
2034
22.3k
        {
2035
22.3k
            i4_part_mode_a += 1;
2036
22.3k
        }
2037
24.8k
        if(0 <= ps_motion_pred[0].i1_ref_frame[1])
2038
9.74k
        {
2039
9.74k
            i4_part_mode_a += 2;
2040
9.74k
        }
2041
24.8k
    }
2042
2043
    /* check the 15th partiton reference indices */
2044
    /* this done since all the reference indices will be replicated */
2045
30.2k
    i4_part_mode_b = 0;
2046
2047
30.2k
    if((PRED_16x8 == i4_part_size) || (PRED_8x16 == i4_part_size))
2048
5.51k
    {
2049
5.51k
        ps_motion_pred += (3 * i4_cur_mot_stride) + 3;
2050
2051
5.51k
        if(0 <= ps_motion_pred[0].i1_ref_frame[0])
2052
4.64k
        {
2053
4.64k
            i4_part_mode_b += 1;
2054
4.64k
        }
2055
5.51k
        if(0 <= ps_motion_pred[0].i1_ref_frame[1])
2056
1.60k
        {
2057
1.60k
            i4_part_mode_b += 2;
2058
1.60k
        }
2059
5.51k
    }
2060
    /* update the pred modes for B cases */
2061
    /* If partition size is not equal to 8x8 */
2062
    /* then update the prediciton mode of    */
2063
    /* partitions                            */
2064
30.2k
    if(PRED_8x8 != i4_part_size)
2065
24.8k
    {
2066
24.8k
        UWORD8 u1_pred_mode_part0;
2067
24.8k
        UWORD8 u1_pred_mode_part1;
2068
2069
24.8k
        i4_idx = 3 * i4_part_size;
2070
24.8k
        i4_idx += 3 * (i4_part_mode_a - 1);
2071
24.8k
        i4_part_mode_b = (i4_part_mode_b > 0) ? i4_part_mode_b : 1;
2072
24.8k
        i4_idx += (i4_part_mode_b - 1);
2073
24.8k
        i4_idx = (i4_idx < 0) ? 0 : i4_idx;
2074
        /* Get the mb type                     */
2075
        /* From mb type - get prediciton modes */
2076
        /*  of parttions                       */
2077
        /* Update the prediciton mode parma of */
2078
        /* mb param structure                  */
2079
2080
24.8k
        ps_mb_params->u1_mb_type = g_au1_eb_mb_type[i4_idx + (6 * i4_part_size)];
2081
24.8k
        u1_pred_mode_part0 = g_au1_mb_pred_mode[0][5 + ps_mb_params->u1_mb_type];
2082
24.8k
        u1_pred_mode_part1 = g_au1_mb_pred_mode[1][5 + ps_mb_params->u1_mb_type];
2083
24.8k
        ps_part[0].u1_pred_mode = u1_pred_mode_part0;
2084
24.8k
        ps_part[1].u1_pred_mode = u1_pred_mode_part1;
2085
24.8k
    }
2086
5.35k
    else
2087
5.35k
    {
2088
5.35k
        WORD32 i4_i, i4_ctr, i4_num_submb_part;
2089
5.35k
        UWORD8 u1_sub_mb_type, u1_sub_mb_mc_mode;
2090
5.35k
        UWORD8 u1_pred_mode;
2091
2092
5.35k
        ps_mb_params->u1_mb_type = B_8x8;
2093
2094
26.7k
        for(i4_i = 0; i4_i < NUM_MB_PARTS; i4_i++)
2095
21.4k
        {
2096
21.4k
            u1_sub_mb_type = (UWORD8) pi4_sub_mb_mode[i4_i];
2097
2098
21.4k
            u1_sub_mb_mc_mode = gau1_ih264d_submb_mc_mode[4 + u1_sub_mb_type];
2099
21.4k
            i4_num_submb_part = g_au1_num_sub_mb_part[u1_sub_mb_mc_mode];
2100
21.4k
            *pu1_col_info |= (u1_sub_mb_mc_mode << 4);
2101
21.4k
            pu1_col_info++;
2102
21.4k
            u1_pred_mode = g_au1_sub_mb_pred_mode[4 + u1_sub_mb_type];
2103
62.0k
            for(i4_ctr = 0; i4_ctr < i4_num_submb_part; i4_ctr++)
2104
40.6k
            {
2105
40.6k
                ps_part->u1_pred_mode = u1_pred_mode;
2106
40.6k
                ps_part++;
2107
40.6k
            }
2108
21.4k
        }
2109
5.35k
    }
2110
2111
30.2k
    return;
2112
30.2k
}
2113
2114
/*****************************************************************************/
2115
/*                                                                           */
2116
/*  Function Name : isvcd_populate_ref_idx                                    */
2117
/*                                                                           */
2118
/*  Description   : this module populates the reference idx based on the     */
2119
/*                  motion prediction flags                                  */
2120
/*                                                                           */
2121
/*  Inputs        :                                                          */
2122
/*  Globals       : none                                                     */
2123
/*  Processing    :                                                          */
2124
/*  Outputs       : none                                                     */
2125
/*  Returns       : none                                                     */
2126
/*                                                                           */
2127
/*  Issues        : none                                                     */
2128
/*                                                                           */
2129
/*  Revision History:                                                        */
2130
/*                                                                           */
2131
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2132
/*         06 09 2021   vijayakumar          creation                        */
2133
/*                                                                           */
2134
/*****************************************************************************/
2135
2136
void isvcd_populate_ref_idx(dec_mb_info_t *ps_mb_params, dec_svc_mb_info_t *ps_svc_mb_params,
2137
                            mv_pred_t *ps_motion_pred, parse_pmbarams_t *ps_mb_part_info,
2138
                            WORD32 i4_listx)
2139
27.3k
{
2140
27.3k
    UWORD8 u1_mot_pred_flag;
2141
27.3k
    WORD32 i4_lx;
2142
2143
66.5k
    for(i4_lx = 0; i4_lx < i4_listx; i4_lx++)
2144
39.2k
    {
2145
39.2k
        u1_mot_pred_flag = ps_svc_mb_params->au1_motion_pred_flag[i4_lx];
2146
2147
39.2k
        if((PRED_16x16 == ps_mb_params->u1_mb_mc_mode) && (u1_mot_pred_flag & 0x1))
2148
12.4k
        {
2149
12.4k
            ps_mb_part_info->i1_ref_idx[i4_lx][0] = ps_motion_pred[0].i1_ref_frame[i4_lx];
2150
12.4k
        }
2151
26.7k
        else if((PRED_8x16 == ps_mb_params->u1_mb_mc_mode))
2152
9.37k
        {
2153
9.37k
            if(u1_mot_pred_flag & 0x01)
2154
2.93k
            {
2155
2.93k
                ps_mb_part_info->i1_ref_idx[i4_lx][0] = ps_motion_pred[0].i1_ref_frame[i4_lx];
2156
2.93k
            }
2157
9.37k
            if(u1_mot_pred_flag & 0x02)
2158
5.31k
            {
2159
5.31k
                ps_mb_part_info->i1_ref_idx[i4_lx][1] = ps_motion_pred[2].i1_ref_frame[i4_lx];
2160
5.31k
            }
2161
9.37k
        }
2162
17.3k
        else if((PRED_16x8 == ps_mb_params->u1_mb_mc_mode))
2163
5.47k
        {
2164
5.47k
            if(u1_mot_pred_flag & 0x01)
2165
3.66k
            {
2166
3.66k
                ps_mb_part_info->i1_ref_idx[i4_lx][0] = ps_motion_pred[0].i1_ref_frame[i4_lx];
2167
3.66k
            }
2168
5.47k
            if(u1_mot_pred_flag & 0x02)
2169
3.93k
            {
2170
3.93k
                ps_mb_part_info->i1_ref_idx[i4_lx][1] = ps_motion_pred[8].i1_ref_frame[i4_lx];
2171
3.93k
            }
2172
5.47k
        }
2173
11.9k
        else if((PRED_8x8 == ps_mb_params->u1_mb_mc_mode))
2174
7.79k
        {
2175
7.79k
            if(u1_mot_pred_flag & 0x01)
2176
3.41k
            {
2177
3.41k
                ps_mb_part_info->i1_ref_idx[i4_lx][0] = ps_motion_pred[0].i1_ref_frame[i4_lx];
2178
3.41k
            }
2179
7.79k
            if(u1_mot_pred_flag & 0x02)
2180
3.33k
            {
2181
3.33k
                ps_mb_part_info->i1_ref_idx[i4_lx][1] = ps_motion_pred[2].i1_ref_frame[i4_lx];
2182
3.33k
            }
2183
7.79k
            if(u1_mot_pred_flag & 0x04)
2184
3.99k
            {
2185
3.99k
                ps_mb_part_info->i1_ref_idx[i4_lx][2] = ps_motion_pred[8].i1_ref_frame[i4_lx];
2186
3.99k
            }
2187
7.79k
            if(u1_mot_pred_flag & 0x08)
2188
3.38k
            {
2189
3.38k
                ps_mb_part_info->i1_ref_idx[i4_lx][3] = ps_motion_pred[10].i1_ref_frame[i4_lx];
2190
3.38k
            }
2191
7.79k
        }
2192
39.2k
    }
2193
27.3k
}
2194
2195
/*****************************************************************************/
2196
/*                                                                           */
2197
/*  Function Name : svcd_interlayer_mbmode_pred                              */
2198
/*                                                                           */
2199
/*  Description   : this module does the mode predcition for base mode MB    */
2200
/*                                                                           */
2201
/*                                                                           */
2202
/*  Inputs        : pv_comp_mode_mv_ctxt : motion mode hanldle               */
2203
/*                  pv_mb_params   : pointer to MB params structure          */
2204
/*                  pi4_sub_mb_mode: pointer to sub mbmodes predicted        */
2205
/*  Globals       : none                                                     */
2206
/*  Processing    : it checks the sub MB type derived motion prediction. if  */
2207
/*                  all partitions are 8x8 then it goes further matching     */
2208
/*                  finally it stores the MB type using a look up table      */
2209
/*  Outputs       : none                                                     */
2210
/*  Returns       : none                                                     */
2211
/*                                                                           */
2212
/*  Issues        : none                                                     */
2213
/*                                                                           */
2214
/*  Revision History:                                                        */
2215
/*                                                                           */
2216
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2217
/*         06 09 2021   vijayakumar          creation                        */
2218
/*                                                                           */
2219
/*****************************************************************************/
2220
void isvcd_interlyr_mbmode_pred(void *pv_comp_mode_mv_ctxt, void *pv_mb_params,
2221
                                WORD32 *pi4_sub_mb_mode, WORD32 *pi4_mb_mode, void *pv_dec,
2222
                                void *pv_mb_part_info, void *pv_part)
2223
105k
{
2224
    /*! Flow of the module is as follows                                   */
2225
    /*! 1. it checks if all the sub mb modes are 8x8 modes                 */
2226
    /*! 2. it matches the motion vectors at 8x8 level and computes the
2227
           partiton size. store the same in the part type of mb params     */
2228
    /*! 3. stores the pred modes based on slcie type and reference indices */
2229
    /*! 4. stores the sub mb type in the mb params if teh part size is 8x8 */
2230
105k
    mode_motion_ctxt_t *ps_ctxt;
2231
105k
    mv_pred_t *ps_motion_pred;
2232
105k
    dec_mb_info_t *ps_mb_params;
2233
105k
    WORD32 i4_listx;
2234
105k
    WORD32 i4_part_size;
2235
105k
    WORD32 i4_mb_mode_flag;
2236
105k
    WORD32 i4_i;
2237
105k
    WORD32 i4_blk_mode;
2238
105k
    parse_part_params_t *ps_part = (parse_part_params_t *) pv_part;
2239
105k
    parse_pmbarams_t *ps_mb_part_info = (parse_pmbarams_t *) pv_mb_part_info;
2240
105k
    UWORD8 *pu1_col_info = ps_mb_part_info->u1_col_info;
2241
105k
    UNUSED(pv_dec);
2242
2243
105k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
2244
105k
    ps_motion_pred = ps_ctxt->ps_motion_pred_struct;
2245
105k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
2246
2247
    /*********** store the MB mode as inter *************************/
2248
105k
    *pi4_mb_mode = SVC_INTER_MB;
2249
2250
    /***********************************************************************/
2251
    /* derivation of part type                                             */
2252
    /***********************************************************************/
2253
105k
    i4_listx = ps_ctxt->i4_listx;
2254
2255
    /* set the mb mode derivation flag to false */
2256
105k
    i4_mb_mode_flag = SVCD_FALSE;
2257
2258
    /* for B and P slice different blk mod treshold */
2259
105k
    if(2 == i4_listx)
2260
16.4k
    {
2261
16.4k
        i4_blk_mode = B_BI_8x8;
2262
16.4k
    }
2263
89.4k
    else
2264
89.4k
    {
2265
89.4k
        i4_blk_mode = P_L0_8x8;
2266
89.4k
    }
2267
2268
    /* set the mode derivation flag to true base on conditions */
2269
105k
    if((i4_blk_mode >= pi4_sub_mb_mode[0]) && (i4_blk_mode >= pi4_sub_mb_mode[1]) &&
2270
105k
       (i4_blk_mode >= pi4_sub_mb_mode[2]) && (i4_blk_mode >= pi4_sub_mb_mode[3]))
2271
97.9k
    {
2272
97.9k
        i4_mb_mode_flag = SVCD_TRUE;
2273
97.9k
    }
2274
2275
    /* store the default 8x8 mode */
2276
105k
    ps_mb_part_info->u1_num_part = 4;
2277
105k
    i4_part_size = PRED_8x8;
2278
2279
    /* further check is present if all are 8x8 mode */
2280
105k
    if(SVCD_TRUE == i4_mb_mode_flag)
2281
97.9k
    {
2282
97.9k
        WORD32 i4_horz_match, i4_vert_match;
2283
2284
        /* check if the motion in horz direction are same*/
2285
97.9k
        i4_horz_match = isvcd_check_motion(ps_motion_pred, (ps_motion_pred + 2), i4_listx);
2286
97.9k
        i4_horz_match += isvcd_check_motion((ps_motion_pred + 8), (ps_motion_pred + 10), i4_listx);
2287
2288
        /* check if the motion in vertical direction is same */
2289
97.9k
        i4_vert_match = isvcd_check_motion(ps_motion_pred, (ps_motion_pred + 8), i4_listx);
2290
97.9k
        i4_vert_match += isvcd_check_motion((ps_motion_pred + 2), (ps_motion_pred + 10), i4_listx);
2291
2292
        /* decide the partition size based on the results of matching */
2293
97.9k
        if((2 == i4_horz_match) && (2 == i4_vert_match))
2294
82.1k
        {
2295
82.1k
            ps_mb_params->u1_mb_type = P_L0_16x16;
2296
82.1k
            i4_part_size = PRED_16x16;
2297
82.1k
            ps_mb_part_info->u1_num_part = 1;
2298
82.1k
            *pu1_col_info++ = (PRED_16x16 << 6);
2299
82.1k
            ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2300
82.1k
            if(2 == i4_listx) ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2301
2302
82.1k
            ps_part->u1_partwidth = 4;  // interms of 4x4
2303
82.1k
            ps_part->u1_partheight = 4;
2304
82.1k
            ps_part->u1_pred_mode = PRED_L0;
2305
82.1k
            ps_part->u1_is_direct = 0;
2306
82.1k
            ps_part->u1_sub_mb_num = 0;
2307
82.1k
        }
2308
15.7k
        else if(2 == i4_horz_match)
2309
6.40k
        {
2310
6.40k
            i4_part_size = PRED_16x8;
2311
6.40k
            ps_mb_params->u1_mb_type = P_L0_L0_16x8;
2312
6.40k
            ps_mb_part_info->u1_num_part = 2;
2313
6.40k
            *pu1_col_info++ = (PRED_16x8 << 6);
2314
6.40k
            *pu1_col_info++ = (PRED_16x8 << 6);
2315
2316
6.40k
            ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2317
6.40k
            ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[8].i1_ref_frame[0];
2318
6.40k
            if(2 == i4_listx)
2319
3.39k
            {
2320
3.39k
                ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2321
3.39k
                ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[8].i1_ref_frame[1];
2322
3.39k
            }
2323
6.40k
            ps_part->u1_partwidth = 4;  // interms of 4x4
2324
6.40k
            ps_part->u1_partheight = 2;
2325
6.40k
            ps_part->u1_pred_mode = PRED_L0;
2326
6.40k
            ps_part->u1_is_direct = 0;
2327
6.40k
            ps_part->u1_sub_mb_num = 0;
2328
2329
6.40k
            ps_part++;
2330
6.40k
            ps_part->u1_partwidth = 4;
2331
6.40k
            ps_part->u1_partheight = 2;
2332
6.40k
            ps_part->u1_pred_mode = PRED_L0;
2333
6.40k
            ps_part->u1_is_direct = 0;
2334
6.40k
            ps_part->u1_sub_mb_num = 8;
2335
6.40k
        }
2336
9.35k
        else if(2 == i4_vert_match)
2337
3.50k
        {
2338
3.50k
            ps_mb_params->u1_mb_type = P_L0_L0_8x16;
2339
3.50k
            i4_part_size = PRED_8x16;
2340
3.50k
            ps_mb_part_info->u1_num_part = 2;
2341
3.50k
            *pu1_col_info++ = (PRED_8x16 << 6);
2342
3.50k
            *pu1_col_info++ = (PRED_8x16 << 6);
2343
2344
3.50k
            ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2345
3.50k
            ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[2].i1_ref_frame[0];
2346
3.50k
            if(2 == i4_listx)
2347
1.32k
            {
2348
1.32k
                ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2349
1.32k
                ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[2].i1_ref_frame[1];
2350
1.32k
            }
2351
3.50k
            ps_part->u1_partwidth = 2;  // interms of 4x4
2352
3.50k
            ps_part->u1_partheight = 4;
2353
3.50k
            ps_part->u1_pred_mode = PRED_L0;
2354
3.50k
            ps_part->u1_is_direct = 0;
2355
3.50k
            ps_part->u1_sub_mb_num = 0;
2356
2357
3.50k
            ps_part++;
2358
3.50k
            ps_part->u1_partwidth = 2;
2359
3.50k
            ps_part->u1_partheight = 4;
2360
3.50k
            ps_part->u1_pred_mode = PRED_L0;
2361
3.50k
            ps_part->u1_is_direct = 0;
2362
3.50k
            ps_part->u1_sub_mb_num = 2;
2363
3.50k
        }
2364
97.9k
    }
2365
2366
    /* store the part size to the mb params */
2367
105k
    ps_mb_params->u1_mb_mc_mode = i4_part_size;
2368
2369
    /* in case of slice derive the partition modes */
2370
2371
105k
    {
2372
        /* store the sub MB modes if 8x8 mode is choosen */
2373
105k
        if(PRED_8x8 == i4_part_size)
2374
13.8k
        {
2375
13.8k
            UWORD8 u1_sub_mb_type, u1_sub_mb_mc_mode = 0;
2376
2377
            /* for P_MB sub part type is same as sub mb type */
2378
13.8k
            ps_mb_params->u1_mb_type = P_8x8;
2379
13.8k
            ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred[0].i1_ref_frame[0];
2380
13.8k
            ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[2].i1_ref_frame[0];
2381
13.8k
            ps_mb_part_info->i1_ref_idx[0][2] = ps_motion_pred[8].i1_ref_frame[0];
2382
13.8k
            ps_mb_part_info->i1_ref_idx[0][3] = ps_motion_pred[10].i1_ref_frame[0];
2383
13.8k
            if(2 == i4_listx)
2384
3.92k
            {
2385
3.92k
                ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred[0].i1_ref_frame[1];
2386
3.92k
                ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[2].i1_ref_frame[1];
2387
3.92k
                ps_mb_part_info->i1_ref_idx[1][2] = ps_motion_pred[8].i1_ref_frame[1];
2388
3.92k
                ps_mb_part_info->i1_ref_idx[1][3] = ps_motion_pred[10].i1_ref_frame[1];
2389
3.92k
            }
2390
2391
13.8k
            ps_mb_part_info->u1_num_part = 0;
2392
69.2k
            for(i4_i = 0; i4_i < NUM_MB_PARTS; i4_i++)
2393
55.3k
            {
2394
55.3k
                WORD32 i4_num_submb_part, i4_part_width, i4_part_height, i4_ctr;
2395
55.3k
                u1_sub_mb_type = (UWORD8) pi4_sub_mb_mode[i4_i];
2396
2397
55.3k
                if(1 == i4_listx)
2398
39.6k
                {
2399
39.6k
                    u1_sub_mb_mc_mode = gau1_ih264d_submb_mc_mode[u1_sub_mb_type];
2400
39.6k
                }
2401
15.7k
                else if(2 == i4_listx)
2402
15.7k
                {
2403
15.7k
                    u1_sub_mb_mc_mode = gau1_ih264d_submb_mc_mode[4 + u1_sub_mb_type];
2404
15.7k
                }
2405
55.3k
                i4_num_submb_part = g_au1_num_sub_mb_part[u1_sub_mb_mc_mode];
2406
2407
55.3k
                ps_mb_part_info->u1_num_part += i4_num_submb_part;
2408
2409
55.3k
                i4_part_width = g_au1_sub_mb_part_wd[u1_sub_mb_mc_mode];
2410
55.3k
                i4_part_height = g_au1_sub_mb_part_ht[u1_sub_mb_mc_mode];
2411
55.3k
                *pu1_col_info++ = (PRED_8x8 << 6) | (u1_sub_mb_mc_mode << 4);
2412
126k
                for(i4_ctr = 0; i4_ctr < i4_num_submb_part; i4_ctr++)
2413
70.6k
                {
2414
70.6k
                    ps_part->u1_partwidth = i4_part_width;  // interms of 4x4
2415
70.6k
                    ps_part->u1_partheight = i4_part_height;
2416
70.6k
                    ps_part->u1_pred_mode = PRED_L0;
2417
70.6k
                    ps_part->u1_is_direct = 0;
2418
70.6k
                    ps_part->u1_sub_mb_num = (i4_i & 0x01) * 2 + (i4_i >> 1) * 8;
2419
70.6k
                    if(i4_num_submb_part == 2)
2420
25.4k
                    {
2421
25.4k
                        ps_part->u1_sub_mb_num +=
2422
25.4k
                            i4_ctr ? (((i4_part_width - 1) << 2) + (i4_part_height - 1)) : 0;
2423
25.4k
                    }
2424
45.1k
                    else if(i4_num_submb_part == 4)
2425
3.38k
                    {
2426
3.38k
                        ps_part->u1_sub_mb_num += ((i4_ctr >> 1) << 2) + (i4_ctr & 0x01);
2427
3.38k
                    }
2428
2429
70.6k
                    ps_part++;
2430
70.6k
                }
2431
55.3k
            }
2432
13.8k
        }
2433
105k
        if(2 == i4_listx)
2434
16.4k
        {
2435
16.4k
            ps_part = (parse_part_params_t *) pv_part;
2436
16.4k
            pu1_col_info = ps_mb_part_info->u1_col_info;
2437
            /* B_MBs */
2438
16.4k
            isvcd_interlyr_mbmode_pred_bmb(ps_ctxt, ps_motion_pred, 4, i4_part_size,
2439
16.4k
                                           pi4_sub_mb_mode, ps_mb_params, ps_part, pu1_col_info);
2440
16.4k
        }
2441
105k
    }
2442
2443
105k
    return;
2444
105k
}
2445
/*****************************************************************************/
2446
/*                                                                           */
2447
/*  Function Name :  isvcd_compute_interlayer_motion_mode                     */
2448
/*                                                                           */
2449
/*  Description   : this function does the  inter layer motion and mode      */
2450
/*                  prediction. of the current MB                            */
2451
/*                                                                           */
2452
/*  Inputs        : pv_comp_mode_mv_ctxt : mode motion handle                */
2453
/*                  pv_ref_layer_motion_mem_elements :  pointer to memory    */
2454
/*                    elements of reference layer motion params              */
2455
/*                  pv_mb_params : pointer to mb params structure            */
2456
/*  Globals       : none                                                     */
2457
/*  Processing    : it calls the module for cal ref part idc and intra flag  */
2458
/*                  if not intra it calls the motion prediction module       */
2459
/*                  if base mdoe flag then it call teh mode prediction module*/
2460
/*  Outputs       : inter layer predicted parameters                         */
2461
/*  Returns       : none                                                     */
2462
/*                                                                           */
2463
/*  Issues        : none                                                     */
2464
/*                                                                           */
2465
/*  Revision History:                                                        */
2466
/*                                                                           */
2467
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2468
/*         06 09 2021   vijayakumar          creation                        */
2469
/*                                                                           */
2470
/*****************************************************************************/
2471
WORD32 isvcd_compute_interlyr_motion_mode(void *pv_comp_mode_mv_ctxt, void *pv_mb_params,
2472
                                          void *pv_svc_mb_params, void *pv_dec,
2473
                                          void *pv_mb_part_info, void *pv_part)
2474
124k
{
2475
    /*! Flow of the module is as follows                                   */
2476
    /*! 1. if dyaydic case then it sets the sub mb mode to 8x8             */
2477
    /*! 2. else it call the ref part idc comute fucntion                   */
2478
    /*! 3. it calls the motion vectors and submb mode derive function.
2479
           if the current mb is not inffered as INTRA                      */
2480
    /*! 4. it calls the mode predcition module if base mode flag is 1      */
2481
2482
124k
    mode_motion_ctxt_t *ps_ctxt;
2483
124k
    WORD32 i4_intra_flag;
2484
124k
    WORD32 ai4_sub_mb_mode[NUM_MB_PARTS] = {0};
2485
124k
    dec_mb_info_t *ps_mb_params;
2486
124k
    dec_svc_mb_info_t *ps_svc_mb_params;
2487
124k
    dec_struct_t *ps_dec = (dec_struct_t *) pv_dec;
2488
124k
    WORD32 i4_mb_mode = -1;
2489
124k
    parse_pmbarams_t *ps_mb_part_info = (parse_pmbarams_t *) pv_mb_part_info;
2490
124k
    parse_part_params_t *ps_part = (parse_part_params_t *) pv_part;
2491
2492
124k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
2493
124k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
2494
124k
    ps_svc_mb_params = (dec_svc_mb_info_t *) pv_svc_mb_params;
2495
2496
124k
    i4_intra_flag = SVCD_FALSE;
2497
2498
124k
    isvcd_ref_lyr_part_idc(pv_comp_mode_mv_ctxt, ps_ctxt->ai4_ref_part_idc, &i4_intra_flag,
2499
124k
                           pv_mb_params);
2500
2501
    /* If base is Intra */
2502
124k
    if(SVCD_TRUE == i4_intra_flag)
2503
9.39k
    {
2504
9.39k
        if(1 == ps_svc_mb_params->u1_base_mode_flag)
2505
8.99k
        {
2506
8.99k
            i4_mb_mode = SVC_IBL_MB;
2507
8.99k
            ps_svc_mb_params->u1_residual_prediction_flag = 0;
2508
8.99k
        }
2509
9.39k
    }
2510
115k
    else
2511
115k
    {
2512
        /* derive the motion and reference index by inter layer predcition */
2513
115k
        isvcd_interlyr_motion_submbmode_pred(pv_comp_mode_mv_ctxt, ps_mb_params, ps_svc_mb_params,
2514
115k
                                             ps_ctxt->ai4_ref_part_idc, ai4_sub_mb_mode, pv_dec);
2515
2516
        /* derive the MB mode */
2517
115k
        if(1 == ps_svc_mb_params->u1_base_mode_flag)
2518
105k
        {
2519
105k
            isvcd_interlyr_mbmode_pred(pv_comp_mode_mv_ctxt, pv_mb_params, ai4_sub_mb_mode,
2520
105k
                                       &i4_mb_mode, ps_dec, ps_mb_part_info, ps_part);
2521
105k
        }
2522
9.35k
        else
2523
9.35k
        {
2524
9.35k
            isvcd_populate_ref_idx(ps_mb_params, ps_svc_mb_params, ps_ctxt->ps_motion_pred_struct,
2525
9.35k
                                   ps_mb_part_info, ps_ctxt->i4_listx);
2526
9.35k
        }
2527
115k
    }
2528
2529
124k
    return i4_mb_mode;
2530
124k
}
2531
2532
/*****************************************************************************/
2533
/*                                                                           */
2534
/*  Function Name :  isvcd_interlyr_motion_mode_pred_dyadic                   */
2535
/*                                                                           */
2536
/*  Description   : this function does the inter layer motion predcition for */
2537
/*                   dyadic cases                                            */
2538
/*                                                                           */
2539
/*  Inputs        : pv_comp_mode_mv_ctxt : motion mode handle                */
2540
/*                  pv_ref_layer_motion_mem_elements : pointer to memory     */
2541
/*                    elements of reference layer motion params              */
2542
/*                  pv_mb_params : pointer to MB params structure            */
2543
/*                  ai4_ref_part_idc : ref partitons idc of all 4x4 blocks   */
2544
/*                  pi4_sub_mb_mode  : pointer to store the sub mb modes     */
2545
/*                  i4_mb_addr       : current mb address                    */
2546
/*                  pi4_intra_flag   : location to store the intra status    */
2547
/*  Globals       : none                                                     */
2548
/*  Processing    : it computes the motion vectors and                       */
2549
/*  Outputs       : inter layer predicted motion vectors and ref indices     */
2550
/*                  sub mbmodes of the 4 mb partitions                       */
2551
/*  Returns       : none                                                     */
2552
/*                                                                           */
2553
/*  Issues        : none                                                     */
2554
/*                                                                           */
2555
/*  Revision History:                                                        */
2556
/*                                                                           */
2557
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2558
/*         06 09 2021   vijayakumar          creation                        */
2559
/*                                                                           */
2560
/*****************************************************************************/
2561
WORD32 isvcd_interlyr_motion_mode_pred_dyadic(void *pv_comp_mode_mv_ctxt, void *pv_mb_params,
2562
                                              void *pv_svc_mb_params, void *pv_dec,
2563
                                              void *pv_mb_part_info, void *pv_part)
2564
66.8k
{
2565
66.8k
    mode_motion_ctxt_t *ps_ctxt;
2566
66.8k
    mode_motion_lyr_ctxt *ps_lyr_mem;
2567
66.8k
    dec_mb_info_t *ps_mb_params;
2568
66.8k
    dec_svc_mb_info_t *ps_svc_mb_params;
2569
66.8k
    WORD32 i4_listx;
2570
66.8k
    WORD32 i4_mb_pic_x, i4_mb_pic_y;
2571
66.8k
    WORD32 i4_ref_x, i4_ref_y;
2572
66.8k
    UWORD8 u1_base_mode_flag;
2573
66.8k
    dec_struct_t *ps_dec = (dec_struct_t *) pv_dec;
2574
66.8k
    WORD32 i4_mb_mode = -1;
2575
66.8k
    parse_pmbarams_t *ps_mb_part_info = (parse_pmbarams_t *) pv_mb_part_info;
2576
66.8k
    UWORD8 *pu1_col_info = ps_mb_part_info->u1_col_info;
2577
66.8k
    parse_part_params_t *ps_part = (parse_part_params_t *) pv_part;
2578
2579
66.8k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
2580
2581
    /* get the current layer ctxt */
2582
66.8k
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
2583
2584
66.8k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
2585
66.8k
    ps_svc_mb_params = (dec_svc_mb_info_t *) pv_svc_mb_params;
2586
66.8k
    i4_listx = ps_ctxt->i4_listx;
2587
2588
66.8k
    {
2589
66.8k
        WORD32 i4_mb_x, i4_mb_y;
2590
        /* derive the MB_X and MB_Y for the current MB */
2591
66.8k
        i4_mb_x = ps_mb_params->u2_mbx;
2592
66.8k
        i4_mb_y = ps_mb_params->u2_mby;
2593
2594
        /* get the colocated position in the refernce layer */
2595
66.8k
        i4_ref_x = ps_lyr_mem->pi2_ref_loc_x[i4_mb_x << 4];
2596
66.8k
        i4_ref_y = ps_lyr_mem->pi2_ref_loc_y[i4_mb_y << 4];
2597
66.8k
        i4_ref_x = CLIP3(0, ((ps_lyr_mem->i4_ref_width) - 1), i4_ref_x);
2598
66.8k
        i4_ref_y = CLIP3(0, ((ps_lyr_mem->i4_ref_height) - 1), i4_ref_y);
2599
2600
        /* convert into picture units */
2601
66.8k
        i4_mb_pic_x = i4_mb_x << 4;
2602
66.8k
        i4_mb_pic_y = i4_mb_y << 4;
2603
66.8k
    }
2604
2605
    /* ref layer mb mode */
2606
66.8k
    {
2607
66.8k
        inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
2608
66.8k
        WORD32 i4_inter_lyr_mb_prms_stride;
2609
66.8k
        WORD32 i4_ref_mb_x, i4_ref_mb_y;
2610
66.8k
        WORD8 i1_ref_mb_mode;
2611
2612
66.8k
        ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) ps_lyr_mem->s_ref_mb_mode.pv_buffer;
2613
66.8k
        i4_inter_lyr_mb_prms_stride = ps_lyr_mem->s_ref_mb_mode.i4_num_element_stride;
2614
2615
        /* get the reference mb x and y */
2616
66.8k
        i4_ref_mb_x = (i4_ref_x >> 4);
2617
66.8k
        i4_ref_mb_y = (i4_ref_y >> 4);
2618
2619
        /* get the appropriate mb params in reference layer */
2620
66.8k
        ps_inter_lyr_mb_prms += i4_ref_mb_x;
2621
66.8k
        ps_inter_lyr_mb_prms += i4_ref_mb_y * i4_inter_lyr_mb_prms_stride;
2622
66.8k
        i1_ref_mb_mode = ps_inter_lyr_mb_prms->i1_mb_mode;
2623
66.8k
        u1_base_mode_flag = ps_svc_mb_params->u1_base_mode_flag;
2624
2625
        /* check if the MB mode of the refernce MB is Intra*/
2626
66.8k
        if(i1_ref_mb_mode > SVC_INTER_MB)
2627
13.3k
        {
2628
13.3k
            if(1 == u1_base_mode_flag)
2629
13.1k
            {
2630
13.1k
                i4_mb_mode = SVC_IBL_MB;
2631
13.1k
                ps_svc_mb_params->u1_residual_prediction_flag = 0;
2632
13.1k
            }
2633
13.3k
            return i4_mb_mode;
2634
13.3k
        }
2635
66.8k
    }
2636
2637
    /*-----------------------------------------------------------------------*/
2638
    /* Inter MB upsampling process                                           */
2639
    /*-----------------------------------------------------------------------*/
2640
53.4k
    {
2641
53.4k
        mv_pred_t *ps_motion_pred;
2642
53.4k
        WORD32 i4_16x16_flag;
2643
53.4k
        WORD32 i4_part_idc;
2644
53.4k
        WORD32 i4_blk_idx;
2645
53.4k
        WORD32 i4_curr_mot_stride;
2646
2647
        /* choose the appropriate mv bank pointer and stride */
2648
53.4k
        if(1 == u1_base_mode_flag)
2649
35.5k
        {
2650
35.5k
            i4_mb_mode = SVC_INTER_MB;
2651
35.5k
        }
2652
2653
53.4k
        ps_motion_pred = ps_ctxt->ps_motion_pred_struct;
2654
53.4k
        i4_curr_mot_stride = 4;
2655
2656
        /* call the motion upsampling for 1st 4x4 */
2657
53.4k
        i4_part_idc = (i4_ref_y << 16) + i4_ref_x;
2658
53.4k
        i4_16x16_flag = isvcd_interlyr_motion_scale(
2659
53.4k
            pv_comp_mode_mv_ctxt, &i4_part_idc, ps_mb_params, ps_motion_pred, i4_listx,
2660
53.4k
            (i4_mb_pic_x + 1), (i4_mb_pic_y + 1), ps_dec->ppv_map_ref_idx_to_poc);
2661
2662
        /* ---------- reference layer MB is 16x16 ------------------*/
2663
53.4k
        if(i4_16x16_flag)
2664
0
        {
2665
0
            if(1 == u1_base_mode_flag)
2666
0
            {
2667
0
                ps_mb_params->u1_mb_type = P_L0_16x16;
2668
0
                ps_mb_params->u1_mb_mc_mode = PRED_16x16;
2669
0
                ps_mb_part_info->u1_num_part = 1;
2670
0
                *pu1_col_info++ = (PRED_16x16 << 6);
2671
0
                ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2672
2673
0
                ps_part->u1_partwidth = 4;  // interms of 4x4
2674
0
                ps_part->u1_partheight = 4;
2675
0
                ps_part->u1_pred_mode = PRED_L0;
2676
0
                ps_part->u1_is_direct = 0;
2677
0
                ps_part->u1_sub_mb_num = 0;
2678
2679
0
                if(2 == i4_listx)
2680
0
                {
2681
0
                    WORD32 i4_part_mode_a = 0;
2682
0
                    WORD32 i4_temp;
2683
2684
0
                    ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2685
0
                    if(0 <= ps_motion_pred[0].i1_ref_frame[0])
2686
0
                    {
2687
0
                        i4_part_mode_a += 1;
2688
0
                    }
2689
0
                    if(0 <= ps_motion_pred[0].i1_ref_frame[1])
2690
0
                    {
2691
0
                        i4_part_mode_a += 2;
2692
0
                    }
2693
2694
0
                    i4_temp = 3 * PRED_16x16;
2695
0
                    i4_temp += (3 * (i4_part_mode_a - 1) - 1);
2696
0
                    i4_temp = (i4_temp < 0) ? 0 : i4_temp;
2697
0
                    i4_temp = g_au1_eb_mb_type[i4_temp];
2698
0
                    ps_mb_params->u1_mb_type = i4_temp;
2699
0
                    ps_part->u1_pred_mode = g_au1_mb_pred_mode[0][5 + i4_temp];
2700
0
                }
2701
0
            }
2702
0
            else
2703
0
            {
2704
                /* motion prediction flag cases replicate the motion vectors for entire MB */
2705
0
                isvcd_store_motion_map(ps_motion_pred, (ps_motion_pred), 0, i4_curr_mot_stride,
2706
0
                                       NUM_MB_PARTS, NUM_MB_PARTS, SVCD_FALSE);
2707
2708
0
                isvcd_populate_ref_idx(ps_mb_params, ps_svc_mb_params, ps_motion_pred,
2709
0
                                       ps_mb_part_info, i4_listx);
2710
0
            }
2711
0
            return i4_mb_mode;
2712
0
        }
2713
        /* ---------- reference layer MB is non 16x16 ------------------ */
2714
53.4k
        else
2715
53.4k
        {
2716
53.4k
            WORD32 ai4_sub_mb_mode[NUM_MB_PARTS] = {0};
2717
2718
            /* replicate the motion vectors for 8x8 */
2719
53.4k
            isvcd_store_motion_map(ps_motion_pred, ps_motion_pred, 0, i4_curr_mot_stride, 2, 2,
2720
53.4k
                                   SVCD_FALSE);
2721
2722
53.4k
            if(2 == i4_listx)
2723
22.2k
            {
2724
22.2k
                WORD32 i4_indx = 0;
2725
2726
                /* replicate the motion vectors for 8x8 */
2727
                /* check the 0th partiton reference indices */
2728
22.2k
                if(0 <= ps_motion_pred[0].i1_ref_frame[0])
2729
21.8k
                {
2730
21.8k
                    i4_indx += 1;
2731
21.8k
                }
2732
22.2k
                if(0 <= ps_motion_pred[0].i1_ref_frame[1])
2733
8.56k
                {
2734
8.56k
                    i4_indx += 2;
2735
8.56k
                }
2736
2737
22.2k
                i4_indx = 3 * PRED_8x8 + (i4_indx - 1);
2738
22.2k
                ai4_sub_mb_mode[0] = g_au1_eb_submb_type[i4_indx];
2739
22.2k
            }
2740
2741
            /* derive the motion vectors and reference indices of 3 rem partitions */
2742
213k
            for(i4_blk_idx = 1; i4_blk_idx < NUM_MB_PARTS; i4_blk_idx++)
2743
160k
            {
2744
160k
                WORD32 i4_blk_y, i4_blk_x;
2745
160k
                mv_pred_t *ps_temp;
2746
2747
160k
                i4_blk_x = i4_blk_idx & 1;
2748
160k
                i4_blk_y = i4_blk_idx >> 1;
2749
2750
160k
                ps_temp = ps_motion_pred + (i4_blk_x << 1);
2751
160k
                ps_temp += (i4_blk_y * i4_curr_mot_stride << 1);
2752
2753
                /* store the reference layer positions */
2754
160k
                i4_part_idc = ((i4_ref_y + (i4_blk_y << 2)) << 16) + (i4_ref_x + (i4_blk_x << 2));
2755
160k
                isvcd_interlyr_motion_scale(pv_comp_mode_mv_ctxt, &i4_part_idc, ps_mb_params,
2756
160k
                                            ps_temp, i4_listx, (i4_mb_pic_x + (i4_blk_x << 2) + 1),
2757
160k
                                            (i4_mb_pic_y + (i4_blk_y << 2) + 1),
2758
160k
                                            ps_dec->ppv_map_ref_idx_to_poc);
2759
2760
                /* replicate the motion vectors for 8x8 */
2761
160k
                isvcd_store_motion_map(ps_temp, ps_temp, 0, i4_curr_mot_stride, 2, 2, SVCD_FALSE);
2762
2763
160k
                if(2 == i4_listx)
2764
66.8k
                {
2765
66.8k
                    WORD32 i4_indx = 0;
2766
2767
                    /* check the 0th partiton reference indices */
2768
66.8k
                    if(0 <= ps_temp[0].i1_ref_frame[0])
2769
65.4k
                    {
2770
65.4k
                        i4_indx += 1;
2771
65.4k
                    }
2772
66.8k
                    if(0 <= ps_temp[0].i1_ref_frame[1])
2773
26.2k
                    {
2774
26.2k
                        i4_indx += 2;
2775
26.2k
                    }
2776
2777
66.8k
                    i4_indx = 3 * PRED_8x8 + (i4_indx - 1);
2778
2779
66.8k
                    ai4_sub_mb_mode[i4_blk_idx] = g_au1_eb_submb_type[i4_indx];
2780
66.8k
                }
2781
160k
            }
2782
2783
            /* if MB mode has to derivied */
2784
53.4k
            if(1 == u1_base_mode_flag)
2785
35.5k
            {
2786
35.5k
                WORD32 i4_horz_match, i4_vert_match;
2787
35.5k
                WORD32 i4_part_size = PRED_8x8;
2788
2789
35.5k
                mv_pred_t *ps_motion_1;
2790
35.5k
                mv_pred_t *ps_motion_2;
2791
35.5k
                mv_pred_t *ps_motion_3;
2792
2793
35.5k
                ps_motion_1 = ps_motion_pred + 2;
2794
35.5k
                ps_motion_2 = ps_motion_pred + (i4_curr_mot_stride << 1);
2795
35.5k
                ps_motion_3 = ps_motion_2 + 2;
2796
2797
                /* check if the motion in horz direction are same*/
2798
35.5k
                i4_horz_match = isvcd_check_motion(ps_motion_pred, ps_motion_1, i4_listx);
2799
35.5k
                i4_horz_match += isvcd_check_motion(ps_motion_2, ps_motion_3, i4_listx);
2800
2801
                /* check if the motion in vertical direction is same */
2802
35.5k
                i4_vert_match = isvcd_check_motion(ps_motion_pred, ps_motion_2, i4_listx);
2803
35.5k
                i4_vert_match += isvcd_check_motion(ps_motion_1, ps_motion_3, i4_listx);
2804
2805
35.5k
                ps_mb_part_info->u1_num_part = 4;
2806
2807
                /* decide the partition size based on the results of matching */
2808
35.5k
                if((2 == i4_horz_match) && (2 == i4_vert_match))
2809
31.6k
                {
2810
31.6k
                    ps_mb_params->u1_mb_type = P_L0_16x16;
2811
31.6k
                    i4_part_size = PRED_16x16;
2812
31.6k
                    ps_mb_part_info->u1_num_part = 1;
2813
31.6k
                    *pu1_col_info++ = (PRED_16x16 << 6);
2814
2815
31.6k
                    ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2816
31.6k
                    if(2 == i4_listx)
2817
11.5k
                        ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2818
2819
31.6k
                    ps_part->u1_partwidth = 4;  // interms of 4x4
2820
31.6k
                    ps_part->u1_partheight = 4;
2821
31.6k
                    ps_part->u1_pred_mode = PRED_L0;
2822
31.6k
                    ps_part->u1_is_direct = 0;
2823
31.6k
                    ps_part->u1_sub_mb_num = 0;
2824
31.6k
                }
2825
3.88k
                else if(2 == i4_horz_match)
2826
926
                {
2827
926
                    ps_mb_params->u1_mb_type = P_L0_L0_16x8;
2828
926
                    i4_part_size = PRED_16x8;
2829
926
                    ps_mb_part_info->u1_num_part = 2;
2830
926
                    *pu1_col_info++ = (PRED_16x8 << 6);
2831
926
                    *pu1_col_info++ = (PRED_16x8 << 6);
2832
2833
926
                    ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2834
926
                    ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[8].i1_ref_frame[0];
2835
926
                    if(2 == i4_listx)
2836
400
                    {
2837
400
                        ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2838
400
                        ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[8].i1_ref_frame[1];
2839
400
                    }
2840
926
                    ps_part->u1_partwidth = 4;  // interms of 4x4
2841
926
                    ps_part->u1_partheight = 2;
2842
926
                    ps_part->u1_pred_mode = PRED_L0;
2843
926
                    ps_part->u1_is_direct = 0;
2844
926
                    ps_part->u1_sub_mb_num = 0;
2845
2846
926
                    ps_part++;
2847
926
                    ps_part->u1_partwidth = 4;
2848
926
                    ps_part->u1_partheight = 2;
2849
926
                    ps_part->u1_pred_mode = PRED_L0;
2850
926
                    ps_part->u1_is_direct = 0;
2851
926
                    ps_part->u1_sub_mb_num = 8;
2852
926
                }
2853
2.95k
                else if(2 == i4_vert_match)
2854
715
                {
2855
715
                    ps_mb_params->u1_mb_type = P_L0_L0_8x16;
2856
715
                    i4_part_size = PRED_8x16;
2857
715
                    ps_mb_part_info->u1_num_part = 2;
2858
715
                    *pu1_col_info++ = (PRED_8x16 << 6);
2859
715
                    *pu1_col_info++ = (PRED_8x16 << 6);
2860
2861
715
                    ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2862
715
                    ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[2].i1_ref_frame[0];
2863
715
                    if(2 == i4_listx)
2864
405
                    {
2865
405
                        ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2866
405
                        ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[2].i1_ref_frame[1];
2867
405
                    }
2868
715
                    ps_part->u1_partwidth = 2;  // interms of 4x4
2869
715
                    ps_part->u1_partheight = 4;
2870
715
                    ps_part->u1_pred_mode = PRED_L0;
2871
715
                    ps_part->u1_is_direct = 0;
2872
715
                    ps_part->u1_sub_mb_num = 0;
2873
2874
715
                    ps_part++;
2875
715
                    ps_part->u1_partwidth = 2;
2876
715
                    ps_part->u1_partheight = 4;
2877
715
                    ps_part->u1_pred_mode = PRED_L0;
2878
715
                    ps_part->u1_is_direct = 0;
2879
715
                    ps_part->u1_sub_mb_num = 2;
2880
715
                }
2881
2882
                /* store the part size to the mb params */
2883
35.5k
                ps_mb_params->u1_mb_mc_mode = i4_part_size;
2884
2885
                /* store the sub partition size */
2886
35.5k
                if(PRED_8x8 == i4_part_size)
2887
2.24k
                {
2888
2.24k
                    UWORD8 u1_ctr;
2889
                    /* for P_MB sub part type is P_L0_8x8*/
2890
2891
2.24k
                    ps_mb_params->u1_mb_type = P_8x8;
2892
2.24k
                    ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred[0].i1_ref_frame[0];
2893
2.24k
                    ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[2].i1_ref_frame[0];
2894
2.24k
                    ps_mb_part_info->i1_ref_idx[0][2] = ps_motion_pred[8].i1_ref_frame[0];
2895
2.24k
                    ps_mb_part_info->i1_ref_idx[0][3] = ps_motion_pred[10].i1_ref_frame[0];
2896
2.24k
                    if(2 == i4_listx)
2897
1.42k
                    {
2898
1.42k
                        ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred[0].i1_ref_frame[1];
2899
1.42k
                        ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[2].i1_ref_frame[1];
2900
1.42k
                        ps_mb_part_info->i1_ref_idx[1][2] = ps_motion_pred[8].i1_ref_frame[1];
2901
1.42k
                        ps_mb_part_info->i1_ref_idx[1][3] = ps_motion_pred[10].i1_ref_frame[1];
2902
1.42k
                    }
2903
2904
11.2k
                    for(u1_ctr = 0; u1_ctr < 4; u1_ctr++)
2905
8.96k
                    {
2906
8.96k
                        *pu1_col_info++ = (PRED_8x8 << 6);
2907
2908
8.96k
                        ps_part->u1_partwidth = 2;  // interms of 4x4
2909
8.96k
                        ps_part->u1_partheight = 2;
2910
8.96k
                        ps_part->u1_pred_mode = PRED_L0;
2911
8.96k
                        ps_part->u1_is_direct = 0;
2912
8.96k
                        ps_part->u1_sub_mb_num = (u1_ctr & 0x01) * 2 + (u1_ctr >> 1) * 8;
2913
8.96k
                        ps_part++;
2914
8.96k
                    }
2915
2.24k
                }
2916
2917
35.5k
                if(2 == i4_listx)
2918
13.7k
                {
2919
13.7k
                    ps_part = (parse_part_params_t *) pv_part;
2920
13.7k
                    pu1_col_info = ps_mb_part_info->u1_col_info;
2921
13.7k
                    isvcd_interlyr_mbmode_pred_bmb(ps_ctxt, ps_motion_pred, i4_curr_mot_stride,
2922
13.7k
                                                   i4_part_size, &ai4_sub_mb_mode[0], ps_mb_params,
2923
13.7k
                                                   ps_part, pu1_col_info);
2924
13.7k
                }
2925
35.5k
            } /* end of mode derivation */
2926
17.9k
            else
2927
17.9k
            {
2928
17.9k
                isvcd_populate_ref_idx(ps_mb_params, ps_svc_mb_params, ps_motion_pred,
2929
17.9k
                                       ps_mb_part_info, i4_listx);
2930
2931
17.9k
            } /* non 16x16 mv mode derivation */
2932
53.4k
        }
2933
53.4k
    }
2934
53.4k
    return i4_mb_mode;
2935
53.4k
}
2936
2937
/*****************************************************************************/
2938
/*                                                                           */
2939
/*  Function Name : isvcd_compute_scaled_offsets                              */
2940
/*                                                                           */
2941
/*  Description   : this module does the projection of the current layer     */
2942
/*                   points (x,0) and (0,y) on to the reference layer and    */
2943
/*                   gets the 1/16 sample of the reference location          */
2944
/*                   x ranges from 0 - frame width                           */
2945
/*                   y ranges from 0 - frame height                          */
2946
/*                   this projection is done for LUMA only                   */
2947
/*  Inputs        :  ps_curr_lyr_slice_prms: pointer to current layer slice  */
2948
/*                                           parameters                      */
2949
/*                   ps_ref_lyr_slice_prms: pointer to ref layer slice prms  */
2950
/*                   pi2_offset_x         : pointer to store x projected     */
2951
/*                   pi2_offset_y         : pointer to store y projected     */
2952
/*  Globals       :  none                                                    */
2953
/*  Processing    :  it store the projected values for those points in the   */
2954
/*                   crop window                                             */
2955
/*  Outputs       :  projected locations                                     */
2956
/*  Returns       :  none                                                    */
2957
/*                                                                           */
2958
/*  Issues        : assumes that outside crop window no projection           */
2959
/*                                                                           */
2960
/*  Revision History:                                                        */
2961
/*                                                                           */
2962
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2963
/*         06 09 2021   vijayakumar          creation                        */
2964
/*                                                                           */
2965
/*****************************************************************************/
2966
WORD32 isvcd_compute_scaled_offsets(res_prms_t *ps_curr_res_prms, res_prms_t *ps_ref_res_prms,
2967
                                    WORD16 *pi2_offset_x, WORD16 *pi2_offset_y, UWORD8 u1_level_idc)
2968
34.0k
{
2969
34.0k
    WORD32 i4_offset_x, i4_offset_y;
2970
34.0k
    UWORD32 i4_scaled_ref_lyr_width;
2971
34.0k
    UWORD32 i4_scaled_ref_lyr_height;
2972
34.0k
    UWORD32 i4_ref_lyr_width;
2973
34.0k
    UWORD32 i4_ref_lyr_height;
2974
34.0k
    UWORD32 i4_shift_x, i4_shift_y;
2975
34.0k
    UWORD32 i4_scale_x, i4_scale_y;
2976
34.0k
    WORD32 i4_cntr;
2977
34.0k
    WORD32 i4_scale_add_x, i4_scale_add_y;
2978
34.0k
    WORD32 i4_curr_lyr_width, i4_curr_lyr_height;
2979
2980
34.0k
    if((NULL == ps_curr_res_prms) || (NULL == ps_ref_res_prms) || (NULL == pi2_offset_x) ||
2981
34.0k
       (NULL == pi2_offset_y))
2982
0
    {
2983
0
        return NOT_OK;
2984
0
    }
2985
    /* initial calculation */
2986
34.0k
    i4_offset_x = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_left;
2987
34.0k
    i4_offset_y = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_top;
2988
2989
    /* get the width and height */
2990
34.0k
    i4_scaled_ref_lyr_width = ps_curr_res_prms->u2_scaled_ref_width;
2991
34.0k
    i4_scaled_ref_lyr_height = ps_curr_res_prms->u2_scaled_ref_height;
2992
34.0k
    i4_ref_lyr_width = ps_ref_res_prms->i4_res_width;
2993
34.0k
    i4_ref_lyr_height = ps_ref_res_prms->i4_res_height;
2994
34.0k
    i4_curr_lyr_width = ps_curr_res_prms->i4_res_width;
2995
34.0k
    i4_curr_lyr_height = ps_curr_res_prms->i4_res_height;
2996
2997
    /* derive shift x and y based on level idd */
2998
34.0k
    if(u1_level_idc <= 30)
2999
31.8k
    {
3000
31.8k
        i4_shift_x = 16;
3001
31.8k
        i4_shift_y = 16;
3002
31.8k
    }
3003
2.23k
    else
3004
2.23k
    {
3005
2.23k
        i4_shift_x = 31 - isvcd_get_ceil_log2(i4_ref_lyr_width);
3006
2.23k
        i4_shift_y = 31 - isvcd_get_ceil_log2(i4_ref_lyr_height);
3007
2.23k
    }
3008
3009
    /* assert on max ranges of width and shift values */
3010
34.0k
    if((i4_ref_lyr_width > H264_MAX_FRAME_WIDTH) ||
3011
34.0k
       (i4_scaled_ref_lyr_width > H264_MAX_FRAME_WIDTH) ||
3012
34.0k
       (i4_ref_lyr_height > H264_MAX_FRAME_HEIGHT) ||
3013
34.0k
       (i4_scaled_ref_lyr_height > H264_MAX_FRAME_HEIGHT) ||
3014
34.0k
       (i4_curr_lyr_width > H264_MAX_FRAME_WIDTH) || (i4_curr_lyr_height > H264_MAX_FRAME_HEIGHT))
3015
0
    {
3016
0
        return NOT_OK;
3017
0
    }
3018
3019
    /* calculate scale factor x and y */
3020
34.0k
    i4_scale_x = (((UWORD32) i4_ref_lyr_width << i4_shift_x) + (i4_scaled_ref_lyr_width >> 1)) /
3021
34.0k
                 i4_scaled_ref_lyr_width;
3022
3023
34.0k
    i4_scale_y = (((UWORD32) i4_ref_lyr_height << i4_shift_y) + (i4_scaled_ref_lyr_height >> 1)) /
3024
34.0k
                 i4_scaled_ref_lyr_height;
3025
3026
    /* calcualte the values to be added based on left and top offset */
3027
34.0k
    i4_scale_add_x = (1 << (i4_shift_x - 1)) - (i4_offset_x * (WORD32) i4_scale_x);
3028
34.0k
    i4_scale_add_y = (1 << (i4_shift_y - 1)) - (i4_offset_y * (WORD32) i4_scale_y);
3029
3030
    /* derive the projected locations in the reference layer */
3031
1.92M
    for(i4_cntr = 0; i4_cntr < i4_curr_lyr_width; i4_cntr++)
3032
1.89M
    {
3033
1.89M
        WORD32 i4_ref_x;
3034
1.89M
        i4_ref_x = (i4_cntr * i4_scale_x + i4_scale_add_x) >> i4_shift_x;
3035
1.89M
        *pi2_offset_x++ = (WORD16) i4_ref_x;
3036
1.89M
    }
3037
3038
    /* derive the projected locations in the reference layer */
3039
5.08M
    for(i4_cntr = 0; i4_cntr < i4_curr_lyr_height; i4_cntr++)
3040
5.04M
    {
3041
5.04M
        WORD32 i4_ref_y;
3042
5.04M
        i4_ref_y = (i4_cntr * i4_scale_y + i4_scale_add_y) >> i4_shift_y;
3043
5.04M
        *pi2_offset_y++ = (WORD16) i4_ref_y;
3044
5.04M
    }
3045
34.0k
    return OK;
3046
34.0k
}
3047
3048
/*****************************************************************************/
3049
/*                                                                           */
3050
/*  Function Name : isvcd_comp_mode_mv_res_init                               */
3051
/*                                                                           */
3052
/*  Description   : this function calculates the scale factors and initialise*/
3053
/*                  the context structure                                    */
3054
/*                                                                           */
3055
/*  Inputs        : pv_comp_mode_mv_ctxt: handle to private structure        */
3056
/*                  ps_curr_lyr_res_prms: pointer to current resolution      */
3057
/*                                               params                      */
3058
/*                  pi2_ref_loc_x             : pointer to buffer having the */
3059
/*                                              projected locations horz     */
3060
/*                  pi2_ref_loc_y             : pointer to buffer having the */
3061
/*                                              projected location vertical  */
3062
/*  Globals       : none                                                     */
3063
/*  Processing    : it calculates the scale factors and stores it            */
3064
/*                                                                           */
3065
/*  Outputs       : none                                                     */
3066
/*  Returns       : none                                                     */
3067
/*                                                                           */
3068
/*  Issues        : none                                                     */
3069
/*                                                                           */
3070
/*  Revision History:                                                        */
3071
/*                                                                           */
3072
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3073
/*         06 09 2021   vijayakumar          creation                        */
3074
/*                                                                           */
3075
/*****************************************************************************/
3076
WORD32 isvcd_comp_mode_mv_res_init(void *pv_svc_dec)
3077
135k
{
3078
    /*! Flow of the module is as follows                                   */
3079
    /*! 1. calculates the scale factors for dyadic cases                   */
3080
    /*! 2. calculaets the loop counts and part width and height based on
3081
           dyadic scale factor                                             */
3082
    /*! 2. calculate the MV scale factors                                  */
3083
    /*! 3. initialises the default mv ped structure with deafult values    */
3084
3085
135k
    mode_motion_ctxt_t *ps_ctxt;
3086
135k
    mode_motion_lyr_ctxt *ps_lyr_mem;
3087
135k
    dec_seq_params_t *ps_sps;
3088
135k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) pv_svc_dec;
3089
135k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
3090
135k
    svc_dec_lyr_struct_t *ps_svc_dec_ref_layer;
3091
135k
    WORD32 ret;
3092
135k
    WORD32 i4_scaled_ref_lyr_width;
3093
135k
    WORD32 i4_scaled_ref_lyr_height;
3094
135k
    WORD32 i4_ref_lyr_width;
3095
135k
    WORD32 i4_ref_lyr_height;
3096
135k
    res_prms_t *ps_curr_lyr_res_prms = &ps_svc_lyr_dec->s_res_prms;
3097
3098
135k
    ps_svc_dec_ref_layer = ps_svc_lyr_dec->ps_dec_svc_ref_layer;
3099
135k
    if(NULL == ps_curr_lyr_res_prms)
3100
0
    {
3101
0
        return NOT_OK;
3102
0
    }
3103
3104
135k
    ps_ctxt = (mode_motion_ctxt_t *) ps_svc_lyr_dec->pv_mode_mv_sample_ctxt;
3105
135k
    ps_ctxt->u1_direct_8x8_inference_flag = ps_curr_lyr_res_prms->u1_direct_8x8_inference_flag;
3106
3107
    /* if called for base resolution store deafult values */
3108
135k
    if(SVCD_TRUE == ps_svc_lyr_dec->u1_base_res_flag)
3109
101k
    {
3110
101k
        ps_ctxt->i4_res_id = -1;
3111
101k
        ps_ctxt->i4_ref_width = ps_curr_lyr_res_prms->i4_res_width;
3112
101k
        ps_ctxt->i4_ref_height = ps_curr_lyr_res_prms->i4_res_height;
3113
101k
        return OK;
3114
101k
    }
3115
3116
    /* call the function which populates the projected ref locations */
3117
34.0k
    ps_sps = ps_dec->ps_cur_sps;
3118
3119
    /* store the res id appropriately */
3120
34.0k
    ps_ctxt->i4_res_id = ps_svc_lyr_dec->u1_layer_id - 1;
3121
3122
    /* get the current layer ctxt */
3123
34.0k
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
3124
3125
    /* store the current and reference res params to the context */
3126
34.0k
    ps_lyr_mem->ps_curr_lyr_res_prms = ps_curr_lyr_res_prms;
3127
3128
    /* store the reference layer mv bank pointer */
3129
34.0k
    ps_lyr_mem->pv_ref_mv_bank_l0 = ps_svc_dec_ref_layer->s_dec.s_cur_pic.ps_mv;
3130
3131
    /* store the reference layer mb mode pointer */
3132
34.0k
    ps_lyr_mem->s_ref_mb_mode.pv_buffer = ps_svc_dec_ref_layer->ps_inter_lyr_mb_prms_frm_start;
3133
34.0k
    ps_lyr_mem->s_ref_mb_mode.i4_num_element_stride =
3134
34.0k
        ps_svc_dec_ref_layer->u2_inter_lyr_mb_prms_stride;
3135
34.0k
    ps_lyr_mem->s_ref_mb_mode.i4_element_size = sizeof(inter_lyr_mb_prms_t);
3136
3137
    /* check for recomputation of mapping required */
3138
34.0k
    if(SVCD_TRUE == ps_curr_lyr_res_prms->u1_remap_req_flag)
3139
34.0k
    {
3140
34.0k
        res_prms_t s_ref_res_prms = {0};
3141
3142
        /* store the reference layer resolution width and height */
3143
34.0k
        s_ref_res_prms.i4_res_width = ps_ctxt->i4_ref_width;
3144
34.0k
        s_ref_res_prms.i4_res_height = ps_ctxt->i4_ref_height;
3145
3146
        /* call projection map calculation function */
3147
34.0k
        ret = isvcd_compute_scaled_offsets(ps_curr_lyr_res_prms, &s_ref_res_prms,
3148
34.0k
                                           ps_lyr_mem->pi2_ref_loc_x, ps_lyr_mem->pi2_ref_loc_y,
3149
34.0k
                                           ps_sps->u1_level_idc);
3150
34.0k
        if(OK != ret)
3151
0
        {
3152
0
            return NOT_OK;
3153
0
        }
3154
3155
        /* derive the scaling variables */
3156
34.0k
        ps_lyr_mem->i4_offset_x = ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left;
3157
3158
34.0k
        ps_lyr_mem->i4_offset_y = ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top;
3159
3160
        /* get the width and heights */
3161
34.0k
        i4_scaled_ref_lyr_width = ps_curr_lyr_res_prms->u2_scaled_ref_width;
3162
34.0k
        i4_scaled_ref_lyr_height = ps_curr_lyr_res_prms->u2_scaled_ref_height;
3163
34.0k
        i4_ref_lyr_width = ps_ctxt->i4_ref_width;
3164
34.0k
        i4_ref_lyr_height = ps_ctxt->i4_ref_height;
3165
3166
        /*store the reference layer width adn height */
3167
34.0k
        ps_lyr_mem->i4_ref_width = ps_ctxt->i4_ref_width;
3168
34.0k
        ps_lyr_mem->i4_ref_height = ps_ctxt->i4_ref_height;
3169
3170
34.0k
        if((i4_ref_lyr_width > H264_MAX_FRAME_WIDTH) || (i4_ref_lyr_width <= 0)) return NOT_OK;
3171
34.0k
        if((i4_scaled_ref_lyr_width > H264_MAX_FRAME_WIDTH) || (i4_scaled_ref_lyr_width <= 0))
3172
0
            return NOT_OK;
3173
34.0k
        if((i4_ref_lyr_height > H264_MAX_FRAME_HEIGHT) || (i4_ref_lyr_height <= 0)) return NOT_OK;
3174
34.0k
        if((i4_scaled_ref_lyr_height > H264_MAX_FRAME_HEIGHT) || (i4_scaled_ref_lyr_height <= 0))
3175
0
            return NOT_OK;
3176
3177
        /* derivation of variables for dyadic cases cropping should be MB aligned */
3178
        /* default values for flags */
3179
34.0k
        ps_lyr_mem->pf_inter_lyr_pred = &isvcd_compute_interlyr_motion_mode;
3180
3181
34.0k
        if(SVCD_TRUE == ps_curr_lyr_res_prms->u1_dyadic_flag)
3182
15.8k
        {
3183
15.8k
            ps_lyr_mem->pf_inter_lyr_pred = &isvcd_interlyr_motion_mode_pred_dyadic;
3184
15.8k
        }
3185
3186
        /* Store the Dyadic flag */
3187
34.0k
        ps_lyr_mem->i4_dyadic_flag = ps_curr_lyr_res_prms->u1_dyadic_flag;
3188
3189
        /* derive the scaling factors for motion upscaling */
3190
        /* this is derived assuming no crop change flag is present */
3191
34.0k
        ps_lyr_mem->i4_scale_mv_x =
3192
34.0k
            ((i4_scaled_ref_lyr_width << 16) + (i4_ref_lyr_width >> 1)) / i4_ref_lyr_width;
3193
3194
34.0k
        ps_lyr_mem->i4_scale_mv_y =
3195
34.0k
            ((i4_scaled_ref_lyr_height << 16) + (i4_ref_lyr_height >> 1)) / i4_ref_lyr_height;
3196
34.0k
    }
3197
0
    else
3198
0
    {
3199
        /* should take false value */
3200
0
        if(SVCD_FALSE != ps_curr_lyr_res_prms->u1_remap_req_flag)
3201
0
        {
3202
0
            return NOT_OK;
3203
0
        }
3204
0
    }
3205
3206
    /* store the current layer width and height to context */
3207
34.0k
    ps_ctxt->i4_ref_width = ps_curr_lyr_res_prms->i4_res_width;
3208
34.0k
    ps_ctxt->i4_ref_height = ps_curr_lyr_res_prms->i4_res_height;
3209
3210
34.0k
    return OK;
3211
34.0k
}