Enlightenment CVS committal Author : codewarrior Project : e_modules Module : mixer
Dir : e_modules/mixer Modified Files: Makefile.am alsa_mixer.c config.h.in configure.in e_mod_main.c oss_mixer.c oss_mixer.h Log Message: FreeBSD anyone? Thank you sir! - [configure.in] better checks for oss / newpcm / alsa - [oss] implement oss support (tested for FreeBSD) - [todo] need to free resources when we're unloaded, better channel support for oss. =================================================================== RCS file: /cvs/e/e_modules/mixer/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- Makefile.am 12 Sep 2006 20:57:47 -0000 1.6 +++ Makefile.am 14 Sep 2006 14:14:45 -0000 1.7 @@ -34,6 +34,8 @@ e_mod_types.h \ alsa_mixer.h \ alsa_mixer.c \ + oss_mixer.h \ + oss_mixer.c \ e_mod_config.c module_la_LIBADD = @e_libs@ @SOUND_LDFLAGS@ =================================================================== RCS file: /cvs/e/e_modules/mixer/alsa_mixer.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -3 -r1.22 -r1.23 --- alsa_mixer.c 12 Sep 2006 21:42:00 -0000 1.22 +++ alsa_mixer.c 14 Sep 2006 14:14:45 -0000 1.23 @@ -1,4 +1,6 @@ #include <e.h> +#include "config.h" +#ifdef HAVE_ALSA #include "e_mod_types.h" #include "alsa_mixer.h" @@ -627,3 +629,5 @@ } return NULL; } + +#endif =================================================================== RCS file: /cvs/e/e_modules/mixer/config.h.in,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- config.h.in 7 Sep 2006 22:07:14 -0000 1.2 +++ config.h.in 14 Sep 2006 14:14:45 -0000 1.3 @@ -1,17 +1,26 @@ /* config.h.in. Generated from configure.in by autoheader. */ +/* Define if the ALSA output plugin should be built */ +#undef HAVE_ALSA + /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 if you have the `asound' library (-lasound). */ -#undef HAVE_LIBASOUND +/* Define to 1 if you have the <machine/soundcard.h> header file. */ +#undef HAVE_MACHINE_SOUNDCARD_H /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H +/* Define if you have the FreeBSD newpcm driver */ +#undef HAVE_NEWPCM + +/* Define if the OSS output plugin should be built */ +#undef HAVE_OSS + /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H @@ -23,6 +32,9 @@ /* Define to 1 if you have the <string.h> header file. */ #undef HAVE_STRING_H + +/* Define to 1 if you have the <sys/soundcard.h> header file. */ +#undef HAVE_SYS_SOUNDCARD_H /* Define to 1 if you have the <sys/stat.h> header file. */ #undef HAVE_SYS_STAT_H =================================================================== RCS file: /cvs/e/e_modules/mixer/configure.in,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- configure.in 12 Sep 2006 12:40:42 -0000 1.5 +++ configure.in 14 Sep 2006 14:14:45 -0000 1.6 @@ -153,22 +153,85 @@ if test "x$enable_alsa" = "xdefault" || test "x$enable_alsa" = "xyes"; then if test "x$uname" = "xLinux"; then - AM_PATH_ALSA(1.0.9, - [ SOUND_CFLAGS="$ALSA_CFLAGS -DHAVE_ALSA $SOUND_CFLAGS" - SOUND_LDFLAGS="$ALSA_LIBS $SOUND_LDFLAGS" ], - [ if test "x$enable_alsa" = "xyes"; then - AC_MSG_ERROR([alsa library >= 1.0.9 not found]) - fi ]) - else - if test "x$uname" = "xFreeBSD"; then PKG_CHECK_MODULES(ALSA, [alsa >= 1.0.9], [ SOUND_CFLAGS="$ALSA_CFLAGS -DHAVE_ALSA $SOUND_CFLAGS" SOUND_LDFLAGS="$ALSA_LIBS $SOUND_LDFLAGS" ], [ if test "x$enable_alsa" = "xyes"; then AC_MSG_ERROR([alsa library >= 1.0.9 not found]) fi ]) - fi + else + have_alsa=no fi +else + have_alsa=no +fi + +if test "$have_alsa" = "yes"; then + AC_DEFINE(HAVE_ALSA, 1, [Define if the ALSA output plugin should be built]) +else + have_alsa=no +fi + +dnl *** OSS output + +AC_ARG_ENABLE(oss, + [ --disable-oss disable the OSS output plugin (default=enabled)], + [have_oss=$enableval], + [have_oss=yes] +) + +if test "$have_oss" = "yes"; then + AC_MSG_CHECKING(for OSS include dir) + OSS_CFLAGS="" + if test -f "/etc/oss.conf" ; then + for i in `cat /etc/oss.conf`; do + t=`echo $i | sed -e 's/OSSLIBDIR=//'` + if test "$i" != "$t" ; then + if test -f "$t/include/sys/soundcard.h" ; then + OSS_CFLAGS="-I$t/include" + fi + fi + done + fi + if test -n "$OSS_CFLAGS" ; then + AC_MSG_RESULT([$OSS_CFLAGS]) + else + AC_MSG_RESULT([not found]) + fi + CFLAGS_save=$CFLAGS + CFLAGS="$CFLAGS $OSS_CFLAGS" + AC_CHECK_HEADERS(sys/soundcard.h) + AC_CHECK_HEADERS(machine/soundcard.h) + CFLAGS=$CFLAGS_save + + if test "${ac_cv_header_sys_soundcard_h}" = "yes" || test "${ac_cv_header_machine_soundcard_h}" = "yes"; then + have_oss=yes + fi +fi + +if test "$have_oss" = "yes"; then + AC_DEFINE(HAVE_OSS, 1, [Define if the OSS output plugin should be built]) +else + have_oss=no +fi + +dnl FreeBSD newpcm driver detection + +AC_CACHE_CHECK(for FreeBSD newpcm driver, freebsd_newpcm_driver, + if test -r "/dev/sndstat"; then + grep 'newpcm' /dev/sndstat 2>/dev/null 1>/dev/null + if test "x$?" = "x0"; then + freebsd_newpcm_driver="yes" + else + freebsd_newpcm_driver="no" + fi + else + freebsd_newpcm_driver="no" + fi +) + +if test "$freebsd_newpcm_driver" = "yes"; then + AC_DEFINE(HAVE_NEWPCM, 1, [Define if you have the FreeBSD newpcm driver]) fi AC_SUBST(SOUND_CFLAGS) @@ -179,3 +242,13 @@ ],[ ]) +echo +echo "Configuration:" +echo +echo " Install path: ${prefix}" +echo +echo " Audio Subsystems" +echo " ----------------" +echo " Advanced Linux Sound Arch. (alsa): $have_alsa" +echo " Open Sound System (oss): $have_oss" + =================================================================== RCS file: /cvs/e/e_modules/mixer/e_mod_main.c,v retrieving revision 1.42 retrieving revision 1.43 diff -u -3 -r1.42 -r1.43 --- e_mod_main.c 12 Sep 2006 21:26:44 -0000 1.42 +++ e_mod_main.c 14 Sep 2006 14:14:45 -0000 1.43 @@ -2,8 +2,10 @@ #include "e_mod_main.h" #include "e_mod_types.h" -#ifdef HAVE_LIBASOUND +#if defined(HAVE_ALSA) # include "alsa_mixer.h" +#elif defined(HAVE_OSS) +# include "oss_mixer.h" #endif /* Define to 1 for testing alsa code */ @@ -325,8 +327,8 @@ sys = E_NEW(Mixer_System, 1); if (!sys) return; mixer->mix_sys = sys; - - #ifdef HAVE_LIBASOUND + +#if defined(HAVE_ALSA) sys->get_cards = alsa_get_cards; sys->get_card = alsa_get_card; sys->get_channels = alsa_card_get_channels; @@ -338,7 +340,19 @@ sys->get_mute = alsa_get_mute; sys->set_mute = alsa_set_mute; - #endif +#elif defined(HAVE_OSS) + sys->get_cards = oss_get_cards; + sys->get_card = oss_get_card; + sys->get_channels = oss_card_get_channels; + sys->get_channel = oss_card_get_channel; + sys->free_cards = oss_free_cards; + + sys->get_volume = oss_get_volume; + sys->set_volume = oss_set_volume; + + sys->get_mute = oss_get_mute; + sys->set_mute = oss_set_mute; +#endif } static void @@ -769,7 +783,7 @@ m = mixer->mix_sys->get_mute(ci->card_id, ci->channel_id); if (m) return; - + val = ((1.0 - (e_slider_value_get(obj))) * 100); if ((ci->card_id != 0) && (ci->channel_id != 0)) { =================================================================== RCS file: /cvs/e/e_modules/mixer/oss_mixer.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- oss_mixer.c 11 Sep 2006 16:42:10 -0000 1.1 +++ oss_mixer.c 14 Sep 2006 14:14:45 -0000 1.2 @@ -1,51 +1,270 @@ #include <e.h> +#include "config.h" +#ifdef HAVE_OSS #include <sys/soundcard.h> #include <sys/ioctl.h> #include <errno.h> +#include <unistd.h> +#include <fcntl.h> #include "e_mod_types.h" #include "oss_mixer.h" -static int mixerfd; +static Evas_List * +_oss_scan_devices(char *type) +{ + FILE *file; + char buffer[256], *temp, *tmp2; + int found = 0; + int index = 0; + static Evas_List *cards = NULL; + + if(cards) + return cards; + + if ((file = fopen("/dev/sndstat", "r"))) + { + while (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; + cards = evas_list_append(cards, strdup(buffer)); + } + else + cards = evas_list_append(cards, strdup(buffer)); + } + if (!strcasecmp(buffer, type)) + found = 1; + } + fclose(file); + } + else + cards = evas_list_append(cards, strdup("Default")); + + return cards; +} Evas_List * oss_get_cards() -{ - Evas_List *cards = NULL; - oss_sysinfo info; - oss_audioinfo ainfo; +{ + static Evas_List *cards = NULL; + Evas_List *hw_cards = NULL; int i, hd; - char dname[256]; - - if ((mixerfd = open("/dev/mixer0", O_RDWR, 0)) == -1) - return NULL; + char dname[256]; + Mixer_Card *card; + + if(cards) + return cards; - if (ioctl(mixerfd, SNDCTL_SYSINFO, &info) == -1) + if((hw_cards = _oss_scan_devices("Installed Devices"))) { - printf("Cannot open oss info: %s\n", strerror(errno)); - return NULL; + Evas_List *l; + int i = 0; + + for(l = hw_cards; l; l = l->next) + { + char *real; + int size; + + size = sizeof(char) * (strlen("/dev/mixerX") + 1); + real = malloc(size); + snprintf(real, size, "/dev/mixer%d", i); + card = E_NEW(Mixer_Card, 1); + card->name = evas_stringshare_add(l->data); + card->real = evas_stringshare_add(real); + card->id = i + 1; + free(real); + ++i; + cards = evas_list_append(cards, card); + } + } + else + { + card = E_NEW(Mixer_Card, 1); + card->name = evas_stringshare_add("Default"); + card->real = evas_stringshare_add("/dev/mixer0"); + card->id = 1; + cards = evas_list_append(cards, card); } + + return cards; +} + +void *oss_get_card(int id) +{ + Evas_List *hw_cards = NULL; + int i; + Mixer_Card *card = NULL; - for (i = 0; i < info.numaudios; i++) + if((hw_cards = _oss_scan_devices("Installed Devices"))) { - Mixer_Card *card; + Evas_List *l; + int i = 0; + char *real; + int size; + char *name; - ainfo.dev = i; - if (ioctl(mixerfd, SNDCTL_AUDIOINFO, &ainfo) == -1) - continue; - if (!ainfo.caps & DSP_CAP_OUTPUT) - continue; + if((name = evas_list_nth(hw_cards, id - 1))) + { + size = sizeof(char) * (strlen("/dev/mixerX") + 1); + real = malloc(size); + snprintf(real, size, "/dev/mixer%d", i); + card = E_NEW(Mixer_Card, 1); + card->name = evas_stringshare_add(l->data); + card->real = evas_stringshare_add(real); + card->id = id; + free(real); + } + } + + if(!card) + { card = E_NEW(Mixer_Card, 1); - if (!card) continue; + card->name = evas_stringshare_add("Default"); + card->real = evas_stringshare_add("/dev/mixer0"); + card->id = 1; + } + + return card; +} - if (!(ainfo.caps & DSP_CAP_OUTPUT)) continue; - - card->id = ainfo.card_number; - card->name = ainfo.name; - card->real = ainfo.name; +Evas_List *oss_card_get_channels(void *data) +{ + Mixer_Channel *ac; + const char *name = "Master"; + Evas_List *channels = NULL; + + /* FIXME: do this properly */ + ac = E_NEW(Mixer_Channel, 1); + + ac->name = evas_stringshare_add(name); + ac->id = 1; + + channels = evas_list_append(channels, ac); + return channels; +} - cards = evas_list_append(cards, card); +void *oss_card_get_channel(void *data, int channel_id) +{ + Mixer_Channel *ac; + + /* FIXME: do this properly */ + ac = E_NEW(Mixer_Channel, 1); + + ac->name = evas_stringshare_add("Master"); + ac->id = 1; + return ac; +} + +void oss_free_cards(void *data) +{ + /* FIXME: free everything here */ +} + +int oss_get_volume(int card_id, int channel_id) +{ + int fd, v, devs; + long cmd; + const char *devname; + int r, l = 0; + Mixer_Card *card; + + card = oss_get_card(card_id); + if(!card) return 0; + + devname = card->real; + fd = open(devname, O_RDONLY); + + if (fd != -1) + { + ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); + if ((devs & SOUND_MASK_PCM) /*&& (oss_cfg.use_master == 0)*/) + cmd = SOUND_MIXER_READ_PCM; + else if ((devs & SOUND_MASK_VOLUME) /*&& (oss_cfg.use_master == 1)*/) + cmd = SOUND_MIXER_READ_VOLUME; + else + { + close(fd); + return; + } + ioctl(fd, cmd, &v); + /* We have the volume for both left / right, returning only one */ + r = (v & 0xFF00) >> 8; + l = (v & 0x00FF); + close(fd); } + E_FREE(card); + return l; +} + +int oss_set_volume(int card_id, int channel_id, double vol) +{ + int fd, v, devs; + long cmd; + const char *devname; + int r, l; + Mixer_Card *card; - return cards; + r = l = (int)vol; + + card = oss_get_card(card_id); + if(!card) return 0; + + devname = card->real; + fd = open(devname, O_RDONLY); + + if (fd != -1) { + ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs); + if ((devs & SOUND_MASK_PCM) /*&& (oss_cfg.use_master == 0)*/) + cmd = SOUND_MIXER_WRITE_PCM; + else if ((devs & SOUND_MASK_VOLUME) /*&& (oss_cfg.use_master == 1)*/) + cmd = SOUND_MIXER_WRITE_VOLUME; + else { + close(fd); + return; + } + v = (r << 8) | l; + ioctl(fd, cmd, &v); + close(fd); + } + else + { + printf("oss_set_volume(): Failed to open mixer device (%s): %s", + devname, strerror(errno)); + } + E_FREE(card); + return 1; +} + +int oss_get_mute(int card_id, int channel_id) +{ + if(oss_get_volume(card_id, channel_id) == 0) + return 1; + else + return 0; } + +int oss_set_mute(int card_id, int channel_id, int mute) +{ + if(mute) + return oss_set_volume(card_id, channel_id, 0); + else + /* FIXME: this is hardcoded, need to restore it */ + return oss_set_volume(card_id, channel_id, 10); +} + +#endif =================================================================== RCS file: /cvs/e/e_modules/mixer/oss_mixer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- oss_mixer.h 11 Sep 2006 16:42:10 -0000 1.1 +++ oss_mixer.h 14 Sep 2006 14:14:45 -0000 1.2 @@ -3,7 +3,15 @@ #include <Evas.h> -Evas_List *oss_get_cards (void); -void *oss_get_card (int id); +Evas_List *oss_get_cards(void); +void *oss_get_card(int id); +Evas_List *oss_card_get_channels(void *data); +void *oss_card_get_channel(void *data, int channel_id); +void oss_free_cards(void *data); +int oss_get_volume(int card_id, int channel_id); +int oss_set_volume(int card_id, int channel_id, double vol); + +int oss_get_mute(int card_id, int channel_id); +int oss_set_mute(int card_id, int channel_id, int mute); #endif ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs