Skip to content

Conversation

gnome-mpv
Copy link
Contributor

@gnome-mpv gnome-mpv commented Mar 29, 2023

Using the default GMainContext may cause deadlocks when mpv-mpris is loaded in an mpv frontend that use GLib. See celluloid-player/celluloid#486 for an example of this happening in Celluloid.

Minimal reproducer:

// Build with: gcc `pkg-config --cflags --libs glib-2.0 mpv` test.c  -o test

#include <glib.h>
#include <stdio.h>
#include <mpv/client.h>

struct UserData
{
	mpv_handle *mpv;
	GMainLoop *loop;
};

gboolean
handle_timeout(struct UserData *user_data)
{
	mpv_terminate_destroy(user_data->mpv);
	g_main_loop_quit(user_data->loop);

	return G_SOURCE_REMOVE;
}

int
main(int argc, char **argv)
{
	mpv_handle *mpv = mpv_create();
	mpv_initialize(mpv);
	mpv_command_string(mpv, "load-script ./mpris.so");

	GMainLoop *loop = g_main_loop_new(NULL, FALSE);

	struct UserData user_data = {.mpv = mpv, .loop = loop};
	g_timeout_add(1000, G_SOURCE_FUNC(handle_timeout), &user_data);

	puts("Quitting in 1 second...");
	g_main_loop_run(loop);

	g_main_loop_unref(loop);

	return 0;
}

Using the default GMainContext may cause deadlocks when mpv-mpris is
loaded in an mpv frontend that use GLib.
@hoyon hoyon merged commit c760491 into hoyon:master Mar 30, 2023
@hoyon
Copy link
Owner

hoyon commented Mar 30, 2023

Thanks!

@gnome-mpv gnome-mpv deleted the own-context branch March 30, 2023 18:24
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Apr 4, 2023
https://build.opensuse.org/request/show/1077054
by user mia + dimstar_suse
- Update to 1.0
  * rename album fields to match MusicBrainz internal names
    gh#hoyon/mpv-mpris#81
  * Fix string leaks in property change handler
    gh#hoyon/mpv-mpris#84
  * Makefile: Allow to append CFLAGS / LDFLAGS from environment.
    gh#hoyon/mpv-mpris#87
  * Do not use the default GMainContext
    gh#hoyon/mpv-mpris#88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants