[Gridflow-cvs] [svn] commit: r5572 - in /trunk/src: v4l2.cxx videodev.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sun May 2 22:56:53 EDT 2010


Author: matju
Date: Sun May  2 22:56:52 2010
New Revision: 5572

Log:
merge initialize2 into \constructor

Modified:
    trunk/src/v4l2.cxx
    trunk/src/videodev.cxx

Modified: trunk/src/v4l2.cxx
==============================================================================
--- trunk/src/v4l2.cxx (original)
+++ trunk/src/v4l2.cxx Sun May  2 22:56:52 2010
@@ -110,6 +110,28 @@
 	WH(memory,"%u"); // enum v4l2_memory
 };
 
+static t_symbol *safe_gensym (const char *s, int n=32) {
+	int i; char buf[n+1]; memcpy(buf,s,n); buf[n]=0;
+	for (i=n-1; buf[i] && !isspace(buf[i]); i--) buf[i]=0;
+	for (i=0; buf[i]; i++) {
+		if (isspace(buf[i])) buf[i]='_';
+		if (buf[i]=='(') buf[i]='[';
+		if (buf[i]==')') buf[i]=']';
+	}
+	return gensym(buf);
+}
+
+
+#define DEBUG(args...) 42
+//#define DEBUG(args...) post(args)
+
+#define  IOCTL( F,NAME,ARG) \
+  (DEBUG("fd%d.ioctl(0x%08x,0x%08x)",F,NAME,ARG), v4l2_ioctl(F,NAME,ARG))
+#define WIOCTL( F,NAME,ARG) \
+  (IOCTL(F,NAME,ARG)<0 && (error("ioctl %s: %s",#NAME,strerror(errno)),1))
+#define WIOCTL2(F,NAME,ARG) \
+  (IOCTL(F,NAME,ARG)<0 && (error("ioctl %s: %s",#NAME,strerror(errno)), RAISE("ioctl error"), 0))
+
 /* **************************************************************** */
 
 struct Frame {uint8 *p; size_t n;};
@@ -135,14 +157,24 @@
 		else            fd =      open(filename.data(),0);
 		if (fd<0) RAISE("can't open device '%s': %s",filename.data(),strerror(errno));
 		f=0;
-		initialize2();
+		//WIOCTL(fd, VIDIOCGCAP, &cap);
+		WIOCTL(fd, VIDIOC_QUERYCAP, &cap);
+		//_0_size(0,0,cap.maxheight,cap.maxwidth);
+		_0_size(0,0,240,320);
+		t_symbol *card = safe_gensym((char *)cap.card,sizeof(cap.card));
+		//t_symbol *bus = safe_gensym((char *)cap.bus_info,sizeof(cap.bus_info));
+		//this->name = symprintf("%s_on_%s",card->s_name,bus->s_name);
+		this->name = card;
+		//WIOCTL(fd, VIDIOCGPICT,&vp);
+		//int checklist[] = {V4L2_PIX_FMT_RGB24,V4L2_PIX_FMT_YVU420};
+		_0_colorspace(0,0,gensym("rgb"));
+		_0_channel(0,0,0);
 	}
 	void frame_finished (uint8 *buf);
 
 	void alloc_image ();
 	void dealloc_image ();
 	void frame_ask ();
-	void initialize2 ();
 	~FormatV4L2 () {
 		if (image) dealloc_image();
 		close(fd); fd=-1; /* can be v4l2_close, not same as in formats.cxx */
@@ -171,16 +203,6 @@
 
 	\decl 0 get (t_symbol *s=0);
 };
-
-#define DEBUG(args...) 42
-//#define DEBUG(args...) post(args)
-
-#define  IOCTL( F,NAME,ARG) \
-  (DEBUG("fd%d.ioctl(0x%08x,0x%08x)",F,NAME,ARG), v4l2_ioctl(F,NAME,ARG))
-#define WIOCTL( F,NAME,ARG) \
-  (IOCTL(F,NAME,ARG)<0 && (error("ioctl %s: %s",#NAME,strerror(errno)),1))
-#define WIOCTL2(F,NAME,ARG) \
-  (IOCTL(F,NAME,ARG)<0 && (error("ioctl %s: %s",#NAME,strerror(errno)), RAISE("ioctl error"), 0))
 
 \def 0 get (t_symbol *s=0) {
 	FObject::_0_get(argc,argv,s);
@@ -473,32 +495,6 @@
 \def uint16 white_blue()       {return v4l2_get_control(fd,V4L2_CID_RED_BALANCE);}
 \def 0 white_blue(uint16 white_blue)  {v4l2_set_control(fd,V4L2_CID_RED_BALANCE,white_blue);}
 
-static t_symbol *mangle (char *s, int n) {
-	int i; char buf[n+1]; memcpy(buf,s,n); buf[n]=0;
-	for (i=n-1; buf[i] && !isspace(buf[i]); i--) buf[i]=0;
-	for (i=0; buf[i]; i++) {
-		if (isspace(buf[i])) buf[i]='_';
-		if (buf[i]=='(') buf[i]='[';
-		if (buf[i]==')') buf[i]=']';
-	}
-	return gensym(buf);
-}
-
-void FormatV4L2::initialize2 () {
-	//WIOCTL(fd, VIDIOCGCAP, &cap);
-	WIOCTL(fd, VIDIOC_QUERYCAP, &cap);
-	//_0_size(0,0,cap.maxheight,cap.maxwidth);
-	_0_size(0,0,240,320);
-	t_symbol *card = mangle((char *)cap.card,sizeof(cap.card));
-	//t_symbol *bus = mangle((char *)cap.bus_info,sizeof(cap.bus_info));
-	//this->name = symprintf("%s_on_%s",card->s_name,bus->s_name);
-	this->name = card;
-	//WIOCTL(fd, VIDIOCGPICT,&vp);
-	//int checklist[] = {V4L2_PIX_FMT_RGB24,V4L2_PIX_FMT_YVU420};
-	_0_colorspace(0,0,gensym("rgb"));
-	_0_channel(0,0,0);
-}
-
 \end class FormatV4L2 {install_format("#io.v4l2",4,"");}
 void startup_v4l2 () {
 	\startall

Modified: trunk/src/videodev.cxx
==============================================================================
--- trunk/src/videodev.cxx (original)
+++ trunk/src/videodev.cxx Sun May  2 22:56:52 2010
@@ -201,6 +201,12 @@
 	return gensym(buf);
 }
 
+#define DEBUG(args...) 42
+//#define DEBUG(args...) post(args)
+#define  IOCTL( F,NAME,ARG) (DEBUG("fd%d.ioctl(0x%08x,0x%08x)",F,NAME,ARG), ioctl(F,NAME,ARG))
+#define WIOCTL( F,NAME,ARG) (IOCTL(F,NAME,ARG)<0 && (error("%s: ioctl %s: %s",__FUNCTION__,#NAME,strerror(errno)),1))
+#define WIOCTL2(F,NAME,ARG) (IOCTL(F,NAME,ARG)<0 && (RAISE("%s: ioctl %s: %s",__FUNCTION__,#NAME,strerror(errno)), RAISE("ioctl error"), 0))
+
 /* **************************************************************** */
 
 \class FormatVideoDev : Format {
@@ -226,21 +232,23 @@
 		has_tuner=false;
 		has_norm=false;
 		image=0;
-		//f = fopen(filename.data(),"r+");
-		//if (!f) RAISE("can't open device '%s': %s",filename.data(),strerror(errno));
-		//fd = fileno(f);
-		if (libv4l)
-			fd = v4l1_open(filename.data(),O_RDWR);
-		else 	fd =      open(filename.data(),O_RDWR);
+		if (libv4l) fd = v4l1_open(filename.data(),O_RDWR);
+		else 	    fd =      open(filename.data(),O_RDWR);
 		if (fd<0) RAISE("can't open device '%s': %s",filename.data(),strerror(errno));
-		initialize2();
+		WIOCTL(fd, VIDIOCGCAP, &vcaps);
+		dim = new Dim(0,0,0);
+		name = safe_gensym(vcaps.name);
+		WIOCTL(fd, VIDIOCGPICT,&vp);
+		detect_palettes();
+		_0_size(0,0,vcaps.maxheight,vcaps.maxwidth);
+		_0_colorspace(0,0,gensym("rgb"));
+		_0_channel(0,0,0);
 	}
 	void frame_finished (uint8 *buf);
 
 	void alloc_image ();
 	void dealloc_image ();
 	void frame_ask ();
-	void initialize2 ();
 	~FormatVideoDev () {
 		if (image) dealloc_image();
 		close(fd); // wtf
@@ -275,14 +283,24 @@
 	\attr t_symbol *name;
 
 	\decl 0 get (t_symbol *s=0);
+	
+	void detect_palettes () {
+		palettes=0;
+		std::ostringstream supp;
+		supp << "camera supports palettes :";
+#if 1 /* keep this at "1" most of the time, because at "0" it crashes certain camera drivers ! */
+		int checklist[] = {VIDEO_PALETTE_RGB565,VIDEO_PALETTE_RGB24,VIDEO_PALETTE_RGB32,VIDEO_PALETTE_YUYV,VIDEO_PALETTE_YUV420P};
+		for (size_t i=0; i<sizeof(checklist)/sizeof(*checklist); i++) {
+			int p = checklist[i];
+#else
+		for (size_t p=1; p<17; p++) {
+#endif
+			vp.palette = p;
+			if (ioctl(fd, VIDIOCSPICT,&vp)>=0) {palettes |= 1<<p; supp << " " << p;}
+		}
+		post(supp);
+	}
 };
-
-#define DEBUG(args...) 42
-//#define DEBUG(args...) post(args)
-
-#define  IOCTL( F,NAME,ARG) (DEBUG("fd%d.ioctl(0x%08x,0x%08x)",F,NAME,ARG), ioctl(F,NAME,ARG))
-#define WIOCTL( F,NAME,ARG) (IOCTL(F,NAME,ARG)<0 && (error("%s: ioctl %s: %s",__FUNCTION__,#NAME,strerror(errno)),1))
-#define WIOCTL2(F,NAME,ARG) (IOCTL(F,NAME,ARG)<0 && (RAISE("%s: ioctl %s: %s",__FUNCTION__,#NAME,strerror(errno)), RAISE("ioctl error"), 0))
 
 \def 0 get (t_symbol *s=0) {
 	// this is abnormal for a get-function
@@ -634,30 +652,6 @@
 \def int compression()     {PWC(0) int compression;     WIOCTL(fd, VIDIOCPWCSCQUAL,    &compression    ); return compression;    }
 \def 0 compression(int compression) {PWC()              WIOCTL(fd, VIDIOCPWCGCQUAL,    &compression    );}
 
-void FormatVideoDev::initialize2 () {
-	WIOCTL(fd, VIDIOCGCAP, &vcaps);
-	dim = new Dim(0,0,0);
-	name = safe_gensym(vcaps.name);
-	WIOCTL(fd, VIDIOCGPICT,&vp);
-	palettes=0;
-	std::ostringstream supp;
-	supp << "camera supports palettes :";
-#if 1 /* keep this at "1" most of the time, because at "0" it crashes certain camera drivers ! */
-	int checklist[] = {VIDEO_PALETTE_RGB565,VIDEO_PALETTE_RGB24,VIDEO_PALETTE_RGB32,VIDEO_PALETTE_YUYV,VIDEO_PALETTE_YUV420P};
-	for (size_t i=0; i<sizeof(checklist)/sizeof(*checklist); i++) {
-		int p = checklist[i];
-#else
-	for (size_t p=1; p<17; p++) {
-#endif
-		vp.palette = p;
-		if (ioctl(fd, VIDIOCSPICT,&vp)>=0) {palettes |= 1<<p; supp << " " << p;}
-	}
-	post(supp);
-	_0_size(0,0,vcaps.maxheight,vcaps.maxwidth);
-	_0_colorspace(0,0,gensym("rgb"));
-	_0_channel(0,0,0);
-}
-
 \end class FormatVideoDev {install_format("#io.videodev",4,"");}
 void startup_videodev () {
 	\startall



More information about the Gridflow-cvs mailing list