aboutsummaryrefslogtreecommitdiff
path: root/src/decoder/mad_decoder_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-02-14 20:36:31 +0100
committerMax Kellermann <max@duempel.org>2010-02-17 07:22:44 +0100
commit5e0117b4441f257fcb1aab48b42a787567ebcbe6 (patch)
tree7233b273814def640145276f1a46d45b8cf274e4 /src/decoder/mad_decoder_plugin.c
parentc05e6a1275621421eb0a7c3112b0401fa458841e (diff)
replay_gain_info: allocate the struct statically
Don't allocate each replay_gain_info object on the heap. Those objects who held a pointer now store a full replay_gain_info object. This reduces the number of allocations and heap fragmentation.
Diffstat (limited to 'src/decoder/mad_decoder_plugin.c')
-rw-r--r--src/decoder/mad_decoder_plugin.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/src/decoder/mad_decoder_plugin.c b/src/decoder/mad_decoder_plugin.c
index 87dfbeab..379cb9b8 100644
--- a/src/decoder/mad_decoder_plugin.c
+++ b/src/decoder/mad_decoder_plugin.c
@@ -300,17 +300,17 @@ static int parse_rva2(struct id3_tag * tag, struct replay_gain_info * replay_gai
#endif
#ifdef HAVE_ID3TAG
-static struct replay_gain_info *
-parse_id3_replay_gain_info(struct id3_tag *tag)
+static bool
+parse_id3_replay_gain_info(struct replay_gain_info *replay_gain_info,
+ struct id3_tag *tag)
{
int i;
char *key;
char *value;
struct id3_frame *frame;
bool found = false;
- struct replay_gain_info *replay_gain_info;
- replay_gain_info = replay_gain_info_new();
+ replay_gain_info_init(replay_gain_info);
for (i = 0; (frame = id3_tag_findframe(tag, "TXXX", i)); i++) {
if (frame->nfields < 3)
@@ -341,15 +341,9 @@ parse_id3_replay_gain_info(struct id3_tag *tag)
free(value);
}
- if (!found) {
+ return found ||
/* fall back on RVA2 if no replaygain tags found */
- found = parse_rva2(tag, replay_gain_info);
- }
-
- if (found)
- return replay_gain_info;
- replay_gain_info_free(replay_gain_info);
- return NULL;
+ parse_rva2(tag, replay_gain_info);
}
#endif
@@ -408,11 +402,9 @@ static void mp3_parse_id3(struct mp3_data *data, size_t tagsize,
}
if (data->decoder != NULL) {
- struct replay_gain_info *tmp_rgi =
- parse_id3_replay_gain_info(id3_tag);
- if (tmp_rgi != NULL) {
- decoder_replay_gain(data->decoder, tmp_rgi);
- replay_gain_info_free(tmp_rgi);
+ struct replay_gain_info rgi;
+ if (parse_id3_replay_gain_info(&rgi, id3_tag)) {
+ decoder_replay_gain(data->decoder, &rgi);
data->found_replay_gain = true;
}
}
@@ -879,15 +871,14 @@ mp3_decode_first_frame(struct mp3_data *data, struct tag **tag)
if (data->decoder != NULL &&
!data->found_replay_gain &&
lame.track_gain) {
- struct replay_gain_info *rgi
- = replay_gain_info_new();
- rgi->tuples[REPLAY_GAIN_TRACK].gain = lame.track_gain;
- rgi->tuples[REPLAY_GAIN_TRACK].peak = lame.peak;
- decoder_replay_gain(data->decoder, rgi);
- replay_gain_info_free(rgi);
+ struct replay_gain_info rgi;
+ replay_gain_info_init(&rgi);
+ rgi.tuples[REPLAY_GAIN_TRACK].gain = lame.track_gain;
+ rgi.tuples[REPLAY_GAIN_TRACK].peak = lame.peak;
+ decoder_replay_gain(data->decoder, &rgi);
}
}
- }
+ }
if (!data->max_frames)
return false;