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

📄 encapi.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 2004 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--          The entire notice above must be reproduced on all copies.         --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Description : Encoder internal
--
-------------------------------------------------------------------------------*/



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

    Table of context

    1. Include headers
    2. External compiler flags
    3. Module defines
    4. Local function prototypes
    5. Functions
        5.1  MP4API_EncoderInit

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


/*------------------------------------------------------------------------------
    1. Include headers
------------------------------------------------------------------------------*/
#include "basetype.h"
#include "EncSim.h"
#include "EncApi.h"

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

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

/*------------------------------------------------------------------------------
    4. Local function prototypes
------------------------------------------------------------------------------*/
static bool_e CheckParameter(instance_s *inst);
static bool_e SetParameter(instance_s *inst, parameter_s *prm);
static bool_e InitHdr(instance_s *inst, scheme_e scheme);

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

	EncApiParameter

	Function return parameter structure.

	Input	scheme	Specifies encoding scheme.

	Return	parameter_s

------------------------------------------------------------------------------*/
status_e EncApiParameter(parameter_s *prm, scheme_e scheme)
{
	i32 schemePrm[4] = {1,0,1,0};

	if ((scheme < MPEG4) || (scheme > H263)) {
		return ERROR;
	}

	prm->scheme = scheme;
	prm->profile = 51;
	prm->width = 176;
	prm->height = 144;
	prm->outRateNum = 30;
	prm->outRateDenom = 1;
	prm->vpSize = 0;
	prm->dataPart = 0;
	prm->rvlc = 0;
	prm->hec = 0;
	prm->gob = 0;
	prm->cir = 127;
	prm->intraDcTrc = 0;
	prm->acPred = schemePrm[scheme];
	prm->mvRange = 0;
	prm->mvOutVop = schemePrm[scheme];
	prm->fourMv = schemePrm[scheme];
	prm->zeroMvFavor = 2;
	prm->inter4vPenalty = 5;
	prm->intraPenalty = 11;
	prm->timeHour = 0;
	prm->timeMinute = 0;
	prm->timeSecond = 0;
	prm->bitPerSecond = 64000;
	prm->vopRc = 1;
	prm->mbRc = 1;
	prm->videoBufferSize = 0;
	prm->vopSkip = 0;
	prm->qpHdr = 10;
	prm->qpHdrMin = 1;
	prm->qpHdrMax = 31;

	return READY;
}

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

	EncApiInit

	Function initializes the Encoder and create new encoder instance.

	Input	scheme	Specifies encoding scheme.

	Return	void *	Pointer to the encoder instance. If initialization fail
			return value is NULL pointer.

------------------------------------------------------------------------------*/
status_e EncApiInit(instance_s *inst, parameter_s *prm)
{
	ASSERT(inst != NULL && prm != NULL);

	EncVosInit(&inst->visualObjectSequence);
	EncVisObInit(&inst->visualObject);
	EncVolInit(&inst->videoObjectLayer);
	EncVopInit(&inst->videoObjectPlane);
	EncSvhInit(&inst->shortVideoHeader);
	EncGoVopInit(&inst->groupOfVideoObjectPlane);

	/* Stream headers depending scheme */
	if (InitHdr(inst, (scheme_e)prm->scheme) != OK) {
		return ERROR;
	}

	/* Set parameters depending of user parameter */
	if (SetParameter(inst, prm) != OK) {
		return ERROR;
	}

	/* Check and init the rest of parameters */
	if (CheckParameter(inst) != OK) {
		return ERROR;
	}

	return READY;
}

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

	InitHdr

------------------------------------------------------------------------------*/
bool_e InitHdr(instance_s *inst, scheme_e scheme)
{
	bool_e status  = OK;

	switch (scheme) {
		case MPEG4:
			inst->visualObjectSequence.header = YES;
			inst->visualObject.header = YES;
			inst->videoObject.header = YES;
			inst->videoObjectLayer.header = YES;
			inst->videoObjectPlane.header = YES;
			inst->shortVideoHeader.header = NO;
			inst->groupOfVideoObjectPlane.header = NO;
			break;
		case SVH:
			inst->visualObjectSequence.header = YES;
			inst->visualObject.header = YES;
			inst->videoObject.header = YES;
			inst->videoObjectLayer.header = NO;
			inst->videoObjectPlane.header = NO;
			inst->shortVideoHeader.header = YES;
			inst->groupOfVideoObjectPlane.header = NO;
			break;
		case MOMYSYS:
			inst->visualObjectSequence.header = NO;
			inst->visualObject.header = NO;
			inst->videoObject.header = YES;
			inst->videoObjectLayer.header = YES;
			inst->videoObjectPlane.header = YES;
			inst->shortVideoHeader.header = NO;
			inst->groupOfVideoObjectPlane.header = YES;
			break;
		case H263:
			inst->visualObjectSequence.header = NO;
			inst->visualObject.header = NO;
			inst->videoObject.header = NO;
			inst->videoObjectLayer.header = NO;
			inst->videoObjectPlane.header = NO;
			inst->shortVideoHeader.header = YES;
			inst->groupOfVideoObjectPlane.header = NO;
			break;
		default:
			status = NOK;
			break;
	}

	return status;
}

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

	SetParameter

------------------------------------------------------------------------------*/
bool_e SetParameter(instance_s *inst, parameter_s *prm)
{
	i32 width, height;

	inst->visualObjectSequence.profile = prm->profile;

	inst->videoObjectLayer.videoObjectLayerWidth = prm->width;
	inst->videoObjectLayer.videoObjectLayerHeight = prm->height;
	inst->videoObjectLayer.vopTimeIncRes = prm->outRateNum;
	inst->videoObjectLayer.fixedVopTimeInc = prm->outRateDenom;
	inst->videoObjectLayer.dataPart = (true_e)prm->dataPart;
	inst->videoObjectLayer.rvlc = (true_e)prm->rvlc;
	if (prm->vpSize > 0) {
		inst->videoObjectLayer.resyncMarkerDisable = NO;
	} else {
		inst->videoObjectLayer.resyncMarkerDisable = YES;
	}

	inst->videoObjectPlane.vopTimeIncRes = prm->outRateNum;
	inst->videoObjectPlane.hec = (true_e)prm->hec;
	inst->videoObjectPlane.intraDcVlcThr = prm->intraDcTrc;
	inst->videoObjectPlane.acPred = (true_e)prm->acPred;
        inst->videoObjectPlane.vopFcodeForward = 1;

	inst->timeCode.vopTimeIncRes = prm->outRateNum;
	inst->timeCode.fixedVopTimeInc = prm->outRateDenom;
	inst->timeCode.timeInc = prm->outRateDenom;
	inst->timeCode.timeCodeHours = prm->timeHour;
	inst->timeCode.timeCodeMinutes = prm->timeMinute;
	inst->timeCode.timeCodeSecond = prm->timeSecond;
	inst->timeCode.svHdr = inst->shortVideoHeader.header;
	inst->timeCode.vopTimeInc = 0;
	inst->timeCode.tempRefRem = 0;

	width  = 16*((inst->videoObjectLayer.videoObjectLayerWidth+15)/16);
	height = 16*((inst->videoObjectLayer.videoObjectLayerHeight+15)/16);

	/* Profile */
	inst->profile.width = width;
	inst->profile.height = height;
	inst->profile.vopTimeIncRes = prm->outRateNum;
	inst->profile.timeInc = prm->outRateDenom;
	inst->profile.profile = prm->profile;
	inst->profile.vpSize = prm->vpSize;
	inst->profile.dataPart = (true_e)prm->dataPart;
	inst->profile.mvRange = prm->mvRange;
	inst->profile.intraDcVlcThr = prm->intraDcTrc;
	inst->profile.mbRc = (true_e)prm->mbRc;
	inst->profile.acPred = (true_e)prm->acPred;
	inst->profile.bitPerSecond = prm->bitPerSecond;
	inst->profile.videoBufferSize = prm->videoBufferSize;

	/* Rate control */
	inst->rateControl.virtualBuffer.bitPerSecond = prm->bitPerSecond;
	inst->rateControl.virtualBuffer.timeInc = prm->outRateDenom;
	inst->rateControl.virtualBuffer.vopTimeIncRes = prm->outRateNum;
	inst->rateControl.virtualBuffer.setFirstVop = YES;
	inst->rateControl.vopRc = (true_e)prm->vopRc;
	inst->rateControl.mbRc = (true_e)prm->mbRc;
	inst->rateControl.vopSkip = (true_e)prm->vopSkip;
	inst->rateControl.qpHdr = prm->qpHdr;
	inst->rateControl.qpHdrPrev[0] = prm->qpHdr;
	inst->rateControl.qpHdrPrev[1] = prm->qpHdr;
	inst->rateControl.qpHdrMin = prm->qpHdrMin;
	inst->rateControl.qpHdrMax = prm->qpHdrMax;
	inst->rateControl.cir.cir = prm->cir;
	inst->rateControl.vopTypeCur = IVOP;
	inst->rateControl.vopTypePrev = IVOP;
	inst->rateControl.vopCoded = YES;
	inst->rateControl.width = width;
	inst->rateControl.height = height;
	inst->rateControl.mbPerVop = (width/16)*(height/16);
	inst->rateControl.coeffCnt = (width/16)*(height/16)*64*6;

	/* Short video header */
	inst->shortVideoHeader.gobPlace = prm->gob;
	inst->shortVideoHeader.videoObjectLayerWidth = prm->width;
	inst->shortVideoHeader.videoObjectLayerHeight = prm->height;

	return OK;
}

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

	CheckParameter

	Check and init parameters.

------------------------------------------------------------------------------*/
bool_e CheckParameter(instance_s *inst)
{
	/* Check H263 */
	if (EncSvhCheck(&inst->shortVideoHeader) != OK) {
		return NOK;
	}

	/* Check TimeCode */
	if (EncTimeCodeCheck(&inst->timeCode) != OK) {
		return NOK;
	}

	/* Init Profile and Level */
	if (EncInitProfile(&inst->profile) != OK) {
		return NOK;
	}

	/* Check Profile and Level */
	if (EncProfileCheck(&inst->profile) != OK) {
		return NOK;
	}

	/* Init rate control */
	inst->rateControl.videoBuffer.videoBufferSize =
		inst->profile.videoBufferSize;
	inst->rateControl.videoBuffer.videoBufferBitCnt =
		inst->profile.videoBufferBitCnt;
	if (EncRcCheck(&inst->rateControl) != OK) {
		return NOK;
	}

	return OK;
}

⌨️ 快捷键说明

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