diff options
Diffstat (limited to 'tests/old/examples/autoplug/autoplug.c')
-rw-r--r-- | tests/old/examples/autoplug/autoplug.c | 210 |
1 files changed, 116 insertions, 94 deletions
diff --git a/tests/old/examples/autoplug/autoplug.c b/tests/old/examples/autoplug/autoplug.c index e9135fb8d..70ac4b7a2 100644 --- a/tests/old/examples/autoplug/autoplug.c +++ b/tests/old/examples/autoplug/autoplug.c @@ -2,94 +2,36 @@ #include <gnome.h> static void -gst_play_have_type (GstElement *sink, GstElement *sink2, gpointer data) +autoplug_have_size (GstElement *element, guint width, guint height, + GtkWidget *socket) { - GST_DEBUG (0,"GstPipeline: play have type %p\n", (gboolean *)data); - - *(gboolean *)data = TRUE; -} - -gboolean -idle_func (gpointer data) -{ - return gst_bin_iterate (GST_BIN (data)); -} - -static GstCaps* -gst_play_typefind (GstBin *bin, GstElement *element) -{ - gboolean found = FALSE; - GstElement *typefind; - GstCaps *caps = NULL; - - GST_DEBUG (0,"GstPipeline: typefind for element \"%s\" %p\n", - GST_ELEMENT_NAME(element), &found); - - typefind = gst_elementfactory_make ("typefind", "typefind"); - g_return_val_if_fail (typefind != NULL, FALSE); - - gtk_signal_connect (GTK_OBJECT (typefind), "have_type", - GTK_SIGNAL_FUNC (gst_play_have_type), &found); - - gst_pad_connect (gst_element_get_pad (element, "src"), - gst_element_get_pad (typefind, "sink")); - - gst_bin_add (bin, typefind); - - gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING); - - // push a buffer... the have_type signal handler will set the found flag - gst_bin_iterate (bin); - - gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL); - - caps = gst_pad_get_caps (gst_element_get_pad (element, "src")); - - gst_pad_disconnect (gst_element_get_pad (element, "src"), - gst_element_get_pad (typefind, "sink")); - gst_bin_remove (bin, typefind); - gst_object_unref (GST_OBJECT (typefind)); - - return caps; + gtk_widget_set_usize(socket,width,height); } -int main(int argc,char *argv[]) +static void +gst_play_have_type (GstElement *typefind, GstCaps *caps, GstElement *pipeline) { - GstElement *disksrc, *osssink, *videosink; - GstElement *bin; + GstElement *osssink, *videosink; GtkWidget *appwindow; - GstCaps *srccaps; GstElement *new_element; GstAutoplug *autoplug; GtkWidget *socket; + GstElement *autobin; + GstElement *disksrc; + GstElement *cache; - g_thread_init(NULL); - gst_init(&argc,&argv); - gnome_init("autoplug","0.0.1", argc,argv); - - if (argc != 2) { - g_print("usage: %s <filename>\n", argv[0]); - exit(-1); - } - - /* create a new bin to hold the elements */ - bin = gst_pipeline_new("pipeline"); - g_assert(bin != NULL); - - /* create a disk reader */ - disksrc = gst_elementfactory_make("disksrc", "disk_source"); - g_assert(disksrc != NULL); - gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL); + GST_DEBUG (0,"GstPipeline: play have type\n"); - gst_bin_add (GST_BIN (bin), disksrc); + gst_element_set_state (pipeline, GST_STATE_PAUSED); - srccaps = gst_play_typefind (GST_BIN (bin), disksrc); + 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"); - if (!srccaps) { - g_print ("could not autoplug, unknown media type...\n"); - exit (-1); - } - + // 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); @@ -102,7 +44,7 @@ int main(int argc,char *argv[]) g_assert (autoplug != NULL); new_element = gst_autoplug_to_renderers (autoplug, - srccaps, + caps, videosink, osssink, NULL); @@ -112,42 +54,122 @@ int main(int argc,char *argv[]) exit (-1); } - gst_bin_remove (GST_BIN (bin), disksrc); - // FIXME hack, reparent the disksrc so the scheduler doesn't break - bin = gst_pipeline_new("pipeline"); + gst_element_set_name (new_element, "new_element"); - gst_bin_add (GST_BIN (bin), disksrc); - gst_bin_add (GST_BIN (bin), new_element); + gst_bin_add (GST_BIN (autobin), new_element); - gst_element_connect (disksrc, "src", new_element, "sink"); + gtk_object_set (GTK_OBJECT (cache), "reset", TRUE, NULL); - appwindow = gnome_app_new("autoplug demo","autoplug demo"); + gst_element_connect (cache, "src", new_element, "sink"); + + appwindow = gnome_app_new ("autoplug demo","autoplug demo"); socket = gtk_socket_new (); gtk_widget_show (socket); - gnome_app_set_contents(GNOME_APP(appwindow), + gnome_app_set_contents (GNOME_APP (appwindow), GTK_WIDGET (socket)); gtk_widget_realize (socket); gtk_socket_steal (GTK_SOCKET (socket), gst_util_get_int_arg (GTK_OBJECT (videosink), "xid")); + gtk_widget_set_usize(socket,320,240); - gtk_widget_show_all(appwindow); + gtk_widget_show_all (appwindow); - xmlSaveFile("xmlTest.gst", gst_xml_write(GST_ELEMENT(bin))); + gtk_signal_connect (GTK_OBJECT (videosink), "have_size", + GTK_SIGNAL_FUNC (autoplug_have_size), socket); - /* start playing */ - gst_element_set_state(GST_ELEMENT(bin), GST_STATE_PLAYING); + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + xmlSaveFile("xmlTest.gst", gst_xml_write (GST_ELEMENT (pipeline))); +} + +gboolean +idle_func (gpointer data) +{ + return gst_bin_iterate (GST_BIN (data)); +} + +static void +gst_play_cache_empty (GstElement *element, GstElement *pipeline) +{ + GstElement *autobin; + GstElement *disksrc; + GstElement *cache; + GstElement *new_element; + + fprintf (stderr, "have cache empty\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"); + new_element = gst_bin_get_by_name (GST_BIN (autobin), "new_element"); + + 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"); + + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + fprintf (stderr, "done with cache_empty\n"); +} + +int main(int argc,char *argv[]) +{ + GstElement *disksrc; + GstElement *pipeline; + GstElement *autobin; + GstElement *typefind; + GstElement *cache; + + g_thread_init(NULL); + gst_init(&argc,&argv); + gnome_init("autoplug","0.0.1", 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); - gtk_idle_add(idle_func, bin); + /* create a disk reader */ + disksrc = gst_elementfactory_make("disksrc", "disk_source"); + g_assert(disksrc != NULL); + gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL); + gst_bin_add (GST_BIN (pipeline), disksrc); + + autobin = gst_bin_new ("autobin"); + cache = gst_elementfactory_make ("autoplugcache", "cache"); + gtk_signal_connect (GTK_OBJECT (cache), "cache_empty", GTK_SIGNAL_FUNC (gst_play_cache_empty), pipeline); + + typefind = gst_elementfactory_make ("typefind", "typefind"); + gtk_signal_connect (GTK_OBJECT (typefind), "have_type", GTK_SIGNAL_FUNC (gst_play_have_type), pipeline); + 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"); + + /* start playing */ + gst_element_set_state( GST_ELEMENT (pipeline), GST_STATE_PLAYING); - gst_main(); + gtk_idle_add (idle_func, pipeline); + gst_main (); - /* stop the bin */ - gst_element_set_state(GST_ELEMENT(bin), GST_STATE_NULL); + /* stop the pipeline */ + gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); - gst_pipeline_destroy(bin); + gst_object_unref (GST_OBJECT (pipeline)); exit(0); } |