Make libao.conf less useless: make it possible to prepend switches to ao_open_live()
I'm too busy to rewrite my entire story. Your Trac ate my description because it contained a link. Thanks and good day, sir!
--- src/ao_private.h Fri Aug 29 20:18:32 2003
+++ src/ao_private.h Sat Mar 3 17:14:59 2007
@@ -61,6 +61,7 @@
typedef struct ao_config {
char *default_driver;
+ ao_option *prepended;
} ao_config;
/* --- Functions --- */
--- src/audio_out.c Tue Mar 9 16:35:41 2004
+++ src/audio_out.c Sat Mar 3 17:23:18 2007
@@ -80,7 +80,8 @@
static driver_list *driver_head = NULL;
static ao_config config = {
- NULL /* default_driver */
+ NULL /* default_driver */,
+ NULL /* prepended options */
};
static ao_info **info_table = NULL;
@@ -446,6 +447,7 @@
static ao_device* _open_device(int driver_id, ao_sample_format *format,
ao_option *options, FILE *file)
{
+ ao_option *prepended = config.prepended;
ao_functions *funcs;
driver_list *driver;
ao_device *device;
@@ -486,6 +488,12 @@
return NULL; /* Couldn't init internal memory */
}
+ /* Default options */
+ while (prepended != NULL) {
+ /* Ignore errors */
+ funcs->set_option(device, prepended->key, prepended->value);
+ prepended = prepended->next;
+ }
/* Load options */
while (options != NULL) {
if (!funcs->set_option(device, options->key, options->value)) {
--- src/config.c Thu Aug 7 17:44:36 2003
+++ src/config.c Sat Mar 3 17:17:28 2007
@@ -23,6 +23,7 @@
*
*/
+#include "ao/ao.h"
#include "ao_private.h"
#include <stdio.h>
#include <stdlib.h>
@@ -52,7 +53,8 @@
int read_config_file(ao_config *config, const char *config_file)
{
FILE *fp;
- char line[LINE_LEN];
+ ao_option *aopt;
+ char line[LINE_LEN], *split;
int end;
@@ -60,15 +62,32 @@
return 0; /* Can't open file */
while (fgets(line, LINE_LEN, fp)) {
- /* All options are key=value */
+ /* Remove trailing newline */
+ end = strlen(line);
+ if (line[end-1] == '\n')
+ line[end-1] = '\0';
if (strncmp(line, "default_driver=", 15) == 0) {
+ /* Store default driver for efficiency */
free(config->default_driver);
- end = strlen(line);
- if (line[end-1] == '\n')
- line[end-1] = 0; /* Remove trailing newline */
-
config->default_driver = strdup(line+15);
+ } else {
+ /* All options are key=value */
+ split = strchr(line, '=');
+ if (split == NULL || split[1] == '\0')
+ continue;
+
+ /* Add new option to the list */
+ aopt = malloc(sizeof(ao_option));
+ if (aopt == NULL)
+ continue;
+ aopt->next = config->prepended;
+ config->prepended = aopt;
+
+ /* Split line in two and copy key/value */
+ *split = '\0';
+ aopt->key = strdup(line);
+ aopt->value = strdup(split + 1);
}
}