From 83fc5b60046b12227540f77969b5c1aa29107bad Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 3 Sep 2011 13:47:56 +0300 Subject: options: move libass-related options to struct --- cfg-mplayer.h | 22 +++++++++--------- command.c | 11 ++++----- defaultopts.c | 3 +++ libmpcodecs/vf_ass.c | 43 +++++++++++++++++++---------------- libmpcodecs/vf_vo.c | 4 ++-- mplayer.c | 6 ++--- options.h | 10 +++++++++ sub/ass_mp.c | 63 +++++++++++++++++++++------------------------------- sub/ass_mp.h | 23 ++++++------------- sub/sd_ass.c | 2 +- 10 files changed, 91 insertions(+), 96 deletions(-) diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 5dd9962238..fc87ed88d8 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -693,20 +693,18 @@ const m_option_t common_opts[] = { #endif #ifdef CONFIG_ASS OPT_MAKE_FLAGS("ass", ass_enabled, 0), - {"ass-font-scale", &ass_font_scale, CONF_TYPE_FLOAT, CONF_RANGE, 0, 100, NULL}, - {"ass-line-spacing", &ass_line_spacing, CONF_TYPE_FLOAT, CONF_RANGE, -1000, 1000, NULL}, - {"ass-top-margin", &ass_top_margin, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL}, - {"ass-bottom-margin", &ass_bottom_margin, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL}, - {"ass-use-margins", &ass_use_margins, CONF_TYPE_FLAG, 0, 0, 1, NULL}, - {"noass-use-margins", &ass_use_margins, CONF_TYPE_FLAG, 0, 1, 0, NULL}, + OPT_FLOATRANGE("ass-font-scale", ass_font_scale, 0, 0, 100), + OPT_FLOATRANGE("ass-line-spacing", ass_line_spacing, 0, -1000, 1000), + OPT_INTRANGE("ass-top-margin", ass_top_margin, 0, 0, 2000), + OPT_INTRANGE("ass-bottom-margin", ass_bottom_margin, 0, 0, 2000), + OPT_MAKE_FLAGS("ass-use-margins", ass_use_margins, 0), OPT_MAKE_FLAGS("ass-vsfilter-aspect-compat", ass_vsfilter_aspect_compat, 0), - {"embeddedfonts", &use_embedded_fonts, CONF_TYPE_FLAG, 0, 0, 1, NULL}, - {"noembeddedfonts", &use_embedded_fonts, CONF_TYPE_FLAG, 0, 1, 0, NULL}, + OPT_MAKE_FLAGS("embeddedfonts", use_embedded_fonts, 0), OPT_STRINGLIST("ass-force-style", ass_force_style_list, 0), - {"ass-color", &ass_color, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"ass-border-color", &ass_border_color, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"ass-styles", &ass_styles_file, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"ass-hinting", &ass_hinting, CONF_TYPE_INT, CONF_RANGE, 0, 7, NULL}, + OPT_STRING("ass-color", ass_color, 0), + OPT_STRING("ass-border-color", ass_border_color, 0), + OPT_STRING("ass-styles", ass_styles_file, 0), + OPT_INTRANGE("ass-hinting", ass_hinting, 0, 0, 7), #endif #ifdef CONFIG_FONTCONFIG {"fontconfig", &font_fontconfig, CONF_TYPE_FLAG, 0, -1, 1, NULL}, diff --git a/command.c b/command.c index 1dea8cfaab..e9fc49fd17 100644 --- a/command.c +++ b/command.c @@ -1959,6 +1959,7 @@ static int mp_property_sub_visibility(m_option_t *prop, int action, static int mp_property_ass_use_margins(m_option_t *prop, int action, void *arg, MPContext *mpctx) { + struct MPOpts *opts = &mpctx->opts; if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; @@ -1970,7 +1971,7 @@ static int mp_property_ass_use_margins(m_option_t *prop, int action, case M_PROPERTY_STEP_DOWN: mpctx->osd->ass_force_reload = true; default: - return m_property_flag(prop, action, arg, &ass_use_margins); + return m_property_flag(prop, action, arg, &opts->ass_use_margins); } } @@ -2032,7 +2033,7 @@ static int mp_property_sub_scale(m_option_t *prop, int action, void *arg, M_PROPERTY_CLAMP(prop, *(float *) arg); #ifdef CONFIG_ASS if (opts->ass_enabled) { - ass_font_scale = *(float *) arg; + opts->ass_font_scale = *(float *) arg; mpctx->osd->ass_force_reload = true; } #endif @@ -2044,9 +2045,9 @@ static int mp_property_sub_scale(m_option_t *prop, int action, void *arg, case M_PROPERTY_STEP_DOWN: #ifdef CONFIG_ASS if (opts->ass_enabled) { - ass_font_scale += (arg ? *(float *) arg : 0.1) * + opts->ass_font_scale += (arg ? *(float *) arg : 0.1) * (action == M_PROPERTY_STEP_UP ? 1.0 : -1.0); - M_PROPERTY_CLAMP(prop, ass_font_scale); + M_PROPERTY_CLAMP(prop, opts->ass_font_scale); mpctx->osd->ass_force_reload = true; } #endif @@ -2059,7 +2060,7 @@ static int mp_property_sub_scale(m_option_t *prop, int action, void *arg, default: #ifdef CONFIG_ASS if (opts->ass_enabled) - return m_property_float_ro(prop, action, arg, ass_font_scale); + return m_property_float_ro(prop, action, arg, opts->ass_font_scale); else #endif return m_property_float_ro(prop, action, arg, text_font_scale_factor); diff --git a/defaultopts.c b/defaultopts.c index a249ec05b6..bfaa1ba777 100644 --- a/defaultopts.c +++ b/defaultopts.c @@ -49,7 +49,10 @@ void set_default_mplayer_options(struct MPOpts *opts) #ifdef CONFIG_ASS .ass_enabled = 1, #endif + .ass_font_scale = 1, .ass_vsfilter_aspect_compat = 1, + .use_embedded_fonts = 1, + .ass_hinting = 5, // light hinting for unscaled osd .lavc_param = { .workaround_bugs = 1, // autodetect diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c index c34c0b88e3..c5613ce992 100644 --- a/libmpcodecs/vf_ass.c +++ b/libmpcodecs/vf_ass.c @@ -81,7 +81,7 @@ static int config(struct vf_instance *vf, if (outfmt == IMGFMT_IF09) return 0; - vf->priv->outh = height + ass_top_margin + ass_bottom_margin; + vf->priv->outh = height + opts->ass_top_margin + opts->ass_bottom_margin; vf->priv->outw = width; if (!opts->screen_size_x && !opts->screen_size_y) { @@ -94,9 +94,9 @@ static int config(struct vf_instance *vf, vf->priv->line_limits = malloc((vf->priv->outh + 1) / 2 * sizeof(*vf->priv->line_limits)); if (vf->priv->renderer_realaspect) { - mp_ass_configure(vf->priv->renderer_realaspect, + mp_ass_configure(vf->priv->renderer_realaspect, opts, vf->priv->outw, vf->priv->outh, 0); - mp_ass_configure(vf->priv->renderer_vsfilter, + mp_ass_configure(vf->priv->renderer_vsfilter, opts, vf->priv->outw, vf->priv->outh, 0); ass_set_aspect_ratio(vf->priv->renderer_realaspect, (double)width / height * d_height / d_width, 1); @@ -127,15 +127,16 @@ static void get_image(struct vf_instance *vf, mp_image_t *mpi) return; } + int tmargin = vf->opts->ass_top_margin; // set up mpi as a cropped-down image of dmpi: if (mpi->flags & MP_IMGFLAG_PLANAR) { - mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0]; - mpi->planes[1] = vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1]; - mpi->planes[2] = vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2]; + mpi->planes[0] = vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0]; + mpi->planes[1] = vf->dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[1]; + mpi->planes[2] = vf->dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[2]; mpi->stride[1] = vf->dmpi->stride[1]; mpi->stride[2] = vf->dmpi->stride[2]; } else { - mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0]; + mpi->planes[0] = vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0]; } mpi->stride[0] = vf->dmpi->stride[0]; mpi->width = vf->dmpi->width; @@ -170,6 +171,8 @@ static void blank(mp_image_t *mpi, int y1, int y2) static int prepare_image(struct vf_instance *vf, mp_image_t *mpi) { + struct MPOpts *opts = vf->opts; + int tmargin = opts->ass_top_margin; if (mpi->flags & MP_IMGFLAG_DIRECT || mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) { vf->dmpi = mpi->priv; @@ -179,10 +182,11 @@ static int prepare_image(struct vf_instance *vf, mp_image_t *mpi) } mpi->priv = NULL; // we've used DR, so we're ready... - if (ass_top_margin) - blank(vf->dmpi, 0, ass_top_margin); - if (ass_bottom_margin) - blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh); + if (tmargin) + blank(vf->dmpi, 0, tmargin); + if (opts->ass_bottom_margin) + blank(vf->dmpi, vf->priv->outh - opts->ass_bottom_margin, + vf->priv->outh); if (!(mpi->flags & MP_IMGFLAG_PLANAR)) vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette return 0; @@ -195,26 +199,26 @@ static int prepare_image(struct vf_instance *vf, mp_image_t *mpi) // copy mpi->dmpi... if (mpi->flags & MP_IMGFLAG_PLANAR) { - memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0], + memcpy_pic(vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h, vf->dmpi->stride[0], mpi->stride[0]); - memcpy_pic(vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1], + memcpy_pic(vf->dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[1], mpi->planes[1], mpi->w >> mpi->chroma_x_shift, mpi->h >> mpi->chroma_y_shift, vf->dmpi->stride[1], mpi->stride[1]); - memcpy_pic(vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2], + memcpy_pic(vf->dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[2], mpi->planes[2], mpi->w >> mpi->chroma_x_shift, mpi->h >> mpi->chroma_y_shift, vf->dmpi->stride[2], mpi->stride[2]); } else { - memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0], + memcpy_pic(vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0], mpi->planes[0], mpi->w * (vf->dmpi->bpp / 8), mpi->h, @@ -222,10 +226,11 @@ static int prepare_image(struct vf_instance *vf, mp_image_t *mpi) mpi->stride[0]); vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette } - if (ass_top_margin) - blank(vf->dmpi, 0, ass_top_margin); - if (ass_bottom_margin) - blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh); + if (tmargin) + blank(vf->dmpi, 0, tmargin); + if (opts->ass_bottom_margin) + blank(vf->dmpi, vf->priv->outh - opts->ass_bottom_margin, + vf->priv->outh); return 0; } diff --git a/libmpcodecs/vf_vo.c b/libmpcodecs/vf_vo.c index 347c1e96b1..9e2612654c 100644 --- a/libmpcodecs/vf_vo.c +++ b/libmpcodecs/vf_vo.c @@ -86,9 +86,9 @@ static int config(struct vf_instance *vf, vf->priv->scale_ratio = (double) d_width / d_height * height / width; if (vf->priv->renderer_realaspect) { - mp_ass_configure(vf->priv->renderer_realaspect, width, height, + mp_ass_configure(vf->priv->renderer_realaspect, vf->opts, width, height, vf->default_caps & VFCAP_EOSD_UNSCALED); - mp_ass_configure(vf->priv->renderer_vsfilter, width, height, + mp_ass_configure(vf->priv->renderer_vsfilter, vf->opts, width, height, vf->default_caps & VFCAP_EOSD_UNSCALED); } #endif diff --git a/mplayer.c b/mplayer.c index 55d81627bb..a3e8c9b5df 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1134,7 +1134,7 @@ void add_subtitles(struct MPContext *mpctx, char *filename, float fps, if (!asst) { subd = sub_read_file(filename, fps, &mpctx->opts); if (subd) { - asst = mp_ass_read_subdata(mpctx->ass_library, subd, fps); + asst = mp_ass_read_subdata(mpctx->ass_library, opts, subd, fps); sub_free(subd); subd = NULL; } @@ -4178,7 +4178,7 @@ int main(int argc, char *argv[]) #endif #ifdef CONFIG_ASS - mpctx->ass_library = mp_ass_init(); + mpctx->ass_library = mp_ass_init(opts); mpctx->osd->ass_library = mpctx->ass_library; #endif @@ -4688,7 +4688,7 @@ goto_enable_cache: struct demuxer *d = mpctx->sources[j].demuxer; for (int i = 0; i < d->num_attachments; i++) { struct demux_attachment *att = d->attachments + i; - if (use_embedded_fonts && attachment_is_font(att)) + if (opts->use_embedded_fonts && attachment_is_font(att)) ass_add_font(mpctx->ass_library, att->name, att->data, att->data_size); } diff --git a/options.h b/options.h index f6f28c0939..6ee25351c8 100644 --- a/options.h +++ b/options.h @@ -92,8 +92,18 @@ typedef struct MPOpts { char **sub_paths; int sub_auto; int ass_enabled; + float ass_font_scale; + float ass_line_spacing; + int ass_top_margin; + int ass_bottom_margin; + int ass_use_margins; int ass_vsfilter_aspect_compat; + int use_embedded_fonts; char **ass_force_style_list; + char *ass_color; + char *ass_border_color; + char *ass_styles_file; + int ass_hinting; struct lavc_param { int workaround_bugs; int error_resilience; diff --git a/sub/ass_mp.c b/sub/ass_mp.c index 6fd50342c3..8af3698a47 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -35,22 +35,7 @@ #include "ass_mp.h" #include "subreader.h" #include "stream/stream.h" - -#ifdef CONFIG_FONTCONFIG -#include -#endif - -// libass-related command line options -float ass_font_scale = 1.; -float ass_line_spacing = 0.; -int ass_top_margin = 0; -int ass_bottom_margin = 0; -int use_embedded_fonts = 1; -int ass_use_margins = 0; -char *ass_color = NULL; -char *ass_border_color = NULL; -char *ass_styles_file = NULL; -int ass_hinting = ASS_HINTING_LIGHT + 4; // light hinting for unscaled osd +#include "options.h" #ifdef CONFIG_FONTCONFIG extern int font_fontconfig; @@ -68,7 +53,7 @@ extern char *sub_cp; static char *sub_cp = 0; #endif -ASS_Track *mp_ass_default_track(ASS_Library *library) +ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts) { ASS_Track *track = ass_new_track(library); @@ -77,8 +62,8 @@ ASS_Track *mp_ass_default_track(ASS_Library *library) track->PlayResY = 288; track->WrapStyle = 0; - if (ass_styles_file) - ass_read_styles(track, ass_styles_file, sub_cp); + if (opts->ass_styles_file) + ass_read_styles(track, opts->ass_styles_file, sub_cp); if (track->n_styles == 0) { track->Kerning = true; @@ -107,10 +92,10 @@ ASS_Track *mp_ass_default_track(ASS_Library *library) uint32_t c1 = 0xFFFFFF00; uint32_t c2 = 0x00000000; - if (ass_color) - c1 = strtoll(ass_color, NULL, 16); - if (ass_border_color) - c2 = strtoll(ass_border_color, NULL, 16); + if (opts->ass_color) + c1 = strtoll(opts->ass_color, NULL, 16); + if (opts->ass_border_color) + c2 = strtoll(opts->ass_border_color, NULL, 16); style->FontSize = fs; style->PrimaryColour = c1; @@ -208,13 +193,13 @@ static int ass_process_subtitle(ASS_Track *track, subtitle *sub) * \param fps video framerate * \return newly allocated ASS_Track, filled with subtitles from subdata */ -ASS_Track *mp_ass_read_subdata(ASS_Library *library, sub_data *subdata, - double fps) +ASS_Track *mp_ass_read_subdata(ASS_Library *library, struct MPOpts *opts, + sub_data *subdata, double fps) { ASS_Track *track; int i; - track = mp_ass_default_track(library); + track = mp_ass_default_track(library, opts); track->name = subdata->filename ? strdup(subdata->filename) : 0; for (i = 0; i < subdata->sub_num; ++i) { @@ -257,19 +242,20 @@ ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname, return track; } -void mp_ass_configure(ASS_Renderer *priv, int w, int h, bool unscaled) +void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, int w, int h, + bool unscaled) { int hinting; ass_set_frame_size(priv, w, h); - ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0); - ass_set_use_margins(priv, ass_use_margins); - ass_set_font_scale(priv, ass_font_scale); - if (!unscaled && (ass_hinting & 4)) + ass_set_margins(priv, opts->ass_top_margin, opts->ass_bottom_margin, 0, 0); + ass_set_use_margins(priv, opts->ass_use_margins); + ass_set_font_scale(priv, opts->ass_font_scale); + if (!unscaled && (opts->ass_hinting & 4)) hinting = 0; else - hinting = ass_hinting & 3; + hinting = opts->ass_hinting & 3; ass_set_hinting(priv, hinting); - ass_set_line_spacing(priv, ass_line_spacing); + ass_set_line_spacing(priv, opts->ass_line_spacing); } void mp_ass_configure_fonts(ASS_Renderer *priv) @@ -304,14 +290,14 @@ static void message_callback(int level, const char *format, va_list va, void *ct mp_msg(MSGT_ASS, level, "\n"); } -ASS_Library *mp_ass_init(void) +ASS_Library *mp_ass_init(struct MPOpts *opts) { ASS_Library *priv; char *path = get_path("fonts"); priv = ass_library_init(); ass_set_message_cb(priv, message_callback, NULL); ass_set_fonts_dir(priv, path); - ass_set_extract_fonts(priv, use_embedded_fonts); + ass_set_extract_fonts(priv, opts->use_embedded_fonts); free(path); return priv; } @@ -320,8 +306,9 @@ void mp_ass_reload_options(ASS_Renderer *priv, struct MPOpts *opts) { /* This could be needed for vf_ass case if the margins were actually * runtime configurable, but would be wrong with EOSD: - * ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0); + * ass_set_margins(priv, opts->ass_top_margin, opts->ass_bottom_margin, + * 0, 0); */ - ass_set_use_margins(priv, ass_use_margins); - ass_set_font_scale(priv, ass_font_scale); + ass_set_use_margins(priv, opts->ass_use_margins); + ass_set_font_scale(priv, opts->ass_font_scale); } diff --git a/sub/ass_mp.h b/sub/ass_mp.h index 5658f4f8c1..a222d61bbb 100644 --- a/sub/ass_mp.h +++ b/sub/ass_mp.h @@ -31,26 +31,17 @@ #include #include -extern float ass_font_scale; -extern float ass_line_spacing; -extern int ass_top_margin; -extern int ass_bottom_margin; -extern int use_embedded_fonts; -extern int ass_use_margins; -extern char *ass_color; -extern char *ass_border_color; -extern char *ass_styles_file; -extern int ass_hinting; - -ASS_Track *mp_ass_default_track(ASS_Library *library); -ASS_Track *mp_ass_read_subdata(ASS_Library *library, sub_data *subdata, - double fps); +ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts); +ASS_Track *mp_ass_read_subdata(ASS_Library *library, struct MPOpts *opts, + sub_data *subdata, double fps); ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname, char *charset); -void mp_ass_configure(ASS_Renderer *priv, int w, int h, bool unscaled); +struct MPOpts; +void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, int w, int h, + bool unscaled); void mp_ass_configure_fonts(ASS_Renderer *priv); -ASS_Library *mp_ass_init(void); +ASS_Library *mp_ass_init(struct MPOpts *opts); void mp_ass_reload_options(ASS_Renderer *priv, struct MPOpts *opts); diff --git a/sub/sd_ass.c b/sub/sd_ass.c index e386cb50d9..0e15a7e28b 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -58,7 +58,7 @@ static void init(struct sh_sub *sh, struct osd_state *osd) ass_process_codec_private(ctx->ass_track, sh->extradata, sh->extradata_len); } else - ctx->ass_track = mp_ass_default_track(osd->ass_library); + ctx->ass_track = mp_ass_default_track(osd->ass_library, sh->opts); } assert(osd->ass_track == NULL); -- cgit v1.2.3