Revert "gst/parse: define pure-parser depending on bison version"
[platform/upstream/gstreamer.git] / gst / gstquery.c
index 52c1118..1a82747 100644 (file)
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /**
  * SECTION:gstquery
- * @short_description: Dynamically register new query types. Provide functions
- *                     to create queries, and to set and parse values in them.
+ * @title: GstQuery
+ * @short_description: Provide functions to create queries, and to set and parse
+ *                     values in them.
  * @see_also: #GstPad, #GstElement
  *
- * GstQuery functions are used to register new query types to the gstreamer
- * core and use them.
  * Queries can be performed on pads (gst_pad_query()) and elements
  * (gst_element_query()). Please note that some queries might need a running
  * pipeline to work.
  * gst_query_parse_*() helpers.
  *
  * The following example shows how to query the duration of a pipeline:
- *
- * <example>
- *  <title>Query duration on a pipeline</title>
- *  <programlisting>
- *  GstQuery *query;
- *  gboolean res;
- *  query = gst_query_new_duration (GST_FORMAT_TIME);
- *  res = gst_element_query (pipeline, query);
- *  if (res) {
- *    gint64 duration;
- *    gst_query_parse_duration (query, NULL, &amp;duration);
- *    g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
- *  }
- *  else {
- *    g_print ("duration query failed...");
- *  }
- *  gst_query_unref (query);
- *  </programlisting>
- * </example>
- *
- * Last reviewed on 2006-02-14 (0.10.4)
- */
-
-
-/* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
- * with newer GLib versions (>= 2.31.0) */
-#define GLIB_DISABLE_DEPRECATION_WARNINGS
+ * |[<!-- language="C" -->
+ *   GstQuery *query;
+ *   gboolean res;
+ *   query = gst_query_new_duration (GST_FORMAT_TIME);
+ *   res = gst_element_query (pipeline, query);
+ *   if (res) {
+ *     gint64 duration;
+ *     gst_query_parse_duration (query, NULL, &amp;duration);
+ *     g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
+ *   } else {
+ *     g_print ("duration query failed...");
+ *   }
+ *   gst_query_unref (query);
+ * ]|
+ */
+
 
 #include "gst_private.h"
 #include "gstinfo.h"
@@ -78,7 +66,7 @@
 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
 #define GST_CAT_DEFAULT gst_query_debug
 
-static GType _gst_query_type = 0;
+GType _gst_query_type = 0;
 
 typedef struct
 {
@@ -89,37 +77,37 @@ typedef struct
 
 #define GST_QUERY_STRUCTURE(q)  (((GstQueryImpl *)(q))->structure)
 
-/* GstQueryBufferingRange: internal struct for GArray */
+
 typedef struct
 {
-  gint64 start;
-  gint64 stop;
-} GstQueryBufferingRange;
-
-static GMutex mutex;
-static GList *_gst_queries = NULL;
-static GHashTable *_nick_to_query = NULL;
-static GHashTable *_query_type_to_nick = NULL;
-static guint32 _n_values = 1;   /* we start from 1 because 0 reserved for NONE */
-
-static GstQueryTypeDefinition standard_definitions[] = {
-  {GST_QUERY_POSITION, "position", "Current position", 0},
-  {GST_QUERY_DURATION, "duration", "Total duration", 0},
-  {GST_QUERY_LATENCY, "latency", "Latency", 0},
-  {GST_QUERY_JITTER, "jitter", "Jitter", 0},
-  {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
-  {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
-  {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
-  {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
-  {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
-  {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
-  {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
-  {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
-  {GST_QUERY_ALLOCATION, "allocation", "Allocation properties", 0},
-  {GST_QUERY_SCHEDULING, "scheduling", "Scheduling properties", 0},
-  {GST_QUERY_ACCEPT_CAPS, "accept-caps", "Accept caps", 0},
-  {GST_QUERY_CAPS, "caps", "Caps", 0},
-  {GST_QUERY_NONE, NULL, NULL, 0}
+  const gint type;
+  const gchar *name;
+  GQuark quark;
+} GstQueryQuarks;
+
+static GstQueryQuarks query_quarks[] = {
+  {GST_QUERY_UNKNOWN, "unknown", 0},
+  {GST_QUERY_POSITION, "position", 0},
+  {GST_QUERY_DURATION, "duration", 0},
+  {GST_QUERY_LATENCY, "latency", 0},
+  {GST_QUERY_JITTER, "jitter", 0},
+  {GST_QUERY_RATE, "rate", 0},
+  {GST_QUERY_SEEKING, "seeking", 0},
+  {GST_QUERY_SEGMENT, "segment", 0},
+  {GST_QUERY_CONVERT, "convert", 0},
+  {GST_QUERY_FORMATS, "formats", 0},
+  {GST_QUERY_BUFFERING, "buffering", 0},
+  {GST_QUERY_CUSTOM, "custom", 0},
+  {GST_QUERY_URI, "uri", 0},
+  {GST_QUERY_ALLOCATION, "allocation", 0},
+  {GST_QUERY_SCHEDULING, "scheduling", 0},
+  {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
+  {GST_QUERY_CAPS, "caps", 0},
+  {GST_QUERY_DRAIN, "drain", 0},
+  {GST_QUERY_CONTEXT, "context", 0},
+  {GST_QUERY_BITRATE, "bitrate", 0},
+
+  {0, NULL, 0}
 };
 
 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
@@ -127,205 +115,73 @@ GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
 void
 _priv_gst_query_initialize (void)
 {
-  GstQueryTypeDefinition *standards = standard_definitions;
+  gint i;
 
-  GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
+  _gst_query_type = gst_query_get_type ();
 
   GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
 
-  g_mutex_lock (&mutex);
-  if (_nick_to_query == NULL) {
-    _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
-    _query_type_to_nick = g_hash_table_new (NULL, NULL);
+  for (i = 0; query_quarks[i].name; i++) {
+    query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
   }
-
-  while (standards->nick) {
-    standards->quark = g_quark_from_static_string (standards->nick);
-    g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
-    g_hash_table_insert (_query_type_to_nick,
-        GINT_TO_POINTER (standards->value), standards);
-
-    _gst_queries = g_list_append (_gst_queries, standards);
-    standards++;
-    _n_values++;
-  }
-  g_mutex_unlock (&mutex);
-
-  _gst_query_type = gst_query_get_type ();
 }
 
 /**
  * gst_query_type_get_name:
- * @query: the query type
+ * @type: the query type
  *
  * Get a printable name for the given query type. Do not modify or free.
  *
  * Returns: a reference to the static name of the query.
  */
 const gchar *
-gst_query_type_get_name (GstQueryType query)
+gst_query_type_get_name (GstQueryType type)
 {
-  const GstQueryTypeDefinition *def;
-
-  def = gst_query_type_get_details (query);
-  g_return_val_if_fail (def != NULL, NULL);
+  gint i;
 
-  return def->nick;
+  for (i = 0; query_quarks[i].name; i++) {
+    if (type == query_quarks[i].type)
+      return query_quarks[i].name;
+  }
+  return "unknown";
 }
 
 /**
  * gst_query_type_to_quark:
- * @query: the query type
+ * @type: the query type
  *
  * Get the unique quark for the given query type.
  *
  * Returns: the quark associated with the query type
  */
 GQuark
-gst_query_type_to_quark (GstQueryType query)
-{
-  const GstQueryTypeDefinition *def;
-
-  def = gst_query_type_get_details (query);
-  g_return_val_if_fail (def != NULL, 0);
-
-  return def->quark;
-}
-
-/**
- * gst_query_type_register:
- * @nick: The nick of the new query
- * @description: The description of the new query
- *
- * Create a new GstQueryType based on the nick or return an
- * already registered query with that nick
- *
- * Returns: A new GstQueryType or an already registered query
- * with the same nick.
- */
-GstQueryType
-gst_query_type_register (const gchar * nick, const gchar * description)
+gst_query_type_to_quark (GstQueryType type)
 {
-  GstQueryTypeDefinition *query;
-  GstQueryType lookup;
-
-  g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
-  g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
-
-  lookup = gst_query_type_get_by_nick (nick);
-  if (lookup != GST_QUERY_NONE)
-    return lookup;
-
-  query = g_slice_new (GstQueryTypeDefinition);
-  query->value = (GstQueryType) _n_values;
-  query->nick = g_strdup (nick);
-  query->description = g_strdup (description);
-  query->quark = g_quark_from_static_string (query->nick);
-
-  g_mutex_lock (&mutex);
-  g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
-  g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
-      query);
-  _gst_queries = g_list_append (_gst_queries, query);
-  _n_values++;
-  g_mutex_unlock (&mutex);
-
-  return query->value;
-}
-
-/**
- * gst_query_type_get_by_nick:
- * @nick: The nick of the query
- *
- * Get the query type registered with @nick.
- *
- * Returns: The query registered with @nick or #GST_QUERY_NONE
- * if the query was not registered.
- */
-GstQueryType
-gst_query_type_get_by_nick (const gchar * nick)
-{
-  GstQueryTypeDefinition *query;
-
-  g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
-
-  g_mutex_lock (&mutex);
-  query = g_hash_table_lookup (_nick_to_query, nick);
-  g_mutex_unlock (&mutex);
-
-  if (query != NULL)
-    return query->value;
-  else
-    return GST_QUERY_NONE;
-}
-
-/**
- * gst_query_types_contains:
- * @types: The query array to search
- * @type: the #GstQueryType to find
- *
- * See if the given #GstQueryType is inside the @types query types array.
- *
- * Returns: TRUE if the type is found inside the array
- */
-gboolean
-gst_query_types_contains (const GstQueryType * types, GstQueryType type)
-{
-  if (!types)
-    return FALSE;
-
-  while (*types) {
-    if (*types == type)
-      return TRUE;
+  gint i;
 
-    types++;
+  for (i = 0; query_quarks[i].name; i++) {
+    if (type == query_quarks[i].type)
+      return query_quarks[i].quark;
   }
-  return FALSE;
+  return 0;
 }
 
-
 /**
- * gst_query_type_get_details:
+ * gst_query_type_get_flags:
  * @type: a #GstQueryType
  *
- * Get details about the given #GstQueryType.
+ * Gets the #GstQueryTypeFlags associated with @type.
  *
- * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
+ * Returns: a #GstQueryTypeFlags.
  */
-const GstQueryTypeDefinition *
-gst_query_type_get_details (GstQueryType type)
+GstQueryTypeFlags
+gst_query_type_get_flags (GstQueryType type)
 {
-  const GstQueryTypeDefinition *result;
+  GstQueryTypeFlags ret;
 
-  g_mutex_lock (&mutex);
-  result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
-  g_mutex_unlock (&mutex);
+  ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
 
-  return result;
-}
-
-/**
- * gst_query_type_iterate_definitions:
- *
- * Get a #GstIterator of all the registered query types. The definitions
- * iterated over are read only.
- *
- * Free-function: gst_iterator_free
- *
- * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
- */
-GstIterator *
-gst_query_type_iterate_definitions (void)
-{
-  GstIterator *result;
-
-  g_mutex_lock (&mutex);
-  /* FIXME: register a boxed type for GstQueryTypeDefinition */
-  result = gst_iterator_new_list (G_TYPE_POINTER,
-      &mutex, &_n_values, &_gst_queries, NULL, NULL);
-  g_mutex_unlock (&mutex);
-
-  return result;
+  return ret;
 }
 
 static void
@@ -340,31 +196,28 @@ _gst_query_free (GstQuery * query)
     gst_structure_set_parent_refcount (s, NULL);
     gst_structure_free (s);
   }
+#ifdef USE_POISONING
+  memset (query, 0xff, sizeof (GstQueryImpl));
+#endif
 
-  g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
+  g_slice_free1 (sizeof (GstQueryImpl), query);
 }
 
 static GstQuery *
 _gst_query_copy (GstQuery * query)
 {
   GstQuery *copy;
+  GstStructure *s;
 
-  copy = gst_query_new_custom (query->type, GST_QUERY_STRUCTURE (query));
+  s = GST_QUERY_STRUCTURE (query);
+  if (s) {
+    s = gst_structure_copy (s);
+  }
+  copy = gst_query_new_custom (query->type, s);
 
   return copy;
 }
 
-static void
-gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
-{
-  gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
-
-  query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
-  query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
-
-  GST_EVENT_TYPE (query) = type;
-}
-
 /**
  * gst_query_new_position:
  * @format: the default #GstFormat for the new query
@@ -373,7 +226,7 @@ gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
  * when done with it. A position query is used to query the current position
  * of playback in the streams, in some format.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -420,11 +273,11 @@ gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
  * gst_query_parse_position:
  * @query: a #GstQuery
  * @format: (out) (allow-none): the storage for the #GstFormat of the
- *     position values (may be NULL)
- * @cur: (out) (allow-none): the storage for the current position (may be NULL)
+ *     position values (may be %NULL)
+ * @cur: (out) (allow-none): the storage for the current position (may be %NULL)
  *
  * Parse a position query, writing the format into @format, and the position
- * into @cur, if the respective parameters are non-NULL.
+ * into @cur, if the respective parameters are non-%NULL.
  */
 void
 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
@@ -452,7 +305,7 @@ gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
  * Use gst_query_unref() when done with it. A duration query will give the
  * total length of the stream.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -497,11 +350,11 @@ gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
  * gst_query_parse_duration:
  * @query: a #GstQuery
  * @format: (out) (allow-none): the storage for the #GstFormat of the duration
- *     value, or NULL.
- * @duration: (out) (allow-none): the storage for the total duration, or NULL.
+ *     value, or %NULL.
+ * @duration: (out) (allow-none): the storage for the total duration, or %NULL.
  *
  * Parse a duration query answer. Write the format of the duration into @format,
- * and the value into @duration, if the respective variables are non-NULL.
+ * and the value into @duration, if the respective variables are non-%NULL.
  */
 void
 gst_query_parse_duration (GstQuery * query, GstFormat * format,
@@ -529,11 +382,9 @@ gst_query_parse_duration (GstQuery * query, GstFormat * format,
  * by sinks to compensate for additional latency introduced by elements in the
  * pipeline.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a #GstQuery
- *
- * Since: 0.10.12
  */
 GstQuery *
 gst_query_new_latency (void)
@@ -544,7 +395,7 @@ gst_query_new_latency (void)
   structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
       GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
       GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
-      GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
+      GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, GST_CLOCK_TIME_NONE, NULL);
 
   query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
 
@@ -559,8 +410,6 @@ gst_query_new_latency (void)
  * @max_latency: the maximal latency of the upstream elements
  *
  * Answer a latency query by setting the requested values in the given format.
- *
- * Since: 0.10.12
  */
 void
 gst_query_set_latency (GstQuery * query, gboolean live,
@@ -569,6 +418,7 @@ gst_query_set_latency (GstQuery * query, gboolean live,
   GstStructure *structure;
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
+  g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
 
   structure = GST_QUERY_STRUCTURE (query);
   gst_structure_id_set (structure,
@@ -580,13 +430,11 @@ gst_query_set_latency (GstQuery * query, gboolean live,
 /**
  * gst_query_parse_latency:
  * @query: a #GstQuery
- * @live: (out) (allow-none): storage for live or NULL
- * @min_latency: (out) (allow-none): the storage for the min latency or NULL
- * @max_latency: (out) (allow-none): the storage for the max latency or NULL
+ * @live: (out) (allow-none): storage for live or %NULL
+ * @min_latency: (out) (allow-none): the storage for the min latency or %NULL
+ * @max_latency: (out) (allow-none): the storage for the max latency or %NULL
  *
  * Parse a latency query answer.
- *
- * Since: 0.10.12
  */
 void
 gst_query_parse_latency (GstQuery * query, gboolean * live,
@@ -619,7 +467,7 @@ gst_query_parse_latency (GstQuery * query, gboolean * live,
  * when done with it. A convert query is used to ask for a conversion between
  * one format and another.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a #GstQuery
  */
@@ -671,15 +519,15 @@ gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
  * gst_query_parse_convert:
  * @query: a #GstQuery
  * @src_format: (out) (allow-none): the storage for the #GstFormat of the
- *     source value, or NULL
- * @src_value: (out) (allow-none): the storage for the source value, or NULL
+ *     source value, or %NULL
+ * @src_value: (out) (allow-none): the storage for the source value, or %NULL
  * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
- *     destination value, or NULL
+ *     destination value, or %NULL
  * @dest_value: (out) (allow-none): the storage for the destination value,
- *     or NULL
+ *     or %NULL
  *
  * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
- * and @dest_value may be NULL, in which case that value is omitted.
+ * and @dest_value may be %NULL, in which case that value is omitted.
  */
 void
 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
@@ -714,7 +562,7 @@ gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
  * when done with it. A segment query is used to discover information about the
  * currently configured segment for playback.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -774,14 +622,14 @@ gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
 /**
  * gst_query_parse_segment:
  * @query: a #GstQuery
- * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
+ * @rate: (out) (allow-none): the storage for the rate of the segment, or %NULL
  * @format: (out) (allow-none): the storage for the #GstFormat of the values,
- *     or NULL
- * @start_value: (out) (allow-none): the storage for the start value, or NULL
- * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
+ *     or %NULL
+ * @start_value: (out) (allow-none): the storage for the start value, or %NULL
+ * @stop_value: (out) (allow-none): the storage for the stop value, or %NULL
  *
  * Parse a segment query answer. Any of @rate, @format, @start_value, and
- * @stop_value may be NULL, which will cause this value to be omitted.
+ * @stop_value may be %NULL, which will cause this value to be omitted.
  *
  * See gst_query_set_segment() for an explanation of the function arguments.
  */
@@ -812,14 +660,14 @@ gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
 /**
  * gst_query_new_custom:
  * @type: the query type
- * @structure: a structure for the query
+ * @structure: (allow-none) (transfer full): a structure for the query
  *
  * Constructs a new custom query object. Use gst_query_unref()
  * when done with it.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
- * Returns: (transfer full): a new #GstQuery
+ * Returns: (transfer full) (nullable): a new #GstQuery
  */
 GstQuery *
 gst_query_new_custom (GstQueryType type, GstStructure * structure)
@@ -836,8 +684,12 @@ gst_query_new_custom (GstQueryType type, GstStructure * structure)
             &query->query.mini_object.refcount))
       goto had_parent;
   }
-  gst_query_init (query, sizeof (GstQueryImpl), type);
 
+  gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
+      (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
+      (GstMiniObjectFreeFunction) _gst_query_free);
+
+  GST_QUERY_TYPE (query) = type;
   GST_QUERY_STRUCTURE (query) = structure;
 
   return GST_QUERY_CAST (query);
@@ -845,7 +697,7 @@ gst_query_new_custom (GstQueryType type, GstStructure * structure)
   /* ERRORS */
 had_parent:
   {
-    g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
+    g_slice_free1 (sizeof (GstQueryImpl), query);
     g_warning ("structure is already owned by another object");
     return NULL;
   }
@@ -857,9 +709,9 @@ had_parent:
  *
  * Get the structure of a query.
  *
- * Returns: (transfer none): the #GstStructure of the query. The structure is
- *     still owned by the query and will therefore be freed when the query
- *     is unreffed.
+ * Returns: (transfer none) (nullable): the #GstStructure of the query. The
+ *     structure is still owned by the query and will therefore be freed when the
+ *     query is unreffed.
  */
 const GstStructure *
 gst_query_get_structure (GstQuery * query)
@@ -873,7 +725,8 @@ gst_query_get_structure (GstQuery * query)
  * gst_query_writable_structure:
  * @query: a #GstQuery
  *
- * Get the structure of a query.
+ * Get the structure of a query. This method should be called with a writable
+ * @query so that the returned structure is guaranteed to be writable.
  *
  * Returns: (transfer none): the #GstStructure of the query. The structure is
  *     still owned by the query and will therefore be freed when the query
@@ -882,10 +735,21 @@ gst_query_get_structure (GstQuery * query)
 GstStructure *
 gst_query_writable_structure (GstQuery * query)
 {
+  GstStructure *structure;
+
   g_return_val_if_fail (GST_IS_QUERY (query), NULL);
   g_return_val_if_fail (gst_query_is_writable (query), NULL);
 
-  return GST_QUERY_STRUCTURE (query);
+  structure = GST_QUERY_STRUCTURE (query);
+
+  if (structure == NULL) {
+    structure =
+        gst_structure_new_id_empty (gst_query_type_to_quark (GST_QUERY_TYPE
+            (query)));
+    gst_structure_set_parent_refcount (structure, &query->mini_object.refcount);
+    GST_QUERY_STRUCTURE (query) = structure;
+  }
+  return structure;
 }
 
 /**
@@ -895,7 +759,7 @@ gst_query_writable_structure (GstQuery * query)
  * Constructs a new query object for querying seeking properties of
  * the stream.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -947,14 +811,14 @@ gst_query_set_seeking (GstQuery * query, GstFormat format,
  * gst_query_parse_seeking:
  * @query: a GST_QUERY_SEEKING type query #GstQuery
  * @format: (out) (allow-none): the format to set for the @segment_start
- *     and @segment_end values, or NULL
- * @seekable: (out) (allow-none): the seekable flag to set, or NULL
- * @segment_start: (out) (allow-none): the segment_start to set, or NULL
- * @segment_end: (out) (allow-none): the segment_end to set, or NULL
+ *     and @segment_end values, or %NULL
+ * @seekable: (out) (allow-none): the seekable flag to set, or %NULL
+ * @segment_start: (out) (allow-none): the segment_start to set, or %NULL
+ * @segment_end: (out) (allow-none): the segment_end to set, or %NULL
  *
  * Parse a seeking query, writing the format into @format, and
  * other results into the passed parameters, if the respective parameters
- * are non-NULL
+ * are non-%NULL
  */
 void
 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
@@ -1011,11 +875,9 @@ ensure_array (GstStructure * s, GQuark quark, gsize element_size,
  * Constructs a new query object for querying formats of
  * the stream.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
- *
- * Since: 0.10.4
  */
 GstQuery *
 gst_query_new_formats (void)
@@ -1084,8 +946,6 @@ gst_query_set_formats (GstQuery * query, gint n_formats, ...)
  *
  * Set the formats query result fields in @query. The number of formats passed
  * in the @formats array must be equal to @n_formats.
- *
- * Since: 0.10.4
  */
 void
 gst_query_set_formatsv (GstQuery * query, gint n_formats,
@@ -1114,8 +974,6 @@ gst_query_set_formatsv (GstQuery * query, gint n_formats,
  * @n_formats: (out) (allow-none): the number of formats in this query.
  *
  * Parse the number of formats in the formats @query.
- *
- * Since: 0.10.4
  */
 void
 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
@@ -1139,7 +997,7 @@ gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
 /**
  * gst_query_parse_nth_format:
  * @query: a #GstQuery
- * @nth: (out): the nth format to retrieve.
+ * @nth: the nth format to retrieve.
  * @format: (out) (allow-none): a pointer to store the nth format
  *
  * Parse the format query and retrieve the @nth format from it into
@@ -1177,11 +1035,9 @@ gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
  * Constructs a new query object for querying the buffering status of
  * a stream.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
- *
- * Since: 0.10.20
  */
 GstQuery *
 gst_query_new_buffering (GstFormat format)
@@ -1216,8 +1072,6 @@ gst_query_new_buffering (GstFormat format)
  *
  * Set the percentage of buffered data. This is a value between 0 and 100.
  * The @busy indicator is %TRUE when the buffering is in progress.
- *
- * Since: 0.10.20
  */
 void
 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
@@ -1237,13 +1091,11 @@ gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
 /**
  * gst_query_parse_buffering_percent:
  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
- * @busy: (out) (allow-none): if buffering is busy, or NULL
- * @percent: (out) (allow-none): a buffering percent, or NULL
+ * @busy: (out) (allow-none): if buffering is busy, or %NULL
+ * @percent: (out) (allow-none): a buffering percent, or %NULL
  *
  * Get the percentage of buffered data. This is a value between 0 and 100.
  * The @busy indicator is %TRUE when the buffering is in progress.
- *
- * Since: 0.10.20
  */
 void
 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
@@ -1268,11 +1120,9 @@ gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
  * @mode: a buffering mode
  * @avg_in: the average input rate
  * @avg_out: the average output rate
- * @buffering_left: amount of buffering time left
+ * @buffering_left: amount of buffering time left in milliseconds
  *
  * Configures the buffering stats values in @query.
- *
- * Since: 0.10.20
  */
 void
 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
@@ -1294,14 +1144,13 @@ gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
 /**
  * gst_query_parse_buffering_stats:
  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
- * @mode: (out) (allow-none): a buffering mode, or NULL
- * @avg_in: (out) (allow-none): the average input rate, or NULL
- * @avg_out: (out) (allow-none): the average output rat, or NULLe
- * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
+ * @mode: (out) (allow-none): a buffering mode, or %NULL
+ * @avg_in: (out) (allow-none): the average input rate, or %NULL
+ * @avg_out: (out) (allow-none): the average output rat, or %NULL
+ * @buffering_left: (out) (allow-none): amount of buffering time left in
+ *     milliseconds, or %NULL
  *
  * Extracts the buffering stats values from @query.
- *
- * Since: 0.10.20
  */
 void
 gst_query_parse_buffering_stats (GstQuery * query,
@@ -1335,11 +1184,10 @@ gst_query_parse_buffering_stats (GstQuery * query,
  * @format: the format to set for the @start and @stop values
  * @start: the start to set
  * @stop: the stop to set
- * @estimated_total: estimated total amount of download time
+ * @estimated_total: estimated total amount of download time remaining in
+ *     milliseconds
  *
  * Set the available query result fields in @query.
- *
- * Since: 0.10.20
  */
 void
 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
@@ -1362,17 +1210,15 @@ gst_query_set_buffering_range (GstQuery * query, GstFormat format,
  * gst_query_parse_buffering_range:
  * @query: a GST_QUERY_BUFFERING type query #GstQuery
  * @format: (out) (allow-none): the format to set for the @segment_start
- *     and @segment_end values, or NULL
- * @start: (out) (allow-none): the start to set, or NULL
- * @stop: (out) (allow-none): the stop to set, or NULL
+ *     and @segment_end values, or %NULL
+ * @start: (out) (allow-none): the start to set, or %NULL
+ * @stop: (out) (allow-none): the stop to set, or %NULL
  * @estimated_total: (out) (allow-none): estimated total amount of download
- *     time, or NULL
+ *     time remaining in milliseconds, or %NULL
  *
  * Parse an available query, writing the format into @format, and
  * other results into the passed parameters, if the respective parameters
- * are non-NULL
- *
- * Since: 0.10.20
+ * are non-%NULL
  */
 void
 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
@@ -1399,6 +1245,13 @@ gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
             GST_QUARK (ESTIMATED_TOTAL)));
 }
 
+/* GstQueryBufferingRange: internal struct for GArray */
+typedef struct
+{
+  gint64 start;
+  gint64 stop;
+} GstQueryBufferingRange;
+
 /**
  * gst_query_add_buffering_range:
  * @query: a GST_QUERY_BUFFERING type query #GstQuery
@@ -1409,8 +1262,6 @@ gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
  * start position of the array should be inferior to @start.
  *
  * Returns: a #gboolean indicating if the range was added or not.
- *
- * Since: 0.10.31
  */
 gboolean
 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
@@ -1453,8 +1304,6 @@ gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
  * buffered-ranges array of the query's structure.
  *
  * Returns: the range array size as a #guint.
- *
- * Since: 0.10.31
  */
 guint
 gst_query_get_n_buffering_ranges (GstQuery * query)
@@ -1476,15 +1325,13 @@ gst_query_get_n_buffering_ranges (GstQuery * query)
  * gst_query_parse_nth_buffering_range:
  * @query: a GST_QUERY_BUFFERING type query #GstQuery
  * @index: position in the buffered-ranges array to read
- * @start: (out) (allow-none): the start position to set, or NULL
- * @stop: (out) (allow-none): the stop position to set, or NULL
+ * @start: (out) (allow-none): the start position to set, or %NULL
+ * @stop: (out) (allow-none): the stop position to set, or %NULL
  *
  * Parse an available query and get the start and stop values stored
  * at the @index of the buffered ranges array.
  *
  * Returns: a #gboolean indicating if the parsing succeeded.
- *
- * Since: 0.10.31
  */
 gboolean
 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
@@ -1520,11 +1367,9 @@ gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
  * when done with it. An URI query is used to query the current URI
  * that is used by the source or sink.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
- *
- * Since: 0.10.22
  */
 GstQuery *
 gst_query_new_uri (void)
@@ -1546,8 +1391,6 @@ gst_query_new_uri (void)
  * @uri: the URI to set
  *
  * Answer a URI query by setting the requested URI.
- *
- * Since: 0.10.22
  */
 void
 gst_query_set_uri (GstQuery * query, const gchar * uri)
@@ -1565,14 +1408,12 @@ gst_query_set_uri (GstQuery * query, const gchar * uri)
 /**
  * gst_query_parse_uri:
  * @query: a #GstQuery
- * @uri: (out callee-allocates) (allow-none): the storage for the current URI
- *     (may be NULL)
+ * @uri: (out) (transfer full) (allow-none): the storage for the current URI
+ *     (may be %NULL)
  *
  * Parse an URI query, writing the URI into @uri as a newly
- * allocated string, if the respective parameters are non-NULL.
+ * allocated string, if the respective parameters are non-%NULL.
  * Free the string with g_free() after usage.
- *
- * Since: 0.10.22
  */
 void
 gst_query_parse_uri (GstQuery * query, gchar ** uri)
@@ -1588,13 +1429,115 @@ gst_query_parse_uri (GstQuery * query, gchar ** uri)
 }
 
 /**
+ * gst_query_set_uri_redirection:
+ * @query: a #GstQuery with query type GST_QUERY_URI
+ * @uri: the URI to set
+ *
+ * Answer a URI query by setting the requested URI redirection.
+ *
+ * Since: 1.2
+ */
+void
+gst_query_set_uri_redirection (GstQuery * query, const gchar * uri)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
+  g_return_if_fail (gst_query_is_writable (query));
+  g_return_if_fail (gst_uri_is_valid (uri));
+
+  structure = GST_QUERY_STRUCTURE (query);
+  gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
+      G_TYPE_STRING, uri, NULL);
+}
+
+/**
+ * gst_query_parse_uri_redirection:
+ * @query: a #GstQuery
+ * @uri: (out) (transfer full) (allow-none): the storage for the redirect URI
+ *     (may be %NULL)
+ *
+ * Parse an URI query, writing the URI into @uri as a newly
+ * allocated string, if the respective parameters are non-%NULL.
+ * Free the string with g_free() after usage.
+ *
+ * Since: 1.2
+ */
+void
+gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  if (uri) {
+    if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION),
+            G_TYPE_STRING, uri, NULL))
+      *uri = NULL;
+  }
+}
+
+/**
+ * gst_query_set_uri_redirection_permanent:
+ * @query: a #GstQuery with query type %GST_QUERY_URI
+ * @permanent: whether the redirect is permanent or not
+ *
+ * Answer a URI query by setting the requested URI redirection
+ * to permanent or not.
+ *
+ * Since: 1.4
+ */
+void
+gst_query_set_uri_redirection_permanent (GstQuery * query, gboolean permanent)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
+  g_return_if_fail (gst_query_is_writable (query));
+
+  structure = GST_QUERY_STRUCTURE (query);
+  gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
+      G_TYPE_BOOLEAN, permanent, NULL);
+}
+
+/**
+ * gst_query_parse_uri_redirection_permanent:
+ * @query: a #GstQuery
+ * @permanent: (out) (allow-none): if the URI redirection is permanent
+ *     (may be %NULL)
+ *
+ * Parse an URI query, and set @permanent to %TRUE if there is a redirection
+ * and it should be considered permanent. If a redirection is permanent,
+ * applications should update their internal storage of the URI, otherwise
+ * they should make all future requests to the original URI.
+ *
+ * Since: 1.4
+ */
+void
+gst_query_parse_uri_redirection_permanent (GstQuery * query,
+    gboolean * permanent)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  if (permanent) {
+    if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
+            G_TYPE_BOOLEAN, permanent, NULL))
+      *permanent = FALSE;
+  }
+}
+
+/**
  * gst_query_new_allocation:
  * @caps: the negotiated caps
  * @need_pool: return a pool
  *
  * Constructs a new query object for querying the allocation properties.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -1606,13 +1549,7 @@ gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
 
   structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
-      GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
-      GST_QUARK (SIZE), G_TYPE_UINT, 0,
-      GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
-      GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
-      GST_QUARK (PREFIX), G_TYPE_UINT, 0,
-      GST_QUARK (ALIGN), G_TYPE_UINT, 0,
-      GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
+      GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
 
   query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
 
@@ -1622,12 +1559,15 @@ gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
 /**
  * gst_query_parse_allocation:
  * @query: a #GstQuery
- * @caps: (out callee-allocates) (allow-none): The #GstCaps
+ * @caps: (out) (transfer none) (allow-none): The #GstCaps
  * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
  *
  * Parse an allocation query, writing the requested caps in @caps and
  * whether a pool is needed in @need_pool, if the respective parameters
- * are non-NULL.
+ * are non-%NULL.
+ *
+ * Pool details can be retrieved using gst_query_get_n_allocation_pools() and
+ * gst_query_parse_nth_allocation_pool().
  */
 void
 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
@@ -1638,97 +1578,235 @@ gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
 
   structure = GST_QUERY_STRUCTURE (query);
+  if (caps) {
+    *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
+            GST_QUARK (CAPS)));
+  }
   gst_structure_id_get (structure,
-      GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
       GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
 }
 
+typedef struct
+{
+  GstBufferPool *pool;
+  guint size;
+  guint min_buffers;
+  guint max_buffers;
+} AllocationPool;
+
+static void
+allocation_pool_free (AllocationPool * ap)
+{
+  if (ap->pool)
+    gst_object_unref (ap->pool);
+}
+
 /**
- * gst_query_set_allocation_params:
+ * gst_query_add_allocation_pool:
  * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
- * @size: the size
+ * @pool: (transfer none) (allow-none): the #GstBufferPool
+ * @size: the buffer size
  * @min_buffers: the min buffers
  * @max_buffers: the max buffers
- * @prefix: the prefix
- * @alignment: the alignment
- * @pool: the #GstBufferPool
  *
- * Set the allocation parameters in @query.
+ * Set the pool parameters in @query.
  */
 void
-gst_query_set_allocation_params (GstQuery * query, guint size,
-    guint min_buffers, guint max_buffers, guint prefix,
-    guint alignment, GstBufferPool * pool)
+gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
+    guint size, guint min_buffers, guint max_buffers)
 {
+  GArray *array;
   GstStructure *structure;
+  AllocationPool ap;
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
   g_return_if_fail (gst_query_is_writable (query));
-  g_return_if_fail (((alignment + 1) & alignment) == 0);
-  g_return_if_fail (size != 0 || pool == NULL);
 
   structure = GST_QUERY_STRUCTURE (query);
-  gst_structure_id_set (structure,
-      GST_QUARK (SIZE), G_TYPE_UINT, size,
-      GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
-      GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
-      GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
-      GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
-      GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
+  array = ensure_array (structure, GST_QUARK (POOL),
+      sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
+
+  if ((ap.pool = pool))
+    gst_object_ref (pool);
+  ap.size = size;
+  ap.min_buffers = min_buffers;
+  ap.max_buffers = max_buffers;
+
+  g_array_append_val (array, ap);
+}
+
+/**
+ * gst_query_get_n_allocation_pools:
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ *
+ * Retrieve the number of values currently stored in the
+ * pool array of the query's structure.
+ *
+ * Returns: the pool array size as a #guint.
+ */
+guint
+gst_query_get_n_allocation_pools (GstQuery * query)
+{
+  GArray *array;
+  GstStructure *structure;
+
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  array = ensure_array (structure, GST_QUARK (POOL),
+      sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
+
+  return array->len;
 }
 
 /**
- * gst_query_parse_allocation_params:
+ * gst_query_parse_nth_allocation_pool:
  * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
- * @size: (out) (allow-none): the size
+ * @index: index to parse
+ * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
+ * @size: (out) (allow-none): the buffer size
  * @min_buffers: (out) (allow-none): the min buffers
  * @max_buffers: (out) (allow-none): the max buffers
- * @prefix: (out) (allow-none): the prefix
- * @alignment: (out) (allow-none): the alignment
- * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
  *
- * Get the allocation parameters in @query.
+ * Get the pool parameters in @query.
+ *
+ * Unref @pool with gst_object_unref() when it's not needed any more.
  */
 void
-gst_query_parse_allocation_params (GstQuery * query, guint * size,
-    guint * min_buffers, guint * max_buffers, guint * prefix,
-    guint * alignment, GstBufferPool ** pool)
+gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
+    GstBufferPool ** pool, guint * size, guint * min_buffers,
+    guint * max_buffers)
 {
+  GArray *array;
   GstStructure *structure;
+  AllocationPool *ap;
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
 
   structure = GST_QUERY_STRUCTURE (query);
-  gst_structure_id_get (structure,
-      GST_QUARK (SIZE), G_TYPE_UINT, size,
-      GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
-      GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
-      GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
-      GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
-      GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
+  array = ensure_array (structure, GST_QUARK (POOL),
+      sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
+  g_return_if_fail (index < array->len);
+
+  ap = &g_array_index (array, AllocationPool, index);
+
+  if (pool)
+    if ((*pool = ap->pool))
+      gst_object_ref (*pool);
+  if (size)
+    *size = ap->size;
+  if (min_buffers)
+    *min_buffers = ap->min_buffers;
+  if (max_buffers)
+    *max_buffers = ap->max_buffers;
+}
+
+/**
+ * gst_query_set_nth_allocation_pool:
+ * @index: index to modify
+ * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
+ * @pool: (transfer none) (allow-none): the #GstBufferPool
+ * @size: the buffer size
+ * @min_buffers: the min buffers
+ * @max_buffers: the max buffers
+ *
+ * Set the pool parameters in @query.
+ */
+void
+gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
+    GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
+{
+  GArray *array;
+  GstStructure *structure;
+  AllocationPool *oldap, ap;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  array = ensure_array (structure, GST_QUARK (POOL),
+      sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
+  g_return_if_fail (index < array->len);
+
+  oldap = &g_array_index (array, AllocationPool, index);
+  allocation_pool_free (oldap);
+
+  if ((ap.pool = pool))
+    gst_object_ref (pool);
+  ap.size = size;
+  ap.min_buffers = min_buffers;
+  ap.max_buffers = max_buffers;
+  g_array_index (array, AllocationPool, index) = ap;
+}
+
+/**
+ * gst_query_remove_nth_allocation_pool:
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ * @index: position in the allocation pool array to remove
+ *
+ * Remove the allocation pool at @index of the allocation pool array.
+ *
+ * Since: 1.2
+ */
+void
+gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
+{
+  GArray *array;
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+  g_return_if_fail (gst_query_is_writable (query));
+
+  structure = GST_QUERY_STRUCTURE (query);
+  array =
+      ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
+      (GDestroyNotify) allocation_pool_free);
+  g_return_if_fail (index < array->len);
+
+  g_array_remove_index (array, index);
+}
+
+typedef struct
+{
+  GType api;
+  GstStructure *params;
+} AllocationMeta;
+
+static void
+allocation_meta_free (AllocationMeta * am)
+{
+  if (am->params)
+    gst_structure_free (am->params);
 }
 
 /**
  * gst_query_add_allocation_meta:
  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
  * @api: the metadata API
+ * @params: (transfer none) (allow-none): API specific parameters
  *
- * Add @api as aone of the supported metadata API to @query.
+ * Add @api with @params as one of the supported metadata API to @query.
  */
 void
-gst_query_add_allocation_meta (GstQuery * query, GType api)
+gst_query_add_allocation_meta (GstQuery * query, GType api,
+    const GstStructure * params)
 {
   GArray *array;
   GstStructure *structure;
+  AllocationMeta am;
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
   g_return_if_fail (api != 0);
   g_return_if_fail (gst_query_is_writable (query));
 
   structure = GST_QUERY_STRUCTURE (query);
-  array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
+  array =
+      ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
+      (GDestroyNotify) allocation_meta_free);
+
+  am.api = api;
+  am.params = (params ? gst_structure_copy (params) : NULL);
 
-  g_array_append_val (array, api);
+  g_array_append_val (array, am);
 }
 
 /**
@@ -1749,7 +1827,9 @@ gst_query_get_n_allocation_metas (GstQuery * query)
   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
 
   structure = GST_QUERY_STRUCTURE (query);
-  array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
+  array =
+      ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
+      (GDestroyNotify) allocation_meta_free);
 
   return array->len;
 }
@@ -1758,6 +1838,7 @@ gst_query_get_n_allocation_metas (GstQuery * query)
  * gst_query_parse_nth_allocation_meta:
  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
  * @index: position in the metadata API array to read
+ * @params: (out) (transfer none) (allow-none): API specific parameters
  *
  * Parse an available query and get the metadata API
  * at @index of the metadata API array.
@@ -1765,19 +1846,28 @@ gst_query_get_n_allocation_metas (GstQuery * query)
  * Returns: a #GType of the metadata API at @index.
  */
 GType
-gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
+gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
+    const GstStructure ** params)
 {
   GArray *array;
   GstStructure *structure;
+  AllocationMeta *am;
 
   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
 
   structure = GST_QUERY_STRUCTURE (query);
-  array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
+  array =
+      ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
+      (GDestroyNotify) allocation_meta_free);
 
   g_return_val_if_fail (index < array->len, 0);
 
-  return g_array_index (array, GType, index);
+  am = &g_array_index (array, AllocationMeta, index);
+
+  if (params)
+    *params = am->params;
+
+  return am->api;
 }
 
 /**
@@ -1797,23 +1887,28 @@ gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
   g_return_if_fail (gst_query_is_writable (query));
 
   structure = GST_QUERY_STRUCTURE (query);
-  array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
+  array =
+      ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
+      (GDestroyNotify) allocation_meta_free);
   g_return_if_fail (index < array->len);
 
   g_array_remove_index (array, index);
 }
 
 /**
- * gst_query_has_allocation_meta:
+ * gst_query_find_allocation_meta:
  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
  * @api: the metadata API
+ * @index: (out) (transfer none) (allow-none): the index
  *
- * Check if @query has metadata @api set.
+ * Check if @query has metadata @api set. When this function returns %TRUE,
+ * @index will contain the index where the requested API and the parameters
+ * can be found.
  *
- * Returns: TRUE when @api is in the list of metadata.
+ * Returns: %TRUE when @api is in the list of metadata.
  */
 gboolean
-gst_query_has_allocation_meta (GstQuery * query, GType api)
+gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
 {
   GArray *array;
   GstStructure *structure;
@@ -1823,55 +1918,85 @@ gst_query_has_allocation_meta (GstQuery * query, GType api)
   g_return_val_if_fail (api != 0, FALSE);
 
   structure = GST_QUERY_STRUCTURE (query);
-  array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
+  array =
+      ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
+      (GDestroyNotify) allocation_meta_free);
 
   len = array->len;
   for (i = 0; i < len; i++) {
-    if (g_array_index (array, GType, i) == api)
+    AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
+    if (am->api == api) {
+      if (index)
+        *index = i;
       return TRUE;
+    }
   }
   return FALSE;
 }
 
+typedef struct
+{
+  GstAllocator *allocator;
+  GstAllocationParams params;
+} AllocationParam;
+
+static void
+allocation_param_free (AllocationParam * ap)
+{
+  if (ap->allocator)
+    gst_object_unref (ap->allocator);
+}
+
 /**
- * gst_query_add_allocation_memory:
+ * gst_query_add_allocation_param:
  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
- * @allocator: the memory allocator
+ * @allocator: (transfer none) (allow-none): the memory allocator
+ * @params: (transfer none) (allow-none): a #GstAllocationParams
  *
- * Add @allocator as a supported memory allocator.
+ * Add @allocator and its @params as a supported memory allocator.
  */
 void
-gst_query_add_allocation_memory (GstQuery * query, GstAllocator * allocator)
+gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
+    const GstAllocationParams * params)
 {
   GArray *array;
   GstStructure *structure;
+  AllocationParam ap;
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
   g_return_if_fail (gst_query_is_writable (query));
-  g_return_if_fail (allocator != NULL);
+  g_return_if_fail (allocator != NULL || params != NULL);
 
   structure = GST_QUERY_STRUCTURE (query);
-  array =
-      ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
-      (GDestroyNotify) gst_allocator_unref);
+  array = ensure_array (structure, GST_QUARK (ALLOCATOR),
+      sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
 
-  g_array_append_val (array, allocator);
+  if ((ap.allocator = allocator))
+    gst_object_ref (allocator);
+  if (params)
+    ap.params = *params;
+  else
+    gst_allocation_params_init (&ap.params);
+
+  g_array_append_val (array, ap);
 }
 
 /**
- * gst_query_get_n_allocation_memories:
+ * gst_query_get_n_allocation_params:
  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
  *
  * Retrieve the number of values currently stored in the
- * allocator array of the query's structure.
+ * allocator params array of the query's structure.
  *
  * If no memory allocator is specified, the downstream element can handle
- * the default memory allocator.
+ * the default memory allocator. The first memory allocator in the query
+ * should be generic and allow mapping to system memory, all following
+ * allocators should be ordered by preference with the preferred one first.
  *
  * Returns: the allocator array size as a #guint.
  */
 guint
-gst_query_get_n_allocation_memories (GstQuery * query)
+gst_query_get_n_allocation_params (GstQuery * query)
 {
   GArray *array;
   GstStructure *structure;
@@ -1879,39 +2004,109 @@ gst_query_get_n_allocation_memories (GstQuery * query)
   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
 
   structure = GST_QUERY_STRUCTURE (query);
-  array =
-      ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
-      (GDestroyNotify) gst_allocator_unref);
+  array = ensure_array (structure, GST_QUARK (ALLOCATOR),
+      sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
 
   return array->len;
 }
 
 /**
- * gst_query_parse_nth_allocation_memory:
+ * gst_query_parse_nth_allocation_param:
  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
  * @index: position in the allocator array to read
+ * @allocator: (out) (transfer full) (allow-none): variable to hold the result
+ * @params: (out) (allow-none): parameters for the allocator
+ *
+ * Parse an available query and get the allocator and its params
+ * at @index of the allocator array.
+ */
+void
+gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
+    GstAllocator ** allocator, GstAllocationParams * params)
+{
+  GArray *array;
+  GstStructure *structure;
+  AllocationParam *ap;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  array = ensure_array (structure, GST_QUARK (ALLOCATOR),
+      sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
+  g_return_if_fail (index < array->len);
+
+  ap = &g_array_index (array, AllocationParam, index);
+
+  if (allocator)
+    if ((*allocator = ap->allocator))
+      gst_object_ref (*allocator);
+  if (params)
+    *params = ap->params;
+}
+
+/**
+ * gst_query_set_nth_allocation_param:
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ * @index: position in the allocator array to set
+ * @allocator: (transfer none) (allow-none): new allocator to set
+ * @params: (transfer none) (allow-none): parameters for the allocator
  *
- * Parse an available query and get the alloctor
+ * Parse an available query and get the allocator and its params
  * at @index of the allocator array.
+ */
+void
+gst_query_set_nth_allocation_param (GstQuery * query, guint index,
+    GstAllocator * allocator, const GstAllocationParams * params)
+{
+  GArray *array;
+  GstStructure *structure;
+  AllocationParam *old, ap;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  array = ensure_array (structure, GST_QUARK (ALLOCATOR),
+      sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
+  g_return_if_fail (index < array->len);
+
+  old = &g_array_index (array, AllocationParam, index);
+  allocation_param_free (old);
+
+  if ((ap.allocator = allocator))
+    gst_object_ref (allocator);
+  if (params)
+    ap.params = *params;
+  else
+    gst_allocation_params_init (&ap.params);
+
+  g_array_index (array, AllocationParam, index) = ap;
+}
+
+/**
+ * gst_query_remove_nth_allocation_param:
+ * @query: a GST_QUERY_ALLOCATION type query #GstQuery
+ * @index: position in the allocation param array to remove
+ *
+ * Remove the allocation param at @index of the allocation param array.
  *
- * Returns: (transfer none): the allocator at @index. The allocator remains
- * valid for as long as @query is valid.
+ * Since: 1.2
  */
-GstAllocator *
-gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
+void
+gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
 {
   GArray *array;
   GstStructure *structure;
 
-  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
+  g_return_if_fail (gst_query_is_writable (query));
 
   structure = GST_QUERY_STRUCTURE (query);
   array =
-      ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
-      (GDestroyNotify) gst_allocator_unref);
-  g_return_val_if_fail (index < array->len, NULL);
+      ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
+      (GDestroyNotify) allocation_param_free);
+  g_return_if_fail (index < array->len);
 
-  return g_array_index (array, GstAllocator *, index);
+  g_array_remove_index (array, index);
 }
 
 /**
@@ -1919,7 +2114,7 @@ gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
  *
  * Constructs a new query object for querying the scheduling properties.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -1997,7 +2192,7 @@ gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
  * @query: a GST_QUERY_SCHEDULING type query #GstQuery
  * @mode: a #GstPadMode
  *
- * Add @mode as aone of the supported scheduling modes to @query.
+ * Add @mode as one of the supported scheduling modes to @query.
  */
 void
 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
@@ -2073,7 +2268,13 @@ gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
  *
  * Check if @query has scheduling mode set.
  *
- * Returns: TRUE when @mode is in the list of scheduling modes.
+ * > When checking if upstream supports pull mode, it is usually not
+ * > enough to just check for GST_PAD_MODE_PULL with this function, you
+ * > also want to check whether the scheduling flags returned by
+ * > gst_query_parse_scheduling() have the seeking flag set (meaning
+ * > random access is supported, not only sequential pulls).
+ *
+ * Returns: %TRUE when @mode is in the list of scheduling modes.
  */
 gboolean
 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
@@ -2097,12 +2298,38 @@ gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
 }
 
 /**
+ * gst_query_has_scheduling_mode_with_flags:
+ * @query: a GST_QUERY_SCHEDULING type query #GstQuery
+ * @mode: the scheduling mode
+ * @flags: #GstSchedulingFlags
+ *
+ * Check if @query has scheduling mode set and @flags is set in
+ * query scheduling flags.
+ *
+ * Returns: %TRUE when @mode is in the list of scheduling modes
+ *    and @flags are compatible with query flags.
+ */
+gboolean
+gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
+    GstSchedulingFlags flags)
+{
+  GstSchedulingFlags sched_flags;
+
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
+
+  gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
+
+  return ((flags & sched_flags) == flags) &&
+      gst_query_has_scheduling_mode (query, mode);
+}
+
+/**
  * gst_query_new_accept_caps:
- * @caps: a #GstCaps
+ * @caps: a fixed #GstCaps
  *
  * Constructs a new query object for querying if @caps are accepted.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -2112,6 +2339,8 @@ gst_query_new_accept_caps (GstCaps * caps)
   GstQuery *query;
   GstStructure *structure;
 
+  g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
+
   structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
       GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
@@ -2123,7 +2352,7 @@ gst_query_new_accept_caps (GstCaps * caps)
 /**
  * gst_query_parse_accept_caps:
  * @query: The query to parse
- * @caps: (out): A pointer to the caps
+ * @caps: (out) (transfer none): A pointer to the caps
  *
  * Get the caps from @query. The caps remains valid as long as @query remains
  * valid.
@@ -2141,6 +2370,13 @@ gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
           GST_QUARK (CAPS)));
 }
 
+/**
+ * gst_query_set_accept_caps_result:
+ * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
+ * @result: the result to set
+ *
+ * Set @result as the result for the @query.
+ */
 void
 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
 {
@@ -2154,6 +2390,13 @@ gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
       GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
 }
 
+/**
+ * gst_query_parse_accept_caps_result:
+ * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
+ * @result: (out) (allow-none): location for the result
+ *
+ * Parse the result from @query and store in @result.
+ */
 void
 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
 {
@@ -2172,7 +2415,7 @@ gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
  *
  * Constructs a new query object for querying the caps.
  *
- * The CAPS query should return the* allowable caps for a pad in the context
+ * The CAPS query should return the allowable caps for a pad in the context
  * of the element's state, its link to other elements, and the devices or files
  * it has opened. These caps must be a subset of the pad template caps. In the
  * NULL state with no links, the CAPS query should ideally return the same caps
@@ -2185,7 +2428,11 @@ gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
  * the CAPS query should return the most specific caps it reasonably can, since this
  * helps with autoplugging.
  *
- * Free-function: gst_query_unref
+ * The @filter is used to restrict the result caps, only the caps matching
+ * @filter should be returned from the CAPS query. Specifying a filter might
+ * greatly reduce the amount of processing an element needs to do.
+ *
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -2206,7 +2453,7 @@ gst_query_new_caps (GstCaps * filter)
 /**
  * gst_query_parse_caps:
  * @query: The query to parse
- * @filter: (out): A pointer to the caps filter
+ * @filter: (out) (transfer none): A pointer to the caps filter
  *
  * Get the filter from the caps @query. The caps remains valid as long as
  * @query remains valid.
@@ -2246,7 +2493,7 @@ gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
 /**
  * gst_query_parse_caps_result:
  * @query: The query to parse
- * @caps: (out): A pointer to the caps
+ * @caps: (out) (transfer none): A pointer to the caps
  *
  * Get the caps result from @query. The caps remains valid as long as
  * @query remains valid.
@@ -2264,6 +2511,7 @@ gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
           GST_QUARK (CAPS)));
 }
 
+#if 0
 void
 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
     GstCapsIntersectMode mode)
@@ -2275,3 +2523,207 @@ gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
   gst_query_set_caps_result (query, res);
   gst_caps_unref (res);
 }
+#endif
+
+/**
+ * gst_query_new_drain:
+ *
+ * Constructs a new query object for querying the drain state.
+ *
+ * Free-function: gst_query_unref()
+ *
+ * Returns: (transfer full): a new #GstQuery
+ */
+GstQuery *
+gst_query_new_drain (void)
+{
+  GstQuery *query;
+  GstStructure *structure;
+
+  structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
+  query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
+
+  return query;
+}
+
+/**
+ * gst_query_new_context:
+ * @context_type: Context type to query
+ *
+ * Constructs a new query object for querying the pipeline-local context.
+ *
+ * Free-function: gst_query_unref()
+ *
+ * Returns: (transfer full): a new #GstQuery
+ *
+ * Since: 1.2
+ */
+GstQuery *
+gst_query_new_context (const gchar * context_type)
+{
+  GstQuery *query;
+  GstStructure *structure;
+
+  g_return_val_if_fail (context_type != NULL, NULL);
+
+  structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
+      GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
+  query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
+
+  return query;
+}
+
+/**
+ * gst_query_set_context:
+ * @query: a #GstQuery with query type GST_QUERY_CONTEXT
+ * @context: the requested #GstContext
+ *
+ * Answer a context query by setting the requested context.
+ *
+ * Since: 1.2
+ */
+void
+gst_query_set_context (GstQuery * query, GstContext * context)
+{
+  GstStructure *s;
+  const gchar *context_type;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
+
+  gst_query_parse_context_type (query, &context_type);
+  g_return_if_fail (strcmp (gst_context_get_context_type (context),
+          context_type) == 0);
+
+  s = GST_QUERY_STRUCTURE (query);
+
+  gst_structure_id_set (s,
+      GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
+}
+
+/**
+ * gst_query_parse_context:
+ * @query: The query to parse
+ * @context: (out) (transfer none): A pointer to store the #GstContext
+ *
+ * Get the context from the context @query. The context remains valid as long as
+ * @query remains valid.
+ *
+ * Since: 1.2
+ */
+void
+gst_query_parse_context (GstQuery * query, GstContext ** context)
+{
+  GstStructure *structure;
+  const GValue *v;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
+  g_return_if_fail (context != NULL);
+
+  structure = GST_QUERY_STRUCTURE (query);
+  v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
+  if (v)
+    *context = g_value_get_boxed (v);
+  else
+    *context = NULL;
+}
+
+/**
+ * gst_query_parse_context_type:
+ * @query: a GST_QUERY_CONTEXT type query
+ * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
+ *
+ * Parse a context type from an existing GST_QUERY_CONTEXT query.
+ *
+ * Returns: a #gboolean indicating if the parsing succeeded.
+ *
+ * Since: 1.2
+ */
+gboolean
+gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
+{
+  GstStructure *structure;
+  const GValue *value;
+
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
+
+  structure = GST_QUERY_STRUCTURE (query);
+
+  if (context_type) {
+    value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
+    *context_type = g_value_get_string (value);
+  }
+
+  return TRUE;
+}
+
+/**
+ * gst_query_new_bitrate:
+ *
+ * Constructs a new query object for querying the bitrate.
+ *
+ * Free-function: gst_query_unref()
+ *
+ * Returns: (transfer full): a new #GstQuery
+ *
+ * Since: 1.16
+ */
+GstQuery *
+gst_query_new_bitrate (void)
+{
+  GstQuery *query;
+  GstStructure *structure;
+
+  structure = gst_structure_new_id_empty (GST_QUARK (QUERY_BITRATE));
+  query = gst_query_new_custom (GST_QUERY_BITRATE, structure);
+
+  return query;
+}
+
+/**
+ * gst_query_set_bitrate:
+ * @query: a GST_QUERY_BITRATE type #GstQuery
+ * @nominal_bitrate: the nominal bitrate in bits per second
+ *
+ * Set the results of a bitrate query.  The nominal bitrate is the average
+ * bitrate expected over the length of the stream as advertised in file
+ * headers (or similar).
+ *
+ * Since: 1.16
+ */
+void
+gst_query_set_bitrate (GstQuery * query, guint nominal_bitrate)
+{
+  GstStructure *s;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
+
+  s = GST_QUERY_STRUCTURE (query);
+
+  gst_structure_id_set (s,
+      GST_QUARK (NOMINAL_BITRATE), G_TYPE_UINT, nominal_bitrate, NULL);
+}
+
+/**
+ * gst_query_parse_bitrate:
+ * @query: a GST_QUERY_BITRATE type #GstQuery
+ * @nominal_bitrate: (out) (allow-none): The resulting bitrate in bits per second
+ *
+ * Get the results of a bitrate query. See also gst_query_set_bitrate().
+ *
+ * Since: 1.16
+ */
+void
+gst_query_parse_bitrate (GstQuery * query, guint * nominal_bitrate)
+{
+  GstStructure *structure;
+  const GValue *value;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
+
+  structure = GST_QUERY_STRUCTURE (query);
+
+  if (nominal_bitrate) {
+    value = gst_structure_id_get_value (structure, GST_QUARK (NOMINAL_BITRATE));
+    *nominal_bitrate = g_value_get_uint (value);
+  }
+}