mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 09:10:36 +00:00
[365/906] Cocoa backend: make sure that nsapp is initialized
gst-launch-0.10 videotestsrc ! tee name=t ! queue ! glimagesink t. ! queue ! glimagesink now works properly on MacOSX
This commit is contained in:
parent
8d6e91838a
commit
e467ea29e9
1 changed files with 47 additions and 30 deletions
|
@ -122,6 +122,7 @@ struct _GstGLWindowPrivate
|
||||||
NSWindow *parent;
|
NSWindow *parent;
|
||||||
NSThread *thread;
|
NSThread *thread;
|
||||||
gboolean running;
|
gboolean running;
|
||||||
|
guint source_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstGLWindow, gst_gl_window, G_TYPE_OBJECT);
|
G_DEFINE_TYPE (GstGLWindow, gst_gl_window, G_TYPE_OBJECT);
|
||||||
|
@ -148,21 +149,58 @@ gst_gl_window_log_handler (const gchar * domain, GLogLevelFlags flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gst_gl_window_nsapp_init (gpointer data)
|
gst_gl_window_nsapp_init (GCond *nsapp_init_cond)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||||
[NSApplication sharedApplication];
|
[NSApplication sharedApplication];
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
|
g_cond_signal (nsapp_init_cond);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gst_gl_window_nsapp_iteration (gpointer data)
|
||||||
|
{
|
||||||
|
NSEvent *event = nil;
|
||||||
|
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
if ([NSThread isMainThread]) {
|
||||||
|
|
||||||
|
while ((event = ([NSApp nextEventMatchingMask:NSAnyEventMask
|
||||||
|
untilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]
|
||||||
|
inMode:NSDefaultRunLoopMode dequeue:YES])) != nil)
|
||||||
|
|
||||||
|
[NSApp sendEvent:event];
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_window_class_init (GstGLWindowClass * klass)
|
gst_gl_window_class_init (GstGLWindowClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
|
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
g_idle_add (gst_gl_window_nsapp_init, NULL);
|
GMutex *nsapp_init_mutex = g_mutex_new ();
|
||||||
|
GCond *nsapp_init_cond = g_cond_new ();
|
||||||
|
|
||||||
|
g_mutex_lock (nsapp_init_mutex);
|
||||||
|
|
||||||
|
g_idle_add ((GSourceFunc) gst_gl_window_nsapp_init, nsapp_init_cond);
|
||||||
|
|
||||||
|
g_cond_wait (nsapp_init_cond, nsapp_init_mutex);
|
||||||
|
g_mutex_unlock (nsapp_init_mutex);
|
||||||
|
|
||||||
|
g_mutex_free (nsapp_init_mutex);
|
||||||
|
g_cond_free (nsapp_init_cond);
|
||||||
|
|
||||||
g_type_class_add_private (klass, sizeof (GstGLWindowPrivate));
|
g_type_class_add_private (klass, sizeof (GstGLWindowPrivate));
|
||||||
|
|
||||||
|
@ -246,6 +284,8 @@ gst_gl_window_new (gint width, gint height, gulong external_gl_context)
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
|
priv->source_id = g_timeout_add_seconds (1, gst_gl_window_nsapp_iteration, priv->internal_win_id);
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +300,8 @@ gst_gl_window_set_external_window_id (GstGLWindow * window, gulong id)
|
||||||
{
|
{
|
||||||
GstGLWindowPrivate *priv = window->priv;
|
GstGLWindowPrivate *priv = window->priv;
|
||||||
|
|
||||||
|
g_source_remove (priv->source_id);
|
||||||
|
|
||||||
if (GSRegisterCurrentThread()) {
|
if (GSRegisterCurrentThread()) {
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
@ -343,26 +385,6 @@ gst_gl_window_draw (GstGLWindow * window)
|
||||||
g_debug ("failed to register current thread, cannot draw");
|
g_debug ("failed to register current thread, cannot draw");
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
gst_gl_window_nsapp_iteration (gpointer data)
|
|
||||||
{
|
|
||||||
NSEvent *event = nil;
|
|
||||||
|
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
|
|
||||||
if ([NSThread isMainThread]) {
|
|
||||||
|
|
||||||
while ((event = ([NSApp nextEventMatchingMask:NSAnyEventMask
|
|
||||||
untilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]
|
|
||||||
inMode:NSDefaultRunLoopMode dequeue:YES])) != nil)
|
|
||||||
[NSApp sendEvent:event];
|
|
||||||
|
|
||||||
[pool release];
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_gl_window_run_loop (GstGLWindow * window)
|
gst_gl_window_run_loop (GstGLWindow * window)
|
||||||
{
|
{
|
||||||
|
@ -373,14 +395,9 @@ gst_gl_window_run_loop (GstGLWindow * window)
|
||||||
g_debug ("begin loop: %lud\n", (gulong) run_loop);
|
g_debug ("begin loop: %lud\n", (gulong) run_loop);
|
||||||
|
|
||||||
if (priv->internal_win_id != nil) {
|
if (priv->internal_win_id != nil) {
|
||||||
while(priv->running) {
|
while(priv->running)
|
||||||
|
|
||||||
[run_loop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
|
[run_loop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
|
||||||
|
|
||||||
if (!priv->parent)
|
|
||||||
g_idle_add (gst_gl_window_nsapp_iteration, priv->internal_win_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
[priv->internal_win_id release];
|
[priv->internal_win_id release];
|
||||||
priv->internal_win_id = nil;
|
priv->internal_win_id = nil;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue