API: Add function to get subtitle track title

This commit is contained in:
Rafał Dzięgiel
2021-06-02 11:08:30 +02:00
parent 1f4698448a
commit 7062af472b
4 changed files with 31 additions and 10 deletions

View File

@@ -45,6 +45,7 @@ struct _GstClapperSubtitleInfo
{ {
GstClapperStreamInfo parent; GstClapperStreamInfo parent;
gchar *title;
gchar *language; gchar *language;
}; };

View File

@@ -379,6 +379,7 @@ gst_clapper_subtitle_info_finalize (GObject * object)
{ {
GstClapperSubtitleInfo *info = GST_CLAPPER_SUBTITLE_INFO (object); GstClapperSubtitleInfo *info = GST_CLAPPER_SUBTITLE_INFO (object);
g_free (info->title);
g_free (info->language); g_free (info->language);
G_OBJECT_CLASS (gst_clapper_subtitle_info_parent_class)->finalize (object); 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; 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: * gst_clapper_subtitle_info_get_language:
* @info: a #GstClapperSubtitleInfo * @info: a #GstClapperSubtitleInfo
@@ -513,6 +528,8 @@ gst_clapper_subtitle_info_copy (GstClapperSubtitleInfo * ref)
GstClapperSubtitleInfo *ret; GstClapperSubtitleInfo *ret;
ret = gst_clapper_subtitle_info_new (); ret = gst_clapper_subtitle_info_new ();
if (ref->title)
ret->title = g_strdup (ref->title);
if (ref->language) if (ref->language)
ret->language = g_strdup (ref->language); ret->language = g_strdup (ref->language);

View File

@@ -170,7 +170,10 @@ GST_CLAPPER_API
GType gst_clapper_subtitle_info_get_type (void); GType gst_clapper_subtitle_info_get_type (void);
GST_CLAPPER_API 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 \ #define GST_TYPE_CLAPPER_MEDIA_INFO \
(gst_clapper_media_info_get_type()) (gst_clapper_media_info_get_type())

View File

@@ -2125,11 +2125,14 @@ gst_clapper_subtitle_info_update (GstClapper * self,
{ {
GstClapperSubtitleInfo *info = (GstClapperSubtitleInfo *) stream_info; 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 */ if (stream_info->tags) {
g_free (info->language); gst_tag_list_get_string (stream_info->tags, GST_TAG_TITLE, &info->title);
info->language = NULL;
/* First try to get the language full name from tag, if name is not /* 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 * 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); 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 static void