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

📄 mp4swdecapi.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        DEC_API_TRC("MP4SwDecGetInfo# ERROR: pDecInst or pDecInfo is NULL");
        return (MP4SWDEC_PARAM_ERR);
    }
    pDecCont = (decContainer_t*)pDecInst;
    
#ifdef MP4DEC_TRACE
    sprintf(pDecCont->str, "MP4SwDecGetInfo# pDecInst %p  pDecInfo %p",
            (MP4SwDecInst *)pDecInst, (MP4SwDecInfo *)pDecInfo);
    DEC_API_TRC(pDecCont->str);
#endif

#define DEC_HDRS ((decContainer_t *)pDecInst)->Hdrs
#define DEC_STRS ((decContainer_t *)pDecInst)->StrmStorage
#define DEC_VOPD ((decContainer_t *)pDecInst)->VopDesc
#define DEC_STRD ((decContainer_t *)pDecInst)->StrmDesc

    pDecInfo->frameWidth      = DEC_VOPD.vopWidth<<4;
    pDecInfo->frameHeight     = DEC_VOPD.vopHeight<<4;
    pDecInfo->isShortVideo    = DEC_STRS.shortVideo;
    pDecInfo->profileAndLevelIndication = DEC_HDRS.profileAndLevelIndication;
    pDecInfo->videoRange      = DEC_HDRS.videoRange;
    pDecInfo->videoFormat     = DEC_HDRS.videoFormat;
    pDecInfo->vopNumber       = DEC_VOPD.vopNumber;
    pDecInfo->vopCodingType   = DEC_VOPD.vopCodingType;
    pDecInfo->resyncMarkerDisable = DEC_HDRS.resyncMarkerDisable;
    pDecInfo->vopQp          = DEC_VOPD.QP;
    pDecInfo->videoObjectLayerWidth = DEC_HDRS.videoObjectLayerWidth;
    pDecInfo->videoObjectLayerHeight = DEC_HDRS.videoObjectLayerHeight;
    
    /* length of user data fields*/
    pDecInfo->userDataVOSLen    = DEC_STRD.userDataVOSLen;
    pDecInfo->userDataVISOLen     = DEC_STRD.userDataVOLen;
    pDecInfo->userDataVOLLen    = DEC_STRD.userDataVOLLen;
    pDecInfo->userDataGOVLen    = DEC_STRD.userDataGOVLen;
    
    DEC_API_TRC("MP4SwDecGetInfo# OK");
    
    return (MP4SWDEC_OK);
    
#undef DEC_HDRS
#undef DEC_STRS
#undef DEC_VOPD
#undef DEC_STRD
    /*lint --e(550) */
}

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

        Function name: MP4SwDecGetUserData()

        Purpose:    This function is used to get user data information.
                 
        Input:      MP4SwDecInst        pDecInst   (decoder instance)
                    MP4SwDecUserConf    *userDataConfig (config structure ptr)
                    
        Output:     MP4SwDecRet

------------------------------------------------------------------------------*/
MP4SwDecRet MP4SwDecGetUserData(MP4SwDecInst        pDecInst,
                                MP4SwDecUserConf    *pUserDataConfig)
{
#ifndef MP4DEC_H263_ONLY
    decContainer_t *pDecCont;
    decStrmDesc_t strmDescBackUp;
    u32 mode = 0;
    
    if ((pDecInst == NULL) || (pUserDataConfig == NULL))
    {
        DEC_API_TRC("MP4SwDecGetUserData# ERROR: input pointer is NULL");
        return (MP4SWDEC_PARAM_ERR);
    }
    pDecCont = (decContainer_t*)pDecInst;
    
#ifdef MP4DEC_TRACE
    sprintf(pDecCont->str,"MP4SwDecGetUserData# pDecInst %p pUserDataConfig %p",
            (MP4SwDecInst *)pDecInst, (MP4SwDecUserConf *)pUserDataConfig);
    DEC_API_TRC(pDecCont->str);
#endif

    /* get backup of StrmDesc structure */
    strmDescBackUp = pDecCont->StrmDesc;
    
    switch(pUserDataConfig->userDataType)
    {
        case USER_DATA_VOS:
            mode = SC_VOS_START;
            if(pUserDataConfig->pUserDataVOS)
            {
                pDecCont->StrmDesc.pUserDataVOS = 
                            pUserDataConfig->pUserDataVOS;
            }
            else 
            {
                DEC_API_TRC("MP4SwDecGetUserData# ERROR: pUserDataVOS = NULL");
                return (MP4SWDEC_PARAM_ERR);
            }
            pDecCont->StrmDesc.userDataVOSMaxLen = 
                        pUserDataConfig->userDataVOSMaxLen;
            break;
        case USER_DATA_VISO:
            mode = SC_VISO_START;
            if(pUserDataConfig->pUserDataVISO)
            {
                pDecCont->StrmDesc.pUserDataVO = 
                            pUserDataConfig->pUserDataVISO;
            }
            else
            {
                DEC_API_TRC("MP4SwDecGetUserData# ERROR: pUserDataVISO = NULL");
                return (MP4SWDEC_PARAM_ERR);                
            }
            pDecCont->StrmDesc.userDataVOMaxLen = 
                        pUserDataConfig->userDataVISOMaxLen;
            break;
        case USER_DATA_VOL:
            mode = SC_VOL_START;
            if (pUserDataConfig->pUserDataVOL)
            {
                pDecCont->StrmDesc.pUserDataVOL = 
                            pUserDataConfig->pUserDataVOL;
            }
            else
            {
                DEC_API_TRC("MP4SwDecGetUserData# ERROR: pUserDataVOL = NULL");
                return (MP4SWDEC_PARAM_ERR);
            }
            pDecCont->StrmDesc.userDataVOLMaxLen = 
                        pUserDataConfig->userDataVOLMaxLen;
            break;
        case USER_DATA_GOV:
            mode = SC_GVOP_START;
            if (pUserDataConfig->pUserDataGOV)
            {
                pDecCont->StrmDesc.pUserDataGOV = 
                            pUserDataConfig->pUserDataGOV;
            }
            else
            {
                DEC_API_TRC("MP4SwDecGetUserData# ERROR: pUserDataGOV = NULL");
                return (MP4SWDEC_PARAM_ERR);
            }
            pDecCont->StrmDesc.userDataGOVMaxLen = 
                        pUserDataConfig->userDataGOVMaxLen;
            break;
        default:
            DEC_API_TRC("MP4SwDecGetUserData# ERROR: incorrect user data type");
            return (MP4SWDEC_PARAM_ERR);
    }

    /* set stream decoding position to start of stream buffer */
    pDecCont->StrmDesc.pStrmCurrPos = pDecCont->StrmDesc.pStrmBuffStart;
    pDecCont->StrmDesc.bitPosInWord = 0;
    pDecCont->StrmDesc.strmBuffReadBits = 0;
    
    /* search VOS, VISO, VOL or GOV start code */
    while (!IS_END_OF_STREAM(pDecCont))
    {
        if (SwDec_ShowBits32(pDecCont) == mode)
            break;

        if (SwDec_FlushBits(pDecCont, 8) == END_OF_STREAM)
        {
            DEC_API_TRC("MP4SwDecGetUserData# ERROR: no start code found");
            return (MP4SWDEC_PARAM_ERR);
        }
    }
    
    /* search user data start code */
    while (!IS_END_OF_STREAM(pDecCont))
    {
        if (SwDec_ShowBits32(pDecCont) == SC_UD_START)
            break;

        if (SwDec_FlushBits(pDecCont, 8) == END_OF_STREAM)
        {
            DEC_API_TRC("MP4SwDecGetUserData# ERROR: no user data start code");
            return (MP4SWDEC_PARAM_ERR);
        }
    }
 
    /* read and save user data */
    if ( SwDec_SaveUserData(pDecCont, mode) == HANTRO_NOK)
    {
        DEC_API_TRC("MP4SwDecGetUserData# ERROR: reading user data failed");
        return (MP4SWDEC_PARAM_ERR);
    }

    /* restore StrmDesc structure */
    pDecCont->StrmDesc = strmDescBackUp;

    /* set zeros after reading user data field */
    switch(pUserDataConfig->userDataType)
    {
        case USER_DATA_VOS:
            pDecCont->StrmDesc.userDataVOSLen = 0;
            pDecCont->StrmDesc.pUserDataVOS = 0;
            pDecCont->StrmDesc.userDataVOSMaxLen = 0;
            break;
        case USER_DATA_VISO:
            pDecCont->StrmDesc.userDataVOLen = 0;
            pDecCont->StrmDesc.pUserDataVO = 0;
            pDecCont->StrmDesc.userDataVOMaxLen = 0;
            break;
        case USER_DATA_VOL:
            pDecCont->StrmDesc.userDataVOLLen = 0;
            pDecCont->StrmDesc.pUserDataVOL = 0;
            pDecCont->StrmDesc.userDataVOLMaxLen = 0;
            break;
        case USER_DATA_GOV:
            pDecCont->StrmDesc.userDataGOVLen = 0;
            pDecCont->StrmDesc.pUserDataGOV = 0;
            pDecCont->StrmDesc.userDataGOVMaxLen = 0;
            break;
        default:
            break;
    }
#endif
    DEC_API_TRC("MP4SwDecGetUserData# OK");
    return (MP4SWDEC_OK);
}
/*------------------------------------------------------------------------------

         Function name: MP4SwDecRelease()

         Purpose:   Free reserved memories
               
         Input:     MP4SwDecInst pDecInst  (decoder instance)
                       
         Output:    None

------------------------------------------------------------------------------*/
void  MP4SwDecRelease(MP4SwDecInst pDecInst)
{
    decContainer_t *pDecCont;

    if (pDecInst == NULL)
    {
        DEC_API_TRC("MP4SwDecRelease# ERROR: pDecInst == NULL");
        return;
    }
    pDecCont = (decContainer_t*)pDecInst;
    
#ifdef MP4DEC_TRACE
    sprintf(pDecCont->str, "MP4SwDecRelease# pDecInst %p",(MP4SwDecInst *)pDecInst);
    DEC_API_TRC(pDecCont->str);
#endif

#define PTR_DECC (decContainer_t*)pDecInst

    SwDec_MemFree(PTR_DECC);
    MP4SwDecFree(PTR_DECC);

#undef PTR_DECC
    /*lint --e(550) */
}

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

         Function name: SwDec_ClearDataStructures

         Purpose:   Initialize data structures to default values 
                 
         Input:     pointer to decContainer_t 
                       
         Output: 

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

