thrprocess.c

来自「TI公司的算法标准 Framework5的源代码」· C语言 代码 · 共 692 行 · 第 1/2 页

C
692
字号
/*
 *  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.
 *  
 */
/* "@(#) RF5_IEK 2.00.02 12-11-02 (swat-c19)" */
/*
 *  ======== 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>

// RF5 module includes
#include <chan.h>
#include <icell.h>
#include <scom.h>
#include <icc_linear.h>
#include <utl.h>

// cell includes
#include "yuv2rgb/cellYuv2rgb.h"
#include "diff/cellDiff.h"
#include "rotate/cellRotate.h"

// Ateme IEKC64 includes
#include "iekc64.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(bufRGBundoubled,".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(ybuff,           MEMALIGN);
#pragma DATA_ALIGN(cbbuff,          MEMALIGN);
#pragma DATA_ALIGN(crbuff,          MEMALIGN);
#pragma DATA_ALIGN(bufRGBundoubled, 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, ".INTPROCBUFF");
#pragma DATA_SECTION(prevCr, ".INTPROCBUFF");
#pragma DATA_SECTION(prevCb, ".INTPROCBUFF");
#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 ];

// RGB buffers 
static MdUns bufRGBundoubled[ RGBF_SIZE_IN_PIXELS ];

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;
    }

	//Place all channels in appropriate	quadrants
    thrProcess.passPlacement[0]   = Q2OFFSET;
    thrProcess.diffPlacement[0]   = Q1OFFSET;
    thrProcess.rotatePlacement[0] = Q3OFFSET;
    thrProcess.comboPlacement[0] = Q4OFFSET;
    
    setParamsAndStartChannels( FALSE );
}


/*
 *  ======== thrProcessStartup ========
 *
 */
Void thrProcessStartup()
{
    setParamsAndStartChannels( TRUE );
}


/*
 *  ======== setParamsAndStartChannels ========
 *
 */
static Void setParamsAndStartChannels( Bool doChannelOpen ) 
{
    IYUV2RGB_Params yuv2rgbParams;
    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;

    yuv2rgbParams             = IYUV2RGB_PARAMS;
    yuv2rgbParams.height      = PROCF_HEIGHT;
    yuv2rgbParams.width       = PROCF_WIDTH;
    yuv2rgbParams.pitch       = RGBF_WIDTH;
    yuv2rgbParams.pitch_in    = PROCF_WIDTH;

    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 
        // -----------------------
        
        for (chanNum = 0; chanNum < NUMPASSCHANS; chanNum++) {
            /*
             *  cell 0 - YUV2RGB: 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.passCells[ chanNum * CHPASSNUMCELLS ];
            *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(NULL, 0);
            UTL_assert( inputIcc != NULL);

            outputIcc = (ICC_Handle)ICC_linearCreate(bufRGBundoubled + 
                                thrProcess.passPlacement[chanNum],
                                PROCF_SIZE_IN_PIXELS);
            UTL_assert( outputIcc != NULL);
        
            rc = CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );
        }

        // -----------------------
        // 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( inputIcc != NULL);

            outputIcc = (ICC_Handle)ICC_linearCreate( bufYCRCB, 
                         sizeof(bufYCRCB));
            UTL_assert( outputIcc != NULL);
                                
            rc = CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );

            /*
             *  cell 1 - YUV2RGB: create an input and output linear ICC.
             */
            cell = &thrProcess.diffCells[ 
                       chanNum * CHDIFFNUMCELLS + CHDIFFCELLYUV];
            *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.diffPlacement[chanNum],
                                PROCF_SIZE_IN_PIXELS);
            UTL_assert( outputIcc != NULL);
        
            rc = CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );
        }
        
        // -----------------------
        // Rotate Channels 
        // -----------------------
        
        for (chanNum = 0; chanNum < NUMROTATECHANS; chanNum++) {
        
            /*
             *  cell 0 - ROTATE: 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.rotateCells[ chanNum * CHROTATENUMCELLS ];
            *cell                = defaultCell;
            cell->name           = "ROTATE";
            cell->cellFxns       = &ROTATE_CELLFXNS;
            cell->cellEnv        = (Ptr *)&thrProcess.rotateEnv[chanNum];
            cell->algFxns        = (IALG_Fxns *)&ROTATE_IROTATE;
            cell->algParams      = (IALG_Params *)&rotateParams;
            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 - YUV2RGB: create an input and output linear ICC.
             */
            cell = &thrProcess.rotateCells[ 
                       chanNum * CHROTATENUMCELLS + CHROTATECELLYUV];
            *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.rotatePlacement[chanNum],
                                PROCF_SIZE_IN_PIXELS);
            UTL_assert( outputIcc != NULL);
        
            rc = CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );

⌨️ 快捷键说明

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