introduce pa_xmalloc() and friends

implement module auto loading


git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@103 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-08-04 16:39:30 +00:00
parent 24291aff27
commit 46091a9237
61 changed files with 700 additions and 631 deletions

View file

@ -37,6 +37,7 @@
#include "util.h"
#include "sample-util.h"
#include "alsa-util.h"
#include "xmalloc.h"
struct userdata {
snd_pcm_t *pcm_handle;
@ -46,6 +47,7 @@ struct userdata {
size_t frame_size, fragment_size;
struct pa_memchunk memchunk, silence;
struct pa_module *module;
};
static const char* const valid_modargs[] = {
@ -62,6 +64,12 @@ static const char* const valid_modargs[] = {
#define DEFAULT_SINK_NAME "alsa_output"
#define DEFAULT_DEVICE "plughw:0,0"
static void update_usage(struct userdata *u) {
pa_module_set_used(u->module,
(u->sink ? pa_idxset_ncontents(u->sink->inputs) : 0) +
(u->sink ? pa_idxset_ncontents(u->sink->monitor_source->outputs) : 0));
}
static void xrun_recovery(struct userdata *u) {
assert(u);
@ -74,6 +82,8 @@ static void xrun_recovery(struct userdata *u) {
static void do_write(struct userdata *u) {
assert(u);
update_usage(u);
for (;;) {
struct pa_memchunk *memchunk = NULL;
snd_pcm_sframes_t frames;
@ -175,10 +185,9 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
}
buffer_size = fragsize/frame_size*periods;
u = malloc(sizeof(struct userdata));
assert(u);
memset(u, 0, sizeof(struct userdata));
u = pa_xmalloc0(sizeof(struct userdata));
m->userdata = u;
u->module = m;
if (snd_pcm_open(&u->pcm_handle, dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) {
fprintf(stderr, __FILE__": Error opening PCM device %s\n", dev);
@ -236,24 +245,25 @@ void pa_module_done(struct pa_core *c, struct pa_module*m) {
struct userdata *u;
assert(c && m);
if ((u = m->userdata)) {
if (u->sink)
pa_sink_free(u->sink);
if (u->io_sources)
pa_free_io_sources(c->mainloop, u->io_sources, u->n_io_sources);
if (u->pcm_handle) {
snd_pcm_drop(u->pcm_handle);
snd_pcm_close(u->pcm_handle);
}
if (u->memchunk.memblock)
pa_memblock_unref(u->memchunk.memblock);
if (u->silence.memblock)
pa_memblock_unref(u->silence.memblock);
free(u);
if (!(u = m->userdata))
return;
if (u->sink)
pa_sink_free(u->sink);
if (u->io_sources)
pa_free_io_sources(c->mainloop, u->io_sources, u->n_io_sources);
if (u->pcm_handle) {
snd_pcm_drop(u->pcm_handle);
snd_pcm_close(u->pcm_handle);
}
if (u->memchunk.memblock)
pa_memblock_unref(u->memchunk.memblock);
if (u->silence.memblock)
pa_memblock_unref(u->silence.memblock);
pa_xfree(u);
}