From 773668b6e85d4da4d252cb4ad8abd50448d70c7c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 21 Oct 2012 18:31:34 +0200 Subject: VF: rename vf_ass to vf_sub This reflects the fact that this filter now renders all types of subtitles, not just ASS subtitles. Always compile this filter, not just on CONFIG_ASS. Note that --no-ass still disables auto-inserting this filter. It's the only way to disable auto-insertion, so keep it even though it's not really ASS specific anymore. --no-ass also disables using libass for rendering text subs directly. --- DOCS/man/en/vf.rst | 4 +- DOCS/tech-overview.txt | 2 +- Makefile | 5 +- libmpcodecs/vf.c | 6 +- libmpcodecs/vf.h | 2 +- libmpcodecs/vf_ass.c | 324 ------------------------------------------------- libmpcodecs/vf_sub.c | 324 +++++++++++++++++++++++++++++++++++++++++++++++++ mplayer.c | 26 ++-- 8 files changed, 344 insertions(+), 349 deletions(-) delete mode 100644 libmpcodecs/vf_ass.c create mode 100644 libmpcodecs/vf_sub.c diff --git a/DOCS/man/en/vf.rst b/DOCS/man/en/vf.rst index b5a672e236..31947e82b6 100644 --- a/DOCS/man/en/vf.rst +++ b/DOCS/man/en/vf.rst @@ -663,14 +663,14 @@ screenshot not always safe to insert this filter by default. See the ``Taking screenshots`` section for details. -ass +sub Moves subtitle rendering to an arbitrary point in the filter chain, or force subtitle rendering in the video filter as opposed to using video output OSD support. *EXAMPLE*: - ``--vf=ass,eq`` + ``--vf=sub,eq`` Moves sub rendering before the eq filter. This will put both subtitle colors and video under the influence of the video equalizer settings. diff --git a/DOCS/tech-overview.txt b/DOCS/tech-overview.txt index 9ffe891c5c..f52601f970 100644 --- a/DOCS/tech-overview.txt +++ b/DOCS/tech-overview.txt @@ -151,7 +151,7 @@ libmpcodecs/: vf_*.c and vf.c form the video filter chain. They are fed by the video decoder, and output the filtered images to the VOs though vf_vo.c. By default, no video filters (except vf_vo) are used, though sometimes - vf_ass.c is inserted for rendering ASS subtitles, when the VO can't. + vf_sub.c is inserted for rendering subtitles, when the VO can't. ad_*.c and dec_audio.c/ad.c handle audio decoding. The audio filter chain is separately in libaf. diff --git a/Makefile b/Makefile index dd476d2a28..7e566f06de 100644 --- a/Makefile +++ b/Makefile @@ -38,9 +38,7 @@ SRCS_COMMON-$(FTP) += stream/stream_ftp.c SRCS_COMMON-$(GIF) += libmpdemux/demux_gif.c SRCS_COMMON-$(HAVE_SYS_MMAN_H) += libaf/af_export.c osdep/mmap_anon.c SRCS_COMMON-$(LADSPA) += libaf/af_ladspa.c -SRCS_COMMON-$(LIBASS) += libmpcodecs/vf_ass.c \ - sub/ass_mp.c \ - sub/sd_ass.c \ +SRCS_COMMON-$(LIBASS) += sub/ass_mp.c sub/sd_ass.c SRCS_COMMON-$(LIBBLURAY) += stream/stream_bluray.c SRCS_COMMON-$(LIBBS2B) += libaf/af_bs2b.c @@ -171,6 +169,7 @@ SRCS_COMMON = asxparser.c \ libmpcodecs/vf_screenshot.c \ libmpcodecs/vf_softpulldown.c \ libmpcodecs/vf_stereo3d.c \ + libmpcodecs/vf_sub.c \ libmpcodecs/vf_swapuv.c \ libmpcodecs/vf_unsharp.c \ libmpcodecs/vf_vo.c \ diff --git a/libmpcodecs/vf.c b/libmpcodecs/vf.c index 5ec7d19570..9ea17f978c 100644 --- a/libmpcodecs/vf.c +++ b/libmpcodecs/vf.c @@ -64,7 +64,7 @@ extern const vf_info_t vf_info_divtc; extern const vf_info_t vf_info_softskip; extern const vf_info_t vf_info_screenshot; extern const vf_info_t vf_info_screenshot_force; -extern const vf_info_t vf_info_ass; +extern const vf_info_t vf_info_sub; extern const vf_info_t vf_info_yadif; extern const vf_info_t vf_info_stereo3d; extern const vf_info_t vf_info_dlopen; @@ -102,9 +102,7 @@ static const vf_info_t *const filter_list[] = { &vf_info_delogo, &vf_info_phase, &vf_info_divtc, -#ifdef CONFIG_ASS - &vf_info_ass, -#endif + &vf_info_sub, &vf_info_yadif, &vf_info_stereo3d, &vf_info_dlopen, diff --git a/libmpcodecs/vf.h b/libmpcodecs/vf.h index 7db9bd5808..4c50f0e9cc 100644 --- a/libmpcodecs/vf.h +++ b/libmpcodecs/vf.h @@ -106,7 +106,7 @@ struct vf_ctrl_screenshot { #define VFCTRL_INIT_OSD 15 // Filter OSD renderer present? #define VFCTRL_SET_DEINTERLACE 18 // Set deinterlacing status #define VFCTRL_GET_DEINTERLACE 19 // Get deinterlacing status -/* Hack to make the OSD state object available to vf_expand and vf_ass which +/* Hack to make the OSD state object available to vf_sub which * access OSD/subtitle state outside of normal OSD draw time. */ #define VFCTRL_SET_OSD_OBJ 20 #define VFCTRL_SET_YUV_COLORSPACE 22 // arg is struct mp_csp_details* diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c deleted file mode 100644 index 1da0b03b44..0000000000 --- a/libmpcodecs/vf_ass.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (C) 2006 Evgeniy Stepanov - * - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "config.h" -#include "mp_msg.h" -#include "options.h" - -#include "img_format.h" -#include "mp_image.h" -#include "vf.h" -#include "sub/sub.h" -#include "sub/dec_sub.h" - -#include "libvo/fastmemcpy.h" -#include "libvo/csputils.h" - -#include "m_option.h" -#include "m_struct.h" - -static const struct vf_priv_s { - int outh, outw; - - unsigned int outfmt; - struct mp_csp_details csp; - - // 1 = auto-added filter: insert only if chain does not support OSD already - // 0 = insert always - int auto_insert; - - struct osd_state *osd; - struct mp_osd_res dim; -} vf_priv_dflt = { - .csp = MP_CSP_DETAILS_DEFAULTS, -}; - -static int config(struct vf_instance *vf, - int width, int height, int d_width, int d_height, - unsigned int flags, unsigned int outfmt) -{ - struct MPOpts *opts = vf->opts; - if (outfmt == IMGFMT_IF09) - return 0; - - 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) { - d_width = d_width * vf->priv->outw / width; - d_height = d_height * vf->priv->outh / height; - } - - double dar = (double)d_width / d_height; - double sar = (double)width / height; - - vf->priv->dim = (struct mp_osd_res) { - .w = vf->priv->outw, - .h = vf->priv->outh, - .mt = opts->ass_top_margin, - .mb = opts->ass_bottom_margin, - .display_par = sar / dar, - .video_par = dar / sar, - }; - - return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, - d_height, flags, outfmt); -} - -static void get_image(struct vf_instance *vf, mp_image_t *mpi) -{ - if (mpi->type == MP_IMGTYPE_IPB) - return; - if (mpi->flags & MP_IMGFLAG_PRESERVE) - return; - if (mpi->imgfmt != vf->priv->outfmt) - return; // colorspace differ - - // width never changes, always try full DR - mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, mpi->type, - mpi->flags | MP_IMGFLAG_READABLE, - FFMAX(mpi->width, vf->priv->outw), - FFMAX(mpi->height, vf->priv->outh)); - - if ((vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) && - !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)) { - mp_tmsg(MSGT_ASS, MSGL_INFO, "Full DR not possible, trying SLICES instead!\n"); - 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] + 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] + tmargin * vf->dmpi->stride[0]; - } - mpi->stride[0] = vf->dmpi->stride[0]; - mpi->width = vf->dmpi->width; - mpi->flags |= MP_IMGFLAG_DIRECT; - mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; -// vf->dmpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK; -} - -static void blank(mp_image_t *mpi, int y1, int y2) -{ - int color[3] = {16, 128, 128}; // black (YUV) - int y; - unsigned char *dst; - int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift; - - dst = mpi->planes[0] + y1 * mpi->stride[0]; - for (y = 0; y < y2 - y1; ++y) { - memset(dst, color[0], mpi->w); - dst += mpi->stride[0]; - } - dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1]; - for (y = 0; y < chroma_rows; ++y) { - memset(dst, color[1], mpi->chroma_width); - dst += mpi->stride[1]; - } - dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2]; - for (y = 0; y < chroma_rows; ++y) { - memset(dst, color[2], mpi->chroma_width); - dst += mpi->stride[2]; - } -} - -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; - if (!vf->dmpi) { - mp_tmsg(MSGT_ASS, MSGL_WARN, "Why do we get NULL??\n"); - return 0; - } - mpi->priv = NULL; - // we've used DR, so we're ready... - 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; - } - - // hope we'll get DR buffer: - vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_TEMP, - MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE, - vf->priv->outw, vf->priv->outh); - - // copy mpi->dmpi... - if (mpi->flags & MP_IMGFLAG_PLANAR) { - 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] + (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] + (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] + tmargin * vf->dmpi->stride[0], - mpi->planes[0], - mpi->w * (vf->dmpi->bpp / 8), - mpi->h, - vf->dmpi->stride[0], - mpi->stride[0]); - vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette - } - 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; -} - -static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) -{ - struct vf_priv_s *priv = vf->priv; - struct osd_state *osd = priv->osd; - - prepare_image(vf, mpi); - - if (pts != MP_NOPTS_VALUE) { - osd_draw_on_image(osd, priv->dim, pts, OSD_DRAW_SUB_FILTER, vf->dmpi, - &priv->csp); - } - - return vf_next_put_image(vf, vf->dmpi, pts); -} - -static int query_format(struct vf_instance *vf, unsigned int fmt) -{ - switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - return vf_next_query_format(vf, vf->priv->outfmt); - } - return 0; -} - -static int control(vf_instance_t *vf, int request, void *data) -{ - switch (request) { - case VFCTRL_SET_OSD_OBJ: - vf->priv->osd = data; - break; - case VFCTRL_INIT_OSD: - return CONTROL_TRUE; - case VFCTRL_SET_YUV_COLORSPACE: { - struct mp_csp_details colorspace = *(struct mp_csp_details *)data; - vf->priv->csp = colorspace; - break; - } - } - return vf_next_control(vf, request, data); -} - -static void uninit(struct vf_instance *vf) -{ - free(vf->priv); -} - -static const unsigned int fmt_list[] = { - IMGFMT_YV12, - IMGFMT_I420, - IMGFMT_IYUV, - 0 -}; - -static int vf_open(vf_instance_t *vf, char *args) -{ - int flags; - vf->priv->outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12); - if (vf->priv->outfmt) - flags = vf_next_query_format(vf, vf->priv->outfmt); - if (!vf->priv->outfmt) { - uninit(vf); - return 0; - } else if (vf->priv->auto_insert && flags & VFCAP_OSD) { - uninit(vf); - return -1; - } - - if (vf->priv->auto_insert) - mp_msg(MSGT_ASS, MSGL_INFO, "[ass] auto-open\n"); - - vf->config = config; - vf->query_format = query_format; - vf->uninit = uninit; - vf->control = control; - vf->get_image = get_image; - vf->put_image = put_image; - vf->default_caps = VFCAP_OSD; - return 1; -} - -#define ST_OFF(f) M_ST_OFF(struct vf_priv_s, f) -static const m_option_t vf_opts_fields[] = { - {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0, 0, 1, NULL}, - {NULL, NULL, 0, 0, 0, 0, NULL} -}; - -static const m_struct_t vf_opts = { - "ass", - sizeof(struct vf_priv_s), - &vf_priv_dflt, - vf_opts_fields -}; - -const vf_info_t vf_info_ass = { - "Render ASS/SSA subtitles", - "ass", - "Evgeniy Stepanov", - "", - vf_open, - &vf_opts -}; diff --git a/libmpcodecs/vf_sub.c b/libmpcodecs/vf_sub.c new file mode 100644 index 0000000000..e377d589c5 --- /dev/null +++ b/libmpcodecs/vf_sub.c @@ -0,0 +1,324 @@ +/* + * Copyright (C) 2006 Evgeniy Stepanov + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "mp_msg.h" +#include "options.h" + +#include "img_format.h" +#include "mp_image.h" +#include "vf.h" +#include "sub/sub.h" +#include "sub/dec_sub.h" + +#include "libvo/fastmemcpy.h" +#include "libvo/csputils.h" + +#include "m_option.h" +#include "m_struct.h" + +static const struct vf_priv_s { + int outh, outw; + + unsigned int outfmt; + struct mp_csp_details csp; + + // 1 = auto-added filter: insert only if chain does not support OSD already + // 0 = insert always + int auto_insert; + + struct osd_state *osd; + struct mp_osd_res dim; +} vf_priv_dflt = { + .csp = MP_CSP_DETAILS_DEFAULTS, +}; + +static int config(struct vf_instance *vf, + int width, int height, int d_width, int d_height, + unsigned int flags, unsigned int outfmt) +{ + struct MPOpts *opts = vf->opts; + if (outfmt == IMGFMT_IF09) + return 0; + + 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) { + d_width = d_width * vf->priv->outw / width; + d_height = d_height * vf->priv->outh / height; + } + + double dar = (double)d_width / d_height; + double sar = (double)width / height; + + vf->priv->dim = (struct mp_osd_res) { + .w = vf->priv->outw, + .h = vf->priv->outh, + .mt = opts->ass_top_margin, + .mb = opts->ass_bottom_margin, + .display_par = sar / dar, + .video_par = dar / sar, + }; + + return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, + d_height, flags, outfmt); +} + +static void get_image(struct vf_instance *vf, mp_image_t *mpi) +{ + if (mpi->type == MP_IMGTYPE_IPB) + return; + if (mpi->flags & MP_IMGFLAG_PRESERVE) + return; + if (mpi->imgfmt != vf->priv->outfmt) + return; // colorspace differ + + // width never changes, always try full DR + mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, mpi->type, + mpi->flags | MP_IMGFLAG_READABLE, + FFMAX(mpi->width, vf->priv->outw), + FFMAX(mpi->height, vf->priv->outh)); + + if ((vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) && + !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)) { + mp_tmsg(MSGT_ASS, MSGL_INFO, "Full DR not possible, trying SLICES instead!\n"); + 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] + 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] + tmargin * vf->dmpi->stride[0]; + } + mpi->stride[0] = vf->dmpi->stride[0]; + mpi->width = vf->dmpi->width; + mpi->flags |= MP_IMGFLAG_DIRECT; + mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; +// vf->dmpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK; +} + +static void blank(mp_image_t *mpi, int y1, int y2) +{ + int color[3] = {16, 128, 128}; // black (YUV) + int y; + unsigned char *dst; + int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift; + + dst = mpi->planes[0] + y1 * mpi->stride[0]; + for (y = 0; y < y2 - y1; ++y) { + memset(dst, color[0], mpi->w); + dst += mpi->stride[0]; + } + dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1]; + for (y = 0; y < chroma_rows; ++y) { + memset(dst, color[1], mpi->chroma_width); + dst += mpi->stride[1]; + } + dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2]; + for (y = 0; y < chroma_rows; ++y) { + memset(dst, color[2], mpi->chroma_width); + dst += mpi->stride[2]; + } +} + +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; + if (!vf->dmpi) { + mp_tmsg(MSGT_ASS, MSGL_WARN, "Why do we get NULL??\n"); + return 0; + } + mpi->priv = NULL; + // we've used DR, so we're ready... + 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; + } + + // hope we'll get DR buffer: + vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_TEMP, + MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE, + vf->priv->outw, vf->priv->outh); + + // copy mpi->dmpi... + if (mpi->flags & MP_IMGFLAG_PLANAR) { + 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] + (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] + (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] + tmargin * vf->dmpi->stride[0], + mpi->planes[0], + mpi->w * (vf->dmpi->bpp / 8), + mpi->h, + vf->dmpi->stride[0], + mpi->stride[0]); + vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette + } + 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; +} + +static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) +{ + struct vf_priv_s *priv = vf->priv; + struct osd_state *osd = priv->osd; + + prepare_image(vf, mpi); + + if (pts != MP_NOPTS_VALUE) { + osd_draw_on_image(osd, priv->dim, pts, OSD_DRAW_SUB_FILTER, vf->dmpi, + &priv->csp); + } + + return vf_next_put_image(vf, vf->dmpi, pts); +} + +static int query_format(struct vf_instance *vf, unsigned int fmt) +{ + switch (fmt) { + case IMGFMT_YV12: + case IMGFMT_I420: + case IMGFMT_IYUV: + return vf_next_query_format(vf, vf->priv->outfmt); + } + return 0; +} + +static int control(vf_instance_t *vf, int request, void *data) +{ + switch (request) { + case VFCTRL_SET_OSD_OBJ: + vf->priv->osd = data; + break; + case VFCTRL_INIT_OSD: + return CONTROL_TRUE; + case VFCTRL_SET_YUV_COLORSPACE: { + struct mp_csp_details colorspace = *(struct mp_csp_details *)data; + vf->priv->csp = colorspace; + break; + } + } + return vf_next_control(vf, request, data); +} + +static void uninit(struct vf_instance *vf) +{ + free(vf->priv); +} + +static const unsigned int fmt_list[] = { + IMGFMT_YV12, + IMGFMT_I420, + IMGFMT_IYUV, + 0 +}; + +static int vf_open(vf_instance_t *vf, char *args) +{ + int flags; + vf->priv->outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12); + if (vf->priv->outfmt) + flags = vf_next_query_format(vf, vf->priv->outfmt); + if (!vf->priv->outfmt) { + uninit(vf); + return 0; + } else if (vf->priv->auto_insert && flags & VFCAP_OSD) { + uninit(vf); + return -1; + } + + if (vf->priv->auto_insert) + mp_msg(MSGT_ASS, MSGL_INFO, "[sub] auto-open\n"); + + vf->config = config; + vf->query_format = query_format; + vf->uninit = uninit; + vf->control = control; + vf->get_image = get_image; + vf->put_image = put_image; + vf->default_caps = VFCAP_OSD; + return 1; +} + +#define ST_OFF(f) M_ST_OFF(struct vf_priv_s, f) +static const m_option_t vf_opts_fields[] = { + {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0, 0, 1, NULL}, + {NULL, NULL, 0, 0, 0, 0, NULL} +}; + +static const m_struct_t vf_opts = { + "sub", + sizeof(struct vf_priv_s), + &vf_priv_dflt, + vf_opts_fields +}; + +const vf_info_t vf_info_sub = { + "Render subtitles", + "sub", + "Evgeniy Stepanov", + "", + vf_open, + &vf_opts +}; diff --git a/mplayer.c b/mplayer.c index 49edfc4636..de85ec2c33 100644 --- a/mplayer.c +++ b/mplayer.c @@ -2267,39 +2267,37 @@ int reinit_video_chain(struct MPContext *mpctx) sh_video->vfilter = vf_open_filter(opts, NULL, "vo", vf_arg); } -#ifdef CONFIG_ASS if (opts->ass_enabled) { int i; int insert = 1; if (opts->vf_settings) for (i = 0; opts->vf_settings[i].name; ++i) - if (strcmp(opts->vf_settings[i].name, "ass") == 0) { + if (strcmp(opts->vf_settings[i].name, "sub") == 0) { insert = 0; break; } if (insert) { - extern vf_info_t vf_info_ass; - const vf_info_t *libass_vfs[] = { - &vf_info_ass, NULL + extern vf_info_t vf_info_sub; + const vf_info_t *sub_vfs[] = { + &vf_info_sub, NULL }; char *vf_arg[] = { "auto", "yes", NULL }; int retcode = 0; - struct vf_instance *vf_ass = vf_open_plugin_noerr(opts, libass_vfs, + struct vf_instance *vf_sub = vf_open_plugin_noerr(opts, sub_vfs, sh_video->vfilter, - "ass", vf_arg, + "sub", vf_arg, &retcode); - if (vf_ass) - sh_video->vfilter = vf_ass; - else if (retcode == -1) // vf_ass open() returns -1 VO has OSD - mp_msg(MSGT_CPLAYER, MSGL_V, "[ass] vf_ass not needed\n"); + if (vf_sub) + sh_video->vfilter = vf_sub; + else if (retcode == -1) // vf_sub open() returns -1 VO has OSD + mp_msg(MSGT_CPLAYER, MSGL_V, "[sub] vf_sub not needed\n"); else mp_msg(MSGT_CPLAYER, MSGL_ERR, - "ASS: cannot add video filter\n"); + "sub: cannot add video filter\n"); } } -#endif sh_video->vfilter = append_filters(sh_video->vfilter, opts->vf_settings); @@ -2415,7 +2413,7 @@ static double update_video(struct MPContext *mpctx) struct sh_video *sh_video = mpctx->sh_video; struct vo *video_out = mpctx->video_out; sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SET_OSD_OBJ, - mpctx->osd); // for vf_ass + mpctx->osd); // for vf_sub if (!mpctx->opts.correct_pts) return update_video_nocorrect_pts(mpctx); -- cgit v1.2.3