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);
342 static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
345 _gst_query_copy (GstQuery * query)
349 copy = gst_query_new (query->type, GST_QUERY_STRUCTURE (query));
355 gst_query_new (GstQueryType type, GstStructure * structure)
359 query = g_slice_new0 (GstQueryImpl);
361 gst_mini_object_init (GST_MINI_OBJECT_CAST (query),
362 _gst_query_type, sizeof (GstQueryImpl));
364 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
365 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
367 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
369 GST_QUERY_TYPE (query) = type;
370 query->structure = structure;
373 gst_structure_set_parent_refcount (structure,
374 &query->query.mini_object.refcount);
376 return GST_QUERY_CAST (query);
380 * gst_query_new_position:
381 * @format: the default #GstFormat for the new query
383 * Constructs a new query stream position query object. Use gst_query_unref()
384 * when done with it. A position query is used to query the current position
385 * of playback in the streams, in some format.
387 * Free-function: gst_query_unref
389 * Returns: (transfer full): a new #GstQuery
392 gst_query_new_position (GstFormat format)
395 GstStructure *structure;
397 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
398 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
399 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
401 query = gst_query_new (GST_QUERY_POSITION, structure);
407 * gst_query_set_position:
408 * @query: a #GstQuery with query type GST_QUERY_POSITION
409 * @format: the requested #GstFormat
410 * @cur: the position to set
412 * Answer a position query by setting the requested value in the given format.
415 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
419 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
421 s = GST_QUERY_STRUCTURE (query);
422 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
423 GST_QUARK (FORMAT))));
425 gst_structure_id_set (s,
426 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
427 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
431 * gst_query_parse_position:
432 * @query: a #GstQuery
433 * @format: (out) (allow-none): the storage for the #GstFormat of the
434 * position values (may be NULL)
435 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
437 * Parse a position query, writing the format into @format, and the position
438 * into @cur, if the respective parameters are non-NULL.
441 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
443 GstStructure *structure;
445 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
447 structure = GST_QUERY_STRUCTURE (query);
450 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
451 GST_QUARK (FORMAT)));
453 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
454 GST_QUARK (CURRENT)));
459 * gst_query_new_duration:
460 * @format: the #GstFormat for this duration query
462 * Constructs a new stream duration query object to query in the given format.
463 * Use gst_query_unref() when done with it. A duration query will give the
464 * total length of the stream.
466 * Free-function: gst_query_unref
468 * Returns: (transfer full): a new #GstQuery
471 gst_query_new_duration (GstFormat format)
474 GstStructure *structure;
476 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
477 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
478 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
480 query = gst_query_new (GST_QUERY_DURATION, structure);
486 * gst_query_set_duration:
487 * @query: a #GstQuery
488 * @format: the #GstFormat for the duration
489 * @duration: the duration of the stream
491 * Answer a duration query by setting the requested value in the given format.
494 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
498 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
500 s = GST_QUERY_STRUCTURE (query);
501 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
502 GST_QUARK (FORMAT))));
503 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
504 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
508 * gst_query_parse_duration:
509 * @query: a #GstQuery
510 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
512 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
514 * Parse a duration query answer. Write the format of the duration into @format,
515 * and the value into @duration, if the respective variables are non-NULL.
518 gst_query_parse_duration (GstQuery * query, GstFormat * format,
521 GstStructure *structure;
523 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
525 structure = GST_QUERY_STRUCTURE (query);
528 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
529 GST_QUARK (FORMAT)));
531 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
532 GST_QUARK (DURATION)));
536 * gst_query_new_latency:
538 * Constructs a new latency query object.
539 * Use gst_query_unref() when done with it. A latency query is usually performed
540 * by sinks to compensate for additional latency introduced by elements in the
543 * Free-function: gst_query_unref
545 * Returns: (transfer full): a #GstQuery
550 gst_query_new_latency (void)
553 GstStructure *structure;
555 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
556 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
557 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
558 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
560 query = gst_query_new (GST_QUERY_LATENCY, structure);
566 * gst_query_set_latency:
567 * @query: a #GstQuery
568 * @live: if there is a live element upstream
569 * @min_latency: the minimal latency of the live element
570 * @max_latency: the maximal latency of the live element
572 * Answer a latency query by setting the requested values in the given format.
577 gst_query_set_latency (GstQuery * query, gboolean live,
578 GstClockTime min_latency, GstClockTime max_latency)
580 GstStructure *structure;
582 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
584 structure = GST_QUERY_STRUCTURE (query);
585 gst_structure_id_set (structure,
586 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
587 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
588 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
592 * gst_query_parse_latency:
593 * @query: a #GstQuery
594 * @live: (out) (allow-none): storage for live or NULL
595 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
596 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
598 * Parse a latency query answer.
603 gst_query_parse_latency (GstQuery * query, gboolean * live,
604 GstClockTime * min_latency, GstClockTime * max_latency)
606 GstStructure *structure;
608 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
610 structure = GST_QUERY_STRUCTURE (query);
613 g_value_get_boolean (gst_structure_id_get_value (structure,
616 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
617 GST_QUARK (MIN_LATENCY)));
619 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
620 GST_QUARK (MAX_LATENCY)));
624 * gst_query_new_convert:
625 * @src_format: the source #GstFormat for the new query
626 * @value: the value to convert
627 * @dest_format: the target #GstFormat
629 * Constructs a new convert query object. Use gst_query_unref()
630 * when done with it. A convert query is used to ask for a conversion between
631 * one format and another.
633 * Free-function: gst_query_unref
635 * Returns: (transfer full): a #GstQuery
638 gst_query_new_convert (GstFormat src_format, gint64 value,
639 GstFormat dest_format)
642 GstStructure *structure;
644 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
645 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
646 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
647 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
648 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
650 query = gst_query_new (GST_QUERY_CONVERT, structure);
656 * gst_query_set_convert:
657 * @query: a #GstQuery
658 * @src_format: the source #GstFormat
659 * @src_value: the source value
660 * @dest_format: the destination #GstFormat
661 * @dest_value: the destination value
663 * Answer a convert query by setting the requested values.
666 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
667 GstFormat dest_format, gint64 dest_value)
669 GstStructure *structure;
671 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
673 structure = GST_QUERY_STRUCTURE (query);
674 gst_structure_id_set (structure,
675 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
676 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
677 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
678 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
682 * gst_query_parse_convert:
683 * @query: a #GstQuery
684 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
685 * source value, or NULL
686 * @src_value: (out) (allow-none): the storage for the source value, or NULL
687 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
688 * destination value, or NULL
689 * @dest_value: (out) (allow-none): the storage for the destination value,
692 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
693 * and @dest_value may be NULL, in which case that value is omitted.
696 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
697 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
699 GstStructure *structure;
701 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
703 structure = GST_QUERY_STRUCTURE (query);
706 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
707 GST_QUARK (SRC_FORMAT)));
709 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
710 GST_QUARK (SRC_VALUE)));
713 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
714 GST_QUARK (DEST_FORMAT)));
716 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
717 GST_QUARK (DEST_VALUE)));
721 * gst_query_new_segment:
722 * @format: the #GstFormat for the new query
724 * Constructs a new segment query object. Use gst_query_unref()
725 * when done with it. A segment query is used to discover information about the
726 * currently configured segment for playback.
728 * Free-function: gst_query_unref
730 * Returns: (transfer full): a new #GstQuery
733 gst_query_new_segment (GstFormat format)
736 GstStructure *structure;
738 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
739 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
740 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
741 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
742 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
744 query = gst_query_new (GST_QUERY_SEGMENT, structure);
750 * gst_query_set_segment:
751 * @query: a #GstQuery
752 * @rate: the rate of the segment
753 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
754 * @start_value: the start value
755 * @stop_value: the stop value
757 * Answer a segment query by setting the requested values. The normal
758 * playback segment of a pipeline is 0 to duration at the default rate of
759 * 1.0. If a seek was performed on the pipeline to play a different
760 * segment, this query will return the range specified in the last seek.
762 * @start_value and @stop_value will respectively contain the configured
763 * playback range start and stop values expressed in @format.
764 * The values are always between 0 and the duration of the media and
765 * @start_value <= @stop_value. @rate will contain the playback rate. For
766 * negative rates, playback will actually happen from @stop_value to
770 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
771 gint64 start_value, gint64 stop_value)
773 GstStructure *structure;
775 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
777 structure = GST_QUERY_STRUCTURE (query);
778 gst_structure_id_set (structure,
779 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
780 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
781 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
782 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
786 * gst_query_parse_segment:
787 * @query: a #GstQuery
788 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
789 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
791 * @start_value: (out) (allow-none): the storage for the start value, or NULL
792 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
794 * Parse a segment query answer. Any of @rate, @format, @start_value, and
795 * @stop_value may be NULL, which will cause this value to be omitted.
797 * See gst_query_set_segment() for an explanation of the function arguments.
800 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
801 gint64 * start_value, gint64 * stop_value)
803 GstStructure *structure;
805 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
807 structure = GST_QUERY_STRUCTURE (query);
809 *rate = g_value_get_double (gst_structure_id_get_value (structure,
813 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
814 GST_QUARK (FORMAT)));
816 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
817 GST_QUARK (START_VALUE)));
819 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
820 GST_QUARK (STOP_VALUE)));
824 * gst_query_new_custom:
825 * @type: the query type
826 * @structure: a structure for the query
828 * Constructs a new custom query object. Use gst_query_unref()
831 * Free-function: gst_query_unref
833 * Returns: (transfer full): a new #GstQuery
836 gst_query_new_custom (GstQueryType type, GstStructure * structure)
838 g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
839 g_return_val_if_fail (structure != NULL, NULL);
841 return gst_query_new (type, structure);
845 * gst_query_get_structure:
846 * @query: a #GstQuery
848 * Get the structure of a query.
850 * Returns: (transfer none): the #GstStructure of the query. The structure is
851 * still owned by the query and will therefore be freed when the query
855 gst_query_get_structure (GstQuery * query)
857 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
859 return GST_QUERY_STRUCTURE (query);
863 * gst_query_writable_structure:
864 * @query: a #GstQuery
866 * Get the structure of a query.
868 * Returns: (transfer none): the #GstStructure of the query. The structure is
869 * still owned by the query and will therefore be freed when the query
873 gst_query_writable_structure (GstQuery * query)
875 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
876 g_return_val_if_fail (gst_query_is_writable (query), NULL);
878 return GST_QUERY_STRUCTURE (query);
882 * gst_query_new_seeking:
883 * @format: the default #GstFormat for the new query
885 * Constructs a new query object for querying seeking properties of
888 * Free-function: gst_query_unref
890 * Returns: (transfer full): a new #GstQuery
893 gst_query_new_seeking (GstFormat format)
896 GstStructure *structure;
898 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
899 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
900 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
901 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
902 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
904 query = gst_query_new (GST_QUERY_SEEKING, structure);
910 * gst_query_set_seeking:
911 * @query: a #GstQuery
912 * @format: the format to set for the @segment_start and @segment_end values
913 * @seekable: the seekable flag to set
914 * @segment_start: the segment_start to set
915 * @segment_end: the segment_end to set
917 * Set the seeking query result fields in @query.
920 gst_query_set_seeking (GstQuery * query, GstFormat format,
921 gboolean seekable, gint64 segment_start, gint64 segment_end)
923 GstStructure *structure;
925 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
926 g_return_if_fail (gst_query_is_writable (query));
928 structure = GST_QUERY_STRUCTURE (query);
929 gst_structure_id_set (structure,
930 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
931 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
932 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
933 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
937 * gst_query_parse_seeking:
938 * @query: a GST_QUERY_SEEKING type query #GstQuery
939 * @format: (out) (allow-none): the format to set for the @segment_start
940 * and @segment_end values, or NULL
941 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
942 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
943 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
945 * Parse a seeking query, writing the format into @format, and
946 * other results into the passed parameters, if the respective parameters
950 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
951 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
953 GstStructure *structure;
955 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
957 structure = GST_QUERY_STRUCTURE (query);
960 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
961 GST_QUARK (FORMAT)));
963 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
964 GST_QUARK (SEEKABLE)));
966 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
967 GST_QUARK (SEGMENT_START)));
969 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
970 GST_QUARK (SEGMENT_END)));
974 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
975 GDestroyNotify clear_func)
980 value = gst_structure_id_get_value (s, quark);
982 array = (GArray *) g_value_get_boxed (value);
984 GValue new_array_val = { 0, };
986 array = g_array_new (FALSE, TRUE, element_size);
988 g_array_set_clear_func (array, clear_func);
990 g_value_init (&new_array_val, G_TYPE_ARRAY);
991 g_value_take_boxed (&new_array_val, array);
993 gst_structure_id_take_value (s, quark, &new_array_val);
999 * gst_query_new_formats:
1001 * Constructs a new query object for querying formats of
1004 * Free-function: gst_query_unref
1006 * Returns: (transfer full): a new #GstQuery
1011 gst_query_new_formats (void)
1014 GstStructure *structure;
1016 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
1017 query = gst_query_new (GST_QUERY_FORMATS, structure);
1023 gst_query_list_add_format (GValue * list, GstFormat format)
1025 GValue item = { 0, };
1027 g_value_init (&item, GST_TYPE_FORMAT);
1028 g_value_set_enum (&item, format);
1029 gst_value_list_append_value (list, &item);
1030 g_value_unset (&item);
1034 * gst_query_set_formats:
1035 * @query: a #GstQuery
1036 * @n_formats: the number of formats to set.
1037 * @...: A number of @GstFormats equal to @n_formats.
1039 * Set the formats query result fields in @query. The number of formats passed
1040 * must be equal to @n_formats.
1043 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1046 GValue list = { 0, };
1048 GstStructure *structure;
1050 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1051 g_return_if_fail (gst_query_is_writable (query));
1053 g_value_init (&list, GST_TYPE_LIST);
1055 va_start (ap, n_formats);
1056 for (i = 0; i < n_formats; i++) {
1057 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1061 structure = GST_QUERY_STRUCTURE (query);
1062 gst_structure_set_value (structure, "formats", &list);
1064 g_value_unset (&list);
1069 * gst_query_set_formatsv:
1070 * @query: a #GstQuery
1071 * @n_formats: the number of formats to set.
1072 * @formats: (in) (array length=n_formats): an array containing @n_formats
1073 * @GstFormat values.
1075 * Set the formats query result fields in @query. The number of formats passed
1076 * in the @formats array must be equal to @n_formats.
1081 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1082 const GstFormat * formats)
1084 GValue list = { 0, };
1086 GstStructure *structure;
1088 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1089 g_return_if_fail (gst_query_is_writable (query));
1091 g_value_init (&list, GST_TYPE_LIST);
1092 for (i = 0; i < n_formats; i++) {
1093 gst_query_list_add_format (&list, formats[i]);
1095 structure = GST_QUERY_STRUCTURE (query);
1096 gst_structure_set_value (structure, "formats", &list);
1098 g_value_unset (&list);
1102 * gst_query_parse_n_formats:
1103 * @query: a #GstQuery
1104 * @n_formats: (out) (allow-none): the number of formats in this query.
1106 * Parse the number of formats in the formats @query.
1111 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1113 GstStructure *structure;
1115 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1120 structure = GST_QUERY_STRUCTURE (query);
1121 list = gst_structure_get_value (structure, "formats");
1125 *n_formats = gst_value_list_get_size (list);
1130 * gst_query_parse_nth_format:
1131 * @query: a #GstQuery
1132 * @nth: (out): the nth format to retrieve.
1133 * @format: (out) (allow-none): a pointer to store the nth format
1135 * Parse the format query and retrieve the @nth format from it into
1136 * @format. If the list contains less elements than @nth, @format will be
1137 * set to GST_FORMAT_UNDEFINED.
1140 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1142 GstStructure *structure;
1144 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1149 structure = GST_QUERY_STRUCTURE (query);
1150 list = gst_structure_get_value (structure, "formats");
1152 *format = GST_FORMAT_UNDEFINED;
1154 if (nth < gst_value_list_get_size (list)) {
1156 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1158 *format = GST_FORMAT_UNDEFINED;
1164 * gst_query_new_buffering:
1165 * @format: the default #GstFormat for the new query
1167 * Constructs a new query object for querying the buffering status of
1170 * Free-function: gst_query_unref
1172 * Returns: (transfer full): a new #GstQuery
1177 gst_query_new_buffering (GstFormat format)
1180 GstStructure *structure;
1182 /* by default, we configure the answer as no buffering with a 100% buffering
1184 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1185 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1186 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1187 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1188 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1189 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1190 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1191 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1192 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1193 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1194 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1196 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1202 * gst_query_set_buffering_percent:
1203 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1204 * @busy: if buffering is busy
1205 * @percent: a buffering percent
1207 * Set the percentage of buffered data. This is a value between 0 and 100.
1208 * The @busy indicator is %TRUE when the buffering is in progress.
1213 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1215 GstStructure *structure;
1217 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1218 g_return_if_fail (gst_query_is_writable (query));
1219 g_return_if_fail (percent >= 0 && percent <= 100);
1221 structure = GST_QUERY_STRUCTURE (query);
1222 gst_structure_id_set (structure,
1223 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1224 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1228 * gst_query_parse_buffering_percent:
1229 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1230 * @busy: (out) (allow-none): if buffering is busy, or NULL
1231 * @percent: (out) (allow-none): a buffering percent, or NULL
1233 * Get the percentage of buffered data. This is a value between 0 and 100.
1234 * The @busy indicator is %TRUE when the buffering is in progress.
1239 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1242 GstStructure *structure;
1244 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1246 structure = GST_QUERY_STRUCTURE (query);
1248 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1251 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1252 GST_QUARK (BUFFER_PERCENT)));
1256 * gst_query_set_buffering_stats:
1257 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1258 * @mode: a buffering mode
1259 * @avg_in: the average input rate
1260 * @avg_out: the average output rate
1261 * @buffering_left: amount of buffering time left
1263 * Configures the buffering stats values in @query.
1268 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1269 gint avg_in, gint avg_out, gint64 buffering_left)
1271 GstStructure *structure;
1273 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1274 g_return_if_fail (gst_query_is_writable (query));
1276 structure = GST_QUERY_STRUCTURE (query);
1277 gst_structure_id_set (structure,
1278 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1279 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1280 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1281 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1285 * gst_query_parse_buffering_stats:
1286 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1287 * @mode: (out) (allow-none): a buffering mode, or NULL
1288 * @avg_in: (out) (allow-none): the average input rate, or NULL
1289 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1290 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1292 * Extracts the buffering stats values from @query.
1297 gst_query_parse_buffering_stats (GstQuery * query,
1298 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1299 gint64 * buffering_left)
1301 GstStructure *structure;
1303 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1305 structure = GST_QUERY_STRUCTURE (query);
1307 *mode = (GstBufferingMode)
1308 g_value_get_enum (gst_structure_id_get_value (structure,
1309 GST_QUARK (BUFFERING_MODE)));
1311 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1312 GST_QUARK (AVG_IN_RATE)));
1314 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1315 GST_QUARK (AVG_OUT_RATE)));
1318 g_value_get_int64 (gst_structure_id_get_value (structure,
1319 GST_QUARK (BUFFERING_LEFT)));
1323 * gst_query_set_buffering_range:
1324 * @query: a #GstQuery
1325 * @format: the format to set for the @start and @stop values
1326 * @start: the start to set
1327 * @stop: the stop to set
1328 * @estimated_total: estimated total amount of download time
1330 * Set the available query result fields in @query.
1335 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1336 gint64 start, gint64 stop, gint64 estimated_total)
1338 GstStructure *structure;
1340 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1341 g_return_if_fail (gst_query_is_writable (query));
1343 structure = GST_QUERY_STRUCTURE (query);
1344 gst_structure_id_set (structure,
1345 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1346 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1347 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1348 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1352 * gst_query_parse_buffering_range:
1353 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1354 * @format: (out) (allow-none): the format to set for the @segment_start
1355 * and @segment_end values, or NULL
1356 * @start: (out) (allow-none): the start to set, or NULL
1357 * @stop: (out) (allow-none): the stop to set, or NULL
1358 * @estimated_total: (out) (allow-none): estimated total amount of download
1361 * Parse an available query, writing the format into @format, and
1362 * other results into the passed parameters, if the respective parameters
1368 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1369 gint64 * start, gint64 * stop, gint64 * estimated_total)
1371 GstStructure *structure;
1373 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1375 structure = GST_QUERY_STRUCTURE (query);
1378 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1379 GST_QUARK (FORMAT)));
1381 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1382 GST_QUARK (START_VALUE)));
1384 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1385 GST_QUARK (STOP_VALUE)));
1386 if (estimated_total)
1388 g_value_get_int64 (gst_structure_id_get_value (structure,
1389 GST_QUARK (ESTIMATED_TOTAL)));
1393 * gst_query_add_buffering_range:
1394 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1395 * @start: start position of the range
1396 * @stop: stop position of the range
1398 * Set the buffering-ranges array field in @query. The current last
1399 * start position of the array should be inferior to @start.
1401 * Returns: a #gboolean indicating if the range was added or not.
1406 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1408 GstQueryBufferingRange range;
1409 GstStructure *structure;
1412 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1413 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1415 if (G_UNLIKELY (start >= stop))
1418 structure = GST_QUERY_STRUCTURE (query);
1419 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1420 sizeof (GstQueryBufferingRange), NULL);
1422 if (array->len > 1) {
1423 GstQueryBufferingRange *last;
1425 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1427 if (G_UNLIKELY (start <= last->start))
1431 range.start = start;
1433 g_array_append_val (array, range);
1439 * gst_query_get_n_buffering_ranges:
1440 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1442 * Retrieve the number of values currently stored in the
1443 * buffered-ranges array of the query's structure.
1445 * Returns: the range array size as a #guint.
1450 gst_query_get_n_buffering_ranges (GstQuery * query)
1452 GstStructure *structure;
1455 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1457 structure = GST_QUERY_STRUCTURE (query);
1458 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1459 sizeof (GstQueryBufferingRange), NULL);
1466 * gst_query_parse_nth_buffering_range:
1467 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1468 * @index: position in the buffered-ranges array to read
1469 * @start: (out) (allow-none): the start position to set, or NULL
1470 * @stop: (out) (allow-none): the stop position to set, or NULL
1472 * Parse an available query and get the start and stop values stored
1473 * at the @index of the buffered ranges array.
1475 * Returns: a #gboolean indicating if the parsing succeeded.
1480 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1481 gint64 * start, gint64 * stop)
1483 GstQueryBufferingRange *range;
1484 GstStructure *structure;
1487 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1489 structure = GST_QUERY_STRUCTURE (query);
1491 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1492 sizeof (GstQueryBufferingRange), NULL);
1494 if (index >= array->len)
1497 range = &g_array_index (array, GstQueryBufferingRange, index);
1500 *start = range->start;
1502 *stop = range->stop;
1509 * gst_query_new_uri:
1511 * Constructs a new query URI query object. Use gst_query_unref()
1512 * when done with it. An URI query is used to query the current URI
1513 * that is used by the source or sink.
1515 * Free-function: gst_query_unref
1517 * Returns: (transfer full): a new #GstQuery
1522 gst_query_new_uri (void)
1525 GstStructure *structure;
1527 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1528 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1530 query = gst_query_new (GST_QUERY_URI, structure);
1536 * gst_query_set_uri:
1537 * @query: a #GstQuery with query type GST_QUERY_URI
1538 * @uri: the URI to set
1540 * Answer a URI query by setting the requested URI.
1545 gst_query_set_uri (GstQuery * query, const gchar * uri)
1547 GstStructure *structure;
1549 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1550 g_return_if_fail (gst_query_is_writable (query));
1551 g_return_if_fail (gst_uri_is_valid (uri));
1553 structure = GST_QUERY_STRUCTURE (query);
1554 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1558 * gst_query_parse_uri:
1559 * @query: a #GstQuery
1560 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1563 * Parse an URI query, writing the URI into @uri as a newly
1564 * allocated string, if the respective parameters are non-NULL.
1565 * Free the string with g_free() after usage.
1570 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1572 GstStructure *structure;
1574 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1576 structure = GST_QUERY_STRUCTURE (query);
1578 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1583 * gst_query_new_allocation:
1584 * @caps: the negotiated caps
1585 * @need_pool: return a pool
1587 * Constructs a new query object for querying the allocation properties.
1589 * Free-function: gst_query_unref
1591 * Returns: (transfer full): a new #GstQuery
1594 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1597 GstStructure *structure;
1599 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1600 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1601 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1602 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1603 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1604 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1605 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1606 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1607 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1609 query = gst_query_new (GST_QUERY_ALLOCATION, structure);
1615 * gst_query_parse_allocation:
1616 * @query: a #GstQuery
1617 * @caps: (out callee-allocates) (allow-none): The #GstCaps
1618 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1620 * Parse an allocation query, writing the requested caps in @caps and
1621 * whether a pool is needed in @need_pool, if the respective parameters
1625 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1626 gboolean * need_pool)
1628 GstStructure *structure;
1630 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1632 structure = GST_QUERY_STRUCTURE (query);
1633 gst_structure_id_get (structure,
1634 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1635 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1639 * gst_query_set_allocation_params:
1640 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1642 * @min_buffers: the min buffers
1643 * @max_buffers: the max buffers
1644 * @prefix: the prefix
1645 * @alignment: the alignment
1646 * @pool: the #GstBufferPool
1648 * Set the allocation parameters in @query.
1651 gst_query_set_allocation_params (GstQuery * query, guint size,
1652 guint min_buffers, guint max_buffers, guint prefix,
1653 guint alignment, GstBufferPool * pool)
1655 GstStructure *structure;
1657 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1658 g_return_if_fail (gst_query_is_writable (query));
1659 g_return_if_fail (((alignment + 1) & alignment) == 0);
1660 g_return_if_fail (size != 0 || pool == NULL);
1662 structure = GST_QUERY_STRUCTURE (query);
1663 gst_structure_id_set (structure,
1664 GST_QUARK (SIZE), G_TYPE_UINT, size,
1665 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1666 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1667 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1668 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1669 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1673 * gst_query_parse_allocation_params:
1674 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1675 * @size: (out) (allow-none): the size
1676 * @min_buffers: (out) (allow-none): the min buffers
1677 * @max_buffers: (out) (allow-none): the max buffers
1678 * @prefix: (out) (allow-none): the prefix
1679 * @alignment: (out) (allow-none): the alignment
1680 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1682 * Get the allocation parameters in @query.
1685 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1686 guint * min_buffers, guint * max_buffers, guint * prefix,
1687 guint * alignment, GstBufferPool ** pool)
1689 GstStructure *structure;
1691 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1693 structure = GST_QUERY_STRUCTURE (query);
1694 gst_structure_id_get (structure,
1695 GST_QUARK (SIZE), G_TYPE_UINT, size,
1696 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1697 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1698 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1699 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1700 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1704 * gst_query_add_allocation_meta:
1705 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1706 * @api: the metadata API
1708 * Add @api as aone of the supported metadata API to @query.
1711 gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
1714 GstStructure *structure;
1716 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1717 g_return_if_fail (api != NULL);
1718 g_return_if_fail (gst_query_is_writable (query));
1720 structure = GST_QUERY_STRUCTURE (query);
1722 ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
1724 api = g_intern_string (api);
1725 g_array_append_val (array, api);
1729 * gst_query_get_n_allocation_metas:
1730 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1732 * Retrieve the number of values currently stored in the
1733 * meta API array of the query's structure.
1735 * Returns: the metadata API array size as a #guint.
1738 gst_query_get_n_allocation_metas (GstQuery * query)
1741 GstStructure *structure;
1743 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1745 structure = GST_QUERY_STRUCTURE (query);
1747 ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
1753 * gst_query_parse_nth_allocation_meta:
1754 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1755 * @index: position in the metadata API array to read
1757 * Parse an available query and get the metadata API
1758 * at @index of the metadata API array.
1760 * Returns: a #gchar of the metadata API at @index.
1763 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1766 const gchar *ret = NULL;
1767 GstStructure *structure;
1769 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1771 structure = GST_QUERY_STRUCTURE (query);
1773 ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
1775 if (index < array->len)
1776 ret = g_array_index (array, const gchar *, index);
1782 * gst_query_has_allocation_meta:
1783 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1784 * @api: the metadata API
1786 * Check if @query has metadata @api set.
1788 * Returns: TRUE when @api is in the list of metadata.
1791 gst_query_has_allocation_meta (GstQuery * query, const gchar * api)
1794 GstStructure *structure;
1797 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1798 g_return_val_if_fail (api != NULL, FALSE);
1800 structure = GST_QUERY_STRUCTURE (query);
1802 ensure_array (structure, GST_QUARK (META), sizeof (const gchar *), NULL);
1805 for (i = 0; i < len; i++) {
1806 if (strcmp (api, g_array_index (array, const gchar *, i)) == 0)
1813 * gst_query_add_allocation_memory:
1814 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1815 * @allocator: the memory allocator
1817 * Add @allocator as a supported memory allocator.
1820 gst_query_add_allocation_memory (GstQuery * query, GstAllocator * allocator)
1823 GstStructure *structure;
1825 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1826 g_return_if_fail (gst_query_is_writable (query));
1827 g_return_if_fail (allocator != NULL);
1829 structure = GST_QUERY_STRUCTURE (query);
1831 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1832 (GDestroyNotify) gst_allocator_unref);
1834 g_array_append_val (array, allocator);
1838 * gst_query_get_n_allocation_memories:
1839 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1841 * Retrieve the number of values currently stored in the
1842 * allocator array of the query's structure.
1844 * If no memory allocator is specified, the downstream element can handle
1845 * the default memory allocator.
1847 * Returns: the allocator array size as a #guint.
1850 gst_query_get_n_allocation_memories (GstQuery * query)
1853 GstStructure *structure;
1855 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1857 structure = GST_QUERY_STRUCTURE (query);
1859 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1860 (GDestroyNotify) gst_allocator_unref);
1866 * gst_query_parse_nth_allocation_memory:
1867 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1868 * @index: position in the allocator array to read
1870 * Parse an available query and get the alloctor
1871 * at @index of the allocator array.
1873 * Returns: (transfer none): the allocator at @index. The allocator remains
1874 * valid for as long as @query is valid.
1877 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1880 GstAllocator *ret = NULL;
1881 GstStructure *structure;
1883 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1885 structure = GST_QUERY_STRUCTURE (query);
1887 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1888 (GDestroyNotify) gst_allocator_unref);
1890 if (index < array->len)
1891 ret = g_array_index (array, GstAllocator *, index);
1897 * gst_query_new_scheduling:
1899 * Constructs a new query object for querying the scheduling properties.
1901 * Free-function: gst_query_unref
1903 * Returns: (transfer full): a new #GstQuery
1906 gst_query_new_scheduling (void)
1909 GstStructure *structure;
1911 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1912 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1913 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1914 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1915 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1916 query = gst_query_new (GST_QUERY_SCHEDULING, structure);
1922 * gst_query_set_scheduling:
1923 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1924 * @flags: #GstSchedulingFlags
1925 * @minsize: the suggested minimum size of pull requests
1926 * @maxsize: the suggested maximum size of pull requests
1927 * @align: the suggested alignment of pull requests
1929 * Set the scheduling properties.
1932 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1933 gint minsize, gint maxsize, gint align)
1935 GstStructure *structure;
1937 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1938 g_return_if_fail (gst_query_is_writable (query));
1940 structure = GST_QUERY_STRUCTURE (query);
1941 gst_structure_id_set (structure,
1942 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1943 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1944 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1945 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1949 * gst_query_parse_scheduling:
1950 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1951 * @flags: (out) (allow-none): #GstSchedulingFlags
1952 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
1953 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
1954 * @align: (out) (allow-none): the suggested alignment of pull requests
1956 * Set the scheduling properties.
1959 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
1960 gint * minsize, gint * maxsize, gint * align)
1962 GstStructure *structure;
1964 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1966 structure = GST_QUERY_STRUCTURE (query);
1967 gst_structure_id_get (structure,
1968 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1969 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1970 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1971 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1975 * gst_query_add_scheduling_mode:
1976 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1977 * @mode: a #GstPadMode
1979 * Add @mode as aone of the supported scheduling modes to @query.
1982 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
1984 GstStructure *structure;
1987 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1988 g_return_if_fail (gst_query_is_writable (query));
1990 structure = GST_QUERY_STRUCTURE (query);
1992 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
1994 g_array_append_val (array, mode);
1998 * gst_query_get_n_scheduling_modes:
1999 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2001 * Retrieve the number of values currently stored in the
2002 * scheduling mode array of the query's structure.
2004 * Returns: the scheduling mode array size as a #guint.
2007 gst_query_get_n_scheduling_modes (GstQuery * query)
2010 GstStructure *structure;
2012 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2014 structure = GST_QUERY_STRUCTURE (query);
2016 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2022 * gst_query_parse_nth_scheduling_mode:
2023 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2024 * @index: position in the scheduling modes array to read
2026 * Parse an available query and get the scheduling mode
2027 * at @index of the scheduling modes array.
2029 * Returns: a #GstPadMode of the scheduling mode at @index.
2032 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2034 GstPadMode ret = GST_PAD_MODE_NONE;
2035 GstStructure *structure;
2038 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, ret);
2040 structure = GST_QUERY_STRUCTURE (query);
2042 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2044 if (index < array->len)
2045 ret = g_array_index (array, GstPadMode, index);
2051 * gst_query_has_scheduling_mode:
2052 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2053 * @mode: the scheduling mode
2055 * Check if @query has scheduling mode set.
2057 * Returns: TRUE when @mode is in the list of scheduling modes.
2060 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2062 GstStructure *structure;
2066 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2068 structure = GST_QUERY_STRUCTURE (query);
2070 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2073 for (i = 0; i < len; i++) {
2074 if (mode == g_array_index (array, GstPadMode, i))
2081 * gst_query_new_accept_caps:
2084 * Constructs a new query object for querying if @caps are accepted.
2086 * Free-function: gst_query_unref
2088 * Returns: (transfer full): a new #GstQuery
2091 gst_query_new_accept_caps (GstCaps * caps)
2094 GstStructure *structure;
2096 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2097 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2098 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2099 query = gst_query_new (GST_QUERY_ACCEPT_CAPS, structure);
2105 * gst_query_parse_accept_caps:
2106 * @query: The query to parse
2107 * @caps: (out): A pointer to the caps
2109 * Get the caps from @query. The caps remains valid as long as @query remains
2113 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2115 GstStructure *structure;
2117 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2118 g_return_if_fail (caps != NULL);
2120 structure = GST_QUERY_STRUCTURE (query);
2121 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2126 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2128 GstStructure *structure;
2130 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2131 g_return_if_fail (gst_query_is_writable (query));
2133 structure = GST_QUERY_STRUCTURE (query);
2134 gst_structure_id_set (structure,
2135 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2139 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2141 GstStructure *structure;
2143 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2145 structure = GST_QUERY_STRUCTURE (query);
2146 gst_structure_id_get (structure,
2147 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2151 * gst_query_new_caps:
2154 * Constructs a new query object for querying the caps.
2156 * The CAPS query should return the* allowable caps for a pad in the context
2157 * of the element's state, its link to other elements, and the devices or files
2158 * it has opened. These caps must be a subset of the pad template caps. In the
2159 * NULL state with no links, the CAPS query should ideally return the same caps
2160 * as the pad template. In rare circumstances, an object property can affect
2161 * the caps returned by the CAPS query, but this is discouraged.
2163 * For most filters, the caps returned by CAPS query is directly affected by the
2164 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2165 * the srcpad's getcaps function is directly related to the stream data. Again,
2166 * the CAPS query should return the most specific caps it reasonably can, since this
2167 * helps with autoplugging.
2169 * Free-function: gst_query_unref
2171 * Returns: (transfer full): a new #GstQuery
2174 gst_query_new_caps (GstCaps * filter)
2177 GstStructure *structure;
2179 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2180 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2181 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2182 query = gst_query_new (GST_QUERY_CAPS, structure);
2188 * gst_query_parse_caps:
2189 * @query: The query to parse
2190 * @filter: (out): A pointer to the caps filter
2192 * Get the filter from the caps @query. The caps remains valid as long as
2193 * @query remains valid.
2196 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2198 GstStructure *structure;
2200 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2201 g_return_if_fail (filter != NULL);
2203 structure = GST_QUERY_STRUCTURE (query);
2204 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2205 GST_QUARK (FILTER)));
2209 * gst_query_set_caps_result:
2210 * @query: The query to use
2211 * @caps: (in): A pointer to the caps
2213 * Set the @caps result in @query.
2216 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2218 GstStructure *structure;
2220 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2221 g_return_if_fail (gst_query_is_writable (query));
2223 structure = GST_QUERY_STRUCTURE (query);
2224 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2228 * gst_query_parse_caps_result:
2229 * @query: The query to parse
2230 * @caps: (out): A pointer to the caps
2232 * Get the caps result from @query. The caps remains valid as long as
2233 * @query remains valid.
2236 gst_query_parse_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 (caps != NULL);
2243 structure = GST_QUERY_STRUCTURE (query);
2244 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2249 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2250 GstCapsIntersectMode mode)
2252 GstCaps *res, *caps = NULL;
2254 gst_query_parse_caps_result (query, &caps);
2255 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2256 gst_query_set_caps_result (query, res);
2257 gst_caps_unref (res);