总的流程 如下:
读文件代码:
static Void *readRevframeThr(Void * prm){
static UInt32 flag =0;
static UInt32 status ;
Chains_chCfg *chCfg ;
H264FileSource *pFileSource;
FILE *fp =NULL;
Bitstream_Buf *pEmptyBuf;
Bitstream_BufList emptyBufList;
Bitstream_BufList fullBufList;
IpcBitsOutLinkHLOS_BitstreamBufReqInfo reqInfo;
static int chn = 0;
UInt32 bitBufSize,readLen;
Uint32 chns[16] = {0};
UInt32 frameStartTime = 0;
UInt32 frameEndTime = 0;
UInt32 frameInterTime = 8;
Int32 milliSecondsToSleep = 0;
UInt64 timestamp_base = 0;
UInt8 *buffer,head[4],FileBuffer[100000];
static int bufnum = 0;
//Char wfileName[MAX_INPUT_STR_SIZE];
// Int32 wfd;
printf("\n buffer read thread ------ ");
chCfg = (Chains_chCfg *) prm;
pFileSource = &chCfg->fileSource;
bitBufSize = 1366*768 /2 ;
chns[chCfg->channel] = chn++;
sprintf(pFileSource->fileName, "/home/root/clientCh%d.h264", chCfg->channel);
// sprintf(wfileName, "/home/root/readclientCh%d.h264", chCfg->channel);
if (access(pFileSource->fileName, F_OK) != 0) {
}
fp = fopen(pFileSource->fileName, "r" );
if (fp == NULL) {
printf("\n Open %s file error !!! ",pFileSource->fileName);
return NULL;
}
if(chCfg->encFlag){
printf("\n encFlag is true ");
}else{
printf("\n encFlag is false ");
}
while (TRUE == chCfg->encFlag){
__startReadthr:
emptyBufList.numBufs =0 ;
//get Frame length======`
UInt32 flength,temp ;
UInt8 i;
#if 1
buffer = head;
flength = fread(buffer, sizeof(UInt8), 4 * sizeof(UInt8),fp);
if( flength != 4 ){//
fclose(fp);
fp = fopen(pFileSource->fileName, "r" );
if (fp == NULL) {
printf("\n Open %s file error !!! ",pFileSource->fileName);
return NULL;
}
else goto __startReadthr;
}
flength =0;
for( i=0; i<4; i++ ){
temp = (*buffer++)&0x00FF;
temp <<= 8*i;
flength |= temp;
}
//printf("\n buffsize--frame ID is %d-- length is %d ",flag++,flength);
//==========end get length ===========
bitBufSize = flength;
reqInfo.bufSize = flength;
reqInfo.chNum = chns[chCfg->channel];
//=======get file buffer==================
buffer = FileBuffer;
readLen = fread(buffer, 1, flength, fp);
//====end get buffer=============
//if (readLen == 0) {
// printf("\n read data1 ERROR ");
// return NULL;
//}
if (readLen != flength) {
printf("\n read data ERROR ");
return NULL;
}
#endif
OSA_waitMsecs(35);
frameStartTime = OSA_getCurTimeInMsec();
status = IpcBitsOutLink_getEmptyVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0,
&emptyBufList,
&reqInfo);
bufnum ++;
if (emptyBufList.numBufs > 0)
{
//printf("get buf %d \n" , bufnum);
}
OSA_assert(0 == status);
if(0 == emptyBufList.numBufs)
{
printf("\n[#lqh11] Channel %d get buffer fail",chns[chCfg->channel]);
goto __return_process;
}
fullBufList.numBufs = 0;
fullBufList.bufs[fullBufList.numBufs++] = emptyBufList.bufs[0];
pEmptyBuf = emptyBufList.bufs[0];
memcpy(pEmptyBuf->addr, buffer,readLen);
pEmptyBuf->fillLength = readLen;
UInt64 curTimeStamp = timestamp_base++ * 16;
pEmptyBuf->lowerTimeStamp = (UInt32)(curTimeStamp & 0xFFFFFFFF);
pEmptyBuf->upperTimeStamp = (UInt32)((curTimeStamp >> 32)& 0xFFFFFFFF);
if(fullBufList.numBufs){
//printf("put buf %d \n" , bufnum);
IpcBitsOutLink_putFullVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0,
&fullBufList);
}
__return_process:
milliSecondsToSleep = 1;
frameEndTime = OSA_getCurTimeInMsec();
milliSecondsToSleep = frameInterTime + frameStartTime - frameEndTime;
if (milliSecondsToSleep > 0) {
OSA_waitMsecs(milliSecondsToSleep);
milliSecondsToSleep = 0;
}
}
fclose(fp);
return NULL;
}
配置link,必须的一些配置,解码器的配置
for (i = 0; i< chainsCfg->chRecNum; i ++)
{
decPrm.chCreateParams[i].format = chainsCfg->chCfg[0].encFormat;
decPrm.chCreateParams[i].profile = IH264VDEC_PROFILE_ANY;
decPrm.chCreateParams[i].targetMaxWidth = chainsCfg->chCfg[0].inWidth;
decPrm.chCreateParams[i].targetMaxHeight = chainsCfg->chCfg[0].inHeight;
decPrm.chCreateParams[i].fieldMergeDecodeEnable = FALSE;
decPrm.chCreateParams[i].algCreateStatus = DEC_LINK_ALG_CREATE_STATUS_CREATE;
decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate = chainsCfg->chCfg[0].encFrameRate;
decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate = chainsCfg->chCfg[0].bitRate;
decPrm.chCreateParams[i].numBufPerCh = 0;
decPrm.chCreateParams[i].tilerEnable = TRUE;
}
IPC配置
System_LinkQueInfo *pQueinfo ;
System_LinkQueInfo queInfo;
//queInfo.numCh = 1;
printf("\n Channel num is = %d",chainsCfg->chRecNum);
queInfo.numCh = chainsCfg->chRecNum;
for(i =0; i < queInfo.numCh; i++){
#if USE_FRAME
queInfo.chInfo[i].bufType = SYSTEM_BUF_TYPE_VIDFRAME;
#else
queInfo.chInfo[i].bufType = SYSTEM_BUF_TYPE_VIDBITSTREAM;
#endif
queInfo.chInfo[i].codingformat = chainsCfg->chCfg[0].encFormat;
queInfo.chInfo[i].height = chainsCfg->chCfg[0].outHeight;
queInfo.chInfo[i].width = chainsCfg->chCfg[0].outWidth;
queInfo.chInfo[i].memType = SYSTEM_MT_TILEDMEM;
queInfo.chInfo[i].dataFormat = SYSTEM_DF_YUV420SP_VU;
queInfo.chInfo[i].scanFormat = SYSTEM_SF_PROGRESSIVE;
}
ipcBitsOutHostPrm.baseCreateParams.inQueParams.prevLinkId = SYSTEM_LINK_ID_INVALID;
ipcBitsOutHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
ipcBitsOutHostPrm.baseCreateParams.numOutQue = 1;
ipcBitsOutHostPrm.baseCreateParams.numChPerOutQue[0] = 1;
ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink = ipcBitsInVideoId;
ipcBitsOutHostPrm.baseCreateParams.notifyNextLink = TRUE;
ipcBitsOutHostPrm.baseCreateParams.notifyPrevLink = FALSE;
ipcBitsOutHostPrm.baseCreateParams.noNotifyMode = FALSE;
Chains_ipcBitsInitCreateParams_BitsOutHLOS(&ipcBitsOutHostPrm,&queInfo);