# HG changeset patch # User Matti Hamalainen # Date 1103641503 0 # Node ID 291715a519e20db451362f53124bdb49f1c5c4e6 # Parent f436e16fa6d9bd1f731cd3e98ef5737dfed2eeab Compile-time setting to enable/disable use of dynamically allocated buffers. diff -r f436e16fa6d9 -r 291715a519e2 src/xmms-sid.c --- a/src/xmms-sid.c Tue Dec 21 15:04:04 2004 +0000 +++ b/src/xmms-sid.c Tue Dec 21 15:05:03 2004 +0000 @@ -254,7 +254,11 @@ gboolean audioOpen = FALSE, doPlay = FALSE; guint audioGot; gint songLength; - gchar audioBuffer[XS_BUFSIZE]; +#ifdef XS_BUF_DYNAMIC + gchar *audioBuffer = NULL; +#else + gchar audioBuffer[XS_AUDIOBUF_SIZE]; +#endif /* Initialize */ XSDEBUG("entering player thread\n"); @@ -263,6 +267,16 @@ myTune = xs_status.tuneInfo; XS_MUTEX_UNLOCK(xs_status); + /* Allocate audio buffer */ +#ifdef XS_BUF_DYNAMIC + audioBuffer = (gchar *) g_malloc(XS_AUDIOBUF_SIZE); + if (audioBuffer == NULL) + { + XSERR("Couldn't allocate memory for audio data buffer!\n"); + goto xs_err_exit; + } +#endif + /* * Main player loop: while not stopped, loop here - play subtunes */ @@ -328,7 +342,7 @@ while (xs_status.isPlaying && myStatus.isPlaying && (xs_status.currSong == myStatus.currSong)) { /* Render audio data */ - audioGot = myStatus.sidPlayer->plrFillBuffer(&myStatus, audioBuffer, XS_BUFSIZE); + audioGot = myStatus.sidPlayer->plrFillBuffer(&myStatus, audioBuffer, XS_AUDIOBUF_SIZE); /* I <3 visualice/haujobb */ xs_plugin_ip.add_vis_pcm( @@ -389,6 +403,10 @@ xs_plugin_ip.output->close_audio(); } +#ifdef XS_BUF_DYNAMIC + g_free(audioBuffer); +#endif + /* Exit the playing thread */ XSDEBUG("exiting thread, bye.\n"); @@ -458,7 +476,6 @@ XSDEBUG("STOP_REQ\n"); xs_subctrl_close(); - xs_fileinfo_update(); XS_MUTEX_LOCK(xs_status); if (xs_status.isPlaying) @@ -472,6 +489,8 @@ XS_MUTEX_UNLOCK(xs_status); } + xs_fileinfo_update(); + /* Free tune information */ xs_status.sidPlayer->plrDeleteSID(&xs_status); xs_tuneinfo_free(xs_status.tuneInfo); diff -r f436e16fa6d9 -r 291715a519e2 src/xmms-sid.h --- a/src/xmms-sid.h Tue Dec 21 15:04:04 2004 +0000 +++ b/src/xmms-sid.h Tue Dec 21 15:05:03 2004 +0000 @@ -40,27 +40,39 @@ extern "C" { #endif -/* Some defines +/* + * Some constants and defines */ -#define DEBUG +/* Define for spurious debugging messages */ +#undef DEBUG -#undef HAVE_HARDSID_BUILDER /* HardSID-support is not working and is untested */ +/* Define to enable non-portable thread and mutex debugging code + * (Works probably with Linux glibc only) */ +#undef XS_MUTEX_DEBUG -#define XS_BUFSIZE (4096) /* Size for some buffers */ +/* HardSID-support is not working and is untested, + * thus we disable it here. */ +#undef HAVE_HARDSID_BUILDER + +/* Size for some small buffers (always static variables) */ +#define XS_BUF_SIZE (1024) -#define XS_SIDBUF_SIZE (80*1024) /* Size of data buffer used for SID-tune - MD5 hash calculation. If this is too small, - the computed hash will be incorrect. - Largest SID files I've seen are ~70kB. - */ +/* If defined, dynamically allocated temp. buffers are used. + * Static (#undef) are probably faster than allocating/deallocating + * from heap, but fails on systems with limited stack space. */ +#define XS_BUF_DYNAMIC + +/* Size of audio buffer */ +#define XS_AUDIOBUF_SIZE (16*1024) -#define XS_SIDBUF_DYNAMIC /* If not defined, static buffer is used. - Probably faster than allocating/deallocating - from heap, but fails on systems with limited - stack space. - */ +/* Size of data buffer used for SID-tune MD5 hash calculation. + * If this is too small, the computed hash will be incorrect. + * Largest SID files I've seen are ~70kB. */ +#define XS_SIDBUF_SIZE (80*1024) -#define XS_STIL_MAXENTRY (128) /* Max number of sub-songs in STIL/SLDB node */ + + +#define XS_STIL_MAXENTRY (128) /* Max number of sub-songs in STIL/SLDB node */ #define XS_CONFIG_IDENT "XMMS-SID" /* Configuration file identifier */ @@ -74,14 +86,17 @@ * easily change from pthreads to glib threads, etc, if necessary. */ #define XS_MPP(M) M ## _mutex -#ifdef DEBUG -#define XS_MUTEX(M) pthread_mutex_t XS_MPP(M) = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; int M ## _qq; -#else -#define XS_MUTEX(M) pthread_mutex_t XS_MPP(M) = PTHREAD_MUTEX_INITIALIZER -#endif -#define XS_MUTEX_H(M) extern pthread_mutex_t XS_MPP(M); extern int M ## _qq; +#if XS_MUTEX_DEBUG +#define XS_MUTEX(M) pthread_mutex_t XS_MPP(M) = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; int M ## _qq; +#define XS_MUTEX_H(M) extern pthread_mutex_t XS_MPP(M); extern int M ## _qq; #define XS_MUTEX_LOCK(M) { M ## _qq = pthread_mutex_lock(&XS_MPP(M)); if (M ## _qq) XSDEBUG("XS_MUTEX_LOCK(" #M ") == %i\n", M ## _qq); } #define XS_MUTEX_UNLOCK(M) { M ## _qq = pthread_mutex_unlock(&XS_MPP(M)); if (M ## _qq) XSDEBUG("XS_MUTEX_UNLOCK(" #M ") == %i\n", M ## _qq); } +#else +#define XS_MUTEX(M) pthread_mutex_t XS_MPP(M) = PTHREAD_MUTEX_INITIALIZER +#define XS_MUTEX_H(M) extern pthread_mutex_t XS_MPP(M); +#define XS_MUTEX_LOCK(M) pthread_mutex_lock(&XS_MPP(M)) +#define XS_MUTEX_UNLOCK(M) pthread_mutex_unlock(&XS_MPP(M)) +#endif /* Shorthands for linked lists */ diff -r f436e16fa6d9 -r 291715a519e2 src/xs_length.c --- a/src/xs_length.c Tue Dec 21 15:04:04 2004 +0000 +++ b/src/xs_length.c Tue Dec 21 15:05:03 2004 +0000 @@ -116,7 +116,7 @@ gint xs_sldb_read(t_xs_sldb *db, gchar *dbFilename) { FILE *inFile; - gchar inLine[XS_BUFSIZE]; + gchar inLine[XS_BUF_SIZE]; guint lineNum, linePos; gboolean iOK; t_xs_sldb_node *tmpNode; @@ -134,7 +134,8 @@ while (!feof(inFile)) { - fgets(inLine, sizeof(inLine), inFile); + fgets(inLine, XS_BUF_SIZE, inFile); + inLine[XS_BUF_SIZE-1] = 0; lineNum++; /* Check if it is datafield */ @@ -424,7 +425,7 @@ t_xs_md5state inState; t_xs_psidv1_header psidH; t_xs_psidv2_header psidH2; -#ifdef XS_SIDBUF_DYNAMIC +#ifdef XS_BUF_DYNAMIC guint8 *songData; #else guint8 songData[XS_SIDBUF_SIZE]; @@ -468,7 +469,7 @@ psidH2.reserved = xs_rd_be16(inFile); } -#ifdef XS_SIDBUF_DYNAMIC +#ifdef XS_BUF_DYNAMIC /* Allocate buffer */ songData = (guint8 *) g_malloc(XS_SIDBUF_SIZE * sizeof(guint8)); if (!songData) @@ -494,7 +495,7 @@ } -#ifdef XS_SIDBUF_DYNAMIC +#ifdef XS_BUF_DYNAMIC /* Free buffer */ g_free(songData); #endif