From 407411a0e3813cf6ed3508fd33bd4f6993ca0087 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Wed, 20 Jan 2010 08:47:08 +0100 Subject: oss plugin Conflicts: Makefile.am configure.ac --- plugins/oss/Makefile.am | 6 + plugins/oss/oss.c | 289 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 295 insertions(+) create mode 100644 plugins/oss/Makefile.am create mode 100644 plugins/oss/oss.c (limited to 'plugins/oss') diff --git a/plugins/oss/Makefile.am b/plugins/oss/Makefile.am new file mode 100644 index 00000000..f8938ff4 --- /dev/null +++ b/plugins/oss/Makefile.am @@ -0,0 +1,6 @@ +ossdir = $(libdir)/$(PACKAGE) +pkglib_LTLIBRARIES = oss.la +oss_la_SOURCES = oss.c +oss_la_LDFLAGS = -module +include /etc/oss.conf +AM_CFLAGS = $(CFLAGS) -I$(OSSLIBDIR)/include/sys -std=c99 diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c new file mode 100644 index 00000000..06befad5 --- /dev/null +++ b/plugins/oss/oss.c @@ -0,0 +1,289 @@ +/* + DeaDBeeF - ultimate music player for GNU/Linux systems with X11 + Copyright (C) 2009-2010 Alexey Yakovenko + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + 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 + along with this program. If not, see . +*/ +#include +#include +#ifdef __linux__ +#include +#endif +#include +#include +#include +#include +#include +#include "../../deadbeef.h" + +#if OSS_VERSION<0x040000 +#error oss4 plugin: at least oss v4.0 is required to build this plugin +#endif + +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) + +static DB_output_t plugin; +DB_functions_t *deadbeef; + +static intptr_t oss_tid; +static int oss_terminate; +static int oss_rate; +static int state; +static int fd; + +static void +oss_thread (void *context); + +static void +oss_callback (char *stream, int len); + +static int +oss_init (void) { + trace ("oss_init\n"); + state = OUTPUT_STATE_STOPPED; + oss_rate = 44100; + oss_terminate = 0; + + // prepare oss for playback + const char *name = "/dev/dsp"; + fd = open (name, O_WRONLY); + if (fd == -1) { + trace ("oss: failed to open file\n"); + perror (name); + plugin.free (); + return -1; + } + + int fmt = AFMT_S16_NE; + if (ioctl (fd, SNDCTL_DSP_SETFMT, &fmt) == -1) { + trace ("oss: failed to set format\n"); + perror ("SNDCTL_DSP_SETFMT"); + plugin.free (); + return -1; + } + + if (fmt != AFMT_S16_NE) { + fprintf (stderr, "oss: device doesn't support 16 bit sample format\n"); + plugin.free (); + return -1; + } + + int channels = 2; + if (ioctl (fd, SNDCTL_DSP_CHANNELS, &channels) == -1) { + trace ("oss: failed to set channels\n"); + perror ("SNDCTL_DSP_CHANNELS"); + plugin.free (); + return -1; + } + if (channels != 2) { + trace ("oss: device doesn't support stereo output\n"); + plugin.free (); + return -1; + } + + if (ioctl (fd, SNDCTL_DSP_SPEED, &oss_rate) == -1) { + trace ("oss: failed to set samplerate\n"); + perror ("SNDCTL_DSP_CHANNELS"); + plugin.free (); + return -1; + } + + trace ("oss: samplerate: %d\n", oss_rate); + + oss_tid = deadbeef->thread_start (oss_thread, NULL); + return 0; +} + +static int +oss_change_rate (int rate) { + if (!fd) { + oss_rate = rate; + return oss_rate; + } + if (rate == oss_rate) { + trace ("oss_change_rate: same rate (%d), ignored\n", rate); + return rate; + } + if (ioctl (fd, SNDCTL_DSP_SPEED, &rate) == -1) { + trace ("oss: can't switch to %d samplerate\n", rate); + perror ("SNDCTL_DSP_CHANNELS"); + plugin.free (); + return -1; + } + oss_rate = rate; + return oss_rate; +} + +static int +oss_free (void) { + trace ("oss_free\n"); + if (!oss_terminate) { + if (oss_tid) { + oss_terminate = 1; + deadbeef->thread_join (oss_tid); + } + oss_tid = 0; + state = OUTPUT_STATE_STOPPED; + oss_terminate = 0; + if (fd) { + close (fd); + } + } + return 0; +} + +static int +oss_play (void) { + if (!oss_tid) { + oss_init (); + } + state = OUTPUT_STATE_PLAYING; + return 0; +} + +static int +oss_stop (void) { + state = OUTPUT_STATE_STOPPED; + deadbeef->streamer_reset (1); + return 0; +} + +static int +oss_pause (void) { + if (state == OUTPUT_STATE_STOPPED) { + return -1; + } + // set pause state + state = OUTPUT_STATE_PAUSED; + return 0; +} + +static int +oss_unpause (void) { + // unset pause state + if (state == OUTPUT_STATE_PAUSED) { + state = OUTPUT_STATE_PLAYING; + } + return 0; +} + +static int +oss_get_rate (void) { + return oss_rate; +} + +static int +oss_get_bps (void) { + return 16; +} + +static int +oss_get_channels (void) { + return 2; +} + +static int +oss_get_endianness (void) { +#if WORDS_BIGENDIAN + return 1; +#else + return 0; +#endif +} + +static void +oss_thread (void *context) { +#ifdef __linux__ + prctl (PR_SET_NAME, "deadbeef-oss", 0, 0, 0, 0); +#endif + for (;;) { + if (oss_terminate) { + break; + } + if (state != OUTPUT_STATE_PLAYING) { + usleep (10000); + continue; + } + + char buf[1024]; + oss_callback (buf, 1024); + if (write (fd, buf, sizeof (buf)) != sizeof (buf)) { + fprintf (stderr, "oss: failed to write buffer\n"); + } + } +} + +static void +oss_callback (char *stream, int len) { + if (!deadbeef->streamer_ok_to_read (len)) { + memset (stream, 0, len); + return; + } + int bytesread = deadbeef->streamer_read (stream, len); + + if (bytesread < len) { + memset (stream + bytesread, 0, len-bytesread); + } +} + +static int +oss_get_state (void) { + return state; +} + +static int +oss_plugin_start (void) { + return 0; +} + +static int +oss_plugin_stop (void) { + return 0; +} + +DB_plugin_t * +oss_load (DB_functions_t *api) { + deadbeef = api; + return DB_PLUGIN (&plugin); +} + +// define plugin interface +static DB_output_t plugin = { + DB_PLUGIN_SET_API_VERSION + .plugin.version_major = 0, + .plugin.version_minor = 1, + .plugin.nostop = 0, + .plugin.type = DB_PLUGIN_OUTPUT, + .plugin.id = "oss", + .plugin.name = "OSS output plugin", + .plugin.descr = "plays sound via OSS API", + .plugin.author = "Alexey Yakovenko", + .plugin.email = "waker@users.sourceforge.net", + .plugin.website = "http://deadbeef.sf.net", + .plugin.start = oss_plugin_start, + .plugin.stop = oss_plugin_stop, + .init = oss_init, + .free = oss_free, + .change_rate = oss_change_rate, + .play = oss_play, + .stop = oss_stop, + .pause = oss_pause, + .unpause = oss_unpause, + .state = oss_get_state, + .samplerate = oss_get_rate, + .bitspersample = oss_get_bps, + .channels = oss_get_channels, + .endianness = oss_get_endianness, +}; -- cgit v1.2.3 From 2de981752d99dfb192a765a770fee3aab46ecaea Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Wed, 20 Jan 2010 08:57:57 +0100 Subject: updated oss plugin Conflicts: Makefile.am --- Makefile.am | 4 ++-- configure.ac | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/oss/oss.c | 24 +++++++++++++++++---- 3 files changed, 86 insertions(+), 6 deletions(-) (limited to 'plugins/oss') diff --git a/Makefile.am b/Makefile.am index a3d0a84a..09629c54 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,8 +19,8 @@ SUBDIRS = gme/Game_Music_Emu-0.5.2\ ${VFS_CURL_DIR}\ ${CDDA_DIR}\ ${GTKUI_DIR}\ - ${FFMPEG_DIR} - plugins/oss + ${FFMPEG_DIR}\ + ${OSS4_DIR} dumbpath=@top_srcdir@/dumb sidpath=@top_srcdir@/sid/sidplay-libs-2.1.0 diff --git a/configure.ac b/configure.ac index 09d4a66c..49073c8c 100644 --- a/configure.ac +++ b/configure.ac @@ -176,6 +176,69 @@ if test ${HAVE_FFMPEG}; then AC_SUBST(FFMPEG_DIR) fi +dnl *** OSS4 output (partly stolen from audacious) +have_oss4=no + +AC_MSG_CHECKING(for OSS4 include dir) +OSS4_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 "x$i" != "x$t" ; then + if test -f "$t/include/sys/soundcard.h" -o -f "$i/include/soundcard.h" ; then + OSS4_CFLAGS="-I$t/include" + fi + fi + done +fi +if test -n "$OSS4_CFLAGS" ; then + AC_MSG_RESULT([$OSS4_CFLAGS]) +else + AC_MSG_RESULT([not found]) +fi +CFLAGS_save=$CFLAGS +CFLAGS="$CFLAGS $OSS4_CFLAGS" +AC_CHECK_HEADERS(soundcard.h) +AC_CHECK_HEADERS(sys/soundcard.h) +AC_CHECK_HEADERS(machine/soundcard.h) +CFLAGS=$CFLAGS_save + +if test "x${ac_cv_header_soundcard_h}" = "xyes" || test "x${ac_cv_header_sys_soundcard_h}" = "xyes" || test "x${ac_cv_header_machine_soundcard_h}" = "xyes"; then + have_oss4=yes +fi + +if test "x${have_oss4}" = "xyes"; then +AC_MSG_CHECKING(whether we need -lossaudio) + AC_TRY_LINK([ + #include + #ifdef HAVE_SYS_SOUNDCARD_H + #include + #else + #include + #endif + ], [ + int fd, value; + ioctl(fd, SOUND_MIXER_READ_VOLUME, &value); +], AC_MSG_RESULT(no), [ + OSS4_LIBS="-lossaudio" + AC_MSG_RESULT(yes) + ]) +fi + +if test "x$have_oss4" = "xyes"; then + AC_DEFINE(HAVE_OSS4, 1, [Define if the OSS4 output plugin should be built]) +else + have_oss4=no +fi + +if test "x$have_oss4" = "xyes"; then + OSS4_DIR="plugins/oss" + AC_SUBST(OSS4_CFLAGS) + AC_SUBST(OSS4_DIR) + AC_SUBST(OSS4_LIBS) +fi + + dnl print summary echo echo "plugin summary:" @@ -211,6 +274,7 @@ dnl PRINT_PLUGIN_INFO([faad2],[aac/mp4 player],[test $HAVE_FAAD && test $HAVE_MP PRINT_PLUGIN_INFO([cdda],[cd audio player],[test $HAVE_CDIO && test $HAVE_CDDB]) PRINT_PLUGIN_INFO([gtkui],[GTK user interface],[test $HAVE_GTK]) PRINT_PLUGIN_INFO([ffmpeg],[ffmpeg codecs],[test $HAVE_FFMPEG]) +PRINT_PLUGIN_INFO([oss],[oss4 output plugin],[test "x$have_oss"="xyes"]) echo AC_OUTPUT([ diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c index 06befad5..5507f59e 100644 --- a/plugins/oss/oss.c +++ b/plugins/oss/oss.c @@ -39,9 +39,10 @@ DB_functions_t *deadbeef; static intptr_t oss_tid; static int oss_terminate; -static int oss_rate; +static int oss_rate = 44100; static int state; static int fd; +static uintptr_t mutex; static void oss_thread (void *context); @@ -53,8 +54,8 @@ static int oss_init (void) { trace ("oss_init\n"); state = OUTPUT_STATE_STOPPED; - oss_rate = 44100; oss_terminate = 0; + mutex = 0; // prepare oss for playback const char *name = "/dev/dsp"; @@ -102,6 +103,8 @@ oss_init (void) { trace ("oss: samplerate: %d\n", oss_rate); + mutex = deadbeef->mutex_create (); + oss_tid = deadbeef->thread_start (oss_thread, NULL); return 0; } @@ -116,6 +119,7 @@ oss_change_rate (int rate) { trace ("oss_change_rate: same rate (%d), ignored\n", rate); return rate; } + deadbeef->mutex_lock (mutex); if (ioctl (fd, SNDCTL_DSP_SPEED, &rate) == -1) { trace ("oss: can't switch to %d samplerate\n", rate); perror ("SNDCTL_DSP_CHANNELS"); @@ -123,6 +127,7 @@ oss_change_rate (int rate) { return -1; } oss_rate = rate; + deadbeef->mutex_unlock (mutex); return oss_rate; } @@ -140,6 +145,10 @@ oss_free (void) { if (fd) { close (fd); } + if (mutex) { + deadbeef->mutex_free (mutex); + mutex = 0; + } } return 0; } @@ -219,9 +228,13 @@ oss_thread (void *context) { char buf[1024]; oss_callback (buf, 1024); - if (write (fd, buf, sizeof (buf)) != sizeof (buf)) { + deadbeef->mutex_lock (mutex); + int res = write (fd, buf, sizeof (buf)); + deadbeef->mutex_unlock (mutex); + if (res != sizeof (buf)) { fprintf (stderr, "oss: failed to write buffer\n"); } + usleep (1000); // this must be here to prevent mutex deadlock } } @@ -232,6 +245,10 @@ oss_callback (char *stream, int len) { return; } int bytesread = deadbeef->streamer_read (stream, len); + int16_t ivolume = deadbeef->volume_get_amp () * 1000; + for (int i = 0; i < bytesread/2; i++) { + ((int16_t*)stream)[i] = (int16_t)(((int32_t)(((int16_t*)stream)[i])) * ivolume / 1000); + } if (bytesread < len) { memset (stream + bytesread, 0, len-bytesread); @@ -266,7 +283,6 @@ static DB_output_t plugin = { .plugin.version_minor = 1, .plugin.nostop = 0, .plugin.type = DB_PLUGIN_OUTPUT, - .plugin.id = "oss", .plugin.name = "OSS output plugin", .plugin.descr = "plays sound via OSS API", .plugin.author = "Alexey Yakovenko", -- cgit v1.2.3 From 56650db1e4d6f39d11167c308b23e70507b05a5c Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Wed, 20 Jan 2010 20:34:43 +0100 Subject: oss build fixes --- configure.ac | 57 +++++++++++++++++-------------------------------- plugins/oss/Makefile.am | 4 ++-- plugins/oss/oss.c | 9 ++++---- 3 files changed, 27 insertions(+), 43 deletions(-) (limited to 'plugins/oss') diff --git a/configure.ac b/configure.ac index 49073c8c..f51d527a 100644 --- a/configure.ac +++ b/configure.ac @@ -39,7 +39,7 @@ dnl INSANE_CFLAGS="-Wcomment -Wchar-subscripts -Wunused-function -Wunused-value dnl INSANE_CXXFLAGS="-Wcomment -Wchar-subscripts -Wunused-function -Wunused-value -Wuninitialized -Wtype-limits" CXXFLAGS="$CXXFLAGS $INSANE_CXXFLAGS -D_GNU_SOURCE -DLIBDIR=\\\"$libdir\\\" -DPREFIX=\\\"$prefix\\\" -DDOCDIR=\\\"$docdir\\\"" -CFLAGS="$CFLAGS $INSANE_CFLAGS -D_GNU_SOURCE -DLIBDIR=\\\"$libdir\\\" -DPREFIX=\\\"$prefix\\\" -DDOCDIR=\\\"$docdir\\\"" +CFLAGS="$CFLAGS $INSANE_CFLAGS -D_GNU_SOURCE -DLIBDIR=\\\"$libdir\\\" -DPREFIX=\\\"$prefix\\\" -DDOCDIR=\\\"$docdir\\\" -std=c99" PKG_CHECK_MODULES(DEPS, samplerate) PKG_CHECK_MODULES(GTKUI_DEPS, gtk+-2.0 >= 2.12 gthread-2.0 glib-2.0, HAVE_GTK=1, NO_GTK=1) @@ -187,57 +187,40 @@ if test -f "/etc/oss.conf" ; then if test "x$i" != "x$t" ; then if test -f "$t/include/sys/soundcard.h" -o -f "$i/include/soundcard.h" ; then OSS4_CFLAGS="-I$t/include" + AC_MSG_RESULT([$OSS4_CFLAGS]) + have_oss4=yes fi fi done -fi -if test -n "$OSS4_CFLAGS" ; then - AC_MSG_RESULT([$OSS4_CFLAGS]) else AC_MSG_RESULT([not found]) fi -CFLAGS_save=$CFLAGS -CFLAGS="$CFLAGS $OSS4_CFLAGS" -AC_CHECK_HEADERS(soundcard.h) -AC_CHECK_HEADERS(sys/soundcard.h) -AC_CHECK_HEADERS(machine/soundcard.h) -CFLAGS=$CFLAGS_save - -if test "x${ac_cv_header_soundcard_h}" = "xyes" || test "x${ac_cv_header_sys_soundcard_h}" = "xyes" || test "x${ac_cv_header_machine_soundcard_h}" = "xyes"; then - have_oss4=yes -fi -if test "x${have_oss4}" = "xyes"; then -AC_MSG_CHECKING(whether we need -lossaudio) - AC_TRY_LINK([ - #include - #ifdef HAVE_SYS_SOUNDCARD_H - #include - #else - #include - #endif - ], [ - int fd, value; - ioctl(fd, SOUND_MIXER_READ_VOLUME, &value); -], AC_MSG_RESULT(no), [ - OSS4_LIBS="-lossaudio" - AC_MSG_RESULT(yes) - ]) +if test "x$have_oss4" != "xyes"; then + AC_MSG_CHECKING(for /usr/include/sys/soundcard.h) + AC_CHECK_HEADERS(sys/soundcard.h) + if test "x${ac_cv_header_sys_soundcard_h}" = "xyes" ; then + have_oss4=yes + AC_MSG_RESULT([found]) + else + AC_MSG_RESULT([not found]) + fi fi -if test "x$have_oss4" = "xyes"; then - AC_DEFINE(HAVE_OSS4, 1, [Define if the OSS4 output plugin should be built]) -else - have_oss4=no -fi if test "x$have_oss4" = "xyes"; then OSS4_DIR="plugins/oss" AC_SUBST(OSS4_CFLAGS) AC_SUBST(OSS4_DIR) - AC_SUBST(OSS4_LIBS) fi +echo +echo "have_oss4=$have_oss4" +echo "OSS4_CFLAGS=$OSS4_CFLAGS" +echo "OSS4_LIBS=$OSS4_LIBS" +echo "OSS4_DIR=$OSS4_DIR" +echo + dnl print summary echo @@ -274,7 +257,7 @@ dnl PRINT_PLUGIN_INFO([faad2],[aac/mp4 player],[test $HAVE_FAAD && test $HAVE_MP PRINT_PLUGIN_INFO([cdda],[cd audio player],[test $HAVE_CDIO && test $HAVE_CDDB]) PRINT_PLUGIN_INFO([gtkui],[GTK user interface],[test $HAVE_GTK]) PRINT_PLUGIN_INFO([ffmpeg],[ffmpeg codecs],[test $HAVE_FFMPEG]) -PRINT_PLUGIN_INFO([oss],[oss4 output plugin],[test "x$have_oss"="xyes"]) +PRINT_PLUGIN_INFO([oss],[oss4 output plugin],[test "x$have_oss4" = "xyes"]) echo AC_OUTPUT([ diff --git a/plugins/oss/Makefile.am b/plugins/oss/Makefile.am index f8938ff4..810bd249 100644 --- a/plugins/oss/Makefile.am +++ b/plugins/oss/Makefile.am @@ -1,6 +1,6 @@ ossdir = $(libdir)/$(PACKAGE) pkglib_LTLIBRARIES = oss.la +AM_CFLAGS = $(CFLAGS) $(OSS4_CFLAGS) oss_la_SOURCES = oss.c oss_la_LDFLAGS = -module -include /etc/oss.conf -AM_CFLAGS = $(CFLAGS) -I$(OSSLIBDIR)/include/sys -std=c99 + diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c index 5507f59e..193970ad 100644 --- a/plugins/oss/oss.c +++ b/plugins/oss/oss.c @@ -22,14 +22,15 @@ #endif #include #include -#include +#include #include +#include #include #include "../../deadbeef.h" -#if OSS_VERSION<0x040000 -#error oss4 plugin: at least oss v4.0 is required to build this plugin -#endif +//#if OSS_VERSION<0x040000 +//#error oss4 plugin: at least oss v4.0 is required to build this plugin +//#endif #define trace(...) { fprintf(stderr, __VA_ARGS__); } //#define trace(fmt,...) -- cgit v1.2.3 From 4872a51d33d9b449f8270a97aa3497e28cd0b3eb Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Wed, 20 Jan 2010 21:48:03 +0100 Subject: oss plugin updates (supports both v3 and v4 now) --- Makefile.am | 2 +- configure.ac | 42 +++++++++++++++++++++--------------------- plugins/oss/Makefile.am | 2 +- plugins/oss/oss.c | 36 ++++++++++++++++++++++++++++++------ 4 files changed, 53 insertions(+), 29 deletions(-) (limited to 'plugins/oss') diff --git a/Makefile.am b/Makefile.am index 09629c54..fd3d386a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,7 +20,7 @@ SUBDIRS = gme/Game_Music_Emu-0.5.2\ ${CDDA_DIR}\ ${GTKUI_DIR}\ ${FFMPEG_DIR}\ - ${OSS4_DIR} + ${OSS_DIR} dumbpath=@top_srcdir@/dumb sidpath=@top_srcdir@/sid/sidplay-libs-2.1.0 diff --git a/configure.ac b/configure.ac index f51d527a..f1ec43fc 100644 --- a/configure.ac +++ b/configure.ac @@ -176,19 +176,19 @@ if test ${HAVE_FFMPEG}; then AC_SUBST(FFMPEG_DIR) fi -dnl *** OSS4 output (partly stolen from audacious) -have_oss4=no +dnl *** OSS output (partly stolen from audacious) +have_oss=no -AC_MSG_CHECKING(for OSS4 include dir) -OSS4_CFLAGS="" +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 "x$i" != "x$t" ; then if test -f "$t/include/sys/soundcard.h" -o -f "$i/include/soundcard.h" ; then - OSS4_CFLAGS="-I$t/include" - AC_MSG_RESULT([$OSS4_CFLAGS]) - have_oss4=yes + OSS_CFLAGS="-I$t/include/sys" + AC_MSG_RESULT([$OSS_CFLAGS]) + have_oss=yes fi fi done @@ -196,11 +196,11 @@ else AC_MSG_RESULT([not found]) fi -if test "x$have_oss4" != "xyes"; then - AC_MSG_CHECKING(for /usr/include/sys/soundcard.h) +if test "x$have_oss" != "xyes"; then + AC_MSG_CHECKING(for sys/soundcard.h) AC_CHECK_HEADERS(sys/soundcard.h) if test "x${ac_cv_header_sys_soundcard_h}" = "xyes" ; then - have_oss4=yes + have_oss=yes AC_MSG_RESULT([found]) else AC_MSG_RESULT([not found]) @@ -208,18 +208,18 @@ if test "x$have_oss4" != "xyes"; then fi -if test "x$have_oss4" = "xyes"; then - OSS4_DIR="plugins/oss" - AC_SUBST(OSS4_CFLAGS) - AC_SUBST(OSS4_DIR) +if test "x$have_oss" = "xyes"; then + OSS_DIR="plugins/oss" + AC_SUBST(OSS_CFLAGS) + AC_SUBST(OSS_DIR) fi -echo -echo "have_oss4=$have_oss4" -echo "OSS4_CFLAGS=$OSS4_CFLAGS" -echo "OSS4_LIBS=$OSS4_LIBS" -echo "OSS4_DIR=$OSS4_DIR" -echo +dnl echo +dnl echo "have_oss=$have_oss" +dnl echo "OSS_CFLAGS=$OSS_CFLAGS" +dnl echo "OSS_LIBS=$OSS_LIBS" +dnl echo "OSS_DIR=$OSS_DIR" +dnl echo dnl print summary @@ -257,7 +257,7 @@ dnl PRINT_PLUGIN_INFO([faad2],[aac/mp4 player],[test $HAVE_FAAD && test $HAVE_MP PRINT_PLUGIN_INFO([cdda],[cd audio player],[test $HAVE_CDIO && test $HAVE_CDDB]) PRINT_PLUGIN_INFO([gtkui],[GTK user interface],[test $HAVE_GTK]) PRINT_PLUGIN_INFO([ffmpeg],[ffmpeg codecs],[test $HAVE_FFMPEG]) -PRINT_PLUGIN_INFO([oss],[oss4 output plugin],[test "x$have_oss4" = "xyes"]) +PRINT_PLUGIN_INFO([oss],[oss output plugin],[test "x$have_oss" = "xyes"]) echo AC_OUTPUT([ diff --git a/plugins/oss/Makefile.am b/plugins/oss/Makefile.am index 810bd249..697f4d32 100644 --- a/plugins/oss/Makefile.am +++ b/plugins/oss/Makefile.am @@ -1,6 +1,6 @@ ossdir = $(libdir)/$(PACKAGE) pkglib_LTLIBRARIES = oss.la -AM_CFLAGS = $(CFLAGS) $(OSS4_CFLAGS) +AM_CFLAGS = $(CFLAGS) $(OSS_CFLAGS) oss_la_SOURCES = oss.c oss_la_LDFLAGS = -module diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c index 193970ad..b8602cf7 100644 --- a/plugins/oss/oss.c +++ b/plugins/oss/oss.c @@ -15,6 +15,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +# include "../../config.h" +#endif #include #include #ifdef __linux__ @@ -22,16 +25,16 @@ #endif #include #include +#if HAVE_SYS_SOUNDCARD_H #include +#else +#include +#endif #include #include #include #include "../../deadbeef.h" -//#if OSS_VERSION<0x040000 -//#error oss4 plugin: at least oss v4.0 is required to build this plugin -//#endif - #define trace(...) { fprintf(stderr, __VA_ARGS__); } //#define trace(fmt,...) @@ -44,6 +47,7 @@ static int oss_rate = 44100; static int state; static int fd; static uintptr_t mutex; +static int blksize; static void oss_thread (void *context); @@ -68,6 +72,18 @@ oss_init (void) { return -1; } +#if OSS_VERSION>=0x040000 +/* + int cooked = 1; + ioctl (fd, SNDCTL_DSP_COOKEDMODE, &cooked); + trace ("oss: cooked_mode=%d\n", cooked); + + int policy = 3; + ioctl (fd, SNDCTL_DSP_POLICY, &policy); + trace ("oss: policy=%d\n", policy); +*/ +#endif + int fmt = AFMT_S16_NE; if (ioctl (fd, SNDCTL_DSP_SETFMT, &fmt) == -1) { trace ("oss: failed to set format\n"); @@ -104,6 +120,14 @@ oss_init (void) { trace ("oss: samplerate: %d\n", oss_rate); +// audio_buf_info bi; +// ioctl (fd, SNDCTL_DSP_GETOSPACE, &bi); +// trace ("oss: bi.bytes=%d, bi.fragsize=%d, bi.fragstotal=%d\n", bi.bytes, bi.fragsize, bi.fragstotal); +// blksize = bi.fragsize; + + ioctl (fd, SNDCTL_DSP_GETBLKSIZE, &blksize); + trace ("oss: blksize: %d\n", blksize); + mutex = deadbeef->mutex_create (); oss_tid = deadbeef->thread_start (oss_thread, NULL); @@ -227,8 +251,8 @@ oss_thread (void *context) { continue; } - char buf[1024]; - oss_callback (buf, 1024); + char buf[blksize]; + oss_callback (buf, sizeof (buf)); deadbeef->mutex_lock (mutex); int res = write (fd, buf, sizeof (buf)); deadbeef->mutex_unlock (mutex); -- cgit v1.2.3 From d2177eebb17eec2af91c26480d36435102c41db1 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Thu, 21 Jan 2010 20:15:52 +0100 Subject: oss buffer tweaks; fixed streamer error handling --- plugins/oss/oss.c | 17 ++++++----------- streamer.c | 5 ++++- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'plugins/oss') diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c index b8602cf7..06eb5a78 100644 --- a/plugins/oss/oss.c +++ b/plugins/oss/oss.c @@ -47,7 +47,8 @@ static int oss_rate = 44100; static int state; static int fd; static uintptr_t mutex; -static int blksize; + +#define BLOCKSIZE 4096 static void oss_thread (void *context); @@ -120,14 +121,6 @@ oss_init (void) { trace ("oss: samplerate: %d\n", oss_rate); -// audio_buf_info bi; -// ioctl (fd, SNDCTL_DSP_GETOSPACE, &bi); -// trace ("oss: bi.bytes=%d, bi.fragsize=%d, bi.fragstotal=%d\n", bi.bytes, bi.fragsize, bi.fragstotal); -// blksize = bi.fragsize; - - ioctl (fd, SNDCTL_DSP_GETBLKSIZE, &blksize); - trace ("oss: blksize: %d\n", blksize); - mutex = deadbeef->mutex_create (); oss_tid = deadbeef->thread_start (oss_thread, NULL); @@ -181,7 +174,9 @@ oss_free (void) { static int oss_play (void) { if (!oss_tid) { - oss_init (); + if (oss_init () < 0) { + return -1; + } } state = OUTPUT_STATE_PLAYING; return 0; @@ -251,7 +246,7 @@ oss_thread (void *context) { continue; } - char buf[blksize]; + char buf[BLOCKSIZE]; oss_callback (buf, sizeof (buf)); deadbeef->mutex_lock (mutex); int res = write (fd, buf, sizeof (buf)); diff --git a/streamer.c b/streamer.c index 3a29866f..0d6c85c8 100644 --- a/streamer.c +++ b/streamer.c @@ -308,7 +308,10 @@ streamer_thread (void *ctx) { else if (pstate == 1) { last_bitrate = -1; avg_bitrate = -1; - p_play (); + if (p_play () < 0) { + fprintf (stderr, "streamer: failed to start playback; output plugin doesn't work\n"); + streamer_set_nextsong (-2, 0); + } } else if (pstate == 2) { p_pause (); -- cgit v1.2.3 From 9832ee35c161a39a215f400639a69f713714243c Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Thu, 21 Jan 2010 20:28:19 +0100 Subject: fixed std=c99 compile issue --- configure.ac | 2 +- plugins/oss/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/oss') diff --git a/configure.ac b/configure.ac index 94e6f780..38161413 100644 --- a/configure.ac +++ b/configure.ac @@ -39,7 +39,7 @@ dnl INSANE_CFLAGS="-Wcomment -Wchar-subscripts -Wunused-function -Wunused-value dnl INSANE_CXXFLAGS="-Wcomment -Wchar-subscripts -Wunused-function -Wunused-value -Wuninitialized -Wtype-limits" CXXFLAGS="$CXXFLAGS $INSANE_CXXFLAGS -D_GNU_SOURCE -DLIBDIR=\\\"$libdir\\\" -DPREFIX=\\\"$prefix\\\" -DDOCDIR=\\\"$docdir\\\"" -CFLAGS="$CFLAGS $INSANE_CFLAGS -D_GNU_SOURCE -DLIBDIR=\\\"$libdir\\\" -DPREFIX=\\\"$prefix\\\" -DDOCDIR=\\\"$docdir\\\" -std=c99" +CFLAGS="$CFLAGS $INSANE_CFLAGS -D_GNU_SOURCE -DLIBDIR=\\\"$libdir\\\" -DPREFIX=\\\"$prefix\\\" -DDOCDIR=\\\"$docdir\\\"" PKG_CHECK_MODULES(DEPS, samplerate) PKG_CHECK_MODULES(GTKUI_DEPS, gtk+-2.0 >= 2.12 gthread-2.0 glib-2.0, HAVE_GTK=1, NO_GTK=1) diff --git a/plugins/oss/Makefile.am b/plugins/oss/Makefile.am index 697f4d32..e2195996 100644 --- a/plugins/oss/Makefile.am +++ b/plugins/oss/Makefile.am @@ -1,6 +1,6 @@ ossdir = $(libdir)/$(PACKAGE) pkglib_LTLIBRARIES = oss.la -AM_CFLAGS = $(CFLAGS) $(OSS_CFLAGS) +AM_CFLAGS = $(CFLAGS) $(OSS_CFLAGS) -std=c99 oss_la_SOURCES = oss.c oss_la_LDFLAGS = -module -- cgit v1.2.3