⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcctest.c

📁 linux 嵌入式原代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	x = read(fd, (void*)&tmcnt, 4);	fprintf(stderr, "tmrec cnt=%d\n", tmcnt);#if VCC_TIMEREC_2	sz = sizeof(Tmrec);#else	sz = sizeof(Tmrec) * tmcnt;	tmrecs = (Tmrec*)malloc(sz);	if(tmrecs == NULL){		fprintf(stderr, "tmrecs == NULL !!\n");		return;	}#endif#if VCC_TIMEREC_2    fp = fopen(tmo_fn, "w");    if(fp == NULL){	fprintf(stderr, "fopen %s err\n", tmo_fn);	return;    }    for(i=0; i<tmcnt; i++){	cp = (char*)&rec;	sz2 = sz;#else	cp = (char*)tmrecs;	sz2 = sz;#endif	while(sz2 > 0){		x = read(fd, (void*)cp, sz2);		if(x <= 0){			fprintf(stderr, "tm read ??\n");			break;		}				sz2 -= x;		cp += x;	}#if VCC_TIMEREC_2	x = fwrite(&rec, 1, sz, fp);	if(x < 0){		fprintf(stderr, "tm fwrite x=%d\n", x);		fclose(fp);		return;	}    }    fclose(fp);#else	save(tmo_fn, (unsigned char *)tmrecs, sz);#endif}#endif /* VCC_TIMEREC */#ifdef USE_SELECTstatic int wait_capture_done(int dev, int captured){    int retval;    fd_set rfd;    struct timeval timeout;    do{	do{	    FD_ZERO(&rfd);	    FD_SET(dev, &rfd);	    timeout.tv_sec = 0;	    timeout.tv_usec = 0;	    retval = select(dev+1, (fd_set *)&rfd, (fd_set *)0, (fd_set *)0,			    &timeout);#ifdef SHOW_DEBUG_INFO	    printf("select: retval=%d\n", retval);#endif	}while(retval <= 0 );#ifdef SHOW_DEBUG_INFO	if( (retval = read(dev, (void *)&vcc_read[captured],			   sizeof(struct fr400cc_vcc_read)))	    != sizeof(struct fr400cc_vcc_read) ){	    printf("fail read (retval=%d)\n", retval);	    return -1;	}	printf("read: type:%d r_cnt:%d time:%d.%06d\n",	       vcc_read[captured].type, 	       vcc_read[captured].count, 	       vcc_read[captured].captime.tv_sec, 	       vcc_read[captured].captime.tv_usec);    }while(vcc_read[captured].type != FR400CC_VCC_RTYPE_CAPTURE);#else /* not SHOW_DEBUG_INFO */        if( (retval = read(dev, (void *)&vcc_read_dummy,			   sizeof(struct fr400cc_vcc_read)))	    != sizeof(struct fr400cc_vcc_read) ){	    printf("fail read (retval=%d)\n", retval);	    return -1;	}    }while(vcc_read_dummy.type != FR400CC_VCC_RTYPE_CAPTURE);#endif  /* not SHOW_DEBUG_INFO */    return 0;}#endifstatic int capture(int dev){    int retval;    int captured = 0;    struct fr400cc_vcc_wait vcc_w;#if CFGCHK    if ( (retval = ioctl_start_vcc (dev, -1)) < 0) {#else    if ( (retval = ioctl (dev, VCCIOCSTART, -1)) < 0) {#endif	printf("fail capture start(retval=%d, errno=%d)\n",	       retval, errno);	return -1;    }        while(1){#ifdef USE_SELECT	if( wait_capture_done(dev, captured) < 0 )            return -1;#endif	/*  USE_SELECT */	vcc_w.num = 1;	if ((retval = ioctl (dev, VCCIOCWAIT, &vcc_w))< 0) {	    printf("fail capture (frame=%d)\n", 0);	    return -1;	}#ifdef SHOW_DEBUG_INFO	if ((retval = ioctl (dev, VCCIOCGINF, &vcc_info[captured]))< 0) {	    printf("fail get info (%d)\n", captured);	    return -1;	}	vcc_frame_info[captured].frame = vcc_w.first_frame;	if ((retval = ioctl (dev, VCCIOCGFINF, &vcc_frame_info[captured]))< 0) {	    printf("fail get frame info (%d)\n", captured);	    return -1;	}#if 0	{	    struct __fr400cc_vcc_regio regio;	    regio.reg_no = VCC_RCC;	    if ((retval = ioctl (dev, __VCCIOCGREGIO, &regio))< 0) {		printf("fail get regio (%d)\n", retval);		return -1;	    }	    printf("rcc=%08x\n", regio.value);	}#endif#endif	/*  SHOW_DEBUG_INFO */#if VCC_TIMEREC	frame_write_ram(frame_base + vcc_mbuf.offsets[vcc_w.first_frame], 1);#else	frame_write_ram(frame_base + vcc_mbuf.offsets[vcc_w.first_frame], 0);#endif	if ((retval = ioctl (dev, VCCIOCFREE, 1))< 0) {	    printf("fail done (retval=%d)\n", retval);	    return -1;	}	//	printf("vcc_wait: retval=%d num=%d, first_frame=%d, count=%d\n",	//	       retval, vcc_w.num, vcc_w.first_frame, vcc_w.count);	captured++;	if( captured >= TMPBUF_LEN )	    break;    }    if ((retval = ioctl (dev, VCCIOCSTOP))< 0) {	printf("fail stop (retval=%d, errno=%d)\n", retval, errno);	return -1;    }    if( mode == 's' ){	printf("sleep(6000)\n");	sleep(6000);    }#if VCC_TIMEREC    time_rec_save(dev);#endif    close(dev);    return captured;}static int vsync_test_select(int dev){    int retval;#ifdef USE_SELECT    int loop = 0;    while(loop++<10){	fd_set rfd;	struct timeval timeout;	struct fr400cc_vcc_read vread;	FD_ZERO(&rfd);	FD_SET(dev, &rfd);	timeout.tv_sec = 0;	timeout.tv_usec = 200000;	retval = select(dev+1, (fd_set *)&rfd, (fd_set *)0, (fd_set *)0,			&timeout);	if( retval <= 0 ){		printf("select: timout 200 msec (retval=%d)\n", retval);	}else{	    if( (retval = read(dev, (void *)&vread,			       sizeof(struct fr400cc_vcc_read)))		!= sizeof(struct fr400cc_vcc_read) ){		printf("fail read (retval=%d)\n", retval);		return -1;	    }	    printf("read: type:%d r_cnt:%d time:%d.%06d\n",		   vread.type, 		   vread.count, 		   vread.captime.tv_sec, 		   vread.captime.tv_usec);	}    }#else    printf("sleep(10)\n");    sleep(10);#endif}static int vsync_test(int dev){    int retval;    printf("vsync start\n");    if ( (retval = ioctl (dev, VCCIOCVSSTART)) < 0) {	printf("fail vsync start(retval=%d, errno=%d)\n",	       retval, errno);	return -1;    }    vsync_test_select(dev);    printf("vsync stop\n");    if ((retval = ioctl (dev, VCCIOCVSSTOP))< 0) {	printf("fail stop (retval=%d, errno=%d)\n", retval, errno);	return -1;    }    vsync_test_select(dev);    printf("vsync start\n");    if ( (retval = ioctl (dev, VCCIOCVSSTART)) < 0) {	printf("fail vsync start(retval=%d, errno=%d)\n",	       retval, errno);	return -1;    }        vsync_test_select(dev);    printf("vsync stop\n");    if ((retval = ioctl (dev, VCCIOCVSSTOP))< 0) {	printf("fail stop (retval=%d, errno=%d)\n", retval, errno);	return -1;    }    vsync_test_select(dev);    close(dev);    return 0;}#ifdef SHOW_DEBUG_INFOstatic void show_debug_info(int captured){    int i;    for(i=0; i< captured; i++){	int usec;	printf("info: st:%d cnt:%d fi:%d num_k:%d num_u:%d rest:%d f(%d,%d)\n",	       vcc_info[i].status,	       vcc_info[i].count,	       vcc_info[i].field,	       vcc_info[i].frame_num_k,	       vcc_info[i].frame_num_u,	       vcc_info[i].rest);#ifdef USE_SELECT	if( i != 0 ){	    usec = tvusec(&(vcc_read[i-1].captime),			  &(vcc_read[i].captime));	}else{	    usec = 0;	}	printf("read: r_cnt:%d time:%d.%06d (d=%d.%03dmsec)\n",	       vcc_read[i].count, 	       vcc_read[i].captime.tv_sec, 	       vcc_read[i].captime.tv_usec, 	       usec / 1000, usec % 1000);#endif	if( i != 0 ){	    usec = tvusec(&(vcc_frame_info[i-1].captime),			  &(vcc_frame_info[i].captime));	}else{	    usec = 0;	}	printf("frame: st:%d cnt:%d lcnt:%d time:%d.%06d (d=%d.%03dmsec)\n",	       vcc_frame_info[i].status,	       vcc_frame_info[i].count,	       vcc_frame_info[i].lost_count,	       vcc_frame_info[i].captime.tv_sec,	       vcc_frame_info[i].captime.tv_usec,	       usec / 1000, usec % 1000);    }}#endif /* SHOW_DEBUG_INFO */static void write_file(int captured){    char buf[128];    int fn, i, pic;    printf("captured %d\n", captured);    pic = 0;    for(i=0; i< captured; i++){	sprintf(buf, "cap%03d.yuv", pic);	write_file_frame(buf, tmpbuf + i*FILESIZE);	pic++;    }}int main(int argc, char **argv){    char *devname="/dev/fr400cc_vcc";    int dev;    int i, n;#if VCC_TIMEREC    i = opt_chk(argc,argv,"-tmo");    if(i!=0 && i+1<argc) tmo_fn = argv[i+1];#endif#if CFGCHK	verbose = (opt_chk(argc,argv, "-v") != 0);#endif    if( argc >= 2 )	mode = argv[1][0];    if( (dev = setup_vcc(devname)) == -1 )	return 1;#if REGIO_TEST    {	unsigned value;	struct fr400cc_vcc_regio regio;	if(opt_chk_val(argc, argv, "-rhy", &value) == 0){		regio.reg_offset = FR400CC_VCC_RHY;		regio.value = value;		if(ioctl(dev, VCCIOCSREGIO, &regio) != 0){			fprintf(stderr, "ioctl VCCIOSREGIO err\n");			close(dev);			return -1;		}	}	if(opt_chk_val(argc, argv, "-rhc", &value) == 0){		regio.reg_offset = FR400CC_VCC_RHC;		regio.value = value;		if(ioctl(dev, VCCIOCSREGIO, &regio) != 0){			fprintf(stderr, "ioctl VCCIOSREGIO err\n");			close(dev);			return -1;		}	}	if(opt_chk_val(argc, argv, "-rv", &value) == 0){		regio.reg_offset = FR400CC_VCC_RV;		regio.value = value;		if(ioctl(dev, VCCIOCSREGIO, &regio) != 0){			fprintf(stderr, "ioctl VCCIOSREGIO err\n");			close(dev);			return -1;		}	}	if(opt_chk(argc, argv, "-show-rcc") != 0){		regio.reg_offset = FR400CC_VCC_RCC;		if(ioctl(dev, VCCIOCGREGIO, &regio) != 0){			fprintf(stderr, "ioctl VCCIOSREGIO err\n");			close(dev);			return -1;		}		printf("-show-rcc : %08x\n", regio.value);	}	if(opt_chk(argc, argv, "-show-ris") != 0){		regio.reg_offset = FR400CC_VCC_RIS;		if(ioctl(dev, VCCIOCGREGIO, &regio) != 0){			fprintf(stderr, "ioctl VCCIOSREGIO err\n");			close(dev);			return -1;		}		printf("-show-ris : %08x\n", regio.value);	}    }#endif    // memcpy_time_check(frame_base, &vcc_mbuf);    sleep(1);    if( mode=='v' ){	vsync_test(dev);    }else if( mode=='t' ){	struct fr400cc_vcc_mbuf mbuf;	while(1)	    ioctl (dev, VCCIOCGMBUF, &mbuf);    }else{	printf("capture start\n");	if( (n = capture(dev)) == -1 )	    return 2;	printf("capture end\n");    }#ifdef SHOW_DEBUG_INFO    show_debug_info(n);#endif#if 1    write_file(n);#endif    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -