Coverage Report

Created: 2026-07-16 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/svc/isvcd_parse_headers.c
Line
Count
Source
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
20.2k
{
98
20.2k
    ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag = 0;
99
20.2k
    ps_seq_svc_ext->u1_extended_spatial_scalability_idc = 0;
100
20.2k
    ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag = 1;
101
20.2k
    ps_seq_svc_ext->u1_chroma_phase_y_plus1 = 1;
102
20.2k
    ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
103
20.2k
        ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag;
104
20.2k
    ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 = ps_seq_svc_ext->u1_chroma_phase_y_plus1;
105
20.2k
    ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset = 0;
106
20.2k
    ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset = 0;
107
20.2k
    ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset = 0;
108
20.2k
    ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset = 0;
109
20.2k
    ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag =
110
20.2k
        ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag = 0;
111
20.2k
    ps_seq_svc_ext->u1_slice_header_restriction_flag = 0;
112
20.2k
    ps_seq_svc_ext->u1_svc_vui_parameters_present_flag = 0;
113
20.2k
}
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
24.7k
{
128
24.7k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
129
24.7k
    UWORD8 i;
130
24.7k
    dec_seq_params_t *ps_seq = NULL;
131
24.7k
    dec_svc_seq_params_t *ps_subset_seq = NULL;
132
24.7k
    dec_subset_seq_params_t *ps_seq_svc_ext;
133
24.7k
    UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
134
24.7k
    UWORD16 i2_max_frm_num;
135
24.7k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
136
24.7k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
137
24.7k
    UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag, uc_constraint_set2_flag;
138
24.7k
    WORD32 i4_cropped_ht, i4_cropped_wd;
139
24.7k
    UWORD32 u4_temp;
140
24.7k
    UWORD64 u8_temp;
141
24.7k
    UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
142
24.7k
    UWORD32 u2_pic_wd = 0;
143
24.7k
    UWORD32 u2_pic_ht = 0;
144
24.7k
    UWORD32 u2_frm_wd_y = 0;
145
24.7k
    UWORD32 u2_frm_ht_y = 0;
146
24.7k
    UWORD32 u2_frm_wd_uv = 0;
147
24.7k
    UWORD32 u2_frm_ht_uv = 0;
148
24.7k
    UWORD32 u2_crop_offset_y = 0;
149
24.7k
    UWORD32 u2_crop_offset_uv = 0;
150
24.7k
    WORD32 ret;
151
    /* High profile related syntax element */
152
24.7k
    WORD32 i4_i;
153
    /* G050 */
154
24.7k
    UWORD8 u1_frame_cropping_flag,
155
24.7k
        u1_frame_cropping_rect_left_ofst = 0, u1_frame_cropping_rect_right_ofst = 0,
156
24.7k
        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
24.7k
    SWITCHONTRACE;
162
24.7k
    u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
163
24.7k
    COPYTHECONTEXT("SPS: profile_idc", u1_profile_idc);
164
165
    /* G050 */
166
24.7k
    uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
167
24.7k
    uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
168
24.7k
    uc_constraint_set2_flag = ih264d_get_bit_h264(ps_bitstrm);
169
24.7k
    UNUSED(uc_constraint_set1_flag);
170
24.7k
    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
24.7k
    ih264d_get_bits_h264(ps_bitstrm, 5);
177
    /* G050 */
178
24.7k
    u1_level_idc = (UWORD8) ih264d_get_bits_h264(ps_bitstrm, 8);
179
24.7k
    COPYTHECONTEXT("SPS: u4_level_idc", u1_level_idc);
180
181
24.7k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
182
24.7k
    if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
183
24.2k
    u1_seq_parameter_set_id = u4_temp;
184
24.2k
    COPYTHECONTEXT("SPS: seq_parameter_set_id", u1_seq_parameter_set_id);
185
186
24.2k
    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
24.2k
    ps_subset_seq = ps_svc_lyr_dec->pv_scratch_subset_sps;
192
24.2k
    memset(ps_subset_seq, 0, sizeof(dec_svc_seq_params_t));
193
24.2k
    ps_seq = ps_dec->pv_scratch_sps_pps;
194
24.2k
    memset(ps_seq, 0, sizeof(dec_seq_params_t));
195
196
24.2k
    ps_seq->u1_profile_idc = u1_profile_idc;
197
24.2k
    ps_seq->u1_level_idc = u1_level_idc;
198
24.2k
    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
24.2k
    u1_seq_parameter_set_id += MAX_NUM_SEQ_PARAMS;
202
24.2k
    ps_subset_seq->ps_seq = &ps_dec->ps_sps[u1_seq_parameter_set_id];
203
204
24.2k
    if((ps_dec->i4_header_decoded & 1) &&
205
12.0k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
206
10.7k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_profile_idc != u1_profile_idc))
207
295
    {
208
295
        ps_dec->u1_res_changed = 1;
209
295
        return IVD_RES_CHANGED;
210
295
    }
211
212
23.9k
    if((ps_dec->i4_header_decoded & 1) &&
213
11.7k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
214
10.4k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_level_idc != u1_level_idc))
215
165
    {
216
165
        ps_dec->u1_res_changed = 1;
217
165
        return IVD_RES_CHANGED;
218
165
    }
219
    /*******************************************************************/
220
    /* Initializations for high profile - Sushant                      */
221
    /*******************************************************************/
222
23.7k
    ps_seq->i4_chroma_format_idc = 1;
223
23.7k
    ps_seq->i4_bit_depth_luma_minus8 = 0;
224
23.7k
    ps_seq->i4_bit_depth_chroma_minus8 = 0;
225
23.7k
    ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
226
23.7k
    ps_seq->i4_seq_scaling_matrix_present_flag = 0;
227
23.7k
    if(u1_profile_idc == HIGH_PROFILE_IDC || u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC ||
228
21.2k
       u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC)
229
5.63k
    {
230
        /* reading chroma_format_idc   */
231
5.63k
        ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
232
233
        /* Monochrome is not supported */
234
5.63k
        if(ps_seq->i4_chroma_format_idc != 1)
235
249
        {
236
249
            return ERROR_FEATURE_UNAVAIL;
237
249
        }
238
239
        /* reading bit_depth_luma_minus8   */
240
5.39k
        ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
241
242
5.39k
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
243
78
        {
244
78
            return ERROR_FEATURE_UNAVAIL;
245
78
        }
246
247
        /* reading bit_depth_chroma_minus8   */
248
5.31k
        ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
249
250
5.31k
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
251
81
        {
252
81
            return ERROR_FEATURE_UNAVAIL;
253
81
        }
254
255
        /* reading qpprime_y_zero_transform_bypass_flag   */
256
5.23k
        ps_seq->i4_qpprime_y_zero_transform_bypass_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
257
258
5.23k
        if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
259
70
        {
260
70
            return ERROR_INV_SPS_PPS_T;
261
70
        }
262
263
        /* reading seq_scaling_matrix_present_flag   */
264
5.16k
        ps_seq->i4_seq_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
265
266
5.16k
        if(ps_seq->i4_seq_scaling_matrix_present_flag)
267
3.57k
        {
268
31.1k
            for(i4_i = 0; i4_i < 8; i4_i++)
269
27.7k
            {
270
27.7k
                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
27.7k
                ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
275
276
27.7k
                if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
277
13.3k
                {
278
13.3k
                    if(i4_i < 6)
279
10.2k
                    {
280
10.2k
                        ret = ih264d_scaling_list(ps_seq->i2_scalinglist4x4[i4_i], 16,
281
10.2k
                                                  &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
282
10.2k
                                                  ps_bitstrm);
283
10.2k
                    }
284
3.10k
                    else
285
3.10k
                    {
286
3.10k
                        ret = ih264d_scaling_list(ps_seq->i2_scalinglist8x8[i4_i - 6], 64,
287
3.10k
                                                  &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
288
3.10k
                                                  ps_bitstrm);
289
3.10k
                    }
290
13.3k
                    if(ret != OK)
291
210
                    {
292
210
                        return ret;
293
210
                    }
294
13.3k
                }
295
27.7k
            }
296
3.57k
        }
297
5.16k
    }
298
    /*--------------------------------------------------------------------*/
299
    /* Decode MaxFrameNum                                                 */
300
    /*--------------------------------------------------------------------*/
301
23.0k
    u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
302
23.0k
    if(u8_temp > MAX_BITS_IN_FRAME_NUM)
303
210
    {
304
210
        return ERROR_INV_SPS_PPS_T;
305
210
    }
306
22.8k
    ps_seq->u1_bits_in_frm_num = (UWORD8) u8_temp;
307
22.8k
    COPYTHECONTEXT("SPS: log2_max_frame_num_minus4", (ps_seq->u1_bits_in_frm_num - 4));
308
309
22.8k
    i2_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
310
22.8k
    ps_seq->u2_u4_max_pic_num_minus1 = i2_max_frm_num - 1;
311
    /*--------------------------------------------------------------------*/
312
    /* Decode picture order count and related values                      */
313
    /*--------------------------------------------------------------------*/
314
22.8k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
315
316
22.8k
    if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
317
197
    {
318
197
        return ERROR_INV_POC_TYPE_T;
319
197
    }
320
22.6k
    ps_seq->u1_pic_order_cnt_type = u4_temp;
321
22.6k
    COPYTHECONTEXT("SPS: pic_order_cnt_type", ps_seq->u1_pic_order_cnt_type);
322
323
22.6k
    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
324
22.6k
    if(ps_seq->u1_pic_order_cnt_type == 0)
325
17.1k
    {
326
17.1k
        u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
327
17.1k
        if(u8_temp > MAX_BITS_IN_POC_LSB)
328
132
        {
329
132
            return ERROR_INV_SPS_PPS_T;
330
132
        }
331
17.0k
        ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = (UWORD8) u8_temp;
332
17.0k
        ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
333
17.0k
        COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4", (u8_temp - 4));
334
17.0k
    }
335
5.46k
    else if(ps_seq->u1_pic_order_cnt_type == 1)
336
2.73k
    {
337
2.73k
        ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(ps_bitstrm);
338
2.73k
        COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
339
2.73k
                       ps_seq->u1_delta_pic_order_always_zero_flag);
340
341
2.73k
        ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
342
2.73k
        COPYTHECONTEXT("SPS: offset_for_non_ref_pic", ps_seq->i4_ofst_for_non_ref_pic);
343
344
2.73k
        ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
345
2.73k
        COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
346
2.73k
                       ps_seq->i4_ofst_for_top_to_bottom_field);
347
348
2.73k
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
349
2.73k
        if(u4_temp > 255) return ERROR_INV_SPS_PPS_T;
350
2.60k
        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
351
2.60k
        COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
352
2.60k
                       ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
353
354
18.9k
        for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
355
16.3k
        {
356
16.3k
            ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
357
16.3k
            COPYTHECONTEXT("SPS: offset_for_ref_frame", ps_seq->i4_ofst_for_ref_frame[i]);
358
16.3k
        }
359
2.60k
    }
360
361
22.3k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
362
363
22.3k
    if((u4_temp > H264_MAX_REF_PICS))
364
170
    {
365
170
        return ERROR_NUM_REF;
366
170
    }
367
368
    /* Compare with older num_ref_frames is header is already once */
369
22.2k
    if((ps_dec->i4_header_decoded & 1) &&
370
11.4k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
371
10.2k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_num_ref_frames != u4_temp))
372
83
    {
373
83
        ps_dec->u1_res_changed = 1;
374
83
        return IVD_RES_CHANGED;
375
83
    }
376
22.1k
    ps_seq->u1_num_ref_frames = u4_temp;
377
22.1k
    COPYTHECONTEXT("SPS: num_ref_frames", ps_seq->u1_num_ref_frames);
378
379
22.1k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(ps_bitstrm);
380
22.1k
    COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
381
22.1k
                   ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
382
    /* SVC_DEC_REVIEW */
383
22.1k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = 0;
384
385
    /*--------------------------------------------------------------------*/
386
    /* Decode FrameWidth and FrameHeight and related values               */
387
    /*--------------------------------------------------------------------*/
388
22.1k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
389
    /* Check  for unsupported resolutions*/
390
22.1k
    if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
391
183
    {
392
183
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
393
183
    }
394
21.9k
    u4_pic_width_in_mbs = (UWORD32) u8_temp;
395
21.9k
    COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1", u4_pic_width_in_mbs - 1);
396
397
21.9k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
398
21.9k
    if(u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
399
172
    {
400
172
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
401
172
    }
402
21.7k
    u4_pic_height_in_map_units = (UWORD32) u8_temp;
403
404
21.7k
    ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
405
21.7k
    ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
406
407
21.7k
    u2_pic_wd = (u4_pic_width_in_mbs << 4);
408
21.7k
    u2_pic_ht = (u4_pic_height_in_map_units << 4);
409
21.7k
    if(ps_svc_lyr_dec->pic_width < u2_pic_wd)
410
7.58k
    {
411
7.58k
        ps_svc_lyr_dec->pic_width = u2_pic_wd;
412
7.58k
    }
413
21.7k
    if(ps_svc_lyr_dec->pic_height < u2_pic_ht)
414
7.62k
    {
415
7.62k
        ps_svc_lyr_dec->pic_height = u2_pic_ht;
416
7.62k
    }
417
418
    /*--------------------------------------------------------------------*/
419
    /* Get the value of MaxMbAddress and Number of bits needed for it     */
420
    /*--------------------------------------------------------------------*/
421
21.7k
    ps_seq->u4_max_mb_addr = (ps_seq->u2_frm_wd_in_mbs * ps_seq->u2_frm_ht_in_mbs) - 1;
422
423
21.7k
    ps_seq->u4_total_num_of_mbs = ps_seq->u4_max_mb_addr + 1;
424
425
21.7k
    ps_seq->u1_level_idc = ih264d_correct_level_idc(u1_level_idc, ps_seq->u4_total_num_of_mbs);
426
427
21.7k
    u1_frm = ih264d_get_bit_h264(ps_bitstrm);
428
429
21.7k
    if((ps_dec->i4_header_decoded & 1) &&
430
11.3k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
431
10.1k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_frame_mbs_only_flag != u1_frm))
432
118
    {
433
118
        ps_dec->u1_res_changed = 1;
434
118
        return IVD_RES_CHANGED;
435
118
    }
436
21.6k
    ps_seq->u1_frame_mbs_only_flag = u1_frm;
437
438
21.6k
    COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
439
440
21.6k
    if(!u1_frm) u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
441
21.6k
    if((ps_dec->i4_header_decoded & 1) &&
442
11.2k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
443
10.0k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_mb_aff_flag != u1_mb_aff_flag))
444
115
    {
445
115
        ps_dec->u1_res_changed = 1;
446
115
        return IVD_RES_CHANGED;
447
115
    }
448
21.5k
    if(!u1_frm)
449
4.64k
    {
450
4.64k
        u2_pic_ht <<= 1;
451
4.64k
        ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
452
4.64k
        COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag", ps_seq->u1_mb_aff_flag);
453
4.64k
    }
454
16.9k
    else
455
16.9k
        ps_seq->u1_mb_aff_flag = 0;
456
457
21.5k
    ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
458
459
21.5k
    COPYTHECONTEXT("SPS: direct_8x8_inference_flag", ps_seq->u1_direct_8x8_inference_flag);
460
461
    /* G050 */
462
21.5k
    u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
463
21.5k
    COPYTHECONTEXT("SPS: frame_cropping_flag", u1_frame_cropping_flag);
464
465
21.5k
    if(u1_frame_cropping_flag)
466
6.07k
    {
467
6.07k
        u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
468
6.07k
        COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset", u1_frame_cropping_rect_left_ofst);
469
6.07k
        u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
470
6.07k
        COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset", u1_frame_cropping_rect_right_ofst);
471
6.07k
        u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
472
6.07k
        COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset", u1_frame_cropping_rect_top_ofst);
473
6.07k
        u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
474
6.07k
        COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
475
6.07k
                       u1_frame_cropping_rect_bottom_ofst);
476
6.07k
    }
477
    /* G050 */
478
21.5k
    ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
479
21.5k
    COPYTHECONTEXT("SPS: vui_parameters_present_flag", ps_seq->u1_vui_parameters_present_flag);
480
481
21.5k
    u2_frm_wd_y = u2_pic_wd + (UWORD8) (PAD_LEN_Y_H << 1);
482
21.5k
    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
21.5k
    u2_frm_ht_y = u2_pic_ht + (UWORD8) (PAD_LEN_Y_V << 2);
488
21.5k
    u2_frm_wd_uv = u2_pic_wd + (UWORD8) (PAD_LEN_UV_H << 2);
489
21.5k
    u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
490
491
21.5k
    u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8) (PAD_LEN_UV_V << 2);
492
21.5k
    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
21.5k
    {
497
21.5k
        UWORD16 u2_rgt_ofst = 0;
498
21.5k
        UWORD16 u2_lft_ofst = 0;
499
21.5k
        UWORD16 u2_top_ofst = 0;
500
21.5k
        UWORD16 u2_btm_ofst = 0;
501
21.5k
        UWORD8 u1_frm_mbs_flag;
502
21.5k
        UWORD8 u1_vert_mult_factor;
503
504
21.5k
        if(u1_frame_cropping_flag)
505
6.07k
        {
506
            /* Calculate right and left u4_ofst for cropped picture           */
507
6.07k
            u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
508
6.07k
            u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
509
510
            /* Know frame MBs only u4_flag                                      */
511
6.07k
            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.07k
            u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
515
516
            /* Calculate bottom and top u4_ofst for cropped  picture          */
517
6.07k
            u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst << u1_vert_mult_factor);
518
6.07k
            u2_top_ofst = (u1_frame_cropping_rect_top_ofst << u1_vert_mult_factor);
519
6.07k
        }
520
521
        /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
522
        /* cropped picture buffer                                           */
523
21.5k
        u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
524
21.5k
        u2_crop_offset_uv =
525
21.5k
            (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
21.5k
        i4_cropped_ht = (WORD32) u2_pic_ht - (WORD32) (u2_btm_ofst + u2_top_ofst);
529
21.5k
        i4_cropped_wd = (WORD32) u2_pic_wd - (WORD32) (u2_rgt_ofst + u2_lft_ofst);
530
531
21.5k
        if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
532
256
        {
533
256
            return ERROR_INV_SPS_PPS_T;
534
256
        }
535
536
21.3k
        if((ps_dec->i4_header_decoded & 1) &&
537
11.0k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
538
9.93k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_wd != u2_pic_wd))
539
84
        {
540
84
            ps_dec->u1_res_changed = 1;
541
84
            return IVD_RES_CHANGED;
542
84
        }
543
544
21.2k
        if((ps_dec->i4_header_decoded & 1) &&
545
11.0k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
546
9.85k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_width != i4_cropped_wd))
547
76
        {
548
76
            ps_dec->u1_res_changed = 1;
549
76
            return IVD_RES_CHANGED;
550
76
        }
551
552
21.1k
        if((ps_dec->i4_header_decoded & 1) &&
553
10.9k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
554
9.77k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_ht != u2_pic_ht))
555
93
        {
556
93
            ps_dec->u1_res_changed = 1;
557
93
            return IVD_RES_CHANGED;
558
93
        }
559
560
21.0k
        if((ps_dec->i4_header_decoded & 1) &&
561
10.8k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
562
9.68k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_height != i4_cropped_ht))
563
67
        {
564
67
            ps_dec->u1_res_changed = 1;
565
67
            return IVD_RES_CHANGED;
566
67
        }
567
        /* Check again for unsupported resolutions with updated values*/
568
20.9k
        if((u2_pic_wd > SVCD_MAX_FRAME_WIDTH) || (u2_pic_ht > SVCD_MAX_FRAME_HEIGHT) ||
569
20.8k
           (u2_pic_wd < SVCD_MIN_FRAME_WIDTH) || (u2_pic_ht < SVCD_MIN_FRAME_HEIGHT) ||
570
20.6k
           (u2_pic_wd * (UWORD32) u2_pic_ht > SVCD_MAX_FRAME_SIZE))
571
361
        {
572
361
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
573
361
        }
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
20.6k
        if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
580
128
        {
581
128
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
582
128
        }
583
20.6k
    }
584
585
20.4k
    if(1 == ps_seq->u1_vui_parameters_present_flag)
586
4.11k
    {
587
4.11k
        ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
588
4.11k
        if(ret != OK) return ret;
589
4.11k
    }
590
20.2k
    ps_seq_svc_ext = &ps_subset_seq->s_sps_svc_ext;
591
592
20.2k
    isvcd_set_default_seq_svc_ext(ps_seq_svc_ext);
593
594
20.2k
    if(SCALABLE_BASELINE_PROFILE_IDC == ps_seq->u1_profile_idc ||
595
18.2k
       SCALABLE_HIGH_PROFILE_IDC == ps_seq->u1_profile_idc)
596
4.64k
    {
597
4.64k
        SWITCHONTRACE;
598
4.64k
        ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag =
599
4.64k
            ih264d_get_bit_h264(ps_bitstrm);
600
4.64k
        COPYTHECONTEXT("SPS_EXt: u1_inter_layer_deblocking_filter_control_present_flag",
601
4.64k
                       ps_seq_svc_ext->u1_inter_layer_deblocking_filter_control_present_flag);
602
603
4.64k
        ps_seq_svc_ext->u1_extended_spatial_scalability_idc = ih264d_get_bits_h264(ps_bitstrm, 2);
604
4.64k
        COPYTHECONTEXT("SPS_EXt: u1_extended_spatial_scalability_idc",
605
4.64k
                       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.64k
        if(ps_seq_svc_ext->u1_extended_spatial_scalability_idc > 2)
609
107
        {
610
107
            return ERROR_SVC_INV_SUBSET_SPS;
611
107
        }
612
613
        /* ChromaArrayType = i4_chroma_format_idc  if  separate_colour_plane_flag =
614
         * 0 for all chroma format except 4:4:4 */
615
4.54k
        if(1 == ps_seq->i4_chroma_format_idc || 2 == ps_seq->i4_chroma_format_idc)
616
4.54k
        {
617
4.54k
            ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag = ih264d_get_bit_h264(ps_bitstrm);
618
4.54k
            COPYTHECONTEXT("SPS_EXt: u1_chroma_phase_x_plus1_flag",
619
4.54k
                           ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag);
620
4.54k
        }
621
622
4.54k
        if(1 == ps_seq->i4_chroma_format_idc)
623
4.54k
        {
624
4.54k
            ps_seq_svc_ext->u1_chroma_phase_y_plus1 = ih264d_get_bits_h264(ps_bitstrm, 2);
625
4.54k
            COPYTHECONTEXT("SPS_EXt: u1_chroma_phase_y_plus1",
626
4.54k
                           ps_seq_svc_ext->u1_chroma_phase_y_plus1);
627
628
4.54k
            if(ps_seq_svc_ext->u1_chroma_phase_y_plus1 >= 3)
629
69
            {
630
69
                return ERROR_SVC_INV_SUBSET_SPS;
631
69
            }
632
4.54k
        }
633
634
        /* inferred values not covered in isvcd_set_default_seq_svc_ext*/
635
4.47k
        ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
636
4.47k
            ps_seq_svc_ext->u1_chroma_phase_x_plus1_flag;
637
4.47k
        ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 =
638
4.47k
            ps_seq_svc_ext->u1_chroma_phase_y_plus1;
639
640
4.47k
        if(1 == ps_seq_svc_ext->u1_extended_spatial_scalability_idc)
641
1.43k
        {
642
1.43k
            if(ps_seq->i4_chroma_format_idc > 0)
643
1.43k
            {
644
1.43k
                ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag =
645
1.43k
                    ih264d_get_bit_h264(ps_bitstrm);
646
1.43k
                COPYTHECONTEXT("SPS_EXt: u1_seq_ref_layer_chroma_phase_x_plus1_flag",
647
1.43k
                               ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_x_plus1_flag);
648
649
1.43k
                ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 =
650
1.43k
                    ih264d_get_bits_h264(ps_bitstrm, 2);
651
1.43k
                COPYTHECONTEXT("SPS_EXt: u1_seq_ref_layer_chroma_phase_y_plus1",
652
1.43k
                               ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1);
653
654
1.43k
                if(ps_seq_svc_ext->u1_seq_ref_layer_chroma_phase_y_plus1 >= 3)
655
68
                {
656
68
                    return ERROR_SVC_INV_SUBSET_SPS;
657
68
                }
658
1.43k
            }
659
660
1.36k
            ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset =
661
1.36k
                ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
662
1.36k
            COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_left_offset",
663
1.36k
                           ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset);
664
665
1.36k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset != 0)
666
131
            {
667
131
                return ERROR_SVC_INV_SUBSET_SPS;
668
131
            }
669
670
1.23k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
671
1.23k
               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.23k
            ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset =
677
1.23k
                ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
678
1.23k
            COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_top_offset",
679
1.23k
                           ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset);
680
681
1.23k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset != 0)
682
133
            {
683
133
                return ERROR_SVC_INV_SUBSET_SPS;
684
133
            }
685
686
1.10k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
687
1.10k
               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.10k
            ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset =
693
1.10k
                ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
694
1.10k
            COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_right_offset",
695
1.10k
                           ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset);
696
697
1.10k
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
698
1.01k
               ps_seq_svc_ext->i4_seq_scaled_ref_layer_right_offset < MIN_SCLD_REF_LAYER_OFFSET)
699
161
            {
700
161
                return ERROR_SVC_INV_SUBSET_SPS;
701
161
            }
702
703
940
            ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset =
704
940
                ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
705
940
            COPYTHECONTEXT("SPS_EXt: i4_seq_scaled_ref_layer_bottom_offset",
706
940
                           ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset);
707
708
940
            if(ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset >= MAX_SCLD_REF_LAYER_OFFSET ||
709
839
               ps_seq_svc_ext->i4_seq_scaled_ref_layer_bottom_offset < MIN_SCLD_REF_LAYER_OFFSET)
