aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputStream_http.c
diff options
context:
space:
mode:
authorQball Cow <qball@qballcow.nl>2007-08-19 14:54:12 +0000
committerQball Cow <qball@qballcow.nl>2007-08-19 14:54:12 +0000
commit30c4da1aa14268334cc0808eb5ed7a45d5f20439 (patch)
treed73f2955073b754debe51afa402fd13f72a8898c /src/inputStream_http.c
parent3cee1f6a2ce66f4bb3b04db5ebb00b1dce9d6c25 (diff)
downloadmpd-30c4da1aa14268334cc0808eb5ed7a45d5f20439.tar.gz
mpd-30c4da1aa14268334cc0808eb5ed7a45d5f20439.tar.xz
mpd-30c4da1aa14268334cc0808eb5ed7a45d5f20439.zip
Add kodest wavpack streaming patch
git-svn-id: https://svn.musicpd.org/mpd/branches/q-mpd@6758 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/inputStream_http.c')
-rw-r--r--src/inputStream_http.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index a2b343c6f..f7bcbce0f 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -698,7 +698,16 @@ int inputStream_httpOpen(InputStream * inStream, char *url)
inStream->atEOFFunc = inputStream_httpAtEOF;
inStream->bufferFunc = inputStream_httpBuffer;
- return 0;
+ while (!inputStream_httpAtEOF(inStream)) {
+ if (inputStream_httpBuffer(inStream) >= 0) {
+ return 0;
+ }
+ /* sleep so we don't consume 100% of the cpu */
+ my_usleep(1000);
+ }
+
+ freeInputStreamHTTPData(data);
+ return -1;
}
int inputStream_httpSeek(InputStream * inStream, long offset, int whence)
@@ -721,15 +730,20 @@ int inputStream_httpSeek(InputStream * inStream, long offset, int whence)
default:
return -1;
}
-
data = (InputStreamHTTPData *)inStream->data;
close(data->sock);
data->connState = HTTP_CONN_STATE_REOPEN;
data->buflen = 0;
- inputStream_httpBuffer(inStream);
+ while (!inputStream_httpAtEOF(inStream)) {
+ if (inputStream_httpBuffer(inStream) >= 0) {
+ return 0;
+ }
+ /* sleep so we don't consume 100% of the cpu */
+ my_usleep(1000);
+ }
- return 0;
+ return -1;
}
static void parseIcyMetadata(InputStream * inStream, char *metadata, int size)
@@ -759,8 +773,12 @@ static void parseIcyMetadata(InputStream * inStream, char *metadata, int size)
free(temp);
}
-size_t inputStream_httpRead(InputStream * inStream, void *ptr, size_t size,
- size_t nmemb)
+/*
+ * This stuff can only handle max bufsize sized blocks in the good case.
+ * Good case means the buffer is full.
+ */
+static size_t inputStream_httpRead_(InputStream * inStream, void *ptr,
+ size_t size, size_t nmemb)
{
InputStreamHTTPData *data = (InputStreamHTTPData *) inStream->data;
long tosend = 0;
@@ -826,6 +844,24 @@ size_t inputStream_httpRead(InputStream * inStream, void *ptr, size_t size,
return tosend / size;
}
+/* wrapper for the previous function */
+size_t inputStream_httpRead(InputStream *inStream, void *ptr, size_t size,
+ size_t nmemb)
+{
+ size_t req = nmemb * size;
+ size_t got = 0;
+
+ while (req) {
+ size_t r = inputStream_httpRead_(inStream, ptr + got, 1, req);
+ got += r;
+ req -= r;
+ if (inputStream_httpAtEOF(inStream))
+ break;
+ }
+
+ return got / size;
+}
+
int inputStream_httpClose(InputStream * inStream)
{
InputStreamHTTPData *data = (InputStreamHTTPData *) inStream->data;