From 940ecf5345f339b9d3ec3e8029e345540358fa4c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: added decoder_read() On our way to stabilize the decoder API, we will one day remove the input stream functions. The most basic function, read() will be provided by decoder_api.h with this patch. It already contains a loop (still with manual polling), error/eof handling and decoder command checks. This kind of code used to be duplicated in all decoder plugins. --- src/decoder_api.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/decoder_api.c') diff --git a/src/decoder_api.c b/src/decoder_api.c index ffc3aa781..9a8b803d9 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -89,6 +89,30 @@ void decoder_seek_error(struct decoder * decoder) decoder_command_finished(decoder); } +size_t decoder_read(struct decoder *decoder, + InputStream *inStream, + void *buffer, size_t length) +{ + size_t nbytes; + + assert(inStream != NULL); + assert(buffer != NULL); + + while (1) { + /* XXX don't allow decoder==NULL */ + if (decoder != NULL && dc.command != DECODE_COMMAND_NONE) + return 0; + + nbytes = readFromInputStream(inStream, buffer, 1, length); + if (nbytes > 0 || inputStreamAtEOF(inStream)) + return nbytes; + + /* sleep for a fraction of a second! */ + /* XXX don't sleep, wait for an event instead */ + my_usleep(10000); + } +} + /** * All chunks are full of decoded data; wait for the player to free * one. -- cgit v1.2.3