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

📄 umc_h264_bitstream.h

📁 audio-video-codecs.rar语音编解码器
💻 H
📖 第 1 页 / 共 2 页
字号:
        Ipp16s coeffRuns[65];

    #ifdef __ICL
        __assume_aligned(pPosCoefbuf, 8);
    #endif
        memset(pPosCoefbuf, 0, sizeof(Coeffs) * 64);

        // See table 9-32 of H.264 standard
        if (field_decoding_flag)
            ctxIdxBase = ctxIdxOffset8x8FieldCoded;
        else
            ctxIdxBase = ctxIdxOffset8x8FrameCoded;

        ctxIdxOffset = ctxIdxBase[SIGNIFICANT_COEFF_FLAG] +
            ctxIdxBlockCatOffset[SIGNIFICANT_COEFF_FLAG][BLOCK_LUMA8X8_LEVELS];
        ctxIdxOffsetLast = ctxIdxBase[LAST_SIGNIFICANT_COEFF_FLAG] +
            ctxIdxBlockCatOffset[LAST_SIGNIFICANT_COEFF_FLAG][BLOCK_LUMA8X8_LEVELS];

        for (; i < maxNumCoeffminus1; i++)
        {
            ctxIdxInc = pHPFF[i];
            // get significant_coeff_flag
            if (DecodeSingleBin_CABAC(ctxIdxOffset+ctxIdxInc))
            {
                // store position of non-zero coeff
                coeffRuns[ncoefs] = (Ipp16s) i;
                // Intel compiler should use memory form of increment
                ncoefs ++;
                ctxIdxInc = hp_CtxIdxInc_last_sig_coeff_flag[i];
                // get last_significant_coeff_flag
                if (DecodeSingleBin_CABAC(ctxIdxOffsetLast+ctxIdxInc)) break;
            }
        }

        if (i == maxNumCoeffminus1)
        {
            coeffRuns[ncoefs] = (Ipp16s) i;
            ncoefs ++;
        }

        // calculate last coefficient in block
        ctxIdxOffset = ctxIdxBase[COEFF_ABS_LEVEL_MINUS1] +
            ctxIdxBlockCatOffset[COEFF_ABS_LEVEL_MINUS1][BLOCK_LUMA8X8_LEVELS];

        for (; ncoefs > 0; ncoefs--)
        {
            Ipp32s level = DecodeSignedLevel_CABAC(ctxIdxOffset,
                                                   numDecodAbsLevelEq1,
                                                   numDecodAbsLevelGt1,9);

            // store coeff position and level to coeff buffer
            Ipp32u pos = coeffRuns[ncoefs - 1];
            pos = single_scan[pos];

            pPosCoefbuf[pos] = (Ipp16s) level;
        }

    } // void ResidualBlock8x8_CABAC(bool field_decoding_flag,

    template <typename Coeffs>
    void ResidualBlock4x4_CABAC(Ipp32s ctxBlockCat,
                                const Ipp32u *ctxIdxBase,
                                const Ipp32s *pScan,
                                Coeffs *pPosCoefbuf,
                                Ipp32s maxNumCoeffminus1)
    {
        // See subclause 7.3.5.3.2 of H.264 standard
        Coeffs coeffRuns[18];
        Ipp32s iNumCoeffs;

        // See table 9-32 of H.264 standard
    #ifdef __ICL
        __assume_aligned(pPosCoefbuf, 8);
    #endif

        // reset destination block
        memset(pPosCoefbuf, 0, sizeof(Coeffs) * 16);

        // decode coefficient(s)
        {
            Ipp32u ctxIdxOffset, ctxIdxOffsetLast;
            Ipp32s i = 0;

            ctxIdxOffset = ctxIdxBase[SIGNIFICANT_COEFF_FLAG] +
                           ctxIdxBlockCatOffset[SIGNIFICANT_COEFF_FLAG][ctxBlockCat];
            ctxIdxOffsetLast = ctxIdxBase[LAST_SIGNIFICANT_COEFF_FLAG] +
                               ctxIdxBlockCatOffset[LAST_SIGNIFICANT_COEFF_FLAG][ctxBlockCat];

            iNumCoeffs = 0;
            do
            {
                // get significant_coeff_flag
                if (DecodeSingleBin_CABAC(ctxIdxOffset + i))
                {
                    // store position of non-zero coeff
                    coeffRuns[iNumCoeffs] = (Ipp16s) i;
                    // Intel compiler should use memory form of increment
                    iNumCoeffs += 1;
                    // get last_significant_coeff_flag
                    if (DecodeSingleBin_CABAC(ctxIdxOffsetLast + i))
                    {
                        // I know "label jumping" is bad programming style,
                        // but there is no another opportunity to avoid extra comparison.
                        goto no_more_coefficients_label;
                    }
                }

            } while (++i < maxNumCoeffminus1);

            // take into account last coefficient
            coeffRuns[iNumCoeffs] = (Ipp16s) maxNumCoeffminus1;
            iNumCoeffs += 1;
        }

no_more_coefficients_label:

        if (1 == iNumCoeffs)
        {
            Ipp32u ctxIdxOffset;

            // calculate last coefficient in block
            ctxIdxOffset = ctxIdxBase[COEFF_ABS_LEVEL_MINUS1] +
                           ctxIdxBlockCatOffset[COEFF_ABS_LEVEL_MINUS1][ctxBlockCat];

            Ipp32s level = DecodeSingleSignedLevel_CABAC(ctxIdxOffset);

            // store coeff to coeff buffer
            Ipp32s pos = pScan[coeffRuns[0] + 15 - maxNumCoeffminus1];
            pPosCoefbuf[pos] = (Coeffs) level;

        }
        // reorder coefficient(s)
        else
        {
            Ipp32u numDecodAbsLevelEq1 = 0, numDecodAbsLevelGt1 = 0;
            Ipp32u ctxIdxOffset;

            // calculate last coefficient in block
            ctxIdxOffset = ctxIdxBase[COEFF_ABS_LEVEL_MINUS1] +
                           ctxIdxBlockCatOffset[COEFF_ABS_LEVEL_MINUS1][ctxBlockCat];

            do
            {
                Ipp32s level = DecodeSignedLevel_CABAC(ctxIdxOffset,
                                                       numDecodAbsLevelEq1,
                                                       numDecodAbsLevelGt1,
                                                       9);

                // store coeff to coeff buffer
                Ipp32s pos = coeffRuns[iNumCoeffs - 1];

                pos = pScan[pos + 15 - maxNumCoeffminus1];

                pPosCoefbuf[pos] = (Coeffs) level;

            } while (0 < --iNumCoeffs);
        }

    } // void ResidualBlock4x4_CABAC(H264BitStream *pBitStream,

