Coverage Report

Created: 2026-09-01 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/svc/isvcd_mode_mv_resamp.c
Line
Count
Source
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
128k
{
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
128k
    mode_motion_ctxt_t *ps_ctxt;
799
128k
    mode_motion_lyr_ctxt *ps_lyr_mem;
800
128k
    inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
801
128k
    WORD32 i4_blk_y, i4_blk_x;
802
128k
    WORD32 i4_mb_x, i4_mb_y;
803
128k
    WORD32 i4_intra_mb_flag;
804
128k
    WORD32 i4_inter_lyr_mb_prms_stride;
805
128k
    dec_mb_info_t *ps_mb_params;
806
807
128k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
808
128k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
809
810
    /* get the current layer ctxt */
811
128k
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
812
813
    /* ref layer mb mode */
814
128k
    ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) ps_lyr_mem->s_ref_mb_mode.pv_buffer;
815
128k
    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
128k
    i4_mb_x = ps_mb_params->u2_mbx;
819
128k
    i4_mb_y = ps_mb_params->u2_mby;
820
821
    /* set the intra MB flag to default TRUE */
822
128k
    i4_intra_mb_flag = SVCD_TRUE;
823
824
    /*-----------------------------------------------------------------------*/
825
    /* derive the reference layer part idc for all 16 partitions             */
826
    /*-----------------------------------------------------------------------*/
827
641k
    for(i4_blk_y = 0; i4_blk_y < NUM_SUB_MB_PARTS; i4_blk_y++)
828
513k
    {
829
2.56M
        for(i4_blk_x = 0; i4_blk_x < NUM_SUB_MB_PARTS; i4_blk_x++)
830
2.05M
        {
831
2.05M
            WORD32 i4_curr_x, i4_curr_y;
832
2.05M
            WORD32 i4_ref_x, i4_ref_y;
833
2.05M
            WORD32 i4_ref_mb_x, i4_ref_mb_y;
834
2.05M
            WORD8 i1_ref_mb_mode;
835
2.05M
            inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms_temp;
836
837
2.05M
            i4_curr_x = (i4_mb_x << 4) + (i4_blk_x << 2) + 1;
838
2.05M
            i4_curr_y = (i4_mb_y << 4) + (i4_blk_y << 2) + 1;
839
840
            /* get the colocated position in the refernce layer */
841
2.05M
            i4_ref_x = ps_lyr_mem->pi2_ref_loc_x[i4_curr_x];
842
2.05M
            i4_ref_y = ps_lyr_mem->pi2_ref_loc_y[i4_curr_y];
843
844
2.05M
            i4_ref_x = CLIP3(0, ((ps_lyr_mem->i4_ref_width) - 1), i4_ref_x);
845
846
2.05M
            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
2.05M
            i4_ref_mb_x = (i4_ref_x >> 4);
850
2.05M
            i4_ref_mb_y = (i4_ref_y >> 4);
851
852
            /* get the appropriate mb params in reference layer */
853
2.05M
            ps_inter_lyr_mb_prms_temp = ps_inter_lyr_mb_prms + i4_ref_mb_x;
854
2.05M
            ps_inter_lyr_mb_prms_temp += i4_ref_mb_y * i4_inter_lyr_mb_prms_stride;
855
856
2.05M
            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
2.05M
            if(i1_ref_mb_mode > SVC_INTER_MB)
860
271k
            {
861
                /* store the -1 value */
862
271k
                ai4_ref_part_idc[i4_blk_y][i4_blk_x] = -1;
863
271k
            }
864
1.78M
            else
865
1.78M
            {
866
                /* pack and store the reference x and y */
867
1.78M
                ai4_ref_part_idc[i4_blk_y][i4_blk_x] = (i4_ref_y << 16) + i4_ref_x;
868
1.78M
                i4_intra_mb_flag = SVCD_FALSE;
869
1.78M
            }
870
871
2.05M
        } /* end of block x loop */
872
873
513k
    }     /* 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
128k
    if(SVCD_FALSE == (ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag) &&
880
128k
       (SVCD_FALSE == i4_intra_mb_flag))
881
119k
    {
882
        /* replace values of "-1" on a 4x4 block basis */
883
119k
        WORD32 i4_xp, i4_yp;
884
119k
        WORD32 i4_indx_x, i4_indx_y;
885
119k
        WORD32 ai4_flag_8x8[2][2] = {SVCD_FALSE};
886
887
        /* loop over (4) 8x8 partitions */
888
357k
        for(i4_yp = 0; i4_yp < 2; i4_yp++)
889
238k
        {
890
715k
            for(i4_xp = 0; i4_xp < 2; i4_xp++)
891
477k
            {
892
477k
                WORD32 i4_xs, i4_ys;
893
477k
                WORD32 ai4_flag_4x4[2][2] = {SVCD_FALSE};
894
895
                /* loop over (4) 4x4 partitions */
896
1.43M
                for(i4_ys = 0; i4_ys < 2; i4_ys++)
897
954k
                {
898
2.86M
                    for(i4_xs = 0; i4_xs < 2; i4_xs++)
899
1.90M
                    {
900
                        /* index to the exact 4x4 block */
901
1.90M
                        i4_indx_y = (i4_yp << 1) + i4_ys;
902
1.90M
                        i4_indx_x = (i4_xp << 1) + i4_xs;
903
904
                        /* check if the current part idc is -1*/
905
1.90M
                        if(ai4_ref_part_idc[i4_indx_y][i4_indx_x] == -1)
906
127k
                        {
907
127k
                            WORD32 i4_temp_x = 1 - i4_xs;
908
127k
                            WORD32 i4_temp_y = 1 - i4_ys;
909
127k
                            WORD32 i4_temp_part_y = (i4_yp << 1) + i4_temp_y;
910
911
127k
                            WORD32 i4_temp_part_x = (i4_xp << 1) + i4_temp_x;
912
913
127k
                            ai4_flag_4x4[i4_ys][i4_xs] = SVCD_TRUE;
914
915
                            /* replace with appropriate values */
916
127k
                            if((SVCD_FALSE == ai4_flag_4x4[i4_ys][i4_temp_x]) &&
917
63.5k
                               (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
127k
                            else if((SVCD_FALSE == ai4_flag_4x4[i4_temp_y][i4_xs]) &&
923
63.5k
                                    (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
127k
                            else if((SVCD_FALSE == ai4_flag_4x4[i4_temp_y][i4_temp_x]) &&
929
63.5k
                                    (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
127k
                        } /* end of part idc equal to -1 check */
935
936
1.90M
                    }     /* end of sub partition xs loop */
937
938
954k
                }         /* end of sub partition ys loop */
939
940
477k
            }             /* end of partition xp loop */
941
942
238k
        }                 /* end of partition yp loop */
943
944
        /* replace values of "-1" on an 8x8 block basis */
945
946
        /* loop over (4) 8x8 partitions */
947
357k
        for(i4_yp = 0; i4_yp < 2; i4_yp++)
948
238k
        {
949
715k
            for(i4_xp = 0; i4_xp < 2; i4_xp++)
950
477k
            {
951
477k
                WORD32 i4_yp_inv = 1 - i4_yp;
952
477k
                WORD32 i4_xp_inv = 1 - i4_xp;
953
477k
                WORD32 i4_xo_inv = (2 - i4_xp);
954
477k
                WORD32 i4_yo_inv = (2 - i4_yp);
955
477k
                i4_indx_x = (i4_xp << 1);
956
477k
                i4_indx_y = (i4_yp << 1);
957
958
                /* check if the current part idc is -1*/
959
477k
                if(ai4_ref_part_idc[i4_indx_y][i4_indx_x] == -1)
960
31.7k
                {
961
31.7k
                    ai4_flag_8x8[i4_yp][i4_xp] = SVCD_TRUE;
962
963
                    /* replace the -1 with appropriate values */
964
31.7k
                    if(SVCD_FALSE == ai4_flag_8x8[i4_yp][i4_xp_inv] &&
965
24.9k
                       ai4_ref_part_idc[i4_indx_y][i4_xo_inv] != -1)
966
18.1k
                    {
967
18.1k
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
968
18.1k
                            ai4_ref_part_idc[i4_indx_y][i4_xo_inv];
969
970
18.1k
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x] =
971
18.1k
                            ai4_ref_part_idc[i4_indx_y + 1][i4_xo_inv];
972
973
18.1k
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x + 1] =
974
18.1k
                            ai4_ref_part_idc[i4_indx_y][i4_xo_inv];
975
976
18.1k
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x + 1] =
977
18.1k
                            ai4_ref_part_idc[i4_indx_y + 1][i4_xo_inv];
978
18.1k
                    }
979
13.6k
                    else if(SVCD_FALSE == ai4_flag_8x8[i4_yp_inv][i4_xp] &&
980
13.3k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x] != -1)
981
13.0k
                    {
982
13.0k
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
983
13.0k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x];
984
985
13.0k
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x] =
986
13.0k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x];
987
988
13.0k
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x + 1] =
989
13.0k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x + 1];
990
991
13.0k
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x + 1] =
992
13.0k
                            ai4_ref_part_idc[i4_yo_inv][i4_indx_x + 1];
993
13.0k
                    }
994
567
                    else if(SVCD_FALSE == ai4_flag_8x8[i4_yp_inv][i4_xp_inv] &&
995
567
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv] != -1)
996
567
                    {
997
567
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x] =
998
567
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv];
999
1000
567
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x] =
1001
567
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv];
1002
1003
567
                        ai4_ref_part_idc[i4_indx_y][i4_indx_x + 1] =
1004
567
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv];
1005
1006
567
                        ai4_ref_part_idc[i4_indx_y + 1][i4_indx_x + 1] =
1007
567
                            ai4_ref_part_idc[i4_yo_inv][i4_xo_inv];
1008
567
                    }
1009
31.7k
                } /* end of part idc equal to -1 check */
1010
1011
477k
            }     /* end of partition xp loop */
1012
1013
238k
        }         /* end of partition yp loop */
1014
1015
119k
    }             /* end of refinement of part idc for non dyadic case*/
1016
1017
    /* store the intra flag in the location provided */
1018
128k
    *pi4_intra_flag = i4_intra_mb_flag;
1019
1020
128k
    return;
