/src/libhevc/decoder/ihevcd_parse_slice.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_parse_slice.c |
22 | | * |
23 | | * @brief |
24 | | * Contains functions for parsing slice data |
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_structs.h" |
54 | | #include "ihevc_macros.h" |
55 | | #include "ihevc_mem_fns.h" |
56 | | #include "ihevc_platform_macros.h" |
57 | | |
58 | | #include "ihevc_common_tables.h" |
59 | | #include "ihevc_error.h" |
60 | | #include "ihevc_cabac_tables.h" |
61 | | |
62 | | #include "ihevcd_trace.h" |
63 | | #include "ihevcd_defs.h" |
64 | | #include "ihevcd_function_selector.h" |
65 | | #include "ihevcd_structs.h" |
66 | | #include "ihevcd_error.h" |
67 | | #include "ihevcd_nal.h" |
68 | | #include "ihevcd_bitstream.h" |
69 | | #include "ihevcd_utils.h" |
70 | | #include "ihevcd_parse_slice.h" |
71 | | #include "ihevcd_parse_residual.h" |
72 | | #include "ihevcd_cabac.h" |
73 | | #include "ihevcd_job_queue.h" |
74 | | #include "ihevcd_intra_pred_mode_prediction.h" |
75 | | #include "ihevcd_common_tables.h" |
76 | | #include "ihevcd_process_slice.h" |
77 | | #include "ihevcd_debug.h" |
78 | | #include "ihevcd_get_mv.h" |
79 | | #include "ihevcd_boundary_strength.h" |
80 | | #include "ihevcd_ilf_padding.h" |
81 | | #include "ihevcd_statistics.h" |
82 | | /* Bit stream offset threshold */ |
83 | 2.61M | #define BITSTRM_OFF_THRS 8 |
84 | | |
85 | 179k | #define MIN_CU_QP_DELTA_ABS(x) (-26 + ((x) * 6) / 2) |
86 | 89.8k | #define MAX_CU_QP_DELTA_ABS(x) (25 + ((x) * 6) / 2) |
87 | | |
88 | | /** |
89 | | * Table used to decode part_mode if AMP is enabled and current CU is not min CU |
90 | | */ |
91 | | const UWORD8 gau1_part_mode_amp[] = { PART_nLx2N, PART_nRx2N, PART_Nx2N, 0xFF, PART_2NxnU, PART_2NxnD, PART_2NxN, 0xFF }; |
92 | | |
93 | | const UWORD32 gau4_ct_depth_mask[] = { 0x0, 0x55555555, 0xAAAAAAAA, 0xFFFFFFFF }; |
94 | | |
95 | | |
96 | | |
97 | | /** |
98 | | ******************************************************************************* |
99 | | * |
100 | | * @brief |
101 | | * Parses Transform tree syntax |
102 | | * |
103 | | * @par Description: |
104 | | * Parses Transform tree syntax as per Section:7.3.9.8 |
105 | | * |
106 | | * @param[in] ps_codec |
107 | | * Pointer to codec context |
108 | | * |
109 | | * @returns Status |
110 | | * |
111 | | * @remarks |
112 | | * |
113 | | * |
114 | | ******************************************************************************* |
115 | | */ |
116 | | |
117 | | WORD32 ihevcd_parse_transform_tree(codec_t *ps_codec, |
118 | | WORD32 x0, WORD32 y0, |
119 | | WORD32 cu_x_base, WORD32 cu_y_base, |
120 | | WORD32 log2_trafo_size, |
121 | | WORD32 trafo_depth, |
122 | | WORD32 blk_idx, |
123 | | WORD32 intra_pred_mode, |
124 | | WORD32 chroma_intra_pred_mode_idx) |
125 | 4.08M | { |
126 | 4.08M | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
127 | 4.08M | sps_t *ps_sps; |
128 | 4.08M | pps_t *ps_pps; |
129 | 4.08M | WORD32 value; |
130 | 4.08M | WORD32 x1, y1; |
131 | 4.08M | WORD32 max_trafo_depth; |
132 | | |
133 | 4.08M | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
134 | 4.08M | WORD32 intra_split_flag; |
135 | 4.08M | WORD32 split_transform_flag; |
136 | 4.08M | WORD32 ctxt_idx; |
137 | 4.08M | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
138 | | |
139 | 4.08M | max_trafo_depth = ps_codec->s_parse.s_cu.i4_max_trafo_depth; |
140 | 4.08M | ps_sps = ps_codec->s_parse.ps_sps; |
141 | 4.08M | ps_pps = ps_codec->s_parse.ps_pps; |
142 | 4.08M | intra_split_flag = ps_codec->s_parse.s_cu.i4_intra_split_flag; |
143 | | |
144 | 4.08M | { |
145 | 4.08M | split_transform_flag = 0; |
146 | 4.08M | if((log2_trafo_size <= ps_sps->i1_log2_max_transform_block_size) && |
147 | 4.00M | (log2_trafo_size > ps_sps->i1_log2_min_transform_block_size) && |
148 | 1.94M | (trafo_depth < max_trafo_depth) && |
149 | 1.28M | !(intra_split_flag && (trafo_depth == 0))) |
150 | 988k | { |
151 | | /* encode the split transform flag, context derived as per Table9-37 */ |
152 | 988k | ctxt_idx = IHEVC_CAB_SPLIT_TFM + (5 - log2_trafo_size); |
153 | | |
154 | 988k | TRACE_CABAC_CTXT("split_transform_flag", ps_cabac->u4_range, ctxt_idx); |
155 | 988k | split_transform_flag = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
156 | 988k | AEV_TRACE("split_transform_flag", split_transform_flag, |
157 | 988k | ps_cabac->u4_range); |
158 | | |
159 | 988k | } |
160 | 3.09M | else |
161 | 3.09M | { |
162 | 3.09M | WORD32 inter_split_flag = 0; |
163 | | |
164 | 3.09M | if((0 == ps_sps->i1_max_transform_hierarchy_depth_inter) && |
165 | 481k | (PRED_MODE_INTER == ps_codec->s_parse.s_cu.i4_pred_mode) && |
166 | 16.4k | (PART_2Nx2N != ps_codec->s_parse.s_cu.i4_part_mode) && |
167 | 970 | (0 == trafo_depth)) |
168 | 178 | { |
169 | 178 | inter_split_flag = 1; |
170 | 178 | } |
171 | | |
172 | 3.09M | if((log2_trafo_size > ps_sps->i1_log2_max_transform_block_size) || |
173 | 3.01M | ((1 == intra_split_flag) && (0 == trafo_depth)) || |
174 | 2.71M | (1 == inter_split_flag)) |
175 | 381k | { |
176 | 381k | split_transform_flag = 1; |
177 | 381k | } |
178 | 3.09M | } |
179 | | |
180 | 4.08M | if(0 == trafo_depth) |
181 | 1.21M | { |
182 | 1.21M | ps_codec->s_parse.s_cu.ai1_cbf_cr[trafo_depth] = 0; |
183 | 1.21M | ps_codec->s_parse.s_cu.ai1_cbf_cb[trafo_depth] = 0; |
184 | 1.21M | #ifdef ENABLE_MAIN_REXT_PROFILE |
185 | 1.21M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) |
186 | 0 | { |
187 | 0 | ps_codec->s_parse.s_cu.ai1_cbf_cr_subtu[trafo_depth] = 0; |
188 | 0 | ps_codec->s_parse.s_cu.ai1_cbf_cb_subtu[trafo_depth] = 0; |
189 | 0 | } |
190 | 1.21M | #endif |
191 | 1.21M | } |
192 | 2.87M | else |
193 | 2.87M | { |
194 | 2.87M | ps_codec->s_parse.s_cu.ai1_cbf_cb[trafo_depth] = ps_codec->s_parse.s_cu.ai1_cbf_cb[trafo_depth - 1]; |
195 | 2.87M | ps_codec->s_parse.s_cu.ai1_cbf_cr[trafo_depth] = ps_codec->s_parse.s_cu.ai1_cbf_cr[trafo_depth - 1]; |
196 | 2.87M | #ifdef ENABLE_MAIN_REXT_PROFILE |
197 | 2.87M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) |
198 | 0 | { |
199 | 0 | ps_codec->s_parse.s_cu.ai1_cbf_cb_subtu[trafo_depth] = |
200 | 0 | ps_codec->s_parse.s_cu.ai1_cbf_cb_subtu[trafo_depth - 1]; |
201 | 0 | ps_codec->s_parse.s_cu.ai1_cbf_cr_subtu[trafo_depth] = |
202 | 0 | ps_codec->s_parse.s_cu.ai1_cbf_cr_subtu[trafo_depth - 1]; |
203 | 0 | } |
204 | 2.87M | #endif |
205 | 2.87M | } |
206 | 4.08M | if ((CHROMA_FMT_IDC_MONOCHROME != ps_sps->i1_chroma_format_idc && log2_trafo_size > 2) || |
207 | 2.06M | ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
208 | 2.02M | { |
209 | 2.02M | ctxt_idx = IHEVC_CAB_CBCR_IDX + trafo_depth; |
210 | | /* CBF for Cb/Cr is sent only if the parent CBF for Cb/Cr is non-zero */ |
211 | 2.02M | if((trafo_depth == 0) || ps_codec->s_parse.s_cu.ai1_cbf_cb[trafo_depth - 1]) |
212 | 1.31M | { |
213 | 1.31M | TRACE_CABAC_CTXT("cbf_cb", ps_cabac->u4_range, ctxt_idx); |
214 | 1.31M | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
215 | 1.31M | AEV_TRACE("cbf_cb", value, ps_cabac->u4_range); |
216 | 1.31M | ps_codec->s_parse.s_cu.ai1_cbf_cb[trafo_depth] = value; |
217 | 1.31M | #ifdef ENABLE_MAIN_REXT_PROFILE |
218 | 1.31M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422 |
219 | 0 | && (!split_transform_flag || log2_trafo_size == 3)) |
220 | 0 | { |
221 | 0 | TRACE_CABAC_CTXT("cbf_cb", ps_cabac->u4_range, ctxt_idx); |
222 | 0 | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
223 | 0 | AEV_TRACE("cbf_cb", value, ps_cabac->u4_range); |
224 | 0 | ps_codec->s_parse.s_cu.ai1_cbf_cb_subtu[trafo_depth] = value; |
225 | 0 | } |
226 | 1.31M | #endif |
227 | 1.31M | } |
228 | | |
229 | 2.02M | if((trafo_depth == 0) || ps_codec->s_parse.s_cu.ai1_cbf_cr[trafo_depth - 1]) |
230 | 1.32M | { |
231 | 1.32M | TRACE_CABAC_CTXT("cbf_cr", ps_cabac->u4_range, ctxt_idx); |
232 | 1.32M | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
233 | 1.32M | AEV_TRACE("cbf_cr", value, ps_cabac->u4_range); |
234 | 1.32M | ps_codec->s_parse.s_cu.ai1_cbf_cr[trafo_depth] = value; |
235 | 1.32M | #ifdef ENABLE_MAIN_REXT_PROFILE |
236 | 1.32M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422 |
237 | 0 | && (!split_transform_flag || log2_trafo_size == 3)) |
238 | 0 | { |
239 | 0 | TRACE_CABAC_CTXT("cbf_cr", ps_cabac->u4_range, ctxt_idx); |
240 | 0 | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
241 | 0 | AEV_TRACE("cbf_cr", value, ps_cabac->u4_range); |
242 | 0 | ps_codec->s_parse.s_cu.ai1_cbf_cr_subtu[trafo_depth] = value; |
243 | 0 | } |
244 | 1.32M | #endif |
245 | 1.32M | } |
246 | 2.02M | } |
247 | 4.08M | if(split_transform_flag) |
248 | 718k | { |
249 | 718k | WORD32 intra_pred_mode_tmp; |
250 | 718k | WORD32 chroma_intra_pred_mode_tmp_idx = ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[0]; |
251 | 718k | x1 = x0 + ((1 << log2_trafo_size) >> 1); |
252 | 718k | y1 = y0 + ((1 << log2_trafo_size) >> 1); |
253 | | |
254 | | /* For transform depth of zero, intra pred mode as decoded at CU */ |
255 | | /* level is sent to the transform tree nodes */ |
256 | | /* When depth is non-zero intra pred mode of parent node is sent */ |
257 | | /* This takes care of passing correct mode to all the child nodes */ |
258 | 718k | intra_pred_mode_tmp = trafo_depth ? intra_pred_mode : ps_codec->s_parse.s_cu.ai4_intra_luma_pred_mode[0]; |
259 | 718k | if (ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
260 | 0 | chroma_intra_pred_mode_tmp_idx = trafo_depth ? chroma_intra_pred_mode_idx : ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[0]; |
261 | 718k | ret = ihevcd_parse_transform_tree(ps_codec, x0, y0, x0, y0, log2_trafo_size - 1, trafo_depth + 1, 0, intra_pred_mode_tmp, chroma_intra_pred_mode_tmp_idx); |
262 | 718k | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
263 | | |
264 | 718k | intra_pred_mode_tmp = trafo_depth ? intra_pred_mode : ps_codec->s_parse.s_cu.ai4_intra_luma_pred_mode[1]; |
265 | 718k | if (ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
266 | 0 | chroma_intra_pred_mode_tmp_idx = trafo_depth ? chroma_intra_pred_mode_idx : ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[1]; |
267 | 718k | ret = ihevcd_parse_transform_tree(ps_codec, x1, y0, x0, y0, log2_trafo_size - 1, trafo_depth + 1, 1, intra_pred_mode_tmp, chroma_intra_pred_mode_tmp_idx); |
268 | 718k | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
269 | | |
270 | 718k | intra_pred_mode_tmp = trafo_depth ? intra_pred_mode : ps_codec->s_parse.s_cu.ai4_intra_luma_pred_mode[2]; |
271 | 718k | if (ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
272 | 0 | chroma_intra_pred_mode_tmp_idx = trafo_depth ? chroma_intra_pred_mode_idx : ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[2]; |
273 | 718k | ret = ihevcd_parse_transform_tree(ps_codec, x0, y1, x0, y0, log2_trafo_size - 1, trafo_depth + 1, 2, intra_pred_mode_tmp, chroma_intra_pred_mode_tmp_idx); |
274 | 718k | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
275 | | |
276 | 718k | intra_pred_mode_tmp = trafo_depth ? intra_pred_mode : ps_codec->s_parse.s_cu.ai4_intra_luma_pred_mode[3]; |
277 | 718k | if (ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
278 | 0 | chroma_intra_pred_mode_tmp_idx = trafo_depth ? chroma_intra_pred_mode_idx : ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[3]; |
279 | 718k | ret = ihevcd_parse_transform_tree(ps_codec, x1, y1, x0, y0, log2_trafo_size - 1, trafo_depth + 1, 3, intra_pred_mode_tmp, chroma_intra_pred_mode_tmp_idx); |
280 | 718k | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
281 | | |
282 | 718k | } |
283 | 3.36M | else |
284 | 3.36M | { |
285 | 3.36M | WORD32 ctb_x_base; |
286 | 3.36M | WORD32 ctb_y_base; |
287 | 3.36M | WORD32 cu_qp_delta_abs; |
288 | 3.36M | WORD32 cbf_chroma; |
289 | | |
290 | | |
291 | | |
292 | 3.36M | tu_t *ps_tu = ps_codec->s_parse.ps_tu; |
293 | 3.36M | cu_qp_delta_abs = 0; |
294 | 3.36M | ctb_x_base = ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size; |
295 | 3.36M | ctb_y_base = ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size; |
296 | 3.36M | cbf_chroma = ps_codec->s_parse.s_cu.ai1_cbf_cb[trafo_depth] |
297 | 2.77M | || ps_codec->s_parse.s_cu.ai1_cbf_cr[trafo_depth]; |
298 | 3.36M | #ifdef ENABLE_MAIN_REXT_PROFILE |
299 | 3.36M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) |
300 | 0 | { |
301 | 0 | cbf_chroma |= ps_codec->s_parse.s_cu.ai1_cbf_cb_subtu[trafo_depth] |
302 | 0 | || ps_codec->s_parse.s_cu.ai1_cbf_cr_subtu[trafo_depth]; |
303 | 0 | } |
304 | 3.36M | #endif |
305 | | |
306 | 3.36M | if((ps_codec->s_parse.s_cu.i4_pred_mode == PRED_MODE_INTRA) || |
307 | 1.20M | (trafo_depth != 0) || |
308 | 208k | (cbf_chroma)) |
309 | 3.18M | { |
310 | 3.18M | ctxt_idx = IHEVC_CAB_CBF_LUMA_IDX; |
311 | 3.18M | ctxt_idx += (trafo_depth == 0) ? 1 : 0; |
312 | | |
313 | 3.18M | TRACE_CABAC_CTXT("cbf_luma", ps_cabac->u4_range, ctxt_idx); |
314 | 3.18M | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
315 | 3.18M | AEV_TRACE("cbf_luma", value, ps_cabac->u4_range); |
316 | | |
317 | 3.18M | ps_codec->s_parse.s_cu.i1_cbf_luma = value; |
318 | 3.18M | } |
319 | 181k | else |
320 | 181k | { |
321 | 181k | ps_codec->s_parse.s_cu.i1_cbf_luma = 1; |
322 | 181k | } |
323 | | |
324 | | /* Initialize ps_tu to default values */ |
325 | | /* If required change this to WORD32 packed write */ |
326 | 3.36M | ps_tu->b1_cb_cbf = 0; |
327 | 3.36M | #ifdef ENABLE_MAIN_REXT_PROFILE |
328 | 3.36M | ps_tu->b1_cb_cbf_subtu1 = 0; |
329 | 3.36M | #endif |
330 | 3.36M | ps_tu->b1_cr_cbf = 0; |
331 | 3.36M | #ifdef ENABLE_MAIN_REXT_PROFILE |
332 | 3.36M | ps_tu->b1_cr_cbf_subtu1 = 0; |
333 | 3.36M | #endif |
334 | 3.36M | ps_tu->b1_y_cbf = 0; |
335 | 3.36M | ps_tu->b4_pos_x = ((x0 - ctb_x_base) >> 2); |
336 | 3.36M | ps_tu->b4_pos_y = ((y0 - ctb_y_base) >> 2); |
337 | 3.36M | ps_tu->b1_transquant_bypass = ps_codec->s_parse.s_cu.i4_cu_transquant_bypass; |
338 | 3.36M | ps_tu->b3_size = (log2_trafo_size - 2); |
339 | 3.36M | ps_tu->b7_qp = ps_codec->s_parse.u4_qp; |
340 | 3.36M | #ifdef ENABLE_MAIN_REXT_PROFILE |
341 | 3.36M | ps_tu->b3_cb_log2_res_scale_abs_plus1 = 0; |
342 | 3.36M | ps_tu->b1_cb_log2_res_sign = 0; |
343 | 3.36M | ps_tu->b3_cr_log2_res_scale_abs_plus1 = 0; |
344 | 3.36M | ps_tu->b1_cr_log2_res_sign = 0; |
345 | 3.36M | #endif |
346 | | |
347 | 3.36M | ps_tu->b6_luma_intra_mode = intra_pred_mode; |
348 | 3.36M | ps_tu->b3_chroma_intra_mode_idx = chroma_intra_pred_mode_idx; |
349 | | |
350 | | /* Section:7.3.12 Transform unit syntax inlined here */ |
351 | 3.36M | if(ps_codec->s_parse.s_cu.i1_cbf_luma || cbf_chroma) |
352 | 2.21M | { |
353 | 2.21M | WORD32 intra_pred_mode_chroma; |
354 | 2.21M | if(ps_pps->i1_cu_qp_delta_enabled_flag && !ps_codec->s_parse.i4_is_cu_qp_delta_coded) |
355 | 89.8k | { |
356 | | |
357 | | |
358 | 89.8k | WORD32 c_max = TU_MAX_QP_DELTA_ABS; |
359 | 89.8k | WORD32 ctxt_inc = IHEVC_CAB_QP_DELTA_ABS; |
360 | 89.8k | WORD32 ctxt_inc_max = CTXT_MAX_QP_DELTA_ABS; |
361 | | |
362 | 89.8k | TRACE_CABAC_CTXT("cu_qp_delta_abs", ps_cabac->u4_range, ctxt_inc); |
363 | | /* qp_delta_abs is coded as combination of tunary and eg0 code */ |
364 | | /* See Table 9-32 and Table 9-37 for details on cu_qp_delta_abs */ |
365 | 89.8k | cu_qp_delta_abs = ihevcd_cabac_decode_bins_tunary(ps_cabac, |
366 | 89.8k | ps_bitstrm, |
367 | 89.8k | c_max, |
368 | 89.8k | ctxt_inc, |
369 | 89.8k | 0, |
370 | 89.8k | ctxt_inc_max); |
371 | 89.8k | if(cu_qp_delta_abs >= c_max) |
372 | 3.69k | { |
373 | 3.69k | value = ihevcd_cabac_decode_bypass_bins_egk(ps_cabac, ps_bitstrm, 0); |
374 | 3.69k | cu_qp_delta_abs += value; |
375 | 3.69k | } |
376 | 89.8k | AEV_TRACE("cu_qp_delta_abs", cu_qp_delta_abs, ps_cabac->u4_range); |
377 | | |
378 | 89.8k | ps_codec->s_parse.i4_is_cu_qp_delta_coded = 1; |
379 | | |
380 | | |
381 | 89.8k | if(cu_qp_delta_abs) |
382 | 39.8k | { |
383 | 39.8k | value = ihevcd_cabac_decode_bypass_bin(ps_cabac, ps_bitstrm); |
384 | 39.8k | AEV_TRACE("cu_qp_delta_sign", value, ps_cabac->u4_range); |
385 | | |
386 | 39.8k | if(value) |
387 | 18.8k | cu_qp_delta_abs = -cu_qp_delta_abs; |
388 | | |
389 | 39.8k | } |
390 | | |
391 | 89.8k | if (cu_qp_delta_abs < MIN_CU_QP_DELTA_ABS(ps_sps->i1_bit_depth_luma_minus8) |
392 | 89.8k | || cu_qp_delta_abs > MAX_CU_QP_DELTA_ABS(ps_sps->i1_bit_depth_luma_minus8)) |
393 | 29 | { |
394 | 29 | return IHEVCD_INVALID_PARAMETER; |
395 | 29 | } |
396 | | |
397 | 89.8k | ps_codec->s_parse.s_cu.i4_cu_qp_delta = cu_qp_delta_abs; |
398 | | |
399 | 89.8k | } |
400 | | |
401 | 2.21M | if(ps_codec->s_parse.s_cu.i1_cbf_luma) |
402 | 1.92M | { |
403 | 1.92M | ps_tu->b1_y_cbf = 1; |
404 | 1.92M | ihevcd_parse_residual_coding(ps_codec, x0, y0, log2_trafo_size, 0, intra_pred_mode); |
405 | 1.92M | } |
406 | | |
407 | 2.21M | WORD32 chroma_blk_luma_intra_pred_mode = |
408 | 2.21M | ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444 ? |
409 | 0 | intra_pred_mode : |
410 | 2.21M | ps_codec->s_parse.s_cu.ai4_intra_luma_pred_mode[0]; |
411 | 2.21M | if(4 == chroma_intra_pred_mode_idx) |
412 | 1.54M | intra_pred_mode_chroma = chroma_blk_luma_intra_pred_mode; |
413 | 671k | else |
414 | 671k | { |
415 | 671k | intra_pred_mode_chroma = gau1_intra_pred_chroma_modes[chroma_intra_pred_mode_idx]; |
416 | | |
417 | 671k | if(intra_pred_mode_chroma == chroma_blk_luma_intra_pred_mode) |
418 | 76.4k | { |
419 | 76.4k | intra_pred_mode_chroma = INTRA_ANGULAR(34); |
420 | 76.4k | } |
421 | 671k | } |
422 | 2.21M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) |
423 | 0 | { |
424 | 0 | intra_pred_mode_chroma = gau1_intra_pred_chroma_modes_422[intra_pred_mode_chroma]; |
425 | 0 | } |
426 | 2.21M | if(log2_trafo_size > 2 || ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
427 | 895k | { |
428 | 895k | WORD32 trafo_offset = (ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444 ? 0 : 1); |
429 | 895k | WORD32 log2_trafo_size_c = MAX(2, log2_trafo_size - trafo_offset); |
430 | | |
431 | 895k | #ifdef ENABLE_MAIN_REXT_PROFILE |
432 | 895k | if(ps_pps->i1_cross_component_prediction_enabled_flag |
433 | 0 | && ps_codec->s_parse.s_cu.i1_cbf_luma |
434 | 0 | && (ps_codec->s_parse.s_cu.i4_pred_mode == PRED_MODE_INTER |
435 | 0 | || chroma_intra_pred_mode_idx == 4)) |
436 | 0 | { |
437 | 0 | ctxt_idx = IHEVC_CAB_CCP_LOG2_RES_ABS; |
438 | 0 | TRACE_CABAC_CTXT("log2_res_scale_abs_plus1", ps_cabac->u4_range, ctxt_idx); |
439 | 0 | value = ihevcd_cabac_decode_bins_tunary(ps_cabac, ps_bitstrm, 4, ctxt_idx, |
440 | 0 | 0, 3); |
441 | 0 | AEV_TRACE("log2_res_scale_abs_plus1", value, ps_cabac->u4_range); |
442 | |
|
443 | 0 | if(value != 0) |
444 | 0 | { |
445 | 0 | ctxt_idx = IHEVC_CAB_CCP_RES_SIGN_FLAG; |
446 | 0 | TRACE_CABAC_CTXT("res_scale_sign_flag", ps_cabac->u4_range, ctxt_idx); |
447 | 0 | ps_tu->b1_cb_log2_res_sign = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
448 | 0 | AEV_TRACE("res_scale_sign_flag", value, ps_cabac->u4_range); |
449 | 0 | ps_tu->b3_cb_log2_res_scale_abs_plus1 = value; |
450 | 0 | } |
451 | 0 | } |
452 | 895k | #endif |
453 | 895k | if(ps_codec->s_parse.s_cu.ai1_cbf_cb[trafo_depth]) |
454 | 167k | { |
455 | 167k | ps_tu->b1_cb_cbf = 1; |
456 | 167k | ihevcd_parse_residual_coding(ps_codec, x0, y0, log2_trafo_size_c, 1, intra_pred_mode_chroma); |
457 | 167k | } |
458 | 895k | #ifdef ENABLE_MAIN_REXT_PROFILE |
459 | 895k | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422 && ps_codec->s_parse.s_cu.ai1_cbf_cb_subtu[trafo_depth]) |
460 | 0 | { |
461 | 0 | ps_tu->b1_cb_cbf_subtu1 = 1; |
462 | 0 | ihevcd_parse_residual_coding(ps_codec, x0, y0 + (1 << log2_trafo_size_c), log2_trafo_size_c, 1, intra_pred_mode_chroma); |
463 | 0 | } |
464 | 895k | #endif |
465 | 895k | #ifdef ENABLE_MAIN_REXT_PROFILE |
466 | 895k | if(ps_pps->i1_cross_component_prediction_enabled_flag |
467 | 0 | && ps_codec->s_parse.s_cu.i1_cbf_luma |
468 | 0 | && (ps_codec->s_parse.s_cu.i4_pred_mode == PRED_MODE_INTER |
469 | 0 | || chroma_intra_pred_mode_idx == 4)) |
470 | 0 | { |
471 | 0 | ctxt_idx = IHEVC_CAB_CCP_LOG2_RES_ABS + 4; |
472 | 0 | TRACE_CABAC_CTXT("log2_res_scale_abs_plus1", ps_cabac->u4_range, ctxt_idx); |
473 | 0 | value = ihevcd_cabac_decode_bins_tunary(ps_cabac, ps_bitstrm, 4, ctxt_idx, |
474 | 0 | 0, 3); |
475 | 0 | AEV_TRACE("log2_res_scale_abs_plus1", value, ps_cabac->u4_range); |
476 | |
|
477 | 0 | if(value != 0) |
478 | 0 | { |
479 | 0 | ctxt_idx = IHEVC_CAB_CCP_RES_SIGN_FLAG + 1; |
480 | 0 | TRACE_CABAC_CTXT("res_scale_sign_flag", ps_cabac->u4_range, ctxt_idx); |
481 | 0 | ps_tu->b1_cr_log2_res_sign = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
482 | 0 | AEV_TRACE("res_scale_sign_flag", value, ps_cabac->u4_range); |
483 | 0 | ps_tu->b3_cr_log2_res_scale_abs_plus1 = value; |
484 | 0 | } |
485 | 0 | } |
486 | 895k | #endif |
487 | 895k | if(ps_codec->s_parse.s_cu.ai1_cbf_cr[trafo_depth]) |
488 | 164k | { |
489 | 164k | ps_tu->b1_cr_cbf = 1; |
490 | 164k | ihevcd_parse_residual_coding(ps_codec, x0, y0, log2_trafo_size_c, 2, intra_pred_mode_chroma); |
491 | 164k | } |
492 | 895k | #ifdef ENABLE_MAIN_REXT_PROFILE |
493 | 895k | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422 && ps_codec->s_parse.s_cu.ai1_cbf_cr_subtu[trafo_depth]) |
494 | 0 | { |
495 | 0 | ps_tu->b1_cr_cbf_subtu1 = 1; |
496 | 0 | ihevcd_parse_residual_coding(ps_codec, x0, y0 + (1 << log2_trafo_size_c), log2_trafo_size_c, 1, intra_pred_mode_chroma); |
497 | 0 | } |
498 | 895k | #endif |
499 | 895k | } |
500 | 1.32M | else if(blk_idx == 3) |
501 | 331k | { |
502 | 331k | if(ps_codec->s_parse.s_cu.ai1_cbf_cb[trafo_depth]) |
503 | 106k | { |
504 | 106k | ps_tu->b1_cb_cbf = 1; |
505 | 106k | ihevcd_parse_residual_coding(ps_codec, cu_x_base, cu_y_base, log2_trafo_size, 1, intra_pred_mode_chroma); |
506 | 106k | } |
507 | 331k | #ifdef ENABLE_MAIN_REXT_PROFILE |
508 | 331k | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422 && ps_codec->s_parse.s_cu.ai1_cbf_cb_subtu[trafo_depth]) |
509 | 0 | { |
510 | 0 | ps_tu->b1_cb_cbf_subtu1 = 1; |
511 | 0 | ihevcd_parse_residual_coding(ps_codec, x0, y0, log2_trafo_size, 1, intra_pred_mode_chroma); |
512 | 0 | } |
513 | 331k | #endif |
514 | | |
515 | 331k | if(ps_codec->s_parse.s_cu.ai1_cbf_cr[trafo_depth]) |
516 | 105k | { |
517 | 105k | ps_tu->b1_cr_cbf = 1; |
518 | 105k | ihevcd_parse_residual_coding(ps_codec, cu_x_base, cu_y_base, log2_trafo_size, 2, intra_pred_mode_chroma); |
519 | 105k | } |
520 | 331k | #ifdef ENABLE_MAIN_REXT_PROFILE |
521 | 331k | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422 && ps_codec->s_parse.s_cu.ai1_cbf_cr_subtu[trafo_depth]) |
522 | 0 | { |
523 | 0 | ps_tu->b1_cr_cbf_subtu1 = 1; |
524 | 0 | ihevcd_parse_residual_coding(ps_codec, x0, y0, log2_trafo_size, 1, intra_pred_mode_chroma); |
525 | 0 | } |
526 | 331k | #endif |
527 | 331k | } |
528 | 990k | else |
529 | 990k | { |
530 | | //ps_tu->b1_chroma_present = 0; |
531 | 990k | ps_tu->b3_chroma_intra_mode_idx = INTRA_PRED_CHROMA_IDX_NONE; |
532 | 990k | } |
533 | 2.21M | } |
534 | 1.15M | else |
535 | 1.15M | { |
536 | 1.15M | if((3 != blk_idx) && (2 == log2_trafo_size && ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_YUV444)) |
537 | 558k | { |
538 | 558k | ps_tu->b3_chroma_intra_mode_idx = INTRA_PRED_CHROMA_IDX_NONE; |
539 | 558k | } |
540 | 1.15M | } |
541 | | |
542 | | /* Set the first TU in CU flag */ |
543 | 3.36M | { |
544 | 3.36M | if((ps_codec->s_parse.s_cu.i4_pos_x << 3) == (ps_tu->b4_pos_x << 2) && |
545 | 1.86M | (ps_codec->s_parse.s_cu.i4_pos_y << 3) == (ps_tu->b4_pos_y << 2)) |
546 | 1.21M | { |
547 | 1.21M | ps_tu->b1_first_tu_in_cu = 1; |
548 | 1.21M | } |
549 | 2.15M | else |
550 | 2.15M | { |
551 | 2.15M | ps_tu->b1_first_tu_in_cu = 0; |
552 | 2.15M | } |
553 | 3.36M | } |
554 | 3.36M | ps_codec->s_parse.ps_tu++; |
555 | 3.36M | ps_codec->s_parse.s_cu.i4_tu_cnt++; |
556 | 3.36M | ps_codec->s_parse.i4_pic_tu_idx++; |
557 | 3.36M | } |
558 | 4.08M | } |
559 | 4.08M | return ret; |
560 | 4.08M | } |
561 | | /** |
562 | | ******************************************************************************* |
563 | | * |
564 | | * @brief |
565 | | * Parses Motion vector difference |
566 | | * |
567 | | * @par Description: |
568 | | * Parses Motion vector difference as per Section:7.3.9.9 |
569 | | * |
570 | | * @param[in] ps_codec |
571 | | * Pointer to codec context |
572 | | * |
573 | | * @returns Error from IHEVCD_ERROR_T |
574 | | * |
575 | | * @remarks |
576 | | * |
577 | | * |
578 | | ******************************************************************************* |
579 | | */ |
580 | | IHEVCD_ERROR_T ihevcd_parse_mvd(codec_t *ps_codec, mv_t *ps_mv) |
581 | 1.38M | { |
582 | 1.38M | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
583 | 1.38M | WORD32 value; |
584 | 1.38M | WORD32 abs_mvd; |
585 | 1.38M | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
586 | 1.38M | WORD32 abs_mvd_greater0_flag[2]; |
587 | 1.38M | WORD32 abs_mvd_greater1_flag[2]; |
588 | 1.38M | WORD32 ctxt_idx; |
589 | 1.38M | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
590 | | |
591 | | |
592 | 1.38M | ctxt_idx = IHEVC_CAB_MVD_GRT0; |
593 | | /* encode absmvd_x > 0 */ |
594 | 1.38M | TRACE_CABAC_CTXT("abs_mvd_greater0_flag[0]", ps_cabac->u4_range, ctxt_idx); |
595 | 1.38M | abs_mvd_greater0_flag[0] = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
596 | 1.38M | AEV_TRACE("abs_mvd_greater0_flag[0]", abs_mvd_greater0_flag[0], ps_cabac->u4_range); |
597 | | |
598 | | /* encode absmvd_y > 0 */ |
599 | 1.38M | TRACE_CABAC_CTXT("abs_mvd_greater0_flag[1]", ps_cabac->u4_range, ctxt_idx); |
600 | 1.38M | abs_mvd_greater0_flag[1] = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
601 | 1.38M | AEV_TRACE("abs_mvd_greater0_flag[1]", abs_mvd_greater0_flag[1], ps_cabac->u4_range); |
602 | | |
603 | 1.38M | ctxt_idx = IHEVC_CAB_MVD_GRT1; |
604 | 1.38M | abs_mvd_greater1_flag[0] = 0; |
605 | 1.38M | abs_mvd_greater1_flag[1] = 0; |
606 | | |
607 | 1.38M | if(abs_mvd_greater0_flag[0]) |
608 | 817k | { |
609 | 817k | TRACE_CABAC_CTXT("abs_mvd_greater1_flag[0]", ps_cabac->u4_range, ctxt_idx); |
610 | 817k | abs_mvd_greater1_flag[0] = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
611 | 817k | AEV_TRACE("abs_mvd_greater1_flag[0]", abs_mvd_greater1_flag[0], ps_cabac->u4_range); |
612 | 817k | } |
613 | 1.38M | if(abs_mvd_greater0_flag[1]) |
614 | 832k | { |
615 | 832k | TRACE_CABAC_CTXT("abs_mvd_greater1_flag[1]", ps_cabac->u4_range, ctxt_idx); |
616 | 832k | abs_mvd_greater1_flag[1] = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
617 | 832k | AEV_TRACE("abs_mvd_greater1_flag[1]", abs_mvd_greater1_flag[1], ps_cabac->u4_range); |
618 | 832k | } |
619 | 1.38M | abs_mvd = 0; |
620 | 1.38M | if(abs_mvd_greater0_flag[0]) |
621 | 817k | { |
622 | 817k | abs_mvd = 1; |
623 | 817k | if(abs_mvd_greater1_flag[0]) |
624 | 432k | { |
625 | 432k | value = ihevcd_cabac_decode_bypass_bins_egk(ps_cabac, ps_bitstrm, 1); |
626 | 432k | AEV_TRACE("abs_mvd_minus2[0]", value, ps_cabac->u4_range); |
627 | 432k | abs_mvd = value + 2; |
628 | 432k | } |
629 | 817k | value = ihevcd_cabac_decode_bypass_bin(ps_cabac, ps_bitstrm); |
630 | 817k | AEV_TRACE("mvd_sign_flag[0]", value, ps_cabac->u4_range); |
631 | 817k | if(value) |
632 | 416k | { |
633 | 416k | abs_mvd = -abs_mvd; |
634 | 416k | } |
635 | | |
636 | 817k | } |
637 | 1.38M | ps_mv->i2_mvx = abs_mvd; |
638 | 1.38M | abs_mvd = 0; |
639 | 1.38M | if(abs_mvd_greater0_flag[1]) |
640 | 832k | { |
641 | 832k | abs_mvd = 1; |
642 | 832k | if(abs_mvd_greater1_flag[1]) |
643 | 438k | { |
644 | 438k | value = ihevcd_cabac_decode_bypass_bins_egk(ps_cabac, ps_bitstrm, 1); |
645 | 438k | AEV_TRACE("abs_mvd_minus2[1]", value, ps_cabac->u4_range); |
646 | 438k | abs_mvd = value + 2; |
647 | | |
648 | 438k | } |
649 | 832k | value = ihevcd_cabac_decode_bypass_bin(ps_cabac, ps_bitstrm); |
650 | 832k | AEV_TRACE("mvd_sign_flag[1]", value, ps_cabac->u4_range); |
651 | | |
652 | 832k | if(value) |
653 | 420k | { |
654 | 420k | abs_mvd = -abs_mvd; |
655 | 420k | } |
656 | 832k | } |
657 | 1.38M | ps_mv->i2_mvy = abs_mvd; |
658 | | |
659 | 1.38M | return ret; |
660 | 1.38M | } |
661 | | |
662 | | /** |
663 | | ******************************************************************************* |
664 | | * |
665 | | * @brief |
666 | | * Parses PCM sample |
667 | | * |
668 | | * |
669 | | * @par Description: |
670 | | * Parses PCM sample as per Section:7.3.9.7 Pcm sample syntax |
671 | | * |
672 | | * @param[in] ps_codec |
673 | | * Pointer to codec context |
674 | | * |
675 | | * @returns Error from IHEVCD_ERROR_T |
676 | | * |
677 | | * @remarks |
678 | | * |
679 | | * |
680 | | ******************************************************************************* |
681 | | */ |
682 | | |
683 | | IHEVCD_ERROR_T ihevcd_parse_pcm_sample(codec_t *ps_codec, |
684 | | WORD32 x0, |
685 | | WORD32 y0, |
686 | | WORD32 log2_cb_size) |
687 | 86 | { |
688 | 86 | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
689 | 86 | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
690 | 86 | sps_t *ps_sps; |
691 | | |
692 | 86 | WORD32 value; |
693 | 86 | WORD32 i; |
694 | | |
695 | 86 | WORD32 num_bits; |
696 | 86 | UWORD32 u4_sig_coeff_map; |
697 | 86 | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
698 | 86 | tu_t *ps_tu = ps_codec->s_parse.ps_tu; |
699 | 86 | tu_sblk_coeff_data_t *ps_tu_sblk_coeff_data; |
700 | 86 | UWORD8 *pu1_coeff_data; |
701 | 86 | ps_sps = ps_codec->s_parse.ps_sps; |
702 | | |
703 | 86 | UNUSED(value); |
704 | 86 | UNUSED(ps_tu); |
705 | 86 | UNUSED(ps_cabac); |
706 | 86 | UNUSED(x0); |
707 | 86 | UNUSED(y0); |
708 | | |
709 | 86 | { |
710 | 86 | WORD8 *pi1_scan_idx; |
711 | 86 | WORD8 *pi1_buf = (WORD8 *)ps_codec->s_parse.pv_tu_coeff_data; |
712 | 86 | WORD8 *pi1_num_coded_subblks; |
713 | | |
714 | | /* First WORD8 gives number of coded subblocks */ |
715 | 86 | pi1_num_coded_subblks = pi1_buf++; |
716 | | |
717 | | /* Set number of coded subblocks in the current TU to zero */ |
718 | | /* For PCM there will be only one subblock which is the same size as CU */ |
719 | 86 | *pi1_num_coded_subblks = 1; |
720 | | |
721 | | /* Second WORD8 gives (scan idx << 1) | trans_skip */ |
722 | 86 | pi1_scan_idx = pi1_buf++; |
723 | 86 | *pi1_scan_idx = (0 << 1) | 1; |
724 | | |
725 | | /* Store the incremented pointer in pv_tu_coeff_data */ |
726 | 86 | ps_codec->s_parse.pv_tu_coeff_data = pi1_buf; |
727 | | |
728 | 86 | } |
729 | | |
730 | 86 | u4_sig_coeff_map = 0xFFFFFFFF; |
731 | 86 | ps_tu_sblk_coeff_data = (tu_sblk_coeff_data_t *)ps_codec->s_parse.pv_tu_coeff_data; |
732 | 86 | ps_tu_sblk_coeff_data->u2_sig_coeff_map = u4_sig_coeff_map; |
733 | 86 | ps_tu_sblk_coeff_data->u2_subblk_pos = 0; |
734 | | |
735 | 86 | pu1_coeff_data = (UWORD8 *)&ps_tu_sblk_coeff_data->ai2_level[0]; |
736 | | |
737 | 86 | num_bits = ps_sps->i1_pcm_sample_bit_depth_luma; |
738 | | |
739 | 86 | WORD32 luma_samples = 1 << (log2_cb_size << 1); |
740 | 10.9k | for(i = 0; i < luma_samples; i++) |
741 | 10.8k | { |
742 | 10.8k | TRACE_CABAC_CTXT("pcm_sample_luma", ps_cabac->u4_range, 0); |
743 | 10.8k | BITS_PARSE("pcm_sample_luma", value, ps_bitstrm, num_bits); |
744 | | |
745 | | //ps_pcmsample_t->i1_pcm_sample_luma[i] = value; |
746 | 10.8k | *pu1_coeff_data++ = value << (BIT_DEPTH_LUMA - num_bits); |
747 | 10.8k | } |
748 | | |
749 | 86 | if(CHROMA_FMT_IDC_MONOCHROME != ps_sps->i1_chroma_format_idc) |
750 | 86 | { |
751 | 86 | WORD32 chroma_samples = 0; |
752 | | |
753 | 86 | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
754 | 0 | chroma_samples = luma_samples << 1; |
755 | 86 | else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) |
756 | 0 | chroma_samples = luma_samples; |
757 | 86 | else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV420) |
758 | 86 | chroma_samples = luma_samples >> 1; |
759 | 86 | num_bits = ps_sps->i1_pcm_sample_bit_depth_chroma; |
760 | 5.52k | for(i = 0; i < chroma_samples; i++) |
761 | 5.44k | { |
762 | 5.44k | TRACE_CABAC_CTXT("pcm_sample_chroma", ps_cabac->u4_range, 0); |
763 | 5.44k | BITS_PARSE("pcm_sample_chroma", value, ps_bitstrm, num_bits); |
764 | | |
765 | | // ps_pcmsample_t->i1_pcm_sample_chroma[i] = value; |
766 | 5.44k | *pu1_coeff_data++ = value << (BIT_DEPTH_CHROMA - num_bits); |
767 | 5.44k | } |
768 | 86 | } |
769 | | |
770 | 86 | ps_codec->s_parse.pv_tu_coeff_data = pu1_coeff_data; |
771 | | |
772 | 86 | return ret; |
773 | 86 | } |
774 | | /** |
775 | | ******************************************************************************* |
776 | | * |
777 | | * @brief |
778 | | * Parses Prediction unit |
779 | | * |
780 | | * @par Description: |
781 | | * Parses Prediction unit as per Section:7.3.9.6 |
782 | | * |
783 | | * @param[in] ps_codec |
784 | | * Pointer to codec context |
785 | | * |
786 | | * @returns Error from IHEVCD_ERROR_T |
787 | | * |
788 | | * @remarks |
789 | | * |
790 | | * |
791 | | ******************************************************************************* |
792 | | */ |
793 | | |
794 | | IHEVCD_ERROR_T ihevcd_parse_pu_mvp(codec_t *ps_codec, pu_t *ps_pu) |
795 | 1.25M | { |
796 | 1.25M | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
797 | 1.25M | WORD32 value; |
798 | 1.25M | slice_header_t *ps_slice_hdr; |
799 | 1.25M | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
800 | 1.25M | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
801 | 1.25M | WORD32 inter_pred_idc; |
802 | | |
803 | 1.25M | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr; |
804 | | |
805 | 1.25M | if(ps_slice_hdr->i1_slice_type == BSLICE) |
806 | 1.24M | { |
807 | 1.24M | WORD32 pu_w_plus_pu_h; |
808 | 1.24M | WORD32 ctxt_idx; |
809 | | /* required to check if w+h==12 case */ |
810 | 1.24M | pu_w_plus_pu_h = ((ps_pu->b4_wd + 1) << 2) + ((ps_pu->b4_ht + 1) << 2); |
811 | 1.24M | if(12 == pu_w_plus_pu_h) |
812 | 669k | { |
813 | 669k | ctxt_idx = IHEVC_CAB_INTER_PRED_IDC + 4; |
814 | 669k | TRACE_CABAC_CTXT("inter_pred_idc", ps_cabac->u4_range, ctxt_idx); |
815 | 669k | inter_pred_idc = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, |
816 | 669k | ctxt_idx); |
817 | 669k | } |
818 | 572k | else |
819 | 572k | { |
820 | | /* larger PUs can be encoded as bi_pred/l0/l1 inter_pred_idc */ |
821 | 572k | WORD32 is_bipred; |
822 | | |
823 | 572k | ctxt_idx = IHEVC_CAB_INTER_PRED_IDC + ps_codec->s_parse.i4_ct_depth; |
824 | 572k | TRACE_CABAC_CTXT("inter_pred_idc", ps_cabac->u4_range, ctxt_idx); |
825 | 572k | is_bipred = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
826 | 572k | inter_pred_idc = PRED_BI; |
827 | 572k | if(!is_bipred) |
828 | 383k | { |
829 | 383k | ctxt_idx = IHEVC_CAB_INTER_PRED_IDC + 4; |
830 | 383k | inter_pred_idc = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, |
831 | 383k | ctxt_idx); |
832 | 383k | } |
833 | 572k | } |
834 | | |
835 | 1.24M | AEV_TRACE("inter_pred_idc", inter_pred_idc, ps_cabac->u4_range); |
836 | 1.24M | } |
837 | 13.4k | else |
838 | 13.4k | inter_pred_idc = PRED_L0; |
839 | 1.25M | ps_pu->mv.i1_l0_ref_idx = 0; |
840 | 1.25M | ps_pu->mv.i1_l1_ref_idx = 0; |
841 | | /* Decode MVD for L0 for PRED_L0 or PRED_BI */ |
842 | 1.25M | if(inter_pred_idc != PRED_L1) |
843 | 1.02M | { |
844 | 1.02M | WORD32 active_refs = ps_slice_hdr->i1_num_ref_idx_l0_active; |
845 | 1.02M | WORD32 ref_idx = 0; |
846 | 1.02M | WORD32 ctxt_idx; |
847 | | |
848 | 1.02M | if(active_refs > 1) |
849 | 790k | { |
850 | 790k | ctxt_idx = IHEVC_CAB_INTER_REF_IDX; |
851 | | /* encode the context modelled first bin */ |
852 | 790k | TRACE_CABAC_CTXT("ref_idx", ps_cabac->u4_range, ctxt_idx); |
853 | 790k | ref_idx = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
854 | | |
855 | 790k | if((active_refs > 2) && ref_idx) |
856 | 46.4k | { |
857 | 46.4k | WORD32 value; |
858 | | /* encode the context modelled second bin */ |
859 | 46.4k | ctxt_idx++; |
860 | 46.4k | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
861 | 46.4k | ref_idx += value; |
862 | 46.4k | if((active_refs > 3) && value) |
863 | 25.2k | { |
864 | | /* encode remaining bypass bins */ |
865 | 25.2k | ref_idx = ihevcd_cabac_decode_bypass_bins_tunary(ps_cabac, |
866 | 25.2k | ps_bitstrm, |
867 | 25.2k | (active_refs - 3) |
868 | 25.2k | ); |
869 | 25.2k | ref_idx += 2; |
870 | 25.2k | } |
871 | 46.4k | } |
872 | 790k | AEV_TRACE("ref_idx", ref_idx, ps_cabac->u4_range); |
873 | 790k | } |
874 | | |
875 | 1.02M | ref_idx = CLIP3(ref_idx, 0, MAX_DPB_SIZE - 1); |
876 | 1.02M | ps_pu->mv.i1_l0_ref_idx = ref_idx; |
877 | | |
878 | 1.02M | ihevcd_parse_mvd(ps_codec, &ps_pu->mv.s_l0_mv); |
879 | | |
880 | 1.02M | ctxt_idx = IHEVC_CAB_MVP_L0L1; |
881 | 1.02M | value = ihevcd_cabac_decode_bin(ps_cabac, |
882 | 1.02M | ps_bitstrm, |
883 | 1.02M | ctxt_idx); |
884 | | |
885 | 1.02M | AEV_TRACE("mvp_l0/l1_flag", value, ps_cabac->u4_range); |
886 | | |
887 | 1.02M | ps_pu->b1_l0_mvp_idx = value; |
888 | | |
889 | 1.02M | } |
890 | | /* Decode MVD for L1 for PRED_L1 or PRED_BI */ |
891 | 1.25M | if(inter_pred_idc != PRED_L0) |
892 | 420k | { |
893 | 420k | WORD32 active_refs = ps_slice_hdr->i1_num_ref_idx_l1_active; |
894 | 420k | WORD32 ref_idx = 0; |
895 | 420k | WORD32 ctxt_idx; |
896 | | |
897 | 420k | if(active_refs > 1) |
898 | 362k | { |
899 | | |
900 | 362k | ctxt_idx = IHEVC_CAB_INTER_REF_IDX; |
901 | 362k | TRACE_CABAC_CTXT("ref_idx", ps_cabac->u4_range, ctxt_idx); |
902 | | /* encode the context modelled first bin */ |
903 | 362k | ref_idx = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
904 | | |
905 | 362k | if((active_refs > 2) && ref_idx) |
906 | 9.04k | { |
907 | 9.04k | WORD32 value; |
908 | | /* encode the context modelled second bin */ |
909 | 9.04k | ctxt_idx++; |
910 | 9.04k | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
911 | 9.04k | ref_idx += value; |
912 | 9.04k | if((active_refs > 3) && value) |
913 | 5.32k | { |
914 | | /* encode remaining bypass bins */ |
915 | 5.32k | ref_idx = ihevcd_cabac_decode_bypass_bins_tunary(ps_cabac, |
916 | 5.32k | ps_bitstrm, |
917 | 5.32k | (active_refs - 3) |
918 | 5.32k | ); |
919 | 5.32k | ref_idx += 2; |
920 | 5.32k | } |
921 | 9.04k | } |
922 | | |
923 | 362k | AEV_TRACE("ref_idx", ref_idx, ps_cabac->u4_range); |
924 | 362k | } |
925 | | |
926 | 420k | ref_idx = CLIP3(ref_idx, 0, MAX_DPB_SIZE - 1); |
927 | 420k | ps_pu->mv.i1_l1_ref_idx = ref_idx; |
928 | | |
929 | 420k | if(ps_slice_hdr->i1_mvd_l1_zero_flag && inter_pred_idc == PRED_BI) |
930 | 60.0k | { |
931 | 60.0k | ps_pu->mv.s_l1_mv.i2_mvx = 0; |
932 | 60.0k | ps_pu->mv.s_l1_mv.i2_mvy = 0; |
933 | 60.0k | } |
934 | 360k | else |
935 | 360k | { |
936 | 360k | ihevcd_parse_mvd(ps_codec, &ps_pu->mv.s_l1_mv); |
937 | 360k | } |
938 | | |
939 | 420k | ctxt_idx = IHEVC_CAB_MVP_L0L1; |
940 | 420k | value = ihevcd_cabac_decode_bin(ps_cabac, |
941 | 420k | ps_bitstrm, |
942 | 420k | ctxt_idx); |
943 | | |
944 | 420k | AEV_TRACE("mvp_l0/l1_flag", value, ps_cabac->u4_range); |
945 | 420k | ps_pu->b1_l1_mvp_idx = value; |
946 | | |
947 | 420k | } |
948 | | |
949 | 1.25M | ps_pu->b2_pred_mode = inter_pred_idc; |
950 | 1.25M | return ret; |
951 | 1.25M | } |
952 | | /** |
953 | | ******************************************************************************* |
954 | | * |
955 | | * @brief |
956 | | * Parses Prediction unit |
957 | | * |
958 | | * @par Description: |
959 | | * Parses Prediction unit as per Section:7.3.9.6 |
960 | | * |
961 | | * @param[in] ps_codec |
962 | | * Pointer to codec context |
963 | | * |
964 | | * @returns Error from IHEVCD_ERROR_T |
965 | | * |
966 | | * @remarks |
967 | | * |
968 | | * |
969 | | ******************************************************************************* |
970 | | */ |
971 | | |
972 | | IHEVCD_ERROR_T ihevcd_parse_prediction_unit(codec_t *ps_codec, |
973 | | WORD32 x0, |
974 | | WORD32 y0, |
975 | | WORD32 wd, |
976 | | WORD32 ht) |
977 | 4.22M | { |
978 | 4.22M | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
979 | 4.22M | slice_header_t *ps_slice_hdr; |
980 | 4.22M | sps_t *ps_sps; |
981 | 4.22M | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
982 | 4.22M | WORD32 ctb_x_base; |
983 | 4.22M | WORD32 ctb_y_base; |
984 | | |
985 | 4.22M | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
986 | 4.22M | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
987 | | |
988 | 4.22M | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr; |
989 | | |
990 | | /* Set PU structure to default values */ |
991 | 4.22M | memset(ps_pu, 0, sizeof(pu_t)); |
992 | | |
993 | 4.22M | ps_sps = ps_codec->s_parse.ps_sps; |
994 | 4.22M | ctb_x_base = ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size; |
995 | 4.22M | ctb_y_base = ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size; |
996 | | |
997 | 4.22M | ps_pu->b4_pos_x = (x0 - ctb_x_base) >> 2; |
998 | 4.22M | ps_pu->b4_pos_y = (y0 - ctb_y_base) >> 2; |
999 | 4.22M | ps_pu->b4_wd = (wd >> 2) - 1; |
1000 | 4.22M | ps_pu->b4_ht = (ht >> 2) - 1; |
1001 | | |
1002 | 4.22M | ps_pu->b1_intra_flag = 0; |
1003 | 4.22M | ps_pu->b3_part_mode = ps_codec->s_parse.s_cu.i4_part_mode; |
1004 | | |
1005 | 4.22M | if(PRED_MODE_SKIP == ps_codec->s_parse.s_cu.i4_pred_mode) |
1006 | 2.04M | { |
1007 | 2.04M | WORD32 merge_idx = 0; |
1008 | 2.04M | if(ps_slice_hdr->i1_max_num_merge_cand > 1) |
1009 | 2.04M | { |
1010 | 2.04M | WORD32 ctxt_idx = IHEVC_CAB_MERGE_IDX_EXT; |
1011 | 2.04M | WORD32 bin; |
1012 | | |
1013 | 2.04M | TRACE_CABAC_CTXT("merge_idx", ps_cabac->u4_range, ctxt_idx); |
1014 | 2.04M | bin = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
1015 | 2.04M | if(bin) |
1016 | 733k | { |
1017 | 733k | if(ps_slice_hdr->i1_max_num_merge_cand > 2) |
1018 | 672k | { |
1019 | 672k | merge_idx = ihevcd_cabac_decode_bypass_bins_tunary( |
1020 | 672k | ps_cabac, ps_bitstrm, |
1021 | 672k | (ps_slice_hdr->i1_max_num_merge_cand - 2)); |
1022 | 672k | } |
1023 | 733k | merge_idx++; |
1024 | 733k | } |
1025 | 2.04M | AEV_TRACE("merge_idx", merge_idx, ps_cabac->u4_range); |
1026 | 2.04M | } |
1027 | 2.04M | ps_pu->b1_merge_flag = 1; |
1028 | 2.04M | ps_pu->b3_merge_idx = merge_idx; |
1029 | | |
1030 | 2.04M | } |
1031 | 2.17M | else |
1032 | 2.17M | { |
1033 | | /* MODE_INTER */ |
1034 | 2.17M | WORD32 merge_flag; |
1035 | 2.17M | WORD32 ctxt_idx = IHEVC_CAB_MERGE_FLAG_EXT; |
1036 | 2.17M | TRACE_CABAC_CTXT("merge_flag", ps_cabac->u4_range, ctxt_idx); |
1037 | 2.17M | merge_flag = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
1038 | 2.17M | AEV_TRACE("merge_flag", merge_flag, ps_cabac->u4_range); |
1039 | | |
1040 | 2.17M | ps_pu->b1_merge_flag = merge_flag; |
1041 | | |
1042 | 2.17M | if(merge_flag) |
1043 | 922k | { |
1044 | 922k | WORD32 merge_idx = 0; |
1045 | 922k | if(ps_slice_hdr->i1_max_num_merge_cand > 1) |
1046 | 922k | { |
1047 | 922k | WORD32 ctxt_idx = IHEVC_CAB_MERGE_IDX_EXT; |
1048 | 922k | WORD32 bin; |
1049 | 922k | TRACE_CABAC_CTXT("merge_idx", ps_cabac->u4_range, ctxt_idx); |
1050 | 922k | bin = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
1051 | 922k | if(bin) |
1052 | 357k | { |
1053 | 357k | if(ps_slice_hdr->i1_max_num_merge_cand > 2) |
1054 | 353k | { |
1055 | 353k | merge_idx = ihevcd_cabac_decode_bypass_bins_tunary( |
1056 | 353k | ps_cabac, ps_bitstrm, |
1057 | 353k | (ps_slice_hdr->i1_max_num_merge_cand - 2)); |
1058 | 353k | } |
1059 | 357k | merge_idx++; |
1060 | 357k | } |
1061 | 922k | AEV_TRACE("merge_idx", merge_idx, ps_cabac->u4_range); |
1062 | 922k | } |
1063 | | |
1064 | 922k | ps_pu->b3_merge_idx = merge_idx; |
1065 | 922k | } |
1066 | 1.25M | else |
1067 | 1.25M | { |
1068 | 1.25M | ihevcd_parse_pu_mvp(ps_codec, ps_pu); |
1069 | 1.25M | } |
1070 | | |
1071 | 2.17M | } |
1072 | 4.22M | STATS_UPDATE_PU_SIZE(ps_pu); |
1073 | | /* Increment PU pointer */ |
1074 | 4.22M | ps_codec->s_parse.ps_pu++; |
1075 | 4.22M | ps_codec->s_parse.i4_pic_pu_idx++; |
1076 | 4.22M | return ret; |
1077 | 4.22M | } |
1078 | | |
1079 | | |
1080 | | WORD32 ihevcd_parse_part_mode_amp(cab_ctxt_t *ps_cabac, bitstrm_t *ps_bitstrm) |
1081 | 369k | { |
1082 | 369k | WORD32 ctxt_idx = IHEVC_CAB_PART_MODE; |
1083 | 369k | WORD32 part_mode_idx; |
1084 | 369k | WORD32 part_mode; |
1085 | 369k | WORD32 bin; |
1086 | | |
1087 | 369k | part_mode = 0; |
1088 | 369k | TRACE_CABAC_CTXT("part_mode", ps_cabac->u4_range, ctxt_idx); |
1089 | 369k | bin = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx++); |
1090 | | |
1091 | 369k | if(!bin) |
1092 | 231k | { |
1093 | 231k | bin = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx++); |
1094 | 231k | part_mode_idx = bin; |
1095 | 231k | part_mode_idx <<= 1; |
1096 | | |
1097 | | /* Following takes of handling context increment for 3rd bin in part_mode */ |
1098 | | /* When AMP is enabled and the current is not min CB */ |
1099 | | /* Context for 3rd bin is 3 and not 2 */ |
1100 | 231k | ctxt_idx += 1; |
1101 | | |
1102 | 231k | bin = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
1103 | 231k | part_mode_idx |= bin; |
1104 | | |
1105 | 231k | part_mode_idx <<= 1; |
1106 | 231k | if(!bin) |
1107 | 118k | { |
1108 | | |
1109 | 118k | bin = ihevcd_cabac_decode_bypass_bin(ps_cabac, ps_bitstrm); |
1110 | 118k | part_mode_idx |= bin; |
1111 | 118k | } |
1112 | 231k | part_mode = gau1_part_mode_amp[part_mode_idx]; |
1113 | 231k | } |
1114 | 369k | return part_mode; |
1115 | 369k | } |
1116 | | IHEVCD_ERROR_T ihevcd_parse_coding_unit_intra(codec_t *ps_codec, |
1117 | | WORD32 x0, |
1118 | | WORD32 y0, |
1119 | | WORD32 log2_cb_size) |
1120 | 825k | { |
1121 | 825k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
1122 | 825k | sps_t *ps_sps; |
1123 | 825k | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
1124 | 825k | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
1125 | 825k | WORD32 pcm_flag; |
1126 | 825k | WORD32 value; |
1127 | 825k | WORD32 cb_size = 1 << log2_cb_size; |
1128 | 825k | WORD32 part_mode = ps_codec->s_parse.s_cu.i4_part_mode; |
1129 | 825k | tu_t *ps_tu = ps_codec->s_parse.ps_tu; |
1130 | 825k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1131 | 825k | WORD32 ctb_x_base; |
1132 | 825k | WORD32 ctb_y_base; |
1133 | 825k | ps_sps = ps_codec->s_parse.ps_sps; |
1134 | 825k | ctb_x_base = ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size; |
1135 | 825k | ctb_y_base = ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size; |
1136 | | |
1137 | 825k | memset(ps_pu, 0, sizeof(pu_t)); |
1138 | 825k | ps_pu->b1_intra_flag = 1; |
1139 | 825k | ps_pu->b4_wd = (cb_size >> 2) - 1; |
1140 | 825k | ps_pu->b4_ht = (cb_size >> 2) - 1; |
1141 | 825k | ps_pu->b4_pos_x = (x0 - ctb_x_base) >> 2; |
1142 | 825k | ps_pu->b4_pos_y = (y0 - ctb_y_base) >> 2; |
1143 | | |
1144 | 825k | pcm_flag = 0; |
1145 | 825k | if((PART_2Nx2N == part_mode) && (ps_sps->i1_pcm_enabled_flag) |
1146 | 29.7k | && (log2_cb_size |
1147 | 29.7k | >= ps_sps->i1_log2_min_pcm_coding_block_size) |
1148 | 29.5k | && (log2_cb_size |
1149 | 29.5k | <= (ps_sps->i1_log2_min_pcm_coding_block_size + ps_sps->i1_log2_diff_max_min_pcm_coding_block_size))) |
1150 | 25.6k | { |
1151 | 25.6k | TRACE_CABAC_CTXT("pcm_flag", ps_cabac->u4_range, 0); |
1152 | 25.6k | pcm_flag = ihevcd_cabac_decode_terminate(ps_cabac, ps_bitstrm); |
1153 | 25.6k | AEV_TRACE("pcm_flag", pcm_flag, ps_cabac->u4_range); |
1154 | 25.6k | } |
1155 | | |
1156 | 825k | ps_codec->s_parse.i4_cu_pcm_flag = pcm_flag; |
1157 | 825k | if(pcm_flag) |
1158 | 86 | { |
1159 | 86 | UWORD8 *pu1_luma_intra_pred_mode_top, *pu1_luma_intra_pred_mode_left; |
1160 | 86 | WORD32 i, num_pred_blocks; |
1161 | | |
1162 | 86 | if(ps_codec->s_parse.s_bitstrm.u4_bit_ofst % 8) |
1163 | 80 | { |
1164 | 80 | TRACE_CABAC_CTXT("pcm_alignment_zero_bit", ps_cabac->u4_range, 0); |
1165 | 80 | ihevcd_bits_flush_to_byte_boundary(&ps_codec->s_parse.s_bitstrm); |
1166 | 80 | AEV_TRACE("pcm_alignment_zero_bit", 0, ps_cabac->u4_range); |
1167 | 80 | } |
1168 | | |
1169 | 86 | ihevcd_parse_pcm_sample(ps_codec, x0, y0, log2_cb_size); |
1170 | | |
1171 | 86 | ihevcd_cabac_reset(&ps_codec->s_parse.s_cabac, |
1172 | 86 | &ps_codec->s_parse.s_bitstrm); |
1173 | | |
1174 | 86 | ps_tu = ps_codec->s_parse.ps_tu; |
1175 | 86 | ps_tu->b1_cb_cbf = 1; |
1176 | 86 | #ifdef ENABLE_MAIN_REXT_PROFILE |
1177 | 86 | ps_tu->b1_cb_cbf_subtu1 = 1; |
1178 | 86 | #endif |
1179 | 86 | ps_tu->b1_cr_cbf = 1; |
1180 | 86 | #ifdef ENABLE_MAIN_REXT_PROFILE |
1181 | 86 | ps_tu->b1_cr_cbf_subtu1 = 1; |
1182 | 86 | #endif |
1183 | 86 | ps_tu->b1_y_cbf = 1; |
1184 | 86 | ps_tu->b4_pos_x = ((x0 - ctb_x_base) >> 2); |
1185 | 86 | ps_tu->b4_pos_y = ((y0 - ctb_y_base) >> 2); |
1186 | 86 | ps_tu->b1_transquant_bypass = 1; |
1187 | 86 | ps_tu->b3_size = (log2_cb_size - 2); |
1188 | 86 | ps_tu->b7_qp = ps_codec->s_parse.u4_qp; |
1189 | 86 | ps_tu->b3_chroma_intra_mode_idx = INTRA_PRED_CHROMA_IDX_NONE; |
1190 | 86 | ps_tu->b6_luma_intra_mode = INTRA_PRED_NONE; |
1191 | 86 | #ifdef ENABLE_MAIN_REXT_PROFILE |
1192 | 86 | ps_tu->b3_cb_log2_res_scale_abs_plus1 = 0; |
1193 | 86 | ps_tu->b1_cb_log2_res_sign = 0; |
1194 | 86 | ps_tu->b3_cr_log2_res_scale_abs_plus1 = 0; |
1195 | 86 | ps_tu->b1_cr_log2_res_sign = 0; |
1196 | 86 | #endif |
1197 | | |
1198 | | /* Set the first TU in CU flag */ |
1199 | 86 | { |
1200 | 86 | if((ps_codec->s_parse.s_cu.i4_pos_x << 3) == (ps_tu->b4_pos_x << 2) && |
1201 | 86 | (ps_codec->s_parse.s_cu.i4_pos_y << 3) == (ps_tu->b4_pos_y << 2)) |
1202 | 86 | { |
1203 | 86 | ps_tu->b1_first_tu_in_cu = 1; |
1204 | 86 | } |
1205 | 0 | else |
1206 | 0 | { |
1207 | 0 | ps_tu->b1_first_tu_in_cu = 0; |
1208 | 0 | } |
1209 | 86 | } |
1210 | | |
1211 | | /* Update the intra pred mode for PCM to INTRA_DC(default mode) */ |
1212 | 86 | pu1_luma_intra_pred_mode_top = ps_codec->s_parse.pu1_luma_intra_pred_mode_top |
1213 | 86 | + (ps_codec->s_parse.s_cu.i4_pos_x * 2); |
1214 | | |
1215 | 86 | pu1_luma_intra_pred_mode_left = ps_codec->s_parse.pu1_luma_intra_pred_mode_left |
1216 | 86 | + (ps_codec->s_parse.s_cu.i4_pos_y * 2); |
1217 | | |
1218 | 86 | num_pred_blocks = 1; /* Because PCM part mode will be 2Nx2N */ |
1219 | | |
1220 | 86 | ps_codec->s_func_selector.ihevc_memset_fptr(pu1_luma_intra_pred_mode_left, INTRA_DC, (cb_size / num_pred_blocks) / MIN_PU_SIZE); |
1221 | 86 | ps_codec->s_func_selector.ihevc_memset_fptr(pu1_luma_intra_pred_mode_top, INTRA_DC, (cb_size / num_pred_blocks) / MIN_PU_SIZE); |
1222 | | |
1223 | | |
1224 | | /* Set no_loop_filter appropriately */ |
1225 | 86 | if(1 == ps_sps->i1_pcm_loop_filter_disable_flag) |
1226 | 54 | { |
1227 | 54 | UWORD8 *pu1_pic_no_loop_filter_flag; |
1228 | 54 | WORD32 numbytes_row; |
1229 | 54 | UWORD32 u4_mask; |
1230 | | |
1231 | 54 | pu1_pic_no_loop_filter_flag = ps_codec->s_parse.pu1_pic_no_loop_filter_flag; |
1232 | 54 | numbytes_row = (ps_sps->i2_pic_width_in_luma_samples + 63) / 64; |
1233 | 54 | pu1_pic_no_loop_filter_flag += (y0 / 8) * numbytes_row; |
1234 | 54 | pu1_pic_no_loop_filter_flag += (x0 / 64); |
1235 | | /* Generate (cb_size / 8) number of 1s */ |
1236 | | /* i.e (log2_cb_size - 2) number of 1s */ |
1237 | 54 | u4_mask = LSB_ONES((cb_size >> 3)); |
1238 | 123 | for(i = 0; i < (cb_size / 8); i++) |
1239 | 69 | { |
1240 | 69 | *pu1_pic_no_loop_filter_flag |= (u4_mask << (((x0) / 8) % 8)); |
1241 | 69 | pu1_pic_no_loop_filter_flag += numbytes_row; |
1242 | 69 | } |
1243 | 54 | } |
1244 | | /* Increment ps_tu and tu_idx */ |
1245 | 86 | ps_codec->s_parse.ps_tu++; |
1246 | 86 | ps_codec->s_parse.s_cu.i4_tu_cnt++; |
1247 | 86 | ps_codec->s_parse.i4_pic_tu_idx++; |
1248 | | |
1249 | 86 | } |
1250 | 825k | else |
1251 | 825k | { |
1252 | 825k | WORD32 cnt = 0; |
1253 | 825k | WORD32 i; |
1254 | 825k | WORD32 part_cnt; |
1255 | | |
1256 | 825k | part_cnt = (part_mode == PART_NxN) ? 4 : 1; |
1257 | | |
1258 | 2.55M | for(i = 0; i < part_cnt; i++) |
1259 | 1.73M | { |
1260 | 1.73M | TRACE_CABAC_CTXT("prev_intra_pred_luma_flag", ps_cabac->u4_range, IHEVC_CAB_INTRA_LUMA_PRED_FLAG); |
1261 | 1.73M | value = ihevcd_cabac_decode_bin(ps_cabac, |
1262 | 1.73M | ps_bitstrm, |
1263 | 1.73M | IHEVC_CAB_INTRA_LUMA_PRED_FLAG); |
1264 | | |
1265 | 1.73M | ps_codec->s_parse.s_cu.ai4_prev_intra_luma_pred_flag[i] = |
1266 | 1.73M | value; |
1267 | 1.73M | AEV_TRACE("prev_intra_pred_luma_flag", value, ps_cabac->u4_range); |
1268 | 1.73M | } |
1269 | | |
1270 | 2.55M | for(i = 0; i < part_cnt; i++) |
1271 | 1.73M | { |
1272 | 1.73M | if(ps_codec->s_parse.s_cu.ai4_prev_intra_luma_pred_flag[cnt]) |
1273 | 937k | { |
1274 | 937k | value = ihevcd_cabac_decode_bypass_bins_tunary(ps_cabac, ps_bitstrm, 2); |
1275 | 937k | AEV_TRACE("mpm_idx", value, ps_cabac->u4_range); |
1276 | 937k | ps_codec->s_parse.s_cu.ai4_mpm_idx[cnt] = value; |
1277 | 937k | } |
1278 | 793k | else |
1279 | 793k | { |
1280 | 793k | value = ihevcd_cabac_decode_bypass_bins(ps_cabac, ps_bitstrm, 5); |
1281 | 793k | AEV_TRACE("rem_intra_luma_pred_mode", value, |
1282 | 793k | ps_cabac->u4_range); |
1283 | 793k | ps_codec->s_parse.s_cu.ai4_rem_intra_luma_pred_mode[cnt] = |
1284 | 793k | value; |
1285 | 793k | } |
1286 | 1.73M | cnt++; |
1287 | 1.73M | } |
1288 | 825k | if(CHROMA_FMT_IDC_YUV444 == ps_sps->i1_chroma_format_idc) |
1289 | 0 | { |
1290 | 0 | for(i = 0; i < part_cnt; i++) |
1291 | 0 | { |
1292 | 0 | TRACE_CABAC_CTXT("intra_chroma_pred_mode", ps_cabac->u4_range, IHEVC_CAB_CHROMA_PRED_MODE); |
1293 | 0 | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, |
1294 | 0 | IHEVC_CAB_CHROMA_PRED_MODE); |
1295 | 0 | ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[i] = 4; |
1296 | 0 | if(value) |
1297 | 0 | { |
1298 | 0 | ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[i] = |
1299 | 0 | ihevcd_cabac_decode_bypass_bins(ps_cabac, |
1300 | 0 | ps_bitstrm, |
1301 | 0 | 2); |
1302 | 0 | } |
1303 | 0 | AEV_TRACE("intra_chroma_pred_mode", |
1304 | 0 | ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[i], |
1305 | 0 | ps_cabac->u4_range); |
1306 | 0 | } |
1307 | 0 | } |
1308 | 825k | else if(CHROMA_FMT_IDC_MONOCHROME != ps_sps->i1_chroma_format_idc) |
1309 | 825k | { |
1310 | 825k | TRACE_CABAC_CTXT("intra_chroma_pred_mode", ps_cabac->u4_range, IHEVC_CAB_CHROMA_PRED_MODE); |
1311 | 825k | value = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, |
1312 | 825k | IHEVC_CAB_CHROMA_PRED_MODE); |
1313 | 825k | ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[0] = 4; |
1314 | 825k | if (value) { |
1315 | 217k | ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[0] = |
1316 | 217k | ihevcd_cabac_decode_bypass_bins(ps_cabac, ps_bitstrm, |
1317 | 217k | 2); |
1318 | 217k | } |
1319 | 825k | AEV_TRACE("intra_chroma_pred_mode", |
1320 | 825k | ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[0], |
1321 | 825k | ps_cabac->u4_range); |
1322 | | |
1323 | 825k | } |
1324 | 825k | ihevcd_intra_pred_mode_prediction(ps_codec, log2_cb_size, x0, y0); |
1325 | | |
1326 | 825k | if(CHROMA_FMT_IDC_MONOCHROME != ps_sps->i1_chroma_format_idc && part_mode != PART_NxN) |
1327 | 523k | { |
1328 | | // Only required for YUV444, but done for all formats to simplify calling arguments for ihevcd_parse_transform_tree |
1329 | 523k | parse_cu_t *ps_cu = &ps_codec->s_parse.s_cu; |
1330 | 523k | ps_cu->ai4_intra_chroma_pred_mode_idx[1] = ps_cu->ai4_intra_chroma_pred_mode_idx[0]; |
1331 | 523k | ps_cu->ai4_intra_chroma_pred_mode_idx[2] = ps_cu->ai4_intra_chroma_pred_mode_idx[0]; |
1332 | 523k | ps_cu->ai4_intra_chroma_pred_mode_idx[3] = ps_cu->ai4_intra_chroma_pred_mode_idx[0]; |
1333 | 523k | } |
1334 | 825k | } |
1335 | 825k | STATS_UPDATE_PU_SIZE(ps_pu); |
1336 | | /* Increment PU pointer */ |
1337 | 825k | ps_codec->s_parse.ps_pu++; |
1338 | 825k | ps_codec->s_parse.i4_pic_pu_idx++; |
1339 | | |
1340 | 825k | return ret; |
1341 | 825k | } |
1342 | | /** |
1343 | | ******************************************************************************* |
1344 | | * |
1345 | | * @brief |
1346 | | * Parses coding unit |
1347 | | * |
1348 | | * @par Description: |
1349 | | * Parses coding unit as per Section:7.3.9.5 |
1350 | | * |
1351 | | * @param[in] ps_codec |
1352 | | * Pointer to codec context |
1353 | | * |
1354 | | * @returns Error from IHEVCD_ERROR_T |
1355 | | * |
1356 | | * @remarks |
1357 | | * |
1358 | | * |
1359 | | ******************************************************************************* |
1360 | | */ |
1361 | | |
1362 | | IHEVCD_ERROR_T ihevcd_parse_coding_unit(codec_t *ps_codec, |
1363 | | WORD32 x0, |
1364 | | WORD32 y0, |
1365 | | WORD32 log2_cb_size) |
1366 | 4.20M | { |
1367 | 4.20M | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
1368 | 4.20M | sps_t *ps_sps; |
1369 | 4.20M | pps_t *ps_pps; |
1370 | 4.20M | WORD32 cb_size; |
1371 | 4.20M | slice_header_t *ps_slice_hdr; |
1372 | 4.20M | WORD32 skip_flag; |
1373 | 4.20M | WORD32 pcm_flag; |
1374 | 4.20M | UWORD32 *pu4_skip_top = ps_codec->s_parse.pu4_skip_cu_top; |
1375 | 4.20M | UWORD32 u4_skip_left = ps_codec->s_parse.u4_skip_cu_left; |
1376 | 4.20M | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
1377 | 4.20M | tu_t *ps_tu = ps_codec->s_parse.ps_tu; |
1378 | | |
1379 | 4.20M | WORD32 cu_pos_x; |
1380 | 4.20M | WORD32 cu_pos_y; |
1381 | 4.20M | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
1382 | | |
1383 | 4.20M | ASSERT(0 == (x0 % 8)); |
1384 | 4.20M | ASSERT(0 == (y0 % 8)); |
1385 | | |
1386 | 4.20M | ps_codec->s_parse.s_cu.i4_tu_cnt = 0; |
1387 | 4.20M | ps_sps = ps_codec->s_parse.ps_sps; |
1388 | 4.20M | ps_pps = ps_codec->s_parse.ps_pps; |
1389 | | |
1390 | 4.20M | cu_pos_x = ps_codec->s_parse.s_cu.i4_pos_x; |
1391 | 4.20M | cu_pos_y = ps_codec->s_parse.s_cu.i4_pos_y; |
1392 | | |
1393 | | |
1394 | | |
1395 | 4.20M | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr; |
1396 | | |
1397 | | |
1398 | 4.20M | cb_size = 1 << log2_cb_size; |
1399 | | |
1400 | 4.20M | ps_codec->s_parse.s_cu.i4_cu_transquant_bypass = 0; |
1401 | | |
1402 | 4.20M | if(ps_pps->i1_transquant_bypass_enable_flag) |
1403 | 54.0k | { |
1404 | 54.0k | TRACE_CABAC_CTXT("cu_transquant_bypass_flag", ps_cabac->u4_range, IHEVC_CAB_CU_TQ_BYPASS_FLAG); |
1405 | 54.0k | ps_codec->s_parse.s_cu.i4_cu_transquant_bypass = |
1406 | 54.0k | ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, |
1407 | 54.0k | IHEVC_CAB_CU_TQ_BYPASS_FLAG); |
1408 | | /* Update transquant_bypass in ps_tu */ |
1409 | | |
1410 | 54.0k | AEV_TRACE("cu_transquant_bypass_flag", ps_codec->s_parse.s_cu.i4_cu_transquant_bypass, |
1411 | 54.0k | ps_cabac->u4_range); |
1412 | | |
1413 | 54.0k | if(ps_codec->s_parse.s_cu.i4_cu_transquant_bypass) |
1414 | 27.9k | { |
1415 | 27.9k | UWORD8 *pu1_pic_no_loop_filter_flag = ps_codec->s_parse.pu1_pic_no_loop_filter_flag; |
1416 | 27.9k | UWORD32 u4_mask; |
1417 | 27.9k | WORD32 i; |
1418 | 27.9k | WORD32 numbytes_row; |
1419 | 27.9k | numbytes_row = (ps_sps->i2_pic_width_in_luma_samples + 63) / 64; |
1420 | 27.9k | pu1_pic_no_loop_filter_flag += (y0 / 8) * numbytes_row; |
1421 | 27.9k | pu1_pic_no_loop_filter_flag += (x0 / 64); |
1422 | | |
1423 | | /* Generate (cb_size / 8) number of 1s */ |
1424 | | /* i.e (log2_cb_size - 2) number of 1s */ |
1425 | 27.9k | u4_mask = LSB_ONES((cb_size >> 3)); |
1426 | 81.7k | for(i = 0; i < (cb_size / 8); i++) |
1427 | 53.7k | { |
1428 | 53.7k | *pu1_pic_no_loop_filter_flag |= (u4_mask << (((x0) / 8) % 8)); |
1429 | 53.7k | pu1_pic_no_loop_filter_flag += numbytes_row; |
1430 | 53.7k | } |
1431 | 27.9k | } |
1432 | 54.0k | } |
1433 | | |
1434 | 4.20M | { |
1435 | 4.20M | UWORD32 u4_skip_top = 0; |
1436 | 4.20M | UWORD32 u4_mask; |
1437 | 4.20M | UWORD32 u4_top_mask, u4_left_mask; |
1438 | 4.20M | UWORD32 u4_min_cu_x = x0 / 8; |
1439 | 4.20M | UWORD32 u4_min_cu_y = y0 / 8; |
1440 | | |
1441 | 4.20M | pu4_skip_top += (u4_min_cu_x / 32); |
1442 | | |
1443 | | |
1444 | 4.20M | if(ps_slice_hdr->i1_slice_type != ISLICE) |
1445 | 3.54M | { |
1446 | 3.54M | WORD32 ctx_idx_inc; |
1447 | 3.54M | ctx_idx_inc = 0; |
1448 | | |
1449 | 3.54M | if((0 != cu_pos_y) || |
1450 | 924k | ((0 != ps_codec->s_parse.i4_ctb_slice_y) && |
1451 | 644k | (0 != ps_codec->s_parse.i4_ctb_tile_y))) |
1452 | 3.19M | { |
1453 | 3.19M | u4_skip_top = *pu4_skip_top; |
1454 | 3.19M | u4_skip_top >>= (u4_min_cu_x % 32); |
1455 | 3.19M | if(u4_skip_top & 1) |
1456 | 1.79M | ctx_idx_inc++; |
1457 | 3.19M | } |
1458 | | |
1459 | | /*****************************************************************/ |
1460 | | /* If cu_pos_x is non-zero then left is available */ |
1461 | | /* If cu_pos_x is zero then ensure both the following are true */ |
1462 | | /* Current CTB is not the first CTB in a tile row */ |
1463 | | /* Current CTB is not the first CTB in a slice */ |
1464 | | /*****************************************************************/ |
1465 | 3.54M | if((0 != cu_pos_x) || |
1466 | 923k | (((0 != ps_codec->s_parse.i4_ctb_slice_x) || (0 != ps_codec->s_parse.i4_ctb_slice_y)) && |
1467 | 897k | (0 != ps_codec->s_parse.i4_ctb_tile_x))) |
1468 | 3.41M | { |
1469 | 3.41M | u4_skip_left >>= (u4_min_cu_y % 32); |
1470 | 3.41M | if(u4_skip_left & 1) |
1471 | 1.92M | ctx_idx_inc++; |
1472 | 3.41M | } |
1473 | 3.54M | TRACE_CABAC_CTXT("cu_skip_flag", ps_cabac->u4_range, (IHEVC_CAB_SKIP_FLAG + ctx_idx_inc)); |
1474 | 3.54M | skip_flag = ihevcd_cabac_decode_bin(ps_cabac, |
1475 | 3.54M | ps_bitstrm, |
1476 | 3.54M | (IHEVC_CAB_SKIP_FLAG + ctx_idx_inc)); |
1477 | | |
1478 | 3.54M | AEV_TRACE("cu_skip_flag", skip_flag, ps_cabac->u4_range); |
1479 | 3.54M | } |
1480 | 658k | else |
1481 | 658k | skip_flag = 0; |
1482 | | |
1483 | | /* Update top skip_flag */ |
1484 | 4.20M | u4_skip_top = *pu4_skip_top; |
1485 | | /* Since Max cb_size is 64, maximum of 8 bits will be set or reset */ |
1486 | | /* Also since Coding block will be within 64x64 grid, only 8bits within a WORD32 |
1487 | | * need to be updated. These 8 bits will not cross 8 bit boundaries |
1488 | | */ |
1489 | 4.20M | u4_mask = LSB_ONES(cb_size / 8); |
1490 | 4.20M | u4_top_mask = u4_mask << (u4_min_cu_x % 32); |
1491 | | |
1492 | | |
1493 | 4.20M | if(skip_flag) |
1494 | 2.04M | { |
1495 | 2.04M | u4_skip_top |= u4_top_mask; |
1496 | 2.04M | } |
1497 | 2.15M | else |
1498 | 2.15M | { |
1499 | 2.15M | u4_skip_top &= ~u4_top_mask; |
1500 | 2.15M | } |
1501 | 4.20M | *pu4_skip_top = u4_skip_top; |
1502 | | |
1503 | | /* Update left skip_flag */ |
1504 | 4.20M | u4_skip_left = ps_codec->s_parse.u4_skip_cu_left; |
1505 | 4.20M | u4_mask = LSB_ONES(cb_size / 8); |
1506 | 4.20M | u4_left_mask = u4_mask << (u4_min_cu_y % 32); |
1507 | | |
1508 | 4.20M | if(skip_flag) |
1509 | 2.04M | { |
1510 | 2.04M | u4_skip_left |= u4_left_mask; |
1511 | 2.04M | } |
1512 | 2.15M | else |
1513 | 2.15M | { |
1514 | 2.15M | u4_skip_left &= ~u4_left_mask; |
1515 | 2.15M | } |
1516 | 4.20M | ps_codec->s_parse.u4_skip_cu_left = u4_skip_left; |
1517 | 4.20M | } |
1518 | 4.20M | ps_codec->s_parse.i4_cu_pcm_flag = 0; |
1519 | | |
1520 | 4.20M | if(skip_flag) |
1521 | 2.04M | { |
1522 | 2.04M | WORD32 ctb_x_base; |
1523 | 2.04M | WORD32 ctb_y_base; |
1524 | | |
1525 | 2.04M | ctb_x_base = ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size; |
1526 | 2.04M | ctb_y_base = ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size; |
1527 | | |
1528 | 2.04M | ps_tu->b1_cb_cbf = 0; |
1529 | 2.04M | #ifdef ENABLE_MAIN_REXT_PROFILE |
1530 | 2.04M | ps_tu->b1_cb_cbf_subtu1 = 0; |
1531 | 2.04M | #endif |
1532 | 2.04M | ps_tu->b1_cr_cbf = 0; |
1533 | 2.04M | #ifdef ENABLE_MAIN_REXT_PROFILE |
1534 | 2.04M | ps_tu->b1_cr_cbf_subtu1 = 0; |
1535 | 2.04M | #endif |
1536 | 2.04M | ps_tu->b1_y_cbf = 0; |
1537 | 2.04M | ps_tu->b4_pos_x = ((x0 - ctb_x_base) >> 2); |
1538 | 2.04M | ps_tu->b4_pos_y = ((y0 - ctb_y_base) >> 2); |
1539 | 2.04M | ps_tu->b1_transquant_bypass = 0; |
1540 | 2.04M | ps_tu->b3_size = (log2_cb_size - 2); |
1541 | 2.04M | ps_tu->b7_qp = ps_codec->s_parse.u4_qp; |
1542 | 2.04M | ps_tu->b3_chroma_intra_mode_idx = INTRA_PRED_CHROMA_IDX_NONE; |
1543 | 2.04M | ps_tu->b6_luma_intra_mode = INTRA_PRED_NONE; |
1544 | 2.04M | #ifdef ENABLE_MAIN_REXT_PROFILE |
1545 | 2.04M | ps_tu->b3_cb_log2_res_scale_abs_plus1 = 0; |
1546 | 2.04M | ps_tu->b1_cb_log2_res_sign = 0; |
1547 | 2.04M | ps_tu->b3_cr_log2_res_scale_abs_plus1 = 0; |
1548 | 2.04M | ps_tu->b1_cr_log2_res_sign = 0; |
1549 | 2.04M | #endif |
1550 | | |
1551 | | /* Set the first TU in CU flag */ |
1552 | 2.04M | { |
1553 | 2.04M | if((ps_codec->s_parse.s_cu.i4_pos_x << 3) == (ps_tu->b4_pos_x << 2) && |
1554 | 2.04M | (ps_codec->s_parse.s_cu.i4_pos_y << 3) == (ps_tu->b4_pos_y << 2)) |
1555 | 2.04M | { |
1556 | 2.04M | ps_tu->b1_first_tu_in_cu = 1; |
1557 | 2.04M | } |
1558 | 0 | else |
1559 | 0 | { |
1560 | 0 | ps_tu->b1_first_tu_in_cu = 0; |
1561 | 0 | } |
1562 | 2.04M | } |
1563 | | |
1564 | 2.04M | ps_codec->s_parse.ps_tu++; |
1565 | 2.04M | ps_codec->s_parse.s_cu.i4_tu_cnt++; |
1566 | 2.04M | ps_codec->s_parse.i4_pic_tu_idx++; |
1567 | | |
1568 | 2.04M | ps_codec->s_parse.s_cu.i4_pred_mode = PRED_MODE_SKIP; |
1569 | 2.04M | ps_codec->s_parse.s_cu.i4_part_mode = PART_2Nx2N; |
1570 | 2.04M | { |
1571 | 2.04M | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1572 | 2.04M | ps_pu->b2_part_idx = 0; |
1573 | 2.04M | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size, cb_size); |
1574 | 2.04M | STATS_UPDATE_PU_SKIP_SIZE(ps_pu); |
1575 | 2.04M | } |
1576 | 2.04M | } |
1577 | 2.15M | else |
1578 | 2.15M | { |
1579 | 2.15M | WORD32 pred_mode; |
1580 | 2.15M | WORD32 part_mode; |
1581 | 2.15M | WORD32 intra_split_flag; |
1582 | 2.15M | WORD32 is_mincb; |
1583 | 2.15M | cb_size = (1 << log2_cb_size); |
1584 | 2.15M | is_mincb = (cb_size == (1 << ps_sps->i1_log2_min_coding_block_size)); |
1585 | 2.15M | pcm_flag = 0; |
1586 | 2.15M | if(ps_slice_hdr->i1_slice_type != ISLICE) |
1587 | 1.50M | { |
1588 | 1.50M | TRACE_CABAC_CTXT("pred_mode_flag", ps_cabac->u4_range, IHEVC_CAB_PRED_MODE); |
1589 | 1.50M | pred_mode = ihevcd_cabac_decode_bin(ps_cabac, |
1590 | 1.50M | ps_bitstrm, |
1591 | 1.50M | IHEVC_CAB_PRED_MODE); |
1592 | | |
1593 | 1.50M | AEV_TRACE("pred_mode_flag", pred_mode, ps_cabac->u4_range); |
1594 | 1.50M | } |
1595 | 658k | else |
1596 | 658k | { |
1597 | 658k | pred_mode = PRED_MODE_INTRA; |
1598 | 658k | } |
1599 | | |
1600 | | /* If current CU is intra then set corresponging bit in picture level intra map */ |
1601 | 2.15M | if(PRED_MODE_INTRA == pred_mode) |
1602 | 825k | { |
1603 | 825k | UWORD8 *pu1_pic_intra_flag = ps_codec->s_parse.pu1_pic_intra_flag; |
1604 | 825k | UWORD32 u4_mask; |
1605 | 825k | WORD32 i; |
1606 | 825k | WORD32 numbytes_row; |
1607 | 825k | numbytes_row = (ps_sps->i2_pic_width_in_luma_samples + 63) / 64; |
1608 | 825k | pu1_pic_intra_flag += (y0 / 8) * numbytes_row; |
1609 | 825k | pu1_pic_intra_flag += (x0 / 64); |
1610 | | |
1611 | | /* Generate (cb_size / 8) number of 1s */ |
1612 | | /* i.e (log2_cb_size - 2) number of 1s */ |
1613 | 825k | u4_mask = LSB_ONES((cb_size >> 3)); |
1614 | 2.36M | for(i = 0; i < (cb_size / 8); i++) |
1615 | 1.53M | { |
1616 | 1.53M | *pu1_pic_intra_flag |= (u4_mask << (((x0) / 8) % 8)); |
1617 | 1.53M | pu1_pic_intra_flag += numbytes_row; |
1618 | 1.53M | } |
1619 | 825k | } |
1620 | | |
1621 | 2.15M | ps_codec->s_parse.s_cu.i4_pred_mode = pred_mode; |
1622 | 2.15M | intra_split_flag = 0; |
1623 | 2.15M | if((PRED_MODE_INTRA != pred_mode) || |
1624 | 825k | is_mincb) |
1625 | 1.98M | { |
1626 | 1.98M | UWORD32 bin; |
1627 | 1.98M | if(PRED_MODE_INTRA == pred_mode) |
1628 | 654k | { |
1629 | 654k | TRACE_CABAC_CTXT("part_mode", ps_cabac->u4_range, IHEVC_CAB_PART_MODE); |
1630 | 654k | bin = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, IHEVC_CAB_PART_MODE); |
1631 | 654k | part_mode = (bin) ? PART_2Nx2N : PART_NxN; |
1632 | 654k | } |
1633 | 1.33M | else |
1634 | 1.33M | { |
1635 | 1.33M | WORD32 amp_enabled = ps_sps->i1_amp_enabled_flag; |
1636 | | |
1637 | 1.33M | UWORD32 u4_max_bin_cnt = 0; |
1638 | | |
1639 | | |
1640 | | |
1641 | 1.33M | if(amp_enabled && !is_mincb) |
1642 | 369k | { |
1643 | 369k | part_mode = ihevcd_parse_part_mode_amp(ps_cabac, ps_bitstrm); |
1644 | 369k | } |
1645 | 964k | else |
1646 | 964k | { |
1647 | 964k | WORD32 ctxt_inc = IHEVC_CAB_PART_MODE; |
1648 | | |
1649 | 964k | u4_max_bin_cnt = 2; |
1650 | 964k | if((is_mincb) && (cb_size > 8)) |
1651 | 22 | { |
1652 | 22 | u4_max_bin_cnt++; |
1653 | 22 | } |
1654 | | |
1655 | 964k | part_mode = -1; |
1656 | 964k | TRACE_CABAC_CTXT("part_mode", ps_cabac->u4_range, IHEVC_CAB_PART_MODE); |
1657 | 964k | do |
1658 | 1.57M | { |
1659 | 1.57M | bin = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, |
1660 | 1.57M | ctxt_inc++); |
1661 | 1.57M | part_mode++; |
1662 | 1.57M | }while(--u4_max_bin_cnt && !bin); |
1663 | | |
1664 | | /* If the last bin was zero, then increment part mode by 1 */ |
1665 | 964k | if(!bin) |
1666 | 338k | part_mode++; |
1667 | 964k | } |
1668 | | |
1669 | | |
1670 | 1.33M | } |
1671 | | |
1672 | 1.98M | AEV_TRACE("part_mode", part_mode, ps_cabac->u4_range); |
1673 | | |
1674 | 1.98M | } |
1675 | 171k | else |
1676 | 171k | { |
1677 | 171k | part_mode = 0; |
1678 | 171k | intra_split_flag = 0; |
1679 | 171k | } |
1680 | 2.15M | ps_codec->s_parse.s_cu.i4_part_mode = part_mode; |
1681 | | |
1682 | 2.15M | if((PRED_MODE_INTRA == ps_codec->s_parse.s_cu.i4_pred_mode) && |
1683 | 825k | (PART_NxN == ps_codec->s_parse.s_cu.i4_part_mode)) |
1684 | 302k | { |
1685 | 302k | intra_split_flag = 1; |
1686 | 302k | } |
1687 | 2.15M | ps_codec->s_parse.s_cu.i4_part_mode = part_mode; |
1688 | 2.15M | ps_codec->s_parse.s_cu.i4_intra_split_flag = intra_split_flag; |
1689 | 2.15M | if(pred_mode == PRED_MODE_INTRA) |
1690 | 825k | { |
1691 | 825k | ps_codec->s_parse.i4_cu_pcm_flag = 0; |
1692 | 825k | ihevcd_parse_coding_unit_intra(ps_codec, x0, y0, log2_cb_size); |
1693 | 825k | pcm_flag = ps_codec->s_parse.i4_cu_pcm_flag; |
1694 | | |
1695 | 825k | } |
1696 | 1.33M | else |
1697 | 1.33M | { |
1698 | 1.33M | if(part_mode == PART_2Nx2N) |
1699 | 490k | { |
1700 | 490k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1701 | 490k | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size, cb_size); |
1702 | 490k | ps_pu->b2_part_idx = 0; |
1703 | 490k | } |
1704 | 843k | else if(part_mode == PART_2NxN) |
1705 | 321k | { |
1706 | 321k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1707 | | |
1708 | 321k | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size, cb_size / 2); |
1709 | 321k | ps_pu->b2_part_idx = 0; |
1710 | | |
1711 | 321k | ps_pu = ps_codec->s_parse.ps_pu; |
1712 | 321k | ihevcd_parse_prediction_unit(ps_codec, x0, y0 + (cb_size / 2), cb_size, cb_size / 2); |
1713 | | |
1714 | 321k | ps_pu->b2_part_idx = 1; |
1715 | 321k | } |
1716 | 522k | else if(part_mode == PART_Nx2N) |
1717 | 404k | { |
1718 | 404k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1719 | 404k | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size / 2, cb_size); |
1720 | 404k | ps_pu->b2_part_idx = 0; |
1721 | 404k | ps_pu = ps_codec->s_parse.ps_pu; |
1722 | 404k | ihevcd_parse_prediction_unit(ps_codec, x0 + (cb_size / 2), y0, cb_size / 2, cb_size); |
1723 | | |
1724 | 404k | ps_pu->b2_part_idx = 1; |
1725 | 404k | } |
1726 | 118k | else if(part_mode == PART_2NxnU) |
1727 | 25.0k | { |
1728 | 25.0k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1729 | 25.0k | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size, cb_size / 4); |
1730 | 25.0k | ps_pu->b2_part_idx = 0; |
1731 | 25.0k | ps_pu = ps_codec->s_parse.ps_pu; |
1732 | 25.0k | ihevcd_parse_prediction_unit(ps_codec, x0, y0 + (cb_size / 4), cb_size, cb_size * 3 / 4); |
1733 | | |
1734 | 25.0k | ps_pu->b2_part_idx = 1; |
1735 | 25.0k | } |
1736 | 93.3k | else if(part_mode == PART_2NxnD) |
1737 | 23.8k | { |
1738 | 23.8k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1739 | 23.8k | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size, cb_size * 3 / 4); |
1740 | 23.8k | ps_pu->b2_part_idx = 0; |
1741 | 23.8k | ps_pu = ps_codec->s_parse.ps_pu; |
1742 | 23.8k | ihevcd_parse_prediction_unit(ps_codec, x0, y0 + (cb_size * 3 / 4), cb_size, cb_size / 4); |
1743 | | |
1744 | 23.8k | ps_pu->b2_part_idx = 1; |
1745 | 23.8k | } |
1746 | 69.5k | else if(part_mode == PART_nLx2N) |
1747 | 37.0k | { |
1748 | 37.0k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1749 | 37.0k | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size / 4, cb_size); |
1750 | 37.0k | ps_pu->b2_part_idx = 0; |
1751 | 37.0k | ps_pu = ps_codec->s_parse.ps_pu; |
1752 | 37.0k | ihevcd_parse_prediction_unit(ps_codec, x0 + (cb_size / 4), y0, cb_size * 3 / 4, cb_size); |
1753 | | |
1754 | 37.0k | ps_pu->b2_part_idx = 1; |
1755 | 37.0k | } |
1756 | 32.4k | else if(part_mode == PART_nRx2N) |
1757 | 32.4k | { |
1758 | 32.4k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1759 | 32.4k | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size * 3 / 4, cb_size); |
1760 | 32.4k | ps_pu->b2_part_idx = 0; |
1761 | 32.4k | ps_pu = ps_codec->s_parse.ps_pu; |
1762 | 32.4k | ihevcd_parse_prediction_unit(ps_codec, x0 + (cb_size * 3 / 4), y0, cb_size / 4, cb_size); |
1763 | 32.4k | ps_pu->b2_part_idx = 1; |
1764 | 32.4k | } |
1765 | 0 | else |
1766 | 0 | { /* PART_NxN */ |
1767 | 0 | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
1768 | |
|
1769 | 0 | ihevcd_parse_prediction_unit(ps_codec, x0, y0, cb_size / 2, cb_size / 2); |
1770 | 0 | ps_pu->b2_part_idx = 0; |
1771 | 0 | ps_pu = ps_codec->s_parse.ps_pu; |
1772 | 0 | ihevcd_parse_prediction_unit(ps_codec, x0 + (cb_size / 2), y0, cb_size / 2, cb_size / 2); |
1773 | |
|
1774 | 0 | ps_pu->b2_part_idx = 1; |
1775 | 0 | ps_pu = ps_codec->s_parse.ps_pu; |
1776 | 0 | ihevcd_parse_prediction_unit(ps_codec, x0, y0 + (cb_size / 2), cb_size / 2, cb_size / 2); |
1777 | |
|
1778 | 0 | ps_pu->b2_part_idx = 2; |
1779 | 0 | ps_pu = ps_codec->s_parse.ps_pu; |
1780 | 0 | ihevcd_parse_prediction_unit(ps_codec, x0 + (cb_size / 2), y0 + (cb_size / 2), cb_size / 2, cb_size / 2); |
1781 | |
|
1782 | 0 | ps_pu->b2_part_idx = 3; |
1783 | 0 | } |
1784 | 1.33M | } |
1785 | | |
1786 | 2.15M | if(!pcm_flag) |
1787 | 2.15M | { |
1788 | 2.15M | WORD32 no_residual_syntax_flag = 0; |
1789 | 2.15M | pu_t *ps_pu; |
1790 | | /* Since ps_pu is incremented for each PU parsed, decrement by 1 to |
1791 | | * access last decoded PU |
1792 | | */ |
1793 | 2.15M | ps_pu = ps_codec->s_parse.ps_pu - 1; |
1794 | 2.15M | if((PRED_MODE_INTRA != pred_mode) && |
1795 | 1.33M | (!((part_mode == PART_2Nx2N) && ps_pu->b1_merge_flag))) |
1796 | 1.18M | { |
1797 | | |
1798 | 1.18M | TRACE_CABAC_CTXT("rqt_root_cbf", ps_cabac->u4_range, IHEVC_CAB_NORES_IDX); |
1799 | 1.18M | no_residual_syntax_flag = ihevcd_cabac_decode_bin(ps_cabac, |
1800 | 1.18M | ps_bitstrm, |
1801 | 1.18M | IHEVC_CAB_NORES_IDX); |
1802 | | |
1803 | 1.18M | AEV_TRACE("rqt_root_cbf", no_residual_syntax_flag, |
1804 | 1.18M | ps_cabac->u4_range); |
1805 | | /* TODO: HACK FOR COMPLIANCE WITH HM REFERENCE DECODER */ |
1806 | | /*********************************************************/ |
1807 | | /* currently the HM decoder expects qtroot cbf instead of */ |
1808 | | /* no_residue_flag which has opposite meaning */ |
1809 | | /* This will be fixed once the software / spec is fixed */ |
1810 | | /*********************************************************/ |
1811 | 1.18M | no_residual_syntax_flag = 1 - no_residual_syntax_flag; |
1812 | 1.18M | } |
1813 | | |
1814 | 2.15M | if(!no_residual_syntax_flag) |
1815 | 1.21M | { |
1816 | | |
1817 | 1.21M | ps_codec->s_parse.s_cu.i4_max_trafo_depth = (pred_mode == PRED_MODE_INTRA) ? |
1818 | 825k | (ps_sps->i1_max_transform_hierarchy_depth_intra + intra_split_flag) : |
1819 | 1.21M | (ps_sps->i1_max_transform_hierarchy_depth_inter); |
1820 | 1.21M | ret = ihevcd_parse_transform_tree(ps_codec, x0, y0, x0, y0, |
1821 | 1.21M | log2_cb_size, 0, 0, |
1822 | 1.21M | ps_codec->s_parse.s_cu.ai4_intra_luma_pred_mode[0], |
1823 | 1.21M | ps_codec->s_parse.s_cu.ai4_intra_chroma_pred_mode_idx[0]); |
1824 | 1.21M | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
1825 | 1.21M | } |
1826 | 944k | else |
1827 | 944k | { |
1828 | 944k | WORD32 ctb_x_base; |
1829 | 944k | WORD32 ctb_y_base; |
1830 | | |
1831 | 944k | ctb_x_base = ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size; |
1832 | 944k | ctb_y_base = ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size; |
1833 | | |
1834 | 944k | ps_tu = ps_codec->s_parse.ps_tu; |
1835 | 944k | ps_tu->b1_cb_cbf = 0; |
1836 | 944k | #ifdef ENABLE_MAIN_REXT_PROFILE |
1837 | 944k | ps_tu->b1_cb_cbf_subtu1 = 0; |
1838 | 944k | #endif |
1839 | 944k | ps_tu->b1_cr_cbf = 0; |
1840 | 944k | #ifdef ENABLE_MAIN_REXT_PROFILE |
1841 | 944k | ps_tu->b1_cr_cbf_subtu1 = 0; |
1842 | 944k | #endif |
1843 | 944k | ps_tu->b1_y_cbf = 0; |
1844 | 944k | ps_tu->b4_pos_x = ((x0 - ctb_x_base) >> 2); |
1845 | 944k | ps_tu->b4_pos_y = ((y0 - ctb_y_base) >> 2); |
1846 | 944k | ps_tu->b1_transquant_bypass = 0; |
1847 | 944k | ps_tu->b3_size = (log2_cb_size - 2); |
1848 | 944k | ps_tu->b7_qp = ps_codec->s_parse.u4_qp; |
1849 | 944k | ps_tu->b3_chroma_intra_mode_idx = INTRA_PRED_CHROMA_IDX_NONE; |
1850 | 944k | ps_tu->b6_luma_intra_mode = ps_codec->s_parse.s_cu.ai4_intra_luma_pred_mode[0]; |
1851 | 944k | #ifdef ENABLE_MAIN_REXT_PROFILE |
1852 | 944k | ps_tu->b3_cb_log2_res_scale_abs_plus1 = 0; |
1853 | 944k | ps_tu->b1_cb_log2_res_sign = 0; |
1854 | 944k | ps_tu->b3_cr_log2_res_scale_abs_plus1 = 0; |
1855 | 944k | ps_tu->b1_cr_log2_res_sign = 0; |
1856 | 944k | #endif |
1857 | | |
1858 | | /* Set the first TU in CU flag */ |
1859 | 944k | { |
1860 | 944k | if((ps_codec->s_parse.s_cu.i4_pos_x << 3) == (ps_tu->b4_pos_x << 2) && |
1861 | 944k | (ps_codec->s_parse.s_cu.i4_pos_y << 3) == (ps_tu->b4_pos_y << 2)) |
1862 | 944k | { |
1863 | 944k | ps_tu->b1_first_tu_in_cu = 1; |
1864 | 944k | } |
1865 | 0 | else |
1866 | 0 | { |
1867 | 0 | ps_tu->b1_first_tu_in_cu = 0; |
1868 | 0 | } |
1869 | 944k | } |
1870 | 944k | ps_codec->s_parse.ps_tu++; |
1871 | 944k | ps_codec->s_parse.s_cu.i4_tu_cnt++; |
1872 | 944k | ps_codec->s_parse.i4_pic_tu_idx++; |
1873 | | |
1874 | 944k | } |
1875 | 2.15M | } |
1876 | | |
1877 | 2.15M | } |
1878 | | |
1879 | | |
1880 | | |
1881 | | |
1882 | 4.20M | return ret; |
1883 | 4.20M | } |
1884 | | |
1885 | | |
1886 | | |
1887 | | |
1888 | | /** |
1889 | | ******************************************************************************* |
1890 | | * |
1891 | | * @brief |
1892 | | * Parses Coding Quad Tree |
1893 | | * |
1894 | | * @par Description: |
1895 | | * Parses Coding Quad Tree as per Section:7.3.9.4 |
1896 | | * |
1897 | | * @param[in] ps_codec |
1898 | | * Pointer to codec context |
1899 | | * |
1900 | | * @returns Error from IHEVCD_ERROR_T |
1901 | | * |
1902 | | * @remarks |
1903 | | * |
1904 | | * |
1905 | | ******************************************************************************* |
1906 | | */ |
1907 | | IHEVCD_ERROR_T ihevcd_parse_coding_quadtree(codec_t *ps_codec, |
1908 | | WORD32 x0, |
1909 | | WORD32 y0, |
1910 | | WORD32 log2_cb_size, |
1911 | | WORD32 ct_depth) |
1912 | 5.57M | { |
1913 | 5.57M | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
1914 | 5.57M | sps_t *ps_sps; |
1915 | 5.57M | pps_t *ps_pps; |
1916 | 5.57M | WORD32 split_cu_flag; |
1917 | 5.57M | WORD32 x1, y1; |
1918 | 5.57M | WORD32 cu_pos_x; |
1919 | 5.57M | WORD32 cu_pos_y; |
1920 | 5.57M | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
1921 | 5.57M | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
1922 | 5.57M | WORD32 cb_size = 1 << log2_cb_size; |
1923 | 5.57M | ps_sps = ps_codec->s_parse.ps_sps; |
1924 | 5.57M | ps_pps = ps_codec->s_parse.ps_pps; |
1925 | | |
1926 | | /* Compute CU position with respect to current CTB in (8x8) units */ |
1927 | 5.57M | cu_pos_x = (x0 - (ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size)) >> 3; |
1928 | 5.57M | cu_pos_y = (y0 - (ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size)) >> 3; |
1929 | | |
1930 | 5.57M | ps_codec->s_parse.s_cu.i4_pos_x = cu_pos_x; |
1931 | 5.57M | ps_codec->s_parse.s_cu.i4_pos_y = cu_pos_y; |
1932 | | |
1933 | 5.57M | ps_codec->s_parse.s_cu.i4_log2_cb_size = log2_cb_size; |
1934 | | |
1935 | 5.57M | ps_codec->s_parse.i4_ct_depth = ct_depth; |
1936 | 5.57M | { |
1937 | 5.57M | UWORD32 *pu4_ct_depth_top = ps_codec->s_parse.pu4_ct_depth_top; |
1938 | 5.57M | UWORD32 u4_ct_depth_left = ps_codec->s_parse.u4_ct_depth_left; |
1939 | 5.57M | UWORD32 u4_ct_depth_top = 0; |
1940 | 5.57M | UWORD32 u4_mask; |
1941 | 5.57M | UWORD32 u4_top_mask, u4_left_mask; |
1942 | 5.57M | WORD32 ctxt_idx; |
1943 | 5.57M | UWORD32 u4_min_cu_x = x0 / 8; |
1944 | 5.57M | UWORD32 u4_min_cu_y = y0 / 8; |
1945 | | |
1946 | 5.57M | pu4_ct_depth_top += (u4_min_cu_x / 16); |
1947 | | |
1948 | | |
1949 | | |
1950 | | |
1951 | 5.57M | if(((x0 + (1 << log2_cb_size)) <= ps_sps->i2_pic_width_in_luma_samples) && |
1952 | 5.49M | ((y0 + (1 << log2_cb_size)) <= ps_sps->i2_pic_height_in_luma_samples) && |
1953 | 5.30M | (log2_cb_size > ps_sps->i1_log2_min_coding_block_size)) |
1954 | 2.42M | { |
1955 | | |
1956 | 2.42M | ctxt_idx = IHEVC_CAB_SPLIT_CU_FLAG; |
1957 | | /* Split cu context increment is decided based on left and top Coding tree |
1958 | | * depth which is stored at frame level |
1959 | | */ |
1960 | | /* Check if the CTB is in first row in the current slice or tile */ |
1961 | 2.42M | if((0 != cu_pos_y) || |
1962 | 1.20M | ((0 != ps_codec->s_parse.i4_ctb_slice_y) && |
1963 | 809k | (0 != ps_codec->s_parse.i4_ctb_tile_y))) |
1964 | 1.95M | { |
1965 | 1.95M | u4_ct_depth_top = *pu4_ct_depth_top; |
1966 | 1.95M | u4_ct_depth_top >>= ((u4_min_cu_x % 16) * 2); |
1967 | 1.95M | u4_ct_depth_top &= 3; |
1968 | | |
1969 | 1.95M | if((WORD32)u4_ct_depth_top > ct_depth) |
1970 | 791k | ctxt_idx++; |
1971 | 1.95M | } |
1972 | | |
1973 | | /* Check if the CTB is in first column in the current slice or tile */ |
1974 | | /*****************************************************************/ |
1975 | | /* If cu_pos_x is non-zero then left is available */ |
1976 | | /* If cu_pos_x is zero then ensure both the following are true */ |
1977 | | /* Current CTB is not the first CTB in a tile row */ |
1978 | | /* Current CTB is not the first CTB in a slice */ |
1979 | | /*****************************************************************/ |
1980 | 2.42M | if((0 != cu_pos_x) || |
1981 | 1.18M | (((0 != ps_codec->s_parse.i4_ctb_slice_x) || (0 != ps_codec->s_parse.i4_ctb_slice_y)) && |
1982 | 1.14M | (0 != ps_codec->s_parse.i4_ctb_tile_x))) |
1983 | 2.27M | { |
1984 | 2.27M | u4_ct_depth_left >>= ((u4_min_cu_y % 16) * 2); |
1985 | 2.27M | u4_ct_depth_left &= 3; |
1986 | 2.27M | if((WORD32)u4_ct_depth_left > ct_depth) |
1987 | 948k | ctxt_idx++; |
1988 | 2.27M | } |
1989 | 2.42M | TRACE_CABAC_CTXT("split_cu_flag", ps_cabac->u4_range, ctxt_idx); |
1990 | 2.42M | split_cu_flag = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
1991 | 2.42M | AEV_TRACE("split_cu_flag", split_cu_flag, ps_cabac->u4_range); |
1992 | 2.42M | } |
1993 | 3.14M | else |
1994 | 3.14M | { |
1995 | 3.14M | if(log2_cb_size > ps_sps->i1_log2_min_coding_block_size) |
1996 | 273k | split_cu_flag = 1; |
1997 | 2.87M | else |
1998 | 2.87M | split_cu_flag = 0; |
1999 | 3.14M | } |
2000 | | |
2001 | 5.57M | if(0 == split_cu_flag) |
2002 | 4.20M | { |
2003 | | /* Update top ct_depth */ |
2004 | 4.20M | u4_ct_depth_top = *pu4_ct_depth_top; |
2005 | | /* Since Max cb_size is 64, maximum of 8 bits will be set or reset */ |
2006 | | /* Also since Coding block will be within 64x64 grid, only 8bits within a WORD32 |
2007 | | * need to be updated. These 8 bits will not cross 8 bit boundaries |
2008 | | */ |
2009 | 4.20M | u4_mask = DUP_LSB_11(cb_size / 8); |
2010 | | |
2011 | 4.20M | u4_top_mask = u4_mask << ((u4_min_cu_x % 16) * 2); |
2012 | 4.20M | u4_ct_depth_top &= ~u4_top_mask; |
2013 | | |
2014 | 4.20M | if(ct_depth) |
2015 | 3.86M | { |
2016 | 3.86M | u4_top_mask = gau4_ct_depth_mask[ct_depth] & u4_mask; |
2017 | | |
2018 | 3.86M | u4_top_mask = u4_top_mask << ((u4_min_cu_x % 16) * 2); |
2019 | 3.86M | u4_ct_depth_top |= u4_top_mask; |
2020 | 3.86M | } |
2021 | | |
2022 | 4.20M | *pu4_ct_depth_top = u4_ct_depth_top; |
2023 | | |
2024 | | /* Update left ct_depth */ |
2025 | 4.20M | u4_ct_depth_left = ps_codec->s_parse.u4_ct_depth_left; |
2026 | | |
2027 | 4.20M | u4_left_mask = u4_mask << ((u4_min_cu_y % 16) * 2); |
2028 | | |
2029 | 4.20M | u4_ct_depth_left &= ~u4_left_mask; |
2030 | 4.20M | if(ct_depth) |
2031 | 3.86M | { |
2032 | 3.86M | u4_left_mask = gau4_ct_depth_mask[ct_depth] & u4_mask; |
2033 | | |
2034 | 3.86M | u4_left_mask = u4_left_mask << ((u4_min_cu_y % 16) * 2); |
2035 | 3.86M | u4_ct_depth_left |= u4_left_mask; |
2036 | 3.86M | } |
2037 | | |
2038 | 4.20M | ps_codec->s_parse.u4_ct_depth_left = u4_ct_depth_left; |
2039 | 4.20M | } |
2040 | 5.57M | } |
2041 | 5.57M | if((ps_pps->i1_cu_qp_delta_enabled_flag) && |
2042 | 3.85M | (log2_cb_size >= ps_pps->i1_log2_min_cu_qp_delta_size)) |
2043 | 383k | { |
2044 | 383k | ps_codec->s_parse.i4_is_cu_qp_delta_coded = 0; |
2045 | 383k | ps_codec->s_parse.i4_cu_qp_delta = 0; |
2046 | 383k | } |
2047 | 5.57M | if(split_cu_flag) |
2048 | 1.37M | { |
2049 | 1.37M | x1 = x0 + ((1 << log2_cb_size) >> 1); |
2050 | 1.37M | y1 = y0 + ((1 << log2_cb_size) >> 1); |
2051 | | |
2052 | 1.37M | ret = ihevcd_parse_coding_quadtree(ps_codec, x0, y0, log2_cb_size - 1, ct_depth + 1); |
2053 | 1.37M | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
2054 | | |
2055 | | /* At frame boundaries coding quadtree nodes are sent only if they fall within the frame */ |
2056 | 1.37M | if(x1 < ps_sps->i2_pic_width_in_luma_samples) |
2057 | 1.30M | { |
2058 | 1.30M | ret = ihevcd_parse_coding_quadtree(ps_codec, x1, y0, log2_cb_size - 1, ct_depth + 1); |
2059 | 1.30M | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
2060 | 1.30M | } |
2061 | | |
2062 | 1.37M | if(y1 < ps_sps->i2_pic_height_in_luma_samples) |
2063 | 1.21M | { |
2064 | 1.21M | ret = ihevcd_parse_coding_quadtree(ps_codec, x0, y1, log2_cb_size - 1, ct_depth + 1); |
2065 | 1.21M | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
2066 | 1.21M | } |
2067 | | |
2068 | 1.37M | if((x1 < ps_sps->i2_pic_width_in_luma_samples) && |
2069 | 1.30M | (y1 < ps_sps->i2_pic_height_in_luma_samples)) |
2070 | 1.14M | { |
2071 | 1.14M | ret = ihevcd_parse_coding_quadtree(ps_codec, x1, y1, log2_cb_size - 1, ct_depth + 1); |
2072 | 1.14M | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
2073 | 1.14M | } |
2074 | 1.37M | } |
2075 | 4.20M | else |
2076 | 4.20M | { |
2077 | 4.20M | WORD32 qp = ps_codec->s_parse.u4_qp; |
2078 | | /* Set current group QP if current CU is aligned with the group */ |
2079 | 4.20M | { |
2080 | 4.20M | WORD32 cu_pos_x = ps_codec->s_parse.s_cu.i4_pos_x << 3; |
2081 | 4.20M | WORD32 cu_pos_y = ps_codec->s_parse.s_cu.i4_pos_y << 3; |
2082 | | |
2083 | 4.20M | WORD32 qpg_x = (cu_pos_x - (cu_pos_x & ((1 << ps_pps->i1_log2_min_cu_qp_delta_size) - 1))); |
2084 | 4.20M | WORD32 qpg_y = (cu_pos_y - (cu_pos_y & ((1 << ps_pps->i1_log2_min_cu_qp_delta_size) - 1))); |
2085 | | |
2086 | 4.20M | if((cu_pos_x == qpg_x) && |
2087 | 1.11M | (cu_pos_y == qpg_y)) |
2088 | 576k | { |
2089 | 576k | ps_codec->s_parse.u4_qpg = ps_codec->s_parse.u4_qp; |
2090 | | |
2091 | 576k | ps_codec->s_parse.s_cu.i4_cu_qp_delta = 0; |
2092 | | |
2093 | 576k | } |
2094 | 4.20M | } |
2095 | | |
2096 | 4.20M | ret = ihevcd_parse_coding_unit(ps_codec, x0, y0, log2_cb_size); |
2097 | 4.20M | RETURN_IF((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret, ret); |
2098 | | |
2099 | 4.20M | if(ps_pps->i1_cu_qp_delta_enabled_flag) |
2100 | 2.89M | { |
2101 | 2.89M | WORD32 qp_pred, qp_left, qp_top; |
2102 | 2.89M | WORD32 cu_pos_x; |
2103 | 2.89M | WORD32 cu_pos_y; |
2104 | 2.89M | WORD32 qpg_x; |
2105 | 2.89M | WORD32 qpg_y; |
2106 | 2.89M | WORD32 i, j; |
2107 | 2.89M | WORD32 cur_cu_offset; |
2108 | 2.89M | tu_t *ps_tu = ps_codec->s_parse.ps_tu; |
2109 | 2.89M | WORD32 cb_size = 1 << ps_codec->s_parse.s_cu.i4_log2_cb_size; |
2110 | | |
2111 | 2.89M | cu_pos_x = ps_codec->s_parse.s_cu.i4_pos_x << 3; |
2112 | 2.89M | cu_pos_y = ps_codec->s_parse.s_cu.i4_pos_y << 3; |
2113 | | |
2114 | 2.89M | qpg_x = (cu_pos_x - (cu_pos_x & ((1 << ps_pps->i1_log2_min_cu_qp_delta_size) - 1))) >> 3; |
2115 | 2.89M | qpg_y = (cu_pos_y - (cu_pos_y & ((1 << ps_pps->i1_log2_min_cu_qp_delta_size) - 1))) >> 3; |
2116 | | |
2117 | | /*previous coded Qp*/ |
2118 | 2.89M | qp_left = ps_codec->s_parse.u4_qpg; |
2119 | 2.89M | qp_top = ps_codec->s_parse.u4_qpg; |
2120 | | |
2121 | 2.89M | if(qpg_x > 0) |
2122 | 30.9k | { |
2123 | 30.9k | qp_left = ps_codec->s_parse.ai1_8x8_cu_qp[qpg_x - 1 + (qpg_y * 8)]; |
2124 | 30.9k | } |
2125 | 2.89M | if(qpg_y > 0) |
2126 | 33.3k | { |
2127 | 33.3k | qp_top = ps_codec->s_parse.ai1_8x8_cu_qp[qpg_x + ((qpg_y - 1) * 8)]; |
2128 | 33.3k | } |
2129 | | |
2130 | 2.89M | qp_pred = (qp_left + qp_top + 1) >> 1; |
2131 | | /* Since qp_pred + ps_codec->s_parse.s_cu.i4_cu_qp_delta can be negative, |
2132 | | 52 is added before taking modulo 52 */ |
2133 | 2.89M | qp = (qp_pred + ps_codec->s_parse.s_cu.i4_cu_qp_delta + 52) % 52; |
2134 | | |
2135 | 2.89M | cur_cu_offset = (cu_pos_x >> 3) + cu_pos_y; |
2136 | 7.83M | for(i = 0; i < (cb_size >> 3); i++) |
2137 | 4.94M | { |
2138 | 20.1M | for(j = 0; j < (cb_size >> 3); j++) |
2139 | 15.2M | { |
2140 | 15.2M | ps_codec->s_parse.ai1_8x8_cu_qp[cur_cu_offset + (i * 8) + j] = qp; |
2141 | 15.2M | } |
2142 | 4.94M | } |
2143 | | |
2144 | 2.89M | ps_codec->s_parse.u4_qp = qp; |
2145 | 2.89M | ps_codec->s_parse.s_cu.i4_qp = qp; |
2146 | | |
2147 | | |
2148 | | /* When change in QP is signaled, update the QP in TUs that are already parsed in the CU */ |
2149 | 2.89M | { |
2150 | 2.89M | tu_t *ps_tu_tmp; |
2151 | 2.89M | ps_tu_tmp = ps_tu - ps_codec->s_parse.s_cu.i4_tu_cnt; |
2152 | 2.89M | ps_tu->b7_qp = ps_codec->s_parse.u4_qp; |
2153 | 7.03M | while(ps_tu_tmp != ps_tu) |
2154 | 4.13M | { |
2155 | 4.13M | ps_tu_tmp->b7_qp = ps_codec->s_parse.u4_qp; |
2156 | | |
2157 | 4.13M | ps_tu_tmp++; |
2158 | 4.13M | } |
2159 | 2.89M | } |
2160 | 2.89M | if(ps_codec->s_parse.s_cu.i4_cu_qp_delta) |
2161 | 495k | { |
2162 | 495k | WORD32 ctb_indx; |
2163 | 495k | ctb_indx = ps_codec->s_parse.i4_ctb_x + ps_sps->i2_pic_wd_in_ctb * ps_codec->s_parse.i4_ctb_y; |
2164 | 495k | ps_codec->s_parse.s_bs_ctxt.pu1_pic_qp_const_in_ctb[ctb_indx >> 3] &= (~(1 << (ctb_indx & 7))); |
2165 | 495k | } |
2166 | | |
2167 | 2.89M | } |
2168 | | /* Populate CU_info maps for current CU*/ |
2169 | 4.20M | if(ps_codec->u1_enable_cu_info) |
2170 | 0 | { |
2171 | 0 | WORD32 cu_info_map_stride = ALIGN64(ps_codec->i4_wd) >> 3; |
2172 | 0 | UWORD8 num_8x8_blks = 1 << (log2_cb_size - 3); |
2173 | 0 | WORD32 vert_8x8, horz_8x8; |
2174 | 0 | UWORD8 *pu1_cur_cu_type_map = |
2175 | 0 | ps_codec->as_buf_id_info_map[ps_codec->as_process[0]. |
2176 | 0 | i4_cur_pic_buf_id].pu1_cu_type_map; |
2177 | 0 | UWORD8 *pu1_cur_qp_map = |
2178 | 0 | ps_codec->as_buf_id_info_map[ps_codec->as_process[0].i4_cur_pic_buf_id].pu1_qp_map; |
2179 | 0 | UWORD8 *pu1_cur_type_cu = pu1_cur_cu_type_map + (x0 >> 3) + |
2180 | 0 | (y0 >> 3) * cu_info_map_stride; |
2181 | 0 | UWORD8 *pu1_cur_qp_cu = pu1_cur_qp_map + (x0 >> 3) + |
2182 | 0 | (y0 >> 3) * cu_info_map_stride; |
2183 | 0 | for(vert_8x8 = 0; vert_8x8 < num_8x8_blks; vert_8x8++) |
2184 | 0 | { |
2185 | 0 | for(horz_8x8 = 0; horz_8x8 < num_8x8_blks; horz_8x8++) |
2186 | 0 | { |
2187 | 0 | pu1_cur_qp_cu[horz_8x8] = qp; |
2188 | 0 | pu1_cur_type_cu[horz_8x8] = ps_codec->s_parse.s_cu.i4_pred_mode; |
2189 | 0 | } |
2190 | 0 | pu1_cur_qp_cu += cu_info_map_stride; |
2191 | 0 | pu1_cur_type_cu += cu_info_map_stride; |
2192 | 0 | } |
2193 | 0 | } |
2194 | | |
2195 | 4.20M | } |
2196 | | |
2197 | | |
2198 | | |
2199 | | |
2200 | 5.57M | return ret; |
2201 | 5.57M | } |
2202 | | |
2203 | | |
2204 | | /** |
2205 | | ******************************************************************************* |
2206 | | * |
2207 | | * @brief |
2208 | | * Parses SAO (Sample adaptive offset syntax) |
2209 | | * |
2210 | | * @par Description: |
2211 | | * Parses SAO (Sample adaptive offset syntax) as per Section:7.3.9.3 |
2212 | | * |
2213 | | * @param[in] ps_codec |
2214 | | * Pointer to codec context |
2215 | | * |
2216 | | * @returns Error from IHEVCD_ERROR_T |
2217 | | * |
2218 | | * @remarks |
2219 | | * |
2220 | | * |
2221 | | ******************************************************************************* |
2222 | | */ |
2223 | | IHEVCD_ERROR_T ihevcd_parse_sao(codec_t *ps_codec) |
2224 | 325k | { |
2225 | 325k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
2226 | 325k | sps_t *ps_sps; |
2227 | 325k | sao_t *ps_sao; |
2228 | 325k | WORD32 rx; |
2229 | 325k | WORD32 ry; |
2230 | 325k | WORD32 value; |
2231 | 325k | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
2232 | 325k | WORD32 sao_merge_left_flag; |
2233 | 325k | WORD32 sao_merge_up_flag; |
2234 | 325k | slice_header_t *ps_slice_hdr; |
2235 | 325k | cab_ctxt_t *ps_cabac = &ps_codec->s_parse.s_cabac; |
2236 | 325k | WORD32 ctxt_idx; |
2237 | | |
2238 | 325k | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr_base; |
2239 | 325k | ps_slice_hdr += (ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1)); |
2240 | | |
2241 | 325k | ps_sps = (ps_codec->s_parse.ps_sps); |
2242 | 325k | rx = ps_codec->s_parse.i4_ctb_x; |
2243 | 325k | ry = ps_codec->s_parse.i4_ctb_y; |
2244 | | |
2245 | 325k | ps_sao = ps_codec->s_parse.ps_pic_sao + rx + ry * ps_sps->i2_pic_wd_in_ctb; |
2246 | | |
2247 | | /* Default values */ |
2248 | 325k | ps_sao->b3_y_type_idx = 0; |
2249 | 325k | ps_sao->b3_cb_type_idx = 0; |
2250 | 325k | ps_sao->b3_cr_type_idx = 0; |
2251 | | |
2252 | 325k | UNUSED(value); |
2253 | 325k | ctxt_idx = IHEVC_CAB_SAO_MERGE; |
2254 | 325k | sao_merge_left_flag = 0; |
2255 | 325k | sao_merge_up_flag = 0; |
2256 | 325k | if(rx > 0) |
2257 | 292k | { |
2258 | | /*TODO:Implemented only for slice. condition for tile is not tested*/ |
2259 | 292k | if(((0 != ps_codec->s_parse.i4_ctb_slice_x) || (0 != ps_codec->s_parse.i4_ctb_slice_y)) && |
2260 | 291k | (0 != ps_codec->s_parse.i4_ctb_tile_x)) |
2261 | 282k | { |
2262 | | |
2263 | 282k | TRACE_CABAC_CTXT("sao_merge_flag", ps_cabac->u4_range, ctxt_idx); |
2264 | 282k | sao_merge_left_flag = ihevcd_cabac_decode_bin(ps_cabac, |
2265 | 282k | ps_bitstrm, |
2266 | 282k | ctxt_idx); |
2267 | 282k | AEV_TRACE("sao_merge_flag", sao_merge_left_flag, ps_cabac->u4_range); |
2268 | 282k | } |
2269 | | |
2270 | 292k | } |
2271 | 325k | if(ry > 0 && !sao_merge_left_flag) |
2272 | 193k | { |
2273 | 193k | if((ps_codec->s_parse.i4_ctb_slice_y > 0) && (ps_codec->s_parse.i4_ctb_tile_y > 0)) |
2274 | 155k | { |
2275 | 155k | TRACE_CABAC_CTXT("sao_merge_flag", ps_cabac->u4_range, ctxt_idx); |
2276 | 155k | sao_merge_up_flag = ihevcd_cabac_decode_bin(ps_cabac, |
2277 | 155k | ps_bitstrm, |
2278 | 155k | ctxt_idx); |
2279 | 155k | AEV_TRACE("sao_merge_flag", sao_merge_up_flag, ps_cabac->u4_range); |
2280 | 155k | } |
2281 | 193k | } |
2282 | 325k | ctxt_idx = IHEVC_CAB_SAO_TYPE; |
2283 | | |
2284 | 325k | if(sao_merge_left_flag) |
2285 | 87.7k | { |
2286 | 87.7k | *ps_sao = *(ps_sao - 1); |
2287 | 87.7k | } |
2288 | 238k | else if(sao_merge_up_flag) |
2289 | 31.7k | { |
2290 | 31.7k | *ps_sao = *(ps_sao - ps_sps->i2_pic_wd_in_ctb); |
2291 | 31.7k | } |
2292 | 206k | else // if(!sao_merge_up_flag && !sao_merge_left_flag) |
2293 | 206k | { |
2294 | 206k | WORD32 c_idx; |
2295 | 206k | WORD32 sao_type_idx = 0; |
2296 | 825k | for(c_idx = 0; c_idx < (CHROMA_FMT_IDC_MONOCHROME != ps_sps->i1_chroma_format_idc ? 3 : 1); c_idx++) |
2297 | 619k | { |
2298 | 619k | if((ps_slice_hdr->i1_slice_sao_luma_flag && c_idx == 0) || (ps_slice_hdr->i1_slice_sao_chroma_flag && c_idx > 0)) |
2299 | 556k | { |
2300 | | |
2301 | | |
2302 | | /* sao_type_idx will be same for c_idx == 1 and c_idx == 2 - hence not initialized to zero for c_idx == 2*/ |
2303 | | |
2304 | 556k | if(c_idx == 0) |
2305 | 202k | { |
2306 | 202k | sao_type_idx = 0; |
2307 | 202k | TRACE_CABAC_CTXT("sao_type_idx", ps_cabac->u4_range, ctxt_idx); |
2308 | 202k | sao_type_idx = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
2309 | | |
2310 | 202k | if(sao_type_idx) |
2311 | 115k | { |
2312 | 115k | sao_type_idx += ihevcd_cabac_decode_bypass_bin(ps_cabac, ps_bitstrm); |
2313 | 115k | } |
2314 | 202k | AEV_TRACE("sao_type_idx", sao_type_idx, ps_cabac->u4_range); |
2315 | | |
2316 | 202k | ps_sao->b3_y_type_idx = sao_type_idx; |
2317 | 202k | } |
2318 | 556k | if(c_idx == 1) |
2319 | 177k | { |
2320 | 177k | sao_type_idx = 0; |
2321 | 177k | TRACE_CABAC_CTXT("sao_type_idx", ps_cabac->u4_range, ctxt_idx); |
2322 | 177k | sao_type_idx = ihevcd_cabac_decode_bin(ps_cabac, ps_bitstrm, ctxt_idx); |
2323 | 177k | if(sao_type_idx) |
2324 | 84.9k | { |
2325 | 84.9k | sao_type_idx += ihevcd_cabac_decode_bypass_bin(ps_cabac, ps_bitstrm); |
2326 | 84.9k | } |
2327 | | |
2328 | 177k | AEV_TRACE("sao_type_idx", sao_type_idx, ps_cabac->u4_range); |
2329 | | |
2330 | 177k | ps_sao->b3_cb_type_idx = sao_type_idx; |
2331 | 177k | ps_sao->b3_cr_type_idx = sao_type_idx; |
2332 | 177k | } |
2333 | | |
2334 | 556k | if(sao_type_idx != 0) |
2335 | 285k | { |
2336 | 285k | WORD32 i; |
2337 | 285k | WORD32 sao_offset[4]; |
2338 | 285k | WORD32 sao_band_position = 0; |
2339 | 285k | WORD32 c_max = (1 << (MIN(BIT_DEPTH, 10) - 5)) - 1; |
2340 | 1.42M | for(i = 0; i < 4; i++) |
2341 | 1.14M | { |
2342 | 1.14M | sao_offset[i] = ihevcd_cabac_decode_bypass_bins_tunary(ps_cabac, ps_bitstrm, c_max); |
2343 | 1.14M | AEV_TRACE("sao_offset_abs", sao_offset[i], ps_cabac->u4_range); |
2344 | | |
2345 | 1.14M | if((2 == sao_type_idx) && (i > 1)) |
2346 | 266k | { |
2347 | 266k | sao_offset[i] = -sao_offset[i]; |
2348 | 266k | } |
2349 | 1.14M | } |
2350 | | |
2351 | 285k | if(sao_type_idx == 1) |
2352 | 151k | { |
2353 | 758k | for(i = 0; i < 4; i++) |
2354 | 606k | { |
2355 | 606k | if(sao_offset[i] != 0) |
2356 | 329k | { |
2357 | 329k | value = ihevcd_cabac_decode_bypass_bin(ps_cabac, ps_bitstrm); |
2358 | 329k | AEV_TRACE("sao_offset_sign", value, ps_cabac->u4_range); |
2359 | | |
2360 | 329k | if(value) |
2361 | 174k | { |
2362 | 174k | sao_offset[i] = -sao_offset[i]; |
2363 | 174k | } |
2364 | 329k | } |
2365 | 606k | } |
2366 | 151k | value = ihevcd_cabac_decode_bypass_bins(ps_cabac, ps_bitstrm, 5); |
2367 | 151k | AEV_TRACE("sao_band_position", value, ps_cabac->u4_range); |
2368 | | |
2369 | 151k | sao_band_position = value; |
2370 | 151k | } |
2371 | 133k | else |
2372 | 133k | { |
2373 | 133k | if(c_idx == 0) |
2374 | 50.3k | { |
2375 | 50.3k | value = ihevcd_cabac_decode_bypass_bins(ps_cabac, ps_bitstrm, 2); |
2376 | 50.3k | AEV_TRACE("sao_eo_class", value, ps_cabac->u4_range); |
2377 | | |
2378 | 50.3k | ps_sao->b3_y_type_idx += value; |
2379 | 50.3k | } |
2380 | | |
2381 | 133k | if(c_idx == 1) |
2382 | 41.5k | { |
2383 | 41.5k | value = ihevcd_cabac_decode_bypass_bins(ps_cabac, ps_bitstrm, 2); |
2384 | 41.5k | AEV_TRACE("sao_eo_class", value, ps_cabac->u4_range); |
2385 | | |
2386 | 41.5k | ps_sao->b3_cb_type_idx += value; |
2387 | 41.5k | ps_sao->b3_cr_type_idx += value; |
2388 | 41.5k | } |
2389 | 133k | } |
2390 | | |
2391 | 285k | if(0 == c_idx) |
2392 | 115k | { |
2393 | 115k | ps_sao->b4_y_offset_1 = sao_offset[0]; |
2394 | 115k | ps_sao->b4_y_offset_2 = sao_offset[1]; |
2395 | 115k | ps_sao->b4_y_offset_3 = sao_offset[2]; |
2396 | 115k | ps_sao->b4_y_offset_4 = sao_offset[3]; |
2397 | | |
2398 | 115k | ps_sao->b5_y_band_pos = sao_band_position; |
2399 | 115k | } |
2400 | 169k | else if(1 == c_idx) |
2401 | 84.9k | { |
2402 | 84.9k | ps_sao->b4_cb_offset_1 = sao_offset[0]; |
2403 | 84.9k | ps_sao->b4_cb_offset_2 = sao_offset[1]; |
2404 | 84.9k | ps_sao->b4_cb_offset_3 = sao_offset[2]; |
2405 | 84.9k | ps_sao->b4_cb_offset_4 = sao_offset[3]; |
2406 | | |
2407 | 84.9k | ps_sao->b5_cb_band_pos = sao_band_position; |
2408 | 84.9k | } |
2409 | 84.9k | else // 2 == c_idx |
2410 | 84.9k | { |
2411 | 84.9k | ps_sao->b4_cr_offset_1 = sao_offset[0]; |
2412 | 84.9k | ps_sao->b4_cr_offset_2 = sao_offset[1]; |
2413 | 84.9k | ps_sao->b4_cr_offset_3 = sao_offset[2]; |
2414 | 84.9k | ps_sao->b4_cr_offset_4 = sao_offset[3]; |
2415 | | |
2416 | 84.9k | ps_sao->b5_cr_band_pos = sao_band_position; |
2417 | 84.9k | } |
2418 | 285k | } |
2419 | 556k | } |
2420 | 619k | } |
2421 | 206k | } |
2422 | | |
2423 | 325k | return ret; |
2424 | 325k | } |
2425 | | /** |
2426 | | ******************************************************************************* |
2427 | | * |
2428 | | * @brief |
2429 | | * Set ctb skip |
2430 | | * |
2431 | | * @par Description: |
2432 | | * During error, sets tu and pu params of a ctb as skip. |
2433 | | * |
2434 | | * @param[in] ps_codec |
2435 | | * Pointer to codec context |
2436 | | * |
2437 | | * @returns None |
2438 | | * |
2439 | | * @remarks |
2440 | | * |
2441 | | * |
2442 | | ******************************************************************************* |
2443 | | */ |
2444 | | void ihevcd_set_ctb_skip(codec_t *ps_codec) |
2445 | 2.06M | { |
2446 | 2.06M | tu_t *ps_tu; |
2447 | 2.06M | pu_t *ps_pu; |
2448 | 2.06M | sps_t *ps_sps = ps_codec->s_parse.ps_sps; |
2449 | 2.06M | WORD32 ctb_size = 1 << ps_sps->i1_log2_ctb_size; |
2450 | 2.06M | WORD32 ctb_skip_wd, ctb_skip_ht; |
2451 | 2.06M | WORD32 rows_remaining, cols_remaining; |
2452 | 2.06M | WORD32 tu_abs_x, tu_abs_y; |
2453 | 2.06M | WORD32 numbytes_row = (ps_sps->i2_pic_width_in_luma_samples + 63) / 64; |
2454 | 2.06M | UWORD8 *pu1_pic_intra_flag; |
2455 | 2.06M | UWORD32 u4_mask; |
2456 | 2.06M | WORD32 pu_x,pu_y; |
2457 | | |
2458 | | /* Set pu wd and ht based on whether the ctb is complete or not */ |
2459 | 2.06M | rows_remaining = ps_sps->i2_pic_height_in_luma_samples |
2460 | 2.06M | - (ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size); |
2461 | 2.06M | ctb_skip_ht = MIN(ctb_size, rows_remaining); |
2462 | | |
2463 | 2.06M | cols_remaining = ps_sps->i2_pic_width_in_luma_samples |
2464 | 2.06M | - (ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size); |
2465 | 2.06M | ctb_skip_wd = MIN(ctb_size, cols_remaining); |
2466 | | |
2467 | 2.06M | ps_codec->s_parse.s_cu.i4_pred_mode = PRED_MODE_SKIP; |
2468 | 2.06M | ps_codec->s_parse.s_cu.i4_part_mode = PART_2Nx2N; |
2469 | | |
2470 | 9.33M | for (pu_y = 0; pu_y < ctb_skip_ht ; pu_y += MIN_CU_SIZE) |
2471 | 7.26M | { |
2472 | 44.3M | for (pu_x = 0; pu_x < ctb_skip_wd ; pu_x += MIN_CU_SIZE) |
2473 | 37.1M | { |
2474 | 37.1M | ps_tu = ps_codec->s_parse.ps_tu; |
2475 | 37.1M | ps_tu->b1_cb_cbf = 0; |
2476 | 37.1M | #ifdef ENABLE_MAIN_REXT_PROFILE |
2477 | 37.1M | ps_tu->b1_cb_cbf_subtu1 = 0; |
2478 | 37.1M | #endif |
2479 | 37.1M | ps_tu->b1_cr_cbf = 0; |
2480 | 37.1M | #ifdef ENABLE_MAIN_REXT_PROFILE |
2481 | 37.1M | ps_tu->b1_cr_cbf_subtu1 = 0; |
2482 | 37.1M | #endif |
2483 | 37.1M | ps_tu->b1_y_cbf = 0; |
2484 | 37.1M | ps_tu->b4_pos_x = pu_x >> 2; |
2485 | 37.1M | ps_tu->b4_pos_y = pu_y >> 2; |
2486 | 37.1M | ps_tu->b1_transquant_bypass = 0; |
2487 | 37.1M | ps_tu->b3_size = 1; |
2488 | 37.1M | ps_tu->b7_qp = ps_codec->s_parse.u4_qp; |
2489 | 37.1M | ps_tu->b3_chroma_intra_mode_idx = INTRA_PRED_CHROMA_IDX_NONE; |
2490 | 37.1M | ps_tu->b6_luma_intra_mode = INTRA_PRED_NONE; |
2491 | 37.1M | #ifdef ENABLE_MAIN_REXT_PROFILE |
2492 | 37.1M | ps_tu->b3_cb_log2_res_scale_abs_plus1 = 0; |
2493 | 37.1M | ps_tu->b1_cb_log2_res_sign = 0; |
2494 | 37.1M | ps_tu->b3_cr_log2_res_scale_abs_plus1 = 0; |
2495 | 37.1M | ps_tu->b1_cr_log2_res_sign = 0; |
2496 | 37.1M | #endif |
2497 | 37.1M | ps_tu->b1_first_tu_in_cu = 1; |
2498 | | |
2499 | 37.1M | ps_codec->s_parse.ps_tu++; |
2500 | 37.1M | ps_codec->s_parse.s_cu.i4_tu_cnt++; |
2501 | 37.1M | ps_codec->s_parse.i4_pic_tu_idx++; |
2502 | | |
2503 | 37.1M | tu_abs_x = (ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size) + pu_x; |
2504 | 37.1M | tu_abs_y = (ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size) + pu_y; |
2505 | 37.1M | pu1_pic_intra_flag = ps_codec->s_parse.pu1_pic_intra_flag; |
2506 | 37.1M | pu1_pic_intra_flag += (tu_abs_y >> 3) * numbytes_row; |
2507 | 37.1M | pu1_pic_intra_flag += (tu_abs_x >> 6); |
2508 | 37.1M | u4_mask = (LSB_ONES((MIN_CU_SIZE >> 3)) << (((tu_abs_x) / 8) % 8)); |
2509 | 37.1M | u4_mask = ~u4_mask; |
2510 | 37.1M | *pu1_pic_intra_flag &= u4_mask; |
2511 | | |
2512 | 37.1M | ps_pu = ps_codec->s_parse.ps_pu; |
2513 | 37.1M | ps_pu->b2_part_idx = 0; |
2514 | 37.1M | ps_pu->b4_pos_x = pu_x >> 2; |
2515 | 37.1M | ps_pu->b4_pos_y = pu_y >> 2; |
2516 | 37.1M | ps_pu->b4_wd = 1; |
2517 | 37.1M | ps_pu->b4_ht = 1; |
2518 | 37.1M | ps_pu->b1_intra_flag = 0; |
2519 | 37.1M | ps_pu->b3_part_mode = ps_codec->s_parse.s_cu.i4_part_mode; |
2520 | 37.1M | ps_pu->b1_merge_flag = 1; |
2521 | 37.1M | ps_pu->b3_merge_idx = 0; |
2522 | | |
2523 | 37.1M | ps_codec->s_parse.ps_pu++; |
2524 | 37.1M | ps_codec->s_parse.i4_pic_pu_idx++; |
2525 | 37.1M | } |
2526 | 7.26M | } |
2527 | 2.06M | } |
2528 | | |
2529 | | /** |
2530 | | ******************************************************************************* |
2531 | | * |
2532 | | * @brief |
2533 | | * Parses Slice data syntax |
2534 | | * |
2535 | | * @par Description: |
2536 | | * Parses Slice data syntax as per Section:7.3.9.1 |
2537 | | * |
2538 | | * @param[in] ps_codec |
2539 | | * Pointer to codec context |
2540 | | * |
2541 | | * @returns Error from IHEVCD_ERROR_T |
2542 | | * |
2543 | | * @remarks |
2544 | | * |
2545 | | * |
2546 | | ******************************************************************************* |
2547 | | */ |
2548 | | IHEVCD_ERROR_T ihevcd_parse_slice_data(codec_t *ps_codec) |
2549 | 22.1k | { |
2550 | | |
2551 | 22.1k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
2552 | 22.1k | WORD32 end_of_slice_flag = 0; |
2553 | 22.1k | sps_t *ps_sps; |
2554 | 22.1k | pps_t *ps_pps; |
2555 | 22.1k | slice_header_t *ps_slice_hdr; |
2556 | 22.1k | WORD32 end_of_pic; |
2557 | 22.1k | tile_t *ps_tile, *ps_tile_prev; |
2558 | 22.1k | WORD32 i; |
2559 | 22.1k | WORD32 ctb_addr; |
2560 | 22.1k | WORD32 tile_idx; |
2561 | 22.1k | WORD32 cabac_init_idc; |
2562 | 22.1k | WORD32 ctb_size; |
2563 | 22.1k | WORD32 num_ctb_in_row; |
2564 | 22.1k | WORD32 num_min4x4_in_ctb; |
2565 | 22.1k | WORD32 slice_qp; |
2566 | 22.1k | WORD32 slice_start_ctb_idx; |
2567 | 22.1k | WORD32 tile_start_ctb_idx; |
2568 | | |
2569 | | |
2570 | 22.1k | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr_base; |
2571 | 22.1k | ps_pps = ps_codec->s_parse.ps_pps_base; |
2572 | 22.1k | ps_sps = ps_codec->s_parse.ps_sps_base; |
2573 | | |
2574 | | /* Get current slice header, pps and sps */ |
2575 | 22.1k | ps_slice_hdr += (ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1)); |
2576 | 22.1k | ps_pps += ps_slice_hdr->i1_pps_id; |
2577 | 22.1k | ps_sps += ps_pps->i1_sps_id; |
2578 | | |
2579 | 22.1k | if(0 != ps_codec->s_parse.i4_cur_slice_idx) |
2580 | 9.26k | { |
2581 | 9.26k | if(!ps_slice_hdr->i1_dependent_slice_flag) |
2582 | 6.98k | { |
2583 | 6.98k | ps_codec->s_parse.i4_cur_independent_slice_idx = |
2584 | 6.98k | ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1); |
2585 | 6.98k | } |
2586 | 9.26k | } |
2587 | | |
2588 | | |
2589 | 22.1k | ctb_size = 1 << ps_sps->i1_log2_ctb_size; |
2590 | 22.1k | num_min4x4_in_ctb = (ctb_size / 4) * (ctb_size / 4); |
2591 | 22.1k | num_ctb_in_row = ps_sps->i2_pic_wd_in_ctb; |
2592 | | |
2593 | | /* Update the parse context */ |
2594 | 22.1k | if(0 == ps_codec->i4_slice_error) |
2595 | 17.2k | { |
2596 | 17.2k | ps_codec->s_parse.i4_ctb_x = ps_slice_hdr->i2_ctb_x; |
2597 | 17.2k | ps_codec->s_parse.i4_ctb_y = ps_slice_hdr->i2_ctb_y; |
2598 | 17.2k | } |
2599 | 22.1k | ps_codec->s_parse.ps_pps = ps_pps; |
2600 | 22.1k | ps_codec->s_parse.ps_sps = ps_sps; |
2601 | 22.1k | ps_codec->s_parse.ps_slice_hdr = ps_slice_hdr; |
2602 | | |
2603 | | /* Derive Tile positions for the current CTB */ |
2604 | | /* Change this to lookup if required */ |
2605 | 22.1k | ihevcd_get_tile_pos(ps_pps, ps_sps, ps_codec->s_parse.i4_ctb_x, |
2606 | 22.1k | ps_codec->s_parse.i4_ctb_y, |
2607 | 22.1k | &ps_codec->s_parse.i4_ctb_tile_x, |
2608 | 22.1k | &ps_codec->s_parse.i4_ctb_tile_y, |
2609 | 22.1k | &tile_idx); |
2610 | 22.1k | ps_codec->s_parse.ps_tile = ps_pps->ps_tile + tile_idx; |
2611 | 22.1k | ps_codec->s_parse.i4_cur_tile_idx = tile_idx; |
2612 | 22.1k | ps_tile = ps_codec->s_parse.ps_tile; |
2613 | 22.1k | if(tile_idx) |
2614 | 3.69k | ps_tile_prev = ps_tile - 1; |
2615 | 18.4k | else |
2616 | 18.4k | ps_tile_prev = ps_tile; |
2617 | | |
2618 | | /* If the present slice is dependent, then store the previous |
2619 | | * independent slices' ctb x and y values for decoding process */ |
2620 | 22.1k | if(0 == ps_codec->i4_slice_error) |
2621 | 17.2k | { |
2622 | 17.2k | if(1 == ps_slice_hdr->i1_dependent_slice_flag) |
2623 | 2.18k | { |
2624 | | /*If slice is present at the start of a new tile*/ |
2625 | 2.18k | if((0 == ps_codec->s_parse.i4_ctb_tile_x) && (0 == ps_codec->s_parse.i4_ctb_tile_y)) |
2626 | 666 | { |
2627 | 666 | ps_codec->s_parse.i4_ctb_slice_x = 0; |
2628 | 666 | ps_codec->s_parse.i4_ctb_slice_y = 0; |
2629 | 666 | } |
2630 | 2.18k | } |
2631 | | |
2632 | 17.2k | if(!ps_slice_hdr->i1_dependent_slice_flag) |
2633 | 15.0k | { |
2634 | 15.0k | ps_codec->s_parse.i4_ctb_slice_x = 0; |
2635 | 15.0k | ps_codec->s_parse.i4_ctb_slice_y = 0; |
2636 | 15.0k | } |
2637 | 17.2k | } |
2638 | | |
2639 | | /* Frame level initializations */ |
2640 | 22.1k | if((0 == ps_codec->s_parse.i4_ctb_y) && |
2641 | 11.5k | (0 == ps_codec->s_parse.i4_ctb_x)) |
2642 | 8.94k | { |
2643 | 8.94k | ret = ihevcd_parse_pic_init(ps_codec); |
2644 | 8.94k | RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); |
2645 | | |
2646 | 8.78k | ps_codec->s_parse.pu4_pic_tu_idx[0] = 0; |
2647 | 8.78k | ps_codec->s_parse.pu4_pic_pu_idx[0] = 0; |
2648 | 8.78k | ps_codec->s_parse.i4_cur_independent_slice_idx = 0; |
2649 | 8.78k | ps_codec->s_parse.i4_ctb_tile_x = 0; |
2650 | 8.78k | ps_codec->s_parse.i4_ctb_tile_y = 0; |
2651 | 8.78k | } |
2652 | | |
2653 | 21.9k | { |
2654 | | /* Updating the poc list of current slice to ps_mv_buf */ |
2655 | 21.9k | mv_buf_t *ps_mv_buf = ps_codec->s_parse.ps_cur_mv_buf; |
2656 | | |
2657 | 21.9k | if(ps_slice_hdr->i1_num_ref_idx_l1_active != 0) |
2658 | 16.2k | { |
2659 | 48.6k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) |
2660 | 32.4k | { |
2661 | 32.4k | ps_mv_buf->ai4_l1_collocated_poc[(ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1))][i] = ((pic_buf_t *)ps_slice_hdr->as_ref_pic_list1[i].pv_pic_buf)->i4_abs_poc; |
2662 | 32.4k | ps_mv_buf->ai1_l1_collocated_poc_lt[(ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1))][i] = ((pic_buf_t *)ps_slice_hdr->as_ref_pic_list1[i].pv_pic_buf)->u1_used_as_ref; |
2663 | 32.4k | } |
2664 | 16.2k | } |
2665 | | |
2666 | 21.9k | if(ps_slice_hdr->i1_num_ref_idx_l0_active != 0) |
2667 | 16.5k | { |
2668 | 51.2k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) |
2669 | 34.7k | { |
2670 | 34.7k | ps_mv_buf->ai4_l0_collocated_poc[(ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1))][i] = ((pic_buf_t *)ps_slice_hdr->as_ref_pic_list0[i].pv_pic_buf)->i4_abs_poc; |
2671 | 34.7k | ps_mv_buf->ai1_l0_collocated_poc_lt[(ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1))][i] = ((pic_buf_t *)ps_slice_hdr->as_ref_pic_list0[i].pv_pic_buf)->u1_used_as_ref; |
2672 | 34.7k | } |
2673 | 16.5k | } |
2674 | 21.9k | } |
2675 | | |
2676 | | /*Initialize the low delay flag at the beginning of every slice*/ |
2677 | 21.9k | if((0 == ps_codec->s_parse.i4_ctb_slice_x) || (0 == ps_codec->s_parse.i4_ctb_slice_y)) |
2678 | 18.2k | { |
2679 | | /* Lowdelay flag */ |
2680 | 18.2k | WORD32 cur_poc, ref_list_poc, flag = 1; |
2681 | 18.2k | cur_poc = ps_slice_hdr->i4_abs_pic_order_cnt; |
2682 | 43.3k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) |
2683 | 27.6k | { |
2684 | 27.6k | ref_list_poc = ((mv_buf_t *)ps_slice_hdr->as_ref_pic_list0[i].pv_mv_buf)->i4_abs_poc; |
2685 | 27.6k | if(ref_list_poc > cur_poc) |
2686 | 2.55k | { |
2687 | 2.55k | flag = 0; |
2688 | 2.55k | break; |
2689 | 2.55k | } |
2690 | 27.6k | } |
2691 | 18.2k | if(flag && (ps_slice_hdr->i1_slice_type == BSLICE)) |
2692 | 10.6k | { |
2693 | 18.9k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) |
2694 | 15.2k | { |
2695 | 15.2k | ref_list_poc = ((mv_buf_t *)ps_slice_hdr->as_ref_pic_list1[i].pv_mv_buf)->i4_abs_poc; |
2696 | 15.2k | if(ref_list_poc > cur_poc) |
2697 | 6.95k | { |
2698 | 6.95k | flag = 0; |
2699 | 6.95k | break; |
2700 | 6.95k | } |
2701 | 15.2k | } |
2702 | 10.6k | } |
2703 | 18.2k | ps_slice_hdr->i1_low_delay_flag = flag; |
2704 | 18.2k | } |
2705 | | |
2706 | | /* initialize the cabac init idc based on slice type */ |
2707 | 21.9k | if(ps_slice_hdr->i1_slice_type == ISLICE) |
2708 | 5.37k | { |
2709 | 5.37k | cabac_init_idc = 0; |
2710 | 5.37k | } |
2711 | 16.5k | else if(ps_slice_hdr->i1_slice_type == PSLICE) |
2712 | 352 | { |
2713 | 352 | cabac_init_idc = ps_slice_hdr->i1_cabac_init_flag ? 2 : 1; |
2714 | 352 | } |
2715 | 16.2k | else |
2716 | 16.2k | { |
2717 | 16.2k | cabac_init_idc = ps_slice_hdr->i1_cabac_init_flag ? 1 : 2; |
2718 | 16.2k | } |
2719 | | |
2720 | 21.9k | slice_qp = ps_slice_hdr->i1_slice_qp_delta + ps_pps->i1_pic_init_qp; |
2721 | 21.9k | slice_qp = CLIP3(slice_qp, 0, 51); |
2722 | | |
2723 | | /*Update QP value for every indepndent slice or for every dependent slice that begins at the start of a new tile*/ |
2724 | 21.9k | if((0 == ps_slice_hdr->i1_dependent_slice_flag) || |
2725 | 2.27k | ((1 == ps_slice_hdr->i1_dependent_slice_flag) && ((0 == ps_codec->s_parse.i4_ctb_tile_x) && (0 == ps_codec->s_parse.i4_ctb_tile_y)))) |
2726 | 20.3k | { |
2727 | 20.3k | ps_codec->s_parse.u4_qp = slice_qp; |
2728 | 20.3k | } |
2729 | | |
2730 | | /*Cabac init at the beginning of a slice*/ |
2731 | | //If the slice is a dependent slice, not present at the start of a tile |
2732 | 21.9k | if(0 == ps_codec->i4_slice_error) |
2733 | 17.1k | { |
2734 | 17.1k | if((1 == ps_slice_hdr->i1_dependent_slice_flag) && (!((ps_codec->s_parse.i4_ctb_tile_x == 0) && (ps_codec->s_parse.i4_ctb_tile_y == 0)))) |
2735 | 1.51k | { |
2736 | 1.51k | if((0 == ps_pps->i1_entropy_coding_sync_enabled_flag) || (ps_pps->i1_entropy_coding_sync_enabled_flag && (0 != ps_codec->s_parse.i4_ctb_x))) |
2737 | 1.51k | { |
2738 | 1.51k | ihevcd_cabac_reset(&ps_codec->s_parse.s_cabac, |
2739 | 1.51k | &ps_codec->s_parse.s_bitstrm); |
2740 | 1.51k | } |
2741 | 1.51k | } |
2742 | 15.6k | else if((0 == ps_pps->i1_entropy_coding_sync_enabled_flag) || (ps_pps->i1_entropy_coding_sync_enabled_flag && (0 != ps_codec->s_parse.i4_ctb_x))) |
2743 | 13.5k | { |
2744 | 13.5k | ret = ihevcd_cabac_init(&ps_codec->s_parse.s_cabac, |
2745 | 13.5k | &ps_codec->s_parse.s_bitstrm, |
2746 | 13.5k | slice_qp, |
2747 | 13.5k | cabac_init_idc, |
2748 | 13.5k | &gau1_ihevc_cab_ctxts[cabac_init_idc][slice_qp][0]); |
2749 | 13.5k | if(ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS) |
2750 | 6 | { |
2751 | 6 | ps_codec->i4_slice_error = 1; |
2752 | 6 | end_of_slice_flag = 1; |
2753 | 6 | ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
2754 | 6 | } |
2755 | 13.5k | } |
2756 | 17.1k | } |
2757 | | |
2758 | | |
2759 | 21.9k | do |
2760 | 2.61M | { |
2761 | | |
2762 | 2.61M | { |
2763 | 2.61M | WORD32 cur_ctb_idx = ps_codec->s_parse.i4_ctb_x |
2764 | 2.61M | + ps_codec->s_parse.i4_ctb_y * (ps_sps->i2_pic_wd_in_ctb); |
2765 | 2.61M | if(1 == ps_codec->i4_num_cores && 0 == cur_ctb_idx % RESET_TU_BUF_NCTB) |
2766 | 4.57k | { |
2767 | 4.57k | ps_codec->s_parse.ps_tu = ps_codec->s_parse.ps_pic_tu; |
2768 | 4.57k | ps_codec->s_parse.i4_pic_tu_idx = 0; |
2769 | 4.57k | } |
2770 | 2.61M | } |
2771 | | |
2772 | 2.61M | end_of_pic = 0; |
2773 | | /* Section:7.3.7 Coding tree unit syntax */ |
2774 | | /* coding_tree_unit() inlined here */ |
2775 | | /* If number of cores is greater than 1, then add job to the queue */ |
2776 | | //TODO: Dual core implementation might need a different algo for better load balancing |
2777 | | /* At the start of ctb row parsing in a tile, queue a job for processing the current tile row */ |
2778 | 2.61M | ps_codec->s_parse.i4_ctb_num_pcm_blks = 0; |
2779 | | |
2780 | | |
2781 | | /*At the beginning of each tile-which is not the beginning of a slice, cabac context must be initialized. |
2782 | | * Hence, check for the tile beginning here */ |
2783 | 2.61M | if(((0 == ps_codec->s_parse.i4_ctb_tile_x) && (0 == ps_codec->s_parse.i4_ctb_tile_y)) |
2784 | 26.4k | && (!((ps_tile->u1_pos_x == 0) && (ps_tile->u1_pos_y == 0))) |
2785 | 17.6k | && (!((0 == ps_codec->s_parse.i4_ctb_slice_x) && (0 == ps_codec->s_parse.i4_ctb_slice_y)))) |
2786 | 16.4k | { |
2787 | 16.4k | slice_qp = ps_slice_hdr->i1_slice_qp_delta + ps_pps->i1_pic_init_qp; |
2788 | 16.4k | slice_qp = CLIP3(slice_qp, 0, 51); |
2789 | 16.4k | ps_codec->s_parse.u4_qp = slice_qp; |
2790 | | |
2791 | 16.4k | ihevcd_get_tile_pos(ps_pps, ps_sps, ps_codec->s_parse.i4_ctb_x, |
2792 | 16.4k | ps_codec->s_parse.i4_ctb_y, |
2793 | 16.4k | &ps_codec->s_parse.i4_ctb_tile_x, |
2794 | 16.4k | &ps_codec->s_parse.i4_ctb_tile_y, |
2795 | 16.4k | &tile_idx); |
2796 | | |
2797 | 16.4k | ps_codec->s_parse.ps_tile = ps_pps->ps_tile + tile_idx; |
2798 | 16.4k | ps_codec->s_parse.i4_cur_tile_idx = tile_idx; |
2799 | 16.4k | ps_tile_prev = ps_tile - 1; |
2800 | | |
2801 | 16.4k | tile_start_ctb_idx = ps_tile->u1_pos_x |
2802 | 16.4k | + ps_tile->u1_pos_y * (ps_sps->i2_pic_wd_in_ctb); |
2803 | | |
2804 | 16.4k | slice_start_ctb_idx = ps_slice_hdr->i2_ctb_x |
2805 | 16.4k | + ps_slice_hdr->i2_ctb_y * (ps_sps->i2_pic_wd_in_ctb); |
2806 | | |
2807 | | /*For slices that span across multiple tiles*/ |
2808 | 16.4k | if(slice_start_ctb_idx < tile_start_ctb_idx) |
2809 | 16.4k | { /* 2 Cases |
2810 | | * 1 - slice spans across frame-width- but does not start from 1st column |
2811 | | * 2 - Slice spans across multiple tiles anywhere is a frame |
2812 | | */ |
2813 | 16.4k | ps_codec->s_parse.i4_ctb_slice_y = ps_tile->u1_pos_y - ps_slice_hdr->i2_ctb_y; |
2814 | 16.4k | if(!(((ps_slice_hdr->i2_ctb_x + ps_tile_prev->u2_wd) % ps_sps->i2_pic_wd_in_ctb) == ps_tile->u1_pos_x)) //Case 2 |
2815 | 7.64k | { |
2816 | 7.64k | if(ps_slice_hdr->i2_ctb_y <= ps_tile->u1_pos_y) |
2817 | 7.64k | { |
2818 | | //Check if ctb x is before or after |
2819 | 7.64k | if(ps_slice_hdr->i2_ctb_x > ps_tile->u1_pos_x) |
2820 | 198 | { |
2821 | 198 | ps_codec->s_parse.i4_ctb_slice_y -= 1; |
2822 | 198 | } |
2823 | 7.64k | } |
2824 | 7.64k | } |
2825 | | /*ps_codec->s_parse.i4_ctb_slice_y = ps_tile->u1_pos_y - ps_slice_hdr->i2_ctb_y; |
2826 | | if (ps_slice_hdr->i2_ctb_y <= ps_tile->u1_pos_y) |
2827 | | { |
2828 | | //Check if ctb x is before or after |
2829 | | if (ps_slice_hdr->i2_ctb_x > ps_tile->u1_pos_x ) |
2830 | | { |
2831 | | ps_codec->s_parse.i4_ctb_slice_y -= 1 ; |
2832 | | } |
2833 | | }*/ |
2834 | 16.4k | } |
2835 | | |
2836 | | /* Cabac init is done unconditionally at the start of the tile irrespective |
2837 | | * of whether it is a dependent or an independent slice */ |
2838 | 16.4k | if(0 == ps_codec->i4_slice_error) |
2839 | 7.97k | { |
2840 | 7.97k | ret = ihevcd_cabac_init(&ps_codec->s_parse.s_cabac, |
2841 | 7.97k | &ps_codec->s_parse.s_bitstrm, |
2842 | 7.97k | slice_qp, |
2843 | 7.97k | cabac_init_idc, |
2844 | 7.97k | &gau1_ihevc_cab_ctxts[cabac_init_idc][slice_qp][0]); |
2845 | 7.97k | if(ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS) |
2846 | 9 | { |
2847 | 9 | ps_codec->i4_slice_error = 1; |
2848 | 9 | end_of_slice_flag = 1; |
2849 | 9 | ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
2850 | 9 | } |
2851 | | |
2852 | 7.97k | } |
2853 | 16.4k | } |
2854 | | /* If number of cores is greater than 1, then add job to the queue */ |
2855 | | //TODO: Dual core implementation might need a different algo for better load balancing |
2856 | | /* At the start of ctb row parsing in a tile, queue a job for processing the current tile row */ |
2857 | | |
2858 | 2.61M | if(0 == ps_codec->s_parse.i4_ctb_tile_x) |
2859 | 184k | { |
2860 | | |
2861 | 184k | if(1 < ps_codec->i4_num_cores) |
2862 | 40.9k | { |
2863 | 40.9k | proc_job_t s_job; |
2864 | 40.9k | IHEVCD_ERROR_T ret; |
2865 | 40.9k | s_job.i4_cmd = CMD_PROCESS; |
2866 | 40.9k | s_job.i2_ctb_cnt = (WORD16)ps_tile->u2_wd; |
2867 | 40.9k | s_job.i2_ctb_x = (WORD16)ps_codec->s_parse.i4_ctb_x; |
2868 | 40.9k | s_job.i2_ctb_y = (WORD16)ps_codec->s_parse.i4_ctb_y; |
2869 | 40.9k | s_job.i2_slice_idx = (WORD16)ps_codec->s_parse.i4_cur_slice_idx; |
2870 | 40.9k | s_job.i4_tu_coeff_data_ofst = (UWORD8 *)ps_codec->s_parse.pv_tu_coeff_data - |
2871 | 40.9k | (UWORD8 *)ps_codec->s_parse.pv_pic_tu_coeff_data; |
2872 | 40.9k | ret = ihevcd_jobq_queue((jobq_t *)ps_codec->s_parse.pv_proc_jobq, &s_job, sizeof(proc_job_t), 1); |
2873 | | |
2874 | 40.9k | if(ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS) |
2875 | 0 | return ret; |
2876 | 40.9k | } |
2877 | 143k | else |
2878 | 143k | { |
2879 | 143k | process_ctxt_t *ps_proc = &ps_codec->as_process[0]; |
2880 | 143k | WORD32 tu_coeff_data_ofst = (UWORD8 *)ps_codec->s_parse.pv_tu_coeff_data - |
2881 | 143k | (UWORD8 *)ps_codec->s_parse.pv_pic_tu_coeff_data; |
2882 | | |
2883 | | /* If the codec is running in single core mode, |
2884 | | * initialize zeroth process context |
2885 | | * TODO: Dual core mode might need a different implementation instead of jobq |
2886 | | */ |
2887 | | |
2888 | 143k | ps_proc->i4_ctb_cnt = ps_tile->u2_wd; |
2889 | 143k | ps_proc->i4_ctb_x = ps_codec->s_parse.i4_ctb_x; |
2890 | 143k | ps_proc->i4_ctb_y = ps_codec->s_parse.i4_ctb_y; |
2891 | 143k | ps_proc->i4_cur_slice_idx = ps_codec->s_parse.i4_cur_slice_idx; |
2892 | | |
2893 | 143k | ihevcd_init_proc_ctxt(ps_proc, tu_coeff_data_ofst); |
2894 | 143k | } |
2895 | 184k | } |
2896 | | |
2897 | | |
2898 | | /* Restore cabac context model from top right CTB if entropy sync is enabled */ |
2899 | 2.61M | if(ps_pps->i1_entropy_coding_sync_enabled_flag) |
2900 | 170k | { |
2901 | | /*TODO Handle single CTB and top-right belonging to a different slice */ |
2902 | 170k | if(0 == ps_codec->s_parse.i4_ctb_x && 0 == ps_codec->i4_slice_error) |
2903 | 9.24k | { |
2904 | | //WORD32 size = sizeof(ps_codec->s_parse.s_cabac.au1_ctxt_models); |
2905 | 9.24k | WORD32 default_ctxt = 0; |
2906 | | |
2907 | 9.24k | if((0 == ps_codec->s_parse.i4_ctb_slice_y) && (!ps_slice_hdr->i1_dependent_slice_flag)) |
2908 | 2.04k | default_ctxt = 1; |
2909 | 9.24k | if(1 == ps_sps->i2_pic_wd_in_ctb) |
2910 | 350 | default_ctxt = 1; |
2911 | | |
2912 | 9.24k | ps_codec->s_parse.u4_qp = slice_qp; |
2913 | 9.24k | if(default_ctxt) |
2914 | 2.04k | { |
2915 | | //memcpy(&ps_codec->s_parse.s_cabac.au1_ctxt_models, &gau1_ihevc_cab_ctxts[cabac_init_idc][slice_qp][0], size); |
2916 | 2.04k | ret = ihevcd_cabac_init(&ps_codec->s_parse.s_cabac, |
2917 | 2.04k | &ps_codec->s_parse.s_bitstrm, |
2918 | 2.04k | slice_qp, |
2919 | 2.04k | cabac_init_idc, |
2920 | 2.04k | &gau1_ihevc_cab_ctxts[cabac_init_idc][slice_qp][0]); |
2921 | | |
2922 | 2.04k | if(ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS) |
2923 | 6 | { |
2924 | 6 | ps_codec->i4_slice_error = 1; |
2925 | 6 | end_of_slice_flag = 1; |
2926 | 6 | ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
2927 | 6 | } |
2928 | 2.04k | } |
2929 | 7.20k | else |
2930 | 7.20k | { |
2931 | | //memcpy(&ps_codec->s_parse.s_cabac.au1_ctxt_models, &ps_codec->s_parse.s_cabac.au1_ctxt_models_sync, size); |
2932 | 7.20k | ret = ihevcd_cabac_init(&ps_codec->s_parse.s_cabac, |
2933 | 7.20k | &ps_codec->s_parse.s_bitstrm, |
2934 | 7.20k | slice_qp, |
2935 | 7.20k | cabac_init_idc, |
2936 | 7.20k | (const UWORD8 *)&ps_codec->s_parse.s_cabac.au1_ctxt_models_sync); |
2937 | | |
2938 | 7.20k | if(ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS) |
2939 | 10 | { |
2940 | 10 | ps_codec->i4_slice_error = 1; |
2941 | 10 | end_of_slice_flag = 1; |
2942 | 10 | ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
2943 | 10 | } |
2944 | 7.20k | } |
2945 | 9.24k | } |
2946 | 170k | } |
2947 | | |
2948 | | |
2949 | | |
2950 | 2.61M | if(0 == ps_codec->i4_slice_error) |
2951 | 547k | { |
2952 | 547k | if(ps_slice_hdr->i1_slice_sao_luma_flag || ps_slice_hdr->i1_slice_sao_chroma_flag) |
2953 | 325k | ihevcd_parse_sao(ps_codec); |
2954 | 547k | } |
2955 | 2.06M | else |
2956 | 2.06M | { |
2957 | 2.06M | sao_t *ps_sao = ps_codec->s_parse.ps_pic_sao + |
2958 | 2.06M | ps_codec->s_parse.i4_ctb_x + |
2959 | 2.06M | ps_codec->s_parse.i4_ctb_y * ps_sps->i2_pic_wd_in_ctb; |
2960 | | |
2961 | | /* Default values */ |
2962 | 2.06M | ps_sao->b3_y_type_idx = 0; |
2963 | 2.06M | ps_sao->b3_cb_type_idx = 0; |
2964 | 2.06M | ps_sao->b3_cr_type_idx = 0; |
2965 | 2.06M | } |
2966 | | |
2967 | | //AEV_TRACE("CTB x", ps_codec->s_parse.i4_ctb_x, 0); |
2968 | | //AEV_TRACE("CTB y", ps_codec->s_parse.i4_ctb_y, 0); |
2969 | | |
2970 | 2.61M | { |
2971 | 2.61M | WORD32 ctb_indx; |
2972 | 2.61M | ctb_indx = ps_codec->s_parse.i4_ctb_x + ps_sps->i2_pic_wd_in_ctb * ps_codec->s_parse.i4_ctb_y; |
2973 | 2.61M | ps_codec->s_parse.s_bs_ctxt.pu1_pic_qp_const_in_ctb[ctb_indx >> 3] |= (1 << (ctb_indx & 7)); |
2974 | 2.61M | { |
2975 | 2.61M | UWORD16 *pu1_slice_idx = ps_codec->s_parse.pu1_slice_idx; |
2976 | 2.61M | pu1_slice_idx[ctb_indx] = ps_codec->s_parse.i4_cur_independent_slice_idx; |
2977 | 2.61M | } |
2978 | 2.61M | } |
2979 | | |
2980 | 2.61M | if(0 == ps_codec->i4_slice_error) |
2981 | 547k | { |
2982 | 547k | tu_t *ps_tu = ps_codec->s_parse.ps_tu; |
2983 | 547k | WORD32 i4_tu_cnt = ps_codec->s_parse.s_cu.i4_tu_cnt; |
2984 | 547k | WORD32 i4_pic_tu_idx = ps_codec->s_parse.i4_pic_tu_idx; |
2985 | | |
2986 | 547k | pu_t *ps_pu = ps_codec->s_parse.ps_pu; |
2987 | 547k | WORD32 i4_pic_pu_idx = ps_codec->s_parse.i4_pic_pu_idx; |
2988 | | |
2989 | 547k | UWORD8 *pu1_tu_coeff_data = (UWORD8 *)ps_codec->s_parse.pv_tu_coeff_data; |
2990 | | |
2991 | 547k | ret = ihevcd_parse_coding_quadtree(ps_codec, |
2992 | 547k | (ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size), |
2993 | 547k | (ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size), |
2994 | 547k | ps_sps->i1_log2_ctb_size, |
2995 | 547k | 0); |
2996 | | /* Check for error */ |
2997 | 547k | if (ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS) |
2998 | 29 | { |
2999 | | /* Reset tu and pu parameters, and signal current ctb as skip */ |
3000 | 29 | WORD32 tu_coeff_data_reset_size; |
3001 | | |
3002 | 29 | ps_codec->s_parse.ps_tu = ps_tu; |
3003 | 29 | ps_codec->s_parse.s_cu.i4_tu_cnt = i4_tu_cnt; |
3004 | 29 | ps_codec->s_parse.i4_pic_tu_idx = i4_pic_tu_idx; |
3005 | | |
3006 | 29 | ps_codec->s_parse.ps_pu = ps_pu; |
3007 | 29 | ps_codec->s_parse.i4_pic_pu_idx = i4_pic_pu_idx; |
3008 | | |
3009 | 29 | tu_coeff_data_reset_size = (UWORD8 *)ps_codec->s_parse.pv_tu_coeff_data - pu1_tu_coeff_data; |
3010 | 29 | memset(pu1_tu_coeff_data, 0, tu_coeff_data_reset_size); |
3011 | 29 | ps_codec->s_parse.pv_tu_coeff_data = (void *)pu1_tu_coeff_data; |
3012 | | |
3013 | 29 | ihevcd_set_ctb_skip(ps_codec); |
3014 | | |
3015 | | /* Set slice error to suppress further parsing and |
3016 | | * signal end of slice. |
3017 | | */ |
3018 | 29 | ps_codec->i4_slice_error = 1; |
3019 | 29 | end_of_slice_flag = 1; |
3020 | 29 | ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
3021 | 29 | } |
3022 | 547k | } |
3023 | 2.06M | else |
3024 | 2.06M | { |
3025 | 2.06M | ihevcd_set_ctb_skip(ps_codec); |
3026 | 2.06M | } |
3027 | | |
3028 | 2.61M | if(0 == ps_codec->i4_slice_error) |
3029 | 547k | end_of_slice_flag = ihevcd_cabac_decode_terminate(&ps_codec->s_parse.s_cabac, &ps_codec->s_parse.s_bitstrm); |
3030 | | |
3031 | 2.61M | AEV_TRACE("end_of_slice_flag", end_of_slice_flag, ps_codec->s_parse.s_cabac.u4_range); |
3032 | | |
3033 | | |
3034 | | /* In case of tiles or entropy sync, terminate cabac and copy cabac context backed up at the end of top-right CTB */ |
3035 | 2.61M | if(ps_pps->i1_tiles_enabled_flag || ps_pps->i1_entropy_coding_sync_enabled_flag) |
3036 | 710k | { |
3037 | 710k | WORD32 end_of_tile = 0; |
3038 | 710k | WORD32 end_of_tile_row = 0; |
3039 | | |
3040 | | /* Take a back up of cabac context models if entropy sync is enabled */ |
3041 | 710k | if(ps_pps->i1_entropy_coding_sync_enabled_flag || ps_pps->i1_tiles_enabled_flag) |
3042 | 710k | { |
3043 | 710k | if(1 == ps_codec->s_parse.i4_ctb_x) |
3044 | 34.2k | { |
3045 | 34.2k | WORD32 size = sizeof(ps_codec->s_parse.s_cabac.au1_ctxt_models); |
3046 | 34.2k | memcpy(&ps_codec->s_parse.s_cabac.au1_ctxt_models_sync, &ps_codec->s_parse.s_cabac.au1_ctxt_models, size); |
3047 | 34.2k | } |
3048 | 710k | } |
3049 | | |
3050 | | /* Since tiles and entropy sync are not enabled simultaneously, the following will not result in any problems */ |
3051 | 710k | if((ps_codec->s_parse.i4_ctb_tile_x + 1) == (ps_tile->u2_wd)) |
3052 | 78.8k | { |
3053 | 78.8k | end_of_tile_row = 1; |
3054 | 78.8k | if((ps_codec->s_parse.i4_ctb_tile_y + 1) == ps_tile->u2_ht) |
3055 | 21.9k | end_of_tile = 1; |
3056 | 78.8k | } |
3057 | 710k | if((0 == end_of_slice_flag) && (0 == ps_codec->i4_slice_error) && |
3058 | 307k | ((ps_pps->i1_tiles_enabled_flag && end_of_tile) || |
3059 | 299k | (ps_pps->i1_entropy_coding_sync_enabled_flag && end_of_tile_row))) |
3060 | 16.8k | { |
3061 | 16.8k | WORD32 end_of_sub_stream_one_bit; |
3062 | 16.8k | end_of_sub_stream_one_bit = ihevcd_cabac_decode_terminate(&ps_codec->s_parse.s_cabac, &ps_codec->s_parse.s_bitstrm); |
3063 | 16.8k | AEV_TRACE("end_of_sub_stream_one_bit", end_of_sub_stream_one_bit, ps_codec->s_parse.s_cabac.u4_range); |
3064 | | |
3065 | | /* TODO: Remove the check for offset when HM is updated to include a byte unconditionally even for aligned location */ |
3066 | | /* For Ittiam streams this check should not be there, for HM9.1 streams this should be there */ |
3067 | 16.8k | if(ps_codec->s_parse.s_bitstrm.u4_bit_ofst % 8) |
3068 | 14.3k | ihevcd_bits_flush_to_byte_boundary(&ps_codec->s_parse.s_bitstrm); |
3069 | | |
3070 | 16.8k | UNUSED(end_of_sub_stream_one_bit); |
3071 | 16.8k | } |
3072 | 710k | } |
3073 | 2.61M | { |
3074 | 2.61M | WORD32 ctb_indx; |
3075 | | |
3076 | 2.61M | ctb_addr = ps_codec->s_parse.i4_ctb_y * num_ctb_in_row + ps_codec->s_parse.i4_ctb_x; |
3077 | | |
3078 | 2.61M | ctb_indx = ++ctb_addr; |
3079 | | |
3080 | | /* Store pu_idx for next CTB in frame level pu_idx array */ |
3081 | | |
3082 | | //In case of multiple tiles, if end-of-tile row is reached |
3083 | 2.61M | if((ps_tile->u2_wd == (ps_codec->s_parse.i4_ctb_tile_x + 1)) && (ps_tile->u2_wd != ps_sps->i2_pic_wd_in_ctb)) |
3084 | 69.9k | { |
3085 | 69.9k | ctb_indx = (ps_sps->i2_pic_wd_in_ctb * (ps_codec->s_parse.i4_ctb_tile_y + 1 + ps_tile->u1_pos_y)) + ps_tile->u1_pos_x; //idx is the beginning of next row in current tile. |
3086 | 69.9k | if(ps_tile->u2_ht == (ps_codec->s_parse.i4_ctb_tile_y + 1)) |
3087 | 19.7k | { |
3088 | | //If the current ctb is the last tile's last ctb |
3089 | 19.7k | if((ps_tile->u2_wd + ps_tile->u1_pos_x == ps_sps->i2_pic_wd_in_ctb) && ((ps_tile->u2_ht + ps_tile->u1_pos_y == ps_sps->i2_pic_ht_in_ctb))) |
3090 | 2.52k | { |
3091 | 2.52k | ctb_indx = ctb_addr; //Next continuous ctb address |
3092 | 2.52k | } |
3093 | 17.2k | else //Not last tile's end , but a tile end |
3094 | 17.2k | { |
3095 | 17.2k | tile_t *ps_next_tile = ps_codec->s_parse.ps_tile + 1; |
3096 | 17.2k | ctb_indx = ps_next_tile->u1_pos_x + (ps_next_tile->u1_pos_y * ps_sps->i2_pic_wd_in_ctb); //idx is the beginning of first row in next tile. |
3097 | 17.2k | } |
3098 | 19.7k | } |
3099 | 69.9k | } |
3100 | | |
3101 | 2.61M | ps_codec->s_parse.pu4_pic_pu_idx[ctb_indx] = ps_codec->s_parse.i4_pic_pu_idx; |
3102 | 2.61M | ps_codec->s_parse.i4_next_pu_ctb_cnt = ctb_indx; |
3103 | | |
3104 | 2.61M | ps_codec->s_parse.pu1_pu_map += num_min4x4_in_ctb; |
3105 | | |
3106 | | /* Store tu_idx for next CTB in frame level tu_idx array */ |
3107 | 2.61M | if(1 == ps_codec->i4_num_cores) |
3108 | 2.12M | { |
3109 | 2.12M | ctb_indx = (0 == ctb_addr % RESET_TU_BUF_NCTB) ? |
3110 | 2.12M | RESET_TU_BUF_NCTB : ctb_addr % RESET_TU_BUF_NCTB; |
3111 | | |
3112 | | //In case of multiple tiles, if end-of-tile row is reached |
3113 | 2.12M | if((ps_tile->u2_wd == (ps_codec->s_parse.i4_ctb_tile_x + 1)) && (ps_tile->u2_wd != ps_sps->i2_pic_wd_in_ctb)) |
3114 | 60.2k | { |
3115 | 60.2k | ctb_indx = (ps_sps->i2_pic_wd_in_ctb * (ps_codec->s_parse.i4_ctb_tile_y + 1 + ps_tile->u1_pos_y)) + ps_tile->u1_pos_x; //idx is the beginning of next row in current tile. |
3116 | 60.2k | if(ps_tile->u2_ht == (ps_codec->s_parse.i4_ctb_tile_y + 1)) |
3117 | 14.9k | { |
3118 | | //If the current ctb is the last tile's last ctb |
3119 | 14.9k | if((ps_tile->u2_wd + ps_tile->u1_pos_x == ps_sps->i2_pic_wd_in_ctb) && ((ps_tile->u2_ht + ps_tile->u1_pos_y == ps_sps->i2_pic_ht_in_ctb))) |
3120 | 1.92k | { |
3121 | 1.92k | ctb_indx = (0 == ctb_addr % RESET_TU_BUF_NCTB) ? |
3122 | 1.92k | RESET_TU_BUF_NCTB : ctb_addr % RESET_TU_BUF_NCTB; |
3123 | 1.92k | } |
3124 | 13.0k | else //Not last tile's end , but a tile end |
3125 | 13.0k | { |
3126 | 13.0k | tile_t *ps_next_tile = ps_codec->s_parse.ps_tile + 1; |
3127 | 13.0k | ctb_indx = ps_next_tile->u1_pos_x + (ps_next_tile->u1_pos_y * ps_sps->i2_pic_wd_in_ctb); //idx is the beginning of first row in next tile. |
3128 | 13.0k | } |
3129 | 14.9k | } |
3130 | 60.2k | } |
3131 | 2.12M | ps_codec->s_parse.i4_next_tu_ctb_cnt = ctb_indx; |
3132 | 2.12M | ps_codec->s_parse.pu4_pic_tu_idx[ctb_indx] = ps_codec->s_parse.i4_pic_tu_idx; |
3133 | 2.12M | } |
3134 | 488k | else |
3135 | 488k | { |
3136 | 488k | ctb_indx = ctb_addr; |
3137 | 488k | if((ps_tile->u2_wd == (ps_codec->s_parse.i4_ctb_tile_x + 1)) && (ps_tile->u2_wd != ps_sps->i2_pic_wd_in_ctb)) |
3138 | 9.65k | { |
3139 | 9.65k | ctb_indx = (ps_sps->i2_pic_wd_in_ctb * (ps_codec->s_parse.i4_ctb_tile_y + 1 + ps_tile->u1_pos_y)) + ps_tile->u1_pos_x; //idx is the beginning of next row in current tile. |
3140 | 9.65k | if(ps_tile->u2_ht == (ps_codec->s_parse.i4_ctb_tile_y + 1)) |
3141 | 4.74k | { |
3142 | | //If the current ctb is the last tile's last ctb |
3143 | 4.74k | if((ps_tile->u2_wd + ps_tile->u1_pos_x == ps_sps->i2_pic_wd_in_ctb) && ((ps_tile->u2_ht + ps_tile->u1_pos_y == ps_sps->i2_pic_ht_in_ctb))) |
3144 | 599 | { |
3145 | 599 | ctb_indx = ctb_addr; |
3146 | 599 | } |
3147 | 4.14k | else //Not last tile's end , but a tile end |
3148 | 4.14k | { |
3149 | 4.14k | tile_t *ps_next_tile = ps_codec->s_parse.ps_tile + 1; |
3150 | 4.14k | ctb_indx = ps_next_tile->u1_pos_x + (ps_next_tile->u1_pos_y * ps_sps->i2_pic_wd_in_ctb); //idx is the beginning of first row in next tile. |
3151 | 4.14k | } |
3152 | 4.74k | } |
3153 | 9.65k | } |
3154 | 488k | ps_codec->s_parse.i4_next_tu_ctb_cnt = ctb_indx; |
3155 | 488k | ps_codec->s_parse.pu4_pic_tu_idx[ctb_indx] = ps_codec->s_parse.i4_pic_tu_idx; |
3156 | 488k | } |
3157 | 2.61M | ps_codec->s_parse.pu1_tu_map += num_min4x4_in_ctb; |
3158 | 2.61M | } |
3159 | | |
3160 | | /* QP array population has to be done if deblocking is enabled in the picture |
3161 | | * but some of the slices in the pic have it disabled */ |
3162 | 2.61M | if((0 != ps_codec->i4_disable_deblk_pic) && |
3163 | 0 | (1 == ps_slice_hdr->i1_slice_disable_deblocking_filter_flag)) |
3164 | 0 | { |
3165 | 0 | bs_ctxt_t *ps_bs_ctxt = &ps_codec->s_parse.s_bs_ctxt; |
3166 | 0 | WORD32 log2_ctb_size = ps_sps->i1_log2_ctb_size; |
3167 | 0 | UWORD8 *pu1_qp; |
3168 | 0 | WORD32 qp_strd; |
3169 | 0 | WORD32 u4_qp_const_in_ctb; |
3170 | 0 | WORD32 cur_ctb_idx; |
3171 | 0 | WORD32 next_ctb_idx; |
3172 | 0 | WORD32 cur_tu_idx; |
3173 | 0 | WORD32 i4_ctb_tu_cnt; |
3174 | 0 | tu_t *ps_tu; |
3175 | |
|
3176 | 0 | cur_ctb_idx = ps_codec->s_parse.i4_ctb_x + ps_sps->i2_pic_wd_in_ctb * ps_codec->s_parse.i4_ctb_y; |
3177 | | /* ctb_size/8 elements per CTB */ |
3178 | 0 | qp_strd = ps_sps->i2_pic_wd_in_ctb << (log2_ctb_size - 3); |
3179 | 0 | pu1_qp = ps_bs_ctxt->pu1_pic_qp + ((ps_codec->s_parse.i4_ctb_x + ps_codec->s_parse.i4_ctb_y * qp_strd) << (log2_ctb_size - 3)); |
3180 | |
|
3181 | 0 | u4_qp_const_in_ctb = ps_bs_ctxt->pu1_pic_qp_const_in_ctb[cur_ctb_idx >> 3] & (1 << (cur_ctb_idx & 7)); |
3182 | |
|
3183 | 0 | next_ctb_idx = ps_codec->s_parse.i4_next_tu_ctb_cnt; |
3184 | 0 | if(1 == ps_codec->i4_num_cores) |
3185 | 0 | { |
3186 | 0 | i4_ctb_tu_cnt = ps_codec->s_parse.pu4_pic_tu_idx[next_ctb_idx] - |
3187 | 0 | ps_codec->s_parse.pu4_pic_tu_idx[cur_ctb_idx % RESET_TU_BUF_NCTB]; |
3188 | |
|
3189 | 0 | cur_tu_idx = ps_codec->s_parse.pu4_pic_tu_idx[cur_ctb_idx % RESET_TU_BUF_NCTB]; |
3190 | 0 | } |
3191 | 0 | else |
3192 | 0 | { |
3193 | 0 | i4_ctb_tu_cnt = ps_codec->s_parse.pu4_pic_tu_idx[next_ctb_idx] - |
3194 | 0 | ps_codec->s_parse.pu4_pic_tu_idx[cur_ctb_idx]; |
3195 | |
|
3196 | 0 | cur_tu_idx = ps_codec->s_parse.pu4_pic_tu_idx[cur_ctb_idx]; |
3197 | 0 | } |
3198 | |
|
3199 | 0 | ps_tu = &ps_codec->s_parse.ps_pic_tu[cur_tu_idx]; |
3200 | |
|
3201 | 0 | if(u4_qp_const_in_ctb) |
3202 | 0 | { |
3203 | 0 | pu1_qp[0] = ps_tu->b7_qp; |
3204 | 0 | } |
3205 | 0 | else |
3206 | 0 | { |
3207 | 0 | for(i = 0; i < i4_ctb_tu_cnt; i++, ps_tu++) |
3208 | 0 | { |
3209 | 0 | WORD32 start_pos_x; |
3210 | 0 | WORD32 start_pos_y; |
3211 | 0 | WORD32 tu_size; |
3212 | | |
3213 | | /* start_pos_x and start_pos_y are in units of min TU size (4x4) */ |
3214 | 0 | start_pos_x = ps_tu->b4_pos_x; |
3215 | 0 | start_pos_y = ps_tu->b4_pos_y; |
3216 | |
|
3217 | 0 | tu_size = 1 << (ps_tu->b3_size + 2); |
3218 | 0 | tu_size >>= 2; /* TU size divided by 4 */ |
3219 | |
|
3220 | 0 | if(0 == (start_pos_x & 1) && 0 == (start_pos_y & 1)) |
3221 | 0 | { |
3222 | 0 | WORD32 row, col; |
3223 | 0 | for(row = start_pos_y; row < start_pos_y + tu_size; row += 2) |
3224 | 0 | { |
3225 | 0 | for(col = start_pos_x; col < start_pos_x + tu_size; col += 2) |
3226 | 0 | { |
3227 | 0 | pu1_qp[(row >> 1) * qp_strd + (col >> 1)] = ps_tu->b7_qp; |
3228 | 0 | } |
3229 | 0 | } |
3230 | 0 | } |
3231 | 0 | } |
3232 | 0 | } |
3233 | 0 | } |
3234 | | |
3235 | 2.61M | if(ps_codec->i4_num_cores <= MV_PRED_NUM_CORES_THRESHOLD) |
3236 | 2.20M | { |
3237 | | /*************************************************/ |
3238 | | /**************** MV pred **********************/ |
3239 | | /*************************************************/ |
3240 | 2.20M | WORD8 u1_top_ctb_avail = 1; |
3241 | 2.20M | WORD8 u1_left_ctb_avail = 1; |
3242 | 2.20M | WORD8 u1_top_lt_ctb_avail = 1; |
3243 | 2.20M | WORD8 u1_top_rt_ctb_avail = 1; |
3244 | 2.20M | WORD16 i2_wd_in_ctb; |
3245 | | |
3246 | 2.20M | tile_start_ctb_idx = ps_tile->u1_pos_x |
3247 | 2.20M | + ps_tile->u1_pos_y * (ps_sps->i2_pic_wd_in_ctb); |
3248 | | |
3249 | 2.20M | slice_start_ctb_idx = ps_slice_hdr->i2_ctb_x |
3250 | 2.20M | + ps_slice_hdr->i2_ctb_y * (ps_sps->i2_pic_wd_in_ctb); |
3251 | | |
3252 | 2.20M | if((slice_start_ctb_idx < tile_start_ctb_idx)) |
3253 | 413k | { |
3254 | | //Slices span across multiple tiles. |
3255 | 413k | i2_wd_in_ctb = ps_sps->i2_pic_wd_in_ctb; |
3256 | 413k | } |
3257 | 1.79M | else |
3258 | 1.79M | { |
3259 | 1.79M | i2_wd_in_ctb = ps_tile->u2_wd; |
3260 | 1.79M | } |
3261 | | /* slice and tile boundaries */ |
3262 | 2.20M | if((0 == ps_codec->s_parse.i4_ctb_y) || (0 == ps_codec->s_parse.i4_ctb_tile_y)) |
3263 | 184k | { |
3264 | 184k | u1_top_ctb_avail = 0; |
3265 | 184k | u1_top_lt_ctb_avail = 0; |
3266 | 184k | u1_top_rt_ctb_avail = 0; |
3267 | 184k | } |
3268 | | |
3269 | 2.20M | if((0 == ps_codec->s_parse.i4_ctb_x) || (0 == ps_codec->s_parse.i4_ctb_tile_x)) |
3270 | 156k | { |
3271 | 156k | u1_left_ctb_avail = 0; |
3272 | 156k | u1_top_lt_ctb_avail = 0; |
3273 | 156k | if((0 == ps_codec->s_parse.i4_ctb_slice_y) || (0 == ps_codec->s_parse.i4_ctb_tile_y)) |
3274 | 25.4k | { |
3275 | 25.4k | u1_top_ctb_avail = 0; |
3276 | 25.4k | if((i2_wd_in_ctb - 1) != ps_codec->s_parse.i4_ctb_slice_x) //TODO: For tile, not implemented |
3277 | 24.3k | { |
3278 | 24.3k | u1_top_rt_ctb_avail = 0; |
3279 | 24.3k | } |
3280 | 25.4k | } |
3281 | 156k | } |
3282 | | /*For slices not beginning at start of a ctb row*/ |
3283 | 2.04M | else if(ps_codec->s_parse.i4_ctb_x > 0) |
3284 | 2.04M | { |
3285 | 2.04M | if((0 == ps_codec->s_parse.i4_ctb_slice_y) || (0 == ps_codec->s_parse.i4_ctb_tile_y)) |
3286 | 533k | { |
3287 | 533k | u1_top_ctb_avail = 0; |
3288 | 533k | u1_top_lt_ctb_avail = 0; |
3289 | 533k | if(0 == ps_codec->s_parse.i4_ctb_slice_x) |
3290 | 4.41k | { |
3291 | 4.41k | u1_left_ctb_avail = 0; |
3292 | 4.41k | } |
3293 | 533k | if((i2_wd_in_ctb - 1) != ps_codec->s_parse.i4_ctb_slice_x) |
3294 | 521k | { |
3295 | 521k | u1_top_rt_ctb_avail = 0; |
3296 | 521k | } |
3297 | 533k | } |
3298 | 1.51M | else if((1 == ps_codec->s_parse.i4_ctb_slice_y) && (0 == ps_codec->s_parse.i4_ctb_slice_x)) |
3299 | 169 | { |
3300 | 169 | u1_top_lt_ctb_avail = 0; |
3301 | 169 | } |
3302 | 2.04M | } |
3303 | | |
3304 | 2.20M | if(((ps_sps->i2_pic_wd_in_ctb - 1) == ps_codec->s_parse.i4_ctb_x) || ((ps_tile->u2_wd - 1) == ps_codec->s_parse.i4_ctb_tile_x)) |
3305 | 156k | { |
3306 | 156k | u1_top_rt_ctb_avail = 0; |
3307 | 156k | } |
3308 | | |
3309 | 2.20M | if(PSLICE == ps_slice_hdr->i1_slice_type |
3310 | 2.19M | || BSLICE == ps_slice_hdr->i1_slice_type) |
3311 | 714k | { |
3312 | 714k | mv_ctxt_t s_mv_ctxt; |
3313 | 714k | process_ctxt_t *ps_proc; |
3314 | 714k | UWORD32 *pu4_ctb_top_pu_idx; |
3315 | 714k | UWORD32 *pu4_ctb_left_pu_idx; |
3316 | 714k | UWORD32 *pu4_ctb_top_left_pu_idx; |
3317 | 714k | WORD32 i4_ctb_pu_cnt; |
3318 | 714k | WORD32 cur_ctb_idx; |
3319 | 714k | WORD32 next_ctb_idx; |
3320 | 714k | WORD32 cur_pu_idx; |
3321 | 714k | ps_proc = &ps_codec->as_process[(ps_codec->i4_num_cores == 1) ? 1 : (ps_codec->i4_num_cores - 1)]; |
3322 | 714k | cur_ctb_idx = ps_codec->s_parse.i4_ctb_x |
3323 | 714k | + ps_codec->s_parse.i4_ctb_y * (ps_sps->i2_pic_wd_in_ctb); |
3324 | 714k | next_ctb_idx = ps_codec->s_parse.i4_next_pu_ctb_cnt; |
3325 | 714k | i4_ctb_pu_cnt = ps_codec->s_parse.pu4_pic_pu_idx[next_ctb_idx] |
3326 | 714k | - ps_codec->s_parse.pu4_pic_pu_idx[cur_ctb_idx]; |
3327 | | |
3328 | 714k | cur_pu_idx = ps_codec->s_parse.pu4_pic_pu_idx[cur_ctb_idx]; |
3329 | | |
3330 | 714k | pu4_ctb_top_pu_idx = ps_proc->pu4_pic_pu_idx_top |
3331 | 714k | + (ps_codec->s_parse.i4_ctb_x * ctb_size / MIN_PU_SIZE); |
3332 | 714k | pu4_ctb_left_pu_idx = ps_proc->pu4_pic_pu_idx_left; |
3333 | 714k | pu4_ctb_top_left_pu_idx = &ps_proc->u4_ctb_top_left_pu_idx; |
3334 | | |
3335 | | /* Initializing s_mv_ctxt */ |
3336 | 714k | { |
3337 | 714k | s_mv_ctxt.ps_pps = ps_pps; |
3338 | 714k | s_mv_ctxt.ps_sps = ps_sps; |
3339 | 714k | s_mv_ctxt.ps_slice_hdr = ps_slice_hdr; |
3340 | 714k | s_mv_ctxt.i4_ctb_x = ps_codec->s_parse.i4_ctb_x; |
3341 | 714k | s_mv_ctxt.i4_ctb_y = ps_codec->s_parse.i4_ctb_y; |
3342 | 714k | s_mv_ctxt.ps_pu = &ps_codec->s_parse.ps_pic_pu[cur_pu_idx]; |
3343 | 714k | s_mv_ctxt.ps_pic_pu = ps_codec->s_parse.ps_pic_pu; |
3344 | 714k | s_mv_ctxt.ps_tile = ps_tile; |
3345 | 714k | s_mv_ctxt.pu4_pic_pu_idx_map = ps_proc->pu4_pic_pu_idx_map; |
3346 | 714k | s_mv_ctxt.pu4_pic_pu_idx = ps_codec->s_parse.pu4_pic_pu_idx; |
3347 | 714k | s_mv_ctxt.pu1_pic_pu_map = ps_codec->s_parse.pu1_pic_pu_map; |
3348 | 714k | s_mv_ctxt.i4_ctb_pu_cnt = i4_ctb_pu_cnt; |
3349 | 714k | s_mv_ctxt.i4_ctb_start_pu_idx = cur_pu_idx; |
3350 | 714k | s_mv_ctxt.u1_top_ctb_avail = u1_top_ctb_avail; |
3351 | 714k | s_mv_ctxt.u1_top_rt_ctb_avail = u1_top_rt_ctb_avail; |
3352 | 714k | s_mv_ctxt.u1_top_lt_ctb_avail = u1_top_lt_ctb_avail; |
3353 | 714k | s_mv_ctxt.u1_left_ctb_avail = u1_left_ctb_avail; |
3354 | 714k | } |
3355 | | |
3356 | 714k | ihevcd_get_mv_ctb(&s_mv_ctxt, pu4_ctb_top_pu_idx, |
3357 | 714k | pu4_ctb_left_pu_idx, pu4_ctb_top_left_pu_idx); |
3358 | | |
3359 | 714k | } |
3360 | 1.48M | else |
3361 | 1.48M | { |
3362 | 1.48M | WORD32 num_minpu_in_ctb = (ctb_size / MIN_PU_SIZE) * (ctb_size / MIN_PU_SIZE); |
3363 | 1.48M | UWORD8 *pu1_pic_pu_map_ctb = ps_codec->s_parse.pu1_pic_pu_map + |
3364 | 1.48M | (ps_codec->s_parse.i4_ctb_x + ps_codec->s_parse.i4_ctb_y * ps_sps->i2_pic_wd_in_ctb) * num_minpu_in_ctb; |
3365 | 1.48M | process_ctxt_t *ps_proc = &ps_codec->as_process[(ps_codec->i4_num_cores == 1) ? 1 : (ps_codec->i4_num_cores - 1)]; |
3366 | 1.48M | WORD32 row, col; |
3367 | 1.48M | WORD32 pu_cnt; |
3368 | 1.48M | WORD32 num_pu_per_ctb; |
3369 | 1.48M | WORD32 cur_ctb_idx; |
3370 | 1.48M | WORD32 next_ctb_idx; |
3371 | 1.48M | WORD32 ctb_start_pu_idx; |
3372 | 1.48M | UWORD32 *pu4_nbr_pu_idx = ps_proc->pu4_pic_pu_idx_map; |
3373 | 1.48M | WORD32 nbr_pu_idx_strd = MAX_CTB_SIZE / MIN_PU_SIZE + 2; |
3374 | 1.48M | pu_t *ps_pu; |
3375 | 1.48M | WORD32 ctb_size_in_min_pu = (ctb_size / MIN_PU_SIZE); |
3376 | | |
3377 | | /* Neighbor PU idx update inside CTB */ |
3378 | | /* 1byte per 4x4. Indicates the PU idx that 4x4 block belongs to */ |
3379 | | |
3380 | 1.48M | cur_ctb_idx = ps_codec->s_parse.i4_ctb_x |
3381 | 1.48M | + ps_codec->s_parse.i4_ctb_y * (ps_sps->i2_pic_wd_in_ctb); |
3382 | 1.48M | next_ctb_idx = ps_codec->s_parse.i4_next_pu_ctb_cnt; |
3383 | 1.48M | num_pu_per_ctb = ps_codec->s_parse.pu4_pic_pu_idx[next_ctb_idx] |
3384 | 1.48M | - ps_codec->s_parse.pu4_pic_pu_idx[cur_ctb_idx]; |
3385 | 1.48M | ctb_start_pu_idx = ps_codec->s_parse.pu4_pic_pu_idx[cur_ctb_idx]; |
3386 | 1.48M | ps_pu = &ps_codec->s_parse.ps_pic_pu[ctb_start_pu_idx]; |
3387 | | |
3388 | 18.2M | for(pu_cnt = 0; pu_cnt < num_pu_per_ctb; pu_cnt++, ps_pu++) |
3389 | 16.8M | { |
3390 | 16.8M | UWORD32 cur_pu_idx; |
3391 | 16.8M | WORD32 pu_ht = (ps_pu->b4_ht + 1) << 2; |
3392 | 16.8M | WORD32 pu_wd = (ps_pu->b4_wd + 1) << 2; |
3393 | | |
3394 | 16.8M | cur_pu_idx = ctb_start_pu_idx + pu_cnt; |
3395 | | |
3396 | 51.0M | for(row = 0; row < pu_ht / MIN_PU_SIZE; row++) |
3397 | 108M | for(col = 0; col < pu_wd / MIN_PU_SIZE; col++) |
3398 | 74.2M | pu4_nbr_pu_idx[(1 + ps_pu->b4_pos_x + col) |
3399 | 74.2M | + (1 + ps_pu->b4_pos_y + row) |
3400 | 74.2M | * nbr_pu_idx_strd] = |
3401 | 74.2M | cur_pu_idx; |
3402 | 16.8M | } |
3403 | | |
3404 | | /* Updating Top and Left pointers */ |
3405 | 1.48M | { |
3406 | 1.48M | WORD32 rows_remaining = ps_sps->i2_pic_height_in_luma_samples |
3407 | 1.48M | - (ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size); |
3408 | 1.48M | WORD32 ctb_size_left = MIN(ctb_size, rows_remaining); |
3409 | | |
3410 | | /* Top Left */ |
3411 | | /* saving top left before updating top ptr, as updating top ptr will overwrite the top left for the next ctb */ |
3412 | 1.48M | ps_proc->u4_ctb_top_left_pu_idx = ps_proc->pu4_pic_pu_idx_top[(ps_codec->s_parse.i4_ctb_x * ctb_size / MIN_PU_SIZE) + ctb_size / MIN_PU_SIZE - 1]; |
3413 | 10.2M | for(i = 0; i < ctb_size / MIN_PU_SIZE; i++) |
3414 | 8.75M | { |
3415 | | /* Left */ |
3416 | | /* Last column of au4_nbr_pu_idx */ |
3417 | 8.75M | ps_proc->pu4_pic_pu_idx_left[i] = pu4_nbr_pu_idx[(ctb_size / MIN_PU_SIZE) |
3418 | 8.75M | + (i + 1) * nbr_pu_idx_strd]; |
3419 | | /* Top */ |
3420 | | /* Last row of au4_nbr_pu_idx */ |
3421 | 8.75M | ps_proc->pu4_pic_pu_idx_top[(ps_codec->s_parse.i4_ctb_x * ctb_size / MIN_PU_SIZE) + i] = |
3422 | 8.75M | pu4_nbr_pu_idx[(ctb_size_left / MIN_PU_SIZE) * nbr_pu_idx_strd + i + 1]; |
3423 | | |
3424 | 8.75M | } |
3425 | 1.48M | } |
3426 | | |
3427 | | /* Updating the CTB level PU idx (Used for collocated MV pred)*/ |
3428 | 1.48M | { |
3429 | 1.48M | WORD32 ctb_row, ctb_col, index_pic_map, index_nbr_map; |
3430 | 1.48M | WORD32 first_pu_of_ctb; |
3431 | 1.48M | first_pu_of_ctb = pu4_nbr_pu_idx[1 + nbr_pu_idx_strd]; |
3432 | 1.48M | UWORD32 cur_ctb_ht_in_min_pu = MIN(((ps_sps->i2_pic_height_in_luma_samples |
3433 | 1.48M | - (ps_codec->s_parse.i4_ctb_y << ps_sps->i1_log2_ctb_size)) / MIN_PU_SIZE), ctb_size_in_min_pu); |
3434 | 1.48M | UWORD32 cur_ctb_wd_in_min_pu = MIN(((ps_sps->i2_pic_width_in_luma_samples |
3435 | 1.48M | - (ps_codec->s_parse.i4_ctb_x << ps_sps->i1_log2_ctb_size)) / MIN_PU_SIZE), ctb_size_in_min_pu); |
3436 | | |
3437 | 1.48M | index_pic_map = 0 * ctb_size_in_min_pu + 0; |
3438 | 1.48M | index_nbr_map = (0 + 1) * nbr_pu_idx_strd + (0 + 1); |
3439 | | |
3440 | 10.0M | for(ctb_row = 0; ctb_row < cur_ctb_ht_in_min_pu; ctb_row++) |
3441 | 8.55M | { |
3442 | 82.7M | for(ctb_col = 0; ctb_col < cur_ctb_wd_in_min_pu; ctb_col++) |
3443 | 74.2M | { |
3444 | 74.2M | pu1_pic_pu_map_ctb[index_pic_map + ctb_col] = pu4_nbr_pu_idx[index_nbr_map + ctb_col] |
3445 | 74.2M | - first_pu_of_ctb; |
3446 | 74.2M | } |
3447 | 8.55M | index_pic_map += ctb_size_in_min_pu; |
3448 | 8.55M | index_nbr_map += nbr_pu_idx_strd; |
3449 | 8.55M | } |
3450 | 1.48M | } |
3451 | 1.48M | } |
3452 | | |
3453 | | /*************************************************/ |
3454 | | /****************** BS, QP *********************/ |
3455 | | /*************************************************/ |
3456 | | /* Check if deblock is disabled for the current slice or if it is disabled for the current picture |
3457 | | * because of disable deblock api |
3458 | | */ |
3459 | 2.20M | if(0 == ps_codec->i4_disable_deblk_pic) |
3460 | 2.20M | { |
3461 | | /* Boundary strength calculation is done irrespective of whether deblocking is disabled |
3462 | | * in the slice or not, to handle deblocking slice boundaries */ |
3463 | 2.20M | if((0 == ps_codec->i4_slice_error)) |
3464 | 371k | { |
3465 | 371k | WORD32 i4_ctb_tu_cnt; |
3466 | 371k | WORD32 cur_ctb_idx, next_ctb_idx; |
3467 | 371k | WORD32 cur_pu_idx; |
3468 | 371k | WORD32 cur_tu_idx; |
3469 | 371k | process_ctxt_t *ps_proc; |
3470 | | |
3471 | 371k | ps_proc = &ps_codec->as_process[(ps_codec->i4_num_cores == 1) ? 1 : (ps_codec->i4_num_cores - 1)]; |
3472 | 371k | cur_ctb_idx = ps_codec->s_parse.i4_ctb_x |
3473 | 371k | + ps_codec->s_parse.i4_ctb_y * (ps_sps->i2_pic_wd_in_ctb); |
3474 | | |
3475 | 371k | cur_pu_idx = ps_codec->s_parse.pu4_pic_pu_idx[cur_ctb_idx]; |
3476 | 371k | next_ctb_idx = ps_codec->s_parse.i4_next_tu_ctb_cnt; |
3477 | 371k | if(1 == ps_codec->i4_num_cores) |
3478 | 316k | { |
3479 | 316k | i4_ctb_tu_cnt = ps_codec->s_parse.pu4_pic_tu_idx[next_ctb_idx] - |
3480 | 316k | ps_codec->s_parse.pu4_pic_tu_idx[cur_ctb_idx % RESET_TU_BUF_NCTB]; |
3481 | | |
3482 | 316k | cur_tu_idx = ps_codec->s_parse.pu4_pic_tu_idx[cur_ctb_idx % RESET_TU_BUF_NCTB]; |
3483 | 316k | } |
3484 | 54.7k | else |
3485 | 54.7k | { |
3486 | 54.7k | i4_ctb_tu_cnt = ps_codec->s_parse.pu4_pic_tu_idx[next_ctb_idx] - |
3487 | 54.7k | ps_codec->s_parse.pu4_pic_tu_idx[cur_ctb_idx]; |
3488 | | |
3489 | 54.7k | cur_tu_idx = ps_codec->s_parse.pu4_pic_tu_idx[cur_ctb_idx]; |
3490 | 54.7k | } |
3491 | | |
3492 | 371k | ps_codec->s_parse.s_bs_ctxt.ps_pps = ps_codec->s_parse.ps_pps; |
3493 | 371k | ps_codec->s_parse.s_bs_ctxt.ps_sps = ps_codec->s_parse.ps_sps; |
3494 | 371k | ps_codec->s_parse.s_bs_ctxt.ps_codec = ps_codec; |
3495 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_ctb_tu_cnt = i4_ctb_tu_cnt; |
3496 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_ctb_x = ps_codec->s_parse.i4_ctb_x; |
3497 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_ctb_y = ps_codec->s_parse.i4_ctb_y; |
3498 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_ctb_tile_x = ps_codec->s_parse.i4_ctb_tile_x; |
3499 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_ctb_tile_y = ps_codec->s_parse.i4_ctb_tile_y; |
3500 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_ctb_slice_x = ps_codec->s_parse.i4_ctb_slice_x; |
3501 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_ctb_slice_y = ps_codec->s_parse.i4_ctb_slice_y; |
3502 | 371k | ps_codec->s_parse.s_bs_ctxt.ps_tu = &ps_codec->s_parse.ps_pic_tu[cur_tu_idx]; |
3503 | 371k | ps_codec->s_parse.s_bs_ctxt.ps_pu = &ps_codec->s_parse.ps_pic_pu[cur_pu_idx]; |
3504 | 371k | ps_codec->s_parse.s_bs_ctxt.pu4_pic_pu_idx_map = ps_proc->pu4_pic_pu_idx_map; |
3505 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_next_pu_ctb_cnt = ps_codec->s_parse.i4_next_pu_ctb_cnt; |
3506 | 371k | ps_codec->s_parse.s_bs_ctxt.i4_next_tu_ctb_cnt = ps_codec->s_parse.i4_next_tu_ctb_cnt; |
3507 | 371k | ps_codec->s_parse.s_bs_ctxt.pu1_slice_idx = ps_codec->s_parse.pu1_slice_idx; |
3508 | 371k | ps_codec->s_parse.s_bs_ctxt.ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr; |
3509 | 371k | ps_codec->s_parse.s_bs_ctxt.ps_tile = ps_codec->s_parse.ps_tile; |
3510 | | |
3511 | 371k | if(ISLICE == ps_slice_hdr->i1_slice_type) |
3512 | 35.1k | { |
3513 | 35.1k | ihevcd_ctb_boundary_strength_islice(&ps_codec->s_parse.s_bs_ctxt); |
3514 | 35.1k | } |
3515 | 336k | else |
3516 | 336k | { |
3517 | 336k | ihevcd_ctb_boundary_strength_pbslice(&ps_codec->s_parse.s_bs_ctxt); |
3518 | 336k | } |
3519 | 371k | } |
3520 | | |
3521 | | /* Boundary strength is set to zero if deblocking is disabled for the current slice */ |
3522 | 2.20M | if(0 != ps_slice_hdr->i1_slice_disable_deblocking_filter_flag) |
3523 | 78.2k | { |
3524 | 78.2k | WORD32 bs_strd = (ps_sps->i2_pic_wd_in_ctb + 1) * (ctb_size * ctb_size / 8 / 16); |
3525 | | |
3526 | 78.2k | UWORD32 *pu4_vert_bs = (UWORD32 *)((UWORD8 *)ps_codec->s_parse.s_bs_ctxt.pu4_pic_vert_bs + |
3527 | 78.2k | ps_codec->s_parse.i4_ctb_x * (ctb_size * ctb_size / 8 / 16) + |
3528 | 78.2k | ps_codec->s_parse.i4_ctb_y * bs_strd); |
3529 | 78.2k | UWORD32 *pu4_horz_bs = (UWORD32 *)((UWORD8 *)ps_codec->s_parse.s_bs_ctxt.pu4_pic_horz_bs + |
3530 | 78.2k | ps_codec->s_parse.i4_ctb_x * (ctb_size * ctb_size / 8 / 16) + |
3531 | 78.2k | ps_codec->s_parse.i4_ctb_y * bs_strd); |
3532 | | |
3533 | 78.2k | memset(pu4_vert_bs, 0, (ctb_size / 8) * (ctb_size / 4) / 8 * 2); |
3534 | 78.2k | memset(pu4_horz_bs, 0, (ctb_size / 8) * (ctb_size / 4) / 8 * 2); |
3535 | 78.2k | } |
3536 | 2.20M | } |
3537 | | |
3538 | 2.20M | } |
3539 | | |
3540 | 2.61M | DATA_SYNC(); |
3541 | | |
3542 | | /* Update the parse status map */ |
3543 | 2.61M | { |
3544 | 2.61M | sps_t *ps_sps = ps_codec->s_parse.ps_sps; |
3545 | 2.61M | UWORD8 *pu1_buf; |
3546 | 2.61M | WORD32 idx; |
3547 | 2.61M | idx = (ps_codec->s_parse.i4_ctb_x); |
3548 | 2.61M | idx += ((ps_codec->s_parse.i4_ctb_y) * ps_sps->i2_pic_wd_in_ctb); |
3549 | 2.61M | pu1_buf = (ps_codec->pu1_parse_map + idx); |
3550 | 2.61M | *pu1_buf = 1; |
3551 | 2.61M | } |
3552 | | |
3553 | | /* Increment CTB x and y positions */ |
3554 | 2.61M | ps_codec->s_parse.i4_ctb_tile_x++; |
3555 | 2.61M | ps_codec->s_parse.i4_ctb_x++; |
3556 | 2.61M | ps_codec->s_parse.i4_ctb_slice_x++; |
3557 | | |
3558 | | /*If tiles are enabled, handle the slice counters differently*/ |
3559 | 2.61M | if(ps_pps->i1_tiles_enabled_flag) |
3560 | 620k | { |
3561 | | //Indicates multiple tiles in a slice case |
3562 | 620k | tile_start_ctb_idx = ps_tile->u1_pos_x |
3563 | 620k | + ps_tile->u1_pos_y * (ps_sps->i2_pic_wd_in_ctb); |
3564 | | |
3565 | 620k | slice_start_ctb_idx = ps_slice_hdr->i2_ctb_x |
3566 | 620k | + ps_slice_hdr->i2_ctb_y * (ps_sps->i2_pic_wd_in_ctb); |
3567 | | |
3568 | 620k | if((slice_start_ctb_idx < tile_start_ctb_idx)) |
3569 | 460k | { |
3570 | 460k | if(ps_codec->s_parse.i4_ctb_slice_x == (ps_tile->u1_pos_x + ps_tile->u2_wd)) |
3571 | 51.9k | { |
3572 | | /* Reached end of slice row within a tile /frame */ |
3573 | 51.9k | ps_codec->s_parse.i4_ctb_slice_y++; |
3574 | 51.9k | ps_codec->s_parse.i4_ctb_slice_x = ps_tile->u1_pos_x; //todo:Check |
3575 | 51.9k | } |
3576 | 460k | } |
3577 | | //Indicates multiple slices in a tile case - hence, reset slice_x |
3578 | 160k | else if(ps_codec->s_parse.i4_ctb_slice_x == (ps_tile->u2_wd)) |
3579 | 17.6k | { |
3580 | 17.6k | ps_codec->s_parse.i4_ctb_slice_y++; |
3581 | 17.6k | ps_codec->s_parse.i4_ctb_slice_x = 0; |
3582 | 17.6k | } |
3583 | 620k | } |
3584 | 1.99M | else |
3585 | 1.99M | { |
3586 | 1.99M | if(ps_codec->s_parse.i4_ctb_slice_x == ps_tile->u2_wd) |
3587 | 107k | { |
3588 | | /* Reached end of slice row within a tile /frame */ |
3589 | 107k | ps_codec->s_parse.i4_ctb_slice_y++; |
3590 | 107k | ps_codec->s_parse.i4_ctb_slice_x = 0; |
3591 | 107k | } |
3592 | 1.99M | } |
3593 | | |
3594 | | |
3595 | 2.61M | if(ps_codec->s_parse.i4_ctb_tile_x == (ps_tile->u2_wd)) |
3596 | 184k | { |
3597 | | /* Reached end of tile row */ |
3598 | 184k | ps_codec->s_parse.i4_ctb_tile_x = 0; |
3599 | 184k | ps_codec->s_parse.i4_ctb_x = ps_tile->u1_pos_x; |
3600 | | |
3601 | 184k | ps_codec->s_parse.i4_ctb_tile_y++; |
3602 | 184k | ps_codec->s_parse.i4_ctb_y++; |
3603 | | |
3604 | 184k | if(ps_codec->s_parse.i4_ctb_tile_y == (ps_tile->u2_ht)) |
3605 | 26.4k | { |
3606 | | /* Reached End of Tile */ |
3607 | 26.4k | ps_codec->s_parse.i4_ctb_tile_y = 0; |
3608 | 26.4k | ps_codec->s_parse.i4_ctb_tile_x = 0; |
3609 | 26.4k | ps_codec->s_parse.ps_tile++; |
3610 | | |
3611 | 26.4k | if((ps_tile->u2_ht + ps_tile->u1_pos_y == ps_sps->i2_pic_ht_in_ctb) && (ps_tile->u2_wd + ps_tile->u1_pos_x == ps_sps->i2_pic_wd_in_ctb)) |
3612 | 8.78k | { |
3613 | | /* Reached end of frame */ |
3614 | 8.78k | end_of_pic = 1; |
3615 | 8.78k | ps_codec->s_parse.i4_ctb_x = 0; |
3616 | 8.78k | ps_codec->s_parse.i4_ctb_y = ps_sps->i2_pic_ht_in_ctb; |
3617 | 8.78k | } |
3618 | 17.6k | else |
3619 | 17.6k | { |
3620 | | /* Initialize ctb_x and ctb_y to start of next tile */ |
3621 | 17.6k | ps_tile = ps_codec->s_parse.ps_tile; |
3622 | 17.6k | ps_codec->s_parse.i4_ctb_x = ps_tile->u1_pos_x; |
3623 | 17.6k | ps_codec->s_parse.i4_ctb_y = ps_tile->u1_pos_y; |
3624 | 17.6k | ps_codec->s_parse.i4_ctb_tile_y = 0; |
3625 | 17.6k | ps_codec->s_parse.i4_ctb_tile_x = 0; |
3626 | 17.6k | ps_codec->s_parse.i4_ctb_slice_x = ps_tile->u1_pos_x; |
3627 | 17.6k | ps_codec->s_parse.i4_ctb_slice_y = ps_tile->u1_pos_y; |
3628 | | |
3629 | 17.6k | } |
3630 | 26.4k | } |
3631 | | |
3632 | 184k | } |
3633 | | |
3634 | 2.61M | ps_codec->s_parse.i4_next_ctb_indx = ps_codec->s_parse.i4_ctb_x + |
3635 | 2.61M | ps_codec->s_parse.i4_ctb_y * ps_sps->i2_pic_wd_in_ctb; |
3636 | | |
3637 | | /* If the current slice is in error, check if the next slice's address |
3638 | | * is reached and mark the end_of_slice flag */ |
3639 | 2.61M | if(ps_codec->i4_slice_error) |
3640 | 2.06M | { |
3641 | 2.06M | slice_header_t *ps_slice_hdr_next = ps_slice_hdr + 1; |
3642 | 2.06M | WORD32 next_slice_addr = ps_slice_hdr_next->i2_ctb_x + |
3643 | 2.06M | ps_slice_hdr_next->i2_ctb_y * ps_sps->i2_pic_wd_in_ctb; |
3644 | | |
3645 | 2.06M | if(ps_codec->s_parse.i4_next_ctb_indx == next_slice_addr) |
3646 | 3.43k | end_of_slice_flag = 1; |
3647 | 2.06M | } |
3648 | | |
3649 | | /* If the codec is running in single core mode |
3650 | | * then call process function for current CTB |
3651 | | */ |
3652 | 2.61M | if((1 == ps_codec->i4_num_cores) && (ps_codec->s_parse.i4_ctb_tile_x == 0)) |
3653 | 143k | { |
3654 | 143k | process_ctxt_t *ps_proc = &ps_codec->as_process[0]; |
3655 | | // ps_proc->i4_ctb_cnt = ihevcd_nctb_cnt(ps_codec, ps_sps); |
3656 | 143k | ps_proc->i4_ctb_cnt = ps_proc->ps_tile->u2_wd; |
3657 | 143k | ihevcd_process(ps_proc); |
3658 | 143k | } |
3659 | | |
3660 | | /* If the bytes for the current slice are exhausted |
3661 | | * set end_of_slice flag to 1 |
3662 | | * This slice will be treated as incomplete */ |
3663 | 2.61M | if((UWORD8 *)ps_codec->s_parse.s_bitstrm.pu1_buf_max + BITSTRM_OFF_THRS < |
3664 | 2.61M | ((UWORD8 *)ps_codec->s_parse.s_bitstrm.pu4_buf + (ps_codec->s_parse.s_bitstrm.u4_bit_ofst / 8))) |
3665 | 142k | { |
3666 | | // end_of_slice_flag = ps_codec->i4_slice_error ? 0 : 1; |
3667 | | |
3668 | 142k | if(0 == ps_codec->i4_slice_error) |
3669 | 3.64k | end_of_slice_flag = 1; |
3670 | 142k | } |
3671 | | |
3672 | | |
3673 | 2.61M | if(end_of_pic) |
3674 | 8.78k | break; |
3675 | 2.61M | } while(!end_of_slice_flag); |
3676 | | |
3677 | | /* Reset slice error */ |
3678 | 21.9k | ps_codec->i4_slice_error = 0; |
3679 | | |
3680 | | /* Increment the slice index for parsing next slice */ |
3681 | 21.9k | if(0 == end_of_pic) |
3682 | 13.1k | { |
3683 | 13.1k | while(1) |
3684 | 13.1k | { |
3685 | | |
3686 | 13.1k | WORD32 parse_slice_idx; |
3687 | 13.1k | parse_slice_idx = ps_codec->s_parse.i4_cur_slice_idx; |
3688 | 13.1k | parse_slice_idx++; |
3689 | | |
3690 | 13.1k | { |
3691 | | /* If the next slice header is not initialized, update cur_slice_idx and break */ |
3692 | 13.1k | if((1 == ps_codec->i4_num_cores) || (0 != (parse_slice_idx & (MAX_SLICE_HDR_CNT - 1)))) |
3693 | 13.1k | { |
3694 | 13.1k | ps_codec->s_parse.i4_cur_slice_idx = parse_slice_idx; |
3695 | 13.1k | break; |
3696 | 13.1k | } |
3697 | | |
3698 | | /* If the next slice header is initialised, wait for the parsed slices to be processed */ |
3699 | 0 | else |
3700 | 0 | { |
3701 | 0 | WORD32 ctb_indx = 0; |
3702 | |
|
3703 | 0 | while(ctb_indx != ps_sps->i4_pic_size_in_ctb) |
3704 | 0 | { |
3705 | 0 | WORD32 parse_status = *(ps_codec->pu1_parse_map + ctb_indx); |
3706 | 0 | volatile WORD32 proc_status = *(ps_codec->pu1_proc_map + ctb_indx) & 1; |
3707 | |
|
3708 | 0 | if(parse_status == proc_status) |
3709 | 0 | ctb_indx++; |
3710 | 0 | } |
3711 | 0 | ps_codec->s_parse.i4_cur_slice_idx = parse_slice_idx; |
3712 | 0 | break; |
3713 | 0 | } |
3714 | | |
3715 | 13.1k | } |
3716 | 13.1k | } |
3717 | | |
3718 | 13.1k | } |
3719 | 8.78k | else |
3720 | 8.78k | { |
3721 | | #if FRAME_ILF_PAD |
3722 | | if(FRAME_ILF_PAD && 1 == ps_codec->i4_num_cores) |
3723 | | { |
3724 | | if(ps_slice_hdr->i4_abs_pic_order_cnt == 0) |
3725 | | { |
3726 | | DUMP_PRE_ILF(ps_codec->as_process[0].pu1_cur_pic_luma, |
3727 | | ps_codec->as_process[0].pu1_cur_pic_chroma, |
3728 | | ps_sps->i2_pic_width_in_luma_samples, |
3729 | | ps_sps->i2_pic_height_in_luma_samples, |
3730 | | ps_codec->i4_strd); |
3731 | | |
3732 | | DUMP_BS(ps_codec->as_process[0].s_bs_ctxt.pu4_pic_vert_bs, |
3733 | | ps_codec->as_process[0].s_bs_ctxt.pu4_pic_horz_bs, |
3734 | | ps_sps->i2_pic_wd_in_ctb * (ctb_size * ctb_size / 8 / 16) * ps_sps->i2_pic_ht_in_ctb, |
3735 | | (ps_sps->i2_pic_wd_in_ctb + 1) * (ctb_size * ctb_size / 8 / 16) * ps_sps->i2_pic_ht_in_ctb); |
3736 | | |
3737 | | DUMP_QP(ps_codec->as_process[0].s_bs_ctxt.pu1_pic_qp, |
3738 | | (ps_sps->i2_pic_height_in_luma_samples * ps_sps->i2_pic_width_in_luma_samples) / (MIN_CU_SIZE * MIN_CU_SIZE)); |
3739 | | |
3740 | | DUMP_QP_CONST_IN_CTB(ps_codec->as_process[0].s_bs_ctxt.pu1_pic_qp_const_in_ctb, |
3741 | | (ps_sps->i2_pic_height_in_luma_samples * ps_sps->i2_pic_width_in_luma_samples) / (MIN_CTB_SIZE * MIN_CTB_SIZE) / 8); |
3742 | | |
3743 | | DUMP_NO_LOOP_FILTER(ps_codec->as_process[0].pu1_pic_no_loop_filter_flag, |
3744 | | (ps_sps->i2_pic_width_in_luma_samples / MIN_CU_SIZE) * (ps_sps->i2_pic_height_in_luma_samples / MIN_CU_SIZE) / 8); |
3745 | | |
3746 | | DUMP_OFFSETS(ps_slice_hdr->i1_beta_offset_div2, |
3747 | | ps_slice_hdr->i1_tc_offset_div2, |
3748 | | ps_pps->i1_pic_cb_qp_offset, |
3749 | | ps_pps->i1_pic_cr_qp_offset); |
3750 | | } |
3751 | | ps_codec->s_parse.s_deblk_ctxt.ps_pps = ps_codec->s_parse.ps_pps; |
3752 | | ps_codec->s_parse.s_deblk_ctxt.ps_sps = ps_codec->s_parse.ps_sps; |
3753 | | ps_codec->s_parse.s_deblk_ctxt.ps_codec = ps_codec; |
3754 | | ps_codec->s_parse.s_deblk_ctxt.ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr; |
3755 | | ps_codec->s_parse.s_deblk_ctxt.is_chroma_yuv420sp_vu = (ps_codec->e_ref_chroma_fmt == IV_YUV_420SP_VU); |
3756 | | |
3757 | | ps_codec->s_parse.s_sao_ctxt.ps_pps = ps_codec->s_parse.ps_pps; |
3758 | | ps_codec->s_parse.s_sao_ctxt.ps_sps = ps_codec->s_parse.ps_sps; |
3759 | | ps_codec->s_parse.s_sao_ctxt.ps_codec = ps_codec; |
3760 | | ps_codec->s_parse.s_sao_ctxt.ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr; |
3761 | | |
3762 | | ihevcd_ilf_pad_frame(&ps_codec->s_parse.s_deblk_ctxt, &ps_codec->s_parse.s_sao_ctxt); |
3763 | | |
3764 | | } |
3765 | | #endif |
3766 | 8.78k | ps_codec->s_parse.i4_end_of_frame = 1; |
3767 | 8.78k | } |
3768 | 21.9k | return ret; |
3769 | 21.9k | } |
3770 | | |
3771 | | |
3772 | | |
3773 | | |
3774 | | |
3775 | | |
3776 | | |
3777 | | |