summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-07-05 16:45:41 +0200
committerwm4 <wm4@nowhere>2014-07-05 17:07:14 +0200
commit58880c00eeca254a5391dd61a920081bb16bc2c1 (patch)
tree56f9bb23059b96c0d7e0eaf58b7ae44f36b0af84
parenta97256c1d58fae714ae94301ab09044081d08c8e (diff)
downloadmpv-58880c00eeca254a5391dd61a920081bb16bc2c1.tar.bz2
mpv-58880c00eeca254a5391dd61a920081bb16bc2c1.tar.xz
demux: make replaygain per-track
It's unlikely that files with multiple audio tracks and with replaygain actually happen, but this change might help avoid minor corner cases with later changes.
-rw-r--r--demux/demux.c9
-rw-r--r--demux/demux.h2
-rw-r--r--demux/demux_lavf.c6
-rw-r--r--demux/stheader.h1
-rw-r--r--player/audio.c2
5 files changed, 11 insertions, 9 deletions
diff --git a/demux/demux.c b/demux/demux.c
index c45575f755..92a68d260e 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -429,8 +429,7 @@ static void demux_export_replaygain(demuxer_t *demuxer)
{
float tg, tp, ag, ap;
- if (!demuxer->replaygain_data &&
- !decode_gain(demuxer, "REPLAYGAIN_TRACK_GAIN", &tg) &&
+ if (!decode_gain(demuxer, "REPLAYGAIN_TRACK_GAIN", &tg) &&
!decode_peak(demuxer, "REPLAYGAIN_TRACK_PEAK", &tp) &&
!decode_gain(demuxer, "REPLAYGAIN_ALBUM_GAIN", &ag) &&
!decode_peak(demuxer, "REPLAYGAIN_ALBUM_PEAK", &ap))
@@ -442,7 +441,11 @@ static void demux_export_replaygain(demuxer_t *demuxer)
rgain->album_gain = ag;
rgain->album_peak = ap;
- demuxer->replaygain_data = rgain;
+ for (int n = 0; n < demuxer->num_streams; n++) {
+ struct sh_stream *sh = demuxer->streams[n];
+ if (sh->audio && !sh->audio->replaygain_data)
+ sh->audio->replaygain_data = rgain;
+ }
}
}
diff --git a/demux/demux.h b/demux/demux.h
index bd963392dd..df1762eb08 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -199,8 +199,6 @@ typedef struct demuxer {
// for trivial demuxers which just read the whole file for codec to use
struct bstr file_contents;
- struct replaygain_data *replaygain_data;
-
// If the file is a playlist file
struct playlist *playlist;
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index 47e4367fc7..f10c23a753 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -399,7 +399,7 @@ static void select_tracks(struct demuxer *demuxer, int start)
}
}
-static void export_replaygain(demuxer_t *demuxer, AVStream *st)
+static void export_replaygain(demuxer_t *demuxer, sh_audio_t *sh, AVStream *st)
{
#if HAVE_AVCODEC_REPLAYGAIN_SIDE_DATA
for (int i = 0; i < st->nb_side_data; i++) {
@@ -425,7 +425,7 @@ static void export_replaygain(demuxer_t *demuxer, AVStream *st)
rgain->album_peak = (av_rgain->album_peak != 0.0) ?
av_rgain->album_peak / 100000.0f : 1.0;
- demuxer->replaygain_data = rgain;
+ sh->replaygain_data = rgain;
}
#endif
}
@@ -454,7 +454,7 @@ static void handle_stream(demuxer_t *demuxer, int i)
sh_audio->samplerate = codec->sample_rate;
sh_audio->bitrate = codec->bit_rate;
- export_replaygain(demuxer, st);
+ export_replaygain(demuxer, sh_audio, st);
break;
}
diff --git a/demux/stheader.h b/demux/stheader.h
index 101c75e880..1771f75ff5 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -73,6 +73,7 @@ typedef struct sh_audio {
// note codec extradata may be either under "wf" or "codecdata"
unsigned char *codecdata;
int codecdata_len;
+ struct replaygain_data *replaygain_data;
} sh_audio_t;
typedef struct sh_video {
diff --git a/player/audio.c b/player/audio.c
index e0c6ca9a0c..a63b847a75 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -120,7 +120,7 @@ void reinit_audio_chain(struct MPContext *mpctx)
mpctx->d_audio->opts = opts;
mpctx->d_audio->header = sh;
mpctx->d_audio->metadata = mpctx->demuxer->metadata;
- mpctx->d_audio->replaygain_data = mpctx->demuxer->replaygain_data;
+ mpctx->d_audio->replaygain_data = sh->audio->replaygain_data;
if (!audio_init_best_codec(mpctx->d_audio, opts->audio_decoders))
goto init_error;
}