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"
66 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
67 #define GST_CAT_DEFAULT gst_query_debug
69 GType _gst_query_type = 0;
75 GstStructure *structure;
78 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
88 static GstQueryQuarks query_quarks[] = {
89 {GST_QUERY_UNKNOWN, "unknown", 0},
90 {GST_QUERY_POSITION, "position", 0},
91 {GST_QUERY_DURATION, "duration", 0},
92 {GST_QUERY_LATENCY, "latency", 0},
93 {GST_QUERY_JITTER, "jitter", 0},
94 {GST_QUERY_RATE, "rate", 0},
95 {GST_QUERY_SEEKING, "seeking", 0},
96 {GST_QUERY_SEGMENT, "segment", 0},
97 {GST_QUERY_CONVERT, "convert", 0},
98 {GST_QUERY_FORMATS, "formats", 0},
99 {GST_QUERY_BUFFERING, "buffering", 0},
100 {GST_QUERY_CUSTOM, "custom", 0},
101 {GST_QUERY_URI, "uri", 0},
102 {GST_QUERY_ALLOCATION, "allocation", 0},
103 {GST_QUERY_SCHEDULING, "scheduling", 0},
104 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
105 {GST_QUERY_CAPS, "caps", 0},
106 {GST_QUERY_DRAIN, "drain", 0},
107 {GST_QUERY_CONTEXT, "context", 0},
108 {GST_QUERY_BITRATE, "bitrate", 0},
113 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
116 _priv_gst_query_initialize (void)
120 _gst_query_type = gst_query_get_type ();
122 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
124 for (i = 0; query_quarks[i].name; i++) {
125 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
130 * gst_query_type_get_name:
131 * @type: the query type
133 * Get a printable name for the given query type. Do not modify or free.
135 * Returns: a reference to the static name of the query.
138 gst_query_type_get_name (GstQueryType type)
142 for (i = 0; query_quarks[i].name; i++) {
143 if (type == query_quarks[i].type)
144 return query_quarks[i].name;
150 * gst_query_type_to_quark:
151 * @type: the query type
153 * Get the unique quark for the given query type.
155 * Returns: the quark associated with the query type
158 gst_query_type_to_quark (GstQueryType type)
162 for (i = 0; query_quarks[i].name; i++) {
163 if (type == query_quarks[i].type)
164 return query_quarks[i].quark;
170 * gst_query_type_get_flags:
171 * @type: a #GstQueryType
173 * Gets the #GstQueryTypeFlags associated with @type.
175 * Returns: a #GstQueryTypeFlags.
178 gst_query_type_get_flags (GstQueryType type)
180 GstQueryTypeFlags ret;
182 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
188 _gst_query_free (GstQuery * query)
192 g_return_if_fail (query != NULL);
194 s = GST_QUERY_STRUCTURE (query);
196 gst_structure_set_parent_refcount (s, NULL);
197 gst_structure_free (s);
200 memset (query, 0xff, sizeof (GstQueryImpl));
203 g_slice_free1 (sizeof (GstQueryImpl), query);
207 _gst_query_copy (GstQuery * query)
212 s = GST_QUERY_STRUCTURE (query);
214 s = gst_structure_copy (s);
216 copy = gst_query_new_custom (query->type, s);
222 * gst_query_new_position:
223 * @format: the default #GstFormat for the new query
225 * Constructs a new query stream position query object. Use gst_query_unref()
226 * when done with it. A position query is used to query the current position
227 * of playback in the streams, in some format.
229 * Free-function: gst_query_unref()
231 * Returns: (transfer full): a new #GstQuery
234 gst_query_new_position (GstFormat format)
237 GstStructure *structure;
239 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
240 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
241 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
243 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
249 * gst_query_set_position:
250 * @query: a #GstQuery with query type GST_QUERY_POSITION
251 * @format: the requested #GstFormat
252 * @cur: the position to set
254 * Answer a position query by setting the requested value in the given format.
257 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
261 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
263 s = GST_QUERY_STRUCTURE (query);
264 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
265 GST_QUARK (FORMAT))));
267 gst_structure_id_set (s,
268 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
269 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
273 * gst_query_parse_position:
274 * @query: a #GstQuery
275 * @format: (out) (optional): the storage for the #GstFormat of the
276 * position values (may be %NULL)
277 * @cur: (out) (optional): the storage for the current position (may be %NULL)
279 * Parse a position query, writing the format into @format, and the position
280 * into @cur, if the respective parameters are non-%NULL.
283 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
285 GstStructure *structure;
287 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
289 structure = GST_QUERY_STRUCTURE (query);
292 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
293 GST_QUARK (FORMAT)));
295 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
296 GST_QUARK (CURRENT)));
301 * gst_query_new_duration:
302 * @format: the #GstFormat for this duration query
304 * Constructs a new stream duration query object to query in the given format.
305 * Use gst_query_unref() when done with it. A duration query will give the
306 * total length of the stream.
308 * Free-function: gst_query_unref()
310 * Returns: (transfer full): a new #GstQuery
313 gst_query_new_duration (GstFormat format)
316 GstStructure *structure;
318 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
319 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
320 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
322 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
328 * gst_query_set_duration:
329 * @query: a #GstQuery
330 * @format: the #GstFormat for the duration
331 * @duration: the duration of the stream
333 * Answer a duration query by setting the requested value in the given format.
336 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
340 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
342 s = GST_QUERY_STRUCTURE (query);
343 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
344 GST_QUARK (FORMAT))));
345 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
346 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
350 * gst_query_parse_duration:
351 * @query: a #GstQuery
352 * @format: (out) (optional): the storage for the #GstFormat of the duration
354 * @duration: (out) (optional): the storage for the total duration, or %NULL.
356 * Parse a duration query answer. Write the format of the duration into @format,
357 * and the value into @duration, if the respective variables are non-%NULL.
360 gst_query_parse_duration (GstQuery * query, GstFormat * format,
363 GstStructure *structure;
365 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
367 structure = GST_QUERY_STRUCTURE (query);
370 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
371 GST_QUARK (FORMAT)));
373 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
374 GST_QUARK (DURATION)));
378 * gst_query_new_latency:
380 * Constructs a new latency query object.
381 * Use gst_query_unref() when done with it. A latency query is usually performed
382 * by sinks to compensate for additional latency introduced by elements in the
385 * Free-function: gst_query_unref()
387 * Returns: (transfer full): a #GstQuery
390 gst_query_new_latency (void)
393 GstStructure *structure;
395 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
396 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
397 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
398 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, GST_CLOCK_TIME_NONE, NULL);
400 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
406 * gst_query_set_latency:
407 * @query: a #GstQuery
408 * @live: if there is a live element upstream
409 * @min_latency: the minimal latency of the upstream elements
410 * @max_latency: the maximal latency of the upstream elements
412 * Answer a latency query by setting the requested values in the given format.
415 gst_query_set_latency (GstQuery * query, gboolean live,
416 GstClockTime min_latency, GstClockTime max_latency)
418 GstStructure *structure;
420 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
421 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
423 structure = GST_QUERY_STRUCTURE (query);
424 gst_structure_id_set (structure,
425 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
426 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
427 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
431 * gst_query_parse_latency:
432 * @query: a #GstQuery
433 * @live: (out) (optional): storage for live or %NULL
434 * @min_latency: (out) (optional): the storage for the min latency or %NULL
435 * @max_latency: (out) (optional): the storage for the max latency or %NULL
437 * Parse a latency query answer.
440 gst_query_parse_latency (GstQuery * query, gboolean * live,
441 GstClockTime * min_latency, GstClockTime * max_latency)
443 GstStructure *structure;
445 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
447 structure = GST_QUERY_STRUCTURE (query);
450 g_value_get_boolean (gst_structure_id_get_value (structure,
453 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
454 GST_QUARK (MIN_LATENCY)));
456 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
457 GST_QUARK (MAX_LATENCY)));
461 * gst_query_new_convert:
462 * @src_format: the source #GstFormat for the new query
463 * @value: the value to convert
464 * @dest_format: the target #GstFormat
466 * Constructs a new convert query object. Use gst_query_unref()
467 * when done with it. A convert query is used to ask for a conversion between
468 * one format and another.
470 * Free-function: gst_query_unref()
472 * Returns: (transfer full): a #GstQuery
475 gst_query_new_convert (GstFormat src_format, gint64 value,
476 GstFormat dest_format)
479 GstStructure *structure;
481 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
482 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
483 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
484 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
485 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
487 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
493 * gst_query_set_convert:
494 * @query: a #GstQuery
495 * @src_format: the source #GstFormat
496 * @src_value: the source value
497 * @dest_format: the destination #GstFormat
498 * @dest_value: the destination value
500 * Answer a convert query by setting the requested values.
503 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
504 GstFormat dest_format, gint64 dest_value)
506 GstStructure *structure;
508 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
510 structure = GST_QUERY_STRUCTURE (query);
511 gst_structure_id_set (structure,
512 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
513 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
514 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
515 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
519 * gst_query_parse_convert:
520 * @query: a #GstQuery
521 * @src_format: (out) (optional): the storage for the #GstFormat of the
522 * source value, or %NULL
523 * @src_value: (out) (optional): the storage for the source value, or %NULL
524 * @dest_format: (out) (optional): the storage for the #GstFormat of the
525 * destination value, or %NULL
526 * @dest_value: (out) (optional): the storage for the destination value,
529 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
530 * and @dest_value may be %NULL, in which case that value is omitted.
533 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
534 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
536 GstStructure *structure;
538 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
540 structure = GST_QUERY_STRUCTURE (query);
543 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
544 GST_QUARK (SRC_FORMAT)));
546 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
547 GST_QUARK (SRC_VALUE)));
550 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
551 GST_QUARK (DEST_FORMAT)));
553 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
554 GST_QUARK (DEST_VALUE)));
558 * gst_query_new_segment:
559 * @format: the #GstFormat for the new query
561 * Constructs a new segment query object. Use gst_query_unref()
562 * when done with it. A segment query is used to discover information about the
563 * currently configured segment for playback.
565 * Free-function: gst_query_unref()
567 * Returns: (transfer full): a new #GstQuery
570 gst_query_new_segment (GstFormat format)
573 GstStructure *structure;
575 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
576 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
577 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
578 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
579 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
581 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
587 * gst_query_set_segment:
588 * @query: a #GstQuery
589 * @rate: the rate of the segment
590 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
591 * @start_value: the start value
592 * @stop_value: the stop value
594 * Answer a segment query by setting the requested values. The normal
595 * playback segment of a pipeline is 0 to duration at the default rate of
596 * 1.0. If a seek was performed on the pipeline to play a different
597 * segment, this query will return the range specified in the last seek.
599 * @start_value and @stop_value will respectively contain the configured
600 * playback range start and stop values expressed in @format.
601 * The values are always between 0 and the duration of the media and
602 * @start_value <= @stop_value. @rate will contain the playback rate. For
603 * negative rates, playback will actually happen from @stop_value to
607 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
608 gint64 start_value, gint64 stop_value)
610 GstStructure *structure;
612 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
614 structure = GST_QUERY_STRUCTURE (query);
615 gst_structure_id_set (structure,
616 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
617 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
618 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
619 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
623 * gst_query_parse_segment:
624 * @query: a #GstQuery
625 * @rate: (out) (optional): the storage for the rate of the segment, or %NULL
626 * @format: (out) (optional): the storage for the #GstFormat of the values,
628 * @start_value: (out) (optional): the storage for the start value, or %NULL
629 * @stop_value: (out) (optional): the storage for the stop value, or %NULL
631 * Parse a segment query answer. Any of @rate, @format, @start_value, and
632 * @stop_value may be %NULL, which will cause this value to be omitted.
634 * See gst_query_set_segment() for an explanation of the function arguments.
637 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
638 gint64 * start_value, gint64 * stop_value)
640 GstStructure *structure;
642 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
644 structure = GST_QUERY_STRUCTURE (query);
646 *rate = g_value_get_double (gst_structure_id_get_value (structure,
650 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
651 GST_QUARK (FORMAT)));
653 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
654 GST_QUARK (START_VALUE)));
656 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
657 GST_QUARK (STOP_VALUE)));
661 * gst_query_new_custom:
662 * @type: the query type
663 * @structure: (nullable) (transfer full): a structure for the query
665 * Constructs a new custom query object. Use gst_query_unref()
668 * Free-function: gst_query_unref()
670 * Returns: (transfer full): a new #GstQuery
673 gst_query_new_custom (GstQueryType type, GstStructure * structure)
677 query = g_slice_new0 (GstQueryImpl);
679 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
682 /* structure must not have a parent */
683 if (!gst_structure_set_parent_refcount (structure,
684 &query->query.mini_object.refcount))
688 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
689 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
690 (GstMiniObjectFreeFunction) _gst_query_free);
692 GST_QUERY_TYPE (query) = type;
693 GST_QUERY_STRUCTURE (query) = structure;
695 return GST_QUERY_CAST (query);
700 g_slice_free1 (sizeof (GstQueryImpl), query);
701 g_warning ("structure is already owned by another object");
707 * gst_query_get_structure:
708 * @query: a #GstQuery
710 * Get the structure of a query.
712 * Returns: (transfer none) (nullable): the #GstStructure of the query. The
713 * structure is still owned by the query and will therefore be freed when the
717 gst_query_get_structure (GstQuery * query)
719 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
721 return GST_QUERY_STRUCTURE (query);
725 * gst_query_writable_structure:
726 * @query: a #GstQuery
728 * Get the structure of a query. This method should be called with a writable
729 * @query so that the returned structure is guaranteed to be writable.
731 * Returns: (transfer none): the #GstStructure of the query. The structure is
732 * still owned by the query and will therefore be freed when the query
736 gst_query_writable_structure (GstQuery * query)
738 GstStructure *structure;
740 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
741 g_return_val_if_fail (gst_query_is_writable (query), NULL);
743 structure = GST_QUERY_STRUCTURE (query);
745 if (structure == NULL) {
747 gst_structure_new_id_empty (gst_query_type_to_quark (GST_QUERY_TYPE
749 gst_structure_set_parent_refcount (structure, &query->mini_object.refcount);
750 GST_QUERY_STRUCTURE (query) = structure;
756 * gst_query_new_seeking:
757 * @format: the default #GstFormat for the new query
759 * Constructs a new query object for querying seeking properties of
762 * Free-function: gst_query_unref()
764 * Returns: (transfer full): a new #GstQuery
767 gst_query_new_seeking (GstFormat format)
770 GstStructure *structure;
772 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
773 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
774 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
775 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
776 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
778 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
784 * gst_query_set_seeking:
785 * @query: a #GstQuery
786 * @format: the format to set for the @segment_start and @segment_end values
787 * @seekable: the seekable flag to set
788 * @segment_start: the segment_start to set
789 * @segment_end: the segment_end to set
791 * Set the seeking query result fields in @query.
794 gst_query_set_seeking (GstQuery * query, GstFormat format,
795 gboolean seekable, gint64 segment_start, gint64 segment_end)
797 GstStructure *structure;
799 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
800 g_return_if_fail (gst_query_is_writable (query));
802 structure = GST_QUERY_STRUCTURE (query);
803 gst_structure_id_set (structure,
804 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
805 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
806 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
807 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
811 * gst_query_parse_seeking:
812 * @query: a GST_QUERY_SEEKING type query #GstQuery
813 * @format: (out) (optional): the format to set for the @segment_start
814 * and @segment_end values, or %NULL
815 * @seekable: (out) (optional): the seekable flag to set, or %NULL
816 * @segment_start: (out) (optional): the segment_start to set, or %NULL
817 * @segment_end: (out) (optional): the segment_end to set, or %NULL
819 * Parse a seeking query, writing the format into @format, and
820 * other results into the passed parameters, if the respective parameters
824 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
825 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
827 GstStructure *structure;
829 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
831 structure = GST_QUERY_STRUCTURE (query);
834 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
835 GST_QUARK (FORMAT)));
837 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
838 GST_QUARK (SEEKABLE)));
840 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
841 GST_QUARK (SEGMENT_START)));
843 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
844 GST_QUARK (SEGMENT_END)));
848 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
849 GDestroyNotify clear_func)
854 value = gst_structure_id_get_value (s, quark);
856 array = (GArray *) g_value_get_boxed (value);
858 GValue new_array_val = { 0, };
860 array = g_array_new (FALSE, TRUE, element_size);
862 g_array_set_clear_func (array, clear_func);
864 g_value_init (&new_array_val, G_TYPE_ARRAY);
865 g_value_take_boxed (&new_array_val, array);
867 gst_structure_id_take_value (s, quark, &new_array_val);
873 * gst_query_new_formats:
875 * Constructs a new query object for querying formats of
878 * Free-function: gst_query_unref()
880 * Returns: (transfer full): a new #GstQuery
883 gst_query_new_formats (void)
886 GstStructure *structure;
888 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
889 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
895 gst_query_list_add_format (GValue * list, GstFormat format)
897 GValue item = { 0, };
899 g_value_init (&item, GST_TYPE_FORMAT);
900 g_value_set_enum (&item, format);
901 gst_value_list_append_value (list, &item);
902 g_value_unset (&item);
906 * gst_query_set_formats:
907 * @query: a #GstQuery
908 * @n_formats: the number of formats to set.
909 * @...: A number of @GstFormats equal to @n_formats.
911 * Set the formats query result fields in @query. The number of formats passed
912 * must be equal to @n_formats.
915 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
918 GValue list = { 0, };
920 GstStructure *structure;
922 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
923 g_return_if_fail (gst_query_is_writable (query));
925 g_value_init (&list, GST_TYPE_LIST);
927 va_start (ap, n_formats);
928 for (i = 0; i < n_formats; i++) {
929 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
933 structure = GST_QUERY_STRUCTURE (query);
934 gst_structure_set_value (structure, "formats", &list);
936 g_value_unset (&list);
941 * gst_query_set_formatsv:
942 * @query: a #GstQuery
943 * @n_formats: the number of formats to set.
944 * @formats: (in) (array length=n_formats): an array containing @n_formats
947 * Set the formats query result fields in @query. The number of formats passed
948 * in the @formats array must be equal to @n_formats.
951 gst_query_set_formatsv (GstQuery * query, gint n_formats,
952 const GstFormat * formats)
954 GValue list = { 0, };
956 GstStructure *structure;
958 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
959 g_return_if_fail (gst_query_is_writable (query));
961 g_value_init (&list, GST_TYPE_LIST);
962 for (i = 0; i < n_formats; i++) {
963 gst_query_list_add_format (&list, formats[i]);
965 structure = GST_QUERY_STRUCTURE (query);
966 gst_structure_set_value (structure, "formats", &list);
968 g_value_unset (&list);
972 * gst_query_parse_n_formats:
973 * @query: a #GstQuery
974 * @n_formats: (out) (optional): the number of formats in this query.
976 * Parse the number of formats in the formats @query.
979 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
981 GstStructure *structure;
983 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
988 structure = GST_QUERY_STRUCTURE (query);
989 list = gst_structure_get_value (structure, "formats");
993 *n_formats = gst_value_list_get_size (list);
998 * gst_query_parse_nth_format:
999 * @query: a #GstQuery
1000 * @nth: the nth format to retrieve.
1001 * @format: (out) (optional): a pointer to store the nth format
1003 * Parse the format query and retrieve the @nth format from it into
1004 * @format. If the list contains less elements than @nth, @format will be
1005 * set to GST_FORMAT_UNDEFINED.
1008 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1010 GstStructure *structure;
1012 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1017 structure = GST_QUERY_STRUCTURE (query);
1018 list = gst_structure_get_value (structure, "formats");
1020 *format = GST_FORMAT_UNDEFINED;
1022 if (nth < gst_value_list_get_size (list)) {
1024 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1026 *format = GST_FORMAT_UNDEFINED;
1032 * gst_query_new_buffering:
1033 * @format: the default #GstFormat for the new query
1035 * Constructs a new query object for querying the buffering status of
1038 * Free-function: gst_query_unref()
1040 * Returns: (transfer full): a new #GstQuery
1043 gst_query_new_buffering (GstFormat format)
1046 GstStructure *structure;
1048 /* by default, we configure the answer as no buffering with a 100% buffering
1050 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1051 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1052 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1053 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1054 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1055 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1056 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1057 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1058 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1059 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1060 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1062 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1068 * gst_query_set_buffering_percent:
1069 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1070 * @busy: if buffering is busy
1071 * @percent: a buffering percent
1073 * Set the percentage of buffered data. This is a value between 0 and 100.
1074 * The @busy indicator is %TRUE when the buffering is in progress.
1077 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1079 GstStructure *structure;
1081 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1082 g_return_if_fail (gst_query_is_writable (query));
1083 g_return_if_fail (percent >= 0 && percent <= 100);
1085 structure = GST_QUERY_STRUCTURE (query);
1086 gst_structure_id_set (structure,
1087 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1088 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1092 * gst_query_parse_buffering_percent:
1093 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1094 * @busy: (out) (optional): if buffering is busy, or %NULL
1095 * @percent: (out) (optional): a buffering percent, or %NULL
1097 * Get the percentage of buffered data. This is a value between 0 and 100.
1098 * The @busy indicator is %TRUE when the buffering is in progress.
1101 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1104 GstStructure *structure;
1106 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1108 structure = GST_QUERY_STRUCTURE (query);
1110 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1113 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1114 GST_QUARK (BUFFER_PERCENT)));
1118 * gst_query_set_buffering_stats:
1119 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1120 * @mode: a buffering mode
1121 * @avg_in: the average input rate
1122 * @avg_out: the average output rate
1123 * @buffering_left: amount of buffering time left in milliseconds
1125 * Configures the buffering stats values in @query.
1128 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1129 gint avg_in, gint avg_out, gint64 buffering_left)
1131 GstStructure *structure;
1133 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1134 g_return_if_fail (gst_query_is_writable (query));
1136 structure = GST_QUERY_STRUCTURE (query);
1137 gst_structure_id_set (structure,
1138 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1139 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1140 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1141 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1145 * gst_query_parse_buffering_stats:
1146 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1147 * @mode: (out) (optional): a buffering mode, or %NULL
1148 * @avg_in: (out) (optional): the average input rate, or %NULL
1149 * @avg_out: (out) (optional): the average output rat, or %NULL
1150 * @buffering_left: (out) (optional): amount of buffering time left in
1151 * milliseconds, or %NULL
1153 * Extracts the buffering stats values from @query.
1156 gst_query_parse_buffering_stats (GstQuery * query,
1157 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1158 gint64 * buffering_left)
1160 GstStructure *structure;
1162 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1164 structure = GST_QUERY_STRUCTURE (query);
1166 *mode = (GstBufferingMode)
1167 g_value_get_enum (gst_structure_id_get_value (structure,
1168 GST_QUARK (BUFFERING_MODE)));
1170 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1171 GST_QUARK (AVG_IN_RATE)));
1173 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1174 GST_QUARK (AVG_OUT_RATE)));
1177 g_value_get_int64 (gst_structure_id_get_value (structure,
1178 GST_QUARK (BUFFERING_LEFT)));
1182 * gst_query_set_buffering_range:
1183 * @query: a #GstQuery
1184 * @format: the format to set for the @start and @stop values
1185 * @start: the start to set
1186 * @stop: the stop to set
1187 * @estimated_total: estimated total amount of download time remaining in
1190 * Set the available query result fields in @query.
1193 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1194 gint64 start, gint64 stop, gint64 estimated_total)
1196 GstStructure *structure;
1198 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1199 g_return_if_fail (gst_query_is_writable (query));
1201 structure = GST_QUERY_STRUCTURE (query);
1202 gst_structure_id_set (structure,
1203 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1204 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1205 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1206 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1210 * gst_query_parse_buffering_range:
1211 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1212 * @format: (out) (optional): the format to set for the @segment_start
1213 * and @segment_end values, or %NULL
1214 * @start: (out) (optional): the start to set, or %NULL
1215 * @stop: (out) (optional): the stop to set, or %NULL
1216 * @estimated_total: (out) (optional): estimated total amount of download
1217 * time remaining in milliseconds, or %NULL
1219 * Parse an available query, writing the format into @format, and
1220 * other results into the passed parameters, if the respective parameters
1224 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1225 gint64 * start, gint64 * stop, gint64 * estimated_total)
1227 GstStructure *structure;
1229 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1231 structure = GST_QUERY_STRUCTURE (query);
1234 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1235 GST_QUARK (FORMAT)));
1237 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1238 GST_QUARK (START_VALUE)));
1240 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1241 GST_QUARK (STOP_VALUE)));
1242 if (estimated_total)
1244 g_value_get_int64 (gst_structure_id_get_value (structure,
1245 GST_QUARK (ESTIMATED_TOTAL)));
1248 /* GstQueryBufferingRange: internal struct for GArray */
1253 } GstQueryBufferingRange;
1256 * gst_query_add_buffering_range:
1257 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1258 * @start: start position of the range
1259 * @stop: stop position of the range
1261 * Set the buffering-ranges array field in @query. The current last
1262 * start position of the array should be inferior to @start.
1264 * Returns: a #gboolean indicating if the range was added or not.
1267 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1269 GstQueryBufferingRange range;
1270 GstStructure *structure;
1273 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1274 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1276 if (G_UNLIKELY (start >= stop))
1279 structure = GST_QUERY_STRUCTURE (query);
1280 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1281 sizeof (GstQueryBufferingRange), NULL);
1283 if (array->len > 1) {
1284 GstQueryBufferingRange *last;
1286 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1288 if (G_UNLIKELY (start <= last->start))
1292 range.start = start;
1294 g_array_append_val (array, range);
1300 * gst_query_get_n_buffering_ranges:
1301 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1303 * Retrieve the number of values currently stored in the
1304 * buffered-ranges array of the query's structure.
1306 * Returns: the range array size as a #guint.
1309 gst_query_get_n_buffering_ranges (GstQuery * query)
1311 GstStructure *structure;
1314 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1316 structure = GST_QUERY_STRUCTURE (query);
1317 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1318 sizeof (GstQueryBufferingRange), NULL);
1325 * gst_query_parse_nth_buffering_range:
1326 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1327 * @index: position in the buffered-ranges array to read
1328 * @start: (out) (optional): the start position to set, or %NULL
1329 * @stop: (out) (optional): the stop position to set, or %NULL
1331 * Parse an available query and get the start and stop values stored
1332 * at the @index of the buffered ranges array.
1334 * Returns: a #gboolean indicating if the parsing succeeded.
1337 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1338 gint64 * start, gint64 * stop)
1340 GstQueryBufferingRange *range;
1341 GstStructure *structure;
1344 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1346 structure = GST_QUERY_STRUCTURE (query);
1348 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1349 sizeof (GstQueryBufferingRange), NULL);
1350 g_return_val_if_fail (index < array->len, FALSE);
1352 range = &g_array_index (array, GstQueryBufferingRange, index);
1355 *start = range->start;
1357 *stop = range->stop;
1364 * gst_query_new_uri:
1366 * Constructs a new query URI query object. Use gst_query_unref()
1367 * when done with it. An URI query is used to query the current URI
1368 * that is used by the source or sink.
1370 * Free-function: gst_query_unref()
1372 * Returns: (transfer full): a new #GstQuery
1375 gst_query_new_uri (void)
1378 GstStructure *structure;
1380 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1381 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1383 query = gst_query_new_custom (GST_QUERY_URI, structure);
1389 * gst_query_set_uri:
1390 * @query: a #GstQuery with query type GST_QUERY_URI
1391 * @uri: (nullable): the URI to set
1393 * Answer a URI query by setting the requested URI.
1396 gst_query_set_uri (GstQuery * query, const gchar * uri)
1398 GstStructure *structure;
1400 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1401 g_return_if_fail (gst_query_is_writable (query));
1403 structure = GST_QUERY_STRUCTURE (query);
1404 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1408 * gst_query_parse_uri:
1409 * @query: a #GstQuery
1410 * @uri: (out) (transfer full) (optional) (nullable): the storage for the current URI
1413 * Parse an URI query, writing the URI into @uri as a newly
1414 * allocated string, if the respective parameters are non-%NULL.
1415 * Free the string with g_free() after usage.
1418 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1420 GstStructure *structure;
1422 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1424 structure = GST_QUERY_STRUCTURE (query);
1426 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1431 * gst_query_set_uri_redirection:
1432 * @query: a #GstQuery with query type GST_QUERY_URI
1433 * @uri: (nullable): the URI to set
1435 * Answer a URI query by setting the requested URI redirection.
1440 gst_query_set_uri_redirection (GstQuery * query, const gchar * uri)
1442 GstStructure *structure;
1444 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1445 g_return_if_fail (gst_query_is_writable (query));
1447 structure = GST_QUERY_STRUCTURE (query);
1448 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
1449 G_TYPE_STRING, uri, NULL);
1453 * gst_query_parse_uri_redirection:
1454 * @query: a #GstQuery
1455 * @uri: (out) (transfer full) (optional) (nullable): the storage for the redirect URI
1458 * Parse an URI query, writing the URI into @uri as a newly
1459 * allocated string, if the respective parameters are non-%NULL.
1460 * Free the string with g_free() after usage.
1465 gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
1467 GstStructure *structure;
1469 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1471 structure = GST_QUERY_STRUCTURE (query);
1473 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION),
1474 G_TYPE_STRING, uri, NULL))
1480 * gst_query_set_uri_redirection_permanent:
1481 * @query: a #GstQuery with query type %GST_QUERY_URI
1482 * @permanent: whether the redirect is permanent or not
1484 * Answer a URI query by setting the requested URI redirection
1485 * to permanent or not.
1490 gst_query_set_uri_redirection_permanent (GstQuery * query, gboolean permanent)
1492 GstStructure *structure;
1494 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1495 g_return_if_fail (gst_query_is_writable (query));
1497 structure = GST_QUERY_STRUCTURE (query);
1498 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1499 G_TYPE_BOOLEAN, permanent, NULL);
1503 * gst_query_parse_uri_redirection_permanent:
1504 * @query: a #GstQuery
1505 * @permanent: (out) (optional): if the URI redirection is permanent
1508 * Parse an URI query, and set @permanent to %TRUE if there is a redirection
1509 * and it should be considered permanent. If a redirection is permanent,
1510 * applications should update their internal storage of the URI, otherwise
1511 * they should make all future requests to the original URI.
1516 gst_query_parse_uri_redirection_permanent (GstQuery * query,
1517 gboolean * permanent)
1519 GstStructure *structure;
1521 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1523 structure = GST_QUERY_STRUCTURE (query);
1525 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1526 G_TYPE_BOOLEAN, permanent, NULL))
1532 * gst_query_new_allocation:
1533 * @caps: the negotiated caps
1534 * @need_pool: return a pool
1536 * Constructs a new query object for querying the allocation properties.
1538 * Free-function: gst_query_unref()
1540 * Returns: (transfer full): a new #GstQuery
1543 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1546 GstStructure *structure;
1548 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1549 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1550 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1552 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1558 * gst_query_parse_allocation:
1559 * @query: a #GstQuery
1560 * @caps: (out) (transfer none) (optional): The #GstCaps
1561 * @need_pool: (out) (optional): Whether a #GstBufferPool is needed
1563 * Parse an allocation query, writing the requested caps in @caps and
1564 * whether a pool is needed in @need_pool, if the respective parameters
1567 * Pool details can be retrieved using gst_query_get_n_allocation_pools() and
1568 * gst_query_parse_nth_allocation_pool().
1571 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1572 gboolean * need_pool)
1574 GstStructure *structure;
1576 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1578 structure = GST_QUERY_STRUCTURE (query);
1580 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1583 gst_structure_id_get (structure,
1584 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1589 GstBufferPool *pool;
1596 allocation_pool_free (AllocationPool * ap)
1599 gst_object_unref (ap->pool);
1603 * gst_query_add_allocation_pool:
1604 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1605 * @pool: (transfer none) (nullable): the #GstBufferPool
1606 * @size: the buffer size
1607 * @min_buffers: the min buffers
1608 * @max_buffers: the max buffers
1610 * Set the pool parameters in @query.
1613 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1614 guint size, guint min_buffers, guint max_buffers)
1617 GstStructure *structure;
1620 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1621 g_return_if_fail (gst_query_is_writable (query));
1623 structure = GST_QUERY_STRUCTURE (query);
1624 array = ensure_array (structure, GST_QUARK (POOL),
1625 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1627 if ((ap.pool = pool))
1628 gst_object_ref (pool);
1630 ap.min_buffers = min_buffers;
1631 ap.max_buffers = max_buffers;
1633 g_array_append_val (array, ap);
1637 * gst_query_get_n_allocation_pools:
1638 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1640 * Retrieve the number of values currently stored in the
1641 * pool array of the query's structure.
1643 * Returns: the pool array size as a #guint.
1646 gst_query_get_n_allocation_pools (GstQuery * query)
1649 GstStructure *structure;
1651 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1653 structure = GST_QUERY_STRUCTURE (query);
1654 array = ensure_array (structure, GST_QUARK (POOL),
1655 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1661 * gst_query_parse_nth_allocation_pool:
1662 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1663 * @index: index to parse
1664 * @pool: (out) (optional) (transfer full) (nullable): the #GstBufferPool
1665 * @size: (out) (optional): the buffer size
1666 * @min_buffers: (out) (optional): the min buffers
1667 * @max_buffers: (out) (optional): the max buffers
1669 * Get the pool parameters in @query.
1671 * Unref @pool with gst_object_unref() when it's not needed any more.
1674 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1675 GstBufferPool ** pool, guint * size, guint * min_buffers,
1676 guint * max_buffers)
1679 GstStructure *structure;
1682 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1684 structure = GST_QUERY_STRUCTURE (query);
1685 array = ensure_array (structure, GST_QUARK (POOL),
1686 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1687 g_return_if_fail (index < array->len);
1689 ap = &g_array_index (array, AllocationPool, index);
1692 if ((*pool = ap->pool))
1693 gst_object_ref (*pool);
1697 *min_buffers = ap->min_buffers;
1699 *max_buffers = ap->max_buffers;
1703 * gst_query_set_nth_allocation_pool:
1704 * @index: index to modify
1705 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1706 * @pool: (transfer none) (nullable): the #GstBufferPool
1707 * @size: the buffer size
1708 * @min_buffers: the min buffers
1709 * @max_buffers: the max buffers
1711 * Set the pool parameters in @query.
1714 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1715 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1718 GstStructure *structure;
1719 AllocationPool *oldap, ap;
1721 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1723 structure = GST_QUERY_STRUCTURE (query);
1724 array = ensure_array (structure, GST_QUARK (POOL),
1725 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1726 g_return_if_fail (index < array->len);
1728 oldap = &g_array_index (array, AllocationPool, index);
1729 allocation_pool_free (oldap);
1731 if ((ap.pool = pool))
1732 gst_object_ref (pool);
1734 ap.min_buffers = min_buffers;
1735 ap.max_buffers = max_buffers;
1736 g_array_index (array, AllocationPool, index) = ap;
1740 * gst_query_remove_nth_allocation_pool:
1741 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1742 * @index: position in the allocation pool array to remove
1744 * Remove the allocation pool at @index of the allocation pool array.
1749 gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
1752 GstStructure *structure;
1754 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1755 g_return_if_fail (gst_query_is_writable (query));
1757 structure = GST_QUERY_STRUCTURE (query);
1759 ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
1760 (GDestroyNotify) allocation_pool_free);
1761 g_return_if_fail (index < array->len);
1763 g_array_remove_index (array, index);
1769 GstStructure *params;
1773 allocation_meta_free (AllocationMeta * am)
1776 gst_structure_free (am->params);
1780 * gst_query_add_allocation_meta:
1781 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1782 * @api: the metadata API
1783 * @params: (transfer none) (nullable): API specific parameters
1785 * Add @api with @params as one of the supported metadata API to @query.
1788 gst_query_add_allocation_meta (GstQuery * query, GType api,
1789 const GstStructure * params)
1792 GstStructure *structure;
1795 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1796 g_return_if_fail (api != 0);
1797 g_return_if_fail (gst_query_is_writable (query));
1799 structure = GST_QUERY_STRUCTURE (query);
1801 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1802 (GDestroyNotify) allocation_meta_free);
1805 am.params = (params ? gst_structure_copy (params) : NULL);
1807 g_array_append_val (array, am);
1811 * gst_query_get_n_allocation_metas:
1812 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1814 * Retrieve the number of values currently stored in the
1815 * meta API array of the query's structure.
1817 * Returns: the metadata API array size as a #guint.
1820 gst_query_get_n_allocation_metas (GstQuery * query)
1823 GstStructure *structure;
1825 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1827 structure = GST_QUERY_STRUCTURE (query);
1829 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1830 (GDestroyNotify) allocation_meta_free);
1836 * gst_query_parse_nth_allocation_meta:
1837 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1838 * @index: position in the metadata API array to read
1839 * @params: (out) (transfer none) (optional): API specific parameters
1841 * Parse an available query and get the metadata API
1842 * at @index of the metadata API array.
1844 * Returns: a #GType of the metadata API at @index.
1847 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1848 const GstStructure ** params)
1851 GstStructure *structure;
1854 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1856 structure = GST_QUERY_STRUCTURE (query);
1858 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1859 (GDestroyNotify) allocation_meta_free);
1861 g_return_val_if_fail (index < array->len, 0);
1863 am = &g_array_index (array, AllocationMeta, index);
1866 *params = am->params;
1872 * gst_query_remove_nth_allocation_meta:
1873 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1874 * @index: position in the metadata API array to remove
1876 * Remove the metadata API at @index of the metadata API array.
1879 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1882 GstStructure *structure;
1884 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1885 g_return_if_fail (gst_query_is_writable (query));
1887 structure = GST_QUERY_STRUCTURE (query);
1889 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1890 (GDestroyNotify) allocation_meta_free);
1891 g_return_if_fail (index < array->len);
1893 g_array_remove_index (array, index);
1897 * gst_query_find_allocation_meta:
1898 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1899 * @api: the metadata API
1900 * @index: (out) (transfer none) (optional): the index
1902 * Check if @query has metadata @api set. When this function returns %TRUE,
1903 * @index will contain the index where the requested API and the parameters
1906 * Returns: %TRUE when @api is in the list of metadata.
1909 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1912 GstStructure *structure;
1915 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1916 g_return_val_if_fail (api != 0, FALSE);
1918 structure = GST_QUERY_STRUCTURE (query);
1920 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1921 (GDestroyNotify) allocation_meta_free);
1924 for (i = 0; i < len; i++) {
1925 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1926 if (am->api == api) {
1937 GstAllocator *allocator;
1938 GstAllocationParams params;
1942 allocation_param_free (AllocationParam * ap)
1945 gst_object_unref (ap->allocator);
1949 * gst_query_add_allocation_param:
1950 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1951 * @allocator: (transfer none) (nullable): the memory allocator
1952 * @params: (transfer none) (nullable): a #GstAllocationParams
1954 * Add @allocator and its @params as a supported memory allocator.
1957 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1958 const GstAllocationParams * params)
1961 GstStructure *structure;
1964 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1965 g_return_if_fail (gst_query_is_writable (query));
1966 g_return_if_fail (allocator != NULL || params != NULL);
1968 structure = GST_QUERY_STRUCTURE (query);
1969 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1970 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1972 if ((ap.allocator = allocator))
1973 gst_object_ref (allocator);
1975 ap.params = *params;
1977 gst_allocation_params_init (&ap.params);
1979 g_array_append_val (array, ap);
1983 * gst_query_get_n_allocation_params:
1984 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1986 * Retrieve the number of values currently stored in the
1987 * allocator params array of the query's structure.
1989 * If no memory allocator is specified, the downstream element can handle
1990 * the default memory allocator. The first memory allocator in the query
1991 * should be generic and allow mapping to system memory, all following
1992 * allocators should be ordered by preference with the preferred one first.
1994 * Returns: the allocator array size as a #guint.
1997 gst_query_get_n_allocation_params (GstQuery * query)
2000 GstStructure *structure;
2002 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
2004 structure = GST_QUERY_STRUCTURE (query);
2005 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2006 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2012 * gst_query_parse_nth_allocation_param:
2013 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2014 * @index: position in the allocator array to read
2015 * @allocator: (out) (transfer full) (optional) (nullable): variable to hold the result
2016 * @params: (out) (optional): parameters for the allocator
2018 * Parse an available query and get the allocator and its params
2019 * at @index of the allocator array.
2022 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
2023 GstAllocator ** allocator, GstAllocationParams * params)
2026 GstStructure *structure;
2027 AllocationParam *ap;
2029 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2031 structure = GST_QUERY_STRUCTURE (query);
2032 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2033 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2034 g_return_if_fail (index < array->len);
2036 ap = &g_array_index (array, AllocationParam, index);
2039 if ((*allocator = ap->allocator))
2040 gst_object_ref (*allocator);
2042 *params = ap->params;
2046 * gst_query_set_nth_allocation_param:
2047 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2048 * @index: position in the allocator array to set
2049 * @allocator: (transfer none) (nullable): new allocator to set
2050 * @params: (transfer none) (nullable): parameters for the allocator
2052 * Parse an available query and get the allocator and its params
2053 * at @index of the allocator array.
2056 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
2057 GstAllocator * allocator, const GstAllocationParams * params)
2060 GstStructure *structure;
2061 AllocationParam *old, ap;
2063 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2065 structure = GST_QUERY_STRUCTURE (query);
2066 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2067 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2068 g_return_if_fail (index < array->len);
2070 old = &g_array_index (array, AllocationParam, index);
2071 allocation_param_free (old);
2073 if ((ap.allocator = allocator))
2074 gst_object_ref (allocator);
2076 ap.params = *params;
2078 gst_allocation_params_init (&ap.params);
2080 g_array_index (array, AllocationParam, index) = ap;
2084 * gst_query_remove_nth_allocation_param:
2085 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2086 * @index: position in the allocation param array to remove
2088 * Remove the allocation param at @index of the allocation param array.
2093 gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
2096 GstStructure *structure;
2098 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2099 g_return_if_fail (gst_query_is_writable (query));
2101 structure = GST_QUERY_STRUCTURE (query);
2103 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
2104 (GDestroyNotify) allocation_param_free);
2105 g_return_if_fail (index < array->len);
2107 g_array_remove_index (array, index);
2111 * gst_query_new_scheduling:
2113 * Constructs a new query object for querying the scheduling properties.
2115 * Free-function: gst_query_unref()
2117 * Returns: (transfer full): a new #GstQuery
2120 gst_query_new_scheduling (void)
2123 GstStructure *structure;
2125 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
2126 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
2127 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
2128 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
2129 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
2130 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2136 * gst_query_set_scheduling:
2137 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2138 * @flags: #GstSchedulingFlags
2139 * @minsize: the suggested minimum size of pull requests
2140 * @maxsize: the suggested maximum size of pull requests
2141 * @align: the suggested alignment of pull requests
2143 * Set the scheduling properties.
2146 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2147 gint minsize, gint maxsize, gint align)
2149 GstStructure *structure;
2151 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2152 g_return_if_fail (gst_query_is_writable (query));
2154 structure = GST_QUERY_STRUCTURE (query);
2155 gst_structure_id_set (structure,
2156 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2157 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2158 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2159 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2163 * gst_query_parse_scheduling:
2164 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2165 * @flags: (out) (optional): #GstSchedulingFlags
2166 * @minsize: (out) (optional): the suggested minimum size of pull requests
2167 * @maxsize: (out) (optional): the suggested maximum size of pull requests:
2168 * @align: (out) (optional): the suggested alignment of pull requests
2170 * Set the scheduling properties.
2173 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2174 gint * minsize, gint * maxsize, gint * align)
2176 GstStructure *structure;
2178 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2180 structure = GST_QUERY_STRUCTURE (query);
2181 gst_structure_id_get (structure,
2182 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2183 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2184 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2185 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2189 * gst_query_add_scheduling_mode:
2190 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2191 * @mode: a #GstPadMode
2193 * Add @mode as one of the supported scheduling modes to @query.
2196 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2198 GstStructure *structure;
2201 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2202 g_return_if_fail (gst_query_is_writable (query));
2204 structure = GST_QUERY_STRUCTURE (query);
2206 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2208 g_array_append_val (array, mode);
2212 * gst_query_get_n_scheduling_modes:
2213 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2215 * Retrieve the number of values currently stored in the
2216 * scheduling mode array of the query's structure.
2218 * Returns: the scheduling mode array size as a #guint.
2221 gst_query_get_n_scheduling_modes (GstQuery * query)
2224 GstStructure *structure;
2226 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2228 structure = GST_QUERY_STRUCTURE (query);
2230 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2236 * gst_query_parse_nth_scheduling_mode:
2237 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2238 * @index: position in the scheduling modes array to read
2240 * Parse an available query and get the scheduling mode
2241 * at @index of the scheduling modes array.
2243 * Returns: a #GstPadMode of the scheduling mode at @index.
2246 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2248 GstStructure *structure;
2251 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2254 structure = GST_QUERY_STRUCTURE (query);
2256 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2257 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2259 return g_array_index (array, GstPadMode, index);
2263 * gst_query_has_scheduling_mode:
2264 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2265 * @mode: the scheduling mode
2267 * Check if @query has scheduling mode set.
2269 * > When checking if upstream supports pull mode, it is usually not
2270 * > enough to just check for GST_PAD_MODE_PULL with this function, you
2271 * > also want to check whether the scheduling flags returned by
2272 * > gst_query_parse_scheduling() have the seeking flag set (meaning
2273 * > random access is supported, not only sequential pulls).
2275 * Returns: %TRUE when @mode is in the list of scheduling modes.
2278 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2280 GstStructure *structure;
2284 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2286 structure = GST_QUERY_STRUCTURE (query);
2288 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2291 for (i = 0; i < len; i++) {
2292 if (mode == g_array_index (array, GstPadMode, i))
2299 * gst_query_has_scheduling_mode_with_flags:
2300 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2301 * @mode: the scheduling mode
2302 * @flags: #GstSchedulingFlags
2304 * Check if @query has scheduling mode set and @flags is set in
2305 * query scheduling flags.
2307 * Returns: %TRUE when @mode is in the list of scheduling modes
2308 * and @flags are compatible with query flags.
2311 gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
2312 GstSchedulingFlags flags)
2314 GstSchedulingFlags sched_flags;
2316 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2318 gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
2320 return ((flags & sched_flags) == flags) &&
2321 gst_query_has_scheduling_mode (query, mode);
2325 * gst_query_new_accept_caps:
2326 * @caps: a fixed #GstCaps
2328 * Constructs a new query object for querying if @caps are accepted.
2330 * Free-function: gst_query_unref()
2332 * Returns: (transfer full): a new #GstQuery
2335 gst_query_new_accept_caps (GstCaps * caps)
2338 GstStructure *structure;
2340 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2342 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2343 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2344 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2345 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2351 * gst_query_parse_accept_caps:
2352 * @query: The query to parse
2353 * @caps: (out) (transfer none): A pointer to the caps
2355 * Get the caps from @query. The caps remains valid as long as @query remains
2359 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2361 GstStructure *structure;
2363 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2364 g_return_if_fail (caps != NULL);
2366 structure = GST_QUERY_STRUCTURE (query);
2367 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2372 * gst_query_set_accept_caps_result:
2373 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2374 * @result: the result to set
2376 * Set @result as the result for the @query.
2379 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2381 GstStructure *structure;
2383 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2384 g_return_if_fail (gst_query_is_writable (query));
2386 structure = GST_QUERY_STRUCTURE (query);
2387 gst_structure_id_set (structure,
2388 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2392 * gst_query_parse_accept_caps_result:
2393 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2394 * @result: (out) (nullable): location for the result
2396 * Parse the result from @query and store in @result.
2399 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2401 GstStructure *structure;
2403 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2405 structure = GST_QUERY_STRUCTURE (query);
2406 gst_structure_id_get (structure,
2407 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2411 * gst_query_new_caps:
2414 * Constructs a new query object for querying the caps.
2416 * The CAPS query should return the allowable caps for a pad in the context
2417 * of the element's state, its link to other elements, and the devices or files
2418 * it has opened. These caps must be a subset of the pad template caps. In the
2419 * NULL state with no links, the CAPS query should ideally return the same caps
2420 * as the pad template. In rare circumstances, an object property can affect
2421 * the caps returned by the CAPS query, but this is discouraged.
2423 * For most filters, the caps returned by CAPS query is directly affected by the
2424 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2425 * the srcpad's getcaps function is directly related to the stream data. Again,
2426 * the CAPS query should return the most specific caps it reasonably can, since this
2427 * helps with autoplugging.
2429 * The @filter is used to restrict the result caps, only the caps matching
2430 * @filter should be returned from the CAPS query. Specifying a filter might
2431 * greatly reduce the amount of processing an element needs to do.
2433 * Free-function: gst_query_unref()
2435 * Returns: (transfer full): a new #GstQuery
2438 gst_query_new_caps (GstCaps * filter)
2441 GstStructure *structure;
2443 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2444 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2445 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2446 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2452 * gst_query_parse_caps:
2453 * @query: The query to parse
2454 * @filter: (out) (transfer none): A pointer to the caps filter
2456 * Get the filter from the caps @query. The caps remains valid as long as
2457 * @query remains valid.
2460 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2462 GstStructure *structure;
2464 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2465 g_return_if_fail (filter != NULL);
2467 structure = GST_QUERY_STRUCTURE (query);
2468 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2469 GST_QUARK (FILTER)));
2473 * gst_query_set_caps_result:
2474 * @query: The query to use
2475 * @caps: (nullable): A pointer to the caps
2477 * Set the @caps result in @query.
2480 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2482 GstStructure *structure;
2484 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2485 g_return_if_fail (gst_query_is_writable (query));
2487 structure = GST_QUERY_STRUCTURE (query);
2488 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2492 * gst_query_parse_caps_result:
2493 * @query: The query to parse
2494 * @caps: (out) (transfer none) (nullable): A pointer to the caps
2496 * Get the caps result from @query. The caps remains valid as long as
2497 * @query remains valid.
2500 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2502 GstStructure *structure;
2504 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2505 g_return_if_fail (caps != NULL);
2507 structure = GST_QUERY_STRUCTURE (query);
2508 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2514 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2515 GstCapsIntersectMode mode)
2517 GstCaps *res, *caps = NULL;
2519 gst_query_parse_caps_result (query, &caps);
2520 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2521 gst_query_set_caps_result (query, res);
2522 gst_caps_unref (res);
2527 * gst_query_new_drain:
2529 * Constructs a new query object for querying the drain state.
2531 * Free-function: gst_query_unref()
2533 * Returns: (transfer full): a new #GstQuery
2536 gst_query_new_drain (void)
2539 GstStructure *structure;
2541 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2542 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2548 * gst_query_new_context:
2549 * @context_type: Context type to query
2551 * Constructs a new query object for querying the pipeline-local context.
2553 * Free-function: gst_query_unref()
2555 * Returns: (transfer full): a new #GstQuery
2560 gst_query_new_context (const gchar * context_type)
2563 GstStructure *structure;
2565 g_return_val_if_fail (context_type != NULL, NULL);
2567 structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
2568 GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2569 query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
2575 * gst_query_set_context:
2576 * @query: a #GstQuery with query type GST_QUERY_CONTEXT
2577 * @context: (nullable): the requested #GstContext
2579 * Answer a context query by setting the requested context.
2584 gst_query_set_context (GstQuery * query, GstContext * context)
2587 const gchar *context_type;
2589 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2591 gst_query_parse_context_type (query, &context_type);
2592 g_return_if_fail (strcmp (gst_context_get_context_type (context),
2593 context_type) == 0);
2595 s = GST_QUERY_STRUCTURE (query);
2597 gst_structure_id_set (s,
2598 GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2602 * gst_query_parse_context:
2603 * @query: The query to parse
2604 * @context: (out) (transfer none) (nullable): A pointer to store the #GstContext
2606 * Get the context from the context @query. The context remains valid as long as
2607 * @query remains valid.
2612 gst_query_parse_context (GstQuery * query, GstContext ** context)
2614 GstStructure *structure;
2617 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2618 g_return_if_fail (context != NULL);
2620 structure = GST_QUERY_STRUCTURE (query);
2621 v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
2623 *context = g_value_get_boxed (v);
2629 * gst_query_parse_context_type:
2630 * @query: a GST_QUERY_CONTEXT type query
2631 * @context_type: (out) (transfer none) (optional): the context type, or %NULL
2633 * Parse a context type from an existing GST_QUERY_CONTEXT query.
2635 * Returns: a #gboolean indicating if the parsing succeeded.
2640 gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
2642 GstStructure *structure;
2643 const GValue *value;
2645 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2647 structure = GST_QUERY_STRUCTURE (query);
2650 value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2651 *context_type = g_value_get_string (value);
2658 * gst_query_new_bitrate:
2660 * Constructs a new query object for querying the bitrate.
2662 * Free-function: gst_query_unref()
2664 * Returns: (transfer full): a new #GstQuery
2669 gst_query_new_bitrate (void)
2672 GstStructure *structure;
2674 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_BITRATE));
2675 query = gst_query_new_custom (GST_QUERY_BITRATE, structure);
2681 * gst_query_set_bitrate:
2682 * @query: a GST_QUERY_BITRATE type #GstQuery
2683 * @nominal_bitrate: the nominal bitrate in bits per second
2685 * Set the results of a bitrate query. The nominal bitrate is the average
2686 * bitrate expected over the length of the stream as advertised in file
2687 * headers (or similar).
2692 gst_query_set_bitrate (GstQuery * query, guint nominal_bitrate)
2696 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
2698 s = GST_QUERY_STRUCTURE (query);
2700 gst_structure_id_set (s,
2701 GST_QUARK (NOMINAL_BITRATE), G_TYPE_UINT, nominal_bitrate, NULL);
2705 * gst_query_parse_bitrate:
2706 * @query: a GST_QUERY_BITRATE type #GstQuery
2707 * @nominal_bitrate: (out) (optional): The resulting bitrate in bits per second
2709 * Get the results of a bitrate query. See also gst_query_set_bitrate().
2714 gst_query_parse_bitrate (GstQuery * query, guint * nominal_bitrate)
2716 GstStructure *structure;
2717 const GValue *value;
2719 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
2721 structure = GST_QUERY_STRUCTURE (query);
2723 if (nominal_bitrate) {
2724 value = gst_structure_id_get_value (structure, GST_QUARK (NOMINAL_BITRATE));
2725 *nominal_bitrate = g_value_get_uint (value);
2730 * gst_query_new_selectable:
2732 * Constructs a new query object for querying the stream selection capability.
2734 * Free-function: gst_query_unref()
2736 * Returns: (transfer full): a new #GstQuery
2741 gst_query_new_selectable (void)
2744 GstStructure *structure;
2746 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_SELECTABLE));
2747 query = gst_query_new_custom (GST_QUERY_SELECTABLE, structure);
2753 * gst_query_set_selectable:
2754 * @query: a GST_QUERY_SELECTABLE type #GstQuery
2755 * @selectable: Whether the element can handle stream selection.
2757 * Set the results of a selectable query. If the element answering the query can
2758 * handle stream selection, @selectable should be set to %TRUE.
2763 gst_query_set_selectable (GstQuery * query, gboolean selectable)
2767 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SELECTABLE);
2769 s = GST_QUERY_STRUCTURE (query);
2771 gst_structure_id_set (s,
2772 GST_QUARK (SELECTABLE), G_TYPE_BOOLEAN, selectable, NULL);
2776 * gst_query_parse_selectable:
2777 * @query: a GST_QUERY_SELECTABLE type #GstQuery
2778 * @selectable: (out) (optional): The resulting stream selection capability
2780 * Get the results of a selectable query. See also gst_query_set_selectable().
2785 gst_query_parse_selectable (GstQuery * query, gboolean * selectable)
2787 GstStructure *structure;
2789 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SELECTABLE);
2791 structure = GST_QUERY_STRUCTURE (query);
2794 const GValue *value =
2795 gst_structure_id_get_value (structure, GST_QUARK (SELECTABLE));
2797 *selectable = g_value_get_boolean (value);
2799 *selectable = FALSE;
2805 * @q: a #GstQuery to increase the refcount of.
2807 * Increases the refcount of the given query by one.
2812 gst_query_ref (GstQuery * q)
2814 return GST_QUERY_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (q)));
2818 * gst_query_unref: (skip)
2819 * @q: a #GstQuery to decrease the refcount of.
2821 * Decreases the refcount of the query. If the refcount reaches 0, the query
2825 gst_query_unref (GstQuery * q)
2827 gst_mini_object_unref (GST_MINI_OBJECT_CAST (q));
2831 * gst_clear_query: (skip)
2832 * @query_ptr: a pointer to a #GstQuery reference
2834 * Clears a reference to a #GstQuery.
2836 * @query_ptr must not be %NULL.
2838 * If the reference is %NULL then this function does nothing. Otherwise, the
2839 * reference count of the query is decreased and the pointer is set to %NULL.
2844 gst_clear_query (GstQuery ** query_ptr)
2846 gst_clear_mini_object ((GstMiniObject **) query_ptr);
2850 * gst_query_copy: (skip)
2851 * @q: a #GstQuery to copy.
2853 * Copies the given query using the copy function of the parent #GstStructure.
2855 * Free-function: gst_query_unref
2857 * Returns: (transfer full): a new copy of @q.
2860 gst_query_copy (const GstQuery * q)
2862 return GST_QUERY_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (q)));
2866 * gst_query_replace: (skip)
2867 * @old_query: (inout) (transfer full) (nullable): pointer to a pointer to a
2868 * #GstQuery to be replaced.
2869 * @new_query: (nullable) (transfer none): pointer to a #GstQuery that will
2870 * replace the query pointed to by @old_query.
2872 * Modifies a pointer to a #GstQuery to point to a different #GstQuery. The
2873 * modification is done atomically (so this is useful for ensuring thread safety
2874 * in some cases), and the reference counts are updated appropriately (the old
2875 * query is unreffed, the new one is reffed).
2877 * Either @new_query or the #GstQuery pointed to by @old_query may be %NULL.
2879 * Returns: %TRUE if @new_query was different from @old_query
2882 gst_query_replace (GstQuery ** old_query, GstQuery * new_query)
2884 return gst_mini_object_replace ((GstMiniObject **) old_query,
2885 (GstMiniObject *) new_query);
2890 * @old_query: (inout) (transfer full) (nullable): pointer to a
2891 * pointer to a #GstQuery to be stolen.
2892 * @new_query: (nullable) (transfer full): pointer to a #GstQuery that will
2893 * replace the query pointed to by @old_query.
2895 * Modifies a pointer to a #GstQuery to point to a different #GstQuery. This
2896 * function is similar to gst_query_replace() except that it takes ownership of
2899 * Either @new_query or the #GstQuery pointed to by @old_query may be %NULL.
2901 * Returns: %TRUE if @new_query was different from @old_query
2906 gst_query_take (GstQuery ** old_query, GstQuery * new_query)
2908 return gst_mini_object_take ((GstMiniObject **) old_query,
2909 (GstMiniObject *) new_query);