osxvideosink: Make osxvideosink use the non-deprecated threading api from glib.

https://bugzilla.gnome.org/show_bug.cgi?id=682446
This commit is contained in:
Martin Ertsaas 2012-08-22 11:21:38 +02:00 committed by Tim-Philipp Müller
parent ef9c81d495
commit 7fcbf88ced
2 changed files with 25 additions and 29 deletions

View file

@ -85,13 +85,13 @@ struct _GstOSXVideoSink {
NSView *superview; NSView *superview;
NSThread *ns_app_thread; NSThread *ns_app_thread;
#ifdef RUN_NS_APP_THREAD #ifdef RUN_NS_APP_THREAD
GMutex *loop_thread_lock; GMutex loop_thread_lock;
GCond *loop_thread_cond; GCond loop_thread_cond;
#else #else
guint cocoa_timeout; guint cocoa_timeout;
#endif #endif
GMutex *mrl_check_lock; GMutex mrl_check_lock;
GCond *mrl_check_cond; GCond mrl_check_cond;
gboolean mrl_check_done; gboolean mrl_check_done;
gboolean main_run_loop_running; gboolean main_run_loop_running;
gboolean app_started; gboolean app_started;

View file

@ -134,18 +134,17 @@ gst_osx_videosink_check_main_run_loop (GstOSXVideoSink *sink)
* be awaken by this function. */ * be awaken by this function. */
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
GstOSXVideoSinkObject * object = (GstOSXVideoSinkObject *) sink->osxvideosinkobject; GstOSXVideoSinkObject * object = (GstOSXVideoSinkObject *) sink->osxvideosinkobject;
GTimeVal abstime; gint64 abstime;
g_mutex_lock(sink->mrl_check_lock); g_mutex_lock (&sink->mrl_check_lock);
[object performSelectorOnMainThread: [object performSelectorOnMainThread:
@selector(checkMainRunLoop) @selector(checkMainRunLoop)
withObject:nil waitUntilDone:NO]; withObject:nil waitUntilDone:NO];
/* Wait 100 ms */ /* Wait 100 ms */
g_get_current_time (&abstime); abstime = g_get_monotonic_time () + 100 * 1000;
g_time_val_add (&abstime, 100 * 1000); is_running = g_cond_wait_until (&sink->mrl_check_cond,
is_running = g_cond_timed_wait(sink->mrl_check_cond, &sink->mrl_check_lock, abstime);
sink->mrl_check_lock, &abstime); g_mutex_unlock (&sink->mrl_check_lock);
g_mutex_unlock(sink->mrl_check_lock);
[pool release]; [pool release];
} }
@ -188,10 +187,10 @@ gst_osx_video_sink_run_cocoa_loop (GstOSXVideoSink * sink )
selector:@selector(nsAppThread) object:nil]; selector:@selector(nsAppThread) object:nil];
[sink->ns_app_thread start]; [sink->ns_app_thread start];
g_mutex_lock (sink->loop_thread_lock); g_mutex_lock (&sink->loop_thread_lock);
while (!sink->app_started) while (!sink->app_started)
g_cond_wait (sink->loop_thread_cond, sink->loop_thread_lock); g_cond_wait (&sink->loop_thread_cond, &sink->loop_thread_lock);
g_mutex_unlock (sink->loop_thread_lock); g_mutex_unlock (&sink->loop_thread_lock);
#else #else
/* assume that there is a GMainLoop and iterate the main runloop from there /* assume that there is a GMainLoop and iterate the main runloop from there
*/ */
@ -505,11 +504,11 @@ gst_osx_video_sink_init (GstOSXVideoSink * sink)
sink->superview = NULL; sink->superview = NULL;
sink->osxvideosinkobject = [[GstOSXVideoSinkObject alloc] initWithSink:sink]; sink->osxvideosinkobject = [[GstOSXVideoSinkObject alloc] initWithSink:sink];
#ifdef RUN_NS_APP_THREAD #ifdef RUN_NS_APP_THREAD
sink->loop_thread_lock = g_mutex_new (); g_mutex_init (&sink->loop_thread_lock);
sink->loop_thread_cond = g_cond_new (); g_cond_init (&sink->loop_thread_cond);
#endif #endif
sink->mrl_check_lock = g_mutex_new (); g_mutex_init (&sink->mrl_check_lock);
sink->mrl_check_cond = g_cond_new (); g_cond_init (&sink->mrl_check_cond);
sink->mrl_check_done = FALSE; sink->mrl_check_done = FALSE;
sink->main_run_loop_running = FALSE; sink->main_run_loop_running = FALSE;
sink->app_started = FALSE; sink->app_started = FALSE;
@ -540,11 +539,8 @@ gst_osx_video_sink_finalize (GObject *object)
if (osxvideosink->osxvideosinkobject) if (osxvideosink->osxvideosinkobject)
[(GstOSXVideoSinkObject*)(osxvideosink->osxvideosinkobject) release]; [(GstOSXVideoSinkObject*)(osxvideosink->osxvideosinkobject) release];
if (osxvideosink->mrl_check_lock) g_mutex_clear (&osxvideosink->mrl_check_lock);
g_mutex_free (osxvideosink->mrl_check_lock); g_cond_clear (&osxvideosink->mrl_check_cond);
if (osxvideosink->mrl_check_cond)
g_cond_free (osxvideosink->mrl_check_cond);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -917,10 +913,10 @@ gst_osx_video_sink_get_type (void)
[NSApplication sharedApplication]; [NSApplication sharedApplication];
[NSApp finishLaunching]; [NSApp finishLaunching];
g_mutex_lock (sink->loop_thread_lock); g_mutex_lock (&sink->loop_thread_lock);
sink->app_started = TRUE; sink->app_started = TRUE;
g_cond_signal (sink->loop_thread_cond); g_cond_signal (&sink->loop_thread_cond);
g_mutex_unlock (sink->loop_thread_lock); g_mutex_unlock (&sink->loop_thread_lock);
/* run the loop */ /* run the loop */
run_ns_app_loop (); run_ns_app_loop ();
@ -931,9 +927,9 @@ gst_osx_video_sink_get_type (void)
-(void) checkMainRunLoop -(void) checkMainRunLoop
{ {
g_mutex_lock(osxvideosink->mrl_check_lock); g_mutex_lock (&osxvideosink->mrl_check_lock);
g_cond_signal(osxvideosink->mrl_check_cond); g_cond_signal (&osxvideosink->mrl_check_cond);
g_mutex_unlock(osxvideosink->mrl_check_lock); g_mutex_unlock (&osxvideosink->mrl_check_lock);
} }
@end @end