From 50c379e2d8a2cee0fcdbadbcbf5d0a0617fdafec Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 27 Dec 2015 01:25:32 +0100 Subject: sub: minor refactor how video FPS for MicroDVD is set So that the video FPs is not required at initialization, and can be set later. (As for whether this MicroDVD crap is worth the trouble to handle it "correctly": MicroDVD files are unfortunately still around, and in at least one case using the video FPS seemed to help indeed.) --- player/sub.c | 8 ++++---- sub/dec_sub.c | 7 ------- sub/dec_sub.h | 5 +---- sub/sd.h | 1 - sub/sd_ass.c | 38 +++++++++++++++++++++++++------------- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/player/sub.c b/player/sub.c index 059dbdc2fd..e1e411e2ec 100644 --- a/player/sub.c +++ b/player/sub.c @@ -152,12 +152,12 @@ static void reinit_subdec(struct MPContext *mpctx, struct track *track) if (sub_is_initialized(dec_sub)) return; + sub_init(dec_sub, track->demuxer, track->stream); + struct sh_video *sh_video = mpctx->d_video ? mpctx->d_video->header->video : NULL; - float fps = sh_video ? sh_video->fps : 25; - - sub_set_video_fps(dec_sub, fps); - sub_init(dec_sub, track->demuxer, track->stream); + double fps = sh_video ? sh_video->fps : 25; + sub_control(dec_sub, SD_CTRL_SET_VIDEO_DEF_FPS, &fps); // Don't do this if the file has video/audio streams. Don't do it even // if it has only sub streams, because reading packets will change the diff --git a/sub/dec_sub.c b/sub/dec_sub.c index a1f72d432b..1a2c170596 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -113,13 +113,6 @@ bool sub_is_initialized(struct dec_sub *sub) return r; } -void sub_set_video_fps(struct dec_sub *sub, double fps) -{ - pthread_mutex_lock(&sub->lock); - sub->init_sd.video_fps = fps; - pthread_mutex_unlock(&sub->lock); -} - static int sub_init_decoder(struct dec_sub *sub, struct sd *sd) { sd->driver = NULL; diff --git a/sub/dec_sub.h b/sub/dec_sub.h index f1f738b695..e202438777 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -8,11 +8,8 @@ struct demuxer; struct sh_stream; -struct ass_track; struct mpv_global; struct demux_packet; -struct ass_library; -struct ass_renderer; struct dec_sub; struct sd; @@ -22,6 +19,7 @@ enum sd_ctrl { SD_CTRL_SET_VIDEO_PARAMS, SD_CTRL_GET_RESOLUTION, SD_CTRL_SET_TOP, + SD_CTRL_SET_VIDEO_DEF_FPS, }; struct dec_sub *sub_create(struct mpv_global *global); @@ -29,7 +27,6 @@ void sub_destroy(struct dec_sub *sub); void sub_lock(struct dec_sub *sub); void sub_unlock(struct dec_sub *sub); -void sub_set_video_fps(struct dec_sub *sub, double fps); void sub_init(struct dec_sub *sub, struct demuxer *demuxer, struct sh_stream *sh); bool sub_is_initialized(struct dec_sub *sub); diff --git a/sub/sd.h b/sub/sd.h index ce312cca70..26f9d4149f 100644 --- a/sub/sd.h +++ b/sub/sd.h @@ -19,7 +19,6 @@ struct sd { struct demuxer *demuxer; struct sh_stream *sh; - double video_fps; }; struct sd_functions { diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 869d8eaf1f..d798b1f4f4 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -48,7 +48,7 @@ struct sd_ass_priv { char last_text[500]; struct mp_image_params video_params; struct mp_image_params last_params; - double sub_speed; + double sub_speed, video_fps, frame_fps; int64_t *seen_packets; int num_seen_packets; }; @@ -147,6 +147,24 @@ static void enable_output(struct sd *sd, bool enable) } } +static void update_subtitle_speed(struct sd *sd) +{ + struct MPOpts *opts = sd->opts; + struct sd_ass_priv *ctx = sd->priv; + ctx->sub_speed = 1.0; + + if (ctx->video_fps > 0 && ctx->frame_fps > 0) { + MP_VERBOSE(sd, "Frame based format, dummy FPS: %f, video FPS: %f\n", + ctx->frame_fps, ctx->video_fps); + ctx->sub_speed *= ctx->frame_fps / ctx->video_fps; + } + + if (opts->sub_fps && ctx->video_fps) + ctx->sub_speed *= opts->sub_fps / ctx->video_fps; + + ctx->sub_speed *= opts->sub_speed; +} + static int init(struct sd *sd) { struct MPOpts *opts = sd->opts; @@ -187,18 +205,8 @@ static int init(struct sd *sd) mp_ass_add_default_styles(ctx->ass_track, opts); - ctx->sub_speed = 1.0; - - if (sd->video_fps && sd->sh && sd->sh->sub->frame_based > 0) { - MP_VERBOSE(sd, "Frame based format, dummy FPS: %f, video FPS: %f\n", - sd->sh->sub->frame_based, sd->video_fps); - ctx->sub_speed *= sd->sh->sub->frame_based / sd->video_fps; - } - - if (opts->sub_fps && sd->video_fps) - ctx->sub_speed *= opts->sub_fps / sd->video_fps; - - ctx->sub_speed *= opts->sub_speed; + ctx->frame_fps = sd->sh->sub->frame_based; + update_subtitle_speed(sd); enable_output(sd, true); @@ -613,6 +621,10 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) case SD_CTRL_SET_TOP: ctx->on_top = *(bool *)arg; return CONTROL_OK; + case SD_CTRL_SET_VIDEO_DEF_FPS: + ctx->video_fps = *(double *)arg; + update_subtitle_speed(sd); + return CONTROL_OK; default: return CONTROL_UNKNOWN; } -- cgit v1.2.3