summaryrefslogtreecommitdiffstats
path: root/media-sound/mpg123/files
diff options
context:
space:
mode:
Diffstat (limited to 'media-sound/mpg123/files')
-rw-r--r--media-sound/mpg123/files/mpg123-ds-rcc.patch150
-rw-r--r--media-sound/mpg123/files/mpg123-ds-rcc1121.patch247
-rw-r--r--media-sound/mpg123/files/mpg123-ds-rcc173.patch271
-rw-r--r--media-sound/mpg123/files/mpg123-ds-rcc65.patch240
-rw-r--r--media-sound/mpg123/files/mpg123-osx.diff394
5 files changed, 1302 insertions, 0 deletions
diff --git a/media-sound/mpg123/files/mpg123-ds-rcc.patch b/media-sound/mpg123/files/mpg123-ds-rcc.patch
new file mode 100644
index 0000000..620457b
--- /dev/null
+++ b/media-sound/mpg123/files/mpg123-ds-rcc.patch
@@ -0,0 +1,150 @@
+diff -dPNur mpg123/Makefile mpg123-new/Makefile
+--- mpg123/Makefile 2005-07-26 05:50:35.000000000 +0000
++++ mpg123-new/Makefile 2005-07-26 05:52:38.000000000 +0000
+@@ -789,12 +789,12 @@
+ mpg123-make:
+ @ $(MAKE) CFLAGS='$(CFLAGS)' BINNAME=mpg123 mpg123
+
+-mpg123: mpg123.o common.o $(OBJECTS) decode_2to1.o decode_4to1.o \
++mpg123: mpg123.o common.o rccpatch.o $(OBJECTS) decode_2to1.o decode_4to1.o \
+ tabinit.o audio.o layer1.o layer2.o layer3.o buffer.o \
+ getlopt.o httpget.o xfermem.o equalizer.o \
+ decode_ntom.o Makefile wav.o readers.o \
+ control_generic.o vbrhead.o playlist.o getbits.o
+- $(CC) $(CFLAGS) $(LDFLAGS) mpg123.o tabinit.o common.o layer1.o \
++ $(CC) $(CFLAGS) $(LDFLAGS) -lrcc rccpatch.o mpg123.o tabinit.o common.o layer1.o \
+ layer2.o layer3.o audio.o buffer.o decode_2to1.o equalizer.o \
+ decode_4to1.o getlopt.o httpget.o xfermem.o decode_ntom.o \
+ wav.o readers.o control_generic.o vbrhead.o playlist.o getbits.o \
+diff -dPNur mpg123/common.c mpg123-new/common.c
+--- mpg123/common.c 2005-07-26 05:50:37.000000000 +0000
++++ mpg123-new/common.c 2005-07-26 05:54:32.000000000 +0000
+@@ -22,6 +22,7 @@
+ #endif
+ #endif
+
++#include "rccpatch.h"
+ #include "mpg123.h"
+ #include "genre.h"
+ #include "common.h"
+@@ -666,6 +667,8 @@
+ char comment[31]={0,};
+ char genre[31]={0,};
+
++ char *ctitle, *cartist, *calbum, *ccomment;
++
+ if(param.quiet)
+ return;
+
+@@ -675,15 +678,25 @@
+ strncpy(year,tag->year,4);
+ strncpy(comment,tag->comment,30);
+
++ ctitle = rccPatchRecode(title);
++ cartist = rccPatchRecode(artist);
++ calbum = rccPatchRecode(album);
++ ccomment = rccPatchRecode(comment);
++
+ if ( tag->genre < sizeof(genre_table)/sizeof(*genre_table) ) {
+ strncpy(genre, genre_table[tag->genre], 30);
+ } else {
+ strncpy(genre,"Unknown",30);
+ }
+-
+- fprintf(stderr,"Title : %-30s Artist: %s\n",title,artist);
+- fprintf(stderr,"Album : %-30s Year : %4s\n",album,year);
+- fprintf(stderr,"Comment: %-30s Genre : %s\n",comment,genre);
++
++ fprintf(stderr,"Title : %-30s Artist: %s\n",ctitle?ctitle:title,cartist?cartist:artist);
++ fprintf(stderr,"Album : %-30s Year : %4s\n",calbum?calbum:album,year);
++ fprintf(stderr,"Comment: %-30s Genre : %s\n",ccomment?ccomment:comment,genre);
++
++ if (ctitle) free(ctitle);
++ if (cartist) free(cartist);
++ if (calbum) free(calbum);
++ if (ccomment) free(ccomment);
+ }
+
+ #if 0
+diff -dPNur mpg123/mpg123.c mpg123-new/mpg123.c
+--- mpg123/mpg123.c 2001-01-18 14:00:35.000000000 +0000
++++ mpg123-new/mpg123.c 2005-07-26 05:51:08.000000000 +0000
+@@ -33,6 +33,8 @@
+ #include "term.h"
+ #include "playlist.h"
+
++#include "rccpatch.h"
++
+ #include "version.h"
+
+ static void usage(char *dummy);
+@@ -890,6 +892,8 @@
+ term_init();
+ }
+ #endif
++
++ rccPatchInit();
+
+ leftFrames = numframes;
+ for(frameNum=0;read_frame(rd,fr) && leftFrames && !intflag;frameNum++) {
+@@ -1006,6 +1010,8 @@
+ }
+ }
+ }
++ rccPatchFree();
++
+ #ifndef NOXFERMEM
+ if (buffermem && param.usebuffer) {
+ buffer_end();
+diff -dPNur mpg123/rccpatch.c mpg123-new/rccpatch.c
+--- mpg123/rccpatch.c 1970-01-01 00:00:00.000000000 +0000
++++ mpg123-new/rccpatch.c 2005-07-26 05:51:08.000000000 +0000
+@@ -0,0 +1,40 @@
++#include <librcc.h>
++
++#define ID3_CLASS 0
++#define OUT_CLASS 1
++static rcc_class classes[] = {
++ { "id3", RCC_CLASS_STANDARD, NULL, NULL, "ID3 Encoding", 0 },
++ { "out", RCC_CLASS_STANDARD, NULL, NULL, "Output Encoding", 0 },
++ { NULL }
++};
++
++static int rcc_initialized = 0;
++
++void rccPatchFree() {
++ if (rcc_initialized) {
++ rccFree();
++ rcc_initialized = 0;
++ }
++}
++
++void rccPatchInit() {
++ if (rcc_initialized) return;
++ rccInit();
++ rccInitDefaultContext(NULL, 0, 0, classes, 0);
++ rccLoad(NULL, "xmms");
++ rccInitDb4(NULL, NULL, 0);
++ rcc_initialized = 1;
++}
++
++static void rccPatchTryInit() {
++ if (!rcc_initialized) {
++ rccPatchInit();
++ if (rcc_initialized) atexit(rccPatchFree);
++ }
++}
++
++char *rccPatchRecode(const char *str) {
++ char *res;
++ rccPatchTryInit();
++ return rccRecode(NULL, ID3_CLASS, OUT_CLASS, str);
++}
+diff -dPNur mpg123/rccpatch.h mpg123-new/rccpatch.h
+--- mpg123/rccpatch.h 1970-01-01 00:00:00.000000000 +0000
++++ mpg123-new/rccpatch.h 2005-07-26 05:51:08.000000000 +0000
+@@ -0,0 +1,4 @@
++void rccPatchFree();
++void rccPatchInit();
++char *rccPatchRecode(const char *str);
++
diff --git a/media-sound/mpg123/files/mpg123-ds-rcc1121.patch b/media-sound/mpg123/files/mpg123-ds-rcc1121.patch
new file mode 100644
index 0000000..1335795
--- /dev/null
+++ b/media-sound/mpg123/files/mpg123-ds-rcc1121.patch
@@ -0,0 +1,247 @@
+diff -dPNur mpg123-1.12.1/configure.ac mpg123-1.12.1-new/configure.ac
+--- mpg123-1.12.1/configure.ac 2010-03-31 10:27:37.000000000 +0200
++++ mpg123-1.12.1-new/configure.ac 2010-07-07 23:44:57.000000000 +0200
+@@ -998,6 +998,21 @@
+ AC_CHECK_LIB([m], [sqrt])
+ AC_CHECK_LIB([mx], [powf])
+
++# LibRCC
++AC_CHECK_LIB(rcc, rccInit,[
++ AC_CHECK_HEADERS(librcc.h,[
++ LIBRCC_LIBS="-lrcc"
++ LIBRCC_INCLUDES="-DHAVE_LIBRCC"
++ ],[
++ LIBRCC_LIBS=""
++ LIBRCC_INCLUDES=""
++])],[
++ LIBRCC_LIBS=""
++ LIBRCC_INCLUDES=""
++])
++AC_SUBST(LIBRCC_LIBS)
++AC_SUBST(LIBRCC_INCLUDES)
++
+ # attempt to make the signal stuff work... also with GENERIC - later
+ #if test x"$ac_cv_header_sys_signal_h" = xyes; then
+ # AC_CHECK_FUNCS( sigemptyset sigaddset sigprocmask sigaction )
+diff -dPNur mpg123-1.12.1/src/libmpg123/id3.c mpg123-1.12.1-new/src/libmpg123/id3.c
+--- mpg123-1.12.1/src/libmpg123/id3.c 2010-03-31 10:27:35.000000000 +0200
++++ mpg123-1.12.1-new/src/libmpg123/id3.c 2010-07-07 23:51:50.000000000 +0200
+@@ -9,6 +9,8 @@
+ #include "mpg123lib_intern.h"
+ #include "id3.h"
+ #include "debug.h"
++#include "rccpatch.h"
++
+
+ #ifndef NO_ID3V2 /* Only the main parsing routine will always be there. */
+
+@@ -829,6 +831,15 @@
+ size_t length = l;
+ size_t i;
+ unsigned char *p;
++ char *ctitle;
++
++ ctitle = mpg123_rcc_recode(s, l, &i);
++ if (ctitle) {
++ convert_utf8(sb, ctitle, i, 0);
++ free(ctitle);
++ return;
++ }
++
+ /* determine real length, a latin1 character can at most take 2 in UTF8 */
+ for(i=0; i<l; ++i)
+ if(s[i] >= 0x80) ++length;
+diff -dPNur mpg123-1.12.1/src/libmpg123/Makefile.am mpg123-1.12.1-new/src/libmpg123/Makefile.am
+--- mpg123-1.12.1/src/libmpg123/Makefile.am 2010-03-31 10:27:35.000000000 +0200
++++ mpg123-1.12.1-new/src/libmpg123/Makefile.am 2010-07-07 23:44:57.000000000 +0200
+@@ -29,6 +29,8 @@
+ libmpg123_la_DEPENDENCIES = @DECODER_LOBJ@ @LFS_LOBJ@
+
+ libmpg123_la_SOURCES = \
++ rccpatch.c \
++ rccpatch.h \
+ compat.c \
+ compat.h \
+ parse.c \
+diff -dPNur mpg123-1.12.1/src/libmpg123/rccpatch.c mpg123-1.12.1-new/src/libmpg123/rccpatch.c
+--- mpg123-1.12.1/src/libmpg123/rccpatch.c 1970-01-01 01:00:00.000000000 +0100
++++ mpg123-1.12.1-new/src/libmpg123/rccpatch.c 2010-07-07 23:55:59.000000000 +0200
+@@ -0,0 +1,76 @@
++#include <string.h>
++#include <librcc.h>
++#include "mpg123.h"
++
++#define ID3_CLASS 0
++#define UTF_CLASS 1
++#define OUT_CLASS 2
++static rcc_class classes[] = {
++ { "id3", RCC_CLASS_STANDARD, NULL, NULL, "ID3 Encoding", 0 },
++ { "utf", RCC_CLASS_KNOWN, "UTF-8", NULL, "Unicode Encoding", 0 },
++ { "out", RCC_CLASS_STANDARD, NULL, NULL, "Output Encoding", 0 },
++ { NULL }
++};
++
++static int rcc_initialized = 0;
++
++void mpg123_rcc_free() {
++ if (rcc_initialized) {
++ rccFree();
++ rcc_initialized = 0;
++ }
++}
++
++void mpg123_rcc_init() {
++ if (rcc_initialized) return;
++ rccInit();
++ rccInitDefaultContext(NULL, 0, 0, classes, 0);
++ rccLoad(NULL, "xmms");
++ rccInitDb4(NULL, NULL, 0);
++ rcc_initialized = 1;
++}
++
++static void mpg123_rcc_try_init() {
++ if (!rcc_initialized) {
++ mpg123_rcc_init();
++ if (rcc_initialized) atexit(mpg123_rcc_free);
++ }
++}
++
++
++char *mpg123_rcc_recode(const char *str, size_t len, size_t *rlen) {
++ char *res;
++ mpg123_rcc_try_init();
++ return rccSizedRecode(NULL, ID3_CLASS, UTF_CLASS, str, len, rlen);
++}
++
++static void mpg123_rcc_recode_string(mpg123_string *str, rcc_class_id from, rcc_class_id to) {
++ size_t size;
++ char *res;
++
++ if ((!str)||(str->fill<2)) return;
++
++ mpg123_rcc_try_init();
++
++ res = rccSizedRecode(NULL, from, to, str->p, str->fill - 1, &size);
++ if (res) {
++ if (size+1>str->size) {
++ if (!mpg123_resize_string(str, size + 1)) {
++ // allocation failed
++ free(res);
++ return;
++ }
++ }
++ strncpy(str->p, res, size + 1);
++ str->fill = size + 1;
++ free(res);
++ }
++}
++
++void mpg123_rcc_recode_utf_string(mpg123_string *str) {
++ mpg123_rcc_recode_string(str, UTF_CLASS, OUT_CLASS);
++}
++
++void mpg123_rcc_recode_latin_string(mpg123_string *str) {
++ mpg123_rcc_recode_string(str, ID3_CLASS, OUT_CLASS);
++}
+diff -dPNur mpg123-1.12.1/src/libmpg123/rccpatch.h mpg123-1.12.1-new/src/libmpg123/rccpatch.h
+--- mpg123-1.12.1/src/libmpg123/rccpatch.h 1970-01-01 01:00:00.000000000 +0100
++++ mpg123-1.12.1-new/src/libmpg123/rccpatch.h 2010-07-07 23:44:57.000000000 +0200
+@@ -0,0 +1,5 @@
++void mpg123_rcc_free();
++void mpg123_rcc_init();
++char *mpg123_rcc_recode(const char *str, size_t len, size_t *rlen);
++void mpg123_rcc_recode_utf_string(mpg123_string *str);
++void mpg123_rcc_recode_latin_string(mpg123_string *str);
+diff -dPNur mpg123-1.12.1/src/Makefile.am mpg123-1.12.1-new/src/Makefile.am
+--- mpg123-1.12.1/src/Makefile.am 2010-03-31 10:27:36.000000000 +0200
++++ mpg123-1.12.1-new/src/Makefile.am 2010-07-07 23:46:10.000000000 +0200
+@@ -5,10 +5,10 @@
+ ## initially written by Nicholas J. Humfrey
+
+ AM_CPPFLAGS = -DPKGLIBDIR="\"$(pkglibdir)\""
+-mpg123_LDADD = $(LIBLTDL) libmpg123/libmpg123.la @MODULE_OBJ@ @OUTPUT_OBJ@ @OUTPUT_LIBS@
++mpg123_LDADD = $(LIBLTDL) libmpg123/libmpg123.la @MODULE_OBJ@ @OUTPUT_OBJ@ @OUTPUT_LIBS@ @LIBRCC_LIBS@
+ mpg123_LDFLAGS = @EXEC_LT_LDFLAGS@ @OUTPUT_LDFLAGS@
+ # Just mpg123_INCLUDES has no effect on build! Trying that before reverting to AM_CPPFLAGS.
+-INCLUDES = $(LTDLINCL) -I$(top_builddir)/src/libmpg123 -I$(top_srcdir)/src/libmpg123
++INCLUDES = $(LTDLINCL) -I$(top_builddir)/src/libmpg123 -I$(top_srcdir)/src/libmpg123 @LIBRCC_INCLUDES@
+ # libltdl is not mentioned here... it's not that trivial
+ mpg123_DEPENDENCIES = @OUTPUT_OBJ@ @MODULE_OBJ@ libmpg123/libmpg123.la
+
+diff -dPNur mpg123-1.12.1/src/metaprint.c mpg123-1.12.1-new/src/metaprint.c
+--- mpg123-1.12.1/src/metaprint.c 2010-03-31 10:27:36.000000000 +0200
++++ mpg123-1.12.1-new/src/metaprint.c 2010-07-07 23:54:21.000000000 +0200
+@@ -17,7 +17,11 @@
+ if(source == NULL) return;
+
+ if(utf8env) mpg123_copy_string(source, dest);
+- else utf8_ascii(dest, source);
++ else {
++ mpg123_copy_string(source, dest);
++ mpg123_rcc_recode_utf_string(dest);
++// utf8_ascii(dest, source);
++ }
+ }
+
+ /* print tags... limiting the UTF-8 to ASCII */
+@@ -53,6 +57,7 @@
+ strncpy(tag[TITLE].p,v1->title,30);
+ tag[TITLE].p[30] = 0;
+ tag[TITLE].fill = strlen(tag[TITLE].p) + 1;
++ mpg123_rcc_recode_latin_string(&tag[TITLE]);
+ }
+ }
+ if(!tag[ARTIST].fill)
+@@ -62,6 +67,7 @@
+ strncpy(tag[ARTIST].p,v1->artist,30);
+ tag[ARTIST].p[30] = 0;
+ tag[ARTIST].fill = strlen(tag[ARTIST].p) + 1;
++ mpg123_rcc_recode_latin_string(&tag[ARTIST]);
+ }
+ }
+ if(!tag[ALBUM].fill)
+@@ -71,6 +77,7 @@
+ strncpy(tag[ALBUM].p,v1->album,30);
+ tag[ALBUM].p[30] = 0;
+ tag[ALBUM].fill = strlen(tag[ALBUM].p) + 1;
++ mpg123_rcc_recode_latin_string(&tag[ALBUM]);
+ }
+ }
+ if(!tag[COMMENT].fill)
+@@ -80,6 +87,7 @@
+ strncpy(tag[COMMENT].p,v1->comment,30);
+ tag[COMMENT].p[30] = 0;
+ tag[COMMENT].fill = strlen(tag[COMMENT].p) + 1;
++ mpg123_rcc_recode_latin_string(&tag[COMMENT]);
+ }
+ }
+ if(!tag[YEAR].fill)
+diff -dPNur mpg123-1.12.1/src/mpg123.c mpg123-1.12.1-new/src/mpg123.c
+--- mpg123-1.12.1/src/mpg123.c 2010-03-31 10:27:36.000000000 +0200
++++ mpg123-1.12.1-new/src/mpg123.c 2010-07-07 23:52:58.000000000 +0200
+@@ -10,6 +10,7 @@
+ #include "mpg123app.h"
+ #include "mpg123.h"
+ #include "local.h"
++#include "rccpatch.h"
+
+ #ifdef HAVE_SYS_WAIT_H
+ #include <sys/wait.h>
+@@ -973,6 +974,8 @@
+ if(param.term_ctrl)
+ term_init();
+ #endif
++
++ mpg123_rcc_init();
+ while ((fname = get_next_file()))
+ {
+ char *dirname, *filename;
+@@ -1132,6 +1135,8 @@
+ #endif
+ }
+ } /* end of loop over input files */
++ mpg123_rcc_free();
++
+ /* Ensure we played everything. */
+ if(param.smooth && param.usebuffer)
+ {
diff --git a/media-sound/mpg123/files/mpg123-ds-rcc173.patch b/media-sound/mpg123/files/mpg123-ds-rcc173.patch
new file mode 100644
index 0000000..ae814ff
--- /dev/null
+++ b/media-sound/mpg123/files/mpg123-ds-rcc173.patch
@@ -0,0 +1,271 @@
+diff -dPNur mpg123-1.7.3/configure.ac mpg123-1.7.3-rusxmms/configure.ac
+--- mpg123-1.7.3/configure.ac 2009-04-27 09:02:40.000000000 +0200
++++ mpg123-1.7.3-rusxmms/configure.ac 2009-06-13 23:22:17.000000000 +0200
+@@ -759,6 +759,21 @@
+ AC_CHECK_LIB([m], [sqrt])
+ AC_CHECK_LIB([mx], [powf])
+
++# LibRCC
++AC_CHECK_LIB(rcc, rccInit,[
++ AC_CHECK_HEADERS(librcc.h,[
++ LIBRCC_LIBS="-lrcc"
++ LIBRCC_INCLUDES="-DHAVE_LIBRCC"
++ ],[
++ LIBRCC_LIBS=""
++ LIBRCC_INCLUDES=""
++])],[
++ LIBRCC_LIBS=""
++ LIBRCC_INCLUDES=""
++])
++AC_SUBST(LIBRCC_LIBS)
++AC_SUBST(LIBRCC_INCLUDES)
++
+ # attempt to make the signal stuff work... also with GENERIC - later
+ #if test x"$ac_cv_header_sys_signal_h" = xyes; then
+ # AC_CHECK_FUNCS( sigemptyset sigaddset sigprocmask sigaction )
+diff -dPNur mpg123-1.7.3/src/libmpg123/id3.c mpg123-1.7.3-rusxmms/src/libmpg123/id3.c
+--- mpg123-1.7.3/src/libmpg123/id3.c 2009-04-27 09:02:12.000000000 +0200
++++ mpg123-1.7.3-rusxmms/src/libmpg123/id3.c 2009-06-14 00:34:23.000000000 +0200
+@@ -9,6 +9,8 @@
+ #include "mpg123lib_intern.h"
+ #include "id3.h"
+ #include "debug.h"
++#include "rccpatch.h"
++
+
+ #ifndef NO_ID3V2 /* Only the main parsing routine will always be there. */
+
+@@ -774,6 +776,15 @@
+ size_t length = l;
+ size_t i;
+ unsigned char *p;
++ char *ctitle;
++
++ ctitle = mpg123_rcc_recode(s, l, &i);
++ if (ctitle) {
++ convert_utf8(sb, ctitle, i);
++ free(ctitle);
++ return;
++ }
++
+ /* determine real length, a latin1 character can at most take 2 in UTF8 */
+ for(i=0; i<l; ++i)
+ if(s[i] >= 0x80) ++length;
+diff -dPNur mpg123-1.7.3/src/libmpg123/libmpg123.sym mpg123-1.7.3-rusxmms/src/libmpg123/libmpg123.sym
+--- mpg123-1.7.3/src/libmpg123/libmpg123.sym 2009-04-27 09:07:20.000000000 +0200
++++ mpg123-1.7.3-rusxmms/src/libmpg123/libmpg123.sym 2009-06-14 01:53:25.000000000 +0200
+@@ -74,3 +74,8 @@
+ mpg123_position
+ mpg123_length
+ mpg123_set_filesize
++mpg123_rcc_free
++mpg123_rcc_init
++mpg123_rcc_recode
++mpg123_rcc_recode_utf_string
++mpg123_rcc_recode_latin_string
+diff -dPNur mpg123-1.7.3/src/libmpg123/libmpg123.sym.in mpg123-1.7.3-rusxmms/src/libmpg123/libmpg123.sym.in
+--- mpg123-1.7.3/src/libmpg123/libmpg123.sym.in 2009-04-27 09:02:12.000000000 +0200
++++ mpg123-1.7.3-rusxmms/src/libmpg123/libmpg123.sym.in 2009-06-14 01:51:45.000000000 +0200
+@@ -74,3 +74,8 @@
+ mpg123_position@LARGEFILE_SUFFIX@
+ mpg123_length@LARGEFILE_SUFFIX@
+ mpg123_set_filesize@LARGEFILE_SUFFIX@
++mpg123_rcc_free
++mpg123_rcc_init
++mpg123_rcc_recode
++mpg123_rcc_recode_utf_string
++mpg123_rcc_recode_latin_string
+diff -dPNur mpg123-1.7.3/src/libmpg123/Makefile.am mpg123-1.7.3-rusxmms/src/libmpg123/Makefile.am
+--- mpg123-1.7.3/src/libmpg123/Makefile.am 2009-04-27 09:02:12.000000000 +0200
++++ mpg123-1.7.3-rusxmms/src/libmpg123/Makefile.am 2009-06-14 00:10:34.000000000 +0200
+@@ -31,6 +31,8 @@
+ libmpg123_la_DEPENDENCIES = @DECODER_LOBJ@ libmpg123.sym
+
+ libmpg123_la_SOURCES = \
++ rccpatch.c \
++ rccpatch.h \
+ compat.c \
+ compat.h \
+ parse.c \
+diff -dPNur mpg123-1.7.3/src/libmpg123/rccpatch.c mpg123-1.7.3-rusxmms/src/libmpg123/rccpatch.c
+--- mpg123-1.7.3/src/libmpg123/rccpatch.c 1970-01-01 01:00:00.000000000 +0100
++++ mpg123-1.7.3-rusxmms/src/libmpg123/rccpatch.c 2009-06-14 01:54:37.000000000 +0200
+@@ -0,0 +1,76 @@
++#include <string.h>
++#include <librcc.h>
++#include "mpg123.h"
++
++#define ID3_CLASS 0
++#define UTF_CLASS 1
++#define OUT_CLASS 2
++static rcc_class classes[] = {
++ { "id3", RCC_CLASS_STANDARD, NULL, NULL, "ID3 Encoding", 0 },
++ { "utf", RCC_CLASS_KNOWN, "UTF-8", NULL, "Unicode Encoding", 0 },
++ { "out", RCC_CLASS_STANDARD, NULL, NULL, "Output Encoding", 0 },
++ { NULL }
++};
++
++static int rcc_initialized = 0;
++
++void mpg123_rcc_free() {
++ if (rcc_initialized) {
++ rccFree();
++ rcc_initialized = 0;
++ }
++}
++
++void mpg123_rcc_init() {
++ if (rcc_initialized) return;
++ rccInit();
++ rccInitDefaultContext(NULL, 0, 0, classes, 0);
++ rccLoad(NULL, "xmms");
++ rccInitDb4(NULL, NULL, 0);
++ rcc_initialized = 1;
++}
++
++static void mpg123_rcc_try_init() {
++ if (!rcc_initialized) {
++ mpg123_rcc_init();
++ if (rcc_initialized) atexit(mpg123_rcc_free);
++ }
++}
++
++
++char *mpg123_rcc_recode(const char *str, size_t len, size_t *rlen) {
++ char *res;
++ mpg123_rcc_try_init();
++ return rccSizedRecode(NULL, ID3_CLASS, UTF_CLASS, str, len, rlen);
++}
++
++static void mpg123_rcc_recode_string(mpg123_string *str, rcc_class_id from, rcc_class_id to) {
++ size_t size;
++ char *res;
++
++ if ((!str)||(str->fill<2)) return;
++
++ mpg123_rcc_try_init();
++
++ res = rccSizedRecode(NULL, from, to, str->p, str->fill - 1, &size);
++ if (res) {
++ if (size+1>str->size) {
++ if (!mpg123_resize_string(str, size + 1)) {
++ // allocation failed
++ free(res);
++ return;
++ }
++ }
++ strncpy(str->p, res, size + 1);
++ str->fill = size + 1;
++ free(res);
++ }
++}
++
++void mpg123_rcc_recode_utf_string(mpg123_string *str) {
++ mpg123_rcc_recode_string(str, UTF_CLASS, OUT_CLASS);
++}
++
++void mpg123_rcc_recode_latin_string(mpg123_string *str) {
++ mpg123_rcc_recode_string(str, ID3_CLASS, OUT_CLASS);
++}
+diff -dPNur mpg123-1.7.3/src/libmpg123/rccpatch.h mpg123-1.7.3-rusxmms/src/libmpg123/rccpatch.h
+--- mpg123-1.7.3/src/libmpg123/rccpatch.h 1970-01-01 01:00:00.000000000 +0100
++++ mpg123-1.7.3-rusxmms/src/libmpg123/rccpatch.h 2009-06-14 01:51:21.000000000 +0200
+@@ -0,0 +1,5 @@
++void mpg123_rcc_free();
++void mpg123_rcc_init();
++char *mpg123_rcc_recode(const char *str, size_t len, size_t *rlen);
++void mpg123_rcc_recode_utf_string(mpg123_string *str);
++void mpg123_rcc_recode_latin_string(mpg123_string *str);
+diff -dPNur mpg123-1.7.3/src/Makefile.am mpg123-1.7.3-rusxmms/src/Makefile.am
+--- mpg123-1.7.3/src/Makefile.am 2009-04-27 09:02:12.000000000 +0200
++++ mpg123-1.7.3-rusxmms/src/Makefile.am 2009-06-14 00:10:22.000000000 +0200
+@@ -5,10 +5,10 @@
+ ## initially written by Nicholas J. Humfrey
+
+ AM_CPPFLAGS = -DPKGLIBDIR="\"$(pkglibdir)\""
+-mpg123_LDADD = $(LIBLTDL) libmpg123/libmpg123.la @MODULE_OBJ@ @OUTPUT_OBJ@ @OUTPUT_LIBS@
++mpg123_LDADD = $(LIBLTDL) libmpg123/libmpg123.la @MODULE_OBJ@ @OUTPUT_OBJ@ @OUTPUT_LIBS@ @LIBRCC_LIBS@
+ mpg123_LDFLAGS = @LT_LDFLAGS@ @OUTPUT_LDFLAGS@
+ # Just mpg123_INCLUDES has no effect on build! Trying that before reverting to AM_CPPFLAGS.
+-INCLUDES = $(LTDLINCL) -I$(top_builddir)/src/libmpg123 -I$(top_srcdir)/src/libmpg123
++INCLUDES = $(LTDLINCL) -I$(top_builddir)/src/libmpg123 -I$(top_srcdir)/src/libmpg123 @LIBRCC_INCLUDES@
+ # libltdl is not mentioned here... it's not that trivial
+ mpg123_DEPENDENCIES = @OUTPUT_OBJ@ @MODULE_OBJ@ libmpg123/libmpg123.la
+
+diff -dPNur mpg123-1.7.3/src/metaprint.c mpg123-1.7.3-rusxmms/src/metaprint.c
+--- mpg123-1.7.3/src/metaprint.c 2009-04-27 09:02:12.000000000 +0200
++++ mpg123-1.7.3-rusxmms/src/metaprint.c 2009-06-14 01:59:09.000000000 +0200
+@@ -17,7 +17,11 @@
+ if(source == NULL) return;
+
+ if(utf8env) mpg123_copy_string(source, dest);
+- else utf8_ascii(dest, source);
++ else {
++ mpg123_copy_string(source, dest);
++ mpg123_rcc_recode_utf_string(dest);
++// utf8_ascii(dest, source);
++ }
+ }
+
+ /* print tags... limiting the UTF-8 to ASCII */
+@@ -53,6 +57,7 @@
+ strncpy(tag[TITLE].p,v1->title,30);
+ tag[TITLE].p[30] = 0;
+ tag[TITLE].fill = strlen(tag[TITLE].p) + 1;
++ mpg123_rcc_recode_latin_string(&tag[TITLE]);
+ }
+ }
+ if(!tag[ARTIST].fill)
+@@ -62,6 +67,7 @@
+ strncpy(tag[ARTIST].p,v1->artist,30);
+ tag[ARTIST].p[30] = 0;
+ tag[ARTIST].fill = strlen(tag[ARTIST].p) + 1;
++ mpg123_rcc_recode_latin_string(&tag[ARTIST]);
+ }
+ }
+ if(!tag[ALBUM].fill)
+@@ -71,6 +77,7 @@
+ strncpy(tag[ALBUM].p,v1->album,30);
+ tag[ALBUM].p[30] = 0;
+ tag[ALBUM].fill = strlen(tag[ALBUM].p) + 1;
++ mpg123_rcc_recode_latin_string(&tag[ALBUM]);
+ }
+ }
+ if(!tag[COMMENT].fill)
+@@ -80,6 +87,7 @@
+ strncpy(tag[COMMENT].p,v1->comment,30);
+ tag[COMMENT].p[30] = 0;
+ tag[COMMENT].fill = strlen(tag[COMMENT].p) + 1;
++ mpg123_rcc_recode_latin_string(&tag[COMMENT]);
+ }
+ }
+ if(!tag[YEAR].fill)
+diff -dPNur mpg123-1.7.3/src/mpg123.c mpg123-1.7.3-rusxmms/src/mpg123.c
+--- mpg123-1.7.3/src/mpg123.c 2009-04-27 09:02:12.000000000 +0200
++++ mpg123-1.7.3-rusxmms/src/mpg123.c 2009-06-14 00:35:14.000000000 +0200
+@@ -10,6 +10,7 @@
+ #include "mpg123app.h"
+ #include "mpg123.h"
+ #include "local.h"
++#include "rccpatch.h"
+
+ #ifdef HAVE_SYS_WAIT_H
+ #include <sys/wait.h>
+@@ -893,6 +894,8 @@
+ if(param.term_ctrl)
+ term_init();
+ #endif
++
++ mpg123_rcc_init();
+ while ((fname = get_next_file()))
+ {
+ char *dirname, *filename;
+@@ -1038,6 +1041,8 @@
+ #endif
+ }
+ } /* end of loop over input files */
++ mpg123_rcc_free();
++
+ /* Ensure we played everything. */
+ if(param.smooth && param.usebuffer)
+ {
diff --git a/media-sound/mpg123/files/mpg123-ds-rcc65.patch b/media-sound/mpg123/files/mpg123-ds-rcc65.patch
new file mode 100644
index 0000000..41a4d33
--- /dev/null
+++ b/media-sound/mpg123/files/mpg123-ds-rcc65.patch
@@ -0,0 +1,240 @@
+diff -dPNur mpg123-0.65/configure.ac mpg123-0.65-new/configure.ac
+--- mpg123-0.65/configure.ac 2007-02-07 10:24:33.000000000 +0100
++++ mpg123-0.65-new/configure.ac 2007-04-15 13:36:52.000000000 +0200
+@@ -137,6 +137,21 @@
+ AC_CHECK_LIB([m], [sqrt])
+ AC_CHECK_LIB([mx], [powf])
+
++# LibRCC
++AC_CHECK_LIB(rcc, rccInit,[
++ AC_CHECK_HEADERS(librcc.h,[
++ LIBRCC_LIBS="-lrcc"
++ LIBRCC_INCLUDES="-DHAVE_LIBRCC"
++ ],[
++ LIBRCC_LIBS=""
++ LIBRCC_INCLUDES=""
++])],[
++ LIBRCC_LIBS=""
++ LIBRCC_INCLUDES=""
++])
++AC_SUBST(LIBRCC_LIBS)
++AC_SUBST(LIBRCC_INCLUDES)
++
+ # Check for JACK
+ PKG_CHECK_MODULES(JACK, jack, HAVE_JACK=yes, HAVE_JACK=no)
+
+diff -dPNur mpg123-0.65/src/id3.c mpg123-0.65-new/src/id3.c
+--- mpg123-0.65/src/id3.c 2007-02-07 10:24:33.000000000 +0100
++++ mpg123-0.65-new/src/id3.c 2007-04-15 13:26:06.000000000 +0200
+@@ -6,6 +6,7 @@
+ #include "stringbuf.h"
+ #include "genre.h"
+ #include "id3.h"
++#include "rccpatch.h"
+
+ struct taginfo
+ {
+@@ -499,6 +500,8 @@
+ void print_id3_tag(unsigned char *id3v1buf)
+ {
+ char genre_from_v1 = 0;
++ char *ctitle, *cartist, *calbum, *ccomment;
++
+ if(!(id3.version || id3v1buf)) return;
+ if(id3v1buf != NULL)
+ {
+@@ -688,17 +691,26 @@
+ free_stringbuf(&tmp);
+ }
+
++ if (id3.title.fill) ctitle = rccPatchRecode(id3.title.p);
++ else ctitle = NULL;
++ if (id3.artist.fill) cartist = rccPatchRecode(id3.artist.p);
++ else cartist = NULL;
++ if (id3.album.fill) calbum = rccPatchRecode(id3.album.p);
++ else calbum = NULL;
++ if (id3.comment.fill) ccomment = rccPatchRecode(id3.comment.p);
++ else ccomment = NULL;
++
+ if(param.long_id3)
+ {
+ fprintf(stderr,"\n");
+ /* print id3v2 */
+ /* dammed, I use pointers as bool again! It's so convenient... */
+- fprintf(stderr,"\tTitle: %s\n", id3.title.fill ? id3.title.p : "");
+- fprintf(stderr,"\tArtist: %s\n", id3.artist.fill ? id3.artist.p : "");
+- fprintf(stderr,"\tAlbum: %s\n", id3.album.fill ? id3.album.p : "");
++ fprintf(stderr,"\tTitle: %s\n", ctitle?ctitle:(id3.title.fill ? id3.title.p : ""));
++ fprintf(stderr,"\tArtist: %s\n", cartist?cartist:(id3.artist.fill ? id3.artist.p : ""));
++ fprintf(stderr,"\tAlbum: %s\n", calbum?calbum:(id3.album.fill ? id3.album.p : ""));
+ fprintf(stderr,"\tYear: %s\n", id3.year.fill ? id3.year.p : "");
+ fprintf(stderr,"\tGenre: %s\n", id3.genre.fill ? id3.genre.p : "");
+- fprintf(stderr,"\tComment: %s\n", id3.comment.fill ? id3.comment.p : "");
++ fprintf(stderr,"\tComment: %s\n", ccomment?ccomment:(id3.comment.fill ? id3.comment.p : ""));
+ fprintf(stderr,"\n");
+ }
+ else
+@@ -708,23 +720,23 @@
+ /* one _could_ circumvent the strlen calls... */
+ if(id3.title.fill && id3.artist.fill && strlen(id3.title.p) <= 30 && strlen(id3.title.p) <= 30)
+ {
+- fprintf(stderr,"Title: %-30s Artist: %s\n",id3.title.p,id3.artist.p);
++ fprintf(stderr,"Title: %-30s Artist: %s\n",ctitle?ctitle:id3.title.p,cartist?cartist:id3.artist.p);
+ }
+ else
+ {
+- if(id3.title.fill) fprintf(stderr,"Title: %s\n", id3.title.p);
+- if(id3.artist.fill) fprintf(stderr,"Artist: %s\n", id3.artist.p);
++ if(id3.title.fill) fprintf(stderr,"Title: %s\n", ctitle?ctitle:id3.title.p);
++ if(id3.artist.fill) fprintf(stderr,"Artist: %s\n", cartist?cartist:id3.artist.p);
+ }
+ if (id3.comment.fill && id3.album.fill && strlen(id3.comment.p) <= 30 && strlen(id3.album.p) <= 30)
+ {
+- fprintf(stderr,"Comment: %-30s Album: %s\n",id3.comment.p,id3.album.p);
++ fprintf(stderr,"Comment: %-30s Album: %s\n",ccomment?ccomment:id3.comment.p,calbum?calbum:id3.album.p);
+ }
+ else
+ {
+ if (id3.comment.fill)
+- fprintf(stderr,"Comment: %s\n", id3.comment.p);
++ fprintf(stderr,"Comment: %s\n", ccomment?ccomment:id3.comment.p);
+ if (id3.album.fill)
+- fprintf(stderr,"Album: %s\n", id3.album.p);
++ fprintf(stderr,"Album: %s\n", calbum?calbum:id3.album.p);
+ }
+ if (id3.year.fill && id3.genre.fill && strlen(id3.year.p) <= 30 && strlen(id3.genre.p) <= 30)
+ {
+@@ -738,6 +750,11 @@
+ fprintf(stderr,"Genre: %s\n", id3.genre.p);
+ }
+ }
++
++ if (ctitle) free(ctitle);
++ if (cartist) free(cartist);
++ if (calbum) free(calbum);
++ if (ccomment) free(ccomment);
+ }
+
+ /*
+diff -dPNur mpg123-0.65/src/Makefile.am mpg123-0.65-new/src/Makefile.am
+--- mpg123-0.65/src/Makefile.am 2007-02-07 10:24:33.000000000 +0100
++++ mpg123-0.65-new/src/Makefile.am 2007-04-15 13:38:44.000000000 +0200
+@@ -4,8 +4,8 @@
+ ## see COPYING and AUTHORS files in distribution or http://mpg123.de
+ ## initially written by Nicholas J. Humfrey
+
+-AM_CFLAGS = @AUDIO_CFLAGS@
+-AM_LDFLAGS = @AUDIO_LIBS@
++AM_CFLAGS = @AUDIO_CFLAGS@ @LIBRCC_INCLUDES@
++AM_LDFLAGS = @AUDIO_LIBS@ @LIBRCC_LIBS@
+ mpg123_LDADD = @AUDIO_OBJ@ @CPU_TYPE_LIB@
+ mpg123_DEPENDENCIES = @AUDIO_OBJ@ @CPU_TYPE_LIB@
+
+@@ -14,6 +14,8 @@
+
+ bin_PROGRAMS = mpg123
+ mpg123_SOURCES = \
++ rccpatch.c \
++ rccpatch.h \
+ audio.c \
+ audio.h \
+ buffer.c \
+diff -dPNur mpg123-0.65/src/mpg123.c mpg123-0.65-new/src/mpg123.c
+--- mpg123-0.65/src/mpg123.c 2007-02-07 10:24:33.000000000 +0100
++++ mpg123-0.65-new/src/mpg123.c 2007-04-15 13:30:42.000000000 +0200
+@@ -35,6 +35,7 @@
+ #include "layer3.h"
+ #endif
+ #include "playlist.h"
++#include "rccpatch.h"
+ #include "id3.h"
+ #include "icy.h"
+
+@@ -814,15 +815,18 @@
+
+ if(param.remote) {
+ int ret;
++ rccPatchInit();
+ init_id3();
+ init_icy();
+ ret = control_generic(&fr);
+ clear_icy();
+ exit_id3();
++ rccPatchFree();
+ safe_exit(ret);
+ }
+ #endif
+
++ rccPatchInit();
+ init_icy();
+ init_id3(); /* prepare id3 memory */
+ while ((fname = get_next_file())) {
+@@ -851,7 +855,7 @@
+ }
+ }
+ #endif
+-
++
+ }
+
+ #if !defined(WIN32) && !defined(GENERIC)
+@@ -1031,6 +1035,7 @@
+ } /* end of loop over input files */
+ clear_icy();
+ exit_id3(); /* free id3 memory */
++ rccPatchFree();
+ #ifndef NOXFERMEM
+ if (param.usebuffer) {
+ buffer_end();
+diff -dPNur mpg123-0.65/src/rccpatch.c mpg123-0.65-new/src/rccpatch.c
+--- mpg123-0.65/src/rccpatch.c 1970-01-01 01:00:00.000000000 +0100
++++ mpg123-0.65-new/src/rccpatch.c 2007-04-15 13:13:09.000000000 +0200
+@@ -0,0 +1,40 @@
++#include <librcc.h>
++
++#define ID3_CLASS 0
++#define OUT_CLASS 1
++static rcc_class classes[] = {
++ { "id3", RCC_CLASS_STANDARD, NULL, NULL, "ID3 Encoding", 0 },
++ { "out", RCC_CLASS_STANDARD, NULL, NULL, "Output Encoding", 0 },
++ { NULL }
++};
++
++static int rcc_initialized = 0;
++
++void rccPatchFree() {
++ if (rcc_initialized) {
++ rccFree();
++ rcc_initialized = 0;
++ }
++}
++
++void rccPatchInit() {
++ if (rcc_initialized) return;
++ rccInit();
++ rccInitDefaultContext(NULL, 0, 0, classes, 0);
++ rccLoad(NULL, "xmms");
++ rccInitDb4(NULL, NULL, 0);
++ rcc_initialized = 1;
++}
++
++static void rccPatchTryInit() {
++ if (!rcc_initialized) {
++ rccPatchInit();
++ if (rcc_initialized) atexit(rccPatchFree);
++ }
++}
++
++char *rccPatchRecode(const char *str) {
++ char *res;
++ rccPatchTryInit();
++ return rccRecode(NULL, ID3_CLASS, OUT_CLASS, str);
++}
+diff -dPNur mpg123-0.65/src/rccpatch.h mpg123-0.65-new/src/rccpatch.h
+--- mpg123-0.65/src/rccpatch.h 1970-01-01 01:00:00.000000000 +0100
++++ mpg123-0.65-new/src/rccpatch.h 2007-04-15 13:13:09.000000000 +0200
+@@ -0,0 +1,4 @@
++void rccPatchFree();
++void rccPatchInit();
++char *rccPatchRecode(const char *str);
++
diff --git a/media-sound/mpg123/files/mpg123-osx.diff b/media-sound/mpg123/files/mpg123-osx.diff
new file mode 100644
index 0000000..a58fffd
--- /dev/null
+++ b/media-sound/mpg123/files/mpg123-osx.diff
@@ -0,0 +1,394 @@
+diff -Naur mpg123-orig/Makefile mpg123/Makefile
+--- mpg123-orig/Makefile Sun Apr 10 13:35:56 2005
++++ mpg123/Makefile Sun Apr 10 13:40:03 2005
+@@ -54,6 +54,7 @@
+ @echo "make netbsd NetBSD"
+ @echo "make openbsd OpenBSD"
+ @echo "make mint MiNT on Atari"
++ @echo "make macos MacOSX
+ @echo "make generic try this one if your system isn't listed above"
+ @echo ""
+ @echo "Please read the file INSTALL for additional information."
+@@ -149,6 +150,16 @@
+ @echo "Please read the file INSTALL for additional information."
+ @echo ""
+
++macos-help:
++ @echo ""
++ @echo "There are several Mac OS X flavours. Choose one:"
++ @echo ""
++ @echo "make macos"
++ @echo "make macos-esd"
++ @echo ""
++ @echo "Please read the file INSTALL for additional information."
++ @echo ""
++
+ linux-devel:
+ $(MAKE) OBJECTS='decode_i386.o dct64_i386.o audio_oss.o' \
+ LDFLAGS= \
+@@ -759,6 +770,24 @@
+ -DI386_ASSEM -DREAL_IS_FLOAT -DUSE_MMAP -DOSS \
+ -DDONT_CATCH_SIGNALS -DNAS' \
+ mpg123-make
++
++macos:
++ $(MAKE) CC=cc LDFLAGS='$(LDFLAGS)' AUDIO_LIB='-framework CoreAudio' \
++ OBJECTS='decode.o dct64.o audio_macosx.o term.o' \
++ CFLAGS='$(CFLAGS) -DINET6 -DTERM_CONTROL -DMAC_OS_X -Wall -O2 -DPPC_ENDIAN' \
++ mpg123-make
++
++macos-generic:
++ $(MAKE) CC=cc LDFLAGS='$(LDFLAGS)' AUDIO_LIB='-framework CoreAudio' \
++ OBJECTS='decode.o dct64.o audio_macosx.o term.o' \
++ CFLAGS='$(CFLAGS) -DINET6 -DTERM_CONTROL -DMAC_OS_X -Wall -O2 -DPPC_ENDIAN' \
++ mpg123-make
++
++macos-esd:
++ $(MAKE) CC=cc LDFLAGS='$(LDFLAGS)' AUDIO_LIB='-lesd -laudiofile' \
++ OBJECTS='decode.o dct64.o audio_esd.o' \
++ CFLAGS='$(CFLAGS) -O -DDARWIN -Wall -O2 -DPPC_ENDIAN -DUSE_ESD' \
++ mpg123-make
+
+ mint:
+ $(MAKE) LDFLAGS= \
+diff -Naur mpg123-orig/audio_macosx.c mpg123/audio_macosx.c
+--- mpg123-orig/audio_macosx.c Wed Dec 31 19:00:00 1969
++++ mpg123/audio_macosx.c Sun Apr 10 13:47:14 2005
+@@ -0,0 +1,337 @@
++/*- This is a 80 chars line, to have pretty formatted comments ---------------*/
++
++/* audio_macosx.c, originally written by Guillaume Outters
++ * to contact the author, please mail to: guillaume.outters@free.fr
++ *
++ * This file is some quick pre-alpha patch to allow me to have some music for my
++ * long working days, and it does it well. But it surely isn't a final version;
++ * as Mac OS X requires at least a G3, I'm not sure it will be useful to
++ * implement downsampling.
++ *
++ * Mac OS X audio works by asking you to fill its buffer, and, to complicate a
++ * bit, you must provide it with floats. In order not to patch too much mpg123,
++ * we'll accept signed short (mpg123 "approved" format) and transform them into
++ * floats as soon as received. Let's say this way calculations are faster.
++ *
++ * As we don't have some /dev/audio device with blocking write, we'll have to
++ * stop mpg123 before it does too much work, while we are waiting our dump proc
++ * to be called. I wanted to use semaphores, but they still need an
++ * implementation from Apple before I can do anything. So we'll block using a
++ * sleep and wake up on SIGUSR2.
++ * Version 0.2: now I use named semaphores (which are implemented AND work).
++ * Preprocessor flag MOSX_USES_SEM (defined at the beginning of this file)
++ * enables this behaviour.
++ *
++ * In order always to have a ready buffer to be dumped when the routine gets
++ * called, we have a "buffer loop" of NUMBER_BUFFERS buffers. mpg123 fills it
++ * on one extremity ('to'), playProc reads it on another point ('from'). 'to'
++ * blocks when it arrives on 'from' (having filled the whole circle of buffers)
++ * and 'from' blocks when no data is available. As soon as it has emptied a
++ * buffer, if mpg123 is sleeping, it awakes it quite brutaly (SIGUSR2) to tell
++ * it to fill the buffer. */
++
++#ifndef MOSX_USES_SEM
++#define MOSX_USES_SEM 1 /* Semaphores or sleep()/kill()? I would say semaphores, but this is just my advice, after all */
++#endif
++#ifndef MOSX_SEM_V2
++#define MOSX_SEM_V2 1
++#endif
++
++#include "mpg123.h"
++#include <CoreAudio/AudioHardware.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <errno.h>
++#if MOSX_USES_SEM
++#include <semaphore.h>
++#endif
++
++struct aBuffer
++{
++ float * buffer;
++ long size;
++
++ float * ptr; /* Where in the buffer are we? */
++ long remaining;
++
++ struct aBuffer * next;
++};
++typedef struct aBuffer aBuffer;
++
++struct anEnv
++{
++ long size;
++ short * debut;
++ short * ptr;
++ AudioDeviceID device;
++ char play;
++
++ /* Intermediate buffers */
++
++ #if MOSX_USES_SEM
++ sem_t * semaphore;
++ #else
++ char wait; /* mpg123 is waiting (due to the semaphore) to show the world its power; let's free him! */
++ pid_t pid;
++ #endif
++ aBuffer * from; /* Current buffers */
++ aBuffer * to;
++};
++
++static struct anEnv env;
++
++#define ENV ((struct anEnv *)inClientData)
++#define NUMBER_BUFFERS 16 /* Tried with 3 buffers, but then any little window move is sufficient to stop the sound. Here we have 1.5 seconds music buffered */
++
++void destroyBuffers()
++{
++ aBuffer * ptr;
++ aBuffer * ptr2;
++
++ ptr = env.to->next;
++ env.to->next = NULL;
++ while(ptr)
++ {
++ ptr2 = ptr->next;
++ if(ptr->buffer) free(ptr->buffer);
++ free(ptr);
++ ptr = ptr2;
++ }
++}
++
++void initBuffers()
++{
++ long m;
++ aBuffer ** ptrptr;
++
++ ptrptr = &env.to;
++ for(m = 0; m < NUMBER_BUFFERS; m++)
++ {
++ *ptrptr = malloc(sizeof(aBuffer));
++ (*ptrptr)->size = 0;
++ (*ptrptr)->remaining = 0;
++ (*ptrptr)->buffer = NULL;
++ ptrptr = &(*ptrptr)->next;
++ #if MOSX_USES_SEM
++ sem_post(env.semaphore); /* This buffer is ready for filling (of course, it is empty!) */
++ #endif
++ }
++ *ptrptr = env.from = env.to;
++}
++
++int fillBuffer(aBuffer * b, short * source, long size)
++{
++ float * dest;
++
++ if(b->remaining) /* Non empty buffer, must still be playing */
++ return(-1);
++ if(b->size != size) /* Hey! What's that? Coudn't this buffer size be fixed once (well, perhaps we just didn't allocate it yet) */
++ {
++ if(b->buffer) free(b->buffer);
++ b->buffer = malloc(size * sizeof(float));
++ b->size = size;
++ }
++
++ dest = b->buffer;
++ while(size--)
++ //*dest++ = ((*source++) + 32768) / 65536.0;
++ *dest++ = (*source++) / 32768.0;
++
++ b->ptr = b->buffer;
++ b->remaining = b->size; /* Do this at last; we shouldn't show the buffer is full before it is effectively */
++
++ #ifdef DEBUG_MOSX
++ printf("."); fflush(stdout);
++ #endif
++
++ return(0);
++}
++
++OSStatus playProc(AudioDeviceID inDevice, const AudioTimeStamp * inNow, const AudioBufferList * inInputData, const AudioTimeStamp * inInputTime, AudioBufferList * outOutputData, const AudioTimeStamp * inOutputTime, void * inClientData)
++{
++ long m, n, o;
++ float * dest;
++
++ for(o = 0; o < outOutputData->mNumberBuffers; o++)
++ {
++ m = outOutputData->mBuffers[o].mDataByteSize / sizeof(float); /* What we have to fill */
++ dest = outOutputData->mBuffers[o].mData;
++
++ while(m > 0)
++ {
++ if( (n = ENV->from->remaining) <= 0 ) /* No more bytes in the current read buffer! */
++ {
++ while( (n = ENV->from->remaining) <= 0)
++ usleep(2000); /* Let's wait a bit for the results... */
++ }
++
++ /* We dump what we can */
++
++ if(n > m) n = m; /* In fact, just the necessary should be sufficient (I think) */
++
++ memcpy(dest, ENV->from->ptr, n * sizeof(float));
++
++ /* Let's remember all done work */
++
++ m -= n;
++ ENV->from->ptr += n;
++ if( (ENV->from->remaining -= n) <= 0) /* ... and tell mpg123 there's a buffer to fill */
++ {
++ #if MOSX_USES_SEM
++ sem_post(ENV->semaphore);
++ #else
++ if(ENV->wait)
++ {
++ kill(ENV->pid, SIGUSR2);
++ ENV->wait = 0;
++ }
++ #endif
++ ENV->from = ENV->from->next;
++ }
++ }
++ }
++
++ return (0);
++}
++
++#if ! MOSX_USES_SEM
++void start(int n)
++{
++ signal(SIGUSR2, start);
++}
++#endif
++
++int audio_open(struct audio_info_struct *ai)
++{
++ long size;
++ AudioStreamBasicDescription format;
++ #if MOSX_USES_SEM
++ char s[10];
++ long m;
++ #endif
++ /*float vol;
++ OSStatus e;*/
++
++ /* Where did that default audio output go? */
++
++ size = sizeof(env.device);
++ if(AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &env.device)) return(-1);
++
++ /* Hmmm, let's choose PCM format */
++
++ size = sizeof(format);
++ if(AudioDeviceGetProperty(env.device, 0, 0, kAudioDevicePropertyStreamFormat, &size, &format)) return(-1);
++ if(format.mFormatID != kAudioFormatLinearPCM) return(-1);
++
++ /* Let's test volume, which doesn't seem to work (but this is only an alpha, remember?) */
++
++ /*vol = 0.5;
++ size = sizeof(vol);
++ if(e = AudioDeviceSetProperty(env.device, NULL, 0, 0, 'volm', size, &vol)) { printf("Didn't your mother ever tell you not to hear music so loudly?\n"); return(-1); } */
++
++ /* Let's init our environment */
++
++ env.size = 0;
++ env.debut = NULL;
++ env.ptr = NULL;
++ env.play = 0;
++
++ #if MOSX_USES_SEM
++ strcpy(s, "/mpg123-0000");
++ do
++ {
++ for(m = 10;; m--)
++ if( (s[m]++) <= '9')
++ break;
++ else
++ s[m] = '0';
++ } while( (env.semaphore = sem_open(s, O_CREAT | O_EXCL, 0644, 0)) == (sem_t *)SEM_FAILED);
++ #else
++ env.pid = getpid();
++ env.wait = 0;
++ signal(SIGUSR2, start);
++ #endif
++
++ initBuffers();
++
++ /* And prepare audio launching */
++
++ if(AudioDeviceAddIOProc(env.device, playProc, &env)) return(-1);
++
++ return(0);
++}
++
++int audio_reset_parameters(struct audio_info_struct *ai)
++{
++ return 0;
++}
++
++int audio_rate_best_match(struct audio_info_struct *ai)
++{
++ return 0;
++}
++
++int audio_set_rate(struct audio_info_struct *ai)
++{
++ return 0;
++}
++
++int audio_set_channels(struct audio_info_struct *ai)
++{
++ return 0;
++}
++
++int audio_set_format(struct audio_info_struct *ai)
++{
++ return 0;
++}
++
++int audio_get_formats(struct audio_info_struct *ai)
++{
++ return AUDIO_FORMAT_SIGNED_16;
++}
++
++int audio_play_samples(struct audio_info_struct *ai,unsigned char *buf,int len)
++{
++ /* We have to calm down mpg123, else he wouldn't hesitate to drop us another buffer (which would be the same, in fact) */
++
++ #if MOSX_USES_SEM && MOSX_SEM_V2 /* Suddenly, I have some kind of doubt: HOW COULD IT WORK??? */
++ while(sem_wait(env.semaphore)){} /* We just have to wait a buffer fill request */
++ fillBuffer(env.to, (short *)buf, len / sizeof(short));
++ #else
++ while(fillBuffer(env.to, (short *)buf, len / sizeof(short)) < 0) /* While the next buffer to write is not empty, we wait a bit... */
++ {
++ #ifdef DEBUG_MOSX
++ printf("|"); fflush(stdout);
++ #endif
++ #if MOSX_USES_SEM
++ sem_wait(env.semaphore); /* This is a bug. I should wait for the semaphore once per empty buffer (and not each time fillBuffers() returns -1). See MOSX_SEM_V2; this was a too quickly modified part when I implemented MOSX_USES_SEM. */
++ #else
++ env.wait = 1;
++ sleep(3600); /* This should be sufficient, shouldn't it? */
++ #endif
++ }
++ #endif
++ env.to = env.to->next;
++
++ /* And we lauch action if not already done */
++
++ if(!env.play)
++ {
++ if(AudioDeviceStart(env.device, playProc)) return(-1);
++ env.play = 1;
++ }
++
++ return len;
++}
++
++int audio_close(struct audio_info_struct *ai)
++{
++ AudioDeviceStop(env.device, playProc); /* No matter the error code, we want to close it (by brute force if necessary) */
++ AudioDeviceRemoveIOProc(env.device, playProc);
++ destroyBuffers();
++ #if MOSX_USES_SEM
++ sem_close(env.semaphore);
++ #endif
++ return 0;
++}