]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gstreamer0-10.git/blob - gst/gstquery.c
g_thread_create() is deprecated in GLib master, use g_thread_try_new() instead
[glsdk/gstreamer0-10.git] / gst / gstquery.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *                    2005 Wim Taymans <wim@fluendo.com>
5  *
6  * gstquery.c: GstQueryType registration and Query parsing/creation
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
24 /**
25  * SECTION:gstquery
26  * @short_description: Dynamically register new query types. Provide functions
27  *                     to create queries, and to set and parse values in them.
28  * @see_also: #GstPad, #GstElement
29  *
30  * GstQuery functions are used to register new query types to the gstreamer
31  * core and use them.
32  * Queries can be performed on pads (gst_pad_query()) and elements
33  * (gst_element_query()). Please note that some queries might need a running
34  * pipeline to work.
35  *
36  * Queries can be created using the gst_query_new_*() functions.
37  * Query values can be set using gst_query_set_*(), and parsed using
38  * gst_query_parse_*() helpers.
39  *
40  * The following example shows how to query the duration of a pipeline:
41  *
42  * <example>
43  *  <title>Query duration on a pipeline</title>
44  *  <programlisting>
45  *  GstQuery *query;
46  *  gboolean res;
47  *  query = gst_query_new_duration (GST_FORMAT_TIME);
48  *  res = gst_element_query (pipeline, query);
49  *  if (res) {
50  *    gint64 duration;
51  *    gst_query_parse_duration (query, NULL, &amp;duration);
52  *    g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
53  *  }
54  *  else {
55  *    g_print ("duration query failed...");
56  *  }
57  *  gst_query_unref (query);
58  *  </programlisting>
59  * </example>
60  *
61  * Last reviewed on 2006-02-14 (0.10.4)
62  */
64 #include "gst_private.h"
65 #include "gstinfo.h"
66 #include "gstquery.h"
67 #include "gstvalue.h"
68 #include "gstenumtypes.h"
69 #include "gstquark.h"
70 #include "gsturi.h"
72 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
73 #define GST_CAT_DEFAULT gst_query_debug
75 static void gst_query_finalize (GstQuery * query);
76 static GstQuery *_gst_query_copy (GstQuery * query);
78 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
79 static GList *_gst_queries = NULL;
80 static GHashTable *_nick_to_query = NULL;
81 static GHashTable *_query_type_to_nick = NULL;
82 static guint32 _n_values = 1;   /* we start from 1 because 0 reserved for NONE */
84 static GstMiniObjectClass *parent_class = NULL;
86 static GstQueryTypeDefinition standard_definitions[] = {
87   {GST_QUERY_POSITION, "position", "Current position", 0},
88   {GST_QUERY_DURATION, "duration", "Total duration", 0},
89   {GST_QUERY_LATENCY, "latency", "Latency", 0},
90   {GST_QUERY_JITTER, "jitter", "Jitter", 0},
91   {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
92   {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
93   {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
94   {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
95   {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
96   {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
97   {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
98   {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
99   {GST_QUERY_NONE, NULL, NULL, 0}
100 };
102 void
103 _gst_query_initialize (void)
105   GstQueryTypeDefinition *standards = standard_definitions;
107   GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
109   GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
111   g_static_mutex_lock (&mutex);
112   if (_nick_to_query == NULL) {
113     _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
114     _query_type_to_nick = g_hash_table_new (NULL, NULL);
115   }
117   while (standards->nick) {
118     standards->quark = g_quark_from_static_string (standards->nick);
119     g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
120     g_hash_table_insert (_query_type_to_nick,
121         GINT_TO_POINTER (standards->value), standards);
123     _gst_queries = g_list_append (_gst_queries, standards);
124     standards++;
125     _n_values++;
126   }
127   g_static_mutex_unlock (&mutex);
129   g_type_class_ref (gst_query_get_type ());
132 /**
133  * gst_query_type_get_name:
134  * @query: the query type
135  *
136  * Get a printable name for the given query type. Do not modify or free.
137  *
138  * Returns: a reference to the static name of the query.
139  */
140 const gchar *
141 gst_query_type_get_name (GstQueryType query)
143   const GstQueryTypeDefinition *def;
145   def = gst_query_type_get_details (query);
147   return def->nick;
150 /**
151  * gst_query_type_to_quark:
152  * @query: the query type
153  *
154  * Get the unique quark for the given query type.
155  *
156  * Returns: the quark associated with the query type
157  */
158 GQuark
159 gst_query_type_to_quark (GstQueryType query)
161   const GstQueryTypeDefinition *def;
163   def = gst_query_type_get_details (query);
165   return def->quark;
168 G_DEFINE_TYPE (GstQuery, gst_query, GST_TYPE_MINI_OBJECT);
170 static void
171 gst_query_class_init (GstQueryClass * klass)
173   parent_class = g_type_class_peek_parent (klass);
175   klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
176   klass->mini_object_class.finalize =
177       (GstMiniObjectFinalizeFunction) gst_query_finalize;
181 static void
182 gst_query_init (GstQuery * query)
186 static void
187 gst_query_finalize (GstQuery * query)
189   g_return_if_fail (query != NULL);
191   if (query->structure) {
192     gst_structure_set_parent_refcount (query->structure, NULL);
193     gst_structure_free (query->structure);
194   }
196 /*   GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (query)); */
199 static GstQuery *
200 _gst_query_copy (GstQuery * query)
202   GstQuery *copy;
204   copy = (GstQuery *) gst_mini_object_new (GST_TYPE_QUERY);
206   copy->type = query->type;
208   if (query->structure) {
209     copy->structure = gst_structure_copy (query->structure);
210     gst_structure_set_parent_refcount (copy->structure,
211         &query->mini_object.refcount);
212   }
214   return copy;
219 /**
220  * gst_query_type_register:
221  * @nick: The nick of the new query
222  * @description: The description of the new query
223  *
224  * Create a new GstQueryType based on the nick or return an
225  * already registered query with that nick
226  *
227  * Returns: A new GstQueryType or an already registered query
228  * with the same nick.
229  */
230 GstQueryType
231 gst_query_type_register (const gchar * nick, const gchar * description)
233   GstQueryTypeDefinition *query;
234   GstQueryType lookup;
236   g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
237   g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
239   lookup = gst_query_type_get_by_nick (nick);
240   if (lookup != GST_QUERY_NONE)
241     return lookup;
243   query = g_slice_new (GstQueryTypeDefinition);
244   query->value = (GstQueryType) _n_values;
245   query->nick = g_strdup (nick);
246   query->description = g_strdup (description);
247   query->quark = g_quark_from_static_string (query->nick);
249   g_static_mutex_lock (&mutex);
250   g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
251   g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
252       query);
253   _gst_queries = g_list_append (_gst_queries, query);
254   _n_values++;
255   g_static_mutex_unlock (&mutex);
257   return query->value;
260 /**
261  * gst_query_type_get_by_nick:
262  * @nick: The nick of the query
263  *
264  * Get the query type registered with @nick.
265  *
266  * Returns: The query registered with @nick or #GST_QUERY_NONE
267  * if the query was not registered.
268  */
269 GstQueryType
270 gst_query_type_get_by_nick (const gchar * nick)
272   GstQueryTypeDefinition *query;
274   g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
276   g_static_mutex_lock (&mutex);
277   query = g_hash_table_lookup (_nick_to_query, nick);
278   g_static_mutex_unlock (&mutex);
280   if (query != NULL)
281     return query->value;
282   else
283     return GST_QUERY_NONE;
286 /**
287  * gst_query_types_contains:
288  * @types: The query array to search
289  * @type: the #GstQueryType to find
290  *
291  * See if the given #GstQueryType is inside the @types query types array.
292  *
293  * Returns: TRUE if the type is found inside the array
294  */
295 gboolean
296 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
298   if (!types)
299     return FALSE;
301   while (*types) {
302     if (*types == type)
303       return TRUE;
305     types++;
306   }
307   return FALSE;
311 /**
312  * gst_query_type_get_details:
313  * @type: a #GstQueryType
314  *
315  * Get details about the given #GstQueryType.
316  *
317  * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
318  */
319 const GstQueryTypeDefinition *
320 gst_query_type_get_details (GstQueryType type)
322   const GstQueryTypeDefinition *result;
324   g_static_mutex_lock (&mutex);
325   result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
326   g_static_mutex_unlock (&mutex);
328   return result;
331 /**
332  * gst_query_type_iterate_definitions:
333  *
334  * Get a #GstIterator of all the registered query types. The definitions
335  * iterated over are read only.
336  *
337  * Free-function: gst_iterator_free
338  *
339  * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
340  */
341 GstIterator *
342 gst_query_type_iterate_definitions (void)
344   GstIterator *result;
346   g_static_mutex_lock (&mutex);
347   /* FIXME: register a boxed type for GstQueryTypeDefinition */
348   result = gst_iterator_new_list (G_TYPE_POINTER,
349       g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries,
350       NULL, NULL, NULL);
351   g_static_mutex_unlock (&mutex);
353   return result;
356 static GstQuery *
357 gst_query_new (GstQueryType type, GstStructure * structure)
359   GstQuery *query;
361   query = (GstQuery *) gst_mini_object_new (GST_TYPE_QUERY);
363   GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
365   query->type = type;
367   if (structure) {
368     query->structure = structure;
369     gst_structure_set_parent_refcount (query->structure,
370         &query->mini_object.refcount);
371   } else {
372     query->structure = NULL;
373   }
375   return query;
378 /**
379  * gst_query_new_position:
380  * @format: the default #GstFormat for the new query
381  *
382  * Constructs a new query stream position query object. Use gst_query_unref()
383  * when done with it. A position query is used to query the current position
384  * of playback in the streams, in some format.
385  *
386  * Free-function: gst_query_unref
387  *
388  * Returns: (transfer full): a new #GstQuery
389  */
390 GstQuery *
391 gst_query_new_position (GstFormat format)
393   GstQuery *query;
394   GstStructure *structure;
396   structure = gst_structure_id_new (GST_QUARK (QUERY_POSITION),
397       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
398       GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
400   query = gst_query_new (GST_QUERY_POSITION, structure);
402   return query;
405 /**
406  * gst_query_set_position:
407  * @query: a #GstQuery with query type GST_QUERY_POSITION
408  * @format: the requested #GstFormat
409  * @cur: the position to set
410  *
411  * Answer a position query by setting the requested value in the given format.
412  */
413 void
414 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
416   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
418   gst_structure_id_set (query->structure,
419       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
420       GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
423 /**
424  * gst_query_parse_position:
425  * @query: a #GstQuery
426  * @format: (out) (allow-none): the storage for the #GstFormat of the
427  *     position values (may be NULL)
428  * @cur: (out) (allow-none): the storage for the current position (may be NULL)
429  *
430  * Parse a position query, writing the format into @format, and the position
431  * into @cur, if the respective parameters are non-NULL.
432  */
433 void
434 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
436   GstStructure *structure;
438   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
440   structure = query->structure;
441   if (format)
442     *format =
443         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
444             GST_QUARK (FORMAT)));
445   if (cur)
446     *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
447             GST_QUARK (CURRENT)));
451 /**
452  * gst_query_new_duration:
453  * @format: the #GstFormat for this duration query
454  *
455  * Constructs a new stream duration query object to query in the given format.
456  * Use gst_query_unref() when done with it. A duration query will give the
457  * total length of the stream.
458  *
459  * Free-function: gst_query_unref
460  *
461  * Returns: (transfer full): a new #GstQuery
462  */
463 GstQuery *
464 gst_query_new_duration (GstFormat format)
466   GstQuery *query;
467   GstStructure *structure;
469   structure = gst_structure_id_new (GST_QUARK (QUERY_DURATION),
470       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
471       GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
473   query = gst_query_new (GST_QUERY_DURATION, structure);
475   return query;
478 /**
479  * gst_query_set_duration:
480  * @query: a #GstQuery
481  * @format: the #GstFormat for the duration
482  * @duration: the duration of the stream
483  *
484  * Answer a duration query by setting the requested value in the given format.
485  */
486 void
487 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
489   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
491   gst_structure_id_set (query->structure,
492       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
493       GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
496 /**
497  * gst_query_parse_duration:
498  * @query: a #GstQuery
499  * @format: (out) (allow-none): the storage for the #GstFormat of the duration
500  *     value, or NULL.
501  * @duration: (out) (allow-none): the storage for the total duration, or NULL.
502  *
503  * Parse a duration query answer. Write the format of the duration into @format,
504  * and the value into @duration, if the respective variables are non-NULL.
505  */
506 void
507 gst_query_parse_duration (GstQuery * query, GstFormat * format,
508     gint64 * duration)
510   GstStructure *structure;
512   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
514   structure = query->structure;
515   if (format)
516     *format =
517         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
518             GST_QUARK (FORMAT)));
519   if (duration)
520     *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
521             GST_QUARK (DURATION)));
524 /**
525  * gst_query_new_latency:
526  *
527  * Constructs a new latency query object.
528  * Use gst_query_unref() when done with it. A latency query is usually performed
529  * by sinks to compensate for additional latency introduced by elements in the
530  * pipeline.
531  *
532  * Free-function: gst_query_unref
533  *
534  * Returns: (transfer full): a #GstQuery
535  *
536  * Since: 0.10.12
537  */
538 GstQuery *
539 gst_query_new_latency (void)
541   GstQuery *query;
542   GstStructure *structure;
544   structure = gst_structure_id_new (GST_QUARK (QUERY_LATENCY),
545       GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
546       GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
547       GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
549   query = gst_query_new (GST_QUERY_LATENCY, structure);
551   return query;
554 /**
555  * gst_query_set_latency:
556  * @query: a #GstQuery
557  * @live: if there is a live element upstream
558  * @min_latency: the minimal latency of the live element
559  * @max_latency: the maximal latency of the live element
560  *
561  * Answer a latency query by setting the requested values in the given format.
562  *
563  * Since: 0.10.12
564  */
565 void
566 gst_query_set_latency (GstQuery * query, gboolean live,
567     GstClockTime min_latency, GstClockTime max_latency)
569   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
571   gst_structure_id_set (query->structure,
572       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
573       GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
574       GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
577 /**
578  * gst_query_parse_latency:
579  * @query: a #GstQuery
580  * @live: (out) (allow-none): storage for live or NULL
581  * @min_latency: (out) (allow-none): the storage for the min latency or NULL
582  * @max_latency: (out) (allow-none): the storage for the max latency or NULL
583  *
584  * Parse a latency query answer.
585  *
586  * Since: 0.10.12
587  */
588 void
589 gst_query_parse_latency (GstQuery * query, gboolean * live,
590     GstClockTime * min_latency, GstClockTime * max_latency)
592   GstStructure *structure;
594   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
596   structure = query->structure;
597   if (live)
598     *live =
599         g_value_get_boolean (gst_structure_id_get_value (structure,
600             GST_QUARK (LIVE)));
601   if (min_latency)
602     *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
603             GST_QUARK (MIN_LATENCY)));
604   if (max_latency)
605     *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
606             GST_QUARK (MAX_LATENCY)));
609 /**
610  * gst_query_new_convert:
611  * @src_format: the source #GstFormat for the new query
612  * @value: the value to convert
613  * @dest_format: the target #GstFormat
614  *
615  * Constructs a new convert query object. Use gst_query_unref()
616  * when done with it. A convert query is used to ask for a conversion between
617  * one format and another.
618  *
619  * Free-function: gst_query_unref
620  *
621  * Returns: (transfer full): a #GstQuery
622  */
623 GstQuery *
624 gst_query_new_convert (GstFormat src_format, gint64 value,
625     GstFormat dest_format)
627   GstQuery *query;
628   GstStructure *structure;
630   structure = gst_structure_id_new (GST_QUARK (QUERY_CONVERT),
631       GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
632       GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
633       GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
634       GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
636   query = gst_query_new (GST_QUERY_CONVERT, structure);
638   return query;
641 /**
642  * gst_query_set_convert:
643  * @query: a #GstQuery
644  * @src_format: the source #GstFormat
645  * @src_value: the source value
646  * @dest_format: the destination #GstFormat
647  * @dest_value: the destination value
648  *
649  * Answer a convert query by setting the requested values.
650  */
651 void
652 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
653     GstFormat dest_format, gint64 dest_value)
655   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
657   gst_structure_id_set (query->structure,
658       GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
659       GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
660       GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
661       GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
664 /**
665  * gst_query_parse_convert:
666  * @query: a #GstQuery
667  * @src_format: (out) (allow-none): the storage for the #GstFormat of the
668  *     source value, or NULL
669  * @src_value: (out) (allow-none): the storage for the source value, or NULL
670  * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
671  *     destination value, or NULL
672  * @dest_value: (out) (allow-none): the storage for the destination value,
673  *     or NULL
674  *
675  * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
676  * and @dest_value may be NULL, in which case that value is omitted.
677  */
678 void
679 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
680     gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
682   GstStructure *structure;
684   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
686   structure = query->structure;
687   if (src_format)
688     *src_format =
689         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
690             GST_QUARK (SRC_FORMAT)));
691   if (src_value)
692     *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
693             GST_QUARK (SRC_VALUE)));
694   if (dest_format)
695     *dest_format =
696         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
697             GST_QUARK (DEST_FORMAT)));
698   if (dest_value)
699     *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
700             GST_QUARK (DEST_VALUE)));
703 /**
704  * gst_query_new_segment:
705  * @format: the #GstFormat for the new query
706  *
707  * Constructs a new segment query object. Use gst_query_unref()
708  * when done with it. A segment query is used to discover information about the
709  * currently configured segment for playback.
710  *
711  * Free-function: gst_query_unref
712  *
713  * Returns: (transfer full): a new #GstQuery
714  */
715 GstQuery *
716 gst_query_new_segment (GstFormat format)
718   GstQuery *query;
719   GstStructure *structure;
721   structure = gst_structure_id_new (GST_QUARK (QUERY_SEGMENT),
722       GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
723       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
724       GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
725       GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
727   query = gst_query_new (GST_QUERY_SEGMENT, structure);
729   return query;
732 /**
733  * gst_query_set_segment:
734  * @query: a #GstQuery
735  * @rate: the rate of the segment
736  * @format: the #GstFormat of the segment values (@start_value and @stop_value)
737  * @start_value: the start value
738  * @stop_value: the stop value
739  *
740  * Answer a segment query by setting the requested values. The normal
741  * playback segment of a pipeline is 0 to duration at the default rate of
742  * 1.0. If a seek was performed on the pipeline to play a different
743  * segment, this query will return the range specified in the last seek.
744  *
745  * @start_value and @stop_value will respectively contain the configured
746  * playback range start and stop values expressed in @format.
747  * The values are always between 0 and the duration of the media and
748  * @start_value <= @stop_value. @rate will contain the playback rate. For
749  * negative rates, playback will actually happen from @stop_value to
750  * @start_value.
751  */
752 void
753 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
754     gint64 start_value, gint64 stop_value)
756   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
758   gst_structure_id_set (query->structure,
759       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
760       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
761       GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
762       GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
765 /**
766  * gst_query_parse_segment:
767  * @query: a #GstQuery
768  * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
769  * @format: (out) (allow-none): the storage for the #GstFormat of the values,
770  *     or NULL
771  * @start_value: (out) (allow-none): the storage for the start value, or NULL
772  * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
773  *
774  * Parse a segment query answer. Any of @rate, @format, @start_value, and
775  * @stop_value may be NULL, which will cause this value to be omitted.
776  *
777  * See gst_query_set_segment() for an explanation of the function arguments.
778  */
779 void
780 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
781     gint64 * start_value, gint64 * stop_value)
783   GstStructure *structure;
785   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
787   structure = query->structure;
788   if (rate)
789     *rate = g_value_get_double (gst_structure_id_get_value (structure,
790             GST_QUARK (RATE)));
791   if (format)
792     *format =
793         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
794             GST_QUARK (FORMAT)));
795   if (start_value)
796     *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
797             GST_QUARK (START_VALUE)));
798   if (stop_value)
799     *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
800             GST_QUARK (STOP_VALUE)));
803 /**
804  * gst_query_new_application:
805  * @type: the query type
806  * @structure: a structure for the query
807  *
808  * Constructs a new custom application query object. Use gst_query_unref()
809  * when done with it.
810  *
811  * Free-function: gst_query_unref
812  *
813  * Returns: (transfer full): a new #GstQuery
814  */
815 GstQuery *
816 gst_query_new_application (GstQueryType type, GstStructure * structure)
818   g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
819   g_return_val_if_fail (structure != NULL, NULL);
821   return gst_query_new (type, structure);
824 /**
825  * gst_query_get_structure:
826  * @query: a #GstQuery
827  *
828  * Get the structure of a query.
829  *
830  * Returns: (transfer none): the #GstStructure of the query. The structure is
831  *     still owned by the query and will therefore be freed when the query
832  *     is unreffed.
833  */
834 GstStructure *
835 gst_query_get_structure (GstQuery * query)
837   g_return_val_if_fail (GST_IS_QUERY (query), NULL);
839   return query->structure;
842 /**
843  * gst_query_new_seeking:
844  * @format: the default #GstFormat for the new query
845  *
846  * Constructs a new query object for querying seeking properties of
847  * the stream.
848  *
849  * Free-function: gst_query_unref
850  *
851  * Returns: (transfer full): a new #GstQuery
852  */
853 GstQuery *
854 gst_query_new_seeking (GstFormat format)
856   GstQuery *query;
857   GstStructure *structure;
859   structure = gst_structure_id_new (GST_QUARK (QUERY_SEEKING),
860       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
861       GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
862       GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
863       GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
865   query = gst_query_new (GST_QUERY_SEEKING, structure);
867   return query;
870 /**
871  * gst_query_set_seeking:
872  * @query: a #GstQuery
873  * @format: the format to set for the @segment_start and @segment_end values
874  * @seekable: the seekable flag to set
875  * @segment_start: the segment_start to set
876  * @segment_end: the segment_end to set
877  *
878  * Set the seeking query result fields in @query.
879  */
880 void
881 gst_query_set_seeking (GstQuery * query, GstFormat format,
882     gboolean seekable, gint64 segment_start, gint64 segment_end)
884   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
886   gst_structure_id_set (query->structure,
887       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
888       GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
889       GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
890       GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
893 /**
894  * gst_query_parse_seeking:
895  * @query: a GST_QUERY_SEEKING type query #GstQuery
896  * @format: (out) (allow-none): the format to set for the @segment_start
897  *     and @segment_end values, or NULL
898  * @seekable: (out) (allow-none): the seekable flag to set, or NULL
899  * @segment_start: (out) (allow-none): the segment_start to set, or NULL
900  * @segment_end: (out) (allow-none): the segment_end to set, or NULL
901  *
902  * Parse a seeking query, writing the format into @format, and
903  * other results into the passed parameters, if the respective parameters
904  * are non-NULL
905  */
906 void
907 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
908     gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
910   GstStructure *structure;
912   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
914   structure = query->structure;
915   if (format)
916     *format =
917         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
918             GST_QUARK (FORMAT)));
919   if (seekable)
920     *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
921             GST_QUARK (SEEKABLE)));
922   if (segment_start)
923     *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
924             GST_QUARK (SEGMENT_START)));
925   if (segment_end)
926     *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
927             GST_QUARK (SEGMENT_END)));
930 /**
931  * gst_query_new_formats:
932  *
933  * Constructs a new query object for querying formats of
934  * the stream.
935  *
936  * Free-function: gst_query_unref
937  *
938  * Returns: (transfer full): a new #GstQuery
939  *
940  * Since: 0.10.4
941  */
942 GstQuery *
943 gst_query_new_formats (void)
945   GstQuery *query;
946   GstStructure *structure;
948   structure = gst_structure_id_empty_new (GST_QUARK (QUERY_FORMATS));
949   query = gst_query_new (GST_QUERY_FORMATS, structure);
951   return query;
954 static void
955 gst_query_list_add_format (GValue * list, GstFormat format)
957   GValue item = { 0, };
959   g_value_init (&item, GST_TYPE_FORMAT);
960   g_value_set_enum (&item, format);
961   gst_value_list_append_value (list, &item);
962   g_value_unset (&item);
965 /**
966  * gst_query_set_formats:
967  * @query: a #GstQuery
968  * @n_formats: the number of formats to set.
969  * @...: A number of @GstFormats equal to @n_formats.
970  *
971  * Set the formats query result fields in @query. The number of formats passed
972  * must be equal to @n_formats.
973  */
974 void
975 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
977   va_list ap;
978   GValue list = { 0, };
979   gint i;
981   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
983   g_value_init (&list, GST_TYPE_LIST);
985   va_start (ap, n_formats);
986   for (i = 0; i < n_formats; i++) {
987     gst_query_list_add_format (&list, va_arg (ap, GstFormat));
988   }
989   va_end (ap);
991   gst_structure_set_value (query->structure, "formats", &list);
993   g_value_unset (&list);
997 /**
998  * gst_query_set_formatsv:
999  * @query: a #GstQuery
1000  * @n_formats: the number of formats to set.
1001  * @formats: (in) (array length=n_formats): an array containing @n_formats
1002  *     @GstFormat values.
1003  *
1004  * Set the formats query result fields in @query. The number of formats passed
1005  * in the @formats array must be equal to @n_formats.
1006  *
1007  * Since: 0.10.4
1008  */
1009 void
1010 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1011     const GstFormat * formats)
1013   GValue list = { 0, };
1014   gint i;
1016   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1018   g_value_init (&list, GST_TYPE_LIST);
1019   for (i = 0; i < n_formats; i++) {
1020     gst_query_list_add_format (&list, formats[i]);
1021   }
1022   gst_structure_set_value (query->structure, "formats", &list);
1024   g_value_unset (&list);
1027 /**
1028  * gst_query_parse_formats_length:
1029  * @query: a #GstQuery
1030  * @n_formats: (out): the number of formats in this query.
1031  *
1032  * Parse the number of formats in the formats @query.
1033  *
1034  * Since: 0.10.4
1035  */
1036 void
1037 gst_query_parse_formats_length (GstQuery * query, guint * n_formats)
1039   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1041   if (n_formats) {
1042     const GValue *list;
1044     list = gst_structure_get_value (query->structure, "formats");
1045     if (list == NULL)
1046       *n_formats = 0;
1047     else
1048       *n_formats = gst_value_list_get_size (list);
1049   }
1052 /**
1053  * gst_query_parse_formats_nth:
1054  * @query: a #GstQuery
1055  * @nth: (out): the nth format to retrieve.
1056  * @format: (out): a pointer to store the nth format
1057  *
1058  * Parse the format query and retrieve the @nth format from it into
1059  * @format. If the list contains less elements than @nth, @format will be
1060  * set to GST_FORMAT_UNDEFINED.
1061  *
1062  * Since: 0.10.4
1063  */
1064 void
1065 gst_query_parse_formats_nth (GstQuery * query, guint nth, GstFormat * format)
1067   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1069   if (format) {
1070     const GValue *list;
1072     list = gst_structure_get_value (query->structure, "formats");
1073     if (list == NULL) {
1074       *format = GST_FORMAT_UNDEFINED;
1075     } else {
1076       if (nth < gst_value_list_get_size (list)) {
1077         *format =
1078             (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1079       } else
1080         *format = GST_FORMAT_UNDEFINED;
1081     }
1082   }
1085 /**
1086  * gst_query_new_buffering
1087  * @format: the default #GstFormat for the new query
1088  *
1089  * Constructs a new query object for querying the buffering status of
1090  * a stream.
1091  *
1092  * Free-function: gst_query_new
1093  *
1094  * Returns: (transfer full): a new #GstQuery
1095  *
1096  * Since: 0.10.20
1097  */
1098 GstQuery *
1099 gst_query_new_buffering (GstFormat format)
1101   GstQuery *query;
1102   GstStructure *structure;
1104   /* by default, we configure the answer as no buffering with a 100% buffering
1105    * progress */
1106   structure = gst_structure_id_new (GST_QUARK (QUERY_BUFFERING),
1107       GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1108       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1109       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1110       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1111       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1112       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1113       GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1114       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1115       GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1116       GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1118   query = gst_query_new (GST_QUERY_BUFFERING, structure);
1120   return query;
1123 /**
1124  * gst_query_set_buffering_percent
1125  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1126  * @busy: if buffering is busy
1127  * @percent: a buffering percent
1128  *
1129  * Set the percentage of buffered data. This is a value between 0 and 100.
1130  * The @busy indicator is %TRUE when the buffering is in progress.
1131  *
1132  * Since: 0.10.20
1133  */
1134 void
1135 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1137   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1138   g_return_if_fail (percent >= 0 && percent <= 100);
1140   gst_structure_id_set (query->structure,
1141       GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1142       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1145 /**
1146  * gst_query_parse_buffering_percent
1147  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1148  * @busy: (out) (allow-none): if buffering is busy, or NULL
1149  * @percent: (out) (allow-none): a buffering percent, or NULL
1150  *
1151  * Get the percentage of buffered data. This is a value between 0 and 100.
1152  * The @busy indicator is %TRUE when the buffering is in progress.
1153  *
1154  * Since: 0.10.20
1155  */
1156 void
1157 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1158     gint * percent)
1160   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1162   if (busy)
1163     *busy = g_value_get_boolean (gst_structure_id_get_value (query->structure,
1164             GST_QUARK (BUSY)));
1165   if (percent)
1166     *percent = g_value_get_int (gst_structure_id_get_value (query->structure,
1167             GST_QUARK (BUFFER_PERCENT)));
1170 /**
1171  * gst_query_set_buffering_stats:
1172  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1173  * @mode: a buffering mode
1174  * @avg_in: the average input rate
1175  * @avg_out: the average output rate
1176  * @buffering_left: amount of buffering time left
1177  *
1178  * Configures the buffering stats values in @query.
1179  *
1180  * Since: 0.10.20
1181  */
1182 void
1183 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1184     gint avg_in, gint avg_out, gint64 buffering_left)
1186   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1188   gst_structure_id_set (query->structure,
1189       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1190       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1191       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1192       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1195 /**
1196  * gst_query_parse_buffering_stats:
1197  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1198  * @mode: (out) (allow-none): a buffering mode, or NULL
1199  * @avg_in: (out) (allow-none): the average input rate, or NULL
1200  * @avg_out: (out) (allow-none): the average output rat, or NULLe
1201  * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1202  *
1203  * Extracts the buffering stats values from @query.
1204  *
1205  * Since: 0.10.20
1206  */
1207 void
1208 gst_query_parse_buffering_stats (GstQuery * query,
1209     GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1210     gint64 * buffering_left)
1212   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1214   if (mode)
1215     *mode = (GstBufferingMode)
1216         g_value_get_enum (gst_structure_id_get_value (query->structure,
1217             GST_QUARK (BUFFERING_MODE)));
1218   if (avg_in)
1219     *avg_in = g_value_get_int (gst_structure_id_get_value (query->structure,
1220             GST_QUARK (AVG_IN_RATE)));
1221   if (avg_out)
1222     *avg_out = g_value_get_int (gst_structure_id_get_value (query->structure,
1223             GST_QUARK (AVG_OUT_RATE)));
1224   if (buffering_left)
1225     *buffering_left =
1226         g_value_get_int64 (gst_structure_id_get_value (query->structure,
1227             GST_QUARK (BUFFERING_LEFT)));
1231 /**
1232  * gst_query_set_buffering_range:
1233  * @query: a #GstQuery
1234  * @format: the format to set for the @start and @stop values
1235  * @start: the start to set
1236  * @stop: the stop to set
1237  * @estimated_total: estimated total amount of download time
1238  *
1239  * Set the available query result fields in @query.
1240  *
1241  * Since: 0.10.20
1242  */
1243 void
1244 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1245     gint64 start, gint64 stop, gint64 estimated_total)
1247   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1249   gst_structure_id_set (query->structure,
1250       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1251       GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1252       GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1253       GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1256 /**
1257  * gst_query_parse_buffering_range:
1258  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1259  * @format: (out) (allow-none): the format to set for the @segment_start
1260  *     and @segment_end values, or NULL
1261  * @start: (out) (allow-none): the start to set, or NULL
1262  * @stop: (out) (allow-none): the stop to set, or NULL
1263  * @estimated_total: (out) (allow-none): estimated total amount of download
1264  *     time, or NULL
1265  *
1266  * Parse an available query, writing the format into @format, and
1267  * other results into the passed parameters, if the respective parameters
1268  * are non-NULL
1269  *
1270  * Since: 0.10.20
1271  */
1272 void
1273 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1274     gint64 * start, gint64 * stop, gint64 * estimated_total)
1276   GstStructure *structure;
1278   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1280   structure = query->structure;
1281   if (format)
1282     *format =
1283         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1284             GST_QUARK (FORMAT)));
1285   if (start)
1286     *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1287             GST_QUARK (START_VALUE)));
1288   if (stop)
1289     *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1290             GST_QUARK (STOP_VALUE)));
1291   if (estimated_total)
1292     *estimated_total =
1293         g_value_get_int64 (gst_structure_id_get_value (structure,
1294             GST_QUARK (ESTIMATED_TOTAL)));
1297 /**
1298  * gst_query_add_buffering_range
1299  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1300  * @start: start position of the range
1301  * @stop: stop position of the range
1302  *
1303  * Set the buffering-ranges array field in @query. The current last
1304  * start position of the array should be inferior to @start.
1305  *
1306  * Returns: a #gboolean indicating if the range was added or not.
1307  *
1308  * Since: 0.10.31
1309  */
1310 gboolean
1311 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1313   GValueArray *array;
1314   GValue *last_array_value;
1315   const GValue *value;
1316   GValue range_value = { 0 };
1318   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1320   if (G_UNLIKELY (start >= stop))
1321     return FALSE;
1323   value =
1324       gst_structure_id_get_value (query->structure,
1325       GST_QUARK (BUFFERING_RANGES));
1326   if (value) {
1327     array = (GValueArray *) g_value_get_boxed (value);
1328     last_array_value = g_value_array_get_nth (array, array->n_values - 1);
1329     if (G_UNLIKELY (start <= gst_value_get_int64_range_min (last_array_value)))
1330       return FALSE;
1331   } else {
1332     GValue new_array_val = { 0, };
1334     array = g_value_array_new (0);
1336     g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1337     g_value_take_boxed (&new_array_val, array);
1339     /* set the value array only once, so we then modify (append to) the
1340      * existing value array owned by the GstStructure / the field's GValue */
1341     gst_structure_id_take_value (query->structure, GST_QUARK (BUFFERING_RANGES),
1342         &new_array_val);
1343   }
1345   g_value_init (&range_value, GST_TYPE_INT64_RANGE);
1346   gst_value_set_int64_range (&range_value, start, stop);
1347   g_value_array_append (array, &range_value);
1348   /* skip the g_value_unset(&range_value) here, we know it's not needed */
1350   return TRUE;
1353 /**
1354  * gst_query_get_n_buffering_ranges
1355  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1356  *
1357  * Retrieve the number of values currently stored in the
1358  * buffered-ranges array of the query's structure.
1359  *
1360  * Returns: the range array size as a #guint.
1361  *
1362  * Since: 0.10.31
1363  */
1364 guint
1365 gst_query_get_n_buffering_ranges (GstQuery * query)
1367   GValueArray *array;
1368   const GValue *value;
1369   guint size = 0;
1371   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1373   value =
1374       gst_structure_id_get_value (query->structure,
1375       GST_QUARK (BUFFERING_RANGES));
1376   if (value) {
1377     array = (GValueArray *) g_value_get_boxed (value);
1378     size = array->n_values;
1379   }
1380   return size;
1384 /**
1385  * gst_query_parse_nth_buffering_range
1386  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1387  * @index: position in the buffered-ranges array to read
1388  * @start: (out) (allow-none): the start position to set, or NULL
1389  * @stop: (out) (allow-none): the stop position to set, or NULL
1390  *
1391  * Parse an available query and get the start and stop values stored
1392  * at the @index of the buffered ranges array.
1393  *
1394  * Returns: a #gboolean indicating if the parsing succeeded.
1395  *
1396  * Since: 0.10.31
1397  */
1398 gboolean
1399 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1400     gint64 * start, gint64 * stop)
1402   const GValue *value;
1403   GValueArray *ranges;
1404   GValue *range_value;
1405   gboolean ret = FALSE;
1407   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1409   value =
1410       gst_structure_id_get_value (query->structure,
1411       GST_QUARK (BUFFERING_RANGES));
1412   ranges = (GValueArray *) g_value_get_boxed (value);
1413   range_value = g_value_array_get_nth (ranges, index);
1414   if (range_value) {
1415     if (start)
1416       *start = gst_value_get_int64_range_min (range_value);
1417     if (stop)
1418       *stop = gst_value_get_int64_range_max (range_value);
1419     ret = TRUE;
1420   }
1422   return ret;
1426 /**
1427  * gst_query_new_uri:
1428  *
1429  * Constructs a new query URI query object. Use gst_query_unref()
1430  * when done with it. An URI query is used to query the current URI
1431  * that is used by the source or sink.
1432  *
1433  * Free-function: gst_query_unref
1434  *
1435  * Returns: (transfer full): a new #GstQuery
1436  *
1437  * Since: 0.10.22
1438  */
1439 GstQuery *
1440 gst_query_new_uri (void)
1442   GstQuery *query;
1443   GstStructure *structure;
1445   structure = gst_structure_id_new (GST_QUARK (QUERY_URI),
1446       GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1448   query = gst_query_new (GST_QUERY_URI, structure);
1450   return query;
1453 /**
1454  * gst_query_set_uri:
1455  * @query: a #GstQuery with query type GST_QUERY_URI
1456  * @uri: the URI to set
1457  *
1458  * Answer a URI query by setting the requested URI.
1459  *
1460  * Since: 0.10.22
1461  */
1462 void
1463 gst_query_set_uri (GstQuery * query, const gchar * uri)
1465   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1466   g_return_if_fail (gst_uri_is_valid (uri));
1468   gst_structure_id_set (query->structure, GST_QUARK (URI), G_TYPE_STRING, uri,
1469       NULL);
1472 /**
1473  * gst_query_parse_uri:
1474  * @query: a #GstQuery
1475  * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1476  *     (may be NULL)
1477  *
1478  * Parse an URI query, writing the URI into @uri as a newly
1479  * allocated string, if the respective parameters are non-NULL.
1480  * Free the string with g_free() after usage.
1481  *
1482  * Since: 0.10.22
1483  */
1484 void
1485 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1487   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1489   if (uri)
1490     *uri = g_value_dup_string (gst_structure_id_get_value (query->structure,
1491             GST_QUARK (URI)));