⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_h264_dec_bitstream.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                    pPredWeight_L1[refindex].chroma_weight[0] = 1<<hdr->chroma_log2_weight_denom;                    pPredWeight_L1[refindex].chroma_weight[1] = 1<<hdr->chroma_log2_weight_denom;                    pPredWeight_L1[refindex].chroma_offset[0] = 0;                    pPredWeight_L1[refindex].chroma_offset[1] = 0;                }            }        }    // B slice    }    // prediction weight table    else    {        hdr->luma_log2_weight_denom = 0;        hdr->chroma_log2_weight_denom = 0;    }    // dec_ref_pic_marking    pAdaptiveMarkingInfo->num_entries = 0;    if (NALRef_idc)    {        if (bIsIDRSlice)        {            hdr->no_output_of_prior_pics_flag = (Ipp8u)Get1Bit();            hdr->long_term_reference_flag = (Ipp8u)Get1Bit();        }        else        {            Ipp32u memory_management_control_operation;            Ipp32u num_entries = 0;            hdr->adaptive_ref_pic_marking_mode_flag = (Ipp8u)Get1Bit();            while (hdr->adaptive_ref_pic_marking_mode_flag != 0)            {                memory_management_control_operation = (Ipp8u)GetVLCElement(false);                if (memory_management_control_operation == 0)                    break;                pAdaptiveMarkingInfo->mmco[num_entries] =                    (Ipp8u)memory_management_control_operation;                if (memory_management_control_operation != 5)                     pAdaptiveMarkingInfo->value[num_entries*2] =                        GetVLCElement(false);                // Only mmco 3 requires 2 values                if (memory_management_control_operation == 3)                     pAdaptiveMarkingInfo->value[num_entries*2+1] =                        GetVLCElement(false);                num_entries++;                if (num_entries >= MAX_NUM_REF_FRAMES)                {                    return UMC_BAD_FORMAT;                }            }    // while            pAdaptiveMarkingInfo->num_entries = num_entries;        }    }    // def_ref_pic_marking    if (pps->entropy_coding_mode == 1  &&    // CABAC        (hdr->slice_type != INTRASLICE && hdr->slice_type != S_INTRASLICE))        hdr->cabac_init_idc = (Ipp8u)GetVLCElement(false);    else        hdr->cabac_init_idc = 0;    hdr->slice_qp_delta = (Ipp8s)GetVLCElement(true);    if (S_PREDSLICE == hdr->slice_type ||        S_INTRASLICE == hdr->slice_type)    {        if (S_PREDSLICE == hdr->slice_type)            hdr->sp_for_switch_flag = (Ipp8u)Get1Bit();        hdr->slice_qs_delta = (Ipp8s)GetVLCElement(true);    }    if (pps->deblocking_filter_variables_present_flag != 0)    {        // deblock filter flag and offsets        hdr->disable_deblocking_filter_idc = (Ipp8u)GetVLCElement(false);        if (hdr->disable_deblocking_filter_idc != 1)        {            hdr->slice_alpha_c0_offset = (Ipp8s)(GetVLCElement(true)<<1);            hdr->slice_beta_offset = (Ipp8s)(GetVLCElement(true)<<1);            if (hdr->slice_alpha_c0_offset < -12 || hdr->slice_alpha_c0_offset > 12)            {                return UMC_BAD_FORMAT;            }            if (hdr->slice_beta_offset < -12 || hdr->slice_beta_offset > 12)            {                return UMC_BAD_FORMAT;            }        }        else        {            // set filter offsets to max values to disable filter            hdr->slice_alpha_c0_offset = (Ipp8s)(0 - QP_MAX);            hdr->slice_beta_offset = (Ipp8s)(0 - QP_MAX);        }    }    //hdr->disable_deblocking_filter_idc = 1;    if ((pps->num_slice_groups > 1) &&        (pps->SliceGroupInfo.slice_group_map_type >= 3) &&        (pps->SliceGroupInfo.slice_group_map_type <= 5))    {        Ipp32u num_bits;    // number of bits used to code slice_group_change_cycle        Ipp32u val;        Ipp32u pic_size_in_map_units;        Ipp32u max_slice_group_change_cycle=0;        // num_bits is Ceil(log2(picsizeinmapunits/slicegroupchangerate + 1))        pic_size_in_map_units = sps->frame_width_in_mbs * sps->frame_height_in_mbs;            // TBD: change above to support fields        max_slice_group_change_cycle = pic_size_in_map_units /                        pps->SliceGroupInfo.t2.slice_group_change_rate;        if (pic_size_in_map_units %                        pps->SliceGroupInfo.t2.slice_group_change_rate)            max_slice_group_change_cycle++;        val = max_slice_group_change_cycle;// + 1;        num_bits = 0;        while (val)        {            num_bits++;            val >>= 1;        }        hdr->slice_group_change_cycle = GetBits(num_bits);        if (hdr->slice_group_change_cycle > max_slice_group_change_cycle)        {            //return UMC_BAD_FORMAT; don't see any reasons for that        }    }    return UMC_OK;} // CH263pbs::GetSliceHeaderPart2()// ---------------------------------------------------------------------------//        H264Bitstream::SearchBits()//        Searches for a code with known number of bits.  Bitstream state,//        pointer and bit offset, will be updated if code found.//        nbits        : number of bits in the code//        code        : code to search for//        lookahead    : maximum number of bits to parse for the code// ---------------------------------------------------------------------------bool H264Bitstream::SearchBits(const Ipp32u    nbits,const Ipp32u code,const Ipp32u lookahead){    Ipp32u    w;    Ipp32u n = nbits;    Ipp32u*    pbs;    Ipp32s    offset;    pbs        = m_pbs;    offset    = m_bitOffset;    ippiGetNBits(m_pbs, m_bitOffset, n, w)    for (n = 0; w != code && n < lookahead; n ++)    {        w = (w << 1) & GetBitsMask[nbits] | Get1Bit();    }    if (w == code)        return(true);    else    {        m_pbs        = pbs;        m_bitOffset = offset;        return(false);    }} // H264Bitstream::SearchBits()Status H264Bitstream::GetVUIParam(H264SeqParamSet *sps){    Status ps=UMC_OK;    sps->aspect_ratio_info_present_flag = (Ipp8u) Get1Bit();    if( sps->aspect_ratio_info_present_flag ) {        sps->aspect_ratio_idc = (Ipp8u) GetBits(8);        if( sps->aspect_ratio_idc  ==  255) {            sps->sar_width = (Ipp16u) GetBits(16);            sps->sar_height = (Ipp16u) GetBits(16);        }    }    sps->overscan_info_present_flag = (Ipp8u) Get1Bit();    if( sps->overscan_info_present_flag )        sps->overscan_appropriate_flag = (Ipp8u) Get1Bit();    sps->video_signal_type_present_flag = (Ipp8u) Get1Bit();    if( sps->video_signal_type_present_flag ) {        sps->video_format = (Ipp8u) GetBits(3);        sps->video_full_range_flag = (Ipp8u) Get1Bit();        sps->colour_description_present_flag = (Ipp8u) Get1Bit();        if( sps->colour_description_present_flag ) {            sps->colour_primaries = (Ipp8u) GetBits(8);            sps->transfer_characteristics = (Ipp8u) GetBits(8);            sps->matrix_coefficients = (Ipp8u) GetBits(8);        }    }    sps->chroma_loc_info_present_flag = (Ipp8u) Get1Bit();    if( sps->chroma_loc_info_present_flag ) {        sps->chroma_sample_loc_type_top_field = (Ipp8u) GetVLCElement(false);        sps->chroma_sample_loc_type_bottom_field = (Ipp8u) GetVLCElement(false);    }    sps->timing_info_present_flag = (Ipp8u) Get1Bit();    if( sps->timing_info_present_flag ) {        sps->num_units_in_tick = GetBits(32);        sps->time_scale = GetBits(32);        sps->fixed_frame_rate_flag = (Ipp8u) Get1Bit();    }    sps->nal_hrd_parameters_present_flag = (Ipp8u) Get1Bit();    if( sps->nal_hrd_parameters_present_flag )        ps=GetHRDParam(sps);    sps->vcl_hrd_parameters_present_flag = (Ipp8u) Get1Bit();    if( sps->vcl_hrd_parameters_present_flag )        ps=GetHRDParam(sps);    if( sps->nal_hrd_parameters_present_flag  ||  sps->vcl_hrd_parameters_present_flag )        sps->low_delay_hrd_flag = (Ipp8u) Get1Bit();    sps->pic_struct_present_flag  = (Ipp8u) Get1Bit();    sps->bitstream_restriction_flag = (Ipp8u) Get1Bit();    if( sps->bitstream_restriction_flag ) {        sps->motion_vectors_over_pic_boundaries_flag = (Ipp8u) Get1Bit();        sps->max_bytes_per_pic_denom = (Ipp8u) GetVLCElement(false);        sps->max_bits_per_mb_denom = (Ipp8u) GetVLCElement(false);        sps->log2_max_mv_length_horizontal = (Ipp8u) GetVLCElement(false);        sps->log2_max_mv_length_vertical = (Ipp8u) GetVLCElement(false);        sps->num_reorder_frames = (Ipp8u) GetVLCElement(false);        sps->max_dec_frame_buffering = (Ipp8u) GetVLCElement(false);    }    return ps;}Status H264Bitstream::GetHRDParam(H264SeqParamSet *sps){    Status ps=UMC_OK;    sps->cpb_cnt = (Ipp8u) GetVLCElement(false)+1;    sps->bit_rate_scale = (Ipp8u) GetBits(4);    sps->cpb_size_scale = (Ipp8u) GetBits(4);    for( int idx= 0; idx < sps->cpb_cnt; idx++ ) {        sps->bit_rate_value[ idx ] = (Ipp32u) (GetVLCElement(false)+1);        sps->cpb_size_value[ idx ] = (Ipp8u) (GetVLCElement(false)+1);        sps->cbr_flag[ idx ] = (Ipp8u) Get1Bit();    }    sps->initial_cpb_removal_delay_length = (Ipp8u) GetBits(5)+1;    sps->cpb_removal_delay_length = (Ipp8u) GetBits(5)+1;    sps->dpb_output_delay_length = (Ipp8u) GetBits(5)+1;    sps->time_offset_length = (Ipp8u) GetBits(5);    return ps;}void H264Bitstream::SetDecodedBytes(size_t nBytes){    m_pbs = m_pbsBase + (nBytes / 4);    m_bitOffset = 31 - (nBytes % 4) * 8;} // void H264Bitstream::SetDecodedBytes(size_t nBytes)long H264Bitstream::DecodeSingleBin_CABAC(long ctxIdx){    // See subclause 9.3.3.2.1 of H.264 standard    unsigned short &pStateIdx = context_array[ctxIdx].pStateIdx;    unsigned short &valMPS = context_array[ctxIdx].valMPS;    long &codIOffset = m_lcodIOffset;    long &codIRange = m_lcodIRange;    long qCodIRangeIdx;    long codIRangeLPS;    long binVal;    qCodIRangeIdx = ((codIRange >> 6) & 0x03);    codIRangeLPS = rangeTabLPS[pStateIdx][qCodIRangeIdx];    codIRange -= codIRangeLPS;    if (codIOffset >= codIRange)    {        binVal = !valMPS;        codIOffset -= codIRange;        codIRange = codIRangeLPS;        if (0 == pStateIdx)            valMPS = 1 - valMPS;        else            pStateIdx = transIdxLPS[pStateIdx];    }    else    {        binVal = valMPS;        pStateIdx = transIdxMPS[pStateIdx];    };    // Renormalization process    // See subclause 9.3.3.2.2 of H.264    while (0x0100 > codIRange)    {        codIRange <<= 1;        codIOffset = (codIOffset << 1) | ReadBit_CABAC();    };    return binVal;} //long H264Bitstream::DecodeSingleBin_CABAC(long ctxIdx)long H264Bitstream::DecodeBypass_CABAC(void){    // See subclause 9.3.3.2.3 of H.264 standard    long &codIOffset = m_lcodIOffset;    long &codIRange = m_lcodIRange;    long binVal;    codIOffset <<= 1;    codIOffset |= ReadBit_CABAC();    if (codIOffset >= codIRange)    {        binVal = 1;        codIOffset -= codIRange;    }    else        binVal = 0;    return binVal;} //long H264Bitstream::DecodeBypass_CABAC(void)long H264Bitstream::DecodeSymbolEnd_CABAC(void){    // See subclause 9.3.3.2.4 of H.264 standard    long &codIOffset = m_lcodIOffset;    long &codIRange = m_lcodIRange;    long binVal;    if (codIOffset >= (codIRange - 2))        binVal = 1;    else    {        binVal = 0;        codIRange -= 2;        // Renormalization process        // See subclause 9.3.3.2.2 of H.264        while (0x0100 > codIRange)        {            codIRange <<= 1;            codIOffset = (codIOffset << 1) | ReadBit_CABAC();        };    };    return binVal;} //long H264Bitstream::DecodeSymbolEnd_CABAC(void)void H264Bitstream::AlignPointerRight(){    ippiAlignBSPointerRight(m_pbs,m_bitOffset);}Ipp32s  H264Bitstream::GetVLCElement(bool bIsSigned){    Ipp16s sval = 0;    ippiDecodeExpGolombOne_H264_1u16s(&m_pbs, &m_bitOffset, &sval, bIsSigned);    return sval;}// ---------------------------------------------------------------------------//      H264Bitstream::GetBits()//      Reads bits from buffer.  Supports up to 25 bits.//      nbits   : number of bits to be read// ---------------------------------------------------------------------------Ipp32u H264Bitstream::GetBits(const Ipp32u nbits){    Ipp32u w,n = nbits;    ippiGetNBits(m_pbs, m_bitOffset, n, w);    return(w);} // H264Bitstream::GetBits()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -