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

📄 swdec_motiontexture.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------
--                                                                            --
--       This software is confidential and proprietary and may be used        --
--        only as expressly authorized by a licensing agreement from          --
--                                                                            --
--                            Hantro Products Oy.                             --
--                                                                            --
--      In the event of publication, the following notice is applicable:      --
--                                                                            --
--                   (C) COPYRIGHT 2004 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--         The entire notice above must be reproduced on all copies.          --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Abstract : Motion texture decoding 
--
-------------------------------------------------------------------------------*/


/*------------------------------------------------------------------------------

    Table of contents
   
    1. Include headers
    2. External compiler flags
    3. Module defines
    4. Module identifiers
    5. Functions
        5.1     SwDec_DecodeMotionTexture
        5.2     SwDec_DecodeCombinedMT
        5.3     SwDec_DecodePartitionedIVop
        5.4     SwDec_DecodePartitionedPVop
        5.5     SwDec_DecodeMb

------------------------------------------------------------------------------*/


/*------------------------------------------------------------------------------
    1. Include headers
------------------------------------------------------------------------------*/

#include "SwDec_MotionTexture.h"
#include "SwDec_MotionTextureUtils.h"
#include "SwDec_Utils.h"
#include "SwDec_Vlc.h"
#include "SwDec_ProcessBlock.h"

/*------------------------------------------------------------------------------
    2. External compiler flags
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
    3. Module defines
------------------------------------------------------------------------------*/
#ifndef MP4DEC_H263_ONLY
enum {
    MOTION_MARKER = 0x1F001,    /* 17 bits */
    DC_MARKER = 0x6B001         /* 19 bits */
};
#endif
/*------------------------------------------------------------------------------
    4. Module identifiers 
------------------------------------------------------------------------------*/

/* value dQuantTable[i] added to QP when value of dquant is i */
static const i32 dQuantTable[4] = {-1,-2,1,2};
#ifndef MP4DEC_H263_ONLY
STATIC u32 SwDec_DecodeCombinedMT(decContainer_t *pDecContainer);
STATIC u32 SwDec_DecodePartitionedIVop(decContainer_t *pDecContainer);
STATIC u32 SwDec_DecodePartitionedPVop(decContainer_t *pDecContainer);

/*------------------------------------------------------------------------------

   5.1  Function name: SwDec_DecodeMotionTexture

        Purpose: Decode motion texture data
                 
        Input: 
            pDecContainer   Pointer to decContainer_t structure

        Output:
            HANTRO_OK/HANTRO_NOK/END_OF_STREAM

------------------------------------------------------------------------------*/

u32 SwDec_DecodeMotionTexture(decContainer_t *pDecContainer)
{

    u32 status = HANTRO_OK;

    if (!pDecContainer->Hdrs.dataPartitioned)
    {
        status = SwDec_DecodeCombinedMT(pDecContainer);
    }
    else if (pDecContainer->VopDesc.vopCodingType == IVOP)
    {
        status = SwDec_DecodePartitionedIVop(pDecContainer);
    }
    else
    {
        status = SwDec_DecodePartitionedPVop(pDecContainer);
    }

    return(status);

}

/*------------------------------------------------------------------------------

   5.2  Function name: SwDec_DecodeCombinedMT

        Purpose: Decode combined motion texture data
                 
        Input: 
            pDecContainer   Pointer to decContainer_t structure

        Output:
            HANTRO_OK/HANTRO_NOK/END_OF_STREAM

------------------------------------------------------------------------------*/

