mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
tools/: Add back --version command line option (#340460).
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.
This commit is contained in:
parent
5648075468
commit
73fd4a213a
7 changed files with 210 additions and 49 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
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:
|
||||
|
|
|
@ -37,24 +37,24 @@ bin_SCRIPTS = gst-feedback-@GST_MAJORMINOR@
|
|||
|
||||
# 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)
|
||||
|
||||
|
@ -112,6 +112,8 @@ man_MANS = $(manpages)
|
|||
# developer helper tools, not meant for installation
|
||||
noinst_SCRIPTS = gst-indent
|
||||
|
||||
noinst_HEADERS = tools.h
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(noinst_SCRIPTS) \
|
||||
gst-feedback.1.in \
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <gst/controller/gstcontroller.h>
|
||||
|
||||
#include "gst/gst-i18n-app.h"
|
||||
#include "tools.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -1098,6 +1099,7 @@ main (int argc, char *argv[])
|
|||
GOptionEntry options[] = {
|
||||
{"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
|
||||
N_("Print all elements"), NULL},
|
||||
GST_TOOLS_GOPTION_VERSION,
|
||||
{NULL}
|
||||
};
|
||||
GOptionContext *ctx;
|
||||
|
@ -1118,6 +1120,8 @@ main (int argc, char *argv[])
|
|||
}
|
||||
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;
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#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. */
|
||||
|
@ -512,6 +513,7 @@ main (int argc, char *argv[])
|
|||
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;
|
||||
|
@ -539,6 +541,8 @@ main (int argc, char *argv[])
|
|||
}
|
||||
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++) {
|
||||
|
|
|
@ -31,38 +31,45 @@
|
|||
#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;
|
||||
GstElement *source;
|
||||
GstElement *typefind;
|
||||
GstElement *fakesink;
|
||||
GstState state;
|
||||
GstCaps *caps = NULL;
|
||||
GDir *dir;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
if ((dir = g_dir_open (filename, 0, NULL))) {
|
||||
const gchar *entry;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
while ((entry = g_dir_read_name (dir))) {
|
||||
gchar *path;
|
||||
|
||||
if (argc < 2) {
|
||||
g_print ("Please give a filename to typefind\n\n");
|
||||
return 1;
|
||||
path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL);
|
||||
typefind_file (path);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
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));
|
||||
|
@ -75,40 +82,102 @@ main (int argc, char *argv[])
|
|||
gst_element_link_many (source, typefind, fakesink, NULL);
|
||||
|
||||
g_signal_connect (G_OBJECT (typefind), "have-type",
|
||||
G_CALLBACK (have_type_handler), NULL);
|
||||
G_CALLBACK (have_type_handler), &caps);
|
||||
|
||||
while (i < argc) {
|
||||
GstStateChangeReturn sret;
|
||||
GstState state;
|
||||
g_object_set (source, "location", filename, NULL);
|
||||
|
||||
filename = argv[i];
|
||||
g_object_set (source, "location", filename, NULL);
|
||||
GST_DEBUG ("Starting typefinding for %s", filename);
|
||||
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
/* wait until state change either completes or fails */
|
||||
sret = gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL, -1);
|
||||
|
||||
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]);
|
||||
switch (sret) {
|
||||
case GST_STATE_CHANGE_FAILURE:{
|
||||
GstMessage *msg;
|
||||
GstBus *bus;
|
||||
GError *err = NULL;
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
case GST_STATE_CHANGE_SUCCESS:{
|
||||
if (caps) {
|
||||
gchar *caps_str;
|
||||
|
||||
i++;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#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); \
|
||||
|
@ -767,6 +769,7 @@ main (int argc, char *argv[])
|
|||
"Show plugin details", NULL},
|
||||
{"gst-inspect-scheduler", 's', 0, G_OPTION_ARG_STRING,
|
||||
"Show scheduler details", NULL},
|
||||
GST_TOOLS_GOPTION_VERSION,
|
||||
{NULL}
|
||||
};
|
||||
GOptionContext *ctx;
|
||||
|
@ -783,6 +786,8 @@ main (int argc, char *argv[])
|
|||
}
|
||||
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 */
|
||||
|
|
63
tools/tools.h
Normal file
63
tools/tools.h
Normal file
|
@ -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__ */
|
Loading…
Reference in a new issue