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

📄 spcav4l.c

📁 一个可以实现嵌入式视频监控系统的最新版客户端软件。
💻 C
📖 第 1 页 / 共 2 页
字号:
      vd->vmmap.format = vd->formatIn;    }  else    {      if (ioctl (vd->fd, VIDIOCGWIN, &vd->videowin) < 0)	perror ("VIDIOCGWIN failed \n");      vd->videowin.height = vd->hdrheight;      vd->videowin.width = vd->hdrwidth;      if (ioctl (vd->fd, VIDIOCSWIN, &vd->videowin) < 0)	perror ("VIDIOCSWIN failed \n");      printf ("VIDIOCGWIN height %d  width %d \n",	      vd->videowin.height, vd->videowin.width);    }  vd->framesizeIn = ((vd->hdrwidth * vd->hdrheight * vd->bppIn) >> 3);//  vd->pixTmp =//    (unsigned char *) realloc (vd->pixTmp, (size_t) vd->framesizeIn);}/* return masq byte for the needed size */static int convertsize( int width, int height){	switch (width){	case 640:		if(height == 480)		return VGA;	break;	case 384:		if(height == 288)		return PAL;	break;	case 352:		if(height == 288)		return SIF;	break;	case 320:		if(height == 240)		return CIF;	break;	case 192:		if(height == 144)		return QPAL;	break;	case 176:		if(height == 144)		return QSIF;	break;	case 160:		if(height == 120)		return QCIF;	break;	default:	break;	} return -1;}static int sizeconvert( int *width, int *height, int size){	switch (size){	case VGA:		*height = 480;		*width = 640;			break;	case PAL:		*height = 288;		*width = 384;			break;	case SIF:		*height = 288;		*width = 352;			break;	case CIF:		*height = 240;		*width = 320;			break;	case QPAL:		*height = 144;		*width = 192;			break;	case QSIF:		*height = 144;		*width = 176;			break;	case QCIF:		*height = 120;		*width = 160;			break;	default:	return -1;	break;	} return 0;}static int convertpalette( int palette){	switch (palette){	case VIDEO_PALETTE_JPEG:		return JPG;	break;	case VIDEO_PALETTE_YUV420P:			return YUV420P;	break;	case VIDEO_PALETTE_RGB24:			return RGB24;	break;	case VIDEO_PALETTE_RGB565:			return RGB565;	break;	case VIDEO_PALETTE_RGB32:			return RGB32;	break;	default:	break;	} return -1;}static int paletteconvert( int code){	switch (code){	case JPG:		return VIDEO_PALETTE_JPEG;				break;	case YUV420P:		return VIDEO_PALETTE_YUV420P;			break;	case RGB24:		return VIDEO_PALETTE_RGB24;				break;	case RGB565:		return VIDEO_PALETTE_RGB565;			break;	case RGB32:		return VIDEO_PALETTE_RGB32;			break;	default:	return -1;	break;	} return 0;}/*check palette not so easy try VIDIOCMCAPTURE IOCTL the only one with palette and size *//* some drivers may fail here  */static int checkpalette (struct vdIn *vd){	unsigned char masq = 0x00;	int f = 0;	int needpalette = 0;	int palette =0;		needpalette = convertpalette(vd->formatIn); 	/* is the palette available */	if (!(vd->palette & needpalette)){	/* find an other one */		if(needpalette >1){			masq = needpalette -1;		}	if (( masq & vd->palette) > 1){		/* check lower masq upper size */		while (!((needpalette = needpalette >> 1) & vd->palette) && needpalette);	} else if ((masq & vd->palette) == 0){		masq = 0xff -(needpalette << 1) +1;		if ((masq & vd->palette) == 0){			/* no more size available */			needpalette = 0;		} else {		/* check upper masq */			while (!((needpalette = needpalette << 1) & vd->palette) && needpalette);		}		} // maybe == 1	} 		if ((palette = paletteconvert( needpalette)) < 0){		printf("Invalid palette in check palette fatal !! \n");		return -1;	}      if (palette){      vd->vmmap.height = vd->hdrheight;      vd->vmmap.width = vd->hdrwidth;      vd->vmmap.format = palette;      	  vd->vmmap.frame = 0;	  if (ioctl (vd->fd, VIDIOCMCAPTURE, &(vd->vmmap)))	    {	      perror ("cmcapture");	      return -1;	    }	    } else {	    printf("palette not find check palette fatal !! \n");	    return -1;		    }	    /*populate the change */	vd->formatIn = palette;return palette;   }/* test is palette and size are available otherwhise return the next available palette and size palette is set by preference order jpeg yuv420p rbg24 rgb565 and rgb32 */static int check_palettesize(struct vdIn *vd ){	int needsize = 0;	int needpalette = 0;	unsigned char masq = 0x00;	/* initialize needed size */	if ((needsize = convertsize(vd->hdrwidth,vd->hdrheight)) < 0){	printf( "size seem unavailable fatal errors !!\n");		return -1;	}	/* is there a match with available palette */	/* check */	if (!(vd->sizeothers & needsize)){	if (needsize > 1){		masq = needsize -1;		}	if (( masq & vd->sizeothers) > 1){		/* check lower masq upper size */		while (!((needsize = needsize >> 1) & vd->sizeothers) && needsize);	} else if ((masq & vd->sizeothers) == 0){		masq = 0xff -(needsize << 1) +1;		if ((masq & vd->sizeothers) == 0){			/* no more size available */			needsize = 0;		} else {		/* check upper masq */			while (!((needsize = needsize << 1) & vd->sizeothers) && needsize);		}		} // maybe == 1	 	}	if(needsize){		/* set the size now check for a palette */		if(sizeconvert( &vd->hdrwidth,&vd->hdrheight,needsize) > 0){			printf( "size not set fatal errors !!\n");		return -1;		}		if((needpalette = checkpalette(vd) < 0)){		return -1;		}	 } else {		 printf ("Damned no match found Fatal errors !!\n");		 return -1;	 }return needsize;	}static intisSpcaChip (const char *BridgeName){  int i = -1;  int find = -1;  int size = 0;    /* Spca506 return more with channel video, cut it */    /* return Bridge otherwhise -1 */  for (i = 0; i < MAX_BRIDGE -1; i++)    {    size = strlen (Blist[i].name) ;    printf ("is_spca %s \n",Blist[i].name);      if (strncmp (BridgeName, Blist[i].name, size) == 0)	{	find = i;	  break;	}    }  return find;}static intGetStreamId (const char *BridgeName){  int i = -1;  int match = -1;/* return Stream_id otherwhise -1 */  if ((match = isSpcaChip (BridgeName)) < 0)    {      printf ("Not an Spca5xx Camera !!\n");      return match;    }  switch (match)    {    case BRIDGE_SPCA505:    case BRIDGE_SPCA506:      i = YYUV;      break;    case BRIDGE_SPCA501:      i = YUYV;      break;    case BRIDGE_SPCA508:      i = YUVY;      break;    case BRIDGE_SPCA536:    case BRIDGE_SPCA504:    case BRIDGE_SPCA500:    case BRIDGE_SPCA504B:    case BRIDGE_SPCA533:    case BRIDGE_SPCA504C:    case BRIDGE_ZR364XX:    case BRIDGE_ZC3XX:    case BRIDGE_CX11646:    case BRIDGE_SN9CXXX:    case BRIDGE_MR97311:         i = JPEG;      break;    case BRIDGE_ETOMS:    case BRIDGE_SONIX:    case BRIDGE_SPCA561:    case BRIDGE_TV8532:      i = GBRG;      break;    default:      i = UNOW; // -1;      printf ("Unable to find a StreamId !!\n");      break;    }  return i;}static intGetDepth (int format){  int depth;  switch (format)    {      case VIDEO_PALETTE_JPEG:      {	depth = 8;		      }      break;    case VIDEO_PALETTE_RAW:      {	depth = 8;		      }      break;    case VIDEO_PALETTE_YUV420P:      {	depth = (8 * 3) >> 1;      }      break;    case VIDEO_PALETTE_RGB565:      depth = 16;      break;    case VIDEO_PALETTE_RGB24:      depth = 24;      break;    case VIDEO_PALETTE_RGB32:      {	depth = 32;      }      break;    default:      depth = -1;      break;    }  return depth;}__u8SpcaGetBrightness (struct vdIn * vdin){  if (GetVideoPict (vdin) < 0)    {      printf (" Error getBrightness \n");      return 0;    }  return ((vdin->videopict.brightness) >> 8);}voidSpcaSetBrightness (struct vdIn *vdin, __u8 bright){  vdin->videopict.brightness = bright << 8;  if (SetVideoPict (vdin) < 0)    {      printf (" Error setBrightness \n");    }}__u8SpcaGetContrast (struct vdIn *vdin){  if (GetVideoPict (vdin) < 0)    {      printf (" Error getContrast \n");      return 0;    }  return ((vdin->videopict.contrast) >> 8);}voidSpcaSetContrast (struct vdIn *vdin, __u8 contrast){  vdin->videopict.contrast = contrast << 8;  if (SetVideoPict (vdin) < 0)    {      printf (" Error setContrast \n");    }}__u8SpcaGetColors (struct vdIn *vdin){  if (GetVideoPict (vdin) < 0)    {      printf (" Error getColors \n");      return 0;    }  return ((vdin->videopict.colour) >> 8);}voidSpcaSetColors (struct vdIn *vdin, __u8 colors){  vdin->videopict.colour = colors << 8;  if (SetVideoPict (vdin) < 0)    {      printf (" Error setColors \n");    }}/* we assume that struct videopict is initialized */unsigned short upbright( struct vdIn *vdin){ 		unsigned short bright =0;		bright = vdin->videopict.brightness;	if(( bright+0x200) < 0xffff){	bright += 0x200;	vdin->videopict.brightness = bright;	if (SetVideoPict (vdin) < 0)    		{      			printf (" Error setVideopict \n");			return 0;    		}		}	return bright;	}unsigned short downbright( struct vdIn *vdin){		unsigned short bright =0;		bright = vdin->videopict.brightness;	if(( bright-0x200) > 0){	bright -= 0x200;	vdin->videopict.brightness = bright;	if (SetVideoPict (vdin) < 0)    		{      			printf (" Error setVideopict \n");			return 0;    		}		}	return bright;	}unsigned short upcontrast( struct vdIn *vdin){		unsigned short contrast =0;		contrast = vdin->videopict.contrast;	if((contrast+0x200) < 0xffff){	contrast += 0x200;	vdin->videopict.contrast = contrast;	if (SetVideoPict (vdin) < 0)    		{      			printf (" Error setVideopict \n");			return 0;    		}		}	return contrast;}unsigned short downcontrast( struct vdIn *vdin){		unsigned short contrast =0;		contrast = vdin->videopict.contrast;	if( (contrast-0x200) > 0){	contrast -= 0x200;	vdin->videopict.contrast = contrast;	if (SetVideoPict (vdin) < 0)    		{      			printf (" Error setVideopict \n");			return 0;    		}		}	return contrast;	}voidqualityUp(struct vdIn *vdin){	struct video_param *videoparam= &vdin->videoparam;	int fd = vdin->fd;	unsigned char index = videoparam->quality;	index += 1;	spcaSetQuality(fd,videoparam,index);}voidqualityDown(struct vdIn *vdin){	struct video_param *videoparam= &vdin->videoparam;	int fd = vdin->fd;	unsigned char index = videoparam->quality;	if(index > 0) index--;	spcaSetQuality(fd,videoparam,index);}voidtimeUp(struct vdIn *vdin){	struct video_param *videoparam= &vdin->videoparam;	int fd = vdin->fd;	unsigned short index = videoparam->time_interval;	index+=10;	spcaSetTimeInterval(fd,videoparam,index);}voidtimeDown(struct vdIn *vdin){	struct video_param *videoparam= &vdin->videoparam;	int fd = vdin->fd;	unsigned short index = videoparam->time_interval;	if(index > 0) index -=10;	spcaSetTimeInterval(fd,videoparam,index);}voidspcaSetAutoExpo(struct vdIn *vdin){	struct video_param *videoparam= &vdin->videoparam;	int fd = vdin->fd;	videoparam->chg_para = CHGABRIGHT;	videoparam->autobright = !videoparam->autobright;	if(ioctl(fd,SPCASVIDIOPARAM, videoparam) == -1){		printf ("autobright error !!\n");	} else		spcaPrintParam (fd,videoparam);	}static void spcaPrintParam (int fd, struct video_param *videoparam){	if(ioctl(fd,SPCAGVIDIOPARAM, videoparam) == -1){		printf ("wrong spca5xx device\n");	} else 		printf("quality %d autoexpo %d Timeframe %d \n",			 videoparam->quality,videoparam->autobright,videoparam->time_interval);}static void spcaSetTimeInterval(int fd, struct video_param *videoparam, unsigned short time){	if (time < 1000) {	videoparam->chg_para = CHGTINTER;	videoparam->time_interval = time;	if(ioctl(fd,SPCASVIDIOPARAM, videoparam) == -1){		printf ("frame_times error !!\n");	} else		spcaPrintParam (fd,videoparam);	}}static void spcaSetQuality(int fd, struct video_param *videoparam, unsigned char index){	if (index < 6) {	videoparam->chg_para = CHGQUALITY;	videoparam->quality = index;	if(ioctl(fd,SPCASVIDIOPARAM, videoparam) == -1){		printf ("quality error !!\n");	} else		spcaPrintParam (fd,videoparam);	}}

⌨️ 快捷键说明

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