*
* 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+#include <locale.h>
+
#include <stdlib.h>
#include <glib.h>
#include <gst/gst.h>
#include <gst/pbutils/pbutils.h>
+#define MAX_INDENT 40
+
+/* *INDENT-OFF* */
+static void my_g_string_append_printf (GString * str, int depth, const gchar * format, ...) G_GNUC_PRINTF (3, 4);
+/* *INDENT-ON* */
+
static gboolean async = FALSE;
-static gboolean silent = FALSE;
+static gboolean show_toc = FALSE;
static gboolean verbose = FALSE;
typedef struct
char **argv;
} PrivStruct;
-#define my_g_string_append_printf(str, format, ...) \
- g_string_append_printf (str, "%*s" format, 2*depth, " ", ##__VA_ARGS__)
+static void
+my_g_string_append_printf (GString * str, int depth, const gchar * format, ...)
+{
+ va_list args;
-static gchar *
-gst_stream_audio_information_to_string (GstDiscovererStreamInfo * info,
- gint depth)
+ while (depth-- > 0) {
+ g_string_append (str, " ");
+ }
+
+ va_start (args, format);
+ g_string_append_vprintf (str, format, args);
+ va_end (args);
+}
+
+static void
+gst_stream_information_to_string (GstDiscovererStreamInfo * info, GString * s,
+ guint depth)
{
- GstDiscovererAudioInfo *audio_info;
- GString *s;
gchar *tmp;
- int len = 400;
- const GstTagList *tags;
GstCaps *caps;
+ const GstStructure *misc;
- g_return_val_if_fail (info != NULL, NULL);
-
- s = g_string_sized_new (len);
-
- my_g_string_append_printf (s, "Codec:\n");
+ my_g_string_append_printf (s, depth, "Codec:\n");
caps = gst_discoverer_stream_info_get_caps (info);
tmp = gst_caps_to_string (caps);
gst_caps_unref (caps);
- my_g_string_append_printf (s, " %s\n", tmp);
+ my_g_string_append_printf (s, depth, " %s\n", tmp);
g_free (tmp);
- my_g_string_append_printf (s, "Additional info:\n");
- if (gst_discoverer_stream_info_get_misc (info)) {
- tmp = gst_structure_to_string (gst_discoverer_stream_info_get_misc (info));
- my_g_string_append_printf (s, " %s\n", tmp);
+ my_g_string_append_printf (s, depth, "Additional info:\n");
+ if ((misc = gst_discoverer_stream_info_get_misc (info))) {
+ tmp = gst_structure_to_string (misc);
+ my_g_string_append_printf (s, depth, " %s\n", tmp);
g_free (tmp);
} else {
- my_g_string_append_printf (s, " None\n");
+ my_g_string_append_printf (s, depth, " None\n");
+ }
+
+ my_g_string_append_printf (s, depth, "Stream ID: %s\n",
+ gst_discoverer_stream_info_get_stream_id (info));
+}
+
+static void
+print_tag_foreach (const GstTagList * tags, const gchar * tag,
+ gpointer user_data)
+{
+ GValue val = { 0, };
+ gchar *str;
+ guint depth = GPOINTER_TO_UINT (user_data);
+
+ if (!gst_tag_list_copy_value (&val, tags, tag))
+ return;
+
+ if (G_VALUE_HOLDS_STRING (&val)) {
+ str = g_value_dup_string (&val);
+ } else if (G_VALUE_TYPE (&val) == GST_TYPE_SAMPLE) {
+ GstSample *sample = gst_value_get_sample (&val);
+ GstBuffer *img = gst_sample_get_buffer (sample);
+ GstCaps *caps = gst_sample_get_caps (sample);
+
+ if (img) {
+ if (caps) {
+ gchar *caps_str;
+
+ caps_str = gst_caps_to_string (caps);
+ str = g_strdup_printf ("buffer of %" G_GSIZE_FORMAT " bytes, "
+ "type: %s", gst_buffer_get_size (img), caps_str);
+ g_free (caps_str);
+ } else {
+ str = g_strdup_printf ("buffer of %" G_GSIZE_FORMAT " bytes",
+ gst_buffer_get_size (img));
+ }
+ } else {
+ str = g_strdup ("NULL buffer");
+ }
+ } else {
+ str = gst_value_serialize (&val);
+ }
+
+ g_print ("%*s%s: %s\n", 2 * depth, " ", gst_tag_get_nick (tag), str);
+ g_free (str);
+
+ g_value_unset (&val);
+}
+
+static void
+print_tags_topology (guint depth, const GstTagList * tags)
+{
+ g_print ("%*sTags:\n", 2 * depth, " ");
+ if (tags) {
+ gst_tag_list_foreach (tags, print_tag_foreach,
+ GUINT_TO_POINTER (depth + 1));
+ } else {
+ g_print ("%*sNone\n", 2 * (depth + 1), " ");
}
+ if (verbose)
+ g_print ("%*s\n", 2 * depth, " ");
+}
+
+static gchar *
+gst_stream_audio_information_to_string (GstDiscovererStreamInfo * info,
+ guint depth)
+{
+ GstDiscovererAudioInfo *audio_info;
+ GString *s;
+ const gchar *ctmp;
+ int len = 400;
+ const GstTagList *tags;
+
+ g_return_val_if_fail (info != NULL, NULL);
+
+ s = g_string_sized_new (len);
+
+ gst_stream_information_to_string (info, s, depth);
audio_info = (GstDiscovererAudioInfo *) info;
- my_g_string_append_printf (s, "Channels: %u\n",
+ ctmp = gst_discoverer_audio_info_get_language (audio_info);
+ my_g_string_append_printf (s, depth, "Language: %s\n",
+ ctmp ? ctmp : "<unknown>");
+ my_g_string_append_printf (s, depth, "Channels: %u\n",
gst_discoverer_audio_info_get_channels (audio_info));
- my_g_string_append_printf (s, "Sample rate: %u\n",
+ my_g_string_append_printf (s, depth, "Sample rate: %u\n",
gst_discoverer_audio_info_get_sample_rate (audio_info));
- my_g_string_append_printf (s, "Depth: %u\n",
+ my_g_string_append_printf (s, depth, "Depth: %u\n",
gst_discoverer_audio_info_get_depth (audio_info));
- my_g_string_append_printf (s, "Bitrate: %u\n",
+ my_g_string_append_printf (s, depth, "Bitrate: %u\n",
gst_discoverer_audio_info_get_bitrate (audio_info));
- my_g_string_append_printf (s, "Max bitrate: %u\n",
+ my_g_string_append_printf (s, depth, "Max bitrate: %u\n",
gst_discoverer_audio_info_get_max_bitrate (audio_info));
- my_g_string_append_printf (s, "Tags:\n");
tags = gst_discoverer_stream_info_get_tags (info);
- if (tags) {
- tmp = gst_structure_to_string ((GstStructure *) tags);
- my_g_string_append_printf (s, " %s\n", tmp);
- g_free (tmp);
- } else {
- my_g_string_append_printf (s, " None\n");
- }
- if (verbose)
- my_g_string_append_printf (s, "\n");
+ print_tags_topology (depth, tags);
return g_string_free (s, FALSE);
}
static gchar *
gst_stream_video_information_to_string (GstDiscovererStreamInfo * info,
- gint depth)
+ guint depth)
{
GstDiscovererVideoInfo *video_info;
GString *s;
- gchar *tmp;
int len = 500;
- const GstStructure *misc;
const GstTagList *tags;
- GstCaps *caps;
g_return_val_if_fail (info != NULL, NULL);
s = g_string_sized_new (len);
- my_g_string_append_printf (s, "Codec:\n");
- caps = gst_discoverer_stream_info_get_caps (info);
- tmp = gst_caps_to_string (caps);
- gst_caps_unref (caps);
- my_g_string_append_printf (s, " %s\n", tmp);
- g_free (tmp);
-
- my_g_string_append_printf (s, "Additional info:\n");
- misc = gst_discoverer_stream_info_get_misc (info);
- if (misc) {
- tmp = gst_structure_to_string (misc);
- my_g_string_append_printf (s, " %s\n", tmp);
- g_free (tmp);
- } else {
- my_g_string_append_printf (s, " None\n");
- }
+ gst_stream_information_to_string (info, s, depth);
video_info = (GstDiscovererVideoInfo *) info;
- my_g_string_append_printf (s, "Width: %u\n",
+ my_g_string_append_printf (s, depth, "Width: %u\n",
gst_discoverer_video_info_get_width (video_info));
- my_g_string_append_printf (s, "Height: %u\n",
+ my_g_string_append_printf (s, depth, "Height: %u\n",
gst_discoverer_video_info_get_height (video_info));
- my_g_string_append_printf (s, "Depth: %u\n",
+ my_g_string_append_printf (s, depth, "Depth: %u\n",
gst_discoverer_video_info_get_depth (video_info));
- my_g_string_append_printf (s, "Frame rate: %u/%u\n",
+ my_g_string_append_printf (s, depth, "Frame rate: %u/%u\n",
gst_discoverer_video_info_get_framerate_num (video_info),
gst_discoverer_video_info_get_framerate_denom (video_info));
- my_g_string_append_printf (s, "Pixel aspect ratio: %u/%u\n",
+ my_g_string_append_printf (s, depth, "Pixel aspect ratio: %u/%u\n",
gst_discoverer_video_info_get_par_num (video_info),
gst_discoverer_video_info_get_par_denom (video_info));
- my_g_string_append_printf (s, "Interlaced: %s\n",
+ my_g_string_append_printf (s, depth, "Interlaced: %s\n",
gst_discoverer_video_info_is_interlaced (video_info) ? "true" : "false");
- my_g_string_append_printf (s, "Bitrate: %u\n",
+ my_g_string_append_printf (s, depth, "Bitrate: %u\n",
gst_discoverer_video_info_get_bitrate (video_info));
- my_g_string_append_printf (s, "Max bitrate: %u\n",
+ my_g_string_append_printf (s, depth, "Max bitrate: %u\n",
gst_discoverer_video_info_get_max_bitrate (video_info));
- my_g_string_append_printf (s, "Tags:\n");
tags = gst_discoverer_stream_info_get_tags (info);
- if (tags) {
- tmp = gst_structure_to_string ((GstStructure *) tags);
- my_g_string_append_printf (s, " %s\n", tmp);
- g_free (tmp);
- } else {
- my_g_string_append_printf (s, " None\n");
- }
- if (verbose)
- my_g_string_append_printf (s, "\n");
+ print_tags_topology (depth, tags);
+
+ return g_string_free (s, FALSE);
+}
+
+static gchar *
+gst_stream_subtitle_information_to_string (GstDiscovererStreamInfo * info,
+ guint depth)
+{
+ GstDiscovererSubtitleInfo *subtitle_info;
+ GString *s;
+ const gchar *ctmp;
+ int len = 400;
+ const GstTagList *tags;
+
+ g_return_val_if_fail (info != NULL, NULL);
+
+ s = g_string_sized_new (len);
+
+ gst_stream_information_to_string (info, s, depth);
+
+ subtitle_info = (GstDiscovererSubtitleInfo *) info;
+ ctmp = gst_discoverer_subtitle_info_get_language (subtitle_info);
+ my_g_string_append_printf (s, depth, "Language: %s\n",
+ ctmp ? ctmp : "<unknown>");
+
+ tags = gst_discoverer_stream_info_get_tags (info);
+ print_tags_topology (depth, tags);
return g_string_free (s, FALSE);
}
desc =
gst_stream_video_information_to_string (info,
GPOINTER_TO_INT (depth) + 1);
+ else if (GST_IS_DISCOVERER_SUBTITLE_INFO (info))
+ desc =
+ gst_stream_subtitle_information_to_string (info,
+ GPOINTER_TO_INT (depth) + 1);
if (desc) {
g_print ("%s", desc);
g_free (desc);
}
static void
-print_topology (GstDiscovererStreamInfo * info, gint depth)
+print_topology (GstDiscovererStreamInfo * info, guint depth)
{
GstDiscovererStreamInfo *next;
}
}
-static gboolean
-print_tag_each (GQuark field_id, const GValue * value, gpointer user_data)
+static void
+print_toc_entry (gpointer data, gpointer user_data)
{
- gint tab = GPOINTER_TO_INT (user_data);
- gchar *ser;
-
- if (G_VALUE_HOLDS_STRING (value))
- ser = g_value_dup_string (value);
- else if (GST_VALUE_HOLDS_BUFFER (value)) {
- GstBuffer *buf = gst_value_get_buffer (value);
- ser =
- g_strdup_printf ("<GstBuffer [%" G_GSIZE_FORMAT " bytes]>",
- gst_buffer_get_size (buf));
- } else
- ser = gst_value_serialize (value);
-
- g_print ("%*s%s: %s\n", tab, " ",
- gst_tag_get_nick (g_quark_to_string (field_id)), ser);
- g_free (ser);
-
- return TRUE;
+ GstTocEntry *entry = (GstTocEntry *) data;
+ guint depth = GPOINTER_TO_UINT (user_data);
+ guint indent = MIN (GPOINTER_TO_UINT (user_data), MAX_INDENT);
+ GstTagList *tags;
+ GList *subentries;
+ gint64 start, stop;
+
+ gst_toc_entry_get_start_stop_times (entry, &start, &stop);
+ g_print ("%*s%s: start: %" GST_TIME_FORMAT " stop: %" GST_TIME_FORMAT "\n",
+ depth, " ",
+ gst_toc_entry_type_get_nick (gst_toc_entry_get_entry_type (entry)),
+ GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
+ indent += 2;
+
+ /* print tags */
+ tags = gst_toc_entry_get_tags (entry);
+ if (tags) {
+ g_print ("%*sTags:\n", 2 * depth, " ");
+ gst_tag_list_foreach (tags, print_tag_foreach, GUINT_TO_POINTER (indent));
+ }
+
+ /* loop over sub-toc entries */
+ subentries = gst_toc_entry_get_sub_entries (entry);
+ g_list_foreach (subentries, print_toc_entry, GUINT_TO_POINTER (indent));
}
static void
print_properties (GstDiscovererInfo * info, gint tab)
{
const GstTagList *tags;
+ const GstToc *toc;
g_print ("%*sDuration: %" GST_TIME_FORMAT "\n", tab + 1, " ",
GST_TIME_ARGS (gst_discoverer_info_get_duration (info)));
(gst_discoverer_info_get_seekable (info) ? "yes" : "no"));
if ((tags = gst_discoverer_info_get_tags (info))) {
g_print ("%*sTags: \n", tab + 1, " ");
- gst_structure_foreach ((const GstStructure *) tags, print_tag_each,
- GINT_TO_POINTER (tab + 5));
+ gst_tag_list_foreach (tags, print_tag_foreach, GUINT_TO_POINTER (tab + 2));
+ }
+ if (show_toc && (toc = gst_discoverer_info_get_toc (info))) {
+ GList *entries;
+
+ g_print ("%*sTOC: \n", tab + 1, " ");
+ entries = gst_toc_get_entries (toc);
+ g_list_foreach (entries, print_toc_entry, GUINT_TO_POINTER (tab + 5));
}
}
static void
print_info (GstDiscovererInfo * info, GError * err)
{
- GstDiscovererResult result = gst_discoverer_info_get_result (info);
+ GstDiscovererResult result;
GstDiscovererStreamInfo *sinfo;
+ if (!info) {
+ g_print ("Could not discover URI\n");
+ g_print (" %s\n", err->message);
+ return;
+ }
+
+ result = gst_discoverer_info_get_result (info);
g_print ("Done discovering %s\n", gst_discoverer_info_get_uri (info));
switch (result) {
case GST_DISCOVERER_OK:
{
g_print ("Missing plugins\n");
if (verbose) {
- gchar *tmp =
- gst_structure_to_string (gst_discoverer_info_get_misc (info));
- g_print (" (%s)\n", tmp);
- g_free (tmp);
+ gint i = 0;
+ const gchar **installer_details =
+ gst_discoverer_info_get_missing_elements_installer_details (info);
+
+ while (installer_details[i]) {
+ g_print (" (%s)\n", installer_details[i]);
+
+ i++;
+ }
}
break;
}
GDir *dir;
gchar *uri, *path;
GstDiscovererInfo *info;
- GstStructure *st = NULL;
if (!gst_uri_is_valid (filename)) {
/* Recurse into directories */
if (err) {
g_warning ("Couldn't convert filename to URI: %s\n", err->message);
- g_error_free (err);
+ g_clear_error (&err);
return;
}
} else {
uri = g_strdup (filename);
}
- if (async == FALSE) {
+ if (!async) {
g_print ("Analyzing %s\n", uri);
info = gst_discoverer_discover_uri (dc, uri, &err);
print_info (info, err);
- gst_discoverer_info_unref (info);
- if (st)
- gst_structure_free (st);
+ g_clear_error (&err);
+ if (info)
+ gst_discoverer_info_unref (info);
} else {
gst_discoverer_discover_uri_async (dc, uri);
}
GOptionEntry options[] = {
{"async", 'a', 0, G_OPTION_ARG_NONE, &async,
"Run asynchronously", NULL},
- {"silent", 's', 0, G_OPTION_ARG_NONE, &silent,
- "Don't output the information structure", NULL},
{"timeout", 't', 0, G_OPTION_ARG_INT, &timeout,
"Specify timeout (in seconds, default 10)", "T"},
/* {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek, */
/* "Seek on elements instead of pads", NULL}, */
+ {"toc", 'c', 0, G_OPTION_ARG_NONE, &show_toc,
+ "Output TOC (chapters and editions)", NULL},
{"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Verbose properties", NULL},
{NULL}
};
GOptionContext *ctx;
- if (!g_thread_supported ())
- g_thread_init (NULL);
+ setlocale (LC_ALL, "");
ctx =
g_option_context_new
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
g_print ("Error initializing: %s\n", err->message);
+ g_option_context_free (ctx);
+ g_clear_error (&err);
exit (1);
}
dc = gst_discoverer_new (timeout * GST_SECOND, &err);
if (G_UNLIKELY (dc == NULL)) {
g_print ("Error initializing: %s\n", err->message);
+ g_clear_error (&err);
exit (1);
}
- if (async == FALSE) {
+ if (!async) {
gint i;
for (i = 1; i < argc; i++)
process_file (dc, argv[i]);