u32 SwDec_DecodeCombinedMT(decContainer_t *pDecContainer)
{

    u32 tmp;
    u32 mbNumber;
    u32 mbCounter=0;

    ASSERT(pDecContainer);
    ASSERT(!pDecContainer->Hdrs.dataPartitioned);

    mbNumber = pDecContainer->StrmStorage.vpMbNumber;
    pDecContainer->StrmStorage.vpFirstCodedMb = mbNumber;

    do {
        tmp = SwDec_DecodeMb(pDecContainer,mbNumber);
        if ( tmp!=HANTRO_OK ) return(tmp);
        if (!MB_IS_STUFFING(mbNumber))
        {
            mbNumber++;
            mbCounter++;
            /* read remaining stuffing macro blocks if end of VOP */
            if (mbNumber == pDecContainer->VopDesc.totalMbInVop)
            {
                /*lint --e(514) */
                tmp = 9 + (pDecContainer->VopDesc.vopCodingType==PVOP);
                while ( SwDec_ShowBits(pDecContainer, tmp)==0x01 )
                    (void)SwDec_FlushBits(pDecContainer, tmp); 
            }
        }
    } while ( (mbNumber < pDecContainer->VopDesc.totalMbInVop) &&
        ((SwDec_CheckStuffing(pDecContainer) != HANTRO_OK) ||
         SwDec_ShowBitsAligned(pDecContainer,16,1)) );

    pDecContainer->StrmStorage.vpNumMbs = mbCounter;

    return(HANTRO_OK);

}

/*------------------------------------------------------------------------------

   5.3  Function name: SwDec_DecodePartitionedIVop

        Purpose: Decode data partitioned motion texture data of I-VOP
                 
        Input: 
            pDecContainer   Pointer to decContainer_t structure

        Output:
            HANTRO_OK/HANTRO_NOK/END_OF_STREAM

------------------------------------------------------------------------------*/

u32 SwDec_DecodePartitionedIVop(decContainer_t *pDecContainer)
{

    u32 i,j,tmp,tmpMask;
    u32 mbNumber, mbCounter;
    i32 QP;
    u32 scanDir;
    u32 status = HANTRO_OK;

    ASSERT(pDecContainer);
    ASSERT(pDecContainer->Hdrs.dataPartitioned);
    ASSERT(pDecContainer->StrmStorage.vpMbNumber <
        pDecContainer->VopDesc.totalMbInVop);

    mbCounter = 0;
    mbNumber = pDecContainer->StrmStorage.vpMbNumber;
    pDecContainer->StrmStorage.vpFirstCodedMb = mbNumber;
    pDecContainer->StrmStorage.vpNumMbs = 0;

    do {
        status = SwDec_DecodeMcbpc(pDecContainer,mbNumber);
        if (status != HANTRO_OK) return(status);

        if (pDecContainer->MbDesc[mbNumber].typeOfMb == MB_STUFFING)
            continue;

        pDecContainer->MbDesc[mbNumber].errorStatus = 0;
        /* reset last element of mb data to indicate that no blocks has yet
         * been processed */
        pDecContainer->MbDesc[mbNumber].data[7] = 0;

        pDecContainer->StrmStorage.prevQP =
            pDecContainer->StrmStorage.QP;
        if (pDecContainer->MbDesc[mbNumber].typeOfMb == MB_INTRAQ)
        {
            tmp = SwDec_GetBits(pDecContainer,2); /* dquant */
            CHECK_END_OF_STREAM(tmp);

            QP = (i32)(pDecContainer->StrmStorage.QP) + dQuantTable[tmp];
            SATURATE(1,QP,31);
            pDecContainer->StrmStorage.QP = (u32)QP;
        }

        pDecContainer->MbDesc[mbNumber].QP =
            pDecContainer->StrmStorage.QP;

        if (SwDec_UseIntraDcVlc(pDecContainer,mbNumber))
        {
            pDecContainer->MbDesc[mbNumber].flags = 
                USE_INTRA_DC_VLC_MASK;
            for (j = 0; j < 6; j++)
            {
                status =
                    SwDec_DecodeDcCoeff(pDecContainer,mbNumber,j);
                if (status != HANTRO_OK) return(status);
            }
        }

        mbCounter++;
        mbNumber++;
        
        /* last macro block of vop -> check stuffing macro blocks */
        if (mbNumber == pDecContainer->VopDesc.totalMbInVop)
        {
            while (SwDec_ShowBits(pDecContainer,9) == 0x1)
            {
                tmp = SwDec_FlushBits(pDecContainer,9);
            }
            if (SwDec_ShowBits(pDecContainer,19) == DC_MARKER)
            {
                break;
            }
            else
            {
                return(HANTRO_NOK);
            }
        }

    } while (SwDec_ShowBits(pDecContainer,19) != DC_MARKER);
    
    status = SwDec_FlushBits(pDecContainer,19);

    pDecContainer->StrmStorage.vpNumMbs = mbCounter;

    mbNumber = pDecContainer->StrmStorage.vpMbNumber;

    for (i = mbNumber; i < (mbNumber + mbCounter); i++)
    {
        /* ac prediction flag */
        tmp = SwDec_GetOneBit(pDecContainer);
        CHECK_END_OF_STREAM(tmp);
        if (tmp)
        {
            pDecContainer->MbDesc[i].flags |= AC_PRED_FLAG_MASK;
        }

        status = SwDec_DecodeCbpy(pDecContainer,i);
        if (status != HANTRO_OK) return(status);
    }

    for (i = mbNumber; i < (mbNumber + mbCounter); i++)
    {
        /* initialize mask for block number 0 */
        tmpMask = 0x20;
        for (j = 0; j < 6; j++)
        {
            i32 scanOut[64] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

            scanDir = SwDec_ScanDir(pDecContainer, i, j);

            pDecContainer->StrmStorage.numIdctRows = 0;
            if (pDecContainer->MbDesc[i].codedBits & tmpMask)
            {

                if (pDecContainer->Hdrs.reversibleVlc)
                {
                    status = SwDec_DecodeRvlcBlock(pDecContainer,scanOut,i,
                        pDecContainer->MbDesc[i].QP, scanDir);
                }
                else
                {
                    status = SwDec_DecodeIntraVlcBlock(pDecContainer,scanOut,
                        pDecContainer->MbDesc[i].QP,
                        pDecContainer->MbDesc[i].flags &
                            USE_INTRA_DC_VLC_MASK,
                        scanDir);
                }
                if (status != HANTRO_OK) return(status);

            }

            SwDec_ProcessIntraBlock(pDecContainer,scanOut,i,j,scanDir);
            /* set i:th bit of last data element to indicate that i:th block
             * has been processed (for error concealment purposes) */
            pDecContainer->MbDesc[i].data[7] |= (i16)tmpMask;

            tmpMask >>= 1;
        }
    }

    return(status);

}

