2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2000-08-14 15:17:24 +00:00
|
|
|
#include <string.h>
|
2000-05-12 17:39:40 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2001-01-06 16:52:44 +00:00
|
|
|
static GstElement *mux = NULL;
|
|
|
|
static GstElement *merge_subtitles;
|
|
|
|
static GstElement *fdsink;
|
2000-05-12 17:39:40 +00:00
|
|
|
|
2001-01-06 16:52:44 +00:00
|
|
|
static void
|
|
|
|
eof(GstElement *src)
|
|
|
|
{
|
2000-05-12 17:39:40 +00:00
|
|
|
g_print("have eos, quitting\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2001-01-06 16:52:44 +00:00
|
|
|
static GstPad*
|
|
|
|
create_muxer (GstElement *pipeline, gchar *type, gchar *number)
|
|
|
|
{
|
|
|
|
if (!mux) {
|
|
|
|
mux = gst_elementfactory_make("system_encode","mux");
|
|
|
|
g_return_val_if_fail(mux != NULL, NULL);
|
|
|
|
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(mux));
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(fdsink));
|
|
|
|
gst_pad_connect(gst_element_get_pad(mux,"src"),
|
|
|
|
gst_element_get_pad(fdsink,"sink"));
|
|
|
|
}
|
|
|
|
gtk_object_set(GTK_OBJECT(mux), type, number,NULL);
|
|
|
|
|
|
|
|
return gst_element_get_pad(mux,g_strconcat (type, "_", number, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mp2tomp1 (GstElement *parser, GstPad *pad, GstElement *pipeline)
|
|
|
|
{
|
2001-04-21 17:45:56 +00:00
|
|
|
GstElement *decode, *decode_video, *play, *encode, *audio_resample;
|
2000-06-11 12:11:41 +00:00
|
|
|
GstElement *smooth, *median;
|
2000-05-12 17:39:40 +00:00
|
|
|
GstElement *audio_queue, *video_queue;
|
|
|
|
GstElement *audio_thread, *video_thread;
|
2000-05-28 19:59:46 +00:00
|
|
|
GstElement *videoscale, *audio_encode;
|
2001-01-06 16:52:44 +00:00
|
|
|
GstPad *muxerpad;
|
2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
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-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
// connect to audio pad
|
2000-05-28 19:59:46 +00:00
|
|
|
//if (0) {
|
|
|
|
if (strncmp(gst_pad_get_name(pad), "private_stream_1.0", 18) == 0) {
|
2000-05-12 17:39:40 +00:00
|
|
|
// construct internal pipeline elements
|
|
|
|
decode = gst_elementfactory_make("ac3dec","decode_audio");
|
|
|
|
g_return_if_fail(decode != NULL);
|
2000-06-11 12:11:41 +00:00
|
|
|
audio_resample = gst_elementfactory_make("audioscale","audioscale");
|
|
|
|
g_return_if_fail(audio_resample != NULL);
|
|
|
|
gtk_object_set(GTK_OBJECT(audio_resample),"frequency", 44100, NULL);
|
2000-06-16 22:30:24 +00:00
|
|
|
|
|
|
|
audio_encode = gst_elementfactory_make("mpegaudio","audio_encode");
|
|
|
|
//audio_encode = gst_elementfactory_make("pipefilter","audio_encode");
|
2000-05-28 19:59:46 +00:00
|
|
|
g_return_if_fail(audio_encode != NULL);
|
2000-06-16 22:30:24 +00:00
|
|
|
//gtk_object_set(GTK_OBJECT(audio_encode),"command", "lame -x - -", NULL);
|
2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
// 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(decode));
|
2000-06-11 12:11:41 +00:00
|
|
|
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(audio_resample));
|
2000-05-28 19:59:46 +00:00
|
|
|
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(audio_encode));
|
|
|
|
|
2001-01-06 16:52:44 +00:00
|
|
|
muxerpad = create_muxer (pipeline, "audio", "00");
|
2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
// set up pad connections
|
|
|
|
gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
|
2001-04-21 17:45:56 +00:00
|
|
|
gst_element_get_pad(decode,"sink"),"sink");
|
2000-05-12 17:39:40 +00:00
|
|
|
gst_pad_connect(gst_element_get_pad(decode,"src"),
|
2000-06-11 12:11:41 +00:00
|
|
|
gst_element_get_pad(audio_resample,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(audio_resample,"src"),
|
2000-05-28 19:59:46 +00:00
|
|
|
gst_element_get_pad(audio_encode,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(audio_encode,"src"),
|
2001-01-06 16:52:44 +00:00
|
|
|
muxerpad);
|
2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
// 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",1,NULL);
|
2000-05-12 17:39:40 +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);
|
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) {
|
2001-01-06 16:52:44 +00:00
|
|
|
//gst_pad_connect(pad,
|
|
|
|
// gst_element_get_pad(merge_subtitles,"subtitle"));
|
2000-05-12 17:39:40 +00:00
|
|
|
} else if (strncmp(gst_pad_get_name(pad), "audio_", 6) == 0) {
|
|
|
|
// construct internal pipeline elements
|
2001-04-21 17:45:56 +00:00
|
|
|
decode = gst_elementfactory_make("mad","decode_audio");
|
2000-05-12 17:39:40 +00:00
|
|
|
g_return_if_fail(decode != NULL);
|
2001-03-24 17:22:03 +00:00
|
|
|
play = gst_elementfactory_make("osssink","play_audio");
|
2000-05-12 17:39:40 +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(decode));
|
|
|
|
gst_bin_add(GST_BIN(audio_thread),GST_ELEMENT(play));
|
|
|
|
|
2000-06-11 12:11:41 +00:00
|
|
|
|
2000-05-12 17:39:40 +00:00
|
|
|
// set up pad connections
|
|
|
|
gst_element_add_ghost_pad(GST_ELEMENT(audio_thread),
|
2001-04-21 17:45:56 +00:00
|
|
|
gst_element_get_pad(decode,"sink"),"sink");
|
2000-05-12 17:39:40 +00:00
|
|
|
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",1,NULL);
|
2000-05-12 17:39:40 +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);
|
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-05-12 17:39:40 +00:00
|
|
|
} else if (strncmp(gst_pad_get_name(pad), "video_", 6) == 0) {
|
|
|
|
//} else if (0) {
|
|
|
|
|
2000-05-21 21:58:20 +00:00
|
|
|
//gst_plugin_load("mpeg1encoder");
|
2000-05-12 17:39:40 +00:00
|
|
|
// construct internal pipeline elements
|
2001-04-21 17:45:56 +00:00
|
|
|
decode_video = gst_elementfactory_make("mpeg2dec","decode_video");
|
2000-05-12 17:39:40 +00:00
|
|
|
g_return_if_fail(decode_video != NULL);
|
2001-01-06 16:52:44 +00:00
|
|
|
//merge_subtitles = gst_elementfactory_make("mpeg2subt","merge_subtitles");
|
|
|
|
//g_return_if_fail(merge_subtitles != NULL);
|
2000-05-12 17:39:40 +00:00
|
|
|
videoscale = gst_elementfactory_make("videoscale","videoscale");
|
|
|
|
g_return_if_fail(videoscale != NULL);
|
2000-08-14 15:17:24 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(videoscale),"width",352, "height", 288,NULL);
|
2000-06-11 12:11:41 +00:00
|
|
|
median = gst_elementfactory_make("median","median");
|
2000-06-12 21:27:19 +00:00
|
|
|
g_return_if_fail(median != NULL);
|
2000-08-14 15:17:24 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(median),"filtersize",5,NULL);
|
|
|
|
gtk_object_set(GTK_OBJECT(median),"active",TRUE,NULL);
|
2000-06-11 12:11:41 +00:00
|
|
|
smooth = gst_elementfactory_make("smooth","smooth");
|
|
|
|
g_return_if_fail(smooth != NULL);
|
|
|
|
gtk_object_set(GTK_OBJECT(smooth),"filtersize",5,NULL);
|
|
|
|
gtk_object_set(GTK_OBJECT(smooth),"tolerance",9,NULL);
|
2000-08-14 15:17:24 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(smooth),"active",FALSE,NULL);
|
2000-05-12 17:39:40 +00:00
|
|
|
encode = gst_elementfactory_make("mpeg2enc","encode");
|
|
|
|
g_return_if_fail(encode != NULL);
|
2001-01-06 16:52:44 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(encode),"frames_per_second",25.0,NULL);
|
|
|
|
//gtk_object_set(GTK_OBJECT(encode),"frames_per_second",29.97,NULL);
|
2000-06-11 12:11:41 +00:00
|
|
|
//encode = gst_elementfactory_make("mpeg1encoder","encode");
|
2000-05-12 17:39:40 +00:00
|
|
|
//gtk_object_set(GTK_OBJECT(show),"width",640, "height", 480,NULL);
|
|
|
|
|
2001-01-06 16:52:44 +00:00
|
|
|
muxerpad = create_muxer (pipeline, "video", "00");
|
2001-04-21 17:45:56 +00:00
|
|
|
g_return_if_fail(muxerpad != NULL);
|
|
|
|
|
2000-05-12 17:39:40 +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(decode_video));
|
2001-04-21 17:45:56 +00:00
|
|
|
//gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(merge_subtitles));
|
2000-06-11 12:11:41 +00:00
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(median));
|
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(smooth));
|
2000-05-12 17:39:40 +00:00
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(videoscale));
|
|
|
|
gst_bin_add(GST_BIN(video_thread),GST_ELEMENT(encode));
|
2000-08-14 15:17:24 +00:00
|
|
|
gst_bin_use_cothreads(GST_BIN(video_thread), FALSE);
|
2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
// set up pad connections
|
|
|
|
gst_element_add_ghost_pad(GST_ELEMENT(video_thread),
|
2001-04-21 17:45:56 +00:00
|
|
|
gst_element_get_pad(decode_video,"sink"),"sink");
|
2000-05-12 17:39:40 +00:00
|
|
|
gst_pad_connect(gst_element_get_pad(decode_video,"src"),
|
2000-06-11 12:11:41 +00:00
|
|
|
gst_element_get_pad(median,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(median,"src"),
|
2001-01-06 16:52:44 +00:00
|
|
|
// gst_element_get_pad(merge_subtitles,"video"));
|
|
|
|
//gst_pad_connect(gst_element_get_pad(merge_subtitles,"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-08-14 15:17:24 +00:00
|
|
|
gst_element_get_pad(smooth,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(smooth,"src"),
|
2000-05-12 17:39:40 +00:00
|
|
|
gst_element_get_pad(encode,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(encode,"src"),
|
2001-01-06 16:52:44 +00:00
|
|
|
muxerpad);
|
2000-05-12 17:39:40 +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",1,NULL);
|
2000-05-12 17:39:40 +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);
|
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-05-12 17:39:40 +00:00
|
|
|
}
|
|
|
|
g_print("\n");
|
2000-08-14 15:17:24 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING);
|
2000-05-12 17:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc,char *argv[]) {
|
2000-12-30 01:53:05 +00:00
|
|
|
GstElement *pipeline, *src, *parse;
|
2000-06-11 12:11:41 +00:00
|
|
|
GstElementFactory *fdsinkfactory;
|
|
|
|
int fd;
|
2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
g_print("have %d args\n",argc);
|
|
|
|
|
|
|
|
gst_init(&argc,&argv);
|
|
|
|
|
|
|
|
pipeline = gst_pipeline_new("pipeline");
|
2000-08-14 15:17:24 +00:00
|
|
|
g_return_val_if_fail(pipeline != NULL, -1);
|
2000-05-12 17:39:40 +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-08-14 15:17:24 +00:00
|
|
|
g_return_val_if_fail(src != NULL, -1);
|
2000-05-12 17:39:40 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(src),"location",argv[1],NULL);
|
|
|
|
g_print("should be using file '%s'\n",argv[1]);
|
|
|
|
|
|
|
|
g_print("should be using output file '%s'\n",argv[2]);
|
|
|
|
|
|
|
|
parse = gst_elementfactory_make("mpeg2parse","parse");
|
2000-08-14 15:17:24 +00:00
|
|
|
g_return_val_if_fail(parse != NULL, -1);
|
2000-05-12 17:39:40 +00:00
|
|
|
|
2000-08-14 15:17:24 +00:00
|
|
|
fd = open(argv[2],O_CREAT|O_RDWR|O_TRUNC, S_IREAD|S_IWRITE);
|
|
|
|
g_return_val_if_fail(fd >= 0, -1);
|
2000-06-11 12:11:41 +00:00
|
|
|
fdsinkfactory = gst_elementfactory_find("fdsink");
|
2000-08-14 15:17:24 +00:00
|
|
|
g_return_val_if_fail(fdsinkfactory != NULL, -1);
|
2000-06-11 12:11:41 +00:00
|
|
|
fdsink = gst_elementfactory_create(fdsinkfactory,"fdsink");
|
2000-08-14 15:17:24 +00:00
|
|
|
g_return_val_if_fail(fdsink != NULL, -1);
|
2000-06-11 12:11:41 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(fdsink),"fd",fd,NULL);
|
|
|
|
|
2000-05-12 17:39:40 +00:00
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(src));
|
|
|
|
gst_bin_add(GST_BIN(pipeline),GST_ELEMENT(parse));
|
2001-01-06 16:52:44 +00:00
|
|
|
|
2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
gtk_signal_connect(GTK_OBJECT(parse),"new_pad",mp2tomp1, pipeline);
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
2000-08-14 15:17:24 +00:00
|
|
|
g_print("setting to READY state\n");
|
2000-12-27 22:39:45 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING);
|
2000-05-12 17:39:40 +00:00
|
|
|
|
|
|
|
while (1) {
|
2000-12-27 22:39:45 +00:00
|
|
|
gst_bin_iterate(GST_BIN(pipeline));
|
2000-05-12 17:39:40 +00:00
|
|
|
}
|
2000-08-14 15:17:24 +00:00
|
|
|
|
|
|
|
return 0;
|
2000-05-12 17:39:40 +00:00
|
|
|
}
|