?? tskprocess.c
字號:
/*
* Copyright 2003 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
*/
#include <std.h>
#include <stdio.h>
#include <csl.h>
#include <csl_cache.h>
#include <csl_dat.h>
#include <chan.h>
#include <scom.h>
#include <utl.h>
#include <tsk.h>
#include "fvid.h"
#include "cellmpeg2enc.h"
#include "appmain.h"
#include "appThreads.h"
#include "tskProcess.h"
#include "evm642_mpeg2enc.h"
IMPEG2VENC_Params mpeg2encParams;
char hname[80]="test.par";
void readparamfile(char *fname,IMPEG2VENC_Params *mpeg2veparam);
ThrProcess thrProcess;
volatile int framenum=0;
void tskProcessInit()
{
int chanNum;
ICELL_Obj *cell;
ICC_Handle inputIcc;
ICC_Handle outputIcc;
readparamfile(hname,&mpeg2encParams);
mpeg2encParams.outstream = bitBuf;
mpeg2encParams.h_recon_all = 1;
for (chanNum = 0; chanNum < PROCESSNUMCHANNELS ; chanNum++)
{
/*------------------------------------------------------------*/
/* register the cells: define what will be input buffers and */
/* what will be output buffers for each cell. */
/*------------------------------------------------------------*/
/*-----------------------------------------------------------*/
/* Setup a default cell used to initialize the actual cells */
/*-----------------------------------------------------------*/
ICELL_Obj defaultCell = ICELL_DEFAULT;
/*-----------------------------------------------------------*/
/* Register the cell for MPEG-2 encoder */
/*-----------------------------------------------------------*/
cell = &thrProcess.cellList[ (chanNum * PROCESSNUMCHANNELS ) + CELLMPEG2ENC];
*cell = defaultCell;
cell->name = "MPEG2ENC";
cell->cellFxns = &MPEG2ENC_CELLFXNS;
cell->algFxns = (IALG_Fxns *)&MPEG2ENC_IMPEG2ENC;
cell->algParams = (IALG_Params *)&mpeg2encParams;
cell->scrBucketIndex = THRIOSSCRBUCKET;
/*-----------------------------------------------------------*/
/* Create the inputICC: object used as input interface to the*/
/* enocoder cell */
/*-----------------------------------------------------------*/
inputIcc = (ICC_Handle)ICC_linearCreate(
thrProcess.bufInput[ chanNum ],
sizeof(unsigned char*)*3);
UTL_assert( inputIcc != NULL);
/*-----------------------------------------------------------*/
/* Create the outputICC: object used as output interface to */
/* enocoder cell */
/*-----------------------------------------------------------*/
outputIcc = (ICC_Handle)ICC_linearCreate(
thrProcess.bufOutput[ chanNum ],
sizeof(BIT_BUF_SIZE));
UTL_assert( outputIcc != NULL);
/*------------------------------------------------------------*/
/* Only one input and one output ICC are needed. */
/*------------------------------------------------------------*/
CHAN_regCell( cell, &inputIcc, 1, &outputIcc, 1 );
thrProcess.cellList[ (chanNum * PROCESSNUMCELLS) + CELLMPEG2ENC].algParams =
(IALG_Params *)&mpeg2encParams;
UTL_logDebug1("Channel Number: %d", chanNum);
//UTL_assert( rc == TRUE );
}
CACHE_clean(CACHE_L2ALL, 0, 0);
CACHE_clean(CACHE_L2ALL, 0, 0);
}
/*-------------------------------------------------------*/
/* Create the channel instance : the cell algorithms will*/
/* be instantiated */
/*-------------------------------------------------------*/
void tskProcessStart() {
int chanNum;
for (chanNum = 0; chanNum < PROCESSNUMCHANNELS ; chanNum++)
{
/*------------------------------------------------------------*/
/* Open the channel: this causes the algorithms to be created */
/*------------------------------------------------------------*/
CHAN_open( &thrProcess.chanList[ chanNum ],
&thrProcess.cellList[ chanNum * PROCESSNUMCELLS ],
PROCESSNUMCELLS ,
NULL );
//UTL_assert( rc == TRUE );
}
}
/*-------------------------------------------------------*/
/* The task will handle the processing part : */
/* -Will get the message from the Input task with input */
/* frame pointers */
/* -Will execute the channel to encode and reconstruct */
/* -Will pass the decoded frame pointers to output task */
/*-------------------------------------------------------*/
void tskProcess()
{
IMPEG2VENC_Status encstatus;
unsigned int *bufs;
ScomBufChannels *pMsgBuf;
SCOM_Handle fromInputtoProc,fromProctoOut;
fromInputtoProc = SCOM_open("INTOPROC");
fromProctoOut = SCOM_open("PROCTOOUT");
while(1)
{
CHAN_Handle chanHandle = &thrProcess.chanList[ 0 ];
/*-----------------------------------------------------------*/
/* Wait for the message from input task to recieve captured */
/* frame to be cycled through encoding and decoding. */
/*-----------------------------------------------------------*/
pMsgBuf = SCOM_getMsg(fromInputtoProc, SYS_FOREVER);
bufs = pMsgBuf->bufChannel;
yuvBufIp[0] = (char *)bufs[0];
yuvBufIp[1] = (char *)bufs[1];
yuvBufIp[2] = (char *)bufs[2];
/*----------------------------------------------------------*/
/* Set the input ICC buffer for MPEG2ENC cell for each channel*/
/*----------------------------------------------------------*/
ICC_setBuf(chanHandle->cellSet[CELLMPEG2ENC].inputIcc[0],
yuvBufIp,
sizeof(unsigned char*)*3);
/*----------------------------------------------------------*/
/* Set the output ICC buffer for MPEG2ENC cell for each channel*/
/*----------------------------------------------------------*/
ICC_setBuf(chanHandle->cellSet[CELLMPEG2ENC].outputIcc[0],
bitBuf,
BIT_BUF_SIZE);
/*-------------------------------------------------------*/
// execute the channel
/*-------------------------------------------------------*/
CACHE_clean(CACHE_L2ALL, 0, 0);
CHAN_execute( chanHandle, framenum );
CACHE_clean(CACHE_L2ALL, 0, 0);
/*-------------------------------------------------------*/
// Call the Control function of encoder to retrieve the
// the pointers to teh reconstructed frames
/*-------------------------------------------------------*/
MPEG2ENC_cellControl(&chanHandle->cellSet[CELLMPEG2ENC],
IMPEG2VENC_GETSTATUS,
(IALG_Status *)&encstatus);
if(encstatus.dispflag == 1)
{
yuvBuf[0] = (char *)encstatus.y;
yuvBuf[1] = (char *)encstatus.u;
yuvBuf[2] = (char *)encstatus.v;
}
/*-----------------------------------------------------------*/
/* Send message to output task with pointers to decoded frame*/
/*-----------------------------------------------------------*/
thrProcess.scomMsgTx.status = encstatus.dispflag;
thrProcess.scomMsgTx.bufChannel= (void *)&yuvBuf[0];
SCOM_putMsg(fromProctoOut,&(thrProcess.scomMsgTx));
framenum++;
if(mpeg2encParams.h_nframes == framenum)
{
framenum = 0;
}
}
}
void readparamfile(char *fname,IMPEG2VENC_Params *mpeg2veparam)
{
int i;
int v;
FILE *fd;
char line[256];
fd = fopen(fname,"r");
if (!fd)
{
printf("Couldn't open parameter file %s",fname);
}
fgets(mpeg2veparam->h_id_string,254,fd);
fgets(line,254,fd); sscanf(line,"%s",mpeg2veparam->h_tplorg);
fgets(line,254,fd); sscanf(line,"%s",mpeg2veparam->h_tplref);
fgets(line,254,fd); sscanf(line,"%s",mpeg2veparam->h_iqname);
fgets(line,254,fd); sscanf(line,"%s",mpeg2veparam->h_niqname);
fgets(line,254,fd); sscanf(line,"%s",mpeg2veparam->h_statname);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_inputtype);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_nframes);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_frame0);
fgets(line,254,fd); sscanf(line,"%d:%d:%d:%d",&mpeg2veparam->h_h,
&mpeg2veparam->h_m,&mpeg2veparam->h_s,&mpeg2veparam->h_f1);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_N);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_M);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_mpeg1);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_fieldpic);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_horizontal_size);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_vertical_size);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_aspectratio);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_frame_rate_code);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_bit_rate); // nc int
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_vbv_buffer_size);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_low_delay);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_constrparms);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_profile);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_level);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_prog_seq);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_chroma_format);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_video_format);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_color_primaries);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_transfer_characteristics);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_matrix_coefficients);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_display_horizontal_size);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_display_vertical_size);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_dc_prec);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_topfirst);
fgets(line,254,fd); sscanf(line,"%d %d %d",
mpeg2veparam->h_frame_pred_dct_tab,mpeg2veparam->h_frame_pred_dct_tab+1,mpeg2veparam->h_frame_pred_dct_tab+2);
fgets(line,254,fd); sscanf(line,"%d %d %d",
mpeg2veparam->h_conceal_tab,mpeg2veparam->h_conceal_tab+1,mpeg2veparam->h_conceal_tab+2);
fgets(line,254,fd); sscanf(line,"%d %d %d",
mpeg2veparam->h_qscale_tab,mpeg2veparam->h_qscale_tab+1,mpeg2veparam->h_qscale_tab+2);
fgets(line,254,fd); sscanf(line,"%d %d %d",
mpeg2veparam->h_intravlc_tab,mpeg2veparam->h_intravlc_tab+1,mpeg2veparam->h_intravlc_tab+2);
fgets(line,254,fd); sscanf(line,"%d %d %d",
mpeg2veparam->h_altscan_tab,mpeg2veparam->h_altscan_tab+1,mpeg2veparam->h_altscan_tab+2);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_repeatfirst);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_prog_frame);
/* intra slice interval refresh period */
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_P);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_r);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_avg_act);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_Xi);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_Xp);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_Xb);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_d0i);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_d0p);
fgets(line,254,fd); sscanf(line,"%d",&mpeg2veparam->h_d0b);
/* For P pictures. Get motion_picdata in motion_picdata[h_M-1] */
/* Parameters in following order */
/* int forw_hor_f_code,forw_vert_f_code,int sxf,int syf */
/* int back_hor_f_code,back_vert_f_code,int sxb,int syb */
fgets(line,254,fd);
sscanf(line,"%d %d %d %d",
&mpeg2veparam->h_motion_picdata[(mpeg2veparam->h_M-1)*8], &mpeg2veparam->h_motion_picdata[(mpeg2veparam->h_M-1)*8+1],
&mpeg2veparam->h_motion_picdata[(mpeg2veparam->h_M-1)*8+2], &mpeg2veparam->h_motion_picdata[(mpeg2veparam->h_M-1)*8+3]);
/* End P Pictures case */
for (i=0; i<mpeg2veparam->h_M-1; i++)
{
fgets(line,254,fd);
sscanf(line,"%d %d %d %d",
&mpeg2veparam->h_motion_picdata[i*8], &mpeg2veparam->h_motion_picdata[i*8+1],
&mpeg2veparam->h_motion_picdata[i*8+2], &mpeg2veparam->h_motion_picdata[i*8+3]);
fgets(line,254,fd);
sscanf(line,"%d %d %d %d",
&mpeg2veparam->h_motion_picdata[i*8+4], &mpeg2veparam->h_motion_picdata[i*8+5],
&mpeg2veparam->h_motion_picdata[i*8+6], &mpeg2veparam->h_motion_picdata[i*8+7]);
}
fclose(fd);
if(mpeg2veparam->h_iqname[0] != '-')
{
/* read customized intra matrix */
//mpeg2veparam->load_iquant = 1;
fd = fopen(mpeg2veparam->h_iqname,"r");
if (!fd)
{
printf("Couldn't open quant matrix file %s",mpeg2veparam->h_iqname);
}
for (i=0; i<64; i++)
{
fscanf(fd,"%d",&v);
if (v<1 || v>255)
printf("invalid value in quant matrix");
mpeg2veparam->h_intra_q[i] = v;
}
fclose(fd);
}
if(mpeg2veparam->h_niqname[0] != '-')
{
/* read customized non-intra matrix */
//mpeg2veparam->load_niquant = 1;
fd = fopen(mpeg2veparam->h_niqname,"r");
if (!fd)
{
printf("Couldn't open quant matrix file %s",mpeg2veparam->h_niqname);
}
for (i=0; i<64; i++)
{
fscanf(fd,"%d",&v);
if (v<1 || v>255)
printf("invalid value in quant matrix");
mpeg2veparam->h_inter_q[i] = v;
}
fclose(fd);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -