/src/libhevc/decoder/ihevcd_parse_headers.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_headers.c |
22 | | * |
23 | | * @brief |
24 | | * Contains functions for parsing headers |
25 | | * |
26 | | * @author |
27 | | * Harish |
28 | | * |
29 | | * @par List of Functions: |
30 | | * |
31 | | * @remarks |
32 | | * None |
33 | | * |
34 | | ******************************************************************************* |
35 | | */ |
36 | | |
37 | | /*****************************************************************************/ |
38 | | /* File Includes */ |
39 | | /*****************************************************************************/ |
40 | | #include <stdio.h> |
41 | | #include <stddef.h> |
42 | | #include <stdlib.h> |
43 | | #include <string.h> |
44 | | #include <assert.h> |
45 | | #include <limits.h> |
46 | | #include <stdint.h> |
47 | | |
48 | | #include "ihevc_typedefs.h" |
49 | | #include "iv.h" |
50 | | #include "ivd.h" |
51 | | #include "ihevcd_cxa.h" |
52 | | |
53 | | #include "ihevc_defs.h" |
54 | | #include "ihevc_debug.h" |
55 | | #include "ihevc_defs.h" |
56 | | #include "ihevc_structs.h" |
57 | | #include "ihevc_buf_mgr.h" |
58 | | #include "ihevc_dpb_mgr.h" |
59 | | #include "ihevc_macros.h" |
60 | | #include "ihevc_platform_macros.h" |
61 | | #include "ihevc_cabac_tables.h" |
62 | | #include "ihevc_common_tables.h" |
63 | | #include "ihevc_quant_tables.h" |
64 | | |
65 | | #include "ihevcd_trace.h" |
66 | | #include "ihevcd_defs.h" |
67 | | #include "ihevcd_function_selector.h" |
68 | | #include "ihevcd_structs.h" |
69 | | #include "ihevcd_error.h" |
70 | | #include "ihevcd_debug.h" |
71 | | #include "ihevcd_nal.h" |
72 | | #include "ihevcd_bitstream.h" |
73 | | #include "ihevcd_parse_headers.h" |
74 | | #include "ihevcd_ref_list.h" |
75 | | |
76 | 19.0k | #define COPY_DEFAULT_SCALING_LIST(pi2_scaling_mat) \ |
77 | 19.0k | { \ |
78 | 19.0k | WORD32 scaling_mat_offset[] = {0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, \ |
79 | 19.0k | 480, 736, 992, 1248, 1504, 1760, 2016, 3040, 4064, 5088, 6112, 7136}; \ |
80 | 19.0k | \ |
81 | 19.0k | /* scaling matrix for 4x4 */ \ |
82 | 19.0k | memcpy(pi2_scaling_mat, gi2_flat_scale_mat_32x32, 6*16*sizeof(WORD16)); \ |
83 | 19.0k | /* scaling matrix for 8x8 */ \ |
84 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[6], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \ |
85 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[7], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \ |
86 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[8], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \ |
87 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[9], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \ |
88 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[10], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \ |
89 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[11], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \ |
90 | 19.0k | /* scaling matrix for 16x16 */ \ |
91 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[12], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \ |
92 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[13], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \ |
93 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[14], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \ |
94 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[15], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \ |
95 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[16], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \ |
96 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[17], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \ |
97 | 19.0k | /* scaling matrix for 32x32 */ \ |
98 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[18], gi2_intra_default_scale_mat_32x32, 1024*sizeof(WORD16)); \ |
99 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[19], gi2_intra_default_scale_mat_32x32, 1024*sizeof(WORD16)); \ |
100 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[20], gi2_intra_default_scale_mat_32x32, 1024*sizeof(WORD16)); \ |
101 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[21], gi2_inter_default_scale_mat_32x32, 1024*sizeof(WORD16)); \ |
102 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[22], gi2_inter_default_scale_mat_32x32, 1024*sizeof(WORD16)); \ |
103 | 19.0k | memcpy(pi2_scaling_mat + scaling_mat_offset[23], gi2_inter_default_scale_mat_32x32, 1024*sizeof(WORD16)); \ |
104 | 19.0k | } |
105 | | |
106 | 17.8k | #define COPY_FLAT_SCALING_LIST(pi2_scaling_mat) \ |
107 | 17.8k | { \ |
108 | 17.8k | WORD32 scaling_mat_offset[] = {0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, \ |
109 | 17.8k | 480, 736, 992, 1248, 1504, 1760, 2016, 3040, 4064, 5088, 6112, 7136}; \ |
110 | 17.8k | \ |
111 | 17.8k | /* scaling matrix for 4x4 */ \ |
112 | 17.8k | memcpy(pi2_scaling_mat, gi2_flat_scale_mat_32x32, 6*16*sizeof(WORD16)); \ |
113 | 17.8k | /* scaling matrix for 8x8 */ \ |
114 | 17.8k | memcpy(pi2_scaling_mat + scaling_mat_offset[6], gi2_flat_scale_mat_32x32, 6*64*sizeof(WORD16)); \ |
115 | 17.8k | /* scaling matrix for 16x16 */ \ |
116 | 17.8k | memcpy(pi2_scaling_mat + scaling_mat_offset[12], gi2_flat_scale_mat_32x32, 3*256*sizeof(WORD16)); \ |
117 | 17.8k | memcpy(pi2_scaling_mat + scaling_mat_offset[15], gi2_flat_scale_mat_32x32, 3*256*sizeof(WORD16)); \ |
118 | 17.8k | /* scaling matrix for 32x32 */ \ |
119 | 125k | for (WORD32 i = 0; i < 6; i++) \ |
120 | 107k | { \ |
121 | 107k | memcpy(pi2_scaling_mat + scaling_mat_offset[18 + i], gi2_flat_scale_mat_32x32, 1024*sizeof(WORD16)); \ |
122 | 107k | } \ |
123 | 17.8k | } |
124 | | |
125 | | /* Function declarations */ |
126 | | |
127 | | /** |
128 | | ******************************************************************************* |
129 | | * |
130 | | * @brief |
131 | | * Parses Prediction weight table syntax |
132 | | * |
133 | | * @par Description: |
134 | | * Parse Prediction weight table syntax as per Section: 7.3.8.4 |
135 | | * |
136 | | * @param[in] ps_bitstrm |
137 | | * Pointer to bitstream context |
138 | | * |
139 | | * @param[in] ps_sps |
140 | | * Current SPS |
141 | | * |
142 | | * @param[in] ps_pps |
143 | | * Current PPS |
144 | | * |
145 | | * @param[in] ps_slice_hdr |
146 | | * Current Slice header |
147 | | * |
148 | | * @returns Error code from IHEVCD_ERROR_T |
149 | | * |
150 | | * @remarks |
151 | | * |
152 | | * |
153 | | ******************************************************************************* |
154 | | */ |
155 | | |
156 | | WORD32 ihevcd_parse_pred_wt_ofst(bitstrm_t *ps_bitstrm, |
157 | | sps_t *ps_sps, |
158 | | pps_t *ps_pps, |
159 | | slice_header_t *ps_slice_hdr) |
160 | 9.59k | { |
161 | 9.59k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
162 | 9.59k | WORD32 value; |
163 | 9.59k | UWORD32 u4_value; |
164 | 9.59k | WORD32 i; |
165 | | |
166 | 9.59k | pred_wt_ofst_t *ps_wt_ofst = &ps_slice_hdr->s_wt_ofst; |
167 | 9.59k | UNUSED(ps_pps); |
168 | | |
169 | 9.59k | UEV_PARSE("luma_log2_weight_denom", u4_value, ps_bitstrm); |
170 | 9.59k | if(u4_value > 7) |
171 | 1.97k | { |
172 | 1.97k | return IHEVCD_INVALID_PARAMETER; |
173 | 1.97k | } |
174 | 7.61k | ps_wt_ofst->i1_luma_log2_weight_denom = u4_value; |
175 | | |
176 | 7.61k | if(ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_MONOCHROME) |
177 | 7.61k | { |
178 | 7.61k | SEV_PARSE("delta_chroma_log2_weight_denom", value, ps_bitstrm); |
179 | 7.61k | if((value < -7) || (value > 7)) |
180 | 570 | { |
181 | 570 | return IHEVCD_INVALID_PARAMETER; |
182 | 570 | } |
183 | | |
184 | 7.04k | if(((ps_wt_ofst->i1_luma_log2_weight_denom + value) < 0) || |
185 | 6.14k | ((ps_wt_ofst->i1_luma_log2_weight_denom + value) > 7)) |
186 | 941 | { |
187 | 941 | return IHEVCD_INVALID_PARAMETER; |
188 | 941 | } |
189 | 6.10k | ps_wt_ofst->i1_chroma_log2_weight_denom = ps_wt_ofst->i1_luma_log2_weight_denom + value; |
190 | 6.10k | } |
191 | | |
192 | 23.2k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) |
193 | 17.1k | { |
194 | 17.1k | BITS_PARSE("luma_weight_l0_flag[ i ]", value, ps_bitstrm, 1); |
195 | 17.1k | ps_wt_ofst->i1_luma_weight_l0_flag[i] = value; |
196 | 17.1k | } |
197 | | |
198 | | |
199 | | |
200 | 6.10k | if(ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_MONOCHROME) |
201 | 6.10k | { |
202 | 23.2k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) |
203 | 17.1k | { |
204 | 17.1k | BITS_PARSE("chroma_weight_l0_flag[ i ]", value, ps_bitstrm, 1); |
205 | 17.1k | ps_wt_ofst->i1_chroma_weight_l0_flag[i] = value; |
206 | 17.1k | } |
207 | 6.10k | } |
208 | 0 | else |
209 | 0 | { |
210 | 0 | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) |
211 | 0 | { |
212 | 0 | ps_wt_ofst->i1_chroma_weight_l0_flag[i] = 0; |
213 | 0 | } |
214 | 0 | } |
215 | | |
216 | | |
217 | 16.6k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) |
218 | 12.8k | { |
219 | 12.8k | if(ps_wt_ofst->i1_luma_weight_l0_flag[i]) |
220 | 5.34k | { |
221 | 5.34k | SEV_PARSE("delta_luma_weight_l0[ i ]", value, ps_bitstrm); |
222 | 5.34k | if( value < -128 || value > 127 ) |
223 | 411 | { |
224 | 411 | return IHEVCD_INVALID_PARAMETER; |
225 | 411 | } |
226 | | |
227 | 4.93k | ps_wt_ofst->i2_luma_weight_l0[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom) + value; |
228 | | |
229 | 4.93k | SEV_PARSE("luma_offset_l0[ i ]", value, ps_bitstrm); |
230 | 4.93k | if( value < -128 || value > 127 ) |
231 | 414 | { |
232 | 414 | return IHEVCD_INVALID_PARAMETER; |
233 | 414 | } |
234 | 4.51k | ps_wt_ofst->i2_luma_offset_l0[i] = value; |
235 | | |
236 | 4.51k | } |
237 | 7.54k | else |
238 | 7.54k | { |
239 | 7.54k | ps_wt_ofst->i2_luma_weight_l0[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom); |
240 | 7.54k | ps_wt_ofst->i2_luma_offset_l0[i] = 0; |
241 | 7.54k | } |
242 | 12.0k | if(ps_wt_ofst->i1_chroma_weight_l0_flag[i]) |
243 | 6.60k | { |
244 | 6.60k | WORD32 ofst; |
245 | 6.60k | WORD32 shift = (1 << (BIT_DEPTH_CHROMA - 1)); |
246 | 6.60k | SEV_PARSE("delta_chroma_weight_l0[ i ][ j ]", value, ps_bitstrm); |
247 | 6.60k | if(value < -128 || value > 127) |
248 | 261 | { |
249 | 261 | return IHEVCD_INVALID_PARAMETER; |
250 | 261 | } |
251 | 6.34k | ps_wt_ofst->i2_chroma_weight_l0_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value; |
252 | | |
253 | | |
254 | 6.34k | SEV_PARSE("delta_chroma_offset_l0[ i ][ j ]", value, ps_bitstrm); |
255 | 6.34k | if( value < -512 || value > 511 ) |
256 | 428 | { |
257 | 428 | return IHEVCD_INVALID_PARAMETER; |
258 | 428 | } |
259 | 5.91k | ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l0_cb[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom); |
260 | 5.91k | ofst = value - ofst + shift; |
261 | | |
262 | 5.91k | ps_wt_ofst->i2_chroma_offset_l0_cb[i] = CLIP_S8(ofst); |
263 | | |
264 | 5.91k | SEV_PARSE("delta_chroma_weight_l0[ i ][ j ]", value, ps_bitstrm); |
265 | 5.91k | if(value < -128 || value > 127) |
266 | 683 | { |
267 | 683 | return IHEVCD_INVALID_PARAMETER; |
268 | 683 | } |
269 | 5.23k | ps_wt_ofst->i2_chroma_weight_l0_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value; |
270 | | |
271 | | |
272 | 5.23k | SEV_PARSE("delta_chroma_offset_l0[ i ][ j ]", value, ps_bitstrm); |
273 | 5.23k | if( value < -512 || value > 511 ) |
274 | 192 | { |
275 | 192 | return IHEVCD_INVALID_PARAMETER; |
276 | 192 | } |
277 | 5.03k | ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l0_cr[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom); |
278 | 5.03k | ofst = value - ofst + shift; |
279 | | |
280 | 5.03k | ps_wt_ofst->i2_chroma_offset_l0_cr[i] = CLIP_S8(ofst); |
281 | | |
282 | 5.03k | } |
283 | 5.45k | else |
284 | 5.45k | { |
285 | 5.45k | ps_wt_ofst->i2_chroma_weight_l0_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom); |
286 | 5.45k | ps_wt_ofst->i2_chroma_weight_l0_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom); |
287 | | |
288 | 5.45k | ps_wt_ofst->i2_chroma_offset_l0_cb[i] = 0; |
289 | 5.45k | ps_wt_ofst->i2_chroma_offset_l0_cr[i] = 0; |
290 | 5.45k | } |
291 | 12.0k | } |
292 | 3.71k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
293 | 3.05k | { |
294 | 10.0k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) |
295 | 7.01k | { |
296 | 7.01k | BITS_PARSE("luma_weight_l1_flag[ i ]", value, ps_bitstrm, 1); |
297 | 7.01k | ps_wt_ofst->i1_luma_weight_l1_flag[i] = value; |
298 | 7.01k | } |
299 | | |
300 | 3.05k | if(ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_MONOCHROME) |
301 | 3.05k | { |
302 | 10.0k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) |
303 | 7.01k | { |
304 | 7.01k | BITS_PARSE("chroma_weight_l1_flag[ i ]", value, ps_bitstrm, 1); |
305 | 7.01k | ps_wt_ofst->i1_chroma_weight_l1_flag[i] = value; |
306 | 7.01k | } |
307 | 3.05k | } |
308 | 0 | else |
309 | 0 | { |
310 | 0 | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) |
311 | 0 | { |
312 | 0 | ps_wt_ofst->i1_chroma_weight_l1_flag[i] = 0; |
313 | 0 | } |
314 | 0 | } |
315 | | |
316 | 7.21k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) |
317 | 5.25k | { |
318 | 5.25k | if(ps_wt_ofst->i1_luma_weight_l1_flag[i]) |
319 | 3.41k | { |
320 | 3.41k | SEV_PARSE("delta_luma_weight_l1[ i ]", value, ps_bitstrm); |
321 | 3.41k | if( value < -128 || value > 127 ) |
322 | 229 | { |
323 | 229 | return IHEVCD_INVALID_PARAMETER; |
324 | 229 | } |
325 | | |
326 | 3.18k | ps_wt_ofst->i2_luma_weight_l1[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom) + value; |
327 | | |
328 | 3.18k | SEV_PARSE("luma_offset_l1[ i ]", value, ps_bitstrm); |
329 | 3.18k | if( value < -128 || value > 127 ) |
330 | 108 | { |
331 | 108 | return IHEVCD_INVALID_PARAMETER; |
332 | 108 | } |
333 | 3.07k | ps_wt_ofst->i2_luma_offset_l1[i] = value; |
334 | | |
335 | 3.07k | } |
336 | 1.84k | else |
337 | 1.84k | { |
338 | 1.84k | ps_wt_ofst->i2_luma_weight_l1[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom); |
339 | 1.84k | ps_wt_ofst->i2_luma_offset_l1[i] = 0; |
340 | 1.84k | } |
341 | | |
342 | 4.92k | if(ps_wt_ofst->i1_chroma_weight_l1_flag[i]) |
343 | 2.97k | { |
344 | 2.97k | WORD32 ofst; |
345 | 2.97k | WORD32 shift = (1 << (BIT_DEPTH_CHROMA - 1)); |
346 | 2.97k | SEV_PARSE("delta_chroma_weight_l1[ i ][ j ]", value, ps_bitstrm); |
347 | 2.97k | if(value < -128 || value > 127) |
348 | 202 | { |
349 | 202 | return IHEVCD_INVALID_PARAMETER; |
350 | 202 | } |
351 | 2.77k | ps_wt_ofst->i2_chroma_weight_l1_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value;; |
352 | | |
353 | | |
354 | 2.77k | SEV_PARSE("delta_chroma_offset_l1[ i ][ j ]", value, ps_bitstrm); |
355 | 2.77k | if( value < -512 || value > 511 ) |
356 | 158 | { |
357 | 158 | return IHEVCD_INVALID_PARAMETER; |
358 | 158 | } |
359 | 2.61k | ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l1_cb[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom); |
360 | 2.61k | ofst = value - ofst + shift; |
361 | | |
362 | 2.61k | ps_wt_ofst->i2_chroma_offset_l1_cb[i] = CLIP_S8(ofst);; |
363 | | |
364 | 2.61k | SEV_PARSE("delta_chroma_weight_l1[ i ][ j ]", value, ps_bitstrm); |
365 | 2.61k | if(value < -128 || value > 127) |
366 | 286 | { |
367 | 286 | return IHEVCD_INVALID_PARAMETER; |
368 | 286 | } |
369 | 2.32k | ps_wt_ofst->i2_chroma_weight_l1_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value; |
370 | | |
371 | | |
372 | 2.32k | SEV_PARSE("delta_chroma_offset_l1[ i ][ j ]", value, ps_bitstrm); |
373 | 2.32k | if( value < -512 || value > 511 ) |
374 | 111 | { |
375 | 111 | return IHEVCD_INVALID_PARAMETER; |
376 | 111 | } |
377 | 2.21k | ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l1_cr[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom); |
378 | 2.21k | ofst = value - ofst + shift; |
379 | | |
380 | 2.21k | ps_wt_ofst->i2_chroma_offset_l1_cr[i] = CLIP_S8(ofst);; |
381 | | |
382 | 2.21k | } |
383 | 1.94k | else |
384 | 1.94k | { |
385 | 1.94k | ps_wt_ofst->i2_chroma_weight_l1_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom); |
386 | 1.94k | ps_wt_ofst->i2_chroma_weight_l1_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom); |
387 | | |
388 | 1.94k | ps_wt_ofst->i2_chroma_offset_l1_cb[i] = 0; |
389 | 1.94k | ps_wt_ofst->i2_chroma_offset_l1_cr[i] = 0; |
390 | | |
391 | 1.94k | } |
392 | 4.92k | } |
393 | 3.05k | } |
394 | 2.62k | return ret; |
395 | 3.71k | } |
396 | | |
397 | | /** |
398 | | ******************************************************************************* |
399 | | * |
400 | | * @brief |
401 | | * Parses short term reference picture set |
402 | | * |
403 | | * @par Description |
404 | | * Parses short term reference picture set as per section 7.3.8.2. |
405 | | * Can be called by either SPS or Slice header parsing modules. |
406 | | * |
407 | | * @param[in] ps_bitstrm |
408 | | * Pointer to bitstream structure |
409 | | * |
410 | | * @param[out] ps_stref_picset_base |
411 | | * Pointer to first short term ref pic set structure |
412 | | * |
413 | | * @param[in] num_short_term_ref_pic_sets |
414 | | * Number of short term reference pic sets |
415 | | * |
416 | | * @param[in] idx |
417 | | * Current short term ref pic set id |
418 | | * |
419 | | * @returns Error code from IHEVCD_ERROR_T |
420 | | * |
421 | | * @remarks |
422 | | * |
423 | | ******************************************************************************* |
424 | | */ |
425 | | IHEVCD_ERROR_T ihevcd_short_term_ref_pic_set(bitstrm_t *ps_bitstrm, |
426 | | stref_picset_t *ps_stref_picset_base, |
427 | | WORD32 num_short_term_ref_pic_sets, |
428 | | WORD32 idx, |
429 | | stref_picset_t *ps_stref_picset) |
430 | 42.6k | { |
431 | 42.6k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
432 | 42.6k | UWORD32 value; |
433 | 42.6k | stref_picset_t *ps_stref_picset_ref; |
434 | 42.6k | WORD32 delta_idx, delta_rps; |
435 | 42.6k | WORD32 r_idx; |
436 | 42.6k | WORD32 i; |
437 | 42.6k | WORD32 j, k, temp; |
438 | 42.6k | if(idx > 0) |
439 | 32.7k | { |
440 | 32.7k | BITS_PARSE("inter_ref_pic_set_prediction_flag", value, ps_bitstrm, 1); |
441 | 32.7k | ps_stref_picset->i1_inter_ref_pic_set_prediction_flag = value; |
442 | 32.7k | } |
443 | 9.96k | else |
444 | 9.96k | ps_stref_picset->i1_inter_ref_pic_set_prediction_flag = 0; |
445 | | |
446 | 42.6k | if(ps_stref_picset->i1_inter_ref_pic_set_prediction_flag) |
447 | 28.3k | { |
448 | 28.3k | WORD32 delta_rps_sign; |
449 | 28.3k | WORD32 abs_delta_rps; |
450 | 28.3k | WORD32 num_neg_pics = 0; |
451 | 28.3k | WORD32 num_pos_pics = 0; |
452 | 28.3k | WORD32 num_pics = 0; |
453 | | |
454 | 28.3k | if(idx == num_short_term_ref_pic_sets) |
455 | 3.68k | { |
456 | 3.68k | UEV_PARSE("delta_idx_minus1", value, ps_bitstrm); |
457 | 3.68k | if(value > num_short_term_ref_pic_sets - 1) |
458 | 263 | { |
459 | 263 | return IHEVCD_INVALID_PARAMETER; |
460 | 263 | } |
461 | 3.41k | delta_idx = value + 1; |
462 | 3.41k | } |
463 | 24.6k | else |
464 | 24.6k | { |
465 | 24.6k | delta_idx = 1; |
466 | 24.6k | } |
467 | 28.0k | r_idx = idx - delta_idx; |
468 | 28.0k | r_idx = CLIP3(r_idx, 0, idx - 1); |
469 | | |
470 | 28.0k | ps_stref_picset_ref = ps_stref_picset_base + r_idx; |
471 | | |
472 | 28.0k | BITS_PARSE("delta_rps_sign", value, ps_bitstrm, 1); |
473 | 28.0k | delta_rps_sign = value; |
474 | | |
475 | 28.0k | UEV_PARSE("abs_delta_rps_minus1", value, ps_bitstrm); |
476 | 28.0k | if(value > 32767) |
477 | 69 | { |
478 | 69 | return IHEVCD_INVALID_PARAMETER; |
479 | 69 | } |
480 | 27.9k | abs_delta_rps = value + 1; |
481 | | |
482 | 27.9k | delta_rps = (1 - 2 * delta_rps_sign) * (abs_delta_rps); |
483 | | |
484 | | |
485 | | |
486 | 161k | for(i = 0; i <= ps_stref_picset_ref->i1_num_delta_pocs; i++) |
487 | 133k | { |
488 | 133k | WORD32 ref_idc; |
489 | | |
490 | | /*****************************************************************/ |
491 | | /* ref_idc is parsed as below */ |
492 | | /* bits "1" ref_idc 1 */ |
493 | | /* bits "01" ref_idc 2 */ |
494 | | /* bits "00" ref_idc 0 */ |
495 | | /*****************************************************************/ |
496 | 133k | BITS_PARSE("used_by_curr_pic_flag", value, ps_bitstrm, 1); |
497 | 133k | ref_idc = value; |
498 | 133k | ps_stref_picset->ai1_used[num_pics] = value; |
499 | | /* If ref_idc is zero check for next bit */ |
500 | 133k | if(0 == ref_idc) |
501 | 22.6k | { |
502 | 22.6k | BITS_PARSE("use_delta_flag", value, ps_bitstrm, 1); |
503 | 22.6k | ref_idc = value << 1; |
504 | 22.6k | } |
505 | 133k | if((ref_idc == 1) || (ref_idc == 2)) |
506 | 113k | { |
507 | 113k | WORD32 delta_poc; |
508 | 113k | delta_poc = delta_rps; |
509 | 113k | delta_poc += |
510 | 113k | ((i < ps_stref_picset_ref->i1_num_delta_pocs) ? |
511 | 94.7k | ps_stref_picset_ref->ai2_delta_poc[i] : |
512 | 113k | 0); |
513 | | |
514 | 113k | ps_stref_picset->ai2_delta_poc[num_pics] = delta_poc; |
515 | | |
516 | 113k | if(delta_poc < 0) |
517 | 62.2k | { |
518 | 62.2k | num_neg_pics++; |
519 | 62.2k | } |
520 | 50.8k | else |
521 | 50.8k | { |
522 | 50.8k | num_pos_pics++; |
523 | 50.8k | } |
524 | 113k | num_pics++; |
525 | 113k | } |
526 | 133k | ps_stref_picset->ai1_ref_idc[i] = ref_idc; |
527 | 133k | } |
528 | | |
529 | 27.9k | num_neg_pics = CLIP3(num_neg_pics, 0, MAX_DPB_SIZE - 1); |
530 | 27.9k | num_pos_pics = CLIP3(num_pos_pics, 0, (MAX_DPB_SIZE - 1 - num_neg_pics)); |
531 | 27.9k | num_pics = num_neg_pics + num_pos_pics; |
532 | | |
533 | 27.9k | ps_stref_picset->i1_num_ref_idc = |
534 | 27.9k | ps_stref_picset_ref->i1_num_delta_pocs + 1; |
535 | 27.9k | ps_stref_picset->i1_num_delta_pocs = num_pics; |
536 | 27.9k | ps_stref_picset->i1_num_pos_pics = num_pos_pics; |
537 | 27.9k | ps_stref_picset->i1_num_neg_pics = num_neg_pics; |
538 | | |
539 | | |
540 | 113k | for(j = 1; j < num_pics; j++) |
541 | 85.3k | { |
542 | 85.3k | WORD32 delta_poc = ps_stref_picset->ai2_delta_poc[j]; |
543 | 85.3k | WORD8 i1_used = ps_stref_picset->ai1_used[j]; |
544 | 299k | for(k = j - 1; k >= 0; k--) |
545 | 214k | { |
546 | 214k | temp = ps_stref_picset->ai2_delta_poc[k]; |
547 | 214k | if(delta_poc < temp) |
548 | 69.0k | { |
549 | 69.0k | ps_stref_picset->ai2_delta_poc[k + 1] = temp; |
550 | 69.0k | ps_stref_picset->ai1_used[k + 1] = ps_stref_picset->ai1_used[k]; |
551 | 69.0k | ps_stref_picset->ai2_delta_poc[k] = delta_poc; |
552 | 69.0k | ps_stref_picset->ai1_used[k] = i1_used; |
553 | 69.0k | } |
554 | 214k | } |
555 | 85.3k | } |
556 | | // flip the negative values to largest first |
557 | 52.5k | for(j = 0, k = num_neg_pics - 1; j < num_neg_pics >> 1; j++, k--) |
558 | 24.5k | { |
559 | 24.5k | WORD32 delta_poc = ps_stref_picset->ai2_delta_poc[j]; |
560 | 24.5k | WORD8 i1_used = ps_stref_picset->ai1_used[j]; |
561 | 24.5k | ps_stref_picset->ai2_delta_poc[j] = ps_stref_picset->ai2_delta_poc[k]; |
562 | 24.5k | ps_stref_picset->ai1_used[j] = ps_stref_picset->ai1_used[k]; |
563 | 24.5k | ps_stref_picset->ai2_delta_poc[k] = delta_poc; |
564 | 24.5k | ps_stref_picset->ai1_used[k] = i1_used; |
565 | 24.5k | } |
566 | | |
567 | 27.9k | } |
568 | 14.3k | else |
569 | 14.3k | { |
570 | 14.3k | WORD32 prev_poc = 0; |
571 | 14.3k | WORD32 poc; |
572 | | |
573 | 14.3k | UEV_PARSE("num_negative_pics", value, ps_bitstrm); |
574 | 14.3k | if(value > MAX_DPB_SIZE - 1) |
575 | 799 | { |
576 | 799 | return IHEVCD_INVALID_PARAMETER; |
577 | 799 | } |
578 | 13.5k | ps_stref_picset->i1_num_neg_pics = value; |
579 | | |
580 | 13.5k | UEV_PARSE("num_positive_pics", value, ps_bitstrm); |
581 | 13.5k | if(value > (MAX_DPB_SIZE - 1 - ps_stref_picset->i1_num_neg_pics)) |
582 | 323 | { |
583 | 323 | return IHEVCD_INVALID_PARAMETER; |
584 | 323 | } |
585 | 13.2k | ps_stref_picset->i1_num_pos_pics = value; |
586 | | |
587 | 13.2k | ps_stref_picset->i1_num_delta_pocs = |
588 | 13.2k | ps_stref_picset->i1_num_neg_pics + |
589 | 13.2k | ps_stref_picset->i1_num_pos_pics; |
590 | | |
591 | | |
592 | 33.9k | for(i = 0; i < ps_stref_picset->i1_num_neg_pics; i++) |
593 | 20.8k | { |
594 | 20.8k | UEV_PARSE("delta_poc_s0_minus1", value, ps_bitstrm); |
595 | 20.8k | if(value > 32767) |
596 | 139 | { |
597 | 139 | return IHEVCD_INVALID_PARAMETER; |
598 | 139 | } |
599 | 20.7k | poc = prev_poc - ((WORD32)(value + 1)); |
600 | 20.7k | prev_poc = poc; |
601 | 20.7k | ps_stref_picset->ai2_delta_poc[i] = poc; |
602 | | |
603 | 20.7k | BITS_PARSE("used_by_curr_pic_s0_flag", value, ps_bitstrm, 1); |
604 | 20.7k | ps_stref_picset->ai1_used[i] = value; |
605 | | |
606 | 20.7k | } |
607 | 13.0k | prev_poc = 0; |
608 | 13.0k | for(i = ps_stref_picset->i1_num_neg_pics; |
609 | 26.5k | i < ps_stref_picset->i1_num_delta_pocs; |
610 | 13.4k | i++) |
611 | 13.6k | { |
612 | 13.6k | UEV_PARSE("delta_poc_s1_minus1", value, ps_bitstrm); |
613 | 13.6k | if(value > 32767) |
614 | 183 | { |
615 | 183 | return IHEVCD_INVALID_PARAMETER; |
616 | 183 | } |
617 | 13.4k | poc = prev_poc + (value + 1); |
618 | 13.4k | prev_poc = poc; |
619 | 13.4k | ps_stref_picset->ai2_delta_poc[i] = poc; |
620 | | |
621 | 13.4k | BITS_PARSE("used_by_curr_pic_s1_flag", value, ps_bitstrm, 1); |
622 | 13.4k | ps_stref_picset->ai1_used[i] = value; |
623 | | |
624 | 13.4k | } |
625 | | |
626 | 13.0k | } |
627 | | |
628 | 40.8k | return ret; |
629 | 42.6k | } |
630 | | |
631 | | |
632 | | static WORD32 ihevcd_parse_sub_layer_hrd_parameters(bitstrm_t *ps_bitstrm, |
633 | | sub_lyr_hrd_params_t *ps_sub_layer_hrd_params, |
634 | | WORD32 cpb_cnt, |
635 | | WORD32 sub_pic_cpb_params_present_flag) |
636 | 1.14k | { |
637 | 1.14k | WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
638 | 1.14k | WORD32 i; |
639 | | |
640 | 4.68k | for(i = 0; i <= cpb_cnt; i++) |
641 | 3.54k | { |
642 | 3.54k | UEV_PARSE("bit_rate_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_bit_rate_value_minus1[i], ps_bitstrm); |
643 | 3.54k | if(ps_sub_layer_hrd_params->au4_bit_rate_value_minus1[i] > UINT_MAX - 1) |
644 | 0 | { |
645 | 0 | return IHEVCD_INVALID_PARAMETER; |
646 | 0 | } |
647 | 3.54k | UEV_PARSE("cpb_size_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_cpb_size_value_minus1[i], ps_bitstrm); |
648 | 3.54k | if(ps_sub_layer_hrd_params->au4_cpb_size_value_minus1[i] > UINT_MAX - 1) |
649 | 0 | { |
650 | 0 | return IHEVCD_INVALID_PARAMETER; |
651 | 0 | } |
652 | 3.54k | if(sub_pic_cpb_params_present_flag) |
653 | 1.54k | { |
654 | 1.54k | UEV_PARSE("cpb_size_du_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_cpb_size_du_value_minus1[i], ps_bitstrm); |
655 | 1.54k | if(ps_sub_layer_hrd_params->au4_cpb_size_du_value_minus1[i] > UINT_MAX - 1) |
656 | 0 | { |
657 | 0 | return IHEVCD_INVALID_PARAMETER; |
658 | 0 | } |
659 | 1.54k | UEV_PARSE("bit_rate_du_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_bit_rate_du_value_minus1[i], ps_bitstrm); |
660 | 1.54k | if(ps_sub_layer_hrd_params->au4_bit_rate_du_value_minus1[i] > UINT_MAX - 1) |
661 | 0 | { |
662 | 0 | return IHEVCD_INVALID_PARAMETER; |
663 | 0 | } |
664 | 1.54k | } |
665 | 3.54k | BITS_PARSE("cbr_flag[ i ]", ps_sub_layer_hrd_params->au1_cbr_flag[i], ps_bitstrm, 1); |
666 | 3.54k | } |
667 | | |
668 | 1.14k | return ret; |
669 | 1.14k | } |
670 | | |
671 | | |
672 | | static WORD32 ihevcd_parse_hrd_parameters(bitstrm_t *ps_bitstrm, |
673 | | hrd_params_t *ps_hrd, |
674 | | WORD32 common_info_present_flag, |
675 | | WORD32 max_num_sub_layers_minus1) |
676 | 465 | { |
677 | 465 | WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
678 | 465 | WORD32 i; |
679 | | |
680 | 465 | ps_hrd->u1_nal_hrd_parameters_present_flag = 0; |
681 | 465 | ps_hrd->u1_vcl_hrd_parameters_present_flag = 0; |
682 | | |
683 | 465 | ps_hrd->u1_sub_pic_cpb_params_present_flag = 0; |
684 | | |
685 | 465 | ps_hrd->u1_tick_divisor_minus2 = 0; |
686 | 465 | ps_hrd->u1_du_cpb_removal_delay_increment_length_minus1 = 0; |
687 | 465 | ps_hrd->u1_sub_pic_cpb_params_in_pic_timing_sei_flag = 0; |
688 | 465 | ps_hrd->u1_dpb_output_delay_du_length_minus1 = 0; |
689 | | |
690 | 465 | ps_hrd->u4_bit_rate_scale = 0; |
691 | 465 | ps_hrd->u4_cpb_size_scale = 0; |
692 | 465 | ps_hrd->u4_cpb_size_du_scale = 0; |
693 | | |
694 | 465 | ps_hrd->u1_initial_cpb_removal_delay_length_minus1 = 23; |
695 | 465 | ps_hrd->u1_au_cpb_removal_delay_length_minus1 = 23; |
696 | 465 | ps_hrd->u1_dpb_output_delay_length_minus1 = 23; |
697 | | |
698 | 465 | if(common_info_present_flag) |
699 | 465 | { |
700 | 465 | BITS_PARSE("nal_hrd_parameters_present_flag", ps_hrd->u1_nal_hrd_parameters_present_flag, ps_bitstrm, 1); |
701 | 465 | BITS_PARSE("vcl_hrd_parameters_present_flag", ps_hrd->u1_vcl_hrd_parameters_present_flag, ps_bitstrm, 1); |
702 | | |
703 | 465 | if(ps_hrd->u1_nal_hrd_parameters_present_flag || ps_hrd->u1_vcl_hrd_parameters_present_flag) |
704 | 443 | { |
705 | 443 | BITS_PARSE("sub_pic_cpb_params_present_flag", ps_hrd->u1_sub_pic_cpb_params_present_flag, ps_bitstrm, 1); |
706 | 443 | if(ps_hrd->u1_sub_pic_cpb_params_present_flag) |
707 | 257 | { |
708 | 257 | BITS_PARSE("tick_divisor_minus2", ps_hrd->u1_tick_divisor_minus2, ps_bitstrm, 8); |
709 | 257 | BITS_PARSE("du_cpb_removal_delay_increment_length_minus1", ps_hrd->u1_du_cpb_removal_delay_increment_length_minus1, ps_bitstrm, 5); |
710 | 257 | BITS_PARSE("sub_pic_cpb_params_in_pic_timing_sei_flag", ps_hrd->u1_sub_pic_cpb_params_in_pic_timing_sei_flag, ps_bitstrm, 1); |
711 | 257 | BITS_PARSE("dpb_output_delay_du_length_minus1", ps_hrd->u1_dpb_output_delay_du_length_minus1, ps_bitstrm, 5); |
712 | 257 | } |
713 | | |
714 | 443 | BITS_PARSE("bit_rate_scale", ps_hrd->u4_bit_rate_scale, ps_bitstrm, 4); |
715 | 443 | BITS_PARSE("cpb_size_scale", ps_hrd->u4_cpb_size_scale, ps_bitstrm, 4); |
716 | 443 | if(ps_hrd->u1_sub_pic_cpb_params_present_flag) |
717 | 257 | BITS_PARSE("cpb_size_du_scale", ps_hrd->u4_cpb_size_du_scale, ps_bitstrm, 4); |
718 | | |
719 | 443 | BITS_PARSE("initial_cpb_removal_delay_length_minus1", ps_hrd->u1_initial_cpb_removal_delay_length_minus1, ps_bitstrm, 5); |
720 | 443 | BITS_PARSE("au_cpb_removal_delay_length_minus1", ps_hrd->u1_au_cpb_removal_delay_length_minus1, ps_bitstrm, 5); |
721 | 443 | BITS_PARSE("dpb_output_delay_length_minus1", ps_hrd->u1_dpb_output_delay_length_minus1, ps_bitstrm, 5); |
722 | 443 | } |
723 | 465 | } |
724 | | |
725 | | |
726 | 1.26k | for(i = 0; i <= max_num_sub_layers_minus1; i++) |
727 | 913 | { |
728 | 913 | BITS_PARSE("fixed_pic_rate_general_flag[ i ]", ps_hrd->au1_fixed_pic_rate_general_flag[i], ps_bitstrm, 1); |
729 | | |
730 | 913 | ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i] = 1; |
731 | 913 | ps_hrd->au2_elemental_duration_in_tc_minus1[i] = 0; |
732 | 913 | ps_hrd->au1_low_delay_hrd_flag[i] = 0; |
733 | 913 | ps_hrd->au1_cpb_cnt_minus1[i] = 0; |
734 | | |
735 | 913 | if(!ps_hrd->au1_fixed_pic_rate_general_flag[i]) |
736 | 453 | BITS_PARSE("fixed_pic_rate_within_cvs_flag[ i ]", ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i], ps_bitstrm, 1); |
737 | | |
738 | 913 | if(ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i]) |
739 | 628 | { |
740 | 628 | UEV_PARSE("elemental_duration_in_tc_minus1[ i ]", ps_hrd->au2_elemental_duration_in_tc_minus1[i], ps_bitstrm); |
741 | 628 | if(ps_hrd->au2_elemental_duration_in_tc_minus1[i] > 2047) |
742 | 10 | { |
743 | 10 | return IHEVCD_INVALID_PARAMETER; |
744 | 10 | } |
745 | 628 | } |
746 | 285 | else |
747 | 285 | { |
748 | 285 | BITS_PARSE("low_delay_hrd_flag[ i ]", ps_hrd->au1_low_delay_hrd_flag[i], ps_bitstrm, 1); |
749 | 285 | } |
750 | | |
751 | 903 | if(!ps_hrd->au1_low_delay_hrd_flag[i]) |
752 | 771 | { |
753 | 771 | UEV_PARSE("cpb_cnt_minus1[ i ]", ps_hrd->au1_cpb_cnt_minus1[i], ps_bitstrm); |
754 | 771 | if(ps_hrd->au1_cpb_cnt_minus1[i] > (MAX_CPB_CNT - 1)) |
755 | 99 | { |
756 | 99 | return IHEVCD_INVALID_PARAMETER; |
757 | 99 | } |
758 | 771 | } |
759 | | |
760 | 804 | if(ps_hrd->u1_nal_hrd_parameters_present_flag) |
761 | 471 | ihevcd_parse_sub_layer_hrd_parameters(ps_bitstrm, |
762 | 471 | &ps_hrd->as_sub_layer_hrd_params[i], |
763 | 471 | ps_hrd->au1_cpb_cnt_minus1[i], |
764 | 471 | ps_hrd->u1_sub_pic_cpb_params_present_flag); |
765 | | |
766 | 804 | if(ps_hrd->u1_vcl_hrd_parameters_present_flag) |
767 | 671 | ihevcd_parse_sub_layer_hrd_parameters(ps_bitstrm, |
768 | 671 | &ps_hrd->as_sub_layer_hrd_params[i], |
769 | 671 | ps_hrd->au1_cpb_cnt_minus1[i], |
770 | 671 | ps_hrd->u1_sub_pic_cpb_params_present_flag); |
771 | 804 | } |
772 | | |
773 | 356 | return ret; |
774 | 465 | } |
775 | | |
776 | | |
777 | | static WORD32 ihevcd_parse_vui_parameters(bitstrm_t *ps_bitstrm, |
778 | | vui_t *ps_vui, |
779 | | WORD32 sps_max_sub_layers_minus1) |
780 | 7.92k | { |
781 | 7.92k | WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
782 | 7.92k | UWORD16 u2_sar_width = 0; |
783 | 7.92k | UWORD16 u2_sar_height = 0; |
784 | | |
785 | 7.92k | BITS_PARSE("aspect_ratio_info_present_flag", ps_vui->u1_aspect_ratio_info_present_flag, ps_bitstrm, 1); |
786 | | |
787 | 7.92k | ps_vui->u1_aspect_ratio_idc = SAR_UNUSED; |
788 | 7.92k | u2_sar_width = 0; |
789 | 7.92k | u2_sar_height = 0; |
790 | 7.92k | if(ps_vui->u1_aspect_ratio_info_present_flag) |
791 | 4.64k | { |
792 | 4.64k | BITS_PARSE("aspect_ratio_idc", ps_vui->u1_aspect_ratio_idc, ps_bitstrm, 8); |
793 | 4.64k | switch(ps_vui->u1_aspect_ratio_idc) |
794 | 4.64k | { |
795 | 43 | case SAR_1_1: |
796 | 43 | u2_sar_width = 1; |
797 | 43 | u2_sar_height = 1; |
798 | 43 | break; |
799 | 31 | case SAR_12_11: |
800 | 31 | u2_sar_width = 12; |
801 | 31 | u2_sar_height = 11; |
802 | 31 | break; |
803 | 45 | case SAR_10_11: |
804 | 45 | u2_sar_width = 10; |
805 | 45 | u2_sar_height = 11; |
806 | 45 | break; |
807 | 18 | case SAR_16_11: |
808 | 18 | u2_sar_width = 16; |
809 | 18 | u2_sar_height = 11; |
810 | 18 | break; |
811 | 23 | case SAR_40_33: |
812 | 23 | u2_sar_width = 40; |
813 | 23 | u2_sar_height = 33; |
814 | 23 | break; |
815 | 31 | case SAR_24_11: |
816 | 31 | u2_sar_width = 24; |
817 | 31 | u2_sar_height = 11; |
818 | 31 | break; |
819 | 15 | case SAR_20_11: |
820 | 15 | u2_sar_width = 20; |
821 | 15 | u2_sar_height = 11; |
822 | 15 | break; |
823 | 12 | case SAR_32_11: |
824 | 12 | u2_sar_width = 32; |
825 | 12 | u2_sar_height = 11; |
826 | 12 | break; |
827 | 1.25k | case SAR_80_33: |
828 | 1.25k | u2_sar_width = 80; |
829 | 1.25k | u2_sar_height = 33; |
830 | 1.25k | break; |
831 | 13 | case SAR_18_11: |
832 | 13 | u2_sar_width = 18; |
833 | 13 | u2_sar_height = 11; |
834 | 13 | break; |
835 | 20 | case SAR_15_11: |
836 | 20 | u2_sar_width = 15; |
837 | 20 | u2_sar_height = 11; |
838 | 20 | break; |
839 | 83 | case SAR_64_33: |
840 | 83 | u2_sar_width = 64; |
841 | 83 | u2_sar_height = 33; |
842 | 83 | break; |
843 | 60 | case SAR_160_99: |
844 | 60 | u2_sar_width = 160; |
845 | 60 | u2_sar_height = 99; |
846 | 60 | break; |
847 | 34 | case SAR_4_3: |
848 | 34 | u2_sar_width = 4; |
849 | 34 | u2_sar_height = 3; |
850 | 34 | break; |
851 | 23 | case SAR_3_2: |
852 | 23 | u2_sar_width = 3; |
853 | 23 | u2_sar_height = 2; |
854 | 23 | break; |
855 | 22 | case SAR_2_1: |
856 | 22 | u2_sar_width = 2; |
857 | 22 | u2_sar_height = 1; |
858 | 22 | break; |
859 | 1.50k | case EXTENDED_SAR: |
860 | 1.50k | BITS_PARSE("sar_width", u2_sar_width, ps_bitstrm, 16); |
861 | 1.50k | BITS_PARSE("sar_height", u2_sar_height, ps_bitstrm, 16); |
862 | 1.50k | break; |
863 | 1.41k | default: |
864 | 1.41k | u2_sar_width = 0; |
865 | 1.41k | u2_sar_height = 0; |
866 | 1.41k | break; |
867 | 4.64k | } |
868 | 4.64k | } |
869 | | |
870 | 7.92k | ps_vui->u2_sar_width = u2_sar_width; |
871 | 7.92k | ps_vui->u2_sar_height = u2_sar_height; |
872 | | |
873 | 7.92k | BITS_PARSE("overscan_info_present_flag", ps_vui->u1_overscan_info_present_flag, ps_bitstrm, 1); |
874 | 7.92k | ps_vui->u1_overscan_appropriate_flag = 0; |
875 | 7.92k | if(ps_vui->u1_overscan_info_present_flag) |
876 | 2.54k | BITS_PARSE("overscan_appropriate_flag", ps_vui->u1_overscan_appropriate_flag, ps_bitstrm, 1); |
877 | | |
878 | 7.92k | BITS_PARSE("video_signal_type_present_flag", ps_vui->u1_video_signal_type_present_flag, ps_bitstrm, 1); |
879 | 7.92k | ps_vui->u1_video_format = VID_FMT_UNSPECIFIED; |
880 | 7.92k | ps_vui->u1_video_full_range_flag = 0; |
881 | 7.92k | ps_vui->u1_colour_description_present_flag = 0; |
882 | 7.92k | ps_vui->u1_colour_primaries = 2; |
883 | 7.92k | ps_vui->u1_transfer_characteristics = 2; |
884 | 7.92k | ps_vui->u1_matrix_coefficients = 2; |
885 | | |
886 | 7.92k | if(ps_vui->u1_video_signal_type_present_flag) |
887 | 2.90k | { |
888 | 2.90k | BITS_PARSE("video_format", ps_vui->u1_video_format, ps_bitstrm, 3); |
889 | 2.90k | BITS_PARSE("video_full_range_flag", ps_vui->u1_video_full_range_flag, ps_bitstrm, 1); |
890 | 2.90k | BITS_PARSE("colour_description_present_flag", ps_vui->u1_colour_description_present_flag, ps_bitstrm, 1); |
891 | 2.90k | if(ps_vui->u1_colour_description_present_flag) |
892 | 2.37k | { |
893 | 2.37k | BITS_PARSE("colour_primaries", ps_vui->u1_colour_primaries, ps_bitstrm, 8); |
894 | 2.37k | BITS_PARSE("transfer_characteristics", ps_vui->u1_transfer_characteristics, ps_bitstrm, 8); |
895 | 2.37k | BITS_PARSE("matrix_coeffs", ps_vui->u1_matrix_coefficients, ps_bitstrm, 8); |
896 | 2.37k | } |
897 | 2.90k | } |
898 | | |
899 | 7.92k | BITS_PARSE("chroma_loc_info_present_flag", ps_vui->u1_chroma_loc_info_present_flag, ps_bitstrm, 1); |
900 | 7.92k | ps_vui->u1_chroma_sample_loc_type_top_field = 0; |
901 | 7.92k | ps_vui->u1_chroma_sample_loc_type_bottom_field = 0; |
902 | 7.92k | if(ps_vui->u1_chroma_loc_info_present_flag) |
903 | 647 | { |
904 | 647 | UEV_PARSE("chroma_sample_loc_type_top_field", ps_vui->u1_chroma_sample_loc_type_top_field, ps_bitstrm); |
905 | 647 | if(ps_vui->u1_chroma_sample_loc_type_top_field > CHROMA_FMT_IDC_YUV444_PLANES + 1) |
906 | 35 | { |
907 | 35 | return IHEVCD_INVALID_PARAMETER; |
908 | 35 | } |
909 | 612 | UEV_PARSE("chroma_sample_loc_type_bottom_field", ps_vui->u1_chroma_sample_loc_type_bottom_field, ps_bitstrm); |
910 | 612 | if(ps_vui->u1_chroma_sample_loc_type_bottom_field > CHROMA_FMT_IDC_YUV444_PLANES + 1) |
911 | 30 | { |
912 | 30 | return IHEVCD_INVALID_PARAMETER; |
913 | 30 | } |
914 | 612 | } |
915 | | |
916 | 7.86k | BITS_PARSE("neutral_chroma_indication_flag", ps_vui->u1_neutral_chroma_indication_flag, ps_bitstrm, 1); |
917 | 7.86k | BITS_PARSE("field_seq_flag", ps_vui->u1_field_seq_flag, ps_bitstrm, 1); |
918 | 7.86k | BITS_PARSE("frame_field_info_present_flag", ps_vui->u1_frame_field_info_present_flag, ps_bitstrm, 1); |
919 | 7.86k | BITS_PARSE("default_display_window_flag", ps_vui->u1_default_display_window_flag, ps_bitstrm, 1); |
920 | 7.86k | ps_vui->u4_def_disp_win_left_offset = 0; |
921 | 7.86k | ps_vui->u4_def_disp_win_right_offset = 0; |
922 | 7.86k | ps_vui->u4_def_disp_win_top_offset = 0; |
923 | 7.86k | ps_vui->u4_def_disp_win_bottom_offset = 0; |
924 | 7.86k | if(ps_vui->u1_default_display_window_flag) |
925 | 740 | { |
926 | 740 | UEV_PARSE("def_disp_win_left_offset", ps_vui->u4_def_disp_win_left_offset, ps_bitstrm); |
927 | 740 | UEV_PARSE("def_disp_win_right_offset", ps_vui->u4_def_disp_win_right_offset, ps_bitstrm); |
928 | 740 | UEV_PARSE("def_disp_win_top_offset", ps_vui->u4_def_disp_win_top_offset, ps_bitstrm); |
929 | 740 | UEV_PARSE("def_disp_win_bottom_offset", ps_vui->u4_def_disp_win_bottom_offset, ps_bitstrm); |
930 | 740 | } |
931 | | |
932 | 7.86k | BITS_PARSE("vui_timing_info_present_flag", ps_vui->u1_vui_timing_info_present_flag, ps_bitstrm, 1); |
933 | 7.86k | if(ps_vui->u1_vui_timing_info_present_flag) |
934 | 1.95k | { |
935 | 1.95k | BITS_PARSE("vui_num_units_in_tick", ps_vui->u4_vui_num_units_in_tick, ps_bitstrm, 32); |
936 | 1.95k | BITS_PARSE("vui_time_scale", ps_vui->u4_vui_time_scale, ps_bitstrm, 32); |
937 | 1.95k | BITS_PARSE("vui_poc_proportional_to_timing_flag", ps_vui->u1_poc_proportional_to_timing_flag, ps_bitstrm, 1); |
938 | 1.95k | if(ps_vui->u1_poc_proportional_to_timing_flag) |
939 | 482 | { |
940 | 482 | UEV_PARSE("vui_num_ticks_poc_diff_one_minus1", ps_vui->u4_num_ticks_poc_diff_one_minus1, ps_bitstrm); |
941 | 482 | if(ps_vui->u4_num_ticks_poc_diff_one_minus1 > UINT_MAX - 1) |
942 | 0 | { |
943 | 0 | return IHEVCD_INVALID_PARAMETER; |
944 | 0 | } |
945 | 482 | } |
946 | 1.95k | BITS_PARSE("vui_hrd_parameters_present_flag", ps_vui->u1_vui_hrd_parameters_present_flag, ps_bitstrm, 1); |
947 | 1.95k | if(ps_vui->u1_vui_hrd_parameters_present_flag) |
948 | 465 | { |
949 | 465 | ret = ihevcd_parse_hrd_parameters(ps_bitstrm, &ps_vui->s_vui_hrd_parameters, 1, sps_max_sub_layers_minus1); |
950 | 465 | RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); |
951 | 356 | } |
952 | 1.95k | } |
953 | | |
954 | 7.75k | BITS_PARSE("bitstream_restriction_flag", ps_vui->u1_bitstream_restriction_flag, ps_bitstrm, 1); |
955 | 7.75k | ps_vui->u1_tiles_fixed_structure_flag = 0; |
956 | 7.75k | ps_vui->u1_motion_vectors_over_pic_boundaries_flag = 1; |
957 | 7.75k | ps_vui->u1_restricted_ref_pic_lists_flag = 0; |
958 | 7.75k | ps_vui->u4_min_spatial_segmentation_idc = 0; |
959 | 7.75k | ps_vui->u1_max_bytes_per_pic_denom = 2; |
960 | 7.75k | ps_vui->u1_max_bits_per_mincu_denom = 1; |
961 | 7.75k | ps_vui->u1_log2_max_mv_length_horizontal = 15; |
962 | 7.75k | ps_vui->u1_log2_max_mv_length_vertical = 15; |
963 | 7.75k | if(ps_vui->u1_bitstream_restriction_flag) |
964 | 632 | { |
965 | 632 | BITS_PARSE("tiles_fixed_structure_flag", ps_vui->u1_tiles_fixed_structure_flag, ps_bitstrm, 1); |
966 | 632 | BITS_PARSE("motion_vectors_over_pic_boundaries_flag", ps_vui->u1_motion_vectors_over_pic_boundaries_flag, ps_bitstrm, 1); |
967 | 632 | BITS_PARSE("restricted_ref_pic_lists_flag", ps_vui->u1_restricted_ref_pic_lists_flag, ps_bitstrm, 1); |
968 | | |
969 | 632 | UEV_PARSE("min_spatial_segmentation_idc", ps_vui->u4_min_spatial_segmentation_idc, ps_bitstrm); |
970 | 632 | if(ps_vui->u4_min_spatial_segmentation_idc > 4095) |
971 | 37 | { |
972 | 37 | return IHEVCD_INVALID_PARAMETER; |
973 | 37 | } |
974 | 595 | UEV_PARSE("max_bytes_per_pic_denom", ps_vui->u1_max_bytes_per_pic_denom, ps_bitstrm); |
975 | 595 | if(ps_vui->u1_max_bytes_per_pic_denom > 16) |
976 | 28 | { |
977 | 28 | return IHEVCD_INVALID_PARAMETER; |
978 | 28 | } |
979 | 567 | UEV_PARSE("max_bits_per_min_cu_denom", ps_vui->u1_max_bits_per_mincu_denom, ps_bitstrm); |
980 | 567 | if(ps_vui->u1_max_bits_per_mincu_denom > 16) |
981 | 35 | { |
982 | 35 | return IHEVCD_INVALID_PARAMETER; |
983 | 35 | } |
984 | 532 | UEV_PARSE("log2_max_mv_length_horizontal", ps_vui->u1_log2_max_mv_length_horizontal, ps_bitstrm); |
985 | 532 | if(ps_vui->u1_max_bits_per_mincu_denom > 16) |
986 | 0 | { |
987 | 0 | return IHEVCD_INVALID_PARAMETER; |
988 | 0 | } |
989 | 532 | UEV_PARSE("log2_max_mv_length_vertical", ps_vui->u1_log2_max_mv_length_vertical, ps_bitstrm); |
990 | 532 | if(ps_vui->u1_max_bits_per_mincu_denom > 15) |
991 | 21 | { |
992 | 21 | return IHEVCD_INVALID_PARAMETER; |
993 | 21 | } |
994 | 532 | } |
995 | | |
996 | 7.63k | return ret; |
997 | 7.75k | } |
998 | | |
999 | | static WORD32 ihevcd_get_profile(profile_tier_lvl_t *ps_ptl) |
1000 | 82.4k | { |
1001 | 82.4k | WORD32 profile = IHEVC_PROFILE_UNKNOWN; |
1002 | | |
1003 | 82.4k | if(ps_ptl->i1_profile_idc == 1 || ps_ptl->ai1_profile_compatibility_flag[1] == 1) |
1004 | 43.3k | profile = IHEVC_PROFILE_MAIN; |
1005 | 39.1k | else if(ps_ptl->i1_profile_idc == 3 || ps_ptl->ai1_profile_compatibility_flag[3] == 1) |
1006 | 6.35k | profile = IHEVC_PROFILE_MAIN_STILL; |
1007 | 32.7k | #ifdef ENABLE_MAIN_REXT_PROFILE |
1008 | 32.7k | else if(ps_ptl->i1_profile_idc == 4 || ps_ptl->ai1_profile_compatibility_flag[4] == 1) |
1009 | 6.37k | profile = IHEVC_PROFILE_MAIN_REXT; |
1010 | 82.4k | #endif |
1011 | | |
1012 | 82.4k | return profile; |
1013 | 82.4k | } |
1014 | | |
1015 | | /** |
1016 | | ******************************************************************************* |
1017 | | * |
1018 | | * @brief |
1019 | | * Parses profile tier and level info for either general layer of sub_layer |
1020 | | * |
1021 | | * @par Description |
1022 | | * Parses profile tier and level info for either general layer of sub_layer |
1023 | | * as per section 7.3.3 |
1024 | | * |
1025 | | * Since the same function is called for parsing general_profile and |
1026 | | * sub_layer_profile etc, variables do not specify whether the syntax is |
1027 | | * for general or sub_layer. Similarly trace functions also do not differentiate |
1028 | | * |
1029 | | * @param[in] ps_bitstrm |
1030 | | * Pointer to bitstream structure |
1031 | | * |
1032 | | * @param[out] ps_ptl |
1033 | | * Pointer to profile, tier level structure |
1034 | | * |
1035 | | * @returns Error code from IHEVCD_ERROR_T |
1036 | | * |
1037 | | * @remarks |
1038 | | * |
1039 | | ******************************************************************************* |
1040 | | */ |
1041 | | |
1042 | | static IHEVCD_ERROR_T ihevcd_parse_profile_tier_level_layer(bitstrm_t *ps_bitstrm, |
1043 | | profile_tier_lvl_t *ps_ptl) |
1044 | 77.2k | { |
1045 | 77.2k | WORD32 value; |
1046 | 77.2k | WORD32 i; |
1047 | 77.2k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
1048 | | |
1049 | 77.2k | BITS_PARSE("XXX_profile_space[]", value, ps_bitstrm, 2); |
1050 | 77.2k | ps_ptl->i1_profile_space = value; |
1051 | | |
1052 | 77.2k | BITS_PARSE("XXX_tier_flag[]", value, ps_bitstrm, 1); |
1053 | 77.2k | ps_ptl->i1_tier_flag = value; |
1054 | | |
1055 | 77.2k | BITS_PARSE("XXX_profile_idc[]", value, ps_bitstrm, 5); |
1056 | 77.2k | ps_ptl->i1_profile_idc = value; |
1057 | | |
1058 | 2.54M | for(i = 0; i < MAX_PROFILE_COMPATBLTY; i++) |
1059 | 2.47M | { |
1060 | 2.47M | BITS_PARSE("XXX_profile_compatibility_flag[][j]", value, ps_bitstrm, 1); |
1061 | 2.47M | ps_ptl->ai1_profile_compatibility_flag[i] = value; |
1062 | 2.47M | } |
1063 | | |
1064 | 77.2k | BITS_PARSE("general_progressive_source_flag", value, ps_bitstrm, 1); |
1065 | 77.2k | ps_ptl->i1_general_progressive_source_flag = value; |
1066 | | |
1067 | 77.2k | BITS_PARSE("general_interlaced_source_flag", value, ps_bitstrm, 1); |
1068 | 77.2k | ps_ptl->i1_general_interlaced_source_flag = value; |
1069 | | |
1070 | 77.2k | BITS_PARSE("general_non_packed_constraint_flag", value, ps_bitstrm, 1); |
1071 | 77.2k | ps_ptl->i1_general_non_packed_constraint_flag = value; |
1072 | | |
1073 | 77.2k | BITS_PARSE("general_frame_only_constraint_flag", value, ps_bitstrm, 1); |
1074 | 77.2k | ps_ptl->i1_frame_only_constraint_flag = value; |
1075 | | |
1076 | 77.2k | BITS_PARSE("XXX_reserved_zero_44bits[0..15]", value, ps_bitstrm, 16); |
1077 | | |
1078 | 77.2k | BITS_PARSE("XXX_reserved_zero_44bits[16..31]", value, ps_bitstrm, 16); |
1079 | | |
1080 | 77.2k | BITS_PARSE("XXX_reserved_zero_44bits[32..43]", value, ps_bitstrm, 12); |
1081 | 77.2k | return ret; |
1082 | 77.2k | } |
1083 | | |
1084 | | |
1085 | | /** |
1086 | | ******************************************************************************* |
1087 | | * |
1088 | | * @brief |
1089 | | * Parses profile tier and level info |
1090 | | * |
1091 | | * @par Description |
1092 | | * Parses profile tier and level info as per section 7.3.3 |
1093 | | * Called during VPS and SPS parsing |
1094 | | * calls ihevcd_parse_profile_tier_level() for general layer and each sub_layers |
1095 | | * |
1096 | | * @param[in] ps_bitstrm |
1097 | | * Pointer to bitstream structure |
1098 | | * |
1099 | | * @param[out] ps_ptl |
1100 | | * Pointer to structure that contains profile, tier level for each layers |
1101 | | * |
1102 | | * @param[in] profile_present |
1103 | | * Flag to indicate if profile data is present |
1104 | | * |
1105 | | * @param[in] max_num_sub_layers |
1106 | | * Number of sub layers present |
1107 | | * |
1108 | | * @returns Error code from IHEVCD_ERROR_T |
1109 | | * |
1110 | | * @remarks |
1111 | | * |
1112 | | ******************************************************************************* |
1113 | | */ |
1114 | | |
1115 | | static IHEVCD_ERROR_T ihevcd_profile_tier_level(bitstrm_t *ps_bitstrm, |
1116 | | profile_tier_lvl_info_t *ps_ptl, |
1117 | | WORD32 profile_present, |
1118 | | WORD32 max_num_sub_layers) |
1119 | 75.0k | { |
1120 | 75.0k | WORD32 value; |
1121 | 75.0k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
1122 | 75.0k | WORD32 i; |
1123 | | |
1124 | 75.0k | if(profile_present) |
1125 | 75.0k | { |
1126 | 75.0k | ret = ihevcd_parse_profile_tier_level_layer(ps_bitstrm, &ps_ptl->s_ptl_gen); |
1127 | 75.0k | if((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret) |
1128 | 0 | { |
1129 | 0 | return ret; |
1130 | 0 | } |
1131 | 75.0k | } |
1132 | | |
1133 | 75.0k | BITS_PARSE("general_level_idc", value, ps_bitstrm, 8); |
1134 | 75.0k | ps_ptl->s_ptl_gen.u1_level_idc = value; |
1135 | | |
1136 | | |
1137 | 99.2k | for(i = 0; i < max_num_sub_layers; i++) |
1138 | 24.1k | { |
1139 | 24.1k | BITS_PARSE("sub_layer_profile_present_flag[i]", value, ps_bitstrm, 1); |
1140 | 24.1k | ps_ptl->ai1_sub_layer_profile_present_flag[i] = value; |
1141 | | |
1142 | 24.1k | BITS_PARSE("sub_layer_level_present_flag[i]", value, ps_bitstrm, 1); |
1143 | 24.1k | ps_ptl->ai1_sub_layer_level_present_flag[i] = value; |
1144 | 24.1k | } |
1145 | | |
1146 | 75.0k | if(max_num_sub_layers > 0) |
1147 | 7.21k | { |
1148 | 40.7k | for(i = max_num_sub_layers; i < 8; i++) |
1149 | 33.5k | { |
1150 | 33.5k | BITS_PARSE("reserved_zero_2bits", value, ps_bitstrm, 2); |
1151 | 33.5k | } |
1152 | 7.21k | } |
1153 | | |
1154 | 99.2k | for(i = 0; i < max_num_sub_layers; i++) |
1155 | 24.1k | { |
1156 | 24.1k | if(ps_ptl->ai1_sub_layer_profile_present_flag[i]) |
1157 | 2.21k | { |
1158 | 2.21k | ret = ihevcd_parse_profile_tier_level_layer(ps_bitstrm, |
1159 | 2.21k | &ps_ptl->as_ptl_sub[i]); |
1160 | 2.21k | } |
1161 | 24.1k | if(ps_ptl->ai1_sub_layer_level_present_flag[i]) |
1162 | 2.91k | { |
1163 | 2.91k | BITS_PARSE("sub_layer_level_idc[i]", value, ps_bitstrm, 8); |
1164 | 2.91k | ps_ptl->as_ptl_sub[i].u1_level_idc = value; |
1165 | | |
1166 | 2.91k | } |
1167 | 24.1k | } |
1168 | | |
1169 | | |
1170 | | |
1171 | 75.0k | return ret; |
1172 | 75.0k | } |
1173 | | |
1174 | | /** |
1175 | | ******************************************************************************* |
1176 | | * |
1177 | | * @brief |
1178 | | * Parses Scaling List Data syntax |
1179 | | * |
1180 | | * @par Description: |
1181 | | * Parses Scaling List Data syntax as per Section: 7.3.6 |
1182 | | * |
1183 | | * @param[in] ps_codec |
1184 | | * Pointer to codec context |
1185 | | * |
1186 | | * @returns Error code from IHEVCD_ERROR_T |
1187 | | * |
1188 | | * @remarks |
1189 | | * |
1190 | | * |
1191 | | ******************************************************************************* |
1192 | | */ |
1193 | | IHEVCD_ERROR_T ihevcd_scaling_list_data(codec_t *ps_codec, WORD16 *pi2_scaling_mat, WORD8 chroma_format_idc) |
1194 | 13.8k | { |
1195 | 13.8k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
1196 | 13.8k | WORD32 size_id; |
1197 | 13.8k | WORD32 matrix_id; |
1198 | 13.8k | WORD32 value, dc_value = 0; |
1199 | 13.8k | UWORD32 u4_value; |
1200 | 13.8k | WORD32 next_coef; |
1201 | 13.8k | WORD32 coef_num; |
1202 | 13.8k | WORD32 i, j, k, offset; |
1203 | 13.8k | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
1204 | 13.8k | WORD16 *pi2_scaling_mat_offset; |
1205 | 13.8k | WORD32 scaling_mat_offset[] = {0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, |
1206 | 13.8k | 480, 736, 992, 1248, 1504, 1760, 2016, 3040, 4064, 5088, 6112, 7136}; |
1207 | 13.8k | UWORD8 *scan_table; |
1208 | | |
1209 | 19.7k | for(size_id = 0; size_id < 4; size_id++) |
1210 | 19.2k | { |
1211 | 56.2k | for(matrix_id = 0; matrix_id < 6; matrix_id += (size_id == 3) ? 3 : 1) |
1212 | 50.3k | { |
1213 | 50.3k | WORD32 scaling_list_pred_mode_flag; |
1214 | 50.3k | WORD32 scaling_list_delta_coef; |
1215 | 50.3k | BITS_PARSE("scaling_list_pred_mode_flag", scaling_list_pred_mode_flag, ps_bitstrm, 1); |
1216 | | |
1217 | 50.3k | offset = size_id * 6 + matrix_id; |
1218 | 50.3k | pi2_scaling_mat_offset = pi2_scaling_mat + scaling_mat_offset[offset]; |
1219 | | |
1220 | 50.3k | if(!scaling_list_pred_mode_flag) |
1221 | 38.8k | { |
1222 | 38.8k | WORD32 num_elements; |
1223 | 38.8k | UEV_PARSE("scaling_list_pred_matrix_id_delta", u4_value, |
1224 | 38.8k | ps_bitstrm); |
1225 | 38.8k | if(size_id <= 2) |
1226 | 38.3k | { |
1227 | 38.3k | if(u4_value > matrix_id) |
1228 | 11.0k | return IHEVCD_INVALID_PARAMETER; |
1229 | 38.3k | } |
1230 | 522 | else |
1231 | 522 | { |
1232 | 522 | if(u4_value > matrix_id / 3) |
1233 | 4 | return IHEVCD_INVALID_PARAMETER; |
1234 | 522 | } |
1235 | | |
1236 | 27.7k | num_elements = (1 << (4 + (size_id << 1))); |
1237 | 27.7k | if(0 != u4_value) |
1238 | 24.1k | { |
1239 | 24.1k | memmove(pi2_scaling_mat_offset, |
1240 | 24.1k | pi2_scaling_mat_offset - (u4_value * (size_id == 3 ? 3 : 1)) * num_elements, |
1241 | 24.1k | num_elements * sizeof(WORD16)); |
1242 | 24.1k | } |
1243 | 27.7k | } |
1244 | 11.4k | else |
1245 | 11.4k | { |
1246 | 11.4k | next_coef = 8; |
1247 | 11.4k | coef_num = MIN(64, (1 << (4 + (size_id << 1)))); |
1248 | | |
1249 | 11.4k | if(size_id > 1) |
1250 | 3.65k | { |
1251 | 3.65k | SEV_PARSE("scaling_list_dc_coef_minus8", value, |
1252 | 3.65k | ps_bitstrm); |
1253 | 3.65k | if(value < -7 || value > 247) |
1254 | 111 | { |
1255 | 111 | return IHEVCD_INVALID_PARAMETER; |
1256 | 111 | } |
1257 | 3.54k | next_coef = value + 8; |
1258 | 3.54k | dc_value = next_coef; |
1259 | 3.54k | } |
1260 | 11.3k | if(size_id < 2) |
1261 | 7.82k | { |
1262 | 7.82k | scan_table = (UWORD8 *)gapv_ihevc_invscan[size_id + 1]; |
1263 | | |
1264 | 258k | for(i = 0; i < coef_num; i++) |
1265 | 251k | { |
1266 | 251k | SEV_PARSE("scaling_list_delta_coef", |
1267 | 251k | scaling_list_delta_coef, ps_bitstrm); |
1268 | 251k | if((scaling_list_delta_coef < -256) || (scaling_list_delta_coef > 255)) |
1269 | 931 | { |
1270 | 931 | return IHEVCD_INVALID_PARAMETER; |
1271 | 931 | } |
1272 | 250k | next_coef = (next_coef + scaling_list_delta_coef + 256) |
1273 | 250k | % 256; |
1274 | 250k | pi2_scaling_mat_offset[scan_table[i]] = next_coef; |
1275 | 250k | } |
1276 | 7.82k | } |
1277 | 3.54k | else if(size_id == 2) |
1278 | 2.24k | { |
1279 | 2.24k | scan_table = (UWORD8 *)gapv_ihevc_invscan[2]; |
1280 | | |
1281 | 127k | for(i = 0; i < coef_num; i++) |
1282 | 125k | { |
1283 | 125k | SEV_PARSE("scaling_list_delta_coef", |
1284 | 125k | scaling_list_delta_coef, ps_bitstrm); |
1285 | 125k | if((scaling_list_delta_coef < -256) || (scaling_list_delta_coef > 255)) |
1286 | 463 | { |
1287 | 463 | return IHEVCD_INVALID_PARAMETER; |
1288 | 463 | } |
1289 | 124k | next_coef = (next_coef + scaling_list_delta_coef + 256) |
1290 | 124k | % 256; |
1291 | | |
1292 | 124k | offset = scan_table[i]; |
1293 | 124k | offset = (offset >> 3) * 16 * 2 + (offset & 0x7) * 2; |
1294 | 124k | pi2_scaling_mat_offset[offset] = next_coef; |
1295 | 124k | pi2_scaling_mat_offset[offset + 1] = next_coef; |
1296 | 124k | pi2_scaling_mat_offset[offset + 16] = next_coef; |
1297 | 124k | pi2_scaling_mat_offset[offset + 16 + 1] = next_coef; |
1298 | 124k | } |
1299 | 1.78k | pi2_scaling_mat_offset[0] = dc_value; |
1300 | 1.78k | } |
1301 | 1.29k | else |
1302 | 1.29k | { |
1303 | 1.29k | scan_table = (UWORD8 *)gapv_ihevc_invscan[2]; |
1304 | | |
1305 | 46.9k | for(i = 0; i < coef_num; i++) |
1306 | 46.4k | { |
1307 | 46.4k | SEV_PARSE("scaling_list_delta_coef", |
1308 | 46.4k | scaling_list_delta_coef, ps_bitstrm); |
1309 | 46.4k | if((scaling_list_delta_coef < -256) || (scaling_list_delta_coef > 255)) |
1310 | 758 | { |
1311 | 758 | return IHEVCD_INVALID_PARAMETER; |
1312 | 758 | } |
1313 | 45.6k | next_coef = (next_coef + scaling_list_delta_coef + 256) |
1314 | 45.6k | % 256; |
1315 | | |
1316 | 45.6k | offset = scan_table[i]; |
1317 | 45.6k | offset = (offset >> 3) * 32 * 4 + (offset & 0x7) * 4; |
1318 | | |
1319 | 228k | for(j = 0; j < 4; j++) |
1320 | 182k | { |
1321 | 182k | pi2_scaling_mat_offset[offset + j * 32] = next_coef; |
1322 | 182k | pi2_scaling_mat_offset[offset + 1 + j * 32] = next_coef; |
1323 | 182k | pi2_scaling_mat_offset[offset + 2 + j * 32] = next_coef; |
1324 | 182k | pi2_scaling_mat_offset[offset + 3 + j * 32] = next_coef; |
1325 | 182k | } |
1326 | 45.6k | pi2_scaling_mat_offset[0] = dc_value; |
1327 | 45.6k | } |
1328 | 1.29k | } |
1329 | 11.3k | } |
1330 | 50.3k | } |
1331 | 19.2k | } |
1332 | | // derive 32x32 CbCr scaling list from 16x16 CbCr scaling list |
1333 | 516 | if(chroma_format_idc == CHROMA_FMT_IDC_YUV444) |
1334 | 0 | { |
1335 | 0 | WORD32 matrix_ids[] = { 1, 2, 4, 5 }; |
1336 | 0 | WORD16 *pi2_ref_scaling_mat; |
1337 | |
|
1338 | 0 | scan_table = (UWORD8 *)gapv_ihevc_invscan[2]; |
1339 | 0 | for(i = 0; i < 4; i++) |
1340 | 0 | { |
1341 | 0 | matrix_id = matrix_ids[i]; |
1342 | 0 | pi2_ref_scaling_mat = pi2_scaling_mat + scaling_mat_offset[2 * 6 + matrix_id]; |
1343 | 0 | pi2_scaling_mat_offset = pi2_scaling_mat + scaling_mat_offset[3 * 6 + matrix_id]; |
1344 | |
|
1345 | 0 | for(j = 0; j < 64; j++) |
1346 | 0 | { |
1347 | 0 | offset = scan_table[j]; |
1348 | 0 | offset = (offset >> 3) * 16 * 2 + (offset & 0x7) * 2; |
1349 | | // the index 0 value may be overwritten by scaling_list_dc_coef. pick its alternative |
1350 | 0 | next_coef = offset == 0 ? pi2_ref_scaling_mat[1] : pi2_ref_scaling_mat[offset]; |
1351 | |
|
1352 | 0 | offset = scan_table[j]; |
1353 | 0 | offset = (offset >> 3) * 32 * 4 + (offset & 0x7) * 4; |
1354 | |
|
1355 | 0 | for(k = 0; k < 4; k++) |
1356 | 0 | { |
1357 | 0 | pi2_scaling_mat_offset[offset + k * 32] = next_coef; |
1358 | 0 | pi2_scaling_mat_offset[offset + 1 + k * 32] = next_coef; |
1359 | 0 | pi2_scaling_mat_offset[offset + 2 + k * 32] = next_coef; |
1360 | 0 | pi2_scaling_mat_offset[offset + 3 + k * 32] = next_coef; |
1361 | 0 | } |
1362 | 0 | } |
1363 | 0 | pi2_scaling_mat_offset[0] = pi2_ref_scaling_mat[0]; |
1364 | 0 | } |
1365 | 0 | } |
1366 | | |
1367 | 516 | return ret; |
1368 | 13.8k | } |
1369 | | |
1370 | | /** |
1371 | | ******************************************************************************* |
1372 | | * |
1373 | | * @brief |
1374 | | * Parses VPS (Video Parameter Set) |
1375 | | * |
1376 | | * @par Description: |
1377 | | * Parse Video Parameter Set as per Section 7.3.2.1 |
1378 | | * update vps structure corresponding to vps ID |
1379 | | * Till parsing VPS id, the elements are stored in local variables and are copied |
1380 | | * later |
1381 | | * |
1382 | | * @param[in] ps_codec |
1383 | | * Pointer to codec context. |
1384 | | * |
1385 | | * @returns Error code from IHEVCD_ERROR_T |
1386 | | * |
1387 | | * @remarks |
1388 | | * |
1389 | | * |
1390 | | ******************************************************************************* |
1391 | | */ |
1392 | | IHEVCD_ERROR_T ihevcd_parse_vps(codec_t *ps_codec) |
1393 | 0 | { |
1394 | 0 | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
1395 | 0 | WORD32 i; |
1396 | 0 | UWORD32 value; |
1397 | 0 | WORD32 vps_id; |
1398 | 0 | vps_t *ps_vps; |
1399 | 0 | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
1400 | 0 | BITS_PARSE("vps_video_parameter_set_id", value, ps_bitstrm, 4); |
1401 | 0 | vps_id = value; |
1402 | |
|
1403 | 0 | if(vps_id >= MAX_VPS_CNT) |
1404 | 0 | { |
1405 | 0 | ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_VPS_ID; |
1406 | 0 | return IHEVCD_UNSUPPORTED_VPS_ID; |
1407 | 0 | } |
1408 | | |
1409 | | |
1410 | 0 | ps_vps = (ps_codec->s_parse.ps_vps_base + vps_id); |
1411 | |
|
1412 | 0 | ps_vps->i1_vps_id = vps_id; |
1413 | |
|
1414 | 0 | BITS_PARSE("vps_reserved_three_2bits", value, ps_bitstrm, 2); |
1415 | 0 | ASSERT(value == 3); |
1416 | |
|
1417 | 0 | BITS_PARSE("vps_max_layers_minus1", value, ps_bitstrm, 6); |
1418 | | //ps_vps->i1_vps_max_layers = value + 1; |
1419 | | |
1420 | | |
1421 | |
|
1422 | 0 | BITS_PARSE("vps_max_sub_layers_minus1", value, ps_bitstrm, 3); |
1423 | 0 | if(value > SPS_MAX_SUB_LAYERS - 1) |
1424 | 0 | { |
1425 | 0 | return IHEVCD_INVALID_PARAMETER; |
1426 | 0 | } |
1427 | 0 | ps_vps->i1_vps_max_sub_layers = value + 1; |
1428 | |
|
1429 | 0 | ASSERT(ps_vps->i1_vps_max_sub_layers < VPS_MAX_SUB_LAYERS); |
1430 | |
|
1431 | 0 | BITS_PARSE("vps_temporal_id_nesting_flag", value, ps_bitstrm, 1); |
1432 | 0 | ps_vps->i1_vps_temporal_id_nesting_flag = value; |
1433 | |
|
1434 | 0 | BITS_PARSE("vps_reserved_ffff_16bits", value, ps_bitstrm, 16); |
1435 | 0 | ASSERT(value == 0xFFFF); |
1436 | | // profile_and_level( 1, vps_max_sub_layers_minus1 ) |
1437 | 0 | ret = ihevcd_profile_tier_level(ps_bitstrm, &(ps_vps->s_ptl), |
1438 | 0 | 1, (ps_vps->i1_vps_max_sub_layers - 1)); |
1439 | |
|
1440 | 0 | BITS_PARSE("vps_sub_layer_ordering_info_present_flag", value, ps_bitstrm, 1); |
1441 | 0 | ps_vps->i1_sub_layer_ordering_info_present_flag = value; |
1442 | 0 | i = (ps_vps->i1_sub_layer_ordering_info_present_flag ? |
1443 | 0 | 0 : (ps_vps->i1_vps_max_sub_layers - 1)); |
1444 | 0 | for(; i < ps_vps->i1_vps_max_sub_layers; i++) |
1445 | 0 | { |
1446 | 0 | UEV_PARSE("vps_max_dec_pic_buffering[i]", value, ps_bitstrm); |
1447 | 0 | if(value > MAX_DPB_SIZE) |
1448 | 0 | { |
1449 | 0 | return IHEVCD_INVALID_PARAMETER; |
1450 | 0 | } |
1451 | 0 | ps_vps->ai1_vps_max_dec_pic_buffering[i] = value; |
1452 | | |
1453 | | /* vps_num_reorder_pics (no max) used in print in order to match with HM */ |
1454 | 0 | UEV_PARSE("vps_num_reorder_pics[i]", value, ps_bitstrm); |
1455 | 0 | if(value >= ps_vps->ai1_vps_max_dec_pic_buffering[i]) |
1456 | 0 | { |
1457 | 0 | return IHEVCD_INVALID_PARAMETER; |
1458 | 0 | } |
1459 | 0 | ps_vps->ai1_vps_max_num_reorder_pics[i] = value; |
1460 | |
|
1461 | 0 | UEV_PARSE("vps_max_latency_increase[i]", value, ps_bitstrm); |
1462 | 0 | if(value > UINT_MAX - 2) |
1463 | 0 | { |
1464 | 0 | return IHEVCD_INVALID_PARAMETER; |
1465 | 0 | } |
1466 | 0 | ps_vps->ai1_vps_max_latency_increase[i] = value; |
1467 | 0 | } |
1468 | | |
1469 | | |
1470 | | |
1471 | 0 | BITS_PARSE("vps_max_layer_id", value, ps_bitstrm, 6); |
1472 | | //ps_vps->i1_vps_max_layer_id = value; |
1473 | |
|
1474 | 0 | UEV_PARSE("vps_num_layer_sets_minus1", value, ps_bitstrm); |
1475 | 0 | if(value > 1023) |
1476 | 0 | { |
1477 | 0 | return IHEVCD_INVALID_PARAMETER; |
1478 | 0 | } |
1479 | | //ps_vps->i1_vps_num_layer_sets = value + 1; |
1480 | | |
1481 | 0 | BITS_PARSE("vps_timing_info_present_flag", value, ps_bitstrm, 1); |
1482 | | //ps_vps->i1_vps_timing_info_present_flag = value; |
1483 | | |
1484 | | |
1485 | |
|
1486 | 0 | return ret; |
1487 | 0 | } |
1488 | | |
1489 | | /** |
1490 | | ******************************************************************************* |
1491 | | * |
1492 | | * @brief |
1493 | | * Parses SPS (Sequence Parameter Set) |
1494 | | * sequence_parameter_set_rbsp() |
1495 | | * |
1496 | | * @par Description: |
1497 | | * Parse Sequence Parameter Set as per section Section: 7.3.2.2 |
1498 | | * The sps is written to a temporary buffer and copied later to the |
1499 | | * appropriate location |
1500 | | * |
1501 | | * @param[in] ps_codec |
1502 | | * Pointer to codec context |
1503 | | * |
1504 | | * @returns Error code from IHEVCD_ERROR_T |
1505 | | * |
1506 | | * @remarks |
1507 | | * |
1508 | | * |
1509 | | ******************************************************************************* |
1510 | | */ |
1511 | | IHEVCD_ERROR_T ihevcd_parse_sps(codec_t *ps_codec) |
1512 | 75.5k | { |
1513 | 75.5k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
1514 | 75.5k | UWORD32 value; |
1515 | | |
1516 | 75.5k | WORD32 i; |
1517 | 75.5k | WORD32 vps_id; |
1518 | 75.5k | WORD32 sps_max_sub_layers; |
1519 | 75.5k | WORD32 sps_id; |
1520 | 75.5k | WORD32 sps_temporal_id_nesting_flag; |
1521 | 75.5k | sps_t *ps_sps; |
1522 | 75.5k | profile_tier_lvl_info_t s_ptl; |
1523 | 75.5k | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
1524 | 75.5k | WORD32 ctb_log2_size_y = 0; |
1525 | | |
1526 | | |
1527 | 75.5k | BITS_PARSE("video_parameter_set_id", value, ps_bitstrm, 4); |
1528 | 75.5k | if(value > MAX_VPS_CNT - 1) |
1529 | 0 | { |
1530 | 0 | return IHEVCD_INVALID_PARAMETER; |
1531 | 0 | } |
1532 | 75.5k | vps_id = value; |
1533 | | |
1534 | 75.5k | BITS_PARSE("sps_max_sub_layers_minus1", value, ps_bitstrm, 3); |
1535 | 75.5k | if(value > SPS_MAX_SUB_LAYERS - 1) |
1536 | 490 | { |
1537 | 490 | return IHEVCD_INVALID_PARAMETER; |
1538 | 490 | } |
1539 | 75.0k | sps_max_sub_layers = value + 1; |
1540 | | |
1541 | 75.0k | BITS_PARSE("sps_temporal_id_nesting_flag", value, ps_bitstrm, 1); |
1542 | 75.0k | sps_temporal_id_nesting_flag = value; |
1543 | | |
1544 | | //profile_and_level( 1, sps_max_sub_layers_minus1 ) |
1545 | 75.0k | ret = ihevcd_profile_tier_level(ps_bitstrm, &(s_ptl), 1, |
1546 | 75.0k | (sps_max_sub_layers - 1)); |
1547 | | |
1548 | 75.0k | UEV_PARSE("seq_parameter_set_id", value, ps_bitstrm); |
1549 | 75.0k | sps_id = value; |
1550 | 75.0k | if((sps_id >= MAX_SPS_CNT) || (sps_id < 0)) |
1551 | 26.7k | { |
1552 | 26.7k | if(ps_codec->i4_sps_done) |
1553 | 9.00k | return IHEVCD_UNSUPPORTED_SPS_ID; |
1554 | 17.7k | else |
1555 | 17.7k | sps_id = 0; |
1556 | 26.7k | } |
1557 | | |
1558 | | |
1559 | 66.0k | ps_sps = (ps_codec->s_parse.ps_sps_base + MAX_SPS_CNT - 1); |
1560 | | /* Reset SPS to zero */ |
1561 | 66.0k | { |
1562 | 66.0k | WORD16 *pi2_scaling_mat = ps_sps->pi2_scaling_mat; |
1563 | 66.0k | memset(ps_sps, 0, sizeof(sps_t)); |
1564 | 66.0k | ps_sps->pi2_scaling_mat = pi2_scaling_mat; |
1565 | 66.0k | } |
1566 | 66.0k | ps_sps->i1_sps_id = sps_id; |
1567 | 66.0k | ps_sps->i1_vps_id = vps_id; |
1568 | 66.0k | ps_sps->i1_sps_max_sub_layers = sps_max_sub_layers; |
1569 | 66.0k | ps_sps->i1_sps_temporal_id_nesting_flag = sps_temporal_id_nesting_flag; |
1570 | | |
1571 | 66.0k | memcpy(&ps_sps->s_ptl, &s_ptl, sizeof(profile_tier_lvl_info_t)); |
1572 | | |
1573 | 66.0k | UEV_PARSE("chroma_format_idc", value, ps_bitstrm); |
1574 | 66.0k | if(value > 3) |
1575 | 5.97k | { |
1576 | 5.97k | return IHEVCD_INVALID_PARAMETER; |
1577 | 5.97k | } |
1578 | | |
1579 | 60.0k | WORD32 profile = ihevcd_get_profile(&ps_sps->s_ptl.s_ptl_gen); |
1580 | 60.0k | if(profile == IHEVC_PROFILE_UNKNOWN) |
1581 | 26.4k | { |
1582 | 26.4k | return IHEVCD_UNSUPPORTED_TOOL_SET; |
1583 | 26.4k | } |
1584 | | |
1585 | 33.6k | switch(value) { |
1586 | 3.29k | case CHROMA_FMT_IDC_MONOCHROME: { |
1587 | 3.29k | if (!(ps_codec->u4_enable_yuv_formats & (1 << CHROMA_FMT_IDC_MONOCHROME))) { |
1588 | 1.28k | ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC; |
1589 | 1.28k | return (IHEVCD_ERROR_T)IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC; |
1590 | 1.28k | } |
1591 | 2.01k | if(profile != IHEVC_PROFILE_MAIN_REXT) |
1592 | 1.89k | return IHEVCD_INVALID_PARAMETER; |
1593 | 2.01k | } |
1594 | 120 | break; |
1595 | 29.7k | case CHROMA_FMT_IDC_YUV420: |
1596 | 29.7k | break; |
1597 | 645 | default: { |
1598 | 645 | ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC; |
1599 | 645 | return (IHEVCD_ERROR_T)IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC; |
1600 | 2.01k | } |
1601 | 0 | break; |
1602 | 33.6k | } |
1603 | 29.8k | ps_sps->i1_chroma_format_idc = value; |
1604 | | |
1605 | 29.8k | if(CHROMA_FMT_IDC_YUV444 == ps_sps->i1_chroma_format_idc) |
1606 | 0 | { |
1607 | 0 | BITS_PARSE("separate_colour_plane_flag", value, ps_bitstrm, 1); |
1608 | 0 | ps_sps->i1_separate_colour_plane_flag = value; |
1609 | 0 | } |
1610 | 29.8k | else |
1611 | 29.8k | { |
1612 | 29.8k | ps_sps->i1_separate_colour_plane_flag = 0; |
1613 | 29.8k | } |
1614 | | |
1615 | 29.8k | UEV_PARSE("pic_width_in_luma_samples", value, ps_bitstrm); |
1616 | 29.8k | if(value > INT16_MAX) |
1617 | 93 | { |
1618 | 93 | return (IHEVCD_ERROR_T)IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED; |
1619 | 93 | } |
1620 | 29.7k | ps_sps->i2_pic_width_in_luma_samples = value; |
1621 | | |
1622 | 29.7k | UEV_PARSE("pic_height_in_luma_samples", value, ps_bitstrm); |
1623 | 29.7k | if(value > INT16_MAX) |
1624 | 313 | { |
1625 | 313 | return (IHEVCD_ERROR_T)IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED; |
1626 | 313 | } |
1627 | 29.4k | ps_sps->i2_pic_height_in_luma_samples = value; |
1628 | | |
1629 | 29.4k | if((0 >= ps_sps->i2_pic_width_in_luma_samples) || (0 >= ps_sps->i2_pic_height_in_luma_samples)) |
1630 | 357 | return IHEVCD_INVALID_PARAMETER; |
1631 | | |
1632 | 29.0k | BITS_PARSE("pic_cropping_flag", value, ps_bitstrm, 1); |
1633 | 29.0k | ps_sps->i1_pic_cropping_flag = value; |
1634 | | |
1635 | 29.0k | if(ps_sps->i1_pic_cropping_flag) |
1636 | 23.6k | { |
1637 | | |
1638 | 23.6k | UEV_PARSE("pic_crop_left_offset", value, ps_bitstrm); |
1639 | 23.6k | if (value >= ps_sps->i2_pic_width_in_luma_samples) |
1640 | 10 | { |
1641 | 10 | return IHEVCD_INVALID_PARAMETER; |
1642 | 10 | } |
1643 | 23.6k | ps_sps->i2_pic_crop_left_offset = value; |
1644 | | |
1645 | 23.6k | UEV_PARSE("pic_crop_right_offset", value, ps_bitstrm); |
1646 | 23.6k | if (value >= ps_sps->i2_pic_width_in_luma_samples) |
1647 | 65 | { |
1648 | 65 | return IHEVCD_INVALID_PARAMETER; |
1649 | 65 | } |
1650 | 23.5k | ps_sps->i2_pic_crop_right_offset = value; |
1651 | | |
1652 | 23.5k | UEV_PARSE("pic_crop_top_offset", value, ps_bitstrm); |
1653 | 23.5k | if (value >= ps_sps->i2_pic_height_in_luma_samples) |
1654 | 140 | { |
1655 | 140 | return IHEVCD_INVALID_PARAMETER; |
1656 | 140 | } |
1657 | 23.4k | ps_sps->i2_pic_crop_top_offset = value; |
1658 | | |
1659 | 23.4k | UEV_PARSE("pic_crop_bottom_offset", value, ps_bitstrm); |
1660 | 23.4k | if (value >= ps_sps->i2_pic_height_in_luma_samples) |
1661 | 31 | { |
1662 | 31 | return IHEVCD_INVALID_PARAMETER; |
1663 | 31 | } |
1664 | 23.4k | ps_sps->i2_pic_crop_bottom_offset = value; |
1665 | 23.4k | } |
1666 | 5.41k | else |
1667 | 5.41k | { |
1668 | 5.41k | ps_sps->i2_pic_crop_left_offset = 0; |
1669 | 5.41k | ps_sps->i2_pic_crop_right_offset = 0; |
1670 | 5.41k | ps_sps->i2_pic_crop_top_offset = 0; |
1671 | 5.41k | ps_sps->i2_pic_crop_bottom_offset = 0; |
1672 | 5.41k | } |
1673 | | |
1674 | | |
1675 | 28.8k | UEV_PARSE("bit_depth_luma_minus8", value, ps_bitstrm); |
1676 | 28.8k | if(0 != value) |
1677 | 407 | return IHEVCD_UNSUPPORTED_BIT_DEPTH; |
1678 | | |
1679 | 28.4k | UEV_PARSE("bit_depth_chroma_minus8", value, ps_bitstrm); |
1680 | 28.4k | if(0 != value) |
1681 | 98 | return IHEVCD_UNSUPPORTED_BIT_DEPTH; |
1682 | | |
1683 | 28.3k | UEV_PARSE("log2_max_pic_order_cnt_lsb_minus4", value, ps_bitstrm); |
1684 | 28.3k | if(value > 12) |
1685 | 14 | return IHEVCD_INVALID_PARAMETER; |
1686 | 28.3k | ps_sps->i1_log2_max_pic_order_cnt_lsb = value + 4; |
1687 | | |
1688 | 28.3k | BITS_PARSE("sps_sub_layer_ordering_info_present_flag", value, ps_bitstrm, 1); |
1689 | | |
1690 | 28.3k | ps_sps->i1_sps_sub_layer_ordering_info_present_flag = value; |
1691 | | |
1692 | | |
1693 | 28.3k | i = (ps_sps->i1_sps_sub_layer_ordering_info_present_flag ? 0 : (ps_sps->i1_sps_max_sub_layers - 1)); |
1694 | 69.1k | for(; i < ps_sps->i1_sps_max_sub_layers; i++) |
1695 | 41.1k | { |
1696 | 41.1k | UEV_PARSE("max_dec_pic_buffering", value, ps_bitstrm); |
1697 | 41.1k | if(value > (MAX_DPB_SIZE - 1)) |
1698 | 88 | { |
1699 | 88 | return IHEVCD_INVALID_PARAMETER; |
1700 | 88 | } |
1701 | 41.0k | ps_sps->ai1_sps_max_dec_pic_buffering[i] = value + 1; |
1702 | | |
1703 | 41.0k | UEV_PARSE("num_reorder_pics", value, ps_bitstrm); |
1704 | 41.0k | if(value >= ps_sps->ai1_sps_max_dec_pic_buffering[i]) |
1705 | 218 | { |
1706 | 218 | return IHEVCD_INVALID_PARAMETER; |
1707 | 218 | } |
1708 | 40.8k | ps_sps->ai1_sps_max_num_reorder_pics[i] = value; |
1709 | | |
1710 | 40.8k | UEV_PARSE("max_latency_increase", value, ps_bitstrm); |
1711 | 40.8k | if(value > UINT_MAX - 2) |
1712 | 23 | { |
1713 | 23 | return IHEVCD_INVALID_PARAMETER; |
1714 | 23 | } |
1715 | 40.8k | ps_sps->ai1_sps_max_latency_increase[i] = value; |
1716 | 40.8k | } |
1717 | | |
1718 | | /* Check if sps_max_dec_pic_buffering or sps_max_num_reorder_pics |
1719 | | has changed */ |
1720 | 27.9k | if(0 != ps_codec->u4_allocate_dynamic_done) |
1721 | 16.6k | { |
1722 | 16.6k | sps_t *ps_sps_old = ps_codec->s_parse.ps_sps; |
1723 | 16.6k | if(ps_sps_old->ai1_sps_max_dec_pic_buffering[ps_sps_old->i1_sps_max_sub_layers - 1] != |
1724 | 16.6k | ps_sps->ai1_sps_max_dec_pic_buffering[ps_sps->i1_sps_max_sub_layers - 1]) |
1725 | 948 | { |
1726 | 948 | if(0 == ps_codec->i4_first_pic_done) |
1727 | 350 | { |
1728 | 350 | return IHEVCD_INVALID_PARAMETER; |
1729 | 350 | } |
1730 | 598 | ps_codec->i4_reset_flag = 1; |
1731 | 598 | return (IHEVCD_ERROR_T)IVD_RES_CHANGED; |
1732 | 948 | } |
1733 | | |
1734 | 15.6k | if(ps_sps_old->ai1_sps_max_num_reorder_pics[ps_sps_old->i1_sps_max_sub_layers - 1] != |
1735 | 15.6k | ps_sps->ai1_sps_max_num_reorder_pics[ps_sps->i1_sps_max_sub_layers - 1]) |
1736 | 212 | { |
1737 | 212 | if(0 == ps_codec->i4_first_pic_done) |
1738 | 11 | { |
1739 | 11 | return IHEVCD_INVALID_PARAMETER; |
1740 | 11 | } |
1741 | 201 | ps_codec->i4_reset_flag = 1; |
1742 | 201 | return (IHEVCD_ERROR_T)IVD_RES_CHANGED; |
1743 | 212 | } |
1744 | 15.6k | } |
1745 | | |
1746 | 26.8k | UEV_PARSE("log2_min_coding_block_size_minus3", value, ps_bitstrm); |
1747 | 26.8k | if(value > (LOG2_MAX_CU_SIZE - 3)) |
1748 | 105 | { |
1749 | 105 | return IHEVCD_INVALID_PARAMETER; |
1750 | 105 | } |
1751 | 26.7k | ps_sps->i1_log2_min_coding_block_size = value + 3; |
1752 | 26.7k | if((ps_sps->i2_pic_width_in_luma_samples % (1 << ps_sps->i1_log2_min_coding_block_size) != 0) || |
1753 | 26.6k | (ps_sps->i2_pic_height_in_luma_samples % (1 << ps_sps->i1_log2_min_coding_block_size) != 0)) |
1754 | 140 | { |
1755 | 140 | return IHEVCD_INVALID_PARAMETER; |
1756 | 140 | } |
1757 | | |
1758 | 26.5k | UEV_PARSE("log2_diff_max_min_coding_block_size", value, ps_bitstrm); |
1759 | 26.5k | if(value > (LOG2_MAX_CU_SIZE - ps_sps->i1_log2_min_coding_block_size)) |
1760 | 63 | { |
1761 | 63 | return IHEVCD_INVALID_PARAMETER; |
1762 | 63 | } |
1763 | 26.5k | ps_sps->i1_log2_diff_max_min_coding_block_size = value; |
1764 | | |
1765 | 26.5k | ctb_log2_size_y = ps_sps->i1_log2_min_coding_block_size + ps_sps->i1_log2_diff_max_min_coding_block_size; |
1766 | | |
1767 | 26.5k | if((ctb_log2_size_y < LOG2_MIN_CTB_SIZE) || (ctb_log2_size_y > LOG2_MAX_CTB_SIZE)) |
1768 | 96 | { |
1769 | 96 | return IHEVCD_INVALID_PARAMETER; |
1770 | 96 | } |
1771 | | /* Check if CTB size is different in case of multiple SPS with same ID */ |
1772 | 26.4k | { |
1773 | 26.4k | sps_t *ps_sps_old = (ps_codec->s_parse.ps_sps_base + sps_id); |
1774 | 26.4k | if(ps_sps_old->i1_sps_valid && ps_sps_old->i1_log2_ctb_size != ctb_log2_size_y) |
1775 | 183 | { |
1776 | 183 | if(0 == ps_codec->i4_first_pic_done) |
1777 | 26 | { |
1778 | 26 | return IHEVCD_INVALID_PARAMETER; |
1779 | 26 | } |
1780 | 157 | ps_codec->i4_reset_flag = 1; |
1781 | 157 | return (IHEVCD_ERROR_T)IVD_RES_CHANGED; |
1782 | 183 | } |
1783 | 26.4k | } |
1784 | 26.2k | ps_sps->i1_log2_ctb_size = ctb_log2_size_y; |
1785 | | |
1786 | 26.2k | UEV_PARSE("log2_min_transform_block_size_minus2", value, ps_bitstrm); |
1787 | 26.2k | if(value > (LOG2_MAX_TU_SIZE - 2)) |
1788 | 298 | { |
1789 | 298 | return IHEVCD_INVALID_PARAMETER; |
1790 | 298 | } |
1791 | 25.9k | ps_sps->i1_log2_min_transform_block_size = value + 2; |
1792 | 25.9k | if(ps_sps->i1_log2_min_transform_block_size >= ps_sps->i1_log2_min_coding_block_size) |
1793 | 43 | { |
1794 | 43 | return IHEVCD_INVALID_PARAMETER; |
1795 | 43 | } |
1796 | | |
1797 | 25.8k | UEV_PARSE("log2_diff_max_min_transform_block_size", value, ps_bitstrm); |
1798 | 25.8k | if(value > (LOG2_MAX_TU_SIZE - ps_sps->i1_log2_min_transform_block_size)) |
1799 | 38 | { |
1800 | 38 | return IHEVCD_INVALID_PARAMETER; |
1801 | 38 | } |
1802 | 25.8k | ps_sps->i1_log2_diff_max_min_transform_block_size = value; |
1803 | | |
1804 | 25.8k | ps_sps->i1_log2_max_transform_block_size = ps_sps->i1_log2_min_transform_block_size + |
1805 | 25.8k | ps_sps->i1_log2_diff_max_min_transform_block_size; |
1806 | | |
1807 | 25.8k | if(ps_sps->i1_log2_max_transform_block_size > ps_sps->i1_log2_ctb_size) |
1808 | 16 | { |
1809 | 16 | return IHEVCD_INVALID_PARAMETER; |
1810 | 16 | } |
1811 | | |
1812 | 25.8k | ps_sps->i1_log2_min_pcm_coding_block_size = 0; |
1813 | 25.8k | ps_sps->i1_log2_diff_max_min_pcm_coding_block_size = 0; |
1814 | | |
1815 | 25.8k | UEV_PARSE("max_transform_hierarchy_depth_inter", value, ps_bitstrm); |
1816 | 25.8k | if(value > (ps_sps->i1_log2_ctb_size - ps_sps->i1_log2_min_transform_block_size)) |
1817 | 54 | { |
1818 | 54 | return IHEVCD_INVALID_PARAMETER; |
1819 | 54 | } |
1820 | 25.7k | ps_sps->i1_max_transform_hierarchy_depth_inter = value; |
1821 | | |
1822 | 25.7k | UEV_PARSE("max_transform_hierarchy_depth_intra", value, ps_bitstrm); |
1823 | 25.7k | if(value > (ps_sps->i1_log2_ctb_size - ps_sps->i1_log2_min_transform_block_size)) |
1824 | 58 | { |
1825 | 58 | return IHEVCD_INVALID_PARAMETER; |
1826 | 58 | } |
1827 | 25.7k | ps_sps->i1_max_transform_hierarchy_depth_intra = value; |
1828 | | |
1829 | | /* String has a d (enabled) in order to match with HM */ |
1830 | 25.7k | BITS_PARSE("scaling_list_enabled_flag", value, ps_bitstrm, 1); |
1831 | 25.7k | ps_sps->i1_scaling_list_enable_flag = value; |
1832 | | |
1833 | 25.7k | if(ps_sps->i1_scaling_list_enable_flag) |
1834 | 7.86k | { |
1835 | 7.86k | COPY_DEFAULT_SCALING_LIST(ps_sps->pi2_scaling_mat); |
1836 | 7.86k | BITS_PARSE("sps_scaling_list_data_present_flag", value, ps_bitstrm, 1); |
1837 | 7.86k | ps_sps->i1_sps_scaling_list_data_present_flag = value; |
1838 | | |
1839 | 7.86k | if(ps_sps->i1_sps_scaling_list_data_present_flag) |
1840 | 2.64k | ihevcd_scaling_list_data(ps_codec, ps_sps->pi2_scaling_mat, ps_sps->i1_chroma_format_idc); |
1841 | 7.86k | } |
1842 | 17.8k | else |
1843 | 17.8k | { |
1844 | 17.8k | COPY_FLAT_SCALING_LIST(ps_sps->pi2_scaling_mat); |
1845 | 17.8k | } |
1846 | | /* String is asymmetric_motion_partitions_enabled_flag instead of amp_enabled_flag in order to match with HM */ |
1847 | 25.7k | BITS_PARSE("asymmetric_motion_partitions_enabled_flag", value, ps_bitstrm, 1); |
1848 | 25.7k | ps_sps->i1_amp_enabled_flag = value; |
1849 | | |
1850 | 25.7k | BITS_PARSE("sample_adaptive_offset_enabled_flag", value, ps_bitstrm, 1); |
1851 | 25.7k | ps_sps->i1_sample_adaptive_offset_enabled_flag = value; |
1852 | | |
1853 | 25.7k | BITS_PARSE("pcm_enabled_flag", value, ps_bitstrm, 1); |
1854 | 25.7k | ps_sps->i1_pcm_enabled_flag = value; |
1855 | | |
1856 | 25.7k | if(ps_sps->i1_pcm_enabled_flag) |
1857 | 13.7k | { |
1858 | 13.7k | BITS_PARSE("pcm_sample_bit_depth_luma", value, ps_bitstrm, 4); |
1859 | 13.7k | ps_sps->i1_pcm_sample_bit_depth_luma = value + 1; |
1860 | | |
1861 | 13.7k | BITS_PARSE("pcm_sample_bit_depth_chroma", value, ps_bitstrm, 4); |
1862 | 13.7k | ps_sps->i1_pcm_sample_bit_depth_chroma = value + 1; |
1863 | | |
1864 | 13.7k | UEV_PARSE("log2_min_pcm_coding_block_size_minus3", value, ps_bitstrm); |
1865 | 13.7k | if(value < (ps_sps->i1_log2_min_coding_block_size - 3) || value > (MIN(ctb_log2_size_y, 5) - 3)) |
1866 | 141 | { |
1867 | 141 | return IHEVCD_INVALID_PARAMETER; |
1868 | 141 | } |
1869 | 13.6k | ps_sps->i1_log2_min_pcm_coding_block_size = value + 3; |
1870 | | |
1871 | 13.6k | UEV_PARSE("log2_diff_max_min_pcm_coding_block_size", value, ps_bitstrm); |
1872 | 13.6k | if(value > MIN(ctb_log2_size_y, 5) - ps_sps->i1_log2_min_pcm_coding_block_size) |
1873 | 60 | { |
1874 | 60 | return IHEVCD_INVALID_PARAMETER; |
1875 | 60 | } |
1876 | 13.5k | ps_sps->i1_log2_diff_max_min_pcm_coding_block_size = value; |
1877 | 13.5k | BITS_PARSE("pcm_loop_filter_disable_flag", value, ps_bitstrm, 1); |
1878 | 13.5k | ps_sps->i1_pcm_loop_filter_disable_flag = value; |
1879 | | |
1880 | 13.5k | } |
1881 | 25.5k | UEV_PARSE("num_short_term_ref_pic_sets", value, ps_bitstrm); |
1882 | 25.5k | if(value > MAX_STREF_PICS_SPS) |
1883 | 243 | { |
1884 | 243 | return IHEVCD_INVALID_PARAMETER; |
1885 | 243 | } |
1886 | 25.2k | ps_sps->i1_num_short_term_ref_pic_sets = value; |
1887 | | |
1888 | 57.7k | for(i = 0; i < ps_sps->i1_num_short_term_ref_pic_sets; i++) |
1889 | 32.9k | { |
1890 | 32.9k | ret = ihevcd_short_term_ref_pic_set(ps_bitstrm, &ps_sps->as_stref_picset[0], ps_sps->i1_num_short_term_ref_pic_sets, i, &ps_sps->as_stref_picset[i]); |
1891 | 32.9k | if (ret != IHEVCD_SUCCESS) |
1892 | 453 | { |
1893 | 453 | return ret; |
1894 | 453 | } |
1895 | 32.9k | } |
1896 | | |
1897 | 24.8k | BITS_PARSE("long_term_ref_pics_present_flag", value, ps_bitstrm, 1); |
1898 | 24.8k | ps_sps->i1_long_term_ref_pics_present_flag = value; |
1899 | | |
1900 | 24.8k | if(ps_sps->i1_long_term_ref_pics_present_flag) |
1901 | 4.36k | { |
1902 | 4.36k | UEV_PARSE("num_long_term_ref_pics_sps", value, ps_bitstrm); |
1903 | 4.36k | if(value > MAX_LTREF_PICS_SPS) |
1904 | 144 | { |
1905 | 144 | return IHEVCD_INVALID_PARAMETER; |
1906 | 144 | } |
1907 | 4.21k | ps_sps->i1_num_long_term_ref_pics_sps = value; |
1908 | | |
1909 | 7.05k | for(i = 0; i < ps_sps->i1_num_long_term_ref_pics_sps; i++) |
1910 | 2.83k | { |
1911 | 2.83k | BITS_PARSE("lt_ref_pic_poc_lsb_sps[ i ]", value, ps_bitstrm, ps_sps->i1_log2_max_pic_order_cnt_lsb); |
1912 | 2.83k | ps_sps->au2_lt_ref_pic_poc_lsb_sps[i] = value; |
1913 | | |
1914 | 2.83k | BITS_PARSE("used_by_curr_pic_lt_sps_flag[ i ]", value, ps_bitstrm, 1); |
1915 | 2.83k | ps_sps->ai1_used_by_curr_pic_lt_sps_flag[i] = value; |
1916 | 2.83k | } |
1917 | 4.21k | } |
1918 | | |
1919 | 24.6k | BITS_PARSE("sps_temporal_mvp_enable_flag", value, ps_bitstrm, 1); |
1920 | 24.6k | ps_sps->i1_sps_temporal_mvp_enable_flag = value; |
1921 | | |
1922 | | /* Print matches HM 8-2 */ |
1923 | 24.6k | BITS_PARSE("sps_strong_intra_smoothing_enable_flag", value, ps_bitstrm, 1); |
1924 | 24.6k | ps_sps->i1_strong_intra_smoothing_enable_flag = value; |
1925 | | |
1926 | 24.6k | BITS_PARSE("vui_parameters_present_flag", value, ps_bitstrm, 1); |
1927 | 24.6k | ps_sps->i1_vui_parameters_present_flag = value; |
1928 | | |
1929 | 24.6k | if(ps_sps->i1_vui_parameters_present_flag) |
1930 | 7.92k | { |
1931 | 7.92k | ret = ihevcd_parse_vui_parameters(ps_bitstrm, |
1932 | 7.92k | &ps_sps->s_vui_parameters, |
1933 | 7.92k | ps_sps->i1_sps_max_sub_layers - 1); |
1934 | 7.92k | RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); |
1935 | | |
1936 | 7.63k | if (0 != ps_codec->u4_allocate_dynamic_done) { |
1937 | | |
1938 | 3.85k | vui_t *ps_vui = &ps_sps->s_vui_parameters; |
1939 | 3.85k | sps_t *ps_sps_old = ps_codec->s_parse.ps_sps; |
1940 | 3.85k | vui_t *ps_vui_old = &ps_sps_old->s_vui_parameters; |
1941 | | |
1942 | 3.85k | if (ps_vui->u1_video_full_range_flag != ps_vui_old->u1_video_full_range_flag || |
1943 | 3.58k | ps_vui->u1_colour_primaries != ps_vui_old->u1_colour_primaries || |
1944 | 2.72k | ps_vui->u1_transfer_characteristics != ps_vui_old->u1_transfer_characteristics || |
1945 | 2.64k | ps_vui->u1_matrix_coefficients != ps_vui_old->u1_matrix_coefficients) { |
1946 | 1.29k | ps_codec->i4_reset_flag = 1; |
1947 | 1.29k | return (IHEVCD_ERROR_T)IVD_RES_CHANGED; |
1948 | 1.29k | } |
1949 | 3.85k | } |
1950 | 7.63k | } |
1951 | | |
1952 | 23.1k | BITS_PARSE("sps_extension_present_flag", value, ps_bitstrm, 1); |
1953 | 23.1k | ps_sps->i1_sps_extension_present_flag = value; |
1954 | | |
1955 | 23.1k | if(ps_sps->i1_sps_extension_present_flag) |
1956 | 618 | { |
1957 | 618 | BITS_PARSE("sps_range_extension_flag", value, ps_bitstrm, 1); |
1958 | 618 | ps_sps->i1_sps_range_extension_flag = value; |
1959 | | |
1960 | 618 | BITS_PARSE("sps_multilayer_extension_flag", value, ps_bitstrm, 1); |
1961 | 618 | ps_sps->i1_sps_multilayer_extension_flag = value; |
1962 | | |
1963 | 618 | BITS_PARSE("sps_3d_extension_flag", value, ps_bitstrm, 1); |
1964 | 618 | ps_sps->i1_sps_3d_extension_flag = value; |
1965 | | |
1966 | 618 | BITS_PARSE("sps_scc_extension_flag", value, ps_bitstrm, 1); |
1967 | 618 | ps_sps->i1_sps_scc_extension_flag = value; |
1968 | | |
1969 | 618 | BITS_PARSE("sps_extension_4bits", value, ps_bitstrm, 4); |
1970 | 618 | ps_sps->i1_sps_extension_4bits = value; |
1971 | 618 | } |
1972 | | |
1973 | 23.1k | #ifdef ENABLE_MAIN_REXT_PROFILE |
1974 | 23.1k | if(ps_sps->i1_sps_range_extension_flag) |
1975 | 295 | { |
1976 | | /* ITU-T H.265 Section 7.3.2.2.2 Range extension sequence parameter set syntax */ |
1977 | 295 | BITS_PARSE("transform_skip_rotation_enabled_flag", value, ps_bitstrm, 1); |
1978 | 295 | ps_sps->i1_transform_skip_rotation_enabled_flag = value; |
1979 | | |
1980 | 295 | BITS_PARSE("transform_skip_context_enabled_flag", value, ps_bitstrm, 1); |
1981 | 295 | ps_sps->i1_transform_skip_context_enabled_flag = value; |
1982 | | |
1983 | 295 | BITS_PARSE("implicit_rdpcm_enabled_flag", value, ps_bitstrm, 1); |
1984 | 295 | ps_sps->i1_implicit_rdpcm_enabled_flag = value; |
1985 | | |
1986 | 295 | BITS_PARSE("explicit_rdpcm_enabled_flag", value, ps_bitstrm, 1); |
1987 | 295 | ps_sps->i1_explicit_rdpcm_enabled_flag = value; |
1988 | | |
1989 | 295 | BITS_PARSE("extended_precision_processing_flag", value, ps_bitstrm, 1); |
1990 | 295 | ps_sps->i1_extended_precision_processing_flag = value; |
1991 | | |
1992 | 295 | BITS_PARSE("intra_smoothing_disabled_flag", value, ps_bitstrm, 1); |
1993 | 295 | ps_sps->i1_intra_smoothing_disabled_flag = value; |
1994 | | |
1995 | 295 | BITS_PARSE("high_precision_offsets_enabled_flag", value, ps_bitstrm, 1); |
1996 | 295 | ps_sps->i1_use_high_precision_pred_wt = value; |
1997 | | |
1998 | 295 | BITS_PARSE("persistent_rice_adaptation_enabled_flag", value, ps_bitstrm, 1); |
1999 | 295 | ps_sps->i1_persistent_rice_adaptation_enabled_flag = value; |
2000 | | |
2001 | 295 | BITS_PARSE("cabac_bypass_alignment_enabled_flag", value, ps_bitstrm, 1); |
2002 | 295 | ps_sps->i1_align_cabac_before_bypass = value; |
2003 | 295 | } |
2004 | 23.1k | if(profile != IHEVC_PROFILE_MAIN_REXT) |
2005 | 19.9k | { |
2006 | 19.9k | if(ps_sps->i1_transform_skip_rotation_enabled_flag |
2007 | 19.7k | || ps_sps->i1_transform_skip_context_enabled_flag |
2008 | 19.7k | || ps_sps->i1_implicit_rdpcm_enabled_flag |
2009 | 19.7k | || ps_sps->i1_explicit_rdpcm_enabled_flag |
2010 | 19.7k | || ps_sps->i1_extended_precision_processing_flag |
2011 | 19.7k | || ps_sps->i1_intra_smoothing_disabled_flag |
2012 | 19.7k | || ps_sps->i1_persistent_rice_adaptation_enabled_flag |
2013 | 19.7k | || ps_sps->i1_align_cabac_before_bypass) |
2014 | 252 | { |
2015 | 252 | return IHEVCD_INVALID_PARAMETER; |
2016 | 252 | } |
2017 | 19.9k | } |
2018 | 22.8k | if(ps_sps->i1_extended_precision_processing_flag || ps_sps->i1_align_cabac_before_bypass) |
2019 | 14 | { |
2020 | | // main-rext 8-bit profiles require these fields to be off |
2021 | 14 | return IHEVCD_INVALID_PARAMETER; |
2022 | 14 | } |
2023 | 22.8k | if(ps_sps->i1_sps_multilayer_extension_flag || ps_sps->i1_sps_3d_extension_flag |
2024 | 22.7k | || ps_sps->i1_sps_scc_extension_flag) |
2025 | 106 | { |
2026 | 106 | return IHEVCD_UNSUPPORTED_TOOL_SET; |
2027 | 106 | } |
2028 | | #else |
2029 | | if(ps_sps->i1_sps_range_extension_flag || ps_sps->i1_sps_multilayer_extension_flag |
2030 | | || ps_sps->i1_sps_3d_extension_flag || ps_sps->i1_sps_scc_extension_flag) |
2031 | | { |
2032 | | // TODO: add support for parsing these syntax elements |
2033 | | return IHEVCD_UNSUPPORTED_TOOL_SET; |
2034 | | } |
2035 | | #endif |
2036 | | |
2037 | 22.7k | if((UWORD8 *)ps_bitstrm->pu4_buf > ps_bitstrm->pu1_buf_max) |
2038 | 569 | { |
2039 | 569 | return IHEVCD_INVALID_PARAMETER; |
2040 | 569 | } |
2041 | | |
2042 | 22.1k | { |
2043 | 22.1k | WORD32 numerator; |
2044 | 22.1k | WORD32 ceil_offset; |
2045 | | |
2046 | 22.1k | ceil_offset = (1 << ps_sps->i1_log2_ctb_size) - 1; |
2047 | 22.1k | numerator = ps_sps->i2_pic_width_in_luma_samples; |
2048 | | |
2049 | 22.1k | ps_sps->i2_pic_wd_in_ctb = ((numerator + ceil_offset) / |
2050 | 22.1k | (1 << ps_sps->i1_log2_ctb_size)); |
2051 | | |
2052 | 22.1k | numerator = ps_sps->i2_pic_height_in_luma_samples; |
2053 | 22.1k | ps_sps->i2_pic_ht_in_ctb = ((numerator + ceil_offset) / |
2054 | 22.1k | (1 << ps_sps->i1_log2_ctb_size)); |
2055 | | |
2056 | 22.1k | ps_sps->i4_pic_size_in_ctb = ps_sps->i2_pic_ht_in_ctb * |
2057 | 22.1k | ps_sps->i2_pic_wd_in_ctb; |
2058 | | |
2059 | 22.1k | if(0 == ps_codec->i4_sps_done) |
2060 | 8.65k | ps_codec->s_parse.i4_next_ctb_indx = ps_sps->i4_pic_size_in_ctb; |
2061 | | |
2062 | 22.1k | numerator = ps_sps->i2_pic_width_in_luma_samples; |
2063 | 22.1k | ps_sps->i2_pic_wd_in_min_cb = numerator / |
2064 | 22.1k | (1 << ps_sps->i1_log2_min_coding_block_size); |
2065 | | |
2066 | 22.1k | numerator = ps_sps->i2_pic_height_in_luma_samples; |
2067 | 22.1k | ps_sps->i2_pic_ht_in_min_cb = numerator / |
2068 | 22.1k | (1 << ps_sps->i1_log2_min_coding_block_size); |
2069 | 22.1k | } |
2070 | 22.1k | if((0 != ps_codec->u4_allocate_dynamic_done) && |
2071 | 13.5k | ((ps_codec->i4_wd != ps_sps->i2_pic_width_in_luma_samples) || |
2072 | 13.4k | (ps_codec->i4_ht != ps_sps->i2_pic_height_in_luma_samples))) |
2073 | 211 | { |
2074 | 211 | if(0 == ps_codec->i4_first_pic_done) |
2075 | 161 | { |
2076 | 161 | return IHEVCD_INVALID_PARAMETER; |
2077 | 161 | } |
2078 | 50 | ps_codec->i4_reset_flag = 1; |
2079 | 50 | return (IHEVCD_ERROR_T)IVD_RES_CHANGED; |
2080 | 211 | } |
2081 | | |
2082 | | // Ensure both i2_pic_width_in_luma_samples and i2_pic_height_in_luma_samples do |
2083 | | // not exceed MAX_WD and their product doesn't exceed MAX_WD * MAX_HT |
2084 | 21.9k | if((ps_sps->i2_pic_width_in_luma_samples > MAX_WD) || |
2085 | 21.9k | (ps_sps->i2_pic_height_in_luma_samples > MAX_WD) || |
2086 | 21.8k | ((ps_sps->i2_pic_width_in_luma_samples * ps_sps->i2_pic_height_in_luma_samples) > |
2087 | 21.8k | (MAX_WD * MAX_HT))) |
2088 | 94 | { |
2089 | 94 | return (IHEVCD_ERROR_T)IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED; |
2090 | 94 | } |
2091 | | |
2092 | | // limit format conversions |
2093 | 21.8k | if(ps_codec->e_chroma_fmt == IV_YUV_444P |
2094 | 0 | && ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_YUV444) |
2095 | 0 | { |
2096 | 0 | return (IHEVCD_ERROR_T)IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED; |
2097 | 0 | } |
2098 | 21.8k | if(ps_codec->e_chroma_fmt == IV_YUV_422P |
2099 | 0 | && ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_YUV422) |
2100 | 0 | { |
2101 | 0 | return (IHEVCD_ERROR_T)IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED; |
2102 | 0 | } |
2103 | 21.8k | if((ps_codec->e_chroma_fmt == IV_YUV_420SP_UV || ps_codec->e_chroma_fmt == IV_YUV_420SP_VU) |
2104 | 10.7k | && ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_YUV420) |
2105 | 0 | { |
2106 | 0 | return (IHEVCD_ERROR_T)IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED; |
2107 | 0 | } |
2108 | | |
2109 | | /* Update display width and display height */ |
2110 | 21.8k | { |
2111 | 21.8k | WORD32 disp_wd, disp_ht; |
2112 | 21.8k | WORD32 crop_unit_x, crop_unit_y; |
2113 | 21.8k | crop_unit_x = 1; |
2114 | 21.8k | crop_unit_y = 1; |
2115 | | |
2116 | 21.8k | if(CHROMA_FMT_IDC_YUV420 == ps_sps->i1_chroma_format_idc) |
2117 | 21.8k | { |
2118 | 21.8k | crop_unit_x = 2; |
2119 | 21.8k | crop_unit_y = 2; |
2120 | 21.8k | } |
2121 | 0 | else if(CHROMA_FMT_IDC_YUV422 == ps_sps->i1_chroma_format_idc) |
2122 | 0 | { |
2123 | 0 | crop_unit_x = 2; |
2124 | 0 | crop_unit_y = 1; |
2125 | 0 | } |
2126 | | |
2127 | 21.8k | disp_wd = ps_sps->i2_pic_width_in_luma_samples; |
2128 | 21.8k | disp_wd -= ps_sps->i2_pic_crop_left_offset * crop_unit_x; |
2129 | 21.8k | disp_wd -= ps_sps->i2_pic_crop_right_offset * crop_unit_x; |
2130 | | |
2131 | | |
2132 | 21.8k | disp_ht = ps_sps->i2_pic_height_in_luma_samples; |
2133 | 21.8k | disp_ht -= ps_sps->i2_pic_crop_top_offset * crop_unit_y; |
2134 | 21.8k | disp_ht -= ps_sps->i2_pic_crop_bottom_offset * crop_unit_y; |
2135 | | |
2136 | 21.8k | if((0 >= disp_wd) || (0 >= disp_ht)) |
2137 | 172 | return IHEVCD_INVALID_PARAMETER; |
2138 | | |
2139 | 21.6k | if((0 != ps_codec->u4_allocate_dynamic_done) && |
2140 | 13.2k | ((ps_codec->i4_disp_wd != disp_wd) || |
2141 | 13.1k | (ps_codec->i4_disp_ht != disp_ht))) |
2142 | 665 | { |
2143 | 665 | if(0 == ps_codec->i4_first_pic_done) |
2144 | 121 | { |
2145 | 121 | return IHEVCD_INVALID_PARAMETER; |
2146 | 121 | } |
2147 | 544 | ps_codec->i4_reset_flag = 1; |
2148 | 544 | return (IHEVCD_ERROR_T)IVD_RES_CHANGED; |
2149 | 665 | } |
2150 | | |
2151 | 21.0k | ps_codec->i4_disp_wd = disp_wd; |
2152 | 21.0k | ps_codec->i4_disp_ht = disp_ht; |
2153 | | |
2154 | | |
2155 | 21.0k | ps_codec->i4_wd = ps_sps->i2_pic_width_in_luma_samples; |
2156 | 21.0k | ps_codec->i4_ht = ps_sps->i2_pic_height_in_luma_samples; |
2157 | 21.0k | ps_codec->u4_num_8x8_blks = ALIGN64(ps_codec->i4_wd) * ALIGN64(ps_codec->i4_ht) >> 6; |
2158 | | |
2159 | 21.0k | { |
2160 | 21.0k | WORD32 ref_strd; |
2161 | 21.0k | ref_strd = ALIGN32(ps_sps->i2_pic_width_in_luma_samples + PAD_WD); |
2162 | 21.0k | if(ps_codec->i4_strd < ref_strd) |
2163 | 8.39k | { |
2164 | 8.39k | ps_codec->i4_strd = ref_strd; |
2165 | 8.39k | } |
2166 | 21.0k | } |
2167 | | |
2168 | 21.0k | if(0 == ps_codec->i4_share_disp_buf) |
2169 | 21.0k | { |
2170 | 21.0k | if(ps_codec->i4_disp_strd < ps_codec->i4_disp_wd) |
2171 | 8.39k | { |
2172 | 8.39k | ps_codec->i4_disp_strd = ps_codec->i4_disp_wd; |
2173 | 8.39k | } |
2174 | 21.0k | } |
2175 | 0 | else |
2176 | 0 | { |
2177 | 0 | if(ps_codec->i4_disp_strd < ps_codec->i4_strd) |
2178 | 0 | { |
2179 | 0 | ps_codec->i4_disp_strd = ps_codec->i4_strd; |
2180 | 0 | } |
2181 | 0 | } |
2182 | 21.0k | } |
2183 | | |
2184 | | /* This is used only during initialization to get reorder count etc */ |
2185 | 0 | ps_codec->i4_sps_id = sps_id; |
2186 | | |
2187 | 21.0k | ps_codec->i4_sps_done = 1; |
2188 | 21.0k | return ret; |
2189 | 21.6k | } |
2190 | | |
2191 | | |
2192 | | void ihevcd_unmark_pps(codec_t *ps_codec, WORD32 sps_id) |
2193 | 0 | { |
2194 | 0 | WORD32 pps_id = 0; |
2195 | 0 | pps_t *ps_pps = ps_codec->ps_pps_base; |
2196 | |
|
2197 | 0 | for(pps_id = 0; pps_id < MAX_PPS_CNT - 1; pps_id++, ps_pps++) |
2198 | 0 | { |
2199 | 0 | if((ps_pps->i1_pps_valid) && |
2200 | 0 | (ps_pps->i1_sps_id == sps_id)) |
2201 | 0 | ps_pps->i1_pps_valid = 0; |
2202 | 0 | } |
2203 | 0 | } |
2204 | | |
2205 | | |
2206 | | void ihevcd_copy_sps(codec_t *ps_codec, WORD32 sps_id, WORD32 sps_id_ref) |
2207 | 21.0k | { |
2208 | 21.0k | sps_t *ps_sps, *ps_sps_ref; |
2209 | 21.0k | WORD16 *pi2_scaling_mat_backup; |
2210 | 21.0k | WORD32 scaling_mat_size; |
2211 | | |
2212 | 21.0k | SCALING_MAT_SIZE(scaling_mat_size); |
2213 | 21.0k | ps_sps_ref = ps_codec->ps_sps_base + sps_id_ref; |
2214 | 21.0k | ps_sps = ps_codec->ps_sps_base + sps_id; |
2215 | | |
2216 | 21.0k | if(ps_sps->i1_sps_valid) |
2217 | 12.6k | { |
2218 | 12.6k | if((ps_sps->i1_log2_ctb_size != ps_sps_ref->i1_log2_ctb_size) || |
2219 | 12.6k | (ps_sps->i2_pic_wd_in_ctb != ps_sps_ref->i2_pic_wd_in_ctb) || |
2220 | 12.6k | (ps_sps->i2_pic_ht_in_ctb != ps_sps_ref->i2_pic_ht_in_ctb)) |
2221 | 0 | { |
2222 | 0 | ihevcd_unmark_pps(ps_codec, sps_id); |
2223 | 0 | } |
2224 | 12.6k | } |
2225 | | |
2226 | 21.0k | pi2_scaling_mat_backup = ps_sps->pi2_scaling_mat; |
2227 | | |
2228 | 21.0k | memcpy(ps_sps, ps_sps_ref, sizeof(sps_t)); |
2229 | 21.0k | ps_sps->pi2_scaling_mat = pi2_scaling_mat_backup; |
2230 | 21.0k | memcpy(ps_sps->pi2_scaling_mat, ps_sps_ref->pi2_scaling_mat, scaling_mat_size * sizeof(WORD16)); |
2231 | 21.0k | ps_sps->i1_sps_valid = 1; |
2232 | | |
2233 | 21.0k | ps_codec->s_parse.ps_sps = ps_sps; |
2234 | 21.0k | } |
2235 | | |
2236 | | |
2237 | | /** |
2238 | | ******************************************************************************* |
2239 | | * |
2240 | | * @brief |
2241 | | * Parses PPS (Picture Parameter Set) |
2242 | | * |
2243 | | * @par Description: |
2244 | | * Parse Picture Parameter Set as per section Section: 7.3.2.3 |
2245 | | * The pps is written to a temporary buffer and copied later to the |
2246 | | * appropriate location |
2247 | | * |
2248 | | * @param[in] ps_codec |
2249 | | * Pointer to codec context |
2250 | | * |
2251 | | * @returns Error code from IHEVCD_ERROR_T |
2252 | | * |
2253 | | * @remarks |
2254 | | * |
2255 | | * |
2256 | | ******************************************************************************* |
2257 | | */ |
2258 | | IHEVCD_ERROR_T ihevcd_parse_pps(codec_t *ps_codec) |
2259 | 44.6k | { |
2260 | 44.6k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
2261 | 44.6k | UWORD32 value; |
2262 | 44.6k | WORD32 i4_value; |
2263 | 44.6k | WORD32 pps_id; |
2264 | | |
2265 | 44.6k | pps_t *ps_pps; |
2266 | 44.6k | sps_t *ps_sps; |
2267 | 44.6k | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
2268 | | |
2269 | | |
2270 | 44.6k | if(0 == ps_codec->i4_sps_done) |
2271 | 15.7k | return IHEVCD_INVALID_HEADER; |
2272 | | |
2273 | 28.9k | UEV_PARSE("pic_parameter_set_id", value, ps_bitstrm); |
2274 | | |
2275 | 28.9k | pps_id = value; |
2276 | 28.9k | if((pps_id >= MAX_PPS_CNT) || (pps_id < 0)) |
2277 | 3.49k | { |
2278 | 3.49k | if(ps_codec->i4_pps_done) |
2279 | 663 | return IHEVCD_UNSUPPORTED_PPS_ID; |
2280 | 2.83k | else |
2281 | 2.83k | pps_id = 0; |
2282 | 3.49k | } |
2283 | | |
2284 | | |
2285 | 28.2k | ps_pps = (ps_codec->s_parse.ps_pps_base + MAX_PPS_CNT - 1); |
2286 | | |
2287 | 28.2k | ps_pps->i1_pps_id = pps_id; |
2288 | | |
2289 | 28.2k | UEV_PARSE("seq_parameter_set_id", value, ps_bitstrm); |
2290 | 28.2k | if(value > MAX_SPS_CNT - 2) |
2291 | 534 | { |
2292 | 534 | return IHEVCD_INVALID_PARAMETER; |
2293 | 534 | } |
2294 | 27.7k | ps_pps->i1_sps_id = value; |
2295 | | |
2296 | 27.7k | ps_sps = (ps_codec->s_parse.ps_sps_base + ps_pps->i1_sps_id); |
2297 | | |
2298 | | /* If the SPS that is being referred to has not been parsed, |
2299 | | * copy an existing SPS to the current location */ |
2300 | 27.7k | if(0 == ps_sps->i1_sps_valid) |
2301 | 1.94k | { |
2302 | 1.94k | return IHEVCD_INVALID_HEADER; |
2303 | | |
2304 | | /* |
2305 | | sps_t *ps_sps_ref = ps_codec->ps_sps_base; |
2306 | | while(0 == ps_sps_ref->i1_sps_valid) |
2307 | | ps_sps_ref++; |
2308 | | ihevcd_copy_sps(ps_codec, ps_pps->i1_sps_id, ps_sps_ref->i1_sps_id); |
2309 | | */ |
2310 | 1.94k | } |
2311 | | |
2312 | 25.7k | BITS_PARSE("dependent_slices_enabled_flag", value, ps_bitstrm, 1); |
2313 | 25.7k | ps_pps->i1_dependent_slice_enabled_flag = value; |
2314 | | |
2315 | 25.7k | BITS_PARSE("output_flag_present_flag", value, ps_bitstrm, 1); |
2316 | 25.7k | ps_pps->i1_output_flag_present_flag = value; |
2317 | | |
2318 | 25.7k | BITS_PARSE("num_extra_slice_header_bits", value, ps_bitstrm, 3); |
2319 | 25.7k | ps_pps->i1_num_extra_slice_header_bits = value; |
2320 | | |
2321 | | |
2322 | 25.7k | BITS_PARSE("sign_data_hiding_flag", value, ps_bitstrm, 1); |
2323 | 25.7k | ps_pps->i1_sign_data_hiding_flag = value; |
2324 | | |
2325 | 25.7k | BITS_PARSE("cabac_init_present_flag", value, ps_bitstrm, 1); |
2326 | 25.7k | ps_pps->i1_cabac_init_present_flag = value; |
2327 | | |
2328 | 25.7k | UEV_PARSE("num_ref_idx_l0_default_active_minus1", value, ps_bitstrm); |
2329 | 25.7k | if(value > MAX_DPB_SIZE - 2) |
2330 | 189 | { |
2331 | 189 | return IHEVCD_INVALID_PARAMETER; |
2332 | 189 | } |
2333 | 25.5k | ps_pps->i1_num_ref_idx_l0_default_active = value + 1; |
2334 | | |
2335 | 25.5k | UEV_PARSE("num_ref_idx_l1_default_active_minus1", value, ps_bitstrm); |
2336 | 25.5k | if(value > MAX_DPB_SIZE - 2) |
2337 | 166 | { |
2338 | 166 | return IHEVCD_INVALID_PARAMETER; |
2339 | 166 | } |
2340 | 25.4k | ps_pps->i1_num_ref_idx_l1_default_active = value + 1; |
2341 | | |
2342 | 25.4k | SEV_PARSE("pic_init_qp_minus26", i4_value, ps_bitstrm); |
2343 | 25.4k | if(i4_value < -26 || i4_value > 25) |
2344 | 220 | { |
2345 | 220 | return IHEVCD_INVALID_PARAMETER; |
2346 | 220 | } |
2347 | 25.1k | ps_pps->i1_pic_init_qp = i4_value + 26; |
2348 | | |
2349 | 25.1k | BITS_PARSE("constrained_intra_pred_flag", value, ps_bitstrm, 1); |
2350 | 25.1k | ps_pps->i1_constrained_intra_pred_flag = value; |
2351 | | |
2352 | 25.1k | BITS_PARSE("transform_skip_enabled_flag", value, ps_bitstrm, 1); |
2353 | 25.1k | ps_pps->i1_transform_skip_enabled_flag = value; |
2354 | | |
2355 | 25.1k | BITS_PARSE("cu_qp_delta_enabled_flag", value, ps_bitstrm, 1); |
2356 | 25.1k | ps_pps->i1_cu_qp_delta_enabled_flag = value; |
2357 | | |
2358 | 25.1k | if(ps_pps->i1_cu_qp_delta_enabled_flag) |
2359 | 8.33k | { |
2360 | 8.33k | UEV_PARSE("diff_cu_qp_delta_depth", value, ps_bitstrm); |
2361 | 8.33k | if(value > ps_sps->i1_log2_diff_max_min_coding_block_size) |
2362 | 448 | { |
2363 | 448 | return IHEVCD_INVALID_PARAMETER; |
2364 | 448 | } |
2365 | 7.88k | ps_pps->i1_diff_cu_qp_delta_depth = value; |
2366 | 7.88k | } |
2367 | 16.8k | else |
2368 | 16.8k | { |
2369 | 16.8k | ps_pps->i1_diff_cu_qp_delta_depth = 0; |
2370 | 16.8k | } |
2371 | 24.7k | ps_pps->i1_log2_min_cu_qp_delta_size = ps_sps->i1_log2_ctb_size - ps_pps->i1_diff_cu_qp_delta_depth; |
2372 | | /* Print different */ |
2373 | 24.7k | SEV_PARSE("cb_qp_offset", i4_value, ps_bitstrm); |
2374 | 24.7k | if(i4_value < -12 || i4_value > 12) |
2375 | 233 | { |
2376 | 233 | return IHEVCD_INVALID_PARAMETER; |
2377 | 233 | } |
2378 | 24.5k | ps_pps->i1_pic_cb_qp_offset = i4_value; |
2379 | | |
2380 | | /* Print different */ |
2381 | 24.5k | SEV_PARSE("cr_qp_offset", i4_value, ps_bitstrm); |
2382 | 24.5k | if(i4_value < -12 || i4_value > 12) |
2383 | 183 | { |
2384 | 183 | return IHEVCD_INVALID_PARAMETER; |
2385 | 183 | } |
2386 | 24.3k | ps_pps->i1_pic_cr_qp_offset = i4_value; |
2387 | | |
2388 | | /* Print different */ |
2389 | 24.3k | BITS_PARSE("slicelevel_chroma_qp_flag", value, ps_bitstrm, 1); |
2390 | 24.3k | ps_pps->i1_pic_slice_level_chroma_qp_offsets_present_flag = value; |
2391 | | |
2392 | 24.3k | BITS_PARSE("weighted_pred_flag", value, ps_bitstrm, 1); |
2393 | 24.3k | ps_pps->i1_weighted_pred_flag = value; |
2394 | | |
2395 | 24.3k | BITS_PARSE("weighted_bipred_flag", value, ps_bitstrm, 1); |
2396 | 24.3k | ps_pps->i1_weighted_bipred_flag = value; |
2397 | | |
2398 | 24.3k | BITS_PARSE("transquant_bypass_enable_flag", value, ps_bitstrm, 1); |
2399 | 24.3k | ps_pps->i1_transquant_bypass_enable_flag = value; |
2400 | | |
2401 | 24.3k | BITS_PARSE("tiles_enabled_flag", value, ps_bitstrm, 1); |
2402 | 24.3k | ps_pps->i1_tiles_enabled_flag = value; |
2403 | | |
2404 | | /* When tiles are enabled and width or height is >= 4096, |
2405 | | * CTB Size should at least be 32 while if width or height is >= 8192, |
2406 | | * CTB Size should at least be 64 and so on. 16x16 CTBs can result |
2407 | | * in tile position greater than 255 for 4096 while 32x32 CTBs can result |
2408 | | * in tile position greater than 255 for 8192, |
2409 | | * which decoder does not support. |
2410 | | */ |
2411 | 24.3k | if (ps_pps->i1_tiles_enabled_flag) |
2412 | 5.26k | { |
2413 | 5.26k | if((ps_sps->i1_log2_ctb_size == 4) && |
2414 | 731 | ((ps_sps->i2_pic_width_in_luma_samples >= 4096) || |
2415 | 683 | (ps_sps->i2_pic_height_in_luma_samples >= 4096))) |
2416 | 200 | { |
2417 | 200 | return IHEVCD_INVALID_HEADER; |
2418 | 200 | } |
2419 | 5.06k | if((ps_sps->i1_log2_ctb_size == 5) && |
2420 | 1.65k | ((ps_sps->i2_pic_width_in_luma_samples >= 8192) || |
2421 | 1.57k | (ps_sps->i2_pic_height_in_luma_samples >= 8192))) |
2422 | 147 | { |
2423 | 147 | return IHEVCD_INVALID_HEADER; |
2424 | 147 | } |
2425 | 4.91k | if((ps_sps->i1_log2_ctb_size == 6) && |
2426 | 2.88k | ((ps_sps->i2_pic_width_in_luma_samples >= 16384) || |
2427 | 2.88k | (ps_sps->i2_pic_height_in_luma_samples >= 16384))) |
2428 | 0 | { |
2429 | 0 | return IHEVCD_INVALID_HEADER; |
2430 | 0 | } |
2431 | 4.91k | } |
2432 | | |
2433 | 23.9k | BITS_PARSE("entropy_coding_sync_enabled_flag", value, ps_bitstrm, 1); |
2434 | 23.9k | ps_pps->i1_entropy_coding_sync_enabled_flag = value; |
2435 | | |
2436 | 23.9k | ps_pps->i1_loop_filter_across_tiles_enabled_flag = 0; |
2437 | 23.9k | if(ps_pps->i1_tiles_enabled_flag) |
2438 | 4.91k | { |
2439 | 4.91k | WORD32 wd = ALIGN64(ps_codec->i4_wd); |
2440 | 4.91k | WORD32 ht = ALIGN64(ps_codec->i4_ht); |
2441 | | |
2442 | 4.91k | WORD32 max_tile_cols = (wd + MIN_TILE_WD - 1) / MIN_TILE_WD; |
2443 | 4.91k | WORD32 max_tile_rows = (ht + MIN_TILE_HT - 1) / MIN_TILE_HT; |
2444 | | |
2445 | 4.91k | UEV_PARSE("num_tile_columns_minus1", value, ps_bitstrm); |
2446 | 4.91k | ps_pps->i1_num_tile_columns = value + 1; |
2447 | | |
2448 | 4.91k | UEV_PARSE("num_tile_rows_minus1", value, ps_bitstrm); |
2449 | 4.91k | ps_pps->i1_num_tile_rows = value + 1; |
2450 | | |
2451 | 4.91k | if((ps_pps->i1_num_tile_columns < 1) || |
2452 | 4.81k | (ps_pps->i1_num_tile_columns > max_tile_cols) || |
2453 | 4.67k | (ps_pps->i1_num_tile_rows < 1) || |
2454 | 4.59k | (ps_pps->i1_num_tile_rows > max_tile_rows)) |
2455 | 476 | return IHEVCD_INVALID_HEADER; |
2456 | | |
2457 | 4.44k | BITS_PARSE("uniform_spacing_flag", value, ps_bitstrm, 1); |
2458 | 4.44k | ps_pps->i1_uniform_spacing_flag = value; |
2459 | | |
2460 | | |
2461 | 4.44k | { |
2462 | | |
2463 | 4.44k | UWORD32 start; |
2464 | 4.44k | WORD32 i, j; |
2465 | | |
2466 | | |
2467 | 4.44k | start = 0; |
2468 | 13.3k | for(i = 0; i < ps_pps->i1_num_tile_columns; i++) |
2469 | 9.08k | { |
2470 | 9.08k | tile_t *ps_tile; |
2471 | 9.08k | if(!ps_pps->i1_uniform_spacing_flag) |
2472 | 6.44k | { |
2473 | 6.44k | if(i < (ps_pps->i1_num_tile_columns - 1)) |
2474 | 3.47k | { |
2475 | 3.47k | UEV_PARSE("column_width_minus1[ i ]", value, ps_bitstrm); |
2476 | 3.47k | value += 1; |
2477 | 3.47k | if (value >= ps_sps->i2_pic_wd_in_ctb - start) |
2478 | 142 | { |
2479 | 142 | return IHEVCD_INVALID_HEADER; |
2480 | 142 | } |
2481 | 3.47k | } |
2482 | 2.97k | else |
2483 | 2.97k | { |
2484 | 2.97k | value = ps_sps->i2_pic_wd_in_ctb - start; |
2485 | 2.97k | } |
2486 | 6.44k | } |
2487 | 2.63k | else |
2488 | 2.63k | { |
2489 | 2.63k | value = ((i + 1) * ps_sps->i2_pic_wd_in_ctb) / ps_pps->i1_num_tile_columns - |
2490 | 2.63k | (i * ps_sps->i2_pic_wd_in_ctb) / ps_pps->i1_num_tile_columns; |
2491 | 2.63k | } |
2492 | | |
2493 | 33.6k | for(j = 0; j < ps_pps->i1_num_tile_rows; j++) |
2494 | 24.7k | { |
2495 | 24.7k | ps_tile = ps_pps->ps_tile + j * ps_pps->i1_num_tile_columns + i; |
2496 | 24.7k | ps_tile->u1_pos_x = start; |
2497 | 24.7k | ps_tile->u2_wd = value; |
2498 | 24.7k | } |
2499 | 8.94k | start += value; |
2500 | | |
2501 | 8.94k | if((start > ps_sps->i2_pic_wd_in_ctb) || |
2502 | 8.94k | (value == 0)) |
2503 | 0 | return IHEVCD_INVALID_HEADER; |
2504 | 8.94k | } |
2505 | | |
2506 | 4.29k | start = 0; |
2507 | 18.6k | for(i = 0; i < (ps_pps->i1_num_tile_rows); i++) |
2508 | 14.4k | { |
2509 | 14.4k | tile_t *ps_tile; |
2510 | 14.4k | if(!ps_pps->i1_uniform_spacing_flag) |
2511 | 5.45k | { |
2512 | 5.45k | if(i < (ps_pps->i1_num_tile_rows - 1)) |
2513 | 2.56k | { |
2514 | | |
2515 | 2.56k | UEV_PARSE("row_height_minus1[ i ]", value, ps_bitstrm); |
2516 | 2.56k | value += 1; |
2517 | 2.56k | if (value >= ps_sps->i2_pic_ht_in_ctb - start) |
2518 | 92 | { |
2519 | 92 | return IHEVCD_INVALID_HEADER; |
2520 | 92 | } |
2521 | 2.56k | } |
2522 | 2.88k | else |
2523 | 2.88k | { |
2524 | 2.88k | value = ps_sps->i2_pic_ht_in_ctb - start; |
2525 | 2.88k | } |
2526 | 5.45k | } |
2527 | 9.01k | else |
2528 | 9.01k | { |
2529 | 9.01k | value = ((i + 1) * ps_sps->i2_pic_ht_in_ctb) / ps_pps->i1_num_tile_rows - |
2530 | 9.01k | (i * ps_sps->i2_pic_ht_in_ctb) / ps_pps->i1_num_tile_rows; |
2531 | 9.01k | } |
2532 | | |
2533 | 37.5k | for(j = 0; j < ps_pps->i1_num_tile_columns; j++) |
2534 | 23.1k | { |
2535 | 23.1k | ps_tile = ps_pps->ps_tile + i * ps_pps->i1_num_tile_columns + j; |
2536 | 23.1k | ps_tile->u1_pos_y = start; |
2537 | 23.1k | ps_tile->u2_ht = value; |
2538 | 23.1k | } |
2539 | 14.3k | start += value; |
2540 | | |
2541 | 14.3k | if((start > ps_sps->i2_pic_ht_in_ctb) || |
2542 | 14.3k | (value == 0)) |
2543 | 0 | return IHEVCD_INVALID_HEADER; |
2544 | 14.3k | } |
2545 | 4.29k | } |
2546 | | |
2547 | | |
2548 | 4.20k | BITS_PARSE("loop_filter_across_tiles_enabled_flag", value, ps_bitstrm, 1); |
2549 | 4.20k | ps_pps->i1_loop_filter_across_tiles_enabled_flag = value; |
2550 | | |
2551 | 4.20k | } |
2552 | 19.0k | else |
2553 | 19.0k | { |
2554 | | /* If tiles are not present, set first tile in each PPS to have tile |
2555 | | width and height equal to picture width and height */ |
2556 | 19.0k | ps_pps->i1_num_tile_columns = 1; |
2557 | 19.0k | ps_pps->i1_num_tile_rows = 1; |
2558 | 19.0k | ps_pps->i1_uniform_spacing_flag = 1; |
2559 | | |
2560 | 19.0k | ps_pps->ps_tile->u1_pos_x = 0; |
2561 | 19.0k | ps_pps->ps_tile->u1_pos_y = 0; |
2562 | 19.0k | ps_pps->ps_tile->u2_wd = ps_sps->i2_pic_wd_in_ctb; |
2563 | 19.0k | ps_pps->ps_tile->u2_ht = ps_sps->i2_pic_ht_in_ctb; |
2564 | 19.0k | } |
2565 | | |
2566 | 23.2k | BITS_PARSE("loop_filter_across_slices_enabled_flag", value, ps_bitstrm, 1); |
2567 | 23.2k | ps_pps->i1_loop_filter_across_slices_enabled_flag = value; |
2568 | | |
2569 | 23.2k | BITS_PARSE("deblocking_filter_control_present_flag", value, ps_bitstrm, 1); |
2570 | 23.2k | ps_pps->i1_deblocking_filter_control_present_flag = value; |
2571 | | |
2572 | | /* Default values */ |
2573 | 23.2k | ps_pps->i1_pic_disable_deblocking_filter_flag = 0; |
2574 | 23.2k | ps_pps->i1_deblocking_filter_override_enabled_flag = 0; |
2575 | 23.2k | ps_pps->i1_beta_offset_div2 = 0; |
2576 | 23.2k | ps_pps->i1_tc_offset_div2 = 0; |
2577 | | |
2578 | 23.2k | if(ps_pps->i1_deblocking_filter_control_present_flag) |
2579 | 2.99k | { |
2580 | | |
2581 | 2.99k | BITS_PARSE("deblocking_filter_override_enabled_flag", value, ps_bitstrm, 1); |
2582 | 2.99k | ps_pps->i1_deblocking_filter_override_enabled_flag = value; |
2583 | | |
2584 | 2.99k | BITS_PARSE("pic_disable_deblocking_filter_flag", value, ps_bitstrm, 1); |
2585 | 2.99k | ps_pps->i1_pic_disable_deblocking_filter_flag = value; |
2586 | | |
2587 | 2.99k | if(!ps_pps->i1_pic_disable_deblocking_filter_flag) |
2588 | 1.28k | { |
2589 | | |
2590 | 1.28k | SEV_PARSE("pps_beta_offset_div2", i4_value, ps_bitstrm); |
2591 | 1.28k | if(i4_value < -6 || i4_value > 6) |
2592 | 219 | { |
2593 | 219 | return IHEVCD_INVALID_PARAMETER; |
2594 | 219 | } |
2595 | 1.06k | ps_pps->i1_beta_offset_div2 = i4_value; |
2596 | | |
2597 | 1.06k | SEV_PARSE("pps_tc_offset_div2", i4_value, ps_bitstrm); |
2598 | 1.06k | if(i4_value < -6 || i4_value > 6) |
2599 | 105 | { |
2600 | 105 | return IHEVCD_INVALID_PARAMETER; |
2601 | 105 | } |
2602 | 962 | ps_pps->i1_tc_offset_div2 = i4_value; |
2603 | | |
2604 | 962 | } |
2605 | 2.99k | } |
2606 | | |
2607 | 22.9k | BITS_PARSE("pps_scaling_list_data_present_flag", value, ps_bitstrm, 1); |
2608 | 22.9k | ps_pps->i1_pps_scaling_list_data_present_flag = value; |
2609 | | |
2610 | 22.9k | if(ps_pps->i1_pps_scaling_list_data_present_flag) |
2611 | 11.2k | { |
2612 | 11.2k | COPY_DEFAULT_SCALING_LIST(ps_pps->pi2_scaling_mat); |
2613 | 11.2k | ihevcd_scaling_list_data(ps_codec, ps_pps->pi2_scaling_mat, ps_sps->i1_chroma_format_idc); |
2614 | 11.2k | } |
2615 | | |
2616 | 22.9k | BITS_PARSE("lists_modification_present_flag", value, ps_bitstrm, 1); |
2617 | 22.9k | ps_pps->i1_lists_modification_present_flag = value; |
2618 | 22.9k | UEV_PARSE("log2_parallel_merge_level_minus2", value, ps_bitstrm); |
2619 | 22.9k | if(value > (ps_sps->i1_log2_min_coding_block_size + ps_sps->i1_log2_diff_max_min_coding_block_size)) |
2620 | 533 | { |
2621 | 533 | return IHEVCD_INVALID_PARAMETER; |
2622 | 533 | } |
2623 | 22.4k | ps_pps->i1_log2_parallel_merge_level = value + 2; |
2624 | | |
2625 | 22.4k | BITS_PARSE("slice_header_extension_present_flag", value, ps_bitstrm, 1); |
2626 | 22.4k | ps_pps->i1_slice_header_extension_present_flag = value; |
2627 | | |
2628 | 22.4k | BITS_PARSE("pps_extension_present_flag", value, ps_bitstrm, 1); |
2629 | 22.4k | ps_pps->i1_pps_extension_present_flag = value; |
2630 | | |
2631 | 22.4k | if(ps_pps->i1_pps_extension_present_flag) |
2632 | 986 | { |
2633 | 986 | BITS_PARSE("pps_range_extension_flag", value, ps_bitstrm, 1); |
2634 | 986 | ps_pps->i1_pps_range_extension_flag = value; |
2635 | | |
2636 | 986 | BITS_PARSE("pps_multilayer_extension_flag", value, ps_bitstrm, 1); |
2637 | 986 | ps_pps->i1_pps_multilayer_extension_flag = value; |
2638 | | |
2639 | 986 | BITS_PARSE("pps_3d_extension_flag", value, ps_bitstrm, 1); |
2640 | 986 | ps_pps->i1_pps_3d_extension_flag = value; |
2641 | | |
2642 | 986 | BITS_PARSE("pps_scc_extension_flag", value, ps_bitstrm, 1); |
2643 | 986 | ps_pps->i1_pps_scc_extension_flag = value; |
2644 | | |
2645 | 986 | BITS_PARSE("pps_extension_4bits", value, ps_bitstrm, 4); |
2646 | 986 | ps_pps->i1_pps_extension_4bits = value; |
2647 | 986 | } |
2648 | | |
2649 | 22.4k | #ifdef ENABLE_MAIN_REXT_PROFILE |
2650 | 22.4k | if(ps_pps->i1_pps_range_extension_flag) |
2651 | 335 | { |
2652 | | /* ITU-T H.265 Section 7.3.2.3.2 Range extension PPS syntax */ |
2653 | 335 | if(ps_pps->i1_transform_skip_enabled_flag) |
2654 | 218 | { |
2655 | 218 | UEV_PARSE("log2_max_transform_skip_block_size_minus2", value, ps_bitstrm); |
2656 | 218 | ps_pps->i1_log2_max_transform_skip_block_size_minus2 = value; |
2657 | 218 | } |
2658 | | |
2659 | 335 | BITS_PARSE("cross_component_prediction_enabled_flag", value, ps_bitstrm, 1); |
2660 | 335 | ps_pps->i1_cross_component_prediction_enabled_flag = value; |
2661 | | |
2662 | | // Parse other bits to maintain bitstream alignment |
2663 | 335 | BITS_PARSE("chroma_qp_offset_list_enabled_flag", value, ps_bitstrm, 1); |
2664 | 335 | ps_pps->i1_chroma_qp_offset_list_enabled_flag = value; |
2665 | | |
2666 | 335 | if(ps_pps->i1_chroma_qp_offset_list_enabled_flag) |
2667 | 126 | { |
2668 | 126 | UEV_PARSE("diff_cu_chroma_qp_offset_depth", value, ps_bitstrm); |
2669 | 126 | ps_pps->i4_diff_cu_chroma_qp_offset_depth = value; |
2670 | | |
2671 | 126 | UEV_PARSE("chroma_qp_offset_list_len_minus1", value, ps_bitstrm); |
2672 | 126 | ps_pps->i4_chroma_qp_offset_list_len_minus1 = value; |
2673 | 126 | if(ps_pps->i4_chroma_qp_offset_list_len_minus1 < 0 |
2674 | 126 | || ps_pps->i4_chroma_qp_offset_list_len_minus1 > 5) |
2675 | 16 | { |
2676 | 16 | return IHEVCD_INVALID_PARAMETER; |
2677 | 16 | } |
2678 | | |
2679 | 257 | for(int i = 0; i <= ps_pps->i4_chroma_qp_offset_list_len_minus1; i++) |
2680 | 147 | { |
2681 | | // cb_qp_offset_list[i] (se-v) |
2682 | 147 | SEV_PARSE("cb_qp_offset_list", value, ps_bitstrm); |
2683 | 147 | ps_pps->i4_cb_qp_offset_list[i] = value; |
2684 | | |
2685 | | // cr_qp_offset_list[i] (se-v) |
2686 | 147 | SEV_PARSE("cr_qp_offset_list", value, ps_bitstrm); |
2687 | 147 | ps_pps->i4_cr_qp_offset_list[i] = value; |
2688 | 147 | } |
2689 | 110 | } |
2690 | | |
2691 | | // log2_sao_offset_scale_luma (ue-v) |
2692 | 319 | UEV_PARSE("log2_sao_ofst_scale_luma", value, ps_bitstrm); |
2693 | 319 | ps_pps->i1_log2_sao_ofst_scale_luma = value; |
2694 | | |
2695 | | // log2_sao_offset_scale_chroma (ue-v) |
2696 | 319 | UEV_PARSE("log2_sao_ofst_scale_chroma", value, ps_bitstrm); |
2697 | 319 | ps_pps->i1_log2_sao_ofst_scale_chroma = value; |
2698 | 319 | } |
2699 | | |
2700 | 22.3k | WORD32 profile = ihevcd_get_profile(&ps_sps->s_ptl.s_ptl_gen); |
2701 | 22.3k | if(profile != IHEVC_PROFILE_MAIN_REXT) |
2702 | 20.3k | { |
2703 | 20.3k | if(ps_pps->i1_log2_max_transform_skip_block_size_minus2 |
2704 | 20.2k | || ps_pps->i1_cross_component_prediction_enabled_flag |
2705 | 20.1k | || ps_pps->i1_chroma_qp_offset_list_enabled_flag |
2706 | 20.1k | || ps_pps->i1_log2_sao_ofst_scale_luma |
2707 | 20.0k | || ps_pps->i1_log2_sao_ofst_scale_chroma) |
2708 | 323 | { |
2709 | 323 | return IHEVCD_INVALID_PARAMETER; |
2710 | 323 | } |
2711 | 20.3k | } |
2712 | 22.0k | if(ps_pps->i1_log2_sao_ofst_scale_luma |
2713 | 22.0k | || ps_pps->i1_log2_sao_ofst_scale_chroma) |
2714 | 54 | { |
2715 | | // main-rext 8-bit profiles require these fields to be off |
2716 | 54 | return IHEVCD_INVALID_PARAMETER; |
2717 | 54 | } |
2718 | | |
2719 | 22.0k | if(ps_pps->i1_chroma_qp_offset_list_enabled_flag) |
2720 | 2 | { |
2721 | | // TODO: decoder does not yet supports these tool-sets |
2722 | 2 | return IHEVCD_UNSUPPORTED_TOOL_SET; |
2723 | 2 | } |
2724 | 22.0k | if(ps_pps->i1_pps_multilayer_extension_flag || ps_pps->i1_pps_3d_extension_flag |
2725 | 21.5k | || ps_pps->i1_pps_scc_extension_flag) |
2726 | 532 | { |
2727 | | // TODO: add support for parsing these syntax elements |
2728 | 532 | return IHEVCD_UNSUPPORTED_TOOL_SET; |
2729 | 532 | } |
2730 | | #else |
2731 | | if(ps_pps->i1_pps_range_extension_flag || ps_pps->i1_pps_multilayer_extension_flag |
2732 | | || ps_pps->i1_pps_3d_extension_flag || ps_pps->i1_pps_scc_extension_flag) |
2733 | | { |
2734 | | // TODO: add support for parsing these syntax elements |
2735 | | return IHEVCD_UNSUPPORTED_TOOL_SET; |
2736 | | } |
2737 | | #endif |
2738 | | |
2739 | 21.4k | if((UWORD8 *)ps_bitstrm->pu4_buf > ps_bitstrm->pu1_buf_max) |
2740 | 165 | return IHEVCD_INVALID_PARAMETER; |
2741 | | |
2742 | 21.3k | ps_codec->i4_pps_done = 1; |
2743 | 21.3k | return ret; |
2744 | 21.4k | } |
2745 | | |
2746 | | |
2747 | | void ihevcd_copy_pps(codec_t *ps_codec, WORD32 pps_id, WORD32 pps_id_ref) |
2748 | 28.4k | { |
2749 | 28.4k | pps_t *ps_pps, *ps_pps_ref; |
2750 | 28.4k | WORD16 *pi2_scaling_mat_backup; |
2751 | 28.4k | WORD32 scaling_mat_size; |
2752 | 28.4k | tile_t *ps_tile_backup; |
2753 | 28.4k | WORD32 max_tile_cols, max_tile_rows; |
2754 | 28.4k | WORD32 wd, ht; |
2755 | 28.4k | wd = ALIGN64(ps_codec->i4_wd); |
2756 | 28.4k | ht = ALIGN64(ps_codec->i4_ht); |
2757 | | |
2758 | 28.4k | SCALING_MAT_SIZE(scaling_mat_size); |
2759 | 28.4k | max_tile_cols = (wd + MIN_TILE_WD - 1) / MIN_TILE_WD; |
2760 | 28.4k | max_tile_rows = (ht + MIN_TILE_HT - 1) / MIN_TILE_HT; |
2761 | | |
2762 | 28.4k | ps_pps_ref = ps_codec->ps_pps_base + pps_id_ref; |
2763 | 28.4k | ps_pps = ps_codec->ps_pps_base + pps_id; |
2764 | | |
2765 | 28.4k | pi2_scaling_mat_backup = ps_pps->pi2_scaling_mat; |
2766 | 28.4k | ps_tile_backup = ps_pps->ps_tile; |
2767 | | |
2768 | 28.4k | memcpy(ps_pps, ps_pps_ref, sizeof(pps_t)); |
2769 | 28.4k | ps_pps->pi2_scaling_mat = pi2_scaling_mat_backup; |
2770 | 28.4k | ps_pps->ps_tile = ps_tile_backup; |
2771 | 28.4k | memcpy(ps_pps->pi2_scaling_mat, ps_pps_ref->pi2_scaling_mat, scaling_mat_size * sizeof(WORD16)); |
2772 | 28.4k | memcpy(ps_pps->ps_tile, ps_pps_ref->ps_tile, max_tile_cols * max_tile_rows * sizeof(tile_t)); |
2773 | | |
2774 | 28.4k | ps_pps->i1_pps_valid = 1; |
2775 | | |
2776 | 28.4k | ps_codec->s_parse.ps_pps = ps_pps; |
2777 | 28.4k | } |
2778 | | |
2779 | | |
2780 | | #ifndef DISABLE_SEI |
2781 | | IHEVCD_ERROR_T ihevcd_parse_buffering_period_sei(codec_t *ps_codec, |
2782 | | sps_t *ps_sps) |
2783 | 2.20k | { |
2784 | 2.20k | parse_ctxt_t *ps_parse = &ps_codec->s_parse; |
2785 | 2.20k | bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; |
2786 | 2.20k | UWORD32 value; |
2787 | 2.20k | vui_t *ps_vui; |
2788 | 2.20k | buf_period_sei_params_t *ps_buf_period_sei_params; |
2789 | 2.20k | UWORD32 i; |
2790 | 2.20k | hrd_params_t *ps_vui_hdr; |
2791 | 2.20k | UWORD32 u4_cpb_cnt; |
2792 | | |
2793 | 2.20k | ps_vui = &ps_sps->s_vui_parameters; |
2794 | 2.20k | ps_vui_hdr = &ps_vui->s_vui_hrd_parameters; |
2795 | | |
2796 | 2.20k | ps_buf_period_sei_params = &ps_parse->s_sei_params.s_buf_period_sei_params; |
2797 | | |
2798 | 2.20k | ps_parse->s_sei_params.i1_buf_period_params_present_flag = 1; |
2799 | | |
2800 | 2.20k | UEV_PARSE("bp_seq_parameter_set_id", value, ps_bitstrm); |
2801 | 2.20k | if(value > MAX_SPS_CNT - 2) |
2802 | 341 | { |
2803 | 341 | return IHEVCD_INVALID_PARAMETER; |
2804 | 341 | } |
2805 | 1.86k | ps_buf_period_sei_params->u1_bp_seq_parameter_set_id = value; |
2806 | | |
2807 | 1.86k | if(!ps_vui_hdr->u1_sub_pic_cpb_params_present_flag) |
2808 | 1.44k | { |
2809 | 1.44k | BITS_PARSE("irap_cpb_params_present_flag", value, ps_bitstrm, 1); |
2810 | 1.44k | ps_buf_period_sei_params->u1_rap_cpb_params_present_flag = value; |
2811 | 1.44k | } |
2812 | | |
2813 | 1.86k | if(ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) |
2814 | 737 | { |
2815 | 737 | BITS_PARSE("cpb_delay_offset", |
2816 | 737 | value, |
2817 | 737 | ps_bitstrm, |
2818 | 737 | (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 |
2819 | 737 | + 1)); |
2820 | 737 | ps_buf_period_sei_params->u4_cpb_delay_offset = value; |
2821 | | |
2822 | 737 | BITS_PARSE("dpb_delay_offset", |
2823 | 737 | value, |
2824 | 737 | ps_bitstrm, |
2825 | 737 | (ps_vui_hdr->u1_dpb_output_delay_length_minus1 |
2826 | 737 | + 1)); |
2827 | 737 | ps_buf_period_sei_params->u4_dpb_delay_offset = value; |
2828 | 737 | } |
2829 | 1.12k | else |
2830 | 1.12k | { |
2831 | 1.12k | ps_buf_period_sei_params->u4_cpb_delay_offset = 0; |
2832 | 1.12k | ps_buf_period_sei_params->u4_dpb_delay_offset = 0; |
2833 | 1.12k | } |
2834 | | |
2835 | 1.86k | BITS_PARSE("concatenation_flag", value, ps_bitstrm, 1); |
2836 | 1.86k | ps_buf_period_sei_params->u1_concatenation_flag = value; |
2837 | | |
2838 | 1.86k | BITS_PARSE("au_cpb_removal_delay_delta_minus1", |
2839 | 1.86k | value, |
2840 | 1.86k | ps_bitstrm, |
2841 | 1.86k | (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 |
2842 | 1.86k | + 1)); |
2843 | 1.86k | ps_buf_period_sei_params->u4_au_cpb_removal_delay_delta_minus1 = value; |
2844 | | |
2845 | 1.86k | if(ps_vui_hdr->u1_nal_hrd_parameters_present_flag) |
2846 | 342 | { |
2847 | 342 | u4_cpb_cnt = ps_vui_hdr->au1_cpb_cnt_minus1[0]; |
2848 | | |
2849 | 4.78k | for(i = 0; i <= u4_cpb_cnt; i++) |
2850 | 4.44k | { |
2851 | 4.44k | BITS_PARSE("nal_initial_cpb_removal_delay[i]", |
2852 | 4.44k | value, |
2853 | 4.44k | ps_bitstrm, |
2854 | 4.44k | (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 |
2855 | 4.44k | + 1)); |
2856 | 4.44k | ps_buf_period_sei_params->au4_nal_initial_cpb_removal_delay[i] = |
2857 | 4.44k | value; |
2858 | | |
2859 | 4.44k | BITS_PARSE("nal_initial_cpb_removal_delay_offset", |
2860 | 4.44k | value, |
2861 | 4.44k | ps_bitstrm, |
2862 | 4.44k | (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 |
2863 | 4.44k | + 1)); |
2864 | 4.44k | ps_buf_period_sei_params->au4_nal_initial_cpb_removal_delay_offset[i] = |
2865 | 4.44k | value; |
2866 | | |
2867 | 4.44k | if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag |
2868 | 4.14k | || ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) |
2869 | 2.86k | { |
2870 | 2.86k | BITS_PARSE("nal_initial_alt_cpb_removal_delay[i]", |
2871 | 2.86k | value, |
2872 | 2.86k | ps_bitstrm, |
2873 | 2.86k | (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 |
2874 | 2.86k | + 1)); |
2875 | 2.86k | ps_buf_period_sei_params->au4_nal_initial_alt_cpb_removal_delay[i] = |
2876 | 2.86k | value; |
2877 | | |
2878 | 2.86k | BITS_PARSE("nal_initial_alt_cpb_removal_delay_offset", |
2879 | 2.86k | value, |
2880 | 2.86k | ps_bitstrm, |
2881 | 2.86k | (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 |
2882 | 2.86k | + 1)); |
2883 | 2.86k | ps_buf_period_sei_params->au4_nal_initial_alt_cpb_removal_delay_offset[i] = |
2884 | 2.86k | value; |
2885 | 2.86k | } |
2886 | 4.44k | } |
2887 | 342 | } |
2888 | | |
2889 | 1.86k | if(ps_vui_hdr->u1_vcl_hrd_parameters_present_flag) |
2890 | 514 | { |
2891 | 514 | u4_cpb_cnt = ps_vui_hdr->au1_cpb_cnt_minus1[0]; |
2892 | | |
2893 | 5.53k | for(i = 0; i <= u4_cpb_cnt; i++) |
2894 | 5.02k | { |
2895 | 5.02k | BITS_PARSE("vcl_initial_cpb_removal_delay[i]", |
2896 | 5.02k | value, |
2897 | 5.02k | ps_bitstrm, |
2898 | 5.02k | (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 |
2899 | 5.02k | + 1)); |
2900 | 5.02k | ps_buf_period_sei_params->au4_vcl_initial_cpb_removal_delay[i] = |
2901 | 5.02k | value; |
2902 | | |
2903 | 5.02k | BITS_PARSE("vcl_initial_cpb_removal_delay_offset", |
2904 | 5.02k | value, |
2905 | 5.02k | ps_bitstrm, |
2906 | 5.02k | (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 |
2907 | 5.02k | + 1)); |
2908 | 5.02k | ps_buf_period_sei_params->au4_vcl_initial_cpb_removal_delay_offset[i] = |
2909 | 5.02k | value; |
2910 | | |
2911 | 5.02k | if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag |
2912 | 1.20k | || ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) |
2913 | 4.37k | { |
2914 | 4.37k | BITS_PARSE("vcl_initial_alt_cpb_removal_delay[i]", |
2915 | 4.37k | value, |
2916 | 4.37k | ps_bitstrm, |
2917 | 4.37k | (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 |
2918 | 4.37k | + 1)); |
2919 | 4.37k | ps_buf_period_sei_params->au4_vcl_initial_alt_cpb_removal_delay[i] = |
2920 | 4.37k | value; |
2921 | | |
2922 | 4.37k | BITS_PARSE("vcl_initial_alt_cpb_removal_delay_offset", |
2923 | 4.37k | value, |
2924 | 4.37k | ps_bitstrm, |
2925 | 4.37k | (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 |
2926 | 4.37k | + 1)); |
2927 | 4.37k | ps_buf_period_sei_params->au4_vcl_initial_alt_cpb_removal_delay_offset[i] = |
2928 | 4.37k | value; |
2929 | 4.37k | } |
2930 | 5.02k | } |
2931 | 514 | } |
2932 | | |
2933 | 1.86k | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
2934 | 2.20k | } |
2935 | | |
2936 | | IHEVCD_ERROR_T ihevcd_parse_pic_timing_sei(codec_t *ps_codec, sps_t *ps_sps) |
2937 | 3.08k | { |
2938 | 3.08k | parse_ctxt_t *ps_parse = &ps_codec->s_parse; |
2939 | 3.08k | bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; |
2940 | 3.08k | UWORD32 value; |
2941 | 3.08k | vui_t *ps_vui; |
2942 | 3.08k | UWORD32 i; |
2943 | 3.08k | hrd_params_t *ps_vui_hdr; |
2944 | 3.08k | UWORD32 u4_cpb_dpb_delays_present_flag = 0; |
2945 | 3.08k | pic_timing_sei_params_t *ps_pic_timing; |
2946 | | |
2947 | 3.08k | ps_pic_timing = &ps_parse->s_sei_params.s_pic_timing_sei_params; |
2948 | 3.08k | ps_vui = &ps_sps->s_vui_parameters; |
2949 | 3.08k | ps_vui_hdr = &ps_vui->s_vui_hrd_parameters; |
2950 | 3.08k | ps_parse->s_sei_params.i1_pic_timing_params_present_flag = 1; |
2951 | 3.08k | if(ps_vui->u1_frame_field_info_present_flag) |
2952 | 2.47k | { |
2953 | 2.47k | BITS_PARSE("pic_struct", value, ps_bitstrm, 4); |
2954 | 2.47k | ps_pic_timing->u4_pic_struct = value; |
2955 | | |
2956 | 2.47k | BITS_PARSE("source_scan_type", value, ps_bitstrm, 2); |
2957 | 2.47k | ps_pic_timing->u4_source_scan_type = value; |
2958 | | |
2959 | 2.47k | BITS_PARSE("duplicate_flag", value, ps_bitstrm, 1); |
2960 | 2.47k | ps_pic_timing->u1_duplicate_flag = value; |
2961 | 2.47k | } |
2962 | | |
2963 | 3.08k | if(ps_vui_hdr->u1_nal_hrd_parameters_present_flag |
2964 | 1.14k | || ps_vui_hdr->u1_vcl_hrd_parameters_present_flag) |
2965 | 2.35k | { |
2966 | 2.35k | u4_cpb_dpb_delays_present_flag = 1; |
2967 | 2.35k | } |
2968 | 729 | else |
2969 | 729 | { |
2970 | 729 | u4_cpb_dpb_delays_present_flag = 0; |
2971 | 729 | } |
2972 | | |
2973 | 3.08k | if(u4_cpb_dpb_delays_present_flag) |
2974 | 2.35k | { |
2975 | 2.35k | BITS_PARSE("au_cpb_removal_delay_minus1", value, ps_bitstrm, |
2976 | 2.35k | (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 + 1)); |
2977 | 2.35k | ps_pic_timing->u4_au_cpb_removal_delay_minus1 = value; |
2978 | | |
2979 | 2.35k | BITS_PARSE("pic_dpb_output_delay", value, ps_bitstrm, |
2980 | 2.35k | (ps_vui_hdr->u1_dpb_output_delay_length_minus1 + 1)); |
2981 | 2.35k | ps_pic_timing->u4_pic_dpb_output_delay = value; |
2982 | | |
2983 | 2.35k | if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag) |
2984 | 1.83k | { |
2985 | 1.83k | BITS_PARSE("pic_dpb_output_du_delay", value, ps_bitstrm, |
2986 | 1.83k | (ps_vui_hdr->u1_dpb_output_delay_du_length_minus1 + 1)); |
2987 | 1.83k | ps_pic_timing->u4_pic_dpb_output_du_delay = value; |
2988 | 1.83k | } |
2989 | | |
2990 | 2.35k | if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag |
2991 | 1.83k | && ps_vui_hdr->u1_sub_pic_cpb_params_in_pic_timing_sei_flag) |
2992 | 1.61k | { |
2993 | 1.61k | UWORD32 num_units_minus1; |
2994 | 1.61k | UWORD32 array_size; |
2995 | | |
2996 | 1.61k | UEV_PARSE("num_decoding_units_minus1", value, ps_bitstrm); |
2997 | 1.61k | if(value > (ps_sps->i4_pic_size_in_ctb -1)) |
2998 | 828 | { |
2999 | 828 | return IHEVCD_INVALID_PARAMETER; |
3000 | 828 | } |
3001 | 782 | ps_pic_timing->u4_num_decoding_units_minus1 = value; |
3002 | | |
3003 | 782 | num_units_minus1 = ps_pic_timing->u4_num_decoding_units_minus1; |
3004 | 782 | array_size = (sizeof(ps_pic_timing->au4_num_nalus_in_du_minus1) |
3005 | 782 | / sizeof(ps_pic_timing->au4_num_nalus_in_du_minus1[0])); |
3006 | 782 | num_units_minus1 = CLIP3(num_units_minus1, 0,(array_size - 1)); |
3007 | 782 | ps_pic_timing->u4_num_decoding_units_minus1 = num_units_minus1; |
3008 | | |
3009 | 782 | BITS_PARSE("du_common_cpb_removal_delay_flag", value, ps_bitstrm, 1); |
3010 | 782 | ps_pic_timing->u1_du_common_cpb_removal_delay_flag = value; |
3011 | | |
3012 | 782 | if(ps_pic_timing->u1_du_common_cpb_removal_delay_flag) |
3013 | 279 | { |
3014 | 279 | BITS_PARSE("du_common_cpb_removal_delay_increment_minus1", |
3015 | 279 | value, |
3016 | 279 | ps_bitstrm, |
3017 | 279 | (ps_vui_hdr->u1_du_cpb_removal_delay_increment_length_minus1 |
3018 | 279 | + 1)); |
3019 | 279 | ps_pic_timing->u4_du_common_cpb_removal_delay_increment_minus1 = |
3020 | 279 | value; |
3021 | 279 | } |
3022 | | |
3023 | 6.31k | for(i = 0; i <= ps_pic_timing->u4_num_decoding_units_minus1; i++) |
3024 | 5.69k | { |
3025 | 5.69k | UEV_PARSE("num_nalus_in_du_minus1", value, ps_bitstrm); |
3026 | 5.69k | if(value > (ps_sps->i4_pic_size_in_ctb -1)) |
3027 | 163 | { |
3028 | 163 | return IHEVCD_INVALID_PARAMETER; |
3029 | 163 | } |
3030 | 5.53k | ps_pic_timing->au4_num_nalus_in_du_minus1[i] = value; |
3031 | | |
3032 | 5.53k | if((!ps_pic_timing->u1_du_common_cpb_removal_delay_flag) |
3033 | 1.88k | && (i < ps_pic_timing->u4_num_decoding_units_minus1)) |
3034 | 1.54k | { |
3035 | 1.54k | BITS_PARSE("du_common_cpb_removal_delay_increment_minus1", |
3036 | 1.54k | value, |
3037 | 1.54k | ps_bitstrm, |
3038 | 1.54k | (ps_vui_hdr->u1_du_cpb_removal_delay_increment_length_minus1 |
3039 | 1.54k | + 1)); |
3040 | 1.54k | ps_pic_timing->au4_du_cpb_removal_delay_increment_minus1[i] = |
3041 | 1.54k | value; |
3042 | 1.54k | } |
3043 | 5.53k | } |
3044 | 782 | } |
3045 | 2.35k | } |
3046 | | |
3047 | 2.09k | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
3048 | 3.08k | } |
3049 | | |
3050 | | IHEVCD_ERROR_T ihevcd_parse_time_code_sei(codec_t *ps_codec) |
3051 | 7.49k | { |
3052 | 7.49k | parse_ctxt_t *ps_parse = &ps_codec->s_parse; |
3053 | 7.49k | bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; |
3054 | 7.49k | UWORD32 value; |
3055 | 7.49k | time_code_t *ps_time_code; |
3056 | 7.49k | WORD32 i; |
3057 | | |
3058 | 7.49k | ps_parse->s_sei_params.i1_time_code_present_flag = 1; |
3059 | 7.49k | ps_time_code = &ps_parse->s_sei_params.s_time_code; |
3060 | | |
3061 | 7.49k | BITS_PARSE("num_clock_ts", value, ps_bitstrm, 2); |
3062 | 7.49k | ps_time_code->u1_num_clock_ts = value; |
3063 | | |
3064 | 26.6k | for(i = 0; i < ps_time_code->u1_num_clock_ts; i++) |
3065 | 19.1k | { |
3066 | 19.1k | BITS_PARSE("clock_timestamp_flag[i]", value, ps_bitstrm, 1); |
3067 | 19.1k | ps_time_code->au1_clock_timestamp_flag[i] = value; |
3068 | | |
3069 | 19.1k | if(ps_time_code->au1_clock_timestamp_flag[i]) |
3070 | 11.2k | { |
3071 | 11.2k | BITS_PARSE("units_field_based_flag[i]", value, ps_bitstrm, 1); |
3072 | 11.2k | ps_time_code->au1_units_field_based_flag[i] = value; |
3073 | | |
3074 | 11.2k | BITS_PARSE("counting_type[i]", value, ps_bitstrm, 5); |
3075 | 11.2k | ps_time_code->au1_counting_type[i] = value; |
3076 | | |
3077 | 11.2k | BITS_PARSE("full_timestamp_flag[i]", value, ps_bitstrm, 1); |
3078 | 11.2k | ps_time_code->au1_full_timestamp_flag[i] = value; |
3079 | | |
3080 | 11.2k | BITS_PARSE("discontinuity_flag[i]", value, ps_bitstrm, 1); |
3081 | 11.2k | ps_time_code->au1_discontinuity_flag[i] = value; |
3082 | | |
3083 | 11.2k | BITS_PARSE("cnt_dropped_flag[i]", value, ps_bitstrm, 1); |
3084 | 11.2k | ps_time_code->au1_cnt_dropped_flag[i] = value; |
3085 | | |
3086 | 11.2k | BITS_PARSE("n_frames[i]", value, ps_bitstrm, 9); |
3087 | 11.2k | ps_time_code->au2_n_frames[i] = value; |
3088 | | |
3089 | 11.2k | if(ps_time_code->au1_full_timestamp_flag[i]) |
3090 | 776 | { |
3091 | 776 | BITS_PARSE("seconds_value[i]", value, ps_bitstrm, 6); |
3092 | 776 | ps_time_code->au1_seconds_value[i] = value; |
3093 | | |
3094 | 776 | BITS_PARSE("minutes_value[i]", value, ps_bitstrm, 6); |
3095 | 776 | ps_time_code->au1_minutes_value[i] = value; |
3096 | | |
3097 | 776 | BITS_PARSE("hours_value[i]", value, ps_bitstrm, 5); |
3098 | 776 | ps_time_code->au1_hours_value[i] = value; |
3099 | 776 | } |
3100 | 10.5k | else |
3101 | 10.5k | { |
3102 | 10.5k | BITS_PARSE("seconds_flag[i]", value, ps_bitstrm, 1); |
3103 | 10.5k | ps_time_code->au1_seconds_flag[i] = value; |
3104 | | |
3105 | 10.5k | if(ps_time_code->au1_seconds_flag[i]) |
3106 | 6.17k | { |
3107 | 6.17k | BITS_PARSE("seconds_value[i]", value, ps_bitstrm, 6); |
3108 | 6.17k | ps_time_code->au1_seconds_value[i] = value; |
3109 | | |
3110 | 6.17k | BITS_PARSE("minutes_flag[i]", value, ps_bitstrm, 1); |
3111 | 6.17k | ps_time_code->au1_minutes_flag[i] = value; |
3112 | | |
3113 | 6.17k | if(ps_time_code->au1_minutes_flag[i]) |
3114 | 4.38k | { |
3115 | 4.38k | BITS_PARSE("minutes_value[i]", value, ps_bitstrm, 6); |
3116 | 4.38k | ps_time_code->au1_minutes_value[i] = value; |
3117 | | |
3118 | 4.38k | BITS_PARSE("hours_flag[i]", value, ps_bitstrm, 1); |
3119 | 4.38k | ps_time_code->au1_hours_flag[i] = value; |
3120 | | |
3121 | 4.38k | if(ps_time_code->au1_hours_flag[i]) |
3122 | 2.80k | { |
3123 | 2.80k | BITS_PARSE("hours_value[i]", value, ps_bitstrm, 5); |
3124 | 2.80k | ps_time_code->au1_hours_value[i] = value; |
3125 | 2.80k | } |
3126 | 4.38k | } |
3127 | 6.17k | } |
3128 | 10.5k | } |
3129 | | |
3130 | 11.2k | BITS_PARSE("time_offset_length[i]", value, ps_bitstrm, 5); |
3131 | 11.2k | ps_time_code->au1_time_offset_length[i] = value; |
3132 | | |
3133 | 11.2k | if(ps_time_code->au1_time_offset_length[i] > 0) |
3134 | 5.53k | { |
3135 | 5.53k | BITS_PARSE("time_offset_value[i]", value, ps_bitstrm, |
3136 | 5.53k | ps_time_code->au1_time_offset_length[i]); |
3137 | 5.53k | ps_time_code->au1_time_offset_value[i] = value; |
3138 | 5.53k | } |
3139 | 5.74k | else |
3140 | 5.74k | { |
3141 | 5.74k | ps_time_code->au1_time_offset_value[i] = 0; |
3142 | 5.74k | } |
3143 | 11.2k | } |
3144 | 19.1k | } |
3145 | | |
3146 | 7.49k | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
3147 | 7.49k | } |
3148 | | |
3149 | | IHEVCD_ERROR_T ihevcd_parse_mastering_disp_params_sei(codec_t *ps_codec) |
3150 | 849 | { |
3151 | 849 | parse_ctxt_t *ps_parse = &ps_codec->s_parse; |
3152 | 849 | bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; |
3153 | 849 | UWORD32 value; |
3154 | 849 | mastering_dis_col_vol_sei_params_t *ps_mastering_dis_col_vol; |
3155 | 849 | WORD32 i; |
3156 | | |
3157 | 849 | ps_parse->s_sei_params.i4_sei_mastering_disp_colour_vol_params_present_flags = 1; |
3158 | | |
3159 | 849 | ps_mastering_dis_col_vol = &ps_parse->s_sei_params.s_mastering_dis_col_vol_sei_params; |
3160 | | |
3161 | 3.39k | for(i = 0; i < 3; i++) |
3162 | 2.54k | { |
3163 | 2.54k | BITS_PARSE("display_primaries_x[c]", value, ps_bitstrm, 16); |
3164 | 2.54k | ps_mastering_dis_col_vol->au2_display_primaries_x[i] = value; |
3165 | | |
3166 | 2.54k | BITS_PARSE("display_primaries_y[c]", value, ps_bitstrm, 16); |
3167 | 2.54k | ps_mastering_dis_col_vol->au2_display_primaries_y[i] = value; |
3168 | 2.54k | } |
3169 | | |
3170 | 849 | BITS_PARSE("white_point_x", value, ps_bitstrm, 16); |
3171 | 849 | ps_mastering_dis_col_vol->u2_white_point_x = value; |
3172 | | |
3173 | 849 | BITS_PARSE("white_point_y", value, ps_bitstrm, 16); |
3174 | 849 | ps_mastering_dis_col_vol->u2_white_point_y = value; |
3175 | | |
3176 | 849 | BITS_PARSE("max_display_mastering_luminance", value, ps_bitstrm, 32); |
3177 | 849 | ps_mastering_dis_col_vol->u4_max_display_mastering_luminance = value; |
3178 | | |
3179 | 849 | BITS_PARSE("min_display_mastering_luminance", value, ps_bitstrm, 32); |
3180 | 849 | ps_mastering_dis_col_vol->u4_min_display_mastering_luminance = value; |
3181 | | |
3182 | 849 | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
3183 | 849 | } |
3184 | | |
3185 | | IHEVCD_ERROR_T ihevcd_parse_user_data_registered_itu_t_t35(codec_t *ps_codec, |
3186 | | UWORD32 u4_payload_size) |
3187 | 186 | { |
3188 | 186 | parse_ctxt_t *ps_parse = &ps_codec->s_parse; |
3189 | 186 | bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; |
3190 | 186 | UWORD32 value; |
3191 | 186 | user_data_registered_itu_t_t35_t *ps_user_data_registered_itu_t_t35; |
3192 | 186 | UWORD32 i; |
3193 | 186 | UWORD32 j = 0; |
3194 | | |
3195 | 186 | ps_parse->s_sei_params.i1_user_data_registered_present_flag = 1; |
3196 | 186 | ps_user_data_registered_itu_t_t35 = |
3197 | 186 | &ps_parse->s_sei_params.as_user_data_registered_itu_t_t35[ps_parse->s_sei_params.i4_sei_user_data_cnt]; |
3198 | 186 | ps_parse->s_sei_params.i4_sei_user_data_cnt++; |
3199 | | |
3200 | 186 | ps_user_data_registered_itu_t_t35->i4_payload_size = u4_payload_size; |
3201 | | |
3202 | 186 | if(u4_payload_size > MAX_USERDATA_PAYLOAD) |
3203 | 7 | { |
3204 | 7 | u4_payload_size = MAX_USERDATA_PAYLOAD; |
3205 | 7 | } |
3206 | | |
3207 | 186 | ps_user_data_registered_itu_t_t35->i4_valid_payload_size = u4_payload_size; |
3208 | | |
3209 | 186 | BITS_PARSE("itu_t_t35_country_code", value, ps_bitstrm, 8); |
3210 | 186 | ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code = value; |
3211 | | |
3212 | 186 | if(0xFF != ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code) |
3213 | 154 | { |
3214 | 154 | i = 1; |
3215 | 154 | } |
3216 | 32 | else |
3217 | 32 | { |
3218 | 32 | BITS_PARSE("itu_t_t35_country_code_extension_byte", value, ps_bitstrm, |
3219 | 32 | 8); |
3220 | 32 | ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code_extension_byte = |
3221 | 32 | value; |
3222 | | |
3223 | 32 | i = 2; |
3224 | 32 | } |
3225 | | |
3226 | 186 | do |
3227 | 3.68k | { |
3228 | 3.68k | BITS_PARSE("itu_t_t35_payload_byte", value, ps_bitstrm, 8); |
3229 | 3.68k | ps_user_data_registered_itu_t_t35->u1_itu_t_t35_payload_byte[j++] = |
3230 | 3.68k | value; |
3231 | | |
3232 | 3.68k | i++; |
3233 | 3.68k | }while(i < u4_payload_size); |
3234 | | |
3235 | 186 | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
3236 | 186 | } |
3237 | | |
3238 | | void ihevcd_parse_sei_payload(codec_t *ps_codec, |
3239 | | UWORD32 u4_payload_type, |
3240 | | UWORD32 u4_payload_size, |
3241 | | WORD8 i1_nal_type) |
3242 | 1.66M | { |
3243 | 1.66M | parse_ctxt_t *ps_parse = &ps_codec->s_parse; |
3244 | 1.66M | bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; |
3245 | 1.66M | WORD32 payload_bits_remaining = 0; |
3246 | 1.66M | sps_t *ps_sps; |
3247 | | |
3248 | 1.66M | UWORD32 i; |
3249 | | |
3250 | 29.6M | for(i = 0; i < MAX_SPS_CNT; i++) |
3251 | 27.9M | { |
3252 | 27.9M | ps_sps = ps_codec->ps_sps_base + i; |
3253 | 27.9M | if(ps_sps->i1_sps_valid) |
3254 | 18.9k | { |
3255 | 18.9k | break; |
3256 | 18.9k | } |
3257 | 27.9M | } |
3258 | 1.66M | if(!ps_sps->i1_sps_valid) |
3259 | 1.64M | { |
3260 | 1.64M | return; |
3261 | 1.64M | } |
3262 | | |
3263 | 18.9k | if(NAL_PREFIX_SEI == i1_nal_type) |
3264 | 16.1k | { |
3265 | 16.1k | switch(u4_payload_type) |
3266 | 16.1k | { |
3267 | 2.20k | case SEI_BUFFERING_PERIOD: |
3268 | 2.20k | ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; |
3269 | 2.20k | ihevcd_parse_buffering_period_sei(ps_codec, ps_sps); |
3270 | 2.20k | break; |
3271 | | |
3272 | 3.08k | case SEI_PICTURE_TIMING: |
3273 | 3.08k | ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; |
3274 | 3.08k | ihevcd_parse_pic_timing_sei(ps_codec, ps_sps); |
3275 | 3.08k | break; |
3276 | | |
3277 | 7.49k | case SEI_TIME_CODE: |
3278 | 7.49k | ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; |
3279 | 7.49k | ihevcd_parse_time_code_sei(ps_codec); |
3280 | 7.49k | break; |
3281 | | |
3282 | 849 | case SEI_MASTERING_DISPLAY_COLOUR_VOLUME: |
3283 | 849 | ps_parse->s_sei_params.i4_sei_mastering_disp_colour_vol_params_present_flags = 1; |
3284 | 849 | ihevcd_parse_mastering_disp_params_sei(ps_codec); |
3285 | 849 | break; |
3286 | | |
3287 | 350 | case SEI_USER_DATA_REGISTERED_ITU_T_T35: |
3288 | 350 | ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; |
3289 | 350 | if(ps_parse->s_sei_params.i4_sei_user_data_cnt >= USER_DATA_MAX) |
3290 | 301 | { |
3291 | 847 | for(i = 0; i < u4_payload_size / 4; i++) |
3292 | 546 | { |
3293 | 546 | ihevcd_bits_flush(ps_bitstrm, 4 * 8); |
3294 | 546 | } |
3295 | | |
3296 | 301 | ihevcd_bits_flush(ps_bitstrm, (u4_payload_size - i * 4) * 8); |
3297 | 301 | } |
3298 | 49 | else |
3299 | 49 | { |
3300 | 49 | ihevcd_parse_user_data_registered_itu_t_t35(ps_codec, |
3301 | 49 | u4_payload_size); |
3302 | 49 | } |
3303 | 350 | break; |
3304 | | |
3305 | 2.17k | default: |
3306 | 64.2k | for(i = 0; i < u4_payload_size; i++) |
3307 | 62.0k | { |
3308 | 62.0k | ihevcd_bits_flush(ps_bitstrm, 8); |
3309 | 62.0k | } |
3310 | 2.17k | break; |
3311 | 16.1k | } |
3312 | 16.1k | } |
3313 | 2.76k | else /* NAL_SUFFIX_SEI */ |
3314 | 2.76k | { |
3315 | 2.76k | switch(u4_payload_type) |
3316 | 2.76k | { |
3317 | 741 | case SEI_USER_DATA_REGISTERED_ITU_T_T35: |
3318 | 741 | ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; |
3319 | 741 | if(ps_parse->s_sei_params.i4_sei_user_data_cnt >= USER_DATA_MAX) |
3320 | 604 | { |
3321 | 1.34k | for(i = 0; i < u4_payload_size / 4; i++) |
3322 | 737 | { |
3323 | 737 | ihevcd_bits_flush(ps_bitstrm, 4 * 8); |
3324 | 737 | } |
3325 | | |
3326 | 604 | ihevcd_bits_flush(ps_bitstrm, (u4_payload_size - i * 4) * 8); |
3327 | 604 | } |
3328 | 137 | else |
3329 | 137 | { |
3330 | 137 | ihevcd_parse_user_data_registered_itu_t_t35(ps_codec, |
3331 | 137 | u4_payload_size); |
3332 | 137 | } |
3333 | 741 | break; |
3334 | | |
3335 | 2.02k | default: |
3336 | 64.5k | for(i = 0; i < u4_payload_size; i++) |
3337 | 62.5k | { |
3338 | 62.5k | ihevcd_bits_flush(ps_bitstrm, 8); |
3339 | 62.5k | } |
3340 | 2.02k | break; |
3341 | 2.76k | } |
3342 | 2.76k | } |
3343 | | |
3344 | | /** |
3345 | | * By definition the underlying bitstream terminates in a byte-aligned manner. |
3346 | | * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data |
3347 | | * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker |
3348 | | * 3. Extract the remainingreserved_payload_extension_data bits. |
3349 | | * |
3350 | | * If there are fewer than 9 bits available, extract them. |
3351 | | */ |
3352 | | |
3353 | 18.9k | payload_bits_remaining = ihevcd_bits_num_bits_remaining(ps_bitstrm); |
3354 | 18.9k | if(payload_bits_remaining) /* more_data_in_payload() */ |
3355 | 9.09k | { |
3356 | 9.09k | WORD32 final_bits; |
3357 | 9.09k | WORD32 final_payload_bits = 0; |
3358 | 9.09k | WORD32 mask = 0xFF; |
3359 | 9.09k | UWORD32 u4_dummy; |
3360 | 9.09k | UWORD32 u4_reserved_payload_extension_data; |
3361 | 9.09k | UNUSED(u4_dummy); |
3362 | 9.09k | UNUSED(u4_reserved_payload_extension_data); |
3363 | | |
3364 | 1.26M | while(payload_bits_remaining > 9) |
3365 | 1.25M | { |
3366 | 1.25M | BITS_PARSE("reserved_payload_extension_data", |
3367 | 1.25M | u4_reserved_payload_extension_data, ps_bitstrm, 1); |
3368 | 1.25M | payload_bits_remaining--; |
3369 | 1.25M | } |
3370 | | |
3371 | 9.09k | final_bits = ihevcd_bits_nxt(ps_bitstrm, payload_bits_remaining); |
3372 | | |
3373 | 60.7k | while(final_bits & (mask >> final_payload_bits)) |
3374 | 51.6k | { |
3375 | 51.6k | final_payload_bits++; |
3376 | 51.6k | continue; |
3377 | 51.6k | } |
3378 | | |
3379 | 56.9k | while(payload_bits_remaining > (9 - final_payload_bits)) |
3380 | 47.8k | { |
3381 | 47.8k | BITS_PARSE("reserved_payload_extension_data", |
3382 | 47.8k | u4_reserved_payload_extension_data, ps_bitstrm, 1); |
3383 | 47.8k | payload_bits_remaining--; |
3384 | 47.8k | } |
3385 | | |
3386 | 9.09k | BITS_PARSE("payload_bit_equal_to_one", u4_dummy, ps_bitstrm, 1); |
3387 | 9.09k | payload_bits_remaining--; |
3388 | 24.9k | while(payload_bits_remaining) |
3389 | 15.8k | { |
3390 | 15.8k | BITS_PARSE("payload_bit_equal_to_zero", u4_dummy, ps_bitstrm, 1); |
3391 | 15.8k | payload_bits_remaining--; |
3392 | 15.8k | } |
3393 | 9.09k | } |
3394 | | |
3395 | 18.9k | return; |
3396 | 18.9k | } |
3397 | | |
3398 | | IHEVCD_ERROR_T ihevcd_read_rbsp_trailing_bits(codec_t *ps_codec, |
3399 | | UWORD32 u4_bits_left) |
3400 | 1.79k | { |
3401 | 1.79k | parse_ctxt_t *ps_parse = &ps_codec->s_parse; |
3402 | 1.79k | UWORD32 value; |
3403 | 1.79k | WORD32 cnt = 0; |
3404 | 1.79k | BITS_PARSE("rbsp_stop_one_bit", value, &ps_parse->s_bitstrm, 1); |
3405 | 1.79k | u4_bits_left--; |
3406 | 1.79k | if(value != 1) |
3407 | 792 | { |
3408 | 792 | return (IHEVCD_ERROR_T)IHEVCD_FAIL; |
3409 | 792 | } |
3410 | 8.05k | while(u4_bits_left) |
3411 | 7.04k | { |
3412 | 7.04k | BITS_PARSE("rbsp_alignment_zero_bit", value, &ps_parse->s_bitstrm, 1); |
3413 | 7.04k | u4_bits_left--; |
3414 | 7.04k | cnt++; |
3415 | 7.04k | } |
3416 | 1.00k | ASSERT(cnt < 8); |
3417 | | |
3418 | 1.00k | return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
3419 | 1.00k | } |
3420 | | /** |
3421 | | ******************************************************************************* |
3422 | | * |
3423 | | * @brief |
3424 | | * Parses SEI (Supplemental Enhancement Information) |
3425 | | * |
3426 | | * @par Description: |
3427 | | * Parses SEI (Supplemental Enhancement Information) as per Section: 7.3.7 |
3428 | | * |
3429 | | * @param[in] ps_codec |
3430 | | * Pointer to codec context |
3431 | | * |
3432 | | * @returns Error code from IHEVCD_ERROR_T |
3433 | | * |
3434 | | * @remarks |
3435 | | * |
3436 | | * |
3437 | | ******************************************************************************* |
3438 | | */ |
3439 | | IHEVCD_ERROR_T ihevcd_parse_sei(codec_t *ps_codec, nal_header_t *ps_nal) |
3440 | 25.3k | { |
3441 | 25.3k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
3442 | 25.3k | parse_ctxt_t *ps_parse = &ps_codec->s_parse; |
3443 | 25.3k | UWORD32 u4_payload_type = 0, u4_last_payload_type_byte = 0; |
3444 | 25.3k | UWORD32 u4_payload_size = 0, u4_last_payload_size_byte = 0; |
3445 | 25.3k | UWORD32 value; |
3446 | 25.3k | bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; |
3447 | 25.3k | UWORD32 u4_bits_left; |
3448 | | |
3449 | 25.3k | u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); |
3450 | | |
3451 | 1.68M | while(u4_bits_left > 8) |
3452 | 1.66M | { |
3453 | 1.66M | while(ihevcd_bits_nxt(ps_bitstrm, 8) == 0xFF) |
3454 | 3.06k | { |
3455 | 3.06k | ihevcd_bits_flush(ps_bitstrm, 8); /* equal to 0xFF */ |
3456 | 3.06k | u4_payload_type += 255; |
3457 | 3.06k | } |
3458 | | |
3459 | 1.66M | BITS_PARSE("last_payload_type_byte", value, ps_bitstrm, 8); |
3460 | 1.66M | u4_last_payload_type_byte = value; |
3461 | | |
3462 | 1.66M | u4_payload_type += u4_last_payload_type_byte; |
3463 | | |
3464 | 1.66M | while(ihevcd_bits_nxt(ps_bitstrm, 8) == 0xFF) |
3465 | 6.40k | { |
3466 | 6.40k | ihevcd_bits_flush(ps_bitstrm, 8); /* equal to 0xFF */ |
3467 | 6.40k | u4_payload_size += 255; |
3468 | 6.40k | } |
3469 | | |
3470 | 1.66M | BITS_PARSE("last_payload_size_byte", value, ps_bitstrm, 8); |
3471 | 1.66M | u4_last_payload_size_byte = value; |
3472 | | |
3473 | 1.66M | u4_payload_size += u4_last_payload_size_byte; |
3474 | 1.66M | u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); |
3475 | 1.66M | u4_payload_size = MIN(u4_payload_size, u4_bits_left / 8); |
3476 | 1.66M | ihevcd_parse_sei_payload(ps_codec, u4_payload_type, u4_payload_size, |
3477 | 1.66M | ps_nal->i1_nal_unit_type); |
3478 | | |
3479 | | /* Calculate the bits left in the current payload */ |
3480 | 1.66M | u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); |
3481 | 1.66M | } |
3482 | | |
3483 | | // read rbsp_trailing_bits |
3484 | 25.3k | if(u4_bits_left) |
3485 | 1.79k | { |
3486 | 1.79k | ihevcd_read_rbsp_trailing_bits(ps_codec, u4_bits_left); |
3487 | 1.79k | } |
3488 | | |
3489 | 25.3k | return ret; |
3490 | 25.3k | } |
3491 | | #endif |
3492 | | |
3493 | | /** |
3494 | | ******************************************************************************* |
3495 | | * |
3496 | | * @brief |
3497 | | * Parses Access unit delimiter |
3498 | | * |
3499 | | * @par Description: |
3500 | | * Parses Access unit delimiter as per section Section: 7.3.2.5 |
3501 | | * |
3502 | | * @param[in] ps_codec |
3503 | | * Pointer to codec context |
3504 | | * |
3505 | | * @returns Error code from IHEVCD_ERROR_T |
3506 | | * |
3507 | | * @remarks |
3508 | | * |
3509 | | * |
3510 | | ******************************************************************************* |
3511 | | */ |
3512 | | WORD32 ihevcd_parse_aud(codec_t *ps_codec) |
3513 | 0 | { |
3514 | 0 | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
3515 | 0 | UNUSED(ps_codec); |
3516 | 0 | return ret; |
3517 | 0 | } |
3518 | | |
3519 | | WORD32 ihevcd_extend_sign_bit(WORD32 value, WORD32 num_bits) |
3520 | 0 | { |
3521 | 0 | WORD32 ret_value = value; |
3522 | 0 | if(value >> (num_bits - 1)) |
3523 | 0 | { |
3524 | 0 | ret_value |= (0xFFFFFFFF << num_bits); |
3525 | 0 | } |
3526 | 0 | return ret_value; |
3527 | 0 | } |
3528 | | |
3529 | | /** |
3530 | | ******************************************************************************* |
3531 | | * |
3532 | | * @brief |
3533 | | * Calculate POC of the current slice |
3534 | | * |
3535 | | * @par Description: |
3536 | | * Calculates the current POC using the previous POC lsb and previous POC msb |
3537 | | * |
3538 | | * @param[in] ps_codec |
3539 | | * Pointer to codec context |
3540 | | * |
3541 | | * @param[in] i1_pic_order_cnt_lsb |
3542 | | * Current POC lsb |
3543 | | * |
3544 | | * @returns Current absolute POC |
3545 | | * |
3546 | | * @remarks |
3547 | | * |
3548 | | * |
3549 | | ******************************************************************************* |
3550 | | */ |
3551 | | |
3552 | | WORD32 ihevcd_calc_poc(codec_t *ps_codec, nal_header_t *ps_nal, WORD8 i1_log2_max_poc_lsb, WORD32 i2_poc_lsb) |
3553 | 54.1k | { |
3554 | 54.1k | WORD32 i4_abs_poc, i4_poc_msb; |
3555 | 54.1k | WORD32 max_poc_lsb; |
3556 | 54.1k | WORD8 i1_nal_unit_type = ps_nal->i1_nal_unit_type; |
3557 | 54.1k | max_poc_lsb = (1 << i1_log2_max_poc_lsb); |
3558 | | |
3559 | 54.1k | if((!ps_codec->i4_first_pic_done) && (!ps_codec->i4_pic_present)) |
3560 | 9.45k | ps_codec->i4_prev_poc_msb = -2 * max_poc_lsb; |
3561 | | |
3562 | 54.1k | if(NAL_IDR_N_LP == i1_nal_unit_type |
3563 | 39.1k | || NAL_IDR_W_LP == i1_nal_unit_type |
3564 | 35.9k | || NAL_BLA_N_LP == i1_nal_unit_type |
3565 | 33.7k | || NAL_BLA_W_DLP == i1_nal_unit_type |
3566 | 24.8k | || NAL_BLA_W_LP == i1_nal_unit_type |
3567 | 23.6k | || (NAL_CRA == i1_nal_unit_type && !ps_codec->i4_first_pic_done)) |
3568 | 30.6k | { |
3569 | 30.6k | i4_poc_msb = ps_codec->i4_prev_poc_msb + 2 * max_poc_lsb; |
3570 | 30.6k | ps_codec->i4_prev_poc_lsb = 0; |
3571 | 30.6k | ps_codec->i4_max_prev_poc_lsb = 0; |
3572 | | // ps_codec->i4_prev_poc_msb = 0; |
3573 | 30.6k | } |
3574 | 23.4k | else |
3575 | 23.4k | { |
3576 | | |
3577 | 23.4k | if((i2_poc_lsb < ps_codec->i4_prev_poc_lsb) |
3578 | 3.74k | && ((ps_codec->i4_prev_poc_lsb - i2_poc_lsb) >= max_poc_lsb / 2)) |
3579 | 65 | { |
3580 | 65 | i4_poc_msb = ps_codec->i4_prev_poc_msb + max_poc_lsb; |
3581 | 65 | } |
3582 | 23.4k | else if((i2_poc_lsb > ps_codec->i4_prev_poc_lsb) |
3583 | 17.6k | && ((i2_poc_lsb - ps_codec->i4_prev_poc_lsb) > max_poc_lsb / 2)) |
3584 | 8.74k | { |
3585 | 8.74k | i4_poc_msb = ps_codec->i4_prev_poc_msb - max_poc_lsb; |
3586 | 8.74k | } |
3587 | 14.6k | else |
3588 | 14.6k | { |
3589 | 14.6k | i4_poc_msb = ps_codec->i4_prev_poc_msb; |
3590 | 14.6k | } |
3591 | | |
3592 | | |
3593 | 23.4k | } |
3594 | | |
3595 | 54.1k | i4_abs_poc = i4_poc_msb + i2_poc_lsb; |
3596 | 54.1k | ps_codec->i4_max_prev_poc_lsb = MAX(ps_codec->i4_max_prev_poc_lsb, i2_poc_lsb); |
3597 | | |
3598 | 54.1k | { |
3599 | 54.1k | WORD32 is_reference_nal = ((i1_nal_unit_type <= NAL_RSV_VCL_R15) && (i1_nal_unit_type % 2 != 0)) || ((i1_nal_unit_type >= NAL_BLA_W_LP) && (i1_nal_unit_type <= NAL_RSV_RAP_VCL23)); |
3600 | 54.1k | WORD32 update_prev_poc = ((is_reference_nal) && ((i1_nal_unit_type < NAL_RADL_N) || (i1_nal_unit_type > NAL_RASL_R))); |
3601 | | |
3602 | 54.1k | if((0 == ps_nal->i1_nuh_temporal_id) && |
3603 | 25.7k | (update_prev_poc)) |
3604 | 21.9k | { |
3605 | 21.9k | ps_codec->i4_prev_poc_lsb = i2_poc_lsb; |
3606 | 21.9k | ps_codec->i4_prev_poc_msb = i4_poc_msb; |
3607 | 21.9k | } |
3608 | 54.1k | } |
3609 | | |
3610 | 54.1k | return i4_abs_poc; |
3611 | 54.1k | } |
3612 | | |
3613 | | |
3614 | | void ihevcd_copy_slice_hdr(codec_t *ps_codec, WORD32 slice_idx, WORD32 slice_idx_ref) |
3615 | 9.81k | { |
3616 | 9.81k | slice_header_t *ps_slice_hdr, *ps_slice_hdr_ref; |
3617 | 9.81k | WORD32 *pu4_entry_offset_backup; |
3618 | | |
3619 | 9.81k | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr_base + slice_idx; |
3620 | 9.81k | ps_slice_hdr_ref = ps_codec->s_parse.ps_slice_hdr_base + slice_idx_ref; |
3621 | | |
3622 | 9.81k | pu4_entry_offset_backup = ps_slice_hdr->pu4_entry_point_offset; |
3623 | 9.81k | memcpy(ps_slice_hdr, ps_slice_hdr_ref, sizeof(slice_header_t)); |
3624 | 9.81k | ps_slice_hdr->pu4_entry_point_offset = pu4_entry_offset_backup; |
3625 | 9.81k | } |
3626 | | |
3627 | | |
3628 | | |