2006-10-01 17:09:04 +00:00
|
|
|
/*
|
2008-05-13 10:16:20 +00:00
|
|
|
* Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-10-01 17:09:04 +00:00
|
|
|
|
2006-07-07 18:26:51 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-09-18 09:30:42 +00:00
|
|
|
#include <inttypes.h>
|
2006-07-07 18:26:51 +00:00
|
|
|
#include <assert.h>
|
2012-05-25 20:31:10 +00:00
|
|
|
#include <libavutil/common.h>
|
2006-07-07 18:26:51 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/mp_msg.h"
|
|
|
|
#include "core/options.h"
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2006-07-07 18:26:51 +00:00
|
|
|
#include "vf.h"
|
2011-01-26 17:40:52 +00:00
|
|
|
#include "sub/sub.h"
|
2012-10-04 15:16:40 +00:00
|
|
|
#include "sub/dec_sub.h"
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/memcpy_pic.h"
|
|
|
|
#include "video/csputils.h"
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/m_option.h"
|
|
|
|
#include "core/m_struct.h"
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2007-11-09 06:58:32 +00:00
|
|
|
static const struct vf_priv_s {
|
2010-10-30 19:15:15 +00:00
|
|
|
int outh, outw;
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2010-10-30 19:15:15 +00:00
|
|
|
unsigned int outfmt;
|
2012-10-19 17:11:08 +00:00
|
|
|
struct mp_csp_details csp;
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2011-01-12 13:15:02 +00:00
|
|
|
struct osd_state *osd;
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
struct mp_osd_res dim;
|
2012-10-19 17:11:08 +00:00
|
|
|
} vf_priv_dflt = {
|
|
|
|
.csp = MP_CSP_DETAILS_DEFAULTS,
|
|
|
|
};
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int config(struct vf_instance *vf,
|
2010-10-30 19:15:15 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt)
|
2006-07-07 18:26:51 +00:00
|
|
|
{
|
2010-10-30 19:15:15 +00:00
|
|
|
struct MPOpts *opts = vf->opts;
|
|
|
|
if (outfmt == IMGFMT_IF09)
|
|
|
|
return 0;
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2011-09-03 10:47:56 +00:00
|
|
|
vf->priv->outh = height + opts->ass_top_margin + opts->ass_bottom_margin;
|
2010-10-30 19:15:15 +00:00
|
|
|
vf->priv->outw = width;
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2010-10-30 19:15:15 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2012-10-18 15:31:00 +00:00
|
|
|
double dar = (double)d_width / d_height;
|
|
|
|
double sar = (double)width / height;
|
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
vf->priv->dim = (struct mp_osd_res) {
|
2012-10-18 15:31:00 +00:00
|
|
|
.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,
|
|
|
|
};
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2010-10-30 19:15:15 +00:00
|
|
|
return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width,
|
|
|
|
d_height, flags, outfmt);
|
2006-07-07 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void get_image(struct vf_instance *vf, mp_image_t *mpi)
|
2006-07-07 18:26:51 +00:00
|
|
|
{
|
2010-10-30 19:15:15 +00:00
|
|
|
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,
|
2012-05-25 20:31:10 +00:00
|
|
|
FFMAX(mpi->width, vf->priv->outw),
|
|
|
|
FFMAX(mpi->height, vf->priv->outh));
|
2010-10-30 19:15:15 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-03 10:47:56 +00:00
|
|
|
int tmargin = vf->opts->ass_top_margin;
|
2010-10-30 19:15:15 +00:00
|
|
|
// set up mpi as a cropped-down image of dmpi:
|
|
|
|
if (mpi->flags & MP_IMGFLAG_PLANAR) {
|
2011-09-03 10:47:56 +00:00
|
|
|
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];
|
2010-10-30 19:15:15 +00:00
|
|
|
mpi->stride[1] = vf->dmpi->stride[1];
|
|
|
|
mpi->stride[2] = vf->dmpi->stride[2];
|
|
|
|
} else {
|
2011-09-03 10:47:56 +00:00
|
|
|
mpi->planes[0] = vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0];
|
2010-10-30 19:15:15 +00:00
|
|
|
}
|
|
|
|
mpi->stride[0] = vf->dmpi->stride[0];
|
|
|
|
mpi->width = vf->dmpi->width;
|
|
|
|
mpi->flags |= MP_IMGFLAG_DIRECT;
|
|
|
|
mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
|
2006-07-07 18:26:51 +00:00
|
|
|
// vf->dmpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blank(mp_image_t *mpi, int y1, int y2)
|
|
|
|
{
|
2010-10-30 19:15:15 +00:00
|
|
|
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];
|
|
|
|
}
|
2006-07-07 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int prepare_image(struct vf_instance *vf, mp_image_t *mpi)
|
2006-07-07 18:26:51 +00:00
|
|
|
{
|
2011-09-03 10:47:56 +00:00
|
|
|
struct MPOpts *opts = vf->opts;
|
|
|
|
int tmargin = opts->ass_top_margin;
|
2010-10-30 19:15:15 +00:00
|
|
|
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...
|
2011-09-03 10:47:56 +00:00
|
|
|
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);
|
2010-10-30 19:15:15 +00:00
|
|
|
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) {
|
2011-09-03 10:47:56 +00:00
|
|
|
memcpy_pic(vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0],
|
2010-10-30 19:15:15 +00:00
|
|
|
mpi->planes[0],
|
|
|
|
mpi->w,
|
|
|
|
mpi->h,
|
|
|
|
vf->dmpi->stride[0],
|
|
|
|
mpi->stride[0]);
|
2011-09-03 10:47:56 +00:00
|
|
|
memcpy_pic(vf->dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[1],
|
2010-10-30 19:15:15 +00:00
|
|
|
mpi->planes[1],
|
|
|
|
mpi->w >> mpi->chroma_x_shift,
|
|
|
|
mpi->h >> mpi->chroma_y_shift,
|
|
|
|
vf->dmpi->stride[1],
|
|
|
|
mpi->stride[1]);
|
2011-09-03 10:47:56 +00:00
|
|
|
memcpy_pic(vf->dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[2],
|
2010-10-30 19:15:15 +00:00
|
|
|
mpi->planes[2],
|
|
|
|
mpi->w >> mpi->chroma_x_shift,
|
|
|
|
mpi->h >> mpi->chroma_y_shift,
|
|
|
|
vf->dmpi->stride[2],
|
|
|
|
mpi->stride[2]);
|
|
|
|
} else {
|
2011-09-03 10:47:56 +00:00
|
|
|
memcpy_pic(vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0],
|
2010-10-30 19:15:15 +00:00
|
|
|
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
|
|
|
|
}
|
2011-09-03 10:47:56 +00:00
|
|
|
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);
|
2010-10-30 19:15:15 +00:00
|
|
|
return 0;
|
2006-07-07 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
|
2006-07-07 18:26:51 +00:00
|
|
|
{
|
2012-08-25 18:22:39 +00:00
|
|
|
struct vf_priv_s *priv = vf->priv;
|
|
|
|
struct osd_state *osd = priv->osd;
|
2012-10-19 17:11:08 +00:00
|
|
|
|
|
|
|
prepare_image(vf, mpi);
|
2012-10-27 16:06:09 +00:00
|
|
|
mp_image_set_colorspace_details(mpi, &priv->csp);
|
2012-10-19 17:11:08 +00:00
|
|
|
|
2012-10-27 16:06:09 +00:00
|
|
|
if (pts != MP_NOPTS_VALUE)
|
|
|
|
osd_draw_on_image(osd, priv->dim, pts, OSD_DRAW_SUB_FILTER, vf->dmpi);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2010-10-30 19:15:15 +00:00
|
|
|
return vf_next_put_image(vf, vf->dmpi, pts);
|
2006-07-07 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
2006-07-07 18:26:51 +00:00
|
|
|
{
|
2010-10-30 19:15:15 +00:00
|
|
|
switch (fmt) {
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
return vf_next_query_format(vf, vf->priv->outfmt);
|
|
|
|
}
|
|
|
|
return 0;
|
2006-07-07 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int control(vf_instance_t *vf, int request, void *data)
|
|
|
|
{
|
2010-10-30 19:15:15 +00:00
|
|
|
switch (request) {
|
2011-01-12 13:15:02 +00:00
|
|
|
case VFCTRL_SET_OSD_OBJ:
|
|
|
|
vf->priv->osd = data;
|
|
|
|
break;
|
2012-10-04 15:16:32 +00:00
|
|
|
case VFCTRL_INIT_OSD:
|
2012-08-25 14:47:50 +00:00
|
|
|
return CONTROL_TRUE;
|
2012-10-19 17:11:08 +00:00
|
|
|
case VFCTRL_SET_YUV_COLORSPACE: {
|
|
|
|
struct mp_csp_details colorspace = *(struct mp_csp_details *)data;
|
|
|
|
vf->priv->csp = colorspace;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-30 19:15:15 +00:00
|
|
|
}
|
|
|
|
return vf_next_control(vf, request, data);
|
2006-07-07 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void uninit(struct vf_instance *vf)
|
2006-07-07 18:26:51 +00:00
|
|
|
{
|
2010-10-30 19:15:15 +00:00
|
|
|
free(vf->priv);
|
2006-07-07 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 19:15:15 +00:00
|
|
|
static const unsigned int fmt_list[] = {
|
|
|
|
IMGFMT_YV12,
|
|
|
|
IMGFMT_I420,
|
|
|
|
IMGFMT_IYUV,
|
|
|
|
0
|
2006-07-07 18:26:51 +00:00
|
|
|
};
|
|
|
|
|
2010-02-21 13:40:49 +00:00
|
|
|
static int vf_open(vf_instance_t *vf, char *args)
|
2006-07-07 18:26:51 +00:00
|
|
|
{
|
2010-10-30 19:15:15 +00:00
|
|
|
vf->priv->outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12);
|
|
|
|
if (!vf->priv->outfmt) {
|
|
|
|
uninit(vf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf->config = config;
|
|
|
|
vf->query_format = query_format;
|
|
|
|
vf->uninit = uninit;
|
|
|
|
vf->control = control;
|
|
|
|
vf->get_image = get_image;
|
|
|
|
vf->put_image = put_image;
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
vf->default_caps = VFCAP_OSD;
|
2010-10-30 19:15:15 +00:00
|
|
|
return 1;
|
2006-07-07 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 19:15:15 +00:00
|
|
|
#define ST_OFF(f) M_ST_OFF(struct vf_priv_s, f)
|
2007-11-09 06:58:32 +00:00
|
|
|
static const m_option_t vf_opts_fields[] = {
|
2010-10-30 19:15:15 +00:00
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
2006-07-07 18:26:51 +00:00
|
|
|
};
|
|
|
|
|
2007-11-09 06:58:32 +00:00
|
|
|
static const m_struct_t vf_opts = {
|
2012-10-21 16:31:34 +00:00
|
|
|
"sub",
|
2010-10-30 19:15:15 +00:00
|
|
|
sizeof(struct vf_priv_s),
|
|
|
|
&vf_priv_dflt,
|
|
|
|
vf_opts_fields
|
2006-07-07 18:26:51 +00:00
|
|
|
};
|
|
|
|
|
2012-10-21 16:31:34 +00:00
|
|
|
const vf_info_t vf_info_sub = {
|
|
|
|
"Render subtitles",
|
|
|
|
"sub",
|
2010-10-30 19:15:15 +00:00
|
|
|
"Evgeniy Stepanov",
|
|
|
|
"",
|
|
|
|
vf_open,
|
|
|
|
&vf_opts
|
2006-07-07 18:26:51 +00:00
|
|
|
};
|