static bool wavpack_open_wvc(struct decoder *decoder, struct input_stream *is_wvc, struct wavpack_input *wpi) { char *utf8url; char *wvc_url = NULL; bool ret; char first_byte; size_t nbytes; /* * As we use dc->utf8url, this function will be bad for * single files. utf8url is not absolute file path :/ */ utf8url = decoder_get_uri(decoder); if (utf8url == NULL) { return false; } wvc_url = g_strconcat(utf8url, "c", NULL); g_free(utf8url); ret = input_stream_open(is_wvc, wvc_url); g_free(wvc_url); if (!ret) { return false; } /* * And we try to buffer in order to get know * about a possible 404 error. */ nbytes = decoder_read( decoder, is_wvc, &first_byte, sizeof(first_byte) ); if (nbytes == 0) { input_stream_close(is_wvc); return false; } /* push it back */ wavpack_input_init(wpi, decoder, is_wvc); wpi->last_byte = first_byte; return true; }
static struct input_stream * wavpack_open_wvc(struct decoder *decoder, const char *uri, struct wavpack_input *wpi) { struct input_stream *is_wvc; char *wvc_url = NULL; char first_byte; size_t nbytes; /* * As we use dc->utf8url, this function will be bad for * single files. utf8url is not absolute file path :/ */ if (uri == NULL) return false; wvc_url = g_strconcat(uri, "c", NULL); is_wvc = input_stream_open(wvc_url, NULL); g_free(wvc_url); if (is_wvc == NULL) return NULL; /* * And we try to buffer in order to get know * about a possible 404 error. */ nbytes = decoder_read( decoder, is_wvc, &first_byte, sizeof(first_byte) ); if (nbytes == 0) { input_stream_close(is_wvc); return NULL; } /* push it back */ wavpack_input_init(wpi, decoder, is_wvc); wpi->last_byte = first_byte; return is_wvc; }
/* * Decodes a stream. */ static void wavpack_streamdecode(struct decoder * decoder, struct input_stream *is) { char error[ERRORLEN]; WavpackContext *wpc; struct input_stream *is_wvc; int open_flags = OPEN_NORMALIZE; struct wavpack_input isp, isp_wvc; bool can_seek = is->seekable; is_wvc = wavpack_open_wvc(decoder, is->uri, &isp_wvc); if (is_wvc != NULL) { open_flags |= OPEN_WVC; can_seek &= is_wvc->seekable; } if (!can_seek) { open_flags |= OPEN_STREAMING; } wavpack_input_init(&isp, decoder, is); wpc = WavpackOpenFileInputEx( &mpd_is_reader, &isp, open_flags & OPEN_WVC ? &isp_wvc : NULL, error, open_flags, 23 ); if (wpc == NULL) { g_warning("failed to open WavPack stream: %s\n", error); return; } wavpack_decode(decoder, wpc, can_seek); WavpackCloseFile(wpc); if (open_flags & OPEN_WVC) { input_stream_close(is_wvc); } }