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

Kenneth C. Arnold kcarnold at xiph.org
Mon Dec 25 14:20:42 PST 2000



kcarnold    00/12/25 14:20:42

  Modified:    ogg123   Makefile.am ogg123.c ogg123.h
  Added:       ogg123   ao_interface.c
  Log:
  Abstracted libao output functions to a separate file (cleanup, and makes
  interfacing to the buffer code (coming!) easier). Removed some unneeded
  #include's in ogg123.c.

Revision  Changes    Path
1.8       +3 -1      vorbis-tools/ogg123/Makefile.am

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Makefile.am	2000/11/18 05:36:32	1.7
+++ Makefile.am	2000/12/25 22:20:41	1.8
@@ -12,7 +12,9 @@
 
 ogg123_LDFLAGS = @OGG_LIBS@ @VORBIS_LIBS@ @VORBISFILE_LIBS@ @AO_LIBS@
 
-ogg123_SOURCES = ogg123.c
+ogg123_INCLUDES = ogg123.h
+
+ogg123_SOURCES = ogg123.c ao_interface.c
 
 EXTRA_DIST = $(man_MANS) $(doc_DATA)
 

1.16      +3 -104    vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ogg123.c	2000/12/25 22:03:24	1.15
+++ ogg123.c	2000/12/25 22:20:41	1.16
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.15 2000/12/25 22:03:24 kcarnold Exp $
+ last mod: $Id: ogg123.c,v 1.16 2000/12/25 22:20:41 kcarnold Exp $
 
  ********************************************************************/
 
@@ -22,24 +22,14 @@
 
 #define OGG123_VERSION "0.6 (CVS post-beta3)"
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
 #include <netdb.h>
 #include <netinet/in.h>
 #include <errno.h>
-#include <math.h>
 #include <getopt.h>
-#include <fcntl.h>
 #include <time.h>
-#include <sys/time.h>
-#include <ogg/ogg.h>
-#include <vorbis/codec.h>
-#include <vorbis/vorbisfile.h>
-#include <ao/ao.h>
 
 #include "ogg123.h"
 
@@ -75,34 +65,6 @@
     {0, 0, 0, 0}
 };
 
-devices_t *append_device(devices_t * devices_list, int driver_id,
-			 ao_option_t * options)
-{
-    devices_t *head = devices_list;
-
-    if (devices_list != NULL) {
-	while (devices_list->next_device != NULL)
-	    devices_list = devices_list->next_device;
-	devices_list = devices_list->next_device =
-	    malloc(sizeof(devices_t));
-    } else {
-	head = devices_list = (devices_t *) malloc(sizeof(devices_t));
-    }
-    devices_list->driver_id = driver_id;
-    devices_list->options = options;
-    devices_list->next_device = NULL;
-
-    return head;
-}
-
-void devices_write(void *ptr, size_t size, devices_t * d)
-{
-    while (d != NULL) {
-	ao_play(d->device, ptr, size);
-	d = d->next_device;
-    }
-}
-
 void usage(void)
 {
     FILE *o;
@@ -125,69 +87,6 @@
             "  -v, --verbose  display progress and other useful stuff\n"
             "  -q, --quiet    don't display anything (no title)\n"
             "  -z, --shuffle  shuffle play\n");
-}
-
-int add_option(ao_option_t ** op_h, const char *optstring)
-{
-    char *key, *value;
-    int result;
-
-    key = strdup(optstring);
-    if (key == NULL)
-	return 0;
-
-    value = strchr(key, ':');
-    if (value == NULL) {
-	free(key);
-	return 0;
-    }
-
-    /* split by replacing the separator with a null */
-    *value++ = '\0';
-
-    result = ao_append_option(op_h, key, value);
-    free(key);
-
-    return (result);
-}
-
-int get_default_device(void)
-{
-    FILE *fp;
-    char filename[NAME_MAX];
-    char line[100];
-    char *device = NULL;
-    char *homedir = getenv("HOME");
-    int i;
-
-    /* Maybe I'm being extremely paranoid, but if ogg123 is ever suid
-       root (to access audio devices), this is a possible buffer overflow. */
-    if (homedir == NULL || strlen(homedir) >= NAME_MAX - 10)
-	return -1;
-
-    strncpy(filename, homedir, NAME_MAX);
-    strcat(filename, "/.ogg123rc");
-
-
-    /* This is a very simplistic parser. If more options are ever added,
-       it will need a serious overhaul. */
-    fp = fopen(filename, "r");
-    if (fp) {
-      if (fgets(line, 100, fp)) {
-	if (strncmp(line, "default_device=", 15) == 0) {
-	  device = &line[15];
-	  for (i = 0; i < strlen(device); i++)
-	    if (device[i] == '\n' || device[i] == '\r')
-	      device[i] = 0;
-	}
-      }
-      fclose(fp);
-    }
-    
-    if (device)
-      return ao_get_driver_id(device);
-    
-    return -1;
 }
 
 int main(int argc, char **argv)

1.2       +6 -0      vorbis-tools/ogg123/ogg123.h

Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ogg123.h	2000/12/25 22:03:24	1.1
+++ ogg123.h	2000/12/25 22:20:41	1.2
@@ -3,6 +3,12 @@
 #ifndef __OGG123_H
 #define __OGG123_H
 
+/* Common includes */
+#include <ogg/ogg.h>
+#include <vorbis/codec.h>
+#include <vorbis/vorbisfile.h>
+#include <ao/ao.h>
+
 /* For facilitating output to multiple devices */
 typedef struct devices_s {
   int driver_id;

1.1                  vorbis-tools/ogg123/ao_interface.c

Index: ao_interface.c
===================================================================
#include <string.h>
#include <limits.h>

#include "ogg123.h"

devices_t *append_device(devices_t * devices_list, int driver_id,
                         ao_option_t * options)
{
    devices_t *head = devices_list;

    if (devices_list != NULL) {
        while (devices_list->next_device != NULL)
            devices_list = devices_list->next_device;
        devices_list = devices_list->next_device =
            malloc(sizeof(devices_t));
    } else {
        head = devices_list = (devices_t *) malloc(sizeof(devices_t));
    }
    devices_list->driver_id = driver_id;
    devices_list->options = options;
    devices_list->next_device = NULL;

    return head;
}

void devices_write(void *ptr, size_t size, devices_t * d)
{
    while (d != NULL) {
        ao_play(d->device, ptr, size);
        d = d->next_device;
    }
}

int add_option(ao_option_t ** op_h, const char *optstring)
{
    char *key, *value;
    int result;

    key = strdup(optstring);
    if (key == NULL)
        return 0;

    value = strchr(key, ':');
    if (value == NULL) {
        free(key);
        return 0;
    }

    /* split by replacing the separator with a null */
    *value++ = '\0';

    result = ao_append_option(op_h, key, value);
    free(key);

    return (result);
}

int get_default_device(void)
{
    FILE *fp;
    char filename[NAME_MAX];
    char line[100];
    char *device = NULL;
    char *homedir = getenv("HOME");
    int i;

    /* Maybe I'm being extremely paranoid, but if ogg123 is ever suid
       root (to access audio devices), this is a possible buffer overflow. */
    if (homedir == NULL || strlen(homedir) >= NAME_MAX - 10)
        return -1;

    strncpy(filename, homedir, NAME_MAX);
    strcat(filename, "/.ogg123rc");

    /* This is a very simplistic parser. If more options are ever added,
       it will need a serious overhaul. */
    fp = fopen(filename, "r");
    if (fp) {
      if (fgets(line, 100, fp)) {
        if (strncmp(line, "default_device=", 15) == 0) {
          device = &line[15];
          for (i = 0; i < strlen(device); i++)
            if (device[i] == '\n' || device[i] == '\r')
              device[i] = 0;
        }
      }
      fclose(fp);
    }
    
    if (device)
      return ao_get_driver_id(device);
    
    return -1;
}

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