int HevcSpsUnit::hrd_parameters(bool commonInfPresentFlag, int maxNumSubLayersMinus1)
{
    if (commonInfPresentFlag)
    {
        nal_hrd_parameters_present_flag = m_reader.getBit();
        vcl_hrd_parameters_present_flag = m_reader.getBit();
        if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag)
        {
            sub_pic_hrd_params_present_flag = m_reader.getBit();
            if (sub_pic_hrd_params_present_flag)
            {
                m_reader.skipBits(8);  // tick_divisor_minus2 u(8)
                m_reader.skipBits(5);  // du_cpb_removal_delay_increment_length_minus1 u(5)
                m_reader.skipBit();    // sub_pic_cpb_params_in_pic_timing_sei_flag u(1)
                m_reader.skipBits(5);  // dpb_output_delay_du_length_minus1 u(5)
            }
            m_reader.skipBits(4);  // bit_rate_scale u(4)
            m_reader.skipBits(4);  // cpb_size_scale u(4)
            if (sub_pic_hrd_params_present_flag)
                m_reader.skipBits(4);  // cpb_size_du_scale u(4)
            m_reader.skipBits(5);      // initial_cpb_removal_delay_length_minus1 u(5)
            m_reader.skipBits(5);      // au_cpb_removal_delay_length_minus1 u(5)
            m_reader.skipBits(5);      // dpb_output_delay_length_minus1 u(5)
        }
    }

    cpb_cnt_minus1.resize(maxNumSubLayersMinus1 + 1);
    for (int i = 0; i <= maxNumSubLayersMinus1; i++)
    {
        bool low_delay_hrd_flag = false;
        bool fixed_pic_rate_general_flag = m_reader.getBit();
        bool fixed_pic_rate_within_cvs_flag = true;
        if (!fixed_pic_rate_general_flag)
            fixed_pic_rate_within_cvs_flag = m_reader.getBit();
        if (fixed_pic_rate_within_cvs_flag)
        {
            unsigned elemental_duration_in_tc_minus1 = extractUEGolombCode();
            if (elemental_duration_in_tc_minus1 > 2047)
                return 1;
        }
        else
            low_delay_hrd_flag = m_reader.getBit();
        if (!low_delay_hrd_flag)
        {
            cpb_cnt_minus1[i] = extractUEGolombCode();
            if (cpb_cnt_minus1[i] > 32)
                return 1;
        }
        if (nal_hrd_parameters_present_flag)
            if (sub_layer_hrd_parameters(i) != 0)
                return 1;
        if (vcl_hrd_parameters_present_flag)
            if (sub_layer_hrd_parameters(i) != 0)
                return 1;
    }
    return 0;
}
int HevcSpsUnit::hrd_parameters(bool commonInfPresentFlag, int maxNumSubLayersMinus1)
{
    if (commonInfPresentFlag)
    {
        nal_hrd_parameters_present_flag = m_reader.getBit();
        vcl_hrd_parameters_present_flag = m_reader.getBit();
        if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag)
        {
            sub_pic_hrd_params_present_flag = m_reader.getBit();
            if (sub_pic_hrd_params_present_flag)
            {
                m_reader.skipBits(8);   
                m_reader.skipBits(5);   
                m_reader.skipBit();     
                m_reader.skipBits(5);   
            }
            m_reader.skipBits(4);   
            m_reader.skipBits(4);   
            if (sub_pic_hrd_params_present_flag)
                m_reader.skipBits(4);   
            m_reader.skipBits(5);       
            m_reader.skipBits(5);       
            m_reader.skipBits(5);       
        }
    }

    cpb_cnt_minus1.resize(maxNumSubLayersMinus1 + 1);
    for (int i = 0; i <= maxNumSubLayersMinus1; i++)
    {
        bool low_delay_hrd_flag = false;
        bool fixed_pic_rate_general_flag = m_reader.getBit();
        bool fixed_pic_rate_within_cvs_flag = true;
        if (!fixed_pic_rate_general_flag)
            fixed_pic_rate_within_cvs_flag = m_reader.getBit();
        if (fixed_pic_rate_within_cvs_flag)
        {
            unsigned elemental_duration_in_tc_minus1 = extractUEGolombCode();
            if (elemental_duration_in_tc_minus1 > 2047)
                return 1;
        }
        else
            low_delay_hrd_flag = m_reader.getBit();
        if (!low_delay_hrd_flag)
        {
            cpb_cnt_minus1[i] = extractUEGolombCode();
            if (cpb_cnt_minus1[i] > 32)
                return 1;
        }
        if (nal_hrd_parameters_present_flag)
            if (sub_layer_hrd_parameters(i) != 0)
                return 1;
        if (vcl_hrd_parameters_present_flag)
            if (sub_layer_hrd_parameters(i) != 0)
                return 1;
    }
    return 0;
}