From 2e7fa817e473ac5d7442f877232d8168cd957aed Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 11 Sep 2003 22:44:58 +0000 Subject: [PATCH] check for md5sink in pipeline Original commit message from CVS: check for md5sink in pipeline --- tools/gst-md5sum.1.in | 32 +++++++++++++++++++++++++++++--- tools/gst-md5sum.c | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/tools/gst-md5sum.1.in b/tools/gst-md5sum.1.in index 4e6970c..90fc694 100644 --- a/tools/gst-md5sum.1.in +++ b/tools/gst-md5sum.1.in @@ -15,10 +15,12 @@ In theory, running should print out the same checksum as md5sum music.mp3 + +If the pipeline contains an md5sink element, gst-md5sum will query it +for the md5sum at the end of pipeline iteration. -The pipeline should be incomplete, that is, a final sink element -should be omitted, so that gst\-md5sum can connect the pipeline to -an md5sink element. +If it doesn't contain an md5sink element, gst-md5sum will automatically +connect an md5sink to the right hand side of the given pipeline. See the man page for gst\-launch or the GStreamer docuementation for more information on how to create a PARTIAL\-PIPELINE\-DESCRIPTION. @@ -52,3 +54,27 @@ Add directories separated with ':' to the plugin search path .BR gst\-launch (1) .SH "AUTHOR" The GStreamer team at http://gstreamer.net/ +*************** +*** 16,24 **** + + md5sum music.mp3 + + The pipeline should be incomplete, that is, a final sink element +- should be omitted, so that gst\-md5sum can connect the pipeline to +- an md5sink element. + + See the man page for gst\-launch or the GStreamer docuementation for + more information on how to create a PARTIAL\-PIPELINE\-DESCRIPTION. +--- 16,27 ---- + + md5sum music.mp3 + ++ If the pipeline contains an md5sink element, gst-md5sum will query it ++ for the md5sum at the end of pipeline iteration. ++ ++ If it doesn't contain an md5sink element, gst-md5sum will automatically ++ connect an md5sink to the right hand side of the given pipeline. + The pipeline should be incomplete, that is, a final sink element + + See the man page for gst\-launch or the GStreamer docuementation for + more information on how to create a PARTIAL\-PIPELINE\-DESCRIPTION. diff --git a/tools/gst-md5sum.c b/tools/gst-md5sum.c index 0d28c81..0863c95 100644 --- a/tools/gst-md5sum.c +++ b/tools/gst-md5sum.c @@ -59,7 +59,7 @@ main (int argc, char *argv[]) POPT_TABLEEND }; - GstElement *pipeline; + GstElement *pipeline = NULL; gchar **argvn; GError *error = NULL; GstElement *md5sink; @@ -70,16 +70,39 @@ main (int argc, char *argv[]) setlocale (LC_ALL, ""); gst_init_with_popt_table (&argc, &argv, options); - - /* make a null-terminated version of argv with ! md5sink appended - * ! is stored in argvn[argc - 1], md5sink in argvn[argc], - * NULL pointer in argvn[argc + 1] */ - argvn = g_new0 (char *, argc + 2); + + /* make a parseable argvn array */ + argvn = g_new0 (char *, argc); memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1)); - argvn[argc - 1] = g_strdup_printf ("!"); - argvn[argc] = g_strdup_printf ("md5sink"); + /* Check if we have an element already that is called md5sink0 + in the pipeline; if not, add one */ pipeline = (GstElement*) gst_parse_launchv ((const gchar**) argvn, &error); + if (!pipeline) { + if (error) + { + g_warning ("pipeline could not be constructed: %s\n", error->message); + g_error_free (error); + } + else + g_warning ("pipeline could not be constructed\n"); + return 1; + } + + md5sink = gst_bin_get_by_name (GST_BIN (pipeline), "md5sink0"); + if (md5sink == NULL) + { + g_print ("adding an md5sink element to the pipeline\n"); + /* make a null-terminated version of argv with ! md5sink appended + * ! is stored in argvn[argc - 1], md5sink in argvn[argc], + * NULL pointer in argvn[argc + 1] */ + g_free (argvn); + argvn = g_new0 (char *, argc + 2); + memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1)); + argvn[argc - 1] = g_strdup_printf ("!"); + argvn[argc] = g_strdup_printf ("md5sink"); + pipeline = (GstElement*) gst_parse_launchv ((const gchar**) argvn, &error); + } if (!pipeline) { if (error) -- 2.7.4