From: Andre Date: Sat, 13 May 2006 21:18:44 +0000 (+0200) Subject: random/mysql selector: make it find m4a files X-Git-Tag: v0.2.14~119 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=e921be422a216b87e3e6812f16b27c9a6927099d;p=paraslash.git random/mysql selector: make it find m4a files This is achieved by adding an array of typical suffixes for the audio format to struct audio_format_handler. --- diff --git a/aac_afh.c b/aac_afh.c index d6f37fcb..55efeefa 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -233,6 +233,7 @@ static char *aac_read_chunk(long unsigned current_chunk, ssize_t *len) return (char *)inbuf; } +static const char* aac_suffixes[] = {"m4a", NULL}; /** the init function of the aac audio format handler */ void aac_afh_init(void *p) { @@ -245,4 +246,5 @@ void aac_afh_init(void *p) af->chunk_tv.tv_sec = 0; af->chunk_tv.tv_usec = 23120; tv_scale(3, &af->chunk_tv, &af->eof_tv); + af->suffixes = aac_suffixes; } diff --git a/afs.h b/afs.h index 19d5b685..3f9c7fc6 100644 --- a/afs.h +++ b/afs.h @@ -130,6 +130,9 @@ struct audio_format_handler { char * (*read_chunk)(long unsigned chunk_num, ssize_t *len); }; +extern struct audio_format_handler afl[]; +#define FOR_EACH_AUDIO_FORMAT(i) for (i = 0; afl[i].name; i++) + void afs_init(void); void afs_send_chunk(void); struct timeval *afs_preselect(void); diff --git a/command.c b/command.c index 5d785f5c..f2c54973 100644 --- a/command.c +++ b/command.c @@ -44,7 +44,6 @@ extern const char *status_item_list[NUM_STAT_ITEMS]; extern struct misc_meta_data *mmd; extern struct gengetopt_args_info conf; extern struct audio_file_selector selectors[]; -extern struct audio_format_handler afl[]; extern struct sender senders[]; extern char *user_list; struct sockaddr_in *in_addr; diff --git a/db.c b/db.c index 26f82d4a..cb6f692a 100644 --- a/db.c +++ b/db.c @@ -33,19 +33,20 @@ */ static int match_audio_file_name(char *name) { - int i, len = strlen(name); - const char *pattern[] = {SUPPORTED_AUDIO_FORMATS_ARRAY}; + int i,j, len = strlen(name); - for (i = 0; pattern[i]; i++) { - const char *p = pattern[i]; - int plen = strlen(p); - if (len < plen + 1) - continue; - if (name[len - plen - 1] != '.') - continue; - if (strcasecmp(name + len - plen, p)) - continue; - return 1; + FOR_EACH_AUDIO_FORMAT(i) { + for (j = 0; afl[i].suffixes[j]; j++) { + const char *p = afl[i].suffixes[j]; + int plen = strlen(p); + if (len < plen + 1) + continue; + if (name[len - plen - 1] != '.') + continue; + if (strcasecmp(name + len - plen, p)) + continue; + return 1; + } } return 0; } diff --git a/mp3.c b/mp3.c index b9b21a94..bac84b6f 100644 --- a/mp3.c +++ b/mp3.c @@ -481,6 +481,7 @@ static void mp3_close_audio_file(void) mp3.file = NULL; } +static const char* mp3_suffixes[] = {"mp3", NULL}; void mp3_init(void *p) { af = p; @@ -492,4 +493,5 @@ void mp3_init(void *p) /* eof_tv gets overwritten in mp3_get_file_info() */ af->eof_tv.tv_sec = 0; af->eof_tv.tv_usec = 100 * 1000; + af->suffixes = mp3_suffixes; } diff --git a/ogg.c b/ogg.c index e5647b26..fa935d50 100644 --- a/ogg.c +++ b/ogg.c @@ -345,6 +345,7 @@ static char *ogg_get_header_info(int *len) return header; } +static const char* ogg_suffixes[] = {"ogg", NULL}; void ogg_init(void *p) { af = p; @@ -356,4 +357,5 @@ void ogg_init(void *p) af->chunk_tv.tv_sec = 0; af->chunk_tv.tv_usec = 250 * 1000; tv_scale(3, &af->chunk_tv, &af->eof_tv); + af->suffixes = ogg_suffixes; } diff --git a/server.c b/server.c index 62427717..56162735 100644 --- a/server.c +++ b/server.c @@ -61,7 +61,6 @@ char *user_list = NULL; extern void dccp_send_init(struct sender *); extern void http_send_init(struct sender *); extern void ortp_send_init(struct sender *); -extern struct audio_format_handler afl[]; /* TODO: This is better handled by autoconf */ /** the list of supported audio file selectors */