diff options
Diffstat (limited to '')
-rw-r--r-- | src/IcyMetaDataParser.cxx | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/src/IcyMetaDataParser.cxx b/src/IcyMetaDataParser.cxx index bfa2e8558..4c13c2c2c 100644 --- a/src/IcyMetaDataParser.cxx +++ b/src/IcyMetaDataParser.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -20,11 +20,10 @@ #include "config.h" #include "IcyMetaDataParser.hxx" #include "tag/Tag.hxx" +#include "tag/TagBuilder.hxx" #include "util/Domain.hxx" #include "Log.hxx" -#include <glib.h> - #include <assert.h> #include <string.h> @@ -37,7 +36,7 @@ IcyMetaDataParser::Reset() return; if (data_rest == 0 && meta_size > 0) - g_free(meta_data); + delete[] meta_data; delete tag; @@ -66,7 +65,7 @@ IcyMetaDataParser::Data(size_t length) } static void -icy_add_item(Tag &tag, TagType type, const char *value) +icy_add_item(TagBuilder &tag, TagType type, const char *value) { size_t length = strlen(value); @@ -81,7 +80,7 @@ icy_add_item(Tag &tag, TagType type, const char *value) } static void -icy_parse_tag_item(Tag &tag, const char *name, const char *value) +icy_parse_tag_item(TagBuilder &tag, const char *name, const char *value) { if (strcmp(name, "StreamTitle") == 0) icy_add_item(tag, TAG_TITLE, value); @@ -122,7 +121,7 @@ icy_parse_tag(char *p, char *const end) assert(end != nullptr); assert(p <= end); - Tag *tag = new Tag(); + TagBuilder tag; while (p != end) { const char *const name = p; @@ -153,7 +152,7 @@ icy_parse_tag(char *p, char *const end) *quote = 0; p = quote + 1; - icy_parse_tag_item(*tag, name, value); + icy_parse_tag_item(tag, name, value); char *semicolon = std::find(p, end, ';'); if (semicolon == end) @@ -161,7 +160,7 @@ icy_parse_tag(char *p, char *const end) p = semicolon + 1; } - return tag; + return tag.CommitNew(); } size_t @@ -190,7 +189,7 @@ IcyMetaDataParser::Meta(const void *data, size_t length) /* initialize metadata reader, allocate enough memory (+1 for the null terminator) */ meta_position = 0; - meta_data = (char *)g_malloc(meta_size + 1); + meta_data = new char[meta_size + 1]; } assert(meta_position < meta_size); @@ -211,7 +210,7 @@ IcyMetaDataParser::Meta(const void *data, size_t length) delete tag; tag = icy_parse_tag(meta_data, meta_data + meta_size); - g_free(meta_data); + delete[] meta_data; /* change back to normal data mode */ @@ -221,3 +220,32 @@ IcyMetaDataParser::Meta(const void *data, size_t length) return length; } + +size_t +IcyMetaDataParser::ParseInPlace(void *data, size_t length) +{ + uint8_t *const dest0 = (uint8_t *)data; + uint8_t *dest = dest0; + const uint8_t *src = dest0; + + while (length > 0) { + size_t chunk = Data(length); + if (chunk > 0) { + memmove(dest, src, chunk); + dest += chunk; + src += chunk; + length -= chunk; + + if (length == 0) + break; + } + + chunk = Meta(src, length); + if (chunk > 0) { + src += chunk; + length -= chunk; + } + } + + return dest - dest0; +} |