1 <!-- ############ chapter ############# -->
3 <chapter id="chapter-building-testapp">
4 <title>Building a Test Application</title>
6 Often, you will want to test your newly written plugin in an as small
7 setting as possible. Ususally, <filename>gst-launch</filename> is a
8 good first step at testing a plugin. However, you will often need more
9 testing features than gst-launch can provide, such as seeking, events,
10 interactivity and more. Writing your own small testing program is the
11 easiest way to accomplish this. This section explains - in a few words
12 - how to do that. For a complete application development guide, see the
13 <ulink type="http" url="../manual/index.html">Application Development
18 At the start, you need to initialize the &GStreamer; core library by
19 calling <function>gst_init ()</function>. You can alternatively call
20 <function>gst_init_with_popt_tables ()</function>, which will return
21 a pointer to popt tables. You can then use libpopt to handle the
22 given argument table, and this will finish the &GStreamer; intialization.
26 You can create elements using <function>gst_element_factory_make ()</function>,
27 where the first argument is the element type that you want to create,
28 and the second argument is a free-form name. The example at the end uses
29 a simple filesource - decoder - soundcard output pipeline, but you can
30 use specific debugging elements if that's necessary. For example, an
31 <classname>identity</classname> element can be used in the middle of
32 the pipeline to act as a data-to-application transmitter. This can be
33 used to check the data for misbehaviours or correctness in your test
34 application. Also, you can use a <classname>fakesink</classname>
35 element at the end of the pipeline to dump your data to the stdout
36 (in order to do this, set the <function>dump</function> property to
37 TRUE). Lastly, you can use the <classname>efence</classname> element
38 (indeed, an eletric fence memory debugger wrapper element) to check
43 During linking, your test application can use fixation or filtered caps
44 as a way to drive a specific type of data to or from your element. This
45 is a very simple and effective way of checking multiple types of input
46 and output in your element.
50 Running the pipeline happens through the <function>gst_bin_iterate ()</function>
51 function. Note that during running, you should connect to at least the
52 <quote>error</quote> and <quote>eos</quote> signals on the pipeline
53 and/or your plugin/element to check for correct handling of this. Also,
54 you should add events into the pipeline and make sure your plugin handles
55 these correctly (with respect to clocking, internal caching, etc.).
59 Never forget to clean up memory in your plugin or your test application.
60 When going to the NULL state, your element should clean up allocated
61 memory and caches. Also, it should close down any references held to
62 possible support libraries. Your application should <function>unref ()</function>
63 the pipeline and make sure it doesn't crash.
67 #include <gst/gst.h>
73 GstElement *pipeline, *filesrc, *decoder, *filter, *sink;
76 gst_init (&argc, &argv);
79 pipeline = gst_pipeline_new ("my_pipeline");
81 filesrc = gst_element_factory_make ("filesrc", "my_filesource");
82 decoder = gst_element_factory_make ("mad", "my_decoder");
83 filter = gst_element_factory_make ("my_filter", "my_filter");
84 sink = gst_element_factory_make ("osssink", "audiosink");
86 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
88 /* link everything together */
89 gst_element_link_many (filesrc, decoder, filter, sink, NULL);
90 gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, filter, sink, NULL);
93 gst_element_set_state (pipeline, GST_STATE_PLAYING);
94 while (gst_bin_iterate (GST_BIN (pipeline)));
97 gst_element_set_state (pipeline, GST_STATE_NULL);
98 gst_object_unref (GST_OBJECT (pipeline));