make module-oss-* use modargs

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@63 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-07-11 23:21:32 +00:00
parent 216591d95e
commit d4e0d51c15
7 changed files with 135 additions and 70 deletions

View file

@ -17,6 +17,7 @@
#include "oss-util.h"
#include "sample-util.h"
#include "util.h"
#include "modargs.h"
struct userdata {
struct pa_sink *sink;
@ -31,6 +32,19 @@ struct userdata {
int fd;
};
static const char* const valid_modargs[] = {
"sink_name",
"source_name",
"device",
"record",
"playback",
NULL
};
#define DEFAULT_SINK_NAME "oss_output"
#define DEFAULT_SOURCE_NAME "oss_input"
#define DEFAULT_DEVICE "/dev/dsp"
static void do_write(struct userdata *u) {
struct pa_memchunk *memchunk;
ssize_t r;
@ -115,39 +129,34 @@ static uint32_t sink_get_latency_cb(struct pa_sink *s) {
int pa_module_init(struct pa_core *c, struct pa_module*m) {
struct audio_buf_info info;
struct userdata *u = NULL;
char *p;
const char *p;
int fd = -1;
int frag_size, in_frag_size, out_frag_size;
int mode;
uint32_t record = 1, playback = 1;
struct pa_sample_spec ss;
struct pa_modargs *ma = NULL;
assert(c && m);
p = m->argument ? m->argument : "/dev/dsp";
if ((fd = open(p, (mode = O_RDWR)|O_NDELAY)) >= 0) {
int caps;
ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
if (ioctl(fd, SNDCTL_DSP_GETCAPS, &caps) < 0) {
fprintf(stderr, "SNDCTL_DSP_GETCAPS: %s\n", strerror(errno));
goto fail;
}
if (!(caps & DSP_CAP_DUPLEX)) {
close(fd);
fd = -1;
}
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
fprintf(stderr, __FILE__": failed to parse module arguments.\n");
goto fail;
}
if (pa_modargs_get_value_u32(ma, "record", &record) < 0 || pa_modargs_get_value_u32(ma, "playback", &playback) < 0) {
fprintf(stderr, __FILE__": record= and playback= expect numeric argument.\n");
goto fail;
}
if (fd < 0) {
if ((fd = open(p, (mode = O_WRONLY)|O_NDELAY)) < 0) {
if ((fd = open(p, (mode = O_RDONLY)|O_NDELAY)) < 0) {
fprintf(stderr, "open('%s'): %s\n", p, strerror(errno));
goto fail;
}
}
mode = (playback&&record) ? O_RDWR : (playback ? O_WRONLY : (record ? O_RDONLY : 0));
if (mode == 0) {
fprintf(stderr, __FILE__": neither playback nor record enabled for device.\n");
goto fail;
}
if ((fd = pa_oss_open(p = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), &mode, NULL)) < 0)
goto fail;
fprintf(stderr, "module-oss: device opened in %s mode.\n", mode == O_WRONLY ? "O_WRONLY" : (mode == O_RDONLY ? "O_RDONLY" : "O_RDWR"));
frag_size = ((int) 12 << 16) | 10; /* nfrags = 12; frag_size = 2^10 */
@ -182,7 +191,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->core = c;
if (mode != O_WRONLY) {
u->source = pa_source_new(c, "oss_input", 0, &ss);
u->source = pa_source_new(c, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss);
assert(u->source);
u->source->userdata = u;
pa_source_set_owner(u->source, m);
@ -191,7 +200,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
u->source = NULL;
if (mode != O_RDONLY) {
u->sink = pa_sink_new(c, "oss_output", 0, &ss);
u->sink = pa_sink_new(c, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss);
assert(u->sink);
u->sink->get_latency = sink_get_latency_cb;
u->sink->userdata = u;
@ -226,6 +235,9 @@ fail:
if (fd >= 0)
close(fd);
if (ma)
pa_modargs_free(ma);
return -1;
}