<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Building a Test Application</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="GStreamer Plugin Writer's Guide" HREF="index.html"><LINK REL="UP" TITLE="Building a Filter" HREF="part-building.html"><LINK REL="PREVIOUS" TITLE="Signals" HREF="chapter-building-signals.html"><LINK REL="NEXT" TITLE="Creating a Filter with a Filter Factory" HREF="chapter-building-filterfactory.html"></HEAD ><BODY CLASS="chapter" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" ><SPAN CLASS="application" >GStreamer</SPAN > Plugin Writer's Guide</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="chapter-building-signals.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="chapter-building-filterfactory.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="chapter-building-testapp" ></A >Chapter 9. Building a Test Application</H1 ><P > Often, you will want to test your newly written plugin in an as small setting as possible. Ususally, <TT CLASS="filename" >gst-launch</TT > is a good first step at testing a plugin. However, you will often need more testing features than gst-launch can provide, such as seeking, events, interactivity and more. Writing your own small testing program is the easiest way to accomplish this. This section explains - in a few words - how to do that. For a complete application development guide, see the <A HREF="../manual/index.html" TARGET="_top" >Application Development Manual</A >. </P ><P > At the start, you need to initialize the <SPAN CLASS="application" >GStreamer</SPAN > core library by calling <CODE CLASS="function" >gst_init ()</CODE >. You can alternatively call <CODE CLASS="function" >gst_init_with_popt_tables ()</CODE >, which will return a pointer to popt tables. You can then use libpopt to handle the given argument table, and this will finish the <SPAN CLASS="application" >GStreamer</SPAN > intialization. </P ><P > You can create elements using <CODE CLASS="function" >gst_element_factory_make ()</CODE >, where the first argument is the element type that you want to create, and the second argument is a free-form name. The example at the end uses a simple filesource - decoder - soundcard output pipeline, but you can use specific debugging elements if that's necessary. For example, an <CODE CLASS="classname" >identity</CODE > element can be used in the middle of the pipeline to act as a data-to-application transmitter. This can be used to check the data for misbehaviours or correctness in your test application. Also, you can use a <CODE CLASS="classname" >fakesink</CODE > element at the end of the pipeline to dump your data to the stdout (in order to do this, set the <CODE CLASS="function" >dump</CODE > property to TRUE). Lastly, you can use the <CODE CLASS="classname" >efence</CODE > element (indeed, an eletric fence memory debugger wrapper element) to check for memory errors. </P ><P > During linking, your test application can use fixation or filtered caps as a way to drive a specific type of data to or from your element. This is a very simple and effective way of checking multiple types of input and output in your element. </P ><P > Running the pipeline happens through the <CODE CLASS="function" >gst_bin_iterate ()</CODE > function. Note that during running, you should connect to at least the <SPAN CLASS="QUOTE" >"error"</SPAN > and <SPAN CLASS="QUOTE" >"eos"</SPAN > signals on the pipeline and/or your plugin/element to check for correct handling of this. Also, you should add events into the pipeline and make sure your plugin handles these correctly (with respect to clocking, internal caching, etc.). </P ><P > Never forget to clean up memory in your plugin or your test application. When going to the NULL state, your element should clean up allocated memory and caches. Also, it should close down any references held to possible support libraries. Your application should <CODE CLASS="function" >unref ()</CODE > the pipeline and make sure it doesn't crash. </P ><PRE CLASS="programlisting" > #include <gst/gst.h> gint main (gint arcg, gchar *argv[]) { GstElement *pipeline, *filesrc, *decoder, *filter, *sink; /* initialization */ gst_init (&argc, &argv); /* create elements */ pipeline = gst_pipeline_new ("my_pipeline"); filesrc = gst_element_factory_make ("filesrc", "my_filesource"); decoder = gst_element_factory_make ("mad", "my_decoder"); filter = gst_element_factory_make ("my_filter", "my_filter"); sink = gst_element_factory_make ("osssink", "audiosink"); g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); /* link everything together */ gst_element_link_many (filesrc, decoder, filter, sink, NULL); gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, filter, sink, NULL); /* run */ gst_element_set_state (pipeline, GST_STATE_PLAYING); while (gst_bin_iterate (GST_BIN (pipeline))); /* clean up */ gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (GST_OBJECT (pipeline)); return 0; } </PRE ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="chapter-building-signals.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="chapter-building-filterfactory.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Signals</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="part-building.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Creating a Filter with a Filter Factory</TD ></TR ></TABLE ></DIV ></BODY ></HTML >