📄 tskencode.c
字号:
#include <std.h>
#include <tsk.h>
#include <stdio.h>
#include <csl.h>
#include <csl_cache.h>
#include <csl_dat.h>
#include <chan.h>
#include <scom.h>
#include <utl.h>
#include <ialg.h>
#include "fvid.h"
#include "celljpegenc_ti.h"
#include "celljpegdec_ti.h"
#include "appmain.h"
#include "appThreads.h"
#include "tskEncode.h"
#include "appBiosObjects.h"
#include "c:\ti\c6000\ndk\inc\netmain.h"
IJPEGENC_Params jpegencParams;
#pragma DATA_SECTION(jpg_img, ".user_data_ext")
#pragma DATA_ALIGN( jpg_img, 128)
static unsigned char jpg_img[128 * 2000];
static Void checkMsg();
ThrEncode thrEncode;
void tskEncodeInit()
{
int chanNum;
ICELL_Obj *cell;
ICC_Handle inputIcc;
ICC_Handle outputIcc;
/*----------------------------------------------------*/
/* Call JPEG specific user initialization if any. */
/*----------------------------------------------------*/
JPEGENC_TI_init();
/*----------------------------------------------------*/
/* Set up params for all XDAIS algorithms. */
/*----------------------------------------------------*/
jpegencParams = IJPEGENC_PARAMS;
for (chanNum = 0; chanNum < PROCESSNUMCHANNELS ; chanNum++)
{
/*
* JPEGENC: create an input and output linear ICC:
* The address to the ICC's will be set in the thrProcessRun()
* function via the ICC_setBuf().
*/
ICELL_Obj defaultCell = ICELL_DEFAULT;
cell = &thrEncode.cellList[(chanNum*PROCESSNUMCELLS) + 0];
*cell = defaultCell;
cell->name = "JPEGENC";
cell->cellFxns = &JPEGENC_CELLFXNS;
cell->algFxns = (IALG_Fxns *)&JPEGENC_IJPEGENC;
cell->algParams = (IALG_Params *)&IJPEGENC_PARAMS;
cell->scrBucketIndex = THRIOSSCRBUCKET;
inputIcc = (ICC_Handle)ICC_linearCreate(NULL, 0);
UTL_assert( inputIcc != NULL);
outputIcc = (ICC_Handle)ICC_linearCreate(NULL, 0);
UTL_assert( outputIcc != NULL);
// Only one input and one output ICC are needed.
CHAN_regCell( cell, &inputIcc, 1, &outputIcc, 1 );
// Setup Encode Parameters
thrEncode.cellList[(chanNum*PROCESSNUMCELLS) + 0].algParams =
(IALG_Params *)&IJPEGENC_PARAMS;
UTL_logDebug1("JPEGEncoder registerd Channel Number: %d", chanNum);
}
}
void tskEncodeStart()
{
Bool rc;
int chanNum;
for( chanNum=0; chanNum < PROCESSNUMCHANNELS; chanNum++ )
{
// open the encode channel: this causes the algorithms to be created
rc = CHAN_open( &thrEncode.chanList[chanNum],
&thrEncode.cellList[(chanNum*PROCESSNUMCELLS)],
PROCESSNUMCELLS, NULL );
UTL_assert( rc == TRUE );
}
}
static Void checkMsg()
{
CtrlMsg rxMsg;
Int index;
Int quality;
ICELL_Handle handle;
IJPEGENC_Params jpegencParams;
int cell_no;
// check message in "mbxProc"
while( MBX_pend( &mbxProcess, &rxMsg, 0) )
{
switch (rxMsg.cmd)
{
case MSGQUALCHANGE: //quality rate value changed
{
index = rxMsg.arg1; // get the index number
UTL_assert( (index >= 0) && (index < PROCESSNUMCHANNELS));
if (index < PROCESSNUMCHANNELS)
{
jpegencParams = IJPEGENC_PARAMS;
cell_no = rxMsg.arg2;
UTL_assert( (cell_no >= 0) && (cell_no < PROCESSNUMCELLS));
quality = rxMsg.arg3;
UTL_assert( (quality >= 0) &&
(quality <= 100));
jpegencParams.quality = quality;
if ((quality > 0) && (quality <= 100))
{
handle = &(thrEncode.cellList[index]);
thrEncode.cellList[cell_no].cellFxns->cellControl
( handle, (IALG_Cmd) (IJPEG_SETSTATUS),
(IALG_Status*)(&(jpegencParams)) );
}
}
break;
}
default:
break;
}
}
}
void tskEncode()
{
int i;
ScomMessage *pMsgBuf;
ScomMessage scomMsg;
void *inBuf[3];
void *outBuf[3];
int jpg_size;
int frame_num = 0;
CHAN_Handle chanHandle;
SCOM_Handle hs_In2Enc,hs_Enc2In;
SCOM_Handle hs_Enc2JPG,hs_JPG2Enc;
hs_In2Enc = SCOM_open("IN2ENC");
hs_Enc2In = SCOM_open("ENC2IN");
hs_Enc2JPG = SCOM_open("ENC2NET");
hs_JPG2Enc = SCOM_open("NET2ENC");
if( !hs_In2Enc || !hs_Enc2In || !hs_Enc2JPG || !hs_JPG2Enc )
{
for(;;);
}
while(1)
{
checkMsg();
for(i=0; i<PROCESSNUMCHANNELS; i++)
{
frame_num++;
// Get Input Buffer
pMsgBuf = SCOM_getMsg( hs_In2Enc, SYS_FOREVER );
//
// Handle Encode Channel
//
chanHandle = &thrEncode.chanList[i];
chanHandle->state = CHAN_ACTIVE;
// Channel Input
inBuf[0] = pMsgBuf->bufY;
inBuf[1] = pMsgBuf->bufU;
inBuf[2] = pMsgBuf->bufV;
ICC_setBuf( chanHandle->cellSet[0].inputIcc[0],
inBuf, sizeof(void *) * 3 );
// Channel Output
outBuf[0] = &jpg_size;
outBuf[1] = jpg_img;
ICC_setBuf( chanHandle->cellSet[0].outputIcc[0],
outBuf, sizeof(void *) * 2 );
// Execute Channel
TSK_setpri( TSK_self(), 6 );
CHAN_execute( chanHandle, frame_num );
TSK_setpri( TSK_self(), 5 );
// UTL_logDebug( "encode finished!" );
// Tell the capture routine we're done
SCOM_putMsg( hs_Enc2In, pMsgBuf );
// Pass the JPG file to the next waiting task
scomMsg.sizeLinear = jpg_size;
scomMsg.bufLinear = jpg_img;
SCOM_putMsg( hs_Enc2JPG, &scomMsg );
// Get back the ownership of the jpg buffer
SCOM_getMsg( hs_JPG2Enc, SYS_FOREVER );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -