# HG changeset patch # User William Pitcock # Date 1194277373 21600 # Node ID a0efcdd66861512cb0aa2ad2f9b32b394437d930 # Parent 2f7eff0bc6eb7deded8338c8806e04f647717096# Parent 8a5231ff9c4f59c523311a3585e089c75bafb3eb Automated merge with ssh://hg.atheme.org//hg/audacious-plugins diff -r 2f7eff0bc6eb -r a0efcdd66861 src/cdaudio-ng/cdaudio-ng.c --- a/src/cdaudio-ng/cdaudio-ng.c Mon Nov 05 09:41:56 2007 -0600 +++ b/src/cdaudio-ng/cdaudio-ng.c Mon Nov 05 09:42:53 2007 -0600 @@ -17,7 +17,6 @@ */ /* TODO (added by ccr) - * - DAE seems to be always used, does analog mode work at all? * - maybe make CDDB lib optional? * - use_cddb/use_cdtext don't seem to be checked in all necessary places. why? */ @@ -405,20 +404,28 @@ pcddb_disc = NULL; } else { - CDDEBUG("discid = %X, category = \"%s\"\n", cddb_disc_get_discid(pcddb_disc), cddb_disc_get_category_str(pcddb_disc)); - - cddb_read(pcddb_conn, pcddb_disc); - if (cddb_errno(pcddb_conn) != CDDB_ERR_OK) { - fprintf(stderr, "cdaudio-ng: failed to read the cddb info: %s\n", cddb_error_str(cddb_errno(pcddb_conn))); + if (!strcmp(cddb_disc_get_category_str(pcddb_disc), "invalid")) { + CDDEBUG("no cddb info available for this disc\n"); + cddb_disc_destroy(pcddb_disc); pcddb_disc = NULL; } else { - CDDEBUG("we have got the cddb info\n"); - cdaudio_set_strinfo(&trackinfo[0], - cddb_disc_get_artist(pcddb_disc), - cddb_disc_get_title(pcddb_disc), - cddb_disc_get_genre(pcddb_disc)); + CDDEBUG("discid = %X, category = \"%s\"\n", cddb_disc_get_discid(pcddb_disc), cddb_disc_get_category_str(pcddb_disc)); + + cddb_read(pcddb_conn, pcddb_disc); + if (cddb_errno(pcddb_conn) != CDDB_ERR_OK) { + cdaudio_error("failed to read the cddb info: %s\n", cddb_error_str(cddb_errno(pcddb_conn))); + cddb_disc_destroy(pcddb_disc); + pcddb_disc = NULL; + } + else { + CDDEBUG("we have got the cddb info\n"); + cdaudio_set_strinfo(&trackinfo[0], + cddb_disc_get_artist(pcddb_disc), + cddb_disc_get_title(pcddb_disc), + cddb_disc_get_genre(pcddb_disc)); + } } } } @@ -725,7 +732,7 @@ else { cdio_audio_volume_t volume = {{l, r, 0, 0}}; if (cdio_audio_set_volume(pcdio, &volume) != DRIVER_OP_SUCCESS) { - fprintf(stderr, "cdaudio-ng: failed to set analog cd volume\n"); + cdaudio_error("cdaudio-ng: failed to set analog cd volume\n"); cleanup_on_error(); return FALSE; } diff -r 2f7eff0bc6eb -r a0efcdd66861 src/neon/Makefile --- a/src/neon/Makefile Mon Nov 05 09:41:56 2007 -0600 +++ b/src/neon/Makefile Mon Nov 05 09:42:53 2007 -0600 @@ -9,5 +9,5 @@ plugindir := ${plugindir}/${TRANSPORT_PLUGIN_DIR} CFLAGS += ${PLUGIN_CFLAGS} -CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} ${ARCH_DEFINES} ${XML_CPPFLAGS} ${NEON_CFLAGS} -I../../intl -I../.. +CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} ${ARCH_DEFINES} ${XML_CPPFLAGS} ${NEON_CFLAGS} -I../../intl -I../.. -D_RB_USE_GLIB LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${XML_LIBS} ${NEON_LIBS} diff -r 2f7eff0bc6eb -r a0efcdd66861 src/neon/neon.c --- a/src/neon/neon.c Mon Nov 05 09:41:56 2007 -0600 +++ b/src/neon/neon.c Mon Nov 05 09:42:53 2007 -0600 @@ -90,7 +90,13 @@ _LEAVE NULL; } - if (0 != init_rb(&(h->rb), NBUFSIZ)) { + h->reader = NULL; + h->reader_status.mutex = g_mutex_new(); + h->reader_status.cond = g_cond_new(); + h->reader_status.reading = FALSE; + h->reader_status.status = NEON_READER_INIT; + + if (0 != init_rb_with_lock(&(h->rb), NBUFSIZ, h->reader_status.mutex)) { _ERROR("Could not initialize buffer"); free(h); _LEAVE NULL; @@ -111,11 +117,6 @@ h->icy_metadata.stream_title = NULL; h->icy_metadata.stream_url = NULL; h->icy_metadata.stream_contenttype = NULL; - h->reader = NULL; - h->reader_status.mutex = g_mutex_new(); - h->reader_status.cond = g_cond_new(); - h->reader_status.reading = FALSE; - h->reader_status.status = NEON_READER_INIT; h->eof = FALSE; _LEAVE h; @@ -715,12 +716,12 @@ g_mutex_lock(h->reader_status.mutex); while(h->reader_status.reading) { - g_mutex_unlock(h->reader_status.mutex); /* * Hit the network only if we have more than NETBLKSIZ of free buffer */ - if (NETBLKSIZ < free_rb(&h->rb)) { + if (NETBLKSIZ < free_rb_locked(&h->rb)) { + g_mutex_unlock(h->reader_status.mutex); _DEBUG("Filling buffer..."); ret = fill_buffer(h); @@ -756,18 +757,9 @@ * Not enough free space in the buffer. * Sleep until the main thread wakes us up. */ - g_mutex_lock(h->reader_status.mutex); - if (h->reader_status.reading) { - _DEBUG("Reader thread going to sleep"); - g_cond_wait(h->reader_status.cond, h->reader_status.mutex); - _DEBUG("Reader thread woke up"); - } else { - /* - * Main thread has ordered termination of this thread. - * Leave the loop. - */ - break; - } + _DEBUG("Reader thread going to sleep"); + g_cond_wait(h->reader_status.cond, h->reader_status.mutex); + _DEBUG("Reader thread woke up"); } } diff -r 2f7eff0bc6eb -r a0efcdd66861 src/neon/rb.c --- a/src/neon/rb.c Mon Nov 05 09:41:56 2007 -0600 +++ b/src/neon/rb.c Mon Nov 05 09:42:53 2007 -0600 @@ -93,7 +93,7 @@ _ENTER; - pthread_mutex_lock(&rb->lock); + _RB_LOCK(rb->lock); rb->wp = rb->buf; rb->rp = rb->buf; @@ -101,7 +101,7 @@ rb->used = 0; rb->end = rb->buf+(rb->size-1); - pthread_mutex_unlock(&rb->lock); + _RB_UNLOCK(rb->lock); _LEAVE; } @@ -120,9 +120,52 @@ _LEAVE -1; } - if (0 != pthread_mutex_init(&rb->lock, NULL)) { + if (NULL == (rb->buf = malloc(size))) { + _LEAVE -1; + } + rb->size = size; + + #ifdef _RB_USE_GLIB + if (NULL == (rb->lock = g_mutex_new())) { + _LEAVE -1; + } + #else + if (NULL == (rb->lock = malloc(sizeof(pthread_mutex_t)))) { + _LEAVE -1; + } + + if (0 != pthread_mutex_init(rb->lock, NULL)) { + free(rb->lock); _LEAVE -1; } + #endif + rb->_free_lock = 1; + + reset_rb(rb); + + ASSERT_RB(rb); + + _LEAVE 0; +} + +/* + * Initialize a ringbuffer structure (including + * memory allocation. + * The mutex to be used is passed in the function call. + * The mutex must not be held while calling this function. + * + * Return -1 on error + */ +int init_rb_with_lock(struct ringbuf* rb, unsigned int size, rb_mutex_t* lock) { + + _ENTER; + + if (0 == size) { + _LEAVE -1; + } + + rb->lock = lock; + rb->_free_lock = 0; if (NULL == (rb->buf = malloc(size))) { _LEAVE -1; @@ -146,7 +189,7 @@ _ENTER; - pthread_mutex_lock(&rb->lock); + _RB_LOCK(rb->lock); ASSERT_RB(rb); @@ -186,7 +229,7 @@ out: ASSERT_RB(rb); - pthread_mutex_unlock(&rb->lock); + _RB_UNLOCK(rb->lock); _LEAVE ret; } @@ -201,9 +244,9 @@ _ENTER; - pthread_mutex_lock(&rb->lock); + _RB_LOCK(rb->lock); ret = read_rb_locked(rb, buf, size); - pthread_mutex_unlock(&rb->lock); + _RB_UNLOCK(rb->lock); _LEAVE ret; } @@ -228,7 +271,7 @@ if (rb->rp < rb->wp) { /* - Read pointer is behind write pointer, all the data is available in one cunk + Read pointer is behind write pointer, all the data is available in one chunk */ memcpy(buf, rb->rp, size); rb->rp += size; @@ -271,13 +314,24 @@ _ENTER; - pthread_mutex_lock(&rb->lock); - f = rb->free; - pthread_mutex_unlock(&rb->lock); + _RB_LOCK(rb->lock); + f = free_rb_locked(rb); + _RB_UNLOCK(rb->lock); _LEAVE f; } +/* + * Return the amount of free space currently in the rb. + * Assume the rb lock is already being held. + */ +unsigned int free_rb_locked(struct ringbuf* rb) { + + _ENTER; + + _LEAVE rb->free; +} + /* * Return the amount of used space currently in the rb @@ -288,9 +342,9 @@ _ENTER; - pthread_mutex_lock(&rb->lock); + _RB_LOCK(rb->lock); u = rb->used; - pthread_mutex_unlock(&rb->lock); + _RB_UNLOCK(rb->lock); _LEAVE u; } @@ -302,9 +356,15 @@ void destroy_rb(struct ringbuf* rb) { _ENTER; - pthread_mutex_lock(&rb->lock); free(rb->buf); - pthread_mutex_unlock(&rb->lock); + if (rb->_free_lock) { +#ifdef _RB_USE_GLIB + g_mutex_free(rb->lock); +#else + pthread_mutex_destroy(rb->lock); + free(rb->lock); +#endif + } _LEAVE; } diff -r 2f7eff0bc6eb -r a0efcdd66861 src/neon/rb.h --- a/src/neon/rb.h Mon Nov 05 09:41:56 2007 -0600 +++ b/src/neon/rb.h Mon Nov 05 09:42:53 2007 -0600 @@ -17,7 +17,21 @@ #ifndef _RB_H #define _RB_H +#ifdef _RB_USE_GLIB +#include + +typedef GMutex rb_mutex_t; +#define _RB_LOCK(L) g_mutex_lock(L) +#define _RB_UNLOCK(L) g_mutex_unlock(L) + +#else #include + +typedef pthread_mutex_t rb_mutex_t; +#define _RB_LOCK(L) pthread_mutex_lock(L) +#define _RB_UNLOCK(L) pthread_mutex_unlock(L) +#endif + #include #ifdef RB_DEBUG @@ -27,7 +41,8 @@ #endif struct ringbuf { - pthread_mutex_t lock; + rb_mutex_t* lock; + char _free_lock; char* buf; char* end; char* wp; @@ -38,11 +53,13 @@ }; int init_rb(struct ringbuf* rb, unsigned int size); +int init_rb_with_lock(struct ringbuf* rb, unsigned int size, rb_mutex_t* lock); int write_rb(struct ringbuf* rb, void* buf, unsigned int size); int read_rb(struct ringbuf* rb, void* buf, unsigned int size); int read_rb_locked(struct ringbuf* rb, void* buf, unsigned int size); void reset_rb(struct ringbuf* rb); unsigned int free_rb(struct ringbuf* rb); +unsigned int free_rb_locked(struct ringbuf* rb); unsigned int used_rb(struct ringbuf* rb); void destroy_rb(struct ringbuf* rb);