Coverage Report

Created: 2023-11-19 06:32

/src/libavc/decoder/ih264d_parse_headers.c
Line
Count
Source (jump to first uncovered line)
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
213k
{
87
213k
    if((NULL != ps_dec->ps_sei) &&
88
213k
        ((0 == ps_dec->ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag) &&
89
213k
        (0 == ps_dec->ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag)))
90
213k
    {
91
213k
        ps_dec->ps_sei->u1_sei_ccv_params_present_flag = 0;
92
213k
        memset(&ps_dec->ps_sei->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
93
213k
    }
94
95
213k
    if((NULL != ps_dec->ps_cur_sps) &&
96
213k
        ((1 == ps_dec->ps_cur_sps->u1_vui_parameters_present_flag) &&
97
204k
        ((2 != ps_dec->ps_cur_sps->s_vui.u1_colour_primaries) &&
98
40.6k
        (2 != ps_dec->ps_cur_sps->s_vui.u1_matrix_coeffs) &&
99
40.6k
        (2 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars) &&
100
40.6k
        (4 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars) &&
101
40.6k
        (5 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars))))
102
3.00k
    {
103
3.00k
        if((1 == ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag) ||
104
3.00k
            (IDR_SLICE_NAL == u1_nal_unit_type))
105
1.62k
        {
106
1.62k
            ps_dec->ps_sei->u1_sei_ccv_params_present_flag =
107
1.62k
                        ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag;
108
1.62k
            ps_dec->ps_sei->s_sei_ccv_params = ps_dec->ps_sei_parse->s_sei_ccv_params;
109
1.62k
        }
110
3.00k
    }
111
210k
    else
112
210k
    {
113
210k
        ps_dec->ps_sei->u1_sei_ccv_params_present_flag = 0;
114
210k
        memset(&ps_dec->ps_sei->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
115
210k
    }
116
117
213k
    if(IDR_SLICE_NAL == u1_nal_unit_type)
118
132k
    {
119
132k
        ps_dec->ps_sei->u1_sei_mdcv_params_present_flag =
120
132k
                        ps_dec->ps_sei_parse->u1_sei_mdcv_params_present_flag;
121
132k
        ps_dec->ps_sei->s_sei_mdcv_params = ps_dec->ps_sei_parse->s_sei_mdcv_params;
122
132k
        ps_dec->ps_sei->u1_sei_cll_params_present_flag =
123
132k
                        ps_dec->ps_sei_parse->u1_sei_cll_params_present_flag;
124
132k
        ps_dec->ps_sei->s_sei_cll_params = ps_dec->ps_sei_parse->s_sei_cll_params;
125
132k
        ps_dec->ps_sei->u1_sei_ave_params_present_flag =
126
132k
                        ps_dec->ps_sei_parse->u1_sei_ave_params_present_flag;
127
132k
        ps_dec->ps_sei->s_sei_ave_params = ps_dec->ps_sei_parse->s_sei_ave_params;
128
132k
        ps_dec->ps_sei->u1_sei_sii_params_present_flag =
129
132k
            ps_dec->ps_sei_parse->u1_sei_sii_params_present_flag;
130
132k
        ps_dec->ps_sei->s_sei_sii_params = ps_dec->ps_sei_parse->s_sei_sii_params;
131
132k
    }
132
133
213k
    if(NULL != ps_dec->ps_sei)
134
213k
    {
135
213k
        ps_dec->ps_sei->u1_sei_fgc_params_present_flag =
136
213k
            ps_dec->ps_sei_parse->u1_sei_fgc_params_present_flag;
137
213k
        ps_dec->ps_sei->s_sei_fgc_params = ps_dec->ps_sei_parse->s_sei_fgc_params;
138
213k
    }
139
140
213k
    ps_dec->ps_sei_parse->u1_sei_mdcv_params_present_flag = 0;
141
213k
    memset(&ps_dec->ps_sei_parse->s_sei_mdcv_params, 0, sizeof(sei_mdcv_params_t));
142
213k
    ps_dec->ps_sei_parse->u1_sei_cll_params_present_flag = 0;
143
213k
    memset(&ps_dec->ps_sei_parse->s_sei_cll_params, 0, sizeof(sei_cll_params_t));
144
213k
    ps_dec->ps_sei_parse->u1_sei_ave_params_present_flag = 0;
145
213k
    memset(&ps_dec->ps_sei_parse->s_sei_ave_params, 0, sizeof(sei_ave_params_t));
146
213k
    ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag = 0;
147
213k
    memset(&ps_dec->ps_sei_parse->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
148
213k
    ps_dec->ps_sei_parse->u1_sei_sii_params_present_flag = 0;
149
213k
    memset(&ps_dec->ps_sei_parse->s_sei_sii_params, 0, sizeof(sei_sii_params_t));
150
213k
}
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
179
{
178
179
    H264_DEC_DEBUG_PRINT("\nSlice partition not supported");
179
179
    UNUSED(ps_dec);
180
179
    UNUSED(ps_bitstrm);
181
179
    return (0);
182
179
}
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
113k
{
208
113k
    UNUSED(ps_dec);
209
113k
    UNUSED(ps_bitstrm);
210
113k
    return (0);
211
113k
}
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
265
{
238
265
    UNUSED(ps_dec);
239
265
    UNUSED(ps_bitstrm);
240
265
    return (0);
241
265
}
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
148
{
266
148
    UNUSED(ps_dec);
267
148
    return;
268
148
}
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
40.6k
{
283
40.6k
    UWORD8 uc_temp;
284
40.6k
    dec_seq_params_t * ps_sps = NULL;
285
40.6k
    dec_pic_params_t * ps_pps = NULL;
286
40.6k
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
287
40.6k
    UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
288
289
    /* Variables used for error resilience checks */
290
40.6k
    UWORD64 u8_temp;
291
40.6k
    UWORD32 u4_temp;
292
40.6k
    WORD32 i_temp;
293
294
    /* For High profile related syntax elements */
295
40.6k
    UWORD8 u1_more_data_flag;
296
40.6k
    WORD32 i4_i;
297
298
40.6k
    if(!(ps_dec->i4_header_decoded & 1))
299
520
        return ERROR_INV_SPS_PPS_T;
300
301
    /*--------------------------------------------------------------------*/
302
    /* Decode pic_parameter_set_id and find corresponding pic params      */
303
    /*--------------------------------------------------------------------*/
304
40.1k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
305
40.1k
    if(u4_temp & MASK_ERR_PIC_SET_ID)
306
397
        return ERROR_INV_SPS_PPS_T;
307
39.7k
    ps_pps = ps_dec->pv_scratch_sps_pps;
308
39.7k
    *ps_pps = ps_dec->ps_pps[u4_temp];
309
39.7k
    ps_pps->u1_pic_parameter_set_id = (WORD8)u4_temp;
310
39.7k
    COPYTHECONTEXT("PPS: pic_parameter_set_id",ps_pps->u1_pic_parameter_set_id);
311
312
    /************************************************/
313
    /* initilization of High profile syntax element */
314
    /************************************************/
315
39.7k
    ps_pps->i4_transform_8x8_mode_flag = 0;
316
39.7k
    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
39.7k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
322
39.7k
    if(u4_temp & MASK_ERR_SEQ_SET_ID)
323
64
        return ERROR_INV_SPS_PPS_T;
324
39.6k
    COPYTHECONTEXT("PPS: seq_parameter_set_id",u4_temp);
325
39.6k
    ps_sps = &ps_dec->ps_sps[u4_temp];
326
327
39.6k
    if(FALSE == ps_sps->u1_is_valid)
328
109
        return ERROR_INV_SPS_PPS_T;
329
39.5k
    ps_pps->ps_sps = ps_sps;
330
331
    /*--------------------------------------------------------------------*/
332
    /* Decode entropy_coding_mode                                         */
333
    /*--------------------------------------------------------------------*/
334
39.5k
    ps_pps->u1_entropy_coding_mode = ih264d_get_bit_h264(ps_bitstrm);
335
39.5k
    COPYTHECONTEXT("PPS: entropy_coding_mode_flag",ps_pps->u1_entropy_coding_mode);
336
337
39.5k
    ps_pps->u1_pic_order_present_flag = ih264d_get_bit_h264(ps_bitstrm);
338
39.5k
    COPYTHECONTEXT("PPS: pic_order_present_flag",ps_pps->u1_pic_order_present_flag);
339
340
    /*--------------------------------------------------------------------*/
341
    /* Decode num_slice_groups_minus1                                     */
342
    /*--------------------------------------------------------------------*/
343
39.5k
    u8_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + (UWORD64)1;
344
39.5k
    if(u8_temp != 1)
345
93
    {
346
93
        return ERROR_FEATURE_UNAVAIL;
347
93
    }
348
39.4k
    ps_pps->u1_num_slice_groups = u8_temp;
349
39.4k
    COPYTHECONTEXT("PPS: num_slice_groups_minus1",ps_pps->u1_num_slice_groups -1);
350
351
    /*--------------------------------------------------------------------*/
352
    /* Other parameter set values                                         */
353
    /*--------------------------------------------------------------------*/
354
39.4k
    u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
355
39.4k
    if(u8_temp > H264_MAX_REF_IDX)
356
54
        return ERROR_REF_IDX;
357
39.3k
    ps_pps->u1_num_ref_idx_lx_active[0] = u8_temp;
358
39.3k
    COPYTHECONTEXT("PPS: num_ref_idx_l0_active_minus1",
359
39.3k
                    ps_pps->u1_num_ref_idx_lx_active[0] - 1);
360
361
39.3k
    u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
362
39.3k
    if(u8_temp > H264_MAX_REF_IDX)
363
63
        return ERROR_REF_IDX;
364
39.3k
    ps_pps->u1_num_ref_idx_lx_active[1] = u8_temp;
365
39.3k
    COPYTHECONTEXT("PPS: num_ref_idx_l1_active_minus1",
366
39.3k
                    ps_pps->u1_num_ref_idx_lx_active[1] - 1);
367
368
39.3k
    ps_pps->u1_wted_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
369
39.3k
    COPYTHECONTEXT("PPS: weighted prediction u4_flag",ps_pps->u1_wted_pred_flag);
370
39.3k
    uc_temp = ih264d_get_bits_h264(ps_bitstrm, 2);
371
39.3k
    COPYTHECONTEXT("PPS: weighted_bipred_idc",uc_temp);
372
39.3k
    ps_pps->u1_wted_bipred_idc = uc_temp;
373
374
39.3k
    if(ps_pps->u1_wted_bipred_idc > MAX_WEIGHT_BIPRED_IDC)
375
124
        return ERROR_INV_SPS_PPS_T;
376
39.2k
    {
377
39.2k
        WORD64 i8_temp;
378
39.2k
        i8_temp = (WORD64)26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
379
380
39.2k
        if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
381
220
            return ERROR_INV_RANGE_QP_T;
382
383
38.9k
        ps_pps->u1_pic_init_qp = i8_temp;
384
38.9k
        COPYTHECONTEXT("PPS: pic_init_qp_minus26",ps_pps->u1_pic_init_qp - 26);
385
386
38.9k
        i8_temp = (WORD64)26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
387
388
38.9k
        if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
389
86
            return ERROR_INV_RANGE_QP_T;
390
391
38.8k
        ps_pps->u1_pic_init_qs = i8_temp;
392
38.8k
        COPYTHECONTEXT("PPS: pic_init_qs_minus26",ps_pps->u1_pic_init_qs - 26);
393
38.8k
    }
394
395
0
    i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
396
38.8k
    if((i_temp < -12) || (i_temp > 12))
397
514
        return ERROR_INV_RANGE_QP_T;
398
38.3k
    ps_pps->i1_chroma_qp_index_offset = i_temp;
399
38.3k
    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
38.3k
    ps_pps->i1_second_chroma_qp_index_offset =
406
38.3k
                    ps_pps->i1_chroma_qp_index_offset;
407
408
38.3k
    ps_pps->u1_deblocking_filter_parameters_present_flag = ih264d_get_bit_h264(
409
38.3k
                    ps_bitstrm);
410
38.3k
    COPYTHECONTEXT("PPS: deblocking_filter_control_present_flag",
411
38.3k
                    ps_pps->u1_deblocking_filter_parameters_present_flag);
412
38.3k
    ps_pps->u1_constrained_intra_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
413
38.3k
    COPYTHECONTEXT("PPS: constrained_intra_pred_flag",
414
38.3k
                    ps_pps->u1_constrained_intra_pred_flag);
415
38.3k
    ps_pps->u1_redundant_pic_cnt_present_flag = ih264d_get_bit_h264(ps_bitstrm);
416
38.3k
    COPYTHECONTEXT("PPS: redundant_pic_cnt_present_flag",
417
38.3k
                    ps_pps->u1_redundant_pic_cnt_present_flag);
418
419
    /* High profile related syntax elements */
420
38.3k
    u1_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
421
38.3k
    if(u1_more_data_flag && (ps_pps->ps_sps->u1_profile_idc == HIGH_PROFILE_IDC))
422
7.25k
    {
423
        /* read transform_8x8_mode_flag  */
424
7.25k
        ps_pps->i4_transform_8x8_mode_flag = (WORD32)ih264d_get_bit_h264(
425
7.25k
                        ps_bitstrm);
426
427
        /* read pic_scaling_matrix_present_flag */
428
7.25k
        ps_pps->i4_pic_scaling_matrix_present_flag =
429
7.25k
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
430
431
7.25k
        if(ps_pps->i4_pic_scaling_matrix_present_flag)
432
2.00k
        {
433
            /* read the scaling matrices */
434
15.7k
            for(i4_i = 0; i4_i < (6 + (ps_pps->i4_transform_8x8_mode_flag << 1)); i4_i++)
435
13.9k
            {
436
13.9k
                ps_pps->u1_pic_scaling_list_present_flag[i4_i] =
437
13.9k
                                ih264d_get_bit_h264(ps_bitstrm);
438
439
13.9k
                if(ps_pps->u1_pic_scaling_list_present_flag[i4_i])
440
3.29k
                {
441
3.29k
                    WORD32 ret;
442
3.29k
                    if(i4_i < 6)
443
2.23k
                    {
444
2.23k
                        ret = ih264d_scaling_list(
445
2.23k
                                        ps_pps->i2_pic_scalinglist4x4[i4_i],
446
2.23k
                                        16,
447
2.23k
                                        &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
448
2.23k
                                        ps_bitstrm);
449
2.23k
                    }
450
1.05k
                    else
451
1.05k
                    {
452
1.05k
                        ret = ih264d_scaling_list(
453
1.05k
                                        ps_pps->i2_pic_scalinglist8x8[i4_i - 6],
454
1.05k
                                        64,
455
1.05k
                                        &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
456
1.05k
                                        ps_bitstrm);
457
1.05k
                    }
458
459
3.29k
                    if(ret != OK)
460
274
                    {
461
274
                        return ret;
462
274
                    }
463
3.29k
                }
464
13.9k
            }
465
2.00k
        }
466
467
        /* read second_chroma_qp_index_offset syntax element */
468
6.98k
        i_temp = ih264d_sev(
469
6.98k
                        pu4_bitstrm_ofst, pu4_bitstrm_buf);
470
471
6.98k
        if((i_temp < -12) || (i_temp > 12))
472
128
            return ERROR_INV_RANGE_QP_T;
473
474
6.85k
        ps_pps->i1_second_chroma_qp_index_offset = i_temp;
475
6.85k
    }
476
477
    /* In case bitstream read has exceeded the filled size, then
478
       return an error */
479
37.9k
    if(EXCEED_OFFSET(ps_bitstrm))
480
93
    {
481
93
        return ERROR_INV_SPS_PPS_T;
482
93
    }
483
37.8k
    ps_pps->u1_is_valid = TRUE;
484
37.8k
    ps_dec->ps_pps[ps_pps->u1_pic_parameter_set_id] = *ps_pps;
485
37.8k
    return OK;
486
37.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
530k
{
501
530k
    UWORD32 u4_max_mbs_allowed;
502
503
530k
    switch(u4_level_idc)
504
530k
    {
505
6.03k
        case H264_LEVEL_1_0:
506
6.03k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_10;
507
6.03k
            break;
508
22.4k
        case H264_LEVEL_1_1:
509
22.4k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_11;
510
22.4k
            break;
511
1.75k
        case H264_LEVEL_1_2:
512
1.75k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_12;
513
1.75k
            break;
514
2.62k
        case H264_LEVEL_1_3:
515
2.62k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_13;
516
2.62k
            break;
517
34.9k
        case H264_LEVEL_2_0:
518
34.9k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_20;
519
34.9k
            break;
520
1.21k
        case H264_LEVEL_2_1:
521
1.21k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_21;
522
1.21k
            break;
523
6.35k
        case H264_LEVEL_2_2:
524
6.35k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_22;
525
6.35k
            break;
526
1.60k
        case H264_LEVEL_3_0:
527
1.60k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_30;
528
1.60k
            break;
529
4.98k
        case H264_LEVEL_3_1:
530
4.98k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_31;
531
4.98k
            break;
532
7.52k
        case H264_LEVEL_3_2:
533
7.52k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_32;
534
7.52k
            break;
535
5.10k
        case H264_LEVEL_4_0:
536
5.10k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_40;
537
5.10k
            break;
538
1.79k
        case H264_LEVEL_4_1:
539
1.79k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_41;
540
1.79k
            break;
541
1.33k
        case H264_LEVEL_4_2:
542
1.33k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_42;
543
1.33k
            break;
544
580
        case H264_LEVEL_5_0:
545
580
            u4_max_mbs_allowed = MAX_MBS_LEVEL_50;
546
580
            break;
547
1.05k
        case H264_LEVEL_5_1:
548
432k
        default:
549
432k
            u4_max_mbs_allowed = MAX_MBS_LEVEL_51;
550
432k
            break;
551
552
530k
    }
553
554
    /*correct of the level is incorrect*/
555
530k
    if(u4_total_mbs > u4_max_mbs_allowed)
556
6.98k
    {
557
6.98k
        if(u4_total_mbs > MAX_MBS_LEVEL_50)
558
551
            u4_level_idc = H264_LEVEL_5_1;
559
6.43k
        else if(u4_total_mbs > MAX_MBS_LEVEL_42)
560
477
            u4_level_idc = H264_LEVEL_5_0;
561
5.95k
        else if(u4_total_mbs > MAX_MBS_LEVEL_41)
562
804
            u4_level_idc = H264_LEVEL_4_2;
563
5.15k
        else if(u4_total_mbs > MAX_MBS_LEVEL_40)
564
0
            u4_level_idc = H264_LEVEL_4_1;
565
5.15k
        else if(u4_total_mbs > MAX_MBS_LEVEL_32)
566
2.69k
            u4_level_idc = H264_LEVEL_4_0;
567
2.45k
        else if(u4_total_mbs > MAX_MBS_LEVEL_31)
568
86
            u4_level_idc = H264_LEVEL_3_2;
569
2.37k
        else if(u4_total_mbs > MAX_MBS_LEVEL_30)
570
272
            u4_level_idc = H264_LEVEL_3_1;
571
2.09k
        else if(u4_total_mbs > MAX_MBS_LEVEL_21)
572
340
            u4_level_idc = H264_LEVEL_3_0;
573
1.75k
        else if(u4_total_mbs > MAX_MBS_LEVEL_20)
574
1.52k
            u4_level_idc = H264_LEVEL_2_1;
575
233
        else if(u4_total_mbs > MAX_MBS_LEVEL_10)
576
233
            u4_level_idc = H264_LEVEL_2_0;
577
6.98k
    }
578
579
530k
    return (u4_level_idc);
580
581
530k
}
582
WORD32 ih264d_parse_sps(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm)
583
414k
{
584
414k
    UWORD8 i;
585
414k
    dec_seq_params_t *ps_seq = NULL;
586
414k
    UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
587
414k
    UWORD16 i2_max_frm_num;
588
414k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
589
414k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
590
414k
    UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag;
591
414k
    WORD32 i4_cropped_ht, i4_cropped_wd;
592
414k
    UWORD32 u4_temp;
593
414k
    UWORD64 u8_temp;
594
414k
    UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
595
414k
    UWORD32 u2_pic_wd = 0;
596
414k
    UWORD32 u2_pic_ht = 0;
597
414k
    UWORD32 u2_frm_wd_y = 0;
598
414k
    UWORD32 u2_frm_ht_y = 0;
599
414k
    UWORD32 u2_frm_wd_uv = 0;
600
414k
    UWORD32 u2_frm_ht_uv = 0;
601
414k
    UWORD32 u2_crop_offset_y = 0;
602
414k
    UWORD32 u2_crop_offset_uv = 0;
603
414k
    WORD32 ret;
604
414k
    WORD32 num_reorder_frames;
605
    /* High profile related syntax element */
606
414k
    WORD32 i4_i;
607
    /* G050 */
608
414k
    UWORD8 u1_frame_cropping_flag, u1_frame_cropping_rect_left_ofst,
609
414k
                    u1_frame_cropping_rect_right_ofst,
610
414k
                    u1_frame_cropping_rect_top_ofst,
611
414k
                    u1_frame_cropping_rect_bottom_ofst;
612
    /* G050 */
613
    /*--------------------------------------------------------------------*/
614
    /* Decode seq_parameter_set_id and profile and level values           */
615
    /*--------------------------------------------------------------------*/
616
414k
    SWITCHONTRACE;
617
414k
    u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
618
414k
    COPYTHECONTEXT("SPS: profile_idc",u1_profile_idc);
619
620
    /* G050 */
621
414k
    uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
622
414k
    uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
623
414k
    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
414k
    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
414k
    if((u1_profile_idc != MAIN_PROFILE_IDC) &&
635
636
414k
    (u1_profile_idc != BASE_PROFILE_IDC) &&
637
638
414k
    (u1_profile_idc != HIGH_PROFILE_IDC)
639
640
414k
    )
641
342k
    {
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
342k
        if((u1_profile_idc != EXTENDED_PROFILE_IDC) ||
648
342k
           ((uc_constraint_set1_flag != 1) && (uc_constraint_set0_flag != 1)))
649
404
        {
650
404
            return (ERROR_FEATURE_UNAVAIL);
651
404
        }
652
342k
    }
653
654
414k
    u1_level_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
655
656
657
658
414k
    COPYTHECONTEXT("SPS: u4_level_idc",u1_level_idc);
659
660
414k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
661
414k
    if(u4_temp & MASK_ERR_SEQ_SET_ID)
662
462
        return ERROR_INV_SPS_PPS_T;
663
413k
    u1_seq_parameter_set_id = u4_temp;
664
413k
    COPYTHECONTEXT("SPS: seq_parameter_set_id",
665
413k
                    u1_seq_parameter_set_id);
666
667
    /*--------------------------------------------------------------------*/
668
    /* Find an seq param entry in seqparam array of decStruct             */
669
    /*--------------------------------------------------------------------*/
670
671
413k
    ps_seq = ps_dec->pv_scratch_sps_pps;
672
413k
    memset(ps_seq, 0, sizeof(dec_seq_params_t));
673
674
413k
    if(ps_dec->i4_header_decoded & 1)
675
393k
    {
676
393k
        *ps_seq = *ps_dec->ps_cur_sps;
677
393k
    }
678
679
680
413k
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_profile_idc != u1_profile_idc))
681
455
    {
682
455
        ps_dec->u1_res_changed = 1;
683
455
        return IVD_RES_CHANGED;
684
455
    }
685
686
413k
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_level_idc != u1_level_idc))
687
862
    {
688
862
        ps_dec->u1_res_changed = 1;
689
862
        return IVD_RES_CHANGED;
690
862
    }
691
692
412k
    ps_seq->u1_profile_idc = u1_profile_idc;
693
412k
    ps_seq->u1_level_idc = u1_level_idc;
694
412k
    ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
695
696
    /*******************************************************************/
697
    /* Initializations for high profile - Sushant                      */
698
    /*******************************************************************/
699
412k
    ps_seq->i4_chroma_format_idc = 1;
700
412k
    ps_seq->i4_bit_depth_luma_minus8 = 0;
701
412k
    ps_seq->i4_bit_depth_chroma_minus8 = 0;
702
412k
    ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
703
412k
    ps_seq->i4_seq_scaling_matrix_present_flag = 0;
704
412k
    if(u1_profile_idc == HIGH_PROFILE_IDC)
705
9.60k
    {
706
707
        /* reading chroma_format_idc   */
708
9.60k
        ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst,
709
9.60k
                                                  pu4_bitstrm_buf);
710
711
        /* Monochrome is not supported */
712
9.60k
        if(ps_seq->i4_chroma_format_idc != 1)
713
111
        {
714
111
            return ERROR_FEATURE_UNAVAIL;
715
111
        }
716
717
        /* reading bit_depth_luma_minus8   */
718
9.49k
        ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst,
719
9.49k
                                                      pu4_bitstrm_buf);
