Index: gstelement.h
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstelement.h,v
retrieving revision 1.177
diff -u -B -b -p -r1.177 gstelement.h
--- gstelement.h	15 Jul 2004 02:26:48 -0000	1.177
+++ gstelement.h	2 Nov 2004 16:09:15 -0000
@@ -446,6 +446,7 @@ gboolean		gst_element_register			(GstPlu
 								 GType type);
 
 GstElementFactory *	gst_element_factory_find		(const gchar *name);
+GstElementClass * 	gst_element_factory_ref_element_class 	(GstElementFactory *factory);
 GType			gst_element_factory_get_element_type	(GstElementFactory *factory);
 G_CONST_RETURN gchar *	gst_element_factory_get_longname	(GstElementFactory *factory);
 G_CONST_RETURN gchar *	gst_element_factory_get_klass		(GstElementFactory *factory);
Index: gstelementfactory.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstelementfactory.c,v
retrieving revision 1.100
diff -u -B -b -p -r1.100 gstelementfactory.c
--- gstelementfactory.c	29 Jul 2004 15:29:36 -0000	1.100
+++ gstelementfactory.c	2 Nov 2004 16:09:15 -0000
@@ -188,6 +188,32 @@ gst_element_factory_cleanup (GstElementF
 }
 
 /**
+ * gst_element_factory_ref_element_class:
+ * @factory: #GstElementFactory to get the class from
+ *
+ * Get a reference to a Class this elementfactory provides or 
+ * NULL when the plugin is not loaded.
+ *
+ * Returns: A reference to the Class created from this factory or
+ *  NULL when the plugin is not loaded.
+ */
+GstElementClass *
+gst_element_factory_ref_element_class (GstElementFactory * factory)
+{
+  GstElementClass *klass;
+
+  /* we can only get a ref to the type when we have loaded the
+   * plugin and thus the type is known */
+  g_return_val_if_fail (factory != NULL, NULL);
+  g_return_val_if_fail (factory->type != 0, NULL);
+
+  klass = GST_ELEMENT_CLASS (g_type_class_ref (factory->type));
+  klass->elementfactory = factory;
+
+  return klass;
+}
+
+/**
  * gst_element_register:
  * @plugin: #GstPlugin to register the element with
  * @name: name of elements of this type
@@ -227,13 +253,14 @@ gst_element_register (GstPlugin * plugin
         g_type_name (type));
   }
 
-  klass = GST_ELEMENT_CLASS (g_type_class_ref (type));
   factory->type = type;
+  klass = gst_element_factory_ref_element_class (factory);
+
+  /* now copy over stuff from the element class to the factory */
   __gst_element_details_copy (&factory->details, &klass->details);
   factory->padtemplates = g_list_copy (klass->padtemplates);
   g_list_foreach (factory->padtemplates, (GFunc) gst_object_ref, NULL);
   factory->numpadtemplates = klass->numpadtemplates;
-  klass->elementfactory = factory;
 
   /* special stuff for URI handling */
   if (g_type_is_a (type, GST_TYPE_URI_HANDLER)) {
