Coverage Report

Created: 2025-11-11 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/ih264d_parse_headers.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_parse_headers.c
23
 *
24
 * \brief
25
 *    Contains High level syntax[above slice] parsing routines
26
 *
27
 * \date
28
 *    19/12/2002
29
 *
30
 * \author  AI
31
 **************************************************************************
32
 */
33
#include <string.h>
34
35
#include "ih264_typedefs.h"
36
#include "ih264_macros.h"
37
#include "ih264_platform_macros.h"
38
#include "ih264_defs.h"
39
#include "ih264d_bitstrm.h"
40
#include "ih264d_structs.h"
41
#include "ih264d_parse_cavlc.h"
42
#include "ih264d_defs.h"
43
#include "ih264d_defs.h"
44
#include "ih264d_defs.h"
45
#include "ih264d_parse_slice.h"
46
#include "ih264d_tables.h"
47
#include "ih264d_utils.h"
48
#include "ih264d_nal.h"
49
#include "ih264d_deblocking.h"
50
51
#include "ih264d_mem_request.h"
52
#include "ih264d_debug.h"
53
#include "ih264d_error_handler.h"
54
#include "ih264d_mb_utils.h"
55
#include "ih264d_sei.h"
56
#include "ih264d_vui.h"
57
#include "ih264d_thread_parse_decode.h"
58
#include "ih264d_thread_compute_bs.h"
59
#include "ih264d_quant_scaling.h"
60
#include "ih264d_defs.h"
61
#include "ivd.h"
62
#include "ih264d.h"
63
64
/*****************************************************************************/
65
/*                                                                           */
66
/*  Function Name : ih264d_get_pre_sei_params                                */
67
/*                                                                           */
68
/*  Description   : Gets valid pre-sei params in decoder struct from parse   */
69
/*                  struct.                                                  */
70
/*  Inputs        : u1_nal_unit_type slice type                              */
71
/*                  ps_dec    Decoder parameters                             */
72
/*  Globals       : None                                                     */
73
/*  Outputs       : None                                                     */
74
/*  Returns       : None                                                     */
75
/*                                                                           */
76
/*  Issues        : None                                                     */
77
/*                                                                           */
78
/*  Revision History:                                                        */
79
/*                                                                           */
80
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
81
/*                                          Draft                            */
82
/*                                                                           */
83
/*****************************************************************************/
84
85
void ih264d_get_pre_sei_params(dec_struct_t *ps_dec, UWORD8 u1_nal_unit_type)
86
200k
{
87
200k
    if((NULL != ps_dec->ps_sei) &&
88
200k
        ((0 == ps_dec->ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag) &&
89
200k
        (0 == ps_dec->ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag)))
90
200k
    {
91
200k
        ps_dec->ps_sei->u1_sei_ccv_params_present_flag = 0;
92
200k
        memset(&ps_dec->ps_sei->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
93
200k
    }
94
95
200k
    if((NULL != ps_dec->ps_cur_sps) &&
96
165k
        ((1 == ps_dec->ps_cur_sps->u1_vui_parameters_present_flag) &&
97
28.9k
        ((2 != ps_dec->ps_cur_sps->s_vui.u1_colour_primaries) &&
98
2.65k
        (2 != ps_dec->ps_cur_sps->s_vui.u1_matrix_coeffs) &&
99
2.45k
        (2 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars) &&
100
2.38k
        (4 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars) &&
101
2.14k
        (5 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars))))
102
2.07k
    {
103
2.07k
        if((1 == ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag) ||
104
1.98k
            (IDR_SLICE_NAL == u1_nal_unit_type))
105
1.11k
        {
106
1.11k
            ps_dec->ps_sei->u1_sei_ccv_params_present_flag =
107
1.11k
                        ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag;
108
1.11k
            ps_dec->ps_sei->s_sei_ccv_params = ps_dec->ps_sei_parse->s_sei_ccv_params;
109
1.11k
        }
110
2.07k
    }
111
198k
    else
112
198k
    {
113
198k
        ps_dec->ps_sei->u1_sei_ccv_params_present_flag = 0;
114
198k
        memset(&ps_dec->ps_sei->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
115
198k
    }
116
117
200k
    if(IDR_SLICE_NAL == u1_nal_unit_type)
118
120k
    {
119
120k
        ps_dec->ps_sei->u1_sei_mdcv_params_present_flag =
120
120k
                        ps_dec->ps_sei_parse->u1_sei_mdcv_params_present_flag;
121
120k
        ps_dec->ps_sei->s_sei_mdcv_params = ps_dec->ps_sei_parse->s_sei_mdcv_params;
122
120k
        ps_dec->ps_sei->u1_sei_cll_params_present_flag =
123
120k
                        ps_dec->ps_sei_parse->u1_sei_cll_params_present_flag;
124
120k
        ps_dec->ps_sei->s_sei_cll_params = ps_dec->ps_sei_parse->s_sei_cll_params;
125
120k
        ps_dec->ps_sei->u1_sei_ave_params_present_flag =
126
120k
                        ps_dec->ps_sei_parse->u1_sei_ave_params_present_flag;
127
120k
        ps_dec->ps_sei->s_sei_ave_params = ps_dec->ps_sei_parse->s_sei_ave_params;
128
120k
        ps_dec->ps_sei->u1_sei_sii_params_present_flag =
129
120k
            ps_dec->ps_sei_parse->u1_sei_sii_params_present_flag;
130
120k
        ps_dec->ps_sei->s_sei_sii_params = ps_dec->ps_sei_parse->s_sei_sii_params;
131
120k
    }
132
133
200k
    if(NULL != ps_dec->ps_sei)
134
200k
    {
135
200k
        ps_dec->ps_sei->u1_sei_fgc_params_present_flag =
136
200k
            ps_dec->ps_sei_parse->u1_sei_fgc_params_present_flag;
137
200k
        ps_dec->ps_sei->s_sei_fgc_params = ps_dec->ps_sei_parse->s_sei_fgc_params;
138
200k
    }
139
140
200k
    ps_dec->ps_sei_parse->u1_sei_mdcv_params_present_flag = 0;
141
200k
    memset(&ps_dec->ps_sei_parse->s_sei_mdcv_params, 0, sizeof(sei_mdcv_params_t));
142
200k
    ps_dec->ps_sei_parse->u1_sei_cll_params_present_flag = 0;
143
200k
    memset(&ps_dec->ps_sei_parse->s_sei_cll_params, 0, sizeof(sei_cll_params_t));
144
200k
    ps_dec->ps_sei_parse->u1_sei_ave_params_present_flag = 0;
145
200k
    memset(&ps_dec->ps_sei_parse->s_sei_ave_params, 0, sizeof(sei_ave_params_t));
146
200k
    ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag = 0;
147
200k
    memset(&ps_dec->ps_sei_parse->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
148
200k
    ps_dec->ps_sei_parse->u1_sei_sii_params_present_flag = 0;
149
200k
    memset(&ps_dec->ps_sei_parse->s_sei_sii_params, 0, sizeof(sei_sii_params_t));
150
200k
}
151
152
/*****************************************************************************/
153
/*                                                                           */
154
/*  Function Name : ih264d_parse_slice_partition                                     */
155
/*                                                                           */
156
/*  Description   : This function is intended to parse and decode slice part */
157
/*                  itions. Currently it's not implemented. Decoder will     */
158
/*                  print a message, skips this NAL and continues            */
159
/*  Inputs        : ps_dec    Decoder parameters                             */
160
/*                  ps_bitstrm    Bitstream                                */
161
/*  Globals       : None                                                     */
162
/*  Processing    : This functionality needs to be implemented               */
163
/*  Outputs       : None                                                     */
164
/*  Returns       : None                                                     */
165
/*                                                                           */
166
/*  Issues        : Not implemented                                          */
167
/*                                                                           */
168
/*  Revision History:                                                        */
169
/*                                                                           */
170
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
171
/*         06 05 2002   NS              Draft                                */
172
/*                                                                           */
173
/*****************************************************************************/
174
175
WORD32 ih264d_parse_slice_partition(dec_struct_t * ps_dec,
176
                                    dec_bit_stream_t * ps_bitstrm)
177
154
{
178
154
    H264_DEC_DEBUG_PRINT("\nSlice partition not supported");
179
154
    UNUSED(ps_dec);
180
154
    UNUSED(ps_bitstrm);
181
154
    return (0);
182
154
}
183
184
/*****************************************************************************/
185
/*                                                                           */
186
/*  Function Name : ih264d_parse_sei                                                */
187
/*                                                                           */
188
/*  Description   : This function is intended to parse and decode SEI        */
189
/*                  Currently it's not implemented. Decoder will print a     */
190
/*                  message, skips this NAL and continues                    */
191
/*  Inputs        : ps_dec    Decoder parameters                       */
192
/*                  ps_bitstrm    Bitstream                                */
193
/*  Globals       : None                                                     */
194
/*  Processing    : This functionality needs to be implemented               */
195
/*  Outputs       : None                                                     */
196
/*  Returns       : None                                                     */
197
/*                                                                           */
198
/*  Issues        : Not implemented                                          */
199
/*                                                                           */
200
/*  Revision History:                                                        */
201
/*                                                                           */
202
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
203
/*         06 05 2002   NS              Draft                                */
204
/*                                                                           */
205
/*****************************************************************************/
206
WORD32 ih264d_parse_sei(dec_struct_t * ps_dec, dec_bit_stream_t * ps_bitstrm)
207
6.03k
{
208
6.03k
    UNUSED(ps_dec);
209
6.03k
    UNUSED(ps_bitstrm);
210
6.03k
    return (0);
211
6.03k
}
212
213
/*****************************************************************************/
214
/*                                                                           */
215
/*  Function Name : ih264d_parse_filler_data                                          */
216
/*                                                                           */
217
/*  Description   : This function is intended to parse and decode filler     */
218
/*                  data NAL. Currently it's not implemented. Decoder will   */
219
/*                  print a message, skips this NAL and continues            */
220
/*  Inputs        : ps_dec    Decoder parameters                       */
221
/*                  ps_bitstrm    Bitstream                                */
222
/*  Globals       : None                                                     */
223
/*  Processing    : This functionality needs to be implemented               */
224
/*  Outputs       : None                                                     */
225
/*  Returns       : None                                                     */
226
/*                                                                           */
227
/*  Issues        : Not implemented                                          */
228
/*                                                                           */
229
/*  Revision History:                                                        */
230
/*                                                                           */
231
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
232
/*         06 05 2002   NS              Draft                                */
233
/*                                                                           */
234
/*****************************************************************************/
235
WORD32 ih264d_parse_filler_data(dec_struct_t * ps_dec,
236
                                dec_bit_stream_t * ps_bitstrm)
237
136
{
238
136
    UNUSED(ps_dec);
239
136
    UNUSED(ps_bitstrm);
240
136
    return (0);
241
136
}
242
243
/*****************************************************************************/
244
/*                                                                           */
245
/*  Function Name : ih264d_parse_end_of_stream                                        */
246
/*                                                                           */
247
/*  Description   : This function is intended to parse and decode end of     */
248
/*                  sequence. Currently it's not implemented. Decoder will   */
249
/*                  print a message, skips this NAL and continues            */
250
/*  Inputs        : ps_dec    Decoder parameters                       */
251
/*  Globals       : None                                                     */
252
/*  Processing    : This functionality needs to be implemented               */
253
/*  Outputs       : None                                                     */
254
/*  Returns       : None                                                     */
255
/*                                                                           */
256
/*  Issues        : Not implemented                                          */
257
/*                                                                           */
258
/*  Revision History:                                                        */
259
/*                                                                           */
260
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
261
/*         06 05 2002   NS              Draft                                */
262
/*                                                                           */
263
/*****************************************************************************/
264
void ih264d_parse_end_of_stream(dec_struct_t * ps_dec)
265
231
{
266
231
    UNUSED(ps_dec);
267
231
    return;
268
231
}
269
270
/*!
271
 **************************************************************************
272
 * \if Function name : ih264d_parse_pps \endif
273
 *
274
 * \brief
275
 *    Decodes Picture Parameter set
276
 *
277
 * \return
278
 *    0 on Success and Error code otherwise
279
 **************************************************************************
280
 */
281
WORD32 ih264d_parse_pps(dec_struct_t * ps_dec, dec_bit_stream_t * ps_bitstrm)
282
44.7k
{
283
44.7k
    UWORD8 uc_temp;
284
44.7k
    dec_seq_params_t * ps_sps = NULL;
285
44.7k
    dec_pic_params_t * ps_pps = NULL;
286
44.7k
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
287
44.7k
    UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
288
289
    /* Variables used for error resilience checks */
290
44.7k
    UWORD64 u8_temp;
291
44.7k
    UWORD32 u4_temp;
292
44.7k
    WORD32 i_temp;
293
294
    /* For High profile related syntax elements */
295
44.7k
    UWORD8 u1_more_data_flag;
296
44.7k
    WORD32 i4_i;
297
298
44.7k
    if(!(ps_dec->i4_header_decoded & 1))
299
808
        return ERROR_INV_SPS_PPS_T;
300
301
    /*--------------------------------------------------------------------*/
302
    /* Decode pic_parameter_set_id and find corresponding pic params      */
303
    /*--------------------------------------------------------------------*/
304
43.9k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
305
43.9k
    if(u4_temp & MASK_ERR_PIC_SET_ID)
306
128
        return ERROR_INV_SPS_PPS_T;
307
43.8k
    ps_pps = ps_dec->pv_scratch_sps_pps;
308
43.8k
    *ps_pps = ps_dec->ps_pps[u4_temp];
309
43.8k
    ps_pps->u1_pic_parameter_set_id = (WORD8)u4_temp;
310
43.8k
    COPYTHECONTEXT("PPS: pic_parameter_set_id",ps_pps->u1_pic_parameter_set_id);
311
312
    /************************************************/
313
    /* initilization of High profile syntax element */
314
    /************************************************/
315
43.8k
    ps_pps->i4_transform_8x8_mode_flag = 0;
316
43.8k
    ps_pps->i4_pic_scaling_matrix_present_flag = 0;
317
318
    /*--------------------------------------------------------------------*/
319
    /* Decode seq_parameter_set_id and map it to a seq_parameter_set      */
320
    /*--------------------------------------------------------------------*/
321
43.8k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
322
43.8k
    if(u4_temp & MASK_ERR_SEQ_SET_ID)
323
83
        return ERROR_INV_SPS_PPS_T;
324
43.7k
    COPYTHECONTEXT("PPS: seq_parameter_set_id",u4_temp);
325
43.7k
    ps_sps = &ps_dec->ps_sps[u4_temp];
326
327
43.7k
    if(FALSE == ps_sps->u1_is_valid)
328
167
        return ERROR_INV_SPS_PPS_T;
329
43.5k
    ps_pps->ps_sps = ps_sps;
330
331
    /*--------------------------------------------------------------------*/
332
    /* Decode entropy_coding_mode                                         */
333
    /*--------------------------------------------------------------------*/
334
43.5k
    ps_pps->u1_entropy_coding_mode = ih264d_get_bit_h264(ps_bitstrm);
335
43.5k
    COPYTHECONTEXT("PPS: entropy_coding_mode_flag",ps_pps->u1_entropy_coding_mode);
336
337
43.5k
    ps_pps->u1_pic_order_present_flag = ih264d_get_bit_h264(ps_bitstrm);
338
43.5k
    COPYTHECONTEXT("PPS: pic_order_present_flag",ps_pps->u1_pic_order_present_flag);
339
340
    /*--------------------------------------------------------------------*/
341
    /* Decode num_slice_groups_minus1                                     */
342
    /*--------------------------------------------------------------------*/
343
43.5k
    u8_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + (UWORD64)1;
344
43.5k
    if(u8_temp != 1)
345
87
    {
346
87
        return ERROR_FEATURE_UNAVAIL;
347
87
    }
348
43.4k
    ps_pps->u1_num_slice_groups = u8_temp;
349
43.4k
    COPYTHECONTEXT("PPS: num_slice_groups_minus1",ps_pps->u1_num_slice_groups -1);
350
351
    /*--------------------------------------------------------------------*/
352
    /* Other parameter set values                                         */
353
    /*--------------------------------------------------------------------*/
354
43.4k
    u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
355
43.4k
    if(u8_temp > H264_MAX_REF_IDX)
356
50
        return ERROR_REF_IDX;
357
43.4k
    ps_pps->u1_num_ref_idx_lx_active[0] = u8_temp;
358
43.4k
    COPYTHECONTEXT("PPS: num_ref_idx_l0_active_minus1",
359
43.4k
                    ps_pps->u1_num_ref_idx_lx_active[0] - 1);
360
361
43.4k
    u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
362
43.4k
    if(u8_temp > H264_MAX_REF_IDX)
363
65
        return ERROR_REF_IDX;
364
43.3k
    ps_pps->u1_num_ref_idx_lx_active[1] = u8_temp;
365
43.3k
    COPYTHECONTEXT("PPS: num_ref_idx_l1_active_minus1",
366
43.3k
                    ps_pps->u1_num_ref_idx_lx_active[1] - 1);
367
368
43.3k
    ps_pps->u1_wted_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
369
43.3k
    COPYTHECONTEXT("PPS: weighted prediction u4_flag",ps_pps->u1_wted_pred_flag);
370
43.3k
    uc_temp = ih264d_get_bits_h264(ps_bitstrm, 2);
371
43.3k
    COPYTHECONTEXT("PPS: weighted_bipred_idc",uc_temp);
372
43.3k
    ps_pps->u1_wted_bipred_idc = uc_temp;
373
374
43.3k
    if(ps_pps->u1_wted_bipred_idc > MAX_WEIGHT_BIPRED_IDC)
375
25
        return ERROR_INV_SPS_PPS_T;
376
43.3k
    {
377
43.3k
        WORD64 i8_temp;
378
43.3k
        i8_temp = (WORD64)26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
379
380
43.3k
        if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
381
93
            return ERROR_INV_RANGE_QP_T;
382
383
43.2k
        ps_pps->u1_pic_init_qp = i8_temp;
384
43.2k
        COPYTHECONTEXT("PPS: pic_init_qp_minus26",ps_pps->u1_pic_init_qp - 26);
385
386
43.2k
        i8_temp = (WORD64)26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
387
388
43.2k
        if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
389
65
            return ERROR_INV_RANGE_QP_T;
390
391
43.1k
        ps_pps->u1_pic_init_qs = i8_temp;
392
43.1k
        COPYTHECONTEXT("PPS: pic_init_qs_minus26",ps_pps->u1_pic_init_qs - 26);
393
43.1k
    }
394
395
0
    i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
396
43.1k
    if((i_temp < -12) || (i_temp > 12))
397
1.54k
        return ERROR_INV_RANGE_QP_T;
398
41.6k
    ps_pps->i1_chroma_qp_index_offset = i_temp;
399
41.6k
    COPYTHECONTEXT("PPS: chroma_qp_index_offset",ps_pps->i1_chroma_qp_index_offset);
400
401
    /***************************************************************************/
402
    /* initialize second_chroma_qp_index_offset to i1_chroma_qp_index_offset if */
403
    /* second_chroma_qp_index_offset is not present in bit-ps_bitstrm              */
404
    /***************************************************************************/
405
41.6k
    ps_pps->i1_second_chroma_qp_index_offset =
406
41.6k
                    ps_pps->i1_chroma_qp_index_offset;
407
408
41.6k
    ps_pps->u1_deblocking_filter_parameters_present_flag = ih264d_get_bit_h264(
409
41.6k
                    ps_bitstrm);
410
41.6k
    COPYTHECONTEXT("PPS: deblocking_filter_control_present_flag",
411
41.6k
                    ps_pps->u1_deblocking_filter_parameters_present_flag);
412
41.6k
    ps_pps->u1_constrained_intra_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
413
41.6k
    COPYTHECONTEXT("PPS: constrained_intra_pred_flag",
414
41.6k
                    ps_pps->u1_constrained_intra_pred_flag);
415
41.6k
    ps_pps->u1_redundant_pic_cnt_present_flag = ih264d_get_bit_h264(ps_bitstrm);
416
41.6k
    COPYTHECONTEXT("PPS: redundant_pic_cnt_present_flag",
417
41.6k
                    ps_pps->u1_redundant_pic_cnt_present_flag);
418
419
    /* High profile related syntax elements */
420
41.6k
    u1_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
421
41.6k
    if(u1_more_data_flag)
422
34.1k
    {
423
        /* read transform_8x8_mode_flag  */
424
34.1k
        ps_pps->i4_transform_8x8_mode_flag = (WORD32)ih264d_get_bit_h264(
425
34.1k
                        ps_bitstrm);
426
427
        /* read pic_scaling_matrix_present_flag */
428
34.1k
        ps_pps->i4_pic_scaling_matrix_present_flag =
429
34.1k
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
430
431
34.1k
        if(ps_pps->i4_pic_scaling_matrix_present_flag)
432
1.69k
        {
433
            /* read the scaling matrices */
434
11.8k
            for(i4_i = 0; i4_i < (6 + (ps_pps->i4_transform_8x8_mode_flag << 1)); i4_i++)
435
10.5k
            {
436
10.5k
                ps_pps->u1_pic_scaling_list_present_flag[i4_i] =
437
10.5k
                                ih264d_get_bit_h264(ps_bitstrm);
438
439
10.5k
                if(ps_pps->u1_pic_scaling_list_present_flag[i4_i])
440
3.50k
                {
441
3.50k
                    WORD32 ret;
442
3.50k
                    if(i4_i < 6)
443
2.85k
                    {
444
2.85k
                        ret = ih264d_scaling_list(
445
2.85k
                                        ps_pps->i2_pic_scalinglist4x4[i4_i],
446
2.85k
                                        16,
447
2.85k
                                        &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
448
2.85k
                                        ps_bitstrm);
449
2.85k
                    }
450
652
                    else
451
652
                    {
452
652
                        ret = ih264d_scaling_list(
453
652
                                        ps_pps->i2_pic_scalinglist8x8[i4_i - 6],
454
652
                                        64,
455
652
                                        &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
456
652
                                        ps_bitstrm);
457
652
                    }
458
459
3.50k
                    if(ret != OK)
460
406
                    {
461
406
                        return ret;
462
406
                    }
463
3.50k
                }
464
10.5k
            }
465
1.69k
        }
466
467
        /* read second_chroma_qp_index_offset syntax element */
468
33.7k
        i_temp = ih264d_sev(
469
33.7k
                        pu4_bitstrm_ofst, pu4_bitstrm_buf);
470
471
33.7k
        if((i_temp < -12) || (i_temp > 12))
472
266
            return ERROR_INV_RANGE_QP_T;
473
474
33.4k
        ps_pps->i1_second_chroma_qp_index_offset = i_temp;
475
33.4k
    }
476
477
    /* In case bitstream read has exceeded the filled size, then
478
       return an error */
479
40.9k
    if(EXCEED_OFFSET(ps_bitstrm))
480
156
    {
481
156
        return ERROR_INV_SPS_PPS_T;
482
156
    }
483
40.7k
    ps_pps->u1_is_valid = TRUE;
484
40.7k
    ps_dec->ps_pps[ps_pps->u1_pic_parameter_set_id] = *ps_pps;
485
40.7k
    return OK;
486
40.9k
}
487
488
/*!
489
 **************************************************************************
490
 * \if Function name : ih264d_parse_sps \endif
491
 *
492
 * \brief
493
 *    Decodes Sequence parameter set from the bitstream
494
 *
495
 * \return
496
 *    0 on Success and Error code otherwise
497
 **************************************************************************
498
 */
499
UWORD32 ih264d_correct_level_idc(UWORD32 u4_level_idc, UWORD32 u4_total_mbs)
500
168k
{
501
168k
    UWORD32 u4_max_mbs_allowed;
502
503
168k
    switch(u4_level_idc)
504
168k
    {
505
4.30k
        case H264_LEVEL_1_0:
506
4.30k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_10;
507
4.30k
            break;
508
18.4k
        case H264_LEVEL_1_1:
509
18.4k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_11;
510
18.4k
            break;
511
3.42k
        case H264_LEVEL_1_2:
512
3.42k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_12;
513
3.42k
            break;
514
1.53k
        case H264_LEVEL_1_3:
515
1.53k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_13;
516
1.53k
            break;
517
22.1k
        case H264_LEVEL_2_0:
518
22.1k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_20;
519
22.1k
            break;
520
4.42k
        case H264_LEVEL_2_1:
521
4.42k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_21;
522
4.42k
            break;
523
1.62k
        case H264_LEVEL_2_2:
524
1.62k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_22;
525
1.62k
            break;
526
3.89k
        case H264_LEVEL_3_0:
527
3.89k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_30;
528
3.89k
            break;
529
3.41k
        case H264_LEVEL_3_1:
530
3.41k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_31;
531
3.41k
            break;
532
39.6k
        case H264_LEVEL_3_2:
533
39.6k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_32;
534
39.6k
            break;
535
5.51k
        case H264_LEVEL_4_0:
536
5.51k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_40;
537
5.51k
            break;
538
2.34k
        case H264_LEVEL_4_1:
539
2.34k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_41;
540
2.34k
            break;
541
6.56k
        case H264_LEVEL_4_2:
542
6.56k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_42;
543
6.56k
            break;
544
774
        case H264_LEVEL_5_0:
545
774
            u4_max_mbs_allowed = MAX_MBS_LEVEL_50;
546
774
            break;
547
114
        case H264_LEVEL_5_1:
548
50.0k
        default:
549
50.0k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_51;
550
50.0k
            break;
551
552
168k
    }
553
554
    /*correct of the level is incorrect*/
555
168k
    if(u4_total_mbs > u4_max_mbs_allowed)
556
3.36k
    {
557
3.36k
        if(u4_total_mbs > MAX_MBS_LEVEL_50)
558
174
            u4_level_idc = H264_LEVEL_5_1;
559
3.19k
        else if(u4_total_mbs > MAX_MBS_LEVEL_42)
560
864
            u4_level_idc = H264_LEVEL_5_0;
561
2.33k
        else if(u4_total_mbs > MAX_MBS_LEVEL_41)
562
352
            u4_level_idc = H264_LEVEL_4_2;
563
1.97k
        else if(u4_total_mbs > MAX_MBS_LEVEL_40)
564
0
            u4_level_idc = H264_LEVEL_4_1;
565
1.97k
        else if(u4_total_mbs > MAX_MBS_LEVEL_32)
566
159
            u4_level_idc = H264_LEVEL_4_0;
567
1.82k
        else if(u4_total_mbs > MAX_MBS_LEVEL_31)
568
341
            u4_level_idc = H264_LEVEL_3_2;
569
1.47k
        else if(u4_total_mbs > MAX_MBS_LEVEL_30)
570
132
            u4_level_idc = H264_LEVEL_3_1;
571
1.34k
        else if(u4_total_mbs > MAX_MBS_LEVEL_21)
572
282
            u4_level_idc = H264_LEVEL_3_0;
573
1.06k
        else if(u4_total_mbs > MAX_MBS_LEVEL_20)
574
664
            u4_level_idc = H264_LEVEL_2_1;
575
401
        else if(u4_total_mbs > MAX_MBS_LEVEL_10)
576
401
            u4_level_idc = H264_LEVEL_2_0;
577
3.36k
    }
578
579
168k
    return (u4_level_idc);
580
581
168k
}
582
WORD32 ih264d_parse_sps(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm)
583
52.3k
{
584
52.3k
    UWORD8 i;
585
52.3k
    dec_seq_params_t *ps_seq = NULL;
586
52.3k
    UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
587
52.3k
    UWORD32 u4_max_frm_num;
588
52.3k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
589
52.3k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
590
52.3k
    UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag;
591
52.3k
    WORD32 i4_cropped_ht, i4_cropped_wd;
592
52.3k
    UWORD32 u4_temp;
593
52.3k
    UWORD64 u8_temp;
594
52.3k
    UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
595
52.3k
    UWORD32 u2_pic_wd = 0;
596
52.3k
    UWORD32 u2_pic_ht = 0;
597
52.3k
    UWORD32 u2_frm_wd_y = 0;
598
52.3k
    UWORD32 u2_frm_ht_y = 0;
599
52.3k
    UWORD32 u2_frm_wd_uv = 0;
600
52.3k
    UWORD32 u2_frm_ht_uv = 0;
601
52.3k
    UWORD32 u2_crop_offset_y = 0;
602
52.3k
    UWORD32 u2_crop_offset_uv = 0;
603
52.3k
    WORD32 ret;
604
52.3k
    WORD32 num_reorder_frames;
605
    /* High profile related syntax element */
606
52.3k
    WORD32 i4_i;
607
    /* G050 */
608
52.3k
    UWORD8 u1_frame_cropping_flag, u1_frame_cropping_rect_left_ofst,
609
52.3k
                    u1_frame_cropping_rect_right_ofst,
610
52.3k
                    u1_frame_cropping_rect_top_ofst,
611
52.3k
                    u1_frame_cropping_rect_bottom_ofst;
612
    /* G050 */
613
    /*--------------------------------------------------------------------*/
614
    /* Decode seq_parameter_set_id and profile and level values           */
615
    /*--------------------------------------------------------------------*/
616
52.3k
    SWITCHONTRACE;
617
52.3k
    u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
618
52.3k
    COPYTHECONTEXT("SPS: profile_idc",u1_profile_idc);
619
620
    /* G050 */
621
52.3k
    uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
622
52.3k
    uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
623
52.3k
    ih264d_get_bit_h264(ps_bitstrm);
624
625
    /*****************************************************/
626
    /* Read 5 bits for uc_constraint_set3_flag (1 bit)   */
627
    /* and reserved_zero_4bits (4 bits) - Sushant        */
628
    /*****************************************************/
629
52.3k
    ih264d_get_bits_h264(ps_bitstrm, 5);
630
    /* G050 */
631
632
    /* Check whether particular profile is suported or not */
633
    /* Check whether particular profile is suported or not */
634
52.3k
    if((u1_profile_idc != MAIN_PROFILE_IDC) &&
635
636
46.3k
    (u1_profile_idc != BASE_PROFILE_IDC) &&
637
638
15.2k
    (u1_profile_idc != HIGH_PROFILE_IDC)
639
640
52.3k
    )
641
4.52k
    {
642
643
        /* Apart from Baseline, main and high profile,
644
         * only extended profile is supported provided
645
         * uc_constraint_set0_flag or uc_constraint_set1_flag are set to 1
646
         */
647
4.52k
        if((u1_profile_idc != EXTENDED_PROFILE_IDC) ||
648
4.23k
           ((uc_constraint_set1_flag != 1) && (uc_constraint_set0_flag != 1)))
649
301
        {
650
301
            return (ERROR_FEATURE_UNAVAIL);
651
301
        }
652
4.52k
    }
653
654
52.0k
    u1_level_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
655
656
657
658
52.0k
    COPYTHECONTEXT("SPS: u4_level_idc",u1_level_idc);
659
660
52.0k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
661
52.0k
    if(u4_temp & MASK_ERR_SEQ_SET_ID)
662
296
        return ERROR_INV_SPS_PPS_T;
663
51.7k
    u1_seq_parameter_set_id = u4_temp;
664
51.7k
    COPYTHECONTEXT("SPS: seq_parameter_set_id",
665
51.7k
                    u1_seq_parameter_set_id);
666
667
    /*--------------------------------------------------------------------*/
668
    /* Find an seq param entry in seqparam array of decStruct             */
669
    /*--------------------------------------------------------------------*/
670
671
51.7k
    ps_seq = ps_dec->pv_scratch_sps_pps;
672
51.7k
    memset(ps_seq, 0, sizeof(dec_seq_params_t));
673
674
51.7k
    if(ps_dec->i4_header_decoded & 1)
675
31.1k
    {
676
31.1k
        *ps_seq = *ps_dec->ps_cur_sps;
677
31.1k
    }
678
679
680
51.7k
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_profile_idc != u1_profile_idc))
681
517
    {
682
517
        ps_dec->u1_res_changed = 1;
683
517
        return IVD_RES_CHANGED;
684
517
    }
685
686
51.2k
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_level_idc != u1_level_idc))
687
2.64k
    {
688
2.64k
        ps_dec->u1_res_changed = 1;
689
2.64k
        return IVD_RES_CHANGED;
690
2.64k
    }
