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)
979 value = gst_structure_id_get_value (s, quark);
981 array = (GArray *) g_value_get_boxed (value);
983 GValue new_array_val = { 0, };
985 array = g_array_new (FALSE, TRUE, element_size);
987 g_value_init (&new_array_val, G_TYPE_ARRAY);
988 g_value_take_boxed (&new_array_val, array);
990 gst_structure_id_take_value (s, quark, &new_array_val);
996 * gst_query_new_formats:
998 * Constructs a new query object for querying formats of
1001 * Free-function: gst_query_unref
1003 * Returns: (transfer full): a new #GstQuery
1008 gst_query_new_formats (void)
1011 GstStructure *structure;
1013 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
1014 query = gst_query_new (GST_QUERY_FORMATS, structure);
1020 gst_query_list_add_format (GValue * list, GstFormat format)
1022 GValue item = { 0, };
1024 g_value_init (&item, GST_TYPE_FORMAT);
1025 g_value_set_enum (&item, format);
1026 gst_value_list_append_value (list, &item);
1027 g_value_unset (&item);
1031 * gst_query_set_formats:
1032 * @query: a #GstQuery
1033 * @n_formats: the number of formats to set.
1034 * @...: A number of @GstFormats equal to @n_formats.
1036 * Set the formats query result fields in @query. The number of formats passed
1037 * must be equal to @n_formats.
1040 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1043 GValue list = { 0, };
1045 GstStructure *structure;
1047 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1048 g_return_if_fail (gst_query_is_writable (query));
1050 g_value_init (&list, GST_TYPE_LIST);
1052 va_start (ap, n_formats);
1053 for (i = 0; i < n_formats; i++) {
1054 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1058 structure = GST_QUERY_STRUCTURE (query);
1059 gst_structure_set_value (structure, "formats", &list);
1061 g_value_unset (&list);
1066 * gst_query_set_formatsv:
1067 * @query: a #GstQuery
1068 * @n_formats: the number of formats to set.
1069 * @formats: (in) (array length=n_formats): an array containing @n_formats
1070 * @GstFormat values.
1072 * Set the formats query result fields in @query. The number of formats passed
1073 * in the @formats array must be equal to @n_formats.
1078 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1079 const GstFormat * formats)
1081 GValue list = { 0, };
1083 GstStructure *structure;
1085 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1086 g_return_if_fail (gst_query_is_writable (query));
1088 g_value_init (&list, GST_TYPE_LIST);
1089 for (i = 0; i < n_formats; i++) {
1090 gst_query_list_add_format (&list, formats[i]);
1092 structure = GST_QUERY_STRUCTURE (query);
1093 gst_structure_set_value (structure, "formats", &list);
1095 g_value_unset (&list);
1099 * gst_query_parse_n_formats:
1100 * @query: a #GstQuery
1101 * @n_formats: (out): the number of formats in this query.
1103 * Parse the number of formats in the formats @query.
1108 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1110 GstStructure *structure;
1112 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1117 structure = GST_QUERY_STRUCTURE (query);
1118 list = gst_structure_get_value (structure, "formats");
1122 *n_formats = gst_value_list_get_size (list);
1127 * gst_query_parse_nth_format:
1128 * @query: a #GstQuery
1129 * @nth: (out): the nth format to retrieve.
1130 * @format: (out): a pointer to store the nth format
1132 * Parse the format query and retrieve the @nth format from it into
1133 * @format. If the list contains less elements than @nth, @format will be
1134 * set to GST_FORMAT_UNDEFINED.
1137 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1139 GstStructure *structure;
1141 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1146 structure = GST_QUERY_STRUCTURE (query);
1147 list = gst_structure_get_value (structure, "formats");
1149 *format = GST_FORMAT_UNDEFINED;
1151 if (nth < gst_value_list_get_size (list)) {
1153 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1155 *format = GST_FORMAT_UNDEFINED;
1161 * gst_query_new_buffering:
1162 * @format: the default #GstFormat for the new query
1164 * Constructs a new query object for querying the buffering status of
1167 * Free-function: gst_query_unref
1169 * Returns: (transfer full): a new #GstQuery
1174 gst_query_new_buffering (GstFormat format)
1177 GstStructure *structure;
1179 /* by default, we configure the answer as no buffering with a 100% buffering
1181 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1182 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1183 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1184 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1185 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1186 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1187 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1188 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1189 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1190 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1191 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1193 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1199 * gst_query_set_buffering_percent:
1200 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1201 * @busy: if buffering is busy
1202 * @percent: a buffering percent
1204 * Set the percentage of buffered data. This is a value between 0 and 100.
1205 * The @busy indicator is %TRUE when the buffering is in progress.
1210 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1212 GstStructure *structure;
1214 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1215 g_return_if_fail (gst_query_is_writable (query));
1216 g_return_if_fail (percent >= 0 && percent <= 100);
1218 structure = GST_QUERY_STRUCTURE (query);
1219 gst_structure_id_set (structure,
1220 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1221 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1225 * gst_query_parse_buffering_percent:
1226 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1227 * @busy: (out) (allow-none): if buffering is busy, or NULL
1228 * @percent: (out) (allow-none): a buffering percent, or NULL
1230 * Get the percentage of buffered data. This is a value between 0 and 100.
1231 * The @busy indicator is %TRUE when the buffering is in progress.
1236 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1239 GstStructure *structure;
1241 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1243 structure = GST_QUERY_STRUCTURE (query);
1245 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1248 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1249 GST_QUARK (BUFFER_PERCENT)));
1253 * gst_query_set_buffering_stats:
1254 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1255 * @mode: a buffering mode
1256 * @avg_in: the average input rate
1257 * @avg_out: the average output rate
1258 * @buffering_left: amount of buffering time left
1260 * Configures the buffering stats values in @query.
1265 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1266 gint avg_in, gint avg_out, gint64 buffering_left)
1268 GstStructure *structure;
1270 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1271 g_return_if_fail (gst_query_is_writable (query));
1273 structure = GST_QUERY_STRUCTURE (query);
1274 gst_structure_id_set (structure,
1275 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1276 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1277 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1278 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1282 * gst_query_parse_buffering_stats:
1283 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1284 * @mode: (out) (allow-none): a buffering mode, or NULL
1285 * @avg_in: (out) (allow-none): the average input rate, or NULL
1286 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1287 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1289 * Extracts the buffering stats values from @query.
1294 gst_query_parse_buffering_stats (GstQuery * query,
1295 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1296 gint64 * buffering_left)
1298 GstStructure *structure;
1300 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1302 structure = GST_QUERY_STRUCTURE (query);
1304 *mode = (GstBufferingMode)
1305 g_value_get_enum (gst_structure_id_get_value (structure,
1306 GST_QUARK (BUFFERING_MODE)));
1308 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1309 GST_QUARK (AVG_IN_RATE)));
1311 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1312 GST_QUARK (AVG_OUT_RATE)));
1315 g_value_get_int64 (gst_structure_id_get_value (structure,
1316 GST_QUARK (BUFFERING_LEFT)));
1320 * gst_query_set_buffering_range:
1321 * @query: a #GstQuery
1322 * @format: the format to set for the @start and @stop values
1323 * @start: the start to set
1324 * @stop: the stop to set
1325 * @estimated_total: estimated total amount of download time
1327 * Set the available query result fields in @query.
1332 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1333 gint64 start, gint64 stop, gint64 estimated_total)
1335 GstStructure *structure;
1337 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1338 g_return_if_fail (gst_query_is_writable (query));
1340 structure = GST_QUERY_STRUCTURE (query);
1341 gst_structure_id_set (structure,
1342 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1343 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1344 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1345 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1349 * gst_query_parse_buffering_range:
1350 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1351 * @format: (out) (allow-none): the format to set for the @segment_start
1352 * and @segment_end values, or NULL
1353 * @start: (out) (allow-none): the start to set, or NULL
1354 * @stop: (out) (allow-none): the stop to set, or NULL
1355 * @estimated_total: (out) (allow-none): estimated total amount of download
1358 * Parse an available query, writing the format into @format, and
1359 * other results into the passed parameters, if the respective parameters
1365 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1366 gint64 * start, gint64 * stop, gint64 * estimated_total)
1368 GstStructure *structure;
1370 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1372 structure = GST_QUERY_STRUCTURE (query);
1375 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1376 GST_QUARK (FORMAT)));
1378 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1379 GST_QUARK (START_VALUE)));
1381 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1382 GST_QUARK (STOP_VALUE)));
1383 if (estimated_total)
1385 g_value_get_int64 (gst_structure_id_get_value (structure,
1386 GST_QUARK (ESTIMATED_TOTAL)));
1390 * gst_query_add_buffering_range:
1391 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1392 * @start: start position of the range
1393 * @stop: stop position of the range
1395 * Set the buffering-ranges array field in @query. The current last
1396 * start position of the array should be inferior to @start.
1398 * Returns: a #gboolean indicating if the range was added or not.
1403 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1405 GstQueryBufferingRange range;
1406 GstStructure *structure;
1409 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1410 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1412 if (G_UNLIKELY (start >= stop))
1415 structure = GST_QUERY_STRUCTURE (query);
1416 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1417 sizeof (GstQueryBufferingRange));
1419 if (array->len > 1) {
1420 GstQueryBufferingRange *last;
1422 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1424 if (G_UNLIKELY (start <= last->start))
1428 range.start = start;
1430 g_array_append_val (array, range);
1436 * gst_query_get_n_buffering_ranges:
1437 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1439 * Retrieve the number of values currently stored in the
1440 * buffered-ranges array of the query's structure.
1442 * Returns: the range array size as a #guint.
1447 gst_query_get_n_buffering_ranges (GstQuery * query)
1449 GstStructure *structure;
1452 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1454 structure = GST_QUERY_STRUCTURE (query);
1455 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1456 sizeof (GstQueryBufferingRange));
1463 * gst_query_parse_nth_buffering_range:
1464 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1465 * @index: position in the buffered-ranges array to read
1466 * @start: (out) (allow-none): the start position to set, or NULL
1467 * @stop: (out) (allow-none): the stop position to set, or NULL
1469 * Parse an available query and get the start and stop values stored
1470 * at the @index of the buffered ranges array.
1472 * Returns: a #gboolean indicating if the parsing succeeded.
1477 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1478 gint64 * start, gint64 * stop)
1480 GstQueryBufferingRange *range;
1481 GstStructure *structure;
1484 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1486 structure = GST_QUERY_STRUCTURE (query);
1488 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1489 sizeof (GstQueryBufferingRange));
1491 if (index >= array->len)
1494 range = &g_array_index (array, GstQueryBufferingRange, index);
1497 *start = range->start;
1499 *stop = range->stop;
1506 * gst_query_new_uri:
1508 * Constructs a new query URI query object. Use gst_query_unref()
1509 * when done with it. An URI query is used to query the current URI
1510 * that is used by the source or sink.
1512 * Free-function: gst_query_unref
1514 * Returns: (transfer full): a new #GstQuery
1519 gst_query_new_uri (void)
1522 GstStructure *structure;
1524 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1525 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1527 query = gst_query_new (GST_QUERY_URI, structure);
1533 * gst_query_set_uri:
1534 * @query: a #GstQuery with query type GST_QUERY_URI
1535 * @uri: the URI to set
1537 * Answer a URI query by setting the requested URI.
1542 gst_query_set_uri (GstQuery * query, const gchar * uri)
1544 GstStructure *structure;
1546 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1547 g_return_if_fail (gst_query_is_writable (query));
1548 g_return_if_fail (gst_uri_is_valid (uri));
1550 structure = GST_QUERY_STRUCTURE (query);
1551 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1555 * gst_query_parse_uri:
1556 * @query: a #GstQuery
1557 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1560 * Parse an URI query, writing the URI into @uri as a newly
1561 * allocated string, if the respective parameters are non-NULL.
1562 * Free the string with g_free() after usage.
1567 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1569 GstStructure *structure;
1571 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1573 structure = GST_QUERY_STRUCTURE (query);
1575 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1580 * gst_query_new_allocation:
1581 * @caps: the negotiated caps
1582 * @need_pool: return a pool
1584 * Constructs a new query object for querying the allocation properties.
1586 * Free-function: gst_query_unref
1588 * Returns: (transfer full): a new #GstQuery
1591 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1594 GstStructure *structure;
1596 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1597 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1598 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1599 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1600 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1601 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1602 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1603 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1604 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1606 query = gst_query_new (GST_QUERY_ALLOCATION, structure);
1612 * gst_query_parse_allocation:
1613 * @query: a #GstQuery
1614 * @caps: (out callee-allocates) (allow-none): The #GstCaps
1615 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1617 * Parse an allocation query, writing the requested caps in @caps and
1618 * whether a pool is needed in @need_pool, if the respective parameters
1622 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1623 gboolean * need_pool)
1625 GstStructure *structure;
1627 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1629 structure = GST_QUERY_STRUCTURE (query);
1630 gst_structure_id_get (structure,
1631 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1632 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1636 * gst_query_set_allocation_params:
1637 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1639 * @min_buffers: the min buffers
1640 * @max_buffers: the max buffers
1641 * @prefix: the prefix
1642 * @alignment: the alignment
1643 * @pool: the #GstBufferPool
1645 * Set the allocation parameters in @query.
1648 gst_query_set_allocation_params (GstQuery * query, guint size,
1649 guint min_buffers, guint max_buffers, guint prefix,
1650 guint alignment, GstBufferPool * pool)
1652 GstStructure *structure;
1654 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1655 g_return_if_fail (gst_query_is_writable (query));
1656 g_return_if_fail (((alignment + 1) & alignment) == 0);
1657 g_return_if_fail (size != 0 || pool == NULL);
1659 structure = GST_QUERY_STRUCTURE (query);
1660 gst_structure_id_set (structure,
1661 GST_QUARK (SIZE), G_TYPE_UINT, size,
1662 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1663 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1664 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1665 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1666 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1670 * gst_query_parse_allocation_params:
1671 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1673 * @min_buffers: the min buffers
1674 * @max_buffers: the max buffers
1675 * @prefix: the prefix
1676 * @alignment: the alignment
1677 * @pool: the #GstBufferPool
1679 * Get the allocation parameters in @query.
1682 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1683 guint * min_buffers, guint * max_buffers, guint * prefix,
1684 guint * alignment, GstBufferPool ** pool)
1686 GstStructure *structure;
1688 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1690 structure = GST_QUERY_STRUCTURE (query);
1691 gst_structure_id_get (structure,
1692 GST_QUARK (SIZE), G_TYPE_UINT, size,
1693 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1694 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1695 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1696 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1697 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1701 * gst_query_add_allocation_meta:
1702 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1703 * @api: the metadata API
1705 * Add @api as aone of the supported metadata API to @query.
1708 gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
1711 GstStructure *structure;
1713 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1714 g_return_if_fail (api != NULL);
1715 g_return_if_fail (gst_query_is_writable (query));
1717 structure = GST_QUERY_STRUCTURE (query);
1718 array = ensure_array (structure, GST_QUARK (META), sizeof (const gchar *));
1720 api = g_intern_string (api);
1721 g_array_append_val (array, api);
1725 * gst_query_get_n_allocation_metas:
1726 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1728 * Retrieve the number of values currently stored in the
1729 * meta API array of the query's structure.
1731 * Returns: the metadata API array size as a #guint.
1734 gst_query_get_n_allocation_metas (GstQuery * query)
1737 GstStructure *structure;
1739 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1741 structure = GST_QUERY_STRUCTURE (query);
1742 array = ensure_array (structure, GST_QUARK (META), sizeof (const gchar *));
1748 * gst_query_parse_nth_allocation_meta:
1749 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1750 * @index: position in the metadata API array to read
1752 * Parse an available query and get the metadata API
1753 * at @index of the metadata API array.
1755 * Returns: a #gchar of the metadata API at @index.
1758 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1761 const gchar *ret = NULL;
1762 GstStructure *structure;
1764 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1766 structure = GST_QUERY_STRUCTURE (query);
1767 array = ensure_array (structure, GST_QUARK (META), sizeof (const gchar *));
1769 if (index < array->len)
1770 ret = g_array_index (array, const gchar *, index);
1776 * gst_query_has_allocation_meta:
1777 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1778 * @api: the metadata API
1780 * Check if @query has metadata @api set.
1782 * Returns: TRUE when @api is in the list of metadata.
1785 gst_query_has_allocation_meta (GstQuery * query, const gchar * api)
1788 GstStructure *structure;
1791 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1792 g_return_val_if_fail (api != NULL, FALSE);
1794 structure = GST_QUERY_STRUCTURE (query);
1795 array = ensure_array (structure, GST_QUARK (META), sizeof (const gchar *));
1798 for (i = 0; i < len; i++) {
1799 if (strcmp (api, g_array_index (array, const gchar *, i)) == 0)
1806 * gst_query_add_allocation_memory:
1807 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1808 * @alloc: the memory allocator
1810 * Add @alloc as a supported memory allocator.
1813 gst_query_add_allocation_memory (GstQuery * query, const gchar * alloc)
1816 GstStructure *structure;
1818 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1819 g_return_if_fail (gst_query_is_writable (query));
1821 structure = GST_QUERY_STRUCTURE (query);
1823 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (const gchar *));
1825 alloc = g_intern_string (alloc);
1826 g_array_append_val (array, alloc);
1830 * gst_query_get_n_allocation_memories:
1831 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1833 * Retrieve the number of values currently stored in the
1834 * allocator array of the query's structure.
1836 * If no memory allocator is specified, the downstream element can handle
1837 * the default memory allocator.
1839 * Returns: the allocator array size as a #guint.
1842 gst_query_get_n_allocation_memories (GstQuery * query)
1845 GstStructure *structure;
1847 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1849 structure = GST_QUERY_STRUCTURE (query);
1851 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (const gchar *));
1857 * gst_query_parse_nth_allocation_memory:
1858 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1859 * @index: position in the allocator array to read
1861 * Parse an available query and get the alloctor
1862 * at @index of the allocator array.
1864 * Returns: the name of the allocator at @index.
1867 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1870 const gchar *ret = NULL;
1871 GstStructure *structure;
1873 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1875 structure = GST_QUERY_STRUCTURE (query);
1877 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (const gchar *));
1879 if (index < array->len)
1880 ret = g_array_index (array, const gchar *, index);
1886 * gst_query_new_scheduling:
1888 * Constructs a new query object for querying the scheduling properties.
1890 * Free-function: gst_query_unref
1892 * Returns: (transfer full): a new #GstQuery
1895 gst_query_new_scheduling (void)
1898 GstStructure *structure;
1900 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1901 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1902 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1903 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1904 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1905 query = gst_query_new (GST_QUERY_SCHEDULING, structure);
1911 * gst_query_set_scheduling:
1912 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1913 * @flags: #GstSchedulingFlags
1914 * @minsize: the suggested minimum size of pull requests
1915 * @maxsize: the suggested maximum size of pull requests
1916 * @align: the suggested alignment of pull requests
1918 * Set the scheduling properties.
1921 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1922 gint minsize, gint maxsize, gint align)
1924 GstStructure *structure;
1926 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1927 g_return_if_fail (gst_query_is_writable (query));
1929 structure = GST_QUERY_STRUCTURE (query);
1930 gst_structure_id_set (structure,
1931 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1932 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1933 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1934 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1938 * gst_query_parse_scheduling:
1939 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1940 * @flags: #GstSchedulingFlags
1941 * @minsize: the suggested minimum size of pull requests
1942 * @maxsize: the suggested maximum size of pull requests:
1943 * @align: the suggested alignment of pull requests
1945 * Set the scheduling properties.
1948 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
1949 gint * minsize, gint * maxsize, gint * align)
1951 GstStructure *structure;
1953 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1955 structure = GST_QUERY_STRUCTURE (query);
1956 gst_structure_id_get (structure,
1957 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1958 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1959 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1960 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1964 * gst_query_add_scheduling_mode:
1965 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1966 * @mode: a #GstPadMode
1968 * Add @mode as aone of the supported scheduling modes to @query.
1971 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
1973 GstStructure *structure;
1976 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1977 g_return_if_fail (gst_query_is_writable (query));
1979 structure = GST_QUERY_STRUCTURE (query);
1980 array = ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode));
1982 g_array_append_val (array, mode);
1986 * gst_query_get_n_scheduling_modes:
1987 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1989 * Retrieve the number of values currently stored in the
1990 * scheduling mode array of the query's structure.
1992 * Returns: the scheduling mode array size as a #guint.
1995 gst_query_get_n_scheduling_modes (GstQuery * query)
1998 GstStructure *structure;
2000 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2002 structure = GST_QUERY_STRUCTURE (query);
2003 array = ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode));
2009 * gst_query_parse_nth_scheduling_mode:
2010 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2011 * @index: position in the scheduling modes array to read
2013 * Parse an available query and get the scheduling mode
2014 * at @index of the scheduling modes array.
2016 * Returns: a #GstPadMode of the scheduling mode at @index.
2019 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2021 GstPadMode ret = GST_PAD_MODE_NONE;
2022 GstStructure *structure;
2025 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, ret);
2027 structure = GST_QUERY_STRUCTURE (query);
2028 array = ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode));
2030 if (index < array->len)
2031 ret = g_array_index (array, GstPadMode, index);
2037 * gst_query_has_scheduling_mode:
2038 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2039 * @mode: the scheduling mode
2041 * Check if @query has scheduling mode set.
2043 * Returns: TRUE when @mode is in the list of scheduling modes.
2046 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2048 GstStructure *structure;
2052 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2054 structure = GST_QUERY_STRUCTURE (query);
2055 array = ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode));
2058 for (i = 0; i < len; i++) {
2059 if (mode == g_array_index (array, GstPadMode, i))
2066 * gst_query_new_accept_caps:
2069 * Constructs a new query object for querying if @caps are accepted.
2071 * Free-function: gst_query_unref
2073 * Returns: (transfer full): a new #GstQuery
2076 gst_query_new_accept_caps (GstCaps * caps)
2079 GstStructure *structure;
2081 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2082 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2083 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2084 query = gst_query_new (GST_QUERY_ACCEPT_CAPS, structure);
2090 * gst_query_parse_accept_caps:
2091 * @query: The query to parse
2092 * @caps: (out): A pointer to the caps
2094 * Get the caps from @query. The caps remains valid as long as @query remains
2098 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2100 GstStructure *structure;
2102 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2104 structure = GST_QUERY_STRUCTURE (query);
2105 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2110 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2112 GstStructure *structure;
2114 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2115 g_return_if_fail (gst_query_is_writable (query));
2117 structure = GST_QUERY_STRUCTURE (query);
2118 gst_structure_id_set (structure,
2119 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2123 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2125 GstStructure *structure;
2127 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2129 structure = GST_QUERY_STRUCTURE (query);
2130 gst_structure_id_get (structure,
2131 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2135 * gst_query_new_caps:
2138 * Constructs a new query object for querying the caps.
2140 * The CAPS query should return the* allowable caps for a pad in the context
2141 * of the element's state, its link to other elements, and the devices or files
2142 * it has opened. These caps must be a subset of the pad template caps. In the
2143 * NULL state with no links, the CAPS query should ideally return the same caps
2144 * as the pad template. In rare circumstances, an object property can affect
2145 * the caps returned by the CAPS query, but this is discouraged.
2147 * For most filters, the caps returned by CAPS query is directly affected by the
2148 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2149 * the srcpad's getcaps function is directly related to the stream data. Again,
2150 * the CAPS query should return the most specific caps it reasonably can, since this
2151 * helps with autoplugging.
2153 * Free-function: gst_query_unref
2155 * Returns: (transfer full): a new #GstQuery
2158 gst_query_new_caps (GstCaps * filter)
2161 GstStructure *structure;
2163 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2164 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2165 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2166 query = gst_query_new (GST_QUERY_CAPS, structure);
2172 * gst_query_parse_caps:
2173 * @query: The query to parse
2174 * @filter: (out): A pointer to the caps filter
2176 * Get the filter from the caps @query. The caps remains valid as long as
2177 * @query remains valid.
2180 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2182 GstStructure *structure;
2184 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2186 structure = GST_QUERY_STRUCTURE (query);
2187 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2188 GST_QUARK (FILTER)));
2192 * gst_query_set_caps_result:
2193 * @query: The query to use
2194 * @caps: (in): A pointer to the caps
2196 * Set the @caps result in @query.
2199 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2201 GstStructure *structure;
2203 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2204 g_return_if_fail (gst_query_is_writable (query));
2206 structure = GST_QUERY_STRUCTURE (query);
2207 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2211 * gst_query_parse_caps_result:
2212 * @query: The query to parse
2213 * @caps: (out): A pointer to the caps
2215 * Get the caps result from @query. The caps remains valid as long as
2216 * @query remains valid.
2219 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2221 GstStructure *structure;
2223 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2225 structure = GST_QUERY_STRUCTURE (query);
2226 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2231 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2232 GstCapsIntersectMode mode)
2234 GstCaps *res, *caps = NULL;
2236 gst_query_parse_caps_result (query, &caps);
2237 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2238 gst_query_set_caps_result (query, res);
2239 gst_caps_unref (res);