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

📄 swdec_shortvideo.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 3 页
字号:
------------------------------------------------------------------------------*/

u32 SwDec_CheckNextGobNumber(decContainer_t *pDecContainer)
{
    u32 tmp;

    /* if not enough bits left -> return 0 */
    if (( (i32)pDecContainer->StrmDesc.strmBuffSize*8 -
          (i32)pDecContainer->StrmDesc.strmBuffReadBits ) >= 5)
    {
        tmp = SwDec_ShowBits(pDecContainer, 5);
        if (tmp >= pDecContainer->StrmStorage.numGobsInVop)
        {
            tmp = 0;
        }
    }
    else
    {
        tmp = 0;
    }

    return (tmp);

}

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

   5.5  Function name: SwDec_DecodeGobHeader

        Purpose: decode Group Of Blocks (GOB) header
                 
        Input: 
            Pointer to decContainer_t structure

        Output:
            HANTRO_OK/HANTRO_NOK/END_OF_STREAM

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

u32 SwDec_DecodeGobHeader(decContainer_t *pDecContainer)
{
    u32 tmp,tmp2;

    tmp = SwDec_GetBits(pDecContainer,5); /* gob_number */
    CHECK_END_OF_STREAM(tmp);

    /* VpMbNumber contains expected number of first macro block in gob */
    if ( pDecContainer->StrmStorage.vpMbNumber !=
         (tmp * pDecContainer->StrmStorage.numMbsInGob) )
    {
        return(HANTRO_NOK);
    }

    /* store old gob frame id */
    tmp = pDecContainer->SvDesc.gobFrameId;

    tmp2 = SwDec_GetBits(pDecContainer,2); /* gob frame id */
    CHECK_END_OF_STREAM(tmp2);

    pDecContainer->SvDesc.gobFrameId = tmp2;

    /* sv vop header lost -> check if gob_frame_id indicates that
     * old source_format etc. are invalid and get away if this is the
     * case */
    if ( !pDecContainer->StrmStorage.validVopHeader &&
         (pDecContainer->SvDesc.gobFrameId != tmp) )
    {
        return(HANTRO_NOK);
    }

    /* QP */
    tmp = SwDec_GetBits(pDecContainer,5);
    CHECK_END_OF_STREAM(tmp);
    if (tmp == 0) return(HANTRO_NOK);

    pDecContainer->StrmStorage.QP = tmp;
    pDecContainer->StrmStorage.prevQP = tmp;
    pDecContainer->StrmStorage.vpQP = pDecContainer->StrmStorage.QP;

    pDecContainer->StrmStorage.validVopHeader = 1;

    return (HANTRO_OK);

}

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

   5.6  Function name: SwDec_InitShortVideo

        Purpose: initialize short video decoding
                 
        Input: 
            Pointer to decContainer_t structure

        Output:
            HANTRO_OK/HANTRO_NOK

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

u32 SwDec_InitShortVideo(decContainer_t *pDecContainer)
{
    u8 *pTmpStrmCurrPos;
    u32 tmpBitPosInWord;
    u32 tmpStrmBuffReadBits;
    
    ASSERT(pDecContainer);
    ASSERT(!pDecContainer->StrmStorage.strmDecReady);

#ifndef MP4DEC_H263_ONLY
    pDecContainer->StrmStorage.resyncMarkerLength = 17;
    
    pDecContainer->VopDesc.vopRoundingType = 0;
    pDecContainer->VopDesc.fcodeFwd = 1;
    pDecContainer->VopDesc.intraDcVlcThr = 0;
    pDecContainer->VopDesc.vopCoded = 1;

    pDecContainer->Hdrs.dataPartitioned = 0;
    pDecContainer->Hdrs.resyncMarkerDisable = 0;

    pDecContainer->Hdrs.colourPrimaries = 1;
    pDecContainer->Hdrs.transferCharacteristics = 1;
    pDecContainer->Hdrs.matrixCoefficients = 6;
#endif
    pDecContainer->Hdrs.vopTimeIncrementResolution = 30000;

    pDecContainer->SvDesc.gobFrameId = 0;
    pDecContainer->SvDesc.temporalReference = 0;
    pDecContainer->SvDesc.tics = 0;
    pDecContainer->SvDesc.clockDivisor = 1;
    pDecContainer->SvDesc.clockConversionCode = 1001;
    
    /* save stream decoding position */
    pTmpStrmCurrPos = pDecContainer->StrmDesc.pStrmCurrPos;
    tmpBitPosInWord = pDecContainer->StrmDesc.bitPosInWord;
    tmpStrmBuffReadBits = pDecContainer->StrmDesc.strmBuffReadBits;
    
    /* Decode header */
    if (SwDec_DecodeShortVideoHeader(pDecContainer) == HANTRO_NOK)
        return (HANTRO_NOK);

    switch(pDecContainer->SvDesc.sourceFormat)
    {
        case 1: /* sub-QCIF */
            pDecContainer->VopDesc.vopWidth = 8;
            pDecContainer->VopDesc.vopHeight = 6;
            pDecContainer->VopDesc.totalMbInVop = 48;
            pDecContainer->StrmStorage.numMbsInGob = 8;
            pDecContainer->StrmStorage.numGobsInVop = 6;
            break;

        case 2: /* QCIF */
            pDecContainer->VopDesc.vopWidth = 11;
            pDecContainer->VopDesc.vopHeight = 9;
            pDecContainer->VopDesc.totalMbInVop = 99;
            pDecContainer->StrmStorage.numMbsInGob = 11;
            pDecContainer->StrmStorage.numGobsInVop = 9;
            break;

        case 3: /* CIF */
            pDecContainer->VopDesc.vopWidth = 22;
            pDecContainer->VopDesc.vopHeight = 18;
            pDecContainer->VopDesc.totalMbInVop = 396;
            pDecContainer->StrmStorage.numMbsInGob = 22;
            pDecContainer->StrmStorage.numGobsInVop = 18;
            break;

        case 4: /* 4CIF */
            pDecContainer->VopDesc.vopWidth = 44;
            pDecContainer->VopDesc.vopHeight = 36;
            pDecContainer->VopDesc.totalMbInVop = 1584;
            pDecContainer->StrmStorage.numMbsInGob = 88;
            pDecContainer->StrmStorage.numGobsInVop = 18;
            break;

        case 5: /* 16CIF */
            pDecContainer->VopDesc.vopWidth = 88;
            pDecContainer->VopDesc.vopHeight = 72;
            pDecContainer->VopDesc.totalMbInVop = 6336;
            pDecContainer->StrmStorage.numMbsInGob = 352;
            pDecContainer->StrmStorage.numGobsInVop = 18;
            break;

        case 6: /* custom picture size */
            if(pDecContainer->SvDesc.customHeight <= 400)
            {
                pDecContainer->StrmStorage.numMbsInGob = 
                                    pDecContainer->SvDesc.customWidth/16;
                if(pDecContainer->SvDesc.customWidth%16)
                {
                    pDecContainer->StrmStorage.numMbsInGob++;
                }
                pDecContainer->StrmStorage.numGobsInVop = 
                                    pDecContainer->SvDesc.customHeight/16;
                if(pDecContainer->SvDesc.customHeight%16)
                {
                    pDecContainer->StrmStorage.numGobsInVop++;
                }
            }
            else if (pDecContainer->SvDesc.customHeight <= 800)
            {
                pDecContainer->StrmStorage.numMbsInGob = 
                                    pDecContainer->SvDesc.customWidth/16;
                if(pDecContainer->SvDesc.customWidth%16)
                {
                    pDecContainer->StrmStorage.numMbsInGob++;
                }
                pDecContainer->StrmStorage.numMbsInGob*=2;

                pDecContainer->StrmStorage.numGobsInVop = 
                                    pDecContainer->SvDesc.customHeight/32;
                if(pDecContainer->SvDesc.customHeight%32)
                {
                    pDecContainer->StrmStorage.numGobsInVop++;
                }
            }
            else
            {
                pDecContainer->StrmStorage.numMbsInGob = 
                                    pDecContainer->SvDesc.customWidth/16;
                if(pDecContainer->SvDesc.customWidth%16)
                {
                    pDecContainer->StrmStorage.numMbsInGob++;
                }
                pDecContainer->StrmStorage.numMbsInGob*=4;

                pDecContainer->StrmStorage.numGobsInVop = 
                                    pDecContainer->SvDesc.customHeight/64;
                if(pDecContainer->SvDesc.customHeight%64)
                {
                    pDecContainer->StrmStorage.numGobsInVop++;
                }
            }
            
            /* VOL size */
            pDecContainer->Hdrs.videoObjectLayerWidth = 
                                    pDecContainer->SvDesc.customWidth;
            pDecContainer->Hdrs.videoObjectLayerHeight =
                                    pDecContainer->SvDesc.customHeight;
            /* VOP size */
            pDecContainer->VopDesc.vopWidth = 
                (pDecContainer->SvDesc.customWidth+15)>>4;
            pDecContainer->VopDesc.vopHeight =
                (pDecContainer->SvDesc.customHeight+15)>>4;
            
            /* number of total MBs in VOP */
            pDecContainer->VopDesc.totalMbInVop =
                pDecContainer->VopDesc.vopWidth *
                pDecContainer->VopDesc.vopHeight;
            break;

        default:
            return(HANTRO_NOK);
    }
    
#ifndef MP4DEC_H263_ONLY
    /* set video object layer dimensions (used in motion compensation) */
    if(pDecContainer->SvDesc.sourceFormat != 6)
    {
        pDecContainer->Hdrs.videoObjectLayerWidth =
            pDecContainer->VopDesc.vopWidth * 16;
        pDecContainer->Hdrs.videoObjectLayerHeight =
            pDecContainer->VopDesc.vopHeight * 16;
    }
    pDecContainer->StrmStorage.shortVideo = 1;
    pDecContainer->Hdrs.lastHeaderType = SC_SV_START;
#endif
    /* restore stream decoding position */ 
    pDecContainer->StrmDesc.pStrmCurrPos = pTmpStrmCurrPos;
    pDecContainer->StrmDesc.bitPosInWord = tmpBitPosInWord;
    pDecContainer->StrmDesc.strmBuffReadBits = tmpStrmBuffReadBits;
    (void)SwDec_UnFlushBits(pDecContainer,22);
    
    return(HANTRO_OK);
}

⌨️ 快捷键说明

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