]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gstreamer0-10.git/blobdiff - gst/gstquery.c
add GstQueryBuffers query
[glsdk/gstreamer0-10.git] / gst / gstquery.c
index b6e994c2b1b9e8f2fc23737fbb6763308428a4e9..1d7f5f99b4e6a354e538ac3456d70e8941c5fb57 100644 (file)
  *                     to create queries, and to set and parse values in them.
  * @see_also: #GstPad, #GstElement
  *
- * GstQuery functions are used to register a new query types to the gstreamer
- * core.
- * Query types can be used to perform queries on pads and elements.
+ * 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.
  *
- * Queries can be created using the gst_query_new_xxx() functions.  
- * Query values can be set using gst_query_set_xxx(), and parsed using 
- * gst_query_parse_xxx() helpers.
+ * Queries can be created using the gst_query_new_*() functions.
+ * Query values can be set using gst_query_set_*(), and parsed using
+ * 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>
@@ -94,7 +96,8 @@ static GstQueryTypeDefinition standard_definitions[] = {
   {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},
-  {0, NULL, NULL, 0}
+  {GST_QUERY_BUFFERS, "buffers", "Minimum buffer requirements", 0},
+  {GST_QUERY_NONE, NULL, NULL, 0}
 };
 
 void
@@ -114,7 +117,7 @@ _gst_query_initialize (void)
 
   while (standards->nick) {
     standards->quark = g_quark_from_static_string (standards->nick);
-    g_hash_table_insert (_nick_to_query, standards->nick, standards);
+    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);
 
@@ -191,7 +194,7 @@ gst_query_finalize (GstQuery * query)
     gst_structure_free (query->structure);
   }
 
-  GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (query));
+/*   GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (query)); */
 }
 
 static GstQuery *
@@ -231,21 +234,21 @@ gst_query_type_register (const gchar * nick, const gchar * description)
   GstQueryTypeDefinition *query;
   GstQueryType lookup;
 
