summaryrefslogtreecommitdiffstats
path: root/encoder/ih264e_deblk.c
blob: db176ac70bbd9f6bc4c7fd3b06d5860278db9f3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

/**
 *******************************************************************************
 * @file
 *  ih264e_deblk.c
 *
 * @brief
 *  This file contains functions that are associated with deblocking
 *
 * @author
 *  ittiam
 *
 * @par List of Functions:
 *  - ih264e_fill_bs_1mv_1ref_non_mbaff
 *  - ih264e_calculate_csbp
 *  - ih264e_compute_bs
 *  - ih264e_filter_top_edge
 *  - ih264e_filter_left_edge
 *  - ih264e_deblock_mb
 *
 * @remarks
 *  None
 *
 *******************************************************************************
 */

/*****************************************************************************/
/* File Includes                                                             */
/*****************************************************************************/

/* System include files */
#include <stdio.h>
#include <string.h>
#include <assert.h>

/* User include files */
#include "ih264e_config.h"
#include "ih264_typedefs.h"
#include "iv2.h"
#include "ive2.h"
#include "ih264_macros.h"
#include "ih264_defs.h"
#include "ih264e_defs.h"
#include "ih264e_error.h"
#include "ih264e_bitstream.h"
#include "ime_distortion_metrics.h"
#include "ime_defs.h"
#include "ime_structs.h"
#include "ih264_structs.h"
#include "ih264_trans_quant_itrans_iquant.h"
#include "ih264_inter_pred_filters.h"
#include "ih264_mem_fns.h"
#include "ih264_padding.h"
#include "ih264_intra_pred_filters.h"
#include "ih264_deblk_edge_filters.h"
#include "ih264_cabac_tables.h"
#include "irc_cntrl_param.h"
#include "irc_frame_info_collector.h"
#include "ih264e_rate_control.h"
#include "ih264e_cabac_structs.h"
#include "ih264e_structs.h"
#include "ih264_trans_data.h"
#include "ih264_deblk_tables.h"
#include "ih264e_deblk.h"


/*****************************************************************************/
/* Extern global definitions                                                 */
/*****************************************************************************/

/**
******************************************************************************
* @brief  BS Table Lookup
* input  :
* output :
* @remarks none
******************************************************************************
*/
static const UWORD32 gu4_bs_table[][16] =
{
    {
        0x00000000, 0x02000000, 0x00020000, 0x02020000,
        0x00000200, 0x02000200, 0x00020200, 0x02020200,
        0x00000002, 0x02000002, 0x00020002, 0x02020002,
        0x00000202, 0x02000202, 0x00020202, 0x02020202
    },
    {
        0x01010101, 0x02010101, 0x01020101, 0x02020101,
        0x01010201, 0x02010201, 0x01020201, 0x02020201,
        0x01010102, 0x02010102, 0x01020102, 0x02020102,
        0x01010202, 0x02010202, 0x01020202, 0x02020202
    }
};

/**
******************************************************************************
* @brief  Transpose Matrix used in BS
* input  :
* output :
* @remarks none
******************************************************************************
*/
static const UWORD16  ih264e_gu2_4x4_v2h_reorder[16] =
{
    0x0000, 0x0001, 0x0010, 0x0011,
    0x0100, 0x0101, 0x0110, 0x0111,
    0x1000, 0x1001, 0x1010, 0x1011,
    0x1100, 0x1101, 0x1110, 0x1111
};


/*****************************************************************************/
/* Function Definitions                                                      */
/*****************************************************************************/

/**
*******************************************************************************
*
* @brief Fill BS value for all the edges of an mb
*
* @par Description:
*  Fill BS value for all the edges of an mb
*
* @param[in] pu4_horz_bs
*  Base pointer of horizontal BS table
*
* @param[in] pu4_vert_bs
*  Base pointer of vertical BS table
*
* @param[in] u4_left_mb_csbp
*  coded sub block pattern of left mb
*
* @param[in] u4_left_mb_csbp
*  coded sub block pattern of top mb
*
* @param[in] ps_left_pu
*  PU for left MB
*
* @param[in] ps_top_pu
*  PU for top MB
*
* @param[in] ps_curr_pu
*  PU for current MB
*
*
* @returns  none
*
* @remarks  none
*
*******************************************************************************
*/
static void 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)
{
    /* motion vectors of blks p & q */
    WORD16 i16_qMvl0_x, i16_qMvl0_y, i16_pMvl0_x, i16_pMvl0_y;
    WORD16 i16_qMvl1_x, i16_qMvl1_y, i16_pMvl1_x, i16_pMvl1_y;

    /* temp var */
    UWORD32 u4_left_flag, u4_top_flag;
    const UWORD32 *bs_map;
    UWORD32 u4_reordered_vert_bs_enc, u4_temp;

    /* Coded Pattern for Horizontal Edge */
    /*-----------------------------------------------------------------------*/
    /*u4_nbr_horz_csbp=11C|10C|9C|8C|7C|6C|5C|4C|3C|2C|1C|0C|15T|14T|13T|12T */
    /*-----------------------------------------------------------------------*/
    UWORD32 u4_nbr_horz_csbp = (u4_cur_mb_csbp << 4) | (u4_top_mb_csbp >> 12);
    UWORD32 u4_horz_bs_enc = u4_cur_mb_csbp | u4_nbr_horz_csbp;

    /* Coded Pattern for Vertical Edge */
    /*-----------------------------------------------------------------------*/
    /*u4_left_mb_masked_csbp = 15L|0|0|0|11L|0|0|0|7L|0|0|0|3L|0|0|0         */
    /*-----------------------------------------------------------------------*/
    UWORD32 u4_left_mb_masked_csbp = u4_left_mb_csbp & CSBP_RIGHT_BLOCK_MASK;

    /*-----------------------------------------------------------------------*/
    /*u4_cur_mb_masked_csbp =14C|13C|12C|x|10C|9C|8C|x|6C|5C|4C|x|2C|1C|0C|x */
    /*-----------------------------------------------------------------------*/
    UWORD32 u4_cur_mb_masked_csbp = (u4_cur_mb_csbp << 1)
                    & (~CSBP_LEFT_BLOCK_MASK);

    /*-----------------------------------------------------------------------*/
    /*u4_nbr_vert_csbp=14C|13C|12C|15L|10C|9C|8C|11L|6C|5C|4C|7L|2C|1C|0C|3L */
    /*-----------------------------------------------------------------------*/
    UWORD32 u4_nbr_vert_csbp = (u4_cur_mb_masked_csbp)
                    | (u4_left_mb_masked_csbp >> 3);
    UWORD32 u4_vert_bs_enc = u4_cur_mb_csbp | u4_nbr_vert_csbp;

    /* BS Calculation for MB Boundary Edges */

    /* BS calculation for 1 2 3 horizontal boundary */
    bs_map = gu4_bs_table[0];
    pu4_horz_bs[1] = bs_map[(u4_horz_bs_enc >> 4) & 0xF];
    pu4_horz_bs[2] = bs_map[(u4_horz_bs_enc >> 8) & 0xF];
    pu4_horz_bs[3] = bs_map[(u4_horz_bs_enc >> 12) & 0xF];

    /* BS calculation for 5 6 7 vertical boundary */
    /* Do 4x4 tranpose of u4_vert_bs_enc by using look up table for reorder */
    u4_reordered_vert_bs_enc = ih264e_gu2_4x4_v2h_reorder[u4_vert_bs_enc & 0xF];

    u4_temp = ih264e_gu2_4x4_v2h_reorder[(u4_vert_bs_enc >> 4) & 0xF];
    u4_reordered_vert_bs_enc |= (u4_temp << 1);

    u4_temp = ih264e_gu2_4x4_v2h_reorder[(u4_vert_bs_enc >> 8) & 0xF];
    u4_reordered_vert_bs_enc |= (u4_temp << 2);

    u4_temp = ih264e_gu2_4x4_v2h_reorder[(u4_vert_bs_enc >> 12) & 0xF];
    u4_reordered_vert_bs_enc |= (u4_temp << 3);

    pu4_vert_bs[1] = bs_map[(u4_reordered_vert_bs_enc >> 4) & 0xF];
    pu4_vert_bs[2] = bs_map[(u4_reordered_vert_bs_enc >> 8) & 0xF];
    pu4_vert_bs[3] = bs_map[(u4_reordered_vert_bs_enc >> 12) & 0xF];


    /* BS Calculation for MB Boundary Edges */
    if (ps_top_pu->b1_intra_flag)
    {
        pu4_horz_bs[0] = 0x04040404;
    }
    else
    {
        if (ps_curr_pu->b2_pred_mode != ps_top_pu->b2_pred_mode)
        {
            u4_top_flag = 1;
        }
        else if(ps_curr_pu->b2_pred_mode != 2)
        {
            i16_pMvl0_x = ps_top_pu->s_me_info[ps_top_pu->b2_pred_mode].s_mv.i2_mvx;
            i16_pMvl0_y = ps_top_pu->s_me_info[ps_top_pu->b2_pred_mode].s_mv.i2_mvy;

            i16_qMvl0_x = ps_curr_pu->s_me_info[ps_curr_pu->b2_pred_mode].s_mv.i2_mvx;
            i16_qMvl0_y = ps_curr_pu->s_me_info[ps_curr_pu->b2_pred_mode].s_mv.i2_mvy;


            u4_top_flag =  (ABS((i16_pMvl0_x - i16_qMvl0_x)) >= 4)
                         | (ABS((i16_pMvl0_y - i16_qMvl0_y)) >= 4);
        }
        else
        {

            i16_pMvl0_x = ps_top_pu->s_me_info[PRED_L0].s_mv.i2_mvx;
            i16_pMvl0_y = ps_top_pu->s_me_info[PRED_L0].s_mv.i2_mvy;
            i16_pMvl1_x = ps_top_pu->s_me_info[PRED_L1].s_mv.i2_mvx;
            i16_pMvl1_y = ps_top_pu->s_me_info[PRED_L1].s_mv.i2_mvy;

            i16_qMvl0_x = ps_curr_pu->s_me_info[PRED_L0].s_mv.i2_mvx;
            i16_qMvl0_y = ps_curr_pu->s_me_info[PRED_L0].s_mv.i2_mvy;
            i16_qMvl1_x = ps_curr_pu->s_me_info[PRED_L1].s_mv.i2_mvx;
            i16_qMvl1_y = ps_curr_pu->s_me_info[PRED_L1].s_mv.i2_mvy;


            u4_top_flag =  (ABS((i16_pMvl0_x - i16_qMvl0_x)) >= 4)
                         | (ABS((i16_pMvl0_y - i16_qMvl0_y)) >= 4)
                         | (ABS((i16_pMvl1_x - i16_qMvl1_x)) >= 4)
                         | (ABS((i16_pMvl1_y - i16_qMvl1_y)) >= 4);
        }

        bs_map = gu4_bs_table[!!u4_top_flag];
        pu4_horz_bs[0] = bs_map[u4_horz_bs_enc & 0xF];
    }


    if (ps_left_pu->b1_intra_flag)
    {
        pu4_vert_bs[0] = 0x04040404;
    }
    else
    {
        if (ps_curr_pu->b2_pred_mode != ps_left_pu->b2_pred_mode)
        {
            u4_left_flag = 1;
        }
        else if(ps_curr_pu->b2_pred_mode != 2)/* Not bipred */
        {
            i16_pMvl0_x = ps_left_pu->s_me_info[ps_left_pu->b2_pred_mode].s_mv.i2_mvx;
            i16_pMvl0_y = ps_left_pu->s_me_info[ps_left_pu->b2_pred_mode].s_mv.i2_mvy;

            i16_qMvl0_x = ps_curr_pu->s_me_info[ps_curr_pu->b2_pred_mode].s_mv.i2_mvx;
            i16_qMvl0_y = ps_curr_pu->s_me_info[ps_curr_pu->b2_pred_mode].s_mv.i2_mvy;


            u4_left_flag =  (ABS((i16_pMvl0_x - i16_qMvl0_x)) >= 4)
                          | (ABS((i16_pMvl0_y - i16_qMvl0_y)) >= 4);
        }
        else
        {

            i16_pMvl0_x = ps_left_pu->s_me_info[PRED_L0].s_mv.i2_mvx;
            i16_pMvl0_y = ps_left_pu->s_me_info[PRED_L0].s_mv.i2_mvy;
            i16_pMvl1_x = ps_left_pu->s_me_info[PRED_L1].s_mv.i2_mvx;
            i16_pMvl1_y = ps_left_pu->s_me_info[PRED_L1].s_mv.i2_mvy;

            i16_qMvl0_x = ps_curr_pu->s_me_info[PRED_L0].s_mv.i2_mvx;
            i16_qMvl0_y = ps_curr_pu->s_me_info[PRED_L0].s_mv.i2_mvy;
            i16_qMvl1_x = ps_curr_pu->s_me_info[PRED_L1].s_mv.i2_mvx;
            i16_qMvl1_y = ps_curr_pu->s_me_info[PRED_L1].s_mv.i2_mvy;


            u4_left_flag =  (ABS((i16_pMvl0_x - i16_qMvl0_x)) >= 4)
                          | (ABS((i16_pMvl0_y - i16_qMvl0_y)) >= 4)
                          | (ABS((i16_pMvl1_x - i16_qMvl1_x)) >= 4)
                          | (ABS((i16_pMvl1_y - i16_qMvl1_y)) >= 4);
        }

        bs_map = gu4_bs_table[!!u4_left_flag];
        pu4_vert_bs[0] = bs_map[u4_reordered_vert_bs_enc & 0xF];
    }
}

/**
*******************************************************************************
*
* @brief calculate coded subblock pattern from nnz
*
* @par Description:
*  calculate coded subblock pattern from nnz
*
* @param[in] ps_proc
*  process context
*
* @returns  csbp
*
* @remarks  none
*
*******************************************************************************
*/
static UWORD32 ih264e_calculate_csbp(process_ctxt_t *ps_proc)
{
    /* number of non zeros for each tx blk */
    UWORD8 *pu1_curr_nnz = (UWORD8 *)ps_proc->au4_nnz;

    /* csbp */
    UWORD32 u4_csbp = 0;

    /* temp var */
    WORD32  i4_i;

    pu1_curr_nnz += 1;

    /* Creating Subblock pattern for current MB */
    /* 15C|14C|13C|12C|11C|10C|9C|8C|7C|6C|5C|4C|3C|2C|1C|0C  */
    for (i4_i = 0; i4_i < 16; i4_i++ )
    {
        u4_csbp |= ((!!*(pu1_curr_nnz + i4_i))<< i4_i);
    }

    return u4_csbp;
}

/**
*******************************************************************************
*
* @brief This function computes blocking strength for an mb
*
* @par Description:
*  This function computes blocking strength for an mb
*
* @param[in] ps_proc
*  process context
*
* @returns  none
*
* @remarks
*
*******************************************************************************
*/
void ih264e_compute_bs(process_ctxt_t * ps_proc)
{
    /* deblk bs context */
    bs_ctxt_t *ps_bs = &(ps_proc->s_deblk_ctxt.s_bs_ctxt);

    /* vertical blocking strength */
    UWORD32 *pu4_pic_vert_bs;

    /* horizontal blocking strength */
    UWORD32 *pu4_pic_horz_bs;

    /* mb indices */
    WORD32 i4_mb_x, i4_mb_y;

    /* is intra */
    WORD32 i4_intra;

    /* temp var */
    WORD32 i4_wd_mbs = ps_proc->i4_wd_mbs;

    /* init indices */
    i4_mb_x = ps_bs->i4_mb_x;
    i4_mb_y = ps_bs->i4_mb_y;

    /* init pointers */
    pu4_pic_vert_bs = ps_bs->pu4_pic_vert_bs + ((i4_mb_y * i4_wd_mbs) + i4_mb_x) * 4;
    pu4_pic_horz_bs = ps_bs->pu4_pic_horz_bs + ((i4_mb_y * i4_wd_mbs) + i4_mb_x) * 4;

    /* is intra? */
    i4_intra = ps_proc->u4_is_intra;

    /* compute blocking strength */
    if (i4_intra)
    {
        pu4_pic_vert_bs[0] = 0x04040404;
        pu4_pic_vert_bs[1] = pu4_pic_vert_bs[2] = pu4_pic_vert_bs[3] = 0x03030303;

        pu4_pic_horz_bs[0] = 0x04040404;
        pu4_pic_horz_bs[1] = pu4_pic_horz_bs[2] = pu4_pic_horz_bs[3] = 0x03030303;
    }
    else
    {
        /* left mb syntax info */
        mb_info_t *ps_left_mb_syntax_ele = &ps_proc->s_left_mb_syntax_ele;

        /* top mb syntax info */
        mb_info_t *ps_top_mb_syntax_ele = ps_proc->ps_top_row_mb_syntax_ele + i4_mb_x;

        /* top row motion vector info */
        enc_pu_t *ps_top_row_pu = ps_proc->ps_top_row_pu + i4_mb_x;

        /* csbp for curr mb */
        ps_proc->u4_csbp = ih264e_calculate_csbp(ps_proc);

        /* csbp for ngbrs */
        if (i4_mb_x == 0)
        {
            ps_left_mb_syntax_ele->u4_csbp = 0;
            ps_proc->s_left_mb_pu.b1_intra_flag = 0;
            ps_proc->s_left_mb_pu.b2_pred_mode = ps_proc->ps_pu->b2_pred_mode;
            ps_proc->s_left_mb_pu.s_me_info[0].s_mv = ps_proc->ps_pu->s_me_info[0].s_mv;
            ps_proc->s_left_mb_pu.s_me_info[1].s_mv = ps_proc->ps_pu->s_me_info[1].s_mv;
        }
        if (i4_mb_y == 0)
        {
            ps_top_mb_syntax_ele->u4_csbp = 0;
            ps_top_row_pu->b1_intra_flag = 0;
            ps_top_row_pu->b2_pred_mode = ps_proc->ps_pu->b2_pred_mode;
            ps_top_row_pu->s_me_info[0].s_mv = ps_proc->ps_pu->s_me_info[0].s_mv;
            ps_top_row_pu->s_me_info[1].s_mv = ps_proc->ps_pu->s_me_info[1].s_mv;
        }

        ih264e_fill_bs_1mv_1ref_non_mbaff(pu4_pic_horz_bs,
                                          pu4_pic_vert_bs,
                                          ps_left_mb_syntax_ele->u4_csbp,
                                          ps_top_mb_syntax_ele->u4_csbp,
                                          ps_proc->u4_csbp,
                                          &ps_proc->s_left_mb_pu,
                                          ps_top_row_pu,
                                          ps_proc->ps_pu);
    }

    return ;
}