691
692
48.5k
    ps_seq->u1_profile_idc = u1_profile_idc;
693
48.5k
    ps_seq->u1_level_idc = u1_level_idc;
694
48.5k
    ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
695
696
    /*******************************************************************/
697
    /* Initializations for high profile - Sushant                      */
698
    /*******************************************************************/
699
48.5k
    ps_seq->i4_chroma_format_idc = 1;
700
48.5k
    ps_seq->i4_bit_depth_luma_minus8 = 0;
701
48.5k
    ps_seq->i4_bit_depth_chroma_minus8 = 0;
702
48.5k
    ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
703
48.5k
    ps_seq->i4_seq_scaling_matrix_present_flag = 0;
704
48.5k
    if(u1_profile_idc == HIGH_PROFILE_IDC)
705
10.5k
    {
706
707
        /* reading chroma_format_idc   */
708
10.5k
        ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst,
709
10.5k
                                                  pu4_bitstrm_buf);
710
711
        /* Monochrome is not supported */
712
10.5k
        if(ps_seq->i4_chroma_format_idc != 1)
713
110
        {
714
110
            return ERROR_FEATURE_UNAVAIL;
715
110
        }
716
717
        /* reading bit_depth_luma_minus8   */
718
10.3k
        ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst,
719
10.3k
                                                      pu4_bitstrm_buf);
