Commit e2c07dbb authored by Max Kellermann's avatar Max Kellermann

ogg: ogg_getReplayGainInfo() returns replay_gain_info pointer

Some code simplification. Avoid pointers to pointers.
parent 837cefdb
...@@ -93,33 +93,31 @@ static const char *ogg_parseComment(const char *comment, const char *needle) ...@@ -93,33 +93,31 @@ static const char *ogg_parseComment(const char *comment, const char *needle)
return NULL; return NULL;
} }
static void static struct replay_gain_info *
ogg_getReplayGainInfo(char **comments, ogg_getReplayGainInfo(char **comments)
struct replay_gain_info **infoPtr)
{ {
struct replay_gain_info *rgi;
const char *temp; const char *temp;
bool found = false; bool found = false;
if (*infoPtr) rgi = replay_gain_info_new();
replay_gain_info_free(*infoPtr);
*infoPtr = replay_gain_info_new();
while (*comments) { while (*comments) {
if ((temp = if ((temp =
ogg_parseComment(*comments, "replaygain_track_gain"))) { ogg_parseComment(*comments, "replaygain_track_gain"))) {
(*infoPtr)->track_gain = atof(temp); rgi->track_gain = atof(temp);
found = true; found = true;
} else if ((temp = ogg_parseComment(*comments, } else if ((temp = ogg_parseComment(*comments,
"replaygain_album_gain"))) { "replaygain_album_gain"))) {
(*infoPtr)->album_gain = atof(temp); rgi->album_gain = atof(temp);
found = true; found = true;
} else if ((temp = ogg_parseComment(*comments, } else if ((temp = ogg_parseComment(*comments,
"replaygain_track_peak"))) { "replaygain_track_peak"))) {
(*infoPtr)->track_peak = atof(temp); rgi->track_peak = atof(temp);
found = true; found = true;
} else if ((temp = ogg_parseComment(*comments, } else if ((temp = ogg_parseComment(*comments,
"replaygain_album_peak"))) { "replaygain_album_peak"))) {
(*infoPtr)->album_peak = atof(temp); rgi->album_peak = atof(temp);
found = true; found = true;
} }
...@@ -127,9 +125,11 @@ ogg_getReplayGainInfo(char **comments, ...@@ -127,9 +125,11 @@ ogg_getReplayGainInfo(char **comments,
} }
if (!found) { if (!found) {
replay_gain_info_free(*infoPtr); replay_gain_info_free(rgi);
*infoPtr = NULL; rgi = NULL;
} }
return rgi;
} }
static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber"; static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber";
...@@ -275,6 +275,8 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) ...@@ -275,6 +275,8 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
if (current_section != prev_section) { if (current_section != prev_section) {
/*printf("new song!\n"); */ /*printf("new song!\n"); */
vorbis_info *vi = ov_info(&vf, -1); vorbis_info *vi = ov_info(&vf, -1);
struct replay_gain_info *new_rgi;
audio_format.channels = vi->channels; audio_format.channels = vi->channels;
audio_format.sample_rate = vi->rate; audio_format.sample_rate = vi->rate;
if (!initialized) { if (!initialized) {
...@@ -289,7 +291,12 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) ...@@ -289,7 +291,12 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
comments = ov_comment(&vf, -1)->user_comments; comments = ov_comment(&vf, -1)->user_comments;
putOggCommentsIntoOutputBuffer(decoder, inStream, putOggCommentsIntoOutputBuffer(decoder, inStream,
comments); comments);
ogg_getReplayGainInfo(comments, &replayGainInfo); new_rgi = ogg_getReplayGainInfo(comments);
if (new_rgi != NULL) {
if (replayGainInfo != NULL)
replay_gain_info_free(replayGainInfo);
replayGainInfo = new_rgi;
}
} }
prev_section = current_section; prev_section = current_section;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment