decoder/wavpack: wavpack_open_wvc() returns WavpackInput*

This commit is contained in:
Max Kellermann 2014-05-22 10:56:27 +02:00
parent 4eeea640f4
commit ba99696771

View File

@ -438,9 +438,8 @@ wavpack_input_init(WavpackInput *isp, Decoder &decoder,
isp->last_byte = EOF; isp->last_byte = EOF;
} }
static InputStream * static WavpackInput *
wavpack_open_wvc(Decoder &decoder, const char *uri, wavpack_open_wvc(Decoder &decoder, const char *uri)
WavpackInput *wpi)
{ {
/* /*
* As we use dc->utf8url, this function will be bad for * As we use dc->utf8url, this function will be bad for
@ -457,8 +456,9 @@ wavpack_open_wvc(Decoder &decoder, const char *uri,
if (is_wvc == nullptr) if (is_wvc == nullptr)
return nullptr; return nullptr;
WavpackInput *wpi = new WavpackInput();
wavpack_input_init(wpi, decoder, *is_wvc); wavpack_input_init(wpi, decoder, *is_wvc);
return is_wvc; return wpi;
} }
/* /*
@ -470,12 +470,10 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is)
int open_flags = OPEN_NORMALIZE; int open_flags = OPEN_NORMALIZE;
bool can_seek = is.IsSeekable(); bool can_seek = is.IsSeekable();
WavpackInput isp_wvc; WavpackInput *wvc = wavpack_open_wvc(decoder, is.GetURI());
InputStream *is_wvc = wavpack_open_wvc(decoder, is.GetURI(), if (wvc != nullptr) {
&isp_wvc);
if (is_wvc != nullptr) {
open_flags |= OPEN_WVC; open_flags |= OPEN_WVC;
can_seek &= is_wvc->IsSeekable(); can_seek &= wvc->is->IsSeekable();
} }
if (!can_seek) { if (!can_seek) {
@ -487,9 +485,7 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is)
char error[ERRORLEN]; char error[ERRORLEN];
WavpackContext *wpc = WavpackContext *wpc =
WavpackOpenFileInputEx(&mpd_is_reader, &isp, WavpackOpenFileInputEx(&mpd_is_reader, &isp, wvc,
open_flags & OPEN_WVC
? &isp_wvc : nullptr,
error, open_flags, 23); error, open_flags, 23);
if (wpc == nullptr) { if (wpc == nullptr) {
@ -501,8 +497,10 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is)
wavpack_decode(decoder, wpc, can_seek); wavpack_decode(decoder, wpc, can_seek);
WavpackCloseFile(wpc); WavpackCloseFile(wpc);
if (open_flags & OPEN_WVC) {
delete is_wvc; if (wvc != nullptr) {
delete wvc->is;
delete wvc;
} }
} }