From b06aad7e49dde2636c639092ee726de589c3fcd6 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sun, 17 Apr 2005 21:41:42 +0000 Subject: [PATCH] make ogg and flac single-pass scanners like wma --- src/flac.c | 72 +++++++++++------------------------------------ src/mp3-scanner.c | 11 ++++---- src/ogg.c | 2 +- 3 files changed, 23 insertions(+), 62 deletions(-) diff --git a/src/flac.c b/src/flac.c index 0b0ccee4..9e0d028d 100644 --- a/src/flac.c +++ b/src/flac.c @@ -48,15 +48,27 @@ #include -int scan_get_flacfileinfo(char *filename, MP3FILE *pmp3) -{ + +#define GET_VORBIS_COMMENT(comment, name, len) \ + (((strncasecmp(name, (comment).entry, strlen(name)) == 0) && \ + ((comment).entry[strlen(name)] == '=')) ? \ + ((*(len) = (comment).length - (strlen(name) + 1)), \ + (&((comment).entry[strlen(name) + 1]))) : \ + NULL) + +int scan_get_flacinfo(char *filename, MP3FILE *pmp3) { FLAC__Metadata_Chain *chain; FLAC__Metadata_Iterator *iterator; FLAC__StreamMetadata *block; - int rv = -1; + int found=0; unsigned int sec, ms; FILE *f; + int i; + char *val; + size_t len; + char tmp; + /* get file length */ if (!(f = fopen(filename, "rb"))) { DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n", filename); return -1; @@ -98,59 +110,9 @@ int scan_get_flacfileinfo(char *filename, MP3FILE *pmp3) pmp3->song_length = (sec * 1000) + ms; pmp3->bitrate = (pmp3->file_size) / (((sec * 1000) + ms) / 8); pmp3->samplerate = block->data.stream_info.sample_rate; - rv = 0; + found=1; break; } - } while (FLAC__metadata_iterator_next(iterator)); - - if (rv < 0) { - DPRINTF(E_WARN,L_SCAN,"Cannot find FLAC metadata in %s\n", filename); - } - - FLAC__metadata_iterator_delete(iterator); - FLAC__metadata_chain_delete(chain); - return rv; -} - -#define GET_VORBIS_COMMENT(comment, name, len) \ - (((strncasecmp(name, (comment).entry, strlen(name)) == 0) && \ - ((comment).entry[strlen(name)] == '=')) ? \ - ((*(len) = (comment).length - (strlen(name) + 1)), \ - (&((comment).entry[strlen(name) + 1]))) : \ - NULL) - -int scan_get_flactags(char *filename, MP3FILE *pmp3) -{ - FLAC__Metadata_Chain *chain; - FLAC__Metadata_Iterator *iterator; - FLAC__StreamMetadata *block; - int i; - char *val; - size_t len; - char tmp; - int found = 0; - - chain = FLAC__metadata_chain_new(); - if (! chain) { - DPRINTF(E_WARN,L_SCAN,"Cannot allocate FLAC metadata chain\n"); - return 0; - } - if (! FLAC__metadata_chain_read(chain, filename)) { - DPRINTF(E_WARN,L_SCAN,"Cannot read FLAC metadata from %s\n", filename); - FLAC__metadata_chain_delete(chain); - return 0; - } - - iterator = FLAC__metadata_iterator_new(); - if (! iterator) { - DPRINTF(E_WARN,L_SCAN,"Cannot allocate FLAC metadata iterator\n"); - FLAC__metadata_chain_delete(chain); - return 0; - } - - FLAC__metadata_iterator_init(iterator, chain); - do { - block = FLAC__metadata_iterator_get_block(iterator); if (block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { { for (i = 0; i < block->data.vorbis_comment.num_comments; i++) { @@ -204,7 +166,7 @@ int scan_get_flactags(char *filename, MP3FILE *pmp3) } } while (FLAC__metadata_iterator_next(iterator)); - if (! found) { + if (!found) { DPRINTF(E_WARN,L_SCAN,"Cannot find FLAC metadata in %s\n", filename); } diff --git a/src/mp3-scanner.c b/src/mp3-scanner.c index 3caf3a2e..c8f64202 100644 --- a/src/mp3-scanner.c +++ b/src/mp3-scanner.c @@ -304,12 +304,11 @@ static time_t mac_to_unix_time(int t); static TAGHANDLER *scan_gethandler(char *type); #ifdef OGGVORBIS -extern int scan_get_oggfileinfo(char *filename, MP3FILE *pmp3); +extern int scan_get_ogginfo(char *filename, MP3FILE *pmp3); #endif #ifdef FLAC -extern int scan_get_flacfileinfo(char *filename, MP3FILE *pmp3); -extern int scan_get_flactags(char *filename, MP3FILE *pmp3); +extern int scan_get_flacinfo(char *filename, MP3FILE *pmp3); #endif /** \see wma.c */ @@ -347,11 +346,11 @@ static TAGHANDLER taghandlers[] = { { "url", scan_get_nultags, scan_get_urlfileinfo, "pls", NULL, "Playlist URL" }, { "pls", scan_get_nultags, scan_get_urlfileinfo, "pls", NULL, "Playlist URL" }, #ifdef OGGVORBIS - { "ogg", scan_get_nultags, scan_get_oggfileinfo, "ogg", "ogg", "Ogg Vorbis audio file" }, + { "ogg", scan_get_nultags, scan_get_ogginfo, "ogg", "ogg", "Ogg Vorbis audio file" }, #endif #ifdef FLAC - { "flac", scan_get_flactags, scan_get_flacfileinfo, "flac","flac", "FLAC audio file" }, - { "fla", scan_get_flactags, scan_get_flacfileinfo, "flac","flac", "FLAC audio file" }, + { "flac", scan_get_nulags, scan_get_flacinfo, "flac","flac", "FLAC audio file" }, + { "fla", scan_get_nultags, scan_get_flacinfo, "flac","flac", "FLAC audio file" }, #endif { NULL, NULL, NULL, NULL, NULL, NULL } }; diff --git a/src/ogg.c b/src/ogg.c index ec2a6bac..8cd86b77 100644 --- a/src/ogg.c +++ b/src/ogg.c @@ -15,7 +15,7 @@ #include "err.h" #include "mp3-scanner.h" -int scan_get_oggfileinfo(char *filename, MP3FILE *pmp3) { +int scan_get_ogginfo(char *filename, MP3FILE *pmp3) { FILE *f; OggVorbis_File vf; vorbis_comment *comment = NULL;