discoverer: Serialize the top level DiscovererInfo

Which contains fields such as duration, uri and tags.

https://bugzilla.gnome.org/show_bug.cgi?id=749673
This commit is contained in:
Mathieu Duponchelle 2015-05-20 18:16:07 +02:00
parent b3b2251c59
commit decea41ac7

View file

@ -1666,6 +1666,24 @@ _serialize_common_stream_info (GstDiscovererStreamInfo * sinfo,
return common;
}
static GVariant *
_serialize_info (GstDiscovererInfo * info, GstDiscovererSerializeFlags flags)
{
gchar *tags_str = NULL;
GVariant *ret;
if (info->tags && (flags & GST_DISCOVERER_SERIALIZE_TAGS))
tags_str = gst_tag_list_to_string (info->tags);
ret =
g_variant_new ("(mstbms)", info->uri, info->duration, info->seekable,
tags_str);
g_free (tags_str);
return ret;
}
static GVariant *
_serialize_audio_stream_info (GstDiscovererAudioInfo * ainfo)
{
@ -1770,6 +1788,23 @@ _maybe_get_string_from_tuple (GVariant * tuple, guint index)
return ret;
}
static void
_parse_info (GstDiscovererInfo * info, GVariant * info_variant)
{
const gchar *str;
str = _maybe_get_string_from_tuple (info_variant, 0);
if (str)
info->uri = g_strdup (str);
GET_FROM_TUPLE (info_variant, uint64, 1, &info->duration);
GET_FROM_TUPLE (info_variant, boolean, 2, &info->seekable);
str = _maybe_get_string_from_tuple (info_variant, 3);
if (str)
info->tags = gst_tag_list_new_from_string (str);
}
static void
_parse_common_stream_info (GstDiscovererStreamInfo * sinfo, GVariant * common)
{
@ -2151,11 +2186,15 @@ gst_discoverer_info_to_variant (GstDiscovererInfo * info,
GstDiscovererSerializeFlags flags)
{
/* FIXME: implement TOC support */
GVariant *stream_variant;
GVariant *variant;
GstDiscovererStreamInfo *sinfo = gst_discoverer_info_get_stream_info (info);
GVariant *wrapper;
variant = gst_discoverer_info_to_variant_recurse (sinfo, flags);
stream_variant = gst_discoverer_info_to_variant_recurse (sinfo, flags);
variant =
g_variant_new ("(vv)", _serialize_info (info, flags), stream_variant);
/* Returning a wrapper implies some small overhead, but simplifies
* deserializing from bytes */
wrapper = g_variant_new_variant (variant);
@ -2179,9 +2218,17 @@ GstDiscovererInfo *
gst_discoverer_info_from_variant (GVariant * variant)
{
GstDiscovererInfo *info = g_object_new (GST_TYPE_DISCOVERER_INFO, NULL);
GVariant *wrapped = g_variant_get_variant (variant);
GVariant *info_variant = g_variant_get_variant (variant);
GVariant *info_specific_variant;
GVariant *wrapped;
GET_FROM_TUPLE (info_variant, variant, 0, &info_specific_variant);
GET_FROM_TUPLE (info_variant, variant, 1, &wrapped);
_parse_info (info, info_specific_variant);
_parse_discovery (wrapped, info);
g_variant_unref (info_specific_variant);
g_variant_unref (info_variant);
return info;
}