Home | History | Annotate | Download | only in decoder
      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 #include "ih264_typedefs.h"
     21 #include "ih264_macros.h"
     22 #include "ih264_platform_macros.h"
     23 #include "ih264d_bitstrm.h"
     24 #include "ih264d_structs.h"
     25 #include "ih264d_parse_cavlc.h"
     26 #include "ih264d_defs.h"
     27 #include "ih264d_defs.h"
     28 #include "ih264d_defs.h"
     29 
     30 #include "ih264d_parse_slice.h"
     31 #include "ih264d_tables.h"
     32 #include "ih264d_utils.h"
     33 #include "ih264d_nal.h"
     34 #include "ih264d_deblocking.h"
     35 
     36 #include "ih264d_mem_request.h"
     37 #include "ih264d_debug.h"
     38 
     39 #include "ih264d_error_handler.h"
     40 #include "ih264d_mb_utils.h"
     41 #include "ih264d_sei.h"
     42 #include "ih264d_vui.h"
     43 #include "ih264d_tables.h"
     44 
     45 #define IDCT_BLOCK_WIDTH8X8  8
     46 
     47 void ih264d_scaling_list(WORD16 *pi2_scaling_list,
     48                          WORD32 i4_size_of_scalinglist,
     49                          UWORD8 *pu1_use_default_scaling_matrix_flag,
     50                          dec_bit_stream_t *ps_bitstrm)
     51 {
     52     WORD32 i4_j, i4_delta_scale, i4_lastScale = 8, i4_nextScale = 8;
     53     UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
     54     UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
     55 
     56     *pu1_use_default_scaling_matrix_flag = 0;
     57 
     58     for(i4_j = 0; i4_j < i4_size_of_scalinglist; i4_j++)
     59     {
     60         if(i4_nextScale != 0)
     61         {
     62             i4_delta_scale = ih264d_sev(pu4_bitstrm_ofst,
     63                                         pu4_bitstrm_buf);
     64 
     65             i4_nextScale = ((i4_lastScale + i4_delta_scale + 256) & 0xff);
     66 
     67             *pu1_use_default_scaling_matrix_flag = ((i4_j == 0)
     68                             && (i4_nextScale == 0));
     69 
     70         }
     71         pi2_scaling_list[i4_j] =
     72                         (i4_nextScale == 0) ? (i4_lastScale) : (i4_nextScale);
     73         i4_lastScale = pi2_scaling_list[i4_j];
     74     }
     75 }
     76 
     77 void ih264d_form_default_scaling_matrix(dec_struct_t *ps_dec)
     78 {
     79 
     80     /*************************************************************************/
     81     /* perform the inverse scanning for the frame and field scaling matrices */
     82     /*************************************************************************/
     83     {
     84         UWORD8 *pu1_inv_scan;
     85         WORD32 i4_i, i4_j;
     86 
     87         pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
     88 
     89         /* for all 4x4 matrices */
     90         for(i4_i = 0; i4_i < 6; i4_i++)
     91         {
     92             for(i4_j = 0; i4_j < 16; i4_j++)
     93             {
     94                 ps_dec->s_high_profile.i2_scalinglist4x4[i4_i][pu1_inv_scan[i4_j]] =
     95                                 16;
     96 
     97             }
     98         }
     99 
    100         /* for all 8x8 matrices */
    101         for(i4_i = 0; i4_i < 2; i4_i++)
    102         {
    103             for(i4_j = 0; i4_j < 64; i4_j++)
    104             {
    105                 ps_dec->s_high_profile.i2_scalinglist8x8[i4_i][gau1_ih264d_inv_scan_prog8x8_cabac[i4_j]] =
    106                                 16;
    107 
    108             }
    109         }
    110     }
    111 }
    112 
    113 void ih264d_form_scaling_matrix_picture(dec_seq_params_t *ps_seq,
    114                                         dec_pic_params_t *ps_pic,
    115                                         dec_struct_t *ps_dec)
    116 {
    117     /* default scaling matrices */
    118     WORD32 i4_i;
    119 
    120     /* check the SPS first */
    121     if(ps_seq->i4_seq_scaling_matrix_present_flag)
    122     {
    123         for(i4_i = 0; i4_i < 8; i4_i++)
    124         {
    125             if(i4_i < 6)
    126             {
    127                 /* fall-back rule A */
    128                 if(!ps_seq->u1_seq_scaling_list_present_flag[i4_i])
    129                 {
    130                     if((i4_i == 0) || (i4_i == 3))
    131                     {
    132                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    133                                         (i4_i == 0) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
    134                     }
    135                     else
    136                     {
    137                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    138                                         ps_dec->s_high_profile.pi2_scale_mat[i4_i
    139                                                         - 1];
    140                     }
    141                 }
    142                 else
    143                 {
    144                     if(ps_seq->u1_use_default_scaling_matrix_flag[i4_i])
    145                     {
    146                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    147                                         (i4_i < 3) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
    148                     }
    149                     else
    150                     {
    151                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    152                                         ps_seq->i2_scalinglist4x4[i4_i];
    153                     }
    154                 }
    155 
    156             }
    157             else
    158             {
    159                 /* fall-back rule A */
    160                 if((!ps_seq->u1_seq_scaling_list_present_flag[i4_i])
    161                                 || (ps_seq->u1_use_default_scaling_matrix_flag[i4_i]))
    162                 {
    163                     ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    164                                     (i4_i == 6) ? ((WORD16*)gai2_ih264d_default_intra8x8) : ((WORD16*)gai2_ih264d_default_inter8x8);
    165                 }
    166                 else
    167                 {
    168                     ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    169                                     ps_seq->i2_scalinglist8x8[i4_i - 6];
    170                 }
    171             }
    172         }
    173     }
    174 
    175     /* checking for the PPS */
    176 
    177     if(ps_pic->i4_pic_scaling_matrix_present_flag)
    178     {
    179         for(i4_i = 0; i4_i < 8; i4_i++)
    180         {
    181             if(i4_i < 6)
    182             {
    183                 /* fall back rule B */
    184                 if(!ps_pic->u1_pic_scaling_list_present_flag[i4_i])
    185                 {
    186                     if((i4_i == 0) || (i4_i == 3))
    187                     {
    188                         if(!ps_seq->i4_seq_scaling_matrix_present_flag)
    189                         {
    190                             ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    191                                             (i4_i == 0) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
    192                         }
    193                     }
    194                     else
    195                     {
    196                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    197                                         ps_dec->s_high_profile.pi2_scale_mat[i4_i
    198                                                         - 1];
    199                     }
    200                 }
    201                 else
    202                 {
    203                     if(ps_pic->u1_pic_use_default_scaling_matrix_flag[i4_i])
    204                     {
    205                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    206                                         (i4_i < 3) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
    207                     }
    208                     else
    209                     {
    210                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    211                                         ps_pic->i2_pic_scalinglist4x4[i4_i];
    212                     }
    213                 }
    214             }
    215             else
    216             {
    217                 if(!ps_pic->u1_pic_scaling_list_present_flag[i4_i])
    218                 {
    219                     if(!ps_seq->u1_seq_scaling_list_present_flag[i4_i])
    220                     {
    221                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    222                                         (i4_i == 6) ? ((WORD16*)gai2_ih264d_default_intra8x8) : ((WORD16*)gai2_ih264d_default_inter8x8);
    223                     }
    224                 }
    225                 else
    226                 {
    227                     if(ps_pic->u1_pic_use_default_scaling_matrix_flag[i4_i])
    228                     {
    229                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    230                                         (i4_i == 6) ? (WORD16 *)(gai2_ih264d_default_intra8x8) : (WORD16 *)(gai2_ih264d_default_inter8x8);
    231                     }
    232                     else
    233                     {
    234                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
    235                                         ps_pic->i2_pic_scalinglist8x8[i4_i - 6];
    236                     }
    237                 }
    238             }
    239         }
    240     }
    241 
    242     /*************************************************************************/
    243     /* perform the inverse scanning for the frame and field scaling matrices */
    244     /*************************************************************************/
    245     {
    246         UWORD8 *pu1_inv_scan_4x4;
    247         WORD32 i4_i, i4_j;
    248 
    249         pu1_inv_scan_4x4 = (UWORD8 *)gau1_ih264d_inv_scan;
    250 
    251         /* for all 4x4 matrices */
    252         for(i4_i = 0; i4_i < 6; i4_i++)
    253         {
    254             for(i4_j = 0; i4_j < 16; i4_j++)
    255             {
    256                 ps_dec->s_high_profile.i2_scalinglist4x4[i4_i][pu1_inv_scan_4x4[i4_j]] =
    257                                 ps_dec->s_high_profile.pi2_scale_mat[i4_i][i4_j];
    258 
    259             }
    260         }
    261 
    262         /* for all 8x8 matrices */
    263         for(i4_i = 0; i4_i < 2; i4_i++)
    264         {
    265             for(i4_j = 0; i4_j < 64; i4_j++)
    266             {
    267                 ps_dec->s_high_profile.i2_scalinglist8x8[i4_i][gau1_ih264d_inv_scan_prog8x8_cabac[i4_j]] =
    268                                 ps_dec->s_high_profile.pi2_scale_mat[i4_i + 6][i4_j];
    269 
    270             }
    271         }
    272     }
    273 }
    274 
    275