Cleanups.
authorWim Taymans <wim.taymans@gmail.com>
Sun, 24 Sep 2000 22:45:48 +0000 (22:45 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Sun, 24 Sep 2000 22:45:48 +0000 (22:45 +0000)
Original commit message from CVS:
Cleanups.
The first steps to a Glade like XML handling.
A first example of what is to come...

17 files changed:
examples/xml/.gitignore [new file with mode: 0644]
examples/xml/Makefile [new file with mode: 0644]
examples/xml/createxml.c [new file with mode: 0644]
examples/xml/runxml.c [new file with mode: 0644]
gst/gstbin.c
gst/gstconnection.h
gst/gstelementfactory.c
gst/gstpipeline.c
gst/gsttee.h
gst/gstthread.c
gst/gstthread.h
gst/gstxml.c
gst/gstxml.h
tests/old/examples/xml/.gitignore [new file with mode: 0644]
tests/old/examples/xml/Makefile [new file with mode: 0644]
tests/old/examples/xml/createxml.c [new file with mode: 0644]
tests/old/examples/xml/runxml.c [new file with mode: 0644]

diff --git a/examples/xml/.gitignore b/examples/xml/.gitignore
new file mode 100644 (file)
index 0000000..be5981b
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile
+queue4
diff --git a/examples/xml/Makefile b/examples/xml/Makefile
new file mode 100644 (file)
index 0000000..5f74b38
--- /dev/null
@@ -0,0 +1,15 @@
+
+CC = gcc
+
+all: createxml runxml
+
+createxml: createxml.c 
+       $(CC) -Wall `gstreamer-config --cflags --libs` createxml.c -o createxml 
+
+runxml: runxml.c 
+       $(CC) -Wall `gstreamer-config --cflags --libs` runxml.c -o runxml 
+
+clean: 
+       rm -f *.o createxml runxml
+       
+       
diff --git a/examples/xml/createxml.c b/examples/xml/createxml.c
new file mode 100644 (file)
index 0000000..36810a8
--- /dev/null
@@ -0,0 +1,73 @@
+#include <gst/gst.h>
+
+gboolean playing;
+
+int main(int argc,char *argv[]) 
+{
+  GstElement *disksrc, *audiosink, *queue, *queue2, *parse, *decode;
+  GstElement *bin;
+  GstElement *thread, *thread2;
+
+  if (argc != 2) {
+    g_print("usage: %s <filename>\n", argv[0]);
+    exit(-1);
+  }
+
+  gst_init(&argc,&argv);
+
+  /* create a new thread to hold the elements */
+  thread = gst_thread_new("thread");
+  g_assert(thread != NULL);
+  thread2 = gst_thread_new("thread2");
+  g_assert(thread2 != NULL);
+
+  /* create a new bin to hold the elements */
+  bin = gst_bin_new("bin");
+  g_assert(bin != NULL);
+
+  /* create a disk reader */
+  disksrc = gst_elementfactory_make("disksrc", "disk_source");
+  g_assert(disksrc != NULL);
+  gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL);
+
+  queue = gst_elementfactory_make("queue", "queue");
+  queue2 = gst_elementfactory_make("queue", "queue2");
+
+  /* and an audio sink */
+  audiosink = gst_elementfactory_make("audiosink", "play_audio");
+  g_assert(audiosink != NULL);
+
+  parse = gst_elementfactory_make("mp3parse", "parse");
+  decode = gst_elementfactory_make("mpg123", "decode");
+
+  /* add objects to the main bin */
+  gst_bin_add(GST_BIN(bin), disksrc);
+  gst_bin_add(GST_BIN(bin), queue);
+
+  gst_bin_add(GST_BIN(thread), parse);
+  gst_bin_add(GST_BIN(thread), decode);
+  gst_bin_add(GST_BIN(thread), queue2);
+
+  gst_bin_add(GST_BIN(thread2), audiosink);
+  
+  gst_pad_connect(gst_element_get_pad(disksrc,"src"),
+                  gst_element_get_pad(queue,"sink"));
+
+  gst_pad_connect(gst_element_get_pad(queue,"src"),
+                  gst_element_get_pad(parse,"sink"));
+  gst_pad_connect(gst_element_get_pad(parse,"src"),
+                  gst_element_get_pad(decode,"sink"));
+  gst_pad_connect(gst_element_get_pad(decode,"src"),
+                  gst_element_get_pad(queue2,"sink"));
+
+  gst_pad_connect(gst_element_get_pad(queue2,"src"),
+                  gst_element_get_pad(audiosink,"sink"));
+
+  gst_bin_add(GST_BIN(bin), thread);
+  gst_bin_add(GST_BIN(bin), thread2);
+
+  xmlSaveFile("xmlTest.gst", gst_xml_write(GST_ELEMENT(bin)));
+
+  exit(0);
+}
+
diff --git a/examples/xml/runxml.c b/examples/xml/runxml.c
new file mode 100644 (file)
index 0000000..b3f8739
--- /dev/null
@@ -0,0 +1,37 @@
+#include <gst/gst.h>
+
+gboolean playing;
+
+/* eos will be called when the src element has an end of stream */
+void eos(GstSrc *src, gpointer data)
+{
+  g_print("have eos, quitting\n");
+
+  playing = FALSE;
+}
+
+int main(int argc,char *argv[]) 
+{
+  GstXML *xml;
+  GstElement *bin;
+
+  gst_init(&argc,&argv);
+
+  xml = gst_xml_new("xmlTest.gst", NULL);
+
+  bin = gst_xml_get_element(xml, "bin");
+  
+  gst_element_set_state(bin, GST_STATE_READY);
+  gst_element_set_state(bin, GST_STATE_PLAYING);
+
+  playing = TRUE;
+
+  while (playing) {
+    gst_bin_iterate(GST_BIN(bin));
+  }
+
+  gst_element_set_state(bin, GST_STATE_NULL);
+
+  exit(0);
+}
+
index 9c03886..38ad526 100644 (file)
@@ -108,6 +108,7 @@ gst_bin_class_init(GstBinClass *klass) {
 
   gstelement_class->change_state = gst_bin_change_state;
   gstelement_class->save_thyself = gst_bin_save_thyself;
+  gstelement_class->elementfactory = gst_elementfactory_find("bin");
 
   gtkobject_class->destroy = gst_bin_real_destroy;
 }
