]> code.delx.au - pulseaudio/blobdiff - polyp/module-alsa-source.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / module-alsa-source.c
index 520b68300762e3a29bff83cc9a441201d903f04e..ba09d319da1e550333c0759142de286fa085957e 100644 (file)
@@ -4,7 +4,7 @@
   This file is part of polypaudio.
  
   polypaudio is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published
+  it under the terms of the GNU Lesser General Public License as published
   by the Free Software Foundation; either version 2 of the License,
   or (at your option) any later version.
  
@@ -13,7 +13,7 @@
   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
+  You should have received a copy of the GNU Lesser General Public License
   along with polypaudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 #include "alsa-util.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-alsa-source-symdef.h"
+
+PA_MODULE_AUTHOR("Lennart Poettering")
+PA_MODULE_DESCRIPTION("ALSA Source")
+PA_MODULE_VERSION(PACKAGE_VERSION)
+PA_MODULE_USAGE("source_name=<name for the source> device=<ALSA device> format=<sample format> channels=<number of channels> rate=<sample rate> fragments=<number of fragments> fragment_size=<fragment size>")
 
 struct userdata {
     snd_pcm_t *pcm_handle;
@@ -54,9 +60,9 @@ struct userdata {
 static const char* const valid_modargs[] = {
     "device",
     "source_name",
-    "format",
     "channels",
     "rate",
+    "format",
     "fragments",
     "fragment_size",
     NULL
@@ -139,7 +145,21 @@ static void io_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int fd,
     do_read(u);
 }
 
-int pa_module_init(struct pa_core *c, struct pa_module*m) {
+static pa_usec_t source_get_latency_cb(struct pa_source *s) {
+    struct userdata *u = s->userdata;
+    snd_pcm_sframes_t frames;
+    assert(s && u && u->source);
+
+    if (snd_pcm_delay(u->pcm_handle, &frames) < 0) {
+        pa_log(__FILE__": failed to get delay\n");
+        s->get_latency = NULL;
+        return 0;
+    }
+
+    return pa_bytes_to_usec(frames * u->frame_size, &s->sample_spec);
+}
+
+int pa__init(struct pa_core *c, struct pa_module*m) {
     struct pa_modargs *ma = NULL;
     int ret = -1;
     struct userdata *u = NULL;
@@ -187,6 +207,7 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
     assert(u->source);
 
     u->source->userdata = u;
+    u->source->get_latency = source_get_latency_cb;
     pa_source_set_owner(u->source, m);
     u->source->description = pa_sprintf_malloc("Advanced Linux Sound Architecture PCM on '%s'", dev);
 
@@ -216,20 +237,22 @@ finish:
 fail:
     
     if (u)
-        pa_module_done(c, m);
+        pa__done(c, m);
 
     goto finish;
 }
 
-void pa_module_done(struct pa_core *c, struct pa_module*m) {
+void pa__done(struct pa_core *c, struct pa_module*m) {
     struct userdata *u;
     assert(c && m);
 
     if (!(u = m->userdata))
         return;
     
-    if (u->source)
-        pa_source_free(u->source);
+    if (u->source) {
+        pa_source_disconnect(u->source);
+        pa_source_unref(u->source);
+    }
     
     if (u->io_events)
         pa_free_io_events(c->mainloop, u->io_events, u->n_io_events);