Coverage Report

Created: 2025-08-26 06:38

/src/libavc/decoder/svc/isvcd_parse_headers.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2022 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
23
 *  isvcd_parse_headers.c
24
 *
25
 * @brief
26
 *  Contains High level syntax[above slice] parsing routines
27
 *
28
 * @author
29
 *  Kishore
30
 *
31
 * @par List of Functions:
32
 *  - isvcd_set_default_seq_svc_ext()
33
 *  - isvcd_parse_subset_sps()
34
 *  - isvcd_dec_ref_base_pic_marking()
35
 *  - isvcd_parse_nal_unit()
36
 *  - isvcd_parse_sps()
37
 *  - isvcd_parse_pps()
38
 *
39
 * @remarks
40
 *  None
41
 *
42
 *******************************************************************************
43
 */
44
45
#include <string.h>
46
#include <assert.h>
47
48
#include "ih264_typedefs.h"
49
#include "ih264_defs.h"
50
#include "ih264_macros.h"
51
#include "ih264_platform_macros.h"
52
#include "ih264d_bitstrm.h"
53
#include "isvcd_structs.h"
54
#include "ih264d_parse_cavlc.h"
55
#include "ih264d_defs.h"
56
#include "ih264d_parse_slice.h"
57
#include "ih264d_tables.h"
58
#include "ih264d_utils.h"
59
#include "ih264d_nal.h"
60
#include "ih264d_deblocking.h"
61
#include "ih264d_mem_request.h"
62
#include "ih264d_debug.h"
63
#include "ih264_debug.h"
64
#include "ih264d_error_handler.h"
65
#include "ih264d_mb_utils.h"
66
#include "ih264d_sei.h"
67
#include "ih264d_vui.h"
68
#include "ih264d_thread_parse_decode.h"
69
#include "ih264d_thread_compute_bs.h"
70
#include "ih264d_quant_scaling.h"
71
#include "ih264d_defs.h"
72
#include "ivd.h"
73
#include "ih264d_parse_islice.h"
74
#include "isvcd_parse_slice.h"
75
#include "ih264d_process_bslice.h"
76
#include "ih264d_process_pslice.h"
77
#include "isvcd_vui.h"
78
79
WORD32 ih264d_access_unit_delimiter_rbsp(dec_struct_t *ps_dec);
80
void ih264d_get_pre_sei_params(dec_struct_t *ps_dec, UWORD8 u1_nal_unit_type);
81
UWORD32 ih264d_correct_level_idc(UWORD32 u4_level_idc, UWORD32 u4_total_mbs);
82
WORD32 ih264d_parse_filler_data(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm);
83
void ih264d_parse_end_of_stream(dec_struct_t *ps_dec);
84
WORD32 ih264d_parse_slice_partition(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm);
85
/*!
86
**************************************************************************
87
* \if Function name : isvcd_set_default_seq_svc_ext \en
88
dif
89
*
90
* \brief
91
*    Sets the default values for the svc params in the SVC bitstream
92
*
93
* \return
94
**************************************************************************
95
*/
96
void isvcd_set_default_seq_svc_ext(dec_subset_seq_params_t *ps_seq_svc_ext)
97
21.4k
{
98
21.4k
    ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag = 0;
99
21.4k
    ps_seq_svc_ext->u1_extended_spatial_scalability_idc = 0;
100
21.4k
    ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag = 1;
101
21.4k
    ps_seq_svc_ext->u1_chroma_phase_y_plus1 = 1;
102
21.4k
    ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
103
21.4k
        ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag;
104
21.4k
    ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 = ps_seq_svc_ext->u1_chroma_phase_y_plus1;
105
21.4k
    ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset = 0;
106
21.4k
    ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset = 0;
107
21.4k
    ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset = 0;
108
21.4k
    ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset = 0;
109
21.4k
    ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag =
110
21.4k
        ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag = 0;
111
21.4k
    ps_seq_svc_ext->u1_slice_header_restriction_flag = 0;
112
21.4k
    ps_seq_svc_ext->u1_svc_vui_parameters_present_flag = 0;
113
21.4k
}
114
/*!
115
**************************************************************************
116
* \if Function name : isvcd_parse_subset_sps \en
117
dif
118
*
119
* \brief
120
*    Decodes Sequence parameter set from the SVC bitstream
121
*
122
* \return
123
*    0 on Success and Error code otherwise
124
**************************************************************************
125
*/
126
WORD32 isvcd_parse_subset_sps(svc_dec_lyr_struct_t *ps_svc_lyr_dec, dec_bit_stream_t *ps_bitstrm)
127
26.1k
{
128
26.1k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
129
26.1k
    UWORD8 i;
130
26.1k
    dec_seq_params_t *ps_seq = NULL;
131
26.1k
    dec_svc_seq_params_t *ps_subset_seq = NULL;
132
26.1k
    dec_subset_seq_params_t *ps_seq_svc_ext;
133
26.1k
    UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
134
26.1k
    UWORD16 i2_max_frm_num;
135
26.1k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
136
26.1k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
137
26.1k
    UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag, uc_constraint_set2_flag;
138
26.1k
    WORD32 i4_cropped_ht, i4_cropped_wd;
139
26.1k
    UWORD32 u4_temp;
140
26.1k
    UWORD64 u8_temp;
141
26.1k
    UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
142
26.1k
    UWORD32 u2_pic_wd = 0;
143
26.1k
    UWORD32 u2_pic_ht = 0;
144
26.1k
    UWORD32 u2_frm_wd_y = 0;
145
26.1k
    UWORD32 u2_frm_ht_y = 0;
146
26.1k
    UWORD32 u2_frm_wd_uv = 0;
147
26.1k
    UWORD32 u2_frm_ht_uv = 0;
148
26.1k
    UWORD32 u2_crop_offset_y = 0;
149
26.1k
    UWORD32 u2_crop_offset_uv = 0;
150
26.1k
    WORD32 ret;
151
    /* High profile related syntax element */
152
26.1k
    WORD32 i4_i;
153
    /* G050 */
154
26.1k
    UWORD8 u1_frame_cropping_flag,
155
26.1k
        u1_frame_cropping_rect_left_ofst = 0, u1_frame_cropping_rect_right_ofst = 0,
156
26.1k
        u1_frame_cropping_rect_top_ofst = 0, u1_frame_cropping_rect_bottom_ofst = 0;
157
    /* G050 */
158
    /*--------------------------------------------------------------------*/
159
    /* Decode seq_parameter_set_id and profile and level values           */
160
    /*--------------------------------------------------------------------*/
161
26.1k
    SWITCHONTRACE;
162
26.1k
    u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
163
26.1k
    COPYTHECONTEXT("SPS: profile_idc", u1_profile_idc);
164
165
    /* G050 */
166
26.1k
    uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
167
26.1k
    uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
168
26.1k
    uc_constraint_set2_flag = ih264d_get_bit_h264(ps_bitstrm);
169
26.1k
    UNUSED(uc_constraint_set1_flag);
170
26.1k
    UNUSED(uc_constraint_set2_flag);
171
172
    /*****************************************************/
173
    /* Read 5 bits for uc_constraint_set3_flag (1 bit)   */
174
    /* and reserved_zero_4bits (4 bits) - Sushant        */
175
    /*****************************************************/
176
26.1k
    ih264d_get_bits_h264(ps_bitstrm, 5);
177
    /* G050 */
178
26.1k
    u1_level_idc = (UWORD8) ih264d_get_bits_h264(ps_bitstrm, 8);
179
26.1k
    COPYTHECONTEXT("SPS: u4_level_idc", u1_level_idc);
180
181
26.1k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
182
26.1k
    if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
183
25.6k
    u1_seq_parameter_set_id = u4_temp;
184
25.6k
    COPYTHECONTEXT("SPS: seq_parameter_set_id", u1_seq_parameter_set_id);
185
186
25.6k
    if(u1_seq_parameter_set_id >= MAX_NUM_SEQ_PARAMS) return ERROR_INV_SPS_PPS_T;
187
188
    /*--------------------------------------------------------------------*/
189
    /* Find an seq param entry in seqparam array of decStruct             */
190
    /*--------------------------------------------------------------------*/
191
25.6k
    ps_subset_seq = ps_svc_lyr_dec->pv_scratch_subset_sps;
192
25.6k
    memset(ps_subset_seq, 0, sizeof(dec_svc_seq_params_t));
193
25.6k
    ps_seq = ps_dec->pv_scratch_sps_pps;
194
25.6k
    memset(ps_seq, 0, sizeof(dec_seq_params_t));
195
196
25.6k
    ps_seq->u1_profile_idc = u1_profile_idc;
197
25.6k
    ps_seq->u1_level_idc = u1_level_idc;
198
25.6k
    ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
199
200
    /* subset_seq_sps_will be stored from location 32 : MAX_NUM_SEQ_PARAMS*/
201
25.6k
    u1_seq_parameter_set_id += MAX_NUM_SEQ_PARAMS;
202
25.6k
    ps_subset_seq->ps_seq = &ps_dec->ps_sps[u1_seq_parameter_set_id];
203
204
25.6k
    if((ps_dec->i4_header_decoded & 1) &&
205
25.6k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
206
25.6k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_profile_idc != u1_profile_idc))
207
373
    {
208
373
        ps_dec->u1_res_changed = 1;
209
373
        return IVD_RES_CHANGED;
210
373
    }
211
212
25.2k
    if((ps_dec->i4_header_decoded & 1) &&
213
25.2k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
214
25.2k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_level_idc != u1_level_idc))
215
198
    {
216
198
        ps_dec->u1_res_changed = 1;
217
198
        return IVD_RES_CHANGED;
218
198
    }
219
    /*******************************************************************/
220
    /* Initializations for high profile - Sushant                      */
221
    /*******************************************************************/
222
25.0k
    ps_seq->i4_chroma_format_idc = 1;
223
25.0k
    ps_seq->i4_bit_depth_luma_minus8 = 0;
224
25.0k
    ps_seq->i4_bit_depth_chroma_minus8 = 0;
225
25.0k
    ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
226
25.0k
    ps_seq->i4_seq_scaling_matrix_present_flag = 0;
227
25.0k
    if(u1_profile_idc == HIGH_PROFILE_IDC || u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC ||
228
25.0k
       u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC)
