⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thrprocess.c

📁 dm642 开发板视频采集输出的例程源码 包括h263_loopback jpeg_loopback mpeg2_loopback 非常珍贵
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 *  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( inputIcc != NULL);
			
            outputIcc = (ICC_Handle)ICC_linearCreate( &thrProcess.OutputBuff, 
                         sizeof(thrProcess.OutputBuff));
                         
            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( &thrProcess.OutputBuff, 
                         sizeof(thrProcess.OutputBuff));
                         
            UTL_assert( outputIcc != NULL);
                                
            rc = CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );

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

⌨️ 快捷键说明

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