Commit d35efda2 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'ae43c10e'

* commit 'ae43c10e':
  replaygain: allow exporting already decoded replaygain values
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 11d187b3 ae43c10e
...@@ -66,23 +66,22 @@ static int32_t parse_value(const char *value, int32_t min) ...@@ -66,23 +66,22 @@ static int32_t parse_value(const char *value, int32_t min)
return db * 100000 + sign * mb; return db * 100000 + sign * mb;
} }
static int replaygain_export(AVStream *st, int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
const uint8_t *track_gain, const uint8_t *track_peak, int32_t ag, uint32_t ap)
const uint8_t *album_gain, const uint8_t *album_peak)
{ {
AVPacketSideData *sd, *tmp; AVPacketSideData *sd, *tmp;
AVReplayGain *replaygain; 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) if (tg == INT32_MIN && ag == INT32_MIN)
return 0; 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)); replaygain = av_mallocz(sizeof(*replaygain));
if (!replaygain) if (!replaygain)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
...@@ -117,9 +116,9 @@ int ff_replaygain_export(AVStream *st, AVDictionary *metadata) ...@@ -117,9 +116,9 @@ int ff_replaygain_export(AVStream *st, AVDictionary *metadata)
ag = av_dict_get(metadata, "REPLAYGAIN_ALBUM_GAIN", NULL, 0); ag = av_dict_get(metadata, "REPLAYGAIN_ALBUM_GAIN", NULL, 0);
ap = av_dict_get(metadata, "REPLAYGAIN_ALBUM_PEAK", NULL, 0); ap = av_dict_get(metadata, "REPLAYGAIN_ALBUM_PEAK", NULL, 0);
return replaygain_export(st, return ff_replaygain_export_raw(st,
tg ? tg->value : NULL, parse_value(tg ? tg->value : NULL, INT32_MIN),
tp ? tp->value : NULL, parse_value(tp ? tp->value : NULL, 0),
ag ? ag->value : NULL, parse_value(ag ? ag->value : NULL, INT32_MIN),
ap ? ap->value : NULL); parse_value(ap ? ap->value : NULL, 0));
} }
...@@ -28,4 +28,11 @@ ...@@ -28,4 +28,11 @@
*/ */
int ff_replaygain_export(AVStream *st, AVDictionary *metadata); int ff_replaygain_export(AVStream *st, AVDictionary *metadata);
/**
* Export already decoded replaygain values as per-stream side data.
*/
int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
int32_t ag, uint32_t ap);
#endif /* AVFORMAT_REPLAYGAIN_H */ #endif /* AVFORMAT_REPLAYGAIN_H */
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