index a98ca1b..cde0cb1 100644 (file)
@@ -39,7 +39,7 @@ extern "C" {
 #define GST_IS_CONNECTION(obj) \
   (GTK_CHECK_TYPE((obj),GST_TYPE_CONNECTION))
 #define GST_IS_CONNECTION_CLASS(obj) \
-  (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_CONNECTION)))
+  (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_CONNECTION))
 
 typedef struct _GstConnection GstConnection;
 typedef struct _GstConnectionClass GstConnectionClass;
index 6debdf4..d1d6796 100644 (file)
@@ -120,6 +120,9 @@ GstElement *gst_elementfactory_create(GstElementFactory *factory,
 
   factory = gst_plugin_load_elementfactory(factory->name);
 
+  if (factory->type == 0) {
+    factory = gst_elementfactory_find(name);
+  }
   g_return_val_if_fail(factory->type != 0, NULL);
 
   // create an instance of the element
index 3b52084..b5f1289 100644 (file)
@@ -88,6 +88,7 @@ gst_pipeline_class_init(GstPipelineClass *klass) {
   parent_class = gtk_type_class(gst_bin_get_type());
 
   gstelement_class->change_state = gst_pipeline_change_state;
+  gstelement_class->elementfactory = gst_elementfactory_find("pipeline");
 }
 
 static void gst_pipeline_init(GstPipeline *pipeline) {
@@ -300,7 +301,7 @@ gboolean gst_pipeline_autoplug(GstPipeline *pipeline) {
   GstElement *element, *srcelement = NULL, *sinkelement= NULL;
   GList *factories;
   GstElementFactory *factory;
-  GList *src_types, *sink_types;
+  GList *src_types;
   guint16 src_type = 0, sink_type = 0;
   gboolean complete = FALSE;
 
@@ -367,27 +368,6 @@ gboolean gst_pipeline_autoplug(GstPipeline *pipeline) {
 
       pads = g_list_next(pads);
     }
-    /*
-    if (GST_IS_SINK(element)) {
-      g_print("GstPipeline: found sink \"%s\"\n", gst_element_get_name(element));
-
-      sinkelement = element;
-      factory = gst_element_get_factory(element);
-      
-      sink_types = factory->sink_types;
-      if (sink_types == NULL) {
-        g_print("GstPipeline: sink \"%s\" has no MIME type, can't autoplug \n", 
-                       gst_element_get_name(element));
-       return FALSE;
-      }
-      else {
-       sink_type = GPOINTER_TO_UINT(sink_types->data);
-        g_print("GstPipeline: sink \"%s\" has MIME type %d \n", 
-                       gst_element_get_name(element), sink_type);
-      }
-    }
-    */
-
     elements = g_list_next(elements);
   }
 
index 1953325..1e81924 100644 (file)
@@ -38,7 +38,7 @@ extern "C" {
 #define GST_IS_TEE(obj) \
   (GTK_CHECK_TYPE((obj),GST_TYPE_TEE))
 #define GST_IS_TEE_CLASS(obj) \
-  (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_TEE)))
+  (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_TEE))
 
 typedef struct _GstTee GstTee;
 typedef struct _GstTeeClass GstTeeClass;
index 5ad60ea..c26f018 100644 (file)
@@ -100,11 +100,13 @@ gst_thread_class_init(GstThreadClass *klass) {
 
   gstelement_class->change_state = gst_thread_change_state;
   gstelement_class->save_thyself = gst_thread_save_thyself;
+  gstelement_class->elementfactory = gst_elementfactory_find("thread");
 
   gstbin_class->create_plan = gst_thread_create_plan_dummy;
 
   gtkobject_class->set_arg = gst_thread_set_arg;
   gtkobject_class->get_arg = gst_thread_get_arg;
+
 }
 
 static void gst_thread_init(GstThread *thread) {
index 7e221f2..ceac92d 100644 (file)
@@ -49,7 +49,7 @@ typedef enum {
 #define GST_IS_THREAD(obj) \
   (GTK_CHECK_TYPE((obj),GST_TYPE_THREAD))
 #define GST_IS_THREAD_CLASS(obj) \
-  (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_THREAD)))
+  (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_THREAD))
 
 typedef struct _GstThread GstThread;
 typedef struct _GstThreadClass GstThreadClass;
index f432100..c4ef8f2 100644 (file)
 
 #include <gst/gstxml.h>
 
+static void gst_xml_class_init(GstXMLClass *klass);
+static void gst_xml_init(GstXML *xml);
+
+static GstObjectClass *parent_class = NULL;
+
+GtkType gst_xml_get_type(void) {
+  static GtkType xml_type = 0;
+
+  if (!xml_type) {
+    static const GtkTypeInfo xml_info = {
+      "GstXML",
+      sizeof(GstElement),
+      sizeof(GstElementClass),
+      (GtkClassInitFunc)gst_xml_class_init,
+      (GtkObjectInitFunc)gst_xml_init,
+      (GtkArgSetFunc)NULL,
+      (GtkArgGetFunc)NULL,
+      (GtkClassInitFunc)NULL,
+    };
+    xml_type = gtk_type_unique(GST_TYPE_XML,&xml_info);
+  }
+  return xml_type;
+}
+
+static void
+gst_xml_class_init(GstXMLClass *klass) {
+  parent_class = gtk_type_class(GST_TYPE_OBJECT);
+}
+
+static void gst_xml_init(GstXML *xml) {
+}
+
 /**
  * gst_xml_write:
  * @element: The element to write out
  *
- * converts the given elkement into an XML presentation
+ * converts the given element into an XML presentation
  *
  * Returns: a pointer to an XML document
  */
@@ -37,3 +69,61 @@ xmlDocPtr gst_xml_write(GstElement *element) {
 
   return doc;
 }
+
+/**
+ * gst_xml_new:
+ * @fname: The filename with the xml description
+ * @root: The name of the root object to build
+ *
+ * Creates a new GstXML object (and the corresponding elements) from 
+ * the XML file fname. Optionally it will only build the element from 
+ * the element node root (if it is not NULL). This feature is useful 
+ * if you only want to build a specific element from an XML file
+ * but not the pipeline it is embedded in. Note also that the XML parse 
+ * tree is cached to speed up creating another GstXML object for 
+ * the same file
+ *
+ * Returns: a pointer to a new GstElement
+ */
+GstXML *gst_xml_new(const guchar *fname, const guchar *root) {
+  xmlDocPtr doc;
+  GstXML *xml;
+
+  g_return_val_if_fail(fname != NULL, NULL);
+       
+  doc = xmlParseFile(fname);
+
+  if (!doc) {
+    g_print("gstxml: XML file \"%s\" could not be read\n", fname);
+    return NULL;
+  }
+  if (strcmp(doc->root->name, "GST-Pipeline")) {
+    g_print("gstxml: XML file \"%s\" is in wrong format\n", fname);
+    return NULL;
+  }
+
+  xml = GST_XML(gtk_type_new(GST_TYPE_XML));
+
+  return xml;
+}
+
+/**
+ * gst_xml_get_element:
+ * @xml: The GstXML to get the element from
+ * @name: The name of element to retreive
+ *
+ * This function is used to get a pointer to the GStElement corresponding 
+ * to name in the pipeline description. You would use this if you have 
+ * to do anything to the element after loading.
+ *
+ * Returns: a pointer to a new GstElement
+ */
+GstElement *gst_xml_get_element(GstXML *xml, const guchar *name) {
+
+  g_return_val_if_fail(xml != NULL, NULL);
+  g_return_val_if_fail(name != NULL, NULL);
+
+  g_print("gstxml: getting element \"%s\" (implement me)\n", name);
+
+  return NULL;
+}
index e253881..a0adf59 100644 (file)
 #include <gst/gst.h>
 #include <gnome-xml/parser.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define GST_TYPE_XML \
+  (gst_object_get_type())
+#define GST_XML(obj) \
+  (GTK_CHECK_CAST((obj),GST_TYPE_XML,GstXML))
+#define GST_XML_CLASS(klass) \
+  (GTK_CHECK_CLASS_CAST((klass),GST_TYPE_XML,GstXMLClass))
+#define GST_IS_XML(obj) \
+  (GTK_CHECK_TYPE((obj),GST_TYPE_XML))
+#define GST_IS_XML_CLASS(obj) \
+  (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_XML))
+
+typedef struct _GstXML GstXML;
+typedef struct _GstXMLClass GstXMLClass;
+
+struct _GstXML {
+  GtkObject object;
+};
+
+struct _GstXMLClass {
+  GtkObjectClass parent_class;
+};
+
+GtkType gst_xml_get_type(void);
+
+
 /* create an XML document out of a pipeline */
 xmlDocPtr gst_xml_write(GstElement *element);
 
+GstXML *gst_xml_new(const guchar *fname, const guchar *root);
+
+GstElement *gst_xml_get_element(GstXML *xml, const guchar *name);
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
 #endif /* __GST_XML_H__ */
