2000-08-21 21:23:27 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
static void
|
|
|
|
gst_play_have_type (GstElement *typefind, GstCaps *caps, GstElement *pipeline)
|
2000-08-21 21:23:27 +00:00
|
|
|
{
|
2001-07-07 13:32:43 +00:00
|
|
|
GstElement *osssink;
|
|
|
|
GstElement *new_element;
|
|
|
|
GstAutoplug *autoplug;
|
|
|
|
GstElement *autobin;
|
|
|
|
GstElement *disksrc;
|
|
|
|
GstElement *cache;
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
GST_DEBUG (0,"GstPipeline: play have type\n");
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
|
|
|
|
disksrc = gst_bin_get_by_name (GST_BIN (pipeline), "disk_source");
|
|
|
|
autobin = gst_bin_get_by_name (GST_BIN (pipeline), "autobin");
|
|
|
|
cache = gst_bin_get_by_name (GST_BIN (autobin), "cache");
|
|
|
|
|
|
|
|
// disconnect the typefind from the pipeline and remove it
|
|
|
|
gst_element_disconnect (cache, "src", typefind, "sink");
|
|
|
|
gst_bin_remove (GST_BIN (autobin), typefind);
|
|
|
|
|
|
|
|
/* and an audio sink */
|
|
|
|
osssink = gst_elementfactory_make("osssink", "play_audio");
|
|
|
|
g_assert(osssink != NULL);
|
|
|
|
|
|
|
|
autoplug = gst_autoplugfactory_make ("staticrender");
|
|
|
|
g_assert (autoplug != NULL);
|
|
|
|
|
|
|
|
new_element = gst_autoplug_to_renderers (autoplug,
|
|
|
|
caps,
|
|
|
|
osssink,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!new_element) {
|
|
|
|
g_print ("could not autoplug, no suitable codecs found...\n");
|
|
|
|
exit (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_name (new_element, "new_element");
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (autobin), new_element);
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (cache), "reset", TRUE, NULL);
|
|
|
|
|
|
|
|
gst_element_connect (cache, "src", new_element, "sink");
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2000-08-21 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
static void
|
|
|
|
gst_play_cache_empty (GstElement *element, GstElement *pipeline)
|
2000-08-21 21:23:27 +00:00
|
|
|
{
|
2001-07-07 13:32:43 +00:00
|
|
|
GstElement *autobin;
|
|
|
|
GstElement *disksrc;
|
|
|
|
GstElement *cache;
|
|
|
|
GstElement *new_element;
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
fprintf (stderr, "have cache empty\n");
|
2001-01-03 22:58:58 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
disksrc = gst_bin_get_by_name (GST_BIN (pipeline), "disk_source");
|
|
|
|
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");
|
2000-11-01 22:11:48 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
gst_element_disconnect (disksrc, "src", cache, "sink");
|
|
|
|
gst_element_disconnect (cache, "src", new_element, "sink");
|
|
|
|
gst_bin_remove (GST_BIN (autobin), cache);
|
|
|
|
gst_element_connect (disksrc, "src", new_element, "sink");
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2000-11-01 22:11:48 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
fprintf (stderr, "done with cache_empty\n");
|
|
|
|
}
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GstElement *disksrc;
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *autobin;
|
|
|
|
GstElement *typefind;
|
|
|
|
GstElement *cache;
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
gst_init (&argc, &argv);
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
g_print ("usage: %s <filename>\n", argv[0]);
|
|
|
|
exit (-1);
|
2000-08-21 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
/* create a new pipeline to hold the elements */
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
g_assert (pipeline != NULL);
|
|
|
|
|
|
|
|
/* create a disk reader */
|
|
|
|
disksrc = gst_elementfactory_make ("disksrc", "disk_source");
|
|
|
|
g_assert (disksrc != NULL);
|
|
|
|
g_object_set (G_OBJECT (disksrc), "location", argv[1], NULL);
|
|
|
|
gst_bin_add (GST_BIN (pipeline), disksrc);
|
|
|
|
|
|
|
|
autobin = gst_bin_new ("autobin");
|
|
|
|
cache = gst_elementfactory_make ("autoplugcache", "cache");
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT (cache), "cache_empty",
|
|
|
|
G_CALLBACK (gst_play_cache_empty), pipeline);
|
2001-07-07 13:32:43 +00:00
|
|
|
|
|
|
|
typefind = gst_elementfactory_make ("typefind", "typefind");
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT (typefind), "have_type",
|
|
|
|
G_CALLBACK (gst_play_have_type), pipeline);
|
2001-07-07 13:32:43 +00:00
|
|
|
gst_bin_add (GST_BIN (autobin), cache);
|
|
|
|
gst_bin_add (GST_BIN (autobin), typefind);
|
|
|
|
|
|
|
|
gst_element_connect (cache, "src", typefind, "sink");
|
|
|
|
gst_element_add_ghost_pad (autobin, gst_element_get_pad (cache, "sink"), "sink");
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN( pipeline), autobin);
|
|
|
|
gst_element_connect (disksrc, "src", autobin, "sink");
|
2001-03-02 17:56:02 +00:00
|
|
|
|
2000-08-21 21:23:27 +00:00
|
|
|
/* start playing */
|
2001-07-07 13:32:43 +00:00
|
|
|
gst_element_set_state( GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
while (gst_bin_iterate (GST_BIN (pipeline)));
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
/* stop the pipeline */
|
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
2000-08-21 21:23:27 +00:00
|
|
|
|
2001-07-07 13:32:43 +00:00
|
|
|
gst_object_unref (GST_OBJECT (pipeline));
|
2000-08-21 21:23:27 +00:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|