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)
64 #include "gst_private.h"
68 #include "gstenumtypes.h"
71 #include "gstbufferpool.h"
73 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
74 #define GST_CAT_DEFAULT gst_query_debug
76 static GType _gst_query_type = 0;
82 GstStructure *structure;
85 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
87 /* GstQueryBufferingRange: internal struct for GArray */
92 } GstQueryBufferingRange;
95 static GList *_gst_queries = NULL;
96 static GHashTable *_nick_to_query = NULL;
97 static GHashTable *_query_type_to_nick = NULL;
98 static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */
100 static GstQueryTypeDefinition standard_definitions[] = {
101 {GST_QUERY_POSITION, "position", "Current position", 0},
102 {GST_QUERY_DURATION, "duration", "Total duration", 0},
103 {GST_QUERY_LATENCY, "latency", "Latency", 0},
104 {GST_QUERY_JITTER, "jitter", "Jitter", 0},
105 {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
106 {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
107 {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
108 {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
109 {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
110 {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
111 {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
112 {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
113 {GST_QUERY_ALLOCATION, "allocation", "Allocation properties", 0},
114 {GST_QUERY_SCHEDULING, "scheduling", "Scheduling properties", 0},
115 {GST_QUERY_ACCEPT_CAPS, "accept-caps", "Accept caps", 0},
116 {GST_QUERY_CAPS, "caps", "Caps", 0},
117 {GST_QUERY_NONE, NULL, NULL, 0}
120 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
123 _priv_gst_query_initialize (void)
125 GstQueryTypeDefinition *standards = standard_definitions;
127 GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
129 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
131 g_mutex_lock (&mutex);
132 if (_nick_to_query == NULL) {
133 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
134 _query_type_to_nick = g_hash_table_new (NULL, NULL);
137 while (standards->nick) {
138 standards->quark = g_quark_from_static_string (standards->nick);
139 g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
140 g_hash_table_insert (_query_type_to_nick,
141 GINT_TO_POINTER (standards->value), standards);
143 _gst_queries = g_list_append (_gst_queries, standards);
147 g_mutex_unlock (&mutex);
149 _gst_query_type = gst_query_get_type ();
153 * gst_query_type_get_name:
154 * @query: the query type
156 * Get a printable name for the given query type. Do not modify or free.
158 * Returns: a reference to the static name of the query.
161 gst_query_type_get_name (GstQueryType query)
163 const GstQueryTypeDefinition *def;
165 def = gst_query_type_get_details (query);
166 g_return_val_if_fail (def != NULL, NULL);
172 * gst_query_type_to_quark:
173 * @query: the query type
175 * Get the unique quark for the given query type.
177 * Returns: the quark associated with the query type
180 gst_query_type_to_quark (GstQueryType query)
182 const GstQueryTypeDefinition *def;
184 def = gst_query_type_get_details (query);
185 g_return_val_if_fail (def != NULL, 0);
191 * gst_query_type_register:
192 * @nick: The nick of the new query
193 * @description: The description of the new query
195 * Create a new GstQueryType based on the nick or return an
196 * already registered query with that nick
198 * Returns: A new GstQueryType or an already registered query
199 * with the same nick.
202 gst_query_type_register (const gchar * nick, const gchar * description)
204 GstQueryTypeDefinition *query;
207 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
208 g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
210 lookup = gst_query_type_get_by_nick (nick);
211 if (lookup != GST_QUERY_NONE)
214 query = g_slice_new (GstQueryTypeDefinition);
215 query->value = (GstQueryType) _n_values;
216 query->nick = g_strdup (nick);
217 query->description = g_strdup (description);
218 query->quark = g_quark_from_static_string (query->nick);
220 g_mutex_lock (&mutex);
221 g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
222 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
224 _gst_queries = g_list_append (_gst_queries, query);
226 g_mutex_unlock (&mutex);
232 * gst_query_type_get_by_nick:
233 * @nick: The nick of the query
235 * Get the query type registered with @nick.
237 * Returns: The query registered with @nick or #GST_QUERY_NONE
238 * if the query was not registered.
241 gst_query_type_get_by_nick (const gchar * nick)
243 GstQueryTypeDefinition *query;
245 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
247 g_mutex_lock (&mutex);
248 query = g_hash_table_lookup (_nick_to_query, nick);
249 g_mutex_unlock (&mutex);
254 return GST_QUERY_NONE;
258 * gst_query_types_contains:
259 * @types: The query array to search
260 * @type: the #GstQueryType to find
262 * See if the given #GstQueryType is inside the @types query types array.
264 * Returns: TRUE if the type is found inside the array
267 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
283 * gst_query_type_get_details:
284 * @type: a #GstQueryType
286 * Get details about the given #GstQueryType.
288 * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
290 const GstQueryTypeDefinition *
291 gst_query_type_get_details (GstQueryType type)
293 const GstQueryTypeDefinition *result;
295 g_mutex_lock (&mutex);
296 result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
297 g_mutex_unlock (&mutex);
303 * gst_query_type_iterate_definitions:
305 * Get a #GstIterator of all the registered query types. The definitions
306 * iterated over are read only.
308 * Free-function: gst_iterator_free
310 * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
313 gst_query_type_iterate_definitions (void)
317 g_mutex_lock (&mutex);
318 /* FIXME: register a boxed type for GstQueryTypeDefinition */
319 result = gst_iterator_new_list (G_TYPE_POINTER,
320 &mutex, &_n_values, &_gst_queries, NULL, NULL);
321 g_mutex_unlock (&mutex);
327 _gst_query_free (GstQuery * query)
331 g_return_if_fail (query != NULL);
333 s = GST_QUERY_STRUCTURE (query);
335 gst_structure_set_parent_refcount (s, NULL);
336 gst_structure_free (s);
339 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
343 _gst_query_copy (GstQuery * query)
347 copy = gst_query_new_custom (query->type, GST_QUERY_STRUCTURE (query));
353 gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
355 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
357 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
358 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
360 GST_EVENT_TYPE (query) = type;
364 * gst_query_new_position:
365 * @format: the default #GstFormat for the new query
367 * Constructs a new query stream position query object. Use gst_query_unref()
368 * when done with it. A position query is used to query the current position
369 * of playback in the streams, in some format.
371 * Free-function: gst_query_unref
373 * Returns: (transfer full): a new #GstQuery
376 gst_query_new_position (GstFormat format)
379 GstStructure *structure;
381 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
382 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
383 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
385 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
391 * gst_query_set_position:
392 * @query: a #GstQuery with query type GST_QUERY_POSITION
393 * @format: the requested #GstFormat
394 * @cur: the position to set
396 * Answer a position query by setting the requested value in the given format.
399 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
403 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
405 s = GST_QUERY_STRUCTURE (query);
406 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
407 GST_QUARK (FORMAT))));
409 gst_structure_id_set (s,
410 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
411 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
415 * gst_query_parse_position:
416 * @query: a #GstQuery
417 * @format: (out) (allow-none): the storage for the #GstFormat of the
418 * position values (may be NULL)
419 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
421 * Parse a position query, writing the format into @format, and the position
422 * into @cur, if the respective parameters are non-NULL.
425 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
427 GstStructure *structure;
429 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
431 structure = GST_QUERY_STRUCTURE (query);
434 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
435 GST_QUARK (FORMAT)));
437 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
438 GST_QUARK (CURRENT)));
443 * gst_query_new_duration:
444 * @format: the #GstFormat for this duration query
446 * Constructs a new stream duration query object to query in the given format.
447 * Use gst_query_unref() when done with it. A duration query will give the
448 * total length of the stream.
450 * Free-function: gst_query_unref
452 * Returns: (transfer full): a new #GstQuery
455 gst_query_new_duration (GstFormat format)
458 GstStructure *structure;
460 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
461 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
462 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
464 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
470 * gst_query_set_duration:
471 * @query: a #GstQuery
472 * @format: the #GstFormat for the duration
473 * @duration: the duration of the stream
475 * Answer a duration query by setting the requested value in the given format.
478 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
482 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
484 s = GST_QUERY_STRUCTURE (query);
485 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
486 GST_QUARK (FORMAT))));
487 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
488 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
492 * gst_query_parse_duration:
493 * @query: a #GstQuery
494 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
496 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
498 * Parse a duration query answer. Write the format of the duration into @format,
499 * and the value into @duration, if the respective variables are non-NULL.
502 gst_query_parse_duration (GstQuery * query, GstFormat * format,
505 GstStructure *structure;
507 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
509 structure = GST_QUERY_STRUCTURE (query);
512 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
513 GST_QUARK (FORMAT)));
515 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
516 GST_QUARK (DURATION)));
520 * gst_query_new_latency:
522 * Constructs a new latency query object.
523 * Use gst_query_unref() when done with it. A latency query is usually performed
524 * by sinks to compensate for additional latency introduced by elements in the
527 * Free-function: gst_query_unref
529 * Returns: (transfer full): a #GstQuery
534 gst_query_new_latency (void)
537 GstStructure *structure;
539 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
540 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
541 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
542 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
544 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
550 * gst_query_set_latency:
551 * @query: a #GstQuery
552 * @live: if there is a live element upstream
553 * @min_latency: the minimal latency of the upstream elements
554 * @max_latency: the maximal latency of the upstream elements
556 * Answer a latency query by setting the requested values in the given format.
561 gst_query_set_latency (GstQuery * query, gboolean live,
562 GstClockTime min_latency, GstClockTime max_latency)
564 GstStructure *structure;
566 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
568 structure = GST_QUERY_STRUCTURE (query);
569 gst_structure_id_set (structure,
570 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
571 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
572 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
576 * gst_query_parse_latency:
577 * @query: a #GstQuery
578 * @live: (out) (allow-none): storage for live or NULL
579 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
580 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
582 * Parse a latency query answer.
587 gst_query_parse_latency (GstQuery * query, gboolean * live,
588 GstClockTime * min_latency, GstClockTime * max_latency)
590 GstStructure *structure;
592 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
594 structure = GST_QUERY_STRUCTURE (query);
597 g_value_get_boolean (gst_structure_id_get_value (structure,
600 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
601 GST_QUARK (MIN_LATENCY)));
603 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
604 GST_QUARK (MAX_LATENCY)));
608 * gst_query_new_convert:
609 * @src_format: the source #GstFormat for the new query
610 * @value: the value to convert
611 * @dest_format: the target #GstFormat
613 * Constructs a new convert query object. Use gst_query_unref()
614 * when done with it. A convert query is used to ask for a conversion between
615 * one format and another.
617 * Free-function: gst_query_unref
619 * Returns: (transfer full): a #GstQuery
622 gst_query_new_convert (GstFormat src_format, gint64 value,
623 GstFormat dest_format)
626 GstStructure *structure;
628 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
629 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
630 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
631 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
632 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
634 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
640 * gst_query_set_convert:
641 * @query: a #GstQuery
642 * @src_format: the source #GstFormat
643 * @src_value: the source value
644 * @dest_format: the destination #GstFormat
645 * @dest_value: the destination value
647 * Answer a convert query by setting the requested values.
650 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
651 GstFormat dest_format, gint64 dest_value)
653 GstStructure *structure;
655 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
657 structure = GST_QUERY_STRUCTURE (query);
658 gst_structure_id_set (structure,
659 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
660 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
661 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
662 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
666 * gst_query_parse_convert:
667 * @query: a #GstQuery
668 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
669 * source value, or NULL
670 * @src_value: (out) (allow-none): the storage for the source value, or NULL
671 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
672 * destination value, or NULL
673 * @dest_value: (out) (allow-none): the storage for the destination value,
676 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
677 * and @dest_value may be NULL, in which case that value is omitted.
680 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
681 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
683 GstStructure *structure;
685 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
687 structure = GST_QUERY_STRUCTURE (query);
690 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
691 GST_QUARK (SRC_FORMAT)));
693 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
694 GST_QUARK (SRC_VALUE)));
697 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
698 GST_QUARK (DEST_FORMAT)));
700 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
701 GST_QUARK (DEST_VALUE)));
705 * gst_query_new_segment:
706 * @format: the #GstFormat for the new query
708 * Constructs a new segment query object. Use gst_query_unref()
709 * when done with it. A segment query is used to discover information about the
710 * currently configured segment for playback.
712 * Free-function: gst_query_unref
714 * Returns: (transfer full): a new #GstQuery
717 gst_query_new_segment (GstFormat format)
720 GstStructure *structure;
722 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
723 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
724 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
725 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
726 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
728 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
734 * gst_query_set_segment:
735 * @query: a #GstQuery
736 * @rate: the rate of the segment
737 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
738 * @start_value: the start value
739 * @stop_value: the stop value
741 * Answer a segment query by setting the requested values. The normal
742 * playback segment of a pipeline is 0 to duration at the default rate of
743 * 1.0. If a seek was performed on the pipeline to play a different
744 * segment, this query will return the range specified in the last seek.
746 * @start_value and @stop_value will respectively contain the configured
747 * playback range start and stop values expressed in @format.
748 * The values are always between 0 and the duration of the media and
749 * @start_value <= @stop_value. @rate will contain the playback rate. For
750 * negative rates, playback will actually happen from @stop_value to
754 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
755 gint64 start_value, gint64 stop_value)
757 GstStructure *structure;
759 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
761 structure = GST_QUERY_STRUCTURE (query);
762 gst_structure_id_set (structure,
763 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
764 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
765 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
766 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
770 * gst_query_parse_segment:
771 * @query: a #GstQuery
772 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
773 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
775 * @start_value: (out) (allow-none): the storage for the start value, or NULL
776 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
778 * Parse a segment query answer. Any of @rate, @format, @start_value, and
779 * @stop_value may be NULL, which will cause this value to be omitted.
781 * See gst_query_set_segment() for an explanation of the function arguments.
784 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
785 gint64 * start_value, gint64 * stop_value)
787 GstStructure *structure;
789 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
791 structure = GST_QUERY_STRUCTURE (query);
793 *rate = g_value_get_double (gst_structure_id_get_value (structure,
797 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
798 GST_QUARK (FORMAT)));
800 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
801 GST_QUARK (START_VALUE)));
803 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
804 GST_QUARK (STOP_VALUE)));
808 * gst_query_new_custom:
809 * @type: the query type
810 * @structure: a structure for the query
812 * Constructs a new custom query object. Use gst_query_unref()
815 * Free-function: gst_query_unref
817 * Returns: (transfer full): a new #GstQuery
820 gst_query_new_custom (GstQueryType type, GstStructure * structure)
824 query = g_slice_new0 (GstQueryImpl);
826 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
829 /* structure must not have a parent */
830 if (!gst_structure_set_parent_refcount (structure,
831 &query->query.mini_object.refcount))
834 gst_query_init (query, sizeof (GstQueryImpl), type);
836 GST_QUERY_STRUCTURE (query) = structure;
838 return GST_QUERY_CAST (query);
843 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
844 g_warning ("structure is already owned by another object");
850 * gst_query_get_structure:
851 * @query: a #GstQuery
853 * Get the structure of a query.
855 * Returns: (transfer none): the #GstStructure of the query. The structure is
856 * still owned by the query and will therefore be freed when the query
860 gst_query_get_structure (GstQuery * query)
862 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
864 return GST_QUERY_STRUCTURE (query);
868 * gst_query_writable_structure:
869 * @query: a #GstQuery
871 * Get the structure of a query.
873 * Returns: (transfer none): the #GstStructure of the query. The structure is
874 * still owned by the query and will therefore be freed when the query
878 gst_query_writable_structure (GstQuery * query)
880 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
881 g_return_val_if_fail (gst_query_is_writable (query), NULL);
883 return GST_QUERY_STRUCTURE (query);
887 * gst_query_new_seeking:
888 * @format: the default #GstFormat for the new query
890 * Constructs a new query object for querying seeking properties of
893 * Free-function: gst_query_unref
895 * Returns: (transfer full): a new #GstQuery
898 gst_query_new_seeking (GstFormat format)
901 GstStructure *structure;
903 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
904 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
905 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
906 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
907 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
909 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
915 * gst_query_set_seeking:
916 * @query: a #GstQuery
917 * @format: the format to set for the @segment_start and @segment_end values
918 * @seekable: the seekable flag to set
919 * @segment_start: the segment_start to set
920 * @segment_end: the segment_end to set
922 * Set the seeking query result fields in @query.
925 gst_query_set_seeking (GstQuery * query, GstFormat format,
926 gboolean seekable, gint64 segment_start, gint64 segment_end)
928 GstStructure *structure;
930 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
931 g_return_if_fail (gst_query_is_writable (query));
933 structure = GST_QUERY_STRUCTURE (query);
934 gst_structure_id_set (structure,
935 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
936 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
937 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
938 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
942 * gst_query_parse_seeking:
943 * @query: a GST_QUERY_SEEKING type query #GstQuery
944 * @format: (out) (allow-none): the format to set for the @segment_start
945 * and @segment_end values, or NULL
946 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
947 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
948 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
950 * Parse a seeking query, writing the format into @format, and
951 * other results into the passed parameters, if the respective parameters
955 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
956 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
958 GstStructure *structure;
960 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
962 structure = GST_QUERY_STRUCTURE (query);
965 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
966 GST_QUARK (FORMAT)));
968 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
969 GST_QUARK (SEEKABLE)));
971 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
972 GST_QUARK (SEGMENT_START)));
974 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
975 GST_QUARK (SEGMENT_END)));
979 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
980 GDestroyNotify clear_func)
985 value = gst_structure_id_get_value (s, quark);
987 array = (GArray *) g_value_get_boxed (value);
989 GValue new_array_val = { 0, };
991 array = g_array_new (FALSE, TRUE, element_size);
993 g_array_set_clear_func (array, clear_func);
995 g_value_init (&new_array_val, G_TYPE_ARRAY);
996 g_value_take_boxed (&new_array_val, array);
998 gst_structure_id_take_value (s, quark, &new_array_val);
1004 * gst_query_new_formats:
1006 * Constructs a new query object for querying formats of
1009 * Free-function: gst_query_unref
1011 * Returns: (transfer full): a new #GstQuery
1016 gst_query_new_formats (void)
1019 GstStructure *structure;
1021 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
1022 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
1028 gst_query_list_add_format (GValue * list, GstFormat format)
1030 GValue item = { 0, };
1032 g_value_init (&item, GST_TYPE_FORMAT);
1033 g_value_set_enum (&item, format);
1034 gst_value_list_append_value (list, &item);
1035 g_value_unset (&item);
1039 * gst_query_set_formats:
1040 * @query: a #GstQuery
1041 * @n_formats: the number of formats to set.
1042 * @...: A number of @GstFormats equal to @n_formats.
1044 * Set the formats query result fields in @query. The number of formats passed
1045 * must be equal to @n_formats.
1048 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1051 GValue list = { 0, };
1053 GstStructure *structure;
1055 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1056 g_return_if_fail (gst_query_is_writable (query));
1058 g_value_init (&list, GST_TYPE_LIST);
1060 va_start (ap, n_formats);
1061 for (i = 0; i < n_formats; i++) {
1062 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1066 structure = GST_QUERY_STRUCTURE (query);
1067 gst_structure_set_value (structure, "formats", &list);
1069 g_value_unset (&list);
1074 * gst_query_set_formatsv:
1075 * @query: a #GstQuery
1076 * @n_formats: the number of formats to set.
1077 * @formats: (in) (array length=n_formats): an array containing @n_formats
1078 * @GstFormat values.
1080 * Set the formats query result fields in @query. The number of formats passed
1081 * in the @formats array must be equal to @n_formats.
1086 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1087 const GstFormat * formats)
1089 GValue list = { 0, };
1091 GstStructure *structure;
1093 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1094 g_return_if_fail (gst_query_is_writable (query));
1096 g_value_init (&list, GST_TYPE_LIST);
1097 for (i = 0; i < n_formats; i++) {
1098 gst_query_list_add_format (&list, formats[i]);
1100 structure = GST_QUERY_STRUCTURE (query);
1101 gst_structure_set_value (structure, "formats", &list);
1103 g_value_unset (&list);
1107 * gst_query_parse_n_formats:
1108 * @query: a #GstQuery
1109 * @n_formats: (out) (allow-none): the number of formats in this query.
1111 * Parse the number of formats in the formats @query.
1116 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1118 GstStructure *structure;
1120 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1125 structure = GST_QUERY_STRUCTURE (query);
1126 list = gst_structure_get_value (structure, "formats");
1130 *n_formats = gst_value_list_get_size (list);
1135 * gst_query_parse_nth_format:
1136 * @query: a #GstQuery
1137 * @nth: (out): the nth format to retrieve.
1138 * @format: (out) (allow-none): a pointer to store the nth format
1140 * Parse the format query and retrieve the @nth format from it into
1141 * @format. If the list contains less elements than @nth, @format will be
1142 * set to GST_FORMAT_UNDEFINED.
1145 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1147 GstStructure *structure;
1149 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1154 structure = GST_QUERY_STRUCTURE (query);
1155 list = gst_structure_get_value (structure, "formats");
1157 *format = GST_FORMAT_UNDEFINED;
1159 if (nth < gst_value_list_get_size (list)) {
1161 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1163 *format = GST_FORMAT_UNDEFINED;
1169 * gst_query_new_buffering:
1170 * @format: the default #GstFormat for the new query
1172 * Constructs a new query object for querying the buffering status of
1175 * Free-function: gst_query_unref
1177 * Returns: (transfer full): a new #GstQuery
1182 gst_query_new_buffering (GstFormat format)
1185 GstStructure *structure;
1187 /* by default, we configure the answer as no buffering with a 100% buffering
1189 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1190 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1191 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1192 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1193 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1194 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1195 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1196 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1197 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1198 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1199 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1201 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1207 * gst_query_set_buffering_percent:
1208 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1209 * @busy: if buffering is busy
1210 * @percent: a buffering percent
1212 * Set the percentage of buffered data. This is a value between 0 and 100.
1213 * The @busy indicator is %TRUE when the buffering is in progress.
1218 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1220 GstStructure *structure;
1222 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1223 g_return_if_fail (gst_query_is_writable (query));
1224 g_return_if_fail (percent >= 0 && percent <= 100);
1226 structure = GST_QUERY_STRUCTURE (query);
1227 gst_structure_id_set (structure,
1228 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1229 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1233 * gst_query_parse_buffering_percent:
1234 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1235 * @busy: (out) (allow-none): if buffering is busy, or NULL
1236 * @percent: (out) (allow-none): a buffering percent, or NULL
1238 * Get the percentage of buffered data. This is a value between 0 and 100.
1239 * The @busy indicator is %TRUE when the buffering is in progress.
1244 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1247 GstStructure *structure;
1249 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1251 structure = GST_QUERY_STRUCTURE (query);
1253 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1256 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1257 GST_QUARK (BUFFER_PERCENT)));
1261 * gst_query_set_buffering_stats:
1262 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1263 * @mode: a buffering mode
1264 * @avg_in: the average input rate
1265 * @avg_out: the average output rate
1266 * @buffering_left: amount of buffering time left
1268 * Configures the buffering stats values in @query.
1273 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1274 gint avg_in, gint avg_out, gint64 buffering_left)
1276 GstStructure *structure;
1278 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1279 g_return_if_fail (gst_query_is_writable (query));
1281 structure = GST_QUERY_STRUCTURE (query);
1282 gst_structure_id_set (structure,
1283 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1284 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1285 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1286 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1290 * gst_query_parse_buffering_stats:
1291 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1292 * @mode: (out) (allow-none): a buffering mode, or NULL
1293 * @avg_in: (out) (allow-none): the average input rate, or NULL
1294 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1295 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1297 * Extracts the buffering stats values from @query.
1302 gst_query_parse_buffering_stats (GstQuery * query,
1303 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1304 gint64 * buffering_left)
1306 GstStructure *structure;
1308 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1310 structure = GST_QUERY_STRUCTURE (query);
1312 *mode = (GstBufferingMode)
1313 g_value_get_enum (gst_structure_id_get_value (structure,
1314 GST_QUARK (BUFFERING_MODE)));
1316 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1317 GST_QUARK (AVG_IN_RATE)));
1319 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1320 GST_QUARK (AVG_OUT_RATE)));
1323 g_value_get_int64 (gst_structure_id_get_value (structure,
1324 GST_QUARK (BUFFERING_LEFT)));
1328 * gst_query_set_buffering_range:
1329 * @query: a #GstQuery
1330 * @format: the format to set for the @start and @stop values
1331 * @start: the start to set
1332 * @stop: the stop to set
1333 * @estimated_total: estimated total amount of download time
1335 * Set the available query result fields in @query.
1340 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1341 gint64 start, gint64 stop, gint64 estimated_total)
1343 GstStructure *structure;
1345 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1346 g_return_if_fail (gst_query_is_writable (query));
1348 structure = GST_QUERY_STRUCTURE (query);
1349 gst_structure_id_set (structure,
1350 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1351 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1352 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1353 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1357 * gst_query_parse_buffering_range:
1358 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1359 * @format: (out) (allow-none): the format to set for the @segment_start
1360 * and @segment_end values, or NULL
1361 * @start: (out) (allow-none): the start to set, or NULL
1362 * @stop: (out) (allow-none): the stop to set, or NULL
1363 * @estimated_total: (out) (allow-none): estimated total amount of download
1366 * Parse an available query, writing the format into @format, and
1367 * other results into the passed parameters, if the respective parameters
1373 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1374 gint64 * start, gint64 * stop, gint64 * estimated_total)
1376 GstStructure *structure;
1378 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1380 structure = GST_QUERY_STRUCTURE (query);
1383 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1384 GST_QUARK (FORMAT)));
1386 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1387 GST_QUARK (START_VALUE)));
1389 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1390 GST_QUARK (STOP_VALUE)));
1391 if (estimated_total)
1393 g_value_get_int64 (gst_structure_id_get_value (structure,
1394 GST_QUARK (ESTIMATED_TOTAL)));
1398 * gst_query_add_buffering_range:
1399 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1400 * @start: start position of the range
1401 * @stop: stop position of the range
1403 * Set the buffering-ranges array field in @query. The current last
1404 * start position of the array should be inferior to @start.
1406 * Returns: a #gboolean indicating if the range was added or not.
1411 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1413 GstQueryBufferingRange range;
1414 GstStructure *structure;
1417 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1418 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1420 if (G_UNLIKELY (start >= stop))
1423 structure = GST_QUERY_STRUCTURE (query);
1424 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1425 sizeof (GstQueryBufferingRange), NULL);
1427 if (array->len > 1) {
1428 GstQueryBufferingRange *last;
1430 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1432 if (G_UNLIKELY (start <= last->start))
1436 range.start = start;
1438 g_array_append_val (array, range);
1444 * gst_query_get_n_buffering_ranges:
1445 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1447 * Retrieve the number of values currently stored in the
1448 * buffered-ranges array of the query's structure.
1450 * Returns: the range array size as a #guint.
1455 gst_query_get_n_buffering_ranges (GstQuery * query)
1457 GstStructure *structure;
1460 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1462 structure = GST_QUERY_STRUCTURE (query);
1463 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1464 sizeof (GstQueryBufferingRange), NULL);
1471 * gst_query_parse_nth_buffering_range:
1472 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1473 * @index: position in the buffered-ranges array to read
1474 * @start: (out) (allow-none): the start position to set, or NULL
1475 * @stop: (out) (allow-none): the stop position to set, or NULL
1477 * Parse an available query and get the start and stop values stored
1478 * at the @index of the buffered ranges array.
1480 * Returns: a #gboolean indicating if the parsing succeeded.
1485 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1486 gint64 * start, gint64 * stop)
1488 GstQueryBufferingRange *range;
1489 GstStructure *structure;
1492 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1494 structure = GST_QUERY_STRUCTURE (query);
1496 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1497 sizeof (GstQueryBufferingRange), NULL);
1499 if (index >= array->len)
1502 range = &g_array_index (array, GstQueryBufferingRange, index);
1505 *start = range->start;
1507 *stop = range->stop;
1514 * gst_query_new_uri:
1516 * Constructs a new query URI query object. Use gst_query_unref()
1517 * when done with it. An URI query is used to query the current URI
1518 * that is used by the source or sink.
1520 * Free-function: gst_query_unref
1522 * Returns: (transfer full): a new #GstQuery
1527 gst_query_new_uri (void)
1530 GstStructure *structure;
1532 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1533 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1535 query = gst_query_new_custom (GST_QUERY_URI, structure);
1541 * gst_query_set_uri:
1542 * @query: a #GstQuery with query type GST_QUERY_URI
1543 * @uri: the URI to set
1545 * Answer a URI query by setting the requested URI.
1550 gst_query_set_uri (GstQuery * query, const gchar * uri)
1552 GstStructure *structure;
1554 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1555 g_return_if_fail (gst_query_is_writable (query));
1556 g_return_if_fail (gst_uri_is_valid (uri));
1558 structure = GST_QUERY_STRUCTURE (query);
1559 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1563 * gst_query_parse_uri:
1564 * @query: a #GstQuery
1565 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1568 * Parse an URI query, writing the URI into @uri as a newly
1569 * allocated string, if the respective parameters are non-NULL.
1570 * Free the string with g_free() after usage.
1575 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1577 GstStructure *structure;
1579 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1581 structure = GST_QUERY_STRUCTURE (query);
1583 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1588 * gst_query_new_allocation:
1589 * @caps: the negotiated caps
1590 * @need_pool: return a pool
1592 * Constructs a new query object for querying the allocation properties.
1594 * Free-function: gst_query_unref
1596 * Returns: (transfer full): a new #GstQuery
1599 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1602 GstStructure *structure;
1604 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1605 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1606 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1607 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1608 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1609 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1610 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1611 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1612 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1614 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1620 * gst_query_parse_allocation:
1621 * @query: a #GstQuery
1622 * @caps: (out callee-allocates) (allow-none): The #GstCaps
1623 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1625 * Parse an allocation query, writing the requested caps in @caps and
1626 * whether a pool is needed in @need_pool, if the respective parameters
1630 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1631 gboolean * need_pool)
1633 GstStructure *structure;
1635 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1637 structure = GST_QUERY_STRUCTURE (query);
1638 gst_structure_id_get (structure,
1639 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1640 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1644 * gst_query_set_allocation_params:
1645 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1647 * @min_buffers: the min buffers
1648 * @max_buffers: the max buffers
1649 * @prefix: the prefix
1650 * @alignment: the alignment
1651 * @pool: the #GstBufferPool
1653 * Set the allocation parameters in @query.
1656 gst_query_set_allocation_params (GstQuery * query, guint size,
1657 guint min_buffers, guint max_buffers, guint prefix,
1658 guint alignment, GstBufferPool * pool)
1660 GstStructure *structure;
1662 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1663 g_return_if_fail (gst_query_is_writable (query));
1664 g_return_if_fail (((alignment + 1) & alignment) == 0);
1665 g_return_if_fail (size != 0 || pool == NULL);
1667 structure = GST_QUERY_STRUCTURE (query);
1668 gst_structure_id_set (structure,
1669 GST_QUARK (SIZE), G_TYPE_UINT, size,
1670 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1671 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1672 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1673 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1674 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1678 * gst_query_parse_allocation_params:
1679 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1680 * @size: (out) (allow-none): the size
1681 * @min_buffers: (out) (allow-none): the min buffers
1682 * @max_buffers: (out) (allow-none): the max buffers
1683 * @prefix: (out) (allow-none): the prefix
1684 * @alignment: (out) (allow-none): the alignment
1685 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1687 * Get the allocation parameters in @query.
1690 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1691 guint * min_buffers, guint * max_buffers, guint * prefix,
1692 guint * alignment, GstBufferPool ** pool)
1694 GstStructure *structure;
1696 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1698 structure = GST_QUERY_STRUCTURE (query);
1699 gst_structure_id_get (structure,
1700 GST_QUARK (SIZE), G_TYPE_UINT, size,
1701 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1702 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1703 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1704 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1705 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1709 * gst_query_add_allocation_meta:
1710 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1711 * @api: the metadata API
1713 * Add @api as aone of the supported metadata API to @query.
1716 gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
1719 GstStructure *structure;
1721 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1722 g_return_if_fail (api != NULL);
1723 g_return_if_fail (gst_query_is_writable (query));
1725 structure = GST_QUERY_STRUCTURE (query);
1727 ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
1729 api = g_intern_string (api);
1730 g_array_append_val (array, api);
1734 * gst_query_get_n_allocation_metas:
1735 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1737 * Retrieve the number of values currently stored in the
1738 * meta API array of the query's structure.
1740 * Returns: the metadata API array size as a #guint.
1743 gst_query_get_n_allocation_metas (GstQuery * query)
1746 GstStructure *structure;
1748 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1750 structure = GST_QUERY_STRUCTURE (query);
1752 ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
1758 * gst_query_parse_nth_allocation_meta:
1759 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1760 * @index: position in the metadata API array to read
1762 * Parse an available query and get the metadata API
1763 * at @index of the metadata API array.
1765 * Returns: a #gchar of the metadata API at @index.
1768 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1771 const gchar *ret = NULL;
1772 GstStructure *structure;
1774 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1776 structure = GST_QUERY_STRUCTURE (query);
1778 ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
1780 if (index < array->len)
1781 ret = g_array_index (array, const gchar *, index);
1787 * gst_query_has_allocation_meta:
1788 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1789 * @api: the metadata API
1791 * Check if @query has metadata @api set.
1793 * Returns: TRUE when @api is in the list of metadata.
1796 gst_query_has_allocation_meta (GstQuery * query, const gchar * api)
1799 GstStructure *structure;
1802 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1803 g_return_val_if_fail (api != NULL, FALSE);
1805 structure = GST_QUERY_STRUCTURE (query);
1807 ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
1810 for (i = 0; i < len; i++) {
1811 if (strcmp (api, g_array_index (array, const gchar *, i)) == 0)
1818 * gst_query_add_allocation_memory:
1819 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1820 * @allocator: the memory allocator
1822 * Add @allocator as a supported memory allocator.
1825 gst_query_add_allocation_memory (GstQuery * query, GstAllocator * allocator)
1828 GstStructure *structure;
1830 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1831 g_return_if_fail (gst_query_is_writable (query));
1832 g_return_if_fail (allocator != NULL);
1834 structure = GST_QUERY_STRUCTURE (query);
1836 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1837 (GDestroyNotify) gst_allocator_unref);
1839 g_array_append_val (array, allocator);
1843 * gst_query_get_n_allocation_memories:
1844 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1846 * Retrieve the number of values currently stored in the
1847 * allocator array of the query's structure.
1849 * If no memory allocator is specified, the downstream element can handle
1850 * the default memory allocator.
1852 * Returns: the allocator array size as a #guint.
1855 gst_query_get_n_allocation_memories (GstQuery * query)
1858 GstStructure *structure;
1860 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1862 structure = GST_QUERY_STRUCTURE (query);
1864 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1865 (GDestroyNotify) gst_allocator_unref);
1871 * gst_query_parse_nth_allocation_memory:
1872 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1873 * @index: position in the allocator array to read
1875 * Parse an available query and get the alloctor
1876 * at @index of the allocator array.
1878 * Returns: (transfer none): the allocator at @index. The allocator remains
1879 * valid for as long as @query is valid.
1882 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1885 GstAllocator *ret = NULL;
1886 GstStructure *structure;
1888 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1890 structure = GST_QUERY_STRUCTURE (query);
1892 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1893 (GDestroyNotify) gst_allocator_unref);
1895 if (index < array->len)
1896 ret = g_array_index (array, GstAllocator *, index);
1902 * gst_query_new_scheduling:
1904 * Constructs a new query object for querying the scheduling properties.
1906 * Free-function: gst_query_unref
1908 * Returns: (transfer full): a new #GstQuery
1911 gst_query_new_scheduling (void)
1914 GstStructure *structure;
1916 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1917 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1918 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1919 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1920 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1921 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
1927 * gst_query_set_scheduling:
1928 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1929 * @flags: #GstSchedulingFlags
1930 * @minsize: the suggested minimum size of pull requests
1931 * @maxsize: the suggested maximum size of pull requests
1932 * @align: the suggested alignment of pull requests
1934 * Set the scheduling properties.
1937 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1938 gint minsize, gint maxsize, gint align)
1940 GstStructure *structure;
1942 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1943 g_return_if_fail (gst_query_is_writable (query));
1945 structure = GST_QUERY_STRUCTURE (query);
1946 gst_structure_id_set (structure,
1947 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1948 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1949 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1950 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1954 * gst_query_parse_scheduling:
1955 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1956 * @flags: (out) (allow-none): #GstSchedulingFlags
1957 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
1958 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
1959 * @align: (out) (allow-none): the suggested alignment of pull requests
1961 * Set the scheduling properties.
1964 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
1965 gint * minsize, gint * maxsize, gint * align)
1967 GstStructure *structure;
1969 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1971 structure = GST_QUERY_STRUCTURE (query);
1972 gst_structure_id_get (structure,
1973 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1974 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1975 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1976 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1980 * gst_query_add_scheduling_mode:
1981 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1982 * @mode: a #GstPadMode
1984 * Add @mode as aone of the supported scheduling modes to @query.
1987 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
1989 GstStructure *structure;
1992 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1993 g_return_if_fail (gst_query_is_writable (query));
1995 structure = GST_QUERY_STRUCTURE (query);
1997 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
1999 g_array_append_val (array, mode);
2003 * gst_query_get_n_scheduling_modes:
2004 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2006 * Retrieve the number of values currently stored in the
2007 * scheduling mode array of the query's structure.
2009 * Returns: the scheduling mode array size as a #guint.
2012 gst_query_get_n_scheduling_modes (GstQuery * query)
2015 GstStructure *structure;
2017 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2019 structure = GST_QUERY_STRUCTURE (query);
2021 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2027 * gst_query_parse_nth_scheduling_mode:
2028 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2029 * @index: position in the scheduling modes array to read
2031 * Parse an available query and get the scheduling mode
2032 * at @index of the scheduling modes array.
2034 * Returns: a #GstPadMode of the scheduling mode at @index.
2037 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2039 GstPadMode ret = GST_PAD_MODE_NONE;
2040 GstStructure *structure;
2043 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, ret);
2045 structure = GST_QUERY_STRUCTURE (query);
2047 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2049 if (index < array->len)
2050 ret = g_array_index (array, GstPadMode, index);
2056 * gst_query_has_scheduling_mode:
2057 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2058 * @mode: the scheduling mode
2060 * Check if @query has scheduling mode set.
2062 * Returns: TRUE when @mode is in the list of scheduling modes.
2065 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2067 GstStructure *structure;
2071 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2073 structure = GST_QUERY_STRUCTURE (query);
2075 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2078 for (i = 0; i < len; i++) {
2079 if (mode == g_array_index (array, GstPadMode, i))
2086 * gst_query_new_accept_caps:
2089 * Constructs a new query object for querying if @caps are accepted.
2091 * Free-function: gst_query_unref
2093 * Returns: (transfer full): a new #GstQuery
2096 gst_query_new_accept_caps (GstCaps * caps)
2099 GstStructure *structure;
2101 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2102 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2103 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2104 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2110 * gst_query_parse_accept_caps:
2111 * @query: The query to parse
2112 * @caps: (out): A pointer to the caps
2114 * Get the caps from @query. The caps remains valid as long as @query remains
2118 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2120 GstStructure *structure;
2122 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2123 g_return_if_fail (caps != NULL);
2125 structure = GST_QUERY_STRUCTURE (query);
2126 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2131 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2133 GstStructure *structure;
2135 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2136 g_return_if_fail (gst_query_is_writable (query));
2138 structure = GST_QUERY_STRUCTURE (query);
2139 gst_structure_id_set (structure,
2140 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2144 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2146 GstStructure *structure;
2148 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2150 structure = GST_QUERY_STRUCTURE (query);
2151 gst_structure_id_get (structure,
2152 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2156 * gst_query_new_caps:
2159 * Constructs a new query object for querying the caps.
2161 * The CAPS query should return the* allowable caps for a pad in the context
2162 * of the element's state, its link to other elements, and the devices or files
2163 * it has opened. These caps must be a subset of the pad template caps. In the
2164 * NULL state with no links, the CAPS query should ideally return the same caps
2165 * as the pad template. In rare circumstances, an object property can affect
2166 * the caps returned by the CAPS query, but this is discouraged.
2168 * For most filters, the caps returned by CAPS query is directly affected by the
2169 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2170 * the srcpad's getcaps function is directly related to the stream data. Again,
2171 * the CAPS query should return the most specific caps it reasonably can, since this
2172 * helps with autoplugging.
2174 * Free-function: gst_query_unref
2176 * Returns: (transfer full): a new #GstQuery
2179 gst_query_new_caps (GstCaps * filter)
2182 GstStructure *structure;
2184 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2185 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2186 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2187 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2193 * gst_query_parse_caps:
2194 * @query: The query to parse
2195 * @filter: (out): A pointer to the caps filter
2197 * Get the filter from the caps @query. The caps remains valid as long as
2198 * @query remains valid.
2201 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2203 GstStructure *structure;
2205 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2206 g_return_if_fail (filter != NULL);
2208 structure = GST_QUERY_STRUCTURE (query);
2209 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2210 GST_QUARK (FILTER)));
2214 * gst_query_set_caps_result:
2215 * @query: The query to use
2216 * @caps: (in): A pointer to the caps
2218 * Set the @caps result in @query.
2221 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2223 GstStructure *structure;
2225 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2226 g_return_if_fail (gst_query_is_writable (query));
2228 structure = GST_QUERY_STRUCTURE (query);
2229 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2233 * gst_query_parse_caps_result:
2234 * @query: The query to parse
2235 * @caps: (out): A pointer to the caps
2237 * Get the caps result from @query. The caps remains valid as long as
2238 * @query remains valid.
2241 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2243 GstStructure *structure;
2245 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2246 g_return_if_fail (caps != NULL);
2248 structure = GST_QUERY_STRUCTURE (query);
2249 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2254 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2255 GstCapsIntersectMode mode)
2257 GstCaps *res, *caps = NULL;
2259 gst_query_parse_caps_result (query, &caps);
2260 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2261 gst_query_set_caps_result (query, res);
2262 gst_caps_unref (res);