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>
6 * gstquery.c: GstQueryType registration and Query parsing/creation
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.
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.
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.
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
30 * GstQuery functions are used to register new query types to the gstreamer
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
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.
40 * The following example shows how to query the duration of a pipeline:
43 * <title>Query duration on a pipeline</title>
47 * query = gst_query_new_duration (GST_FORMAT_TIME);
48 * res = gst_element_query (pipeline, query);
51 * gst_query_parse_duration (query, NULL, &duration);
52 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
55 * g_print ("duration query failed...");
57 * gst_query_unref (query);
61 * Last reviewed on 2006-02-14 (0.10.4)
65 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
66 * with newer GLib versions (>= 2.31.0) */
67 #define GLIB_DISABLE_DEPRECATION_WARNINGS
69 #include "gst_private.h"
73 #include "gstenumtypes.h"
76 #include "gstbufferpool.h"
78 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
79 #define GST_CAT_DEFAULT gst_query_debug
81 static GType _gst_query_type = 0;
87 GstStructure *structure;
90 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
92 /* GstQueryBufferingRange: internal struct for GArray */
97 } GstQueryBufferingRange;
106 static GstQueryQuarks query_quarks[] = {
107 {GST_QUERY_UNKNOWN, "unknown", 0},
108 {GST_QUERY_POSITION, "position", 0},
109 {GST_QUERY_DURATION, "duration", 0},
110 {GST_QUERY_LATENCY, "latency", 0},
111 {GST_QUERY_JITTER, "jitter", 0},
112 {GST_QUERY_RATE, "rate", 0},
113 {GST_QUERY_SEEKING, "seeking", 0},
114 {GST_QUERY_SEGMENT, "segment", 0},
115 {GST_QUERY_CONVERT, "convert", 0},
116 {GST_QUERY_FORMATS, "formats", 0},
117 {GST_QUERY_BUFFERING, "buffering", 0},
118 {GST_QUERY_CUSTOM, "custom", 0},
119 {GST_QUERY_URI, "uri", 0},
120 {GST_QUERY_ALLOCATION, "allocation", 0},
121 {GST_QUERY_SCHEDULING, "scheduling", 0},
122 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
123 {GST_QUERY_CAPS, "caps", 0},
124 {GST_QUERY_DRAIN, "drain", 0},
129 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
132 _priv_gst_query_initialize (void)
136 _gst_query_type = gst_query_get_type ();
138 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
140 for (i = 0; query_quarks[i].name; i++) {
141 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
146 * gst_query_type_get_name:
147 * @type: the query type
149 * Get a printable name for the given query type. Do not modify or free.
151 * Returns: a reference to the static name of the query.
154 gst_query_type_get_name (GstQueryType type)
158 for (i = 0; query_quarks[i].name; i++) {
159 if (type == query_quarks[i].type)
160 return query_quarks[i].name;
166 * gst_query_type_to_quark:
167 * @type: the query type
169 * Get the unique quark for the given query type.
171 * Returns: the quark associated with the query type
174 gst_query_type_to_quark (GstQueryType type)
178 for (i = 0; query_quarks[i].name; i++) {
179 if (type == query_quarks[i].type)
180 return query_quarks[i].quark;
186 * gst_query_type_get_flags:
187 * @type: a #GstQueryType
189 * Gets the #GstQueryTypeFlags associated with @type.
191 * Returns: a #GstQueryTypeFlags.
194 gst_query_type_get_flags (GstQueryType type)
196 GstQueryTypeFlags ret;
198 ret = type & ((1 << GST_EVENT_NUM_SHIFT) - 1);
204 _gst_query_free (GstQuery * query)
208 g_return_if_fail (query != NULL);
210 s = GST_QUERY_STRUCTURE (query);
212 gst_structure_set_parent_refcount (s, NULL);
213 gst_structure_free (s);
216 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
220 _gst_query_copy (GstQuery * query)
225 s = GST_QUERY_STRUCTURE (query);
227 s = gst_structure_copy (s);
229 copy = gst_query_new_custom (query->type, s);
235 gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
237 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
239 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
240 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
242 GST_EVENT_TYPE (query) = type;
246 * gst_query_new_position:
247 * @format: the default #GstFormat for the new query
249 * Constructs a new query stream position query object. Use gst_query_unref()
250 * when done with it. A position query is used to query the current position
251 * of playback in the streams, in some format.
253 * Free-function: gst_query_unref
255 * Returns: (transfer full): a new #GstQuery
258 gst_query_new_position (GstFormat format)
261 GstStructure *structure;
263 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
264 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
265 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
267 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
273 * gst_query_set_position:
274 * @query: a #GstQuery with query type GST_QUERY_POSITION
275 * @format: the requested #GstFormat
276 * @cur: the position to set
278 * Answer a position query by setting the requested value in the given format.
281 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
285 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
287 s = GST_QUERY_STRUCTURE (query);
288 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
289 GST_QUARK (FORMAT))));
291 gst_structure_id_set (s,
292 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
293 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
297 * gst_query_parse_position:
298 * @query: a #GstQuery
299 * @format: (out) (allow-none): the storage for the #GstFormat of the
300 * position values (may be NULL)
301 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
303 * Parse a position query, writing the format into @format, and the position
304 * into @cur, if the respective parameters are non-NULL.
307 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
309 GstStructure *structure;
311 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
313 structure = GST_QUERY_STRUCTURE (query);
316 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
317 GST_QUARK (FORMAT)));
319 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
320 GST_QUARK (CURRENT)));
325 * gst_query_new_duration:
326 * @format: the #GstFormat for this duration query
328 * Constructs a new stream duration query object to query in the given format.
329 * Use gst_query_unref() when done with it. A duration query will give the
330 * total length of the stream.
332 * Free-function: gst_query_unref
334 * Returns: (transfer full): a new #GstQuery
337 gst_query_new_duration (GstFormat format)
340 GstStructure *structure;
342 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
343 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
344 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
346 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
352 * gst_query_set_duration:
353 * @query: a #GstQuery
354 * @format: the #GstFormat for the duration
355 * @duration: the duration of the stream
357 * Answer a duration query by setting the requested value in the given format.
360 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
364 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
366 s = GST_QUERY_STRUCTURE (query);
367 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
368 GST_QUARK (FORMAT))));
369 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
370 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
374 * gst_query_parse_duration:
375 * @query: a #GstQuery
376 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
378 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
380 * Parse a duration query answer. Write the format of the duration into @format,
381 * and the value into @duration, if the respective variables are non-NULL.
384 gst_query_parse_duration (GstQuery * query, GstFormat * format,
387 GstStructure *structure;
389 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
391 structure = GST_QUERY_STRUCTURE (query);
394 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
395 GST_QUARK (FORMAT)));
397 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
398 GST_QUARK (DURATION)));
402 * gst_query_new_latency:
404 * Constructs a new latency query object.
405 * Use gst_query_unref() when done with it. A latency query is usually performed
406 * by sinks to compensate for additional latency introduced by elements in the
409 * Free-function: gst_query_unref
411 * Returns: (transfer full): a #GstQuery
416 gst_query_new_latency (void)
419 GstStructure *structure;
421 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
422 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
423 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
424 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
426 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
432 * gst_query_set_latency:
433 * @query: a #GstQuery
434 * @live: if there is a live element upstream
435 * @min_latency: the minimal latency of the upstream elements
436 * @max_latency: the maximal latency of the upstream elements
438 * Answer a latency query by setting the requested values in the given format.
443 gst_query_set_latency (GstQuery * query, gboolean live,
444 GstClockTime min_latency, GstClockTime max_latency)
446 GstStructure *structure;
448 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
450 structure = GST_QUERY_STRUCTURE (query);
451 gst_structure_id_set (structure,
452 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
453 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
454 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
458 * gst_query_parse_latency:
459 * @query: a #GstQuery
460 * @live: (out) (allow-none): storage for live or NULL
461 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
462 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
464 * Parse a latency query answer.
469 gst_query_parse_latency (GstQuery * query, gboolean * live,
470 GstClockTime * min_latency, GstClockTime * max_latency)
472 GstStructure *structure;
474 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
476 structure = GST_QUERY_STRUCTURE (query);
479 g_value_get_boolean (gst_structure_id_get_value (structure,
482 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
483 GST_QUARK (MIN_LATENCY)));
485 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
486 GST_QUARK (MAX_LATENCY)));
490 * gst_query_new_convert:
491 * @src_format: the source #GstFormat for the new query
492 * @value: the value to convert
493 * @dest_format: the target #GstFormat
495 * Constructs a new convert query object. Use gst_query_unref()
496 * when done with it. A convert query is used to ask for a conversion between
497 * one format and another.
499 * Free-function: gst_query_unref
501 * Returns: (transfer full): a #GstQuery
504 gst_query_new_convert (GstFormat src_format, gint64 value,
505 GstFormat dest_format)
508 GstStructure *structure;
510 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
511 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
512 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
513 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
514 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
516 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
522 * gst_query_set_convert:
523 * @query: a #GstQuery
524 * @src_format: the source #GstFormat
525 * @src_value: the source value
526 * @dest_format: the destination #GstFormat
527 * @dest_value: the destination value
529 * Answer a convert query by setting the requested values.
532 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
533 GstFormat dest_format, gint64 dest_value)
535 GstStructure *structure;
537 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
539 structure = GST_QUERY_STRUCTURE (query);
540 gst_structure_id_set (structure,
541 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
542 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
543 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
544 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
548 * gst_query_parse_convert:
549 * @query: a #GstQuery
550 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
551 * source value, or NULL
552 * @src_value: (out) (allow-none): the storage for the source value, or NULL
553 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
554 * destination value, or NULL
555 * @dest_value: (out) (allow-none): the storage for the destination value,
558 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
559 * and @dest_value may be NULL, in which case that value is omitted.
562 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
563 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
565 GstStructure *structure;
567 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
569 structure = GST_QUERY_STRUCTURE (query);
572 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
573 GST_QUARK (SRC_FORMAT)));
575 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
576 GST_QUARK (SRC_VALUE)));
579 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
580 GST_QUARK (DEST_FORMAT)));
582 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
583 GST_QUARK (DEST_VALUE)));
587 * gst_query_new_segment:
588 * @format: the #GstFormat for the new query
590 * Constructs a new segment query object. Use gst_query_unref()
591 * when done with it. A segment query is used to discover information about the
592 * currently configured segment for playback.
594 * Free-function: gst_query_unref
596 * Returns: (transfer full): a new #GstQuery
599 gst_query_new_segment (GstFormat format)
602 GstStructure *structure;
604 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
605 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
606 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
607 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
608 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
610 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
616 * gst_query_set_segment:
617 * @query: a #GstQuery
618 * @rate: the rate of the segment
619 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
620 * @start_value: the start value
621 * @stop_value: the stop value
623 * Answer a segment query by setting the requested values. The normal
624 * playback segment of a pipeline is 0 to duration at the default rate of
625 * 1.0. If a seek was performed on the pipeline to play a different
626 * segment, this query will return the range specified in the last seek.
628 * @start_value and @stop_value will respectively contain the configured
629 * playback range start and stop values expressed in @format.
630 * The values are always between 0 and the duration of the media and
631 * @start_value <= @stop_value. @rate will contain the playback rate. For
632 * negative rates, playback will actually happen from @stop_value to
636 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
637 gint64 start_value, gint64 stop_value)
639 GstStructure *structure;
641 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
643 structure = GST_QUERY_STRUCTURE (query);
644 gst_structure_id_set (structure,
645 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
646 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
647 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
648 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
652 * gst_query_parse_segment:
653 * @query: a #GstQuery
654 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
655 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
657 * @start_value: (out) (allow-none): the storage for the start value, or NULL
658 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
660 * Parse a segment query answer. Any of @rate, @format, @start_value, and
661 * @stop_value may be NULL, which will cause this value to be omitted.
663 * See gst_query_set_segment() for an explanation of the function arguments.
666 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
667 gint64 * start_value, gint64 * stop_value)
669 GstStructure *structure;
671 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
673 structure = GST_QUERY_STRUCTURE (query);
675 *rate = g_value_get_double (gst_structure_id_get_value (structure,
679 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
680 GST_QUARK (FORMAT)));
682 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
683 GST_QUARK (START_VALUE)));
685 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
686 GST_QUARK (STOP_VALUE)));
690 * gst_query_new_custom:
691 * @type: the query type
692 * @structure: a structure for the query
694 * Constructs a new custom query object. Use gst_query_unref()
697 * Free-function: gst_query_unref
699 * Returns: (transfer full): a new #GstQuery
702 gst_query_new_custom (GstQueryType type, GstStructure * structure)
706 query = g_slice_new0 (GstQueryImpl);
708 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
711 /* structure must not have a parent */
712 if (!gst_structure_set_parent_refcount (structure,
713 &query->query.mini_object.refcount))
716 gst_query_init (query, sizeof (GstQueryImpl), type);
718 GST_QUERY_STRUCTURE (query) = structure;
720 return GST_QUERY_CAST (query);
725 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
726 g_warning ("structure is already owned by another object");
732 * gst_query_get_structure:
733 * @query: a #GstQuery
735 * Get the structure of a query.
737 * Returns: (transfer none): the #GstStructure of the query. The structure is
738 * still owned by the query and will therefore be freed when the query
742 gst_query_get_structure (GstQuery * query)
744 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
746 return GST_QUERY_STRUCTURE (query);
750 * gst_query_writable_structure:
751 * @query: a #GstQuery
753 * Get the structure of a query. This method should be called with a writable
754 * @query so that the returned structure is guranteed to be writable.
756 * Returns: (transfer none): the #GstStructure of the query. The structure is
757 * still owned by the query and will therefore be freed when the query
761 gst_query_writable_structure (GstQuery * query)
763 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
764 g_return_val_if_fail (gst_query_is_writable (query), NULL);
766 return GST_QUERY_STRUCTURE (query);
770 * gst_query_new_seeking:
771 * @format: the default #GstFormat for the new query
773 * Constructs a new query object for querying seeking properties of
776 * Free-function: gst_query_unref
778 * Returns: (transfer full): a new #GstQuery
781 gst_query_new_seeking (GstFormat format)
784 GstStructure *structure;
786 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
787 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
788 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
789 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
790 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
792 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
798 * gst_query_set_seeking:
799 * @query: a #GstQuery
800 * @format: the format to set for the @segment_start and @segment_end values
801 * @seekable: the seekable flag to set
802 * @segment_start: the segment_start to set
803 * @segment_end: the segment_end to set
805 * Set the seeking query result fields in @query.
808 gst_query_set_seeking (GstQuery * query, GstFormat format,
809 gboolean seekable, gint64 segment_start, gint64 segment_end)
811 GstStructure *structure;
813 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
814 g_return_if_fail (gst_query_is_writable (query));
816 structure = GST_QUERY_STRUCTURE (query);
817 gst_structure_id_set (structure,
818 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
819 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
820 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
821 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
825 * gst_query_parse_seeking:
826 * @query: a GST_QUERY_SEEKING type query #GstQuery
827 * @format: (out) (allow-none): the format to set for the @segment_start
828 * and @segment_end values, or NULL
829 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
830 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
831 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
833 * Parse a seeking query, writing the format into @format, and
834 * other results into the passed parameters, if the respective parameters
838 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
839 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
841 GstStructure *structure;
843 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
845 structure = GST_QUERY_STRUCTURE (query);
848 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
849 GST_QUARK (FORMAT)));
851 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
852 GST_QUARK (SEEKABLE)));
854 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
855 GST_QUARK (SEGMENT_START)));
857 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
858 GST_QUARK (SEGMENT_END)));
862 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
863 GDestroyNotify clear_func)
868 value = gst_structure_id_get_value (s, quark);
870 array = (GArray *) g_value_get_boxed (value);
872 GValue new_array_val = { 0, };
874 array = g_array_new (FALSE, TRUE, element_size);
876 g_array_set_clear_func (array, clear_func);
878 g_value_init (&new_array_val, G_TYPE_ARRAY);
879 g_value_take_boxed (&new_array_val, array);
881 gst_structure_id_take_value (s, quark, &new_array_val);
887 * gst_query_new_formats:
889 * Constructs a new query object for querying formats of
892 * Free-function: gst_query_unref
894 * Returns: (transfer full): a new #GstQuery
899 gst_query_new_formats (void)
902 GstStructure *structure;
904 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
905 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
911 gst_query_list_add_format (GValue * list, GstFormat format)
913 GValue item = { 0, };
915 g_value_init (&item, GST_TYPE_FORMAT);
916 g_value_set_enum (&item, format);
917 gst_value_list_append_value (list, &item);
918 g_value_unset (&item);
922 * gst_query_set_formats:
923 * @query: a #GstQuery
924 * @n_formats: the number of formats to set.
925 * @...: A number of @GstFormats equal to @n_formats.
927 * Set the formats query result fields in @query. The number of formats passed
928 * must be equal to @n_formats.
931 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
934 GValue list = { 0, };
936 GstStructure *structure;
938 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
939 g_return_if_fail (gst_query_is_writable (query));
941 g_value_init (&list, GST_TYPE_LIST);
943 va_start (ap, n_formats);
944 for (i = 0; i < n_formats; i++) {
945 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
949 structure = GST_QUERY_STRUCTURE (query);
950 gst_structure_set_value (structure, "formats", &list);
952 g_value_unset (&list);
957 * gst_query_set_formatsv:
958 * @query: a #GstQuery
959 * @n_formats: the number of formats to set.
960 * @formats: (in) (array length=n_formats): an array containing @n_formats
963 * Set the formats query result fields in @query. The number of formats passed
964 * in the @formats array must be equal to @n_formats.
969 gst_query_set_formatsv (GstQuery * query, gint n_formats,
970 const GstFormat * formats)
972 GValue list = { 0, };
974 GstStructure *structure;
976 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
977 g_return_if_fail (gst_query_is_writable (query));
979 g_value_init (&list, GST_TYPE_LIST);
980 for (i = 0; i < n_formats; i++) {
981 gst_query_list_add_format (&list, formats[i]);
983 structure = GST_QUERY_STRUCTURE (query);
984 gst_structure_set_value (structure, "formats", &list);
986 g_value_unset (&list);
990 * gst_query_parse_n_formats:
991 * @query: a #GstQuery
992 * @n_formats: (out) (allow-none): the number of formats in this query.
994 * Parse the number of formats in the formats @query.
999 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1001 GstStructure *structure;
1003 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1008 structure = GST_QUERY_STRUCTURE (query);
1009 list = gst_structure_get_value (structure, "formats");
1013 *n_formats = gst_value_list_get_size (list);
1018 * gst_query_parse_nth_format:
1019 * @query: a #GstQuery
1020 * @nth: (out): the nth format to retrieve.
1021 * @format: (out) (allow-none): a pointer to store the nth format
1023 * Parse the format query and retrieve the @nth format from it into
1024 * @format. If the list contains less elements than @nth, @format will be
1025 * set to GST_FORMAT_UNDEFINED.
1028 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1030 GstStructure *structure;
1032 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1037 structure = GST_QUERY_STRUCTURE (query);
1038 list = gst_structure_get_value (structure, "formats");
1040 *format = GST_FORMAT_UNDEFINED;
1042 if (nth < gst_value_list_get_size (list)) {
1044 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1046 *format = GST_FORMAT_UNDEFINED;
1052 * gst_query_new_buffering:
1053 * @format: the default #GstFormat for the new query
1055 * Constructs a new query object for querying the buffering status of
1058 * Free-function: gst_query_unref
1060 * Returns: (transfer full): a new #GstQuery
1065 gst_query_new_buffering (GstFormat format)
1068 GstStructure *structure;
1070 /* by default, we configure the answer as no buffering with a 100% buffering
1072 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1073 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1074 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1075 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1076 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1077 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1078 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1079 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1080 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1081 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1082 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1084 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1090 * gst_query_set_buffering_percent:
1091 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1092 * @busy: if buffering is busy
1093 * @percent: a buffering percent
1095 * Set the percentage of buffered data. This is a value between 0 and 100.
1096 * The @busy indicator is %TRUE when the buffering is in progress.
1101 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1103 GstStructure *structure;
1105 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1106 g_return_if_fail (gst_query_is_writable (query));
1107 g_return_if_fail (percent >= 0 && percent <= 100);
1109 structure = GST_QUERY_STRUCTURE (query);
1110 gst_structure_id_set (structure,
1111 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1112 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1116 * gst_query_parse_buffering_percent:
1117 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1118 * @busy: (out) (allow-none): if buffering is busy, or NULL
1119 * @percent: (out) (allow-none): a buffering percent, or NULL
1121 * Get the percentage of buffered data. This is a value between 0 and 100.
1122 * The @busy indicator is %TRUE when the buffering is in progress.
1127 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1130 GstStructure *structure;
1132 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1134 structure = GST_QUERY_STRUCTURE (query);
1136 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1139 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1140 GST_QUARK (BUFFER_PERCENT)));
1144 * gst_query_set_buffering_stats:
1145 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1146 * @mode: a buffering mode
1147 * @avg_in: the average input rate
1148 * @avg_out: the average output rate
1149 * @buffering_left: amount of buffering time left
1151 * Configures the buffering stats values in @query.
1156 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1157 gint avg_in, gint avg_out, gint64 buffering_left)
1159 GstStructure *structure;
1161 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1162 g_return_if_fail (gst_query_is_writable (query));
1164 structure = GST_QUERY_STRUCTURE (query);
1165 gst_structure_id_set (structure,
1166 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1167 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1168 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1169 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1173 * gst_query_parse_buffering_stats:
1174 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1175 * @mode: (out) (allow-none): a buffering mode, or NULL
1176 * @avg_in: (out) (allow-none): the average input rate, or NULL
1177 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1178 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1180 * Extracts the buffering stats values from @query.
1185 gst_query_parse_buffering_stats (GstQuery * query,
1186 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1187 gint64 * buffering_left)
1189 GstStructure *structure;
1191 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1193 structure = GST_QUERY_STRUCTURE (query);
1195 *mode = (GstBufferingMode)
1196 g_value_get_enum (gst_structure_id_get_value (structure,
1197 GST_QUARK (BUFFERING_MODE)));
1199 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1200 GST_QUARK (AVG_IN_RATE)));
1202 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1203 GST_QUARK (AVG_OUT_RATE)));
1206 g_value_get_int64 (gst_structure_id_get_value (structure,
1207 GST_QUARK (BUFFERING_LEFT)));
1211 * gst_query_set_buffering_range:
1212 * @query: a #GstQuery
1213 * @format: the format to set for the @start and @stop values
1214 * @start: the start to set
1215 * @stop: the stop to set
1216 * @estimated_total: estimated total amount of download time
1218 * Set the available query result fields in @query.
1223 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1224 gint64 start, gint64 stop, gint64 estimated_total)
1226 GstStructure *structure;
1228 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1229 g_return_if_fail (gst_query_is_writable (query));
1231 structure = GST_QUERY_STRUCTURE (query);
1232 gst_structure_id_set (structure,
1233 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1234 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1235 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1236 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1240 * gst_query_parse_buffering_range:
1241 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1242 * @format: (out) (allow-none): the format to set for the @segment_start
1243 * and @segment_end values, or NULL
1244 * @start: (out) (allow-none): the start to set, or NULL
1245 * @stop: (out) (allow-none): the stop to set, or NULL
1246 * @estimated_total: (out) (allow-none): estimated total amount of download
1249 * Parse an available query, writing the format into @format, and
1250 * other results into the passed parameters, if the respective parameters
1256 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1257 gint64 * start, gint64 * stop, gint64 * estimated_total)
1259 GstStructure *structure;
1261 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1263 structure = GST_QUERY_STRUCTURE (query);
1266 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1267 GST_QUARK (FORMAT)));
1269 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1270 GST_QUARK (START_VALUE)));
1272 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1273 GST_QUARK (STOP_VALUE)));
1274 if (estimated_total)
1276 g_value_get_int64 (gst_structure_id_get_value (structure,
1277 GST_QUARK (ESTIMATED_TOTAL)));
1281 * gst_query_add_buffering_range:
1282 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1283 * @start: start position of the range
1284 * @stop: stop position of the range
1286 * Set the buffering-ranges array field in @query. The current last
1287 * start position of the array should be inferior to @start.
1289 * Returns: a #gboolean indicating if the range was added or not.
1294 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1296 GstQueryBufferingRange range;
1297 GstStructure *structure;
1300 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1301 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1303 if (G_UNLIKELY (start >= stop))
1306 structure = GST_QUERY_STRUCTURE (query);
1307 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1308 sizeof (GstQueryBufferingRange), NULL);
1310 if (array->len > 1) {
1311 GstQueryBufferingRange *last;
1313 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1315 if (G_UNLIKELY (start <= last->start))
1319 range.start = start;
1321 g_array_append_val (array, range);
1327 * gst_query_get_n_buffering_ranges:
1328 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1330 * Retrieve the number of values currently stored in the
1331 * buffered-ranges array of the query's structure.
1333 * Returns: the range array size as a #guint.
1338 gst_query_get_n_buffering_ranges (GstQuery * query)
1340 GstStructure *structure;
1343 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1345 structure = GST_QUERY_STRUCTURE (query);
1346 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1347 sizeof (GstQueryBufferingRange), NULL);
1354 * gst_query_parse_nth_buffering_range:
1355 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1356 * @index: position in the buffered-ranges array to read
1357 * @start: (out) (allow-none): the start position to set, or NULL
1358 * @stop: (out) (allow-none): the stop position to set, or NULL
1360 * Parse an available query and get the start and stop values stored
1361 * at the @index of the buffered ranges array.
1363 * Returns: a #gboolean indicating if the parsing succeeded.
1368 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1369 gint64 * start, gint64 * stop)
1371 GstQueryBufferingRange *range;
1372 GstStructure *structure;
1375 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1377 structure = GST_QUERY_STRUCTURE (query);
1379 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1380 sizeof (GstQueryBufferingRange), NULL);
1381 g_return_val_if_fail (index < array->len, FALSE);
1383 range = &g_array_index (array, GstQueryBufferingRange, index);
1386 *start = range->start;
1388 *stop = range->stop;
1395 * gst_query_new_uri:
1397 * Constructs a new query URI query object. Use gst_query_unref()
1398 * when done with it. An URI query is used to query the current URI
1399 * that is used by the source or sink.
1401 * Free-function: gst_query_unref
1403 * Returns: (transfer full): a new #GstQuery
1408 gst_query_new_uri (void)
1411 GstStructure *structure;
1413 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1414 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1416 query = gst_query_new_custom (GST_QUERY_URI, structure);
1422 * gst_query_set_uri:
1423 * @query: a #GstQuery with query type GST_QUERY_URI
1424 * @uri: the URI to set
1426 * Answer a URI query by setting the requested URI.
1431 gst_query_set_uri (GstQuery * query, const gchar * uri)
1433 GstStructure *structure;
1435 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1436 g_return_if_fail (gst_query_is_writable (query));
1437 g_return_if_fail (gst_uri_is_valid (uri));
1439 structure = GST_QUERY_STRUCTURE (query);
1440 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1444 * gst_query_parse_uri:
1445 * @query: a #GstQuery
1446 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1449 * Parse an URI query, writing the URI into @uri as a newly
1450 * allocated string, if the respective parameters are non-NULL.
1451 * Free the string with g_free() after usage.
1456 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1458 GstStructure *structure;
1460 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1462 structure = GST_QUERY_STRUCTURE (query);
1464 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1469 * gst_query_new_allocation:
1470 * @caps: the negotiated caps
1471 * @need_pool: return a pool
1473 * Constructs a new query object for querying the allocation properties.
1475 * Free-function: gst_query_unref
1477 * Returns: (transfer full): a new #GstQuery
1480 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1483 GstStructure *structure;
1485 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1486 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1487 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1488 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1489 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1490 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1491 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1492 GST_QUARK (PADDING), G_TYPE_UINT, 0,
1493 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1494 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1496 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1502 * gst_query_parse_allocation:
1503 * @query: a #GstQuery
1504 * @caps: (out callee-allocates) (allow-none): The #GstCaps
1505 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1507 * Parse an allocation query, writing the requested caps in @caps and
1508 * whether a pool is needed in @need_pool, if the respective parameters
1512 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1513 gboolean * need_pool)
1515 GstStructure *structure;
1517 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1519 structure = GST_QUERY_STRUCTURE (query);
1520 gst_structure_id_get (structure,
1521 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1522 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1526 * gst_query_set_allocation_params:
1527 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1529 * @min_buffers: the min buffers
1530 * @max_buffers: the max buffers
1531 * @prefix: the prefix
1532 * @padding: the padding
1533 * @alignment: the alignment
1534 * @pool: the #GstBufferPool
1536 * Set the allocation parameters in @query.
1539 gst_query_set_allocation_params (GstQuery * query, guint size,
1540 guint min_buffers, guint max_buffers, guint prefix, guint padding,
1541 guint alignment, GstBufferPool * pool)
1543 GstStructure *structure;
1545 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1546 g_return_if_fail (gst_query_is_writable (query));
1547 g_return_if_fail (((alignment + 1) & alignment) == 0);
1548 g_return_if_fail (size != 0 || pool == NULL);
1550 structure = GST_QUERY_STRUCTURE (query);
1551 gst_structure_id_set (structure,
1552 GST_QUARK (SIZE), G_TYPE_UINT, size,
1553 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1554 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1555 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1556 GST_QUARK (PADDING), G_TYPE_UINT, padding,
1557 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1558 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1562 * gst_query_parse_allocation_params:
1563 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1564 * @size: (out) (allow-none): the size
1565 * @min_buffers: (out) (allow-none): the min buffers
1566 * @max_buffers: (out) (allow-none): the max buffers
1567 * @prefix: (out) (allow-none): the prefix
1568 * @padding: (out) (allow-none): the padding
1569 * @alignment: (out) (allow-none): the alignment
1570 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1572 * Get the allocation parameters in @query.
1575 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1576 guint * min_buffers, guint * max_buffers, guint * prefix,
1577 guint * padding, guint * alignment, GstBufferPool ** pool)
1579 GstStructure *structure;
1581 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1583 structure = GST_QUERY_STRUCTURE (query);
1584 gst_structure_id_get (structure,
1585 GST_QUARK (SIZE), G_TYPE_UINT, size,
1586 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1587 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1588 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1589 GST_QUARK (PADDING), G_TYPE_UINT, padding,
1590 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1591 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1595 * gst_query_add_allocation_meta:
1596 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1597 * @api: the metadata API
1599 * Add @api as aone of the supported metadata API to @query.
1602 gst_query_add_allocation_meta (GstQuery * query, GType api)
1605 GstStructure *structure;
1607 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1608 g_return_if_fail (api != 0);
1609 g_return_if_fail (gst_query_is_writable (query));
1611 structure = GST_QUERY_STRUCTURE (query);
1612 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1614 g_array_append_val (array, api);
1618 * gst_query_get_n_allocation_metas:
1619 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1621 * Retrieve the number of values currently stored in the
1622 * meta API array of the query's structure.
1624 * Returns: the metadata API array size as a #guint.
1627 gst_query_get_n_allocation_metas (GstQuery * query)
1630 GstStructure *structure;
1632 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1634 structure = GST_QUERY_STRUCTURE (query);
1635 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1641 * gst_query_parse_nth_allocation_meta:
1642 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1643 * @index: position in the metadata API array to read
1645 * Parse an available query and get the metadata API
1646 * at @index of the metadata API array.
1648 * Returns: a #GType of the metadata API at @index.
1651 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1654 GstStructure *structure;
1656 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1658 structure = GST_QUERY_STRUCTURE (query);
1659 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1661 g_return_val_if_fail (index < array->len, 0);
1663 return g_array_index (array, GType, index);
1667 * gst_query_remove_nth_allocation_meta:
1668 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1669 * @index: position in the metadata API array to remove
1671 * Remove the metadata API at @index of the metadata API array.
1674 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1677 GstStructure *structure;
1679 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1680 g_return_if_fail (gst_query_is_writable (query));
1682 structure = GST_QUERY_STRUCTURE (query);
1683 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1684 g_return_if_fail (index < array->len);
1686 g_array_remove_index (array, index);
1690 * gst_query_has_allocation_meta:
1691 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1692 * @api: the metadata API
1694 * Check if @query has metadata @api set.
1696 * Returns: TRUE when @api is in the list of metadata.
1699 gst_query_has_allocation_meta (GstQuery * query, GType api)
1702 GstStructure *structure;
1705 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1706 g_return_val_if_fail (api != 0, FALSE);
1708 structure = GST_QUERY_STRUCTURE (query);
1709 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1712 for (i = 0; i < len; i++) {
1713 if (g_array_index (array, GType, i) == api)
1720 * gst_query_add_allocation_memory:
1721 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1722 * @allocator: the memory allocator
1724 * Add @allocator as a supported memory allocator.
1727 gst_query_add_allocation_memory (GstQuery * query, GstAllocator * allocator)
1730 GstStructure *structure;
1732 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1733 g_return_if_fail (gst_query_is_writable (query));
1734 g_return_if_fail (allocator != NULL);
1736 structure = GST_QUERY_STRUCTURE (query);
1738 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1739 (GDestroyNotify) gst_allocator_unref);
1741 g_array_append_val (array, allocator);
1745 * gst_query_get_n_allocation_memories:
1746 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1748 * Retrieve the number of values currently stored in the
1749 * allocator array of the query's structure.
1751 * If no memory allocator is specified, the downstream element can handle
1752 * the default memory allocator.
1754 * Returns: the allocator array size as a #guint.
1757 gst_query_get_n_allocation_memories (GstQuery * query)
1760 GstStructure *structure;
1762 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1764 structure = GST_QUERY_STRUCTURE (query);
1766 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1767 (GDestroyNotify) gst_allocator_unref);
1773 * gst_query_parse_nth_allocation_memory:
1774 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1775 * @index: position in the allocator array to read
1777 * Parse an available query and get the alloctor
1778 * at @index of the allocator array.
1780 * Returns: (transfer none): the allocator at @index. The allocator remains
1781 * valid for as long as @query is valid.
1784 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1787 GstStructure *structure;
1789 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1791 structure = GST_QUERY_STRUCTURE (query);
1793 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1794 (GDestroyNotify) gst_allocator_unref);
1795 g_return_val_if_fail (index < array->len, NULL);
1797 return g_array_index (array, GstAllocator *, index);
1801 * gst_query_new_scheduling:
1803 * Constructs a new query object for querying the scheduling properties.
1805 * Free-function: gst_query_unref
1807 * Returns: (transfer full): a new #GstQuery
1810 gst_query_new_scheduling (void)
1813 GstStructure *structure;
1815 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1816 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1817 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1818 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1819 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1820 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
1826 * gst_query_set_scheduling:
1827 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1828 * @flags: #GstSchedulingFlags
1829 * @minsize: the suggested minimum size of pull requests
1830 * @maxsize: the suggested maximum size of pull requests
1831 * @align: the suggested alignment of pull requests
1833 * Set the scheduling properties.
1836 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1837 gint minsize, gint maxsize, gint align)
1839 GstStructure *structure;
1841 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1842 g_return_if_fail (gst_query_is_writable (query));
1844 structure = GST_QUERY_STRUCTURE (query);
1845 gst_structure_id_set (structure,
1846 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1847 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1848 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1849 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1853 * gst_query_parse_scheduling:
1854 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1855 * @flags: (out) (allow-none): #GstSchedulingFlags
1856 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
1857 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
1858 * @align: (out) (allow-none): the suggested alignment of pull requests
1860 * Set the scheduling properties.
1863 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
1864 gint * minsize, gint * maxsize, gint * align)
1866 GstStructure *structure;
1868 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1870 structure = GST_QUERY_STRUCTURE (query);
1871 gst_structure_id_get (structure,
1872 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1873 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1874 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1875 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1879 * gst_query_add_scheduling_mode:
1880 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1881 * @mode: a #GstPadMode
1883 * Add @mode as aone of the supported scheduling modes to @query.
1886 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
1888 GstStructure *structure;
1891 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1892 g_return_if_fail (gst_query_is_writable (query));
1894 structure = GST_QUERY_STRUCTURE (query);
1896 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
1898 g_array_append_val (array, mode);
1902 * gst_query_get_n_scheduling_modes:
1903 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1905 * Retrieve the number of values currently stored in the
1906 * scheduling mode array of the query's structure.
1908 * Returns: the scheduling mode array size as a #guint.
1911 gst_query_get_n_scheduling_modes (GstQuery * query)
1914 GstStructure *structure;
1916 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
1918 structure = GST_QUERY_STRUCTURE (query);
1920 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
1926 * gst_query_parse_nth_scheduling_mode:
1927 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1928 * @index: position in the scheduling modes array to read
1930 * Parse an available query and get the scheduling mode
1931 * at @index of the scheduling modes array.
1933 * Returns: a #GstPadMode of the scheduling mode at @index.
1936 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
1938 GstStructure *structure;
1941 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
1944 structure = GST_QUERY_STRUCTURE (query);
1946 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
1947 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
1949 return g_array_index (array, GstPadMode, index);
1953 * gst_query_has_scheduling_mode:
1954 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1955 * @mode: the scheduling mode
1957 * Check if @query has scheduling mode set.
1959 * Returns: TRUE when @mode is in the list of scheduling modes.
1962 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
1964 GstStructure *structure;
1968 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
1970 structure = GST_QUERY_STRUCTURE (query);
1972 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
1975 for (i = 0; i < len; i++) {
1976 if (mode == g_array_index (array, GstPadMode, i))
1983 * gst_query_new_accept_caps:
1986 * Constructs a new query object for querying if @caps are accepted.
1988 * Free-function: gst_query_unref
1990 * Returns: (transfer full): a new #GstQuery
1993 gst_query_new_accept_caps (GstCaps * caps)
1996 GstStructure *structure;
1998 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
1999 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2000 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2001 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2007 * gst_query_parse_accept_caps:
2008 * @query: The query to parse
2009 * @caps: (out): A pointer to the caps
2011 * Get the caps from @query. The caps remains valid as long as @query remains
2015 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2017 GstStructure *structure;
2019 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2020 g_return_if_fail (caps != NULL);
2022 structure = GST_QUERY_STRUCTURE (query);
2023 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2028 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2030 GstStructure *structure;
2032 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2033 g_return_if_fail (gst_query_is_writable (query));
2035 structure = GST_QUERY_STRUCTURE (query);
2036 gst_structure_id_set (structure,
2037 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2041 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2043 GstStructure *structure;
2045 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2047 structure = GST_QUERY_STRUCTURE (query);
2048 gst_structure_id_get (structure,
2049 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2053 * gst_query_new_caps:
2056 * Constructs a new query object for querying the caps.
2058 * The CAPS query should return the* allowable caps for a pad in the context
2059 * of the element's state, its link to other elements, and the devices or files
2060 * it has opened. These caps must be a subset of the pad template caps. In the
2061 * NULL state with no links, the CAPS query should ideally return the same caps
2062 * as the pad template. In rare circumstances, an object property can affect
2063 * the caps returned by the CAPS query, but this is discouraged.
2065 * For most filters, the caps returned by CAPS query is directly affected by the
2066 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2067 * the srcpad's getcaps function is directly related to the stream data. Again,
2068 * the CAPS query should return the most specific caps it reasonably can, since this
2069 * helps with autoplugging.
2071 * Free-function: gst_query_unref
2073 * Returns: (transfer full): a new #GstQuery
2076 gst_query_new_caps (GstCaps * filter)
2079 GstStructure *structure;
2081 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2082 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2083 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2084 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2090 * gst_query_parse_caps:
2091 * @query: The query to parse
2092 * @filter: (out): A pointer to the caps filter
2094 * Get the filter from the caps @query. The caps remains valid as long as
2095 * @query remains valid.
2098 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2100 GstStructure *structure;
2102 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2103 g_return_if_fail (filter != NULL);
2105 structure = GST_QUERY_STRUCTURE (query);
2106 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2107 GST_QUARK (FILTER)));
2111 * gst_query_set_caps_result:
2112 * @query: The query to use
2113 * @caps: (in): A pointer to the caps
2115 * Set the @caps result in @query.
2118 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2120 GstStructure *structure;
2122 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2123 g_return_if_fail (gst_query_is_writable (query));
2125 structure = GST_QUERY_STRUCTURE (query);
2126 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2130 * gst_query_parse_caps_result:
2131 * @query: The query to parse
2132 * @caps: (out): A pointer to the caps
2134 * Get the caps result from @query. The caps remains valid as long as
2135 * @query remains valid.
2138 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2140 GstStructure *structure;
2142 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2143 g_return_if_fail (caps != NULL);
2145 structure = GST_QUERY_STRUCTURE (query);
2146 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2151 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2152 GstCapsIntersectMode mode)
2154 GstCaps *res, *caps = NULL;
2156 gst_query_parse_caps_result (query, &caps);
2157 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2158 gst_query_set_caps_result (query, res);
2159 gst_caps_unref (res);
2163 * gst_query_new_drain:
2165 * Constructs a new query object for querying the drain state.
2167 * Free-function: gst_query_unref
2169 * Returns: (transfer full): a new #GstQuery
2172 gst_query_new_drain (void)
2175 GstStructure *structure;
2177 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2178 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);