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

📄 swdec_errorconcealment.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 : Error Concealment
--
-------------------------------------------------------------------------------*/



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

    Table of contents
   
     1. Include headers
     2. External identifiers
     3. Module defines
     4. Module identifiers
     5. Fuctions
        5.1     SwDec_ErrorConcealment
        5.2     SwDec_PConcealment
        5.2     SwDec_PTextureConcealment
        5.2     SwDec_IConcealment
        5.2     SwDec_ITextureConcealment
        5.3     SwDec_MotionVectorConcealment

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

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

#include "SwDec_Container.h"
#include "SwDec_ErrorConcealment.h"
#include "SwDec_Utils.h"
#include "SwDec_ProcessBlock.h"
#include "SwDec_Idct.h"
#include "SwDec_MotionTextureUtils.h"

/*------------------------------------------------------------------------------
    2. External identifiers 
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
    3. Module defines 
------------------------------------------------------------------------------*/

enum {
    MASK_BIT0 = 0x1,
    MASK_BIT1 = 0x2
};

enum {
    EC_ABOVE,
    EC_ABOVELEFT,
    EC_ABOVERIGHT,
    EC_NOCANDO
};

/*------------------------------------------------------------------------------
    4. Module indentifiers 
------------------------------------------------------------------------------*/

STATIC void SwDec_PConcealment(decContainer_t *pDecCont, u32 mbNum);
STATIC void SwDec_IConcealment(decContainer_t *pDecCont, u32 mbNum);
STATIC void SwDec_MotionVectorConcealment(decContainer_t* pDecCont, u32 mbNum);

#ifndef MP4DEC_H263_ONLY
STATIC void SwDec_PTextureConcealment (decContainer_t *pDecCont, u32 mbNum);
STATIC void SwDec_ITextureConcealment(decContainer_t *pDecCont, u32 mbNum);
#endif
/*------------------------------------------------------------------------------

   5.1  Function name: SwDec_ErrorConcealment 

        Purpose: Perform error concealment for macro blocks [start,end]
                 
        Input:
        pDecContainer   pointer to decContainer_t
        start
        end

        Output:

------------------------------------------------------------------------------*/
void SwDec_ErrorConcealment(decContainer_t *pDecContainer, u32 start, u32 end)
{

    u32 i;
    u32 vopCodingType;

    vopCodingType = pDecContainer->VopDesc.vopCodingType;

    ASSERT(pDecContainer);
    ASSERT((vopCodingType == PVOP) || (vopCodingType == IVOP));
    ASSERT(start < pDecContainer->VopDesc.totalMbInVop);
    ASSERT(start >= pDecContainer->StrmStorage.vpMbNumber);
    ASSERT(end < pDecContainer->VopDesc.totalMbInVop);
    ASSERT(start <= end);
    ASSERT(pDecContainer->VopDesc.vopWidth);

#ifdef MP4DEC_H263_ONLY
    for (i = start; i <= end; i++)
    {
        if ( (vopCodingType == PVOP) ||
             !pDecContainer->StrmStorage.validVopHeader )
        {
            SwDec_PConcealment(pDecContainer, i);
        }
        else
        {
            SwDec_IConcealment(pDecContainer, i);
        }
    }
#else
    for (i = start; i <= end; i++)
    {
        if ( (vopCodingType == PVOP) ||
             !pDecContainer->StrmStorage.validVopHeader )
        {
            /* whole macro block lost */
            if (pDecContainer->MbDesc[i].errorStatus & MASK_BIT1)
            {
                SwDec_PConcealment(pDecContainer, i);
            }
            /* texture part lost */
            else
            {
                SwDec_PTextureConcealment(pDecContainer, i);
            }
        }
        else
        {
            /* whole macro block lost */
            if (pDecContainer->MbDesc[i].errorStatus & MASK_BIT1)
            {
                SwDec_IConcealment(pDecContainer, i);
            } 
            /* texture part lost */
            else
            {
                SwDec_ITextureConcealment(pDecContainer, i);
            }
        }
    }
#endif
    /* update number of concealed blocks */
    pDecContainer->ErrInfo.numErrMb += end - start + 1;

}

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

   5.2  Function name:SwDec_PConcealment 

        Purpose: Conceal macro block in P-VOP. Conceal motion vectors and
        perform motion compensation.
                 
        Input:
        pDecContainer   pointer to decContainer_t
        mbNum

        Output:

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

void SwDec_PConcealment(decContainer_t *pDecContainer, u32 mbNum)
{

    u32 i;
    u8 ref[64];

    pDecContainer->MbDesc[mbNum].typeOfMb = MB_INTER;
    pDecContainer->MbDesc[mbNum].flags = INTER_MB_MASK;

    SwDec_MotionVectorConcealment(pDecContainer, mbNum);

    /* get reference block for each block and write output picture */
    for (i = 0; i < 6; i++)
    {
        SwDec_GetReference(pDecContainer, ref, mbNum, i);
        SwDec_WriteInterOutput(pDecContainer, ref, mbNum, i);
    }

    /* set macro block status to concealed */
    pDecContainer->MbDesc[mbNum].errorStatus |= 0x80;

}
    
/*------------------------------------------------------------------------------

   5.3  Function name: SwDec_PTextureConcealment

        Purpose: Conceal macro block in P-VOP. Motion vectors of inter macro
        blocks are not concealed. Intra macro blocks are changed to inter and
        motion vector concealment is performed.
                 
        Input:
        pDecContainer   pointer to decContainer_t
        mbNum

        Output:

------------------------------------------------------------------------------*/
#ifndef MP4DEC_H263_ONLY
void SwDec_PTextureConcealment(decContainer_t *pDecContainer, u32 mbNum)

{

    u32 i;
    u8 ref[64];

    if (MB_IS_INTRA(mbNum))
    {
        pDecContainer->MbDesc[mbNum].typeOfMb = MB_INTER;
        pDecContainer->MbDesc[mbNum].flags = INTER_MB_MASK;
        SwDec_MotionVectorConcealment(pDecContainer, mbNum);
        /* set macro block status to concealed */
        pDecContainer->MbDesc[mbNum].errorStatus |= 0x80;
    }
    /* inter and valid motion vectors -> not concealed */
    else
        pDecContainer->MbDesc[mbNum].errorStatus &= 0x7F;

    /* motion compensation for all blocks */
    for (i = 0; i < 6; i++)
    {
        SwDec_GetReference(pDecContainer, ref, mbNum, i);
        SwDec_WriteInterOutput(pDecContainer, ref, mbNum, i);
    }

} 
#endif
/*------------------------------------------------------------------------------

   5.4  Function name:SwDec_IConcealment; 

        Purpose: Conceal macro block in I-VOP. Dc coefficient concealment is
        performed so that above coefficient is used if not on the first row,
        otherwise left coefficient is used if not on the first column and
        finally if neither of the conditions are true default coefficient
        value 1024 is used.  After that inverse dct is computed and output
        written to output picture.
                 
        Input:
        pDecContainer   pointer to decContainer_t
        mbNum

        Output:

⌨️ 快捷键说明

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