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

Stan Seibert volsung at xiph.org
Wed Oct 17 09:58:18 PDT 2001



volsung     01/10/17 09:58:17

  Modified:    ogg123   Tag: volsung_kc_20011011 buffer.c buffer.h
                        curl_interface.c curl_interface.h ogg123.c
  Log:
  New streaming algorithm.  Buffer interface enhanced to allow push or pull
  consumption of the data.  (Audio devices need push consumption, vorbisfile
  needs pull consumption.)  libcurl now puts ogg vorbis data into an input
  buffer which is extracted by vorbisfile as needed.
  
  The code works, but still looks funny.  Function names and variables are
  not quite right and will be fixed soon.

Revision  Changes    Path
No                   revision

No                   revision

1.7.2.23.2.3 +82 -16    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.2
retrieving revision 1.7.2.23.2.3
diff -u -r1.7.2.23.2.2 -r1.7.2.23.2.3
--- buffer.c	2001/10/15 05:56:55	1.7.2.23.2.2
+++ buffer.c	2001/10/17 16:58:14	1.7.2.23.2.3
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: buffer.c,v 1.7.2.23.2.2 2001/10/15 05:56:55 volsung Exp $
+ last mod: $Id: buffer.c,v 1.7.2.23.2.3 2001/10/17 16:58:14 volsung Exp $
 
  ********************************************************************/
 
@@ -30,9 +30,8 @@
 #include <string.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <unistd.h>
 
-#include <assert.h> /* for debug purposes */
-
 #include "ogg123.h"
 #include "buffer.h"
 
@@ -43,7 +42,7 @@
 
 #ifdef DEBUG_BUFFER
 FILE *debugfile;
-#define DEBUG(x, y...) { if (pthread_self() != buf->thread) fprintf (debugfile, "D: " x "\n", ## y ); else fprintf (debugfile, "P: " x "\n", ## y ); }
+#define DEBUG(x, y...) { fprintf (debugfile, "%d: " x "\n", getpid(),  ## y); }
 #else
 #define DEBUG(x, y...)
 #endif
@@ -66,6 +65,17 @@
 }
 
 
+void _buffer_init_vars (buf_t *buf)
+{
+  /* Initialize buffer flags */
+  buf->prebuffering = buf->prebuffer_size > 0;
+  buf->paused = 0;
+  buf->eos = 0;
+  
+  buf->curfill = 0;
+  buf->start = 0;
+}
+
 void _buffer_thread_init (buf_t *buf)
 {
   sigset_t set;
@@ -89,18 +99,7 @@
         pthread_exit ((void*)ret);
     }
         
-  /* Setup pthread variables */
-  pthread_mutex_init (&buf->mutex, NULL);
-  pthread_cond_init (&buf->write_cond, NULL);
-  pthread_cond_init (&buf->playback_cond, NULL);
-
-  /* Initialize buffer flags */
-  buf->prebuffering = buf->prebuffer_size > 0;
-  buf->paused = 0;
-  buf->eos = 0;
-  
-  buf->curfill = 0;
-  buf->start = 0;
+  _buffer_init_vars(buf);
 }
 
 
@@ -263,6 +262,11 @@
 
   buf->initData = initData;
   buf->init_func = init_func;
+
+  /* Setup pthread variables */
+  pthread_mutex_init (&buf->mutex, NULL);
+  pthread_cond_init (&buf->write_cond, NULL);
+  pthread_cond_init (&buf->playback_cond, NULL);
   
   /* Correct for impossible chunk sizes */
   if (audio_chunk_size > size || audio_chunk_size == 0)
@@ -272,6 +276,9 @@
   buf->prebuffer_size = prebuffer_size;
   buf->size = size;
 
+  /* Initialize flags */
+  _buffer_init_vars(buf);
+
   return buf;
 }
 
@@ -341,6 +348,65 @@
   _submit_data_chunk (buf, data, size);
 }
 
