Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use the default GMainContext #88

Merged
merged 1 commit into from
Mar 30, 2023
Merged

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.

None yet

2 participants