diff options
Diffstat (limited to 'sub')
-rw-r--r-- | sub/ass_mp.c | 3 | ||||
-rw-r--r-- | sub/dec_sub.c | 14 | ||||
-rw-r--r-- | sub/dec_sub.h | 3 | ||||
-rw-r--r-- | sub/osd.c | 2 | ||||
-rw-r--r-- | sub/osd.h | 11 | ||||
-rw-r--r-- | sub/osd_dummy.c | 8 | ||||
-rw-r--r-- | sub/osd_libass.c | 28 | ||||
-rw-r--r-- | sub/osd_state.h | 6 | ||||
-rw-r--r-- | sub/sd_ass.c | 4 | ||||
-rw-r--r-- | sub/sd_lavc.c | 48 |
10 files changed, 73 insertions, 54 deletions
diff --git a/sub/ass_mp.c b/sub/ass_mp.c index 84a706b681..6d85ac1f28 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -78,6 +78,9 @@ void mp_ass_set_style(ASS_Style *style, double res_y, style->ScaleX = 1.; style->ScaleY = 1.; style->Alignment = 1 + (opts->align_x + 1) + (opts->align_y + 2) % 3 * 4; +#ifdef ASS_JUSTIFY_LEFT + style->Justify = opts->justify; +#endif style->Blur = opts->blur; style->Bold = opts->bold; style->Italic = opts->italic; diff --git a/sub/dec_sub.c b/sub/dec_sub.c index b9f04b3123..743a06ed14 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -29,6 +29,7 @@ #include "options/options.h" #include "common/global.h" #include "common/msg.h" +#include "common/recorder.h" #include "osdep/threads.h" extern const struct sd_functions sd_ass; @@ -49,6 +50,8 @@ struct dec_sub { struct mpv_global *global; struct MPOpts *opts; + struct mp_recorder_sink *recorder_sink; + struct attachment_list *attachments; struct sh_stream *sh; @@ -240,6 +243,9 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts) break; } + if (sub->recorder_sink) + mp_recorder_feed_packet(sub->recorder_sink, pkt); + sub->last_pkt_pts = pkt->pts; if (is_new_segment(sub, pkt)) { @@ -323,3 +329,11 @@ int sub_control(struct dec_sub *sub, enum sd_ctrl cmd, void *arg) pthread_mutex_unlock(&sub->lock); return r; } + +void sub_set_recorder_sink(struct dec_sub *sub, struct mp_recorder_sink *sink) +{ + pthread_mutex_lock(&sub->lock); + sub->recorder_sink = sink; + pthread_mutex_unlock(&sub->lock); +} + diff --git a/sub/dec_sub.h b/sub/dec_sub.h index 341966a430..26781fd99f 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -9,6 +9,7 @@ struct sh_stream; struct mpv_global; struct demux_packet; +struct mp_recorder_sink; struct dec_sub; struct sd; @@ -16,7 +17,6 @@ struct sd; enum sd_ctrl { SD_CTRL_SUB_STEP, SD_CTRL_SET_VIDEO_PARAMS, - SD_CTRL_GET_RESOLUTION, SD_CTRL_SET_TOP, SD_CTRL_SET_VIDEO_DEF_FPS, SD_CTRL_UPDATE_SPEED, @@ -41,6 +41,7 @@ void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, int format, char *sub_get_text(struct dec_sub *sub, double pts); void sub_reset(struct dec_sub *sub); void sub_select(struct dec_sub *sub, bool selected); +void sub_set_recorder_sink(struct dec_sub *sub, struct mp_recorder_sink *sink); int sub_control(struct dec_sub *sub, enum sd_ctrl cmd, void *arg); @@ -62,6 +62,8 @@ static const m_option_t style_opts[] = { OPT_FLOATRANGE("blur", blur, 0, 0, 20), OPT_FLAG("bold", bold, 0), OPT_FLAG("italic", italic, 0), + OPT_CHOICE("justify", justify, 0, + ({"auto", 0}, {"left", 1}, {"center", 2}, {"right", 3})), {0} }; @@ -134,6 +134,7 @@ struct osd_style_opts { float blur; int bold; int italic; + int justify; }; extern const struct m_sub_options osd_style_conf; @@ -199,17 +200,9 @@ void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h, struct mp_osd_res res, double compensate_par); // defined in osd_libass.c and osd_dummy.c - -// internal use only -void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj, - int format, struct sub_bitmaps *out_imgs); -void osd_init_backend(struct osd_state *osd); -void osd_destroy_backend(struct osd_state *osd); - void osd_set_external(struct osd_state *osd, void *id, int res_x, int res_y, char *text); - -// doesn't need locking +void osd_get_text_size(struct osd_state *osd, int *out_screen_h, int *out_font_h); void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function); #endif /* MPLAYER_SUB_H */ diff --git a/sub/osd_dummy.c b/sub/osd_dummy.c index 796d954c08..0e6b802cef 100644 --- a/sub/osd_dummy.c +++ b/sub/osd_dummy.c @@ -4,7 +4,7 @@ #include "config.h" #include "mpv_talloc.h" -#include "osd.h" +#include "osd_state.h" void osd_init_backend(struct osd_state *osd) { @@ -28,3 +28,9 @@ void osd_set_external(struct osd_state *osd, void *id, int res_x, int res_y, char *text) { } + +void osd_get_text_size(struct osd_state *osd, int *out_screen_h, int *out_font_h) +{ + *out_screen_h = 0; + *out_font_h = 0; +} diff --git a/sub/osd_libass.c b/sub/osd_libass.c index 454d0387a4..44fcf6d269 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -219,13 +219,10 @@ static ASS_Event *add_osd_ass_event_escaped(ASS_Track *track, const char *style, return e; } -static void update_osd_text(struct osd_state *osd, struct osd_object *obj) +static ASS_Style *prepare_osd_ass(struct osd_state *osd, struct osd_object *obj) { struct MPOpts *opts = osd->opts; - if (!obj->text[0]) - return; - create_ass_track(osd, obj, &obj->ass, 0, 0); struct osd_style_opts font = *opts->osd_style; @@ -236,10 +233,31 @@ static void update_osd_text(struct osd_state *osd, struct osd_object *obj) if (!opts->osd_scale_by_window) playresy *= 720.0 / obj->vo_res.h; - mp_ass_set_style(get_style(&obj->ass, "OSD"), playresy, &font); + ASS_Style *style = get_style(&obj->ass, "OSD"); + mp_ass_set_style(style, playresy, &font); + return style; +} + +static void update_osd_text(struct osd_state *osd, struct osd_object *obj) +{ + + if (!obj->text[0]) + return; + + prepare_osd_ass(osd, obj); add_osd_ass_event_escaped(obj->ass.track, "OSD", obj->text); } +void osd_get_text_size(struct osd_state *osd, int *out_screen_h, int *out_font_h) +{ + pthread_mutex_lock(&osd->lock); + struct osd_object *obj = osd->objs[OSDTYPE_OSD]; + ASS_Style *style = prepare_osd_ass(osd, obj); + *out_screen_h = obj->ass.track->PlayResY - style->MarginV; + *out_font_h = style->FontSize; + pthread_mutex_unlock(&osd->lock); +} + // align: -1 .. +1 // frame: size of the containing area // obj: size of the object that should be positioned inside the area diff --git a/sub/osd_state.h b/sub/osd_state.h index cce415a1b9..dc2d6d5b6c 100644 --- a/sub/osd_state.h +++ b/sub/osd_state.h @@ -79,4 +79,10 @@ struct osd_state { struct mp_draw_sub_cache *draw_cache; }; +// defined in osd_libass.c and osd_dummy.c +void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj, + int format, struct sub_bitmaps *out_imgs); +void osd_init_backend(struct osd_state *osd); +void osd_destroy_backend(struct osd_state *osd); + #endif diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 31c66a6087..9b4d3763c5 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -333,6 +333,10 @@ static void configure_ass(struct sd *sd, struct mp_osd_res *dim, if (converted) set_force_flags |= ASS_OVERRIDE_BIT_ALIGNMENT; #endif +#ifdef ASS_JUSTIFY_AUTO + if ((converted || opts->ass_style_override) && opts->ass_justify) + set_force_flags |= ASS_OVERRIDE_BIT_JUSTIFY; +#endif ass_set_selective_style_override_enabled(priv, set_force_flags); ASS_Style style = {0}; mp_ass_set_style(&style, 288, opts->sub_style); diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 4ce8c5588c..b660912bf5 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -71,35 +71,6 @@ struct sd_lavc_priv { struct bitmap_packer *packer; }; -static void get_resolution(struct sd *sd, int wh[2]) -{ - struct sd_lavc_priv *priv = sd->priv; - enum AVCodecID codec = priv->avctx->codec_id; - int *w = &wh[0], *h = &wh[1]; - *w = priv->avctx->width; - *h = priv->avctx->height; - if (codec == AV_CODEC_ID_DVD_SUBTITLE) { - if (*w <= 0 || *h <= 0) { - *w = priv->video_params.w; - *h = priv->video_params.h; - } - /* XXX Although the video frame is some size, the SPU frame is - always maximum size i.e. 720 wide and 576 or 480 high */ - // For HD files in MKV the VobSub resolution can be higher though, - // see largeres_vobsub.mkv - if (*w <= 720 && *h <= 576) { - *w = 720; - *h = (*h == 480 || *h == 240) ? 480 : 576; - } - } else { - // Hope that PGS subs set these and 720/576 works for dvb subs - if (!*w) - *w = 720; - if (!*h) - *h = 576; - } -} - static int init(struct sd *sd) { enum AVCodecID cid = mp_codec_to_av_codec_id(sd->codec->codec); @@ -466,13 +437,17 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, int format, video_par = -1; if (opts->stretch_image_subs) d.ml = d.mr = d.mt = d.mb = 0; - int insize[2]; - get_resolution(sd, insize); - if (current->src_w > insize[0] || current->src_h > insize[1]) { - insize[0] = priv->video_params.w; - insize[1] = priv->video_params.h; + int w = priv->avctx->width; + int h = priv->avctx->height; + if (w <= 0 || h <= 0 || opts->image_subs_video_res) { + w = priv->video_params.w; + h = priv->video_params.h; } - osd_rescale_bitmaps(res, insize[0], insize[1], d, video_par); + if (current->src_w > w || current->src_h > h) { + w = priv->video_params.w; + h = priv->video_params.h; + } + osd_rescale_bitmaps(res, w, h, d, video_par); } static bool accepts_packet(struct sd *sd, double min_pts) @@ -606,9 +581,6 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) case SD_CTRL_SET_VIDEO_PARAMS: priv->video_params = *(struct mp_image_params *)arg; return CONTROL_OK; - case SD_CTRL_GET_RESOLUTION: - get_resolution(sd, arg); - return CONTROL_OK; default: return CONTROL_UNKNOWN; } |