📄 image.c
字号:
/*
* ======== video_encdec.c ========
*
*/
/* Codec Engine include files: */
#include <xdc/std.h>
#include <ti/sdo/ce/Engine.h>
#include <ti/sdo/ce/osal/Memory.h>
#include <ti/sdo/ce/image/imgenc.h>
#include <ti/sdo/ce/image/imgdec.h>
/* BIOS include files: */
#include <ti/bios/include/std.h>
#include <tsk.h>
/* Run Time lib include files: */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
/* PSP include files: */
#include <psp_vpfe.h>
#include <psp_vpbe.h>
#include <fvid.h>
#include <psp_tvp5146_extVidDecoder.h>
/* BSL include files */
#include <evmdm6437.h>
#include <evmdm6437_dip.h>
/* Video Params Defaults */
#include <vid_params_default.h>
/* Video Encoder initialization param: */
#define VE_MAX_BR (4000000)
/* Align on cache-line boundary since encoder uses DMA */
#define BUFALIGN 128
/* Number of buffers to allocate for video capture + display: */
#define FRAME_BUFF_CNT 6
/* This example supports either PAL or NTSC depending on position of JP1 */
#define STANDARD_PAL 0
#define STANDARD_NTSC 1
/* Video Encoder parameters for D1, set depending on PAL vs NTSC: */
static int intraFrameInterval;
static int inputWidth;
static int inputHeight;
static int maxFrameRate;
/* Encoder Input, Encoder output, and Decoder Output Frame sizes */
static int framesize;
/* Video Frame buffers: */
static FVID_Frame *frameBuffTable[FRAME_BUFF_CNT];
static FVID_Frame *frameBuffPtr = NULL;
/* Video Driver Handles: */
static FVID_Handle hGioVpfeCcdc = NULL;
static FVID_Handle hGioVpbeVid0 = NULL;
static FVID_Handle hGioVpbeVenc = NULL;
/* Intermediate buffer for the encoded video stream: */
static XDAS_Int8 *encodedBuf;
/* Codec Engine engine and codec labels, defined in cfg file: */
static String decoderName = "h264dec";
static String encoderName = "h264enc";
static String engineName = "encdec";
static String progName = "app";
/* Function prototypes */
static Void initVE_StaticParams(IMGENC_Params *vencParams);
static Void initVE_DynamicParams(IMGENC_DynamicParams *encDynParams);
static Void initVD_StaticParams(IMGDEC_Params *vdecParams);
static Void initVD_DynamicParams(IMGDEC_DynamicParams *decDynParams);
static Void encode_decode(IMGENC_Handle enc, IMGDEC_Handle dec,FILE *fh_enc);
static int read_JP1(void);
/*
* ======== video_encdec ========
*/
/* ARGSUSED */
Int video_encdec(Int argc, String argv[])
{
int status = 0;
int result;
int i;
FILE *fh_enc = NULL;
String encodedFile;
Engine_Handle ce = NULL;
IMGDEC_Handle dec = NULL;
IMGENC_Handle enc = NULL;
IMGENC_Status encStatus;
IMGENC_Params vencParams;
IMGENC_DynamicParams encDynParams;
IMGDEC_Status decStatus;
IMGDEC_Params vdecParams;
IMGDEC_DynamicParams decDynParams;
int standard;
/* Set video display/capture driver params to defaults */
PSP_VPFE_TVP5146_ConfigParams tvp5146Params =
VID_PARAMS_TVP5146_DEFAULT;
PSP_VPFECcdcConfigParams vpfeCcdcConfigParams =
VID_PARAMS_CCDC_DEFAULT_D1;
PSP_VPBEOsdConfigParams vpbeOsdConfigParams =
VID_PARAMS_OSD_DEFAULT_D1;
PSP_VPBEVencConfigParams vpbeVencConfigParams;
printf("video_encdec started.\n");
standard = read_JP1();
encodedFile = "..\\data\\akiyo_10frames_qcif.h264";
if ((fh_enc = fopen(encodedFile, "wb")) == NULL) {
printf("ERROR: can't write to file %s\n", encodedFile);
goto end;
}
/* Update display/capture params based on video standard (PAL/NTSC) */
if (standard == STANDARD_PAL) {
inputWidth = 720;
inputHeight = 576;
intraFrameInterval = 25;
maxFrameRate = 25000;
vpbeVencConfigParams.displayStandard = PSP_VPBE_DISPLAY_PAL_INTERLACED_COMPOSITE;
}
else {
inputWidth = 720;
inputHeight = 480;
intraFrameInterval = 30;
maxFrameRate = 30000;
vpbeVencConfigParams.displayStandard = PSP_VPBE_DISPLAY_NTSC_INTERLACED_COMPOSITE;
}
framesize = (inputWidth * inputHeight * 2 * sizeof(Int8));
vpfeCcdcConfigParams.height = vpbeOsdConfigParams.height = inputHeight;
vpfeCcdcConfigParams.width = vpbeOsdConfigParams.width = inputWidth;
vpfeCcdcConfigParams.pitch = vpbeOsdConfigParams.pitch = inputWidth * 2;
/* Initialize Video Display Driver: */
/* create video input channel */
if (status == 0) {
PSP_VPFEChannelParams vpfeChannelParams;
vpfeChannelParams.id = PSP_VPFE_CCDC;
vpfeChannelParams.params = (PSP_VPFECcdcConfigParams*)&vpfeCcdcConfigParams;
hGioVpfeCcdc = FVID_create("/VPFE0",IOM_INOUT,NULL,&vpfeChannelParams,NULL);
status = (hGioVpfeCcdc == NULL ? -1 : 0);
}
/* create video output channel, plane 0 */
if (status == 0) {
PSP_VPBEChannelParams vpbeChannelParams;
vpbeChannelParams.id = PSP_VPBE_VIDEO_0;
vpbeChannelParams.params = (PSP_VPBEOsdConfigParams*)&vpbeOsdConfigParams;
hGioVpbeVid0 = FVID_create("/VPBE0",IOM_INOUT,NULL,&vpbeChannelParams,NULL);
status = (hGioVpbeVid0 == NULL ? -1 : 0);
}
/* create video output channel, venc */
if (status == 0) {
PSP_VPBEChannelParams vpbeChannelParams;
vpbeChannelParams.id = PSP_VPBE_VENC;
vpbeChannelParams.params = (PSP_VPBEVencConfigParams *)&vpbeVencConfigParams;
hGioVpbeVenc = FVID_create("/VPBE0",IOM_INOUT,NULL,&vpbeChannelParams,NULL);
status = (hGioVpbeVenc == NULL ? -1 : 0);
}
/* configure the TVP5146 video decoder */
if (status == 0) {
result = FVID_control(hGioVpfeCcdc,
VPFE_ExtVD_BASE+PSP_VPSS_EXT_VIDEO_DECODER_CONFIG, &tvp5146Params);
status = (result == IOM_COMPLETED ? 0 : -1);
}
/* allocate display/capture frame buffers */
for (i=0; i<FRAME_BUFF_CNT; i++) {
frameBuffTable[i] = NULL;
}
if (status == 0) {
for (i=0; i<FRAME_BUFF_CNT && status == 0; i++) {
result = FVID_allocBuffer(hGioVpfeCcdc, &frameBuffTable[i]);
status = (result == IOM_COMPLETED && frameBuffTable[i] != NULL ? 0 : -1);
}
}
/* prime up the video capture channel */
if (status == 0) {
FVID_queue(hGioVpfeCcdc, frameBuffTable[0]);
FVID_queue(hGioVpfeCcdc, frameBuffTable[1]);
FVID_queue(hGioVpfeCcdc, frameBuffTable[2]);
}
/* prime up the video display channel */
if (status == 0) {
FVID_queue(hGioVpbeVid0, frameBuffTable[3]);
FVID_queue(hGioVpbeVid0, frameBuffTable[4]);
FVID_queue(hGioVpbeVid0, frameBuffTable[5]);
}
/* grab first buffer from input queue */
if (status == 0) {
FVID_dequeue(hGioVpfeCcdc, &frameBuffPtr);
}
if (status != 0) {
goto end;
}
/* Allocate Encoder output buffer: */
encodedBuf = (XDAS_Int8 *)Memory_contigAlloc(framesize, BUFALIGN);
if (encodedBuf == NULL) {
goto end;
}
else {
Memory_cacheWbInv(encodedBuf, framesize);
}
/* reset, load, and start DSP Engine */
if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) {
fprintf(stderr, "%s: error: can't open engine %s\n",
progName, engineName);
goto end;
}
/* Set init params for video encoder: */
initVE_StaticParams(&vencParams);
/* Set init params for video decoder: */
initVD_StaticParams(&vdecParams);
/* Instantiate the encoder: */
enc = IMGENC_create(ce, encoderName, &vencParams);
if (enc == NULL) {
fprintf(stderr, "%s: error: can't open codec %s\n",
progName, encoderName);
goto end;
}
/* allocate and initialize video decoder on the engine */
dec = IMGDEC_create(ce, decoderName, &vdecParams);
if (dec == NULL) {
printf( "ERROR: can't open codec %s\n", decoderName);
goto end;
}
/* Set Dynamic Params for Encoder */
initVE_DynamicParams(&encDynParams);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -