/*
* Copyright 2002 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.
*
*/
/*
* ======== thrProcess.c ========
* This file contains the main processing thread.
* A captured and preprocessed QCIF image is expected from the
* capture thread. Then the image will be sent to the 2 "live"
* and 2 "diff" channels for processing.
*/
// DSP/BIOS includes
#include <std.h>
#include <sts.h>
#include <string.h>
// DSP/BIOS includes
#include <tsk.h>
// CSL modules
#include <csl_dat.h>
#include <csl_cache.h>
// RF5 module includes
#include <chan.h>
#include <icell.h>
#include <scom.h>
#include <icc_linear.h>
#include <utl.h>
// cell includes
#include "diff/cellDiff.h"
#include "rotate/cellRotate.h"
// application includes
#include "appResources.h" // application-wide common info
// Thread include
#include "thrProcess.h"
#pragma DATA_SECTION(ybuffCap, ".EXTPROCBUFF");
#pragma DATA_SECTION(crbuffCap, ".EXTPROCBUFF");
#pragma DATA_SECTION(cbbuffCap, ".EXTPROCBUFF");
#pragma DATA_SECTION(ybuffDis, ".EXTPROCBUFF");
#pragma DATA_SECTION(crbuffDis, ".EXTPROCBUFF");
#pragma DATA_SECTION(cbbuffDis, ".EXTPROCBUFF");
#pragma DATA_SECTION(ybuff, ".EXTPROCBUFF");
#pragma DATA_SECTION(crbuff, ".EXTPROCBUFF");
#pragma DATA_SECTION(cbbuff, ".EXTPROCBUFF");
#pragma DATA_ALIGN(ybuffCap, MEMALIGN);
#pragma DATA_ALIGN(crbuffCap, MEMALIGN);
#pragma DATA_ALIGN(cbbuffCap, MEMALIGN);
#pragma DATA_ALIGN(ybuffDis, MEMALIGN);
#pragma DATA_ALIGN(crbuffDis, MEMALIGN);
#pragma DATA_ALIGN(cbbuffDis, MEMALIGN);
#pragma DATA_ALIGN(ybuff, MEMALIGN);
#pragma DATA_ALIGN(cbbuff, MEMALIGN);
#pragma DATA_ALIGN(crbuff, MEMALIGN);
//Buffers for cells of DIFF
#pragma DATA_SECTION(intYBuf, ".INTPROCBUFF");
#pragma DATA_SECTION(intCrBuf, ".INTPROCBUFF");
#pragma DATA_SECTION(intCbBuf, ".INTPROCBUFF");
#pragma DATA_SECTION(prevY, ".EXTPROCBUFF");
#pragma DATA_SECTION(prevCr, ".EXTPROCBUFF");
#pragma DATA_SECTION(prevCb, ".EXTPROCBUFF");
#pragma DATA_ALIGN(intYBuf, MEMALIGN);
#pragma DATA_ALIGN(intCrBuf, MEMALIGN);
#pragma DATA_ALIGN(intCbBuf, MEMALIGN);
#pragma DATA_ALIGN(prevY, MEMALIGN);
#pragma DATA_ALIGN(prevCr, MEMALIGN);
#pragma DATA_ALIGN(prevCb, MEMALIGN);
// Static intermediate processing buffers used in cellDiff and cellRotate
static Char intYBuf[DIFF_Y_BUFSIZE];
static Char intCrBuf[DIFF_CR_BUFSIZE];
static Char intCbBuf[DIFF_CB_BUFSIZE];
static Char prevY[PROCF_SIZE_IN_PIXELS];
static Char prevCr[PROCF_SIZE_IN_PIXELS >> 2];
static Char prevCb[PROCF_SIZE_IN_PIXELS >> 2];
/*
* Thread process object which encapsulates the state information
* of the thread.
*/
ThrProcess thrProcess;
// Buffers for ICC
static Char ybuff [ PROCF_SIZE_IN_PIXELS ];
static Char crbuff[ PROCF_SIZE_IN_PIXELS >> 2 ];
static Char cbbuff[ PROCF_SIZE_IN_PIXELS >> 2 ];
static Char *bufYCRCB[3] = {ybuff, crbuff, cbbuff};
// Buffers for SCOM
static Char ybuffCap [ PROCF_SIZE_IN_PIXELS ];
static Char crbuffCap[ PROCF_SIZE_IN_PIXELS >> 2 ];
static Char cbbuffCap[ PROCF_SIZE_IN_PIXELS >> 2 ];
static Char ybuffDis [ OPF_SIZE_IN_PIXELS ];
static Char crbuffDis[ OPF_SIZE_IN_PIXELS >> 2 ];
static Char cbbuffDis[ OPF_SIZE_IN_PIXELS >> 2 ];
static SCOM_Handle scomReceiveFromCapture;
static SCOM_Handle scomSendToCapture;
static SCOM_Handle scomReceiveFromDisplay;
static SCOM_Handle scomSendToDisplay;
// Local function prototypes
static Void setParamsAndStartChannels( Bool doChannelOpen );
static Void checkMsg();
/*
* ======== thrProcessInit ========
*
*/
Void thrProcessInit()
{
Int i;
// create named SCOM queues for receiving messages from other tasks
scomReceiveFromCapture = SCOM_create( "scomToProcessFromCapture",
&SCOM_ATTRS );
scomReceiveFromDisplay = SCOM_create( "scomToProcessFromDisplay",
&SCOM_ATTRS );
UTL_assert( scomReceiveFromCapture != NULL);
UTL_assert( scomReceiveFromDisplay != NULL);
//Set up the diff cell's env.
for(i = 0; i < (NUMDIFFCHANS + NUMCOMBOCHANS); i++) {
thrProcess.diffEnv[i].intYBuf = intYBuf;
thrProcess.diffEnv[i].intCrBuf = intCrBuf;
thrProcess.diffEnv[i].intCbBuf = intCbBuf;
thrProcess.diffEnv[i].prevY = prevY;
thrProcess.diffEnv[i].prevCr = prevCr;
thrProcess.diffEnv[i].prevCb = prevCb;
thrProcess.diffEnv[i].yBufSize = DIFF_Y_BUFSIZE;
thrProcess.diffEnv[i].crBufSize = DIFF_CR_BUFSIZE;
thrProcess.diffEnv[i].cbBufSize = DIFF_CB_BUFSIZE;
thrProcess.diffEnv[i].numBlocks = DIFF_NUMBLOCKS;
}
//Set up the rotate cell's env
for(i = 0; i < (NUMROTATECHANS + NUMCOMBOCHANS); i++)
{
thrProcess.rotateEnv[i].intYBuf = intYBuf;
thrProcess.rotateEnv[i].intCrBuf = intCrBuf;
thrProcess.rotateEnv[i].intCbBuf = intCbBuf;
thrProcess.rotateEnv[i].yBufSize = ROTATE_Y_BUFSIZE;
thrProcess.rotateEnv[i].crBufSize = ROTATE_CR_BUFSIZE;
thrProcess.rotateEnv[i].cbBufSize = ROTATE_CB_BUFSIZE;
thrProcess.rotateEnv[i].numBlocks = ROTATE_NUMBLOCKS;
}
//Allocate appropriate addresses for SCOM buffers
thrProcess.scombufCap.bufYCRCB[Y] = ybuffCap;
thrProcess.scombufCap.bufYCRCB[CR] = crbuffCap;
thrProcess.scombufCap.bufYCRCB[CB] = cbbuffCap;
thrProcess.scombufDisp.bufYCRCB[Y] = ybuffDis;
thrProcess.scombufDisp.bufYCRCB[CR] = crbuffDis;
thrProcess.scombufDisp.bufYCRCB[CB] = cbbuffDis;
setParamsAndStartChannels( FALSE );
}
/*
* ======== thrProcessStartup ========
*
*/
Void thrProcessStartup()
{
setParamsAndStartChannels( TRUE );
}
/*
* ======== setParamsAndStartChannels ========
*
*/
static Void setParamsAndStartChannels( Bool doChannelOpen )
{
IDIFF_Params diffParams;
IROTATE_Params rotateParams;
ICC_Handle inputIcc;
ICC_Handle outputIcc;
Uns chanNum;
ICELL_Handle cell;
Bool rc;
// Set up params for all XDAIS algorithms
rotateParams = IROTATE_PARAMS;
diffParams = IDIFF_PARAMS;
if (doChannelOpen == FALSE) {
/* Setup a default cell used to initialize the actual cells */
ICELL_Obj defaultCell = ICELL_DEFAULT;
// Create and assign the linear ICC objects. Then register each cell.
// -----------------------
// Pass-thru Channels
// -----------------------
// Pass-thru channel does not have any cells, so it needs no initialization
// -----------------------
// Difference Channels
// -----------------------
for (chanNum = 0; chanNum < NUMDIFFCHANS; 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.diffCells[ chanNum * CHDIFFNUMCELLS ];
*cell = defaultCell;
cell->name = "DIFF";
cell->cellFxns = &DIFF_CELLFXNS;
cell->cellEnv = (Ptr *)&thrProcess.diffEnv[chanNum];
cell->algFxns = (IALG_Fxns *)&DIFF_IDIFF;
cell->algParams = (IALG_Params *)&diffParams;
cell->scrBucketIndex = VIDEOPROCSCRBUCKET;
inputIcc = (ICC_Handle)ICC_linearCreate( NULL, 0);
UTL_assert(