Two issues were present with the previous implementation for interface
handling.
- Contrary to bin/vlc.c, darwinvlc.m needs to handle the CFRunLoop in
the main thread, but libvlc was released only after the runloop was
terminated, meaning that interfaces could not use the runloop on
close.
- Some application-specific runloop stop code was present to stop the
NSApp for the main macosx.m interface, with conditionals to check
whether the NSApp was started or not. darwinvlc.m shouldn't need to
know whether it needs to do that and should only handle the
termination of its own CFRunLoopRun() call, even if an interface
nests the runloop afterwards. As with the point above, the interface
should terminate its NSApp before darwinvlc terminates its runloop.
This commit reorder the resource deallocation to first remove the
interfaces, by releasing the libvlc instance, and only then destroy the
runloop. It uses previous changes in the macosx interface to handle the
stopping through libvlc_Quit.
By reordering this way, it's now possible to use SIGINT to stop the Qt
interface also.
The handling through GCD was added back then in commit
cc07bce0d2. In that commit,
signal(SIGCHLD, SIG_DFL) was already called to ensure the behavior of
the signal is restored to default handlers.
In `man 3 signal` from the macos manual, it is said that when setting
SIG_IGN for SIGCHLD, the operating system will not create zombie process
and the exit status will be ignored. We do want to avoid creating zombie
process but we also want to have exit status, which means we do indeed
need the SIG_DFL handler here. See also the following commit on the
linux side: 94763831fb.
However, GCD was used to automatically call waitpid() on the process
that are being signalled as closing. Since we're always calling waitpid
when spawning any process, this duplicates the handling. But the clients
are actually using vlc_waitpid which is checking errno != ECHILD, so it
would break as soon as the GCD handler is executed before the
vlc_waitpid call.
Since every cases are explicitely calling vlc_waitpid(), do as linux and
just remove the specific GCD handling.
Co-authored-by: Marvin Scholz <epirat07@gmail.com>
Fixes#29099
Interfaces from libvlc were started from the main thread directly. But
UI inserting their own event loop inside the main runloop like Qt were
taking over the interface insertion. It was preventing other interfaces
to load correctly, required dedicated code to handle the startup in the
Qt interface and it was not possible to exit the interface correctly.
By moving the creation of the interfaces in a dedicated thread, we can
ensure all UI are created and destroyed correctly, but the macosx
interface must now dispatch its own creation into the main thread to
match Cocoa requirement on main thread usage for UI components.
Note that libvlc_new itself must be moved to the intf_queue given that
it starts additional extraintf.
The macosx interface must now start its own NSApp inside the main loop,
via a dispatch call, which simplify the main loop into running the
default main loop.
For posix-style installations, use the defined directories
for libraries and data.
With that, running vlc from the install dirs works fine in principle.
What is left to do currently is to adapt the RPATH to find the
libvlc libraries.
This moves the main loop out of the macosx interface module.
Instead, the open callback only initializes the interface and the
close callback cleans up stuff. The mainloop is now started in
darwinvlc.m. In case the mac interface is not used, a CoreFoundation
mainloop is solely started to wait for termination events.
Additionally, this cleans up darwinvlc.m, and fixes signal
handling, which was dead code so far (in case the interface was used).
Now, GCD is used to catch SIGINT and SIGTERM in order to allow
ordinary shutdown.
refs #14362close#6354
As we do not want to break other os versions, the only way to
select the proper linker is to use another target for osx.
Still, "make install" should produce a binary named "vlc" in the
end, thus the binary is renamed at install stage.
This is the only supported way to terminate an cocoa application and also ensure
that the gui settings are getting saved. Adapted from similar code in the qt
module.
The actions of the hotkeys interface all affect the playlist, the
playlist's input, the playlist's input's vout(s), the playlist's aout
or the interfaces (controller). It has no use outside VLC.
...as for plugins directory. Most of the content is anyway per-process,
either because gettext and interfaces are per-process. The only caller
of the function that is not an interface or gettext is the DVB scanner.
This is even probably a bug.