2002-01-28 01:47:31 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2002-02-05 17:08:08 +00:00
|
|
|
/* returns all factories which have a maximum of maxtemplates GstPadTemplates in direction dir
|
|
|
|
*/
|
|
|
|
GList *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_factories_at_most_templates (GList * factories, GstPadDirection dir,
|
|
|
|
guint maxtemplates)
|
2002-02-05 17:08:08 +00:00
|
|
|
{
|
|
|
|
GList *ret = NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
while (factories) {
|
2002-02-05 17:08:08 +00:00
|
|
|
guint count = 0;
|
|
|
|
GList *templs = ((GstElementFactory *) factories->data)->padtemplates;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (templs) {
|
|
|
|
if (GST_PAD_TEMPLATE_DIRECTION (templs->data) == dir) {
|
2004-03-15 19:27:17 +00:00
|
|
|
count++;
|
2002-02-05 17:08:08 +00:00
|
|
|
}
|
|
|
|
if (count > maxtemplates)
|
2004-03-15 19:27:17 +00:00
|
|
|
break;
|
2002-02-05 17:08:08 +00:00
|
|
|
templs = g_list_next (templs);
|
|
|
|
}
|
|
|
|
if (count <= maxtemplates)
|
|
|
|
ret = g_list_prepend (ret, factories->data);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-02-05 17:08:08 +00:00
|
|
|
factories = g_list_next (factories);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-02-06 18:58:53 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
property_change_callback (GObject * object, GstObject * orig,
|
|
|
|
GParamSpec * pspec)
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
2004-03-15 19:27:17 +00:00
|
|
|
GValue value = { 0, }; /* the important thing is that value.type = 0 */
|
2002-02-06 18:58:53 +00:00
|
|
|
gchar *str = 0;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-02-06 18:58:53 +00:00
|
|
|
if (pspec->flags & G_PARAM_READABLE) {
|
2004-03-13 15:27:01 +00:00
|
|
|
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
2002-02-06 18:58:53 +00:00
|
|
|
g_object_get_property (G_OBJECT (orig), pspec->name, &value);
|
|
|
|
if (G_IS_PARAM_SPEC_STRING (pspec))
|
|
|
|
str = g_value_dup_string (&value);
|
|
|
|
else if (G_IS_PARAM_SPEC_ENUM (pspec))
|
|
|
|
str = g_strdup_printf ("%d", g_value_get_enum (&value));
|
|
|
|
else if (G_IS_PARAM_SPEC_INT64 (pspec))
|
2003-02-01 20:29:27 +00:00
|
|
|
str = g_strdup_printf ("%" G_GINT64_FORMAT, g_value_get_int64 (&value));
|
2002-02-06 18:58:53 +00:00
|
|
|
else
|
|
|
|
str = g_strdup_value_contents (&value);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-02-06 18:58:53 +00:00
|
|
|
g_print ("%s: %s = %s\n", GST_OBJECT_NAME (orig), pspec->name, str);
|
|
|
|
g_free (str);
|
2004-03-13 15:27:01 +00:00
|
|
|
g_value_unset (&value);
|
2002-02-06 18:58:53 +00:00
|
|
|
} else {
|
|
|
|
g_warning ("Parameter not readable. What's up with that?");
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-06 18:58:53 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
error_callback (GObject * object, GstObject * orig, gchar * error)
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
2002-02-06 18:58:53 +00:00
|
|
|
g_print ("ERROR: %s: %s\n", GST_OBJECT_NAME (orig), error);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
2002-04-18 19:30:55 +00:00
|
|
|
/*
|
2002-01-28 01:47:31 +00:00
|
|
|
* Test program for the autoplugger.
|
|
|
|
* Uses new API extensions (2002-01-28), too.
|
|
|
|
*
|
|
|
|
* USAGE: spidertest <mediafile>
|
|
|
|
* If mediafile can be recognized, xvideo and oss audio output are tried.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
|
|
|
GstElement *bin, *filesrc, *decoder, *osssink, *videosink;
|
2002-02-05 17:08:08 +00:00
|
|
|
GList *facs;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-02-05 17:08:08 +00:00
|
|
|
if (argc < 2) {
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("usage: %s <file>\n", argv[0]);
|
|
|
|
exit (-1);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_init (&argc, &argv);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
/* create a new bin to hold the elements */
|
2004-03-13 15:27:01 +00:00
|
|
|
bin = gst_pipeline_new ("pipeline");
|
|
|
|
g_signal_connect (bin, "deep_notify", G_CALLBACK (property_change_callback),
|
|
|
|
NULL);
|
2002-02-06 18:58:53 +00:00
|
|
|
g_signal_connect (bin, "error", G_CALLBACK (error_callback), NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
/* create a disk reader */
|
2004-03-13 15:27:01 +00:00
|
|
|
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
|
|
|
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
/* now it's time to get the decoder */
|
2004-03-13 15:27:01 +00:00
|
|
|
decoder = gst_element_factory_make ("spider", "spider");
|
2002-01-28 01:47:31 +00:00
|
|
|
if (!decoder) {
|
|
|
|
g_print ("could not find plugin \"spider\"\n");
|
|
|
|
exit (-2);
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
/* only use decoding plugins */
|
2002-02-05 17:08:08 +00:00
|
|
|
g_object_get (decoder, "factories", &facs, NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
facs = gst_factories_at_most_templates (facs, GST_PAD_SINK, 1);
|
2002-02-05 17:08:08 +00:00
|
|
|
g_object_set (decoder, "factories", facs, NULL);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
/* create video and audio sink */
|
2004-03-13 15:27:01 +00:00
|
|
|
osssink = gst_element_factory_make ("osssink", "audio");
|
|
|
|
videosink = gst_element_factory_make ("xvideosink", "video");
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
if ((!osssink) || (!videosink)) {
|
|
|
|
g_print ("could not create output plugins\n");
|
|
|
|
exit (-3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add objects to the main pipeline */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_bin_add (GST_BIN (bin), filesrc);
|
|
|
|
gst_bin_add (GST_BIN (bin), decoder);
|
|
|
|
gst_bin_add (GST_BIN (bin), osssink);
|
|
|
|
gst_bin_add (GST_BIN (bin), videosink);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2003-01-09 20:02:34 +00:00
|
|
|
/* link objects */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!(gst_element_link (filesrc, decoder) &&
|
2004-03-15 19:27:17 +00:00
|
|
|
gst_element_link (decoder, osssink) &&
|
|
|
|
gst_element_link (decoder, videosink))) {
|
2003-01-09 20:02:34 +00:00
|
|
|
g_print ("the pipeline could not be linked\n");
|
2002-01-28 01:47:31 +00:00
|
|
|
exit (-4);
|
|
|
|
}
|
|
|
|
|
2002-04-04 19:28:23 +00:00
|
|
|
/* gst_bin_use_clock (GST_BIN (bin), gst_system_clock_obtain ());*/
|
2002-02-03 20:07:09 +00:00
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
/* start playing */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_element_set_state (bin, GST_STATE_PLAYING);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
while (gst_bin_iterate (GST_BIN (bin)));
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
exit (0);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|