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

📄 ceapp_y264_enc.c

📁 ti的Davinic平台的DM6446的ARM测例子程序
💻 C
字号:
#include "ceapp_y264_enc.h"
//////////////////////////////////////////////////////////////////////////
int ceapp_init(ceapp_Handle *ceapphandle)
{
	/* nonzero means failure */
    int status = -1;    
	
    /* initialize Codec Engine runtime first */
    CERuntime_init();
	
    /* reset, load, and start DSP Engine */
    if ((ceapphandle->ce_Handle = Engine_open(ceapphandle->engine_Name, NULL, NULL)) == NULL) 
	{
#ifdef  LOG_MY_CE
        printf("CEapp-> ERROR: can't open engine %s\n", ceapphandle->engine_Name);
#endif
        goto INIT_FAIL;
    }
	
    /* activate DSP trace collection thread */
    TraceUtil_start(ceapphandle->engine_Name);
	
    /* allocate and initialize video encoder on the engine */
    if ((ceapphandle->enc_Handle = VIDENC_create(ceapphandle->ce_Handle, ceapphandle->engine_Name, NULL)) == NULL) 
	{
#ifdef  LOG_MY_CE
        printf("CEapp-> ERROR: can't open codec %s\n", ceapphandle->engine_Name);
#endif
        goto INIT_FAIL;
    }

	/* success */
    status = 0;     
	
INIT_FAIL:
	if (ceapphandle->enc_Handle != NULL)
	{
		VIDENC_delete(ceapphandle->enc_Handle);
		ceapphandle->enc_Handle = NULL;
	}
	if (ceapphandle->ce_Handle != NULL)
	{
		Engine_close(ceapphandle->ce_Handle);
		ceapphandle->ce_Handle = NULL;
	}
	
    return status;
}

void* ceapp_allocContigBuf(int bufSize, int bufAlign)
{
    void *buf;
	
    buf = Memory_contigAlloc(bufSize, bufAlign);

    return buf;
}

void ceapp_freeContigBuf(char *buf, int bufSize)
{
    Memory_contigFree(buf, bufSize);
}


int ceapp_validateBufSizes(ceapp_Handle *ceapphandle, int inBufSize0, int inBufSize1, int inBufSize2, int outBufSize)
{
    VIDENC_DynamicParams  encDynParams;
    VIDENC_Status         encStatus;

    Int32                 status;
	/* nonzero means failure */
    int                   retval = -1;      

    /*
     * Query the encoder.
     * This app expects the encoder to provide 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    encStatus.size = sizeof(encStatus);
    encDynParams.size = sizeof(encDynParams);

    status = VIDENC_control(ceapphandle->enc_Handle, XDM_GETSTATUS, &encDynParams, &encStatus);

    if (status != VIDENC_EOK) 
	{
#ifdef  LOG_MY_CE
        printf("CEapp-> Video Encoder control FAILED, status = %ld\n", status);
#endif
        goto VALIDATE_FAIL;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if( (encStatus.bufInfo.minNumInBufs     > 3)			||
        (encStatus.bufInfo.minInBufSize[0]  > inBufSize0)	||
        (encStatus.bufInfo.minInBufSize[1]  > inBufSize1)	||
        (encStatus.bufInfo.minInBufSize[2]  > inBufSize2)	||
        (encStatus.bufInfo.minNumOutBufs    > 1)			||
        (encStatus.bufInfo.minOutBufSize[0] > outBufSize)) 
	{
#ifdef  LOG_MY_CE
        printf("CEapp-> ERROR: encoder does not meet buffer requirements.\n");
#endif
        goto VALIDATE_FAIL;
    }

	/* success */
    retval = 0; 

VALIDATE_FAIL:

    return (retval);
}

int ceapp_encodeoneframe(ceapp_Handle *ceapphandle, char *inBufyuv[3], int inBufSize[3], char *encodedBuf, int encodedBufSize)
{
    /* declare codec I/O buffer descriptors for the codec's process() func. */
    XDM_BufDesc      inBufDesc;
    XDM_BufDesc      encodedBufDesc;
	
    /* declare in and out argument descriptors for process() */
    VIDENC_InArgs    encoderInArgs;
    VIDENC_OutArgs   encoderOutArgs;
	
    /* declare arrays describing I/O buffers and their sizes */
    XDAS_Int8*       inBufs         [ XDM_MAX_IO_BUFFERS ];
    XDAS_Int32       inBufSizes     [ XDM_MAX_IO_BUFFERS ];
    XDAS_Int8*       encodedBufs    [ XDM_MAX_IO_BUFFERS ];
    XDAS_Int32       encodedBufSizes[ XDM_MAX_IO_BUFFERS ];
	
    Int32            status;
    int              retval = -1;      /* nonzero means failure */
	
    /* define the arrays describing I/O buffers and their sizes */
    inBufs[0]          = inBufyuv[0];//y
    inBufSizes[0]      = inBufSize[0];
    inBufs[1]          = inBufyuv[1];//u
    inBufSizes[1]      = inBufSize[1];
    inBufs[2]          = inBufyuv[2];//v
    inBufSizes[2]      = inBufSize[2];
    encodedBufs[0]     = encodedBuf;//outbits
    encodedBufSizes[0] = encodedBufSize;
	
    /* define I/O buffer descriptors using lengths and addrs of arrays above */
    inBufDesc.numBufs       = 3;
    inBufDesc.bufs          = inBufs;
    inBufDesc.bufSizes      = inBufSizes;
    encodedBufDesc.numBufs  = 1;
    encodedBufDesc.bufs     = encodedBufs;
    encodedBufDesc.bufSizes = encodedBufSizes;
	
    /* fill in the input arguments structure; we have nothing for this case */
    encoderInArgs.size = sizeof(encoderInArgs);
    encoderOutArgs.size = sizeof(encoderOutArgs);
	
    /* encode the frame, pass addrs of the structures we populated above */
    status = VIDENC_process(ceapphandle->enc_Handle, &inBufDesc, &encodedBufDesc, &encoderInArgs, &encoderOutArgs);
	
    if (status == VIDENC_EOK) 
	{
        retval = 0;
    }
    else 
	{
#ifdef  LOG_MY_CE
        printf("CEapp-> VIDENC_process() failed, status = 0x%lx, "
            "extendedError = 0x%lx\n", status, encoderOutArgs.extendedError);
#endif
    }
	
    return retval;
}

void ceapp_exit(ceapp_Handle *ceapphandle)
{
	if (ceapphandle->enc_Handle != NULL)
	{
		VIDENC_delete(ceapphandle->enc_Handle);
		ceapphandle->enc_Handle = NULL;
	}

	if (ceapphandle->dec_Handle != NULL)
	{
		VIDDEC_delete(ceapphandle->dec_Handle);
		ceapphandle->dec_Handle = NULL;
	}

	if (ceapphandle->ce_Handle != NULL)
	{
		Engine_close(ceapphandle->ce_Handle);
		ceapphandle->ce_Handle = NULL;
	}
}

⌨️ 快捷键说明

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