summaryrefslogtreecommitdiffstats
path: root/demux/demux_lavf.c
diff options
context:
space:
mode:
authorBenjamin Barenblat <bbaren@google.com>2018-12-18 15:15:09 -0500
committersfan5 <sfan5@live.de>2019-01-16 16:58:33 +0100
commit585f9ff42f3195c5b726101dd34c1ee72633f867 (patch)
treef08c88cbd7bfeda0f02f2ebc62d108c790b53a71 /demux/demux_lavf.c
parentaab595f828c9e158cd08cadc48ccc6fe9725e464 (diff)
downloadmpv-585f9ff42f3195c5b726101dd34c1ee72633f867.tar.bz2
mpv-585f9ff42f3195c5b726101dd34c1ee72633f867.tar.xz
demux: make ALBUM ReplayGain tags optional when using libavformat
Commit e392d6610d1e35cc0190c794c151211b0aae83e6 modified the native demuxer to use track gain as a fallback for album gain if the latter is not present. This commit makes functionally equivalent changes in the libavformat demuxer.
Diffstat (limited to 'demux/demux_lavf.c')
-rw-r--r--demux/demux_lavf.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index b1800018c4..4802278af5 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2004 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2018 Google LLC
*
* This file is part of mpv.
*
@@ -561,17 +562,27 @@ static void export_replaygain(demuxer_t *demuxer, struct sh_stream *sh,
av_rgain = (AVReplayGain*)src_sd->data;
rgain = talloc_ptrtype(demuxer, rgain);
- rgain->track_gain = (av_rgain->track_gain != INT32_MIN) ?
- av_rgain->track_gain / 100000.0f : 0.0;
-
- rgain->track_peak = (av_rgain->track_peak != 0.0) ?
- av_rgain->track_peak / 100000.0f : 1.0;
-
- rgain->album_gain = (av_rgain->album_gain != INT32_MIN) ?
- av_rgain->album_gain / 100000.0f : 0.0;
-
- rgain->album_peak = (av_rgain->album_peak != 0.0) ?
- av_rgain->album_peak / 100000.0f : 1.0;
+ // Set values in *rgain, using track gain as a fallback for album gain
+ // if the latter is not present. This behavior matches that in
+ // demux/demux.c's decode_rgain; if you change this, please make
+ // equivalent changes there too.
+ if (av_rgain->track_gain != INT32_MIN && av_rgain->track_peak != 0.0) {
+ // Track gain is defined.
+ rgain->track_gain = av_rgain->track_gain / 100000.0f;
+ rgain->track_peak = av_rgain->track_peak / 100000.0f;
+
+ if (av_rgain->album_gain != INT32_MIN &&
+ av_rgain->album_peak != 0.0)
+ {
+ // Album gain is also defined.
+ rgain->album_gain = av_rgain->album_gain / 100000.0f;
+ rgain->album_peak = av_rgain->album_peak / 100000.0f;
+ } else {
+ // Album gain is undefined; fall back to track gain.
+ rgain->album_gain = rgain->track_gain;
+ rgain->album_peak = rgain->track_peak;
+ }
+ }
// This must be run only before the stream was added, otherwise there
// will be race conditions with accesses from the user thread.