playlist/SoundCloud: move code to Yajl::Parse(InputStream&)

This commit is contained in:
Max Kellermann
2018-01-11 20:02:01 +01:00
parent 7fe07324d7
commit 26b1573cbe
4 changed files with 80 additions and 17 deletions

View File

@@ -22,6 +22,7 @@
#include "../PlaylistPlugin.hxx"
#include "../MemorySongEnumerator.hxx"
#include "lib/yajl/Handle.hxx"
#include "lib/yajl/ParseInputStream.hxx"
#include "config/Block.hxx"
#include "input/InputStream.hxx"
#include "tag/Builder.hxx"
@@ -227,23 +228,7 @@ soundcloud_parse_json(const char *url, Yajl::Handle &handle,
Mutex &mutex, Cond &cond)
{
auto input_stream = InputStream::OpenReady(url, mutex, cond);
const std::lock_guard<Mutex> protect(mutex);
bool done = false;
while (!done) {
unsigned char buffer[4096];
const size_t nbytes =
input_stream->Read(buffer, sizeof(buffer));
if (nbytes == 0)
done = true;
if (done) {
handle.CompleteParse();
} else
handle.Parse(buffer, nbytes);
}
Yajl::ParseInputStream(handle, *input_stream);
}
/**