diff --git a/tools/gst-md5sum.1.in b/tools/gst-md5sum.1.in index 4e6970c6fd..90fc69443f 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 0d28c81ebc..0863c95146 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); - memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1)); - argvn[argc - 1] = g_strdup_printf ("!"); - argvn[argc] = g_strdup_printf ("md5sink"); + /* make a parseable argvn array */ + argvn = g_new0 (char *, argc); + memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1)); + + /* 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)