2001-05-06 17:33:57 +00:00
|
|
|
#include <gst/gst.h>
|
2001-05-10 08:16:36 +00:00
|
|
|
#include <string.h>
|
2001-05-06 17:33:57 +00:00
|
|
|
|
|
|
|
GstElement *pipeline, *src, *autobin, *cache, *typefind, *decoder, *sink;
|
|
|
|
|
2001-05-07 21:46:15 +00:00
|
|
|
void cache_empty(GstElement *element, gpointer private) {
|
|
|
|
fprintf(stderr,"have cache empty\n");
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
|
|
|
|
gst_element_disconnect(src,"src",cache,"sink");
|
|
|
|
gst_schedule_show (GST_ELEMENT_SCHED(pipeline));
|
|
|
|
gst_element_disconnect(cache,"src",decoder,"sink");
|
|
|
|
gst_schedule_show (GST_ELEMENT_SCHED(pipeline));
|
|
|
|
gst_bin_remove (GST_BIN(autobin), cache);
|
|
|
|
gst_schedule_show (GST_ELEMENT_SCHED(pipeline));
|
|
|
|
gst_element_connect(src,"src",decoder,"sink");
|
|
|
|
gst_schedule_show (GST_ELEMENT_SCHED(pipeline));
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
gst_schedule_show (GST_ELEMENT_SCHED(pipeline));
|
|
|
|
|
|
|
|
fprintf(stderr,"done with cache_empty\n");
|
|
|
|
}
|
|
|
|
|
2001-05-06 17:33:57 +00:00
|
|
|
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-05-06 22:12:00 +00:00
|
|
|
// disconnect the typefind from the pipeline and remove it
|
2001-05-06 17:33:57 +00:00
|
|
|
gst_element_disconnect(cache,"src",typefind,"sink");
|
2001-05-06 18:03:49 +00:00
|
|
|
gst_bin_remove(GST_BIN(autobin),typefind);
|
2001-05-06 17:33:57 +00:00
|
|
|
|
2001-05-06 22:12:00 +00:00
|
|
|
gst_schedule_show (GST_ELEMENT_SCHED(pipeline));
|
|
|
|
|
|
|
|
if (strstr(gst_caps_get_mime(caps),"mp3")) {
|
2001-05-06 17:33:57 +00:00
|
|
|
decoder = gst_elementfactory_make ("mad","decoder");
|
2001-05-07 21:46:15 +00:00
|
|
|
sink = gst_elementfactory_make ("osssink","sink");
|
2001-05-06 17:33:57 +00:00
|
|
|
gst_bin_add(GST_BIN(autobin),decoder);
|
|
|
|
gst_bin_add(GST_BIN(autobin),sink);
|
|
|
|
gst_element_connect(decoder,"src",sink,"sink");
|
|
|
|
|
2001-05-07 21:46:15 +00:00
|
|
|
gtk_object_set (GTK_OBJECT(cache), "reset", TRUE, NULL);
|
|
|
|
|
2001-05-06 17:33:57 +00:00
|
|
|
gst_element_connect(cache,"src",decoder,"sink");
|
|
|
|
}
|
2001-05-06 22:12:00 +00:00
|
|
|
else if (strstr(gst_caps_get_mime(caps),"x-ogg")) {
|
|
|
|
decoder = gst_elementfactory_make ("vorbisdec","decoder");
|
|
|
|
sink = gst_elementfactory_make ("osssink","sink");
|
|
|
|
gst_bin_add(GST_BIN(autobin),decoder);
|
|
|
|
gst_bin_add(GST_BIN(autobin),sink);
|
|
|
|
gst_element_connect(decoder,"src",sink,"sink");
|
|
|
|
|
2001-05-07 21:46:15 +00:00
|
|
|
gtk_object_set (GTK_OBJECT(cache), "reset", TRUE, NULL);
|
|
|
|
|
2001-05-06 22:12:00 +00:00
|
|
|
gst_element_connect(cache,"src",decoder,"sink");
|
|
|
|
}
|
2001-05-06 17:33:57 +00:00
|
|
|
|
2001-05-06 22:12:00 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2001-05-06 17:33:57 +00:00
|
|
|
fprintf(stderr,"done with have_type signal\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc,char *argv[]) {
|
|
|
|
GstCaps *caps;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gst_init(&argc,&argv);
|
|
|
|
|
|
|
|
pipeline = gst_pipeline_new("pipeline");
|
|
|
|
src = gst_elementfactory_make ("disksrc","src");
|
|
|
|
gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
|
|
|
|
gst_bin_add (GST_BIN(pipeline),src);
|
|
|
|
|
|
|
|
autobin = gst_bin_new("autobin");
|
|
|
|
cache = gst_elementfactory_make ("autoplugcache","cache");
|
2001-05-07 21:46:15 +00:00
|
|
|
gtk_signal_connect (GTK_OBJECT(cache),"cache_empty",GTK_SIGNAL_FUNC(cache_empty),NULL);
|
2001-05-06 17:33:57 +00:00
|
|
|
typefind = gst_elementfactory_make ("typefind", "typefind");
|
|
|
|
gtk_signal_connect (GTK_OBJECT(typefind),"have_type",GTK_SIGNAL_FUNC(have_type),&caps);
|
|
|
|
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 (src,"src",autobin,"sink");
|
|
|
|
|
|
|
|
gst_element_set_state(pipeline,GST_STATE_PLAYING);
|
|
|
|
|
2001-05-06 22:12:00 +00:00
|
|
|
while (1)
|
|
|
|
gst_bin_iterate(GST_BIN(pipeline));
|
2001-05-06 17:33:57 +00:00
|
|
|
}
|