From aa2fcfa7574ebdf3e348c051e496797841aa4f1d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 25 Aug 2008 15:49:06 +0200 Subject: fixed ringbuf.c warnings Fix a "signed/unsigned comparison warning", and several void pointer math warnings. --- src/ringbuf.c | 8 ++++---- src/ringbuf.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ringbuf.c b/src/ringbuf.c index ed46c3beb..20a09b326 100644 --- a/src/ringbuf.c +++ b/src/ringbuf.c @@ -36,7 +36,7 @@ struct ringbuf *ringbuf_create(size_t sz) struct ringbuf *rb = xmalloc(sizeof(struct ringbuf)); size_t power_of_two; - for (power_of_two = 1; 1 << power_of_two < sz; power_of_two++) + for (power_of_two = 1; (size_t)(1 << power_of_two) < sz; power_of_two++) /* next power_of_two... */; rb->size = 1 << power_of_two; @@ -137,7 +137,7 @@ size_t ringbuf_read(struct ringbuf * rb, void *dest, size_t cnt) ringbuf_read_advance(rb, n1); if (n2) { - memcpy(dest + n1, rb->buf + rb->read_ptr, n2); + memcpy((char*)dest + n1, rb->buf + rb->read_ptr, n2); ringbuf_read_advance(rb, n2); } @@ -175,7 +175,7 @@ size_t ringbuf_peek(struct ringbuf * rb, void *dest, size_t cnt) advance_ptr(tmp_read_ptr, n1, rb->size_mask); if (n2) { - memcpy(dest + n1, rb->buf + tmp_read_ptr, n2); + memcpy((char*)dest + n1, rb->buf + tmp_read_ptr, n2); advance_ptr(tmp_read_ptr, n2, rb->size_mask); } @@ -211,7 +211,7 @@ size_t ringbuf_write(struct ringbuf * rb, const void *src, size_t cnt) ringbuf_write_advance(rb, n1); if (n2) { - memcpy(rb->buf + rb->write_ptr, src + n1, n2); + memcpy(rb->buf + rb->write_ptr, (const char*)src + n1, n2); ringbuf_write_advance(rb, n2); } diff --git a/src/ringbuf.h b/src/ringbuf.h index 43ba83a7c..93f753897 100644 --- a/src/ringbuf.h +++ b/src/ringbuf.h @@ -39,7 +39,7 @@ */ struct ringbuf { - void *buf; + unsigned char *buf; size_t write_ptr; size_t read_ptr; size_t size; -- cgit v1.2.3 From a848893d85cd027d831ba0ecae9dacef0a5f0605 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 30 Aug 2008 17:33:07 -0700 Subject: ringbuf: create a new struct rbvec instead of reusing struct iovec Using struct iovec means having to cast iov_base everywhere we want to do pointer arithmetic. Instead, just use rbvec which can be safely casted to iovec whenever we use the readv/writev functions. --- src/inputStream_http.c | 2 +- src/outputBuffer.c | 24 ++++++++++++------------ src/outputBuffer_ob_send.h | 6 +++--- src/outputBuffer_xfade.h | 8 ++++---- src/ringbuf.c | 36 ++++++++++++++++++------------------ src/ringbuf.h | 18 ++++++++++++------ 6 files changed, 50 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/inputStream_http.c b/src/inputStream_http.c index a6c715459..cc31ed435 100644 --- a/src/inputStream_http.c +++ b/src/inputStream_http.c @@ -461,7 +461,7 @@ static ssize_t buffer_data(InputStream *is) assert(pthread_equal(data->io_thread, pthread_self())); assert_state2(CONN_STATE_BUFFER, CONN_STATE_PREBUFFER); - if (!ringbuf_get_write_vector(data->rb, vec)) { + if (!ringbuf_get_write_vector(data->rb, (struct rbvec *)vec)) { data->state = CONN_STATE_BUFFER_FULL; return 0; } diff --git a/src/outputBuffer.c b/src/outputBuffer.c index a856c9a8c..27bb18b44 100644 --- a/src/outputBuffer.c +++ b/src/outputBuffer.c @@ -152,7 +152,7 @@ static enum action_status ob_finalize_action(void) /* marks all buffered chunks with sequence number matching `seq' as invalid */ static enum action_status ob_do_drop(void) { - struct iovec vec[2]; + struct rbvec vec[2]; long i; mpd_uint8 seq_drop; @@ -190,7 +190,7 @@ static enum action_status ob_do_pause(void) static void reader_reset_buffer(void) { - struct iovec vec[2]; + struct rbvec vec[2]; size_t nr; long i; @@ -330,15 +330,15 @@ static enum action_status ob_take_action(void) * like an infinite, rotating buffer. The first available chunk * is always indexed as `0', the second one as `1', and so on... */ -static struct ob_chunk *get_chunk(struct iovec vec[2], size_t i) +static struct ob_chunk *get_chunk(struct rbvec vec[2], size_t i) { - if (vec[0].iov_len > i) - return &ob.chunks[vec[0].iov_base + i - ob.index->buf]; - if (i && vec[1].iov_base) { - assert(vec[0].iov_len > 0); - i -= vec[0].iov_len; - if (vec[1].iov_len > i) - return &ob.chunks[vec[1].iov_base + i - ob.index->buf]; + if (vec[0].len > i) + return &ob.chunks[vec[0].base + i - ob.index->buf]; + if (i && vec[1].base) { + assert(vec[0].len > 0); + i -= vec[0].len; + if (vec[1].len > i) + return &ob.chunks[vec[1].base + i - ob.index->buf]; } return NULL; } @@ -426,7 +426,7 @@ static void send_next_tag(void) static void play_next_chunk(void) { - struct iovec vec[2]; + struct rbvec vec[2]; struct ob_chunk *a; size_t nr; static float last_time; @@ -551,7 +551,7 @@ void ob_seek_finish(void) */ void ob_flush(void) { - struct iovec vec[2]; + struct rbvec vec[2]; assert(pthread_equal(pthread_self(), dc.thread)); /* DEBUG(__FILE__":%s %d\n", __func__, __LINE__); */ diff --git a/src/outputBuffer_ob_send.h b/src/outputBuffer_ob_send.h index 2a4a84763..d2c99b3f2 100644 --- a/src/outputBuffer_ob_send.h +++ b/src/outputBuffer_ob_send.h @@ -63,7 +63,7 @@ enum dc_action ob_send(void *data, size_t len, float decode_time, mpd_uint16 bit_rate, ReplayGainInfo * rgi) { - struct iovec vec[2]; + struct rbvec vec[2]; struct ob_chunk *c; size_t idx; size_t i, j; @@ -86,9 +86,9 @@ ob_send(void *data, size_t len, } for (i = 0; i < ARRAY_SIZE(vec); i++) { - for (j = 0; j < vec[i].iov_len; j++) { + for (j = 0; j < vec[i].len; j++) { size_t c_len; - idx = vec[i].iov_base - ob.index->buf + j; + idx = vec[i].base - ob.index->buf + j; c = &(ob.chunks[idx]); if (!c->len) { /* populate empty chunk */ diff --git a/src/outputBuffer_xfade.h b/src/outputBuffer_xfade.h index 336a7adc2..50fb062ce 100644 --- a/src/outputBuffer_xfade.h +++ b/src/outputBuffer_xfade.h @@ -5,8 +5,8 @@ #include "audio.h" #include "pcm_utils.h" -static struct ob_chunk *get_chunk(struct iovec vec[2], size_t i); -static size_t calculate_xfade_chunks(struct iovec vec[2]) +static struct ob_chunk *get_chunk(struct rbvec vec[2], size_t i); +static size_t calculate_xfade_chunks(struct rbvec vec[2]) { float xfade_time = ob.xfade_time; /* prevent race conditions */ size_t chunks; @@ -37,7 +37,7 @@ static size_t calculate_xfade_chunks(struct iovec vec[2]) if (chunks > (ob.index->size - ob.bpp_cur)) chunks = ob.index->size - ob.bpp_cur; DEBUG("calculated xfade chunks: %d\n", chunks); - nr = vec[0].iov_len + vec[1].iov_len; + nr = vec[0].len + vec[1].len; if (chunks <= nr) { c = get_chunk(vec, chunks); @@ -64,7 +64,7 @@ static size_t calculate_xfade_chunks(struct iovec vec[2]) return chunks; } -static size_t xfade_chunks_needed(struct iovec vec[2]) +static size_t xfade_chunks_needed(struct rbvec vec[2]) { assert(pthread_equal(ob.thread, pthread_self())); diff --git a/src/ringbuf.c b/src/ringbuf.c index 20a09b326..ec388abf3 100644 --- a/src/ringbuf.c +++ b/src/ringbuf.c @@ -236,7 +236,7 @@ void ringbuf_write_advance(struct ringbuf * rb, size_t cnt) * the readable data is in one segment the second segment has zero * length. */ -size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec) +size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct rbvec * vec) { size_t free_cnt; size_t cnt2; @@ -255,17 +255,17 @@ size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec) * Two part vector: the rest of the buffer after the current * write ptr, plus some from the start of the buffer. */ - vec[0].iov_base = rb->buf + r; - vec[0].iov_len = rb->size - r; - vec[1].iov_base = rb->buf; - vec[1].iov_len = cnt2 & rb->size_mask; + vec[0].base = rb->buf + r; + vec[0].len = rb->size - r; + vec[1].base = rb->buf; + vec[1].len = cnt2 & rb->size_mask; } else { /* Single part vector: just the rest of the buffer */ - vec[0].iov_base = rb->buf + r; - vec[0].iov_len = free_cnt; - vec[1].iov_len = 0; + vec[0].base = rb->buf + r; + vec[0].len = free_cnt; + vec[1].len = 0; } - return vec[0].iov_len + vec[1].iov_len; + return vec[0].len + vec[1].len; } /* @@ -274,7 +274,7 @@ size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec) * the writeable data is in one segment the second segment has zero * length. */ -size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec) +size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct rbvec * vec) { size_t free_cnt; size_t cnt2; @@ -295,15 +295,15 @@ size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec) * Two part vector: the rest of the buffer after the current * write ptr, plus some from the start of the buffer. */ - vec[0].iov_base = rb->buf + w; - vec[0].iov_len = rb->size - w; - vec[1].iov_base = rb->buf; - vec[1].iov_len = cnt2 & rb->size_mask; + vec[0].base = rb->buf + w; + vec[0].len = rb->size - w; + vec[1].base = rb->buf; + vec[1].len = cnt2 & rb->size_mask; } else { - vec[0].iov_base = rb->buf + w; - vec[0].iov_len = free_cnt; - vec[1].iov_len = 0; + vec[0].base = rb->buf + w; + vec[0].len = free_cnt; + vec[1].len = 0; } - return vec[0].iov_len + vec[1].iov_len; + return vec[0].len + vec[1].len; } diff --git a/src/ringbuf.h b/src/ringbuf.h index 93f753897..6225fcadf 100644 --- a/src/ringbuf.h +++ b/src/ringbuf.h @@ -46,6 +46,12 @@ struct ringbuf { size_t size_mask; }; +/* remain binary-compatible with struct iovec declared in : */ +struct rbvec { + unsigned char *base; + size_t len; +}; + /** * Allocates a ringbuffer data structure of a specified size. The * caller must arrange for a call to ringbuf_free() to release @@ -69,7 +75,7 @@ void ringbuf_free(struct ringbuf * rb); /** * Fill a data structure with a description of the current readable * data held in the ringbuffer. This description is returned in a two - * element array of struct iovec. Two elements are needed + * element array of struct rbvec. Two elements are needed * because the data to be read may be split across the end of the * ringbuffer. * @@ -83,16 +89,16 @@ void ringbuf_free(struct ringbuf * rb); * its corresponding @a buf field. * * @param rb a pointer to the ringbuffer structure. - * @param vec a pointer to a 2 element array of struct iovec. + * @param vec a pointer to a 2 element array of struct rbvec. * * @return total number of bytes readable into both vec elements */ -size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec); +size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct rbvec * vec); /** * Fill a data structure with a description of the current writable * space in the ringbuffer. The description is returned in a two - * element array of struct iovec. Two elements are needed + * element array of struct rbvec. Two elements are needed * because the space available for writing may be split across the end * of the ringbuffer. * @@ -106,11 +112,11 @@ size_t ringbuf_get_read_vector(const struct ringbuf * rb, struct iovec * vec); * the corresponding @a buf field. * * @param rb a pointer to the ringbuffer structure. - * @param vec a pointer to a 2 element array of struct iovec. + * @param vec a pointer to a 2 element array of struct rbvec. * * @return total number of bytes writable in both vec elements */ -size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct iovec * vec); +size_t ringbuf_get_write_vector(const struct ringbuf * rb, struct rbvec * vec); /** * Read data from the ringbuffer. -- cgit v1.2.3 From f150a02a3f025e71bac74dd9ca3eb262daeeed6e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 25 Aug 2008 15:49:06 +0200 Subject: fix warnings in the HTTP client Fix a "unused argument" warning, and several warnings regarding void pointer calculation. --- src/inputStream_http.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/inputStream_http.c b/src/inputStream_http.c index cc31ed435..8e4e0e115 100644 --- a/src/inputStream_http.c +++ b/src/inputStream_http.c @@ -847,7 +847,8 @@ static void parse_icy_metadata(InputStream * is, char *metadata, size_t size) } } -static size_t read_with_metadata(InputStream *is, void *ptr, ssize_t len) +static size_t read_with_metadata(InputStream *is, unsigned char *ptr, + ssize_t len) { struct http_data *data = (struct http_data *) is->data; size_t readed = 0; @@ -887,13 +888,13 @@ static size_t read_with_metadata(InputStream *is, void *ptr, ssize_t len) return readed; } -size_t inputStream_httpRead(InputStream * is, void *ptr, size_t size, +size_t inputStream_httpRead(InputStream * is, void *_ptr, size_t size, size_t nmemb) { struct http_data *data = (struct http_data *) is->data; size_t len = size * nmemb; size_t r; - void *ptr0 = ptr; + unsigned char *ptr = _ptr, *ptr0 = _ptr; long tries = len / 128; /* try harder for bigger reads */ retry: -- cgit v1.2.3 From ac5ec35a6e222f635912f6a7eaf3c036c71367b6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:02 +0200 Subject: enable -Wpointer-arith, -Wstrict-prototypes Also enable -Wunused-parameter - this forces us to add the gcc "unused" attribute to a lot of parameters (mostly library callback functions), but it's worth it during code refactorizations. --- src/audioOutputs/audioOutput_ao.c | 2 +- src/audioOutputs/audioOutput_jack.c | 4 +- src/audioOutputs/audioOutput_null.c | 5 +- src/audioOutputs/audioOutput_oss.c | 3 +- src/command.c | 198 +++++++++++++++++++++++------------- src/dbUtils.c | 22 ++-- src/inputPlugins/_flac_common.c | 2 +- src/inputPlugins/flac_plugin.c | 14 +-- src/inputPlugins/oggvorbis_plugin.c | 2 +- src/inputPlugins/wavpack_plugin.c | 3 +- src/inputStream_file.c | 2 +- src/inputStream_http.c | 2 +- src/main.c | 4 +- src/pcm_utils.c | 6 +- src/playlist.c | 2 +- src/sig_handlers.c | 2 +- src/tree.c | 14 +-- src/volume.c | 2 +- src/zeroconf.c | 9 +- 19 files changed, 182 insertions(+), 116 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c index 65ffa2c27..e7e201add 100644 --- a/src/audioOutputs/audioOutput_ao.c +++ b/src/audioOutputs/audioOutput_ao.c @@ -158,7 +158,7 @@ static void audioOutputAo_finishDriver(AudioOutput * audioOutput) ao_shutdown(); } -static void audioOutputAo_dropBufferedAudio(AudioOutput * audioOutput) +static void audioOutputAo_dropBufferedAudio(mpd_unused AudioOutput * audioOutput) { /* not supported by libao */ } diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index ed0bceb46..c8aa4dcb6 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -102,7 +102,7 @@ static void jack_finishDriver(AudioOutput *audioOutput) freeJackData(audioOutput); } -static int srate(jack_nframes_t rate, void *data) +static int srate(mpd_unused jack_nframes_t rate, void *data) { JackData *jd = (JackData *) ((AudioOutput*) data)->data; AudioFormat *audioFormat = &(((AudioOutput*) data)->outAudioFormat); @@ -366,7 +366,7 @@ static void jack_closeDevice(AudioOutput * audioOutput) DEBUG("jack_closeDevice (pid=%d)\n", getpid()); } -static void jack_dropBufferedAudio (AudioOutput * audioOutput) +static void jack_dropBufferedAudio (mpd_unused AudioOutput * audioOutput) { } diff --git a/src/audioOutputs/audioOutput_null.c b/src/audioOutputs/audioOutput_null.c index 37ff7194a..d63004645 100644 --- a/src/audioOutputs/audioOutput_null.c +++ b/src/audioOutputs/audioOutput_null.c @@ -19,7 +19,8 @@ #include "../audioOutput.h" #include "../timer.h" -static int null_initDriver(AudioOutput *audioOutput, ConfigParam *param) +static int null_initDriver(AudioOutput *audioOutput, + mpd_unused ConfigParam *param) { audioOutput->data = NULL; return 0; @@ -43,7 +44,7 @@ static void null_closeDevice(AudioOutput *audioOutput) } static int null_playAudio(AudioOutput *audioOutput, - const char *playChunk, size_t size) + mpd_unused const char *playChunk, size_t size) { Timer *timer = audioOutput->data; diff --git a/src/audioOutputs/audioOutput_oss.c b/src/audioOutputs/audioOutput_oss.c index 2a6a4876b..2df7d5728 100644 --- a/src/audioOutputs/audioOutput_oss.c +++ b/src/audioOutputs/audioOutput_oss.c @@ -334,7 +334,8 @@ static int oss_testDefault(void) return -1; } -static int oss_open_default(AudioOutput *ao, ConfigParam *param, OssData *od) +static int oss_open_default(mpd_unused AudioOutput *ao, ConfigParam *param, + OssData *od) { int i; int err[ARRAY_SIZE(default_devices)]; diff --git a/src/command.c b/src/command.c index a8c49e8c9..abe0ab8b0 100644 --- a/src/command.c +++ b/src/command.c @@ -234,18 +234,21 @@ static void addCommand(const char *name, insertInList(commandList, cmd->cmd, cmd); } -static int handleUrlHandlers(int fd, int *permission, int argc, char *argv[]) +static int handleUrlHandlers(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return printRemoteUrlHandlers(fd); } -static int handleTagTypes(int fd, int *permission, int argc, char *argv[]) +static int handleTagTypes(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { printTagTypes(fd); return 0; } -static int handlePlay(int fd, int *permission, int argc, char *argv[]) +static int handlePlay(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int song = -1; @@ -254,7 +257,8 @@ static int handlePlay(int fd, int *permission, int argc, char *argv[]) return playPlaylist(fd, song, 0); } -static int handlePlayId(int fd, int *permission, int argc, char *argv[]) +static int handlePlayId(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int id = -1; @@ -264,12 +268,14 @@ static int handlePlayId(int fd, int *permission, int argc, char *argv[]) return playPlaylistById(fd, id, 0); } -static int handleStop(int fd, int *permission, int argc, char *argv[]) +static int handleStop(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return stopPlaylist(fd); } -static int handleCurrentSong(int fd, int *permission, int argc, char *argv[]) +static int handleCurrentSong(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { int song = getPlaylistCurrentSong(); @@ -279,7 +285,8 @@ static int handleCurrentSong(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handlePause(int fd, int *permission, int argc, char *argv[]) +static int handlePause(int fd, mpd_unused int *permission, + int argc, char *argv[]) { enum ob_action action = OB_ACTION_PAUSE_FLIP; if (argc == 2) { @@ -292,7 +299,8 @@ static int handlePause(int fd, int *permission, int argc, char *argv[]) return 0; } -static int commandStatus(int fd, int *permission, int argc, char *argv[]) +static int commandStatus(mpd_unused int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { const char *state = NULL; int updateJobId; @@ -355,17 +363,20 @@ static int commandStatus(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handleKill(int fd, int *permission, int argc, char *argv[]) +static int handleKill(mpd_unused int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return COMMAND_RETURN_KILL; } -static int handleClose(int fd, int *permission, int argc, char *argv[]) +static int handleClose(mpd_unused int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return COMMAND_RETURN_CLOSE; } -static int handleAdd(int fd, int *permission, int argc, char *argv[]) +static int handleAdd(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { char *path = argv[1]; @@ -375,7 +386,8 @@ static int handleAdd(int fd, int *permission, int argc, char *argv[]) return addAllIn(fd, path); } -static int handleAddId(int fd, int *permission, int argc, char *argv[]) +static int handleAddId(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int added_id; int ret = addToPlaylist(fd, argv[1], &added_id); @@ -397,7 +409,8 @@ static int handleAddId(int fd, int *permission, int argc, char *argv[]) return ret; } -static int handleDelete(int fd, int *permission, int argc, char *argv[]) +static int handleDelete(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int song; @@ -406,7 +419,8 @@ static int handleDelete(int fd, int *permission, int argc, char *argv[]) return deleteFromPlaylist(fd, song); } -static int handleDeleteId(int fd, int *permission, int argc, char *argv[]) +static int handleDeleteId(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int id; @@ -415,43 +429,50 @@ static int handleDeleteId(int fd, int *permission, int argc, char *argv[]) return deleteFromPlaylistById(fd, id); } -static int handlePlaylist(int fd, int *permission, int argc, char *argv[]) +static int handlePlaylist(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return showPlaylist(fd); } -static int handleShuffle(int fd, int *permission, int argc, char *argv[]) +static int handleShuffle(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return shufflePlaylist(fd); } -static int handleClear(int fd, int *permission, int argc, char *argv[]) +static int handleClear(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return clearPlaylist(fd); } -static int handleSave(int fd, int *permission, int argc, char *argv[]) +static int handleSave(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { return savePlaylist(fd, argv[1]); } -static int handleLoad(int fd, int *permission, int argc, char *argv[]) +static int handleLoad(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { return loadPlaylist(fd, argv[1]); } -static int handleListPlaylist(int fd, int *permission, int argc, char *argv[]) +static int handleListPlaylist(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { return PlaylistInfo(fd, argv[1], 0); } -static int handleListPlaylistInfo(int fd, int *permission, - int argc, char *argv[]) +static int handleListPlaylistInfo(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { return PlaylistInfo(fd, argv[1], 1); } -static int handleLsInfo(int fd, int *permission, int argc, char *argv[]) +static int handleLsInfo(int fd, mpd_unused int *permission, + int argc, char *argv[]) { const char *path = ""; @@ -467,18 +488,20 @@ static int handleLsInfo(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handleRm(int fd, int *permission, int argc, char *argv[]) +static int handleRm(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { return deletePlaylist(fd, argv[1]); } -static int handleRename(int fd, int *permission, int argc, char *argv[]) +static int handleRename(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { return renameStoredPlaylist(fd, argv[1], argv[2]); } -static int handlePlaylistChanges(int fd, int *permission, - int argc, char *argv[]) +static int handlePlaylistChanges(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { mpd_uint32 version; @@ -487,8 +510,8 @@ static int handlePlaylistChanges(int fd, int *permission, return playlistChanges(fd, version); } -static int handlePlaylistChangesPosId(int fd, int *permission, - int argc, char *argv[]) +static int handlePlaylistChangesPosId(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { mpd_uint32 version; @@ -497,7 +520,8 @@ static int handlePlaylistChangesPosId(int fd, int *permission, return playlistChangesPosId(fd, version); } -static int handlePlaylistInfo(int fd, int *permission, int argc, char *argv[]) +static int handlePlaylistInfo(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int song = -1; @@ -506,7 +530,8 @@ static int handlePlaylistInfo(int fd, int *permission, int argc, char *argv[]) return playlistInfo(fd, song); } -static int handlePlaylistId(int fd, int *permission, int argc, char *argv[]) +static int handlePlaylistId(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int id = -1; @@ -515,7 +540,8 @@ static int handlePlaylistId(int fd, int *permission, int argc, char *argv[]) return playlistId(fd, id); } -static int handleFind(int fd, int *permission, int argc, char *argv[]) +static int handleFind(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int ret; @@ -536,7 +562,8 @@ static int handleFind(int fd, int *permission, int argc, char *argv[]) return ret; } -static int handleSearch(int fd, int *permission, int argc, char *argv[]) +static int handleSearch(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int ret; @@ -557,7 +584,8 @@ static int handleSearch(int fd, int *permission, int argc, char *argv[]) return ret; } -static int handleCount(int fd, int *permission, int argc, char *argv[]) +static int handleCount(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int ret; @@ -578,7 +606,8 @@ static int handleCount(int fd, int *permission, int argc, char *argv[]) return ret; } -static int handlePlaylistFind(int fd, int *permission, int argc, char *argv[]) +static int handlePlaylistFind(int fd, mpd_unused int *permission, + int argc, char *argv[]) { LocateTagItem *items; int numItems = newLocateTagItemArrayFromArgArray(argv + 1, @@ -597,7 +626,8 @@ static int handlePlaylistFind(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handlePlaylistSearch(int fd, int *permission, int argc, char *argv[]) +static int handlePlaylistSearch(int fd, mpd_unused int *permission, + int argc, char *argv[]) { LocateTagItem *items; int numItems = newLocateTagItemArrayFromArgArray(argv + 1, @@ -616,7 +646,8 @@ static int handlePlaylistSearch(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handlePlaylistDelete(int fd, int *permission, int argc, char *argv[]) { +static int handlePlaylistDelete(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { char *playlist = argv[1]; int from; @@ -626,7 +657,8 @@ static int handlePlaylistDelete(int fd, int *permission, int argc, char *argv[]) return removeOneSongFromStoredPlaylistByPath(fd, playlist, from); } -static int handlePlaylistMove(int fd, int *permission, int argc, char *argv[]) +static int handlePlaylistMove(int fd, mpd_unused int *permission, + mpd_unused mpd_unused int argc, char *argv[]) { char *playlist = argv[1]; int from, to; @@ -640,8 +672,8 @@ static int handlePlaylistMove(int fd, int *permission, int argc, char *argv[]) } static int listHandleUpdate(int fd, - int *permission, - int argc, + mpd_unused int *permission, + mpd_unused int argc, char *argv[], struct strnode *cmdnode, CommandEntry * cmd) { @@ -670,7 +702,8 @@ static int listHandleUpdate(int fd, return 0; } -static int handleUpdate(int fd, int *permission, int argc, char *argv[]) +static int handleUpdate(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { if (argc == 2) { int ret; @@ -683,17 +716,20 @@ static int handleUpdate(int fd, int *permission, int argc, char *argv[]) return updateInit(fd, NULL); } -static int handleNext(int fd, int *permission, int argc, char *argv[]) +static int handleNext(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return nextSongInPlaylist(fd); } -static int handlePrevious(int fd, int *permission, int argc, char *argv[]) +static int handlePrevious(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return previousSongInPlaylist(fd); } -static int handleListAll(int fd, int *permission, int argc, char *argv[]) +static int handleListAll(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { char *directory = NULL; @@ -702,7 +738,8 @@ static int handleListAll(int fd, int *permission, int argc, char *argv[]) return printAllIn(fd, directory); } -static int handleVolume(int fd, int *permission, int argc, char *argv[]) +static int handleVolume(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int change; @@ -711,7 +748,8 @@ static int handleVolume(int fd, int *permission, int argc, char *argv[]) return changeVolumeLevel(fd, change, 1); } -static int handleSetVol(int fd, int *permission, int argc, char *argv[]) +static int handleSetVol(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int level; @@ -720,7 +758,8 @@ static int handleSetVol(int fd, int *permission, int argc, char *argv[]) return changeVolumeLevel(fd, level, 0); } -static int handleRepeat(int fd, int *permission, int argc, char *argv[]) +static int handleRepeat(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int status; @@ -729,7 +768,8 @@ static int handleRepeat(int fd, int *permission, int argc, char *argv[]) return setPlaylistRepeatStatus(fd, status); } -static int handleRandom(int fd, int *permission, int argc, char *argv[]) +static int handleRandom(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int status; @@ -738,18 +778,21 @@ static int handleRandom(int fd, int *permission, int argc, char *argv[]) return setPlaylistRandomStatus(fd, status); } -static int handleStats(int fd, int *permission, int argc, char *argv[]) +static int handleStats(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return printStats(fd); } -static int handleClearError(int fd, int *permission, int argc, char *argv[]) +static int handleClearError(mpd_unused int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { player_clearerror(); return 0; } -static int handleList(int fd, int *permission, int argc, char *argv[]) +static int handleList(int fd, mpd_unused int *permission, + int argc, char *argv[]) { int numConditionals; LocateTagItem *conditionals = NULL; @@ -798,7 +841,8 @@ static int handleList(int fd, int *permission, int argc, char *argv[]) return ret; } -static int handleMove(int fd, int *permission, int argc, char *argv[]) +static int handleMove(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int from, to; @@ -809,7 +853,8 @@ static int handleMove(int fd, int *permission, int argc, char *argv[]) return moveSongInPlaylist(fd, from, to); } -static int handleMoveId(int fd, int *permission, int argc, char *argv[]) +static int handleMoveId(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int id, to; @@ -820,7 +865,8 @@ static int handleMoveId(int fd, int *permission, int argc, char *argv[]) return moveSongInPlaylistById(fd, id, to); } -static int handleSwap(int fd, int *permission, int argc, char *argv[]) +static int handleSwap(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int song1, song2; @@ -831,7 +877,8 @@ static int handleSwap(int fd, int *permission, int argc, char *argv[]) return swapSongsInPlaylist(fd, song1, song2); } -static int handleSwapId(int fd, int *permission, int argc, char *argv[]) +static int handleSwapId(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int id1, id2; @@ -842,7 +889,8 @@ static int handleSwapId(int fd, int *permission, int argc, char *argv[]) return swapSongsInPlaylistById(fd, id1, id2); } -static int handleSeek(int fd, int *permission, int argc, char *argv[]) +static int handleSeek(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int song, seek_time; @@ -853,7 +901,8 @@ static int handleSeek(int fd, int *permission, int argc, char *argv[]) return seekSongInPlaylist(fd, song, seek_time); } -static int handleSeekId(int fd, int *permission, int argc, char *argv[]) +static int handleSeekId(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int id, seek_time; @@ -864,7 +913,8 @@ static int handleSeekId(int fd, int *permission, int argc, char *argv[]) return seekSongInPlaylistById(fd, id, seek_time); } -static int handleListAllInfo(int fd, int *permission, int argc, char *argv[]) +static int handleListAllInfo(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { char *directory = NULL; @@ -873,12 +923,14 @@ static int handleListAllInfo(int fd, int *permission, int argc, char *argv[]) return printInfoForAllIn(fd, directory); } -static int handlePing(int fd, int *permission, int argc, char *argv[]) +static int handlePing(mpd_unused int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { return 0; } -static int handlePassword(int fd, int *permission, int argc, char *argv[]) +static int handlePassword(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { if (getPermissionFromPassword(argv[1], permission) < 0) { commandError(fd, ACK_ERROR_PASSWORD, "incorrect password"); @@ -888,7 +940,8 @@ static int handlePassword(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handleCrossfade(int fd, int *permission, int argc, char *argv[]) +static int handleCrossfade(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int xfade_time; @@ -899,7 +952,8 @@ static int handleCrossfade(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handleEnableDevice(int fd, int *permission, int argc, char *argv[]) +static int handleEnableDevice(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int device; @@ -908,7 +962,8 @@ static int handleEnableDevice(int fd, int *permission, int argc, char *argv[]) return enableAudioDevice(fd, device); } -static int handleDisableDevice(int fd, int *permission, int argc, char *argv[]) +static int handleDisableDevice(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { int device; @@ -917,7 +972,8 @@ static int handleDisableDevice(int fd, int *permission, int argc, char *argv[]) return disableAudioDevice(fd, device); } -static int handleDevices(int fd, int *permission, int argc, char *argv[]) +static int handleDevices(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { printAudioDevices(fd); @@ -925,7 +981,8 @@ static int handleDevices(int fd, int *permission, int argc, char *argv[]) } /* don't be fooled, this is the command handler for "commands" command */ -static int handleCommands(int fd, int *permission, int argc, char *argv[]) +static int handleCommands(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { ListNode *node = commandList->firstNode; CommandEntry *cmd; @@ -942,7 +999,8 @@ static int handleCommands(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handleNotcommands(int fd, int *permission, int argc, char *argv[]) +static int handleNotcommands(int fd, mpd_unused int *permission, + mpd_unused int argc, mpd_unused char *argv[]) { ListNode *node = commandList->firstNode; CommandEntry *cmd; @@ -960,12 +1018,14 @@ static int handleNotcommands(int fd, int *permission, int argc, char *argv[]) return 0; } -static int handlePlaylistClear(int fd, int *permission, int argc, char *argv[]) +static int handlePlaylistClear(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { return clearStoredPlaylist(fd, argv[1]); } -static int handlePlaylistAdd(int fd, int *permission, int argc, char *argv[]) +static int handlePlaylistAdd(int fd, mpd_unused int *permission, + mpd_unused int argc, char *argv[]) { char *playlist = argv[1]; char *path = argv[2]; @@ -1139,7 +1199,7 @@ static CommandEntry *getCommandEntryFromString(char *string, int *permission) return cmd; } -static int processCommandInternal(int fd, int *permission, +static int processCommandInternal(int fd, mpd_unused int *permission, char *commandString, struct strnode *cmdnode) { int argc; diff --git a/src/dbUtils.c b/src/dbUtils.c index 11f724b21..5d070e588 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -45,7 +45,8 @@ typedef struct _SearchStats { unsigned long playTime; } SearchStats; -static int countSongsInDirectory(int fd, Directory * directory, void *data) +static int countSongsInDirectory(mpd_unused int fd, Directory * directory, + void *data) { int *count = (int *)data; @@ -55,7 +56,7 @@ static int countSongsInDirectory(int fd, Directory * directory, void *data) } static int printDirectoryInDirectory(int fd, Directory * directory, - void *data) + mpd_unused void *data) { if (directory->path) { fdprintf(fd, "directory: %s\n", getDirectoryPath(directory)); @@ -63,7 +64,7 @@ static int printDirectoryInDirectory(int fd, Directory * directory, return 0; } -static int printSongInDirectory(int fd, Song * song, void *data) +static int printSongInDirectory(int fd, Song * song, mpd_unused void *data) { printSongUrl(fd, song); return 0; @@ -133,7 +134,7 @@ static void printSearchStats(int fd, SearchStats *stats) fdprintf(fd, "playtime: %li\n", stats->playTime); } -static int searchStatsInDirectory(int fd, Song * song, void *data) +static int searchStatsInDirectory(mpd_unused int fd, Song * song, void *data) { SearchStats *stats = data; @@ -171,7 +172,8 @@ int printAllIn(int fd, char *name) printDirectoryInDirectory, NULL); } -static int directoryAddSongToPlaylist(int fd, Song * song, void *data) +static int directoryAddSongToPlaylist(int fd, Song * song, + mpd_unused void *data) { return addSongToPlaylist(fd, song, NULL); } @@ -194,12 +196,12 @@ int addAllInToStoredPlaylist(int fd, char *name, char *utf8file) (void *)utf8file); } -static int directoryPrintSongInfo(int fd, Song * song, void *data) +static int directoryPrintSongInfo(int fd, Song * song, mpd_unused void *data) { return printSongInfo(fd, song); } -static int sumSongTime(int fd, Song * song, void *data) +static int sumSongTime(mpd_unused int fd, Song * song, void *data) { unsigned long *sum_time = (unsigned long *)data; @@ -307,7 +309,8 @@ int listAllUniqueTags(int fd, int type, int numConditionals, return ret; } -static int sumSavedFilenameMemoryInDirectory(int fd, Directory * dir, +static int sumSavedFilenameMemoryInDirectory(mpd_unused int fd, + Directory * dir, void *data) { int *sum = data; @@ -321,7 +324,8 @@ static int sumSavedFilenameMemoryInDirectory(int fd, Directory * dir, return 0; } -static int sumSavedFilenameMemoryInSong(int fd, Song * song, void *data) +static int sumSavedFilenameMemoryInSong(mpd_unused int fd, Song * song, + void *data) { int *sum = data; diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c index 3401a8b4f..3655fd478 100644 --- a/src/inputPlugins/_flac_common.c +++ b/src/inputPlugins/_flac_common.c @@ -180,7 +180,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block, void flac_error_common_cb(const char *plugin, const FLAC__StreamDecoderErrorStatus status, - FlacData * data) + mpd_unused FlacData * data) { if (dc_intr()) return; diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c index 4a4ac627c..5c27cab39 100644 --- a/src/inputPlugins/flac_plugin.c +++ b/src/inputPlugins/flac_plugin.c @@ -31,7 +31,7 @@ /* this code was based on flac123, from flac-tools */ -static flac_read_status flacRead(const flac_decoder * flacDec, +static flac_read_status flacRead(mpd_unused const flac_decoder * flacDec, FLAC__byte buf[], flac_read_status_size_t *bytes, void *fdata) @@ -57,7 +57,7 @@ static flac_read_status flacRead(const flac_decoder * flacDec, return flac_read_status_continue; } -static flac_seek_status flacSeek(const flac_decoder * flacDec, +static flac_seek_status flacSeek(mpd_unused const flac_decoder * flacDec, FLAC__uint64 offset, void *fdata) { @@ -70,7 +70,7 @@ static flac_seek_status flacSeek(const flac_decoder * flacDec, return flac_seek_status_ok; } -static flac_tell_status flacTell(const flac_decoder * flacDec, +static flac_tell_status flacTell(mpd_unused const flac_decoder * flacDec, FLAC__uint64 * offset, void *fdata) { @@ -81,7 +81,7 @@ static flac_tell_status flacTell(const flac_decoder * flacDec, return flac_tell_status_ok; } -static flac_length_status flacLength(const flac_decoder * flacDec, +static flac_length_status flacLength(mpd_unused const flac_decoder * flacDec, FLAC__uint64 * length, void *fdata) { @@ -92,7 +92,7 @@ static flac_length_status flacLength(const flac_decoder * flacDec, return flac_length_status_ok; } -static FLAC__bool flacEOF(const flac_decoder * flacDec, void *fdata) +static FLAC__bool flacEOF(mpd_unused const flac_decoder * flacDec, void *fdata) { FlacData *data = (FlacData *) fdata; @@ -101,7 +101,7 @@ static FLAC__bool flacEOF(const flac_decoder * flacDec, void *fdata) return false; } -static void flacError(const flac_decoder *dec, +static void flacError(mpd_unused const flac_decoder *dec, FLAC__StreamDecoderErrorStatus status, void *fdata) { flac_error_common_cb("flac", status, (FlacData *) fdata); @@ -199,7 +199,7 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state) } #endif /* FLAC_API_VERSION_CURRENT >= 7 */ -static void flacMetadata(const flac_decoder * dec, +static void flacMetadata(mpd_unused const flac_decoder * dec, const FLAC__StreamMetadata * block, void *vdata) { flac_metadata_common_cb(block, (FlacData *) vdata); diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index cb6eed28e..567515d23 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -86,7 +86,7 @@ static int ogg_seek_cb(void *vdata, ogg_int64_t offset, int whence) } /* TODO: check Ogg libraries API and see if we can just not have this func */ -static int ogg_close_cb(void *vdata) +static int ogg_close_cb(mpd_unused void *vdata) { return 0; } diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index 2538be326..f1491d095 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -113,7 +113,8 @@ static void format_samples_int(int Bps, void *buffer, uint32_t samcnt) /* * This function converts floating point sample data to 16 bit integer. */ -static void format_samples_float(int Bps, void *buffer, uint32_t samcnt) +static void format_samples_float(mpd_unused int Bps, void *buffer, + uint32_t samcnt) { int16_t *dst = (int16_t *)buffer; float *src = (float *)buffer; diff --git a/src/inputStream_file.c b/src/inputStream_file.c index fb433d380..2e51e3f6c 100644 --- a/src/inputStream_file.c +++ b/src/inputStream_file.c @@ -106,7 +106,7 @@ int inputStream_fileAtEOF(InputStream * inStream) return 0; } -int inputStream_fileBuffer(InputStream * inStream) +int inputStream_fileBuffer(mpd_unused InputStream * inStream) { return 0; } diff --git a/src/inputStream_http.c b/src/inputStream_http.c index 8e4e0e115..8802eda2b 100644 --- a/src/inputStream_http.c +++ b/src/inputStream_http.c @@ -750,7 +750,7 @@ closed: return NULL; } -int inputStream_httpBuffer(InputStream *is) +int inputStream_httpBuffer(mpd_unused InputStream *is) { return 0; } diff --git a/src/main.c b/src/main.c index e897cacc1..57766d04b 100644 --- a/src/main.c +++ b/src/main.c @@ -352,7 +352,7 @@ static void cleanUpPidFile(void) unlink(pidFileParam->value); } -static void killFromPidFile(char *cmd, int killOption) +static void killFromPidFile(void) { FILE *fp; ConfigParam *pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0); @@ -391,7 +391,7 @@ int main(int argc, char *argv[]) parseOptions(argc, argv, &options); if (options.kill) - killFromPidFile(argv[0], options.kill); + killFromPidFile(); initStats(); initTagConfig(); diff --git a/src/pcm_utils.c b/src/pcm_utils.c index 3cf57def1..f716c279d 100644 --- a/src/pcm_utils.c +++ b/src/pcm_utils.c @@ -258,9 +258,11 @@ static size_t pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate, #else /* !HAVE_LIBSAMPLERATE */ /* resampling code blatantly ripped from ESD */ static size_t pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate, - const char *inBuffer, size_t inSize, + const char *inBuffer, + mpd_unused size_t inSize, mpd_uint32 outSampleRate, char *outBuffer, - size_t outSize, ConvState *convState) + size_t outSize, + mpd_unused ConvState *convState) { mpd_uint32 rd_dat = 0; mpd_uint32 wr_dat = 0; diff --git a/src/playlist.c b/src/playlist.c index 9751eda76..39e806670 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -1261,7 +1261,7 @@ int previousSongInPlaylist(int fd) return play_order_num(fd, prev_order_num, 0); } -int shufflePlaylist(int fd) +int shufflePlaylist(mpd_unused int fd) { int i; int ri; diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 0ad35b779..2d2e08278 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -46,7 +46,7 @@ int handlePendingSignals(void) return 0; } -static void chldSigHandler(int sig) +static void chldSigHandler(mpd_unused int sig) { int status; int pid; diff --git a/src/tree.c b/src/tree.c index 4b212cca6..40dc4224c 100644 --- a/src/tree.c +++ b/src/tree.c @@ -171,8 +171,7 @@ _SplitNode(TreeNode * node) static void -_InsertNodeAndData(Tree * tree, - TreeNode * node, +_InsertNodeAndData(TreeNode * node, int pos, TreeNode * newNode, TreeKeyData keyData) @@ -204,8 +203,7 @@ _InsertNodeAndData(Tree * tree, static TreeKeyData -_AddDataToSplitNodes(Tree * tree, - TreeNode * lessNode, +_AddDataToSplitNodes(TreeNode * lessNode, TreeNode * moreNode, int pos, TreeNode * newNode, @@ -217,7 +215,7 @@ _AddDataToSplitNodes(Tree * tree, if (pos <= lessNode->count) { - _InsertNodeAndData(tree, lessNode, pos, newNode, keyData); + _InsertNodeAndData(lessNode, pos, newNode, keyData); lessNode->count--; retKeyData = lessNode->keyData[lessNode->count]; _ClearKeyData(&(lessNode->keyData[lessNode->count])); @@ -277,8 +275,7 @@ _InsertAt(TreeIterator * iter, TreeKeyData keyData) TreeNode * newNode = _SplitNode(node); /* insert data in split nodes */ - keyData = _AddDataToSplitNodes(iter->tree, - node, + keyData = _AddDataToSplitNodes(node, newNode, pos, insertNode, @@ -306,8 +303,7 @@ _InsertAt(TreeIterator * iter, TreeKeyData keyData) else { /* insert the data and newNode */ - _InsertNodeAndData(iter->tree, - node, + _InsertNodeAndData(node, pos, insertNode, keyData); diff --git a/src/volume.c b/src/volume.c index 0da7d0360..791c1ea02 100644 --- a/src/volume.c +++ b/src/volume.c @@ -468,7 +468,7 @@ int getVolumeLevel(void) } } -static int changeSoftwareVolume(int fd, int change, int rel) +static int changeSoftwareVolume(mpd_unused int fd, int change, int rel) { int new = change; diff --git a/src/zeroconf.c b/src/zeroconf.c index 421a037b8..e6cbb4287 100644 --- a/src/zeroconf.c +++ b/src/zeroconf.c @@ -94,7 +94,7 @@ struct AvahiTimeout { static AvahiWatch *avahiWatchList; static AvahiTimeout *avahiTimeoutList; -static AvahiWatch *avahiWatchNew(const AvahiPoll * api, int fd, +static AvahiWatch *avahiWatchNew(mpd_unused const AvahiPoll * api, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, void *userdata) { @@ -177,7 +177,7 @@ static void avahiTimeoutFree(AvahiTimeout * t) free(t); } -static AvahiTimeout *avahiTimeoutNew(const AvahiPoll * api, +static AvahiTimeout *avahiTimeoutNew(mpd_unused const AvahiPoll * api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) @@ -201,7 +201,8 @@ static AvahiTimeout *avahiTimeoutNew(const AvahiPoll * api, /* Callback when the EntryGroup changes state */ static void avahiGroupCallback(AvahiEntryGroup * g, - AvahiEntryGroupState state, void *userdata) + AvahiEntryGroupState state, + mpd_unused void *userdata) { char *n; assert(g); @@ -291,7 +292,7 @@ fail: /* Callback when avahi changes state */ static void avahiClientCallback(AvahiClient * c, AvahiClientState state, - void *userdata) + mpd_unused void *userdata) { int reason; assert(c); -- cgit v1.2.3 From 27ce02fa9146601ab4a0210cc85c2d5f50b833f4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:03 +0200 Subject: clean up CPP includes Include only headers which are really required. This speeds up compilation and helps detect cross-layer accesses. [ew: minor fixups to not break on new core] --- src/inputPlugin.h | 1 + src/inputPlugins/_flac_common.c | 6 ------ src/inputPlugins/_flac_common.h | 4 ---- src/inputPlugins/_ogg_common.c | 1 - src/inputPlugins/aac_plugin.c | 4 ---- src/inputPlugins/audiofile_plugin.c | 4 ---- src/inputPlugins/flac_plugin.c | 6 ------ src/inputPlugins/mod_plugin.c | 3 --- src/inputPlugins/mp3_plugin.c | 5 ----- src/inputPlugins/mp4_plugin.c | 6 ------ src/inputPlugins/mpc_plugin.c | 6 ------ src/inputPlugins/oggflac_plugin.c | 6 ------ src/inputPlugins/oggvorbis_plugin.c | 6 ------ src/inputPlugins/wavpack_plugin.c | 4 ---- src/outputBuffer.c | 1 + src/outputBuffer.h | 1 - src/sig_handlers.c | 1 - 17 files changed, 2 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/inputPlugin.h b/src/inputPlugin.h index 2f337acef..161a0db59 100644 --- a/src/inputPlugin.h +++ b/src/inputPlugin.h @@ -22,6 +22,7 @@ #include "inputStream.h" #include "outputBuffer.h" #include "metadata_pipe.h" +#include "decode.h" /* valid values for streamTypes in the InputPlugin struct: */ #define INPUT_PLUGIN_STREAM_FILE 0x01 diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c index 3655fd478..6890c7c50 100644 --- a/src/inputPlugins/_flac_common.c +++ b/src/inputPlugins/_flac_common.c @@ -26,12 +26,6 @@ #include "_flac_common.h" #include "../log.h" -#include "../tag.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../decode.h" -#include "../replayGain.h" -#include "../os_compat.h" #include #include diff --git a/src/inputPlugins/_flac_common.h b/src/inputPlugins/_flac_common.h index 5c147a064..6fe5bd744 100644 --- a/src/inputPlugins/_flac_common.h +++ b/src/inputPlugins/_flac_common.h @@ -26,10 +26,6 @@ #if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC) -#include "../tag.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../decode.h" #include #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 # include diff --git a/src/inputPlugins/_ogg_common.c b/src/inputPlugins/_ogg_common.c index d24b2b47b..a7525c2de 100644 --- a/src/inputPlugins/_ogg_common.c +++ b/src/inputPlugins/_ogg_common.c @@ -28,7 +28,6 @@ (defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7) #include "../utils.h" -#include "../os_compat.h" ogg_stream_type ogg_stream_type_detect(InputStream * inStream) { diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 98329a4b3..dd255903a 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -23,11 +23,7 @@ #define AAC_MAX_CHANNELS 6 #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../os_compat.h" #include diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c index 114a87786..7f748fc1b 100644 --- a/src/inputPlugins/audiofile_plugin.c +++ b/src/inputPlugins/audiofile_plugin.c @@ -22,11 +22,7 @@ #ifdef HAVE_AUDIOFILE -#include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../os_compat.h" #include diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c index 5c27cab39..de0648c90 100644 --- a/src/inputPlugins/flac_plugin.c +++ b/src/inputPlugins/flac_plugin.c @@ -22,12 +22,6 @@ #include "../utils.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../replayGain.h" -#include "../audio.h" -#include "../os_compat.h" /* this code was based on flac123, from flac-tools */ diff --git a/src/inputPlugins/mod_plugin.c b/src/inputPlugins/mod_plugin.c index 9f9da6273..df938f0ed 100644 --- a/src/inputPlugins/mod_plugin.c +++ b/src/inputPlugins/mod_plugin.c @@ -21,10 +21,7 @@ #ifdef HAVE_MIKMOD #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../os_compat.h" #include diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index c36cab6f0..684655f97 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -20,7 +20,6 @@ #ifdef HAVE_MAD -#include "../pcm_utils.h" #include #ifdef HAVE_ID3TAG @@ -29,12 +28,8 @@ #include "../log.h" #include "../utils.h" -#include "../replayGain.h" -#include "../tag.h" #include "../conf.h" -#include "../os_compat.h" - #define FRAMES_CUSHION 2000 #define READ_BUFFER_SIZE 40960 diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c index bf200c534..66dbbfdba 100644 --- a/src/inputPlugins/mp4_plugin.c +++ b/src/inputPlugins/mp4_plugin.c @@ -21,13 +21,7 @@ #ifdef HAVE_FAAD #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../decode.h" -#include "../os_compat.h" #include "../mp4ff/mp4ff.h" diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c index 116e471ff..ea27d1dbf 100644 --- a/src/inputPlugins/mpc_plugin.c +++ b/src/inputPlugins/mpc_plugin.c @@ -21,13 +21,7 @@ #ifdef HAVE_MPCDEC #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../replayGain.h" -#include "../os_compat.h" #include diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c index 6c5998afe..87444d261 100644 --- a/src/inputPlugins/oggflac_plugin.c +++ b/src/inputPlugins/oggflac_plugin.c @@ -27,12 +27,6 @@ #include "../utils.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../replayGain.h" -#include "../audio.h" -#include "../os_compat.h" static void oggflac_cleanup(FlacData * data, OggFLAC__SeekableStreamDecoder * decoder) diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index 567515d23..7612b1db5 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -25,13 +25,7 @@ #include "_ogg_common.h" #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../replayGain.h" -#include "../os_compat.h" #ifndef HAVE_TREMOR #include diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index f1491d095..4199dd946 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -23,11 +23,7 @@ #ifdef HAVE_WAVPACK #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../outputBuffer.h" -#include "../os_compat.h" #include "../path.h" #include diff --git a/src/outputBuffer.c b/src/outputBuffer.c index 27bb18b44..fd6b115f6 100644 --- a/src/outputBuffer.c +++ b/src/outputBuffer.c @@ -27,6 +27,7 @@ #include "player_error.h" #include "log.h" #include "action_status.h" +#include "decode.h" /* typically have 2048-4096 of these structs, so pack tightly */ struct ob_chunk { diff --git a/src/outputBuffer.h b/src/outputBuffer.h index 15e46da60..3fc440af3 100644 --- a/src/outputBuffer.h +++ b/src/outputBuffer.h @@ -21,7 +21,6 @@ #include "pcm_utils.h" #include "mpd_types.h" -#include "decode.h" #include "inputStream.h" #include "replayGain.h" diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 2d2e08278..6b28cb675 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -23,7 +23,6 @@ #include "command.h" #include "signal_check.h" #include "log.h" -#include "decode.h" int handlePendingSignals(void) { -- cgit v1.2.3 From 360c188c9d0460aff44f9c78bec25fcbab1cbead Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:06 +0200 Subject: aac/mp4: removed local variable "eof" because it is unused "break" is so much easier than "eof=1; continue;", when "!eof" is the loop condition. --- src/inputPlugins/aac_plugin.c | 12 +++++------- src/inputPlugins/mp4_plugin.c | 15 +++++---------- 2 files changed, 10 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index dd255903a..7cff31d40 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -288,7 +288,6 @@ static int aac_decode(char *path) long bread; uint32_t sampleRate; unsigned char channels; - int eof = 0; unsigned int sampleCount; char *sampleBuffer; size_t sampleBufferLen; @@ -342,13 +341,12 @@ static int aac_decode(char *path) advanceAacBuffer(&b, bread); - while (!eof) { + while (1) { fillAacBuffer(&b); - if (b.bytesIntoBuffer == 0) { - eof = 1; + if (b.bytesIntoBuffer == 0) break; - } + #ifdef HAVE_FAAD_BUFLEN_FUNCS sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer, b.bytesIntoBuffer); @@ -360,7 +358,6 @@ static int aac_decode(char *path) ERROR("error decoding AAC file: %s\n", path); ERROR("faad2 error: %s\n", faacDecGetErrorMessage(frameInfo.error)); - eof = 1; break; } #ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE @@ -395,9 +392,10 @@ static int aac_decode(char *path) */ dc_action_seek_fail(DC_SEEK_ERROR); break; - default: eof = 1; + default: goto out; } } +out: faacDecClose(decoder); if (b.buffer) diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c index 66dbbfdba..8e3d02354 100644 --- a/src/inputPlugins/mp4_plugin.c +++ b/src/inputPlugins/mp4_plugin.c @@ -94,7 +94,6 @@ static int mp4_decode(InputStream * inStream) unsigned char channels; long sampleId; long numSamples; - int eof = 0; long dur; unsigned int sampleCount; char *sampleBuffer; @@ -177,7 +176,7 @@ static int mp4_decode(InputStream * inStream) seekTable = xmalloc(sizeof(float) * numSamples); - for (sampleId = 0; sampleId < numSamples && !eof; sampleId++) { + for (sampleId = 0; sampleId < numSamples; sampleId++) { if (!seeking && dc_seek()) { dc_action_begin(); assert(dc.action == DC_ACTION_SEEK); @@ -223,10 +222,9 @@ static int mp4_decode(InputStream * inStream) continue; if (mp4ff_read_sample(mp4fh, track, sampleId, &mp4Buffer, - &mp4BufferSize) == 0) { - eof = 1; - continue; - } + &mp4BufferSize) == 0) + break; + #ifdef HAVE_FAAD_BUFLEN_FUNCS sampleBuffer = faacDecDecode(decoder, &frameInfo, mp4Buffer, mp4BufferSize); @@ -239,7 +237,6 @@ static int mp4_decode(InputStream * inStream) if (frameInfo.error > 0) { ERROR("faad2 error: %s\n", faacDecGetErrorMessage(frameInfo.error)); - eof = 1; break; } @@ -270,10 +267,8 @@ static int mp4_decode(InputStream * inStream) ob_send(sampleBuffer, sampleBufferLen, file_time, bitRate, NULL); - if (dc_intr()) { - eof = 1; + if (dc_intr()) break; - } } free(seekTable); -- cgit v1.2.3 From 7750e5b1e8f989513ef982c4c4dca4dbe4fe7a92 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:06 +0200 Subject: audiofile: use break instead of local variable "eof" Similar to previous patch: eliminate one variable by using "break". This also simplifies the code since we can remove one level of indent. [ew: rewritten to match current API] --- src/inputPlugins/audiofile_plugin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c index 7f748fc1b..d32a99857 100644 --- a/src/inputPlugins/audiofile_plugin.c +++ b/src/inputPlugins/audiofile_plugin.c @@ -85,10 +85,10 @@ static int audiofile_decode(char *path) fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1); { - int ret, eof = 0, current = 0; + int ret, current = 0; char chunk[CHUNK_SIZE]; - while (!eof) { + while (1) { if (dc_seek()) { dc_action_begin(); current = dc.seek_where * @@ -101,7 +101,7 @@ static int audiofile_decode(char *path) afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, CHUNK_SIZE / fs); if (ret <= 0) - eof = 1; + break; else { current += ret; ob_send(chunk, ret * fs, -- cgit v1.2.3 From 0ab398363a14eb5a59a374697fbac80264d10087 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:06 +0200 Subject: audiofile: remove one indent level from audiofile plugin Anonymous code blocks just to declare variables look ugly. Move the variable declarations up and disband the code block. --- src/inputPlugins/audiofile_plugin.c | 51 +++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c index d32a99857..fcebf562b 100644 --- a/src/inputPlugins/audiofile_plugin.c +++ b/src/inputPlugins/audiofile_plugin.c @@ -47,6 +47,8 @@ static int audiofile_decode(char *path) int bits; mpd_uint16 bitRate; struct stat st; + int ret, current = 0; + char chunk[CHUNK_SIZE]; if (stat(path, &st) < 0) { ERROR("failed to stat: %s\n", path); @@ -84,34 +86,29 @@ static int audiofile_decode(char *path) fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1); - { - int ret, current = 0; - char chunk[CHUNK_SIZE]; - - while (1) { - if (dc_seek()) { - dc_action_begin(); - current = dc.seek_where * - dc.audio_format.sampleRate; - afSeekFrame(af_fp, AF_DEFAULT_TRACK, current); - dc_action_end(); - } - - ret = - afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, - CHUNK_SIZE / fs); - if (ret <= 0) + while (1) { + if (dc_seek()) { + dc_action_begin(); + current = dc.seek_where * + dc.audio_format.sampleRate; + afSeekFrame(af_fp, AF_DEFAULT_TRACK, current); + dc_action_end(); + } + + ret = + afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, + CHUNK_SIZE / fs); + if (ret <= 0) + break; + else { + current += ret; + ob_send(chunk, ret * fs, + (float)current / + (float)dc.audio_format.sampleRate, + bitRate, + NULL); + if (dc_intr()) break; - else { - current += ret; - ob_send(chunk, ret * fs, - (float)current / - (float)dc.audio_format.sampleRate, - bitRate, - NULL); - if (dc_intr()) - break; - } } } afCloseFile(af_fp); -- cgit v1.2.3 From 554c708450dd5008c310902f67702b9727b944d3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:06 +0200 Subject: moved struct AudioFormat to audio_format.h We want to expose the AudioFormat structure to plugins; remove some clutter by moving its declaration to a separate header file. --- src/audio.h | 13 +------------ src/audioOutput.c | 1 + src/audioOutput.h | 2 +- src/audio_format.h | 35 +++++++++++++++++++++++++++++++++++ src/command.c | 1 + src/decode.h | 2 +- src/normalize.h | 2 +- src/pcm_utils.h | 2 +- src/replayGain.h | 2 +- src/timer.h | 4 ++-- 10 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 src/audio_format.h (limited to 'src') diff --git a/src/audio.h b/src/audio.h index eab83916a..c9dea54d2 100644 --- a/src/audio.h +++ b/src/audio.h @@ -19,23 +19,12 @@ #ifndef AUDIO_H #define AUDIO_H -#include "mpd_types.h" #include "tag.h" #include "os_compat.h" +#include "audio_format.h" #define AUDIO_AO_DRIVER_DEFAULT "default" -typedef struct _AudioFormat { - volatile mpd_sint8 channels; - volatile mpd_uint32 sampleRate; - volatile mpd_sint8 bits; -} AudioFormat; - -static inline double audioFormatSizeToTime(const AudioFormat * af) -{ - return 8.0 / af->bits / af->channels / af->sampleRate; -} - void copyAudioFormat(AudioFormat * dest, const AudioFormat * src); int cmpAudioFormat(const AudioFormat * dest, const AudioFormat * src); diff --git a/src/audioOutput.c b/src/audioOutput.c index ff5efabc9..24779a04d 100644 --- a/src/audioOutput.c +++ b/src/audioOutput.c @@ -22,6 +22,7 @@ #include "log.h" #include "pcm_utils.h" #include "os_compat.h" +#include "audio.h" #define AUDIO_OUTPUT_TYPE "type" #define AUDIO_OUTPUT_NAME "name" diff --git a/src/audioOutput.h b/src/audioOutput.h index 7574f5ae1..71c1e4b14 100644 --- a/src/audioOutput.h +++ b/src/audioOutput.h @@ -23,7 +23,7 @@ #include "pcm_utils.h" #include "mpd_types.h" -#include "audio.h" +#include "audio_format.h" #include "tag.h" #include "conf.h" #include "utils.h" diff --git a/src/audio_format.h b/src/audio_format.h new file mode 100644 index 000000000..ba22b3bf6 --- /dev/null +++ b/src/audio_format.h @@ -0,0 +1,35 @@ +/* the Music Player Daemon (MPD) + * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) + * This project's homepage is: http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef AUDIO_FORMAT_H +#define AUDIO_FORMAT_H + +#include "mpd_types.h" + +typedef struct _AudioFormat { + volatile mpd_sint8 channels; + volatile mpd_uint32 sampleRate; + volatile mpd_sint8 bits; +} AudioFormat; + +static inline double audioFormatSizeToTime(const AudioFormat * af) +{ + return 8.0 / af->bits / af->channels / af->sampleRate; +} + +#endif diff --git a/src/command.c b/src/command.c index abe0ab8b0..27e7f3408 100644 --- a/src/command.c +++ b/src/command.c @@ -31,6 +31,7 @@ #include "storedPlaylist.h" #include "sllist.h" #include "ack.h" +#include "audio.h" #include "os_compat.h" #include "player_error.h" #include "outputBuffer.h" diff --git a/src/decode.h b/src/decode.h index b1ba138e2..61eeee078 100644 --- a/src/decode.h +++ b/src/decode.h @@ -21,8 +21,8 @@ #include "song.h" -#include "audio.h" #include "condition.h" +#include "audio_format.h" #define DECODE_TYPE_FILE 0 #define DECODE_TYPE_URL 1 diff --git a/src/normalize.h b/src/normalize.h index 8356b2a7c..81c9c81c4 100644 --- a/src/normalize.h +++ b/src/normalize.h @@ -19,7 +19,7 @@ #ifndef NORMALIZE_H #define NORMALIZE_H -#include "audio.h" +#include "audio_format.h" extern int normalizationEnabled; diff --git a/src/pcm_utils.h b/src/pcm_utils.h index 53d268db7..2ecb56201 100644 --- a/src/pcm_utils.h +++ b/src/pcm_utils.h @@ -21,7 +21,7 @@ #include "../config.h" -#include "audio.h" +#include "audio_format.h" #include "os_compat.h" #ifdef HAVE_LIBSAMPLERATE diff --git a/src/replayGain.h b/src/replayGain.h index 8df6fb0b1..8282da785 100644 --- a/src/replayGain.h +++ b/src/replayGain.h @@ -20,7 +20,7 @@ #ifndef REPLAYGAIN_H #define REPLAYGAIN_H -#include "audio.h" +#include "audio_format.h" #define REPLAYGAIN_OFF 0 #define REPLAYGAIN_TRACK 1 diff --git a/src/timer.h b/src/timer.h index c8018e260..6851a1535 100644 --- a/src/timer.h +++ b/src/timer.h @@ -19,8 +19,8 @@ #ifndef MPD_TIMER_H #define MPD_TIMER_H -#include "audio.h" -#include "mpd_types.h" +#include "audio_format.h" +#include "os_compat.h" typedef struct _Timer { uint64_t time; -- cgit v1.2.3 From 29eba419627437fb6f20714bb553d39a58305c5e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:09 +0200 Subject: converted MpdTagItem.type to an enum Don't use CPP macros when you can use C enum... this also allows better type checking. --- src/audioOutputs/audioOutput_shout.c | 2 ++ src/dbUtils.c | 2 +- src/locate.c | 4 ++-- src/tag.c | 8 +++++--- src/tag.h | 34 ++++++++++++++++++---------------- 5 files changed, 28 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c index 9ed5b4e7e..49d69eebd 100644 --- a/src/audioOutputs/audioOutput_shout.c +++ b/src/audioOutputs/audioOutput_shout.c @@ -413,6 +413,8 @@ static void copyTagToVorbisComment(ShoutData * sd) case TAG_ITEM_TITLE: addTag(sd, "TITLE", sd->tag->items[i].value); break; + default: + break; } } } diff --git a/src/dbUtils.c b/src/dbUtils.c index 5d070e588..519c1802d 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -254,7 +254,7 @@ static void freeListCommandItem(ListCommandItem * item) free(item); } -static void visitTag(int fd, Song * song, int tagType) +static void visitTag(int fd, Song * song, enum tag_type tagType) { int i; MpdTag *tag = song->tag; diff --git a/src/locate.c b/src/locate.c index d97097f37..f68afdedb 100644 --- a/src/locate.c +++ b/src/locate.c @@ -121,7 +121,7 @@ void freeLocateTagItem(LocateTagItem * item) free(item); } -static int strstrSearchTag(Song * song, int type, char *str) +static int strstrSearchTag(Song * song, enum tag_type type, char *str) { int i; char *duplicate; @@ -169,7 +169,7 @@ int strstrSearchTags(Song * song, int numItems, LocateTagItem * items) return 1; } -static int tagItemFoundAndMatches(Song * song, int type, char *str) +static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str) { int i; diff --git a/src/tag.c b/src/tag.c index 5023a58cb..fc85a6ff9 100644 --- a/src/tag.c +++ b/src/tag.c @@ -606,7 +606,7 @@ static void deleteItem(MpdTag * tag, int idx) } } -void clearItemsFromMpdTag(MpdTag * tag, int type) +void clearItemsFromMpdTag(MpdTag * tag, enum tag_type type) { int i; @@ -697,7 +697,8 @@ int mpdTagsAreEqual(MpdTag * tag1, MpdTag * tag2) } \ } -static void appendToTagItems(MpdTag * tag, int type, char *value, int len) +static void appendToTagItems(MpdTag * tag, enum tag_type type, + char *value, int len) { int i = tag->numOfItems; char *duplicated = xmalloc(len + 1); @@ -717,7 +718,8 @@ static void appendToTagItems(MpdTag * tag, int type, char *value, int len) free(duplicated); } -void addItemToMpdTagWithLen(MpdTag * tag, int itemType, char *value, int len) +void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType, + char *value, int len) { if (ignoreTagItems[itemType]) { diff --git a/src/tag.h b/src/tag.h index 363ad98aa..99b32653c 100644 --- a/src/tag.h +++ b/src/tag.h @@ -27,24 +27,25 @@ #include #endif -#define TAG_ITEM_ARTIST 0 -#define TAG_ITEM_ALBUM 1 -#define TAG_ITEM_TITLE 2 -#define TAG_ITEM_TRACK 3 -#define TAG_ITEM_NAME 4 -#define TAG_ITEM_GENRE 5 -#define TAG_ITEM_DATE 6 -#define TAG_ITEM_COMPOSER 7 -#define TAG_ITEM_PERFORMER 8 -#define TAG_ITEM_COMMENT 9 -#define TAG_ITEM_DISC 10 - -#define TAG_NUM_OF_ITEM_TYPES 11 +enum tag_type { + TAG_ITEM_ARTIST, + TAG_ITEM_ALBUM, + TAG_ITEM_TITLE, + TAG_ITEM_TRACK, + TAG_ITEM_NAME, + TAG_ITEM_GENRE, + TAG_ITEM_DATE, + TAG_ITEM_COMPOSER, + TAG_ITEM_PERFORMER, + TAG_ITEM_COMMENT, + TAG_ITEM_DISC, + TAG_NUM_OF_ITEM_TYPES +}; extern const char *mpdTagItemKeys[]; typedef struct _MpdTagItem { - mpd_sint8 type; + enum tag_type type; char *value; } MpdTagItem; @@ -66,11 +67,12 @@ MpdTag *newMpdTag(void); void initTagConfig(void); -void clearItemsFromMpdTag(MpdTag * tag, int itemType); +void clearItemsFromMpdTag(MpdTag * tag, enum tag_type itemType); void freeMpdTag(MpdTag * tag); -void addItemToMpdTagWithLen(MpdTag * tag, int itemType, char *value, int len); +void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType, + char *value, int len); #define addItemToMpdTag(tag, itemType, value) \ addItemToMpdTagWithLen(tag, itemType, value, strlen(value)) -- cgit v1.2.3 From 43fc7747130702b7a2a02547f90bbcbddf42d32d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:09 +0200 Subject: added inline function audio_format_time_to_size() Make the code more readable by hiding big formulas in an inline function with a nice name. --- src/audio_format.h | 5 +++++ src/outputBuffer_xfade.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/audio_format.h b/src/audio_format.h index ba22b3bf6..a6e97e046 100644 --- a/src/audio_format.h +++ b/src/audio_format.h @@ -27,6 +27,11 @@ typedef struct _AudioFormat { volatile mpd_sint8 bits; } AudioFormat; +static inline double audio_format_time_to_size(const AudioFormat * af) +{ + return af->sampleRate * af->bits * af->channels / 8.0; +} + static inline double audioFormatSizeToTime(const AudioFormat * af) { return 8.0 / af->bits / af->channels / af->sampleRate; diff --git a/src/outputBuffer_xfade.h b/src/outputBuffer_xfade.h index 50fb062ce..70e490c65 100644 --- a/src/outputBuffer_xfade.h +++ b/src/outputBuffer_xfade.h @@ -29,7 +29,7 @@ static size_t calculate_xfade_chunks(struct rbvec vec[2]) assert(af->channels > 0); assert(af->sampleRate > 0); - chunks = af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE; + chunks = audio_format_time_to_size(af) / CHUNK_SIZE; chunks = chunks * (xfade_time + 0.5); assert(chunks); -- cgit v1.2.3 From 5cabe3399b7e1b47ad62b57815987742b424c5dc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: eliminate unused variables in the AAC decoder --- src/inputPlugins/aac_plugin.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 7cff31d40..400b43f28 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -93,9 +93,8 @@ static int adtsSampleRates[] = static int adtsParse(AacBuffer * b, float *length) { int frames, frameLength; - int tFrameLength = 0; int sampleRate = 0; - float framesPerSec, bytesPerFrame; + float framesPerSec; /* Read all frames to ensure correct time and bitrate */ for (frames = 0;; frames++) { @@ -118,8 +117,6 @@ static int adtsParse(AacBuffer * b, float *length) << 11) | (((unsigned int)b->buffer[4]) << 3) | (b->buffer[5] >> 5); - tFrameLength += frameLength; - if (frameLength > b->bytesIntoBuffer) break; @@ -129,10 +126,6 @@ static int adtsParse(AacBuffer * b, float *length) } framesPerSec = (float)sampleRate / 1024.0; - if (frames != 0) { - bytesPerFrame = (float)tFrameLength / (float)(frames * 1000); - } else - bytesPerFrame = 0; if (framesPerSec != 0) *length = (float)frames / framesPerSec; @@ -227,7 +220,6 @@ static float getAacFloatTotalTime(char *file) { AacBuffer b; float length; - size_t fileread, tagsize; faacDecHandle decoder; faacDecConfigurationPtr config; uint32_t sampleRate; @@ -238,7 +230,7 @@ static float getAacFloatTotalTime(char *file) if (openInputStream(&inStream, file) < 0) return -1; - initAacBuffer(&inStream, &b, &length, &fileread, &tagsize); + initAacBuffer(&inStream, &b, &length, NULL, NULL); if (length < 0) { decoder = faacDecOpen(); -- cgit v1.2.3 From c917b19a2afb6916daf5aa8ae73697c2528b2cf3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: removed unused initAacBuffer() parameters Since we eliminated the parameters retFileread and retTagsize in all callers, we can now safely remove it from the function prototype. --- src/inputPlugins/aac_plugin.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 400b43f28..f398a822d 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -132,8 +132,7 @@ static int adtsParse(AacBuffer * b, float *length) return 1; } -static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length, - size_t * retFileread, size_t * retTagsize) +static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) { size_t fileread; size_t bread; @@ -170,11 +169,6 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length, fillAacBuffer(b); } - if (retFileread) - *retFileread = fileread; - if (retTagsize) - *retTagsize = tagsize; - if (length == NULL) return; @@ -230,7 +224,7 @@ static float getAacFloatTotalTime(char *file) if (openInputStream(&inStream, file) < 0) return -1; - initAacBuffer(&inStream, &b, &length, NULL, NULL); + initAacBuffer(&inStream, &b, &length); if (length < 0) { decoder = faacDecOpen(); @@ -296,7 +290,7 @@ static int aac_decode(char *path) if (openInputStream(&inStream, path) < 0) return -1; - initAacBuffer(&inStream, &b, NULL, NULL, NULL); + initAacBuffer(&inStream, &b, NULL); decoder = faacDecOpen(); -- cgit v1.2.3 From d9ae11d885acdca92ce0f17cc455e891e88a0f77 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: use size_t --- src/inputPlugins/aac_plugin.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index f398a822d..1487a6c2f 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -30,9 +30,9 @@ /* all code here is either based on or copied from FAAD2's frontend code */ typedef struct { InputStream *inStream; - long bytesIntoBuffer; - long bytesConsumed; - long fileOffset; + size_t bytesIntoBuffer; + size_t bytesConsumed; + off_t fileOffset; unsigned char *buffer; int atEof; } AacBuffer; @@ -40,7 +40,7 @@ typedef struct { static void fillAacBuffer(AacBuffer * b) { if (b->bytesConsumed > 0) { - int bread; + size_t bread; if (b->bytesIntoBuffer) { memmove((void *)b->buffer, (void *)(b->buffer + @@ -78,7 +78,7 @@ static void fillAacBuffer(AacBuffer * b) } } -static void advanceAacBuffer(AacBuffer * b, int bytes) +static void advanceAacBuffer(AacBuffer * b, size_t bytes) { b->fileOffset += bytes; b->bytesConsumed = bytes; @@ -92,7 +92,7 @@ static int adtsSampleRates[] = static int adtsParse(AacBuffer * b, float *length) { - int frames, frameLength; + unsigned int frames, frameLength; int sampleRate = 0; float framesPerSec; -- cgit v1.2.3 From 15e76670b40a223ee58c5aae26b2d9540a1b87b8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: make adtsParse() void adtsParse() always returns 1, and its caller does not use the return value. --- src/inputPlugins/aac_plugin.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 1487a6c2f..353fafd40 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -90,7 +90,7 @@ static int adtsSampleRates[] = 16000, 12000, 11025, 8000, 7350, 0, 0, 0 }; -static int adtsParse(AacBuffer * b, float *length) +static void adtsParse(AacBuffer * b, float *length) { unsigned int frames, frameLength; int sampleRate = 0; @@ -128,8 +128,6 @@ static int adtsParse(AacBuffer * b, float *length) framesPerSec = (float)sampleRate / 1024.0; if (framesPerSec != 0) *length = (float)frames / framesPerSec; - - return 1; } static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) -- cgit v1.2.3 From d1015501dffd383b9ab9428303999615fde0fc66 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: simplified fillAacBuffer() Return instead of putting all the code into a if-closure. That saves one level of indentation. --- src/inputPlugins/aac_plugin.c | 58 +++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 353fafd40..de611b1ce 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -39,43 +39,35 @@ typedef struct { static void fillAacBuffer(AacBuffer * b) { - if (b->bytesConsumed > 0) { - size_t bread; - - if (b->bytesIntoBuffer) { - memmove((void *)b->buffer, (void *)(b->buffer + - b->bytesConsumed), - b->bytesIntoBuffer); - } + size_t bread; - if (!b->atEof) { - bread = readFromInputStream(b->inStream, - (void *)(b->buffer + - b-> - bytesIntoBuffer), - 1, b->bytesConsumed); - if (bread != b->bytesConsumed) - b->atEof = 1; - b->bytesIntoBuffer += bread; - } + if (b->bytesConsumed == 0) + return; - b->bytesConsumed = 0; + if (b->bytesIntoBuffer) { + memmove((void *)b->buffer, (void *)(b->buffer + + b->bytesConsumed), + b->bytesIntoBuffer); + } - if (b->bytesIntoBuffer > 3) { - if (memcmp(b->buffer, "TAG", 3) == 0) - b->bytesIntoBuffer = 0; - } - if (b->bytesIntoBuffer > 11) { - if (memcmp(b->buffer, "LYRICSBEGIN", 11) == 0) { - b->bytesIntoBuffer = 0; - } - } - if (b->bytesIntoBuffer > 8) { - if (memcmp(b->buffer, "APETAGEX", 8) == 0) { - b->bytesIntoBuffer = 0; - } - } + if (!b->atEof) { + bread = readFromInputStream(b->inStream, + (void *)(b->buffer + + b-> + bytesIntoBuffer), + 1, b->bytesConsumed); + if (bread != b->bytesConsumed) + b->atEof = 1; + b->bytesIntoBuffer += bread; } + + b->bytesConsumed = 0; + + if ((b->bytesIntoBuffer > 3 && memcmp(b->buffer, "TAG", 3) == 0) || + (b->bytesIntoBuffer > 11 && + memcmp(b->buffer, "LYRICSBEGIN", 11) == 0) || + (b->bytesIntoBuffer > 8 && memcmp(b->buffer, "APETAGEX", 8) == 0)) + b->bytesIntoBuffer = 0; } static void advanceAacBuffer(AacBuffer * b, size_t bytes) -- cgit v1.2.3 From 7b47338ca996f8fda1bd0f8c743555a25409c200 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: don't depend on consumed data in fillAacBuffer() Fill the AacBuffer even when nothing has been consumed yet. The function should not check for consumed data, but for free space at the end of the buffer. --- src/inputPlugins/aac_plugin.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index de611b1ce..15a7da0ef 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -41,28 +41,32 @@ static void fillAacBuffer(AacBuffer * b) { size_t bread; - if (b->bytesConsumed == 0) + if (b->bytesIntoBuffer >= FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS) + /* buffer already full */ return; - if (b->bytesIntoBuffer) { + if (b->bytesConsumed > 0 && b->bytesIntoBuffer > 0) { memmove((void *)b->buffer, (void *)(b->buffer + b->bytesConsumed), b->bytesIntoBuffer); } + b->bytesConsumed = 0; + if (!b->atEof) { + size_t rest = FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS - + b->bytesIntoBuffer; + bread = readFromInputStream(b->inStream, (void *)(b->buffer + b-> bytesIntoBuffer), - 1, b->bytesConsumed); - if (bread != b->bytesConsumed) + 1, rest); + if (bread != rest) b->atEof = 1; b->bytesIntoBuffer += bread; } - b->bytesConsumed = 0; - if ((b->bytesIntoBuffer > 3 && memcmp(b->buffer, "TAG", 3) == 0) || (b->bytesIntoBuffer > 11 && memcmp(b->buffer, "LYRICSBEGIN", 11) == 0) || -- cgit v1.2.3 From d39395f3cdd937fc38d794de8706c9bc4cb96bd2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: use inputStreamAtEOF() When checking for EOF, we should not check whether the read request has been fully satisified. The InputStream API does not guarantee that readFromInputStream() always fills the whole buffer, if EOF is not reached. Since there is the function inputStreamAtEOF() dedicated for this purpose, we should use it for EOF checking after readFromInputStream()==0. --- src/inputPlugins/aac_plugin.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 15a7da0ef..b6e7e3fe4 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -62,7 +62,7 @@ static void fillAacBuffer(AacBuffer * b) b-> bytesIntoBuffer), 1, rest); - if (bread != rest) + if (bread == 0 && inputStreamAtEOF(b->inStream)) b->atEof = 1; b->bytesIntoBuffer += bread; } @@ -150,7 +150,7 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) b->bytesConsumed = 0; b->fileOffset = 0; - if (bread != FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS) + if (bread == 0 && inputStreamAtEOF(inStream)) b->atEof = 1; tagsize = 0; @@ -173,10 +173,9 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) bread = readFromInputStream(b->inStream, b->buffer, 1, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); - if (bread != FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS) + if (bread == 0 && inputStreamAtEOF(inStream)) b->atEof = 1; - else - b->atEof = 0; + b->bytesIntoBuffer = bread; b->bytesConsumed = 0; b->fileOffset = tagsize; -- cgit v1.2.3 From c7e1a79a6b10f6714db31bb65d17db479b4a69d2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: moved code to aac_buffer_shift() Shifting from the buffer queue is a common operation, and should be provided as a separate function. Move code to aac_buffer_shift() and add a bunch of assertions. --- src/inputPlugins/aac_plugin.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index b6e7e3fe4..3d6c40fb6 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -37,6 +37,19 @@ typedef struct { int atEof; } AacBuffer; +static void aac_buffer_shift(AacBuffer * b, size_t length) +{ + assert(length >= b->bytesConsumed); + assert(length <= b->bytesConsumed + b->bytesIntoBuffer); + + memmove(b->buffer, b->buffer + length, + b->bytesConsumed + b->bytesIntoBuffer - length); + + length -= b->bytesConsumed; + b->bytesConsumed = 0; + b->bytesIntoBuffer -= length; +} + static void fillAacBuffer(AacBuffer * b) { size_t bread; @@ -45,13 +58,7 @@ static void fillAacBuffer(AacBuffer * b) /* buffer already full */ return; - if (b->bytesConsumed > 0 && b->bytesIntoBuffer > 0) { - memmove((void *)b->buffer, (void *)(b->buffer + - b->bytesConsumed), - b->bytesIntoBuffer); - } - - b->bytesConsumed = 0; + aac_buffer_shift(b, b->bytesConsumed); if (!b->atEof) { size_t rest = FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS - -- cgit v1.2.3 From 5afa07de0569e2993532b77581dd03ae04653591 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: moved code to adts_check_frame() adts_check_frame() checks whether the buffer head is an AAC frame, and returns the frame length. --- src/inputPlugins/aac_plugin.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 3d6c40fb6..82ebecafc 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -93,6 +93,24 @@ static int adtsSampleRates[] = 16000, 12000, 11025, 8000, 7350, 0, 0, 0 }; +/** + * Check whether the buffer head is an AAC frame, and return the frame + * length. Returns 0 if it is not a frame. + */ +static size_t adts_check_frame(AacBuffer * b) +{ + if (b->bytesIntoBuffer <= 7) + return 0; + + /* check syncword */ + if (!((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0))) + return 0; + + return (((unsigned int)b->buffer[3] & 0x3) << 11) | + (((unsigned int)b->buffer[4]) << 3) | + (b->buffer[5] >> 5); +} + static void adtsParse(AacBuffer * b, float *length) { unsigned int frames, frameLength; @@ -103,23 +121,14 @@ static void adtsParse(AacBuffer * b, float *length) for (frames = 0;; frames++) { fillAacBuffer(b); - if (b->bytesIntoBuffer > 7) { - /* check syncword */ - if (!((b->buffer[0] == 0xFF) && - ((b->buffer[1] & 0xF6) == 0xF0))) { - break; - } - + frameLength = adts_check_frame(b); + if (frameLength > 0) { if (frames == 0) { sampleRate = adtsSampleRates[(b-> buffer[2] & 0x3c) >> 2]; } - frameLength = ((((unsigned int)b->buffer[3] & 0x3)) - << 11) | (((unsigned int)b->buffer[4]) - << 3) | (b->buffer[5] >> 5); - if (frameLength > b->bytesIntoBuffer) break; -- cgit v1.2.3 From 0db89f3e2cc7375273e32f77628ca0583d7a7026 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: find AAC frames Find AAC frames in the input and skip invalid data. This prepares AAC streaming. --- src/inputPlugins/aac_plugin.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 82ebecafc..f6f731332 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -111,6 +111,40 @@ static size_t adts_check_frame(AacBuffer * b) (b->buffer[5] >> 5); } +/** + * Find the next AAC frame in the buffer. Returns 0 if no frame is + * found or if not enough data is available. + */ +static size_t adts_find_frame(AacBuffer * b) +{ + const unsigned char *p; + size_t frame_length; + + while ((p = memchr(b->buffer, 0xff, b->bytesIntoBuffer)) != NULL) { + /* discard data before 0xff */ + if (p > b->buffer) + aac_buffer_shift(b, p - b->buffer); + + if (b->bytesIntoBuffer <= 7) + /* not enough data yet */ + return 0; + + /* is it a frame? */ + frame_length = adts_check_frame(b); + if (frame_length > 0) + /* yes, it is */ + return frame_length; + + /* it's just some random 0xff byte; discard and and + continue searching */ + aac_buffer_shift(b, 1); + } + + /* nothing at all; discard the whole buffer */ + aac_buffer_shift(b, b->bytesIntoBuffer); + return 0; +} + static void adtsParse(AacBuffer * b, float *length) { unsigned int frames, frameLength; @@ -121,7 +155,7 @@ static void adtsParse(AacBuffer * b, float *length) for (frames = 0;; frames++) { fillAacBuffer(b); - frameLength = adts_check_frame(b); + frameLength = adts_find_frame(b); if (frameLength > 0) { if (frames == 0) { sampleRate = adtsSampleRates[(b-> -- cgit v1.2.3 From 20755291951a9cb9e21afba763a80015229e7655 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: use fillAacBuffer() instead of manual reading Eliminate some duplicated code by using fillAacBuffer(). --- src/inputPlugins/aac_plugin.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index f6f731332..e9eccf31a 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -179,7 +179,6 @@ static void adtsParse(AacBuffer * b, float *length) static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) { size_t fileread; - size_t bread; size_t tagsize; if (length) @@ -194,14 +193,7 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) b->buffer = xmalloc(FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); memset(b->buffer, 0, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); - bread = readFromInputStream(inStream, b->buffer, 1, - FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); - b->bytesIntoBuffer = bread; - b->bytesConsumed = 0; - b->fileOffset = 0; - - if (bread == 0 && inputStreamAtEOF(inStream)) - b->atEof = 1; + fillAacBuffer(b); tagsize = 0; if (!memcmp(b->buffer, "ID3", 3)) { @@ -220,15 +212,11 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) adtsParse(b, length); seekInputStream(b->inStream, tagsize, SEEK_SET); - bread = readFromInputStream(b->inStream, b->buffer, 1, - FAAD_MIN_STREAMSIZE * - AAC_MAX_CHANNELS); - if (bread == 0 && inputStreamAtEOF(inStream)) - b->atEof = 1; - - b->bytesIntoBuffer = bread; + b->bytesIntoBuffer = 0; b->bytesConsumed = 0; b->fileOffset = tagsize; + + fillAacBuffer(b); } else if (memcmp(b->buffer, "ADIF", 4) == 0) { int bitRate; int skipSize = (b->buffer[4] & 0x80) ? 9 : 0; -- cgit v1.2.3 From ca5eaffc16b9ace0ea7af519ef949bf014f42120 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: check buffer lengths The AAC plugin sometimes does not check the length of available data when checking for magic prefixes. Add length checks. --- src/inputPlugins/aac_plugin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index e9eccf31a..faddb78c6 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -196,7 +196,7 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) fillAacBuffer(b); tagsize = 0; - if (!memcmp(b->buffer, "ID3", 3)) { + if (b->bytesIntoBuffer >= 10 && !memcmp(b->buffer, "ID3", 3)) { tagsize = (b->buffer[6] << 21) | (b->buffer[7] << 14) | (b->buffer[8] << 7) | (b->buffer[9] << 0); @@ -208,7 +208,8 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) if (length == NULL) return; - if ((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) { + if (b->bytesIntoBuffer >= 2 && + (b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) { adtsParse(b, length); seekInputStream(b->inStream, tagsize, SEEK_SET); -- cgit v1.2.3 From 4c8ae1ffa7e9c0b4fdd2247ea1cc851691386f14 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: splitted aac_parse_header() from initAacBuffer() initAacBuffer() should really only initialize the buffer; currently, it also reads data from the input stream and parses the header. All of the AAC buffer code should probably be moved to a separate library anyway. --- src/inputPlugins/aac_plugin.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index faddb78c6..26e55aa57 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -176,22 +176,25 @@ static void adtsParse(AacBuffer * b, float *length) *length = (float)frames / framesPerSec; } -static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) +static void initAacBuffer(InputStream * inStream, AacBuffer * b) { - size_t fileread; - size_t tagsize; - - if (length) - *length = -1; - memset(b, 0, sizeof(AacBuffer)); b->inStream = inStream; - fileread = inStream->size; - b->buffer = xmalloc(FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); memset(b->buffer, 0, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); +} + +static void aac_parse_header(AacBuffer * b, float *length) +{ + size_t fileread; + size_t tagsize; + + if (length) + *length = -1; + + fileread = b->inStream->size; fillAacBuffer(b); @@ -256,7 +259,8 @@ static float getAacFloatTotalTime(char *file) if (openInputStream(&inStream, file) < 0) return -1; - initAacBuffer(&inStream, &b, &length); + initAacBuffer(&inStream, &b); + aac_parse_header(&b, &length); if (length < 0) { decoder = faacDecOpen(); @@ -322,7 +326,8 @@ static int aac_decode(char *path) if (openInputStream(&inStream, path) < 0) return -1; - initAacBuffer(&inStream, &b, NULL); + initAacBuffer(&inStream, &b); + aac_parse_header(&b, NULL); decoder = faacDecOpen(); -- cgit v1.2.3 From 6fb3490015d6d0c3433e259cb2099d4bb9e58b7f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: support decoding AAC streams Copy some code from aac_decode() to aac_stream_decode() and apply necessary changes to allow streaming audio data. Both functions might be merged later. --- src/inputPlugins/aac_plugin.c | 130 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 26e55aa57..512e73e53 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -300,6 +300,132 @@ static int getAacTotalTime(char *file) return file_time; } +static int aac_stream_decode(InputStream *inStream) +{ + float file_time; + float totalTime = 0; + faacDecHandle decoder; + faacDecFrameInfo frameInfo; + faacDecConfigurationPtr config; + long bread; + uint32_t sampleRate; + unsigned char channels; + unsigned int sampleCount; + char *sampleBuffer; + size_t sampleBufferLen; + mpd_uint16 bitRate = 0; + AacBuffer b; + + initAacBuffer(inStream, &b); + aac_parse_header(&b, NULL); + + decoder = faacDecOpen(); + + config = faacDecGetCurrentConfiguration(decoder); + config->outputFormat = FAAD_FMT_16BIT; +#ifdef HAVE_FAACDECCONFIGURATION_DOWNMATRIX + config->downMatrix = 1; +#endif +#ifdef HAVE_FAACDECCONFIGURATION_DONTUPSAMPLEIMPLICITSBR + config->dontUpSampleImplicitSBR = 0; +#endif + faacDecSetConfiguration(decoder, config); + + while (b.bytesIntoBuffer < FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS && + !b.atEof && !dc_intr()) { + fillAacBuffer(&b); + adts_find_frame(&b); + fillAacBuffer(&b); + } + +#ifdef HAVE_FAAD_BUFLEN_FUNCS + bread = faacDecInit(decoder, b.buffer, b.bytesIntoBuffer, + &sampleRate, &channels); +#else + bread = faacDecInit(decoder, b.buffer, &sampleRate, &channels); +#endif + if (bread < 0) { + ERROR("Error not a AAC stream.\n"); + faacDecClose(decoder); + if (b.buffer) + free(b.buffer); + return -1; + } + + dc.audio_format.bits = 16; + dc.total_time = totalTime; + + file_time = 0.0; + + advanceAacBuffer(&b, bread); + + while (1) { + fillAacBuffer(&b); + adts_find_frame(&b); + fillAacBuffer(&b); + + if (b.bytesIntoBuffer == 0) + break; + +#ifdef HAVE_FAAD_BUFLEN_FUNCS + sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer, + b.bytesIntoBuffer); +#else + sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer); +#endif + + if (frameInfo.error > 0) { + ERROR("error decoding AAC stream\n"); + ERROR("faad2 error: %s\n", + faacDecGetErrorMessage(frameInfo.error)); + break; + } +#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE + sampleRate = frameInfo.samplerate; +#endif + + dc.audio_format.channels = frameInfo.channels; + dc.audio_format.sampleRate = sampleRate; + + advanceAacBuffer(&b, frameInfo.bytesconsumed); + + sampleCount = (unsigned long)(frameInfo.samples); + + if (sampleCount > 0) { + bitRate = frameInfo.bytesconsumed * 8.0 * + frameInfo.channels * sampleRate / + frameInfo.samples / 1000 + 0.5; + file_time += + (float)(frameInfo.samples) / frameInfo.channels / + sampleRate; + } + + sampleBufferLen = sampleCount * 2; + + switch (ob_send(sampleBuffer, sampleBufferLen, + file_time, bitRate, NULL)) { + case DC_ACTION_NONE: break; + case DC_ACTION_SEEK: + /* + * this plugin doesn't support seek because nobody + * has bothered, yet... + */ + dc_action_seek_fail(DC_SEEK_ERROR); + break; + default: goto out; + } + } +out: + + faacDecClose(decoder); + if (b.buffer) + free(b.buffer); + + return 0; +} + + + static int aac_decode(char *path) { float file_time; @@ -452,10 +578,10 @@ InputPlugin aacPlugin = { NULL, NULL, NULL, - NULL, + aac_stream_decode, aac_decode, aacTagDup, - INPUT_PLUGIN_STREAM_FILE, + INPUT_PLUGIN_STREAM_FILE | INPUT_PLUGIN_STREAM_URL, aac_suffixes, aac_mimeTypes }; -- cgit v1.2.3 From 6489019322e07411a0c9552644d8ddb62961d0eb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: assert song->url != NULL --- src/song.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/song.c b/src/song.c index a8ab4284f..cc1547d10 100644 --- a/src/song.c +++ b/src/song.c @@ -315,6 +315,9 @@ char *get_song_url(char *path_max_tmp, Song *song) { if (!song) return NULL; + + assert(song->url != NULL); + if (!song->parentDir || !song->parentDir->path) strcpy(path_max_tmp, song->url); else -- cgit v1.2.3 From a7eebfdd0e84653e2a005b47f4091c263c0bbd99 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: don't check dropSamplesAtStart in the loop Performance improvement by moving stuff out of a loop: skip part of the first frame before entering the loop. --- src/inputPlugins/mp3_plugin.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 684655f97..11d543199 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -921,15 +921,24 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) samplesLeft = (data->synth).pcm.length; - for (i = 0; i < (data->synth).pcm.length; i++) { + if (!data->decodedFirstFrame) { + if (data->dropSamplesAtStart >= samplesLeft) { + i = samplesLeft; + samplesLeft = 0; + } else { + i = data->dropSamplesAtStart; + samplesLeft -= data->dropSamplesAtStart; + } + data->decodedFirstFrame = 1; + } else + i = 0; + + for (; i < (data->synth).pcm.length; i++) { mpd_sint16 *sample; samplesLeft--; - if (!data->decodedFirstFrame && - (i < data->dropSamplesAtStart)) { - continue; - } else if (data->dropSamplesAtEnd && + if (data->dropSamplesAtEnd && (data->currentFrame == (data->maxFrames - data->dropFramesAtEnd)) && (samplesLeft < data->dropSamplesAtEnd)) { /* stop decoding, effectively dropping @@ -972,8 +981,6 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) } } - data->decodedFirstFrame = 1; - if (dc_seek()) { if (data->inStream->seekable) mp3Read_seek(data); -- cgit v1.2.3 From 34b5a1c80be51698acc7ac22a3480097ca33e7ad Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: moved code to dither_buffer() Preparing for simplifying and thus speeding up the dithering code: moved dithering to a separate function which contains a trivial loop. With this patch, only one sample is dithered at a time, but the following patches will allow us to dither a whole block at a time, without complicated buffer length checks. --- src/inputPlugins/mp3_plugin.c | 44 +++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 11d543199..87c8d6ea9 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -105,6 +105,30 @@ static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample, return output >> scalebits; } +static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth, + struct audio_dither *dither, + unsigned int start, unsigned int end, + unsigned int num_channels) +{ + mpd_sint16 *dest = dest0; + unsigned int i; + + for (i = start; i < end; ++i) { + *dest++ = (mpd_sint16) + audio_linear_dither(16, + synth->pcm.samples[0][i], + dither); + + if (num_channels == 2) + *dest++ = (mpd_sint16) + audio_linear_dither(16, + synth->pcm.samples[1][i], + dither); + } + + return dest - dest0; +} + /* end of stolen stuff from mpg321 */ static int mp3_plugin_init(void) @@ -934,7 +958,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) i = 0; for (; i < (data->synth).pcm.length; i++) { - mpd_sint16 *sample; + unsigned int num_samples; samplesLeft--; @@ -946,19 +970,11 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) return DECODE_BREAK; } - sample = (mpd_sint16 *) data->outputPtr; - *sample = (mpd_sint16) audio_linear_dither(16, - (data->synth).pcm.samples[0][i], - &(data->dither)); - data->outputPtr += 2; - - if (MAD_NCHANNELS(&(data->frame).header) == 2) { - sample = (mpd_sint16 *) data->outputPtr; - *sample = (mpd_sint16) audio_linear_dither(16, - (data->synth).pcm.samples[1][i], - &(data->dither)); - data->outputPtr += 2; - } + num_samples = dither_buffer((mpd_sint16 *) data->outputPtr, + &data->synth, &data->dither, + i, i + 1, + MAD_NCHANNELS(&(data->frame).header)); + data->outputPtr += 2 * num_samples; if (data->outputPtr >= data->outputBufferEnd) { enum dc_action action = ob_send( -- cgit v1.2.3 From 70bf8cfa27ed88bd01ace37949599ef5680aa6c5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: unsigned integers --- src/inputPlugins/mp3_plugin.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 87c8d6ea9..000a4c688 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -158,13 +158,13 @@ typedef struct _mp3DecodeData { int muteFrame; long *frameOffset; mad_timer_t *times; - long highestFrame; - long maxFrames; - long currentFrame; - int dropFramesAtStart; - int dropFramesAtEnd; - int dropSamplesAtStart; - int dropSamplesAtEnd; + unsigned long highestFrame; + unsigned long maxFrames; + unsigned long currentFrame; + unsigned int dropFramesAtStart; + unsigned int dropFramesAtEnd; + unsigned int dropSamplesAtStart; + unsigned int dropSamplesAtEnd; int foundXing; int foundFirstFrame; int decodedFirstFrame; @@ -838,7 +838,7 @@ static float frame_time(mp3DecodeData * data, long j) static void mp3Read_seek(mp3DecodeData * data) { - long j = 0; + unsigned long j = 0; data->muteFrame = MUTEFRAME_SEEK; assert(pthread_equal(pthread_self(), dc.thread)); @@ -861,9 +861,9 @@ static void mp3Read_seek(mp3DecodeData * data) static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { - int samplesPerFrame; - int samplesLeft; - int i; + unsigned int samplesPerFrame; + unsigned int samplesLeft; + unsigned int i; int ret; int skip; -- cgit v1.2.3 From 173b3cc28d40f7555d0f7dbf1cc8823f81762fdb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: make samplesPerFrame more local The variable samplesPerFrame is used only in one single closure. Make it local to this closure. The compiler will probably convert it to a register anyway. --- src/inputPlugins/mp3_plugin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 000a4c688..8213dbc0b 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -861,7 +861,6 @@ static void mp3Read_seek(mp3DecodeData * data) static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { - unsigned int samplesPerFrame; unsigned int samplesLeft; unsigned int i; int ret; @@ -911,7 +910,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) mad_synth_frame(&data->synth, &data->frame); if (!data->foundFirstFrame) { - samplesPerFrame = (data->synth).pcm.length; + unsigned int samplesPerFrame = (data->synth).pcm.length; data->dropFramesAtStart = data->dropSamplesAtStart / samplesPerFrame; data->dropFramesAtEnd = data->dropSamplesAtEnd / samplesPerFrame; data->dropSamplesAtStart = data->dropSamplesAtStart % samplesPerFrame; -- cgit v1.2.3 From fdad7dc9df25ba74d8a4c4d9fab7a25e3e0ef3ca Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: moved dropSamplesAtEnd check out of the loop Simplifying loops for performance: why check dropSamplesAtEnd in every iteration, when we could modify the loop boundary? The (writable) variable samplesLeft can be eliminated; add a write-once variable pcm_length instead, which is used for the loop condition. --- src/inputPlugins/mp3_plugin.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 8213dbc0b..9c4925dfa 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -861,7 +861,7 @@ static void mp3Read_seek(mp3DecodeData * data) static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { - unsigned int samplesLeft; + unsigned int pcm_length; unsigned int i; int ret; int skip; @@ -942,32 +942,23 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) metadata_pipe_send(tag, data->elapsedTime); } - samplesLeft = (data->synth).pcm.length; - if (!data->decodedFirstFrame) { - if (data->dropSamplesAtStart >= samplesLeft) { - i = samplesLeft; - samplesLeft = 0; - } else { - i = data->dropSamplesAtStart; - samplesLeft -= data->dropSamplesAtStart; - } + i = data->dropSamplesAtStart; data->decodedFirstFrame = 1; } else i = 0; - for (; i < (data->synth).pcm.length; i++) { - unsigned int num_samples; - - samplesLeft--; + pcm_length = data->synth.pcm.length; + if (data->dropSamplesAtEnd && + (data->currentFrame == data->maxFrames - data->dropFramesAtEnd)) { + if (data->dropSamplesAtEnd >= pcm_length) + pcm_length = 0; + else + pcm_length -= data->dropSamplesAtEnd; + } - if (data->dropSamplesAtEnd && - (data->currentFrame == (data->maxFrames - data->dropFramesAtEnd)) && - (samplesLeft < data->dropSamplesAtEnd)) { - /* stop decoding, effectively dropping - * all remaining samples */ - return DECODE_BREAK; - } + for (; i < pcm_length; i++) { + unsigned int num_samples; num_samples = dither_buffer((mpd_sint16 *) data->outputPtr, &data->synth, &data->dither, @@ -996,6 +987,13 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) } } + if (data->dropSamplesAtEnd && + (data->currentFrame == + (data->maxFrames - data->dropFramesAtEnd))) + /* stop decoding, effectively dropping + * all remaining samples */ + return DECODE_BREAK; + if (dc_seek()) { if (data->inStream->seekable) mp3Read_seek(data); -- cgit v1.2.3 From 33b39572ddff251333d92e174d304adb6b2d3b83 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: dither a whole block at a time Fill the whole output buffer at a time by using dither_buffer()'s ability to decode blocks. Calculate how many samples fit into the output buffer before each invocation. --- src/inputPlugins/mp3_plugin.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 9c4925dfa..2bdff4bd4 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -957,12 +957,18 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) pcm_length -= data->dropSamplesAtEnd; } - for (; i < pcm_length; i++) { - unsigned int num_samples; + while (i < pcm_length) { + unsigned int num_samples = + (data->outputBufferEnd - data->outputPtr) / + (2 * MAD_NCHANNELS(&(data->frame).header)); + if (num_samples > pcm_length - i) + num_samples = pcm_length - i; + + i += num_samples; num_samples = dither_buffer((mpd_sint16 *) data->outputPtr, &data->synth, &data->dither, - i, i + 1, + i - num_samples, i, MAD_NCHANNELS(&(data->frame).header)); data->outputPtr += 2 * num_samples; -- cgit v1.2.3 From b40e8194e8e7ff816ca225ddedf5b546c8ecae96 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: always flush directly after decoding/dithering Since we try to fill the buffer in every iteration, we assume that we should flush the output buffer at the end of each iteration. --- src/inputPlugins/mp3_plugin.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 2bdff4bd4..c9de49290 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -958,6 +958,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) } while (i < pcm_length) { + enum dc_action action; unsigned int num_samples = (data->outputBufferEnd - data->outputPtr) / (2 * MAD_NCHANNELS(&(data->frame).header)); @@ -972,25 +973,20 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) MAD_NCHANNELS(&(data->frame).header)); data->outputPtr += 2 * num_samples; - if (data->outputPtr >= data->outputBufferEnd) { - enum dc_action action = ob_send( - data->outputBuffer, - data->outputPtr - - data->outputBuffer, - data->elapsedTime, - data->bitRate / 1000, - replayGainInfo ? *replayGainInfo - : NULL); - - if (action == DC_ACTION_STOP) { - data->flush = 0; - return DECODE_BREAK; - } - data->outputPtr = data->outputBuffer; + action = ob_send(data->outputBuffer, + data->outputPtr - data->outputBuffer, + data->elapsedTime, + data->bitRate / 1000, + replayGainInfo ? *replayGainInfo : NULL); - if (action == DC_ACTION_SEEK) - break; + if (action == DC_ACTION_STOP) { + data->flush = 0; + return DECODE_BREAK; } + data->outputPtr = data->outputBuffer; + + if (action == DC_ACTION_SEEK) + break; } if (data->dropSamplesAtEnd && -- cgit v1.2.3 From c9c9a7c7742afa59990cd1a3f1d52d2ab8c486d1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: don't do a second flush in mp3_decode() The previous patch made mp3Read() flush the output buffer in every iteration, which means we can eliminate the flush check after invoking mp3Read(). --- src/inputPlugins/mp3_plugin.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index c9de49290..5e217c6ee 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -168,7 +168,6 @@ typedef struct _mp3DecodeData { int foundXing; int foundFirstFrame; int decodedFirstFrame; - int flush; unsigned long bitRate; InputStream *inStream; struct audio_dither dither; @@ -193,7 +192,6 @@ static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream) data->foundXing = 0; data->foundFirstFrame = 0; data->decodedFirstFrame = 0; - data->flush = 1; data->inStream = inStream; data->layer = 0; memset(&(data->dither), 0, sizeof(struct audio_dither)); @@ -419,7 +417,6 @@ static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, ERROR("unrecoverable frame level error " "(%s).\n", mad_stream_errorstr(&data->stream)); - data->flush = 0; return DECODE_BREAK; } } @@ -472,7 +469,6 @@ static int decodeNextFrame(mp3DecodeData * data) ERROR("unrecoverable frame level error " "(%s).\n", mad_stream_errorstr(&data->stream)); - data->flush = 0; return DECODE_BREAK; } } @@ -979,10 +975,8 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) data->bitRate / 1000, replayGainInfo ? *replayGainInfo : NULL); - if (action == DC_ACTION_STOP) { - data->flush = 0; + if (action == DC_ACTION_STOP) return DECODE_BREAK; - } data->outputPtr = data->outputBuffer; if (action == DC_ACTION_SEEK) @@ -1082,11 +1076,6 @@ static int mp3_decode(InputStream * inStream) metadata_pipe_send(tag, 0); while (mp3Read(&data, &replayGainInfo) != DECODE_BREAK) ; - /* send last little bit if not dc_intr() */ - if (!dc_intr() && data.outputPtr != data.outputBuffer && data.flush) { - ob_send(data.outputBuffer, data.outputPtr - data.outputBuffer, - data.elapsedTime, data.bitRate / 1000, replayGainInfo); - } if (replayGainInfo) freeReplayGainInfo(replayGainInfo); -- cgit v1.2.3 From 66ecc1901ad51a1c8a54064fd5ac33454a7cd4b2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: eliminated outputPtr The output buffer is always flushed after being appended to, which allows us to assume it is always empty. Always start writing at outputBuffer, don't remember outputPtr. --- src/inputPlugins/mp3_plugin.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 5e217c6ee..16770e63f 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -151,8 +151,6 @@ typedef struct _mp3DecodeData { mad_timer_t timer; unsigned char readBuffer[READ_BUFFER_SIZE]; char outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE]; - char *outputPtr; - char *outputBufferEnd; float totalTime; float elapsedTime; int muteFrame; @@ -176,9 +174,6 @@ typedef struct _mp3DecodeData { static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream) { - data->outputPtr = data->outputBuffer; - data->outputBufferEnd = - data->outputBuffer + MP3_DATA_OUTPUT_BUFFER_SIZE; data->muteFrame = 0; data->highestFrame = 0; data->maxFrames = 0; @@ -844,12 +839,10 @@ static void mp3Read_seek(mp3DecodeData * data) j++; if (j < data->highestFrame) { dc_action_begin(); - if (seekMp3InputBuffer(data, data->frameOffset[j]) < 0) { + if (seekMp3InputBuffer(data, data->frameOffset[j]) < 0) dc.seek_where = DC_SEEK_ERROR; - } else { - data->outputPtr = data->outputBuffer; + else data->currentFrame = j; - } data->muteFrame = 0; dc_action_end(); } @@ -897,7 +890,6 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) if (dc.seek_where <= data->elapsedTime) { dc_action_begin(); assert(dc.action == DC_ACTION_SEEK); - data->outputPtr = data->outputBuffer; data->muteFrame = 0; dc_action_end(); } @@ -955,29 +947,29 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) while (i < pcm_length) { enum dc_action action; - unsigned int num_samples = - (data->outputBufferEnd - data->outputPtr) / + unsigned int num_samples = sizeof(data->outputBuffer) / (2 * MAD_NCHANNELS(&(data->frame).header)); + if (num_samples > pcm_length - i) num_samples = pcm_length - i; i += num_samples; - num_samples = dither_buffer((mpd_sint16 *) data->outputPtr, + num_samples = dither_buffer((mpd_sint16 *) + data->outputBuffer, &data->synth, &data->dither, i - num_samples, i, - MAD_NCHANNELS(&(data->frame).header)); - data->outputPtr += 2 * num_samples; + MAD_NCHANNELS( + &(data->frame).header)); action = ob_send(data->outputBuffer, - data->outputPtr - data->outputBuffer, + 2 * num_samples, data->elapsedTime, data->bitRate / 1000, replayGainInfo ? *replayGainInfo : NULL); if (action == DC_ACTION_STOP) return DECODE_BREAK; - data->outputPtr = data->outputBuffer; if (action == DC_ACTION_SEEK) break; -- cgit v1.2.3 From 6bb58f41a999fba23a758c072c8c1fd87cf209d3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: moved num_samples calculation out of the loop The previous patch removed all loop specific dependencies from the num_samples formula; we can now calculate it before entering the loop. --- src/inputPlugins/mp3_plugin.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 16770e63f..40a2b9c73 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -850,7 +850,7 @@ static void mp3Read_seek(mp3DecodeData * data) static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { - unsigned int pcm_length; + unsigned int pcm_length, max_samples; unsigned int i; int ret; int skip; @@ -945,14 +945,15 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) pcm_length -= data->dropSamplesAtEnd; } + max_samples = sizeof(data->outputBuffer) / + (2 * MAD_NCHANNELS(&(data->frame).header)); + while (i < pcm_length) { enum dc_action action; - unsigned int num_samples = sizeof(data->outputBuffer) / - (2 * MAD_NCHANNELS(&(data->frame).header)); - - if (num_samples > pcm_length - i) - num_samples = pcm_length - i; + unsigned int num_samples = pcm_length - i; + if (num_samples > max_samples) + num_samples = max_samples; i += num_samples; num_samples = dither_buffer((mpd_sint16 *) -- cgit v1.2.3 From f4f318fcffe454b4c74bb66a674b016f9ac501f3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: changed outputBuffer's type to mpd_sint16[] The output buffer always contains mpd_sint16; declaring it with that type saves several casts. --- src/inputPlugins/mp3_plugin.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 40a2b9c73..46b0a875c 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -142,7 +142,7 @@ static int mp3_plugin_init(void) /* decoder stuff is based on madlld */ -#define MP3_DATA_OUTPUT_BUFFER_SIZE 4096 +#define MP3_DATA_OUTPUT_BUFFER_SIZE 2048 typedef struct _mp3DecodeData { struct mad_stream stream; @@ -150,7 +150,7 @@ typedef struct _mp3DecodeData { struct mad_synth synth; mad_timer_t timer; unsigned char readBuffer[READ_BUFFER_SIZE]; - char outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE]; + mpd_sint16 outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE]; float totalTime; float elapsedTime; int muteFrame; @@ -956,8 +956,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) num_samples = max_samples; i += num_samples; - num_samples = dither_buffer((mpd_sint16 *) - data->outputBuffer, + num_samples = dither_buffer(data->outputBuffer, &data->synth, &data->dither, i - num_samples, i, MAD_NCHANNELS( -- cgit v1.2.3 From dcd1a83a07d918f1fc69d2062a6be9f1aa396659 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: audio_linear_dither() returns mpd_sint16 The return value of audio_linear_dither() is always casted to mpd_sint16. Returning long does not make sense, and consumed 8 bytes on a 64 bit platform. --- src/inputPlugins/mp3_plugin.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 46b0a875c..a39b0d128 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -60,8 +60,8 @@ static unsigned long prng(unsigned long state) return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL; } -static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample, - struct audio_dither *dither) +static mpd_sint16 audio_linear_dither(unsigned int bits, mad_fixed_t sample, + struct audio_dither *dither) { unsigned int scalebits; mad_fixed_t output, mask, rnd; @@ -102,7 +102,7 @@ static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample, dither->error[0] = sample - output; - return output >> scalebits; + return (mpd_sint16)(output >> scalebits); } static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth, @@ -114,16 +114,14 @@ static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth, unsigned int i; for (i = start; i < end; ++i) { - *dest++ = (mpd_sint16) - audio_linear_dither(16, - synth->pcm.samples[0][i], - dither); + *dest++ = audio_linear_dither(16, + synth->pcm.samples[0][i], + dither); if (num_channels == 2) - *dest++ = (mpd_sint16) - audio_linear_dither(16, - synth->pcm.samples[1][i], - dither); + *dest++ = audio_linear_dither(16, + synth->pcm.samples[1][i], + dither); } return dest - dest0; -- cgit v1.2.3 From 5136928aef27ae6e81ef56b7f005e04455d35c2f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: oggvorbis: don't detect OGG header if stream is not seekable If the input stream is not seekable, the try_decode() function consumes valuable data, which is not available to the decode() function anymore. This means that the decode() function does not parse the header correctly. Better skip the detection if we cannot seek. Or implement better buffering, something like unread() or buffered rewind(). --- src/inputPlugins/oggflac_plugin.c | 5 +++++ src/inputPlugins/oggvorbis_plugin.c | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c index 87444d261..d3016c9a2 100644 --- a/src/inputPlugins/oggflac_plugin.c +++ b/src/inputPlugins/oggflac_plugin.c @@ -327,6 +327,11 @@ static MpdTag *oggflac_TagDup(char *file) static unsigned int oggflac_try_decode(InputStream * inStream) { + if (!inStream->seekable) + /* we cannot seek after the detection, so don't bother + checking */ + return 1; + return (ogg_stream_type_detect(inStream) == FLAC) ? 1 : 0; } diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index 7612b1db5..a28bbc737 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -362,6 +362,11 @@ static MpdTag *oggvorbis_TagDup(char *file) static unsigned int oggvorbis_try_decode(InputStream * inStream) { + if (!inStream->seekable) + /* we cannot seek after the detection, so don't bother + checking */ + return 1; + return (ogg_stream_type_detect(inStream) == VORBIS) ? 1 : 0; } -- cgit v1.2.3 From d855b25b96aba8ca883e886ad229e83c0b31005c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: simplified code in the ogg decoder plugin Return early when the player thread sent us a command. This saves one level of indentation. --- src/inputPlugins/oggvorbis_plugin.c | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index a28bbc737..75c52dab4 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -240,32 +240,32 @@ static int oggvorbis_decode(InputStream * inStream) callbacks.close_func = ogg_close_cb; callbacks.tell_func = ogg_tell_cb; if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) { - if (!dc_intr()) { - switch (ret) { - case OV_EREAD: - errorStr = "read error"; - break; - case OV_ENOTVORBIS: - errorStr = "not vorbis stream"; - break; - case OV_EVERSION: - errorStr = "vorbis version mismatch"; - break; - case OV_EBADHEADER: - errorStr = "invalid vorbis header"; - break; - case OV_EFAULT: - errorStr = "internal logic error"; - break; - default: - errorStr = "unknown error"; - break; - } - ERROR("Error decoding Ogg Vorbis stream: %s\n", - errorStr); - return -1; + if (dc_intr()) + return 0; + + switch (ret) { + case OV_EREAD: + errorStr = "read error"; + break; + case OV_ENOTVORBIS: + errorStr = "not vorbis stream"; + break; + case OV_EVERSION: + errorStr = "vorbis version mismatch"; + break; + case OV_EBADHEADER: + errorStr = "invalid vorbis header"; + break; + case OV_EFAULT: + errorStr = "internal logic error"; + break; + default: + errorStr = "unknown error"; + break; } - return 0; + + ERROR("Error decoding Ogg Vorbis stream: %s\n", errorStr); + return -1; } dc.total_time = ov_time_total(&vf, -1); if (dc.total_time < 0) -- cgit v1.2.3 From 82107df9ddbbf739b6daa08c391e15a0b9b1cdfd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: wavpack: moved code to wavpack_open_wvc() Move everything related to finding and initializing the WVC stream to wavpack_open_wvc(). This greatly simplifies its error handling and the function wavpack_streamdecode(). --- src/inputPlugins/wavpack_plugin.c | 136 ++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index 4199dd946..5e593ad98 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -424,87 +424,84 @@ static unsigned int wavpack_trydecode(InputStream *is) return 1; } -/* - * Decodes a stream. - */ -static int wavpack_streamdecode(InputStream *is) +/* wvc being the "correction" file to supplement the original .wv */ +static int wavpack_open_wvc(InputStream *is_wvc) { - char error[ERRORLEN]; - WavpackContext *wpc; - InputStream is_wvc; - int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/; - char *wvc_url = NULL; - int err; - InputStreamPlus isp, isp_wvc; - int canseek; + char wvc_url[MPD_PATH_MAX]; + size_t len; - /* Try to find wvc */ - /* wvc being the "correction" file to supplement the original .wv */ - do { - char tmp[MPD_PATH_MAX]; - const char *utf8url; - size_t len; - err = 1; + /* This is the only reader of dc.current_song */ + if (!get_song_url(wvc_url, dc.current_song)) + return 0; - /* This is the only reader of dc.current_song */ - if (!(utf8url = get_song_url(tmp, dc.current_song))) - break; + len = strlen(wvc_url); + if ((len + 2) >= MPD_PATH_MAX) + return 0; - if (!(len = strlen(utf8url))) - break; + /* convert the original ".wv" path to a ".wvc" path */ + assert(wvc_url[len - 3] == '.'); + assert(wvc_url[len - 2] == 'w' || wvc_url[len - 2] == 'w'); + assert(wvc_url[len - 1] == 'v' || wvc_url[len - 1] == 'V'); + assert(wvc_url[len] == '\0'); - wvc_url = (char *)xmalloc(len + sizeof("c")); - memcpy(wvc_url, utf8url, len); - wvc_url[len] = 'c'; - wvc_url[len + 1] = '\0'; + wvc_url[len] = 'c'; + wvc_url[len + 1] = '\0'; - if (openInputStream(&is_wvc, wvc_url)) + if (openInputStream(is_wvc, wvc_url) < 0) { + /* lowercase 'c' didn't work, maybe uppercase... */ + wvc_url[len] = 'C'; + if (openInputStream(is_wvc, wvc_url) < 0) + return 0; + } + + /* + * And we try to buffer in order to get know + * about a possible 404 error. + */ + for (;;) { + if (inputStreamAtEOF(is_wvc)) + /* + * EOF is reached even without + * a single byte is read... + * So, this is not good :/ + */ break; - /* - * And we try to buffer in order to get know - * about a possible 404 error. - */ - for (;;) { - if (inputStreamAtEOF(&is_wvc)) { - /* - * EOF is reached even without - * a single byte is read... - * So, this is not good :/ - */ - break; - } + /* FIXME: replace with future "peek" function */ + if (bufferInputStream(is_wvc) >= 0) { + DEBUG("wavpack: got wvc file: %s\n", wvc_url); + return 1; /* success */ + } - /* FIXME: replace with future "peek" function */ - if (bufferInputStream(&is_wvc) >= 0) { - err = 0; - break; - } + if (dc_intr()) + break; + /* Save some CPU */ + my_usleep(1000); /* FIXME: remove */ + } - if (dc_intr()) - break; + closeInputStream(is_wvc); + return 0; +} - /* Save some CPU */ - my_usleep(1000); /* FIXME: remove */ - } - if (err) { - closeInputStream(&is_wvc); - break; - } - open_flags |= OPEN_WVC; +/* + * Decodes a stream. + */ +static int wavpack_streamdecode(InputStream *is) +{ + char error[ERRORLEN]; + WavpackContext *wpc; + InputStream is_wvc; + int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/; + InputStreamPlus isp, isp_wvc; + int canseek; - } while (0); + if (wavpack_open_wvc(&is_wvc)) { + initInputStreamPlus(&isp_wvc, &is_wvc); + open_flags |= OPEN_WVC; + } canseek = can_seek(&isp); - if (wvc_url != NULL) { - if (err) { - free(wvc_url); - wvc_url = NULL; - } else { - initInputStreamPlus(&isp_wvc, &is_wvc); - } - } initInputStreamPlus(&isp, is); wpc = WavpackOpenFileInputEx(&mpd_is_reader, &isp, &isp_wvc, error, @@ -512,17 +509,16 @@ static int wavpack_streamdecode(InputStream *is) if (wpc == NULL) { ERROR("failed to open WavPack stream: %s\n", error); + if (open_flags & OPEN_WVC) + closeInputStream(&is_wvc); return -1; } wavpack_decode(wpc, canseek, NULL); WavpackCloseFile(wpc); - if (wvc_url != NULL) { + if (open_flags & OPEN_WVC) closeInputStream(&is_wvc); - free(wvc_url); - } - closeInputStream(is); return 0; } -- cgit v1.2.3 From 4ea80a16634be04aad3dfcb5cb46afa8a7e84827 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: wavpack: don't use "isp" before initialization The old code called can_seek() with the uninitialized pointer "isp.is". Has this ever worked? Anyway, initialize "isp" first, then call can_seek(&isp). --- src/inputPlugins/wavpack_plugin.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index 5e593ad98..c7e024a41 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -494,15 +494,12 @@ static int wavpack_streamdecode(InputStream *is) InputStream is_wvc; int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/; InputStreamPlus isp, isp_wvc; - int canseek; if (wavpack_open_wvc(&is_wvc)) { initInputStreamPlus(&isp_wvc, &is_wvc); open_flags |= OPEN_WVC; } - canseek = can_seek(&isp); - initInputStreamPlus(&isp, is); wpc = WavpackOpenFileInputEx(&mpd_is_reader, &isp, &isp_wvc, error, open_flags, 15); @@ -514,7 +511,7 @@ static int wavpack_streamdecode(InputStream *is) return -1; } - wavpack_decode(wpc, canseek, NULL); + wavpack_decode(wpc, can_seek(&isp), NULL); WavpackCloseFile(wpc); if (open_flags & OPEN_WVC) -- cgit v1.2.3 From 6208397d5c06e1f637057a61c2cd6fb23f3e066a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: mp3: converted the DECODE_ constants to an enum --- src/inputPlugins/mp3_plugin.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index a39b0d128..a1c0510da 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -34,10 +34,12 @@ #define READ_BUFFER_SIZE 40960 -#define DECODE_SKIP -3 -#define DECODE_BREAK -2 -#define DECODE_CONT -1 -#define DECODE_OK 0 +enum mp3_action { + DECODE_SKIP = -3, + DECODE_BREAK = -2, + DECODE_CONT = -1, + DECODE_OK = 0 +}; #define MUTEFRAME_SKIP 1 #define MUTEFRAME_SEEK 2 @@ -367,8 +369,9 @@ fail: } #endif -static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, - ReplayGainInfo ** replayGainInfo) +static enum mp3_action +decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, + ReplayGainInfo ** replayGainInfo) { enum mad_layer layer; @@ -430,7 +433,8 @@ static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, return DECODE_OK; } -static int decodeNextFrame(mp3DecodeData * data) +static enum mp3_action +decodeNextFrame(mp3DecodeData * data) { if ((data->stream).buffer == NULL || (data->stream).error == MAD_ERROR_BUFLEN) { @@ -846,7 +850,8 @@ static void mp3Read_seek(mp3DecodeData * data) } } -static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) +static enum mp3_action +mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { unsigned int pcm_length, max_samples; unsigned int i; -- cgit v1.2.3 From ce28a60fd5cb17103372000dba818726551ec617 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: mp3: converted the MUTEFRAME_ macros to an enum Also introduce MUTEFRAME_NONE; previously, the code used "0". --- src/inputPlugins/mp3_plugin.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index a1c0510da..f1304f401 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -41,8 +41,11 @@ enum mp3_action { DECODE_OK = 0 }; -#define MUTEFRAME_SKIP 1 -#define MUTEFRAME_SEEK 2 +enum muteframe { + MUTEFRAME_NONE, + MUTEFRAME_SKIP, + MUTEFRAME_SEEK +}; /* the number of samples of silence the decoder inserts at start */ #define DECODERDELAY 529 @@ -153,7 +156,7 @@ typedef struct _mp3DecodeData { mpd_sint16 outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE]; float totalTime; float elapsedTime; - int muteFrame; + enum muteframe muteFrame; long *frameOffset; mad_timer_t *times; unsigned long highestFrame; @@ -174,7 +177,7 @@ typedef struct _mp3DecodeData { static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream) { - data->muteFrame = 0; + data->muteFrame = MUTEFRAME_NONE; data->highestFrame = 0; data->maxFrames = 0; data->frameOffset = NULL; @@ -845,7 +848,7 @@ static void mp3Read_seek(mp3DecodeData * data) dc.seek_where = DC_SEEK_ERROR; else data->currentFrame = j; - data->muteFrame = 0; + data->muteFrame = MUTEFRAME_NONE; dc_action_end(); } } @@ -887,17 +890,17 @@ mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) switch (data->muteFrame) { case MUTEFRAME_SKIP: - data->muteFrame = 0; + data->muteFrame = MUTEFRAME_NONE; break; case MUTEFRAME_SEEK: if (dc.seek_where <= data->elapsedTime) { dc_action_begin(); assert(dc.action == DC_ACTION_SEEK); - data->muteFrame = 0; + data->muteFrame = MUTEFRAME_NONE; dc_action_end(); } break; - default: + case MUTEFRAME_NONE: mad_synth_frame(&data->synth, &data->frame); if (!data->foundFirstFrame) { @@ -1003,7 +1006,7 @@ mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) break; else if (ret == DECODE_SKIP) skip = 1; - if (!data->muteFrame) { + if (data->muteFrame == MUTEFRAME_NONE) { while ((ret = decodeNextFrame(data)) == DECODE_CONT && !dc_intr() && dc_seek()) ; if (ret == DECODE_BREAK || dc_intr() || dc_seek()) -- cgit v1.2.3 From 8e0b55596ee1b33457b14f757eb50a69caeab60e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:15 +0200 Subject: jack: eliminate superfluous freeJackData() calls connect_jack() invokes freeJackData() in every error handler, although its caller also invokes this function after a failure. We can save a lot of lines in connect_jack() by removing these redundant freeJackData() invocations. --- src/audioOutputs/audioOutput_jack.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index c8aa4dcb6..a62c0a0e9 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -257,7 +257,6 @@ static int connect_jack(AudioOutput *audioOutput) if ( (jd->client = jack_client_new(name)) == NULL ) { ERROR("jack server not running?\n"); - freeJackData(audioOutput); return -1; } @@ -269,7 +268,6 @@ static int connect_jack(AudioOutput *audioOutput) if ( jack_activate(jd->client) ) { ERROR("cannot activate client\n"); - freeJackData(audioOutput); return -1; } @@ -278,7 +276,6 @@ static int connect_jack(AudioOutput *audioOutput) JackPortIsOutput, 0); if ( !jd->ports[0] ) { ERROR("Cannot register left output port.\n"); - freeJackData(audioOutput); return -1; } @@ -287,7 +284,6 @@ static int connect_jack(AudioOutput *audioOutput) JackPortIsOutput, 0); if ( !jd->ports[1] ) { ERROR("Cannot register right output port.\n"); - freeJackData(audioOutput); return -1; } @@ -315,7 +311,6 @@ static int connect_jack(AudioOutput *audioOutput) output_ports[0])) != 0 ) { ERROR("%s is not a valid Jack Client / Port\n", output_ports[0]); - freeJackData(audioOutput); free(port_name); return -1; } @@ -324,7 +319,6 @@ static int connect_jack(AudioOutput *audioOutput) output_ports[1])) != 0 ) { ERROR("%s is not a valid Jack Client / Port\n", output_ports[1]); - freeJackData(audioOutput); free(port_name); return -1; } -- cgit v1.2.3 From 641e530f447771642ac627c91e8bff67fcb71fd3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:15 +0200 Subject: jack: initialize jd->client after !jd check Prepare the next patch: make the "!jd" check independent of the jd->client initialization. This way we can change the "jd" initialization semantics later. --- src/audioOutputs/audioOutput_jack.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index a62c0a0e9..4a30e897e 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -337,12 +337,12 @@ static int jack_openDevice(AudioOutput *audioOutput) DEBUG("connect!\n"); jd = newJackData(); audioOutput->data = jd; + } - if (connect_jack(audioOutput) < 0) { - freeJackData(audioOutput); - audioOutput->open = 0; - return -1; - } + if (jd->client == NULL && connect_jack(audioOutput) < 0) { + freeJackData(audioOutput); + audioOutput->open = 0; + return -1; } set_audioformat(audioOutput); -- cgit v1.2.3 From 8c419bb006e376cd0b78453a988976d96027a9f4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:15 +0200 Subject: jack: added freeJackClient() No need to destroy the JackData object when an error occurs, since jack_finishDriver() already frees it. Only deinitialize the jack library, introduce freeJackClient() for that, and move code from freeJackData(). --- src/audioOutputs/audioOutput_jack.c | 38 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index 4a30e897e..47997df01 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -63,14 +63,32 @@ static JackData *newJackData(void) return ret; } +static void freeJackClient(JackData *jd) +{ + assert(jd != NULL); + + if (jd->client != NULL) { + jack_deactivate(jd->client); + jack_client_close(jd->client); + jd->client = NULL; + } + + if (jd->ringbuffer[0] != NULL) { + jack_ringbuffer_free(jd->ringbuffer[0]); + jd->ringbuffer[0] = NULL; + } + + if (jd->ringbuffer[1] != NULL) { + jack_ringbuffer_free(jd->ringbuffer[1]); + jd->ringbuffer[1] = NULL; + } +} + static void freeJackData(AudioOutput *audioOutput) { JackData *jd = audioOutput->data; if (jd) { - if (jd->ringbuffer[0]) - jack_ringbuffer_free(jd->ringbuffer[0]); - if (jd->ringbuffer[1]) - jack_ringbuffer_free(jd->ringbuffer[1]); + freeJackClient(jd); free(jd); audioOutput->data = NULL; } @@ -78,13 +96,9 @@ static void freeJackData(AudioOutput *audioOutput) static void jack_finishDriver(AudioOutput *audioOutput) { - JackData *jd = audioOutput->data; int i; - if ( jd && jd->client ) { - jack_deactivate(jd->client); - jack_client_close(jd->client); - } + freeJackData(audioOutput); DEBUG("disconnect_jack (pid=%d)\n", getpid ()); if ( strcmp(name, "mpd") ) { @@ -98,8 +112,6 @@ static void jack_finishDriver(AudioOutput *audioOutput) free(output_ports[i]); output_ports[i] = NULL; } - - freeJackData(audioOutput); } static int srate(mpd_unused jack_nframes_t rate, void *data) @@ -340,7 +352,7 @@ static int jack_openDevice(AudioOutput *audioOutput) } if (jd->client == NULL && connect_jack(audioOutput) < 0) { - freeJackData(audioOutput); + freeJackClient(jd); audioOutput->open = 0; return -1; } @@ -378,7 +390,7 @@ static int jack_playAudio(AudioOutput * audioOutput, if ( jd->shutdown ) { ERROR("Refusing to play, because there is no client thread.\n"); - freeJackData(audioOutput); + freeJackClient(jd); audioOutput->open = 0; return 0; } -- cgit v1.2.3 From 25b5471f415db926e8b4ebe1a02e209d70757191 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:15 +0200 Subject: jack: initialize JackData in jack_initDriver() Over the lifetime of the jack AudioOutput object, we want a single valid JackData object, so we can persistently store data there (configuration etc.). Allocate JackData in jack_initDriver(). After that, we can safely remove all audioOutput->data==NULL checks (and replace them with assertions). --- src/audioOutputs/audioOutput_jack.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index 47997df01..9fc52055f 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -205,7 +205,7 @@ static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param) int val; char *cp = NULL; - audioOutput->data = NULL; + audioOutput->data = newJackData(); DEBUG("jack_initDriver (pid=%d)\n", getpid()); if ( ! param ) return 0; @@ -345,11 +345,7 @@ static int jack_openDevice(AudioOutput *audioOutput) { JackData *jd = audioOutput->data; - if ( !jd ) { - DEBUG("connect!\n"); - jd = newJackData(); - audioOutput->data = jd; - } + assert(jd != NULL); if (jd->client == NULL && connect_jack(audioOutput) < 0) { freeJackClient(jd); -- cgit v1.2.3 From 5742bc42d061b7f60c6ed3dbd71c64f12c77f91f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:15 +0200 Subject: jack: don't set audioOutput->data=NULL There is only one caller of freeJackData() left: jack_finishDriver(). This function is called by the mpd core, and is called exactly once for every successful jack_initDriver(). We do not need to clear audioOutput->data, since this variable is invalidated anyway. --- src/audioOutputs/audioOutput_jack.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index 9fc52055f..5e0b1b599 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -87,11 +87,11 @@ static void freeJackClient(JackData *jd) static void freeJackData(AudioOutput *audioOutput) { JackData *jd = audioOutput->data; - if (jd) { - freeJackClient(jd); - free(jd); - audioOutput->data = NULL; - } + + assert(jd != NULL); + + freeJackClient(jd); + free(jd); } static void jack_finishDriver(AudioOutput *audioOutput) -- cgit v1.2.3 From 22454dc6c9bf87c0c565d20d1f48b97877197f6e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:15 +0200 Subject: jack: removed unused macros --- src/audioOutputs/audioOutput_jack.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index 5e0b1b599..708b0e4ad 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -30,16 +30,6 @@ pthread_mutex_t play_audio_lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t play_audio = PTHREAD_COND_INITIALIZER; -/*#include "dmalloc.h"*/ - -#ifdef MIN -# undef MIN -# define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif - -/*#define SAMPLE_SIZE sizeof(jack_default_audio_sample_t);*/ - - static char *name = "mpd"; static char *output_ports[2]; static int ringbuf_sz = 32768; -- cgit v1.2.3 From 070b952ae48da684461a3efa039be3b081f90f4d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:16 +0200 Subject: moved jack configuration to the JackData struct Storing local configuration in global (static) variables is obviously a bad idea. Move all those variables into the JackData struct, including the locks. --- src/audioOutputs/audioOutput_jack.c | 113 ++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index 708b0e4ad..955eccd0b 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -27,15 +27,19 @@ #include #include -pthread_mutex_t play_audio_lock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t play_audio = PTHREAD_COND_INITIALIZER; - -static char *name = "mpd"; -static char *output_ports[2]; -static int ringbuf_sz = 32768; size_t sample_size = sizeof(jack_default_audio_sample_t); typedef struct _JackData { + /* configuration */ + char *name; + char *output_ports[2]; + int ringbuf_sz; + + /* locks */ + pthread_mutex_t play_audio_lock; + pthread_cond_t play_audio; + + /* jack library stuff */ jack_port_t *ports[2]; jack_client_t *client; jack_ringbuffer_t *ringbuffer[2]; @@ -50,6 +54,12 @@ static JackData *newJackData(void) JackData *ret; ret = xcalloc(sizeof(JackData), 1); + ret->name = "mpd"; + ret->ringbuf_sz = 32768; + + pthread_mutex_init(&ret->play_audio_lock, NULL); + pthread_cond_init(&ret->play_audio, NULL); + return ret; } @@ -72,36 +82,36 @@ static void freeJackClient(JackData *jd) jack_ringbuffer_free(jd->ringbuffer[1]); jd->ringbuffer[1] = NULL; } + + pthread_mutex_destroy(&jd->play_audio_lock); + pthread_cond_destroy(&jd->play_audio); } static void freeJackData(AudioOutput *audioOutput) { JackData *jd = audioOutput->data; + int i; assert(jd != NULL); freeJackClient(jd); + + if (strcmp(jd->name, "mpd") != 0) + free(jd->name); + + for ( i = ARRAY_SIZE(jd->output_ports); --i >= 0; ) { + if (!jd->output_ports[i]) + continue; + free(jd->output_ports[i]); + } + free(jd); } static void jack_finishDriver(AudioOutput *audioOutput) { - int i; - freeJackData(audioOutput); DEBUG("disconnect_jack (pid=%d)\n", getpid ()); - - if ( strcmp(name, "mpd") ) { - free(name); - name = "mpd"; - } - - for ( i = ARRAY_SIZE(output_ports); --i >= 0; ) { - if (!output_ports[i]) - continue; - free(output_ports[i]); - output_ports[i] = NULL; - } } static int srate(mpd_unused jack_nframes_t rate, void *data) @@ -152,9 +162,9 @@ static int process(jack_nframes_t nframes, void *arg) nframes = 0; } - if (pthread_mutex_trylock (&play_audio_lock) == 0) { - pthread_cond_signal (&play_audio); - pthread_mutex_unlock (&play_audio_lock); + if (pthread_mutex_trylock (&jd->play_audio_lock) == 0) { + pthread_cond_signal (&jd->play_audio); + pthread_mutex_unlock (&jd->play_audio_lock); } } @@ -190,12 +200,14 @@ static void error_callback(const char *msg) static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param) { + JackData *jd; BlockParam *bp; char *endptr; int val; char *cp = NULL; audioOutput->data = newJackData(); + jd = audioOutput->data; DEBUG("jack_initDriver (pid=%d)\n", getpid()); if ( ! param ) return 0; @@ -209,18 +221,19 @@ static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param) bp->name, bp->line, bp->value); *cp = '\0'; - output_ports[0] = xstrdup(bp->value); + jd->output_ports[0] = xstrdup(bp->value); *cp++ = ','; if (!*cp) FATAL("expected a second value for '%s' at line %d: " "%s\n", bp->name, bp->line, bp->value); - output_ports[1] = xstrdup(cp); + jd->output_ports[1] = xstrdup(cp); if (strchr(cp,',')) FATAL("Only %d values are supported for '%s' " - "at line %d\n", (int)ARRAY_SIZE(output_ports), + "at line %d\n", + (int)ARRAY_SIZE(jd->output_ports), bp->name, bp->line); } @@ -229,18 +242,18 @@ static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param) val = strtol(bp->value, &endptr, 10); if ( errno == 0 && endptr != bp->value) { - ringbuf_sz = val < 32768 ? 32768 : val; - DEBUG("ringbuffer_size=%d\n", ringbuf_sz); + jd->ringbuf_sz = val < 32768 ? 32768 : val; + DEBUG("ringbuffer_size=%d\n", jd->ringbuf_sz); } else { FATAL("%s is not a number; ringbuf_size=%d\n", - bp->value, ringbuf_sz); + bp->value, jd->ringbuf_sz); } } if ( (bp = getBlockParam(param, "name")) && (strcmp(bp->value, "mpd") != 0) ) { - name = xstrdup(bp->value); - DEBUG("name=%s\n", name); + jd->name = xstrdup(bp->value); + DEBUG("name=%s\n", jd->name); } return 0; @@ -257,7 +270,7 @@ static int connect_jack(AudioOutput *audioOutput) char **jports; char *port_name; - if ( (jd->client = jack_client_new(name)) == NULL ) { + if ( (jd->client = jack_client_new(jd->name)) == NULL ) { ERROR("jack server not running?\n"); return -1; } @@ -290,37 +303,38 @@ static int connect_jack(AudioOutput *audioOutput) } /* hay que buscar que hay */ - if ( !output_ports[1] + if ( !jd->output_ports[1] && (jports = (char **)jack_get_ports(jd->client, NULL, NULL, JackPortIsPhysical| JackPortIsInput)) ) { - output_ports[0] = jports[0]; - output_ports[1] = jports[1] ? jports[1] : jports[0]; - DEBUG("output_ports: %s %s\n", output_ports[0], output_ports[1]); + jd->output_ports[0] = jports[0]; + jd->output_ports[1] = jports[1] ? jports[1] : jports[0]; + DEBUG("output_ports: %s %s\n", + jd->output_ports[0], jd->output_ports[1]); free(jports); } - if ( output_ports[1] ) { - jd->ringbuffer[0] = jack_ringbuffer_create(ringbuf_sz); - jd->ringbuffer[1] = jack_ringbuffer_create(ringbuf_sz); + if ( jd->output_ports[1] ) { + jd->ringbuffer[0] = jack_ringbuffer_create(jd->ringbuf_sz); + jd->ringbuffer[1] = jack_ringbuffer_create(jd->ringbuf_sz); memset(jd->ringbuffer[0]->buf, 0, jd->ringbuffer[0]->size); memset(jd->ringbuffer[1]->buf, 0, jd->ringbuffer[1]->size); - port_name = xmalloc(sizeof(char)*(7+strlen(name))); + port_name = xmalloc(sizeof(char)*(7+strlen(jd->name))); - sprintf(port_name, "%s:left", name); + sprintf(port_name, "%s:left", jd->name); if ( (jack_connect(jd->client, port_name, - output_ports[0])) != 0 ) { + jd->output_ports[0])) != 0 ) { ERROR("%s is not a valid Jack Client / Port\n", - output_ports[0]); + jd->output_ports[0]); free(port_name); return -1; } - sprintf(port_name, "%s:right", name); + sprintf(port_name, "%s:right", jd->name); if ( (jack_connect(jd->client, port_name, - output_ports[1])) != 0 ) { + jd->output_ports[1])) != 0 ) { ERROR("%s is not a valid Jack Client / Port\n", - output_ports[1]); + jd->output_ports[1]); free(port_name); return -1; } @@ -406,9 +420,10 @@ static int jack_playAudio(AudioOutput * audioOutput, samples=0; } else { - pthread_mutex_lock(&play_audio_lock); - pthread_cond_wait(&play_audio, &play_audio_lock); - pthread_mutex_unlock(&play_audio_lock); + pthread_mutex_lock(&jd->play_audio_lock); + pthread_cond_wait(&jd->play_audio, + &jd->play_audio_lock); + pthread_mutex_unlock(&jd->play_audio_lock); } } -- cgit v1.2.3 From e4db015707016978b6a478e06a908fb1a1577601 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:16 +0200 Subject: jack: made "sample_size" static const sample_size is a variable which is computed at compile time. Declare it "static const", so the compiler can optimize it away. --- src/audioOutputs/audioOutput_jack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index 955eccd0b..8818bb739 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -27,7 +27,7 @@ #include #include -size_t sample_size = sizeof(jack_default_audio_sample_t); +static const size_t sample_size = sizeof(jack_default_audio_sample_t); typedef struct _JackData { /* configuration */ -- cgit v1.2.3 From b2de20ad8ebdba6d78c63a32a28340faf51778c1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:16 +0200 Subject: playlist: eliminate unused fd parameters Again, remove file descriptor parameters, which are not actually used. These functions can also be converted to return void. --- src/command.c | 20 ++++++++++++-------- src/playlist.c | 40 ++++++++++++++++++---------------------- src/playlist.h | 8 ++++---- 3 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/command.c b/src/command.c index 27e7f3408..af559bd6b 100644 --- a/src/command.c +++ b/src/command.c @@ -269,10 +269,11 @@ static int handlePlayId(int fd, mpd_unused int *permission, return playPlaylistById(fd, id, 0); } -static int handleStop(int fd, mpd_unused int *permission, +static int handleStop(mpd_unused int fd, mpd_unused int *permission, mpd_unused int argc, mpd_unused char *argv[]) { - return stopPlaylist(fd); + stopPlaylist(); + return 0; } static int handleCurrentSong(int fd, mpd_unused int *permission, @@ -442,10 +443,11 @@ static int handleShuffle(int fd, mpd_unused int *permission, return shufflePlaylist(fd); } -static int handleClear(int fd, mpd_unused int *permission, +static int handleClear(mpd_unused int fd, mpd_unused int *permission, mpd_unused int argc, mpd_unused char *argv[]) { - return clearPlaylist(fd); + clearPlaylist(); + return 0; } static int handleSave(int fd, mpd_unused int *permission, @@ -717,16 +719,18 @@ static int handleUpdate(int fd, mpd_unused int *permission, return updateInit(fd, NULL); } -static int handleNext(int fd, mpd_unused int *permission, +static int handleNext(mpd_unused int fd, mpd_unused int *permission, mpd_unused int argc, mpd_unused char *argv[]) { - return nextSongInPlaylist(fd); + nextSongInPlaylist(); + return 0; } -static int handlePrevious(int fd, mpd_unused int *permission, +static int handlePrevious(mpd_unused int fd, mpd_unused int *permission, mpd_unused int argc, mpd_unused char *argv[]) { - return previousSongInPlaylist(fd); + previousSongInPlaylist(); + return 0; } static int handleListAll(int fd, mpd_unused int *permission, diff --git a/src/playlist.c b/src/playlist.c index 39e806670..0512951fd 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -94,7 +94,7 @@ static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER; int playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS; static void swapOrder(int a, int b); -static int play_order_num(int fd, int order_num, float seek_time); +static void play_order_num(int order_num, float seek_time); static void randomizeOrder(int start, int end); static void incrPlaylistVersion(void) @@ -219,12 +219,11 @@ void finishPlaylist(void) playlist.positionToId = NULL; } -int clearPlaylist(int fd) +void clearPlaylist(void) { int i; - if (stopPlaylist(fd) < 0) - return -1; + stopPlaylist(); for (i = 0; i < playlist.length; i++) { if (playlist.songs[i]->type == SONG_TYPE_URL) { @@ -237,8 +236,6 @@ int clearPlaylist(int fd) playlist.current = -1; incrPlaylistVersion(); - - return 0; } int clearStoredPlaylist(int fd, char *utf8file) @@ -834,9 +831,9 @@ int deleteFromPlaylist(int fd, int song) if (stop_current) { /* DEBUG(__FILE__": %d\n", __LINE__); */ if (playlist.current >= 0 && songOrder > 0) - play_order_num(fd, playlist.current, 0); + play_order_num(playlist.current, 0); else - stopPlaylist(fd); + stopPlaylist(); } else { /* DEBUG(__FILE__": %d\n", __LINE__); */ queueNextSongInPlaylist(); @@ -866,7 +863,7 @@ void deleteASongFromPlaylist(Song * song) } } -int stopPlaylist(int fd) +void stopPlaylist(void) { DEBUG("playlist: stop\n"); @@ -883,10 +880,9 @@ int stopPlaylist(int fd) playlist_state = PLAYLIST_STATE_STOP; if (playlist.random) randomizeOrder(0, playlist.length - 1); - return 0; } -static int play_order_num(int fd, int order_num, float seek_time) +static void play_order_num(int order_num, float seek_time) { char path[MPD_PATH_MAX]; enum dc_action action = seek_time ? DC_ACTION_SEEK : DC_ACTION_START; @@ -906,8 +902,6 @@ static int play_order_num(int fd, int order_num, float seek_time) dc_trigger_action(action, seek_time); if (dc.seek_where >= 0) playlist.current = order_num; - - return 0; } int playPlaylist(int fd, int song, int stopOnError) @@ -954,7 +948,8 @@ int playPlaylist(int fd, int song, int stopOnError) ERROR(__FILE__ ": %d current:%d\n", __LINE__, playlist.current); ob_trigger_action(OB_ACTION_PAUSE_UNSET); - return play_order_num(fd, i, 0); + play_order_num(i, 0); + return 0; } int playPlaylistById(int fd, int id, int stopOnError) @@ -1015,20 +1010,21 @@ void syncPlayerAndPlaylist(void) } } -int nextSongInPlaylist(int fd) +void nextSongInPlaylist(void) { int next; if (playlist_state != PLAYLIST_STATE_PLAY) - return 0; + return; playlist_stopOnError = 0; next = next_order_num(); if (next < 0) { /* we were already at last song w/o repeat: */ incrPlaylistCurrent(); - return stopPlaylist(fd); + stopPlaylist(); + return; } ob_trigger_action(OB_ACTION_PAUSE_UNSET); - return play_order_num(fd, next, 0); + play_order_num(next, 0); } int getPlaylistRepeatStatus(void) @@ -1234,7 +1230,7 @@ int setPlaylistRandomStatus(int fd, int status) return 0; } -int previousSongInPlaylist(int fd) +void previousSongInPlaylist(void) { static time_t lastTime; time_t diff = time(NULL) - lastTime; @@ -1243,7 +1239,7 @@ int previousSongInPlaylist(int fd) lastTime += diff; if (playlist_state != PLAYLIST_STATE_PLAY) - return 0; + return; syncPlaylistWithQueue(); @@ -1258,7 +1254,7 @@ int previousSongInPlaylist(int fd) prev_order_num = playlist.current; } ob_trigger_action(OB_ACTION_PAUSE_UNSET); - return play_order_num(fd, prev_order_num, 0); + play_order_num(prev_order_num, 0); } int shufflePlaylist(mpd_unused int fd) @@ -1419,7 +1415,7 @@ int seekSongInPlaylist(int fd, int song, float seek_time) } DEBUG("playlist: seek %i:\"%s\"\n", i, get_song_url(path, song_at(i))); - play_order_num(fd, i, seek_time); + play_order_num(i, seek_time); return 0; } diff --git a/src/playlist.h b/src/playlist.h index 2ba28f9e4..2e9e02a91 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -36,7 +36,7 @@ void readPlaylistState(FILE *); void savePlaylistState(FILE *); -int clearPlaylist(int fd); +void clearPlaylist(void); int clearStoredPlaylist(int fd, char *utf8file); @@ -62,17 +62,17 @@ void playlist_queue_next(void); int playlist_playing(void); -int stopPlaylist(int fd); +void stopPlaylist(void); int playPlaylist(int fd, int song, int stopOnError); int playPlaylistById(int fd, int song, int stopOnError); -int nextSongInPlaylist(int fd); +void nextSongInPlaylist(void); void syncPlayerAndPlaylist(void); -int previousSongInPlaylist(int fd); +void previousSongInPlaylist(void); int shufflePlaylist(int fd); -- cgit v1.2.3 From 9144751e21315878343a94997ee0bda36ff7483d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 28 Aug 2008 20:01:08 +0200 Subject: protect locate.h from double inclusion --- src/locate.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/locate.h b/src/locate.h index 28b2782b0..325ae384d 100644 --- a/src/locate.h +++ b/src/locate.h @@ -16,6 +16,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef LOCATE_H +#define LOCATE_H + #include "song.h" #define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10 @@ -44,3 +47,5 @@ void freeLocateTagItem(LocateTagItem * item); int strstrSearchTags(Song * song, int numItems, LocateTagItem * items); int tagItemsFoundAndMatches(Song * song, int numItems, LocateTagItem * items); + +#endif -- cgit v1.2.3 From 929305101d4fbde7c0c540264106c4275860a3b8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 28 Aug 2008 20:01:08 +0200 Subject: include cleanup Only include headers which are really needed. --- src/command.c | 1 + src/directory.c | 1 + src/main.c | 1 - src/playlist.h | 2 +- 4 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/command.c b/src/command.c index af559bd6b..805addde1 100644 --- a/src/command.c +++ b/src/command.c @@ -32,6 +32,7 @@ #include "sllist.h" #include "ack.h" #include "audio.h" +#include "dbUtils.h" #include "os_compat.h" #include "player_error.h" #include "outputBuffer.h" diff --git a/src/directory.c b/src/directory.c index 7168dab02..94a55d664 100644 --- a/src/directory.c +++ b/src/directory.c @@ -32,6 +32,7 @@ #include "volume.h" #include "ack.h" #include "myfprintf.h" +#include "dbUtils.h" #define DIRECTORY_DIR "directory: " #define DIRECTORY_MTIME "mtime: " diff --git a/src/main.c b/src/main.c index 57766d04b..9d75fadc7 100644 --- a/src/main.c +++ b/src/main.c @@ -35,7 +35,6 @@ #include "inputStream.h" #include "state_file.h" #include "tag.h" -#include "tagTracker.h" #include "dbUtils.h" #include "../config.h" #include "utils.h" diff --git a/src/playlist.h b/src/playlist.h index 2e9e02a91..0bcc9680a 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -19,7 +19,7 @@ #ifndef PLAYLIST_H #define PLAYLIST_H -#include "dbUtils.h" +#include "locate.h" #define PLAYLIST_FILE_SUFFIX "m3u" #define PLAYLIST_COMMENT '#' -- cgit v1.2.3 From bfd5d4e220bb3570c27e7b84118f17bb610be01c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 29 Aug 2008 15:03:09 +0200 Subject: oggflac: fix GCC warnings Fix lots of "unused parameter" warnings in the OggFLAC decoder plugin. Not sure if anybody uses it anymore, since newer libflac obsoletes it. --- src/inputPlugins/oggflac_plugin.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c index d3016c9a2..4b3bb0a6b 100644 --- a/src/inputPlugins/oggflac_plugin.c +++ b/src/inputPlugins/oggflac_plugin.c @@ -37,7 +37,7 @@ static void oggflac_cleanup(FlacData * data, OggFLAC__seekable_stream_decoder_delete(decoder); } -static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const +static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__byte buf[], @@ -62,7 +62,7 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; } -static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(const +static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__uint64 offset, @@ -77,7 +77,7 @@ static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(const return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; } -static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(const +static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__uint64 * @@ -90,7 +90,7 @@ static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(const return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; } -static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(const +static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__uint64 * @@ -104,7 +104,7 @@ static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(const return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; } -static FLAC__bool of_EOF_cb(const OggFLAC__SeekableStreamDecoder * decoder, +static FLAC__bool of_EOF_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, void *fdata) { FlacData *data = (FlacData *) fdata; @@ -114,7 +114,7 @@ static FLAC__bool of_EOF_cb(const OggFLAC__SeekableStreamDecoder * decoder, return false; } -static void of_error_cb(const OggFLAC__SeekableStreamDecoder * decoder, +static void of_error_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__StreamDecoderErrorStatus status, void *fdata) { flac_error_common_cb("oggflac", status, (FlacData *) fdata); @@ -151,7 +151,7 @@ static void oggflacPrintErroredState(OggFLAC__SeekableStreamDecoderState state) } } -static FLAC__StreamDecoderWriteStatus oggflacWrite(const +static FLAC__StreamDecoderWriteStatus oggflacWrite(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, const FLAC__Frame * frame, @@ -208,7 +208,7 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(const } /* used by TagDup */ -static void of_metadata_dup_cb(const OggFLAC__SeekableStreamDecoder * decoder, +static void of_metadata_dup_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, const FLAC__StreamMetadata * block, void *vdata) { FlacData *data = (FlacData *) vdata; @@ -229,7 +229,7 @@ static void of_metadata_dup_cb(const OggFLAC__SeekableStreamDecoder * decoder, } /* used by decode */ -static void of_metadata_decode_cb(const OggFLAC__SeekableStreamDecoder * dec, +static void of_metadata_decode_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * dec, const FLAC__StreamMetadata * block, void *vdata) { -- cgit v1.2.3 From ad02ebe21138fed633af5465d1690db103c4934e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 28 Aug 2008 20:02:16 +0200 Subject: unsigned integers and size_t Use "unsigned int" whenever negative values are not meaningful. Use size_t whenever we are going to describe buffer sizes. --- src/tag.c | 7 +++---- src/tag.h | 3 ++- src/utf8.c | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/tag.c b/src/tag.c index fc85a6ff9..00f09f10f 100644 --- a/src/tag.c +++ b/src/tag.c @@ -25,7 +25,6 @@ #include "charConv.h" #include "tagTracker.h" #include "song.h" -#include "os_compat.h" #ifdef HAVE_ID3TAG # define isId3v1(tag) (id3_tag_options(tag, 0, 0) & ID3_TAG_OPTION_ID3V1) @@ -698,9 +697,9 @@ int mpdTagsAreEqual(MpdTag * tag1, MpdTag * tag2) } static void appendToTagItems(MpdTag * tag, enum tag_type type, - char *value, int len) + char *value, size_t len) { - int i = tag->numOfItems; + unsigned int i = tag->numOfItems; char *duplicated = xmalloc(len + 1); memcpy(duplicated, value, len); @@ -719,7 +718,7 @@ static void appendToTagItems(MpdTag * tag, enum tag_type type, } void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType, - char *value, int len) + char *value, size_t len) { if (ignoreTagItems[itemType]) { diff --git a/src/tag.h b/src/tag.h index 99b32653c..74770e49e 100644 --- a/src/tag.h +++ b/src/tag.h @@ -22,6 +22,7 @@ #include "../config.h" #include "mpd_types.h" +#include "os_compat.h" #ifdef HAVE_ID3TAG #include @@ -72,7 +73,7 @@ void clearItemsFromMpdTag(MpdTag * tag, enum tag_type itemType); void freeMpdTag(MpdTag * tag); void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType, - char *value, int len); + char *value, size_t len); #define addItemToMpdTag(tag, itemType, value) \ addItemToMpdTagWithLen(tag, itemType, value, strlen(value)) diff --git a/src/utf8.c b/src/utf8.c index f0d6b3b11..e8f3dbdde 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -69,7 +69,7 @@ static char utf8_to_latin1_char(const char *inUtf8) return (char)(c + utf8[1]); } -static int validateUtf8Char(const char *inUtf8Char) +static unsigned int validateUtf8Char(const char *inUtf8Char) { const unsigned char *utf8Char = (const unsigned char *)inUtf8Char; @@ -77,9 +77,9 @@ static int validateUtf8Char(const char *inUtf8Char) return 1; if (utf8Char[0] >= 0xC0 && utf8Char[0] <= 0xFD) { - int count = 1; + unsigned int count = 1; char t = 1 << 5; - int i; + unsigned int i; while (count < 6 && (t & utf8Char[0])) { t = (t >> 1); count++; @@ -97,7 +97,7 @@ static int validateUtf8Char(const char *inUtf8Char) int validUtf8String(const char *string) { - int ret; + unsigned int ret; while (*string) { ret = validateUtf8Char(string); @@ -114,7 +114,7 @@ char *utf8StrToLatin1Dup(const char *utf8) /* utf8 should have at most two char's per latin1 char */ char *ret = xmalloc(strlen(utf8) + 1); char *cp = ret; - int count; + unsigned int count; size_t len = 0; while (*utf8) { @@ -136,7 +136,7 @@ char *utf8StrToLatin1Dup(const char *utf8) char *utf8_to_latin1(char *dest, const char *utf8) { char *cp = dest; - int count; + unsigned int count; size_t len = 0; while (*utf8) { -- cgit v1.2.3 From c52667aa8eee2a40547026735b9670a2221d4168 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 28 Aug 2008 20:02:17 +0200 Subject: const pointers The usual bunch of pointer arguments which should be const. --- src/interface.c | 10 +++++----- src/interface.h | 4 ++-- src/sllist.c | 8 ++++---- src/sllist.h | 4 ++-- src/tag.c | 4 ++-- src/tag.h | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/interface.c b/src/interface.c index 45b81a2f7..83e0084b5 100644 --- a/src/interface.c +++ b/src/interface.c @@ -234,7 +234,7 @@ static void closeInterface(Interface * interface) SECURE("interface %i: closed\n", interface->num); } -void openAInterface(int fd, struct sockaddr *addr) +void openAInterface(int fd, const struct sockaddr *addr) { unsigned int i; @@ -249,7 +249,7 @@ void openAInterface(int fd, struct sockaddr *addr) switch (addr->sa_family) { #ifdef HAVE_TCP case AF_INET: - hostname = (const char *)inet_ntoa(((struct sockaddr_in *) + hostname = (const char *)inet_ntoa(((const struct sockaddr_in *) addr)->sin_addr); if (!hostname) hostname = "error getting ipv4 address"; @@ -259,8 +259,8 @@ void openAInterface(int fd, struct sockaddr *addr) { static char host[INET6_ADDRSTRLEN + 1]; memset(host, 0, INET6_ADDRSTRLEN + 1); - if (inet_ntop(AF_INET6, (void *) - &(((struct sockaddr_in6 *)addr)-> + if (inet_ntop(AF_INET6, (const void *) + &(((const struct sockaddr_in6 *)addr)-> sin6_addr), host, INET6_ADDRSTRLEN)) { hostname = (const char *)host; @@ -686,7 +686,7 @@ static void flushInterfaceBuffer(Interface * interface) } } -int interfacePrintWithFD(int fd, char *buffer, size_t buflen) +int interfacePrintWithFD(int fd, const char *buffer, size_t buflen) { static unsigned int i; size_t copylen; diff --git a/src/interface.h b/src/interface.h index a364f7922..c83381319 100644 --- a/src/interface.h +++ b/src/interface.h @@ -22,10 +22,10 @@ #include "os_compat.h" void initInterfaces(void); -void openAInterface(int fd, struct sockaddr *addr); +void openAInterface(int fd, const struct sockaddr *addr); void freeAllInterfaces(void); void closeOldInterfaces(void); -int interfacePrintWithFD(int fd, char *buffer, size_t len); +int interfacePrintWithFD(int fd, const char *buffer, size_t len); int doIOForInterfaces(void); diff --git a/src/sllist.c b/src/sllist.c index cfe392d60..0f4529fd3 100644 --- a/src/sllist.c +++ b/src/sllist.c @@ -34,22 +34,22 @@ struct strnode *new_strnode(char *s) return x; } -struct strnode *new_strnode_dup(char *s, const size_t size) +struct strnode *new_strnode_dup(const char *s, const size_t size) { struct strnode *x = xmalloc(sizeof(struct strnode) + size); x->next = NULL; x->data = ((char *)x + sizeof(struct strnode)); - memcpy((void *)x->data, (void*)s, size); + memcpy((void *)x->data, (const void*)s, size); return x; } -struct sllnode *new_sllnode(void *s, const size_t size) +struct sllnode *new_sllnode(const void *s, const size_t size) { struct sllnode *x = xmalloc(sizeof(struct sllnode) + size); x->next = NULL; x->size = size; x->data = ((char *)x + sizeof(struct sllnode)); - memcpy(x->data, (void *)s, size); + memcpy(x->data, (const void *)s, size); return x; } diff --git a/src/sllist.h b/src/sllist.h index ba7d8ea95..e8cb8805d 100644 --- a/src/sllist.h +++ b/src/sllist.h @@ -42,11 +42,11 @@ struct sllnode { struct strnode *new_strnode(char *s); -struct strnode *new_strnode_dup(char *s, const size_t size); +struct strnode *new_strnode_dup(const char *s, const size_t size); struct strnode *dup_strlist(struct strnode *old); -struct sllnode *new_sllnode(void *s, const size_t size); +struct sllnode *new_sllnode(const void *s, const size_t size); #endif /* SLLIST_H */ diff --git a/src/tag.c b/src/tag.c index 00f09f10f..c1ccd0a42 100644 --- a/src/tag.c +++ b/src/tag.c @@ -697,7 +697,7 @@ int mpdTagsAreEqual(MpdTag * tag1, MpdTag * tag2) } static void appendToTagItems(MpdTag * tag, enum tag_type type, - char *value, size_t len) + const char *value, size_t len) { unsigned int i = tag->numOfItems; char *duplicated = xmalloc(len + 1); @@ -718,7 +718,7 @@ static void appendToTagItems(MpdTag * tag, enum tag_type type, } void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType, - char *value, size_t len) + const char *value, size_t len) { if (ignoreTagItems[itemType]) { diff --git a/src/tag.h b/src/tag.h index 74770e49e..a9bf19934 100644 --- a/src/tag.h +++ b/src/tag.h @@ -73,7 +73,7 @@ void clearItemsFromMpdTag(MpdTag * tag, enum tag_type itemType); void freeMpdTag(MpdTag * tag); void addItemToMpdTagWithLen(MpdTag * tag, enum tag_type itemType, - char *value, size_t len); + const char *value, size_t len); #define addItemToMpdTag(tag, itemType, value) \ addItemToMpdTagWithLen(tag, itemType, value, strlen(value)) -- cgit v1.2.3 From 6982a829e22d2bc7cf7c829c4430a4ea6f5bc7fa Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 29 Aug 2008 09:01:53 +0200 Subject: pass constant pointers And again, convert arguments to const. --- src/audio.c | 2 +- src/audio.h | 2 +- src/audioOutput.c | 2 +- src/audioOutput.h | 4 ++-- src/ls.c | 6 +++--- src/ls.h | 4 ++-- src/tagTracker.c | 2 +- src/tagTracker.h | 2 +- src/tree.c | 6 +++--- src/tree.h | 3 ++- 10 files changed, 17 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/audio.c b/src/audio.c index 34b74e6e1..409761177 100644 --- a/src/audio.c +++ b/src/audio.c @@ -419,7 +419,7 @@ void closeAudioDevice(void) audioOpened = 0; } -void sendMetadataToAudioDevice(MpdTag * tag) +void sendMetadataToAudioDevice(const MpdTag * tag) { unsigned int i; diff --git a/src/audio.h b/src/audio.h index c9dea54d2..0032cff22 100644 --- a/src/audio.h +++ b/src/audio.h @@ -55,7 +55,7 @@ int isAudioDeviceOpen(void); int isCurrentAudioFormat(const AudioFormat * audioFormat); -void sendMetadataToAudioDevice(MpdTag * tag); +void sendMetadataToAudioDevice(const MpdTag * tag); /* these functions are called in the main parent process while the child process is busy playing to the audio */ diff --git a/src/audioOutput.c b/src/audioOutput.c index 24779a04d..f165979d0 100644 --- a/src/audioOutput.c +++ b/src/audioOutput.c @@ -244,7 +244,7 @@ void finishAudioOutput(AudioOutput * audioOutput) free(audioOutput->convBuffer); } -void sendMetadataToAudioOutput(AudioOutput * audioOutput, MpdTag * tag) +void sendMetadataToAudioOutput(AudioOutput * audioOutput, const MpdTag * tag) { if (!audioOutput->sendMetdataFunc) return; diff --git a/src/audioOutput.h b/src/audioOutput.h index 71c1e4b14..f82eedfba 100644 --- a/src/audioOutput.h +++ b/src/audioOutput.h @@ -50,7 +50,7 @@ typedef void (*AudioOutputDropBufferedAudioFunc) (AudioOutput * audioOutput); typedef void (*AudioOutputCloseDeviceFunc) (AudioOutput * audioOutput); typedef void (*AudioOutputSendMetadataFunc) (AudioOutput * audioOutput, - MpdTag * tag); + const MpdTag * tag); struct _AudioOutput { int open; @@ -104,7 +104,7 @@ void dropBufferedAudioOutput(AudioOutput * audioOutput); void closeAudioOutput(AudioOutput * audioOutput); void finishAudioOutput(AudioOutput * audioOutput); int keepAudioOutputAlive(AudioOutput * audioOutput, int ms); -void sendMetadataToAudioOutput(AudioOutput * audioOutput, MpdTag * tag); +void sendMetadataToAudioOutput(AudioOutput * audioOutput, const MpdTag * tag); void printAllOutputPluginTypes(FILE * fp); diff --git a/src/ls.c b/src/ls.c index 3032935c6..f87e09fdb 100644 --- a/src/ls.c +++ b/src/ls.c @@ -42,10 +42,10 @@ int printRemoteUrlHandlers(int fd) return 0; } -int isValidRemoteUtf8Url(char *utf8url) +int isValidRemoteUtf8Url(const char *utf8url) { int ret = 0; - char *temp; + const char *temp; switch (isRemoteUrl(utf8url)) { case 1: @@ -82,7 +82,7 @@ int isValidRemoteUtf8Url(char *utf8url) return ret; } -int isRemoteUrl(char *url) +int isRemoteUrl(const char *url) { int count = 0; const char **urlPrefixes = remoteUrlPrefixes; diff --git a/src/ls.h b/src/ls.h index ed49c99d8..ce4f94b56 100644 --- a/src/ls.h +++ b/src/ls.h @@ -25,9 +25,9 @@ int lsPlaylists(int fd, const char *utf8path); const char *getSuffix(const char *utf8file); -int isValidRemoteUtf8Url(char *utf8url); +int isValidRemoteUtf8Url(const char *utf8url); -int isRemoteUrl(char *url); +int isRemoteUrl(const char *url); int myStat(const char *utf8file, struct stat *st); diff --git a/src/tagTracker.c b/src/tagTracker.c index acc8a4d2e..892cc2955 100644 --- a/src/tagTracker.c +++ b/src/tagTracker.c @@ -117,7 +117,7 @@ void resetVisitedFlagsInTagTracker(int type) } } -void visitInTagTracker(int type, char *str) +void visitInTagTracker(int type, const char *str) { TreeIterator iter; diff --git a/src/tagTracker.h b/src/tagTracker.h index 17958f3af..84506426e 100644 --- a/src/tagTracker.h +++ b/src/tagTracker.h @@ -29,7 +29,7 @@ void printMemorySavedByTagTracker(void); void resetVisitedFlagsInTagTracker(int type); -void visitInTagTracker(int type, char *str); +void visitInTagTracker(int type, const char *str); void printVisitedInTagTracker(int fd, int type); diff --git a/src/tree.c b/src/tree.c index 40dc4224c..d583aee7c 100644 --- a/src/tree.c +++ b/src/tree.c @@ -71,7 +71,7 @@ _ClearKeyData(TreeKeyData * keyData) static int -_FindPosition(Tree * tree, TreeNode * node, void * key, int * pos) +_FindPosition(Tree * tree, TreeNode * node, const void * key, int * pos) { #ifdef USE_BINARY_SEARCH int low = 0; @@ -113,7 +113,7 @@ _FindPosition(Tree * tree, TreeNode * node, void * key, int * pos) static int -_Find(TreeIterator * iter, void * key) +_Find(TreeIterator * iter, const void * key) { while (1) { @@ -680,7 +680,7 @@ RemoveFromTreeByIterator(Tree * tree, TreeIterator * iter) } int -FindInTree(Tree * tree, void * key, TreeIterator * iter) +FindInTree(Tree * tree, const void * key, TreeIterator * iter) { TreeIterator i; diff --git a/src/tree.h b/src/tree.h index 4d30e0106..ef397bbd4 100644 --- a/src/tree.h +++ b/src/tree.h @@ -57,6 +57,7 @@ int InsertInTree(Tree * tree, void * key, void * data); int RemoveFromTreeByKey(Tree * tree, void * key); void RemoveFromTreeByIterator(Tree * tree, TreeIterator * iter); -int FindInTree(Tree * tree, void * key, TreeIterator * iter /* can be NULL */); +int FindInTree(Tree * tree, const void * key, + TreeIterator * iter /* can be NULL */); #endif -- cgit v1.2.3