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.
This commit is contained in:
wm4 2014-07-05 16:45:41 +02:00
parent a97256c1d5
commit 58880c00ee
5 changed files with 11 additions and 9 deletions

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;
}