Blob Blame History Raw
diff -Nur audacious-plugins-fedora-2.1-orig/src/alsa-ng/alsa-configure.c audacious-plugins-fedora-2.1/src/alsa-ng/alsa-configure.c
--- audacious-plugins-fedora-2.1-orig/src/alsa-ng/alsa-configure.c	2009-07-07 00:40:36.000000000 +0200
+++ audacious-plugins-fedora-2.1/src/alsa-ng/alsa-configure.c	2009-09-16 00:57:07.000000000 +0200
@@ -245,8 +245,7 @@
 
 void alsaplug_configure(void)
 {
-	GtkWidget *vbox, *notebook;
-	GtkWidget *dev_vbox, *adevice_frame, *adevice_box;
+        GtkWidget * vbox, * adevice_frame, * adevice_box;
 	GtkWidget *mixer_frame, *mixer_box, *mixer_table, *mixer_card_om;
 	GtkWidget *mixer_card_label, *mixer_device_label;
 	GtkWidget *bbox, *ok, *cancel;
@@ -259,31 +258,25 @@
 		return;
 	}
 
-	configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	gtk_signal_connect(GTK_OBJECT(configure_win), "destroy",
-			   GTK_SIGNAL_FUNC(gtk_widget_destroyed),
-			   &configure_win);
-	gtk_window_set_title(GTK_WINDOW(configure_win),
-			     _("ALSA Driver configuration"));
-	gtk_window_set_policy(GTK_WINDOW(configure_win),
-			      FALSE, TRUE, FALSE);
-	gtk_container_border_width(GTK_CONTAINER(configure_win), 10);
-
-	vbox = gtk_vbox_new(FALSE, 10);
-	gtk_container_add(GTK_CONTAINER(configure_win), vbox);
-
-	notebook = gtk_notebook_new();
-	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
-
-	dev_vbox = gtk_vbox_new(FALSE, 5);
-	gtk_container_set_border_width(GTK_CONTAINER(dev_vbox), 5);
-
-	adevice_frame = gtk_frame_new(_("Audio device:"));
-	gtk_box_pack_start(GTK_BOX(dev_vbox), adevice_frame, FALSE, FALSE, 0);
-
-	adevice_box = gtk_vbox_new(FALSE, 5);
-	gtk_container_set_border_width(GTK_CONTAINER(adevice_box), 5);
-	gtk_container_add(GTK_CONTAINER(adevice_frame), adevice_box);
+        configure_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+        gtk_window_set_title ((GtkWindow *) configure_win, _("ALSA Output "
+         "Plugin Preferences"));
+        gtk_window_set_type_hint ((GtkWindow *) configure_win,
+         GDK_WINDOW_TYPE_HINT_DIALOG);
+        gtk_window_set_resizable ((GtkWindow *) configure_win, FALSE);
+        gtk_container_set_border_width ((GtkContainer *) configure_win, 6);
+        g_signal_connect ((GObject *) configure_win, "destroy", (GCallback)
+         gtk_widget_destroyed, & configure_win);
+
+        vbox = gtk_vbox_new (FALSE, 6);
+        gtk_container_add ((GtkContainer *) configure_win, vbox);
+
+        adevice_frame = gtk_frame_new (_("Device:"));
+        gtk_box_pack_start ((GtkBox *) vbox, adevice_frame, FALSE, FALSE, 0);
+
+        adevice_box = gtk_vbox_new (FALSE, 6);
+        gtk_container_set_border_width ((GtkContainer *) adevice_box, 6);
+        gtk_container_add ((GtkContainer *) adevice_frame, adevice_box);
 
 	devices_combo = gtk_combo_new();
 	gtk_box_pack_start(GTK_BOX(adevice_box), devices_combo,
@@ -292,12 +285,12 @@
 	gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(devices_combo)->entry),
 			   alsaplug_cfg.pcm_device);
 
-	mixer_frame = gtk_frame_new(_("Mixer:"));
-	gtk_box_pack_start(GTK_BOX(dev_vbox), mixer_frame, FALSE, FALSE, 0);
+        mixer_frame = gtk_frame_new (_("Mixer:"));
+        gtk_box_pack_start ((GtkBox *) vbox, mixer_frame, FALSE, FALSE, 0);
 
-	mixer_box = gtk_vbox_new(FALSE, 5);
-	gtk_container_set_border_width(GTK_CONTAINER(mixer_box), 5);
-	gtk_container_add(GTK_CONTAINER(mixer_frame), mixer_box);
+        mixer_box = gtk_vbox_new (FALSE, 6);
+        gtk_container_set_border_width ((GtkContainer *) mixer_box, 6);
+        gtk_container_add ((GtkContainer *) mixer_frame, mixer_box);
 
 	mixer_table = gtk_table_new(2, 2, FALSE);
 	gtk_table_set_row_spacings(GTK_TABLE(mixer_table), 5);
@@ -331,9 +324,6 @@
 	gtk_table_attach(GTK_TABLE(mixer_table), mixer_devices_combo,
 			 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, 0, 0, 0);
 
-	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dev_vbox,
-				 gtk_label_new(_("Device settings")));
-
 	bbox = gtk_hbutton_box_new();
 	gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
 	gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
diff -Nur audacious-plugins-fedora-2.1-orig/src/alsa-ng/alsa-core.c audacious-plugins-fedora-2.1/src/alsa-ng/alsa-core.c
--- audacious-plugins-fedora-2.1-orig/src/alsa-ng/alsa-core.c	2009-07-07 00:40:36.000000000 +0200
+++ audacious-plugins-fedora-2.1/src/alsa-ng/alsa-core.c	2009-09-16 00:57:07.000000000 +0200
@@ -222,10 +222,14 @@
         else
         {
             gint err = snd_pcm_recover(pcm_handle, wr_frames, 1);
-            if (err < 0)
-                _ERROR("(write) snd_pcm_recover: %s", snd_strerror(err));
 
-            return;
+            _DEBUG ("snd_pcm_writei error: %s", snd_strerror (wr_frames));
+
+            if (err < 0)
+            {
+                _ERROR ("snd_pcm_recover error: %s", snd_strerror (err));
+                return;
+            }
         }
     }
 }
@@ -299,13 +303,40 @@
     if (alsaplug_cfg.mixer_card == NULL)
         alsaplug_cfg.mixer_card = g_strdup("default");
 
+    if (!alsaplug_mixer_new(&amixer))
+        mixer_ready = TRUE;
+
     return OUTPUT_PLUGIN_INIT_FOUND_DEVICES;
 }
 
+static void alsaplug_cleanup(void)
+{
+    if (mixer_ready == TRUE)
+    {
+        snd_mixer_detach(amixer, alsaplug_cfg.mixer_card);
+        snd_mixer_close(amixer);
+
+        amixer = NULL;
+        mixer_ready = FALSE;
+    }
+}
+
+#define CHECK_FAIL(expression, name) \
+{ \
+    gint error = expression; \
+    if (error) \
+    { \
+        _ERROR (name " failed: %s.\n", snd_strerror (error)); \
+        snd_pcm_close (pcm_handle); \
+        pcm_handle = NULL; \
+        return -1; \
+    } \
+}
+
 static gint
 alsaplug_open_audio(AFormat fmt, gint rate, gint nch)
 {
-    gint err, bitwidth, ringbuf_size;
+    gint err, bitwidth, ringbuf_size, buf_size;
     snd_pcm_format_t afmt;
     snd_pcm_hw_params_t *hwparams = NULL;
 
@@ -316,9 +347,6 @@
         return -1;
     }
 
-    if (!alsaplug_mixer_new(&amixer))
-        mixer_ready = TRUE;
-
     if ((err = snd_pcm_open(&pcm_handle, alsaplug_cfg.pcm_device, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
     {
         _ERROR("snd_pcm_open: %s", snd_strerror(err));
@@ -328,27 +356,31 @@
 
     snd_pcm_hw_params_alloca(&hwparams);
     snd_pcm_hw_params_any(pcm_handle, hwparams);
-    snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED);
-    snd_pcm_hw_params_set_format(pcm_handle, hwparams, afmt);
-    snd_pcm_hw_params_set_channels(pcm_handle, hwparams, nch);
-    snd_pcm_hw_params_set_rate(pcm_handle, hwparams, rate, 0);
 
-    err = snd_pcm_hw_params(pcm_handle, hwparams);
-    if (err < 0)
-    {
-        _ERROR("snd_pcm_hw_params failed: %s", snd_strerror(err));
-        return -1;
-    }
+    CHECK_FAIL (snd_pcm_hw_params_set_access (pcm_handle, hwparams,
+     SND_PCM_ACCESS_RW_INTERLEAVED), "snd_pcm_hw_params_set_access");
+    CHECK_FAIL (snd_pcm_hw_params_set_format (pcm_handle, hwparams, afmt),
+     "snd_pcm_hw_params_set_format");
+    CHECK_FAIL (snd_pcm_hw_params_set_channels (pcm_handle, hwparams, nch),
+     "snd_pcm_hw_params_set_channels");
+    CHECK_FAIL (snd_pcm_hw_params_set_rate (pcm_handle, hwparams, rate, 0),
+     "snd_pcm_hw_params_set_rate");
+    CHECK_FAIL (snd_pcm_hw_params (pcm_handle, hwparams), "snd_pcm_hw_params");
 
     bitwidth = snd_pcm_format_physical_width(afmt);
     bps = (rate * bitwidth * nch) >> 3;
-    ringbuf_size = aud_cfg->output_buffer_size * bps / 1000;
+
+    buf_size = MAX(aud_cfg->output_buffer_size, 100);
+    ringbuf_size = buf_size * bps / 1000;
+
     if (alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size) == -1) {
         _ERROR("alsaplug_ringbuffer_init failed");
         return -1;
     }
+
     pcm_going = TRUE;
     flush_request = -1;
+    paused = FALSE;
 
     audio_thread = g_thread_create(alsaplug_loop, NULL, TRUE, NULL);
     return 1;
@@ -371,15 +403,6 @@
         g_thread_join(audio_thread);
 
     audio_thread = NULL;
-
-    if (mixer_ready == TRUE)
-    {
-        snd_mixer_detach(amixer, alsaplug_cfg.mixer_card);
-        snd_mixer_close(amixer);
-
-        amixer = NULL;
-        mixer_ready = FALSE;
-    }
 }
 
 static void
@@ -500,6 +523,7 @@
     .description = "ALSA Output Plugin (-ng)",
     .probe_priority = 1,
     .init = alsaplug_init,
+    .cleanup = alsaplug_cleanup,
     .open_audio = alsaplug_open_audio,
     .close_audio = alsaplug_close_audio,
     .write_audio = alsaplug_write_audio,