aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-05-18 19:32:05 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-05-18 19:32:05 +0000
commita19a79227c8d7c6bc1ad0606c31657602ca23a85 (patch)
tree9be0bc43581a0c02cea03f69d6d055f612aae370
parenta2b6583db6da3e044f3718f660c7f9a1adf2bb10 (diff)
downloadmpd-a19a79227c8d7c6bc1ad0606c31657602ca23a85.tar.gz
mpd-a19a79227c8d7c6bc1ad0606c31657602ca23a85.tar.xz
mpd-a19a79227c8d7c6bc1ad0606c31657602ca23a85.zip
streaming fixes and such, now it seems to work good, what an annoying bug
to find git-svn-id: https://svn.musicpd.org/mpd/trunk@1066 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/decode.c15
-rw-r--r--src/inputStream_http.c81
-rw-r--r--src/mp3_decode.c8
-rw-r--r--src/player.c4
4 files changed, 59 insertions, 49 deletions
diff --git a/src/decode.c b/src/decode.c
index 49babb31f..3ab15d00b 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -234,13 +234,13 @@ void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
switch(pc->decodeType) {
case DECODE_TYPE_URL:
#ifdef HAVE_MAD
- if(pc->fileSuffix == DECODE_SUFFIX_MP3 || (inStream.mime &&
- 0 == strcmp(inStream.mime, "audio/mpeg")))
+ /*if(pc->fileSuffix == DECODE_SUFFIX_MP3 || (inStream.mime &&
+ 0 == strcmp(inStream.mime, "audio/mpeg")))*/
{
ret = mp3_decode(cb,dc,&inStream);
break;
}
- else ret = DECODE_ERROR_UNKTYPE;
+ /*else ret = DECODE_ERROR_UNKTYPE;*/
#endif
case DECODE_TYPE_FILE:
#ifdef HAVE_MAD
@@ -374,6 +374,9 @@ void decode() {
int fadePosition;
int nextChunk = -1;
int test;
+ char silence[CHUNK_SIZE];
+
+ memset(silence,0,CHUNK_SIZE);
if(waitOnDecode(pc,dc,cb)<0) return;
@@ -533,7 +536,11 @@ void decode() {
quit = 1;
break;
}
- else my_usleep(1000);
+ else {
+ if(playAudio(silence, CHUNK_SIZE) < 0) {
+ quit = 1;
+ }
+ }
}
pc->totalPlayTime+= pc->elapsedTime-pc->beginTime; \
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index 9d0909ba2..964039a35 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -40,6 +40,7 @@
#define HTTP_CONN_STATE_REOPEN 4
#define HTTP_BUFFER_SIZE 524289
+#define HTTP_PREBUFFER_SIZE (HTTP_BUFFER_SIZE >> 2)
#define HTTP_REDIRECT_MAX 10
@@ -50,10 +51,11 @@ typedef struct _InputStreemHTTPData {
int sock;
int connState;
char buffer[HTTP_BUFFER_SIZE];
- int buflen;
+ size_t buflen;
int timesRedirected;
int icyMetaint;
char * icyName;
+ int prebuffer;
} InputStreamHTTPData;
static InputStreamHTTPData * newInputStreamHTTPData() {
@@ -66,6 +68,7 @@ static InputStreamHTTPData * newInputStreamHTTPData() {
ret->timesRedirected = 0;
ret->icyName = NULL;
ret->icyMetaint = 0;
+ ret->prebuffer = 0;
return ret;
}
@@ -223,12 +226,13 @@ static int finishHTTPInit(InputStream * inStream) {
}
memset(request, 0, 2049);
+ /* deal with ICY metadata later, for now its fucking up stuff! */
snprintf(request, 2048, "GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Connection: close\r\n"
"User-Agent: %s/%s\r\n"
"Range: bytes=%ld-\r\n"
- "Icy-Metadata:1\r\n"
+ /*"Icy-Metadata:1\r\n"*/
"\r\n",
data->path, data->host, "httpTest", "0.0.0",
inStream->offset);
@@ -253,7 +257,7 @@ static int getHTTPHello(InputStream * inStream) {
char * needle;
char * cur = data->buffer;
int rc;
- int readed;
+ long readed;
FD_ZERO(&readSet);
FD_SET(data->sock, &readSet);
@@ -381,13 +385,11 @@ static int getHTTPHello(InputStream * inStream) {
*temp = '\r';
}
else if(0 == strncmp(cur, "\r\nContent-Type:", 15)) {
- char * temp2 = cur+15;
- char * temp = strstr(temp2,"\r\n");
+ char * temp = strstr(cur+15,"\r\n");
if(!temp) break;
- while(*temp2 && *temp2==' ') temp2++;
*temp = '\0';
if(inStream->mime) free(inStream->mime);
- inStream->mime = strdup(temp2);
+ inStream->mime = strdup(cur+15);
*temp = '\r';
}
@@ -397,12 +399,14 @@ static int getHTTPHello(InputStream * inStream) {
if(inStream->size <= 0) inStream->seekable = 0;
needle += 4; /* 4 == strlen("\r\n\r\n") */
- data->buflen -= data->buffer+data->buflen-needle;
+ data->buflen -= (needle-data->buffer);
/*fwrite(data->buffer, 1, data->buflen, stdout);*/
memmove(data->buffer, needle, data->buflen);
data->connState = HTTP_CONN_STATE_OPEN;
+ data->prebuffer = 1;
+
return 0;
}
@@ -444,8 +448,8 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
size_t nmemb)
{
InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
- int readed = 0;
- int inlen = size*nmemb;
+ long tosend = 0;
+ long inlen = size*nmemb;
inputStream_httpBuffer(inStream);
@@ -457,17 +461,22 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
return 0;
}
- if(data->buflen > 0) {
- readed = inlen > data->buflen ? data->buflen : inlen;
-
- memcpy(ptr, data->buffer, readed);
- data->buflen -= readed;
- memmove(data->buffer, data->buffer+readed, data->buflen);
+ if(data->prebuffer) return 0;
- inStream->offset+= readed;
+ if(data->buflen > 0) {
+ tosend = inlen > data->buflen ? data->buflen : inlen;
+ tosend = (tosend/size)*size;
+
+ memcpy(ptr, data->buffer, tosend);
+ /*fwrite(ptr,1,readed,stdout);*/
+ data->buflen -= tosend;
+ /*fwrite(data->buffer,1,readed,stdout);*/
+ memmove(data->buffer, data->buffer+tosend, data->buflen);
+
+ inStream->offset += tosend;
}
- return readed;
+ return tosend/size;
}
int inputStream_httpClose(InputStream * inStream) {
@@ -498,10 +507,7 @@ int inputStream_httpAtEOF(InputStream * inStream) {
int inputStream_httpBuffer(InputStream * inStream) {
InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
- int readed = 0;
- fd_set readSet;
- struct timeval tv;
- int ret;
+ ssize_t readed = 0;
if(data->connState == HTTP_CONN_STATE_REOPEN) {
if(initHTTPConnection(inStream) < 0) return -1;
@@ -523,36 +529,29 @@ int inputStream_httpBuffer(InputStream * inStream) {
return -1;
}
+ if(data->buflen == 0) data->prebuffer = 1;
+ else if(data->buflen > HTTP_PREBUFFER_SIZE) data->prebuffer = 0;
+
if(data->connState == HTTP_CONN_STATE_OPEN &&
data->buflen < HTTP_BUFFER_SIZE-1)
{
- FD_ZERO(&readSet);
- FD_SET(data->sock, &readSet);
-
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
- ret = select(data->sock+1,&readSet,NULL,NULL,&tv);
- if(ret == 0 || (ret < 0 && errno == EINTR)) ret = 0;
- else if(ret < 0) {
- data->connState = HTTP_CONN_STATE_CLOSED;
- close(data->sock);
- return 0;
- }
-
- if(ret == 0) return 0;
-
- readed = recv(data->sock, data->buffer+data->buflen,
- HTTP_BUFFER_SIZE-1-data->buflen, 0);
+ readed = read(data->sock, data->buffer+data->buflen,
+ (size_t)(HTTP_BUFFER_SIZE-1-data->buflen));
if(readed < 0 && (errno == EAGAIN || errno == EINTR));
else if(readed <= 0) {
close(data->sock);
data->connState = HTTP_CONN_STATE_CLOSED;
}
- else data->buflen += readed;
+ else {
+ /*fwrite(data->buffer+data->buflen,1,readed,stdout);*/
+ data->buflen += readed;
+ }
+
}
+ if(data->buflen > HTTP_PREBUFFER_SIZE) data->prebuffer = 0;
+
return 0;
}
/* vim:set shiftwidth=8 tabstop=8 expandtab: */
diff --git a/src/mp3_decode.c b/src/mp3_decode.c
index 116083eb5..501042f76 100644
--- a/src/mp3_decode.c
+++ b/src/mp3_decode.c
@@ -213,7 +213,9 @@ int decodeNextFrameHeader(mp3DecodeData * data) {
}
}
#endif
- if(MAD_RECOVERABLE((data->stream).error)) return DECODE_SKIP;
+ if(MAD_RECOVERABLE((data->stream).error)) {
+ return DECODE_SKIP;
+ }
else {
if((data->stream).error==MAD_ERROR_BUFLEN) return DECODE_CONT;
else
@@ -249,7 +251,9 @@ int decodeNextFrame(mp3DecodeData * data) {
}
}
#endif
- if(MAD_RECOVERABLE((data->stream).error)) return DECODE_SKIP;
+ if(MAD_RECOVERABLE((data->stream).error)) {
+ return DECODE_SKIP;
+ }
else {
if((data->stream).error==MAD_ERROR_BUFLEN) return DECODE_CONT;
else
diff --git a/src/player.c b/src/player.c
index a05b43b14..aa3f34362 100644
--- a/src/player.c
+++ b/src/player.c
@@ -249,9 +249,9 @@ void playerKill() {
int pid;
PlayerControl * pc = &(getPlayerData()->playerControl);
- playerStop(stderr);
+ /*playerStop(stderr);
playerCloseAudio(stderr);
- if(player_pid>0 && pc->closeAudio) sleep(1);
+ if(player_pid>0 && pc->closeAudio) sleep(1);*/
pid = player_pid;
if(pid>0) kill(pid,SIGTERM);