1021
128k
}
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
530k
{
1050
530k
    mv_pred_t *ps_part_a;
1051
530k
    mv_pred_t *ps_part_b;
1052
530k
    WORD32 i4_cntr;
1053
530k
    WORD32 i4_mv_treshold;
1054
530k
    WORD32 i4_flag = 0;
1055
1056
530k
    ps_part_a = (mv_pred_t *) pv_motion_prm_mb_part_a;
1057
530k
    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
631k
    {
1061
        /* calculate the absolute diff of both components */
1062
631k
        i4_mv_treshold = ABS((ps_part_a->i2_mv[2 * i4_cntr]) - (ps_part_b->i2_mv[2 * i4_cntr]));
1063
631k
        i4_mv_treshold +=
1064
631k
            ABS((ps_part_a->i2_mv[1 + 2 * i4_cntr]) - (ps_part_b->i2_mv[1 + 2 * i4_cntr]));
1065
1066
631k
        if((0 == i4_mv_treshold) &&
1067
590k
           (ps_part_a->i1_ref_frame[i4_cntr] == ps_part_b->i1_ref_frame[i4_cntr]))
1068
582k
        {
1069
582k
            i4_flag = 1;
1070
582k
        }
1071
49.0k
        else
1072
49.0k
        {
1073
49.0k
            i4_flag = 0;
1074
49.0k
            return (i4_flag);
1075
49.0k
        }
1076
1077
631k
    } /* end of loop over lists */
1078
1079
481k
    return (i4_flag);
1080
530k
}
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.27M
{
1105
2.27M
    UWORD32 u4_x, u4_y;
1106
2.27M
    WORD32 i4_min_positive;
1107
1108
    /* get positive values */
1109
2.27M
    u4_x = (UWORD32) i4_input_1;
1110
2.27M
    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.27M
    if((u4_y < u4_x) && (0 <= i4_input_2))
1128
3.70k
    {
1129
3.70k
        i4_min_positive = i4_input_2;
1130
3.70k
    }
1131
2.26M
    else
1132
2.26M
    {
1133
2.26M
        i4_min_positive = i4_input_1;
1134
2.26M
    }
1135
2.27M
    return (i4_min_positive);
1136
2.27M
}
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.11M
{
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.11M
    mode_motion_ctxt_t *ps_ctxt;
1294
2.11M
    mode_motion_lyr_ctxt *ps_lyr_mem;
1295
2.11M
    mv_pred_t *ps_motion_pred;
1296
2.11M
    mv_pred_t *ps_ref_mv;
1297
2.11M
    WORD32 i4_lists;
1298
2.11M
    WORD32 i4_ref_16x16_flag = 0;
1299
2.11M
    WORD32 i4_scale_x, i4_scale_y;
1300
2.11M
    WORD16 i2_max_mv_x, i2_max_mv_y;
1301
1302
2.11M
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
1303
1304
    /* get the current layer ctxt */
1305
2.11M
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
1306
1307
    /* ----------- Get the reference layer MV structure ---------- */
1308
2.11M
    {
1309
2.11M
        mv_pred_t *ps_ref_lyr_motion_prms;
1310
2.11M
        WORD32 i4_ref_x, i4_ref_y;
1311
2.11M
        WORD32 i4_ref_mb_x, i4_ref_mb_y;
1312
2.11M
        WORD32 i4_ref_width;
1313
1314
2.11M
        ps_ref_lyr_motion_prms = (mv_pred_t *) ps_lyr_mem->pv_ref_mv_bank_l0;
1315
2.11M
        i4_ref_width = ps_lyr_mem->i4_ref_width;
1316
2.11M
        i2_max_mv_x = i4_ref_width << 2;
1317
2.11M
        i2_max_mv_y = ps_lyr_mem->i4_ref_height << 2;
1318
1319
        /* extract the reference x and y positions */
1320
2.11M
        i4_ref_x = (*pi4_ref_part_idc) & 0xFFFF;
1321
2.11M
        i4_ref_y = (*pi4_ref_part_idc) >> 16;
1322
1323
        /* get the reference mb x and y */
1324
2.11M
        i4_ref_mb_x = (i4_ref_x >> 4);
1325
2.11M
        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.11M
        ps_ref_mv = ps_ref_lyr_motion_prms + (i4_ref_mb_x << 4);
1330
2.11M
        ps_ref_mv += (i4_ref_mb_y * i4_ref_width);
1331
1332
        /* if reference layer mb type is non 16x16 */
1333
2.11M
        if(0 == i4_ref_16x16_flag)
1334
2.11M
        {
1335
            /* increment the pointer to appropaite 4x4 */
1336
2.11M
            ps_ref_mv += ((i4_ref_x >> 2) & 0x03);
1337
2.11M
            ps_ref_mv += (((i4_ref_y >> 2) & 0x03) << 2);
1338
2.11M
        }
1339
2.11M
    }
1340
1341
    /* motion pred structure */
1342
2.11M
    ps_motion_pred = pv_motion_pred;
1343
1344
    /* retrive the scale factors */
1345
2.11M
    i4_scale_x = ps_lyr_mem->i4_scale_mv_x;
1346
2.11M
    i4_scale_y = ps_lyr_mem->i4_scale_mv_y;
1347
1348
    /* loop on the lists given as input */
1349
4.68M
    for(i4_lists = 0; i4_lists < i4_listx; i4_lists++)
1350
2.56M
    {
1351
2.56M
        WORD32 i4_mv_x, i4_mv_y;
1352
2.56M
        WORD16 i2_mv_x, i2_mv_y;
1353
1354
        /* if the refernce index is -1 set the default values */
1355
2.56M
        if(-1 == ps_ref_mv->i1_ref_frame[i4_lists])
1356
277k
        {
1357
277k
            ps_motion_pred->i1_ref_frame[i4_lists] = -1;
1358
277k
            ps_motion_pred->i2_mv[2 * i4_lists] = 0;
1359
277k
            ps_motion_pred->i2_mv[1 + 2 * i4_lists] = 0;
1360
277k
        }
1361
2.28M
        else
1362
2.28M
        {
1363
            /* field MB and field pictures modification are present */
1364
            /* currently not implemented */
1365
2.28M
            ps_motion_pred->i1_ref_frame[i4_lists] = ps_ref_mv->i1_ref_frame[i4_lists];
1366
1367
2.28M
            i2_mv_x = ps_ref_mv->i2_mv[2 * i4_lists];
1368
2.28M
            i2_mv_y = ps_ref_mv->i2_mv[1 + 2 * i4_lists];
1369
2.28M
            i2_mv_x = CLIP3(-i2_max_mv_x, i2_max_mv_x, i2_mv_x);
1370
2.28M
            i2_mv_y = CLIP3(-i2_max_mv_y, i2_max_mv_y, i2_mv_y);
1371
            /* scale the motion vectors */
1372
2.28M
            i4_mv_x = (i2_mv_x * i4_scale_x + 32768) >> 16;
1373
2.28M
            i4_mv_y = (i2_mv_y * i4_scale_y + 32768) >> 16;
1374
1375
            /* store the final motion vectors */
1376
2.28M
            ps_motion_pred->i2_mv[2 * i4_lists] = i4_mv_x;
1377
2.28M
            ps_motion_pred->i2_mv[1 + 2 * i4_lists] = i4_mv_y;
1378
1379
            /* if cropping change flag is present */
1380
2.28M
            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.28M
        }
1388
2.56M
    } /* end of lists loop */
1389
1390
2.11M
    return (i4_ref_16x16_flag);
1391
2.11M
}
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
209k
{
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
209k
    WORD32 i4_i, i4_j;
1432
209k
    mv_pred_t *ps_mv_pred_src;
1433
209k
    mv_pred_t *ps_mv_map_dst;
1434
1435
209k
    ps_mv_pred_src = (mv_pred_t *) pv_motion_pred;
1436
209k
    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
629k
    for(i4_i = 0; i4_i < i4_part_height; i4_i++)
1440
419k
    {
1441
1.25M
        for(i4_j = 0; i4_j < i4_part_width; i4_j++)
1442
839k
        {
1443
            /* copy form source to destination */
1444
839k
            *(ps_mv_map_dst + i4_j) = *(ps_mv_pred_src + (i4_src_update_flag * i4_j));
1445
1446
839k
        } /* end of loop over partition width */
1447
1448
419k
        ps_mv_map_dst += i4_dst_stride;
1449
419k
        ps_mv_pred_src += (i4_src_stride * i4_src_update_flag);
1450
1451
419k
    } /* end of loop over partition height */
1452
209k
    return;
1453
209k
}
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.38M
{
1483
2.38M
    mv_pred_t *ps_part_a;
1484
2.38M
    mv_pred_t *ps_part_b;
1485
2.38M
    WORD32 i4_cntr;
1486
2.38M
    WORD32 i4_mv_treshold;
1487
2.38M
    WORD32 i4_flag;
1488
1489
2.38M
    ps_part_a = (mv_pred_t *) pv_motion_prm_a;
1490
2.38M
    ps_part_b = (mv_pred_t *) pv_motion_prm_b;
1491
1492
2.38M
    i4_flag = 1;
1493
5.17M
    for(i4_cntr = 0; i4_cntr < i4_listx; i4_cntr++)
1494
2.83M
    {
1495
        /* calculate the absolute diff of both components */
1496
2.83M
        i4_mv_treshold = ABS((ps_part_a->i2_mv[2 * i4_cntr]) - (ps_part_b->i2_mv[2 * i4_cntr]));
1497
2.83M
        i4_mv_treshold +=
1498
2.83M
            ABS((ps_part_a->i2_mv[1 + (2 * i4_cntr)]) - (ps_part_b->i2_mv[1 + (2 * i4_cntr)]));
1499
1500
2.83M
        if(i4_actual_threshold < i4_mv_treshold)
1501
41.5k
        {
1502
41.5k
            i4_flag = 0;
1503
41.5k
            break;
1504
41.5k
        }
1505
1506
2.83M
    } /* end of loop over lists */
1507
2.38M
    return (i4_flag);
1508
2.38M
}
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
119k
{
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
119k
    mode_motion_ctxt_t *ps_ctxt;
1558
119k
    mode_motion_lyr_ctxt *ps_lyr_mem;
1559
119k
    mv_pred_t *ps_motion_pred;
1560
119k
    dec_mb_info_t *ps_mb_params;
1561
119k
    dec_svc_mb_info_t *ps_svc_mb_params;
1562
119k
    WORD32 i4_blk_y, i4_blk_x;
1563
119k
    WORD32 i4_i;
1564
119k
    WORD32 i4_listx;
1565
119k
    WORD32 i4_mv_treshold;
1566
119k
    WORD32 ai4_temp_ref_indx[NUM_REF_LISTS][NUM_MB_PARTS] = {0};
1567
119k
    WORD32 i4_mb_x, i4_mb_y;
1568
119k
    WORD32 i4_mb_pic_x, i4_mb_pic_y;
1569
119k
    dec_struct_t *ps_dec;
1570
1571
119k
    ps_dec = (dec_struct_t *) pv_dec;
1572
119k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
1573
1574
    /* get the current layer ctxt */
1575
119k
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
1576
1577
119k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
1578
119k
    ps_svc_mb_params = (dec_svc_mb_info_t *) pv_svc_mb_params;
1579
119k
    ps_motion_pred = ps_ctxt->ps_motion_pred_struct;
1580
1581
119k
    i4_listx = ps_ctxt->i4_listx;
1582
1583
    /* derive the MB_X and MB_Y for the current MB */
1584
119k
    i4_mb_x = ps_mb_params->u2_mbx;
1585
119k
    i4_mb_y = ps_mb_params->u2_mby;
1586
1587
    /* convert into picture units */
1588
119k
    i4_mb_pic_x = i4_mb_x << 4;
1589
119k
    i4_mb_pic_y = i4_mb_y << 4;
1590
1591
    /* compute the motion vectors and reference indices of all part */
1592
596k
    for(i4_blk_y = 0; i4_blk_y < NUM_SUB_MB_PARTS; i4_blk_y++)
1593
477k
    {
1594
2.38M
        for(i4_blk_x = 0; i4_blk_x < NUM_SUB_MB_PARTS; i4_blk_x++)
1595
1.90M
        {
1596
1.90M
            isvcd_interlyr_motion_scale(pv_comp_mode_mv_ctxt, &ai4_ref_part_idc[i4_blk_y][i4_blk_x],
1597
1.90M
                                        ps_mb_params, (ps_motion_pred + (4 * i4_blk_y) + i4_blk_x),
1598
1.90M
                                        i4_listx, (i4_mb_pic_x + (i4_blk_x << 2) + 1),
1599
1.90M
                                        (i4_mb_pic_y + (i4_blk_y << 2) + 1),
1600
1.90M
                                        ps_dec->ppv_map_ref_idx_to_poc);
1601
1602
1.90M
        } /* end of blk x loop */
1603
477k
    }     /* end of blk y loop */
1604
1605
    /********************************************************/
1606
    /* get the final reference index into a temparory array */
1607
    /********************************************************/
1608
1609
    /* set reference indices */
1610
261k
    for(i4_i = 0; i4_i < i4_listx; i4_i++)
1611
141k
    {
1612
141k
        ai4_temp_ref_indx[i4_i][0] = ps_motion_pred[0].i1_ref_frame[i4_i];
1613
141k
        ai4_temp_ref_indx[i4_i][1] = ps_motion_pred[2].i1_ref_frame[i4_i];
1614
141k
        ai4_temp_ref_indx[i4_i][2] = ps_motion_pred[8].i1_ref_frame[i4_i];
1615
141k
        ai4_temp_ref_indx[i4_i][3] = ps_motion_pred[10].i1_ref_frame[i4_i];
1616
1617
141k
    } /* end of loop over lists */
1618
1619
    /* if restricted spatial resolution change is not set */
1620
119k
    if(SVCD_FALSE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag)
1621
119k
    {
1622
119k
        WORD32 i4_xp, i4_yp;
1623
119k
        WORD32 i4_xs, i4_ys;
1624
1625
        /* merge reference indices and modify the motion vectors */
1626
261k
        for(i4_i = 0; i4_i < i4_listx; i4_i++)
1627
141k
        {
1628
425k
            for(i4_yp = 0; i4_yp < 2; i4_yp++)
1629
283k
            {
1630
851k
                for(i4_xp = 0; i4_xp < 2; i4_xp++)
1631
567k
                {
1632
                    /* get the minimum positive of the refernce index */
1633
1.70M
                    for(i4_ys = 0; i4_ys < 2; i4_ys++)
1634
1.13M
                    {
1635
3.40M
                        for(i4_xs = 0; i4_xs < 2; i4_xs++)
1636
2.27M
                        {
1637
2.27M
                            mv_pred_t *ps_temp;
1638
2.27M
                            ps_temp = ps_motion_pred + (i4_xp << 1) + i4_xs;
1639
2.27M
                            ps_temp += 4 * ((i4_yp << 1) + i4_ys);
1640
1641
                            /* get the minimum positive */
1642
2.27M
                            ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp] =
1643
2.27M
                                isvcd_get_min_positive(ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp],
1644
2.27M
                                                       ps_temp->i1_ref_frame[i4_i]);
1645
2.27M
                        }
1646
1.13M
                    }
1647
                    /* update motion vectors */
1648
1.70M
                    for(i4_ys = 0; i4_ys < 2; i4_ys++)
1649
1.13M
                    {
1650
3.40M
                        for(i4_xs = 0; i4_xs < 2; i4_xs++)
1651
2.27M
                        {
1652
2.27M
                            mv_pred_t *ps_temp;
1653
2.27M
                            ps_temp = ps_motion_pred + (i4_xp << 1) + i4_xs;
1654
2.27M
                            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.27M
                            if(ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp] !=
1660
2.27M
                               ps_temp->i1_ref_frame[i4_i])
1661
9.78k
                            {
1662
9.78k
                                mv_pred_t *ps_temp_1;
1663
9.78k
                                WORD32 i4_updated_flag = SVCD_FALSE;
1664
1665
9.78k
                                ps_temp_1 = ps_motion_pred + (i4_xp << 1) + (1 - i4_xs);
1666
9.78k
                                ps_temp_1 += 4 * ((i4_yp << 1) + i4_ys);
1667
1668
                                /* store the appropriate neighbours */
1669
9.78k
                                if(ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp] ==
1670
9.78k
                                   ps_temp_1->i1_ref_frame[i4_i])
1671
4.18k
                                {
1672
4.18k
                                    ps_temp->i2_mv[2 * i4_i] = ps_temp_1->i2_mv[2 * i4_i];
1673
1674
4.18k
                                    ps_temp->i2_mv[1 + (2 * i4_i)] =
1675
4.18k
                                        ps_temp_1->i2_mv[1 + (2 * i4_i)];
1676
4.18k
                                    i4_updated_flag = SVCD_TRUE;
1677
4.18k
                                }
1678
1679
9.78k
                                if(SVCD_FALSE == i4_updated_flag)
1680
5.59k
                                {
1681
5.59k
                                    ps_temp_1 = ps_motion_pred + (i4_xp << 1) + i4_xs;
1682
1683
5.59k
                                    ps_temp_1 += 4 * ((i4_yp << 1) + 1 - i4_ys);
1684
1685
5.59k
                                    if(ai4_temp_ref_indx[i4_i][2 * i4_yp + i4_xp] ==
1686
5.59k
                                       ps_temp_1->i1_ref_frame[i4_i])
1687
5.26k
                                    {
1688
5.26k
                                        ps_temp->i2_mv[2 * i4_i] = ps_temp_1->i2_mv[2 * i4_i];
1689
1690
5.26k
                                        ps_temp->i2_mv[1 + (2 * i4_i)] =
1691
5.26k
                                            ps_temp_1->i2_mv[1 + (2 * i4_i)];
1692
5.26k
                                        i4_updated_flag = SVCD_TRUE;
1693
5.26k
                                    }
1694
5.59k
                                }
1695
9.78k
                                if(SVCD_FALSE == i4_updated_flag)
1696
329
                                {
1697
329
                                    ps_temp_1 = ps_motion_pred + (i4_xp << 1) + (1 - i4_xs);
1698
329
                                    ps_temp_1 += 4 * ((i4_yp << 1) + 1 - i4_ys);
1699
1700
329
                                    ps_temp->i2_mv[2 * i4_i] = ps_temp_1->i2_mv[2 * i4_i];
1701
1702
329
                                    ps_temp->i2_mv[1 + (2 * i4_i)] =
1703
329
                                        ps_temp_1->i2_mv[1 + (2 * i4_i)];
1704
1705
329
                                    i4_updated_flag = SVCD_TRUE;
1706
329
                                }
1707
9.78k
                            } /* end of replacement of mv based on ref indx */
1708
2.27M
                        }     /* end of loop over sub partition xs */
1709
1.13M
                    }         /* end of loop over sub partition ys */
1710
567k
                }             /* end of loop over partition xp */
