aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/oggflac_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/oggflac_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/oggflac_plugin.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/decoder/oggflac_plugin.c b/src/decoder/oggflac_plugin.c
index 237f826d3..667f8b17e 100644
--- a/src/decoder/oggflac_plugin.c
+++ b/src/decoder/oggflac_plugin.c
@@ -24,6 +24,7 @@
#include <glib.h>
#include <OggFLAC/seekable_stream_decoder.h>
+#include <assert.h>
#include <unistd.h>
static void oggflac_cleanup(struct flac_data *data,
@@ -168,16 +169,16 @@ static void of_metadata_dup_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecode
{
struct flac_data *data = (struct flac_data *) vdata;
+ assert(data->tag != NULL);
+
switch (block->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
- if (!data->tag)
- data->tag = tag_new();
data->tag->time = ((float)block->data.stream_info.
total_samples) /
block->data.stream_info.sample_rate + 0.5;
return;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
- flac_vorbis_comments_to_tag(block, data->tag);
+ flac_vorbis_comments_to_tag(data->tag, block);
default:
break;
}
@@ -271,6 +272,8 @@ oggflac_tag_dup(const char *file)
flac_data_init(&data, NULL, &input_stream);
+ data.tag = tag_new();
+
/* errors here won't matter,
* data.tag will be set or unset, that's all we care about */
decoder = full_decoder_init_and_read_metadata(&data, 1);
@@ -278,6 +281,11 @@ oggflac_tag_dup(const char *file)
oggflac_cleanup(&data, decoder);
input_stream_close(&input_stream);
+ if (!tag_is_defined(data.tag)) {
+ tag_free(data.tag);
+ data.tag = NULL;
+ }
+
return data.tag;
}