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

Monty xiphmont at xiph.org
Tue Nov 6 22:46:45 PST 2001



xiphmont    01/11/06 22:46:45

  Modified:    .        libsnatch.c snatch.pl
  Log:
  alert dialogs, successful complete child throwing

Revision  Changes    Path
1.7       +30 -10    snatch/libsnatch.c

Index: libsnatch.c
===================================================================
RCS file: /usr/local/cvsroot/snatch/libsnatch.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- libsnatch.c	2001/11/07 05:13:46	1.6
+++ libsnatch.c	2001/11/07 06:46:44	1.7
@@ -104,6 +104,11 @@
   return(audio_fmts[0]);
 }
 
+static char *nstrdup(char *s){
+  if(s)return strdup(s);
+  return NULL;
+}
+
 /* 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 */
@@ -129,6 +134,8 @@
 
 static pthread_cond_t event_cond=PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t event_mutex=PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t display_cond=PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t display_mutex=PTHREAD_MUTEX_INITIALIZER;
 
 void *event_thread(void *dummy){
   if(debug)
@@ -153,12 +160,17 @@
     fprintf(stderr,"    ...: Backchannel thread %lx reporting for duty!\n",
             (unsigned long)pthread_self());
 
+  pthread_mutex_lock(&display_mutex);
+  if(!Xdisplay)
+    pthread_cond_wait(&display_cond,&display_mutex);
+  pthread_mutex_unlock(&display_mutex);
+
   while(1){
     char rq;
     size_t ret=fread(&rq,1,1,backchannel_fd);
     short length;
     char *buf=NULL;
-    
+
     if(ret<=0){
       fprintf(stderr,"**ERROR: Backchannel lost!  exit(1)ing...\n");
       exit(1);
@@ -205,8 +217,8 @@
             openfile=buf;
             break;
           case 'F':
-	    if(outfile)free(outfile);
-	    outfile=buf;
+	    if(outpath)free(outpath);
+	    outpath=buf;
             break;
           case 'D':
             if(audioname)free(audioname);
@@ -265,13 +277,13 @@
     xlib_xopen=get_me_symbol("XOpenDisplay");
 
     /* output path? */
-    outpath=strdup(getenv("SNATCH_OUTPUT_PATH"));
+    outpath=nstrdup(getenv("SNATCH_OUTPUT_PATH"));
     if(!outpath){
       if(debug)
         fprintf(stderr,
                 "----env: SNATCH_OUTPUT_PATH\n"
                 "           not set. Using current working directory.\n");
-      outpath=strdup(".");
+      outpath=nstrdup(".");
     }else{
       if(debug)
         fprintf(stderr,
@@ -280,13 +292,13 @@
     }
 
     /* audio device? */
-    audioname=strdup(getenv("SNATCH_AUDIO_DEVICE"));
+    audioname=nstrdup(getenv("SNATCH_AUDIO_DEVICE"));
     if(!audioname){
       if(debug)
         fprintf(stderr,
                 "----env: SNATCH_AUDIO_DEVICE\n"
                 "           not set. Using default (/dev/dsp*).\n");
-      audioname=strdup("/dev/dsp*");
+      audioname=nstrdup("/dev/dsp*");
     }else{
       if(debug)
         fprintf(stderr,
@@ -348,7 +360,7 @@
     
     if(Xname[0]==':'){
       /* local display */
-      Xunix_socket=strdup("/tmp/.X11-unix/X                          ");
+      Xunix_socket=nstrdup("/tmp/.X11-unix/X                          ");
       sprintf(Xunix_socket+16,"%d",atoi(Xname+1));
 
       if(debug)
@@ -357,7 +369,7 @@
                 "         local AF_UNIX socket %s\n",Xunix_socket);
 
     }else if(Xname[0]=='/'){
-      Xunix_socket=strdup(Xname);
+      Xunix_socket=nstrdup(Xname);
 
       if(debug)
         fprintf(stderr,
@@ -593,6 +605,8 @@
 
     StopClientConnection();
     StopServerConnection();
+    (*libc_close)(STDERR_FILENO);
+
   }
   
   return(ret);
@@ -702,12 +716,18 @@
 }
 
 Display *XOpenDisplay(const char *d){
+  initialize();
+
   if(!XInitThreads()){
     fprintf(stderr,"**ERROR: Unable to set multithreading support in Xlib.\n"
             "         exit(1)ing...\n\n");
     exit(1);
   }
-  return(Xdisplay=(*xlib_xopen)(d));
+  Xdisplay=(*xlib_xopen)(d);
+  pthread_mutex_lock(&display_mutex);
+  pthread_cond_signal(&display_cond);
+  pthread_mutex_unlock(&display_mutex);
+  return(Xdisplay);
 }
 
 static void queue_task(void (*f)(void)){

1.6       +40 -19    snatch/snatch.pl

Index: snatch.pl
===================================================================
RCS file: /usr/local/cvsroot/snatch/snatch.pl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- snatch.pl	2001/11/07 05:13:46	1.5
+++ snatch.pl	2001/11/07 06:46:44	1.6
@@ -281,6 +281,8 @@
 
 
 sub ThrowRealPlayer{
+    $SIG{CHLD}='IGNORE';
+
     Status("Starting RealPlayer...");
     # set up the environment
 
@@ -296,7 +298,7 @@
     }
 
     die "pipe call failed unexpectedly: $!" unless pipe REAL_STDERR,WRITEH;
-    $realpid=open3("<&STDIN",">&STDOUT",">&WRITEH", at list[0]);
+    $realpid=open3("STDIN",">&STDOUT",">&WRITEH", at list[0]);
     close WRITEH;
 
     # a select loop until we have the socket accepted
@@ -316,6 +318,7 @@
             $time--;
             Status("Waiting for rendevous... [$time]");
         }else{
+	    $toplevel->update();
             if(vec($rout,fileno(REAL_STDERR),1)){
                 $bytes=sysread REAL_STDERR, my$scalar, 4096;
                 $stderr_output.=$scalar;
@@ -328,14 +331,12 @@
                           "attempt:",
                           $stderr_output);
 
-		    print "EOF on REAL_STDERR!\n";
                     return;
                 }
             }
             if(vec($rout,fileno(LISTEN_SOCK),1)){
                 # socket has a request
                 $status=accept(COMM_SOCK,LISTEN_SOCK);
-		Status("libsnatch contacted");
                 $comm_ready=1;
                 $time=0;
             }
@@ -344,10 +345,18 @@
 
 
     # configure
+    Status("RealPlayer started...");
+    $window_active->configure(state=>normal);
+    $window_timer->configure(state=>normal);
+    $window_inactive->configure(state=>normal);
+
+    $window_amute->configure(state=>normal);
+    $window_vmute->configure(state=>normal);
+    $toplevel->fileevent(REAL_STDERR,'readable'=>[sub{ReadStderr();}]);
     send_string("F",$CONFIG{'OUTPUT_PATH'});
     send_string("D",$CONFIG{'AUDIO_DEVICE'});
-    Robot_Audio($global_audio_setting);
-    Robot_Video($global_video_setting);
+    Robot_Active();
+
 }
 
 sub BindSocket{
@@ -389,6 +398,7 @@
 
 sub Shutdown{
 # save the config/history
+    Robot_Exit();
     ReleaseSocket();
 
     die $! unless open CFILE, ">$configfile".".tmp";
@@ -451,8 +461,6 @@
     my $exitcode=join "",("Kx",pack ("S",4));
     syswrite COMM_SOCK,$playcode;
     close COMM_SOCK;
-    Status("Waiting for RealPlayer exit...");
-    waitpid $realpid, 0
 }
 
 sub Robot_Active{
@@ -462,18 +470,18 @@
     send_string("O","");
     send_string("L","");
     syswrite COMM_SOCK,'A';
-    Amute($global_audio_setting);
-    Vmute($global_video_setting);
-    Status("Recording ACTIVE: Idle/Nominal");
+    Robot_Audio($global_audio_setting);
+    Robot_Video($global_video_setting);
+    Status("Active/Nominal");
 }
 
-sub Robot_Inctive{
+sub Robot_Inactive{
     send_string("U","");
     send_string("P","");
     send_string("O","");
     send_string("L","");
-    Amute($global_audio_setting);
-    Vmute($global_video_setting);
+    Robot_Audio($global_audio_setting);
+    Robot_Video($global_video_setting);
     syswrite COMM_SOCK,'I';
     Status("Recording off");
 }
@@ -483,8 +491,8 @@
     send_string("P","");
     send_string("O","");
     send_string("L","");
-    Amute($global_audio_setting);
-    Vmute($global_video_setting);
+    Robot_Audio($global_audio_setting);
+    Robot_Video($global_video_setting);
     syswrite COMM_SOCK,'T';
     Status("Inactive [Timer]");
 }
@@ -717,11 +725,24 @@
     $modal->transient($toplevel);
     $modal_exit->configure(-command=>[sub{$modal->destroy();undef $modal}]);
 }
-
-
 
-
-
+sub ReadStderr{
+    $bytes=sysread REAL_STDERR, my$scalar, 4096;
+    if($bytes==0){
+	Alert("RealPlayer unexpectedly exited!","Attempting to start a new copy...\n");
+	$toplevel->fileevent(REAL_STDERR,'readable' => ''); 
+	close REAL_STDERR;
+	ThrowRealPlayer();
+    }
+
+    if($scalar=~/shut down X/){
+	$toplevel->fileevent(REAL_STDERR,'readable' => ''); 
+	close REAL_STDERR;
+	close COMM_SOCK;
+      Tk::exit(0);
+    }	
+    print $scalar;
+}
 
 
 

--- >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