aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/flac_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-15 22:43:39 +0100
committerMax Kellermann <max@duempel.org>2009-01-15 22:43:39 +0100
commitf30adc352627d5aaaa933340dee24308e5920f15 (patch)
tree6126fe0c0ea493f80e0628384fd4a2f80caf8485 /src/decoder/flac_plugin.c
parentccea3654945809932a7b85b365af11f91b5a1ded (diff)
downloadmpd-f30adc352627d5aaaa933340dee24308e5920f15.tar.gz
mpd-f30adc352627d5aaaa933340dee24308e5920f15.tar.xz
mpd-f30adc352627d5aaaa933340dee24308e5920f15.zip
flac: always allocate tag object
Free the tag object when it turns out to be empty. This simplifies several functions and APIs.
Diffstat (limited to '')
-rw-r--r--src/decoder/flac_plugin.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/decoder/flac_plugin.c b/src/decoder/flac_plugin.c
index edf268331..e02c13638 100644
--- a/src/decoder/flac_plugin.c
+++ b/src/decoder/flac_plugin.c
@@ -225,7 +225,7 @@ flac_write_cb(const flac_decoder *dec, const FLAC__Frame *frame,
static struct tag *
flac_tag_load(const char *file)
{
- struct tag *ret = NULL;
+ struct tag *tag;
FLAC__Metadata_SimpleIterator *it;
FLAC__StreamMetadata *block = NULL;
@@ -252,27 +252,31 @@ flac_tag_load(const char *file)
g_debug("Reading '%s' metadata gave the following error: %s\n",
file, err);
FLAC__metadata_simple_iterator_delete(it);
- return ret;
+ return NULL;
}
+ tag = tag_new();
do {
block = FLAC__metadata_simple_iterator_get_block(it);
if (!block)
break;
if (block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
- flac_vorbis_comments_to_tag(block, ret);
+ flac_vorbis_comments_to_tag(tag, block);
} else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) {
- if (!ret)
- ret = tag_new();
- ret->time = ((float)block->data.stream_info.
- total_samples) /
+ tag->time = ((float)block->data.stream_info.total_samples) /
block->data.stream_info.sample_rate + 0.5;
}
FLAC__metadata_object_delete(block);
} while (FLAC__metadata_simple_iterator_next(it));
FLAC__metadata_simple_iterator_delete(it);
- return ret;
+
+ if (!tag_is_defined(tag)) {
+ tag_free(tag);
+ tag = NULL;
+ }
+
+ return tag;
}
static struct tag *
@@ -419,20 +423,26 @@ oggflac_tag_dup(const char *file)
goto out;
it = FLAC__metadata_iterator_new();
FLAC__metadata_iterator_init(it, chain);
+
+ ret = tag_new();
do {
if (!(block = FLAC__metadata_iterator_get_block(it)))
break;
if (block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
- ret = flac_vorbis_comments_to_tag(block, ret);
+ flac_vorbis_comments_to_tag(ret, block);
} else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) {
- if (!ret)
- ret = tag_new();
ret->time = ((float)block->data.stream_info.
total_samples) /
block->data.stream_info.sample_rate + 0.5;
}
} while (FLAC__metadata_iterator_next(it));
FLAC__metadata_iterator_delete(it);
+
+ if (!tag_is_defined(ret)) {
+ tag_free(ret);
+ ret = NULL;
+ }
+
out:
FLAC__metadata_chain_delete(chain);
return ret;