diff --git a/tests/old/examples/xml/.gitignore b/tests/old/examples/xml/.gitignore
new file mode 100644 (file)
index 0000000..be5981b
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile
+queue4
diff --git a/tests/old/examples/xml/Makefile b/tests/old/examples/xml/Makefile
new file mode 100644 (file)
index 0000000..5f74b38
--- /dev/null
@@ -0,0 +1,15 @@
+
+CC = gcc
+
+all: createxml runxml
+
+createxml: createxml.c 
+       $(CC) -Wall `gstreamer-config --cflags --libs` createxml.c -o createxml 
+
+runxml: runxml.c 
+       $(CC) -Wall `gstreamer-config --cflags --libs` runxml.c -o runxml 
+
+clean: 
+       rm -f *.o createxml runxml
+       
+       
diff --git a/tests/old/examples/xml/createxml.c b/tests/old/examples/xml/createxml.c
new file mode 100644 (file)
index 0000000..36810a8
--- /dev/null
@@ -0,0 +1,73 @@
+#include <gst/gst.h>
+
+gboolean playing;
+
+int main(int argc,char *argv[]) 
+{
+  GstElement *disksrc, *audiosink, *queue, *queue2, *parse, *decode;
+  GstElement *bin;
+  GstElement *thread, *thread2;
+
+  if (argc != 2) {
+    g_print("usage: %s <filename>\n", argv[0]);
+    exit(-1);
+  }
+
+  gst_init(&argc,&argv);
+
+  /* create a new thread to hold the elements */
+  thread = gst_thread_new("thread");
+  g_assert(thread != NULL);
+  thread2 = gst_thread_new("thread2");
+  g_assert(thread2 != NULL);
+
+  /* create a new bin to hold the elements */
+  bin = gst_bin_new("bin");
+  g_assert(bin != NULL);
+
+  /* create a disk reader */
+  disksrc = gst_elementfactory_make("disksrc", "disk_source");
+  g_assert(disksrc != NULL);
+  gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL);
+
+  queue = gst_elementfactory_make("queue", "queue");
+  queue2 = gst_elementfactory_make("queue", "queue2");
+
+  /* and an audio sink */
+  audiosink = gst_elementfactory_make("audiosink", "play_audio");
+  g_assert(audiosink != NULL);
+
+  parse = gst_elementfactory_make("mp3parse", "parse");
+  decode = gst_elementfactory_make("mpg123", "decode");
+
+  /* add objects to the main bin */
+  gst_bin_add(GST_BIN(bin), disksrc);
+  gst_bin_add(GST_BIN(bin), queue);
+
+  gst_bin_add(GST_BIN(thread), parse);
+  gst_bin_add(GST_BIN(thread), decode);
+  gst_bin_add(GST_BIN(thread), queue2);
+
+  gst_bin_add(GST_BIN(thread2), audiosink);
+  
+  gst_pad_connect(gst_element_get_pad(disksrc,"src"),
+                  gst_element_get_pad(queue,"sink"));
+
+  gst_pad_connect(gst_element_get_pad(queue,"src"),
+                  gst_element_get_pad(parse,"sink"));
+  gst_pad_connect(gst_element_get_pad(parse,"src"),
+                  gst_element_get_pad(decode,"sink"));
+  gst_pad_connect(gst_element_get_pad(decode,"src"),
+                  gst_element_get_pad(queue2,"sink"));
+
+  gst_pad_connect(gst_element_get_pad(queue2,"src"),
+                  gst_element_get_pad(audiosink,"sink"));
+
+  gst_bin_add(GST_BIN(bin), thread);
+  gst_bin_add(GST_BIN(bin), thread2);
+
+  xmlSaveFile("xmlTest.gst", gst_xml_write(GST_ELEMENT(bin)));
+
+  exit(0);
+}
+
diff --git a/tests/old/examples/xml/runxml.c b/tests/old/examples/xml/runxml.c
new file mode 100644 (file)
index 0000000..b3f8739
--- /dev/null
@@ -0,0 +1,37 @@
+#include <gst/gst.h>
+
+gboolean playing;
+
+/* eos will be called when the src element has an end of stream */
+void eos(GstSrc *src, gpointer data)
+{
+  g_print("have eos, quitting\n");
+
+  playing = FALSE;
+}
+
+int main(int argc,char *argv[]) 
+{
+  GstXML *xml;
+  GstElement *bin;
+
+  gst_init(&argc,&argv);
+
+  xml = gst_xml_new("xmlTest.gst", NULL);
+
+  bin = gst_xml_get_element(xml, "bin");
+  
+  gst_element_set_state(bin, GST_STATE_READY);
+  gst_element_set_state(bin, GST_STATE_PLAYING);
+
+  playing = TRUE;
+
+  while (playing) {
+    gst_bin_iterate(GST_BIN(bin));
+  }
+
+  gst_element_set_state(bin, GST_STATE_NULL);
+
+  exit(0);
+}
+