From 15ee41dfc9dd4d3dc80cc0a6d2f332aa59284ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 20 Nov 2012 14:56:45 +0100 Subject: [PATCH] discoverer: Add support for getting the stream-id https://bugzilla.gnome.org/show_bug.cgi?id=654830 --- docs/libs/gst-plugins-base-libs-sections.txt | 1 + gst-libs/gst/pbutils/gstdiscoverer-types.c | 20 ++++++++++ gst-libs/gst/pbutils/gstdiscoverer.c | 42 +++++++++++++++++++- gst-libs/gst/pbutils/gstdiscoverer.h | 1 + gst-libs/gst/pbutils/pbutils-private.h | 1 + tools/gst-discoverer.c | 9 +++++ win32/common/libgstpbutils.def | 1 + 7 files changed, 74 insertions(+), 1 deletion(-) diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 606645fbcf..442279d811 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -2388,6 +2388,7 @@ gst_discoverer_stream_info_get_next gst_discoverer_stream_info_get_previous gst_discoverer_stream_info_get_tags gst_discoverer_stream_info_get_toc +gst_discoverer_stream_info_get_stream_id gst_discoverer_stream_info_ref gst_discoverer_stream_info_unref gst_discoverer_stream_info_list_free diff --git a/gst-libs/gst/pbutils/gstdiscoverer-types.c b/gst-libs/gst/pbutils/gstdiscoverer-types.c index 14d6f32943..8763efff77 100644 --- a/gst-libs/gst/pbutils/gstdiscoverer-types.c +++ b/gst-libs/gst/pbutils/gstdiscoverer-types.c @@ -70,6 +70,8 @@ gst_discoverer_stream_info_finalize (GObject * object) if (info->toc) gst_toc_unref (info->toc); + g_free (info->stream_id); + if (info->misc) gst_structure_free (info->misc); } @@ -132,6 +134,9 @@ gst_discoverer_info_copy_int (GstDiscovererStreamInfo * info, if (info->toc) ret->toc = gst_toc_ref (info->toc); + if (info->stream_id) + ret->stream_id = g_strdup (info->stream_id); + if (info->misc) ret->misc = gst_structure_copy (info->misc); @@ -663,6 +668,21 @@ gst_discoverer_stream_info_get_toc (GstDiscovererStreamInfo * info) return info->toc; } +/** + * gst_discoverer_stream_info_get_stream_id: + * @info: a #GstDiscovererStreamInfo + * + * Returns: (transfer none): the stream ID of this stream. If you wish to + * use the stream ID after the life-time of @info you will need to copy it. + */ +const gchar * +gst_discoverer_stream_info_get_stream_id (GstDiscovererStreamInfo * info) +{ + g_return_val_if_fail (GST_IS_DISCOVERER_STREAM_INFO (info), NULL); + + return info->stream_id; +} + /** * gst_discoverer_stream_info_get_misc: * @info: a #GstDiscovererStreamInfo diff --git a/gst-libs/gst/pbutils/gstdiscoverer.c b/gst-libs/gst/pbutils/gstdiscoverer.c index d0be61298b..2427e080a4 100644 --- a/gst-libs/gst/pbutils/gstdiscoverer.c +++ b/gst-libs/gst/pbutils/gstdiscoverer.c @@ -54,6 +54,7 @@ GST_DEBUG_CATEGORY_STATIC (discoverer_debug); static GQuark _CAPS_QUARK; static GQuark _TAGS_QUARK; static GQuark _TOC_QUARK; +static GQuark _STREAM_ID_QUARK; static GQuark _MISSING_PLUGIN_QUARK; static GQuark _STREAM_TOPOLOGY_QUARK; static GQuark _TOPOLOGY_PAD_QUARK; @@ -67,6 +68,7 @@ typedef struct GstElement *sink; GstTagList *tags; GstToc *toc; + gchar *stream_id; } PrivateStream; struct _GstDiscovererPrivate @@ -134,7 +136,8 @@ _do_init (void) _CAPS_QUARK = g_quark_from_static_string ("caps"); _TAGS_QUARK = g_quark_from_static_string ("tags"); - _TOC_QUARK = g_quark_from_static_string ("toc"); + _TOC_QUARK = g_quark_from_static_string ("stream-id"); + _STREAM_ID_QUARK = g_quark_from_static_string ("toc"); _MISSING_PLUGIN_QUARK = g_quark_from_static_string ("missing-plugin"); _STREAM_TOPOLOGY_QUARK = g_quark_from_static_string ("stream-topology"); _TOPOLOGY_PAD_QUARK = g_quark_from_static_string ("pad"); @@ -503,6 +506,15 @@ _event_probe (GstPad * pad, GstPadProbeInfo * info, PrivateStream * ps) DISCO_UNLOCK (ps->dc); break; } + case GST_EVENT_STREAM_START:{ + const gchar *stream_id; + + gst_event_parse_stream_start (event, &stream_id); + + g_free (ps->stream_id); + ps->stream_id = stream_id ? g_strdup (stream_id) : NULL; + break; + } default: break; } @@ -691,6 +703,7 @@ uridecodebin_pad_removed_cb (GstElement * uridecodebin, GstPad * pad, if (ps->toc) { gst_toc_unref (ps->toc); } + g_free (ps->stream_id); g_slice_free (PrivateStream, ps); @@ -725,6 +738,9 @@ collect_stream_information (GstDiscoverer * dc, PrivateStream * ps, guint idx) gst_structure_id_set (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, ps->tags, NULL); if (ps->toc) gst_structure_id_set (st, _TOC_QUARK, GST_TYPE_TOC, ps->toc, NULL); + if (ps->stream_id) + gst_structure_id_set (st, _STREAM_ID_QUARK, G_TYPE_STRING, ps->stream_id, + NULL); return st; } @@ -758,6 +774,7 @@ collect_information (GstDiscoverer * dc, const GstStructure * st, GstTagList *tags_st; GstToc *toc_st; const gchar *name; + gchar *stream_id; int tmp; guint utmp; @@ -822,6 +839,12 @@ collect_information (GstDiscoverer * dc, const GstStructure * st, info->parent.toc = toc_st; } + if (gst_structure_id_has_field (st, _STREAM_ID_QUARK)) { + gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id, + NULL); + info->parent.stream_id = stream_id; + } + if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) { gchar *language; if (gst_tag_list_get_string (((GstDiscovererStreamInfo *) info)->tags, @@ -881,6 +904,12 @@ collect_information (GstDiscoverer * dc, const GstStructure * st, info->parent.toc = toc_st; } + if (gst_structure_id_has_field (st, _STREAM_ID_QUARK)) { + gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id, + NULL); + info->parent.stream_id = stream_id; + } + gst_caps_unref (caps); return (GstDiscovererStreamInfo *) info; @@ -914,6 +943,12 @@ collect_information (GstDiscoverer * dc, const GstStructure * st, info->parent.toc = toc_st; } + if (gst_structure_id_has_field (st, _STREAM_ID_QUARK)) { + gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id, + NULL); + info->parent.stream_id = stream_id; + } + if (!info->language && ((GstDiscovererStreamInfo *) info)->tags) { gchar *language; if (gst_tag_list_get_string (((GstDiscovererStreamInfo *) info)->tags, @@ -946,6 +981,11 @@ collect_information (GstDiscoverer * dc, const GstStructure * st, info->toc = toc_st; } + if (gst_structure_id_get (st, _STREAM_ID_QUARK, G_TYPE_STRING, &stream_id, + NULL)) { + info->stream_id = stream_id; + } + gst_caps_unref (caps); return info; } diff --git a/gst-libs/gst/pbutils/gstdiscoverer.h b/gst-libs/gst/pbutils/gstdiscoverer.h index 866994877b..1df0f505d1 100644 --- a/gst-libs/gst/pbutils/gstdiscoverer.h +++ b/gst-libs/gst/pbutils/gstdiscoverer.h @@ -62,6 +62,7 @@ GstDiscovererStreamInfo* gst_discoverer_stream_info_get_next(GstDiscovererStream GstCaps* gst_discoverer_stream_info_get_caps(GstDiscovererStreamInfo* info); const GstTagList* gst_discoverer_stream_info_get_tags(GstDiscovererStreamInfo* info); const GstToc* gst_discoverer_stream_info_get_toc(GstDiscovererStreamInfo* info); +const gchar* gst_discoverer_stream_info_get_stream_id(GstDiscovererStreamInfo* info); const GstStructure* gst_discoverer_stream_info_get_misc(GstDiscovererStreamInfo* info); const gchar * gst_discoverer_stream_info_get_stream_type_nick(GstDiscovererStreamInfo* info); diff --git a/gst-libs/gst/pbutils/pbutils-private.h b/gst-libs/gst/pbutils/pbutils-private.h index 5223a369a0..82fd22c890 100644 --- a/gst-libs/gst/pbutils/pbutils-private.h +++ b/gst-libs/gst/pbutils/pbutils-private.h @@ -27,6 +27,7 @@ struct _GstDiscovererStreamInfo { GstCaps *caps; GstTagList *tags; GstToc *toc; + gchar *stream_id; GstStructure *misc; gpointer _gst_reserved[GST_PADDING]; diff --git a/tools/gst-discoverer.c b/tools/gst-discoverer.c index 9ea7b03090..2c02b07846 100644 --- a/tools/gst-discoverer.c +++ b/tools/gst-discoverer.c @@ -83,6 +83,9 @@ gst_stream_audio_information_to_string (GstDiscovererStreamInfo * info, 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)); + audio_info = (GstDiscovererAudioInfo *) info; ctmp = gst_discoverer_audio_info_get_language (audio_info); my_g_string_append_printf (s, depth, "Language: %s\n", @@ -147,6 +150,9 @@ gst_stream_video_information_to_string (GstDiscovererStreamInfo * info, 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)); + video_info = (GstDiscovererVideoInfo *) info; my_g_string_append_printf (s, depth, "Width: %u\n", gst_discoverer_video_info_get_width (video_info)); @@ -218,6 +224,9 @@ gst_stream_subtitle_information_to_string (GstDiscovererStreamInfo * info, 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)); + subtitle_info = (GstDiscovererSubtitleInfo *) info; ctmp = gst_discoverer_subtitle_info_get_language (subtitle_info); my_g_string_append_printf (s, depth, "Language: %s\n", diff --git a/win32/common/libgstpbutils.def b/win32/common/libgstpbutils.def index 0d81051729..55f10eba1e 100644 --- a/win32/common/libgstpbutils.def +++ b/win32/common/libgstpbutils.def @@ -46,6 +46,7 @@ EXPORTS gst_discoverer_stream_info_get_misc gst_discoverer_stream_info_get_next gst_discoverer_stream_info_get_previous + gst_discoverer_stream_info_get_stream_id gst_discoverer_stream_info_get_stream_type_nick gst_discoverer_stream_info_get_tags gst_discoverer_stream_info_get_toc