/src/libavc/decoder/ih264d_quant_scaling.c
Line | Count | Source |
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 "ih264_defs.h" |
24 | | #include "ih264d_bitstrm.h" |
25 | | #include "ih264d_structs.h" |
26 | | #include "ih264d_parse_cavlc.h" |
27 | | #include "ih264d_defs.h" |
28 | | #include "ih264d_defs.h" |
29 | | #include "ih264d_defs.h" |
30 | | |
31 | | #include "ih264d_parse_slice.h" |
32 | | #include "ih264d_tables.h" |
33 | | #include "ih264d_utils.h" |
34 | | #include "ih264d_nal.h" |
35 | | #include "ih264d_deblocking.h" |
36 | | |
37 | | #include "ih264d_mem_request.h" |
38 | | #include "ih264d_debug.h" |
39 | | |
40 | | #include "ih264d_error_handler.h" |
41 | | #include "ih264d_mb_utils.h" |
42 | | #include "ih264d_sei.h" |
43 | | #include "ih264d_vui.h" |
44 | | #include "ih264d_tables.h" |
45 | | |
46 | | #define IDCT_BLOCK_WIDTH8X8 8 |
47 | | |
48 | | WORD32 ih264d_scaling_list(WORD16 *pi2_scaling_list, |
49 | | WORD32 i4_size_of_scalinglist, |
50 | | UWORD8 *pu1_use_default_scaling_matrix_flag, |
51 | | dec_bit_stream_t *ps_bitstrm) |
52 | 28.0k | { |
53 | 28.0k | WORD32 i4_j, i4_delta_scale, i4_lastScale = 8, i4_nextScale = 8; |
54 | 28.0k | UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; |
55 | 28.0k | UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst; |
56 | | |
57 | 28.0k | *pu1_use_default_scaling_matrix_flag = 0; |
58 | | |
59 | 851k | for(i4_j = 0; i4_j < i4_size_of_scalinglist; i4_j++) |
60 | 824k | { |
61 | 824k | if(i4_nextScale != 0) |
62 | 434k | { |
63 | 434k | i4_delta_scale = ih264d_sev(pu4_bitstrm_ofst, |
64 | 434k | pu4_bitstrm_buf); |
65 | | |
66 | 434k | if(i4_delta_scale < MIN_H264_DELTA_SCALE || |
67 | 434k | i4_delta_scale > MAX_H264_DELTA_SCALE) |
68 | 1.14k | { |
69 | 1.14k | return ERROR_INV_RANGE_QP_T; |
70 | 1.14k | } |
71 | 433k | i4_nextScale = ((i4_lastScale + i4_delta_scale + 256) & 0xff); |
72 | | |
73 | 433k | *pu1_use_default_scaling_matrix_flag = ((i4_j == 0) |
74 | 27.9k | && (i4_nextScale == 0)); |
75 | | |
76 | 433k | } |
77 | 823k | pi2_scaling_list[i4_j] = |
78 | 823k | (i4_nextScale == 0) ? (i4_lastScale) : (i4_nextScale); |
79 | 823k | i4_lastScale = pi2_scaling_list[i4_j]; |
80 | 823k | } |
81 | 26.9k | return OK; |
82 | 28.0k | } |
83 | | |
84 | | WORD32 ih264d_form_default_scaling_matrix(dec_struct_t *ps_dec) |
85 | 181k | { |
86 | | |
87 | | /*************************************************************************/ |
88 | | /* perform the inverse scanning for the frame and field scaling matrices */ |
89 | | /*************************************************************************/ |
90 | 181k | { |
91 | 181k | UWORD8 *pu1_inv_scan; |
92 | 181k | WORD32 i4_i, i4_j; |
93 | | |
94 | 181k | pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan; |
95 | | |
96 | | /* for all 4x4 matrices */ |
97 | 1.26M | for(i4_i = 0; i4_i < 6; i4_i++) |
98 | 1.08M | { |
99 | 18.4M | for(i4_j = 0; i4_j < 16; i4_j++) |
100 | 17.3M | { |
101 | 17.3M | ps_dec->s_high_profile.i2_scalinglist4x4[i4_i][pu1_inv_scan[i4_j]] = |
102 | 17.3M | 16; |
103 | | |
104 | 17.3M | } |
105 | 1.08M | } |
106 | | |
107 | | /* for all 8x8 matrices */ |
108 | 543k | for(i4_i = 0; i4_i < 2; i4_i++) |
109 | 362k | { |
110 | 23.5M | for(i4_j = 0; i4_j < 64; i4_j++) |
111 | 23.1M | { |
112 | 23.1M | ps_dec->s_high_profile.i2_scalinglist8x8[i4_i][gau1_ih264d_inv_scan_prog8x8_cabac[i4_j]] = |
113 | 23.1M | 16; |
114 | | |
115 | 23.1M | } |
116 | 362k | } |
117 | 181k | } |
118 | 181k | return OK; |
119 | 181k | } |
120 | | |
121 | | WORD32 ih264d_form_scaling_matrix_picture(dec_seq_params_t *ps_seq, |
122 | | dec_pic_params_t *ps_pic, |
123 | | dec_struct_t *ps_dec) |
124 | 14.3k | { |
125 | | /* default scaling matrices */ |
126 | 14.3k | WORD32 i4_i; |
127 | | |
128 | | /* check the SPS first */ |
129 | 14.3k | if(ps_seq->i4_seq_scaling_matrix_present_flag) |
130 | 11.3k | { |
131 | 101k | for(i4_i = 0; i4_i < 8; i4_i++) |
132 | 90.5k | { |
133 | 90.5k | if(i4_i < 6) |
134 | 67.8k | { |
135 | | /* fall-back rule A */ |
136 | 67.8k | if(!ps_seq->u1_seq_scaling_list_present_flag[i4_i]) |
137 | 40.7k | { |
138 | 40.7k | if((i4_i == 0) || (i4_i == 3)) |
139 | 14.4k | { |
140 | 14.4k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
141 | 14.4k | (i4_i == 0) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4); |
142 | 14.4k | } |
143 | 26.2k | else |
144 | 26.2k | { |
145 | 26.2k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
146 | 26.2k | ps_dec->s_high_profile.pi2_scale_mat[i4_i |
147 | 26.2k | - 1]; |
148 | 26.2k | } |
149 | 40.7k | } |
150 | 27.1k | else |
151 | 27.1k | { |
152 | 27.1k | if(ps_seq->u1_use_default_scaling_matrix_flag[i4_i]) |
153 | 328 | { |
154 | 328 | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
155 | 328 | (i4_i < 3) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4); |
156 | 328 | } |
157 | 26.8k | else |
158 | 26.8k | { |
159 | 26.8k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
160 | 26.8k | ps_seq->i2_scalinglist4x4[i4_i]; |
161 | 26.8k | } |
162 | 27.1k | } |
163 | | |
164 | 67.8k | } |
165 | 22.6k | else |
166 | 22.6k | { |
167 | | /* fall-back rule A */ |
168 | 22.6k | if((!ps_seq->u1_seq_scaling_list_present_flag[i4_i]) |
169 | 10.5k | || (ps_seq->u1_use_default_scaling_matrix_flag[i4_i])) |
170 | 13.0k | { |
171 | 13.0k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
172 | 13.0k | (i4_i == 6) ? ((WORD16*)gai2_ih264d_default_intra8x8) : ((WORD16*)gai2_ih264d_default_inter8x8); |
173 | 13.0k | } |
174 | 9.59k | else |
175 | 9.59k | { |
176 | 9.59k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
177 | 9.59k | ps_seq->i2_scalinglist8x8[i4_i - 6]; |
178 | 9.59k | } |
179 | 22.6k | } |
180 | 90.5k | } |
181 | 11.3k | } |
182 | | |
183 | | /* checking for the PPS */ |
184 | | |
185 | 14.3k | if(ps_pic->i4_pic_scaling_matrix_present_flag) |
186 | 6.33k | { |
187 | 57.0k | for(i4_i = 0; i4_i < 8; i4_i++) |
188 | 50.7k | { |
189 | 50.7k | if(i4_i < 6) |
190 | 38.0k | { |
191 | | /* fall back rule B */ |
192 | 38.0k | if(!ps_pic->u1_pic_scaling_list_present_flag[i4_i]) |
193 | 27.6k | { |
194 | 27.6k | if((i4_i == 0) || (i4_i == 3)) |
195 | 8.93k | { |
196 | 8.93k | if(!ps_seq->i4_seq_scaling_matrix_present_flag) |
197 | 3.60k | { |
198 | 3.60k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
199 | 3.60k | (i4_i == 0) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4); |
200 | 3.60k | } |
201 | 8.93k | } |
202 | 18.7k | else |
203 | 18.7k | { |
204 | 18.7k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
205 | 18.7k | ps_dec->s_high_profile.pi2_scale_mat[i4_i |
206 | 18.7k | - 1]; |
207 | 18.7k | } |
208 | 27.6k | } |
209 | 10.3k | else |
210 | 10.3k | { |
211 | 10.3k | if(ps_pic->u1_pic_use_default_scaling_matrix_flag[i4_i]) |
212 | 507 | { |
213 | 507 | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
214 | 507 | (i4_i < 3) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4); |
215 | 507 | } |
216 | 9.86k | else |
217 | 9.86k | { |
218 | 9.86k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
219 | 9.86k | ps_pic->i2_pic_scalinglist4x4[i4_i]; |
220 | 9.86k | } |
221 | 10.3k | } |
222 | 38.0k | } |
223 | 12.6k | else |
224 | 12.6k | { |
225 | 12.6k | if(!ps_pic->u1_pic_scaling_list_present_flag[i4_i]) |
226 | 9.01k | { |
227 | 9.01k | if(!ps_seq->i4_seq_scaling_matrix_present_flag) |
228 | 3.78k | { |
229 | 3.78k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
230 | 3.78k | (i4_i == 6) ? ((WORD16*)gai2_ih264d_default_intra8x8) : ((WORD16*)gai2_ih264d_default_inter8x8); |
231 | 3.78k | } |
232 | 9.01k | } |
233 | 3.66k | else |
234 | 3.66k | { |
235 | 3.66k | if(ps_pic->u1_pic_use_default_scaling_matrix_flag[i4_i]) |
236 | 443 | { |
237 | 443 | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
238 | 443 | (i4_i == 6) ? (WORD16 *)(gai2_ih264d_default_intra8x8) : (WORD16 *)(gai2_ih264d_default_inter8x8); |
239 | 443 | } |
240 | 3.22k | else |
241 | 3.22k | { |
242 | 3.22k | ps_dec->s_high_profile.pi2_scale_mat[i4_i] = |
243 | 3.22k | ps_pic->i2_pic_scalinglist8x8[i4_i - 6]; |
244 | 3.22k | } |
245 | 3.66k | } |
246 | 12.6k | } |
247 | 50.7k | } |
248 | 6.33k | } |
249 | | |
250 | | /*************************************************************************/ |
251 | | /* perform the inverse scanning for the frame and field scaling matrices */ |
252 | | /*************************************************************************/ |
253 | 14.3k | { |
254 | 14.3k | UWORD8 *pu1_inv_scan_4x4; |
255 | 14.3k | WORD32 i4_i, i4_j; |
256 | | |
257 | 14.3k | pu1_inv_scan_4x4 = (UWORD8 *)gau1_ih264d_inv_scan; |
258 | | |
259 | | /* for all 4x4 matrices */ |
260 | 100k | for(i4_i = 0; i4_i < 6; i4_i++) |
261 | 86.3k | { |
262 | 86.3k | if(ps_dec->s_high_profile.pi2_scale_mat[i4_i] == NULL) |
263 | 0 | return ERROR_CORRUPTED_SLICE; |
264 | | |
265 | 1.46M | for(i4_j = 0; i4_j < 16; i4_j++) |
266 | 1.38M | { |
267 | 1.38M | ps_dec->s_high_profile.i2_scalinglist4x4[i4_i][pu1_inv_scan_4x4[i4_j]] = |
268 | 1.38M | ps_dec->s_high_profile.pi2_scale_mat[i4_i][i4_j]; |
269 | | |
270 | 1.38M | } |
271 | 86.3k | } |
272 | | |
273 | | /* for all 8x8 matrices */ |
274 | 43.1k | for(i4_i = 0; i4_i < 2; i4_i++) |
275 | 28.7k | { |
276 | 28.7k | if(ps_dec->s_high_profile.pi2_scale_mat[i4_i + 6] == NULL) |
277 | 0 | return ERROR_CORRUPTED_SLICE; |
278 | | |
279 | 1.87M | for(i4_j = 0; i4_j < 64; i4_j++) |
280 | 1.84M | { |
281 | 1.84M | ps_dec->s_high_profile.i2_scalinglist8x8[i4_i][gau1_ih264d_inv_scan_prog8x8_cabac[i4_j]] = |
282 | 1.84M | ps_dec->s_high_profile.pi2_scale_mat[i4_i + 6][i4_j]; |
283 | | |
284 | 1.84M | } |
285 | 28.7k | } |
286 | 14.3k | } |
287 | 14.3k | return OK; |
288 | 14.3k | } |
289 | | |