229
6.01k
    {
230
        /* reading chroma_format_idc   */
231
6.01k
        ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
232
233
        /* Monochrome is not supported */
234
6.01k
        if(ps_seq->i4_chroma_format_idc != 1)
235
167
        {
236
167
            return ERROR_FEATURE_UNAVAIL;
237
167
        }
238
239
        /* reading bit_depth_luma_minus8   */
240
5.84k
        ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
241
242
5.84k
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
243
120
        {
244
120
            return ERROR_FEATURE_UNAVAIL;
245
120
        }
246
247
        /* reading bit_depth_chroma_minus8   */
248
5.72k
        ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
249
250
5.72k
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
251
111
        {
252
111
            return ERROR_FEATURE_UNAVAIL;
253
111
        }
254
255
        /* reading qpprime_y_zero_transform_bypass_flag   */
256
5.61k
        ps_seq->i4_qpprime_y_zero_transform_bypass_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
257
258
5.61k
        if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
259
66
        {
260
66
            return ERROR_INV_SPS_PPS_T;
261
66
        }
262
263
        /* reading seq_scaling_matrix_present_flag   */
264
5.54k
        ps_seq->i4_seq_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
265
266
5.54k
        if(ps_seq->i4_seq_scaling_matrix_present_flag)
267
3.88k
        {
268
34.0k
            for(i4_i = 0; i4_i < 8; i4_i++)
269
30.4k
            {
270
30.4k
                ps_seq->u1_seq_scaling_list_present_flag[i4_i] = ih264d_get_bit_h264(ps_bitstrm);
271
272
                /* initialize u1_use_default_scaling_matrix_flag[i4_i] to zero */
273
                /* before calling scaling list                             */
274
30.4k
                ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
275
276
30.4k
                if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
277
14.8k
                {
278
14.8k
                    if(i4_i < 6)
279
11.3k
                    {
280
11.3k
                        ret = ih264d_scaling_list(ps_seq->i2_scalinglist4x4[i4_i], 16,
281
11.3k
                                                  &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
282
11.3k
                                                  ps_bitstrm);
283
11.3k
                    }
284
3.57k
                    else
285
3.57k
                    {
286
3.57k
                        ret = ih264d_scaling_list(ps_seq->i2_scalinglist8x8[i4_i - 6], 64,
287
3.57k
                                                  &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
288
3.57k
                                                  ps_bitstrm);
289
3.57k
                    }
290
14.8k
                    if(ret != OK)
291
315
                    {
292
315
                        return ret;
293
315
                    }
294
14.8k
                }
295
30.4k
            }
296
3.88k
        }
297
5.54k
    }
298
    /*--------------------------------------------------------------------*/
299
    /* Decode MaxFrameNum                                                 */
300
    /*--------------------------------------------------------------------*/
301
24.2k
    u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
302
24.2k
    if(u8_temp > MAX_BITS_IN_FRAME_NUM)
303
253
    {
304
253
        return ERROR_INV_SPS_PPS_T;
305
253
    }
306
24.0k
    ps_seq->u1_bits_in_frm_num = (UWORD8) u8_temp;
307
24.0k
    COPYTHECONTEXT("SPS: log2_max_frame_num_minus4", (ps_seq->u1_bits_in_frm_num - 4));
308
309
24.0k
    i2_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
310
24.0k
    ps_seq->u2_u4_max_pic_num_minus1 = i2_max_frm_num - 1;
311
    /*--------------------------------------------------------------------*/
312
    /* Decode picture order count and related values                      */
313
    /*--------------------------------------------------------------------*/
314
24.0k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
315
316
24.0k
    if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
317
191
    {
318
191
        return ERROR_INV_POC_TYPE_T;
319
191
    }
320
23.8k
    ps_seq->u1_pic_order_cnt_type = u4_temp;
321
23.8k
    COPYTHECONTEXT("SPS: pic_order_cnt_type", ps_seq->u1_pic_order_cnt_type);
322
323
23.8k
    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
324
23.8k
    if(ps_seq->u1_pic_order_cnt_type == 0)
325
19.2k
    {
326
19.2k
        u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
327
19.2k
        if(u8_temp > MAX_BITS_IN_POC_LSB)
328
122
        {
329
122
            return ERROR_INV_SPS_PPS_T;
330
122
        }
331
19.0k
        ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = (UWORD8) u8_temp;
332
19.0k
        ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
333
19.0k
        COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4", (u8_temp - 4));
334
19.0k
    }
335
4.61k
    else if(ps_seq->u1_pic_order_cnt_type == 1)
336
3.07k
    {
337
3.07k
        ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(ps_bitstrm);
338
3.07k
        COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
339
3.07k
                       ps_seq->u1_delta_pic_order_always_zero_flag);
340
341
3.07k
        ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
342
3.07k
        COPYTHECONTEXT("SPS: offset_for_non_ref_pic", ps_seq->i4_ofst_for_non_ref_pic);
343
344
3.07k
        ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
345
3.07k
        COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
346
3.07k
                       ps_seq->i4_ofst_for_top_to_bottom_field);
347
348
3.07k
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
349
3.07k
        if(u4_temp > 255) return ERROR_INV_SPS_PPS_T;
350
2.97k
        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
351
2.97k
        COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
352
2.97k
                       ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
353
354
20.4k
        for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
355
17.4k
        {
356
17.4k
            ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
357
17.4k
            COPYTHECONTEXT("SPS: offset_for_ref_frame", ps_seq->i4_ofst_for_ref_frame[i]);
358
17.4k
        }
359
2.97k
    }
360
361
23.6k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
362
363
23.6k
    if((u4_temp > H264_MAX_REF_PICS))
364
191
    {
365
191
        return ERROR_NUM_REF;
366
191
    }
367
368
    /* Compare with older num_ref_frames is header is already once */
369
23.4k
    if((ps_dec->i4_header_decoded & 1) &&
370
23.4k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
371
23.4k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_num_ref_frames != u4_temp))
372
91
    {
373
91
        ps_dec->u1_res_changed = 1;
374
91
        return IVD_RES_CHANGED;
375
91
    }
376
23.3k
    ps_seq->u1_num_ref_frames = u4_temp;
377
23.3k
    COPYTHECONTEXT("SPS: num_ref_frames", ps_seq->u1_num_ref_frames);
378
379
23.3k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(ps_bitstrm);
380
23.3k
    COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
381
23.3k
                   ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
382
    /* SVC_DEC_REVIEW */
383
23.3k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = 0;
384
385
    /*--------------------------------------------------------------------*/
386
    /* Decode FrameWidth and FrameHeight and related values               */
387
    /*--------------------------------------------------------------------*/
388
23.3k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
389
    /* Check  for unsupported resolutions*/
390
23.3k
    if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
391
164
    {
392
164
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
393
164
    }
394
23.1k
    u4_pic_width_in_mbs = (UWORD32) u8_temp;
395
23.1k
    COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1", u4_pic_width_in_mbs - 1);
396
397
23.1k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
398
23.1k
    if(u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
399
169
    {
400
169
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
401
169
    }
402
22.9k
    u4_pic_height_in_map_units = (UWORD32) u8_temp;
403
404
22.9k
    ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
405
22.9k
    ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
406
407
22.9k
    u2_pic_wd = (u4_pic_width_in_mbs << 4);
408
22.9k
    u2_pic_ht = (u4_pic_height_in_map_units << 4);
409
22.9k
    if(ps_svc_lyr_dec->pic_width < u2_pic_wd)
410
8.90k
    {
411
8.90k
        ps_svc_lyr_dec->pic_width = u2_pic_wd;
412
8.90k
    }
413
22.9k
    if(ps_svc_lyr_dec->pic_height < u2_pic_ht)
414
8.97k
    {
415
8.97k
        ps_svc_lyr_dec->pic_height = u2_pic_ht;
416
8.97k
    }
417
418
    /*--------------------------------------------------------------------*/
419
    /* Get the value of MaxMbAddress and Number of bits needed for it     */
420
    /*--------------------------------------------------------------------*/
421
22.9k
    ps_seq->u4_max_mb_addr = (ps_seq->u2_frm_wd_in_mbs * ps_seq->u2_frm_ht_in_mbs) - 1;
422
423
22.9k
    ps_seq->u4_total_num_of_mbs = ps_seq->u4_max_mb_addr + 1;
424
425
22.9k
    ps_seq->u1_level_idc = ih264d_correct_level_idc(u1_level_idc, ps_seq->u4_total_num_of_mbs);
426
427
22.9k
    u1_frm = ih264d_get_bit_h264(ps_bitstrm);
428
429
22.9k
    if((ps_dec->i4_header_decoded & 1) &&
430
22.9k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
431
22.9k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_frame_mbs_only_flag != u1_frm))
432
129
    {
433
129
        ps_dec->u1_res_changed = 1;
434
129
        return IVD_RES_CHANGED;
435
129
    }
436
22.8k
    ps_seq->u1_frame_mbs_only_flag = u1_frm;
437
438
22.8k
    COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
439
440
22.8k
    if(!u1_frm) u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
441
22.8k
    if((ps_dec->i4_header_decoded & 1) &&
442
22.8k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
443
22.8k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_mb_aff_flag != u1_mb_aff_flag))
444
73
    {
445
73
        ps_dec->u1_res_changed = 1;
446
73
        return IVD_RES_CHANGED;
447
73
    }
448
22.7k
    if(!u1_frm)
449
3.71k
    {
450
3.71k
        u2_pic_ht <<= 1;
451
3.71k
        ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
452
3.71k
        COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag", ps_seq->u1_mb_aff_flag);
453
3.71k
    }
454
19.0k
    else
455
19.0k
        ps_seq->u1_mb_aff_flag = 0;
456
457
22.7k
    ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
458
459
22.7k
    COPYTHECONTEXT("SPS: direct_8x8_inference_flag", ps_seq->u1_direct_8x8_inference_flag);
460
461
    /* G050 */
462
22.7k
    u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
463
22.7k
    COPYTHECONTEXT("SPS: frame_cropping_flag", u1_frame_cropping_flag);
464
465
22.7k
    if(u1_frame_cropping_flag)
466
6.39k
    {
467
6.39k
        u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
468
6.39k
        COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset", u1_frame_cropping_rect_left_ofst);
469
6.39k
        u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
470
6.39k
        COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset", u1_frame_cropping_rect_right_ofst);
471
6.39k
        u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
472
6.39k
        COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset", u1_frame_cropping_rect_top_ofst);
473
6.39k
        u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
474
6.39k
        COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
475
6.39k
                       u1_frame_cropping_rect_bottom_ofst);
476
6.39k
    }
477
    /* G050 */
478
22.7k
    ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
479
22.7k
    COPYTHECONTEXT("SPS: vui_parameters_present_flag", ps_seq->u1_vui_parameters_present_flag);
480
481
22.7k
    u2_frm_wd_y = u2_pic_wd + (UWORD8) (PAD_LEN_Y_H << 1);
482
22.7k
    if(1 == ps_dec->u4_share_disp_buf)
483
0
    {
484
0
        if(ps_dec->u4_app_disp_width > u2_frm_wd_y) u2_frm_wd_y = ps_dec->u4_app_disp_width;
485
0
    }
486
487
22.7k
    u2_frm_ht_y = u2_pic_ht + (UWORD8) (PAD_LEN_Y_V << 2);
