From e5c094754157102a964364041d6fb0caf2188809 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 29 Jun 2013 01:34:11 +0200 Subject: dec_sub: introduce sub_control(), use it for sub_step This means the direct libass usage can be removed from command.c, and no weird hacks for retrieving the ASS_Track are needed. Also fix a bug when using this feature with ordered chapters. --- sub/dec_sub.c | 14 +++++++++++++- sub/dec_sub.h | 10 +++++----- sub/sd.h | 1 + sub/sd_ass.c | 25 +++++++++++++++---------- 4 files changed, 34 insertions(+), 16 deletions(-) (limited to 'sub') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 1a7180b260..5fb8722296 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -102,7 +102,7 @@ bool sub_is_initialized(struct dec_sub *sub) return !!sub->num_sd; } -struct sd *sub_get_last_sd(struct dec_sub *sub) +static struct sd *sub_get_last_sd(struct dec_sub *sub) { return sub->num_sd ? sub->sd[sub->num_sd - 1] : NULL; } @@ -482,6 +482,18 @@ void sub_reset(struct dec_sub *sub) } } +int sub_control(struct dec_sub *sub, enum sd_ctrl cmd, void *arg) +{ + for (int n = 0; n < sub->num_sd; n++) { + if (sub->sd[n]->driver->control) { + int r = sub->sd[n]->driver->control(sub->sd[n], cmd, arg); + if (r != CONTROL_UNKNOWN) + return r; + } + } + return CONTROL_UNKNOWN; +} + #define MAX_PACKETS 10 #define MAX_BYTES 10000 diff --git a/sub/dec_sub.h b/sub/dec_sub.h index c285449f94..3fb35deace 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -16,6 +16,10 @@ struct ass_renderer; struct dec_sub; struct sd; +enum sd_ctrl { + SD_CTRL_SUB_STEP, +}; + struct dec_sub *sub_create(struct MPOpts *opts); void sub_destroy(struct dec_sub *sub); @@ -37,10 +41,6 @@ bool sub_has_get_text(struct dec_sub *sub); char *sub_get_text(struct dec_sub *sub, double pts); void sub_reset(struct dec_sub *sub); -struct sd *sub_get_last_sd(struct dec_sub *sub); - -#ifdef CONFIG_ASS -struct ass_track *sub_get_ass_track(struct dec_sub *sub); -#endif +int sub_control(struct dec_sub *sub, enum sd_ctrl cmd, void *arg); #endif diff --git a/sub/sd.h b/sub/sd.h index 4268137921..3b83197989 100644 --- a/sub/sd.h +++ b/sub/sd.h @@ -54,6 +54,7 @@ struct sd_functions { void (*uninit)(struct sd *sd); void (*fix_events)(struct sd *sd); + int (*control)(struct sd *sd, enum sd_ctrl cmd, void *arg); // decoder void (*get_bitmaps)(struct sd *sd, struct mp_osd_res dim, double pts, diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 9c51398f33..c82e1e80bb 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -318,6 +318,20 @@ static void uninit(struct sd *sd) talloc_free(ctx); } +static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) +{ + struct sd_ass_priv *ctx = sd->priv; + switch (cmd) { + case SD_CTRL_SUB_STEP: { + double *a = arg; + a[0] = ass_step_sub(ctx->ass_track, a[0] * 1000 + .5, a[1]) / 1000.0; + return CONTROL_OK; + } + default: + return CONTROL_UNKNOWN; + } +} + const struct sd_functions sd_ass = { .name = "ass", .accept_packets_in_advance = true, @@ -327,16 +341,7 @@ const struct sd_functions sd_ass = { .get_bitmaps = get_bitmaps, .get_text = get_text, .fix_events = fix_events, + .control = control, .reset = reset, .uninit = uninit, }; - -struct ass_track *sub_get_ass_track(struct dec_sub *sub) -{ - struct sd *sd = sub_get_last_sd(sub); - if (sd && sd->driver == &sd_ass && sd->priv) { - struct sd_ass_priv *ctx = sd->priv; - return ctx->ass_track; - } - return NULL; -} -- cgit v1.2.3