From 987d66af1a3e807537bbdcc3db16f1b0b0c17564 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 28 May 2000 22:46:46 +0000 Subject: [PATCH] Rewrote the mpeg2 system parser like the mpeg1 parser. Original commit message from CVS: Rewrote the mpeg2 system parser like the mpeg1 parser. Added a command property to the pipefilter. --- gst/elements/gstpipefilter.c | 36 +++++++++++++++++++------------- gst/elements/gstpipefilter.h | 7 +++---- plugins/elements/gstpipefilter.c | 36 +++++++++++++++++++------------- plugins/elements/gstpipefilter.h | 7 +++---- test/.gitignore | 2 ++ test/mp2tomp1.c | 2 ++ 6 files changed, 52 insertions(+), 38 deletions(-) diff --git a/gst/elements/gstpipefilter.c b/gst/elements/gstpipefilter.c index b054c93e11..a660592cac 100644 --- a/gst/elements/gstpipefilter.c +++ b/gst/elements/gstpipefilter.c @@ -48,7 +48,7 @@ enum { enum { ARG_0, - ARG_CONTROL + ARG_COMMAND }; @@ -98,11 +98,11 @@ static void gst_pipefilter_class_init(GstPipefilterClass *klass) { gstelement_class->change_state = gst_pipefilter_change_state; - //gtk_object_add_arg_type("GstPipefilter::control", GTK_TYPE_INT, - // GTK_ARG_READWRITE, ARG_CONTROL); + gtk_object_add_arg_type("GstPipefilter::command", GTK_TYPE_STRING, + GTK_ARG_READWRITE, ARG_COMMAND); - //gtkobject_class->set_arg = gst_pipefilter_set_arg; - //gtkobject_class->get_arg = gst_pipefilter_get_arg; + gtkobject_class->set_arg = gst_pipefilter_set_arg; + gtkobject_class->get_arg = gst_pipefilter_get_arg; } static void gst_pipefilter_init(GstPipefilter *pipefilter) { @@ -112,7 +112,7 @@ static void gst_pipefilter_init(GstPipefilter *pipefilter) { pipefilter->srcpad = gst_pad_new("src",GST_PAD_SRC); gst_element_add_pad(GST_ELEMENT(pipefilter),pipefilter->srcpad); - pipefilter->control = 0; + pipefilter->command = NULL; pipefilter->curoffset = 0; pipefilter->bytes_per_read = 4096; pipefilter->seq = 0; @@ -199,8 +199,9 @@ static void gst_pipefilter_set_arg(GtkObject *object,GtkArg *arg,guint id) { pipefilter = GST_PIPEFILTER(object); switch(id) { - case ARG_CONTROL: - pipefilter->control = GTK_VALUE_INT(*arg); + case ARG_COMMAND: + pipefilter->orig_command = g_strdup(GTK_VALUE_STRING(*arg)); + pipefilter->command = g_strsplit(GTK_VALUE_STRING(*arg), " ", 0); break; default: break; @@ -215,8 +216,8 @@ static void gst_pipefilter_get_arg(GtkObject *object,GtkArg *arg,guint id) { pipefilter = GST_PIPEFILTER(object); switch (id) { - case ARG_CONTROL: - GTK_VALUE_INT(*arg) = pipefilter->control; + case ARG_COMMAND: + GTK_VALUE_STRING(*arg) = pipefilter->orig_command; break; default: arg->type = GTK_TYPE_INVALID; @@ -246,11 +247,16 @@ static gboolean gst_pipefilter_open_file(GstPipefilter *src) { if(src->childpid == 0) { - close(1); - dup(src->fdout[1]); /* set the childs output stream */ - close(0); - dup(src->fdin[0]); /* set the childs output stream */ - execlp("lame", "lame", "-x", "-", "-", NULL); + // child + dup2(src->fdin[0], STDIN_FILENO); /* set the childs input stream */ + dup2(src->fdout[1], STDOUT_FILENO); /* set the childs output stream */ + //execlp("lame", "lame", "-x", "-s", "48", "--resample", "44.1", "-", "-", NULL); + execvp(src->command[0], &src->command[0]); + // will only reach if error + perror("exec"); + gst_element_error(GST_ELEMENT(src),"starting child process"); + return FALSE; + } GST_FLAG_SET(src,GST_PIPEFILTER_OPEN); diff --git a/gst/elements/gstpipefilter.h b/gst/elements/gstpipefilter.h index 4e20e2bb48..5243643e80 100644 --- a/gst/elements/gstpipefilter.h +++ b/gst/elements/gstpipefilter.h @@ -58,8 +58,9 @@ struct _GstPipefilter { GstPad *sinkpad; GstPad *srcpad; - /* filename */ - gchar *filename; + /* command */ + gchar **command; + gchar *orig_command; /* fd */ gint fdout[2]; gint fdin[2]; @@ -69,8 +70,6 @@ struct _GstPipefilter { gulong bytes_per_read; /* bytes per read */ gulong seq; /* buffer sequence number */ - - gint control; }; struct _GstPipefilterClass { diff --git a/plugins/elements/gstpipefilter.c b/plugins/elements/gstpipefilter.c index b054c93e11..a660592cac 100644 --- a/plugins/elements/gstpipefilter.c +++ b/plugins/elements/gstpipefilter.c @@ -48,7 +48,7 @@ enum { enum { ARG_0, - ARG_CONTROL + ARG_COMMAND }; @@ -98,11 +98,11 @@ static void gst_pipefilter_class_init(GstPipefilterClass *klass) { gstelement_class->change_state = gst_pipefilter_change_state; - //gtk_object_add_arg_type("GstPipefilter::control", GTK_TYPE_INT, - // GTK_ARG_READWRITE, ARG_CONTROL); + gtk_object_add_arg_type("GstPipefilter::command", GTK_TYPE_STRING, + GTK_ARG_READWRITE, ARG_COMMAND); - //gtkobject_class->set_arg = gst_pipefilter_set_arg; - //gtkobject_class->get_arg = gst_pipefilter_get_arg; + gtkobject_class->set_arg = gst_pipefilter_set_arg; + gtkobject_class->get_arg = gst_pipefilter_get_arg; } static void gst_pipefilter_init(GstPipefilter *pipefilter) { @@ -112,7 +112,7 @@ static void gst_pipefilter_init(GstPipefilter *pipefilter) { pipefilter->srcpad = gst_pad_new("src",GST_PAD_SRC); gst_element_add_pad(GST_ELEMENT(pipefilter),pipefilter->srcpad); - pipefilter->control = 0; + pipefilter->command = NULL; pipefilter->curoffset = 0; pipefilter->bytes_per_read = 4096; pipefilter->seq = 0; @@ -199,8 +199,9 @@ static void gst_pipefilter_set_arg(GtkObject *object,GtkArg *arg,guint id) { pipefilter = GST_PIPEFILTER(object); switch(id) { - case ARG_CONTROL: - pipefilter->control = GTK_VALUE_INT(*arg); + case ARG_COMMAND: + pipefilter->orig_command = g_strdup(GTK_VALUE_STRING(*arg)); + pipefilter->command = g_strsplit(GTK_VALUE_STRING(*arg), " ", 0); break; default: break; @@ -215,8 +216,8 @@ static void gst_pipefilter_get_arg(GtkObject *object,GtkArg *arg,guint id) { pipefilter = GST_PIPEFILTER(object); switch (id) { - case ARG_CONTROL: - GTK_VALUE_INT(*arg) = pipefilter->control; + case ARG_COMMAND: + GTK_VALUE_STRING(*arg) = pipefilter->orig_command; break; default: arg->type = GTK_TYPE_INVALID; @@ -246,11 +247,16 @@ static gboolean gst_pipefilter_open_file(GstPipefilter *src) { if(src->childpid == 0) { - close(1); - dup(src->fdout[1]); /* set the childs output stream */ - close(0); - dup(src->fdin[0]); /* set the childs output stream */ - execlp("lame", "lame", "-x", "-", "-", NULL); + // child + dup2(src->fdin[0], STDIN_FILENO); /* set the childs input stream */ + dup2(src->fdout[1], STDOUT_FILENO); /* set the childs output stream */ + //execlp("lame", "lame", "-x", "-s", "48", "--resample", "44.1", "-", "-", NULL); + execvp(src->command[0], &src->command[0]); + // will only reach if error + perror("exec"); + gst_element_error(GST_ELEMENT(src),"starting child process"); + return FALSE; + } GST_FLAG_SET(src,GST_PIPEFILTER_OPEN); diff --git a/plugins/elements/gstpipefilter.h b/plugins/elements/gstpipefilter.h index 4e20e2bb48..5243643e80 100644 --- a/plugins/elements/gstpipefilter.h +++ b/plugins/elements/gstpipefilter.h @@ -58,8 +58,9 @@ struct _GstPipefilter { GstPad *sinkpad; GstPad *srcpad; - /* filename */ - gchar *filename; + /* command */ + gchar **command; + gchar *orig_command; /* fd */ gint fdout[2]; gint fdin[2]; @@ -69,8 +70,6 @@ struct _GstPipefilter { gulong bytes_per_read; /* bytes per read */ gulong seq; /* buffer sequence number */ - - gint control; }; struct _GstPipefilterClass { diff --git a/test/.gitignore b/test/.gitignore index 930e53a258..348b1819f0 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -39,3 +39,5 @@ aviparse avi2mpg vidcapture mp2tomp1 +mp1tomp1 +pipetest diff --git a/test/mp2tomp1.c b/test/mp2tomp1.c index 7ee5249d63..ee6bdd0a45 100644 --- a/test/mp2tomp1.c +++ b/test/mp2tomp1.c @@ -36,6 +36,8 @@ void mp2tomp1(GstElement *parser,GstPad *pad, GstElement *pipeline) { g_return_if_fail(decode != NULL); audio_encode = gst_elementfactory_make("pipefilter","audio_encode"); g_return_if_fail(audio_encode != NULL); + gtk_object_set(GTK_OBJECT(audio_encode),"command", + "lame -x -s 48 --resample 44.1 - -", NULL); // create the thread and pack stuff into it audio_thread = gst_thread_new("audio_thread");