diff -ur edam-0.1/Makefile edam-0.2/Makefile --- edam-0.1/Makefile Wed Jan 22 11:04:39 2003 +++ edam-0.2/Makefile Wed Aug 13 09:19:07 2003 @@ -1,5 +1,7 @@ -CFLAGS = -Wall -g -DSYSLOG +CFLAGS = -Wall -g + +RM = rm -f all: edam diff -ur edam-0.1/edam.c edam-0.2/edam.c --- edam-0.1/edam.c Wed Jan 22 11:04:49 2003 +++ edam-0.2/edam.c Wed Aug 13 09:16:42 2003 @@ -763,7 +763,6 @@ struct input_state input_state; fd_set active_fds; struct stream_list list; - struct stream *new_stream; mp3_chunk input_chunk; char scratch[128], *filename; struct playlist pls; @@ -893,7 +892,7 @@ if (nread <= 0) { msg("%s closed connection", - inet_ntoa(new_stream->addr.sin_addr)); + inet_ntoa(list.streams[stream]->addr.sin_addr)); list.streams[stream]->state = STATE_CLOSED; } else diff -ur edam-0.1/mp3.c edam-0.2/mp3.c --- edam-0.1/mp3.c Wed Jan 22 11:05:02 2003 +++ edam-0.2/mp3.c Wed Aug 13 10:06:10 2003 @@ -1,10 +1,7 @@ /* - * *** IMPORTANT *** * Much of this code is derived (some lifted wholesale) from * the excellent mpg123 by Michael Hipp (http://www.mpg123.de/). - * mpg123 is not GPL, therefore neither is this - * *** IMPORTANT *** */ #include @@ -37,21 +34,21 @@ { if ((header & 0xFFE00000) != 0xFFE00000) { - fprintf(stderr, "MPEG header not found!\n"); - fprintf(stderr, "Header: %8lx\nExpect: FFE00000\n", header); + warn("MPEG header error. Expecting 0xFFE00000, got: 0x%08lX", + header & 0xFFE00000); return -1; } if (layer(header) != 3) { - fprintf(stderr, "Layer %ld MPEG found. Only layer 3 supported\n", + err("Layer %ld MPEG found. Only layer 3 supported", 4 - ((header >> 17) & 3)); return -2; } if (lsf(header)) { - fprintf(stderr, "LSF (?) bit set!\n"); + err("LSF (?) bit set!"); return -3; } @@ -155,19 +152,37 @@ return fd; } - - /* OK, so it's a bit gross.. */ char chunk_buffer[1024 * 5]; mp3_chunk read_chunk(int fd) { mp3_chunk chunk; - int nread; + int nread, max_searchbytes = 2048; chunk.data = chunk_buffer; nread = read(fd, chunk.data, 4); + while( nread == 4 + + /* Do we have an mp3 header? */ + && (ntohl(*(unsigned long *)chunk.data) & 0xFFE00000) != 0xFFE00000 + + /* Do we have a TAG? */ + && strncmp(chunk.data, "TAG", 3) != 0 + /* && (ntohl(*(unsigned long *)chunk.data & 0xFFFFFF00)) != 0x54414700 */ + + && --max_searchbytes > 0) + { + chunk.data[0] = chunk.data[1]; + chunk.data[1] = chunk.data[2]; + chunk.data[2] = chunk.data[3]; + + nread = read(fd, chunk.data + 3, 1); + if (nread == 1) nread = 4; + /* dbg("data = %08lX", ntohl(*(unsigned long *)chunk.data)); */ + } + if (nread < 4) { if (nread < 0) @@ -186,6 +201,13 @@ { /* Old style ID3. Means we hit the bottom of the file */ dbg("Skipping old skool ID3"); + chunk.len = 0; + return chunk; + } + + if (max_searchbytes <= 0) + { + err("Search for MPG header failed"); chunk.len = 0; return chunk; }