aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-06-07 05:00:56 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-06-07 05:00:56 +0000
commit283e34eaae554604ed1f2f848026840c0eed3dfd (patch)
tree1ca514a48ce28be1da09eee5eed95435b760b9ad /src
parent74f1c8c0181ce00546455b5408a186cca02f16cb (diff)
downloadmpd-283e34eaae554604ed1f2f848026840c0eed3dfd.tar.gz
mpd-283e34eaae554604ed1f2f848026840c0eed3dfd.tar.xz
mpd-283e34eaae554604ed1f2f848026840c0eed3dfd.zip
icy metadata! wahoo
still lots some debug code with print out's, so don't bitch about it! git-svn-id: https://svn.musicpd.org/mpd/trunk@1364 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r--src/decode.c6
-rw-r--r--src/inputPlugins/mp3_plugin.c39
-rw-r--r--src/inputPlugins/ogg_plugin.c2
-rw-r--r--src/inputStream.c13
-rw-r--r--src/inputStream.h1
-rw-r--r--src/inputStream_file.c3
-rw-r--r--src/inputStream_http.c80
7 files changed, 116 insertions, 28 deletions
diff --git a/src/decode.c b/src/decode.c
index ea41aef31..202415934 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -287,12 +287,12 @@ void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
return;
}
- if(inStream.metaTitle) {
+ /*if(inStream.metaName) {
MpdTag * tag = newMpdTag();
- tag->name = strdup(inStream.metaTitle);
+ tag->name = strdup(inStream.metaName);
copyMpdTagToOutputBuffer(cb, tag);
freeMpdTag(tag);
- }
+ }*/
/* reset Metadata in OutputBuffer */
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index f2ad57500..2921c9351 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -531,6 +531,18 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) {
default:
mad_synth_frame(&data->synth,&data->frame);
+ if(data->inStream->metaTitle) {
+ MpdTag * tag = newMpdTag();
+ if(data->inStream->metaName) {
+ tag->name = strdup(data->inStream->metaName);
+ }
+ tag->title = strdup(data->inStream->metaTitle);
+ free(data->inStream->metaTitle);
+ data->inStream->metaTitle = NULL;
+ copyMpdTagToOutputBuffer(cb, tag);
+ freeMpdTag(tag);
+ }
+
for(i=0;i<(data->synth).pcm.length;i++) {
mpd_sint16 * sample;
@@ -643,10 +655,31 @@ int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream) {
dc->totalTime = data.totalTime;
- if(tag) {
- if(inStream->metaTitle) {
+ if(inStream->metaTitle) {
+ if(tag) freeMpdTag(tag);
+ tag = newMpdTag();
+ tag->title = strdup(inStream->metaTitle);
+ /* free ths now, so we know we are done with it */
+ free(inStream->metaTitle);
+ inStream->metaTitle = NULL;
+ if(inStream->metaName) {
+ tag->name = strdup(inStream->metaName);
+ }
+ copyMpdTagToOutputBuffer(cb, tag);
+ freeMpdTag(tag);
+ }
+ else if(tag) {
+ if(inStream->metaName) {
if(tag->name) free(tag->name);
- tag->name = strdup(inStream->metaTitle);
+ tag->name = strdup(inStream->metaName);
+ }
+ copyMpdTagToOutputBuffer(cb, tag);
+ freeMpdTag(tag);
+ }
+ else if(inStream->metaName) {
+ tag = newMpdTag();
+ if(inStream->metaName) {
+ tag->name = strdup(inStream->metaName);
}
copyMpdTagToOutputBuffer(cb, tag);
freeMpdTag(tag);
diff --git a/src/inputPlugins/ogg_plugin.c b/src/inputPlugins/ogg_plugin.c
index a79c0d876..e47471177 100644
--- a/src/inputPlugins/ogg_plugin.c
+++ b/src/inputPlugins/ogg_plugin.c
@@ -291,7 +291,7 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
dc->state = DECODE_STATE_DECODE;
}
comments = ov_comment(&vf, -1)->user_comments;
- putOggCommentsIntoOutputBuffer(cb, inStream->metaTitle,
+ putOggCommentsIntoOutputBuffer(cb, inStream->metaName,
comments);
replayGainScale = ogg_getReplayGainScale(comments);
}
diff --git a/src/inputStream.c b/src/inputStream.c
index 6ff2d1bd5..e15788a13 100644
--- a/src/inputStream.c
+++ b/src/inputStream.c
@@ -26,6 +26,14 @@
#include <unistd.h>
int openInputStream(InputStream * inStream, char * url) {
+ inStream->offset = 0;
+ inStream->size = 0;
+ inStream->error = 0;
+ inStream->mime = NULL;
+ inStream->seekable = 0;
+ inStream->metaName = NULL;
+ inStream->metaTitle = NULL;
+
if(inputStream_fileOpen(inStream,url) == 0) return 0;
if(inputStream_httpOpen(inStream,url) == 0) return 0;
@@ -43,6 +51,10 @@ size_t readFromInputStream(InputStream * inStream, void * ptr, size_t size,
}
int closeInputStream(InputStream * inStream) {
+ if(inStream->mime) free(inStream->mime);
+ if(inStream->metaName) free(inStream->metaName);
+ if(inStream->metaTitle) free(inStream->metaTitle);
+
return inStream->closeFunc(inStream);
}
@@ -53,4 +65,3 @@ int inputStreamAtEOF(InputStream * inStream) {
int bufferInputStream(InputStream * inStream) {
return inStream->bufferFunc(inStream);
}
-/* vim:set shiftwidth=8 tabstop=8 expandtab: */
diff --git a/src/inputStream.h b/src/inputStream.h
index 6e54315fe..af0f706f4 100644
--- a/src/inputStream.h
+++ b/src/inputStream.h
@@ -45,6 +45,7 @@ struct _InputStream {
InputStreamAtEOFFunc atEOFFunc;
InputStreamBufferFunc bufferFunc;
void * data;
+ char * metaName;
char * metaTitle;
};
diff --git a/src/inputStream_file.c b/src/inputStream_file.c
index 814cc3395..5d88fa5ac 100644
--- a/src/inputStream_file.c
+++ b/src/inputStream_file.c
@@ -32,10 +32,7 @@ int inputStream_fileOpen(InputStream * inStream, char * filename) {
return -1;
}
- inStream->offset = 0;
inStream->seekable = 1;
- inStream->mime = NULL;
- inStream->metaTitle = NULL;
fseek(fp,0,SEEK_END);
inStream->size = ftell(fp);
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index 218918829..26637adf3 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -57,6 +57,7 @@ typedef struct _InputStreemHTTPData {
int timesRedirected;
int icyMetaint;
int prebuffer;
+ int icyOffset;
} InputStreamHTTPData;
static InputStreamHTTPData * newInputStreamHTTPData() {
@@ -69,6 +70,7 @@ static InputStreamHTTPData * newInputStreamHTTPData() {
ret->timesRedirected = 0;
ret->icyMetaint = 0;
ret->prebuffer = 0;
+ ret->icyOffset = 0;
return ret;
}
@@ -231,7 +233,7 @@ static int finishHTTPInit(InputStream * inStream) {
"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);
@@ -366,15 +368,16 @@ static int getHTTPHello(InputStream * inStream) {
}
else if(0 == strncmp(cur, "\r\nicy-metaint:", 14)) {
data->icyMetaint = atoi(cur+14);
+ printf("icyMetaint: %i\n", data->icyMetaint);
}
else if(0 == strncmp(cur, "\r\nicy-name:", 11)) {
int incr = 11;
char * temp = strstr(cur+incr,"\r\n");
if(!temp) break;
*temp = '\0';
- if(inStream->metaTitle) free(inStream->metaTitle);
+ if(inStream->metaName) free(inStream->metaName);
while(*(incr+cur) == ' ') incr++;
- inStream->metaTitle = strdup(cur+incr);
+ inStream->metaName = strdup(cur+incr);
*temp = '\r';
}
else if(0 == strncmp(cur, "\r\nx-audiocast-name:", 19)) {
@@ -382,9 +385,9 @@ static int getHTTPHello(InputStream * inStream) {
char * temp = strstr(cur+incr,"\r\n");
if(!temp) break;
*temp = '\0';
- if(inStream->metaTitle) free(inStream->metaTitle);
+ if(inStream->metaName) free(inStream->metaName);
while(*(incr+cur) == ' ') incr++;
- inStream->metaTitle = strdup(cur+incr);
+ inStream->metaName = strdup(cur+incr);
*temp = '\r';
}
else if(0 == strncmp(cur, "\r\nContent-Type:", 15)) {
@@ -439,13 +442,6 @@ int inputStream_httpOpen(InputStream * inStream, char * url) {
inStream->atEOFFunc = inputStream_httpAtEOF;
inStream->bufferFunc = inputStream_httpBuffer;
- inStream->offset = 0;
- inStream->size = 0;
- inStream->error = 0;
- inStream->mime = NULL;
- inStream->seekable = 0;
- inStream->metaTitle = NULL;
-
return 0;
}
@@ -453,12 +449,33 @@ int inputStream_httpSeek(InputStream * inStream, long offset, int whence) {
return -1;
}
+static void parseIcyMetadata(InputStream * inStream, char * metadata,
+ int size)
+{
+ char * r;
+ char * s;
+ char * temp = malloc(size+1);
+ memcpy(temp, metadata, size);
+ temp[size] = '\0';
+ s = strtok_r(temp, ";", &r);
+ while(s) {
+ if(0 == strncmp(s, "StreamTitle=", 12)) {
+ printf("StreamTitle: %s\n", s+12);
+ if(inStream->metaTitle) free(inStream->metaTitle);
+ inStream->metaTitle = strdup(s+12);
+ }
+ s = strtok_r(NULL, ";", &r);
+ }
+ free(temp);
+}
+
size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
size_t nmemb)
{
InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
long tosend = 0;
long inlen = size*nmemb;
+ long maxToSend = data->buflen;
inputStream_httpBuffer(inStream);
@@ -470,15 +487,44 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
return 0;
}
- if(data->prebuffer) return 0;
+ if(data->prebuffer || data->buflen < data->icyMetaint) return 0;
+
+ if(data->icyMetaint > 0) {
+ if(data->icyOffset >= data->icyMetaint) {
+ int metalen = *(data->buffer);
+ metalen <<= 4;
+ if(metalen < 0) metalen = 0;
+ if(metalen+1 > data->buflen) {
+ /* damn that's some fucking big metadata! */
+ if(HTTP_BUFFER_SIZE < metalen+1) {
+ data->connState =
+ HTTP_CONN_STATE_CLOSED;
+ close(data->sock);
+ data->buflen = 0;
+ }
+ return 0;
+ }
+ if(metalen > 0) {
+ parseIcyMetadata(inStream, data->buffer+1,
+ metalen);
+ }
+ data->buflen -= metalen+1;
+ memmove(data->buffer, data->buffer+metalen+1,
+ data->buflen);
+ data->icyOffset = 0;
+ }
+ maxToSend = data->icyMetaint-data->icyOffset;
+ maxToSend = maxToSend > data->buflen ? data->buflen : maxToSend;
+ }
if(data->buflen > 0) {
- tosend = inlen > data->buflen ? data->buflen : inlen;
+ tosend = inlen > maxToSend ? maxToSend : inlen;
tosend = (tosend/size)*size;
memcpy(ptr, data->buffer, tosend);
/*fwrite(ptr,1,readed,stdout);*/
data->buflen -= tosend;
+ data->icyOffset+= tosend;
/*fwrite(data->buffer,1,readed,stdout);*/
memmove(data->buffer, data->buffer+tosend, data->buflen);
@@ -498,7 +544,6 @@ int inputStream_httpClose(InputStream * inStream) {
close(data->sock);
}
- if(inStream->mime) free(inStream->mime);
freeInputStreamHTTPData(data);
return 0;
@@ -538,7 +583,9 @@ int inputStream_httpBuffer(InputStream * inStream) {
return -1;
}
- if(data->buflen == 0) data->prebuffer = 1;
+ if(data->buflen == 0 || data->buflen < data->icyMetaint) {
+ data->prebuffer = 1;
+ }
else if(data->buflen > HTTP_PREBUFFER_SIZE) data->prebuffer = 0;
if(data->connState == HTTP_CONN_STATE_OPEN &&
@@ -563,4 +610,3 @@ int inputStream_httpBuffer(InputStream * inStream) {
return (readed ? 1 : 0);
}
-/* vim:set shiftwidth=8 tabstop=8 expandtab: */