/*------------------------------------------------------------------------------

   5.4  Function name: SwDec_DecodePartitionedPVop

        Purpose: Decode data partitioned motion texture data of P-VOP
                 
        Input: 
            pDecContainer   Pointer to decContainer_t structure

        Output:
            HANTRO_OK/HANTRO_NOK/END_OF_STREAM

------------------------------------------------------------------------------*/

u32 SwDec_DecodePartitionedPVop(decContainer_t *pDecContainer)
{

    u32 i,j,tmp,tmpMask;
    u32 mbNumber, mbCounter;
    i32 QP;
    u32 scanDir;
    u32 status = HANTRO_OK;

    ASSERT(pDecContainer);
    ASSERT(pDecContainer->Hdrs.dataPartitioned);
    ASSERT(pDecContainer->StrmStorage.vpMbNumber <
        pDecContainer->VopDesc.totalMbInVop);

    mbCounter = 0;
    mbNumber = pDecContainer->StrmStorage.vpMbNumber;
    pDecContainer->StrmStorage.vpFirstCodedMb = mbNumber;
    pDecContainer->StrmStorage.vpNumMbs = 0;

    do {
        tmp = SwDec_GetOneBit(pDecContainer); /* not_coded */
        CHECK_END_OF_STREAM(tmp);

        if (!tmp)
        {
            status = SwDec_DecodeMcbpc(pDecContainer,mbNumber);
            if (status != HANTRO_OK) return(status);

            if (pDecContainer->MbDesc[mbNumber].typeOfMb == MB_STUFFING)
                continue;

            pDecContainer->MbDesc[mbNumber].errorStatus = 0;

            if (MB_IS_INTER(mbNumber))

⌨️ 快捷键说明

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