710
196
            {
711
196
                return ERROR_INV_SLICE_HDR_T;
712
196
            }
713
940
        }
714
715
3.78k
        ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag = ih264d_get_bit_h264(ps_bitstrm);
716
3.78k
        COPYTHECONTEXT("SPS_EXt: u1_seq_tcoeff_level_prediction_flag",
717
3.78k
                       ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag);
718
719
3.78k
        if(1 == ps_seq_svc_ext->u1_seq_tcoeff_level_prediction_flag)
720
2.56k
        {
721
2.56k
            ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag =
722
2.56k
                ih264d_get_bit_h264(ps_bitstrm);
723
2.56k
            COPYTHECONTEXT("SPS_EXt: u1_adaptive_tcoeff_level_prediction_flag",
724
2.56k
                           ps_seq_svc_ext->u1_adaptive_tcoeff_level_prediction_flag);
725
2.56k
        }
726
727
3.78k
        ps_seq_svc_ext->u1_slice_header_restriction_flag = ih264d_get_bit_h264(ps_bitstrm);
728
3.78k
        COPYTHECONTEXT("SPS_EXt: u1_slice_header_restriction_flag",
729
3.78k
                       ps_seq_svc_ext->u1_slice_header_restriction_flag);
730
731
3.78k
        ps_seq_svc_ext->u1_svc_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
732
3.78k
        COPYTHECONTEXT("SPS_EXt: u1_svc_vui_parameters_present_flag",
733
3.78k
                       ps_seq_svc_ext->u1_svc_vui_parameters_present_flag);
734
735
3.78k
        if(1 == ps_seq_svc_ext->u1_svc_vui_parameters_present_flag)
736
1.25k
        {
737
1.25k
            if(NULL ==
738
1.25k
               ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext)
739
446
            {
740
446
                void *pv_buf;
741
446
                UWORD32 size;
742
                /* Memory allocation only if VUI is enabled in a particular subset SPS*/
743
446
                size = sizeof(svc_vui_ext_t);
744
446
                pv_buf = ps_dec->pf_aligned_alloc(ps_dec->pv_mem_ctxt, 128, size);
745
446
                RETURN_IF((NULL == pv_buf), IV_FAIL);
746
446
                memset(pv_buf, 0, size);
747
446
                ps_seq_svc_ext->ps_svc_vui_ext = pv_buf;
748
446
                ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id]
749
446
                    .s_sps_svc_ext.ps_svc_vui_ext = pv_buf;
750
446
            }
751
809
            else
752
809
            {
753
809
                ps_seq_svc_ext->ps_svc_vui_ext =
754
809
                    ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id]
755
809
                        .s_sps_svc_ext.ps_svc_vui_ext;
756
809
            }
757
1.25k
            ret = isvcd_parse_vui_ext_parametres(ps_seq_svc_ext->ps_svc_vui_ext, ps_bitstrm);
758
1.25k
            if(ret != OK) return ret;
759
1.25k
        }
760
3.78k
    }
761
    /* Add conditions for SCALABLE BASELINE PROFILE */
762
19.0k
    if(SCALABLE_BASELINE_PROFILE_IDC == ps_seq->u1_profile_idc ||
763
17.2k
       ((SCALABLE_HIGH_PROFILE_IDC == ps_seq->u1_profile_idc) && (1 == uc_constraint_set0_flag)))
764
2.08k
    {
765
2.08k
        if(ps_seq->i4_chroma_format_idc != 1)
766
0
        {
767
0
            return ERROR_FEATURE_UNAVAIL;
768
0
        }
769
770
2.08k
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
771
0
        {
772
0
            return ERROR_FEATURE_UNAVAIL;
773
0
        }
774
775
2.08k
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
776
0
        {
777
0
            return ERROR_FEATURE_UNAVAIL;
778
0
        }
779
780
2.08k
        if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
781
0
        {
782
0
            return ERROR_FEATURE_UNAVAIL;
783
0
        }
784
785
2.08k
        if(ps_seq->u1_frame_mbs_only_flag != 1)
786
210
        {
787
210
            return ERROR_FEATURE_UNAVAIL;
788
210
        }
789
790
1.87k
        if((0 != ps_seq_svc_ext->i4_seq_scaled_ref_layer_left_offset % 16) &&
791
0
           (0 != ps_seq_svc_ext->i4_seq_scaled_ref_layer_top_offset % 16))
792
0
        {
793
0
            return ERROR_FEATURE_UNAVAIL;
794
0
        }
795
1.87k
    }
796
    /* Compare older num_reorder_frames with the new one if header is already
797
     * decoded */
798
18.8k
    if((ps_dec->i4_header_decoded & 1) &&
799
10.7k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
800
9.61k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_vui_parameters_present_flag) &&
801
1.38k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].s_vui.u1_bitstream_restriction_flag))
802
76
    {
803
76
        ps_dec->u1_res_changed = 1;
804
76
        return IVD_RES_CHANGED;
805
76
    }
806
    /* In case bitstream read has exceeded the filled size, then return an error */
807
18.7k
    if(EXCEED_OFFSET(ps_bitstrm))
808
604
    {
809
604
        return ERROR_INV_SPS_PPS_T;
810
604
    }
811
812
    /*--------------------------------------------------------------------*/
813
    /* All initializations to ps_dec are beyond this point                */
814
    /*--------------------------------------------------------------------*/
815
18.1k
    {
816
18.1k
        WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
817
18.1k
        if((1 == ps_seq->u1_vui_parameters_present_flag) &&
818
3.19k
           (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
819
217
        {
820
217
            reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
821
217
        }
822
823
18.1k
        if(reorder_depth > H264_MAX_REF_PICS)
824
66
        {
825
66
            return ERROR_INV_SPS_PPS_T;
826
66
        }
827
828
18.0k
        if(ps_seq->u1_frame_mbs_only_flag != 1) reorder_depth *= 2;
829
18.0k
        ps_subset_seq->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
830
18.0k
    }
831
0
    ps_subset_seq->u2_disp_height = i4_cropped_ht;
832
18.0k
    ps_subset_seq->u2_disp_width = i4_cropped_wd;
833
18.0k
    ps_subset_seq->u2_pic_wd = u2_pic_wd;
834
18.0k
    ps_subset_seq->u2_pic_ht = u2_pic_ht;
835
836
    /* Assuming 8k is the maximum resolution svc dec supports*/
837
18.0k
    if(u2_frm_wd_y > H264_MAX_FRAME_WIDTH) return (NOT_OK);
838
17.8k
    if(u2_frm_ht_y > H264_MAX_FRAME_HEIGHT) return (NOT_OK);
839
17.8k
    if(u2_frm_wd_uv > H264_MAX_FRAME_WIDTH) return (NOT_OK);
840
17.8k
    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
17.8k
    ps_subset_seq->u2_frm_wd_y = u2_frm_wd_y;
844
17.8k
    ps_subset_seq->u2_frm_ht_y = u2_frm_ht_y;
845
17.8k
    ps_subset_seq->u2_frm_wd_uv = u2_frm_wd_uv;
846
17.8k
    ps_subset_seq->u2_frm_ht_uv = u2_frm_ht_uv;
847
848
17.8k
    ps_subset_seq->u1_pad_len_y_v = (UWORD8) (PAD_LEN_Y_V << (1 - u1_frm));
849
17.8k
    ps_subset_seq->u1_pad_len_cr_v = (UWORD8) (PAD_LEN_UV_V << (1 - u1_frm));
850
851
17.8k
    ps_subset_seq->u2_crop_offset_y = u2_crop_offset_y;
852
17.8k
    ps_subset_seq->u2_crop_offset_uv = u2_crop_offset_uv;
853
854
17.8k
    ps_seq->u1_is_valid = TRUE;
855
17.8k
    ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
856
17.8k
    if(NULL != ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext)
857
764
    {
858
764
        ps_seq_svc_ext->ps_svc_vui_ext =
859
764
            ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].s_sps_svc_ext.ps_svc_vui_ext;
860
764
    }
861
17.8k
    ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id] = *ps_subset_seq;
862
17.8k
    ps_svc_lyr_dec->ps_cur_subset_sps = &ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id];
863
864
17.8k
    return OK;
865
17.8k
}
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
178k
{
944
178k
    dec_bit_stream_t *ps_bitstrm;
945
946
178k
    dec_struct_t *ps_dec;
947
178k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec;
948
178k
    UWORD8 u1_nal_unit_type;
949
178k
    WORD32 i_status = OK;
950
951
178k
    ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) dec_svc_hdl;
952
178k
    ps_dec = &ps_svc_lyr_dec->s_dec;
953
954
178k
    {
955
178k
        SWITCHOFFTRACE;
956
178k
        u1_nal_unit_type = ps_dec->u1_nal_unit_type;
957
958
178k
        ps_bitstrm = ps_dec->ps_bitstrm;
959
960
        // Skip all NALUs if SPS and PPS are not decoded
961
178k
        switch(u1_nal_unit_type)
962
178k
        {
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
66
                {
974
66
                    return NOT_OK;
975
66
                }
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
55.2k
                break;
999
1000
55.2k
            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
42.5k
            case CODED_SLICE_EXTENSION_NAL:
1028
1029
42.5k
                if(ps_svc_lyr_dec->u1_base_res_flag == 1)
1030
3.11k
                {
1031
3.11k
                    return NOT_OK;
1032
3.11k
                }
1033
39.3k
                if(!ps_dec->i4_decode_header)
1034
39.3k
                {
1035
39.3k
                    if(ps_dec->i4_header_decoded == 3)
1036
39.3k
                    {
1037
                        /* ! */
1038
39.3k
                        DEBUG_THREADS_PRINTF("Decoding  an SVC slice NAL\n");
1039
39.3k
                        {
1040
39.3k
                            {
1041
39.3k
                                ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
1042
                                /* ! */
1043
39.3k
                                ps_dec->u4_slice_start_code_found = 1;
1044
1045
39.3k
                                i_status = isvcd_parse_decode_slice_ext_nal(
1046
39.3k
                                    (UWORD8) (ps_svc_lyr_dec->ps_nal_svc_ext->u1_idr_flag),
1047
39.3k
                                    u1_nal_ref_idc, ps_svc_lyr_dec);
1048
1049
39.3k
                                if(i_status != OK)
1050
27.4k
                                {
1051
27.4k
                                    return i_status;
1052
27.4k
                                }
1053
39.3k
                            }
1054
39.3k
                        }
1055
39.3k
                    }
1056
39.3k
                }
1057
11.9k
                break;
1058
1059
11.9k
            default:
1060
0
                H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1061
0
                break;
1062
178k
        }
1063
178k
    }
1064
67.2k
    return i_status;
1065
178k
}
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
123k
{
1080
123k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1081
123k
    UWORD8 i;
1082
123k
    dec_seq_params_t *ps_seq = NULL;
1083
123k
    dec_svc_seq_params_t *ps_subset_seq = NULL;
1084
123k
    UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
1085
123k
    UWORD16 i2_max_frm_num;
1086
123k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1087
123k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1088
123k
    UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag, uc_constraint_set2_flag;
1089
123k
    WORD32 i4_cropped_ht, i4_cropped_wd;
1090
123k
    UWORD32 u4_temp;
1091
123k
    UWORD64 u8_temp;
1092
123k
    UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
1093
123k
    UWORD32 u2_pic_wd = 0;
1094
123k
    UWORD32 u2_pic_ht = 0;
1095
123k
    UWORD32 u2_frm_wd_y = 0;
1096
123k
    UWORD32 u2_frm_ht_y = 0;
1097
123k
    UWORD32 u2_frm_wd_uv = 0;
1098
123k
    UWORD32 u2_frm_ht_uv = 0;
1099
123k
    UWORD32 u2_crop_offset_y = 0;
1100
123k
    UWORD32 u2_crop_offset_uv = 0;
1101
123k
    WORD32 ret;
1102
123k
    WORD32 num_reorder_frames;
1103
    /* High profile related syntax element */
1104
123k
    WORD32 i4_i;
1105
    /* G050 */
1106
123k
    UWORD8 u1_frame_cropping_flag,
1107
123k
        u1_frame_cropping_rect_left_ofst = 0, u1_frame_cropping_rect_right_ofst = 0,
1108
123k
        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
123k
    SWITCHONTRACE;
1114
123k
    u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
1115
123k
    COPYTHECONTEXT("SPS: profile_idc", u1_profile_idc);
1116
1117
    /* G050 */
1118
123k
    uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
1119
123k
    uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
1120
123k
    uc_constraint_set2_flag = ih264d_get_bit_h264(ps_bitstrm);
1121
123k
    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
123k
    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
123k
    if((u1_profile_idc != MAIN_PROFILE_IDC) && (u1_profile_idc != BASE_PROFILE_IDC) &&
1131
83.2k
       (u1_profile_idc != HIGH_PROFILE_IDC))
1132
79.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
79.2k
        if((u1_profile_idc != EXTENDED_PROFILE_IDC) ||
1138
78.7k
           ((uc_constraint_set1_flag != 1) && (uc_constraint_set0_flag != 1)))
1139
742
        {
1140
742
            return (ERROR_FEATURE_UNAVAIL);
1141
742
        }
1142
79.2k
    }
1143
1144
123k
    u1_level_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
1145
123k
    COPYTHECONTEXT("SPS: u4_level_idc", u1_level_idc);
1146
1147
123k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1148
123k
    if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
1149
122k
    u1_seq_parameter_set_id = u4_temp;
1150
122k
    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
122k
    ps_subset_seq = ps_svc_lyr_dec->pv_scratch_subset_sps;
1156
122k
    memset(ps_subset_seq, 0, sizeof(dec_svc_seq_params_t));
1157
122k
    ps_seq = ps_dec->pv_scratch_sps_pps;
1158
122k
    memset(ps_seq, 0, sizeof(dec_seq_params_t));
1159
1160
122k
    if((ps_dec->i4_header_decoded & 1) &&
1161
101k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1162
95.7k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_profile_idc != u1_profile_idc))
1163
341
    {
1164
341
        ps_dec->u1_res_changed = 1;
1165
341
        return IVD_RES_CHANGED;
1166
341
    }
1167
1168
122k
    if((ps_dec->i4_header_decoded & 1) &&
1169
101k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1170
95.3k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_level_idc != u1_level_idc))
1171
1.30k
    {
1172
1.30k
        ps_dec->u1_res_changed = 1;
1173
1.30k
        return IVD_RES_CHANGED;
1174
1.30k
    }
1175
1176
120k
    ps_seq->u1_profile_idc = u1_profile_idc;
1177
120k
    ps_seq->u1_level_idc = u1_level_idc;
1178
120k
    ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
1179
120k
    ps_subset_seq->ps_seq = &ps_dec->ps_sps[u1_seq_parameter_set_id];
1180
1181
    /*******************************************************************/
1182
    /* Initializations for high profile - Sushant                      */
1183
    /*******************************************************************/
1184
120k
    ps_seq->i4_chroma_format_idc = 1;
1185
120k
    ps_seq->i4_bit_depth_luma_minus8 = 0;
1186
120k
    ps_seq->i4_bit_depth_chroma_minus8 = 0;
1187
120k
    ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
1188
120k
    ps_seq->i4_seq_scaling_matrix_present_flag = 0;
1189
120k
    if(u1_profile_idc == HIGH_PROFILE_IDC || u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC ||
1190
117k
       u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC)
1191
3.84k
    {
1192
        /* reading chroma_format_idc   */
1193
3.84k
        ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1194
1195
        /* Monochrome is not supported */
1196
3.84k
        if(ps_seq->i4_chroma_format_idc != 1)
1197
133
        {
1198
133
            return ERROR_FEATURE_UNAVAIL;
1199
133
        }
1200
1201
        /* reading bit_depth_luma_minus8   */
1202
3.71k
        ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1203
1204
3.71k
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
1205
152
        {
1206
152
            return ERROR_FEATURE_UNAVAIL;
1207
152
        }
1208
1209
        /* reading bit_depth_chroma_minus8   */
1210
3.55k
        ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1211
1212
3.55k
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
1213
106
        {
1214
106
            return ERROR_FEATURE_UNAVAIL;
1215
106
        }
1216
1217
        /* reading qpprime_y_zero_transform_bypass_flag   */
1218
3.45k
        ps_seq->i4_qpprime_y_zero_transform_bypass_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1219
1220
3.45k
        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
3.38k
        ps_seq->i4_seq_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1227
1228
3.38k
        if(ps_seq->i4_seq_scaling_matrix_present_flag)
1229
1.10k
        {
1230
9.62k
            for(i4_i = 0; i4_i < 8; i4_i++)
1231
8.69k
            {
1232
8.69k
                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
8.69k
                ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
1237
1238
8.69k
                if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
1239
2.23k
                {
1240
2.23k
                    if(i4_i < 6)
1241
1.68k
                    {
1242
1.68k
                        ret = ih264d_scaling_list(ps_seq->i2_scalinglist4x4[i4_i], 16,
1243
1.68k
                                                  &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
1244
1.68k
                                                  ps_bitstrm);
1245
1.68k
                    }
1246
553
                    else
1247
553
                    {
1248
553
                        ret = ih264d_scaling_list(ps_seq->i2_scalinglist8x8[i4_i - 6], 64,
1249
553
                                                  &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
1250
553
                                                  ps_bitstrm);
1251
553
                    }
1252
2.23k
                    if(ret != OK)
1253
179
                    {
1254
179
                        return ret;
1255
179
                    }
1256
2.23k
                }
1257
8.69k
            }
1258
1.10k
        }
1259
3.38k
    }
