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

Kenneth C. Arnold kcarnold at xiph.org
Mon Aug 13 13:41:53 PDT 2001



kcarnold    01/08/13 13:41:53

  Modified:    ogg123   Tag: kcarnold_work buffer.c buffer.h ogg123.c
                        ogg123.h
  Log:
  Ctrl-Z now stops buffer also. Made the condition waits in buffer.c be
  timed waits, because we can't signal a condition in a signal handler
  (for the unpause).

Revision  Changes    Path
No                   revision

No                   revision

1.7.2.15  +15 -15    vorbis-tools/ogg123/buffer.c

Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.7.2.14
retrieving revision 1.7.2.15
diff -u -r1.7.2.14 -r1.7.2.15
--- buffer.c	2001/08/13 01:48:38	1.7.2.14
+++ buffer.c	2001/08/13 20:41:51	1.7.2.15
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: buffer.c,v 1.7.2.14 2001/08/13 01:48:38 kcarnold Exp $
+ last mod: $Id: buffer.c,v 1.7.2.15 2001/08/13 20:41:51 kcarnold Exp $
 
  ********************************************************************/
 
@@ -49,6 +49,7 @@
 
 #define LOCK_MUTEX(mutex) do { DEBUG1("Locking mutex %s.", #mutex); pthread_mutex_lock (&(mutex)); } while (0)
 #define UNLOCK_MUTEX(mutex) do { DEBUG1("Unlocking mutex %s", #mutex); pthread_mutex_unlock(&(mutex)); } while (0) 
+#define TIMEDWAIT(cond, mutex, sec, nsec) do { struct timeval now; struct timespec timeout; gettimeofday(&now, NULL); timeout.tv_sec = now.tv_sec + sec; timeout.tv_nsec = now.tv_usec * 1000 + nsec; pthread_cond_timedwait (&(cond), &(mutex), &timeout); } while (0)
 
 void Prebuffer (buf_t * buf)
 {
@@ -78,7 +79,9 @@
 
 void PthreadCleanup (void *arg)
 {
+#if 0 
   buf_t *buf = (buf_t*) arg;
+#endif
   
   DEBUG0("PthreadCleanup");
 #if 0
@@ -121,10 +124,10 @@
     {
       LOCK_MUTEX (buf->SizeMutex);
     checkPlaying:
-      while (!(buf->StatMask & STAT_PLAYING) ||
+      while (!(buf->Playing) || 
              (buf->StatMask & STAT_PREBUFFERING)) {
         DEBUG1 ("waiting on !playing || prebuffering (stat=%d)", buf->StatMask);
-	pthread_cond_wait (&buf->DataReadyCondition, &buf->SizeMutex);
+	TIMEDWAIT (buf->DataReadyCondition, buf->SizeMutex, 1, 0);
       }
 
       DUMP_BUFFER_INFO(buf);
@@ -166,7 +169,7 @@
           pthread_exit (NULL);
         }
         DEBUG0 ("waiting on data ready");
-	pthread_cond_wait (&buf->DataReadyCondition, &buf->SizeMutex);
+	TIMEDWAIT (buf->DataReadyCondition, buf->SizeMutex, 1, 0);
         goto checkPlaying;
       }
 
@@ -298,7 +301,7 @@
   buf->size = size;
   buf->prebuffer = prebuffer;
   Prebuffer (buf);
-  buf->StatMask |= STAT_PLAYING;
+  buf->Playing = 1;
   buf->ReaderActive = buf->WriterActive = 1;
 
   /* pthreads initialization */
@@ -323,7 +326,7 @@
   /* wait on buffer overflow or ack for eos */
   while (buf->curfill + size > buf->size || buf->eos) {
     UnPrebuffer (buf);
-    pthread_cond_wait (&buf->DataReadyCondition, &buf->SizeMutex);
+    TIMEDWAIT (buf->DataReadyCondition, buf->SizeMutex, 1, 0);
   }
 
   DEBUG0("writing chunk into buffer");
@@ -394,7 +397,7 @@
   DEBUG0("signalled all");
   LOCK_MUTEX(buf->SizeMutex);
   while (buf->curfill > 0)
-    pthread_cond_wait (&buf->UnderflowCondition, &buf->SizeMutex);
+    TIMEDWAIT(buf->UnderflowCondition, buf->SizeMutex, 1, 0);
   DEBUG0("done waiting");
   UNLOCK_MUTEX (buf->SizeMutex);
   DEBUG0("buffer empty");
@@ -413,22 +416,19 @@
 
 void buffer_Pause (buf_t *buf)
 {
-  LOCK_MUTEX (buf->StatMutex);
-  buf->StatMask &= ~STAT_PLAYING;
-  UNLOCK_MUTEX (buf->StatMutex);
+  buf->Playing = 0;
 }
 
 void buffer_Unpause (buf_t *buf)
 {
-  LOCK_MUTEX (buf->StatMutex);
-  buf->StatMask |= STAT_PLAYING;
-  UNLOCK_MUTEX (buf->StatMutex);
-  pthread_cond_signal (&buf->DataReadyCondition);
+  buf->Playing = 1;
+  /* can't signal here; this can be called from sighandler :( */
+  /* pthread_cond_signal (&buf->DataReadyCondition); */
 }
 
 char buffer_Paused (buf_t *buf)
 {
-  return (char) !(buf->StatMask & STAT_PLAYING);
+  return (char) !(buf->Playing);
 }
 
 void buffer_MarkEOS (buf_t *buf)

1.2.2.13  +6 -5      vorbis-tools/ogg123/buffer.h

Index: buffer.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.h,v
retrieving revision 1.2.2.12
retrieving revision 1.2.2.13
diff -u -r1.2.2.12 -r1.2.2.13
--- buffer.h	2001/08/13 00:43:20	1.2.2.12
+++ buffer.h	2001/08/13 20:41:51	1.2.2.13
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
  
- last mod: $Id: buffer.h,v 1.2.2.12 2001/08/13 00:43:20 kcarnold Exp $
+ last mod: $Id: buffer.h,v 1.2.2.13 2001/08/13 20:41:51 kcarnold Exp $
  
 ********************************************************************/
 
@@ -43,9 +43,11 @@
   pthread_cond_t OverflowCondition;  /* signalled on buffer overflow */
   pthread_cond_t DataReadyCondition; /* signalled when data is ready and it wasn't before */
   
-  /* the buffer itself */
   char StatMask;
-  char FlushPending; /* must be separate from statmask */
+  /* And the stats that can't be in statmask: */
+  char FlushPending;
+  char Playing;
+
   char ReaderActive;
   char WriterActive;
   int OptimalWriteSize; /* optimal size to write out in chunks of, if possible. */
@@ -60,8 +62,7 @@
 } buf_t;
 
 #define STAT_PREBUFFERING 1
-#define STAT_PLAYING 2
-#define STAT_INACTIVE 4
+#define STAT_INACTIVE 2
 
 buf_t *StartBuffer (long size, long prebuffer, void *data, 
                     pWriteFunc write_func, void *initData, 

1.39.2.20 +26 -9     vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.19
retrieving revision 1.39.2.20
diff -u -r1.39.2.19 -r1.39.2.20
--- ogg123.c	2001/08/13 20:07:03	1.39.2.19
+++ ogg123.c	2001/08/13 20:41:51	1.39.2.20
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.39.2.19 2001/08/13 20:07:03 kcarnold Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.20 2001/08/13 20:41:51 kcarnold Exp $
 
  ********************************************************************/
 
@@ -200,7 +200,7 @@
     cur += sprintf (cur, "%sPrebuffering", sep);
     sep = comma;
   }
-  if (!buf->StatMask & STAT_PLAYING) {
+  if (!buf->Playing) {
     cur += sprintf (cur, "%sPaused", sep);
     sep = comma;
   }
@@ -338,7 +338,9 @@
   Options.playOpts.ntimes = 1;
 
   on_exit (ogg123_onexit, &Options);
-  signal (SIGINT, signal_quit);
+  signal (SIGINT, SigHandler);
+  signal (SIGTSTP, SigHandler);
+  signal (SIGCONT, SigHandler);
   ao_initialize();
   
   InitOgg123Stats (Options.statOpts.stats);
@@ -542,7 +544,7 @@
    * and blow away existing "output.wav" file.
    */
 
-  signal (SIGINT, signal_quit);
+  signal (SIGINT, SigHandler);
 }
 
 void signal_activate_skipfile(int ignored)
@@ -550,11 +552,26 @@
   signal(SIGINT,signal_skipfile);
 }
 
-void signal_quit(int ignored)
+void SigHandler (int signo)
 {
-  exit_requested = 1;
-  if (Options.outputOpts.buffer)
-    buffer_flush (Options.outputOpts.buffer);
+  switch (signo) {
+  case SIGINT:
+    exit_requested = 1;
+    if (Options.outputOpts.buffer)
+      buffer_flush (Options.outputOpts.buffer);
+    break;
+  case SIGTSTP:
+    if (Options.outputOpts.buffer)
+      buffer_Pause (Options.outputOpts.buffer);
+    kill (getpid(), SIGSTOP);
+    break;
+  case SIGCONT:
+    if (Options.outputOpts.buffer)
+      buffer_Unpause (Options.outputOpts.buffer);
+    break;
+  default:
+    psignal (signo, "Unknown signal caught");
+  }
 }
 
 #if 0
@@ -787,7 +804,7 @@
     
     alarm(0);
     signal(SIGALRM,SIG_DFL);
-    signal(SIGINT,signal_quit);
+    signal(SIGINT,SigHandler);
     
     ov_clear(&vf);
     

1.7.2.10  +2 -2      vorbis-tools/ogg123/ogg123.h

Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.7.2.9
retrieving revision 1.7.2.10
diff -u -r1.7.2.9 -r1.7.2.10
--- ogg123.h	2001/08/13 00:43:20	1.7.2.9
+++ ogg123.h	2001/08/13 20:41:52	1.7.2.10
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.h,v 1.7.2.9 2001/08/13 00:43:20 kcarnold Exp $
+ last mod: $Id: ogg123.h,v 1.7.2.10 2001/08/13 20:41:52 kcarnold Exp $
 
  ********************************************************************/
 
@@ -73,7 +73,7 @@
 void usage(void);
 void play_file();
 int open_audio_devices();
-void signal_quit (int ignored);
+void SigHandler (int ignored);
 void ogg123_onexit (int exitcode, void *arg);
 
 #endif /* !defined(__OGG123_H) */

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