protected:
    Status GetVUIParam(H264SeqParamSet *sps);
    Status GetHRDParam(H264SeqParamSet *sps);
    // Initialize bitstream tables
    Status InitTables(void);
    // Release bitstream tables
    void ReleaseTables(void);

    Ipp32u *m_pbs;                                              // (Ipp32u *) pointer to the current position of the buffer.
    Ipp32s m_bitOffset;                                         // (Ipp32s) the bit position (0 to 31) in the dword pointed by m_pbs.
    Ipp32u *m_pbsBase;                                          // (Ipp32u *) pointer to the first byte of the buffer.
    Ipp32u m_maxBsSize;                                         // (Ipp32u) maximum buffer size in bytes.

    IppVCHuffmanSpec_32s *(m_tblCoeffToken[5]);
    IppVCHuffmanSpec_32s *(m_tblRunBefore [16]);
    IppVCHuffmanSpec_32s *(m_tblTotalZeros[16]);

    IppVCHuffmanSpec_32s *(m_tblTotalZerosCR[4]);
    IppVCHuffmanSpec_32s *(m_tblTotalZerosCR422[8]);
    bool m_bTablesInited;                                       // (bool) tables have been allocated

    CABAC_CONTEXT context_array[460];                           // (CABAC_CONTEXT []) array of cabac context(s)
    Ipp32u m_lcodIRange;                                        // (Ipp32u) arithmetic decoding engine variable
    Ipp32u m_lcodIOffset;                                       // (Ipp32u) arithmetic decoding engine variable
    Ipp32s m_iMagicBits;                                        // (Ipp32s) available extra CABAC bits
    Ipp16u *m_pMagicBits;                                       // (Ipp16u *) pointer to CABAC data

    // Decoding SEI message functions
    Ipp32s sei_message(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s sei_payload(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s buffering_period(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s pic_timing(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s pan_scan_rect(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s filler_payload(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s user_data_registered_itu_t_t35(H264SeqParamSet **sps, Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s user_data_unregistered(H264SeqParamSet **sps, Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s recovery_point(H264SeqParamSet **sps, Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s dec_ref_pic_marking_repetition(H264SeqParamSet **sps, Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s spare_pic(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s scene_info(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s sub_seq_info(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s sub_seq_layer_characteristics(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s sub_seq_characteristics(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s full_frame_freeze(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s full_frame_freeze_release(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s full_frame_snapshot(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s progressive_refinement_segment_start(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s progressive_refinement_segment_end(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s motion_constrained_slice_group_set(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s reserved_sei_message(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
    Ipp32s unparsed_sei_message(H264SeqParamSet **sps,Ipp32s current_sps,H264SEIPayLoad *spl);
};

// disable the "conditional expression is constant" warning
#pragma warning(disable: 4127)

template <typename Coeffs, Ipp32s color_format>
class BitStreamColorSpecific
{
public:
    typedef Coeffs * CoeffsPtr;

    static inline void ResidualChromaDCBlock_CABAC(const Ipp32u *ctxIdxBase, const Ipp32s *single_scan,
                                                   Coeffs *pPosCoefbuf, H264Bitstream * bs)
    {
        // See subclause 7.3.5.3.2 of H.264 standard
        Ipp32s coef_ctr=-1;
        Ipp32s maxNumCoeffminus1;
        Ipp32u ctxIdxOffset, ctxIdxOffsetLast;
        Ipp32u numDecodAbsLevelEq1 = 0, numDecodAbsLevelGt1 = 0;
        Ipp16s coeffRuns[18];

        Ipp32s numOfCoeffs = 0;
        switch (color_format)
        {
        case 1:
            numOfCoeffs = 4;
            break;
        case 2:
            numOfCoeffs = 8;
            break;
        case 3:
            numOfCoeffs = 16;
            break;
        };

        // See table 9-32 of H.264 standard
    #ifdef __ICL
        __assume_aligned(pPosCoefbuf, 8);
    #endif
        memset(pPosCoefbuf, 0, sizeof(Coeffs) * numOfCoeffs);
        maxNumCoeffminus1 = numOfCoeffs - 1;

        ctxIdxOffset = ctxIdxBase[SIGNIFICANT_COEFF_FLAG] +
            ctxIdxBlockCatOffset[SIGNIFICANT_COEFF_FLAG][BLOCK_CHROMA_DC_LEVELS + color_format];
        ctxIdxOffsetLast = ctxIdxBase[LAST_SIGNIFICANT_COEFF_FLAG] +
            ctxIdxBlockCatOffset[LAST_SIGNIFICANT_COEFF_FLAG][BLOCK_CHROMA_DC_LEVELS + color_format];

        Ipp32u ncoefs = 0;
        Ipp32s i = 0;
        for (; i < maxNumCoeffminus1; i++)
        {
            Ipp32s k;

            if (color_format == 1)
                k = i;
            else
                k = IPP_MIN(i >> (3 & (color_format - 1)), 2);

            // get significant_coeff_flag
            if (bs->DecodeSingleBin_CABAC(ctxIdxOffset+k))
            {
                // store position of non-zero coeff
                coeffRuns[ncoefs] = (Ipp16s) i;
                // Intel compiler should use memory form of increment
                ncoefs ++;
                // get last_significant_coeff_flag
                if (bs->DecodeSingleBin_CABAC(ctxIdxOffsetLast + k))
                    break;
            }
        }

        if (i == maxNumCoeffminus1)
        {
            coeffRuns[ncoefs] = (Ipp16s) i;
            ncoefs ++;
        }

        // calculate last coefficient in block
        ctxIdxOffset = ctxIdxBase[COEFF_ABS_LEVEL_MINUS1] +
            ctxIdxBlockCatOffset[COEFF_ABS_LEVEL_MINUS1][BLOCK_CHROMA_DC_LEVELS + color_format];

        for (; ncoefs > 0; ncoefs--)
        {
            Ipp32s level = bs->DecodeSignedLevel_CABAC(ctxIdxOffset,
                                                       numDecodAbsLevelEq1,
                                                       numDecodAbsLevelGt1,8);

            // store coeff position and level to coeff buffer
            Ipp32u pos = coeffRuns[ncoefs - 1] + coef_ctr + 1;

            if (color_format != 1)
                pos = single_scan[pos];

            pPosCoefbuf[pos] = (Coeffs) level;
        }

    } // void H264Bitstream::ResidualChromaDCBlock_CABAC(const Ipp32u *ctxIdxBase,
};
#pragma warning(default: 4127)


void SetDefaultScalingLists(H264SeqParamSet * sps);

inline
void FillFlatScalingList4x4(H264ScalingList4x4 *scl)
{
    for (Ipp32s i=0;i<16;i++)
        scl->ScalingListCoeffs[i] = 16;
}

inline
void FillFlatScalingList8x8(H264ScalingList8x8 *scl)
{
    for (Ipp32s i=0;i<64;i++)
        scl->ScalingListCoeffs[i] = 16;
}

inline
void FillScalingList4x4(H264ScalingList4x4 *scl_dst,Ipp8u *coefs_src)
{
    for (Ipp32s i=0;i<16;i++)
        scl_dst->ScalingListCoeffs[i] = coefs_src[i];
}

inline
void FillScalingList8x8(H264ScalingList8x8 *scl_dst,Ipp8u *coefs_src)
{
    for (Ipp32s i=0;i<64;i++)
        scl_dst->ScalingListCoeffs[i] = coefs_src[i];
}


} // namespace UMC

#include "umc_h264_bitstream_inlines.h"

#endif // __UMC_H264_BITSTREAM_H_

#endif // UMC_ENABLE_H264_VIDEO_DECODER

⌨️ 快捷键说明

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