+size_t buffer_get_data (buf_t *buf, chunk *data, size_t size, size_t nmemb)
+{
+  int write_amount;
+  int orig_size;
+
+  size *= nmemb;
+  orig_size = size;
+
+  DEBUG("Enter buffer_get_data");
+
+  LOCK_MUTEX(buf->mutex);
+
+  /* Put the data into the buffer as space is made available */
+  while (size > 0)
+    {
+      DEBUG("Obtaining lock on buffer");
+      /* Block until we can read something */
+      if (buf->curfill == 0)
+	{
+	  if (buf->eos)
+	    break; /* No more data to read */
+
+	  DEBUG("Waiting for more data to copy.");
+	  COND_WAIT(buf->playback_cond, buf->mutex);
+	}
+
+      /* Note: Even if curfill is still 0, nothing bad will happen here */
+
+      /* For simplicity, the number of bytes played must satisfy
+	 the following three requirements:
+	 
+	 1. Do not copy more bytes than are stored in the buffer.
+	 2. Do not copy more bytes than the reqested data size.
+	 3. Do not run off the end of the buffer. */
+      write_amount = MIN3(buf->curfill, size, buf->size - buf->start);
+      
+      /* No need to lock mutex here because the other thread will
+	 NEVER reduce the number of bytes stored in the buffer */
+      DEBUG("Copying %d bytes from the buffer", write_amount);
+      memcpy(data, buf->buffer + buf->start, write_amount);
+      
+      buf->curfill -= write_amount;
+      data += write_amount;
+      size -= write_amount;
+      buf->start = (buf->start + write_amount) % buf->size;
+      DEBUG("Updated buffer fill, curfill = %ld", buf->curfill);
+      
+      /* Signal a waiting decoder thread that they can put more
+	 audio into the buffer */
+      DEBUG("Signal decoder thread that buffer space is available");
+      COND_SIGNAL(buf->write_cond);
+    }
+
+   UNLOCK_MUTEX(buf->mutex);
+
+   DEBUG("Exit buffer_get_data");
+   
+   return orig_size - size;
+}
 
 void buffer_mark_eos (buf_t *buf)
 {

1.2.2.16.2.2 +3 -1      vorbis-tools/ogg123/buffer.h

Index: buffer.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.h,v
retrieving revision 1.2.2.16.2.1
retrieving revision 1.2.2.16.2.2
diff -u -r1.2.2.16.2.1 -r1.2.2.16.2.2
--- buffer.h	2001/10/14 05:42:51	1.2.2.16.2.1
+++ buffer.h	2001/10/17 16:58:14	1.2.2.16.2.2
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
  
- last mod: $Id: buffer.h,v 1.2.2.16.2.1 2001/10/14 05:42:51 volsung Exp $
+ last mod: $Id: buffer.h,v 1.2.2.16.2.2 2001/10/17 16:58:14 volsung Exp $
  
 ********************************************************************/
 
@@ -78,6 +78,8 @@
 
 /* --- Data buffering functions --- */
 void buffer_submit_data (buf_t *buf, chunk *data, size_t size, size_t nmemb);
+size_t buffer_get_data (buf_t *buf, chunk *data, size_t size, size_t nmemb);
+
 void buffer_mark_eos (buf_t *buf);
 
 /* --- Buffer status functions --- */

1.1.2.6.2.2 +43 -162   vorbis-tools/ogg123/Attic/curl_interface.c

Index: curl_interface.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/curl_interface.c,v
retrieving revision 1.1.2.6.2.1
retrieving revision 1.1.2.6.2.2
diff -u -r1.1.2.6.2.1 -r1.1.2.6.2.2
--- curl_interface.c	2001/10/14 05:42:51	1.1.2.6.2.1
+++ curl_interface.c	2001/10/17 16:58:14	1.1.2.6.2.2
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
  
- last mod: $Id: curl_interface.c,v 1.1.2.6.2.1 2001/10/14 05:42:51 volsung Exp $
+ last mod: $Id: curl_interface.c,v 1.1.2.6.2.2 2001/10/17 16:58:14 volsung Exp $
  
 ********************************************************************/
 
@@ -22,7 +22,7 @@
 #include <string.h> /* for memmove */
 #include <signal.h>		/* for SIGINT */
 
-#define DEBUG_CURLINTERFACE
+#undef DEBUG_CURLINTERFACE
 
 #ifdef DEBUG_CURLINTERFACE
 #define debug(x, y...) do { fprintf (stderr, x , ## y); } while (0)
@@ -47,71 +47,7 @@
   return size * nmemb;
 }
 
-size_t
-BufferWriteChunk (void *voidptr, size_t size, void *arg, char iseos)
-{
-  StreamInputBufferData_t *data = arg;
-  unsigned char *ptr = voidptr;
-
-  debug ("buffer writing chunk of %d, %d bytes to go\n", size,
-	 data->BytesRequested);
-
-  pthread_mutex_lock (&data->ReadDataMutex);
-  while (data->BytesRequested == 0 && !data->ShuttingDown)
-    pthread_cond_wait (&data->ReadRequestedCondition, &data->ReadDataMutex);
-
-  data->EOS = iseos;
-  if (iseos)
-    debug ("End of stream.\n");
-
-  if (size <= data->BytesRequested)
-    {
-      debug ("simply moving %d bytes in.\n", size);
-      memmove (data->CurWritePtr, ptr, size);
-      data->CurWritePtr += size;
-      data->BytesRequested -= size;
-      pthread_mutex_unlock (&data->ReadDataMutex);
-      if (data->BytesRequested == 0 || iseos)
-	pthread_cond_signal (&data->ReadDoneCondition);
-    }
-  else
-    {
-      /* There will be some excess data here. Write it, then block on needing more data. */
-      debug ("writing %d bytes, ", data->BytesRequested);
-      memmove (data->CurWritePtr, ptr, data->BytesRequested);
-      data->CurWritePtr += data->BytesRequested;
-      size -= data->BytesRequested;
-      ptr += data->BytesRequested;
-      data->BytesRequested = 0;
-      debug ("saving %d bytes of excess data\n", size);
-      memmove (data->ExcessData, ptr, size);
-      data->ExcessDataSize = size;
-
-      debug ("signalling successful read\n");
-      pthread_mutex_unlock (&data->ReadDataMutex);
-      pthread_cond_signal (&data->ReadDoneCondition);
-    }
-
-  debug ("buffer write done.\n");
-  return size;
-}
 
-size_t
-BufferWriteFunction (void *ptr, size_t size, size_t nmemb, void *arg,
-		     char iseos)
-{
-  size_t written = 0;
-  while (nmemb > 0)
-    {
-      if (nmemb == 1)
-	written += BufferWriteChunk (ptr, size, arg, iseos);
-      else
-	written += BufferWriteChunk (ptr, size, arg, 0);
-      nmemb--;
-    }
-  return written;
-}
-
 int
 CurlProgressFunction (void *arg, size_t dltotal, size_t dlnow, size_t ultotal,
                       size_t ulnow)
@@ -153,23 +89,25 @@
 void *
 CurlGo (void *arg)
 {
-  buf_t *buf = arg;
-  StreamInputBufferData_t *data = buf->data;
+  StreamInputBufferData_t *data = (StreamInputBufferData_t *) arg;
   CURLcode ret;
+
   debug ("CurlGo\n");
   ret = curl_easy_perform ((CURL *) data->CurlHandle);
   debug ("curl done.\n");
-  buffer_thread_kill (buf);
+
+  buffer_mark_eos (data->buf);
+
   curl_easy_cleanup (data->CurlHandle);
   data->CurlHandle = 0;
+
   return (void *) ret;
 }
 
-buf_t *
+StreamInputBufferData_t *
 InitStream (InputOpts_t inputOpts)
 {
-  StreamInputBufferData_t *data = calloc (1, sizeof (StreamInputBufferData_t));
-  buf_t *buf;
+  StreamInputBufferData_t *data = malloc (sizeof (StreamInputBufferData_t));
 
   debug ("InitStream\n");
   debug (" Allocated data\n");
@@ -180,10 +118,7 @@
       exit (1);
     }
 
-  debug (" init pthreads\n");
-  pthread_mutex_init (&data->ReadDataMutex, NULL);
-  pthread_cond_init (&data->ReadRequestedCondition, NULL);
-  pthread_cond_init (&data->ReadDoneCondition, NULL);
+  data->SavedStream = NULL;
 
   debug (" curl init\n");
   data->CurlHandle = curl_easy_init ();
@@ -192,97 +127,52 @@
       perror ("curl_easy_init");
       exit (1);
     }
-
-  debug (" create buffer\n");
-  buf = buffer_create (inputOpts.BufferSize, inputOpts.Prebuffer, data,
-		       BufferWriteFunction, NULL, NULL, VORBIS_CHUNKIN_SIZE);
 
-  if (!buf)
+  debug (" create buffer, prebuf = %ld\n", inputOpts.Prebuffer);
+  inputOpts.Prebuffer = 0;
+  inputOpts.BufferSize = 1024*500;
+  data->buf = buffer_create (inputOpts.BufferSize, inputOpts.Prebuffer, NULL,
+			     NULL, NULL, NULL, VORBIS_CHUNKIN_SIZE);
+  /* Don't start the thread since we are going to be pulling data from
+     the buffer instead. */
+  
+  if (!data->buf)
     {
       perror ("Create Buffer");
       exit (1);
     }
 
   debug (" set curl opts\n");
-  CurlSetopts (data->CurlHandle, buf, inputOpts);
+  CurlSetopts (data->CurlHandle, data->buf, inputOpts);
 
   debug (" init saving stream\n");
   if (inputOpts.SaveStream)
     data->SavedStream = fopen (inputOpts.SaveStream, "wb");
 
-  pthread_create (&data->CurlThread, NULL, CurlGo, buf);
+  pthread_create (&data->CurlThread, NULL, CurlGo, data);
 
   debug ("returning.\n");
-  return buf;
+  return data;
 }
 
-size_t
-_StreamBufferRead (void *voidptr, size_t size, size_t nmemb, void *arg)
+void StreamCleanup (StreamInputBufferData_t *data)
 {
-  StreamInputBufferData_t *data = arg;
-  unsigned char *ptr = voidptr;
-  size_t ret;
-
-  ret = size *= nmemb;		/* makes things simpler and run smoother */
-
-  debug ("StreamBufferRead %d bytes\n", ret);
-
-  pthread_mutex_lock (&data->ReadDataMutex);
-
-  if (size <= data->ExcessDataSize)
-    {
-      debug ("reading out of excess data\n");
-      memmove (ptr, data->ExcessData, size);
-      data->ExcessDataSize -= size;
-      if (size < data->ExcessDataSize)
-	memmove (data->ExcessData, data->ExcessData + size,
-		 data->ExcessDataSize);
-      pthread_mutex_unlock (&data->ReadDataMutex);
-    }
-  else
-    {
-      debug ("Using %d bytes of excess data.\n", data->ExcessDataSize);
-      memmove (ptr, data->ExcessData, data->ExcessDataSize);
-      ptr += data->ExcessDataSize;
-      size -= data->ExcessDataSize;
-      if (data->EOS)
-	{
-	  ret = data->ExcessDataSize;
-	  debug ("Data marked EOS, so returning just excess data\n");
-	  pthread_mutex_unlock (&data->ReadDataMutex);
-	  data->ExcessDataSize = 0;
-	  return ret;
-	}
-      else
-	data->ExcessDataSize = 0;
-
-      data->BytesRequested = size;
-      data->WriteTarget = data->CurWritePtr = ptr;
-
-      pthread_mutex_unlock (&data->ReadDataMutex);
-      pthread_cond_signal (&data->ReadRequestedCondition);
-      pthread_mutex_lock (&data->ReadDataMutex);
-
-      while (data->BytesRequested > 0 && !data->EOS)
-	{
-	  debug ("Waiting for %d bytes of data to be read, eos=%d.\n",
-		 data->BytesRequested, data->EOS);
-	  pthread_cond_wait (&data->ReadDoneCondition, &data->ReadDataMutex);
-	}
-      if (data->EOS)
-	ret -= data->BytesRequested;
-      pthread_mutex_unlock (&data->ReadDataMutex);
-    }
-  debug ("buffer read done.\n");
-  return ret;
+  free (data);
 }
 
+/* --------------- vorbisfile callbacks --------------- */
+
 size_t StreamBufferRead (void *ptr, size_t size, size_t nmemb, void *arg)
 {
   StreamInputBufferData_t *data = arg;
-  size_t ret = _StreamBufferRead (ptr, size, nmemb, arg);
+  size_t ret;
+
+  debug ("StreamBufferRead %d bytes\n", size*nmemb);
+  ret = buffer_get_data(data->buf, ptr, size, nmemb);
+
   if (data->SavedStream)
     fwrite (ptr, ret, 1, data->SavedStream);
+
   return ret;
 }
 
@@ -300,17 +190,16 @@
   StreamInputBufferData_t *data = arg;
 
   debug ("StreamBufferClose\n");
-  if (data)
-    {
-      pthread_kill (data->CurlThread, SIGTERM);
-      pthread_join (data->CurlThread, NULL);
-      data->ShuttingDown = 1;
-      data->EOS = 1;
-      data->BytesRequested = 0;
-      pthread_cond_signal (&data->ReadRequestedCondition);
-      memset (data, 0, sizeof(data));
-      free (data);
-    }
+
+  pthread_kill (data->CurlThread, SIGTERM);
+  pthread_join (data->CurlThread, NULL);
+
+  buffer_destroy(data->buf);
+  data->buf = NULL;
+
+  if (data->SavedStream)
+    fclose (data->SavedStream);
+
   return 0;
 }
 
@@ -318,12 +207,4 @@
 StreamBufferTell (void *arg)
 {
   return 0;
-}
-
-void StreamInputCleanup (buf_t *buf)
-{ 
-  StreamBufferClose (buf->data);
-  buf->data = 0;
-  buffer_thread_kill (buf);
-  buffer_destroy (buf);
 }

1.1.2.7.2.1 +14 -22    vorbis-tools/ogg123/Attic/curl_interface.h

Index: curl_interface.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/curl_interface.h,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.7.2.1
diff -u -r1.1.2.7 -r1.1.2.7.2.1
--- curl_interface.h	2001/08/31 18:01:12	1.1.2.7
+++ curl_interface.h	2001/10/17 16:58:14	1.1.2.7.2.1
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
  
- last mod: $Id: curl_interface.h,v 1.1.2.7 2001/08/31 18:01:12 kcarnold Exp $
+ last mod: $Id: curl_interface.h,v 1.1.2.7.2.1 2001/10/17 16:58:14 volsung Exp $
  
 ********************************************************************/
 
@@ -25,8 +25,19 @@
 
 #include "buffer.h"
 
+typedef struct StreamInputBufferData_s {
+  buf_t *buf;
+
+  pthread_t CurlThread;
+
+  CURL * CurlHandle;
+
+  FILE *SavedStream;
+} StreamInputBufferData_t;
+
 typedef struct InputOpts_s {
-  buf_t *buffer;
+  StreamInputBufferData_t *data;
+
   /* Input buffer options */
   long BufferSize;
   long Prebuffer;
@@ -50,27 +61,8 @@
 } InputOpts_t;
 
 #define VORBIS_CHUNKIN_SIZE (8500)
-
-typedef struct StreamInputBufferData_s {
-  pthread_t CurlThread;
-  pthread_mutex_t ReadDataMutex;
-  pthread_cond_t ReadRequestedCondition;
-  pthread_cond_t ReadDoneCondition;
-
-  CURL * CurlHandle;
-
-  char EOS;
-  char ShuttingDown;
-
-  size_t BytesRequested;
-  unsigned char *WriteTarget;
-  unsigned char *CurWritePtr;
-  unsigned char ExcessData[VORBIS_CHUNKIN_SIZE];
-  size_t ExcessDataSize;
-  FILE *SavedStream;
-} StreamInputBufferData_t;
 
-buf_t *InitStream (InputOpts_t inputOpts);
+StreamInputBufferData_t *InitStream (InputOpts_t inputOpts);
 size_t StreamBufferRead (void *ptr, size_t size, size_t nmemb, void *arg);
 int StreamBufferSeek (void *arg, ogg_int64_t offset, int whence);
 int StreamBufferClose (void *arg);

