[xiph-cvs] cvs commit: snatch libsnatch.c snatch.pl x11.c

Monty xiphmont at xiph.org
Sat Nov 10 05:05:09 PST 2001



xiphmont    01/11/10 05:05:09

  Modified:    .        libsnatch.c snatch.pl x11.c
  Log:
  'twould appear it all works.  Capture util ready for pounding.
  
  Monty

Revision  Changes    Path
1.15      +47 -18    snatch/libsnatch.c

Index: libsnatch.c
===================================================================
RCS file: /usr/local/cvsroot/snatch/libsnatch.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- libsnatch.c	2001/11/10 10:57:39	1.14
+++ libsnatch.c	2001/11/10 13:05:08	1.15
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
+#include <errno.h>
 #include <dlfcn.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -93,14 +94,10 @@
 static void (*QueuedTask)(void);
 
 static int outfile_fd=-1;
-static FILE *outfile_file=NULL;
 
 static void CloseOutputFile();
 static void OpenOutputFile();
 
-#include "x11.c" /* yeah, ugly, but I don't want to leak symbols. 
-		    Oh and I'm lazy. */
-
 static char *audio_fmts[]={"unknown format",
                           "8 bit mu-law",
                           "8 bit A-law",
@@ -126,6 +123,34 @@
   return NULL;
 }
 
+static int gwrite(int fd, void *buf, int n){
+  while(n){
+    int ret=(*libc_write)(fd,buf,n);
+    if(ret<0){
+      if(errno==EAGAIN)
+	ret=0;
+      else
+	return(ret);
+    }
+    buf+=ret;
+    n-=ret;
+  }
+  return(0);
+}
+
+static void bigtime(long *seconds,long *micros){
+  static struct timeval   tp;
+    
+  (void)gettimeofday(&tp, (struct timezone *)NULL);
+  *seconds=tp.tv_sec;
+  *micros=tp.tv_usec;
+
+}
+
+#include "x11.c" /* yeah, ugly, but I don't want to leak symbols. 
+		    Oh and I'm lazy. */
+
+
 /* although RealPlayer is both multiprocess and multithreaded, we
 don't lock because we assume only one thread/process will be mucking
 with a specific X drawable or audio device at a time */
@@ -531,10 +556,15 @@
     if(count>0 && snatch_active==1){
       if(outfile_fd<0)OpenOutputFile();
       if(outfile_fd>=0){ /* always be careful */
-
-	  fprintf(outfile_file,"AUDIO %d %d %d %d:",audio_channels,
-		  audio_rate,audio_format,count);
-	  fwrite(buf,1,count,outfile_file);
+	char cbuf[80];
+	long a,b;
+	int len;
+
+	bigtime(&a,&b);
+	len=sprintf(cbuf,"AUDIO %ld %ld %d %d %d %d:",a,b,audio_channels,
+		    audio_rate,audio_format,count);
+	gwrite(outfile_fd,cbuf,len);
+	gwrite(outfile_fd,(void *)buf,count);
         
       }
     }
@@ -652,7 +682,6 @@
   if(outfile_fd!=-2){
     if(!strcmp(outpath,"-")){
       outfile_fd=STDOUT_FILENO;
-      outfile_file=stdout;
       if(debug)fprintf(stderr,"    ...: Capturing to stdout\n");
     }else{
       struct stat buf;
@@ -683,11 +712,14 @@
                     video_height);
           }
         }else{
-	  sprintf(buf2,"%s/%s_%s%dHz_A.snatch",
-		  outpath,
-		  buf1,
-		  (audio_channels==1?"mono":"stereo"),
-		  audio_rate);
+	  if(audio_channels){
+	    sprintf(buf2,"%s/%s_%s%dHz_A.snatch",
+		    outpath,
+		    buf1,
+		    (audio_channels==1?"mono":"stereo"),
+		    audio_rate);
+	  }else
+	    return;
         }
         
         outfile_fd=(*libc_open)(buf2,O_RDWR|O_CREAT|O_APPEND,0770);
@@ -697,7 +729,6 @@
           outfile_fd=-2;
         }else{
           if(debug)fprintf(stderr,"    ...: Capturing to file %s\n",buf2);
-	  outfile_file=fdopen(outfile_fd,"w+");
         }
         
       }else{
@@ -708,7 +739,6 @@
           outfile_fd=-2;
         }else{
           if(debug)fprintf(stderr,"    ...: Capturing to file %s\n",outpath);
-	  outfile_file=fdopen(outfile_fd,"w+");
         }
       }
     }
@@ -723,8 +753,7 @@
 
     if(debug)fprintf(stderr,"    ...: Capture stopped.\n");
     if(outfile_fd!=STDOUT_FILENO)
-      fclose(outfile_file);
+      close(outfile_fd);
     outfile_fd=-1;
-    outfile_file=NULL;
   }
 }

1.23      +13 -5     snatch/snatch.pl

Index: snatch.pl
===================================================================
RCS file: /usr/local/cvsroot/snatch/snatch.pl,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- snatch.pl	2001/11/10 11:12:27	1.22
+++ snatch.pl	2001/11/10 13:05:08	1.23
@@ -1029,17 +1029,25 @@
               "Hopefully self explanatory...\n");
     }
 
+    if($scalar=~/bit ZPixmap/){
+	Alert("ERROR: This X server is not using 24/32 bit visuals!",
+	      "Right now, Snatch is still new ad as such only supports the highest".
+	      " bitdepth visuals.  These visuals give the best quality and are thus".
+	      " recommended strongly for capture.  Other visuals will eventually be".
+	      " supported as well, but they won't work for now.\n");
+    }
+
+    if($scalar=~/Capture stopped/){
+	$recording_active=0;
+	$recording_pending=0;
+    }
+
     if($scalar=~/Capturing/){
         $recording_active=time();
         $recording_pending=0;
         if(!defined($timer_callback)){
             $timer_callback=$toplevel->repeat(1000,[sub{main::TimerWatch();}]);
         }
-    }
-
-    if($scalar=~/Capture stopped/){
-	$recording_active=0;
-	$recording_pending=0;
     }
 
     print $scalar if($CONFIG{DEBUG} eq 'yes');

1.16      +239 -123  snatch/x11.c

Index: x11.c
===================================================================
RCS file: /usr/local/cvsroot/snatch/x11.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- x11.c	2001/11/10 10:57:39	1.15
+++ x11.c	2001/11/10 13:05:08	1.16
@@ -54,6 +54,7 @@
 static void queue_task(void (*f)(void));
 static void initialize();
 static int videocount=0;
+static int depthwarningflag;
 
 static void XGetGeometryRoot(unsigned long id,int *root_x,int *root_y){
   int x=0;
@@ -149,6 +150,7 @@
   event.window=rpplay_window;
   event.width=rpplay_width;
   event.height=rpplay_height;
+  logo_y=-1;
 
   XSendEvent(Xdisplay,(Window)rpplay_window,0,0,(XEvent *)&event);
 }
@@ -505,6 +507,8 @@
   return(ret);
 }
 
+static char *workbuffer;
+static long worksize;
 
 int XPutImage(Display *display,Drawable id,GC gc,XImage *image,
               int src_x,int src_y,
@@ -512,18 +516,69 @@
               unsigned int d_width, 
               unsigned int d_height){
 
-  int ret;
+  int ret=0;
 
   if(snatch_active==1 && id==rpvideo_window){
     videocount++;
     if(videocount>5 && outfile_fd<0)OpenOutputFile();
-    if(outfile_fd>=0){
+    /* only do 24 bit zPixmaps for now */
 
-
-
+    if(image->format==2 && image->depth>16 && image->depth<=24){
+      if(outfile_fd>=0){
+	char cbuf[80];
+	int bpp=image->bytes_per_line/image->width;
+	long a,b,n=image->width*image->height*3;
+	int i,j,len;
+	
+	bigtime(&a,&b);
+	len=sprintf(cbuf,"VIDEO %ld %ld %d %d %ld:",a,b,video_width,
+		    video_height,n);
+	gwrite(outfile_fd,cbuf,len);
+	
+	if(worksize<n){
+	  if(worksize==0)
+	    workbuffer=malloc(n);
+	  else
+	    workbuffer=realloc(workbuffer,n);
+	  worksize=n;
+	}
+	
+	if(image->byte_order){      
+	  char *work=workbuffer;
+	  char *ptr=image->data;
+	  for(i=0;i<image->height;i++){
+	    for(j=0;j<image->width*bpp;){
+	      j++;
+	      *work++=ptr[j++];
+	      *work++=ptr[j++];
+	      *work++=ptr[j++];
+	    }
+	    ptr+=image->bytes_per_line;
+	  }
+	}else{
+	  char *work=workbuffer;
+	  char *ptr=image->data;
+	  for(i=0;i<image->height;i++){
+	    for(j=0;j<image->width*bpp;j+=4){
+	      *work++=ptr[j+2];
+	      *work++=ptr[j+1];
+	      *work++=ptr[j];
+	    }
+	    ptr+=image->bytes_per_line;
+	  }
+	}
+	  	  
+	gwrite(outfile_fd,workbuffer,n);
 
+      }
+    }else{
+      if(!depthwarningflag)
+	fprintf(stderr,"**ERROR: Right now, Snatch only works with 17-24 bit ZPixmap\n"
+		"         based visuals packed into 8bpp 32 bit units.  This\n"
+		"         X server is not in a 24/32 bit mode. \n");
+      depthwarningflag=1;
+    }
 
-    }    
   }
 
   /* Subvert the Real sign on logo; paste the Snatch logo in.
@@ -536,160 +591,221 @@
   if(id==rpplay_window){
     int width=image->width;
     int height=image->height;
-    int depth=image->depth;
     int endian=image->byte_order;
 
-    char *ptr=image->data;
-    long i,j,k;
-    
-    /* after a resize, look where to put the logo... */
-    if(logo_y==-1 && height==rpplay_height && width==rpplay_width){
-      int test;      
-
-      play_blackupper=42;
-      play_blacklower=-1;
-      play_blackleft=-1;
-      play_blackright=-1;
+    if(image->format==2 && image->depth>16 && image->depth<=24){
       
-      for(play_blackleft=20;play_blackleft>0;play_blackleft--)
-	if(ptr[play_blackupper*width*4+play_blackleft*4+1]!=0)break;
-      play_blackleft++;
-      for(play_blackright=width-20;play_blackright<width;play_blackright++)
-	if(ptr[play_blackupper*width*4+play_blackright*4+1]!=0)break;
-
-      if(play_blacklower==-1){
-	play_blacklower=42;
-	for(;play_blacklower<height;play_blacklower++)
-	  if(ptr[play_blacklower*width*4+81]!=0)break;
-	
-	if(play_blacklower==height)play_blacklower=-1;
-      }
+      char *ptr=image->data;
+      long i,j,k;
       
-      for(test=play_blackupper;test<height;test++)
-	if(ptr[test*width*4+(width/2*4)+1]!=0)break;
-      
-      if(test<height && test+snatchheight<play_blacklower){
-	logo_y=test;
+      /* after a resize, look where to put the logo... */
+      if(logo_y==-1 && height==rpplay_height && width==rpplay_width){
+	int test;      
         
-	/* verify enough room to display... */
-	if(test<50){
-	  long blacklower;
-	  
-	  for(blacklower=test;blacklower<height;blacklower++)
-	    if(ptr[blacklower*width*4+(20*4)+1]!=0)break;
+	play_blackupper=42;
+	play_blacklower=-1;
+	play_blackleft=-1;
+	play_blackright=-1;
+	
+	for(play_blackleft=20;play_blackleft>0;play_blackleft--)
+	  if(ptr[play_blackupper*width*4+play_blackleft*4+1]!=0)break;
+	play_blackleft++;
+	for(play_blackright=width-20;play_blackright<width;play_blackright++)
+	  if(ptr[play_blackupper*width*4+play_blackright*4+1]!=0)break;
+	
+	if(play_blacklower==-1){
+	  play_blacklower=42;
+	  for(;play_blacklower<height;play_blacklower++)
+	    if(ptr[play_blacklower*width*4+81]!=0)break;
           
-	  if(blacklower-test<snatchheight)logo_y=-1;
+	  if(play_blacklower==height)play_blacklower=-1;
         }
-      }
-    }
-      
-    /* blank background */
-    {
-      unsigned char *bptr;
-      
-      if(snatch_active==1)
-	bptr=snatchppm;
-      else
-	bptr=waitppm;
-      
-      if(endian){
-	for(i=play_blackupper;i<play_blacklower;i++)
-	  for(j=play_blackleft;j<play_blackright;j++){
-	    ptr[i*width*4+j*4]=0x00;
-	    ptr[i*width*4+j*4+1]=bptr[0];
-	    ptr[i*width*4+j*4+2]=bptr[1];
-	    ptr[i*width*4+j*4+3]=bptr[2];
-	  }
-      }else{
-	for(i=play_blackupper;i<play_blacklower;i++)
-	  for(j=play_blackleft;j<play_blackright;j++){
-	    ptr[i*width*4+j*4+3]=0x00;
-	    ptr[i*width*4+j*4+2]=bptr[0];
-	    ptr[i*width*4+j*4+1]=bptr[1];
-	    ptr[i*width*4+j*4]=bptr[2];
+	
+	for(test=play_blackupper;test<height;test++)
+	  if(ptr[test*width*4+(width/2*4)+1]!=0)break;
+	
+	if(test<height && test+snatchheight<play_blacklower){
+	  logo_y=test;
+	  
+	  /* verify enough room to display... */
+	  if(test<50){
+	    long blacklower;
+	    
+	    for(blacklower=test;blacklower<height;blacklower++)
+	      if(ptr[blacklower*width*4+(20*4)+1]!=0)break;
+	    
+	    if(blacklower-test<snatchheight)logo_y=-1;
           }
+	}
       }
-    }
       
-    /* paint logo */
-    if(logo_y!=-1){
-      unsigned char *logo;
-      int logowidth;
-      int logoheight;
-
-      switch(snatch_active){
-      case 0:
-	logo=realppm;
-	logowidth=realwidth;
-	logoheight=realheight;
-	break;
-      case 1:
-	logo=snatchppm;
-	logowidth=snatchwidth;
-	logoheight=snatchheight;
-	break;
-      case 2:
-	logo=waitppm;
-	logowidth=snatchwidth;
-	logoheight=snatchheight;
-	break;
-      }
-
-      for(i=0;i<logoheight;i++){
-	if(i+logo_y<height){
-	  char *snatch;
-	  char *real;
+      /* blank background */
+      if(x==0 && y==0 && d_width==rpplay_width && d_height==rpplay_height){
+	unsigned char *bptr;
+	
+	if(snatch_active==1)
+	  bptr=snatchppm;
+	else
+	  bptr=waitppm;
+	
+	if(endian){
+	  for(i=play_blackupper;i<play_blacklower;i++)
+	    for(j=play_blackleft;j<play_blackright;j++){
+	      ptr[i*width*4+j*4]=0x00;
+	      ptr[i*width*4+j*4+1]=bptr[0];
+	      ptr[i*width*4+j*4+2]=bptr[1];
+	      ptr[i*width*4+j*4+3]=bptr[2];
+	    }
+	}else{
+	  for(i=play_blackupper;i<play_blacklower;i++)
+	    for(j=play_blackleft;j<play_blackright;j++){
+	      ptr[i*width*4+j*4+3]=0x00;
+	      ptr[i*width*4+j*4+2]=bptr[0];
+	      ptr[i*width*4+j*4+1]=bptr[1];
+	      ptr[i*width*4+j*4]=bptr[2];
+	    }
+	}
+	
+	
+	/* paint logo */
+	if(logo_y!=-1){
+	  unsigned char *logo;
+	  int logowidth;
+	  int logoheight;
           
-	  real=ptr+width*4*(i+logo_y)+(rpplay_width-logowidth)*2;
-	  snatch=logo+logowidth*3*i;
+	  switch(snatch_active){
+	  case 0:
+	    logo=realppm;
+	    logowidth=realwidth;
+	    logoheight=realheight;
+	    break;
+	  case 1:
+	    logo=snatchppm;
+	    logowidth=snatchwidth;
+	    logoheight=snatchheight;
+	    break;
+	  case 2:
+	    logo=waitppm;
+	    logowidth=snatchwidth;
+	    logoheight=snatchheight;
+	    break;
+	  }
           
-	  if(endian){
-	    
-	    for(k=0,j=0;k<logowidth*3 && j<width*4;){
-	      real[++j]=snatch[k++];
-	      real[++j]=snatch[k++];
-	      real[++j]=snatch[k++];
-	      ++j;
+	  for(i=0;i<logoheight;i++){
+	    if(i+logo_y<height){
+	      char *snatch;
+	      char *real;
+	      
+	      real=ptr+width*4*(i+logo_y)+(rpplay_width-logowidth)/2*4;                                                                       /* not the same as *2 */
+	      snatch=logo+logowidth*3*i;
+	      
+	      if(endian){
+	      
+		for(k=0,j=0;k<logowidth*3 && j<width*4;){
+		  real[++j]=snatch[k++];
+		  real[++j]=snatch[k++];
+		  real[++j]=snatch[k++];
+		  ++j;
+		}
+		
+	      }else{
+		for(k=0,j=0;k<logowidth*3 && j<width*4;j+=4){
+		  real[j+2]=snatch[k++];
+		  real[j+1]=snatch[k++];
+		  real[j]=snatch[k++];
+		}
+	      }
             }
-	    
-	  }else{
-	    for(k=0,j=0;k<logowidth*3 && j<width*4;j+=4){
-	      real[j+2]=snatch[k++];
-	      real[j+1]=snatch[k++];
-	      real[j]=snatch[k++];
-	    }
           }
         }
       }
+    }else{
+      if(!depthwarningflag)
+	fprintf(stderr,"**ERROR: Right now, Snatch only works with 17-24 bit ZPixmap\n"
+		"         based visuals packed into 8bpp 32 bit units.  This\n"
+		"         X server is not in a 24/32 bit mode. \n");
+      depthwarningflag=1;
     }
   }
 
-  ret=(*xlib_xputimage)(display,id,gc,image,src_x,src_y,x,y,d_width,d_height);
+  if(!fake_videop)
+    ret=(*xlib_xputimage)(display,id,gc,image,src_x,src_y,x,y,d_width,d_height);
 
   return(ret);
 }
- 
+
 int XShmPutImage(Display *display,Drawable id,GC gc,XImage *image,
                  int src_x, int src_y, int dest_x, int dest_y,
                  unsigned int width, unsigned int height,
                  Bool send_event){
+  int ret=0;
 
-  int ret=(*xlib_xshmputimage)(display, id, gc, image, src_x, src_y,
-			       dest_x, dest_y, width, height, send_event);
+  if(!fake_videop)
+    ret=(*xlib_xshmputimage)(display, id, gc, image, src_x, src_y,
+			     dest_x, dest_y, width, height, send_event);
 
 
   if(snatch_active==1 && id==rpvideo_window){
     videocount++;
     if(videocount>5 && outfile_fd<0)OpenOutputFile();
-    if(outfile_fd>=0){
 
-
-
-
+    /* only do 24 bit zPixmaps for now */
+    if(image->format==2 && image->depth>16 && image->depth<=24){
+      if(outfile_fd>=0){
+	char cbuf[80];
+	int bpp=image->bytes_per_line/image->width;
+	long a,b,n=image->width*image->height*3;
+	int i,j,len;
+	
+	bigtime(&a,&b);
+	len=sprintf(cbuf,"VIDEO %ld %ld %d %d %ld:",a,b,video_width,
+		    video_height,n);
+	gwrite(outfile_fd,cbuf,len);
+	
+	if(worksize<n){
+	  if(worksize==0)
+	    workbuffer=malloc(n);
+	  else
+	    workbuffer=realloc(workbuffer,n);
+	  worksize=n;
+	}
+	
+	if(image->byte_order){      
+	  char *work=workbuffer;
+	  char *ptr=image->data;
+	  for(i=0;i<image->height;i++){
+	    for(j=0;j<image->width*bpp;){
+	      j++;
+	      *work++=ptr[j++];
+	      *work++=ptr[j++];
+	      *work++=ptr[j++];
+	    }
+	    ptr+=image->bytes_per_line;
+	  }
+	}else{
+	  char *work=workbuffer;
+	  char *ptr=image->data;
+	  for(i=0;i<image->height;i++){
+	    for(j=0;j<image->width*bpp;j+=4){
+	      *work++=ptr[j+2];
+	      *work++=ptr[j+1];
+	      *work++=ptr[j];
+	    }
+	    ptr+=image->bytes_per_line;
+	  }
+	}
+	gwrite(outfile_fd,workbuffer,n);
 
+      }
+    }else{
+      if(!depthwarningflag)
+	fprintf(stderr,"**ERROR: Right now, Snatch only works with 17-24 bit ZPixmap\n"
+		"         based visuals packed into 8bpp 32 bit units.  This\n"
+		"         X server is not in a 24/32 bit mode. \n");
+      depthwarningflag=1;
     }
   }
-  
+
   return(ret);
 }
 

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list