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

📄 umc_avs_dec_bit_stream.h

📁 audio-video-codecs.rar语音编解码器
💻 H
字号:
/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007 Intel Corporation. All Rights Reserved.
//
//
*/

#ifndef __UMC_AVS_DEC_BIT_STREAM_H
#define __UMC_AVS_DEC_BIT_STREAM_H

#include "ippdefs.h"
#include "umc_avs_dec_context.h"

namespace UMC
{

//
// Entropy decoding functions
//

inline
Ipp32u GetBit(AVS_BIT_STREAM_CONTEXT *pCtx)
{
    Ipp32u res;

    // get 1 bit
    res = *(pCtx->src);
    res = (res >> pCtx->offset) & 1;

    // update variables
    pCtx->offset -= 1;
    if (0 > pCtx->offset)
    {
        pCtx->src += 1;
        pCtx->offset = 31;
    }

    return res;

} // Ipp32u GetBit(AVS_BIT_STREAM_CONTEXT *pCtx)

inline
Ipp32u GetBits(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s iNum)
{
    Ipp32u res;

    // update variables
    pCtx->offset -= iNum;

    if (0 <= pCtx->offset)
    {
        // get bits
        res = *(pCtx->src);
        res = res >> (pCtx->offset + 1);
    }
    else
    {
        pCtx->offset += 32;

        // get bits
        res = pCtx->src[1] >> pCtx->offset;
        res >>= 1;
        res += pCtx->src[0] << (31 - pCtx->offset);

        // advance source pointer
        pCtx->src += 1;
    }

    // mask required bits
    res &= ~(-1 << iNum);

    return res;

} // Ipp32u GetBits(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s iNum)

inline
Ipp32s GetSignedBits(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s iNum)
{
    Ipp32s res;

    res = GetBits(pCtx, iNum);

    // MSB is the sign bits
    // we need to clone it
    res <<= (32 - iNum);
    res >>= (32 - iNum);

    return res;

} // Ipp32s GetSignedBits(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s iNum)

inline
Ipp32u LookUpNextBit(AVS_BIT_STREAM_CONTEXT *pCtx)
{
    return (((*(pCtx->src)) >> pCtx->offset) & 1);

} // Ipp32u LookUpNextBit(AVS_BIT_STREAM_CONTEXT *pCtx)

inline
void SkipBits(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s iNum)
{
    pCtx->offset -= iNum;
    if (0 > pCtx->offset)
    {
        pCtx->src += 1;
        pCtx->offset += 32;
    }

} // void SkipBits(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s iNum)

inline
Ipp32u GetExpGolombCode(AVS_BIT_STREAM_CONTEXT *pCtx)
{
    Ipp32s leadingZeroBits = 0;
    Ipp32u CodeNum;

    // calculate leading zeros
    while (0 == LookUpNextBit(pCtx))
    {
        leadingZeroBits += 1;
        SkipBits(pCtx, 1);
    }

    // get code, which fits the scheme 1XXX
    CodeNum = GetBits(pCtx, leadingZeroBits + 1);
    CodeNum = CodeNum - 1;

    return CodeNum;

} // Ipp32u GetExpGolombCode(AVS_BIT_STREAM_CONTEXT *pCtx)

inline
Ipp32u GetUE(AVS_BIT_STREAM_CONTEXT *pCtx)
{
    return GetExpGolombCode(pCtx);

} // Ipp32u GetUE(AVS_BIT_STREAM_CONTEXT *pCtx)

inline
Ipp32s GetSE(AVS_BIT_STREAM_CONTEXT *pCtx)
{
    Ipp32s element;
    Ipp32u CodeNum;
    Ipp32s signExtended;

    // decode Exp-Glolomb code
    CodeNum = GetExpGolombCode(pCtx);

    // create signed element
    element = (CodeNum + 1) >> 1;
    signExtended = (CodeNum & 1) - 1;
    // we use simple scheme of sign restoration,
    // using one ADD and one XOR operation
    element = (element + signExtended) ^ signExtended;

    return element;

} // Ipp32s GetSE(AVS_BIT_STREAM_CONTEXT *pCtx)

inline
Ipp32u GetExpGolombCode(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s order)
{
    Ipp32s leadingZeroBits = 0;
    Ipp32u CodeNum;

    // calculate leading zeros
    while (0 == LookUpNextBit(pCtx))
    {
        leadingZeroBits += 1;
        SkipBits(pCtx, 1);
    }

    // get code, which fits the scheme 1XXX
    CodeNum = GetBits(pCtx, leadingZeroBits + 1 + order);
    CodeNum = CodeNum - (1 << order);

    return CodeNum;

} // Ipp32u GetExpGolombCode(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s order)

inline
Ipp32u GetUE(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s order)
{
    return GetExpGolombCode(pCtx, order);

} // Ipp32u GetUE(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s order)

inline
Ipp32s GetSE(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s order)
{
    Ipp32s element;
    Ipp32u CodeNum;
    Ipp32s signExtended;

    // decode Exp-Glolomb code
    CodeNum = GetExpGolombCode(pCtx, order);

    // create signed element
    element = (CodeNum + 1) >> 1;
    signExtended = (CodeNum & 1) - 1;
    // we use simple scheme of sign restoration,
    // using one ADD and one XOR operation
    element = (element + signExtended) ^ signExtended;

    return element;

} // Ipp32s GetSE(AVS_BIT_STREAM_CONTEXT *pCtx, Ipp32s order)

// forward declaration of used types
struct AVS_SEQUENCE_HEADER;
struct AVS_PICTURE_HEADER;
struct AVS_SLICE_HEADER;

// declaration of headers' parsing routines
extern
void DecodeSeqHeader(AVS_BIT_STREAM_CONTEXT *pCtx,
                     AVS_SEQUENCE_HEADER *pSeqHeader);
extern
void DecodePicHeader(AVS_BIT_STREAM_CONTEXT *pCtx,
                     AVS_SEQUENCE_HEADER *pSeqHeader,
                     AVS_PICTURE_HEADER *pPicHeader);
extern
void DecodeSlcHeader(AVS_BIT_STREAM_CONTEXT *pCtx,
                     AVS_SEQUENCE_HEADER *pSeqHeader,
                     AVS_PICTURE_HEADER *pPicHeader,
                     AVS_SLICE_HEADER *pSlcHeader);
extern
Ipp32s GetFieldNum(Ipp32u *pSlcData,
                   AVS_SEQUENCE_HEADER *pSeqHeader,
                   AVS_PICTURE_HEADER *pPicHeader);
} // namespace UMC

#endif // __UMC_AVS_DEC_BIT_STREAM_H

⌨️ 快捷键说明

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