720
721
10.3k
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
722
59
        {
723
59
            return ERROR_FEATURE_UNAVAIL;
724
59
        }
725
726
        /* reading bit_depth_chroma_minus8   */
727
10.3k
        ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst,
728
10.3k
                                                        pu4_bitstrm_buf);
729
730
10.3k
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
731
61
        {
732
61
            return ERROR_FEATURE_UNAVAIL;
733
61
        }
734
735
        /* reading qpprime_y_zero_transform_bypass_flag   */
736
10.2k
        ps_seq->i4_qpprime_y_zero_transform_bypass_flag =
737
10.2k
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
738
739
10.2k
        if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
740
10
        {
741
10
            return ERROR_INV_SPS_PPS_T;
742
10
        }
743
744
        /* reading seq_scaling_matrix_present_flag   */
745
10.2k
        ps_seq->i4_seq_scaling_matrix_present_flag =
746
10.2k
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
747
748
10.2k
        if(ps_seq->i4_seq_scaling_matrix_present_flag)
749
1.50k
        {
750
12.9k
            for(i4_i = 0; i4_i < 8; i4_i++)
751
11.5k
            {
752
11.5k
                ps_seq->u1_seq_scaling_list_present_flag[i4_i] =
753
11.5k
                                ih264d_get_bit_h264(ps_bitstrm);
754
755
                /* initialize u1_use_default_scaling_matrix_flag[i4_i] to zero */
756
                /* before calling scaling list                             */
757
11.5k
                ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
758
759
11.5k
                if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
760
3.07k
                {
761
3.07k
                    if(i4_i < 6)
762
1.69k
                    {
763
1.69k
                        ret = ih264d_scaling_list(
764
1.69k
                                        ps_seq->i2_scalinglist4x4[i4_i],
765
1.69k
                                        16,
766
1.69k
                                        &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
767
1.69k
                                        ps_bitstrm);
768
1.69k
                    }
769
1.38k
                    else
770
1.38k
                    {
771
1.38k
                        ret = ih264d_scaling_list(
772
1.38k
                                        ps_seq->i2_scalinglist8x8[i4_i - 6],
773
1.38k
                                        64,
774
1.38k
                                        &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
775
1.38k
                                        ps_bitstrm);
776
1.38k
                    }
777
3.07k
                    if(ret != OK)
778
104
                    {
779
104
                        return ret;
780
104
                    }
781
3.07k
                }
782
11.5k
            }
783
1.50k
        }
784
10.2k
    }
785
    /*--------------------------------------------------------------------*/
786
    /* Decode MaxFrameNum                                                 */
787
    /*--------------------------------------------------------------------*/
788
48.2k
    u8_temp = (UWORD64)4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
789
48.2k
    if(u8_temp > MAX_BITS_IN_FRAME_NUM)
790
76
    {
791
76
        return ERROR_INV_SPS_PPS_T;
792
76
    }
793
48.1k
    ps_seq->u1_bits_in_frm_num = u8_temp;
794
48.1k
    COPYTHECONTEXT("SPS: log2_max_frame_num_minus4",
795
48.1k
                    (ps_seq->u1_bits_in_frm_num - 4));
796
797
48.1k
    u4_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
798
48.1k
    ps_seq->u2_u4_max_pic_num_minus1 = u4_max_frm_num - 1;
799
    /*--------------------------------------------------------------------*/
800
    /* Decode picture order count and related values                      */
801
    /*--------------------------------------------------------------------*/
802
48.1k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
803
804
48.1k
    if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
805
93
    {
806
93
        return ERROR_INV_POC_TYPE_T;
807
93
    }
808
48.0k
    ps_seq->u1_pic_order_cnt_type = u4_temp;
809
48.0k
    COPYTHECONTEXT("SPS: pic_order_cnt_type",ps_seq->u1_pic_order_cnt_type);
