From 95c1f67d6925322609017e650e29e2442ec38335 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 9 Feb 2021 19:56:49 -0300 Subject: [PATCH] discoverer: Set number to stream infos 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: --- .../gst/pbutils/gstdiscoverer-types.c | 21 ++++++++++++++++++- .../gst-libs/gst/pbutils/gstdiscoverer.c | 10 +++++++-- .../gst-libs/gst/pbutils/gstdiscoverer.h | 3 +++ .../gst-libs/gst/pbutils/pbutils-private.h | 3 +++ .../gst-plugins-base/tools/gst-discoverer.c | 4 ++-- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer-types.c b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer-types.c index dd77cf3c90f..418d69f85ad 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer-types.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer-types.c @@ -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 */ /** diff --git a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.c b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.c index 42cfd6408a3..5075fe3f6dd 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.c @@ -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; diff --git a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.h b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.h index f30f0ce2a46..61a6575391a 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.h @@ -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: * diff --git a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/pbutils-private.h b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/pbutils-private.h index 835d670eece..4a10167b952 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/pbutils/pbutils-private.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/pbutils/pbutils-private.h @@ -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; }; diff --git a/subprojects/gst-plugins-base/tools/gst-discoverer.c b/subprojects/gst-plugins-base/tools/gst-discoverer.c index 6cfea210e4c..454ff89f0e9 100644 --- a/subprojects/gst-plugins-base/tools/gst-discoverer.c +++ b/subprojects/gst-plugins-base/tools/gst-discoverer.c @@ -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); -- GitLab