diff --git a/src/plugin.c b/src/plugin.c index 00f42c94..b2bceec0 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -20,7 +20,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #define _XOPEN_SOURCE 500 /** unix98? pthread_once_t, etc */ diff --git a/src/scan-wma.c b/src/scan-wma.c index 74567f00..8ea4c7f0 100644 --- a/src/scan-wma.c +++ b/src/scan-wma.c @@ -242,6 +242,16 @@ typedef struct tag_wma_subheader { unsigned char objectid[16]; long long size; } _PACKED WMA_SUBHEADER; + +typedef struct tag_wma_stream_properties { + unsigned char stream_type[16]; + unsigned char codec_type[16]; + char time_offset[8]; + unsigned int tsdl; + unsigned int ecdl; + unsigned short int flags; + unsigned int reserved; +} _PACKED WMA_STREAM_PROP; #pragma pack() /* @@ -255,7 +265,8 @@ char *wma_utf16toutf8(unsigned char *utf16, int len); int wma_parse_content_description(int fd,int size, MP3FILE *pmp3); int wma_parse_extended_content_description(int fd,int size, MP3FILE *pmp3); int wma_parse_file_properteis(int fd,int size, MP3FILE *pmp3); - +int wma_parse_audio_media(int fd, int size, MP3FILE *pmp3); +int wma_parse_stream_properties(int fd, int size, MP3FILE *pmp3); /** * read an unsigned short int from the fd @@ -325,6 +336,70 @@ int wma_file_read_bytes(int fd,int len, unsigned char **data) { return 1; } + +/** + * another try to get stream codec type + * + * @param fd fd of the file we are reading from -- positioned at start + * @param size size of the content description block + * @param pmp3 the mp3 struct we are filling with gleaned data + */ +int wma_parse_stream_properties(int fd, int size, MP3FILE *pmp3) { + WMA_STREAM_PROP sp; + WMA_GUID *pguid; + + if(r_read(fd,&sp,sizeof(sp)) != sizeof(sp)) + return FALSE; + + pguid = wma_find_guid(sp.stream_type); + if(!pguid) + return TRUE; + + if(strcmp(pguid->name,"ASF_Audio_Media") != 0) + return TRUE; + + /* it is an audio stream... find codec. The Type-Specific + * data should be a WAVEFORMATEX... so we'll leverage + * wma_parse_audio_media + */ + return wma_parse_audio_media(fd,size - sizeof(WMA_STREAM_PROP),pmp3); +} + +/** + * parse the audio media section... This is essentially a + * WAVFORMATEX structure. Generally we only care about the + * codec type. + * + * @param fd fd of the file we are reading from -- positioned at start + * @param size size of the content description block + * @param pmp3 the mp3 struct we are filling with gleaned data + */ +int wma_parse_audio_media(int fd, int size, MP3FILE *pmp3) { + unsigned short int codec; + + if(size < 2) + return TRUE; /* we'll leave it wma. will work or not! */ + + if(!wma_file_read_short(fd,&codec)) { + return FALSE; + } + + DPRINTF(E_DBG,L_SCAN,"WMA Codec Type: %02X\n",codec); + + switch(codec) { + case 0x162: + MAYBEFREE(pmp3->codectype); + pmp3->codectype = strdup("wmap"); /* pro */ + break; + case 0x163: + MAYBEFREE(pmp3->codectype); + pmp3->codectype = strdup("wmal"); /* lossless */ + break; + } + + return TRUE; +} + /** * parse the extended content description object. this is an object that * has ad-hoc tags, basically. @@ -830,6 +905,10 @@ int scan_get_wmainfo(char *filename, MP3FILE *pmp3) { res &= wma_parse_extended_content_description(wma_fd,(int)subhdr.size,pmp3); } else if (strcmp(pguid->name,"ASF_File_Properties_Object")==0) { res &= wma_parse_file_properties(wma_fd,(int)subhdr.size,pmp3); + } else if (strcmp(pguid->name,"ASF_Audio_Media")==0) { + res &= wma_parse_audio_media(wma_fd,(int)subhdr.size,pmp3); + } else if (strcmp(pguid->name,"ASF_Stream_Properties_Object")==0) { + res &= wma_parse_stream_properties(wma_fd,(int)subhdr.size,pmp3); } } else { DPRINTF(E_DBG,L_SCAN,"Unknown subheader: %02hhx%02hhx%02hhx%02hhx-" diff --git a/src/scanner-driver.c b/src/scanner-driver.c index 048c44b4..0fec2f2a 100644 --- a/src/scanner-driver.c +++ b/src/scanner-driver.c @@ -143,7 +143,8 @@ int main(int argc, char *argv[]) { SCANNERLIST *plist; int option; char *ext; - char *configfile; + char *configfile = "mt-daapd.conf"; + int debuglevel=1; memset((void*)&mp3,0x00,sizeof(MP3FILE)); @@ -156,7 +157,7 @@ int main(int argc, char *argv[]) { while((option = getopt(argc, argv, "d:c:")) != -1) { switch(option) { case 'd': - err_setlevel(atoi(optarg)); + debuglevel = atoi(optarg); break; case 'c': configfile=optarg; @@ -182,10 +183,10 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } + err_setdest(LOGDEST_STDERR); + err_setlevel(debuglevel); printf("Getting info for %s\n",argv[0]); - - ext = strrchr(argv[0],'.')+1; plist=scanner_list; diff --git a/src/scanner.mk b/src/scanner.mk index 42d0a669..01cf39e4 100644 --- a/src/scanner.mk +++ b/src/scanner.mk @@ -1,8 +1,8 @@ CC=gcc -CFLAGS := $(CFLAGS) -g -I/opt/local/include -DHAVE_CONFIG_H -I. -I.. -DHOST='"foo"' -DHAVE_SQL -LDFLAGS := $(LDFLAGS) -L/opt/local/lib -lid3tag -logg -lvorbisfile -lFLAC -lvorbis -ltag_c -lsqlite -lsqlite3 +CFLAGS := $(CFLAGS) -g -I/opt/local/include -DHAVE_CONFIG_H -I. -I.. -DHOST='"foo"' -DHAVE_SQL -DHAVE_CONFIG_H +LDFLAGS := $(LDFLAGS) -L/opt/local/lib -lid3tag -logg -lvorbisfile -lFLAC -lvorbis -ltag_c -lsqlite -lsqlite3 -lm TARGET = scanner -OBJECTS=scanner-driver.o restart.o err.o scan-wma.o scan-aac.o scan-wav.o scan-flac.o scan-ogg.o scan-mp3.o scan-url.o scan-mpc.o os-unix.o conf.o ll.o xml-rpc.o webserver.o uici.o rend-win32.o configfile.o db-generic.o ssc.o db-sql-sqlite3.o db-sql-sqlite2.o db-sql.o smart-parser.o +OBJECTS=scanner-driver.o restart.o err.o scan-wma.o scan-aac.o scan-wav.o scan-flac.o scan-ogg.o scan-mp3.o scan-url.o scan-mpc.o os-unix.o conf.o ll.o xml-rpc.o webserver.o uici.o rend-win32.o configfile.o db-generic.o db-sql-sqlite3.o db-sql-sqlite2.o db-sql.o smart-parser.o plugin.o dispatch.o dynamic-art.o $(TARGET): $(OBJECTS) $(CC) -o $(TARGET) $(LDFLAGS) $(OBJECTS)