aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/_flac_common.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-11 07:35:16 +0100
committerMax Kellermann <max@duempel.org>2009-11-11 07:35:16 +0100
commit43549db718f4d3f8fb5809f5bf4dd0e0903e8b04 (patch)
treeef6452ff64d689d6082c5310537a822412539291 /src/decoder/_flac_common.c
parent7c0c8ca8d790eba95eba4138074897e4ceca99df (diff)
downloadmpd-43549db718f4d3f8fb5809f5bf4dd0e0903e8b04.tar.gz
mpd-43549db718f4d3f8fb5809f5bf4dd0e0903e8b04.tar.xz
mpd-43549db718f4d3f8fb5809f5bf4dd0e0903e8b04.zip
decoder/flac: return replay_gain_info object from helper function
Make the function more generic by not passing "struct flac_data" to it.
Diffstat (limited to 'src/decoder/_flac_common.c')
-rw-r--r--src/decoder/_flac_common.c52
1 files changed, 24 insertions, 28 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c
index 9b3272cf2..7516a7ae5 100644
--- a/src/decoder/_flac_common.c
+++ b/src/decoder/_flac_common.c
@@ -54,9 +54,9 @@ flac_data_deinit(struct flac_data *data)
tag_free(data->tag);
}
-static void
+static bool
flac_find_float_comment(const FLAC__StreamMetadata *block,
- const char *cmnt, float *fl, bool *found_r)
+ const char *cmnt, float *fl)
{
int offset;
size_t pos;
@@ -66,12 +66,12 @@ flac_find_float_comment(const FLAC__StreamMetadata *block,
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
cmnt);
if (offset < 0)
- return;
+ return false;
pos = strlen(cmnt) + 1; /* 1 is for '=' */
len = block->data.vorbis_comment.comments[offset].length - pos;
if (len <= 0)
- return;
+ return false;
p = &block->data.vorbis_comment.comments[offset].entry[pos];
tmp = p[len];
@@ -79,37 +79,31 @@ flac_find_float_comment(const FLAC__StreamMetadata *block,
*fl = (float)atof((char *)p);
p[len] = tmp;
- *found_r = true;
+ return true;
}
-static void
-flac_parse_replay_gain(const FLAC__StreamMetadata *block,
- struct flac_data *data)
+static struct replay_gain_info *
+flac_parse_replay_gain(const FLAC__StreamMetadata *block)
{
+ struct replay_gain_info *rgi;
bool found = false;
- if (data->replay_gain_info)
- replay_gain_info_free(data->replay_gain_info);
-
- data->replay_gain_info = replay_gain_info_new();
-
- flac_find_float_comment(block, "replaygain_album_gain",
- &data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].gain,
- &found);
- flac_find_float_comment(block, "replaygain_album_peak",
- &data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak,
- &found);
- flac_find_float_comment(block, "replaygain_track_gain",
- &data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].gain,
- &found);
- flac_find_float_comment(block, "replaygain_track_peak",
- &data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].peak,
- &found);
+ rgi = replay_gain_info_new();
+ found = flac_find_float_comment(block, "replaygain_album_gain",
+ &rgi->tuples[REPLAY_GAIN_ALBUM].gain) ||
+ flac_find_float_comment(block, "replaygain_album_peak",
+ &rgi->tuples[REPLAY_GAIN_ALBUM].peak) ||
+ flac_find_float_comment(block, "replaygain_track_gain",
+ &rgi->tuples[REPLAY_GAIN_TRACK].gain) ||
+ flac_find_float_comment(block, "replaygain_track_peak",
+ &rgi->tuples[REPLAY_GAIN_TRACK].peak);
if (!found) {
- replay_gain_info_free(data->replay_gain_info);
- data->replay_gain_info = NULL;
+ replay_gain_info_free(rgi);
+ rgi = NULL;
}
+
+ return rgi;
}
/**
@@ -236,7 +230,9 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
data->total_time = ((float)si->total_samples) / (si->sample_rate);
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
- flac_parse_replay_gain(block, data);
+ if (data->replay_gain_info)
+ replay_gain_info_free(data->replay_gain_info);
+ data->replay_gain_info = flac_parse_replay_gain(block);
if (data->tag != NULL)
flac_vorbis_comments_to_tag(data->tag, NULL,