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

📄 encstrmforming.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
字号:
/*------------------------------------------------------------------------------
--                                                                            --
--       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 2003 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--          The entire notice above must be reproduced on all copies.         --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Abstract : Encoder stream handling functions
--
-------------------------------------------------------------------------------*/


#include "basetype.h"
#include "enccontainer.h"
#include "mp4encapi.h"
#include "EncApi.h"

/*------------------------------------------------------------------------------
    
    Initialize the encoder instance for given configuration

------------------------------------------------------------------------------*/
i32 EncStrmInit(EncContainer_t * pEncCont, MP4EncCfg * pCfg)
{
    parameter_s prm;
    scheme_e scheme;
    u32 mbTotal;

    switch (pCfg->strmType)
    {
    case MPEG4_PLAIN_STRM:
    case MPEG4_VP_STRM:
    case MPEG4_VP_DP_STRM:
    case MPEG4_VP_DP_RVLC_STRM:
        scheme = MPEG4;
        break;
    case MPEG4_SVH_STRM:
        scheme = SVH;
        break;
    case H263_STRM:
        scheme = H263;
        break;
    default:
        return NOK;
    }

    EncApiParameter(&prm, scheme);

    prm.profile = pCfg->profileAndLevel;
    prm.width = pCfg->width;
    prm.height = pCfg->height;

    /* AC-prediction or macroblock rate control has to be disabled in
     * Simple Profile @ Levels 0 and 0b */
    if (prm.profile == 8 || prm.profile == 9)
	prm.acPred = NO;

    /* Maximum amount of AC-predicted macroblocks is limited:
     * Advanced Simple Profile Level 4, 396 macroblocks
     * Advanced Simple Profile Level 5, 405 macroblocks */

    mbTotal = ((prm.width + 15)/16) * ((prm.height + 15)/16);

    if (((prm.profile == 244) && (mbTotal > 396)) ||
        ((prm.profile == 245) && (mbTotal > 405)))
        prm.acPred = NO;

    prm.outRateNum = pCfg->frmRateNum;
    prm.outRateDenom = pCfg->frmRateDenom;

    switch (pCfg->strmType)
    {
    case MPEG4_PLAIN_STRM:
        break;

    case MPEG4_VP_DP_RVLC_STRM:
        prm.rvlc = YES;
    case MPEG4_VP_DP_STRM:
        prm.dataPart = YES;
    case MPEG4_VP_STRM:
        prm.vpSize = 400;  /* Default video packet size */
        prm.hec = YES;     /* HEC enabled by default */
        break;

    case MPEG4_SVH_STRM:
    case H263_STRM:
        prm.gob = 0;    /* No GOBs by default */
        break;
    }

    /* Enable VBV with standard video buffer size */
    prm.videoBufferSize = 1;

    if(EncApiInit(&pEncCont->inst, &prm) != READY)
        return NOK;

    /* Set some default values that differ from the system model */
    
    /* Disable CIR */
    pEncCont->inst.rateControl.cir.cir = 0;
        
    /* Default bitrate is maximum allowed in profile and level, 
     * limited to 4Mbps */
    pEncCont->inst.rateControl.virtualBuffer.bitPerSecond =
        MIN(pEncCont->inst.profile.bitPerSecondMax * 1000, 4000000);
    pEncCont->inst.rateControl.virtualBuffer.setFirstVop = YES;
    EncRcCheck(&pEncCont->inst.rateControl);

    /* Init pre-processing */
    pEncCont->inst.preProcess.smooth = NO;
    pEncCont->inst.preProcess.stabFrame = 0;

    /* By default the input size is the encoding size with 
     * width extended to the next multiple of 8 */
    pEncCont->inst.preProcess.lumWidthSrc = ((pCfg->width + 7) / 8) * 8;
    pEncCont->inst.preProcess.lumWidth = pCfg->width;
        
    pEncCont->inst.preProcess.lumHeightSrc =
        pEncCont->inst.preProcess.lumHeight = pCfg->height;
        
    pEncCont->inst.preProcess.horOffsetSrc = 0;
    pEncCont->inst.preProcess.verOffsetSrc = 0;

    if (EncPreProcessCheck(&pEncCont->inst.preProcess) != OK)
        return NOK;
    
    /* Init asic structure */
    pEncCont->asic.mvSadPenalty = prm.zeroMvFavor;
    pEncCont->asic.fourMvSadPenalty = prm.inter4vPenalty;
    pEncCont->asic.intraSadPenalty = prm.intraPenalty;

    pEncCont->asic.width_mb =
        (pEncCont->inst.videoObjectLayer.videoObjectLayerWidth + 15) / 16;
    pEncCont->asic.height_mb =
        (pEncCont->inst.videoObjectLayer.videoObjectLayerHeight + 15) / 16;

    if(pEncCont->inst.shortVideoHeader.header == NO)
    {
        pEncCont->asic.outsideVopMv = 1;
        pEncCont->asic.fourMV = 1;
    }
    else
    {
        pEncCont->asic.outsideVopMv = 0;
        pEncCont->asic.fourMV = 0;
    }

    return OK;
}

/*------------------------------------------------------------------------------
    
    Generate stream headers

------------------------------------------------------------------------------*/
i32 EncStrmStart(EncContainer_t * pEncCont, u32 * pBuf, u32 * size)
{
    stream_s stream;

    if(EncSetBuffer(&stream, (u8 *) pBuf, *size) != OK)
    {
        return -1;
    }

    EncVosHrd(&stream, &pEncCont->inst.visualObjectSequence);

    EncVisObHdr(&stream, &pEncCont->inst.visualObject);

    EncVidObHdr(&stream, &pEncCont->inst.videoObject);

    EncVolHdr(&stream, &pEncCont->inst.videoObjectLayer);

    if(stream.overflow != 0)
    {
        return -1;
    }

    *size = stream.byteCnt; /* return the number of bytes written */

    return 0;

}

/*------------------------------------------------------------------------------
    
    Generate stream end header

------------------------------------------------------------------------------*/
i32 EncStrmEnd(EncContainer_t * pEncCont, u32 * pBuf, u32 * size)
{
    stream_s stream;

    if(EncSetBuffer(&stream, (u8 *) pBuf, *size) != OK)
    {
        return -1;
    }

    EncVosEndHrd(&stream, &pEncCont->inst.visualObjectSequence);

    if(stream.overflow != 0)
    {
        return -1;
    }

    *size = stream.byteCnt; /* return the number of bytes written */

    return 0;

}

/*------------------------------------------------------------------------------
    
    Release stream memories

------------------------------------------------------------------------------*/
void EncStrmRelease(EncContainer_t * pEncCont)
{
    EncUserDataFree(&pEncCont->inst.visualObjectSequence.userData);

    EncUserDataFree(&pEncCont->inst.visualObject.userData);

    EncUserDataFree(&pEncCont->inst.videoObjectLayer.userData);

    EncUserDataFree(&pEncCont->inst.groupOfVideoObjectPlane.userData);

}


⌨️ 快捷键说明

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