thrprocess.c
来自「TI公司的算法标准 Framework5的源代码」· C语言 代码 · 共 692 行 · 第 1/2 页
C
692 行
}
// -------------------------------------
// Combo Channels (DIFF and then ROTATE)
// -------------------------------------
for (chanNum = 0; chanNum < NUMCOMBOCHANS; chanNum++) {
/*
* cell 0 - DIFF: create an input and output linear ICC.
* The address to the input ICC will be set in the thrProcessRun()
* function via ICC_setBuf().
*/
cell = &thrProcess.comboCells[ chanNum * CHCOMBONUMCELLS ];
*cell = defaultCell;
cell->name = "DIFF";
cell->cellFxns = &DIFF_CELLFXNS;
cell->cellEnv = (Ptr *)&thrProcess.diffEnv[chanNum + NUMDIFFCHANS];
cell->algFxns = (IALG_Fxns *)&DIFF_IDIFF;
cell->algParams = (IALG_Params *)&diffParams;
cell->scrBucketIndex = VIDEOPROCSCRBUCKET;
inputIcc = (ICC_Handle)ICC_linearCreate( NULL, 0);
UTL_assert( inputIcc != NULL);
outputIcc = (ICC_Handle)ICC_linearCreate( bufYCRCB,
sizeof(bufYCRCB));
UTL_assert( outputIcc != NULL);
rc = CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );
/*
* cell 1 - ROTATE: create an input and output linear ICC.
*/
cell = &thrProcess.comboCells[
chanNum * CHCOMBONUMCELLS + CHCOMBOCELLROTATE];
*cell = defaultCell;
cell->name = "ROTATE";
cell->cellFxns = &ROTATE_CELLFXNS;
cell->cellEnv = (Ptr *)&thrProcess.rotateEnv[chanNum + NUMROTATECHANS];
cell->algFxns = (IALG_Fxns *)&ROTATE_IROTATE;
cell->algParams = (IALG_Params *)&rotateParams;
cell->scrBucketIndex = VIDEOPROCSCRBUCKET;
inputIcc = (ICC_Handle)ICC_linearCreate(
bufYCRCB, sizeof(bufYCRCB));
UTL_assert( inputIcc != NULL);
outputIcc = (ICC_Handle)ICC_linearCreate(
bufYCRCB, sizeof(bufYCRCB));
UTL_assert( outputIcc != NULL);
rc = CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );
/*
* cell 2 - YUV2RGB: create an input and output linear ICC.
*/
cell = &thrProcess.comboCells[
chanNum * CHCOMBONUMCELLS + CHCOMBOCELLYUV];
*cell = defaultCell;
cell->name = "YUV2RGB";
cell->cellFxns = &YUV2RGB_CELLFXNS;
cell->algFxns = (IALG_Fxns *)&YUV2RGB_IYUV2RGB;
cell->algParams = (IALG_Params *)&yuv2rgbParams;
cell->scrBucketIndex = VIDEOPROCSCRBUCKET;
inputIcc = (ICC_Handle)ICC_linearCreate(
bufYCRCB, sizeof(bufYCRCB));
UTL_assert( inputIcc != NULL);
outputIcc = (ICC_Handle)ICC_linearCreate(bufRGBundoubled +
thrProcess.comboPlacement[chanNum],
PROCF_SIZE_IN_PIXELS);
UTL_assert( outputIcc != NULL);
rc = CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );
}
}
else {
// Open the channels
//Open Pass thru chans
for (chanNum = 0; chanNum < NUMPASSCHANS; chanNum++) {
// Set the algorithm's parameters
thrProcess.passCells[chanNum * CHPASSNUMCELLS].algParams =
(IALG_Params *)&yuv2rgbParams;
// Open the channel
UTL_logDebug1("Process: Pass-thru Channel Number: %d", chanNum);
rc = CHAN_open( &thrProcess.passChans[chanNum],
&thrProcess.passCells[chanNum * CHPASSNUMCELLS],
CHPASSNUMCELLS, NULL );
UTL_assert( rc == TRUE );
}
//Open Diff chans
for (chanNum = 0; chanNum < NUMDIFFCHANS; chanNum++) {
// Set the algorithm's parameters
thrProcess.diffCells[chanNum * CHDIFFNUMCELLS].algParams =
(IALG_Params *)&diffParams;
thrProcess.diffCells[
chanNum * CHDIFFNUMCELLS + CHDIFFCELLYUV].algParams =
(IALG_Params *)&yuv2rgbParams;
// Open the channel
UTL_logDebug1("Process: Diff Channel Number: %d", chanNum);
rc = CHAN_open( &thrProcess.diffChans[chanNum],
&thrProcess.diffCells[chanNum * CHDIFFNUMCELLS],
CHDIFFNUMCELLS, NULL );
UTL_assert( rc == TRUE );
}
//Open Rotate chans
for (chanNum = 0; chanNum < NUMROTATECHANS; chanNum++) {
// Set the algorithm's parameters
thrProcess.rotateCells[chanNum * CHROTATENUMCELLS].algParams =
(IALG_Params *)&rotateParams;
thrProcess.rotateCells[
chanNum * CHROTATENUMCELLS + CHROTATECELLYUV].algParams =
(IALG_Params *)&yuv2rgbParams;
// Open the channel
UTL_logDebug1("Process: Rotate Channel Number: %d", chanNum);
rc = CHAN_open( &thrProcess.rotateChans[chanNum],
&thrProcess.rotateCells[chanNum * CHROTATENUMCELLS],
CHROTATENUMCELLS, NULL );
UTL_assert( rc == TRUE );
}
//Open Combo chans
for (chanNum = 0; chanNum < NUMCOMBOCHANS; chanNum++) {
// Set the algorithm's parameters
thrProcess.comboCells[chanNum * CHCOMBONUMCELLS].algParams =
(IALG_Params *)&diffParams;
thrProcess.comboCells[
chanNum * CHCOMBONUMCELLS + CHCOMBOCELLROTATE].algParams =
(IALG_Params *)&rotateParams;
thrProcess.comboCells[
chanNum * CHCOMBONUMCELLS + CHCOMBOCELLYUV].algParams =
(IALG_Params *)&yuv2rgbParams;
// Open the channel
UTL_logDebug1("Process: Combo Channel Number: %d", chanNum);
rc = CHAN_open( &thrProcess.comboChans[chanNum],
&thrProcess.comboCells[chanNum * CHCOMBONUMCELLS],
CHCOMBONUMCELLS, NULL );
UTL_assert( rc == TRUE );
}
}
}
static Void checkMsg()
{
CtrlMsg rxMsg;
Int index;
// check message in "mbxProc"
while( MBX_pend( &mbxProcess, &rxMsg, 0) ) {
switch (rxMsg.cmd) {
case MSGNEWREFERENCE: //setting a new reference frame
thrProcess.diffEnv->SetReference = TRUE;
break;
case MSGNEWCOLOR: //change color of unequal pixels
for (index = 0; index < (NUMDIFFCHANS + NUMCOMBOCHANS); index++)
{
thrProcess.diffEnv[index].yValue = rxMsg.arg1;
thrProcess.diffEnv[index].crValue = rxMsg.arg2 >> 8;
thrProcess.diffEnv[index].cbValue = rxMsg.arg2 % 256;
}
break;
default:
break;
}
}
}
/*
* ======== thrProcessRun ========
*
* Main function of Process Thread.
*/
Void thrProcessRun()
{
CHAN_Handle chan;
Int prevYId;
Int prevCrId;
Int prevCbId;
UTL_logDebug1("thrProcessRun: task = 0x%x", TSK_self());
// open SCOM queues for sending messages to other tasks
scomSendToCapture = SCOM_open( "scomCapture" );
scomSendToDisplay = SCOM_open( "scomDisplay" );
UTL_assert( scomSendToCapture != NULL);
UTL_assert( scomSendToDisplay != NULL);
// processed buffers
memset(ybuff, 0x00, PROCF_SIZE_IN_PIXELS);
memset(crbuff, 0x00, PROCF_SIZE_IN_PIXELS >> 2);
memset(cbbuff, 0x00, PROCF_SIZE_IN_PIXELS >> 2);
memset(bufRGBundoubled,0x00,RGBF_SIZE_IN_PIXELS*RGBF_PXLSIZE );
memset(ybuffCap, 0x00, PROCF_SIZE_IN_PIXELS);
memset(crbuffCap, 0x00, PROCF_SIZE_IN_PIXELS >> 2);
memset(cbbuffCap, 0x00, PROCF_SIZE_IN_PIXELS >> 2);
// prepare the SCOM buffers
thrProcess.scombufDisp.bufRGB = bufRGBundoubled;
thrProcess.scombufCap.bufYCRCB[0] = ybuffCap;
thrProcess.scombufCap.bufYCRCB[1] = crbuffCap;
thrProcess.scombufCap.bufYCRCB[2] = cbbuffCap;
// put the Rx message on the SCOM queue for Capture thread
SCOM_putMsg( scomSendToCapture, &thrProcess.scombufCap );
// put the Tx message on the SCOM queue for Display thread
SCOM_putMsg( scomSendToDisplay, &thrProcess.scombufDisp );
// Main loop
while (TRUE) {
ScomProcToDisp *scombufDisp;
ScomCapToProc *scombufCap;
Int chanNum;
Bool rc;
// check message from the control thread
checkMsg();
// get the message describing full input buffers from Capture
scombufCap = SCOM_getMsg(scomReceiveFromCapture,
SYS_FOREVER);
// get the message describing empty output buffers from Display
scombufDisp = SCOM_getMsg(scomReceiveFromDisplay,
SYS_FOREVER);
//Update Reference Frame if necessary
if (thrProcess.diffEnv->SetReference == TRUE)
{
prevYId = DAT_copy2d(DAT_2D1D, (Void *) scombufCap->bufYCRCB[0], (Void *) prevY, PROCF_WIDTH, PROCF_HEIGHT, PROCF_WIDTH);
prevCrId = DAT_copy2d(DAT_2D1D, (Void *) scombufCap->bufYCRCB[1], (Void *) prevCr, PROCF_WIDTH>>1, PROCF_HEIGHT>>1, PROCF_WIDTH>>1);
prevCbId = DAT_copy2d(DAT_2D1D, (Void *) scombufCap->bufYCRCB[2], (Void *) prevCb, PROCF_WIDTH>>1, PROCF_HEIGHT>>1, PROCF_WIDTH>>1);
thrProcess.diffEnv->SetReference = FALSE;
}
DAT_wait(prevYId);
DAT_wait(prevCrId);
DAT_wait(prevCbId);
//Execute all passthrough channels
for (chanNum = 0; chanNum < NUMPASSCHANS; chanNum++) {
chan = &(thrProcess.passChans[chanNum]);
// assign the buffers to the ICC objects
// Redundant with the SCOM queue is single-buffered. Needed when the
// queue is multiple-buffered.
ICC_setBuf(chan->cellSet[CHPASSCELLYUV].inputIcc[0],
scombufCap->bufYCRCB, 0);
ICC_setBuf(chan->cellSet[CHPASSCELLYUV].outputIcc[0],
scombufDisp->bufRGB + thrProcess.passPlacement[chanNum], 0);
UTL_stsStart( stsExeTimeChPass );
rc = CHAN_execute( chan, NULL );
UTL_assert( rc == TRUE );
UTL_stsStop( stsExeTimeChPass );
}
//Execute all diff channels
for (chanNum = 0; chanNum < NUMDIFFCHANS; chanNum++) {
chan = &(thrProcess.diffChans[chanNum]);
// assign the buffers to the ICC objects
// Redundant with the SCOM queue is single-buffered. Needed when the
// queue is multiple-buffered.
ICC_setBuf(chan->cellSet[CHDIFFCELLDIFF].inputIcc[0],
scombufCap->bufYCRCB, 0);
ICC_setBuf(chan->cellSet[CHDIFFCELLYUV].outputIcc[0],
scombufDisp->bufRGB + thrProcess.diffPlacement[chanNum], 0);
UTL_stsStart( stsExeTimeChDiff );
rc = CHAN_execute( &thrProcess.diffChans[ chanNum ], NULL );
UTL_assert( rc == TRUE );
UTL_stsStop( stsExeTimeChDiff );
}
//Execute all rotate channels
for (chanNum = 0; chanNum < NUMROTATECHANS; chanNum++) {
chan = &(thrProcess.rotateChans[chanNum]);
// assign the buffers to the ICC objects
// Redundant with the SCOM queue is single-buffered. Needed when the
// queue is multiple-buffered.
ICC_setBuf(chan->cellSet[CHROTATECELLROTATE].inputIcc[0],
scombufCap->bufYCRCB, 0);
ICC_setBuf(chan->cellSet[CHROTATECELLYUV].outputIcc[0],
scombufDisp->bufRGB + thrProcess.rotatePlacement[chanNum], 0);
UTL_stsStart( stsExeTimeChRotate );
rc = CHAN_execute( &thrProcess.rotateChans[ chanNum ], NULL );
UTL_assert( rc == TRUE );
UTL_stsStop( stsExeTimeChRotate );
}
//Execute all combo channels
for (chanNum = 0; chanNum < NUMCOMBOCHANS; chanNum++) {
chan = &(thrProcess.comboChans[chanNum]);
// assign the buffers to the ICC objects
// Redundant with the SCOM queue is single-buffered. Needed when the
// queue is multiple-buffered.
ICC_setBuf(chan->cellSet[CHCOMBOCELLDIFF].inputIcc[0],
scombufCap->bufYCRCB, 0);
ICC_setBuf(chan->cellSet[CHCOMBOCELLYUV].outputIcc[0],
scombufDisp->bufRGB + thrProcess.comboPlacement[chanNum], 0);
UTL_stsStart( stsExeTimeChCombo );
rc = CHAN_execute( &thrProcess.comboChans[ chanNum ], NULL );
UTL_assert( rc == TRUE );
UTL_stsStop( stsExeTimeChCombo );
}
// send the now full buffer to Display
SCOM_putMsg( scomSendToDisplay, scombufDisp );
// send the message describing consumed input buffers to Capture
SCOM_putMsg( scomSendToCapture, scombufCap );
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?