[MPlayer-dev-eng] [PATCH] Updated JACK audio output driver

Kamil Strzelecki esack at o2.pl
Tue Jun 22 20:43:47 CEST 2004


On 11:29 22.06.2004, Reimar Döffinger wrote:
> [...]
> This is wrong! You can't just cast to (unsigned long *)! When int!=long, 
> this will overwrite the data behinde rate_hz and won't work at all on 
> big-endian! Don't make rate a pointer!

Is it ok now?

cheers
-- 
              ..:: Kamil Strzelecki = esack at dharma.one.pl ::..
 
    "There are two major products that come out of Berkeley: LSD and UNIX.
       We don't believe this to be a coincidence." --Jeremy S. Anderson

-------------- next part --------------
diff -Nur main/configure main-jack/configure
--- main/configure	2004-06-21 13:53:44.000000000 +0200
+++ main-jack/configure	2004-06-21 13:55:20.000000000 +0200
@@ -254,6 +254,7 @@
   --disable-ossaudio     disable OSS sound support [autodetect]
   --disable-arts         disable aRts sound support [autodetect]
   --disable-esd          disable esd sound support [autodetect]
+  --disable-jack         disable JACK sound support [autodetect]
   --disable-nas          disable NAS sound support [autodetect]
   --disable-sgiaudio     disable SGI sound support [autodetect]
   --disable-sunaudio     disable Sun sound support [autodetect]
@@ -320,6 +321,7 @@
   --with-livelibdir=DIR    path to LIVE.COM Streaming Media libraries
   --with-xmmsplugindir=DIR path to XMMS plugins
   --with-xmmslibdir=DIR    path to libxmms.so.1
+  --with-bio2jack=DIR      path to libbio2jack.a (e.g. /home/user/bio2jack)
   --with-cdparanoiaincdir=DIR  cdparanoia headers in DIR
   --with-cdparanoialibdir=DIR  cdparanoia libraries (libcdda_*) in DIR
   --with-termcaplib=NAME   name of library with termcap functionality
@@ -1171,6 +1173,7 @@
 _ossaudio=auto
 _arts=auto
 _esd=auto
+_jack=auto
 _liblzo=auto
 _mad=auto
 _vorbis=auto
@@ -1336,6 +1339,8 @@
   --disable-arts)	_arts=no	;;
   --enable-esd)		_esd=yes	;;
   --disable-esd)	_esd=no		;;
+  --enable-jack)	_jack=yes	;;
+  --disable-jack)	_jack=no	;;
   --enable-mad)		_mad=yes	;;
   --disable-mad)	_mad=no		;;
   --enable-liblzo)	_liblzo=yes	;;
@@ -1545,6 +1550,10 @@
   --with-xmmsplugindir=*)
     _xmmsplugindir=`echo $ac_option | cut -d '=' -f 2`
     ;;
+
+  --with-bio2jack=*)
+    _bio2jackdir=`echo $ac_option | cut -d '=' -f 2`
+    ;;
     
   --enable-profile)
     _profile='-p'
@@ -4068,6 +4077,47 @@
   _noaomodules="esd $_noaomodules"
 fi
 
+
+echocheck "JACK"
+if test "$_jack" = auto || test "$_jack" = yes ; then
+  _jack=no
+  if ( jackd --version | grep version | awk '{ print $3 }' ) >> "$TMPLOG" 2>&1 ; then
+
+cat > $TMPC << EOF
+#include <jack/jack.h>
+int main(void) { JACK_Init(); return 0; }
+EOF
+	if test -z "$_bio2jackdir" ; then
+		cc_check -lbio2jack `pkg-config --libs --cflags jack` && ( "$TMPO" >> "$TMPLOG" 2>&1 ) && _jack=yes
+	else
+		cc_check -L "$_bio2jackdir" -lbio2jack `pkg-config --libs --cflags jack` && ( "$TMPO" >> "$TMPLOG" 2>&1 ) && _jack=yes
+	fi
+
+	if test "$_jack" = no ; then
+	cat << EOF
+JACK audio output disabled.
+Please check if you have bio2jack (http://bio2jack.sf.net/) installed in your library path or use --with-bio2jack switch.
+EOF
+	fi
+  fi
+fi
+
+if test "$_jack" = yes ; then
+  _def_jack='#define USE_JACK 1'
+  _aosrc="$_aosrc ao_jack.c"
+  _aomodules="jack $_aomodules"
+  if test -z "$_bio2jackdir" ; then
+    _ld_jack="-lbio2jack `pkg-config --libs jack`"
+  else
+	_ld_jack="-L \"$_bio2jackdir\" -lbio2jack `pkg-config --libs jack`"
+  fi
+  _inc_jack=`pkg-config --cflags jack`
+else
+  _noaomodules="jack $_noaomodules"
+fi
+echores "$_jack"
+
+
 echocheck "ALSA audio"
 if test "$_alsa" != no ; then
   _alsa=no
@@ -6044,6 +6094,8 @@
 ARTS_INC = $_inc_arts
 ESD_LIB = $_ld_esd
 ESD_INC = $_inc_esd
+JACK_LIB = $_ld_jack
+JACK_INC = $_inc_jack
 SGIAUDIO_LIB = $_ld_sgiaudio
 
 # input/demuxer/codecs
@@ -6430,6 +6482,7 @@
 $_def_arts
 $_def_esd
 $_def_esd_latency
+$_def_jack
 $_def_sys_asoundlib_h
 $_def_alsa_asoundlib_h
 $_def_sunaudio
diff -Nur main/DOCS/man/en/mplayer.1 main-jack/DOCS/man/en/mplayer.1
--- main/DOCS/man/en/mplayer.1	2004-06-21 13:53:45.000000000 +0200
+++ main-jack/DOCS/man/en/mplayer.1	2004-06-21 13:55:20.000000000 +0200
@@ -1615,6 +1615,9 @@
 .B esd\ \ \ \ 
 Audio output through the ESD daemon.
 .TP
+.B jack\ \ \ \ 
+Audio output through JACK (Jack Audio Connection Kit).
+.TP
 .B nas\ \ \ \ 
 Audio output through NAS.
 .TP
diff -Nur main/DOCS/xml/en/audio.xml main-jack/DOCS/xml/en/audio.xml
--- main/DOCS/xml/en/audio.xml	2004-05-01 14:03:03.000000000 +0200
+++ main-jack/DOCS/xml/en/audio.xml	2004-06-21 13:55:20.000000000 +0200
@@ -47,6 +47,9 @@
 <row><entry>esd</entry><entry>
   native ESD driver (mostly for GNOME users)
   </entry></row>
+<row><entry>jack</entry><entry>
+  JACK (Jack Audio Connection Kit) driver
+  </entry></row>
 </tbody>
 </tgroup>
 </informaltable>
diff -Nur main/DOCS/xml/en/install.xml main-jack/DOCS/xml/en/install.xml
--- main/DOCS/xml/en/install.xml	2004-06-21 13:53:49.000000000 +0200
+++ main-jack/DOCS/xml/en/install.xml	2004-06-21 13:55:20.000000000 +0200
@@ -117,6 +117,16 @@
 <listitem><para>
   <emphasis role="bold">libsmb</emphasis> - optional, for Samba support.
   </para></listitem>
+<listitem><para>
+  <emphasis role="bold">bio2jack</emphasis> - optional, for JACK audio output
+  support, needed only in compile time. You can obtain it from 
+  <ulink url="http://bio2jack.sf.net/">http://bio2jack.sf.net</ulink>. Since it
+  doesn't have install option you have to manually put the file 
+  <filename>libbio2jack.a</filename> somewhere in your library path 
+  (e.g. <filename>/usr/local/lib</filename>) or use the 
+  <option>--with-bio2jack=DIR</option> switch to tell 
+  <filename>./configure</filename> where that file is.
+  </para></listitem>
 </itemizedlist>
 </sect2>
 
diff -Nur main/DOCS/xml/pl/audio.xml main-jack/DOCS/xml/pl/audio.xml
--- main/DOCS/xml/pl/audio.xml	2004-05-01 14:09:26.000000000 +0200
+++ main-jack/DOCS/xml/pl/audio.xml	2004-06-21 13:55:20.000000000 +0200
@@ -49,6 +49,9 @@
 <row><entry>esd</entry><entry>
   rdzenny sterownik ESD (g?ównie dla u?ytkowników GNOMEa)
   </entry></row>
+<row><entry>jack</entry><entry>
+  sterownik JACK (Jack Audio Connection Kit)
+  </entry></row>
 </tbody>
 </tgroup>
 </informaltable>
diff -Nur main/DOCS/xml/pl/install.xml main-jack/DOCS/xml/pl/install.xml
--- main/DOCS/xml/pl/install.xml	2004-06-21 13:53:52.000000000 +0200
+++ main-jack/DOCS/xml/pl/install.xml	2004-06-21 13:55:20.000000000 +0200
@@ -119,6 +119,16 @@
 <listitem><para>
   <emphasis role="bold">libsmb</emphasis> - opcjonalna, do obs?ugi Samby.
   </para></listitem>
+<listitem><para>
+  <emphasis role="bold">bio2jack</emphasis> - opcjonalna, do obs?ugi wyj?cia
+  d?wi?ku poprzez JACK, potrzebna jedynie w czasie kompilacji. Do pobrania z
+  <ulink url="http://bio2jack.sf.net/">http://bio2jack.sf.net</ulink>. Poniewa?
+  nie posiada ona opcji instalacji musisz samodzielnie umie?ci? plik
+  <filename>libbio2jack.a</filename> w swoim katalogu z bibliotekami 
+  (np. <filename>/usr/local/lib/</filename>) lub u?y? opcji 
+  <option>--with-bio2jack=KATALOG</option> aby przekaza? jego lokalizacj? do
+  skryptu <filename>./configure</filename>.
+  </para></listitem>
 </itemizedlist>
 </sect2>
 
diff -Nur main/libao2/ao_jack.c main-jack/libao2/ao_jack.c
--- main/libao2/ao_jack.c	1970-01-01 01:00:00.000000000 +0100
+++ main-jack/libao2/ao_jack.c	2004-06-22 20:07:42.000000000 +0200
@@ -0,0 +1,194 @@
+/*
+ * ao_jack - JACK audio output driver for MPlayer
+ *
+ * Kamil Strzelecki < esack at browarek.net >
+ *
+ * This driver is distribuited under terms of GPL
+ *
+ * It uses bio2jack (http://bio2jack.sf.net/).
+ *
+ */
+
+#include <stdio.h>
+
+#include "audio_out.h"
+#include "audio_out_internal.h"
+#include "afmt.h"
+#include "../config.h"
+#include "../mp_msg.h"
+
+//#include "bio2jack.h"
+
+static int driver = 0;
+
+//bio2jack stuff:
+#define ERR_SUCCESS						0
+#define ERR_OPENING_JACK				1
+#define ERR_RATE_MISMATCH				2
+#define ERR_BYTES_PER_FRAME_INVALID		3
+enum status_enum { PLAYING, PAUSED, STOPPED, CLOSED, RESET };
+void JACK_Init(void);
+int  JACK_Open(int* deviceID, unsigned int bits_per_sample, unsigned long *rate, int channels);
+int  JACK_Close(int deviceID); /* return 0 for success */
+void JACK_Reset(int deviceID); /* free all buffered data and reset several values in the device */
+long JACK_Write(int deviceID, char *data, unsigned long bytes); /* returns the number of bytes written */
+long JACK_GetJackLatency(int deviceID); /* return the latency in milliseconds of jack */
+int  JACK_SetState(int deviceID, enum status_enum state); /* playing, paused, stopped */
+int  JACK_SetVolume(int deviceID, int left, int right); /* returns 0 on success */
+void JACK_GetVolume(int deviceID, int *left, int *right);
+//
+
+
+static ao_info_t info =
+{
+	"JACK audio output",
+	"jack",
+	"Kamil Strzelecki <esack at browarek.net>",
+	""
+};
+
+
+LIBAO_EXTERN(jack)
+
+
+static int control(int cmd, void *arg)
+{
+	switch (cmd) {
+		case AOCONTROL_GET_VOLUME:	
+			{
+				ao_control_vol_t *vol = (ao_control_vol_t *)arg;
+				int *l, *r;
+				
+				JACK_GetVolume(driver, l, r);
+				vol->left = (float )*l;
+				vol->right = (float )*r;
+				
+				return CONTROL_OK;
+			}
+		case AOCONTROL_SET_VOLUME:
+			{
+				ao_control_vol_t *vol = (ao_control_vol_t *)arg;
+				int l = (int )vol->left,
+					r = (int )vol->right,
+					err = 0;
+
+				if((err = JACK_SetVolume(driver, l, r))) {
+					mp_msg(MSGT_AO, MSGL_ERR, 
+							"AO: [Jack] Setting volume failed, error %d\n",err);
+					return CONTROL_ERROR;
+				}
+				
+				return CONTROL_OK;
+			}
+	}
+
+	return(CONTROL_UNKNOWN);
+}
+
+
+static int init(int rate_hz, int channels, int format, int flags)
+{
+	int err, m, frag_spec;
+	unsigned long rate;
+	unsigned int bits_per_sample;
+	
+	mp_msg(MSGT_AO, MSGL_INFO, "AO: [Jack] Initialising library.\n");
+	JACK_Init();
+
+	switch (format) {
+		case AFMT_U8:
+		case AFMT_S8:
+			format = AFMT_U8;
+			bits_per_sample = 8;
+			m = 1;
+			break;
+		default:
+			format = AFMT_S16_LE;
+			bits_per_sample = 16;
+			m = 2;
+			break;
+	}
+
+	rate = rate_hz;
+	
+	err = JACK_Open(&driver, bits_per_sample, &rate, channels);
+	
+	/* if sample rates doesn't match try to open device with jack's rate and
+	 * let mplayer convert it (rate now contains that which jackd use) */
+	if(err == ERR_RATE_MISMATCH) {
+		mp_msg(MSGT_AO, MSGL_INFO, 
+				"AO: [Jack] Sample rate mismatch, trying to resample.\n");
+		
+		if((err = JACK_Open(&driver, bits_per_sample, &rate, channels))) {
+			mp_msg(MSGT_AO, MSGL_ERR,
+					"AO: [Jack] JACK_Open() failed, error %d\n", err);
+			return 0;
+		}
+	}
+	/* any other error */
+	else if(err != ERR_SUCCESS) {
+		mp_msg(MSGT_AO, MSGL_ERR, 
+				"AO: [Jack] JACK_Open() failed, error %d\n", err);
+		return 0;
+	}
+	
+	ao_data.format = format;
+	ao_data.channels = channels;
+	ao_data.samplerate = rate;
+	ao_data.bps = ( rate * channels * m );
+
+	mp_msg(MSGT_AO, MSGL_INFO, 
+			"AO: [Jack] OK. I'm ready to go (%d Hz/%d channels/%d bit)\n",
+			ao_data.samplerate, ao_data.channels, bits_per_sample);
+
+	return 1;
+}
+
+
+static void uninit(int immed)
+{
+	int errval = 0;
+	
+	JACK_Reset(driver);
+	
+	if((errval = JACK_Close(driver)))
+		mp_msg(MSGT_AO, MSGL_ERR, 
+				"AO: [Jack] error closing device, error %d\n", errval);
+}
+
+
+static int play(void* data,int len,int flags)
+{
+	return JACK_Write(driver, data, len);
+}
+
+
+static void audio_pause()
+{
+	JACK_SetState(driver, PAUSED);
+}
+
+
+static void audio_resume()
+{
+	JACK_SetState(driver, PLAYING);
+}
+
+
+static void reset()
+{
+	JACK_Reset(driver);
+}
+
+
+static int get_space()
+{
+	return JACK_GetBytesFreeSpace(driver);
+}
+
+
+static float get_delay()
+{
+	return (float )JACK_GetJackLatency(driver);
+}
+
diff -Nur main/libao2/audio_out.c main-jack/libao2/audio_out.c
--- main/libao2/audio_out.c	2004-05-13 00:48:15.000000000 +0200
+++ main-jack/libao2/audio_out.c	2004-06-21 13:55:20.000000000 +0200
@@ -22,6 +22,9 @@
 #ifdef USE_ESD
 extern ao_functions_t audio_out_esd;
 #endif
+#ifdef USE_JACK
+extern ao_functions_t audio_out_jack;
+#endif
 extern ao_functions_t audio_out_null;
 #ifdef HAVE_ALSA5
  extern ao_functions_t audio_out_alsa5;
@@ -97,6 +100,9 @@
 #ifdef USE_ESD
         &audio_out_esd,
 #endif
+#ifdef USE_JACK
+        &audio_out_jack,
+#endif
 #ifdef HAVE_NAS
 	&audio_out_nas,
 #endif
diff -Nur main/libao2/Makefile main-jack/libao2/Makefile
--- main/libao2/Makefile	2003-05-23 14:37:58.000000000 +0200
+++ main-jack/libao2/Makefile	2004-06-21 13:55:20.000000000 +0200
@@ -6,7 +6,7 @@
 
 OBJS=$(SRCS:.c=.o)
 
-CFLAGS  = $(OPTFLAGS) -I. -I.. $(ARTS_INC) $(ESD_INC) $(SDL_INC) $(X11_INC) $(EXTRA_INC) $(DXR2_INC) $(DVB_INC)
+CFLAGS  = $(OPTFLAGS) -I. -I.. $(ARTS_INC) $(ESD_INC) $(JACK_INC) $(SDL_INC) $(X11_INC) $(EXTRA_INC) $(DXR2_INC) $(DVB_INC)
 
 .SUFFIXES: .c .o
 
diff -Nur main/Makefile main-jack/Makefile
--- main/Makefile	2004-06-21 13:53:41.000000000 +0200
+++ main-jack/Makefile	2004-06-21 13:55:20.000000000 +0200
@@ -33,7 +33,7 @@
 OBJS_MPLAYER = $(SRCS_MPLAYER:.c=.o)
 
 VO_LIBS = $(AA_LIB) $(X_LIB) $(SDL_LIB) $(GGI_LIB) $(MP1E_LIB) $(MLIB_LIB) $(SVGA_LIB) $(DIRECTFB_LIB) $(CACA_LIB)
-AO_LIBS = $(ARTS_LIB) $(ESD_LIB) $(NAS_LIB) $(SGIAUDIO_LIB)
+AO_LIBS = $(ARTS_LIB) $(ESD_LIB) $(JACK_LIB) $(NAS_LIB) $(SGIAUDIO_LIB)
 CODEC_LIBS = $(AV_LIB) $(FAME_LIB) $(MAD_LIB) $(VORBIS_LIB) $(THEORA_LIB) $(FAAD_LIB) $(LIBLZO_LIB) $(DECORE_LIB) $(XVID_LIB) $(PNG_LIB) $(Z_LIB) $(JPEG_LIB) $(ALSA_LIB) $(XMMS_LIB) $(MATROSKA_LIB) 
 COMMON_LIBS = libmpcodecs/libmpcodecs.a mp3lib/libMP3.a liba52/liba52.a libmpeg2/libmpeg2.a $(W32_LIB) $(DS_LIB) libaf/libaf.a libmpdemux/libmpdemux.a input/libinput.a postproc/libswscale.a osdep/libosdep.a $(DVDREAD_LIB) $(CODEC_LIBS) $(FREETYPE_LIB) $(TERMCAP_LIB) $(CDPARANOIA_LIB) $(MPLAYER_NETWORK_LIB) $(WIN32_LIB) $(GIF_LIB) $(MACOSX_FRAMEWORKS) $(SMBSUPPORT_LIB) $(FRIBIDI_LIB) $(FONTCONFIG_LIB) $(ENCA_LIB)
 


More information about the MPlayer-dev-eng mailing list