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

📄 video_encoder.c

📁 TI workshop 培训资料。 是关于如何创建DAVINCI平台下codec engine
💻 C
字号:
/* * video_encoder.c *//* Standard Linux headers */#include <stdio.h>		// always include stdio.h#include <stdlib.h>		// always include stdlib.h#include <string.h>             // defines memset and memcpy methods/* Codec Engine headers */#include <xdc/std.h>			// xdc base definitions. Must come 1st#include <ti/sdo/ce/Engine.h>		// required for any CE application#include <ti/sdo/ce/video/videnc.h>	// defines video encoder methods/*  Application header files */#include "debug.h"		// DBG and ERR macros#include "video_encoder.h"	// video encoder functions, must be included				//       after codec engine headers!/* Macro for clearing structures */#define CLEAR(x) memset (&(x), 0, sizeof (x))/****************************************************************************** * video_encoder_setup ******************************************************************************//*  input parameters:                                                         *//*      Engine_Handle engineHandle  --  handle to the open codec engine       *//*                                      containing the video encoder          *//*      char *encoderName           --  name of the video encoder to create   *//*      VIDENC_Handle *encoderHandleByRef -- a video encoder handle passed by *//*                                      reference. Used to return the handle  *//*                                      of the newly created video encoder    *//*                                                                            *//*                                                                            *//*  return value:                                                             *//*      int  --  VENC_SUCCESS or VENC_FAILURE as defined in video_encoder.h   *//*                                                                            *//******************************************************************************/int video_encoder_setup(Engine_Handle engineHandle, char *encoderName,				VIDENC_Handle *encoderHandleByRef){    VIDENC_Handle encoderHandle;	// handle to the video encoder instance    /* Create video encoder instance */    encoderHandle = VIDENC_create(engineHandle, encoderName, NULL);    if (encoderHandle == NULL) {        ERR("Can't open encode algorithm: %s\n", encoderName);        return VENC_FAILURE;    }    DBG("Created video encoder instance of %s\n", encoderName);    DBG("\tWith handle %p\n", encoderHandle);    DBG("\tUsing default static and dynamic parameters\n");    /* return the decoder instance handle through the provided pointer */    *encoderHandleByRef = encoderHandle;    /* indicate successful completion of function with return value */    return VENC_SUCCESS;}/****************************************************************************** * encode_video ******************************************************************************//*  input parameters:                                                         *//*      VIDENC_Handle encoderHandle  --  handle to the video encoder as       *//*                                       returned by video_encoder_setup        *//*      char *inputBuffer            --  pointer to buffer of input data      *//*      int inputSize                --  size of inputBuffer in bytes         *//*      char *outputBuffer           --  pointer to output buffer             *//*      int outputSizeByRef          --  used as both an input and output     *//*                                       on input: size of outputBuffer       *//*                                       on output: size of encoded data      *//*                                                                            *//*                                                                            *//*  return value:                                                             *//*      int  --  VENC_SUCCESS or VENC_FAILURE as defined in video_encoder.h   *//*                                                                            *//******************************************************************************/int encode_video(VIDENC_Handle encoderHandle, char *inputBuffer, int inputSize,                             char *outputBuffer, int *outputSizeByRef){/* Declare arguments and return value for VIDDEC_process  */    VIDENC_InArgs           inArgs;	// input args for VIDENC_process    VIDENC_OutArgs          outArgs;	// output (return) from VIDENC_process    XDM_BufDesc             inBufDesc;	// buffer descriptor for input buffer    XDM_BufDesc             outBufDesc;	// buffer descriptor for output buffer    XDAS_Int32              status;	// success or failure for VIDENC_process	/* Declare buffer descriptor elements */    XDAS_Int32      inBufSizeArray[1];	// pointed to by inBufDesc.bufSizes    XDAS_Int32      outBufSizeArray[1];	// pointed to by outBufDesc.bufSizes/* Fill in input buffer descriptor */    inBufSizeArray[0]       = inputSize;    inBufDesc.numBufs       = 1;			// one input buffer    inBufDesc.bufSizes      = inBufSizeArray;		// of this size    inBufDesc.bufs          = (XDAS_Int8 **) &inputBuffer;  // located here/* Fill in output buffer descriptor */    outBufSizeArray[0]      = *outputSizeByRef;    outBufDesc.numBufs      = 1;			// one output buffer    outBufDesc.bufSizes     = outBufSizeArray;		// of this size    outBufDesc.bufs         = (XDAS_Int8 **) &outputBuffer;  // located here/*  Fill in input arguments structure */    inArgs.size             = sizeof(VIDENC_InArgs);/*  Specify size of output arguments (return) structure */    outArgs.size            = sizeof(VIDENC_OutArgs);    /* Encode video buffer */    status = VIDENC_process(encoderHandle, &inBufDesc, &outBufDesc,                            &inArgs, &outArgs);    if (status != VIDENC_EOK) {        ERR("VIDENC_process() failed with a fatal error (%ld ext: %#lx\n",            status, outArgs.extendedError);        return VENC_FAILURE;    }    /* Return size of encoded buffer through the provided pointer */    *outputSizeByRef = outArgs.bytesGenerated;    /* return VENC_SUCCESS if video encoder executes correctly */    return VENC_SUCCESS;}/****************************************************************************** * video_encoder_cleanup ******************************************************************************//*  input parameters:                                                         *//*      VIDENC_Handle encoderHandle  --  handle to the video encoder as       *//*                                       returned by video_encoder_setup        *//*                                                                            *//*                                                                            *//*  return value:                                                             *//*      int  --  always returns VENC_SUCCESS as defined in video_encoder.h    *//*                                                                            *//******************************************************************************/int video_encoder_cleanup(VIDENC_Handle encoderHandle){    VIDENC_Status status;    VIDENC_DynamicParams dynParams;    /*  Zero out the status and dynParams structures */    CLEAR(status);    CLEAR(dynParams);    /*  Set size field of status and dynParams */    status.size = sizeof(VIDENC_Status);    dynParams.size = sizeof(VIDENC_DynamicParams);    /*  Query encoder for status */    VIDENC_control(encoderHandle, XDM_GETSTATUS, &dynParams, &status);    /*  Delete encoder instance */    VIDENC_delete(encoderHandle);    /*  Report any errors */    if(status.extendedError){	ERR("Deleted video encoder instance with handle %#0lx\n", 					(unsigned long) encoderHandle);	ERR("\tEncoder exited with error mask %#0x\n", 					(unsigned int) status.extendedError );    }    else{        DBG("Deleted video encoder instance with handle %#0lx\n", 					(unsigned long) encoderHandle);	DBG("\tEncoder exited with no errors\n");    }    /* Return success */    return VENC_SUCCESS;}

⌨️ 快捷键说明

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