Skip to content

Commit

Permalink
discoverer: Enhance printed information when not verbose
Browse files Browse the repository at this point in the history
Basically print information about media tracks making without tags
nor buffers in caps making still quite small but containing all
information infos.

Stop making 'Topology' section and just print the info

before:

```
Topology:
  container: MPEG-2 Transport Stream
    audio: AC-3 (ATSC A/52)
    video: H.264 (High Profile)

Properties:
  Duration: 0:00:05.512394259
  Seekable: yes
  Live: no
  Tags:
      audio codec: AC-3 (ATSC A/52)
      bitrate: 192000
      video codec: H.264 (High Profile)
      minimum bitrate: 12947
      maximum bitrate: 12947
```

After:

```
Properties:
  Duration: 0:00:05.512394259
  Seekable: yes
  Live: no
  container: MPEG-2 Transport Stream
    audio: AC-3 (ATSC A/52)
      Stream ID: b076403d73e0c5fc13985832e8d585945603993437ba14b0799f422f9495e8ef:1/00001100
      Language: <unknown>
      Channels: 2 (front-left, front-right)
      Sample rate: 48000
      Depth: 32
      Bitrate: 192000
      Max bitrate: 0
    video: H.264 (High Profile)
      Stream ID: b076403d73e0c5fc13985832e8d585945603993437ba14b0799f422f9495e8ef:1/00001011
      Width: 1920
      Height: 1080
      Depth: 24
      Frame rate: 30000/1001
      Pixel aspect ratio: 1/1
      Interlaced: true
      Bitrate: 10363396
      Max bitrate: 12947
```
  • Loading branch information
thiblahute committed Apr 6, 2020
1 parent 6ea225c commit 545a993
Showing 1 changed file with 95 additions and 45 deletions.
140 changes: 95 additions & 45 deletions tools/gst-discoverer.c
Expand Up @@ -46,6 +46,37 @@ typedef struct
char **argv;
} PrivStruct;

static gboolean
structure_remove_buffers_ip (GQuark field_id, GValue * value,
gpointer user_data)
{
if (G_VALUE_HOLDS (value, GST_TYPE_BUFFER))
return FALSE;

if (GST_VALUE_HOLDS_ARRAY (value)) {
gint i;

for (i = 0; i < gst_value_array_get_size (value); i++) {
if (structure_remove_buffers_ip (0,
(GValue *) gst_value_array_get_value (value, i), user_data))
return TRUE;
}

return FALSE;
}
return TRUE;
}

static gboolean
caps_remove_buffers_ip (GstCapsFeatures * features, GstStructure * structure,
gpointer user_data)
{
gst_structure_filter_and_map_in_place (structure,
structure_remove_buffers_ip, NULL);

return TRUE;
}

static void
my_g_string_append_printf (GString * str, int depth, const gchar * format, ...)
{
Expand All @@ -60,6 +91,26 @@ my_g_string_append_printf (GString * str, int depth, const gchar * format, ...)
va_end (args);
}

static gchar *
caps_to_string (GstCaps * caps)
{
gchar *res = NULL;

if (verbose) {
res = gst_caps_to_string (caps);
goto done;
}

caps = gst_caps_make_writable (caps);

gst_caps_map_in_place (caps, caps_remove_buffers_ip, NULL);
res = gst_caps_to_string (caps);

done:
gst_caps_unref (caps);
return res;
}

static void
gst_stream_information_to_string (GstDiscovererStreamInfo * info, GString * s,
guint depth)
Expand All @@ -70,21 +121,22 @@ gst_stream_information_to_string (GstDiscovererStreamInfo * info, GString * s,
const GstStructure *misc;
#endif

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, depth, " %s\n", tmp);
g_free (tmp);

