2001-05-25 21:00:07 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
GstElement *pipeline, *src, *autobin, *cache, *typefind, *decoder, *sink;
|
|
|
|
|
|
|
|
void cache_empty(GstElement *element, gpointer private) {
|
|
|
|
fprintf(stderr,"have cache empty\n");
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_disconnect_pads (src,"src",cache,"sink");
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_scheduler_show (GST_ELEMENT_SCHED(pipeline));
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_disconnect_pads (cache,"src",decoder,"sink");
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_scheduler_show (GST_ELEMENT_SCHED(pipeline));
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_remove (GST_BIN(autobin), cache);
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_scheduler_show (GST_ELEMENT_SCHED(pipeline));
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_connect_pads (src,"src",decoder,"sink");
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_scheduler_show (GST_ELEMENT_SCHED(pipeline));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_scheduler_show (GST_ELEMENT_SCHED(pipeline));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
fprintf(stderr,"done with cache_empty\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void have_type(GstElement *element, GstCaps *caps, GstCaps **private_caps) {
|
|
|
|
fprintf(stderr,"have caps, mime type is %s\n",gst_caps_get_mime(caps));
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* disconnect the typefind from the pipeline and remove it */
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_disconnect(cache,typefind);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_remove(GST_BIN(autobin),typefind);
|
|
|
|
|
2001-12-04 22:12:50 +00:00
|
|
|
gst_scheduler_show (GST_ELEMENT_SCHED(pipeline));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
if (strstr(gst_caps_get_mime(caps),"mp3")) {
|
2002-04-11 20:35:18 +00:00
|
|
|
decoder = gst_element_factory_make ("mad","decoder");
|
|
|
|
sink = gst_element_factory_make ("osssink","sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add(GST_BIN(autobin),decoder);
|
|
|
|
gst_bin_add(GST_BIN(autobin),sink);
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_connect_pads(decoder,"src",sink,"sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
g_object_set (G_OBJECT(cache), "reset", TRUE, NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_connect_pads(cache,"src",decoder,"sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
else if (strstr(gst_caps_get_mime(caps),"x-ogg")) {
|
2002-04-11 20:35:18 +00:00
|
|
|
decoder = gst_element_factory_make ("vorbisdec","decoder");
|
|
|
|
sink = gst_element_factory_make ("osssink","sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add(GST_BIN(autobin),decoder);
|
|
|
|
gst_bin_add(GST_BIN(autobin),sink);
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_connect_pads(decoder,"src",sink,"sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
g_object_set (G_OBJECT(cache), "reset", TRUE, NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_connect_pads(cache,"src",decoder,"sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
fprintf(stderr,"done with have_type signal\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc,char *argv[]) {
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_init(&argc,&argv);
|
|
|
|
|
|
|
|
pipeline = gst_pipeline_new("pipeline");
|
2002-04-11 20:35:18 +00:00
|
|
|
src = gst_element_factory_make ("filesrc","src");
|
2001-06-25 01:20:11 +00:00
|
|
|
g_object_set(G_OBJECT(src),"location",argv[1],NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add (GST_BIN(pipeline),src);
|
|
|
|
|
|
|
|
autobin = gst_bin_new("autobin");
|
2002-04-11 20:35:18 +00:00
|
|
|
cache = gst_element_factory_make ("autoplugcache","cache");
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT(cache),"cache_empty",(GCallback)cache_empty,NULL);
|
2002-04-11 20:35:18 +00:00
|
|
|
typefind = gst_element_factory_make ("typefind", "typefind");
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT(typefind),"have_type",(GCallback)have_type,&caps);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add (GST_BIN(autobin),cache);
|
|
|
|
gst_bin_add (GST_BIN(autobin),typefind);
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_connect_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);
|
2002-04-07 23:32:16 +00:00
|
|
|
gst_element_connect_pads (src,"src",autobin,"sink");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
gst_element_set_state(pipeline,GST_STATE_PLAYING);
|
|
|
|
|
2002-04-07 23:32:16 +00:00
|
|
|
while (gst_bin_iterate(GST_BIN(pipeline)));
|
|
|
|
|
|
|
|
return 0;
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|