/src/libavc/decoder/ih264d_utils.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 | | /*! |
21 | | ************************************************************************** |
22 | | * \file ih264d_utils.c |
23 | | * |
24 | | * \brief |
25 | | * Contains routines that handle of start and end of pic processing |
26 | | * |
27 | | * \date |
28 | | * 19/12/2002 |
29 | | * |
30 | | * \author AI |
31 | | ************************************************************************** |
32 | | */ |
33 | | |
34 | | #include <string.h> |
35 | | #include "ih264_typedefs.h" |
36 | | #include "ithread.h" |
37 | | #include "ih264d_deblocking.h" |
38 | | #include "ih264d_parse_slice.h" |
39 | | #include "ih264d_parse_cavlc.h" |
40 | | #include "ih264d_dpb_manager.h" |
41 | | #include "ih264d_defs.h" |
42 | | #include "ih264d_structs.h" |
43 | | #include "ih264d_mem_request.h" |
44 | | #include "ih264_typedefs.h" |
45 | | #include "ih264_macros.h" |
46 | | #include "ih264_platform_macros.h" |
47 | | #include "ih264d_tables.h" |
48 | | #include "ih264d_debug.h" |
49 | | #include "ih264d_mb_utils.h" |
50 | | #include "ih264d_error_handler.h" |
51 | | #include "ih264d_dpb_manager.h" |
52 | | #include "ih264d_utils.h" |
53 | | #include "ih264d_defs.h" |
54 | | #include "ih264d_tables.h" |
55 | | #include "ih264d_inter_pred.h" |
56 | | #include "ih264d_dpb_manager.h" |
57 | | #include "iv.h" |
58 | | #include "ivd.h" |
59 | | #include "ih264d_format_conv.h" |
60 | | #include "ih264_error.h" |
61 | | #include "ih264_disp_mgr.h" |
62 | | #include "ih264_buf_mgr.h" |
63 | | #include "ih264d_utils.h" |
64 | | |
65 | | /*! |
66 | | ************************************************************************** |
67 | | * \if Function name : ih264d_is_end_of_pic \endif |
68 | | * |
69 | | * \brief |
70 | | * Determines whether current slice is first slice of a new picture as |
71 | | * defined in 7.4.1.2.4 of 14496-10. |
72 | | * |
73 | | * \return |
74 | | * Return 1 if current slice is first slice of a new picture |
75 | | * Otherwise it returns 0 |
76 | | ************************************************************************** |
77 | | */ |
78 | | UWORD8 ih264d_is_end_of_pic(UWORD16 u2_frame_num, |
79 | | UWORD8 u1_nal_ref_idc, |
80 | | pocstruct_t *ps_cur_poc, |
81 | | pocstruct_t *ps_prev_poc, |
82 | | dec_slice_params_t * ps_prev_slice, /*!< Previous slice parameters*/ |
83 | | UWORD8 u1_pic_order_cnt_type, |
84 | | UWORD8 u1_nal_unit_type, |
85 | | UWORD32 u4_idr_pic_id, |
86 | | UWORD8 u1_field_pic_flag, |
87 | | UWORD8 u1_bottom_field_flag) |
88 | 0 | { |
89 | 0 | WORD8 i1_is_end_of_pic; |
90 | 0 | WORD8 a, b, c, d, e, f, g, h; |
91 | |
|
92 | 0 | a = b = c = d = e = f = g = h = 0; |
93 | 0 | a = (ps_prev_slice->u2_frame_num != u2_frame_num); |
94 | 0 | b = (ps_prev_slice->u1_field_pic_flag != u1_field_pic_flag); |
95 | 0 | if(u1_field_pic_flag && ps_prev_slice->u1_field_pic_flag) |
96 | 0 | c = (u1_bottom_field_flag != ps_prev_slice->u1_bottom_field_flag); |
97 | 0 | d = |
98 | 0 | (u1_nal_ref_idc == 0 && ps_prev_slice->u1_nal_ref_idc != 0) |
99 | 0 | || (u1_nal_ref_idc != 0 |
100 | 0 | && ps_prev_slice->u1_nal_ref_idc |
101 | 0 | == 0); |
102 | 0 | if(!a) |
103 | 0 | { |
104 | 0 | if((u1_pic_order_cnt_type == 0) |
105 | 0 | && (ps_prev_slice->u1_pic_order_cnt_type == 0)) |
106 | 0 | { |
107 | 0 | e = |
108 | 0 | ((ps_cur_poc->i4_pic_order_cnt_lsb |
109 | 0 | != ps_prev_poc->i4_pic_order_cnt_lsb) |
110 | 0 | || (ps_cur_poc->i4_delta_pic_order_cnt_bottom |
111 | 0 | != ps_prev_poc->i4_delta_pic_order_cnt_bottom)); |
112 | 0 | } |
113 | |
|
114 | 0 | if((u1_pic_order_cnt_type == 1) |
115 | 0 | && (ps_prev_slice->u1_pic_order_cnt_type == 1)) |
116 | 0 | { |
117 | 0 | f = |
118 | 0 | ((ps_cur_poc->i4_delta_pic_order_cnt[0] |
119 | 0 | != ps_prev_poc->i4_delta_pic_order_cnt[0]) |
120 | 0 | || (ps_cur_poc->i4_delta_pic_order_cnt[1] |
121 | 0 | != ps_prev_poc->i4_delta_pic_order_cnt[1])); |
122 | 0 | } |
123 | 0 | } |
124 | |
|
125 | 0 | if((u1_nal_unit_type == IDR_SLICE_NAL) |
126 | 0 | && (ps_prev_slice->u1_nal_unit_type == IDR_SLICE_NAL)) |
127 | 0 | { |
128 | 0 | g = (u4_idr_pic_id != ps_prev_slice->u4_idr_pic_id); |
129 | 0 | } |
130 | |
|
131 | 0 | if((u1_nal_unit_type == IDR_SLICE_NAL) |
132 | 0 | && (ps_prev_slice->u1_nal_unit_type != IDR_SLICE_NAL)) |
133 | 0 | { |
134 | 0 | h = 1; |
135 | 0 | } |
136 | 0 | i1_is_end_of_pic = a + b + c + d + e + f + g + h; |
137 | 0 | return (i1_is_end_of_pic); |
138 | 0 | } |
139 | | |
140 | | /*! |
141 | | ************************************************************************** |
142 | | * \if Function name : ih264d_decode_pic_order_cnt \endif |
143 | | * |
144 | | * \brief |
145 | | * Calculates picture order count of picture. |
146 | | * |
147 | | * \return |
148 | | * Returns the pic order count of the picture to which current |
149 | | * Slice belongs. |
150 | | * |
151 | | ************************************************************************** |
152 | | */ |
153 | | WORD32 ih264d_decode_pic_order_cnt(UWORD8 u1_is_idr_slice, |
154 | | UWORD32 u2_frame_num, |
155 | | pocstruct_t *ps_prev_poc, |
156 | | pocstruct_t *ps_cur_poc, |
157 | | dec_slice_params_t *ps_cur_slice, /*!< Pointer to current slice Params*/ |
158 | | dec_pic_params_t * ps_pps, |
159 | | UWORD8 u1_nal_ref_idc, |
160 | | UWORD8 u1_bottom_field_flag, |
161 | | UWORD8 u1_field_pic_flag, |
162 | | WORD32 *pi4_poc) |
163 | 203k | { |
164 | 203k | WORD64 i8_pic_msb; |
165 | 203k | WORD32 i4_top_field_order_cnt = 0, i4_bottom_field_order_cnt = 0; |
166 | 203k | dec_seq_params_t *ps_seq = ps_pps->ps_sps; |
167 | 203k | WORD32 i4_prev_frame_num_ofst; |
168 | | |
169 | 203k | switch(ps_seq->u1_pic_order_cnt_type) |
170 | 203k | { |
171 | 32.2k | case 0: |
172 | | /* POC TYPE 0 */ |
173 | 32.2k | if(u1_is_idr_slice) |
174 | 9.14k | { |
175 | 9.14k | ps_cur_poc->i4_pic_order_cnt_msb = 0; |
176 | 9.14k | ps_cur_poc->i4_pic_order_cnt_lsb = 0; |
177 | 9.14k | } |
178 | 32.2k | if(ps_prev_poc->u1_mmco_equalto5) |
179 | 0 | { |
180 | 0 | if(ps_prev_poc->u1_bot_field != 1) |
181 | 0 | { |
182 | 0 | ps_prev_poc->i4_pic_order_cnt_msb = 0; |
183 | 0 | ps_prev_poc->i4_pic_order_cnt_lsb = |
184 | 0 | ps_prev_poc->i4_top_field_order_count; |
185 | 0 | } |
186 | 0 | else |
187 | 0 | { |
188 | 0 | ps_prev_poc->i4_pic_order_cnt_msb = 0; |
189 | 0 | ps_prev_poc->i4_pic_order_cnt_lsb = 0; |
190 | 0 | } |
191 | 0 | } |
192 | | |
193 | 32.2k | if((ps_cur_poc->i4_pic_order_cnt_lsb |
194 | 32.2k | < ps_prev_poc->i4_pic_order_cnt_lsb) |
195 | 5.45k | && ((ps_prev_poc->i4_pic_order_cnt_lsb |
196 | 5.45k | - ps_cur_poc->i4_pic_order_cnt_lsb) |
197 | 5.45k | >= (ps_seq->i4_max_pic_order_cntLsb |
198 | 5.45k | >> 1))) |
199 | 3.26k | { |
200 | 3.26k | i8_pic_msb = (WORD64)ps_prev_poc->i4_pic_order_cnt_msb |
201 | 3.26k | + ps_seq->i4_max_pic_order_cntLsb; |
202 | 3.26k | } |
203 | 28.9k | else if((ps_cur_poc->i4_pic_order_cnt_lsb |
204 | 28.9k | > ps_prev_poc->i4_pic_order_cnt_lsb) |
205 | 9.16k | && ((ps_cur_poc->i4_pic_order_cnt_lsb |
206 | 9.16k | - ps_prev_poc->i4_pic_order_cnt_lsb) |
207 | 9.16k | >= (ps_seq->i4_max_pic_order_cntLsb |
208 | 9.16k | >> 1))) |
209 | 3.25k | { |
210 | 3.25k | i8_pic_msb = (WORD64)ps_prev_poc->i4_pic_order_cnt_msb |
211 | 3.25k | - ps_seq->i4_max_pic_order_cntLsb; |
212 | 3.25k | } |
213 | 25.7k | else |
214 | 25.7k | { |
215 | 25.7k | i8_pic_msb = ps_prev_poc->i4_pic_order_cnt_msb; |
216 | 25.7k | } |
217 | | |
218 | 32.2k | if(!u1_field_pic_flag || !u1_bottom_field_flag) |
219 | 32.2k | { |
220 | 32.2k | WORD64 i8_result = i8_pic_msb + ps_cur_poc->i4_pic_order_cnt_lsb; |
221 | 32.2k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
222 | 0 | { |
223 | 0 | return ERROR_INV_POC; |
224 | 0 | } |
225 | 32.2k | i4_top_field_order_cnt = i8_result; |
226 | 32.2k | } |
227 | | |
228 | 32.2k | if(!u1_field_pic_flag) |
229 | 32.2k | { |
230 | 32.2k | WORD64 i8_result = (WORD64)i4_top_field_order_cnt |
231 | 32.2k | + ps_cur_poc->i4_delta_pic_order_cnt_bottom; |
232 | 32.2k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
233 | 1 | { |
234 | 1 | return ERROR_INV_POC; |
235 | 1 | } |
236 | 32.2k | i4_bottom_field_order_cnt = i8_result; |
237 | 32.2k | } |
238 | 0 | else if(u1_bottom_field_flag) |
239 | 0 | { |
240 | 0 | WORD64 i8_result = i8_pic_msb + ps_cur_poc->i4_pic_order_cnt_lsb; |
241 | 0 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
242 | 0 | { |
243 | 0 | return ERROR_INV_POC; |
244 | 0 | } |
245 | 0 | i4_bottom_field_order_cnt = i8_result; |
246 | 0 | } |
247 | | |
248 | 32.2k | if(IS_OUT_OF_RANGE_S32(i8_pic_msb)) |
249 | 0 | { |
250 | 0 | return ERROR_INV_POC; |
251 | 0 | } |
252 | 32.2k | ps_cur_poc->i4_pic_order_cnt_msb = i8_pic_msb; |
253 | 32.2k | break; |
254 | | |
255 | 113k | case 1: |
256 | 113k | { |
257 | | /* POC TYPE 1 */ |
258 | 113k | UWORD8 i; |
259 | 113k | WORD32 prev_frame_num; |
260 | 113k | WORD32 frame_num_ofst; |
261 | 113k | WORD32 abs_frm_num; |
262 | 113k | WORD32 poc_cycle_cnt, frame_num_in_poc_cycle; |
263 | 113k | WORD64 i8_expected_delta_poc_cycle; |
264 | 113k | WORD32 expected_poc; |
265 | 113k | WORD64 i8_result; |
266 | | |
267 | 113k | prev_frame_num = (WORD32)ps_cur_slice->u2_frame_num; |
268 | 113k | if(!u1_is_idr_slice) |
269 | 105k | { |
270 | 105k | if(ps_cur_slice->u1_mmco_equalto5) |
271 | 2.77k | { |
272 | 2.77k | prev_frame_num = 0; |
273 | 2.77k | i4_prev_frame_num_ofst = 0; |
274 | 2.77k | } |
275 | 102k | else |
276 | 102k | { |
277 | 102k | i4_prev_frame_num_ofst = ps_prev_poc->i4_prev_frame_num_ofst; |
278 | 102k | } |
279 | 105k | } |
280 | 8.19k | else |
281 | 8.19k | i4_prev_frame_num_ofst = 0; |
282 | | |
283 | | /* 1. Derivation for FrameNumOffset */ |
284 | 113k | if(u1_is_idr_slice) |
285 | 8.19k | { |
286 | 8.19k | frame_num_ofst = 0; |
287 | 8.19k | ps_cur_poc->i4_delta_pic_order_cnt[0] = 0; |
288 | 8.19k | ps_cur_poc->i4_delta_pic_order_cnt[1] = 0; |
289 | 8.19k | } |
290 | 105k | else if(prev_frame_num > ((WORD32)u2_frame_num)) |
291 | 8.57k | { |
292 | 8.57k | WORD64 i8_result = i4_prev_frame_num_ofst |
293 | 8.57k | + (WORD64)ps_seq->u2_u4_max_pic_num_minus1 + 1; |
294 | 8.57k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
295 | 0 | { |
296 | 0 | return ERROR_INV_FRAME_NUM; |
297 | 0 | } |
298 | 8.57k | frame_num_ofst = i8_result; |
299 | 8.57k | } |
300 | 97.1k | else |
301 | 97.1k | frame_num_ofst = i4_prev_frame_num_ofst; |
302 | | |
303 | | /* 2. Derivation for absFrameNum */ |
304 | 113k | if(0 != ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle) |
305 | 8.68k | { |
306 | 8.68k | WORD64 i8_result = frame_num_ofst + (WORD64)u2_frame_num; |
307 | 8.68k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
308 | 0 | { |
309 | 0 | return ERROR_INV_FRAME_NUM; |
310 | 0 | } |
311 | 8.68k | abs_frm_num = i8_result; |
312 | 8.68k | } |
313 | 105k | else |
314 | 105k | abs_frm_num = 0; |
315 | 113k | if((u1_nal_ref_idc == 0) && (abs_frm_num > 0)) |
316 | 788 | abs_frm_num = abs_frm_num - 1; |
317 | | |
318 | | /* 4. expectedDeltaPerPicOrderCntCycle is derived as */ |
319 | 113k | i8_expected_delta_poc_cycle = 0; |
320 | 181k | for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; |
321 | 113k | i++) |
322 | 67.9k | { |
323 | 67.9k | i8_expected_delta_poc_cycle += |
324 | 67.9k | ps_seq->i4_ofst_for_ref_frame[i]; |
325 | 67.9k | } |
326 | | |
327 | | /* 3. When absFrameNum > 0, picOrderCntCycleCnt and |
328 | | frame_num_in_poc_cycle are derived as : */ |
329 | | /* 5. expectedPicOrderCnt is derived as : */ |
330 | 113k | if(abs_frm_num > 0) |
331 | 8.47k | { |
332 | 8.47k | poc_cycle_cnt = |
333 | 8.47k | DIV((abs_frm_num - 1), |
334 | 8.47k | ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle); |
335 | 8.47k | frame_num_in_poc_cycle = |
336 | 8.47k | MOD((abs_frm_num - 1), |
337 | 8.47k | ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle); |
338 | | |
339 | 8.47k | i8_result = poc_cycle_cnt |
340 | 8.47k | * i8_expected_delta_poc_cycle; |
341 | | |
342 | 36.6k | for(i = 0; i <= frame_num_in_poc_cycle; i++) |
343 | 28.1k | { |
344 | 28.1k | i8_result = i8_result |
345 | 28.1k | + ps_seq->i4_ofst_for_ref_frame[i]; |
346 | 28.1k | } |
347 | | |
348 | 8.47k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
349 | 2 | return ERROR_INV_POC; |
350 | | |
351 | 8.47k | expected_poc = (WORD32)i8_result; |
352 | | |
353 | 8.47k | } |
354 | 105k | else |
355 | 105k | expected_poc = 0; |
356 | | |
357 | 113k | if(u1_nal_ref_idc == 0) |
358 | 8.00k | { |
359 | 8.00k | i8_result = (WORD64)expected_poc |
360 | 8.00k | + ps_seq->i4_ofst_for_non_ref_pic; |
361 | | |
362 | 8.00k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
363 | 1 | return ERROR_INV_POC; |
364 | | |
365 | 8.00k | expected_poc = (WORD32)i8_result; |
366 | 8.00k | } |
367 | | |
368 | | /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */ |
369 | 113k | if(!u1_field_pic_flag) |
370 | 113k | { |
371 | 113k | i8_result = (WORD64)expected_poc |
372 | 113k | + ps_cur_poc->i4_delta_pic_order_cnt[0]; |
373 | | |
374 | 113k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
375 | 1 | return ERROR_INV_POC; |
376 | 113k | i4_top_field_order_cnt = (WORD32)i8_result; |
377 | | |
378 | 113k | i8_result = (WORD64)i4_top_field_order_cnt |
379 | 113k | + ps_seq->i4_ofst_for_top_to_bottom_field |
380 | 113k | + ps_cur_poc->i4_delta_pic_order_cnt[1]; |
381 | | |
382 | 113k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
383 | 0 | return ERROR_INV_POC; |
384 | 113k | i4_bottom_field_order_cnt = (WORD32)i8_result; |
385 | 113k | } |
386 | 0 | else if(!u1_bottom_field_flag) |
387 | 0 | { |
388 | 0 | i8_result = (WORD64)expected_poc |
389 | 0 | + ps_cur_poc->i4_delta_pic_order_cnt[0]; |
390 | |
|
391 | 0 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
392 | 0 | return ERROR_INV_POC; |
393 | 0 | i4_top_field_order_cnt = (WORD32)i8_result; |
394 | 0 | } |
395 | 0 | else |
396 | 0 | { |
397 | 0 | i8_result = (WORD64)expected_poc |
398 | 0 | + ps_seq->i4_ofst_for_top_to_bottom_field |
399 | 0 | + ps_cur_poc->i4_delta_pic_order_cnt[0]; |
400 | |
|
401 | 0 | if(IS_OUT_OF_RANGE_S32(i8_result)) |
402 | 0 | return ERROR_INV_POC; |
403 | 0 | i4_bottom_field_order_cnt = (WORD32)i8_result; |
404 | 0 | } |
405 | | /* Copy the current POC info into Previous POC structure */ |
406 | 113k | ps_cur_poc->i4_prev_frame_num_ofst = frame_num_ofst; |
407 | 113k | } |
408 | | |
409 | 0 | break; |
410 | 57.6k | case 2: |
411 | 57.6k | { |
412 | | /* POC TYPE 2 */ |
413 | 57.6k | WORD32 prev_frame_num; |
414 | 57.6k | WORD32 frame_num_ofst; |
415 | 57.6k | WORD32 tmp_poc; |
416 | | |
417 | 57.6k | prev_frame_num = (WORD32)ps_cur_slice->u2_frame_num; |
418 | 57.6k | if(!u1_is_idr_slice) |
419 | 48.6k | { |
420 | 48.6k | if(ps_cur_slice->u1_mmco_equalto5) |
421 | 245 | { |
422 | 245 | prev_frame_num = 0; |
423 | 245 | i4_prev_frame_num_ofst = 0; |
424 | 245 | } |
425 | 48.3k | else |
426 | 48.3k | i4_prev_frame_num_ofst = ps_prev_poc->i4_prev_frame_num_ofst; |
427 | 48.6k | } |
428 | 8.98k | else |
429 | 8.98k | i4_prev_frame_num_ofst = 0; |
430 | | |
431 | | /* 1. Derivation for FrameNumOffset */ |
432 | 57.6k | if(u1_is_idr_slice) |
433 | 8.98k | { |
434 | 8.98k | frame_num_ofst = 0; |
435 | 8.98k | ps_cur_poc->i4_delta_pic_order_cnt[0] = 0; |
436 | 8.98k | ps_cur_poc->i4_delta_pic_order_cnt[1] = 0; |
437 | 8.98k | } |
438 | 48.6k | else if(prev_frame_num > ((WORD32)u2_frame_num)) |
439 | 2.86k | { |
440 | 2.86k | WORD64 i8_result = i4_prev_frame_num_ofst |
441 | 2.86k | + (WORD64)ps_seq->u2_u4_max_pic_num_minus1 + 1; |
442 | 2.86k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
443 | 0 | { |
444 | 0 | return ERROR_INV_FRAME_NUM; |
445 | 0 | } |
446 | 2.86k | frame_num_ofst = i8_result; |
447 | 2.86k | } |
448 | 45.7k | else |
449 | 45.7k | frame_num_ofst = i4_prev_frame_num_ofst; |
450 | | |
451 | | /* 2. Derivation for tempPicOrderCnt */ |
452 | 57.6k | if(u1_is_idr_slice) |
453 | 8.98k | tmp_poc = 0; |
454 | 48.6k | else if(u1_nal_ref_idc == 0) |
455 | 2.81k | { |
456 | 2.81k | WORD64 i8_result = ((frame_num_ofst + (WORD64)u2_frame_num) << 1) - 1; |
457 | 2.81k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
458 | 0 | { |
459 | 0 | return ERROR_INV_POC; |
460 | 0 | } |
461 | 2.81k | tmp_poc = i8_result; |
462 | 2.81k | } |
463 | 45.8k | else |
464 | 45.8k | { |
465 | 45.8k | WORD64 i8_result = (frame_num_ofst + (WORD64)u2_frame_num) << 1; |
466 | 45.8k | if(IS_OUT_OF_RANGE_S32(i8_result)) |
467 | 0 | { |
468 | 0 | return ERROR_INV_POC; |
469 | 0 | } |
470 | 45.8k | tmp_poc = i8_result; |
471 | 45.8k | } |
472 | | |
473 | | /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */ |
474 | 57.6k | if(!u1_field_pic_flag) |
475 | 57.6k | { |
476 | 57.6k | i4_top_field_order_cnt = tmp_poc; |
477 | 57.6k | i4_bottom_field_order_cnt = tmp_poc; |
478 | 57.6k | } |
479 | 0 | else if(!u1_bottom_field_flag) |
480 | 0 | i4_top_field_order_cnt = tmp_poc; |
481 | 0 | else |
482 | 0 | i4_bottom_field_order_cnt = tmp_poc; |
483 | | |
484 | | /* Copy the current POC info into Previous POC structure */ |
485 | 57.6k | ps_prev_poc->i4_prev_frame_num_ofst = frame_num_ofst; |
486 | 57.6k | ps_cur_poc->i4_prev_frame_num_ofst = frame_num_ofst; |
487 | 57.6k | } |
488 | 0 | break; |
489 | 0 | default: |
490 | 0 | return ERROR_INV_POC_TYPE_T; |
491 | 0 | break; |
492 | 203k | } |
493 | | |
494 | 203k | if(!u1_field_pic_flag) // or a complementary field pair |
495 | 203k | { |
496 | 203k | *pi4_poc = MIN(i4_top_field_order_cnt, i4_bottom_field_order_cnt); |
497 | 203k | ps_pps->i4_top_field_order_cnt = i4_top_field_order_cnt; |
498 | 203k | ps_pps->i4_bottom_field_order_cnt = i4_bottom_field_order_cnt; |
499 | 203k | } |
500 | 0 | else if(!u1_bottom_field_flag) |
501 | 0 | { |
502 | 0 | *pi4_poc = i4_top_field_order_cnt; |
503 | 0 | ps_pps->i4_top_field_order_cnt = i4_top_field_order_cnt; |
504 | 0 | } |
505 | 0 | else |
506 | 0 | { |
507 | 0 | *pi4_poc = i4_bottom_field_order_cnt; |
508 | 0 | ps_pps->i4_bottom_field_order_cnt = i4_bottom_field_order_cnt; |
509 | 0 | } |
510 | | |
511 | 203k | ps_pps->i4_avg_poc = *pi4_poc; |
512 | | |
513 | 203k | return OK; |
514 | 203k | } |
515 | | |
516 | | /*! |
517 | | ************************************************************************** |
518 | | * \if Function name : ih264d_end_of_pic_processing \endif |
519 | | * |
520 | | * \brief |
521 | | * Performs the end of picture processing. |
522 | | * |
523 | | * It performs deblocking on the current picture and sets the i4_status of |
524 | | * current picture as decoded. |
525 | | * |
526 | | * \return |
527 | | * 0 on Success and Error code otherwise. |
528 | | ************************************************************************** |
529 | | */ |
530 | | WORD32 ih264d_end_of_pic_processing(dec_struct_t *ps_dec) |
531 | 0 | { |
532 | 0 | UWORD8 u1_pic_type, u1_nal_ref_idc; |
533 | 0 | dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice; |
534 | | |
535 | | /* If nal_ref_idc is equal to 0 for one slice or slice data partition NAL |
536 | | unit of a particular picture, it shall be equal to 0 for all slice and |
537 | | slice data partition NAL units of the picture. nal_ref_idc greater |
538 | | than 0 indicates that the content of the NAL unit belongs to a decoded |
539 | | picture that is stored and marked for use as a reference picture in the |
540 | | decoded picture buffer. */ |
541 | | |
542 | | /* 1. Do MMCO |
543 | | 2. Add Cur Pic to list of reference pics. |
544 | | */ |
545 | | |
546 | | /* Call MMCO */ |
547 | 0 | u1_pic_type = 0; |
548 | 0 | u1_nal_ref_idc = ps_cur_slice->u1_nal_ref_idc; |
549 | |
|
550 | 0 | if(u1_nal_ref_idc) |
551 | 0 | { |
552 | 0 | if(ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL) |
553 | 0 | { |
554 | 0 | ps_dec->ps_dpb_mgr->u1_mmco_error_in_seq = 0; |
555 | 0 | if(ps_dec->ps_dpb_cmds->u1_long_term_reference_flag == 0) |
556 | 0 | { |
557 | 0 | ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr); |
558 | | /* ignore DPB errors */ |
559 | 0 | ih264d_insert_st_node(ps_dec->ps_dpb_mgr, |
560 | 0 | ps_dec->ps_cur_pic, |
561 | 0 | ps_dec->u1_pic_buf_id, |
562 | 0 | ps_cur_slice->u2_frame_num); |
563 | 0 | ps_dec->ps_dpb_mgr->u1_max_lt_frame_idx = NO_LONG_TERM_INDICIES; |
564 | 0 | } |
565 | 0 | else |
566 | 0 | { |
567 | | /* Equivalent of inserting a pic directly as longterm Pic */ |
568 | |
|
569 | 0 | { |
570 | | /* ignore DPB errors */ |
571 | 0 | ih264d_insert_st_node(ps_dec->ps_dpb_mgr, |
572 | 0 | ps_dec->ps_cur_pic, |
573 | 0 | ps_dec->u1_pic_buf_id, |
574 | 0 | ps_cur_slice->u2_frame_num); |
575 | | |
576 | | /* Set longTermIdx = 0, MaxLongTermFrameIdx = 0 */ |
577 | 0 | ih264d_delete_st_node_or_make_lt( |
578 | 0 | ps_dec->ps_dpb_mgr, |
579 | 0 | ps_cur_slice->u2_frame_num, 0, |
580 | 0 | ps_cur_slice->u1_field_pic_flag); |
581 | |
|
582 | 0 | ps_dec->ps_dpb_mgr->u1_max_lt_frame_idx = 0; |
583 | 0 | } |
584 | 0 | } |
585 | 0 | } |
586 | 0 | else |
587 | 0 | { |
588 | |
|
589 | 0 | { |
590 | 0 | UWORD16 u2_pic_num = ps_cur_slice->u2_frame_num; |
591 | |
|
592 | 0 | if(!ps_dec->ps_dpb_mgr->u1_mmco_error_in_seq) |
593 | 0 | { |
594 | 0 | WORD32 ret = ih264d_do_mmco_buffer(ps_dec->ps_dpb_cmds, ps_dec->ps_dpb_mgr, |
595 | 0 | ps_dec->ps_cur_sps->u1_num_ref_frames, u2_pic_num, |
596 | 0 | (ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1), |
597 | 0 | ps_dec->u1_nal_unit_type, ps_dec->ps_cur_pic, |
598 | 0 | ps_dec->u1_pic_buf_id, |
599 | 0 | ps_cur_slice->u1_field_pic_flag, |
600 | 0 | ps_dec->e_dec_status); |
601 | 0 | ps_dec->ps_dpb_mgr->u1_mmco_error_in_seq = ret != OK; |
602 | 0 | } |
603 | 0 | } |
604 | 0 | } |
605 | 0 | ih264d_update_default_index_list(ps_dec->ps_dpb_mgr); |
606 | 0 | } |
607 | |
|
608 | 0 | if(ps_cur_slice->u1_field_pic_flag) |
609 | 0 | { |
610 | 0 | if(ps_cur_slice->u1_bottom_field_flag) |
611 | 0 | { |
612 | 0 | if(u1_nal_ref_idc) |
613 | 0 | u1_pic_type = u1_pic_type | BOT_REF; |
614 | 0 | u1_pic_type = u1_pic_type | BOT_FLD; |
615 | 0 | } |
616 | 0 | else |
617 | 0 | { |
618 | 0 | if(u1_nal_ref_idc) |
619 | 0 | u1_pic_type = u1_pic_type | TOP_REF; |
620 | 0 | u1_pic_type = u1_pic_type | TOP_FLD; |
621 | 0 | } |
622 | 0 | } |
623 | 0 | else |
624 | 0 | u1_pic_type = TOP_REF | BOT_REF; |
625 | 0 | ps_dec->ps_cur_pic->u1_pic_type |= u1_pic_type; |
626 | | |
627 | |
|
628 | 0 | if(ps_cur_slice->u1_field_pic_flag) |
629 | 0 | { |
630 | 0 | H264_DEC_DEBUG_PRINT("Toggling secondField\n"); |
631 | 0 | ps_dec->u1_second_field = 1 - ps_dec->u1_second_field; |
632 | 0 | } |
633 | |
|
634 | 0 | return OK; |
635 | 0 | } |
636 | | |
637 | | /*****************************************************************************/ |
638 | | /* */ |
639 | | /* Function Name : init_dpb_size */ |
640 | | /* */ |
641 | | /* Description : This function calculates the DBP i4_size in frames */ |
642 | | /* Inputs : ps_seq - current sequence params */ |
643 | | /* */ |
644 | | /* Globals : None */ |
645 | | /* */ |
646 | | /* Outputs : None */ |
647 | | /* */ |
648 | | /* Returns : DPB in frames */ |
649 | | /* */ |
650 | | /* Issues : None */ |
651 | | /* */ |
652 | | /* Revision History: */ |
653 | | /* */ |
654 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
655 | | /* 28 04 2005 NS Draft */ |
656 | | /* */ |
657 | | /*****************************************************************************/ |
658 | | WORD32 ih264d_get_dpb_size(dec_seq_params_t *ps_seq) |
659 | 19.8k | { |
660 | 19.8k | WORD32 i4_size; |
661 | 19.8k | UWORD8 u1_level_idc; |
662 | | |
663 | 19.8k | u1_level_idc = ps_seq->u1_level_idc; |
664 | | |
665 | 19.8k | switch(u1_level_idc) |
666 | 19.8k | { |
667 | 345 | case 10: |
668 | 345 | i4_size = 152064; |
669 | 345 | break; |
670 | 616 | case 11: |
671 | 616 | i4_size = 345600; |
672 | 616 | break; |
673 | 493 | case 12: |
674 | 493 | i4_size = 912384; |
675 | 493 | break; |
676 | 350 | case 13: |
677 | 350 | i4_size = 912384; |
678 | 350 | break; |
679 | 530 | case 20: |
680 | 530 | i4_size = 912384; |
681 | 530 | break; |
682 | 437 | case 21: |
683 | 437 | i4_size = 1824768; |
684 | 437 | break; |
685 | 244 | case 22: |
686 | 244 | i4_size = 3110400; |
687 | 244 | break; |
688 | 308 | case 30: |
689 | 308 | i4_size = 3110400; |
690 | 308 | break; |
691 | 1.27k | case 31: |
692 | 1.27k | i4_size = 6912000; |
693 | 1.27k | break; |
694 | 947 | case 32: |
695 | 947 | i4_size = 7864320; |
696 | 947 | break; |
697 | 537 | case 40: |
698 | 537 | i4_size = 12582912; |
699 | 537 | break; |
700 | 316 | case 41: |
701 | 316 | i4_size = 12582912; |
702 | 316 | break; |
703 | 311 | case 42: |
704 | 311 | i4_size = 12582912; |
705 | 311 | break; |
706 | 401 | case 50: |
707 | 401 | i4_size = 42393600; |
708 | 401 | break; |
709 | 202 | case 51: |
710 | 202 | i4_size = 70778880; |
711 | 202 | break; |
712 | 0 | case 52: |
713 | 0 | i4_size = 70778880; |
714 | 0 | break; |
715 | 12.5k | default: |
716 | 12.5k | i4_size = 70778880; |
717 | 12.5k | break; |
718 | 19.8k | } |
719 | | |
720 | 19.8k | i4_size /= (ps_seq->u2_frm_wd_in_mbs * (ps_seq->u2_frm_ht_in_mbs << (1 - ps_seq->u1_frame_mbs_only_flag))); |
721 | 19.8k | i4_size /= 384; |
722 | 19.8k | i4_size = MIN(i4_size, 16); |
723 | 19.8k | i4_size = MAX(i4_size, 1); |
724 | 19.8k | return (i4_size); |
725 | 19.8k | } |
726 | | |
727 | | /**************************************************************************/ |
728 | | /* This function initialises the value of ps_dec->u4_recon_mb_grp */ |
729 | | /* ps_dec->u4_recon_mb_grp must satisfy the following criteria */ |
730 | | /* - multiple of 2 (required for N/2 parse-mvpred design) */ |
731 | | /* - multiple of 4 (if it is not a frame_mbs_only sequence), */ |
732 | | /* in this case N/2 itself needs to be even for mbpair processing */ |
733 | | /* - lesser than ps_dec->u2_frm_wd_in_mbs/2 (at least 3 N-Chunks */ |
734 | | /* should make a row to ensure proper MvTop transferring) */ |
735 | | /**************************************************************************/ |
736 | | WORD32 ih264d_init_dec_mb_grp(dec_struct_t *ps_dec) |
737 | 3.37k | { |
738 | 3.37k | dec_seq_params_t *ps_seq = ps_dec->ps_cur_sps; |
739 | 3.37k | UWORD8 u1_frm = ps_seq->u1_frame_mbs_only_flag; |
740 | | |
741 | 3.37k | ps_dec->u4_recon_mb_grp = ps_dec->u2_frm_wd_in_mbs << ps_seq->u1_mb_aff_flag; |
742 | | |
743 | 3.37k | ps_dec->u4_recon_mb_grp_pair = ps_dec->u4_recon_mb_grp >> 1; |
744 | | |
745 | 3.37k | if(!ps_dec->u4_recon_mb_grp) |
746 | 0 | { |
747 | 0 | return ERROR_MB_GROUP_ASSGN_T; |
748 | 0 | } |
749 | | |
750 | 3.37k | ps_dec->u4_num_mbs_prev_nmb = ps_dec->u4_recon_mb_grp; |
751 | | |
752 | 3.37k | return OK; |
753 | 3.37k | } |
754 | | |
755 | | |
756 | | /*! |
757 | | ************************************************************************** |
758 | | * \if Function name : ih264d_init_pic \endif |
759 | | * |
760 | | * \brief |
761 | | * Initializes the picture. |
762 | | * |
763 | | * \return |
764 | | * 0 on Success and Error code otherwise |
765 | | * |
766 | | * \note |
767 | | * This function is called when first slice of the |
768 | | * NON -IDR picture is encountered. |
769 | | ************************************************************************** |
770 | | */ |
771 | | WORD32 ih264d_init_pic(dec_struct_t *ps_dec, |
772 | | UWORD16 u2_frame_num, |
773 | | WORD32 i4_poc, |
774 | | dec_pic_params_t *ps_pps) |
775 | 0 | { |
776 | 0 | dec_seq_params_t *ps_seq = ps_pps->ps_sps; |
777 | 0 | prev_seq_params_t * ps_prev_seq_params = &ps_dec->s_prev_seq_params; |
778 | 0 | WORD32 i4_pic_bufs; |
779 | 0 | WORD32 ret; |
780 | |
|
781 | 0 | ps_dec->ps_cur_slice->u2_frame_num = u2_frame_num; |
782 | 0 | ps_dec->ps_cur_slice->i4_poc = i4_poc; |
783 | 0 | ps_dec->ps_cur_pps = ps_pps; |
784 | 0 | ps_dec->ps_cur_pps->pv_codec_handle = ps_dec; |
785 | |
|
786 | 0 | ps_dec->ps_cur_sps = ps_seq; |
787 | 0 | ps_dec->ps_dpb_mgr->i4_max_frm_num = ps_seq->u2_u4_max_pic_num_minus1 |
788 | 0 | + 1; |
789 | |
|
790 | 0 | ps_dec->ps_dpb_mgr->u2_pic_ht = ps_dec->u2_pic_ht; |
791 | 0 | ps_dec->ps_dpb_mgr->u2_pic_wd = ps_dec->u2_pic_wd; |
792 | 0 | ps_dec->i4_pic_type = NA_SLICE; |
793 | 0 | ps_dec->i4_frametype = IV_NA_FRAME; |
794 | 0 | ps_dec->i4_content_type = IV_CONTENTTYPE_NA; |
795 | | |
796 | | /*--------------------------------------------------------------------*/ |
797 | | /* Get the value of MaxMbAddress and frmheight in Mbs */ |
798 | | /*--------------------------------------------------------------------*/ |
799 | 0 | ps_seq->u4_max_mb_addr = |
800 | 0 | ((UWORD32)ps_seq->u2_frm_wd_in_mbs |
801 | 0 | * ((UWORD32)ps_dec->u2_pic_ht |
802 | 0 | >> (4 |
803 | 0 | + ps_dec->ps_cur_slice->u1_field_pic_flag))) |
804 | 0 | - 1; |
805 | 0 | ps_dec->u2_frm_ht_in_mbs = (ps_dec->u2_pic_ht |
806 | 0 | >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag)); |
807 | | |
808 | | /***************************************************************************/ |
809 | | /* If change in Level or the required PicBuffers i4_size is more than the */ |
810 | | /* current one FREE the current PicBuffers and allocate affresh */ |
811 | | /***************************************************************************/ |
812 | 0 | if(!ps_dec->u1_init_dec_flag) |
813 | 0 | { |
814 | 0 | ps_dec->u1_max_dec_frame_buffering = ih264d_get_dpb_size(ps_seq); |
815 | |
|
816 | 0 | ps_dec->i4_display_delay = ps_dec->u1_max_dec_frame_buffering; |
817 | 0 | if((1 == ps_seq->u1_vui_parameters_present_flag) && |
818 | 0 | (1 == ps_seq->s_vui.u1_bitstream_restriction_flag)) |
819 | 0 | { |
820 | 0 | if(ps_seq->u1_frame_mbs_only_flag == 1) |
821 | 0 | ps_dec->i4_display_delay = ps_seq->s_vui.u4_num_reorder_frames + 1; |
822 | 0 | else |
823 | 0 | ps_dec->i4_display_delay = ps_seq->s_vui.u4_num_reorder_frames * 2 + 2; |
824 | 0 | } |
825 | |
|
826 | 0 | if(IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode) |
827 | 0 | ps_dec->i4_display_delay = 0; |
828 | |
|
829 | 0 | if(ps_dec->u4_share_disp_buf == 0) |
830 | 0 | { |
831 | 0 | UWORD8 u1_num_ref_frames = ps_dec->u4_thumbnail_mode ? 0 : ps_seq->u1_num_ref_frames; |
832 | 0 | if(ps_seq->u1_frame_mbs_only_flag == 1) |
833 | 0 | ps_dec->u1_pic_bufs = ps_dec->i4_display_delay + u1_num_ref_frames + 1; |
834 | 0 | else |
835 | 0 | ps_dec->u1_pic_bufs = ps_dec->i4_display_delay + u1_num_ref_frames * 2 + 2; |
836 | 0 | } |
837 | 0 | else |
838 | 0 | { |
839 | 0 | ps_dec->u1_pic_bufs = (WORD32)ps_dec->u4_num_disp_bufs; |
840 | 0 | } |
841 | |
|
842 | 0 | if(!ps_dec->u4_thumbnail_mode) |
843 | 0 | { |
844 | | /* Ensure at least two buffers are allocated */ |
845 | 0 | ps_dec->u1_pic_bufs = MAX(ps_dec->u1_pic_bufs, 2); |
846 | 0 | } |
847 | |
|
848 | 0 | if(ps_dec->u4_share_disp_buf == 0) |
849 | 0 | ps_dec->u1_pic_bufs = MIN(ps_dec->u1_pic_bufs, |
850 | 0 | (H264_MAX_REF_PICS * 2)); |
851 | |
|
852 | 0 | ps_dec->u1_max_dec_frame_buffering = MIN( |
853 | 0 | ps_dec->u1_max_dec_frame_buffering, |
854 | 0 | ps_dec->u1_pic_bufs); |
855 | | |
856 | | /* Temporary hack to run Tractor Cav/Cab/MbAff Profiler streams also for CAFI1_SVA_C.264 in conformance*/ |
857 | 0 | if(ps_dec->u1_init_dec_flag) |
858 | 0 | { |
859 | 0 | ih264d_release_pics_in_dpb((void *)ps_dec, |
860 | 0 | ps_dec->u1_pic_bufs); |
861 | 0 | ih264d_release_display_bufs(ps_dec); |
862 | 0 | ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr); |
863 | 0 | } |
864 | | |
865 | | /*********************************************************************/ |
866 | | /* Configuring decoder parameters based on level and then */ |
867 | | /* fresh pointer initialisation in decoder scratch and state buffers */ |
868 | | /*********************************************************************/ |
869 | 0 | if(!ps_dec->u1_init_dec_flag || |
870 | 0 | ((ps_seq->u1_level_idc < H264_LEVEL_3_0) ^ (ps_prev_seq_params->u1_level_idc < H264_LEVEL_3_0))) |
871 | 0 | { |
872 | 0 | ret = ih264d_init_dec_mb_grp(ps_dec); |
873 | 0 | if(ret != OK) |
874 | 0 | return ret; |
875 | 0 | } |
876 | | |
877 | 0 | ret = ih264d_allocate_dynamic_bufs(ps_dec); |
878 | 0 | if(ret != OK) |
879 | 0 | { |
880 | | /* Free any dynamic buffers that are allocated */ |
881 | 0 | ih264d_free_dynamic_bufs(ps_dec); |
882 | 0 | ps_dec->i4_error_code = IVD_MEM_ALLOC_FAILED; |
883 | 0 | return IVD_MEM_ALLOC_FAILED; |
884 | 0 | } |
885 | | |
886 | 0 | ret = ih264d_create_pic_buffers(ps_dec->u1_pic_bufs, |
887 | 0 | ps_dec); |
888 | 0 | if(ret != OK) |
889 | 0 | return ret; |
890 | | |
891 | | |
892 | | |
893 | 0 | ret = ih264d_create_mv_bank(ps_dec, ps_dec->u2_pic_wd, |
894 | 0 | ps_dec->u2_pic_ht); |
895 | 0 | if(ret != OK) |
896 | 0 | return ret; |
897 | | |
898 | | /* In shared mode, set all of them as used by display */ |
899 | 0 | if(ps_dec->u4_share_disp_buf == 1) |
900 | 0 | { |
901 | 0 | WORD32 i; |
902 | |
|
903 | 0 | for(i = 0; i < ps_dec->u1_pic_bufs; i++) |
904 | 0 | { |
905 | 0 | ih264_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mgr, i, |
906 | 0 | BUF_MGR_IO); |
907 | 0 | } |
908 | 0 | } |
909 | |
|
910 | 0 | ps_dec->u1_init_dec_flag = 1; |
911 | 0 | ps_prev_seq_params->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs; |
912 | 0 | ps_prev_seq_params->u1_level_idc = ps_seq->u1_level_idc; |
913 | 0 | ps_prev_seq_params->u1_profile_idc = ps_seq->u1_profile_idc; |
914 | 0 | ps_prev_seq_params->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs; |
915 | 0 | ps_prev_seq_params->u1_frame_mbs_only_flag = |
916 | 0 | ps_seq->u1_frame_mbs_only_flag; |
917 | 0 | ps_prev_seq_params->u1_direct_8x8_inference_flag = |
918 | 0 | ps_seq->u1_direct_8x8_inference_flag; |
919 | |
|
920 | 0 | ps_dec->i4_cur_display_seq = 0; |
921 | 0 | ps_dec->i4_prev_max_display_seq = 0; |
922 | 0 | ps_dec->i4_max_poc = 0; |
923 | |
|
924 | 0 | { |
925 | | /* 0th entry of CtxtIncMbMap will be always be containing default values |
926 | | for CABAC context representing MB not available */ |
927 | 0 | ctxt_inc_mb_info_t *p_DefCtxt = ps_dec->p_ctxt_inc_mb_map - 1; |
928 | 0 | UWORD8 *pu1_temp; |
929 | 0 | WORD8 i; |
930 | 0 | p_DefCtxt->u1_mb_type = CAB_SKIP; |
931 | |
|
932 | 0 | p_DefCtxt->u1_cbp = 0x0f; |
933 | 0 | p_DefCtxt->u1_intra_chroma_pred_mode = 0; |
934 | |
|
935 | 0 | p_DefCtxt->u1_yuv_dc_csbp = 0x7; |
936 | |
|
937 | 0 | p_DefCtxt->u1_transform8x8_ctxt = 0; |
938 | |
|
939 | 0 | pu1_temp = (UWORD8*)p_DefCtxt->i1_ref_idx; |
940 | 0 | for(i = 0; i < 4; i++, pu1_temp++) |
941 | 0 | (*pu1_temp) = 0; |
942 | 0 | pu1_temp = (UWORD8*)p_DefCtxt->u1_mv; |
943 | 0 | for(i = 0; i < 16; i++, pu1_temp++) |
944 | 0 | (*pu1_temp) = 0; |
945 | 0 | ps_dec->ps_def_ctxt_mb_info = p_DefCtxt; |
946 | 0 | } |
947 | |
|
948 | 0 | } |
949 | | /* reset DBP commands read u4_flag */ |
950 | 0 | ps_dec->ps_dpb_cmds->u1_dpb_commands_read = 0; |
951 | |
|
952 | 0 | return OK; |
953 | 0 | } |
954 | | |
955 | | /*****************************************************************************/ |
956 | | /* */ |
957 | | /* Function Name : ih264d_get_next_display_field */ |
958 | | /* */ |
959 | | /* Description : Application calls this module to get the next field */ |
960 | | /* to be displayed */ |
961 | | /* */ |
962 | | /* Inputs : 1. IBUFAPI_Handle Hnadle to the Display buffer */ |
963 | | /* 2. IH264DEC_DispUnit Pointer to the display struct */ |
964 | | /* */ |
965 | | /* Globals : */ |
966 | | /* */ |
967 | | /* */ |
968 | | /* Processing : None */ |
969 | | /* Outputs : None */ |
970 | | /* Returns : None */ |
971 | | /* Issues : None */ |
972 | | /* */ |
973 | | /* Revision History: */ |
974 | | /* */ |
975 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
976 | | /* 27 05 2005 Ittiam Draft */ |
977 | | /* */ |
978 | | /*****************************************************************************/ |
979 | | |
980 | | WORD32 ih264d_get_next_display_field(dec_struct_t * ps_dec, |
981 | | ivd_out_bufdesc_t *ps_out_buffer, |
982 | | ivd_get_display_frame_op_t *pv_disp_op) |
983 | 0 | { |
984 | 0 | pic_buffer_t *pic_buf; |
985 | |
|
986 | 0 | UWORD8 i1_cur_fld; |
987 | 0 | WORD32 u4_api_ret = -1; |
988 | 0 | WORD32 i4_disp_buf_id; |
989 | 0 | iv_yuv_buf_t *ps_op_frm; |
990 | | |
991 | | |
992 | |
|
993 | 0 | ps_op_frm = &(ps_dec->s_disp_frame_info); |
994 | 0 | H264_MUTEX_LOCK(&ps_dec->process_disp_mutex); |
995 | 0 | pic_buf = (pic_buffer_t *)ih264_disp_mgr_get( |
996 | 0 | (disp_mgr_t *)ps_dec->pv_disp_buf_mgr, &i4_disp_buf_id); |
997 | 0 | ps_dec->u4_num_fld_in_frm = 0; |
998 | 0 | u4_api_ret = -1; |
999 | 0 | pv_disp_op->u4_ts = 0; |
1000 | 0 | pv_disp_op->e_output_format = ps_dec->u1_chroma_format; |
1001 | |
|
1002 | 0 | pv_disp_op->s_disp_frm_buf.pv_y_buf = ps_out_buffer->pu1_bufs[0]; |
1003 | 0 | pv_disp_op->s_disp_frm_buf.pv_u_buf = ps_out_buffer->pu1_bufs[1]; |
1004 | 0 | pv_disp_op->s_disp_frm_buf.pv_v_buf = ps_out_buffer->pu1_bufs[2]; |
1005 | 0 | ps_dec->i4_display_index = DEFAULT_POC; |
1006 | 0 | if(pic_buf != NULL) |
1007 | 0 | { |
1008 | 0 | ps_dec->pv_disp_sei_params = &pic_buf->s_sei_pic; |
1009 | 0 | pv_disp_op->e4_fld_type = 0; |
1010 | 0 | pv_disp_op->u4_disp_buf_id = i4_disp_buf_id; |
1011 | |
|
1012 | 0 | ps_op_frm->u4_y_ht = pic_buf->u2_disp_height << 1; |
1013 | 0 | ps_op_frm->u4_u_ht = ps_op_frm->u4_v_ht = ps_op_frm->u4_y_ht >> 1; |
1014 | 0 | ps_op_frm->u4_y_wd = pic_buf->u2_disp_width; |
1015 | |
|
1016 | 0 | ps_op_frm->u4_u_wd = ps_op_frm->u4_v_wd = ps_op_frm->u4_y_wd >> 1; |
1017 | |
|
1018 | 0 | ps_op_frm->u4_y_strd = pic_buf->u2_frm_wd_y; |
1019 | 0 | ps_op_frm->u4_u_strd = ps_op_frm->u4_v_strd = pic_buf->u2_frm_wd_uv; |
1020 | | |
1021 | | /* ! */ |
1022 | 0 | pv_disp_op->u4_ts = pic_buf->u4_ts; |
1023 | 0 | ps_dec->i4_display_index = pic_buf->i4_poc; |
1024 | | |
1025 | | /* set the start of the Y, U and V buffer pointer for display */ |
1026 | 0 | ps_op_frm->pv_y_buf = pic_buf->pu1_buf1 + pic_buf->u2_crop_offset_y; |
1027 | 0 | ps_op_frm->pv_u_buf = pic_buf->pu1_buf2 + pic_buf->u2_crop_offset_uv; |
1028 | 0 | ps_op_frm->pv_v_buf = pic_buf->pu1_buf3 + pic_buf->u2_crop_offset_uv; |
1029 | 0 | ps_dec->u4_num_fld_in_frm++; |
1030 | 0 | ps_dec->u4_num_fld_in_frm++; |
1031 | 0 | u4_api_ret = 0; |
1032 | |
|
1033 | 0 | if(pic_buf->u1_picturetype == 0) |
1034 | 0 | pv_disp_op->u4_progressive_frame_flag = 1; |
1035 | 0 | else |
1036 | 0 | pv_disp_op->u4_progressive_frame_flag = 0; |
1037 | |
|
1038 | 0 | } H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex); |
1039 | 0 | pv_disp_op->u4_error_code = u4_api_ret; |
1040 | 0 | pv_disp_op->e_pic_type = 0xFFFFFFFF; //Junk; |
1041 | |
|
1042 | 0 | if(u4_api_ret) |
1043 | 0 | { |
1044 | 0 | pv_disp_op->u4_error_code = 1; //put a proper error code here |
1045 | 0 | } |
1046 | 0 | else |
1047 | 0 | { |
1048 | | |
1049 | | //Release the buffer if being sent for display |
1050 | 0 | UWORD32 temp; |
1051 | 0 | UWORD32 dest_inc_Y = 0, dest_inc_UV = 0; |
1052 | |
|
1053 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_wd = temp = MIN(ps_op_frm->u4_y_wd, |
1054 | 0 | ps_op_frm->u4_y_strd); |
1055 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_wd = pv_disp_op->s_disp_frm_buf.u4_y_wd |
1056 | 0 | >> 1; |
1057 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_wd = pv_disp_op->s_disp_frm_buf.u4_y_wd |
1058 | 0 | >> 1; |
1059 | |
|
1060 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_ht = ps_op_frm->u4_y_ht; |
1061 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_ht = pv_disp_op->s_disp_frm_buf.u4_y_ht |
1062 | 0 | >> 1; |
1063 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_ht = pv_disp_op->s_disp_frm_buf.u4_y_ht |
1064 | 0 | >> 1; |
1065 | 0 | if(0 == ps_dec->u4_share_disp_buf) |
1066 | 0 | { |
1067 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_strd = |
1068 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_wd; |
1069 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_strd = |
1070 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_wd >> 1; |
1071 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_strd = |
1072 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_wd >> 1; |
1073 | |
|
1074 | 0 | } |
1075 | 0 | else |
1076 | 0 | { |
1077 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_strd = ps_op_frm->u4_y_strd; |
1078 | 0 | } |
1079 | |
|
1080 | 0 | if(ps_dec->u4_app_disp_width) |
1081 | 0 | { |
1082 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_strd = MAX( |
1083 | 0 | ps_dec->u4_app_disp_width, |
1084 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_strd); |
1085 | 0 | } |
1086 | |
|
1087 | 0 | pv_disp_op->u4_error_code = 0; |
1088 | 0 | if(pv_disp_op->e_output_format == IV_YUV_420P) |
1089 | 0 | { |
1090 | 0 | UWORD32 i; |
1091 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_strd = |
1092 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_strd >> 1; |
1093 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_strd = |
1094 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_strd >> 1; |
1095 | |
|
1096 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_wd = ps_op_frm->u4_y_wd >> 1; |
1097 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_wd = ps_op_frm->u4_y_wd >> 1; |
1098 | |
|
1099 | 0 | if(1 == ps_dec->u4_share_disp_buf) |
1100 | 0 | { |
1101 | 0 | pv_disp_op->s_disp_frm_buf.pv_y_buf = ps_op_frm->pv_y_buf; |
1102 | |
|
1103 | 0 | for(i = 0; i < MAX_DISP_BUFS_NEW; i++) |
1104 | 0 | { |
1105 | 0 | UWORD8 *buf = ps_dec->disp_bufs[i].buf[0]; |
1106 | 0 | buf += ps_dec->disp_bufs[i].u4_ofst[0]; |
1107 | 0 | if(((UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf |
1108 | 0 | - pic_buf->u2_crop_offset_y) == buf) |
1109 | 0 | { |
1110 | 0 | buf = ps_dec->disp_bufs[i].buf[1]; |
1111 | 0 | buf += ps_dec->disp_bufs[i].u4_ofst[1]; |
1112 | 0 | pv_disp_op->s_disp_frm_buf.pv_u_buf = buf |
1113 | 0 | + (pic_buf->u2_crop_offset_uv |
1114 | 0 | / YUV420SP_FACTOR); |
1115 | |
|
1116 | 0 | buf = ps_dec->disp_bufs[i].buf[2]; |
1117 | 0 | buf += ps_dec->disp_bufs[i].u4_ofst[2]; |
1118 | 0 | pv_disp_op->s_disp_frm_buf.pv_v_buf = buf |
1119 | 0 | + (pic_buf->u2_crop_offset_uv |
1120 | 0 | / YUV420SP_FACTOR); |
1121 | |
|
1122 | 0 | } |
1123 | 0 | } |
1124 | 0 | } |
1125 | |
|
1126 | 0 | } |
1127 | 0 | else if((pv_disp_op->e_output_format == IV_YUV_420SP_UV) |
1128 | 0 | || (pv_disp_op->e_output_format == IV_YUV_420SP_VU)) |
1129 | 0 | { |
1130 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_strd = |
1131 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_strd; |
1132 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_strd = 0; |
1133 | |
|
1134 | 0 | if(1 == ps_dec->u4_share_disp_buf) |
1135 | 0 | { |
1136 | 0 | UWORD32 i; |
1137 | |
|
1138 | 0 | pv_disp_op->s_disp_frm_buf.pv_y_buf = ps_op_frm->pv_y_buf; |
1139 | |
|
1140 | 0 | for(i = 0; i < MAX_DISP_BUFS_NEW; i++) |
1141 | 0 | { |
1142 | 0 | UWORD8 *buf = ps_dec->disp_bufs[i].buf[0]; |
1143 | 0 | buf += ps_dec->disp_bufs[i].u4_ofst[0]; |
1144 | 0 | if((UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf |
1145 | 0 | - pic_buf->u2_crop_offset_y == buf) |
1146 | 0 | { |
1147 | 0 | buf = ps_dec->disp_bufs[i].buf[1]; |
1148 | 0 | buf += ps_dec->disp_bufs[i].u4_ofst[1]; |
1149 | 0 | pv_disp_op->s_disp_frm_buf.pv_u_buf = buf |
1150 | 0 | + pic_buf->u2_crop_offset_uv; |
1151 | 0 | ; |
1152 | |
|
1153 | 0 | buf = ps_dec->disp_bufs[i].buf[2]; |
1154 | 0 | buf += ps_dec->disp_bufs[i].u4_ofst[2]; |
1155 | 0 | pv_disp_op->s_disp_frm_buf.pv_v_buf = buf |
1156 | 0 | + pic_buf->u2_crop_offset_uv; |
1157 | 0 | ; |
1158 | 0 | } |
1159 | 0 | } |
1160 | 0 | } |
1161 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_wd = |
1162 | 0 | pv_disp_op->s_disp_frm_buf.u4_y_wd; |
1163 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_wd = 0; |
1164 | |
|
1165 | 0 | } |
1166 | 0 | else if((pv_disp_op->e_output_format == IV_RGB_565) |
1167 | 0 | || (pv_disp_op->e_output_format == IV_YUV_422ILE)) |
1168 | 0 | { |
1169 | |
|
1170 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_strd = 0; |
1171 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_strd = 0; |
1172 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_wd = 0; |
1173 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_wd = 0; |
1174 | 0 | pv_disp_op->s_disp_frm_buf.u4_u_ht = 0; |
1175 | 0 | pv_disp_op->s_disp_frm_buf.u4_v_ht = 0; |
1176 | |
|
1177 | 0 | } |
1178 | | |
1179 | |
|
1180 | 0 | } |
1181 | |
|
1182 | 0 | return u4_api_ret; |
1183 | 0 | } |
1184 | | |
1185 | | |
1186 | | /*****************************************************************************/ |
1187 | | /* Function Name : ih264d_release_display_field */ |
1188 | | /* */ |
1189 | | /* Description : This function releases the display field that was returned */ |
1190 | | /* here. */ |
1191 | | /* Inputs : ps_dec - Decoder parameters */ |
1192 | | /* Globals : None */ |
1193 | | /* Processing : Refer bumping process in the standard */ |
1194 | | /* Outputs : Assigns display sequence number. */ |
1195 | | /* Returns : None */ |
1196 | | /* */ |
1197 | | /* Issues : None */ |
1198 | | /* */ |
1199 | | /* Revision History: */ |
1200 | | /* */ |
1201 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
1202 | | /* 27 04 2005 NS Draft */ |
1203 | | /* */ |
1204 | | /*****************************************************************************/ |
1205 | | void ih264d_release_display_field(dec_struct_t *ps_dec, |
1206 | | ivd_get_display_frame_op_t *pv_disp_op) |
1207 | 0 | { |
1208 | 0 | if(1 == pv_disp_op->u4_error_code) |
1209 | 0 | { |
1210 | 0 | if(1 == ps_dec->u1_flushfrm) |
1211 | 0 | { |
1212 | 0 | UWORD32 i; |
1213 | |
|
1214 | 0 | if(1 == ps_dec->u4_share_disp_buf) |
1215 | 0 | { |
1216 | 0 | H264_MUTEX_LOCK(&ps_dec->process_disp_mutex); |
1217 | 0 | for(i = 0; i < (MAX_DISP_BUFS_NEW); i++) |
1218 | 0 | { |
1219 | 0 | if(1 == ps_dec->u4_disp_buf_mapping[i]) |
1220 | 0 | { |
1221 | 0 | ih264_buf_mgr_release( |
1222 | 0 | (buf_mgr_t *)ps_dec->pv_pic_buf_mgr, i, |
1223 | 0 | BUF_MGR_IO); |
1224 | 0 | ps_dec->u4_disp_buf_mapping[i] = 0; |
1225 | 0 | } |
1226 | 0 | } H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex); |
1227 | |
|
1228 | 0 | memset(ps_dec->u4_disp_buf_to_be_freed, 0, |
1229 | 0 | (MAX_DISP_BUFS_NEW) * sizeof(UWORD32)); |
1230 | 0 | for(i = 0; i < ps_dec->u1_pic_bufs; i++) |
1231 | 0 | ps_dec->u4_disp_buf_mapping[i] = 1; |
1232 | 0 | } |
1233 | 0 | ps_dec->u1_flushfrm = 0; |
1234 | |
|
1235 | 0 | } |
1236 | 0 | } |
1237 | 0 | else |
1238 | 0 | { |
1239 | 0 | H264_MUTEX_LOCK(&ps_dec->process_disp_mutex); |
1240 | |
|
1241 | 0 | if(0 == ps_dec->u4_share_disp_buf) |
1242 | 0 | { |
1243 | 0 | ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr, |
1244 | 0 | pv_disp_op->u4_disp_buf_id, |
1245 | 0 | BUF_MGR_IO); |
1246 | |
|
1247 | 0 | } |
1248 | 0 | else |
1249 | 0 | { |
1250 | 0 | ps_dec->u4_disp_buf_mapping[pv_disp_op->u4_disp_buf_id] = 1; |
1251 | 0 | } H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex); |
1252 | |
|
1253 | 0 | } |
1254 | 0 | } |
1255 | | /*****************************************************************************/ |
1256 | | /* Function Name : ih264d_assign_display_seq */ |
1257 | | /* */ |
1258 | | /* Description : This function implments bumping process. Every outgoing */ |
1259 | | /* frame from DPB is assigned a display sequence number */ |
1260 | | /* which increases monotonically. System looks for this */ |
1261 | | /* number to display a frame. */ |
1262 | | /* here. */ |
1263 | | /* Inputs : ps_dec - Decoder parameters */ |
1264 | | /* Globals : None */ |
1265 | | /* Processing : Refer bumping process in the standard */ |
1266 | | /* Outputs : Assigns display sequence number. */ |
1267 | | /* Returns : None */ |
1268 | | /* */ |
1269 | | /* Issues : None */ |
1270 | | /* */ |
1271 | | /* Revision History: */ |
1272 | | /* */ |
1273 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
1274 | | /* 27 04 2005 NS Draft */ |
1275 | | /* */ |
1276 | | /*****************************************************************************/ |
1277 | | WORD32 ih264d_assign_display_seq(dec_struct_t *ps_dec) |
1278 | 0 | { |
1279 | 0 | WORD32 i; |
1280 | 0 | WORD32 i4_min_poc; |
1281 | 0 | WORD32 i4_min_poc_buf_id; |
1282 | 0 | WORD32 i4_min_index; |
1283 | 0 | dpb_manager_t *ps_dpb_mgr = ps_dec->ps_dpb_mgr; |
1284 | 0 | WORD32 (*i4_poc_buf_id_map)[3] = ps_dpb_mgr->ai4_poc_buf_id_map; |
1285 | |
|
1286 | 0 | i4_min_poc = 0x7fffffff; |
1287 | 0 | i4_min_poc_buf_id = -1; |
1288 | 0 | i4_min_index = -1; |
1289 | |
|
1290 | 0 | if(ps_dpb_mgr->i1_poc_buf_id_entries >= ps_dec->i4_display_delay) |
1291 | 0 | { |
1292 | 0 | for(i = 0; i < MAX_BUF_ID_MAP_ENTRIES; i++) |
1293 | 0 | { |
1294 | 0 | if((i4_poc_buf_id_map[i][0] != -1) |
1295 | 0 | && (DO_NOT_DISP |
1296 | 0 | != ps_dpb_mgr->ai4_poc_buf_id_map[i][0])) |
1297 | 0 | { |
1298 | | /* Checking for <= is necessary to handle cases where there is one |
1299 | | valid buffer with poc set to 0x7FFFFFFF. */ |
1300 | 0 | if(i4_poc_buf_id_map[i][1] <= i4_min_poc) |
1301 | 0 | { |
1302 | 0 | i4_min_poc = i4_poc_buf_id_map[i][1]; |
1303 | 0 | i4_min_poc_buf_id = i4_poc_buf_id_map[i][0]; |
1304 | 0 | i4_min_index = i; |
1305 | 0 | } |
1306 | 0 | } |
1307 | 0 | } |
1308 | |
|
1309 | 0 | if((i4_min_index != -1) && (DO_NOT_DISP != i4_min_poc_buf_id)) |
1310 | 0 | { |
1311 | 0 | ps_dec->i4_cur_display_seq++; |
1312 | 0 | ih264_disp_mgr_add( |
1313 | 0 | (disp_mgr_t *)ps_dec->pv_disp_buf_mgr, |
1314 | 0 | i4_min_poc_buf_id, ps_dec->i4_cur_display_seq, |
1315 | 0 | ps_dec->apv_buf_id_pic_buf_map[i4_min_poc_buf_id]); |
1316 | 0 | i4_poc_buf_id_map[i4_min_index][0] = -1; |
1317 | 0 | i4_poc_buf_id_map[i4_min_index][1] = 0x7fffffff; |
1318 | 0 | ps_dpb_mgr->i1_poc_buf_id_entries--; |
1319 | 0 | } |
1320 | 0 | else if(DO_NOT_DISP == i4_min_poc_buf_id) |
1321 | 0 | { |
1322 | 0 | WORD32 i4_error_code; |
1323 | 0 | i4_error_code = ERROR_GAPS_IN_FRM_NUM; |
1324 | | // i4_error_code |= 1<<IVD_CORRUPTEDDATA; |
1325 | 0 | return i4_error_code; |
1326 | 0 | } |
1327 | 0 | } |
1328 | 0 | return OK; |
1329 | 0 | } |
1330 | | |
1331 | | /*****************************************************************************/ |
1332 | | /* */ |
1333 | | /* Function Name : ih264d_release_display_bufs */ |
1334 | | /* */ |
1335 | | /* Description : This function implments bumping process when mmco = 5. */ |
1336 | | /* Each outgoing frame from DPB is assigned a display */ |
1337 | | /* sequence number which increases monotonically. System */ |
1338 | | /* looks for this number to display a frame. */ |
1339 | | /* Inputs : ps_dec - Decoder parameters */ |
1340 | | /* Globals : None */ |
1341 | | /* Processing : Refer bumping process in the standard for mmco = 5 */ |
1342 | | /* Outputs : Assigns display sequence number. */ |
1343 | | /* Returns : None */ |
1344 | | /* */ |
1345 | | /* Issues : None */ |
1346 | | /* */ |
1347 | | /* Revision History: */ |
1348 | | /* */ |
1349 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
1350 | | /* 27 04 2005 NS Draft */ |
1351 | | /* */ |
1352 | | /*****************************************************************************/ |
1353 | | void ih264d_release_display_bufs(dec_struct_t *ps_dec) |
1354 | 0 | { |
1355 | 0 | WORD32 i, j; |
1356 | 0 | WORD32 i4_min_poc; |
1357 | 0 | WORD32 i4_min_poc_buf_id; |
1358 | 0 | WORD32 i4_min_index; |
1359 | 0 | WORD64 i8_temp; |
1360 | 0 | dpb_manager_t *ps_dpb_mgr = ps_dec->ps_dpb_mgr; |
1361 | 0 | WORD32 (*i4_poc_buf_id_map)[3] = ps_dpb_mgr->ai4_poc_buf_id_map; |
1362 | |
|
1363 | 0 | i4_min_poc = 0x7fffffff; |
1364 | 0 | i4_min_poc_buf_id = 0; |
1365 | 0 | i4_min_index = 0; |
1366 | |
|
1367 | 0 | ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr); |
1368 | |
|
1369 | 0 | for(j = 0; j < ps_dpb_mgr->i1_poc_buf_id_entries; j++) |
1370 | 0 | { |
1371 | 0 | i4_min_poc = 0x7fffffff; |
1372 | 0 | for(i = 0; i < MAX_BUF_ID_MAP_ENTRIES; i++) |
1373 | 0 | { |
1374 | 0 | if(i4_poc_buf_id_map[i][0] != -1) |
1375 | 0 | { |
1376 | | /* Checking for <= is necessary to handle cases where there is one |
1377 | | valid buffer with poc set to 0x7FFFFFFF. */ |
1378 | 0 | if(i4_poc_buf_id_map[i][1] <= i4_min_poc) |
1379 | 0 | { |
1380 | 0 | i4_min_poc = i4_poc_buf_id_map[i][1]; |
1381 | 0 | i4_min_poc_buf_id = i4_poc_buf_id_map[i][0]; |
1382 | 0 | i4_min_index = i; |
1383 | 0 | } |
1384 | 0 | } |
1385 | 0 | } |
1386 | |
|
1387 | 0 | if(DO_NOT_DISP != i4_min_poc_buf_id) |
1388 | 0 | { |
1389 | 0 | ps_dec->i4_cur_display_seq++; |
1390 | 0 | ih264_disp_mgr_add( |
1391 | 0 | (disp_mgr_t *)ps_dec->pv_disp_buf_mgr, |
1392 | 0 | i4_min_poc_buf_id, ps_dec->i4_cur_display_seq, |
1393 | 0 | ps_dec->apv_buf_id_pic_buf_map[i4_min_poc_buf_id]); |
1394 | 0 | i4_poc_buf_id_map[i4_min_index][0] = -1; |
1395 | 0 | i4_poc_buf_id_map[i4_min_index][1] = 0x7fffffff; |
1396 | 0 | ps_dpb_mgr->ai4_poc_buf_id_map[i4_min_index][2] = 0; |
1397 | 0 | } |
1398 | 0 | else |
1399 | 0 | { |
1400 | 0 | i4_poc_buf_id_map[i4_min_index][0] = -1; |
1401 | 0 | i4_poc_buf_id_map[i4_min_index][1] = 0x7fffffff; |
1402 | 0 | ps_dpb_mgr->ai4_poc_buf_id_map[i4_min_index][2] = 0; |
1403 | 0 | } |
1404 | 0 | } |
1405 | 0 | ps_dpb_mgr->i1_poc_buf_id_entries = 0; |
1406 | 0 | i8_temp = (WORD64)ps_dec->i4_prev_max_display_seq + ps_dec->i4_max_poc |
1407 | 0 | + ps_dec->u1_max_dec_frame_buffering + 1; |
1408 | | /*If i4_prev_max_display_seq overflows integer range, reset it */ |
1409 | 0 | ps_dec->i4_prev_max_display_seq = IS_OUT_OF_RANGE_S32(i8_temp)? |
1410 | 0 | 0 : i8_temp; |
1411 | 0 | ps_dec->i4_max_poc = 0; |
1412 | 0 | } |
1413 | | |
1414 | | /*****************************************************************************/ |
1415 | | /* */ |
1416 | | /* Function Name : ih264d_assign_pic_num */ |
1417 | | /* */ |
1418 | | /* Description : This function assigns pic num to each reference frame */ |
1419 | | /* depending on the cur_frame_num as speified in section */ |
1420 | | /* 8.2.4.1 */ |
1421 | | /* */ |
1422 | | /* Inputs : ps_dec */ |
1423 | | /* */ |
1424 | | /* Globals : NO globals used */ |
1425 | | /* */ |
1426 | | /* Processing : for all ST pictures */ |
1427 | | /* if( FrameNum > cur_frame_num) */ |
1428 | | /* PicNum = FrameNum - MaxFrameNum */ |
1429 | | /* else */ |
1430 | | /* PicNum = FrameNum */ |
1431 | | /* */ |
1432 | | /* Returns : void */ |
1433 | | /* */ |
1434 | | /* Issues : NO */ |
1435 | | /* */ |
1436 | | /* Revision History: */ |
1437 | | /* */ |
1438 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
1439 | | /* 13 07 2002 Jay Draft */ |
1440 | | /* */ |
1441 | | /*****************************************************************************/ |
1442 | | |
1443 | | void ih264d_assign_pic_num(dec_struct_t *ps_dec) |
1444 | 0 | { |
1445 | 0 | dpb_manager_t *ps_dpb_mgr; |
1446 | 0 | struct dpb_info_t *ps_next_dpb; |
1447 | 0 | WORD8 i; |
1448 | 0 | WORD32 i4_cur_frame_num, i4_max_frame_num; |
1449 | 0 | WORD32 i4_ref_frame_num; |
1450 | 0 | UWORD8 u1_fld_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag; |
1451 | |
|
1452 | 0 | i4_max_frame_num = ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1 + 1; |
1453 | 0 | i4_cur_frame_num = ps_dec->ps_cur_pic->i4_frame_num; |
1454 | 0 | ps_dpb_mgr = ps_dec->ps_dpb_mgr; |
1455 | | |
1456 | | /* Start from ST head */ |
1457 | 0 | ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head; |
1458 | 0 | for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++) |
1459 | 0 | { |
1460 | 0 | WORD32 i4_pic_num; |
1461 | |
|
1462 | 0 | i4_ref_frame_num = ps_next_dpb->ps_pic_buf->i4_frame_num; |
1463 | 0 | if(i4_ref_frame_num > i4_cur_frame_num) |
1464 | 0 | { |
1465 | | /* RefPic Buf frame_num is before Current frame_num in decode order */ |
1466 | 0 | i4_pic_num = i4_ref_frame_num - i4_max_frame_num; |
1467 | 0 | } |
1468 | 0 | else |
1469 | 0 | { |
1470 | | /* RefPic Buf frame_num is after Current frame_num in decode order */ |
1471 | 0 | i4_pic_num = i4_ref_frame_num; |
1472 | 0 | } |
1473 | |
|
1474 | 0 | ps_next_dpb->ps_pic_buf->i4_pic_num = i4_pic_num; |
1475 | 0 | ps_next_dpb->i4_frame_num = i4_pic_num; |
1476 | 0 | ps_next_dpb->ps_pic_buf->u1_long_term_frm_idx = MAX_REF_BUFS + 1; |
1477 | 0 | if(u1_fld_pic_flag) |
1478 | 0 | { |
1479 | | /* Assign the pic num to top fields and bot fields */ |
1480 | |
|
1481 | 0 | ps_next_dpb->s_top_field.i4_pic_num = i4_pic_num * 2 |
1482 | 0 | + !(ps_dec->ps_cur_slice->u1_bottom_field_flag); |
1483 | 0 | ps_next_dpb->s_bot_field.i4_pic_num = i4_pic_num * 2 |
1484 | 0 | + ps_dec->ps_cur_slice->u1_bottom_field_flag; |
1485 | 0 | } |
1486 | | /* Chase the next link */ |
1487 | 0 | ps_next_dpb = ps_next_dpb->ps_prev_short; |
1488 | 0 | } |
1489 | |
|
1490 | 0 | if(ps_dec->ps_cur_sps->u1_gaps_in_frame_num_value_allowed_flag |
1491 | 0 | && ps_dpb_mgr->u1_num_gaps) |
1492 | 0 | { |
1493 | 0 | WORD32 i4_start_frm, i4_end_frm; |
1494 | | /* Assign pic numbers for gaps */ |
1495 | 0 | for(i = 0; i < MAX_BUF_ID_MAP_ENTRIES; i++) |
1496 | 0 | { |
1497 | 0 | i4_start_frm = ps_dpb_mgr->ai4_gaps_start_frm_num[i]; |
1498 | 0 | if(i4_start_frm != INVALID_FRAME_NUM) |
1499 | 0 | { |
1500 | 0 | if(i4_start_frm > i4_cur_frame_num) |
1501 | 0 | { |
1502 | | /* gap's frame_num is before Current frame_num in |
1503 | | decode order */ |
1504 | 0 | i4_start_frm -= i4_max_frame_num; |
1505 | 0 | } |
1506 | 0 | ps_dpb_mgr->ai4_gaps_start_frm_num[i] = i4_start_frm; |
1507 | 0 | i4_end_frm = ps_dpb_mgr->ai4_gaps_end_frm_num[i]; |
1508 | |
|
1509 | 0 | if(i4_end_frm > i4_cur_frame_num) |
1510 | 0 | { |
1511 | | /* gap's frame_num is before Current frame_num in |
1512 | | decode order */ |
1513 | 0 | i4_end_frm -= i4_max_frame_num; |
1514 | 0 | } |
1515 | 0 | ps_dpb_mgr->ai4_gaps_end_frm_num[i] = i4_end_frm; |
1516 | 0 | } |
1517 | 0 | } |
1518 | 0 | } |
1519 | 0 | } |
1520 | | |
1521 | | /*! |
1522 | | ************************************************************************** |
1523 | | * \if Function name : ih264d_update_qp \endif |
1524 | | * |
1525 | | * \brief |
1526 | | * Updates the values of QP and its related entities |
1527 | | * |
1528 | | * \return |
1529 | | * 0 on Success and Error code otherwise |
1530 | | * |
1531 | | ************************************************************************** |
1532 | | */ |
1533 | | WORD32 ih264d_update_qp(dec_struct_t * ps_dec, const WORD8 i1_qp) |
1534 | 450k | { |
1535 | 450k | WORD32 i_temp; |
1536 | 450k | i_temp = (ps_dec->u1_qp + i1_qp + 52) % 52; |
1537 | | |
1538 | 450k | if((i_temp < 0) || (i_temp > 51) || (i1_qp < -26) || (i1_qp > 25)) |
1539 | 0 | return ERROR_INV_RANGE_QP_T; |
1540 | | |
1541 | 450k | ps_dec->u1_qp = i_temp; |
1542 | 450k | ps_dec->u1_qp_y_rem6 = ps_dec->u1_qp % 6; |
1543 | 450k | ps_dec->u1_qp_y_div6 = ps_dec->u1_qp / 6; |
1544 | 450k | i_temp = CLIP3(0, 51, ps_dec->u1_qp + ps_dec->ps_cur_pps->i1_chroma_qp_index_offset); |
1545 | 450k | ps_dec->u1_qp_u_rem6 = MOD(gau1_ih264d_qp_scale_cr[12 + i_temp], 6); |
1546 | 450k | ps_dec->u1_qp_u_div6 = DIV(gau1_ih264d_qp_scale_cr[12 + i_temp], 6); |
1547 | | |
1548 | 450k | i_temp = CLIP3(0, 51, ps_dec->u1_qp + ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset); |
1549 | 450k | ps_dec->u1_qp_v_rem6 = MOD(gau1_ih264d_qp_scale_cr[12 + i_temp], 6); |
1550 | 450k | ps_dec->u1_qp_v_div6 = DIV(gau1_ih264d_qp_scale_cr[12 + i_temp], 6); |
1551 | | |
1552 | 450k | ps_dec->pu2_quant_scale_y = |
1553 | 450k | gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_y_rem6]; |
1554 | 450k | ps_dec->pu2_quant_scale_u = |
1555 | 450k | gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_u_rem6]; |
1556 | 450k | ps_dec->pu2_quant_scale_v = |
1557 | 450k | gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_v_rem6]; |
1558 | 450k | return OK; |
1559 | 450k | } |
1560 | | |
1561 | | /*****************************************************************************/ |
1562 | | /* */ |
1563 | | /* Function Name : ih264d_decode_gaps_in_frame_num */ |
1564 | | /* */ |
1565 | | /* Description : This function decodes gaps in frame number */ |
1566 | | /* */ |
1567 | | /* Inputs : ps_dec Decoder parameters */ |
1568 | | /* u2_frame_num current frame number */ |
1569 | | /* */ |
1570 | | /* Globals : None */ |
1571 | | /* Processing : This functionality needs to be implemented */ |
1572 | | /* Outputs : None */ |
1573 | | /* Returns : None */ |
1574 | | /* */ |
1575 | | /* Issues : Not implemented */ |
1576 | | /* */ |
1577 | | /* Revision History: */ |
1578 | | /* */ |
1579 | | /* DD MM YYYY Author(s) Changes (Describe the changes made) */ |
1580 | | /* 06 05 2002 NS Draft */ |
1581 | | /* */ |
1582 | | /*****************************************************************************/ |
1583 | | WORD32 ih264d_decode_gaps_in_frame_num(dec_struct_t *ps_dec, |
1584 | | UWORD16 u2_frame_num) |
1585 | 0 | { |
1586 | 0 | UWORD32 u4_next_frm_num, u4_start_frm_num; |
1587 | 0 | UWORD32 u4_max_frm_num; |
1588 | 0 | pocstruct_t s_tmp_poc; |
1589 | 0 | WORD32 i4_poc; |
1590 | 0 | dec_slice_params_t *ps_cur_slice; |
1591 | |
|
1592 | 0 | dec_pic_params_t *ps_pic_params; |
1593 | 0 | WORD8 i1_gap_idx; |
1594 | 0 | WORD32 *i4_gaps_start_frm_num; |
1595 | 0 | dpb_manager_t *ps_dpb_mgr; |
1596 | 0 | WORD32 i4_frame_gaps; |
1597 | 0 | WORD8 *pi1_gaps_per_seq; |
1598 | 0 | WORD32 ret; |
1599 | |
|
1600 | 0 | ps_cur_slice = ps_dec->ps_cur_slice; |
1601 | 0 | if(ps_cur_slice->u1_field_pic_flag) |
1602 | 0 | { |
1603 | 0 | if(ps_dec->u2_prev_ref_frame_num == u2_frame_num) |
1604 | 0 | return 0; |
1605 | 0 | } |
1606 | 0 | ps_pic_params = ps_dec->ps_cur_pps; |
1607 | |
|
1608 | 0 | u4_next_frm_num = ps_dec->u2_prev_ref_frame_num + 1; |
1609 | 0 | u4_max_frm_num = ps_pic_params->ps_sps->u2_u4_max_pic_num_minus1 + 1; |
1610 | | |
1611 | | // check |
1612 | 0 | if(u4_next_frm_num >= u4_max_frm_num) |
1613 | 0 | { |
1614 | 0 | u4_next_frm_num -= u4_max_frm_num; |
1615 | 0 | } |
1616 | |
|
1617 | 0 | if(u4_next_frm_num == u2_frame_num) |
1618 | 0 | { |
1619 | 0 | return (0); |
1620 | 0 | } |
1621 | | |
1622 | | // check |
1623 | 0 | if((ps_dec->u1_nal_unit_type == IDR_SLICE_NAL) |
1624 | 0 | && (u4_next_frm_num >= u2_frame_num)) |
1625 | 0 | { |
1626 | 0 | return (0); |
1627 | 0 | } |
1628 | 0 | u4_start_frm_num = u4_next_frm_num; |
1629 | |
|
1630 | 0 | s_tmp_poc.i4_pic_order_cnt_lsb = 0; |
1631 | 0 | s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0; |
1632 | 0 | s_tmp_poc.i4_pic_order_cnt_lsb = 0; |
1633 | 0 | s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0; |
1634 | 0 | s_tmp_poc.i4_delta_pic_order_cnt[0] = 0; |
1635 | 0 | s_tmp_poc.i4_delta_pic_order_cnt[1] = 0; |
1636 | |
|
1637 | 0 | ps_cur_slice = ps_dec->ps_cur_slice; |
1638 | |
|
1639 | 0 | i4_frame_gaps = 0; |
1640 | 0 | ps_dpb_mgr = ps_dec->ps_dpb_mgr; |
1641 | | |
1642 | | /* Find a empty slot to store gap seqn info */ |
1643 | 0 | i4_gaps_start_frm_num = ps_dpb_mgr->ai4_gaps_start_frm_num; |
1644 | 0 | for(i1_gap_idx = 0; i1_gap_idx < MAX_BUF_ID_MAP_ENTRIES; i1_gap_idx++) |
1645 | 0 | { |
1646 | 0 | if(INVALID_FRAME_NUM == i4_gaps_start_frm_num[i1_gap_idx]) |
1647 | 0 | break; |
1648 | 0 | } |
1649 | 0 | if(MAX_BUF_ID_MAP_ENTRIES == i1_gap_idx) |
1650 | 0 | { |
1651 | 0 | UWORD32 i4_error_code; |
1652 | 0 | i4_error_code = ERROR_DBP_MANAGER_T; |
1653 | | // i4_error_code |= 1<<IVD_CORRUPTEDDATA; |
1654 | 0 | return i4_error_code; |
1655 | 0 | } |
1656 | | |
1657 | 0 | i4_poc = 0; |
1658 | 0 | i4_gaps_start_frm_num[i1_gap_idx] = u4_start_frm_num; |
1659 | 0 | ps_dpb_mgr->ai4_gaps_end_frm_num[i1_gap_idx] = u2_frame_num - 1; |
1660 | 0 | pi1_gaps_per_seq = ps_dpb_mgr->ai1_gaps_per_seq; |
1661 | 0 | pi1_gaps_per_seq[i1_gap_idx] = 0; |
1662 | 0 | while(u4_next_frm_num != u2_frame_num) |
1663 | 0 | { |
1664 | 0 | ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr); |
1665 | 0 | if(ps_pic_params->ps_sps->u1_pic_order_cnt_type) |
1666 | 0 | { |
1667 | | /* allocate a picture buffer and insert it as ST node */ |
1668 | 0 | ret = ih264d_decode_pic_order_cnt(0, u4_next_frm_num, |
1669 | 0 | &ps_dec->s_prev_pic_poc, |
1670 | 0 | &s_tmp_poc, ps_cur_slice, |
1671 | 0 | ps_pic_params, 1, 0, 0, |
1672 | 0 | &i4_poc); |
1673 | 0 | if(ret != OK) |
1674 | 0 | return ret; |
1675 | | |
1676 | | /* Display seq no calculations */ |
1677 | 0 | if(i4_poc >= ps_dec->i4_max_poc) |
1678 | 0 | ps_dec->i4_max_poc = i4_poc; |
1679 | | /* IDR Picture or POC wrap around */ |
1680 | 0 | if(i4_poc == 0) |
1681 | 0 | { |
1682 | 0 | WORD64 i8_temp; |
1683 | 0 | i8_temp = (WORD64)ps_dec->i4_prev_max_display_seq |
1684 | 0 | + ps_dec->i4_max_poc |
1685 | 0 | + ps_dec->u1_max_dec_frame_buffering + 1; |
1686 | | /*If i4_prev_max_display_seq overflows integer range, reset it */ |
1687 | 0 | ps_dec->i4_prev_max_display_seq = IS_OUT_OF_RANGE_S32(i8_temp)? |
1688 | 0 | 0 : i8_temp; |
1689 | 0 | ps_dec->i4_max_poc = 0; |
1690 | 0 | } |
1691 | |
|
1692 | 0 | ps_cur_slice->u1_mmco_equalto5 = 0; |
1693 | 0 | ps_cur_slice->u2_frame_num = u4_next_frm_num; |
1694 | 0 | } |
1695 | | |
1696 | | // check |
1697 | 0 | if(ps_dpb_mgr->i1_poc_buf_id_entries |
1698 | 0 | >= ps_dec->u1_max_dec_frame_buffering) |
1699 | 0 | { |
1700 | 0 | ret = ih264d_assign_display_seq(ps_dec); |
1701 | 0 | if(ret != OK) |
1702 | 0 | return ret; |
1703 | 0 | } |
1704 | | |
1705 | 0 | { |
1706 | 0 | WORD64 i8_display_poc; |
1707 | 0 | i8_display_poc = (WORD64)ps_dec->i4_prev_max_display_seq + |
1708 | 0 | i4_poc; |
1709 | 0 | if(IS_OUT_OF_RANGE_S32(i8_display_poc)) |
1710 | 0 | { |
1711 | 0 | ps_dec->i4_prev_max_display_seq = 0; |
1712 | 0 | } |
1713 | 0 | } |
1714 | 0 | ret = ih264d_insert_pic_in_display_list( |
1715 | 0 | ps_dec->ps_dpb_mgr, (WORD8) DO_NOT_DISP, |
1716 | 0 | (WORD32)(ps_dec->i4_prev_max_display_seq + i4_poc), |
1717 | 0 | u4_next_frm_num); |
1718 | 0 | if(ret != OK) |
1719 | 0 | return ret; |
1720 | | |
1721 | 0 | pi1_gaps_per_seq[i1_gap_idx]++; |
1722 | 0 | ret = ih264d_do_mmco_for_gaps(ps_dpb_mgr, |
1723 | 0 | ps_dec->ps_cur_sps->u1_num_ref_frames); |
1724 | 0 | if(ret != OK) |
1725 | 0 | return ret; |
1726 | | |
1727 | 0 | ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr); |
1728 | |
|
1729 | 0 | u4_next_frm_num++; |
1730 | 0 | if(u4_next_frm_num >= u4_max_frm_num) |
1731 | 0 | { |
1732 | 0 | u4_next_frm_num -= u4_max_frm_num; |
1733 | 0 | } |
1734 | |
|
1735 | 0 | i4_frame_gaps++; |
1736 | 0 | } |
1737 | | |
1738 | 0 | return OK; |
1739 | 0 | } |
1740 | | |
1741 | | /*! |
1742 | | ************************************************************************** |
1743 | | * \if Function name : ih264d_create_pic_buffers \endif |
1744 | | * |
1745 | | * \brief |
1746 | | * This function creates Picture Buffers. |
1747 | | * |
1748 | | * \return |
1749 | | * 0 on Success and -1 on error |
1750 | | ************************************************************************** |
1751 | | */ |
1752 | | WORD32 ih264d_create_pic_buffers(UWORD8 u1_num_of_buf, |
1753 | | dec_struct_t *ps_dec) |
1754 | 0 | { |
1755 | 0 | struct pic_buffer_t *ps_pic_buf; |
1756 | 0 | UWORD8 i; |
1757 | 0 | UWORD32 u4_luma_size, u4_chroma_size; |
1758 | 0 | UWORD8 u1_frm = ps_dec->ps_cur_sps->u1_frame_mbs_only_flag; |
1759 | 0 | WORD32 j; |
1760 | 0 | UWORD8 *pu1_buf; |
1761 | |
|
1762 | 0 | ps_pic_buf = ps_dec->ps_pic_buf_base; |
1763 | 0 | ih264_disp_mgr_init((disp_mgr_t *)ps_dec->pv_disp_buf_mgr); |
1764 | 0 | ih264_buf_mgr_init((buf_mgr_t *)ps_dec->pv_pic_buf_mgr); |
1765 | 0 | u4_luma_size = ps_dec->u2_frm_wd_y * ps_dec->u2_frm_ht_y; |
1766 | 0 | u4_chroma_size = ps_dec->u2_frm_wd_uv * ps_dec->u2_frm_ht_uv; |
1767 | |
|
1768 | 0 | { |
1769 | 0 | if(ps_dec->u4_share_disp_buf == 1) |
1770 | 0 | { |
1771 | | /* In case of buffers getting shared between application and library |
1772 | | there is no need of reference memtabs. Instead of setting the i4_size |
1773 | | to zero, it is reduced to a small i4_size to ensure that changes |
1774 | | in the code are minimal */ |
1775 | 0 | if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV) |
1776 | 0 | || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU) |
1777 | 0 | || (ps_dec->u1_chroma_format == IV_YUV_420P)) |
1778 | 0 | { |
1779 | 0 | u4_luma_size = 64; |
1780 | 0 | } |
1781 | |
|
1782 | 0 | if(ps_dec->u1_chroma_format == IV_YUV_420SP_UV) |
1783 | 0 | { |
1784 | 0 | u4_chroma_size = 64; |
1785 | 0 | } |
1786 | |
|
1787 | 0 | } |
1788 | 0 | } |
1789 | |
|
1790 | 0 | pu1_buf = ps_dec->pu1_pic_buf_base; |
1791 | | |
1792 | | /* Allocate memory for refernce buffers */ |
1793 | 0 | for(i = 0; i < u1_num_of_buf; i++) |
1794 | 0 | { |
1795 | 0 | UWORD32 u4_offset; |
1796 | 0 | WORD32 buf_ret; |
1797 | 0 | UWORD8 *pu1_luma, *pu1_chroma; |
1798 | 0 | void *pv_mem_ctxt = ps_dec->pv_mem_ctxt; |
1799 | |
|
1800 | 0 | pu1_luma = pu1_buf; |
1801 | 0 | pu1_buf += ALIGN64(u4_luma_size); |
1802 | 0 | pu1_chroma = pu1_buf; |
1803 | 0 | pu1_buf += ALIGN64(u4_chroma_size); |
1804 | | |
1805 | | /* Offset to the start of the pic from the top left corner of the frame |
1806 | | buffer */ |
1807 | |
|
1808 | 0 | if((0 == ps_dec->u4_share_disp_buf) |
1809 | 0 | || (NULL == ps_dec->disp_bufs[i].buf[0])) |
1810 | 0 | { |
1811 | 0 | UWORD32 pad_len_h, pad_len_v; |
1812 | |
|
1813 | 0 | u4_offset = ps_dec->u2_frm_wd_y * (PAD_LEN_Y_V << 1) + PAD_LEN_Y_H; |
1814 | 0 | ps_pic_buf->pu1_buf1 = (UWORD8 *)(pu1_luma) + u4_offset; |
1815 | |
|
1816 | 0 | pad_len_h = MAX(PAD_LEN_UV_H, (PAD_LEN_Y_H >> 1)); |
1817 | 0 | pad_len_v = MAX(PAD_LEN_UV_V, PAD_LEN_Y_V); |
1818 | |
|
1819 | 0 | u4_offset = ps_dec->u2_frm_wd_uv * pad_len_v + pad_len_h; |
1820 | |
|
1821 | 0 | ps_pic_buf->pu1_buf2 = (UWORD8 *)(pu1_chroma) + u4_offset; |
1822 | 0 | ps_pic_buf->pu1_buf3 = (UWORD8 *)(NULL) + u4_offset; |
1823 | |
|
1824 | 0 | } |
1825 | 0 | else |
1826 | 0 | { |
1827 | 0 | UWORD32 pad_len_h, pad_len_v; |
1828 | 0 | u4_offset = ps_dec->u2_frm_wd_y * (PAD_LEN_Y_V << 1) + PAD_LEN_Y_H; |
1829 | 0 | ps_pic_buf->pu1_buf1 = (UWORD8 *)ps_dec->disp_bufs[i].buf[0] |
1830 | 0 | + u4_offset; |
1831 | |
|
1832 | 0 | ps_dec->disp_bufs[i].u4_ofst[0] = u4_offset; |
1833 | |
|
1834 | 0 | if(ps_dec->u1_chroma_format == IV_YUV_420P) |
1835 | 0 | { |
1836 | 0 | pad_len_h = MAX(PAD_LEN_UV_H * YUV420SP_FACTOR, |
1837 | 0 | (PAD_LEN_Y_H >> 1)); |
1838 | 0 | pad_len_v = MAX(PAD_LEN_UV_V, PAD_LEN_Y_V); |
1839 | |
|
1840 | 0 | u4_offset = ps_dec->u2_frm_wd_uv * pad_len_v + pad_len_h; |
1841 | 0 | ps_pic_buf->pu1_buf2 = (UWORD8 *)(pu1_chroma) + u4_offset; |
1842 | 0 | ps_pic_buf->pu1_buf3 = (UWORD8 *)(NULL) + u4_offset; |
1843 | |
|
1844 | 0 | ps_dec->disp_bufs[i].u4_ofst[1] = u4_offset; |
1845 | 0 | ps_dec->disp_bufs[i].u4_ofst[2] = u4_offset; |
1846 | |
|
1847 | 0 | } |
1848 | 0 | else |
1849 | 0 | { |
1850 | 0 | pad_len_h = MAX(PAD_LEN_UV_H * YUV420SP_FACTOR, |
1851 | 0 | (PAD_LEN_Y_H >> 1)); |
1852 | 0 | pad_len_v = MAX(PAD_LEN_UV_V, PAD_LEN_Y_V); |
1853 | |
|
1854 | 0 | u4_offset = ps_dec->u2_frm_wd_uv * pad_len_v + pad_len_h; |
1855 | 0 | ps_pic_buf->pu1_buf2 = (UWORD8 *)(ps_dec->disp_bufs[i].buf[1]) |
1856 | 0 | + u4_offset; |
1857 | 0 | ps_pic_buf->pu1_buf3 = (UWORD8 *)(ps_dec->disp_bufs[i].buf[1]) |
1858 | 0 | + u4_offset; |
1859 | |
|
1860 | 0 | ps_dec->disp_bufs[i].u4_ofst[1] = u4_offset; |
1861 | 0 | ps_dec->disp_bufs[i].u4_ofst[2] = u4_offset; |
1862 | 0 | } |
1863 | 0 | } |
1864 | |
|
1865 | 0 | ps_pic_buf->u2_frm_ht_y = ps_dec->u2_frm_ht_y; |
1866 | 0 | ps_pic_buf->u2_frm_ht_uv = ps_dec->u2_frm_ht_uv; |
1867 | 0 | ps_pic_buf->u2_frm_wd_y = ps_dec->u2_frm_wd_y; |
1868 | 0 | ps_pic_buf->u2_frm_wd_uv = ps_dec->u2_frm_wd_uv; |
1869 | |
|
1870 | 0 | ps_pic_buf->u1_pic_buf_id = i; |
1871 | |
|
1872 | 0 | buf_ret = ih264_buf_mgr_add((buf_mgr_t *)ps_dec->pv_pic_buf_mgr, |
1873 | 0 | ps_pic_buf, i); |
1874 | 0 | if(0 != buf_ret) |
1875 | 0 | { |
1876 | 0 | ps_dec->i4_error_code = ERROR_BUF_MGR; |
1877 | 0 | return ERROR_BUF_MGR; |
1878 | 0 | } |
1879 | | |
1880 | 0 | ps_dec->apv_buf_id_pic_buf_map[i] = (void *)ps_pic_buf; |
1881 | 0 | ps_pic_buf++; |
1882 | 0 | } |
1883 | | |
1884 | 0 | if(1 == ps_dec->u4_share_disp_buf) |
1885 | 0 | { |
1886 | 0 | for(i = 0; i < u1_num_of_buf; i++) |
1887 | 0 | ps_dec->u4_disp_buf_mapping[i] = 1; |
1888 | 0 | } |
1889 | 0 | return OK; |
1890 | 0 | } |
1891 | | |
1892 | | /*! |
1893 | | ************************************************************************** |
1894 | | * \if Function name : ih264d_allocate_dynamic_bufs \endif |
1895 | | * |
1896 | | * \brief |
1897 | | * This function allocates memory required by Decoder. |
1898 | | * |
1899 | | * \param ps_dec: Pointer to dec_struct_t. |
1900 | | * |
1901 | | * \return |
1902 | | * Returns i4_status as returned by MemManager. |
1903 | | * |
1904 | | ************************************************************************** |
1905 | | */ |
1906 | | WORD16 ih264d_allocate_dynamic_bufs(dec_struct_t * ps_dec) |
1907 | 0 | { |
1908 | 0 | struct MemReq s_MemReq; |
1909 | 0 | struct MemBlock *p_MemBlock; |
1910 | |
|
1911 | 0 | pred_info_t *ps_pred_frame; |
1912 | 0 | dec_mb_info_t *ps_frm_mb_info; |
1913 | 0 | dec_slice_struct_t *ps_dec_slice_buf; |
1914 | 0 | UWORD8 *pu1_dec_mb_map, *pu1_recon_mb_map; |
1915 | 0 | UWORD16 *pu2_slice_num_map; |
1916 | |
|
1917 | 0 | WORD16 *pi16_res_coeff; |
1918 | 0 | WORD16 i16_status = 0; |
1919 | 0 | UWORD8 uc_frmOrFld = (1 - ps_dec->ps_cur_sps->u1_frame_mbs_only_flag); |
1920 | 0 | UWORD16 u4_luma_wd = ps_dec->u2_frm_wd_y; |
1921 | 0 | UWORD16 u4_chroma_wd = ps_dec->u2_frm_wd_uv; |
1922 | 0 | WORD8 c_i = 0; |
1923 | 0 | dec_seq_params_t *ps_sps = ps_dec->ps_cur_sps; |
1924 | 0 | UWORD32 u4_total_mbs = ps_sps->u4_total_num_of_mbs << uc_frmOrFld; |
1925 | 0 | UWORD32 u4_wd_mbs = ps_dec->u2_frm_wd_in_mbs; |
1926 | 0 | UWORD32 u4_ht_mbs = ps_dec->u2_frm_ht_in_mbs; |
1927 | 0 | UWORD32 u4_blk_wd; |
1928 | 0 | UWORD32 ui_size = 0; |
1929 | 0 | UWORD32 u4_int_scratch_size = 0, u4_ref_pred_size = 0; |
1930 | 0 | UWORD8 *pu1_buf; |
1931 | 0 | WORD32 num_entries; |
1932 | 0 | WORD32 size; |
1933 | 0 | void *pv_buf; |
1934 | 0 | UWORD32 u4_num_bufs; |
1935 | 0 | UWORD32 u4_luma_size, u4_chroma_size; |
1936 | 0 | void *pv_mem_ctxt = ps_dec->pv_mem_ctxt; |
1937 | | |
1938 | | /* Free any dynamic buffers that are allocated earlier. As ps_dec is memset to zero */ |
1939 | | /* at the beginning, it is safe to call this even if no memory was allocated earlier */ |
1940 | 0 | ih264d_free_dynamic_bufs(ps_dec); |
1941 | |
|
1942 | 0 | size = u4_total_mbs; |
1943 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
1944 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
1945 | 0 | memset(pv_buf, 0, size); |
1946 | 0 | ps_dec->pu1_dec_mb_map = pv_buf; |
1947 | |
|
1948 | 0 | size = u4_total_mbs; |
1949 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
1950 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
1951 | 0 | memset(pv_buf, 0, size); |
1952 | 0 | ps_dec->pu1_recon_mb_map = pv_buf; |
1953 | |
|
1954 | 0 | size = u4_total_mbs * sizeof(UWORD16); |
1955 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
1956 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
1957 | 0 | memset(pv_buf, 0, size); |
1958 | 0 | ps_dec->pu2_slice_num_map = pv_buf; |
1959 | | |
1960 | | /************************************************************/ |
1961 | | /* Post allocation Initialisations */ |
1962 | | /************************************************************/ |
1963 | 0 | ps_dec->ps_parse_cur_slice = &(ps_dec->ps_dec_slice_buf[0]); |
1964 | 0 | ps_dec->ps_decode_cur_slice = &(ps_dec->ps_dec_slice_buf[0]); |
1965 | 0 | ps_dec->ps_computebs_cur_slice = &(ps_dec->ps_dec_slice_buf[0]); |
1966 | |
|
1967 | 0 | ps_dec->ps_pred_start = ps_dec->ps_pred; |
1968 | |
|
1969 | 0 | size = sizeof(parse_pmbarams_t) * (ps_dec->u4_recon_mb_grp); |
1970 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
1971 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
1972 | 0 | memset(pv_buf, 0, size); |
1973 | 0 | ps_dec->ps_parse_mb_data = pv_buf; |
1974 | |
|
1975 | 0 | size = sizeof(parse_part_params_t) |
1976 | 0 | * ((ps_dec->u4_recon_mb_grp) << 4); |
1977 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
1978 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
1979 | 0 | memset(pv_buf, 0, size); |
1980 | 0 | ps_dec->ps_parse_part_params = pv_buf; |
1981 | |
|
1982 | 0 | size = ((u4_wd_mbs * sizeof(deblkmb_neighbour_t)) << uc_frmOrFld); |
1983 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
1984 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
1985 | 0 | memset(pv_buf, 0, size); |
1986 | 0 | ps_dec->ps_deblk_top_mb = pv_buf; |
1987 | |
|
1988 | 0 | size = ((sizeof(ctxt_inc_mb_info_t)) |
1989 | 0 | * (((u4_wd_mbs + 1) << uc_frmOrFld) + 1)); |
1990 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
1991 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
1992 | 0 | memset(pv_buf, 0, size); |
1993 | 0 | ps_dec->p_ctxt_inc_mb_map = pv_buf; |
1994 | | |
1995 | | /* 0th entry of CtxtIncMbMap will be always be containing default values |
1996 | | for CABAC context representing MB not available */ |
1997 | 0 | ps_dec->p_ctxt_inc_mb_map += 1; |
1998 | |
|
1999 | 0 | size = (sizeof(mv_pred_t) * ps_dec->u4_recon_mb_grp |
2000 | 0 | * 16); |
2001 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2002 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2003 | 0 | memset(pv_buf, 0, size); |
2004 | 0 | ps_dec->ps_mv_p[0] = pv_buf; |
2005 | |
|
2006 | 0 | size = (sizeof(mv_pred_t) * ps_dec->u4_recon_mb_grp |
2007 | 0 | * 16); |
2008 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2009 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2010 | 0 | memset(pv_buf, 0, size); |
2011 | 0 | ps_dec->ps_mv_p[1] = pv_buf; |
2012 | |
|
2013 | 0 | { |
2014 | 0 | UWORD8 i; |
2015 | 0 | for(i = 0; i < MV_SCRATCH_BUFS; i++) |
2016 | 0 | { |
2017 | 0 | size = (sizeof(mv_pred_t) |
2018 | 0 | * ps_dec->u4_recon_mb_grp * 4); |
2019 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2020 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2021 | 0 | memset(pv_buf, 0, size); |
2022 | 0 | ps_dec->ps_mv_top_p[i] = pv_buf; |
2023 | 0 | } |
2024 | 0 | } |
2025 | | |
2026 | 0 | size = sizeof(UWORD8) * ((u4_wd_mbs + 2) * MB_SIZE) * 2; |
2027 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2028 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2029 | 0 | ps_dec->pu1_y_intra_pred_line = pv_buf; |
2030 | 0 | memset(ps_dec->pu1_y_intra_pred_line, 0, size); |
2031 | 0 | ps_dec->pu1_y_intra_pred_line += MB_SIZE; |
2032 | |
|
2033 | 0 | size = sizeof(UWORD8) * ((u4_wd_mbs + 2) * MB_SIZE) * 2; |
2034 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2035 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2036 | 0 | ps_dec->pu1_u_intra_pred_line = pv_buf; |
2037 | 0 | memset(ps_dec->pu1_u_intra_pred_line, 0, size); |
2038 | 0 | ps_dec->pu1_u_intra_pred_line += MB_SIZE; |
2039 | |
|
2040 | 0 | size = sizeof(UWORD8) * ((u4_wd_mbs + 2) * MB_SIZE) * 2; |
2041 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2042 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2043 | 0 | ps_dec->pu1_v_intra_pred_line = pv_buf; |
2044 | 0 | memset(ps_dec->pu1_v_intra_pred_line, 0, size); |
2045 | 0 | ps_dec->pu1_v_intra_pred_line += MB_SIZE; |
2046 | |
|
2047 | 0 | if(ps_dec->u1_separate_parse) |
2048 | 0 | { |
2049 | | /* Needs one extra row of info, to hold top row data */ |
2050 | 0 | size = sizeof(mb_neigbour_params_t) |
2051 | 0 | * 2 * ((u4_wd_mbs + 2) * (u4_ht_mbs + 1)); |
2052 | 0 | } |
2053 | 0 | else |
2054 | 0 | { |
2055 | 0 | size = sizeof(mb_neigbour_params_t) |
2056 | 0 | * 2 * ((u4_wd_mbs + 2) << uc_frmOrFld); |
2057 | 0 | } |
2058 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2059 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2060 | |
|
2061 | 0 | ps_dec->ps_nbr_mb_row = pv_buf; |
2062 | 0 | memset(ps_dec->ps_nbr_mb_row, 0, size); |
2063 | | |
2064 | | /* Allocate deblock MB info */ |
2065 | 0 | size = (u4_total_mbs + u4_wd_mbs) * sizeof(deblk_mb_t); |
2066 | |
|
2067 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2068 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2069 | 0 | ps_dec->ps_deblk_pic = pv_buf; |
2070 | |
|
2071 | 0 | memset(ps_dec->ps_deblk_pic, 0, size); |
2072 | | |
2073 | | /* Allocate frame level mb info */ |
2074 | 0 | size = sizeof(dec_mb_info_t) * u4_total_mbs; |
2075 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2076 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2077 | 0 | ps_dec->ps_frm_mb_info = pv_buf; |
2078 | 0 | memset(ps_dec->ps_frm_mb_info, 0, size); |
2079 | | |
2080 | | /* Allocate memory for slice headers dec_slice_struct_t */ |
2081 | 0 | num_entries = MAX_FRAMES; |
2082 | 0 | if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) && |
2083 | 0 | (0 == ps_dec->i4_display_delay)) |
2084 | 0 | { |
2085 | 0 | num_entries = 1; |
2086 | 0 | } |
2087 | 0 | num_entries = ((2 * num_entries) + 1); |
2088 | 0 | num_entries *= 2; |
2089 | |
|
2090 | 0 | size = num_entries * sizeof(void *); |
2091 | 0 | size += PAD_MAP_IDX_POC * sizeof(void *); |
2092 | 0 | size *= u4_total_mbs; |
2093 | 0 | size += sizeof(dec_slice_struct_t) * u4_total_mbs; |
2094 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2095 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2096 | |
|
2097 | 0 | ps_dec->ps_dec_slice_buf = pv_buf; |
2098 | 0 | memset(ps_dec->ps_dec_slice_buf, 0, size); |
2099 | 0 | pu1_buf = (UWORD8 *)ps_dec->ps_dec_slice_buf; |
2100 | 0 | pu1_buf += sizeof(dec_slice_struct_t) * u4_total_mbs; |
2101 | 0 | ps_dec->pv_map_ref_idx_to_poc_buf = (void *)pu1_buf; |
2102 | | |
2103 | | /* Allocate memory for packed pred info */ |
2104 | 0 | num_entries = u4_total_mbs; |
2105 | 0 | num_entries *= 16 * 2; |
2106 | |
|
2107 | 0 | size = sizeof(pred_info_pkd_t) * num_entries; |
2108 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2109 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2110 | 0 | memset(pv_buf, 0, size); |
2111 | 0 | ps_dec->ps_pred_pkd = pv_buf; |
2112 | | |
2113 | | /* Allocate memory for coeff data */ |
2114 | 0 | size = MB_LUM_SIZE * sizeof(WORD16); |
2115 | | /*For I16x16 MBs, 16 4x4 AC coeffs and 1 4x4 DC coeff TU blocks will be sent |
2116 | | For all MBs along with 8 4x4 AC coeffs 2 2x2 DC coeff TU blocks will be sent |
2117 | | So use 17 4x4 TU blocks for luma and 9 4x4 TU blocks for chroma */ |
2118 | 0 | size += u4_total_mbs * (MAX(17 * sizeof(tu_sblk4x4_coeff_data_t),4 * sizeof(tu_blk8x8_coeff_data_t)) |
2119 | 0 | + 9 * sizeof(tu_sblk4x4_coeff_data_t)); |
2120 | | //32 bytes for each mb to store u1_prev_intra4x4_pred_mode and u1_rem_intra4x4_pred_mode data |
2121 | 0 | size += u4_total_mbs * 32; |
2122 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2123 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2124 | 0 | memset(pv_buf, 0, size); |
2125 | |
|
2126 | 0 | ps_dec->pi2_coeff_data = pv_buf; |
2127 | |
|
2128 | 0 | ps_dec->pv_pic_tu_coeff_data = (void *)(ps_dec->pi2_coeff_data + MB_LUM_SIZE); |
2129 | | |
2130 | | /* Allocate MV bank buffer */ |
2131 | 0 | { |
2132 | 0 | UWORD32 col_flag_buffer_size, mvpred_buffer_size; |
2133 | 0 | UWORD8 u1_num_ref_frames = ps_dec->u4_thumbnail_mode ? |
2134 | 0 | !ps_dec->ps_cur_sps->u1_frame_mbs_only_flag : |
2135 | 0 | ps_dec->ps_cur_sps->u1_num_ref_frames; |
2136 | |
|
2137 | 0 | col_flag_buffer_size = ((ps_dec->u2_pic_wd * ps_dec->u2_pic_ht) >> 4); |
2138 | 0 | mvpred_buffer_size = sizeof(mv_pred_t) |
2139 | 0 | * ((ps_dec->u2_pic_wd * (ps_dec->u2_pic_ht + PAD_MV_BANK_ROW)) >> 4); |
2140 | |
|
2141 | 0 | u4_num_bufs = u1_num_ref_frames + 1; |
2142 | |
|
2143 | 0 | u4_num_bufs = MIN(u4_num_bufs, ps_dec->u1_pic_bufs); |
2144 | 0 | if(!ps_dec->u4_thumbnail_mode) |
2145 | 0 | { |
2146 | 0 | u4_num_bufs = MAX(u4_num_bufs, 2); |
2147 | 0 | } |
2148 | 0 | size = ALIGN64(mvpred_buffer_size) + ALIGN64(col_flag_buffer_size); |
2149 | 0 | size *= u4_num_bufs; |
2150 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2151 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2152 | 0 | memset(pv_buf, 0, size); |
2153 | 0 | ps_dec->pu1_mv_bank_buf_base = pv_buf; |
2154 | 0 | } |
2155 | | |
2156 | | /* Allocate Pic buffer */ |
2157 | 0 | u4_luma_size = ps_dec->u2_frm_wd_y * ps_dec->u2_frm_ht_y; |
2158 | 0 | u4_chroma_size = ps_dec->u2_frm_wd_uv * ps_dec->u2_frm_ht_uv; |
2159 | |
|
2160 | 0 | { |
2161 | 0 | if(ps_dec->u4_share_disp_buf == 1) |
2162 | 0 | { |
2163 | | /* In case of buffers getting shared between application and library |
2164 | | there is no need of reference memtabs. Instead of setting the i4_size |
2165 | | to zero, it is reduced to a small i4_size to ensure that changes |
2166 | | in the code are minimal */ |
2167 | 0 | if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV) |
2168 | 0 | || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU) |
2169 | 0 | || (ps_dec->u1_chroma_format == IV_YUV_420P)) |
2170 | 0 | { |
2171 | 0 | u4_luma_size = 64; |
2172 | 0 | } |
2173 | |
|
2174 | 0 | if(ps_dec->u1_chroma_format == IV_YUV_420SP_UV) |
2175 | 0 | { |
2176 | 0 | u4_chroma_size = 64; |
2177 | 0 | } |
2178 | |
|
2179 | 0 | } |
2180 | 0 | } |
2181 | |
|
2182 | 0 | size = ALIGN64(u4_luma_size) + ALIGN64(u4_chroma_size); |
2183 | 0 | size *= ps_dec->u1_pic_bufs; |
2184 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2185 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2186 | 0 | memset(pv_buf, 0, size); |
2187 | 0 | ps_dec->pu1_pic_buf_base = pv_buf; |
2188 | | |
2189 | | /* Allocate memory for mb_info maps */ |
2190 | 0 | if(ps_dec->u1_enable_mb_info) |
2191 | 0 | { |
2192 | 0 | size = (u4_total_mbs << 2) * MAX_DISP_BUFS_NEW; |
2193 | |
|
2194 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2195 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2196 | 0 | memset(pv_buf, 0, size); |
2197 | 0 | ps_dec->pu1_qp_map_base = pv_buf; |
2198 | |
|
2199 | 0 | pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size); |
2200 | 0 | RETURN_IF((NULL == pv_buf), IV_FAIL); |
2201 | 0 | memset(pv_buf, 0, size); |
2202 | 0 | ps_dec->pu1_mb_type_map_base = pv_buf; |
2203 | 0 | } |
2204 | | |
2205 | | /* Post allocation Increment Actions */ |
2206 | | |
2207 | | /***************************************************************************/ |
2208 | | /*Initialize cabac context pointers for every SE that has fixed contextIdx */ |
2209 | | /***************************************************************************/ |
2210 | 0 | { |
2211 | 0 | bin_ctxt_model_t * const p_cabac_ctxt_table_t = |
2212 | 0 | ps_dec->p_cabac_ctxt_table_t; |
2213 | 0 | bin_ctxt_model_t * * p_coeff_abs_level_minus1_t = |
2214 | 0 | ps_dec->p_coeff_abs_level_minus1_t; |
2215 | 0 | bin_ctxt_model_t * * p_cbf_t = ps_dec->p_cbf_t; |
2216 | |
|
2217 | 0 | ps_dec->p_mb_field_dec_flag_t = p_cabac_ctxt_table_t |
2218 | 0 | + MB_FIELD_DECODING_FLAG; |
2219 | 0 | ps_dec->p_prev_intra4x4_pred_mode_flag_t = p_cabac_ctxt_table_t |
2220 | 0 | + PREV_INTRA4X4_PRED_MODE_FLAG; |
2221 | 0 | ps_dec->p_rem_intra4x4_pred_mode_t = p_cabac_ctxt_table_t |
2222 | 0 | + REM_INTRA4X4_PRED_MODE; |
2223 | 0 | ps_dec->p_intra_chroma_pred_mode_t = p_cabac_ctxt_table_t |
2224 | 0 | + INTRA_CHROMA_PRED_MODE; |
2225 | 0 | ps_dec->p_mb_qp_delta_t = p_cabac_ctxt_table_t + MB_QP_DELTA; |
2226 | 0 | ps_dec->p_ref_idx_t = p_cabac_ctxt_table_t + REF_IDX; |
2227 | 0 | ps_dec->p_mvd_x_t = p_cabac_ctxt_table_t + MVD_X; |
2228 | 0 | ps_dec->p_mvd_y_t = p_cabac_ctxt_table_t + MVD_Y; |
2229 | 0 | p_cbf_t[0] = p_cabac_ctxt_table_t + CBF + 0; |
2230 | 0 | p_cbf_t[1] = p_cabac_ctxt_table_t + CBF + 4; |
2231 | 0 | p_cbf_t[2] = p_cabac_ctxt_table_t + CBF + 8; |
2232 | 0 | p_cbf_t[3] = p_cabac_ctxt_table_t + CBF + 12; |
2233 | 0 | p_cbf_t[4] = p_cabac_ctxt_table_t + CBF + 16; |
2234 | 0 | ps_dec->p_cbp_luma_t = p_cabac_ctxt_table_t + CBP_LUMA; |
2235 | 0 | ps_dec->p_cbp_chroma_t = p_cabac_ctxt_table_t + CBP_CHROMA; |
2236 | |
|
2237 | 0 | p_coeff_abs_level_minus1_t[LUMA_DC_CTXCAT] = p_cabac_ctxt_table_t |
2238 | 0 | + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_0_OFFSET; |
2239 | |
|
2240 | 0 | p_coeff_abs_level_minus1_t[LUMA_AC_CTXCAT] = p_cabac_ctxt_table_t |
2241 | 0 | + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_1_OFFSET; |
2242 | |
|
2243 | 0 | p_coeff_abs_level_minus1_t[LUMA_4X4_CTXCAT] = p_cabac_ctxt_table_t |
2244 | 0 | + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_2_OFFSET; |
2245 | |
|
2246 | 0 | p_coeff_abs_level_minus1_t[CHROMA_DC_CTXCAT] = p_cabac_ctxt_table_t |
2247 | 0 | + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_3_OFFSET; |
2248 | |
|
2249 | 0 | p_coeff_abs_level_minus1_t[CHROMA_AC_CTXCAT] = p_cabac_ctxt_table_t |
2250 | 0 | + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_4_OFFSET; |
2251 | |
|
2252 | 0 | p_coeff_abs_level_minus1_t[LUMA_8X8_CTXCAT] = p_cabac_ctxt_table_t |
2253 | 0 | + COEFF_ABS_LEVEL_MINUS1_8X8 |
2254 | 0 | + COEFF_ABS_LEVEL_CAT_5_OFFSET; |
2255 | | |
2256 | | /********************************************************/ |
2257 | | /* context for the high profile related syntax elements */ |
2258 | | /* This is maintained seperately in s_high_profile */ |
2259 | | /********************************************************/ |
2260 | 0 | { |
2261 | |
|
2262 | 0 | ps_dec->s_high_profile.ps_transform8x8_flag = p_cabac_ctxt_table_t |
2263 | 0 | + TRANSFORM_SIZE_8X8_FLAG; |
2264 | |
|
2265 | 0 | ps_dec->s_high_profile.ps_sigcoeff_8x8_frame = p_cabac_ctxt_table_t |
2266 | 0 | + SIGNIFICANT_COEFF_FLAG_8X8_FRAME; |
2267 | |
|
2268 | 0 | ps_dec->s_high_profile.ps_last_sigcoeff_8x8_frame = |
2269 | 0 | p_cabac_ctxt_table_t |
2270 | 0 | + LAST_SIGNIFICANT_COEFF_FLAG_8X8_FRAME; |
2271 | |
|
2272 | 0 | ps_dec->s_high_profile.ps_coeff_abs_levelminus1 = |
2273 | 0 | p_cabac_ctxt_table_t + COEFF_ABS_LEVEL_MINUS1_8X8; |
2274 | |
|
2275 | 0 | ps_dec->s_high_profile.ps_sigcoeff_8x8_field = p_cabac_ctxt_table_t |
2276 | 0 | + SIGNIFICANT_COEFF_FLAG_8X8_FIELD; |
2277 | |
|
2278 | 0 | ps_dec->s_high_profile.ps_last_sigcoeff_8x8_field = |
2279 | 0 | p_cabac_ctxt_table_t |
2280 | 0 | + LAST_SIGNIFICANT_COEFF_FLAG_8X8_FIELD; |
2281 | 0 | } |
2282 | 0 | } |
2283 | 0 | return (i16_status); |
2284 | 0 | } |
2285 | | |
2286 | | /*! |
2287 | | ************************************************************************** |
2288 | | * \if Function name : ih264d_free_dynamic_bufs \endif |
2289 | | * |
2290 | | * \brief |
2291 | | * This function frees dynamic memory allocated by Decoder. |
2292 | | * |
2293 | | * \param ps_dec: Pointer to dec_struct_t. |
2294 | | * |
2295 | | * \return |
2296 | | * Returns i4_status as returned by MemManager. |
2297 | | * |
2298 | | ************************************************************************** |
2299 | | */ |
2300 | | WORD16 ih264d_free_dynamic_bufs(dec_struct_t * ps_dec) |
2301 | 0 | { |
2302 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_deblk_pic); |
2303 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_dec_mb_map); |
2304 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_recon_mb_map); |
2305 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu2_slice_num_map); |
2306 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dec_slice_buf); |
2307 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_frm_mb_info); |
2308 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pi2_coeff_data); |
2309 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_parse_mb_data); |
2310 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_parse_part_params); |
2311 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_deblk_top_mb); |
2312 | |
|
2313 | 0 | if(ps_dec->p_ctxt_inc_mb_map) |
2314 | 0 | { |
2315 | 0 | ps_dec->p_ctxt_inc_mb_map -= 1; |
2316 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->p_ctxt_inc_mb_map); |
2317 | 0 | } |
2318 | |
|
2319 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_mv_p[0]); |
2320 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_mv_p[1]); |
2321 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pred_pkd); |
2322 | 0 | { |
2323 | 0 | UWORD8 i; |
2324 | 0 | for(i = 0; i < MV_SCRATCH_BUFS; i++) |
2325 | 0 | { |
2326 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_mv_top_p[i]); |
2327 | 0 | } |
2328 | 0 | } |
2329 | |
|
2330 | 0 | if(ps_dec->pu1_y_intra_pred_line) |
2331 | 0 | { |
2332 | 0 | ps_dec->pu1_y_intra_pred_line -= MB_SIZE; |
2333 | 0 | } |
2334 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_y_intra_pred_line); |
2335 | |
|
2336 | 0 | if(ps_dec->pu1_u_intra_pred_line) |
2337 | 0 | { |
2338 | 0 | ps_dec->pu1_u_intra_pred_line -= MB_SIZE; |
2339 | 0 | } |
2340 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_u_intra_pred_line); |
2341 | |
|
2342 | 0 | if(ps_dec->pu1_v_intra_pred_line) |
2343 | 0 | { |
2344 | 0 | ps_dec->pu1_v_intra_pred_line -= MB_SIZE; |
2345 | 0 | } |
2346 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_v_intra_pred_line); |
2347 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_nbr_mb_row); |
2348 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_mv_bank_buf_base); |
2349 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_pic_buf_base); |
2350 | | |
2351 | | /* Free memory for mb_info maps */ |
2352 | 0 | if(ps_dec->u1_enable_mb_info) |
2353 | 0 | { |
2354 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_qp_map_base); |
2355 | 0 | PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_mb_type_map_base); |
2356 | 0 | } |
2357 | 0 | return 0; |
2358 | 0 | } |
2359 | | |
2360 | | /*! |
2361 | | ************************************************************************** |
2362 | | * \if Function name : ih264d_create_mv_bank \endif |
2363 | | * |
2364 | | * \brief |
2365 | | * This function creates MV bank. |
2366 | | * |
2367 | | * \param memType : Type of memory being handled |
2368 | | * 0: Display Buffer |
2369 | | * 1: Decoder Buffer |
2370 | | * 2: Internal Buffer |
2371 | | * \param u1_num_of_buf: Number of decode or display buffers. |
2372 | | * \param u4_wd : Frame width. |
2373 | | * \param u4_ht : Frame Height. |
2374 | | * \param ps_pic_buf_api : Pointer to Picture Buffer API. |
2375 | | * \param ih264d_dec_mem_manager : Memory manager utility supplied by system. |
2376 | | * |
2377 | | * \return |
2378 | | * 0 on Success and -1 on error |
2379 | | * |
2380 | | ************************************************************************** |
2381 | | */ |
2382 | | WORD32 ih264d_create_mv_bank(void *pv_dec, |
2383 | | UWORD32 ui_width, |
2384 | | UWORD32 ui_height) |
2385 | 0 | { |
2386 | 0 | UWORD8 i; |
2387 | 0 | UWORD32 col_flag_buffer_size, mvpred_buffer_size; |
2388 | 0 | UWORD8 *pu1_mv_buf_mgr_base, *pu1_mv_bank_base; |
2389 | 0 | col_mv_buf_t *ps_col_mv; |
2390 | 0 | mv_pred_t *ps_mv; |
2391 | 0 | UWORD8 *pu1_col_zero_flag_buf; |
2392 | 0 | dec_struct_t *ps_dec = (dec_struct_t *)pv_dec; |
2393 | 0 | WORD32 buf_ret; |
2394 | 0 | UWORD32 u4_num_bufs; |
2395 | 0 | UWORD8 *pu1_buf; |
2396 | 0 | WORD32 size; |
2397 | 0 | void *pv_mem_ctxt = ps_dec->pv_mem_ctxt; |
2398 | |
|
2399 | 0 | col_flag_buffer_size = ((ui_width * ui_height) >> 4); |
2400 | 0 | mvpred_buffer_size = sizeof(mv_pred_t) |
2401 | 0 | * ((ui_width * (ui_height + PAD_MV_BANK_ROW)) >> 4); |
2402 | |
|
2403 | 0 | ih264_buf_mgr_init((buf_mgr_t *)ps_dec->pv_mv_buf_mgr); |
2404 | |
|
2405 | 0 | ps_col_mv = ps_dec->ps_col_mv_base; |
2406 | |
|
2407 | 0 | { |
2408 | 0 | UWORD8 u1_num_ref_frames = ps_dec->u4_thumbnail_mode ? |
2409 | 0 | !ps_dec->ps_cur_sps->u1_frame_mbs_only_flag : |
2410 | 0 | ps_dec->ps_cur_sps->u1_num_ref_frames; |
2411 | 0 | u4_num_bufs = u1_num_ref_frames + 1; |
2412 | 0 | } |
2413 | |
|
2414 | 0 | u4_num_bufs = MIN(u4_num_bufs, ps_dec->u1_pic_bufs); |
2415 | 0 | if(!ps_dec->u4_thumbnail_mode) |
2416 | 0 | { |
2417 | 0 | u4_num_bufs = MAX(u4_num_bufs, 2); |
2418 | 0 | } |
2419 | 0 | pu1_buf = ps_dec->pu1_mv_bank_buf_base; |
2420 | 0 | for(i = 0 ; i < u4_num_bufs ; i++) |
2421 | 0 | { |
2422 | 0 | pu1_col_zero_flag_buf = pu1_buf; |
2423 | 0 | pu1_buf += ALIGN64(col_flag_buffer_size); |
2424 | |
|
2425 | 0 | ps_mv = (mv_pred_t *)pu1_buf; |
2426 | 0 | pu1_buf += ALIGN64(mvpred_buffer_size); |
2427 | |
|
2428 | 0 | memset(ps_mv, 0, ((ui_width * OFFSET_MV_BANK_ROW) >> 4) * sizeof(mv_pred_t)); |
2429 | 0 | ps_mv += (ui_width*OFFSET_MV_BANK_ROW) >> 4; |
2430 | |
|
2431 | 0 | ps_col_mv->pv_col_zero_flag = (void *)pu1_col_zero_flag_buf; |
2432 | 0 | ps_col_mv->pv_mv = (void *)ps_mv; |
2433 | 0 | buf_ret = ih264_buf_mgr_add((buf_mgr_t *)ps_dec->pv_mv_buf_mgr, ps_col_mv, i); |
2434 | 0 | if(0 != buf_ret) |
2435 | 0 | { |
2436 | 0 | ps_dec->i4_error_code = ERROR_BUF_MGR; |
2437 | 0 | return ERROR_BUF_MGR; |
2438 | 0 | } |
2439 | 0 | ps_col_mv++; |
2440 | 0 | } |
2441 | 0 | return OK; |
2442 | 0 | } |
2443 | | |
2444 | | void ih264d_unpack_coeff4x4_dc_4x4blk(tu_sblk4x4_coeff_data_t *ps_tu_4x4, |
2445 | | WORD16 *pi2_out_coeff_data, |
2446 | | UWORD8 *pu1_inv_scan) |
2447 | 110k | { |
2448 | 110k | UWORD16 u2_sig_coeff_map = ps_tu_4x4->u2_sig_coeff_map; |
2449 | 110k | WORD32 idx; |
2450 | 110k | WORD16 *pi2_coeff_data = &ps_tu_4x4->ai2_level[0]; |
2451 | | |
2452 | 269k | while(u2_sig_coeff_map) |
2453 | 158k | { |
2454 | 158k | idx = CLZ(u2_sig_coeff_map); |
2455 | | |
2456 | 158k | idx = 31 - idx; |
2457 | 158k | RESET_BIT(u2_sig_coeff_map,idx); |
2458 | | |
2459 | 158k | idx = pu1_inv_scan[idx]; |
2460 | 158k | pi2_out_coeff_data[idx] = *pi2_coeff_data++; |
2461 | | |
2462 | 158k | } |
2463 | 110k | } |