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
46 #include "ihevc_typedefs.h"
47 #include "iv.h"
48 #include "ivd.h"
49 #include "ihevcd_cxa.h"
50
51 #include "ihevc_defs.h"
52 #include "ihevc_debug.h"
53 #include "ihevc_defs.h"
54 #include "ihevc_structs.h"
55 #include "ihevc_buf_mgr.h"
56 #include "ihevc_dpb_mgr.h"
57 #include "ihevc_macros.h"
58 #include "ihevc_platform_macros.h"
59 #include "ihevc_cabac_tables.h"
60 #include "ihevc_common_tables.h"
61 #include "ihevc_quant_tables.h"
62
63 #include "ihevcd_trace.h"
64 #include "ihevcd_defs.h"
65 #include "ihevcd_function_selector.h"
66 #include "ihevcd_structs.h"
67 #include "ihevcd_error.h"
68 #include "ihevcd_debug.h"
69 #include "ihevcd_nal.h"
70 #include "ihevcd_bitstream.h"
71 #include "ihevcd_parse_headers.h"
72 #include "ihevcd_ref_list.h"
73
74 #define COPY_DEFAULT_SCALING_LIST(pi2_scaling_mat) \
75 { \
76 WORD32 scaling_mat_offset[]={0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, 480, 736, 992, 1248, 1504, 1760, 2016, 3040}; \
77 \
78 /* scaling matrix for 4x4 */ \
79 memcpy(pi2_scaling_mat, gi2_flat_scale_mat_32x32, 6*16*sizeof(WORD16)); \
80 /* scaling matrix for 8x8 */ \
81 memcpy(pi2_scaling_mat + scaling_mat_offset[6], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \
82 memcpy(pi2_scaling_mat + scaling_mat_offset[7], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \
83 memcpy(pi2_scaling_mat + scaling_mat_offset[8], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \
84 memcpy(pi2_scaling_mat + scaling_mat_offset[9], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \
85 memcpy(pi2_scaling_mat + scaling_mat_offset[10], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \
86 memcpy(pi2_scaling_mat + scaling_mat_offset[11], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \
87 /* scaling matrix for 16x16 */ \
88 memcpy(pi2_scaling_mat + scaling_mat_offset[12], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \
89 memcpy(pi2_scaling_mat + scaling_mat_offset[13], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \
90 memcpy(pi2_scaling_mat + scaling_mat_offset[14], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \
91 memcpy(pi2_scaling_mat + scaling_mat_offset[15], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \
92 memcpy(pi2_scaling_mat + scaling_mat_offset[16], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \
93 memcpy(pi2_scaling_mat + scaling_mat_offset[17], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \
94 /* scaling matrix for 32x32 */ \
95 memcpy(pi2_scaling_mat + scaling_mat_offset[18], gi2_intra_default_scale_mat_32x32, 1024*sizeof(WORD16)); \
96 memcpy(pi2_scaling_mat + scaling_mat_offset[19], gi2_inter_default_scale_mat_32x32, 1024*sizeof(WORD16)); \
97 }
98
99 #define COPY_FLAT_SCALING_LIST(pi2_scaling_mat) \
100 { \
101 WORD32 scaling_mat_offset[]={0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, 480, 736, 992, 1248, 1504, 1760, 2016, 3040}; \
102 \
103 /* scaling matrix for 4x4 */ \
104 memcpy(pi2_scaling_mat, gi2_flat_scale_mat_32x32, 6*16*sizeof(WORD16)); \
105 /* scaling matrix for 8x8 */ \
106 memcpy(pi2_scaling_mat + scaling_mat_offset[6], gi2_flat_scale_mat_32x32, 6*64*sizeof(WORD16)); \
107 /* scaling matrix for 16x16 */ \
108 memcpy(pi2_scaling_mat + scaling_mat_offset[12], gi2_flat_scale_mat_32x32, 3*256*sizeof(WORD16)); \
109 memcpy(pi2_scaling_mat + scaling_mat_offset[15], gi2_flat_scale_mat_32x32, 3*256*sizeof(WORD16)); \
110 /* scaling matrix for 32x32 */ \
111 memcpy(pi2_scaling_mat + scaling_mat_offset[18], gi2_flat_scale_mat_32x32, 1024*sizeof(WORD16)); \
112 memcpy(pi2_scaling_mat + scaling_mat_offset[19], gi2_flat_scale_mat_32x32, 1024*sizeof(WORD16)); \
113 }
114
115 /* Function declarations */
116
117 /**
118 *******************************************************************************
119 *
120 * @brief
121 * Parses Prediction weight table syntax
122 *
123 * @par Description:
124 * Parse Prediction weight table syntax as per Section: 7.3.8.4
125 *
126 * @param[in] ps_bitstrm
127 * Pointer to bitstream context
128 *
129 * @param[in] ps_sps
130 * Current SPS
131 *
132 * @param[in] ps_pps
133 * Current PPS
134 *
135 * @param[in] ps_slice_hdr
136 * Current Slice header
137 *
138 * @returns Error code from IHEVCD_ERROR_T
139 *
140 * @remarks
141 *
142 *
143 *******************************************************************************
144 */
145
ihevcd_parse_pred_wt_ofst(bitstrm_t * ps_bitstrm,sps_t * ps_sps,pps_t * ps_pps,slice_header_t * ps_slice_hdr)146 WORD32 ihevcd_parse_pred_wt_ofst(bitstrm_t *ps_bitstrm,
147 sps_t *ps_sps,
148 pps_t *ps_pps,
149 slice_header_t *ps_slice_hdr)
150 {
151 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
152 WORD32 value;
153 WORD32 i;
154
155 pred_wt_ofst_t *ps_wt_ofst = &ps_slice_hdr->s_wt_ofst;
156 UNUSED(ps_pps);
157
158 UEV_PARSE("luma_log2_weight_denom", value, ps_bitstrm);
159 ps_wt_ofst->i1_luma_log2_weight_denom = value;
160
161 if(ps_sps->i1_chroma_format_idc != 0)
162 {
163 SEV_PARSE("delta_chroma_log2_weight_denom", value, ps_bitstrm);
164 ps_wt_ofst->i1_chroma_log2_weight_denom = ps_wt_ofst->i1_luma_log2_weight_denom + value;
165 }
166
167 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++)
168 {
169 BITS_PARSE("luma_weight_l0_flag[ i ]", value, ps_bitstrm, 1);
170 ps_wt_ofst->i1_luma_weight_l0_flag[i] = value;
171 }
172
173
174
175 if(ps_sps->i1_chroma_format_idc != 0)
176 {
177 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++)
178 {
179 BITS_PARSE("chroma_weight_l0_flag[ i ]", value, ps_bitstrm, 1);
180 ps_wt_ofst->i1_chroma_weight_l0_flag[i] = value;
181 }
182 }
183 else
184 {
185 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++)
186 {
187 ps_wt_ofst->i1_chroma_weight_l0_flag[i] = 0;
188 }
189 }
190
191
192 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++)
193 {
194 if(ps_wt_ofst->i1_luma_weight_l0_flag[i])
195 {
196 SEV_PARSE("delta_luma_weight_l0[ i ]", value, ps_bitstrm);
197
198
199 ps_wt_ofst->i2_luma_weight_l0[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom) + value;
200
201 SEV_PARSE("luma_offset_l0[ i ]", value, ps_bitstrm);
202 ps_wt_ofst->i2_luma_offset_l0[i] = value;
203
204 }
205 else
206 {
207 ps_wt_ofst->i2_luma_weight_l0[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom);
208 ps_wt_ofst->i2_luma_offset_l0[i] = 0;
209 }
210 if(ps_wt_ofst->i1_chroma_weight_l0_flag[i])
211 {
212 WORD32 ofst;
213 WORD32 shift = (1 << (BIT_DEPTH_CHROMA - 1));
214 SEV_PARSE("delta_chroma_weight_l0[ i ][ j ]", value, ps_bitstrm);
215 ps_wt_ofst->i2_chroma_weight_l0_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value;
216
217
218 SEV_PARSE("delta_chroma_offset_l0[ i ][ j ]", value, ps_bitstrm);
219 ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l0_cb[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom);
220 ofst = value - ofst + shift;
221
222 ps_wt_ofst->i2_chroma_offset_l0_cb[i] = CLIP_S8(ofst);
223
224 SEV_PARSE("delta_chroma_weight_l0[ i ][ j ]", value, ps_bitstrm);
225 ps_wt_ofst->i2_chroma_weight_l0_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value;
226
227
228 SEV_PARSE("delta_chroma_offset_l0[ i ][ j ]", value, ps_bitstrm);
229 ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l0_cr[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom);
230 ofst = value - ofst + shift;
231
232 ps_wt_ofst->i2_chroma_offset_l0_cr[i] = CLIP_S8(ofst);
233
234 }
235 else
236 {
237 ps_wt_ofst->i2_chroma_weight_l0_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom);
238 ps_wt_ofst->i2_chroma_weight_l0_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom);
239
240 ps_wt_ofst->i2_chroma_offset_l0_cb[i] = 0;
241 ps_wt_ofst->i2_chroma_offset_l0_cr[i] = 0;
242 }
243 }
244 if(BSLICE == ps_slice_hdr->i1_slice_type)
245 {
246 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++)
247 {
248 BITS_PARSE("luma_weight_l1_flag[ i ]", value, ps_bitstrm, 1);
249 ps_wt_ofst->i1_luma_weight_l1_flag[i] = value;
250 }
251
252 if(ps_sps->i1_chroma_format_idc != 0)
253 {
254 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++)
255 {
256 BITS_PARSE("chroma_weight_l1_flag[ i ]", value, ps_bitstrm, 1);
257 ps_wt_ofst->i1_chroma_weight_l1_flag[i] = value;
258 }
259 }
260 else
261 {
262 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++)
263 {
264 ps_wt_ofst->i1_chroma_weight_l1_flag[i] = 0;
265 }
266 }
267
268 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++)
269 {
270 if(ps_wt_ofst->i1_luma_weight_l1_flag[i])
271 {
272 SEV_PARSE("delta_luma_weight_l1[ i ]", value, ps_bitstrm);
273
274
275 ps_wt_ofst->i2_luma_weight_l1[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom) + value;
276
277 SEV_PARSE("luma_offset_l1[ i ]", value, ps_bitstrm);
278 ps_wt_ofst->i2_luma_offset_l1[i] = value;
279
280 }
281 else
282 {
283 ps_wt_ofst->i2_luma_weight_l1[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom);
284 ps_wt_ofst->i2_luma_offset_l1[i] = 0;
285 }
286
287 if(ps_wt_ofst->i1_chroma_weight_l1_flag[i])
288 {
289 WORD32 ofst;
290 WORD32 shift = (1 << (BIT_DEPTH_CHROMA - 1));
291 SEV_PARSE("delta_chroma_weight_l1[ i ][ j ]", value, ps_bitstrm);
292 ps_wt_ofst->i2_chroma_weight_l1_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value;;
293
294
295 SEV_PARSE("delta_chroma_offset_l1[ i ][ j ]", value, ps_bitstrm);
296 ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l1_cb[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom);
297 ofst = value - ofst + shift;
298
299 ps_wt_ofst->i2_chroma_offset_l1_cb[i] = CLIP_S8(ofst);;
300
301 SEV_PARSE("delta_chroma_weight_l1[ i ][ j ]", value, ps_bitstrm);
302 ps_wt_ofst->i2_chroma_weight_l1_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value;
303
304
305 SEV_PARSE("delta_chroma_offset_l1[ i ][ j ]", value, ps_bitstrm);
306 ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l1_cr[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom);
307 ofst = value - ofst + shift;
308
309 ps_wt_ofst->i2_chroma_offset_l1_cr[i] = CLIP_S8(ofst);;
310
311 }
312 else
313 {
314 ps_wt_ofst->i2_chroma_weight_l1_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom);
315 ps_wt_ofst->i2_chroma_weight_l1_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom);
316
317 ps_wt_ofst->i2_chroma_offset_l1_cb[i] = 0;
318 ps_wt_ofst->i2_chroma_offset_l1_cr[i] = 0;
319
320 }
321 }
322 }
323 return ret;
324 }
325
326 /**
327 *******************************************************************************
328 *
329 * @brief
330 * Parses short term reference picture set
331 *
332 * @par Description
333 * Parses short term reference picture set as per section 7.3.8.2.
334 * Can be called by either SPS or Slice header parsing modules.
335 *
336 * @param[in] ps_bitstrm
337 * Pointer to bitstream structure
338 *
339 * @param[out] ps_stref_picset_base
340 * Pointer to first short term ref pic set structure
341 *
342 * @param[in] num_short_term_ref_pic_sets
343 * Number of short term reference pic sets
344 *
345 * @param[in] idx
346 * Current short term ref pic set id
347 *
348 * @returns Error code from IHEVCD_ERROR_T
349 *
350 * @remarks
351 *
352 *******************************************************************************
353 */
ihevcd_short_term_ref_pic_set(bitstrm_t * ps_bitstrm,stref_picset_t * ps_stref_picset_base,WORD32 num_short_term_ref_pic_sets,WORD32 idx,stref_picset_t * ps_stref_picset)354 IHEVCD_ERROR_T ihevcd_short_term_ref_pic_set(bitstrm_t *ps_bitstrm,
355 stref_picset_t *ps_stref_picset_base,
356 WORD32 num_short_term_ref_pic_sets,
357 WORD32 idx,
358 stref_picset_t *ps_stref_picset)
359 {
360 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
361 WORD32 value;
362 stref_picset_t *ps_stref_picset_ref;
363 WORD32 delta_idx, delta_rps;
364 WORD32 r_idx;
365 WORD32 i;
366 WORD32 j, k, temp;
367 if(idx > 0)
368 {
369 BITS_PARSE("inter_ref_pic_set_prediction_flag", value, ps_bitstrm, 1);
370 ps_stref_picset->i1_inter_ref_pic_set_prediction_flag = value;
371 }
372 else
373 ps_stref_picset->i1_inter_ref_pic_set_prediction_flag = 0;
374
375 if(ps_stref_picset->i1_inter_ref_pic_set_prediction_flag)
376 {
377 WORD32 delta_rps_sign;
378 WORD32 abs_delta_rps;
379 WORD32 num_neg_pics = 0;
380 WORD32 num_pos_pics = 0;
381 WORD32 num_pics = 0;
382
383 if(idx == num_short_term_ref_pic_sets)
384 {
385 UEV_PARSE("delta_idx_minus1", value, ps_bitstrm);
386 delta_idx = value + 1;
387 }
388 else
389 {
390 delta_idx = 1;
391 }
392 r_idx = idx - delta_idx;
393 r_idx = CLIP3(r_idx, 0, idx - 1);
394
395 ps_stref_picset_ref = ps_stref_picset_base + r_idx;
396
397 BITS_PARSE("delta_rps_sign", value, ps_bitstrm, 1);
398 delta_rps_sign = value;
399
400 UEV_PARSE("abs_delta_rps_minus1", value, ps_bitstrm);
401 abs_delta_rps = value + 1;
402
403 delta_rps = (1 - 2 * delta_rps_sign) * (abs_delta_rps);
404
405
406
407 for(i = 0; i <= ps_stref_picset_ref->i1_num_delta_pocs; i++)
408 {
409 WORD32 ref_idc;
410
411 /*****************************************************************/
412 /* ref_idc is parsed as below */
413 /* bits "1" ref_idc 1 */
414 /* bits "01" ref_idc 2 */
415 /* bits "00" ref_idc 0 */
416 /*****************************************************************/
417 BITS_PARSE("used_by_curr_pic_flag", value, ps_bitstrm, 1);
418 ref_idc = value;
419 ps_stref_picset->ai1_used[num_pics] = value;
420 /* If ref_idc is zero check for next bit */
421 if(0 == ref_idc)
422 {
423 BITS_PARSE("use_delta_flag", value, ps_bitstrm, 1);
424 ps_stref_picset->ai1_used[i] = value;
425 ref_idc = value << 1;
426 }
427 if((ref_idc == 1) || (ref_idc == 2))
428 {
429 WORD32 delta_poc;
430 delta_poc = delta_rps;
431 delta_poc +=
432 ((i < ps_stref_picset_ref->i1_num_delta_pocs) ?
433 ps_stref_picset_ref->ai2_delta_poc[i] :
434 0);
435
436 ps_stref_picset->ai2_delta_poc[num_pics] = delta_poc;
437
438 if(delta_poc < 0)
439 {
440 num_neg_pics++;
441 }
442 else
443 {
444 num_pos_pics++;
445 }
446 num_pics++;
447 }
448 ps_stref_picset->ai1_ref_idc[i] = ref_idc;
449 }
450
451 num_neg_pics = CLIP3(num_neg_pics, 0, MAX_DPB_SIZE - 1);
452 num_pos_pics = CLIP3(num_pos_pics, 0, (MAX_DPB_SIZE - 1 - num_neg_pics));
453 num_pics = num_neg_pics + num_pos_pics;
454
455 ps_stref_picset->i1_num_ref_idc =
456 ps_stref_picset_ref->i1_num_delta_pocs + 1;
457 ps_stref_picset->i1_num_delta_pocs = num_pics;
458 ps_stref_picset->i1_num_pos_pics = num_pos_pics;
459 ps_stref_picset->i1_num_neg_pics = num_neg_pics;
460
461
462 for(j = 1; j < num_pics; j++)
463 {
464 WORD32 delta_poc = ps_stref_picset->ai2_delta_poc[j];
465 WORD8 i1_used = ps_stref_picset->ai1_used[j];
466 for(k = j - 1; k >= 0; k--)
467 {
468 temp = ps_stref_picset->ai2_delta_poc[k];
469 if(delta_poc < temp)
470 {
471 ps_stref_picset->ai2_delta_poc[k + 1] = temp;
472 ps_stref_picset->ai1_used[k + 1] = ps_stref_picset->ai1_used[k];
473 ps_stref_picset->ai2_delta_poc[k] = delta_poc;
474 ps_stref_picset->ai1_used[k] = i1_used;
475 }
476 }
477 }
478 // flip the negative values to largest first
479 for(j = 0, k = num_neg_pics - 1; j < num_neg_pics >> 1; j++, k--)
480 {
481 WORD32 delta_poc = ps_stref_picset->ai2_delta_poc[j];
482 WORD8 i1_used = ps_stref_picset->ai1_used[j];
483 ps_stref_picset->ai2_delta_poc[j] = ps_stref_picset->ai2_delta_poc[k];
484 ps_stref_picset->ai1_used[j] = ps_stref_picset->ai1_used[k];
485 ps_stref_picset->ai2_delta_poc[k] = delta_poc;
486 ps_stref_picset->ai1_used[k] = i1_used;
487 }
488
489 }
490 else
491 {
492 WORD32 prev_poc = 0;
493 WORD32 poc;
494
495 UEV_PARSE("num_negative_pics", value, ps_bitstrm);
496 ps_stref_picset->i1_num_neg_pics = value;
497 ps_stref_picset->i1_num_neg_pics = CLIP3(ps_stref_picset->i1_num_neg_pics,
498 0,
499 MAX_DPB_SIZE - 1);
500
501 UEV_PARSE("num_positive_pics", value, ps_bitstrm);
502 ps_stref_picset->i1_num_pos_pics = value;
503 ps_stref_picset->i1_num_pos_pics = CLIP3(ps_stref_picset->i1_num_pos_pics,
504 0,
505 (MAX_DPB_SIZE - 1 - ps_stref_picset->i1_num_neg_pics));
506
507 ps_stref_picset->i1_num_delta_pocs =
508 ps_stref_picset->i1_num_neg_pics +
509 ps_stref_picset->i1_num_pos_pics;
510
511
512 for(i = 0; i < ps_stref_picset->i1_num_neg_pics; i++)
513 {
514 UEV_PARSE("delta_poc_s0_minus1", value, ps_bitstrm);
515 poc = prev_poc - (value + 1);
516 prev_poc = poc;
517 ps_stref_picset->ai2_delta_poc[i] = poc;
518
519 BITS_PARSE("used_by_curr_pic_s0_flag", value, ps_bitstrm, 1);
520 ps_stref_picset->ai1_used[i] = value;
521
522 }
523 prev_poc = 0;
524 for(i = ps_stref_picset->i1_num_neg_pics;
525 i < ps_stref_picset->i1_num_delta_pocs;
526 i++)
527 {
528 UEV_PARSE("delta_poc_s1_minus1", value, ps_bitstrm);
529 poc = prev_poc + (value + 1);
530 prev_poc = poc;
531 ps_stref_picset->ai2_delta_poc[i] = poc;
532
533 BITS_PARSE("used_by_curr_pic_s1_flag", value, ps_bitstrm, 1);
534 ps_stref_picset->ai1_used[i] = value;
535
536 }
537
538 }
539
540 return ret;
541 }
542
543
ihevcd_parse_sub_layer_hrd_parameters(bitstrm_t * ps_bitstrm,sub_lyr_hrd_params_t * ps_sub_layer_hrd_params,WORD32 cpb_cnt,WORD32 sub_pic_cpb_params_present_flag)544 static WORD32 ihevcd_parse_sub_layer_hrd_parameters(bitstrm_t *ps_bitstrm,
545 sub_lyr_hrd_params_t *ps_sub_layer_hrd_params,
546 WORD32 cpb_cnt,
547 WORD32 sub_pic_cpb_params_present_flag)
548 {
549 WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
550 WORD32 i;
551
552 for(i = 0; i <= cpb_cnt; i++)
553 {
554 UEV_PARSE("bit_rate_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_bit_rate_value_minus1[i], ps_bitstrm);
555 UEV_PARSE("cpb_size_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_cpb_size_value_minus1[i], ps_bitstrm);
556
557 if(sub_pic_cpb_params_present_flag)
558 {
559 UEV_PARSE("cpb_size_du_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_cpb_size_du_value_minus1[i], ps_bitstrm);
560 UEV_PARSE("bit_rate_du_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_bit_rate_du_value_minus1[i], ps_bitstrm);
561 }
562 BITS_PARSE("cbr_flag[ i ]", ps_sub_layer_hrd_params->au1_cbr_flag[i], ps_bitstrm, 1);
563 }
564
565 return ret;
566 }
567
568
ihevcd_parse_hrd_parameters(bitstrm_t * ps_bitstrm,hrd_params_t * ps_hrd,WORD32 common_info_present_flag,WORD32 max_num_sub_layers_minus1)569 static WORD32 ihevcd_parse_hrd_parameters(bitstrm_t *ps_bitstrm,
570 hrd_params_t *ps_hrd,
571 WORD32 common_info_present_flag,
572 WORD32 max_num_sub_layers_minus1)
573 {
574 WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
575 WORD32 i;
576
577 ps_hrd->u1_nal_hrd_parameters_present_flag = 0;
578 ps_hrd->u1_vcl_hrd_parameters_present_flag = 0;
579
580 ps_hrd->u1_sub_pic_cpb_params_present_flag = 0;
581
582 ps_hrd->u1_tick_divisor_minus2 = 0;
583 ps_hrd->u1_du_cpb_removal_delay_increment_length_minus1 = 0;
584 ps_hrd->u1_sub_pic_cpb_params_in_pic_timing_sei_flag = 0;
585 ps_hrd->u1_dpb_output_delay_du_length_minus1 = 0;
586
587 ps_hrd->u4_bit_rate_scale = 0;
588 ps_hrd->u4_cpb_size_scale = 0;
589 ps_hrd->u4_cpb_size_du_scale = 0;
590
591 ps_hrd->u1_initial_cpb_removal_delay_length_minus1 = 23;
592 ps_hrd->u1_au_cpb_removal_delay_length_minus1 = 23;
593 ps_hrd->u1_dpb_output_delay_length_minus1 = 23;
594
595 if(common_info_present_flag)
596 {
597 BITS_PARSE("nal_hrd_parameters_present_flag", ps_hrd->u1_nal_hrd_parameters_present_flag, ps_bitstrm, 1);
598 BITS_PARSE("vcl_hrd_parameters_present_flag", ps_hrd->u1_vcl_hrd_parameters_present_flag, ps_bitstrm, 1);
599
600 if(ps_hrd->u1_nal_hrd_parameters_present_flag || ps_hrd->u1_vcl_hrd_parameters_present_flag)
601 {
602 BITS_PARSE("sub_pic_cpb_params_present_flag", ps_hrd->u1_sub_pic_cpb_params_present_flag, ps_bitstrm, 1);
603 if(ps_hrd->u1_sub_pic_cpb_params_present_flag)
604 {
605 BITS_PARSE("tick_divisor_minus2", ps_hrd->u1_tick_divisor_minus2, ps_bitstrm, 8);
606 BITS_PARSE("du_cpb_removal_delay_increment_length_minus1", ps_hrd->u1_du_cpb_removal_delay_increment_length_minus1, ps_bitstrm, 5);
607 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);
608 BITS_PARSE("dpb_output_delay_du_length_minus1", ps_hrd->u1_dpb_output_delay_du_length_minus1, ps_bitstrm, 5);
609 }
610
611 BITS_PARSE("bit_rate_scale", ps_hrd->u4_bit_rate_scale, ps_bitstrm, 4);
612 BITS_PARSE("cpb_size_scale", ps_hrd->u4_cpb_size_scale, ps_bitstrm, 4);
613 if(ps_hrd->u1_sub_pic_cpb_params_present_flag)
614 BITS_PARSE("cpb_size_du_scale", ps_hrd->u4_cpb_size_du_scale, ps_bitstrm, 4);
615
616 BITS_PARSE("initial_cpb_removal_delay_length_minus1", ps_hrd->u1_initial_cpb_removal_delay_length_minus1, ps_bitstrm, 5);
617 BITS_PARSE("au_cpb_removal_delay_length_minus1", ps_hrd->u1_au_cpb_removal_delay_length_minus1, ps_bitstrm, 5);
618 BITS_PARSE("dpb_output_delay_length_minus1", ps_hrd->u1_dpb_output_delay_length_minus1, ps_bitstrm, 5);
619 }
620 }
621
622
623 for(i = 0; i <= max_num_sub_layers_minus1; i++)
624 {
625 BITS_PARSE("fixed_pic_rate_general_flag[ i ]", ps_hrd->au1_fixed_pic_rate_general_flag[i], ps_bitstrm, 1);
626
627 ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i] = 1;
628 ps_hrd->au1_elemental_duration_in_tc_minus1[i] = 0;
629 ps_hrd->au1_low_delay_hrd_flag[i] = 0;
630 ps_hrd->au1_cpb_cnt_minus1[i] = 0;
631
632 if(!ps_hrd->au1_fixed_pic_rate_general_flag[i])
633 BITS_PARSE("fixed_pic_rate_within_cvs_flag[ i ]", ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i], ps_bitstrm, 1);
634
635 if(ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i])
636 {
637 UEV_PARSE("elemental_duration_in_tc_minus1[ i ]", ps_hrd->au1_elemental_duration_in_tc_minus1[i], ps_bitstrm);
638 }
639 else
640 {
641 BITS_PARSE("low_delay_hrd_flag[ i ]", ps_hrd->au1_low_delay_hrd_flag[i], ps_bitstrm, 1);
642 }
643
644 if(!ps_hrd->au1_low_delay_hrd_flag[i])
645 UEV_PARSE("cpb_cnt_minus1[ i ]", ps_hrd->au1_cpb_cnt_minus1[i], ps_bitstrm);
646
647 if(ps_hrd->u1_nal_hrd_parameters_present_flag)
648 ihevcd_parse_sub_layer_hrd_parameters(ps_bitstrm,
649 &ps_hrd->as_sub_layer_hrd_params[i],
650 ps_hrd->au1_cpb_cnt_minus1[i],
651 ps_hrd->u1_sub_pic_cpb_params_present_flag);
652
653 if(ps_hrd->u1_vcl_hrd_parameters_present_flag)
654 ihevcd_parse_sub_layer_hrd_parameters(ps_bitstrm,
655 &ps_hrd->as_sub_layer_hrd_params[i],
656 ps_hrd->au1_cpb_cnt_minus1[i],
657 ps_hrd->u1_sub_pic_cpb_params_present_flag);
658 }
659
660 return ret;
661 }
662
663
ihevcd_parse_vui_parameters(bitstrm_t * ps_bitstrm,vui_t * ps_vui,WORD32 sps_max_sub_layers_minus1)664 static WORD32 ihevcd_parse_vui_parameters(bitstrm_t *ps_bitstrm,
665 vui_t *ps_vui,
666 WORD32 sps_max_sub_layers_minus1)
667 {
668 WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
669
670 BITS_PARSE("aspect_ratio_info_present_flag", ps_vui->u1_aspect_ratio_info_present_flag, ps_bitstrm, 1);
671
672 ps_vui->u1_aspect_ratio_idc = SAR_UNUSED;
673 ps_vui->u2_sar_width = 0;
674 ps_vui->u2_sar_height = 0;
675 if(ps_vui->u1_aspect_ratio_info_present_flag)
676 {
677 BITS_PARSE("aspect_ratio_idc", ps_vui->u1_aspect_ratio_idc, ps_bitstrm, 8);
678 if(ps_vui->u1_aspect_ratio_idc == EXTENDED_SAR)
679 {
680 BITS_PARSE("sar_width", ps_vui->u2_sar_width, ps_bitstrm, 16);
681 BITS_PARSE("sar_height", ps_vui->u2_sar_height, ps_bitstrm, 16);
682 }
683 }
684
685 BITS_PARSE("overscan_info_present_flag", ps_vui->u1_overscan_info_present_flag, ps_bitstrm, 1);
686 ps_vui->u1_overscan_appropriate_flag = 0;
687 if(ps_vui->u1_overscan_info_present_flag)
688 BITS_PARSE("overscan_appropriate_flag", ps_vui->u1_overscan_appropriate_flag, ps_bitstrm, 1);
689
690 BITS_PARSE("video_signal_type_present_flag", ps_vui->u1_video_signal_type_present_flag, ps_bitstrm, 1);
691 ps_vui->u1_video_format = VID_FMT_UNSPECIFIED;
692 ps_vui->u1_video_full_range_flag = 0;
693 ps_vui->u1_colour_description_present_flag = 0;
694 if(ps_vui->u1_video_signal_type_present_flag)
695 {
696 BITS_PARSE("video_format", ps_vui->u1_video_format, ps_bitstrm, 3);
697 BITS_PARSE("video_full_range_flag", ps_vui->u1_video_full_range_flag, ps_bitstrm, 1);
698 BITS_PARSE("colour_description_present_flag", ps_vui->u1_colour_description_present_flag, ps_bitstrm, 1);
699 ps_vui->u1_colour_primaries = 2;
700 ps_vui->u1_transfer_characteristics = 2;
701 if(ps_vui->u1_colour_description_present_flag)
702 {
703 BITS_PARSE("colour_primaries", ps_vui->u1_colour_primaries, ps_bitstrm, 8);
704 BITS_PARSE("transfer_characteristics", ps_vui->u1_transfer_characteristics, ps_bitstrm, 8);
705 BITS_PARSE("matrix_coeffs", ps_vui->u1_matrix_coefficients, ps_bitstrm, 8);
706 }
707 }
708
709 BITS_PARSE("chroma_loc_info_present_flag", ps_vui->u1_chroma_loc_info_present_flag, ps_bitstrm, 1);
710 ps_vui->u1_chroma_sample_loc_type_top_field = 0;
711 ps_vui->u1_chroma_sample_loc_type_bottom_field = 0;
712 if(ps_vui->u1_chroma_loc_info_present_flag)
713 {
714 UEV_PARSE("chroma_sample_loc_type_top_field", ps_vui->u1_chroma_sample_loc_type_top_field, ps_bitstrm);
715 UEV_PARSE("chroma_sample_loc_type_bottom_field", ps_vui->u1_chroma_sample_loc_type_bottom_field, ps_bitstrm);
716 }
717
718 BITS_PARSE("neutral_chroma_indication_flag", ps_vui->u1_neutral_chroma_indication_flag, ps_bitstrm, 1);
719 BITS_PARSE("field_seq_flag", ps_vui->u1_field_seq_flag, ps_bitstrm, 1);
720 BITS_PARSE("frame_field_info_present_flag", ps_vui->u1_frame_field_info_present_flag, ps_bitstrm, 1);
721 BITS_PARSE("default_display_window_flag", ps_vui->u1_default_display_window_flag, ps_bitstrm, 1);
722 ps_vui->u4_def_disp_win_left_offset = 0;
723 ps_vui->u4_def_disp_win_right_offset = 0;
724 ps_vui->u4_def_disp_win_top_offset = 0;
725 ps_vui->u4_def_disp_win_bottom_offset = 0;
726 if(ps_vui->u1_default_display_window_flag)
727 {
728 UEV_PARSE("def_disp_win_left_offset", ps_vui->u4_def_disp_win_left_offset, ps_bitstrm);
729 UEV_PARSE("def_disp_win_right_offset", ps_vui->u4_def_disp_win_right_offset, ps_bitstrm);
730 UEV_PARSE("def_disp_win_top_offset", ps_vui->u4_def_disp_win_top_offset, ps_bitstrm);
731 UEV_PARSE("def_disp_win_bottom_offset", ps_vui->u4_def_disp_win_bottom_offset, ps_bitstrm);
732 }
733
734 BITS_PARSE("vui_timing_info_present_flag", ps_vui->u1_vui_timing_info_present_flag, ps_bitstrm, 1);
735 if(ps_vui->u1_vui_timing_info_present_flag)
736 {
737 BITS_PARSE("vui_num_units_in_tick", ps_vui->u4_vui_num_units_in_tick, ps_bitstrm, 32);
738 BITS_PARSE("vui_time_scale", ps_vui->u4_vui_time_scale, ps_bitstrm, 32);
739 BITS_PARSE("vui_poc_proportional_to_timing_flag", ps_vui->u1_poc_proportional_to_timing_flag, ps_bitstrm, 1);
740 if(ps_vui->u1_poc_proportional_to_timing_flag)
741 UEV_PARSE("vui_num_ticks_poc_diff_one_minus1", ps_vui->u1_num_ticks_poc_diff_one_minus1, ps_bitstrm);
742
743 BITS_PARSE("vui_hrd_parameters_present_flag", ps_vui->u1_vui_hrd_parameters_present_flag, ps_bitstrm, 1);
744 if(ps_vui->u1_vui_hrd_parameters_present_flag)
745 ihevcd_parse_hrd_parameters(ps_bitstrm, &ps_vui->s_vui_hrd_parameters, 1, sps_max_sub_layers_minus1);
746 }
747
748 BITS_PARSE("bitstream_restriction_flag", ps_vui->u1_bitstream_restriction_flag, ps_bitstrm, 1);
749 ps_vui->u1_tiles_fixed_structure_flag = 0;
750 ps_vui->u1_motion_vectors_over_pic_boundaries_flag = 1;
751 ps_vui->u1_restricted_ref_pic_lists_flag = 0;
752 ps_vui->u4_min_spatial_segmentation_idc = 0;
753 ps_vui->u1_max_bytes_per_pic_denom = 2;
754 ps_vui->u1_max_bits_per_mincu_denom = 1;
755 ps_vui->u1_log2_max_mv_length_horizontal = 15;
756 ps_vui->u1_log2_max_mv_length_vertical = 15;
757 if(ps_vui->u1_bitstream_restriction_flag)
758 {
759 BITS_PARSE("tiles_fixed_structure_flag", ps_vui->u1_tiles_fixed_structure_flag, ps_bitstrm, 1);
760 BITS_PARSE("motion_vectors_over_pic_boundaries_flag", ps_vui->u1_motion_vectors_over_pic_boundaries_flag, ps_bitstrm, 1);
761 BITS_PARSE("restricted_ref_pic_lists_flag", ps_vui->u1_restricted_ref_pic_lists_flag, ps_bitstrm, 1);
762
763 UEV_PARSE("min_spatial_segmentation_idc", ps_vui->u4_min_spatial_segmentation_idc, ps_bitstrm);
764 UEV_PARSE("max_bytes_per_pic_denom", ps_vui->u1_max_bytes_per_pic_denom, ps_bitstrm);
765 UEV_PARSE("max_bits_per_min_cu_denom", ps_vui->u1_max_bits_per_mincu_denom, ps_bitstrm);
766 UEV_PARSE("log2_max_mv_length_horizontal", ps_vui->u1_log2_max_mv_length_horizontal, ps_bitstrm);
767 UEV_PARSE("log2_max_mv_length_vertical", ps_vui->u1_log2_max_mv_length_vertical, ps_bitstrm);
768 }
769
770 return ret;
771 }
772
773 /**
774 *******************************************************************************
775 *
776 * @brief
777 * Parses profile tier and level info for either general layer of sub_layer
778 *
779 * @par Description
780 * Parses profile tier and level info for either general layer of sub_layer
781 * as per section 7.3.3
782 *
783 * Since the same function is called for parsing general_profile and
784 * sub_layer_profile etc, variables do not specify whether the syntax is
785 * for general or sub_layer. Similarly trace functions also do not differentiate
786 *
787 * @param[in] ps_bitstrm
788 * Pointer to bitstream structure
789 *
790 * @param[out] ps_ptl
791 * Pointer to profile, tier level structure
792 *
793 * @returns Error code from IHEVCD_ERROR_T
794 *
795 * @remarks
796 *
797 *******************************************************************************
798 */
799
ihevcd_parse_profile_tier_level_layer(bitstrm_t * ps_bitstrm,profile_tier_lvl_t * ps_ptl)800 static IHEVCD_ERROR_T ihevcd_parse_profile_tier_level_layer(bitstrm_t *ps_bitstrm,
801 profile_tier_lvl_t *ps_ptl)
802 {
803 WORD32 value;
804 WORD32 i;
805 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
806
807 BITS_PARSE("XXX_profile_space[]", value, ps_bitstrm, 2);
808 ps_ptl->i1_profile_space = value;
809
810 BITS_PARSE("XXX_tier_flag[]", value, ps_bitstrm, 1);
811 ps_ptl->i1_tier_flag = value;
812
813 BITS_PARSE("XXX_profile_idc[]", value, ps_bitstrm, 5);
814 ps_ptl->i1_profile_idc = value;
815
816 for(i = 0; i < MAX_PROFILE_COMPATBLTY; i++)
817 {
818 BITS_PARSE("XXX_profile_compatibility_flag[][j]", value, ps_bitstrm, 1);
819 ps_ptl->ai1_profile_compatibility_flag[i] = value;
820 }
821
822 BITS_PARSE("general_progressive_source_flag", value, ps_bitstrm, 1);
823 ps_ptl->i1_general_progressive_source_flag = value;
824
825 BITS_PARSE("general_interlaced_source_flag", value, ps_bitstrm, 1);
826 ps_ptl->i1_general_progressive_source_flag = value;
827
828 BITS_PARSE("general_non_packed_constraint_flag", value, ps_bitstrm, 1);
829 ps_ptl->i1_general_progressive_source_flag = value;
830
831 BITS_PARSE("general_frame_only_constraint_flag", value, ps_bitstrm, 1);
832 ps_ptl->i1_general_progressive_source_flag = value;
833
834 BITS_PARSE("XXX_reserved_zero_44bits[0..15]", value, ps_bitstrm, 16);
835
836 BITS_PARSE("XXX_reserved_zero_44bits[16..31]", value, ps_bitstrm, 16);
837
838 BITS_PARSE("XXX_reserved_zero_44bits[32..43]", value, ps_bitstrm, 12);
839 return ret;
840 }
841
842
843 /**
844 *******************************************************************************
845 *
846 * @brief
847 * Parses profile tier and level info
848 *
849 * @par Description
850 * Parses profile tier and level info as per section 7.3.3
851 * Called during VPS and SPS parsing
852 * calls ihevcd_parse_profile_tier_level() for general layer and each sub_layers
853 *
854 * @param[in] ps_bitstrm
855 * Pointer to bitstream structure
856 *
857 * @param[out] ps_ptl
858 * Pointer to structure that contains profile, tier level for each layers
859 *
860 * @param[in] profile_present
861 * Flag to indicate if profile data is present
862 *
863 * @param[in] max_num_sub_layers
864 * Number of sub layers present
865 *
866 * @returns Error code from IHEVCD_ERROR_T
867 *
868 * @remarks
869 *
870 *******************************************************************************
871 */
872
ihevcd_profile_tier_level(bitstrm_t * ps_bitstrm,profile_tier_lvl_info_t * ps_ptl,WORD32 profile_present,WORD32 max_num_sub_layers)873 static IHEVCD_ERROR_T ihevcd_profile_tier_level(bitstrm_t *ps_bitstrm,
874 profile_tier_lvl_info_t *ps_ptl,
875 WORD32 profile_present,
876 WORD32 max_num_sub_layers)
877 {
878 WORD32 value;
879 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
880 WORD32 i;
881
882 if(profile_present)
883 {
884 ret = ihevcd_parse_profile_tier_level_layer(ps_bitstrm, &ps_ptl->s_ptl_gen);
885 }
886
887 BITS_PARSE("general_level_idc", value, ps_bitstrm, 8);
888 ps_ptl->s_ptl_gen.u1_level_idc = value;
889
890
891 for(i = 0; i < max_num_sub_layers; i++)
892 {
893 BITS_PARSE("sub_layer_profile_present_flag[i]", value, ps_bitstrm, 1);
894 ps_ptl->ai1_sub_layer_profile_present_flag[i] = value;
895
896 BITS_PARSE("sub_layer_level_present_flag[i]", value, ps_bitstrm, 1);
897 ps_ptl->ai1_sub_layer_level_present_flag[i] = value;
898 }
899
900 if(max_num_sub_layers > 0)
901 {
902 for(i = max_num_sub_layers; i < 8; i++)
903 {
904 BITS_PARSE("reserved_zero_2bits", value, ps_bitstrm, 2);
905 }
906 }
907
908 for(i = 0; i < max_num_sub_layers; i++)
909 {
910 if(ps_ptl->ai1_sub_layer_profile_present_flag[i])
911 {
912 ret = ihevcd_parse_profile_tier_level_layer(ps_bitstrm,
913 &ps_ptl->as_ptl_sub[i]);
914 }
915 if(ps_ptl->ai1_sub_layer_level_present_flag[i])
916 {
917 BITS_PARSE("sub_layer_level_idc[i]", value, ps_bitstrm, 8);
918 ps_ptl->as_ptl_sub[i].u1_level_idc = value;
919
920 }
921 }
922
923
924
925 return ret;
926 }
927
928 /**
929 *******************************************************************************
930 *
931 * @brief
932 * Parses Scaling List Data syntax
933 *
934 * @par Description:
935 * Parses Scaling List Data syntax as per Section: 7.3.6
936 *
937 * @param[in] ps_codec
938 * Pointer to codec context
939 *
940 * @returns Error code from IHEVCD_ERROR_T
941 *
942 * @remarks
943 *
944 *
945 *******************************************************************************
946 */
ihevcd_scaling_list_data(codec_t * ps_codec,WORD16 * pi2_scaling_mat)947 IHEVCD_ERROR_T ihevcd_scaling_list_data(codec_t *ps_codec, WORD16 *pi2_scaling_mat)
948 {
949 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
950 WORD32 size_id;
951 WORD32 matrix_id;
952 WORD32 value, dc_value = 0;
953 WORD32 next_coef;
954 WORD32 coef_num;
955 WORD32 i, j, offset;
956 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm;
957 WORD16 *pi2_scaling_mat_offset;
958 WORD32 scaling_mat_offset[] = { 0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, 480, 736, 992, 1248, 1504, 1760, 2016, 3040 };
959 UWORD8 *scan_table;
960
961 for(size_id = 0; size_id < 4; size_id++)
962 {
963 for(matrix_id = 0; matrix_id < ((size_id == 3) ? 2 : 6); matrix_id++)
964 {
965 WORD32 scaling_list_pred_mode_flag;
966 WORD32 scaling_list_delta_coef;
967 BITS_PARSE("scaling_list_pred_mode_flag", scaling_list_pred_mode_flag, ps_bitstrm, 1);
968
969 offset = size_id * 6 + matrix_id;
970 pi2_scaling_mat_offset = pi2_scaling_mat + scaling_mat_offset[offset];
971
972 if(!scaling_list_pred_mode_flag)
973 {
974 WORD32 num_elements;
975 UEV_PARSE("scaling_list_pred_matrix_id_delta", value,
976 ps_bitstrm);
977 value = CLIP3(value, 0, matrix_id);
978
979 num_elements = (1 << (4 + (size_id << 1)));
980 if(0 != value)
981 memcpy(pi2_scaling_mat_offset, pi2_scaling_mat_offset - value * num_elements, num_elements * sizeof(WORD16));
982 }
983 else
984 {
985 next_coef = 8;
986 coef_num = MIN(64, (1 << (4 + (size_id << 1))));
987
988 if(size_id > 1)
989 {
990 SEV_PARSE("scaling_list_dc_coef_minus8", value,
991 ps_bitstrm);
992
993 next_coef = value + 8;
994 dc_value = next_coef;
995 }
996 if(size_id < 2)
997 {
998 scan_table = (UWORD8 *)gapv_ihevc_invscan[size_id + 1];
999
1000 for(i = 0; i < coef_num; i++)
1001 {
1002 SEV_PARSE("scaling_list_delta_coef",
1003 scaling_list_delta_coef, ps_bitstrm);
1004 next_coef = (next_coef + scaling_list_delta_coef + 256)
1005 % 256;
1006 pi2_scaling_mat_offset[scan_table[i]] = next_coef;
1007 }
1008 }
1009 else if(size_id == 2)
1010 {
1011 scan_table = (UWORD8 *)gapv_ihevc_invscan[2];
1012
1013 for(i = 0; i < coef_num; i++)
1014 {
1015 SEV_PARSE("scaling_list_delta_coef",
1016 scaling_list_delta_coef, ps_bitstrm);
1017 next_coef = (next_coef + scaling_list_delta_coef + 256)
1018 % 256;
1019
1020 offset = scan_table[i];
1021 offset = (offset >> 3) * 16 * 2 + (offset & 0x7) * 2;
1022 pi2_scaling_mat_offset[offset] = next_coef;
1023 pi2_scaling_mat_offset[offset + 1] = next_coef;
1024 pi2_scaling_mat_offset[offset + 16] = next_coef;
1025 pi2_scaling_mat_offset[offset + 16 + 1] = next_coef;
1026 }
1027 pi2_scaling_mat_offset[0] = dc_value;
1028 }
1029 else
1030 {
1031 scan_table = (UWORD8 *)gapv_ihevc_invscan[2];
1032
1033 for(i = 0; i < coef_num; i++)
1034 {
1035 SEV_PARSE("scaling_list_delta_coef",
1036 scaling_list_delta_coef, ps_bitstrm);
1037 next_coef = (next_coef + scaling_list_delta_coef + 256)
1038 % 256;
1039
1040 offset = scan_table[i];
1041 offset = (offset >> 3) * 32 * 4 + (offset & 0x7) * 4;
1042
1043 for(j = 0; j < 4; j++)
1044 {
1045 pi2_scaling_mat_offset[offset + j * 32] = next_coef;
1046 pi2_scaling_mat_offset[offset + 1 + j * 32] = next_coef;
1047 pi2_scaling_mat_offset[offset + 2 + j * 32] = next_coef;
1048 pi2_scaling_mat_offset[offset + 3 + j * 32] = next_coef;
1049 }
1050 pi2_scaling_mat_offset[0] = dc_value;
1051 }
1052 }
1053 }
1054 }
1055 }
1056
1057 return ret;
1058 }
1059
1060 /**
1061 *******************************************************************************
1062 *
1063 * @brief
1064 * Parses VPS (Video Parameter Set)
1065 *
1066 * @par Description:
1067 * Parse Video Parameter Set as per Section 7.3.2.1
1068 * update vps structure corresponding to vps ID
1069 * Till parsing VPS id, the elements are stored in local variables and are copied
1070 * later
1071 *
1072 * @param[in] ps_codec
1073 * Pointer to codec context.
1074 *
1075 * @returns Error code from IHEVCD_ERROR_T
1076 *
1077 * @remarks
1078 *
1079 *
1080 *******************************************************************************
1081 */
ihevcd_parse_vps(codec_t * ps_codec)1082 IHEVCD_ERROR_T ihevcd_parse_vps(codec_t *ps_codec)
1083 {
1084 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
1085 WORD32 i;
1086 WORD32 value;
1087 WORD32 vps_id;
1088 vps_t *ps_vps;
1089 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm;
1090 BITS_PARSE("vps_video_parameter_set_id", value, ps_bitstrm, 4);
1091 vps_id = value;
1092
1093 if(vps_id >= MAX_VPS_CNT)
1094 {
1095 ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_VPS_ID;
1096 return IHEVCD_UNSUPPORTED_VPS_ID;
1097 }
1098
1099
1100 ps_vps = (ps_codec->s_parse.ps_vps_base + vps_id);
1101
1102 ps_vps->i1_vps_id = vps_id;
1103
1104 BITS_PARSE("vps_reserved_three_2bits", value, ps_bitstrm, 2);
1105 ASSERT(value == 3);
1106
1107 BITS_PARSE("vps_max_layers_minus1", value, ps_bitstrm, 6);
1108 //ps_vps->i1_vps_max_layers = value + 1;
1109
1110
1111
1112 BITS_PARSE("vps_max_sub_layers_minus1", value, ps_bitstrm, 3);
1113 ps_vps->i1_vps_max_sub_layers = value + 1;
1114
1115 ASSERT(ps_vps->i1_vps_max_sub_layers < VPS_MAX_SUB_LAYERS);
1116
1117 BITS_PARSE("vps_temporal_id_nesting_flag", value, ps_bitstrm, 1);
1118 ps_vps->i1_vps_temporal_id_nesting_flag = value;
1119
1120 BITS_PARSE("vps_reserved_ffff_16bits", value, ps_bitstrm, 16);
1121 ASSERT(value == 0xFFFF);
1122 // profile_and_level( 1, vps_max_sub_layers_minus1 )
1123 ret = ihevcd_profile_tier_level(ps_bitstrm, &(ps_vps->s_ptl),
1124 1, (ps_vps->i1_vps_max_sub_layers - 1));
1125
1126 BITS_PARSE("vps_sub_layer_ordering_info_present_flag", value, ps_bitstrm, 1);
1127 ps_vps->i1_sub_layer_ordering_info_present_flag = value;
1128 i = (ps_vps->i1_sub_layer_ordering_info_present_flag ?
1129 0 : (ps_vps->i1_vps_max_sub_layers - 1));
1130 for(; i < ps_vps->i1_vps_max_sub_layers; i++)
1131 {
1132 UEV_PARSE("vps_max_dec_pic_buffering[i]", value, ps_bitstrm);
1133 ps_vps->ai1_vps_max_dec_pic_buffering[i] = value;
1134
1135 /* vps_num_reorder_pics (no max) used in print in order to match with HM */
1136 UEV_PARSE("vps_num_reorder_pics[i]", value, ps_bitstrm);
1137 ps_vps->ai1_vps_max_num_reorder_pics[i] = value;
1138
1139 UEV_PARSE("vps_max_latency_increase[i]", value, ps_bitstrm);
1140 ps_vps->ai1_vps_max_latency_increase[i] = value;
1141 }
1142
1143
1144
1145 BITS_PARSE("vps_max_layer_id", value, ps_bitstrm, 6);
1146 //ps_vps->i1_vps_max_layer_id = value;
1147
1148 UEV_PARSE("vps_num_layer_sets_minus1", value, ps_bitstrm);
1149 //ps_vps->i1_vps_num_layer_sets = value + 1;
1150
1151 BITS_PARSE("vps_timing_info_present_flag", value, ps_bitstrm, 1);
1152 //ps_vps->i1_vps_timing_info_present_flag = value;
1153
1154
1155
1156 return ret;
1157 }
1158
1159 /**
1160 *******************************************************************************
1161 *
1162 * @brief
1163 * Parses SPS (Sequence Parameter Set)
1164 * sequence_parameter_set_rbsp()
1165 *
1166 * @par Description:
1167 * Parse Sequence Parameter Set as per section Section: 7.3.2.2
1168 * The sps is written to a temporary buffer and copied later to the
1169 * appropriate location
1170 *
1171 * @param[in] ps_codec
1172 * Pointer to codec context
1173 *
1174 * @returns Error code from IHEVCD_ERROR_T
1175 *
1176 * @remarks
1177 *
1178 *
1179 *******************************************************************************
1180 */
ihevcd_parse_sps(codec_t * ps_codec)1181 IHEVCD_ERROR_T ihevcd_parse_sps(codec_t *ps_codec)
1182 {
1183 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
1184 WORD32 value;
1185
1186 WORD32 i;
1187 WORD32 vps_id;
1188 WORD32 sps_max_sub_layers;
1189 WORD32 sps_id;
1190 WORD32 sps_temporal_id_nesting_flag;
1191 sps_t *ps_sps;
1192 profile_tier_lvl_info_t s_ptl;
1193 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm;
1194
1195
1196 BITS_PARSE("video_parameter_set_id", value, ps_bitstrm, 4);
1197 vps_id = value;
1198 vps_id = CLIP3(vps_id, 0, MAX_VPS_CNT - 1);
1199
1200 BITS_PARSE("sps_max_sub_layers_minus1", value, ps_bitstrm, 3);
1201 sps_max_sub_layers = value + 1;
1202 sps_max_sub_layers = CLIP3(sps_max_sub_layers, 1, 7);
1203
1204 BITS_PARSE("sps_temporal_id_nesting_flag", value, ps_bitstrm, 1);
1205 sps_temporal_id_nesting_flag = value;
1206
1207 //profile_and_level( 1, sps_max_sub_layers_minus1 )
1208 ret = ihevcd_profile_tier_level(ps_bitstrm, &(s_ptl), 1,
1209 (sps_max_sub_layers - 1));
1210
1211 UEV_PARSE("seq_parameter_set_id", value, ps_bitstrm);
1212 sps_id = value;
1213
1214 if((sps_id >= MAX_SPS_CNT) || (sps_id < 0))
1215 {
1216 if(ps_codec->i4_sps_done)
1217 return IHEVCD_UNSUPPORTED_SPS_ID;
1218 else
1219 sps_id = 0;
1220 }
1221
1222
1223 ps_sps = (ps_codec->s_parse.ps_sps_base + MAX_SPS_CNT - 1);
1224 ps_sps->i1_sps_id = sps_id;
1225 ps_sps->i1_vps_id = vps_id;
1226 ps_sps->i1_sps_max_sub_layers = sps_max_sub_layers;
1227 ps_sps->i1_sps_temporal_id_nesting_flag = sps_temporal_id_nesting_flag;
1228 /* This is used only during initialization to get reorder count etc */
1229 ps_codec->i4_sps_id = sps_id;
1230 memcpy(&ps_sps->s_ptl, &s_ptl, sizeof(profile_tier_lvl_info_t));
1231
1232 UEV_PARSE("chroma_format_idc", value, ps_bitstrm);
1233 ps_sps->i1_chroma_format_idc = value;
1234
1235 if(ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_YUV420)
1236 {
1237 ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC;
1238 return (IHEVCD_ERROR_T)IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC;
1239 }
1240
1241 if(CHROMA_FMT_IDC_YUV444_PLANES == ps_sps->i1_chroma_format_idc)
1242 {
1243 BITS_PARSE("separate_colour_plane_flag", value, ps_bitstrm, 1);
1244 ps_sps->i1_separate_colour_plane_flag = value;
1245 }
1246 else
1247 {
1248 ps_sps->i1_separate_colour_plane_flag = 0;
1249 }
1250
1251 UEV_PARSE("pic_width_in_luma_samples", value, ps_bitstrm);
1252 ps_sps->i2_pic_width_in_luma_samples = value;
1253
1254 UEV_PARSE("pic_height_in_luma_samples", value, ps_bitstrm);
1255 ps_sps->i2_pic_height_in_luma_samples = value;
1256
1257 if((0 >= ps_sps->i2_pic_width_in_luma_samples) || (0 >= ps_sps->i2_pic_height_in_luma_samples))
1258 return IHEVCD_INVALID_PARAMETER;
1259
1260 /* i2_pic_width_in_luma_samples and i2_pic_height_in_luma_samples
1261 should be multiples of min_cb_size. Here these are aligned to 8,
1262 i.e. smallest CB size */
1263 ps_sps->i2_pic_width_in_luma_samples = ALIGN8(ps_sps->i2_pic_width_in_luma_samples);
1264 ps_sps->i2_pic_height_in_luma_samples = ALIGN8(ps_sps->i2_pic_height_in_luma_samples);
1265
1266 BITS_PARSE("pic_cropping_flag", value, ps_bitstrm, 1);
1267 ps_sps->i1_pic_cropping_flag = value;
1268
1269 if(ps_sps->i1_pic_cropping_flag)
1270 {
1271
1272 UEV_PARSE("pic_crop_left_offset", value, ps_bitstrm);
1273 ps_sps->i2_pic_crop_left_offset = value;
1274
1275 UEV_PARSE("pic_crop_right_offset", value, ps_bitstrm);
1276 ps_sps->i2_pic_crop_right_offset = value;
1277
1278 UEV_PARSE("pic_crop_top_offset", value, ps_bitstrm);
1279 ps_sps->i2_pic_crop_top_offset = value;
1280
1281 UEV_PARSE("pic_crop_bottom_offset", value, ps_bitstrm);
1282 ps_sps->i2_pic_crop_bottom_offset = value;
1283 }
1284 else
1285 {
1286 ps_sps->i2_pic_crop_left_offset = 0;
1287 ps_sps->i2_pic_crop_right_offset = 0;
1288 ps_sps->i2_pic_crop_top_offset = 0;
1289 ps_sps->i2_pic_crop_bottom_offset = 0;
1290 }
1291
1292
1293 UEV_PARSE("bit_depth_luma_minus8", value, ps_bitstrm);
1294 if(0 != value)
1295 return IHEVCD_UNSUPPORTED_BIT_DEPTH;
1296
1297 UEV_PARSE("bit_depth_chroma_minus8", value, ps_bitstrm);
1298 if(0 != value)
1299 return IHEVCD_UNSUPPORTED_BIT_DEPTH;
1300
1301 UEV_PARSE("log2_max_pic_order_cnt_lsb_minus4", value, ps_bitstrm);
1302 ps_sps->i1_log2_max_pic_order_cnt_lsb = value + 4;
1303
1304 BITS_PARSE("sps_sub_layer_ordering_info_present_flag", value, ps_bitstrm, 1);
1305 ps_sps->i1_sps_sub_layer_ordering_info_present_flag = value;
1306
1307
1308 i = (ps_sps->i1_sps_sub_layer_ordering_info_present_flag ? 0 : (ps_sps->i1_sps_max_sub_layers - 1));
1309 for(; i < ps_sps->i1_sps_max_sub_layers; i++)
1310 {
1311 UEV_PARSE("max_dec_pic_buffering", value, ps_bitstrm);
1312 ps_sps->ai1_sps_max_dec_pic_buffering[i] = value + 1;
1313
1314 UEV_PARSE("num_reorder_pics", value, ps_bitstrm);
1315 ps_sps->ai1_sps_max_num_reorder_pics[i] = value;
1316
1317 UEV_PARSE("max_latency_increase", value, ps_bitstrm);
1318 ps_sps->ai1_sps_max_latency_increase[i] = value;
1319 }
1320 UEV_PARSE("log2_min_coding_block_size_minus3", value, ps_bitstrm);
1321 ps_sps->i1_log2_min_coding_block_size = value + 3;
1322
1323 UEV_PARSE("log2_diff_max_min_coding_block_size", value, ps_bitstrm);
1324 ps_sps->i1_log2_diff_max_min_coding_block_size = value;
1325
1326 UEV_PARSE("log2_min_transform_block_size_minus2", value, ps_bitstrm);
1327 ps_sps->i1_log2_min_transform_block_size = value + 2;
1328
1329 UEV_PARSE("log2_diff_max_min_transform_block_size", value, ps_bitstrm);
1330 ps_sps->i1_log2_diff_max_min_transform_block_size = value;
1331
1332 ps_sps->i1_log2_max_transform_block_size = ps_sps->i1_log2_min_transform_block_size +
1333 ps_sps->i1_log2_diff_max_min_transform_block_size;
1334
1335 ps_sps->i1_log2_ctb_size = ps_sps->i1_log2_min_coding_block_size +
1336 ps_sps->i1_log2_diff_max_min_coding_block_size;
1337
1338 if((ps_sps->i1_log2_min_coding_block_size < 3) ||
1339 (ps_sps->i1_log2_min_transform_block_size < 2) ||
1340 (ps_sps->i1_log2_diff_max_min_transform_block_size < 0) ||
1341 (ps_sps->i1_log2_max_transform_block_size > ps_sps->i1_log2_ctb_size) ||
1342 (ps_sps->i1_log2_ctb_size < 4) ||
1343 (ps_sps->i1_log2_ctb_size > 6))
1344 {
1345 return IHEVCD_INVALID_PARAMETER;
1346 }
1347
1348 ps_sps->i1_log2_min_pcm_coding_block_size = 0;
1349 ps_sps->i1_log2_diff_max_min_pcm_coding_block_size = 0;
1350
1351 UEV_PARSE("max_transform_hierarchy_depth_inter", value, ps_bitstrm);
1352 ps_sps->i1_max_transform_hierarchy_depth_inter = value;
1353
1354 UEV_PARSE("max_transform_hierarchy_depth_intra", value, ps_bitstrm);
1355 ps_sps->i1_max_transform_hierarchy_depth_intra = value;
1356
1357 /* String has a d (enabled) in order to match with HM */
1358 BITS_PARSE("scaling_list_enabled_flag", value, ps_bitstrm, 1);
1359 ps_sps->i1_scaling_list_enable_flag = value;
1360
1361 if(ps_sps->i1_scaling_list_enable_flag)
1362 {
1363 COPY_DEFAULT_SCALING_LIST(ps_sps->pi2_scaling_mat);
1364 BITS_PARSE("sps_scaling_list_data_present_flag", value, ps_bitstrm, 1);
1365 ps_sps->i1_sps_scaling_list_data_present_flag = value;
1366
1367 if(ps_sps->i1_sps_scaling_list_data_present_flag)
1368 ihevcd_scaling_list_data(ps_codec, ps_sps->pi2_scaling_mat);
1369 }
1370 else
1371 {
1372 COPY_FLAT_SCALING_LIST(ps_sps->pi2_scaling_mat);
1373 }
1374 /* String is asymmetric_motion_partitions_enabled_flag instead of amp_enabled_flag in order to match with HM */
1375 BITS_PARSE("asymmetric_motion_partitions_enabled_flag", value, ps_bitstrm, 1);
1376 ps_sps->i1_amp_enabled_flag = value;
1377
1378 BITS_PARSE("sample_adaptive_offset_enabled_flag", value, ps_bitstrm, 1);
1379 ps_sps->i1_sample_adaptive_offset_enabled_flag = value;
1380
1381 BITS_PARSE("pcm_enabled_flag", value, ps_bitstrm, 1);
1382 ps_sps->i1_pcm_enabled_flag = value;
1383
1384 if(ps_sps->i1_pcm_enabled_flag)
1385 {
1386 BITS_PARSE("pcm_sample_bit_depth_luma", value, ps_bitstrm, 4);
1387 ps_sps->i1_pcm_sample_bit_depth_luma = value + 1;
1388
1389 BITS_PARSE("pcm_sample_bit_depth_chroma", value, ps_bitstrm, 4);
1390 ps_sps->i1_pcm_sample_bit_depth_chroma = value + 1;
1391
1392 UEV_PARSE("log2_min_pcm_coding_block_size_minus3", value, ps_bitstrm);
1393 ps_sps->i1_log2_min_pcm_coding_block_size = value + 3;
1394
1395 UEV_PARSE("log2_diff_max_min_pcm_coding_block_size", value, ps_bitstrm);
1396 ps_sps->i1_log2_diff_max_min_pcm_coding_block_size = value;
1397 BITS_PARSE("pcm_loop_filter_disable_flag", value, ps_bitstrm, 1);
1398 ps_sps->i1_pcm_loop_filter_disable_flag = value;
1399
1400 }
1401 UEV_PARSE("num_short_term_ref_pic_sets", value, ps_bitstrm);
1402 ps_sps->i1_num_short_term_ref_pic_sets = value;
1403
1404 ps_sps->i1_num_short_term_ref_pic_sets = CLIP3(ps_sps->i1_num_short_term_ref_pic_sets, 0, MAX_STREF_PICS_SPS);
1405
1406 for(i = 0; i < ps_sps->i1_num_short_term_ref_pic_sets; i++)
1407 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]);
1408
1409 BITS_PARSE("long_term_ref_pics_present_flag", value, ps_bitstrm, 1);
1410 ps_sps->i1_long_term_ref_pics_present_flag = value;
1411
1412 if(ps_sps->i1_long_term_ref_pics_present_flag)
1413 {
1414 UEV_PARSE("num_long_term_ref_pics_sps", value, ps_bitstrm);
1415 ps_sps->i1_num_long_term_ref_pics_sps = value;
1416
1417 for(i = 0; i < ps_sps->i1_num_long_term_ref_pics_sps; i++)
1418 {
1419 BITS_PARSE("lt_ref_pic_poc_lsb_sps[ i ]", value, ps_bitstrm, ps_sps->i1_log2_max_pic_order_cnt_lsb);
1420 ps_sps->ai1_lt_ref_pic_poc_lsb_sps[i] = value;
1421
1422 BITS_PARSE("used_by_curr_pic_lt_sps_flag[ i ]", value, ps_bitstrm, 1);
1423 ps_sps->ai1_used_by_curr_pic_lt_sps_flag[i] = value;
1424 }
1425 }
1426
1427 BITS_PARSE("sps_temporal_mvp_enable_flag", value, ps_bitstrm, 1);
1428 ps_sps->i1_sps_temporal_mvp_enable_flag = value;
1429
1430 /* Print matches HM 8-2 */
1431 BITS_PARSE("sps_strong_intra_smoothing_enable_flag", value, ps_bitstrm, 1);
1432 ps_sps->i1_strong_intra_smoothing_enable_flag = value;
1433
1434 BITS_PARSE("vui_parameters_present_flag", value, ps_bitstrm, 1);
1435 ps_sps->i1_vui_parameters_present_flag = value;
1436
1437 if(ps_sps->i1_vui_parameters_present_flag)
1438 ihevcd_parse_vui_parameters(ps_bitstrm,
1439 &ps_sps->s_vui_parameters,
1440 ps_sps->i1_sps_max_sub_layers - 1);
1441
1442 BITS_PARSE("sps_extension_flag", value, ps_bitstrm, 1);
1443
1444
1445 {
1446 WORD32 numerator;
1447 WORD32 ceil_offset;
1448
1449 ceil_offset = (1 << ps_sps->i1_log2_ctb_size) - 1;
1450 numerator = ps_sps->i2_pic_width_in_luma_samples;
1451
1452 ps_sps->i2_pic_wd_in_ctb = ((numerator + ceil_offset) /
1453 (1 << ps_sps->i1_log2_ctb_size));
1454
1455 numerator = ps_sps->i2_pic_height_in_luma_samples;
1456 ps_sps->i2_pic_ht_in_ctb = ((numerator + ceil_offset) /
1457 (1 << ps_sps->i1_log2_ctb_size));
1458
1459 ps_sps->i4_pic_size_in_ctb = ps_sps->i2_pic_ht_in_ctb *
1460 ps_sps->i2_pic_wd_in_ctb;
1461
1462 if(0 == ps_codec->i4_sps_done)
1463 ps_codec->s_parse.i4_next_ctb_indx = ps_sps->i4_pic_size_in_ctb;
1464
1465 numerator = ps_sps->i2_pic_width_in_luma_samples;
1466 ps_sps->i2_pic_wd_in_min_cb = numerator /
1467 (1 << ps_sps->i1_log2_min_coding_block_size);
1468
1469 numerator = ps_sps->i2_pic_height_in_luma_samples;
1470 ps_sps->i2_pic_ht_in_min_cb = numerator /
1471 (1 << ps_sps->i1_log2_min_coding_block_size);
1472 }
1473 if((0 != ps_codec->i4_first_pic_done) &&
1474 ((ps_codec->i4_wd != ps_sps->i2_pic_width_in_luma_samples) ||
1475 (ps_codec->i4_ht != ps_sps->i2_pic_height_in_luma_samples)))
1476 {
1477 ps_codec->i4_reset_flag = 1;
1478 return (IHEVCD_ERROR_T)IVD_RES_CHANGED;
1479 }
1480
1481 /* Update display width and display height */
1482 {
1483 WORD32 disp_wd, disp_ht;
1484 WORD32 crop_unit_x, crop_unit_y;
1485 crop_unit_x = 1;
1486 crop_unit_y = 1;
1487
1488 if(CHROMA_FMT_IDC_YUV420 == ps_sps->i1_chroma_format_idc)
1489 {
1490 crop_unit_x = 2;
1491 crop_unit_y = 2;
1492 }
1493
1494 disp_wd = ps_sps->i2_pic_width_in_luma_samples;
1495 disp_wd -= ps_sps->i2_pic_crop_left_offset * crop_unit_x;
1496 disp_wd -= ps_sps->i2_pic_crop_right_offset * crop_unit_x;
1497
1498
1499 disp_ht = ps_sps->i2_pic_height_in_luma_samples;
1500 disp_ht -= ps_sps->i2_pic_crop_top_offset * crop_unit_y;
1501 disp_ht -= ps_sps->i2_pic_crop_bottom_offset * crop_unit_y;
1502
1503 if((0 >= disp_wd) || (0 >= disp_ht))
1504 return IHEVCD_INVALID_PARAMETER;
1505
1506 ps_codec->i4_disp_wd = disp_wd;
1507 ps_codec->i4_disp_ht = disp_ht;
1508
1509
1510 ps_codec->i4_wd = ps_sps->i2_pic_width_in_luma_samples;
1511 ps_codec->i4_ht = ps_sps->i2_pic_height_in_luma_samples;
1512
1513 {
1514 WORD32 ref_strd;
1515 ref_strd = ALIGN32(ps_sps->i2_pic_width_in_luma_samples + PAD_WD);
1516 if(ps_codec->i4_strd < ref_strd)
1517 {
1518 ps_codec->i4_strd = ref_strd;
1519 }
1520 }
1521
1522 if(0 == ps_codec->i4_share_disp_buf)
1523 {
1524 if(ps_codec->i4_disp_strd < ps_codec->i4_disp_wd)
1525 {
1526 ps_codec->i4_disp_strd = ps_codec->i4_disp_wd;
1527 }
1528 }
1529 else
1530 {
1531 if(ps_codec->i4_disp_strd < ps_codec->i4_strd)
1532 {
1533 ps_codec->i4_disp_strd = ps_codec->i4_strd;
1534 }
1535 }
1536 }
1537
1538 ps_codec->i4_sps_done = 1;
1539 return ret;
1540 }
1541
1542
ihevcd_unmark_pps(codec_t * ps_codec,WORD32 sps_id)1543 void ihevcd_unmark_pps(codec_t *ps_codec, WORD32 sps_id)
1544 {
1545 WORD32 pps_id = 0;
1546 pps_t *ps_pps = ps_codec->ps_pps_base;
1547
1548 for(pps_id = 0; pps_id < MAX_PPS_CNT - 1; pps_id++, ps_pps++)
1549 {
1550 if((ps_pps->i1_pps_valid) &&
1551 (ps_pps->i1_sps_id == sps_id))
1552 ps_pps->i1_pps_valid = 0;
1553 }
1554 }
1555
1556
ihevcd_copy_sps(codec_t * ps_codec,WORD32 sps_id,WORD32 sps_id_ref)1557 void ihevcd_copy_sps(codec_t *ps_codec, WORD32 sps_id, WORD32 sps_id_ref)
1558 {
1559 sps_t *ps_sps, *ps_sps_ref;
1560 WORD16 *pi2_scaling_mat_backup;
1561 WORD32 scaling_mat_size;
1562
1563 SCALING_MAT_SIZE(scaling_mat_size);
1564 ps_sps_ref = ps_codec->ps_sps_base + sps_id_ref;
1565 ps_sps = ps_codec->ps_sps_base + sps_id;
1566
1567 if(ps_sps->i1_sps_valid)
1568 {
1569 if((ps_sps->i1_log2_ctb_size != ps_sps_ref->i1_log2_ctb_size) ||
1570 (ps_sps->i2_pic_wd_in_ctb != ps_sps_ref->i2_pic_wd_in_ctb) ||
1571 (ps_sps->i2_pic_ht_in_ctb != ps_sps_ref->i2_pic_ht_in_ctb))
1572 {
1573 ihevcd_unmark_pps(ps_codec, sps_id);
1574 }
1575 }
1576
1577 pi2_scaling_mat_backup = ps_sps->pi2_scaling_mat;
1578
1579 memcpy(ps_sps, ps_sps_ref, sizeof(sps_t));
1580 ps_sps->pi2_scaling_mat = pi2_scaling_mat_backup;
1581 memcpy(ps_sps->pi2_scaling_mat, ps_sps_ref->pi2_scaling_mat, scaling_mat_size * sizeof(WORD16));
1582 ps_sps->i1_sps_valid = 1;
1583
1584 ps_codec->s_parse.ps_sps = ps_sps;
1585 }
1586
1587
1588 /**
1589 *******************************************************************************
1590 *
1591 * @brief
1592 * Parses PPS (Picture Parameter Set)
1593 *
1594 * @par Description:
1595 * Parse Picture Parameter Set as per section Section: 7.3.2.3
1596 * The pps is written to a temporary buffer and copied later to the
1597 * appropriate location
1598 *
1599 * @param[in] ps_codec
1600 * Pointer to codec context
1601 *
1602 * @returns Error code from IHEVCD_ERROR_T
1603 *
1604 * @remarks
1605 *
1606 *
1607 *******************************************************************************
1608 */
ihevcd_parse_pps(codec_t * ps_codec)1609 IHEVCD_ERROR_T ihevcd_parse_pps(codec_t *ps_codec)
1610 {
1611 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
1612 WORD32 value;
1613 WORD32 pps_id;
1614
1615 pps_t *ps_pps;
1616 sps_t *ps_sps;
1617 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm;
1618
1619
1620 if(0 == ps_codec->i4_sps_done)
1621 return IHEVCD_INVALID_HEADER;
1622
1623 UEV_PARSE("pic_parameter_set_id", value, ps_bitstrm);
1624
1625 pps_id = value;
1626 if((pps_id >= MAX_PPS_CNT) || (pps_id < 0))
1627 {
1628 if(ps_codec->i4_pps_done)
1629 return IHEVCD_UNSUPPORTED_PPS_ID;
1630 else
1631 pps_id = 0;
1632 }
1633
1634
1635 ps_pps = (ps_codec->s_parse.ps_pps_base + MAX_PPS_CNT - 1);
1636
1637 ps_pps->i1_pps_id = pps_id;
1638
1639 UEV_PARSE("seq_parameter_set_id", value, ps_bitstrm);
1640 ps_pps->i1_sps_id = value;
1641 ps_pps->i1_sps_id = CLIP3(ps_pps->i1_sps_id, 0, MAX_SPS_CNT - 2);
1642
1643 ps_sps = (ps_codec->s_parse.ps_sps_base + ps_pps->i1_sps_id);
1644
1645 /* If the SPS that is being referred to has not been parsed,
1646 * copy an existing SPS to the current location */
1647 if(0 == ps_sps->i1_sps_valid)
1648 {
1649 return IHEVCD_INVALID_HEADER;
1650
1651 /*
1652 sps_t *ps_sps_ref = ps_codec->ps_sps_base;
1653 while(0 == ps_sps_ref->i1_sps_valid)
1654 ps_sps_ref++;
1655 ihevcd_copy_sps(ps_codec, ps_pps->i1_sps_id, ps_sps_ref->i1_sps_id);
1656 */
1657 }
1658
1659 BITS_PARSE("dependent_slices_enabled_flag", value, ps_bitstrm, 1);
1660 ps_pps->i1_dependent_slice_enabled_flag = value;
1661
1662 BITS_PARSE("output_flag_present_flag", value, ps_bitstrm, 1);
1663 ps_pps->i1_output_flag_present_flag = value;
1664
1665 BITS_PARSE("num_extra_slice_header_bits", value, ps_bitstrm, 3);
1666 ps_pps->i1_num_extra_slice_header_bits = value;
1667
1668
1669 BITS_PARSE("sign_data_hiding_flag", value, ps_bitstrm, 1);
1670 ps_pps->i1_sign_data_hiding_flag = value;
1671
1672 BITS_PARSE("cabac_init_present_flag", value, ps_bitstrm, 1);
1673 ps_pps->i1_cabac_init_present_flag = value;
1674
1675 UEV_PARSE("num_ref_idx_l0_default_active_minus1", value, ps_bitstrm);
1676 ps_pps->i1_num_ref_idx_l0_default_active = value + 1;
1677
1678 UEV_PARSE("num_ref_idx_l1_default_active_minus1", value, ps_bitstrm);
1679 ps_pps->i1_num_ref_idx_l1_default_active = value + 1;
1680
1681 SEV_PARSE("pic_init_qp_minus26", value, ps_bitstrm);
1682 ps_pps->i1_pic_init_qp = value + 26;
1683
1684 BITS_PARSE("constrained_intra_pred_flag", value, ps_bitstrm, 1);
1685 ps_pps->i1_constrained_intra_pred_flag = value;
1686
1687 BITS_PARSE("transform_skip_enabled_flag", value, ps_bitstrm, 1);
1688 ps_pps->i1_transform_skip_enabled_flag = value;
1689
1690 BITS_PARSE("cu_qp_delta_enabled_flag", value, ps_bitstrm, 1);
1691 ps_pps->i1_cu_qp_delta_enabled_flag = value;
1692
1693 if(ps_pps->i1_cu_qp_delta_enabled_flag)
1694 {
1695 UEV_PARSE("diff_cu_qp_delta_depth", value, ps_bitstrm);
1696 ps_pps->i1_diff_cu_qp_delta_depth = value;
1697 }
1698 else
1699 {
1700 ps_pps->i1_diff_cu_qp_delta_depth = 0;
1701 }
1702 ps_pps->i1_log2_min_cu_qp_delta_size = ps_sps->i1_log2_ctb_size - ps_pps->i1_diff_cu_qp_delta_depth;
1703 /* Print different */
1704 SEV_PARSE("cb_qp_offset", value, ps_bitstrm);
1705 ps_pps->i1_pic_cb_qp_offset = value;
1706
1707 /* Print different */
1708 SEV_PARSE("cr_qp_offset", value, ps_bitstrm);
1709 ps_pps->i1_pic_cr_qp_offset = value;
1710
1711 /* Print different */
1712 BITS_PARSE("slicelevel_chroma_qp_flag", value, ps_bitstrm, 1);
1713 ps_pps->i1_pic_slice_level_chroma_qp_offsets_present_flag = value;
1714
1715 BITS_PARSE("weighted_pred_flag", value, ps_bitstrm, 1);
1716 ps_pps->i1_weighted_pred_flag = value;
1717
1718 BITS_PARSE("weighted_bipred_flag", value, ps_bitstrm, 1);
1719 ps_pps->i1_weighted_bipred_flag = value;
1720
1721 BITS_PARSE("transquant_bypass_enable_flag", value, ps_bitstrm, 1);
1722 ps_pps->i1_transquant_bypass_enable_flag = value;
1723
1724 BITS_PARSE("tiles_enabled_flag", value, ps_bitstrm, 1);
1725 ps_pps->i1_tiles_enabled_flag = value;
1726
1727 BITS_PARSE("entropy_coding_sync_enabled_flag", value, ps_bitstrm, 1);
1728 ps_pps->i1_entropy_coding_sync_enabled_flag = value;
1729
1730 ps_pps->i1_loop_filter_across_tiles_enabled_flag = 0;
1731 if(ps_pps->i1_tiles_enabled_flag)
1732 {
1733 UEV_PARSE("num_tile_columns_minus1", value, ps_bitstrm);
1734 ps_pps->i1_num_tile_columns = value + 1;
1735
1736 UEV_PARSE("num_tile_rows_minus1", value, ps_bitstrm);
1737 ps_pps->i1_num_tile_rows = value + 1;
1738
1739 if((ps_pps->i1_num_tile_columns < 1) ||
1740 (ps_pps->i1_num_tile_columns > ps_sps->i2_pic_wd_in_ctb) ||
1741 (ps_pps->i1_num_tile_rows < 1) ||
1742 (ps_pps->i1_num_tile_rows > ps_sps->i2_pic_ht_in_ctb))
1743 return IHEVCD_INVALID_HEADER;
1744
1745 BITS_PARSE("uniform_spacing_flag", value, ps_bitstrm, 1);
1746 ps_pps->i1_uniform_spacing_flag = value;
1747
1748
1749 {
1750
1751 WORD32 start;
1752 WORD32 i, j;
1753
1754
1755 start = 0;
1756 for(i = 0; i < ps_pps->i1_num_tile_columns; i++)
1757 {
1758 tile_t *ps_tile;
1759 if(!ps_pps->i1_uniform_spacing_flag)
1760 {
1761 if(i < (ps_pps->i1_num_tile_columns - 1))
1762 {
1763 UEV_PARSE("column_width_minus1[ i ]", value, ps_bitstrm);
1764 value += 1;
1765 }
1766 else
1767 {
1768 value = ps_sps->i2_pic_wd_in_ctb - start;
1769 }
1770 }
1771 else
1772 {
1773 value = ((i + 1) * ps_sps->i2_pic_wd_in_ctb) / ps_pps->i1_num_tile_columns -
1774 (i * ps_sps->i2_pic_wd_in_ctb) / ps_pps->i1_num_tile_columns;
1775 }
1776
1777 for(j = 0; j < ps_pps->i1_num_tile_rows; j++)
1778 {
1779 ps_tile = ps_pps->ps_tile + j * ps_pps->i1_num_tile_columns + i;
1780 ps_tile->u1_pos_x = start;
1781 ps_tile->u2_wd = value;
1782 }
1783 start += value;
1784
1785 if((start > ps_sps->i2_pic_wd_in_ctb) ||
1786 (value <= 0))
1787 return IHEVCD_INVALID_HEADER;
1788 }
1789
1790 start = 0;
1791 for(i = 0; i < (ps_pps->i1_num_tile_rows); i++)
1792 {
1793 tile_t *ps_tile;
1794 if(!ps_pps->i1_uniform_spacing_flag)
1795 {
1796 if(i < (ps_pps->i1_num_tile_rows - 1))
1797 {
1798
1799 UEV_PARSE("row_height_minus1[ i ]", value, ps_bitstrm);
1800 value += 1;
1801 }
1802 else
1803 {
1804 value = ps_sps->i2_pic_ht_in_ctb - start;
1805 }
1806 }
1807 else
1808 {
1809 value = ((i + 1) * ps_sps->i2_pic_ht_in_ctb) / ps_pps->i1_num_tile_rows -
1810 (i * ps_sps->i2_pic_ht_in_ctb) / ps_pps->i1_num_tile_rows;
1811 }
1812
1813 for(j = 0; j < ps_pps->i1_num_tile_columns; j++)
1814 {
1815 ps_tile = ps_pps->ps_tile + i * ps_pps->i1_num_tile_columns + j;
1816 ps_tile->u1_pos_y = start;
1817 ps_tile->u2_ht = value;
1818 }
1819 start += value;
1820
1821 if((start > ps_sps->i2_pic_ht_in_ctb) ||
1822 (value <= 0))
1823 return IHEVCD_INVALID_HEADER;
1824 }
1825 }
1826
1827
1828 BITS_PARSE("loop_filter_across_tiles_enabled_flag", value, ps_bitstrm, 1);
1829 ps_pps->i1_loop_filter_across_tiles_enabled_flag = value;
1830
1831 }
1832 else
1833 {
1834 /* If tiles are not present, set first tile in each PPS to have tile
1835 width and height equal to picture width and height */
1836 ps_pps->i1_num_tile_columns = 1;
1837 ps_pps->i1_num_tile_rows = 1;
1838 ps_pps->i1_uniform_spacing_flag = 1;
1839
1840 ps_pps->ps_tile->u1_pos_x = 0;
1841 ps_pps->ps_tile->u1_pos_y = 0;
1842 ps_pps->ps_tile->u2_wd = ps_sps->i2_pic_wd_in_ctb;
1843 ps_pps->ps_tile->u2_ht = ps_sps->i2_pic_ht_in_ctb;
1844 }
1845
1846 BITS_PARSE("loop_filter_across_slices_enabled_flag", value, ps_bitstrm, 1);
1847 ps_pps->i1_loop_filter_across_slices_enabled_flag = value;
1848
1849 BITS_PARSE("deblocking_filter_control_present_flag", value, ps_bitstrm, 1);
1850 ps_pps->i1_deblocking_filter_control_present_flag = value;
1851
1852 /* Default values */
1853 ps_pps->i1_pic_disable_deblocking_filter_flag = 0;
1854 ps_pps->i1_deblocking_filter_override_enabled_flag = 0;
1855 ps_pps->i1_beta_offset_div2 = 0;
1856 ps_pps->i1_tc_offset_div2 = 0;
1857
1858 if(ps_pps->i1_deblocking_filter_control_present_flag)
1859 {
1860
1861 BITS_PARSE("deblocking_filter_override_enabled_flag", value, ps_bitstrm, 1);
1862 ps_pps->i1_deblocking_filter_override_enabled_flag = value;
1863
1864 BITS_PARSE("pic_disable_deblocking_filter_flag", value, ps_bitstrm, 1);
1865 ps_pps->i1_pic_disable_deblocking_filter_flag = value;
1866
1867 if(!ps_pps->i1_pic_disable_deblocking_filter_flag)
1868 {
1869
1870 SEV_PARSE("pps_beta_offset_div2", value, ps_bitstrm);
1871 ps_pps->i1_beta_offset_div2 = value;
1872
1873 SEV_PARSE("pps_tc_offset_div2", value, ps_bitstrm);
1874 ps_pps->i1_tc_offset_div2 = value;
1875
1876 }
1877 }
1878
1879 BITS_PARSE("pps_scaling_list_data_present_flag", value, ps_bitstrm, 1);
1880 ps_pps->i1_pps_scaling_list_data_present_flag = value;
1881
1882 if(ps_pps->i1_pps_scaling_list_data_present_flag)
1883 {
1884 COPY_DEFAULT_SCALING_LIST(ps_pps->pi2_scaling_mat);
1885 ihevcd_scaling_list_data(ps_codec, ps_pps->pi2_scaling_mat);
1886 }
1887
1888 BITS_PARSE("lists_modification_present_flag", value, ps_bitstrm, 1);
1889 ps_pps->i1_lists_modification_present_flag = value;
1890 UEV_PARSE("log2_parallel_merge_level_minus2", value, ps_bitstrm);
1891 ps_pps->i1_log2_parallel_merge_level = value + 2;
1892
1893 BITS_PARSE("slice_header_extension_present_flag", value, ps_bitstrm, 1);
1894 ps_pps->i1_slice_header_extension_present_flag = value;
1895 /* Not present in HM */
1896 BITS_PARSE("pps_extension_flag", value, ps_bitstrm, 1);
1897
1898 ps_codec->i4_pps_done = 1;
1899 return ret;
1900 }
1901
1902
ihevcd_copy_pps(codec_t * ps_codec,WORD32 pps_id,WORD32 pps_id_ref)1903 void ihevcd_copy_pps(codec_t *ps_codec, WORD32 pps_id, WORD32 pps_id_ref)
1904 {
1905 pps_t *ps_pps, *ps_pps_ref;
1906 WORD16 *pi2_scaling_mat_backup;
1907 WORD32 scaling_mat_size;
1908 tile_t *ps_tile_backup;
1909 WORD32 max_tile_cols, max_tile_rows;
1910 WORD32 wd, ht;
1911 wd = ALIGN64(ps_codec->i4_wd);
1912 ht = ALIGN64(ps_codec->i4_ht);
1913
1914 SCALING_MAT_SIZE(scaling_mat_size);
1915 max_tile_cols = (wd + MIN_TILE_WD - 1) / MIN_TILE_WD;
1916 max_tile_rows = (ht + MIN_TILE_HT - 1) / MIN_TILE_HT;
1917
1918 ps_pps_ref = ps_codec->ps_pps_base + pps_id_ref;
1919 ps_pps = ps_codec->ps_pps_base + pps_id;
1920
1921 pi2_scaling_mat_backup = ps_pps->pi2_scaling_mat;
1922 ps_tile_backup = ps_pps->ps_tile;
1923
1924 memcpy(ps_pps, ps_pps_ref, sizeof(pps_t));
1925 ps_pps->pi2_scaling_mat = pi2_scaling_mat_backup;
1926 ps_pps->ps_tile = ps_tile_backup;
1927 memcpy(ps_pps->pi2_scaling_mat, ps_pps_ref->pi2_scaling_mat, scaling_mat_size * sizeof(WORD16));
1928 memcpy(ps_pps->ps_tile, ps_pps_ref->ps_tile, max_tile_cols * max_tile_rows * sizeof(tile_t));
1929
1930 ps_pps->i1_pps_valid = 1;
1931
1932 ps_codec->s_parse.ps_pps = ps_pps;
1933 }
1934
1935
1936
1937 /**
1938 *******************************************************************************
1939 *
1940 * @brief
1941 * Parses SEI (Supplemental Enhancement Information)
1942 *
1943 * @par Description:
1944 * Parses SEI (Supplemental Enhancement Information) as per Section: 7.3.7
1945 *
1946 * @param[in] ps_codec
1947 * Pointer to codec context
1948 *
1949 * @returns Error code from IHEVCD_ERROR_T
1950 *
1951 * @remarks
1952 *
1953 *
1954 *******************************************************************************
1955 */
ihevcd_parse_sei(codec_t * ps_codec)1956 IHEVCD_ERROR_T ihevcd_parse_sei(codec_t *ps_codec)
1957 {
1958 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
1959 UNUSED(ps_codec);
1960 return ret;
1961 }
1962
1963 /**
1964 *******************************************************************************
1965 *
1966 * @brief
1967 * Parses Access unit delimiter
1968 *
1969 * @par Description:
1970 * Parses Access unit delimiter as per section Section: 7.3.2.5
1971 *
1972 * @param[in] ps_codec
1973 * Pointer to codec context
1974 *
1975 * @returns Error code from IHEVCD_ERROR_T
1976 *
1977 * @remarks
1978 *
1979 *
1980 *******************************************************************************
1981 */
ihevcd_parse_aud(codec_t * ps_codec)1982 WORD32 ihevcd_parse_aud(codec_t *ps_codec)
1983 {
1984 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS;
1985 UNUSED(ps_codec);
1986 return ret;
1987 }
1988
ihevcd_extend_sign_bit(WORD32 value,WORD32 num_bits)1989 WORD32 ihevcd_extend_sign_bit(WORD32 value, WORD32 num_bits)
1990 {
1991 WORD32 ret_value = value;
1992 if(value >> (num_bits - 1))
1993 {
1994 ret_value |= (0xFFFFFFFF << num_bits);
1995 }
1996 return ret_value;
1997 }
1998
1999 /**
2000 *******************************************************************************
2001 *
2002 * @brief
2003 * Calculate POC of the current slice
2004 *
2005 * @par Description:
2006 * Calculates the current POC using the previous POC lsb and previous POC msb
2007 *
2008 * @param[in] ps_codec
2009 * Pointer to codec context
2010 *
2011 * @param[in] i1_pic_order_cnt_lsb
2012 * Current POC lsb
2013 *
2014 * @returns Current absolute POC
2015 *
2016 * @remarks
2017 *
2018 *
2019 *******************************************************************************
2020 */
2021
ihevcd_calc_poc(codec_t * ps_codec,nal_header_t * ps_nal,WORD8 i1_log2_max_poc_lsb,WORD32 i2_poc_lsb)2022 WORD32 ihevcd_calc_poc(codec_t *ps_codec, nal_header_t *ps_nal, WORD8 i1_log2_max_poc_lsb, WORD32 i2_poc_lsb)
2023 {
2024 WORD32 i4_abs_poc, i4_poc_msb;
2025 WORD32 max_poc_lsb;
2026 WORD8 i1_nal_unit_type = ps_nal->i1_nal_unit_type;
2027 max_poc_lsb = (1 << i1_log2_max_poc_lsb);
2028
2029 if((!ps_codec->i4_first_pic_done) && (!ps_codec->i4_pic_present))
2030 ps_codec->i4_prev_poc_msb = -2 * max_poc_lsb;
2031
2032 if(NAL_IDR_N_LP == i1_nal_unit_type
2033 || NAL_IDR_W_LP == i1_nal_unit_type
2034 || NAL_BLA_N_LP == i1_nal_unit_type
2035 || NAL_BLA_W_DLP == i1_nal_unit_type
2036 || NAL_BLA_W_LP == i1_nal_unit_type
2037 || (NAL_CRA == i1_nal_unit_type && !ps_codec->i4_first_pic_done))
2038 {
2039 i4_poc_msb = ps_codec->i4_prev_poc_msb + 2 * max_poc_lsb;
2040 ps_codec->i4_prev_poc_lsb = 0;
2041 ps_codec->i4_max_prev_poc_lsb = 0;
2042 // ps_codec->i4_prev_poc_msb = 0;
2043 }
2044 else
2045 {
2046
2047 if((i2_poc_lsb < ps_codec->i4_prev_poc_lsb)
2048 && ((ps_codec->i4_prev_poc_lsb - i2_poc_lsb) >= max_poc_lsb / 2))
2049 {
2050 i4_poc_msb = ps_codec->i4_prev_poc_msb + max_poc_lsb;
2051 }
2052 else if((i2_poc_lsb > ps_codec->i4_prev_poc_lsb)
2053 && ((i2_poc_lsb - ps_codec->i4_prev_poc_lsb) > max_poc_lsb / 2))
2054 {
2055 i4_poc_msb = ps_codec->i4_prev_poc_msb - max_poc_lsb;
2056 }
2057 else
2058 {
2059 i4_poc_msb = ps_codec->i4_prev_poc_msb;
2060 }
2061
2062
2063 }
2064
2065 i4_abs_poc = i4_poc_msb + i2_poc_lsb;
2066 ps_codec->i4_max_prev_poc_lsb = MAX(ps_codec->i4_max_prev_poc_lsb, i2_poc_lsb);
2067
2068 {
2069 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));
2070 WORD32 update_prev_poc = ((is_reference_nal) && ((i1_nal_unit_type < NAL_RADL_N) || (i1_nal_unit_type > NAL_RASL_R)));
2071
2072 if((0 == ps_nal->i1_nuh_temporal_id) &&
2073 (update_prev_poc))
2074 {
2075 ps_codec->i4_prev_poc_lsb = i2_poc_lsb;
2076 ps_codec->i4_prev_poc_msb = i4_poc_msb;
2077 }
2078 }
2079
2080 return i4_abs_poc;
2081 }
2082
2083
ihevcd_copy_slice_hdr(codec_t * ps_codec,WORD32 slice_idx,WORD32 slice_idx_ref)2084 void ihevcd_copy_slice_hdr(codec_t *ps_codec, WORD32 slice_idx, WORD32 slice_idx_ref)
2085 {
2086 slice_header_t *ps_slice_hdr, *ps_slice_hdr_ref;
2087 WORD32 *pu4_entry_offset_backup;
2088
2089 ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr_base + slice_idx;
2090 ps_slice_hdr_ref = ps_codec->s_parse.ps_slice_hdr_base + slice_idx_ref;
2091
2092 pu4_entry_offset_backup = ps_slice_hdr->pu4_entry_point_offset;
2093 memcpy(ps_slice_hdr, ps_slice_hdr_ref, sizeof(slice_header_t));
2094 ps_slice_hdr->pu4_entry_point_offset = pu4_entry_offset_backup;
2095 }
2096
2097
2098
2099