void SwDec_ClearDataStructures(decContainer_t *pDecCont)
{
#ifdef MP4DEC_TRACE
    sprintf(pDecCont->str, "SwDec_ClearDataStructures# pDecCont %p",(void*)pDecCont);
    DEC_API_TRC(pDecCont->str);
#endif


#define DEC_VOPD pDecCont->VopDesc
#define DEC_MBSD pDecCont->MbSetDesc
#define DEC_STRM pDecCont->StrmDesc
#define DEC_SVDS pDecCont->SvDesc

    pDecCont->pRef                  = NULL;
    pDecCont->pOut                  = NULL;
    pDecCont->MbDesc                = NULL;

    MP4SwDecMemset(&(pDecCont->VopDesc), 0, sizeof(decVopDesc_t));
    MP4SwDecMemset(&(pDecCont->StrmDesc), 0, sizeof(decStrmDesc_t));
    MP4SwDecMemset(&(pDecCont->ErrInfo), 0, sizeof(decErrorInfo_t));
    MP4SwDecMemset(&(pDecCont->SvDesc), 0, sizeof(decSvDesc_t));
#ifdef MP4DEC_H263_ONLY
    pDecCont->Hdrs.lock = 0;
#else
    SwDec_ClearHeaders(&(pDecCont->Hdrs));
#endif    

    DEC_API_TRC("SwDec_ClearDataStructures# OK");
    return;

#undef DEC_VOPD
#undef DEC_MBSD
#undef DEC_STRM
#undef DEC_SVDS 

}

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

    Function name: MP4SwDecGetAPIVersion()

    Purpose: This function is used to read decoder API version number.

    Input:   None

    Output:  struct { u32  major;
                      u32  minor;
                    }MP4SwDecApiVersion

