Commit 38d587aa authored by Max Kellermann's avatar Max Kellermann

decoder/wavpack: wavpack_open_wvc() returns InputStreamPtr

Let std::unique_ptr manage both the InputStream and the WavpackInput.
parent fe9bafa7
...@@ -475,7 +475,7 @@ static WavpackStreamReader mpd_is_reader = { ...@@ -475,7 +475,7 @@ static WavpackStreamReader mpd_is_reader = {
nullptr /* no need to write edited tags */ nullptr /* no need to write edited tags */
}; };
static WavpackInput * static InputStreamPtr
wavpack_open_wvc(Decoder &decoder, const char *uri) wavpack_open_wvc(Decoder &decoder, const char *uri)
{ {
/* /*
...@@ -490,11 +490,7 @@ wavpack_open_wvc(Decoder &decoder, const char *uri) ...@@ -490,11 +490,7 @@ wavpack_open_wvc(Decoder &decoder, const char *uri)
free(wvc_url); free(wvc_url);
}; };
auto is_wvc = decoder_open_uri(decoder, uri, IgnoreError()); return decoder_open_uri(decoder, uri, IgnoreError());
if (is_wvc == nullptr)
return nullptr;
return new WavpackInput(decoder, *is_wvc.release());
} }
/* /*
...@@ -506,18 +502,14 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is) ...@@ -506,18 +502,14 @@ 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 *wvc = wavpack_open_wvc(decoder, is.GetURI()); std::unique_ptr<WavpackInput> wvc;
if (wvc != nullptr) { auto is_wvc = wavpack_open_wvc(decoder, is.GetURI());
if (is_wvc) {
open_flags |= OPEN_WVC; open_flags |= OPEN_WVC;
can_seek &= wvc->is.IsSeekable(); can_seek &= wvc->is.IsSeekable();
}
AtScopeExit(wvc) { wvc.reset(new WavpackInput(decoder, *is_wvc));
if (wvc != nullptr) {
delete &wvc->is;
delete wvc;
} }
};
if (!can_seek) { if (!can_seek) {
open_flags |= OPEN_STREAMING; open_flags |= OPEN_STREAMING;
...@@ -527,7 +519,7 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is) ...@@ -527,7 +519,7 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is)
char error[ERRORLEN]; char error[ERRORLEN];
WavpackContext *wpc = WavpackContext *wpc =
WavpackOpenFileInputEx(&mpd_is_reader, &isp, wvc, WavpackOpenFileInputEx(&mpd_is_reader, &isp, wvc.get(),
error, open_flags, 23); error, open_flags, 23);
if (wpc == nullptr) { if (wpc == nullptr) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment