[maemo-commits] [maemo-commits] r16677 - in projects/haf/trunk/hildon-thumbnail: . daemon/plugins

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Nov 14 13:05:09 EET 2008
Author: pvanhoof
Date: 2008-11-14 13:05:08 +0200 (Fri, 14 Nov 2008)
New Revision: 16677

Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c
Log:
2008-11-14  Philip Van Hoof  <philip at codeminded.be>

        * daemon/plugins/gstreamer-video-plugin.c: Replaced a GMainLoop with a
        less confusing GCond



Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-11-14 09:42:14 UTC (rev 16676)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-11-14 11:05:08 UTC (rev 16677)
@@ -1,5 +1,10 @@
 2008-11-14  Philip Van Hoof  <philip at codeminded.be>
 
+	* daemon/plugins/gstreamer-video-plugin.c: Replaced a GMainLoop with a
+	less confusing GCond
+
+2008-11-14  Philip Van Hoof  <philip at codeminded.be>
+
 	* daemon/hildon-thumbnail-plugin.c: Fixed the locking to cope with
 	the video plugin
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-11-14 09:42:14 UTC (rev 16676)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-11-14 11:05:08 UTC (rev 16677)
@@ -52,7 +52,9 @@
 
 	guint           mtime;
 
-	GMainLoop      *loop;
+	GCond          *condition;
+	gboolean        had_callback;
+	GMutex         *mutex;
 
 	GstElement     *pipeline;
 	GstElement     *source;
@@ -122,7 +124,12 @@
 			   thumber->size, thumber->size,
 			   24, thumber->uri, thumber->mtime);
 
-	g_main_loop_quit (thumber->loop);
+	if (thumber->condition) {
+		g_mutex_lock (thumber->mutex);
+		g_cond_broadcast (thumber->condition);
+		thumber->had_callback = TRUE;
+		g_mutex_unlock (thumber->mutex);
+	}
 
 	return TRUE;
 }
@@ -178,21 +185,42 @@
 			g_error_free (error);
 		g_free(message_str);
 		thumber->bugged = TRUE;
-		g_main_loop_quit (thumber->loop);
+
+		if (thumber->condition) {
+			g_mutex_lock (thumber->mutex);
+			g_cond_broadcast (thumber->condition);
+			thumber->had_callback = TRUE;
+			g_mutex_unlock (thumber->mutex);
+		}
+
 		break;
-	
+
 	case GST_MESSAGE_WARNING:
 		gst_message_parse_warning(message, &error, &message_str);
 		g_warning("GStreamer warning: %s\n", message_str);
 		if (error)
 			g_error_free(error);
 		g_free(message_str);
-		g_main_loop_quit (thumber->loop);
+
+		if (thumber->condition) {
+			g_mutex_lock (thumber->mutex);
+			g_cond_broadcast (thumber->condition);
+			thumber->had_callback = TRUE;
+			g_mutex_unlock (thumber->mutex);
+		}
+
 		break;
 
 	case GST_MESSAGE_EOS:
 		thumber->bugged = TRUE;
-		g_main_loop_quit (thumber->loop);
+
+		if (thumber->condition) {
+			g_mutex_lock (thumber->mutex);
+			g_cond_broadcast (thumber->condition);
+			thumber->had_callback = TRUE;
+			g_mutex_unlock (thumber->mutex);
+		}
+
 		break;
 
 	case GST_MESSAGE_STATE_CHANGED:
@@ -243,11 +271,11 @@
 	GstBus            *bus;
 	GstPad            *videopad;
 	GstCaps           *caps;
+	GTimeVal           timev;
 
 	/* Resetting */
 	thumber->bugged       = FALSE;
 
-	thumber->loop         = NULL;
 	thumber->source       = NULL;
 	thumber->decodebin    = NULL;
 	thumber->bin          = NULL;
@@ -255,6 +283,10 @@
 	thumber->video_filter = NULL;
 	thumber->video_sink   = NULL;
 
+	thumber->had_callback = FALSE;
+	thumber->mutex = g_mutex_new ();
+	thumber->condition = g_cond_new ();
+
 	/* Preparing the source, decodebin and pipeline */
 	thumber->pipeline     = gst_pipeline_new("source pipeline");
 	thumber->source       = gst_element_factory_make ("filesrc", "source");
@@ -337,15 +369,22 @@
 	gst_bin_add (GST_BIN (thumber->pipeline), thumber->bin);
 
 	/* Run */
-	thumber->loop = g_main_loop_new (NULL, FALSE);
 	gst_element_set_state (thumber->pipeline, GST_STATE_PAUSED);
 
-	// g_timeout_add_seconds (10, g_main_loop_quit, thumber->loop);
-	if (!(thumber->bugged)) 
-		g_main_loop_run (thumber->loop);
+	g_get_current_time (&timev);
+	g_time_val_add  (&timev, 10000000); /* 10 seconds */
 
+	g_mutex_lock (thumber->mutex);
+	if (!thumber->had_callback)
+		g_cond_timed_wait (thumber->condition, thumber->mutex, &timev);
+	g_mutex_unlock (thumber->mutex);
+
+
 	cleanup:
 
+	g_cond_free (thumber->condition);
+	g_mutex_free (thumber->mutex);
+
 	if (thumber->pipeline) {
 		gst_element_set_state (thumber->pipeline, GST_STATE_NULL);
 
@@ -371,8 +410,6 @@
 			gst_object_unref (thumber->video_sink);
 	}
 
-	if (thumber->loop)
-		g_main_loop_unref (thumber->loop);
 }
 
 const gchar** 


More information about the maemo-commits mailing list