decoder/flac: added function flac_data_deinit()

Clean up tag and replay_gain_info there.
This commit is contained in:
Max Kellermann 2009-11-10 21:42:15 +01:00
parent 6a5f4651a1
commit b6a2ffd3d7
4 changed files with 26 additions and 17 deletions

View File

@ -40,6 +40,16 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
data->tag = NULL; data->tag = NULL;
} }
void
flac_data_deinit(struct flac_data *data)
{
if (data->replay_gain_info != NULL)
replay_gain_info_free(data->replay_gain_info);
if (data->tag != NULL)
tag_free(data->tag);
}
static void static void
flac_find_float_comment(const FLAC__StreamMetadata *block, flac_find_float_comment(const FLAC__StreamMetadata *block,
const char *cmnt, float *fl, bool *found_r) const char *cmnt, float *fl, bool *found_r)

View File

@ -162,6 +162,9 @@ void
flac_data_init(struct flac_data *data, struct decoder * decoder, flac_data_init(struct flac_data *data, struct decoder * decoder,
struct input_stream *input_stream); struct input_stream *input_stream);
void
flac_data_deinit(struct flac_data *data);
void flac_metadata_common_cb(const FLAC__StreamMetadata * block, void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
struct flac_data *data); struct flac_data *data);

View File

@ -485,10 +485,7 @@ flac_decode_internal(struct decoder * decoder,
} }
fail: fail:
if (data.replay_gain_info) flac_data_deinit(&data);
replay_gain_info_free(data.replay_gain_info);
tag_free(data.tag);
if (flac_dec) if (flac_dec)
flac_delete(flac_dec); flac_delete(flac_dec);
@ -670,8 +667,7 @@ fail:
if (pathname) if (pathname)
g_free(pathname); g_free(pathname);
if (data.replay_gain_info) flac_data_deinit(&data);
replay_gain_info_free(data.replay_gain_info);
if (flac_dec) if (flac_dec)
flac_delete(flac_dec); flac_delete(flac_dec);
@ -793,8 +789,7 @@ flac_filedecode_internal(struct decoder* decoder,
} }
fail: fail:
if (data.replay_gain_info) flac_data_deinit(&data);
replay_gain_info_free(data.replay_gain_info);
if (flac_dec) if (flac_dec)
flac_delete(flac_dec); flac_delete(flac_dec);

View File

@ -29,11 +29,8 @@
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
static void oggflac_cleanup(struct flac_data *data, static void oggflac_cleanup(OggFLAC__SeekableStreamDecoder * decoder)
OggFLAC__SeekableStreamDecoder * decoder)
{ {
if (data->replay_gain_info)
replay_gain_info_free(data->replay_gain_info);
if (decoder) if (decoder)
OggFLAC__seekable_stream_decoder_delete(decoder); OggFLAC__seekable_stream_decoder_delete(decoder);
} }
@ -264,6 +261,7 @@ oggflac_tag_dup(const char *file)
struct input_stream input_stream; struct input_stream input_stream;
OggFLAC__SeekableStreamDecoder *decoder; OggFLAC__SeekableStreamDecoder *decoder;
struct flac_data data; struct flac_data data;
struct tag *tag;
if (!input_stream_open(&input_stream, file)) if (!input_stream_open(&input_stream, file))
return NULL; return NULL;
@ -280,15 +278,17 @@ oggflac_tag_dup(const char *file)
* data.tag will be set or unset, that's all we care about */ * data.tag will be set or unset, that's all we care about */
decoder = full_decoder_init_and_read_metadata(&data, 1); decoder = full_decoder_init_and_read_metadata(&data, 1);
oggflac_cleanup(&data, decoder); oggflac_cleanup(decoder);
input_stream_close(&input_stream); input_stream_close(&input_stream);
if (!tag_is_defined(data.tag)) { if (tag_is_defined(data.tag)) {
tag_free(data.tag); tag = data.tag;
data.tag = NULL; data.tag = NULL;
} }
return data.tag; flac_data_deinit(&data);
return tag;
} }
static void static void
@ -344,7 +344,8 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *input_stream)
} }
fail: fail:
oggflac_cleanup(&data, decoder); oggflac_cleanup(decoder);
flac_data_deinit(&data);
} }
static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL }; static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL };