diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2021-07-22 20:45:10 +0300 |
---|---|---|
committer | avih <avih@users.noreply.github.com> | 2021-08-05 21:32:22 +0300 |
commit | 62704e231578d9593739d62b82a676ddbda84ac0 (patch) | |
tree | 18e720335b827ab755f96979369b252a7ea9d444 /sub | |
parent | ab689a33a86d806726ee551fb25994fd0918a2a2 (diff) | |
download | mpv-62704e231578d9593739d62b82a676ddbda84ac0.tar.bz2 mpv-62704e231578d9593739d62b82a676ddbda84ac0.tar.xz |
sub: SDH filter: small refinements
1. On a pathological case where event_format is NULL, previously the
filter was trying to use it with each new sub - and re-failed. Now
the filter gets disabled on init (event_format doesn't change).
2. Previously, if the filter didn't modify the text or if the text
could not be extracted - it still allocated a new packet with same
content. Now it returns the original, saving a whole lot of no-ops
(there are still few allocations in this case though).
1 above is preparation for the next commit, and 2 was trivial, but
there's more to do if anyone cares (NIH string functions instead of
bstr, unused arguments, messages could be improved, and more).
Diffstat (limited to 'sub')
-rw-r--r-- | sub/filter_sdh.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sub/filter_sdh.c b/sub/filter_sdh.c index 2b544ea222..9271cc261a 100644 --- a/sub/filter_sdh.c +++ b/sub/filter_sdh.c @@ -346,11 +346,6 @@ static void remove_leading_hyphen_space(struct sd_filter *sd, int start_pos, static char *filter_SDH(struct sd_filter *sd, char *format, int n_ignored, char *data, int length) { - if (!format) { - MP_VERBOSE(sd, "SDH filtering not possible - format missing\n"); - return length ? talloc_strndup(NULL, data, length) : talloc_strdup(NULL, data); - } - // need null terminated string char *ass = length ? talloc_strndup(NULL, data, length) : data; @@ -475,6 +470,11 @@ static bool sdh_init(struct sd_filter *ft) if (!ft->opts->sub_filter_SDH) return false; + if (!ft->event_format) { + MP_VERBOSE(ft, "SDH filtering not possible - format missing\n"); + return false; + } + return true; } @@ -489,10 +489,14 @@ static struct demux_packet *sdh_filter(struct sd_filter *ft, line = filter_SDH(ft, ft->event_format, 1, line, len); if (!line) return NULL; + if (0 == bstrcmp0((bstr){(char *)pkt->buffer, pkt->len}, line)) { + talloc_free(line); + return pkt; // unmodified, no need to allocate new packet + } // Stupidly, this copies it again. One could possibly allocate the packet // for writing in the first place (new_demux_packet()) and use - // demux_packet_shorten(). Or not allocate anything on no change. + // demux_packet_shorten(). struct demux_packet *npkt = new_demux_packet_from(line, strlen(line)); if (npkt) demux_packet_copy_attribs(npkt, pkt); |