Repository navigation
player/main: implement single instance mode - #18932
guidocella wants to merge 10 commits into
Conversation
kasper93
left a comment
There was a problem hiding this comment.
umpv should be rewrite to call mpv with appropriate options and remove the comunication part that lives in mpv now.
|
|
||
| ``--single-instance=<yes|no>`` | ||
| If another mpv instance is listening on the ``--input-ipc-server`` path, | ||
| append the files to its playlist with ``loadfile <file> append-play`` and |
There was a problem hiding this comment.
This has to be configurable, one may want to append-play other replace and so on.
There was a problem hiding this comment.
Funny cause I had all loadfile options but removed them because they didn't seem necessary 😂 But do you want to settle #17458 first so this won't have to be changed later as well?
|
|
||
| Put this in ``mpv.conf`` to play every file in the same window:: | ||
|
|
||
| input-ipc-server=/tmp/mpv-socket |
There was a problem hiding this comment.
It shouldn't steal the ipc socket. It should be dedicated socket. Most importantly, we shouldn't make every mpv instance run unrestricted ipc socket. It should be either dedicated secure and restricted ipc or some other solution.
There was a problem hiding this comment.
What if I want a single instance for videos and one for music that use different sockets?
There was a problem hiding this comment.
Then you configure different "single instance" socket.
Why is umpv still needed? |
For backward compatibility for users who want to use umpv. |
That would break it for Linux users who download it without using git master though. |
3ae0e7c to
4ec4830
Compare
Why does this matter? |
kasper93
left a comment
There was a problem hiding this comment.
Instead of generating loadfile commands, how about reusing the drag and drop loader? Split handle_dnd() in input/dnd.c into the --drag-and-drop handling and a loader that takes files and an action. The second instance sends {"action": "append", "files": [...]}, and the single-instance calls the code with that.
This will cut a lot of duplication.
| the FD value is the same (but the string is different e.g. due to | ||
| whitespace). This is not a bug. | ||
|
|
||
| ``--single-instance=<no|replace|append|append-play|insert-next|insert-next-play>`` |
There was a problem hiding this comment.
I think options could be split into --instance-name=<...> and --on-instance-action or some better name, not sure what works. Then we could have multiple multiple instances for music/images.
Move loading files with an action into mp_load_files(), so that it can be reused for files received from other instances.
bb75f27 to
1ed4079
Compare
|
You also need to split the commits into separate changes. There is a lot different files and functions changes in "add" commit. |
Like node_map_add_string(), but for arrays.
Create and bind the socket in mp_init_ipc() instead of in the IPC thread, so that the caller knows whether it is listening. Factor building the socket address and creating the listening socket out of the thread, so that they can be reused for other sockets.
Create the first pipe instance in mp_init_ipc() instead of in the IPC thread, so that the caller knows whether it is listening. Since creating the first instance with FILE_FLAG_FIRST_PIPE_INSTANCE is atomic, this can also be used to determine which of several processes listens. Factor out building the pipe path, creating pipe instances and starting the server, so that they can be reused for other pipes.
This will be used to check the user of the process at the other end of a pipe.
Load the files in a message received from another instance using the drag and drop loader.
If another instance with the same name is running, send it a message with files to load. Otherwise, listen for messages from instances started later. The socket is created in $XDG_RUNTIME_DIR, or in the cache directory if it is not set. Both ends verify that the peer runs as the same user. A lock file serializes startup, so that of multiple instances started at the same time, e.g. by a file manager opening several files, only one listens and the others send their files to it. Nothing but a list of files to load is accepted over the socket.
Use a named pipe unique to the user and session, with the existing restricted security descriptor. Creating its first instance is atomic, so of multiple instances started at the same time only one listens. The client verifies that the server runs as the same user, and doesn't allow it to impersonate the client.
If another instance with the same --instance-name is running, send it the files and exit instead of playing them. Otherwise, accept files from instances with the same name started later, and load them like dropped files according to --instance-action. Different names allow e.g. separate instances for videos and music. This doesn't need --input-ipc-server, so it works without further configuration and can be enabled by default.
mpv can now send files to an existing instance by itself, so just run it with --instance-name=umpv. This also fixes files being played in separate instances when umpv is run multiple times at once. UMPV_SOCKET_DIR is no longer used.
1ed4079 to
edac9d1
Compare
on #18225 (and #17921) we argued about not dissecting DnD for loading files. did the opinion on that change now? |
If another instance is listening on the --input-ipc-server path, send it the files with loadfile append-play and exit instead of playing them.
Add mp_ipc_send() to connect to an IPC server and send it commands. It waits until the server has processed them before disconnecting, because the Unix server stops processing commands when it can't write their replies.
Fixes #18897.
Written by Claude Opus 5.5. Not tested on Windows.