• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
ih264d_scaling_list(WORD16 * pi2_scaling_list,WORD32 i4_size_of_scalinglist,UWORD8 * pu1_use_default_scaling_matrix_flag,dec_bit_stream_t * ps_bitstrm)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 
ih264d_form_default_scaling_matrix(dec_struct_t * ps_dec)77 WORD32 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     return OK;
112 }
113 
ih264d_form_scaling_matrix_picture(dec_seq_params_t * ps_seq,dec_pic_params_t * ps_pic,dec_struct_t * ps_dec)114 WORD32 ih264d_form_scaling_matrix_picture(dec_seq_params_t *ps_seq,
115                                           dec_pic_params_t *ps_pic,
116                                           dec_struct_t *ps_dec)
117 {
118     /* default scaling matrices */
119     WORD32 i4_i;
120 
121     /* check the SPS first */
122     if(ps_seq->i4_seq_scaling_matrix_present_flag)
123     {
124         for(i4_i = 0; i4_i < 8; i4_i++)
125         {
126             if(i4_i < 6)
127             {
128                 /* fall-back rule A */
129                 if(!ps_seq->u1_seq_scaling_list_present_flag[i4_i])
130                 {
131                     if((i4_i == 0) || (i4_i == 3))
132                     {
133                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
134                                         (i4_i == 0) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
135                     }
136                     else
137                     {
138                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
139                                         ps_dec->s_high_profile.pi2_scale_mat[i4_i
140                                                         - 1];
141                     }
142                 }
143                 else
144                 {
145                     if(ps_seq->u1_use_default_scaling_matrix_flag[i4_i])
146                     {
147                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
148                                         (i4_i < 3) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
149                     }
150                     else
151                     {
152                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
153                                         ps_seq->i2_scalinglist4x4[i4_i];
154                     }
155                 }
156 
157             }
158             else
159             {
160                 /* fall-back rule A */
161                 if((!ps_seq->u1_seq_scaling_list_present_flag[i4_i])
162                                 || (ps_seq->u1_use_default_scaling_matrix_flag[i4_i]))
163                 {
164                     ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
165                                     (i4_i == 6) ? ((WORD16*)gai2_ih264d_default_intra8x8) : ((WORD16*)gai2_ih264d_default_inter8x8);
166                 }
167                 else
168                 {
169                     ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
170                                     ps_seq->i2_scalinglist8x8[i4_i - 6];
171                 }
172             }
173         }
174     }
175 
176     /* checking for the PPS */
177 
178     if(ps_pic->i4_pic_scaling_matrix_present_flag)
179     {
180         for(i4_i = 0; i4_i < 8; i4_i++)
181         {
182             if(i4_i < 6)
183             {
184                 /* fall back rule B */
185                 if(!ps_pic->u1_pic_scaling_list_present_flag[i4_i])
186                 {
187                     if((i4_i == 0) || (i4_i == 3))
188                     {
189                         if(!ps_seq->i4_seq_scaling_matrix_present_flag)
190                         {
191                             ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
192                                             (i4_i == 0) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
193                         }
194                     }
195                     else
196                     {
197                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
198                                         ps_dec->s_high_profile.pi2_scale_mat[i4_i
199                                                         - 1];
200                     }
201                 }
202                 else
203                 {
204                     if(ps_pic->u1_pic_use_default_scaling_matrix_flag[i4_i])
205                     {
206                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
207                                         (i4_i < 3) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
208                     }
209                     else
210                     {
211                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
212                                         ps_pic->i2_pic_scalinglist4x4[i4_i];
213                     }
214                 }
215             }
216             else
217             {
218                 if(!ps_pic->u1_pic_scaling_list_present_flag[i4_i])
219                 {
220                     if(!ps_seq->i4_seq_scaling_matrix_present_flag)
221                     {
222                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
223                                         (i4_i == 6) ? ((WORD16*)gai2_ih264d_default_intra8x8) : ((WORD16*)gai2_ih264d_default_inter8x8);
224                     }
225                 }
226                 else
227                 {
228                     if(ps_pic->u1_pic_use_default_scaling_matrix_flag[i4_i])
229                     {
230                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
231                                         (i4_i == 6) ? (WORD16 *)(gai2_ih264d_default_intra8x8) : (WORD16 *)(gai2_ih264d_default_inter8x8);
232                     }
233                     else
234                     {
235                         ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
236                                         ps_pic->i2_pic_scalinglist8x8[i4_i - 6];
237                     }
238                 }
239             }
240         }
241     }
242 
243     /*************************************************************************/
244     /* perform the inverse scanning for the frame and field scaling matrices */
245     /*************************************************************************/
246     {
247         UWORD8 *pu1_inv_scan_4x4;
248         WORD32 i4_i, i4_j;
249 
250         pu1_inv_scan_4x4 = (UWORD8 *)gau1_ih264d_inv_scan;
251 
252         /* for all 4x4 matrices */
253         for(i4_i = 0; i4_i < 6; i4_i++)
254         {
255             if(ps_dec->s_high_profile.pi2_scale_mat[i4_i] == NULL)
256                 return ERROR_CORRUPTED_SLICE;
257 
258             for(i4_j = 0; i4_j < 16; i4_j++)
259             {
260                 ps_dec->s_high_profile.i2_scalinglist4x4[i4_i][pu1_inv_scan_4x4[i4_j]] =
261                                 ps_dec->s_high_profile.pi2_scale_mat[i4_i][i4_j];
262 
263             }
264         }
265 
266         /* for all 8x8 matrices */
267         for(i4_i = 0; i4_i < 2; i4_i++)
268         {
269             if(ps_dec->s_high_profile.pi2_scale_mat[i4_i + 6] == NULL)
270                 return ERROR_CORRUPTED_SLICE;
271 
272             for(i4_j = 0; i4_j < 64; i4_j++)
273             {
274                 ps_dec->s_high_profile.i2_scalinglist8x8[i4_i][gau1_ih264d_inv_scan_prog8x8_cabac[i4_j]] =
275                                 ps_dec->s_high_profile.pi2_scale_mat[i4_i + 6][i4_j];
276 
277             }
278         }
279     }
280     return OK;
281 }
282 
283