1.39.2.30.2.3 +140 -140  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.2
retrieving revision 1.39.2.30.2.3
diff -u -r1.39.2.30.2.2 -r1.39.2.30.2.3
--- ogg123.c	2001/10/15 05:56:55	1.39.2.30.2.2
+++ ogg123.c	2001/10/17 16:58:14	1.39.2.30.2.3
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.39.2.30.2.2 2001/10/15 05:56:55 volsung Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.30.2.3 2001/10/17 16:58:14 volsung Exp $
 
  ********************************************************************/
 
@@ -218,9 +218,9 @@
   Stat_t *stats = Options.statOpts.stats;
 
   memset (strbuf, 0, 80);
-  if (Options.inputOpts.buffer) {
-    SetBufferStats (Options.inputOpts.buffer, strbuf);
-    stats[6].arg.doublearg = (double) buffer_full(Options.inputOpts.buffer) / (double) Options.inputOpts.buffer->size * 100.0f;
+  if (Options.inputOpts.data->buf) {
+    SetBufferStats (Options.inputOpts.data->buf, strbuf);
+    stats[6].arg.doublearg = (double) buffer_full(Options.inputOpts.data->buf) / (double) Options.inputOpts.data->buf->size * 100.0f;
   }
   if (stats[7].arg.stringarg)
     free (stats[7].arg.stringarg);
@@ -650,8 +650,8 @@
       VorbisfileCallbacks.tell_func = StreamBufferTell;
       
       Options.inputOpts.URL = Options.playOpts.read_file;
-      Options.inputOpts.buffer = InitStream (Options.inputOpts);
-      if ((ov_open_callbacks (Options.inputOpts.buffer->data, &vf, NULL, 0, VorbisfileCallbacks)) < 0) {
+      Options.inputOpts.data = InitStream (Options.inputOpts);
+      if ((ov_open_callbacks (Options.inputOpts.data, &vf, NULL, 0, VorbisfileCallbacks)) < 0) {
         Error ("=== Input not an Ogg Vorbis audio stream.\n");
         return;
       }
@@ -686,59 +686,59 @@
         return;
       }
     }
