gstpad: Probes that return HANDLED can reset the data info field
[platform/upstream/gstreamer.git] / gst / gstquery.c
index 5f21be9..1a82747 100644 (file)
@@ -23,6 +23,7 @@
 
 /**
  * SECTION:gstquery
+ * @title: GstQuery
  * @short_description: Provide functions to create queries, and to set and parse
  *                     values in them.
  * @see_also: #GstPad, #GstElement
  * 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 2012-03-29 (0.11.3)
+ * |[<!-- 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);
+ * ]|
  */
 
 
@@ -72,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
 {
@@ -111,6 +105,7 @@ static GstQueryQuarks query_quarks[] = {
   {GST_QUERY_CAPS, "caps", 0},
   {GST_QUERY_DRAIN, "drain", 0},
   {GST_QUERY_CONTEXT, "context", 0},
+  {GST_QUERY_BITRATE, "bitrate", 0},
 
   {0, NULL, 0}
 };
@@ -201,6 +196,9 @@ _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 (sizeof (GstQueryImpl), query);
 }
@@ -228,7 +226,7 @@ _gst_query_copy (GstQuery * query)
  * 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
  */
@@ -275,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)
@@ -307,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
  */
@@ -352,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,
@@ -384,7 +382,7 @@ 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
  */
@@ -397,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);
 
@@ -420,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,
@@ -431,9 +430,9 @@ 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.
  */
@@ -468,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
  */
@@ -520,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,
@@ -563,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
  */
@@ -623,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.
  */
@@ -661,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)
@@ -710,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)
@@ -727,7 +726,7 @@ gst_query_get_structure (GstQuery * query)
  * @query: a #GstQuery
  *
  * Get the structure of a query. This method should be called with a writable
- * @query so that the returned structure is guranteed to be 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
@@ -736,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;
 }
 
 /**
@@ -749,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
  */
@@ -801,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,
@@ -865,7 +875,7 @@ 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
  */
@@ -987,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
@@ -1025,7 +1035,7 @@ 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
  */
@@ -1081,8 +1091,8 @@ 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.
@@ -1134,11 +1144,11 @@ 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
+ * @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
+ *     milliseconds, or %NULL
  *
  * Extracts the buffering stats values from @query.
  */
@@ -1175,7 +1185,7 @@ gst_query_parse_buffering_stats (GstQuery * query,
  * @start: the start to set
  * @stop: the stop to set
  * @estimated_total: estimated total amount of download time remaining in
- *     miliseconds
+ *     milliseconds
  *
  * Set the available query result fields in @query.
  */
@@ -1200,15 +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 remaining in miliseconds, 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
+ * are non-%NULL
  */
 void
 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
@@ -1315,8 +1325,8 @@ 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.
@@ -1357,7 +1367,7 @@ 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
  */
@@ -1398,11 +1408,11 @@ 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.
  */
 void
@@ -1419,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
  */
@@ -1452,7 +1564,10 @@ gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
  *
  * 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,
@@ -1489,8 +1604,8 @@ allocation_pool_free (AllocationPool * ap)
 /**
  * gst_query_add_allocation_pool:
  * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
- * @pool: the #GstBufferPool
- * @size: the size
+ * @pool: (transfer none) (allow-none): the #GstBufferPool
+ * @size: the buffer size
  * @min_buffers: the min buffers
  * @max_buffers: the max buffers
  *
@@ -1506,7 +1621,6 @@ gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
   g_return_if_fail (gst_query_is_writable (query));
-  g_return_if_fail (size != 0);
 
   structure = GST_QUERY_STRUCTURE (query);
   array = ensure_array (structure, GST_QUARK (POOL),
@@ -1521,7 +1635,6 @@ gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
   g_array_append_val (array, ap);
 }
 
-
 /**
  * gst_query_get_n_allocation_pools:
  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
@@ -1551,7 +1664,7 @@ gst_query_get_n_allocation_pools (GstQuery * query)
  * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
  * @index: index to parse
  * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
- * @size: (out) (allow-none): the size
+ * @size: (out) (allow-none): the buffer size
  * @min_buffers: (out) (allow-none): the min buffers
  * @max_buffers: (out) (allow-none): the max buffers
  *
@@ -1592,8 +1705,8 @@ gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
  * gst_query_set_nth_allocation_pool:
  * @index: index to modify
  * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
- * @pool: the #GstBufferPool
- * @size: the size
+ * @pool: (transfer none) (allow-none): the #GstBufferPool
+ * @size: the buffer size
  * @min_buffers: the min buffers
  * @max_buffers: the max buffers
  *
@@ -1725,7 +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) (allow-none): API specific flags
+ * @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.
@@ -1786,13 +1899,13 @@ gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
  * gst_query_find_allocation_meta:
  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
  * @api: the metadata API
- * @index: (out) (allow-none): the index
+ * @index: (out) (transfer none) (allow-none): the index
  *
- * Check if @query has metadata @api set. When this function returns TRUE,
- * @index will contain the index where the requested API and the flags can be
- * found.
+ * 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_find_allocation_meta (GstQuery * query, GType api, guint * index)
@@ -1904,7 +2017,7 @@ gst_query_get_n_allocation_params (GstQuery * query)
  * @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 alloctor and its params
+ * Parse an available query and get the allocator and its params
  * at @index of the allocator array.
  */
 void
@@ -1938,7 +2051,7 @@ gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
  * @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 and its params
+ * Parse an available query and get the allocator and its params
  * at @index of the allocator array.
  */
 void
@@ -2001,7 +2114,7 @@ gst_query_remove_nth_allocation_param (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
  */
@@ -2079,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)
@@ -2155,17 +2268,13 @@ gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
  *
  * Check if @query has scheduling mode set.
  *
- * <note>
- *   <para>
- *     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).
- *   </para>
- * </note>
+ * > 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.
+ * Returns: %TRUE when @mode is in the list of scheduling modes.
  */
 gboolean
 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
@@ -2197,7 +2306,7 @@ gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
  * 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
+ * Returns: %TRUE when @mode is in the list of scheduling modes
  *    and @flags are compatible with query flags.
  */
 gboolean
@@ -2220,7 +2329,7 @@ gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
  *
  * 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
  */
@@ -2243,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.
@@ -2284,7 +2393,7 @@ gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
 /**
  * gst_query_parse_accept_caps_result:
  * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
- * @result: location for the result
+ * @result: (out) (allow-none): location for the result
  *
  * Parse the result from @query and store in @result.
  */
@@ -2323,7 +2432,7 @@ gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
  * @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
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -2344,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.
@@ -2384,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.
@@ -2421,7 +2530,7 @@ gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
  *
  * Constructs a new query object for querying the drain state.
  *
- * Free-function: gst_query_unref
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  */
@@ -2439,22 +2548,26 @@ gst_query_new_drain (void)
 
 /**
  * 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
+ * Free-function: gst_query_unref()
  *
  * Returns: (transfer full): a new #GstQuery
  *
  * Since: 1.2
  */
 GstQuery *
-gst_query_new_context (void)
+gst_query_new_context (const gchar * context_type)
 {
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_new_id_empty (GST_QUARK (QUERY_CONTEXT));
+  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;
@@ -2473,9 +2586,14 @@ 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,
@@ -2485,7 +2603,7 @@ gst_query_set_context (GstQuery * query, GstContext * context)
 /**
  * gst_query_parse_context:
  * @query: The query to parse
- * @context: (out): A pointer to store the #GstContext
+ * @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.
@@ -2509,127 +2627,103 @@ gst_query_parse_context (GstQuery * query, GstContext ** context)
     *context = NULL;
 }
 
-static void
-free_array_string (gpointer ptr)
-{
-  gchar *str = *(gchar **) ptr;
-  g_free (str);
-}
-
 /**
- * gst_query_add_context_type:
+ * gst_query_parse_context_type:
  * @query: a GST_QUERY_CONTEXT type query
- * @context_type: a context type
+ * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
+ *
+ * Parse a context type from an existing GST_QUERY_CONTEXT query.
  *
- * Add a new context type to @query.
+ * Returns: a #gboolean indicating if the parsing succeeded.
  *
  * Since: 1.2
  */
-void
-gst_query_add_context_type (GstQuery * query, const gchar * context_type)
+gboolean
+gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
 {
   GstStructure *structure;
-  GArray *array;
-  gchar *copy;
+  const GValue *value;
 
-  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
-  g_return_if_fail (gst_query_is_writable (query));
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
 
   structure = GST_QUERY_STRUCTURE (query);
-  array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
-      sizeof (gchar *), free_array_string);
 
-  copy = g_strdup (context_type);
-  g_array_append_val (array, copy);
+  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_get_n_context_types:
- * @query: a GST_QUERY_CONTEXT type query
+ * gst_query_new_bitrate:
  *
- * Retrieve the number of values currently stored in the
- * context-types array of the query's structure.
+ * Constructs a new query object for querying the bitrate.
  *
- * Returns: the context-types array size as a #guint.
+ * Free-function: gst_query_unref()
  *
- * Since: 1.2
+ * Returns: (transfer full): a new #GstQuery
+ *
+ * Since: 1.16
  */
-guint
-gst_query_get_n_context_types (GstQuery * query)
+GstQuery *
+gst_query_new_bitrate (void)
 {
+  GstQuery *query;
   GstStructure *structure;
-  GArray *array;
-
-  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, 0);
 
-  structure = GST_QUERY_STRUCTURE (query);
-  array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
-      sizeof (gchar *), free_array_string);
+  structure = gst_structure_new_id_empty (GST_QUARK (QUERY_BITRATE));
+  query = gst_query_new_custom (GST_QUERY_BITRATE, structure);
 
