summaryrefslogtreecommitdiffstats
path: root/filters/f_autoconvert.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-04-07 14:38:40 +0200
committerJan Ekström <jeebjp@gmail.com>2018-04-15 23:11:33 +0300
commit3c123281a7eb3181a9706a52d0148f70aa65cff5 (patch)
tree86fe71febdffb4bead600b47371f28c7838ff3d2 /filters/f_autoconvert.h
parent4b48966d87d7759346f989c44e8ab3cb405d0037 (diff)
downloadmpv-3c123281a7eb3181a9706a52d0148f70aa65cff5.tar.bz2
mpv-3c123281a7eb3181a9706a52d0148f70aa65cff5.tar.xz
audio: change format negotiation, remove channel remix fudging
The audio format neogitation code was pretty complicated, although the idea was simple: when the format changes (or on the first audio frame), filter only the new frame through the entire filter chain, discard the resulting frame, but use the format to initialize the AO. This was useful for "fudging" the channel remix behavior (upmix or downmix), and moving it before other filters. Apparently this was useful for things like DRC filters, which might work better in stereo, and which also can only achieve the desired volume levels by doing it before a downmix, which would modify the volume. This mechanism was introduced in commit 60048b7eb957b (which the commit message also describes as "idiotic heuristic"). Knowing the output format is inherently necessary for this, because otherwise we can't know what the hell the user defined filters will do. There were problems with robustness. Some filters needed more than one frame. Resampling in particular would discard initial audio at high resampling ratios. Some filters might drop audio intentionally (like clipping data on timestamp ranges). There were also allegations that some decoders output 0 length frames (although that is invalid in libavcodec). The state machine was excessively complex and hard to understand too. There are 3 things that could have been done: 1. Fix robustness problems by doing more heuristics, like repeating audio frames or simply decoding several frames. Since filters can behave differently, this would have added lots of complexity. 2. Make use of libavfilter's format negotiation, and add the same to mpv builtin filters. This is sort of annoying, because the format negotiation in libavfilter changes the state of the filters. It also reports only some parameters (mostly all for audio, but a lot of holes for video). It would remove some of the state machine, but not all. 3. Drop the channel remix fudging, and do the same as the video chain. This would not require format negotiation, but instead you can just filter the audio frames, and look what comes out of it. If nothing comes out, simply never create an AO. This commit selects option 3. It removes the remix fudging, which means the loss of a feature. Users can instead add "--af=format=channels=2" before their DRC filter, or something. I'm also considering changing the default for --audio-channels back to stereo, and downmix in the decoder or at the start of the filter chain, which would give the same results, except requiring more configuration. Implementation-wise, this is still a bit different from the video path. The VO always remains the same instance, while the AO might have to be recreated on configuration changes. This still requires explicit format change handling + draining old data, but by putting it into f_autoconvert, not much new code is needed.
Diffstat (limited to 'filters/f_autoconvert.h')
-rw-r--r--filters/f_autoconvert.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/filters/f_autoconvert.h b/filters/f_autoconvert.h
index 77e07aecf1..4cd0cb3d6d 100644
--- a/filters/f_autoconvert.h
+++ b/filters/f_autoconvert.h
@@ -8,6 +8,13 @@
struct mp_autoconvert {
// f->pins[0] is input, f->pins[1] is output
struct mp_filter *f;
+
+ // If this is set, the callback is invoked (from the process function), and
+ // further data flow is blocked until mp_autoconvert_format_change_continue()
+ // is called. The idea is that you can reselect the output parameters on
+ // format changes and continue filtering when ready.
+ void (*on_audio_format_change)(void *opaque);
+ void *on_audio_format_change_opaque;
};
// (to free this, free the filter itself, mp_autoconvert.f)
@@ -46,5 +53,8 @@ void mp_autoconvert_add_srate(struct mp_autoconvert *c, int rate);
// filter.)
void mp_autoconvert_clear(struct mp_autoconvert *c);
+// See mp_autoconvert.on_audio_format_change.
+void mp_autoconvert_format_change_continue(struct mp_autoconvert *c);
+
// vf_d3d11vpp.c
struct mp_filter *vf_d3d11_create_outconv(struct mp_filter *parent);