488
22.7k
    u2_frm_wd_uv = u2_pic_wd + (UWORD8) (PAD_LEN_UV_H << 2);
489
22.7k
    u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
490
491
22.7k
    u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8) (PAD_LEN_UV_V << 2);
492
22.7k
    u2_frm_ht_uv = MAX(u2_frm_ht_uv, (u2_frm_ht_y >> 1));
493
494
    /* Calculate display picture width, height and start u4_ofst from YUV420 */
495
    /* pictute buffers as per cropping information parsed above             */
496
22.7k
    {
497
22.7k
        UWORD16 u2_rgt_ofst = 0;
498
22.7k
        UWORD16 u2_lft_ofst = 0;
499
22.7k
        UWORD16 u2_top_ofst = 0;
500
22.7k
        UWORD16 u2_btm_ofst = 0;
501
22.7k
        UWORD8 u1_frm_mbs_flag;
502
22.7k
        UWORD8 u1_vert_mult_factor;
503
504
22.7k
        if(u1_frame_cropping_flag)
505
6.39k
        {
506
            /* Calculate right and left u4_ofst for cropped picture           */
507
6.39k
            u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
508
6.39k
            u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
509
510
            /* Know frame MBs only u4_flag                                      */
511
6.39k
            u1_frm_mbs_flag = (1 == ps_seq->u1_frame_mbs_only_flag);
512
513
            /* Simplify the vertical u4_ofst calculation from field/frame     */
514
6.39k
            u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
515
516
            /* Calculate bottom and top u4_ofst for cropped  picture          */
517
6.39k
            u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst << u1_vert_mult_factor);
518
6.39k
            u2_top_ofst = (u1_frame_cropping_rect_top_ofst << u1_vert_mult_factor);
519
6.39k
        }
520
521
        /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
522
        /* cropped picture buffer                                           */
523
22.7k
        u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
524
22.7k
        u2_crop_offset_uv =
525
22.7k
            (u2_frm_wd_uv * (u2_top_ofst >> 1)) + (u2_lft_ofst >> 1) * YUV420SP_FACTOR;
526
        /* Calculate the display picture width and height based on crop      */
527
        /* information                                                       */
528
22.7k
        i4_cropped_ht = (WORD32) u2_pic_ht - (WORD32) (u2_btm_ofst + u2_top_ofst);
529
22.7k
        i4_cropped_wd = (WORD32) u2_pic_wd - (WORD32) (u2_rgt_ofst + u2_lft_ofst);
530
531
22.7k
        if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
532
246
        {
533
246
            return ERROR_INV_SPS_PPS_T;
534
246
        }
535
536
22.5k
        if((ps_dec->i4_header_decoded & 1) &&
537
22.5k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
538
22.5k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_wd != u2_pic_wd))
539
168
        {
540
168
            ps_dec->u1_res_changed = 1;
541
168
            return IVD_RES_CHANGED;
542
168
        }
543
544
22.3k
        if((ps_dec->i4_header_decoded & 1) &&
545
22.3k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
546
22.3k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_width != i4_cropped_wd))
547
67
        {
548
67
            ps_dec->u1_res_changed = 1;
549
67
            return IVD_RES_CHANGED;
550
67
        }
551
552
22.3k
        if((ps_dec->i4_header_decoded & 1) &&
553
22.3k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
554
22.3k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_ht != u2_pic_ht))
555
82
        {
556
82
            ps_dec->u1_res_changed = 1;
557
82
            return IVD_RES_CHANGED;
558
82
        }
559
560
22.2k
        if((ps_dec->i4_header_decoded & 1) &&
561
22.2k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
562
22.2k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_height != i4_cropped_ht))
563
70
        {
564
70
            ps_dec->u1_res_changed = 1;
565
70
            return IVD_RES_CHANGED;
566
70
        }
567
        /* Check again for unsupported resolutions with updated values*/
568
22.1k
        if((u2_pic_wd > SVCD_MAX_FRAME_WIDTH) || (u2_pic_ht > SVCD_MAX_FRAME_HEIGHT) ||
569
22.1k
           (u2_pic_wd < SVCD_MIN_FRAME_WIDTH) || (u2_pic_ht < SVCD_MIN_FRAME_HEIGHT) ||
570
22.1k
           (u2_pic_wd * (UWORD32) u2_pic_ht > SVCD_MAX_FRAME_SIZE))
571
342
        {
572
342
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
573
342
        }
574
575
        /* If MBAff is enabled, decoder support is limited to streams with
576
         * width less than half of H264_MAX_FRAME_WIDTH.
577
         * In case of MBAff decoder processes two rows at a time
578
         */
579
21.8k
        if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
580
83
        {
581
83
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
582
83
        }
583
21.8k
    }
584
585
21.7k
    if(1 == ps_seq->u1_vui_parameters_present_flag)
586
5.25k
    {
587
5.25k
        ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
588
5.25k
        if(ret != OK) return ret;
589
5.25k
    }
590
21.4k
    ps_seq_svc_ext = &ps_subset_seq->s_sps_svc_ext;
591
592
21.4k
    isvcd_set_default_seq_svc_ext(ps_seq_svc_ext);
593
594
21.4k
    if(SCALABLE_BASELINE_PROFILE_IDC == ps_seq->u1_profile_idc ||
595
21.4k
       SCALABLE_HIGH_PROFILE_IDC == ps_seq->u1_profile_idc)
596
4.88k
    {
597
4.88k
        SWITCHONTRACE;
598
4.88k
        ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag =
599
4.88k
            ih264d_get_bit_h264(ps_bitstrm);
600
4.88k
        COPYTHECONTEXT("SPS_EXt: u1_inter_layer_deblocking_filter_control_present_flag",
601
4.88k
                       ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag);
602
603
4.88k
        ps_seq_svc_ext->u1_extended_spatial_scalability_idc = ih264d_get_bits_h264(ps_bitstrm, 2);
604
4.88k
        COPYTHECONTEXT("SPS_EXt: u1_extended_spatial_scalability_idc",
605
4.88k
                       ps_seq_svc_ext->u1_extended_spatial_scalability_idc);
606
607
        /* u1_extended_spatial_scalability_idc value 0, 1 and 2 are supported */
608
4.88k
        if(ps_seq_svc_ext->u1_extended_spatial_scalability_idc > 2)
609
72
        {
610
72
            return ERROR_SVC_INV_SUBSET_SPS;
611
72
        }
612
613
        /* ChromaArrayType = i4_chroma_format_idc  if  separate_colour_plane_flag =
614
         * 0 for all chroma format except 4:4:4 */
615
4.81k
        if(1 == ps_seq->i4_chroma_format_idc || 2 == ps_seq->i4_chroma_format_idc)
616
4.81k
        {
617
4.81k
            ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag = ih264d_get_bit_h264(ps_bitstrm);
618
4.81k
            COPYTHECONTEXT("SPS_EXt: u1_chroma_phase_x_plus1_flag",
619
4.81k
                           ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag);
620
4.81k
        }
621
622
4.81k
        if(1 == ps_seq->i4_chroma_format_idc)
623
4.81k
        {
624
4.81k
            ps_seq_svc_ext->u1_chroma_phase_y_plus1 = ih264d_get_bits_h264(ps_bitstrm, 2);
625
4.81k
            COPYTHECONTEXT("SPS_EXt: u1_chroma_phase_y_plus1",
626
4.81k
                           ps_seq_svc_ext->u1_chroma_phase_y_plus1);
627
628
4.81k
            if(ps_seq_svc_ext->u1_chroma_phase_y_plus1 >= 3)
629
76
            {
630
76
                return ERROR_SVC_INV_SUBSET_SPS;
631
76
            }
632
4.81k
        }
633
634
        /* inferred values not covered in isvcd_set_default_seq_svc_ext*/
635
4.73k
        ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
636
4.73k
            ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag;
637
4.73k
        ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 =
638
4.73k
            ps_seq_svc_ext->u1_chroma_phase_y_plus1;
639
640
4.73k
        if(1 == ps_seq_svc_ext->u1_extended_spatial_scalability_idc)
641
1.76k
        {
642
1.76k
            if(ps_seq->i4_chroma_format_idc > 0)
643
1.76k
            {
644
1.76k
                ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
645
1.76k
                    ih264d_get_bit_h264(ps_bitstrm);
646
1.76k
                COPYTHECONTEXT("SPS_EXt: u1_seq_ref_layer_chroma_phase_x_plus1_flag",
647
1.76k
                               ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag);
648
649
1.76k
                ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 =
650
1.76k
                    ih264d_get_bits_h264(ps_bitstrm, 2);
651
1.76k
                COPYTHECONTEXT("SPS_EXt: u1_seq_ref_layer_chroma_phase_y_plus1",
652
1.76k
                               ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1);
653
654
1.76k
                if(ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 >= 3)
655
69
                {
656
69
                    return ERROR_SVC_INV_SUBSET_SPS;
657
69
                }
658
1.76k
            }
659
660
1.69k
            ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset =
661
1.69k
                ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
662
1.69k
            COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_left_offset",
663
1.69k
                           ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset);
664
665
1.69k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset != 0)
666
146
            {
667
146
                return ERROR_SVC_INV_SUBSET_SPS;
668
146
            }
669
670
1.55k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
671
1.55k
               ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset < MIN_SCLD_REF_LAYER_OFFSET)
672
0
            {
673
0
                return ERROR_SVC_INV_SUBSET_SPS;
674
0
            }
675
676
1.55k
            ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset =
677
1.55k
                ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
678
1.55k
            COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_top_offset",
679
1.55k
                           ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset);
680
681
1.55k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset != 0)
682
121
            {
683
121
                return ERROR_SVC_INV_SUBSET_SPS;
684
121
            }
685
686
1.43k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
687
1.43k
               ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset < MIN_SCLD_REF_LAYER_OFFSET)
688
0
            {
689
0
                return ERROR_SVC_INV_SUBSET_SPS;
690
0
            }
691
692
1.43k
            ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset =
693
1.43k
                ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
694
1.43k
            COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_right_offset",
695
1.43k
                           ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset);
696
697
1.43k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
698
1.43k
               ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset < MIN_SCLD_REF_LAYER_OFFSET)
699
163
            {
700
163
                return ERROR_SVC_INV_SUBSET_SPS;
701
163
            }
702
703
1.26k
            ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset =
704
1.26k
                ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
705
1.26k
            COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_bottom_offset",
706
1.26k
                           ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset);
707
708
1.26k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
709
1.26k
               ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset < MIN_SCLD_REF_LAYER_OFFSET)
710
169
            {
711
169
                return ERROR_INV_SLICE_HDR_T;
712
169
            }
713
1.26k
        }
714
715
4.06k
        ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag = ih264d_get_bit_h264(ps_bitstrm);
716
4.06k
        COPYTHECONTEXT("SPS_EXt: u1_seq_tcoeff_level_prediction_flag",
717
4.06k
                       ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag);
718
719
4.06k
        if(1 == ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag)
720
2.88k
        {
721
2.88k
            ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag =
722
2.88k
                ih264d_get_bit_h264(ps_bitstrm);
723
2.88k
            COPYTHECONTEXT("SPS_EXt: u1_adaptive_tcoeff_level_prediction_flag",
724
2.88k
                           ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag);
725
2.88k
        }
726
727
4.06k
        ps_seq_svc_ext->u1_slice_header_restriction_flag = ih264d_get_bit_h264(ps_bitstrm);
728
4.06k
        COPYTHECONTEXT("SPS_EXt: u1_slice_header_restriction_flag",
729
4.06k
                       ps_seq_svc_ext->u1_slice_header_restriction_flag);
730
731
4.06k
        ps_seq_svc_ext->u1_svc_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
732
4.06k
        COPYTHECONTEXT("SPS_EXt: u1_svc_vui_parameters_present_flag",
733
4.06k
                       ps_seq_svc_ext->u1_svc_vui_parameters_present_flag);
734
735
4.06k
        if(1 == ps_seq_svc_ext->u1_svc_vui_parameters_present_flag)
736
978
        {
737
978
            if(NULL ==
738
978
               ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext)
739
406
            {
740
406
                void *pv_buf;
741
406
                UWORD32 size;
742
                /* Memory allocation only if VUI is enabled in a particular subset SPS*/
743
406
                size = sizeof(svc_vui_ext_t);
744
406
                pv_buf = ps_dec->pf_aligned_alloc(ps_dec->pv_mem_ctxt, 128, size);
745
406
                RETURN_IF((NULL == pv_buf), IV_FAIL);
746
406
                memset(pv_buf, 0, size);
747
406
                ps_seq_svc_ext->ps_svc_vui_ext = pv_buf;
748
406
                ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id]
749
406
                    .s_sps_svc_ext.ps_svc_vui_ext = pv_buf;
750
406
            }
751
572
            else
752
572
            {
753
572
                ps_seq_svc_ext->ps_svc_vui_ext =
754
572
                    ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id]
755
572
                        .s_sps_svc_ext.ps_svc_vui_ext;
756
572
            }
757
978
            ret = isvcd_parse_vui_ext_parametres(ps_seq_svc_ext->ps_svc_vui_ext, ps_bitstrm);
758
978
            if(ret != OK) return ret;
759
978
        }
760
4.06k
    }
761
    /* Add conditions for SCALABLE BASELINE PROFILE */
762
20.3k
    if(SCALABLE_BASELINE_PROFILE_IDC == ps_seq->u1_profile_idc ||
763
20.3k
       ((SCALABLE_HIGH_PROFILE_IDC == ps_seq->u1_profile_idc) && (1 == uc_constraint_set0_flag)))
764
2.64k
    {
765
2.64k
        if(ps_seq->i4_chroma_format_idc != 1)
766
0
        {
767
0
            return ERROR_FEATURE_UNAVAIL;
768
0
        }
769
770
2.64k
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
771
0
        {
772
0
            return ERROR_FEATURE_UNAVAIL;
773
0
        }
774
775
2.64k
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
776
0
        {
777
0
            return ERROR_FEATURE_UNAVAIL;
778
0
        }
779
780
2.64k
        if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
781
0
        {
782
0
            return ERROR_FEATURE_UNAVAIL;
783
0
        }
784
785
2.64k
        if(ps_seq->u1_frame_mbs_only_flag != 1)
786
192
        {
787
192
            return ERROR_FEATURE_UNAVAIL;
788
192
        }
789
790
2.45k
        if((0 != ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset % 16) &&
791
2.45k
           (0 != ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset % 16))
792
0
        {
793
0
            return ERROR_FEATURE_UNAVAIL;
794
0
        }
795
2.45k
    }
796
    /* Compare older num_reorder_frames with the new one if header is already
797
     * decoded */
798
20.1k
    if((ps_dec->i4_header_decoded & 1) &&
799
20.1k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
800
20.1k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_vui_parameters_present_flag) &&
801
20.1k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].s_vui.u1_bitstream_restriction_flag))
802
71
    {
803
71
        ps_dec->u1_res_changed = 1;
804
71
        return IVD_RES_CHANGED;
805
71
    }
806
    /* In case bitstream read has exceeded the filled size, then return an error */
807
20.0k
    if(EXCEED_OFFSET(ps_bitstrm))
808
1.05k
    {
809
1.05k
        return ERROR_INV_SPS_PPS_T;
810
1.05k
    }
811
812
    /*--------------------------------------------------------------------*/
813
    /* All initializations to ps_dec are beyond this point                */
814
    /*--------------------------------------------------------------------*/
815
18.9k
    {
816
18.9k
        WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
817
18.9k
        if((1 == ps_seq->u1_vui_parameters_present_flag) &&
818
18.9k
           (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
819
236
        {
820
236
            reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
821
236
        }
822
823
18.9k
        if(reorder_depth > H264_MAX_REF_PICS)
824
66
        {
825
66
            return ERROR_INV_SPS_PPS_T;
826
66
        }
827
828
18.9k
        if(ps_seq->u1_frame_mbs_only_flag != 1) reorder_depth *= 2;
829
18.9k
        ps_subset_seq->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
830
18.9k
    }
831
0
    ps_subset_seq->u2_disp_height = i4_cropped_ht;
832
18.9k
    ps_subset_seq->u2_disp_width = i4_cropped_wd;
833
18.9k
    ps_subset_seq->u2_pic_wd = u2_pic_wd;
834
18.9k
    ps_subset_seq->u2_pic_ht = u2_pic_ht;
835
836
    /* Assuming 8k is the maximum resolution svc dec supports*/
837
18.9k
    if(u2_frm_wd_y > H264_MAX_FRAME_WIDTH) return (NOT_OK);
838
18.7k
    if(u2_frm_ht_y > H264_MAX_FRAME_HEIGHT) return (NOT_OK);
839
18.6k
    if(u2_frm_wd_uv > H264_MAX_FRAME_WIDTH) return (NOT_OK);
840
18.6k
    if(u2_frm_ht_uv > H264_MAX_FRAME_HEIGHT) return (NOT_OK);
841
842
    /* Determining the Width and Height of Frame from that of Picture */
843
18.6k
    ps_subset_seq->u2_frm_wd_y = u2_frm_wd_y;
844
18.6k
    ps_subset_seq->u2_frm_ht_y = u2_frm_ht_y;
845
18.6k
    ps_subset_seq->u2_frm_wd_uv = u2_frm_wd_uv;
846
18.6k
    ps_subset_seq->u2_frm_ht_uv = u2_frm_ht_uv;
847
848
18.6k
    ps_subset_seq->u1_pad_len_y_v = (UWORD8) (PAD_LEN_Y_V << (1 - u1_frm));
849
18.6k
    ps_subset_seq->u1_pad_len_cr_v = (UWORD8) (PAD_LEN_UV_V << (1 - u1_frm));
850
851
18.6k
    ps_subset_seq->u2_crop_offset_y = u2_crop_offset_y;
852
18.6k
    ps_subset_seq->u2_crop_offset_uv = u2_crop_offset_uv;
853
854
18.6k
    ps_seq->u1_is_valid = TRUE;
855
18.6k
    ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
856
18.6k
    if(NULL != ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext)
857
584
    {
858
584
        ps_seq_svc_ext->ps_svc_vui_ext =
859
584
            ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext;
860
584
    }
861
18.6k
    ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id] = *ps_subset_seq;
862
18.6k
    ps_svc_lyr_dec->ps_cur_subset_sps = &ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id];
863
864
18.6k
    return OK;
865
18.6k
}
866
/*!
867
 **************************************************************************
868
 * \if Function name : isvcd_dec_ref_base_pic_marking \endif
869
 *
870
 * \brief
871
 *    Decodes reference base pic marking params
872
 *
873
 * \return
874
 *    0 on Success and error code otherwise
875
 **************************************************************************
876
 */
877
878
WORD32 isvcd_dec_ref_base_pic_marking(
879
    dec_ref_base_pic_marking_params_t *ps_ref_base_pic_marking_svc_ext,
880
    dec_bit_stream_t *ps_bitstrm)
881
0
{
882
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
883
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
884
885
0
    SWITCHONTRACE;
886
887
0
    ps_ref_base_pic_marking_svc_ext->u1_adaptive_ref_base_pic_marking_mode_flag =
888
0
        ih264d_get_bit_h264(ps_bitstrm);
889
0
    COPYTHECONTEXT(
890
0
        "Dec ref base pic marking params : "
891
0
        "u1_adaptive_ref_base_pic_marking_mode_flag",
892
0
        ps_ref_base_pic_marking_svc_ext->u1_adaptive_ref_base_pic_marking_mode_flag);
893
894
0
    if(1 == ps_ref_base_pic_marking_svc_ext->u1_adaptive_ref_base_pic_marking_mode_flag)
895
0
    {
896
0
        do
897
0
        {
898
0
            ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation =
899
0
                ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
900
0
            COPYTHECONTEXT(
901
0
                "Dec ref base pic marking params : "
902
0
                "u4_memory_management_base_control_operation",
903
0
                ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation);
904
905
0
            if(1 == ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation)
906
0
            {
907
0
                ps_ref_base_pic_marking_svc_ext->u4_difference_of_base_pic_nums_minus1 =
908
0
                    ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
909
0
                COPYTHECONTEXT(
910
0
                    "Dec ref base pic marking params : "
911
0
                    "u4_difference_of_base_pic_nums_minus1",
912
0
                    ps_ref_base_pic_marking_svc_ext->u4_difference_of_base_pic_nums_minus1);
913
0
            }
914
915
0
            if(2 == ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation)
916
0
            {
917
0
                ps_ref_base_pic_marking_svc_ext->u4_long_term_base_pic_num =
918
0
                    ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
919
0
                COPYTHECONTEXT("Dec ref base pic marking params : u4_long_term_base_pic_num",
920
0
                               ps_ref_base_pic_marking_svc_ext->u4_long_term_base_pic_num);
921
0
            }
922
923
0
        } while(0 != ps_ref_base_pic_marking_svc_ext->u4_memory_management_base_control_operation);
924
0
    }
925
0
    SWITCHOFFTRACE;
926
927
0
    return OK;
928
0
}
929
930
/*!
931
 **************************************************************************
932
 * \if Function name : isvcd_parse_nal_unit \endif
933
 *
934
 * \brief
935
 *    Decodes NAL unit
936
 *
937
 * \return
938
 *    0 on Success and error code otherwise
939
 **************************************************************************
940
 */
941
942
WORD32 isvcd_parse_nal_unit(svc_dec_lyr_struct_t *dec_svc_hdl, UWORD8 u1_nal_ref_idc)
943
176k
{
944
176k
    dec_bit_stream_t *ps_bitstrm;
945
946
176k
    dec_struct_t *ps_dec;
947
176k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec;
948
176k
    UWORD8 u1_nal_unit_type;
949
176k
    WORD32 i_status = OK;
950
951
176k
    ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) dec_svc_hdl;
952
176k
    ps_dec = &ps_svc_lyr_dec->s_dec;
953
954
176k
    {
955
176k
        SWITCHOFFTRACE;
956
176k
        u1_nal_unit_type = ps_dec->u1_nal_unit_type;
957
958
176k
        ps_bitstrm = ps_dec->ps_bitstrm;
959
960
        // Skip all NALUs if SPS and PPS are not decoded
961
176k
        switch(u1_nal_unit_type)
962
176k
        {
963
0
            case SLICE_DATA_PARTITION_A_NAL:
964
0
            case SLICE_DATA_PARTITION_B_NAL:
965
0
            case SLICE_DATA_PARTITION_C_NAL:
966
0
                if(!ps_dec->i4_decode_header) ih264d_parse_slice_partition(ps_dec, ps_bitstrm);
967
0
                break;
968
969
111k
            case IDR_SLICE_NAL:
970
135k
            case SLICE_NAL:
971
972
135k
                if(ps_svc_lyr_dec->u1_base_res_flag != 1)
973
67
                {
974
67
                    return NOT_OK;
975
67
                }
976
135k
                if(!ps_dec->i4_decode_header)
977
135k
                {
978
135k
                    if(ps_dec->i4_header_decoded == 3)
979
135k
                    {
980
                        /* ! */
981
135k
                        DEBUG_THREADS_PRINTF("Decoding  a slice NAL\n");
982
135k
                        {
983
135k
                            ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
984
                            /* ! */
985
135k
                            ps_dec->u4_slice_start_code_found = 1;
986
987
135k
                            i_status = isvcd_parse_decode_slice(
988
135k
                                (UWORD8) (u1_nal_unit_type == IDR_SLICE_NAL), u1_nal_ref_idc,
989
135k
                                ps_svc_lyr_dec);
990
991
135k
                            if(i_status != OK)
992
80.4k
                            {
993
80.4k
                                return i_status;
994
80.4k
                            }
995
135k
                        }
996
135k
                    }
997
135k
                }
998
54.6k
                break;
999
1000
54.6k
            case SEI_NAL:
1001
0
            case PREFIX_UNIT_NAL:
1002
0
            case SEQ_PARAM_NAL:
1003
0
            case PIC_PARAM_NAL:
1004
0
            case SUBSET_SPS_NAL:
1005
0
                H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1006
0
                break;
1007
1008
0
            case ACCESS_UNIT_DELIMITER_RBSP:
1009
0
                if(!ps_dec->i4_decode_header)
1010
0
                {
1011
0
                    ih264d_access_unit_delimiter_rbsp(ps_dec);
1012
0
                }
1013
0
                break;
1014
                // ignore the END_OF_SEQ_RBSP NAL and decode even after this NAL
1015
0
            case END_OF_STREAM_RBSP:
1016
0
                if(!ps_dec->i4_decode_header)
1017
0
                {
1018
0
                    ih264d_parse_end_of_stream(ps_dec);
1019
0
                }
1020
0
                break;
1021
0
            case FILLER_DATA_NAL:
1022
0
                if(!ps_dec->i4_decode_header)
1023
0
                {
1024
0
                    ih264d_parse_filler_data(ps_dec, ps_bitstrm);
1025
0
                }
1026
0
                break;
1027
41.7k
            case CODED_SLICE_EXTENSION_NAL:
1028
1029
41.7k
                if(ps_svc_lyr_dec->u1_base_res_flag == 1)
1030
3.20k
                {
1031
3.20k
                    return NOT_OK;
1032
3.20k
                }
1033
38.5k
                if(!ps_dec->i4_decode_header)
1034
38.5k
                {
1035
38.5k
                    if(ps_dec->i4_header_decoded == 3)
1036
38.5k
                    {
1037
                        /* ! */
1038
38.5k
                        DEBUG_THREADS_PRINTF("Decoding  an SVC slice NAL\n");
1039
38.5k
                        {
1040
38.5k
                            {
1041
38.5k
                                ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
1042
                                /* ! */
1043
38.5k
                                ps_dec->u4_slice_start_code_found = 1;
1044
1045
38.5k
                                i_status = isvcd_parse_decode_slice_ext_nal(
1046
38.5k
                                    (UWORD8) (ps_svc_lyr_dec->ps_nal_svc_ext->u1_idr_flag),
1047
38.5k
                                    u1_nal_ref_idc, ps_svc_lyr_dec);
1048
1049
38.5k
                                if(i_status != OK)
1050
27.4k
                                {
1051
27.4k
                                    return i_status;
1052
27.4k
                                }
1053
38.5k
                            }
1054
38.5k
                        }
1055
38.5k
                    }
1056
38.5k
                }
1057
11.1k
                break;
1058
1059
11.1k
            default:
1060
0
                H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1061
0
                break;
1062
176k
        }
1063
176k
    }
1064
65.8k
    return i_status;
1065
176k
}
1066
1067
/*!
1068
**************************************************************************
1069
* \if Function name : isvcd_parse_sps \endif
1070
*
1071
* \brief
1072
*    Decodes Picture Parameter set
1073
*
1074
* \return
1075
*    0 on Success and Error code otherwise
1076
**************************************************************************
1077
*/
1078
WORD32 isvcd_parse_sps(svc_dec_lyr_struct_t *ps_svc_lyr_dec, dec_bit_stream_t *ps_bitstrm)
1079
111k
{
1080
111k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1081
111k
    UWORD8 i;
1082
111k
    dec_seq_params_t *ps_seq = NULL;
1083
111k
    dec_svc_seq_params_t *ps_subset_seq = NULL;
1084
111k
    UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
1085
111k
    UWORD16 i2_max_frm_num;
1086
111k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1087
111k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1088
111k
    UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag, uc_constraint_set2_flag;
1089
111k
    WORD32 i4_cropped_ht, i4_cropped_wd;
1090
111k
    UWORD32 u4_temp;
1091
111k
    UWORD64 u8_temp;
1092
111k
    UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
1093
111k
    UWORD32 u2_pic_wd = 0;
1094
111k
    UWORD32 u2_pic_ht = 0;
1095
111k
    UWORD32 u2_frm_wd_y = 0;
1096
111k
    UWORD32 u2_frm_ht_y = 0;
1097
111k
    UWORD32 u2_frm_wd_uv = 0;
1098
111k
    UWORD32 u2_frm_ht_uv = 0;
1099
111k
    UWORD32 u2_crop_offset_y = 0;
1100
111k
    UWORD32 u2_crop_offset_uv = 0;
1101
111k
    WORD32 ret;
1102
111k
    WORD32 num_reorder_frames;
1103
    /* High profile related syntax element */
1104
111k
    WORD32 i4_i;
1105
    /* G050 */
1106
111k
    UWORD8 u1_frame_cropping_flag,
1107
111k
        u1_frame_cropping_rect_left_ofst = 0, u1_frame_cropping_rect_right_ofst = 0,
1108
111k
        u1_frame_cropping_rect_top_ofst = 0, u1_frame_cropping_rect_bottom_ofst = 0;
1109
    /* G050 */
1110
    /*--------------------------------------------------------------------*/
1111
    /* Decode seq_parameter_set_id and profile and level values           */
1112
    /*--------------------------------------------------------------------*/
1113
111k
    SWITCHONTRACE;
1114
111k
    u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
1115
111k
    COPYTHECONTEXT("SPS: profile_idc", u1_profile_idc);
1116
1117
    /* G050 */
1118
111k
    uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
1119
111k
    uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
1120
111k
    uc_constraint_set2_flag = ih264d_get_bit_h264(ps_bitstrm);
1121
111k
    UNUSED(uc_constraint_set2_flag);
1122
    /*****************************************************/
1123
    /* Read 5 bits for uc_constraint_set3_flag (1 bit)   */
1124
    /* and reserved_zero_4bits (4 bits) - Sushant        */
1125
    /*****************************************************/
1126
111k
    ih264d_get_bits_h264(ps_bitstrm, 5);
1127
    /* G050 */
1128
    /* Check whether particular profile is suported or not */
1129
    /* Check whether particular profile is suported or not */
1130
111k
    if((u1_profile_idc != MAIN_PROFILE_IDC) && (u1_profile_idc != BASE_PROFILE_IDC) &&
1131
111k
       (u1_profile_idc != HIGH_PROFILE_IDC))
1132
48.2k
    {
1133
        /* Apart from Baseline, main and high profile,
1134
         * only extended profile is supported provided
1135
         * uc_constraint_set0_flag or uc_constraint_set1_flag are set to 1
1136
         */
1137
48.2k
        if((u1_profile_idc != EXTENDED_PROFILE_IDC) ||
1138
48.2k
           ((uc_constraint_set1_flag != 1) && (uc_constraint_set0_flag != 1)))
1139
635
        {
1140
635
            return (ERROR_FEATURE_UNAVAIL);
1141
635
        }
1142
48.2k
    }
1143
1144
111k
    u1_level_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
1145
111k
    COPYTHECONTEXT("SPS: u4_level_idc", u1_level_idc);
1146
1147
111k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1148
111k
    if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
1149
110k
    u1_seq_parameter_set_id = u4_temp;
1150
110k
    COPYTHECONTEXT("SPS: seq_parameter_set_id", u1_seq_parameter_set_id);
1151
1152
    /*--------------------------------------------------------------------*/
1153
    /* Find an seq param entry in seqparam array of decStruct             */
1154
    /*--------------------------------------------------------------------*/
1155
110k
    ps_subset_seq = ps_svc_lyr_dec->pv_scratch_subset_sps;
1156
110k
    memset(ps_subset_seq, 0, sizeof(dec_svc_seq_params_t));
1157
110k
    ps_seq = ps_dec->pv_scratch_sps_pps;
1158
110k
    memset(ps_seq, 0, sizeof(dec_seq_params_t));
1159
1160
110k
    if((ps_dec->i4_header_decoded & 1) &&
1161
110k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1162
110k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_profile_idc != u1_profile_idc))
1163
539
    {
1164
539
        ps_dec->u1_res_changed = 1;
1165
539
        return IVD_RES_CHANGED;
1166
539
    }
1167
1168
110k
    if((ps_dec->i4_header_decoded & 1) &&
1169
110k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1170
110k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_level_idc != u1_level_idc))
1171
1.29k
    {
1172
1.29k
        ps_dec->u1_res_changed = 1;
1173
1.29k
        return IVD_RES_CHANGED;
1174
1.29k
    }
1175
1176
109k
    ps_seq->u1_profile_idc = u1_profile_idc;
1177
109k
    ps_seq->u1_level_idc = u1_level_idc;