1260
    /*--------------------------------------------------------------------*/
1261
    /* Decode MaxFrameNum                                                 */
1262
    /*--------------------------------------------------------------------*/
1263
120k
    u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1264
120k
    if(u8_temp > MAX_BITS_IN_FRAME_NUM)
1265
196
    {
1266
196
        return ERROR_INV_SPS_PPS_T;
1267
196
    }
1268
120k
    ps_seq->u1_bits_in_frm_num = (UWORD8) u8_temp;
1269
120k
    COPYTHECONTEXT("SPS: log2_max_frame_num_minus4", (ps_seq->u1_bits_in_frm_num - 4));
1270
1271
120k
    i2_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
1272
120k
    ps_seq->u2_u4_max_pic_num_minus1 = i2_max_frm_num - 1;
1273
    /*--------------------------------------------------------------------*/
1274
    /* Decode picture order count and related values                      */
1275
    /*--------------------------------------------------------------------*/
1276
120k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1277
120k
    if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
1278
161
    {
1279
161
        return ERROR_INV_POC_TYPE_T;
1280
161
    }
1281
119k
    ps_seq->u1_pic_order_cnt_type = u4_temp;
1282
119k
    COPYTHECONTEXT("SPS: pic_order_cnt_type", ps_seq->u1_pic_order_cnt_type);
1283
1284
119k
    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
1285
119k
    if(ps_seq->u1_pic_order_cnt_type == 0)
1286
104k
    {
1287
104k
        u8_temp = (UWORD64) 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1288
104k
        if(u8_temp > MAX_BITS_IN_POC_LSB)
1289
104
        {
1290
104
            return ERROR_INV_SPS_PPS_T;
1291
104
        }
1292
104k
        ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = (UWORD8) u8_temp;
1293
104k
        ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
1294
104k
        COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4", (u8_temp - 4));
1295
104k
    }
1296
15.0k
    else if(ps_seq->u1_pic_order_cnt_type == 1)
1297
13.9k
    {
1298
13.9k
        ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(ps_bitstrm);
1299
13.9k
        COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
1300
13.9k
                       ps_seq->u1_delta_pic_order_always_zero_flag);
1301
1302
13.9k
        ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1303
13.9k
        COPYTHECONTEXT("SPS: offset_for_non_ref_pic", ps_seq->i4_ofst_for_non_ref_pic);
1304
1305
13.9k
        ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1306
13.9k
        COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
1307
13.9k
                       ps_seq->i4_ofst_for_top_to_bottom_field);
1308
1309
13.9k
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1310
13.9k
        if(u4_temp > 255) return ERROR_INV_SPS_PPS_T;
1311
13.7k
        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
1312
13.7k
        COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
1313
13.7k
                       ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
1314
1315
44.3k
        for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
1316
30.5k
        {
1317
30.5k
            ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1318
30.5k
            COPYTHECONTEXT("SPS: offset_for_ref_frame", ps_seq->i4_ofst_for_ref_frame[i]);
1319
30.5k
        }
1320
13.7k
    }
1321
1322
119k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1323
1324
119k
    if((u4_temp > H264_MAX_REF_PICS))
1325
296
    {
1326
296
        return ERROR_NUM_REF;
1327
296
    }
1328
1329
    /* Compare with older num_ref_frames is header is already once */
1330
119k
    if((ps_dec->i4_header_decoded & 1) &&
1331
100k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1332
94.0k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_num_ref_frames != u4_temp))
1333
212
    {
1334
212
        ps_dec->u1_res_changed = 1;
1335
212
        return IVD_RES_CHANGED;
1336
212
    }
1337
1338
119k
    ps_seq->u1_num_ref_frames = u4_temp;
1339
119k
    COPYTHECONTEXT("SPS: num_ref_frames", ps_seq->u1_num_ref_frames);
1340
1341
119k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(ps_bitstrm);
1342
119k
    COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
1343
119k
                   ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
1344
1345
119k
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = 0;
1346
1347
    /*--------------------------------------------------------------------*/
1348
    /* Decode FrameWidth and FrameHeight and related values               */
1349
    /*--------------------------------------------------------------------*/
1350
119k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1351
    /* Check  for unsupported resolutions*/
1352
119k
    if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
1353
158
    {
1354
158
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1355
158
    }
1356
119k
    u4_pic_width_in_mbs = (UWORD32) u8_temp;
1357
119k
    COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1", u4_pic_width_in_mbs - 1);
1358
1359
119k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1360
119k
    if(u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
1361
161
    {
1362
161
        return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1363
161
    }
1364
118k
    u4_pic_height_in_map_units = (UWORD32) u8_temp;
1365
1366
118k
    ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
1367
118k
    ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
1368
118k
    u2_pic_wd = (u4_pic_width_in_mbs << 4);
1369
118k
    u2_pic_ht = (u4_pic_height_in_map_units << 4);
1370
118k
    if(ps_svc_lyr_dec->pic_width < u2_pic_wd)
1371
12.6k
    {
1372
12.6k
        ps_svc_lyr_dec->pic_width = u2_pic_wd;
1373
12.6k
    }
1374
118k
    if(ps_svc_lyr_dec->pic_height < u2_pic_ht)
1375
12.7k
    {
1376
12.7k
        ps_svc_lyr_dec->pic_height = u2_pic_ht;
1377
12.7k
    }
1378
1379
    /*--------------------------------------------------------------------*/
1380
    /* Get the value of MaxMbAddress and Number of bits needed for it     */
1381
    /*--------------------------------------------------------------------*/
1382
118k
    ps_seq->u4_max_mb_addr = ((UWORD32)ps_seq->u2_frm_wd_in_mbs * (UWORD32)ps_seq->u2_frm_ht_in_mbs) - 1;
1383
118k
    ps_seq->u4_total_num_of_mbs = ps_seq->u4_max_mb_addr + 1;
1384
118k
    ps_seq->u1_level_idc = ih264d_correct_level_idc(u1_level_idc, ps_seq->u4_total_num_of_mbs);
1385
1386
118k
    u1_frm = ih264d_get_bit_h264(ps_bitstrm);
1387
118k
    if((ps_dec->i4_header_decoded & 1) &&
1388
99.8k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1389
93.8k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_frame_mbs_only_flag != u1_frm))
1390
2.66k
    {
1391
2.66k
        ps_dec->u1_res_changed = 1;
1392
2.66k
        return IVD_RES_CHANGED;
1393
2.66k
    }
1394
116k
    ps_seq->u1_frame_mbs_only_flag = u1_frm;
1395
116k
    COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
1396
1397
116k
    if(!u1_frm) u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
1398
1399
116k
    if((ps_dec->i4_header_decoded & 1) &&
1400
97.1k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1401
91.1k
       (ps_dec->ps_sps[u1_seq_parameter_set_id].u1_mb_aff_flag != u1_mb_aff_flag))
1402
653
    {
1403
653
        ps_dec->u1_res_changed = 1;
1404
653
        return IVD_RES_CHANGED;
1405
653
    }
1406
1407
115k
    if(!u1_frm)
1408
57.3k
    {
1409
57.3k
        u2_pic_ht <<= 1;
1410
57.3k
        ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
1411
57.3k
        COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag", ps_seq->u1_mb_aff_flag);
1412
57.3k
    }
1413
58.2k
    else
1414
58.2k
        ps_seq->u1_mb_aff_flag = 0;
1415
1416
115k
    ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
1417
115k
    COPYTHECONTEXT("SPS: direct_8x8_inference_flag", ps_seq->u1_direct_8x8_inference_flag);
1418
1419
    /* G050 */
1420
115k
    u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
1421
115k
    COPYTHECONTEXT("SPS: frame_cropping_flag", u1_frame_cropping_flag);
1422
1423
115k
    if(u1_frame_cropping_flag)
1424
15.4k
    {
1425
15.4k
        u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1426
15.4k
        COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset", u1_frame_cropping_rect_left_ofst);
1427
15.4k
        u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1428
15.4k
        COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset", u1_frame_cropping_rect_right_ofst);
1429
15.4k
        u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1430
15.4k
        COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset", u1_frame_cropping_rect_top_ofst);
1431
15.4k
        u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1432
15.4k
        COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
1433
15.4k
                       u1_frame_cropping_rect_bottom_ofst);
1434
15.4k
    }
1435
    /* G050 */
1436
115k
    ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1437
115k
    COPYTHECONTEXT("SPS: vui_parameters_present_flag", ps_seq->u1_vui_parameters_present_flag);