/**
*******************************************************************************
*
* @brief This function performs deblocking of top horizontal edge
*
* @par Description:
*  This function performs deblocking of top horizontal edge
*
* @param[in] ps_codec
*  pointer to codec context
*
* @param[in] ps_proc
*  pointer to proc context
*
* @param[in] pu1_mb_qp
*  pointer to mb quantization param
*
* @param[in] pu1_cur_pic_luma
*  pointer to recon buffer luma
*
* @param[in] pu1_cur_pic_chroma
*  pointer to recon buffer chroma
*
* @param[in] pu4_pic_horz_bs
*  pointer to horizontal blocking strength
*
* @returns  none
*
* @remarks none
*
*******************************************************************************
*/
static void 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)
{
    /* strd */
    WORD32 i4_rec_strd = ps_proc->i4_rec_strd;

    /* deblk params */
    UWORD32 u4_alpha_luma, u4_beta_luma, u4_qp_luma, u4_idx_A_luma, u4_idx_B_luma, u4_qp_p, u4_qp_q;
    UWORD32 u4_alpha_chroma, u4_beta_chroma, u4_qp_chroma, u4_idx_A_chroma, u4_idx_B_chroma;

    /* collect qp of left & top mb */
    u4_qp_p = pu1_mb_qp[-ps_proc->i4_wd_mbs];
    u4_qp_q = pu1_mb_qp[0];

    /********/
    /* luma */
    /********/
    u4_qp_luma = (u4_qp_p + u4_qp_q + 1) >> 1;

    /* filter offset A and filter offset B have to be received from slice header */
    /* TODO : for now lets set these offsets as zero */


    u4_idx_A_luma = MIN(51, u4_qp_luma + 0);
    u4_idx_B_luma = MIN(51, u4_qp_luma + 0);

    /* alpha, beta computation */
    u4_alpha_luma = gu1_ih264_alpha_table[u4_idx_A_luma];
    u4_beta_luma = gu1_ih264_beta_table[u4_idx_B_luma];

    /**********/
    /* chroma */
    /**********/
    u4_qp_chroma = (gu1_qpc_fqpi[u4_qp_p] + gu1_qpc_fqpi[u4_qp_q] + 1) >> 1;

    /* filter offset A and filter offset B have to be received from slice header */
    /* TODO : for now lets set these offsets as zero */


    u4_idx_A_chroma = MIN(51, u4_qp_chroma + 0);
    u4_idx_B_chroma = MIN(51, u4_qp_chroma + 0);

    /* alpha, beta computation */
    u4_alpha_chroma = gu1_ih264_alpha_table[u4_idx_A_chroma];
    u4_beta_chroma = gu1_ih264_beta_table[u4_idx_B_chroma];

    /* deblk edge */
    /* top Horizontal edge - allowed to be deblocked ? */
    if (pu4_pic_horz_bs[0] == 0x04040404)
    {
        /* strong filter */
        ps_codec->pf_deblk_luma_horz_bs4(pu1_cur_pic_luma, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
        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);
    }
    else
    {
        /* normal filter */
        ps_codec->pf_deblk_luma_horz_bslt4(pu1_cur_pic_luma, i4_rec_strd, u4_alpha_luma,
                                               u4_beta_luma, pu4_pic_horz_bs[0],
                                               gu1_ih264_clip_table[u4_idx_A_luma]);

        ps_codec->pf_deblk_chroma_horz_bslt4(pu1_cur_pic_chroma, i4_rec_strd, u4_alpha_chroma,
                                             u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma, pu4_pic_horz_bs[0],
                                             gu1_ih264_clip_table[u4_idx_A_chroma], gu1_ih264_clip_table[u4_idx_A_chroma]);
    }
}

/**
*******************************************************************************
*
* @brief This function performs deblocking of left vertical edge
*
* @par Description:
*  This function performs deblocking of top horizontal edge
*
* @param[in] ps_codec
*  pointer to codec context
*
* @param[in] ps_proc
*  pointer to proc context
*
* @param[in] pu1_mb_qp
*  pointer to mb quantization param
*
* @param[in] pu1_cur_pic_luma
*  pointer to recon buffer luma
*
* @param[in] pu1_cur_pic_chroma
*  pointer to recon buffer chroma
*
* @param[in] pu4_pic_vert_bs
*  pointer to vertical blocking strength
*
* @returns  none
*
* @remarks none
*
*******************************************************************************
*/
static void 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)
{
    /* strd */
    WORD32 i4_rec_strd = ps_proc->i4_rec_strd;

    /* deblk params */
    UWORD32 u4_alpha_luma, u4_beta_luma, u4_qp_luma, u4_idx_A_luma, u4_idx_B_luma, u4_qp_p, u4_qp_q;
    UWORD32 u4_alpha_chroma, u4_beta_chroma, u4_qp_chroma, u4_idx_A_chroma, u4_idx_B_chroma;

    /* collect qp of left & curr mb */
    u4_qp_p = pu1_mb_qp[-1];
    u4_qp_q = pu1_mb_qp[0];

    /********/
    /* luma */
    /********/
    u4_qp_luma = (u4_qp_p + u4_qp_q + 1) >> 1;

    /* filter offset A and filter offset B have to be received from slice header */
    /* TODO : for now lets set these offsets as zero */


    u4_idx_A_luma = MIN(51, u4_qp_luma + 0);
    u4_idx_B_luma = MIN(51, u4_qp_luma + 0);

    /* alpha, beta computation */
    u4_alpha_luma = gu1_ih264_alpha_table[u4_idx_A_luma];
    u4_beta_luma = gu1_ih264_beta_table[u4_idx_B_luma];

    /**********/
    /* chroma */
    /**********/
    u4_qp_chroma = (gu1_qpc_fqpi[u4_qp_p] + gu1_qpc_fqpi[u4_qp_q] + 1) >> 1;

    /* filter offset A and filter offset B have to be received from slice header */
    /* TODO : for now lets set these offsets as zero */


    u4_idx_A_chroma = MIN(51, u4_qp_chroma + 0);
    u4_idx_B_chroma = MIN(51, u4_qp_chroma + 0);

    /* alpha, beta computation */
    u4_alpha_chroma = gu1_ih264_alpha_table[u4_idx_A_chroma];
    u4_beta_chroma = gu1_ih264_beta_table[u4_idx_B_chroma];

    /* deblk edge */
    if (pu4_pic_vert_bs[0] == 0x04040404)
    {
        /* strong filter */
        ps_codec->pf_deblk_luma_vert_bs4(pu1_cur_pic_luma, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
        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);
    }
    else
    {
        /* normal filter */
        ps_codec->pf_deblk_luma_vert_bslt4(pu1_cur_pic_luma, i4_rec_strd,
                                           u4_alpha_luma, u4_beta_luma,
                                           pu4_pic_vert_bs[0],
                                           gu1_ih264_clip_table[u4_idx_A_luma]);

        ps_codec->pf_deblk_chroma_vert_bslt4(pu1_cur_pic_chroma, i4_rec_strd, u4_alpha_chroma,
                                             u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma, pu4_pic_vert_bs[0],
                                             gu1_ih264_clip_table[u4_idx_A_chroma], gu1_ih264_clip_table[u4_idx_A_chroma]);
    }
}