1178
109k
    ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
1179
109k
    ps_subset_seq->ps_seq = &ps_dec->ps_sps[u1_seq_parameter_set_id];
1180
1181
    /*******************************************************************/
1182
    /* Initializations for high profile - Sushant                      */
1183
    /*******************************************************************/
1184
109k
    ps_seq->i4_chroma_format_idc = 1;
1185
109k
    ps_seq->i4_bit_depth_luma_minus8 = 0;
1186
109k
    ps_seq->i4_bit_depth_chroma_minus8 = 0;
1187
109k
    ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
1188
109k
    ps_seq->i4_seq_scaling_matrix_present_flag = 0;
1189
109k
    if(u1_profile_idc == HIGH_PROFILE_IDC || u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC ||
1190
109k
       u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC)
1191
4.45k
    {
1192
        /* reading chroma_format_idc   */
1193
4.45k
        ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1194
1195
        /* Monochrome is not supported */
1196
4.45k
        if(ps_seq->i4_chroma_format_idc != 1)
1197
117
        {
1198
117
            return ERROR_FEATURE_UNAVAIL;
1199
117
        }
1200
1201
        /* reading bit_depth_luma_minus8   */
1202
4.33k
        ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1203
1204
4.33k
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
1205
119
        {
1206
119
            return ERROR_FEATURE_UNAVAIL;
1207
119
        }
1208
1209
        /* reading bit_depth_chroma_minus8   */
1210
4.21k
        ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1211
1212
4.21k
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
1213
82
        {
1214
82
            return ERROR_FEATURE_UNAVAIL;
1215
82
        }
1216
1217
        /* reading qpprime_y_zero_transform_bypass_flag   */
1218
4.13k
        ps_seq->i4_qpprime_y_zero_transform_bypass_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1219
1220
4.13k
        if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
1221
66
        {
1222
66
            return ERROR_INV_SPS_PPS_T;
1223
66
        }
1224
1225
        /* reading seq_scaling_matrix_present_flag   */
1226
4.07k
        ps_seq->i4_seq_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1227
1228
4.07k
        if(ps_seq->i4_seq_scaling_matrix_present_flag)
1229
1.39k
        {
1230
11.5k
            for(i4_i = 0; i4_i < 8; i4_i++)
1231
10.4k
            {
1232
10.4k
                ps_seq->u1_seq_scaling_list_present_flag[i4_i] = ih264d_get_bit_h264(ps_bitstrm);
1233
1234
                /* initialize u1_use_default_scaling_matrix_flag[i4_i] to zero */
1235
                /* before calling scaling list                             */
1236
10.4k
                ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
1237
1238
10.4k
                if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
1239
2.58k
                {
1240
2.58k
                    if(i4_i < 6)
1241
2.04k
                    {
1242
2.04k
                        ret = ih264d_scaling_list(ps_seq->i2_scalinglist4x4[i4_i], 16,
1243
2.04k
                                                  &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
1244
2.04k
                                                  ps_bitstrm);
1245
2.04k
                    }
1246
533
                    else
1247
533
                    {
1248
533
                        ret = ih264d_scaling_list(ps_seq->i2_scalinglist8x8[i4_i - 6], 64,
1249
533
                                                  &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
1250
533
                                                  ps_bitstrm);
1251
533
                    }
1252
2.58k
                    if(ret != OK)
1253
253
                    {
1254
253
                        return ret;
1255
253
                    }
1256
2.58k
                }
1257
10.4k
            }
1258
1.39k
        }
1259
4.07k
    }
1260
    /*--------------------------------------------------------------------*/
1261
    /* Decode MaxFrameNum                                                 */
1262
    /*--------------------------------------------------------------------*/
1263
108k
    u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1264
108k
    if(u8_temp > MAX_BITS_IN_FRAME_NUM)
1265
135
    {
1266
135
        return ERROR_INV_SPS_PPS_T;
1267
135
    }
1268
108k
    ps_seq->u1_bits_in_frm_num = (UWORD8) u8_temp;
1269
108k
    COPYTHECONTEXT("SPS: log2_max_frame_num_minus4", (ps_seq->u1_bits_in_frm_num - 4));
1270
1271
108k
    i2_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
1272
108k
    ps_seq->u2_u4_max_pic_num_minus1 = i2_max_frm_num - 1;
1273
    /*--------------------------------------------------------------------*/
1274
    /* Decode picture order count and related values                      */
1275
    /*--------------------------------------------------------------------*/
1276
108k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1277
108k
    if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
1278
150
    {
1279
150
        return ERROR_INV_POC_TYPE_T;
1280
150
    }
1281
108k
    ps_seq->u1_pic_order_cnt_type = u4_temp;
1282
108k
    COPYTHECONTEXT("SPS: pic_order_cnt_type", ps_seq->u1_pic_order_cnt_type);
1283
1284
108k
    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
1285
108k
    if(ps_seq->u1_pic_order_cnt_type == 0)
1286
85.0k
    {
1287
85.0k
        u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1288
85.0k
        if(u8_temp > MAX_BITS_IN_POC_LSB)
1289
137
        {
1290
137
            return ERROR_INV_SPS_PPS_T;
1291
137
        }
1292
84.9k
        ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = (UWORD8) u8_temp;
1293
84.9k
        ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
1294
84.9k
        COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4", (u8_temp - 4));
1295
84.9k
    }
1296
23.0k
    else if(ps_seq->u1_pic_order_cnt_type == 1)
1297
21.9k
    {
1298
21.9k
        ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(ps_bitstrm);
1299
21.9k
        COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
1300
21.9k
                       ps_seq->u1_delta_pic_order_always_zero_flag);
1301
1302
21.9k
        ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1303
21.9k
        COPYTHECONTEXT("SPS: offset_for_non_ref_pic", ps_seq->i4_ofst_for_non_ref_pic);
1304
1305
21.9k
        ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1306
21.9k
        COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
1307
21.9k
                       ps_seq->i4_ofst_for_top_to_bottom_field);
1308
1309
21.9k
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1310
21.9k
        if(u4_temp > 255) return ERROR_INV_SPS_PPS_T;
1311
21.8k
        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
1312
21.8k
        COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
1313
21.8k
                       ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
1314
1315
50.2k
        for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
1316
28.4k
        {
1317
28.4k
            ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1318
28.4k
            COPYTHECONTEXT("SPS: offset_for_ref_frame", ps_seq->i4_ofst_for_ref_frame[i]);
1319
28.4k
        }
1320
21.8k
    }
1321
1322
107k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1323
1324
107k
    if((u4_temp > H264_MAX_REF_PICS))
1325
204
    {
1326
204
        return ERROR_NUM_REF;
1327
204
    }
1328
1329
    /* Compare with older num_ref_frames is header is already once */
1330
107k
    if((ps_dec->i4_header_decoded & 1) &&
1331
107k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1332
107k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_num_ref_frames != u4_temp))
1333
260
    {
1334
260
        ps_dec->u1_res_changed = 1;
1335
260
        return IVD_RES_CHANGED;
1336
260
    }
1337
1338
107k
    ps_seq->u1_num_ref_frames = u4_temp;
1339
107k
    COPYTHECONTEXT("SPS: num_ref_frames", ps_seq->u1_num_ref_frames);
1340
1341
107k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(ps_bitstrm);
1342
107k
    COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
1343
107k
                   ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
1344
1345
107k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = 0;
1346
1347
    /*--------------------------------------------------------------------*/
1348
    /* Decode FrameWidth and FrameHeight and related values               */
1349
    /*--------------------------------------------------------------------*/
1350
107k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1351
    /* Check  for unsupported resolutions*/
1352
107k
    if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
1353
151
    {
1354
151
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1355
151
    }
1356
107k
    u4_pic_width_in_mbs = (UWORD32) u8_temp;
1357
107k
    COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1", u4_pic_width_in_mbs - 1);
1358
1359
107k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1360
107k
    if(u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
1361
180
    {
1362
180
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1363
180
    }
1364
107k
    u4_pic_height_in_map_units = (UWORD32) u8_temp;
1365
1366
107k
    ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
1367
107k
    ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
1368
107k
    u2_pic_wd = (u4_pic_width_in_mbs << 4);
1369
107k
    u2_pic_ht = (u4_pic_height_in_map_units << 4);
1370
107k
    if(ps_svc_lyr_dec->pic_width < u2_pic_wd)
1371
15.4k
    {
1372
15.4k
        ps_svc_lyr_dec->pic_width = u2_pic_wd;
1373
15.4k
    }
1374
107k
    if(ps_svc_lyr_dec->pic_height < u2_pic_ht)
1375
15.5k
    {
1376
15.5k
        ps_svc_lyr_dec->pic_height = u2_pic_ht;
1377
15.5k
    }
1378
1379
    /*--------------------------------------------------------------------*/
1380
    /* Get the value of MaxMbAddress and Number of bits needed for it     */
1381
    /*--------------------------------------------------------------------*/
1382
107k
    ps_seq->u4_max_mb_addr = ((UWORD32)ps_seq->u2_frm_wd_in_mbs * (UWORD32)ps_seq->u2_frm_ht_in_mbs) - 1;
1383
107k
    ps_seq->u4_total_num_of_mbs = ps_seq->u4_max_mb_addr + 1;
1384
107k
    ps_seq->u1_level_idc = ih264d_correct_level_idc(u1_level_idc, ps_seq->u4_total_num_of_mbs);
1385
1386
107k
    u1_frm = ih264d_get_bit_h264(ps_bitstrm);
1387
107k
    if((ps_dec->i4_header_decoded & 1) &&
1388
107k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1389
107k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_frame_mbs_only_flag != u1_frm))
1390
4.58k
    {
1391
4.58k
        ps_dec->u1_res_changed = 1;
1392
4.58k
        return IVD_RES_CHANGED;
1393
4.58k
    }
1394
102k
    ps_seq->u1_frame_mbs_only_flag = u1_frm;
1395
102k
    COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
1396
1397
102k
    if(!u1_frm) u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
1398
1399
102k
    if((ps_dec->i4_header_decoded & 1) &&
1400
102k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1401
102k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_mb_aff_flag != u1_mb_aff_flag))
1402
128
    {
1403
128
        ps_dec->u1_res_changed = 1;
1404
128
        return IVD_RES_CHANGED;
1405
128
    }
1406
1407
102k
    if(!u1_frm)
1408
16.9k
    {
1409
16.9k
        u2_pic_ht <<= 1;
1410
16.9k
        ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
1411
16.9k
        COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag", ps_seq->u1_mb_aff_flag);
1412
16.9k
    }
1413
85.4k
    else
1414
85.4k
        ps_seq->u1_mb_aff_flag = 0;
1415
1416
102k
    ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
1417
102k
    COPYTHECONTEXT("SPS: direct_8x8_inference_flag", ps_seq->u1_direct_8x8_inference_flag);
