From 81e15d22c02b14b2a58436b0dd8d9d58048ff94f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 10 Jan 2015 15:51:16 +0100 Subject: [PATCH] osxvideosink: Disable hack for NSApp iteration with a special #define The hack causes deadlocks and other interesting problems and it really can only be fixed properly inside GLib. We will include a patch for GLib in our builds for now that handles this, and hopefully at some point GLib will also merge a proper solution. A proper solution would first require to refactor the polling in GMainContext to only provide a single fd, e.g. via epoll/kqueue or a thread like the one added by our patch. Then this single fd could be retrieved from the GMainContext and directly integrated into a NSRunLoop. https://bugzilla.gnome.org/show_bug.cgi?id=741450 https://bugzilla.gnome.org/show_bug.cgi?id=704374 --- sys/osxvideo/cocoawindow.h | 2 ++ sys/osxvideo/cocoawindow.m | 2 ++ sys/osxvideo/osxvideosink.h | 2 ++ sys/osxvideo/osxvideosink.m | 19 ++++++++++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sys/osxvideo/cocoawindow.h b/sys/osxvideo/cocoawindow.h index a7e7f98..9355d3c 100644 --- a/sys/osxvideo/cocoawindow.h +++ b/sys/osxvideo/cocoawindow.h @@ -70,7 +70,9 @@ struct _GstOSXImage; - (void) addToSuperview: (NSView *)superview; - (void) removeFromSuperview: (id)unused; - (void) setNavigation: (GstNavigation *) nav; +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION - (void) setMainThread: (NSThread *) thread; +#endif @end diff --git a/sys/osxvideo/cocoawindow.m b/sys/osxvideo/cocoawindow.m index 03bd4c1..57d19a9 100644 --- a/sys/osxvideo/cocoawindow.m +++ b/sys/osxvideo/cocoawindow.m @@ -648,9 +648,11 @@ const gchar* gst_keycode_to_keyname(gint16 keycode) [self reshape]; } +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION - (void) setMainThread: (NSThread *) thread { mainThread = thread; } +#endif - (void) haveSuperviewReal:(NSMutableArray *)closure { BOOL haveSuperview = [self superview] != nil; diff --git a/sys/osxvideo/osxvideosink.h b/sys/osxvideo/osxvideosink.h index 8f6bbd0..2bf5d25 100644 --- a/sys/osxvideo/osxvideosink.h +++ b/sys/osxvideo/osxvideosink.h @@ -130,8 +130,10 @@ GType gst_osx_video_sink_get_type(void); -(void) showFrame: (GstBufferObject*) buf; -(void) setView: (NSView*) view; + (BOOL) isMainThread; +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION -(void) nsAppThread; -(void) checkMainRunLoop; +#endif @end G_END_DECLS diff --git a/sys/osxvideo/osxvideosink.m b/sys/osxvideo/osxvideosink.m index aa428f0..486ae7a 100644 --- a/sys/osxvideo/osxvideosink.m +++ b/sys/osxvideo/osxvideosink.m @@ -43,11 +43,11 @@ GST_DEBUG_CATEGORY (gst_debug_osx_video_sink); #define GST_CAT_DEFAULT gst_debug_osx_video_sink +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION #include extern void _CFRunLoopSetCurrent (CFRunLoopRef rl); extern pthread_t _CFMainPThread; - - +#endif static GstStaticPadTemplate gst_osx_video_sink_sink_template_factory = GST_STATIC_PAD_TEMPLATE ("sink", @@ -72,9 +72,13 @@ enum }; static void gst_osx_video_sink_osxwindow_destroy (GstOSXVideoSink * osxvideosink); + +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION static GMutex _run_loop_check_mutex; static GMutex _run_loop_mutex; static GCond _run_loop_cond; +#endif + static GstOSXVideoSinkClass *sink_class = NULL; static GstVideoSinkClass *parent_class = NULL; @@ -98,6 +102,7 @@ gst_osx_video_sink_call_from_main_thread(GstOSXVideoSink *osxvideosink, [pool release]; } +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION /* Poll for cocoa events */ static void run_ns_app_loop (void) { @@ -215,6 +220,7 @@ static void gst_osx_video_sink_stop_cocoa_loop (GstOSXVideoSink * osxvideosink) { } +#endif /* This function handles osx window creation */ static gboolean @@ -245,9 +251,10 @@ gst_osx_video_sink_osxwindow_create (GstOSXVideoSink * osxvideosink, gint width, rect.size.height = (float) osxwindow->height; osxwindow->gstview =[[GstGLView alloc] initWithFrame:rect]; - +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION gst_osx_video_sink_run_cocoa_loop (osxvideosink); [osxwindow->gstview setMainThread:sink_class->ns_app_thread]; +#endif if (osxvideosink->superview == NULL) { GST_INFO_OBJECT (osxvideosink, "emitting prepare-xwindow-id"); @@ -290,7 +297,9 @@ gst_osx_video_sink_osxwindow_destroy (GstOSXVideoSink * osxvideosink) osxvideosink->osxvideosinkobject, @selector(destroy), (id) nil, YES); GST_OBJECT_UNLOCK (osxvideosink); +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION gst_osx_video_sink_stop_cocoa_loop (osxvideosink); +#endif [pool release]; } @@ -764,6 +773,8 @@ gst_osx_video_sink_get_type (void) NSRect rect; unsigned int mask; + [NSApplication sharedApplication]; + osxwindow->internal = TRUE; mask = NSTitledWindowMask | @@ -929,6 +940,7 @@ no_texture_buffer: [pool release]; } +#ifndef GSTREAMER_GLIB_COCOA_NSAPPLICATION -(void) nsAppThread { NSAutoreleasePool *pool; @@ -965,6 +977,7 @@ no_texture_buffer: g_cond_signal (&_run_loop_cond); g_mutex_unlock (&_run_loop_mutex); } +#endif @end -- 2.7.4