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

Kenneth C. Arnold kcarnold at xiph.org
Fri Aug 10 19:10:11 PDT 2001



kcarnold    01/08/10 19:10:11

  Modified:    ogg123   Tag: kcarnold_work Makefile.am ao_interface.c
                        buffer.c buffer.h ogg123.c
  Added:       ogg123   Tag: kcarnold_work curl_interface.c
                        curl_interface.h
  Log:
  libcurl streaming. buffer work; it's more generic now. cool except EOF on curl stream don't work yet.

Revision  Changes    Path
No                   revision

No                   revision

1.14.2.3  +2 -2      vorbis-tools/ogg123/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Makefile.am,v
retrieving revision 1.14.2.2
retrieving revision 1.14.2.3
diff -u -r1.14.2.2 -r1.14.2.3
--- Makefile.am	2001/08/10 16:33:40	1.14.2.2
+++ Makefile.am	2001/08/11 02:10:09	1.14.2.3
@@ -11,9 +11,9 @@
 INCLUDES = @OGG_CFLAGS@ @VORBIS_CFLAGS@ @AO_CFLAGS@
 
 ogg123_LDADD = @VORBISFILE_LIBS@ @VORBIS_LIBS@ @OGG_LIBS@ @AO_LIBS@ \
-		@SOCKET_LIBS@
+		@SOCKET_LIBS@ -lcurl
 
-ogg123_SOURCES = ogg123.c ao_interface.c buffer.c ogg123.h buffer.h getopt.c getopt1.c getopt.h ao_interface.h
+ogg123_SOURCES = ogg123.c ao_interface.c buffer.c ogg123.h buffer.h getopt.c getopt1.c getopt.h ao_interface.h curl_interface.c curl_interface.h
 ## Comment the above and uncomment the next line to disable the buffer support
 ##ogg123_SOURCES = ogg123.c ao_interface.c nullbuffer.c ogg123.h buffer.h getopt.c getopt1.c getopt.h
 

1.5.2.3   +4 -2      vorbis-tools/ogg123/ao_interface.c

Index: ao_interface.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ao_interface.c,v
retrieving revision 1.5.2.2
retrieving revision 1.5.2.3
diff -u -r1.5.2.2 -r1.5.2.3
--- ao_interface.c	2001/08/10 16:33:40	1.5.2.2
+++ ao_interface.c	2001/08/11 02:10:09	1.5.2.3
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ao_interface.c,v 1.5.2.2 2001/08/10 16:33:40 kcarnold Exp $
+ last mod: $Id: ao_interface.c,v 1.5.2.3 2001/08/11 02:10:09 kcarnold Exp $
 
  ********************************************************************/
 
@@ -129,7 +129,9 @@
 {
   devices_t *current = devices;
   while (current != NULL) {
-    ao_close(current->device);
+    if (current->device)
+      ao_close(current->device);
+    current->device = NULL;
     current = current->next_device;
   }
 }

1.7.2.8   +15 -4     vorbis-tools/ogg123/buffer.c

Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.7.2.7
retrieving revision 1.7.2.8
diff -u -r1.7.2.7 -r1.7.2.8
--- buffer.c	2001/08/10 20:48:06	1.7.2.7
+++ buffer.c	2001/08/11 02:10:09	1.7.2.8
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: buffer.c,v 1.7.2.7 2001/08/10 20:48:06 kcarnold Exp $
+ last mod: $Id: buffer.c,v 1.7.2.8 2001/08/11 02:10:09 kcarnold Exp $
 
  ********************************************************************/
 
@@ -50,8 +50,6 @@
 #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 TARGET_WRITE_SIZE 4096 /* to agree with other mechanisms used in ogg123 */
-
 void Prebuffer (buf_t * buf)
 {
   if (buf->prebuffer > 0)
@@ -90,7 +88,16 @@
   sigfillset (&set);
   pthread_sigmask (SIG_SETMASK, &set, NULL);
 
+  /* Run the initialization function, if there is one */
+  if (buf->init_func)
+    {
+      int ret = buf->init_func (buf->initData);
+      if (!ret)
+	pthread_exit ((void*)ret);
+    }
+
   pthread_cleanup_push (PthreadCleanup, buf);
+
   while (1)
     {
       /* don't touch the size unless we ask you to. */
@@ -177,7 +184,8 @@
 }
 
 buf_t *StartBuffer (long size, long prebuffer, void *data, 
-		    size_t (*write_func) (void *, size_t, size_t, void *))
+		    size_t (*write_func) (void *, size_t, size_t, void *),
+		    void *initData, int (*init_func) (void*))
 {
   buf_t *buf = malloc (sizeof(buf_t) + sizeof (chunk) * (size - 1));
 
@@ -200,6 +208,9 @@
 
   buf->data = data;
   buf->write_func = write_func;
+
+  buf->initData = initData;
+  buf->init_func = init_func;
 
   buf->reader = buf->writer = buf->buffer;
   buf->end = buf->buffer + (size - 1);

1.2.2.8   +8 -2      vorbis-tools/ogg123/buffer.h

Index: buffer.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.h,v
retrieving revision 1.2.2.7
retrieving revision 1.2.2.8
diff -u -r1.2.2.7 -r1.2.2.8
--- buffer.h	2001/08/10 20:48:06	1.2.2.7
+++ buffer.h	2001/08/11 02:10:09	1.2.2.8
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
  
- last mod: $Id: buffer.h,v 1.2.2.7 2001/08/10 20:48:06 kcarnold Exp $
+ last mod: $Id: buffer.h,v 1.2.2.8 2001/08/11 02:10:09 kcarnold Exp $
  
 ********************************************************************/
 
@@ -29,6 +29,9 @@
   /* generic buffer interface */
   void * data;
   size_t (*write_func) (chunk *ptr, size_t size, size_t nmemb, void * d);
+
+  void * initData;
+  int (*init_func) (void *);
   
   /* pthreads variables */
   pthread_t BufferThread;
@@ -53,8 +56,11 @@
 #define STAT_PLAYING 2
 #define STAT_EMPTYING 4
 
+#define TARGET_WRITE_SIZE 4096 /* to agree with other mechanisms used in ogg123 */
+
 buf_t *StartBuffer (long size, long prebuffer, void *data, 
-		    size_t (*write_func) (void *, size_t, size_t, void *));
+		    size_t (*write_func) (void *, size_t, size_t, void *),
+		    void *initData, int (*init_func) (void*));
 void SubmitData (buf_t *buf, chunk *data, size_t size, size_t nmemb);
 void buffer_shutdown (buf_t *buf);
 void buffer_cleanup (buf_t *buf);

1.39.2.10 +88 -45    vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.9
retrieving revision 1.39.2.10
diff -u -r1.39.2.9 -r1.39.2.10
--- ogg123.c	2001/08/10 20:48:06	1.39.2.9
+++ ogg123.c	2001/08/11 02:10:09	1.39.2.10
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.39.2.9 2001/08/10 20:48:06 kcarnold Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.10 2001/08/11 02:10:09 kcarnold Exp $
 
  ********************************************************************/
 
@@ -32,6 +32,7 @@
 
 #include "ogg123.h"
 #include "ao_interface.h"
+#include "curl_interface.h"
 #include "buffer.h"
 
 /* take buffer out of the data segment, not the stack */
@@ -245,7 +246,8 @@
       {
         opt.prebuffer = (int) ((double) opt.prebuffer * (double) opt.buffer_size / 100.0F);
         OutBuffer = StartBuffer (opt.buffer_size, opt.prebuffer,
-				 opt.outdevices, devices_write);
+				 opt.outdevices, devices_write,
+				 NULL, NULL);
       }
     
     if (opt.shuffle) {
@@ -307,23 +309,79 @@
   exit(0);
 }
 
-void play_file(ogg123_options_t opt)
+/* from vorbisfile.c */
+static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence)
 {
-    /* Oh my gosh this is disgusting. Big cleanups here will include an
-       almost complete rewrite of the hacked-out HTTP streaming and a shift
-       to using callbacks for the vorbisfile input.
-    */
-
-    OggVorbis_File vf;
-    int current_section = -1, eof = 0, eos = 0, ret;
-    int old_section = -1;
-    long t_min = 0, c_min = 0, r_min = 0;
-    double t_sec = 0, c_sec = 0, r_sec = 0;
-    int is_big_endian = ao_is_big_endian();
-    double realseekpos = opt.seekpos;
-    int nthc = 0, ntimesc = 0;
-    double u_time, u_pos;
+  if(f==NULL)return(-1);
+  return fseek(f,(int)off,whence);
+}
 
+void play_file(ogg123_options_t opt)
+{
+  OggVorbis_File vf;
+  int current_section = -1, eof = 0, eos = 0, ret;
+  int old_section = -1;
+  long t_min = 0, c_min = 0, r_min = 0;
+  double t_sec = 0, c_sec = 0, r_sec = 0;
+  int is_big_endian = ao_is_big_endian();
+  double realseekpos = opt.seekpos;
+  int nthc = 0, ntimesc = 0;
+  double u_time, u_pos;
+  int tmp;
+  ov_callbacks VorbisfileCallbacks;
+  
+  tmp = strchr(opt.read_file, ':') - opt.read_file;
+  if (tmp < 10 && tmp + 2 < strlen(opt.read_file) && !strncmp(opt.read_file + tmp, "://", 3))
+    {
+      InputOpts_t inputOpts;
+      
+      /* let's call this a URL. */
+      if (opt.quiet < 1)
+	fprintf (stderr, "Playing from stream %s\n", opt.read_file);
+      VorbisfileCallbacks.read_func = StreamBufferRead;
+      VorbisfileCallbacks.seek_func = StreamBufferSeek;
+      VorbisfileCallbacks.close_func = StreamBufferClose;
+      VorbisfileCallbacks.tell_func = StreamBufferTell;
+      
+      inputOpts.BufferSize = 1024*1024;
+      inputOpts.Prebuffer = 0;
+      inputOpts.URL = opt.read_file;
+      InBuffer = InitStream (inputOpts);
+      if ((ov_open_callbacks (InBuffer->data, &vf, NULL, 0, VorbisfileCallbacks)) < 0) {
+	fprintf(stderr, "E: input not an Ogg Vorbis audio stream.\n");
+	return;
+      }
+      
+    }
+  else
+    {
+      VorbisfileCallbacks.read_func = fread;
+      VorbisfileCallbacks.seek_func = _fseek64_wrap;
+      VorbisfileCallbacks.close_func = fclose;
+      VorbisfileCallbacks.tell_func = ftell;
+      if (strcmp(opt.read_file, "-"))
+	{
+	  if (opt.quiet < 1)
+	    fprintf(stderr, "Playing from file %s.\n", opt.read_file);
+	  /* Open the file. */
+	  if ((opt.instream = fopen(opt.read_file, "rb")) == NULL) {
+	    fprintf(stderr, "Error opening input file.\n");
+	    exit(1);
+	  }
+	}
+      else
+	{
+	  if (opt.quiet < 1)
+	    fprintf(stderr, "Playing from standard input.\n");
+	  opt.instream = stdin;
+	}
+      if ((ov_open_callbacks (opt.instream, &vf, NULL, 0, VorbisfileCallbacks)) < 0) {
+	fprintf(stderr, "E: input not an Ogg Vorbis audio stream.\n");
+	return;
+      }
+    }
+#if 0
+      /* old stream code */
     if (strcmp(opt.read_file, "-")) {	/* input file not stdin */
         if (!strncmp(opt.read_file, "http://", 7)) {
             /* Stream down over http */
@@ -391,42 +449,27 @@
             free(server);
             free(path);
         } else {
-	    if (opt.quiet < 1)
-		fprintf(stderr, "Playing from file %s.\n", opt.read_file);
-	    /* Open the file. */
-	    if ((opt.instream = fopen(opt.read_file, "rb")) == NULL) {
-		fprintf(stderr, "Error opening input file.\n");
-		exit(1);
-	    }
         }
-    } else {
-	if (opt.quiet < 1)
-	    fprintf(stderr, "Playing from standard input.\n");
-	opt.instream = stdin;
-    }
-
-    if ((ov_open(opt.instream, &vf, NULL, 0)) < 0) {
-	fprintf(stderr, "E: input not an Ogg Vorbis audio stream.\n");
-	return;
     }
-
+#endif
+    
     /* 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 (opt.delay > 0) {
-        skipfile_requested = 0;
-	signal(SIGALRM,signal_activate_skipfile);
-	alarm(opt.delay);
+      skipfile_requested = 0;
+      signal(SIGALRM,signal_activate_skipfile);
+      alarm(opt.delay);
     }
-
+    
     while (!eof) {
-	int i;
-	vorbis_comment *vc = ov_comment(&vf, -1);
-	vorbis_info *vi = ov_info(&vf, -1);
-
-	if(open_audio_devices(&opt, vi->rate, vi->channels) < 0)
-		exit(1);
+      int i;
+      vorbis_comment *vc = ov_comment(&vf, -1);
+      vorbis_info *vi = ov_info(&vf, -1);
+      
+      if(open_audio_devices(&opt, vi->rate, vi->channels) < 0)
+	exit(1);
 
         if (opt.quiet < 1) {
             if (eos && opt.verbose) fprintf (stderr, "\r                                                                          \r\n");

No                   revision

No                   revision

1.1.2.1   +247 -0    vorbis-tools/ogg123/Attic/curl_interface.c

1.1.2.1   +69 -0     vorbis-tools/ogg123/Attic/curl_interface.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