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/inputPlugins/wavpack_plugin.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/inputPlugins/wavpack_plugin.c') 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; -- 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/inputPlugins/wavpack_plugin.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/inputPlugins/wavpack_plugin.c') 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 -- 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/inputPlugins/wavpack_plugin.c') 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/inputPlugins/wavpack_plugin.c') 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