2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
4 * 2005 Wim Taymans <wim@fluendo.com>
6 * gstquery.c: GstQueryType registration and Query parsing/creation
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * @short_description: Dynamically register new query types. Provide functions
27 * to create queries, and to set and parse values in them.
28 * @see_also: #GstPad, #GstElement
30 * GstQuery functions are used to register new query types to the gstreamer
32 * Queries can be performed on pads (gst_pad_query()) and elements
33 * (gst_element_query()). Please note that some queries might need a running
36 * Queries can be created using the gst_query_new_*() functions.
37 * Query values can be set using gst_query_set_*(), and parsed using
38 * gst_query_parse_*() helpers.
40 * The following example shows how to query the duration of a pipeline:
43 * <title>Query duration on a pipeline</title>
47 * query = gst_query_new_duration (GST_FORMAT_TIME);
48 * res = gst_element_query (pipeline, query);
51 * gst_query_parse_duration (query, NULL, &duration);
52 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
55 * g_print ("duration query failed...");
57 * gst_query_unref (query);
61 * Last reviewed on 2006-02-14 (0.10.4)
65 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
66 * with newer GLib versions (>= 2.31.0) */
67 #define GLIB_DISABLE_DEPRECATION_WARNINGS
69 #include "gst_private.h"
73 #include "gstenumtypes.h"
76 #include "gstbufferpool.h"
78 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
79 #define GST_CAT_DEFAULT gst_query_debug
81 static GType _gst_query_type = 0;
87 GstStructure *structure;
90 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
92 /* GstQueryBufferingRange: internal struct for GArray */
97 } GstQueryBufferingRange;
100 static GList *_gst_queries = NULL;
101 static GHashTable *_nick_to_query = NULL;
102 static GHashTable *_query_type_to_nick = NULL;
103 static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */
105 static GstQueryTypeDefinition standard_definitions[] = {
106 {GST_QUERY_POSITION, "position", "Current position", 0},
107 {GST_QUERY_DURATION, "duration", "Total duration", 0},
108 {GST_QUERY_LATENCY, "latency", "Latency", 0},
109 {GST_QUERY_JITTER, "jitter", "Jitter", 0},
110 {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
111 {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
112 {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
113 {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
114 {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
115 {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
116 {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
117 {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
118 {GST_QUERY_ALLOCATION, "allocation", "Allocation properties", 0},
119 {GST_QUERY_SCHEDULING, "scheduling", "Scheduling properties", 0},
120 {GST_QUERY_ACCEPT_CAPS, "accept-caps", "Accept caps", 0},
121 {GST_QUERY_CAPS, "caps", "Caps", 0},
122 {GST_QUERY_NONE, NULL, NULL, 0}
125 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
128 _priv_gst_query_initialize (void)
130 GstQueryTypeDefinition *standards = standard_definitions;
132 GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
134 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
136 g_mutex_lock (&mutex);
137 if (_nick_to_query == NULL) {
138 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
139 _query_type_to_nick = g_hash_table_new (NULL, NULL);
142 while (standards->nick) {
143 standards->quark = g_quark_from_static_string (standards->nick);
144 g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
145 g_hash_table_insert (_query_type_to_nick,
146 GINT_TO_POINTER (standards->value), standards);
148 _gst_queries = g_list_append (_gst_queries, standards);
152 g_mutex_unlock (&mutex);
154 _gst_query_type = gst_query_get_type ();
158 * gst_query_type_get_name:
159 * @query: the query type
161 * Get a printable name for the given query type. Do not modify or free.
163 * Returns: a reference to the static name of the query.
166 gst_query_type_get_name (GstQueryType query)
168 const GstQueryTypeDefinition *def;
170 def = gst_query_type_get_details (query);
171 g_return_val_if_fail (def != NULL, NULL);
177 * gst_query_type_to_quark:
178 * @query: the query type
180 * Get the unique quark for the given query type.
182 * Returns: the quark associated with the query type
185 gst_query_type_to_quark (GstQueryType query)
187 const GstQueryTypeDefinition *def;
189 def = gst_query_type_get_details (query);
190 g_return_val_if_fail (def != NULL, 0);
196 * gst_query_type_register:
197 * @nick: The nick of the new query
198 * @description: The description of the new query
200 * Create a new GstQueryType based on the nick or return an
201 * already registered query with that nick
203 * Returns: A new GstQueryType or an already registered query
204 * with the same nick.
207 gst_query_type_register (const gchar * nick, const gchar * description)
209 GstQueryTypeDefinition *query;
212 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
213 g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
215 lookup = gst_query_type_get_by_nick (nick);
216 if (lookup != GST_QUERY_NONE)
219 query = g_slice_new (GstQueryTypeDefinition);
220 query->value = (GstQueryType) _n_values;
221 query->nick = g_strdup (nick);
222 query->description = g_strdup (description);
223 query->quark = g_quark_from_static_string (query->nick);
225 g_mutex_lock (&mutex);
226 g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
227 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
229 _gst_queries = g_list_append (_gst_queries, query);
231 g_mutex_unlock (&mutex);
237 * gst_query_type_get_by_nick:
238 * @nick: The nick of the query
240 * Get the query type registered with @nick.
242 * Returns: The query registered with @nick or #GST_QUERY_NONE
243 * if the query was not registered.
246 gst_query_type_get_by_nick (const gchar * nick)
248 GstQueryTypeDefinition *query;
250 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
252 g_mutex_lock (&mutex);
253 query = g_hash_table_lookup (_nick_to_query, nick);
254 g_mutex_unlock (&mutex);
259 return GST_QUERY_NONE;
263 * gst_query_types_contains:
264 * @types: The query array to search
265 * @type: the #GstQueryType to find
267 * See if the given #GstQueryType is inside the @types query types array.
269 * Returns: TRUE if the type is found inside the array
272 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
288 * gst_query_type_get_details:
289 * @type: a #GstQueryType
291 * Get details about the given #GstQueryType.
293 * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
295 const GstQueryTypeDefinition *
296 gst_query_type_get_details (GstQueryType type)
298 const GstQueryTypeDefinition *result;
300 g_mutex_lock (&mutex);
301 result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
302 g_mutex_unlock (&mutex);
308 * gst_query_type_iterate_definitions:
310 * Get a #GstIterator of all the registered query types. The definitions
311 * iterated over are read only.
313 * Free-function: gst_iterator_free
315 * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
318 gst_query_type_iterate_definitions (void)
322 g_mutex_lock (&mutex);
323 /* FIXME: register a boxed type for GstQueryTypeDefinition */
324 result = gst_iterator_new_list (G_TYPE_POINTER,
325 &mutex, &_n_values, &_gst_queries, NULL, NULL);
326 g_mutex_unlock (&mutex);
332 _gst_query_free (GstQuery * query)
336 g_return_if_fail (query != NULL);
338 s = GST_QUERY_STRUCTURE (query);
340 gst_structure_set_parent_refcount (s, NULL);
341 gst_structure_free (s);
344 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
348 _gst_query_copy (GstQuery * query)
352 copy = gst_query_new_custom (query->type, GST_QUERY_STRUCTURE (query));
358 gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
360 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
362 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
363 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
365 GST_EVENT_TYPE (query) = type;
369 * gst_query_new_position:
370 * @format: the default #GstFormat for the new query
372 * Constructs a new query stream position query object. Use gst_query_unref()
373 * when done with it. A position query is used to query the current position
374 * of playback in the streams, in some format.
376 * Free-function: gst_query_unref
378 * Returns: (transfer full): a new #GstQuery
381 gst_query_new_position (GstFormat format)
384 GstStructure *structure;
386 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
387 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
388 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
390 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
396 * gst_query_set_position:
397 * @query: a #GstQuery with query type GST_QUERY_POSITION
398 * @format: the requested #GstFormat
399 * @cur: the position to set
401 * Answer a position query by setting the requested value in the given format.
404 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
408 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
410 s = GST_QUERY_STRUCTURE (query);
411 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
412 GST_QUARK (FORMAT))));
414 gst_structure_id_set (s,
415 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
416 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
420 * gst_query_parse_position:
421 * @query: a #GstQuery
422 * @format: (out) (allow-none): the storage for the #GstFormat of the
423 * position values (may be NULL)
424 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
426 * Parse a position query, writing the format into @format, and the position
427 * into @cur, if the respective parameters are non-NULL.
430 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
432 GstStructure *structure;
434 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
436 structure = GST_QUERY_STRUCTURE (query);
439 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
440 GST_QUARK (FORMAT)));
442 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
443 GST_QUARK (CURRENT)));
448 * gst_query_new_duration:
449 * @format: the #GstFormat for this duration query
451 * Constructs a new stream duration query object to query in the given format.
452 * Use gst_query_unref() when done with it. A duration query will give the
453 * total length of the stream.
455 * Free-function: gst_query_unref
457 * Returns: (transfer full): a new #GstQuery
460 gst_query_new_duration (GstFormat format)
463 GstStructure *structure;
465 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
466 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
467 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
469 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
475 * gst_query_set_duration:
476 * @query: a #GstQuery
477 * @format: the #GstFormat for the duration
478 * @duration: the duration of the stream
480 * Answer a duration query by setting the requested value in the given format.
483 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
487 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
489 s = GST_QUERY_STRUCTURE (query);
490 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
491 GST_QUARK (FORMAT))));
492 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
493 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
497 * gst_query_parse_duration:
498 * @query: a #GstQuery
499 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
501 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
503 * Parse a duration query answer. Write the format of the duration into @format,
504 * and the value into @duration, if the respective variables are non-NULL.
507 gst_query_parse_duration (GstQuery * query, GstFormat * format,
510 GstStructure *structure;
512 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
514 structure = GST_QUERY_STRUCTURE (query);
517 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
518 GST_QUARK (FORMAT)));
520 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
521 GST_QUARK (DURATION)));
525 * gst_query_new_latency:
527 * Constructs a new latency query object.
528 * Use gst_query_unref() when done with it. A latency query is usually performed
529 * by sinks to compensate for additional latency introduced by elements in the
532 * Free-function: gst_query_unref
534 * Returns: (transfer full): a #GstQuery
539 gst_query_new_latency (void)
542 GstStructure *structure;
544 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
545 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
546 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
547 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
549 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
555 * gst_query_set_latency:
556 * @query: a #GstQuery
557 * @live: if there is a live element upstream
558 * @min_latency: the minimal latency of the upstream elements
559 * @max_latency: the maximal latency of the upstream elements
561 * Answer a latency query by setting the requested values in the given format.
566 gst_query_set_latency (GstQuery * query, gboolean live,
567 GstClockTime min_latency, GstClockTime max_latency)
569 GstStructure *structure;
571 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
573 structure = GST_QUERY_STRUCTURE (query);
574 gst_structure_id_set (structure,
575 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
576 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
577 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
581 * gst_query_parse_latency:
582 * @query: a #GstQuery
583 * @live: (out) (allow-none): storage for live or NULL
584 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
585 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
587 * Parse a latency query answer.
592 gst_query_parse_latency (GstQuery * query, gboolean * live,
593 GstClockTime * min_latency, GstClockTime * max_latency)
595 GstStructure *structure;
597 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
599 structure = GST_QUERY_STRUCTURE (query);
602 g_value_get_boolean (gst_structure_id_get_value (structure,
605 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
606 GST_QUARK (MIN_LATENCY)));
608 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
609 GST_QUARK (MAX_LATENCY)));
613 * gst_query_new_convert:
614 * @src_format: the source #GstFormat for the new query
615 * @value: the value to convert
616 * @dest_format: the target #GstFormat
618 * Constructs a new convert query object. Use gst_query_unref()
619 * when done with it. A convert query is used to ask for a conversion between
620 * one format and another.
622 * Free-function: gst_query_unref
624 * Returns: (transfer full): a #GstQuery
627 gst_query_new_convert (GstFormat src_format, gint64 value,
628 GstFormat dest_format)
631 GstStructure *structure;
633 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
634 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
635 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
636 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
637 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
639 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
645 * gst_query_set_convert:
646 * @query: a #GstQuery
647 * @src_format: the source #GstFormat
648 * @src_value: the source value
649 * @dest_format: the destination #GstFormat
650 * @dest_value: the destination value
652 * Answer a convert query by setting the requested values.
655 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
656 GstFormat dest_format, gint64 dest_value)
658 GstStructure *structure;
660 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
662 structure = GST_QUERY_STRUCTURE (query);
663 gst_structure_id_set (structure,
664 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
665 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
666 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
667 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
671 * gst_query_parse_convert:
672 * @query: a #GstQuery
673 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
674 * source value, or NULL
675 * @src_value: (out) (allow-none): the storage for the source value, or NULL
676 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
677 * destination value, or NULL
678 * @dest_value: (out) (allow-none): the storage for the destination value,
681 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
682 * and @dest_value may be NULL, in which case that value is omitted.
685 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
686 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
688 GstStructure *structure;
690 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
692 structure = GST_QUERY_STRUCTURE (query);
695 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
696 GST_QUARK (SRC_FORMAT)));
698 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
699 GST_QUARK (SRC_VALUE)));
702 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
703 GST_QUARK (DEST_FORMAT)));
705 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
706 GST_QUARK (DEST_VALUE)));
710 * gst_query_new_segment:
711 * @format: the #GstFormat for the new query
713 * Constructs a new segment query object. Use gst_query_unref()
714 * when done with it. A segment query is used to discover information about the
715 * currently configured segment for playback.
717 * Free-function: gst_query_unref
719 * Returns: (transfer full): a new #GstQuery
722 gst_query_new_segment (GstFormat format)
725 GstStructure *structure;
727 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
728 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
729 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
730 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
731 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
733 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
739 * gst_query_set_segment:
740 * @query: a #GstQuery
741 * @rate: the rate of the segment
742 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
743 * @start_value: the start value
744 * @stop_value: the stop value
746 * Answer a segment query by setting the requested values. The normal
747 * playback segment of a pipeline is 0 to duration at the default rate of
748 * 1.0. If a seek was performed on the pipeline to play a different
749 * segment, this query will return the range specified in the last seek.
751 * @start_value and @stop_value will respectively contain the configured
752 * playback range start and stop values expressed in @format.
753 * The values are always between 0 and the duration of the media and
754 * @start_value <= @stop_value. @rate will contain the playback rate. For
755 * negative rates, playback will actually happen from @stop_value to
759 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
760 gint64 start_value, gint64 stop_value)
762 GstStructure *structure;
764 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
766 structure = GST_QUERY_STRUCTURE (query);
767 gst_structure_id_set (structure,
768 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
769 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
770 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
771 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
775 * gst_query_parse_segment:
776 * @query: a #GstQuery
777 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
778 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
780 * @start_value: (out) (allow-none): the storage for the start value, or NULL
781 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
783 * Parse a segment query answer. Any of @rate, @format, @start_value, and
784 * @stop_value may be NULL, which will cause this value to be omitted.
786 * See gst_query_set_segment() for an explanation of the function arguments.
789 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
790 gint64 * start_value, gint64 * stop_value)
792 GstStructure *structure;
794 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
796 structure = GST_QUERY_STRUCTURE (query);
798 *rate = g_value_get_double (gst_structure_id_get_value (structure,
802 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
803 GST_QUARK (FORMAT)));
805 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
806 GST_QUARK (START_VALUE)));
808 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
809 GST_QUARK (STOP_VALUE)));
813 * gst_query_new_custom:
814 * @type: the query type
815 * @structure: a structure for the query
817 * Constructs a new custom query object. Use gst_query_unref()
820 * Free-function: gst_query_unref
822 * Returns: (transfer full): a new #GstQuery
825 gst_query_new_custom (GstQueryType type, GstStructure * structure)
829 query = g_slice_new0 (GstQueryImpl);
831 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
834 /* structure must not have a parent */
835 if (!gst_structure_set_parent_refcount (structure,
836 &query->query.mini_object.refcount))
839 gst_query_init (query, sizeof (GstQueryImpl), type);
841 GST_QUERY_STRUCTURE (query) = structure;
843 return GST_QUERY_CAST (query);
848 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
849 g_warning ("structure is already owned by another object");
855 * gst_query_get_structure:
856 * @query: a #GstQuery
858 * Get the structure of a query.
860 * Returns: (transfer none): the #GstStructure of the query. The structure is
861 * still owned by the query and will therefore be freed when the query
865 gst_query_get_structure (GstQuery * query)
867 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
869 return GST_QUERY_STRUCTURE (query);
873 * gst_query_writable_structure:
874 * @query: a #GstQuery
876 * Get the structure of a query.
878 * Returns: (transfer none): the #GstStructure of the query. The structure is
879 * still owned by the query and will therefore be freed when the query
883 gst_query_writable_structure (GstQuery * query)
885 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
886 g_return_val_if_fail (gst_query_is_writable (query), NULL);
888 return GST_QUERY_STRUCTURE (query);
892 * gst_query_new_seeking:
893 * @format: the default #GstFormat for the new query
895 * Constructs a new query object for querying seeking properties of
898 * Free-function: gst_query_unref
900 * Returns: (transfer full): a new #GstQuery
903 gst_query_new_seeking (GstFormat format)
906 GstStructure *structure;
908 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
909 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
910 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
911 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
912 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
914 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
920 * gst_query_set_seeking:
921 * @query: a #GstQuery
922 * @format: the format to set for the @segment_start and @segment_end values
923 * @seekable: the seekable flag to set
924 * @segment_start: the segment_start to set
925 * @segment_end: the segment_end to set
927 * Set the seeking query result fields in @query.
930 gst_query_set_seeking (GstQuery * query, GstFormat format,
931 gboolean seekable, gint64 segment_start, gint64 segment_end)
933 GstStructure *structure;
935 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
936 g_return_if_fail (gst_query_is_writable (query));
938 structure = GST_QUERY_STRUCTURE (query);
939 gst_structure_id_set (structure,
940 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
941 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
942 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
943 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
947 * gst_query_parse_seeking:
948 * @query: a GST_QUERY_SEEKING type query #GstQuery
949 * @format: (out) (allow-none): the format to set for the @segment_start
950 * and @segment_end values, or NULL
951 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
952 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
953 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
955 * Parse a seeking query, writing the format into @format, and
956 * other results into the passed parameters, if the respective parameters
960 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
961 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
963 GstStructure *structure;
965 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
967 structure = GST_QUERY_STRUCTURE (query);
970 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
971 GST_QUARK (FORMAT)));
973 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
974 GST_QUARK (SEEKABLE)));
976 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
977 GST_QUARK (SEGMENT_START)));
979 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
980 GST_QUARK (SEGMENT_END)));
984 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
985 GDestroyNotify clear_func)
990 value = gst_structure_id_get_value (s, quark);
992 array = (GArray *) g_value_get_boxed (value);
994 GValue new_array_val = { 0, };
996 array = g_array_new (FALSE, TRUE, element_size);
998 g_array_set_clear_func (array, clear_func);
1000 g_value_init (&new_array_val, G_TYPE_ARRAY);
1001 g_value_take_boxed (&new_array_val, array);
1003 gst_structure_id_take_value (s, quark, &new_array_val);
1009 * gst_query_new_formats:
1011 * Constructs a new query object for querying formats of
1014 * Free-function: gst_query_unref
1016 * Returns: (transfer full): a new #GstQuery
1021 gst_query_new_formats (void)
1024 GstStructure *structure;
1026 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
1027 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
1033 gst_query_list_add_format (GValue * list, GstFormat format)
1035 GValue item = { 0, };
1037 g_value_init (&item, GST_TYPE_FORMAT);
1038 g_value_set_enum (&item, format);
1039 gst_value_list_append_value (list, &item);
1040 g_value_unset (&item);
1044 * gst_query_set_formats:
1045 * @query: a #GstQuery
1046 * @n_formats: the number of formats to set.
1047 * @...: A number of @GstFormats equal to @n_formats.
1049 * Set the formats query result fields in @query. The number of formats passed
1050 * must be equal to @n_formats.
1053 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1056 GValue list = { 0, };
1058 GstStructure *structure;
1060 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1061 g_return_if_fail (gst_query_is_writable (query));
1063 g_value_init (&list, GST_TYPE_LIST);
1065 va_start (ap, n_formats);
1066 for (i = 0; i < n_formats; i++) {
1067 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1071 structure = GST_QUERY_STRUCTURE (query);
1072 gst_structure_set_value (structure, "formats", &list);
1074 g_value_unset (&list);
1079 * gst_query_set_formatsv:
1080 * @query: a #GstQuery
1081 * @n_formats: the number of formats to set.
1082 * @formats: (in) (array length=n_formats): an array containing @n_formats
1083 * @GstFormat values.
1085 * Set the formats query result fields in @query. The number of formats passed
1086 * in the @formats array must be equal to @n_formats.
1091 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1092 const GstFormat * formats)
1094 GValue list = { 0, };
1096 GstStructure *structure;
1098 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1099 g_return_if_fail (gst_query_is_writable (query));
1101 g_value_init (&list, GST_TYPE_LIST);
1102 for (i = 0; i < n_formats; i++) {
1103 gst_query_list_add_format (&list, formats[i]);
1105 structure = GST_QUERY_STRUCTURE (query);
1106 gst_structure_set_value (structure, "formats", &list);
1108 g_value_unset (&list);
1112 * gst_query_parse_n_formats:
1113 * @query: a #GstQuery
1114 * @n_formats: (out) (allow-none): the number of formats in this query.
1116 * Parse the number of formats in the formats @query.
1121 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1123 GstStructure *structure;
1125 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1130 structure = GST_QUERY_STRUCTURE (query);
1131 list = gst_structure_get_value (structure, "formats");
1135 *n_formats = gst_value_list_get_size (list);
1140 * gst_query_parse_nth_format:
1141 * @query: a #GstQuery
1142 * @nth: (out): the nth format to retrieve.
1143 * @format: (out) (allow-none): a pointer to store the nth format
1145 * Parse the format query and retrieve the @nth format from it into
1146 * @format. If the list contains less elements than @nth, @format will be
1147 * set to GST_FORMAT_UNDEFINED.
1150 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1152 GstStructure *structure;
1154 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1159 structure = GST_QUERY_STRUCTURE (query);
1160 list = gst_structure_get_value (structure, "formats");
1162 *format = GST_FORMAT_UNDEFINED;
1164 if (nth < gst_value_list_get_size (list)) {
1166 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1168 *format = GST_FORMAT_UNDEFINED;
1174 * gst_query_new_buffering:
1175 * @format: the default #GstFormat for the new query
1177 * Constructs a new query object for querying the buffering status of
1180 * Free-function: gst_query_unref
1182 * Returns: (transfer full): a new #GstQuery
1187 gst_query_new_buffering (GstFormat format)
1190 GstStructure *structure;
1192 /* by default, we configure the answer as no buffering with a 100% buffering
1194 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1195 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1196 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1197 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1198 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1199 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1200 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1201 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1202 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1203 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1204 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1206 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1212 * gst_query_set_buffering_percent:
1213 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1214 * @busy: if buffering is busy
1215 * @percent: a buffering percent
1217 * Set the percentage of buffered data. This is a value between 0 and 100.
1218 * The @busy indicator is %TRUE when the buffering is in progress.
1223 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1225 GstStructure *structure;
1227 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1228 g_return_if_fail (gst_query_is_writable (query));
1229 g_return_if_fail (percent >= 0 && percent <= 100);
1231 structure = GST_QUERY_STRUCTURE (query);
1232 gst_structure_id_set (structure,
1233 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1234 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1238 * gst_query_parse_buffering_percent:
1239 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1240 * @busy: (out) (allow-none): if buffering is busy, or NULL
1241 * @percent: (out) (allow-none): a buffering percent, or NULL
1243 * Get the percentage of buffered data. This is a value between 0 and 100.
1244 * The @busy indicator is %TRUE when the buffering is in progress.
1249 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1252 GstStructure *structure;
1254 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1256 structure = GST_QUERY_STRUCTURE (query);
1258 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1261 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1262 GST_QUARK (BUFFER_PERCENT)));
1266 * gst_query_set_buffering_stats:
1267 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1268 * @mode: a buffering mode
1269 * @avg_in: the average input rate
1270 * @avg_out: the average output rate
1271 * @buffering_left: amount of buffering time left
1273 * Configures the buffering stats values in @query.
1278 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1279 gint avg_in, gint avg_out, gint64 buffering_left)
1281 GstStructure *structure;
1283 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1284 g_return_if_fail (gst_query_is_writable (query));
1286 structure = GST_QUERY_STRUCTURE (query);
1287 gst_structure_id_set (structure,
1288 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1289 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1290 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1291 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1295 * gst_query_parse_buffering_stats:
1296 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1297 * @mode: (out) (allow-none): a buffering mode, or NULL
1298 * @avg_in: (out) (allow-none): the average input rate, or NULL
1299 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1300 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1302 * Extracts the buffering stats values from @query.
1307 gst_query_parse_buffering_stats (GstQuery * query,
1308 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1309 gint64 * buffering_left)
1311 GstStructure *structure;
1313 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1315 structure = GST_QUERY_STRUCTURE (query);
1317 *mode = (GstBufferingMode)
1318 g_value_get_enum (gst_structure_id_get_value (structure,
1319 GST_QUARK (BUFFERING_MODE)));
1321 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1322 GST_QUARK (AVG_IN_RATE)));
1324 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1325 GST_QUARK (AVG_OUT_RATE)));
1328 g_value_get_int64 (gst_structure_id_get_value (structure,
1329 GST_QUARK (BUFFERING_LEFT)));
1333 * gst_query_set_buffering_range:
1334 * @query: a #GstQuery
1335 * @format: the format to set for the @start and @stop values
1336 * @start: the start to set
1337 * @stop: the stop to set
1338 * @estimated_total: estimated total amount of download time
1340 * Set the available query result fields in @query.
1345 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1346 gint64 start, gint64 stop, gint64 estimated_total)
1348 GstStructure *structure;
1350 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1351 g_return_if_fail (gst_query_is_writable (query));
1353 structure = GST_QUERY_STRUCTURE (query);
1354 gst_structure_id_set (structure,
1355 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1356 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1357 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1358 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1362 * gst_query_parse_buffering_range:
1363 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1364 * @format: (out) (allow-none): the format to set for the @segment_start
1365 * and @segment_end values, or NULL
1366 * @start: (out) (allow-none): the start to set, or NULL
1367 * @stop: (out) (allow-none): the stop to set, or NULL
1368 * @estimated_total: (out) (allow-none): estimated total amount of download
1371 * Parse an available query, writing the format into @format, and
1372 * other results into the passed parameters, if the respective parameters
1378 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1379 gint64 * start, gint64 * stop, gint64 * estimated_total)
1381 GstStructure *structure;
1383 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1385 structure = GST_QUERY_STRUCTURE (query);
1388 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1389 GST_QUARK (FORMAT)));
1391 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1392 GST_QUARK (START_VALUE)));
1394 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1395 GST_QUARK (STOP_VALUE)));
1396 if (estimated_total)
1398 g_value_get_int64 (gst_structure_id_get_value (structure,
1399 GST_QUARK (ESTIMATED_TOTAL)));
1403 * gst_query_add_buffering_range:
1404 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1405 * @start: start position of the range
1406 * @stop: stop position of the range
1408 * Set the buffering-ranges array field in @query. The current last
1409 * start position of the array should be inferior to @start.
1411 * Returns: a #gboolean indicating if the range was added or not.
1416 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1418 GstQueryBufferingRange range;
1419 GstStructure *structure;
1422 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1423 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1425 if (G_UNLIKELY (start >= stop))
1428 structure = GST_QUERY_STRUCTURE (query);
1429 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1430 sizeof (GstQueryBufferingRange), NULL);
1432 if (array->len > 1) {
1433 GstQueryBufferingRange *last;
1435 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1437 if (G_UNLIKELY (start <= last->start))
1441 range.start = start;
1443 g_array_append_val (array, range);
1449 * gst_query_get_n_buffering_ranges:
1450 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1452 * Retrieve the number of values currently stored in the
1453 * buffered-ranges array of the query's structure.
1455 * Returns: the range array size as a #guint.
1460 gst_query_get_n_buffering_ranges (GstQuery * query)
1462 GstStructure *structure;
1465 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1467 structure = GST_QUERY_STRUCTURE (query);
1468 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1469 sizeof (GstQueryBufferingRange), NULL);
1476 * gst_query_parse_nth_buffering_range:
1477 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1478 * @index: position in the buffered-ranges array to read
1479 * @start: (out) (allow-none): the start position to set, or NULL
1480 * @stop: (out) (allow-none): the stop position to set, or NULL
1482 * Parse an available query and get the start and stop values stored
1483 * at the @index of the buffered ranges array.
1485 * Returns: a #gboolean indicating if the parsing succeeded.
1490 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1491 gint64 * start, gint64 * stop)
1493 GstQueryBufferingRange *range;
1494 GstStructure *structure;
1497 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1499 structure = GST_QUERY_STRUCTURE (query);
1501 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1502 sizeof (GstQueryBufferingRange), NULL);
1503 g_return_val_if_fail (index < array->len, FALSE);
1505 range = &g_array_index (array, GstQueryBufferingRange, index);
1508 *start = range->start;
1510 *stop = range->stop;
1517 * gst_query_new_uri:
1519 * Constructs a new query URI query object. Use gst_query_unref()
1520 * when done with it. An URI query is used to query the current URI
1521 * that is used by the source or sink.
1523 * Free-function: gst_query_unref
1525 * Returns: (transfer full): a new #GstQuery
1530 gst_query_new_uri (void)
1533 GstStructure *structure;
1535 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1536 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1538 query = gst_query_new_custom (GST_QUERY_URI, structure);
1544 * gst_query_set_uri:
1545 * @query: a #GstQuery with query type GST_QUERY_URI
1546 * @uri: the URI to set
1548 * Answer a URI query by setting the requested URI.
1553 gst_query_set_uri (GstQuery * query, const gchar * uri)
1555 GstStructure *structure;
1557 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1558 g_return_if_fail (gst_query_is_writable (query));
1559 g_return_if_fail (gst_uri_is_valid (uri));
1561 structure = GST_QUERY_STRUCTURE (query);
1562 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1566 * gst_query_parse_uri:
1567 * @query: a #GstQuery
1568 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1571 * Parse an URI query, writing the URI into @uri as a newly
1572 * allocated string, if the respective parameters are non-NULL.
1573 * Free the string with g_free() after usage.
1578 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1580 GstStructure *structure;
1582 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1584 structure = GST_QUERY_STRUCTURE (query);
1586 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1591 * gst_query_new_allocation:
1592 * @caps: the negotiated caps
1593 * @need_pool: return a pool
1595 * Constructs a new query object for querying the allocation properties.
1597 * Free-function: gst_query_unref
1599 * Returns: (transfer full): a new #GstQuery
1602 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1605 GstStructure *structure;
1607 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1608 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1609 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1610 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1611 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1612 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1613 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1614 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1615 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1617 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1623 * gst_query_parse_allocation:
1624 * @query: a #GstQuery
1625 * @caps: (out callee-allocates) (allow-none): The #GstCaps
1626 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1628 * Parse an allocation query, writing the requested caps in @caps and
1629 * whether a pool is needed in @need_pool, if the respective parameters
1633 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1634 gboolean * need_pool)
1636 GstStructure *structure;
1638 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1640 structure = GST_QUERY_STRUCTURE (query);
1641 gst_structure_id_get (structure,
1642 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1643 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1647 * gst_query_set_allocation_params:
1648 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1650 * @min_buffers: the min buffers
1651 * @max_buffers: the max buffers
1652 * @prefix: the prefix
1653 * @alignment: the alignment
1654 * @pool: the #GstBufferPool
1656 * Set the allocation parameters in @query.
1659 gst_query_set_allocation_params (GstQuery * query, guint size,
1660 guint min_buffers, guint max_buffers, guint prefix,
1661 guint alignment, GstBufferPool * pool)
1663 GstStructure *structure;
1665 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1666 g_return_if_fail (gst_query_is_writable (query));
1667 g_return_if_fail (((alignment + 1) & alignment) == 0);
1668 g_return_if_fail (size != 0 || pool == NULL);
1670 structure = GST_QUERY_STRUCTURE (query);
1671 gst_structure_id_set (structure,
1672 GST_QUARK (SIZE), G_TYPE_UINT, size,
1673 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1674 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1675 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1676 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1677 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1681 * gst_query_parse_allocation_params:
1682 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1683 * @size: (out) (allow-none): the size
1684 * @min_buffers: (out) (allow-none): the min buffers
1685 * @max_buffers: (out) (allow-none): the max buffers
1686 * @prefix: (out) (allow-none): the prefix
1687 * @alignment: (out) (allow-none): the alignment
1688 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1690 * Get the allocation parameters in @query.
1693 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1694 guint * min_buffers, guint * max_buffers, guint * prefix,
1695 guint * alignment, GstBufferPool ** pool)
1697 GstStructure *structure;
1699 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1701 structure = GST_QUERY_STRUCTURE (query);
1702 gst_structure_id_get (structure,
1703 GST_QUARK (SIZE), G_TYPE_UINT, size,
1704 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1705 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1706 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1707 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1708 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1712 * gst_query_add_allocation_meta:
1713 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1714 * @api: the metadata API
1716 * Add @api as aone of the supported metadata API to @query.
1719 gst_query_add_allocation_meta (GstQuery * query, GType api)
1722 GstStructure *structure;
1724 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1725 g_return_if_fail (api != 0);
1726 g_return_if_fail (gst_query_is_writable (query));
1728 structure = GST_QUERY_STRUCTURE (query);
1729 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1731 g_array_append_val (array, api);
1735 * gst_query_get_n_allocation_metas:
1736 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1738 * Retrieve the number of values currently stored in the
1739 * meta API array of the query's structure.
1741 * Returns: the metadata API array size as a #guint.
1744 gst_query_get_n_allocation_metas (GstQuery * query)
1747 GstStructure *structure;
1749 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1751 structure = GST_QUERY_STRUCTURE (query);
1752 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), 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 #GType of the metadata API at @index.
1768 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1771 GstStructure *structure;
1773 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1775 structure = GST_QUERY_STRUCTURE (query);
1776 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1778 g_return_val_if_fail (index < array->len, 0);
1780 return g_array_index (array, GType, index);
1784 * gst_query_remove_nth_allocation_meta:
1785 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1786 * @index: position in the metadata API array to remove
1788 * Remove the metadata API at @index of the metadata API array.
1791 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1794 GstStructure *structure;
1796 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1797 g_return_if_fail (gst_query_is_writable (query));
1799 structure = GST_QUERY_STRUCTURE (query);
1800 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1801 g_return_if_fail (index < array->len);
1803 g_array_remove_index (array, index);
1807 * gst_query_has_allocation_meta:
1808 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1809 * @api: the metadata API
1811 * Check if @query has metadata @api set.
1813 * Returns: TRUE when @api is in the list of metadata.
1816 gst_query_has_allocation_meta (GstQuery * query, GType api)
1819 GstStructure *structure;
1822 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1823 g_return_val_if_fail (api != 0, FALSE);
1825 structure = GST_QUERY_STRUCTURE (query);
1826 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1829 for (i = 0; i < len; i++) {
1830 if (g_array_index (array, GType, i) == api)
1837 * gst_query_add_allocation_memory:
1838 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1839 * @allocator: the memory allocator
1841 * Add @allocator as a supported memory allocator.
1844 gst_query_add_allocation_memory (GstQuery * query, GstAllocator * allocator)
1847 GstStructure *structure;
1849 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1850 g_return_if_fail (gst_query_is_writable (query));
1851 g_return_if_fail (allocator != NULL);
1853 structure = GST_QUERY_STRUCTURE (query);
1855 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1856 (GDestroyNotify) gst_allocator_unref);
1858 g_array_append_val (array, allocator);
1862 * gst_query_get_n_allocation_memories:
1863 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1865 * Retrieve the number of values currently stored in the
1866 * allocator array of the query's structure.
1868 * If no memory allocator is specified, the downstream element can handle
1869 * the default memory allocator.
1871 * Returns: the allocator array size as a #guint.
1874 gst_query_get_n_allocation_memories (GstQuery * query)
1877 GstStructure *structure;
1879 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1881 structure = GST_QUERY_STRUCTURE (query);
1883 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1884 (GDestroyNotify) gst_allocator_unref);
1890 * gst_query_parse_nth_allocation_memory:
1891 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1892 * @index: position in the allocator array to read
1894 * Parse an available query and get the alloctor
1895 * at @index of the allocator array.
1897 * Returns: (transfer none): the allocator at @index. The allocator remains
1898 * valid for as long as @query is valid.
1901 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1904 GstStructure *structure;
1906 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1908 structure = GST_QUERY_STRUCTURE (query);
1910 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (GstAllocator *),
1911 (GDestroyNotify) gst_allocator_unref);
1912 g_return_val_if_fail (index < array->len, NULL);
1914 return g_array_index (array, GstAllocator *, index);
1918 * gst_query_new_scheduling:
1920 * Constructs a new query object for querying the scheduling properties.
1922 * Free-function: gst_query_unref
1924 * Returns: (transfer full): a new #GstQuery
1927 gst_query_new_scheduling (void)
1930 GstStructure *structure;
1932 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1933 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1934 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1935 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1936 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1937 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
1943 * gst_query_set_scheduling:
1944 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1945 * @flags: #GstSchedulingFlags
1946 * @minsize: the suggested minimum size of pull requests
1947 * @maxsize: the suggested maximum size of pull requests
1948 * @align: the suggested alignment of pull requests
1950 * Set the scheduling properties.
1953 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1954 gint minsize, gint maxsize, gint align)
1956 GstStructure *structure;
1958 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1959 g_return_if_fail (gst_query_is_writable (query));
1961 structure = GST_QUERY_STRUCTURE (query);
1962 gst_structure_id_set (structure,
1963 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1964 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1965 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1966 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1970 * gst_query_parse_scheduling:
1971 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1972 * @flags: (out) (allow-none): #GstSchedulingFlags
1973 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
1974 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
1975 * @align: (out) (allow-none): the suggested alignment of pull requests
1977 * Set the scheduling properties.
1980 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
1981 gint * minsize, gint * maxsize, gint * align)
1983 GstStructure *structure;
1985 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1987 structure = GST_QUERY_STRUCTURE (query);
1988 gst_structure_id_get (structure,
1989 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1990 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1991 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1992 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1996 * gst_query_add_scheduling_mode:
1997 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1998 * @mode: a #GstPadMode
2000 * Add @mode as aone of the supported scheduling modes to @query.
2003 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2005 GstStructure *structure;
2008 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2009 g_return_if_fail (gst_query_is_writable (query));
2011 structure = GST_QUERY_STRUCTURE (query);
2013 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2015 g_array_append_val (array, mode);
2019 * gst_query_get_n_scheduling_modes:
2020 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2022 * Retrieve the number of values currently stored in the
2023 * scheduling mode array of the query's structure.
2025 * Returns: the scheduling mode array size as a #guint.
2028 gst_query_get_n_scheduling_modes (GstQuery * query)
2031 GstStructure *structure;
2033 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2035 structure = GST_QUERY_STRUCTURE (query);
2037 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2043 * gst_query_parse_nth_scheduling_mode:
2044 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2045 * @index: position in the scheduling modes array to read
2047 * Parse an available query and get the scheduling mode
2048 * at @index of the scheduling modes array.
2050 * Returns: a #GstPadMode of the scheduling mode at @index.
2053 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2055 GstStructure *structure;
2058 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2061 structure = GST_QUERY_STRUCTURE (query);
2063 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2064 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2066 return g_array_index (array, GstPadMode, index);
2070 * gst_query_has_scheduling_mode:
2071 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2072 * @mode: the scheduling mode
2074 * Check if @query has scheduling mode set.
2076 * Returns: TRUE when @mode is in the list of scheduling modes.
2079 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2081 GstStructure *structure;
2085 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2087 structure = GST_QUERY_STRUCTURE (query);
2089 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2092 for (i = 0; i < len; i++) {
2093 if (mode == g_array_index (array, GstPadMode, i))
2100 * gst_query_new_accept_caps:
2103 * Constructs a new query object for querying if @caps are accepted.
2105 * Free-function: gst_query_unref
2107 * Returns: (transfer full): a new #GstQuery
2110 gst_query_new_accept_caps (GstCaps * caps)
2113 GstStructure *structure;
2115 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2116 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2117 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2118 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2124 * gst_query_parse_accept_caps:
2125 * @query: The query to parse
2126 * @caps: (out): A pointer to the caps
2128 * Get the caps from @query. The caps remains valid as long as @query remains
2132 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2134 GstStructure *structure;
2136 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2137 g_return_if_fail (caps != NULL);
2139 structure = GST_QUERY_STRUCTURE (query);
2140 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2145 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2147 GstStructure *structure;
2149 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2150 g_return_if_fail (gst_query_is_writable (query));
2152 structure = GST_QUERY_STRUCTURE (query);
2153 gst_structure_id_set (structure,
2154 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2158 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2160 GstStructure *structure;
2162 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2164 structure = GST_QUERY_STRUCTURE (query);
2165 gst_structure_id_get (structure,
2166 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2170 * gst_query_new_caps:
2173 * Constructs a new query object for querying the caps.
2175 * The CAPS query should return the* allowable caps for a pad in the context
2176 * of the element's state, its link to other elements, and the devices or files
2177 * it has opened. These caps must be a subset of the pad template caps. In the
2178 * NULL state with no links, the CAPS query should ideally return the same caps
2179 * as the pad template. In rare circumstances, an object property can affect
2180 * the caps returned by the CAPS query, but this is discouraged.
2182 * For most filters, the caps returned by CAPS query is directly affected by the
2183 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2184 * the srcpad's getcaps function is directly related to the stream data. Again,
2185 * the CAPS query should return the most specific caps it reasonably can, since this
2186 * helps with autoplugging.
2188 * Free-function: gst_query_unref
2190 * Returns: (transfer full): a new #GstQuery
2193 gst_query_new_caps (GstCaps * filter)
2196 GstStructure *structure;
2198 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2199 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2200 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2201 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2207 * gst_query_parse_caps:
2208 * @query: The query to parse
2209 * @filter: (out): A pointer to the caps filter
2211 * Get the filter from the caps @query. The caps remains valid as long as
2212 * @query remains valid.
2215 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2217 GstStructure *structure;
2219 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2220 g_return_if_fail (filter != NULL);
2222 structure = GST_QUERY_STRUCTURE (query);
2223 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2224 GST_QUARK (FILTER)));
2228 * gst_query_set_caps_result:
2229 * @query: The query to use
2230 * @caps: (in): A pointer to the caps
2232 * Set the @caps result in @query.
2235 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2237 GstStructure *structure;
2239 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2240 g_return_if_fail (gst_query_is_writable (query));
2242 structure = GST_QUERY_STRUCTURE (query);
2243 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2247 * gst_query_parse_caps_result:
2248 * @query: The query to parse
2249 * @caps: (out): A pointer to the caps
2251 * Get the caps result from @query. The caps remains valid as long as
2252 * @query remains valid.
2255 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2257 GstStructure *structure;
2259 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2260 g_return_if_fail (caps != NULL);
2262 structure = GST_QUERY_STRUCTURE (query);
2263 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2268 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2269 GstCapsIntersectMode mode)
2271 GstCaps *res, *caps = NULL;
2273 gst_query_parse_caps_result (query, &caps);
2274 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2275 gst_query_set_caps_result (query, res);
2276 gst_caps_unref (res);