2009-02-08 03:27:30 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-03-24 04:36:17 +00:00
|
|
|
|
2002-04-06 19:09:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-14 21:28:18 +00:00
|
|
|
#include <string.h>
|
2012-09-28 19:33:26 +00:00
|
|
|
#include <assert.h>
|
2002-04-06 19:09:06 +00:00
|
|
|
|
2012-07-30 19:13:03 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/mp_common.h"
|
2002-11-06 23:54:29 +00:00
|
|
|
|
2006-11-25 13:03:51 +00:00
|
|
|
#include "stream/stream.h"
|
2006-11-25 11:20:02 +00:00
|
|
|
|
2007-09-10 11:10:50 +00:00
|
|
|
#include "osdep/timer.h"
|
2007-07-29 17:57:39 +00:00
|
|
|
|
2008-06-23 22:53:58 +00:00
|
|
|
#include "talloc.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/options.h"
|
|
|
|
#include "core/mplayer.h"
|
|
|
|
#include "core/mp_msg.h"
|
2001-03-27 00:32:24 +00:00
|
|
|
#include "sub.h"
|
2012-10-04 15:16:40 +00:00
|
|
|
#include "dec_sub.h"
|
2012-09-28 19:38:52 +00:00
|
|
|
#include "img_convert.h"
|
2012-10-07 01:26:46 +00:00
|
|
|
#include "draw_bmp.h"
|
2004-10-28 01:15:53 +00:00
|
|
|
#include "spudec.h"
|
2012-10-22 14:15:52 +00:00
|
|
|
#include "subreader.h"
|
sub: do not copy the target image if there is no OSD/subs
It's not easy to tell whether the OSD/subs are empty, or if something is
drawn. In general you have to use osd_draw() with a custom callback. If
nothing is visible, the callback is never invoked. (The actual reason
why this is so "hard" is the implementation of osd_libass.c, which
doesn't allow separating rendering and drawing of OSD elements, because
all OSD elements share the same ASS_Renderer.)
To simplify avoiding copies, make osd_draw_on_image() instead of the
caller use mp_image_make_writeable(). Introduce osd_draw_on_image_p(),
which works like osd_draw_on_image(), but gets the new image allocation
from an image pool. This is supposed to be an optimization, because it
reduces the frequency of large allocations/deallocations for image data.
The result of this is that the frequency of copies needed in conjunction
with vf_sub, screenshots, and vo_lavc (encoding) should be reduced.
vf_sub now always does true pass-through if no subs are shown.
Drop the pts check from vf_sub. This didn't make much sense.
2012-12-22 16:17:43 +00:00
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "video/mp_image_pool.h"
|
2001-03-27 00:32:24 +00:00
|
|
|
|
2003-09-21 13:20:06 +00:00
|
|
|
|
2008-05-01 06:12:38 +00:00
|
|
|
char * const sub_osd_names[]={
|
2009-07-06 22:15:02 +00:00
|
|
|
_("Seekbar"),
|
|
|
|
_("Play"),
|
|
|
|
_("Pause"),
|
|
|
|
_("Stop"),
|
|
|
|
_("Rewind"),
|
|
|
|
_("Forward"),
|
|
|
|
_("Clock"),
|
|
|
|
_("Contrast"),
|
|
|
|
_("Saturation"),
|
|
|
|
_("Volume"),
|
|
|
|
_("Brightness"),
|
|
|
|
_("Hue"),
|
|
|
|
_("Balance")
|
2001-10-27 14:30:43 +00:00
|
|
|
};
|
2008-05-01 06:12:38 +00:00
|
|
|
char * const sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" };
|
2001-10-27 14:30:43 +00:00
|
|
|
|
2002-02-20 22:43:34 +00:00
|
|
|
int sub_pos=100;
|
2002-10-06 17:40:51 +00:00
|
|
|
int sub_visibility=1;
|
2001-03-24 04:36:17 +00:00
|
|
|
|
osd: use libass for OSD rendering
The OSD will now be rendered with libass. The old rendering code, which
used freetype/fontconfig and did text layout manually, is disabled. To
re-enable the old code, use the --disable-libass-osd configure switch.
Some switches do nothing with the new code enabled, such as -subalign,
-sub-bg-alpha, -sub-bg-color, and many more. (The reason is mostly that
the code for rendering unstyled subtitles with libass doesn't make any
attempts to support them. Some of them could be supported in theory.)
Teletext rendering is not implemented in the new OSD rendering code. I
don't have any teletext sources for testing, and since teletext is
being phased out world-wide, the need for this is questionable.
Note that rendering is extremely inefficient, mostly because the libass
output is blended with the extremely strange mplayer OSD format. This
could be improved at a later point.
Remove most OSD rendering from vo_aa.c, because that was extremely
hacky, can't be made work with osd_libass, and didn't work anyway in
my tests.
Internally, some cleanup is done. Subtitle and OSD related variable
declarations were literally all over the place. Move them to sub.h and
sub.c, which were hoarding most of these declarations already. Make the
player core in mplayer.c free of concerns like bitmap font loading.
The old OSD rendering code has been moved to osd_ft.c. The font_load.c
and font_load_ft.c are only needed and compiled if the old OSD
rendering code is configured.
2012-03-22 05:26:37 +00:00
|
|
|
subtitle* vo_sub=NULL;
|
|
|
|
|
|
|
|
float sub_delay = 0;
|
|
|
|
float sub_fps = 0;
|
2002-04-17 20:46:12 +00:00
|
|
|
|
2001-11-20 18:36:50 +00:00
|
|
|
void *vo_spudec=NULL;
|
2002-01-10 17:21:00 +00:00
|
|
|
void *vo_vobsub=NULL;
|
2001-11-20 18:36:50 +00:00
|
|
|
|
2012-11-17 19:56:45 +00:00
|
|
|
static const const struct osd_style_opts osd_style_opts_def = {
|
|
|
|
.font = "Sans",
|
|
|
|
.font_size = 45,
|
|
|
|
.color = {255, 255, 255, 255},
|
|
|
|
.border_color = {0, 0, 0, 255},
|
|
|
|
.shadow_color = {240, 240, 240, 128},
|
|
|
|
.border_size = 2.5,
|
|
|
|
.shadow_offset = 0,
|
|
|
|
.margin_x = 25,
|
|
|
|
.margin_y = 10,
|
|
|
|
};
|
2002-01-10 17:21:00 +00:00
|
|
|
|
2012-11-17 19:56:45 +00:00
|
|
|
#undef OPT_BASE_STRUCT
|
|
|
|
#define OPT_BASE_STRUCT struct osd_style_opts
|
|
|
|
const struct m_sub_options osd_style_conf = {
|
|
|
|
.opts = (m_option_t[]) {
|
|
|
|
OPT_STRING("font", font, 0),
|
|
|
|
OPT_FLOATRANGE("font-size", font_size, 0, 1, 9000),
|
|
|
|
OPT_COLOR("color", color, 0),
|
|
|
|
OPT_COLOR("border-color", border_color, 0),
|
|
|
|
OPT_COLOR("shadow-color", shadow_color, 0),
|
|
|
|
OPT_COLOR("back-color", back_color, 0),
|
|
|
|
OPT_FLOATRANGE("border-size", border_size, 0, 0, 10),
|
|
|
|
OPT_FLOATRANGE("shadow-offset", shadow_offset, 0, 0, 10),
|
|
|
|
OPT_FLOATRANGE("spacing", spacing, 0, -10, 10),
|
|
|
|
OPT_INTRANGE("margin-x", margin_x, 0, 0, 300),
|
|
|
|
OPT_INTRANGE("margin-y", margin_y, 0, 0, 600),
|
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.size = sizeof(struct osd_style_opts),
|
|
|
|
.defaults = &osd_style_opts_def,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct osd_state *global_osd;
|
2002-01-10 17:21:00 +00:00
|
|
|
|
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
|
|
|
static bool osd_res_equals(struct mp_osd_res a, struct mp_osd_res b)
|
2008-06-23 22:53:58 +00:00
|
|
|
{
|
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
|
|
|
return a.w == b.w && a.h == b.h && a.ml == b.ml && a.mt == b.mt
|
|
|
|
&& a.mr == b.mr && a.mb == b.mb
|
|
|
|
&& a.display_par == b.display_par
|
|
|
|
&& a.video_par == b.video_par;
|
2009-01-10 13:47:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 17:21:46 +00:00
|
|
|
struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib)
|
2008-06-23 22:53:58 +00:00
|
|
|
{
|
2008-06-24 05:29:36 +00:00
|
|
|
struct osd_state *osd = talloc_zero(NULL, struct osd_state);
|
2012-09-28 19:38:52 +00:00
|
|
|
*osd = (struct osd_state) {
|
osd: use libass for OSD rendering
The OSD will now be rendered with libass. The old rendering code, which
used freetype/fontconfig and did text layout manually, is disabled. To
re-enable the old code, use the --disable-libass-osd configure switch.
Some switches do nothing with the new code enabled, such as -subalign,
-sub-bg-alpha, -sub-bg-color, and many more. (The reason is mostly that
the code for rendering unstyled subtitles with libass doesn't make any
attempts to support them. Some of them could be supported in theory.)
Teletext rendering is not implemented in the new OSD rendering code. I
don't have any teletext sources for testing, and since teletext is
being phased out world-wide, the need for this is questionable.
Note that rendering is extremely inefficient, mostly because the libass
output is blended with the extremely strange mplayer OSD format. This
could be improved at a later point.
Remove most OSD rendering from vo_aa.c, because that was extremely
hacky, can't be made work with osd_libass, and didn't work anyway in
my tests.
Internally, some cleanup is done. Subtitle and OSD related variable
declarations were literally all over the place. Move them to sub.h and
sub.c, which were hoarding most of these declarations already. Make the
player core in mplayer.c free of concerns like bitmap font loading.
The old OSD rendering code has been moved to osd_ft.c. The font_load.c
and font_load_ft.c are only needed and compiled if the old OSD
rendering code is configured.
2012-03-22 05:26:37 +00:00
|
|
|
.opts = opts,
|
2012-08-07 17:21:46 +00:00
|
|
|
.ass_library = asslib,
|
2012-09-29 09:03:53 +00:00
|
|
|
.osd_text = talloc_strdup(osd, ""),
|
|
|
|
.progbar_type = -1,
|
2008-06-23 22:53:58 +00:00
|
|
|
};
|
2012-10-04 15:16:32 +00:00
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++) {
|
|
|
|
struct osd_object *obj = talloc_struct(osd, struct osd_object, {
|
|
|
|
.type = n,
|
|
|
|
});
|
|
|
|
for (int i = 0; i < OSD_CONV_CACHE_MAX; i++)
|
|
|
|
obj->cache[i] = talloc_steal(obj, osd_conv_cache_new());
|
|
|
|
osd->objs[n] = obj;
|
|
|
|
}
|
2012-10-04 15:16:32 +00:00
|
|
|
|
2012-10-19 17:11:08 +00:00
|
|
|
osd->objs[OSDTYPE_SPU]->is_sub = true; // spudec.c
|
2012-10-04 15:16:32 +00:00
|
|
|
osd->objs[OSDTYPE_SUB]->is_sub = true; // dec_sub.c
|
|
|
|
osd->objs[OSDTYPE_SUBTITLE]->is_sub = true; // osd_libass.c
|
|
|
|
|
osd: use libass for OSD rendering
The OSD will now be rendered with libass. The old rendering code, which
used freetype/fontconfig and did text layout manually, is disabled. To
re-enable the old code, use the --disable-libass-osd configure switch.
Some switches do nothing with the new code enabled, such as -subalign,
-sub-bg-alpha, -sub-bg-color, and many more. (The reason is mostly that
the code for rendering unstyled subtitles with libass doesn't make any
attempts to support them. Some of them could be supported in theory.)
Teletext rendering is not implemented in the new OSD rendering code. I
don't have any teletext sources for testing, and since teletext is
being phased out world-wide, the need for this is questionable.
Note that rendering is extremely inefficient, mostly because the libass
output is blended with the extremely strange mplayer OSD format. This
could be improved at a later point.
Remove most OSD rendering from vo_aa.c, because that was extremely
hacky, can't be made work with osd_libass, and didn't work anyway in
my tests.
Internally, some cleanup is done. Subtitle and OSD related variable
declarations were literally all over the place. Move them to sub.h and
sub.c, which were hoarding most of these declarations already. Make the
player core in mplayer.c free of concerns like bitmap font loading.
The old OSD rendering code has been moved to osd_ft.c. The font_load.c
and font_load_ft.c are only needed and compiled if the old OSD
rendering code is configured.
2012-03-22 05:26:37 +00:00
|
|
|
osd_init_backend(osd);
|
2012-09-28 19:38:52 +00:00
|
|
|
global_osd = osd;
|
2008-06-23 22:53:58 +00:00
|
|
|
return osd;
|
2002-04-15 19:17:12 +00:00
|
|
|
}
|
2001-06-02 16:02:38 +00:00
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
void osd_free(struct osd_state *osd)
|
|
|
|
{
|
|
|
|
if (!osd)
|
|
|
|
return;
|
|
|
|
osd_destroy_backend(osd);
|
|
|
|
talloc_free(osd);
|
|
|
|
global_osd = NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-01 16:23:28 +00:00
|
|
|
void osd_set_text(struct osd_state *osd, const char *text)
|
|
|
|
{
|
2011-08-08 08:07:17 +00:00
|
|
|
if (!text)
|
|
|
|
text = "";
|
2012-08-01 16:23:28 +00:00
|
|
|
if (strcmp(osd->osd_text, text) == 0)
|
|
|
|
return;
|
|
|
|
talloc_free(osd->osd_text);
|
2011-08-08 08:07:17 +00:00
|
|
|
osd->osd_text = talloc_strdup(osd, text);
|
2012-08-01 16:23:28 +00:00
|
|
|
vo_osd_changed(OSDTYPE_OSD);
|
2011-08-08 08:07:17 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
static bool spu_visible(struct osd_state *osd, struct osd_object *obj)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = osd->opts;
|
|
|
|
return opts->sub_visibility && vo_spudec && spudec_visible(vo_spudec);
|
|
|
|
}
|
|
|
|
|
2012-10-19 17:11:08 +00:00
|
|
|
static void render_object(struct osd_state *osd, struct osd_object *obj,
|
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 res, double video_pts,
|
|
|
|
const bool formats[SUBBITMAP_COUNT],
|
|
|
|
struct sub_bitmaps *out_imgs)
|
2012-09-28 19:38:52 +00:00
|
|
|
{
|
2012-11-24 23:06:16 +00:00
|
|
|
struct MPOpts *opts = osd->opts;
|
|
|
|
|
2012-10-19 17:11:08 +00:00
|
|
|
*out_imgs = (struct sub_bitmaps) {0};
|
2012-09-28 19:38:52 +00:00
|
|
|
|
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
|
|
|
if (!osd_res_equals(res, obj->vo_res))
|
|
|
|
obj->force_redraw = true;
|
|
|
|
obj->vo_res = res;
|
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
if (obj->type == OSDTYPE_SPU) {
|
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
|
|
|
if (spu_visible(osd, obj))
|
|
|
|
spudec_get_indexed(vo_spudec, &obj->vo_res, out_imgs);
|
2012-10-04 15:16:32 +00:00
|
|
|
} else if (obj->type == OSDTYPE_SUB) {
|
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
|
|
|
double sub_pts = video_pts;
|
|
|
|
if (sub_pts != MP_NOPTS_VALUE)
|
|
|
|
sub_pts += sub_delay - osd->sub_offset;
|
|
|
|
sub_get_bitmaps(osd, obj->vo_res, sub_pts, out_imgs);
|
2012-09-28 19:38:52 +00:00
|
|
|
} else {
|
|
|
|
osd_object_get_bitmaps(osd, obj, out_imgs);
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:26:45 +00:00
|
|
|
if (obj->force_redraw) {
|
|
|
|
out_imgs->bitmap_id++;
|
|
|
|
out_imgs->bitmap_pos_id++;
|
|
|
|
}
|
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
obj->force_redraw = false;
|
|
|
|
obj->vo_bitmap_id += out_imgs->bitmap_id;
|
|
|
|
obj->vo_bitmap_pos_id += out_imgs->bitmap_pos_id;
|
|
|
|
|
|
|
|
if (out_imgs->num_parts == 0)
|
2012-10-19 17:11:08 +00:00
|
|
|
return;
|
2012-09-28 19:38:52 +00:00
|
|
|
|
2012-10-16 05:26:45 +00:00
|
|
|
if (obj->cached.bitmap_id == obj->vo_bitmap_id
|
2012-09-28 19:38:52 +00:00
|
|
|
&& obj->cached.bitmap_pos_id == obj->vo_bitmap_pos_id
|
|
|
|
&& formats[obj->cached.format])
|
|
|
|
{
|
|
|
|
*out_imgs = obj->cached;
|
2012-10-19 17:11:08 +00:00
|
|
|
return;
|
2012-09-28 19:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out_imgs->render_index = obj->type;
|
|
|
|
out_imgs->bitmap_id = obj->vo_bitmap_id;
|
|
|
|
out_imgs->bitmap_pos_id = obj->vo_bitmap_pos_id;
|
|
|
|
|
|
|
|
if (formats[out_imgs->format])
|
2012-10-19 17:11:08 +00:00
|
|
|
return;
|
2012-09-28 19:38:52 +00:00
|
|
|
|
|
|
|
bool cached = false; // do we have a copy of all the image data?
|
|
|
|
|
2012-11-25 22:32:35 +00:00
|
|
|
if (out_imgs->format == SUBBITMAP_INDEXED && opts->sub_gray)
|
|
|
|
cached |= osd_conv_idx_to_gray(obj->cache[0], out_imgs);
|
|
|
|
|
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
|
|
|
if (formats[SUBBITMAP_RGBA] && out_imgs->format == SUBBITMAP_INDEXED)
|
2012-11-25 22:32:35 +00:00
|
|
|
cached |= osd_conv_idx_to_rgba(obj->cache[1], out_imgs);
|
2012-09-28 19:38:52 +00:00
|
|
|
|
2012-11-24 23:06:16 +00:00
|
|
|
if (out_imgs->format == SUBBITMAP_RGBA && opts->sub_gauss != 0.0f)
|
2012-11-25 22:32:35 +00:00
|
|
|
cached |= osd_conv_blur_rgba(obj->cache[2], out_imgs, opts->sub_gauss);
|
2012-11-24 23:06:16 +00:00
|
|
|
|
2012-12-11 15:24:24 +00:00
|
|
|
// Do this conversion last to not trigger gauss blurring for ASS
|
|
|
|
if (formats[SUBBITMAP_RGBA] && out_imgs->format == SUBBITMAP_LIBASS)
|
|
|
|
cached |= osd_conv_ass_to_rgba(obj->cache[3], out_imgs);
|
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
if (cached)
|
|
|
|
obj->cached = *out_imgs;
|
2012-10-04 15:16:32 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 17:11:08 +00:00
|
|
|
// draw_flags is a bit field of OSD_DRAW_* constants
|
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
|
|
|
void osd_draw(struct osd_state *osd, struct mp_osd_res res,
|
|
|
|
double video_pts, int draw_flags,
|
|
|
|
const bool formats[SUBBITMAP_COUNT],
|
2012-10-19 17:11:08 +00:00
|
|
|
void (*cb)(void *ctx, struct sub_bitmaps *imgs), void *cb_ctx)
|
2012-10-04 15:16:32 +00:00
|
|
|
{
|
2012-10-19 17:11:08 +00:00
|
|
|
if (draw_flags & OSD_DRAW_SUB_FILTER)
|
|
|
|
draw_flags |= OSD_DRAW_SUB_ONLY;
|
|
|
|
|
2012-10-04 15:16:32 +00:00
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++) {
|
|
|
|
struct osd_object *obj = osd->objs[n];
|
2012-10-19 17:11:08 +00:00
|
|
|
|
|
|
|
// Object is drawn into the video frame itself; don't draw twice
|
|
|
|
if (osd->render_subs_in_filter && obj->is_sub &&
|
|
|
|
!(draw_flags & OSD_DRAW_SUB_FILTER))
|
|
|
|
continue;
|
|
|
|
if ((draw_flags & OSD_DRAW_SUB_ONLY) && !obj->is_sub)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
struct sub_bitmaps imgs;
|
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
|
|
|
render_object(osd, obj, res, video_pts, formats, &imgs);
|
2012-10-19 17:11:08 +00:00
|
|
|
if (imgs.num_parts > 0) {
|
|
|
|
if (formats[imgs.format]) {
|
|
|
|
cb(cb_ctx, &imgs);
|
|
|
|
} else {
|
|
|
|
mp_msg(MSGT_OSD, MSGL_ERR,
|
|
|
|
"Can't render OSD part %d (format %d).\n",
|
|
|
|
obj->type, imgs.format);
|
|
|
|
}
|
2012-10-04 15:16:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-19 17:11:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct draw_on_image_closure {
|
2012-10-19 15:49:49 +00:00
|
|
|
struct osd_state *osd;
|
2012-10-19 17:11:08 +00:00
|
|
|
struct mp_image *dest;
|
sub: do not copy the target image if there is no OSD/subs
It's not easy to tell whether the OSD/subs are empty, or if something is
drawn. In general you have to use osd_draw() with a custom callback. If
nothing is visible, the callback is never invoked. (The actual reason
why this is so "hard" is the implementation of osd_libass.c, which
doesn't allow separating rendering and drawing of OSD elements, because
all OSD elements share the same ASS_Renderer.)
To simplify avoiding copies, make osd_draw_on_image() instead of the
caller use mp_image_make_writeable(). Introduce osd_draw_on_image_p(),
which works like osd_draw_on_image(), but gets the new image allocation
from an image pool. This is supposed to be an optimization, because it
reduces the frequency of large allocations/deallocations for image data.
The result of this is that the frequency of copies needed in conjunction
with vf_sub, screenshots, and vo_lavc (encoding) should be reduced.
vf_sub now always does true pass-through if no subs are shown.
Drop the pts check from vf_sub. This didn't make much sense.
2012-12-22 16:17:43 +00:00
|
|
|
struct mp_image_pool *pool;
|
2012-10-19 17:11:08 +00:00
|
|
|
bool changed;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void draw_on_image(void *ctx, struct sub_bitmaps *imgs)
|
|
|
|
{
|
|
|
|
struct draw_on_image_closure *closure = ctx;
|
2012-10-19 15:49:49 +00:00
|
|
|
struct osd_state *osd = closure->osd;
|
sub: do not copy the target image if there is no OSD/subs
It's not easy to tell whether the OSD/subs are empty, or if something is
drawn. In general you have to use osd_draw() with a custom callback. If
nothing is visible, the callback is never invoked. (The actual reason
why this is so "hard" is the implementation of osd_libass.c, which
doesn't allow separating rendering and drawing of OSD elements, because
all OSD elements share the same ASS_Renderer.)
To simplify avoiding copies, make osd_draw_on_image() instead of the
caller use mp_image_make_writeable(). Introduce osd_draw_on_image_p(),
which works like osd_draw_on_image(), but gets the new image allocation
from an image pool. This is supposed to be an optimization, because it
reduces the frequency of large allocations/deallocations for image data.
The result of this is that the frequency of copies needed in conjunction
with vf_sub, screenshots, and vo_lavc (encoding) should be reduced.
vf_sub now always does true pass-through if no subs are shown.
Drop the pts check from vf_sub. This didn't make much sense.
2012-12-22 16:17:43 +00:00
|
|
|
if (closure->pool) {
|
|
|
|
mp_image_pool_make_writeable(closure->pool, closure->dest);
|
|
|
|
} else {
|
|
|
|
mp_image_make_writeable(closure->dest);
|
|
|
|
}
|
2012-10-27 16:06:09 +00:00
|
|
|
mp_draw_sub_bitmaps(&osd->draw_cache, closure->dest, imgs);
|
2012-10-19 15:49:49 +00:00
|
|
|
talloc_steal(osd, osd->draw_cache);
|
2012-10-19 17:11:08 +00:00
|
|
|
closure->changed = true;
|
2012-09-28 19:38:52 +00:00
|
|
|
}
|
|
|
|
|
sub: do not copy the target image if there is no OSD/subs
It's not easy to tell whether the OSD/subs are empty, or if something is
drawn. In general you have to use osd_draw() with a custom callback. If
nothing is visible, the callback is never invoked. (The actual reason
why this is so "hard" is the implementation of osd_libass.c, which
doesn't allow separating rendering and drawing of OSD elements, because
all OSD elements share the same ASS_Renderer.)
To simplify avoiding copies, make osd_draw_on_image() instead of the
caller use mp_image_make_writeable(). Introduce osd_draw_on_image_p(),
which works like osd_draw_on_image(), but gets the new image allocation
from an image pool. This is supposed to be an optimization, because it
reduces the frequency of large allocations/deallocations for image data.
The result of this is that the frequency of copies needed in conjunction
with vf_sub, screenshots, and vo_lavc (encoding) should be reduced.
vf_sub now always does true pass-through if no subs are shown.
Drop the pts check from vf_sub. This didn't make much sense.
2012-12-22 16:17:43 +00:00
|
|
|
// Calls mp_image_make_writeable() on the dest image if something is drawn.
|
2012-10-07 01:26:46 +00:00
|
|
|
// Returns whether anything was drawn.
|
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
|
|
|
bool osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res,
|
2012-10-27 16:06:09 +00:00
|
|
|
double video_pts, int draw_flags, struct mp_image *dest)
|
2012-10-07 01:26:46 +00:00
|
|
|
{
|
2012-10-27 16:06:09 +00:00
|
|
|
struct draw_on_image_closure closure = {osd, dest};
|
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
|
|
|
osd_draw(osd, res, video_pts, draw_flags, mp_draw_sub_formats,
|
2012-10-19 15:49:49 +00:00
|
|
|
&draw_on_image, &closure);
|
2012-10-19 17:11:08 +00:00
|
|
|
return closure.changed;
|
2012-10-07 01:26:46 +00:00
|
|
|
}
|
|
|
|
|
sub: do not copy the target image if there is no OSD/subs
It's not easy to tell whether the OSD/subs are empty, or if something is
drawn. In general you have to use osd_draw() with a custom callback. If
nothing is visible, the callback is never invoked. (The actual reason
why this is so "hard" is the implementation of osd_libass.c, which
doesn't allow separating rendering and drawing of OSD elements, because
all OSD elements share the same ASS_Renderer.)
To simplify avoiding copies, make osd_draw_on_image() instead of the
caller use mp_image_make_writeable(). Introduce osd_draw_on_image_p(),
which works like osd_draw_on_image(), but gets the new image allocation
from an image pool. This is supposed to be an optimization, because it
reduces the frequency of large allocations/deallocations for image data.
The result of this is that the frequency of copies needed in conjunction
with vf_sub, screenshots, and vo_lavc (encoding) should be reduced.
vf_sub now always does true pass-through if no subs are shown.
Drop the pts check from vf_sub. This didn't make much sense.
2012-12-22 16:17:43 +00:00
|
|
|
// Like osd_draw_on_image(), but if dest needs to be copied to make it
|
|
|
|
// writeable, allocate images from the given pool. (This is a minor
|
|
|
|
// optimization to reduce "real" image sized memory allocations.)
|
|
|
|
void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
|
|
|
|
double video_pts, int draw_flags,
|
|
|
|
struct mp_image_pool *pool, struct mp_image *dest)
|
|
|
|
{
|
2012-12-22 16:50:15 +00:00
|
|
|
struct draw_on_image_closure closure = {osd, dest, pool};
|
2012-11-21 16:59:24 +00:00
|
|
|
osd_draw(osd, res, video_pts, draw_flags, mp_draw_sub_formats,
|
|
|
|
&draw_on_image, &closure);
|
|
|
|
}
|
|
|
|
|
2012-08-01 16:23:28 +00:00
|
|
|
void vo_osd_changed(int new_value)
|
2002-02-22 15:25:11 +00:00
|
|
|
{
|
2012-09-28 19:38:52 +00:00
|
|
|
struct osd_state *osd = global_osd;
|
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++) {
|
|
|
|
if (osd->objs[n]->type == new_value)
|
|
|
|
osd->objs[n]->force_redraw = true;
|
2012-08-06 23:58:43 +00:00
|
|
|
}
|
2012-10-21 12:58:46 +00:00
|
|
|
osd->want_redraw = true;
|
osd: use libass for OSD rendering
The OSD will now be rendered with libass. The old rendering code, which
used freetype/fontconfig and did text layout manually, is disabled. To
re-enable the old code, use the --disable-libass-osd configure switch.
Some switches do nothing with the new code enabled, such as -subalign,
-sub-bg-alpha, -sub-bg-color, and many more. (The reason is mostly that
the code for rendering unstyled subtitles with libass doesn't make any
attempts to support them. Some of them could be supported in theory.)
Teletext rendering is not implemented in the new OSD rendering code. I
don't have any teletext sources for testing, and since teletext is
being phased out world-wide, the need for this is questionable.
Note that rendering is extremely inefficient, mostly because the libass
output is blended with the extremely strange mplayer OSD format. This
could be improved at a later point.
Remove most OSD rendering from vo_aa.c, because that was extremely
hacky, can't be made work with osd_libass, and didn't work anyway in
my tests.
Internally, some cleanup is done. Subtitle and OSD related variable
declarations were literally all over the place. Move them to sub.h and
sub.c, which were hoarding most of these declarations already. Make the
player core in mplayer.c free of concerns like bitmap font loading.
The old OSD rendering code has been moved to osd_ft.c. The font_load.c
and font_load_ft.c are only needed and compiled if the old OSD
rendering code is configured.
2012-03-22 05:26:37 +00:00
|
|
|
}
|
2002-04-16 00:35:01 +00:00
|
|
|
|
2012-11-17 19:56:45 +00:00
|
|
|
void osd_subs_changed(struct osd_state *osd)
|
|
|
|
{
|
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++) {
|
|
|
|
if (osd->objs[n]->is_sub)
|
|
|
|
vo_osd_changed(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 17:37:43 +00:00
|
|
|
bool sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb)
|
2012-09-28 19:33:26 +00:00
|
|
|
{
|
2012-10-25 17:37:43 +00:00
|
|
|
struct mp_rect bb = {INT_MAX, INT_MAX, INT_MIN, INT_MIN};
|
2012-09-28 19:38:52 +00:00
|
|
|
for (int n = 0; n < imgs->num_parts; n++) {
|
|
|
|
struct sub_bitmap *p = &imgs->parts[n];
|
2012-10-25 17:37:43 +00:00
|
|
|
bb.x0 = FFMIN(bb.x0, p->x);
|
|
|
|
bb.y0 = FFMIN(bb.y0, p->y);
|
|
|
|
bb.x1 = FFMAX(bb.x1, p->x + p->dw);
|
|
|
|
bb.y1 = FFMAX(bb.y1, p->y + p->dh);
|
2012-09-28 19:33:26 +00:00
|
|
|
}
|
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
// avoid degenerate bounding box if empty
|
2012-10-25 17:37:43 +00:00
|
|
|
bb.x0 = FFMIN(bb.x0, bb.x1);
|
|
|
|
bb.y0 = FFMIN(bb.y0, bb.y1);
|
2012-09-28 19:33:26 +00:00
|
|
|
|
2012-10-25 17:37:43 +00:00
|
|
|
*out_bb = bb;
|
|
|
|
|
|
|
|
return bb.x0 < bb.x1 && bb.y0 < bb.y1;
|
2012-09-28 19:33:26 +00:00
|
|
|
}
|