aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-01-06 08:28:27 +0100
committerMax Kellermann <max@duempel.org>2010-01-06 08:50:35 +0100
commitd6d5caae23f5b452a3d2de9f576d0137bbc472e3 (patch)
tree0a111705bc616f06ab2dcc08456edb8e5600c322
parent382691179f6da54be2b3b1d8bc3146a23b6ea148 (diff)
downloadmpd-d6d5caae23f5b452a3d2de9f576d0137bbc472e3.tar.gz
mpd-d6d5caae23f5b452a3d2de9f576d0137bbc472e3.tar.xz
mpd-d6d5caae23f5b452a3d2de9f576d0137bbc472e3.zip
decoder/flac: moved flac_tag_load() to flac_metadata.c
Make this code is reusable.
-rw-r--r--src/decoder/flac_decoder_plugin.c53
-rw-r--r--src/decoder/flac_metadata.c53
-rw-r--r--src/decoder/flac_metadata.h3
3 files changed, 56 insertions, 53 deletions
diff --git a/src/decoder/flac_decoder_plugin.c b/src/decoder/flac_decoder_plugin.c
index df5778e03..db0c077ea 100644
--- a/src/decoder/flac_decoder_plugin.c
+++ b/src/decoder/flac_decoder_plugin.c
@@ -214,59 +214,6 @@ flac_write_cb(const FLAC__StreamDecoder *dec, const FLAC__Frame *frame,
return flac_common_write(data, frame, buf, nbytes);
}
-static struct tag *
-flac_tag_load(const char *file, const char *char_tnum)
-{
- struct tag *tag;
- FLAC__Metadata_SimpleIterator *it;
- FLAC__StreamMetadata *block = NULL;
-
- it = FLAC__metadata_simple_iterator_new();
- if (!FLAC__metadata_simple_iterator_init(it, file, 1, 0)) {
- const char *err;
- FLAC_API FLAC__Metadata_SimpleIteratorStatus s;
-
- s = FLAC__metadata_simple_iterator_status(it);
-
- switch (s) { /* slightly more human-friendly messages: */
- case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT:
- err = "illegal input";
- break;
- case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE:
- err = "error opening file";
- break;
- case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE:
- err = "not a FLAC file";
- break;
- default:
- err = FLAC__Metadata_SimpleIteratorStatusString[s];
- }
- g_debug("Reading '%s' metadata gave the following error: %s\n",
- file, err);
- FLAC__metadata_simple_iterator_delete(it);
- return NULL;
- }
-
- tag = tag_new();
- do {
- block = FLAC__metadata_simple_iterator_get_block(it);
- if (!block)
- break;
-
- flac_tag_apply_metadata(tag, char_tnum, block);
- FLAC__metadata_object_delete(block);
- } while (FLAC__metadata_simple_iterator_next(it));
-
- FLAC__metadata_simple_iterator_delete(it);
-
- if (!tag_is_defined(tag)) {
- tag_free(tag);
- tag = NULL;
- }
-
- return tag;
-}
-
#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7
static struct tag *
diff --git a/src/decoder/flac_metadata.c b/src/decoder/flac_metadata.c
index b05dca3e5..2bfb1a6f8 100644
--- a/src/decoder/flac_metadata.c
+++ b/src/decoder/flac_metadata.c
@@ -191,3 +191,56 @@ flac_tag_apply_metadata(struct tag *tag, const char *track,
break;
}
}
+
+struct tag *
+flac_tag_load(const char *file, const char *char_tnum)
+{
+ struct tag *tag;
+ FLAC__Metadata_SimpleIterator *it;
+ FLAC__StreamMetadata *block = NULL;
+
+ it = FLAC__metadata_simple_iterator_new();
+ if (!FLAC__metadata_simple_iterator_init(it, file, 1, 0)) {
+ const char *err;
+ FLAC_API FLAC__Metadata_SimpleIteratorStatus s;
+
+ s = FLAC__metadata_simple_iterator_status(it);
+
+ switch (s) { /* slightly more human-friendly messages: */
+ case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT:
+ err = "illegal input";
+ break;
+ case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE:
+ err = "error opening file";
+ break;
+ case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE:
+ err = "not a FLAC file";
+ break;
+ default:
+ err = FLAC__Metadata_SimpleIteratorStatusString[s];
+ }
+ g_debug("Reading '%s' metadata gave the following error: %s\n",
+ file, err);
+ FLAC__metadata_simple_iterator_delete(it);
+ return NULL;
+ }
+
+ tag = tag_new();
+ do {
+ block = FLAC__metadata_simple_iterator_get_block(it);
+ if (!block)
+ break;
+
+ flac_tag_apply_metadata(tag, char_tnum, block);
+ FLAC__metadata_object_delete(block);
+ } while (FLAC__metadata_simple_iterator_next(it));
+
+ FLAC__metadata_simple_iterator_delete(it);
+
+ if (!tag_is_defined(tag)) {
+ tag_free(tag);
+ tag = NULL;
+ }
+
+ return tag;
+}
diff --git a/src/decoder/flac_metadata.h b/src/decoder/flac_metadata.h
index ba90806f7..5c5c6445e 100644
--- a/src/decoder/flac_metadata.h
+++ b/src/decoder/flac_metadata.h
@@ -42,4 +42,7 @@ void
flac_tag_apply_metadata(struct tag *tag, const char *track,
const FLAC__StreamMetadata *block);
+struct tag *
+flac_tag_load(const char *file, const char *char_tnum);
+
#endif