1438
1439
115k
    u2_frm_wd_y = u2_pic_wd + (UWORD8) (PAD_LEN_Y_H << 1);
1440
1441
115k
    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
115k
    u2_frm_ht_y = u2_pic_ht + (UWORD8) (PAD_LEN_Y_V << 2);
1447
115k
    u2_frm_wd_uv = u2_pic_wd + (UWORD8) (PAD_LEN_UV_H << 2);
1448
115k
    u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
1449
115k
    u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8) (PAD_LEN_UV_V << 2);
1450
115k
    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
115k
    {
1455
115k
        UWORD16 u2_rgt_ofst = 0;
1456
115k
        UWORD16 u2_lft_ofst = 0;
1457
115k
        UWORD16 u2_top_ofst = 0;
1458
115k
        UWORD16 u2_btm_ofst = 0;
1459
115k
        UWORD8 u1_frm_mbs_flag;
1460
115k
        UWORD8 u1_vert_mult_factor;
1461
1462
115k
        if(u1_frame_cropping_flag)
1463
15.4k
        {
1464
            /* Calculate right and left u4_ofst for cropped picture           */
1465
15.4k
            u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
1466
15.4k
            u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
1467
1468
            /* Know frame MBs only u4_flag                                      */
1469
15.4k
            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.4k
            u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
1473
1474
            /* Calculate bottom and top u4_ofst for cropped  picture          */
1475
15.4k
            u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst << u1_vert_mult_factor);
1476
15.4k
            u2_top_ofst = (u1_frame_cropping_rect_top_ofst << u1_vert_mult_factor);
1477
15.4k
        }
1478
1479
        /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
1480
        /* cropped picture buffer                                           */
1481
115k
        u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
1482
115k
        u2_crop_offset_uv =
1483
115k
            (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
115k
        i4_cropped_ht = (WORD32) u2_pic_ht - (WORD32) (u2_btm_ofst + u2_top_ofst);
1487
115k
        i4_cropped_wd = (WORD32) u2_pic_wd - (WORD32) (u2_rgt_ofst + u2_lft_ofst);
1488
1489
115k
        if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
1490
313
        {
1491
313
            return ERROR_INV_SPS_PPS_T;
1492
313
        }
1493
1494
115k
        if((ps_dec->i4_header_decoded & 1) &&
1495
96.4k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1496
90.4k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_wd != u2_pic_wd))
1497
230
        {
1498
230
            ps_dec->u1_res_changed = 1;
1499
230
            return IVD_RES_CHANGED;
1500
230
        }
1501
1502
115k
        if((ps_dec->i4_header_decoded & 1) &&
1503
96.2k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1504
90.2k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_width != i4_cropped_wd))
1505
120
        {
1506
120
            ps_dec->u1_res_changed = 1;
1507
120
            return IVD_RES_CHANGED;
1508
120
        }
1509
1510
114k
        if((ps_dec->i4_header_decoded & 1) &&
1511
96.1k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1512
90.1k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_pic_ht != u2_pic_ht))
1513
431
        {
1514
431
            ps_dec->u1_res_changed = 1;
1515
431
            return IVD_RES_CHANGED;
1516
431
        }
1517
1518
114k
        if((ps_dec->i4_header_decoded & 1) &&
1519
95.6k
           (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) &&
1520
89.7k
           (ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id].u2_disp_height != i4_cropped_ht))
1521
169
        {
1522
169
            ps_dec->u1_res_changed = 1;
1523
169
            return IVD_RES_CHANGED;
1524
169
        }
1525
        /* Check again for unsupported resolutions with updated values*/
1526
114k
        if((u2_pic_wd > SVCD_MAX_FRAME_WIDTH) || (u2_pic_ht > SVCD_MAX_FRAME_HEIGHT) ||
1527
114k
           (u2_pic_wd < SVCD_MIN_FRAME_WIDTH) || (u2_pic_ht < SVCD_MIN_FRAME_HEIGHT) ||
1528
113k
           (u2_pic_wd * (UWORD32) u2_pic_ht > SVCD_MAX_FRAME_SIZE))
1529
740
        {
1530
740
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1531
740
        }
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
113k
        if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
1538
41
        {
1539
41
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1540
41
        }
1541
113k
    }
1542
1543
    /* Backup num_reorder_frames if header is already decoded */
1544
113k
    if((ps_dec->i4_header_decoded & 1) && (1 == ps_seq->u1_vui_parameters_present_flag) &&
1545
5.95k
       (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
113k
    else
1550
113k
    {
1551
113k
        num_reorder_frames = -1;
1552
113k
    }
1553
113k
    if(1 == ps_seq->u1_vui_parameters_present_flag)
1554
6.99k
    {
1555
6.99k
        ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
1556
6.99k
        if(ret != OK) return ret;
1557
6.99k
    }
1558
1559
    /* Compare older num_reorder_frames with the new one if header is already
1560
     * decoded */
1561
113k
    if((ps_dec->i4_header_decoded & 1) &&
1562
95.1k
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_is_valid) && (-1 != num_reorder_frames) &&
1563
0
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].u1_vui_parameters_present_flag) &&
1564
0
       (1 == ps_dec->ps_sps[u1_seq_parameter_set_id].s_vui.u1_bitstream_restriction_flag) &&
