[totem/wip/hadess/lang-menus: 4/6] backend: Return more info about subtitles/audio tracks
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/wip/hadess/lang-menus: 4/6] backend: Return more info about subtitles/audio tracks
- Date: Sat, 16 Feb 2019 17:59:45 +0000 (UTC)
commit 89ca25bd92202bde758722799904c1ac419de25b
Author: Bastien Nocera <hadess hadess net>
Date: Thu Feb 14 00:20:33 2019 +0100
backend: Return more info about subtitles/audio tracks
Instead of simply returning a list of language codes for subtitles and
audio tracks, return a struct contains both the language code and the
audio codec. We will be able to use this to differentiate tracks better
in the menus.
There are no functional or UI changes in this commit, just an API
extension.
src/backend/bacon-video-widget.c | 49 +++++++++++++++++++++-------------------
src/backend/bacon-video-widget.h | 17 ++++++++++++++
src/totem-menu.c | 30 +++++++++++++-----------
3 files changed, 60 insertions(+), 36 deletions(-)
---
diff --git a/src/backend/bacon-video-widget.c b/src/backend/bacon-video-widget.c
index 3c9666249..166482495 100644
--- a/src/backend/bacon-video-widget.c
+++ b/src/backend/bacon-video-widget.c
@@ -3389,40 +3389,45 @@ get_lang_list_for_type (BaconVideoWidget * bvw, const gchar * type_name)
for (i = 0; i < n; i++) {
GstTagList *tags = NULL;
+ BvwLangInfo *info;
g_signal_emit_by_name (G_OBJECT (bvw->priv->play), signal, i, &tags);
- if (tags) {
- gchar *lc = NULL, *cd = NULL;
+ info = g_new0 (BvwLangInfo, 1);
- gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_CODE, &lc);
- gst_tag_list_get_string (tags, GST_TAG_CODEC, &cd);
+ if (tags) {
+ gst_tag_list_get_string (tags, GST_TAG_LANGUAGE_CODE, &info->language);
+ if (g_str_equal (type_name, "AUDIO"))
+ gst_tag_list_get_string (tags, GST_TAG_AUDIO_CODEC, &info->codec);
- if (lc) {
- ret = g_list_prepend (ret, lc);
- g_free (cd);
- } else if (cd) {
- ret = g_list_prepend (ret, cd);
- } else {
- ret = g_list_prepend (ret, get_label_for_type (type_name, num++));
- }
gst_tag_list_unref (tags);
- } else {
- ret = g_list_prepend (ret, get_label_for_type (type_name, num++));
}
+
+ if (info->language == NULL)
+ info->language = g_strdup ("und");
+ ret = g_list_prepend (ret, info);
}
return g_list_reverse (ret);
}
+void
+bacon_video_widget_lang_info_free (BvwLangInfo *info)
+{
+ if (info == NULL)
+ return;
+ g_free (info->language);
+ g_free (info->codec);
+ g_free (info);
+}
+
/**
* bacon_video_widget_get_subtitles:
* @bvw: a #BaconVideoWidget
*
- * Returns a list of subtitle tags, each in the form <literal>TEXT <replaceable>x</replaceable></literal>,
- * where <replaceable>x</replaceable> is the subtitle index.
+ * Returns a list of #BvwLangInfo for each subtitle track.
*
- * Return value: a #GList of subtitle tags, or %NULL; free each element with g_free() and the list with
g_list_free()
+ * Return value: a #GList of #BvwLangInfo, or %NULL; free each element with
bacon_video_widget_lang_info_free() and the list with g_list_free()
**/
GList *
bacon_video_widget_get_subtitles (BaconVideoWidget * bvw)
@@ -3441,10 +3446,9 @@ bacon_video_widget_get_subtitles (BaconVideoWidget * bvw)
* bacon_video_widget_get_languages:
* @bvw: a #BaconVideoWidget
*
- * Returns a list of audio language tags, each in the form <literal>AUDIO
<replaceable>x</replaceable></literal>,
- * where <replaceable>x</replaceable> is the language index.
+ * Returns a list of #BvwLangInfo for each audio track.
*
- * Return value: a #GList of audio language tags, or %NULL; free each element with g_free() and the list
with g_list_free()
+ * Return value: a #GList of #BvwLanginfo, or %NULL; free each element with
bacon_video_widget_lang_info_free() and the list with g_list_free()
**/
GList *
bacon_video_widget_get_languages (BaconVideoWidget * bvw)
@@ -3459,9 +3463,8 @@ bacon_video_widget_get_languages (BaconVideoWidget * bvw)
/* When we have only one language, we don't need to show
* any languages, we default to the only track */
if (g_list_length (list) == 1) {
- g_free (list->data);
- g_list_free (list);
- list = NULL;
+ g_list_free_full (list, bacon_video_widget_lang_info_free);
+ return NULL;
}
return list;
diff --git a/src/backend/bacon-video-widget.h b/src/backend/bacon-video-widget.h
index 0d2f271b4..2d3f91252 100644
--- a/src/backend/bacon-video-widget.h
+++ b/src/backend/bacon-video-widget.h
@@ -381,6 +381,23 @@ typedef enum {
void bacon_video_widget_dvd_event (BaconVideoWidget *bvw,
BvwDVDEvent type);
+
+/**
+ * BvwLangInfo:
+ * @language: the ISO-639 language code for the track, or "und" if unknown.
+ * @codec: the codec for the track
+ *
+ * #BvwLangInfo holds the language code and codec for each subtitle
+ * or audio track for a media, which would allow the front-ends to
+ * present appropriate information to the user.
+ */
+typedef struct {
+ const char *language;
+ const char *codec;
+} BvwLangInfo;
+
+void bacon_video_widget_lang_info_free (BvwLangInfo *info);
+
GList *bacon_video_widget_get_languages (BaconVideoWidget *bvw);
int bacon_video_widget_get_language (BaconVideoWidget *bvw);
void bacon_video_widget_set_language (BaconVideoWidget *bvw,
diff --git a/src/totem-menu.c b/src/totem-menu.c
index 57fc8e547..a609e87c8 100644
--- a/src/totem-menu.c
+++ b/src/totem-menu.c
@@ -438,22 +438,23 @@ create_lang_actions (GMenu *menu,
add_lang_action (menu, action, C_("Language", "Auto"), -1, 0);
i = 0;
- lookup = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
+ lookup = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
for (l = list; l != NULL; l = l->next) {
guint num;
unsigned int *hash_value;
+ BvwLangInfo *info = l->data;
- hash_value = g_hash_table_lookup (lookup, l->data);
+ hash_value = g_hash_table_lookup (lookup, info->language);
if (hash_value == NULL)
num = 0;
else
num = GPOINTER_TO_INT (hash_value);
num++;
- g_hash_table_insert (lookup, l->data, GINT_TO_POINTER (num));
+ g_hash_table_insert (lookup, g_strdup (info->language), GINT_TO_POINTER (num));
- add_lang_action (menu, action, l->data, i, num);
+ add_lang_action (menu, action, info->language, i, num);
i++;
}
@@ -478,9 +479,12 @@ totem_sublang_equal_lists (GList *orig, GList *new)
retval = TRUE;
o = orig;
n = new;
- while (o != NULL && n != NULL && retval != FALSE)
- {
- if (g_str_equal (o->data, n->data) == FALSE)
+ while (o != NULL && n != NULL && retval != FALSE) {
+ BvwLangInfo *info_o, *info_n;
+
+ info_o = o->data;
+ info_n = n->data;
+ if (g_strcmp0 (info_o->language, info_n->language) != 0)
retval = FALSE;
o = g_list_next (o);
n = g_list_next (n);
@@ -510,7 +514,7 @@ totem_languages_update (Totem *totem, GList *list)
g_action_change_state (action, g_variant_new_int32 (current));
totem->updating_menu = FALSE;
- g_list_free_full (totem->languages_list, g_free);
+ g_list_free_full (totem->languages_list, (GDestroyNotify) bacon_video_widget_lang_info_free);
totem->languages_list = list;
}
@@ -535,7 +539,7 @@ totem_subtitles_update (Totem *totem, GList *list)
g_action_change_state (action, g_variant_new_int32 (current));
totem->updating_menu = FALSE;
- g_list_free_full (totem->subtitles_list, g_free);
+ g_list_free_full (totem->subtitles_list, (GDestroyNotify) bacon_video_widget_lang_info_free);
totem->subtitles_list = list;
}
@@ -546,14 +550,14 @@ totem_sublang_update (Totem *totem)
list = bacon_video_widget_get_languages (totem->bvw);
if (totem_sublang_equal_lists (totem->languages_list, list) == TRUE) {
- g_list_free_full (list, g_free);
+ g_list_free_full (list, (GDestroyNotify) bacon_video_widget_lang_info_free);
} else {
totem_languages_update (totem, list);
}
list = bacon_video_widget_get_subtitles (totem->bvw);
if (totem_sublang_equal_lists (totem->subtitles_list, list) == TRUE) {
- g_list_free_full (list, g_free);
+ g_list_free_full (list, (GDestroyNotify) bacon_video_widget_lang_info_free);
} else {
totem_subtitles_update (totem, list);
}
@@ -562,6 +566,6 @@ totem_sublang_update (Totem *totem)
void
totem_sublang_exit (Totem *totem)
{
- g_list_free_full (totem->subtitles_list, g_free);
- g_list_free_full (totem->languages_list, g_free);
+ g_list_free_full (totem->subtitles_list, (GDestroyNotify) bacon_video_widget_lang_info_free);
+ g_list_free_full (totem->languages_list, (GDestroyNotify) bacon_video_widget_lang_info_free);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]