2000-01-30 10:44:33 +00:00
|
|
|
|
2000-04-13 21:59:38 +00:00
|
|
|
#include <gnome.h>
|
2000-01-30 10:44:33 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2000-12-30 01:53:05 +00:00
|
|
|
void eof(GstElement *src) {
|
2000-04-13 21:59:38 +00:00
|
|
|
g_print("have eos, quitting\n");
|
|
|
|
exit(0);
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
gboolean idle_func(gpointer data) {
|
2000-12-27 22:39:45 +00:00
|
|
|
gst_bin_iterate(GST_BIN(data));
|
2000-07-05 10:21:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-08-14 15:17:24 +00:00
|
|
|
GstElement *merge_subtitles;
|
|
|
|
|
2000-04-13 21:59:38 +00:00
|
|
|
void mpeg2parse_newpad(GstElement *parser,GstPad *pad, GstElement *pipeline) {
|
|
|
|
GstElement *parse_audio, *parse_video, *decode, *decode_video, *play, *show;
|
|
|
|
GstElement *audio_queue, *video_queue;
|
|
|
|
GstElement *audio_thread, *video_thread;
|
|
|
|
|
|
|
|
GtkWidget *appwindow;
|
|
|
|
|
|
|
|
g_print("***** a new pad %s was created\n", gst_pad_get_name(pad));
|
2000-08-14 15:17:24 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PAUSED);
|
2000-04-13 21:59:38 +00:00
|
|
|
|
|
|
|
// connect to audio pad
|
2000-05-01 23:09:46 +00:00
|
|
|
//if (0) {
|
|
|
|
if (strncmp(gst_pad_get_name(pad), "private_stream_1.0", 18) == 0) {
|
2000-04-13 21:59:38 +00:00
|
|
|
gst_plugin_load("ac3parse");
|
|
|
|
gst_plugin_load("ac3dec");
|
|
|
|
// construct internal pipeline elements
|
|
|
|
parse_audio = gst_elementfactory_make("ac3parse","parse_audio");
|
|
|
|
g_return_if_fail(parse_audio != NULL);
|
|
|
|
decode = gst_elementfactory_make("ac3dec","decode_audio");
|
|
|
|
g_return_if_fail(decode != NULL);
|
2001-03-24 17:22:03 +00:00
|
|
|
play = gst_elementfactory_make("osssink","play_audio");
|
2000-04-13 21:59:38 +00:00
|
|
|
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));
|
|
|
|
|
2000-05-01 23:09:46 +00:00
|
|
|
// set up pad connections
|
|
|
|
gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
|
2001-01-20 03:33:55 +00:00
|
|
|
gst_element_get_pad(parse_audio,"sink"),"sink");
|
2000-05-01 23:09:46 +00:00
|
|
|
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");
|
|
|
|
gtk_object_set(GTK_OBJECT(audio_queue),"max_level",30,NULL);
|
|
|
|
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);
|
2000-08-14 15:17:24 +00:00
|
|
|
g_print("setting to READY state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(audio_thread),GST_STATE_READY);
|
|
|
|
} else if (strncmp(gst_pad_get_name(pad), "subtitle_stream_4", 17) == 0) {
|
|
|
|
gst_pad_connect(pad,
|
|
|
|
gst_element_get_pad(merge_subtitles,"subtitle"));
|
|
|
|
|
2000-05-01 23:09:46 +00:00
|
|
|
} else if (strncmp(gst_pad_get_name(pad), "audio_", 6) == 0) {
|
|
|
|
gst_plugin_load("mp3parse");
|
|
|
|
gst_plugin_load("mpg123");
|
|
|
|
// 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);
|
2001-03-24 17:22:03 +00:00
|
|
|
play = gst_elementfactory_make("osssink","play_audio");
|
2000-05-01 23:09:46 +00:00
|
|
|
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));
|
|
|
|
|
2000-04-13 21:59:38 +00:00
|
|
|
// set up pad connections
|
|
|
|
gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
|
2001-01-20 03:33:55 +00:00
|
|
|
gst_element_get_pad(parse_audio,"sink"),"sink");
|
2000-04-13 21:59:38 +00:00
|
|
|
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");
|
|
|
|
gtk_object_set(GTK_OBJECT(audio_queue),"max_level",30,NULL);
|
|
|
|
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);
|
2000-08-14 15:17:24 +00:00
|
|
|
g_print("setting to READY state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(audio_thread),GST_STATE_READY);
|
2000-04-24 20:51:30 +00:00
|
|
|
} else if (strncmp(gst_pad_get_name(pad), "video_", 6) == 0) {
|
|
|
|
//} else if (0) {
|
2000-04-13 21:59:38 +00:00
|
|
|
|
|
|
|
gst_plugin_load("mp1videoparse");
|
2000-04-24 20:51:30 +00:00
|
|
|
gst_plugin_load("mpeg2play");
|
2000-08-14 15:17:24 +00:00
|
|
|
gst_plugin_load("mpeg2subt");
|
2000-04-13 21:59:38 +00:00
|
|
|
gst_plugin_load("videosink");
|
|
|
|
// construct internal pipeline elements
|
|
|
|
parse_video = gst_elementfactory_make("mp1videoparse","parse_video");
|
|
|
|
g_return_if_fail(parse_video != NULL);
|
2000-04-24 20:51:30 +00:00
|
|
|
decode_video = gst_elementfactory_make("mpeg2play","decode_video");
|
2000-04-13 21:59:38 +00:00
|
|
|
g_return_if_fail(decode_video != NULL);
|
2000-08-14 15:17:24 +00:00
|
|
|
merge_subtitles = gst_elementfactory_make("mpeg2subt","merge_subtitles");
|
|
|
|
g_return_if_fail(merge_subtitles != NULL);
|
2000-04-13 21:59:38 +00:00
|
|
|
show = gst_elementfactory_make("videosink","show");
|
2000-08-14 15:17:24 +00:00
|
|
|
//gtk_object_set(GTK_OBJECT(show),"xv_enabled",FALSE,NULL);
|
2000-04-13 21:59:38 +00:00
|
|
|
g_return_if_fail(show != NULL);
|
|
|
|
//gtk_object_set(GTK_OBJECT(show),"width",640, "height", 480,NULL);
|
|
|
|
|
2000-04-24 20:51:30 +00:00
|
|
|
appwindow = gnome_app_new("MPEG player","MPEG player");
|
2000-04-13 21:59:38 +00:00
|
|
|
gnome_app_set_contents(GNOME_APP(appwindow),
|
|
|
|
gst_util_get_widget_arg(GTK_OBJECT(show),"widget"));
|
|
|
|
gtk_widget_show_all(appwindow);
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(decode_video));
|
2000-08-14 15:17:24 +00:00
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(merge_subtitles));
|
2000-04-13 21:59:38 +00:00
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(show));
|
2000-08-14 15:17:24 +00:00
|
|
|
gst_bin_use_cothreads(GST_BIN(video_thread), FALSE);
|
2000-04-13 21:59:38 +00:00
|
|
|
|
|
|
|
// set up pad connections
|
|
|
|
gst_element_add_ghost_pad(GST_ELEMENT(video_thread),
|
2001-01-20 03:33:55 +00:00
|
|
|
gst_element_get_pad(parse_video,"sink"),"sink");
|
2000-04-13 21:59:38 +00:00
|
|
|
gst_pad_connect(gst_element_get_pad(parse_video,"src"),
|
|
|
|
gst_element_get_pad(decode_video,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(decode_video,"src"),
|
2000-08-14 15:17:24 +00:00
|
|
|
gst_element_get_pad(merge_subtitles,"video"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(merge_subtitles,"src"),
|
2000-04-13 21:59:38 +00:00
|
|
|
gst_element_get_pad(show,"sink"));
|
|
|
|
|
|
|
|
// construct queue and connect everything in the main pipeline
|
|
|
|
video_queue = gst_elementfactory_make("queue","video_queue");
|
|
|
|
gtk_object_set(GTK_OBJECT(video_queue),"max_level",30,NULL);
|
|
|
|
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);
|
2000-08-14 15:17:24 +00:00
|
|
|
g_print("setting to READY state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(video_thread),GST_STATE_READY);
|
2000-04-13 21:59:38 +00:00
|
|
|
}
|
|
|
|
g_print("\n");
|
2000-08-14 15:17:24 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING);
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc,char *argv[]) {
|
|
|
|
GstPipeline *pipeline;
|
2000-08-14 15:17:24 +00:00
|
|
|
GstElement *src, *parse;
|
2000-01-30 10:44:33 +00:00
|
|
|
|
|
|
|
g_print("have %d args\n",argc);
|
|
|
|
|
2000-08-14 15:17:24 +00:00
|
|
|
g_thread_init(NULL);
|
2000-07-05 10:21:08 +00:00
|
|
|
gtk_init(&argc,&argv);
|
2000-01-30 10:44:33 +00:00
|
|
|
gst_init(&argc,&argv);
|
2000-04-13 21:59:38 +00:00
|
|
|
gnome_init("MPEG2 Video player","0.0.1",argc,argv);
|
|
|
|
gst_plugin_load("mpeg2parse");
|
2000-05-12 17:33:35 +00:00
|
|
|
//gst_plugin_load("mpeg1parse");
|
2000-01-30 10:44:33 +00:00
|
|
|
|
2000-12-30 01:53:05 +00:00
|
|
|
pipeline = GST_PIPELINE(gst_pipeline_new("pipeline"));
|
2000-08-14 15:17:24 +00:00
|
|
|
g_return_val_if_fail(pipeline != NULL, -1);
|
2000-01-30 10:44:33 +00:00
|
|
|
|
|
|
|
if (strstr(argv[1],"video_ts")) {
|
|
|
|
src = gst_elementfactory_make("dvdsrc","src");
|
|
|
|
g_print("using DVD source\n");
|
|
|
|
} else
|
|
|
|
src = gst_elementfactory_make("disksrc","src");
|
2000-04-13 21:59:38 +00:00
|
|
|
|
2000-08-14 15:17:24 +00:00
|
|
|
g_return_val_if_fail(src != NULL, -1);
|
2000-01-30 10:44:33 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
|
|
|
|
if (argc >= 3) {
|
|
|
|
gtk_object_set(GTK_OBJECT(src),"bytesperread",atoi(argv[2]),NULL);
|
|
|
|
g_print("block size is %d\n",atoi(argv[2]));
|
|
|
|
}
|
|
|
|
g_print("should be using file '%s'\n",argv[1]);
|
|
|
|
|
|
|
|
parse = gst_elementfactory_make("mpeg2parse","parse");
|
2000-05-12 17:33:35 +00:00
|
|
|
//parse = gst_elementfactory_make("mpeg1parse","parse");
|
2000-08-14 15:17:24 +00:00
|
|
|
g_return_val_if_fail(parse != NULL, -1);
|
2000-01-30 10:44:33 +00:00
|
|
|
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(src));
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(parse));
|
|
|
|
|
2000-04-13 21:59:38 +00:00
|
|
|
gtk_signal_connect(GTK_OBJECT(parse),"new_pad",mpeg2parse_newpad, pipeline);
|
|
|
|
|
|
|
|
gtk_signal_connect(GTK_OBJECT(src),"eos",GTK_SIGNAL_FUNC(eof),NULL);
|
|
|
|
|
2000-01-30 10:44:33 +00:00
|
|
|
gst_pad_connect(gst_element_get_pad(src,"src"),
|
|
|
|
gst_element_get_pad(parse,"sink"));
|
|
|
|
|
2000-08-14 15:17:24 +00:00
|
|
|
g_print("setting to READY state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_READY);
|
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING);
|
2000-01-30 10:44:33 +00:00
|
|
|
|
2000-12-27 22:39:45 +00:00
|
|
|
gtk_idle_add(idle_func,pipeline);
|
2000-07-05 10:21:08 +00:00
|
|
|
|
2000-08-14 15:17:24 +00:00
|
|
|
gdk_threads_enter();
|
2000-07-05 10:21:08 +00:00
|
|
|
gtk_main();
|
2000-08-14 15:17:24 +00:00
|
|
|
gdk_threads_leave();
|
|
|
|
|
|
|
|
return 0;
|
2000-01-30 10:44:33 +00:00
|
|
|
}
|