/src/libmpeg2/decoder/impeg2d_pnb_pic.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 <stdio.h> |
21 | | #include <string.h> |
22 | | |
23 | | #include "iv_datatypedef.h" |
24 | | #include "iv.h" |
25 | | |
26 | | #include "impeg2_buf_mgr.h" |
27 | | #include "impeg2_disp_mgr.h" |
28 | | #include "impeg2_defs.h" |
29 | | #include "impeg2_platform_macros.h" |
30 | | #include "impeg2_inter_pred.h" |
31 | | #include "impeg2_idct.h" |
32 | | #include "impeg2_globals.h" |
33 | | #include "impeg2_format_conv.h" |
34 | | #include "impeg2_macros.h" |
35 | | |
36 | | #include "ivd.h" |
37 | | #include "impeg2d.h" |
38 | | #include "impeg2d_bitstream.h" |
39 | | #include "impeg2d_structs.h" |
40 | | #include "impeg2d_vld_tables.h" |
41 | | #include "impeg2d_vld.h" |
42 | | #include "impeg2d_pic_proc.h" |
43 | | #include "impeg2d_debug.h" |
44 | | #include "impeg2d_mc.h" |
45 | | |
46 | | #define BLK_SIZE 8 |
47 | | #define LUMA_BLK_SIZE (2 * (BLK_SIZE)) |
48 | | #define CHROMA_BLK_SIZE (BLK_SIZE) |
49 | | |
50 | | |
51 | | /******************************************************************************* |
52 | | * |
53 | | * Function Name : impeg2d_dec_p_mb_params |
54 | | * |
55 | | * Description : Decodes the parameters for P |
56 | | * |
57 | | * Arguments : |
58 | | * dec : Decoder context |
59 | | * |
60 | | * Values Returned : None |
61 | | *******************************************************************************/ |
62 | | WORD32 impeg2d_dec_p_mb_params(dec_state_t *ps_dec) |
63 | 3.46M | { |
64 | 3.46M | stream_t *ps_stream = &ps_dec->s_bit_stream; |
65 | 3.46M | UWORD16 u2_mb_addr_incr; |
66 | 3.46M | UWORD16 u2_total_len; |
67 | 3.46M | UWORD16 u2_len; |
68 | 3.46M | UWORD16 u2_mb_type; |
69 | 3.46M | UWORD32 u4_next_word; |
70 | 3.46M | const dec_mb_params_t *ps_dec_mb_params; |
71 | 3.46M | if(impeg2d_bit_stream_nxt(ps_stream,1) == 1) |
72 | 2.81M | { |
73 | 2.81M | impeg2d_bit_stream_flush(ps_stream,1); |
74 | | |
75 | 2.81M | } |
76 | 648k | else |
77 | 648k | { |
78 | 648k | u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream); |
79 | | |
80 | 648k | if(!u2_mb_addr_incr) |
81 | 250 | { |
82 | 250 | return IV_FAIL; |
83 | 250 | } |
84 | | |
85 | 648k | if(0 == ps_dec->u2_first_mb) |
86 | 640k | { |
87 | | /****************************************************************/ |
88 | | /* If the 2nd member of a field picture pair is a P picture and */ |
89 | | /* the first one was an I picture, there cannot be any skipped */ |
90 | | /* MBs in the second field picture */ |
91 | | /****************************************************************/ |
92 | | /* |
93 | | if((dec->picture_structure != FRAME_PICTURE) && |
94 | | (dec->f->FieldFuncCall != 0) && |
95 | | (dec->las->u1_last_coded_vop_type == I)) |
96 | | { |
97 | | core0_err_handler((void *)(VOLParams), |
98 | | ITTMPEG2_ERR_INVALID_MB_SKIP); |
99 | | } |
100 | | */ |
101 | | /****************************************************************/ |
102 | | /* In MPEG-2, the last MB of the row cannot be skipped and the */ |
103 | | /* MBAddrIncr cannot be such that it will take the current MB */ |
104 | | /* beyond the current row */ |
105 | | /* In MPEG-1, the slice could start and end anywhere and is not */ |
106 | | /* restricted to a row like in MPEG-2. Hence this check should */ |
107 | | /* not be done for MPEG-1 streams. */ |
108 | | /****************************************************************/ |
109 | 640k | if(ps_dec->u2_is_mpeg2 && ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb) ) |
110 | 1.65k | { |
111 | 1.65k | u2_mb_addr_incr = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x; |
112 | 1.65k | } |
113 | | |
114 | 640k | if ((u2_mb_addr_incr - 1) > ps_dec->u2_num_mbs_left) |
115 | 300 | { |
116 | | /* If the number of skip MBs are more than the number of MBs |
117 | | * left, indicate error. |
118 | | */ |
119 | 300 | return IV_FAIL; |
120 | 300 | } |
121 | | |
122 | 639k | impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1)); |
123 | 639k | } |
124 | 8.51k | else |
125 | 8.51k | { |
126 | | |
127 | | /****************************************************************/ |
128 | | /* Section 6.3.17 */ |
129 | | /* The first MB of a slice cannot be skipped */ |
130 | | /* But the mb_addr_incr can be > 1, because at the beginning of */ |
131 | | /* a slice, it indicates the offset from the last MB in the */ |
132 | | /* previous row. Hence for the first slice in a row, the */ |
133 | | /* mb_addr_incr needs to be 1. */ |
134 | | /****************************************************************/ |
135 | | /* MB_x is set to zero whenever MB_y changes. */ |
136 | 8.51k | ps_dec->u2_mb_x = u2_mb_addr_incr - 1; |
137 | | /* For error resilience */ |
138 | 8.51k | ps_dec->u2_mb_x = MIN(ps_dec->u2_mb_x, (ps_dec->u2_num_horiz_mb - 1)); |
139 | 8.51k | ps_dec->u2_num_mbs_left = ((ps_dec->u2_num_vert_mb - ps_dec->u2_mb_y) |
140 | 8.51k | * ps_dec->u2_num_horiz_mb) - ps_dec->u2_mb_x; |
141 | | |
142 | | /****************************************************************/ |
143 | | /* mb_addr_incr is forced to 1 because in this decoder it is used */ |
144 | | /* more as an indicator of the number of MBs skipped than the */ |
145 | | /* as defined by the standard (Section 6.3.17) */ |
146 | | /****************************************************************/ |
147 | 8.51k | u2_mb_addr_incr = 1; |
148 | 8.51k | ps_dec->u2_first_mb = 0; |
149 | | |
150 | 8.51k | } |
151 | | |
152 | 648k | } |
153 | 3.46M | u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16); |
154 | | /*-----------------------------------------------------------------------*/ |
155 | | /* MB type */ |
156 | | /*-----------------------------------------------------------------------*/ |
157 | 3.46M | { |
158 | 3.46M | u2_mb_type = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)]; |
159 | 3.46M | u2_len = BITS(u2_mb_type,15,8); |
160 | 3.46M | u2_total_len = u2_len; |
161 | 3.46M | u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len); |
162 | 3.46M | } |
163 | | /*-----------------------------------------------------------------------*/ |
164 | | /* motion type */ |
165 | | /*-----------------------------------------------------------------------*/ |
166 | 3.46M | { |
167 | 3.46M | if((u2_mb_type & MB_FORW_OR_BACK) && ps_dec->u2_read_motion_type) |
168 | 15.4k | { |
169 | 15.4k | WORD32 i4_motion_type; |
170 | 15.4k | ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14); |
171 | 15.4k | u2_total_len += MB_MOTION_TYPE_LEN; |
172 | 15.4k | u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN); |
173 | 15.4k | i4_motion_type = ps_dec->u2_motion_type; |
174 | | |
175 | 15.4k | if((i4_motion_type == 0) || |
176 | 15.0k | (i4_motion_type == 4) || |
177 | 15.0k | (i4_motion_type > 7)) |
178 | 349 | { |
179 | | //TODO : VANG Check for validity |
180 | 349 | i4_motion_type = 1; |
181 | 349 | } |
182 | | |
183 | 15.4k | } |
184 | 3.46M | } |
185 | | /*-----------------------------------------------------------------------*/ |
186 | | /* dct type */ |
187 | | /*-----------------------------------------------------------------------*/ |
188 | 3.46M | { |
189 | 3.46M | if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type) |
190 | 2.76k | { |
191 | 2.76k | ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15); |
192 | 2.76k | u2_total_len += MB_DCT_TYPE_LEN; |
193 | 2.76k | u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN); |
194 | 2.76k | } |
195 | 3.46M | } |
196 | | /*-----------------------------------------------------------------------*/ |
197 | | /* Quant scale code */ |
198 | | /*-----------------------------------------------------------------------*/ |
199 | 3.46M | if(u2_mb_type & MB_QUANT) |
200 | 32.4k | { |
201 | 32.4k | UWORD16 u2_quant_scale_code; |
202 | 32.4k | u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11); |
203 | | |
204 | 32.4k | ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ? |
205 | 31.8k | gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1); |
206 | 32.4k | u2_total_len += MB_QUANT_SCALE_CODE_LEN; |
207 | 32.4k | } |
208 | 3.46M | impeg2d_bit_stream_flush(ps_stream,u2_total_len); |
209 | | /*-----------------------------------------------------------------------*/ |
210 | | /* Set the function pointers */ |
211 | | /*-----------------------------------------------------------------------*/ |
212 | 3.46M | ps_dec->u2_coded_mb = (UWORD16)(u2_mb_type & MB_CODED); |
213 | | |
214 | 3.46M | if(u2_mb_type & MB_FORW_OR_BACK) |
215 | 3.03M | { |
216 | | |
217 | 3.03M | UWORD16 refPic = !(u2_mb_type & MB_MV_FORW); |
218 | 3.03M | UWORD16 index = (ps_dec->u2_motion_type); |
219 | 3.03M | ps_dec->u2_prev_intra_mb = 0; |
220 | 3.03M | ps_dec->e_mb_pred = (e_pred_direction_t)refPic; |
221 | 3.03M | ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index]; |
222 | 3.03M | ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type; |
223 | 3.03M | if(NULL == ps_dec_mb_params->pf_func_mb_params) |
224 | 0 | return -1; |
225 | 3.03M | ps_dec_mb_params->pf_func_mb_params(ps_dec); |
226 | | |
227 | 3.03M | } |
228 | 426k | else if(u2_mb_type & MB_TYPE_INTRA) |
229 | 3.11k | { |
230 | 3.11k | ps_dec->u2_prev_intra_mb = 1; |
231 | 3.11k | impeg2d_dec_intra_mb(ps_dec); |
232 | | |
233 | 3.11k | } |
234 | 423k | else |
235 | 423k | { |
236 | 423k | ps_dec->u2_prev_intra_mb = 0; |
237 | 423k | ps_dec->e_mb_pred = FORW; |
238 | 423k | ps_dec->u2_motion_type = 0; |
239 | 423k | impeg2d_dec_0mv_coded_mb(ps_dec); |
240 | 423k | } |
241 | | |
242 | | /*-----------------------------------------------------------------------*/ |
243 | | /* decode cbp */ |
244 | | /*-----------------------------------------------------------------------*/ |
245 | 3.46M | if((u2_mb_type & MB_TYPE_INTRA)) |
246 | 3.11k | { |
247 | 3.11k | ps_dec->u2_cbp = 0x3f; |
248 | 3.11k | ps_dec->u2_prev_intra_mb = 1; |
249 | 3.11k | } |
250 | 3.45M | else |
251 | 3.45M | { |
252 | 3.45M | ps_dec->u2_prev_intra_mb = 0; |
253 | 3.45M | ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision; |
254 | 3.45M | ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision; |
255 | 3.45M | ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision; |
256 | 3.45M | if((ps_dec->u2_coded_mb)) |
257 | 3.08M | { |
258 | 3.08M | UWORD16 cbpValue; |
259 | 3.08M | cbpValue = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)]; |
260 | 3.08M | ps_dec->u2_cbp = cbpValue & 0xFF; |
261 | 3.08M | impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF); |
262 | 3.08M | } |
263 | 372k | else |
264 | 372k | { |
265 | 372k | ps_dec->u2_cbp = 0; |
266 | 372k | } |
267 | 3.45M | } |
268 | 3.46M | return 0; |
269 | 3.46M | } |
270 | | |
271 | | |
272 | | /******************************************************************************* |
273 | | * |
274 | | * Function Name : impeg2d_dec_pnb_mb_params |
275 | | * |
276 | | * Description : Decodes the parameters for P and B pictures |
277 | | * |
278 | | * Arguments : |
279 | | * dec : Decoder context |
280 | | * |
281 | | * Values Returned : None |
282 | | *******************************************************************************/ |
283 | | WORD32 impeg2d_dec_pnb_mb_params(dec_state_t *ps_dec) |
284 | 301k | { |
285 | 301k | stream_t *ps_stream = &ps_dec->s_bit_stream; |
286 | 301k | UWORD16 u2_mb_addr_incr; |
287 | 301k | UWORD16 u2_total_len; |
288 | 301k | UWORD16 u2_len; |
289 | 301k | UWORD16 u2_mb_type; |
290 | 301k | UWORD32 u4_next_word; |
291 | 301k | const dec_mb_params_t *ps_dec_mb_params; |
292 | 301k | if(impeg2d_bit_stream_nxt(ps_stream,1) == 1) |
293 | 117k | { |
294 | 117k | impeg2d_bit_stream_flush(ps_stream,1); |
295 | | |
296 | 117k | } |
297 | 184k | else |
298 | 184k | { |
299 | 184k | u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream); |
300 | | |
301 | 184k | if(0 == u2_mb_addr_incr) |
302 | 196 | { |
303 | 196 | return IV_FAIL; |
304 | 196 | } |
305 | | |
306 | 184k | if(ps_dec->u2_first_mb) |
307 | 6.26k | { |
308 | | /****************************************************************/ |
309 | | /* Section 6.3.17 */ |
310 | | /* The first MB of a slice cannot be skipped */ |
311 | | /* But the mb_addr_incr can be > 1, because at the beginning of */ |
312 | | /* a slice, it indicates the offset from the last MB in the */ |
313 | | /* previous row. Hence for the first slice in a row, the */ |
314 | | /* mb_addr_incr needs to be 1. */ |
315 | | /****************************************************************/ |
316 | | /* MB_x is set to zero whenever MB_y changes. */ |
317 | 6.26k | ps_dec->u2_mb_x = u2_mb_addr_incr - 1; |
318 | | /* For error resilience */ |
319 | 6.26k | ps_dec->u2_mb_x = MIN(ps_dec->u2_mb_x, (ps_dec->u2_num_horiz_mb - 1)); |
320 | 6.26k | ps_dec->u2_num_mbs_left = ((ps_dec->u2_num_vert_mb - ps_dec->u2_mb_y) |
321 | 6.26k | * ps_dec->u2_num_horiz_mb) - ps_dec->u2_mb_x; |
322 | | |
323 | | /****************************************************************/ |
324 | | /* mb_addr_incr is forced to 1 because in this decoder it is used */ |
325 | | /* more as an indicator of the number of MBs skipped than the */ |
326 | | /* as defined by the standard (Section 6.3.17) */ |
327 | | /****************************************************************/ |
328 | 6.26k | u2_mb_addr_incr = 1; |
329 | 6.26k | ps_dec->u2_first_mb = 0; |
330 | 6.26k | } |
331 | 178k | else |
332 | 178k | { |
333 | | /****************************************************************/ |
334 | | /* In MPEG-2, the last MB of the row cannot be skipped and the */ |
335 | | /* mb_addr_incr cannot be such that it will take the current MB */ |
336 | | /* beyond the current row */ |
337 | | /* In MPEG-1, the slice could start and end anywhere and is not */ |
338 | | /* restricted to a row like in MPEG-2. Hence this check should */ |
339 | | /* not be done for MPEG-1 streams. */ |
340 | | /****************************************************************/ |
341 | 178k | if(ps_dec->u2_is_mpeg2 && |
342 | 107k | ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb)) |
343 | 14.1k | { |
344 | 14.1k | u2_mb_addr_incr = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x; |
345 | 14.1k | } |
346 | | |
347 | 178k | if ((u2_mb_addr_incr - 1) > ps_dec->u2_num_mbs_left) |
348 | 292 | { |
349 | | /* If the number of skip MBs are more than the number of MBs |
350 | | * left, indicate error. |
351 | | */ |
352 | 292 | return IV_FAIL; |
353 | 292 | } |
354 | | |
355 | 177k | impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1)); |
356 | 177k | } |
357 | | |
358 | 184k | } |
359 | 301k | u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16); |
360 | | /*-----------------------------------------------------------------------*/ |
361 | | /* MB type */ |
362 | | /*-----------------------------------------------------------------------*/ |
363 | 301k | { |
364 | 301k | u2_mb_type = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)]; |
365 | 301k | u2_len = BITS(u2_mb_type,15,8); |
366 | 301k | u2_total_len = u2_len; |
367 | 301k | u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len); |
368 | 301k | } |
369 | | /*-----------------------------------------------------------------------*/ |
370 | | /* motion type */ |
371 | | /*-----------------------------------------------------------------------*/ |
372 | 301k | { |
373 | 301k | WORD32 i4_motion_type = ps_dec->u2_motion_type; |
374 | | |
375 | 301k | if((u2_mb_type & MB_FORW_OR_BACK) && ps_dec->u2_read_motion_type) |
376 | 199k | { |
377 | 199k | ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14); |
378 | 199k | u2_total_len += MB_MOTION_TYPE_LEN; |
379 | 199k | u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN); |
380 | 199k | i4_motion_type = ps_dec->u2_motion_type; |
381 | | |
382 | 199k | } |
383 | | |
384 | | |
385 | 301k | if ((u2_mb_type & MB_FORW_OR_BACK) && |
386 | 283k | ((i4_motion_type == 0) || |
387 | 250k | (i4_motion_type == 3) || |
388 | 232k | (i4_motion_type == 4) || |
389 | 232k | (i4_motion_type >= 7))) |
390 | 50.9k | { |
391 | | //TODO: VANG Check for validity |
392 | 50.9k | i4_motion_type = 1; |
393 | 50.9k | } |
394 | | |
395 | 301k | } |
396 | | /*-----------------------------------------------------------------------*/ |
397 | | /* dct type */ |
398 | | /*-----------------------------------------------------------------------*/ |
399 | 301k | { |
400 | 301k | if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type) |
401 | 63.2k | { |
402 | 63.2k | ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15); |
403 | 63.2k | u2_total_len += MB_DCT_TYPE_LEN; |
404 | 63.2k | u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN); |
405 | 63.2k | } |
406 | 301k | } |
407 | | /*-----------------------------------------------------------------------*/ |
408 | | /* Quant scale code */ |
409 | | /*-----------------------------------------------------------------------*/ |
410 | 301k | if(u2_mb_type & MB_QUANT) |
411 | 32.9k | { |
412 | 32.9k | UWORD16 u2_quant_scale_code; |
413 | 32.9k | u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11); |
414 | | |
415 | 32.9k | ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ? |
416 | 17.1k | gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1); |
417 | 32.9k | u2_total_len += MB_QUANT_SCALE_CODE_LEN; |
418 | 32.9k | } |
419 | 301k | impeg2d_bit_stream_flush(ps_stream,u2_total_len); |
420 | | /*-----------------------------------------------------------------------*/ |
421 | | /* Set the function pointers */ |
422 | | /*-----------------------------------------------------------------------*/ |
423 | 301k | ps_dec->u2_coded_mb = (UWORD16)(u2_mb_type & MB_CODED); |
424 | | |
425 | 301k | if(u2_mb_type & MB_BIDRECT) |
426 | 87.5k | { |
427 | 87.5k | UWORD16 u2_index = (ps_dec->u2_motion_type); |
428 | | |
429 | 87.5k | ps_dec->u2_prev_intra_mb = 0; |
430 | 87.5k | ps_dec->e_mb_pred = BIDIRECT; |
431 | 87.5k | ps_dec_mb_params = &ps_dec->ps_func_bi_direct[u2_index]; |
432 | 87.5k | ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type; |
433 | 87.5k | if(NULL == ps_dec_mb_params->pf_func_mb_params) |
434 | 2.26k | return -1; |
435 | 85.2k | ps_dec_mb_params->pf_func_mb_params(ps_dec); |
436 | 85.2k | } |
437 | 213k | else if(u2_mb_type & MB_FORW_OR_BACK) |
438 | 196k | { |
439 | | |
440 | 196k | UWORD16 u2_refPic = !(u2_mb_type & MB_MV_FORW); |
441 | 196k | UWORD16 u2_index = (ps_dec->u2_motion_type); |
442 | 196k | ps_dec->u2_prev_intra_mb = 0; |
443 | 196k | ps_dec->e_mb_pred = (e_pred_direction_t)u2_refPic; |
444 | 196k | ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[u2_index]; |
445 | 196k | ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type; |
446 | 196k | if(NULL == ps_dec_mb_params->pf_func_mb_params) |
447 | 0 | return -1; |
448 | 196k | ps_dec_mb_params->pf_func_mb_params(ps_dec); |
449 | | |
450 | 196k | } |
451 | 17.6k | else if(u2_mb_type & MB_TYPE_INTRA) |
452 | 5.48k | { |
453 | 5.48k | ps_dec->u2_prev_intra_mb = 1; |
454 | 5.48k | impeg2d_dec_intra_mb(ps_dec); |
455 | | |
456 | 5.48k | } |
457 | 12.1k | else |
458 | 12.1k | { |
459 | 12.1k | ps_dec->u2_prev_intra_mb =0; |
460 | 12.1k | ps_dec->e_mb_pred = FORW; |
461 | 12.1k | ps_dec->u2_motion_type = 0; |
462 | 12.1k | impeg2d_dec_0mv_coded_mb(ps_dec); |
463 | 12.1k | } |
464 | | |
465 | | /*-----------------------------------------------------------------------*/ |
466 | | /* decode cbp */ |
467 | | /*-----------------------------------------------------------------------*/ |
468 | 299k | if((u2_mb_type & MB_TYPE_INTRA)) |
469 | 5.48k | { |
470 | 5.48k | ps_dec->u2_cbp = 0x3f; |
471 | 5.48k | ps_dec->u2_prev_intra_mb = 1; |
472 | 5.48k | } |
473 | 293k | else |
474 | 293k | { |
475 | 293k | ps_dec->u2_prev_intra_mb = 0; |
476 | 293k | ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision; |
477 | 293k | ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision; |
478 | 293k | ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision; |
479 | 293k | if((ps_dec->u2_coded_mb)) |
480 | 77.2k | { |
481 | 77.2k | UWORD16 cbpValue; |
482 | 77.2k | cbpValue = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)]; |
483 | 77.2k | ps_dec->u2_cbp = cbpValue & 0xFF; |
484 | 77.2k | impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF); |
485 | 77.2k | } |
486 | 216k | else |
487 | 216k | { |
488 | 216k | ps_dec->u2_cbp = 0; |
489 | 216k | } |
490 | 293k | } |
491 | 299k | return 0; |
492 | 301k | } |
493 | | |
494 | | /******************************************************************************* |
495 | | * Function Name : impeg2d_dec_p_b_slice |
496 | | * |
497 | | * Description : Decodes P and B slices |
498 | | * |
499 | | * Arguments : |
500 | | * dec : Decoder state |
501 | | * |
502 | | * Values Returned : None |
503 | | *******************************************************************************/ |
504 | | IMPEG2D_ERROR_CODES_T impeg2d_dec_p_b_slice(dec_state_t *ps_dec) |
505 | 23.9k | { |
506 | 23.9k | WORD16 *pi2_vld_out; |
507 | 23.9k | UWORD32 i; |
508 | 23.9k | yuv_buf_t *ps_cur_frm_buf = &ps_dec->s_cur_frm_buf; |
509 | | |
510 | 23.9k | UWORD32 u4_frm_offset = 0; |
511 | 23.9k | const dec_mb_params_t *ps_dec_mb_params; |
512 | 23.9k | IMPEG2D_ERROR_CODES_T e_error = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE; |
513 | | |
514 | 23.9k | pi2_vld_out = ps_dec->ai2_vld_buf; |
515 | 23.9k | memset(ps_dec->ai2_pred_mv,0,sizeof(ps_dec->ai2_pred_mv)); |
516 | | |
517 | 23.9k | ps_dec->u2_prev_intra_mb = 0; |
518 | 23.9k | ps_dec->u2_first_mb = 1; |
519 | | |
520 | 23.9k | ps_dec->u2_picture_width = ps_dec->u2_frame_width; |
521 | | |
522 | 23.9k | if(ps_dec->u2_picture_structure != FRAME_PICTURE) |
523 | 1.31k | { |
524 | 1.31k | ps_dec->u2_picture_width <<= 1; |
525 | 1.31k | if(ps_dec->u2_picture_structure == BOTTOM_FIELD) |
526 | 525 | { |
527 | 525 | u4_frm_offset = ps_dec->u2_frame_width; |
528 | 525 | } |
529 | 1.31k | } |
530 | | |
531 | 23.9k | do |
532 | 3.76M | { |
533 | 3.76M | UWORD32 u4_x_offset, u4_y_offset; |
534 | 3.76M | WORD32 ret; |
535 | | |
536 | | |
537 | 3.76M | UWORD32 u4_x_dst_offset = 0; |
538 | 3.76M | UWORD32 u4_y_dst_offset = 0; |
539 | 3.76M | UWORD8 *pu1_out_p; |
540 | 3.76M | UWORD8 *pu1_pred; |
541 | 3.76M | WORD32 u4_pred_strd; |
542 | | |
543 | 3.76M | IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y); |
544 | | |
545 | 3.76M | if(ps_dec->e_pic_type == B_PIC) |
546 | 301k | ret = impeg2d_dec_pnb_mb_params(ps_dec); |
547 | 3.46M | else |
548 | 3.46M | ret = impeg2d_dec_p_mb_params(ps_dec); |
549 | | |
550 | 3.76M | if(ret) |
551 | 3.30k | return IMPEG2D_MB_TEX_DECODE_ERR; |
552 | | |
553 | 3.75M | if(0 >= ps_dec->u2_num_mbs_left) |
554 | 410 | { |
555 | 410 | break; |
556 | 410 | } |
557 | | |
558 | 3.75M | IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y); |
559 | | |
560 | 3.75M | u4_x_dst_offset = u4_frm_offset + (ps_dec->u2_mb_x << 4); |
561 | 3.75M | u4_y_dst_offset = (ps_dec->u2_mb_y << 4) * ps_dec->u2_picture_width; |
562 | 3.75M | pu1_out_p = ps_cur_frm_buf->pu1_y + u4_x_dst_offset + u4_y_dst_offset; |
563 | 3.75M | if(ps_dec->u2_prev_intra_mb == 0) |
564 | 3.75M | { |
565 | 3.75M | UWORD32 offset_x, offset_y, stride; |
566 | 3.75M | UWORD16 index = (ps_dec->u2_motion_type); |
567 | | /*only for non intra mb's*/ |
568 | 3.75M | if(ps_dec->e_mb_pred == BIDIRECT) |
569 | 85.3k | { |
570 | 85.3k | ps_dec_mb_params = &ps_dec->ps_func_bi_direct[index]; |
571 | 85.3k | } |
572 | 3.67M | else |
573 | 3.67M | { |
574 | 3.67M | ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index]; |
575 | 3.67M | } |
576 | | |
577 | 3.75M | stride = ps_dec->u2_picture_width; |
578 | | |
579 | 3.75M | offset_x = u4_frm_offset + (ps_dec->u2_mb_x << 4); |
580 | | |
581 | 3.75M | offset_y = (ps_dec->u2_mb_y << 4); |
582 | | |
583 | 3.75M | ps_dec->s_dest_buf.pu1_y = ps_cur_frm_buf->pu1_y + offset_y * stride + offset_x; |
584 | | |
585 | 3.75M | stride = stride >> 1; |
586 | | |
587 | 3.75M | ps_dec->s_dest_buf.pu1_u = ps_cur_frm_buf->pu1_u + (offset_y >> 1) * stride |
588 | 3.75M | + (offset_x >> 1); |
589 | | |
590 | 3.75M | ps_dec->s_dest_buf.pu1_v = ps_cur_frm_buf->pu1_v + (offset_y >> 1) * stride |
591 | 3.75M | + (offset_x >> 1); |
592 | | |
593 | 3.75M | PROFILE_DISABLE_MC_IF0 |
594 | 3.75M | ps_dec_mb_params->pf_mc(ps_dec); |
595 | | |
596 | 3.75M | } |
597 | 18.6M | for(i = 0; i < NUM_LUMA_BLKS; ++i) |
598 | 14.8M | { |
599 | 14.8M | if((ps_dec->u2_cbp & (1 << (BLOCKS_IN_MB - 1 - i))) != 0) |
600 | 7.42M | { |
601 | 7.42M | e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix, |
602 | 7.42M | ps_dec->u2_prev_intra_mb, Y_LUMA, 0); |
603 | 7.42M | if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error) |
604 | 6.41k | { |
605 | 6.41k | return e_error; |
606 | 6.41k | } |
607 | | |
608 | 7.41M | u4_x_offset = gai2_impeg2_blk_x_off[i]; |
609 | | |
610 | 7.41M | if(ps_dec->u2_field_dct == 0) |
611 | 7.43M | u4_y_offset = gai2_impeg2_blk_y_off_frm[i] ; |
612 | 18.4E | else |
613 | 18.4E | u4_y_offset = gai2_impeg2_blk_y_off_fld[i] ; |
614 | | |
615 | | |
616 | | |
617 | | |
618 | | |
619 | 7.41M | IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows); |
620 | | |
621 | 7.41M | PROFILE_DISABLE_IDCT_IF0 |
622 | 7.41M | { |
623 | 7.41M | WORD32 idx; |
624 | 7.41M | if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows)) |
625 | 360k | idx = 0; |
626 | 7.05M | else |
627 | 7.05M | idx = 1; |
628 | | |
629 | 7.41M | if(0 == ps_dec->u2_prev_intra_mb) |
630 | 7.44M | { |
631 | 7.44M | pu1_pred = pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset; |
632 | 7.44M | u4_pred_strd = ps_dec->u2_picture_width << ps_dec->u2_field_dct; |
633 | 7.44M | } |
634 | 18.4E | else |
635 | 18.4E | { |
636 | 18.4E | pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf; |
637 | 18.4E | u4_pred_strd = 8; |
638 | 18.4E | } |
639 | | |
640 | 7.41M | ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out, |
641 | 7.41M | ps_dec->ai2_idct_stg1, |
642 | 7.41M | pu1_pred, |
643 | 7.41M | pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset, |
644 | 7.41M | 8, |
645 | 7.41M | u4_pred_strd, |
646 | 7.41M | ps_dec->u2_picture_width << ps_dec->u2_field_dct, |
647 | 7.41M | ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows); |
648 | 7.41M | } |
649 | 7.41M | } |
650 | | |
651 | 14.8M | } |
652 | | |
653 | | /* For U and V blocks, divide the x and y offsets by 2. */ |
654 | 3.75M | u4_x_dst_offset >>= 1; |
655 | 3.75M | u4_y_dst_offset >>= 2; |
656 | | |
657 | | |
658 | | /* In case of chrominance blocks the DCT will be frame DCT */ |
659 | | /* i = 0, U component and i = 1 is V componet */ |
660 | 3.75M | if((ps_dec->u2_cbp & 0x02) != 0) |
661 | 42.2k | { |
662 | 42.2k | pu1_out_p = ps_cur_frm_buf->pu1_u + u4_x_dst_offset + u4_y_dst_offset; |
663 | 42.2k | e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix, |
664 | 42.2k | ps_dec->u2_prev_intra_mb, U_CHROMA, 0); |
665 | 42.2k | if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error) |
666 | 1.03k | { |
667 | 1.03k | return e_error; |
668 | 1.03k | } |
669 | | |
670 | | |
671 | 41.1k | IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows); |
672 | | |
673 | 41.1k | PROFILE_DISABLE_IDCT_IF0 |
674 | 41.1k | { |
675 | 41.1k | WORD32 idx; |
676 | 41.1k | if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows)) |
677 | 21.5k | idx = 0; |
678 | 19.6k | else |
679 | 19.6k | idx = 1; |
680 | | |
681 | 41.1k | if(0 == ps_dec->u2_prev_intra_mb) |
682 | 34.6k | { |
683 | 34.6k | pu1_pred = pu1_out_p; |
684 | 34.6k | u4_pred_strd = ps_dec->u2_picture_width >> 1; |
685 | 34.6k | } |
686 | 6.55k | else |
687 | 6.55k | { |
688 | 6.55k | pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf; |
689 | 6.55k | u4_pred_strd = 8; |
690 | 6.55k | } |
691 | | |
692 | 41.1k | ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out, |
693 | 41.1k | ps_dec->ai2_idct_stg1, |
694 | 41.1k | pu1_pred, |
695 | 41.1k | pu1_out_p, |
696 | 41.1k | 8, |
697 | 41.1k | u4_pred_strd, |
698 | 41.1k | ps_dec->u2_picture_width >> 1, |
699 | 41.1k | ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows); |
700 | | |
701 | 41.1k | } |
702 | | |
703 | 41.1k | } |
704 | | |
705 | | |
706 | 3.75M | if((ps_dec->u2_cbp & 0x01) != 0) |
707 | 319k | { |
708 | 319k | pu1_out_p = ps_cur_frm_buf->pu1_v + u4_x_dst_offset + u4_y_dst_offset; |
709 | 319k | e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix, |
710 | 319k | ps_dec->u2_prev_intra_mb, V_CHROMA, 0); |
711 | 319k | if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error) |
712 | 541 | { |
713 | 541 | return e_error; |
714 | 541 | } |
715 | | |
716 | | |
717 | 318k | IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows); |
718 | | |
719 | 318k | PROFILE_DISABLE_IDCT_IF0 |
720 | 318k | { |
721 | 318k | WORD32 idx; |
722 | 318k | if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows)) |
723 | 11.4k | idx = 0; |
724 | 307k | else |
725 | 307k | idx = 1; |
726 | 318k | if(0 == ps_dec->u2_prev_intra_mb) |
727 | 312k | { |
728 | 312k | pu1_pred = pu1_out_p; |
729 | 312k | u4_pred_strd = ps_dec->u2_picture_width >> 1; |
730 | 312k | } |
731 | 6.30k | else |
732 | 6.30k | { |
733 | 6.30k | pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf; |
734 | 6.30k | u4_pred_strd = 8; |
735 | 6.30k | } |
736 | | |
737 | 318k | ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out, |
738 | 318k | ps_dec->ai2_idct_stg1, |
739 | 318k | pu1_pred, |
740 | 318k | pu1_out_p, |
741 | 318k | 8, |
742 | 318k | u4_pred_strd, |
743 | 318k | ps_dec->u2_picture_width >> 1, |
744 | 318k | ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows); |
745 | | |
746 | 318k | } |
747 | 318k | } |
748 | | |
749 | 3.75M | ps_dec->u2_num_mbs_left--; |
750 | 3.75M | ps_dec->u2_first_mb = 0; |
751 | 3.75M | ps_dec->u2_mb_x++; |
752 | | |
753 | 3.75M | if(ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset) |
754 | 805 | { |
755 | 805 | return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR; |
756 | 805 | } |
757 | 3.75M | else if (ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb) |
758 | 51.4k | { |
759 | 51.4k | ps_dec->u2_mb_x = 0; |
760 | 51.4k | ps_dec->u2_mb_y++; |
761 | | |
762 | 51.4k | } |
763 | 3.75M | } |
764 | 3.75M | while(ps_dec->u2_num_mbs_left != 0 && impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,23) != 0x0); |
765 | 11.8k | return e_error; |
766 | 23.9k | } |