2000-02-18 23:07:33 +00:00
|
|
|
|
2000-06-11 12:11:41 +00:00
|
|
|
#define BUFFER 1
|
|
|
|
#define VIDEO_DECODER "mpeg_play"
|
|
|
|
|
2000-02-18 23:07:33 +00:00
|
|
|
#include <gnome.h>
|
2000-02-06 00:56:12 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
extern gboolean _gst_plugin_spew;
|
2000-02-18 23:07:33 +00:00
|
|
|
gboolean idle_func(gpointer data);
|
2000-02-06 00:56:12 +00:00
|
|
|
|
|
|
|
void eof(GstSrc *src) {
|
2000-02-12 23:09:57 +00:00
|
|
|
g_print("have eos, quitting\n");
|
|
|
|
exit(0);
|
2000-02-06 00:56:12 +00:00
|
|
|
}
|
|
|
|
|
2000-02-12 23:09:57 +00:00
|
|
|
void new_pad_created(GstElement *parse,GstPad *pad,GstElement *pipeline) {
|
2000-06-12 21:27:19 +00:00
|
|
|
GstElement *parse_audio, *parse_video, *decode, *decode_video, *play, *videoscale, *show;
|
2000-02-12 23:09:57 +00:00
|
|
|
GstElement *audio_queue, *video_queue;
|
|
|
|
GstElement *audio_thread, *video_thread;
|
2000-02-06 18:50:38 +00:00
|
|
|
|
2000-04-09 21:36:56 +00:00
|
|
|
GtkWidget *appwindow;
|
2000-02-18 23:07:33 +00:00
|
|
|
|
2000-02-12 23:09:57 +00:00
|
|
|
g_print("***** a new pad %s was created\n", gst_pad_get_name(pad));
|
2000-02-06 01:52:15 +00:00
|
|
|
|
|
|
|
// connect to audio pad
|
2000-02-16 16:44:54 +00:00
|
|
|
//if (0) {
|
2000-02-06 01:52:15 +00:00
|
|
|
if (strncmp(gst_pad_get_name(pad), "audio_", 6) == 0) {
|
2000-03-20 20:25:03 +00:00
|
|
|
gst_plugin_load("mp3parse");
|
|
|
|
gst_plugin_load("mpg123");
|
2000-02-12 23:09:57 +00:00
|
|
|
// construct internal pipeline elements
|
|
|
|
parse_audio = gst_elementfactory_make("mp3parse","parse_audio");
|
|
|
|
g_return_if_fail(parse_audio != NULL);
|
|
|
|
decode = gst_elementfactory_make("mpg123","decode_audio");
|
|
|
|
g_return_if_fail(decode != NULL);
|
|
|
|
play = gst_elementfactory_make("audiosink","play_audio");
|
|
|
|
g_return_if_fail(play != NULL);
|
|
|
|
|
|
|
|
// create the thread and pack stuff into it
|
|
|
|
audio_thread = gst_thread_new("audio_thread");
|
|
|
|
g_return_if_fail(audio_thread != NULL);
|
|
|
|
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(parse_audio));
|
|
|
|
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(decode));
|
|
|
|
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(play));
|
|
|
|
|
|
|
|
// set up pad connections
|
|
|
|
gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
|
|
|
|
gst_element_get_pad(parse_audio,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(parse_audio,"src"),
|
|
|
|
gst_element_get_pad(decode,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(decode,"src"),
|
|
|
|
gst_element_get_pad(play,"sink"));
|
|
|
|
|
|
|
|
// construct queue and connect everything in the main pipelie
|
|
|
|
audio_queue = gst_elementfactory_make("queue","audio_queue");
|
2000-06-11 12:11:41 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(audio_queue),"max_level",BUFFER,NULL);
|
2000-02-12 23:09:57 +00:00
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(audio_queue));
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(audio_thread));
|
|
|
|
gst_pad_connect(pad,
|
|
|
|
gst_element_get_pad(audio_queue,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(audio_queue,"src"),
|
|
|
|
gst_element_get_pad(audio_thread,"sink"));
|
|
|
|
|
|
|
|
// set up thread state and kick things off
|
|
|
|
gtk_object_set(GTK_OBJECT(audio_thread),"create_thread",TRUE,NULL);
|
|
|
|
g_print("setting to RUNNING state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(audio_thread),GST_STATE_RUNNING);
|
|
|
|
g_print("setting to PLAYING state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(audio_thread),GST_STATE_PLAYING);
|
|
|
|
} else if (strncmp(gst_pad_get_name(pad), "video_", 6) == 0) {
|
2000-04-09 21:36:56 +00:00
|
|
|
//} else if (0) {
|
2000-02-12 23:09:57 +00:00
|
|
|
|
2000-03-20 20:25:03 +00:00
|
|
|
gst_plugin_load("mp1videoparse");
|
2000-06-11 12:11:41 +00:00
|
|
|
gst_plugin_load(VIDEO_DECODER);
|
2000-06-12 21:27:19 +00:00
|
|
|
gst_plugin_load("videoscale");
|
2000-03-20 20:25:03 +00:00
|
|
|
gst_plugin_load("videosink");
|
2000-02-12 23:09:57 +00:00
|
|
|
// construct internal pipeline elements
|
|
|
|
parse_video = gst_elementfactory_make("mp1videoparse","parse_video");
|
|
|
|
g_return_if_fail(parse_video != NULL);
|
2000-06-11 12:11:41 +00:00
|
|
|
decode_video = gst_elementfactory_make(VIDEO_DECODER,"decode_video");
|
2000-02-12 23:09:57 +00:00
|
|
|
g_return_if_fail(decode_video != NULL);
|
2000-06-12 21:27:19 +00:00
|
|
|
videoscale = gst_elementfactory_make("videoscale","videoscale");
|
|
|
|
g_return_if_fail(videoscale != NULL);
|
|
|
|
gtk_object_set(GTK_OBJECT(videoscale),"width",704, "height", 576,NULL);
|
|
|
|
|
|
|
|
|
2000-02-18 23:07:33 +00:00
|
|
|
show = gst_elementfactory_make("videosink","show");
|
|
|
|
g_return_if_fail(show != NULL);
|
2000-02-26 18:55:14 +00:00
|
|
|
//gtk_object_set(GTK_OBJECT(show),"width",640, "height", 480,NULL);
|
2000-02-18 23:07:33 +00:00
|
|
|
|
2000-04-09 21:36:56 +00:00
|
|
|
appwindow = gnome_app_new("MPEG1 player","MPEG1 player");
|
|
|
|
gnome_app_set_contents(GNOME_APP(appwindow),
|
|
|
|
gst_util_get_widget_arg(GTK_OBJECT(show),"widget"));
|
2000-02-18 23:07:33 +00:00
|
|
|
gtk_widget_show_all(appwindow);
|
2000-02-12 23:09:57 +00:00
|
|
|
|
|
|
|
// create the thread and pack stuff into it
|
|
|
|
video_thread = gst_thread_new("video_thread");
|
|
|
|
g_return_if_fail(video_thread != NULL);
|
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(parse_video));
|
2000-04-09 21:36:56 +00:00
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(decode_video));
|
2000-06-12 21:27:19 +00:00
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(videoscale));
|
2000-02-18 23:07:33 +00:00
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(show));
|
2000-02-12 23:09:57 +00:00
|
|
|
|
|
|
|
// set up pad connections
|
|
|
|
gst_element_add_ghost_pad(GST_ELEMENT(video_thread),
|
|
|
|
gst_element_get_pad(parse_video,"sink"));
|
2000-02-10 17:02:34 +00:00
|
|
|
gst_pad_connect(gst_element_get_pad(parse_video,"src"),
|
2000-04-09 21:36:56 +00:00
|
|
|
gst_element_get_pad(decode_video,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(decode_video,"src"),
|
2000-06-12 21:27:19 +00:00
|
|
|
// gst_element_get_pad(videoscale,"sink"));
|
|
|
|
//gst_pad_connect(gst_element_get_pad(videoscale,"src"),
|
2000-02-18 23:07:33 +00:00
|
|
|
gst_element_get_pad(show,"sink"));
|
2000-02-12 23:09:57 +00:00
|
|
|
|
|
|
|
// construct queue and connect everything in the main pipeline
|
|
|
|
video_queue = gst_elementfactory_make("queue","video_queue");
|
2000-06-11 12:11:41 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(video_queue),"max_level",BUFFER,NULL);
|
2000-02-12 23:09:57 +00:00
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(video_queue));
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(video_thread));
|
|
|
|
gst_pad_connect(pad,
|
|
|
|
gst_element_get_pad(video_queue,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(video_queue,"src"),
|
|
|
|
gst_element_get_pad(video_thread,"sink"));
|
|
|
|
|
|
|
|
// set up thread state and kick things off
|
|
|
|
gtk_object_set(GTK_OBJECT(video_thread),"create_thread",TRUE,NULL);
|
|
|
|
g_print("setting to RUNNING state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(video_thread),GST_STATE_RUNNING);
|
|
|
|
g_print("setting to PLAYING state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(video_thread),GST_STATE_PLAYING);
|
2000-02-08 22:36:20 +00:00
|
|
|
}
|
2000-02-12 23:09:57 +00:00
|
|
|
g_print("\n");
|
2000-02-06 01:52:15 +00:00
|
|
|
}
|
|
|
|
|
2000-02-06 00:56:12 +00:00
|
|
|
int main(int argc,char *argv[]) {
|
2000-02-12 23:09:57 +00:00
|
|
|
GstPipeline *pipeline;
|
2000-02-06 00:56:12 +00:00
|
|
|
GstElement *src, *parse;
|
|
|
|
|
|
|
|
g_print("have %d args\n",argc);
|
|
|
|
|
2000-03-20 20:25:03 +00:00
|
|
|
//_gst_plugin_spew = TRUE;
|
2000-02-06 00:56:12 +00:00
|
|
|
gst_init(&argc,&argv);
|
2000-02-18 23:07:33 +00:00
|
|
|
gnome_init("MPEG1 Video player","0.0.1",argc,argv);
|
2000-03-20 20:25:03 +00:00
|
|
|
gst_plugin_load("mpeg1parse");
|
2000-02-06 00:56:12 +00:00
|
|
|
|
|
|
|
pipeline = gst_pipeline_new("pipeline");
|
|
|
|
g_return_if_fail(pipeline != NULL);
|
|
|
|
|
2000-04-09 21:36:56 +00:00
|
|
|
//src = gst_elementfactory_make("asyncdisksrc","src");
|
2000-02-12 23:09:57 +00:00
|
|
|
src = gst_elementfactory_make("disksrc","src");
|
2000-02-06 00:56:12 +00:00
|
|
|
g_return_if_fail(src != NULL);
|
|
|
|
gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
|
|
|
|
g_print("should be using file '%s'\n",argv[1]);
|
2000-02-12 23:09:57 +00:00
|
|
|
|
|
|
|
parse = gst_elementfactory_make("mpeg1parse","parse");
|
2000-02-06 00:56:12 +00:00
|
|
|
g_return_if_fail(parse != NULL);
|
|
|
|
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(src));
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(parse));
|
|
|
|
|
2000-02-06 01:52:15 +00:00
|
|
|
gtk_signal_connect(GTK_OBJECT(parse),"new_pad",
|
2000-02-12 23:09:57 +00:00
|
|
|
GTK_SIGNAL_FUNC(new_pad_created),pipeline);
|
2000-02-06 01:52:15 +00:00
|
|
|
|
2000-02-06 00:56:12 +00:00
|
|
|
gtk_signal_connect(GTK_OBJECT(src),"eos",
|
|
|
|
GTK_SIGNAL_FUNC(eof),NULL);
|
|
|
|
|
|
|
|
gst_pad_connect(gst_element_get_pad(src,"src"),
|
|
|
|
gst_element_get_pad(parse,"sink"));
|
|
|
|
|
|
|
|
g_print("setting to RUNNING state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_RUNNING);
|
|
|
|
|
2000-02-12 23:09:57 +00:00
|
|
|
xmlSaveFile("mp1parse.xml",gst_xml_write(GST_ELEMENT(pipeline)));
|
|
|
|
|
2000-02-06 00:56:12 +00:00
|
|
|
g_print("about to enter loop\n");
|
2000-02-16 23:27:45 +00:00
|
|
|
|
2000-04-09 21:36:56 +00:00
|
|
|
while (1) {
|
|
|
|
gst_src_push(GST_SRC(src));
|
|
|
|
}
|
|
|
|
// this does not work due to multithreading
|
|
|
|
/*
|
|
|
|
g_idle_add(idle_func,src);
|
2000-02-18 23:07:33 +00:00
|
|
|
|
2000-04-09 21:36:56 +00:00
|
|
|
gtk_main();
|
|
|
|
*/
|
2000-02-18 23:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean idle_func(gpointer data) {
|
2000-04-09 21:36:56 +00:00
|
|
|
gst_src_push(GST_SRC(data));
|
|
|
|
return TRUE;
|
2000-02-06 00:56:12 +00:00
|
|
|
}
|