summaryrefslogtreecommitdiffstats
path: root/sub/osd_libass.c
Commit message (Collapse)AuthorAgeFilesLines
* command: add escape-assGuido Cella8 days1-2/+10
| | | | | | | | | | | | | | | | | This adds a command to escape ASS tags to remove code duplication between sub/osd_libass.c, console.lua, osc.lua, stats.lua and any user script that calls mp.create_osd_overlay(). A command is used instead of scripting functions so that all clients can use this and not just use Lua and JS ones. osd_mangle_ass() also interprets osd-sym-cc and osd-ass-cc/{0,1}, but since they use invalid UTF-8 characters there is no risk of escape-ass users using them by accident, like with any OSD message. Always replacing \n with \\N in mangle_ass() even when it is not called by escape-ass doesn't seem to cause any issue, but I made it conditional anyway to avoid changing how all OSD messages are treated unnecessarily.
* sub: add flag if sub_bitmap should be rendered in video color spaceKacper Michajłow2024-03-021-1/+1
|
* osd_libass: update the OSD bar's dent and border sizeGuido Cella2024-02-261-1/+1
| | | | | Make the OSD bar markers bigger so we can default to a smaller, better-looking border size, without sacrificing markers' visibility.
* options: add --osd-bar-border-sizeGuido Cella2023-11-271-6/+1
| | | | | Closes #1484. The default size is smaller than the previous --osd-border-size default value of 3 with the default --osd-bar-h.
* ALL: use new mp_thread abstractionKacper Michajłow2023-11-051-6/+6
|
* build: remove outdated generated directoryDudemanguy2023-07-311-1/+1
| | | | | | | | | | | | | | | | This only existed as essentially a workaround for meson's behavior and to maintain compatibility with the waf build. Since waf put everything in a generated subdirectory, we had to put make a subdirectory called "generated" in the source for meson so stuff could go to the right place. Well now we don't need to do that anymore. Move the meson.build files around so they go in the appropriate place in the subdirectory of the source tree and change the paths of the headers accordingly. A couple of important things to note. 1. mpv.com now gets made in build/player/mpv.com (necessary because of a meson limitation) 2. The macos icon generation path is shortened to TOOLS/osxbundle/icon.icns.inc.
* sub: add --sub-fonts-dir and --osd-fonts-dir optionsFrédéric Brière2023-03-011-1/+1
| | | | | | | | These options make it possible to specify the directory that will be passed to ass_set_fonts_dir(), akin to VLC's `--ssa-fontsdir` and FFmpeg's `fontsdir`. Fixes #8338
* various: drop unused #include "config.h"Thomas Weißschuh2023-02-201-2/+0
| | | | | | Most sources don't need config.h. The inclusion only leads to lots of unneeded recompilation if the configuration is changed.
* command: only avoid redrawing when old and new osd are both hiddenChristoph Heinrich2023-02-111-5/+5
| | | | | | | The `osd-overlay` command didn't trigger a redraw when the overlay was set to hidden. This is fine when the overlay was already hidden before that, but transitioning from not hidden to hidden requires a redraw.
* sub: use Unicode linebreaking for non-ASS subs and OSDOneric2022-09-191-1/+3
| | | | | | | | | | | | ASS must only automatically break at ASCII spaces (\x20), but other subtitle formats might expect more breaking oppurtinities. Especially non-ASS subs in scripts, which typically do not use (ASCII) spaces to seperate words, like e.g. CJK, might overflow the screen if the conversion didn't insert additional linebreaks (ffmpeg does not). Thus try to enable Unicode linebreaking for converted subs and the OSD if libass is new enough. The feature may still be unavailable at runtime if libass wasn't build with Unicode linebreaking support.
* osd_libass: --osd-back-color: apply to the progress barAvi Halachmi (:avih)2021-08-191-0/+16
| | | | | | | This is an artificial background box with the original colors, rendered as a plain rectangle instead of libass's opaque-box. Fixes #9134 (together with the previous commit)
* osd_libass: disable --osd-back-color for the progress barAvi Halachmi (:avih)2021-08-191-0/+8
| | | | | | | This breaks the rendering in various ways, so first workaround is to simply disable the opaque box for the bar. Next commit will add an artificial background box.
* osd_libass: don't use deprecated ass_set_aspect_ratioOneric2020-08-281-2/+2
|
* osd_libass: set ScaledBorderAndShadowOleg Oshmyan2020-07-151-0/+1
| | | | | | | | | | | libass recently switched the default from 1 to 0 for compatibility with ASS scripts that rely on the historical/VSFilter default of 0. libass does attempt to detect and avoid breaking scripts that rely on the historic libass-only default of 1, but it doesn't cover tracks created directly through the API, so set the header explicitly. Fixes https://github.com/mpv-player/mpv/issues/7900.
* build: change filenames of generated fileswm42020-06-041-1/+1
| | | | Force them into a more consistent naming schema.
* video: make OSD/subtitle bitmaps refcounted (sort of)wm42020-04-261-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* command: extend osd-overlay command with bounds reportingwm42020-03-061-7/+50
| | | | | | | | | | | | | | | | | | | | This is more or less a minimal hack to make _some_ text measurement functionality available to scripts. Since libass does not support such a thing, this simply uses the bounding box of the rendered text. This is far from ideal. Problems include: - using a bitmap bounding box - additional memory waste and/or flushing caches - dependency on window size - odd small deviations with different window sizes (run osd-test.lua and resize the window after each timer update; the bounding boxes aren't adjusted in an overly useful way) - inability to query the size _after_ actual rendering But I guess it's a start. Since I'm aware that it's crap, add a threat to the manpage that this may be changed/removed again. For now, I'm interested whether anyone will have use for it in its current form, as it's an often requested feature.
* client API, lua: add new API for setting OSD overlayswm42019-12-231-31/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Replace uses of FFMIN/MAX with MPMIN/MAXwm42019-10-311-5/+4
| | | | And remove libavutil includes where possible.
* options: move most subtitle and OSD rendering options to sub structswm42018-01-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Remove them from the big MPOpts struct and move them to their sub structs. In the places where their fields are used, create a private copy of the structs, instead of accessing the semi-deprecated global option struct instance (mpv_global.opts) directly. This actually makes accessing these options finally thread-safe. They weren't even if they should have for years. (Including some potential for undefined behavior when e.g. the OSD font was changed at runtime.) This is mostly transparent. All options get moved around, but most users of the options just need to access a different struct (changing sd.opts to a different type changes a lot of uses, for example). One thing which has to be considered and could cause potential regressions is that the new option copies must be explicitly updated. sub_update_opts() takes care of this for example. Another thing is that writing to the option structs manually won't work, because the changes won't be propagated to other copies. Apparently the only affected case is the implementation of the sub-step command, which tries to change sub_delay. Handle this one explicitly (osd_changed() doesn't need to be called anymore, because changing the option triggers UPDATE_OSD, and updates the OSD as a consequence). The way the option value is propagated is rather hacky, but for now this will do.
* osd: don't skip leading whitespace on the first line eitherwm42017-11-021-1/+1
| | | | Stupid libass.
* osd: don't strip leading whitespace in messageswm42017-10-301-0/+7
| | | | Do this by replacing the first space after a line break with "\h".
* osd_libass: avoid libass warnings if scripts set ASS text earlywm42017-07-161-19/+29
| | | | | | | | | | | | | | | | Lua scripts can call osd_set_external() early (before the VO window is created and obj->vo_res is filled), in which case the PlayResX field would be set to nonsense, and libass would print a pointless warning. There's an easy and a hard fix: either just go on and pass dummy values to libass (basically like before, just clamp them to avoid the values which make libass print the warning). Or attempt to update the PlayRes field to correct values on rendering (since at rendering time, you always know the screen size and the correct values). Do the latter. Since various things use PlayRes for scaling things, this might still not be fully ideal. This is a general problem with the async scripting interface.
* command: shorten long playlists on OSDwm42017-01-261-5/+23
| | | | | | | | | | | | A hacky, convoluted, half-working mess that attempts to cut off overlong playlists. It does so by relying on the ASS formatting rule that the font size is specified in the virtual PlayResY resolution. This means we can (normally) easily tell how many lines fit on the screen. On the other hand, this does not work if the text is wrapped. This as a kludge until a Better™ solution is available.
* osd: fix OSD redrawing after removing external overlayswm42016-09-201-0/+2
|
* osd: fix OSD getting stuck with --blend-subtitles=yeswm42016-09-161-2/+3
| | | | | | | | | | | | | If --blend-subtitles=yes is given, vo_opengl will call osd_draw() multiple times, once for subtitles, and once for OSD. This meant that the want_redraw flag was reset before the OSD was rendered, which in turn meant that update_osd() was never called. It seems like removing the per-OSD object want_redraw wasn't such a good idea. Fix it by reintroducing such a flag for OSDTYPE_OSD only. Also, the want_redraw flag is now unused, so kill it. Another regression caused by commit 9c9cf125. Fixes #3535.
* osd: slightly simplify update logicwm42016-09-151-2/+2
| | | | | | | | | | | | | | | | Remove the per-part force_redraw flags, and instead make the difference between flagging dirty state and returning it to the player frontend more explicit. The big issue is that 1. the OSD needs to know the dirty state, and it should be cleared strictly when it is re-rendered (force_redraw flag), and 2. the player core needs to be notified once, and the notification must be reset (want_redraw flag). The call in loadfile.c is replaced by making osd_set_sub() set the change flag. Increasing the change flag on dirty state (the force_redraw check in render_object()) should not be needed, because OSD part renderers set it correctly (at least now). Doing this just because someone pointed this out.
* sub: pass preferred OSD format to subtitle rendererswm42016-07-031-2/+2
| | | | | | | | The intention is to let mp_ass_packer_pack() produce different output for the RGBA and LIBASS formats. VOs (or whatever generates the OSD) currently do not signal a preferred format, and this mechanism just exists to switch between RGBA and LIBASS formats correctly, preferring LIBASS if the VO supports it.
* sub: pack libass bitmaps directly in sd_ass.c and osd_libass.cwm42016-06-301-11/+22
| | | | | | | | | | | | | | | | Change all producer of libass images to packing the bitmaps into a single larger bitmap directly when they're output. This is supposed to help working towards refcounted sub bitmaps. This will reduce performance for VOs like vo_xv, but not for vo_opengl. vo_opengl simply will pick up the pre-packed sub bitmaps, and skip packing them again. vo_xv will copy and pack the sub bitmaps unnecessarily - but if we want sub bitmap refcounting, they'd have to be copied anyway. The packing code cannot be removed yet from vo_opengl, because there are certain corner cases that still produce unpackad other sub bitmaps. Actual refcounting will also require more work.
* osd: make osd_ass_0/1 defineswm42016-05-031-6/+3
| | | | So we can concatenate them with strings at compile time.
* osd, lua: manage multiple ASS overlays set with set_osd_ass() callswm42016-03-081-19/+62
| | | | | | | | | | | | | | | | | | | | | | | | | Until now, there was only 1 global ASS overlay that could be set by all scripts. This was often perceived as bug when multiple scripts tried to set their own ASS overlay. This was kind of hard to solve because the script could set its own ASS PlayResX/Y, which makes it impossible to share a single ASS_Renderer for multiple scripts. The OSC unfortunately makes use of this feature (and unfortunately can't be fixed because it's a POS), so we're stuck with this complication. Implement the worst-case solution and fix this by creating separate ASS track and renderer objects for each script that wants to set an ASS overlay. The z-order is decided by the order the scripts set their text first. This is essentially random, unless you do it at script init, and you pass scripts in a specific order. Script initialization is currently serialized (as a feature), so the first loaded script gets lowest Z-order. The Lua script API interestingly remains the same. (And also will remain undocumented, unsupported, and potentially volatile.)
* osd: restructure and move ASS objects into its own structwm42016-03-081-58/+73
| | | | | | All ASS objects used by the OSD renderer go into struct ass_state. Preparation for the following commit.
* osd: refactor how mp_ass_render_frame() is calledwm42016-03-081-4/+7
| | | | | | | | Instead of passing an explicit cache to the function, the res parameter is used. Also, instead of replacing its contents, sub bitmaps are now appended to it (all assuming the format doesn't actually change). This is preparation for the following commits.
* osd, lua: remove weird OSD scalingwm42016-03-071-10/+0
| | | | | | | | | | | | | | | | | | | | | Do not scale OSD mouse input to the ASS OSD script resolution. The original idea of this mechanism was that the user doesn't have to care about the actual resolution of anything, and can just use the OSD resolution consistently. But this made things worse. Remove the implicit scaling, and always use the screen resolution. (Except with --vo=xv, where additional scaling is forced upon everything.) Drop get_osd_resolution(). There is no replacement. Rename get_screen_size() and get_screen_margins() to use "osd" instead of "screen". For anything but --vo=xv these are equivalent, but with --vo=xv the OSD resolution has additional implicit scaling. Add code to osc.lua which emulates the old behavior. Note that none of the changed functions were public API, so implicit breakage of scripts which used it is just going to happen.
* Relicense some non-MPlayer source files to LGPL 2.1 or laterwm42016-01-191-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This covers source files which were added in mplayer2 and mpv times only, and where all code is covered by LGPL relicensing agreements. There are probably more files to which this applies, but I'm being conservative here. A file named ao_sdl.c exists in MPlayer too, but the mpv one is a complete rewrite, and was added some time after the original ao_sdl.c was removed. The same applies to vo_sdl.c, for which the SDL2 API is radically different in addition (MPlayer supports SDL 1.2 only). common.c contains only code written by me. But common.h is a strange case: although it originally was named mp_common.h and exists in MPlayer too, by now it contains only definitions written by uau and me. The exceptions are the CONTROL_ defines - thus not changing the license of common.h yet. codec_tags.c contained once large tables generated from MPlayer's codecs.conf, but all of these tables were removed. From demux_playlist.c I'm removing a code fragment from someone who was not asked; this probably could be done later (see commit 15dccc37). misc.c is a bit complicated to reason about (it was split off mplayer.c and thus contains random functions out of this file), but actually all functions have been added post-MPlayer. Except get_relative_time(), which was written by uau, but looks similar to 3 different versions of something similar in each of the Unix/win32/OSX timer source files. I'm not sure what that means in regards to copyright, so I've just moved it into another still-GPL source file for now. screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but they're all gone.
* mpv_talloc.h: rename from talloc.hDmitrij D. Czarkoff2016-01-111-1/+1
| | | | This change helps avoiding conflict with talloc.h from libtalloc.
* osd: fix and cleanup font style managementwm42015-11-291-48/+59
| | | | | | | | | | | Commit 2b07d3eb merged progbar and OSD text renderer into one ASS_Track, but it confused the styles. Specifically, if both progbar and OSD are visible, the create_ass_track() call made by the progbar code will reset the style adjusted by the OSD text code. Change create_ass_track() not to add any styles. Instead let the caller manage the styles. They are now referenced by name, and lazily added if they don't exist yet. This is also much cleaner.
* osd: use the same ASS_Renderer for OSD text and progbarwm42015-11-281-29/+41
| | | | | | Reduces memory usage and startup times. The implementation is a bit weird, because both OSD parts have conflicting requirements on the used ASS styles.
* player: remove OSD subtitle render pathwm42015-11-171-30/+0
| | | | | | | | | | | | | | | | | | | This was used with --no-sub-ass (aka --no-ass). This option (which is not yet removed) strips all styling from the subtitles, and renders them as plaintext only. For some reason, it originally seemed convenient to reuse all the OSD text rendering code (osd_libass.c). While this was indeed simple, it had a bad influence on the rest of the code. For example, it had to decide whether to go through the OSD code path, or the proper subtitle renderer in sd_ass.c. Kill the OSD subtitle renderer. Reimplement --no-sub-ass and also "secondary" subtitles in sd_ass.c. fill_plaintext() contains some rather minor code duplication with osd_libass.c for setting up a dummy ASS_Event and escaping the stripped text. Since sd_ass.c already has to handle "normal" text subtitles, and has code for stripping ASS tags, this remains all relatively simple. Remove all the unnecessary crap from the rest of the code.
* options: remove --use-text-osdwm42015-10-241-3/+0
|
* osd: delay libass initialization as far as possiblewm42015-09-071-5/+9
| | | | | | | | | | | | Until now, most OSD objects created the associated ASS_Renderer instance as soon as possible, even if nothing was going to be rendered. Maybe this was even intentional. Change this for the sake of lowering resource usage, and strictly initialize ASS_Renderer only when it's really needed. For the OSC, initialization has to be forced, because of the insane mechanism for translating mouse coordinates to OSD coordinates.
* Update license headersMarcin Kurczewski2015-04-131-4/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* osd: force alignment for OSD barwm42015-02-241-1/+2
| | | | | | | | Overwrite the alignment applied by the OSD style. Additionally, remove the initialization of the Alignment field in create_ass_track(); the value is always overwritten by mp_ass_set_style() later. Fixes #1626.
* osd: always reset style paramswm42015-02-241-11/+8
| | | | | | | There was some logic to set certain things on init only. Not sure why this was done (saving some cheap calculations?) - but since the next call would override these style settings by applying the usual subtitle style, I don't think this was intended.
* libass: remove redundant checks for LIBASS_VERSIONBen Boeckel2015-02-241-2/+0
| | | | Since 0.12.1 is the minimum, just assume it in the code too.
* player: add option not to use OSD/fontconfigwm42014-11-251-0/+3
| | | | | | | Makeshift-solution for working around certain fontconfig issues. With --use-text-osd=no, libass and fontconfig won't be initialized, and fontconfig won't block everything with scanning for fonts.
* Add some missing "const"swm42014-10-101-2/+2
| | | | | | | The one in msg.c was mistakenly removed with commit e99a37f6. I didn't actually test the change in ao_sndio.c (but obviously "ap" shouldn't be static).
* command: allow using ASS tags on OSD messageswm42014-09-181-2/+12
| | | | | | | | | | | We don't allow this by default, because it would be silly if random external data (like filenames or file tags) could accidentally trigger them. Add a property that magically disables this ASS tag escaping. Note that malicious input could still disable ASS tag escaping by itself. This would be annoying but harmless.
* Move compat/ and bstr/ directory contents somewhere elsewm42014-08-291-1/+1
| | | | | | | | | bstr.c doesn't really deserve its own directory, and compat had just a few files, most of which may as well be in osdep. There isn't really any justification for these extra directories, so get rid of them. The compat/libav.h was empty - just delete it. We changed our approach to API compatibility, and will likely not need it anymore.
* sub: uglify OSD code path with lockingwm42014-01-181-17/+21
| | | |