Commit 7e50485a authored by Kenneth Arnold's avatar Kenneth Arnold

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.

svn path=/trunk/vorbis-tools/; revision=1129
parent 87178bf1
......@@ -12,7 +12,9 @@ INCLUDES = @OGG_CFLAGS@ @VORBIS_CFLAGS@ @AO_CFLAGS@
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)
......
#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;
}
......@@ -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 @@ struct option long_options[] = {
{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;
......@@ -127,69 +89,6 @@ void usage(void)
" -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)
{
ogg123_options_t opt;
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment