mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 19:21:06 +00:00
Cleanups.
Original commit message from CVS: Cleanups. The first steps to a Glade like XML handling. A first example of what is to come...
This commit is contained in:
parent
c6b47b8ed2
commit
31d31ddc2a
17 changed files with 392 additions and 26 deletions
2
examples/xml/.gitignore
vendored
Normal file
2
examples/xml/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
Makefile
|
||||
queue4
|
15
examples/xml/Makefile
Normal file
15
examples/xml/Makefile
Normal file
|
@ -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
|
||||
|
||||
|
73
examples/xml/createxml.c
Normal file
73
examples/xml/createxml.c
Normal file
|
@ -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);
|
||||
}
|
||||
|
37
examples/xml/runxml.c
Normal file
37
examples/xml/runxml.c
Normal file
|
@ -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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
92
gst/gstxml.c
92
gst/gstxml.c
|
@ -19,11 +19,43 @@
|
|||
|
||||
#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;
|
||||
}
|
||||
|
|
36
gst/gstxml.h
36
gst/gstxml.h
|
@ -24,7 +24,43 @@
|
|||
#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__ */
|
||||
|
|
2
tests/old/examples/xml/.gitignore
vendored
Normal file
2
tests/old/examples/xml/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
Makefile
|
||||
queue4
|
15
tests/old/examples/xml/Makefile
Normal file
15
tests/old/examples/xml/Makefile
Normal file
|
@ -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
|
||||
|
||||
|
73
tests/old/examples/xml/createxml.c
Normal file
73
tests/old/examples/xml/createxml.c
Normal file
|
@ -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);
|
||||
}
|
||||
|
37
tests/old/examples/xml/runxml.c
Normal file
37
tests/old/examples/xml/runxml.c
Normal file
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in a new issue