Commits

Thijs Alkemade committed 313cad9

Silence some warnings. Change the CFRunloop based code to libdispatch. According to my understanding of this code, it should work in the same way, but I'm not 100% sure of that.

Comments (0)

Files changed (1)

Plugins/Purple Service/adiumPurpleMedia.m

 #include <gst/gststructure.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <pthread.h>
-
-
-typedef struct _AIGstBusSourceStruct AIGstBusSource;
-
-struct _AIGstBusSourceStruct {
-	CFRunLoopRef m_loop;
-	CFRunLoopSourceRef m_source;
-	CFRunLoopObserverRef m_observer;
-	pthread_t m_thread_id;
-	GstBus *bus;
-	GstPipeline *pipeline;
-	bool inited;
-};
 
 GstElement *osxvideosink;
 NSWindow* remote_window = NULL;
 NSWindow* local_window = NULL;
 
-
-void adium_gst_bus_observer_cb (CFRunLoopObserverRef observer,CFRunLoopActivity activity, void *info) {
-	printf("adium_media_bus_observer_cb: called before run loop sleeps\n");
-	AIGstBusSource *source = (AIGstBusSource *) info;
-	CFRetain(source->m_source);
-	if(gst_bus_have_pending(source->bus)) { 
-		printf("adium_media_bus_observer_cb: messages on bus, signalling source\n");
-		CFRunLoopSourceSignal(source->m_source); // signal the source before the run loop goes to sleep again
-	}
-	CFRelease(source->m_source);
-}
-
-
-
 void adium_media_print_pipeline_latency(GstPipeline *pipeline) {
     //  prints out latency
 	GstQuery *q = gst_query_new_latency();
 	GstIterator *iterator = gst_bin_iterate_sorted(GST_BIN(pipeline));
 	bool done = FALSE;
 	while(!done) {
-		switch(gst_iterator_next(iterator, &cur_element)) {
+		switch(gst_iterator_next(iterator, (gpointer *)&cur_element)) {
 				
 			case GST_ITERATOR_OK:
 				printf("%s\n", gst_element_get_name(cur_element));
 				done = TRUE;
 
 				break;
+			case GST_ITERATOR_RESYNC:
+				printf("GST_ITERATOR_RESYNC\n");
 				
+				break;
 		}
 	}
-		
-	
 }
 
-void adium_media_bus_event_cb(void *info) {
-    // callback for adium_media_bus_event_cb
-    // will get called by the main loop every time a media bus event is fired
-
-	AIGstBusSource *source = (AIGstBusSource *) info;
-	CFRetain(source->m_source);
-	GstMessage *message;
-	
-    // pop EVERY pending message off the bus using thread safe gst_bus_pop and gst_bus_have_pending
-	while(gst_bus_have_pending(source->bus)) {
-		message = gst_bus_pop(source->bus);
-		
-		if(message != NULL) {
-			if (gst_structure_has_name(message->structure, "have-ns-view")) {
-				AILogWithSignature(@"adium_media_bus_event_cb: called to handle new message %s", gst_structure_get_name(message->structure));
-			} else {
-				gst_bus_async_signal_func(source->bus, message, NULL); // dispatch event to all objects hooked up to this kind of message
-			}
-            
-        }
-		
-		gst_message_unref(message);
-		
-	}
-
-	CFRelease(source->m_source);
-
-	
-}
-
-
 GstBusSyncReply
 adium_bus_sync_signal_handler (GstBus * bus, GstMessage * message, gpointer data) {
     // adium_bus_sync_signal_handler is called whenever a synchronous event occurs on ANY thread
-    // it then pushes the event onto the bus, signals the run source, and wakes up the main thread by calling CFRunLoopWakeup
-	AIGstBusSource *source = (AIGstBusSource *) data;
-	CFRetain(source->m_source);
+    // it then handles the message asynchronously using libdispatch on the main queue
+	dispatch_queue_t queue = (dispatch_queue_t)data;
+	dispatch_retain(queue);
+	
+	gst_object_ref(bus);
 	
 	if(gst_bus_sync_signal_handler(bus, message, data) != GST_BUS_DROP) {
-			g_mutex_lock (bus->queue_lock);
-			g_queue_push_tail (bus->queue, message);
-//			printf("posting message %s type %d thread %d main %d\n", gst_structure_get_name(message->structure), message->type, pthread_self(), source->m_thread_id);
-			// signal the source to fire
-	
-			g_mutex_unlock (bus->queue_lock);
-			CFRunLoopSourceSignal (source->m_source);	
-			CFRunLoopWakeUp (source->m_loop);
-
-
+		dispatch_async(queue, ^{
+			if (message != NULL) {
+				if (gst_structure_has_name(message->structure, "have-ns-view")) {
+					AILogWithSignature(@"Handing have-ns-view");
+				}
+				gst_bus_async_signal_func(bus, message, NULL);
+			}
+			
+			gst_message_unref(message);
+			gst_object_unref(bus);
+		});
 	}
 
-	CFRelease(source->m_source);
+	dispatch_release(queue);
+	
 	return GST_BUS_DROP; // we've already done everything that gst_bus_post does
 }
 
 
 
-void adium_add_media_bus_source(GstBus *bus, PurpleMedia *media, PurpleMediaManager *manager) {
-    // adium_add_media_bus_source creates an asynchronous run loop source which calls adium_media_bus_event_cb every time
-    // a media bus event is fired.
-	AIGstBusSource *source = (AIGstBusSource *) malloc(sizeof(AIGstBusSource));
-
-	CFRunLoopSourceContext *ctx = (CFRunLoopSourceContext *) malloc(sizeof(CFRunLoopSourceContext));
-	CFRunLoopObserverContext *obs_ctx = (CFRunLoopObserverContext *) malloc(sizeof(CFRunLoopObserverContext));
+static void
+adium_add_media_bus_source(GstBus *bus, PurpleMedia *media, PurpleMediaManager *manager)
+{
+	dispatch_queue_t queue = dispatch_queue_create("im.adium.gstreamer.BusQueue", NULL);
+	dispatch_set_target_queue(queue, dispatch_get_main_queue());
 	
-	ctx->info = source;
-	ctx->version = 0;
-	ctx->retain = NULL;
-	ctx->release = NULL;
-	ctx->copyDescription = NULL;
-	ctx->equal = NULL;
-	ctx->hash = NULL;
-	ctx->schedule = NULL;
-	ctx->cancel = NULL;
-	ctx->perform = adium_media_bus_event_cb;
-	
-	obs_ctx->info = source;
-	obs_ctx->version = 0;
-	obs_ctx->retain = NULL;
-	obs_ctx->release = NULL;
-	obs_ctx->copyDescription = NULL;
-	
-	source->m_loop = CFRunLoopGetCurrent();
-	source->m_thread_id = pthread_self();
-	source->bus =bus;
-	source->pipeline = purple_media_manager_get_pipeline(manager);
-	source->inited = false;
-	source->m_source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, ctx);
-	source->m_observer = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, true, 0, adium_gst_bus_observer_cb, obs_ctx);
-	
-	CFRunLoopAddSource(source->m_loop, source->m_source, kCFRunLoopDefaultMode);
-
-	
-	CFRelease(source->m_source);
-		
-	gst_bus_set_sync_handler(bus, NULL, NULL); // for some reason you can't just replace the sync signal handlerr
-	gst_bus_set_sync_handler(bus, adium_bus_sync_signal_handler, source);
-	
+	gst_bus_set_sync_handler(bus, NULL, NULL);
+	gst_bus_set_sync_handler(bus, adium_bus_sync_signal_handler, queue);
 }
 
 
 {
 #warning emit message	
 	
-	NSLog(@"Media emit message: %s", message);
+	AILogWithSignature(@"Media emit message: %s", message);
 }
 
 static void
 {
 #warning error message
 	
-	NSLog(@"Media error message: %s", message);
+	AILogWithSignature(@"Media error message: %s", message);
 }
 
 static void
 	GstPad *ghost;
 	GstCaps *caps;
 
-	src = gst_element_factory_make("videotestsrc", NULL);
+	src = gst_element_factory_make("qtkitvideosrc", NULL);
 	
 	NSString *deviceUID = [adium.preferenceController preferenceForKey:KEY_VIDEO_DEVICE_UID
 																 group:PREF_GROUP_MEDIA];
 	caps = gst_caps_from_string("video/x-raw-rgb, width=[176,352] , height=[144,288] , framerate=[1/1,20/1]");
 	g_object_set(G_OBJECT(capsfilter), "caps", caps, NULL);
 
-	gst_bin_add_many(GST_BIN(sendbin), src, autoconvert, videorate, NULL);
-	gst_element_link_many(src, autoconvert, videorate, NULL);
+	gst_bin_add_many(GST_BIN(sendbin), src, colorspace, autoconvert, videorate, NULL);
+	gst_element_link_many(src, colorspace, autoconvert, videorate, NULL);
 
 	pad = gst_element_get_static_pad(videorate, "src");
 	ghost = gst_ghost_pad_new("ghostsrc", pad);
 {
 	NSLog(@"create_default_audio_sink");
 	PurpleMediaManager *manager = purple_media_get_manager(media);
-	GstPipeline *pipeline = (GstElement *) purple_media_manager_get_pipeline(manager);
+	GstPipeline *pipeline = GST_PIPELINE(purple_media_manager_get_pipeline(manager));
 	GstElement *bin, *convert, *resample, *sink;
 	GstPad *pad;
 	bin = gst_bin_new("adiumdefaultaudiosinkbin");