add libsndio backend to mplayer

ok sthen@
This commit is contained in:
ratchov 2008-10-30 18:33:42 +00:00
parent 31102238b1
commit 65bd1c865f
4 changed files with 330 additions and 25 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.137 2008/10/11 11:07:32 ajacoutot Exp $
# $OpenBSD: Makefile,v 1.138 2008/10/30 18:33:42 ratchov Exp $
# May not be hard to add more.
ONLY_FOR_ARCHS= amd64 i386 powerpc sparc64 arm
@ -9,7 +9,7 @@ V= 1.0rc2
N= mplayer
DISTNAME= MPlayer-${V}
DIST_SUBDIR= ${N}
PKGNAME= ${N}-${V}p11
PKGNAME= ${N}-${V}p12
CATEGORIES= x11 multimedia
EXTRACT_SUFX= .tar.bz2
@ -20,7 +20,7 @@ PERMIT_PACKAGE_CDROM= patents
PERMIT_PACKAGE_FTP= Yes
PERMIT_DISTFILES_CDROM= Yes
PERMIT_DISTFILES_FTP= Yes
WANTLIB= c m ncurses pthread stdc++ util z
WANTLIB= c m ncurses pthread stdc++ util sndio z
MASTER_SITES= http://www1.mplayerhq.hu/MPlayer/releases/ \
http://www2.mplayerhq.hu/MPlayer/releases/ \
@ -211,7 +211,7 @@ CONFIGURE_ARGS+=--disable-jack
NO_REGRESS= Yes
post-patch:
@cp ${FILESDIR}/ao_rtunes.c ${WRKSRC}/libao2
@cp ${FILESDIR}/ao_rtunes.c ${FILESDIR}/ao_libsndio.c ${WRKSRC}/libao2
post-install:
${INSTALL_DATA_DIR} ${PREFIX}/share/doc/mplayer

View File

@ -0,0 +1,226 @@
#include <sys/types.h>
#include <poll.h>
#include <errno.h>
#include <sndio.h>
#include "config.h"
#include "mp_msg.h"
#include "mixer.h"
#include "help_mp.h"
#include "libaf/af_format.h"
#include "audio_out.h"
#include "audio_out_internal.h"
static ao_info_t info = {
"libsndio audio output",
"libsndio",
"Alexandre Ratchov <alex@caoua.org>",
""
};
LIBAO_EXTERN(libsndio)
static struct sio_hdl *hdl = NULL;
static struct sio_par par;
static long long realpos = 0, playpos = 0;
#define SILENCE_NMAX 0x1000
static char silence[SILENCE_NMAX];
/*
* misc parameters (volume, etc...)
*/
static int control(int cmd, void *arg)
{
return CONTROL_FALSE;
}
/*
* call-back invoked to notify of the hardware position
*/
static void movecb(void *addr, int delta)
{
realpos += delta * (int)(par.bps * par.pchan);
}
/*
* open device and setup parameters
* return: 1 = success, 0 = failure
*/
static int init(int rate, int channels, int format, int flags)
{
hdl = sio_open(NULL, SIO_PLAY, 0);
if (hdl == NULL) {
mp_msg(MSGT_AO, MSGL_ERR, "ao2: can't open libsndio\n");
return 0;
}
sio_initpar(&par);
switch (format) {
case AF_FORMAT_U8:
par.bits = 8;
par.sig = 0;
break;
case AF_FORMAT_S8:
par.bits = 8;
par.sig = 1;
break;
case AF_FORMAT_U16_LE:
par.bits = 16;
par.sig = 0;
par.le = 1;
break;
case AF_FORMAT_S16_LE:
par.bits = 16;
par.sig = 1;
par.le = 1;
break;
case AF_FORMAT_U16_BE:
par.bits = 16;
par.sig = 0;
par.le = 0;
break;
case AF_FORMAT_S16_BE:
par.bits = 16;
par.sig = 1;
par.le = 0;
break;
default:
mp_msg(MSGT_AO, MSGL_ERR, "ao2: unsupported format\n");
return 0;
}
par.rate = rate;
par.pchan = channels;
par.bufsz = par.rate * 250 / 1000; /* 250ms buffer */
if (!sio_setpar(hdl, &par)) {
mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't set params\n");
return 0;
}
if (!sio_getpar(hdl, &par)) {
mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't get params\n");
return 0;
}
if (par.bits == 8 && par.bps == 1) {
format = par.sig ? AF_FORMAT_S8 : AF_FORMAT_U8;
} else if (par.bits == 16 && par.bps == 2) {
format = par.sig ?
(par.le ? AF_FORMAT_S16_LE : AF_FORMAT_S16_BE) :
(par.le ? AF_FORMAT_U16_LE : AF_FORMAT_U16_BE);
} else {
mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't set format\n");
return 0;
}
ao_data.samplerate = par.rate;
ao_data.channels = par.pchan;
ao_data.format = format;
ao_data.bps = par.bps * par.pchan * par.rate;
ao_data.buffersize = par.bufsz * par.bps * par.pchan;
ao_data.outburst = par.round * par.bps * par.pchan;
sio_onmove(hdl, movecb, NULL);
realpos = playpos = 0;
if (!sio_start(hdl)) {
mp_msg(MSGT_AO, MSGL_ERR, "ao2: init: couldn't start\n");
}
return 1;
}
/*
* close device
*/
static void uninit(int immed)
{
if (hdl)
sio_close(hdl);
}
/*
* stop playing and empty buffers (for seeking/pause)
*/
static void reset(void) {
if (!sio_stop(hdl)) {
mp_msg(MSGT_AO, MSGL_ERR, "ao2: reset: couldn't stop\n");
}
realpos = playpos = 0;
if (!sio_start(hdl)) {
mp_msg(MSGT_AO, MSGL_ERR, "ao2: reset: couldn't start\n");
}
}
/*
* how many bytes can be played without blocking
*/
static int get_space(void)
{
struct pollfd pfd;
int bufused, space, revents, n;
/*
* call poll() and sio_revents(), so the
* playpos and realpos counters are updated
*/
n = sio_pollfd(hdl, &pfd, POLLOUT);
while (poll(&pfd, n, 0) < 0 && errno == EINTR)
; /* nothing */
revents = sio_revents(hdl, &pfd);
bufused = (realpos < 0) ? playpos : playpos - realpos;
space = par.bufsz * par.pchan * par.bps - bufused;
return space;
}
/*
* play given number of bytes until sio_write() blocks
*/
static int play(void *data, int len, int flags)
{
int n;
n = sio_write(hdl, data, len);
playpos += n;
return n;
}
/*
* return: delay in seconds between first and last sample in buffer
*/
static float get_delay(void)
{
int bufused;
bufused = (realpos < 0) ? playpos : playpos - realpos;
return (float)bufused / (par.bps * par.pchan * par.rate);
}
/*
* stop playing, keep buffers (for pause)
*/
static void audio_pause(void)
{
/* libsndio stops automatically if no data is available */
}
/*
* resume playing, after audio_pause()
*/
static void audio_resume(void)
{
struct pollfd pfd;
int n, count, todo, revents;
todo = par.bufsz * par.pchan * par.bps;
/*
* libsndio starts automatically if enough data is available;
* however we want to start with buffers full, because video
* would accelerate during buffers are filled
*/
while (todo > 0) {
count = todo;
if (count > SILENCE_NMAX)
count = SILENCE_NMAX;
n = sio_write(hdl, silence, count);
if (n == 0)
break;
todo -= n;
realpos -= n;
}
}

View File

@ -1,6 +1,5 @@
$OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
--- configure.orig Sun Oct 7 20:49:33 2007
+++ configure Thu May 1 00:29:07 2008
--- configure.old Mon Sep 29 17:11:48 2008
+++ configure Mon Sep 29 17:13:03 2008
@@ -76,7 +76,7 @@ cc_check() {
}
@ -10,7 +9,15 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
}
tmp_run() {
@@ -501,7 +501,7 @@ _libavcodec_a=auto
@@ -397,6 +397,7 @@ Audio output:
--disable-nas disable NAS audio output [autodetect]
--disable-sgiaudio disable SGI audio output [autodetect]
--disable-sunaudio disable Sun audio output [autodetect]
+ --disable-libsndio disable libsndio audio output [autodetect]
--disable-win32waveout disable Windows waveout audio output [autodetect]
--disable-select disable using select() on the audio device [enable]
@@ -501,7 +502,7 @@ _libavcodec_a=auto
_libamr_nb=auto
_libamr_wb=auto
_libavdecoders_all=`sed -n 's/^[^#]*DEC.*(.*, *\(.*\)).*/\1_decoder/p' libavcodec/allcodecs.c | tr '[a-z]' '[A-Z]'`
@ -19,7 +26,24 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
_libavencoders_all=`sed -n 's/^[^#]*ENC.*(.*, *\(.*\)).*/\1_encoder/p' libavcodec/allcodecs.c | tr '[a-z]' '[A-Z]'`
_libavencoders=` echo $_libavencoders_all | sed -e s/LIBGSM_ENCODER// -e s/LIBGSM_MS_ENCODER// -e s/LIBTHEORA_ENCODER// `
_libavparsers_all=`sed -n 's/^[^#]*PARSER.*(.*, *\(.*\)).*/\1_parser/p' libavcodec/allcodecs.c | tr '[a-z]' '[A-Z]'`
@@ -1557,6 +1557,8 @@ if x86 ; then
@@ -598,6 +599,7 @@ _xf86keysym=auto
_mlib=no #broken, thus disabled
_sgiaudio=auto
_sunaudio=auto
+_libsndio=auto
_alsa=auto
_fastmemcpy=yes
_unrarlib=yes
@@ -963,6 +965,8 @@ for ac_option do
--disable-mlib) _mlib=no ;;
--enable-sunaudio) _sunaudio=yes ;;
--disable-sunaudio) _sunaudio=no ;;
+ --enable-libsndio) _libsndio=yes ;;
+ --disable-libsndio) _libsndio=no ;;
--enable-sgiaudio) _sgiaudio=yes ;;
--disable-sgiaudio) _sgiaudio=no ;;
--enable-alsa) _alsa=yes ;;
@@ -1557,6 +1561,8 @@ if x86 ; then
pparam=`echo $exts | sed -e s/k6_mtrr/mtrr/ -e s/cyrix_arr/mtrr/ -e s/centaur_mcr/mtrr/ \
-e s/xmm/sse/ -e s/kni/sse/`
@ -28,7 +52,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
for ext in $pparam ; do
eval test \"\$_$ext\" = auto 2>/dev/null && eval _$ext=kernel_check
done
@@ -3065,7 +3067,7 @@ int main(void) { pthread_t tid; return pthread_create
@@ -3065,7 +3071,7 @@ int main(void) { pthread_t tid; return pthread_create
EOF
_pthreads=no
if not hpux ; then
@ -37,7 +61,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
# for crosscompilation, we cannot execute the program, be happy if we can link statically
cc_check $_ld_tmp && (tmp_run || test "$_ld_static") && _ld_pthread="$_ld_tmp" && _pthreads=yes && break
done
@@ -3108,7 +3110,7 @@ fi
@@ -3108,7 +3114,7 @@ fi
echores "$_rpath"
echocheck "iconv"
@ -46,7 +70,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
cat > $TMPC << EOF
#include <stdio.h>
#include <unistd.h>
@@ -4369,6 +4371,8 @@ if test "$_aa" = yes ; then
@@ -4369,6 +4375,8 @@ if test "$_aa" = yes ; then
_def_aa='#define HAVE_AA 1'
if cygwin ; then
_libs_mplayer="$_libs_mplayer `aalib-config --libs | cut -d " " -f 2,5,6`"
@ -55,7 +79,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
fi
_vosrc="$_vosrc vo_aa.c"
_vomodules="aa $_vomodules"
@@ -4576,7 +4580,7 @@ fi
@@ -4576,7 +4584,7 @@ fi
echores "$_png"
if test "$_png" = yes ; then
_def_png='#define HAVE_PNG 1'
@ -64,7 +88,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
_vosrc="$_vosrc vo_png.c"
_vomodules="png $_vomodules"
else
@@ -5054,7 +5058,7 @@ if test "$_arts" = yes ; then
@@ -5054,7 +5062,7 @@ if test "$_arts" = yes ; then
_def_arts='#define USE_ARTS 1'
_aosrc="$_aosrc ao_arts.c"
_aomodules="arts $_aomodules"
@ -73,7 +97,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
_inc_extra="$_inc_extra `artsc-config --cflags`"
else
_noaomodules="arts $_noaomodules"
@@ -5129,7 +5133,8 @@ fi
@@ -5129,7 +5137,8 @@ fi
echocheck "JACK"
if test "$_jack" = auto ; then
_jack=yes
@ -83,7 +107,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
cat > $TMPC << EOF
#include <jack/jack.h>
int main(void) { jack_client_new("test"); return 0; }
@@ -5144,6 +5149,7 @@ EOF
@@ -5144,6 +5153,7 @@ EOF
fi
fi
@ -91,7 +115,35 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
if test "$_jack" = yes ; then
_def_jack='#define USE_JACK 1'
_aosrc="$_aosrc ao_jack.c"
@@ -5343,7 +5349,7 @@ fi #if irix
@@ -5303,6 +5313,27 @@ fi
echores "$_sunaudio"
+echocheck "libsndio audio"
+if test "$_libsndio" = auto ; then
+ cat > $TMPC << EOF
+#include <sndio.h>
+int main(void) { struct sio_par par; sio_initpar(&par); return 0; }
+EOF
+ _libsndio=no
+ cc_check -lsndio && _libsndio=yes
+fi
+if test "$_libsndio" = yes ; then
+ _def_libsndio='#define USE_LIBSNDIO_AUDIO 1'
+ _aosrc="$_aosrc ao_libsndio.c"
+ _aomodules="libsndio $_aomodules"
+ _libs_mplayer="$_libs_mplayer -lsndio"
+else
+ _def_libsndio='#undef USE_LIBSNDIO_AUDIO'
+ _noaomodules="libsndio $_noaomodules"
+fi
+echores "$_libsndio"
+
+
if sunos; then
echocheck "Sun mediaLib"
if test "$_mlib" = auto ; then
@@ -5343,7 +5374,7 @@ fi #if irix
echocheck "VCD support"
@ -100,7 +152,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
_inputmodules="vcd $_inputmodules"
_def_vcd='#define HAVE_VCD 1'
_vcd="yes"
@@ -5592,7 +5598,7 @@ int main()
@@ -5592,7 +5623,7 @@ int main()
}
EOF
_fontconfig=no
@ -109,7 +161,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
_ld_tmp="-lfontconfig $_ld_tmp"
cc_check $_ld_tmp && _fontconfig=yes && _ld_extra="$_ld_extra $_ld_tmp" && break
done
@@ -5704,10 +5710,10 @@ cat > $TMPC << EOF
@@ -5704,10 +5735,10 @@ cat > $TMPC << EOF
int main(void) { (void) inflate(0, Z_NO_FLUSH); return 0; }
EOF
_zlib=no
@ -122,7 +174,7 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
else
_def_zlib='#undef HAVE_ZLIB'
_libavdecoders=`echo $_libavdecoders | sed -e s/FLASHSV_DECODER// -e s/PNG_DECODER// -e s/ZMBV_DECODER// -e s/DXA_DECODER// `
@@ -6207,7 +6213,7 @@ if test "$_real" = auto ; then
@@ -6207,7 +6238,7 @@ if test "$_real" = auto ; then
_real=no
_res_comment="dynamic loader support needed"
if test "$_dl" = yes || test "$_win32dll" = yes &&
@ -131,3 +183,11 @@ $OpenBSD: patch-configure,v 1.46 2008/05/01 13:52:19 sthen Exp $
_real=yes
fi
fi
@@ -8151,6 +8182,7 @@ $_def_openal_h
$_def_sys_asoundlib_h
$_def_alsa_asoundlib_h
$_def_sunaudio
+$_def_libsndio
$_def_sgiaudio
$_def_win32waveout
$_def_nas

View File

@ -1,7 +1,16 @@
$OpenBSD: patch-libao2_audio_out_c,v 1.1 2008/02/12 11:33:16 jakemsr Exp $
--- libao2/audio_out.c.orig Sun Oct 7 12:49:27 2007
+++ libao2/audio_out.c Sun Feb 10 17:00:56 2008
@@ -74,6 +74,7 @@ extern ao_functions_t audio_out_v4l2;
--- libao2/audio_out.c.orig Sun Oct 7 21:49:27 2007
+++ libao2/audio_out.c Tue Oct 14 11:48:58 2008
@@ -53,6 +53,9 @@ extern ao_functions_t audio_out_sdl;
#ifdef USE_SUN_AUDIO
extern ao_functions_t audio_out_sun;
#endif
+#ifdef USE_LIBSNDIO_AUDIO
+extern ao_functions_t audio_out_libsndio;
+#endif
#ifdef USE_SGI_AUDIO
extern ao_functions_t audio_out_sgi;
#endif
@@ -74,6 +77,7 @@ extern ao_functions_t audio_out_v4l2;
extern ao_functions_t audio_out_mpegpes;
extern ao_functions_t audio_out_pcm;
extern ao_functions_t audio_out_pss;
@ -9,7 +18,17 @@ $OpenBSD: patch-libao2_audio_out_c,v 1.1 2008/02/12 11:33:16 jakemsr Exp $
ao_functions_t* audio_out_drivers[] =
{
@@ -140,6 +141,7 @@ ao_functions_t* audio_out_drivers[] =
@@ -102,6 +106,9 @@ ao_functions_t* audio_out_drivers[] =
#ifdef USE_SGI_AUDIO
&audio_out_sgi,
#endif
+#ifdef USE_LIBSNDIO_AUDIO
+ &audio_out_libsndio,
+#endif
#ifdef USE_SUN_AUDIO
&audio_out_sun,
#endif
@@ -140,6 +147,7 @@ ao_functions_t* audio_out_drivers[] =
&audio_out_null,
// should not be auto-selected:
&audio_out_pcm,