diff options
author | Max Kellermann <max@duempel.org> | 2009-01-15 22:45:28 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-15 22:45:28 +0100 |
commit | 9cc373d62d702188e6b30bacb517a9e3ac0448a6 (patch) | |
tree | 3068be0eb8151329887109d19abba5faaa824eb3 /src/decoder | |
parent | 0dec3f787ffbf9c48e09a45dae469393a28bdb60 (diff) | |
download | mpd-9cc373d62d702188e6b30bacb517a9e3ac0448a6.tar.gz mpd-9cc373d62d702188e6b30bacb517a9e3ac0448a6.tar.xz mpd-9cc373d62d702188e6b30bacb517a9e3ac0448a6.zip |
flac: splitted flac_copy_vorbis_comment()
Splitted flac_copy_vorbis_comment() into flac_copy_comment() and
flac_copy_comment().
Diffstat (limited to '')
-rw-r--r-- | src/decoder/_flac_common.c | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c index c702f6715..5a16e7748 100644 --- a/src/decoder/_flac_common.c +++ b/src/decoder/_flac_common.c @@ -26,6 +26,8 @@ #include <FLAC/format.h> #include <FLAC/metadata.h> +#include <assert.h> + void flac_data_init(struct flac_data *data, struct decoder * decoder, struct input_stream *input_stream) @@ -114,60 +116,59 @@ flac_comment_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry, return NULL; } -/* tracknumber is used in VCs, MPD uses "track" ..., all the other - * tag names match */ -static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber"; -static const char *VORBIS_COMMENT_DISC_KEY = "discnumber"; - +/** + * Check if the comment's name equals the passed name, and if so, copy + * the comment value into the tag. + */ static bool -flac_copy_vorbis_comment(struct tag *tag, - const FLAC__StreamMetadata_VorbisComment_Entry *entry, - enum tag_type type) +flac_copy_comment(struct tag *tag, + const FLAC__StreamMetadata_VorbisComment_Entry *entry, + const char *name, enum tag_type tag_type) { - const char *str; - size_t slen; - int vlen; const char *value; size_t value_length; - switch (type) { - case TAG_ITEM_TRACK: - str = VORBIS_COMMENT_TRACK_KEY; - break; - case TAG_ITEM_DISC: - str = VORBIS_COMMENT_DISC_KEY; - break; - default: - str = mpdTagItemKeys[type]; - } - slen = strlen(str); - vlen = entry->length - slen - 1; - - value = flac_comment_value(entry, str, &value_length); + value = flac_comment_value(entry, name, &value_length); if (value != NULL) { - tag_add_item_n(tag, type, value, value_length); + tag_add_item_n(tag, tag_type, value, value_length); return true; } return false; } +/* tracknumber is used in VCs, MPD uses "track" ..., all the other + * tag names match */ +static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber"; +static const char *VORBIS_COMMENT_DISC_KEY = "discnumber"; + +static void +flac_parse_comment(struct tag *tag, + const FLAC__StreamMetadata_VorbisComment_Entry *entry) +{ + assert(tag != NULL); + + if (flac_copy_comment(tag, entry, VORBIS_COMMENT_TRACK_KEY, + TAG_ITEM_TRACK) || + flac_copy_comment(tag, entry, VORBIS_COMMENT_DISC_KEY, + TAG_ITEM_DISC)) + return; + + for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) + if (flac_copy_comment(tag, entry, + mpdTagItemKeys[i], i)) + return; +} + void flac_vorbis_comments_to_tag(struct tag *tag, const FLAC__StreamMetadata *block) { - unsigned int i, j; - FLAC__StreamMetadata_VorbisComment_Entry *comments; + FLAC__StreamMetadata_VorbisComment_Entry *comments = + block->data.vorbis_comment.comments; - comments = block->data.vorbis_comment.comments; - - for (i = block->data.vorbis_comment.num_comments; i != 0; --i) { - for (j = TAG_NUM_OF_ITEM_TYPES; j--;) { - if (flac_copy_vorbis_comment(tag, comments, j)) - break; - } - comments++; - } + for (unsigned i = block->data.vorbis_comment.num_comments; i > 0; --i) + flac_parse_comment(tag, comments++); } void flac_metadata_common_cb(const FLAC__StreamMetadata * block, |