/*
* This file is part of DisOrder.
- * Copyright (C) 2007-2009 Richard Kettlewell
+ * Copyright (C) 2007-2009, 2011, 2013 Richard Kettlewell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
logdate = 1;
mem_init();
if(!setlocale(LC_CTYPE, "")) disorder_fatal(errno, "error calling setlocale");
- backend = uaudio_apis[0];
while((n = getopt_long(argc, argv, "hVdD:m:x:L:R:aocC:re:P:M", options, 0)) >= 0) {
switch(n) {
case 'h': help();
}
}
if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration");
+ if(!backend) {
+ backend = uaudio_default(uaudio_apis, UAUDIO_API_CLIENT);
+ if(!backend)
+ disorder_fatal(0, "no default uaudio API found");
+ disorder_info("default audio API %s", backend->name);
+ }
if(backend == &uaudio_rtp) {
/* This means that you have NO local sound output. This can happen if you
* use a non-Apple GCC on a Mac (because it doesn't know how to compile
mainloop = g_main_loop_new(0, 0);
if(config_read(0, NULL)) disorder_fatal(0, "cannot read configuration");
/* we'll need mixer support */
- backend = uaudio_apis[0];
+ backend = uaudio_default(uaudio_apis, UAUDIO_API_CLIENT);
if(backend->configure)
backend->configure();
if(backend->open_mixer)
else if(c->broadcast.af != -1)
c->api = xstrdup("rtp");
else if(config_uaudio_apis)
- c->api = xstrdup(config_uaudio_apis[0]->name);
+ c->api = xstrdup(uaudio_default(config_uaudio_apis,
+ UAUDIO_API_SERVER)->name);
else
c->api = xstrdup("<none>");
}
}
static void alsa_start(uaudio_callback *callback,
- void *userdata) {
+ void *userdata) {
if(uaudio_channels != 1 && uaudio_channels != 2)
disorder_fatal(0, "asked for %d channels but only support 1 or 2",
uaudio_channels);
.close_mixer = alsa_close_mixer,
.get_volume = alsa_get_volume,
.set_volume = alsa_set_volume,
- .configure = alsa_configure
+ .configure = alsa_configure,
+ .flags = UAUDIO_API_CLIENT | UAUDIO_API_SERVER,
};
#endif
}
static void command_start(uaudio_callback *callback,
- void *userdata) {
+ void *userdata) {
const char *pausemode = uaudio_get("pause-mode", "silence");
unsigned flags = 0;
.activate = uaudio_thread_activate,
.deactivate = uaudio_thread_deactivate,
.configure = command_configure,
+ .flags = UAUDIO_API_CLIENT | UAUDIO_API_SERVER,
};
/*
.activate = coreaudio_activate,
.deactivate = coreaudio_deactivate,
.configure = coreaudio_configure,
+ .flags = UAUDIO_API_CLIENT | UAUDIO_API_SERVER,
};
#endif
.get_volume = oss_get_volume,
.set_volume = oss_set_volume,
.configure = oss_configure,
+ .flags = UAUDIO_API_CLIENT | UAUDIO_API_SERVER,
};
#endif
.activate = uaudio_thread_activate,
.deactivate = uaudio_thread_deactivate,
.configure = rtp_configure,
+ .flags = UAUDIO_API_SERVER,
};
/*
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
return xstrdup(*valuep);
}
-/** @brief Set sample format
+/** @brief Set sample format
* @param rate Sample rate in KHz
* @param channels Number of channels (i.e. 2 for stereo)
* @param bits Number of bits per channel (typically 8 or 16)
uaudio_sample_size = bits / CHAR_BIT;
}
+/** @brief Choose the default audio API by context
+ * @param apis Table of APIs or a null pointer
+ * @param context @ref UAUDIO_API_SERVER or @ref UAUDIO_API_CLIENT
+ * @return Default API or a null pointer
+ */
+const struct uaudio *uaudio_default(const struct uaudio *const *apis,
+ unsigned context) {
+ if(apis) {
+ for(int n = 0; apis[n]; ++n)
+ if(apis[n]->flags & context)
+ return apis[n];
+ }
+ return 0;
+}
+
/*
Local Variables:
c-basic-offset:2
/** @brief Set configuration */
void (*configure)(void);
-
+
+ /** @brief Descriptive flags */
+ unsigned flags;
};
+/** @brief API is suitable for clients */
+#define UAUDIO_API_CLIENT 0x0001
+
+/** @brief API is suitable for servers */
+#define UAUDIO_API_SERVER 0x0002
+
void uaudio_set_format(int rate, int channels, int samplesize, int signed_);
void uaudio_set(const char *name, const char *value);
char *uaudio_get(const char *name, const char *default_value);
void uaudio_schedule_sent(size_t nsamples_sent);
void uaudio_schedule_init(void);
const struct uaudio *uaudio_find(const char *name);
+const struct uaudio *uaudio_default(const struct uaudio *const *apis,
+ unsigned context);
extern uint64_t uaudio_schedule_timestamp;
extern int uaudio_schedule_reactivated;