From 7062af472b559d73881cecc5fd383e4887878b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Wed, 2 Jun 2021 11:08:30 +0200 Subject: [PATCH] API: Add function to get subtitle track title --- .../clapper/gstclapper-media-info-private.h | 1 + lib/gst/clapper/gstclapper-media-info.c | 17 +++++++++++++++++ lib/gst/clapper/gstclapper-media-info.h | 5 ++++- lib/gst/clapper/gstclapper.c | 18 +++++++++--------- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/gst/clapper/gstclapper-media-info-private.h b/lib/gst/clapper/gstclapper-media-info-private.h index 87e1f4b6..e89d4514 100644 --- a/lib/gst/clapper/gstclapper-media-info-private.h +++ b/lib/gst/clapper/gstclapper-media-info-private.h @@ -45,6 +45,7 @@ struct _GstClapperSubtitleInfo { GstClapperStreamInfo parent; + gchar *title; gchar *language; }; diff --git a/lib/gst/clapper/gstclapper-media-info.c b/lib/gst/clapper/gstclapper-media-info.c index 20aca105..98374266 100644 --- a/lib/gst/clapper/gstclapper-media-info.c +++ b/lib/gst/clapper/gstclapper-media-info.c @@ -379,6 +379,7 @@ gst_clapper_subtitle_info_finalize (GObject * object) { GstClapperSubtitleInfo *info = GST_CLAPPER_SUBTITLE_INFO (object); + g_free (info->title); g_free (info->language); G_OBJECT_CLASS (gst_clapper_subtitle_info_parent_class)->finalize (object); @@ -392,6 +393,20 @@ gst_clapper_subtitle_info_class_init (GstClapperSubtitleInfoClass * klass) gobject_class->finalize = gst_clapper_subtitle_info_finalize; } +/** + * gst_clapper_subtitle_info_get_title: + * @info: a #GstClapperSubtitleInfo + * + * Returns: the title of the stream, or NULL if unknown. + */ +const gchar * +gst_clapper_subtitle_info_get_title (const GstClapperSubtitleInfo * info) +{ + g_return_val_if_fail (GST_IS_CLAPPER_SUBTITLE_INFO (info), NULL); + + return info->title; +} + /** * gst_clapper_subtitle_info_get_language: * @info: a #GstClapperSubtitleInfo @@ -513,6 +528,8 @@ gst_clapper_subtitle_info_copy (GstClapperSubtitleInfo * ref) GstClapperSubtitleInfo *ret; ret = gst_clapper_subtitle_info_new (); + if (ref->title) + ret->title = g_strdup (ref->title); if (ref->language) ret->language = g_strdup (ref->language); diff --git a/lib/gst/clapper/gstclapper-media-info.h b/lib/gst/clapper/gstclapper-media-info.h index 1e101caf..e0359d35 100644 --- a/lib/gst/clapper/gstclapper-media-info.h +++ b/lib/gst/clapper/gstclapper-media-info.h @@ -170,7 +170,10 @@ GST_CLAPPER_API GType gst_clapper_subtitle_info_get_type (void); GST_CLAPPER_API -const gchar * gst_clapper_subtitle_info_get_language (const GstClapperSubtitleInfo* info); +const gchar * gst_clapper_subtitle_info_get_title (const GstClapperSubtitleInfo *info); + +GST_CLAPPER_API +const gchar * gst_clapper_subtitle_info_get_language (const GstClapperSubtitleInfo *info); #define GST_TYPE_CLAPPER_MEDIA_INFO \ (gst_clapper_media_info_get_type()) diff --git a/lib/gst/clapper/gstclapper.c b/lib/gst/clapper/gstclapper.c index 924eac53..2ec39444 100644 --- a/lib/gst/clapper/gstclapper.c +++ b/lib/gst/clapper/gstclapper.c @@ -2125,11 +2125,14 @@ gst_clapper_subtitle_info_update (GstClapper * self, { GstClapperSubtitleInfo *info = (GstClapperSubtitleInfo *) stream_info; - if (stream_info->tags) { + /* Free the old info */ + g_free (info->title); + info->title = NULL; + g_free (info->language); + info->language = NULL; - /* free the old language info */ - g_free (info->language); - info->language = NULL; + if (stream_info->tags) { + gst_tag_list_get_string (stream_info->tags, GST_TAG_TITLE, &info->title); /* First try to get the language full name from tag, if name is not * available then try language code. If we find the language code @@ -2171,13 +2174,10 @@ gst_clapper_subtitle_info_update (GstClapper * self, g_free (suburi); } } - - } else { - g_free (info->language); - info->language = NULL; } - GST_DEBUG_OBJECT (self, "language=%s", info->language); + GST_DEBUG_OBJECT (self, "Subtitle title: %s", info->title); + GST_DEBUG_OBJECT (self, "Subtitle language: %s", info->language); } static void