aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-26 08:27:14 +0200
committerMax Kellermann <max@duempel.org>2008-08-26 08:27:14 +0200
commit2e822a577d95c962b871bf7106b2268ac249ea30 (patch)
tree1861fd59625c829fe0889f7dcbd599863e423c84 /src
parentaf58de65436ea93299edf58248a68b62d9610164 (diff)
downloadmpd-2e822a577d95c962b871bf7106b2268ac249ea30.tar.gz
mpd-2e822a577d95c962b871bf7106b2268ac249ea30.tar.xz
mpd-2e822a577d95c962b871bf7106b2268ac249ea30.zip
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().
Diffstat (limited to 'src')
-rw-r--r--src/inputPlugins/wavpack_plugin.c145
1 files changed, 66 insertions, 79 deletions
diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c
index b641ab7dc..af4a75ebf 100644
--- a/src/inputPlugins/wavpack_plugin.c
+++ b/src/inputPlugins/wavpack_plugin.c
@@ -434,98 +434,87 @@ static unsigned int wavpack_trydecode(InputStream *is)
return 1;
}
-/*
- * Decodes a stream.
- */
-static int wavpack_streamdecode(struct decoder * decoder, InputStream *is)
+static int wavpack_open_wvc(struct decoder *decoder,
+ InputStream *is_wvc)
{
- char error[ERRORLEN];
- WavpackContext *wpc;
- InputStream is_wvc;
- int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/;
+ char tmp[MPD_PATH_MAX];
+ const char *utf8url;
+ size_t len;
char *wvc_url = NULL;
- int err;
- InputStreamPlus isp, isp_wvc;
- int canseek;
+ int ret;
+
+ /*
+ * As we use dc->utf8url, this function will be bad for
+ * single files. utf8url is not absolute file path :/
+ */
+ utf8url = decoder_get_url(decoder, tmp);
+ if (utf8url == NULL)
+ return 0;
- /* Try to find wvc */
- do {
- char tmp[MPD_PATH_MAX];
- const char *utf8url;
- size_t len;
- err = 1;
-
- /*
- * As we use dc.utf8url, this function will be bad for
- * single files. utf8url is not absolute file path :/
- */
- utf8url = decoder_get_url(decoder, tmp);
- if (utf8url == NULL) {
- break;
- }
+ len = strlen(utf8url);
+ if (!len)
+ return 0;
- len = strlen(utf8url);
- if (!len) {
- break;
- }
+ wvc_url = (char *)xmalloc(len + 2); /* +2: 'c' and EOS */
+ if (wvc_url == NULL)
+ return 0;
- wvc_url = (char *)xmalloc(len + 2); /* +2: 'c' and EOS */
- if (wvc_url == NULL) {
- break;
- }
+ memcpy(wvc_url, utf8url, len);
+ wvc_url[len] = 'c';
+ wvc_url[len + 1] = '\0';
- memcpy(wvc_url, utf8url, len);
- wvc_url[len] = 'c';
- wvc_url[len + 1] = '\0';
+ ret = openInputStream(is_wvc, wvc_url);
+ free(wvc_url);
- if (openInputStream(&is_wvc, wvc_url)) {
- break;
+ if (ret)
+ 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 :/
+ */
+ closeInputStream(is_wvc);
+ 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;
- }
+ if (bufferInputStream(is_wvc) >= 0)
+ return 1;
- if (bufferInputStream(&is_wvc) >= 0) {
- err = 0;
- break;
- }
+ if (decoder_get_command(decoder) == DECODE_COMMAND_STOP) {
+ closeInputStream(is_wvc);
+ return 0;
+ }
- if (decoder_get_command(decoder) == DECODE_COMMAND_STOP) {
- break;
- }
+ /* Save some CPU */
+ my_usleep(1000);
+ }
+}
- /* Save some CPU */
- my_usleep(1000);
- }
- if (err) {
- closeInputStream(&is_wvc);
- break;
- }
+/*
+ * Decodes a stream.
+ */
+static int wavpack_streamdecode(struct decoder * decoder, 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;
+ if (wavpack_open_wvc(decoder, &is_wvc)) {
+ initInputStreamPlus(&isp_wvc, decoder, &is_wvc);
open_flags |= OPEN_WVC;
-
- } while (0);
+ }
canseek = can_seek(&isp);
- if (wvc_url != NULL) {
- if (err) {
- free(wvc_url);
- wvc_url = NULL;
- } else {
- initInputStreamPlus(&isp_wvc, decoder, &is_wvc);
- }
- }
initInputStreamPlus(&isp, decoder, is);
wpc = WavpackOpenFileInputEx(&mpd_is_reader, &isp, &isp_wvc, error,
@@ -539,10 +528,8 @@ static int wavpack_streamdecode(struct decoder * decoder, InputStream *is)
wavpack_decode(decoder, wpc, canseek, NULL);
WavpackCloseFile(wpc);
- if (wvc_url != NULL) {
+ if (open_flags & OPEN_WVC)
closeInputStream(&is_wvc);
- free(wvc_url);
- }
closeInputStream(is);
return 0;