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
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2009-02-08 03:27:30 +00:00
|
|
|
* 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.
|
|
|
|
*
|
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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* 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>
|
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>
|
|
|
|
|
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
|
|
|
|
2008-06-23 22:53:58 +00:00
|
|
|
#include "talloc.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"
|
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),
|
|
|
|
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),
|
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),
|
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
|
|
|
},
|
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
|
|
|
},
|
2012-11-17 19:56:45 +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
|
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
|
|
|
{
|
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) {
|
2013-12-21 18:06:37 +00:00
|
|
|
.opts = global->opts,
|
|
|
|
.global = global,
|
|
|
|
.log = mp_log_new(osd, global->log, "osd"),
|
2008-06-23 22:53:58 +00:00
|
|
|
};
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_init(&osd->lock, NULL);
|
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
|
|
|
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
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
static void osd_changed_unlocked(struct osd_state *osd, int obj)
|
2012-08-01 16:23:28 +00:00
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
osd->objs[obj]->force_redraw = true;
|
|
|
|
osd->want_redraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void osd_set_text(struct osd_state *osd, int obj, const char *text)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
struct osd_object *osd_obj = osd->objs[obj];
|
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);
|
|
|
|
osd_changed_unlocked(osd, obj);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
2015-11-17 00:54:02 +00:00
|
|
|
void osd_set_sub(struct osd_state *osd, int obj, struct dec_sub *dec_sub)
|
2014-01-18 00:19:20 +00:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
2015-11-17 00:54:02 +00:00
|
|
|
osd->objs[obj]->sub = dec_sub;
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
memcpy(osd_obj->progbar_state.stops, s->stops,
|
|
|
|
sizeof(osd_obj->progbar_state.stops[0]) * s->num_stops);
|
|
|
|
osd_changed_unlocked(osd, osd_obj->type);
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void osd_set_external(struct osd_state *osd, int res_x, int res_y, char *text)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
struct osd_object *osd_obj = osd->objs[OSDTYPE_EXTERNAL];
|
|
|
|
if (strcmp(osd_obj->text, text) != 0 ||
|
|
|
|
osd_obj->external_res_x != res_x ||
|
|
|
|
osd_obj->external_res_y != res_y)
|
|
|
|
{
|
|
|
|
talloc_free(osd_obj->text);
|
|
|
|
osd_obj->text = talloc_strdup(osd_obj, text);
|
|
|
|
osd_obj->external_res_x = res_x;
|
|
|
|
osd_obj->external_res_y = res_y;
|
|
|
|
osd_changed_unlocked(osd, osd_obj->type);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
2013-04-28 19:12:11 +00:00
|
|
|
}
|
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
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;
|
2014-10-14 16:33:31 +00:00
|
|
|
osd_changed_unlocked(osd, OSDTYPE_EXTERNAL2);
|
2014-01-18 00:19:20 +00:00
|
|
|
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
|
|
|
{
|
2012-11-24 23:06:16 +00:00
|
|
|
struct MPOpts *opts = osd->opts;
|
|
|
|
|
2012-12-28 16:17:16 +00:00
|
|
|
bool formats[SUBBITMAP_COUNT];
|
|
|
|
memcpy(formats, sub_formats, sizeof(formats));
|
2013-03-04 16:40:21 +00:00
|
|
|
if (opts->force_rgba_osd)
|
2012-12-28 16:17:16 +00:00
|
|
|
formats[SUBBITMAP_LIBASS] = false;
|
|
|
|
|
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;
|
|
|
|
|
2013-12-24 16:46:14 +00:00
|
|
|
if (obj->type == OSDTYPE_SUB || obj->type == OSDTYPE_SUB2) {
|
2015-11-17 00:54:02 +00:00
|
|
|
if (obj->sub) {
|
2013-04-28 19:12:11 +00:00
|
|
|
double sub_pts = video_pts;
|
|
|
|
if (sub_pts != MP_NOPTS_VALUE)
|
2015-11-16 22:15:59 +00:00
|
|
|
sub_pts -= opts->sub_delay;
|
2015-11-17 00:54:02 +00:00
|
|
|
sub_get_bitmaps(obj->sub, obj->vo_res, sub_pts, out_imgs);
|
2013-04-28 19:12:11 +00:00
|
|
|
}
|
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 {
|
|
|
|
osd_object_get_bitmaps(osd, obj, out_imgs);
|
|
|
|
}
|
|
|
|
|
2015-03-18 11:33:14 +00:00
|
|
|
if (obj->force_redraw)
|
|
|
|
out_imgs->change_id++;
|
2012-10-16 05:26:45 +00:00
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
obj->force_redraw = false;
|
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
|
|
|
|
2015-03-18 11:33:14 +00:00
|
|
|
if (obj->cached.change_id == obj->vo_change_id && formats[obj->cached.format])
|
2012-09-28 19:38:52 +00:00
|
|
|
{
|
|
|
|
*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;
|
2015-03-18 11:33:14 +00:00
|
|
|
out_imgs->change_id = obj->vo_change_id;
|
2012-09-28 19:38:52 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2013-08-12 00:40:20 +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
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
|
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
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
double sar = (double)p->w / p->h;
|
|
|
|
double dar = (double)p->d_w / p->d_h;
|
|
|
|
|
|
|
|
return (struct mp_osd_res) {
|
|
|
|
.w = p->w,
|
|
|
|
.h = p->h,
|
|
|
|
.display_par = sar / dar,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-04-28 23:49:20 +00:00
|
|
|
void osd_changed(struct osd_state *osd, int new_value)
|
2002-02-22 15:25:11 +00:00
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
osd_changed_unlocked(osd, new_value);
|
|
|
|
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
|
|
|
|
2013-05-14 21:14:23 +00:00
|
|
|
void osd_changed_all(struct osd_state *osd)
|
2012-11-17 19:56:45 +00:00
|
|
|
{
|
2013-05-14 21:14:23 +00:00
|
|
|
for (int n = 0; n < MAX_OSD_PARTS; n++)
|
2013-04-28 23:49:20 +00:00
|
|
|
osd_changed(osd, n);
|
2012-11-17 19:56:45 +00:00
|
|
|
}
|
Add initial Lua scripting support
This is preliminary. There are still tons of issues, and any aspect
of scripting may change in the future. I decided to merge this
(preliminary) work now because it makes it easier to develop it, not
because it's done. lua.rst is clear enough about it (plus some
sarcasm).
This requires linking to Lua. Lua has no official pkg-config file, but
there are distribution specific .pc files, all with different names.
Adding a non-pkg-config based configure test was considered, but we'd
rather not.
One major complication is that libquvi links against Lua too, and if
the Lua version is different from mpv's, you will get a crash as soon
as libquvi uses Lua. (libquvi by design always runs when a file is
opened.) I would consider this the problem of distros and whoever
builds mpv, but to make things easier for users, we add a terrible
runtime test to the configure script, which probes whether libquvi
will crash. This is disabled when cross-compiling, but in that case
we hope the user knows what he is doing.
2013-09-25 22:41:14 +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);
|
|
|
|
bool r = osd->want_redraw;
|
|
|
|
osd->want_redraw = false;
|
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
Add initial Lua scripting support
This is preliminary. There are still tons of issues, and any aspect
of scripting may change in the future. I decided to merge this
(preliminary) work now because it makes it easier to develop it, not
because it's done. lua.rst is clear enough about it (plus some
sarcasm).
This requires linking to Lua. Lua has no official pkg-config file, but
there are distribution specific .pc files, all with different names.
Adding a non-pkg-config based configure test was considered, but we'd
rather not.
One major complication is that libquvi links against Lua too, and if
the Lua version is different from mpv's, you will get a crash as soon
as libquvi uses Lua. (libquvi by design always runs when a file is
opened.) I would consider this the problem of distros and whoever
builds mpv, but to make things easier for users, we add a terrible
runtime test to the configure script, which probes whether libquvi
will crash. This is disabled when cross-compiling, but in that case
we hope the user knows what he is doing.
2013-09-25 22:41:14 +00:00
|
|
|
// Scale factor to translate OSD coordinates to what the obj uses internally.
|
2013-12-10 18:57:08 +00:00
|
|
|
// osd_coordinates * (sw, sh) = obj_coordinates
|
2014-01-18 00:19:20 +00:00
|
|
|
void osd_object_get_scale_factor(struct osd_state *osd, int obj,
|
Add initial Lua scripting support
This is preliminary. There are still tons of issues, and any aspect
of scripting may change in the future. I decided to merge this
(preliminary) work now because it makes it easier to develop it, not
because it's done. lua.rst is clear enough about it (plus some
sarcasm).
This requires linking to Lua. Lua has no official pkg-config file, but
there are distribution specific .pc files, all with different names.
Adding a non-pkg-config based configure test was considered, but we'd
rather not.
One major complication is that libquvi links against Lua too, and if
the Lua version is different from mpv's, you will get a crash as soon
as libquvi uses Lua. (libquvi by design always runs when a file is
opened.) I would consider this the problem of distros and whoever
builds mpv, but to make things easier for users, we add a terrible
runtime test to the configure script, which probes whether libquvi
will crash. This is disabled when cross-compiling, but in that case
we hope the user knows what he is doing.
2013-09-25 22:41:14 +00:00
|
|
|
double *sw, double *sh)
|
|
|
|
{
|
|
|
|
int nw, nh;
|
|
|
|
osd_object_get_resolution(osd, obj, &nw, &nh);
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_lock(&osd->lock);
|
2014-09-14 18:35:56 +00:00
|
|
|
int vow = osd->objs[obj]->vo_res.w;
|
|
|
|
int voh = osd->objs[obj]->vo_res.h;
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
2014-09-14 18:35:56 +00:00
|
|
|
*sw = vow ? nw / (double)vow : 0;
|
|
|
|
*sh = voh ? nh / (double)voh : 0;
|
Add initial Lua scripting support
This is preliminary. There are still tons of issues, and any aspect
of scripting may change in the future. I decided to merge this
(preliminary) work now because it makes it easier to develop it, not
because it's done. lua.rst is clear enough about it (plus some
sarcasm).
This requires linking to Lua. Lua has no official pkg-config file, but
there are distribution specific .pc files, all with different names.
Adding a non-pkg-config based configure test was considered, but we'd
rather not.
One major complication is that libquvi links against Lua too, and if
the Lua version is different from mpv's, you will get a crash as soon
as libquvi uses Lua. (libquvi by design always runs when a file is
opened.) I would consider this the problem of distros and whoever
builds mpv, but to make things easier for users, we add a terrible
runtime test to the configure script, which probes whether libquvi
will crash. This is disabled when cross-compiling, but in that case
we hope the user knows what he is doing.
2013-09-25 22:41:14 +00:00
|
|
|
}
|
2013-12-11 22:15:29 +00:00
|
|
|
|
2013-12-12 23:19:17 +00:00
|
|
|
// Turn *x and *y, which are given in OSD coordinates, to video coordinates.
|
|
|
|
// frame_w and frame_h give the dimensions of the original, unscaled video.
|
|
|
|
// (This gives correct results only after the OSD has been updated after a
|
|
|
|
// resize or video reconfig.)
|
|
|
|
void osd_coords_to_video(struct osd_state *osd, int frame_w, int frame_h,
|
|
|
|
int *x, int *y)
|
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_lock(&osd->lock);
|
2013-12-12 23:19:17 +00:00
|
|
|
struct mp_osd_res res = osd->objs[OSDTYPE_OSD]->vo_res;
|
|
|
|
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;
|
|
|
|
// The OSD size + margins make up the scaled rectangle of the video.
|
|
|
|
*x = (*x - res.ml) / xscale;
|
|
|
|
*y = (*y - res.mt) / yscale;
|
2014-01-18 00:19:20 +00:00
|
|
|
pthread_mutex_unlock(&osd->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mp_osd_res osd_get_vo_res(struct osd_state *osd, int obj)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&osd->lock);
|
|
|
|
struct mp_osd_res res = osd->objs[obj]->vo_res;
|
|
|
|
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
|
|
|
}
|
|
|
|
imgs->scaled = xscale != 1 || yscale != 1;
|
|
|
|
}
|