1 /******************************************************************************
2 *
3 * Copyright (C) 2015 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20
21 /**
22 *******************************************************************************
23 * @file
24 * ih264e_deblk.c
25 *
26 * @brief
27 * This file contains functions that are associated with deblocking
28 *
29 * @author
30 * ittiam
31 *
32 * @par List of Functions:
33 * - ih264e_fill_bs_1mv_1ref_non_mbaff
34 * - ih264e_calculate_csbp
35 * - ih264e_compute_bs
36 * - ih264e_filter_top_edge
37 * - ih264e_filter_left_edge
38 * - ih264e_deblock_mb
39 *
40 * @remarks
41 * none
42 *
43 *******************************************************************************
44 */
45
46 /*****************************************************************************/
47 /* File Includes */
48 /*****************************************************************************/
49
50 /* System Include Files */
51 #include <stdio.h>
52 #include <string.h>
53 #include <assert.h>
54
55 /* User Include Files */
56 #include "ih264e_config.h"
57 #include "ih264_typedefs.h"
58 #include "iv2.h"
59 #include "ive2.h"
60
61 #include "ih264_macros.h"
62 #include "ih264_defs.h"
63 #include "ih264_mem_fns.h"
64 #include "ih264_padding.h"
65 #include "ih264_structs.h"
66 #include "ih264_trans_quant_itrans_iquant.h"
67 #include "ih264_inter_pred_filters.h"
68 #include "ih264_intra_pred_filters.h"
69 #include "ih264_deblk_edge_filters.h"
70 #include "ih264_trans_data.h"
71 #include "ih264_cabac_tables.h"
72 #include "ih264_deblk_tables.h"
73
74 #include "ime_defs.h"
75 #include "ime_distortion_metrics.h"
76 #include "ime_structs.h"
77
78 #include "irc_cntrl_param.h"
79 #include "irc_frame_info_collector.h"
80
81 #include "ih264e_error.h"
82 #include "ih264e_defs.h"
83 #include "ih264e_rate_control.h"
84 #include "ih264e_bitstream.h"
85 #include "ih264e_cabac_structs.h"
86 #include "ih264e_structs.h"
87 #include "ih264e_deblk.h"
88
89
90 /*****************************************************************************/
91 /* global definitions */
92 /*****************************************************************************/
93
94 /**
95 ******************************************************************************
96 * @brief BS Table Lookup
97 * input :
98 * output :
99 * @remarks none
100 ******************************************************************************
101 */
102 static const UWORD32 gu4_bs_table[][16] =
103 {
104 {
105 0x00000000, 0x02000000, 0x00020000, 0x02020000,
106 0x00000200, 0x02000200, 0x00020200, 0x02020200,
107 0x00000002, 0x02000002, 0x00020002, 0x02020002,
108 0x00000202, 0x02000202, 0x00020202, 0x02020202
109 },
110 {
111 0x01010101, 0x02010101, 0x01020101, 0x02020101,
112 0x01010201, 0x02010201, 0x01020201, 0x02020201,
113 0x01010102, 0x02010102, 0x01020102, 0x02020102,
114 0x01010202, 0x02010202, 0x01020202, 0x02020202
115 }
116 };
117
118 /**
119 ******************************************************************************
120 * @brief Transpose Matrix used in BS
121 * input :
122 * output :
123 * @remarks none
124 ******************************************************************************
125 */
126 static const UWORD16 ih264e_gu2_4x4_v2h_reorder[16] =
127 {
128 0x0000, 0x0001, 0x0010, 0x0011,
129 0x0100, 0x0101, 0x0110, 0x0111,
130 0x1000, 0x1001, 0x1010, 0x1011,
131 0x1100, 0x1101, 0x1110, 0x1111
132 };
133
134
135 /*****************************************************************************/
136 /* Function Definitions */
137 /*****************************************************************************/
138
139 /**
140 *******************************************************************************
141 *
142 * @brief Fill BS value for all the edges of an mb
143 *
144 * @par Description:
145 * Fill BS value for all the edges of an mb
146 *
147 * @param[in] pu4_horz_bs
148 * Base pointer of horizontal BS table
149 *
150 * @param[in] pu4_vert_bs
151 * Base pointer of vertical BS table
152 *
153 * @param[in] u4_left_mb_csbp
154 * coded sub block pattern of left mb
155 *
156 * @param[in] u4_left_mb_csbp
157 * coded sub block pattern of top mb
158 *
159 * @param[in] ps_left_pu
160 * PU for left MB
161 *
162 * @param[in] ps_top_pu
163 * PU for top MB
164 *
165 * @param[in] ps_curr_pu
166 * PU for current MB
167 *
168 * @returns none
169 *
170 * @remarks none
171 *
172 *******************************************************************************
173 */
ih264e_fill_bs_1mv_1ref_non_mbaff(UWORD32 * pu4_horz_bs,UWORD32 * pu4_vert_bs,UWORD32 u4_left_mb_csbp,UWORD32 u4_top_mb_csbp,UWORD32 u4_cur_mb_csbp,enc_pu_t * ps_left_pu,enc_pu_t * ps_top_pu,enc_pu_t * ps_curr_pu)174 static void ih264e_fill_bs_1mv_1ref_non_mbaff(UWORD32 *pu4_horz_bs,
175 UWORD32 *pu4_vert_bs,
176 UWORD32 u4_left_mb_csbp,
177 UWORD32 u4_top_mb_csbp,
178 UWORD32 u4_cur_mb_csbp,
179 enc_pu_t *ps_left_pu,
180 enc_pu_t *ps_top_pu,
181 enc_pu_t *ps_curr_pu)
182 {
183 /* motion vectors of blks p & q */
184 WORD16 i16_qMvl0_x, i16_qMvl0_y, i16_pMvl0_x, i16_pMvl0_y;
185 WORD16 i16_qMvl1_x, i16_qMvl1_y, i16_pMvl1_x, i16_pMvl1_y;
186
187 /* temp var */
188 UWORD32 u4_left_flag, u4_top_flag;
189 const UWORD32 *bs_map;
190 UWORD32 u4_reordered_vert_bs_enc, u4_temp;
191
192 /* Coded Pattern for Horizontal Edge */
193 /*-----------------------------------------------------------------------*/
194 /*u4_nbr_horz_csbp=11C|10C|9C|8C|7C|6C|5C|4C|3C|2C|1C|0C|15T|14T|13T|12T */
195 /*-----------------------------------------------------------------------*/
196 UWORD32 u4_nbr_horz_csbp = (u4_cur_mb_csbp << 4) | (u4_top_mb_csbp >> 12);
197 UWORD32 u4_horz_bs_enc = u4_cur_mb_csbp | u4_nbr_horz_csbp;
198
199 /* Coded Pattern for Vertical Edge */
200 /*-----------------------------------------------------------------------*/
201 /*u4_left_mb_masked_csbp = 15L|0|0|0|11L|0|0|0|7L|0|0|0|3L|0|0|0 */
202 /*-----------------------------------------------------------------------*/
203 UWORD32 u4_left_mb_masked_csbp = u4_left_mb_csbp & CSBP_RIGHT_BLOCK_MASK;
204
205 /*-----------------------------------------------------------------------*/
206 /*u4_cur_mb_masked_csbp =14C|13C|12C|x|10C|9C|8C|x|6C|5C|4C|x|2C|1C|0C|x */
207 /*-----------------------------------------------------------------------*/
208 UWORD32 u4_cur_mb_masked_csbp = (u4_cur_mb_csbp << 1)
209 & (~CSBP_LEFT_BLOCK_MASK);
210
211 /*-----------------------------------------------------------------------*/
212 /*u4_nbr_vert_csbp=14C|13C|12C|15L|10C|9C|8C|11L|6C|5C|4C|7L|2C|1C|0C|3L */
213 /*-----------------------------------------------------------------------*/
214 UWORD32 u4_nbr_vert_csbp = (u4_cur_mb_masked_csbp)
215 | (u4_left_mb_masked_csbp >> 3);
216 UWORD32 u4_vert_bs_enc = u4_cur_mb_csbp | u4_nbr_vert_csbp;
217
218 /* BS Calculation for MB Boundary Edges */
219
220 /* BS calculation for 1 2 3 horizontal boundary */
221 bs_map = gu4_bs_table[0];
222 pu4_horz_bs[1] = bs_map[(u4_horz_bs_enc >> 4) & 0xF];
223 pu4_horz_bs[2] = bs_map[(u4_horz_bs_enc >> 8) & 0xF];
224 pu4_horz_bs[3] = bs_map[(u4_horz_bs_enc >> 12) & 0xF];
225
226 /* BS calculation for 5 6 7 vertical boundary */
227 /* Do 4x4 tranpose of u4_vert_bs_enc by using look up table for reorder */
228 u4_reordered_vert_bs_enc = ih264e_gu2_4x4_v2h_reorder[u4_vert_bs_enc & 0xF];
229
230 u4_temp = ih264e_gu2_4x4_v2h_reorder[(u4_vert_bs_enc >> 4) & 0xF];
231 u4_reordered_vert_bs_enc |= (u4_temp << 1);
232
233 u4_temp = ih264e_gu2_4x4_v2h_reorder[(u4_vert_bs_enc >> 8) & 0xF];
234 u4_reordered_vert_bs_enc |= (u4_temp << 2);
235
236 u4_temp = ih264e_gu2_4x4_v2h_reorder[(u4_vert_bs_enc >> 12) & 0xF];
237 u4_reordered_vert_bs_enc |= (u4_temp << 3);
238
239 pu4_vert_bs[1] = bs_map[(u4_reordered_vert_bs_enc >> 4) & 0xF];
240 pu4_vert_bs[2] = bs_map[(u4_reordered_vert_bs_enc >> 8) & 0xF];
241 pu4_vert_bs[3] = bs_map[(u4_reordered_vert_bs_enc >> 12) & 0xF];
242
243
244 /* BS Calculation for MB Boundary Edges */
245 if (ps_top_pu->b1_intra_flag)
246 {
247 pu4_horz_bs[0] = 0x04040404;
248 }
249 else
250 {
251 if (ps_curr_pu->b2_pred_mode != ps_top_pu->b2_pred_mode)
252 {
253 u4_top_flag = 1;
254 }
255 else if(ps_curr_pu->b2_pred_mode != 2)
256 {
257 i16_pMvl0_x = ps_top_pu->s_me_info[ps_top_pu->b2_pred_mode].s_mv.i2_mvx;
258 i16_pMvl0_y = ps_top_pu->s_me_info[ps_top_pu->b2_pred_mode].s_mv.i2_mvy;
259
260 i16_qMvl0_x = ps_curr_pu->s_me_info[ps_curr_pu->b2_pred_mode].s_mv.i2_mvx;
261 i16_qMvl0_y = ps_curr_pu->s_me_info[ps_curr_pu->b2_pred_mode].s_mv.i2_mvy;
262
263
264 u4_top_flag = (ABS((i16_pMvl0_x - i16_qMvl0_x)) >= 4)
265 | (ABS((i16_pMvl0_y - i16_qMvl0_y)) >= 4);
266 }
267 else
268 {
269
270 i16_pMvl0_x = ps_top_pu->s_me_info[PRED_L0].s_mv.i2_mvx;
271 i16_pMvl0_y = ps_top_pu->s_me_info[PRED_L0].s_mv.i2_mvy;
272 i16_pMvl1_x = ps_top_pu->s_me_info[PRED_L1].s_mv.i2_mvx;
273 i16_pMvl1_y = ps_top_pu->s_me_info[PRED_L1].s_mv.i2_mvy;
274
275 i16_qMvl0_x = ps_curr_pu->s_me_info[PRED_L0].s_mv.i2_mvx;
276 i16_qMvl0_y = ps_curr_pu->s_me_info[PRED_L0].s_mv.i2_mvy;
277 i16_qMvl1_x = ps_curr_pu->s_me_info[PRED_L1].s_mv.i2_mvx;
278 i16_qMvl1_y = ps_curr_pu->s_me_info[PRED_L1].s_mv.i2_mvy;
279
280
281 u4_top_flag = (ABS((i16_pMvl0_x - i16_qMvl0_x)) >= 4)
282 | (ABS((i16_pMvl0_y - i16_qMvl0_y)) >= 4)
283 | (ABS((i16_pMvl1_x - i16_qMvl1_x)) >= 4)
284 | (ABS((i16_pMvl1_y - i16_qMvl1_y)) >= 4);
285 }
286
287 bs_map = gu4_bs_table[!!u4_top_flag];
288 pu4_horz_bs[0] = bs_map[u4_horz_bs_enc & 0xF];
289 }
290
291
292 if (ps_left_pu->b1_intra_flag)
293 {
294 pu4_vert_bs[0] = 0x04040404;
295 }
296 else
297 {
298 if (ps_curr_pu->b2_pred_mode != ps_left_pu->b2_pred_mode)
299 {
300 u4_left_flag = 1;
301 }
302 else if (ps_curr_pu->b2_pred_mode != 2)/* Not bipred */
303 {
304 i16_pMvl0_x = ps_left_pu->s_me_info[ps_left_pu->b2_pred_mode].s_mv.i2_mvx;
305 i16_pMvl0_y = ps_left_pu->s_me_info[ps_left_pu->b2_pred_mode].s_mv.i2_mvy;
306
307 i16_qMvl0_x = ps_curr_pu->s_me_info[ps_curr_pu->b2_pred_mode].s_mv.i2_mvx;
308 i16_qMvl0_y = ps_curr_pu->s_me_info[ps_curr_pu->b2_pred_mode].s_mv.i2_mvy;
309
310
311 u4_left_flag = (ABS((i16_pMvl0_x - i16_qMvl0_x)) >= 4)
312 | (ABS((i16_pMvl0_y - i16_qMvl0_y)) >= 4);
313 }
314 else
315 {
316 i16_pMvl0_x = ps_left_pu->s_me_info[PRED_L0].s_mv.i2_mvx;
317 i16_pMvl0_y = ps_left_pu->s_me_info[PRED_L0].s_mv.i2_mvy;
318 i16_pMvl1_x = ps_left_pu->s_me_info[PRED_L1].s_mv.i2_mvx;
319 i16_pMvl1_y = ps_left_pu->s_me_info[PRED_L1].s_mv.i2_mvy;
320
321 i16_qMvl0_x = ps_curr_pu->s_me_info[PRED_L0].s_mv.i2_mvx;
322 i16_qMvl0_y = ps_curr_pu->s_me_info[PRED_L0].s_mv.i2_mvy;
323 i16_qMvl1_x = ps_curr_pu->s_me_info[PRED_L1].s_mv.i2_mvx;
324 i16_qMvl1_y = ps_curr_pu->s_me_info[PRED_L1].s_mv.i2_mvy;
325
326
327 u4_left_flag = (ABS((i16_pMvl0_x - i16_qMvl0_x)) >= 4)
328 | (ABS((i16_pMvl0_y - i16_qMvl0_y)) >= 4)
329 | (ABS((i16_pMvl1_x - i16_qMvl1_x)) >= 4)
330 | (ABS((i16_pMvl1_y - i16_qMvl1_y)) >= 4);
331 }
332
333 bs_map = gu4_bs_table[!!u4_left_flag];
334 pu4_vert_bs[0] = bs_map[u4_reordered_vert_bs_enc & 0xF];
335 }
336 }
337
338 /**
339 *******************************************************************************
340 *
341 * @brief calculate coded subblock pattern from nnz
342 *
343 * @par Description:
344 * calculate coded subblock pattern from nnz
345 *
346 * @param[in] ps_proc
347 * process context
348 *
349 * @returns csbp
350 *
351 * @remarks none
352 *
353 *******************************************************************************
354 */
ih264e_calculate_csbp(process_ctxt_t * ps_proc)355 static UWORD32 ih264e_calculate_csbp(process_ctxt_t *ps_proc)
356 {
357 /* number of non zeros for each tx blk */
358 UWORD8 *pu1_curr_nnz = (UWORD8 *)ps_proc->au4_nnz;
359
360 /* csbp */
361 UWORD32 u4_csbp = 0;
362
363 /* temp var */
364 WORD32 i4_i;
365
366 pu1_curr_nnz += 1;
367
368 /* Creating Subblock pattern for current MB */
369 /* 15C|14C|13C|12C|11C|10C|9C|8C|7C|6C|5C|4C|3C|2C|1C|0C */
370 for (i4_i = 0; i4_i < 16; i4_i++ )
371 {
372 u4_csbp |= ((!!*(pu1_curr_nnz + i4_i))<< i4_i);
373 }
374
375 return u4_csbp;
376 }
377
378 /**
379 *******************************************************************************
380 *
381 * @brief This function computes blocking strength for an mb
382 *
383 * @par Description:
384 * This function computes blocking strength for an mb
385 *
386 * @param[in] ps_proc
387 * process context
388 *
389 * @returns none
390 *
391 * @remarks
392 *
393 *******************************************************************************
394 */
ih264e_compute_bs(process_ctxt_t * ps_proc)395 void ih264e_compute_bs(process_ctxt_t * ps_proc)
396 {
397 /* deblk bs context */
398 bs_ctxt_t *ps_bs = &(ps_proc->s_deblk_ctxt.s_bs_ctxt);
399
400 /* vertical blocking strength */
401 UWORD32 *pu4_pic_vert_bs;
402
403 /* horizontal blocking strength */
404 UWORD32 *pu4_pic_horz_bs;
405
406 /* mb indices */
407 WORD32 i4_mb_x, i4_mb_y;
408
409 /* is intra */
410 WORD32 i4_intra;
411
412 /* temp var */
413 WORD32 i4_wd_mbs = ps_proc->i4_wd_mbs;
414
415 /* init indices */
416 i4_mb_x = ps_bs->i4_mb_x;
417 i4_mb_y = ps_bs->i4_mb_y;
418
419 /* init pointers */
420 pu4_pic_vert_bs = ps_bs->pu4_pic_vert_bs + ((i4_mb_y * i4_wd_mbs) + i4_mb_x) * 4;
421 pu4_pic_horz_bs = ps_bs->pu4_pic_horz_bs + ((i4_mb_y * i4_wd_mbs) + i4_mb_x) * 4;
422
423 /* is intra? */
424 i4_intra = ps_proc->u4_is_intra;
425
426 /* compute blocking strength */
427 if (i4_intra)
428 {
429 pu4_pic_vert_bs[0] = 0x04040404;
430 pu4_pic_vert_bs[1] = pu4_pic_vert_bs[2] = pu4_pic_vert_bs[3] = 0x03030303;
431
432 pu4_pic_horz_bs[0] = 0x04040404;
433 pu4_pic_horz_bs[1] = pu4_pic_horz_bs[2] = pu4_pic_horz_bs[3] = 0x03030303;
434 }
435 else
436 {
437 /* left mb syntax info */
438 mb_info_t *ps_left_mb_syntax_ele = &ps_proc->s_left_mb_syntax_ele;
439
440 /* top mb syntax info */
441 mb_info_t *ps_top_mb_syntax_ele = ps_proc->ps_top_row_mb_syntax_ele + i4_mb_x;
442
443 /* top row motion vector info */
444 enc_pu_t *ps_top_row_pu = ps_proc->ps_top_row_pu + i4_mb_x;
445
446 /* csbp for curr mb */
447 ps_proc->u4_csbp = ih264e_calculate_csbp(ps_proc);
448
449 /* csbp for ngbrs */
450 if (i4_mb_x == 0)
451 {
452 ps_left_mb_syntax_ele->u4_csbp = 0;
453 ps_proc->s_left_mb_pu.b1_intra_flag = 0;
454 ps_proc->s_left_mb_pu.b2_pred_mode = ps_proc->ps_pu->b2_pred_mode;
455 ps_proc->s_left_mb_pu.s_me_info[0].s_mv = ps_proc->ps_pu->s_me_info[0].s_mv;
456 ps_proc->s_left_mb_pu.s_me_info[1].s_mv = ps_proc->ps_pu->s_me_info[1].s_mv;
457 }
458 if (i4_mb_y == 0)
459 {
460 ps_top_mb_syntax_ele->u4_csbp = 0;
461 ps_top_row_pu->b1_intra_flag = 0;
462 ps_top_row_pu->b2_pred_mode = ps_proc->ps_pu->b2_pred_mode;
463 ps_top_row_pu->s_me_info[0].s_mv = ps_proc->ps_pu->s_me_info[0].s_mv;
464 ps_top_row_pu->s_me_info[1].s_mv = ps_proc->ps_pu->s_me_info[1].s_mv;
465 }
466
467 ih264e_fill_bs_1mv_1ref_non_mbaff(pu4_pic_horz_bs,
468 pu4_pic_vert_bs,
469 ps_left_mb_syntax_ele->u4_csbp,
470 ps_top_mb_syntax_ele->u4_csbp,
471 ps_proc->u4_csbp,
472 &ps_proc->s_left_mb_pu,
473 ps_top_row_pu,
474 ps_proc->ps_pu);
475 }
476
477 return ;
478 }
479
480 /**
481 *******************************************************************************
482 *
483 * @brief This function performs deblocking of top horizontal edge
484 *
485 * @par Description:
486 * This function performs deblocking of top horizontal edge
487 *
488 * @param[in] ps_codec
489 * pointer to codec context
490 *
491 * @param[in] ps_proc
492 * pointer to proc context
493 *
494 * @param[in] pu1_mb_qp
495 * pointer to mb quantization param
496 *
497 * @param[in] pu1_cur_pic_luma
498 * pointer to recon buffer luma
499 *
500 * @param[in] pu1_cur_pic_chroma
501 * pointer to recon buffer chroma
502 *
503 * @param[in] pu4_pic_horz_bs
504 * pointer to horizontal blocking strength
505 *
506 * @returns none
507 *
508 * @remarks none
509 *
510 *******************************************************************************
511 */
ih264e_filter_top_edge(codec_t * ps_codec,process_ctxt_t * ps_proc,UWORD8 * pu1_mb_qp,UWORD8 * pu1_cur_pic_luma,UWORD8 * pu1_cur_pic_chroma,UWORD32 * pu4_pic_horz_bs)512 static void ih264e_filter_top_edge(codec_t *ps_codec,
513 process_ctxt_t *ps_proc,
514 UWORD8 *pu1_mb_qp,
515 UWORD8 *pu1_cur_pic_luma,
516 UWORD8 *pu1_cur_pic_chroma,
517 UWORD32 *pu4_pic_horz_bs)
518 {
519 /* strd */
520 WORD32 i4_rec_strd = ps_proc->i4_rec_strd;
521
522 /* deblk params */
523 UWORD32 u4_alpha_luma, u4_beta_luma, u4_qp_luma, u4_idx_A_luma, u4_idx_B_luma, u4_qp_p, u4_qp_q;
524 UWORD32 u4_alpha_chroma, u4_beta_chroma, u4_qp_chroma, u4_idx_A_chroma, u4_idx_B_chroma;
525
526 /* collect qp of left & top mb */
527 u4_qp_p = pu1_mb_qp[-ps_proc->i4_wd_mbs];
528 u4_qp_q = pu1_mb_qp[0];
529
530 /********/
531 /* luma */
532 /********/
533 u4_qp_luma = (u4_qp_p + u4_qp_q + 1) >> 1;
534
535 /* filter offset A and filter offset B have to be received from slice header */
536 /* TODO : for now lets set these offsets as zero */
537
538
539 u4_idx_A_luma = MIN(51, u4_qp_luma + 0);
540 u4_idx_B_luma = MIN(51, u4_qp_luma + 0);
541
542 /* alpha, beta computation */
543 u4_alpha_luma = gu1_ih264_alpha_table[u4_idx_A_luma];
544 u4_beta_luma = gu1_ih264_beta_table[u4_idx_B_luma];
545
546 /**********/
547 /* chroma */
548 /**********/
549 u4_qp_chroma = (gu1_qpc_fqpi[u4_qp_p] + gu1_qpc_fqpi[u4_qp_q] + 1) >> 1;
550
551 /* filter offset A and filter offset B have to be received from slice header */
552 /* TODO : for now lets set these offsets as zero */
553
554
555 u4_idx_A_chroma = MIN(51, u4_qp_chroma + 0);
556 u4_idx_B_chroma = MIN(51, u4_qp_chroma + 0);
557
558 /* alpha, beta computation */
559 u4_alpha_chroma = gu1_ih264_alpha_table[u4_idx_A_chroma];
560 u4_beta_chroma = gu1_ih264_beta_table[u4_idx_B_chroma];
561
562 /* deblk edge */
563 /* top Horizontal edge - allowed to be deblocked ? */
564 if (pu4_pic_horz_bs[0] == 0x04040404)
565 {
566 /* strong filter */
567 ps_codec->pf_deblk_luma_horz_bs4(pu1_cur_pic_luma, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
568 ps_codec->pf_deblk_chroma_horz_bs4(pu1_cur_pic_chroma, i4_rec_strd, u4_alpha_chroma, u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma);
569 }
570 else
571 {
572 /* normal filter */
573 ps_codec->pf_deblk_luma_horz_bslt4(pu1_cur_pic_luma, i4_rec_strd, u4_alpha_luma,
574 u4_beta_luma, pu4_pic_horz_bs[0],
575 gu1_ih264_clip_table[u4_idx_A_luma]);
576
577 ps_codec->pf_deblk_chroma_horz_bslt4(pu1_cur_pic_chroma, i4_rec_strd, u4_alpha_chroma,
578 u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma, pu4_pic_horz_bs[0],
579 gu1_ih264_clip_table[u4_idx_A_chroma], gu1_ih264_clip_table[u4_idx_A_chroma]);
580 }
581 }
582
583 /**
584 *******************************************************************************
585 *
586 * @brief This function performs deblocking of left vertical edge
587 *
588 * @par Description:
589 * This function performs deblocking of top horizontal edge
590 *
591 * @param[in] ps_codec
592 * pointer to codec context
593 *
594 * @param[in] ps_proc
595 * pointer to proc context
596 *
597 * @param[in] pu1_mb_qp
598 * pointer to mb quantization param
599 *
600 * @param[in] pu1_cur_pic_luma
601 * pointer to recon buffer luma
602 *
603 * @param[in] pu1_cur_pic_chroma
604 * pointer to recon buffer chroma
605 *
606 * @param[in] pu4_pic_vert_bs
607 * pointer to vertical blocking strength
608 *
609 * @returns none
610 *
611 * @remarks none
612 *
613 *******************************************************************************
614 */
ih264e_filter_left_edge(codec_t * ps_codec,process_ctxt_t * ps_proc,UWORD8 * pu1_mb_qp,UWORD8 * pu1_cur_pic_luma,UWORD8 * pu1_cur_pic_chroma,UWORD32 * pu4_pic_vert_bs)615 static void ih264e_filter_left_edge(codec_t *ps_codec,
616 process_ctxt_t *ps_proc,
617 UWORD8 *pu1_mb_qp,
618 UWORD8 *pu1_cur_pic_luma,
619 UWORD8 *pu1_cur_pic_chroma,
620 UWORD32 *pu4_pic_vert_bs)
621 {
622 /* strd */
623 WORD32 i4_rec_strd = ps_proc->i4_rec_strd;
624
625 /* deblk params */
626 UWORD32 u4_alpha_luma, u4_beta_luma, u4_qp_luma, u4_idx_A_luma, u4_idx_B_luma, u4_qp_p, u4_qp_q;
627 UWORD32 u4_alpha_chroma, u4_beta_chroma, u4_qp_chroma, u4_idx_A_chroma, u4_idx_B_chroma;
628
629 /* collect qp of left & curr mb */
630 u4_qp_p = pu1_mb_qp[-1];
631 u4_qp_q = pu1_mb_qp[0];
632
633 /********/
634 /* luma */
635 /********/
636 u4_qp_luma = (u4_qp_p + u4_qp_q + 1) >> 1;
637
638 /* filter offset A and filter offset B have to be received from slice header */
639 /* TODO : for now lets set these offsets as zero */
640
641
642 u4_idx_A_luma = MIN(51, u4_qp_luma + 0);
643 u4_idx_B_luma = MIN(51, u4_qp_luma + 0);
644
645 /* alpha, beta computation */
646 u4_alpha_luma = gu1_ih264_alpha_table[u4_idx_A_luma];
647 u4_beta_luma = gu1_ih264_beta_table[u4_idx_B_luma];
648
649 /**********/
650 /* chroma */
651 /**********/
652 u4_qp_chroma = (gu1_qpc_fqpi[u4_qp_p] + gu1_qpc_fqpi[u4_qp_q] + 1) >> 1;
653
654 /* filter offset A and filter offset B have to be received from slice header */
655 /* TODO : for now lets set these offsets as zero */
656
657
658 u4_idx_A_chroma = MIN(51, u4_qp_chroma + 0);
659 u4_idx_B_chroma = MIN(51, u4_qp_chroma + 0);
660
661 /* alpha, beta computation */
662 u4_alpha_chroma = gu1_ih264_alpha_table[u4_idx_A_chroma];
663 u4_beta_chroma = gu1_ih264_beta_table[u4_idx_B_chroma];
664
665 /* deblk edge */
666 if (pu4_pic_vert_bs[0] == 0x04040404)
667 {
668 /* strong filter */
669 ps_codec->pf_deblk_luma_vert_bs4(pu1_cur_pic_luma, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
670 ps_codec->pf_deblk_chroma_vert_bs4(pu1_cur_pic_chroma, i4_rec_strd, u4_alpha_chroma, u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma);
671 }
672 else
673 {
674 /* normal filter */
675 ps_codec->pf_deblk_luma_vert_bslt4(pu1_cur_pic_luma, i4_rec_strd,
676 u4_alpha_luma, u4_beta_luma,
677 pu4_pic_vert_bs[0],
678 gu1_ih264_clip_table[u4_idx_A_luma]);
679
680 ps_codec->pf_deblk_chroma_vert_bslt4(pu1_cur_pic_chroma, i4_rec_strd, u4_alpha_chroma,
681 u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma, pu4_pic_vert_bs[0],
682 gu1_ih264_clip_table[u4_idx_A_chroma], gu1_ih264_clip_table[u4_idx_A_chroma]);
683 }
684 }
685
686 /**
687 *******************************************************************************
688 *
689 * @brief This function performs deblocking on an mb
690 *
691 * @par Description:
692 * This function performs deblocking on an mb
693 *
694 * @param[in] ps_proc
695 * process context corresponding to the job
696 *
697 * @param[in] ps_deblk
698 * pointer to deblock context
699 *
700 * @returns none
701 *
702 * @remarks none
703 *
704 *******************************************************************************
705 */
ih264e_deblock_mb(process_ctxt_t * ps_proc,deblk_ctxt_t * ps_deblk)706 void ih264e_deblock_mb(process_ctxt_t *ps_proc, deblk_ctxt_t * ps_deblk)
707 {
708 /* codec ctxt */
709 codec_t *ps_codec = ps_proc->ps_codec;
710
711 /* ngbr availability */
712 UWORD8 u1_mb_a, u1_mb_b;
713
714 /* mb indices */
715 WORD32 i4_mb_x = ps_deblk->i4_mb_x, i4_mb_y = ps_deblk->i4_mb_y;
716
717 /* pic qp ptr */
718 UWORD8 *pu1_pic_qp = ps_deblk->s_bs_ctxt.pu1_pic_qp;
719
720 /* vertical blocking strength */
721 UWORD32 *pu4_pic_vert_bs = ps_deblk->s_bs_ctxt.pu4_pic_vert_bs;
722
723 /* horizontal blocking strength */
724 UWORD32 *pu4_pic_horz_bs = ps_deblk->s_bs_ctxt.pu4_pic_horz_bs;
725
726 /* src buffers luma */
727 UWORD8 *pu1_cur_pic_luma = ps_deblk->pu1_cur_pic_luma;
728
729 /* src buffers chroma */
730 UWORD8 *pu1_cur_pic_chroma = ps_deblk->pu1_cur_pic_chroma;
731
732 /* strd */
733 WORD32 i4_rec_strd = ps_proc->i4_rec_strd;
734
735 /* deblk params */
736 UWORD32 u4_alpha_luma, u4_beta_luma, u4_qp_luma, u4_idx_A_luma, u4_idx_B_luma;
737 UWORD32 u4_alpha_chroma, u4_beta_chroma, u4_qp_chroma, u4_idx_A_chroma, u4_idx_B_chroma;
738
739 /* temp var */
740 UWORD32 push_ptr = (i4_mb_y * ps_proc->i4_wd_mbs) + i4_mb_x;
741
742 /* derive neighbor availability */
743 /* In slice mode the edges of mbs that lie on the slice boundary are not deblocked */
744 /* deblocking filter idc '2' */
745 if (ps_codec->s_cfg.e_slice_mode != IVE_SLICE_MODE_NONE)
746 {
747 /* slice index */
748 UWORD8 *pu1_slice_idx = ps_deblk->pu1_slice_idx;
749
750 pu1_slice_idx += (i4_mb_y * ps_proc->i4_wd_mbs);
751 /* left macroblock availability */
752 u1_mb_a = (i4_mb_x == 0 ||
753 (pu1_slice_idx[i4_mb_x - 1 ] != pu1_slice_idx[i4_mb_x]))? 0 : 1;
754 /* top macroblock availability */
755 u1_mb_b = (i4_mb_y == 0 ||
756 (pu1_slice_idx[i4_mb_x-ps_proc->i4_wd_mbs] != pu1_slice_idx[i4_mb_x]))? 0 : 1;
757 }
758 else
759 {
760 /* left macroblock availability */
761 u1_mb_a = (i4_mb_x == 0)? 0 : 1;
762 /* top macroblock availability */
763 u1_mb_b = (i4_mb_y == 0)? 0 : 1;
764 }
765
766 pu1_pic_qp += push_ptr;
767 pu4_pic_vert_bs += push_ptr * 4;
768 pu4_pic_horz_bs += push_ptr * 4;
769
770 /********/
771 /* luma */
772 /********/
773 u4_qp_luma = pu1_pic_qp[0];
774
775 /* filter offset A and filter offset B have to be received from slice header */
776 /* TODO : for now lets set these offsets as zero */
777
778
779 u4_idx_A_luma = MIN(51, u4_qp_luma + 0);
780 u4_idx_B_luma = MIN(51, u4_qp_luma + 0);
781
782 /* alpha, beta computation */
783 u4_alpha_luma = gu1_ih264_alpha_table[u4_idx_A_luma];
784 u4_beta_luma = gu1_ih264_beta_table[u4_idx_B_luma];
785
786 /**********/
787 /* chroma */
788 /**********/
789 u4_qp_chroma = gu1_qpc_fqpi[u4_qp_luma];
790
791 /* filter offset A and filter offset B have to be received from slice header */
792 /* TODO : for now lets set these offsets as zero */
793
794
795 u4_idx_A_chroma = MIN(51, u4_qp_chroma + 0);
796 u4_idx_B_chroma = MIN(51, u4_qp_chroma + 0);
797
798 /* alpha, beta computation */
799 u4_alpha_chroma = gu1_ih264_alpha_table[u4_idx_A_chroma];
800 u4_beta_chroma = gu1_ih264_beta_table[u4_idx_B_chroma];
801
802 /* Deblock vertical edges */
803 /* left vertical edge 0 - allowed to be deblocked ? */
804 if (u1_mb_a)
805 {
806 ih264e_filter_left_edge(ps_codec, ps_proc, pu1_pic_qp, pu1_cur_pic_luma, pu1_cur_pic_chroma, pu4_pic_vert_bs);
807 }
808
809 /* vertical edge 1 */
810 if (pu4_pic_vert_bs[1] == 0x04040404)
811 {
812 /* strong filter */
813 ps_codec->pf_deblk_luma_vert_bs4(pu1_cur_pic_luma + 4, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
814 }
815 else
816 {
817 /* normal filter */
818 ps_codec->pf_deblk_luma_vert_bslt4(pu1_cur_pic_luma + 4, i4_rec_strd,
819 u4_alpha_luma, u4_beta_luma,
820 pu4_pic_vert_bs[1],
821 gu1_ih264_clip_table[u4_idx_A_luma]);
822 }
823
824 /* vertical edge 2 */
825 if (pu4_pic_vert_bs[2] == 0x04040404)
826 {
827 /* strong filter */
828 ps_codec->pf_deblk_luma_vert_bs4(pu1_cur_pic_luma + 8, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
829 ps_codec->pf_deblk_chroma_vert_bs4(pu1_cur_pic_chroma + 8, i4_rec_strd, u4_alpha_chroma, u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma);
830 }
831 else
832 {
833 /* normal filter */
834 ps_codec->pf_deblk_luma_vert_bslt4(pu1_cur_pic_luma + 8, i4_rec_strd, u4_alpha_luma,
835 u4_beta_luma, pu4_pic_vert_bs[2],
836 gu1_ih264_clip_table[u4_idx_A_luma]);
837
838 ps_codec->pf_deblk_chroma_vert_bslt4(pu1_cur_pic_chroma + 8, i4_rec_strd, u4_alpha_chroma,
839 u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma, pu4_pic_vert_bs[2],
840 gu1_ih264_clip_table[u4_idx_A_chroma], gu1_ih264_clip_table[u4_idx_A_chroma]);
841 }
842
843 /* vertical edge 3 */
844 if (pu4_pic_vert_bs[3] == 0x04040404)
845 {
846 /* strong filter */
847 ps_codec->pf_deblk_luma_vert_bs4(pu1_cur_pic_luma + 12, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
848 }
849 else
850 {
851 /* normal filter */
852 ps_codec->pf_deblk_luma_vert_bslt4(pu1_cur_pic_luma + 12, i4_rec_strd, u4_alpha_luma,
853 u4_beta_luma, pu4_pic_vert_bs[3],
854 gu1_ih264_clip_table[u4_idx_A_luma]);
855 }
856
857 /* Deblock Horizontal edges */
858 /* Horizontal edge 0 */
859 if (u1_mb_b)
860 {
861 ih264e_filter_top_edge(ps_codec, ps_proc, pu1_pic_qp, pu1_cur_pic_luma, pu1_cur_pic_chroma, pu4_pic_horz_bs);
862 }
863
864 /* horizontal edge 1 */
865 if (pu4_pic_horz_bs[1] == 0x04040404)
866 {
867 /* strong filter */
868 ps_codec->pf_deblk_luma_horz_bs4(pu1_cur_pic_luma + 4 * i4_rec_strd, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
869 }
870 else
871 {
872 /* normal filter */
873 ps_codec->pf_deblk_luma_horz_bslt4(pu1_cur_pic_luma + 4 * i4_rec_strd, i4_rec_strd, u4_alpha_luma,
874 u4_beta_luma, pu4_pic_horz_bs[1],
875 gu1_ih264_clip_table[u4_idx_A_luma]);
876 }
877
878 /* horizontal edge 2 */
879 if (pu4_pic_horz_bs[2] == 0x04040404)
880 {
881 /* strong filter */
882 ps_codec->pf_deblk_luma_horz_bs4(pu1_cur_pic_luma + 8 * i4_rec_strd, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
883 ps_codec->pf_deblk_chroma_horz_bs4(pu1_cur_pic_chroma + 4 * i4_rec_strd, i4_rec_strd, u4_alpha_chroma, u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma);
884 }
885 else
886 {
887 /* normal filter */
888 ps_codec->pf_deblk_luma_horz_bslt4(pu1_cur_pic_luma + 8 * i4_rec_strd, i4_rec_strd, u4_alpha_luma,
889 u4_beta_luma, pu4_pic_horz_bs[2],
890 gu1_ih264_clip_table[u4_idx_A_luma]);
891
892 ps_codec->pf_deblk_chroma_horz_bslt4(pu1_cur_pic_chroma + 4 * i4_rec_strd, i4_rec_strd, u4_alpha_chroma,
893 u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma, pu4_pic_horz_bs[2],
894 gu1_ih264_clip_table[u4_idx_A_chroma], gu1_ih264_clip_table[u4_idx_A_chroma]);
895 }
896
897 /* horizontal edge 3 */
898 if (pu4_pic_horz_bs[3] == 0x04040404)
899 {
900 /* strong filter */
901 ps_codec->pf_deblk_luma_horz_bs4(pu1_cur_pic_luma + 12 * i4_rec_strd, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
902 }
903 else
904 {
905 /* normal filter */
906 ps_codec->pf_deblk_luma_horz_bslt4(pu1_cur_pic_luma + 12 * i4_rec_strd, i4_rec_strd, u4_alpha_luma,
907 u4_beta_luma, pu4_pic_horz_bs[3],
908 gu1_ih264_clip_table[u4_idx_A_luma]);
909 }
910
911 return ;
912 }
913