aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder_thread.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-12-30 23:27:37 +0100
committerMax Kellermann <max@duempel.org>2010-01-01 17:25:07 +0100
commitd3b763a48c09a60a0c0b5ccb6cccd9376875c470 (patch)
tree83b8794f78ef8941806cf5757888d8abf2eaa126 /src/decoder_thread.c
parent816b6ad4a71c3ade95e62b62396f2b0415c03f20 (diff)
downloadmpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.tar.gz
mpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.tar.xz
mpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.zip
input_stream: return allocated input_stream objects
Major API redesign: don't let the caller allocate the input_stream object. Let each input plugin allocate its own (derived/extended) input_stream pointer. The "data" attribute can now be removed, and all input plugins simply cast the input_stream pointer to their own structure (with an "struct input_stream base" as the first attribute).
Diffstat (limited to 'src/decoder_thread.c')
-rw-r--r--src/decoder_thread.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/decoder_thread.c b/src/decoder_thread.c
index 7e9c820d2..de095216a 100644
--- a/src/decoder_thread.c
+++ b/src/decoder_thread.c
@@ -56,22 +56,23 @@ decoder_lock_get_command(struct decoder_control *dc)
*
* Unlock the decoder before calling this function.
*
- * @return true on success of if #DECODE_COMMAND_STOP is received,
- * false on error
+ * @return an input_stream on success or if #DECODE_COMMAND_STOP is
+ * received, NULL on error
*/
-static bool
-decoder_input_stream_open(struct decoder_control *dc,
- struct input_stream *is, const char *uri)
+static struct input_stream *
+decoder_input_stream_open(struct decoder_control *dc, const char *uri)
{
GError *error = NULL;
+ struct input_stream *is;
- if (!input_stream_open(is, uri, &error)) {
+ is = input_stream_open(uri, &error);
+ if (is == NULL) {
if (error != NULL) {
g_warning("%s", error->message);
g_error_free(error);
}
- return false;
+ return NULL;
}
/* wait for the input stream to become ready; its metadata
@@ -86,11 +87,11 @@ decoder_input_stream_open(struct decoder_control *dc,
input_stream_close(is);
g_warning("%s", error->message);
g_error_free(error);
- return false;
+ return NULL;
}
}
- return true;
+ return is;
}
static bool
@@ -215,12 +216,13 @@ static bool
decoder_run_stream(struct decoder *decoder, const char *uri)
{
struct decoder_control *dc = decoder->dc;
- struct input_stream input_stream;
+ struct input_stream *input_stream;
bool success;
decoder_unlock(dc);
- if (!decoder_input_stream_open(dc, &input_stream, uri)) {
+ input_stream = decoder_input_stream_open(dc, uri);
+ if (input_stream == NULL) {
decoder_lock(dc);
return false;
}
@@ -229,15 +231,15 @@ decoder_run_stream(struct decoder *decoder, const char *uri)
success = dc->command == DECODE_COMMAND_STOP ||
/* first we try mime types: */
- decoder_run_stream_mime_type(decoder, &input_stream) ||
+ decoder_run_stream_mime_type(decoder, input_stream) ||
/* if that fails, try suffix matching the URL: */
- decoder_run_stream_suffix(decoder, &input_stream, uri) ||
+ decoder_run_stream_suffix(decoder, input_stream, uri) ||
/* fallback to mp3: this is needed for bastard streams
that don't have a suffix or set the mimeType */
- decoder_run_stream_fallback(decoder, &input_stream);
+ decoder_run_stream_fallback(decoder, input_stream);
decoder_unlock(dc);
- input_stream_close(&input_stream);
+ input_stream_close(input_stream);
decoder_lock(dc);
return success;
@@ -267,21 +269,21 @@ decoder_run_file(struct decoder *decoder, const char *path_fs)
decoder_unlock(dc);
} else if (plugin->stream_decode != NULL) {
- struct input_stream input_stream;
+ struct input_stream *input_stream;
bool success;
- if (!decoder_input_stream_open(dc, &input_stream,
- path_fs))
+ input_stream = decoder_input_stream_open(dc, path_fs);
+ if (input_stream == NULL)
continue;
decoder_lock(dc);
success = decoder_stream_decode(plugin, decoder,
- &input_stream);
+ input_stream);
decoder_unlock(dc);
- input_stream_close(&input_stream);
+ input_stream_close(input_stream);
if (success) {
decoder_lock(dc);