720
721
9.49k
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
722
67
        {
723
67
            return ERROR_FEATURE_UNAVAIL;
724
67
        }
725
726
        /* reading bit_depth_chroma_minus8   */
727
9.42k
        ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst,
728
9.42k
                                                        pu4_bitstrm_buf);
729
730
9.42k
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
731
59
        {
732
59
            return ERROR_FEATURE_UNAVAIL;
733
59
        }
734
735
        /* reading qpprime_y_zero_transform_bypass_flag   */
736
9.36k
        ps_seq->i4_qpprime_y_zero_transform_bypass_flag =
737
9.36k
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
738
739
9.36k
        if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
740
13
        {
741
13
            return ERROR_INV_SPS_PPS_T;
742
13
        }
743
744
        /* reading seq_scaling_matrix_present_flag   */
745
9.35k
        ps_seq->i4_seq_scaling_matrix_present_flag =
746
9.35k
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
747
748
9.35k
        if(ps_seq->i4_seq_scaling_matrix_present_flag)
749
1.00k
        {
750
8.57k
            for(i4_i = 0; i4_i < 8; i4_i++)
751
7.66k
            {
752
7.66k
                ps_seq->u1_seq_scaling_list_present_flag[i4_i] =
753
7.66k
                                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
7.66k
                ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
758
759
7.66k
                if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
760
2.18k
                {
761
2.18k
                    if(i4_i < 6)
762
1.46k
                    {
763
1.46k
                        ret = ih264d_scaling_list(
764
1.46k
                                        ps_seq->i2_scalinglist4x4[i4_i],
765
1.46k
                                        16,
766
1.46k
                                        &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
767
1.46k
                                        ps_bitstrm);
768
1.46k
                    }
769
719
                    else
770
719
                    {
771
719
                        ret = ih264d_scaling_list(
772
719
                                        ps_seq->i2_scalinglist8x8[i4_i - 6],
773
719
                                        64,
774
719
                                        &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
775
719
                                        ps_bitstrm);
776
719
                    }
777
2.18k
                    if(ret != OK)
778
100
                    {
779
100
                        return ret;
780
100
                    }
781
2.18k
                }
782
7.66k
            }
783
1.00k
        }
784
9.35k
    }
785
    /*--------------------------------------------------------------------*/
786
    /* Decode MaxFrameNum                                                 */
787
    /*--------------------------------------------------------------------*/
788
411k
    u8_temp = (UWORD64)4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
789
411k
    if(u8_temp > MAX_BITS_IN_FRAME_NUM)
790
69
    {
791
69
        return ERROR_INV_SPS_PPS_T;
792
69
    }
793
411k
    ps_seq->u1_bits_in_frm_num = u8_temp;
794
411k
    COPYTHECONTEXT("SPS: log2_max_frame_num_minus4",
795
411k
                    (ps_seq->u1_bits_in_frm_num - 4));
796
797
411k
    i2_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
798
411k
    ps_seq->u2_u4_max_pic_num_minus1 = i2_max_frm_num - 1;
799
    /*--------------------------------------------------------------------*/
800
    /* Decode picture order count and related values                      */
801
    /*--------------------------------------------------------------------*/
802
411k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
803
804
411k
    if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
805
1.90k
    {
806
1.90k
        return ERROR_INV_POC_TYPE_T;
807
1.90k
    }
808
409k
    ps_seq->u1_pic_order_cnt_type = u4_temp;
809
409k
    COPYTHECONTEXT("SPS: pic_order_cnt_type",ps_seq->u1_pic_order_cnt_type);
810
811
409k
    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
812
409k
    if(ps_seq->u1_pic_order_cnt_type == 0)
813
370k
    {
814
370k
        u8_temp = (UWORD64)4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
815
370k
        if(u8_temp > MAX_BITS_IN_POC_LSB)
816
52
        {
817
52
            return ERROR_INV_SPS_PPS_T;
818
52
        }
819
370k
        ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = u8_temp;
820
370k
        ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
821
370k
        COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4",(u8_temp - 4));
822
370k
    }
823
39.5k
    else if(ps_seq->u1_pic_order_cnt_type == 1)
824
8.48k
    {
825
8.48k
        ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(
826
8.48k
                        ps_bitstrm);
827
8.48k
        COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
828
8.48k
                        ps_seq->u1_delta_pic_order_always_zero_flag);
829
830
8.48k
        ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst,
831
8.48k
                                                     pu4_bitstrm_buf);
832
8.48k
        COPYTHECONTEXT("SPS: offset_for_non_ref_pic",
833
8.48k
                        ps_seq->i4_ofst_for_non_ref_pic);
834
835
8.48k
        ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(
836
8.48k
                        pu4_bitstrm_ofst, pu4_bitstrm_buf);
837
8.48k
        COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
838
8.48k
                        ps_seq->i4_ofst_for_top_to_bottom_field);
