From 585f9ff42f3195c5b726101dd34c1ee72633f867 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Tue, 18 Dec 2018 15:15:09 -0500 Subject: 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. --- demux/demux.c | 5 +++++ demux/demux_lavf.c | 33 ++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) (limited to 'demux') diff --git a/demux/demux.c b/demux/demux.c index f02f9b77aa..a8b392d74e 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1946,12 +1946,17 @@ static struct replaygain_data *decode_rgain(struct mp_log *log, { struct replaygain_data rg = {0}; + // Set values in *rg, using track gain as a fallback for album gain if the + // latter is not present. This behavior matches that in demux/demux_lavf.c's + // export_replaygain; if you change this, please make equivalent changes + // there too. if (decode_gain(log, tags, "REPLAYGAIN_TRACK_GAIN", &rg.track_gain) >= 0 && decode_peak(log, tags, "REPLAYGAIN_TRACK_PEAK", &rg.track_peak) >= 0) { if (decode_gain(log, tags, "REPLAYGAIN_ALBUM_GAIN", &rg.album_gain) < 0 || decode_peak(log, tags, "REPLAYGAIN_ALBUM_PEAK", &rg.album_peak) < 0) { + // Album gain is undefined; fall back to track gain. rg.album_gain = rg.track_gain; rg.album_peak = rg.track_peak; } 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 + * 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. -- cgit v1.2.3 From b275232141f569d14d34b263ac059a77225222cc Mon Sep 17 00:00:00 2001 From: Gunnar Marten Date: Thu, 28 Feb 2019 21:48:51 +0100 Subject: demux: fix seek range update after head packets are pruned The seek range update was to early and did not take the removed head packets into account. And therefore missed that the queue was not BOF anymore. This led to not be able to backward seek before the first packet of the first seek range. Fix it by moving the seek range update after the possible removal and the change of the BOF flag. Fixes: #6522 --- demux/demux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'demux') diff --git a/demux/demux.c b/demux/demux.c index a8b392d74e..81d8fa5c2c 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1569,8 +1569,6 @@ static void prune_old_packets(struct demux_internal *in) } prev = prev->next; } - - update_seek_ranges(range); } bool done = false; @@ -1579,6 +1577,8 @@ static void prune_old_packets(struct demux_internal *in) remove_head_packet(queue); } + update_seek_ranges(range); + if (range != in->current_range && range->seek_start == MP_NOPTS_VALUE) free_empty_cached_ranges(in); } -- cgit v1.2.3 From 89eacf8131827533c956a9a10ec1519d2ebdcc31 Mon Sep 17 00:00:00 2001 From: Philip Sequeira Date: Sat, 2 Mar 2019 18:14:57 -0500 Subject: demux_edl: don't assume data follows a comment line There could be another comment line or the end of the file. Fixes #6529. --- demux/demux_edl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'demux') diff --git a/demux/demux_edl.c b/demux/demux_edl.c index b724ffa592..7f85568eae 100644 --- a/demux/demux_edl.c +++ b/demux/demux_edl.c @@ -80,8 +80,10 @@ static struct tl_parts *parse_edl(bstr str) { struct tl_parts *tl = talloc_zero(NULL, struct tl_parts); while (str.len) { - if (bstr_eatstart0(&str, "#")) + if (bstr_eatstart0(&str, "#")) { bstr_split_tok(str, "\n", &(bstr){0}, &str); + continue; + } if (bstr_eatstart0(&str, "\n") || bstr_eatstart0(&str, ";")) continue; bool is_header = bstr_eatstart0(&str, "!"); -- cgit v1.2.3