/src/libhevc/decoder/ihevcd_utils.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore |
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 | | /** |
19 | | ******************************************************************************* |
20 | | * @file |
21 | | * ihevcd_utils.c |
22 | | * |
23 | | * @brief |
24 | | * Contains miscellaneous utility functions such as init() etc |
25 | | * |
26 | | * @author |
27 | | * Harish |
28 | | * |
29 | | * @par List of Functions: |
30 | | * |
31 | | * @remarks |
32 | | * None |
33 | | * |
34 | | ******************************************************************************* |
35 | | */ |
36 | | /*****************************************************************************/ |
37 | | /* File Includes */ |
38 | | /*****************************************************************************/ |
39 | | #include <stdio.h> |
40 | | #include <stddef.h> |
41 | | #include <stdlib.h> |
42 | | #include <string.h> |
43 | | #include <assert.h> |
44 | | |
45 | | #include "ihevc_typedefs.h" |
46 | | #include "iv.h" |
47 | | #include "ivd.h" |
48 | | #include "ihevcd_cxa.h" |
49 | | #include "ithread.h" |
50 | | |
51 | | #include "ihevc_defs.h" |
52 | | #include "ihevc_debug.h" |
53 | | #include "ihevc_defs.h" |
54 | | #include "ihevc_error.h" |
55 | | #include "ihevc_structs.h" |
56 | | #include "ihevc_buf_mgr.h" |
57 | | #include "ihevc_dpb_mgr.h" |
58 | | #include "ihevc_macros.h" |
59 | | #include "ihevc_platform_macros.h" |
60 | | |
61 | | #include "ihevc_common_tables.h" |
62 | | #include "ihevc_buf_mgr.h" |
63 | | #include "ihevc_disp_mgr.h" |
64 | | #include "ihevc_cabac_tables.h" |
65 | | |
66 | | #include "ihevcd_defs.h" |
67 | | |
68 | | #include "ihevcd_function_selector.h" |
69 | | #include "ihevcd_structs.h" |
70 | | #include "ihevcd_error.h" |
71 | | #include "ihevcd_nal.h" |
72 | | #include "ihevcd_bitstream.h" |
73 | | #include "ihevcd_utils.h" |
74 | | #include "ihevcd_trace.h" |
75 | | #include "ihevcd_process_slice.h" |
76 | | #include "ihevcd_job_queue.h" |
77 | | #define MAX_DPB_PIC_BUF 6 |
78 | | |
79 | | /* Function declarations */ |
80 | | mv_buf_t* ihevcd_mv_mgr_get_poc(buf_mgr_t *ps_mv_buf_mgr, UWORD32 abs_poc); |
81 | | |
82 | | /** |
83 | | ******************************************************************************* |
84 | | * |
85 | | * @brief |
86 | | * Used to get level index for a given level |
87 | | * |
88 | | * @par Description: |
89 | | * Converts from level_idc (which is multiplied by 30) to an index that can be |
90 | | * used as a lookup. Also used to ignore invalid levels like 2.2 , 3.2 etc |
91 | | * |
92 | | * @param[in] level |
93 | | * Level of the stream |
94 | | * |
95 | | * @returns Level index for a given level |
96 | | * |
97 | | * @remarks |
98 | | * |
99 | | * |
100 | | ******************************************************************************* |
101 | | */ |
102 | | WORD32 ihevcd_get_lvl_idx(WORD32 level) |
103 | 0 | { |
104 | 0 | WORD32 lvl_idx = 0; |
105 | |
|
106 | 0 | if(level < IHEVC_LEVEL_20) |
107 | 0 | { |
108 | 0 | lvl_idx = 0; |
109 | 0 | } |
110 | 0 | else if(level >= IHEVC_LEVEL_20 && level < IHEVC_LEVEL_21) |
111 | 0 | { |
112 | 0 | lvl_idx = 1; |
113 | 0 | } |
114 | 0 | else if(level >= IHEVC_LEVEL_21 && level < IHEVC_LEVEL_30) |
115 | 0 | { |
116 | 0 | lvl_idx = 2; |
117 | 0 | } |
118 | 0 | else if(level >= IHEVC_LEVEL_30 && level < IHEVC_LEVEL_31) |
119 | 0 | { |
120 | 0 | lvl_idx = 3; |
121 | 0 | } |
122 | 0 | else if(level >= IHEVC_LEVEL_31 && level < IHEVC_LEVEL_40) |
123 | 0 | { |
124 | 0 | lvl_idx = 4; |
125 | 0 | } |
126 | 0 | else if(level >= IHEVC_LEVEL_40 && level < IHEVC_LEVEL_41) |
127 | 0 | { |
128 | 0 | lvl_idx = 5; |
129 | 0 | } |
130 | 0 | else if(level >= IHEVC_LEVEL_41 && level < IHEVC_LEVEL_50) |
131 | 0 | { |
132 | 0 | lvl_idx = 6; |
133 | 0 | } |
134 | 0 | else if(level >= IHEVC_LEVEL_50 && level < IHEVC_LEVEL_51) |
135 | 0 | { |
136 | 0 | lvl_idx = 7; |
137 | 0 | } |
138 | 0 | else if(level >= IHEVC_LEVEL_51 && level < IHEVC_LEVEL_52) |
139 | 0 | { |
140 | 0 | lvl_idx = 8; |
141 | 0 | } |
142 | 0 | else if(level >= IHEVC_LEVEL_52 && level < IHEVC_LEVEL_60) |
143 | 0 | { |
144 | 0 | lvl_idx = 9; |
145 | 0 | } |
146 | 0 | else if(level >= IHEVC_LEVEL_60 && level < IHEVC_LEVEL_61) |
147 | 0 | { |
148 | 0 | lvl_idx = 10; |
149 | 0 | } |
150 | 0 | else if(level >= IHEVC_LEVEL_61 && level < IHEVC_LEVEL_62) |
151 | 0 | { |
152 | 0 | lvl_idx = 11; |
153 | 0 | } |
154 | 0 | else if(level >= IHEVC_LEVEL_62) |
155 | 0 | { |
156 | 0 | lvl_idx = 12; |
157 | 0 | } |
158 | |
|
159 | 0 | return (lvl_idx); |
160 | 0 | } |
161 | | |
162 | | /** |
163 | | ******************************************************************************* |
164 | | * |
165 | | * @brief |
166 | | * Used to get reference picture buffer size for a given level and |
167 | | * and padding used |
168 | | * |
169 | | * @par Description: |
170 | | * Used to get reference picture buffer size for a given level and padding used |
171 | | * Each picture is padded on all four sides |
172 | | * |
173 | | * @param[in] pic_size |
174 | | * Mumber of luma samples (Width * Height) |
175 | | * |
176 | | * @param[in] level |
177 | | * Level |
178 | | * |
179 | | * @param[in] horz_pad |
180 | | * Total padding used in horizontal direction |
181 | | * |
182 | | * @param[in] vert_pad |
183 | | * Total padding used in vertical direction |
184 | | * |
185 | | * @returns Total picture buffer size |
186 | | * |
187 | | * @remarks |
188 | | * |
189 | | * |
190 | | ******************************************************************************* |
191 | | */ |
192 | | WORD32 ihevcd_get_total_pic_buf_size(codec_t *ps_codec, |
193 | | WORD32 wd, |
194 | | WORD32 ht) |
195 | 26.2k | { |
196 | 26.2k | WORD32 size; |
197 | 26.2k | WORD32 pixel_size = ps_codec->i4_pixel_size_y; |
198 | 26.2k | WORD32 num_luma_samples; |
199 | 26.2k | WORD32 max_dpb_size; |
200 | 26.2k | WORD32 num_samples; |
201 | | |
202 | | |
203 | 26.2k | sps_t *ps_sps = (ps_codec->s_parse.ps_sps_base + ps_codec->i4_sps_id); |
204 | | |
205 | | /* Get maximum number of buffers for the current picture size */ |
206 | 26.2k | max_dpb_size = ps_codec->u4_disable_ref_retention ? 0 : |
207 | 26.2k | ps_sps->ai1_sps_max_dec_pic_buffering[ps_sps->i1_sps_max_sub_layers - 1]; |
208 | | |
209 | 26.2k | if(!ps_codec->u4_disable_ref_retention && (ps_codec->e_frm_out_mode != IVD_DECODE_FRAME_OUT)) |
210 | 26.2k | max_dpb_size += ps_sps->ai1_sps_max_num_reorder_pics[ps_sps->i1_sps_max_sub_layers - 1]; |
211 | | |
212 | 26.2k | max_dpb_size++; |
213 | | /* Allocation is required for |
214 | | * (Wd + horz_pad) * (Ht + vert_pad) * (2 * max_dpb_size + 1) |
215 | | */ |
216 | | |
217 | | /* Account for padding area */ |
218 | 26.2k | num_luma_samples = (wd + PAD_WD) * (ht + PAD_HT); |
219 | | |
220 | | /* Account for chroma */ |
221 | 26.2k | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
222 | 1.55k | { |
223 | 1.55k | num_samples = num_luma_samples * 3; |
224 | 1.55k | } |
225 | 24.7k | else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) |
226 | 4.07k | { |
227 | 4.07k | num_samples = num_luma_samples * 2; |
228 | 4.07k | } |
229 | 20.6k | else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV420) |
230 | 20.1k | { |
231 | 20.1k | num_samples = num_luma_samples * 3 / 2; |
232 | 20.1k | } |
233 | 484 | else |
234 | 484 | { |
235 | 484 | num_samples = num_luma_samples; |
236 | 484 | } |
237 | | |
238 | | /* Number of bytes in reference pictures */ |
239 | 26.2k | size = num_samples * max_dpb_size; |
240 | | |
241 | | |
242 | | /* Account for bit depth of pixels */ |
243 | 26.2k | size *= pixel_size; |
244 | | |
245 | 26.2k | return size; |
246 | 26.2k | } |
247 | | /** |
248 | | ******************************************************************************* |
249 | | * |
250 | | * @brief |
251 | | * Used to get MV bank size for a given number of luma samples |
252 | | * |
253 | | * @par Description: |
254 | | * For given number of luma samples one MV bank size is computed |
255 | | * Each MV bank includes pu_map and pu_t for all the min PUs(4x4) in a picture |
256 | | * |
257 | | * @param[in] num_luma_samples |
258 | | * Max number of luma pixels in the frame |
259 | | * |
260 | | * @returns Total MV Bank size |
261 | | * |
262 | | * @remarks |
263 | | * |
264 | | * |
265 | | ******************************************************************************* |
266 | | */ |
267 | | WORD32 ihevcd_get_pic_mv_bank_size(WORD32 num_luma_samples) |
268 | 48.5k | { |
269 | 48.5k | WORD32 size; |
270 | | |
271 | 48.5k | WORD32 pic_size; |
272 | | |
273 | 48.5k | WORD32 mv_bank_size; |
274 | 48.5k | WORD32 num_pu; |
275 | 48.5k | WORD32 num_ctb; |
276 | 48.5k | pic_size = num_luma_samples; |
277 | | |
278 | | |
279 | 48.5k | num_pu = pic_size / (MIN_PU_SIZE * MIN_PU_SIZE); |
280 | 48.5k | num_ctb = pic_size / (MIN_CTB_SIZE * MIN_CTB_SIZE); |
281 | | |
282 | 48.5k | mv_bank_size = 0; |
283 | | |
284 | | /* Size for storing pu_t start index each CTB */ |
285 | | /* One extra entry is needed to compute number of PUs in the last CTB */ |
286 | 48.5k | mv_bank_size += (num_ctb + 1) * sizeof(WORD32); |
287 | | |
288 | | /* Size for pu_map */ |
289 | 48.5k | mv_bank_size += num_pu; |
290 | | |
291 | | /* Size for storing pu_t for each PU */ |
292 | 48.5k | mv_bank_size += num_pu * sizeof(pu_t); |
293 | | |
294 | | /* Size for storing slice_idx for each CTB */ |
295 | 48.5k | mv_bank_size += ALIGN4(num_ctb * sizeof(UWORD16)); |
296 | | |
297 | 48.5k | size = mv_bank_size; |
298 | 48.5k | return size; |
299 | 48.5k | } |
300 | | /** |
301 | | ******************************************************************************* |
302 | | * |
303 | | * @brief |
304 | | * Used to get TU data size for a given number luma samples |
305 | | * |
306 | | * @par Description: |
307 | | * For a given number of luma samples TU data size is computed |
308 | | * Each TU data includes tu_map and tu_t and coeff data for all |
309 | | * the min TUs(4x4) in given CTB |
310 | | * |
311 | | * @param[in] num_luma_samples |
312 | | * Number of 64 x 64 CTBs for which TU data has to be allocated. |
313 | | * |
314 | | * @returns Total TU data size |
315 | | * |
316 | | * @remarks Assumption is num_luma_samples will be at least |
317 | | * 64 x 64 to handle CTB of size 64 x 64. Can be frame size as well |
318 | | * |
319 | | ******************************************************************************* |
320 | | */ |
321 | | WORD32 ihevcd_get_tu_data_size(codec_t *ps_codec, WORD32 num_luma_samples) |
322 | 26.2k | { |
323 | | |
324 | 26.2k | sps_t *ps_sps = (ps_codec->s_parse.ps_sps_base + ps_codec->i4_sps_id); |
325 | 26.2k | WORD32 tu_data_size; |
326 | 26.2k | WORD32 num_ctb; |
327 | 26.2k | WORD32 num_luma_tu, num_chroma_tu, num_tu; |
328 | 26.2k | WORD32 num_chroma_sub_tu = 0; |
329 | 26.2k | num_ctb = num_luma_samples / (MIN_CTB_SIZE * MIN_CTB_SIZE); |
330 | | |
331 | 26.2k | num_luma_tu = num_luma_samples / (MIN_TU_SIZE * MIN_TU_SIZE); |
332 | | |
333 | 26.2k | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
334 | 1.55k | { |
335 | 1.55k | num_chroma_tu = num_luma_tu << 1; |
336 | 1.55k | } |
337 | 24.7k | else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) |
338 | 4.07k | { |
339 | 4.07k | num_chroma_tu = num_luma_tu >> 1; |
340 | 4.07k | num_chroma_sub_tu = num_luma_tu >> 1; |
341 | 4.07k | } |
342 | 20.6k | else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV420) |
343 | 20.1k | { |
344 | 20.1k | num_chroma_tu = num_luma_tu >> 1; |
345 | 20.1k | } |
346 | 484 | else |
347 | 484 | { |
348 | 484 | num_chroma_tu = 0; |
349 | 484 | } |
350 | | |
351 | 26.2k | num_tu = num_luma_tu + num_chroma_tu; |
352 | 26.2k | tu_data_size = 0; |
353 | | |
354 | | /* Size for storing tu_t start index each CTB */ |
355 | | /* One extra entry is needed to compute number of TUs in the last CTB */ |
356 | 26.2k | tu_data_size += (num_ctb + 1) * sizeof(WORD32); |
357 | | |
358 | | /* Size for storing tu map */ |
359 | 26.2k | tu_data_size += num_tu * sizeof(UWORD8); |
360 | | |
361 | | /* Size for storing tu_t for each TU */ |
362 | 26.2k | tu_data_size += num_tu * sizeof(tu_t); |
363 | | |
364 | | /* Size for storing number of coded subblocks and scan_idx for each TU */ |
365 | 26.2k | tu_data_size += (num_tu + num_chroma_sub_tu) * (sizeof(WORD8) + sizeof(WORD8)); |
366 | | |
367 | | /* Size for storing coeff data for each TU */ |
368 | 26.2k | tu_data_size += (num_tu + num_chroma_sub_tu) * sizeof(tu_sblk_coeff_data_t); |
369 | | |
370 | | |
371 | 26.2k | return tu_data_size; |
372 | 26.2k | } |
373 | | |
374 | | |
375 | | WORD32 ihevcd_nctb_cnt(codec_t *ps_codec, sps_t *ps_sps) |
376 | 89.4k | { |
377 | 89.4k | WORD32 nctb = 1; |
378 | 89.4k | UNUSED(ps_codec); |
379 | | //TODO: Currently set to 1 |
380 | | /* If CTB size is less than 32 x 32 then set nCTB as 4 */ |
381 | 89.4k | if(ps_sps->i1_log2_ctb_size < 5) |
382 | 8.66k | nctb = 1; |
383 | | |
384 | 89.4k | return nctb; |
385 | 89.4k | } |
386 | | |
387 | | IHEVCD_ERROR_T ihevcd_get_tile_pos(pps_t *ps_pps, |
388 | | sps_t *ps_sps, |
389 | | WORD32 ctb_x, |
390 | | WORD32 ctb_y, |
391 | | WORD32 *pi4_ctb_tile_x, |
392 | | WORD32 *pi4_ctb_tile_y, |
393 | | WORD32 *pi4_tile_idx) |
394 | 2.99M | { |
395 | | |
396 | 2.99M | tile_t *ps_tile_tmp; |
397 | 2.99M | WORD32 i; |
398 | 2.99M | WORD32 tile_row, tile_col; |
399 | | |
400 | 2.99M | if(ctb_x < 0 || ctb_y < 0) |
401 | 0 | { |
402 | 0 | *pi4_ctb_tile_x = 0; |
403 | 0 | *pi4_ctb_tile_y = 0; |
404 | 0 | *pi4_tile_idx = 0; |
405 | |
|
406 | 0 | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
407 | 0 | } |
408 | | |
409 | 2.99M | tile_row = 0; |
410 | 2.99M | tile_col = 0; |
411 | 2.99M | ps_tile_tmp = ps_pps->ps_tile; |
412 | 2.99M | if(0 == ps_pps->i1_tiles_enabled_flag) |
413 | 964k | { |
414 | 964k | *pi4_ctb_tile_x = ctb_x; |
415 | 964k | *pi4_ctb_tile_y = ctb_y; |
416 | 964k | *pi4_tile_idx = 0; |
417 | 964k | } |
418 | 2.02M | else |
419 | 2.02M | { |
420 | 42.1M | for(i = 0; i < ps_pps->i1_num_tile_columns; i++) |
421 | 42.1M | { |
422 | 42.1M | WORD16 next_tile_ctb_x; |
423 | 42.1M | ps_tile_tmp = ps_pps->ps_tile + i; //* ps_pps->i1_num_tile_rows; |
424 | 42.1M | if((ps_pps->i1_num_tile_columns - 1) == i) |
425 | 189k | { |
426 | 189k | next_tile_ctb_x = ps_sps->i2_pic_wd_in_ctb; |
427 | 189k | } |
428 | 41.9M | else |
429 | 41.9M | { |
430 | 41.9M | tile_t *ps_tile_next_tmp; |
431 | 41.9M | ps_tile_next_tmp = ps_pps->ps_tile + i + 1; |
432 | 41.9M | next_tile_ctb_x = ps_tile_next_tmp->u1_pos_x; |
433 | 41.9M | } |
434 | 42.1M | if((ctb_x >= ps_tile_tmp->u1_pos_x) && (ctb_x < next_tile_ctb_x)) |
435 | 2.02M | { |
436 | 2.02M | tile_col = i; |
437 | 2.02M | break; |
438 | 2.02M | } |
439 | 42.1M | } |
440 | 2.02M | *pi4_ctb_tile_x = ctb_x - ps_tile_tmp->u1_pos_x; |
441 | | |
442 | 8.81M | for(i = 0; i < ps_pps->i1_num_tile_rows; i++) |
443 | 8.81M | { |
444 | 8.81M | WORD16 next_tile_ctb_y; |
445 | 8.81M | ps_tile_tmp = ps_pps->ps_tile + i * ps_pps->i1_num_tile_columns; |
446 | 8.81M | if((ps_pps->i1_num_tile_rows - 1) == i) |
447 | 419k | { |
448 | 419k | next_tile_ctb_y = ps_sps->i2_pic_ht_in_ctb; |
449 | 419k | } |
450 | 8.39M | else |
451 | 8.39M | { |
452 | 8.39M | tile_t *ps_tile_next_tmp; |
453 | 8.39M | ps_tile_next_tmp = ps_pps->ps_tile + ((i + 1) * ps_pps->i1_num_tile_columns); |
454 | 8.39M | next_tile_ctb_y = ps_tile_next_tmp->u1_pos_y; |
455 | 8.39M | } |
456 | 8.81M | if((ctb_y >= ps_tile_tmp->u1_pos_y) && (ctb_y < next_tile_ctb_y)) |
457 | 2.02M | { |
458 | 2.02M | tile_row = i; |
459 | 2.02M | break; |
460 | 2.02M | } |
461 | | |
462 | 8.81M | } |
463 | 2.02M | *pi4_ctb_tile_y = ctb_y - ps_tile_tmp->u1_pos_y; |
464 | 2.02M | *pi4_tile_idx = tile_row * ps_pps->i1_num_tile_columns |
465 | 2.02M | + tile_col; |
466 | 2.02M | } |
467 | 2.99M | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
468 | 2.99M | } |
469 | | /** |
470 | | ******************************************************************************* |
471 | | * |
472 | | * @brief |
473 | | * Function to initialize ps_pic_buf structs add pic buffers to |
474 | | * buffer manager in case of non-shared mode |
475 | | * |
476 | | * @par Description: |
477 | | * Function to initialize ps_pic_buf structs add pic buffers to |
478 | | * buffer manager in case of non-shared mode |
479 | | * To be called once per stream or for every reset |
480 | | * |
481 | | * @param[in] ps_codec |
482 | | * Pointer to codec context |
483 | | * |
484 | | * @returns Error from IHEVCD_ERROR_T |
485 | | * |
486 | | * @remarks |
487 | | * |
488 | | * |
489 | | ******************************************************************************* |
490 | | */ |
491 | | IHEVCD_ERROR_T ihevcd_pic_buf_mgr_add_bufs(codec_t *ps_codec) |
492 | 22.1k | { |
493 | 22.1k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
494 | 22.1k | WORD32 i; |
495 | 22.1k | WORD32 max_dpb_size; |
496 | 22.1k | sps_t *ps_sps; |
497 | 22.1k | UWORD8 *pu1_buf; |
498 | 22.1k | pic_buf_t *ps_pic_buf; |
499 | 22.1k | WORD32 pic_buf_size_allocated; |
500 | 22.1k | WORD32 h_samp_factor, v_samp_factor; |
501 | 22.1k | WORD32 chroma_pixel_strd = 2; |
502 | | |
503 | 22.1k | WORD32 pixel_size_y; |
504 | 22.1k | WORD32 pixel_size_uv; |
505 | | |
506 | | /* Derive the pixel size for luma and chroma */ |
507 | 22.1k | pixel_size_y = ps_codec->i4_pixel_size_y; |
508 | 22.1k | pixel_size_uv = ps_codec->i4_pixel_size_uv; |
509 | | |
510 | | |
511 | | /* Initialize Pic buffer manager */ |
512 | 22.1k | ps_sps = ps_codec->s_parse.ps_sps; |
513 | | |
514 | 22.1k | h_samp_factor = (CHROMA_FMT_IDC_YUV444 == ps_sps->i1_chroma_format_idc) ? 1 : 2; |
515 | 22.1k | v_samp_factor = (CHROMA_FMT_IDC_YUV420 == ps_sps->i1_chroma_format_idc) ? 2 : 1; |
516 | | |
517 | | /* Compute the number of Pic buffers needed */ |
518 | 22.1k | max_dpb_size = ps_codec->u4_disable_ref_retention ? 0 : |
519 | 22.1k | ps_sps->ai1_sps_max_dec_pic_buffering[ps_sps->i1_sps_max_sub_layers - 1]; |
520 | | |
521 | 22.1k | if(!ps_codec->u4_disable_ref_retention && (ps_codec->e_frm_out_mode != IVD_DECODE_FRAME_OUT)) |
522 | 22.1k | max_dpb_size += ps_sps->ai1_sps_max_num_reorder_pics[ps_sps->i1_sps_max_sub_layers - 1]; |
523 | | |
524 | | /* Allocate one extra picture to handle current frame |
525 | | * In case of asynchronous parsing and processing, number of buffers should increase here |
526 | | * based on when parsing and processing threads are synchronized |
527 | | */ |
528 | 22.1k | max_dpb_size++; |
529 | | |
530 | | |
531 | 22.1k | pu1_buf = (UWORD8 *)ps_codec->pu1_ref_pic_buf_base; |
532 | | |
533 | 22.1k | ps_pic_buf = (pic_buf_t *)ps_codec->ps_pic_buf; |
534 | | |
535 | | /* In case of non-shared mode, add picture buffers to buffer manager |
536 | | * In case of shared mode buffers are added in the run-time |
537 | | */ |
538 | 22.1k | if(0 == ps_codec->i4_share_disp_buf) |
539 | 22.1k | { |
540 | 22.1k | WORD32 buf_ret; |
541 | 22.1k | WORD32 luma_samples; |
542 | 22.1k | WORD32 chroma_samples; |
543 | 22.1k | pic_buf_size_allocated = ps_codec->i4_total_pic_buf_size; |
544 | | |
545 | 22.1k | luma_samples = (ps_codec->i4_strd * pixel_size_y) * |
546 | 22.1k | (ps_sps->i2_pic_height_in_luma_samples + PAD_HT); |
547 | | |
548 | 22.1k | if(CHROMA_FMT_IDC_MONOCHROME == ps_sps->i1_chroma_format_idc) |
549 | 329 | { |
550 | 329 | chroma_samples = 0; |
551 | 329 | } |
552 | 21.8k | else |
553 | 21.8k | { |
554 | 21.8k | chroma_samples = luma_samples * 2 / (h_samp_factor * v_samp_factor); |
555 | 21.8k | } |
556 | | |
557 | | /* Try to add as many buffers as possible since memory is already allocated */ |
558 | | /* If the number of buffers that can be added is less than max_num_bufs |
559 | | * return with an error. |
560 | | */ |
561 | 110k | for(i = 0; i < max_dpb_size; i++) |
562 | 88.5k | { |
563 | 88.5k | pic_buf_size_allocated -= (luma_samples + chroma_samples); |
564 | | |
565 | 88.5k | if(pic_buf_size_allocated < 0) |
566 | 100 | { |
567 | 100 | ps_codec->s_parse.i4_error_code = IHEVCD_INSUFFICIENT_MEM_PICBUF; |
568 | 100 | return IHEVCD_INSUFFICIENT_MEM_PICBUF; |
569 | 100 | } |
570 | | |
571 | 88.4k | ps_pic_buf->pu1_luma = pu1_buf + (ps_codec->i4_strd * PAD_TOP + PAD_LEFT) * pixel_size_y; |
572 | 88.4k | pu1_buf += luma_samples; |
573 | | |
574 | 88.4k | if(chroma_samples) |
575 | 87.0k | { |
576 | 87.0k | ps_pic_buf->pu1_chroma = pu1_buf |
577 | 87.0k | + ((ps_codec->i4_strd * chroma_pixel_strd / h_samp_factor) * (PAD_TOP / v_samp_factor) |
578 | 87.0k | + (PAD_LEFT * chroma_pixel_strd / h_samp_factor)) * pixel_size_uv; |
579 | 87.0k | pu1_buf += chroma_samples; |
580 | 87.0k | } |
581 | 1.33k | else |
582 | 1.33k | { |
583 | 1.33k | ps_pic_buf->pu1_chroma = NULL; |
584 | 1.33k | } |
585 | | |
586 | | /* Pad boundary pixels (one pixel on all sides) */ |
587 | | /* This ensures SAO does not read uninitialized pixels */ |
588 | | /* Note these are not used in actual processing */ |
589 | 88.4k | { |
590 | 88.4k | UWORD8 *pu1_buf; |
591 | 88.4k | WORD32 strd, wd, ht; |
592 | 88.4k | WORD32 i; |
593 | 88.4k | strd = ps_codec->i4_strd; |
594 | 88.4k | wd = ps_codec->i4_wd; |
595 | 88.4k | ht = ps_codec->i4_ht; |
596 | | |
597 | 88.4k | pu1_buf = ps_pic_buf->pu1_luma; |
598 | 38.7M | for(i = 0; i < ht; i++) |
599 | 38.6M | { |
600 | 38.6M | pu1_buf[-1] = 0; |
601 | 38.6M | pu1_buf[wd] = 0; |
602 | 38.6M | pu1_buf += strd; |
603 | 38.6M | } |
604 | 88.4k | pu1_buf = ps_pic_buf->pu1_luma; |
605 | 88.4k | memset(pu1_buf - strd - 1, 0, wd + 2); |
606 | | |
607 | 88.4k | pu1_buf += strd * ht; |
608 | 88.4k | memset(pu1_buf - 1, 0, wd + 2); |
609 | | |
610 | 88.4k | if(ps_pic_buf->pu1_chroma) |
611 | 87.0k | { |
612 | 87.0k | pu1_buf = ps_pic_buf->pu1_chroma; |
613 | 87.0k | ht /= v_samp_factor; |
614 | 87.0k | WORD32 chroma_strd_scale = chroma_pixel_strd / h_samp_factor; |
615 | 21.9M | for(i = 0; i < ht; i++) |
616 | 21.8M | { |
617 | 21.8M | pu1_buf[-1] = 0; |
618 | 21.8M | pu1_buf[-2] = 0; |
619 | 21.8M | pu1_buf[wd * chroma_strd_scale] = 0; |
620 | 21.8M | pu1_buf[wd * chroma_strd_scale + 1] = 0; |
621 | 21.8M | pu1_buf += (strd * chroma_strd_scale); |
622 | 21.8M | } |
623 | 87.0k | pu1_buf = ps_pic_buf->pu1_chroma; |
624 | 87.0k | memset(pu1_buf - (strd * chroma_strd_scale) - 2, 0, wd * chroma_strd_scale + 4); |
625 | | |
626 | 87.0k | pu1_buf += (strd * chroma_strd_scale) * ht; |
627 | 87.0k | memset(pu1_buf - 2, 0, wd * chroma_strd_scale + 4); |
628 | 87.0k | } |
629 | 88.4k | } |
630 | | |
631 | 88.4k | buf_ret = ihevc_buf_mgr_add((buf_mgr_t *)ps_codec->pv_pic_buf_mgr, ps_pic_buf, i); |
632 | | |
633 | | |
634 | 88.4k | if(0 != buf_ret) |
635 | 0 | { |
636 | 0 | ps_codec->s_parse.i4_error_code = IHEVCD_BUF_MGR_ERROR; |
637 | 0 | return IHEVCD_BUF_MGR_ERROR; |
638 | 0 | } |
639 | 88.4k | ps_pic_buf++; |
640 | 88.4k | } |
641 | 22.1k | } |
642 | 0 | else |
643 | 0 | { |
644 | | /* In case of shared mode, buffers are added without adjusting for padding. |
645 | | Update luma and chroma pointers here to account for padding as per stride. |
646 | | In some cases stride might not be available when set_display_frame is called. |
647 | | Hence updated luma and chroma pointers here */ |
648 | |
|
649 | 0 | for(i = 0; i < BUF_MGR_MAX_CNT; i++) |
650 | 0 | { |
651 | 0 | ps_pic_buf = ihevc_buf_mgr_get_buf((buf_mgr_t *)ps_codec->pv_pic_buf_mgr, i); |
652 | 0 | if((NULL == ps_pic_buf) || |
653 | 0 | (NULL == ps_pic_buf->pu1_luma) || |
654 | 0 | (NULL == ps_pic_buf->pu1_chroma)) |
655 | 0 | { |
656 | 0 | break; |
657 | 0 | } |
658 | 0 | ps_pic_buf->pu1_luma += (ps_codec->i4_strd * PAD_TOP + PAD_LEFT) * pixel_size_y; |
659 | 0 | ps_pic_buf->pu1_chroma += ((ps_codec->i4_strd * chroma_pixel_strd / h_samp_factor) * (PAD_TOP / v_samp_factor) |
660 | 0 | + (PAD_LEFT * chroma_pixel_strd / h_samp_factor)) * pixel_size_uv; |
661 | 0 | } |
662 | 0 | } |
663 | | |
664 | 22.0k | return ret; |
665 | 22.1k | } |
666 | | /** |
667 | | ******************************************************************************* |
668 | | * |
669 | | * @brief |
670 | | * Function to add buffers to MV Bank buffer manager |
671 | | * |
672 | | * @par Description: |
673 | | * Function to add buffers to MV Bank buffer manager |
674 | | * To be called once per stream or for every reset |
675 | | * |
676 | | * @param[in] ps_codec |
677 | | * Pointer to codec context |
678 | | * |
679 | | * @returns Error from IHEVCD_ERROR_T |
680 | | * |
681 | | * @remarks |
682 | | * |
683 | | * |
684 | | ******************************************************************************* |
685 | | */ |
686 | | IHEVCD_ERROR_T ihevcd_mv_buf_mgr_add_bufs(codec_t *ps_codec) |
687 | 22.2k | { |
688 | 22.2k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
689 | 22.2k | WORD32 i; |
690 | 22.2k | WORD32 max_dpb_size; |
691 | 22.2k | WORD32 mv_bank_size_allocated; |
692 | 22.2k | WORD32 pic_mv_bank_size; |
693 | | |
694 | 22.2k | sps_t *ps_sps; |
695 | 22.2k | UWORD8 *pu1_buf; |
696 | 22.2k | mv_buf_t *ps_mv_buf; |
697 | | |
698 | | |
699 | | /* Initialize MV Bank buffer manager */ |
700 | 22.2k | ps_sps = ps_codec->s_parse.ps_sps; |
701 | | |
702 | | |
703 | | /* Compute the number of MV Bank buffers needed */ |
704 | 22.2k | max_dpb_size = ps_codec->u4_disable_ref_retention ? 0 : |
705 | 22.2k | ps_sps->ai1_sps_max_dec_pic_buffering[ps_sps->i1_sps_max_sub_layers - 1]; |
706 | | |
707 | | /* Allocate one extra MV Bank to handle current frame |
708 | | * In case of asynchronous parsing and processing, number of buffers should increase here |
709 | | * based on when parsing and processing threads are synchronized |
710 | | */ |
711 | 22.2k | max_dpb_size++; |
712 | | |
713 | 22.2k | ps_codec->i4_max_dpb_size = max_dpb_size; |
714 | | |
715 | 22.2k | pu1_buf = (UWORD8 *)ps_codec->pv_mv_bank_buf_base; |
716 | | |
717 | 22.2k | ps_mv_buf = (mv_buf_t *)pu1_buf; |
718 | 22.2k | pu1_buf += max_dpb_size * sizeof(mv_buf_t); |
719 | 22.2k | ps_codec->ps_mv_buf = ps_mv_buf; |
720 | 22.2k | mv_bank_size_allocated = ps_codec->i4_total_mv_bank_size - max_dpb_size * sizeof(mv_buf_t); |
721 | | |
722 | | /* Compute MV bank size per picture */ |
723 | 22.2k | pic_mv_bank_size = ihevcd_get_pic_mv_bank_size(ALIGN64(ps_sps->i2_pic_width_in_luma_samples) * |
724 | 22.2k | ALIGN64(ps_sps->i2_pic_height_in_luma_samples)); |
725 | | |
726 | 107k | for(i = 0; i < max_dpb_size; i++) |
727 | 85.0k | { |
728 | 85.0k | WORD32 buf_ret; |
729 | 85.0k | WORD32 num_pu; |
730 | 85.0k | WORD32 num_ctb; |
731 | 85.0k | WORD32 pic_size; |
732 | 85.0k | pic_size = ALIGN64(ps_sps->i2_pic_width_in_luma_samples) * |
733 | 85.0k | ALIGN64(ps_sps->i2_pic_height_in_luma_samples); |
734 | | |
735 | | |
736 | 85.0k | num_pu = pic_size / (MIN_PU_SIZE * MIN_PU_SIZE); |
737 | 85.0k | num_ctb = pic_size / (MIN_CTB_SIZE * MIN_CTB_SIZE); |
738 | | |
739 | | |
740 | 85.0k | mv_bank_size_allocated -= pic_mv_bank_size; |
741 | | |
742 | 85.0k | if(mv_bank_size_allocated < 0) |
743 | 78 | { |
744 | 78 | ps_codec->s_parse.i4_error_code = IHEVCD_INSUFFICIENT_MEM_MVBANK; |
745 | 78 | return IHEVCD_INSUFFICIENT_MEM_MVBANK; |
746 | 78 | } |
747 | | |
748 | 84.9k | ps_mv_buf->pu4_pic_pu_idx = (UWORD32 *)pu1_buf; |
749 | 84.9k | pu1_buf += (num_ctb + 1) * sizeof(WORD32); |
750 | | |
751 | 84.9k | ps_mv_buf->pu1_pic_pu_map = pu1_buf; |
752 | 84.9k | pu1_buf += num_pu; |
753 | | |
754 | 84.9k | ps_mv_buf->pu1_pic_slice_map = (UWORD16 *)pu1_buf; |
755 | 84.9k | pu1_buf += ALIGN4(num_ctb * sizeof(UWORD16)); |
756 | | |
757 | 84.9k | ps_mv_buf->ps_pic_pu = (pu_t *)pu1_buf; |
758 | 84.9k | pu1_buf += num_pu * sizeof(pu_t); |
759 | | |
760 | 84.9k | buf_ret = ihevc_buf_mgr_add((buf_mgr_t *)ps_codec->pv_mv_buf_mgr, ps_mv_buf, i); |
761 | | |
762 | 84.9k | if(0 != buf_ret) |
763 | 0 | { |
764 | 0 | ps_codec->s_parse.i4_error_code = IHEVCD_BUF_MGR_ERROR; |
765 | 0 | return IHEVCD_BUF_MGR_ERROR; |
766 | 0 | } |
767 | | |
768 | 84.9k | ps_mv_buf++; |
769 | | |
770 | 84.9k | } |
771 | 22.1k | return ret; |
772 | 22.2k | } |
773 | | /** |
774 | | ******************************************************************************* |
775 | | * |
776 | | * @brief |
777 | | * Output buffer check |
778 | | * |
779 | | * @par Description: |
780 | | * Check for the number of buffers and buffer sizes of output buffer |
781 | | * |
782 | | * @param[in] ps_codec |
783 | | * Pointer to codec context |
784 | | * |
785 | | * @returns Error from IHEVCD_ERROR_T |
786 | | * |
787 | | * @remarks |
788 | | * |
789 | | * |
790 | | ******************************************************************************* |
791 | | */ |
792 | | IHEVCD_ERROR_T ihevcd_check_out_buf_size(codec_t *ps_codec) |
793 | 90.3k | { |
794 | 90.3k | ivd_out_bufdesc_t *ps_out_buffer = ps_codec->ps_out_buffer; |
795 | 90.3k | UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS]; |
796 | 90.3k | UWORD32 u4_min_num_out_bufs = 0, i; |
797 | 90.3k | UWORD32 wd, ht; |
798 | 90.3k | UWORD32 aligned_wd, aligned_ht; |
799 | 90.3k | WORD32 pixel_size_y = ps_codec->i4_pixel_size_y; |
800 | 90.3k | WORD32 pixel_size_uv = ps_codec->i4_pixel_size_uv; |
801 | | |
802 | 90.3k | if(0 == ps_codec->i4_share_disp_buf) |
803 | 90.3k | { |
804 | 90.3k | wd = ps_codec->i4_disp_wd; |
805 | 90.3k | ht = ps_codec->i4_disp_ht; |
806 | 90.3k | } |
807 | 0 | else |
808 | 0 | { |
809 | | /* In case of shared mode, do not check validity of ps_codec->ps_out_buffer */ |
810 | 0 | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
811 | 0 | } |
812 | | |
813 | 90.3k | if(ps_codec->i4_disp_strd > (WORD32)wd) |
814 | 0 | wd = ps_codec->i4_disp_strd; |
815 | | |
816 | 90.3k | if(ps_codec->e_chroma_fmt == IV_YUV_420P) |
817 | 41.8k | u4_min_num_out_bufs = MIN_OUT_BUFS_420; |
818 | 48.5k | else if(ps_codec->e_chroma_fmt == IV_YUV_444P) |
819 | 9.58k | u4_min_num_out_bufs = MIN_OUT_BUFS_444; |
820 | 38.9k | else if(ps_codec->e_chroma_fmt == IV_YUV_422P) |
821 | 2.46k | u4_min_num_out_bufs = MIN_OUT_BUFS_422; |
822 | 36.4k | else if((ps_codec->e_chroma_fmt == IV_YUV_420SP_UV) |
823 | 24.2k | || (ps_codec->e_chroma_fmt == IV_YUV_420SP_VU)) |
824 | 22.2k | u4_min_num_out_bufs = MIN_OUT_BUFS_420SP; |
825 | 14.1k | else if(ps_codec->e_chroma_fmt == IV_GRAY) |
826 | 14.1k | u4_min_num_out_bufs = MIN_OUT_BUFS_GRAY; |
827 | | |
828 | 90.3k | aligned_wd = ALIGN2(wd); |
829 | 90.3k | aligned_ht = ALIGN2(ht); |
830 | 90.3k | if(ps_codec->e_chroma_fmt == IV_YUV_420P) |
831 | 41.8k | { |
832 | 41.8k | au4_min_out_buf_size[0] = (wd * ht) * pixel_size_y; |
833 | 41.8k | au4_min_out_buf_size[1] = ((aligned_wd * aligned_ht) >> 2) * pixel_size_uv; |
834 | 41.8k | au4_min_out_buf_size[2] = ((aligned_wd * aligned_ht) >> 2) * pixel_size_uv; |
835 | 41.8k | } |
836 | 48.5k | else if(ps_codec->e_chroma_fmt == IV_YUV_444P) |
837 | 9.58k | { |
838 | 9.58k | au4_min_out_buf_size[0] = (wd * ht) * pixel_size_y; |
839 | 9.58k | au4_min_out_buf_size[1] = (wd * ht) * pixel_size_uv; |
840 | 9.58k | au4_min_out_buf_size[2] = (wd * ht) * pixel_size_uv; |
841 | 9.58k | } |
842 | 38.9k | else if((ps_codec->e_chroma_fmt == IV_YUV_420SP_UV) |
843 | 26.6k | || (ps_codec->e_chroma_fmt == IV_YUV_420SP_VU)) |
844 | 22.2k | { |
845 | 22.2k | au4_min_out_buf_size[0] = (wd * ht) * pixel_size_y; |
846 | 22.2k | au4_min_out_buf_size[1] = ((aligned_wd * aligned_ht) >> 1) * pixel_size_uv; |
847 | 22.2k | au4_min_out_buf_size[2] = 0; |
848 | 22.2k | } |
849 | 16.6k | else if(ps_codec->e_chroma_fmt == IV_GRAY) |
850 | 14.1k | { |
851 | 14.1k | au4_min_out_buf_size[0] = (wd * ht) * pixel_size_y; |
852 | 14.1k | au4_min_out_buf_size[1] = 0; |
853 | 14.1k | au4_min_out_buf_size[2] = 0; |
854 | 14.1k | } |
855 | 2.46k | else if(ps_codec->e_chroma_fmt == IV_YUV_422P) |
856 | 2.46k | { |
857 | 2.46k | au4_min_out_buf_size[0] = (wd * ht) * pixel_size_y; |
858 | 2.46k | au4_min_out_buf_size[1] = ((aligned_wd * ht) >> 1) * pixel_size_uv; |
859 | 2.46k | au4_min_out_buf_size[2] = ((aligned_wd * ht) >> 1) * pixel_size_uv; |
860 | 2.46k | } |
861 | | |
862 | | |
863 | 90.3k | if(ps_out_buffer->u4_num_bufs < u4_min_num_out_bufs) |
864 | 0 | { |
865 | 0 | return (IHEVCD_ERROR_T)IV_FAIL; |
866 | 0 | } |
867 | | |
868 | 309k | for (i = 0 ; i < u4_min_num_out_bufs; i++) |
869 | 219k | { |
870 | 219k | if(ps_out_buffer->u4_min_out_buf_size[i] < au4_min_out_buf_size[i]) |
871 | 490 | { |
872 | 490 | return (IHEVCD_ERROR_T)IV_FAIL; |
873 | 490 | } |
874 | 219k | } |
875 | | |
876 | 89.8k | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
877 | 90.3k | } |
878 | | |
879 | | /** |
880 | | ******************************************************************************* |
881 | | * |
882 | | * @brief |
883 | | * Picture level initializations required during parsing |
884 | | * |
885 | | * @par Description: |
886 | | * Initialize picture level context variables during parsing Initialize mv |
887 | | * bank buffer manager in the first init call |
888 | | * |
889 | | * @param[in] ps_codec |
890 | | * Pointer to codec context |
891 | | * |
892 | | * @returns Error from IHEVCD_ERROR_T |
893 | | * |
894 | | * @remarks |
895 | | * |
896 | | * |
897 | | ******************************************************************************* |
898 | | */ |
899 | | IHEVCD_ERROR_T ihevcd_parse_pic_init(codec_t *ps_codec) |
900 | 90.5k | { |
901 | 90.5k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
902 | 90.5k | mv_buf_t *ps_mv_buf; |
903 | 90.5k | sps_t *ps_sps; |
904 | 90.5k | WORD32 num_min_cu; |
905 | 90.5k | WORD32 cur_pic_buf_id; |
906 | 90.5k | WORD32 cur_mv_bank_buf_id; |
907 | 90.5k | pic_buf_t *ps_cur_pic; |
908 | 90.5k | slice_header_t *ps_slice_hdr; |
909 | 90.5k | UWORD8 *pu1_cur_pic_luma, *pu1_cur_pic_chroma; |
910 | 90.5k | WORD32 h_samp_factor, v_samp_factor; |
911 | 90.5k | WORD32 chroma_pixel_strd = 2; |
912 | 90.5k | WORD32 i; |
913 | | |
914 | 90.5k | ps_codec->s_parse.i4_error_code = IHEVCD_SUCCESS; |
915 | 90.5k | ps_sps = ps_codec->s_parse.ps_sps; |
916 | 90.5k | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr; |
917 | | |
918 | | /* Memset picture level intra map and transquant bypass map to zero */ |
919 | 90.5k | num_min_cu = ((ps_sps->i2_pic_height_in_luma_samples + 7) / 8) * ((ps_sps->i2_pic_width_in_luma_samples + 63) / 64); |
920 | 90.5k | memset(ps_codec->s_parse.pu1_pic_intra_flag, 0, num_min_cu); |
921 | 90.5k | memset(ps_codec->s_parse.pu1_pic_no_loop_filter_flag, 0, num_min_cu); |
922 | | |
923 | 90.5k | h_samp_factor = (CHROMA_FMT_IDC_YUV444 == ps_sps->i1_chroma_format_idc) ? 1 : 2; |
924 | 90.5k | v_samp_factor = (CHROMA_FMT_IDC_YUV420 == ps_sps->i1_chroma_format_idc) ? 2 : 1; |
925 | | |
926 | 90.5k | if(0 == ps_codec->s_parse.i4_first_pic_init) |
927 | 22.2k | { |
928 | 22.2k | ret = ihevcd_mv_buf_mgr_add_bufs(ps_codec); |
929 | 22.2k | RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); |
930 | | |
931 | 22.1k | ret = ihevcd_pic_buf_mgr_add_bufs(ps_codec); |
932 | 22.1k | RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); |
933 | | |
934 | 22.0k | ps_codec->s_parse.i4_first_pic_init = 1; |
935 | 22.0k | } |
936 | | |
937 | | /* Output buffer check */ |
938 | 90.3k | ret = ihevcd_check_out_buf_size(ps_codec); |
939 | 90.3k | RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); |
940 | | |
941 | | /* Initialize all the slice headers' slice addresses to zero */ |
942 | 89.8k | { |
943 | 89.8k | WORD32 slice_idx; |
944 | 89.8k | WORD32 slice_start_idx; |
945 | | |
946 | 89.8k | slice_start_idx = (ps_codec->i4_slice_error && !ps_slice_hdr->i1_first_slice_in_pic_flag) ? 2 : 1; |
947 | | |
948 | 22.9M | for(slice_idx = slice_start_idx; slice_idx < MAX_SLICE_HDR_CNT; slice_idx++) |
949 | 22.9M | { |
950 | 22.9M | slice_header_t *ps_slice_hdr_tmp = ps_codec->ps_slice_hdr_base + slice_idx; |
951 | 22.9M | ps_slice_hdr_tmp->i2_ctb_x = -1; |
952 | 22.9M | ps_slice_hdr_tmp->i2_ctb_y = -1; |
953 | | |
954 | 22.9M | } |
955 | 89.8k | } |
956 | | |
957 | | /* Get free MV Bank to hold current picture's motion vector data */ |
958 | 89.8k | { |
959 | 89.8k | ps_mv_buf = (mv_buf_t *)ihevc_buf_mgr_get_next_free((buf_mgr_t *)ps_codec->pv_mv_buf_mgr, &cur_mv_bank_buf_id); |
960 | | |
961 | | /* If there are no free buffers then return with an error code. |
962 | | * If the buffer is to be freed by another thread , change the |
963 | | * following to call thread yield and wait for buffer to be freed |
964 | | */ |
965 | 89.8k | if(NULL == ps_mv_buf) |
966 | 420 | { |
967 | 420 | ps_codec->s_parse.i4_error_code = IHEVCD_NO_FREE_MVBANK; |
968 | 420 | ps_codec->i4_error_code = IHEVCD_NO_FREE_MVBANK; |
969 | 420 | return IHEVCD_NO_FREE_MVBANK; |
970 | 420 | } |
971 | | |
972 | 89.4k | ps_codec->s_parse.ps_cur_mv_buf = ps_mv_buf; |
973 | | /* Set current ABS poc to ps_mv_buf, so that while freeing a reference buffer |
974 | | * corresponding mv buffer can be found by looping through ps_codec->ps_mv_buf array |
975 | | * and getting a buffer id to free |
976 | | */ |
977 | 89.4k | ps_mv_buf->i4_abs_poc = ps_slice_hdr->i4_abs_pic_order_cnt; |
978 | 89.4k | } |
979 | | |
980 | | /* Get free picture buffer to hold current picture recon data */ |
981 | | /* TODO: For asynchronous api the following initializations related to picture |
982 | | * buffer should be moved to processing side |
983 | | */ |
984 | 0 | { |
985 | | |
986 | 89.4k | UWORD8 *pu1_buf; |
987 | 89.4k | ps_cur_pic = (pic_buf_t *)ihevc_buf_mgr_get_next_free((buf_mgr_t *)ps_codec->pv_pic_buf_mgr, &cur_pic_buf_id); |
988 | | |
989 | | /* If there are no free buffers then return with an error code. |
990 | | * TODO: If the buffer is to be freed by another thread , change the |
991 | | * following to call thread yield and wait for buffer to be freed |
992 | | */ |
993 | 89.4k | if(NULL == ps_cur_pic) |
994 | 39 | { |
995 | 39 | ps_codec->s_parse.i4_error_code = IHEVCD_NO_FREE_PICBUF; |
996 | 39 | ps_codec->i4_error_code = IHEVCD_NO_FREE_PICBUF; |
997 | 39 | return IHEVCD_NO_FREE_PICBUF; |
998 | 39 | } |
999 | | |
1000 | | /* Store input timestamp sent with input buffer */ |
1001 | 89.4k | ps_cur_pic->u4_ts = ps_codec->u4_ts; |
1002 | 89.4k | ps_cur_pic->i4_abs_poc = ps_slice_hdr->i4_abs_pic_order_cnt; |
1003 | 89.4k | ps_cur_pic->i4_poc_lsb = ps_slice_hdr->i4_pic_order_cnt_lsb; |
1004 | 89.4k | if((NAL_IDR_W_LP == ps_slice_hdr->i1_nal_unit_type) || |
1005 | 71.7k | (NAL_IDR_N_LP == ps_slice_hdr->i1_nal_unit_type)) |
1006 | 66.1k | { |
1007 | 66.1k | ps_codec->e_dec_pic_type = IV_IDR_FRAME; |
1008 | 66.1k | } |
1009 | 23.2k | else if(ISLICE == ps_slice_hdr->i1_slice_type) |
1010 | 9.70k | { |
1011 | 9.70k | ps_codec->e_dec_pic_type = IV_I_FRAME; |
1012 | 9.70k | } |
1013 | 13.5k | else if(PSLICE == ps_slice_hdr->i1_slice_type) |
1014 | 951 | { |
1015 | 951 | ps_codec->e_dec_pic_type = IV_P_FRAME; |
1016 | 951 | } |
1017 | 12.6k | else if(BSLICE == ps_slice_hdr->i1_slice_type) |
1018 | 12.6k | { |
1019 | 12.6k | ps_codec->e_dec_pic_type = IV_B_FRAME; |
1020 | 12.6k | } |
1021 | 0 | else |
1022 | 0 | { |
1023 | 0 | ps_codec->e_dec_pic_type = IV_NA_FRAME; |
1024 | 0 | } |
1025 | 89.4k | pu1_buf = ps_cur_pic->pu1_luma; |
1026 | 89.4k | pu1_cur_pic_luma = pu1_buf; |
1027 | | |
1028 | 89.4k | pu1_buf = ps_cur_pic->pu1_chroma; |
1029 | 89.4k | pu1_cur_pic_chroma = pu1_buf; |
1030 | | |
1031 | 89.4k | #ifndef DISABLE_SEI |
1032 | 89.4k | ps_cur_pic->s_sei_params.i1_sei_parameters_present_flag = 0; |
1033 | 89.4k | if(ps_codec->s_parse.s_sei_params.i1_sei_parameters_present_flag) |
1034 | 1.12k | { |
1035 | 1.12k | sei_params_t *ps_sei = &ps_codec->s_parse.s_sei_params; |
1036 | 1.12k | ps_cur_pic->s_sei_params = ps_codec->s_parse.s_sei_params; |
1037 | | |
1038 | | /* Once sei_params is copied to pic_buf, |
1039 | | * mark sei_params in s_parse as not present, |
1040 | | * this ensures that future frames do not use this data again. |
1041 | | */ |
1042 | 1.12k | ps_sei->i1_sei_parameters_present_flag = 0; |
1043 | 1.12k | ps_sei->i1_user_data_registered_present_flag = 0; |
1044 | 1.12k | ps_sei->i1_aud_present_flag = 0; |
1045 | 1.12k | ps_sei->i1_time_code_present_flag = 0; |
1046 | 1.12k | ps_sei->i1_buf_period_params_present_flag = 0; |
1047 | 1.12k | ps_sei->i1_pic_timing_params_present_flag = 0; |
1048 | 1.12k | ps_sei->i1_recovery_point_params_present_flag = 0; |
1049 | 1.12k | ps_sei->i1_active_parameter_set = 0; |
1050 | 1.12k | ps_sei->i4_sei_mastering_disp_colour_vol_params_present_flags = 0; |
1051 | 1.12k | } |
1052 | 89.4k | #endif |
1053 | 89.4k | } |
1054 | | |
1055 | 89.4k | if(0 == ps_codec->u4_pic_cnt) |
1056 | 21.7k | { |
1057 | 21.7k | WORD32 luma_samples = (ps_sps->i2_pic_width_in_luma_samples + PAD_WD) * ps_sps->i2_pic_height_in_luma_samples; |
1058 | 21.7k | if(PIXEL_SIZE_1BYTE == ps_codec->i4_pixel_size_y) |
1059 | 14.2k | { |
1060 | 14.2k | memset(ps_cur_pic->pu1_luma, 128, luma_samples); |
1061 | 14.2k | } |
1062 | 7.50k | else |
1063 | 7.50k | { |
1064 | 7.50k | ps_codec->s_func_selector.ihevc_memset_16bit_fptr( |
1065 | 7.50k | (UWORD16 *)ps_cur_pic->pu1_luma, |
1066 | 7.50k | (1 << (ps_codec->i4_bit_depth_luma - 1)), |
1067 | 7.50k | luma_samples); |
1068 | 7.50k | } |
1069 | | |
1070 | 21.7k | if(ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_MONOCHROME) |
1071 | 21.4k | { |
1072 | 21.4k | WORD32 chroma_samples = (((ps_sps->i2_pic_width_in_luma_samples + PAD_WD) * (chroma_pixel_strd / h_samp_factor)) |
1073 | 21.4k | * ps_sps->i2_pic_height_in_luma_samples / v_samp_factor); |
1074 | 21.4k | if(PIXEL_SIZE_1BYTE == ps_codec->i4_pixel_size_uv) |
1075 | 14.1k | { |
1076 | 14.1k | memset(ps_cur_pic->pu1_chroma, 128, chroma_samples); |
1077 | 14.1k | } |
1078 | 7.31k | else |
1079 | 7.31k | { |
1080 | 7.31k | ps_codec->s_func_selector.ihevc_memset_16bit_fptr( |
1081 | 7.31k | (UWORD16 *)ps_cur_pic->pu1_chroma, |
1082 | 7.31k | (1 << (ps_codec->i4_bit_depth_chroma - 1)), |
1083 | 7.31k | chroma_samples); |
1084 | 7.31k | } |
1085 | 21.4k | } |
1086 | 21.7k | } |
1087 | | |
1088 | | /* Fill the remaining entries of the reference lists with the nearest POC |
1089 | | * This is done to handle cases where there is a corruption in the reference index */ |
1090 | 89.4k | { |
1091 | 89.4k | pic_buf_t *ps_pic_buf_ref; |
1092 | 89.4k | mv_buf_t *ps_mv_buf_ref; |
1093 | 89.4k | WORD32 r_idx; |
1094 | 89.4k | dpb_mgr_t *ps_dpb_mgr = (dpb_mgr_t *)ps_codec->pv_dpb_mgr; |
1095 | 89.4k | buf_mgr_t *ps_mv_buf_mgr = (buf_mgr_t *)ps_codec->pv_mv_buf_mgr; |
1096 | | |
1097 | 89.4k | ps_pic_buf_ref = ihevc_dpb_mgr_get_ref_by_nearest_poc(ps_dpb_mgr, ps_slice_hdr->i4_abs_pic_order_cnt); |
1098 | 89.4k | if(NULL == ps_pic_buf_ref) |
1099 | 82.4k | { |
1100 | 82.4k | WORD32 size; |
1101 | | |
1102 | 82.4k | WORD32 num_pu; |
1103 | 82.4k | WORD32 num_ctb; |
1104 | 82.4k | WORD32 pic_size; |
1105 | | /* In case current mv buffer itself is being used as reference mv buffer for colocated |
1106 | | * calculations, then memset all the buffers to zero. |
1107 | | */ |
1108 | 82.4k | pic_size = ALIGN64(ps_sps->i2_pic_width_in_luma_samples) * |
1109 | 82.4k | ALIGN64(ps_sps->i2_pic_height_in_luma_samples); |
1110 | | |
1111 | 82.4k | num_pu = pic_size / (MIN_PU_SIZE * MIN_PU_SIZE); |
1112 | 82.4k | num_ctb = pic_size / (MIN_CTB_SIZE * MIN_CTB_SIZE); |
1113 | | |
1114 | 82.4k | memset(ps_mv_buf->ai4_l0_collocated_poc, 0, sizeof(ps_mv_buf->ai4_l0_collocated_poc)); |
1115 | 82.4k | memset(ps_mv_buf->ai1_l0_collocated_poc_lt, 0, sizeof(ps_mv_buf->ai1_l0_collocated_poc_lt)); |
1116 | 82.4k | memset(ps_mv_buf->ai4_l1_collocated_poc, 0, sizeof(ps_mv_buf->ai4_l1_collocated_poc)); |
1117 | 82.4k | memset(ps_mv_buf->ai1_l1_collocated_poc_lt, 0, sizeof(ps_mv_buf->ai1_l1_collocated_poc_lt)); |
1118 | | |
1119 | 82.4k | size = (num_ctb + 1) * sizeof(WORD32); |
1120 | 82.4k | memset(ps_mv_buf->pu4_pic_pu_idx, 0, size); |
1121 | | |
1122 | 82.4k | size = num_pu; |
1123 | 82.4k | memset(ps_mv_buf->pu1_pic_pu_map, 0, size); |
1124 | 82.4k | size = ALIGN4(num_ctb * sizeof(UWORD16)); |
1125 | 82.4k | memset(ps_mv_buf->pu1_pic_slice_map, 0, size); |
1126 | 82.4k | size = num_pu * sizeof(pu_t); |
1127 | 82.4k | memset(ps_mv_buf->ps_pic_pu, 0, size); |
1128 | | |
1129 | 82.4k | ps_pic_buf_ref = ps_cur_pic; |
1130 | 82.4k | ps_mv_buf_ref = ps_mv_buf; |
1131 | 82.4k | } |
1132 | 6.99k | else |
1133 | 6.99k | { |
1134 | 6.99k | ps_mv_buf_ref = ihevcd_mv_mgr_get_poc(ps_mv_buf_mgr, ps_pic_buf_ref->i4_abs_poc); |
1135 | 6.99k | } |
1136 | | |
1137 | 117k | for(r_idx = 0; r_idx < ps_slice_hdr->i1_num_ref_idx_l0_active; r_idx++) |
1138 | 28.0k | { |
1139 | 28.0k | if(NULL == ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf) |
1140 | 11.5k | { |
1141 | 11.5k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1142 | 11.5k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1143 | 11.5k | } |
1144 | 28.0k | } |
1145 | | |
1146 | 1.49M | for(r_idx = ps_slice_hdr->i1_num_ref_idx_l0_active; r_idx < MAX_DPB_SIZE; r_idx++) |
1147 | 1.40M | { |
1148 | 1.40M | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1149 | 1.40M | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1150 | 1.40M | } |
1151 | | |
1152 | 117k | for(r_idx = 0; r_idx < ps_slice_hdr->i1_num_ref_idx_l1_active; r_idx++) |
1153 | 27.7k | { |
1154 | 27.7k | if(NULL == ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf) |
1155 | 10.8k | { |
1156 | 10.8k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1157 | 10.8k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1158 | 10.8k | } |
1159 | 27.7k | } |
1160 | | |
1161 | 1.49M | for(r_idx = ps_slice_hdr->i1_num_ref_idx_l1_active; r_idx < MAX_DPB_SIZE; r_idx++) |
1162 | 1.40M | { |
1163 | 1.40M | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1164 | 1.40M | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1165 | 1.40M | } |
1166 | 89.4k | } |
1167 | | |
1168 | | |
1169 | | /* Reset the jobq to start of the jobq buffer */ |
1170 | 89.4k | ihevcd_jobq_reset((jobq_t *)ps_codec->pv_proc_jobq); |
1171 | | |
1172 | 89.4k | if(ps_codec->i4_threads_active) |
1173 | 89.4k | { |
1174 | 89.4k | ps_codec->i4_break_threads = 0; |
1175 | 89.4k | } |
1176 | 89.4k | ps_codec->s_parse.i4_pic_pu_idx = 0; |
1177 | 89.4k | ps_codec->s_parse.i4_pic_tu_idx = 0; |
1178 | | |
1179 | 89.4k | ps_codec->s_parse.pu1_pic_pu_map = ps_mv_buf->pu1_pic_pu_map; |
1180 | 89.4k | ps_codec->s_parse.ps_pic_pu = ps_mv_buf->ps_pic_pu; |
1181 | 89.4k | ps_codec->s_parse.pu4_pic_pu_idx = ps_mv_buf->pu4_pic_pu_idx; |
1182 | 89.4k | ps_codec->s_parse.pu1_slice_idx = (UWORD16 *)ps_mv_buf->pu1_pic_slice_map; |
1183 | 804k | for(i = 0; i < MAX_PROCESS_THREADS; i++) |
1184 | 715k | { |
1185 | 715k | ps_codec->as_process[i].pu1_slice_idx = (UWORD16 *)ps_mv_buf->pu1_pic_slice_map; |
1186 | 715k | } |
1187 | 89.4k | ps_codec->s_parse.pu1_pu_map = ps_codec->s_parse.pu1_pic_pu_map; |
1188 | 89.4k | ps_codec->s_parse.ps_pu = ps_codec->s_parse.ps_pic_pu; |
1189 | | |
1190 | 89.4k | { |
1191 | 89.4k | UWORD8 *pu1_buf; |
1192 | 89.4k | WORD32 ctb_luma_min_tu_cnt, ctb_chroma_min_tu_cnt, ctb_min_tu_cnt; |
1193 | 89.4k | WORD32 pic_size; |
1194 | 89.4k | WORD32 num_ctb; |
1195 | | |
1196 | 89.4k | pic_size = ALIGN64(ps_sps->i2_pic_width_in_luma_samples) * |
1197 | 89.4k | ALIGN64(ps_sps->i2_pic_height_in_luma_samples); |
1198 | | |
1199 | 89.4k | ctb_luma_min_tu_cnt = pic_size / (MIN_TU_SIZE * MIN_TU_SIZE); |
1200 | | |
1201 | 89.4k | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
1202 | 16.8k | { |
1203 | 16.8k | ctb_chroma_min_tu_cnt = ctb_luma_min_tu_cnt << 1; |
1204 | 16.8k | } |
1205 | 72.5k | else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422 || |
1206 | 55.3k | ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV420) |
1207 | 71.7k | { |
1208 | 71.7k | ctb_chroma_min_tu_cnt = ctb_luma_min_tu_cnt >> 1; |
1209 | 71.7k | } |
1210 | 811 | else |
1211 | 811 | { |
1212 | 811 | ctb_chroma_min_tu_cnt = 0; |
1213 | 811 | } |
1214 | | |
1215 | 89.4k | ctb_min_tu_cnt = ctb_luma_min_tu_cnt + ctb_chroma_min_tu_cnt; |
1216 | | |
1217 | 89.4k | num_ctb = pic_size / (MIN_CTB_SIZE * MIN_CTB_SIZE); |
1218 | 89.4k | pu1_buf = (UWORD8 *)ps_codec->pv_tu_data; |
1219 | 89.4k | ps_codec->s_parse.pu4_pic_tu_idx = (UWORD32 *)pu1_buf; |
1220 | 89.4k | pu1_buf += (num_ctb + 1) * sizeof(WORD32); |
1221 | | |
1222 | 89.4k | ps_codec->s_parse.pu1_pic_tu_map = pu1_buf; |
1223 | 89.4k | pu1_buf += ctb_min_tu_cnt; |
1224 | | |
1225 | 89.4k | ps_codec->s_parse.ps_pic_tu = (tu_t *)pu1_buf; |
1226 | 89.4k | pu1_buf += ctb_min_tu_cnt * sizeof(tu_t); |
1227 | | |
1228 | 89.4k | ps_codec->s_parse.pv_pic_tu_coeff_data = pu1_buf; |
1229 | | |
1230 | 89.4k | ps_codec->s_parse.pu1_tu_map = ps_codec->s_parse.pu1_pic_tu_map; |
1231 | 89.4k | ps_codec->s_parse.ps_tu = ps_codec->s_parse.ps_pic_tu; |
1232 | 89.4k | ps_codec->s_parse.pv_tu_coeff_data = ps_codec->s_parse.pv_pic_tu_coeff_data; |
1233 | 89.4k | } |
1234 | | |
1235 | 89.4k | ps_codec->s_parse.s_bs_ctxt.ps_pic_pu = ps_codec->s_parse.ps_pic_pu; |
1236 | 89.4k | ps_codec->s_parse.s_bs_ctxt.pu4_pic_pu_idx = ps_codec->s_parse.pu4_pic_pu_idx; |
1237 | 89.4k | ps_codec->s_parse.s_bs_ctxt.pu4_pic_tu_idx = ps_codec->s_parse.pu4_pic_tu_idx; |
1238 | | |
1239 | | |
1240 | | /* Set number of CTBs to be processed simultaneously */ |
1241 | 89.4k | ps_codec->i4_proc_nctb = ihevcd_nctb_cnt(ps_codec, ps_sps); |
1242 | | |
1243 | | /* Memset Parse Map and process map at the start of frame */ |
1244 | | //TODO: In case of asynchronous API proc_map can not be set to zero here |
1245 | 89.4k | { |
1246 | 89.4k | WORD32 num_ctb; |
1247 | | |
1248 | 89.4k | num_ctb = ps_sps->i4_pic_size_in_ctb; |
1249 | | |
1250 | 89.4k | memset(ps_codec->pu1_parse_map, 0, num_ctb); |
1251 | | |
1252 | 89.4k | memset(ps_codec->pu1_proc_map, 0, num_ctb); |
1253 | 89.4k | } |
1254 | | |
1255 | | |
1256 | | |
1257 | | /* Initialize disp buf id to -1, this will be updated at the end of frame if there is |
1258 | | * buffer to be displayed |
1259 | | */ |
1260 | 89.4k | ps_codec->i4_disp_buf_id = -1; |
1261 | 89.4k | ps_codec->ps_disp_buf = NULL; |
1262 | | |
1263 | 89.4k | ps_codec->i4_disable_deblk_pic = 0; |
1264 | 89.4k | ps_codec->i4_disable_sao_pic = 0; |
1265 | 89.4k | ps_codec->i4_fullpel_inter_pred = 0; |
1266 | 89.4k | ps_codec->i4_mv_frac_mask = 0x7FFFFFFF; |
1267 | | |
1268 | | /* If degrade is enabled, set the degrade flags appropriately */ |
1269 | 89.4k | if(ps_codec->i4_degrade_type && ps_codec->i4_degrade_pics) |
1270 | 0 | { |
1271 | 0 | WORD32 degrade_pic; |
1272 | 0 | ps_codec->i4_degrade_pic_cnt++; |
1273 | 0 | degrade_pic = 0; |
1274 | | |
1275 | | /* If degrade is to be done in all frames, then do not check further */ |
1276 | 0 | switch(ps_codec->i4_degrade_pics) |
1277 | 0 | { |
1278 | 0 | case 4: |
1279 | 0 | { |
1280 | 0 | degrade_pic = 1; |
1281 | 0 | break; |
1282 | 0 | } |
1283 | 0 | case 3: |
1284 | 0 | { |
1285 | 0 | if(ps_slice_hdr->i1_slice_type != ISLICE) |
1286 | 0 | degrade_pic = 1; |
1287 | |
|
1288 | 0 | break; |
1289 | 0 | } |
1290 | 0 | case 2: |
1291 | 0 | { |
1292 | | |
1293 | | /* If pic count hits non-degrade interval or it is an islice, then do not degrade */ |
1294 | 0 | if((ps_slice_hdr->i1_slice_type != ISLICE) && |
1295 | 0 | (ps_codec->i4_degrade_pic_cnt != ps_codec->i4_nondegrade_interval)) |
1296 | 0 | degrade_pic = 1; |
1297 | |
|
1298 | 0 | break; |
1299 | 0 | } |
1300 | 0 | case 1: |
1301 | 0 | { |
1302 | | /* Check if the current picture is non-ref */ |
1303 | 0 | if((ps_slice_hdr->i1_nal_unit_type < NAL_BLA_W_LP) && |
1304 | 0 | (ps_slice_hdr->i1_nal_unit_type % 2 == 0)) |
1305 | 0 | { |
1306 | 0 | degrade_pic = 1; |
1307 | 0 | } |
1308 | 0 | break; |
1309 | 0 | } |
1310 | | |
1311 | |
|
1312 | 0 | } |
1313 | 0 | if(degrade_pic) |
1314 | 0 | { |
1315 | 0 | if(ps_codec->i4_degrade_type & 0x1) |
1316 | 0 | ps_codec->i4_disable_sao_pic = 1; |
1317 | |
|
1318 | 0 | if(ps_codec->i4_degrade_type & 0x2) |
1319 | 0 | ps_codec->i4_disable_deblk_pic = 1; |
1320 | | |
1321 | | /* MC degrading is done only for non-ref pictures */ |
1322 | 0 | if((ps_slice_hdr->i1_nal_unit_type < NAL_BLA_W_LP) && |
1323 | 0 | (ps_slice_hdr->i1_nal_unit_type % 2 == 0)) |
1324 | 0 | { |
1325 | 0 | if(ps_codec->i4_degrade_type & 0x4) |
1326 | 0 | ps_codec->i4_mv_frac_mask = 0; |
1327 | |
|
1328 | 0 | if(ps_codec->i4_degrade_type & 0x8) |
1329 | 0 | ps_codec->i4_mv_frac_mask = 0; |
1330 | 0 | } |
1331 | 0 | } |
1332 | 0 | else |
1333 | 0 | ps_codec->i4_degrade_pic_cnt = 0; |
1334 | 0 | } |
1335 | | |
1336 | | |
1337 | 89.4k | { |
1338 | 89.4k | WORD32 i; |
1339 | 804k | for(i = 0; i < MAX_PROCESS_THREADS; i++) |
1340 | 715k | { |
1341 | 715k | ps_codec->as_process[i].pu4_pic_pu_idx = ps_codec->s_parse.pu4_pic_pu_idx; |
1342 | 715k | ps_codec->as_process[i].ps_pic_pu = ps_codec->s_parse.ps_pic_pu; |
1343 | 715k | ps_codec->as_process[i].pu1_pic_pu_map = ps_codec->s_parse.pu1_pic_pu_map; |
1344 | 715k | ps_codec->as_process[i].pu4_pic_tu_idx = ps_codec->s_parse.pu4_pic_tu_idx; |
1345 | 715k | ps_codec->as_process[i].ps_pic_tu = ps_codec->s_parse.ps_pic_tu; |
1346 | 715k | ps_codec->as_process[i].pu1_pic_tu_map = ps_codec->s_parse.pu1_pic_tu_map; |
1347 | 715k | ps_codec->as_process[i].pv_pic_tu_coeff_data = ps_codec->s_parse.pv_pic_tu_coeff_data; |
1348 | 715k | ps_codec->as_process[i].i4_cur_mv_bank_buf_id = cur_mv_bank_buf_id; |
1349 | 715k | ps_codec->as_process[i].s_sao_ctxt.pu1_slice_idx = ps_codec->as_process[i].pu1_slice_idx; |
1350 | 715k | ps_codec->as_process[i].s_sao_ctxt.pu1_tile_idx = ps_codec->as_process[i].pu1_tile_idx; |
1351 | | |
1352 | | /* TODO: For asynchronous api the following initializations related to picture |
1353 | | * buffer should be moved to processing side |
1354 | | */ |
1355 | 715k | ps_codec->as_process[i].pu1_cur_pic_luma = pu1_cur_pic_luma; |
1356 | 715k | ps_codec->as_process[i].pu1_cur_pic_chroma = pu1_cur_pic_chroma; |
1357 | 715k | ps_codec->as_process[i].ps_cur_pic = ps_cur_pic; |
1358 | 715k | ps_codec->as_process[i].i4_cur_pic_buf_id = cur_pic_buf_id; |
1359 | | |
1360 | 715k | ps_codec->as_process[i].ps_out_buffer = ps_codec->ps_out_buffer; |
1361 | 715k | if(1 < ps_codec->i4_num_cores) |
1362 | 475k | { |
1363 | 475k | ps_codec->as_process[i].i4_check_parse_status = 1; |
1364 | 475k | ps_codec->as_process[i].i4_check_proc_status = 1; |
1365 | 475k | } |
1366 | 239k | else |
1367 | 239k | { |
1368 | 239k | ps_codec->as_process[i].i4_check_parse_status = 0; |
1369 | 239k | ps_codec->as_process[i].i4_check_proc_status = 0; |
1370 | 239k | } |
1371 | 715k | ps_codec->as_process[i].pu1_pic_intra_flag = ps_codec->s_parse.pu1_pic_intra_flag; |
1372 | 715k | ps_codec->as_process[i].pu1_pic_no_loop_filter_flag = ps_codec->s_parse.pu1_pic_no_loop_filter_flag; |
1373 | 715k | ps_codec->as_process[i].i4_init_done = 0; |
1374 | | |
1375 | 715k | ps_codec->as_process[i].s_bs_ctxt.pu4_pic_tu_idx = ps_codec->as_process[i].pu4_pic_tu_idx; |
1376 | 715k | ps_codec->as_process[i].s_bs_ctxt.pu4_pic_pu_idx = ps_codec->as_process[i].pu4_pic_pu_idx; |
1377 | 715k | ps_codec->as_process[i].s_bs_ctxt.ps_pic_pu = ps_codec->as_process[i].ps_pic_pu; |
1378 | 715k | ps_codec->as_process[i].s_deblk_ctxt.pu1_pic_no_loop_filter_flag = ps_codec->s_parse.pu1_pic_no_loop_filter_flag; |
1379 | 715k | ps_codec->as_process[i].s_deblk_ctxt.pu1_cur_pic_luma = pu1_cur_pic_luma; |
1380 | 715k | ps_codec->as_process[i].s_deblk_ctxt.pu1_cur_pic_chroma = pu1_cur_pic_chroma; |
1381 | 715k | ps_codec->as_process[i].s_sao_ctxt.pu1_pic_no_loop_filter_flag = ps_codec->s_parse.pu1_pic_no_loop_filter_flag; |
1382 | 715k | ps_codec->as_process[i].s_sao_ctxt.pu1_cur_pic_luma = pu1_cur_pic_luma; |
1383 | 715k | ps_codec->as_process[i].s_sao_ctxt.pu1_cur_pic_chroma = pu1_cur_pic_chroma; |
1384 | 715k | if(i < (ps_codec->i4_num_cores - 1)) |
1385 | 114k | { |
1386 | 114k | if (!ps_codec->ai4_process_thread_created[i]) |
1387 | 27.0k | { |
1388 | 27.0k | ithread_create(ps_codec->apv_process_thread_handle[i], NULL, |
1389 | 27.0k | (void *)ihevcd_process_thread, |
1390 | 27.0k | (void *)&ps_codec->as_process[i]); |
1391 | 27.0k | ps_codec->ai4_process_thread_created[i] = 1; |
1392 | 27.0k | } |
1393 | 114k | if(ps_codec->i4_threads_active) |
1394 | 114k | { |
1395 | 114k | ret = ithread_mutex_lock(ps_codec->apv_proc_start_mutex[i]); |
1396 | 114k | RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); |
1397 | | |
1398 | 114k | ps_codec->ai4_process_start[i] = 1; |
1399 | 114k | ithread_cond_signal(ps_codec->apv_proc_start_condition[i]); |
1400 | | |
1401 | 114k | ret = ithread_mutex_unlock(ps_codec->apv_proc_start_mutex[i]); |
1402 | 114k | RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); |
1403 | 114k | } |
1404 | 114k | } |
1405 | 600k | else |
1406 | 600k | { |
1407 | 600k | ps_codec->ai4_process_thread_created[i] = 0; |
1408 | 600k | } |
1409 | | |
1410 | 715k | } |
1411 | 89.4k | if(ps_codec->u1_enable_cu_info) |
1412 | 0 | { |
1413 | 0 | ps_codec->as_buf_id_info_map[cur_pic_buf_id].pu1_qp_map = |
1414 | 0 | ps_codec->pu1_qp_map_base + (cur_pic_buf_id * ps_codec->u4_num_8x8_blks); |
1415 | 0 | ps_codec->as_buf_id_info_map[cur_pic_buf_id].pu1_cu_type_map = |
1416 | 0 | ps_codec->pu1_cu_type_map_base + (cur_pic_buf_id * ps_codec->u4_num_8x8_blks); |
1417 | 0 | memset(ps_codec->as_buf_id_info_map[cur_pic_buf_id].pu1_qp_map, |
1418 | 0 | 0, ps_codec->u4_num_8x8_blks); |
1419 | 0 | memset(ps_codec->as_buf_id_info_map[cur_pic_buf_id].pu1_qp_map, |
1420 | 0 | 0, ps_codec->u4_num_8x8_blks); |
1421 | 0 | } |
1422 | | |
1423 | 89.4k | ps_codec->s_parse.s_deblk_ctxt.pu1_cur_pic_luma = pu1_cur_pic_luma; |
1424 | 89.4k | ps_codec->s_parse.s_deblk_ctxt.pu1_cur_pic_chroma = pu1_cur_pic_chroma; |
1425 | | |
1426 | 89.4k | ps_codec->s_parse.s_sao_ctxt.pu1_cur_pic_luma = pu1_cur_pic_luma; |
1427 | 89.4k | ps_codec->s_parse.s_sao_ctxt.pu1_cur_pic_chroma = pu1_cur_pic_chroma; |
1428 | 89.4k | } |
1429 | | /* Since any input bitstream buffer that contains slice data will be sent to output(even in |
1430 | | * case of error, this buffer is added to display queue and next buffer in the display queue |
1431 | | * will be returned as the display buffer. |
1432 | | * Note: If format conversion (or frame copy) is used and is scheduled |
1433 | | * in a different thread then it has to check if the processing for the current row is complete before |
1434 | | * it copies/converts a given row. In case of low delay or in case of B pictures, current frame being decoded has to be |
1435 | | * returned, which requires a status check to ensure that the current row is reconstructed before copying. |
1436 | | */ |
1437 | | /* Add current picture to display manager */ |
1438 | 0 | { |
1439 | 89.4k | WORD32 abs_poc; |
1440 | 89.4k | slice_header_t *ps_slice_hdr; |
1441 | 89.4k | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr; |
1442 | 89.4k | abs_poc = ps_slice_hdr->i4_abs_pic_order_cnt; |
1443 | 89.4k | ihevc_disp_mgr_add((disp_mgr_t *)ps_codec->pv_disp_buf_mgr, |
1444 | 89.4k | ps_codec->as_process[0].i4_cur_pic_buf_id, |
1445 | 89.4k | abs_poc, |
1446 | 89.4k | ps_codec->as_process[0].ps_cur_pic); |
1447 | 89.4k | } |
1448 | 89.4k | ps_codec->ps_disp_buf = NULL; |
1449 | | /* Get picture to be displayed if number of pictures decoded is more than max allowed reorder */ |
1450 | | /* Since the current will be decoded, check is fore >= instead of > */ |
1451 | 89.4k | if(((WORD32)(ps_codec->u4_pic_cnt - ps_codec->u4_disp_cnt) >= ps_sps->ai1_sps_max_num_reorder_pics[ps_sps->i1_sps_max_sub_layers - 1]) || |
1452 | 2.99k | (ps_codec->e_frm_out_mode == IVD_DECODE_FRAME_OUT)) |
1453 | | |
1454 | 86.4k | { |
1455 | 86.4k | ps_codec->ps_disp_buf = (pic_buf_t *)ihevc_disp_mgr_get((disp_mgr_t *)ps_codec->pv_disp_buf_mgr, &ps_codec->i4_disp_buf_id); |
1456 | 86.4k | ps_codec->u4_disp_cnt++; |
1457 | 86.4k | } |
1458 | | |
1459 | 89.4k | ps_codec->s_fmt_conv.i4_cur_row = 0; |
1460 | | /* Set number of rows to be processed at a time */ |
1461 | 89.4k | ps_codec->s_fmt_conv.i4_num_rows = 4; |
1462 | | |
1463 | 89.4k | if(ps_codec->u4_enable_fmt_conv_ahead && (ps_codec->i4_num_cores > 1)) |
1464 | 0 | { |
1465 | 0 | process_ctxt_t *ps_proc; |
1466 | | |
1467 | | /* i4_num_cores - 1 contexts are currently being used by other threads */ |
1468 | 0 | ps_proc = &ps_codec->as_process[ps_codec->i4_num_cores - 1]; |
1469 | | |
1470 | | /* If the frame being decoded and displayed are different, schedule format conversion jobs |
1471 | | * this will keep the proc threads busy and lets parse thread decode few CTBs ahead |
1472 | | * If the frame being decoded and displayed are same, then format conversion is scheduled later. |
1473 | | */ |
1474 | 0 | if((ps_codec->ps_disp_buf) && (ps_codec->i4_disp_buf_id != ps_proc->i4_cur_pic_buf_id) && |
1475 | 0 | ((0 == ps_codec->i4_share_disp_buf) || (IV_YUV_420P == ps_codec->e_chroma_fmt))) |
1476 | 0 | { |
1477 | |
|
1478 | 0 | for(i = 0; i < ps_sps->i2_pic_ht_in_ctb; i++) |
1479 | 0 | { |
1480 | 0 | proc_job_t s_job; |
1481 | 0 | IHEVCD_ERROR_T ret; |
1482 | 0 | s_job.i4_cmd = CMD_FMTCONV; |
1483 | 0 | s_job.i2_ctb_cnt = 0; |
1484 | 0 | s_job.i2_ctb_x = 0; |
1485 | 0 | s_job.i2_ctb_y = i; |
1486 | 0 | s_job.i2_slice_idx = 0; |
1487 | 0 | s_job.i4_tu_coeff_data_ofst = 0; |
1488 | 0 | ret = ihevcd_jobq_queue((jobq_t *)ps_codec->s_parse.pv_proc_jobq, |
1489 | 0 | &s_job, sizeof(proc_job_t), 1); |
1490 | 0 | if(ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS) |
1491 | 0 | return ret; |
1492 | 0 | } |
1493 | 0 | } |
1494 | 0 | } |
1495 | | |
1496 | | /* If parse_pic_init is called, then slice data is present in the input bitstrea stream */ |
1497 | 89.4k | ps_codec->i4_pic_present = 1; |
1498 | | |
1499 | 89.4k | return ret; |
1500 | 89.4k | } |
1501 | | |
1502 | | |