1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-30 23:38:10 +00:00

input: allow passing FDs to --input-file

This commit is contained in:
wm4 2015-02-26 22:04:43 +01:00
parent a22de99544
commit 7b02c79a23
2 changed files with 15 additions and 3 deletions

View File

@ -2318,6 +2318,9 @@ Input
get replies or events. Use ``--input-unix-socket`` for something
bi-directional. On MS Windows, JSON commands are not available.
This can also specify a direct file descriptor with ``fd://N`` (UNIX only).
In this case, JSON replies will be written if the FD is writable.
See also ``--slave-broken``.
.. note::

View File

@ -678,10 +678,20 @@ static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path)
int mode = O_RDONLY;
int client_fd = -1;
bool close_client_fd = true;
bool writable = false;
if (strcmp(path, "/dev/stdin") == 0) { // for symmetry with Linux
client_fd = STDIN_FILENO;
close_client_fd = false;
} else if (strncmp(path, "fd://", 5) == 0) {
char *end = NULL;
client_fd = strtol(path + 5, &end, 0);
if (!end || end == path + 5 || end[0]) {
MP_ERR(ctx, "Invalid FD: %s\n", path);
return;
}
close_client_fd = false;
writable = true; // maybe
} else {
// Use RDWR for FIFOs to ensure they stay open over multiple accesses.
struct stat st;
@ -690,7 +700,7 @@ static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path)
client_fd = open(path, mode);
}
if (client_fd < 0) {
MP_ERR(ctx, "Could not open pipe at '%s'\n", path);
MP_ERR(ctx, "Could not open '%s'\n", path);
return;
}
@ -699,8 +709,7 @@ static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path)
.client_name = "input-file",
.client_fd = client_fd,
.close_client_fd = close_client_fd,
.writable = false,
.writable = writable,
};
ipc_start_client(ctx, client);