From 58880c00eeca254a5391dd61a920081bb16bc2c1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 5 Jul 2014 16:45:41 +0200 Subject: 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. --- demux/demux.c | 9 ++++++--- demux/demux.h | 2 -- demux/demux_lavf.c | 6 +++--- demux/stheader.h | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) (limited to 'demux') 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 { -- cgit v1.2.3