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