summaryrefslogtreecommitdiffstats
path: root/common/common.c
Commit message (Collapse)AuthorAgeFilesLines
* m_property: add `>` for fixed precision floating-point expansionKacper Michajłow2024-03-211-0/+19
| | | | | | | | | | | | | | This enhancement makes it easier to create constant width property expansions, useful for the `--term-status-msg`. Additionally, it changes to `%f` printing with manual zero trimming, which is easier to control than `%g`. With this method, we can directly specify precision, not just significant numbers. This approach also avoids overly high precision for values less than 1, which is not necessary for a generic floating-point print function. A new print helper function is added, which can be used with adjusted precision for specific cases where a different default is needed. This also unifies the code slightly.
* common: add mp_lcm helperNiklas Haas2023-10-191-0/+7
|
* vo: add --video-cropKacper Michajłow2023-08-311-0/+31
| | | | | | Just cropping by VO that works with hwdec. Fixes: #12222
* common: constify mp_rect_equalsKacper Michajłow2023-08-311-1/+1
|
* common: add helper for subtracting rectangleswm42020-05-221-0/+22
| | | | Not sure if generally useful; the following commit uses it.
* common: fix mp_round_next_power_of_2()wm42020-04-101-5/+6
| | | | | | | Who write this dumb shit¹? It didn't handle 1<<31, and was unnecessarily slow. ¹ it was me
* common: add a helper to round up to next power of 2wm42019-11-061-0/+14
| | | | | | This is something relatively frequently needed, and there must be half a dozen ad-hoc implementations in mpv. The next commit uses this, the suspected duplicate implementations are hiding.
* common: add mp_log2()wm42019-10-311-0/+18
| | | | | | | | | | | To be used in the next commit. According to compiler explorer, __builtin_clz is very widely available, and it barely makes sense to provide a fallback. clang also eats this (and identifies at least as GCC 4). Actually, there's doubt that a fast log2 implementation is needed at all (I guess UTF-8 parsing needs it, but something UTF-8-specific would probably make it faster than using log2). So the fallback is just something naive.
* Replace uses of FFMIN/MAX with MPMIN/MAXwm42019-10-311-8/+8
| | | | And remove libavutil includes where possible.
* common: add missing %f time formatwm42018-05-011-0/+1
| | | | | | | | It was documented for --screenshot-template, but apparently never implemented. This value is not explicitly rounded, other than for printf() %f default formatting (which rounds to 6 digits).
* common: round all integer times to millisecondswm42018-05-011-2/+6
| | | | | | | | | This means that a time of 4.5678 is displayed as "00:00:04.568" when the format string is "%H:%M:%S.%T". Likewise, 59.99999 will be displayed as "00:01:00.000". Before this change, the sub-ms times were just truncated. Requested by TheAMM.
* video: rewrite filtering glue codewm42018-01-301-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Get rid of the old vf.c code. Replace it with a generic filtering framework, which can potentially handle more than just --vf. At least reimplementing --af with this code is planned. This changes some --vf semantics (including runtime behavior and the "vf" command). The most important ones are listed in interface-changes. vf_convert.c is renamed to f_swscale.c. It is now an internal filter that can not be inserted by the user manually. f_lavfi.c is a refactor of player/lavfi.c. The latter will be removed once --lavfi-complex is reimplemented on top of f_lavfi.c. (which is conceptually easy, but a big mess due to the data flow changes). The existing filters are all changed heavily. The data flow of the new filter framework is different. Especially EOF handling changes - EOF is now a "frame" rather than a state, and must be passed through exactly once. Another major thing is that all filters must support dynamic format changes. The filter reconfig() function goes away. (This sounds complex, but since all filters need to handle EOF draining anyway, they can use the same code, and it removes the mess with reconfig() having to predict the output format, which completely breaks with libavfilter anyway.) In addition, there is no automatic format negotiation or conversion. libavfilter's primitive and insufficient API simply doesn't allow us to do this in a reasonable way. Instead, filters can use f_autoconvert as sub-filter, and tell it which formats they support. This filter will in turn add actual conversion filters, such as f_swscale, to perform necessary format changes. vf_vapoursynth.c uses the same basic principle of operation as before, but with worryingly different details in data flow. Still appears to work. The hardware deint filters (vf_vavpp.c, vf_d3d11vpp.c, vf_vdpaupp.c) are heavily changed. Fortunately, they all used refqueue.c, which is for sharing the data flow logic (especially for managing future/past surfaces and such). It turns out it can be used to factor out most of the data flow. Some of these filters accepted software input. Instead of having ad-hoc upload code in each filter, surface upload is now delegated to f_autoconvert, which can use f_hwupload to perform this. Exporting VO capabilities is still a big mess (mp_stream_info stuff). The D3D11 code drops the redundant image formats, and all code uses the hw_subfmt (sw_format in FFmpeg) instead. Although that too seems to be a big mess for now. f_async_queue is unused.
* vo_opengl: further GL API use separationwm42017-08-071-0/+6
| | | | | | | | | | | | | | | Move multiple GL-specific things from the renderer to other places like vo_opengl.c, vo_opengl_cb.c, and ra_gl.c. The vp_w/vp_h parameters to gl_video_resize() make no sense anymore, and are implicitly part of struct fbodst. Checking the main framebuffer depth is moved to vo_opengl.c. For vo_opengl_cb.c it always assumes 8. The API user now has to override this manually. The previous heuristic didn't make much sense anyway. The only remaining dependency on GL is the hwdec stuff, which is harder to change.
* common, vo_opengl: add/use helper for formatted strings on the stackwm42017-07-241-0/+9
| | | | | | | | | | | Seems like I really like this C99 idiom. No reason not to generalize it do snprintf(). Introduce mp_tprintf(), which basically this idiom to snprintf(). This macro looks like it returns a string that was allocated with alloca() on the caller site, except it's portable C99/C11. (And unlike alloca(), the result is valid only within block scope.) Use it in 2 places in the vo_opengl code. But it has the potential to make a whole bunch of weird looking code look slightly nicer.
* Initial Android supportJan Ekström2016-02-101-0/+1
| | | | | * Adds an 'android' feature, which is automatically detected. * Android has a broken strnlen, so a wrapper is added from FreeBSD.
* common/common.c: handle utf16 in mp_parse_escapekwkam2016-02-061-1/+12
| | | | Signed-off-by: wm4 <wm4@nowhere>
* 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.
* common: add mp_tag_str() utility functionwm42016-01-111-0/+17
|
* common: allow "\/" as escape sequencewm42016-01-081-1/+2
| | | | | | | | | | | | | mp_parse_escape() is used by the JSON parser in json.c, and JSON allows escaping "/" (solidus). Although it makes no sense, apparently Javascript traditionally allowed that as escape sequence for working around issues with embedding Javascript in HTML. (Or something like this must have been the history of this issue.) Since it's valid in Javascript, it had to be valid in JSON as well, and JSON explicitly specifies it as valid escape. Fixes #2694.
* x11: query ICC profile based on center of windowNiklas Haas2015-04-291-0/+6
| | | | | | | | | | Right now, the default behavior is to pick the numerically lowest screen ID that overlaps the window in any way - but this means that mpv will decide to pick an ICC profile in a pretty arbitrary way even if the window only overlaps another screen by a single pixel. The new behavior is to query it based on the center of the window instead.
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* Do not call strerror()wm42014-11-261-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | ...because everything is terrible. strerror() is not documented as having to be thread-safe by POSIX and C11. (Which is pretty much bullshit, because both mandate threads and some form of thread-local storage - so there's no excuse why implementation couldn't implement this in a thread-safe way. Especially with C11 this is ridiculous, because there is no way to use threads and convert error numbers to strings at the same time!) Since we heavily use threads now, we should avoid unsafe functions like strerror(). strerror_r() is in POSIX, but GNU/glibc deliberately fucks it up and gives the function different semantics than the POSIX one. It's a bit of work to convince this piece of shit to expose the POSIX standard function, and not the messed up GNU one. strerror_l() is also in POSIX, but only since the 2008 standard, and thus is not widespread. The solution is using avlibc (libavutil, by its official name), which handles the unportable details for us, mostly. We avoid some pain.
* common: fix \x-style escapingshdown2014-10-161-1/+1
| | | | This was rejecting correct escapes and accepting incorrect ones.
* 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.
* common: change mp_snprintf_append semanticswm42014-05-051-4/+11
| | | | | | | | Make it more suitable for chaining. This means a function formatting a value to a string using a static buffer can work exactly like mp_snprintf_append itself. Also rename it to mp_snprintf_cat, because that's shorter.
* common: add mp_snprintf_append() utility functionwm42014-04-291-0/+19
|
* common: drop mp_append_utf8_buffer()wm42013-12-301-11/+2
|
* common: simplify and optimize string escape parsingwm42013-12-301-4/+69
| | | | | | | | | | | This code is shared between input.conf parser and option parser. Until now, the performance didn't really matter. But I want to use this code for JSON parsing too, and since JSON will have to be parsed a lot, it should probably try to avoid realloc'ing too much. This commit moves parsing of C-style escaped strings into a common function, and allows using it in a way realloc can be completely avoided, if the already allocated buffer is large enough.
* Split mpvcore/ into common/, misc/, bstr/wm42013-12-171-0/+163