pad: make an ACCEPT_CAPS query
[platform/upstream/gstreamer.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  */
23
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  */
63
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"
71 #include "gstbufferpool.h"
72
73 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
74 #define GST_CAT_DEFAULT gst_query_debug
75
76 static GType _gst_query_type = 0;
77
78 typedef struct
79 {
80   GstQuery query;
81
82   GstStructure *structure;
83 } GstQueryImpl;
84
85 #define GST_QUERY_STRUCTURE(q)  (((GstQueryImpl *)(q))->structure)
86
87 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
88 static GList *_gst_queries = NULL;
89 static GHashTable *_nick_to_query = NULL;
90 static GHashTable *_query_type_to_nick = NULL;
91 static guint32 _n_values = 1;   /* we start from 1 because 0 reserved for NONE */
92
93 static GstQueryTypeDefinition standard_definitions[] = {
94   {GST_QUERY_POSITION, "position", "Current position", 0},
95   {GST_QUERY_DURATION, "duration", "Total duration", 0},
96   {GST_QUERY_LATENCY, "latency", "Latency", 0},
97   {GST_QUERY_JITTER, "jitter", "Jitter", 0},
98   {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
99   {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
100   {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
101   {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
102   {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
103   {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
104   {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
105   {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
106   {GST_QUERY_ALLOCATION, "allocation", "Allocation properties", 0},
107   {GST_QUERY_SCHEDULING, "scheduling", "Scheduling properties", 0},
108   {GST_QUERY_ACCEPT_CAPS, "accept-caps", "Accept caps", 0},
109   {GST_QUERY_NONE, NULL, NULL, 0}
110 };
111
112 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
113
114 void
115 _priv_gst_query_initialize (void)
116 {
117   GstQueryTypeDefinition *standards = standard_definitions;
118
119   GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
120
121   GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
122
123   g_static_mutex_lock (&mutex);
124   if (_nick_to_query == NULL) {
125     _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
126     _query_type_to_nick = g_hash_table_new (NULL, NULL);
127   }
128
129   while (standards->nick) {
130     standards->quark = g_quark_from_static_string (standards->nick);
131     g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
132     g_hash_table_insert (_query_type_to_nick,
133         GINT_TO_POINTER (standards->value), standards);
134
135     _gst_queries = g_list_append (_gst_queries, standards);
136     standards++;
137     _n_values++;
138   }
139   g_static_mutex_unlock (&mutex);
140
141   _gst_query_type = gst_query_get_type ();
142 }
143
144 /**
145  * gst_query_type_get_name:
146  * @query: the query type
147  *
148  * Get a printable name for the given query type. Do not modify or free.
149  *
150  * Returns: a reference to the static name of the query.
151  */
152 const gchar *
153 gst_query_type_get_name (GstQueryType query)
154 {
155   const GstQueryTypeDefinition *def;
156
157   def = gst_query_type_get_details (query);
158   g_return_val_if_fail (def != NULL, NULL);
159
160   return def->nick;
161 }
162
163 /**
164  * gst_query_type_to_quark:
165  * @query: the query type
166  *
167  * Get the unique quark for the given query type.
168  *
169  * Returns: the quark associated with the query type
170  */
171 GQuark
172 gst_query_type_to_quark (GstQueryType query)
173 {
174   const GstQueryTypeDefinition *def;
175
176   def = gst_query_type_get_details (query);
177   g_return_val_if_fail (def != NULL, 0);
178
179   return def->quark;
180 }
181
182 /**
183  * gst_query_type_register:
184  * @nick: The nick of the new query
185  * @description: The description of the new query
186  *
187  * Create a new GstQueryType based on the nick or return an
188  * already registered query with that nick
189  *
190  * Returns: A new GstQueryType or an already registered query
191  * with the same nick.
192  */
193 GstQueryType
194 gst_query_type_register (const gchar * nick, const gchar * description)
195 {
196   GstQueryTypeDefinition *query;
197   GstQueryType lookup;
198
199   g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
200   g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
201
202   lookup = gst_query_type_get_by_nick (nick);
203   if (lookup != GST_QUERY_NONE)
204     return lookup;
205
206   query = g_slice_new (GstQueryTypeDefinition);
207   query->value = (GstQueryType) _n_values;
208   query->nick = g_strdup (nick);
209   query->description = g_strdup (description);
210   query->quark = g_quark_from_static_string (query->nick);
211
212   g_static_mutex_lock (&mutex);
213   g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
214   g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
215       query);
216   _gst_queries = g_list_append (_gst_queries, query);
217   _n_values++;
218   g_static_mutex_unlock (&mutex);
219
220   return query->value;
221 }
222
223 /**
224  * gst_query_type_get_by_nick:
225  * @nick: The nick of the query
226  *
227  * Get the query type registered with @nick.
228  *
229  * Returns: The query registered with @nick or #GST_QUERY_NONE
230  * if the query was not registered.
231  */
232 GstQueryType
233 gst_query_type_get_by_nick (const gchar * nick)
234 {
235   GstQueryTypeDefinition *query;
236
237   g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
238
239   g_static_mutex_lock (&mutex);
240   query = g_hash_table_lookup (_nick_to_query, nick);
241   g_static_mutex_unlock (&mutex);
242
243   if (query != NULL)
244     return query->value;
245   else
246     return GST_QUERY_NONE;
247 }
248
249 /**
250  * gst_query_types_contains:
251  * @types: The query array to search
252  * @type: the #GstQueryType to find
253  *
254  * See if the given #GstQueryType is inside the @types query types array.
255  *
256  * Returns: TRUE if the type is found inside the array
257  */
258 gboolean
259 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
260 {
261   if (!types)
262     return FALSE;
263
264   while (*types) {
265     if (*types == type)
266       return TRUE;
267
268     types++;
269   }
270   return FALSE;
271 }
272
273
274 /**
275  * gst_query_type_get_details:
276  * @type: a #GstQueryType
277  *
278  * Get details about the given #GstQueryType.
279  *
280  * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
281  */
282 const GstQueryTypeDefinition *
283 gst_query_type_get_details (GstQueryType type)
284 {
285   const GstQueryTypeDefinition *result;
286
287   g_static_mutex_lock (&mutex);
288   result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
289   g_static_mutex_unlock (&mutex);
290
291   return result;
292 }
293
294 /**
295  * gst_query_type_iterate_definitions:
296  *
297  * Get a #GstIterator of all the registered query types. The definitions
298  * iterated over are read only.
299  *
300  * Free-function: gst_iterator_free
301  *
302  * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
303  */
304 GstIterator *
305 gst_query_type_iterate_definitions (void)
306 {
307   GstIterator *result;
308
309   g_static_mutex_lock (&mutex);
310   /* FIXME: register a boxed type for GstQueryTypeDefinition */
311   result = gst_iterator_new_list (G_TYPE_POINTER,
312       g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries, NULL, NULL);
313   g_static_mutex_unlock (&mutex);
314
315   return result;
316 }
317
318 static void
319 _gst_query_free (GstQuery * query)
320 {
321   GstStructure *s;
322
323   g_return_if_fail (query != NULL);
324
325   s = GST_QUERY_STRUCTURE (query);
326   if (s) {
327     gst_structure_set_parent_refcount (s, NULL);
328     gst_structure_free (s);
329   }
330
331   g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
332 }
333
334 static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
335
336 static GstQuery *
337 _gst_query_copy (GstQuery * query)
338 {
339   GstQuery *copy;
340
341   copy = gst_query_new (query->type, GST_QUERY_STRUCTURE (query));
342
343   return copy;
344 }
345
346 static GstQuery *
347 gst_query_new (GstQueryType type, GstStructure * structure)
348 {
349   GstQueryImpl *query;
350
351   query = g_slice_new0 (GstQueryImpl);
352
353   gst_mini_object_init (GST_MINI_OBJECT_CAST (query),
354       _gst_query_type, sizeof (GstQueryImpl));
355
356   query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
357   query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
358
359   GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
360
361   GST_QUERY_TYPE (query) = type;
362   query->structure = structure;
363
364   if (structure)
365     gst_structure_set_parent_refcount (structure,
366         &query->query.mini_object.refcount);
367
368   return GST_QUERY_CAST (query);
369 }
370
371 /**
372  * gst_query_new_position:
373  * @format: the default #GstFormat for the new query
374  *
375  * Constructs a new query stream position query object. Use gst_query_unref()
376  * when done with it. A position query is used to query the current position
377  * of playback in the streams, in some format.
378  *
379  * Free-function: gst_query_unref
380  *
381  * Returns: (transfer full): a new #GstQuery
382  */
383 GstQuery *
384 gst_query_new_position (GstFormat format)
385 {
386   GstQuery *query;
387   GstStructure *structure;
388
389   structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
390       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
391       GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
392
393   query = gst_query_new (GST_QUERY_POSITION, structure);
394
395   return query;
396 }
397
398 /**
399  * gst_query_set_position:
400  * @query: a #GstQuery with query type GST_QUERY_POSITION
401  * @format: the requested #GstFormat
402  * @cur: the position to set
403  *
404  * Answer a position query by setting the requested value in the given format.
405  */
406 void
407 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
408 {
409   GstStructure *s;
410
411   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
412
413   s = GST_QUERY_STRUCTURE (query);
414   g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
415               GST_QUARK (FORMAT))));
416
417   gst_structure_id_set (s,
418       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
419       GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
420 }
421
422 /**
423  * gst_query_parse_position:
424  * @query: a #GstQuery
425  * @format: (out) (allow-none): the storage for the #GstFormat of the
426  *     position values (may be NULL)
427  * @cur: (out) (allow-none): the storage for the current position (may be NULL)
428  *
429  * Parse a position query, writing the format into @format, and the position
430  * into @cur, if the respective parameters are non-NULL.
431  */
432 void
433 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
434 {
435   GstStructure *structure;
436
437   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
438
439   structure = GST_QUERY_STRUCTURE (query);
440   if (format)
441     *format =
442         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
443             GST_QUARK (FORMAT)));
444   if (cur)
445     *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
446             GST_QUARK (CURRENT)));
447 }
448
449
450 /**
451  * gst_query_new_duration:
452  * @format: the #GstFormat for this duration query
453  *
454  * Constructs a new stream duration query object to query in the given format.
455  * Use gst_query_unref() when done with it. A duration query will give the
456  * total length of the stream.
457  *
458  * Free-function: gst_query_unref
459  *
460  * Returns: (transfer full): a new #GstQuery
461  */
462 GstQuery *
463 gst_query_new_duration (GstFormat format)
464 {
465   GstQuery *query;
466   GstStructure *structure;
467
468   structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
469       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
470       GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
471
472   query = gst_query_new (GST_QUERY_DURATION, structure);
473
474   return query;
475 }
476
477 /**
478  * gst_query_set_duration:
479  * @query: a #GstQuery
480  * @format: the #GstFormat for the duration
481  * @duration: the duration of the stream
482  *
483  * Answer a duration query by setting the requested value in the given format.
484  */
485 void
486 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
487 {
488   GstStructure *s;
489
490   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
491
492   s = GST_QUERY_STRUCTURE (query);
493   g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
494               GST_QUARK (FORMAT))));
495   gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
496       GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
497 }
498
499 /**
500  * gst_query_parse_duration:
501  * @query: a #GstQuery
502  * @format: (out) (allow-none): the storage for the #GstFormat of the duration
503  *     value, or NULL.
504  * @duration: (out) (allow-none): the storage for the total duration, or NULL.
505  *
506  * Parse a duration query answer. Write the format of the duration into @format,
507  * and the value into @duration, if the respective variables are non-NULL.
508  */
509 void
510 gst_query_parse_duration (GstQuery * query, GstFormat * format,
511     gint64 * duration)
512 {
513   GstStructure *structure;
514
515   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
516
517   structure = GST_QUERY_STRUCTURE (query);
518   if (format)
519     *format =
520         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
521             GST_QUARK (FORMAT)));
522   if (duration)
523     *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
524             GST_QUARK (DURATION)));
525 }
526
527 /**
528  * gst_query_new_latency:
529  *
530  * Constructs a new latency query object.
531  * Use gst_query_unref() when done with it. A latency query is usually performed
532  * by sinks to compensate for additional latency introduced by elements in the
533  * pipeline.
534  *
535  * Free-function: gst_query_unref
536  *
537  * Returns: (transfer full): a #GstQuery
538  *
539  * Since: 0.10.12
540  */
541 GstQuery *
542 gst_query_new_latency (void)
543 {
544   GstQuery *query;
545   GstStructure *structure;
546
547   structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
548       GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
549       GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
550       GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
551
552   query = gst_query_new (GST_QUERY_LATENCY, structure);
553
554   return query;
555 }
556
557 /**
558  * gst_query_set_latency:
559  * @query: a #GstQuery
560  * @live: if there is a live element upstream
561  * @min_latency: the minimal latency of the live element
562  * @max_latency: the maximal latency of the live element
563  *
564  * Answer a latency query by setting the requested values in the given format.
565  *
566  * Since: 0.10.12
567  */
568 void
569 gst_query_set_latency (GstQuery * query, gboolean live,
570     GstClockTime min_latency, GstClockTime max_latency)
571 {
572   GstStructure *structure;
573
574   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
575
576   structure = GST_QUERY_STRUCTURE (query);
577   gst_structure_id_set (structure,
578       GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
579       GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
580       GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
581 }
582
583 /**
584  * gst_query_parse_latency:
585  * @query: a #GstQuery
586  * @live: (out) (allow-none): storage for live or NULL
587  * @min_latency: (out) (allow-none): the storage for the min latency or NULL
588  * @max_latency: (out) (allow-none): the storage for the max latency or NULL
589  *
590  * Parse a latency query answer.
591  *
592  * Since: 0.10.12
593  */
594 void
595 gst_query_parse_latency (GstQuery * query, gboolean * live,
596     GstClockTime * min_latency, GstClockTime * max_latency)
597 {
598   GstStructure *structure;
599
600   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
601
602   structure = GST_QUERY_STRUCTURE (query);
603   if (live)
604     *live =
605         g_value_get_boolean (gst_structure_id_get_value (structure,
606             GST_QUARK (LIVE)));
607   if (min_latency)
608     *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
609             GST_QUARK (MIN_LATENCY)));
610   if (max_latency)
611     *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
612             GST_QUARK (MAX_LATENCY)));
613 }
614
615 /**
616  * gst_query_new_convert:
617  * @src_format: the source #GstFormat for the new query
618  * @value: the value to convert
619  * @dest_format: the target #GstFormat
620  *
621  * Constructs a new convert query object. Use gst_query_unref()
622  * when done with it. A convert query is used to ask for a conversion between
623  * one format and another.
624  *
625  * Free-function: gst_query_unref
626  *
627  * Returns: (transfer full): a #GstQuery
628  */
629 GstQuery *
630 gst_query_new_convert (GstFormat src_format, gint64 value,
631     GstFormat dest_format)
632 {
633   GstQuery *query;
634   GstStructure *structure;
635
636   structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
637       GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
638       GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
639       GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
640       GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
641
642   query = gst_query_new (GST_QUERY_CONVERT, structure);
643
644   return query;
645 }
646
647 /**
648  * gst_query_set_convert:
649  * @query: a #GstQuery
650  * @src_format: the source #GstFormat
651  * @src_value: the source value
652  * @dest_format: the destination #GstFormat
653  * @dest_value: the destination value
654  *
655  * Answer a convert query by setting the requested values.
656  */
657 void
658 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
659     GstFormat dest_format, gint64 dest_value)
660 {
661   GstStructure *structure;
662
663   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
664
665   structure = GST_QUERY_STRUCTURE (query);
666   gst_structure_id_set (structure,
667       GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
668       GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
669       GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
670       GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
671 }
672
673 /**
674  * gst_query_parse_convert:
675  * @query: a #GstQuery
676  * @src_format: (out) (allow-none): the storage for the #GstFormat of the
677  *     source value, or NULL
678  * @src_value: (out) (allow-none): the storage for the source value, or NULL
679  * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
680  *     destination value, or NULL
681  * @dest_value: (out) (allow-none): the storage for the destination value,
682  *     or NULL
683  *
684  * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
685  * and @dest_value may be NULL, in which case that value is omitted.
686  */
687 void
688 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
689     gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
690 {
691   GstStructure *structure;
692
693   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
694
695   structure = GST_QUERY_STRUCTURE (query);
696   if (src_format)
697     *src_format =
698         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
699             GST_QUARK (SRC_FORMAT)));
700   if (src_value)
701     *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
702             GST_QUARK (SRC_VALUE)));
703   if (dest_format)
704     *dest_format =
705         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
706             GST_QUARK (DEST_FORMAT)));
707   if (dest_value)
708     *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
709             GST_QUARK (DEST_VALUE)));
710 }
711
712 /**
713  * gst_query_new_segment:
714  * @format: the #GstFormat for the new query
715  *
716  * Constructs a new segment query object. Use gst_query_unref()
717  * when done with it. A segment query is used to discover information about the
718  * currently configured segment for playback.
719  *
720  * Free-function: gst_query_unref
721  *
722  * Returns: (transfer full): a new #GstQuery
723  */
724 GstQuery *
725 gst_query_new_segment (GstFormat format)
726 {
727   GstQuery *query;
728   GstStructure *structure;
729
730   structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
731       GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
732       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
733       GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
734       GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
735
736   query = gst_query_new (GST_QUERY_SEGMENT, structure);
737
738   return query;
739 }
740
741 /**
742  * gst_query_set_segment:
743  * @query: a #GstQuery
744  * @rate: the rate of the segment
745  * @format: the #GstFormat of the segment values (@start_value and @stop_value)
746  * @start_value: the start value
747  * @stop_value: the stop value
748  *
749  * Answer a segment query by setting the requested values. The normal
750  * playback segment of a pipeline is 0 to duration at the default rate of
751  * 1.0. If a seek was performed on the pipeline to play a different
752  * segment, this query will return the range specified in the last seek.
753  *
754  * @start_value and @stop_value will respectively contain the configured
755  * playback range start and stop values expressed in @format.
756  * The values are always between 0 and the duration of the media and
757  * @start_value <= @stop_value. @rate will contain the playback rate. For
758  * negative rates, playback will actually happen from @stop_value to
759  * @start_value.
760  */
761 void
762 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
763     gint64 start_value, gint64 stop_value)
764 {
765   GstStructure *structure;
766
767   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
768
769   structure = GST_QUERY_STRUCTURE (query);
770   gst_structure_id_set (structure,
771       GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
772       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
773       GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
774       GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
775 }
776
777 /**
778  * gst_query_parse_segment:
779  * @query: a #GstQuery
780  * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
781  * @format: (out) (allow-none): the storage for the #GstFormat of the values,
782  *     or NULL
783  * @start_value: (out) (allow-none): the storage for the start value, or NULL
784  * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
785  *
786  * Parse a segment query answer. Any of @rate, @format, @start_value, and
787  * @stop_value may be NULL, which will cause this value to be omitted.
788  *
789  * See gst_query_set_segment() for an explanation of the function arguments.
790  */
791 void
792 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
793     gint64 * start_value, gint64 * stop_value)
794 {
795   GstStructure *structure;
796
797   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
798
799   structure = GST_QUERY_STRUCTURE (query);
800   if (rate)
801     *rate = g_value_get_double (gst_structure_id_get_value (structure,
802             GST_QUARK (RATE)));
803   if (format)
804     *format =
805         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
806             GST_QUARK (FORMAT)));
807   if (start_value)
808     *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
809             GST_QUARK (START_VALUE)));
810   if (stop_value)
811     *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
812             GST_QUARK (STOP_VALUE)));
813 }
814
815 /**
816  * gst_query_new_custom:
817  * @type: the query type
818  * @structure: a structure for the query
819  *
820  * Constructs a new custom query object. Use gst_query_unref()
821  * when done with it.
822  *
823  * Free-function: gst_query_unref
824  *
825  * Returns: (transfer full): a new #GstQuery
826  */
827 GstQuery *
828 gst_query_new_custom (GstQueryType type, GstStructure * structure)
829 {
830   g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
831   g_return_val_if_fail (structure != NULL, NULL);
832
833   return gst_query_new (type, structure);
834 }
835
836 /**
837  * gst_query_get_structure:
838  * @query: a #GstQuery
839  *
840  * Get the structure of a query.
841  *
842  * Returns: (transfer none): the #GstStructure of the query. The structure is
843  *     still owned by the query and will therefore be freed when the query
844  *     is unreffed.
845  */
846 const GstStructure *
847 gst_query_get_structure (GstQuery * query)
848 {
849   g_return_val_if_fail (GST_IS_QUERY (query), NULL);
850
851   return GST_QUERY_STRUCTURE (query);
852 }
853
854 /**
855  * gst_query_writable_structure:
856  * @query: a #GstQuery
857  *
858  * Get the structure of a query.
859  *
860  * Returns: (transfer none): the #GstStructure of the query. The structure is
861  *     still owned by the query and will therefore be freed when the query
862  *     is unreffed.
863  */
864 GstStructure *
865 gst_query_writable_structure (GstQuery * query)
866 {
867   g_return_val_if_fail (GST_IS_QUERY (query), NULL);
868   g_return_val_if_fail (gst_query_is_writable (query), NULL);
869
870   return GST_QUERY_STRUCTURE (query);
871 }
872
873 /**
874  * gst_query_new_seeking:
875  * @format: the default #GstFormat for the new query
876  *
877  * Constructs a new query object for querying seeking properties of
878  * the stream.
879  *
880  * Free-function: gst_query_unref
881  *
882  * Returns: (transfer full): a new #GstQuery
883  */
884 GstQuery *
885 gst_query_new_seeking (GstFormat format)
886 {
887   GstQuery *query;
888   GstStructure *structure;
889
890   structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
891       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
892       GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
893       GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
894       GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
895
896   query = gst_query_new (GST_QUERY_SEEKING, structure);
897
898   return query;
899 }
900
901 /**
902  * gst_query_set_seeking:
903  * @query: a #GstQuery
904  * @format: the format to set for the @segment_start and @segment_end values
905  * @seekable: the seekable flag to set
906  * @segment_start: the segment_start to set
907  * @segment_end: the segment_end to set
908  *
909  * Set the seeking query result fields in @query.
910  */
911 void
912 gst_query_set_seeking (GstQuery * query, GstFormat format,
913     gboolean seekable, gint64 segment_start, gint64 segment_end)
914 {
915   GstStructure *structure;
916
917   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
918   g_return_if_fail (gst_query_is_writable (query));
919
920   structure = GST_QUERY_STRUCTURE (query);
921   gst_structure_id_set (structure,
922       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
923       GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
924       GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
925       GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
926 }
927
928 /**
929  * gst_query_parse_seeking:
930  * @query: a GST_QUERY_SEEKING type query #GstQuery
931  * @format: (out) (allow-none): the format to set for the @segment_start
932  *     and @segment_end values, or NULL
933  * @seekable: (out) (allow-none): the seekable flag to set, or NULL
934  * @segment_start: (out) (allow-none): the segment_start to set, or NULL
935  * @segment_end: (out) (allow-none): the segment_end to set, or NULL
936  *
937  * Parse a seeking query, writing the format into @format, and
938  * other results into the passed parameters, if the respective parameters
939  * are non-NULL
940  */
941 void
942 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
943     gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
944 {
945   GstStructure *structure;
946
947   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
948
949   structure = GST_QUERY_STRUCTURE (query);
950   if (format)
951     *format =
952         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
953             GST_QUARK (FORMAT)));
954   if (seekable)
955     *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
956             GST_QUARK (SEEKABLE)));
957   if (segment_start)
958     *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
959             GST_QUARK (SEGMENT_START)));
960   if (segment_end)
961     *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
962             GST_QUARK (SEGMENT_END)));
963 }
964
965 /**
966  * gst_query_new_formats:
967  *
968  * Constructs a new query object for querying formats of
969  * the stream.
970  *
971  * Free-function: gst_query_unref
972  *
973  * Returns: (transfer full): a new #GstQuery
974  *
975  * Since: 0.10.4
976  */
977 GstQuery *
978 gst_query_new_formats (void)
979 {
980   GstQuery *query;
981   GstStructure *structure;
982
983   structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
984   query = gst_query_new (GST_QUERY_FORMATS, structure);
985
986   return query;
987 }
988
989 static void
990 gst_query_list_add_format (GValue * list, GstFormat format)
991 {
992   GValue item = { 0, };
993
994   g_value_init (&item, GST_TYPE_FORMAT);
995   g_value_set_enum (&item, format);
996   gst_value_list_append_value (list, &item);
997   g_value_unset (&item);
998 }
999
1000 /**
1001  * gst_query_set_formats:
1002  * @query: a #GstQuery
1003  * @n_formats: the number of formats to set.
1004  * @...: A number of @GstFormats equal to @n_formats.
1005  *
1006  * Set the formats query result fields in @query. The number of formats passed
1007  * must be equal to @n_formats.
1008  */
1009 void
1010 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1011 {
1012   va_list ap;
1013   GValue list = { 0, };
1014   gint i;
1015   GstStructure *structure;
1016
1017   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1018   g_return_if_fail (gst_query_is_writable (query));
1019
1020   g_value_init (&list, GST_TYPE_LIST);
1021
1022   va_start (ap, n_formats);
1023   for (i = 0; i < n_formats; i++) {
1024     gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1025   }
1026   va_end (ap);
1027
1028   structure = GST_QUERY_STRUCTURE (query);
1029   gst_structure_set_value (structure, "formats", &list);
1030
1031   g_value_unset (&list);
1032
1033 }
1034
1035 /**
1036  * gst_query_set_formatsv:
1037  * @query: a #GstQuery
1038  * @n_formats: the number of formats to set.
1039  * @formats: (in) (array length=n_formats): an array containing @n_formats
1040  *     @GstFormat values.
1041  *
1042  * Set the formats query result fields in @query. The number of formats passed
1043  * in the @formats array must be equal to @n_formats.
1044  *
1045  * Since: 0.10.4
1046  */
1047 void
1048 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1049     const GstFormat * formats)
1050 {
1051   GValue list = { 0, };
1052   gint i;
1053   GstStructure *structure;
1054
1055   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1056   g_return_if_fail (gst_query_is_writable (query));
1057
1058   g_value_init (&list, GST_TYPE_LIST);
1059   for (i = 0; i < n_formats; i++) {
1060     gst_query_list_add_format (&list, formats[i]);
1061   }
1062   structure = GST_QUERY_STRUCTURE (query);
1063   gst_structure_set_value (structure, "formats", &list);
1064
1065   g_value_unset (&list);
1066 }
1067
1068 /**
1069  * gst_query_parse_n_formats:
1070  * @query: a #GstQuery
1071  * @n_formats: (out): the number of formats in this query.
1072  *
1073  * Parse the number of formats in the formats @query.
1074  *
1075  * Since: 0.10.4
1076  */
1077 void
1078 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1079 {
1080   GstStructure *structure;
1081
1082   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1083
1084   if (n_formats) {
1085     const GValue *list;
1086
1087     structure = GST_QUERY_STRUCTURE (query);
1088     list = gst_structure_get_value (structure, "formats");
1089     if (list == NULL)
1090       *n_formats = 0;
1091     else
1092       *n_formats = gst_value_list_get_size (list);
1093   }
1094 }
1095
1096 /**
1097  * gst_query_parse_nth_format:
1098  * @query: a #GstQuery
1099  * @nth: (out): the nth format to retrieve.
1100  * @format: (out): a pointer to store the nth format
1101  *
1102  * Parse the format query and retrieve the @nth format from it into
1103  * @format. If the list contains less elements than @nth, @format will be
1104  * set to GST_FORMAT_UNDEFINED.
1105  */
1106 void
1107 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1108 {
1109   GstStructure *structure;
1110
1111   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1112
1113   if (format) {
1114     const GValue *list;
1115
1116     structure = GST_QUERY_STRUCTURE (query);
1117     list = gst_structure_get_value (structure, "formats");
1118     if (list == NULL) {
1119       *format = GST_FORMAT_UNDEFINED;
1120     } else {
1121       if (nth < gst_value_list_get_size (list)) {
1122         *format =
1123             (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1124       } else
1125         *format = GST_FORMAT_UNDEFINED;
1126     }
1127   }
1128 }
1129
1130 /**
1131  * gst_query_new_buffering
1132  * @format: the default #GstFormat for the new query
1133  *
1134  * Constructs a new query object for querying the buffering status of
1135  * a stream.
1136  *
1137  * Free-function: gst_query_unref
1138  *
1139  * Returns: (transfer full): a new #GstQuery
1140  *
1141  * Since: 0.10.20
1142  */
1143 GstQuery *
1144 gst_query_new_buffering (GstFormat format)
1145 {
1146   GstQuery *query;
1147   GstStructure *structure;
1148
1149   /* by default, we configure the answer as no buffering with a 100% buffering
1150    * progress */
1151   structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1152       GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1153       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1154       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1155       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1156       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1157       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1158       GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1159       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1160       GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1161       GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1162
1163   query = gst_query_new (GST_QUERY_BUFFERING, structure);
1164
1165   return query;
1166 }
1167
1168 /**
1169  * gst_query_set_buffering_percent
1170  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1171  * @busy: if buffering is busy
1172  * @percent: a buffering percent
1173  *
1174  * Set the percentage of buffered data. This is a value between 0 and 100.
1175  * The @busy indicator is %TRUE when the buffering is in progress.
1176  *
1177  * Since: 0.10.20
1178  */
1179 void
1180 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1181 {
1182   GstStructure *structure;
1183
1184   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1185   g_return_if_fail (gst_query_is_writable (query));
1186   g_return_if_fail (percent >= 0 && percent <= 100);
1187
1188   structure = GST_QUERY_STRUCTURE (query);
1189   gst_structure_id_set (structure,
1190       GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1191       GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1192 }
1193
1194 /**
1195  * gst_query_parse_buffering_percent
1196  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1197  * @busy: (out) (allow-none): if buffering is busy, or NULL
1198  * @percent: (out) (allow-none): a buffering percent, or NULL
1199  *
1200  * Get the percentage of buffered data. This is a value between 0 and 100.
1201  * The @busy indicator is %TRUE when the buffering is in progress.
1202  *
1203  * Since: 0.10.20
1204  */
1205 void
1206 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1207     gint * percent)
1208 {
1209   GstStructure *structure;
1210
1211   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1212
1213   structure = GST_QUERY_STRUCTURE (query);
1214   if (busy)
1215     *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1216             GST_QUARK (BUSY)));
1217   if (percent)
1218     *percent = g_value_get_int (gst_structure_id_get_value (structure,
1219             GST_QUARK (BUFFER_PERCENT)));
1220 }
1221
1222 /**
1223  * gst_query_set_buffering_stats:
1224  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1225  * @mode: a buffering mode
1226  * @avg_in: the average input rate
1227  * @avg_out: the average output rate
1228  * @buffering_left: amount of buffering time left
1229  *
1230  * Configures the buffering stats values in @query.
1231  *
1232  * Since: 0.10.20
1233  */
1234 void
1235 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1236     gint avg_in, gint avg_out, gint64 buffering_left)
1237 {
1238   GstStructure *structure;
1239
1240   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1241   g_return_if_fail (gst_query_is_writable (query));
1242
1243   structure = GST_QUERY_STRUCTURE (query);
1244   gst_structure_id_set (structure,
1245       GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1246       GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1247       GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1248       GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1249 }
1250
1251 /**
1252  * gst_query_parse_buffering_stats:
1253  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1254  * @mode: (out) (allow-none): a buffering mode, or NULL
1255  * @avg_in: (out) (allow-none): the average input rate, or NULL
1256  * @avg_out: (out) (allow-none): the average output rat, or NULLe
1257  * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1258  *
1259  * Extracts the buffering stats values from @query.
1260  *
1261  * Since: 0.10.20
1262  */
1263 void
1264 gst_query_parse_buffering_stats (GstQuery * query,
1265     GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1266     gint64 * buffering_left)
1267 {
1268   GstStructure *structure;
1269
1270   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1271
1272   structure = GST_QUERY_STRUCTURE (query);
1273   if (mode)
1274     *mode = (GstBufferingMode)
1275         g_value_get_enum (gst_structure_id_get_value (structure,
1276             GST_QUARK (BUFFERING_MODE)));
1277   if (avg_in)
1278     *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1279             GST_QUARK (AVG_IN_RATE)));
1280   if (avg_out)
1281     *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1282             GST_QUARK (AVG_OUT_RATE)));
1283   if (buffering_left)
1284     *buffering_left =
1285         g_value_get_int64 (gst_structure_id_get_value (structure,
1286             GST_QUARK (BUFFERING_LEFT)));
1287 }
1288
1289
1290 /**
1291  * gst_query_set_buffering_range:
1292  * @query: a #GstQuery
1293  * @format: the format to set for the @start and @stop values
1294  * @start: the start to set
1295  * @stop: the stop to set
1296  * @estimated_total: estimated total amount of download time
1297  *
1298  * Set the available query result fields in @query.
1299  *
1300  * Since: 0.10.20
1301  */
1302 void
1303 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1304     gint64 start, gint64 stop, gint64 estimated_total)
1305 {
1306   GstStructure *structure;
1307
1308   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1309   g_return_if_fail (gst_query_is_writable (query));
1310
1311   structure = GST_QUERY_STRUCTURE (query);
1312   gst_structure_id_set (structure,
1313       GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1314       GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1315       GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1316       GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1317 }
1318
1319 /**
1320  * gst_query_parse_buffering_range:
1321  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1322  * @format: (out) (allow-none): the format to set for the @segment_start
1323  *     and @segment_end values, or NULL
1324  * @start: (out) (allow-none): the start to set, or NULL
1325  * @stop: (out) (allow-none): the stop to set, or NULL
1326  * @estimated_total: (out) (allow-none): estimated total amount of download
1327  *     time, or NULL
1328  *
1329  * Parse an available query, writing the format into @format, and
1330  * other results into the passed parameters, if the respective parameters
1331  * are non-NULL
1332  *
1333  * Since: 0.10.20
1334  */
1335 void
1336 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1337     gint64 * start, gint64 * stop, gint64 * estimated_total)
1338 {
1339   GstStructure *structure;
1340
1341   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1342
1343   structure = GST_QUERY_STRUCTURE (query);
1344   if (format)
1345     *format =
1346         (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1347             GST_QUARK (FORMAT)));
1348   if (start)
1349     *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1350             GST_QUARK (START_VALUE)));
1351   if (stop)
1352     *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1353             GST_QUARK (STOP_VALUE)));
1354   if (estimated_total)
1355     *estimated_total =
1356         g_value_get_int64 (gst_structure_id_get_value (structure,
1357             GST_QUARK (ESTIMATED_TOTAL)));
1358 }
1359
1360 /**
1361  * gst_query_add_buffering_range
1362  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1363  * @start: start position of the range
1364  * @stop: stop position of the range
1365  *
1366  * Set the buffering-ranges array field in @query. The current last
1367  * start position of the array should be inferior to @start.
1368  *
1369  * Returns: a #gboolean indicating if the range was added or not.
1370  *
1371  * Since: 0.10.31
1372  */
1373 gboolean
1374 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1375 {
1376   GValueArray *array;
1377   GValue *last_array_value;
1378   const GValue *value;
1379   GValue range_value = { 0 };
1380   GstStructure *structure;
1381
1382   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1383   g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1384
1385   if (G_UNLIKELY (start >= stop))
1386     return FALSE;
1387
1388   structure = GST_QUERY_STRUCTURE (query);
1389   value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1390   if (value) {
1391     array = (GValueArray *) g_value_get_boxed (value);
1392     last_array_value = g_value_array_get_nth (array, array->n_values - 1);
1393     if (G_UNLIKELY (start <= gst_value_get_int64_range_min (last_array_value)))
1394       return FALSE;
1395   } else {
1396     GValue new_array_val = { 0, };
1397
1398     array = g_value_array_new (0);
1399
1400     g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1401     g_value_take_boxed (&new_array_val, array);
1402
1403     /* set the value array only once, so we then modify (append to) the
1404      * existing value array owned by the GstStructure / the field's GValue */
1405     gst_structure_id_take_value (structure, GST_QUARK (BUFFERING_RANGES),
1406         &new_array_val);
1407   }
1408
1409   g_value_init (&range_value, GST_TYPE_INT64_RANGE);
1410   gst_value_set_int64_range (&range_value, start, stop);
1411   g_value_array_append (array, &range_value);
1412   /* skip the g_value_unset(&range_value) here, we know it's not needed */
1413
1414   return TRUE;
1415 }
1416
1417 /**
1418  * gst_query_get_n_buffering_ranges
1419  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1420  *
1421  * Retrieve the number of values currently stored in the
1422  * buffered-ranges array of the query's structure.
1423  *
1424  * Returns: the range array size as a #guint.
1425  *
1426  * Since: 0.10.31
1427  */
1428 guint
1429 gst_query_get_n_buffering_ranges (GstQuery * query)
1430 {
1431   GValueArray *array;
1432   const GValue *value;
1433   guint size = 0;
1434   GstStructure *structure;
1435
1436   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1437
1438   structure = GST_QUERY_STRUCTURE (query);
1439   value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1440   if (value) {
1441     array = (GValueArray *) g_value_get_boxed (value);
1442     size = array->n_values;
1443   }
1444   return size;
1445 }
1446
1447
1448 /**
1449  * gst_query_parse_nth_buffering_range
1450  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1451  * @index: position in the buffered-ranges array to read
1452  * @start: (out) (allow-none): the start position to set, or NULL
1453  * @stop: (out) (allow-none): the stop position to set, or NULL
1454  *
1455  * Parse an available query and get the start and stop values stored
1456  * at the @index of the buffered ranges array.
1457  *
1458  * Returns: a #gboolean indicating if the parsing succeeded.
1459  *
1460  * Since: 0.10.31
1461  */
1462 gboolean
1463 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1464     gint64 * start, gint64 * stop)
1465 {
1466   const GValue *value;
1467   GValueArray *ranges;
1468   GValue *range_value;
1469   gboolean ret = FALSE;
1470   GstStructure *structure;
1471
1472   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1473
1474   structure = GST_QUERY_STRUCTURE (query);
1475   value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1476   ranges = (GValueArray *) g_value_get_boxed (value);
1477   range_value = g_value_array_get_nth (ranges, index);
1478   if (range_value) {
1479     if (start)
1480       *start = gst_value_get_int64_range_min (range_value);
1481     if (stop)
1482       *stop = gst_value_get_int64_range_max (range_value);
1483     ret = TRUE;
1484   }
1485
1486   return ret;
1487 }
1488
1489
1490 /**
1491  * gst_query_new_uri:
1492  *
1493  * Constructs a new query URI query object. Use gst_query_unref()
1494  * when done with it. An URI query is used to query the current URI
1495  * that is used by the source or sink.
1496  *
1497  * Free-function: gst_query_unref
1498  *
1499  * Returns: (transfer full): a new #GstQuery
1500  *
1501  * Since: 0.10.22
1502  */
1503 GstQuery *
1504 gst_query_new_uri (void)
1505 {
1506   GstQuery *query;
1507   GstStructure *structure;
1508
1509   structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1510       GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1511
1512   query = gst_query_new (GST_QUERY_URI, structure);
1513
1514   return query;
1515 }
1516
1517 /**
1518  * gst_query_set_uri:
1519  * @query: a #GstQuery with query type GST_QUERY_URI
1520  * @uri: the URI to set
1521  *
1522  * Answer a URI query by setting the requested URI.
1523  *
1524  * Since: 0.10.22
1525  */
1526 void
1527 gst_query_set_uri (GstQuery * query, const gchar * uri)
1528 {
1529   GstStructure *structure;
1530
1531   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1532   g_return_if_fail (gst_query_is_writable (query));
1533   g_return_if_fail (gst_uri_is_valid (uri));
1534
1535   structure = GST_QUERY_STRUCTURE (query);
1536   gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1537 }
1538
1539 /**
1540  * gst_query_parse_uri:
1541  * @query: a #GstQuery
1542  * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1543  *     (may be NULL)
1544  *
1545  * Parse an URI query, writing the URI into @uri as a newly
1546  * allocated string, if the respective parameters are non-NULL.
1547  * Free the string with g_free() after usage.
1548  *
1549  * Since: 0.10.22
1550  */
1551 void
1552 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1553 {
1554   GstStructure *structure;
1555
1556   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1557
1558   structure = GST_QUERY_STRUCTURE (query);
1559   if (uri)
1560     *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1561             GST_QUARK (URI)));
1562 }
1563
1564 /**
1565  * gst_query_new_allocation
1566  * @caps: the negotiated caps
1567  * @need_pool: return a pool
1568  *
1569  * Constructs a new query object for querying the allocation properties.
1570  *
1571  * Free-function: gst_query_unref
1572  *
1573  * Returns: (transfer full): a new #GstQuery
1574  */
1575 GstQuery *
1576 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1577 {
1578   GstQuery *query;
1579   GstStructure *structure;
1580
1581   structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1582       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1583       GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1584       GST_QUARK (SIZE), G_TYPE_UINT, 0,
1585       GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1586       GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1587       GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1588       GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1589       GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1590
1591   query = gst_query_new (GST_QUERY_ALLOCATION, structure);
1592
1593   return query;
1594 }
1595
1596 void
1597 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1598     gboolean * need_pool)
1599 {
1600   GstStructure *structure;
1601
1602   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1603
1604   structure = GST_QUERY_STRUCTURE (query);
1605   gst_structure_id_get (structure,
1606       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1607       GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1608 }
1609
1610 /**
1611  * gst_query_set_allocation_params
1612  * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1613  * @size: the size
1614  * @min_buffers: the min buffers
1615  * @max_buffers: the max buffers
1616  * @prefix: the prefix
1617  * @alignment: the alignment
1618  * @pool: the #GstBufferPool
1619  *
1620  * Set the allocation parameters in @query.
1621  */
1622 void
1623 gst_query_set_allocation_params (GstQuery * query, guint size,
1624     guint min_buffers, guint max_buffers, guint prefix,
1625     guint alignment, GstBufferPool * pool)
1626 {
1627   GstStructure *structure;
1628
1629   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1630   g_return_if_fail (gst_query_is_writable (query));
1631   g_return_if_fail (((alignment + 1) & alignment) == 0);
1632   g_return_if_fail (size != 0 || pool == NULL);
1633
1634   structure = GST_QUERY_STRUCTURE (query);
1635   gst_structure_id_set (structure,
1636       GST_QUARK (SIZE), G_TYPE_UINT, size,
1637       GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1638       GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1639       GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1640       GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1641       GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1642 }
1643
1644 /**
1645  * gst_query_parse_allocation_params
1646  * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1647  * @size: the size
1648  * @min_buffers: the min buffers
1649  * @max_buffers: the max buffers
1650  * @prefix: the prefix
1651  * @alignment: the alignment
1652  * @pool: the #GstBufferPool
1653  *
1654  * Get the allocation parameters in @query.
1655  */
1656 void
1657 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1658     guint * min_buffers, guint * max_buffers, guint * prefix,
1659     guint * alignment, GstBufferPool ** pool)
1660 {
1661   GstStructure *structure;
1662
1663   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1664
1665   structure = GST_QUERY_STRUCTURE (query);
1666   gst_structure_id_get (structure,
1667       GST_QUARK (SIZE), G_TYPE_UINT, size,
1668       GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1669       GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1670       GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1671       GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1672       GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1673 }
1674
1675 /**
1676  * gst_query_add_allocation_meta
1677  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1678  * @api: the metadata API
1679  *
1680  * Add @api as aone of the supported metadata API to @query.
1681  */
1682 void
1683 gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
1684 {
1685   GValueArray *array;
1686   const GValue *value;
1687   GValue api_value = { 0 };
1688   GstStructure *structure;
1689
1690   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1691   g_return_if_fail (api != NULL);
1692   g_return_if_fail (gst_query_is_writable (query));
1693
1694   structure = GST_QUERY_STRUCTURE (query);
1695   value = gst_structure_id_get_value (structure, GST_QUARK (META));
1696   if (value) {
1697     array = (GValueArray *) g_value_get_boxed (value);
1698   } else {
1699     GValue new_array_val = { 0, };
1700
1701     array = g_value_array_new (0);
1702
1703     g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1704     g_value_take_boxed (&new_array_val, array);
1705
1706     gst_structure_id_take_value (structure, GST_QUARK (META), &new_array_val);
1707   }
1708
1709   g_value_init (&api_value, G_TYPE_STRING);
1710   g_value_set_string (&api_value, api);
1711   g_value_array_append (array, &api_value);
1712   g_value_unset (&api_value);
1713 }
1714
1715 /**
1716  * gst_query_get_n_allocation_metas:
1717  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1718  *
1719  * Retrieve the number of values currently stored in the
1720  * meta API array of the query's structure.
1721  *
1722  * Returns: the metadata API array size as a #guint.
1723  */
1724 guint
1725 gst_query_get_n_allocation_metas (GstQuery * query)
1726 {
1727   GValueArray *array;
1728   const GValue *value;
1729   guint size = 0;
1730   GstStructure *structure;
1731
1732   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1733
1734   structure = GST_QUERY_STRUCTURE (query);
1735   value = gst_structure_id_get_value (structure, GST_QUARK (META));
1736   if (value) {
1737     array = (GValueArray *) g_value_get_boxed (value);
1738     size = array->n_values;
1739   }
1740   return size;
1741 }
1742
1743 /**
1744  * gst_query_parse_nth_allocation_meta
1745  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1746  * @index: position in the metadata API array to read
1747  *
1748  * Parse an available query and get the metadata API
1749  * at @index of the metadata API array.
1750  *
1751  * Returns: a #gchar of the metadata API at @index.
1752  */
1753 const gchar *
1754 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1755 {
1756   const GValue *value;
1757   const gchar *ret = NULL;
1758   GstStructure *structure;
1759
1760   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1761
1762   structure = GST_QUERY_STRUCTURE (query);
1763   value = gst_structure_id_get_value (structure, GST_QUARK (META));
1764   if (value) {
1765     GValueArray *meta;
1766     GValue *api_value;
1767
1768     meta = (GValueArray *) g_value_get_boxed (value);
1769     api_value = g_value_array_get_nth (meta, index);
1770
1771     if (api_value)
1772       ret = g_value_get_string (api_value);
1773   }
1774   return ret;
1775 }
1776
1777 /**
1778  * gst_query_has_allocation_meta
1779  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1780  * @api: the metadata API
1781  *
1782  * Check if @query has metadata @api set.
1783  *
1784  * Returns: TRUE when @api is in the list of metadata.
1785  */
1786 gboolean
1787 gst_query_has_allocation_meta (GstQuery * query, const gchar * api)
1788 {
1789   const GValue *value;
1790   GstStructure *structure;
1791
1792   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1793   g_return_val_if_fail (api != NULL, FALSE);
1794
1795   structure = GST_QUERY_STRUCTURE (query);
1796   value = gst_structure_id_get_value (structure, GST_QUARK (META));
1797   if (value) {
1798     GValueArray *array;
1799     GValue *api_value;
1800     guint i;
1801
1802     array = (GValueArray *) g_value_get_boxed (value);
1803     for (i = 0; i < array->n_values; i++) {
1804       api_value = g_value_array_get_nth (array, i);
1805       if (!strcmp (api, g_value_get_string (api_value)))
1806         return TRUE;
1807     }
1808   }
1809   return FALSE;
1810 }
1811
1812 /**
1813  * gst_query_add_allocation_memory
1814  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1815  * @alloc: the memory allocator
1816  *
1817  * Add @alloc as a supported memory allocator.
1818  */
1819 void
1820 gst_query_add_allocation_memory (GstQuery * query, const gchar * alloc)
1821 {
1822   GValueArray *array;
1823   const GValue *value;
1824   GValue alloc_value = { 0 };
1825   GstStructure *structure;
1826
1827   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1828   g_return_if_fail (gst_query_is_writable (query));
1829
1830   structure = GST_QUERY_STRUCTURE (query);
1831   value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1832   if (value) {
1833     array = (GValueArray *) g_value_get_boxed (value);
1834   } else {
1835     GValue new_array_val = { 0, };
1836
1837     array = g_value_array_new (0);
1838
1839     g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1840     g_value_take_boxed (&new_array_val, array);
1841
1842     gst_structure_id_take_value (structure, GST_QUARK (ALLOCATOR),
1843         &new_array_val);
1844   }
1845
1846   g_value_init (&alloc_value, G_TYPE_STRING);
1847   g_value_set_string (&alloc_value, alloc);
1848   g_value_array_append (array, &alloc_value);
1849   g_value_unset (&alloc_value);
1850 }
1851
1852 /**
1853  * gst_query_get_n_allocation_memories:
1854  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1855  *
1856  * Retrieve the number of values currently stored in the
1857  * allocator array of the query's structure.
1858  *
1859  * If no memory allocator is specified, the downstream element can handle
1860  * the default memory allocator.
1861  *
1862  * Returns: the allocator array size as a #guint.
1863  */
1864 guint
1865 gst_query_get_n_allocation_memories (GstQuery * query)
1866 {
1867   GValueArray *array;
1868   const GValue *value;
1869   guint size = 0;
1870   GstStructure *structure;
1871
1872   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1873
1874   structure = GST_QUERY_STRUCTURE (query);
1875   value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1876   if (value) {
1877     array = (GValueArray *) g_value_get_boxed (value);
1878     size = array->n_values;
1879   }
1880   return size;
1881 }
1882
1883 /**
1884  * gst_query_parse_nth_allocation_memory
1885  * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1886  * @index: position in the allocator array to read
1887  *
1888  * Parse an available query and get the alloctor
1889  * at @index of the allocator array.
1890  *
1891  * Returns: the name of the allocator at @index.
1892  */
1893 const gchar *
1894 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1895 {
1896   const GValue *value;
1897   const gchar *ret = NULL;
1898   GstStructure *structure;
1899
1900   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1901
1902   structure = GST_QUERY_STRUCTURE (query);
1903   value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1904   if (value) {
1905     GValueArray *memory;
1906     GValue *alloc_value;
1907
1908     memory = (GValueArray *) g_value_get_boxed (value);
1909     alloc_value = g_value_array_get_nth (memory, index);
1910
1911     if (alloc_value)
1912       ret = g_value_get_string (alloc_value);
1913   }
1914   return ret;
1915 }
1916
1917 /**
1918  * gst_query_new_scheduling
1919  *
1920  * Constructs a new query object for querying the scheduling properties.
1921  *
1922  * Free-function: gst_query_unref
1923  *
1924  * Returns: (transfer full): a new #GstQuery
1925  */
1926 GstQuery *
1927 gst_query_new_scheduling (void)
1928 {
1929   GstQuery *query;
1930   GstStructure *structure;
1931
1932   structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1933       GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, FALSE,
1934       GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, FALSE,
1935       GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, TRUE,
1936       GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1937       GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1938       GST_QUARK (ALIGN), G_TYPE_INT, 1, NULL);
1939   query = gst_query_new (GST_QUERY_SCHEDULING, structure);
1940
1941   return query;
1942 }
1943
1944 /**
1945  * gst_query_set_scheduling
1946  * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1947  * @pull_mode: if pull mode scheduling is supported
1948  * @random_access: if random access is possible
1949  * @sequential: if sequential access is recommended
1950  * @minsize: the suggested minimum size of pull requests
1951  * @maxsize: the suggested maximum size of pull requests
1952  * @align: the suggested alignment of pull requests
1953  *
1954  * Set the scheduling properties.
1955  */
1956 void
1957 gst_query_set_scheduling (GstQuery * query, gboolean pull_mode,
1958     gboolean random_access, gboolean sequential,
1959     gint minsize, gint maxsize, gint align)
1960 {
1961   GstStructure *structure;
1962
1963   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1964   g_return_if_fail (gst_query_is_writable (query));
1965
1966   structure = GST_QUERY_STRUCTURE (query);
1967   gst_structure_id_set (structure,
1968       GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, pull_mode,
1969       GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, random_access,
1970       GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, sequential,
1971       GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1972       GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1973       GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1974 }
1975
1976 /**
1977  * gst_query_parse_scheduling
1978  * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1979  * @pull_mode: if pull mode scheduling is supported
1980  * @random_access: if random access is possible
1981  * @sequential: if sequential access is recommended
1982  * @minsize: the suggested minimum size of pull requests
1983  * @maxsize: the suggested maximum size of pull requests:
1984  * @align: the suggested alignment of pull requests
1985  *
1986  * Set the scheduling properties.
1987  */
1988 void
1989 gst_query_parse_scheduling (GstQuery * query, gboolean * pull_mode,
1990     gboolean * random_access, gboolean * sequential,
1991     gint * minsize, gint * maxsize, gint * align)
1992 {
1993   GstStructure *structure;
1994
1995   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1996
1997   structure = GST_QUERY_STRUCTURE (query);
1998   gst_structure_id_get (structure,
1999       GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, pull_mode,
2000       GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, random_access,
2001       GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, sequential,
2002       GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2003       GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2004       GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2005 }
2006
2007 /**
2008  * gst_query_new_accept_caps
2009  * @caps: a #GstCaps
2010  *
2011  * Constructs a new query object for querying if @caps are accepted.
2012  *
2013  * Free-function: gst_query_unref
2014  *
2015  * Returns: (transfer full): a new #GstQuery
2016  */
2017 GstQuery *
2018 gst_query_new_accept_caps (GstCaps * caps)
2019 {
2020   GstQuery *query;
2021   GstStructure *structure;
2022
2023   structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2024       GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2025       GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2026   query = gst_query_new (GST_QUERY_ACCEPT_CAPS, structure);
2027
2028   return query;
2029 }
2030
2031 void
2032 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2033 {
2034   GstStructure *structure;
2035
2036   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2037
2038   structure = GST_QUERY_STRUCTURE (query);
2039   gst_structure_id_get (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2040 }
2041
2042 void
2043 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2044 {
2045   GstStructure *structure;
2046
2047   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2048   g_return_if_fail (gst_query_is_writable (query));
2049
2050   structure = GST_QUERY_STRUCTURE (query);
2051   gst_structure_id_set (structure,
2052       GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2053 }
2054
2055 void
2056 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2057 {
2058   GstStructure *structure;
2059
2060   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2061
2062   structure = GST_QUERY_STRUCTURE (query);
2063   gst_structure_id_get (structure,
2064       GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2065 }