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
This commit is contained in:
Sebastian Dröge 2015-01-10 15:51:16 +01:00
parent 0dd46accf6
commit 81e15d22c0
4 changed files with 22 additions and 3 deletions

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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 <pthread.h>
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