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>
|
|
|
|
|
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"
|
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
|
|
|
|
2013-03-03 10:14:44 +00:00
|
|
|
static const struct osd_style_opts osd_style_opts_def = {
|
2013-07-08 08:32:41 +00:00
|
|
|
.font = "sans-serif",
|
2012-11-17 19:56:45 +00:00
|
|
|
.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
|
|
|
#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),
|
2013-04-13 16:53:03 +00:00
|
|
|
OPT_FLOATRANGE("blur", blur, 0, 0, 20),
|
2012-11-17 19:56:45 +00:00
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.size = sizeof(struct osd_style_opts),
|
|
|
|
.defaults = &osd_style_opts_def,
|
|
|
|
};
|
|
|
|
|
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"),
|
2012-09-29 09:03:53 +00:00
|
|
|
.osd_text = talloc_strdup(osd, ""),
|
2013-04-28 19:12:11 +00:00
|
|
|
.sub_text = talloc_strdup(osd, ""),
|
2012-09-29 09:03:53 +00:00
|
|
|
.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
|
|
|
|
|
|
|
osd->objs[OSDTYPE_SUB]->is_sub = true; // dec_sub.c
|
2013-04-28 19:12:11 +00:00
|
|
|
osd->objs[OSDTYPE_SUBTEXT]->is_sub = true; // osd_libass.c
|
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);
|
|
|
|
talloc_free(osd);
|
|
|
|
}
|
|
|
|
|
2013-04-28 19:12:11 +00:00
|
|
|
static bool set_text(void *talloc_ctx, char **var, const char *text)
|
2012-08-01 16:23:28 +00:00
|
|
|
{
|
2011-08-08 08:07:17 +00:00
|
|
|
if (!text)
|
|
|
|
text = "";
|
2013-04-28 19:12:11 +00:00
|
|
|
if (strcmp(*var, text) == 0)
|
|
|
|
return true;
|
|
|
|
talloc_free(*var);
|
|
|
|
*var = talloc_strdup(talloc_ctx, text);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void osd_set_text(struct osd_state *osd, const char *text)
|
|
|
|
{
|
|
|
|
if (!set_text(osd, &osd->osd_text, text))
|
2013-04-28 23:49:20 +00:00
|
|
|
osd_changed(osd, OSDTYPE_OSD);
|
2013-04-28 19:12:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void osd_set_sub(struct osd_state *osd, const char *text)
|
|
|
|
{
|
|
|
|
if (!set_text(osd, &osd->sub_text, text))
|
2013-04-28 23:49:20 +00:00
|
|
|
osd_changed(osd, OSDTYPE_SUBTEXT);
|
2011-08-08 08:07:17 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.
Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.
One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.
Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.
There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.
As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-04-28 23:13:22 +00:00
|
|
|
if (obj->type == OSDTYPE_SUB) {
|
2013-06-01 17:44:12 +00:00
|
|
|
if (osd->render_bitmap_subs && osd->dec_sub) {
|
2013-04-28 19:12:11 +00:00
|
|
|
double sub_pts = video_pts;
|
|
|
|
if (sub_pts != MP_NOPTS_VALUE)
|
2013-06-28 23:31:19 +00:00
|
|
|
sub_pts -= osd->video_offset - opts->sub_delay;
|
2013-06-01 17:44:12 +00:00
|
|
|
sub_get_bitmaps(osd->dec_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) {
|
|
|
|
if (osd->external2.format) {
|
|
|
|
*out_imgs = osd->external2;
|
|
|
|
osd->external2.bitmap_id = osd->external2.bitmap_pos_id = 0;
|
|
|
|
}
|
Add prelimimary (basic, possibly broken) dvdnav support
This readds a more or less completely new dvdnav implementation, though
it's based on the code from before commit 41fbcee. Note that this is
rather basic, and might be broken or not quite usable in many cases.
Most importantly, navigation highlights are not correctly implemented.
This would require changes in the FFmpeg dvdsub decoder (to apply a
different internal CLUT), so supporting it is not really possible right
now. And in fact, I don't think I ever want to support it, because it's
a very small gain for a lot of work. Instead, mpv will display fake
highlights, which are an approximate bounding box around the real
highlights.
Some things like mouse input or switching audio/subtitles stream using
the dvdnav VM are not supported.
Might be quite fragile on transitions: if dvdnav initiates a transition,
and doesn't give us enough mpeg data to initialize video playback, the
player will just quit.
This is added only because some users seem to want it. I don't intend to
make mpv a good DVD player, so the very basic minimum will have to do.
How about you just convert your DVD to proper video files?
2013-12-12 00:44:28 +00:00
|
|
|
} else if (obj->type == OSDTYPE_NAV_HIGHLIGHT) {
|
|
|
|
mp_nav_get_highlight(osd, obj->vo_res, 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
|
|
|
|
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
|
|
|
{
|
2012-10-19 17:11:08 +00:00
|
|
|
if (draw_flags & OSD_DRAW_SUB_FILTER)
|
|
|
|
draw_flags |= OSD_DRAW_SUB_ONLY;
|
|
|
|
|
2013-09-30 20:25:34 +00:00
|
|
|
if (!(draw_flags & OSD_DRAW_SUB_ONLY))
|
|
|
|
osd->last_vo_res = res;
|
|
|
|
|
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 {
|
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
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-09-28 19:38:52 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
// 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
|
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
|
|
|
void osd_object_get_scale_factor(struct osd_state *osd, struct osd_object *obj,
|
|
|
|
double *sw, double *sh)
|
|
|
|
{
|
|
|
|
int nw, nh;
|
|
|
|
osd_object_get_resolution(osd, obj, &nw, &nh);
|
|
|
|
*sw = nw / (double)obj->vo_res.w;
|
|
|
|
*sh = nh / (double)obj->vo_res.h;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// fullscreen). If compensate_par is given, adjust the way the subtitles are
|
|
|
|
// "stretched" on the screen, and letter-box the result.
|
|
|
|
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;
|
|
|
|
if (compensate_par > 0) {
|
|
|
|
if (compensate_par > 1.0) {
|
|
|
|
xscale /= compensate_par;
|
|
|
|
} else {
|
|
|
|
yscale *= compensate_par;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
bi->x = bi->x * xscale + cx + res.ml;
|
|
|
|
bi->y = bi->y * yscale + cy + res.mt;
|
|
|
|
bi->dw = bi->w * xscale;
|
|
|
|
bi->dh = bi->h * yscale;
|
|
|
|
}
|
|
|
|
imgs->scaled = xscale != 1 || yscale != 1;
|
|
|
|
}
|