thrcapture.c
来自「TI公司的算法标准 Framework5的源代码」· C语言 代码 · 共 242 行
C
242 行
/*
* 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)" */
/*
* ======== thrCapture.c ========
*/
#include <std.h>
#include <string.h>
// DSP/BIOS includes
#include <tsk.h>
// CSL includes
#include <csl_dat.h>
// RF5 module includes
#include <chan.h>
#include <icell.h>
#include <scom.h>
#include <icc_linear.h>
#include <utl.h>
// application includes
#include "appResources.h"
// Ateme IEKC64
#include "iekc64.h"
// Thread include
#include "thrCapture.h"
//Ateme Graphics Library
#include "agl.h"
#pragma DATA_SECTION(thrCaptureInputBuffer,".captureBuf");
#pragma DATA_SECTION(internalCapBuf, ".INTPROCBUFF");
#pragma DATA_SECTION(thrCaptureBufferY,".INTPROCBUFF");
#pragma DATA_SECTION(thrCaptureBufferU,".INTPROCBUFF");
#pragma DATA_SECTION(thrCaptureBufferV,".INTPROCBUFF");
#pragma DATA_ALIGN(thrCaptureInputBuffer,MEMALIGN)
#pragma DATA_ALIGN(internalCapBuf, MEMALIGN);
#pragma DATA_ALIGN(thrCaptureBufferY,MEMALIGN);
#pragma DATA_ALIGN(thrCaptureBufferU,MEMALIGN);
#pragma DATA_ALIGN(thrCaptureBufferV,MEMALIGN);
// Capture Thread object
ThrCapture thrCapture;
//Buffer for interleaved captured image
void *framePtr;
// Buffers for captured images
static Char thrCaptureBufferY[CAPF_SIZE_IN_PIXELS];
static Char thrCaptureBufferU[CAPF_SIZE_IN_PIXELS >> 1];
static Char thrCaptureBufferV[CAPF_SIZE_IN_PIXELS >> 1];
static Char *thrCaptureBufYUV[3];
// IEK required buffer and object
static Uint16 thrCaptureInputBuffer[CAPF_SIZE_IN_PIXELS*CAP_FRAMES];
//Internal buffer for input frame
static Uint16 internalCapBuf[CAPF_SIZE_IN_PIXELS];
static Bool openInput( Void );
static Void getInputFrame( Void );
/*
* ======== thrCaptureInit ========
*
*/
Void thrCaptureInit()
{
SCOM_Handle scomReceive;
/* create your receiving SCOM queue */
scomReceive = SCOM_create( "scomCapture", &SCOM_ATTRS );
UTL_assert( scomReceive != NULL);
}
/*
* ======== thrCaptureStartup ========
*
*/
Void thrCaptureStartup()
{
// open the input device
if (openInput() == FALSE) {
UTL_logError("Input stream failed to open");
SYS_abort("Input stream failed to open");
}
}
/*
* ======== getInputFrame ========
*
* Get and reformat an input frame.
*/
static Void getInputFrame( Void )
{
Bool rc;
thrCapture.thrCaptureHVin = NULL;
// Wait until we get an input frame
UTL_stsStart( stsWaitTime );
rc = IEKC64_SUCCESS(VIN_getFrame(thrCapture.thrCaptureHVin, &framePtr,
IEKC64_VIDEO_WAIT_INFINITE));
UTL_stsStop( stsWaitTime );
UTL_assert( rc == TRUE );
//Transfer input buffer from external mem to internal for coherency
DAT_wait(DAT_copy2d(DAT_2D1D, framePtr, (void *) internalCapBuf, CAPF_WIDTH << 1, CAPF_HEIGHT, CAPF_WIDTH << 1));
/*
Convert [y0,u0,y1,v0,y2,u1,...] to separate buffers
[y0,y1,y2,...]
[u0,u1,u2,...]
[v0,v1,v2,...]
*/
CONV_YUY2toIYUV((const Uint16 *) internalCapBuf, CAPF_WIDTH, CAPF_HEIGHT,
(Uint16 *) thrCaptureBufferY,
(Uint16 *) thrCaptureBufferU,
(Uint16 *) thrCaptureBufferV);
// Copy address of Y,U,and V into output buffers
thrCaptureBufYUV[0] = thrCaptureBufferY;
thrCaptureBufYUV[1] = thrCaptureBufferU;
thrCaptureBufYUV[2] = thrCaptureBufferV;
}
/*
* ======== openInput ========
*
* Open the Ateme video input port.
*/
static Bool openInput( Void )
{
static Bool firstTime = TRUE; // Must not allocate resources multiple times
IEKC64_STATUS status;
if (firstTime == TRUE) {
firstTime = FALSE;
thrCapture.thrCaptureVideoIn.Standard=VIDEO_STANDARD;
thrCapture.thrCaptureVideoIn.Resolution=VIDEO_INPUT_RES;
thrCapture.thrCaptureVideoIn.FrameFormat=YUV422PIXEL;
thrCapture.thrCaptureVideoIn.VideoInSelect=COMPOSITE;
thrCapture.thrCaptureVideoIn.nTemporalDecimationFactor=1;
thrCapture.thrCaptureVideoIn.isOneShot=FALSE;
thrCapture.thrCaptureVideoIn.nFramesInBuffer=CAP_FRAMES;
thrCapture.thrCaptureVideoIn.nFramesToKeep=2;
thrCapture.thrCaptureVideoIn.pCaptureBuffer=(Uint32*)thrCaptureInputBuffer;
// Init capture buffer to 0 for debugging
memset(thrCaptureInputBuffer, 0x00,
CAPF_SIZE_IN_PIXELS * CAP_FRAMES * sizeof(Uint16) );
// Let's open and start capture
status = VIN_open(&thrCapture.thrCaptureVideoIn,&thrCapture.thrCaptureHVin);
if (!IEKC64_SUCCESS(status)) {
UTL_logError1("VIN_open() failed with 0x%08X\n", status );
return (FALSE);
}
status = VIN_start(thrCapture.thrCaptureHVin);
if (!IEKC64_SUCCESS(status)) {
UTL_logError1("VIN_start() failed with 0x%08X\n", status );
return (FALSE);
}
}
return (TRUE);
}
/*
* ======== thrCaptureRun ========
*
* Main function of capture thread.
*/
Void thrCaptureRun()
{
SCOM_Handle scomReceive, scomSend;
Int counter = 0;
UTL_logDebug1("thrCaptureRun: task = 0x%x", TSK_self());
// create the SCOM links (one for receiving and another for sending)
scomReceive = SCOM_open( "scomCapture" );
scomSend = SCOM_open( "scomToProcessFromCapture" );
UTL_assert( scomReceive != NULL );
UTL_assert( scomSend != NULL );
while (TRUE) {
ScomCapToProc *scombufCap;
Int yBufId;
Int CrBufId;
Int CbBufId;
getInputFrame();
//Counter for measuring frames/sec - use with stopwatch
counter++;
// get the structure describing destination channels
scombufCap = SCOM_getMsg( scomReceive, SYS_FOREVER );
// Calculate how long it takes to capture + display one frame
UTL_stsPeriod( stsCycleTime );
//Copy buffers to SCOM object buffer
yBufId = DAT_copy2d(DAT_2D1D, (void *)thrCaptureBufYUV[0], (void *)scombufCap->bufYCRCB[0],
CAPF_WIDTH, CAPF_HEIGHT, CAPF_WIDTH);
CrBufId = DAT_copy2d(DAT_2D1D, (void *)thrCaptureBufYUV[1], (void *)scombufCap->bufYCRCB[1],
CAPF_WIDTH>>1, CAPF_HEIGHT, CAPF_WIDTH>>1);
CbBufId = DAT_copy2d(DAT_2D1D, (void *)thrCaptureBufYUV[2], (void *)scombufCap->bufYCRCB[2],
CAPF_WIDTH>>1, CAPF_HEIGHT, CAPF_WIDTH>>1);
//Wait for transfers
DAT_wait(yBufId);
DAT_wait(CrBufId);
DAT_wait(CbBufId);
// send the now full buffer to Process
SCOM_putMsg( scomSend, scombufCap );
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?