-  g_return_val_if_fail (nick != NULL, 0);
-  g_return_val_if_fail (description != NULL, 0);
+  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_new0 (GstQueryTypeDefinition, 1);
-  query->value = _n_values;
+  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_static_mutex_lock (&mutex);
-  g_hash_table_insert (_nick_to_query, query->nick, query);
+  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);
@@ -269,7 +272,7 @@ gst_query_type_get_by_nick (const gchar * nick)
 {
   GstQueryTypeDefinition *query;
 
-  g_return_val_if_fail (nick != NULL, 0);
+  g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
 
   g_static_mutex_lock (&mutex);
   query = g_hash_table_lookup (_nick_to_query, nick);
@@ -329,10 +332,12 @@ gst_query_type_get_details (GstQueryType type)
 /**
  * gst_query_type_iterate_definitions:
  *
- * Get a #GstIterator of all the registered query types. The definitions 
+ * Get a #GstIterator of all the registered query types. The definitions
  * iterated over are read only.
  *
- * Returns: A #GstIterator of #GstQueryTypeDefinition.
+ * Free-function: gst_iterator_free
+ *
+ * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
  */
 GstIterator *
 gst_query_type_iterate_definitions (void)
@@ -356,7 +361,7 @@ gst_query_new (GstQueryType type, GstStructure * structure)
 
   query = (GstQuery *) gst_mini_object_new (GST_TYPE_QUERY);
 
-  GST_DEBUG ("creating new query %p %d", query, type);
+  GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
 
   query->type = type;
 
@@ -379,7 +384,9 @@ gst_query_new (GstQueryType type, GstStructure * structure)
  * when done with it. A position query is used to query the current position
  * of playback in the streams, in some format.
  *
- * Returns: A #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a new #GstQuery
  */
 GstQuery *
 gst_query_new_position (GstFormat format)
@@ -387,8 +394,7 @@ gst_query_new_position (GstFormat format)
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_empty_new ("GstQueryPosition");
-  gst_structure_id_set (structure,
+  structure = gst_structure_id_new (GST_QUARK (QUERY_POSITION),
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
 
@@ -408,12 +414,9 @@ gst_query_new_position (GstFormat format)
 void
 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
 
-  structure = gst_query_get_structure (query);
-  gst_structure_id_set (structure,
+  gst_structure_id_set (query->structure,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
 }
@@ -421,8 +424,9 @@ gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
 /**
  * gst_query_parse_position:
  * @query: a #GstQuery
- * @format: the storage for the #GstFormat of the position values (may be NULL)
- * @cur: the storage for the current position (may be NULL)
+ * @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)
  *
  * Parse a position query, writing the format into @format, and the position
  * into @cur, if the respective parameters are non-NULL.
@@ -434,9 +438,10 @@ gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
 
-  structure = gst_query_get_structure (query);
+  structure = query->structure;
   if (format)
-    *format = g_value_get_enum (gst_structure_id_get_value (structure,
+    *format =
+        (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (FORMAT)));
   if (cur)
     *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
@@ -448,11 +453,13 @@ gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
  * gst_query_new_duration:
  * @format: the #GstFormat for this duration query
  *
- * Constructs a new stream duration query object to query in the given format. 
+ * Constructs a new stream duration query object to query in the given format.
  * Use gst_query_unref() when done with it. A duration query will give the
  * total length of the stream.
  *
- * Returns: A #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a new #GstQuery
  */
 GstQuery *
 gst_query_new_duration (GstFormat format)
@@ -460,8 +467,7 @@ gst_query_new_duration (GstFormat format)
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_empty_new ("GstQueryDuration");
-  gst_structure_id_set (structure,
+  structure = gst_structure_id_new (GST_QUARK (QUERY_DURATION),
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
 
@@ -481,12 +487,9 @@ gst_query_new_duration (GstFormat format)
 void
 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
 
-  structure = gst_query_get_structure (query);
-  gst_structure_id_set (structure,
+  gst_structure_id_set (query->structure,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
 }
@@ -494,8 +497,9 @@ gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
 /**
  * gst_query_parse_duration:
  * @query: a #GstQuery
- * @format: the storage for the #GstFormat of the duration value, or NULL.
- * @duration: the storage for the total duration, or NULL.
+ * @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.
  *
  * 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.
@@ -508,9 +512,10 @@ gst_query_parse_duration (GstQuery * query, GstFormat * format,
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
 
-  structure = gst_query_get_structure (query);
+  structure = query->structure;
   if (format)
-    *format = g_value_get_enum (gst_structure_id_get_value (structure,
+    *format =
+        (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (FORMAT)));
   if (duration)
     *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
@@ -520,12 +525,14 @@ gst_query_parse_duration (GstQuery * query, GstFormat * format,
 /**
  * gst_query_new_latency:
  *
- * Constructs a new latency query object. 
+ * Constructs a new latency query object.
  * Use gst_query_unref() when done with it. A latency query is usually performed
  * by sinks to compensate for additional latency introduced by elements in the
  * pipeline.
  *
- * Returns: A #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a #GstQuery
  *
  * Since: 0.10.12
  */
@@ -535,8 +542,7 @@ gst_query_new_latency (void)
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_empty_new ("GstQueryLatency");
-  gst_structure_id_set (structure,
+  structure = gst_structure_id_new (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);
@@ -561,12 +567,9 @@ void
 gst_query_set_latency (GstQuery * query, gboolean live,
     GstClockTime min_latency, GstClockTime max_latency)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
 
-  structure = gst_query_get_structure (query);
-  gst_structure_id_set (structure,
+  gst_structure_id_set (query->structure,
       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
       GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
       GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
@@ -575,11 +578,11 @@ gst_query_set_latency (GstQuery * query, gboolean live,
 /**
  * gst_query_parse_latency:
  * @query: a #GstQuery
- * @live: storage for live or NULL 
- * @min_latency: the storage for the min latency or NULL
- * @max_latency: 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. 
+ * Parse a latency query answer.
  *
  * Since: 0.10.12
  */
@@ -591,7 +594,7 @@ gst_query_parse_latency (GstQuery * query, gboolean * live,
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
 
-  structure = gst_query_get_structure (query);
+  structure = query->structure;
   if (live)
     *live =
         g_value_get_boolean (gst_structure_id_get_value (structure,
@@ -614,7 +617,9 @@ 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.
  *
- * Returns: A #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a #GstQuery
  */
 GstQuery *
 gst_query_new_convert (GstFormat src_format, gint64 value,
@@ -623,8 +628,7 @@ gst_query_new_convert (GstFormat src_format, gint64 value,
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_empty_new ("GstQueryConvert");
-  gst_structure_id_set (structure,
+  structure = gst_structure_id_new (GST_QUARK (QUERY_CONVERT),
       GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
       GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
       GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
@@ -649,12 +653,9 @@ void
 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
     GstFormat dest_format, gint64 dest_value)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
 
-  structure = gst_query_get_structure (query);
-  gst_structure_id_set (structure,
+  gst_structure_id_set (query->structure,
       GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
       GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
       GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
@@ -664,10 +665,13 @@ gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
 /**
  * gst_query_parse_convert:
  * @query: a #GstQuery
- * @src_format: the storage for the #GstFormat of the source value, or NULL
- * @src_value: the storage for the source value, or NULL
- * @dest_format: the storage for the #GstFormat of the destination value, or NULL
- * @dest_value: the storage for the destination value, or NULL
+ * @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
+ * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
+ *     destination value, or NULL
+ * @dest_value: (out) (allow-none): the storage for the destination value,
+ *     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.
@@ -680,15 +684,17 @@ gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
 
-  structure = gst_query_get_structure (query);
+  structure = query->structure;
   if (src_format)
-    *src_format = g_value_get_enum (gst_structure_id_get_value (structure,
+    *src_format =
+        (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (SRC_FORMAT)));
   if (src_value)
     *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
             GST_QUARK (SRC_VALUE)));
   if (dest_format)
-    *dest_format = g_value_get_enum (gst_structure_id_get_value (structure,
+    *dest_format =
+        (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (DEST_FORMAT)));
   if (dest_value)
     *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
@@ -703,7 +709,9 @@ 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.
  *
- * Returns: a #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a new #GstQuery
  */
 GstQuery *
 gst_query_new_segment (GstFormat format)
@@ -711,8 +719,7 @@ gst_query_new_segment (GstFormat format)
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_empty_new ("GstQuerySegment");
-  gst_structure_id_set (structure,
+  structure = gst_structure_id_new (GST_QUARK (QUERY_SEGMENT),
       GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
@@ -736,9 +743,9 @@ gst_query_new_segment (GstFormat format)
  * 1.0. If a seek was performed on the pipeline to play a different
  * segment, this query will return the range specified in the last seek.
  *
- * @start_value and @stop_value will respectively contain the configured 
- * playback range start and stop values expressed in @format. 
- * The values are always between 0 and the duration of the media and 
+ * @start_value and @stop_value will respectively contain the configured
+ * playback range start and stop values expressed in @format.
+ * The values are always between 0 and the duration of the media and
  * @start_value <= @stop_value. @rate will contain the playback rate. For
  * negative rates, playback will actually happen from @stop_value to
  * @start_value.
@@ -747,12 +754,9 @@ void
 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
     gint64 start_value, gint64 stop_value)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
 
-  structure = gst_query_get_structure (query);
-  gst_structure_id_set (structure,
+  gst_structure_id_set (query->structure,
       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
@@ -762,12 +766,13 @@ gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
 /**
  * gst_query_parse_segment:
  * @query: a #GstQuery
- * @rate: the storage for the rate of the segment, or NULL
- * @format: the storage for the #GstFormat of the values, or NULL
- * @start_value: the storage for the start value, or NULL
- * @stop_value: the storage for the stop value, 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
  *
- * Parse a segment query answer. Any of @rate, @format, @start_value, and 
+ * 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.
  *
  * See gst_query_set_segment() for an explanation of the function arguments.
@@ -780,12 +785,13 @@ gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
 
-  structure = gst_query_get_structure (query);
+  structure = query->structure;
   if (rate)
     *rate = g_value_get_double (gst_structure_id_get_value (structure,
             GST_QUARK (RATE)));
   if (format)
-    *format = g_value_get_enum (gst_structure_id_get_value (structure,
+    *format =
+        (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (FORMAT)));
   if (start_value)
     *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
@@ -803,7 +809,9 @@ gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
  * Constructs a new custom application query object. Use gst_query_unref()
  * when done with it.
  *
- * Returns: a #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a new #GstQuery
  */
 GstQuery *
 gst_query_new_application (GstQueryType type, GstStructure * structure)
@@ -820,8 +828,9 @@ gst_query_new_application (GstQueryType type, GstStructure * structure)
  *
  * Get the structure of a query.
  *
- * Returns: 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): the #GstStructure of the query. The structure is
+ *     still owned by the query and will therefore be freed when the query
+ *     is unreffed.
  */
 GstStructure *
 gst_query_get_structure (GstQuery * query)
@@ -832,13 +841,15 @@ gst_query_get_structure (GstQuery * query)
 }
 
 /**
- * gst_query_new_seeking (GstFormat *format)
+ * gst_query_new_seeking:
  * @format: the default #GstFormat for the new query
  *
  * Constructs a new query object for querying seeking properties of
- * the stream. 
+ * the stream.
  *
- * Returns: A #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a new #GstQuery
  */
 GstQuery *
 gst_query_new_seeking (GstFormat format)
@@ -846,8 +857,7 @@ gst_query_new_seeking (GstFormat format)
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_empty_new ("GstQuerySeeking");
-  gst_structure_id_set (structure,
+  structure = gst_structure_id_new (GST_QUARK (QUERY_SEEKING),
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
       GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
@@ -872,12 +882,9 @@ void
 gst_query_set_seeking (GstQuery * query, GstFormat format,
     gboolean seekable, gint64 segment_start, gint64 segment_end)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
 
-  structure = gst_query_get_structure (query);
-  gst_structure_id_set (structure,
+  gst_structure_id_set (query->structure,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
       GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
@@ -887,12 +894,13 @@ gst_query_set_seeking (GstQuery * query, GstFormat format,
 /**
  * gst_query_parse_seeking:
  * @query: a GST_QUERY_SEEKING type query #GstQuery
- * @format: the format to set for the @segment_start and @segment_end values
- * @seekable: the seekable flag to set
- * @segment_start: the segment_start to set
- * @segment_end: the segment_end to set
+ * @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
  *
- * Parse a seeking query, writing the format into @format, and 
+ * Parse a seeking query, writing the format into @format, and
  * other results into the passed parameters, if the respective parameters
  * are non-NULL
  */
@@ -904,9 +912,10 @@ gst_query_parse_seeking (GstQuery * query, GstFormat * format,
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
 
-  structure = gst_query_get_structure (query);
+  structure = query->structure;
   if (format)
-    *format = g_value_get_enum (gst_structure_id_get_value (structure,
+    *format =
+        (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (FORMAT)));
   if (seekable)
     *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
@@ -923,9 +932,11 @@ gst_query_parse_seeking (GstQuery * query, GstFormat * format,
  * gst_query_new_formats:
  *
  * Constructs a new query object for querying formats of
- * the stream. 
+ * the stream.
  *
- * Returns: A #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a new #GstQuery
  *
  * Since: 0.10.4
  */
@@ -935,7 +946,7 @@ gst_query_new_formats (void)
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_new ("GstQueryFormats", NULL);
+  structure = gst_structure_id_empty_new (GST_QUARK (QUERY_FORMATS));
   query = gst_query_new (GST_QUERY_FORMATS, structure);
 
   return query;
@@ -966,7 +977,6 @@ gst_query_set_formats (GstQuery * query, gint n_formats, ...)
 {
   va_list ap;
   GValue list = { 0, };
-  GstStructure *structure;
   gint i;
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
@@ -979,8 +989,7 @@ gst_query_set_formats (GstQuery * query, gint n_formats, ...)
   }
   va_end (ap);
 
-  structure = gst_query_get_structure (query);
-  gst_structure_set_value (structure, "formats", &list);
+  gst_structure_set_value (query->structure, "formats", &list);
 
   g_value_unset (&list);
 
@@ -990,7 +999,8 @@ gst_query_set_formats (GstQuery * query, gint n_formats, ...)
  * gst_query_set_formatsv:
  * @query: a #GstQuery
  * @n_formats: the number of formats to set.
- * @formats: An array containing @n_formats @GstFormat values.
+ * @formats: (in) (array length=n_formats): an array containing @n_formats
+ *     @GstFormat values.
  *
  * Set the formats query result fields in @query. The number of formats passed
  * in the @formats array must be equal to @n_formats.
@@ -998,10 +1008,10 @@ gst_query_set_formats (GstQuery * query, gint n_formats, ...)
  * Since: 0.10.4
  */
 void
-gst_query_set_formatsv (GstQuery * query, gint n_formats, GstFormat * formats)
+gst_query_set_formatsv (GstQuery * query, gint n_formats,
+    const GstFormat * formats)
 {
   GValue list = { 0, };
-  GstStructure *structure;
   gint i;
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
@@ -1010,8 +1020,7 @@ gst_query_set_formatsv (GstQuery * query, gint n_formats, GstFormat * formats)
   for (i = 0; i < n_formats; i++) {
     gst_query_list_add_format (&list, formats[i]);
   }
-  structure = gst_query_get_structure (query);
-  gst_structure_set_value (structure, "formats", &list);
+  gst_structure_set_value (query->structure, "formats", &list);
 
   g_value_unset (&list);
 }
@@ -1019,24 +1028,21 @@ gst_query_set_formatsv (GstQuery * query, gint n_formats, GstFormat * formats)
 /**
  * gst_query_parse_formats_length:
  * @query: a #GstQuery
- * @n_formats: the number of formats in this query.
+ * @n_formats: (out): the number of formats in this query.
  *
- * Parse the number of formats in the formats @query. 
+ * Parse the number of formats in the formats @query.
  *
  * Since: 0.10.4
  */
 void
 gst_query_parse_formats_length (GstQuery * query, guint * n_formats)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
 
   if (n_formats) {
     const GValue *list;
 
-    structure = gst_query_get_structure (query);
-    list = gst_structure_get_value (structure, "formats");
+    list = gst_structure_get_value (query->structure, "formats");
     if (list == NULL)
       *n_formats = 0;
     else
@@ -1047,10 +1053,10 @@ gst_query_parse_formats_length (GstQuery * query, guint * n_formats)
 /**
  * gst_query_parse_formats_nth:
  * @query: a #GstQuery
- * @nth: the nth format to retrieve.
- * @format: a pointer to store the nth format
+ * @nth: (out): the nth format to retrieve.
+ * @format: (out): a pointer to store the nth format
  *
- * Parse the format query and retrieve the @nth format from it into 
+ * Parse the format query and retrieve the @nth format from it into
  * @format. If the list contains less elements than @nth, @format will be
  * set to GST_FORMAT_UNDEFINED.
  *
@@ -1059,20 +1065,18 @@ gst_query_parse_formats_length (GstQuery * query, guint * n_formats)
 void
 gst_query_parse_formats_nth (GstQuery * query, guint nth, GstFormat * format)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
 
   if (format) {
     const GValue *list;
 
-    structure = gst_query_get_structure (query);
-    list = gst_structure_get_value (structure, "formats");
+    list = gst_structure_get_value (query->structure, "formats");
     if (list == NULL) {
       *format = GST_FORMAT_UNDEFINED;
     } else {
       if (nth < gst_value_list_get_size (list)) {
-        *format = g_value_get_enum (gst_value_list_get_value (list, nth));
+        *format =
+            (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
       } else
         *format = GST_FORMAT_UNDEFINED;
     }
@@ -1086,7 +1090,9 @@ gst_query_parse_formats_nth (GstQuery * query, guint nth, GstFormat * format)
  * Constructs a new query object for querying the buffering status of
  * a stream.
  *
- * Returns: A #GstQuery
+ * Free-function: gst_query_new
+ *
+ * Returns: (transfer full): a new #GstQuery
  *
  * Since: 0.10.20
  */
@@ -1096,10 +1102,9 @@ gst_query_new_buffering (GstFormat format)
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_empty_new ("GstQueryBuffering");
   /* by default, we configure the answer as no buffering with a 100% buffering
    * progress */
-  gst_structure_id_set (structure,
+  structure = gst_structure_id_new (GST_QUARK (QUERY_BUFFERING),
       GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
@@ -1141,8 +1146,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: if buffering is busy
- * @percent: a buffering percent
+ * @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.
@@ -1166,7 +1171,7 @@ gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
 /**
  * gst_query_set_buffering_stats:
  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
- * @mode: a buffering mode 
+ * @mode: a buffering mode
  * @avg_in: the average input rate
  * @avg_out: the average output rate
  * @buffering_left: amount of buffering time left
@@ -1191,10 +1196,10 @@ gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
 /**
  * gst_query_parse_buffering_stats:
  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
- * @mode: a buffering mode 
- * @avg_in: the average input rate
- * @avg_out: the average output rate
- * @buffering_left: amount of buffering time left
+ * @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
  *
  * Extracts the buffering stats values from @query.
  *
@@ -1208,7 +1213,8 @@ gst_query_parse_buffering_stats (GstQuery * query,
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
 
   if (mode)
-    *mode = g_value_get_enum (gst_structure_id_get_value (query->structure,
+    *mode = (GstBufferingMode)
+        g_value_get_enum (gst_structure_id_get_value (query->structure,
             GST_QUARK (BUFFERING_MODE)));
   if (avg_in)
     *avg_in = g_value_get_int (gst_structure_id_get_value (query->structure,
@@ -1231,7 +1237,7 @@ gst_query_parse_buffering_stats (GstQuery * query,
  * @stop: the stop to set
  * @estimated_total: estimated total amount of download time
  *
- * Set the available query result fields in @query. 
+ * Set the available query result fields in @query.
  *
  * Since: 0.10.20
  */
@@ -1239,12 +1245,9 @@ void
 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
     gint64 start, gint64 stop, gint64 estimated_total)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
 
-  structure = gst_query_get_structure (query);
-  gst_structure_id_set (structure,
+  gst_structure_id_set (query->structure,
       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
       GST_QUARK (START_VALUE), G_TYPE_INT64, start,
       GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
@@ -1253,13 +1256,15 @@ gst_query_set_buffering_range (GstQuery * query, GstFormat format,
 
 /**
  * gst_query_parse_buffering_range:
- * @query: a GST_QUERY_SEEKING type query #GstQuery
- * @format: the format to set for the @segment_start and @segment_end values
- * @start: the start to set
- * @stop: the stop to set
- * @estimated_total: estimated total amount of download time
- *
- * Parse an available query, writing the format into @format, and 
+ * @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
+ * @estimated_total: (out) (allow-none): estimated total amount of download
+ *     time, 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
  *
@@ -1273,9 +1278,10 @@ gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
 
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
 
-  structure = gst_query_get_structure (query);
+  structure = query->structure;
   if (format)
-    *format = g_value_get_enum (gst_structure_id_get_value (structure,
+    *format =
+        (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
             GST_QUARK (FORMAT)));
   if (start)
     *start = g_value_get_int64 (gst_structure_id_get_value (structure,
@@ -1289,6 +1295,135 @@ gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
             GST_QUARK (ESTIMATED_TOTAL)));
 }
 
+/**
+ * gst_query_add_buffering_range
+ * @query: a GST_QUERY_BUFFERING type query #GstQuery
+ * @start: start position of the range
+ * @stop: stop position of the range
+ *
+ * Set the buffering-ranges array field in @query. The current last
+ * 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)
+{
+  GValueArray *array;
+  GValue *last_array_value;
+  const GValue *value;
+  GValue range_value = { 0 };
+
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
+
+  if (G_UNLIKELY (start >= stop))
+    return FALSE;
+
+  value =
+      gst_structure_id_get_value (query->structure,
+      GST_QUARK (BUFFERING_RANGES));
+  if (value) {
+    array = (GValueArray *) g_value_get_boxed (value);
+    last_array_value = g_value_array_get_nth (array, array->n_values - 1);
+    if (G_UNLIKELY (start <= gst_value_get_int64_range_min (last_array_value)))
+      return FALSE;
+  } else {
+    GValue new_array_val = { 0, };
+
+    array = g_value_array_new (0);
+
+    g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
+    g_value_take_boxed (&new_array_val, array);
+
+    /* set the value array only once, so we then modify (append to) the
+     * existing value array owned by the GstStructure / the field's GValue */
+    gst_structure_id_take_value (query->structure, GST_QUARK (BUFFERING_RANGES),
+        &new_array_val);
+  }
+
+  g_value_init (&range_value, GST_TYPE_INT64_RANGE);
+  gst_value_set_int64_range (&range_value, start, stop);
+  g_value_array_append (array, &range_value);
+  /* skip the g_value_unset(&range_value) here, we know it's not needed */
+
+  return TRUE;
+}
+
+/**
+ * gst_query_get_n_buffering_ranges
+ * @query: a GST_QUERY_BUFFERING type query #GstQuery
+ *
+ * Retrieve the number of values currently stored in the
+ * 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)
+{
+  GValueArray *array;
+  const GValue *value;
+  guint size = 0;
+
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
+
+  value =
+      gst_structure_id_get_value (query->structure,
+      GST_QUARK (BUFFERING_RANGES));
+  if (value) {
+    array = (GValueArray *) g_value_get_boxed (value);
+    size = array->n_values;
+  }
+  return size;
+}
+
+
+/**
+ * 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
+ *
+ * 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,
+    gint64 * start, gint64 * stop)
+{
+  const GValue *value;
+  GValueArray *ranges;
+  GValue *range_value;
+  gboolean ret = FALSE;
+
+  g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
+
+  value =
+      gst_structure_id_get_value (query->structure,
+      GST_QUARK (BUFFERING_RANGES));
+  ranges = (GValueArray *) g_value_get_boxed (value);
+  range_value = g_value_array_get_nth (ranges, index);
+  if (range_value) {
+    if (start)
+      *start = gst_value_get_int64_range_min (range_value);
+    if (stop)
+      *stop = gst_value_get_int64_range_max (range_value);
+    ret = TRUE;
+  }
+
+  return ret;
+}
+
+
 /**
  * gst_query_new_uri:
  *
@@ -1296,7 +1431,9 @@ gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
  * when done with it. An URI query is used to query the current URI
  * that is used by the source or sink.
  *
- * Returns: A #GstQuery
+ * Free-function: gst_query_unref
+ *
+ * Returns: (transfer full): a new #GstQuery
  *
  * Since: 0.10.22
  */
@@ -1306,8 +1443,8 @@ gst_query_new_uri (void)
   GstQuery *query;
   GstStructure *structure;
 
-  structure = gst_structure_empty_new ("GstQueryURI");
-  gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
+  structure = gst_structure_id_new (GST_QUARK (QUERY_URI),
+      GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
 
   query = gst_query_new (GST_QUERY_URI, structure);
 
@@ -1326,19 +1463,18 @@ gst_query_new_uri (void)
 void
 gst_query_set_uri (GstQuery * query, const gchar * uri)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
   g_return_if_fail (gst_uri_is_valid (uri));
 
-  structure = gst_query_get_structure (query);
-  gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
+  gst_structure_id_set (query->structure, GST_QUARK (URI), G_TYPE_STRING, uri,
+      NULL);
 }
 
 /**
  * gst_query_parse_uri:
  * @query: a #GstQuery
- * @uri: the storage for the current URI (may be NULL)
+ * @uri: (out callee-allocates) (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.
@@ -1349,12 +1485,149 @@ gst_query_set_uri (GstQuery * query, const gchar * uri)
 void
 gst_query_parse_uri (GstQuery * query, gchar ** uri)
 {
-  GstStructure *structure;
-
   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
 
-  structure = gst_query_get_structure (query);
   if (uri)
-    *uri = g_value_dup_string (gst_structure_id_get_value (structure,
+    *uri = g_value_dup_string (gst_structure_id_get_value (query->structure,
             GST_QUARK (URI)));
 }
+
+/**
+ * gst_query_new_buffers:
+ * @caps: the #GstCaps for the buffers that are going to be allocated
+ *
+ * Constructs a new buffer requirements query object to query buffer
+ * requirements for a particular caps.  Use gst_query_unref() when done
+ * with it.
+ *
+ * Returns: A #GstQuery
+ */
+GstQuery *
+gst_query_new_buffers (GstCaps * caps)
+{
+  GstQuery *query;
+  GstStructure *structure;
+
+  /* XXX could add size here, for linear (non YUV/RGB) buffers?  But I'm not
+   * entirely sure what is the use-case for that.. it should be easy enough
+   * to add more optional reply fields later
+   */
+  structure = gst_structure_id_new (GST_QUARK (QUERY_BUFFERS),
+      GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
+      GST_QUARK (COUNT), G_TYPE_INT, -1,
+      GST_QUARK (WIDTH), G_TYPE_INT, -1,
+      GST_QUARK (HEIGHT), G_TYPE_INT, -1, NULL);
+
+  query = gst_query_new (GST_QUERY_BUFFERS, structure);
+
+  return query;
+}
+
+/**
+ * gst_query_set_buffers_count:
+ * @count: minimum number of buffers required
+ *
+ * Answer a buffers query by setting the minimum number of buffers required.
+ * If there is no minimum buffer count requirement, don't set this field in
+ * the query.
+ */
+void
+gst_query_set_buffers_count (GstQuery * query, gint count)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERS);
+
+  structure = gst_query_get_structure (query);
+  gst_structure_id_set (structure, GST_QUARK (COUNT), G_TYPE_INT, count, NULL);
+}
+
+/**
+ * gst_query_set_buffers_dimensions:
+ * @width: minimum buffer width
+ * @height: minimum buffer height
+ *
+ * Answer a buffers query by setting the minimum buffer dimensions required.
+ * If there is no minimum buffer dimensions (beyond the width/height specified
+ * in the #GstCaps), don't set this field in the query.
+ */
+void
+gst_query_set_buffers_dimensions (GstQuery * query, gint width, gint height)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERS);
+
+  structure = gst_query_get_structure (query);
+  gst_structure_id_set (structure,
+      GST_QUARK (WIDTH), G_TYPE_INT, width,
+      GST_QUARK (HEIGHT), G_TYPE_INT, height, NULL);
+}
+
+/**
+ * gst_query_parse_buffers_caps:
+ * @query: a #GstQuery
+ * @caps: the storage for the #GstCaps pointer, or NULL
+ *
+ * Parse a buffers query.
+ */
+void
+gst_query_parse_buffers_caps (GstQuery * query, const GstCaps ** caps)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERS);
+
+  structure = gst_query_get_structure (query);
+  if (caps)
+    *caps = gst_value_get_caps (gst_structure_id_get_value (structure,
+            GST_QUARK (CAPS)));
+}
+
+/**
+ * gst_query_parse_buffers_count:
+ * @query: a #GstQuery
+ * @count: the storage for minimum number of buffers, or NULL
+ *
+ * Parse a buffers query answer to see the minimum number of buffers
+ * required.  A returned value of -1 means there is no minimum requirement
+ */
+void
+gst_query_parse_buffers_count (GstQuery * query, gint * count)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERS);
+
+  structure = gst_query_get_structure (query);
+  if (count)
+    *count = g_value_get_int (gst_structure_id_get_value (structure,
+            GST_QUARK (COUNT)));
+}
+
+/**
+ * gst_query_parse_buffers_dimensions:
+ * @query: a #GstQuery
+ * @width: the storage for minimum width, or NULL
+ * @height: the storage for minimum height, or NULL
+ *
+ * Parse a buffers query answer to see the minimum buffer dimensions required.
+ * A returned value of -1 for either dimension means there is no minimum
+ * requirement in that axis
+ */
+void
+gst_query_parse_buffers_dimensions (GstQuery * query, gint * width,
+    gint * height)
+{
+  GstStructure *structure;
+
+  g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERS);
+
+  structure = gst_query_get_structure (query);
+  if (width)
+    *width = g_value_get_int (gst_structure_id_get_value (structure,
+            GST_QUARK (WIDTH)));
+  if (height)
+    *height = g_value_get_int (gst_structure_id_get_value (structure,
+            GST_QUARK (HEIGHT)));
+}