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);
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},
112 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
115 _priv_gst_query_initialize (void)
119 _gst_query_type = gst_query_get_type ();
121 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
123 for (i = 0; query_quarks[i].name; i++) {
124 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
129 * gst_query_type_get_name:
130 * @type: the query type
132 * Get a printable name for the given query type. Do not modify or free.
134 * Returns: a reference to the static name of the query.
137 gst_query_type_get_name (GstQueryType type)
141 for (i = 0; query_quarks[i].name; i++) {
142 if (type == query_quarks[i].type)
143 return query_quarks[i].name;
149 * gst_query_type_to_quark:
150 * @type: the query type
152 * Get the unique quark for the given query type.
154 * Returns: the quark associated with the query type
157 gst_query_type_to_quark (GstQueryType type)
161 for (i = 0; query_quarks[i].name; i++) {
162 if (type == query_quarks[i].type)
163 return query_quarks[i].quark;
169 * gst_query_type_get_flags:
170 * @type: a #GstQueryType
172 * Gets the #GstQueryTypeFlags associated with @type.
174 * Returns: a #GstQueryTypeFlags.
177 gst_query_type_get_flags (GstQueryType type)
179 GstQueryTypeFlags ret;
181 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
187 _gst_query_free (GstQuery * query)
191 g_return_if_fail (query != NULL);
193 s = GST_QUERY_STRUCTURE (query);
195 gst_structure_set_parent_refcount (s, NULL);
196 gst_structure_free (s);
199 memset (query, 0xff, sizeof (GstQueryImpl));
202 g_slice_free1 (sizeof (GstQueryImpl), query);
206 _gst_query_copy (GstQuery * query)
211 s = GST_QUERY_STRUCTURE (query);
213 s = gst_structure_copy (s);
215 copy = gst_query_new_custom (query->type, s);
221 * gst_query_new_position:
222 * @format: the default #GstFormat for the new query
224 * Constructs a new query stream position query object. Use gst_query_unref()
225 * when done with it. A position query is used to query the current position
226 * of playback in the streams, in some format.
228 * Free-function: gst_query_unref()
230 * Returns: (transfer full): a new #GstQuery
233 gst_query_new_position (GstFormat format)
236 GstStructure *structure;
238 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
239 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
240 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
242 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
248 * gst_query_set_position:
249 * @query: a #GstQuery with query type GST_QUERY_POSITION
250 * @format: the requested #GstFormat
251 * @cur: the position to set
253 * Answer a position query by setting the requested value in the given format.
256 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
260 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
262 s = GST_QUERY_STRUCTURE (query);
263 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
264 GST_QUARK (FORMAT))));
266 gst_structure_id_set (s,
267 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
268 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
272 * gst_query_parse_position:
273 * @query: a #GstQuery
274 * @format: (out) (allow-none): the storage for the #GstFormat of the
275 * position values (may be %NULL)
276 * @cur: (out) (allow-none): the storage for the current position (may be %NULL)
278 * Parse a position query, writing the format into @format, and the position
279 * into @cur, if the respective parameters are non-%NULL.
282 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
284 GstStructure *structure;
286 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
288 structure = GST_QUERY_STRUCTURE (query);
291 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
292 GST_QUARK (FORMAT)));
294 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
295 GST_QUARK (CURRENT)));
300 * gst_query_new_duration:
301 * @format: the #GstFormat for this duration query
303 * Constructs a new stream duration query object to query in the given format.
304 * Use gst_query_unref() when done with it. A duration query will give the
305 * total length of the stream.
307 * Free-function: gst_query_unref()
309 * Returns: (transfer full): a new #GstQuery
312 gst_query_new_duration (GstFormat format)
315 GstStructure *structure;
317 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
318 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
319 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
321 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
327 * gst_query_set_duration:
328 * @query: a #GstQuery
329 * @format: the #GstFormat for the duration
330 * @duration: the duration of the stream
332 * Answer a duration query by setting the requested value in the given format.
335 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
339 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
341 s = GST_QUERY_STRUCTURE (query);
342 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
343 GST_QUARK (FORMAT))));
344 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
345 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
349 * gst_query_parse_duration:
350 * @query: a #GstQuery
351 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
353 * @duration: (out) (allow-none): the storage for the total duration, or %NULL.
355 * Parse a duration query answer. Write the format of the duration into @format,
356 * and the value into @duration, if the respective variables are non-%NULL.
359 gst_query_parse_duration (GstQuery * query, GstFormat * format,
362 GstStructure *structure;
364 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
366 structure = GST_QUERY_STRUCTURE (query);
369 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
370 GST_QUARK (FORMAT)));
372 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
373 GST_QUARK (DURATION)));
377 * gst_query_new_latency:
379 * Constructs a new latency query object.
380 * Use gst_query_unref() when done with it. A latency query is usually performed
381 * by sinks to compensate for additional latency introduced by elements in the
384 * Free-function: gst_query_unref()
386 * Returns: (transfer full): a #GstQuery
389 gst_query_new_latency (void)
392 GstStructure *structure;
394 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
395 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
396 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
397 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, GST_CLOCK_TIME_NONE, NULL);
399 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
405 * gst_query_set_latency:
406 * @query: a #GstQuery
407 * @live: if there is a live element upstream
408 * @min_latency: the minimal latency of the upstream elements
409 * @max_latency: the maximal latency of the upstream elements
411 * Answer a latency query by setting the requested values in the given format.
414 gst_query_set_latency (GstQuery * query, gboolean live,
415 GstClockTime min_latency, GstClockTime max_latency)
417 GstStructure *structure;
419 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
420 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
422 structure = GST_QUERY_STRUCTURE (query);
423 gst_structure_id_set (structure,
424 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
425 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
426 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
430 * gst_query_parse_latency:
431 * @query: a #GstQuery
432 * @live: (out) (allow-none): storage for live or %NULL
433 * @min_latency: (out) (allow-none): the storage for the min latency or %NULL
434 * @max_latency: (out) (allow-none): the storage for the max latency or %NULL
436 * Parse a latency query answer.
439 gst_query_parse_latency (GstQuery * query, gboolean * live,
440 GstClockTime * min_latency, GstClockTime * max_latency)
442 GstStructure *structure;
444 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
446 structure = GST_QUERY_STRUCTURE (query);
449 g_value_get_boolean (gst_structure_id_get_value (structure,
452 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
453 GST_QUARK (MIN_LATENCY)));
455 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
456 GST_QUARK (MAX_LATENCY)));
460 * gst_query_new_convert:
461 * @src_format: the source #GstFormat for the new query
462 * @value: the value to convert
463 * @dest_format: the target #GstFormat
465 * Constructs a new convert query object. Use gst_query_unref()
466 * when done with it. A convert query is used to ask for a conversion between
467 * one format and another.
469 * Free-function: gst_query_unref()
471 * Returns: (transfer full): a #GstQuery
474 gst_query_new_convert (GstFormat src_format, gint64 value,
475 GstFormat dest_format)
478 GstStructure *structure;
480 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
481 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
482 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
483 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
484 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
486 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
492 * gst_query_set_convert:
493 * @query: a #GstQuery
494 * @src_format: the source #GstFormat
495 * @src_value: the source value
496 * @dest_format: the destination #GstFormat
497 * @dest_value: the destination value
499 * Answer a convert query by setting the requested values.
502 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
503 GstFormat dest_format, gint64 dest_value)
505 GstStructure *structure;
507 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
509 structure = GST_QUERY_STRUCTURE (query);
510 gst_structure_id_set (structure,
511 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
512 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
513 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
514 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
518 * gst_query_parse_convert:
519 * @query: a #GstQuery
520 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
521 * source value, or %NULL
522 * @src_value: (out) (allow-none): the storage for the source value, or %NULL
523 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
524 * destination value, or %NULL
525 * @dest_value: (out) (allow-none): the storage for the destination value,
528 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
529 * and @dest_value may be %NULL, in which case that value is omitted.
532 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
533 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
535 GstStructure *structure;
537 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
539 structure = GST_QUERY_STRUCTURE (query);
542 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
543 GST_QUARK (SRC_FORMAT)));
545 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
546 GST_QUARK (SRC_VALUE)));
549 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
550 GST_QUARK (DEST_FORMAT)));
552 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
553 GST_QUARK (DEST_VALUE)));
557 * gst_query_new_segment:
558 * @format: the #GstFormat for the new query
560 * Constructs a new segment query object. Use gst_query_unref()
561 * when done with it. A segment query is used to discover information about the
562 * currently configured segment for playback.
564 * Free-function: gst_query_unref()
566 * Returns: (transfer full): a new #GstQuery
569 gst_query_new_segment (GstFormat format)
572 GstStructure *structure;
574 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
575 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
576 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
577 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
578 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
580 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
586 * gst_query_set_segment:
587 * @query: a #GstQuery
588 * @rate: the rate of the segment
589 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
590 * @start_value: the start value
591 * @stop_value: the stop value
593 * Answer a segment query by setting the requested values. The normal
594 * playback segment of a pipeline is 0 to duration at the default rate of
595 * 1.0. If a seek was performed on the pipeline to play a different
596 * segment, this query will return the range specified in the last seek.
598 * @start_value and @stop_value will respectively contain the configured
599 * playback range start and stop values expressed in @format.
600 * The values are always between 0 and the duration of the media and
601 * @start_value <= @stop_value. @rate will contain the playback rate. For
602 * negative rates, playback will actually happen from @stop_value to
606 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
607 gint64 start_value, gint64 stop_value)
609 GstStructure *structure;
611 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
613 structure = GST_QUERY_STRUCTURE (query);
614 gst_structure_id_set (structure,
615 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
616 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
617 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
618 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
622 * gst_query_parse_segment:
623 * @query: a #GstQuery
624 * @rate: (out) (allow-none): the storage for the rate of the segment, or %NULL
625 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
627 * @start_value: (out) (allow-none): the storage for the start value, or %NULL
628 * @stop_value: (out) (allow-none): the storage for the stop value, or %NULL
630 * Parse a segment query answer. Any of @rate, @format, @start_value, and
631 * @stop_value may be %NULL, which will cause this value to be omitted.
633 * See gst_query_set_segment() for an explanation of the function arguments.
636 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
637 gint64 * start_value, gint64 * stop_value)
639 GstStructure *structure;
641 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
643 structure = GST_QUERY_STRUCTURE (query);
645 *rate = g_value_get_double (gst_structure_id_get_value (structure,
649 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
650 GST_QUARK (FORMAT)));
652 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
653 GST_QUARK (START_VALUE)));
655 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
656 GST_QUARK (STOP_VALUE)));
660 * gst_query_new_custom:
661 * @type: the query type
662 * @structure: (allow-none) (transfer full): a structure for the query
664 * Constructs a new custom query object. Use gst_query_unref()
667 * Free-function: gst_query_unref()
669 * Returns: (transfer full) (nullable): a new #GstQuery
672 gst_query_new_custom (GstQueryType type, GstStructure * structure)
676 query = g_slice_new0 (GstQueryImpl);
678 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
681 /* structure must not have a parent */
682 if (!gst_structure_set_parent_refcount (structure,
683 &query->query.mini_object.refcount))
687 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
688 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
689 (GstMiniObjectFreeFunction) _gst_query_free);
691 GST_QUERY_TYPE (query) = type;
692 GST_QUERY_STRUCTURE (query) = structure;
694 return GST_QUERY_CAST (query);
699 g_slice_free1 (sizeof (GstQueryImpl), query);
700 g_warning ("structure is already owned by another object");
706 * gst_query_get_structure:
707 * @query: a #GstQuery
709 * Get the structure of a query.
711 * Returns: (transfer none) (nullable): the #GstStructure of the query. The
712 * structure is still owned by the query and will therefore be freed when the
716 gst_query_get_structure (GstQuery * query)
718 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
720 return GST_QUERY_STRUCTURE (query);
724 * gst_query_writable_structure:
725 * @query: a #GstQuery
727 * Get the structure of a query. This method should be called with a writable
728 * @query so that the returned structure is guaranteed to be writable.
730 * Returns: (transfer none): the #GstStructure of the query. The structure is
731 * still owned by the query and will therefore be freed when the query
735 gst_query_writable_structure (GstQuery * query)
737 GstStructure *structure;
739 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
740 g_return_val_if_fail (gst_query_is_writable (query), NULL);
742 structure = GST_QUERY_STRUCTURE (query);
744 if (structure == NULL) {
746 gst_structure_new_id_empty (gst_query_type_to_quark (GST_QUERY_TYPE
748 gst_structure_set_parent_refcount (structure, &query->mini_object.refcount);
749 GST_QUERY_STRUCTURE (query) = structure;
755 * gst_query_new_seeking:
756 * @format: the default #GstFormat for the new query
758 * Constructs a new query object for querying seeking properties of
761 * Free-function: gst_query_unref()
763 * Returns: (transfer full): a new #GstQuery
766 gst_query_new_seeking (GstFormat format)
769 GstStructure *structure;
771 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
772 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
773 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
774 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
775 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
777 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
783 * gst_query_set_seeking:
784 * @query: a #GstQuery
785 * @format: the format to set for the @segment_start and @segment_end values
786 * @seekable: the seekable flag to set
787 * @segment_start: the segment_start to set
788 * @segment_end: the segment_end to set
790 * Set the seeking query result fields in @query.
793 gst_query_set_seeking (GstQuery * query, GstFormat format,
794 gboolean seekable, gint64 segment_start, gint64 segment_end)
796 GstStructure *structure;
798 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
799 g_return_if_fail (gst_query_is_writable (query));
801 structure = GST_QUERY_STRUCTURE (query);
802 gst_structure_id_set (structure,
803 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
804 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
805 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
806 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
810 * gst_query_parse_seeking:
811 * @query: a GST_QUERY_SEEKING type query #GstQuery
812 * @format: (out) (allow-none): the format to set for the @segment_start
813 * and @segment_end values, or %NULL
814 * @seekable: (out) (allow-none): the seekable flag to set, or %NULL
815 * @segment_start: (out) (allow-none): the segment_start to set, or %NULL
816 * @segment_end: (out) (allow-none): the segment_end to set, or %NULL
818 * Parse a seeking query, writing the format into @format, and
819 * other results into the passed parameters, if the respective parameters
823 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
824 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
826 GstStructure *structure;
828 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
830 structure = GST_QUERY_STRUCTURE (query);
833 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
834 GST_QUARK (FORMAT)));
836 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
837 GST_QUARK (SEEKABLE)));
839 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
840 GST_QUARK (SEGMENT_START)));
842 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
843 GST_QUARK (SEGMENT_END)));
847 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
848 GDestroyNotify clear_func)
853 value = gst_structure_id_get_value (s, quark);
855 array = (GArray *) g_value_get_boxed (value);
857 GValue new_array_val = { 0, };
859 array = g_array_new (FALSE, TRUE, element_size);
861 g_array_set_clear_func (array, clear_func);
863 g_value_init (&new_array_val, G_TYPE_ARRAY);
864 g_value_take_boxed (&new_array_val, array);
866 gst_structure_id_take_value (s, quark, &new_array_val);
872 * gst_query_new_formats:
874 * Constructs a new query object for querying formats of
877 * Free-function: gst_query_unref()
879 * Returns: (transfer full): a new #GstQuery
882 gst_query_new_formats (void)
885 GstStructure *structure;
887 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
888 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
894 gst_query_list_add_format (GValue * list, GstFormat format)
896 GValue item = { 0, };
898 g_value_init (&item, GST_TYPE_FORMAT);
899 g_value_set_enum (&item, format);
900 gst_value_list_append_value (list, &item);
901 g_value_unset (&item);
905 * gst_query_set_formats:
906 * @query: a #GstQuery
907 * @n_formats: the number of formats to set.
908 * @...: A number of @GstFormats equal to @n_formats.
910 * Set the formats query result fields in @query. The number of formats passed
911 * must be equal to @n_formats.
914 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
917 GValue list = { 0, };
919 GstStructure *structure;
921 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
922 g_return_if_fail (gst_query_is_writable (query));
924 g_value_init (&list, GST_TYPE_LIST);
926 va_start (ap, n_formats);
927 for (i = 0; i < n_formats; i++) {
928 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
932 structure = GST_QUERY_STRUCTURE (query);
933 gst_structure_set_value (structure, "formats", &list);
935 g_value_unset (&list);
940 * gst_query_set_formatsv:
941 * @query: a #GstQuery
942 * @n_formats: the number of formats to set.
943 * @formats: (in) (array length=n_formats): an array containing @n_formats
946 * Set the formats query result fields in @query. The number of formats passed
947 * in the @formats array must be equal to @n_formats.
950 gst_query_set_formatsv (GstQuery * query, gint n_formats,
951 const GstFormat * formats)
953 GValue list = { 0, };
955 GstStructure *structure;
957 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
958 g_return_if_fail (gst_query_is_writable (query));
960 g_value_init (&list, GST_TYPE_LIST);
961 for (i = 0; i < n_formats; i++) {
962 gst_query_list_add_format (&list, formats[i]);
964 structure = GST_QUERY_STRUCTURE (query);
965 gst_structure_set_value (structure, "formats", &list);
967 g_value_unset (&list);
971 * gst_query_parse_n_formats:
972 * @query: a #GstQuery
973 * @n_formats: (out) (allow-none): the number of formats in this query.
975 * Parse the number of formats in the formats @query.
978 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
980 GstStructure *structure;
982 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
987 structure = GST_QUERY_STRUCTURE (query);
988 list = gst_structure_get_value (structure, "formats");
992 *n_formats = gst_value_list_get_size (list);
997 * gst_query_parse_nth_format:
998 * @query: a #GstQuery
999 * @nth: the nth format to retrieve.
1000 * @format: (out) (allow-none): a pointer to store the nth format
1002 * Parse the format query and retrieve the @nth format from it into
1003 * @format. If the list contains less elements than @nth, @format will be
1004 * set to GST_FORMAT_UNDEFINED.
1007 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1009 GstStructure *structure;
1011 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1016 structure = GST_QUERY_STRUCTURE (query);
1017 list = gst_structure_get_value (structure, "formats");
1019 *format = GST_FORMAT_UNDEFINED;
1021 if (nth < gst_value_list_get_size (list)) {
1023 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1025 *format = GST_FORMAT_UNDEFINED;
1031 * gst_query_new_buffering:
1032 * @format: the default #GstFormat for the new query
1034 * Constructs a new query object for querying the buffering status of
1037 * Free-function: gst_query_unref()
1039 * Returns: (transfer full): a new #GstQuery
1042 gst_query_new_buffering (GstFormat format)
1045 GstStructure *structure;
1047 /* by default, we configure the answer as no buffering with a 100% buffering
1049 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1050 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1051 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1052 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1053 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1054 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1055 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1056 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1057 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1058 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1059 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1061 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1067 * gst_query_set_buffering_percent:
1068 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1069 * @busy: if buffering is busy
1070 * @percent: a buffering percent
1072 * Set the percentage of buffered data. This is a value between 0 and 100.
1073 * The @busy indicator is %TRUE when the buffering is in progress.
1076 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1078 GstStructure *structure;
1080 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1081 g_return_if_fail (gst_query_is_writable (query));
1082 g_return_if_fail (percent >= 0 && percent <= 100);
1084 structure = GST_QUERY_STRUCTURE (query);
1085 gst_structure_id_set (structure,
1086 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1087 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1091 * gst_query_parse_buffering_percent:
1092 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1093 * @busy: (out) (allow-none): if buffering is busy, or %NULL
1094 * @percent: (out) (allow-none): a buffering percent, or %NULL
1096 * Get the percentage of buffered data. This is a value between 0 and 100.
1097 * The @busy indicator is %TRUE when the buffering is in progress.
1100 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1103 GstStructure *structure;
1105 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1107 structure = GST_QUERY_STRUCTURE (query);
1109 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1112 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1113 GST_QUARK (BUFFER_PERCENT)));
1117 * gst_query_set_buffering_stats:
1118 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1119 * @mode: a buffering mode
1120 * @avg_in: the average input rate
1121 * @avg_out: the average output rate
1122 * @buffering_left: amount of buffering time left in milliseconds
1124 * Configures the buffering stats values in @query.
1127 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1128 gint avg_in, gint avg_out, gint64 buffering_left)
1130 GstStructure *structure;
1132 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1133 g_return_if_fail (gst_query_is_writable (query));
1135 structure = GST_QUERY_STRUCTURE (query);
1136 gst_structure_id_set (structure,
1137 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1138 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1139 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1140 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1144 * gst_query_parse_buffering_stats:
1145 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1146 * @mode: (out) (allow-none): a buffering mode, or %NULL
1147 * @avg_in: (out) (allow-none): the average input rate, or %NULL
1148 * @avg_out: (out) (allow-none): the average output rat, or %NULL
1149 * @buffering_left: (out) (allow-none): amount of buffering time left in
1150 * milliseconds, or %NULL
1152 * Extracts the buffering stats values from @query.
1155 gst_query_parse_buffering_stats (GstQuery * query,
1156 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1157 gint64 * buffering_left)
1159 GstStructure *structure;
1161 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1163 structure = GST_QUERY_STRUCTURE (query);
1165 *mode = (GstBufferingMode)
1166 g_value_get_enum (gst_structure_id_get_value (structure,
1167 GST_QUARK (BUFFERING_MODE)));
1169 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1170 GST_QUARK (AVG_IN_RATE)));
1172 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1173 GST_QUARK (AVG_OUT_RATE)));
1176 g_value_get_int64 (gst_structure_id_get_value (structure,
1177 GST_QUARK (BUFFERING_LEFT)));
1181 * gst_query_set_buffering_range:
1182 * @query: a #GstQuery
1183 * @format: the format to set for the @start and @stop values
1184 * @start: the start to set
1185 * @stop: the stop to set
1186 * @estimated_total: estimated total amount of download time remaining in
1189 * Set the available query result fields in @query.
1192 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1193 gint64 start, gint64 stop, gint64 estimated_total)
1195 GstStructure *structure;
1197 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1198 g_return_if_fail (gst_query_is_writable (query));
1200 structure = GST_QUERY_STRUCTURE (query);
1201 gst_structure_id_set (structure,
1202 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1203 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1204 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1205 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1209 * gst_query_parse_buffering_range:
1210 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1211 * @format: (out) (allow-none): the format to set for the @segment_start
1212 * and @segment_end values, or %NULL
1213 * @start: (out) (allow-none): the start to set, or %NULL
1214 * @stop: (out) (allow-none): the stop to set, or %NULL
1215 * @estimated_total: (out) (allow-none): estimated total amount of download
1216 * time remaining in milliseconds, or %NULL
1218 * Parse an available query, writing the format into @format, and
1219 * other results into the passed parameters, if the respective parameters
1223 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1224 gint64 * start, gint64 * stop, gint64 * estimated_total)
1226 GstStructure *structure;
1228 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1230 structure = GST_QUERY_STRUCTURE (query);
1233 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1234 GST_QUARK (FORMAT)));
1236 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1237 GST_QUARK (START_VALUE)));
1239 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1240 GST_QUARK (STOP_VALUE)));
1241 if (estimated_total)
1243 g_value_get_int64 (gst_structure_id_get_value (structure,
1244 GST_QUARK (ESTIMATED_TOTAL)));
1247 /* GstQueryBufferingRange: internal struct for GArray */
1252 } GstQueryBufferingRange;
1255 * gst_query_add_buffering_range:
1256 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1257 * @start: start position of the range
1258 * @stop: stop position of the range
1260 * Set the buffering-ranges array field in @query. The current last
1261 * start position of the array should be inferior to @start.
1263 * Returns: a #gboolean indicating if the range was added or not.
1266 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1268 GstQueryBufferingRange range;
1269 GstStructure *structure;
1272 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1273 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1275 if (G_UNLIKELY (start >= stop))
1278 structure = GST_QUERY_STRUCTURE (query);
1279 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1280 sizeof (GstQueryBufferingRange), NULL);
1282 if (array->len > 1) {
1283 GstQueryBufferingRange *last;
1285 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1287 if (G_UNLIKELY (start <= last->start))
1291 range.start = start;
1293 g_array_append_val (array, range);
1299 * gst_query_get_n_buffering_ranges:
1300 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1302 * Retrieve the number of values currently stored in the
1303 * buffered-ranges array of the query's structure.
1305 * Returns: the range array size as a #guint.
1308 gst_query_get_n_buffering_ranges (GstQuery * query)
1310 GstStructure *structure;
1313 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1315 structure = GST_QUERY_STRUCTURE (query);
1316 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1317 sizeof (GstQueryBufferingRange), NULL);
1324 * gst_query_parse_nth_buffering_range:
1325 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1326 * @index: position in the buffered-ranges array to read
1327 * @start: (out) (allow-none): the start position to set, or %NULL
1328 * @stop: (out) (allow-none): the stop position to set, or %NULL
1330 * Parse an available query and get the start and stop values stored
1331 * at the @index of the buffered ranges array.
1333 * Returns: a #gboolean indicating if the parsing succeeded.
1336 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1337 gint64 * start, gint64 * stop)
1339 GstQueryBufferingRange *range;
1340 GstStructure *structure;
1343 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1345 structure = GST_QUERY_STRUCTURE (query);
1347 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1348 sizeof (GstQueryBufferingRange), NULL);
1349 g_return_val_if_fail (index < array->len, FALSE);
1351 range = &g_array_index (array, GstQueryBufferingRange, index);
1354 *start = range->start;
1356 *stop = range->stop;
1363 * gst_query_new_uri:
1365 * Constructs a new query URI query object. Use gst_query_unref()
1366 * when done with it. An URI query is used to query the current URI
1367 * that is used by the source or sink.
1369 * Free-function: gst_query_unref()
1371 * Returns: (transfer full): a new #GstQuery
1374 gst_query_new_uri (void)
1377 GstStructure *structure;
1379 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1380 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1382 query = gst_query_new_custom (GST_QUERY_URI, structure);
1388 * gst_query_set_uri:
1389 * @query: a #GstQuery with query type GST_QUERY_URI
1390 * @uri: the URI to set
1392 * Answer a URI query by setting the requested URI.
1395 gst_query_set_uri (GstQuery * query, const gchar * uri)
1397 GstStructure *structure;
1399 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1400 g_return_if_fail (gst_query_is_writable (query));
1401 g_return_if_fail (gst_uri_is_valid (uri));
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) (allow-none): 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: 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));
1446 g_return_if_fail (gst_uri_is_valid (uri));
1448 structure = GST_QUERY_STRUCTURE (query);
1449 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
1450 G_TYPE_STRING, uri, NULL);
1454 * gst_query_parse_uri_redirection:
1455 * @query: a #GstQuery
1456 * @uri: (out) (transfer full) (allow-none): the storage for the redirect URI
1459 * Parse an URI query, writing the URI into @uri as a newly
1460 * allocated string, if the respective parameters are non-%NULL.
1461 * Free the string with g_free() after usage.
1466 gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
1468 GstStructure *structure;
1470 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1472 structure = GST_QUERY_STRUCTURE (query);
1474 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION),
1475 G_TYPE_STRING, uri, NULL))
1481 * gst_query_set_uri_redirection_permanent:
1482 * @query: a #GstQuery with query type %GST_QUERY_URI
1483 * @permanent: whether the redirect is permanent or not
1485 * Answer a URI query by setting the requested URI redirection
1486 * to permanent or not.
1491 gst_query_set_uri_redirection_permanent (GstQuery * query, gboolean permanent)
1493 GstStructure *structure;
1495 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1496 g_return_if_fail (gst_query_is_writable (query));
1498 structure = GST_QUERY_STRUCTURE (query);
1499 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1500 G_TYPE_BOOLEAN, permanent, NULL);
1504 * gst_query_parse_uri_redirection_permanent:
1505 * @query: a #GstQuery
1506 * @permanent: (out) (allow-none): if the URI redirection is permanent
1509 * Parse an URI query, and set @permanent to %TRUE if there is a redirection
1510 * and it should be considered permanent. If a redirection is permanent,
1511 * applications should update their internal storage of the URI, otherwise
1512 * they should make all future requests to the original URI.
1517 gst_query_parse_uri_redirection_permanent (GstQuery * query,
1518 gboolean * permanent)
1520 GstStructure *structure;
1522 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1524 structure = GST_QUERY_STRUCTURE (query);
1526 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1527 G_TYPE_BOOLEAN, permanent, NULL))
1533 * gst_query_new_allocation:
1534 * @caps: the negotiated caps
1535 * @need_pool: return a pool
1537 * Constructs a new query object for querying the allocation properties.
1539 * Free-function: gst_query_unref()
1541 * Returns: (transfer full): a new #GstQuery
1544 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1547 GstStructure *structure;
1549 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1550 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1551 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1553 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1559 * gst_query_parse_allocation:
1560 * @query: a #GstQuery
1561 * @caps: (out) (transfer none) (allow-none): The #GstCaps
1562 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1564 * Parse an allocation query, writing the requested caps in @caps and
1565 * whether a pool is needed in @need_pool, if the respective parameters
1568 * Pool details can be retrieved using gst_query_get_n_allocation_pools() and
1569 * gst_query_parse_nth_allocation_pool().
1572 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1573 gboolean * need_pool)
1575 GstStructure *structure;
1577 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1579 structure = GST_QUERY_STRUCTURE (query);
1581 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1584 gst_structure_id_get (structure,
1585 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1590 GstBufferPool *pool;
1597 allocation_pool_free (AllocationPool * ap)
1600 gst_object_unref (ap->pool);
1604 * gst_query_add_allocation_pool:
1605 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1606 * @pool: (transfer none) (allow-none): the #GstBufferPool
1607 * @size: the buffer size
1608 * @min_buffers: the min buffers
1609 * @max_buffers: the max buffers
1611 * Set the pool parameters in @query.
1614 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1615 guint size, guint min_buffers, guint max_buffers)
1618 GstStructure *structure;
1621 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1622 g_return_if_fail (gst_query_is_writable (query));
1624 structure = GST_QUERY_STRUCTURE (query);
1625 array = ensure_array (structure, GST_QUARK (POOL),
1626 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1628 if ((ap.pool = pool))
1629 gst_object_ref (pool);
1631 ap.min_buffers = min_buffers;
1632 ap.max_buffers = max_buffers;
1634 g_array_append_val (array, ap);
1638 * gst_query_get_n_allocation_pools:
1639 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1641 * Retrieve the number of values currently stored in the
1642 * pool array of the query's structure.
1644 * Returns: the pool array size as a #guint.
1647 gst_query_get_n_allocation_pools (GstQuery * query)
1650 GstStructure *structure;
1652 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1654 structure = GST_QUERY_STRUCTURE (query);
1655 array = ensure_array (structure, GST_QUARK (POOL),
1656 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1662 * gst_query_parse_nth_allocation_pool:
1663 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1664 * @index: index to parse
1665 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1666 * @size: (out) (allow-none): the buffer size
1667 * @min_buffers: (out) (allow-none): the min buffers
1668 * @max_buffers: (out) (allow-none): the max buffers
1670 * Get the pool parameters in @query.
1672 * Unref @pool with gst_object_unref() when it's not needed any more.
1675 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1676 GstBufferPool ** pool, guint * size, guint * min_buffers,
1677 guint * max_buffers)
1680 GstStructure *structure;
1683 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1685 structure = GST_QUERY_STRUCTURE (query);
1686 array = ensure_array (structure, GST_QUARK (POOL),
1687 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1688 g_return_if_fail (index < array->len);
1690 ap = &g_array_index (array, AllocationPool, index);
1693 if ((*pool = ap->pool))
1694 gst_object_ref (*pool);
1698 *min_buffers = ap->min_buffers;
1700 *max_buffers = ap->max_buffers;
1704 * gst_query_set_nth_allocation_pool:
1705 * @index: index to modify
1706 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1707 * @pool: (transfer none) (allow-none): the #GstBufferPool
1708 * @size: the buffer size
1709 * @min_buffers: the min buffers
1710 * @max_buffers: the max buffers
1712 * Set the pool parameters in @query.
1715 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1716 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1719 GstStructure *structure;
1720 AllocationPool *oldap, ap;
1722 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1724 structure = GST_QUERY_STRUCTURE (query);
1725 array = ensure_array (structure, GST_QUARK (POOL),
1726 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1727 g_return_if_fail (index < array->len);
1729 oldap = &g_array_index (array, AllocationPool, index);
1730 allocation_pool_free (oldap);
1732 if ((ap.pool = pool))
1733 gst_object_ref (pool);
1735 ap.min_buffers = min_buffers;
1736 ap.max_buffers = max_buffers;
1737 g_array_index (array, AllocationPool, index) = ap;
1741 * gst_query_remove_nth_allocation_pool:
1742 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1743 * @index: position in the allocation pool array to remove
1745 * Remove the allocation pool at @index of the allocation pool array.
1750 gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
1753 GstStructure *structure;
1755 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1756 g_return_if_fail (gst_query_is_writable (query));
1758 structure = GST_QUERY_STRUCTURE (query);
1760 ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
1761 (GDestroyNotify) allocation_pool_free);
1762 g_return_if_fail (index < array->len);
1764 g_array_remove_index (array, index);
1770 GstStructure *params;
1774 allocation_meta_free (AllocationMeta * am)
1777 gst_structure_free (am->params);
1781 * gst_query_add_allocation_meta:
1782 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1783 * @api: the metadata API
1784 * @params: (transfer none) (allow-none): API specific parameters
1786 * Add @api with @params as one of the supported metadata API to @query.
1789 gst_query_add_allocation_meta (GstQuery * query, GType api,
1790 const GstStructure * params)
1793 GstStructure *structure;
1796 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1797 g_return_if_fail (api != 0);
1798 g_return_if_fail (gst_query_is_writable (query));
1800 structure = GST_QUERY_STRUCTURE (query);
1802 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1803 (GDestroyNotify) allocation_meta_free);
1806 am.params = (params ? gst_structure_copy (params) : NULL);
1808 g_array_append_val (array, am);
1812 * gst_query_get_n_allocation_metas:
1813 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1815 * Retrieve the number of values currently stored in the
1816 * meta API array of the query's structure.
1818 * Returns: the metadata API array size as a #guint.
1821 gst_query_get_n_allocation_metas (GstQuery * query)
1824 GstStructure *structure;
1826 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1828 structure = GST_QUERY_STRUCTURE (query);
1830 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1831 (GDestroyNotify) allocation_meta_free);
1837 * gst_query_parse_nth_allocation_meta:
1838 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1839 * @index: position in the metadata API array to read
1840 * @params: (out) (transfer none) (allow-none): API specific parameters
1842 * Parse an available query and get the metadata API
1843 * at @index of the metadata API array.
1845 * Returns: a #GType of the metadata API at @index.
1848 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1849 const GstStructure ** params)
1852 GstStructure *structure;
1855 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1857 structure = GST_QUERY_STRUCTURE (query);
1859 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1860 (GDestroyNotify) allocation_meta_free);
1862 g_return_val_if_fail (index < array->len, 0);
1864 am = &g_array_index (array, AllocationMeta, index);
1867 *params = am->params;
1873 * gst_query_remove_nth_allocation_meta:
1874 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1875 * @index: position in the metadata API array to remove
1877 * Remove the metadata API at @index of the metadata API array.
1880 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1883 GstStructure *structure;
1885 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1886 g_return_if_fail (gst_query_is_writable (query));
1888 structure = GST_QUERY_STRUCTURE (query);
1890 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1891 (GDestroyNotify) allocation_meta_free);
1892 g_return_if_fail (index < array->len);
1894 g_array_remove_index (array, index);
1898 * gst_query_find_allocation_meta:
1899 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1900 * @api: the metadata API
1901 * @index: (out) (transfer none) (allow-none): the index
1903 * Check if @query has metadata @api set. When this function returns %TRUE,
1904 * @index will contain the index where the requested API and the parameters
1907 * Returns: %TRUE when @api is in the list of metadata.
1910 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1913 GstStructure *structure;
1916 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1917 g_return_val_if_fail (api != 0, FALSE);
1919 structure = GST_QUERY_STRUCTURE (query);
1921 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1922 (GDestroyNotify) allocation_meta_free);
1925 for (i = 0; i < len; i++) {
1926 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1927 if (am->api == api) {
1938 GstAllocator *allocator;
1939 GstAllocationParams params;
1943 allocation_param_free (AllocationParam * ap)
1946 gst_object_unref (ap->allocator);
1950 * gst_query_add_allocation_param:
1951 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1952 * @allocator: (transfer none) (allow-none): the memory allocator
1953 * @params: (transfer none) (allow-none): a #GstAllocationParams
1955 * Add @allocator and its @params as a supported memory allocator.
1958 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1959 const GstAllocationParams * params)
1962 GstStructure *structure;
1965 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1966 g_return_if_fail (gst_query_is_writable (query));
1967 g_return_if_fail (allocator != NULL || params != NULL);
1969 structure = GST_QUERY_STRUCTURE (query);
1970 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1971 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1973 if ((ap.allocator = allocator))
1974 gst_object_ref (allocator);
1976 ap.params = *params;
1978 gst_allocation_params_init (&ap.params);
1980 g_array_append_val (array, ap);
1984 * gst_query_get_n_allocation_params:
1985 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1987 * Retrieve the number of values currently stored in the
1988 * allocator params array of the query's structure.
1990 * If no memory allocator is specified, the downstream element can handle
1991 * the default memory allocator. The first memory allocator in the query
1992 * should be generic and allow mapping to system memory, all following
1993 * allocators should be ordered by preference with the preferred one first.
1995 * Returns: the allocator array size as a #guint.
1998 gst_query_get_n_allocation_params (GstQuery * query)
2001 GstStructure *structure;
2003 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
2005 structure = GST_QUERY_STRUCTURE (query);
2006 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2007 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2013 * gst_query_parse_nth_allocation_param:
2014 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2015 * @index: position in the allocator array to read
2016 * @allocator: (out) (transfer full) (allow-none): variable to hold the result
2017 * @params: (out) (allow-none): parameters for the allocator
2019 * Parse an available query and get the allocator and its params
2020 * at @index of the allocator array.
2023 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
2024 GstAllocator ** allocator, GstAllocationParams * params)
2027 GstStructure *structure;
2028 AllocationParam *ap;
2030 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2032 structure = GST_QUERY_STRUCTURE (query);
2033 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2034 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2035 g_return_if_fail (index < array->len);
2037 ap = &g_array_index (array, AllocationParam, index);
2040 if ((*allocator = ap->allocator))
2041 gst_object_ref (*allocator);
2043 *params = ap->params;
2047 * gst_query_set_nth_allocation_param:
2048 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2049 * @index: position in the allocator array to set
2050 * @allocator: (transfer none) (allow-none): new allocator to set
2051 * @params: (transfer none) (allow-none): parameters for the allocator
2053 * Parse an available query and get the allocator and its params
2054 * at @index of the allocator array.
2057 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
2058 GstAllocator * allocator, const GstAllocationParams * params)
2061 GstStructure *structure;
2062 AllocationParam *old, ap;
2064 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2066 structure = GST_QUERY_STRUCTURE (query);
2067 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2068 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2069 g_return_if_fail (index < array->len);
2071 old = &g_array_index (array, AllocationParam, index);
2072 allocation_param_free (old);
2074 if ((ap.allocator = allocator))
2075 gst_object_ref (allocator);
2077 ap.params = *params;
2079 gst_allocation_params_init (&ap.params);
2081 g_array_index (array, AllocationParam, index) = ap;
2085 * gst_query_remove_nth_allocation_param:
2086 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2087 * @index: position in the allocation param array to remove
2089 * Remove the allocation param at @index of the allocation param array.
2094 gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
2097 GstStructure *structure;
2099 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2100 g_return_if_fail (gst_query_is_writable (query));
2102 structure = GST_QUERY_STRUCTURE (query);
2104 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
2105 (GDestroyNotify) allocation_param_free);
2106 g_return_if_fail (index < array->len);
2108 g_array_remove_index (array, index);
2112 * gst_query_new_scheduling:
2114 * Constructs a new query object for querying the scheduling properties.
2116 * Free-function: gst_query_unref()
2118 * Returns: (transfer full): a new #GstQuery
2121 gst_query_new_scheduling (void)
2124 GstStructure *structure;
2126 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
2127 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
2128 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
2129 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
2130 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
2131 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2137 * gst_query_set_scheduling:
2138 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2139 * @flags: #GstSchedulingFlags
2140 * @minsize: the suggested minimum size of pull requests
2141 * @maxsize: the suggested maximum size of pull requests
2142 * @align: the suggested alignment of pull requests
2144 * Set the scheduling properties.
2147 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2148 gint minsize, gint maxsize, gint align)
2150 GstStructure *structure;
2152 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2153 g_return_if_fail (gst_query_is_writable (query));
2155 structure = GST_QUERY_STRUCTURE (query);
2156 gst_structure_id_set (structure,
2157 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2158 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2159 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2160 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2164 * gst_query_parse_scheduling:
2165 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2166 * @flags: (out) (allow-none): #GstSchedulingFlags
2167 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
2168 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
2169 * @align: (out) (allow-none): the suggested alignment of pull requests
2171 * Set the scheduling properties.
2174 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2175 gint * minsize, gint * maxsize, gint * align)
2177 GstStructure *structure;
2179 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2181 structure = GST_QUERY_STRUCTURE (query);
2182 gst_structure_id_get (structure,
2183 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2184 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2185 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2186 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2190 * gst_query_add_scheduling_mode:
2191 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2192 * @mode: a #GstPadMode
2194 * Add @mode as one of the supported scheduling modes to @query.
2197 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2199 GstStructure *structure;
2202 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2203 g_return_if_fail (gst_query_is_writable (query));
2205 structure = GST_QUERY_STRUCTURE (query);
2207 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2209 g_array_append_val (array, mode);
2213 * gst_query_get_n_scheduling_modes:
2214 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2216 * Retrieve the number of values currently stored in the
2217 * scheduling mode array of the query's structure.
2219 * Returns: the scheduling mode array size as a #guint.
2222 gst_query_get_n_scheduling_modes (GstQuery * query)
2225 GstStructure *structure;
2227 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2229 structure = GST_QUERY_STRUCTURE (query);
2231 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2237 * gst_query_parse_nth_scheduling_mode:
2238 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2239 * @index: position in the scheduling modes array to read
2241 * Parse an available query and get the scheduling mode
2242 * at @index of the scheduling modes array.
2244 * Returns: a #GstPadMode of the scheduling mode at @index.
2247 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2249 GstStructure *structure;
2252 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2255 structure = GST_QUERY_STRUCTURE (query);
2257 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2258 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2260 return g_array_index (array, GstPadMode, index);
2264 * gst_query_has_scheduling_mode:
2265 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2266 * @mode: the scheduling mode
2268 * Check if @query has scheduling mode set.
2270 * > When checking if upstream supports pull mode, it is usually not
2271 * > enough to just check for GST_PAD_MODE_PULL with this function, you
2272 * > also want to check whether the scheduling flags returned by
2273 * > gst_query_parse_scheduling() have the seeking flag set (meaning
2274 * > random access is supported, not only sequential pulls).
2276 * Returns: %TRUE when @mode is in the list of scheduling modes.
2279 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2281 GstStructure *structure;
2285 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2287 structure = GST_QUERY_STRUCTURE (query);
2289 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2292 for (i = 0; i < len; i++) {
2293 if (mode == g_array_index (array, GstPadMode, i))
2300 * gst_query_has_scheduling_mode_with_flags:
2301 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2302 * @mode: the scheduling mode
2303 * @flags: #GstSchedulingFlags
2305 * Check if @query has scheduling mode set and @flags is set in
2306 * query scheduling flags.
2308 * Returns: %TRUE when @mode is in the list of scheduling modes
2309 * and @flags are compatible with query flags.
2312 gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
2313 GstSchedulingFlags flags)
2315 GstSchedulingFlags sched_flags;
2317 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2319 gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
2321 return ((flags & sched_flags) == flags) &&
2322 gst_query_has_scheduling_mode (query, mode);
2326 * gst_query_new_accept_caps:
2327 * @caps: a fixed #GstCaps
2329 * Constructs a new query object for querying if @caps are accepted.
2331 * Free-function: gst_query_unref()
2333 * Returns: (transfer full): a new #GstQuery
2336 gst_query_new_accept_caps (GstCaps * caps)
2339 GstStructure *structure;
2341 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2343 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2344 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2345 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2346 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2352 * gst_query_parse_accept_caps:
2353 * @query: The query to parse
2354 * @caps: (out) (transfer none): A pointer to the caps
2356 * Get the caps from @query. The caps remains valid as long as @query remains
2360 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2362 GstStructure *structure;
2364 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2365 g_return_if_fail (caps != NULL);
2367 structure = GST_QUERY_STRUCTURE (query);
2368 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2373 * gst_query_set_accept_caps_result:
2374 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2375 * @result: the result to set
2377 * Set @result as the result for the @query.
2380 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2382 GstStructure *structure;
2384 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2385 g_return_if_fail (gst_query_is_writable (query));
2387 structure = GST_QUERY_STRUCTURE (query);
2388 gst_structure_id_set (structure,
2389 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2393 * gst_query_parse_accept_caps_result:
2394 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2395 * @result: (out) (allow-none): location for the result
2397 * Parse the result from @query and store in @result.
2400 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2402 GstStructure *structure;
2404 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2406 structure = GST_QUERY_STRUCTURE (query);
2407 gst_structure_id_get (structure,
2408 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2412 * gst_query_new_caps:
2415 * Constructs a new query object for querying the caps.
2417 * The CAPS query should return the allowable caps for a pad in the context
2418 * of the element's state, its link to other elements, and the devices or files
2419 * it has opened. These caps must be a subset of the pad template caps. In the
2420 * NULL state with no links, the CAPS query should ideally return the same caps
2421 * as the pad template. In rare circumstances, an object property can affect
2422 * the caps returned by the CAPS query, but this is discouraged.
2424 * For most filters, the caps returned by CAPS query is directly affected by the
2425 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2426 * the srcpad's getcaps function is directly related to the stream data. Again,
2427 * the CAPS query should return the most specific caps it reasonably can, since this
2428 * helps with autoplugging.
2430 * The @filter is used to restrict the result caps, only the caps matching
2431 * @filter should be returned from the CAPS query. Specifying a filter might
2432 * greatly reduce the amount of processing an element needs to do.
2434 * Free-function: gst_query_unref()
2436 * Returns: (transfer full): a new #GstQuery
2439 gst_query_new_caps (GstCaps * filter)
2442 GstStructure *structure;
2444 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2445 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2446 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2447 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2453 * gst_query_parse_caps:
2454 * @query: The query to parse
2455 * @filter: (out) (transfer none): A pointer to the caps filter
2457 * Get the filter from the caps @query. The caps remains valid as long as
2458 * @query remains valid.
2461 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2463 GstStructure *structure;
2465 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2466 g_return_if_fail (filter != NULL);
2468 structure = GST_QUERY_STRUCTURE (query);
2469 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2470 GST_QUARK (FILTER)));
2474 * gst_query_set_caps_result:
2475 * @query: The query to use
2476 * @caps: (in): A pointer to the caps
2478 * Set the @caps result in @query.
2481 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2483 GstStructure *structure;
2485 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2486 g_return_if_fail (gst_query_is_writable (query));
2488 structure = GST_QUERY_STRUCTURE (query);
2489 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2493 * gst_query_parse_caps_result:
2494 * @query: The query to parse
2495 * @caps: (out) (transfer none): A pointer to the caps
2497 * Get the caps result from @query. The caps remains valid as long as
2498 * @query remains valid.
2501 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2503 GstStructure *structure;
2505 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2506 g_return_if_fail (caps != NULL);
2508 structure = GST_QUERY_STRUCTURE (query);
2509 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2515 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2516 GstCapsIntersectMode mode)
2518 GstCaps *res, *caps = NULL;
2520 gst_query_parse_caps_result (query, &caps);
2521 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2522 gst_query_set_caps_result (query, res);
2523 gst_caps_unref (res);
2528 * gst_query_new_drain:
2530 * Constructs a new query object for querying the drain state.
2532 * Free-function: gst_query_unref()
2534 * Returns: (transfer full): a new #GstQuery
2537 gst_query_new_drain (void)
2540 GstStructure *structure;
2542 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2543 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2549 * gst_query_new_context:
2550 * @context_type: Context type to query
2552 * Constructs a new query object for querying the pipeline-local context.
2554 * Free-function: gst_query_unref()
2556 * Returns: (transfer full): a new #GstQuery
2561 gst_query_new_context (const gchar * context_type)
2564 GstStructure *structure;
2566 g_return_val_if_fail (context_type != NULL, NULL);
2568 structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
2569 GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2570 query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
2576 * gst_query_set_context:
2577 * @query: a #GstQuery with query type GST_QUERY_CONTEXT
2578 * @context: the requested #GstContext
2580 * Answer a context query by setting the requested context.
2585 gst_query_set_context (GstQuery * query, GstContext * context)
2588 const gchar *context_type;
2590 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2592 gst_query_parse_context_type (query, &context_type);
2593 g_return_if_fail (strcmp (gst_context_get_context_type (context),
2594 context_type) == 0);
2596 s = GST_QUERY_STRUCTURE (query);
2598 gst_structure_id_set (s,
2599 GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2603 * gst_query_parse_context:
2604 * @query: The query to parse
2605 * @context: (out) (transfer none): A pointer to store the #GstContext
2607 * Get the context from the context @query. The context remains valid as long as
2608 * @query remains valid.
2613 gst_query_parse_context (GstQuery * query, GstContext ** context)
2615 GstStructure *structure;
2618 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2619 g_return_if_fail (context != NULL);
2621 structure = GST_QUERY_STRUCTURE (query);
2622 v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
2624 *context = g_value_get_boxed (v);
2630 * gst_query_parse_context_type:
2631 * @query: a GST_QUERY_CONTEXT type query
2632 * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
2634 * Parse a context type from an existing GST_QUERY_CONTEXT query.
2636 * Returns: a #gboolean indicating if the parsing succeeded.
2641 gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
2643 GstStructure *structure;
2644 const GValue *value;
2646 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2648 structure = GST_QUERY_STRUCTURE (query);
2651 value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2652 *context_type = g_value_get_string (value);