Updated the autoplug example with the new autoplugger. there still is a scheduling issue though.

Original commit message from CVS:
Updated the autoplug example with the new autoplugger. there still is
a scheduling issue though.
This commit is contained in:
Wim Taymans 2001-03-13 18:57:25 +00:00
parent 0bb78cefa8
commit 29a006c8d8
2 changed files with 162 additions and 64 deletions

View file

@ -1,26 +1,64 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gnome.h> #include <gnome.h>
static gboolean playing; static void
gst_play_have_type (GstElement *sink, GstElement *sink2, gpointer data)
/* eos will be called when the src element has an end of stream */
void eos(GstElement *element)
{ {
g_print("have eos, quitting\n"); GST_DEBUG (0,"GstPipeline: play have type %p\n", (gboolean *)data);
playing = FALSE; *(gboolean *)data = TRUE;
} }
gboolean idle_func(gpointer data) { gboolean idle_func(gpointer data) {
gst_bin_iterate(GST_BIN(data)); return gst_bin_iterate(GST_BIN(data));
return TRUE; }
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;
} }
int main(int argc,char *argv[]) int main(int argc,char *argv[])
{ {
GstElement *disksrc, *audiosink, *videosink; GstElement *disksrc, *audiosink, *videosink;
GstElement *pipeline; GstElement *bin;
GtkWidget *appwindow; GtkWidget *appwindow;
GstCaps *srccaps;
GstElement *new_element;
GstAutoplug *autoplug;
g_thread_init(NULL); g_thread_init(NULL);
gst_init(&argc,&argv); gst_init(&argc,&argv);
@ -32,15 +70,22 @@ int main(int argc,char *argv[])
} }
/* create a new bin to hold the elements */ /* create a new bin to hold the elements */
pipeline = gst_pipeline_new("pipeline"); bin = gst_bin_new("bin");
g_assert(pipeline != NULL); g_assert(bin != NULL);
/* create a disk reader */ /* create a disk reader */
disksrc = gst_elementfactory_make("disksrc", "disk_source"); disksrc = gst_elementfactory_make("disksrc", "disk_source");
g_assert(disksrc != NULL); g_assert(disksrc != NULL);
gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL); gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL);
gtk_signal_connect(GTK_OBJECT(disksrc),"eos",
GTK_SIGNAL_FUNC(eos),NULL); gst_bin_add (GST_BIN (bin), disksrc);
srccaps = gst_play_typefind (GST_BIN (bin), disksrc);
if (!srccaps) {
g_print ("could not autoplug, unknown media type...\n");
exit (-1);
}
/* and an audio sink */ /* and an audio sink */
audiosink = gst_elementfactory_make("audiosink", "play_audio"); audiosink = gst_elementfactory_make("audiosink", "play_audio");
@ -51,38 +96,42 @@ int main(int argc,char *argv[])
g_assert(videosink != NULL); g_assert(videosink != NULL);
gtk_object_set(GTK_OBJECT(videosink),"xv_enabled", FALSE,NULL); gtk_object_set(GTK_OBJECT(videosink),"xv_enabled", FALSE,NULL);
autoplug = gst_autoplugfactory_make ("staticrender");
g_assert (autoplug != NULL);
new_element = gst_autoplug_to_renderers (autoplug,
srccaps,
videosink,
audiosink,
NULL);
if (!new_element) {
g_print ("could not autoplug, no suitable codecs found...\n");
exit (-1);
}
gst_bin_add (GST_BIN (bin), new_element);
gst_element_connect (disksrc, "src", new_element, "sink");
appwindow = gnome_app_new("autoplug demo","autoplug demo"); appwindow = gnome_app_new("autoplug demo","autoplug demo");
gnome_app_set_contents(GNOME_APP(appwindow), gnome_app_set_contents(GNOME_APP(appwindow),
gst_util_get_widget_arg(GTK_OBJECT(videosink),"widget")); gst_util_get_widget_arg(GTK_OBJECT(videosink),"widget"));
gtk_widget_show_all(appwindow); gtk_widget_show_all(appwindow);
/* add objects to the main pipeline */ xmlSaveFile("xmlTest.gst", gst_xml_write(GST_ELEMENT(bin)));
/*
gst_pipeline_add_src(GST_PIPELINE(pipeline), disksrc);
gst_pipeline_add_sink(GST_PIPELINE(pipeline), videosink);
gst_pipeline_add_sink(GST_PIPELINE(pipeline), audiosink);
if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) {
g_print("unable to handle stream\n");
exit(-1);
}
*/
xmlSaveFile("xmlTest.gst", gst_xml_write(GST_ELEMENT(pipeline)));
/* start playing */ /* start playing */
gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING); gst_element_set_state(GST_ELEMENT(bin), GST_STATE_PLAYING);
playing = TRUE; gtk_idle_add(idle_func, bin);
gtk_idle_add(idle_func, pipeline);
gst_main(); gst_main();
/* stop the bin */ /* stop the bin */
gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL); gst_element_set_state(GST_ELEMENT(bin), GST_STATE_NULL);
gst_pipeline_destroy(pipeline); gst_pipeline_destroy(bin);
exit(0); exit(0);
} }

View file

@ -1,26 +1,64 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gnome.h> #include <gnome.h>
static gboolean playing; static void
gst_play_have_type (GstElement *sink, GstElement *sink2, gpointer data)
/* eos will be called when the src element has an end of stream */
void eos(GstElement *element)
{ {
g_print("have eos, quitting\n"); GST_DEBUG (0,"GstPipeline: play have type %p\n", (gboolean *)data);
playing = FALSE; *(gboolean *)data = TRUE;
} }
gboolean idle_func(gpointer data) { gboolean idle_func(gpointer data) {
gst_bin_iterate(GST_BIN(data)); return gst_bin_iterate(GST_BIN(data));
return TRUE; }
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;
} }
int main(int argc,char *argv[]) int main(int argc,char *argv[])
{ {
GstElement *disksrc, *audiosink, *videosink; GstElement *disksrc, *audiosink, *videosink;
GstElement *pipeline; GstElement *bin;
GtkWidget *appwindow; GtkWidget *appwindow;
GstCaps *srccaps;
GstElement *new_element;
GstAutoplug *autoplug;
g_thread_init(NULL); g_thread_init(NULL);
gst_init(&argc,&argv); gst_init(&argc,&argv);
@ -32,15 +70,22 @@ int main(int argc,char *argv[])
} }
/* create a new bin to hold the elements */ /* create a new bin to hold the elements */
pipeline = gst_pipeline_new("pipeline"); bin = gst_bin_new("bin");
g_assert(pipeline != NULL); g_assert(bin != NULL);
/* create a disk reader */ /* create a disk reader */
disksrc = gst_elementfactory_make("disksrc", "disk_source"); disksrc = gst_elementfactory_make("disksrc", "disk_source");
g_assert(disksrc != NULL); g_assert(disksrc != NULL);
gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL); gtk_object_set(GTK_OBJECT(disksrc),"location", argv[1],NULL);
gtk_signal_connect(GTK_OBJECT(disksrc),"eos",
GTK_SIGNAL_FUNC(eos),NULL); gst_bin_add (GST_BIN (bin), disksrc);
srccaps = gst_play_typefind (GST_BIN (bin), disksrc);
if (!srccaps) {
g_print ("could not autoplug, unknown media type...\n");
exit (-1);
}
/* and an audio sink */ /* and an audio sink */
audiosink = gst_elementfactory_make("audiosink", "play_audio"); audiosink = gst_elementfactory_make("audiosink", "play_audio");
@ -51,38 +96,42 @@ int main(int argc,char *argv[])
g_assert(videosink != NULL); g_assert(videosink != NULL);
gtk_object_set(GTK_OBJECT(videosink),"xv_enabled", FALSE,NULL); gtk_object_set(GTK_OBJECT(videosink),"xv_enabled", FALSE,NULL);
autoplug = gst_autoplugfactory_make ("staticrender");
g_assert (autoplug != NULL);
new_element = gst_autoplug_to_renderers (autoplug,
srccaps,
videosink,
audiosink,
NULL);
if (!new_element) {
g_print ("could not autoplug, no suitable codecs found...\n");
exit (-1);
}
gst_bin_add (GST_BIN (bin), new_element);
gst_element_connect (disksrc, "src", new_element, "sink");
appwindow = gnome_app_new("autoplug demo","autoplug demo"); appwindow = gnome_app_new("autoplug demo","autoplug demo");
gnome_app_set_contents(GNOME_APP(appwindow), gnome_app_set_contents(GNOME_APP(appwindow),
gst_util_get_widget_arg(GTK_OBJECT(videosink),"widget")); gst_util_get_widget_arg(GTK_OBJECT(videosink),"widget"));
gtk_widget_show_all(appwindow); gtk_widget_show_all(appwindow);
/* add objects to the main pipeline */ xmlSaveFile("xmlTest.gst", gst_xml_write(GST_ELEMENT(bin)));
/*
gst_pipeline_add_src(GST_PIPELINE(pipeline), disksrc);
gst_pipeline_add_sink(GST_PIPELINE(pipeline), videosink);
gst_pipeline_add_sink(GST_PIPELINE(pipeline), audiosink);
if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) {
g_print("unable to handle stream\n");
exit(-1);
}
*/
xmlSaveFile("xmlTest.gst", gst_xml_write(GST_ELEMENT(pipeline)));
/* start playing */ /* start playing */
gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING); gst_element_set_state(GST_ELEMENT(bin), GST_STATE_PLAYING);
playing = TRUE; gtk_idle_add(idle_func, bin);
gtk_idle_add(idle_func, pipeline);
gst_main(); gst_main();
/* stop the bin */ /* stop the bin */
gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL); gst_element_set_state(GST_ELEMENT(bin), GST_STATE_NULL);
gst_pipeline_destroy(pipeline); gst_pipeline_destroy(bin);
exit(0); exit(0);
} }