Example #1
0
int main(int argc, char const *argv[])
{
    VI_EXT_CHN_ATTR_S stExtChnAttr;
    VB_BLK hBlock;
    VB_POOL hPool = VB_INVALID_POOLID;
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize, u32DstBlkSize;
    VIDEO_FRAME_INFO_S FrameInfo;
    IVE_HANDLE IveHandle;
    IVE_SRC_IMAGE_S stSrc;
    IVE_DST_IMAGE_S stDst;
    IVE_CSC_CTRL_S stCscCtrl;
    HI_BOOL bInstant = HI_TRUE;
    HI_BOOL bFinish;
    IplImage *iplImage;
    FILE *fp,*fp2;

    int k=1;
#if 0
    memset(&stVbConf, 0, sizeof(VB_CONF_S));
    stVbConf.u32MaxPoolCnt = 128;
    SAMPLE_COMM_VI_GetSizeBySensor(&enSize);
    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,
                enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
    stVbConf.astCommPool[0].u32BlkCnt = 12;

	s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
	if (HI_SUCCESS != s32Ret)
	{
		printf("system init failed with err code %#x!\n", s32Ret );
	}

	stViConfig.enViMode = SENSOR_TYPE;
	stViConfig.enRotate = ROTATE_NONE;
	stViConfig.enNorm = VIDEO_ENCODING_MODE_AUTO;
	stViConfig.enViChnSet = VI_CHN_SET_NORMAL;

	s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
	if (HI_SUCCESS != s32Ret)
	{
		printf("start vi failed with err code %#x!\n", s32Ret);
	//	goto END_1;
	}
#endif
    iplImage = cvCreateImageHeader(cvSize(WIDTH,HEIGHT), IPL_DEPTH_8U, 3);

	stExtChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	stExtChnAttr.s32BindChn = ViChn;
	stExtChnAttr.stDestSize.u32Width = WIDTH;
	stExtChnAttr.stDestSize.u32Height = HEIGHT;
	stExtChnAttr.s32DstFrameRate = -1;
	stExtChnAttr.s32SrcFrameRate = -1;
	stExtChnAttr.enCompressMode = COMPRESS_MODE_NONE;
    HI_MPI_VI_DisableChn(ExtChn);
	s32Ret = HI_MPI_VI_SetExtChnAttr(ExtChn, &stExtChnAttr);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_SetExtChnAttr failed with err code %#x\n", s32Ret);
		return -1;
	}
	s32Ret = HI_MPI_VI_SetFrameDepth(ExtChn, 1);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_SetFrameDepth failed with err code %#x\n", s32Ret);
		return -1;
	}
    stSrc.enType = IVE_IMAGE_TYPE_YUV420SP;
    //stDst.enType = IVE_IMAGE_TYPE_U8C3_PLANAR;
    stDst.enType = IVE_IMAGE_TYPE_U8C3_PACKAGE;
    stCscCtrl.enMode = IVE_CSC_MODE_PIC_BT709_YUV2RGB;

#if 1
	s32Ret = HI_MPI_VI_EnableChn(ExtChn);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_EnableChn failed with err code %#x\n", s32Ret);
		return -1;
	}
#endif
    printf("begin\n");
    det_t *pdet = det_open("bd_detect_trace.config");
    while(k)
    {
        s32Ret = HI_MPI_VI_GetFrame(ExtChn, &FrameInfo, -1);
        if(HI_SUCCESS != s32Ret)
        {
            printf("HI_MPI_VI_GetFrame failed with err code %#x!\n",s32Ret);
        }
        printf("get frame!\n");

        u32DstBlkSize = FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height * 3;
        s32Ret = HI_MPI_SYS_MmzAlloc_Cached(&stDst.u32PhyAddr[0],(void**) &stDst.pu8VirAddr[0], "user", HI_NULL, u32DstBlkSize);
        HI_MPI_SYS_MmzFlushCache(stDst.u32PhyAddr[0], (void *)stDst.pu8VirAddr[0], u32DstBlkSize);
#if 0
        stDst.u32PhyAddr[1] = stDst.u32PhyAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;
        stDst.u32PhyAddr[2] = stDst.u32PhyAddr[1] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;

        stDst.pu8VirAddr[0] = (HI_U8*) HI_MPI_SYS_Mmap(stDst.u32PhyAddr[0], u32DstBlkSize);
        stDst.pu8VirAddr[1] = stDst.pu8VirAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;
        stDst.pu8VirAddr[2] = stDst.pu8VirAddr[1] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;

        stDst.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0];
        stDst.u16Stride[1] = FrameInfo.stVFrame.u32Stride[0];
        stDst.u16Stride[2] = FrameInfo.stVFrame.u32Stride[0];

        stDst.u16Width = FrameInfo.stVFrame.u32Width;
        stDst.u16Height = FrameInfo.stVFrame.u32Height;
#endif
#if 1
        stDst.pu8VirAddr[0] = (HI_U8*) HI_MPI_SYS_Mmap(stDst.u32PhyAddr[0], u32DstBlkSize);
        stDst.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0];
        stDst.u16Width = FrameInfo.stVFrame.u32Width;
        stDst.u16Height = FrameInfo.stVFrame.u32Height;
#endif

        stSrc.u32PhyAddr[0] = FrameInfo.stVFrame.u32PhyAddr[0];
        stSrc.u32PhyAddr[1] = FrameInfo.stVFrame.u32PhyAddr[1];
        stSrc.u32PhyAddr[2] = FrameInfo.stVFrame.u32PhyAddr[2];

        stSrc.pu8VirAddr[0] = (HI_U8*)HI_MPI_SYS_Mmap(FrameInfo.stVFrame.u32PhyAddr[0], u32DstBlkSize / 2);
        stSrc.pu8VirAddr[1] = stSrc.pu8VirAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height;
        stSrc.pu8VirAddr[2] = stSrc.pu8VirAddr[1] + 1;


        stSrc.u16Stride[1] = FrameInfo.stVFrame.u32Stride[0];
        stSrc.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0];
        stSrc.u16Stride[2] = 0;

        stSrc.u16Width = FrameInfo.stVFrame.u32Width;
        stSrc.u16Height = FrameInfo.stVFrame.u32Height;

#if 0
        for(k = 0; k < 720 * 576 * 3 / 2;k++)
            *(stSrc.pu8VirAddr[0] + k) = 130;
        k = 0;
#endif
        s32Ret = HI_MPI_IVE_CSC(&IveHandle, &stSrc, &stDst, &stCscCtrl, bInstant);
        if(s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_IVE_CSC failed with error code %#x\n",s32Ret);
            continue;
        }
        s32Ret = HI_MPI_IVE_Query(IveHandle, &bFinish, HI_TRUE);
        if(s32Ret != HI_SUCCESS)
        {
            printf("HI_MPI_IVE_Query failed with error code %#x\n",s32Ret);
            continue;
        }
#if 0
        fp = fopen("image.rgb","wb");
        fwrite(stDst.pu8VirAddr[0], WIDTH * HEIGHT * 3, 1, fp);
        fclose(fp);

        fp2 = fopen("image2.yuv","wb");
        fwrite(stSrc.pu8VirAddr[0], WIDTH * HEIGHT * 3 / 2, 1, fp2);
        fclose(fp2);
#endif
        //printf("u16Width:%d,u16Height:%d\n",stDst.u16Width,stDst.u16Height);
        //printf("widthStep:%d\n",iplImage->widthStep);
        //cvSetData(iplImage, stDst.pu8VirAddr[0], iplImage->widthStep);
        //cvSaveImage("saveImage.jpg",iplImage);
        char *str = det_detect(pdet, HEIGHT, WIDTH, (char *)stDst.pu8VirAddr[0]);
        printf("%s\n",str);
        HI_MPI_SYS_Munmap(stDst.pu8VirAddr[0], u32DstBlkSize);
        HI_MPI_SYS_Munmap(stSrc.pu8VirAddr[0], u32DstBlkSize / 2);
        HI_MPI_SYS_MmzFree(stDst.u32PhyAddr[0], NULL);
        HI_MPI_VI_ReleaseFrame(ExtChn, &FrameInfo);
    }
    det_close(pdet);
}
Example #2
0
static int vin_capture(int vin, FILE* bitmap_stream)
{
	int ret = 0;
	int api_ret = SDK_FAILURE;
	if(vin < HI3520A_VIN_CH_BACKLOG_REF){
		int frame_depth = 0;
		VIDEO_FRAME_INFO_S video_frame_info;
		

		SOC_CHECK(HI_MPI_VI_GetFrameDepth(vin, &frame_depth));
		if(0 == frame_depth){
			HI_MPI_VI_SetFrameDepth(vin, 1);
		}

		if(HI_SUCCESS == HI_MPI_VI_GetFrame(vin, &video_frame_info)){
			if(PIXEL_FORMAT_YUV_SEMIPLANAR_420 == video_frame_info.stVFrame.enPixelFormat){
				int i = 0, ii = 0;
				int const width = video_frame_info.stVFrame.u32Width;
				int const height = video_frame_info.stVFrame.u32Height;
				size_t const stride = video_frame_info.stVFrame.u32Stride[0];
				size_t const yuv420_size = stride * height * 3 / 2;
				const uint8_t* yuv420_data = HI_MPI_SYS_Mmap(video_frame_info.stVFrame.u32PhyAddr[0], yuv420_size);
				// allocate the bitmap data
				size_t bitmap24_size = width * height * 3;
				uint8_t* bitmap24_data = alloca(bitmap24_size);
				uint8_t* bitmap24_pixel = bitmap24_data;

				SOC_TRACE("Frame(%d) [%dx%d] stride %d", vin, width, height, stride);
				
				if(yuv420_data){
					int y, u, v, yy, vr, ug, vg, ub;
					int r, g, b;
					const uint8_t *py = (uint8_t*)(yuv420_data);
					const uint8_t *puv = (uint8_t*)(py + width * height);

					// yuv420 to rgb888
					for(i = 0; i < height; ++i){
						for(ii = 0; ii < width; ++ii){
							y = py[0];
							yy = y * 256;
							
							u = puv[1] - 128;
							ug = 88 * u;
							ub = 454 * u;

							v = puv[0] - 128;
							vg = 183 * v;
							vr = 359 * v;

							///////////////////////////////////
							// convert
							r = (yy + vr) >> 8;
							g = (yy - ug - vg) >> 8;
							b = (yy + ub) >> 8;

							if(r < 0){
								r = 0;
							}
							if(r > 255){
								r = 255;
							}
							if(g < 0){
								g = 0;
							}
							if(g > 255){
								g = 255;
							}
							if(b < 0){
								b = 0;
							}
							if(b > 255){
								b = 255;
							}

							*bitmap24_pixel++ = (uint8_t)b;
							*bitmap24_pixel++ = (uint8_t)g;
							*bitmap24_pixel++ = (uint8_t)r;

							//SOC_TRACE("RGB[%3d,%3d,%3d] @ (%3d,%3d)", r, g, b, ii, i);

							///////////////////////////////////
							++py;
							if(0 != (ii % 2)){
								// even
								puv += 2;
							}
						}

						if(0 != (i % 2)){
							// try twice
							puv -= width;
						}
					}
					SOC_CHECK(HI_MPI_SYS_Munmap(yuv420_data, yuv420_size));

					if(0 == fseek(bitmap_stream, 0, SEEK_SET)){
						

						BIT_MAP_FILE_HEADER_t bmp_header;
						memset(&bmp_header, 0, sizeof(bmp_header));

						bmp_header.type[0] = 'B';
						bmp_header.type[1] = 'M';
						bmp_header.file_size = sizeof(bmp_header) + bitmap24_size;
						bmp_header.reserved_zero = 0;
						bmp_header.off_bits = sizeof(bmp_header);
						bmp_header.info_size = 40;
						bmp_header.width = width;
						bmp_header.height = height;
						bmp_header.planes = 1;
						bmp_header.bit_count = 24;
						bmp_header.compression = 0;
						bmp_header.size_image = bitmap24_size;
						bmp_header.xpels_per_meter = 0;
						bmp_header.ypels_per_meter = 0;
						bmp_header.clr_used = 0;
						bmp_header.clr_important = 0;

						fwrite(&bmp_header, 1, sizeof(bmp_header), bitmap_stream);
						for(i = 0; i < height; ++i){
							void* bitmap_offset = bitmap24_data + (height - i - 1) * width * 3;
							fwrite(bitmap_offset, 1, width * 3, bitmap_stream);
						}
						
						api_ret = SDK_SUCCESS;
					}
				}
			}
			SOC_CHECK(HI_MPI_VI_ReleaseFrame(vin, &video_frame_info));
		}
Example #3
0
/******************************************************************************
* function : Start BT1120 720P vi/vo/venc
******************************************************************************/
HI_S32 SAMPLE_COMM_IVE_BT1120_720P_PreView(SAMPLE_IVE_VI_VO_CONFIG_S *pstViVoConfig,
	HI_BOOL bOpenVi,HI_BOOL bOpenViExt,HI_BOOL bOpenVo,HI_BOOL bOpenVenc,HI_BOOL bOpenVpss,HI_U32 u32VpssChnNum)
{
    HI_U32 u32ViChnCnt = 1;
    VB_CONF_S stVbConf;
    VO_DEV VoDev = SAMPLE_VO_DEV_DSD0;
    VI_CHN ViChn = 0;
	VI_CHN ViExtChn = 1;
    VO_PUB_ATTR_S stVoPubAttr;
    SAMPLE_VO_MODE_E enVoMode = VO_MODE_1MUX;
    PIC_SIZE_E enPicSize = pstViVoConfig->enPicSize;
	VI_EXT_CHN_ATTR_S stExtChnAttr;
   
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 u32BlkSize;
    SIZE_S stSize;
    VO_LAYER VoLayer = 0;
    VO_VIDEO_LAYER_ATTR_S stLayerAttr;
	SAMPLE_VI_CONFIG_S *pstViConfig = &(pstViVoConfig->stViConfig);
	VENC_CHN VencChn = 0;
	HI_U32 u32ViDepth = 4;
	VI_CHN_ATTR_S stChnAttr;
	HI_U32 u32VpssGrpCnt = 1;	
	VPSS_CHN aVpssChn[2] = {VPSS_CHN0, VPSS_CHN3};
    VPSS_GRP_ATTR_S stVpssGrpAttr;
	SIZE_S astSize[2];
	
    memset(&stVbConf,0,sizeof(VB_CONF_S));

    u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(pstViVoConfig->enNorm, enPicSize,
                            SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
    stVbConf.u32MaxPoolCnt = 64;

    /*ddr0 video buffer*/
    stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
    stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 3;

	if ((HI_TRUE == bOpenViExt) || (HI_TRUE ==  bOpenVpss))
	{
		u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(pstViVoConfig->enNorm,PIC_CIF, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
		stVbConf.astCommPool[1].u32BlkSize = u32BlkSize;
		stVbConf.astCommPool[1].u32BlkCnt = 3;
	}    
    // mpp system init.
    s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
    if (HI_SUCCESS != s32Ret)
    {
        SAMPLE_PRT("SAMPLE_COMM_SYS_Init fail,Error(%#x)\n", s32Ret);
        goto END_720P_0;
    }

	if (HI_TRUE == bOpenVi)
	{
		s32Ret = SAMPLE_COMM_VI_StartVi(pstViConfig);
		if (HI_SUCCESS != s32Ret)
		{
			SAMPLE_PRT("SAMPLE_COMM_VI_StartVi fail,Error(%#x)\n",s32Ret);
			goto END_720P_0;
		}
		s32Ret = HI_MPI_VI_SetFrameDepth(ViChn,u32ViDepth);
		if (HI_SUCCESS != s32Ret)
		{
			SAMPLE_PRT("HI_MPI_VI_SetFrameDepth fail,ViChn(%d),Error(%#x)\n",ViChn,s32Ret);
			goto END_720P_1;
		}
		s32Ret = HI_MPI_VI_GetChnAttr(ViChn,&stChnAttr);
		if (HI_SUCCESS != s32Ret)
		{
			SAMPLE_PRT("HI_MPI_VI_GetChnAttr fail,ViChn(%d),Error(%#x)\n",ViChn,s32Ret);
			goto END_720P_1;
		}
		//Set Vi frame rate,because vi from BT1120 is 720P@30
		stChnAttr.s32SrcFrameRate = 3;
		stChnAttr.s32DstFrameRate = 1;
		s32Ret = HI_MPI_VI_SetChnAttr(ViChn,&stChnAttr);
		if (HI_SUCCESS != s32Ret)
		{
			SAMPLE_PRT("HI_MPI_VI_SetChnAttr,ViChn(%d),Error(%#x)\n",ViChn,s32Ret);
			goto END_720P_1;
		}

	}

	//Open vi ext chn
	if (HI_TRUE == bOpenViExt)
	{
	   stExtChnAttr.enPixFormat = SAMPLE_PIXEL_FORMAT;
	   stExtChnAttr.s32BindChn = ViChn;
	   stExtChnAttr.stDestSize.u32Width = 352;
	   stExtChnAttr.stDestSize.u32Height = 288;
	   stExtChnAttr.s32DstFrameRate = -1;
	   stExtChnAttr.s32SrcFrameRate = -1;
	   stExtChnAttr.enCompressMode  = COMPRESS_MODE_NONE;
	   
	  s32Ret = HI_MPI_VI_SetExtChnAttr(ViExtChn, &stExtChnAttr);
	  if (HI_SUCCESS != s32Ret)
	  {
		  SAMPLE_PRT("HI_MPI_VI_SetExtChnAttr fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
		  goto END_720P_1;
	  }
	  s32Ret = HI_MPI_VI_EnableChn(ViExtChn);
	  if (HI_SUCCESS != s32Ret)
	  {
		  SAMPLE_PRT("HI_MPI_VI_EnableChn fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
		  goto END_720P_1;
	  }
	  s32Ret = HI_MPI_VI_SetFrameDepth(ViExtChn,u32ViDepth);
	  if (HI_SUCCESS != s32Ret)
	  {
		SAMPLE_PRT("HI_MPI_VI_SetFrameDepth fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret);
		goto END_720P_1;
	  }

	}
	//Open vo 
	if (HI_TRUE == bOpenVo)
	{
	    s32Ret = SAMPLE_COMM_SYS_GetPicSize(pstViVoConfig->enNorm, enPicSize, &stSize);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize fail,Error(%#x)\n",s32Ret);
	        goto END_720P_2;
	    }
	    stVoPubAttr.enIntfType = pstViVoConfig->enVoIntfType;
		//hi3518e Vo only suppurt pal
        //if(VO_INTF_BT1120 == pstViVoConfig->enVoIntfType)
        //{
        //    stVoPubAttr.enIntfSync = /*VO_OUTPUT_720P60*/VO_OUTPUT_1080P30;
        //}
        //       if(SAMPLE_VI_MODE_BT1120_1080P == pstViVoConfig->stViConfig.enViMode)
        //      {
        //          stVoPubAttr.enIntfSync = VO_OUTPUT_1080P30;
        //      }
        //else if(SAMPLE_VI_MODE_BT1120_720P == pstViVoConfig->stViConfig.enViMode)
        //      {
        //          stVoPubAttr.enIntfSync = VO_OUTPUT_720P60;
        //      }
        //   else
	    {
	        stVoPubAttr.enIntfSync = VO_OUTPUT_PAL;
	    }
	    stVoPubAttr.u32BgColor = 0x000000ff;
	    /* In HD, this item should be set to HI_FALSE */
	    s32Ret = SAMPLE_COMM_VO_StartDev(VoDev, &stVoPubAttr);
	    if (HI_SUCCESS != s32Ret)
	    {
	       SAMPLE_PRT("SAMPLE_COMM_VO_StartDevLayer fail,VoDev(%d),Error(%#x)!\n",VoDev,s32Ret);
	       goto END_720P_2;
	    }

	    stLayerAttr.bClusterMode = HI_FALSE;
		stLayerAttr.bDoubleFrame = HI_FALSE;
		stLayerAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	    memcpy(&stLayerAttr.stImageSize,&stSize,sizeof(stSize)); 

		stLayerAttr.u32DispFrmRt = 60 ;
		stLayerAttr.stDispRect.s32X = 0;
		stLayerAttr.stDispRect.s32Y = 0;
		if((stVoPubAttr.enIntfSync == VO_OUTPUT_720P60) || (stVoPubAttr.enIntfSync == VO_OUTPUT_1080P30))
	    {
	    	stLayerAttr.stDispRect.u32Width = stSize.u32Width;
	    	stLayerAttr.stDispRect.u32Height = stSize.u32Height;
	    }
	    else if(stVoPubAttr.enIntfSync == VO_OUTPUT_PAL)
	    {
	        stLayerAttr.stDispRect.u32Width = 720;
	    	stLayerAttr.stDispRect.u32Height = 576;
	    }     
	    s32Ret = SAMPLE_COMM_VO_StartLayer(VoLayer, &stLayerAttr, HI_TRUE);
		if (HI_SUCCESS != s32Ret)
		{		
			SAMPLE_PRT("SAMPLE_COMM_VO_StartLayer fail,VoLayer(%d),Error(%#x)\n",VoLayer,s32Ret);
			goto END_720P_3;
		}

	    s32Ret = SAMPLE_COMM_VO_StartChn(VoDev, enVoMode);
	    if (HI_SUCCESS != s32Ret)
	    {
	       SAMPLE_PRT("SAMPLE_COMM_VO_StartChn fail,VoDev(%d),Error(%#x)\n",VoDev,s32Ret);
	       goto END_720P_4;
	    }
	}

	if (HI_TRUE == bOpenVenc)
	{
		s32Ret = SAMPLE_COMM_VENC_Start(VencChn, PT_H264, pstViVoConfig->enNorm, enPicSize, SAMPLE_RC_CBR,0);
		if(s32Ret != HI_SUCCESS)
		{
			SAMPLE_PRT("SAMPLE_COMM_VENC_Start fail,VencChn(%d),Error(%#x)\n",VencChn,s32Ret);
			goto END_720P_5;
		}
         s32Ret = SAMPLE_COMM_VENC_StartGetStream(1);
        if (HI_SUCCESS != s32Ret)
        {
            SAMPLE_PRT("SAMPLE_COMM_VENC_StartGetStream fail,Error(%#x)\n",s32Ret);
            goto END_720P_6;
        }
	}
	if (HI_TRUE ==  bOpenVpss)
	{
		s32Ret = SAMPLE_COMM_SYS_GetPicSize(pstViVoConfig->enNorm, enPicSize, &astSize[0]);
	    if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize fail,Error(%#x)\n",s32Ret);
	        goto END_720P_6;
	    }
		astSize[1].u32Width = 352;
		astSize[1].u32Height = 288;
		SAMPLE_COMM_IVE_VpssGrpAttr(u32VpssGrpCnt, &stVpssGrpAttr, &stSize);
		s32Ret = SAMPLE_COMM_IVE_VpssStart(u32VpssGrpCnt, astSize, aVpssChn, u32VpssChnNum, &stVpssGrpAttr);
		if (HI_SUCCESS != s32Ret)
	    {
	        SAMPLE_PRT("SAMPLE_COMM_IVE_VpssStart fail,Error(%#x)\n",s32Ret);
	        goto END_720P_6;
	    }

	}
	return s32Ret;

//END_720P_7:
    //if (HI_TRUE == bOpenVpss)
    //{
    //	SAMPLE_COMM_IVE_StopVpss(u32VpssGrpCnt,u32VpssChnNum);
    //}

END_720P_6:
	if (HI_TRUE == bOpenVenc)
	{
		SAMPLE_COMM_VENC_Stop(VencChn);
	}
END_720P_5:
	if (HI_TRUE == bOpenVo)
	{
		SAMPLE_COMM_VO_StopChn(VoDev, enVoMode);
	}
END_720P_4:   
	if (HI_TRUE == bOpenVo)
	{
		SAMPLE_COMM_VO_StopLayer(VoLayer);
	}    
END_720P_3:
	if (HI_TRUE == bOpenVo)
	{
		SAMPLE_COMM_VO_StopDev(VoDev);
	}    
END_720P_2:
	if(HI_TRUE == bOpenViExt)
	{
		(HI_VOID)HI_MPI_VI_DisableChn(ViExtChn);
	}
END_720P_1:
	if (HI_TRUE == bOpenVi)
	{
		SAMPLE_COMM_VI_StopVi(pstViConfig);
	}
END_720P_0:
    SAMPLE_COMM_SYS_Exit();

    return s32Ret;
}
Example #4
0
File: b.c Project: thatking/hi3516c
int main(int argc, char const *argv[])
{
	PAYLOAD_TYPE_E enPayLoad = PT_H264;
	VB_CONF_S stVbConf;
	SAMPLE_VI_CONFIG_S stViConfig;
	VPSS_GRP_ATTR_S stVpssGrpAttr;
	VPSS_CHN_ATTR_S stVpssChnAttr;
	VPSS_CHN_MODE_S stVpssChnMode;
	VI_EXT_CHN_ATTR_S stExtChnAttr;
	SAMPLE_RC_E enRcMode = SAMPLE_RC_CBR;
	HI_S32 s32ChnNum = 1;
	HI_S32 s32Ret = HI_SUCCESS;
	HI_U32 u32BlkSize;
	SIZE_S stSize;
	int sockfd, SendSockfd;
	struct sockaddr_in SendServaddr;
	pthread_t sendvideotid, AnalyzePictid, snaptid, accepttid;
	int ret;
	MPP_CHN_S stSrcChn;
	MPP_CHN_S stDestChn;


	memset(&stVbConf, 0 , sizeof(VB_CONF_S));
	stVbConf.u32MaxPoolCnt = 128;
	u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,
	             enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
	stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
	stVbConf.astCommPool[0].u32BlkCnt = 10;

//	u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,
//	             PIC_QVGA, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH);
//	stVbConf.astCommPool[0].u32BlkSize = u32BlkSize;
//	stVbConf.astCommPool[0].u32BlkCnt = 10;

	//初始化系统
	printf("-----------------------V0.01-----------------------\n");
	s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
	if (HI_SUCCESS != s32Ret)
	{
		printf("system init failed with err code %#x!\n", s32Ret );
	}
	stViConfig.enViMode = SENSOR_TYPE;
	//stViConfig.enViMode = SONY_IMX122_DC_1080P_30FPS;
	stViConfig.enRotate = ROTATE_NONE;
	stViConfig.enNorm = VIDEO_ENCODING_MODE_AUTO;
	stViConfig.enViChnSet = VI_CHN_SET_NORMAL;

	//配置并启动VI
	s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);
	if (HI_SUCCESS != s32Ret)
	{
		printf("start vi failed with err code %#x!\n", s32Ret);
		goto END_1;
	}

	stExtChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	stExtChnAttr.s32BindChn = ViChn;
	stExtChnAttr.stDestSize.u32Width = WIDTH;
	stExtChnAttr.stDestSize.u32Height = HEIGHT;
	stExtChnAttr.s32FrameRate = -1;
	stExtChnAttr.s32SrcFrameRate = -1;
	s32Ret = HI_MPI_VI_SetExtChnAttr(ExtChn, &stExtChnAttr);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_SetExtChnAttr failed with err code %#x\n", s32Ret);
		return -1;
	}
	s32Ret = HI_MPI_VI_SetFrameDepth(1, 5);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_SetFrameDepth failed with err code %#x\n", s32Ret);
		return -1;
	}
	s32Ret = HI_MPI_VI_EnableChn(ExtChn);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_EnableChn failed with err code %#x\n", s32Ret);
		return -1;
	}

	stExtChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
	stExtChnAttr.s32BindChn = ViChn;
	stExtChnAttr.stDestSize.u32Width = WIDTH;
	stExtChnAttr.stDestSize.u32Height = HEIGHT;
	stExtChnAttr.s32FrameRate = -1;
	stExtChnAttr.s32SrcFrameRate = -1;
	s32Ret = HI_MPI_VI_SetExtChnAttr(SnapExtChn, &stExtChnAttr);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_SetExtChnAttr failed with err code %#x\n", s32Ret);
		return -1;
	}

	s32Ret = HI_MPI_VI_EnableChn(SnapExtChn);
	if (HI_SUCCESS != s32Ret)
	{
		printf("HI_MPI_VI_EnableChn failed with err code %#x\n", s32Ret);
		return -1;
	}

#if 1

	s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize);
	if (HI_SUCCESS != s32Ret)
	{
		printf("SAMPLE_COMM_SYS_GetPicSize failed with err code %#x!\n", s32Ret);
		goto END_2;
	}

	//配置并启动VPSS组
	stVpssGrpAttr.u32MaxW = stSize.u32Width;
	stVpssGrpAttr.u32MaxH = stSize.u32Height;
	stVpssGrpAttr.bDrEn = HI_FALSE;
	stVpssGrpAttr.bDbEn = HI_FALSE;
	stVpssGrpAttr.bIeEn = HI_TRUE;
	stVpssGrpAttr.bNrEn = HI_TRUE;
	stVpssGrpAttr.bHistEn = HI_TRUE;
	stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_AUTO;
	stVpssGrpAttr.enPixFmt = SAMPLE_PIXEL_FORMAT;
	s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr);
	if (HI_SUCCESS != s32Ret)
	{
		printf("SAMPLE_COMM_VPSS_StartGroup failed with err code %#x!\n", s32Ret);
		goto END_3;
	}

	//绑定VI和VPSS
	s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode);
	if (HI_SUCCESS != s32Ret)
	{
		printf("SAMPLE_COMM_vi_BindVpss failed with err code %#x\n", s32Ret);
		goto END_4;
	}

	//配置并启动VPSS通道
	memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr));
	stVpssChnAttr.bFrameEn = HI_FALSE;
	stVpssChnAttr.bSpEn = HI_TRUE;

	stVpssChnMode.enChnMode     = VPSS_CHN_MODE_USER;
	stVpssChnMode.bDouble       = HI_FALSE;
	stVpssChnMode.enPixelFormat = SAMPLE_PIXEL_FORMAT;
	stVpssChnMode.u32Width      = 1920;
	stVpssChnMode.u32Height     = 1080;
	s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL);
	if (HI_SUCCESS != s32Ret)
	{
		printf("SAMPLE_COMM_VPSS_EnableChn failed with err code %#x\n", s32Ret);
		goto END_5;
	}

#if 0
	s32Ret = SAMPLE_COMM_VENC_BindVpss(SnapVencGrp, VpssGrp, VpssChn);
	if (HI_SUCCESS != s32Ret)
	{
		printf("SAMPLE_COMM_VENC_BindVpss failed with err code %#x\n", s32Ret);
	}
	gs_enNorm = PIC_D1;
	s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize);
	if (HI_SUCCESS != s32Ret)
	{
		printf("SAMPLE_COMM_SYS_GetPicSize failed with err code %#x\n", s32Ret);
	}
#endif

#endif

	stSrcChn.enModId = HI_ID_VIU;
	stSrcChn.s32DevId = 0;
	stSrcChn.s32ChnId = SnapExtChn;

	stDestChn.enModId = HI_ID_GROUP;
	stDestChn.s32DevId = SnapVencGrp;
	stDestChn.s32ChnId = 0;

	s32Ret = HI_MPI_SYS_Bind(&stSrcChn, &stDestChn);
	if (s32Ret != HI_SUCCESS)
	{
		SAMPLE_PRT("failed with %#x!\n", s32Ret);
		//return HI_FAILURE;
	}

	stSize.u32Width = 720;
	stSize.u32Height = 576;
	//printf("%d,%d\n",stSize.u32Width,stSize.u32Height);
	s32Ret = SAMPLE_COMM_VENC_SnapStart(SnapVencGrp, SnapVencChn, &stSize);
	if (HI_SUCCESS != s32Ret)
	{
		printf("SAMPLE_COMM_VENC_SnapStart failed with err code %#x\n", s32Ret);
	}

#if 1
#if 0
	//创建发送视频流socket
	//SendSockfd = socket(AF_INET, SOCK_STREAM, 0);
	SendSockfd = socket(AF_INET, SOCK_DGRAM, 0);
	if (SendSockfd == -1)
	{
		perror("send socket error");
		exit(0);
	}
	memset(&SendServaddr, 0, sizeof(SendServaddr));
	SendServaddr.sin_family = AF_INET;
	//SendServaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	SendServaddr.sin_addr.s_addr = inet_addr("10.1.2.60");
	SendServaddr.sin_port = htons(6666);
#endif
#if 0
	if (bind(SendSockfd, (struct sockaddr *)&SendServaddr, sizeof(SendServaddr)) == -1)
	{
		perror("send bind error");
		exit(0);
	}
	if (listen(SendSockfd, 10) == -1)
	{
		perror("send listen error");
		exit(0);
	}
#endif
#if 0
	//ret = pthread_create(&sendvideotid, 0, (HI_VOID*)SendVideoStream, SendSockfd);
	ret = pthread_create(&sendvideotid, 0, (HI_VOID*)SendVideoStream, 0);
	if (ret != 0)
	{
		perror("create SendVideoStream error");
		exit(0);
	}
	printf("create SendVideoStream thread successfully!\n");
#endif
#endif
	ret = pthread_create(&AnalyzePictid, 0, (HI_VOID*)AnalyzePic, NULL);
	if (ret != 0)
	{
		perror("create AnalyzePic error");
		exit(0);
	}
	ret = pthread_create(&snaptid, 0, (HI_VOID*)SnapPic, NULL);
	if (ret != 0)
	{
		perror("create SnapPic error");
		exit(0);
	}
	ret = pthread_create(&accepttid, 0, (HI_VOID*)accept_thread, NULL);
	if (ret != 0)
	{
		perror("create accept_thread error");
		exit(0);
	}
	while (1)
	{
		sleep(10);
	}

END_5:
	SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn);
END_4:
	SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode);
END_3:
	SAMPLE_COMM_VPSS_StopGroup(VpssGrp);
END_2:
	SAMPLE_COMM_VI_StopVi(&stViConfig);
END_1:
	SAMPLE_COMM_SYS_Exit();

	close(SendSockfd);
	pthread_join(sendvideotid, NULL);
	return 0;
}