2009-02-08 03:27:30 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2009-02-08 03:27:30 +00:00
|
|
|
*
|
sub/osd: relicense to LGPL
All contributors of the code used for these files agreed to the LGPL
relicensing.
There are some unaccounted contributors, but all of their code was
completely removed before. (The only exception is one contributor whose
only line left was "#include <string.h>". I don't know if that's
copyrightable, but it wasn't needed anyway, so just remove it.)
These files started out as libvo/sub.* (renamed to sub/sub.*, then
renamed again to sub/osd.*). They used to contain code for rendering
the OSD (as in, actual pixel manipulation and text layouting). But
later all this code was dropped, and libass was used to render the OSD
instead. Actual subtitle rendering was reimplemented in other files
(the old subtitle rendering path is completely gone).
One potential problem are the option declarations, which makes this
harder, as these options involve more history. But it turns out most of
them were reimplemented since 80270218cb9, rather than taken from old
code. (Although not all - but the rest covered by relicensing
agreements.)
This also affects osd_state.h, which was apparently incorrectly implied
to be LGPL.
2017-04-20 10:39:00 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-02-08 03:27:30 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2009-02-08 03:27:30 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
sub/osd: relicense to LGPL
All contributors of the code used for these files agreed to the LGPL
relicensing.
There are some unaccounted contributors, but all of their code was
completely removed before. (The only exception is one contributor whose
only line left was "#include <string.h>". I don't know if that's
copyrightable, but it wasn't needed anyway, so just remove it.)
These files started out as libvo/sub.* (renamed to sub/sub.*, then
renamed again to sub/osd.*). They used to contain code for rendering
the OSD (as in, actual pixel manipulation and text layouting). But
later all this code was dropped, and libass was used to render the OSD
instead. Actual subtitle rendering was reimplemented in other files
(the old subtitle rendering path is completely gone).
One potential problem are the option declarations, which makes this
harder, as these options involve more history. But it turns out most of
them were reimplemented since 80270218cb9, rather than taken from old
code. (Although not all - but the rest covered by relicensing
agreements.)
This also affects osd_state.h, which was apparently incorrectly implied
to be LGPL.
2017-04-20 10:39:00 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2009-02-08 03:27:30 +00:00
|
|
|
*
|
sub/osd: relicense to LGPL
All contributors of the code used for these files agreed to the LGPL
relicensing.
There are some unaccounted contributors, but all of their code was
completely removed before. (The only exception is one contributor whose
only line left was "#include <string.h>". I don't know if that's
copyrightable, but it wasn't needed anyway, so just remove it.)
These files started out as libvo/sub.* (renamed to sub/sub.*, then
renamed again to sub/osd.*). They used to contain code for rendering
the OSD (as in, actual pixel manipulation and text layouting). But
later all this code was dropped, and libass was used to render the OSD
instead. Actual subtitle rendering was reimplemented in other files
(the old subtitle rendering path is completely gone).
One potential problem are the option declarations, which makes this
harder, as these options involve more history. But it turns out most of
them were reimplemented since 80270218cb9, rather than taken from old
code. (Although not all - but the rest covered by relicensing
agreements.)
This also affects osd_state.h, which was apparently incorrectly implied
to be LGPL.
2017-04-20 10:39:00 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2009-02-08 03:27:30 +00:00
|
|
|
*/
|
2001-03-24 04:36:17 +00:00
|
|
|
|
2002-04-06 19:09:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.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>
|
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/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
|
|
|
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2017-12-29 16:19:25 +00:00
|
|
|
#include "options/m_config.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2013-12-21 18:06:37 +00:00
|
|
|
#include "common/global.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2016-01-15 21:53:53 +00:00
|
|
|
#include "player/client.h"
|
|
|
|
#include "player/command.h"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "osd.h"
|
2014-01-18 00:19:20 +00:00
|
|
|
#include "osd_state.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"
|
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
|
|
|
|
2015-02-16 19:03:56 +00:00
|
|
|
#define OPT_BASE_STRUCT struct osd_style_opts
|
|
|
|
static const m_option_t style_opts[] = {
|
|
|
|
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),
|
2018-01-24 19:35:55 +00:00
|
|
|
OPT_FLOAT("border-size", border_size, 0),
|
|
|
|
OPT_FLOAT("shadow-offset", shadow_offset, 0),
|
2015-02-16 19:03:56 +00:00
|
|
|
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),
|
2015-02-16 19:04:02 +00:00
|
|
|
OPT_CHOICE("align-x", align_x, 0,
|
|
|
|
({"left", -1}, {"center", 0}, {"right", +1})),
|
|
|
|
OPT_CHOICE("align-y", align_y, 0,
|
|
|
|
({"top", -1}, {"center", 0}, {"bottom", +1})),
|
2015-02-16 19:03:56 +00:00
|
|
|
OPT_FLOATRANGE("blur", blur, 0, 0, 20),
|
2015-04-01 20:58:12 +00:00
|
|
|
OPT_FLAG("bold", bold, 0),
|
2016-04-08 08:43:34 +00:00
|
|
|
OPT_FLAG("italic", italic, 0),
|
2017-02-01 12:19:09 +00:00
|
|
|
OPT_CHOICE("justify", justify, 0,
|
|
|
|
({"auto", 0}, {"left", 1}, {"center", 2}, {"right", 3})),
|
2015-02-16 19:03:56 +00:00
|
|
|
{0}
|
2012-11-17 19:56:45 +00:00
|
|
|
};
|
2002-01-10 17:21:00 +00:00
|
|
|
|
2012-11-17 19:56:45 +00:00
|
|
|
const struct m_sub_options osd_style_conf = {
|
2015-02-16 19:03:56 +00:00
|
|
|
.opts = style_opts,
|
|
|
|
.size = sizeof(struct osd_style_opts),
|
|
|
|
.defaults = &(const struct osd_style_opts){
|
|
|
|
.font = "sans-serif",
|
|
|
|
.font_size = 55,
|
|
|
|
.color = {255, 255, 255, 255},
|
|
|
|
.border_color = {0, 0, 0, 255},
|
|
|
|
.shadow_color = {240, 240, 240, 128},
|
|
|
|
.border_size = 3,
|
|
|
|
.shadow_offset = 0,
|
|
|
|
.margin_x = 25,
|
|
|
|
.margin_y = 22,
|
2015-02-16 19:04:02 +00:00
|
|
|
.align_x = -1,
|
|
|
|
.align_y = -1,
|
2012-11-17 19:56:45 +00:00
|
|
|
},
|
2016-09-19 18:16:44 +00:00
|
|
|
.change_flags = UPDATE_OSD,
|
2015-02-16 19:03:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct m_sub_options sub_style_conf = {
|
|
|
|
.opts = style_opts,
|
2012-11-17 19:56:45 +00:00
|
|
|
.size = sizeof(struct osd_style_opts),
|
2015-02-16 19:03:56 +00:00
|
|
|
.defaults = &(const struct osd_style_opts){
|
|
|
|
.font = "sans-serif",
|
|
|
|
.font_size = 55,
|
|
|
|
.color = {255, 255, 255, 255},
|
|
|
|
.border_color = {0, 0, 0, 255},
|
|
|
|
.shadow_color = {240, 240, 240, 128},
|
|
|
|
.border_size = 3,
|
|
|
|
.shadow_offset = 0,
|
|
|
|
.margin_x = 25,
|
|
|
|
.margin_y = 22,
|
2015-02-16 19:04:02 +00:00
|
|
|
.align_x = 0,
|
|
|
|
.align_y = 1,
|
2015-02-16 19:03:56 +00:00
|
|
|
},
|
2016-09-19 18:16:44 +00:00
|
|
|
.change_flags = UPDATE_OSD,
|
2012-11-17 19:56:45 +00:00
|
|
|
};
|
|
|
|
|
2017-08-29 13:15:34 +00:00
|
|
|
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
|
2013-11-24 12:07:49 +00:00
|
|
|
&& a.display_par == b.display_par;
|
2009-01-10 13:47:41 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 18:06:37 +00:00
|
|
|
struct osd_state *osd_create(struct mpv_global *global)
|
2008-06-23 22:53:58 +00:00
|
|
|
{
|
2016-03-08 20:54:17 +00:00
|
|
|
assert(MAX_OSD_PARTS >= OSDTYPE_COUNT);
|
|
|
|
|
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) {
|
2017-12-29 16:19:25 +00:00
|
|
|
.opts_cache = m_config_cache_alloc(osd, global, &mp_osd_render_sub_opts),
|
2013-12-21 18:06:37 +00:00
|
|
|
.global = global,
|
|
|
|
.log = mp_log_new(osd, global->log, "osd"),
|
2016-10-26 18:43:03 +00:00
|
|
|
.force_video_pts = MP_NOPTS_VALUE,
|
2008-06-23 22:53:58 +00:00
|
|
|
};
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_init(&osd->lock, NULL);
|
2017-12-29 16:19:25 +00:00
|
|
|
osd->opts = osd->opts_cache->opts;
|
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++) {
|
2013-12-24 16:46:14 +00:00
|
|
|
struct osd_object *obj = talloc(osd, struct osd_object);
|
|
|
|
*obj = (struct osd_object) {
|
2012-09-28 19:38:52 +00:00
|
|
|
.type = n,
|
2014-01-18 00:19:20 +00:00
|
|
|
.text = talloc_strdup(obj, ""),
|
|
|
|
.progbar_state = {.type = -1},
|
2013-12-24 16:46:14 +00:00
|
|
|
};
|
2012-09-28 19:38:52 +00:00
|
|
|
osd->objs[n] = obj;
|
|
|
|
}
|
2012-10-04 15:16:32 +00:00
|
|
|
|
2013-12-24 16:46:14 +00:00
|
|
|
osd->objs[OSDTYPE_SUB]->is_sub = true;
|
|
|
|
osd->objs[OSDTYPE_SUB2]->is_sub = true;
|
2012-10-04 15:16:32 +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
|
|
|
osd_init_backend(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);
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_destroy(&osd->lock);
|
2012-09-28 19:38:52 +00:00
|
|
|
talloc_free(osd);
|
|
|
|
}
|
|
|
|
|
2016-03-08 20:54:17 +00:00
|
|
|
void osd_set_text(struct osd_state *osd, const char *text)
|
2014-01-18 00:19:20 +00:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
2016-03-08 20:54:17 +00:00
|
|
|
struct osd_object *osd_obj = osd->objs[OSDTYPE_OSD];
|
2011-08-08 08:07:17 +00:00
|
|
|
if (!text)
|
|
|
|
text = "";
|
2014-01-18 00:19:20 +00:00
|
|
|
if (strcmp(osd_obj->text, text) != 0) {
|
|
|
|
talloc_free(osd_obj->text);
|
|
|
|
osd_obj->text = talloc_strdup(osd_obj, text);
|
2016-09-16 15:17:32 +00:00
|
|
|
osd_obj->osd_changed = true;
|
|
|
|
osd->want_redraw_notification = true;
|
2014-01-18 00:19:20 +00:00
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
2016-03-08 20:54:17 +00:00
|
|
|
void osd_set_sub(struct osd_state *osd, int index, struct dec_sub *dec_sub)
|
2014-01-18 00:19:20 +00:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
2016-09-16 12:21:09 +00:00
|
|
|
if (index >= 0 && index < 2) {
|
|
|
|
struct osd_object *obj = osd->objs[OSDTYPE_SUB + index];
|
|
|
|
obj->sub = dec_sub;
|
|
|
|
obj->vo_change_id += 1;
|
|
|
|
}
|
2016-09-16 15:17:32 +00:00
|
|
|
osd->want_redraw_notification = true;
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool osd_get_render_subs_in_filter(struct osd_state *osd)
|
2013-04-28 19:12:11 +00:00
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
bool r = osd->render_subs_in_filter;
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void osd_set_render_subs_in_filter(struct osd_state *osd, bool s)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
osd->render_subs_in_filter = s;
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
2016-10-26 18:43:03 +00:00
|
|
|
void osd_set_force_video_pts(struct osd_state *osd, double video_pts)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
osd->force_video_pts = video_pts;
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
double osd_get_force_video_pts(struct osd_state *osd)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
double pts = osd->force_video_pts;
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
return pts;
|
|
|
|
}
|
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
void osd_set_progbar(struct osd_state *osd, struct osd_progbar_state *s)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
2015-11-28 18:24:31 +00:00
|
|
|
struct osd_object *osd_obj = osd->objs[OSDTYPE_OSD];
|
2014-01-18 00:19:20 +00:00
|
|
|
osd_obj->progbar_state.type = s->type;
|
|
|
|
osd_obj->progbar_state.value = s->value;
|
|
|
|
osd_obj->progbar_state.num_stops = s->num_stops;
|
|
|
|
MP_TARRAY_GROW(osd_obj, osd_obj->progbar_state.stops, s->num_stops);
|
2018-10-14 13:51:36 +00:00
|
|
|
if (s->num_stops) {
|
|
|
|
memcpy(osd_obj->progbar_state.stops, s->stops,
|
|
|
|
sizeof(osd_obj->progbar_state.stops[0]) * s->num_stops);
|
|
|
|
}
|
2016-09-16 15:17:32 +00:00
|
|
|
osd_obj->osd_changed = true;
|
|
|
|
osd->want_redraw_notification = true;
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void osd_set_external2(struct osd_state *osd, struct sub_bitmaps *imgs)
|
2013-04-28 19:12:11 +00:00
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
osd->objs[OSDTYPE_EXTERNAL2]->external2 = imgs;
|
2016-09-16 12:21:09 +00:00
|
|
|
osd->objs[OSDTYPE_EXTERNAL2]->vo_change_id += 1;
|
2016-09-16 15:17:32 +00:00
|
|
|
osd->want_redraw_notification = true;
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
2016-03-21 21:23:41 +00:00
|
|
|
static void check_obj_resize(struct osd_state *osd, struct mp_osd_res res,
|
|
|
|
struct osd_object *obj)
|
|
|
|
{
|
|
|
|
if (!osd_res_equals(res, obj->vo_res)) {
|
|
|
|
obj->vo_res = res;
|
|
|
|
mp_client_broadcast_event(mp_client_api_get_core(osd->global->client_api),
|
|
|
|
MP_EVENT_WIN_RESIZE, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optional. Can be called for faster reaction of OSD-generating scripts like
|
|
|
|
// osc.lua. This can achieve that the resize happens first, so that the OSD is
|
|
|
|
// generated at the correct resolution the first time the resized frame is
|
|
|
|
// rendered. Since the OSD doesn't (and can't) wait for the script, this
|
|
|
|
// increases the time in which the script can react, and also gets rid of the
|
|
|
|
// unavoidable redraw delay (though it will still be racy).
|
|
|
|
// Unnecessary for anything else.
|
|
|
|
void osd_resize(struct osd_state *osd, struct mp_osd_res res)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
int types[] = {OSDTYPE_OSD, OSDTYPE_EXTERNAL, OSDTYPE_EXTERNAL2, -1};
|
|
|
|
for (int n = 0; types[n] >= 0; n++)
|
|
|
|
check_obj_resize(osd, res, osd->objs[types[n]]);
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
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,
|
2012-12-28 16:17:16 +00:00
|
|
|
const bool sub_formats[SUBBITMAP_COUNT],
|
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 sub_bitmaps *out_imgs)
|
2012-09-28 19:38:52 +00:00
|
|
|
{
|
2016-07-03 16:33:28 +00:00
|
|
|
int format = SUBBITMAP_LIBASS;
|
2017-12-29 16:19:25 +00:00
|
|
|
if (!sub_formats[format] || osd->opts->force_rgba_osd)
|
2016-07-03 16:33:28 +00:00
|
|
|
format = SUBBITMAP_RGBA;
|
|
|
|
|
2012-10-19 17:11:08 +00:00
|
|
|
*out_imgs = (struct sub_bitmaps) {0};
|
2012-09-28 19:38:52 +00:00
|
|
|
|
2016-03-21 21:23:41 +00:00
|
|
|
check_obj_resize(osd, res, 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
|
|
|
|
2013-12-24 16:46:14 +00:00
|
|
|
if (obj->type == OSDTYPE_SUB || obj->type == OSDTYPE_SUB2) {
|
2017-12-29 14:39:38 +00:00
|
|
|
if (obj->sub)
|
|
|
|
sub_get_bitmaps(obj->sub, obj->vo_res, format, video_pts, out_imgs);
|
2013-09-30 20:27:37 +00:00
|
|
|
} else if (obj->type == OSDTYPE_EXTERNAL2) {
|
2014-01-18 00:19:20 +00:00
|
|
|
if (obj->external2 && obj->external2->format) {
|
|
|
|
*out_imgs = *obj->external2;
|
2015-03-18 11:33:14 +00:00
|
|
|
obj->external2->change_id = 0;
|
2013-09-30 20:27:37 +00:00
|
|
|
}
|
2012-09-28 19:38:52 +00:00
|
|
|
} else {
|
2016-07-03 16:33:28 +00:00
|
|
|
osd_object_get_bitmaps(osd, obj, format, out_imgs);
|
2012-09-28 19:38:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:33:14 +00:00
|
|
|
obj->vo_change_id += out_imgs->change_id;
|
2012-09-28 19:38:52 +00:00
|
|
|
|
|
|
|
if (out_imgs->num_parts == 0)
|
2012-10-19 17:11:08 +00:00
|
|
|
return;
|
2012-09-28 19:38:52 +00:00
|
|
|
|
|
|
|
out_imgs->render_index = obj->type;
|
2015-03-18 11:33:14 +00:00
|
|
|
out_imgs->change_id = obj->vo_change_id;
|
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
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
|
2016-10-26 18:43:03 +00:00
|
|
|
if (osd->force_video_pts != MP_NOPTS_VALUE)
|
|
|
|
video_pts = osd->force_video_pts;
|
|
|
|
|
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;
|
2015-03-23 01:42:19 +00:00
|
|
|
if ((draw_flags & OSD_DRAW_OSD_ONLY) && obj->is_sub)
|
|
|
|
continue;
|
2012-10-19 17:11:08 +00:00
|
|
|
|
2015-11-17 00:54:02 +00:00
|
|
|
if (obj->sub)
|
|
|
|
sub_lock(obj->sub);
|
sub: uglify sub decoder with locking
The plan is to make the whole OSD thread-safe, and we start with this.
We just put locks on all entry points (fortunately, dec_sub.c and all
sd_*.c decoders are very closed off, and only the entry points in
dec_sub.h let you access it). I think this is pretty ugly, but at least
it's very simple.
There's a special case with sub_get_bitmaps(): this function returns
pointers to decoder data (specifically, libass images). There's no way
to synchronize this internally, so expose sub_lock/sub_unlock functions.
To make things simpler, and especially because the lock is sort-of
exposed to the outside world, make the locks recursive. Although the
only case where this is actually needed (although trivial) is
sub_set_extradata().
One corner case are ASS subtitles: for some reason, we keep a single
ASS_Renderer instance for subtitles around (probably to avoid rescanning
fonts with ordered chapters), and this ASS_Renderer instance is not
synchronized. Also, demux_libass.c loads ASS_Track objects, which are
directly passed to sd_ass.c. These things are not synchronized (and
would be hard to synchronize), and basically we're out of luck. But I
think for now, accesses happen reasonably serialized, so there is no
actual problem yet, even if we start to access OSD from other threads.
2014-01-17 22:13:09 +00:00
|
|
|
|
2012-10-19 17:11:08 +00:00
|
|
|
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 {
|
2013-12-21 18:06:37 +00:00
|
|
|
MP_ERR(osd, "Can't render OSD part %d (format %d).\n",
|
2012-10-19 17:11:08 +00:00
|
|
|
obj->type, imgs.format);
|
|
|
|
}
|
2012-10-04 15:16:32 +00:00
|
|
|
}
|
sub: uglify sub decoder with locking
The plan is to make the whole OSD thread-safe, and we start with this.
We just put locks on all entry points (fortunately, dec_sub.c and all
sd_*.c decoders are very closed off, and only the entry points in
dec_sub.h let you access it). I think this is pretty ugly, but at least
it's very simple.
There's a special case with sub_get_bitmaps(): this function returns
pointers to decoder data (specifically, libass images). There's no way
to synchronize this internally, so expose sub_lock/sub_unlock functions.
To make things simpler, and especially because the lock is sort-of
exposed to the outside world, make the locks recursive. Although the
only case where this is actually needed (although trivial) is
sub_set_extradata().
One corner case are ASS subtitles: for some reason, we keep a single
ASS_Renderer instance for subtitles around (probably to avoid rescanning
fonts with ordered chapters), and this ASS_Renderer instance is not
synchronized. Also, demux_libass.c loads ASS_Track objects, which are
directly passed to sd_ass.c. These things are not synchronized (and
would be hard to synchronize), and basically we're out of luck. But I
think for now, accesses happen reasonably serialized, so there is no
actual problem yet, even if we start to access OSD from other threads.
2014-01-17 22:13:09 +00:00
|
|
|
|
2015-11-17 00:54:02 +00:00
|
|
|
if (obj->sub)
|
|
|
|
sub_unlock(obj->sub);
|
2012-10-04 15:16:32 +00:00
|
|
|
}
|
2014-01-18 00:19:20 +00:00
|
|
|
|
2016-09-16 15:17:32 +00:00
|
|
|
// If this is called with OSD_DRAW_SUB_ONLY or OSD_DRAW_OSD_ONLY set, assume
|
|
|
|
// it will always draw the complete OSD by doing multiple osd_draw() calls.
|
|
|
|
// OSD_DRAW_SUB_FILTER on the other hand is an evil special-case, and we
|
|
|
|
// must not reset the flag when it happens.
|
2016-09-15 12:22:48 +00:00
|
|
|
if (!(draw_flags & OSD_DRAW_SUB_FILTER))
|
2016-09-16 15:17:32 +00:00
|
|
|
osd->want_redraw_notification = false;
|
2016-09-15 12:22:48 +00:00
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
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;
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
if (!mp_image_pool_make_writeable(closure->pool, closure->dest))
|
|
|
|
return; // on OOM, skip
|
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);
|
|
|
|
}
|
|
|
|
|
2014-01-21 22:43:54 +00:00
|
|
|
// Setup the OSD resolution to render into an image with the given parameters.
|
|
|
|
// The interesting part about this is that OSD has to compensate the aspect
|
|
|
|
// ratio if the image does not have a 1:1 pixel aspect ratio.
|
|
|
|
struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p)
|
|
|
|
{
|
|
|
|
return (struct mp_osd_res) {
|
|
|
|
.w = p->w,
|
|
|
|
.h = p->h,
|
2015-12-19 19:04:31 +00:00
|
|
|
.display_par = p->p_h / (double)p->p_w,
|
2014-01-21 22:43:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-16 15:17:32 +00:00
|
|
|
// Typically called to react to OSD style changes.
|
2016-09-15 12:22:48 +00:00
|
|
|
void osd_changed(struct osd_state *osd)
|
2002-02-22 15:25:11 +00:00
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_lock(&osd->lock);
|
2016-09-16 15:17:32 +00:00
|
|
|
osd->objs[OSDTYPE_OSD]->osd_changed = true;
|
|
|
|
osd->want_redraw_notification = true;
|
2017-12-29 16:19:25 +00:00
|
|
|
// Done here for a lack of a better place.
|
|
|
|
m_config_cache_update(osd->opts_cache);
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
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
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
bool osd_query_and_reset_want_redraw(struct osd_state *osd)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
2016-09-15 12:22:48 +00:00
|
|
|
bool r = osd->want_redraw_notification;
|
|
|
|
osd->want_redraw_notification = false;
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2016-03-08 20:54:17 +00:00
|
|
|
struct mp_osd_res osd_get_vo_res(struct osd_state *osd)
|
2014-01-18 00:19:20 +00:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
2016-03-08 20:54:17 +00:00
|
|
|
// Any OSDTYPE is fine; but it mustn't be a subtitle one (can have lower res.)
|
|
|
|
struct mp_osd_res res = osd->objs[OSDTYPE_OSD]->vo_res;
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
return res;
|
2013-12-12 23:19:17 +00:00
|
|
|
}
|
|
|
|
|
2013-12-11 22:15:29 +00:00
|
|
|
// Position the subbitmaps in imgs on the screen. Basically, this fits the
|
|
|
|
// subtitle canvas (of size frame_w x frame_h) onto the screen, such that it
|
|
|
|
// fills the whole video area (especially if the video is magnified, e.g. on
|
2014-10-21 09:37:32 +00:00
|
|
|
// fullscreen). If compensate_par is >0, adjust the way the subtitles are
|
|
|
|
// "stretched" on the screen, and letter-box the result. If compensate_par
|
|
|
|
// is <0, strictly letter-box the subtitles. If it is 0, stretch them.
|
2013-12-11 22:15:29 +00:00
|
|
|
void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h,
|
|
|
|
struct mp_osd_res res, double compensate_par)
|
|
|
|
{
|
|
|
|
int vidw = res.w - res.ml - res.mr;
|
|
|
|
int vidh = res.h - res.mt - res.mb;
|
|
|
|
double xscale = (double)vidw / frame_w;
|
|
|
|
double yscale = (double)vidh / frame_h;
|
2014-10-21 09:37:32 +00:00
|
|
|
if (compensate_par < 0)
|
|
|
|
compensate_par = xscale / yscale / res.display_par;
|
2015-10-21 21:07:24 +00:00
|
|
|
if (compensate_par > 0)
|
|
|
|
xscale /= compensate_par;
|
2013-12-11 22:15:29 +00:00
|
|
|
int cx = vidw / 2 - (int)(frame_w * xscale) / 2;
|
|
|
|
int cy = vidh / 2 - (int)(frame_h * yscale) / 2;
|
|
|
|
for (int i = 0; i < imgs->num_parts; i++) {
|
|
|
|
struct sub_bitmap *bi = &imgs->parts[i];
|
2014-10-01 21:58:14 +00:00
|
|
|
bi->x = (int)(bi->x * xscale) + cx + res.ml;
|
|
|
|
bi->y = (int)(bi->y * yscale) + cy + res.mt;
|
|
|
|
bi->dw = (int)(bi->w * xscale + 0.5);
|
|
|
|
bi->dh = (int)(bi->h * yscale + 0.5);
|
2013-12-11 22:15:29 +00:00
|
|
|
}
|
|
|
|
}
|