hi3518e - mpp2/sample_venc 解读

SAMPLE_VENC_720P_MJPEG(HI_VOID)
// step  1: init sys variable 
 u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\
                enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH,);
// step 2: mpp system init. 
s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
    HI_MPI_SYS_Exit();
    HI_MPI_VB_Exit();
    s32Ret = HI_MPI_VB_SetConf(pstVbConf);
    s32Ret = HI_MPI_VB_Init();
    s32Ret = HI_MPI_SYS_SetConf(&stSysConf);
    s32Ret = HI_MPI_SYS_Init();
// step 3: start vi dev & chn to capture
s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
    s32Ret = SAMPLE_COMM_VI_StartIsp(pstViConfig);
    			//* step 1: configure sensor.
    			s32Ret = SAMPLE_COMM_ISP_SensorInit();
    					  //** 1. sensor init */
    					 sensor_init();
    					 			sensor_write_register(int addr, int data)
    					 						 //  打开的是/dev/gpioi2c_ov 还是/dev/hi_i2c 要由#ifdef HI_GPIO_I2C确定
     					 						 fd = open("/dev/gpioi2c_ov", 0);
    					 						 ret = ioctl(fd, GPIO_I2C_WRITE, &value);
    					 					   close(fd);
    					 //** 2. sensor register callback */
    					 s32Ret = sensor_register_callback(); ??
    		  //* step 2: configure & run isp thread 
    		  s32Ret = SAMPLE_COMM_ISP_Run();
    		  			s32Ret = SAMPLE_COMM_ISP_Init();
    		  			pthread_create(&gs_IspPid, 0, (void* (*)(void*))HI_MPI_ISP_Run, NULL)
    		  			s32Ret = SAMPLE_COMM_ISP_LoadRegFile(CFG_OPT_LOAD, SAMPLE_ISPCFG_FILE);
    		  
    		  //* step 3 : config & start vicap dev
    		  s32Ret = SAMPLE_COMM_VI_StartDev(ViDev, enViMode);
    		  			memcpy(&stViDevAttr,&DEV_ATTR_OV9712_DC_720P,sizeof(stViDevAttr));
    		  			s32Ret = HI_MPI_VI_SetDevAttr(ViDev, &stViDevAttr);  //设置设备的属性
    		  			s32Ret = HI_MPI_VI_EnableDev(ViDev);
    		  //* Step 4: config & start vicap chn (max 1)  			
    	 	  s32Ret = SAMPLE_COMM_VI_StartChn(ViChn, &stCapRect, &stTargetSize, pstViConfig);
    		 				s32Ret = HI_MPI_VI_SetChnAttr(ViChn, &stChnAttr);
    		 				s32Ret = HI_MPI_VI_SetRotate(ViChn, enRotate);
    		 				s32Ret = HI_MPI_VI_EnableChn(ViChn);
// step 4: start vpss and vi bind vpss	 				
s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize);
s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);    
			s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp, pstVpssGrpAttr);
			s32Ret = HI_MPI_VPSS_GetGrpParam(VpssGrp, &stVpssParam);
			s32Ret = HI_MPI_VPSS_SetGrpParam(VpssGrp, &stVpssParam);
			s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);
s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);			
			s32Ret = SAMPLE_COMM_VI_Mode2Param(enViMode, &stViParam);
			s32Ret = HI_MPI_SYS_Bind(&stSrcChn, &stDestChn);
s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, HI_NULL, HI_NULL);
			s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, pstVpssChnAttr);
			s32Ret = HI_MPI_VPSS_SetChnMode(VpssGrp, VpssChn, pstVpssChnMode);
			s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn);
// step 5: start stream venc			
s32Ret = SAMPLE_COMM_VENC_Start(VencGrp, VencChn, enPayLoad,gs_enNorm, enSize, enRcMode);
s32Ret = SAMPLE_COMM_VENC_BindVpss(VencGrp, VpssGrp, VpssChn);
			s32Ret = HI_MPI_SYS_Bind(HI_ID_VPSS, HI_ID_GROUP);
// step 6: stream venc process -- get stream, then save it to file. 
s32Ret = SAMPLE_COMM_VENC_StartGetStream(s32ChnNum);
			pthread_create(&gs_VencPid, 0, SAMPLE_COMM_VENC_GetVencStreamProc, (HI_VOID*)&gs_stPara);
getchar();
getchar();



产生的线程一:(pthread_create(&gs_IspPid, 0, (void* (*)(void*))HI_MPI_ISP_Run, NULL))
(void* (*)(void*))HI_MPI_ISP_Run

产生的线程二:pthread_create(&gs_VencPid, 0, SAMPLE_COMM_VENC_GetVencStreamProc, (HI_VOID*)&gs_stPara);
HI_VOID* SAMPLE_COMM_VENC_GetVencStreamProc(HI_VOID *p)

//  step 1:  check & prepare save-file & venc-fd
s32Ret = HI_MPI_VENC_GetChnAttr(VencChn, &stVencChnAttr);
s32Ret = SAMPLE_COMM_VENC_GetFilePostfix(enPayLoadType[i], szFilePostfix);
			strcpy(szFilePostfix, ".h264");
sprintf(aszFileName[i], "stream_chn%d%s", i, szFilePostfix);
pFile[i] = fopen(aszFileName[i], "wb");
VencFd[i] = HI_MPI_VENC_GetFd(i);

//  step 2:  Start to get streams of each channel.
while (HI_TRUE == pstPara->bThreadStart)
{
s32Ret = HI_MPI_VENC_Query(i, &stStat);
stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
s32Ret = HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE);
s32Ret = SAMPLE_COMM_VENC_SaveStream(enPayLoadType[i], pFile[i], &stStream);
			s32Ret = SAMPLE_COMM_VENC_SaveH264(pFd, pstStream);
						 fwrite(pstStream->pstPack[i].pu8Addr[0],pstStream->pstPack[i].u32Len[0], 1, fpH264File);
             fflush(fpH264File);
s32Ret = HI_MPI_VENC_ReleaseStream(i, &stStream);
}
fclose(pFile[i]);

你可能感兴趣的:(hi3518e,开发记录)