gstvalue: Do more checks when guessing at flagset strings
[platform/upstream/gstreamer.git] / gst / gsturi.c
index 8623d44..3312e33 100644 (file)
@@ -25,6 +25,7 @@
 
 /**
  * SECTION:gsturihandler
+ * @title: GstUriHandler
  * @short_description: Interface to ease URI handling in plugins.
  *
  * The #GstURIHandler is an interface that is implemented by Source and Sink
@@ -960,6 +961,7 @@ beach:
 
 /**
  * SECTION:gsturi
+ * @title: GstUri
  * @short_description: URI parsing and manipulation.
  *
  * A #GstUri object can be used to parse and split a URI string into its
@@ -994,6 +996,9 @@ static GstUri *
 _gst_uri_new (void)
 {
   GstUri *uri;
+
+  g_return_val_if_fail (gst_is_initialized (), NULL);
+
   uri = GST_URI_CAST (g_slice_new0 (GstUri));
 
   if (uri)
@@ -1553,7 +1558,7 @@ gst_uri_from_string (const gchar * uri)
         if (eoh == NULL || eoh > eoa) {
           GST_DEBUG ("Unable to parse the host part of the URI '%s'.",
               orig_uri);
-          _gst_uri_free (uri_obj);
+          gst_uri_unref (uri_obj);
           return NULL;
         }
         reoh = eoh + 1;
@@ -1573,7 +1578,7 @@ gst_uri_from_string (const gchar * uri)
         if (uri[0] != ':' || strspn (uri + 1, "0123456789") != eoa - uri - 1) {
           GST_DEBUG ("Unable to parse host/port part of the URI '%s'.",
               orig_uri);
-          _gst_uri_free (uri_obj);
+          gst_uri_unref (uri_obj);
           return NULL;
         }
         /* otherwise treat port as unsigned decimal number */
@@ -2800,3 +2805,34 @@ gst_uri_set_fragment (GstUri * uri, const gchar * fragment)
   uri->fragment = g_strdup (fragment);
   return TRUE;
 }
+
+/**
+ * gst_uri_get_media_fragment_table:
+ * @uri: (nullable): The #GstUri to get the fragment table from.
+ *
+ * Get the media fragment table from the URI, as defined by "Media Fragments URI 1.0".
+ * Hash table returned by this API is a list of "key-value" pairs, and the each
+ * pair is generated by splitting "URI fragment" per "&" sub-delims, then "key"
+ * and "value" are splitted by "=" sub-delims. The "key" returned by this API may
+ * be undefined keyword by standard.
+ * A value may be %NULL to indicate that the key should appear in the fragment
+ * string in the URI, but does not have a value. Free the returned #GHashTable
+ * with #g_hash_table_unref() when it is no longer required.
+ * Modifying this hash table does not affect the fragment in the URI.
+ *
+ * See more about Media Fragments URI 1.0 (W3C) at https://www.w3.org/TR/media-frags/
+ *
+ * Returns: (transfer full)(element-type gchar* gchar*): The fragment hash table
+ *          from the URI.
+ *
+ * Since: 1.12
+ */
+GHashTable *
+gst_uri_get_media_fragment_table (const GstUri * uri)
+{
+  g_return_val_if_fail (uri == NULL || GST_IS_URI (uri), NULL);
+
+  if (!uri->fragment)
+    return NULL;
+  return _gst_uri_string_to_table (uri->fragment, "&", "=", TRUE, TRUE);
+}