diff options
author | wm4 <wm4@nowhere> | 2020-02-16 01:02:17 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-02-16 02:07:24 +0100 |
commit | 0b35b4c91796fb020e13d955efd450021eb5eedb (patch) | |
tree | 2223d7c7f32afc60efb12b0051343e99e6bf727b /sub/sd.h | |
parent | e162bcb5a09b5ad514636684314e8e797ab2a47b (diff) | |
download | mpv-0b35b4c91796fb020e13d955efd450021eb5eedb.tar.bz2 mpv-0b35b4c91796fb020e13d955efd450021eb5eedb.tar.xz |
sub: make filter_sdh a "proper" filter, allow runtime changes
Until now, filter_sdh was simply a function that was called by sd_ass
directly (if enabled).
I want to add another filter, so it's time to turn this into a somewhat
more general subtitle filtering infrastructure.
I pondered whether to reuse the audio/video filtering stuff - but better
not. Also, since subtitles are horrible and tend to refuse proper
abstraction, it's still messed into sd_ass, instead of working on the
dec_sub.c level. Actually mpv used to have subtitle "filters" and even
made subtitle converters part of it, but it was fairly horrible, so
don't do that again.
In addition, make runtime changes possible. Since this was supposed to
be a quick hack, I just decided to put all subtitle filter options into
a separate option group (=> simpler change notification), to manually
push the change through the playloop (like it was sort of before for OSD
options), and to recreate the sub filter chain completely in every
change. Should be good enough.
One strangeness is that due to prefetching and such, most subtitle
packets (or those some time ahead) are actually done filtering when we
change, so the user still needs to manually seek to actually refresh
everything. And since subtitle data is usually cached in ASS_Track (for
other terrible but user-friendly reasons), we also must clear the
subtitle data, but of course only on seek, since otherwise all subtitles
would just disappear. What a fucking mess, but such is life. We could
trigger a "refresh seek" to make this more automatic, but I don't feel
like it currently.
This is slightly inefficient (lots of allocations and copying), but I
decided that it doesn't matter. Could matter slightly for crazy ASS
subtitles that render with thousands of events.
Not very well tested. Still seems to work, but I didn't have many test
cases.
Diffstat (limited to 'sub/sd.h')
-rw-r--r-- | sub/sd.h | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -3,6 +3,7 @@ #include "dec_sub.h" #include "demux/packet.h" +#include "misc/bstr.h" // up to 210 ms overlaps or gaps are removed #define SUB_GAP_THRESHOLD 0.210 @@ -43,6 +44,7 @@ struct sd_functions { struct sd_times (*get_times)(struct sd *sd, double pts); }; +// lavc_conv.c struct lavc_conv; struct lavc_conv *lavc_conv_create(struct mp_log *log, const char *codec_name, char *extradata, int extradata_len); @@ -52,6 +54,38 @@ char **lavc_conv_decode(struct lavc_conv *priv, struct demux_packet *packet, void lavc_conv_reset(struct lavc_conv *priv); void lavc_conv_uninit(struct lavc_conv *priv); -char *filter_SDH(struct sd *sd, char *format, int n_ignored, char *data, int length); +struct sd_filter { + struct mpv_global *global; + struct mp_log *log; + struct mp_sub_filter_opts *opts; + const struct sd_filter_functions *driver; + + void *priv; + + // Static codec parameters. Set by sd; cannot be changed by filter. + char *codec; + char *event_format; +}; + +struct sd_filter_functions { + bool (*init)(struct sd_filter *ft); + + // Filter an ASS event (usually in the Matroska format, but event_format + // can be used to determine details). + // Returning NULL is interpreted as dropping the event completely. + // Returning pkt makes it no-op. + // If the returned packet is not pkt or NULL, it must have been properly + // allocated. + // pkt is owned by the caller (and freed by the caller when needed). + // Note: as by normal demux_packet rules, you must not modify any fields in + // it, or the data referenced by it. You must create a new demux_packet + // when modifying data. + struct demux_packet *(*filter)(struct sd_filter *ft, + struct demux_packet *pkt); + + void (*uninit)(struct sd_filter *ft); +}; + +extern const struct sd_filter_functions sd_filter_sdh; #endif |