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. --- core/command.c | 15 +++++++-------- sub/dec_sub.c | 14 +++++++++++++- sub/dec_sub.h | 10 +++++----- sub/sd.h | 1 + sub/sd_ass.c | 25 +++++++++++++++---------- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/core/command.c b/core/command.c index f273bda2b2..453ddbe974 100644 --- a/core/command.c +++ b/core/command.c @@ -55,7 +55,6 @@ #include "video/decode/dec_video.h" #include "audio/decode/dec_audio.h" #include "core/path.h" -#include "sub/ass_mp.h" #include "stream/tv.h" #include "stream/stream_radio.h" #include "stream/pvr.h" @@ -2087,18 +2086,18 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) } case MP_CMD_SUB_STEP: -#ifdef CONFIG_ASS if (mpctx->osd->dec_sub) { - int movement = cmd->args[0].v.i; - struct ass_track *ass_track = sub_get_ass_track(mpctx->osd->dec_sub); - if (ass_track) { + double a[2]; + a[0] = mpctx->video_pts - mpctx->osd->video_offset + opts->sub_delay; + a[1] = cmd->args[0].v.i; + if (sub_control(mpctx->osd->dec_sub, SD_CTRL_SUB_STEP, a) > 0) { + opts->sub_delay += a[0]; + + osd_changed_all(mpctx->osd); set_osd_tmsg(mpctx, OSD_MSG_SUB_DELAY, osdl, osd_duration, "Sub delay: %d ms", ROUND(opts->sub_delay * 1000)); - double cur = (mpctx->video_pts + opts->sub_delay) * 1000 + .5; - opts->sub_delay += ass_step_sub(ass_track, cur, movement) / 1000.; } } -#endif break; case MP_CMD_OSD: { 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