810
811
48.0k
    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
812
48.0k
    if(ps_seq->u1_pic_order_cnt_type == 0)
813
19.1k
    {
814
19.1k
        u8_temp = (UWORD64)4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
815
19.1k
        if(u8_temp > MAX_BITS_IN_POC_LSB)
816
63
        {
817
63
            return ERROR_INV_SPS_PPS_T;
818
63
        }
819
19.1k
        ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = u8_temp;
820
19.1k
        ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
821
19.1k
        COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4",(u8_temp - 4));
822
19.1k
    }
823
28.8k
    else if(ps_seq->u1_pic_order_cnt_type == 1)
824
6.36k
    {
825
6.36k
        ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(
826
6.36k
                        ps_bitstrm);
827
6.36k
        COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
828
6.36k
                        ps_seq->u1_delta_pic_order_always_zero_flag);
829
830
6.36k
        ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst,
831
6.36k
                                                     pu4_bitstrm_buf);
832
6.36k
        COPYTHECONTEXT("SPS: offset_for_non_ref_pic",
833
6.36k
                        ps_seq->i4_ofst_for_non_ref_pic);
834
835
6.36k
        ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(
836
6.36k
                        pu4_bitstrm_ofst, pu4_bitstrm_buf);
837
6.36k
        COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
838
6.36k
                        ps_seq->i4_ofst_for_top_to_bottom_field);
839
840
6.36k
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
841
6.36k
        if(u4_temp > 255)
842
52
            return ERROR_INV_SPS_PPS_T;
843
6.31k
        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
844
6.31k
        COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
845
6.31k
                        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
846
847
25.4k
        for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
848
19.1k
        {
849
19.1k
            ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(
850
19.1k
                            pu4_bitstrm_ofst, pu4_bitstrm_buf);
851
19.1k
            COPYTHECONTEXT("SPS: offset_for_ref_frame",
852
19.1k
                            ps_seq->i4_ofst_for_ref_frame[i]);
853
19.1k
        }
854
6.31k
    }
855
856
47.9k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
857
858
47.9k
    if((u4_temp > H264_MAX_REF_PICS))
859
151
    {
860
151
        return ERROR_NUM_REF;
861
151
    }
862
863
    /* Compare with older num_ref_frames is header is already once */
864
47.7k
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_num_ref_frames != u4_temp))
865
91
    {
866
91
        ps_dec->u1_res_changed = 1;
867
91
        return IVD_RES_CHANGED;
868
91
    }
869
870
47.7k
    ps_seq->u1_num_ref_frames = u4_temp;
871
47.7k
    COPYTHECONTEXT("SPS: num_ref_frames",ps_seq->u1_num_ref_frames);
872
873
47.7k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(
874
47.7k
                    ps_bitstrm);
875
47.7k
    COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
876
47.7k
                    ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
877
878
    /*--------------------------------------------------------------------*/
879
    /* Decode FrameWidth and FrameHeight and related values               */
880
    /*--------------------------------------------------------------------*/
881
47.7k
    u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
882
    /* Check  for unsupported resolutions*/
883
47.7k
    if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
884
104
    {
885
104
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
886
104
    }
887
47.6k
    u4_pic_width_in_mbs = u8_temp;
888
47.6k
    COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1",
889
47.6k
                   u4_pic_width_in_mbs - 1);
890
891
47.6k
    u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
892
47.6k
    if (u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
893
72
    {
894
72
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
895
72
    }
896
47.5k
    u4_pic_height_in_map_units = u8_temp;
897
898
47.5k
    ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
899
47.5k
    ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
900
901
47.5k
    u2_pic_wd = (u4_pic_width_in_mbs << 4);
902
47.5k
    u2_pic_ht = (u4_pic_height_in_map_units << 4);
903
    /*--------------------------------------------------------------------*/
904
    /* Get the value of MaxMbAddress and Number of bits needed for it     */
905
    /*--------------------------------------------------------------------*/
906
47.5k
    ps_seq->u4_max_mb_addr = ((UWORD32)ps_seq->u2_frm_wd_in_mbs
907
47.5k
                    * (UWORD32)ps_seq->u2_frm_ht_in_mbs) - 1;
908
909
47.5k
    ps_seq->u4_total_num_of_mbs = ps_seq->u4_max_mb_addr + 1;
910
911
47.5k
    ps_seq->u1_level_idc = ih264d_correct_level_idc(
912
47.5k
                    u1_level_idc, ps_seq->u4_total_num_of_mbs);
913
914
47.5k
    u1_frm = ih264d_get_bit_h264(ps_bitstrm);
915
47.5k
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_frame_mbs_only_flag != u1_frm))
916
27
    {
917
27
        ps_dec->u1_res_changed = 1;
918
27
        return IVD_RES_CHANGED;
919
27
    }
920
921
47.5k
    ps_seq->u1_frame_mbs_only_flag = u1_frm;
922
923
47.5k
    COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
924
925
47.5k
    if(!u1_frm)
926
4.92k
        u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
927
928
47.5k
    if((ps_dec->i4_header_decoded & 1)
929
27.8k
                    && (ps_seq->u1_mb_aff_flag != u1_mb_aff_flag))
930
19
    {
931
19
        ps_dec->u1_res_changed = 1;
932
19
        return IVD_RES_CHANGED;
933
19
    }
934
935
47.4k
    if(!u1_frm)
936
4.90k
    {
937
4.90k
        u2_pic_ht <<= 1;
938
4.90k
        ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
939
4.90k
        COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag",
940
4.90k
                        ps_seq->u1_mb_aff_flag);
941
942
4.90k
    }
943
42.5k
    else
944
42.5k
        ps_seq->u1_mb_aff_flag = 0;
945
946
47.4k
    ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
947
948
47.4k
    COPYTHECONTEXT("SPS: direct_8x8_inference_flag",
949
47.4k
                    ps_seq->u1_direct_8x8_inference_flag);
950
951
    /* G050 */
952
47.4k
    u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
953
47.4k
    COPYTHECONTEXT("SPS: frame_cropping_flag",u1_frame_cropping_flag);
954
955
47.4k
    if(u1_frame_cropping_flag)
956
6.81k
    {
957
6.81k
        u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst,
958
6.81k
                                                      pu4_bitstrm_buf);
959
6.81k
        COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset",
960
6.81k
                        u1_frame_cropping_rect_left_ofst);
961
6.81k
        u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst,
962
6.81k
                                                       pu4_bitstrm_buf);
963
6.81k
        COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset",
964
6.81k
                        u1_frame_cropping_rect_right_ofst);
965
6.81k
        u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst,
966
6.81k
                                                     pu4_bitstrm_buf);
967
6.81k
        COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset",
968
6.81k
                        u1_frame_cropping_rect_top_ofst);
969
6.81k
        u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst,
970
6.81k
                                                        pu4_bitstrm_buf);
971
6.81k
        COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
972
6.81k
                        u1_frame_cropping_rect_bottom_ofst);
973
6.81k
    }
974
    /* G050 */
975
976
47.4k
    ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
977
47.4k
    COPYTHECONTEXT("SPS: vui_parameters_present_flag",
978
47.4k
                    ps_seq->u1_vui_parameters_present_flag);
979
980
47.4k
    u2_frm_wd_y = u2_pic_wd + (UWORD8)(PAD_LEN_Y_H << 1);
981
47.4k
    if(1 == ps_dec->u4_share_disp_buf)
982
0
    {
983
0
        if(ps_dec->u4_app_disp_width > u2_frm_wd_y)
984
0
            u2_frm_wd_y = ps_dec->u4_app_disp_width;
985
0
    }
986
987
47.4k
    u2_frm_ht_y = u2_pic_ht + (UWORD8)(PAD_LEN_Y_V << 2);
988
47.4k
    u2_frm_wd_uv = u2_pic_wd + (UWORD8)(PAD_LEN_UV_H << 2);
989
47.4k
    u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
990
991
47.4k
    u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8)(PAD_LEN_UV_V << 2);
992
47.4k
    u2_frm_ht_uv = MAX(u2_frm_ht_uv, (u2_frm_ht_y >> 1));
993
994
995
    /* Calculate display picture width, height and start u4_ofst from YUV420 */
996
    /* pictute buffers as per cropping information parsed above             */
997
47.4k
    {
998
47.4k
        UWORD16 u2_rgt_ofst = 0;
999
47.4k
        UWORD16 u2_lft_ofst = 0;
1000
47.4k
        UWORD16 u2_top_ofst = 0;
1001
47.4k
        UWORD16 u2_btm_ofst = 0;
1002
47.4k
        UWORD8 u1_frm_mbs_flag;
1003
47.4k
        UWORD8 u1_vert_mult_factor;
1004
1005
47.4k
        if(u1_frame_cropping_flag)
1006
6.81k
        {
1007
            /* Calculate right and left u4_ofst for cropped picture           */
1008
6.81k
            u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
1009
6.81k
            u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
1010
1011
            /* Know frame MBs only u4_flag                                      */
1012
6.81k
            u1_frm_mbs_flag = (1 == ps_seq->u1_frame_mbs_only_flag);
1013
1014
            /* Simplify the vertical u4_ofst calculation from field/frame     */
1015
6.81k
            u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
1016
1017
            /* Calculate bottom and top u4_ofst for cropped  picture          */
1018
6.81k
            u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst
1019
6.81k
                            << u1_vert_mult_factor);
1020
6.81k
            u2_top_ofst = (u1_frame_cropping_rect_top_ofst
1021
6.81k
                            << u1_vert_mult_factor);
1022
6.81k
        }
1023
1024
        /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
1025
        /* cropped picture buffer                                           */
1026
47.4k
        u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
1027
47.4k
        u2_crop_offset_uv = (u2_frm_wd_uv * (u2_top_ofst >> 1))
1028
47.4k
                        + (u2_lft_ofst >> 1) * YUV420SP_FACTOR;
1029
        /* Calculate the display picture width and height based on crop      */
1030
        /* information                                                       */
1031
47.4k
        i4_cropped_ht = (WORD32)u2_pic_ht - (WORD32)(u2_btm_ofst + u2_top_ofst);
1032
47.4k
        i4_cropped_wd = (WORD32)u2_pic_wd - (WORD32)(u2_rgt_ofst + u2_lft_ofst);
1033
1034
47.4k
        if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
1035
142
        {
1036
142
            return ERROR_INV_SPS_PPS_T;
1037
142
        }
1038
1039
47.3k
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_wd != u2_pic_wd))
1040
23
        {
1041
23
            ps_dec->u1_res_changed = 1;
1042
23
            return IVD_RES_CHANGED;
1043
23
        }
1044
1045
47.3k
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_disp_width != i4_cropped_wd))
1046
145
        {
1047
145
            ps_dec->u1_res_changed = 1;
1048
145
            return IVD_RES_CHANGED;
1049
145
        }
1050
1051
47.1k
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_ht != u2_pic_ht))
1052
18
        {
1053
18
            ps_dec->u1_res_changed = 1;
1054
18
            return IVD_RES_CHANGED;
1055
18
        }
1056
1057
47.1k
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_disp_height != i4_cropped_ht))
1058
145
        {
1059
145
            ps_dec->u1_res_changed = 1;
1060
145
            return IVD_RES_CHANGED;
1061
145
        }
1062
1063
        /* Check again for unsupported resolutions with updated values*/
1064
47.0k
        if((u2_pic_wd > H264_MAX_FRAME_WIDTH) || (u2_pic_ht > H264_MAX_FRAME_HEIGHT)
1065
46.9k
                || (u2_pic_wd < H264_MIN_FRAME_WIDTH) || (u2_pic_ht < H264_MIN_FRAME_HEIGHT)
1066
46.9k
                || (u2_pic_wd * (UWORD32)u2_pic_ht > H264_MAX_FRAME_SIZE))
1067
28
        {
1068
28
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1069
28
        }
1070
1071
        /* If MBAff is enabled, decoder support is limited to streams with
1072
         * width less than half of H264_MAX_FRAME_WIDTH.
1073
         * In case of MBAff decoder processes two rows at a time
1074
         */
1075
46.9k
        if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
1076
53
        {
1077
53
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1078
53
        }
1079
1080
46.9k
    }
1081
1082
    /* Backup num_reorder_frames if header is already decoded */
1083
46.9k
    if((ps_dec->i4_header_decoded & 1) &&
1084
27.4k
                    (1 == ps_seq->u1_vui_parameters_present_flag) &&
1085
5.50k
                    (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1086
2.38k
    {
1087
2.38k
        num_reorder_frames =  (WORD32)ps_seq->s_vui.u4_num_reorder_frames;
1088
2.38k
    }
1089
44.5k
    else
1090
44.5k
    {
1091
44.5k
        num_reorder_frames = -1;
1092
44.5k
    }
1093
46.9k
    if(1 == ps_seq->u1_vui_parameters_present_flag)
1094
7.78k
    {
1095
7.78k
        ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
1096
7.78k
        if(ret != OK)
1097
350
            return ret;
1098
1099
7.43k
        if (ps_dec->pu1_bits_buf_dynamic != NULL && ps_dec->ps_cur_sps != NULL) {
1100
3.78k
            vui_t *ps_vui = &ps_seq->s_vui;
1101
3.78k
            dec_seq_params_t *ps_sps_old = ps_dec->ps_cur_sps;
1102
3.78k
            vui_t *ps_vui_old = &ps_sps_old->s_vui;
1103
1104
3.78k
            if (ps_vui->u1_video_full_range_flag != ps_vui_old->u1_video_full_range_flag ||
1105
3.65k
                ps_vui->u1_colour_primaries != ps_vui_old->u1_colour_primaries ||
1106
3.46k
                ps_vui->u1_tfr_chars != ps_vui_old->u1_tfr_chars ||
1107
3.25k
                ps_vui->u1_matrix_coeffs != ps_vui_old->u1_matrix_coeffs) {
1108
682
                ps_dec->u1_res_changed = 1;
1109
682
                return IVD_RES_CHANGED;
1110
682
            }
1111
3.78k
        }
1112
7.43k
    }
1113
1114
    /* Compare older num_reorder_frames with the new one if header is already decoded */
1115
45.8k
    if((ps_dec->i4_header_decoded & 1) &&
1116
26.7k
                    (-1 != num_reorder_frames) &&
1117
2.15k
                    (1 == ps_seq->u1_vui_parameters_present_flag) &&
1118
2.15k
                    (1 == ps_seq->s_vui.u1_bitstream_restriction_flag) &&
1119
1.73k
                    ((WORD32)ps_seq->s_vui.u4_num_reorder_frames != num_reorder_frames))
1120
170
    {
1121
170
        ps_dec->u1_res_changed = 1;
1122
170
        return IVD_RES_CHANGED;
1123
170
    }
1124
1125
    /* In case bitstream read has exceeded the filled size, then
1126
     return an error */
1127
45.7k
    if (EXCEED_OFFSET(ps_bitstrm))
1128
457
    {
1129
457
        return ERROR_INV_SPS_PPS_T;
1130
457
    }
1131
1132
    /*--------------------------------------------------------------------*/
1133
    /* All initializations to ps_dec are beyond this point                */
1134
    /*--------------------------------------------------------------------*/
1135
45.2k
    {
1136
45.2k
        WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
1137
45.2k
        if((1 == ps_seq->u1_vui_parameters_present_flag) &&
1138
6.31k
           (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1139
2.66k
        {
1140
2.66k
            reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
1141
2.66k
        }
1142
1143
45.2k
        if (reorder_depth > H264_MAX_REF_PICS)
1144
130
        {
1145
130
            return ERROR_INV_SPS_PPS_T;
1146
130
        }
1147
1148
45.1k
        if(ps_seq->u1_frame_mbs_only_flag != 1)
1149
3.53k
            reorder_depth *= 2;
1150
45.1k
        ps_dec->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
1151
45.1k
    }
1152
0
    ps_dec->u2_disp_height = i4_cropped_ht;
1153
45.1k
    ps_dec->u2_disp_width = i4_cropped_wd;
1154
1155
45.1k
    ps_dec->u2_pic_wd = u2_pic_wd;
1156
45.1k
    ps_dec->u2_pic_ht = u2_pic_ht;
1157
45.1k
    ps_dec->u4_total_mbs = ps_seq->u4_total_num_of_mbs << (1 - ps_seq->u1_frame_mbs_only_flag);
1158
1159
    /* Determining the Width and Height of Frame from that of Picture */
1160
45.1k
    ps_dec->u2_frm_wd_y = u2_frm_wd_y;
1161
45.1k
    ps_dec->u2_frm_ht_y = u2_frm_ht_y;
1162
1163
45.1k
    ps_dec->u2_frm_wd_uv = u2_frm_wd_uv;
1164
45.1k
    ps_dec->u2_frm_ht_uv = u2_frm_ht_uv;
1165
45.1k
    ps_dec->s_pad_mgr.u1_pad_len_y_v = (UWORD8)(PAD_LEN_Y_V << (1 - u1_frm));
1166
45.1k
    ps_dec->s_pad_mgr.u1_pad_len_cr_v = (UWORD8)(PAD_LEN_UV_V << (1 - u1_frm));
1167
1168
45.1k
    ps_dec->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs;
1169
45.1k
    ps_dec->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs;
1170
1171
45.1k
    ps_dec->u2_crop_offset_y = u2_crop_offset_y;
1172
45.1k
    ps_dec->u2_crop_offset_uv = u2_crop_offset_uv;
1173
1174
45.1k
    ps_seq->u1_is_valid = TRUE;
1175
45.1k
    ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
1176
45.1k
    ps_dec->ps_cur_sps = &ps_dec->ps_sps[u1_seq_parameter_set_id];
1177
1178
45.1k
    return OK;
1179
45.2k
}
1180
1181
/*!
1182
 **************************************************************************
1183
 * \if Function name : ih264d_parse_end_of_sequence \endif
1184
 *
1185
 * \brief
1186
 *    Decodes End of Sequence.
1187
 *
1188
 * \param ps_bitstrm   : Pointer to bit ps_bitstrm containing the NAL unit
1189
 *
1190
 * \return
1191
 *    0 on Success and error code otherwise
1192
 **************************************************************************
1193
 */
1194
WORD32 ih264d_parse_end_of_sequence(dec_struct_t * ps_dec)
1195
0
{
1196
0
    WORD32 ret;
1197
1198
0
    ret = ih264d_end_of_pic_processing(ps_dec);
1199
0
    return ret;
1200
0
}
1201
1202
/*!
1203
 **************************************************************************
1204
 * \if Function name : AcessUnitDelimiterRbsp \endif
1205
 *
1206
 * \brief
1207
 *    Decodes AcessUnitDelimiterRbsp.
1208
 *
1209
 * \param ps_bitstrm   : Pointer to bit ps_bitstrm containing the NAL unit
1210
 *
1211
 * \return
1212
 *    0 on Success and error code otherwise
1213
 **************************************************************************
1214
 */
1215
1216
WORD32 ih264d_access_unit_delimiter_rbsp(dec_struct_t * ps_dec)
1217
11.7k
{
1218
11.7k
    UWORD8 u1_primary_pic_type;
1219
11.7k
    u1_primary_pic_type = ih264d_get_bits_h264(ps_dec->ps_bitstrm, 3);
1220
11.7k
    switch(u1_primary_pic_type)
1221
11.7k
    {
1222
8.88k
        case I_PIC:
1223
8.98k
        case SI_PIC:
1224
8.99k
        case ISI_PIC:
1225
8.99k
            ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_I;
1226
8.99k
            break;
1227
2.76k
        default:
1228
2.76k
            ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
1229
11.7k
    }
1230
11.7k
    return (0);
1231
11.7k
}
1232
/*!
1233
 **************************************************************************
1234
 * \if Function name : ih264d_parse_nal_unit \endif
1235
 *
1236
 * \brief
1237
 *    Decodes NAL unit
1238
 *
1239
 * \return
1240
 *    0 on Success and error code otherwise
1241
 **************************************************************************
1242
 */
1243
1244
WORD32 ih264d_parse_nal_unit(iv_obj_t *dec_hdl,
1245
                          ivd_video_decode_op_t *ps_dec_op,
1246
                          UWORD8 *pu1_buf,
1247
                          UWORD32 u4_length)
1248
663k
{
1249
1250
663k
    dec_bit_stream_t *ps_bitstrm;
1251
1252
1253
663k
    dec_struct_t *ps_dec = (dec_struct_t *)dec_hdl->pv_codec_handle;
1254
663k
    ivd_video_decode_ip_t *ps_dec_in =
1255
663k
                    (ivd_video_decode_ip_t *)ps_dec->pv_dec_in;
1256
663k
    dec_slice_params_t * ps_cur_slice = ps_dec->ps_cur_slice;
1257
663k
    UWORD8 u1_first_byte, u1_nal_ref_idc;
1258
663k
    UWORD8 u1_nal_unit_type;
1259
663k
    WORD32 i_status = OK;
1260
663k
    ps_bitstrm = ps_dec->ps_bitstrm;
1261
1262
663k
    if(pu1_buf)
1263
663k
    {
1264
663k
        if(u4_length)
1265
663k
        {
1266
663k
            ps_dec_op->u4_frame_decoded_flag = 0;
1267
663k
            ih264d_process_nal_unit(ps_dec->ps_bitstrm, pu1_buf,
1268
663k
                                    u4_length);
1269
1270
663k
            SWITCHOFFTRACE;
1271
663k
            u1_first_byte = ih264d_get_bits_h264(ps_bitstrm, 8);
1272
1273
663k
            if(NAL_FORBIDDEN_BIT(u1_first_byte))
1274
64.7k
            {
1275
64.7k
                H264_DEC_DEBUG_PRINT("\nForbidden bit set in Nal Unit, Let's try\n");
1276
64.7k
            }
1277
663k
            u1_nal_unit_type = NAL_UNIT_TYPE(u1_first_byte);
1278
            // if any other nal unit other than slice nal is encountered in between a
1279
            // frame break out of loop without consuming header
1280
663k
            if ((ps_dec->u4_slice_start_code_found == 1)
1281
34.7k
                    && (ps_dec->u1_pic_decode_done != 1)
1282
28.1k
                    && (u1_nal_unit_type > IDR_SLICE_NAL))
1283
4.47k
            {
1284
4.47k
                return ERROR_INCOMPLETE_FRAME;
1285
4.47k
            }
1286
659k
            ps_dec->u1_nal_unit_type = u1_nal_unit_type;
1287
659k
            u1_nal_ref_idc = (UWORD8)(NAL_REF_IDC(u1_first_byte));
1288
            //Skip all NALUs if SPS and PPS are not decoded
1289
659k
            switch(u1_nal_unit_type)
1290
659k
            {
1291
165
                case SLICE_DATA_PARTITION_A_NAL:
1292
207
                case SLICE_DATA_PARTITION_B_NAL:
1293
258
                case SLICE_DATA_PARTITION_C_NAL:
1294
258
                    if(!ps_dec->i4_decode_header)
1295
154
                        ih264d_parse_slice_partition(ps_dec, ps_bitstrm);
1296
1297
258
                    break;
1298
1299
11.8k
                case IDR_SLICE_NAL:
1300
49.4k
                case SLICE_NAL:
1301
1302
                    /* ! */
1303
49.4k
                    DEBUG_THREADS_PRINTF("Decoding  a slice NAL\n");
1304
49.4k
                    if(!ps_dec->i4_decode_header)
1305
35.9k
                    {
1306
35.9k
                        if(ps_dec->i4_header_decoded == 3)
1307
28.5k
                        {
1308
28.5k
                            ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
1309
                            /* ! */
1310
28.5k
                            ps_dec->u4_slice_start_code_found = 1;
1311
1312
28.5k
                            ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1313
1314
28.5k
                            i_status = ih264d_parse_decode_slice(
1315
28.5k
                                            (UWORD8)(u1_nal_unit_type
1316
28.5k
                                                            == IDR_SLICE_NAL),
1317
28.5k
                                            u1_nal_ref_idc, ps_dec);
1318
1319
28.5k
                            if(i_status != OK)
1320
20.3k
                            {
1321
20.3k
                                return i_status;
1322
20.3k
                            }
1323
28.5k
                        }
1324
7.31k
                        else
1325
7.31k
                        {
1326
7.31k
                            H264_DEC_DEBUG_PRINT(
1327
7.31k
                                            "\nSlice NAL Supplied but no header has been supplied\n");
1328
7.31k
                        }
1329
35.9k
                    }
1330
29.1k
                    break;
1331
1332
29.1k
                case SEI_NAL:
1333
16.0k
                    if(!ps_dec->i4_decode_header)
1334
10.1k
                    {
1335
10.1k
                        ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1336
10.1k
                        i_status = ih264d_parse_sei_message(ps_dec, ps_bitstrm);
1337
10.1k
                        if(i_status != OK)
1338
6.43k
                            return i_status;
1339
3.75k
                        ih264d_parse_sei(ps_dec, ps_bitstrm);
1340
3.75k
                    }
1341
9.61k
                    break;
1342
52.3k
                case SEQ_PARAM_NAL:
1343
                    /* ! */
1344
52.3k
                    ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1345
52.3k
                    i_status = ih264d_parse_sps(ps_dec, ps_bitstrm);
1346
52.3k
                    ps_dec->u4_sps_cnt_in_process++;
1347
                    /*If a resolution change happens within a process call, due to multiple sps
1348
                     * we will not support it.
1349
                     */
1350
52.3k
                    if((ps_dec->u4_sps_cnt_in_process > 1 ) &&
1351
11.7k
                                    (i_status == IVD_RES_CHANGED))
1352
2.11k
                    {
1353
2.11k
                        i_status = ERROR_INV_SPS_PPS_T;
1354
2.11k
                        ps_dec->u1_res_changed = 0;
1355
2.11k
                    }
1356
52.3k
                    if(i_status == ERROR_INV_SPS_PPS_T)
1357
3.68k
                        return i_status;
1358
48.6k
                    if(!i_status)
1359
45.1k
                        ps_dec->i4_header_decoded |= 0x1;
1360
48.6k
                    break;
1361
1362
44.7k
                case PIC_PARAM_NAL:
1363
                    /* ! */
1364
44.7k
                    ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1365
44.7k
                    i_status = ih264d_parse_pps(ps_dec, ps_bitstrm);
1366
44.7k
                    if(i_status == ERROR_INV_SPS_PPS_T)
1367
1.36k
                        return i_status;
1368
43.3k
                    if(!i_status)
1369
40.7k
                        ps_dec->i4_header_decoded |= 0x2;
1370
43.3k
                    break;
1371
17.4k
                case ACCESS_UNIT_DELIMITER_RBSP:
1372
17.4k
                    if(!ps_dec->i4_decode_header)
1373
11.7k
                    {
1374
11.7k
                        ih264d_access_unit_delimiter_rbsp(ps_dec);
1375
11.7k
                    }
1376
17.4k
                    break;
1377
                    //Let us ignore the END_OF_SEQ_RBSP NAL and decode even after this NAL
1378
292
                case END_OF_STREAM_RBSP:
1379
292
                    if(!ps_dec->i4_decode_header)
1380
231
                    {
1381
231
                        ih264d_parse_end_of_stream(ps_dec);
1382
231
                    }
1383
292
                    break;
1384
175
                case FILLER_DATA_NAL:
1385
175
                    if(!ps_dec->i4_decode_header)
1386
136
                    {
1387
136
                        ih264d_parse_filler_data(ps_dec, ps_bitstrm);
1388
136
                    }
1389
175
                    break;
1390
478k
                default:
1391
478k
                    H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1392
478k
                    break;
1393
659k
            }
1394
1395
659k
        }
1396
1397
663k
    }
1398
1399
627k
    return i_status;
1400
1401
663k
}