------------------------------------------------------------------------------*/
MP4SwDecApiVersion MP4SwDecGetAPIVersion()
{
    MP4SwDecApiVersion decAPIVersion_t;

    decAPIVersion_t.major = MP4SWDEC_MAJOR_VERSION;
    decAPIVersion_t.minor = MP4SWDEC_MINOR_VERSION;

    return (decAPIVersion_t);
}

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

    Function name: MP4SwDecGetQPs

    Purpose: This function is used to read quantization parameters of all
             macro blocks in a VOP. QPs are read to memory pointed by
             pQpInfo->pQp argument. Note that no checking is performed on the
             size of the allocated memory but user is assumed to reserve enough
             memory to store QPs of all the macro blocks of a VOP.

    Input:   MP4SwDecInst   pDecInst    (decoder instance)
             MP4SwDecQpInfo *pQpInfo    (pointer to user allocated memory)

    Output:  MP4SwDecRet

------------------------------------------------------------------------------*/
MP4SwDecRet MP4SwDecGetQPs(MP4SwDecInst pDecInst, MP4SwDecQpInfo  *pQpInfo)
{
    u32 i,addr;
    decContainer_t *pDecCont;
    u8* pWriteQp;

    if ((pDecInst == NULL) || (pQpInfo == NULL))
    {
        DEC_API_TRC("MP4SwDecGetQPs# ERROR: pDecInst or pAddr is NULL");
        return(MP4SWDEC_PARAM_ERR);
    }   
    pDecCont = (decContainer_t*)pDecInst;
    
#ifdef MP4DEC_TRACE
    sprintf(pDecCont->str, "MP4SwDecGetQPs# pDecInst %p  pQpInfo %p",
            (MP4SwDecInst*)pDecCont, pQpInfo);
    DEC_API_TRC(pDecCont->str);
#endif

    pQpInfo->vopQp = (u8)pDecCont->VopDesc.QP;
    pWriteQp = (u8*)pQpInfo->pQp;

    /* Write QPs of macroblocks, add stuffing after each MB line
     * if now word aligned already */
    for(i = 0; i < pDecCont->VopDesc.totalMbInVop; i++)
    {
        if (i % pDecCont->VopDesc.vopWidth)
        {
            *pWriteQp = (u8)pDecCont->MbDesc[i].QP;
            pWriteQp++;
        }
        else
        {
            addr = (u32)pWriteQp;
            while((addr&0x3) != 0)
            {
                *pWriteQp = 0;
                pWriteQp++;
                addr = (u32)pWriteQp;
            }
            *pWriteQp = (u8)pDecCont->MbDesc[i].QP;
            pWriteQp++;
        }   
    } 

    DEC_API_TRC("MP4SwDecGetQPs# OK");
    return(MP4SWDEC_OK);

}

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

    Function name: MP4SwDecGetDeblockingInfo

    Purpose: This function is used to read VOP quantization parameter and
             a pointer to old (unused) reference image.

    Input:   MP4SwDecInst           pDecInst (decoder instance)
             MP4SwDecDeblockingInfo pInfo    (pointer to MP4SwDecDeblockingInfo)

    Output:  MP4SwDecRet

------------------------------------------------------------------------------*/
MP4SwDecRet MP4SwDecGetDeblockingInfo( MP4SwDecInst pDecInst, 
                                   MP4SwDecDeblockingInfo *pInfo)
    {
    decContainer_t *pDecCont;

    if ((pDecInst == NULL) || (pInfo == NULL))
    {
        DEC_API_TRC("MP4SwDecGetDeblockingInfo# ERROR: pDecInst or pInfo is NULL");
        return(MP4SWDEC_PARAM_ERR);
    }   
    pDecCont = (decContainer_t*)pDecInst;

#ifdef MP4DEC_TRACE
    sprintf(pDecCont->str, "MP4SwDecGetDeblockingInfo# pDecInst %p  pInfo %p",
            (MP4SwDecInst*)pDecInst, pInfo);
    DEC_API_TRC(pDecCont->str);
#endif

    pInfo->vopQP = (u8)pDecCont->VopDesc.QP;
    pInfo->pYuvBuffer = (u8 *)pDecCont->pRef;

    DEC_API_TRC("MP4SwDecGetDeblockingInfo# OK");

    return(MP4SWDEC_OK);
}
/*lint +e826 +e702 +e774 */

⌨️ 快捷键说明

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