#include <unistd.h>
#include <limits.h>
+#include <polyp/xmalloc.h>
+
+#include <polypcore/core-error.h>
#include <polypcore/iochannel.h>
#include <polypcore/sink.h>
#include <polypcore/source.h>
#include <polypcore/module.h>
#include <polypcore/sample-util.h>
-#include <polypcore/util.h>
+#include <polypcore/core-util.h>
#include <polypcore/modargs.h>
-#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "oss-util.h"
PA_MODULE_AUTHOR("Lennart Poettering")
PA_MODULE_DESCRIPTION("OSS Sink/Source")
PA_MODULE_VERSION(PACKAGE_VERSION)
-PA_MODULE_USAGE("sink_name=<name for the sink> source_name=<name for the source> device=<OSS device> record=<enable source?> playback=<enable sink?> format=<sample format> channels=<number of channels> rate=<sample rate> fragments=<number of fragments> fragment_size=<fragment size>")
+PA_MODULE_USAGE(
+ "sink_name=<name for the sink> "
+ "source_name=<name for the source> "
+ "device=<OSS device> "
+ "record=<enable source?> "
+ "playback=<enable sink?> "
+ "format=<sample format> "
+ "channels=<number of channels> "
+ "rate=<sample rate> "
+ "fragments=<number of fragments> "
+ "fragment_size=<fragment size> "
+ "channel_map=<channel map>")
struct userdata {
pa_sink *sink;
"format",
"rate",
"channels",
+ "channel_map",
NULL
};
assert(memchunk->length);
if ((r = pa_iochannel_write(u->io, (uint8_t*) memchunk->memblock->data + memchunk->index, memchunk->length)) < 0) {
- pa_log(__FILE__": write() failed: %s", strerror(errno));
+ pa_log(__FILE__": write() failed: %s", pa_cstrerror(errno));
break;
}
if ((r = pa_iochannel_read(u->io, memchunk.memblock->data, memchunk.memblock->length)) < 0) {
pa_memblock_unref(memchunk.memblock);
if (errno != EAGAIN)
- pa_log(__FILE__": read() failed: %s", strerror(errno));
+ pa_log(__FILE__": read() failed: %s", pa_cstrerror(errno));
break;
}
assert(s && u && u->sink);
if (ioctl(u->fd, SNDCTL_DSP_GETODELAY, &arg) < 0) {
- pa_log_info(__FILE__": device doesn't support SNDCTL_DSP_GETODELAY: %s", strerror(errno));
+ pa_log_info(__FILE__": device doesn't support SNDCTL_DSP_GETODELAY: %s", pa_cstrerror(errno));
s->get_latency = NULL;
return 0;
}
static int sink_get_hw_volume(pa_sink *s) {
struct userdata *u = s->userdata;
- if (pa_oss_get_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
- pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", strerror(errno));
+ if (pa_oss_get_pcm_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
+ pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
s->get_hw_volume = NULL;
return -1;
}
static int sink_set_hw_volume(pa_sink *s) {
struct userdata *u = s->userdata;
- if (pa_oss_set_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
- pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", strerror(errno));
+ if (pa_oss_set_pcm_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
+ pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", pa_cstrerror(errno));
+ s->set_hw_volume = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int source_get_hw_volume(pa_source *s) {
+ struct userdata *u = s->userdata;
+
+ if (pa_oss_get_input_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
+ pa_log_info(__FILE__": device doesn't support reading mixer settings: %s", pa_cstrerror(errno));
+ s->get_hw_volume = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int source_set_hw_volume(pa_source *s) {
+ struct userdata *u = s->userdata;
+
+ if (pa_oss_set_input_volume(u->fd, &s->sample_spec, &s->hw_volume) < 0) {
+ pa_log_info(__FILE__": device doesn't support writing mixer settings: %s", pa_cstrerror(errno));
s->set_hw_volume = NULL;
return -1;
}
int mode;
int record = 1, playback = 1;
pa_sample_spec ss;
+ pa_channel_map map;
pa_modargs *ma = NULL;
char hwdesc[64];
}
mode = (playback&&record) ? O_RDWR : (playback ? O_WRONLY : (record ? O_RDONLY : 0));
+
+ ss = c->default_sample_spec;
+ if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_OSS) < 0) {
+ pa_log(__FILE__": failed to parse sample specification or channel map");
+ goto fail;
+ }
+ /* Fix latency to 100ms */
nfrags = 12;
- frag_size = 1024;
+ frag_size = pa_bytes_per_second(&ss)/128;
+
if (pa_modargs_get_value_s32(ma, "fragments", &nfrags) < 0 || pa_modargs_get_value_s32(ma, "fragment_size", &frag_size) < 0) {
pa_log(__FILE__": failed to parse fragments arguments");
goto fail;
}
- ss = c->default_sample_spec;
- if (pa_modargs_get_sample_spec(ma, &ss) < 0) {
- pa_log(__FILE__": failed to parse sample specification");
- goto fail;
- }
-
if ((fd = pa_oss_open(p = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), &mode, NULL)) < 0)
goto fail;
goto fail;
if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &frag_size) < 0) {
- pa_log(__FILE__": SNDCTL_DSP_GETBLKSIZE: %s", strerror(errno));
+ pa_log(__FILE__": SNDCTL_DSP_GETBLKSIZE: %s", pa_cstrerror(errno));
goto fail;
}
assert(frag_size);
}
if (mode != O_WRONLY) {
- u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, NULL);
- assert(u->source);
+ if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map)))
+ goto fail;
+
u->source->userdata = u;
u->source->notify = source_notify_cb;
u->source->get_latency = source_get_latency_cb;
+ u->source->get_hw_volume = source_get_hw_volume;
+ u->source->set_hw_volume = source_set_hw_volume;
pa_source_set_owner(u->source, m);
u->source->description = pa_sprintf_malloc("Open Sound System PCM on '%s'%s%s%s",
p,
u->source = NULL;
if (mode != O_RDONLY) {
- u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, NULL);
- assert(u->sink);
+ if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map)))
+ goto fail;
+
u->sink->get_latency = sink_get_latency_cb;
u->sink->get_hw_volume = sink_get_hw_volume;
u->sink->set_hw_volume = sink_set_hw_volume;
* Without this snippet, poll will never register the fd as ready.
*/
if (u->source) {
- char buf[u->sample_size];
+ char *buf = pa_xnew(char, u->sample_size);
read(u->fd, buf, u->sample_size);
+ pa_xfree(buf);
}
/* Read mixer settings */
+ if (u->source)
+ source_get_hw_volume(u->source);
if (u->sink)
sink_get_hw_volume(u->sink);
void pa__done(pa_core *c, pa_module*m) {
struct userdata *u;
- assert(c && m);
+
+ assert(c);
+ assert(m);
if (!(u = m->userdata))
return;