input_stream: non-blocking I/O

Add GMutex, GCond attributes which will be used by callers to
conditionally wait on the stream.

Remove the (now-useless) plugin method buffer(), wait on GCond
instead.  Lock the input_stream before each method call.  Do the same
with the playlist plugins.
This commit is contained in:
Max Kellermann
2011-09-14 21:46:41 +02:00
parent 29241c4f83
commit 754f26a97c
57 changed files with 655 additions and 379 deletions

View File

@@ -112,7 +112,7 @@ decoder_read(G_GNUC_UNUSED struct decoder *decoder,
struct input_stream *is,
void *buffer, size_t length)
{
return input_stream_read(is, buffer, length, NULL);
return input_stream_lock_read(is, buffer, length, NULL);
}
void
@@ -209,8 +209,11 @@ int main(int argc, char **argv)
decoder_plugin_file_decode(decoder.plugin, &decoder,
decoder.uri);
} else if (decoder.plugin->stream_decode != NULL) {
GMutex *mutex = g_mutex_new();
GCond *cond = g_cond_new();
struct input_stream *is =
input_stream_open(decoder.uri, &error);
input_stream_open(decoder.uri, mutex, cond, &error);
if (is == NULL) {
if (error != NULL) {
g_warning("%s", error->message);
@@ -224,6 +227,9 @@ int main(int argc, char **argv)
decoder_plugin_stream_decode(decoder.plugin, &decoder, is);
input_stream_close(is);
g_cond_free(cond);
g_mutex_free(mutex);
} else {
g_printerr("Decoder plugin is not usable\n");
return 1;