1
mirror of https://github.com/mpv-player/mpv synced 2024-11-07 01:47:00 +01:00

command: allow passing memory addresses to overlay_add

For the sake of libmpv. Might make things much easier for the user,
especially on Windows. On the other hand, it's a bit sketchy that a
command exists that makes the player access arbitrary memory regions.
(But do note that input commands are not meant to be "secure" and never
were - for example, there's the "run" command, which obviously allows
running random shell commands.)
This commit is contained in:
wm4 2014-10-03 01:24:48 +02:00
parent 3e899b102e
commit 4332105352
2 changed files with 16 additions and 0 deletions

View File

@ -456,6 +456,16 @@ Input Commands that are Possibly Subject to Change
random points. Instead, call ``overlay_add`` again (preferably with a
different memory region to prevent tearing).
It is also possible to pass a raw memory address for use as bitmap memory
by passing a memory address as integer prefixed with a ``&`` character.
Passing the wrong thing here will crash the player. The ``offset`` parameter
is not used and must be 0. This mode might be useful for use with libmpv.
On Windows, currently only raw memory addresses work. File mapping is not
implemented because a ``mmap`` compatibility layer is missing, and because
this kind of shared memory method would perhaps not be overly useful on
Windows.
``offset`` is the offset of the first pixel in the source file. It is
passed directly to ``mmap`` and is subject to certain restrictions
(see ``man mmap`` for details). In particular, this value has to be a

View File

@ -3326,6 +3326,12 @@ static int overlay_add(struct MPContext *mpctx, int id, int x, int y,
if (!file[1] || end[0])
fd = -1;
close_fd = false;
} else if (file[0] == '&') {
char *end;
unsigned long long addr = strtoull(&file[1], &end, 0);
if (!file[1] || end[0])
addr = 0;
p = (void *)(uintptr_t)addr;
} else {
fd = open(file, O_RDONLY | O_BINARY | O_CLOEXEC);
}