1418
1419
    /* G050 */
1420
102k
    u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
1421
102k
    COPYTHECONTEXT("SPS: frame_cropping_flag", u1_frame_cropping_flag);
1422
1423
102k
    if(u1_frame_cropping_flag)
1424
15.1k
    {
1425
15.1k
        u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1426
15.1k
        COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset", u1_frame_cropping_rect_left_ofst);
1427
15.1k
        u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1428
15.1k
        COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset", u1_frame_cropping_rect_right_ofst);
1429
15.1k
        u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1430
15.1k
        COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset", u1_frame_cropping_rect_top_ofst);
1431
15.1k
        u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1432
15.1k
        COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
1433
15.1k
                       u1_frame_cropping_rect_bottom_ofst);
1434
15.1k
    }
1435
    /* G050 */
1436
102k
    ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1437
102k
    COPYTHECONTEXT("SPS: vui_parameters_present_flag", ps_seq->u1_vui_parameters_present_flag);
1438
1439
102k
    u2_frm_wd_y = u2_pic_wd + (UWORD8) (PAD_LEN_Y_H << 1);
1440
1441
102k
    if(1 == ps_dec->u4_share_disp_buf)
1442
0
    {
1443
0
        if(ps_dec->u4_app_disp_width > u2_frm_wd_y) u2_frm_wd_y = ps_dec->u4_app_disp_width;
1444
0
    }
1445
1446
102k
    u2_frm_ht_y = u2_pic_ht + (UWORD8) (PAD_LEN_Y_V << 2);
1447
102k
    u2_frm_wd_uv = u2_pic_wd + (UWORD8) (PAD_LEN_UV_H << 2);
1448
102k
    u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
1449
102k
    u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8) (PAD_LEN_UV_V << 2);
1450
102k
    u2_frm_ht_uv = MAX(u2_frm_ht_uv, (u2_frm_ht_y >> 1));
1451
1452
    /* Calculate display picture width, height and start u4_ofst from YUV420 */
1453
    /* pictute buffers as per cropping information parsed above             */
1454
102k
    {
1455
102k
        UWORD16 u2_rgt_ofst = 0;
1456
102k
        UWORD16 u2_lft_ofst = 0;
1457
102k
        UWORD16 u2_top_ofst = 0;
1458
102k
        UWORD16 u2_btm_ofst = 0;
1459
102k
        UWORD8 u1_frm_mbs_flag;
1460
102k
        UWORD8 u1_vert_mult_factor;
1461
1462
102k
        if(u1_frame_cropping_flag)
1463
15.1k
        {
1464
            /* Calculate right and left u4_ofst for cropped picture           */
1465
15.1k
            u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
1466
15.1k
            u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
1467
1468
            /* Know frame MBs only u4_flag                                      */
1469
15.1k
            u1_frm_mbs_flag = (1 == ps_seq->u1_frame_mbs_only_flag);
1470
1471
            /* Simplify the vertical u4_ofst calculation from field/frame     */
1472
15.1k
            u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
1473
1474
            /* Calculate bottom and top u4_ofst for cropped  picture          */
1475
15.1k
            u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst << u1_vert_mult_factor);
1476
15.1k
            u2_top_ofst = (u1_frame_cropping_rect_top_ofst << u1_vert_mult_factor);
1477
15.1k
        }
1478
1479
        /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
1480
        /* cropped picture buffer                                           */
1481
102k
        u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
1482
102k
        u2_crop_offset_uv =
1483
102k
            (u2_frm_wd_uv * (u2_top_ofst >> 1)) + (u2_lft_ofst >> 1) * YUV420SP_FACTOR;
1484
        /* Calculate the display picture width and height based on crop      */
1485
        /* information                                                       */
1486
102k
        i4_cropped_ht = (WORD32) u2_pic_ht - (WORD32) (u2_btm_ofst + u2_top_ofst);
1487
102k
        i4_cropped_wd = (WORD32) u2_pic_wd - (WORD32) (u2_rgt_ofst + u2_lft_ofst);
1488
1489
102k
        if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
1490
300
        {
1491
300
            return ERROR_INV_SPS_PPS_T;
1492
300
        }
1493
1494
102k
        if((ps_dec->i4_header_decoded & 1) &&
1495
102k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1496
102k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_wd != u2_pic_wd))
1497
365
        {
1498
365
            ps_dec->u1_res_changed = 1;
1499
365
            return IVD_RES_CHANGED;
1500
365
        }
1501
1502
101k
        if((ps_dec->i4_header_decoded & 1) &&
1503
101k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1504
101k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_width != i4_cropped_wd))
1505
90
        {
1506
90
            ps_dec->u1_res_changed = 1;
1507
90
            return IVD_RES_CHANGED;
1508
90
        }
1509
1510
101k
        if((ps_dec->i4_header_decoded & 1) &&
1511
101k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1512
101k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_ht != u2_pic_ht))
1513
393
        {
1514
393
            ps_dec->u1_res_changed = 1;
1515
393
            return IVD_RES_CHANGED;
1516
393
        }
1517
1518
101k
        if((ps_dec->i4_header_decoded & 1) &&
1519
101k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1520
101k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_height != i4_cropped_ht))
1521
131
        {
1522
131
            ps_dec->u1_res_changed = 1;
1523
131
            return IVD_RES_CHANGED;
1524
131
        }
1525
        /* Check again for unsupported resolutions with updated values*/
1526
101k
        if((u2_pic_wd > SVCD_MAX_FRAME_WIDTH) || (u2_pic_ht > SVCD_MAX_FRAME_HEIGHT) ||
1527
101k
           (u2_pic_wd < SVCD_MIN_FRAME_WIDTH) || (u2_pic_ht < SVCD_MIN_FRAME_HEIGHT) ||
1528
101k
           (u2_pic_wd * (UWORD32) u2_pic_ht > SVCD_MAX_FRAME_SIZE))
1529
481
        {
1530
481
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1531
481
        }
1532
1533
        /* If MBAff is enabled, decoder support is limited to streams with
1534
         * width less than half of H264_MAX_FRAME_WIDTH.
1535
         * In case of MBAff decoder processes two rows at a time
1536
         */
1537
100k
        if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
1538
70
        {
1539
70
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1540
70
        }
1541
100k
    }
1542
1543
    /* Backup num_reorder_frames if header is already decoded */
1544
100k
    if((ps_dec->i4_header_decoded & 1) && (1 == ps_seq->u1_vui_parameters_present_flag) &&
1545
100k
       (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1546
0
    {
1547
0
        num_reorder_frames = (WORD32) ps_seq->s_vui.u4_num_reorder_frames;
1548
0
    }
1549
100k
    else
1550
100k
    {
1551
100k
        num_reorder_frames = -1;
1552
100k
    }
1553
100k
    if(1 == ps_seq->u1_vui_parameters_present_flag)
1554
4.11k
    {
1555
4.11k
        ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
1556
4.11k
        if(ret != OK) return ret;
1557
4.11k
    }
1558
1559
    /* Compare older num_reorder_frames with the new one if header is already
1560
     * decoded */
1561
100k
    if((ps_dec->i4_header_decoded & 1) &&
1562
100k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) && (-1 != num_reorder_frames) &&
1563
100k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_vui_parameters_present_flag) &&
1564
100k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].s_vui.u1_bitstream_restriction_flag) &&
1565
100k
       ((WORD32) ps_dec->ps_sps[u1_seq_parameter_set_id].s_vui.u4_num_reorder_frames !=
1566
0
        num_reorder_frames))
1567
0
    {
1568
0
        ps_dec->u1_res_changed = 1;
1569
0
        return IVD_RES_CHANGED;
1570
0
    }
1571
1572
    /* In case bitstream read has exceeded the filled size, then return an error */
1573
100k
    if(EXCEED_OFFSET(ps_bitstrm))
1574
350
    {
1575
350
        return ERROR_INV_SPS_PPS_T;
1576
350
    }
1577
1578
    /*--------------------------------------------------------------------*/
1579
    /* All initializations to ps_dec are beyond this point                */
1580
    /*--------------------------------------------------------------------*/
1581
100k
    {
1582
100k
        WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
1583
100k
        if((1 == ps_seq->u1_vui_parameters_present_flag) &&
1584
100k
           (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1585
924
        {
1586
924
            reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
1587
924
        }
1588
1589
100k
        if(reorder_depth > H264_MAX_REF_PICS)
1590
68
        {
1591
68
            return ERROR_INV_SPS_PPS_T;
1592
68
        }
1593
1594
99.9k
        if(ps_seq->u1_frame_mbs_only_flag != 1) reorder_depth *= 2;
1595
99.9k
        ps_subset_seq->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
1596
99.9k
    }
1597
0
    ps_subset_seq->u2_disp_height = i4_cropped_ht;
1598
99.9k
    ps_subset_seq->u2_disp_width = i4_cropped_wd;
1599
99.9k
    ps_subset_seq->u2_pic_wd = u2_pic_wd;
1600
99.9k
    ps_subset_seq->u2_pic_ht = u2_pic_ht;
1601
1602
    /* Determining the Width and Height of Frame from that of Picture */
1603
99.9k
    ps_subset_seq->u2_frm_wd_y = u2_frm_wd_y;
1604
99.9k
    ps_subset_seq->u2_frm_ht_y = u2_frm_ht_y;
1605
99.9k
    ps_subset_seq->u2_frm_wd_uv = u2_frm_wd_uv;
1606
99.9k
    ps_subset_seq->u2_frm_ht_uv = u2_frm_ht_uv;
1607
1608
99.9k
    ps_subset_seq->u1_pad_len_y_v = (UWORD8) (PAD_LEN_Y_V << (1 - u1_frm));
1609
99.9k
    ps_subset_seq->u1_pad_len_cr_v = (UWORD8) (PAD_LEN_UV_V << (1 - u1_frm));
1610
1611
99.9k
    ps_subset_seq->u2_crop_offset_y = u2_crop_offset_y;
1612
99.9k
    ps_subset_seq->u2_crop_offset_uv = u2_crop_offset_uv;
1613
1614
99.9k
    ps_seq->u1_is_valid = TRUE;
1615
99.9k
    ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
1616
99.9k
    ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id] = *ps_subset_seq;
1617
99.9k
    ps_svc_lyr_dec->ps_cur_subset_sps = &ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id];
1618
1619
99.9k
    return OK;
1620
100k
}
1621
1622
/*!
1623
**************************************************************************
1624
* \if Function name : isvcd_parse_pps \endif
1625
*
1626
* \brief
1627
*    Decodes Picture Parameter set
1628
*
1629
* \return
1630
*    0 on Success and Error code otherwise
1631
**************************************************************************
1632
*/
1633
WORD32 isvcd_parse_pps(svc_dec_lyr_struct_t *ps_svc_lyr_dec, dec_bit_stream_t *ps_bitstrm)
1634
83.8k
{
1635
83.8k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1636
83.8k
    UWORD8 uc_temp;
1637
83.8k
    dec_seq_params_t *ps_sps = NULL;
1638
83.8k
    dec_pic_params_t *ps_pps = NULL;
1639
83.8k
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
1640
83.8k
    UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
1641
1642
    /* Variables used for error resilience checks */
1643
83.8k
    UWORD64 u8_temp;
1644
83.8k
    UWORD32 u4_temp;
1645
83.8k
    WORD32 i_temp;
1646
1647
    /* For High profile related syntax elements */
1648
83.8k
    UWORD8 u1_more_data_flag;
1649
83.8k
    WORD32 i4_i;
1650
1651
    /*--------------------------------------------------------------------*/
1652
    /* Decode pic_parameter_set_id and find corresponding pic params      */
1653
    /*--------------------------------------------------------------------*/
1654
83.8k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1655
83.8k
    if(u4_temp & MASK_ERR_PIC_SET_ID) return ERROR_INV_SPS_PPS_T;
1656
83.6k
    ps_pps = ps_dec->pv_scratch_sps_pps;
1657
83.6k
    *ps_pps = ps_dec->ps_pps[u4_temp];
1658
83.6k
    ps_pps->u1_pic_parameter_set_id = (UWORD8) u4_temp;
1659
83.6k
    COPYTHECONTEXT("PPS: pic_parameter_set_id", ps_pps->u1_pic_parameter_set_id);
1660
1661
    /************************************************/
1662
    /* initilization of High profile syntax element */
1663
    /************************************************/
1664
83.6k
    ps_pps->i4_transform_8x8_mode_flag = 0;
1665
83.6k
    ps_pps->i4_pic_scaling_matrix_present_flag = 0;
1666
1667
    /*--------------------------------------------------------------------*/
1668
    /* Decode seq_parameter_set_id and map it to a seq_parameter_set      */
1669
    /*--------------------------------------------------------------------*/
1670
83.6k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1671
83.6k
    if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
1672
83.4k
    COPYTHECONTEXT("PPS: seq_parameter_set_id", u4_temp);
1673
83.4k
    ps_sps = &ps_dec->ps_sps[u4_temp];
1674
83.4k
    ps_pps->ps_sps = ps_sps;
1675
1676
    /*--------------------------------------------------------------------*/
1677
    /* Decode entropy_coding_mode                                         */
1678
    /*--------------------------------------------------------------------*/
1679
83.4k
    ps_pps->u1_entropy_coding_mode = ih264d_get_bit_h264(ps_bitstrm);
1680
83.4k
    COPYTHECONTEXT("PPS: entropy_coding_mode_flag", ps_pps->u1_entropy_coding_mode);
1681
1682
83.4k
    ps_pps->u1_pic_order_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1683
83.4k
    COPYTHECONTEXT("PPS: pic_order_present_flag", ps_pps->u1_pic_order_present_flag);
1684
1685
    /*--------------------------------------------------------------------*/
1686
    /* Decode num_slice_groups_minus1                                     */
1687
    /*--------------------------------------------------------------------*/
1688
83.4k
    u8_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + (UWORD64) 1;
1689
83.4k
    if(u8_temp != 1)
1690
308
    {
1691
308
        return ERROR_FEATURE_UNAVAIL;
1692
308
    }
1693
83.1k
    ps_pps->u1_num_slice_groups = (UWORD8) u8_temp;
1694
83.1k
    COPYTHECONTEXT("PPS: num_slice_groups_minus1", ps_pps->u1_num_slice_groups - 1);
1695
1696
    /*--------------------------------------------------------------------*/
1697
    /* Other parameter set values                                         */
1698
    /*--------------------------------------------------------------------*/
1699
83.1k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1700
83.1k
    if(u8_temp >= H264_MAX_REF_IDX) return ERROR_REF_IDX;
1701
83.0k
    ps_pps->u1_num_ref_idx_lx_active[0] = (UWORD8) u8_temp;
1702
83.0k
    COPYTHECONTEXT("PPS: num_ref_idx_l0_active_minus1", ps_pps->u1_num_ref_idx_lx_active[0] - 1);
1703
1704
83.0k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1705
83.0k
    if(u8_temp >= H264_MAX_REF_IDX) return ERROR_REF_IDX;
1706
82.8k
    ps_pps->u1_num_ref_idx_lx_active[1] = (UWORD8) u8_temp;
1707
82.8k
    COPYTHECONTEXT("PPS: num_ref_idx_l1_active_minus1", ps_pps->u1_num_ref_idx_lx_active[1] - 1);
1708
1709
82.8k
    ps_pps->u1_wted_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
1710
82.8k
    COPYTHECONTEXT("PPS: weighted prediction u4_flag", ps_pps->u1_wted_pred_flag);
1711
82.8k
    uc_temp = (UWORD8) ih264d_get_bits_h264(ps_bitstrm, 2);
1712
82.8k
    COPYTHECONTEXT("PPS: weighted_bipred_idc", uc_temp);
1713
82.8k
    ps_pps->u1_wted_bipred_idc = uc_temp;
1714
1715
82.8k
    if(ps_pps->u1_wted_bipred_idc > MAX_WEIGHT_BIPRED_IDC) return ERROR_INV_SPS_PPS_T;
1716
1717
82.5k
    {
1718
82.5k
        WORD64 i8_temp = (WORD64) 26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1719
1720
82.5k
        if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP)) return ERROR_INV_RANGE_QP_T;
1721
1722
82.3k
        ps_pps->u1_pic_init_qp = (UWORD8) i8_temp;
1723
82.3k
        COPYTHECONTEXT("PPS: pic_init_qp_minus26", ps_pps->u1_pic_init_qp - 26);
1724
1725
82.3k
        i8_temp = (WORD64) 26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1726
82.3k
        if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP)) return ERROR_INV_RANGE_QP_T;
1727
1728
82.0k
        ps_pps->u1_pic_init_qs = (UWORD8) i8_temp;
1729
82.0k
        COPYTHECONTEXT("PPS: pic_init_qs_minus26", ps_pps->u1_pic_init_qs - 26);
1730
82.0k
    }
1731
1732
0
    i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1733
82.0k
    if((i_temp < -12) || (i_temp > 12)) return ERROR_INV_RANGE_QP_T;
1734
81.8k
    ps_pps->i1_chroma_qp_index_offset = i_temp;
1735
81.8k
    COPYTHECONTEXT("PPS: chroma_qp_index_offset", ps_pps->i1_chroma_qp_index_offset);
1736
1737
    /***************************************************************************/
1738
    /* initialize second_chroma_qp_index_offset to i1_chroma_qp_index_offset if */
1739
    /* second_chroma_qp_index_offset is not present in bit-ps_bitstrm */
1740
    /***************************************************************************/
1741
81.8k
    ps_pps->i1_second_chroma_qp_index_offset = ps_pps->i1_chroma_qp_index_offset;
1742
1743
81.8k
    ps_pps->u1_deblocking_filter_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1744
81.8k
    COPYTHECONTEXT("PPS: deblocking_filter_control_present_flag",
1745
81.8k
                   ps_pps->u1_deblocking_filter_parameters_present_flag);
1746
81.8k
    ps_pps->u1_constrained_intra_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
1747
81.8k
    COPYTHECONTEXT("PPS: constrained_intra_pred_flag", ps_pps->u1_constrained_intra_pred_flag);
1748
81.8k
    ps_pps->u1_redundant_pic_cnt_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1749
81.8k
    COPYTHECONTEXT("PPS: redundant_pic_cnt_present_flag",
1750
81.8k
                   ps_pps->u1_redundant_pic_cnt_present_flag);
1751
1752
    /* High profile related syntax elements */
1753
81.8k
    u1_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
1754
1755
81.8k
    if(u1_more_data_flag)
1756
79.3k
    {
1757
        /* read transform_8x8_mode_flag  */
1758
79.3k
        ps_pps->i4_transform_8x8_mode_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1759
1760
        /* read pic_scaling_matrix_present_flag */
1761
79.3k
        ps_pps->i4_pic_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1762
1763
79.3k
        if(ps_pps->i4_pic_scaling_matrix_present_flag)
1764
2.72k
        {
1765
            /* read the scaling matrices */
1766
19.8k
            for(i4_i = 0; i4_i < (6 + (ps_pps->i4_transform_8x8_mode_flag << 1)); i4_i++)
1767
17.4k
            {
1768
17.4k
                ps_pps->u1_pic_scaling_list_present_flag[i4_i] = ih264d_get_bit_h264(ps_bitstrm);
1769
1770
17.4k
                if(ps_pps->u1_pic_scaling_list_present_flag[i4_i])
1771
3.24k
                {
1772
3.24k
                    WORD32 ret;
1773
3.24k
                    if(i4_i < 6)
1774
2.62k
                    {
1775
2.62k
                        ret = ih264d_scaling_list(
1776
2.62k
                            ps_pps->i2_pic_scalinglist4x4[i4_i], 16,
1777
2.62k
                            &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i], ps_bitstrm);
1778
2.62k
                    }
1779
626
                    else
1780
626
                    {
1781
626
                        ret = ih264d_scaling_list(
1782
626
                            ps_pps->i2_pic_scalinglist8x8[i4_i - 6], 64,
1783
626
                            &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i], ps_bitstrm);
1784
626
                    }
1785
1786
3.24k
                    if(ret != OK)
1787
334
                    {
1788
334
                        return ret;
1789
334
                    }
1790
3.24k
                }
1791
17.4k
            }
1792
2.72k
        }
1793
1794
        /* read second_chroma_qp_index_offset syntax element */
1795
79.0k
        i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1796
79.0k
        if((i_temp < -12) || (i_temp > 12)) return ERROR_INV_RANGE_QP_T;
1797
1798
78.7k
        ps_pps->i1_second_chroma_qp_index_offset = i_temp;
1799
78.7k
    }
1800
1801
81.2k
    if(SCALABLE_BASELINE_PROFILE_IDC == ps_sps->u1_profile_idc)
1802
1803
0
    {
1804
0
        if(ps_pps->u1_num_slice_groups > 7)
1805
0
        {
1806
0
            return ERROR_INV_SPS_PPS_T;
1807
0
        }
1808
0
    }
1809
1810
    /* In case bitstream read has exceeded the filled size, then return an error */
1811
81.2k
    if(EXCEED_OFFSET(ps_bitstrm))
1812
128
    {
1813
128
        return ERROR_INV_SPS_PPS_T;
1814
128
    }
1815
81.1k
    ps_pps->u1_is_valid = TRUE;
1816
81.1k
    ps_dec->ps_pps[ps_pps->u1_pic_parameter_set_id] = *ps_pps;
1817
81.1k
    return OK;
1818
81.2k
}