2 #include <Cocoa/Cocoa.h>
4 typedef struct _ThreadArgs ThreadArgs;
15 gst_thread_func (ThreadArgs *args)
18 if (args->is_simple) {
19 ret = ((GstMainFuncSimple) args->main_func) (args->user_data);
21 ret = ((GstMainFunc) args->main_func) (args->argc, args->argv, args->user_data);
24 [NSApp terminate: nil];
29 run_main_with_nsapp (ThreadArgs args)
33 [NSApplication sharedApplication];
34 gst_thread = g_thread_new ("macos-gst-thread", (GThreadFunc) gst_thread_func, &args);
37 return GPOINTER_TO_INT (g_thread_join (gst_thread));
42 * @main_func: (scope async): pointer to the main function to be called
43 * @argc: the amount of arguments passed in @argv
44 * @argv: (array length=argc): an array of arguments to be passed to the main function
45 * @user_data: (nullable): user data to be passed to the main function
47 * Starts an NSApplication on the main thread before calling
48 * the provided main() function on a secondary thread.
50 * This ensures that GStreamer can correctly perform actions
51 * such as creating a GL window, which require a Cocoa main loop
52 * to be running on the main thread.
54 * Do not call this function more than once - especially while
55 * another one is still running - as that will cause unpredictable
56 * behaviour and most likely completely fail.
58 * Returns: the return value of the provided main_func
63 gst_macos_main (GstMainFunc main_func, int argc, char **argv, gpointer user_data)
69 args.main_func = main_func;
70 args.user_data = user_data;
71 args.is_simple = FALSE;
73 return run_main_with_nsapp (args);
77 * gst_macos_main_simple:
78 * @main_func: (scope async): pointer to the main function to be called
79 * @user_data: (nullable): user data to be passed to the main function
81 * Simplified variant of gst_macos_main(), meant to be used with bindings
82 * for languages which do not have to pass argc and argv like C does.
83 * See gst_macos_main() for a more detailed description.
85 * Returns: the return value of the provided main_func
90 gst_macos_main_simple (GstMainFuncSimple main_func, gpointer user_data)
96 args.main_func = main_func;
97 args.user_data = user_data;
98 args.is_simple = TRUE;
100 return run_main_with_nsapp (args);