2000-10-08 22:23:12 +00:00
|
|
|
#include <gst/gst.h>
|
2000-10-09 20:01:17 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
static void
|
|
|
|
gst_play_have_type (GstElement *typefind, GstCaps *caps, GstElement *pipeline)
|
2000-10-08 22:23:12 +00:00
|
|
|
{
|
2001-06-27 20:19:00 +00:00
|
|
|
GstElement *osssink, *videosink, *videoelement, *colorspace;
|
2001-03-13 18:57:25 +00:00
|
|
|
GstElement *new_element;
|
|
|
|
GstAutoplug *autoplug;
|
2001-05-25 21:00:07 +00:00
|
|
|
GstElement *autobin;
|
2002-01-05 23:05:56 +00:00
|
|
|
GstElement *filesrc;
|
2001-05-25 21:00:07 +00:00
|
|
|
GstElement *cache;
|
2000-10-08 22:23:12 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ("GstPipeline: play have type");
|
2000-10-08 22:23:12 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
2001-03-13 18:57:25 +00:00
|
|
|
|
2002-01-05 23:05:56 +00:00
|
|
|
filesrc = gst_bin_get_by_name (GST_BIN (pipeline), "disk_source");
|
2001-05-25 21:00:07 +00:00
|
|
|
autobin = gst_bin_get_by_name (GST_BIN (pipeline), "autobin");
|
|
|
|
cache = gst_bin_get_by_name (GST_BIN (autobin), "cache");
|
2001-03-13 18:57:25 +00:00
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* unlink the typefind from the pipeline and remove it */
|
|
|
|
gst_element_unlink_pads (cache, "src", typefind, "sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_remove (GST_BIN (autobin), typefind);
|
|
|
|
|
2000-10-08 22:23:12 +00:00
|
|
|
/* and an audio sink */
|
2002-04-11 20:35:18 +00:00
|
|
|
osssink = gst_element_factory_make ("osssink", "play_audio");
|
2002-04-07 23:32:16 +00:00
|
|
|
g_assert (osssink != NULL);
|
2000-10-08 22:23:12 +00:00
|
|
|
|
2001-06-27 20:19:00 +00:00
|
|
|
videosink = gst_bin_new ("videosink");
|
2000-10-08 22:23:12 +00:00
|
|
|
/* and an video sink */
|
2002-04-11 20:35:18 +00:00
|
|
|
videoelement = gst_element_factory_make ("xvideosink", "play_video");
|
2002-04-07 23:32:16 +00:00
|
|
|
g_assert (videosink != NULL);
|
2000-10-08 22:23:12 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
colorspace = gst_element_factory_make ("colorspace", "colorspace");
|
2002-04-07 23:32:16 +00:00
|
|
|
g_assert (colorspace != NULL);
|
2001-06-27 20:19:00 +00:00
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_element_link_pads (colorspace, "src", videoelement, "sink");
|
2001-06-27 20:19:00 +00:00
|
|
|
gst_bin_add (GST_BIN (videosink), colorspace);
|
|
|
|
gst_bin_add (GST_BIN (videosink), videoelement);
|
|
|
|
|
|
|
|
gst_element_add_ghost_pad (videosink,
|
|
|
|
gst_element_get_pad (colorspace, "sink"), "sink");
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
autoplug = gst_autoplug_factory_make ("staticrender");
|
2001-03-13 18:57:25 +00:00
|
|
|
g_assert (autoplug != NULL);
|
|
|
|
|
|
|
|
new_element = gst_autoplug_to_renderers (autoplug,
|
2001-05-25 21:00:07 +00:00
|
|
|
caps,
|
2001-03-13 18:57:25 +00:00
|
|
|
videosink,
|
2001-03-24 17:22:03 +00:00
|
|
|
osssink,
|
2001-03-13 18:57:25 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!new_element) {
|
|
|
|
g_print ("could not autoplug, no suitable codecs found...\n");
|
|
|
|
exit (-1);
|
|
|
|
}
|
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_name (new_element, "new_element");
|
2001-04-21 17:45:56 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add (GST_BIN (autobin), new_element);
|
2001-03-13 18:57:25 +00:00
|
|
|
|
2002-01-17 20:56:12 +00:00
|
|
|
g_object_set (G_OBJECT (cache), "reset", TRUE, NULL);
|
2001-03-13 18:57:25 +00:00
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_element_link_pads (cache, "src", new_element, "sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2002-01-11 15:49:47 +00:00
|
|
|
gst_xml_write_file (GST_ELEMENT (pipeline), fopen ("xmlTest.gst", "w"));
|
2001-10-17 10:21:27 +00:00
|
|
|
#endif
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_cache_empty (GstElement *element, GstElement *pipeline)
|
|
|
|
{
|
|
|
|
GstElement *autobin;
|
2002-01-05 23:05:56 +00:00
|
|
|
GstElement *filesrc;
|
2001-05-25 21:00:07 +00:00
|
|
|
GstElement *cache;
|
|
|
|
GstElement *new_element;
|
|
|
|
|
|
|
|
fprintf (stderr, "have cache empty\n");
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
|
2002-01-05 23:05:56 +00:00
|
|
|
filesrc = gst_bin_get_by_name (GST_BIN (pipeline), "disk_source");
|
2001-05-25 21:00:07 +00:00
|
|
|
autobin = gst_bin_get_by_name (GST_BIN (pipeline), "autobin");
|
|
|
|
cache = gst_bin_get_by_name (GST_BIN (autobin), "cache");
|
|
|
|
new_element = gst_bin_get_by_name (GST_BIN (autobin), "new_element");
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_element_unlink_many (filesrc, cache, new_element, NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_remove (GST_BIN (autobin), cache);
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_element_link_pads (filesrc, "src", new_element, "sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
fprintf (stderr, "done with cache_empty\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc,char *argv[])
|
|
|
|
{
|
2002-01-05 23:05:56 +00:00
|
|
|
GstElement *filesrc;
|
2001-05-25 21:00:07 +00:00
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *autobin;
|
|
|
|
GstElement *typefind;
|
|
|
|
GstElement *cache;
|
|
|
|
|
|
|
|
g_thread_init(NULL);
|
|
|
|
gst_init(&argc,&argv);
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
g_print("usage: %s <filename>\n", argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new pipeline to hold the elements */
|
|
|
|
pipeline = gst_pipeline_new("pipeline");
|
|
|
|
g_assert(pipeline != NULL);
|
2000-10-08 22:23:12 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
/* create a disk reader */
|
2002-04-11 20:35:18 +00:00
|
|
|
filesrc = gst_element_factory_make("filesrc", "disk_source");
|
2002-01-05 23:05:56 +00:00
|
|
|
g_assert(filesrc != NULL);
|
2002-01-17 20:56:12 +00:00
|
|
|
g_object_set(G_OBJECT(filesrc),"location", argv[1],NULL);
|
2002-01-05 23:05:56 +00:00
|
|
|
gst_bin_add (GST_BIN (pipeline), filesrc);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
autobin = gst_bin_new ("autobin");
|
2002-04-11 20:35:18 +00:00
|
|
|
cache = gst_element_factory_make ("autoplugcache", "cache");
|
2002-01-17 20:56:12 +00:00
|
|
|
g_signal_connect (G_OBJECT (cache), "cache_empty", G_CALLBACK (gst_play_cache_empty), pipeline);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
typefind = gst_element_factory_make ("typefind", "typefind");
|
2002-01-17 20:56:12 +00:00
|
|
|
g_signal_connect (G_OBJECT (typefind), "have_type", G_CALLBACK (gst_play_have_type), pipeline);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add (GST_BIN (autobin), cache);
|
|
|
|
gst_bin_add (GST_BIN (autobin), typefind);
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_element_link_pads (cache, "src", typefind, "sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_add_ghost_pad (autobin, gst_element_get_pad (cache, "sink"), "sink");
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN( pipeline), autobin);
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_element_link_pads (filesrc, "src", autobin, "sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
/* start playing */
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
2000-10-09 20:01:17 +00:00
|
|
|
|
2002-01-17 20:56:12 +00:00
|
|
|
while (gst_bin_iterate (GST_BIN (pipeline)));
|
2000-10-08 22:23:12 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
/* stop the pipeline */
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
2000-10-08 22:23:12 +00:00
|
|
|
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (pipeline));
|
2000-10-08 22:23:12 +00:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|