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

📄 video_decoder.c

📁 TI workshop 培训资料。 是关于如何创建DAVINCI平台下h.264 codec
💻 C
字号:
/* * video_decoder.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/viddec.h>	// defines video decoder methods/* Application headers */#include "debug.h"		// DBG and ERR macros#include "video_decoder.h"      // video decoder definitions, must be included				//     after codec engine headers!/* Macro for clearing structures */#define CLEAR(x) memset (&(x), 0, sizeof (x))/****************************************************************************** * video_decoder_setup ******************************************************************************//*  input parameters:                                                         *//*      Engine_Handle engineHandle  --  handle to the codec engine            *//*      char *decoderName           --  name of video decoder to create       *//*      VIDDEC_Handle *decoderHandleByRef -- video decoder handle passed by   *//*                                   reference, used to return the handle of  *//*                                   the decoder created by this function.    *//*      int frameWidth              -- width of the video frames decoded      *//*      int frameHeight             -- height of the video frames decoded     *//*      int *minInputSizeByRef      -- used to return the minimum input       *//*                                     (encoded) buffer size the decoder will *//*                                     accept.                                *//*                                                                            *//*                                                                            *//*  return value:                                                             *//*      int  --  VDEC_SUCCESS or VDEC_FAILURE as defined in video_decoder.h   *//*                                                                            *//******************************************************************************/int video_decoder_setup(Engine_Handle engineHandle, char *decoderName, 				VIDDEC_Handle *decoderHandleByRef, 				int frameWidth, int frameHeight,				int *minInputSizeByRef){    VIDDEC_Handle decoderHandle;	// handle to the video decoder instance    VIDDEC_Params           params;     // static parameters for video decoder    VIDDEC_DynamicParams    dynamicParams; // required for VIDDEC_control call    VIDDEC_Status           decStatus;  // provides buffer information    XDAS_Int32 		    status;      // return val of VIDDEC_control    /* Set video decoder static parameters */    CLEAR(params);    params.size              = sizeof(VIDDEC_Params);    params.dataEndianness    = XDM_BYTE;    params.forceChromaFormat = XDM_YUV_422ILE;    params.maxFrameRate	     = 0;    params.maxBitRate        = 0;    params.maxHeight         = frameHeight;    params.maxWidth          = frameWidth;    /* Create video decoder instance */    decoderHandle = VIDDEC_create(engineHandle, decoderName, &params);    if (decoderHandle == NULL) {        ERR("Can't open decode algorithm: %s\n", decoderName);        return VDEC_FAILURE;    }    DBG("Created video decoder instance of %s\n", decoderName);    DBG("\tWith handle %p\n", decoderHandle);    DBG("\tUsing default static and dynamic parameters\n");    /* set up dynamicParams and decStatus for call */    CLEAR(dynamicParams);    dynamicParams.size = sizeof(VIDDEC_DynamicParams);    CLEAR(decStatus);    decStatus.size = sizeof(VIDDEC_Status);    dynamicParams.decodeHeader = XDM_DECODE_AU;    dynamicParams.displayWidth = 0;    dynamicParams.frameSkipMode = IVIDEO_NO_SKIP;    /*  The H.264 encoder and decoder must be both created before any  */    /*      control or process calls are made on either due to a known */    /*      scratch memory sharing issue.                              */    status = VIDDEC_control(decoderHandle, XDM_SETPARAMS, &dynamicParams,			    &decStatus);    if (status != VIDDEC_EOK) {        ERR("XDM_SETPARAMS failed, extended error=%#x\n", 				decStatus.extendedError);        VIDDEC_delete(decoderHandle);	*decoderHandleByRef = NULL;        return VDEC_FAILURE;    }    /* Get buffer information from video decoder */    status = VIDDEC_control(decoderHandle, XDM_GETBUFINFO, &dynamicParams,                            &decStatus);    if (status != VIDDEC_EOK) {        ERR("XDM_GETBUFINFO failed, extended error=%#x\n", 				decStatus.extendedError);        VIDDEC_delete(decoderHandle);	*decoderHandleByRef = NULL;        return VDEC_FAILURE;    }    /* return the decoder instance handle and minimum input buffer size */    *decoderHandleByRef = decoderHandle;    *minInputSizeByRef = decStatus.bufInfo.minInBufSize[0];    /* indicate successful completion of function with return value */    return VDEC_SUCCESS;}/****************************************************************************** * decode_video ******************************************************************************//*  input parameters:                                                         *//*      VIDDEC_Handle decoderHandle  --  handle to the speech decoder as      *//*                                       returned by video_decoder_setup        *//*      char *inputBuffer            --  pointer to buffer of input data      *//*      int inputSize                --  size of inputBuffer in bytes         *//*      char *outputBuffer           --  pointer to output buffer             *//*      int outputSize               --  size of outputBuffer in bytes        *//*                                                                            *//*                                                                            *//*  return value:                                                             *//*      int  --  VDEC_SUCCESS or VDEC_FAILURE as defined in video_decoder.h   *//*                                                                            *//******************************************************************************/int decode_video(VIDDEC_Handle decoderHandle, char *inputBuffer,                             int inputSize, char *outputBuffer, int outputSize){/* Declare arguments and return value for VIDDEC_process  */    VIDDEC_InArgs           inArgs;	// input args for VIDDEC_process    VIDDEC_OutArgs          outArgs;	// output (return) from VIDDEC_process    XDM_BufDesc             inBufDesc;	// buffer descriptor for input buffer    XDM_BufDesc             outBufDesc;	// buffer descriptor for output buffer    XDAS_Int32              status;	// success or failure for VIDDEC_process/* Declare buffer descriptor elements */    XDAS_Int32      inputSizeArray[1];	// pointed to by inBufDesc.bufSizes    XDAS_Int32      outputSizeArray[1]; // pointed to by outBufDesc.bufSizes/* Fill in input buffer descriptor */    inputSizeArray[0]       = inputSize;    inBufDesc.numBufs       = 1;			// one input buffer    inBufDesc.bufSizes      = inputSizeArray;		// of this size    inBufDesc.bufs          = (XDAS_Int8 **) &inputBuffer;	// located here/* Fill in output buffer descriptor */    outputSizeArray[0]      = outputSize;    outBufDesc.numBufs      = 1;			// one output buffer    outBufDesc.bufSizes     = outputSizeArray;		// of this size    outBufDesc.bufs         = (XDAS_Int8 **) &outputBuffer;	// located here/*  Fill in input arguments structure  */    inArgs.size             = sizeof(VIDDEC_InArgs);    inArgs.numBytes         = inputSize;    inArgs.inputID          = 0;/*  Specify size of output arguments (return) structure */    outArgs.size            = sizeof(VIDDEC_OutArgs);    /* Decode video buffer */    status = VIDDEC_process(decoderHandle, &inBufDesc, &outBufDesc,                            &inArgs, &outArgs);    if (status != VIDDEC_EOK) {        ERR("VIDDEC_process() failed with a fatal error (%ld ext: %#lx\n",            status, outArgs.extendedError);        return VDEC_FAILURE;    }    /* return VDEC_SUCCESS if video decoder executes correctly */    return VDEC_SUCCESS;}/****************************************************************************** * video_decoder_cleanup ******************************************************************************//*  input parameters:                                                         *//*      AUDDEC_Handle decoderHandle  --  handle to the video decoder as       *//*                                       returned by video_decoder_setup        *//*                                                                            *//*                                                                            *//*  return value:                                                             *//*      int  --  always returns VDEC_SUCCESS as defined in video_decoder.h    *//*                                                                            *//******************************************************************************/int video_decoder_cleanup(VIDDEC_Handle decoderHandle){    VIDDEC_Status status;    VIDDEC_DynamicParams dynParams;    /*  Zero out the status and dynParams structures */    CLEAR(status);    CLEAR(dynParams);    /*  Set size field of status and dynParams */    status.size = sizeof(VIDDEC_Status);    dynParams.size = sizeof(VIDDEC_DynamicParams);    /*  Query decoder for status */    VIDDEC_control(decoderHandle, XDM_GETSTATUS, &dynParams, &status);    /*  Delete decoder instance */    VIDDEC_delete(decoderHandle);    /*  Report any errors */    if(status.extendedError){	ERR("Deleted video decoder instance with handle %#0lx\n", 					(unsigned long) decoderHandle);	ERR("\tDecoder exited with error mask %#0x\n", 					(unsigned int) status.extendedError );    }    else{        DBG("Deleted video decoder instance with handle %#0lx\n", 					(unsigned long) decoderHandle);	DBG("\tDecoder exited with no errors\n");    }    /* Return success */    return VDEC_SUCCESS;}

⌨️ 快捷键说明

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