1565
0
       ((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
113k
    if(EXCEED_OFFSET(ps_bitstrm))
1574
300
    {
1575
300
        return ERROR_INV_SPS_PPS_T;
1576
300
    }
1577
1578
    /*--------------------------------------------------------------------*/
1579
    /* All initializations to ps_dec are beyond this point                */
1580
    /*--------------------------------------------------------------------*/
1581
113k
    {
1582
113k
        WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
1583
113k
        if((1 == ps_seq->u1_vui_parameters_present_flag) &&
1584
6.60k
           (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1585
1.07k
        {
1586
1.07k
            reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
1587
1.07k
        }
1588
1589
113k
        if(reorder_depth > H264_MAX_REF_PICS)
1590
76
        {
1591
76
            return ERROR_INV_SPS_PPS_T;
1592
76
        }
1593
1594
112k
        if(ps_seq->u1_frame_mbs_only_flag != 1) reorder_depth *= 2;
1595
112k
        ps_subset_seq->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
1596
112k
    }
1597
0
    ps_subset_seq->u2_disp_height = i4_cropped_ht;
1598
112k
    ps_subset_seq->u2_disp_width = i4_cropped_wd;
1599
112k
    ps_subset_seq->u2_pic_wd = u2_pic_wd;
1600
112k
    ps_subset_seq->u2_pic_ht = u2_pic_ht;
1601
1602
    /* Determining the Width and Height of Frame from that of Picture */
1603
112k
    ps_subset_seq->u2_frm_wd_y = u2_frm_wd_y;
1604
112k
    ps_subset_seq->u2_frm_ht_y = u2_frm_ht_y;
1605
112k
    ps_subset_seq->u2_frm_wd_uv = u2_frm_wd_uv;
1606
112k
    ps_subset_seq->u2_frm_ht_uv = u2_frm_ht_uv;
1607
1608
112k
    ps_subset_seq->u1_pad_len_y_v = (UWORD8) (PAD_LEN_Y_V << (1 - u1_frm));
1609
112k
    ps_subset_seq->u1_pad_len_cr_v = (UWORD8) (PAD_LEN_UV_V << (1 - u1_frm));
1610
1611
112k
    ps_subset_seq->u2_crop_offset_y = u2_crop_offset_y;
1612
112k
    ps_subset_seq->u2_crop_offset_uv = u2_crop_offset_uv;
1613
1614
112k
    ps_seq->u1_is_valid = TRUE;
1615
112k
    ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
1616
112k
    ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id] = *ps_subset_seq;
1617
112k
    ps_svc_lyr_dec->ps_cur_subset_sps = &ps_svc_lyr_dec->ps_subset_sps[u1_seq_parameter_set_id];
1618
1619
112k
    return OK;
1620
113k
}
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
107k
{
1635
107k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
1636
107k
    UWORD8 uc_temp;
1637
107k
    dec_seq_params_t *ps_sps = NULL;
1638
107k
    dec_pic_params_t *ps_pps = NULL;
1639
107k
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
1640
107k
    UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
1641
1642
    /* Variables used for error resilience checks */
1643
107k
    UWORD64 u8_temp;
1644
107k
    UWORD32 u4_temp;
1645
107k
    WORD32 i_temp;
1646
1647
    /* For High profile related syntax elements */
1648
107k
    UWORD8 u1_more_data_flag;
1649
107k
    WORD32 i4_i;
1650
1651
    /*--------------------------------------------------------------------*/
1652
    /* Decode pic_parameter_set_id and find corresponding pic params      */
1653
    /*--------------------------------------------------------------------*/
1654
107k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1655
107k
    if(u4_temp & MASK_ERR_PIC_SET_ID) return ERROR_INV_SPS_PPS_T;
1656
107k
    ps_pps = ps_dec->pv_scratch_sps_pps;
1657
107k
    *ps_pps = ps_dec->ps_pps[u4_temp];
1658
107k
    ps_pps->u1_pic_parameter_set_id = (UWORD8) u4_temp;
1659
107k
    COPYTHECONTEXT("PPS: pic_parameter_set_id", ps_pps->u1_pic_parameter_set_id);
1660
1661
    /************************************************/
1662
    /* initilization of High profile syntax element */
1663
    /************************************************/
1664
107k
    ps_pps->i4_transform_8x8_mode_flag = 0;
1665
107k
    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
107k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1671
107k
    if(u4_temp & MASK_ERR_SEQ_SET_ID) return ERROR_INV_SPS_PPS_T;
1672
107k
    COPYTHECONTEXT("PPS: seq_parameter_set_id", u4_temp);
1673
107k
    ps_sps = &ps_dec->ps_sps[u4_temp];
1674
107k
    ps_pps->ps_sps = ps_sps;
1675
1676
    /*--------------------------------------------------------------------*/
1677
    /* Decode entropy_coding_mode                                         */
1678
    /*--------------------------------------------------------------------*/
1679
107k
    ps_pps->u1_entropy_coding_mode = ih264d_get_bit_h264(ps_bitstrm);
1680
107k
    COPYTHECONTEXT("PPS: entropy_coding_mode_flag", ps_pps->u1_entropy_coding_mode);
1681
1682
107k
    ps_pps->u1_pic_order_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1683
107k
    COPYTHECONTEXT("PPS: pic_order_present_flag", ps_pps->u1_pic_order_present_flag);
1684
1685
    /*--------------------------------------------------------------------*/
1686
    /* Decode num_slice_groups_minus1                                     */
1687
    /*--------------------------------------------------------------------*/
1688
107k
    u8_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + (UWORD64) 1;
1689
107k
    if(u8_temp != 1)
1690
429
    {
1691
429
        return ERROR_FEATURE_UNAVAIL;
1692
429
    }
1693
106k
    ps_pps->u1_num_slice_groups = (UWORD8) u8_temp;
1694
106k
    COPYTHECONTEXT("PPS: num_slice_groups_minus1", ps_pps->u1_num_slice_groups - 1);
1695
1696
    /*--------------------------------------------------------------------*/
1697
    /* Other parameter set values                                         */
1698
    /*--------------------------------------------------------------------*/
1699
106k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1700
106k
    if(u8_temp >= H264_MAX_REF_IDX) return ERROR_REF_IDX;
1701
106k
    ps_pps->u1_num_ref_idx_lx_active[0] = (UWORD8) u8_temp;
1702
106k
    COPYTHECONTEXT("PPS: num_ref_idx_l0_active_minus1", ps_pps->u1_num_ref_idx_lx_active[0] - 1);
1703
1704
106k
    u8_temp = (UWORD64) 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1705
106k
    if(u8_temp >= H264_MAX_REF_IDX) return ERROR_REF_IDX;
1706
106k
    ps_pps->u1_num_ref_idx_lx_active[1] = (UWORD8) u8_temp;
1707
106k
    COPYTHECONTEXT("PPS: num_ref_idx_l1_active_minus1", ps_pps->u1_num_ref_idx_lx_active[1] - 1);
1708
1709
106k
    ps_pps->u1_wted_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
1710
106k
    COPYTHECONTEXT("PPS: weighted prediction u4_flag", ps_pps->u1_wted_pred_flag);
1711
106k
    uc_temp = (UWORD8) ih264d_get_bits_h264(ps_bitstrm, 2);
1712
106k
    COPYTHECONTEXT("PPS: weighted_bipred_idc", uc_temp);
1713
106k
    ps_pps->u1_wted_bipred_idc = uc_temp;
1714
1715
106k
    if(ps_pps->u1_wted_bipred_idc > MAX_WEIGHT_BIPRED_IDC) return ERROR_INV_SPS_PPS_T;
1716
1717
106k
    {
1718
106k
        WORD64 i8_temp = (WORD64) 26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1719
1720
106k
        if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP)) return ERROR_INV_RANGE_QP_T;
1721
1722
105k
        ps_pps->u1_pic_init_qp = (UWORD8) i8_temp;
1723
105k
        COPYTHECONTEXT("PPS: pic_init_qp_minus26", ps_pps->u1_pic_init_qp - 26);
1724
1725
105k
        i8_temp = (WORD64) 26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1726
105k
        if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP)) return ERROR_INV_RANGE_QP_T;
1727
1728
105k
        ps_pps->u1_pic_init_qs = (UWORD8) i8_temp;
1729
105k
        COPYTHECONTEXT("PPS: pic_init_qs_minus26", ps_pps->u1_pic_init_qs - 26);
1730
105k
    }
1731
1732
0
    i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1733
105k
    if((i_temp < -12) || (i_temp > 12)) return ERROR_INV_RANGE_QP_T;
1734
105k
    ps_pps->i1_chroma_qp_index_offset = i_temp;
1735
105k
    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
105k
    ps_pps->i1_second_chroma_qp_index_offset = ps_pps->i1_chroma_qp_index_offset;
1742
1743
105k
    ps_pps->u1_deblocking_filter_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1744
105k
    COPYTHECONTEXT("PPS: deblocking_filter_control_present_flag",
1745
105k
                   ps_pps->u1_deblocking_filter_parameters_present_flag);
1746
105k
    ps_pps->u1_constrained_intra_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
1747
105k
    COPYTHECONTEXT("PPS: constrained_intra_pred_flag", ps_pps->u1_constrained_intra_pred_flag);
1748
105k
    ps_pps->u1_redundant_pic_cnt_present_flag = ih264d_get_bit_h264(ps_bitstrm);
1749
105k
    COPYTHECONTEXT("PPS: redundant_pic_cnt_present_flag",
1750
105k
                   ps_pps->u1_redundant_pic_cnt_present_flag);
1751
1752
    /* High profile related syntax elements */
1753
105k
    u1_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
1754
1755
105k
    if(u1_more_data_flag)
1756
102k
    {
1757
        /* read transform_8x8_mode_flag  */
1758
102k
        ps_pps->i4_transform_8x8_mode_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1759
1760
        /* read pic_scaling_matrix_present_flag */
1761
102k
        ps_pps->i4_pic_scaling_matrix_present_flag = (WORD32) ih264d_get_bit_h264(ps_bitstrm);
1762
1763
102k
        if(ps_pps->i4_pic_scaling_matrix_present_flag)
1764
2.44k
        {
1765
            /* read the scaling matrices */
1766
18.1k
            for(i4_i = 0; i4_i < (6 + (ps_pps->i4_transform_8x8_mode_flag << 1)); i4_i++)
1767
16.0k
            {
1768
16.0k
                ps_pps->u1_pic_scaling_list_present_flag[i4_i] = ih264d_get_bit_h264(ps_bitstrm);
1769
1770
16.0k
                if(ps_pps->u1_pic_scaling_list_present_flag[i4_i])
1771
4.36k
                {
1772
4.36k
                    WORD32 ret;
1773
4.36k
                    if(i4_i < 6)
1774
3.44k
                    {
1775
3.44k
                        ret = ih264d_scaling_list(
1776
3.44k
                            ps_pps->i2_pic_scalinglist4x4[i4_i], 16,
1777
3.44k
                            &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i], ps_bitstrm);
1778
3.44k
                    }
1779
917
                    else
1780
917
                    {
1781
917
                        ret = ih264d_scaling_list(
1782
917
                            ps_pps->i2_pic_scalinglist8x8[i4_i - 6], 64,
1783
917
                            &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i], ps_bitstrm);
1784
917
                    }
1785
1786
4.36k
                    if(ret != OK)
1787
304
                    {
1788
304
                        return ret;
1789
304
                    }
1790
4.36k
                }
1791
16.0k
            }
1792
2.44k
        }
1793
1794
        /* read second_chroma_qp_index_offset syntax element */
1795
102k
        i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1796
102k
        if((i_temp < -12) || (i_temp > 12)) return ERROR_INV_RANGE_QP_T;
1797
1798
102k
        ps_pps->i1_second_chroma_qp_index_offset = i_temp;
1799
102k
    }
1800
1801
104k
    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
104k
    if(EXCEED_OFFSET(ps_bitstrm))
1812
97
    {
1813
97
        return ERROR_INV_SPS_PPS_T;
1814
97
    }
1815
104k
    ps_pps->u1_is_valid = TRUE;
1816
104k
    ps_dec->ps_pps[ps_pps->u1_pic_parameter_set_id] = *ps_pps;
1817
104k
    return OK;
1818
104k
}