-  return array->len;
+  return query;
 }
 
 /**
- * gst_query_parse_nth_context_type:
- * @query: a GST_QUERY_CONTEXT type query
- * @context_type: (out) (allow-none): the context type, or NULL
- *
- * Parse a context type from an existing GST_QUERY_CONTEXT query
- * from @index.
+ * gst_query_set_bitrate:
+ * @query: a GST_QUERY_BITRATE type #GstQuery
+ * @nominal_bitrate: the nominal bitrate in bits per second
  *
- * Returns: a #gboolean indicating if the parsing succeeded.
+ * 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.2
+ * Since: 1.16
  */
-gboolean
-gst_query_parse_nth_context_type (GstQuery * query, guint index,
-    const gchar ** context_type)
+void
+gst_query_set_bitrate (GstQuery * query, guint nominal_bitrate)
 {
-  GstStructure *structure;
-  GArray *array;
-
-  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
+  GstStructure *s;
 
-  structure = GST_QUERY_STRUCTURE (query);
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
 
-  array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
-      sizeof (gchar *), free_array_string);
-  g_return_val_if_fail (index < array->len, FALSE);
-
-  if (context_type)
-    *context_type = g_array_index (array, gchar *, index);
+  s = GST_QUERY_STRUCTURE (query);
 
-  return TRUE;
+  gst_structure_id_set (s,
+      GST_QUARK (NOMINAL_BITRATE), G_TYPE_UINT, nominal_bitrate, NULL);
 }
 
 /**
- * gst_query_has_context_type:
- * @query: a GST_QUERY_CONTEXT type query
- * @context_type: the context type
+ * gst_query_parse_bitrate:
+ * @query: a GST_QUERY_BITRATE type #GstQuery
+ * @nominal_bitrate: (out) (allow-none): The resulting bitrate in bits per second
  *
- * Check if @query is asking for @context_type.
+ * Get the results of a bitrate query. See also gst_query_set_bitrate().
  *
- * Returns: %TRUE if @context_type is requested.
- *
- * Since: 1.2
+ * Since: 1.16
  */
-gboolean
-gst_query_has_context_type (GstQuery * query, const gchar * context_type)
+void
+gst_query_parse_bitrate (GstQuery * query, guint * nominal_bitrate)
 {
-  guint i, n;
+  GstStructure *structure;
+  const GValue *value;
 
-  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
-  g_return_val_if_fail (context_type != NULL, FALSE);
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
 
-  n = gst_query_get_n_context_types (query);
-  for (i = 0; i < n; i++) {
-    const gchar *tmp;
+  structure = GST_QUERY_STRUCTURE (query);
 
-    if (gst_query_parse_nth_context_type (query, i, &tmp) &&
-        strcmp (tmp, context_type) == 0)
-      return TRUE;
+  if (nominal_bitrate) {
+    value = gst_structure_id_get_value (structure, GST_QUARK (NOMINAL_BITRATE));
+    *nominal_bitrate = g_value_get_uint (value);
   }
-
-
-  return FALSE;
 }