diff options
author | Alessandro Ghedini <alessandro@ghedini.me> | 2014-04-12 18:25:40 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2014-04-17 20:08:19 +0200 |
commit | ae43c10e36197000de2f3cc99ea35727ce98a796 (patch) | |
tree | af9b998f29df0cd41908d213e9a04ae3a2ab3e86 /libavformat/replaygain.c | |
parent | 21d8f4da91673051ad7055cf63d989488a56368e (diff) | |
download | ffmpeg-ae43c10e36197000de2f3cc99ea35727ce98a796.tar.gz |
replaygain: allow exporting already decoded replaygain values
This adds a function to export raw replaygain values (i.e. in the (u)int32_t
form). It first checks whether AV_PKT_DATA_REPLAYGAIN side data is present, in
which case it does nothing.
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavformat/replaygain.c')
-rw-r--r-- | libavformat/replaygain.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/libavformat/replaygain.c b/libavformat/replaygain.c index fb3bdc7700..6c5b582cdf 100644 --- a/libavformat/replaygain.c +++ b/libavformat/replaygain.c @@ -66,23 +66,22 @@ static int32_t parse_value(const char *value, int32_t min) return db * 100000 + sign * mb; } -static int replaygain_export(AVStream *st, - const uint8_t *track_gain, const uint8_t *track_peak, - const uint8_t *album_gain, const uint8_t *album_peak) +int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp, + int32_t ag, uint32_t ap) { AVPacketSideData *sd, *tmp; AVReplayGain *replaygain; - int32_t tg, ag; - uint32_t tp, ap; - - tg = parse_value(track_gain, INT32_MIN); - ag = parse_value(album_gain, INT32_MIN); - tp = parse_value(track_peak, 0); - ap = parse_value(album_peak, 0); if (tg == INT32_MIN && ag == INT32_MIN) return 0; + for (int i = 0; i < st->nb_side_data; i++) { + AVPacketSideData *src_sd = &st->side_data[i]; + + if (src_sd->type == AV_PKT_DATA_REPLAYGAIN) + return 0; + } + replaygain = av_mallocz(sizeof(*replaygain)); if (!replaygain) return AVERROR(ENOMEM); @@ -117,9 +116,9 @@ int ff_replaygain_export(AVStream *st, AVDictionary *metadata) ag = av_dict_get(metadata, "REPLAYGAIN_ALBUM_GAIN", NULL, 0); ap = av_dict_get(metadata, "REPLAYGAIN_ALBUM_PEAK", NULL, 0); - return replaygain_export(st, - tg ? tg->value : NULL, - tp ? tp->value : NULL, - ag ? ag->value : NULL, - ap ? ap->value : NULL); + return ff_replaygain_export_raw(st, + parse_value(tg ? tg->value : NULL, INT32_MIN), + parse_value(tp ? tp->value : NULL, 0), + parse_value(ag ? ag->value : NULL, INT32_MIN), + parse_value(ap ? ap->value : NULL, 0)); } |