This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DM8168 DVRRDK standalone decoder using LinkAPI

Hi,

I am writing a decoder app that will take input from .h264 file , decode and write the output to another file. I am using TI DM8168 platform.

After reading other forum articles, my present form of code is below.

Being inside the directory "dvr_rdk/demos/link_api_demos/vpss_chains", I compiled the below program by linking with ./dec_single_syslink.c ../common/chains_ipcBits.c dvr_rdk_mcfw_api.a dvr_rdk_link_api.a dvr_rdk_mcfw_api.a dvr_rdk_osa.a syslink.a -lpthread -lm

I ran the resultant output executable, on the target-board after performing /opt/dvr_rdk/ti816x/init.sh and load.sh.


I am able to run the program, and it shows the links as successfully created as follows:

"

[host] 3676: SYSTEM: Opening ListMP [VIDEO-M3_IPC_OUT_19] ...
3678: SYSTEM: Opening ListMP [VIDEO-M3_IPC_IN_19] ...

[host] 3680: IPC_FRAMES_IN : Create Done !!!
SYSTEM INFO >>> FILE - DEC - FILE Links Created

Enter Choice: [m3video] 23665: IPC_FRAMES_OUT : Create in progress !!!
[m3video] 23667: IPC_FRAMES_OUT : Create Done !!!

"

But the statistics show that the frames are never processed through the links and there is no output frame.

I wrote my own "input_from_file" thread and didnt use chains_ipcBitsinit.

I am also not sure whether i am using the getBitstream buffer APIs correctly,

I dont know what i am missing here and will appreciate the help.

Code:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <demos/link_api_demos/common/chains.h>

Void Chains_FileDecFileWr(Chains_Ctrl *chainsCfg);

#define TRUE 1
#define FALSE 0

#define SRC_NUM_CH 1
#define NUM_BUF_PER_CH 1

pthread_mutex_t g_mutex;
pthread_cond_t g_condition;
int conditionMet=0;

/**
FILE (H264)
|
|
IPC_BITS_OUT_A8 (BitStream)
|
IPC_BITS_IN_M3 (BitStream)
|
DEC
|
IPC_FRAMES_OUT_M3 (Frames)
|
IPC_FRAMES_IN_A8 (Frames)
|
|
FILE (YUV)
*/

static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl =
{
.isPopulated = 1,
.ivaMap[0] =
{
.EncNumCh = 0,
.EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
.DecNumCh = 1,
.DecChList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 , 14, 15},
},
.ivaMap[1] =
{
.EncNumCh = 0,
.EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
.DecNumCh = 0,
.DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0},
},
.ivaMap[2] =
{
.EncNumCh = 0,
.EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
.DecNumCh = 0,
.DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
},
};


Int32 Chains_memPrintHeapStatus()
{
printf("Stub: chains_memPrintHeap");

return 0;
}

char gChains_runTimeMenu[] = {
"\r\n ===================="
"\r\n Chains Run-time Menu"
"\r\n ===================="
"\r\n"
"\r\n 0: Stop Chain"
"\r\n"
"\r\n i: Print IVA-HD Statistics "
"\r\n "
"\r\n Enter Choice: "
};

/* Heap Id registered with MessageQ for allocating message buffers.
The heap associated with PE_MESSAGEQ_SHARED_REGION_ID is registered
as PE_MESSAGEQ_HEAP_ID. */
const unsigned short Rpe_messageqHeapId = 0;

char Chains_menuRunTime()
{
char ch[128];
printf(gChains_runTimeMenu);
fgets(ch, 128, stdin);
if(ch[1] != '\n' || ch[0] == '\n')
ch[0] = '\n';
return ch[0];
}

Void Chains_run(Chains_RunFunc chainsRunFunc)
{
Chains_Ctrl chainsCtrl;

//Chains_detectBoard();

System_linkControl(
SYSTEM_LINK_ID_M3VPSS,
SYSTEM_M3VPSS_CMD_RESET_VIDEO_DEVICES,
NULL,
0,
TRUE
);
#if 0
UInt32 displayResDefault[SYSTEM_DC_MAX_VENC] =
{VSYS_STD_1080P_60, //SYSTEM_DC_VENC_HDMI,
VSYS_STD_1080P_60, //SYSTEM_DC_VENC_HDCOMP,
VSYS_STD_1080P_60, //SYSTEM_DC_VENC_DVO2
VSYS_STD_NTSC //SYSTEM_DC_VENC_SD,
};

chainsCtrl.enableNsfLink = FALSE;
chainsCtrl.enableOsdAlgLink = FALSE;
chainsCtrl.enableVidFrameExport = FALSE;
chainsCtrl.bypassNsf = FALSE;

// memcpy(gChains_ctrl.displayRes,displayResDefault,sizeof(gChains_ctrl.displayRes));
// memcpy(&chainsCtrl, &gChains_ctrl, sizeof(gChains_ctrl));

// Chains_memPrintHeapStatus();
#endif 
UTILS_assert( chainsRunFunc!=NULL);
chainsRunFunc(&chainsCtrl);


}

char gChains_menuMain0[] = {
"\r\n ============"
"\r\n Chain Select"
"\r\n ============"
"\r\n"
};

char gChains_menuMainVs[] = {
"\r\n"
"\r\n 1: <H264 FILERD-> DEC->FILEWR>"
"\r\n "
"\r\n s: System Settings "
"\r\n "
"\r\n x: Exit "
"\r\n "
"\r\n Enter Choice: "
};

Void Chains_menuMainShow()
{
printf(gChains_menuMain0);

//Chains_menuCurrentSettingsShow();

printf(gChains_menuMainVs);
}


Void Chains_menuMainRunVs(char ch)
{


switch(ch)
{
case '1':

Chains_run(Chains_FileDecFileWr);
break;
case '2':
printf("invalid option 2");
// Chains_run(Chains_multiChEncDecLoopBack);
break;
case '3':
printf("invalid option 3");
// Chains_run(Chains_multiChEncDecLoopBack);
break;
case '4':
printf("invalid option 4");
// Chains_run(Chains_multiChEncDecLoopBack);
break;
default:
break;
}
}

Void Chains_main()
{
char ch[128];
Bool done;

done = FALSE;

// Chains_setDefaultCfg();

while(!done)
{
Chains_menuMainShow();

fgets(ch, 128, stdin);
if(ch[1] != '\n' || ch[0] == '\n')
continue;

printf(" \r\n");

Chains_menuMainRunVs(ch[0]);

switch(ch[0])
{
case 's':
// Chains_menuSettings();
break;
case 'x':
done = TRUE;
break;
case 'd':
//Chains_detectBoard();
break;
}

}
}


#define INI_FILE "/opt/sample.h264"
#define INI_FRAME_WIDTH 2048
#define INI_FRAME_HEIGHT 1536
#define INI_ENABLE 1
#define INI_CODEC h264
#define INI_NUMBUF 0
#define INI_DISP_DELAY 0


Void Chains_FileDecFileWr(Chains_Ctrl *chainsCfg)
{
IpcBitsOutLinkHLOS_CreateParams ipcBitsOutHostPrm;
IpcBitsInLinkRTOS_CreateParams ipcBitsInVideoPrm;


DecLink_CreateParams decPrm;

IpcFramesOutLinkRTOS_CreateParams ipcFramesOutVideoPrm;
IpcFramesInLinkHLOS_CreateParams ipcFramesInHostPrm;


Int i;
Bool isProgressive;
System_LinkInfo bitsProducerLinkInfo;

UInt32 decId;
UInt32 ipcFramesOutVideoId, ipcFramesInHostId;
UInt32 ipcBitsInVideoId, ipcBitsOutHostId;
char ch; 
int rc;

//Chains_ipcBitsInit();
CHAINS_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
CHAINS_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);

CHAINS_INIT_STRUCT(DecLink_CreateParams, decPrm);

CHAINS_INIT_STRUCT(IpcFramesOutLinkRTOS_CreateParams,ipcFramesOutVideoPrm);
CHAINS_INIT_STRUCT(IpcFramesInLinkHLOS_CreateParams,ipcFramesInHostPrm);

ipcBitsOutHostId = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
ipcBitsInVideoId = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;

decId = SYSTEM_LINK_ID_VDEC_0;

ipcFramesOutVideoId = SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_OUT_0;
ipcFramesInHostId = SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0;

//decPrm.tilerEnable = FALSE; 
isProgressive = TRUE;

System_linkControl(
SYSTEM_LINK_ID_M3VIDEO,
SYSTEM_COMMON_CMD_SET_CH2IVAHD_MAP_TBL,
&systemVid_encDecIvaChMapTbl,
sizeof(SystemVideo_Ivahd2ChMap_Tbl),
TRUE
);


ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink = ipcBitsInVideoId;
ipcBitsOutHostPrm.baseCreateParams.notifyNextLink = FALSE;
ipcBitsOutHostPrm.baseCreateParams.notifyPrevLink = FALSE;
ipcBitsOutHostPrm.baseCreateParams.noNotifyMode = TRUE;
ipcBitsOutHostPrm.baseCreateParams.numOutQue = 1;
ipcBitsOutHostPrm.inQueInfo.numCh = SRC_NUM_CH;
ipcBitsOutHostPrm.bufPoolPerCh = TRUE;

for (i=0; i<SRC_NUM_CH; i++)
{
ipcBitsOutHostPrm.inQueInfo.chInfo[i].width = INI_FRAME_WIDTH;
ipcBitsOutHostPrm.inQueInfo.chInfo[i].height = INI_FRAME_HEIGHT;
ipcBitsOutHostPrm.inQueInfo.chInfo[i].scanFormat = SYSTEM_SF_PROGRESSIVE;
ipcBitsOutHostPrm.inQueInfo.chInfo[i].bufType = 0; // NOT USED
ipcBitsOutHostPrm.inQueInfo.chInfo[i].codingformat = 0; // NOT USED
ipcBitsOutHostPrm.inQueInfo.chInfo[i].dataFormat = 0; // NOT USED
ipcBitsOutHostPrm.inQueInfo.chInfo[i].memType = 0; // NOT USED
ipcBitsOutHostPrm.inQueInfo.chInfo[i].startX = 0; // NOT USED
ipcBitsOutHostPrm.inQueInfo.chInfo[i].startY = 0; // NOT USED
ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[0] = 0; // NOT USED
ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[1] = 0; // NOT USED
ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[2] = 0; // NOT USED
ipcBitsOutHostPrm.numBufPerCh[i] = NUM_BUF_PER_CH;
}

/* IPC Host to IPC Video*/
ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId = ipcBitsOutHostId;
ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink = decId;
ipcBitsInVideoPrm.baseCreateParams.noNotifyMode = TRUE;
ipcBitsInVideoPrm.baseCreateParams.notifyNextLink = TRUE;
ipcBitsInVideoPrm.baseCreateParams.notifyPrevLink = TRUE;
ipcBitsInVideoPrm.baseCreateParams.numOutQue = 1;

/* IPC Video to DEC*/
for (i=0; i<SRC_NUM_CH; i++) {
decPrm.chCreateParams[i].format = IVIDEO_H264HP;
decPrm.chCreateParams[i].profile = IH264VDEC_PROFILE_ANY;
decPrm.chCreateParams[i].targetMaxWidth = INI_FRAME_WIDTH;
decPrm.chCreateParams[i].targetMaxHeight = INI_FRAME_HEIGHT;
#if 0
if (isProgressive)
decPrm.chCreateParams[i].fieldMergeDecodeEnable = FALSE;
else
decPrm.chCreateParams[i].fieldMergeDecodeEnable = TRUE;
#endif
decPrm.chCreateParams[i].numBufPerCh = NUM_BUF_PER_CH;
decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate = 25;
decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate = (2 * 1000 * 1000);
}
decPrm.inQueParams.prevLinkId = ipcBitsInVideoId;
decPrm.inQueParams.prevLinkQueId = 0;
decPrm.outQueParams.nextLink = ipcFramesOutVideoId;

/*DEC to IPC Video Frame out*/

ipcFramesOutVideoPrm.baseCreateParams.noNotifyMode = TRUE;
ipcFramesOutVideoPrm.baseCreateParams.notifyNextLink = FALSE;
ipcFramesOutVideoPrm.baseCreateParams.notifyPrevLink = FALSE;
ipcFramesOutVideoPrm.baseCreateParams.inQueParams.prevLinkId = decId;
ipcFramesOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
ipcFramesOutVideoPrm.baseCreateParams.numOutQue = 1;
ipcFramesOutVideoPrm.baseCreateParams.outQueParams[0].nextLink = ipcFramesInHostId;

/*IPC Frame video out to Host IN*/
ipcFramesInHostPrm.baseCreateParams.noNotifyMode = TRUE;
ipcFramesInHostPrm.baseCreateParams.notifyNextLink = FALSE;
ipcFramesInHostPrm.baseCreateParams.notifyPrevLink = FALSE;
ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkId = ipcFramesOutVideoId;
ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
ipcFramesInHostPrm.baseCreateParams.outQueParams[0].nextLink = SYSTEM_LINK_ID_INVALID;


System_linkCreate(ipcBitsOutHostId,&ipcBitsOutHostPrm,sizeof(ipcBitsOutHostPrm));
System_linkCreate(ipcBitsInVideoId,&ipcBitsInVideoPrm,sizeof(ipcBitsInVideoPrm));
System_linkCreate(decId, &decPrm, sizeof(decPrm));
sleep(2);
System_linkCreate(ipcFramesOutVideoId, &ipcFramesOutVideoPrm, sizeof(ipcFramesOutVideoPrm));
System_linkCreate(ipcFramesInHostId, &ipcFramesInHostPrm, sizeof(ipcFramesInHostPrm));

printf("SYSTEM INFO >>> FILE - DEC - FILE Links Created\n");


System_linkStart(ipcFramesInHostId);
System_linkStart(ipcFramesOutVideoId);
System_linkStart(decId);
System_linkStart(ipcBitsInVideoId);
System_linkStart(ipcBitsOutHostId);

rc = pthread_mutex_lock(&g_mutex);
conditionMet =1;
rc = pthread_cond_broadcast(&g_condition);
rc = pthread_mutex_unlock(&g_mutex);


/* Start taking CPU load just before starting of links */


while(1)
{
ch = Chains_menuRunTime();
if(ch=='0')
break;
if(ch=='i')
System_linkControl(decId, DEC_LINK_CMD_PRINT_IVAHD_STATISTICS, NULL, 0, TRUE);
if(ch=='d')
System_linkControl(decId, DEC_LINK_CMD_PRINT_STATISTICS, NULL, 0, TRUE);
if(ch=='D')
System_linkControl(decId, DEC_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);
if(ch=='b')
System_linkControl(ipcBitsOutHostId, IPCBITSOUT_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);
}
//Chains_ipcBitsStop();
System_linkStop(ipcBitsOutHostId);
System_linkStop(ipcBitsInVideoId);
System_linkStop(decId);

System_linkDelete(ipcBitsOutHostId);
System_linkDelete(ipcBitsInVideoId);
System_linkDelete(decId);
System_linkDelete(ipcFramesOutVideoId);
System_linkDelete(ipcFramesInHostId);


//Chains_ipcBitsExit();
}


#if 0

static Void VdecVdis_setFrameTimeStamp(VCODEC_BITSBUF_S *pEmptyBuf)
{
UInt64 curTimeStamp =
gVdecVdis_config.frameCnt[pEmptyBuf->chnId] * VDEC_VDIS_FRAME_DURATION_MS;
pEmptyBuf->lowerTimeStamp = (UInt32)(curTimeStamp & 0xFFFFFFFF);
pEmptyBuf->upperTimeStamp = (UInt32)((curTimeStamp >> 32)& 0xFFFFFFFF);
if (0 == gVdecVdis_config.frameCnt[pEmptyBuf->chnId])
{
UInt32 displayChId;

Vdec_mapDec2DisplayChId(VDIS_DEV_HDMI,pEmptyBuf->chnId,&displayChId);
Vdis_setFirstVidPTS(VDIS_DEV_HDMI,displayChId,curTimeStamp);
Vdec_mapDec2DisplayChId(VDIS_DEV_HDCOMP,pEmptyBuf->chnId,&displayChId);
Vdis_setFirstVidPTS(VDIS_DEV_HDCOMP,displayChId,curTimeStamp);
Vdec_mapDec2DisplayChId(VDIS_DEV_SD,pEmptyBuf->chnId,&displayChId);
Vdis_setFirstVidPTS(VDIS_DEV_SD,displayChId,curTimeStamp);
}
gVdecVdis_config.frameCnt[pEmptyBuf->chnId] += 1;
}

#endif

static Void Vdec_copyBitBufInfoLink2McFw(VCODEC_BITSBUF_S *dstBuf,
Bitstream_Buf *srcBuf)
{
dstBuf->reserved = (UInt32)srcBuf;
dstBuf->bufVirtAddr = srcBuf->addr;
dstBuf->bufSize = srcBuf->bufSize;
dstBuf->chnId = srcBuf->channelNum;
dstBuf->codecType = srcBuf->codingType;
dstBuf->filledBufSize = srcBuf->fillLength;
dstBuf->timestamp = srcBuf->timeStamp;
dstBuf->upperTimeStamp = srcBuf->upperTimeStamp;
dstBuf->lowerTimeStamp = srcBuf->lowerTimeStamp;
dstBuf->bottomFieldBitBufSize = srcBuf->bottomFieldBitBufSize;
dstBuf->inputFileChanged = srcBuf->inputFileChanged;

if (srcBuf->isKeyFrame)
dstBuf->frameType = VCODEC_FRAME_TYPE_I_FRAME;
else
dstBuf->frameType = VCODEC_FRAME_TYPE_P_FRAME;

dstBuf->bufPhysAddr = (Void *)srcBuf->phyAddr;
dstBuf->frameWidth = srcBuf->frameWidth;
dstBuf->frameHeight = srcBuf->frameHeight;
dstBuf->doNotDisplay = FALSE;
/*TODO the following members need to be added to bitstream buf */
dstBuf->fieldId = 0;
dstBuf->strmId = 0;
dstBuf->seqId = srcBuf->seqId;
print_diag(dstBuf);
}

void print_diag(VCODEC_BITSBUF_S *dstBuf)
{
printf("dstBuf->reserved = %u\n",dstBuf->reserved);
printf("dstBuf->bufVirtAddr = %u\n", dstBuf->bufVirtAddr);
printf("dstBuf->bufSize = %u\n", dstBuf->bufSize);
printf("dstBuf->chnId = %u\n", dstBuf->chnId);
printf("dstBuf->codecType = %u\n", dstBuf->codecType);
printf("dstBuf->filledBufSize = %u\n", dstBuf->filledBufSize);
printf("dstBuf->timestamp = %u\n", dstBuf->timestamp);
printf("dstBuf->upperTimeStamp = %u\n", dstBuf->upperTimeStamp);
printf("dstBuf->lowerTimeStamp = %u\n", dstBuf->lowerTimeStamp);
printf("dstBuf->bottomFieldBitBufSize = %u\n", dstBuf->bottomFieldBitBufSize);
printf("dstBuf->inputFileChanged = %u\n", dstBuf->inputFileChanged);
printf("dstBuf->frameType = %u\n", dstBuf->frameType);
printf("dstBuf->bufPhysAddr = %u\n", dstBuf->bufPhysAddr);
printf("dstBuf->frameWidth = %u\n", dstBuf->frameWidth);
printf("dstBuf->frameHeight = %u\n", dstBuf->frameHeight);
printf("dstBuf->doNotDisplay = %u\n", dstBuf->doNotDisplay);
printf("dstBuf->seqId = %u\n", dstBuf->seqId);
fflush(stdout);
}


void input_from_file(void *parm)
{
int rc;
IpcBitsOutLinkHLOS_BitstreamBufReqInfo reqInfo;
Bitstream_BufList emptyBufList;
Bitstream_BufList bufList;
int iRet;
int i;
int read_size;
int status;
FILE *fphdr;
int fd;
VCODEC_BITSBUF_S *pEmptyBuf;
VCODEC_BITSBUF_S *pOutBuf, *pInBuf;
VCODEC_BITSBUF_LIST_S BitsBufList;
VCODEC_BITSBUF_LIST_S *pBitsBufList;
int ret_status;
int input_frame_count = 0;

/* wait for links to be created*/
/*
int pthread_cond_wait(pthread_cond_t *restrict cond,
pthread_mutex_t *restrict mutex);

*/


while (!conditionMet) {
printf("input Thread blocked\n");
rc = pthread_cond_wait(&g_condition, &g_mutex);

}


fd = open("/opt/sample.h264", O_RDONLY);
if(fd <= 0)
{
printf("file open error");
exit(-1);
}

fphdr = fopen("/opt/sample.h264.hdr", "r");
if(fphdr == NULL)
{
printf("file open error");
exit(-1);
}

while(1)
{
reqInfo.numBufs = 1;
reqInfo.reqType = IPC_BITSOUTHLOS_BITBUFREQTYPE_CHID;

for (i = 0; i< 1; i++) 
reqInfo.u[i].chNum = i;

ret_status = IpcBitsOutLink_getEmptyVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &emptyBufList, &reqInfo);

OSA_assert(0 == ret_status);

pBitsBufList = &BitsBufList;
pBitsBufList->numBufs = emptyBufList.numBufs;

for (i = 0; i < emptyBufList.numBufs; i++)
{
pOutBuf = &pBitsBufList->bitsBuf[i];
pInBuf = emptyBufList.bufs[i];
Vdec_copyBitBufInfoLink2McFw(pOutBuf, pInBuf);
}

pEmptyBuf= &BitsBufList.bitsBuf[0];

/*iChains_ipcBitsReadBitsFromFile(&emptyBufList, maxDataSize);*/
int statHdr, statData;
int curCh;
statHdr = fscanf(fphdr,"%d",&(pEmptyBuf->filledBufSize));

OSA_assert(pEmptyBuf->filledBufSize <= pEmptyBuf->bufSize);
statData = read(fd, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
print_diag(pEmptyBuf);
if( feof(fphdr) || statData != pEmptyBuf->filledBufSize)
{

printf(" CH Reached the end of file, inputframecount = %d !!!",input_frame_count);

#if 0

/*rewind*/
clearerr(fphdr);

rewind(fphdr);
lseek(fp, 0, SEEK_SET);
statHdr = fscanf(fphdr,"%d",&(pEmptyBuf->filledBufSize));

OSA_assert(pEmptyBuf->filledBufSize <= pEmptyBuf->bufSize);
statData = read(fp, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
#endif
break;
}

ret_status = IpcBitsOutLink_putFullVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &BitsBufList);
input_frame_count++;

//sleep(1);
}

close(fd);
fclose(fphdr);


}

static Void Chains_ipcFramesPrintFrameInfo(VIDFrame_Buf *buf)
{
OSA_printf("CHAINS_IPCFRAMES:VIDFRAME_INFO:"
"chNum:%d\t"
"fid:%d\t"
"frameWidth:%d\t"
"frameHeight:%d\t"
"timeStamp:%d\t"
"virtAddr[0][0]:%p\t"
"phyAddr[0][0]:%p",
buf->channelNum,
buf->fid,
buf->frameWidth,
buf->frameHeight,
buf->timeStamp,
buf->addr[0][0],
buf->phyAddr[0][0]);

}


void receive_output_and_filw(void *parm)
{

int fd;
VCODEC_BITSBUF_S *pEmptyBuf;
VIDFrame_BufList bufList;
int status;
int i;
int rc;

OSA_printf("CHAINS_IPCFRAMES:%s:Entered...",__func__);
// OSA_semWait(&thrObj->framesInNotifySem,OSA_TIMEOUT_FOREVER);
OSA_printf("CHAINS_IPCFRAMES:Received first frame notify...");

#if 0
fd = open("/opt/out.yuv", O_WRONLY);
if(fd <= 0)
{
printf("file open error");
exit(-1);
}
#endif

while (!conditionMet) {
printf("Output Thread blocked\n");
rc = pthread_cond_wait(&g_condition, &g_mutex);

}
sleep(1);

while(1)
{


status = IpcFramesInLink_getFullVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0,
&bufList);
OSA_assert(0 == status);
if (bufList.numFrames > 0)
{
printf("FULLF:");
for(i = 0; i < bufList.numFrames;i++)
/*writetofile(bufList.frames[i])*/
Chains_ipcFramesPrintFrameInfo(&bufList.frames[i]);


// pEmptyBuf= &BitsBufList.bitsBuf[0];
// statData = write(fd, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
status = IpcFramesInLink_putEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0, &bufList);

}

#if 0
status = IpcFramesOutLink_getEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_OUT_0,
&bufList);
OSA_assert(0 == status);
if (bufList.numFrames)
{
printf("emptyF:");
for(i = 0; i < bufList.numFrames;i++)
/*writetofile(bufList.frames[i])*/
Chains_ipcFramesPrintFrameInfo(&bufList.frames[i]);


status = IpcFramesInLink_putEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0,
&bufList);
OSA_assert(0 == status);
}
#endif

}
close(fd);


}

int main()
{
pthread_t thrd,thrd2;
char *message1 = "Thread 1";
char *message2 = "Thread 2";
pthread_mutexattr_t mutexattr; // Mutex Attribute
pthread_condattr_t attr;
int rc;
int iret1;


System_init();

rc = pthread_condattr_init(&attr);
pthread_mutexattr_init(&mutexattr);
pthread_mutex_init(&(g_mutex), &mutexattr);
pthread_cond_init(&(g_condition), &attr);
conditionMet = 0;
iret1 = pthread_create( &thrd, NULL, input_from_file, (void*) message1);
iret1 = pthread_create( &thrd2, NULL, receive_output_and_filw, (void*) message2);
Chains_main();


System_deInit();

pthread_cond_destroy(&g_condition);
return 0;
}

  • The statistic infor for IOCTL  "IPCBITSOUT_LINK_CMD_PRINT_BUFFER_STATISTICS" is:


    "
    [m3video] *** Decode Statistics ***
    [m3video] 213312: DEC: Rcvd from prev = 0, Returned to prev = 0
    [m3video] DEC Out BufExt Q Status
    [m3video] Empty Q 0 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Full Q -> count 0, wrPtr 0, rdPtr 0

    "

    Does it mean that  i am not sending the input buffers correctly?.

    thanks,

  • There are a couple of issues with your usecase file:.Below code is wrong:

    ipcFramesInHostPrm.baseCreateParams.noNotifyMode = TRUE;
    ipcFramesInHostPrm.baseCreateParams.notifyNextLink = FALSE;
    ipcFramesInHostPrm.baseCreateParams.notifyPrevLink = FALSE;

    ipcBitsInVideoPrm.baseCreateParams.noNotifyMode = TRUE;
    ipcBitsInVideoPrm.baseCreateParams.notifyNextLink = TRUE;
    ipcBitsInVideoPrm.baseCreateParams.notifyPrevLink = TRUE;

    It should be

    ipcFramesInHostPrm.baseCreateParams.noNotifyMode = TRUE;
    ipcFramesInHostPrm.baseCreateParams.notifyNextLink = FALSE;
    ipcFramesInHostPrm.baseCreateParams.notifyPrevLink = TRUE;

    ipcBitsInVideoPrm.baseCreateParams.noNotifyMode = TRUE;
    ipcBitsInVideoPrm.baseCreateParams.notifyNextLink = TRUE;
    ipcBitsInVideoPrm.baseCreateParams.notifyPrevLink = FALSE;

  • Thanks Badri  for replying. But still i am not able to get the output frame.

    I have attached the C file that i used. The statistics that i collected after the links are started is below.

    I suspect that i am not giving the input buffers at all.

    Is it possible that "IpcBitsOutLink_getEmptyVideoBitStreamBufs" to block, because i am not getting the subsequent printfs.

    stats:

    =======================

    DEC_LINK_CMD_PRINT_IVAHD_STATISTICS
    ================================

    [m3video] *** DECODE Statistics ***
    [m3video]
    [m3video] Elasped Time : 38 secs
    [m3video]
    [m3video]
    [m3video] CH | In Recv In User Out
    [m3video] Num | FPS Skip FPS FPS
    [m3video] -----------------------------------
    [m3video] 0 | 0 0 0
    [m3video] 1 | 0 0 0
    [m3video] 2 | 0 0 0
    [m3video] 3 | 0 0 0
    [m3video] 4 | 0 0 0
    [m3video] 5 | 0 0 0
    [m3video] 6 | 0 0 0
    [m3video] 7 | 0 0 0
    [m3video] 8 | 0 0 0
    [m3video] 9 | 0 0 0
    [m3video] 10 | 0 0 0
    [m3video] 11 | 0 0 0
    [m3video] 12 | 0 0 0
    [m3video] 13 | 0 0 0
    [m3video] 14 | 0 0 0
    [m3video] 15 | 0 0 0
    [m3video]
    [m3video] Multi Channel Decode Average Submit Batch Size
    [m3video] Max Submit Batch Size : 24
    [m3video] IVAHD_0 Average Batch Size : 0
    [m3video] IVAHD_0 Max achieved Batch Size : 0
    [m3video] IVAHD_1 Average Batch Size : 0
    [m3video] IVAHD_1 Max achieved Batch Size : 0
    [m3video] IVAHD_2 Average Batch Size : 0
    [m3video] IVAHD_2 Max achieved Batch Size : 0
    [m3video]
    [m3video] Multi Channel Decode Batch break Stats
    [m3video] Total Number of Batches created: 0
    [m3video] All numbers are based off total number of Batches created
    [m3video] Batch breaks due to batch sizeexceeding limit: 0 %
    [m3video] Batch breaks due to ReqObj Que being empty: 0 %
    [m3video] Batch breaks due to changed resolution class: 0 %
    [m3video] Batch breaks due to interlace and progressivecontent mix: 0 %
    [m3video] Batch breaks due to channel repeat: 0 %
    [m3video] Batch breaks due to different codec: 0 %
    [m3video] Total Number of Batches created: 0
    [m3video] All numbers are based off total number of Batches created
    [m3video] Batch breaks due to batch sizeexceeding limit: 0 %
    [m3video] Batch breaks due to ReqObj Que being empty: 0 %
    [m3video] Batch breaks due to changed resolution class: 0 %
    [m3video] Batch breaks due to interlace and progressivecontent mix: 0 %
    [m3video] Batch breaks due to channel repeat: 0 %
    [m3video] Batch breaks due to different codec: 0 %
    [m3video] Total Number of Batches created: 0
    [m3video] All numbers are based off total number of Batches created
    [m3video] Batch breaks due to batch sizeexceeding limit: 0 %
    [m3video] Batch breaks due to ReqObj Que being empty: 0 %
    [m3video] Batch breaks due to changed resolution class: 0 %
    [m3video] Batch breaks due to interlace and progressivecontent mix: 0 %
    [m3video] Batch breaks due to channel repeat: 0 %
    [m3video] Batch breaks due to different codec: 0 %
    [m3video]

    =================================

     IPCBITSOUT_LINK_CMD_PRINT_BUFFER_STATISTICS

    ================================

    IPCBITSOUTLINK:Buffer Statistics
    Num Alloc Pools:16
    PoolId | TotalBufCnt | FreeBufCnt | BufSize | AppAllocCount
    0| 1| 1| 230400| 0
    1| 1| 1| 230400| 0
    2| 1| 1| 230400| 0
    3| 1| 1| 230400| 0
    4| 1| 1| 230400| 0
    5| 1| 1| 230400| 0
    6| 1| 1| 230400| 0
    7| 1| 1| 230400| 0
    8| 1| 1| 230400| 0
    9| 1| 1| 230400| 0
    10| 1| 1| 230400| 0
    11| 1| 1| 230400| 0
    12| 1| 1| 230400| 0
    13| 1| 1| 230400| 0
    14| 1| 1| 230400| 0
    15| 1| 1| 230400| 0

    ====================
    DEC_LINK_CMD_PRINT_BUFFER_STATISTICS

    ====================

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <demos/link_api_demos/common/chains.h>
    
    Void Chains_FileDecFileWr(Chains_Ctrl *chainsCfg);
    
    #define TRUE              1
    #define FALSE 0
    
    #define SRC_NUM_CH 16
    #define NUM_BUF_PER_CH 1
    
    pthread_mutex_t g_mutex;
    pthread_cond_t g_condition;
    int conditionMet=0;
    
    /**
                           FILE (H264)
                              |
                              |
                        IPC_BITS_OUT_A8 (BitStream)
                              |
                        IPC_BITS_IN_M3 (BitStream)
                              |
                             DEC
                              |
                       IPC_FRAMES_OUT_M3 (Frames)
                              |
                        IPC_FRAMES_IN_A8 (Frames)
                              |
                              |
                            FILE (YUV)
    */
    
    
    #if 0
    static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl =
    {
        .isPopulated = 1,
        .ivaMap[0] =
        {
            .EncNumCh  = 0,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            .DecNumCh  = 16,
            .DecChList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 , 14, 15},
        },
        .ivaMap[1] =
        {
            .EncNumCh  = 0,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            .DecNumCh  = 0,
            .DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0},
        },
        .ivaMap[2] =
        {
            .EncNumCh  = 0,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            .DecNumCh  = 0,
            .DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        },
    };
    
    #endif
    static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl =
    {
        .isPopulated = 1,
        .ivaMap[0] =
        {
            .EncNumCh  = 0,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            .DecNumCh  = SRC_NUM_CH,
            .DecChList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 , 14, 15}
        },
    
    };
    
    
    Int32 Chains_memPrintHeapStatus()
    {
        printf("Stub: chains_memPrintHeap");
    
        return 0;
    }
    
    char gChains_runTimeMenu[] = {
        "\r\n ===================="
        "\r\n Chains Run-time Menu"
        "\r\n ===================="
        "\r\n"
        "\r\n 0: Stop Chain"
        "\r\n"
        "\r\n i: Print IVA-HD Statistics "
        "\r\n "
        "\r\n Enter Choice: "
    };
    
    /* Heap Id registered with MessageQ for allocating message buffers.
       The heap associated with PE_MESSAGEQ_SHARED_REGION_ID is registered
       as PE_MESSAGEQ_HEAP_ID. */
    const unsigned short Rpe_messageqHeapId = 0;
    
    char Chains_menuRunTime()
    {
    	char ch[128];
    	printf(gChains_runTimeMenu);
    	fgets(ch, 128, stdin);
    	if(ch[1] != '\n' || ch[0] == '\n')
    	ch[0] = '\n';
    	return ch[0];
    }
    
    
    
    Void Chains_run(Chains_RunFunc chainsRunFunc)
    {
    	Chains_Ctrl chainsCtrl;
    	
    	//Chains_detectBoard();
    	
    	System_linkControl(
    		SYSTEM_LINK_ID_M3VPSS,
    		SYSTEM_M3VPSS_CMD_RESET_VIDEO_DEVICES,
    		NULL,
    		0,
    		TRUE
    		);
    #if 0
    	UInt32 displayResDefault[SYSTEM_DC_MAX_VENC] =
            {VSYS_STD_1080P_60,   //SYSTEM_DC_VENC_HDMI,
             VSYS_STD_1080P_60,    //SYSTEM_DC_VENC_HDCOMP,
             VSYS_STD_1080P_60,    //SYSTEM_DC_VENC_DVO2
             VSYS_STD_NTSC        //SYSTEM_DC_VENC_SD,
            };
    
    	chainsCtrl.enableNsfLink = FALSE;
    	chainsCtrl.enableOsdAlgLink = FALSE;
    	chainsCtrl.enableVidFrameExport = FALSE;
    	chainsCtrl.bypassNsf = FALSE;
    
    	// memcpy(gChains_ctrl.displayRes,displayResDefault,sizeof(gChains_ctrl.displayRes));
    	//    memcpy(&chainsCtrl, &gChains_ctrl, sizeof(gChains_ctrl));
    	
    	//  Chains_memPrintHeapStatus();
    #endif	
    	UTILS_assert(  chainsRunFunc!=NULL);
    	chainsRunFunc(&chainsCtrl);
    
    
    }
    
    char gChains_menuMain0[] = {
        "\r\n ============"
        "\r\n Chain Select"
        "\r\n ============"
        "\r\n"
    };
    
    char gChains_menuMainVs[] = {
        "\r\n"
        "\r\n 1: <H264 FILERD-> DEC->FILEWR>"
        "\r\n "
        "\r\n s: System Settings "
        "\r\n "
        "\r\n x: Exit "
        "\r\n "
        "\r\n Enter Choice: "
    };
    
    Void Chains_menuMainShow()
    {
    	printf(gChains_menuMain0);
    
    	//Chains_menuCurrentSettingsShow();
    
    	printf(gChains_menuMainVs);
    }
    
    
    Void Chains_menuMainRunVs(char ch)
    {
    
    	
    	switch(ch)
    	{
    	case '1':
    	
    		Chains_run(Chains_FileDecFileWr);
    		break;
    	case '2':
    		printf("invalid option 2");
    //		Chains_run(Chains_multiChEncDecLoopBack);
    		break;
    	case '3':
    		printf("invalid option 3");
    //		Chains_run(Chains_multiChEncDecLoopBack);
    		break;
    	case '4':
    		printf("invalid option 4");
    //		Chains_run(Chains_multiChEncDecLoopBack);
    		break;
    	default:
    		break;
    	}
    }
    
    Void Chains_main()
    {
    	char ch[128];
    	Bool done;
    	
    	done = FALSE;
    	
    	// Chains_setDefaultCfg();
    	
    	while(!done)
    	{
    		Chains_menuMainShow();
    		
    		fgets(ch, 128, stdin);
    		if(ch[1] != '\n' || ch[0] == '\n')
    			continue;
    		
    		printf(" \r\n");
    		
    		Chains_menuMainRunVs(ch[0]);
    		
    		switch(ch[0])
    		{
    			case 's':
    			// Chains_menuSettings();
    			break;
    			case 'x':
    			done = TRUE;
    			break;
    			case 'd':
    			//Chains_detectBoard();
    			break;
    		}
    		
    	}
    }
    
    
    #define INI_FILE "/opt/sample.h264"
    #define INI_FRAME_WIDTH 640
    #define INI_FRAME_HEIGHT 360
    #define INI_ENABLE 1
    #define INI_CODEC h264
    #define INI_NUMBUF 0
    #define INI_DISP_DELAY 0
    
    
    
    
    Void Chains_FileDecFileWr(Chains_Ctrl *chainsCfg)
    {
    	IpcBitsOutLinkHLOS_CreateParams   ipcBitsOutHostPrm;
    	IpcBitsInLinkRTOS_CreateParams    ipcBitsInVideoPrm;
    	
    	
    	DecLink_CreateParams     decPrm;
    	
    	IpcFramesOutLinkRTOS_CreateParams   ipcFramesOutVideoPrm;
    	IpcFramesInLinkHLOS_CreateParams  ipcFramesInHostPrm;
    	
    	
    	Int i;
    	Bool isProgressive;
    	System_LinkInfo bitsProducerLinkInfo;
    	
    	UInt32 decId;
    	UInt32 ipcFramesOutVideoId, ipcFramesInHostId;
    	UInt32 ipcBitsInVideoId, ipcBitsOutHostId;
    	char ch; 
    	int rc;
    	
    	//Chains_ipcBitsInit();
    	CHAINS_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
    	CHAINS_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);
    	
    	CHAINS_INIT_STRUCT(DecLink_CreateParams, decPrm);
    	
    	CHAINS_INIT_STRUCT(IpcFramesOutLinkRTOS_CreateParams,ipcFramesOutVideoPrm);
    	CHAINS_INIT_STRUCT(IpcFramesInLinkHLOS_CreateParams,ipcFramesInHostPrm);
    	
    	ipcBitsOutHostId  = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
    	ipcBitsInVideoId  = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;
    	
    	decId  = SYSTEM_LINK_ID_VDEC_0;
    	
    	ipcFramesOutVideoId = SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_OUT_0;
    	ipcFramesInHostId   = SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0;
    	
    	//decPrm.tilerEnable = FALSE; 
    	isProgressive = TRUE;
    	
    	System_linkControl(
    	SYSTEM_LINK_ID_M3VIDEO,
    	SYSTEM_COMMON_CMD_SET_CH2IVAHD_MAP_TBL,
    	&systemVid_encDecIvaChMapTbl,
    	sizeof(SystemVideo_Ivahd2ChMap_Tbl),
    	TRUE
    	);
    	
    	
    	ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink = ipcBitsInVideoId;
    	ipcBitsOutHostPrm.baseCreateParams.notifyNextLink = FALSE;
    	ipcBitsOutHostPrm.baseCreateParams.notifyPrevLink = FALSE;
    	ipcBitsOutHostPrm.baseCreateParams.noNotifyMode = TRUE;
    	ipcBitsOutHostPrm.baseCreateParams.numOutQue = 1;
    	ipcBitsOutHostPrm.inQueInfo.numCh = SRC_NUM_CH;
    	ipcBitsOutHostPrm.bufPoolPerCh = TRUE;
    	
    	for (i=0; i<SRC_NUM_CH; i++)
    	{
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].width = INI_FRAME_WIDTH;
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].height = INI_FRAME_HEIGHT;
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].scanFormat = SYSTEM_SF_PROGRESSIVE;
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].bufType        = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].codingformat   = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].dataFormat     = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].memType        = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].startX         = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].startY         = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[0]       = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[1]       = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[2]       = 0; // NOT USED
    	ipcBitsOutHostPrm.numBufPerCh[i] = NUM_BUF_PER_CH;
    	}
    
    	/* IPC Host to IPC Video*/
    	ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId    = ipcBitsOutHostId;
    	ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    	ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink  = decId;
    	ipcBitsInVideoPrm.baseCreateParams.noNotifyMode              = TRUE;
    	ipcBitsInVideoPrm.baseCreateParams.notifyNextLink            = TRUE;
    	/* badri's changes*/
    	ipcBitsInVideoPrm.baseCreateParams.notifyPrevLink            = FALSE;
    	ipcBitsInVideoPrm.baseCreateParams.numOutQue                 = 1;
    
    	/* IPC Video to DEC*/
    	for (i=0; i<SRC_NUM_CH; i++) {
    		decPrm.chCreateParams[i].format          = IVIDEO_H264HP;
    		decPrm.chCreateParams[i].profile         = IH264VDEC_PROFILE_ANY;
    		decPrm.chCreateParams[i].targetMaxWidth  = INI_FRAME_WIDTH;
    		decPrm.chCreateParams[i].targetMaxHeight = INI_FRAME_HEIGHT;
    	#if 0
    		if (isProgressive)
    		decPrm.chCreateParams[i].fieldMergeDecodeEnable  = FALSE;
    		else
    		decPrm.chCreateParams[i].fieldMergeDecodeEnable  = TRUE;
    	#endif
    		decPrm.chCreateParams[i].numBufPerCh = NUM_BUF_PER_CH;
    		decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate = 25;
    		decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate = (2 * 1000 * 1000);
    	}
    	decPrm.inQueParams.prevLinkId = ipcBitsInVideoId;
    	decPrm.inQueParams.prevLinkQueId = 0;
    	decPrm.outQueParams.nextLink     = ipcFramesOutVideoId;
    	
    	/*DEC to IPC Video Frame out*/
    	
    	ipcFramesOutVideoPrm.baseCreateParams.noNotifyMode = TRUE;
    	ipcFramesOutVideoPrm.baseCreateParams.notifyNextLink = FALSE;
    	ipcFramesOutVideoPrm.baseCreateParams.notifyPrevLink = FALSE;
    	ipcFramesOutVideoPrm.baseCreateParams.inQueParams.prevLinkId = decId;
    	ipcFramesOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    	ipcFramesOutVideoPrm.baseCreateParams.numOutQue = 1;
    	ipcFramesOutVideoPrm.baseCreateParams.outQueParams[0].nextLink = ipcFramesInHostId;
    	
    	/*IPC  Frame video out to Host IN*/
    	ipcFramesInHostPrm.baseCreateParams.noNotifyMode = TRUE;
    	ipcFramesInHostPrm.baseCreateParams.notifyNextLink = FALSE;
    	/* badri's changes*/
    	ipcFramesInHostPrm.baseCreateParams.notifyPrevLink = TRUE;
    	ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkId = ipcFramesOutVideoId;
    	ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    	ipcFramesInHostPrm.baseCreateParams.outQueParams[0].nextLink = SYSTEM_LINK_ID_INVALID;
    	
    	
    	System_linkCreate(ipcBitsOutHostId,&ipcBitsOutHostPrm,sizeof(ipcBitsOutHostPrm));
    	System_linkCreate(ipcBitsInVideoId,&ipcBitsInVideoPrm,sizeof(ipcBitsInVideoPrm));
    	System_linkCreate(decId, &decPrm, sizeof(decPrm));
    	sleep(2);
    	System_linkCreate(ipcFramesOutVideoId, &ipcFramesOutVideoPrm, sizeof(ipcFramesOutVideoPrm));
    	System_linkCreate(ipcFramesInHostId, &ipcFramesInHostPrm, sizeof(ipcFramesInHostPrm));
    
    	printf("SYSTEM INFO >>> FILE - DEC - FILE Links Created\n");
    	
    
    
        
    	
    	System_linkStart(ipcFramesInHostId);
    	System_linkStart(ipcFramesOutVideoId);
    	System_linkStart(decId);
    	System_linkStart(ipcBitsInVideoId);
    	System_linkStart(ipcBitsOutHostId);
    	
    	rc = pthread_mutex_lock(&g_mutex);
    	conditionMet =1;
    	rc = pthread_cond_broadcast(&g_condition);
    	rc = pthread_mutex_unlock(&g_mutex);
    	
    	
    	/* Start taking CPU load just before starting of links */
    	
    	
    	while(1)
    	{
    		ch = Chains_menuRunTime();
    		if(ch=='0')
    		break;
    		if(ch=='i')
    		System_linkControl(decId, DEC_LINK_CMD_PRINT_IVAHD_STATISTICS, NULL, 0, TRUE);
    		if(ch=='d')
    		System_linkControl(decId, DEC_LINK_CMD_PRINT_STATISTICS, NULL, 0, TRUE);
    		if(ch=='D')
    			System_linkControl(decId, DEC_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);
    		if(ch=='b')
    		System_linkControl(ipcBitsOutHostId, IPCBITSOUT_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);
    	}
    	//Chains_ipcBitsStop();
    	System_linkStop(ipcBitsOutHostId);
    	System_linkStop(ipcBitsInVideoId);
    	System_linkStop(decId);
        
    
    	System_linkDelete(ipcBitsOutHostId);
    	System_linkDelete(ipcBitsInVideoId);
    	System_linkDelete(decId);
    	System_linkDelete(ipcFramesOutVideoId);
    	System_linkDelete(ipcFramesInHostId);
    
    
    	//Chains_ipcBitsExit();
    }
    
    
    #if 0
    
    static Void VdecVdis_setFrameTimeStamp(VCODEC_BITSBUF_S *pEmptyBuf)
    {
        UInt64 curTimeStamp =
          gVdecVdis_config.frameCnt[pEmptyBuf->chnId] * VDEC_VDIS_FRAME_DURATION_MS;
        pEmptyBuf->lowerTimeStamp = (UInt32)(curTimeStamp & 0xFFFFFFFF);
        pEmptyBuf->upperTimeStamp = (UInt32)((curTimeStamp >> 32)& 0xFFFFFFFF);
        if (0 == gVdecVdis_config.frameCnt[pEmptyBuf->chnId])
        {
            UInt32 displayChId;
    
            Vdec_mapDec2DisplayChId(VDIS_DEV_HDMI,pEmptyBuf->chnId,&displayChId);
            Vdis_setFirstVidPTS(VDIS_DEV_HDMI,displayChId,curTimeStamp);
            Vdec_mapDec2DisplayChId(VDIS_DEV_HDCOMP,pEmptyBuf->chnId,&displayChId);
            Vdis_setFirstVidPTS(VDIS_DEV_HDCOMP,displayChId,curTimeStamp);
            Vdec_mapDec2DisplayChId(VDIS_DEV_SD,pEmptyBuf->chnId,&displayChId);
            Vdis_setFirstVidPTS(VDIS_DEV_SD,displayChId,curTimeStamp);
        }
        gVdecVdis_config.frameCnt[pEmptyBuf->chnId] += 1;
    }
    
    #endif
    
    static Void Vdec_copyBitBufInfoLink2McFw(VCODEC_BITSBUF_S *dstBuf,
                                             Bitstream_Buf    *srcBuf)
    {
        dstBuf->reserved              = (UInt32)srcBuf;
        dstBuf->bufVirtAddr           = srcBuf->addr;
        dstBuf->bufSize               = srcBuf->bufSize;
        dstBuf->chnId                 = srcBuf->channelNum;
        dstBuf->codecType             = srcBuf->codingType;
        dstBuf->filledBufSize         = srcBuf->fillLength;
        dstBuf->timestamp             = srcBuf->timeStamp;
        dstBuf->upperTimeStamp        = srcBuf->upperTimeStamp;
        dstBuf->lowerTimeStamp        = srcBuf->lowerTimeStamp;
        dstBuf->bottomFieldBitBufSize = srcBuf->bottomFieldBitBufSize;
        dstBuf->inputFileChanged      = srcBuf->inputFileChanged;
    
        if (srcBuf->isKeyFrame)
            dstBuf->frameType      = VCODEC_FRAME_TYPE_I_FRAME;
        else
            dstBuf->frameType      = VCODEC_FRAME_TYPE_P_FRAME;
    
        dstBuf->bufPhysAddr    = (Void *)srcBuf->phyAddr;
        dstBuf->frameWidth     = srcBuf->frameWidth;
        dstBuf->frameHeight    = srcBuf->frameHeight;
        dstBuf->doNotDisplay   = FALSE;
        /*TODO the following members need to be added to bitstream buf */
        dstBuf->fieldId        = 0;
        dstBuf->strmId         = 0;
        dstBuf->seqId          = srcBuf->seqId;
       print_diag(dstBuf);
    }
    
    
    
    void print_diag(VCODEC_BITSBUF_S *dstBuf)
    {
        printf("dstBuf->reserved = %u\n",dstBuf->reserved);
        printf("dstBuf->bufVirtAddr = %u\n", dstBuf->bufVirtAddr);
        printf("dstBuf->bufSize = %u\n", dstBuf->bufSize);
        printf("dstBuf->chnId = %u\n", dstBuf->chnId);
        printf("dstBuf->codecType = %u\n", dstBuf->codecType);
        printf("dstBuf->filledBufSize = %u\n", dstBuf->filledBufSize);
        printf("dstBuf->timestamp = %u\n", dstBuf->timestamp);
        printf("dstBuf->upperTimeStamp = %u\n", dstBuf->upperTimeStamp);
        printf("dstBuf->lowerTimeStamp = %u\n", dstBuf->lowerTimeStamp);
        printf("dstBuf->bottomFieldBitBufSize = %u\n", dstBuf->bottomFieldBitBufSize);
        printf("dstBuf->inputFileChanged = %u\n", dstBuf->inputFileChanged);
        printf("dstBuf->frameType = %u\n", dstBuf->frameType);
        printf("dstBuf->bufPhysAddr = %u\n", dstBuf->bufPhysAddr);
        printf("dstBuf->frameWidth = %u\n", dstBuf->frameWidth);
        printf("dstBuf->frameHeight = %u\n", dstBuf->frameHeight);
        printf("dstBuf->doNotDisplay = %u\n", dstBuf->doNotDisplay);
        printf("dstBuf->seqId = %u\n", dstBuf->seqId);
        fflush(stdout);
    }
    
    
    
    
    void input_from_file(void *parm)
    {
    	int rc;
    	IpcBitsOutLinkHLOS_BitstreamBufReqInfo reqInfo;
    	Bitstream_BufList emptyBufList;
    	Bitstream_BufList bufList;
    	int iRet;
    	int i;
    	int read_size;
    	int status;
    	FILE *fphdr;
    	int fd;
    	VCODEC_BITSBUF_S *pEmptyBuf;
    	VCODEC_BITSBUF_S *pOutBuf, *pInBuf;
    	VCODEC_BITSBUF_LIST_S BitsBufList;
    	VCODEC_BITSBUF_LIST_S *pBitsBufList;
    	int ret_status;
    	int input_frame_count = 0;
    	
    	/* wait for links to be created*/
    	/*
    	int pthread_cond_wait(pthread_cond_t *restrict cond,
    	pthread_mutex_t *restrict mutex); 
    	
    	*/
    
    	
    	while (!conditionMet) {
    	printf("input Thread blocked\n");
    	rc = pthread_cond_wait(&g_condition, &g_mutex);
    	
    	}
    
    	
    	fd = open("/opt/sample_tmr.h264", O_RDONLY);
    	if(fd <= 0)
    	{
    		printf("file open error");
    		exit(-1);
    	}
    	
    	fphdr = fopen("/opt/sample_tmr.h264.hdr", "r");
    	if(fphdr == NULL)
    	{
    		printf("file open error");
    		exit(-1);
    	}
    
    
    
    	while(1)
    	{
    		reqInfo.numBufs = NUM_BUF_PER_CH;
    		reqInfo.reqType = IPC_BITSOUTHLOS_BITBUFREQTYPE_CHID;
    		
    		for (i = 0; i< NUM_BUF_PER_CH; i++) 
    			reqInfo.u[i].chNum = i;
    		
    		ret_status = IpcBitsOutLink_getEmptyVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &emptyBufList, &reqInfo);
    
            	OSA_assert(0 == ret_status);
    		
    		pBitsBufList = &BitsBufList;
    		pBitsBufList->numBufs = emptyBufList.numBufs;
    
    		for (i = 0; i < emptyBufList.numBufs; i++)
    		{
    			pOutBuf = &pBitsBufList->bitsBuf[i];
    			pInBuf = emptyBufList.bufs[i];
    			Vdec_copyBitBufInfoLink2McFw(pOutBuf, pInBuf);
    		}
    
    		pEmptyBuf= &BitsBufList.bitsBuf[0];
    
    		/*iChains_ipcBitsReadBitsFromFile(&emptyBufList, maxDataSize);*/
    		int statHdr, statData;
    		int curCh;
    		statHdr  = fscanf(fphdr,"%d",&(pEmptyBuf->filledBufSize));
    
    		OSA_assert(pEmptyBuf->filledBufSize <= pEmptyBuf->bufSize);
    		statData = read(fd, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
    		print_diag(pEmptyBuf);
    		if( feof(fphdr) || statData != pEmptyBuf->filledBufSize)
    		{
    		
    			printf(" CH Reached the end of file, inputframecount = %d !!!",input_frame_count);
    
    			#if 0
    
    			/*rewind*/
    			clearerr(fphdr);
    			
    			rewind(fphdr);
    			lseek(fp, 0, SEEK_SET);
    			statHdr = fscanf(fphdr,"%d",&(pEmptyBuf->filledBufSize));
    			
    			OSA_assert(pEmptyBuf->filledBufSize <= pEmptyBuf->bufSize);
    			statData = read(fp, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
    			#endif
    			break;
    		}
    
    		ret_status = IpcBitsOutLink_putFullVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &BitsBufList);
    		input_frame_count++;
    
    		//sleep(1);
    	 }
    
    	close(fd);
    	fclose(fphdr);
    
    
    }
    
    static Void Chains_ipcFramesPrintFrameInfo(VIDFrame_Buf *buf)
    {
        OSA_printf("CHAINS_IPCFRAMES:VIDFRAME_INFO:"
                   "chNum:%d\t"
                   "fid:%d\t"
                   "frameWidth:%d\t"
                   "frameHeight:%d\t"
                   "timeStamp:%d\t"
                   "virtAddr[0][0]:%p\t"
                   "phyAddr[0][0]:%p",
                    buf->channelNum,
                    buf->fid,
                    buf->frameWidth,
                    buf->frameHeight,
                    buf->timeStamp,
                    buf->addr[0][0],
                    buf->phyAddr[0][0]);
    
    }
    
    
    void receive_output_and_filw(void *parm)
    {	
    
    	int fd;
    	VCODEC_BITSBUF_S *pEmptyBuf;
    	VIDFrame_BufList bufList;
    	int status;
    	int i;
    	int rc;
    
    	OSA_printf("CHAINS_IPCFRAMES:%s:Entered...",__func__);
    //	OSA_semWait(&thrObj->framesInNotifySem,OSA_TIMEOUT_FOREVER);
    	OSA_printf("CHAINS_IPCFRAMES:Received first frame notify...");
    
    #if 0
    	fd = open("/opt/out.yuv", O_WRONLY);
    	if(fd <= 0)
    	{
    		printf("file open error");
    		exit(-1);
    	}
    #endif
    
    	while (!conditionMet) {
    	printf("Output Thread blocked\n");
    	rc = pthread_cond_wait(&g_condition, &g_mutex);
    	
    	}
    	sleep(1);
    
    	while(1)
    	{
    
    			
    		status =  IpcFramesInLink_getFullVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0,
                                                        &bufList);
    		OSA_assert(0 == status);
    		if (bufList.numFrames > 0)
    		{
    			printf("FULLF:");
    			for(i = 0; i < bufList.numFrames;i++)
    				/*writetofile(bufList.frames[i])*/
    				 Chains_ipcFramesPrintFrameInfo(&bufList.frames[i]);
    
    
    //			pEmptyBuf= &BitsBufList.bitsBuf[0];
    //			statData = write(fd, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
    			status = IpcFramesInLink_putEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0, &bufList);
    
    		}
    
    #if 0
    		status =  IpcFramesOutLink_getEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_OUT_0,
                                                           &bufList);
    		OSA_assert(0 == status);
    		if (bufList.numFrames)
    	        {
    			printf("emptyF:");
    			for(i = 0; i < bufList.numFrames;i++)
    				/*writetofile(bufList.frames[i])*/
    			   Chains_ipcFramesPrintFrameInfo(&bufList.frames[i]);
    
    
            	    status = IpcFramesInLink_putEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0,
                                                             &bufList);
            	    OSA_assert(0 == status);
            	}
    #endif
    
    	}
    	close(fd);
    
    
    }
    
    int main()
    {
    	pthread_t thrd,thrd2;
    	char *message1 = "Thread 1";
    	char *message2 = "Thread 2";
    	pthread_mutexattr_t mutexattr;  // Mutex Attribute
    	pthread_condattr_t    attr;
    	int rc;
    	int iret1;
    
    
    	System_init();
    
    	rc = pthread_condattr_init(&attr);
    	pthread_mutexattr_init(&mutexattr);
    	pthread_mutex_init(&(g_mutex), &mutexattr);
    	pthread_cond_init(&(g_condition), &attr);
    	conditionMet = 0;
    	iret1 = pthread_create( &thrd, NULL, input_from_file, (void*) message1);
    	iret1 = pthread_create( &thrd2, NULL, receive_output_and_filw, (void*) message2);
    	Chains_main();
    
    	
    	System_deInit();
    
    	pthread_cond_destroy(&g_condition);
    	return 0;
    }
    
    


    Enter Choice: [m3video]
    [m3video] *** Decode Statistics ***
    [m3video] 362474: DEC: Rcvd from prev = 0, Returned to prev = 0
    [m3video] DEC Out BufExt Q Status
    [m3video] Empty Q 0 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 1 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 2 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 3 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 4 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 5 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 6 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 7 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 8 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 9 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 10 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 11 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 12 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 13 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 14 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Empty Q 15 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Full Q -> count 0, wrPtr 0, rdPtr 0

    The C test file:

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <demos/link_api_demos/common/chains.h>

    Void Chains_FileDecFileWr(Chains_Ctrl *chainsCfg);

    #define TRUE 1
    #define FALSE 0

    #define SRC_NUM_CH 16
    #define NUM_BUF_PER_CH 1

    pthread_mutex_t g_mutex;
    pthread_cond_t g_condition;
    int conditionMet=0;

    /**
    FILE (H264)
    |
    |
    IPC_BITS_OUT_A8 (BitStream)
    |
    IPC_BITS_IN_M3 (BitStream)
    |
    DEC
    |
    IPC_FRAMES_OUT_M3 (Frames)
    |
    IPC_FRAMES_IN_A8 (Frames)
    |
    |
    FILE (YUV)
    */


    #if 0
    static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl =
    {
    .isPopulated = 1,
    .ivaMap[0] =
    {
    .EncNumCh = 0,
    .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    .DecNumCh = 16,
    .DecChList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 , 14, 15},
    },
    .ivaMap[1] =
    {
    .EncNumCh = 0,
    .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    .DecNumCh = 0,
    .DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0},
    },
    .ivaMap[2] =
    {
    .EncNumCh = 0,
    .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    .DecNumCh = 0,
    .DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    },
    };

    #endif
    static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl =
    {
    .isPopulated = 1,
    .ivaMap[0] =
    {
    .EncNumCh = 0,
    .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    .DecNumCh = SRC_NUM_CH,
    .DecChList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 , 14, 15}
    },

    };


    Int32 Chains_memPrintHeapStatus()
    {
    printf("Stub: chains_memPrintHeap");

    return 0;
    }

    char gChains_runTimeMenu[] = {
    "\r\n ===================="
    "\r\n Chains Run-time Menu"
    "\r\n ===================="
    "\r\n"
    "\r\n 0: Stop Chain"
    "\r\n"
    "\r\n i: Print IVA-HD Statistics "
    "\r\n "
    "\r\n Enter Choice: "
    };

    /* Heap Id registered with MessageQ for allocating message buffers.
    The heap associated with PE_MESSAGEQ_SHARED_REGION_ID is registered
    as PE_MESSAGEQ_HEAP_ID. */
    const unsigned short Rpe_messageqHeapId = 0;

    char Chains_menuRunTime()
    {
    char ch[128];
    printf(gChains_runTimeMenu);
    fgets(ch, 128, stdin);
    if(ch[1] != '\n' || ch[0] == '\n')
    ch[0] = '\n';
    return ch[0];
    }

    Void Chains_run(Chains_RunFunc chainsRunFunc)
    {
    Chains_Ctrl chainsCtrl;

    //Chains_detectBoard();

    System_linkControl(
    SYSTEM_LINK_ID_M3VPSS,
    SYSTEM_M3VPSS_CMD_RESET_VIDEO_DEVICES,
    NULL,
    0,
    TRUE
    );
    #if 0
    UInt32 displayResDefault[SYSTEM_DC_MAX_VENC] =
    {VSYS_STD_1080P_60, //SYSTEM_DC_VENC_HDMI,
    VSYS_STD_1080P_60, //SYSTEM_DC_VENC_HDCOMP,
    VSYS_STD_1080P_60, //SYSTEM_DC_VENC_DVO2
    VSYS_STD_NTSC //SYSTEM_DC_VENC_SD,
    };

    chainsCtrl.enableNsfLink = FALSE;
    chainsCtrl.enableOsdAlgLink = FALSE;
    chainsCtrl.enableVidFrameExport = FALSE;
    chainsCtrl.bypassNsf = FALSE;

    // memcpy(gChains_ctrl.displayRes,displayResDefault,sizeof(gChains_ctrl.displayRes));
    // memcpy(&chainsCtrl, &gChains_ctrl, sizeof(gChains_ctrl));

    // Chains_memPrintHeapStatus();
    #endif
    UTILS_assert( chainsRunFunc!=NULL);
    chainsRunFunc(&chainsCtrl);


    }

    char gChains_menuMain0[] = {
    "\r\n ============"
    "\r\n Chain Select"
    "\r\n ============"
    "\r\n"
    };

    char gChains_menuMainVs[] = {
    "\r\n"
    "\r\n 1: <H264 FILERD-> DEC->FILEWR>"
    "\r\n "
    "\r\n s: System Settings "
    "\r\n "
    "\r\n x: Exit "
    "\r\n "
    "\r\n Enter Choice: "
    };

    Void Chains_menuMainShow()
    {
    printf(gChains_menuMain0);

    //Chains_menuCurrentSettingsShow();

    printf(gChains_menuMainVs);
    }


    Void Chains_menuMainRunVs(char ch)
    {


    switch(ch)
    {
    case '1':

    Chains_run(Chains_FileDecFileWr);
    break;
    case '2':
    printf("invalid option 2");
    // Chains_run(Chains_multiChEncDecLoopBack);
    break;
    case '3':
    printf("invalid option 3");
    // Chains_run(Chains_multiChEncDecLoopBack);
    break;
    case '4':
    printf("invalid option 4");
    // Chains_run(Chains_multiChEncDecLoopBack);
    break;
    default:
    break;
    }
    }

    Void Chains_main()
    {
    char ch[128];
    Bool done;

    done = FALSE;

    // Chains_setDefaultCfg();

    while(!done)
    {
    Chains_menuMainShow();

    fgets(ch, 128, stdin);
    if(ch[1] != '\n' || ch[0] == '\n')
    continue;

    printf(" \r\n");

    Chains_menuMainRunVs(ch[0]);

    switch(ch[0])
    {
    case 's':
    // Chains_menuSettings();
    break;
    case 'x':
    done = TRUE;
    break;
    case 'd':
    //Chains_detectBoard();
    break;
    }

    }
    }


    #define INI_FILE "/opt/sample.h264"
    #define INI_FRAME_WIDTH 640
    #define INI_FRAME_HEIGHT 360
    #define INI_ENABLE 1
    #define INI_CODEC h264
    #define INI_NUMBUF 0
    #define INI_DISP_DELAY 0


    Void Chains_FileDecFileWr(Chains_Ctrl *chainsCfg)
    {
    IpcBitsOutLinkHLOS_CreateParams ipcBitsOutHostPrm;
    IpcBitsInLinkRTOS_CreateParams ipcBitsInVideoPrm;


    DecLink_CreateParams decPrm;

    IpcFramesOutLinkRTOS_CreateParams ipcFramesOutVideoPrm;
    IpcFramesInLinkHLOS_CreateParams ipcFramesInHostPrm;


    Int i;
    Bool isProgressive;
    System_LinkInfo bitsProducerLinkInfo;

    UInt32 decId;
    UInt32 ipcFramesOutVideoId, ipcFramesInHostId;
    UInt32 ipcBitsInVideoId, ipcBitsOutHostId;
    char ch;
    int rc;

    //Chains_ipcBitsInit();
    CHAINS_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
    CHAINS_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);

    CHAINS_INIT_STRUCT(DecLink_CreateParams, decPrm);

    CHAINS_INIT_STRUCT(IpcFramesOutLinkRTOS_CreateParams,ipcFramesOutVideoPrm);
    CHAINS_INIT_STRUCT(IpcFramesInLinkHLOS_CreateParams,ipcFramesInHostPrm);

    ipcBitsOutHostId = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
    ipcBitsInVideoId = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;

    decId = SYSTEM_LINK_ID_VDEC_0;

    ipcFramesOutVideoId = SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_OUT_0;
    ipcFramesInHostId = SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0;

    //decPrm.tilerEnable = FALSE;
    isProgressive = TRUE;

    System_linkControl(
    SYSTEM_LINK_ID_M3VIDEO,
    SYSTEM_COMMON_CMD_SET_CH2IVAHD_MAP_TBL,
    &systemVid_encDecIvaChMapTbl,
    sizeof(SystemVideo_Ivahd2ChMap_Tbl),
    TRUE
    );


    ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink = ipcBitsInVideoId;
    ipcBitsOutHostPrm.baseCreateParams.notifyNextLink = FALSE;
    ipcBitsOutHostPrm.baseCreateParams.notifyPrevLink = FALSE;
    ipcBitsOutHostPrm.baseCreateParams.noNotifyMode = TRUE;
    ipcBitsOutHostPrm.baseCreateParams.numOutQue = 1;
    ipcBitsOutHostPrm.inQueInfo.numCh = SRC_NUM_CH;
    ipcBitsOutHostPrm.bufPoolPerCh = TRUE;

    for (i=0; i<SRC_NUM_CH; i++)
    {
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].width = INI_FRAME_WIDTH;
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].height = INI_FRAME_HEIGHT;
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].scanFormat = SYSTEM_SF_PROGRESSIVE;
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].bufType = 0; // NOT USED
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].codingformat = 0; // NOT USED
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].dataFormat = 0; // NOT USED
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].memType = 0; // NOT USED
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].startX = 0; // NOT USED
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].startY = 0; // NOT USED
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[0] = 0; // NOT USED
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[1] = 0; // NOT USED
    ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[2] = 0; // NOT USED
    ipcBitsOutHostPrm.numBufPerCh[i] = NUM_BUF_PER_CH;
    }

    /* IPC Host to IPC Video*/
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId = ipcBitsOutHostId;
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink = decId;
    ipcBitsInVideoPrm.baseCreateParams.noNotifyMode = TRUE;
    ipcBitsInVideoPrm.baseCreateParams.notifyNextLink = TRUE;
    /* badri's changes*/
    ipcBitsInVideoPrm.baseCreateParams.notifyPrevLink = FALSE;
    ipcBitsInVideoPrm.baseCreateParams.numOutQue = 1;

    /* IPC Video to DEC*/
    for (i=0; i<SRC_NUM_CH; i++) {
    decPrm.chCreateParams[i].format = IVIDEO_H264HP;
    decPrm.chCreateParams[i].profile = IH264VDEC_PROFILE_ANY;
    decPrm.chCreateParams[i].targetMaxWidth = INI_FRAME_WIDTH;
    decPrm.chCreateParams[i].targetMaxHeight = INI_FRAME_HEIGHT;
    #if 0
    if (isProgressive)
    decPrm.chCreateParams[i].fieldMergeDecodeEnable = FALSE;
    else
    decPrm.chCreateParams[i].fieldMergeDecodeEnable = TRUE;
    #endif
    decPrm.chCreateParams[i].numBufPerCh = NUM_BUF_PER_CH;
    decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate = 25;
    decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate = (2 * 1000 * 1000);
    }
    decPrm.inQueParams.prevLinkId = ipcBitsInVideoId;
    decPrm.inQueParams.prevLinkQueId = 0;
    decPrm.outQueParams.nextLink = ipcFramesOutVideoId;

    /*DEC to IPC Video Frame out*/

    ipcFramesOutVideoPrm.baseCreateParams.noNotifyMode = TRUE;
    ipcFramesOutVideoPrm.baseCreateParams.notifyNextLink = FALSE;
    ipcFramesOutVideoPrm.baseCreateParams.notifyPrevLink = FALSE;
    ipcFramesOutVideoPrm.baseCreateParams.inQueParams.prevLinkId = decId;
    ipcFramesOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcFramesOutVideoPrm.baseCreateParams.numOutQue = 1;
    ipcFramesOutVideoPrm.baseCreateParams.outQueParams[0].nextLink = ipcFramesInHostId;

    /*IPC Frame video out to Host IN*/
    ipcFramesInHostPrm.baseCreateParams.noNotifyMode = TRUE;
    ipcFramesInHostPrm.baseCreateParams.notifyNextLink = FALSE;
    /* badri's changes*/
    ipcFramesInHostPrm.baseCreateParams.notifyPrevLink = TRUE;
    ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkId = ipcFramesOutVideoId;
    ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcFramesInHostPrm.baseCreateParams.outQueParams[0].nextLink = SYSTEM_LINK_ID_INVALID;


    System_linkCreate(ipcBitsOutHostId,&ipcBitsOutHostPrm,sizeof(ipcBitsOutHostPrm));
    System_linkCreate(ipcBitsInVideoId,&ipcBitsInVideoPrm,sizeof(ipcBitsInVideoPrm));
    System_linkCreate(decId, &decPrm, sizeof(decPrm));
    sleep(2);
    System_linkCreate(ipcFramesOutVideoId, &ipcFramesOutVideoPrm, sizeof(ipcFramesOutVideoPrm));
    System_linkCreate(ipcFramesInHostId, &ipcFramesInHostPrm, sizeof(ipcFramesInHostPrm));

    printf("SYSTEM INFO >>> FILE - DEC - FILE Links Created\n");




    System_linkStart(ipcFramesInHostId);
    System_linkStart(ipcFramesOutVideoId);
    System_linkStart(decId);
    System_linkStart(ipcBitsInVideoId);
    System_linkStart(ipcBitsOutHostId);

    rc = pthread_mutex_lock(&g_mutex);
    conditionMet =1;
    rc = pthread_cond_broadcast(&g_condition);
    rc = pthread_mutex_unlock(&g_mutex);


    /* Start taking CPU load just before starting of links */


    while(1)
    {
    ch = Chains_menuRunTime();
    if(ch=='0')
    break;
    if(ch=='i')
    System_linkControl(decId, DEC_LINK_CMD_PRINT_IVAHD_STATISTICS, NULL, 0, TRUE);
    if(ch=='d')
    System_linkControl(decId, DEC_LINK_CMD_PRINT_STATISTICS, NULL, 0, TRUE);
    if(ch=='D')
    System_linkControl(decId, DEC_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);
    if(ch=='b')
    System_linkControl(ipcBitsOutHostId, IPCBITSOUT_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);
    }
    //Chains_ipcBitsStop();
    System_linkStop(ipcBitsOutHostId);
    System_linkStop(ipcBitsInVideoId);
    System_linkStop(decId);

    System_linkDelete(ipcBitsOutHostId);
    System_linkDelete(ipcBitsInVideoId);
    System_linkDelete(decId);
    System_linkDelete(ipcFramesOutVideoId);
    System_linkDelete(ipcFramesInHostId);


    //Chains_ipcBitsExit();
    }


    #if 0

    static Void VdecVdis_setFrameTimeStamp(VCODEC_BITSBUF_S *pEmptyBuf)
    {
    UInt64 curTimeStamp =
    gVdecVdis_config.frameCnt[pEmptyBuf->chnId] * VDEC_VDIS_FRAME_DURATION_MS;
    pEmptyBuf->lowerTimeStamp = (UInt32)(curTimeStamp & 0xFFFFFFFF);
    pEmptyBuf->upperTimeStamp = (UInt32)((curTimeStamp >> 32)& 0xFFFFFFFF);
    if (0 == gVdecVdis_config.frameCnt[pEmptyBuf->chnId])
    {
    UInt32 displayChId;

    Vdec_mapDec2DisplayChId(VDIS_DEV_HDMI,pEmptyBuf->chnId,&displayChId);
    Vdis_setFirstVidPTS(VDIS_DEV_HDMI,displayChId,curTimeStamp);
    Vdec_mapDec2DisplayChId(VDIS_DEV_HDCOMP,pEmptyBuf->chnId,&displayChId);
    Vdis_setFirstVidPTS(VDIS_DEV_HDCOMP,displayChId,curTimeStamp);
    Vdec_mapDec2DisplayChId(VDIS_DEV_SD,pEmptyBuf->chnId,&displayChId);
    Vdis_setFirstVidPTS(VDIS_DEV_SD,displayChId,curTimeStamp);
    }
    gVdecVdis_config.frameCnt[pEmptyBuf->chnId] += 1;
    }

    #endif

    static Void Vdec_copyBitBufInfoLink2McFw(VCODEC_BITSBUF_S *dstBuf,
    Bitstream_Buf *srcBuf)
    {
    dstBuf->reserved = (UInt32)srcBuf;
    dstBuf->bufVirtAddr = srcBuf->addr;
    dstBuf->bufSize = srcBuf->bufSize;
    dstBuf->chnId = srcBuf->channelNum;
    dstBuf->codecType = srcBuf->codingType;
    dstBuf->filledBufSize = srcBuf->fillLength;
    dstBuf->timestamp = srcBuf->timeStamp;
    dstBuf->upperTimeStamp = srcBuf->upperTimeStamp;
    dstBuf->lowerTimeStamp = srcBuf->lowerTimeStamp;
    dstBuf->bottomFieldBitBufSize = srcBuf->bottomFieldBitBufSize;
    dstBuf->inputFileChanged = srcBuf->inputFileChanged;

    if (srcBuf->isKeyFrame)
    dstBuf->frameType = VCODEC_FRAME_TYPE_I_FRAME;
    else
    dstBuf->frameType = VCODEC_FRAME_TYPE_P_FRAME;

    dstBuf->bufPhysAddr = (Void *)srcBuf->phyAddr;
    dstBuf->frameWidth = srcBuf->frameWidth;
    dstBuf->frameHeight = srcBuf->frameHeight;
    dstBuf->doNotDisplay = FALSE;
    /*TODO the following members need to be added to bitstream buf */
    dstBuf->fieldId = 0;
    dstBuf->strmId = 0;
    dstBuf->seqId = srcBuf->seqId;
    print_diag(dstBuf);
    }

    void print_diag(VCODEC_BITSBUF_S *dstBuf)
    {
    printf("dstBuf->reserved = %u\n",dstBuf->reserved);
    printf("dstBuf->bufVirtAddr = %u\n", dstBuf->bufVirtAddr);
    printf("dstBuf->bufSize = %u\n", dstBuf->bufSize);
    printf("dstBuf->chnId = %u\n", dstBuf->chnId);
    printf("dstBuf->codecType = %u\n", dstBuf->codecType);
    printf("dstBuf->filledBufSize = %u\n", dstBuf->filledBufSize);
    printf("dstBuf->timestamp = %u\n", dstBuf->timestamp);
    printf("dstBuf->upperTimeStamp = %u\n", dstBuf->upperTimeStamp);
    printf("dstBuf->lowerTimeStamp = %u\n", dstBuf->lowerTimeStamp);
    printf("dstBuf->bottomFieldBitBufSize = %u\n", dstBuf->bottomFieldBitBufSize);
    printf("dstBuf->inputFileChanged = %u\n", dstBuf->inputFileChanged);
    printf("dstBuf->frameType = %u\n", dstBuf->frameType);
    printf("dstBuf->bufPhysAddr = %u\n", dstBuf->bufPhysAddr);
    printf("dstBuf->frameWidth = %u\n", dstBuf->frameWidth);
    printf("dstBuf->frameHeight = %u\n", dstBuf->frameHeight);
    printf("dstBuf->doNotDisplay = %u\n", dstBuf->doNotDisplay);
    printf("dstBuf->seqId = %u\n", dstBuf->seqId);
    fflush(stdout);
    }


    void input_from_file(void *parm)
    {
    int rc;
    IpcBitsOutLinkHLOS_BitstreamBufReqInfo reqInfo;
    Bitstream_BufList emptyBufList;
    Bitstream_BufList bufList;
    int iRet;
    int i;
    int read_size;
    int status;
    FILE *fphdr;
    int fd;
    VCODEC_BITSBUF_S *pEmptyBuf;
    VCODEC_BITSBUF_S *pOutBuf, *pInBuf;
    VCODEC_BITSBUF_LIST_S BitsBufList;
    VCODEC_BITSBUF_LIST_S *pBitsBufList;
    int ret_status;
    int input_frame_count = 0;

    /* wait for links to be created*/
    /*
    int pthread_cond_wait(pthread_cond_t *restrict cond,
    pthread_mutex_t *restrict mutex);

    */


    while (!conditionMet) {
    printf("input Thread blocked\n");
    rc = pthread_cond_wait(&g_condition, &g_mutex);

    }


    fd = open("/opt/sample_tmr.h264", O_RDONLY);
    if(fd <= 0)
    {
    printf("file open error");
    exit(-1);
    }

    fphdr = fopen("/opt/sample_tmr.h264.hdr", "r");
    if(fphdr == NULL)
    {
    printf("file open error");
    exit(-1);
    }

    while(1)
    {
    reqInfo.numBufs = NUM_BUF_PER_CH;
    reqInfo.reqType = IPC_BITSOUTHLOS_BITBUFREQTYPE_CHID;

    for (i = 0; i< NUM_BUF_PER_CH; i++)
    reqInfo.u[i].chNum = i;

    ret_status = IpcBitsOutLink_getEmptyVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &emptyBufList, &reqInfo);

    OSA_assert(0 == ret_status);

    pBitsBufList = &BitsBufList;
    pBitsBufList->numBufs = emptyBufList.numBufs;

    for (i = 0; i < emptyBufList.numBufs; i++)
    {
    pOutBuf = &pBitsBufList->bitsBuf[i];
    pInBuf = emptyBufList.bufs[i];
    Vdec_copyBitBufInfoLink2McFw(pOutBuf, pInBuf);
    }

    pEmptyBuf= &BitsBufList.bitsBuf[0];

    /*iChains_ipcBitsReadBitsFromFile(&emptyBufList, maxDataSize);*/
    int statHdr, statData;
    int curCh;
    statHdr = fscanf(fphdr,"%d",&(pEmptyBuf->filledBufSize));

    OSA_assert(pEmptyBuf->filledBufSize <= pEmptyBuf->bufSize);
    statData = read(fd, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
    print_diag(pEmptyBuf);
    if( feof(fphdr) || statData != pEmptyBuf->filledBufSize)
    {

    printf(" CH Reached the end of file, inputframecount = %d !!!",input_frame_count);

    #if 0

    /*rewind*/
    clearerr(fphdr);

    rewind(fphdr);
    lseek(fp, 0, SEEK_SET);
    statHdr = fscanf(fphdr,"%d",&(pEmptyBuf->filledBufSize));

    OSA_assert(pEmptyBuf->filledBufSize <= pEmptyBuf->bufSize);
    statData = read(fp, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
    #endif
    break;
    }

    ret_status = IpcBitsOutLink_putFullVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &BitsBufList);
    input_frame_count++;

    //sleep(1);
    }

    close(fd);
    fclose(fphdr);


    }

    static Void Chains_ipcFramesPrintFrameInfo(VIDFrame_Buf *buf)
    {
    OSA_printf("CHAINS_IPCFRAMES:VIDFRAME_INFO:"
    "chNum:%d\t"
    "fid:%d\t"
    "frameWidth:%d\t"
    "frameHeight:%d\t"
    "timeStamp:%d\t"
    "virtAddr[0][0]:%p\t"
    "phyAddr[0][0]:%p",
    buf->channelNum,
    buf->fid,
    buf->frameWidth,
    buf->frameHeight,
    buf->timeStamp,
    buf->addr[0][0],
    buf->phyAddr[0][0]);

    }


    void receive_output_and_filw(void *parm)
    {

    int fd;
    VCODEC_BITSBUF_S *pEmptyBuf;
    VIDFrame_BufList bufList;
    int status;
    int i;
    int rc;

    OSA_printf("CHAINS_IPCFRAMES:%s:Entered...",__func__);
    // OSA_semWait(&thrObj->framesInNotifySem,OSA_TIMEOUT_FOREVER);
    OSA_printf("CHAINS_IPCFRAMES:Received first frame notify...");

    #if 0
    fd = open("/opt/out.yuv", O_WRONLY);
    if(fd <= 0)
    {
    printf("file open error");
    exit(-1);
    }
    #endif

    while (!conditionMet) {
    printf("Output Thread blocked\n");
    rc = pthread_cond_wait(&g_condition, &g_mutex);

    }
    sleep(1);

    while(1)
    {


    status = IpcFramesInLink_getFullVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0,
    &bufList);
    OSA_assert(0 == status);
    if (bufList.numFrames > 0)
    {
    printf("FULLF:");
    for(i = 0; i < bufList.numFrames;i++)
    /*writetofile(bufList.frames[i])*/
    Chains_ipcFramesPrintFrameInfo(&bufList.frames[i]);


    // pEmptyBuf= &BitsBufList.bitsBuf[0];
    // statData = write(fd, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
    status = IpcFramesInLink_putEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0, &bufList);

    }

    #if 0
    status = IpcFramesOutLink_getEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_OUT_0,
    &bufList);
    OSA_assert(0 == status);
    if (bufList.numFrames)
    {
    printf("emptyF:");
    for(i = 0; i < bufList.numFrames;i++)
    /*writetofile(bufList.frames[i])*/
    Chains_ipcFramesPrintFrameInfo(&bufList.frames[i]);


    status = IpcFramesInLink_putEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0,
    &bufList);
    OSA_assert(0 == status);
    }
    #endif

    }
    close(fd);


    }

    int main()
    {
    pthread_t thrd,thrd2;
    char *message1 = "Thread 1";
    char *message2 = "Thread 2";
    pthread_mutexattr_t mutexattr; // Mutex Attribute
    pthread_condattr_t attr;
    int rc;
    int iret1;


    System_init();

    rc = pthread_condattr_init(&attr);
    pthread_mutexattr_init(&mutexattr);
    pthread_mutex_init(&(g_mutex), &mutexattr);
    pthread_cond_init(&(g_condition), &attr);
    conditionMet = 0;
    iret1 = pthread_create( &thrd, NULL, input_from_file, (void*) message1);
    iret1 = pthread_create( &thrd2, NULL, receive_output_and_filw, (void*) message2);
    Chains_main();


    System_deInit();

    pthread_cond_destroy(&g_condition);
    return 0;
    }

  • In my input_from_file thread , I am calling IpcBitsOutLink_getEmptyVideoBitStreamBufs to get bufs

    while(1){

    ret_status = IpcBitsOutLink_getEmptyVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &emptyBufList, &reqInfo);

    ...

    ...

    }

    the emptyBufList.numBufs is 1, only for the first call and subsequent call is zero, so i am not passing the input buffers correctly.

    What is the right way to use IpcBitsOutLink_getEmptyVideoBitStreamBufs?

  • You are getting only one buffer because you have set NUM_BUF_PER_CH  to 1.

    Your code is wrong. Pls look at the prorotype of IpcBitsOutLink_getEmptyVideoBitStreamBufs & IpcBitsOutLink_putFullVideoBitStreamBufs.It expects Bitstream_BufList *. You are passing something else. You should have got compiler warnings. Delete all code related to VCODEC_BITSBUF_LIST_S and VCODEC_BITSBUF_S.When using links they should not be used.


  • Hi,
    I incorporated BitsBufList based changes. But i was not able to make it work.

    when i run i get the info that the links are created:

    "
    [host] 1739: IPC_BITS_OUT : Create in progress !!!
    ###Bit buff of size from the SR # 1 : 230400

    [host] IPC_BITSOUT:BitBuffer Alloc.PoolID:0,Size:0x38400
    [host] IPCBITSOUTLINK:Translated Addr Virt:0x412d3080 To Phy:0x90000080
    [host] 1740: IPC_BITS_OUT : Create Done !!!
    [m3video] 20620: IPC_BITS_IN : Create in progress !!!
    [m3video] 20620: SYSTEM: Opening ListMP [HOST_IPC_OUT_24] ...
    [m3video] 20621: SYSTEM: Opening ListMP [HOST_IPC_IN_24] ...
    [m3video] 20622: SYSTEM: Opening MsgQ [HOST_MSGQ] ...
    [m3video] 20623: IPC_BITS_IN : Create Done !!!
    [m3video] 20623: DECODE: Create in progress ... !!!
    [m3video] DECLINK_H264:HEAPID:0 USED:4264
    [m3video] DECLINK_H264:HEAPID:3 USED:3678208
    [m3video] 20647: DECODE: Creating CH0 of 640 x 360 [PROGRESSIVE] [NON-TILED ],target bitrate = 2000 Kbps ...
    [m3video] 20648: DECODE: All CH Create ... DONE !!!
    [m3video] DECLINK:HEAPID:0 USED:4384
    [m3video] DECLINK:HEAPID:3 USED:4581376
    [m3video] 20651: DECODE: Create ... DONE !!!

    [host] IpcFramesInLink_tskMain:Entered
    [host] 3773: IPC_FRAMES_IN : Create in progress !!!

    [host] 3773: SYSTEM: Opening ListMP [VIDEO-M3_IPC_OUT_19] ...
    3775: SYSTEM: Opening ListMP [VIDEO-M3_IPC_IN_19] ...
    [m3video] 22652: IPC_FRAMES_OUT : Create in progress !!!

    [host] 3778: IPC_FRAMES_IN : Create Done !!!
    SYSTEM INFO >>> FILE - DEC - FILE Links Created
    [m3video] 22653: IPC_FRAMES_OUT : Create Done !!!
    "

    Then i pass the input buffer from another "input_from_file" pthread. For testing, I just give only 8 frame-input.

    1. I first get the empty buffer
    calling "IpcBitsOutLink_getEmptyVideoBitStreamBufs"
    2. then fill it with data from input .h264 file with fillsize obtained from .h264hdr file and
    3. then directly give it to "IpcBitsOutLink_putFullVideoBitStreamBufs". I am not changing the timestamp or sequenceId
    info of the buffers. is that a problem?

    I am printing the buffer statistics before i pass it to "IpcBitsOutLink_putFullVideoBitStreamBufs" and the for the 8 buffers that i get
    the statistics is as follows:

    dstBuf->reserved = 1080806656
    dstBuf->addr = 1093480576
    dstBuf->bufSize = 230400
    dstBuf->fillLength = 0
    dstBuf->startOffset = 0
    dstBuf->mvDataOffset = 4294967295
    dstBuf->mvDataFilledSize = 0
    dstBuf->channelNum = 0
    dstBuf->codingType = 4294967295
    dstBuf->appData = 4294967295
    dstBuf->timeStamp = 4294967295
    dstBuf->temporalId = 0
    dstBuf->numTemporalLayerSetInCodec = 0
    dstBuf->upperTimeStamp = 4294967295
    dstBuf->lowerTimeStamp = 4294967295
    dstBuf->encodeTimeStamp = 4294967295
    dstBuf->bottomFieldBitBufSize = 0
    dstBuf->frameWidth = 4294967295
    dstBuf->frameHeight = 4294967295
    dstBuf->isKeyFrame = 4294967295
    dstBuf->allocPoolID = 0
    dstBuf->inputFileChanged = 0
    dstBuf->phyAddr = 2415919232
    dstBuf->doNotDisplay = 0
    dstBuf->seqId = 0
    =====
    dstBuf->reserved = 1080806656
    dstBuf->addr = 1093480576
    dstBuf->bufSize = 230400
    dstBuf->fillLength = 0
    dstBuf->startOffset = 0
    dstBuf->mvDataOffset = 4294967295
    dstBuf->mvDataFilledSize = 0
    dstBuf->channelNum = 0
    dstBuf->codingType = 4294967295
    dstBuf->appData = 4294967295
    dstBuf->timeStamp = 4294967295
    dstBuf->temporalId = 0
    dstBuf->numTemporalLayerSetInCodec = 0
    dstBuf->upperTimeStamp = 4294967295
    dstBuf->lowerTimeStamp = 4294967295
    dstBuf->encodeTimeStamp = 4294967295
    dstBuf->bottomFieldBitBufSize = 0
    dstBuf->frameWidth = 4294967295
    dstBuf->frameHeight = 4294967295
    dstBuf->isKeyFrame = 4294967295
    dstBuf->allocPoolID = 0
    dstBuf->inputFileChanged = 0
    dstBuf->phyAddr = 2415919232
    dstBuf->doNotDisplay = 0
    dstBuf->seqId = 0
    =====
    .. ..(the above dstBuf info is repeated for 8 times)

    I am still getting the statistics showing no decoding as happening.

    and
    ==============
    DEC_LINK_CMD_PRINT_BUFFER_STATISTICS :

    [m3video] *** Decode Statistics ***
    [m3video] 143569: DEC: Rcvd from prev = 0, Returned to prev = 0
    [m3video] DEC Out BufExt Q Status
    [m3video] Empty Q 0 -> count 1, wrPtr 1, rdPtr 0
    [m3video] Full Q -> count 0, wrPtr 0, rdPtr 0
    ====================

    IPCBITSOUT_LINK_CMD_PRINT_BUFFER_STATISTICS


    IPCBITSOUTLINK:Buffer Statistics
    Num Alloc Pools:1
    PoolId | TotalBufCnt | FreeBufCnt | BufSize | AppAllocCount
    0| 1| 1| 230400| 0


    and the IVAHD buffer statistics is all 0's

    I suspect the problem is in my input feeding part. I would greatly appreciate your help.
    My present file is :

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <demos/link_api_demos/common/chains.h>
    
    Void Chains_FileDecFileWr(Chains_Ctrl *chainsCfg);
    
    #define TRUE              1
    #define FALSE 0
    
    #define SRC_NUM_CH 1
    #define NUM_BUF_PER_CH 1
    
    pthread_mutex_t g_mutex;
    pthread_cond_t g_condition;
    int conditionMet=0;
    
    pthread_mutex_t g_mutex2;
    pthread_cond_t g_condition2;
    int conditionMet2=0;
    
    
    
    #define INI_FILE "/opt/sample.h264"
    #define INI_FRAME_WIDTH 640
    #define INI_FRAME_HEIGHT 360
    #define INI_ENABLE 1
    #define INI_CODEC h264
    #define INI_NUMBUF 0
    #define INI_DISP_DELAY 0
    
    
    
    /**
                           FILE (H264)
                              |
                              |
                        IPC_BITS_OUT_A8 (BitStream)
                              |
                        IPC_BITS_IN_M3 (BitStream)
                              |
                             DEC
                              |
                       IPC_FRAMES_OUT_M3 (Frames)
                              |
                        IPC_FRAMES_IN_A8 (Frames)
                              |
                              |
                            FILE (YUV)
    */
    
    
    static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl =
    {
        .isPopulated = 1,
        .ivaMap[0] =
        {
            .EncNumCh  = 0,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            .DecNumCh  = SRC_NUM_CH,
            .DecChList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 , 14, 15}
        },
    
    };
    
    
    
    
    /* Heap Id registered with MessageQ for allocating message buffers.
       The heap associated with PE_MESSAGEQ_SHARED_REGION_ID is registered
       as PE_MESSAGEQ_HEAP_ID. */
    const unsigned short Rpe_messageqHeapId = 0;
    
    
    
    
    
    char gChains_runTimeMenu[] = {
        "\r\n ===================="
        "\r\n Chains Run-time Menu"
        "\r\n ===================="
        "\r\n"
        "\r\n 0: Stop Chain"
        "\r\n"
        "\r\n i: Print  DEC_LINK_CMD_PRINT_IVAHD_STATISTICS "
        "\r\n "
        "\r\n d: Print DEC_LINK_CMD_PRINT_STATISTICS "
        "\r\n "
        "\r\n D: Print DEC_LINK_CMD_PRINT_BUFFER_STATISTICS "
        "\r\n "
        "\r\n b: Print IPCBITSOUT_LINK_CMD_PRINT_BUFFER_STATISTICS "
        "\r\n "
        "\r\n Enter Choice: "
    };
    
    char gChains_menuMain0[] = {
        "\r\n ============"
        "\r\n Chain Select"
        "\r\n ============"
        "\r\n"
    };
    
    char gChains_menuMainVs[] = {
        "\r\n"
        "\r\n 1: <H264 FILERD-> DEC->FILEWR>"
        "\r\n "
        "\r\n x: Exit "
        "\r\n "
        "\r\n Enter Choice: "
    };
    
    
    char Chains_menuRunTime()
    {
    	char ch[128];
    	printf(gChains_runTimeMenu);
    	fgets(ch, 128, stdin);
    	if(ch[1] != '\n' || ch[0] == '\n')
    	ch[0] = '\n';
    	return ch[0];
    }
    
    
    Void Chains_menuMainShow()
    {
    	printf(gChains_menuMain0);
    
    	//Chains_menuCurrentSettingsShow();
    
    	printf(gChains_menuMainVs);
    }
    
    Void Chains_run(Chains_RunFunc chainsRunFunc)
    {
    	Chains_Ctrl chainsCtrl;
    
    	System_linkControl(
    		SYSTEM_LINK_ID_M3VPSS,
    		SYSTEM_M3VPSS_CMD_RESET_VIDEO_DEVICES,
    		NULL,
    		0,
    		TRUE
    		);
    
    	UTILS_assert(  chainsRunFunc!=NULL);
    	chainsRunFunc(&chainsCtrl);
    }
    
    Void Chains_menuMainRunVs(char ch)
    {
    
    	
    	switch(ch)
    	{
    	case '1':
    	
    		Chains_run(Chains_FileDecFileWr);
    		break;
    	case '2':
    		printf("invalid option 2");
    
    		break;
    	case '3':
    		printf("invalid option 3");
    
    		break;
    	case '4':
    		printf("invalid option 4");
    
    		break;
    	default:
    		printf("invalid option ");
    		break;
    	}
    }
    
    
    Void Chains_main()
    {
    	char ch[128];
    	Bool done;
    	
    	done = FALSE;
    	
    	// Chains_setDefaultCfg();
    	
    	while(!done)
    	{
    		Chains_menuMainShow();
    		
    		fgets(ch, 128, stdin);
    		if(ch[1] != '\n' || ch[0] == '\n')
    			continue;
    		
    		printf(" \r\n");
    		
    		Chains_menuMainRunVs(ch[0]);
    		
    		switch(ch[0])
    		{
    			case 's':
    			// Chains_menuSettings();
    			break;
    			case 'x':
    			done = TRUE;
    			break;
    			case 'd':
    			//Chains_detectBoard();
    			break;
    		}
    		
    	}
    }
    
    
    Void Chains_FileDecFileWr(Chains_Ctrl *chainsCfg)
    {
    	IpcBitsOutLinkHLOS_CreateParams   ipcBitsOutHostPrm;
    	IpcBitsInLinkRTOS_CreateParams    ipcBitsInVideoPrm;
    	
    	
    	DecLink_CreateParams     decPrm;
    	
    	IpcFramesOutLinkRTOS_CreateParams   ipcFramesOutVideoPrm;
    	IpcFramesInLinkHLOS_CreateParams  ipcFramesInHostPrm;
    	
    	
    	Int i;
    	Bool isProgressive;
    	System_LinkInfo bitsProducerLinkInfo;
    	
    	UInt32 decId;
    	UInt32 ipcFramesOutVideoId, ipcFramesInHostId;
    	UInt32 ipcBitsInVideoId, ipcBitsOutHostId;
    	char ch; 
    	int rc;
    	
    	//Chains_ipcBitsInit();
    	CHAINS_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
    	CHAINS_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);
    	
    	CHAINS_INIT_STRUCT(DecLink_CreateParams, decPrm);
    	
    	CHAINS_INIT_STRUCT(IpcFramesOutLinkRTOS_CreateParams,ipcFramesOutVideoPrm);
    	CHAINS_INIT_STRUCT(IpcFramesInLinkHLOS_CreateParams,ipcFramesInHostPrm);
    	
    	ipcBitsOutHostId  = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
    	ipcBitsInVideoId  = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;
    	
    	decId  = SYSTEM_LINK_ID_VDEC_0;
    	
    	ipcFramesOutVideoId = SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_OUT_0;
    	ipcFramesInHostId   = SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0;
    	
    	//decPrm.tilerEnable = FALSE; 
    	isProgressive = TRUE;
    	
    	System_linkControl(
    	SYSTEM_LINK_ID_M3VIDEO,
    	SYSTEM_COMMON_CMD_SET_CH2IVAHD_MAP_TBL,
    	&systemVid_encDecIvaChMapTbl,
    	sizeof(SystemVideo_Ivahd2ChMap_Tbl),
    	TRUE
    	);
    	
    	
    	ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink = ipcBitsInVideoId;
    	ipcBitsOutHostPrm.baseCreateParams.notifyNextLink = FALSE;
    	ipcBitsOutHostPrm.baseCreateParams.notifyPrevLink = FALSE;
    	ipcBitsOutHostPrm.baseCreateParams.noNotifyMode = TRUE;
    	ipcBitsOutHostPrm.baseCreateParams.numOutQue = 1;
    	ipcBitsOutHostPrm.inQueInfo.numCh = SRC_NUM_CH;
    	ipcBitsOutHostPrm.bufPoolPerCh = TRUE;
    	
    	for (i=0; i<SRC_NUM_CH; i++)
    	{
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].width = INI_FRAME_WIDTH;
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].height = INI_FRAME_HEIGHT;
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].scanFormat = SYSTEM_SF_PROGRESSIVE;
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].bufType        = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].codingformat   = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].dataFormat     = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].memType        = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].startX         = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].startY         = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[0]       = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[1]       = 0; // NOT USED
    	ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[2]       = 0; // NOT USED
    	ipcBitsOutHostPrm.numBufPerCh[i] = NUM_BUF_PER_CH;
    	}
    
    	/* IPC Host to IPC Video*/
    	ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId    = ipcBitsOutHostId;
    	ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    	ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink  = decId;
    	ipcBitsInVideoPrm.baseCreateParams.noNotifyMode              = TRUE;
    	ipcBitsInVideoPrm.baseCreateParams.notifyNextLink            = TRUE;
    	/* badri's changes*/
    	ipcBitsInVideoPrm.baseCreateParams.notifyPrevLink            = FALSE;
    	ipcBitsInVideoPrm.baseCreateParams.numOutQue                 = 1;
    
    	/* IPC Video to DEC*/
    	for (i=0; i<SRC_NUM_CH; i++) {
    		decPrm.chCreateParams[i].format          = IVIDEO_H264HP;
    		decPrm.chCreateParams[i].profile         = IH264VDEC_PROFILE_ANY;
    		decPrm.chCreateParams[i].targetMaxWidth  = INI_FRAME_WIDTH;
    		decPrm.chCreateParams[i].targetMaxHeight = INI_FRAME_HEIGHT;
    	#if 0
    		if (isProgressive)
    		decPrm.chCreateParams[i].fieldMergeDecodeEnable  = FALSE;
    		else
    		decPrm.chCreateParams[i].fieldMergeDecodeEnable  = TRUE;
    	#endif
    		decPrm.chCreateParams[i].numBufPerCh = NUM_BUF_PER_CH;
    		decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate = 25;
    		decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate = (2 * 1000 * 1000);
    	}
    	decPrm.inQueParams.prevLinkId = ipcBitsInVideoId;
    	decPrm.inQueParams.prevLinkQueId = 0;
    	decPrm.outQueParams.nextLink     = ipcFramesOutVideoId;
    	
    	/*DEC to IPC Video Frame out*/
    	
    	ipcFramesOutVideoPrm.baseCreateParams.noNotifyMode = TRUE;
    	ipcFramesOutVideoPrm.baseCreateParams.notifyNextLink = FALSE;
    	ipcFramesOutVideoPrm.baseCreateParams.notifyPrevLink = FALSE;
    	ipcFramesOutVideoPrm.baseCreateParams.inQueParams.prevLinkId = decId;
    	ipcFramesOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    	ipcFramesOutVideoPrm.baseCreateParams.numOutQue = 1;
    	ipcFramesOutVideoPrm.baseCreateParams.outQueParams[0].nextLink = ipcFramesInHostId;
    	
    	/*IPC  Frame video out to Host IN*/
    	ipcFramesInHostPrm.baseCreateParams.noNotifyMode = TRUE;
    	ipcFramesInHostPrm.baseCreateParams.notifyNextLink = FALSE;
    	/* badri's changes*/
    	ipcFramesInHostPrm.baseCreateParams.notifyPrevLink = TRUE;
    	ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkId = ipcFramesOutVideoId;
    	ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    	ipcFramesInHostPrm.baseCreateParams.outQueParams[0].nextLink = SYSTEM_LINK_ID_INVALID;
    	
    	
    	System_linkCreate(ipcBitsOutHostId,&ipcBitsOutHostPrm,sizeof(ipcBitsOutHostPrm));
    	System_linkCreate(ipcBitsInVideoId,&ipcBitsInVideoPrm,sizeof(ipcBitsInVideoPrm));
    	System_linkCreate(decId, &decPrm, sizeof(decPrm));
    	sleep(2);
    	System_linkCreate(ipcFramesOutVideoId, &ipcFramesOutVideoPrm, sizeof(ipcFramesOutVideoPrm));
    	System_linkCreate(ipcFramesInHostId, &ipcFramesInHostPrm, sizeof(ipcFramesInHostPrm));
    
    	printf("SYSTEM INFO >>> FILE - DEC - FILE Links Created\n");
    	
    
    
        
    	
    	System_linkStart(ipcFramesInHostId);
    	System_linkStart(ipcFramesOutVideoId);
    	System_linkStart(decId);
    	System_linkStart(ipcBitsInVideoId);
    	System_linkStart(ipcBitsOutHostId);
    	
    	rc = pthread_mutex_lock(&g_mutex);
    	conditionMet =1;
    	rc = pthread_cond_broadcast(&g_condition);
    	rc = pthread_mutex_unlock(&g_mutex);
    	
    	rc = pthread_mutex_lock(&g_mutex2);
    	conditionMet2 =1;
    	rc = pthread_cond_broadcast(&g_condition2);
    	rc = pthread_mutex_unlock(&g_mutex2);
    	
    	/* Start taking CPU load just before starting of links */
    	
    	
    	while(1)
    	{
    		ch = Chains_menuRunTime();
    		if(ch=='0')
    		break;
    		if(ch=='i')
    		System_linkControl(decId, DEC_LINK_CMD_PRINT_IVAHD_STATISTICS, NULL, 0, TRUE);
    		if(ch=='d')
    		System_linkControl(decId, DEC_LINK_CMD_PRINT_STATISTICS, NULL, 0, TRUE);
    		if(ch=='D')
    			System_linkControl(decId, DEC_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);
    		if(ch=='b')
    		System_linkControl(ipcBitsOutHostId, IPCBITSOUT_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);
    	}
    	//Chains_ipcBitsStop();
    	System_linkStop(ipcBitsOutHostId);
    	System_linkStop(ipcBitsInVideoId);
    	System_linkStop(decId);
        
    
    	System_linkDelete(ipcBitsOutHostId);
    	System_linkDelete(ipcBitsInVideoId);
    	System_linkDelete(decId);
    	System_linkDelete(ipcFramesOutVideoId);
    	System_linkDelete(ipcFramesInHostId);
    
    
    	//Chains_ipcBitsExit();
    }
    
    
    void print_diagnostics(	Bitstream_Buf  *dstBuf)
    {
    
        printf("dstBuf->reserved = %u\n",dstBuf->reserved);
        printf("dstBuf->addr = %u\n", dstBuf->addr);
        printf("dstBuf->bufSize = %u\n", dstBuf->bufSize);
        printf("dstBuf->fillLength = %u\n", dstBuf->fillLength);
        printf("dstBuf->startOffset = %u\n", dstBuf->startOffset);
        printf("dstBuf->mvDataOffset = %u\n", dstBuf->mvDataOffset);
        printf("dstBuf->mvDataFilledSize = %u\n", dstBuf->mvDataFilledSize);
        printf("dstBuf->channelNum = %u\n", dstBuf->channelNum);
        printf("dstBuf->codingType = %u\n", dstBuf->codingType);
        printf("dstBuf->appData = %u\n", dstBuf->appData);
        printf("dstBuf->timeStamp = %u\n", dstBuf->timeStamp);
        printf("dstBuf->temporalId = %u\n", dstBuf->temporalId);
    
        printf("dstBuf->numTemporalLayerSetInCodec = %u\n", dstBuf->numTemporalLayerSetInCodec);
    
        printf("dstBuf->upperTimeStamp = %u\n", dstBuf->upperTimeStamp);
        printf("dstBuf->lowerTimeStamp = %u\n", dstBuf->lowerTimeStamp);
        printf("dstBuf->encodeTimeStamp = %u\n", dstBuf->encodeTimeStamp);
        printf("dstBuf->bottomFieldBitBufSize = %u\n", dstBuf->bottomFieldBitBufSize);
        printf("dstBuf->frameWidth = %u\n", dstBuf->frameWidth);
        printf("dstBuf->frameHeight = %u\n", dstBuf->frameHeight);
        printf("dstBuf->isKeyFrame = %u\n", dstBuf->isKeyFrame);
        printf("dstBuf->allocPoolID = %u\n", dstBuf->allocPoolID);
    
        printf("dstBuf->inputFileChanged = %u\n", dstBuf->inputFileChanged);
    
        printf("dstBuf->phyAddr = %u\n", dstBuf->phyAddr);
    
        printf("dstBuf->doNotDisplay = %u\n", dstBuf->doNotDisplay);
        printf("dstBuf->seqId = %u\n", dstBuf->seqId);
        printf("=====\n");
        fflush(stdout);
    }
    
    static Void Chains_ipcFramesPrintFrameInfo(VIDFrame_Buf *buf)
    {
        OSA_printf("CHAINS_IPCFRAMES:VIDFRAME_INFO:"
                   "chNum:%d\t"
                   "fid:%d\t"
                   "frameWidth:%d\t"
                   "frameHeight:%d\t"
                   "timeStamp:%d\t"
                   "virtAddr[0][0]:%p\t"
                   "phyAddr[0][0]:%p",
                    buf->channelNum,
                    buf->fid,
                    buf->frameWidth,
                    buf->frameHeight,
                    buf->timeStamp,
                    buf->addr[0][0],
                    buf->phyAddr[0][0]);
    
    }
    
    
    
    void input_from_file(void *parm)
    {
    	int rc;
    	IpcBitsOutLinkHLOS_BitstreamBufReqInfo reqInfo;
    	Bitstream_BufList emptyBufList;
    
    	int iRet;
    	int i;
    	int read_size;
    	int status;
    	FILE *fphdr;
    	int fd;
    	Bitstream_Buf  *thisbuf_struct;
    
    	int ret_status;
    	int input_frame_count = 0;
    
    	int statHdr, statData;
    	int curCh;
    	unsigned long filledBufSize;
    	
    	/* wait for links to be created*/
    	/*
    	int pthread_cond_wait(pthread_cond_t *restrict cond,
    	pthread_mutex_t *restrict mutex); 
    	
    	*/
    
    	
    	while (!conditionMet) {
    	printf("input Thread blocked\n");
    	rc = pthread_cond_wait(&g_condition, &g_mutex);
    	
    	}
    
    	
    	fd = open("/opt/sample_tmr.h264", O_RDONLY);
    	if(fd <= 0)
    	{
    		printf("file open error");
    		exit(-1);
    	}
    	
    	fphdr = fopen("/opt/sample_tmr.h264.hdr", "r");
    	if(fphdr == NULL)
    	{
    		printf("file open error");
    		exit(-1);
    	}
    
    
    
    	int framei;
    //	while(1)
    	for (framei = 0; framei < 8; framei++)
    	{
    		reqInfo.numBufs = NUM_BUF_PER_CH;
    		reqInfo.reqType = IPC_BITSOUTHLOS_BITBUFREQTYPE_CHID;
    		
    		for (i = 0; i< NUM_BUF_PER_CH; i++) 
    		{
    			reqInfo.u[i].chNum = i;
    		    	// reqInfo.u[i].minBufSize =  ((INI_FRAME_WIDTH) * (INI_FRAME_HEIGHT)/2);
    
    		}
    
    
    
    
    
    
    		emptyBufList.numBufs = 0;
    		ret_status = IpcBitsOutLink_getEmptyVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &emptyBufList, &reqInfo);
    
            	OSA_assert(0 == ret_status);
    
    		if(emptyBufList.numBufs == 0)
    		{
    			printf("no empty buf received\n");
    			continue;
    		}
    
    		//for (bufi = 0; bufi< emptyBufList.numBufs; bufi++) 
    		int bufi;
    		bufi = 0;
    		{
    
    			thisbuf_struct = emptyBufList.bufs[bufi];
    
    			statHdr  = fscanf(fphdr,"%d",&(filledBufSize));
    
    			OSA_assert(filledBufSize <= thisbuf_struct->bufSize);
    
    			statData = read(fd, thisbuf_struct->addr, filledBufSize);
    			if( feof(fphdr) || statData != filledBufSize)
    			{
    		
    				printf(" CH Reached the end of file, inputframecount = %d !!!",input_frame_count);
    				break;
    			}
    		}
    
    		print_diagnostics(thisbuf_struct);
    		ret_status = IpcBitsOutLink_putFullVideoBitStreamBufs(SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0, &emptyBufList);
    		input_frame_count++;
    
    		sleep(1);
    	 }
    
    	close(fd);
    	fclose(fphdr);
    
    
    }
    
    
    void receive_output_and_filw(void *parm)
    {	
    
    	int fd;
    	VCODEC_BITSBUF_S *pEmptyBuf;
    	VIDFrame_BufList bufList;
    	int status;
    	int i;
    	int rc;
    
    	OSA_printf("CHAINS_IPCFRAMES:%s:Entered...",__func__);
    //	OSA_semWait(&thrObj->framesInNotifySem,OSA_TIMEOUT_FOREVER);
    	OSA_printf("CHAINS_IPCFRAMES:Received first frame notify...");
    
    #if 0
    	fd = open("/opt/out.yuv", O_WRONLY);
    	if(fd <= 0)
    	{
    		printf("file open error");
    		exit(-1);
    	}
    
    	
    	}
    #endif
    
    	while (!conditionMet2) {
    	printf("Output Thread blocked\n");
    	rc = pthread_cond_wait(&g_condition2, &g_mutex2);
    	}
    
    
    	sleep(2);
    
    	while(1)
    	{
    
    			
    		status =  IpcFramesInLink_getFullVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0,
                                                        &bufList);
    		OSA_assert(0 == status);
    		if (bufList.numFrames > 0)
    		{
    			printf("FULLF:");
    			for(i = 0; i < bufList.numFrames;i++)
    				/*writetofile(bufList.frames[i])*/
    				 Chains_ipcFramesPrintFrameInfo(&bufList.frames[i]);
    
    
    //			pEmptyBuf= &BitsBufList.bitsBuf[0];
    //			statData = write(fd, pEmptyBuf->bufVirtAddr, pEmptyBuf->filledBufSize);
    			status = IpcFramesInLink_putEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0, &bufList);
    
    		}
    
    #if 0
    		status =  IpcFramesOutLink_getEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_OUT_0,
                                                           &bufList);
    		OSA_assert(0 == status);
    		if (bufList.numFrames)
    	        {
    			printf("emptyF:");
    			for(i = 0; i < bufList.numFrames;i++)
    				/*writetofile(bufList.frames[i])*/
    			   Chains_ipcFramesPrintFrameInfo(&bufList.frames[i]);
    
    
            	    status = IpcFramesInLink_putEmptyVideoFrames(SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0,
                                                             &bufList);
            	    OSA_assert(0 == status);
            	}
    #endif
    
    	}
    	close(fd);
    
    
    }
    
    int main()
    {
    	pthread_t thrd,thrd2;
    	char *message1 = "Thread 1";
    	char *message2 = "Thread 2";
    	pthread_mutexattr_t mutexattr;  // Mutex Attribute
    	pthread_condattr_t    attr;
    	int rc;
    	int iret1;
    
    
    	System_init();
    
    	rc = pthread_condattr_init(&attr);
    	pthread_mutexattr_init(&mutexattr);
    
    	pthread_mutex_init(&(g_mutex), &mutexattr);
    	pthread_cond_init(&(g_condition), &attr);
    
    	pthread_mutex_init(&(g_mutex2), &mutexattr);
    	pthread_cond_init(&(g_condition2), &attr);
    
    	conditionMet = 0;
    	conditionMet2 = 0;
    
    	iret1 = pthread_create( &thrd, NULL, input_from_file, (void*) message1);
    	iret1 = pthread_create( &thrd2, NULL, receive_output_and_filw, (void*) message2);
    
    
    	Chains_main();
    
    	System_deInit();
    
    	pthread_cond_destroy(&g_condition);
    	pthread_cond_destroy(&g_condition2);
    	return 0;
    }
    
    

    thanks.

  • The problem with your implementation are:

    NUM_BUF_PER_CH 1 will not work.It should be 6 atleast.

    You are only copying the bitstream but are not populating any info in the bitstream buffer.

    You should atleast populate the filledBufSize for decoding to happen.

  • I also have got the same problem but my application is : Receiving encoded stream from network via RTSPClient and decode those stream. I just know copy the encoded stream from the network into Bitstream_Buf->addr and I don't know how to initialize (fill up) all fields of Bitstream_Buf before put them to the decoder by calling the function IpcBitsOutLink_putFullVideoBitStreamBufs. 

    Could you help of give me information abow how to resolve this problem. Thank you very much!

  • I am working on DM8148 RDK 3.5. I use ENC_A8_DEC usecase(multich_encode_decode.c) for my application

  • You have to set filledBufSize and channelNum atleast