+  
+  /* Setup so that pressing ^C in the first second of playback
+   * interrupts the program, but after the first second, skips
+   * the song.  This functionality is similar to mpg123's abilities. */
+  
+  if (Options.playOpts.delay > 0) {
+    skipfile_requested = 0;
+    signal(SIGALRM,signal_activate_skipfile);
+    alarm(Options.playOpts.delay);
+  }
+  
+  exit_requested = 0;
+  pause_requested = 0;
+  
+  while (!eof && !exit_requested) {
+    int i;
+    vorbis_comment *vc = ov_comment(&vf, -1);
+    vorbis_info *vi = ov_info(&vf, -1);
     
-    /* Setup so that pressing ^C in the first second of playback
-     * interrupts the program, but after the first second, skips
-     * the song.  This functionality is similar to mpg123's abilities. */
-    
-    if (Options.playOpts.delay > 0) {
-      skipfile_requested = 0;
-      signal(SIGALRM,signal_activate_skipfile);
-      alarm(Options.playOpts.delay);
-    }
-        
-    exit_requested = 0;
-    pause_requested = 0;
-
-    while (!eof && !exit_requested) {
-      int i;
-      vorbis_comment *vc = ov_comment(&vf, -1);
-      vorbis_info *vi = ov_info(&vf, -1);
-      
-      Options.outputOpts.rate = vi->rate;
-      Options.outputOpts.channels = vi->channels;
-      if(open_audio_devices() < 0)
-	exit(1);
-      
-      for (i = 0; i < vc->comments; i++) {
-	char *cc = vc->user_comments[i];	/* current comment */
-	int j;
-	
-	for (j = 0; ogg_comment_keys[j].key != NULL; j++)
-	  if (!strncasecmp
-	      (ogg_comment_keys[j].key, cc,
-	       strlen(ogg_comment_keys[j].key))) {
-	    ShowMessage (1, 0, 1, ogg_comment_keys[j].formatstr,
-			 cc + strlen(ogg_comment_keys[j].key));
-	    break;
-	  }
-	if (ogg_comment_keys[j].key == NULL)
-	  ShowMessage (1, 0, 1, "Unrecognized comment: '%s'", cc);
-      }
+    Options.outputOpts.rate = vi->rate;
+    Options.outputOpts.channels = vi->channels;
+    if(open_audio_devices() < 0)
+      exit(1);
+    
+    for (i = 0; i < vc->comments; i++) {
+      char *cc = vc->user_comments[i];	/* current comment */
+      int j;
       
-      ShowMessage (3, 0, 1, "Version is %d", vi->version);
-      ShowMessage (3, 0, 1, "Bitrate Hints: upper=%ld nominal=%ld lower=%ld window=%ld",
-		   vi->bitrate_upper, vi->bitrate_nominal, vi->bitrate_lower, vi->bitrate_window);
-      ShowMessage (2, 0, 1, "Bitstream is %d channel, %ldHz",
-		   vi->channels, vi->rate);
-      ShowMessage (2, 0, 1, "Encoded by: %s", vc->vendor);
+      for (j = 0; ogg_comment_keys[j].key != NULL; j++)
+	if (!strncasecmp
+	    (ogg_comment_keys[j].key, cc,
+	     strlen(ogg_comment_keys[j].key))) {
+	  ShowMessage (1, 0, 1, ogg_comment_keys[j].formatstr,
+		       cc + strlen(ogg_comment_keys[j].key));
+	  break;
+	}
+      if (ogg_comment_keys[j].key == NULL)
+	ShowMessage (1, 0, 1, "Unrecognized comment: '%s'", cc);
+    }
+    
+    ShowMessage (3, 0, 1, "Version is %d", vi->version);
+    ShowMessage (3, 0, 1, "Bitrate Hints: upper=%ld nominal=%ld lower=%ld window=%ld",
+		 vi->bitrate_upper, vi->bitrate_nominal, vi->bitrate_lower, vi->bitrate_window);
+    ShowMessage (2, 0, 1, "Bitstream is %d channel, %ldHz",
+		 vi->channels, vi->rate);
+    ShowMessage (2, 0, 1, "Encoded by: %s", vc->vendor);
+    
+    if (ov_seekable (&vf)) {
+      if ((realseekpos > ov_time_total(&vf, -1)) || (realseekpos < 0))
+	/* If we're out of range set it to right before the end. If we set it
+	 * right to the end when we seek it will go to the beginning of the song */
+	realseekpos = ov_time_total(&vf, -1) - 0.01;
       
-      if (ov_seekable (&vf)) {
-	if ((realseekpos > ov_time_total(&vf, -1)) || (realseekpos < 0))
-	  /* If we're out of range set it to right before the end. If we set it
-	   * right to the end when we seek it will go to the beginning of the song */
-	  realseekpos = ov_time_total(&vf, -1) - 0.01;
-	
         Options.inputOpts.seekable = 1;
         Options.inputOpts.totalTime = ov_time_total(&vf, -1);
         Options.inputOpts.totalSamples = ov_pcm_total(&vf, -1);
@@ -749,99 +749,99 @@
         
         if (realseekpos > 0)
           ov_time_seek(&vf, realseekpos);
-      }
-      else
-	Options.inputOpts.seekable = 0;
-
-      /* Ready to start sending data to the audio playback thread */
-
-      if (Options.outputOpts.buffer)
-	buffer_thread_start (Options.outputOpts.buffer);
-
-      eos = 0;
+    }
+    else
+      Options.inputOpts.seekable = 0;
+    
+    /* Ready to start sending data to the audio playback thread */
+    
+    if (Options.outputOpts.buffer)
+      buffer_thread_start (Options.outputOpts.buffer);
+    
+    eos = 0;
+    
+    while (!eos && !exit_requested) {
       
-      while (!eos && !exit_requested) {
-	
-	if (skipfile_requested) {
-	  eof = eos = 1;
-	  signal(SIGALRM,signal_activate_skipfile);
+      if (skipfile_requested) {
+	eof = eos = 1;
+	signal(SIGALRM,signal_activate_skipfile);
           alarm(Options.playOpts.delay);
           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,
+      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,
                   2, 1, &current_section);
-	if (ret == 0) {
-	  /* End of file */
-	  eof = eos = 1;
-	} else if (ret == OV_HOLE) {
-	  if (Options.statOpts.verbose > 1) 
-	    /* we should be able to resync silently; if not there are 
-	       bigger problems. */
-	    Error ("--- Hole in the stream; probably harmless\n");
-	} else if (ret < 0) {
-	  /* Stream error */
-	  Error ("=== Vorbis library reported a stream error.\n");
-	} else {
-	  /* did we enter a new logical bitstream */
-	  if (old_section != current_section && old_section != -1)
-	    eos = 1;
-	  
-	  Options.statOpts.stats[4].arg.doublearg = (double) ov_bitrate_instant (&vf) / 1000.0f;
-
-	  do {
-	    if (nthc-- == 0) {
-	      if (Options.outputOpts.buffer) {
-		buffer_submit_data (Options.outputOpts.buffer, 
-				    convbuffer, ret, 1);
-		Ogg123UpdateStats();
+      if (ret == 0) {
+	/* End of file */
+	eof = eos = 1;
+      } else if (ret == OV_HOLE) {
+	if (Options.statOpts.verbose > 1) 
+	  /* we should be able to resync silently; if not there are 
+	     bigger problems. */
+	  Error ("--- Hole in the stream; probably harmless\n");
+      } else if (ret < 0) {
+	/* Stream error */
+	Error ("=== Vorbis library reported a stream error.\n");
+      } else {
+	/* did we enter a new logical bitstream */
+	if (old_section != current_section && old_section != -1)
+	  eos = 1;
+	
+	Options.statOpts.stats[4].arg.doublearg = (double) ov_bitrate_instant (&vf) / 1000.0f;
+	
+	do {
+	  if (nthc-- == 0) {
+	    if (Options.outputOpts.buffer) {
+	      buffer_submit_data (Options.outputOpts.buffer, 
+				  convbuffer, ret, 1);
+	      Ogg123UpdateStats();
               }
-	      else
-		OutBufferWrite (convbuffer, ret, 1, &Options, 0);
-	      nthc = Options.playOpts.nth - 1;
+	    else
+	      OutBufferWrite (convbuffer, ret, 1, &Options, 0);
+	    nthc = Options.playOpts.nth - 1;
             }
-	  } while (++ntimesc < Options.playOpts.ntimes);
-	  ntimesc = 0;
-	  
-	}
-      }
-
-      /* Done playing this logical bitstream.  Now we cleanup. */
-      if (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);
+	} while (++ntimesc < Options.playOpts.ntimes);
+	ntimesc = 0;
+	
       }
-
     }
     
-    alarm(0);
-    signal(SIGALRM,SIG_DFL);
-    signal(SIGINT,SigHandler);
-    
-    ov_clear(&vf);
+    /* Done playing this logical bitstream.  Now we cleanup. */
+    if (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);
+    }
     
-    ShowMessage (1, 1, 1, "Done.");
+  }
     
-    if (exit_requested)
-      exit (0);
+  alarm(0);
+  signal(SIGALRM,SIG_DFL);
+  signal(SIGINT,SigHandler);
+  
+  ov_clear(&vf);
+  
+  ShowMessage (1, 1, 1, "Done.");
+  
+  if (exit_requested)
+    exit (0);
 }
 
 int open_audio_devices()
@@ -926,9 +926,9 @@
 
 void ogg123_onexit (int exitcode, void *arg)
 {
-  if (Options.inputOpts.buffer) {
-    StreamInputCleanup (Options.inputOpts.buffer);
-    Options.inputOpts.buffer = NULL;
+  if (Options.inputOpts.data) {
+    StreamCleanup (Options.inputOpts.data);
+    Options.inputOpts.data = NULL;
   }
       
   if (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