]> code.delx.au - pulseaudio/blobdiff - polyp/module-alsa-sink.c
Merge Pierre's changes
[pulseaudio] / polyp / module-alsa-sink.c
index 55e719c90677f825c742033b0a2d43d5828eb88e..dde5d8b6996d78b70d7679dbae0cde86f95dcf62 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 <assert.h>
 #include <stdio.h>
+
+#ifdef HAVE_SYS_POLL_H
 #include <sys/poll.h>
+#else
+#include "poll.h"
+#endif
 
 #include <asoundlib.h>
 
 #include "alsa-util.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-alsa-sink-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("ALSA Sink")
 PA_MODULE_VERSION(PACKAGE_VERSION)
+PA_MODULE_USAGE("sink_name=<name for the sink> device=<ALSA device> format=<sample format> channels=<number of channels> rate=<sample rate> fragments=<number of fragments> fragment_size=<fragment size>")
+
+#define PA_TYPEID_ALSA PA_TYPEID_MAKE('A', 'L', 'S', 'A')
 
 struct userdata {
     snd_pcm_t *pcm_handle;
@@ -67,7 +76,7 @@ static const char* const valid_modargs[] = {
 };
 
 #define DEFAULT_SINK_NAME "alsa_output"
-#define DEFAULT_DEVICE "plughw:0,0"
+#define DEFAULT_DEVICE "default"
 
 static void update_usage(struct userdata *u) {
    pa_module_set_used(u->module,
@@ -172,8 +181,8 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
     struct userdata *u = NULL;
     const char *dev;
     struct pa_sample_spec ss;
-    unsigned periods, fragsize;
-    snd_pcm_uframes_t buffer_size;
+    uint32_t periods, fragsize;
+    snd_pcm_uframes_t period_size;
     size_t frame_size;
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
@@ -188,29 +197,30 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
     }
     frame_size = pa_frame_size(&ss);
     
-    periods = 12;
+    periods = 8;
     fragsize = 1024;
     if (pa_modargs_get_value_u32(ma, "fragments", &periods) < 0 || pa_modargs_get_value_u32(ma, "fragment_size", &fragsize) < 0) {
         pa_log(__FILE__": failed to parse buffer metrics\n");
         goto fail;
     }
-    buffer_size = fragsize/frame_size*periods;
+    period_size = fragsize;
     
     u = pa_xmalloc0(sizeof(struct userdata));
     m->userdata = u;
     u->module = m;
     
+    snd_config_update_free_global();
     if (snd_pcm_open(&u->pcm_handle, dev = pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0) {
         pa_log(__FILE__": Error opening PCM device %s\n", dev);
         goto fail;
     }
 
-    if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &buffer_size) < 0) {
+    if (pa_alsa_set_hw_params(u->pcm_handle, &ss, &periods, &period_size) < 0) {
         pa_log(__FILE__": Failed to set hardware parameters\n");
         goto fail;
     }
 
-    u->sink = pa_sink_new(c, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss);
+    u->sink = pa_sink_new(c, PA_TYPEID_ALSA, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss);
     assert(u->sink);
 
     u->sink->get_latency = sink_get_latency_cb;
@@ -224,7 +234,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
     }
     
     u->frame_size = frame_size;
-    u->fragment_size = buffer_size*u->frame_size/periods;
+    u->fragment_size = period_size;
 
     pa_log(__FILE__": using %u fragments of size %u bytes.\n", periods, u->fragment_size);
 
@@ -259,8 +269,10 @@ void pa__done(struct pa_core *c, struct pa_module*m) {
     if (!(u = m->userdata))
         return;
     
-    if (u->sink)
-        pa_sink_free(u->sink);
+    if (u->sink) {
+        pa_sink_disconnect(u->sink);
+        pa_sink_unref(u->sink);
+    }
     
     if (u->io_events)
         pa_free_io_events(c->mainloop, u->io_events, u->n_io_events);