<programlisting>
// create the mp3player element
- GstElement *mp3player = gst_elementfactory_make("mp3player","mp3player");
+ GstElement *mp3player = gst_elementfactory_make ("mp3player", "mp3player");
// set the source mp3 audio file
- gtk_object_set(GTK_OBJECT(mp3player), "location", "helloworld.mp3", NULL);
+ g_object_set (G_OBJECT (mp3player), "location", "helloworld.mp3", NULL);
// start playback
- gst_element_set_state(GST_ELEMENT(mp3player),GST_STATE_PLAYING);
+ gst_element_set_state (GST_ELEMENT (mp3player), GST_STATE_PLAYING);
...
// pause playback
- gst_element_set_state(GST_ELEMENT(mp3player),GST_STATE_PAUSED);
+ gst_element_set_state (GST_ELEMENT (mp3player), GST_STATE_PAUSED);
...
// stop
- gst_element_set_state(GST_ELEMENT(mp3player),GST_STATE_NULL);
+ gst_element_set_state (GST_ELEMENT (mp3player), GST_STATE_NULL);
</programlisting>
Custom bins can be created with a plugin or an XML description. You will find more
src = gst_elementfactory_make ("disksrc", "src");
g_return_val_if_fail (src != NULL, -1);
- gtk_object_set (GTK_OBJECT (src), "location", argv[1], NULL);
+ g_object_set (G_OBJECT (src), "location", argv[1], NULL);
parse = gst_elementfactory_make ("mpeg1parse", "parse");
g_return_val_if_fail (parse != NULL, -1);
gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (src));
gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (parse));
- gtk_signal_connect (GTK_OBJECT (parse), "new_pad",
- GTK_SIGNAL_FUNC (new_pad_created), pipeline);
+ g_signal_connectc (G_OBJECT (parse), "new_pad",
+ G_CALLBACK (new_pad_created), pipeline, FALSE);
- gtk_signal_connect (GTK_OBJECT (src), "eos",
- GTK_SIGNAL_FUNC (eof), NULL);
+ g_signal_connectc (G_OBJECT (src), "eos",
+ G_CALLBACK (eof), NULL, FALSE);
gst_pad_connect (gst_element_get_pad (src, "src"),
gst_element_get_pad (parse, "sink"));
'new_pad' that we connected to the mpeg1parser using:
</para>
<programlisting>
- gtk_signal_connect (GTK_OBJECT (parse), "new_pad",
- GTK_SIGNAL_FUNC (new_pad_created), pipeline);
+ g_signal_connectc (G_OBJECT (parse), "new_pad",
+ G_CALLBACK (new_pad_created), pipeline, FALSE);
</programlisting>
<para>
When an elementary stream has been detected in the system stream,
gst_element_get_pad (video_thread, "sink"));
// set up thread state and kick things off
- gtk_object_set (GTK_OBJECT (video_thread), "create_thread", TRUE, NULL);
+ g_object_set (G_OBJECT (video_thread), "create_thread", TRUE, NULL);
g_print ("setting to READY state\n");
gst_element_set_state (GST_ELEMENT (video_thread), GST_STATE_READY);
}
<programlisting>
...
/* now it's time to get the parser */
- parse = gst_elementfactory_make("mp3parse","parse");
- decoder = gst_elementfactory_make("mpg123","decoder");
+ parse = gst_elementfactory_make ("mp3parse", "parse");
+ decoder = gst_elementfactory_make ("mpg123", "decoder");
...
</programlisting>
<programlisting>
guint16 id;
- id = gst_type_find_by_mime("audio/mpeg");
+ id = gst_type_find_by_mime ("audio/mpeg");
</programlisting>
<para>
This function will return 0 if the type was not known.
<programlisting>
GstType *type;
- type = gst_type_find_by_id(id);
+ type = gst_type_find_by_id (id);
</programlisting>
<para>
This function will return NULL if the id was associated with
<programlisting>
guint16 id;
- id = gst_type_find_by_ext(".mp3");
+ id = gst_type_find_by_ext (".mp3");
</programlisting>
<para>
This function will return 0 if the extension was not known.
<programlisting>
GList *list;
- list = gst_type_gst_srcs(id);
+ list = gst_type_gst_srcs (id);
</programlisting>
<para>
<programlisting>
GList *list;
- list = gst_type_gst_sinks(id);
+ list = gst_type_gst_sinks (id);
</programlisting>
<para>
When you have a list of elements, you can simply take the first
<programlisting>
GList *list;
- list = gst_type_gst_sink_to_src(sourceid, sinkid);
+ list = gst_type_gst_sink_to_src (sourceid, sinkid);
</programlisting>
<para>
This piece of code will give you the elements needed to construct
// obtain the factory
factory = ...
- element = gst_elementfactory_create(factory, "name");
+ element = gst_elementfactory_create (factory, "name");
</programlisting>
<para>
This way, you do not have to create elements by name which
<sect2 id="sec-goals-object">
<title>Object oriented</title>
<para>
- Adhere as much as possible to the GTK+ object model. A programmer familiar
- with GTK+ will be confortable with GStreamer.
+ Adhere as much as possible to the glib2.0 object model. A programmer familiar
+ with glib2 and GTK+ will be confortable with GStreamer.
</para>
<para>
GStreamer uses the mechanism of signals and object arguments.
<sect2 id="sec-goals-extensible">
<title>Extensible</title>
<para>
- All GStreamer Objects can be extended using the GTK+ inheritance methods.
+ All GStreamer Objects can be extended using the glib2 inheritance methods.
</para>
<para>
All plugins are loaded dynamically and can be extended and upgraded
<title>Allow binary only plugins</title>
<para>
plugins are shared libraries that are loaded at runtime. since all the
- properties of the plugin can be set using the GtkObject arguments, there
+ properties of the plugin can be set using the GObject properties, there
is no need to have any header files installed for the plugins.
</para>
<para>
The first chapter of the book gives you an overview of <application>GStreamer</application>
design goals. Chapter 2 rapidly covers the basics of <application>GStreamer</application>
programming. In chapter 3 we will move on to the examples.
- Since <application>GStreamer</application> adheres to the GTK+ programming model, the reader is
- assumed to understand the basics of GTK+.
+ Since <application>GStreamer</application> adheres to the GTK+/glib2 programming model, the reader is
+ assumed to understand the basics of GTK+ and the glib2.0 object model.
For a gentle introduction to GTK+, you may wish to read the <emphasis>GTK+
Tutorial</emphasis> or Eric Harlow's book <emphasis>Developing Linux
Applications with GTK+ and GDK</emphasis>.
/* create a disk reader */
disksrc = gst_elementfactory_make ("disksrc", "disk_source");
- gtk_object_set (GTK_OBJECT (disksrc),"location", argv[1], NULL);
+ g_object_set (G_OBJECT (disksrc), "location", argv[1], NULL);
/* now it's time to get the parser */
parse = gst_elementfactory_make ("mp3parse", "parse");
<para>
We then create a disk source element. The disk source element is able to
- read from a file. We use the standard GTK+ argument mechanism to set
+ read from a file. We use the standard GObject property mechanism to set
a property of the element: the file to read from.
</para>
<programlisting>
/* create a disk reader */
disksrc = gst_elementfactory_make ("disksrc", "disk_source");
- gtk_object_set (GTK_OBJECT (disksrc),"location", argv[1], NULL);
+ g_object_set (G_OBJECT (disksrc), "location", argv[1], NULL);
</programlisting>
<note>
<para>
/* create a disk reader */
disksrc = gst_elementfactory_make ("disksrc", "disk_source");
- gtk_object_set (GTK_OBJECT (disksrc), "location", argv[1], NULL);
- gtk_signal_connect (GTK_OBJECT (disksrc), "eos",
- GTK_SIGNAL_FUNC (eos), NULL);
+ g_object_set (G_OBJECT (disksrc), "location", argv[1], NULL);
+ g_signal_connectc (G_OBJECT (disksrc), "eos",
+ G_CALLBACK (eos), NULL, FALSE);
/* and an audio sink */
audiosink = gst_elementfactory_make ("audiosink", "play_audio");
...
mpeg2parser = gst_elementfactory_make ("mpeg2parse", "mpeg2parse");
- gtk_signal_connect (GTK_OBJECT (mpeg2parser), "new_pad", pad_connect_func, pipeline);
+ g_signal_connectc (G_OBJECT (mpeg2parser), "new_pad", pad_connect_func, pipeline, FALSE);
...
// start the pipeline
</para>
</listitem>
</itemizedlist>
- All of the above values can be given with a list too using:
+ All of the above values can be given with a list too, using:
<itemizedlist>
<listitem>
<para>
#include <stdlib.h>
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
GstElement *pipeline;
char **argvn;
gchar *cmdline;
int i;
- gst_init(&argc,&argv);
+ gst_init (&argc, &argv);
- pipeline = gst_pipeline_new("launch");
+ pipeline = gst_pipeline_new ("launch");
// make a null-terminated version of argv
- argvn = g_new0(char *,argc);
- memcpy(argvn,argv+1,sizeof(char*)*(argc-1));
+ argvn = g_new0 (char *,argc);
+ memcpy (argvn, argv+1, sizeof (char*) * (argc-1));
// join the argvs together
- cmdline = g_strjoinv(" ",argvn);
+ cmdline = g_strjoinv (" ", argvn);
// free the null-terminated argv
- g_free(argvn);
+ g_free (argvn);
- gst_parse_launch(cmdline,pipeline);
+ gst_parse_launch (cmdline, pipeline);
fprintf(stderr,"RUNNING pipeline\n");
- gst_element_set_state(pipeline,GST_STATE_PLAYING);
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);
while (1)
gst_bin_iterate (GST_BIN (pipeline));
<para>
The standard <application>GStreamer</application> queue implementation has some
- properties that can be changed using the gtk_objet_set () method. To set the
+ properties that can be changed using the g_objet_set () method. To set the
maximum number of buffers that can be queued to 30, do:
</para>
<programlisting>
- gtk_object_set (GTK_OBJECT (queue), "max_level", 30, NULL);
+ g_object_set (G_OBJECT (queue), "max_level", 30, NULL);
</programlisting>
<para>
/* 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);
- gtk_signal_connect (GTK_OBJECT (disksrc), "eos",
- GTK_SIGNAL_FUNC (eos), thread);
+ g_object_set (G_OBJECT (disksrc), "location", argv[1], NULL);
+ g_signal_connectc (G_OBJECT (disksrc), "eos",
+ G_CALLBACK (eos), thread, FALSE);
queue = gst_elementfactory_make ("queue", "queue");
gst_bin_add (GST_BIN (bin), thread);
- /* make it ready */
- gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
/* start playing */
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
/* 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);
- gtk_signal_connect (GTK_OBJECT (disksrc), "eos",
- GTK_SIGNAL_FUNC (eos), thread);
+ g_object_set (G_OBJECT (disksrc), "location", argv[1], NULL);
+ g_signal_connectc (G_OBJECT (disksrc), "eos",
+ G_CALLBACK (eos), thread, FALSE);
/* and an audio sink */
audiosink = gst_elementfactory_make ("audiosink", "play_audio");
{
GstElement *bin, *disksrc, *typefind;
- gst_init(&argc,&argv);
+ gst_init (&argc, &argv);
if (argc != 2) {
- g_print("usage: %s <filename>\n", argv[0]);
- exit(-1);
+ g_print ("usage: %s <filename>\n", argv[0]);
+ exit (-1);
}
/* create a new bin to hold the elements */
- bin = gst_bin_new("bin");
- g_assert(bin != NULL);
+ 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);
+ disksrc = gst_elementfactory_make ("disksrc", "disk_source");
+ g_assert (disksrc != NULL);
+ g_object_set (G_OBJECT (disksrc), "location", argv[1], NULL);
/* create the typefind element */
- typefind = gst_elementfactory_make("typefind", "typefind");
- g_assert(typefind != NULL);
+ typefind = gst_elementfactory_make ("typefind", "typefind");
+ g_assert (typefind != NULL);
/* add objects to the main pipeline */
- gst_bin_add(GST_BIN(bin), disksrc);
- gst_bin_add(GST_BIN(bin), typefind);
+ gst_bin_add (GST_BIN (bin), disksrc);
+ gst_bin_add (GST_BIN (bin), typefind);
- gtk_signal_connect (GTK_OBJECT (typefind), "have_type",
- type_found, NULL);
+ g_signal_connectc (G_OBJECT (typefind), "have_type",
+ G_CALLBACK (type_found), NULL, FALSE);
- gst_pad_connect(gst_element_get_pad(disksrc,"src"),
- gst_element_get_pad(typefind,"sink"));
+ gst_pad_connect (gst_element_get_pad (disksrc, "src"),
+ gst_element_get_pad (typefind, "sink"));
/* start playing */
- gst_element_set_state(GST_ELEMENT(bin), GST_STATE_PLAYING);
+ gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
- gst_bin_iterate(GST_BIN(bin));
+ gst_bin_iterate (GST_BIN (bin));
- gst_element_set_state(GST_ELEMENT(bin), GST_STATE_NULL);
+ gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
- exit(0);
+ exit (0);
}
</programlisting>
<para>
<chapter id="cha-utility">
<title>Utility functions</title>
<para>
- while you can use the regular gtk_object_getv () function to
+ while you can use the regular g_object_getv () function to
query the value of an object property, <application>GStreamer</application>
provides some easy wrappers for this common operation.
</para>
guchar *value;
arg.name = argname;
- gtk_object_getv (GTK_OBJECT (object), 1, &arg);
+ g_object_getv (G_OBJECT (object), 1, &arg);
value = GTK_VALUE_STRING (arg);
</programlisting>
<para>
gpointer: with gst_util_get_pointer_arg ();
</para>
</listitem>
- <listitem>
- <para>
- GtkWidget*: with gst_util_get_widget_arg ();
- </para>
- </listitem>
</itemizedlist>
</para>
<para>
to by mem.
</para>
<programlisting>
- void gst_util_dump_mem(guchar *mem, guint size);
+ void gst_util_dump_mem (guchar *mem, guint size);
</programlisting>
</chapter>
/* 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);
+ g_object_set (G_OBJECT (disksrc), "location", argv[1], NULL);
queue = gst_elementfactory_make ("queue", "queue");
queue2 = gst_elementfactory_make ("queue", "queue2");
...
ns = xmlNewNs (NULL, "http://gstreamer.net/gst-test/1.0/", "test");
...
- thread = gst_elementfactory_make("thread", "thread");
- gtk_signal_connect (GTK_OBJECT (thread), "object_saved", object_saved, g_strdup ("decoder thread"));
+ thread = gst_elementfactory_make ("thread", "thread");
+ g_signal_connectc (G_OBJECT (thread), "object_saved",
+ G_CALLBACK (object_saved), g_strdup ("decoder thread"), FALSE);
...
</programlisting>
<para>
{
xmlNodePtr child;
- child = xmlNewChild(parent, ns, "comment", NULL);
- xmlNewChild(child, ns, "text", (gchar *)data);
+ child = xmlNewChild (parent, ns, "comment", NULL);
+ xmlNewChild (child, ns, "text", (gchar *)data);
}
</programlisting>
<para>
<programlisting>
xml = gst_xml_new ();
- gtk_signal_connect (GTK_OBJECT (xml), "object_loaded", xml_loaded, xml);
+ g_signal_connectc (G_OBJECT (xml), "object_loaded",
+ G_CALLBACK (xml_loaded), xml);
- ret = gst_xml_parse_file(xml, "xmlTest.gst", NULL);
+ ret = gst_xml_parse_file (xml, "xmlTest.gst", NULL);
g_assert (ret == TRUE);
</programlisting>