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-27 00:32:24 +00:00
|
|
|
|
2007-07-02 22:34:45 +00:00
|
|
|
#ifndef MPLAYER_SUB_H
|
|
|
|
#define MPLAYER_SUB_H
|
2001-04-24 11:42:04 +00:00
|
|
|
|
2012-10-22 14:15:52 +00:00
|
|
|
#include <stddef.h>
|
2011-01-19 18:13:48 +00:00
|
|
|
#include <stdbool.h>
|
2012-10-04 15:16:40 +00:00
|
|
|
#include <stdint.h>
|
2011-01-19 18:13:48 +00:00
|
|
|
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2012-11-17 19:56:45 +00:00
|
|
|
|
2022-01-11 20:03:27 +00:00
|
|
|
// NOTE: VOs must support at least SUBBITMAP_BGRA.
|
2012-10-04 15:16:40 +00:00
|
|
|
enum sub_bitmap_format {
|
|
|
|
SUBBITMAP_EMPTY = 0,// no bitmaps; always has num_parts==0
|
|
|
|
SUBBITMAP_LIBASS, // A8, with a per-surface blend color (libass.color)
|
2022-01-11 20:03:27 +00:00
|
|
|
SUBBITMAP_BGRA, // IMGFMT_BGRA (MSB=A, LSB=B), scaled, premultiplied alpha
|
2012-10-04 15:16:40 +00:00
|
|
|
|
|
|
|
SUBBITMAP_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sub_bitmap {
|
|
|
|
void *bitmap;
|
|
|
|
int stride;
|
2012-10-04 15:16:47 +00:00
|
|
|
// Note: not clipped, going outside the screen area is allowed
|
|
|
|
// (except for SUBBITMAP_LIBASS, which is always clipped)
|
2012-10-04 15:16:40 +00:00
|
|
|
int w, h;
|
|
|
|
int x, y;
|
|
|
|
int dw, dh;
|
|
|
|
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
// If the containing struct sub_bitmaps has the packed field set, then this
|
|
|
|
// is the position within the source. (Strictly speaking this is redundant
|
|
|
|
// with the bitmap pointer.)
|
|
|
|
int src_x, src_y;
|
|
|
|
|
2014-04-26 14:02:49 +00:00
|
|
|
struct {
|
|
|
|
uint32_t color;
|
|
|
|
} libass;
|
2012-10-04 15:16:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sub_bitmaps {
|
2012-10-04 15:16:47 +00:00
|
|
|
// For VO cache state (limited by MAX_OSD_PARTS)
|
|
|
|
int render_index;
|
2012-10-04 15:16:40 +00:00
|
|
|
|
|
|
|
enum sub_bitmap_format format;
|
2012-10-04 15:16:47 +00:00
|
|
|
|
2012-10-04 15:16:40 +00:00
|
|
|
struct sub_bitmap *parts;
|
|
|
|
int num_parts;
|
|
|
|
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
// Packed representation of the bitmap data. If non-NULL, then the
|
|
|
|
// parts[].bitmap pointer points into the image data here (and stride will
|
|
|
|
// correspond to packed->stride[0]).
|
2022-01-11 20:03:27 +00:00
|
|
|
// SUBBITMAP_BGRA: IMGFMT_BGRA (exact match)
|
2016-06-30 19:38:50 +00:00
|
|
|
// SUBBITMAP_LIBASS: IMGFMT_Y8 (not the same, but compatible layout)
|
sub, vo_opengl: use packed sub-bitmaps directly if available
The previous few commits changed sd_lavc.c's output to packed RGB sub-
images. In particular, this means all sub-bitmaps are part of a larger,
single bitmap. Change the vo_opengl OSD code such that it can make use
of this, and upload the pre-packed image, instead of packing and copying
them again.
This complicates the upload code a bit (4 code paths due to messy PBO
handling). The plan is to make sub-bitmaps always packed, but some more
work is required to reach this point. The plan is to pack libass images
as well. Since this implies a copy, this will make it easy to refcount
the result.
(This is all targeted towards vo_opengl. Other VOs, vo_xv, vo_x11, and
vo_wayland in particular, will become less efficient. Although at least
vo_vdpau and vo_direct3d could be switched to the new method as well.)
2016-06-17 21:11:05 +00:00
|
|
|
// Other formats have this set to NULL.
|
|
|
|
struct mp_image *packed;
|
|
|
|
|
|
|
|
// Bounding box for the packed image. All parts will be within the bounding
|
|
|
|
// box. (The origin of the box is at (0,0).)
|
|
|
|
int packed_w, packed_h;
|
|
|
|
|
2020-05-09 15:54:33 +00:00
|
|
|
int change_id; // Incremented on each change (0 is never used)
|
2024-02-27 01:12:46 +00:00
|
|
|
|
|
|
|
bool video_color_space; // True if the bitmap is in video color space
|
2012-10-04 15:16:40 +00:00
|
|
|
};
|
|
|
|
|
video: make OSD/subtitle bitmaps refcounted (sort of)
Making OSD/subtitle bitmaps refcounted was planend a longer time ago,
e.g. the sub_bitmaps.packed field (which refcounts the subtitle bitmap
data) was added in 2016. But nothing benefited much from it, because
struct sub_bitmaps was usually stack allocated, and there was this weird
callback stuff through osd_draw().
Make it possible to get actually refcounted subtitle bitmaps on the OSD
API level. For this, we just copy all subtitle data other than the
bitmaps with sub_bitmaps_copy(). At first, I had planned some fancy
refcount shit, but when that was a big mess and hard to debug and just
boiled to emulating malloc(), I made it a full allocation+copy. This
affects mostly the parts array. With crazy ASS subtitles, this parts
array can get pretty big (thousands of elements or more), in which case
the extra alloc/copy could become performance relevant. But then again
this is just pure bullshit, and I see no need to care. In practice, this
extra work most likely gets drowned out by libass murdering a single
core (while mpv is waiting for it) anyway. So fuck it.
I just wanted this so draw_bmp.c requires only a single call to render
everything. VOs also can benefit from this, because the weird callback
shit isn't necessary anymore (simpler code), but I haven't done anything
about it yet. In general I'd hope this will work towards simplifying the
OSD layer, which is prerequisite for making actual further improvements.
I haven't tested some cases such as the "overlay-add" command. Maybe it
crashes now? Who knows, who cares.
In addition, it might be worthwhile to reduce the code duplication
between all the things that output subtitle bitmaps (with repacking,
image allocation, etc.), but that's orthogonal.
2020-04-26 21:34:32 +00:00
|
|
|
struct sub_bitmap_list {
|
2020-05-09 15:54:33 +00:00
|
|
|
// Combined change_id - of any of the existing items change (even if they
|
|
|
|
// e.g. go away and are removed from items[]), this is incremented.
|
|
|
|
int64_t change_id;
|
|
|
|
|
|
|
|
// Bounding box for rendering. It's notable that SUBBITMAP_LIBASS images are
|
2022-01-11 20:03:27 +00:00
|
|
|
// always within these bounds, while SUBBITMAP_BGRA is not necessarily.
|
2020-05-09 15:54:33 +00:00
|
|
|
int w, h;
|
|
|
|
|
|
|
|
// Sorted by sub_bitmaps.render_index. Unused parts are not in the array,
|
|
|
|
// and you cannot index items[] with render_index.
|
video: make OSD/subtitle bitmaps refcounted (sort of)
Making OSD/subtitle bitmaps refcounted was planend a longer time ago,
e.g. the sub_bitmaps.packed field (which refcounts the subtitle bitmap
data) was added in 2016. But nothing benefited much from it, because
struct sub_bitmaps was usually stack allocated, and there was this weird
callback stuff through osd_draw().
Make it possible to get actually refcounted subtitle bitmaps on the OSD
API level. For this, we just copy all subtitle data other than the
bitmaps with sub_bitmaps_copy(). At first, I had planned some fancy
refcount shit, but when that was a big mess and hard to debug and just
boiled to emulating malloc(), I made it a full allocation+copy. This
affects mostly the parts array. With crazy ASS subtitles, this parts
array can get pretty big (thousands of elements or more), in which case
the extra alloc/copy could become performance relevant. But then again
this is just pure bullshit, and I see no need to care. In practice, this
extra work most likely gets drowned out by libass murdering a single
core (while mpv is waiting for it) anyway. So fuck it.
I just wanted this so draw_bmp.c requires only a single call to render
everything. VOs also can benefit from this, because the weird callback
shit isn't necessary anymore (simpler code), but I haven't done anything
about it yet. In general I'd hope this will work towards simplifying the
OSD layer, which is prerequisite for making actual further improvements.
I haven't tested some cases such as the "overlay-add" command. Maybe it
crashes now? Who knows, who cares.
In addition, it might be worthwhile to reduce the code duplication
between all the things that output subtitle bitmaps (with repacking,
image allocation, etc.), but that's orthogonal.
2020-04-26 21:34:32 +00:00
|
|
|
struct sub_bitmaps **items;
|
|
|
|
int num_items;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sub_bitmap_copy_cache;
|
|
|
|
struct sub_bitmaps *sub_bitmaps_copy(struct sub_bitmap_copy_cache **cache,
|
|
|
|
struct sub_bitmaps *in);
|
|
|
|
|
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 {
|
2012-10-04 15:16:40 +00:00
|
|
|
int w, h; // screen dimensions, including black borders
|
|
|
|
int mt, mb, ml, mr; // borders (top, bottom, left, right)
|
2012-10-18 15:31:00 +00:00
|
|
|
double display_par;
|
2012-10-04 15:16:40 +00:00
|
|
|
};
|
2012-09-28 19:33:26 +00:00
|
|
|
|
2017-08-29 13:15:34 +00:00
|
|
|
bool osd_res_equals(struct mp_osd_res a, struct mp_osd_res b);
|
|
|
|
|
2016-03-08 20:54:17 +00:00
|
|
|
// 0 <= sub_bitmaps.render_index < MAX_OSD_PARTS
|
|
|
|
#define MAX_OSD_PARTS 5
|
2012-09-28 19:38:52 +00:00
|
|
|
|
2012-09-29 07:53:28 +00:00
|
|
|
// Start of OSD symbols in osd_font.pfb
|
|
|
|
#define OSD_CODEPOINTS 0xE000
|
|
|
|
|
|
|
|
// OSD symbols. osd_font.pfb has them starting from codepoint OSD_CODEPOINTS.
|
|
|
|
// Symbols with a value >= 32 are normal unicode codepoints.
|
|
|
|
enum mp_osd_font_codepoints {
|
|
|
|
OSD_PLAY = 0x01,
|
|
|
|
OSD_PAUSE = 0x02,
|
|
|
|
OSD_STOP = 0x03,
|
|
|
|
OSD_REW = 0x04,
|
|
|
|
OSD_FFW = 0x05,
|
|
|
|
OSD_CLOCK = 0x06,
|
|
|
|
OSD_CONTRAST = 0x07,
|
|
|
|
OSD_SATURATION = 0x08,
|
|
|
|
OSD_VOLUME = 0x09,
|
|
|
|
OSD_BRIGHTNESS = 0x0A,
|
|
|
|
OSD_HUE = 0x0B,
|
|
|
|
OSD_BALANCE = 0x0C,
|
2020-09-25 20:34:55 +00:00
|
|
|
OSD_REV = 0x0D,
|
2012-09-29 07:53:28 +00:00
|
|
|
OSD_PANSCAN = 0x50,
|
|
|
|
|
|
|
|
OSD_PB_START = 0x10,
|
|
|
|
OSD_PB_0 = 0x11,
|
|
|
|
OSD_PB_END = 0x12,
|
|
|
|
OSD_PB_1 = 0x13,
|
|
|
|
};
|
2001-03-27 00:32:24 +00:00
|
|
|
|
2016-05-03 20:29:12 +00:00
|
|
|
|
|
|
|
// Never valid UTF-8, so we expect it's free for use.
|
|
|
|
// Specially interpreted by osd_libass.c, in order to allow/escape ASS tags.
|
|
|
|
#define OSD_ASS_0 "\xFD"
|
|
|
|
#define OSD_ASS_1 "\xFE"
|
|
|
|
|
2012-11-17 19:56:45 +00:00
|
|
|
struct osd_style_opts {
|
|
|
|
char *font;
|
|
|
|
float font_size;
|
|
|
|
struct m_color color;
|
|
|
|
struct m_color border_color;
|
|
|
|
struct m_color shadow_color;
|
|
|
|
struct m_color back_color;
|
|
|
|
float border_size;
|
|
|
|
float shadow_offset;
|
|
|
|
float spacing;
|
|
|
|
int margin_x;
|
|
|
|
int margin_y;
|
2015-02-16 19:04:02 +00:00
|
|
|
int align_x;
|
|
|
|
int align_y;
|
2013-04-13 16:53:03 +00:00
|
|
|
float blur;
|
2023-02-20 03:32:50 +00:00
|
|
|
bool bold;
|
|
|
|
bool italic;
|
2017-02-01 12:19:09 +00:00
|
|
|
int justify;
|
2019-09-25 20:11:39 +00:00
|
|
|
int font_provider;
|
2022-02-11 02:36:34 +00:00
|
|
|
char *fonts_dir;
|
2012-11-17 19:56:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const struct m_sub_options osd_style_conf;
|
2015-02-16 19:03:56 +00:00
|
|
|
extern const struct m_sub_options sub_style_conf;
|
2012-11-17 19:56:45 +00:00
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
struct osd_state;
|
|
|
|
struct osd_object;
|
|
|
|
struct mpv_global;
|
2015-11-17 00:54:02 +00:00
|
|
|
struct dec_sub;
|
2014-01-18 00:19:20 +00:00
|
|
|
|
2013-12-21 18:06:37 +00:00
|
|
|
struct osd_state *osd_create(struct mpv_global *global);
|
2016-09-15 12:22:48 +00:00
|
|
|
void osd_changed(struct osd_state *osd);
|
2008-06-23 22:53:58 +00:00
|
|
|
void osd_free(struct osd_state *osd);
|
2002-02-22 15:25:11 +00:00
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
bool osd_query_and_reset_want_redraw(struct osd_state *osd);
|
|
|
|
|
2016-03-08 20:54:17 +00:00
|
|
|
void osd_set_text(struct osd_state *osd, const char *text);
|
|
|
|
void osd_set_sub(struct osd_state *osd, int index, struct dec_sub *dec_sub);
|
2014-01-18 00:19:20 +00:00
|
|
|
|
|
|
|
bool osd_get_render_subs_in_filter(struct osd_state *osd);
|
|
|
|
void osd_set_render_subs_in_filter(struct osd_state *osd, bool s);
|
2016-10-26 18:43:03 +00:00
|
|
|
void osd_set_force_video_pts(struct osd_state *osd, double video_pts);
|
|
|
|
double osd_get_force_video_pts(struct osd_state *osd);
|
2014-01-18 00:19:20 +00:00
|
|
|
|
|
|
|
struct osd_progbar_state {
|
|
|
|
int type; // <0: disabled, 1-255: symbol, else: no symbol
|
|
|
|
float value; // range 0.0-1.0
|
|
|
|
float *stops; // used for chapter indicators (0.0-1.0 each)
|
|
|
|
int num_stops;
|
|
|
|
};
|
|
|
|
void osd_set_progbar(struct osd_state *osd, struct osd_progbar_state *s);
|
|
|
|
|
|
|
|
void osd_set_external2(struct osd_state *osd, struct sub_bitmaps *imgs);
|
|
|
|
|
2012-10-19 17:11:08 +00:00
|
|
|
enum mp_osd_draw_flags {
|
|
|
|
OSD_DRAW_SUB_FILTER = (1 << 0),
|
|
|
|
OSD_DRAW_SUB_ONLY = (1 << 1),
|
2015-03-23 01:42:19 +00:00
|
|
|
OSD_DRAW_OSD_ONLY = (1 << 2),
|
2012-10-19 17:11:08 +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
|
|
|
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
|
|
|
|
video: make OSD/subtitle bitmaps refcounted (sort of)
Making OSD/subtitle bitmaps refcounted was planend a longer time ago,
e.g. the sub_bitmaps.packed field (which refcounts the subtitle bitmap
data) was added in 2016. But nothing benefited much from it, because
struct sub_bitmaps was usually stack allocated, and there was this weird
callback stuff through osd_draw().
Make it possible to get actually refcounted subtitle bitmaps on the OSD
API level. For this, we just copy all subtitle data other than the
bitmaps with sub_bitmaps_copy(). At first, I had planned some fancy
refcount shit, but when that was a big mess and hard to debug and just
boiled to emulating malloc(), I made it a full allocation+copy. This
affects mostly the parts array. With crazy ASS subtitles, this parts
array can get pretty big (thousands of elements or more), in which case
the extra alloc/copy could become performance relevant. But then again
this is just pure bullshit, and I see no need to care. In practice, this
extra work most likely gets drowned out by libass murdering a single
core (while mpv is waiting for it) anyway. So fuck it.
I just wanted this so draw_bmp.c requires only a single call to render
everything. VOs also can benefit from this, because the weird callback
shit isn't necessary anymore (simpler code), but I haven't done anything
about it yet. In general I'd hope this will work towards simplifying the
OSD layer, which is prerequisite for making actual further improvements.
I haven't tested some cases such as the "overlay-add" command. Maybe it
crashes now? Who knows, who cares.
In addition, it might be worthwhile to reduce the code duplication
between all the things that output subtitle bitmaps (with repacking,
image allocation, etc.), but that's orthogonal.
2020-04-26 21:34:32 +00:00
|
|
|
struct sub_bitmap_list *osd_render(struct osd_state *osd, struct mp_osd_res res,
|
|
|
|
double video_pts, int draw_flags,
|
|
|
|
const bool formats[SUBBITMAP_COUNT]);
|
|
|
|
|
2012-10-07 01:26:46 +00:00
|
|
|
struct mp_image;
|
video: make OSD/subtitle bitmaps refcounted (sort of)
Making OSD/subtitle bitmaps refcounted was planend a longer time ago,
e.g. the sub_bitmaps.packed field (which refcounts the subtitle bitmap
data) was added in 2016. But nothing benefited much from it, because
struct sub_bitmaps was usually stack allocated, and there was this weird
callback stuff through osd_draw().
Make it possible to get actually refcounted subtitle bitmaps on the OSD
API level. For this, we just copy all subtitle data other than the
bitmaps with sub_bitmaps_copy(). At first, I had planned some fancy
refcount shit, but when that was a big mess and hard to debug and just
boiled to emulating malloc(), I made it a full allocation+copy. This
affects mostly the parts array. With crazy ASS subtitles, this parts
array can get pretty big (thousands of elements or more), in which case
the extra alloc/copy could become performance relevant. But then again
this is just pure bullshit, and I see no need to care. In practice, this
extra work most likely gets drowned out by libass murdering a single
core (while mpv is waiting for it) anyway. So fuck it.
I just wanted this so draw_bmp.c requires only a single call to render
everything. VOs also can benefit from this, because the weird callback
shit isn't necessary anymore (simpler code), but I haven't done anything
about it yet. In general I'd hope this will work towards simplifying the
OSD layer, which is prerequisite for making actual further improvements.
I haven't tested some cases such as the "overlay-add" command. Maybe it
crashes now? Who knows, who cares.
In addition, it might be worthwhile to reduce the code duplication
between all the things that output subtitle bitmaps (with repacking,
image allocation, etc.), but that's orthogonal.
2020-04-26 21:34:32 +00:00
|
|
|
void 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
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
|
2016-03-21 21:23:41 +00:00
|
|
|
void osd_resize(struct osd_state *osd, struct mp_osd_res res);
|
|
|
|
|
2014-01-21 22:43:54 +00:00
|
|
|
struct mp_image_params;
|
|
|
|
struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p);
|
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
|
client API, lua: add new API for setting OSD overlays
Lua scripting has an undocumented mp.set_osd_ass() function, which is
used by osc.lua and console.lua. Apparently, 3rd party scripts also use
this. It's probably time to make this a public API.
The Lua implementation just bypassed the libmpv API. To make it usable
by any type of client, turn it into a command, "osd-overlay".
There's already a "overlay-add". Ignore it (although the manpage admits
guiltiness). I don't really want to deal with that old command. Its main
problem is that it uses global IDs, while I'd like to avoid that scripts
mess with each others overlays (whether that is accidentally or
intentionally). Maybe "overlay-add" can eventually be merged into
"osd-overlay", but I'm too lazy to do that now.
Scripting now uses the commands. There is a helper to manage OSD
overlays. The helper is very "thin"; I only want to force script authors
to use the ID allocation, which may help with putting multiple scripts
into a single .lua file without causing conflicts (basically, avoiding
singletons within a script's environment). The old set_osd_ass() is
emulated with the new API.
The JS scripting wrapper also provides a set_osd_ass() function, which
calls internal mpv API. Comment that part (to keep it compiling), but
I'm leaving it to @avih to finish the change.
2019-12-23 10:40:27 +00:00
|
|
|
struct osd_external_ass {
|
|
|
|
void *owner; // unique pointer (NULL is also allowed)
|
|
|
|
int64_t id;
|
|
|
|
int format;
|
|
|
|
char *data;
|
|
|
|
int res_x, res_y;
|
|
|
|
int z;
|
2020-03-06 17:20:11 +00:00
|
|
|
bool hidden;
|
|
|
|
|
|
|
|
double *out_rc; // hack to pass boundary rect, [x0, y0, x1, y1]
|
client API, lua: add new API for setting OSD overlays
Lua scripting has an undocumented mp.set_osd_ass() function, which is
used by osc.lua and console.lua. Apparently, 3rd party scripts also use
this. It's probably time to make this a public API.
The Lua implementation just bypassed the libmpv API. To make it usable
by any type of client, turn it into a command, "osd-overlay".
There's already a "overlay-add". Ignore it (although the manpage admits
guiltiness). I don't really want to deal with that old command. Its main
problem is that it uses global IDs, while I'd like to avoid that scripts
mess with each others overlays (whether that is accidentally or
intentionally). Maybe "overlay-add" can eventually be merged into
"osd-overlay", but I'm too lazy to do that now.
Scripting now uses the commands. There is a helper to manage OSD
overlays. The helper is very "thin"; I only want to force script authors
to use the ID allocation, which may help with putting multiple scripts
into a single .lua file without causing conflicts (basically, avoiding
singletons within a script's environment). The old set_osd_ass() is
emulated with the new API.
The JS scripting wrapper also provides a set_osd_ass() function, which
calls internal mpv API. Comment that part (to keep it compiling), but
I'm leaving it to @avih to finish the change.
2019-12-23 10:40:27 +00:00
|
|
|
};
|
|
|
|
|
2012-09-28 19:38:52 +00:00
|
|
|
// defined in osd_libass.c and osd_dummy.c
|
client API, lua: add new API for setting OSD overlays
Lua scripting has an undocumented mp.set_osd_ass() function, which is
used by osc.lua and console.lua. Apparently, 3rd party scripts also use
this. It's probably time to make this a public API.
The Lua implementation just bypassed the libmpv API. To make it usable
by any type of client, turn it into a command, "osd-overlay".
There's already a "overlay-add". Ignore it (although the manpage admits
guiltiness). I don't really want to deal with that old command. Its main
problem is that it uses global IDs, while I'd like to avoid that scripts
mess with each others overlays (whether that is accidentally or
intentionally). Maybe "overlay-add" can eventually be merged into
"osd-overlay", but I'm too lazy to do that now.
Scripting now uses the commands. There is a helper to manage OSD
overlays. The helper is very "thin"; I only want to force script authors
to use the ID allocation, which may help with putting multiple scripts
into a single .lua file without causing conflicts (basically, avoiding
singletons within a script's environment). The old set_osd_ass() is
emulated with the new API.
The JS scripting wrapper also provides a set_osd_ass() function, which
calls internal mpv API. Comment that part (to keep it compiling), but
I'm leaving it to @avih to finish the change.
2019-12-23 10:40:27 +00:00
|
|
|
void osd_set_external(struct osd_state *osd, struct osd_external_ass *ov);
|
|
|
|
void osd_set_external_remove_owner(struct osd_state *osd, void *owner);
|
2017-01-26 17:24:53 +00:00
|
|
|
void osd_get_text_size(struct osd_state *osd, int *out_screen_h, int *out_font_h);
|
2014-01-18 00:19:20 +00:00
|
|
|
void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function);
|
2022-05-01 05:29:32 +00:00
|
|
|
void osd_mangle_ass(bstr *dst, const char *in, bool replace_newlines);
|
2014-01-18 00:19:20 +00:00
|
|
|
|
2007-12-31 16:15:50 +00:00
|
|
|
#endif /* MPLAYER_SUB_H */
|