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

📄 arm_client.c

📁 本程序实现了在s3c2410嵌入式板子下
💻 C
字号:
/**Arm_Client.c*@周润生 万世辉 张灿群*/#include "MyHost.h"char  errMsg[MAXLINE];static struct v4ldevice vd;void err_exit(char *err_msg){	printf(err_msg);	if (errno != 0)		perror("error:");	close(vd.deviceHandle);	exit(-1);}int videodevice_open(char deviceName[]){       vd.deviceHandle = open (deviceName, O_RDWR);       if (vd.deviceHandle == -1)        {           sprintf (errMsg,"Could not open device %s \n", deviceName);           err_exit(errMsg);        }       if (ioctl (vd.deviceHandle, VIDIOCGCAP, &vd.capability) == -1)        {           sprintf (errMsg,"could not obtain device capabilities\n");           err_exit(errMsg);        }        if ((vd.capability.type & VID_TYPE_CAPTURE) == 0)        {           sprintf (errMsg,"this device cannot capture video to memory\n");           err_exit(errMsg);        }	if ((vd.capability.type & VID_TYPE_SCALES) != -1)        {               vd.captureWindow.x = 0;              vd.captureWindow.y = 0;              vd.captureWindow.width = 256;              vd.captureWindow.height = 256;              vd.captureWindow.chromakey = 0;              vd.captureWindow.flags = 0;              vd.captureWindow.clips = 0;              vd.captureWindow.clipcount = 0;              if (ioctl (vd.deviceHandle, VIDIOCSWIN, &vd.captureWindow) == -1)                {                  sprintf (errMsg,"Could not set desired dimensions\nNot a fatal error.\n");	    	  err_exit(errMsg);                }        }	if (ioctl (vd.deviceHandle, VIDIOCGWIN, &vd.captureWindow) == -1)        {            sprintf (errMsg,"Could not obtain capture window dimensions.\n");            err_exit(errMsg);        }        printf ("Capturing dimensions are : %d, %d\n", vd.captureWindow.width, vd.captureWindow.height);        if (ioctl (vd.deviceHandle, VIDIOCGPICT, &vd.imageProperties) == -1)        {            sprintf (errMsg,"Failed to retrieve the video depth and palette.\n");            err_exit(errMsg);        }        printf ("Capture depth is %dbit\n",vd.imageProperties.depth);        if (vd.imageProperties.palette==PIC_PALETTE)         {           printf ("capture palette is YUV420P.\n");        }	if (ioctl (vd.deviceHandle, VIDIOCGMBUF, &vd.memoryBuffer) == -1)        {           sprintf (errMsg,"Failed to retrieve information about MMIO space.\n");           err_exit(errMsg);        }	vd.memoryMap = (char*)mmap (0, vd.memoryBuffer.size, PROT_READ | PROT_WRITE, MAP_SHARED, vd.deviceHandle, 0);        if (vd.memoryMap == NULL)        {            sprintf (errMsg,"Failed to obtain MMIO space.\n");            err_exit(errMsg);        } 	vd.mmaps.width = vd.captureWindow.width;        vd.mmaps.height = vd.captureWindow.height;        vd.mmaps.format = vd.imageProperties.palette;	return 0;}void videodevice_close(){        munmap (vd.memoryMap, vd.memoryBuffer.size);        close (vd.deviceHandle);	vd.deviceHandle=0;}char* NextFrame(int bufferIndex){	vd.mmaps.frame=bufferIndex;	 	if(ioctl(vd.deviceHandle,VIDIOCMCAPTURE,&vd.mmaps) == -1)	 {       		sprintf (errMsg,"send a request to begin capturing to the currently indexed buffer error\n");                err_exit(errMsg);	 }        if (ioctl (vd.deviceHandle, VIDIOCSYNC, &vd.mmaps) == -1)        {     		sprintf (errMsg,"wait for the currently indexed frame to complete capture error\n");                err_exit(errMsg);        }        return (vd.memoryMap + vd.memoryBuffer.offsets[bufferIndex]);}int main(int argc,char *argv[]){		int i=0;	int width,height;	char *temp=NULL,*frame=NULL;	if(argc<3)	{	 printf("please input deviceName and hostname!\n");	 exit(1);	}	videodevice_open(argv[1]);	width=vd.captureWindow.width;	height=vd.captureWindow.height;	printf("***** width=%d *** height=%d *****\n",width,height);	printf ("*****Capture is ready:*****\n");	printf ("*****capturing  images display on LCD.*****\n");		for(i=0;i<50;i++)	{		if(temp!=NULL) free(temp);		temp=(char *)malloc(width*height*4*sizeof(char));		frame=NULL;		frame=NextFrame(i%2);		rgb24(width,height,frame,temp);		MyClient(argv[2],8888,"output.ppm");		sleep(1);	 	printf("*****picture_%d seccess!*****\n",i);	}	videodevice_close();	return 0;}

⌨️ 快捷键说明

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