[xiph-cvs] cvs commit: vorbis-tools/ogg123 buffer.c ogg123.c

Stan Seibert volsung at xiph.org
Sun Oct 14 22:56:57 PDT 2001



volsung     01/10/14 22:56:57

  Modified:    ogg123   Tag: volsung_kc_20011011 buffer.c ogg123.c
  Log:
  - Fixed data stomping bug when buffer filled up
  - Initial pass at fixing signal handling.  Casual testing suggests that
    there are no glaring bugs.  I'll be going back through this logic more
    closely at a later data.

Revision  Changes    Path
No                   revision

No                   revision

1.7.2.23.2.2 +12 -2     vorbis-tools/ogg123/buffer.c

Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.7.2.23.2.1
retrieving revision 1.7.2.23.2.2
diff -u -r1.7.2.23.2.1 -r1.7.2.23.2.2
--- buffer.c	2001/10/14 05:42:51	1.7.2.23.2.1
+++ buffer.c	2001/10/15 05:56:55	1.7.2.23.2.2
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: buffer.c,v 1.7.2.23.2.1 2001/10/14 05:42:51 volsung Exp $
+ last mod: $Id: buffer.c,v 1.7.2.23.2.2 2001/10/15 05:56:55 volsung Exp $
 
  ********************************************************************/
 
@@ -74,7 +74,12 @@
 
   /* Block signals to this thread */
   sigfillset (&set);
-  //pthread_sigmask (SIG_SETMASK, &set, NULL);
+  sigaddset (&set, SIGINT);
+  sigaddset (&set, SIGTSTP);
+  sigaddset (&set, SIGCONT);
+  if (pthread_sigmask (SIG_BLOCK, &set, NULL) != 0)
+    DEBUG("pthread_sigmask failed");
+      
   
   /* Run the initialization function, if there is one */
   if (buf->init_func) 
@@ -194,6 +199,7 @@
 
           memmove (buf->buffer + buf_write_pos, data, write_size);
           buf->curfill += write_size;
+	  data += write_size;
           size -= write_size;
           DEBUG("writing chunk into buffer, curfill = %ld", buf->curfill);
         }
@@ -316,6 +322,10 @@
 
   /* End thread */
   pthread_cancel (buf->thread);
+  
+  /* Signal all the playback condition to wake stuff up */
+  COND_SIGNAL(buf->playback_cond);
+
   pthread_join (buf->thread, NULL);
 
   _buffer_thread_cleanup(buf);

1.39.2.30.2.2 +22 -21    vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.30.2.1
retrieving revision 1.39.2.30.2.2
diff -u -r1.39.2.30.2.1 -r1.39.2.30.2.2
--- ogg123.c	2001/10/14 05:42:51	1.39.2.30.2.1
+++ ogg123.c	2001/10/15 05:56:55	1.39.2.30.2.2
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.39.2.30.2.1 2001/10/14 05:42:51 volsung Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.30.2.2 2001/10/15 05:56:55 volsung Exp $
 
  ********************************************************************/
 
@@ -47,6 +47,7 @@
 
 char skipfile_requested;
 char exit_requested;
+char pause_requested;
 
 pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
 
@@ -562,10 +563,6 @@
         optind++;
     }
 
-    if (Options.outputOpts.buffer != NULL) {
-      buffer_wait_for_empty (Options.outputOpts.buffer);
-    }
-    
     exit (0);
 }
 
@@ -599,14 +596,8 @@
   switch (signo) {
   case SIGINT:
     exit_requested = 1;
-    if (Options.outputOpts.buffer)
-      buffer_thread_kill (Options.outputOpts.buffer);
-    break;
   case SIGTSTP:
-    if (Options.outputOpts.buffer) {
-      buffer_thread_pause (Options.outputOpts.buffer);
-    }
-    kill (getpid(), SIGSTOP);
+    pause_requested = 1;
     /* buffer_Pause (Options.outputOpts.buffer);
        buffer_WaitForPaused (Options.outputOpts.buffer);
        }
@@ -622,8 +613,6 @@
     */
     break;
   case SIGCONT:
-    if (Options.outputOpts.buffer)
-      buffer_thread_unpause (Options.outputOpts.buffer);
     break;
   default:
     psignal (signo, "Unknown signal caught");
@@ -709,7 +698,8 @@
     }
         
     exit_requested = 0;
-    
+    pause_requested = 0;
+
     while (!eof && !exit_requested) {
       int i;
       vorbis_comment *vc = ov_comment(&vf, -1);
@@ -774,15 +764,21 @@
         
         if (skipfile_requested) {
           eof = eos = 1;
-	  skipfile_requested = 0;
           signal(SIGALRM,signal_activate_skipfile);
           alarm(Options.playOpts.delay);
-	  if (Options.outputOpts.buffer) {
-	    buffer_thread_kill (Options.outputOpts.buffer);
-	  }
           break;
         }
 
+	if (pause_requested) {
+	  buffer_thread_pause (Options.outputOpts.buffer);
+	  kill (getpid(), SIGSTOP); /* We stall here */
+	  
+	  /* Done pausing */
+	  buffer_thread_unpause (Options.outputOpts.buffer);
+	  pause_requested = 0;
+	}
+
+
         old_section = current_section;
         ret =
           ov_read(&vf, (char *) convbuffer, sizeof(convbuffer), is_big_endian,
@@ -824,8 +820,13 @@
 
       /* Done playing this logical bitstream.  Now we cleanup. */
       if (Options.outputOpts.buffer) {
-	buffer_mark_eos (Options.outputOpts.buffer);
-	buffer_wait_for_empty (Options.outputOpts.buffer);
+	fprintf(stderr, "exit requested = %d", exit_requested);
+
+	if (!exit_requested && !skipfile_requested) {
+	  buffer_mark_eos (Options.outputOpts.buffer);
+	  buffer_wait_for_empty (Options.outputOpts.buffer);
+	}
+
         buffer_thread_kill (Options.outputOpts.buffer);
       }
 

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