1711
283k
            }                 /* end of loop over partition yp */
1712
141k
        }                     /* end of loop over lists */
1713
119k
    }
1714
1715
    /************************************************************************/
1716
    /* if restircted saptial resolution change flag is 0                    */
1717
    /* modify the reference indixes and motion vectors                      */
1718
    /************************************************************************/
1719
119k
    if((SVCD_FALSE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag) &&
1720
119k
       (2 == i4_listx) && (SVCD_TRUE == ps_ctxt->u1_direct_8x8_inference_flag))
1721
9.79k
    {
1722
        /* only applicable for EB Slice */
1723
        /* store the corner 4x4 motion vectors to the whole block */
1724
        /* 2 lists and 4 partitions */
1725
9.79k
        mot_vec_t s_temp_mv[2][4];
1726
9.79k
        WORD32 i4_xp, i4_yp;
1727
9.79k
        memset(&s_temp_mv[0][0], 0, sizeof(s_temp_mv));
1728
1729
29.3k
        for(i4_i = 0; i4_i < i4_listx; i4_i++)
1730
19.5k
        {
1731
19.5k
            s_temp_mv[i4_i][0].i2_mv_x = ps_motion_pred[0].i2_mv[2 * i4_i];
1732
19.5k
            s_temp_mv[i4_i][0].i2_mv_y = ps_motion_pred[0].i2_mv[1 + (2 * i4_i)];
1733
1734
19.5k
            s_temp_mv[i4_i][1].i2_mv_x = ps_motion_pred[3].i2_mv[2 * i4_i];
1735
19.5k
            s_temp_mv[i4_i][1].i2_mv_y = ps_motion_pred[3].i2_mv[1 + (2 * i4_i)];
1736
1737
19.5k
            s_temp_mv[i4_i][2].i2_mv_x = ps_motion_pred[12].i2_mv[2 * i4_i];
1738
19.5k
            s_temp_mv[i4_i][2].i2_mv_y = ps_motion_pred[12].i2_mv[1 + (2 * i4_i)];
1739
1740
19.5k
            s_temp_mv[i4_i][3].i2_mv_x = ps_motion_pred[15].i2_mv[2 * i4_i];
1741
19.5k
            s_temp_mv[i4_i][3].i2_mv_y = ps_motion_pred[15].i2_mv[1 + (2 * i4_i)];
1742
1743
19.5k
        } /* end of loop over lists */
1744
1745
        /* replace the motion vectors */
1746
29.3k
        for(i4_i = 0; i4_i < i4_listx; i4_i++)
1747
19.5k
        {
1748
97.9k
            for(i4_yp = 0; i4_yp < 4; i4_yp++)
1749
78.3k
            {
1750
391k
                for(i4_xp = 0; i4_xp < 4; i4_xp++)
1751
313k
                {
1752
313k
                    mv_pred_t *ps_temp;
1753
313k
                    ps_temp = ps_motion_pred + i4_xp;
1754
313k
                    ps_temp += 4 * i4_yp;
1755
1756
313k
                    ps_temp->i2_mv[2 * i4_i] =
1757
313k
                        s_temp_mv[i4_i][2 * (i4_yp >> 1) + (i4_xp >> 1)].i2_mv_x;
1758
1759
313k
                    ps_temp->i2_mv[1 + (2 * i4_i)] =
1760
313k
                        s_temp_mv[i4_i][2 * (i4_yp >> 1) + (i4_xp >> 1)].i2_mv_y;
1761
1762
313k
                } /* end of loop over sub partitions xp */
1763
78.3k
            }     /* end of loop over sub partitions yp */
1764
19.5k
        }         /* end of loop over lists */
1765
9.79k
    }
1766
1767
    /* store the final reference index for all sub partitions */
1768
    /* approporiate reference index is stored for each 4x4 belonging to 8x8 */
1769
119k
    {
1770
119k
        WORD32 i4_xp, i4_yp;
1771
1772
261k
        for(i4_i = 0; i4_i < i4_listx; i4_i++)
1773
141k
        {
1774
709k
            for(i4_yp = 0; i4_yp < 4; i4_yp++)
1775
567k
            {
1776
2.83M
                for(i4_xp = 0; i4_xp < 4; i4_xp++)
1777
2.27M
                {
1778
2.27M
                    mv_pred_t *ps_temp;
1779
2.27M
                    ps_temp = ps_motion_pred + i4_xp;
1780
2.27M
                    ps_temp += 4 * i4_yp;
1781
1782
2.27M
                    ps_temp->i1_ref_frame[i4_i] =
1783
2.27M
                        ai4_temp_ref_indx[i4_i][2 * (i4_yp >> 1) + (i4_xp >> 1)];
1784
1785
2.27M
                } /* end of loop over partition xp */
1786
567k
            }     /* end of loop over partition yp */
1787
141k
        }         /* end of loop over lists */
1788
119k
    }
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
119k
    if(SVCD_FALSE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag)
1795
119k
    {
1796
        /* non dyadic cases set the mv treshold to 1 */
1797
119k
        i4_mv_treshold = 1;
1798
119k
    }
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
119k
    if((SVCD_FALSE == ps_lyr_mem->ps_curr_lyr_res_prms->u1_rstrct_res_change_flag) ||
1807
0
       (1 == ps_svc_mb_params->u1_base_mode_flag))
1808
119k
    {
1809
119k
        WORD32 i4_xp, i4_yp;
1810
357k
        for(i4_yp = 0; i4_yp < 2; i4_yp++)
1811
238k
        {
1812
715k
            for(i4_xp = 0; i4_xp < 2; i4_xp++)
1813
477k
            {
1814
477k
                mv_pred_t *ps_temp;
1815
477k
                WORD32 i4_part_size = 0;
1816
477k
                WORD32 i4_horz1_match, i4_vert1_match;
1817
477k
                WORD32 i4_horz2_match, i4_vert2_match;
1818
477k
                WORD32 i4_diag_match;
1819
1820
477k
                WORD32 i4_8x8_match, i4_horz_match, i4_vert_match;
1821
477k
                WORD32 i4_mv_x, i4_mv_y;
1822
1823
477k
                ps_temp = ps_motion_pred + (i4_xp << 1);
1824
477k
                ps_temp += 4 * ((i4_yp << 1));
1825
1826
                /* default init */
1827
477k
                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
477k
                i4_horz1_match =
1831
477k
                    isvcd_check_mv_diff(ps_temp, (ps_temp + 1), i4_listx, i4_mv_treshold);
1832
1833
477k
                i4_horz2_match =
1834
477k
                    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
477k
                i4_vert1_match =
1838
477k
                    isvcd_check_mv_diff(ps_temp, (ps_temp + 4), i4_listx, i4_mv_treshold);
1839
1840
477k
                i4_vert2_match =
1841
477k
                    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
477k
                i4_diag_match =
1845
477k
                    isvcd_check_mv_diff(ps_temp, (ps_temp + 4 + 1), i4_listx, i4_mv_treshold);
1846
1847
                /* calculate the excat matching points*/
1848
477k
                i4_8x8_match = i4_8x8_match && i4_horz1_match && i4_vert1_match && i4_diag_match;
1849
477k
                i4_horz_match = i4_horz_match && i4_horz1_match && i4_horz2_match;
1850
477k
                i4_vert_match = i4_vert_match && i4_vert1_match && i4_vert2_match;
1851
1852
                /* modify the motion vectors appropriately */
1853
1854
1.04M
                for(i4_i = 0; i4_i < i4_listx; i4_i++)
1855
567k
                {
1856
                    /* 8x8 mode all the 4 blocks are under threshold */
1857
567k
                    if(SVCD_TRUE == i4_8x8_match)
1858
552k
                    {
1859
                        /* calculate the avarage */
1860
552k
                        i4_mv_x =
1861
552k
                            ((ps_temp[0].i2_mv[2 * i4_i]) + (ps_temp[1].i2_mv[2 * i4_i]) +
1862
552k
                             (ps_temp[4].i2_mv[2 * i4_i]) + (ps_temp[5].i2_mv[2 * i4_i] + 2)) >>
1863
552k
                            2;
1864
1865
552k
                        i4_mv_y = ((ps_temp[0].i2_mv[1 + (2 * i4_i)]) +
1866
552k
                                   (ps_temp[1].i2_mv[1 + (2 * i4_i)]) +
1867
552k
                                   (ps_temp[4].i2_mv[1 + (2 * i4_i)]) +
1868
552k
                                   (ps_temp[5].i2_mv[1 + (2 * i4_i)] + 2)) >>
1869
552k
                                  2;
1870
1871
                        /* store the modified motion vectors */
1872
552k
                        ps_temp[0].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1873
552k
                        ps_temp[1].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1874
552k
                        ps_temp[4].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1875
552k
                        ps_temp[5].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1876
1877
552k
                        ps_temp[0].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1878
552k
                        ps_temp[1].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1879
552k
                        ps_temp[4].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1880
552k
                        ps_temp[5].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1881
1882
                        /* store the sub mb partition size */
1883
552k
                        i4_part_size = SUBMB_8x8;
1884
552k
                    }
1885
                    /* 8x4 mode  */
1886
15.1k
                    else if(SVCD_TRUE == i4_horz_match)
1887
7.24k
                    {
1888
                        /* horizontal directional merging */
1889
                        /* calculate the average of first two and store back*/
1890
7.24k
                        i4_mv_x =
1891
7.24k
                            ((ps_temp[0].i2_mv[2 * i4_i]) + (ps_temp[1].i2_mv[2 * i4_i] + 1)) >> 1;
1892
1893
7.24k
                        i4_mv_y = ((ps_temp[0].i2_mv[1 + (2 * i4_i)]) +
1894
7.24k
                                   (ps_temp[1].i2_mv[1 + (2 * i4_i)] + 1)) >>
1895
7.24k
                                  1;
1896
1897
7.24k
                        ps_temp[0].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1898
7.24k
                        ps_temp[1].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1899
1900
7.24k
                        ps_temp[0].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1901
7.24k
                        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.24k
                        i4_mv_x =
1905
7.24k
                            ((ps_temp[4].i2_mv[2 * i4_i]) + (ps_temp[5].i2_mv[2 * i4_i] + 1)) >> 1;
1906
1907
7.24k
                        i4_mv_y = ((ps_temp[4].i2_mv[1 + (2 * i4_i)]) +
1908
7.24k
                                   (ps_temp[5].i2_mv[1 + (2 * i4_i)] + 1)) >>
1909
7.24k
                                  1;
1910
1911
7.24k
                        ps_temp[4].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1912
7.24k
                        ps_temp[5].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1913
1914
7.24k
                        ps_temp[4].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1915
7.24k
                        ps_temp[5].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1916
                        /* store the sub mb partition size */
1917
7.24k
                        i4_part_size = SUBMB_8x4;
1918
7.24k
                    }
1919
                    /* 4x8 mode all the 4 blocks are under threshold */
1920
7.93k
                    else if(SVCD_TRUE == i4_vert_match)
1921
7.01k
                    {
1922
                        /* vertical directional merging */
1923
7.01k
                        i4_mv_x =
1924
7.01k
                            ((ps_temp[0].i2_mv[2 * i4_i]) + (ps_temp[4].i2_mv[2 * i4_i] + 1)) >> 1;
1925
1926
7.01k
                        i4_mv_y = ((ps_temp[0].i2_mv[1 + (2 * i4_i)]) +
1927
7.01k
                                   (ps_temp[4].i2_mv[1 + (2 * i4_i)] + 1)) >>
1928
7.01k
                                  1;
1929
1930
7.01k
                        ps_temp[0].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1931
7.01k
                        ps_temp[4].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1932
1933
7.01k
                        ps_temp[0].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1934
7.01k
                        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.01k
                        i4_mv_x =
1938
7.01k
                            ((ps_temp[1].i2_mv[2 * i4_i]) + (ps_temp[5].i2_mv[2 * i4_i] + 1)) >> 1;
1939
1940
7.01k
                        i4_mv_y = ((ps_temp[1].i2_mv[1 + (2 * i4_i)]) +
1941
7.01k
                                   (ps_temp[5].i2_mv[1 + (2 * i4_i)] + 1)) >>
1942
7.01k
                                  1;
1943
1944
7.01k
                        ps_temp[1].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1945
7.01k
                        ps_temp[5].i2_mv[2 * i4_i] = (WORD16) i4_mv_x;
1946
1947
7.01k
                        ps_temp[1].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1948
7.01k
                        ps_temp[5].i2_mv[1 + (2 * i4_i)] = (WORD16) i4_mv_y;
1949
                        /* store the sub mb partition size */
1950
7.01k
                        i4_part_size = SUBMB_4x8;
1951
7.01k
                    }
1952
929
                    else
1953
929
                    {
1954
                        /* store the sub mb partition size */
1955
929
                        i4_part_size = SUBMB_4x4;
1956
929
                    }
1957
1958
567k
                } /* end of loop over lists */
1959
1960
                /* store the sub MB type B slice */
1961
477k
                if(2 == i4_listx)
1962
90.5k
                {
1963
90.5k
                    WORD32 i4_part_mode_a;
1964
90.5k
                    WORD32 i4_indx;
1965
1966
90.5k
                    i4_part_mode_a = 0;
1967
                    /* check the 0th partiton reference indices */
1968
90.5k
                    if(0 <= ps_temp[0].i1_ref_frame[0])
1969
76.6k
                    {
1970
76.6k
                        i4_part_mode_a += 1;
1971
76.6k
                    }
1972
90.5k
                    if(0 <= ps_temp[0].i1_ref_frame[1])
1973
49.6k
                    {
1974
49.6k
                        i4_part_mode_a += 2;
1975
49.6k
                    }
1976
90.5k
                    i4_indx = 3 * i4_part_size + (i4_part_mode_a - 1);
1977
1978
90.5k
                    pi4_sub_mb_mode[2 * i4_yp + i4_xp] = g_au1_eb_submb_type[i4_indx];
1979
90.5k
                }
1980
                /* P slice */
1981
386k
                else
1982
386k
                {
1983
386k
                    pi4_sub_mb_mode[2 * i4_yp + i4_xp] = g_au1_ep_submb_type[i4_part_size];
1984
386k
                }
1985
477k
            } /* end of loop over partition xp */
1986
1987
238k
        }     /* end of loop over partition yp */
1988
119k
    }
1989
1990
119k
    return;
1991
119k
}
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.8k
{
2021
30.8k
    WORD32 i4_part_mode_a, i4_part_mode_b;
2022
30.8k
    WORD32 i4_idx;
2023
30.8k
    dec_mb_info_t *ps_mb_params = (dec_mb_info_t *) pv_mb_params;
2024
30.8k
    parse_part_params_t *ps_part = (parse_part_params_t *) pv_part;
2025
2026
30.8k
    UNUSED(ps_ctxt);
2027
2028
30.8k
    i4_part_mode_a = 0;
2029
2030
    /* check the 0th partiton reference indices */
2031
30.8k
    if(PRED_8x8 != i4_part_size)
2032
26.4k
    {
2033
26.4k
        if(0 <= ps_motion_pred[0].i1_ref_frame[0])
2034
23.0k
        {
2035
23.0k
            i4_part_mode_a += 1;
2036
23.0k
        }
2037
26.4k
        if(0 <= ps_motion_pred[0].i1_ref_frame[1])
2038
12.5k
        {
2039
12.5k
            i4_part_mode_a += 2;
2040
12.5k
        }
2041
26.4k
    }
2042
2043
    /* check the 15th partiton reference indices */
2044
    /* this done since all the reference indices will be replicated */
2045
30.8k
    i4_part_mode_b = 0;
2046
2047
30.8k
    if((PRED_16x8 == i4_part_size) || (PRED_8x16 == i4_part_size))
2048
5.58k
    {
2049
5.58k
        ps_motion_pred += (3 * i4_cur_mot_stride) + 3;
2050
2051
5.58k
        if(0 <= ps_motion_pred[0].i1_ref_frame[0])
2052
4.00k
        {
2053
4.00k
            i4_part_mode_b += 1;
2054
4.00k
        }
2055
5.58k
        if(0 <= ps_motion_pred[0].i1_ref_frame[1])
2056
2.68k
        {
2057
2.68k
            i4_part_mode_b += 2;
2058
2.68k
        }
2059
5.58k
    }
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.8k
    if(PRED_8x8 != i4_part_size)
2065
26.4k
    {
2066
26.4k
        UWORD8 u1_pred_mode_part0;
2067
26.4k
        UWORD8 u1_pred_mode_part1;
2068
2069
26.4k
        i4_idx = 3 * i4_part_size;
2070
26.4k
        i4_idx += 3 * (i4_part_mode_a - 1);
2071
26.4k
        i4_part_mode_b = (i4_part_mode_b > 0) ? i4_part_mode_b : 1;
2072
26.4k
        i4_idx += (i4_part_mode_b - 1);
2073
26.4k
        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
26.4k
        ps_mb_params->u1_mb_type = g_au1_eb_mb_type[i4_idx + (6 * i4_part_size)];
2081
26.4k
        u1_pred_mode_part0 = g_au1_mb_pred_mode[0][5 + ps_mb_params->u1_mb_type];
2082
26.4k
        u1_pred_mode_part1 = g_au1_mb_pred_mode[1][5 + ps_mb_params->u1_mb_type];
2083
26.4k
        ps_part[0].u1_pred_mode = u1_pred_mode_part0;
2084
26.4k
        ps_part[1].u1_pred_mode = u1_pred_mode_part1;
2085
26.4k
    }
2086
4.41k
    else
2087
4.41k
    {
2088
4.41k
        WORD32 i4_i, i4_ctr, i4_num_submb_part;
2089
4.41k
        UWORD8 u1_sub_mb_type, u1_sub_mb_mc_mode;
2090
4.41k
        UWORD8 u1_pred_mode;
2091
2092
4.41k
        ps_mb_params->u1_mb_type = B_8x8;
2093
2094
22.0k
        for(i4_i = 0; i4_i < NUM_MB_PARTS; i4_i++)
2095
17.6k
        {
2096
17.6k
            u1_sub_mb_type = (UWORD8) pi4_sub_mb_mode[i4_i];
2097
2098
17.6k
            u1_sub_mb_mc_mode = gau1_ih264d_submb_mc_mode[4 + u1_sub_mb_type];
2099
17.6k
            i4_num_submb_part = g_au1_num_sub_mb_part[u1_sub_mb_mc_mode];
2100
17.6k
            *pu1_col_info |= (u1_sub_mb_mc_mode << 4);
2101
17.6k
            pu1_col_info++;
2102
17.6k
            u1_pred_mode = g_au1_sub_mb_pred_mode[4 + u1_sub_mb_type];
2103
48.6k
            for(i4_ctr = 0; i4_ctr < i4_num_submb_part; i4_ctr++)
2104
31.0k
            {
2105
31.0k
                ps_part->u1_pred_mode = u1_pred_mode;
2106
31.0k
                ps_part++;
2107
31.0k
            }
2108
17.6k
        }
2109
4.41k
    }
2110
2111
30.8k
    return;
2112
30.8k
}
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
31.1k
{
2140
31.1k
    UWORD8 u1_mot_pred_flag;
2141
31.1k
    WORD32 i4_lx;
2142
2143
75.8k
    for(i4_lx = 0; i4_lx < i4_listx; i4_lx++)
2144
44.7k
    {
2145
44.7k
        u1_mot_pred_flag = ps_svc_mb_params->au1_motion_pred_flag[i4_lx];
2146
2147
44.7k
        if((PRED_16x16 == ps_mb_params->u1_mb_mc_mode) && (u1_mot_pred_flag & 0x1))
2148
12.3k
        {
2149
12.3k
            ps_mb_part_info->i1_ref_idx[i4_lx][0] = ps_motion_pred[0].i1_ref_frame[i4_lx];
2150
12.3k
        }
2151
32.3k
        else if((PRED_8x16 == ps_mb_params->u1_mb_mc_mode))
2152
11.7k
        {
2153
11.7k
            if(u1_mot_pred_flag & 0x01)
2154
3.75k
            {
2155
3.75k
                ps_mb_part_info->i1_ref_idx[i4_lx][0] = ps_motion_pred[0].i1_ref_frame[i4_lx];
2156
3.75k
            }
2157
11.7k
            if(u1_mot_pred_flag & 0x02)
2158
6.93k
            {
2159
6.93k
                ps_mb_part_info->i1_ref_idx[i4_lx][1] = ps_motion_pred[2].i1_ref_frame[i4_lx];
2160
6.93k
            }
2161
11.7k
        }
2162
20.5k
        else if((PRED_16x8 == ps_mb_params->u1_mb_mc_mode))
2163
5.46k
        {
2164
5.46k
            if(u1_mot_pred_flag & 0x01)
2165
2.97k
            {
2166
2.97k
                ps_mb_part_info->i1_ref_idx[i4_lx][0] = ps_motion_pred[0].i1_ref_frame[i4_lx];
2167
2.97k
            }
2168
5.46k
            if(u1_mot_pred_flag & 0x02)
2169
3.71k
            {
2170
3.71k
                ps_mb_part_info->i1_ref_idx[i4_lx][1] = ps_motion_pred[8].i1_ref_frame[i4_lx];
2171
3.71k
            }
2172
5.46k
        }
2173
15.1k
        else if((PRED_8x8 == ps_mb_params->u1_mb_mc_mode))
2174
10.6k
        {
2175
10.6k
            if(u1_mot_pred_flag & 0x01)
2176
4.28k
            {
2177
4.28k
                ps_mb_part_info->i1_ref_idx[i4_lx][0] = ps_motion_pred[0].i1_ref_frame[i4_lx];
2178
4.28k
            }
2179
10.6k
            if(u1_mot_pred_flag & 0x02)
2180
4.19k
            {
2181
4.19k
                ps_mb_part_info->i1_ref_idx[i4_lx][1] = ps_motion_pred[2].i1_ref_frame[i4_lx];
2182
4.19k
            }
2183
10.6k
            if(u1_mot_pred_flag & 0x04)
2184
4.96k
            {
2185
4.96k
                ps_mb_part_info->i1_ref_idx[i4_lx][2] = ps_motion_pred[8].i1_ref_frame[i4_lx];
2186
4.96k
            }
2187
10.6k
            if(u1_mot_pred_flag & 0x08)
2188
4.25k
            {
2189
4.25k
                ps_mb_part_info->i1_ref_idx[i4_lx][3] = ps_motion_pred[10].i1_ref_frame[i4_lx];
2190
4.25k
            }
2191
10.6k
        }
2192
44.7k
    }
2193
31.1k
}
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
111k
{
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
111k
    mode_motion_ctxt_t *ps_ctxt;
2231
111k
    mv_pred_t *ps_motion_pred;
2232
111k
    dec_mb_info_t *ps_mb_params;
2233
111k
    WORD32 i4_listx;
2234
111k
    WORD32 i4_part_size;
2235
111k
    WORD32 i4_mb_mode_flag;
2236
111k
    WORD32 i4_i;
2237
111k
    WORD32 i4_blk_mode;
2238
111k
    parse_part_params_t *ps_part = (parse_part_params_t *) pv_part;
2239
111k
    parse_pmbarams_t *ps_mb_part_info = (parse_pmbarams_t *) pv_mb_part_info;
2240
111k
    UWORD8 *pu1_col_info = ps_mb_part_info->u1_col_info;
2241
111k
    UNUSED(pv_dec);
2242
2243
111k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
2244
111k
    ps_motion_pred = ps_ctxt->ps_motion_pred_struct;
2245
111k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
2246
2247
    /*********** store the MB mode as inter *************************/
2248
111k
    *pi4_mb_mode = SVC_INTER_MB;
2249
2250
    /***********************************************************************/
2251
    /* derivation of part type                                             */
2252
    /***********************************************************************/
2253
111k
    i4_listx = ps_ctxt->i4_listx;
2254
2255
    /* set the mb mode derivation flag to false */
2256
111k
    i4_mb_mode_flag = SVCD_FALSE;
2257
2258
    /* for B and P slice different blk mod treshold */
2259
111k
    if(2 == i4_listx)
2260
19.3k
    {
2261
19.3k
        i4_blk_mode = B_BI_8x8;
2262
19.3k
    }
2263
91.7k
    else
2264
91.7k
    {
2265
91.7k
        i4_blk_mode = P_L0_8x8;
2266
91.7k
    }
2267
2268
    /* set the mode derivation flag to true base on conditions */
2269
111k
    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
103k
    {
2272
103k
        i4_mb_mode_flag = SVCD_TRUE;
2273
103k
    }
2274
2275
    /* store the default 8x8 mode */
2276
111k
    ps_mb_part_info->u1_num_part = 4;
2277
111k
    i4_part_size = PRED_8x8;
2278
2279
    /* further check is present if all are 8x8 mode */
2280
111k
    if(SVCD_TRUE == i4_mb_mode_flag)
2281
103k
    {
2282
103k
        WORD32 i4_horz_match, i4_vert_match;
2283
2284
        /* check if the motion in horz direction are same*/
2285
103k
        i4_horz_match = isvcd_check_motion(ps_motion_pred, (ps_motion_pred + 2), i4_listx);
2286
103k
        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
103k
        i4_vert_match = isvcd_check_motion(ps_motion_pred, (ps_motion_pred + 8), i4_listx);
2290
103k
        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
103k
        if((2 == i4_horz_match) && (2 == i4_vert_match))
2294
85.7k
        {
2295
85.7k
            ps_mb_params->u1_mb_type = P_L0_16x16;
2296
85.7k
            i4_part_size = PRED_16x16;
2297
85.7k
            ps_mb_part_info->u1_num_part = 1;
2298
85.7k
            *pu1_col_info++ = (PRED_16x16 << 6);
2299
85.7k
            ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2300
85.7k
            if(2 == i4_listx) ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2301
2302
85.7k
            ps_part->u1_partwidth = 4;  // interms of 4x4
2303
85.7k
            ps_part->u1_partheight = 4;
2304
85.7k
            ps_part->u1_pred_mode = PRED_L0;
2305
85.7k
            ps_part->u1_is_direct = 0;
2306
85.7k
            ps_part->u1_sub_mb_num = 0;
2307
85.7k
        }
2308
17.3k
        else if(2 == i4_horz_match)
2309
6.81k
        {
2310
6.81k
            i4_part_size = PRED_16x8;
2311
6.81k
            ps_mb_params->u1_mb_type = P_L0_L0_16x8;
2312
6.81k
            ps_mb_part_info->u1_num_part = 2;
2313
6.81k
            *pu1_col_info++ = (PRED_16x8 << 6);
2314
6.81k
            *pu1_col_info++ = (PRED_16x8 << 6);
2315
2316
6.81k
            ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2317
6.81k
            ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[8].i1_ref_frame[0];
2318
6.81k
            if(2 == i4_listx)
2319
3.69k
            {
2320
3.69k
                ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2321
3.69k
                ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[8].i1_ref_frame[1];
2322
3.69k
            }
2323
6.81k
            ps_part->u1_partwidth = 4;  // interms of 4x4
2324
6.81k
            ps_part->u1_partheight = 2;
2325
6.81k
            ps_part->u1_pred_mode = PRED_L0;
2326
6.81k
            ps_part->u1_is_direct = 0;
2327
6.81k
            ps_part->u1_sub_mb_num = 0;
2328
2329
6.81k
            ps_part++;
2330
6.81k
            ps_part->u1_partwidth = 4;
2331
6.81k
            ps_part->u1_partheight = 2;
2332
6.81k
            ps_part->u1_pred_mode = PRED_L0;
2333
6.81k
            ps_part->u1_is_direct = 0;
2334
6.81k
            ps_part->u1_sub_mb_num = 8;
2335
6.81k
        }
2336
10.5k
        else if(2 == i4_vert_match)
2337
4.22k
        {
2338
4.22k
            ps_mb_params->u1_mb_type = P_L0_L0_8x16;
2339
4.22k
            i4_part_size = PRED_8x16;
2340
4.22k
            ps_mb_part_info->u1_num_part = 2;
2341
4.22k
            *pu1_col_info++ = (PRED_8x16 << 6);
2342
4.22k
            *pu1_col_info++ = (PRED_8x16 << 6);
2343
2344
4.22k
            ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2345
4.22k
            ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[2].i1_ref_frame[0];
2346
4.22k
            if(2 == i4_listx)
2347
1.37k
            {
2348
1.37k
                ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2349
1.37k
                ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[2].i1_ref_frame[1];
2350
1.37k
            }
2351
4.22k
            ps_part->u1_partwidth = 2;  // interms of 4x4
2352
4.22k
            ps_part->u1_partheight = 4;
2353
4.22k
            ps_part->u1_pred_mode = PRED_L0;
2354
4.22k
            ps_part->u1_is_direct = 0;
2355
4.22k
            ps_part->u1_sub_mb_num = 0;
2356
2357
4.22k
            ps_part++;
2358
4.22k
            ps_part->u1_partwidth = 2;
2359
4.22k
            ps_part->u1_partheight = 4;
2360
4.22k
            ps_part->u1_pred_mode = PRED_L0;
2361
4.22k
            ps_part->u1_is_direct = 0;
2362
4.22k
            ps_part->u1_sub_mb_num = 2;
2363
4.22k
        }
2364
103k
    }
2365
2366
    /* store the part size to the mb params */
2367
111k
    ps_mb_params->u1_mb_mc_mode = i4_part_size;
2368
2369
    /* in case of slice derive the partition modes */
2370
2371
111k
    {
2372
        /* store the sub MB modes if 8x8 mode is choosen */
2373
111k
        if(PRED_8x8 == i4_part_size)
2374
14.3k
        {
2375
14.3k
            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
14.3k
            ps_mb_params->u1_mb_type = P_8x8;
2379
14.3k
            ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred[0].i1_ref_frame[0];
2380
14.3k
            ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[2].i1_ref_frame[0];
2381
14.3k
            ps_mb_part_info->i1_ref_idx[0][2] = ps_motion_pred[8].i1_ref_frame[0];
2382
14.3k
            ps_mb_part_info->i1_ref_idx[0][3] = ps_motion_pred[10].i1_ref_frame[0];
2383
14.3k
            if(2 == i4_listx)
2384
3.40k
            {
2385
3.40k
                ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred[0].i1_ref_frame[1];
2386
3.40k
                ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[2].i1_ref_frame[1];
2387
3.40k
                ps_mb_part_info->i1_ref_idx[1][2] = ps_motion_pred[8].i1_ref_frame[1];
2388
3.40k
                ps_mb_part_info->i1_ref_idx[1][3] = ps_motion_pred[10].i1_ref_frame[1];
2389
3.40k
            }
2390
2391
14.3k
            ps_mb_part_info->u1_num_part = 0;
2392
71.5k
            for(i4_i = 0; i4_i < NUM_MB_PARTS; i4_i++)
2393
57.2k
            {
2394
57.2k
                WORD32 i4_num_submb_part, i4_part_width, i4_part_height, i4_ctr;
2395
57.2k
                u1_sub_mb_type = (UWORD8) pi4_sub_mb_mode[i4_i];
2396
2397
57.2k
                if(1 == i4_listx)
2398
43.5k
                {
2399
43.5k
                    u1_sub_mb_mc_mode = gau1_ih264d_submb_mc_mode[u1_sub_mb_type];
2400
43.5k
                }
2401
13.6k
                else if(2 == i4_listx)
2402
13.6k
                {
2403
13.6k
                    u1_sub_mb_mc_mode = gau1_ih264d_submb_mc_mode[4 + u1_sub_mb_type];
2404
13.6k
                }
2405
57.2k
                i4_num_submb_part = g_au1_num_sub_mb_part[u1_sub_mb_mc_mode];
2406
2407
57.2k
                ps_mb_part_info->u1_num_part += i4_num_submb_part;
2408
2409
57.2k
                i4_part_width = g_au1_sub_mb_part_wd[u1_sub_mb_mc_mode];
2410
57.2k
                i4_part_height = g_au1_sub_mb_part_ht[u1_sub_mb_mc_mode];
2411
57.2k
                *pu1_col_info++ = (PRED_8x8 << 6) | (u1_sub_mb_mc_mode << 4);
2412
129k
                for(i4_ctr = 0; i4_ctr < i4_num_submb_part; i4_ctr++)
2413
72.4k
                {
2414
72.4k
                    ps_part->u1_partwidth = i4_part_width;  // interms of 4x4
2415
72.4k
                    ps_part->u1_partheight = i4_part_height;
2416
72.4k
                    ps_part->u1_pred_mode = PRED_L0;
2417
72.4k
                    ps_part->u1_is_direct = 0;
2418
72.4k
                    ps_part->u1_sub_mb_num = (i4_i & 0x01) * 2 + (i4_i >> 1) * 8;
2419
72.4k
                    if(i4_num_submb_part == 2)
2420
25.1k
                    {
2421
25.1k
                        ps_part->u1_sub_mb_num +=
2422
25.1k
                            i4_ctr ? (((i4_part_width - 1) << 2) + (i4_part_height - 1)) : 0;
2423
25.1k
                    }
2424
47.3k
                    else if(i4_num_submb_part == 4)
2425
3.58k
                    {
2426
3.58k
                        ps_part->u1_sub_mb_num += ((i4_ctr >> 1) << 2) + (i4_ctr & 0x01);
2427
3.58k
                    }
2428
2429
72.4k
                    ps_part++;
2430
72.4k
                }
2431
57.2k
            }
2432
14.3k
        }
2433
111k
        if(2 == i4_listx)
2434
19.3k
        {
2435
19.3k
            ps_part = (parse_part_params_t *) pv_part;
2436
19.3k
            pu1_col_info = ps_mb_part_info->u1_col_info;
2437
            /* B_MBs */
2438
19.3k
            isvcd_interlyr_mbmode_pred_bmb(ps_ctxt, ps_motion_pred, 4, i4_part_size,
2439
19.3k
                                           pi4_sub_mb_mode, ps_mb_params, ps_part, pu1_col_info);
2440
19.3k
        }
2441
111k
    }
2442
2443
111k
    return;
2444
111k
}
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
128k
{
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
128k
    mode_motion_ctxt_t *ps_ctxt;
2483
128k
    WORD32 i4_intra_flag;
2484
128k
    WORD32 ai4_sub_mb_mode[NUM_MB_PARTS] = {0};
2485
128k
    dec_mb_info_t *ps_mb_params;
2486
128k
    dec_svc_mb_info_t *ps_svc_mb_params;
2487
128k
    dec_struct_t *ps_dec = (dec_struct_t *) pv_dec;
2488
128k
    WORD32 i4_mb_mode = -1;
2489
128k
    parse_pmbarams_t *ps_mb_part_info = (parse_pmbarams_t *) pv_mb_part_info;
2490
128k
    parse_part_params_t *ps_part = (parse_part_params_t *) pv_part;
2491
2492
128k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
2493
128k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
2494
128k
    ps_svc_mb_params = (dec_svc_mb_info_t *) pv_svc_mb_params;
2495
2496
128k
    i4_intra_flag = SVCD_FALSE;
2497
2498
128k
    isvcd_ref_lyr_part_idc(pv_comp_mode_mv_ctxt, ps_ctxt->ai4_ref_part_idc, &i4_intra_flag,
2499
128k
                           pv_mb_params);
2500
2501
    /* If base is Intra */
2502
128k
    if(SVCD_TRUE == i4_intra_flag)
2503
9.04k
    {
2504
9.04k
        if(1 == ps_svc_mb_params->u1_base_mode_flag)
2505
8.67k
        {
2506
8.67k
            i4_mb_mode = SVC_IBL_MB;
2507
8.67k
            ps_svc_mb_params->u1_residual_prediction_flag = 0;
2508
8.67k
        }
2509
9.04k
    }
2510
119k
    else
2511
119k
    {
2512
        /* derive the motion and reference index by inter layer predcition */
2513
119k
        isvcd_interlyr_motion_submbmode_pred(pv_comp_mode_mv_ctxt, ps_mb_params, ps_svc_mb_params,
2514
119k
                                             ps_ctxt->ai4_ref_part_idc, ai4_sub_mb_mode, pv_dec);
2515
2516
        /* derive the MB mode */
2517
119k
        if(1 == ps_svc_mb_params->u1_base_mode_flag)
2518
111k
        {
2519
111k
            isvcd_interlyr_mbmode_pred(pv_comp_mode_mv_ctxt, pv_mb_params, ai4_sub_mb_mode,
2520
111k
                                       &i4_mb_mode, ps_dec, ps_mb_part_info, ps_part);
2521
111k
        }
2522
8.12k
        else
2523
8.12k
        {
2524
8.12k
            isvcd_populate_ref_idx(ps_mb_params, ps_svc_mb_params, ps_ctxt->ps_motion_pred_struct,
2525
8.12k
                                   ps_mb_part_info, ps_ctxt->i4_listx);
2526
8.12k
        }
2527
119k
    }
2528
2529
128k
    return i4_mb_mode;
2530
128k
}
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
64.4k
{
2565
64.4k
    mode_motion_ctxt_t *ps_ctxt;
2566
64.4k
    mode_motion_lyr_ctxt *ps_lyr_mem;
2567
64.4k
    dec_mb_info_t *ps_mb_params;
2568
64.4k
    dec_svc_mb_info_t *ps_svc_mb_params;
2569
64.4k
    WORD32 i4_listx;
2570
64.4k
    WORD32 i4_mb_pic_x, i4_mb_pic_y;
2571
64.4k
    WORD32 i4_ref_x, i4_ref_y;
2572
64.4k
    UWORD8 u1_base_mode_flag;
2573
64.4k
    dec_struct_t *ps_dec = (dec_struct_t *) pv_dec;
2574
64.4k
    WORD32 i4_mb_mode = -1;
2575
64.4k
    parse_pmbarams_t *ps_mb_part_info = (parse_pmbarams_t *) pv_mb_part_info;
2576
64.4k
    UWORD8 *pu1_col_info = ps_mb_part_info->u1_col_info;
2577
64.4k
    parse_part_params_t *ps_part = (parse_part_params_t *) pv_part;
2578
2579
64.4k
    ps_ctxt = (mode_motion_ctxt_t *) pv_comp_mode_mv_ctxt;
2580
2581
    /* get the current layer ctxt */
2582
64.4k
    ps_lyr_mem = &ps_ctxt->as_res_lyr_mem[ps_ctxt->i4_res_id];
2583
2584
64.4k
    ps_mb_params = (dec_mb_info_t *) pv_mb_params;
2585
64.4k
    ps_svc_mb_params = (dec_svc_mb_info_t *) pv_svc_mb_params;
2586
64.4k
    i4_listx = ps_ctxt->i4_listx;
2587
2588
64.4k
    {
2589
64.4k
        WORD32 i4_mb_x, i4_mb_y;
2590
        /* derive the MB_X and MB_Y for the current MB */
2591
64.4k
        i4_mb_x = ps_mb_params->u2_mbx;
2592
64.4k
        i4_mb_y = ps_mb_params->u2_mby;
2593
2594
        /* get the colocated position in the refernce layer */
2595
64.4k
        i4_ref_x = ps_lyr_mem->pi2_ref_loc_x[i4_mb_x << 4];
2596
64.4k
        i4_ref_y = ps_lyr_mem->pi2_ref_loc_y[i4_mb_y << 4];
2597
64.4k
        i4_ref_x = CLIP3(0, ((ps_lyr_mem->i4_ref_width) - 1), i4_ref_x);
2598
64.4k
        i4_ref_y = CLIP3(0, ((ps_lyr_mem->i4_ref_height) - 1), i4_ref_y);
2599
2600
        /* convert into picture units */
2601
64.4k
        i4_mb_pic_x = i4_mb_x << 4;
2602
64.4k
        i4_mb_pic_y = i4_mb_y << 4;
2603
64.4k
    }
2604
2605
    /* ref layer mb mode */
2606
64.4k
    {
2607
64.4k
        inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
2608
64.4k
        WORD32 i4_inter_lyr_mb_prms_stride;
2609
64.4k
        WORD32 i4_ref_mb_x, i4_ref_mb_y;
2610
64.4k
        WORD8 i1_ref_mb_mode;
2611
2612
64.4k
        ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) ps_lyr_mem->s_ref_mb_mode.pv_buffer;
2613
64.4k
        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
64.4k
        i4_ref_mb_x = (i4_ref_x >> 4);
2617
64.4k
        i4_ref_mb_y = (i4_ref_y >> 4);
2618
2619
        /* get the appropriate mb params in reference layer */
2620
64.4k
        ps_inter_lyr_mb_prms += i4_ref_mb_x;
2621
64.4k
        ps_inter_lyr_mb_prms += i4_ref_mb_y * i4_inter_lyr_mb_prms_stride;
2622
64.4k
        i1_ref_mb_mode = ps_inter_lyr_mb_prms->i1_mb_mode;
2623
64.4k
        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
64.4k
        if(i1_ref_mb_mode > SVC_INTER_MB)
2627
11.9k
        {
2628
11.9k
            if(1 == u1_base_mode_flag)
2629
11.6k
            {
2630
11.6k
                i4_mb_mode = SVC_IBL_MB;
2631
11.6k
                ps_svc_mb_params->u1_residual_prediction_flag = 0;
2632
11.6k
            }
2633
11.9k
            return i4_mb_mode;
2634
11.9k
        }
2635
64.4k
    }
2636
2637
    /*-----------------------------------------------------------------------*/
2638
    /* Inter MB upsampling process                                           */
2639
    /*-----------------------------------------------------------------------*/
2640
52.4k
    {
2641
52.4k
        mv_pred_t *ps_motion_pred;
2642
52.4k
        WORD32 i4_16x16_flag;
2643
52.4k
        WORD32 i4_part_idc;
2644
52.4k
        WORD32 i4_blk_idx;
2645
52.4k
        WORD32 i4_curr_mot_stride;
2646
2647
        /* choose the appropriate mv bank pointer and stride */
2648
52.4k
        if(1 == u1_base_mode_flag)
2649
29.4k
        {
2650
29.4k
            i4_mb_mode = SVC_INTER_MB;
2651
29.4k
        }
2652
2653
52.4k
        ps_motion_pred = ps_ctxt->ps_motion_pred_struct;
2654
52.4k
        i4_curr_mot_stride = 4;
2655
2656
        /* call the motion upsampling for 1st 4x4 */
2657
52.4k
        i4_part_idc = (i4_ref_y << 16) + i4_ref_x;
2658
52.4k
        i4_16x16_flag = isvcd_interlyr_motion_scale(
2659
52.4k
            pv_comp_mode_mv_ctxt, &i4_part_idc, ps_mb_params, ps_motion_pred, i4_listx,
2660
52.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
52.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
52.4k
        else
2715
52.4k
        {
2716
52.4k
            WORD32 ai4_sub_mb_mode[NUM_MB_PARTS] = {0};
2717
2718
            /* replicate the motion vectors for 8x8 */
2719
52.4k
            isvcd_store_motion_map(ps_motion_pred, ps_motion_pred, 0, i4_curr_mot_stride, 2, 2,
2720
52.4k
                                   SVCD_FALSE);
2721
2722
52.4k
            if(2 == i4_listx)
2723
21.8k
            {
2724
21.8k
                WORD32 i4_indx = 0;
2725
2726
                /* replicate the motion vectors for 8x8 */
2727
                /* check the 0th partiton reference indices */
2728
21.8k
                if(0 <= ps_motion_pred[0].i1_ref_frame[0])
2729
20.9k
                {
2730
20.9k
                    i4_indx += 1;
2731
20.9k
                }
2732
21.8k
                if(0 <= ps_motion_pred[0].i1_ref_frame[1])
2733
8.61k
                {
2734
8.61k
                    i4_indx += 2;
2735
8.61k
                }
2736
2737
21.8k
                i4_indx = 3 * PRED_8x8 + (i4_indx - 1);
2738
21.8k
                ai4_sub_mb_mode[0] = g_au1_eb_submb_type[i4_indx];
2739
21.8k
            }
2740
2741
            /* derive the motion vectors and reference indices of 3 rem partitions */
2742
209k
            for(i4_blk_idx = 1; i4_blk_idx < NUM_MB_PARTS; i4_blk_idx++)
2743
157k
            {
2744
157k
                WORD32 i4_blk_y, i4_blk_x;
2745
157k
                mv_pred_t *ps_temp;
2746
2747
157k
                i4_blk_x = i4_blk_idx & 1;
2748
157k
                i4_blk_y = i4_blk_idx >> 1;
2749
2750
157k
                ps_temp = ps_motion_pred + (i4_blk_x << 1);
2751
157k
                ps_temp += (i4_blk_y * i4_curr_mot_stride << 1);
2752
2753
                /* store the reference layer positions */
2754
157k
                i4_part_idc = ((i4_ref_y + (i4_blk_y << 2)) << 16) + (i4_ref_x + (i4_blk_x << 2));
2755
157k
                isvcd_interlyr_motion_scale(pv_comp_mode_mv_ctxt, &i4_part_idc, ps_mb_params,
2756
157k
                                            ps_temp, i4_listx, (i4_mb_pic_x + (i4_blk_x << 2) + 1),
2757
157k
                                            (i4_mb_pic_y + (i4_blk_y << 2) + 1),
2758
157k
                                            ps_dec->ppv_map_ref_idx_to_poc);
2759
2760
                /* replicate the motion vectors for 8x8 */
2761
157k
                isvcd_store_motion_map(ps_temp, ps_temp, 0, i4_curr_mot_stride, 2, 2, SVCD_FALSE);
2762
2763
157k
                if(2 == i4_listx)
2764
65.5k
                {
2765
65.5k
                    WORD32 i4_indx = 0;
2766
2767
                    /* check the 0th partiton reference indices */
2768
65.5k
                    if(0 <= ps_temp[0].i1_ref_frame[0])
2769
62.9k
                    {
2770
62.9k
                        i4_indx += 1;
2771
62.9k
                    }
2772
65.5k
                    if(0 <= ps_temp[0].i1_ref_frame[1])
2773
26.4k
                    {
2774
26.4k
                        i4_indx += 2;
2775
26.4k
                    }
2776
2777
65.5k
                    i4_indx = 3 * PRED_8x8 + (i4_indx - 1);
2778
2779
65.5k
                    ai4_sub_mb_mode[i4_blk_idx] = g_au1_eb_submb_type[i4_indx];
2780
65.5k
                }
2781
157k
            }
2782
2783
            /* if MB mode has to derivied */
2784
52.4k
            if(1 == u1_base_mode_flag)
2785
29.4k
            {
2786
29.4k
                WORD32 i4_horz_match, i4_vert_match;
2787
29.4k
                WORD32 i4_part_size = PRED_8x8;
2788
2789
29.4k
                mv_pred_t *ps_motion_1;
2790
29.4k
                mv_pred_t *ps_motion_2;
2791
29.4k
                mv_pred_t *ps_motion_3;
2792
2793
29.4k
                ps_motion_1 = ps_motion_pred + 2;
2794
29.4k
                ps_motion_2 = ps_motion_pred + (i4_curr_mot_stride << 1);
2795
29.4k
                ps_motion_3 = ps_motion_2 + 2;
2796
2797
                /* check if the motion in horz direction are same*/
2798
29.4k
                i4_horz_match = isvcd_check_motion(ps_motion_pred, ps_motion_1, i4_listx);
2799
29.4k
                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
29.4k
                i4_vert_match = isvcd_check_motion(ps_motion_pred, ps_motion_2, i4_listx);
2803
29.4k
                i4_vert_match += isvcd_check_motion(ps_motion_1, ps_motion_3, i4_listx);
2804
2805
29.4k
                ps_mb_part_info->u1_num_part = 4;
2806
2807
                /* decide the partition size based on the results of matching */
2808
29.4k
                if((2 == i4_horz_match) && (2 == i4_vert_match))
2809
26.3k
                {
2810
26.3k
                    ps_mb_params->u1_mb_type = P_L0_16x16;
2811
26.3k
                    i4_part_size = PRED_16x16;
2812
26.3k
                    ps_mb_part_info->u1_num_part = 1;
2813
26.3k
                    *pu1_col_info++ = (PRED_16x16 << 6);
2814
2815
26.3k
                    ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2816
26.3k
                    if(2 == i4_listx)
2817
9.99k
                        ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2818
2819
26.3k
                    ps_part->u1_partwidth = 4;  // interms of 4x4
2820
26.3k
                    ps_part->u1_partheight = 4;
2821
26.3k
                    ps_part->u1_pred_mode = PRED_L0;
2822
26.3k
                    ps_part->u1_is_direct = 0;
2823
26.3k
                    ps_part->u1_sub_mb_num = 0;
2824
26.3k
                }
2825
3.13k
                else if(2 == i4_horz_match)
2826
581
                {
2827
581
                    ps_mb_params->u1_mb_type = P_L0_L0_16x8;
2828
581
                    i4_part_size = PRED_16x8;
2829
581
                    ps_mb_part_info->u1_num_part = 2;
2830
581
                    *pu1_col_info++ = (PRED_16x8 << 6);
2831
581
                    *pu1_col_info++ = (PRED_16x8 << 6);
2832
2833
581
                    ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2834
581
                    ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[8].i1_ref_frame[0];
2835
581
                    if(2 == i4_listx)
2836
307
                    {
2837
307
                        ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2838
307
                        ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[8].i1_ref_frame[1];
2839
307
                    }
2840
581
                    ps_part->u1_partwidth = 4;  // interms of 4x4
2841
581
                    ps_part->u1_partheight = 2;
2842
581
                    ps_part->u1_pred_mode = PRED_L0;
2843
581
                    ps_part->u1_is_direct = 0;
2844
581
                    ps_part->u1_sub_mb_num = 0;
2845
2846
581
                    ps_part++;
2847
581
                    ps_part->u1_partwidth = 4;
2848
581
                    ps_part->u1_partheight = 2;
2849
581
                    ps_part->u1_pred_mode = PRED_L0;
2850
581
                    ps_part->u1_is_direct = 0;
2851
581
                    ps_part->u1_sub_mb_num = 8;
2852
581
                }
2853
2.54k
                else if(2 == i4_vert_match)
2854
368
                {
2855
368
                    ps_mb_params->u1_mb_type = P_L0_L0_8x16;
2856
368
                    i4_part_size = PRED_8x16;
2857
368
                    ps_mb_part_info->u1_num_part = 2;
2858
368
                    *pu1_col_info++ = (PRED_8x16 << 6);
2859
368
                    *pu1_col_info++ = (PRED_8x16 << 6);
2860
2861
368
                    ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred->i1_ref_frame[0];
2862
368
                    ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[2].i1_ref_frame[0];
2863
368
                    if(2 == i4_listx)
2864
213
                    {
2865
213
                        ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred->i1_ref_frame[1];
2866
213
                        ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[2].i1_ref_frame[1];
2867
213
                    }
2868
368
                    ps_part->u1_partwidth = 2;  // interms of 4x4
2869
368
                    ps_part->u1_partheight = 4;
2870
368
                    ps_part->u1_pred_mode = PRED_L0;
2871
368
                    ps_part->u1_is_direct = 0;
2872
368
                    ps_part->u1_sub_mb_num = 0;
2873
2874
368
                    ps_part++;
2875
368
                    ps_part->u1_partwidth = 2;
2876
368
                    ps_part->u1_partheight = 4;
2877
368
                    ps_part->u1_pred_mode = PRED_L0;
2878
368
                    ps_part->u1_is_direct = 0;
2879
368
                    ps_part->u1_sub_mb_num = 2;
2880
368
                }
2881
2882
                /* store the part size to the mb params */
2883
29.4k
                ps_mb_params->u1_mb_mc_mode = i4_part_size;
2884
2885
                /* store the sub partition size */
2886
29.4k
                if(PRED_8x8 == i4_part_size)
2887
2.18k
                {
2888
2.18k
                    UWORD8 u1_ctr;
2889
                    /* for P_MB sub part type is P_L0_8x8*/
2890
2891
2.18k
                    ps_mb_params->u1_mb_type = P_8x8;
2892
2.18k
                    ps_mb_part_info->i1_ref_idx[0][0] = ps_motion_pred[0].i1_ref_frame[0];
2893
2.18k
                    ps_mb_part_info->i1_ref_idx[0][1] = ps_motion_pred[2].i1_ref_frame[0];
2894
2.18k
                    ps_mb_part_info->i1_ref_idx[0][2] = ps_motion_pred[8].i1_ref_frame[0];
2895
2.18k
                    ps_mb_part_info->i1_ref_idx[0][3] = ps_motion_pred[10].i1_ref_frame[0];
2896
2.18k
                    if(2 == i4_listx)
2897
1.00k
                    {
2898
1.00k
                        ps_mb_part_info->i1_ref_idx[1][0] = ps_motion_pred[0].i1_ref_frame[1];
2899
1.00k
                        ps_mb_part_info->i1_ref_idx[1][1] = ps_motion_pred[2].i1_ref_frame[1];
2900
1.00k
                        ps_mb_part_info->i1_ref_idx[1][2] = ps_motion_pred[8].i1_ref_frame[1];
2901
1.00k
                        ps_mb_part_info->i1_ref_idx[1][3] = ps_motion_pred[10].i1_ref_frame[1];
2902
1.00k
                    }
2903
2904
10.9k
                    for(u1_ctr = 0; u1_ctr < 4; u1_ctr++)
2905
8.72k
                    {
2906
8.72k
                        *pu1_col_info++ = (PRED_8x8 << 6);
2907
2908
8.72k
                        ps_part->u1_partwidth = 2;  // interms of 4x4
2909
8.72k
                        ps_part->u1_partheight = 2;
2910
8.72k
                        ps_part->u1_pred_mode = PRED_L0;
2911
8.72k
                        ps_part->u1_is_direct = 0;
2912
8.72k
                        ps_part->u1_sub_mb_num = (u1_ctr & 0x01) * 2 + (u1_ctr >> 1) * 8;
2913
8.72k
                        ps_part++;
2914
8.72k
                    }
2915
2.18k
                }
2916
2917
29.4k
                if(2 == i4_listx)
2918
11.5k
                {
2919
11.5k
                    ps_part = (parse_part_params_t *) pv_part;
2920
11.5k
                    pu1_col_info = ps_mb_part_info->u1_col_info;
2921
11.5k
                    isvcd_interlyr_mbmode_pred_bmb(ps_ctxt, ps_motion_pred, i4_curr_mot_stride,
2922
11.5k
                                                   i4_part_size, &ai4_sub_mb_mode[0], ps_mb_params,
2923
11.5k
                                                   ps_part, pu1_col_info);
2924
11.5k
                }
2925
29.4k
            } /* end of mode derivation */
2926
22.9k
            else
2927
22.9k
            {
2928
22.9k
                isvcd_populate_ref_idx(ps_mb_params, ps_svc_mb_params, ps_motion_pred,
2929
22.9k
                                       ps_mb_part_info, i4_listx);
2930
2931
22.9k
            } /* non 16x16 mv mode derivation */
2932
52.4k
        }
2933
52.4k
    }
2934
52.4k
    return i4_mb_mode;
2935
52.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
33.9k
{
2969
33.9k
    WORD32 i4_offset_x, i4_offset_y;
2970
33.9k
    UWORD32 i4_scaled_ref_lyr_width;
2971
33.9k
    UWORD32 i4_scaled_ref_lyr_height;
2972
33.9k
    UWORD32 i4_ref_lyr_width;
2973
33.9k
    UWORD32 i4_ref_lyr_height;
2974
33.9k
    UWORD32 i4_shift_x, i4_shift_y;
2975
33.9k
    UWORD32 i4_scale_x, i4_scale_y;
2976
33.9k
    WORD32 i4_cntr;
2977
33.9k
    WORD32 i4_scale_add_x, i4_scale_add_y;
2978
33.9k
    WORD32 i4_curr_lyr_width, i4_curr_lyr_height;
2979
2980
33.9k
    if((NULL == ps_curr_res_prms) || (NULL == ps_ref_res_prms) || (NULL == pi2_offset_x) ||
2981
33.9k
       (NULL == pi2_offset_y))
2982
0
    {
2983
0
        return NOT_OK;
2984
0
    }
2985
    /* initial calculation */
2986
33.9k
    i4_offset_x = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_left;
2987
33.9k
    i4_offset_y = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_top;
2988
2989
    /* get the width and height */
2990
33.9k
    i4_scaled_ref_lyr_width = ps_curr_res_prms->u2_scaled_ref_width;
2991
33.9k
    i4_scaled_ref_lyr_height = ps_curr_res_prms->u2_scaled_ref_height;
2992
33.9k
    i4_ref_lyr_width = ps_ref_res_prms->i4_res_width;
2993
33.9k
    i4_ref_lyr_height = ps_ref_res_prms->i4_res_height;
2994
33.9k
    i4_curr_lyr_width = ps_curr_res_prms->i4_res_width;
2995
33.9k
    i4_curr_lyr_height = ps_curr_res_prms->i4_res_height;
2996
2997
    /* derive shift x and y based on level idd */
2998
33.9k
    if(u1_level_idc <= 30)
2999
32.0k
    {
3000
32.0k
        i4_shift_x = 16;
3001
32.0k
        i4_shift_y = 16;
3002
32.0k
    }
3003
1.92k
    else
3004
1.92k
    {
3005
1.92k
        i4_shift_x = 31 - isvcd_get_ceil_log2(i4_ref_lyr_width);
3006
1.92k
        i4_shift_y = 31 - isvcd_get_ceil_log2(i4_ref_lyr_height);
3007
1.92k
    }
3008
3009
    /* assert on max ranges of width and shift values */
3010
33.9k
    if((i4_ref_lyr_width > H264_MAX_FRAME_WIDTH) ||
3011
33.9k
       (i4_scaled_ref_lyr_width > H264_MAX_FRAME_WIDTH) ||
3012
33.9k
       (i4_ref_lyr_height > H264_MAX_FRAME_HEIGHT) ||
3013
33.9k
       (i4_scaled_ref_lyr_height > H264_MAX_FRAME_HEIGHT) ||
3014
33.9k
       (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
33.9k
    i4_scale_x = (((UWORD32) i4_ref_lyr_width << i4_shift_x) + (i4_scaled_ref_lyr_width >> 1)) /
3021
33.9k
                 i4_scaled_ref_lyr_width;
3022
3023
33.9k
    i4_scale_y = (((UWORD32) i4_ref_lyr_height << i4_shift_y) + (i4_scaled_ref_lyr_height >> 1)) /
3024
33.9k
                 i4_scaled_ref_lyr_height;
3025
3026
    /* calcualte the values to be added based on left and top offset */
3027
33.9k
    i4_scale_add_x = (1 << (i4_shift_x - 1)) - (i4_offset_x * (WORD32) i4_scale_x);
3028
33.9k
    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.95M
    for(i4_cntr = 0; i4_cntr < i4_curr_lyr_width; i4_cntr++)
3032
1.91M
    {
3033
1.91M
        WORD32 i4_ref_x;
3034
1.91M
        i4_ref_x = (i4_cntr * i4_scale_x + i4_scale_add_x) >> i4_shift_x;
3035
1.91M
        *pi2_offset_x++ = (WORD16) i4_ref_x;
3036
1.91M
    }
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.05M
    {
3041
5.05M
        WORD32 i4_ref_y;
3042
5.05M
        i4_ref_y = (i4_cntr * i4_scale_y + i4_scale_add_y) >> i4_shift_y;
3043
5.05M
        *pi2_offset_y++ = (WORD16) i4_ref_y;
3044
5.05M
    }
3045
33.9k
    return OK;
3046
33.9k
}
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
138k
{
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
138k
    mode_motion_ctxt_t *ps_ctxt;
3086
138k
    mode_motion_lyr_ctxt *ps_lyr_mem;
3087
138k
    dec_seq_params_t *ps_sps;
3088
138k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) pv_svc_dec;
3089
138k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
3090
138k
    svc_dec_lyr_struct_t *ps_svc_dec_ref_layer;
3091
138k
    WORD32 ret;
3092
138k
    WORD32 i4_scaled_ref_lyr_width;
3093
138k
    WORD32 i4_scaled_ref_lyr_height;
3094
138k
    WORD32 i4_ref_lyr_width;
3095
138k
    WORD32 i4_ref_lyr_height;
3096
138k
    res_prms_t *ps_curr_lyr_res_prms = &ps_svc_lyr_dec->s_res_prms;
3097
3098
138k
    ps_svc_dec_ref_layer = ps_svc_lyr_dec->ps_dec_svc_ref_layer;
3099
138k
    if(NULL == ps_curr_lyr_res_prms)
3100
0
    {
3101
0
        return NOT_OK;
3102
0
    }
3103
3104
138k
    ps_ctxt = (mode_motion_ctxt_t *) ps_svc_lyr_dec->pv_mode_mv_sample_ctxt;
3105
138k
    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
138k
    if(SVCD_TRUE == ps_svc_lyr_dec->u1_base_res_flag)
3109
104k
    {
3110
104k
        ps_ctxt->i4_res_id = -1;
3111
104k
        ps_ctxt->i4_ref_width = ps_curr_lyr_res_prms->i4_res_width;
3112
104k
        ps_ctxt->i4_ref_height = ps_curr_lyr_res_prms->i4_res_height;
3113
104k
        return OK;
3114
104k
    }
3115
3116
    /* call the function which populates the projected ref locations */
3117
33.9k
    ps_sps = ps_dec->ps_cur_sps;
3118
3119
    /* store the res id appropriately */
3120
33.9k
    ps_ctxt->i4_res_id = ps_svc_lyr_dec->u1_layer_id - 1;
3121
3122
    /* get the current layer ctxt */
3123
33.9k
    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
33.9k
    ps_lyr_mem->ps_curr_lyr_res_prms = ps_curr_lyr_res_prms;
3127
3128
    /* store the reference layer mv bank pointer */
3129
33.9k
    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
33.9k
    ps_lyr_mem->s_ref_mb_mode.pv_buffer = ps_svc_dec_ref_layer->ps_inter_lyr_mb_prms_frm_start;
3133
33.9k
    ps_lyr_mem->s_ref_mb_mode.i4_num_element_stride =
3134
33.9k
        ps_svc_dec_ref_layer->u2_inter_lyr_mb_prms_stride;
3135
33.9k
    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
33.9k
    if(SVCD_TRUE == ps_curr_lyr_res_prms->u1_remap_req_flag)
3139
33.9k
    {
3140
33.9k
        res_prms_t s_ref_res_prms = {0};
3141
3142
        /* store the reference layer resolution width and height */
3143
33.9k
        s_ref_res_prms.i4_res_width = ps_ctxt->i4_ref_width;
3144
33.9k
        s_ref_res_prms.i4_res_height = ps_ctxt->i4_ref_height;
3145
3146
        /* call projection map calculation function */
3147
33.9k
        ret = isvcd_compute_scaled_offsets(ps_curr_lyr_res_prms, &s_ref_res_prms,
3148
33.9k
                                           ps_lyr_mem->pi2_ref_loc_x, ps_lyr_mem->pi2_ref_loc_y,
3149
33.9k
                                           ps_sps->u1_level_idc);
3150
33.9k
        if(OK != ret)
3151
0
        {
3152
0
            return NOT_OK;
3153
0
        }
3154
3155
        /* derive the scaling variables */
3156
33.9k
        ps_lyr_mem->i4_offset_x = ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left;
3157
3158
33.9k
        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
33.9k
        i4_scaled_ref_lyr_width = ps_curr_lyr_res_prms->u2_scaled_ref_width;
3162
33.9k
        i4_scaled_ref_lyr_height = ps_curr_lyr_res_prms->u2_scaled_ref_height;
3163
33.9k
        i4_ref_lyr_width = ps_ctxt->i4_ref_width;
3164
33.9k
        i4_ref_lyr_height = ps_ctxt->i4_ref_height;
3165
3166
        /*store the reference layer width adn height */
3167
33.9k
        ps_lyr_mem->i4_ref_width = ps_ctxt->i4_ref_width;
3168
33.9k
        ps_lyr_mem->i4_ref_height = ps_ctxt->i4_ref_height;
3169
3170
33.9k
        if((i4_ref_lyr_width > H264_MAX_FRAME_WIDTH) || (i4_ref_lyr_width <= 0)) return NOT_OK;
3171
33.9k
        if((i4_scaled_ref_lyr_width > H264_MAX_FRAME_WIDTH) || (i4_scaled_ref_lyr_width <= 0))
3172
0
            return NOT_OK;
3173
33.9k
        if((i4_ref_lyr_height > H264_MAX_FRAME_HEIGHT) || (i4_ref_lyr_height <= 0)) return NOT_OK;
3174
33.9k
        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
33.9k
        ps_lyr_mem->pf_inter_lyr_pred = &isvcd_compute_interlyr_motion_mode;
3180
3181
33.9k
        if(SVCD_TRUE == ps_curr_lyr_res_prms->u1_dyadic_flag)
3182
17.9k
        {
3183
17.9k
            ps_lyr_mem->pf_inter_lyr_pred = &isvcd_interlyr_motion_mode_pred_dyadic;
3184
17.9k
        }
3185
3186
        /* Store the Dyadic flag */
3187
33.9k
        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
33.9k
        ps_lyr_mem->i4_scale_mv_x =
3192
33.9k
            ((i4_scaled_ref_lyr_width << 16) + (i4_ref_lyr_width >> 1)) / i4_ref_lyr_width;
3193
3194
33.9k
        ps_lyr_mem->i4_scale_mv_y =
3195
33.9k
            ((i4_scaled_ref_lyr_height << 16) + (i4_ref_lyr_height >> 1)) / i4_ref_lyr_height;
3196
33.9k
    }
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
33.9k
    ps_ctxt->i4_ref_width = ps_curr_lyr_res_prms->i4_res_width;
3208
33.9k
    ps_ctxt->i4_ref_height = ps_curr_lyr_res_prms->i4_res_height;
3209
3210
33.9k
    return OK;
3211
33.9k
}