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

Kenneth C. Arnold kcarnold at xiph.org
Wed Feb 21 18:49:13 PST 2001



kcarnold    01/02/21 18:49:13

  Modified:    ogg123   ogg123.c ogg123.h
  Log:
  Buffering works again. Messy solution though...

Revision  Changes    Path
1.28      +53 -56    vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- ogg123.c	2001/02/22 02:37:59	1.27
+++ ogg123.c	2001/02/22 02:49:12	1.28
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.27 2001/02/22 02:37:59 kcarnold Exp $
+ last mod: $Id: ogg123.c,v 1.28 2001/02/22 02:49:12 kcarnold Exp $
 
  ********************************************************************/
 
@@ -99,7 +99,6 @@
     ao_option_t *temp_options = NULL;
     ao_option_t ** current_options = &temp_options;
     int temp_driver_id = -1;
-    buf_t *buffer = NULL;
         devices_t *current;
 
     opt.read_file = NULL;
@@ -185,14 +184,6 @@
         exit(1);
     }
 
-    /* Open all of the devices */
-
-    if (opt.verbose > 0)
-	fprintf(stderr, "Opening devices...\n");
-
-    if (opt.buffer_size)
-      buffer = fork_writer (opt.buffer_size, opt.outdevices);
-    
     if (opt.shuffle) {
         /* Messy code that I didn't write -ken */
         int i;
@@ -210,19 +201,16 @@
         }
         for (i = 0; i < nb; i++) {
             opt.read_file = argv[p[i] + optind];
-	    play_file(opt, buffer);
+	    play_file(opt);
         }
     } else {
         while (optind < argc) {
             opt.read_file = argv[optind];
-	    play_file(opt, buffer);
+	    play_file(opt);
             optind++;
         }
     }
 
-    if (buffer != NULL)
-      buffer_shutdown (buffer);
-
     while (opt.outdevices != NULL) {
       ao_close(opt.outdevices->device);
       current = opt.outdevices->next_device;
@@ -235,7 +223,7 @@
     return (0);
 }
 
-void play_file(ogg123_options_t opt, buf_t *buffer)
+void play_file(ogg123_options_t opt)
 {
     /* Oh my gosh this is disgusting. Big cleanups here will include an
        almost complete rewrite of the hacked-out HTTP streaming, a shift
@@ -248,6 +236,7 @@
     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();
+    buf_t *buffer = NULL;
     double realseekpos = opt.seekpos;
 
     /* Junk left over from the failed info struct */
@@ -340,14 +329,14 @@
     }
 
     /* Throw the comments plus a few lines about the bitstream we're
-       ** decoding */
+     * decoding */
 
     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)
+	if(open_audio_devices(&opt, vi->rate, vi->channels, &buffer) < 0)
                 exit(1);
 
         if (opt.quiet < 1) {
@@ -381,7 +370,7 @@
 
         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 sond */
+	     * 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 (realseekpos > 0)
@@ -468,45 +457,53 @@
     return fdopen(sockfd, "r+b");
 }
 
-int open_audio_devices(ogg123_options_t *opt, int rate, int channels)
+int open_audio_devices(ogg123_options_t *opt, int rate, int channels, buf_t **buffer)
 {
-    static int prevrate=0, prevchan=0;
-    devices_t *current;
-
-    if(prevrate == rate && prevchan == channels)
-	return 0;
-
-	if(prevrate !=0 && prevchan!=0)
+  static int prevrate=0, prevchan=0;
+  devices_t *current;
+  
+  if(prevrate == rate && prevchan == channels)
+    return 0;
+  
+  if(prevrate !=0 && prevchan!=0)
         {
-		current = opt->outdevices;
-    	while (current != NULL) {
-	      ao_close(current->device);
-		  current = current->next_device;
-		}
-    }
-
-    prevrate = rate;
-    prevchan = channels;
-
-	current = opt->outdevices;
-    while (current != NULL) {
-	ao_info_t *info = ao_get_driver_info(current->driver_id);
-
-	if (opt->verbose > 0) {
-	    fprintf(stderr, "Device:   %s\n", info->name);
-	    fprintf(stderr, "Author:   %s\n", info->author);
-	    fprintf(stderr, "Comments: %s\n", info->comment);
-	    fprintf(stderr, "\n");	
-	}
-
-	current->device = ao_open(current->driver_id, 16, rate, channels,
-				  current->options);
-	if (current->device == NULL) {
-	    fprintf(stderr, "Error opening device.\n");
-	    return -1;
-	}
-	current = current->next_device;
+	  if (buffer != NULL) {
+	    buffer_shutdown (*buffer);
+	    *buffer = NULL;
+	  }
+
+	  current = opt->outdevices;
+	  while (current != NULL) {
+	    ao_close(current->device);
+	    current = current->next_device;
+	  }
+	}
+  
+  prevrate = rate;
+  prevchan = channels;
+  
+  current = opt->outdevices;
+  while (current != NULL) {
+    ao_info_t *info = ao_get_driver_info(current->driver_id);
+    
+    if (opt->verbose > 0) {
+      fprintf(stderr, "Device:   %s\n", info->name);
+      fprintf(stderr, "Author:   %s\n", info->author);
+      fprintf(stderr, "Comments: %s\n", info->comment);
+      fprintf(stderr, "\n");	
     }
-
+    
+    current->device = ao_open(current->driver_id, 16, rate, channels,
+			      current->options);
+    if (current->device == NULL) {
+      fprintf(stderr, "Error opening device.\n");
+      return -1;
+    }
+    current = current->next_device;
+  }
+  
+  if (opt->buffer_size)
+    *buffer = fork_writer (opt->buffer_size, opt->outdevices);
+  
     return 0;
 }

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

Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ogg123.h	2001/02/19 05:22:09	1.5
+++ ogg123.h	2001/02/22 02:49:12	1.6
@@ -42,9 +42,9 @@
 void usage(void);
 int add_option(ao_option_t ** op_h, const char *optstring);
 int get_default_device(void);
-void play_file(ogg123_options_t opt, buf_t *buffer);
+void play_file(ogg123_options_t opt);
 int get_tcp_socket(void); /* Will be going soon. */
 FILE *http_open(char *server, int port, char *path); /* ditto */
-int open_audio_devices(ogg123_options_t *opt, int rate, int channels);
+int open_audio_devices(ogg123_options_t *opt, int rate, int channels, buf_t ** buffer);
 
 #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