summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5648075)
raw | patch | inline | side by side (parent: 5648075)
author | Tim-Philipp Müller <tim@centricular.net> | |
Fri, 5 May 2006 17:07:42 +0000 (17:07 +0000) | ||
committer | Tim-Philipp Müller <tim@centricular.net> | |
Fri, 5 May 2006 17:07:42 +0000 (17:07 +0000) |
Original commit message from CVS:
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-xmlinspect.c: (main):
* tools/tools.h:
Add back --version command line option (#340460).
* tools/gst-typefind.c: (have_type_handler), (typefind_file), (main):
Add --version option and use GOption for argument parsing; refactor a
bit; accept directories as arguments and recurse into them; lastly,
print a decent error message when things go wrong.
* tools/Makefile.am:
* tools/gst-inspect.c: (main):
* tools/gst-launch.c: (main):
* tools/gst-xmlinspect.c: (main):
* tools/tools.h:
Add back --version command line option (#340460).
* tools/gst-typefind.c: (have_type_handler), (typefind_file), (main):
Add --version option and use GOption for argument parsing; refactor a
bit; accept directories as arguments and recurse into them; lastly,
print a decent error message when things go wrong.
ChangeLog | patch | blob | history | |
tools/Makefile.am | patch | blob | history | |
tools/gst-inspect.c | patch | blob | history | |
tools/gst-launch.c | patch | blob | history | |
tools/gst-typefind.c | patch | blob | history | |
tools/gst-xmlinspect.c | patch | blob | history | |
tools/tools.h | [new file with mode: 0644] | patch | blob |
diff --git a/ChangeLog b/ChangeLog
index 1a739338f96edeeff636be197b0b52a8d67a2edb..996eff7617d823b0f49f82bf9408077011f78bc3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+2006-05-05 Tim-Philipp Müller <tim at centricular dot net>
+
+ * tools/Makefile.am:
+ * tools/gst-inspect.c: (main):
+ * tools/gst-launch.c: (main):
+ * tools/gst-xmlinspect.c: (main):
+ * tools/tools.h:
+ Add back --version command line option (#340460).
+
+ * tools/gst-typefind.c: (have_type_handler), (typefind_file), (main):
+ Add --version option and use GOption for argument parsing; refactor a
+ bit; accept directories as arguments and recurse into them; lastly,
+ print a decent error message when things go wrong.
+
2006-05-05 Maciej Katafiasz <mathrick@freedesktop.org>
* docs/manual/basics-bins.xml:
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 69757efa693cac130c6c7a7ba839bc5dae2a7717..05d5f480f6146bc5194b535eb153ba48ccfbcbbf 100644 (file)
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
# make sure each versioned tool has the right source file and flags
if !GST_DISABLE_LOADSAVE
-gst_xmllaunch_@GST_MAJORMINOR@_SOURCES = gst-launch.c
+gst_xmllaunch_@GST_MAJORMINOR@_SOURCES = gst-launch.c tools.h
gst_xmllaunch_@GST_MAJORMINOR@_CFLAGS = $(GST_OBJ_CFLAGS)
gst_xmllaunch_@GST_MAJORMINOR@_LDFLAGS = $(GST_OBJ_LIBS)
endif
if !GST_DISABLE_PARSE
-gst_launch_@GST_MAJORMINOR@_SOURCES = gst-launch.c
+gst_launch_@GST_MAJORMINOR@_SOURCES = gst-launch.c tools.h
gst_launch_@GST_MAJORMINOR@_CFLAGS = $(GST_OBJ_CFLAGS)
gst_launch_@GST_MAJORMINOR@_LDFLAGS = $(GST_OBJ_LIBS)
endif
-gst_inspect_@GST_MAJORMINOR@_SOURCES = gst-inspect.c
+gst_inspect_@GST_MAJORMINOR@_SOURCES = gst-inspect.c tools.h
gst_inspect_@GST_MAJORMINOR@_CFLAGS = $(GST_OBJ_CFLAGS)
gst_inspect_@GST_MAJORMINOR@_LDFLAGS = $(GST_OBJ_LIBS)
-gst_typefind_@GST_MAJORMINOR@_SOURCES = gst-typefind.c
+gst_typefind_@GST_MAJORMINOR@_SOURCES = gst-typefind.c tools.h
gst_typefind_@GST_MAJORMINOR@_CFLAGS = $(GST_OBJ_CFLAGS)
gst_typefind_@GST_MAJORMINOR@_LDFLAGS = $(GST_OBJ_LIBS)
-gst_xmlinspect_@GST_MAJORMINOR@_SOURCES = gst-xmlinspect.c
+gst_xmlinspect_@GST_MAJORMINOR@_SOURCES = gst-xmlinspect.c tools.h
gst_xmlinspect_@GST_MAJORMINOR@_CFLAGS = $(GST_OBJ_CFLAGS)
gst_xmlinspect_@GST_MAJORMINOR@_LDFLAGS = $(GST_OBJ_LIBS)
# developer helper tools, not meant for installation
noinst_SCRIPTS = gst-indent
+noinst_HEADERS = tools.h
+
EXTRA_DIST = \
$(noinst_SCRIPTS) \
gst-feedback.1.in \
diff --git a/tools/gst-inspect.c b/tools/gst-inspect.c
index b79f3d5aeea6f691388b7d3d5dc8e24d6aa5d6a3..f7a359f23fe4a16848510380eae9182367318f74 100644 (file)
--- a/tools/gst-inspect.c
+++ b/tools/gst-inspect.c
#include <gst/controller/gstcontroller.h>
#include "gst/gst-i18n-app.h"
+#include "tools.h"
#include <stdlib.h>
#include <string.h>
GOptionEntry options[] = {
{"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
N_("Print all elements"), NULL},
+ GST_TOOLS_GOPTION_VERSION,
{NULL}
};
GOptionContext *ctx;
}
g_option_context_free (ctx);
+ gst_tools_print_version ("gst-inspect");
+
if (print_all && argc > 2) {
g_print ("-a requires no extra arguments\n");
return 1;
diff --git a/tools/gst-launch.c b/tools/gst-launch.c
index 2d5b35d21b5f39674e6fac7081ca23a448fc9f93..dcce615141d6d26d5b839ac962daac82b4f29a7b 100644 (file)
--- a/tools/gst-launch.c
+++ b/tools/gst-launch.c
#include "gst/gst-i18n-app.h"
#include <gst/gst.h>
+#include "tools.h"
/* FIXME: This is just a temporary hack. We should have a better
* check for siginfo handling. */
N_("Do not install a fault handler"), NULL},
{"trace", 'T', 0, G_OPTION_ARG_NONE, &trace,
N_("Print alloc trace (if enabled at compile time)"), NULL},
+ GST_TOOLS_GOPTION_VERSION,
{NULL}
};
GOptionContext *ctx;
}
g_option_context_free (ctx);
+ gst_tools_print_version ("gst-launch");
+
/* FIXpopt: strip short args, too. We do it ourselves for now */
j = 1;
for (i = 1; i < argc; i++) {
diff --git a/tools/gst-typefind.c b/tools/gst-typefind.c
index 08413b488366b94b951c9113dd728cae7f1d6db1..5ce894711f8e4eefc4df14975c2efc7c98455544 100644 (file)
--- a/tools/gst-typefind.c
+++ b/tools/gst-typefind.c
#include <locale.h>
#include <gst/gst.h>
+#include "tools.h"
-char *filename = NULL;
-
-
-void
+static void
have_type_handler (GstElement * typefind, guint probability,
- const GstCaps * caps, gpointer unused)
+ const GstCaps * caps, GstCaps ** p_caps)
{
- gchar *caps_str;
-
- caps_str = gst_caps_to_string (caps);
- g_print ("%s - %s\n", filename, caps_str);
- g_free (caps_str);
+ if (p_caps) {
+ *p_caps = gst_caps_copy (caps);
+ }
}
-int
-main (int argc, char *argv[])
+static void
+typefind_file (const gchar * filename)
{
- guint i = 1;
+ GstStateChangeReturn sret;
GstElement *pipeline;
- GstElement *source, *typefind, *fakesink;
-
- setlocale (LC_ALL, "");
-
- gst_init (&argc, &argv);
+ GstElement *source;
+ GstElement *typefind;
+ GstElement *fakesink;
+ GstState state;
+ GstCaps *caps = NULL;
+ GDir *dir;
+
+ if ((dir = g_dir_open (filename, 0, NULL))) {
+ const gchar *entry;
+
+ while ((entry = g_dir_read_name (dir))) {
+ gchar *path;
+
+ path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL);
+ typefind_file (path);
+ g_free (path);
+ }
- if (argc < 2) {
- g_print ("Please give a filename to typefind\n\n");
- return 1;
+ g_dir_close (dir);
+ return;
}
- pipeline = gst_pipeline_new (NULL);
+ pipeline = gst_pipeline_new ("pipeline");
source = gst_element_factory_make ("filesrc", "source");
g_assert (GST_IS_ELEMENT (source));
gst_element_link_many (source, typefind, fakesink, NULL);
g_signal_connect (G_OBJECT (typefind), "have-type",
- G_CALLBACK (have_type_handler), NULL);
-
- while (i < argc) {
- GstStateChangeReturn sret;
- GstState state;
-
- filename = argv[i];
- g_object_set (source, "location", filename, NULL);
-
- GST_DEBUG ("Starting typefinding for %s", filename);
-
- /* typefind will only commit to PAUSED if it actually finds a type;
- * otherwise the state change fails */
- sret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
-
- if (GST_STATE_CHANGE_ASYNC == sret) {
- if (GST_STATE_CHANGE_FAILURE ==
- gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
- GST_CLOCK_TIME_NONE))
- break;
- } else if (sret != GST_STATE_CHANGE_SUCCESS)
- g_print ("%s - No type found\n", argv[i]);
-
- if (GST_STATE_CHANGE_ASYNC ==
- gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL)) {
- if (GST_STATE_CHANGE_FAILURE ==
- gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
- GST_CLOCK_TIME_NONE))
- break;
+ G_CALLBACK (have_type_handler), &caps);
+
+ g_object_set (source, "location", filename, NULL);
+
+ GST_DEBUG ("Starting typefinding for %s", filename);
+
+ /* typefind will only commit to PAUSED if it actually finds a type;
+ * otherwise the state change fails */
+ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
+
+ /* wait until state change either completes or fails */
+ sret = gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL, -1);
+
+ switch (sret) {
+ case GST_STATE_CHANGE_FAILURE:{
+ GstMessage *msg;
+ GstBus *bus;
+ GError *err = NULL;
+
+ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+ msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
+ gst_object_unref (bus);
+
+ if (msg) {
+ gst_message_parse_error (msg, &err, NULL);
+ g_printerr ("%s - FAILED: %s\n", filename, err->message);
+ g_error_free (err);
+ gst_message_unref (msg);
+ } else {
+ g_printerr ("%s - FAILED: unknown error\n", filename);
+ }
+ break;
}
-
- i++;
+ case GST_STATE_CHANGE_SUCCESS:{
+ if (caps) {
+ gchar *caps_str;
+
+ caps_str = gst_caps_to_string (caps);
+ g_print ("%s - %s\n", filename, caps_str);
+ g_free (caps_str);
+ gst_caps_unref (caps);
+ } else {
+ g_print ("%s - %s\n", filename, "No type found");
+ }
+ break;
+ }
+ default:
+ g_assert_not_reached ();
}
+ gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
+}
+
+int
+main (int argc, char *argv[])
+{
+ gchar **filenames = NULL;
+ guint num, i;
+ GError *err = NULL;
+ GOptionContext *ctx;
+ GOptionEntry options[] = {
+ GST_TOOLS_GOPTION_VERSION,
+ {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
+ {NULL}
+ };
+
+#ifdef ENABLE_NLS
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+#endif
+
+ ctx = g_option_context_new ("gst-typefind");
+ g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
+ g_option_context_add_group (ctx, gst_init_get_option_group ());
+ if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
+ g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
+ exit (1);
+ }
+ g_option_context_free (ctx);
+
+ gst_tools_print_version ("gst-typefind");
+
+ if (filenames == NULL || *filenames == NULL) {
+ g_print ("Please give a filename to typefind\n\n");
+ return 1;
+ }
+
+ num = g_strv_length (filenames);
+
+ for (i = 0; i < num; ++i) {
+ typefind_file (filenames[i]);
+ }
+
+ g_strfreev (filenames);
+
return 0;
}
diff --git a/tools/gst-xmlinspect.c b/tools/gst-xmlinspect.c
index d7f5a0785228c38752afb2830dd164aefd0f76bb..9526754d08d8ec3ebd487d306956cbb4421df1df 100644 (file)
--- a/tools/gst-xmlinspect.c
+++ b/tools/gst-xmlinspect.c
#include <locale.h>
#include <glib/gprintf.h>
+#include "tools.h"
+
#define PUT_START_TAG(pfx,tag) \
G_STMT_START{ \
g_print ("%*.*s<%s>\n", pfx, pfx, "", tag); \
"Show plugin details", NULL},
{"gst-inspect-scheduler", 's', 0, G_OPTION_ARG_STRING,
"Show scheduler details", NULL},
+ GST_TOOLS_GOPTION_VERSION,
{NULL}
};
GOptionContext *ctx;
}
g_option_context_free (ctx);
+ gst_tools_print_version ("gst-xmlinspect");
+
PUT_STRING (0, "<?xml version=\"1.0\"?>");
/* if no arguments, print out list of elements */
diff --git a/tools/tools.h b/tools/tools.h
--- /dev/null
+++ b/tools/tools.h
@@ -0,0 +1,63 @@
+/* GStreamer
+ * Copyright (C) 2005 Benjamin Otte <otte@gnome.org>
+ *
+ * tools.h: header for common stuff of all GStreamer tools
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifndef __GST_TOOLS_H__
+#define __GST_TOOLS_H__
+
+#include "gst/gst-i18n-app.h"
+
+/*
+ * This is a kind of hacky way to make all the tools use the same version code.
+ * If anyone knows a less hacky way to get this done, feel free to implement it.
+ *
+ * It also includes all the files that all the tools require.
+ */
+
+static gboolean __gst_tools_version = FALSE;
+
+#define GST_TOOLS_GOPTION_VERSION \
+ { "version", 0, 0, G_OPTION_ARG_NONE, &__gst_tools_version, \
+ N_("Print version information and exit"), NULL }
+
+static void
+gst_tools_print_version (const gchar * tool)
+{
+ gchar *s;
+
+ s = g_strdup_printf ("%s-%u.%u", tool, GST_VERSION_MAJOR, GST_VERSION_MINOR);
+ g_set_prgname (s);
+ g_free (s);
+
+ if (__gst_tools_version) {
+ gchar *version_str;
+
+ version_str = gst_version_string ();
+ g_print ("%s version %u.%u.%u\n", g_get_prgname (),
+ GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO);
+ g_print ("%s\n", version_str);
+ g_print ("%s\n", GST_PACKAGE_ORIGIN);
+ g_free (version_str);
+ exit (0);
+ }
+}
+
+#endif /* __GST_TOOLS_H__ */