Mercurial > audlegacy-plugins
changeset 3049:9ec8a613a1d6
More OSS4 plugin changes
author | Michal Lipski <tallica@o2.pl> |
---|---|
date | Sat, 18 Apr 2009 13:59:58 +0200 |
parents | c269a0351b53 |
children | 504fe83d18c9 |
files | src/OSS4/OSS4.c src/OSS4/OSS4.h src/OSS4/audio.c src/OSS4/configure.c |
diffstat | 4 files changed, 84 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/src/OSS4/OSS4.c Fri Apr 17 17:31:14 2009 +0200 +++ b/src/OSS4/OSS4.c Sat Apr 18 13:59:58 2009 +0200 @@ -107,7 +107,6 @@ g_free(oss_cfg.alt_audio_device); oss_cfg.alt_audio_device = NULL; } - } static OutputPlugin oss4_op = {
--- a/src/OSS4/OSS4.h Fri Apr 17 17:31:14 2009 +0200 +++ b/src/OSS4/OSS4.h Sat Apr 18 13:59:58 2009 +0200 @@ -34,6 +34,7 @@ #include <glib.h> #define IS_BIG_ENDIAN (G_BYTE_ORDER == G_BIG_ENDIAN) +#define DEFAULT_MIXER "/dev/mixer" extern OutputPlugin op; @@ -50,6 +51,7 @@ int vol; void oss_configure(void); int oss_hardware_present(void); +void oss_describe_error(); void oss_get_volume(int *l, int *r); void oss_set_volume(int l, int r);
--- a/src/OSS4/audio.c Fri Apr 17 17:31:14 2009 +0200 +++ b/src/OSS4/audio.c Sat Apr 18 13:59:58 2009 +0200 @@ -19,9 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -static void oss_describe_error(); -static void close_mixer_device(); - #include <glib.h> #include <string.h> @@ -36,8 +33,7 @@ #define NFRAGS 32 -static gint fd = -1, mixerfd = -1; -static oss_sysinfo sysinfo; +static gint fd = -1; static char *buffer; static gboolean going, prebuffer, paused, unpause, do_pause, remove_prebuffer; static gint device_buffer_used, buffer_size, prebuffer_size, blk_size; @@ -85,17 +81,18 @@ */ struct format_info output; -int oss_hardware_present() +gint oss_hardware_present() { + gint mixerfd; + oss_sysinfo sysinfo; + /* - * Open the mixer device used for calling SNDCTL_SYSINFO and - * SNDCTL_AUDIOINFO. + * Open the mixer device used for calling SNDCTL_SYSINFO */ - if ((mixerfd = open("/dev/mixer", O_RDWR, 0)) == -1) + if ((mixerfd = open(DEFAULT_MIXER, O_RDWR, 0)) == -1) { - perror("/dev/mixer"); + perror(DEFAULT_MIXER); oss_describe_error(); - close_mixer_device(); return 0; } @@ -104,13 +101,13 @@ { perror("SNDCTL_SYSINFO"); oss_describe_error(); - close_mixer_device(); + close(mixerfd); return 0; } else { - close_mixer_device(); + close(mixerfd); if (sysinfo.numaudios > 0) { @@ -123,7 +120,7 @@ } } -static void +void oss_describe_error() { switch (errno) @@ -574,7 +571,11 @@ wr_index = 0; rd_index = 0; - close_mixer_device(); + if (fd != -1) + { + close(fd); + fd = -1; + } } void @@ -808,19 +809,3 @@ vol = (r << 8) | l; ioctl(fd, cmd, &vol); } - -void -close_mixer_device() -{ - if (fd != -1) - { - close(fd); - fd = -1; - } - - if (mixerfd != -1) - { - close(mixerfd); - mixerfd = -1; - } -}
--- a/src/OSS4/configure.c Fri Apr 17 17:31:14 2009 +0200 +++ b/src/OSS4/configure.c Sat Apr 18 13:59:58 2009 +0200 @@ -27,7 +27,7 @@ #include <string.h> #include <audlegacy/plugin.h> #include <audlegacy/i18n.h> - +#include <sys/ioctl.h> static GtkWidget *configure_win = NULL; static GtkWidget *mixer_save_check,*buffer_size_spin, *buffer_pre_spin; @@ -75,9 +75,9 @@ } static void -configure_win_audio_dev_cb(GtkWidget * widget, gint device) +configure_win_audio_dev_cb(GtkWidget * widget, gpointer data) { - audio_device = device; + audio_device = GPOINTER_TO_INT(data); } static void @@ -92,53 +92,76 @@ scan_devices(gchar * type, GtkWidget * option_menu, GtkSignalFunc sigfunc) { GtkWidget *menu, *item; - VFSFile *file; - gchar buffer[256], *temp, *tmp2; - gboolean found = FALSE; - gint index = 0; - + oss_sysinfo sysinfo; + gint mixerfd = -1; + gint i, acc; + menu = gtk_menu_new(); - - if ((file = aud_vfs_fopen("/dev/sndstat", "r"))) { - while (aud_vfs_fgets(buffer, 255, file)) { - if (found && buffer[0] == '\n') - break; - if (buffer[strlen(buffer) - 1] == '\n') - buffer[strlen(buffer) - 1] = '\0'; - if (found) { - if (index == 0) { - tmp2 = strchr(buffer, ':'); - if (tmp2) { - tmp2++; - while (*tmp2 == ' ') - tmp2++; - } - else - tmp2 = buffer; - temp = g_strdup_printf(_("Default (%s)"), tmp2); - item = gtk_menu_item_new_with_label(temp); - g_free(temp); + + /* + * Open the mixer device used for calling SNDCTL_SYSINFO and + * SNDCTL_AUDIOINFO. + */ + if ((mixerfd = open(DEFAULT_MIXER, O_RDWR, 0)) == -1) + { + perror(DEFAULT_MIXER); + oss_describe_error(); + } + else + { + if (ioctl(mixerfd, SNDCTL_SYSINFO, &sysinfo) == -1) + { + perror("SNDCTL_SYSINFO"); + oss_describe_error(); + close(mixerfd); + } + else + { + for (i = 0; i < sysinfo.numaudios; i++) + { + oss_audioinfo ainfo; + ainfo.dev = i; + + if (ioctl(mixerfd, SNDCTL_AUDIOINFO, &ainfo) == -1) + { + perror("SNDCTL_AUDIOINFO"); + oss_describe_error(); + close(mixerfd); } else - item = gtk_menu_item_new_with_label(buffer); - g_signal_connect(G_OBJECT(item), "activate", - G_CALLBACK(sigfunc), (gpointer)(long)(index++)); - gtk_widget_show(item); - gtk_menu_append(GTK_MENU(menu), item); + { + acc = ainfo.caps & (PCM_CAP_INPUT | PCM_CAP_OUTPUT); + + switch (acc) + { + case PCM_CAP_OUTPUT: + item = gtk_menu_item_new_with_label(g_strdup_printf("%d. %s (OUTPUT)", i, ainfo.name)); + break; + + case PCM_CAP_INPUT | PCM_CAP_OUTPUT: + item = gtk_menu_item_new_with_label(g_strdup_printf("%d. %s (INPUT/OUTPUT)", i, ainfo.name)); + break; + + case PCM_CAP_INPUT: + item = gtk_menu_item_new_with_label(g_strdup_printf("%d. %s (INPUT)", i, ainfo.name)); + break; + + default: + continue; + } + + gtk_widget_show(item); + gtk_menu_append(GTK_MENU(menu), item); + + g_signal_connect(G_OBJECT(item), "activate", + G_CALLBACK(sigfunc), GINT_TO_POINTER(i)); + } } - if (!strcasecmp(buffer, type)) - found = 1; + close(mixerfd); } - aud_vfs_fclose(file); } - else { - item = gtk_menu_item_new_with_label(_("Default")); - g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(sigfunc), - (gpointer) 0); - gtk_widget_show(item); - gtk_menu_append(GTK_MENU(menu), item); - } + gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu); }