839
840
8.48k
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
841
8.48k
        if(u4_temp > 255)
842
59
            return ERROR_INV_SPS_PPS_T;
843
8.42k
        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
844
8.42k
        COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
845
8.42k
                        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
846
847
27.7k
        for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
848
19.3k
        {
849
19.3k
            ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(
850
19.3k
                            pu4_bitstrm_ofst, pu4_bitstrm_buf);
851
19.3k
            COPYTHECONTEXT("SPS: offset_for_ref_frame",
852
19.3k
                            ps_seq->i4_ofst_for_ref_frame[i]);
853
19.3k
        }
854
8.42k
    }
855
856
409k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
857
858
409k
    if((u4_temp > H264_MAX_REF_PICS))
859
99
    {
860
99
        return ERROR_NUM_REF;
861
99
    }
862
863
    /* Compare with older num_ref_frames is header is already once */
864
409k
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_num_ref_frames != u4_temp))
865
158
    {
866
158
        ps_dec->u1_res_changed = 1;
867
158
        return IVD_RES_CHANGED;
868
158
    }
869
870
409k
    ps_seq->u1_num_ref_frames = u4_temp;
871
409k
    COPYTHECONTEXT("SPS: num_ref_frames",ps_seq->u1_num_ref_frames);
872
873
409k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(
874
409k
                    ps_bitstrm);
875
409k
    COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
876
409k
                    ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
877
878
    /*--------------------------------------------------------------------*/
879
    /* Decode FrameWidth and FrameHeight and related values               */
880
    /*--------------------------------------------------------------------*/
881
409k
    u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
882
    /* Check  for unsupported resolutions*/
883
409k
    if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
884
72
    {
885
72
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
886
72
    }
887
409k
    u4_pic_width_in_mbs = u8_temp;
888
409k
    COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1",
889
409k
                   u4_pic_width_in_mbs - 1);
890
891
409k
    u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
892
409k
    if (u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
893
111
    {
894
111
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
895
111
    }
896
409k
    u4_pic_height_in_map_units = u8_temp;
897
898
409k
    ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
899
409k
    ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
900
901
409k
    u2_pic_wd = (u4_pic_width_in_mbs << 4);
902
409k
    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
409k
    ps_seq->u2_max_mb_addr = (ps_seq->u2_frm_wd_in_mbs
907
409k
                    * ps_seq->u2_frm_ht_in_mbs) - 1;
908
909
409k
    ps_seq->u2_total_num_of_mbs = ps_seq->u2_max_mb_addr + 1;
910
911
409k
    ps_seq->u1_level_idc = ih264d_correct_level_idc(
912
409k
                    u1_level_idc, ps_seq->u2_total_num_of_mbs);
913
914
409k
    u1_frm = ih264d_get_bit_h264(ps_bitstrm);
915
409k
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_frame_mbs_only_flag != u1_frm))
916
88
    {
917
88
        ps_dec->u1_res_changed = 1;
918
88
        return IVD_RES_CHANGED;
919
88
    }
920
921
409k
    ps_seq->u1_frame_mbs_only_flag = u1_frm;
922
923
409k
    COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
924
925
409k
    if(!u1_frm)
926
9.81k
        u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
927
928
409k
    if((ps_dec->i4_header_decoded & 1)
929
409k
                    && (ps_seq->u1_mb_aff_flag != u1_mb_aff_flag))
930
7
    {
931
7
        ps_dec->u1_res_changed = 1;
932
7
        return IVD_RES_CHANGED;
933
7
    }
934
935
409k
    if(!u1_frm)
936
9.80k
    {
937
9.80k
        u2_pic_ht <<= 1;
938
9.80k
        ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
939
9.80k
        COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag",
940
9.80k
                        ps_seq->u1_mb_aff_flag);
941
942
9.80k
    }
943
399k
    else
944
399k
        ps_seq->u1_mb_aff_flag = 0;
945
946
409k
    ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
947
948
409k
    COPYTHECONTEXT("SPS: direct_8x8_inference_flag",
949
409k
                    ps_seq->u1_direct_8x8_inference_flag);
950
951
    /* G050 */
952
409k
    u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
953
409k
    COPYTHECONTEXT("SPS: frame_cropping_flag",u1_frame_cropping_flag);
954
955
409k
    if(u1_frame_cropping_flag)
956
347k
    {
957
347k
        u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst,
958
347k
                                                      pu4_bitstrm_buf);
959
347k
        COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset",
960
347k
                        u1_frame_cropping_rect_left_ofst);
961
347k
        u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst,
962
347k
                                                       pu4_bitstrm_buf);
963
347k
        COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset",
964
347k
                        u1_frame_cropping_rect_right_ofst);
965
347k
        u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst,
966
347k
                                                     pu4_bitstrm_buf);
967
347k
        COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset",
968
347k
                        u1_frame_cropping_rect_top_ofst);
969
347k
        u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst,
970
347k
                                                        pu4_bitstrm_buf);
971
347k
        COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
972
347k
                        u1_frame_cropping_rect_bottom_ofst);
973
347k
    }
974
    /* G050 */
975
976
409k
    ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
977
409k
    COPYTHECONTEXT("SPS: vui_parameters_present_flag",
978
409k
                    ps_seq->u1_vui_parameters_present_flag);
979
980
409k
    u2_frm_wd_y = u2_pic_wd + (UWORD8)(PAD_LEN_Y_H << 1);
981
409k
    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
409k
    u2_frm_ht_y = u2_pic_ht + (UWORD8)(PAD_LEN_Y_V << 2);
988
409k
    u2_frm_wd_uv = u2_pic_wd + (UWORD8)(PAD_LEN_UV_H << 2);
989
409k
    u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
990
991
409k
    u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8)(PAD_LEN_UV_V << 2);
992
409k
    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
409k
    {
998
409k
        UWORD16 u2_rgt_ofst = 0;
999
409k
        UWORD16 u2_lft_ofst = 0;
1000
409k
        UWORD16 u2_top_ofst = 0;
1001
409k
        UWORD16 u2_btm_ofst = 0;
1002
409k
        UWORD8 u1_frm_mbs_flag;
1003
409k
        UWORD8 u1_vert_mult_factor;
1004
1005
409k
        if(u1_frame_cropping_flag)
1006
347k
        {
1007
            /* Calculate right and left u4_ofst for cropped picture           */
1008
347k
            u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
1009
347k
            u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
1010
1011
            /* Know frame MBs only u4_flag                                      */
1012
347k
            u1_frm_mbs_flag = (1 == ps_seq->u1_frame_mbs_only_flag);
1013
1014
            /* Simplify the vertical u4_ofst calculation from field/frame     */
1015
347k
            u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
1016
1017
            /* Calculate bottom and top u4_ofst for cropped  picture          */
1018
347k
            u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst
1019
347k
                            << u1_vert_mult_factor);
1020
347k
            u2_top_ofst = (u1_frame_cropping_rect_top_ofst
1021
347k
                            << u1_vert_mult_factor);
1022
347k
        }
1023
1024
        /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
1025
        /* cropped picture buffer                                           */
1026
409k
        u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
1027
409k
        u2_crop_offset_uv = (u2_frm_wd_uv * (u2_top_ofst >> 1))
1028
409k
                        + (u2_lft_ofst >> 1) * YUV420SP_FACTOR;
1029
        /* Calculate the display picture width and height based on crop      */
1030
        /* information                                                       */
1031
409k
        i4_cropped_ht = (WORD32)u2_pic_ht - (WORD32)(u2_btm_ofst + u2_top_ofst);
1032
409k
        i4_cropped_wd = (WORD32)u2_pic_wd - (WORD32)(u2_rgt_ofst + u2_lft_ofst);
1033
1034
409k
        if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
1035
89
        {
1036
89
            return ERROR_INV_SPS_PPS_T;
1037
89
        }
1038
1039
409k
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_wd != u2_pic_wd))
1040
52
        {
1041
52
            ps_dec->u1_res_changed = 1;
1042
52
            return IVD_RES_CHANGED;
1043
52
        }
1044
1045
409k
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_disp_width != i4_cropped_wd))
1046
363
        {
1047
363
            ps_dec->u1_res_changed = 1;
1048
363
            return IVD_RES_CHANGED;
1049
363
        }
1050
1051
408k
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_ht != u2_pic_ht))
1052
250
        {
1053
250
            ps_dec->u1_res_changed = 1;
1054
250
            return IVD_RES_CHANGED;
1055
250
        }
1056
1057
408k
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_disp_height != i4_cropped_ht))
1058
12
        {
1059
12
            ps_dec->u1_res_changed = 1;
1060
12
            return IVD_RES_CHANGED;
1061
12
        }
1062
1063
        /* Check again for unsupported resolutions with updated values*/
1064
408k
        if((u2_pic_wd > H264_MAX_FRAME_WIDTH) || (u2_pic_ht > H264_MAX_FRAME_HEIGHT)
1065
408k
                || (u2_pic_wd < H264_MIN_FRAME_WIDTH) || (u2_pic_ht < H264_MIN_FRAME_HEIGHT)
1066
408k
                || (u2_pic_wd * (UWORD32)u2_pic_ht > H264_MAX_FRAME_SIZE))
1067
38
        {
1068
38
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1069
38
        }
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
408k
        if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
1076
8
        {
1077
8
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1078
8
        }
1079
1080
408k
    }
1081
1082
    /* Backup num_reorder_frames if header is already decoded */
1083
408k
    if((ps_dec->i4_header_decoded & 1) &&
1084
408k
                    (1 == ps_seq->u1_vui_parameters_present_flag) &&
1085
408k
                    (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1086
339k
    {
1087
339k
        num_reorder_frames =  (WORD32)ps_seq->s_vui.u4_num_reorder_frames;
1088
339k
    }
1089
68.7k
    else
1090
68.7k
    {
1091
68.7k
        num_reorder_frames = -1;
1092
68.7k
    }
1093
408k
    if(1 == ps_seq->u1_vui_parameters_present_flag)
1094
344k
    {
1095
344k
        ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
1096
344k
        if(ret != OK)
1097
149
            return ret;
1098
344k
    }
1099
1100
    /* Compare older num_reorder_frames with the new one if header is already decoded */
1101
408k
    if((ps_dec->i4_header_decoded & 1) &&
1102
408k
                    (-1 != num_reorder_frames) &&
1103
408k
                    (1 == ps_seq->u1_vui_parameters_present_flag) &&
1104
408k
                    (1 == ps_seq->s_vui.u1_bitstream_restriction_flag) &&
1105
408k
                    ((WORD32)ps_seq->s_vui.u4_num_reorder_frames != num_reorder_frames))
1106
136
    {
1107
136
        ps_dec->u1_res_changed = 1;
1108
136
        return IVD_RES_CHANGED;
1109
136
    }
1110
1111
    /* In case bitstream read has exceeded the filled size, then
1112
     return an error */
1113
408k
    if (EXCEED_OFFSET(ps_bitstrm))
1114
376
    {
1115
376
        return ERROR_INV_SPS_PPS_T;
1116
376
    }
1117
1118
    /*--------------------------------------------------------------------*/
1119
    /* All initializations to ps_dec are beyond this point                */
1120
    /*--------------------------------------------------------------------*/
1121
407k
    {
1122
407k
        WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
1123
407k
        if((1 == ps_seq->u1_vui_parameters_present_flag) &&
1124
407k
           (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1125
339k
        {
1126
339k
            reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
1127
339k
        }
1128
1129
407k
        if (reorder_depth > H264_MAX_REF_PICS)
1130
130
        {
1131
130
            return ERROR_INV_SPS_PPS_T;
1132
130
        }
1133
1134
407k
        if(ps_seq->u1_frame_mbs_only_flag != 1)
1135
9.30k
            reorder_depth *= 2;
1136
407k
        ps_dec->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
1137
407k
    }
1138
0
    ps_dec->u2_disp_height = i4_cropped_ht;
1139
407k
    ps_dec->u2_disp_width = i4_cropped_wd;
1140
1141
407k
    ps_dec->u2_pic_wd = u2_pic_wd;
1142
407k
    ps_dec->u2_pic_ht = u2_pic_ht;
1143
407k
    ps_dec->u4_total_mbs = ps_seq->u2_total_num_of_mbs << (1 - ps_seq->u1_frame_mbs_only_flag);
1144
1145
    /* Determining the Width and Height of Frame from that of Picture */
1146
407k
    ps_dec->u2_frm_wd_y = u2_frm_wd_y;
1147
407k
    ps_dec->u2_frm_ht_y = u2_frm_ht_y;
1148
1149
407k
    ps_dec->u2_frm_wd_uv = u2_frm_wd_uv;
1150
407k
    ps_dec->u2_frm_ht_uv = u2_frm_ht_uv;
1151
407k
    ps_dec->s_pad_mgr.u1_pad_len_y_v = (UWORD8)(PAD_LEN_Y_V << (1 - u1_frm));
1152
407k
    ps_dec->s_pad_mgr.u1_pad_len_cr_v = (UWORD8)(PAD_LEN_UV_V << (1 - u1_frm));
1153
1154
407k
    ps_dec->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs;
1155
407k
    ps_dec->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs;
1156
1157
407k
    ps_dec->u2_crop_offset_y = u2_crop_offset_y;
1158
407k
    ps_dec->u2_crop_offset_uv = u2_crop_offset_uv;
1159
1160
407k
    ps_seq->u1_is_valid = TRUE;
1161
407k
    ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
1162
407k
    ps_dec->ps_cur_sps = &ps_dec->ps_sps[u1_seq_parameter_set_id];
1163
1164
407k
    return OK;
1165
407k
}
1166
1167
/*!
1168
 **************************************************************************
1169
 * \if Function name : ih264d_parse_end_of_sequence \endif
1170
 *
1171
 * \brief
1172
 *    Decodes End of Sequence.
1173
 *
1174
 * \param ps_bitstrm   : Pointer to bit ps_bitstrm containing the NAL unit
1175
 *
1176
 * \return
1177
 *    0 on Success and error code otherwise
1178
 **************************************************************************
1179
 */
1180
WORD32 ih264d_parse_end_of_sequence(dec_struct_t * ps_dec)
1181
0
{
1182
0
    WORD32 ret;
1183
1184
0
    ret = ih264d_end_of_pic_processing(ps_dec);
1185
0
    return ret;
1186
0
}
1187
1188
/*!
1189
 **************************************************************************
1190
 * \if Function name : AcessUnitDelimiterRbsp \endif
1191
 *
1192
 * \brief
1193
 *    Decodes AcessUnitDelimiterRbsp.
1194
 *
1195
 * \param ps_bitstrm   : Pointer to bit ps_bitstrm containing the NAL unit
1196
 *
1197
 * \return
1198
 *    0 on Success and error code otherwise
1199
 **************************************************************************
1200
 */
1201
1202
WORD32 ih264d_access_unit_delimiter_rbsp(dec_struct_t * ps_dec)
1203
2.91k
{
1204
2.91k
    UWORD8 u1_primary_pic_type;
1205
2.91k
    u1_primary_pic_type = ih264d_get_bits_h264(ps_dec->ps_bitstrm, 3);
1206
2.91k
    switch(u1_primary_pic_type)
1207
2.91k
    {
1208
2.32k
        case I_PIC:
1209
2.35k
        case SI_PIC:
1210
2.36k
        case ISI_PIC:
1211
2.36k
            ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_I;
1212
2.36k
            break;
1213
554
        default:
1214
554
            ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
1215
2.91k
    }
1216
2.91k
    return (0);
1217
2.91k
}
1218
/*!
1219
 **************************************************************************
1220
 * \if Function name : ih264d_parse_nal_unit \endif
1221
 *
1222
 * \brief
1223
 *    Decodes NAL unit
1224
 *
1225
 * \return
1226
 *    0 on Success and error code otherwise
1227
 **************************************************************************
1228
 */
1229
1230
WORD32 ih264d_parse_nal_unit(iv_obj_t *dec_hdl,
1231
                          ivd_video_decode_op_t *ps_dec_op,
1232
                          UWORD8 *pu1_buf,
1233
                          UWORD32 u4_length)
1234
863k
{
1235
1236
863k
    dec_bit_stream_t *ps_bitstrm;
1237
1238
1239
863k
    dec_struct_t *ps_dec = (dec_struct_t *)dec_hdl->pv_codec_handle;
1240
863k
    ivd_video_decode_ip_t *ps_dec_in =
1241
863k
                    (ivd_video_decode_ip_t *)ps_dec->pv_dec_in;
1242
863k
    dec_slice_params_t * ps_cur_slice = ps_dec->ps_cur_slice;
1243
863k
    UWORD8 u1_first_byte, u1_nal_ref_idc;
1244
863k
    UWORD8 u1_nal_unit_type;
1245
863k
    WORD32 i_status = OK;
1246
863k
    ps_bitstrm = ps_dec->ps_bitstrm;
1247
1248
863k
    if(pu1_buf)
1249
863k
    {
1250
863k
        if(u4_length)
1251
863k
        {
1252
863k
            ps_dec_op->u4_frame_decoded_flag = 0;
1253
863k
            ih264d_process_nal_unit(ps_dec->ps_bitstrm, pu1_buf,
1254
863k
                                    u4_length);
1255
1256
863k
            SWITCHOFFTRACE;
1257
863k
            u1_first_byte = ih264d_get_bits_h264(ps_bitstrm, 8);
1258
1259
863k
            if(NAL_FORBIDDEN_BIT(u1_first_byte))
1260
63.6k
            {
1261
63.6k
                H264_DEC_DEBUG_PRINT("\nForbidden bit set in Nal Unit, Let's try\n");
1262
63.6k
            }
1263
863k
            u1_nal_unit_type = NAL_UNIT_TYPE(u1_first_byte);
1264
            // if any other nal unit other than slice nal is encountered in between a
1265
            // frame break out of loop without consuming header
1266
863k
            if ((ps_dec->u4_slice_start_code_found == 1)
1267
863k
                    && (ps_dec->u1_pic_decode_done != 1)
1268
863k
                    && (u1_nal_unit_type > IDR_SLICE_NAL))
1269
3.72k
            {
1270
3.72k
                return ERROR_INCOMPLETE_FRAME;
1271
3.72k
            }
1272
859k
            ps_dec->u1_nal_unit_type = u1_nal_unit_type;
1273
859k
            u1_nal_ref_idc = (UWORD8)(NAL_REF_IDC(u1_first_byte));
1274
            //Skip all NALUs if SPS and PPS are not decoded
1275
859k
            switch(u1_nal_unit_type)
1276
859k
            {
1277
99
                case SLICE_DATA_PARTITION_A_NAL:
1278
224
                case SLICE_DATA_PARTITION_B_NAL:
1279
264
                case SLICE_DATA_PARTITION_C_NAL:
1280
264
                    if(!ps_dec->i4_decode_header)
1281
179
                        ih264d_parse_slice_partition(ps_dec, ps_bitstrm);
1282
1283
264
                    break;
1284
1285
5.72k
                case IDR_SLICE_NAL:
1286
70.1k
                case SLICE_NAL:
1287
1288
                    /* ! */
1289
70.1k
                    DEBUG_THREADS_PRINTF("Decoding  a slice NAL\n");
1290
70.1k
                    if(!ps_dec->i4_decode_header)
1291
38.0k
                    {
1292
38.0k
                        if(ps_dec->i4_header_decoded == 3)
1293
17.3k
                        {
1294
17.3k
                            ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
1295
                            /* ! */
1296
17.3k
                            ps_dec->u4_slice_start_code_found = 1;
1297
1298
17.3k
                            ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1299
1300
17.3k
                            i_status = ih264d_parse_decode_slice(
1301
17.3k
                                            (UWORD8)(u1_nal_unit_type
1302
17.3k
                                                            == IDR_SLICE_NAL),
1303
17.3k
                                            u1_nal_ref_idc, ps_dec);
1304
1305
17.3k
                            if(i_status != OK)
1306
11.7k
                            {
1307
11.7k
                                return i_status;
1308
11.7k
                            }
1309
17.3k
                        }
1310
20.6k
                        else
1311
20.6k
                        {
1312
20.6k
                            H264_DEC_DEBUG_PRINT(
1313
20.6k
                                            "\nSlice NAL Supplied but no header has been supplied\n");
1314
20.6k
                        }
1315
38.0k
                    }
1316
58.4k
                    break;
1317
1318
58.4k
                case SEI_NAL:
1319
15.3k
                    if(!ps_dec->i4_decode_header)
1320
10.2k
                    {
1321
10.2k
                        ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1322
10.2k
                        i_status = ih264d_parse_sei_message(ps_dec, ps_bitstrm);
1323
10.2k
                        if(i_status != OK)
1324
8.17k
                            return i_status;
1325
2.07k
                        ih264d_parse_sei(ps_dec, ps_bitstrm);
1326
2.07k
                    }
1327
7.13k
                    break;
1328
414k
                case SEQ_PARAM_NAL:
1329
                    /* ! */
1330
414k
                    ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1331
414k
                    i_status = ih264d_parse_sps(ps_dec, ps_bitstrm);
1332
414k
                    ps_dec->u4_sps_cnt_in_process++;
1333
                    /*If a resolution change happens within a process call, due to multiple sps
1334
                     * we will not support it.
1335
                     */
1336
414k
                    if((ps_dec->u4_sps_cnt_in_process > 1 ) &&
1337
414k
                                    (i_status == IVD_RES_CHANGED))
1338
912
                    {
1339
912
                        i_status = ERROR_INV_SPS_PPS_T;
1340
912
                        ps_dec->u1_res_changed = 0;
1341
912
                    }
1342
414k
                    if(i_status == ERROR_INV_SPS_PPS_T)
1343
2.31k
                        return i_status;
1344
412k
                    if(!i_status)
1345
407k
                        ps_dec->i4_header_decoded |= 0x1;
1346
412k
                    break;
1347
1348
40.6k
                case PIC_PARAM_NAL:
1349
                    /* ! */
1350
40.6k
                    ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1351
40.6k
                    i_status = ih264d_parse_pps(ps_dec, ps_bitstrm);
1352
40.6k
                    if(i_status == ERROR_INV_SPS_PPS_T)
1353
1.30k
                        return i_status;
1354
39.3k
                    if(!i_status)
1355
37.8k
                        ps_dec->i4_header_decoded |= 0x2;
1356
39.3k
                    break;
1357
3.87k
                case ACCESS_UNIT_DELIMITER_RBSP:
1358
3.87k
                    if(!ps_dec->i4_decode_header)
1359
2.91k
                    {
1360
2.91k
                        ih264d_access_unit_delimiter_rbsp(ps_dec);
1361
2.91k
                    }
1362
3.87k
                    break;
1363
                    //Let us ignore the END_OF_SEQ_RBSP NAL and decode even after this NAL
1364
158
                case END_OF_STREAM_RBSP:
1365
158
                    if(!ps_dec->i4_decode_header)
1366
148
                    {
1367
148
                        ih264d_parse_end_of_stream(ps_dec);
1368
148
                    }
1369
158
                    break;
1370
281
                case FILLER_DATA_NAL:
1371
281
                    if(!ps_dec->i4_decode_header)
1372
265
                    {
1373
265
                        ih264d_parse_filler_data(ps_dec, ps_bitstrm);
1374
265
                    }
1375
281
                    break;
1376
314k
                default:
1377
314k
                    H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1378
314k
                    break;
1379
859k
            }
1380
1381
859k
        }
1382
1383
863k
    }
1384
1385
836k
    return i_status;
1386
1387
863k
}