aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-02 17:10:02 +0100
committerMax Kellermann <max@duempel.org>2008-11-02 17:10:02 +0100
commit2124df13909a2413dfc41684323f4cee78283c31 (patch)
tree0b1b875e475af1f01187cdad83c6662c7e08c5f1
parent395aa4e847424e74b874ce7e04bcec53e7347925 (diff)
downloadmpd-2124df13909a2413dfc41684323f4cee78283c31.tar.gz
mpd-2124df13909a2413dfc41684323f4cee78283c31.tar.xz
mpd-2124df13909a2413dfc41684323f4cee78283c31.zip
decoder: rewind input stream after try_decode()
The try_decode() method may have read some data from the stream, which is now lost. To make this data available to other methods, get it back by rewinding the input stream after each try_decode() invocation. The ogg and wavpack plugins did this manually and inconsistently; this code can now be removed.
Diffstat (limited to '')
-rw-r--r--src/decoder/_ogg_common.c6
-rw-r--r--src/decoder/wavpack_plugin.c2
-rw-r--r--src/decoder_thread.c9
3 files changed, 8 insertions, 9 deletions
diff --git a/src/decoder/_ogg_common.c b/src/decoder/_ogg_common.c
index e18b9dadb..03606b415 100644
--- a/src/decoder/_ogg_common.c
+++ b/src/decoder/_ogg_common.c
@@ -30,13 +30,7 @@ ogg_stream_type ogg_stream_type_detect(struct input_stream *inStream)
unsigned char buf[41];
size_t r;
- input_stream_seek(inStream, 0, SEEK_SET);
-
r = decoder_read(NULL, inStream, buf, sizeof(buf));
-
- if (r > 0)
- input_stream_seek(inStream, 0, SEEK_SET);
-
if (r >= 32 && memcmp(buf, "OggS", 4) == 0 && (
(memcmp(buf+29, "FLAC", 4) == 0
&& memcmp(buf+37, "fLaC", 4) == 0)
diff --git a/src/decoder/wavpack_plugin.c b/src/decoder/wavpack_plugin.c
index 663bc1f2b..14ccb8630 100644
--- a/src/decoder/wavpack_plugin.c
+++ b/src/decoder/wavpack_plugin.c
@@ -424,8 +424,6 @@ static bool wavpack_trydecode(struct input_stream *is)
return false;
WavpackCloseFile(wpc);
- /* Seek it back in order to play from the first byte. */
- input_stream_seek(is, 0, SEEK_SET);
return true;
}
diff --git a/src/decoder_thread.c b/src/decoder_thread.c
index 403c2bac8..d66094cd2 100644
--- a/src/decoder_thread.c
+++ b/src/decoder_thread.c
@@ -32,10 +32,17 @@ static bool
decoder_try_decode(const struct decoder_plugin *plugin,
struct input_stream *input_stream)
{
+ bool ret;
+
if (plugin->try_decode == NULL)
return true;
- return plugin->try_decode(input_stream);
+ ret = plugin->try_decode(input_stream);
+
+ /* rewind the stream, so the next reader gets a fresh start */
+ input_stream_seek(input_stream, 0, SEEK_SET);
+
+ return ret;
}
static void decodeStart(void)