diff options
author | wm4 <wm4@nowhere> | 2020-05-14 22:14:49 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-05-14 22:14:49 +0200 |
commit | c6369933f1d9cd204b09be95ef7d4ed1351610e2 (patch) | |
tree | d7b45307780aef2dafde89795f49d564c7aed313 /sub | |
parent | 0049ea38be72884fabeee3ce52e2d6796c3abd53 (diff) | |
download | mpv-c6369933f1d9cd204b09be95ef7d4ed1351610e2.tar.bz2 mpv-c6369933f1d9cd204b09be95ef7d4ed1351610e2.tar.xz |
command: add property to return text subtitles in ASS
See manpage additions. This was requested, sort of. Although what has
been requested might be something completely different. So this is
speculative.
This also changes sub_get_text() to return an allocated copy, because
the buffer shit was too damn messy.
Diffstat (limited to 'sub')
-rw-r--r-- | sub/dec_sub.c | 10 | ||||
-rw-r--r-- | sub/dec_sub.h | 7 | ||||
-rw-r--r-- | sub/sd.h | 2 | ||||
-rw-r--r-- | sub/sd_ass.c | 17 |
4 files changed, 26 insertions, 10 deletions
diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 76e96bc16b..aedb836235 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -348,10 +348,10 @@ struct sub_bitmaps *sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, return res; } -// See sub_get_bitmaps() for locking requirements. -// It can be called unlocked too, but then only 1 thread must call this function -// at a time (unless exclusive access is guaranteed). -char *sub_get_text(struct dec_sub *sub, double pts) +// This can only be called by the main thread, due to the returned text pointing +// to a buffer bound to the sub object. The main thread is the designated +// "outside" owner of the buffer. +char *sub_get_text(struct dec_sub *sub, double pts, enum sd_text_type type) { pthread_mutex_lock(&sub->lock); char *text = NULL; @@ -362,7 +362,7 @@ char *sub_get_text(struct dec_sub *sub, double pts) update_segment(sub); if (sub->sd->driver->get_text) - text = sub->sd->driver->get_text(sub->sd, pts); + text = sub->sd->driver->get_text(sub->sd, pts, type); pthread_mutex_unlock(&sub->lock); return text; } diff --git a/sub/dec_sub.h b/sub/dec_sub.h index 8d0c76cd14..f998b59f6b 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -22,6 +22,11 @@ enum sd_ctrl { SD_CTRL_UPDATE_OPTS, }; +enum sd_text_type { + SD_TEXT_TYPE_PLAIN, + SD_TEXT_TYPE_ASS, +}; + struct sd_times { double start; double end; @@ -41,7 +46,7 @@ void sub_preload(struct dec_sub *sub); bool sub_read_packets(struct dec_sub *sub, double video_pts); struct sub_bitmaps *sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, int format, double pts); -char *sub_get_text(struct dec_sub *sub, double pts); +char *sub_get_text(struct dec_sub *sub, double pts, enum sd_text_type type); struct sd_times sub_get_times(struct dec_sub *sub, double pts); void sub_reset(struct dec_sub *sub); void sub_select(struct dec_sub *sub, bool selected); @@ -40,7 +40,7 @@ struct sd_functions { struct sub_bitmaps *(*get_bitmaps)(struct sd *sd, struct mp_osd_res dim, int format, double pts); - char *(*get_text)(struct sd *sd, double pts); + char *(*get_text)(struct sd *sd, double pts, enum sd_text_type type); struct sd_times (*get_times)(struct sd *sd, double pts); }; diff --git a/sub/sd_ass.c b/sub/sd_ass.c index d51f892dd4..46f16908b0 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -627,7 +627,7 @@ static bool is_whitespace_only(char *s, int len) return true; } -static char *get_text(struct sd *sd, double pts) +static char *get_text_buf(struct sd *sd, double pts, enum sd_text_type type) { struct sd_ass_priv *ctx = sd->priv; ASS_Track *track = ctx->ass_track; @@ -643,7 +643,13 @@ static char *get_text(struct sd *sd, double pts) if (ipts >= event->Start && ipts < event->Start + event->Duration) { if (event->Text) { int start = b.len; - ass_to_plaintext(&b, event->Text); + if (type == SD_TEXT_TYPE_PLAIN) { + ass_to_plaintext(&b, event->Text); + } else { + char *t = event->Text; + while (*t) + append(&b, *t++); + } if (is_whitespace_only(&b.start[start], b.len - start)) { b.len = start; } else { @@ -661,6 +667,11 @@ static char *get_text(struct sd *sd, double pts) return ctx->last_text; } +static char *get_text(struct sd *sd, double pts, enum sd_text_type type) +{ + return talloc_strdup(NULL, get_text_buf(sd, pts, type)); +} + static struct sd_times get_times(struct sd *sd, double pts) { struct sd_ass_priv *ctx = sd->priv; @@ -697,7 +708,7 @@ static void fill_plaintext(struct sd *sd, double pts) ass_flush_events(track); - char *text = get_text(sd, pts); + char *text = get_text_buf(sd, pts, SD_TEXT_TYPE_PLAIN); if (!text) return; |