int HevcSpsUnit::vui_parameters()
{
    bool aspect_ratio_info_present_flag = m_reader.getBit();
    if (aspect_ratio_info_present_flag)
    {
        int aspect_ratio_idc = m_reader.getBits(8);
        if (aspect_ratio_idc == EXTENDED_SAR)
        {
            int sar_width = m_reader.getBits(16);
            int sar_height = m_reader.getBits(16);
        }
    }

    bool overscan_info_present_flag = m_reader.getBit();
    if (overscan_info_present_flag)
        m_reader.skipBit();  // overscan_appropriate_flag u(1)
    bool video_signal_type_present_flag = m_reader.getBit();
    if (video_signal_type_present_flag)
    {
        m_reader.skipBits(3);  // video_format u(3)
        video_full_range_flag = m_reader.getBit();
        bool colour_description_present_flag = m_reader.getBit();
        if (colour_description_present_flag)
        {
            colour_primaries = m_reader.getBits(8);
            transfer_characteristics = m_reader.getBits(8);
            matrix_coeffs = m_reader.getBits(8);
        }
    }

    bool chroma_loc_info_present_flag = m_reader.getBit();
    if (chroma_loc_info_present_flag)
    {
        chroma_sample_loc_type_top_field = extractUEGolombCode();
        if (chroma_sample_loc_type_top_field > 5)
            return 1;
        chroma_sample_loc_type_bottom_field = extractUEGolombCode();
        if (chroma_sample_loc_type_bottom_field > 5)
            return 1;
    }

    m_reader.skipBit();  // neutral_chroma_indication_flag u(1)
    m_reader.skipBit();  // field_seq_flag u(1)
    m_reader.skipBit();  // frame_field_info_present_flag u(1)
    bool default_display_window_flag = m_reader.getBit();
    if (default_display_window_flag)
    {
        extractUEGolombCode();  // def_disp_win_left_offset ue(v)
        extractUEGolombCode();  // def_disp_win_right_offset ue(v)
        extractUEGolombCode();  // def_disp_win_top_offset ue(v)
        extractUEGolombCode();  // def_disp_win_bottom_offset ue(v)
    }

    bool vui_timing_info_present_flag = m_reader.getBit();
    if (vui_timing_info_present_flag)
    {
        num_units_in_tick = m_reader.getBits(32);
        time_scale = m_reader.getBits(32);
        bool vui_poc_proportional_to_timing_flag = m_reader.getBit();
        if (vui_poc_proportional_to_timing_flag)
        {
            unsigned vui_num_ticks_poc_diff_one_minus1 = extractUEGolombCode();
            if (vui_num_ticks_poc_diff_one_minus1 == 0xffffffff)
                return 1;
        }
        bool vui_hrd_parameters_present_flag = m_reader.getBit();
        if (vui_hrd_parameters_present_flag)
            if (hrd_parameters(1, max_sub_layers - 1) != 0)
                return 1;
    }
    bool bitstream_restriction_flag = m_reader.getBit();
    if (bitstream_restriction_flag)
    {
        m_reader.skipBit();  // m_readtiles_fixed_structure_flag u(1)
        m_reader.skipBit();  // motion_vectors_over_pic_boundaries_flag u(1)
        m_reader.skipBit();  // restricted_ref_pic_lists_flag u(1)
        unsigned min_spatial_segmentation_idc = extractUEGolombCode();
        if (min_spatial_segmentation_idc > 4095)
            return 1;
        unsigned max_bytes_per_pic_denom = extractUEGolombCode();
        if (max_bytes_per_pic_denom > 16)
            return 1;
        unsigned max_bits_per_min_cu_denom = extractUEGolombCode();
        if (max_bits_per_min_cu_denom > 16)
            return 1;
        unsigned log2_max_mv_length_horizontal = extractUEGolombCode();
        if (log2_max_mv_length_horizontal > 15)
            return 1;
        unsigned log2_max_mv_length_vertical = extractUEGolombCode();
        if (log2_max_mv_length_vertical > 15)
            return 1;
    }
    return 0;
}
int HevcSpsUnit::vui_parameters()
{
    bool aspect_ratio_info_present_flag = m_reader.getBit();
    if (aspect_ratio_info_present_flag)
    {
        int aspect_ratio_idc = m_reader.getBits(8);
        if (aspect_ratio_idc == EXTENDED_SAR)
        {
            int sar_width = m_reader.getBits(16);
            int sar_height = m_reader.getBits(16);
        }
    }

    bool overscan_info_present_flag = m_reader.getBit();
    if (overscan_info_present_flag)
        m_reader.skipBit();   
    bool video_signal_type_present_flag = m_reader.getBit();
    if (video_signal_type_present_flag)
    {
        m_reader.skipBits(3);   
        video_full_range_flag = m_reader.getBit();
        bool colour_description_present_flag = m_reader.getBit();
        if (colour_description_present_flag)
        {
            colour_primaries = m_reader.getBits(8);
            transfer_characteristics = m_reader.getBits(8);
            matrix_coeffs = m_reader.getBits(8);
        }
    }

    bool chroma_loc_info_present_flag = m_reader.getBit();
    if (chroma_loc_info_present_flag)
    {
        chroma_sample_loc_type_top_field = extractUEGolombCode();
        if (chroma_sample_loc_type_top_field > 5)
            return 1;
        chroma_sample_loc_type_bottom_field = extractUEGolombCode();
        if (chroma_sample_loc_type_bottom_field > 5)
            return 1;
    }

    m_reader.skipBit();   
    m_reader.skipBit();   
    m_reader.skipBit();   
    bool default_display_window_flag = m_reader.getBit();
    if (default_display_window_flag)
    {
        extractUEGolombCode();   
        extractUEGolombCode();   
        extractUEGolombCode();   
        extractUEGolombCode();   
    }

    bool vui_timing_info_present_flag = m_reader.getBit();
    if (vui_timing_info_present_flag)
    {
        num_units_in_tick = m_reader.getBits(32);
        time_scale = m_reader.getBits(32);
        bool vui_poc_proportional_to_timing_flag = m_reader.getBit();
        if (vui_poc_proportional_to_timing_flag)
        {
            unsigned vui_num_ticks_poc_diff_one_minus1 = extractUEGolombCode();
            if (vui_num_ticks_poc_diff_one_minus1 == 0xffffffff)
                return 1;
        }
        bool vui_hrd_parameters_present_flag = m_reader.getBit();
        if (vui_hrd_parameters_present_flag)
            if (hrd_parameters(1, max_sub_layers - 1) != 0)
                return 1;
    }
    bool bitstream_restriction_flag = m_reader.getBit();
    if (bitstream_restriction_flag)
    {
        m_reader.skipBit();   
        m_reader.skipBit();   
        m_reader.skipBit();   
        unsigned min_spatial_segmentation_idc = extractUEGolombCode();
        if (min_spatial_segmentation_idc > 4095)
            return 1;
        unsigned max_bytes_per_pic_denom = extractUEGolombCode();
        if (max_bytes_per_pic_denom > 16)
            return 1;
        unsigned max_bits_per_min_cu_denom = extractUEGolombCode();
        if (max_bits_per_min_cu_denom > 16)
            return 1;
        unsigned log2_max_mv_length_horizontal = extractUEGolombCode();
        if (log2_max_mv_length_horizontal > 15)
            return 1;
        unsigned log2_max_mv_length_vertical = extractUEGolombCode();
        if (log2_max_mv_length_vertical > 15)
            return 1;
    }
    return 0;
}