sys/osxvideo/osxvideosink.m (gst_osx_video_sink_osxwindow_destroy)

Original commit message from CVS:
2008-03-18  Andy Wingo  <wingo@pobox.com>

* sys/osxvideo/osxvideosink.m (gst_osx_video_sink_osxwindow_destroy)
(gst_osx_video_sink_osxwindow_new, cocoa_event_loop):
* sys/osxvideo/osxvideosink.h (struct _GstOSXVideoSink): If we
need to run an event loop, do so in a task instead of assuming
that there will be a GMainLoop. Fixes #523134.
This commit is contained in:
Andy Wingo 2008-03-18 11:50:08 +00:00
parent a6019fc0bf
commit a6267f383e
2 changed files with 19 additions and 11 deletions

View file

@ -76,6 +76,8 @@ struct _GstOSXVideoSink {
gint fps_n; gint fps_n;
gint fps_d; gint fps_d;
GstTask *event_task;
/* Unused */ /* Unused */
gint pixel_width, pixel_height; gint pixel_width, pixel_height;

View file

@ -111,34 +111,33 @@ static GstVideoSinkClass *parent_class = NULL;
/* cocoa event loop - needed if not run in own app */ /* cocoa event loop - needed if not run in own app */
gint static void
cocoa_event_loop (GstOSXVideoSink * vsink) cocoa_event_loop (GstOSXVideoSink * vsink)
{ {
NSAutoreleasePool *pool; NSAutoreleasePool *pool;
gboolean ret = TRUE;
GST_DEBUG_OBJECT (vsink, "Entering event loop"); GST_DEBUG_OBJECT (vsink, "Entering event loop");
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
if ([NSApp isRunning]) { while ([NSApp isRunning]) {
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast] untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode dequeue:YES ]; inMode:NSDefaultRunLoopMode dequeue:YES ];
if ( event != nil ) { if ( event == nil ) {
g_usleep (100);
break;
} else {
switch ([event type]) { switch ([event type]) {
default: //XXX Feed me please default: //XXX Feed me please
[NSApp sendEvent:event]; [NSApp sendEvent:event];
break; break;
} }
/* loop */
} }
} }
[pool release]; [pool release];
GST_DEBUG_OBJECT (vsink, "Leaving event loop with ret : %d", ret);
return ret;
} }
static NSString * static NSString *
@ -281,8 +280,9 @@ gst_osx_video_sink_osxwindow_new (GstOSXVideoSink * osxvideosink, gint width,
[NSApp setDelegate:[[GstAppDelegate alloc] init]]; [NSApp setDelegate:[[GstAppDelegate alloc] init]];
[NSApp setRunning]; [NSApp setRunning];
// insert event dispatch in the glib main loop osxvideosink->event_task = gst_task_create ((GstTaskFunction)cocoa_event_loop,
g_idle_add ((GSourceFunc) cocoa_event_loop, osxvideosink); osxvideosink);
gst_task_start (osxvideosink->event_task);
} else { } else {
GstStructure *s; GstStructure *s;
GstMessage *msg; GstMessage *msg;
@ -323,6 +323,12 @@ gst_osx_video_sink_osxwindow_destroy (GstOSXVideoSink * osxvideosink,
[osxwindow->pool release]; [osxwindow->pool release];
if (osxvideosink->event_task) {
gst_task_join (osxvideosink->event_task);
gst_object_unref (osxvideosink->event_task);
osxvideosink->event_task = NULL;
}
g_free (osxwindow); g_free (osxwindow);
} }