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

📄 umc_h264_dec_bitstream.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*
//
//              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) 2003-2007 Intel Corporation. All Rights Reserved.
//
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_H264_VIDEO_DECODER)

#include "vm_debug.h"
#include "umc_h264_dec.h"
#include "umc_h264_bitstream.h"
#include "umc_h264_dec_coeff_token_map.h"
#include "umc_h264_dec_total_zero.h"
#include "umc_h264_dec_run_before.h"
#include "umc_h264_bitstream_inlines.h"
#include "umc_h264_dec_internal_cabac.h"

namespace UMC
{

static
const Ipp32u GetBitsMask[25] =
{
    0x00000000, 0x00000001, 0x00000003, 0x00000007,
    0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f,
    0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff,
    0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff,
    0x0000ffff, 0x0001ffff, 0x0003ffff, 0x0007ffff,
    0x000fffff, 0x001fffff, 0x003fffff, 0x007fffff,
    0x00ffffff
};

void H264Bitstream::GetOrg(Ipp32u **pbs, Ipp32u *size)
{
    *pbs       = m_pbsBase;
    *size      = m_maxBsSize;
}

void H264Bitstream::GetState(Ipp32u** pbs,Ipp32u* bitOffset)
{
    *pbs       = m_pbs;
    *bitOffset = m_bitOffset;

} // H264Bitstream::GetState()

void H264Bitstream::SetState(Ipp32u* pbs,Ipp32u bitOffset)
{
    m_pbs = pbs;
    m_bitOffset = bitOffset;

} // H264Bitstream::GetState()

H264Bitstream::H264Bitstream(Ipp8u * const pb,
                             const Ipp32u maxsize)
{
    m_pbsBase = (Ipp32u *) pb;
    m_pbs = (Ipp32u *) pb;
    m_bitOffset = 31;
    m_maxBsSize = maxsize;

    memset(m_tblCoeffToken, 0, sizeof(m_tblCoeffToken));
    memset(m_tblTotalZerosCR, 0, sizeof(m_tblTotalZerosCR));
    memset(m_tblTotalZerosCR422, 0, sizeof(m_tblTotalZerosCR422));
    memset(m_tblTotalZeros, 0, sizeof(m_tblTotalZeros));
    memset(m_tblRunBefore, 0, sizeof(m_tblRunBefore));

    m_bTablesInited = false;

} // H264Bitstream::H264Bitstream(Ipp8u * const pb,

H264Bitstream::H264Bitstream(void)
{
    m_pbs = 0;
    m_pbsBase = 0;
    m_bitOffset = 0;
    m_maxBsSize    = 0;

    memset(m_tblCoeffToken, 0, sizeof(m_tblCoeffToken));
    memset(m_tblTotalZerosCR, 0, sizeof(m_tblTotalZerosCR));
    memset(m_tblTotalZerosCR422, 0, sizeof(m_tblTotalZerosCR422));
    memset(m_tblTotalZeros, 0, sizeof(m_tblTotalZeros));
    memset(m_tblRunBefore, 0, sizeof(m_tblRunBefore));

    m_bTablesInited = false;

} // H264Bitstream::H264Bitstream(void)

H264Bitstream::~H264Bitstream()
{
    ReleaseTables();

} // H264Bitstream::~H264Bitstream()

void H264Bitstream::ReleaseTables(void)
{
    Ipp32s i;

    if (!m_bTablesInited)
        return;

    for (i = 0; i <= 4; i++ )
    {
        if (m_tblCoeffToken[i])
        {
            ippiHuffmanTableFree_32s(m_tblCoeffToken[i]);
            m_tblCoeffToken[i] = NULL;
        }
    }

    for (i = 1; i <= 15; i++)
    {
        if (m_tblTotalZeros[i])
        {
            ippiHuffmanTableFree_32s(m_tblTotalZeros[i]);
            m_tblTotalZeros[i] = NULL;
        }
    }

    for(i = 1; i <= 3; i++)
    {
        if(m_tblTotalZerosCR[i])
        {
            ippiHuffmanTableFree_32s(m_tblTotalZerosCR[i]);
            m_tblTotalZerosCR[i] = NULL;
        }
    }

    for(i = 1; i <= 7; i++)
    {
        if(m_tblTotalZerosCR422[i])
        {
            ippiHuffmanTableFree_32s(m_tblTotalZerosCR422[i]);
            m_tblTotalZerosCR[i] = NULL;
        }
    }

    for(i = 1; i <= 7; i++)
    {
        if(m_tblRunBefore[i])
        {
            ippiHuffmanTableFree_32s(m_tblRunBefore[i]);
            m_tblRunBefore[i] = NULL;
        }
    }
    for(; i <= 15; i++)
    {
        m_tblRunBefore[i] = NULL;
    }

    m_bTablesInited = false;

} // void H264Bitstream::ReleaseTable(void)

Status H264Bitstream::InitTables(void)
{
    IppStatus ippSts;

    // check tables allocation status
    if (m_bTablesInited)
        return UMC_OK;

    // release tables before initialization
    ReleaseTables();

    //
    // number Coeffs and Trailing Ones map tables allocation
    //

    ippSts = ippiHuffmanRunLevelTableInitAlloc_32s(coeff_token_map_02, &m_tblCoeffToken[0]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanRunLevelTableInitAlloc_32s(coeff_token_map_24, &m_tblCoeffToken[1]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanRunLevelTableInitAlloc_32s(coeff_token_map_48, &m_tblCoeffToken[2]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanRunLevelTableInitAlloc_32s(coeff_token_map_cr, &m_tblCoeffToken[3]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanRunLevelTableInitAlloc_32s(coeff_token_map_cr2, &m_tblCoeffToken[4]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    //
    // TotalZeros tables allocation
    //

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr1, &m_tblTotalZerosCR[1]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr2, &m_tblTotalZerosCR[2]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr3, &m_tblTotalZerosCR[3]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr422_1, &m_tblTotalZerosCR422[1]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr422_2, &m_tblTotalZerosCR422[2]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr422_3, &m_tblTotalZerosCR422[3]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr422_4, &m_tblTotalZerosCR422[4]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr422_5, &m_tblTotalZerosCR422[5]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr422_6, &m_tblTotalZerosCR422[6]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_cr422_7, &m_tblTotalZerosCR422[7]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_1, &m_tblTotalZeros[1]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_2, &m_tblTotalZeros[2]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_3, &m_tblTotalZeros[3]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_4, &m_tblTotalZeros[4]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_5, &m_tblTotalZeros[5]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_6, &m_tblTotalZeros[6]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_7, &m_tblTotalZeros[7]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_8, &m_tblTotalZeros[8]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_9, &m_tblTotalZeros[9]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_10, &m_tblTotalZeros[10]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_11, &m_tblTotalZeros[11]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_12, &m_tblTotalZeros[12]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_13, &m_tblTotalZeros[13]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_14, &m_tblTotalZeros[14]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(total_zeros_map_15, &m_tblTotalZeros[15]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    //
    // Run Befores tables allocation
    //

    ippSts = ippiHuffmanTableInitAlloc_32s(run_before_map_1, &m_tblRunBefore[1]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(run_before_map_2, &m_tblRunBefore[2]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(run_before_map_3, &m_tblRunBefore[3]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(run_before_map_4, &m_tblRunBefore[4]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(run_before_map_5, &m_tblRunBefore[5]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(run_before_map_6, &m_tblRunBefore[6]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    ippSts = ippiHuffmanTableInitAlloc_32s(run_before_map_6p, &m_tblRunBefore[7]);
    if (ippStsNoErr != ippSts)
        return UMC_ERR_ALLOC;

    m_tblRunBefore[8]  = m_tblRunBefore[7];
    m_tblRunBefore[9]  = m_tblRunBefore[7];
    m_tblRunBefore[10] = m_tblRunBefore[7];
    m_tblRunBefore[11] = m_tblRunBefore[7];
    m_tblRunBefore[12] = m_tblRunBefore[7];
    m_tblRunBefore[13] = m_tblRunBefore[7];
    m_tblRunBefore[14] = m_tblRunBefore[7];
    m_tblRunBefore[15] = m_tblRunBefore[7];

    m_bTablesInited = true;

    return UMC_OK;

} // Status H264Bitstream::InitTables(void)

bool H264Bitstream::Init(void)
{
    // check decoding tables status
    if (UMC_OK != InitTables())
        return false;

    return true;

} // bool H264Bitstream::Init(void)

void H264Bitstream::Reset(Ipp8u * const pb, const Ipp32u maxsize)
{
    m_pbs       = (Ipp32u*)pb;
    m_pbsBase   = (Ipp32u*)pb;
    m_bitOffset = 31;
    m_maxBsSize    = maxsize;

} // void H264Bitstream::Reset(Ipp8u * const pb, const Ipp32u maxsize)

void H264Bitstream::Reset(Ipp8u * const pb, Ipp32s offset, const Ipp32u maxsize)

⌨️ 快捷键说明

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