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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
27 * @short_description: Provide functions to create queries, and to set and parse
29 * @see_also: #GstPad, #GstElement
31 * Queries can be performed on pads (gst_pad_query()) and elements
32 * (gst_element_query()). Please note that some queries might need a running
35 * Queries can be created using the gst_query_new_*() functions.
36 * Query values can be set using gst_query_set_*(), and parsed using
37 * gst_query_parse_*() helpers.
39 * The following example shows how to query the duration of a pipeline:
40 * |[<!-- language="C" -->
43 * query = gst_query_new_duration (GST_FORMAT_TIME);
44 * res = gst_element_query (pipeline, query);
47 * gst_query_parse_duration (query, NULL, &duration);
48 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
50 * g_print ("duration query failed...");
52 * gst_query_unref (query);
56 #define GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS
57 #include "gst_private.h"
61 #include "gstenumtypes.h"
64 #include "gstbufferpool.h"
65 #ifdef TIZEN_PROFILE_TV
69 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
70 #define GST_CAT_DEFAULT gst_query_debug
72 GType _gst_query_type = 0;
78 GstStructure *structure;
81 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
91 static GstQueryQuarks query_quarks[] = {
92 {GST_QUERY_UNKNOWN, "unknown", 0},
93 {GST_QUERY_POSITION, "position", 0},
94 {GST_QUERY_DURATION, "duration", 0},
95 {GST_QUERY_LATENCY, "latency", 0},
96 {GST_QUERY_JITTER, "jitter", 0},
97 {GST_QUERY_RATE, "rate", 0},
98 {GST_QUERY_SEEKING, "seeking", 0},
99 {GST_QUERY_SEGMENT, "segment", 0},
100 {GST_QUERY_CONVERT, "convert", 0},
101 {GST_QUERY_FORMATS, "formats", 0},
102 {GST_QUERY_BUFFERING, "buffering", 0},
103 {GST_QUERY_CUSTOM, "custom", 0},
104 {GST_QUERY_URI, "uri", 0},
105 {GST_QUERY_ALLOCATION, "allocation", 0},
106 {GST_QUERY_SCHEDULING, "scheduling", 0},
107 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
108 {GST_QUERY_CAPS, "caps", 0},
109 {GST_QUERY_DRAIN, "drain", 0},
110 {GST_QUERY_CONTEXT, "context", 0},
111 {GST_QUERY_BITRATE, "bitrate", 0},
112 #ifdef TIZEN_PROFILE_TV
113 {GST_QUERY_RESOURCE, "resource", 0},
115 {GST_QUERY_SELECTABLE, "selectable", 0},
119 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
122 _priv_gst_query_initialize (void)
126 _gst_query_type = gst_query_get_type ();
128 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
130 for (i = 0; query_quarks[i].name; i++) {
131 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
136 * gst_query_type_get_name:
137 * @type: the query type
139 * Get a printable name for the given query type. Do not modify or free.
141 * Returns: a reference to the static name of the query.
144 gst_query_type_get_name (GstQueryType type)
148 for (i = 0; query_quarks[i].name; i++) {
149 if (type == query_quarks[i].type)
150 return query_quarks[i].name;
156 * gst_query_type_to_quark:
157 * @type: the query type
159 * Get the unique quark for the given query type.
161 * Returns: the quark associated with the query type
164 gst_query_type_to_quark (GstQueryType type)
168 for (i = 0; query_quarks[i].name; i++) {
169 if (type == query_quarks[i].type)
170 return query_quarks[i].quark;
176 * gst_query_type_get_flags:
177 * @type: a #GstQueryType
179 * Gets the #GstQueryTypeFlags associated with @type.
181 * Returns: a #GstQueryTypeFlags.
184 gst_query_type_get_flags (GstQueryType type)
186 GstQueryTypeFlags ret;
188 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
194 _gst_query_free (GstQuery * query)
198 g_return_if_fail (query != NULL);
200 s = GST_QUERY_STRUCTURE (query);
202 gst_structure_set_parent_refcount (s, NULL);
203 gst_structure_free (s);
206 memset (query, 0xff, sizeof (GstQueryImpl));
209 g_slice_free1 (sizeof (GstQueryImpl), query);
213 _gst_query_copy (GstQuery * query)
218 s = GST_QUERY_STRUCTURE (query);
220 s = gst_structure_copy (s);
222 copy = gst_query_new_custom (query->type, s);
228 * gst_query_new_position:
229 * @format: the default #GstFormat for the new query
231 * Constructs a new query stream position query object. Use gst_query_unref()
232 * when done with it. A position query is used to query the current position
233 * of playback in the streams, in some format.
235 * Free-function: gst_query_unref()
237 * Returns: (transfer full): a new #GstQuery
240 gst_query_new_position (GstFormat format)
243 GstStructure *structure;
245 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
246 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
247 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
249 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
255 * gst_query_set_position:
256 * @query: a #GstQuery with query type GST_QUERY_POSITION
257 * @format: the requested #GstFormat
258 * @cur: the position to set
260 * Answer a position query by setting the requested value in the given format.
263 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
267 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
269 s = GST_QUERY_STRUCTURE (query);
270 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
271 GST_QUARK (FORMAT))));
273 gst_structure_id_set (s,
274 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
275 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
279 * gst_query_parse_position:
280 * @query: a #GstQuery
281 * @format: (out) (optional): the storage for the #GstFormat of the
282 * position values (may be %NULL)
283 * @cur: (out) (optional): the storage for the current position (may be %NULL)
285 * Parse a position query, writing the format into @format, and the position
286 * into @cur, if the respective parameters are non-%NULL.
289 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
291 GstStructure *structure;
293 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
295 structure = GST_QUERY_STRUCTURE (query);
298 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
299 GST_QUARK (FORMAT)));
301 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
302 GST_QUARK (CURRENT)));
307 * gst_query_new_duration:
308 * @format: the #GstFormat for this duration query
310 * Constructs a new stream duration query object to query in the given format.
311 * Use gst_query_unref() when done with it. A duration query will give the
312 * total length of the stream.
314 * Free-function: gst_query_unref()
316 * Returns: (transfer full): a new #GstQuery
319 gst_query_new_duration (GstFormat format)
322 GstStructure *structure;
324 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
325 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
326 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
328 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
334 * gst_query_set_duration:
335 * @query: a #GstQuery
336 * @format: the #GstFormat for the duration
337 * @duration: the duration of the stream
339 * Answer a duration query by setting the requested value in the given format.
342 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
346 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
348 s = GST_QUERY_STRUCTURE (query);
349 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
350 GST_QUARK (FORMAT))));
351 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
352 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
356 * gst_query_parse_duration:
357 * @query: a #GstQuery
358 * @format: (out) (optional): the storage for the #GstFormat of the duration
360 * @duration: (out) (optional): the storage for the total duration, or %NULL.
362 * Parse a duration query answer. Write the format of the duration into @format,
363 * and the value into @duration, if the respective variables are non-%NULL.
366 gst_query_parse_duration (GstQuery * query, GstFormat * format,
369 GstStructure *structure;
371 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
373 structure = GST_QUERY_STRUCTURE (query);
376 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
377 GST_QUARK (FORMAT)));
379 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
380 GST_QUARK (DURATION)));
384 * gst_query_new_latency:
386 * Constructs a new latency query object.
387 * Use gst_query_unref() when done with it. A latency query is usually performed
388 * by sinks to compensate for additional latency introduced by elements in the
391 * Free-function: gst_query_unref()
393 * Returns: (transfer full): a #GstQuery
396 gst_query_new_latency (void)
399 GstStructure *structure;
401 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
402 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
403 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
404 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, GST_CLOCK_TIME_NONE, NULL);
406 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
412 * gst_query_set_latency:
413 * @query: a #GstQuery
414 * @live: if there is a live element upstream
415 * @min_latency: the minimal latency of the upstream elements
416 * @max_latency: the maximal latency of the upstream elements
418 * Answer a latency query by setting the requested values in the given format.
421 gst_query_set_latency (GstQuery * query, gboolean live,
422 GstClockTime min_latency, GstClockTime max_latency)
424 GstStructure *structure;
426 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
427 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
429 structure = GST_QUERY_STRUCTURE (query);
430 gst_structure_id_set (structure,
431 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
432 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
433 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
437 * gst_query_parse_latency:
438 * @query: a #GstQuery
439 * @live: (out) (optional): storage for live or %NULL
440 * @min_latency: (out) (optional): the storage for the min latency or %NULL
441 * @max_latency: (out) (optional): the storage for the max latency or %NULL
443 * Parse a latency query answer.
446 gst_query_parse_latency (GstQuery * query, gboolean * live,
447 GstClockTime * min_latency, GstClockTime * max_latency)
449 GstStructure *structure;
451 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
453 structure = GST_QUERY_STRUCTURE (query);
456 g_value_get_boolean (gst_structure_id_get_value (structure,
459 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
460 GST_QUARK (MIN_LATENCY)));
462 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
463 GST_QUARK (MAX_LATENCY)));
467 * gst_query_new_convert:
468 * @src_format: the source #GstFormat for the new query
469 * @value: the value to convert
470 * @dest_format: the target #GstFormat
472 * Constructs a new convert query object. Use gst_query_unref()
473 * when done with it. A convert query is used to ask for a conversion between
474 * one format and another.
476 * Free-function: gst_query_unref()
478 * Returns: (transfer full): a #GstQuery
481 gst_query_new_convert (GstFormat src_format, gint64 value,
482 GstFormat dest_format)
485 GstStructure *structure;
487 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
488 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
489 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
490 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
491 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
493 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
499 * gst_query_set_convert:
500 * @query: a #GstQuery
501 * @src_format: the source #GstFormat
502 * @src_value: the source value
503 * @dest_format: the destination #GstFormat
504 * @dest_value: the destination value
506 * Answer a convert query by setting the requested values.
509 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
510 GstFormat dest_format, gint64 dest_value)
512 GstStructure *structure;
514 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
516 structure = GST_QUERY_STRUCTURE (query);
517 gst_structure_id_set (structure,
518 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
519 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
520 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
521 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
525 * gst_query_parse_convert:
526 * @query: a #GstQuery
527 * @src_format: (out) (optional): the storage for the #GstFormat of the
528 * source value, or %NULL
529 * @src_value: (out) (optional): the storage for the source value, or %NULL
530 * @dest_format: (out) (optional): the storage for the #GstFormat of the
531 * destination value, or %NULL
532 * @dest_value: (out) (optional): the storage for the destination value,
535 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
536 * and @dest_value may be %NULL, in which case that value is omitted.
539 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
540 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
542 GstStructure *structure;
544 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
546 structure = GST_QUERY_STRUCTURE (query);
549 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
550 GST_QUARK (SRC_FORMAT)));
552 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
553 GST_QUARK (SRC_VALUE)));
556 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
557 GST_QUARK (DEST_FORMAT)));
559 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
560 GST_QUARK (DEST_VALUE)));
564 * gst_query_new_segment:
565 * @format: the #GstFormat for the new query
567 * Constructs a new segment query object. Use gst_query_unref()
568 * when done with it. A segment query is used to discover information about the
569 * currently configured segment for playback.
571 * Free-function: gst_query_unref()
573 * Returns: (transfer full): a new #GstQuery
576 gst_query_new_segment (GstFormat format)
579 GstStructure *structure;
581 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
582 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
583 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
584 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
585 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
587 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
592 #ifdef TIZEN_PROFILE_TV
594 * gst_query_new_resource:
595 * @resources: pointer to store the resources
597 * Constructs a new query stream position query object. Use
599 * when done with it. A resource query is used to query the resources used
600 * by the element/bin/pipelein
602 * Free-function: gst_query_unref
604 * Returns: (transfer full): a new #GstQuery
607 gst_query_new_resource (gchar * resources)
610 GstStructure *structure;
612 structure = gst_structure_new_id (GST_QUARK (QUERY_RESOURCE),
613 GST_QUARK (QUERY_RESOURCE), G_TYPE_POINTER, resources, NULL);
615 query = gst_query_new_custom (GST_QUERY_RESOURCE, structure);
621 * gst_query_add_resource:
622 * @query: a #GstQuery
623 * @resource: resource data to add
626 gst_query_add_resource (GstQuery * query, gint resource_id)
628 gchar *resource_info;
629 resource_info = gst_query_parse_resource (query);
630 sprintf (resource_info, "%d", resource_id);
633 /* gst_query_parse_resources:
634 * @query: a #GstQuery
635 * @resources: (out) the storage for the resource
639 gst_query_parse_resource (GstQuery * query)
641 GstStructure *structure;
643 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_RESOURCE, NULL);
645 structure = GST_QUERY_STRUCTURE (query);
646 resources = g_value_get_pointer (gst_structure_id_get_value (structure,
647 GST_QUARK (QUERY_RESOURCE)));
653 * gst_query_set_segment:
654 * @query: a #GstQuery
655 * @rate: the rate of the segment
656 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
657 * @start_value: the start value
658 * @stop_value: the stop value
660 * Answer a segment query by setting the requested values. The normal
661 * playback segment of a pipeline is 0 to duration at the default rate of
662 * 1.0. If a seek was performed on the pipeline to play a different
663 * segment, this query will return the range specified in the last seek.
665 * @start_value and @stop_value will respectively contain the configured
666 * playback range start and stop values expressed in @format.
667 * The values are always between 0 and the duration of the media and
668 * @start_value <= @stop_value. @rate will contain the playback rate. For
669 * negative rates, playback will actually happen from @stop_value to
673 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
674 gint64 start_value, gint64 stop_value)
676 GstStructure *structure;
678 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
680 structure = GST_QUERY_STRUCTURE (query);
681 gst_structure_id_set (structure,
682 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
683 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
684 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
685 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
689 * gst_query_parse_segment:
690 * @query: a #GstQuery
691 * @rate: (out) (optional): the storage for the rate of the segment, or %NULL
692 * @format: (out) (optional): the storage for the #GstFormat of the values,
694 * @start_value: (out) (optional): the storage for the start value, or %NULL
695 * @stop_value: (out) (optional): the storage for the stop value, or %NULL
697 * Parse a segment query answer. Any of @rate, @format, @start_value, and
698 * @stop_value may be %NULL, which will cause this value to be omitted.
700 * See gst_query_set_segment() for an explanation of the function arguments.
703 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
704 gint64 * start_value, gint64 * stop_value)
706 GstStructure *structure;
708 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
710 structure = GST_QUERY_STRUCTURE (query);
712 *rate = g_value_get_double (gst_structure_id_get_value (structure,
716 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
717 GST_QUARK (FORMAT)));
719 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
720 GST_QUARK (START_VALUE)));
722 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
723 GST_QUARK (STOP_VALUE)));
727 * gst_query_new_custom:
728 * @type: the query type
729 * @structure: (nullable) (transfer full): a structure for the query
731 * Constructs a new custom query object. Use gst_query_unref()
734 * Free-function: gst_query_unref()
736 * Returns: (transfer full): a new #GstQuery
739 gst_query_new_custom (GstQueryType type, GstStructure * structure)
743 query = g_slice_new0 (GstQueryImpl);
745 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
748 /* structure must not have a parent */
749 if (!gst_structure_set_parent_refcount (structure,
750 &query->query.mini_object.refcount))
754 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
755 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
756 (GstMiniObjectFreeFunction) _gst_query_free);
758 GST_QUERY_TYPE (query) = type;
759 GST_QUERY_STRUCTURE (query) = structure;
761 return GST_QUERY_CAST (query);
766 g_slice_free1 (sizeof (GstQueryImpl), query);
767 g_warning ("structure is already owned by another object");
773 * gst_query_get_structure:
774 * @query: a #GstQuery
776 * Get the structure of a query.
778 * Returns: (transfer none) (nullable): the #GstStructure of the query. The
779 * structure is still owned by the query and will therefore be freed when the
783 gst_query_get_structure (GstQuery * query)
785 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
787 return GST_QUERY_STRUCTURE (query);
791 * gst_query_writable_structure:
792 * @query: a #GstQuery
794 * Get the structure of a query. This method should be called with a writable
795 * @query so that the returned structure is guaranteed to be writable.
797 * Returns: (transfer none): the #GstStructure of the query. The structure is
798 * still owned by the query and will therefore be freed when the query
802 gst_query_writable_structure (GstQuery * query)
804 GstStructure *structure;
806 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
807 g_return_val_if_fail (gst_query_is_writable (query), NULL);
809 structure = GST_QUERY_STRUCTURE (query);
811 if (structure == NULL) {
813 gst_structure_new_id_empty (gst_query_type_to_quark (GST_QUERY_TYPE
815 gst_structure_set_parent_refcount (structure, &query->mini_object.refcount);
816 GST_QUERY_STRUCTURE (query) = structure;
822 * gst_query_new_seeking:
823 * @format: the default #GstFormat for the new query
825 * Constructs a new query object for querying seeking properties of
828 * Free-function: gst_query_unref()
830 * Returns: (transfer full): a new #GstQuery
833 gst_query_new_seeking (GstFormat format)
836 GstStructure *structure;
838 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
839 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
840 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
841 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
842 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
844 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
850 * gst_query_set_seeking:
851 * @query: a #GstQuery
852 * @format: the format to set for the @segment_start and @segment_end values
853 * @seekable: the seekable flag to set
854 * @segment_start: the segment_start to set
855 * @segment_end: the segment_end to set
857 * Set the seeking query result fields in @query.
860 gst_query_set_seeking (GstQuery * query, GstFormat format,
861 gboolean seekable, gint64 segment_start, gint64 segment_end)
863 GstStructure *structure;
865 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
866 g_return_if_fail (gst_query_is_writable (query));
868 structure = GST_QUERY_STRUCTURE (query);
869 gst_structure_id_set (structure,
870 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
871 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
872 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
873 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
877 * gst_query_parse_seeking:
878 * @query: a GST_QUERY_SEEKING type query #GstQuery
879 * @format: (out) (optional): the format to set for the @segment_start
880 * and @segment_end values, or %NULL
881 * @seekable: (out) (optional): the seekable flag to set, or %NULL
882 * @segment_start: (out) (optional): the segment_start to set, or %NULL
883 * @segment_end: (out) (optional): the segment_end to set, or %NULL
885 * Parse a seeking query, writing the format into @format, and
886 * other results into the passed parameters, if the respective parameters
890 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
891 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
893 GstStructure *structure;
895 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
897 structure = GST_QUERY_STRUCTURE (query);
900 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
901 GST_QUARK (FORMAT)));
903 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
904 GST_QUARK (SEEKABLE)));
906 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
907 GST_QUARK (SEGMENT_START)));
909 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
910 GST_QUARK (SEGMENT_END)));
914 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
915 GDestroyNotify clear_func)
920 value = gst_structure_id_get_value (s, quark);
922 array = (GArray *) g_value_get_boxed (value);
924 GValue new_array_val = { 0, };
926 array = g_array_new (FALSE, TRUE, element_size);
928 g_array_set_clear_func (array, clear_func);
930 g_value_init (&new_array_val, G_TYPE_ARRAY);
931 g_value_take_boxed (&new_array_val, array);
933 gst_structure_id_take_value (s, quark, &new_array_val);
939 * gst_query_new_formats:
941 * Constructs a new query object for querying formats of
944 * Free-function: gst_query_unref()
946 * Returns: (transfer full): a new #GstQuery
949 gst_query_new_formats (void)
952 GstStructure *structure;
954 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
955 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
961 gst_query_list_add_format (GValue * list, GstFormat format)
963 GValue item = { 0, };
965 g_value_init (&item, GST_TYPE_FORMAT);
966 g_value_set_enum (&item, format);
967 gst_value_list_append_value (list, &item);
968 g_value_unset (&item);
972 * gst_query_set_formats:
973 * @query: a #GstQuery
974 * @n_formats: the number of formats to set.
975 * @...: A number of @GstFormats equal to @n_formats.
977 * Set the formats query result fields in @query. The number of formats passed
978 * must be equal to @n_formats.
981 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
984 GValue list = { 0, };
986 GstStructure *structure;
988 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
989 g_return_if_fail (gst_query_is_writable (query));
991 g_value_init (&list, GST_TYPE_LIST);
993 va_start (ap, n_formats);
994 for (i = 0; i < n_formats; i++) {
995 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
999 structure = GST_QUERY_STRUCTURE (query);
1000 gst_structure_set_value (structure, "formats", &list);
1002 g_value_unset (&list);
1007 * gst_query_set_formatsv:
1008 * @query: a #GstQuery
1009 * @n_formats: the number of formats to set.
1010 * @formats: (in) (array length=n_formats): an array containing @n_formats
1011 * @GstFormat values.
1013 * Set the formats query result fields in @query. The number of formats passed
1014 * in the @formats array must be equal to @n_formats.
1017 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1018 const GstFormat * formats)
1020 GValue list = { 0, };
1022 GstStructure *structure;
1024 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1025 g_return_if_fail (gst_query_is_writable (query));
1027 g_value_init (&list, GST_TYPE_LIST);
1028 for (i = 0; i < n_formats; i++) {
1029 gst_query_list_add_format (&list, formats[i]);
1031 structure = GST_QUERY_STRUCTURE (query);
1032 gst_structure_set_value (structure, "formats", &list);
1034 g_value_unset (&list);
1038 * gst_query_parse_n_formats:
1039 * @query: a #GstQuery
1040 * @n_formats: (out) (optional): the number of formats in this query.
1042 * Parse the number of formats in the formats @query.
1045 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1047 GstStructure *structure;
1049 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1054 structure = GST_QUERY_STRUCTURE (query);
1055 list = gst_structure_get_value (structure, "formats");
1059 *n_formats = gst_value_list_get_size (list);
1064 * gst_query_parse_nth_format:
1065 * @query: a #GstQuery
1066 * @nth: the nth format to retrieve.
1067 * @format: (out) (optional): a pointer to store the nth format
1069 * Parse the format query and retrieve the @nth format from it into
1070 * @format. If the list contains less elements than @nth, @format will be
1071 * set to GST_FORMAT_UNDEFINED.
1074 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1076 GstStructure *structure;
1078 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1083 structure = GST_QUERY_STRUCTURE (query);
1084 list = gst_structure_get_value (structure, "formats");
1086 *format = GST_FORMAT_UNDEFINED;
1088 if (nth < gst_value_list_get_size (list)) {
1090 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1092 *format = GST_FORMAT_UNDEFINED;
1098 * gst_query_new_buffering:
1099 * @format: the default #GstFormat for the new query
1101 * Constructs a new query object for querying the buffering status of
1104 * Free-function: gst_query_unref()
1106 * Returns: (transfer full): a new #GstQuery
1109 gst_query_new_buffering (GstFormat format)
1112 GstStructure *structure;
1114 /* by default, we configure the answer as no buffering with a 100% buffering
1116 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1117 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1118 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1119 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1120 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1121 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1122 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1123 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1124 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1125 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1126 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1128 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1134 * gst_query_set_buffering_percent:
1135 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1136 * @busy: if buffering is busy
1137 * @percent: a buffering percent
1139 * Set the percentage of buffered data. This is a value between 0 and 100.
1140 * The @busy indicator is %TRUE when the buffering is in progress.
1143 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1145 GstStructure *structure;
1147 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1148 g_return_if_fail (gst_query_is_writable (query));
1149 g_return_if_fail (percent >= 0 && percent <= 100);
1151 structure = GST_QUERY_STRUCTURE (query);
1152 gst_structure_id_set (structure,
1153 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1154 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1158 * gst_query_parse_buffering_percent:
1159 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1160 * @busy: (out) (optional): if buffering is busy, or %NULL
1161 * @percent: (out) (optional): a buffering percent, or %NULL
1163 * Get the percentage of buffered data. This is a value between 0 and 100.
1164 * The @busy indicator is %TRUE when the buffering is in progress.
1167 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1170 GstStructure *structure;
1172 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1174 structure = GST_QUERY_STRUCTURE (query);
1176 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1179 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1180 GST_QUARK (BUFFER_PERCENT)));
1184 * gst_query_set_buffering_stats:
1185 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1186 * @mode: a buffering mode
1187 * @avg_in: the average input rate
1188 * @avg_out: the average output rate
1189 * @buffering_left: amount of buffering time left in milliseconds
1191 * Configures the buffering stats values in @query.
1194 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1195 gint avg_in, gint avg_out, gint64 buffering_left)
1197 GstStructure *structure;
1199 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1200 g_return_if_fail (gst_query_is_writable (query));
1202 structure = GST_QUERY_STRUCTURE (query);
1203 gst_structure_id_set (structure,
1204 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1205 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1206 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1207 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1211 * gst_query_parse_buffering_stats:
1212 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1213 * @mode: (out) (optional): a buffering mode, or %NULL
1214 * @avg_in: (out) (optional): the average input rate, or %NULL
1215 * @avg_out: (out) (optional): the average output rat, or %NULL
1216 * @buffering_left: (out) (optional): amount of buffering time left in
1217 * milliseconds, or %NULL
1219 * Extracts the buffering stats values from @query.
1222 gst_query_parse_buffering_stats (GstQuery * query,
1223 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1224 gint64 * buffering_left)
1226 GstStructure *structure;
1228 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1230 structure = GST_QUERY_STRUCTURE (query);
1232 *mode = (GstBufferingMode)
1233 g_value_get_enum (gst_structure_id_get_value (structure,
1234 GST_QUARK (BUFFERING_MODE)));
1236 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1237 GST_QUARK (AVG_IN_RATE)));
1239 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1240 GST_QUARK (AVG_OUT_RATE)));
1243 g_value_get_int64 (gst_structure_id_get_value (structure,
1244 GST_QUARK (BUFFERING_LEFT)));
1248 * gst_query_set_buffering_range:
1249 * @query: a #GstQuery
1250 * @format: the format to set for the @start and @stop values
1251 * @start: the start to set
1252 * @stop: the stop to set
1253 * @estimated_total: estimated total amount of download time remaining in
1256 * Set the available query result fields in @query.
1259 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1260 gint64 start, gint64 stop, gint64 estimated_total)
1262 GstStructure *structure;
1264 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1265 g_return_if_fail (gst_query_is_writable (query));
1267 structure = GST_QUERY_STRUCTURE (query);
1268 gst_structure_id_set (structure,
1269 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1270 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1271 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1272 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1276 * gst_query_parse_buffering_range:
1277 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1278 * @format: (out) (optional): the format to set for the @segment_start
1279 * and @segment_end values, or %NULL
1280 * @start: (out) (optional): the start to set, or %NULL
1281 * @stop: (out) (optional): the stop to set, or %NULL
1282 * @estimated_total: (out) (optional): estimated total amount of download
1283 * time remaining in milliseconds, or %NULL
1285 * Parse an available query, writing the format into @format, and
1286 * other results into the passed parameters, if the respective parameters
1290 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1291 gint64 * start, gint64 * stop, gint64 * estimated_total)
1293 GstStructure *structure;
1295 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1297 structure = GST_QUERY_STRUCTURE (query);
1300 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1301 GST_QUARK (FORMAT)));
1303 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1304 GST_QUARK (START_VALUE)));
1306 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1307 GST_QUARK (STOP_VALUE)));
1308 if (estimated_total)
1310 g_value_get_int64 (gst_structure_id_get_value (structure,
1311 GST_QUARK (ESTIMATED_TOTAL)));
1314 /* GstQueryBufferingRange: internal struct for GArray */
1319 } GstQueryBufferingRange;
1322 * gst_query_add_buffering_range:
1323 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1324 * @start: start position of the range
1325 * @stop: stop position of the range
1327 * Set the buffering-ranges array field in @query. The current last
1328 * start position of the array should be inferior to @start.
1330 * Returns: a #gboolean indicating if the range was added or not.
1333 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1335 GstQueryBufferingRange range;
1336 GstStructure *structure;
1339 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1340 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1342 if (G_UNLIKELY (start >= stop))
1345 structure = GST_QUERY_STRUCTURE (query);
1346 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1347 sizeof (GstQueryBufferingRange), NULL);
1349 if (array->len > 1) {
1350 GstQueryBufferingRange *last;
1352 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1354 if (G_UNLIKELY (start <= last->start))
1358 range.start = start;
1360 g_array_append_val (array, range);
1366 * gst_query_get_n_buffering_ranges:
1367 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1369 * Retrieve the number of values currently stored in the
1370 * buffered-ranges array of the query's structure.
1372 * Returns: the range array size as a #guint.
1375 gst_query_get_n_buffering_ranges (GstQuery * query)
1377 GstStructure *structure;
1380 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1382 structure = GST_QUERY_STRUCTURE (query);
1383 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1384 sizeof (GstQueryBufferingRange), NULL);
1391 * gst_query_parse_nth_buffering_range:
1392 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1393 * @index: position in the buffered-ranges array to read
1394 * @start: (out) (optional): the start position to set, or %NULL
1395 * @stop: (out) (optional): the stop position to set, or %NULL
1397 * Parse an available query and get the start and stop values stored
1398 * at the @index of the buffered ranges array.
1400 * Returns: a #gboolean indicating if the parsing succeeded.
1403 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1404 gint64 * start, gint64 * stop)
1406 GstQueryBufferingRange *range;
1407 GstStructure *structure;
1410 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1412 structure = GST_QUERY_STRUCTURE (query);
1414 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1415 sizeof (GstQueryBufferingRange), NULL);
1416 g_return_val_if_fail (index < array->len, FALSE);
1418 range = &g_array_index (array, GstQueryBufferingRange, index);
1421 *start = range->start;
1423 *stop = range->stop;
1430 * gst_query_new_uri:
1432 * Constructs a new query URI query object. Use gst_query_unref()
1433 * when done with it. An URI query is used to query the current URI
1434 * that is used by the source or sink.
1436 * Free-function: gst_query_unref()
1438 * Returns: (transfer full): a new #GstQuery
1441 gst_query_new_uri (void)
1444 GstStructure *structure;
1446 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1447 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1449 query = gst_query_new_custom (GST_QUERY_URI, structure);
1455 * gst_query_set_uri:
1456 * @query: a #GstQuery with query type GST_QUERY_URI
1457 * @uri: (nullable): the URI to set
1459 * Answer a URI query by setting the requested URI.
1462 gst_query_set_uri (GstQuery * query, const gchar * uri)
1464 GstStructure *structure;
1466 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1467 g_return_if_fail (gst_query_is_writable (query));
1469 structure = GST_QUERY_STRUCTURE (query);
1470 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1474 * gst_query_parse_uri:
1475 * @query: a #GstQuery
1476 * @uri: (out) (transfer full) (optional) (nullable): the storage for the current URI
1479 * Parse an URI query, writing the URI into @uri as a newly
1480 * allocated string, if the respective parameters are non-%NULL.
1481 * Free the string with g_free() after usage.
1484 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1486 GstStructure *structure;
1488 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1490 structure = GST_QUERY_STRUCTURE (query);
1492 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1497 * gst_query_set_uri_redirection:
1498 * @query: a #GstQuery with query type GST_QUERY_URI
1499 * @uri: (nullable): the URI to set
1501 * Answer a URI query by setting the requested URI redirection.
1506 gst_query_set_uri_redirection (GstQuery * query, const gchar * uri)
1508 GstStructure *structure;
1510 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1511 g_return_if_fail (gst_query_is_writable (query));
1513 structure = GST_QUERY_STRUCTURE (query);
1514 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
1515 G_TYPE_STRING, uri, NULL);
1519 * gst_query_parse_uri_redirection:
1520 * @query: a #GstQuery
1521 * @uri: (out) (transfer full) (optional) (nullable): the storage for the redirect URI
1524 * Parse an URI query, writing the URI into @uri as a newly
1525 * allocated string, if the respective parameters are non-%NULL.
1526 * Free the string with g_free() after usage.
1531 gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
1533 GstStructure *structure;
1535 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1537 structure = GST_QUERY_STRUCTURE (query);
1539 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION),
1540 G_TYPE_STRING, uri, NULL))
1546 * gst_query_set_uri_redirection_permanent:
1547 * @query: a #GstQuery with query type %GST_QUERY_URI
1548 * @permanent: whether the redirect is permanent or not
1550 * Answer a URI query by setting the requested URI redirection
1551 * to permanent or not.
1556 gst_query_set_uri_redirection_permanent (GstQuery * query, gboolean permanent)
1558 GstStructure *structure;
1560 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1561 g_return_if_fail (gst_query_is_writable (query));
1563 structure = GST_QUERY_STRUCTURE (query);
1564 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1565 G_TYPE_BOOLEAN, permanent, NULL);
1569 * gst_query_parse_uri_redirection_permanent:
1570 * @query: a #GstQuery
1571 * @permanent: (out) (optional): if the URI redirection is permanent
1574 * Parse an URI query, and set @permanent to %TRUE if there is a redirection
1575 * and it should be considered permanent. If a redirection is permanent,
1576 * applications should update their internal storage of the URI, otherwise
1577 * they should make all future requests to the original URI.
1582 gst_query_parse_uri_redirection_permanent (GstQuery * query,
1583 gboolean * permanent)
1585 GstStructure *structure;
1587 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1589 structure = GST_QUERY_STRUCTURE (query);
1591 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1592 G_TYPE_BOOLEAN, permanent, NULL))
1598 * gst_query_new_allocation:
1599 * @caps: (nullable): the negotiated caps
1600 * @need_pool: return a pool
1602 * Constructs a new query object for querying the allocation properties.
1604 * Free-function: gst_query_unref()
1606 * Returns: (transfer full): a new #GstQuery
1609 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1612 GstStructure *structure;
1614 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1615 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1616 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1618 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1624 * gst_query_parse_allocation:
1625 * @query: a #GstQuery
1626 * @caps: (out) (transfer none) (optional) (nullable): The #GstCaps
1627 * @need_pool: (out) (optional): Whether a #GstBufferPool is needed
1629 * Parse an allocation query, writing the requested caps in @caps and
1630 * whether a pool is needed in @need_pool, if the respective parameters
1633 * Pool details can be retrieved using gst_query_get_n_allocation_pools() and
1634 * gst_query_parse_nth_allocation_pool().
1637 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1638 gboolean * need_pool)
1640 GstStructure *structure;
1642 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1644 structure = GST_QUERY_STRUCTURE (query);
1646 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1649 gst_structure_id_get (structure,
1650 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1655 GstBufferPool *pool;
1662 allocation_pool_free (AllocationPool * ap)
1665 gst_object_unref (ap->pool);
1669 * gst_query_add_allocation_pool:
1670 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1671 * @pool: (transfer none) (nullable): the #GstBufferPool
1672 * @size: the buffer size
1673 * @min_buffers: the min buffers
1674 * @max_buffers: the max buffers
1676 * Set the pool parameters in @query.
1679 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1680 guint size, guint min_buffers, guint max_buffers)
1683 GstStructure *structure;
1686 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1687 g_return_if_fail (gst_query_is_writable (query));
1689 structure = GST_QUERY_STRUCTURE (query);
1690 array = ensure_array (structure, GST_QUARK (POOL),
1691 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1693 if ((ap.pool = pool))
1694 gst_object_ref (pool);
1696 ap.min_buffers = min_buffers;
1697 ap.max_buffers = max_buffers;
1699 g_array_append_val (array, ap);
1703 * gst_query_get_n_allocation_pools:
1704 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1706 * Retrieve the number of values currently stored in the
1707 * pool array of the query's structure.
1709 * Returns: the pool array size as a #guint.
1712 gst_query_get_n_allocation_pools (GstQuery * query)
1715 GstStructure *structure;
1717 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1719 structure = GST_QUERY_STRUCTURE (query);
1720 array = ensure_array (structure, GST_QUARK (POOL),
1721 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1727 * gst_query_parse_nth_allocation_pool:
1728 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1729 * @index: index to parse
1730 * @pool: (out) (optional) (transfer full) (nullable): the #GstBufferPool
1731 * @size: (out) (optional): the buffer size
1732 * @min_buffers: (out) (optional): the min buffers
1733 * @max_buffers: (out) (optional): the max buffers
1735 * Get the pool parameters in @query.
1737 * Unref @pool with gst_object_unref() when it's not needed any more.
1740 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1741 GstBufferPool ** pool, guint * size, guint * min_buffers,
1742 guint * max_buffers)
1745 GstStructure *structure;
1748 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1750 structure = GST_QUERY_STRUCTURE (query);
1751 array = ensure_array (structure, GST_QUARK (POOL),
1752 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1753 g_return_if_fail (index < array->len);
1755 ap = &g_array_index (array, AllocationPool, index);
1758 if ((*pool = ap->pool))
1759 gst_object_ref (*pool);
1763 *min_buffers = ap->min_buffers;
1765 *max_buffers = ap->max_buffers;
1769 * gst_query_set_nth_allocation_pool:
1770 * @index: index to modify
1771 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1772 * @pool: (transfer none) (nullable): the #GstBufferPool
1773 * @size: the buffer size
1774 * @min_buffers: the min buffers
1775 * @max_buffers: the max buffers
1777 * Set the pool parameters in @query.
1780 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1781 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1784 GstStructure *structure;
1785 AllocationPool *oldap, ap;
1787 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1789 structure = GST_QUERY_STRUCTURE (query);
1790 array = ensure_array (structure, GST_QUARK (POOL),
1791 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1792 g_return_if_fail (index < array->len);
1794 oldap = &g_array_index (array, AllocationPool, index);
1795 allocation_pool_free (oldap);
1797 if ((ap.pool = pool))
1798 gst_object_ref (pool);
1800 ap.min_buffers = min_buffers;
1801 ap.max_buffers = max_buffers;
1802 g_array_index (array, AllocationPool, index) = ap;
1806 * gst_query_remove_nth_allocation_pool:
1807 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1808 * @index: position in the allocation pool array to remove
1810 * Remove the allocation pool at @index of the allocation pool array.
1815 gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
1818 GstStructure *structure;
1820 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1821 g_return_if_fail (gst_query_is_writable (query));
1823 structure = GST_QUERY_STRUCTURE (query);
1825 ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
1826 (GDestroyNotify) allocation_pool_free);
1827 g_return_if_fail (index < array->len);
1829 g_array_remove_index (array, index);
1835 GstStructure *params;
1839 allocation_meta_free (AllocationMeta * am)
1842 gst_structure_free (am->params);
1846 * gst_query_add_allocation_meta:
1847 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1848 * @api: the metadata API
1849 * @params: (transfer none) (nullable): API specific parameters
1851 * Add @api with @params as one of the supported metadata API to @query.
1854 gst_query_add_allocation_meta (GstQuery * query, GType api,
1855 const GstStructure * params)
1858 GstStructure *structure;
1861 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1862 g_return_if_fail (api != 0);
1863 g_return_if_fail (gst_query_is_writable (query));
1865 structure = GST_QUERY_STRUCTURE (query);
1867 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1868 (GDestroyNotify) allocation_meta_free);
1871 am.params = (params ? gst_structure_copy (params) : NULL);
1873 g_array_append_val (array, am);
1877 * gst_query_get_n_allocation_metas:
1878 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1880 * Retrieve the number of values currently stored in the
1881 * meta API array of the query's structure.
1883 * Returns: the metadata API array size as a #guint.
1886 gst_query_get_n_allocation_metas (GstQuery * query)
1889 GstStructure *structure;
1891 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1893 structure = GST_QUERY_STRUCTURE (query);
1895 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1896 (GDestroyNotify) allocation_meta_free);
1902 * gst_query_parse_nth_allocation_meta:
1903 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1904 * @index: position in the metadata API array to read
1905 * @params: (out) (transfer none) (optional): API specific parameters
1907 * Parse an available query and get the metadata API
1908 * at @index of the metadata API array.
1910 * Returns: a #GType of the metadata API at @index.
1913 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1914 const GstStructure ** params)
1917 GstStructure *structure;
1920 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1922 structure = GST_QUERY_STRUCTURE (query);
1924 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1925 (GDestroyNotify) allocation_meta_free);
1927 g_return_val_if_fail (index < array->len, 0);
1929 am = &g_array_index (array, AllocationMeta, index);
1932 *params = am->params;
1938 * gst_query_remove_nth_allocation_meta:
1939 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1940 * @index: position in the metadata API array to remove
1942 * Remove the metadata API at @index of the metadata API array.
1945 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1948 GstStructure *structure;
1950 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1951 g_return_if_fail (gst_query_is_writable (query));
1953 structure = GST_QUERY_STRUCTURE (query);
1955 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1956 (GDestroyNotify) allocation_meta_free);
1957 g_return_if_fail (index < array->len);
1959 g_array_remove_index (array, index);
1963 * gst_query_find_allocation_meta:
1964 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1965 * @api: the metadata API
1966 * @index: (out) (transfer none) (optional): the index
1968 * Check if @query has metadata @api set. When this function returns %TRUE,
1969 * @index will contain the index where the requested API and the parameters
1972 * Returns: %TRUE when @api is in the list of metadata.
1975 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1978 GstStructure *structure;
1981 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1982 g_return_val_if_fail (api != 0, FALSE);
1984 structure = GST_QUERY_STRUCTURE (query);
1986 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1987 (GDestroyNotify) allocation_meta_free);
1990 for (i = 0; i < len; i++) {
1991 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1992 if (am->api == api) {
2003 GstAllocator *allocator;
2004 GstAllocationParams params;
2008 allocation_param_free (AllocationParam * ap)
2011 gst_object_unref (ap->allocator);
2015 * gst_query_add_allocation_param:
2016 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2017 * @allocator: (transfer none) (nullable): the memory allocator
2018 * @params: (transfer none) (nullable): a #GstAllocationParams
2020 * Add @allocator and its @params as a supported memory allocator.
2023 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
2024 const GstAllocationParams * params)
2027 GstStructure *structure;
2030 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2031 g_return_if_fail (gst_query_is_writable (query));
2032 g_return_if_fail (allocator != NULL || params != NULL);
2034 structure = GST_QUERY_STRUCTURE (query);
2035 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2036 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2038 if ((ap.allocator = allocator))
2039 gst_object_ref (allocator);
2041 ap.params = *params;
2043 gst_allocation_params_init (&ap.params);
2045 g_array_append_val (array, ap);
2049 * gst_query_get_n_allocation_params:
2050 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2052 * Retrieve the number of values currently stored in the
2053 * allocator params array of the query's structure.
2055 * If no memory allocator is specified, the downstream element can handle
2056 * the default memory allocator. The first memory allocator in the query
2057 * should be generic and allow mapping to system memory, all following
2058 * allocators should be ordered by preference with the preferred one first.
2060 * Returns: the allocator array size as a #guint.
2063 gst_query_get_n_allocation_params (GstQuery * query)
2066 GstStructure *structure;
2068 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
2070 structure = GST_QUERY_STRUCTURE (query);
2071 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2072 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2078 * gst_query_parse_nth_allocation_param:
2079 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2080 * @index: position in the allocator array to read
2081 * @allocator: (out) (transfer full) (optional) (nullable): variable to hold the result
2082 * @params: (out) (optional): parameters for the allocator
2084 * Parse an available query and get the allocator and its params
2085 * at @index of the allocator array.
2088 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
2089 GstAllocator ** allocator, GstAllocationParams * params)
2092 GstStructure *structure;
2093 AllocationParam *ap;
2095 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2097 structure = GST_QUERY_STRUCTURE (query);
2098 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2099 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2100 g_return_if_fail (index < array->len);
2102 ap = &g_array_index (array, AllocationParam, index);
2105 if ((*allocator = ap->allocator))
2106 gst_object_ref (*allocator);
2108 *params = ap->params;
2112 * gst_query_set_nth_allocation_param:
2113 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2114 * @index: position in the allocator array to set
2115 * @allocator: (transfer none) (nullable): new allocator to set
2116 * @params: (transfer none) (nullable): parameters for the allocator
2118 * Parse an available query and get the allocator and its params
2119 * at @index of the allocator array.
2122 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
2123 GstAllocator * allocator, const GstAllocationParams * params)
2126 GstStructure *structure;
2127 AllocationParam *old, ap;
2129 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2131 structure = GST_QUERY_STRUCTURE (query);
2132 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2133 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2134 g_return_if_fail (index < array->len);
2136 old = &g_array_index (array, AllocationParam, index);
2137 allocation_param_free (old);
2139 if ((ap.allocator = allocator))
2140 gst_object_ref (allocator);
2142 ap.params = *params;
2144 gst_allocation_params_init (&ap.params);
2146 g_array_index (array, AllocationParam, index) = ap;
2150 * gst_query_remove_nth_allocation_param:
2151 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2152 * @index: position in the allocation param array to remove
2154 * Remove the allocation param at @index of the allocation param array.
2159 gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
2162 GstStructure *structure;
2164 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2165 g_return_if_fail (gst_query_is_writable (query));
2167 structure = GST_QUERY_STRUCTURE (query);
2169 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
2170 (GDestroyNotify) allocation_param_free);
2171 g_return_if_fail (index < array->len);
2173 g_array_remove_index (array, index);
2177 * gst_query_new_scheduling:
2179 * Constructs a new query object for querying the scheduling properties.
2181 * Free-function: gst_query_unref()
2183 * Returns: (transfer full): a new #GstQuery
2186 gst_query_new_scheduling (void)
2189 GstStructure *structure;
2191 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
2192 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
2193 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
2194 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
2195 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
2196 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2202 * gst_query_set_scheduling:
2203 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2204 * @flags: #GstSchedulingFlags
2205 * @minsize: the suggested minimum size of pull requests
2206 * @maxsize: the suggested maximum size of pull requests
2207 * @align: the suggested alignment of pull requests
2209 * Set the scheduling properties.
2212 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2213 gint minsize, gint maxsize, gint align)
2215 GstStructure *structure;
2217 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2218 g_return_if_fail (gst_query_is_writable (query));
2220 structure = GST_QUERY_STRUCTURE (query);
2221 gst_structure_id_set (structure,
2222 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2223 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2224 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2225 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2229 * gst_query_parse_scheduling:
2230 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2231 * @flags: (out) (optional): #GstSchedulingFlags
2232 * @minsize: (out) (optional): the suggested minimum size of pull requests
2233 * @maxsize: (out) (optional): the suggested maximum size of pull requests:
2234 * @align: (out) (optional): the suggested alignment of pull requests
2236 * Set the scheduling properties.
2239 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2240 gint * minsize, gint * maxsize, gint * align)
2242 GstStructure *structure;
2244 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2246 structure = GST_QUERY_STRUCTURE (query);
2247 gst_structure_id_get (structure,
2248 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2249 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2250 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2251 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2255 * gst_query_add_scheduling_mode:
2256 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2257 * @mode: a #GstPadMode
2259 * Add @mode as one of the supported scheduling modes to @query.
2262 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2264 GstStructure *structure;
2267 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2268 g_return_if_fail (gst_query_is_writable (query));
2270 structure = GST_QUERY_STRUCTURE (query);
2272 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2274 g_array_append_val (array, mode);
2278 * gst_query_get_n_scheduling_modes:
2279 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2281 * Retrieve the number of values currently stored in the
2282 * scheduling mode array of the query's structure.
2284 * Returns: the scheduling mode array size as a #guint.
2287 gst_query_get_n_scheduling_modes (GstQuery * query)
2290 GstStructure *structure;
2292 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2294 structure = GST_QUERY_STRUCTURE (query);
2296 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2302 * gst_query_parse_nth_scheduling_mode:
2303 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2304 * @index: position in the scheduling modes array to read
2306 * Parse an available query and get the scheduling mode
2307 * at @index of the scheduling modes array.
2309 * Returns: a #GstPadMode of the scheduling mode at @index.
2312 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2314 GstStructure *structure;
2317 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2320 structure = GST_QUERY_STRUCTURE (query);
2322 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2323 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2325 return g_array_index (array, GstPadMode, index);
2329 * gst_query_has_scheduling_mode:
2330 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2331 * @mode: the scheduling mode
2333 * Check if @query has scheduling mode set.
2335 * > When checking if upstream supports pull mode, it is usually not
2336 * > enough to just check for GST_PAD_MODE_PULL with this function, you
2337 * > also want to check whether the scheduling flags returned by
2338 * > gst_query_parse_scheduling() have the seeking flag set (meaning
2339 * > random access is supported, not only sequential pulls).
2341 * Returns: %TRUE when @mode is in the list of scheduling modes.
2344 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2346 GstStructure *structure;
2350 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2352 structure = GST_QUERY_STRUCTURE (query);
2354 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2357 for (i = 0; i < len; i++) {
2358 if (mode == g_array_index (array, GstPadMode, i))
2365 * gst_query_has_scheduling_mode_with_flags:
2366 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2367 * @mode: the scheduling mode
2368 * @flags: #GstSchedulingFlags
2370 * Check if @query has scheduling mode set and @flags is set in
2371 * query scheduling flags.
2373 * Returns: %TRUE when @mode is in the list of scheduling modes
2374 * and @flags are compatible with query flags.
2377 gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
2378 GstSchedulingFlags flags)
2380 GstSchedulingFlags sched_flags;
2382 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2384 gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
2386 return ((flags & sched_flags) == flags) &&
2387 gst_query_has_scheduling_mode (query, mode);
2391 * gst_query_new_accept_caps:
2392 * @caps: a fixed #GstCaps
2394 * Constructs a new query object for querying if @caps are accepted.
2396 * Free-function: gst_query_unref()
2398 * Returns: (transfer full): a new #GstQuery
2401 gst_query_new_accept_caps (GstCaps * caps)
2404 GstStructure *structure;
2406 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2408 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2409 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2410 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2411 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2417 * gst_query_parse_accept_caps:
2418 * @query: The query to parse
2419 * @caps: (out) (transfer none): A pointer to the caps
2421 * Get the caps from @query. The caps remains valid as long as @query remains
2425 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2427 GstStructure *structure;
2429 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2430 g_return_if_fail (caps != NULL);
2432 structure = GST_QUERY_STRUCTURE (query);
2433 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2438 * gst_query_set_accept_caps_result:
2439 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2440 * @result: the result to set
2442 * Set @result as the result for the @query.
2445 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2447 GstStructure *structure;
2449 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2450 g_return_if_fail (gst_query_is_writable (query));
2452 structure = GST_QUERY_STRUCTURE (query);
2453 gst_structure_id_set (structure,
2454 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2458 * gst_query_parse_accept_caps_result:
2459 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2460 * @result: (out) (nullable): location for the result
2462 * Parse the result from @query and store in @result.
2465 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2467 GstStructure *structure;
2469 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2471 structure = GST_QUERY_STRUCTURE (query);
2472 gst_structure_id_get (structure,
2473 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2477 * gst_query_new_caps:
2480 * Constructs a new query object for querying the caps.
2482 * The CAPS query should return the allowable caps for a pad in the context
2483 * of the element's state, its link to other elements, and the devices or files
2484 * it has opened. These caps must be a subset of the pad template caps. In the
2485 * NULL state with no links, the CAPS query should ideally return the same caps
2486 * as the pad template. In rare circumstances, an object property can affect
2487 * the caps returned by the CAPS query, but this is discouraged.
2489 * For most filters, the caps returned by CAPS query is directly affected by the
2490 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2491 * the srcpad's getcaps function is directly related to the stream data. Again,
2492 * the CAPS query should return the most specific caps it reasonably can, since this
2493 * helps with autoplugging.
2495 * The @filter is used to restrict the result caps, only the caps matching
2496 * @filter should be returned from the CAPS query. Specifying a filter might
2497 * greatly reduce the amount of processing an element needs to do.
2499 * Free-function: gst_query_unref()
2501 * Returns: (transfer full): a new #GstQuery
2504 gst_query_new_caps (GstCaps * filter)
2507 GstStructure *structure;
2509 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2510 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2511 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2512 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2518 * gst_query_parse_caps:
2519 * @query: The query to parse
2520 * @filter: (out) (transfer none): A pointer to the caps filter
2522 * Get the filter from the caps @query. The caps remains valid as long as
2523 * @query remains valid.
2526 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2528 GstStructure *structure;
2530 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2531 g_return_if_fail (filter != NULL);
2533 structure = GST_QUERY_STRUCTURE (query);
2534 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2535 GST_QUARK (FILTER)));
2539 * gst_query_set_caps_result:
2540 * @query: The query to use
2541 * @caps: (nullable): A pointer to the caps
2543 * Set the @caps result in @query.
2546 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2548 GstStructure *structure;
2550 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2551 g_return_if_fail (gst_query_is_writable (query));
2553 structure = GST_QUERY_STRUCTURE (query);
2554 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2558 * gst_query_parse_caps_result:
2559 * @query: The query to parse
2560 * @caps: (out) (transfer none) (nullable): A pointer to the caps
2562 * Get the caps result from @query. The caps remains valid as long as
2563 * @query remains valid.
2566 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2568 GstStructure *structure;
2570 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2571 g_return_if_fail (caps != NULL);
2573 structure = GST_QUERY_STRUCTURE (query);
2574 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2580 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2581 GstCapsIntersectMode mode)
2583 GstCaps *res, *caps = NULL;
2585 gst_query_parse_caps_result (query, &caps);
2586 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2587 gst_query_set_caps_result (query, res);
2588 gst_caps_unref (res);
2593 * gst_query_new_drain:
2595 * Constructs a new query object for querying the drain state.
2597 * Free-function: gst_query_unref()
2599 * Returns: (transfer full): a new #GstQuery
2602 gst_query_new_drain (void)
2605 GstStructure *structure;
2607 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2608 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2614 * gst_query_new_context:
2615 * @context_type: Context type to query
2617 * Constructs a new query object for querying the pipeline-local context.
2619 * Free-function: gst_query_unref()
2621 * Returns: (transfer full): a new #GstQuery
2626 gst_query_new_context (const gchar * context_type)
2629 GstStructure *structure;
2631 g_return_val_if_fail (context_type != NULL, NULL);
2633 structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
2634 GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2635 query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
2641 * gst_query_set_context:
2642 * @query: a #GstQuery with query type GST_QUERY_CONTEXT
2643 * @context: (nullable): the requested #GstContext
2645 * Answer a context query by setting the requested context.
2650 gst_query_set_context (GstQuery * query, GstContext * context)
2653 const gchar *context_type;
2655 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2657 gst_query_parse_context_type (query, &context_type);
2658 g_return_if_fail (strcmp (gst_context_get_context_type (context),
2659 context_type) == 0);
2661 s = GST_QUERY_STRUCTURE (query);
2663 gst_structure_id_set (s,
2664 GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2668 * gst_query_parse_context:
2669 * @query: The query to parse
2670 * @context: (out) (transfer none) (nullable): A pointer to store the #GstContext
2672 * Get the context from the context @query. The context remains valid as long as
2673 * @query remains valid.
2678 gst_query_parse_context (GstQuery * query, GstContext ** context)
2680 GstStructure *structure;
2683 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2684 g_return_if_fail (context != NULL);
2686 structure = GST_QUERY_STRUCTURE (query);
2687 v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
2689 *context = g_value_get_boxed (v);
2695 * gst_query_parse_context_type:
2696 * @query: a GST_QUERY_CONTEXT type query
2697 * @context_type: (out) (transfer none) (optional): the context type, or %NULL
2699 * Parse a context type from an existing GST_QUERY_CONTEXT query.
2701 * Returns: a #gboolean indicating if the parsing succeeded.
2706 gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
2708 GstStructure *structure;
2709 const GValue *value;
2711 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2713 structure = GST_QUERY_STRUCTURE (query);
2716 value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2717 *context_type = g_value_get_string (value);
2724 * gst_query_new_bitrate:
2726 * Constructs a new query object for querying the bitrate.
2728 * Free-function: gst_query_unref()
2730 * Returns: (transfer full): a new #GstQuery
2735 gst_query_new_bitrate (void)
2738 GstStructure *structure;
2740 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_BITRATE));
2741 query = gst_query_new_custom (GST_QUERY_BITRATE, structure);
2747 * gst_query_set_bitrate:
2748 * @query: a GST_QUERY_BITRATE type #GstQuery
2749 * @nominal_bitrate: the nominal bitrate in bits per second
2751 * Set the results of a bitrate query. The nominal bitrate is the average
2752 * bitrate expected over the length of the stream as advertised in file
2753 * headers (or similar).
2758 gst_query_set_bitrate (GstQuery * query, guint nominal_bitrate)
2762 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
2764 s = GST_QUERY_STRUCTURE (query);
2766 gst_structure_id_set (s,
2767 GST_QUARK (NOMINAL_BITRATE), G_TYPE_UINT, nominal_bitrate, NULL);
2771 * gst_query_parse_bitrate:
2772 * @query: a GST_QUERY_BITRATE type #GstQuery
2773 * @nominal_bitrate: (out) (optional): The resulting bitrate in bits per second
2775 * Get the results of a bitrate query. See also gst_query_set_bitrate().
2780 gst_query_parse_bitrate (GstQuery * query, guint * nominal_bitrate)
2782 GstStructure *structure;
2783 const GValue *value;
2785 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
2787 structure = GST_QUERY_STRUCTURE (query);
2789 if (nominal_bitrate) {
2790 value = gst_structure_id_get_value (structure, GST_QUARK (NOMINAL_BITRATE));
2791 *nominal_bitrate = g_value_get_uint (value);
2796 * gst_query_new_selectable:
2798 * Constructs a new query object for querying the stream selection capability.
2800 * Free-function: gst_query_unref()
2802 * Returns: (transfer full): a new #GstQuery
2807 gst_query_new_selectable (void)
2810 GstStructure *structure;
2812 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_SELECTABLE));
2813 query = gst_query_new_custom (GST_QUERY_SELECTABLE, structure);
2819 * gst_query_set_selectable:
2820 * @query: a GST_QUERY_SELECTABLE type #GstQuery
2821 * @selectable: Whether the element can handle stream selection.
2823 * Set the results of a selectable query. If the element answering the query can
2824 * handle stream selection, @selectable should be set to %TRUE.
2829 gst_query_set_selectable (GstQuery * query, gboolean selectable)
2833 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SELECTABLE);
2835 s = GST_QUERY_STRUCTURE (query);
2837 gst_structure_id_set (s,
2838 GST_QUARK (SELECTABLE), G_TYPE_BOOLEAN, selectable, NULL);
2842 * gst_query_parse_selectable:
2843 * @query: a GST_QUERY_SELECTABLE type #GstQuery
2844 * @selectable: (out) (optional): The resulting stream selection capability
2846 * Get the results of a selectable query. See also gst_query_set_selectable().
2851 gst_query_parse_selectable (GstQuery * query, gboolean * selectable)
2853 GstStructure *structure;
2855 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SELECTABLE);
2857 structure = GST_QUERY_STRUCTURE (query);
2860 const GValue *value =
2861 gst_structure_id_get_value (structure, GST_QUARK (SELECTABLE));
2863 *selectable = g_value_get_boolean (value);
2865 *selectable = FALSE;
2871 * @q: a #GstQuery to increase the refcount of.
2873 * Increases the refcount of the given query by one.
2878 gst_query_ref (GstQuery * q)
2880 return GST_QUERY_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (q)));
2884 * gst_query_unref: (skip)
2885 * @q: a #GstQuery to decrease the refcount of.
2887 * Decreases the refcount of the query. If the refcount reaches 0, the query
2891 gst_query_unref (GstQuery * q)
2893 gst_mini_object_unref (GST_MINI_OBJECT_CAST (q));
2897 * gst_clear_query: (skip)
2898 * @query_ptr: a pointer to a #GstQuery reference
2900 * Clears a reference to a #GstQuery.
2902 * @query_ptr must not be %NULL.
2904 * If the reference is %NULL then this function does nothing. Otherwise, the
2905 * reference count of the query is decreased and the pointer is set to %NULL.
2910 gst_clear_query (GstQuery ** query_ptr)
2912 gst_clear_mini_object ((GstMiniObject **) query_ptr);
2916 * gst_query_copy: (skip)
2917 * @q: a #GstQuery to copy.
2919 * Copies the given query using the copy function of the parent #GstStructure.
2921 * Free-function: gst_query_unref
2923 * Returns: (transfer full): a new copy of @q.
2926 gst_query_copy (const GstQuery * q)
2928 return GST_QUERY_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (q)));
2932 * gst_query_replace: (skip)
2933 * @old_query: (inout) (transfer full) (nullable): pointer to a pointer to a
2934 * #GstQuery to be replaced.
2935 * @new_query: (nullable) (transfer none): pointer to a #GstQuery that will
2936 * replace the query pointed to by @old_query.
2938 * Modifies a pointer to a #GstQuery to point to a different #GstQuery. The
2939 * modification is done atomically (so this is useful for ensuring thread safety
2940 * in some cases), and the reference counts are updated appropriately (the old
2941 * query is unreffed, the new one is reffed).
2943 * Either @new_query or the #GstQuery pointed to by @old_query may be %NULL.
2945 * Returns: %TRUE if @new_query was different from @old_query
2948 gst_query_replace (GstQuery ** old_query, GstQuery * new_query)
2950 return gst_mini_object_replace ((GstMiniObject **) old_query,
2951 (GstMiniObject *) new_query);
2956 * @old_query: (inout) (transfer full) (nullable): pointer to a
2957 * pointer to a #GstQuery to be stolen.
2958 * @new_query: (nullable) (transfer full): pointer to a #GstQuery that will
2959 * replace the query pointed to by @old_query.
2961 * Modifies a pointer to a #GstQuery to point to a different #GstQuery. This
2962 * function is similar to gst_query_replace() except that it takes ownership of
2965 * Either @new_query or the #GstQuery pointed to by @old_query may be %NULL.
2967 * Returns: %TRUE if @new_query was different from @old_query
2972 gst_query_take (GstQuery ** old_query, GstQuery * new_query)
2974 return gst_mini_object_take ((GstMiniObject **) old_query,
2975 (GstMiniObject *) new_query);