discoverer: Set number to stream infos
authorThibault Saunier <tsaunier@igalia.com>
Tue, 9 Feb 2021 22:56:49 +0000 (19:56 -0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 20 Oct 2021 09:16:38 +0000 (09:16 +0000)
The idea is that we can reference to streams using this unique number,
within the context of that discoverer info. That number should always
be usable to reference the streams for a specific stream.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/897>

subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer-types.c
subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.c
subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.h
subprojects/gst-plugins-base/gst-libs/gst/pbutils/pbutils-private.h
subprojects/gst-plugins-base/tools/gst-discoverer.c

index dd77cf3..418d69f 100644 (file)
@@ -50,7 +50,7 @@ G_DEFINE_TYPE (GstDiscovererStreamInfo, gst_discoverer_stream_info,
 static void
 gst_discoverer_stream_info_init (GstDiscovererStreamInfo * info)
 {
-  /* Nothing needs initialization */
+  info->stream_number = -1;
 }
 
 static void
@@ -143,6 +143,8 @@ gst_discoverer_info_copy_int (GstDiscovererStreamInfo * info,
   if (stream_map)
     g_hash_table_insert (stream_map, info, ret);
 
+  ret->stream_number = info->stream_number;
+
   return ret;
 }
 
@@ -718,6 +720,23 @@ gst_discoverer_stream_info_get_misc (GstDiscovererStreamInfo * info)
 }
 #endif
 
+/**
+ * gst_discoverer_stream_info_get_stream_number:
+ * @info: a #GstDiscovererStreamInfo
+ *
+ * Returns: the stream number, -1 if no index could be determined. This property
+ * acts as a unique identifier as a 'int' for the stream.
+ *
+ * Since: 1.20
+ */
+gint
+gst_discoverer_stream_info_get_stream_number (GstDiscovererStreamInfo * info)
+{
+  g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), -1);
+
+  return info->stream_number;
+}
+
 /* GstDiscovererContainerInfo */
 
 /**
index 42cfd64..5075fe3 100644 (file)
@@ -1284,6 +1284,7 @@ parse_stream_topology (GstDiscoverer * dc, const GstStructure * topology,
     }
 
     if (add_to_list) {
+      res->stream_number = dc->priv->current_info->stream_count++;
       dc->priv->current_info->stream_list =
           g_list_append (dc->priv->current_info->stream_list, res);
     } else {
@@ -1476,9 +1477,13 @@ discoverer_collect (GstDiscoverer * dc)
     else
       dc->priv->current_info->live = TRUE;
 
-    if (dc->priv->current_topology)
+    if (dc->priv->current_topology) {
+      dc->priv->current_info->stream_count = 1;
       dc->priv->current_info->stream_info = parse_stream_topology (dc,
           dc->priv->current_topology, NULL);
+      if (dc->priv->current_info->stream_info)
+        dc->priv->current_info->stream_info->stream_number = 0;
+    }
 
     /*
      * Images need some special handling. They do not have a duration, have
@@ -2385,8 +2390,9 @@ _parse_discovery (GVariant * variant, GstDiscovererInfo * info)
   _parse_common_stream_info (sinfo, g_variant_get_child_value (common, 0),
       info);
 
-  if (!GST_IS_DISCOVERER_CONTAINER_INFO (sinfo))
+  if (!GST_IS_DISCOVERER_CONTAINER_INFO (sinfo)) {
     info->stream_list = g_list_append (info->stream_list, sinfo);
+  }
 
   if (!info->stream_info) {
     info->stream_info = sinfo;
index f30f0ce..61a6575 100644 (file)
@@ -84,6 +84,9 @@ const GstStructure*      gst_discoverer_stream_info_get_misc(GstDiscovererStream
 GST_PBUTILS_API
 const gchar *            gst_discoverer_stream_info_get_stream_type_nick(GstDiscovererStreamInfo* info);
 
+GST_PBUTILS_API
+gint                     gst_discoverer_stream_info_get_stream_number(GstDiscovererStreamInfo *info);
+
 /**
  * GstDiscovererContainerInfo:
  *
index 835d670..4a10167 100644 (file)
@@ -31,6 +31,7 @@ struct _GstDiscovererStreamInfo {
   GstToc                *toc;
   gchar                 *stream_id;
   GstStructure          *misc;
+  gint                  stream_number;
 };
 
 struct _GstDiscovererContainerInfo {
@@ -97,6 +98,8 @@ struct _GstDiscovererInfo {
   gboolean seekable;
   GPtrArray *missing_elements_details;
 
+  gint stream_count;
+
   gchar *cachefile;
   gpointer from_cache;
 };
index 6cfea21..454ff89 100644 (file)
@@ -367,9 +367,9 @@ print_stream_info (GstDiscovererStreamInfo * info, void *depth)
     gst_caps_unref (caps);
   }
 
-  g_print ("%*s%s: %s\n", 2 * GPOINTER_TO_INT (depth), " ",
+  g_print ("%*s%s #%d: %s\n", 2 * GPOINTER_TO_INT (depth), " ",
       gst_discoverer_stream_info_get_stream_type_nick (info),
-      GST_STR_NULL (desc));
+      gst_discoverer_stream_info_get_stream_number (info), GST_STR_NULL (desc));
 
   if (desc) {
     g_free (desc);