#ifndef GST_DISABLE_DEPRECATED
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);
if (verbose) {
my_g_string_append_printf (s, depth, "Codec:\n");
caps = gst_discoverer_stream_info_get_caps (info);
tmp = caps_to_string (caps);
my_g_string_append_printf (s, depth, " %s\n", tmp);
g_free (tmp);
} else {
my_g_string_append_printf (s, depth, " None\n");
}
#ifndef GST_DISABLE_DEPRECATED
if (verbose) {
misc = gst_discoverer_stream_info_get_misc (info);
if (misc) {
my_g_string_append_printf (s, depth, "Additional info:\n");
tmp = gst_structure_to_string (misc);
my_g_string_append_printf (s, depth, " %s\n", tmp);
g_free (tmp);
}
}
#endif

Expand Down Expand Up @@ -114,7 +166,7 @@ print_tag_foreach (const GstTagList * tags, const gchar * tag,
if (caps) {
gchar *caps_str;

caps_str = gst_caps_to_string (caps);
caps_str = caps_to_string (gst_caps_ref (caps));
str = g_strdup_printf ("buffer of %" G_GSIZE_FORMAT " bytes, "
"type: %s", gst_buffer_get_size (img), caps_str);
g_free (caps_str);
Expand All @@ -138,15 +190,17 @@ print_tag_foreach (const GstTagList * tags, const gchar * tag,
static void
print_tags_topology (guint depth, const GstTagList * tags)
{
if (!verbose)
return;

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, " ");
g_print ("%*s\n", 2 * depth, " ");
}

static gchar *
Expand Down Expand Up @@ -309,7 +363,7 @@ print_stream_info (GstDiscovererStreamInfo * info, void *depth)
if (gst_caps_is_fixed (caps) && !verbose)
desc = gst_pb_utils_get_codec_description (caps);
else
desc = gst_caps_to_string (caps);
desc = caps_to_string (gst_caps_ref (caps));
gst_caps_unref (caps);
}

Expand All @@ -322,23 +376,21 @@ print_stream_info (GstDiscovererStreamInfo * info, void *depth)
desc = NULL;
}

if (verbose) {
if (GST_IS_DISCOVERER_AUDIO_INFO (info))
desc =
gst_stream_audio_information_to_string (info,
GPOINTER_TO_INT (depth) + 1);
else if (GST_IS_DISCOVERER_VIDEO_INFO (info))
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);
}
if (GST_IS_DISCOVERER_AUDIO_INFO (info))
desc =
gst_stream_audio_information_to_string (info,
GPOINTER_TO_INT (depth) + 1);
else if (GST_IS_DISCOVERER_VIDEO_INFO (info))
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);
}
}

Expand Down Expand Up @@ -411,7 +463,7 @@ print_properties (GstDiscovererInfo * info, gint tab)
(gst_discoverer_info_get_seekable (info) ? "yes" : "no"));
g_print ("%*sLive: %s\n", tab + 1, " ",
(gst_discoverer_info_get_live (info) ? "yes" : "no"));
if ((tags = gst_discoverer_info_get_tags (info))) {
if (verbose && (tags = gst_discoverer_info_get_tags (info))) {
g_print ("%*sTags: \n", tab + 1, " ");
gst_tag_list_foreach (tags, print_tag_foreach, GUINT_TO_POINTER (tab + 2));
}
Expand Down Expand Up @@ -466,27 +518,25 @@ print_info (GstDiscovererInfo * info, GError * err)
}
case GST_DISCOVERER_MISSING_PLUGINS:
{
gint i = 0;
const gchar **installer_details =
gst_discoverer_info_get_missing_elements_installer_details (info);

g_print ("Missing plugins\n");
if (verbose) {
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]);
while (installer_details[i]) {
g_print (" (%s)\n", installer_details[i]);

i++;
}
i++;
}
break;
}
}

if ((sinfo = gst_discoverer_info_get_stream_info (info))) {
g_print ("\nTopology:\n");
print_topology (sinfo, 1);
g_print ("\nProperties:\n");
print_properties (info, 1);
print_topology (sinfo, 1);
gst_discoverer_stream_info_unref (sinfo);
}

Expand Down

0 comments on commit 545a993

Please sign in to comment.