/**
*******************************************************************************
*
* @brief This function performs deblocking on an mb
*
* @par Description:
*  This function performs deblocking on an mb
*
* @param[in] ps_proc
*  process context corresponding to the job
*
* @param[in] ps_deblk
*  pointer to deblock context
*
* @returns  none
*
* @remarks none
*
*******************************************************************************
*/
void ih264e_deblock_mb(process_ctxt_t *ps_proc, deblk_ctxt_t * ps_deblk)
{
    /* codec ctxt */
    codec_t *ps_codec = ps_proc->ps_codec;

    /* ngbr availability */
    UWORD8  u1_mb_a, u1_mb_b;

    /* mb indices */
    WORD32  i4_mb_x = ps_deblk->i4_mb_x, i4_mb_y = ps_deblk->i4_mb_y;

    /* pic qp ptr */
    UWORD8  *pu1_pic_qp = ps_deblk->s_bs_ctxt.pu1_pic_qp;

    /* vertical blocking strength */
    UWORD32 *pu4_pic_vert_bs = ps_deblk->s_bs_ctxt.pu4_pic_vert_bs;

    /* horizontal blocking strength */
    UWORD32 *pu4_pic_horz_bs = ps_deblk->s_bs_ctxt.pu4_pic_horz_bs;

    /* src buffers luma */
    UWORD8  *pu1_cur_pic_luma = ps_deblk->pu1_cur_pic_luma;

    /* src buffers chroma */
    UWORD8  *pu1_cur_pic_chroma = ps_deblk->pu1_cur_pic_chroma;

    /* strd */
    WORD32 i4_rec_strd = ps_proc->i4_rec_strd;

    /* deblk params */
    UWORD32 u4_alpha_luma, u4_beta_luma, u4_qp_luma, u4_idx_A_luma, u4_idx_B_luma;
    UWORD32 u4_alpha_chroma, u4_beta_chroma, u4_qp_chroma, u4_idx_A_chroma, u4_idx_B_chroma;

    /* temp var */
    UWORD32 push_ptr = (i4_mb_y * ps_proc->i4_wd_mbs) + i4_mb_x;

    /* derive neighbor availability */
    /* In slice mode the edges of mbs that lie on the slice boundary are not deblocked */
    /* deblocking filter idc '2' */
    if (ps_codec->s_cfg.e_slice_mode != IVE_SLICE_MODE_NONE)
    {
        /* slice index */
        UWORD8  *pu1_slice_idx = ps_deblk->pu1_slice_idx;

        pu1_slice_idx += (i4_mb_y * ps_proc->i4_wd_mbs);
        /* left macroblock availability */
        u1_mb_a = (i4_mb_x == 0 ||
                        (pu1_slice_idx[i4_mb_x - 1 ] != pu1_slice_idx[i4_mb_x]))? 0 : 1;
        /* top macroblock availability */
        u1_mb_b = (i4_mb_y == 0 ||
                        (pu1_slice_idx[i4_mb_x-ps_proc->i4_wd_mbs] != pu1_slice_idx[i4_mb_x]))? 0 : 1;
    }
    else
    {
        /* left macroblock availability */
        u1_mb_a = (i4_mb_x == 0)? 0 : 1;
        /* top macroblock availability */
        u1_mb_b = (i4_mb_y == 0)? 0 : 1;
    }

    pu1_pic_qp += push_ptr;
    pu4_pic_vert_bs += push_ptr * 4;
    pu4_pic_horz_bs += push_ptr * 4;

    /********/
    /* luma */
    /********/
    u4_qp_luma = pu1_pic_qp[0];

    /* filter offset A and filter offset B have to be received from slice header */
    /* TODO : for now lets set these offsets as zero */


    u4_idx_A_luma = MIN(51, u4_qp_luma + 0);
    u4_idx_B_luma = MIN(51, u4_qp_luma + 0);

    /* alpha, beta computation */
    u4_alpha_luma = gu1_ih264_alpha_table[u4_idx_A_luma];
    u4_beta_luma = gu1_ih264_beta_table[u4_idx_B_luma];

    /**********/
    /* chroma */
    /**********/
    u4_qp_chroma = gu1_qpc_fqpi[u4_qp_luma];

    /* filter offset A and filter offset B have to be received from slice header */
    /* TODO : for now lets set these offsets as zero */


    u4_idx_A_chroma = MIN(51, u4_qp_chroma + 0);
    u4_idx_B_chroma = MIN(51, u4_qp_chroma + 0);

    /* alpha, beta computation */
    u4_alpha_chroma = gu1_ih264_alpha_table[u4_idx_A_chroma];
    u4_beta_chroma = gu1_ih264_beta_table[u4_idx_B_chroma];

    /* Deblock vertical edges */
    /* left vertical edge 0 - allowed to be deblocked ? */
    if (u1_mb_a)
    {
        ih264e_filter_left_edge(ps_codec, ps_proc, pu1_pic_qp, pu1_cur_pic_luma, pu1_cur_pic_chroma, pu4_pic_vert_bs);
    }

    /* vertical edge 1 */
    if (pu4_pic_vert_bs[1] == 0x04040404)
    {
        /* strong filter */
        ps_codec->pf_deblk_luma_vert_bs4(pu1_cur_pic_luma + 4, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
    }
    else
    {
        /* normal filter */
        ps_codec->pf_deblk_luma_vert_bslt4(pu1_cur_pic_luma + 4, i4_rec_strd,
                                           u4_alpha_luma, u4_beta_luma,
                                           pu4_pic_vert_bs[1],
                                           gu1_ih264_clip_table[u4_idx_A_luma]);
    }

    /* vertical edge 2 */
    if (pu4_pic_vert_bs[2] == 0x04040404)
    {
        /* strong filter */
        ps_codec->pf_deblk_luma_vert_bs4(pu1_cur_pic_luma + 8, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
        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);
    }
    else
    {
        /* normal filter */
        ps_codec->pf_deblk_luma_vert_bslt4(pu1_cur_pic_luma + 8, i4_rec_strd, u4_alpha_luma,
                                           u4_beta_luma, pu4_pic_vert_bs[2],
                                           gu1_ih264_clip_table[u4_idx_A_luma]);

        ps_codec->pf_deblk_chroma_vert_bslt4(pu1_cur_pic_chroma + 8, i4_rec_strd, u4_alpha_chroma,
                                             u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma, pu4_pic_vert_bs[2],
                                             gu1_ih264_clip_table[u4_idx_A_chroma], gu1_ih264_clip_table[u4_idx_A_chroma]);
    }

    /* vertical edge 3 */
    if (pu4_pic_vert_bs[3] == 0x04040404)
    {
        /* strong filter */
        ps_codec->pf_deblk_luma_vert_bs4(pu1_cur_pic_luma + 12, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
    }
    else
    {
        /* normal filter */
        ps_codec->pf_deblk_luma_vert_bslt4(pu1_cur_pic_luma + 12, i4_rec_strd, u4_alpha_luma,
                                           u4_beta_luma, pu4_pic_vert_bs[3],
                                           gu1_ih264_clip_table[u4_idx_A_luma]);
    }

    /* Deblock Horizontal edges */
    /* Horizontal edge 0 */
    if (u1_mb_b)
    {
        ih264e_filter_top_edge(ps_codec, ps_proc, pu1_pic_qp, pu1_cur_pic_luma, pu1_cur_pic_chroma, pu4_pic_horz_bs);
    }

    /* horizontal edge 1 */
    if (pu4_pic_horz_bs[1] == 0x04040404)
    {
        /* strong filter */
        ps_codec->pf_deblk_luma_horz_bs4(pu1_cur_pic_luma + 4 * i4_rec_strd, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
    }
    else
    {
        /* normal filter */
        ps_codec->pf_deblk_luma_horz_bslt4(pu1_cur_pic_luma + 4 * i4_rec_strd, i4_rec_strd, u4_alpha_luma,
                                           u4_beta_luma, pu4_pic_horz_bs[1],
                                           gu1_ih264_clip_table[u4_idx_A_luma]);
    }

    /* horizontal edge 2 */
    if (pu4_pic_horz_bs[2] == 0x04040404)
    {
        /* strong filter */
        ps_codec->pf_deblk_luma_horz_bs4(pu1_cur_pic_luma + 8 * i4_rec_strd, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
        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);
    }
    else
    {
        /* normal filter */
        ps_codec->pf_deblk_luma_horz_bslt4(pu1_cur_pic_luma + 8 * i4_rec_strd, i4_rec_strd, u4_alpha_luma,
                                           u4_beta_luma, pu4_pic_horz_bs[2],
                                           gu1_ih264_clip_table[u4_idx_A_luma]);

        ps_codec->pf_deblk_chroma_horz_bslt4(pu1_cur_pic_chroma + 4 * i4_rec_strd, i4_rec_strd, u4_alpha_chroma,
                                             u4_beta_chroma, u4_alpha_chroma, u4_beta_chroma, pu4_pic_horz_bs[2],
                                             gu1_ih264_clip_table[u4_idx_A_chroma], gu1_ih264_clip_table[u4_idx_A_chroma]);
    }

    /* horizontal edge 3 */
    if (pu4_pic_horz_bs[3] == 0x04040404)
    {
        /* strong filter */
        ps_codec->pf_deblk_luma_horz_bs4(pu1_cur_pic_luma + 12 * i4_rec_strd, i4_rec_strd, u4_alpha_luma, u4_beta_luma);
    }
    else
    {
        /* normal filter */
        ps_codec->pf_deblk_luma_horz_bslt4(pu1_cur_pic_luma + 12 * i4_rec_strd, i4_rec_strd, u4_alpha_luma,
                                           u4_beta_luma, pu4_pic_horz_bs[3],
                                           gu1_ih264_clip_table[u4_idx_A_luma]);
    }

    return ;
}