2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
4 * 2005 Wim Taymans <wim@fluendo.com>
6 * gstquery.c: GstQueryType registration and Query parsing/creation
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * @short_description: Dynamically register new query types. Provide functions
27 * to create queries, and to set and parse values in them.
28 * @see_also: #GstPad, #GstElement
30 * GstQuery functions are used to register new query types to the gstreamer
32 * Queries can be performed on pads (gst_pad_query()) and elements
33 * (gst_element_query()). Please note that some queries might need a running
36 * Queries can be created using the gst_query_new_*() functions.
37 * Query values can be set using gst_query_set_*(), and parsed using
38 * gst_query_parse_*() helpers.
40 * The following example shows how to query the duration of a pipeline:
43 * <title>Query duration on a pipeline</title>
47 * query = gst_query_new_duration (GST_FORMAT_TIME);
48 * res = gst_element_query (pipeline, query);
51 * gst_query_parse_duration (query, NULL, &duration);
52 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
55 * g_print ("duration query failed...");
57 * gst_query_unref (query);
61 * Last reviewed on 2006-02-14 (0.10.4)
65 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
66 * with newer GLib versions (>= 2.31.0) */
67 #define GLIB_DISABLE_DEPRECATION_WARNINGS
69 #include "gst_private.h"
73 #include "gstenumtypes.h"
76 #include "gstbufferpool.h"
78 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
79 #define GST_CAT_DEFAULT gst_query_debug
81 static GType _gst_query_type = 0;
87 GstStructure *structure;
90 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
92 /* GstQueryBufferingRange: internal struct for GArray */
97 } GstQueryBufferingRange;
100 static GList *_gst_queries = NULL;
101 static GHashTable *_nick_to_query = NULL;
102 static GHashTable *_query_type_to_nick = NULL;
103 static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */
105 static GstQueryTypeDefinition standard_definitions[] = {
106 {GST_QUERY_POSITION, "position", "Current position", 0},
107 {GST_QUERY_DURATION, "duration", "Total duration", 0},
108 {GST_QUERY_LATENCY, "latency", "Latency", 0},
109 {GST_QUERY_JITTER, "jitter", "Jitter", 0},
110 {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
111 {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
112 {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
113 {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
114 {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
115 {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
116 {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
117 {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
118 {GST_QUERY_ALLOCATION, "allocation", "Allocation properties", 0},
119 {GST_QUERY_SCHEDULING, "scheduling", "Scheduling properties", 0},
120 {GST_QUERY_ACCEPT_CAPS, "accept-caps", "Accept caps", 0},
121 {GST_QUERY_CAPS, "caps", "Caps", 0},
122 {GST_QUERY_NONE, NULL, NULL, 0}
125 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
128 _priv_gst_query_initialize (void)
130 GstQueryTypeDefinition *standards = standard_definitions;
132 GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
134 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
136 g_mutex_lock (&mutex);
137 if (_nick_to_query == NULL) {
138 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
139 _query_type_to_nick = g_hash_table_new (NULL, NULL);
142 while (standards->nick) {
143 standards->quark = g_quark_from_static_string (standards->nick);
144 g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
145 g_hash_table_insert (_query_type_to_nick,
146 GINT_TO_POINTER (standards->value), standards);
148 _gst_queries = g_list_append (_gst_queries, standards);
152 g_mutex_unlock (&mutex);
154 _gst_query_type = gst_query_get_type ();
158 * gst_query_type_get_name:
159 * @query: the query type
161 * Get a printable name for the given query type. Do not modify or free.
163 * Returns: a reference to the static name of the query.
166 gst_query_type_get_name (GstQueryType query)
168 const GstQueryTypeDefinition *def;
170 def = gst_query_type_get_details (query);
171 g_return_val_if_fail (def != NULL, NULL);
177 * gst_query_type_to_quark:
178 * @query: the query type
180 * Get the unique quark for the given query type.
182 * Returns: the quark associated with the query type
185 gst_query_type_to_quark (GstQueryType query)
187 const GstQueryTypeDefinition *def;
189 def = gst_query_type_get_details (query);
190 g_return_val_if_fail (def != NULL, 0);
196 * gst_query_type_register:
197 * @nick: The nick of the new query
198 * @description: The description of the new query
200 * Create a new GstQueryType based on the nick or return an
201 * already registered query with that nick
203 * Returns: A new GstQueryType or an already registered query
204 * with the same nick.
207 gst_query_type_register (const gchar * nick, const gchar * description)
209 GstQueryTypeDefinition *query;
212 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
213 g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
215 lookup = gst_query_type_get_by_nick (nick);
216 if (lookup != GST_QUERY_NONE)
219 query = g_slice_new (GstQueryTypeDefinition);
220 query->value = (GstQueryType) _n_values;
221 query->nick = g_strdup (nick);
222 query->description = g_strdup (description);
223 query->quark = g_quark_from_static_string (query->nick);
225 g_mutex_lock (&mutex);
226 g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
227 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
229 _gst_queries = g_list_append (_gst_queries, query);
231 g_mutex_unlock (&mutex);
237 * gst_query_type_get_by_nick:
238 * @nick: The nick of the query
240 * Get the query type registered with @nick.
242 * Returns: The query registered with @nick or #GST_QUERY_NONE
243 * if the query was not registered.
246 gst_query_type_get_by_nick (const gchar * nick)
248 GstQueryTypeDefinition *query;
250 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
252 g_mutex_lock (&mutex);
253 query = g_hash_table_lookup (_nick_to_query, nick);
254 g_mutex_unlock (&mutex);
259 return GST_QUERY_NONE;
263 * gst_query_types_contains:
264 * @types: The query array to search
265 * @type: the #GstQueryType to find
267 * See if the given #GstQueryType is inside the @types query types array.
269 * Returns: TRUE if the type is found inside the array
272 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
288 * gst_query_type_get_details:
289 * @type: a #GstQueryType
291 * Get details about the given #GstQueryType.
293 * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
295 const GstQueryTypeDefinition *
296 gst_query_type_get_details (GstQueryType type)
298 const GstQueryTypeDefinition *result;
300 g_mutex_lock (&mutex);
301 result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
302 g_mutex_unlock (&mutex);
308 * gst_query_type_iterate_definitions:
310 * Get a #GstIterator of all the registered query types. The definitions
311 * iterated over are read only.
313 * Free-function: gst_iterator_free
315 * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
318 gst_query_type_iterate_definitions (void)
322 g_mutex_lock (&mutex);
323 /* FIXME: register a boxed type for GstQueryTypeDefinition */
324 result = gst_iterator_new_list (G_TYPE_POINTER,
325 &mutex, &_n_values, &_gst_queries, NULL, NULL);
326 g_mutex_unlock (&mutex);
332 _gst_query_free (GstQuery * query)
336 g_return_if_fail (query != NULL);
338 s = GST_QUERY_STRUCTURE (query);
340 gst_structure_set_parent_refcount (s, NULL);
341 gst_structure_free (s);
344 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
348 _gst_query_copy (GstQuery * query)
352 copy = gst_query_new_custom (query->type, GST_QUERY_STRUCTURE (query));
358 gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
360 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
362 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
363 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
365 GST_EVENT_TYPE (query) = type;
369 * gst_query_new_position:
370 * @format: the default #GstFormat for the new query
372 * Constructs a new query stream position query object. Use gst_query_unref()
373 * when done with it. A position query is used to query the current position
374 * of playback in the streams, in some format.
376 * Free-function: gst_query_unref
378 * Returns: (transfer full): a new #GstQuery
381 gst_query_new_position (GstFormat format)
384 GstStructure *structure;
386 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
387 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
388 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
390 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
396 * gst_query_set_position:
397 * @query: a #GstQuery with query type GST_QUERY_POSITION
398 * @format: the requested #GstFormat
399 * @cur: the position to set
401 * Answer a position query by setting the requested value in the given format.
404 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
408 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
410 s = GST_QUERY_STRUCTURE (query);
411 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
412 GST_QUARK (FORMAT))));
414 gst_structure_id_set (s,
415 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
416 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
420 * gst_query_parse_position:
421 * @query: a #GstQuery
422 * @format: (out) (allow-none): the storage for the #GstFormat of the
423 * position values (may be NULL)
424 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
426 * Parse a position query, writing the format into @format, and the position
427 * into @cur, if the respective parameters are non-NULL.
430 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
432 GstStructure *structure;
434 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
436 structure = GST_QUERY_STRUCTURE (query);
439 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
440 GST_QUARK (FORMAT)));
442 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
443 GST_QUARK (CURRENT)));
448 * gst_query_new_duration:
449 * @format: the #GstFormat for this duration query
451 * Constructs a new stream duration query object to query in the given format.
452 * Use gst_query_unref() when done with it. A duration query will give the
453 * total length of the stream.
455 * Free-function: gst_query_unref
457 * Returns: (transfer full): a new #GstQuery
460 gst_query_new_duration (GstFormat format)
463 GstStructure *structure;
465 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
466 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
467 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
469 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
475 * gst_query_set_duration:
476 * @query: a #GstQuery
477 * @format: the #GstFormat for the duration
478 * @duration: the duration of the stream
480 * Answer a duration query by setting the requested value in the given format.
483 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
487 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
489 s = GST_QUERY_STRUCTURE (query);
490 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
491 GST_QUARK (FORMAT))));
492 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
493 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
497 * gst_query_parse_duration:
498 * @query: a #GstQuery
499 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
501 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
503 * Parse a duration query answer. Write the format of the duration into @format,
504 * and the value into @duration, if the respective variables are non-NULL.
507 gst_query_parse_duration (GstQuery * query, GstFormat * format,
510 GstStructure *structure;
512 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
514 structure = GST_QUERY_STRUCTURE (query);
517 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
518 GST_QUARK (FORMAT)));
520 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
521 GST_QUARK (DURATION)));
525 * gst_query_new_latency:
527 * Constructs a new latency query object.
528 * Use gst_query_unref() when done with it. A latency query is usually performed
529 * by sinks to compensate for additional latency introduced by elements in the
532 * Free-function: gst_query_unref
534 * Returns: (transfer full): a #GstQuery
539 gst_query_new_latency (void)
542 GstStructure *structure;
544 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
545 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
546 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
547 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
549 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
555 * gst_query_set_latency:
556 * @query: a #GstQuery
557 * @live: if there is a live element upstream
558 * @min_latency: the minimal latency of the upstream elements
559 * @max_latency: the maximal latency of the upstream elements
561 * Answer a latency query by setting the requested values in the given format.
566 gst_query_set_latency (GstQuery * query, gboolean live,
567 GstClockTime min_latency, GstClockTime max_latency)
569 GstStructure *structure;
571 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
573 structure = GST_QUERY_STRUCTURE (query);
574 gst_structure_id_set (structure,
575 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
576 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
577 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
581 * gst_query_parse_latency:
582 * @query: a #GstQuery
583 * @live: (out) (allow-none): storage for live or NULL
584 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
585 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
587 * Parse a latency query answer.
592 gst_query_parse_latency (GstQuery * query, gboolean * live,
593 GstClockTime * min_latency, GstClockTime * max_latency)
595 GstStructure *structure;
597 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
599 structure = GST_QUERY_STRUCTURE (query);
602 g_value_get_boolean (gst_structure_id_get_value (structure,
605 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
606 GST_QUARK (MIN_LATENCY)));
608 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
609 GST_QUARK (MAX_LATENCY)));
613 * gst_query_new_convert:
614 * @src_format: the source #GstFormat for the new query
615 * @value: the value to convert
616 * @dest_format: the target #GstFormat
618 * Constructs a new convert query object. Use gst_query_unref()
619 * when done with it. A convert query is used to ask for a conversion between
620 * one format and another.
622 * Free-function: gst_query_unref
624 * Returns: (transfer full): a #GstQuery
627 gst_query_new_convert (GstFormat src_format, gint64 value,
628 GstFormat dest_format)
631 GstStructure *structure;
633 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
634 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
635 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
636 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
637 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
639 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
645 * gst_query_set_convert:
646 * @query: a #GstQuery
647 * @src_format: the source #GstFormat
648 * @src_value: the source value
649 * @dest_format: the destination #GstFormat
650 * @dest_value: the destination value
652 * Answer a convert query by setting the requested values.
655 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
656 GstFormat dest_format, gint64 dest_value)
658 GstStructure *structure;
660 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
662 structure = GST_QUERY_STRUCTURE (query);
663 gst_structure_id_set (structure,
664 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
665 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
666 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
667 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
671 * gst_query_parse_convert:
672 * @query: a #GstQuery
673 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
674 * source value, or NULL
675 * @src_value: (out) (allow-none): the storage for the source value, or NULL
676 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
677 * destination value, or NULL
678 * @dest_value: (out) (allow-none): the storage for the destination value,
681 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
682 * and @dest_value may be NULL, in which case that value is omitted.
685 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
686 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
688 GstStructure *structure;
690 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
692 structure = GST_QUERY_STRUCTURE (query);
695 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
696 GST_QUARK (SRC_FORMAT)));
698 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
699 GST_QUARK (SRC_VALUE)));
702 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
703 GST_QUARK (DEST_FORMAT)));
705 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
706 GST_QUARK (DEST_VALUE)));
710 * gst_query_new_segment:
711 * @format: the #GstFormat for the new query
713 * Constructs a new segment query object. Use gst_query_unref()
714 * when done with it. A segment query is used to discover information about the
715 * currently configured segment for playback.
717 * Free-function: gst_query_unref
719 * Returns: (transfer full): a new #GstQuery
722 gst_query_new_segment (GstFormat format)
725 GstStructure *structure;
727 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
728 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
729 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
730 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
731 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
733 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
739 * gst_query_set_segment:
740 * @query: a #GstQuery
741 * @rate: the rate of the segment
742 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
743 * @start_value: the start value
744 * @stop_value: the stop value
746 * Answer a segment query by setting the requested values. The normal
747 * playback segment of a pipeline is 0 to duration at the default rate of
748 * 1.0. If a seek was performed on the pipeline to play a different
749 * segment, this query will return the range specified in the last seek.
751 * @start_value and @stop_value will respectively contain the configured
752 * playback range start and stop values expressed in @format.
753 * The values are always between 0 and the duration of the media and
754 * @start_value <= @stop_value. @rate will contain the playback rate. For
755 * negative rates, playback will actually happen from @stop_value to
759 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
760 gint64 start_value, gint64 stop_value)
762 GstStructure *structure;
764 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
766 structure = GST_QUERY_STRUCTURE (query);
767 gst_structure_id_set (structure,
768 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
769 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
770 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
771 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
775 * gst_query_parse_segment:
776 * @query: a #GstQuery
777 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
778 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
780 * @start_value: (out) (allow-none): the storage for the start value, or NULL
781 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
783 * Parse a segment query answer. Any of @rate, @format, @start_value, and
784 * @stop_value may be NULL, which will cause this value to be omitted.
786 * See gst_query_set_segment() for an explanation of the function arguments.
789 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
790 gint64 * start_value, gint64 * stop_value)
792 GstStructure *structure;
794 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
796 structure = GST_QUERY_STRUCTURE (query);
798 *rate = g_value_get_double (gst_structure_id_get_value (structure,
802 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
803 GST_QUARK (FORMAT)));
805 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
806 GST_QUARK (START_VALUE)));
808 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
809 GST_QUARK (STOP_VALUE)));
813 * gst_query_new_custom:
814 * @type: the query type
815 * @structure: a structure for the query
817 * Constructs a new custom query object. Use gst_query_unref()
820 * Free-function: gst_query_unref
822 * Returns: (transfer full): a new #GstQuery
825 gst_query_new_custom (GstQueryType type, GstStructure * structure)
829 query = g_slice_new0 (GstQueryImpl);
831 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
834 /* structure must not have a parent */
835 if (!gst_structure_set_parent_refcount (structure,
836 &query->query.mini_object.refcount))
839 gst_query_init (query, sizeof (GstQueryImpl), type);
841 GST_QUERY_STRUCTURE (query) = structure;
843 return GST_QUERY_CAST (query);
848 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
849 g_warning ("structure is already owned by another object");
855 * gst_query_get_structure:
856 * @query: a #GstQuery
858 * Get the structure of a query.
860 * Returns: (transfer none): the #GstStructure of the query. The structure is
861 * still owned by the query and will therefore be freed when the query
865 gst_query_get_structure (GstQuery * query)
867 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
869 return GST_QUERY_STRUCTURE (query);
873 * gst_query_writable_structure:
874 * @query: a #GstQuery
876 * Get the structure of a query. This method should be called with a writable
877 * @query so that the returned structure is guranteed to be writable.
879 * Returns: (transfer none): the #GstStructure of the query. The structure is
880 * still owned by the query and will therefore be freed when the query
884 gst_query_writable_structure (GstQuery * query)
886 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
887 g_return_val_if_fail (gst_query_is_writable (query), NULL);
889 return GST_QUERY_STRUCTURE (query);
893 * gst_query_new_seeking:
894 * @format: the default #GstFormat for the new query
896 * Constructs a new query object for querying seeking properties of
899 * Free-function: gst_query_unref
901 * Returns: (transfer full): a new #GstQuery
904 gst_query_new_seeking (GstFormat format)
907 GstStructure *structure;
909 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
910 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
911 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
912 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
913 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
915 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
921 * gst_query_set_seeking:
922 * @query: a #GstQuery
923 * @format: the format to set for the @segment_start and @segment_end values
924 * @seekable: the seekable flag to set
925 * @segment_start: the segment_start to set
926 * @segment_end: the segment_end to set
928 * Set the seeking query result fields in @query.
931 gst_query_set_seeking (GstQuery * query, GstFormat format,
932 gboolean seekable, gint64 segment_start, gint64 segment_end)
934 GstStructure *structure;
936 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
937 g_return_if_fail (gst_query_is_writable (query));
939 structure = GST_QUERY_STRUCTURE (query);
940 gst_structure_id_set (structure,
941 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
942 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
943 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
944 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
948 * gst_query_parse_seeking:
949 * @query: a GST_QUERY_SEEKING type query #GstQuery
950 * @format: (out) (allow-none): the format to set for the @segment_start
951 * and @segment_end values, or NULL
952 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
953 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
954 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
956 * Parse a seeking query, writing the format into @format, and
957 * other results into the passed parameters, if the respective parameters
961 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
962 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
964 GstStructure *structure;
966 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
968 structure = GST_QUERY_STRUCTURE (query);
971 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
972 GST_QUARK (FORMAT)));
974 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
975 GST_QUARK (SEEKABLE)));
977 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
978 GST_QUARK (SEGMENT_START)));
980 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
981 GST_QUARK (SEGMENT_END)));
985 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
986 GDestroyNotify clear_func)
991 value = gst_structure_id_get_value (s, quark);
993 array = (GArray *) g_value_get_boxed (value);
995 GValue new_array_val = { 0, };
997 array = g_array_new (FALSE, TRUE, element_size);
999 g_array_set_clear_func (array, clear_func);
1001 g_value_init (&new_array_val, G_TYPE_ARRAY);
1002 g_value_take_boxed (&new_array_val, array);
1004 gst_structure_id_take_value (s, quark, &new_array_val);
1010 * gst_query_new_formats:
1012 * Constructs a new query object for querying formats of
1015 * Free-function: gst_query_unref
1017 * Returns: (transfer full): a new #GstQuery
1022 gst_query_new_formats (void)
1025 GstStructure *structure;
1027 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
1028 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
1034 gst_query_list_add_format (GValue * list, GstFormat format)
1036 GValue item = { 0, };
1038 g_value_init (&item, GST_TYPE_FORMAT);
1039 g_value_set_enum (&item, format);
1040 gst_value_list_append_value (list, &item);
1041 g_value_unset (&item);
1045 * gst_query_set_formats:
1046 * @query: a #GstQuery
1047 * @n_formats: the number of formats to set.
1048 * @...: A number of @GstFormats equal to @n_formats.
1050 * Set the formats query result fields in @query. The number of formats passed
1051 * must be equal to @n_formats.
1054 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1057 GValue list = { 0, };
1059 GstStructure *structure;
1061 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1062 g_return_if_fail (gst_query_is_writable (query));
1064 g_value_init (&list, GST_TYPE_LIST);
1066 va_start (ap, n_formats);
1067 for (i = 0; i < n_formats; i++) {
1068 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1072 structure = GST_QUERY_STRUCTURE (query);
1073 gst_structure_set_value (structure, "formats", &list);
1075 g_value_unset (&list);
1080 * gst_query_set_formatsv:
1081 * @query: a #GstQuery
1082 * @n_formats: the number of formats to set.
1083 * @formats: (in) (array length=n_formats): an array containing @n_formats
1084 * @GstFormat values.
1086 * Set the formats query result fields in @query. The number of formats passed
1087 * in the @formats array must be equal to @n_formats.
1092 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1093 const GstFormat * formats)
1095 GValue list = { 0, };
1097 GstStructure *structure;
1099 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1100 g_return_if_fail (gst_query_is_writable (query));
1102 g_value_init (&list, GST_TYPE_LIST);
1103 for (i = 0; i < n_formats; i++) {
1104 gst_query_list_add_format (&list, formats[i]);
1106 structure = GST_QUERY_STRUCTURE (query);
1107 gst_structure_set_value (structure, "formats", &list);
1109 g_value_unset (&list);
1113 * gst_query_parse_n_formats:
1114 * @query: a #GstQuery
1115 * @n_formats: (out) (allow-none): the number of formats in this query.
1117 * Parse the number of formats in the formats @query.
1122 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1124 GstStructure *structure;
1126 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1131 structure = GST_QUERY_STRUCTURE (query);
1132 list = gst_structure_get_value (structure, "formats");
1136 *n_formats = gst_value_list_get_size (list);
1141 * gst_query_parse_nth_format:
1142 * @query: a #GstQuery
1143 * @nth: (out): the nth format to retrieve.
1144 * @format: (out) (allow-none): a pointer to store the nth format
1146 * Parse the format query and retrieve the @nth format from it into
1147 * @format. If the list contains less elements than @nth, @format will be
1148 * set to GST_FORMAT_UNDEFINED.
1151 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1153 GstStructure *structure;
1155 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1160 structure = GST_QUERY_STRUCTURE (query);
1161 list = gst_structure_get_value (structure, "formats");
1163 *format = GST_FORMAT_UNDEFINED;
1165 if (nth < gst_value_list_get_size (list)) {
1167 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1169 *format = GST_FORMAT_UNDEFINED;
1175 * gst_query_new_buffering:
1176 * @format: the default #GstFormat for the new query
1178 * Constructs a new query object for querying the buffering status of
1181 * Free-function: gst_query_unref
1183 * Returns: (transfer full): a new #GstQuery
1188 gst_query_new_buffering (GstFormat format)
1191 GstStructure *structure;
1193 /* by default, we configure the answer as no buffering with a 100% buffering
1195 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1196 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1197 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1198 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1199 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1200 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1201 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1202 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1203 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1204 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1205 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1207 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1213 * gst_query_set_buffering_percent:
1214 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1215 * @busy: if buffering is busy
1216 * @percent: a buffering percent
1218 * Set the percentage of buffered data. This is a value between 0 and 100.
1219 * The @busy indicator is %TRUE when the buffering is in progress.
1224 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1226 GstStructure *structure;
1228 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1229 g_return_if_fail (gst_query_is_writable (query));
1230 g_return_if_fail (percent >= 0 && percent <= 100);
1232 structure = GST_QUERY_STRUCTURE (query);
1233 gst_structure_id_set (structure,
1234 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1235 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1239 * gst_query_parse_buffering_percent:
1240 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1241 * @busy: (out) (allow-none): if buffering is busy, or NULL
1242 * @percent: (out) (allow-none): a buffering percent, or NULL
1244 * Get the percentage of buffered data. This is a value between 0 and 100.
1245 * The @busy indicator is %TRUE when the buffering is in progress.
1250 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1253 GstStructure *structure;
1255 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1257 structure = GST_QUERY_STRUCTURE (query);
1259 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1262 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1263 GST_QUARK (BUFFER_PERCENT)));
1267 * gst_query_set_buffering_stats:
1268 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1269 * @mode: a buffering mode
1270 * @avg_in: the average input rate
1271 * @avg_out: the average output rate
1272 * @buffering_left: amount of buffering time left
1274 * Configures the buffering stats values in @query.
1279 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1280 gint avg_in, gint avg_out, gint64 buffering_left)
1282 GstStructure *structure;
1284 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1285 g_return_if_fail (gst_query_is_writable (query));
1287 structure = GST_QUERY_STRUCTURE (query);
1288 gst_structure_id_set (structure,
1289 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1290 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1291 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1292 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1296 * gst_query_parse_buffering_stats:
1297 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1298 * @mode: (out) (allow-none): a buffering mode, or NULL
1299 * @avg_in: (out) (allow-none): the average input rate, or NULL
1300 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1301 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1303 * Extracts the buffering stats values from @query.
1308 gst_query_parse_buffering_stats (GstQuery * query,
1309 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1310 gint64 * buffering_left)
1312 GstStructure *structure;
1314 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1316 structure = GST_QUERY_STRUCTURE (query);
1318 *mode = (GstBufferingMode)
1319 g_value_get_enum (gst_structure_id_get_value (structure,
1320 GST_QUARK (BUFFERING_MODE)));
1322 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1323 GST_QUARK (AVG_IN_RATE)));
1325 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1326 GST_QUARK (AVG_OUT_RATE)));
1329 g_value_get_int64 (gst_structure_id_get_value (structure,
1330 GST_QUARK (BUFFERING_LEFT)));
1334 * gst_query_set_buffering_range:
1335 * @query: a #GstQuery
1336 * @format: the format to set for the @start and @stop values
1337 * @start: the start to set
1338 * @stop: the stop to set
1339 * @estimated_total: estimated total amount of download time
1341 * Set the available query result fields in @query.
1346 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1347 gint64 start, gint64 stop, gint64 estimated_total)
1349 GstStructure *structure;
1351 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1352 g_return_if_fail (gst_query_is_writable (query));
1354 structure = GST_QUERY_STRUCTURE (query);
1355 gst_structure_id_set (structure,
1356 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1357 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1358 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1359 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1363 * gst_query_parse_buffering_range:
1364 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1365 * @format: (out) (allow-none): the format to set for the @segment_start
1366 * and @segment_end values, or NULL
1367 * @start: (out) (allow-none): the start to set, or NULL
1368 * @stop: (out) (allow-none): the stop to set, or NULL
1369 * @estimated_total: (out) (allow-none): estimated total amount of download
1372 * Parse an available query, writing the format into @format, and
1373 * other results into the passed parameters, if the respective parameters
1379 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1380 gint64 * start, gint64 * stop, gint64 * estimated_total)
1382 GstStructure *structure;
1384 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1386 structure = GST_QUERY_STRUCTURE (query);
1389 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1390 GST_QUARK (FORMAT)));
1392 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1393 GST_QUARK (START_VALUE)));
1395 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1396 GST_QUARK (STOP_VALUE)));
1397 if (estimated_total)
1399 g_value_get_int64 (gst_structure_id_get_value (structure,
1400 GST_QUARK (ESTIMATED_TOTAL)));
1404 * gst_query_add_buffering_range:
1405 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1406 * @start: start position of the range
1407 * @stop: stop position of the range
1409 * Set the buffering-ranges array field in @query. The current last
1410 * start position of the array should be inferior to @start.
1412 * Returns: a #gboolean indicating if the range was added or not.
1417 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1419 GstQueryBufferingRange range;
1420 GstStructure *structure;
1423 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1424 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1426 if (G_UNLIKELY (start >= stop))
1429 structure = GST_QUERY_STRUCTURE (query);
1430 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1431 sizeof (GstQueryBufferingRange), NULL);
1433 if (array->len > 1) {
1434 GstQueryBufferingRange *last;
1436 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1438 if (G_UNLIKELY (start <= last->start))
1442 range.start = start;
1444 g_array_append_val (array, range);
1450 * gst_query_get_n_buffering_ranges:
1451 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1453 * Retrieve the number of values currently stored in the
1454 * buffered-ranges array of the query's structure.
1456 * Returns: the range array size as a #guint.
1461 gst_query_get_n_buffering_ranges (GstQuery * query)
1463 GstStructure *structure;
1466 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1468 structure = GST_QUERY_STRUCTURE (query);
1469 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1470 sizeof (GstQueryBufferingRange), NULL);
1477 * gst_query_parse_nth_buffering_range:
1478 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1479 * @index: position in the buffered-ranges array to read
1480 * @start: (out) (allow-none): the start position to set, or NULL
1481 * @stop: (out) (allow-none): the stop position to set, or NULL
1483 * Parse an available query and get the start and stop values stored
1484 * at the @index of the buffered ranges array.
1486 * Returns: a #gboolean indicating if the parsing succeeded.
1491 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1492 gint64 * start, gint64 * stop)
1494 GstQueryBufferingRange *range;
1495 GstStructure *structure;
1498 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1500 structure = GST_QUERY_STRUCTURE (query);
1502 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1503 sizeof (GstQueryBufferingRange), NULL);
1504 g_return_val_if_fail (index < array->len, FALSE);
1506 range = &g_array_index (array, GstQueryBufferingRange, index);
1509 *start = range->start;
1511 *stop = range->stop;
1518 * gst_query_new_uri:
1520 * Constructs a new query URI query object. Use gst_query_unref()
1521 * when done with it. An URI query is used to query the current URI
1522 * that is used by the source or sink.
1524 * Free-function: gst_query_unref
1526 * Returns: (transfer full): a new #GstQuery
1531 gst_query_new_uri (void)
1534 GstStructure *structure;
1536 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1537 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1539 query = gst_query_new_custom (GST_QUERY_URI, structure);
1545 * gst_query_set_uri:
1546 * @query: a #GstQuery with query type GST_QUERY_URI
1547 * @uri: the URI to set
1549 * Answer a URI query by setting the requested URI.
1554 gst_query_set_uri (GstQuery * query, const gchar * uri)
1556 GstStructure *structure;
1558 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1559 g_return_if_fail (gst_query_is_writable (query));
1560 g_return_if_fail (gst_uri_is_valid (uri));
1562 structure = GST_QUERY_STRUCTURE (query);
1563 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1567 * gst_query_parse_uri:
1568 * @query: a #GstQuery
1569 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1572 * Parse an URI query, writing the URI into @uri as a newly
1573 * allocated string, if the respective parameters are non-NULL.
1574 * Free the string with g_free() after usage.
1579 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1581 GstStructure *structure;
1583 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1585 structure = GST_QUERY_STRUCTURE (query);
1587 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1592 * gst_query_new_allocation:
1593 * @caps: the negotiated caps
1594 * @need_pool: return a pool
1596 * Constructs a new query object for querying the allocation properties.
1598 * Free-function: gst_query_unref
1600 * Returns: (transfer full): a new #GstQuery
1603 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1606 GstStructure *structure;
1608 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1609 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1610 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1611 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1612 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1613 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1614 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1615 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1616 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1618 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1624 * gst_query_parse_allocation:
1625 * @query: a #GstQuery
1626 * @caps: (out callee-allocates) (allow-none): The #GstCaps
1627 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1629 * Parse an allocation query, writing the requested caps in @caps and
1630 * whether a pool is needed in @need_pool, if the respective parameters
1634 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1635 gboolean * need_pool)
1637 GstStructure *structure;
1639 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1641 structure = GST_QUERY_STRUCTURE (query);
1642 gst_structure_id_get (structure,
1643 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1644 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1648 * gst_query_set_allocation_params:
1649 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1651 * @min_buffers: the min buffers
1652 * @max_buffers: the max buffers
1653 * @prefix: the prefix
1654 * @alignment: the alignment
1655 * @pool: the #GstBufferPool
1657 * Set the allocation parameters in @query.
1660 gst_query_set_allocation_params (GstQuery * query, guint size,
1661 guint min_buffers, guint max_buffers, guint prefix,
1662 guint alignment, GstBufferPool * pool)
1664 GstStructure *structure;
1666 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1667 g_return_if_fail (gst_query_is_writable (query));
1668 g_return_if_fail (((alignment + 1) & alignment) == 0);
1669 g_return_if_fail (size != 0 || pool == NULL);
1671 structure = GST_QUERY_STRUCTURE (query);
1672 gst_structure_id_set (structure,
1673 GST_QUARK (SIZE), G_TYPE_UINT, size,
1674 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1675 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1676 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1677 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1678 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1682 * gst_query_parse_allocation_params:
1683 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1684 * @size: (out) (allow-none): the size
1685 * @min_buffers: (out) (allow-none): the min buffers
1686 * @max_buffers: (out) (allow-none): the max buffers
1687 * @prefix: (out) (allow-none): the prefix
1688 * @alignment: (out) (allow-none): the alignment
1689 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1691 * Get the allocation parameters in @query.
1694 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1695 guint * min_buffers, guint * max_buffers, guint * prefix,
1696 guint * alignment, GstBufferPool ** pool)
1698 GstStructure *structure;
1700 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1702 structure = GST_QUERY_STRUCTURE (query);
1703 gst_structure_id_get (structure,
1704 GST_QUARK (SIZE), G_TYPE_UINT, size,
1705 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1706 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1707 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1708 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1709 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1713 * gst_query_add_allocation_meta:
1714 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1715 * @api: the metadata API
1717 * Add @api as aone of the supported metadata API to @query.
1720 gst_query_add_allocation_meta (GstQuery * query, GType api)
1723 GstStructure *structure;
1725 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1726 g_return_if_fail (api != 0);
1727 g_return_if_fail (gst_query_is_writable (query));
1729 structure = GST_QUERY_STRUCTURE (query);
1730 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1732 g_array_append_val (array, api);
1736 * gst_query_get_n_allocation_metas:
1737 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1739 * Retrieve the number of values currently stored in the
1740 * meta API array of the query's structure.
1742 * Returns: the metadata API array size as a #guint.
1745 gst_query_get_n_allocation_metas (GstQuery * query)
1748 GstStructure *structure;
1750 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1752 structure = GST_QUERY_STRUCTURE (query);
1753 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1759 * gst_query_parse_nth_allocation_meta:
1760 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1761 * @index: position in the metadata API array to read
1763 * Parse an available query and get the metadata API
1764 * at @index of the metadata API array.
1766 * Returns: a #GType of the metadata API at @index.
1769 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1772 GstStructure *structure;
1774 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1776 structure = GST_QUERY_STRUCTURE (query);
1777 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1779 g_return_val_if_fail (index < array->len, 0);
1781 return g_array_index (array, GType, index);
1785 * gst_query_remove_nth_allocation_meta:
1786 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1787 * @index: position in the metadata API array to remove
1789 * Remove the metadata API at @index of the metadata API array.
1792 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1795 GstStructure *structure;
1797 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1798 g_return_if_fail (gst_query_is_writable (query));
1800 structure = GST_QUERY_STRUCTURE (query);
1801 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1802 g_return_if_fail (index < array->len);
1804 g_array_remove_index (array, index);
1808 * gst_query_has_allocation_meta:
1809 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1810 * @api: the metadata API
1812 * Check if @query has metadata @api set.
1814 * Returns: TRUE when @api is in the list of metadata.
1817 gst_query_has_allocation_meta (GstQuery * query, GType api)
1820 GstStructure *structure;
1823 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1824 g_return_val_if_fail (api != 0, FALSE);
1826 structure = GST_QUERY_STRUCTURE (query);
1827 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1830 for (i = 0; i < len; i++) {
1831 if (g_array_index (array, GType, i) == api)
1838 * gst_query_add_allocation_memory:
1839 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1840 * @allocator: the memory allocator
1842 * Add @allocator as a supported memory allocator.
1845 gst_query_add_allocation_memory (GstQuery * query, GstAllocator * allocator)
1848 GstStructure *structure;
1850 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1851 g_return_if_fail (gst_query_is_writable (query));
1852 g_return_if_fail (allocator != NULL);
1854 structure = GST_QUERY_STRUCTURE (query);
1856 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1857 (GDestroyNotify) gst_allocator_unref);
1859 g_array_append_val (array, allocator);
1863 * gst_query_get_n_allocation_memories:
1864 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1866 * Retrieve the number of values currently stored in the
1867 * allocator array of the query's structure.
1869 * If no memory allocator is specified, the downstream element can handle
1870 * the default memory allocator.
1872 * Returns: the allocator array size as a #guint.
1875 gst_query_get_n_allocation_memories (GstQuery * query)
1878 GstStructure *structure;
1880 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1882 structure = GST_QUERY_STRUCTURE (query);
1884 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1885 (GDestroyNotify) gst_allocator_unref);
1891 * gst_query_parse_nth_allocation_memory:
1892 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1893 * @index: position in the allocator array to read
1895 * Parse an available query and get the alloctor
1896 * at @index of the allocator array.
1898 * Returns: (transfer none): the allocator at @index. The allocator remains
1899 * valid for as long as @query is valid.
1902 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1905 GstStructure *structure;
1907 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1909 structure = GST_QUERY_STRUCTURE (query);
1911 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1912 (GDestroyNotify) gst_allocator_unref);
1913 g_return_val_if_fail (index < array->len, NULL);
1915 return g_array_index (array, GstAllocator *, index);
1919 * gst_query_new_scheduling:
1921 * Constructs a new query object for querying the scheduling properties.
1923 * Free-function: gst_query_unref
1925 * Returns: (transfer full): a new #GstQuery
1928 gst_query_new_scheduling (void)
1931 GstStructure *structure;
1933 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1934 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1935 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1936 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1937 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1938 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
1944 * gst_query_set_scheduling:
1945 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1946 * @flags: #GstSchedulingFlags
1947 * @minsize: the suggested minimum size of pull requests
1948 * @maxsize: the suggested maximum size of pull requests
1949 * @align: the suggested alignment of pull requests
1951 * Set the scheduling properties.
1954 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1955 gint minsize, gint maxsize, gint align)
1957 GstStructure *structure;
1959 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1960 g_return_if_fail (gst_query_is_writable (query));
1962 structure = GST_QUERY_STRUCTURE (query);
1963 gst_structure_id_set (structure,
1964 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1965 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1966 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1967 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1971 * gst_query_parse_scheduling:
1972 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1973 * @flags: (out) (allow-none): #GstSchedulingFlags
1974 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
1975 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
1976 * @align: (out) (allow-none): the suggested alignment of pull requests
1978 * Set the scheduling properties.
1981 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
1982 gint * minsize, gint * maxsize, gint * align)
1984 GstStructure *structure;
1986 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1988 structure = GST_QUERY_STRUCTURE (query);
1989 gst_structure_id_get (structure,
1990 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1991 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1992 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1993 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1997 * gst_query_add_scheduling_mode:
1998 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1999 * @mode: a #GstPadMode
2001 * Add @mode as aone of the supported scheduling modes to @query.
2004 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2006 GstStructure *structure;
2009 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2010 g_return_if_fail (gst_query_is_writable (query));
2012 structure = GST_QUERY_STRUCTURE (query);
2014 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2016 g_array_append_val (array, mode);
2020 * gst_query_get_n_scheduling_modes:
2021 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2023 * Retrieve the number of values currently stored in the
2024 * scheduling mode array of the query's structure.
2026 * Returns: the scheduling mode array size as a #guint.
2029 gst_query_get_n_scheduling_modes (GstQuery * query)
2032 GstStructure *structure;
2034 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2036 structure = GST_QUERY_STRUCTURE (query);
2038 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2044 * gst_query_parse_nth_scheduling_mode:
2045 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2046 * @index: position in the scheduling modes array to read
2048 * Parse an available query and get the scheduling mode
2049 * at @index of the scheduling modes array.
2051 * Returns: a #GstPadMode of the scheduling mode at @index.
2054 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2056 GstStructure *structure;
2059 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2062 structure = GST_QUERY_STRUCTURE (query);
2064 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2065 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2067 return g_array_index (array, GstPadMode, index);
2071 * gst_query_has_scheduling_mode:
2072 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2073 * @mode: the scheduling mode
2075 * Check if @query has scheduling mode set.
2077 * Returns: TRUE when @mode is in the list of scheduling modes.
2080 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2082 GstStructure *structure;
2086 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2088 structure = GST_QUERY_STRUCTURE (query);
2090 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2093 for (i = 0; i < len; i++) {
2094 if (mode == g_array_index (array, GstPadMode, i))
2101 * gst_query_new_accept_caps:
2104 * Constructs a new query object for querying if @caps are accepted.
2106 * Free-function: gst_query_unref
2108 * Returns: (transfer full): a new #GstQuery
2111 gst_query_new_accept_caps (GstCaps * caps)
2114 GstStructure *structure;
2116 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2117 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2118 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2119 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2125 * gst_query_parse_accept_caps:
2126 * @query: The query to parse
2127 * @caps: (out): A pointer to the caps
2129 * Get the caps from @query. The caps remains valid as long as @query remains
2133 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2135 GstStructure *structure;
2137 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2138 g_return_if_fail (caps != NULL);
2140 structure = GST_QUERY_STRUCTURE (query);
2141 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2146 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2148 GstStructure *structure;
2150 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2151 g_return_if_fail (gst_query_is_writable (query));
2153 structure = GST_QUERY_STRUCTURE (query);
2154 gst_structure_id_set (structure,
2155 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2159 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2161 GstStructure *structure;
2163 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2165 structure = GST_QUERY_STRUCTURE (query);
2166 gst_structure_id_get (structure,
2167 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2171 * gst_query_new_caps:
2174 * Constructs a new query object for querying the caps.
2176 * The CAPS query should return the* allowable caps for a pad in the context
2177 * of the element's state, its link to other elements, and the devices or files
2178 * it has opened. These caps must be a subset of the pad template caps. In the
2179 * NULL state with no links, the CAPS query should ideally return the same caps
2180 * as the pad template. In rare circumstances, an object property can affect
2181 * the caps returned by the CAPS query, but this is discouraged.
2183 * For most filters, the caps returned by CAPS query is directly affected by the
2184 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2185 * the srcpad's getcaps function is directly related to the stream data. Again,
2186 * the CAPS query should return the most specific caps it reasonably can, since this
2187 * helps with autoplugging.
2189 * Free-function: gst_query_unref
2191 * Returns: (transfer full): a new #GstQuery
2194 gst_query_new_caps (GstCaps * filter)
2197 GstStructure *structure;
2199 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2200 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2201 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2202 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2208 * gst_query_parse_caps:
2209 * @query: The query to parse
2210 * @filter: (out): A pointer to the caps filter
2212 * Get the filter from the caps @query. The caps remains valid as long as
2213 * @query remains valid.
2216 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2218 GstStructure *structure;
2220 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2221 g_return_if_fail (filter != NULL);
2223 structure = GST_QUERY_STRUCTURE (query);
2224 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2225 GST_QUARK (FILTER)));
2229 * gst_query_set_caps_result:
2230 * @query: The query to use
2231 * @caps: (in): A pointer to the caps
2233 * Set the @caps result in @query.
2236 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2238 GstStructure *structure;
2240 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2241 g_return_if_fail (gst_query_is_writable (query));
2243 structure = GST_QUERY_STRUCTURE (query);
2244 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2248 * gst_query_parse_caps_result:
2249 * @query: The query to parse
2250 * @caps: (out): A pointer to the caps
2252 * Get the caps result from @query. The caps remains valid as long as
2253 * @query remains valid.
2256 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2258 GstStructure *structure;
2260 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2261 g_return_if_fail (caps != NULL);
2263 structure = GST_QUERY_STRUCTURE (query);
2264 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2269 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2270 GstCapsIntersectMode mode)
2272 GstCaps *res, *caps = NULL;
2274 gst_query_parse_caps_result (query, &caps);
2275 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2276 gst_query_set_caps_result (query, res);
2277 gst_caps_unref (res);