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 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
88 static GList *_gst_queries = NULL;
89 static GHashTable *_nick_to_query = NULL;
90 static GHashTable *_query_type_to_nick = NULL;
91 static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */
93 static GstQueryTypeDefinition standard_definitions[] = {
94 {GST_QUERY_POSITION, "position", "Current position", 0},
95 {GST_QUERY_DURATION, "duration", "Total duration", 0},
96 {GST_QUERY_LATENCY, "latency", "Latency", 0},
97 {GST_QUERY_JITTER, "jitter", "Jitter", 0},
98 {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
99 {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
100 {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
101 {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
102 {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
103 {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
104 {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
105 {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
106 {GST_QUERY_ALLOCATION, "allocation", "Allocation properties", 0},
107 {GST_QUERY_SCHEDULING, "scheduling", "Scheduling properties", 0},
108 {GST_QUERY_ACCEPT_CAPS, "accept-caps", "Accept caps", 0},
109 {GST_QUERY_CAPS, "caps", "Caps", 0},
110 {GST_QUERY_NONE, NULL, NULL, 0}
113 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
116 _priv_gst_query_initialize (void)
118 GstQueryTypeDefinition *standards = standard_definitions;
120 GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
122 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
124 g_static_mutex_lock (&mutex);
125 if (_nick_to_query == NULL) {
126 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
127 _query_type_to_nick = g_hash_table_new (NULL, NULL);
130 while (standards->nick) {
131 standards->quark = g_quark_from_static_string (standards->nick);
132 g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
133 g_hash_table_insert (_query_type_to_nick,
134 GINT_TO_POINTER (standards->value), standards);
136 _gst_queries = g_list_append (_gst_queries, standards);
140 g_static_mutex_unlock (&mutex);
142 _gst_query_type = gst_query_get_type ();
146 * gst_query_type_get_name:
147 * @query: the query type
149 * Get a printable name for the given query type. Do not modify or free.
151 * Returns: a reference to the static name of the query.
154 gst_query_type_get_name (GstQueryType query)
156 const GstQueryTypeDefinition *def;
158 def = gst_query_type_get_details (query);
159 g_return_val_if_fail (def != NULL, NULL);
165 * gst_query_type_to_quark:
166 * @query: the query type
168 * Get the unique quark for the given query type.
170 * Returns: the quark associated with the query type
173 gst_query_type_to_quark (GstQueryType query)
175 const GstQueryTypeDefinition *def;
177 def = gst_query_type_get_details (query);
178 g_return_val_if_fail (def != NULL, 0);
184 * gst_query_type_register:
185 * @nick: The nick of the new query
186 * @description: The description of the new query
188 * Create a new GstQueryType based on the nick or return an
189 * already registered query with that nick
191 * Returns: A new GstQueryType or an already registered query
192 * with the same nick.
195 gst_query_type_register (const gchar * nick, const gchar * description)
197 GstQueryTypeDefinition *query;
200 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
201 g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
203 lookup = gst_query_type_get_by_nick (nick);
204 if (lookup != GST_QUERY_NONE)
207 query = g_slice_new (GstQueryTypeDefinition);
208 query->value = (GstQueryType) _n_values;
209 query->nick = g_strdup (nick);
210 query->description = g_strdup (description);
211 query->quark = g_quark_from_static_string (query->nick);
213 g_static_mutex_lock (&mutex);
214 g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
215 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
217 _gst_queries = g_list_append (_gst_queries, query);
219 g_static_mutex_unlock (&mutex);
225 * gst_query_type_get_by_nick:
226 * @nick: The nick of the query
228 * Get the query type registered with @nick.
230 * Returns: The query registered with @nick or #GST_QUERY_NONE
231 * if the query was not registered.
234 gst_query_type_get_by_nick (const gchar * nick)
236 GstQueryTypeDefinition *query;
238 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
240 g_static_mutex_lock (&mutex);
241 query = g_hash_table_lookup (_nick_to_query, nick);
242 g_static_mutex_unlock (&mutex);
247 return GST_QUERY_NONE;
251 * gst_query_types_contains:
252 * @types: The query array to search
253 * @type: the #GstQueryType to find
255 * See if the given #GstQueryType is inside the @types query types array.
257 * Returns: TRUE if the type is found inside the array
260 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
276 * gst_query_type_get_details:
277 * @type: a #GstQueryType
279 * Get details about the given #GstQueryType.
281 * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
283 const GstQueryTypeDefinition *
284 gst_query_type_get_details (GstQueryType type)
286 const GstQueryTypeDefinition *result;
288 g_static_mutex_lock (&mutex);
289 result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
290 g_static_mutex_unlock (&mutex);
296 * gst_query_type_iterate_definitions:
298 * Get a #GstIterator of all the registered query types. The definitions
299 * iterated over are read only.
301 * Free-function: gst_iterator_free
303 * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
306 gst_query_type_iterate_definitions (void)
310 g_static_mutex_lock (&mutex);
311 /* FIXME: register a boxed type for GstQueryTypeDefinition */
312 result = gst_iterator_new_list (G_TYPE_POINTER,
313 g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries, NULL, NULL);
314 g_static_mutex_unlock (&mutex);
320 _gst_query_free (GstQuery * query)
324 g_return_if_fail (query != NULL);
326 s = GST_QUERY_STRUCTURE (query);
328 gst_structure_set_parent_refcount (s, NULL);
329 gst_structure_free (s);
332 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
335 static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
338 _gst_query_copy (GstQuery * query)
342 copy = gst_query_new (query->type, GST_QUERY_STRUCTURE (query));
348 gst_query_new (GstQueryType type, GstStructure * structure)
352 query = g_slice_new0 (GstQueryImpl);
354 gst_mini_object_init (GST_MINI_OBJECT_CAST (query),
355 _gst_query_type, sizeof (GstQueryImpl));
357 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
358 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
360 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
362 GST_QUERY_TYPE (query) = type;
363 query->structure = structure;
366 gst_structure_set_parent_refcount (structure,
367 &query->query.mini_object.refcount);
369 return GST_QUERY_CAST (query);
373 * gst_query_new_position:
374 * @format: the default #GstFormat for the new query
376 * Constructs a new query stream position query object. Use gst_query_unref()
377 * when done with it. A position query is used to query the current position
378 * of playback in the streams, in some format.
380 * Free-function: gst_query_unref
382 * Returns: (transfer full): a new #GstQuery
385 gst_query_new_position (GstFormat format)
388 GstStructure *structure;
390 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
391 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
392 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
394 query = gst_query_new (GST_QUERY_POSITION, structure);
400 * gst_query_set_position:
401 * @query: a #GstQuery with query type GST_QUERY_POSITION
402 * @format: the requested #GstFormat
403 * @cur: the position to set
405 * Answer a position query by setting the requested value in the given format.
408 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
412 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
414 s = GST_QUERY_STRUCTURE (query);
415 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
416 GST_QUARK (FORMAT))));
418 gst_structure_id_set (s,
419 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
420 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
424 * gst_query_parse_position:
425 * @query: a #GstQuery
426 * @format: (out) (allow-none): the storage for the #GstFormat of the
427 * position values (may be NULL)
428 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
430 * Parse a position query, writing the format into @format, and the position
431 * into @cur, if the respective parameters are non-NULL.
434 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
436 GstStructure *structure;
438 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
440 structure = GST_QUERY_STRUCTURE (query);
443 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
444 GST_QUARK (FORMAT)));
446 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
447 GST_QUARK (CURRENT)));
452 * gst_query_new_duration:
453 * @format: the #GstFormat for this duration query
455 * Constructs a new stream duration query object to query in the given format.
456 * Use gst_query_unref() when done with it. A duration query will give the
457 * total length of the stream.
459 * Free-function: gst_query_unref
461 * Returns: (transfer full): a new #GstQuery
464 gst_query_new_duration (GstFormat format)
467 GstStructure *structure;
469 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
470 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
471 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
473 query = gst_query_new (GST_QUERY_DURATION, structure);
479 * gst_query_set_duration:
480 * @query: a #GstQuery
481 * @format: the #GstFormat for the duration
482 * @duration: the duration of the stream
484 * Answer a duration query by setting the requested value in the given format.
487 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
491 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
493 s = GST_QUERY_STRUCTURE (query);
494 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
495 GST_QUARK (FORMAT))));
496 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
497 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
501 * gst_query_parse_duration:
502 * @query: a #GstQuery
503 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
505 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
507 * Parse a duration query answer. Write the format of the duration into @format,
508 * and the value into @duration, if the respective variables are non-NULL.
511 gst_query_parse_duration (GstQuery * query, GstFormat * format,
514 GstStructure *structure;
516 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
518 structure = GST_QUERY_STRUCTURE (query);
521 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
522 GST_QUARK (FORMAT)));
524 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
525 GST_QUARK (DURATION)));
529 * gst_query_new_latency:
531 * Constructs a new latency query object.
532 * Use gst_query_unref() when done with it. A latency query is usually performed
533 * by sinks to compensate for additional latency introduced by elements in the
536 * Free-function: gst_query_unref
538 * Returns: (transfer full): a #GstQuery
543 gst_query_new_latency (void)
546 GstStructure *structure;
548 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
549 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
550 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
551 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
553 query = gst_query_new (GST_QUERY_LATENCY, structure);
559 * gst_query_set_latency:
560 * @query: a #GstQuery
561 * @live: if there is a live element upstream
562 * @min_latency: the minimal latency of the live element
563 * @max_latency: the maximal latency of the live element
565 * Answer a latency query by setting the requested values in the given format.
570 gst_query_set_latency (GstQuery * query, gboolean live,
571 GstClockTime min_latency, GstClockTime max_latency)
573 GstStructure *structure;
575 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
577 structure = GST_QUERY_STRUCTURE (query);
578 gst_structure_id_set (structure,
579 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
580 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
581 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
585 * gst_query_parse_latency:
586 * @query: a #GstQuery
587 * @live: (out) (allow-none): storage for live or NULL
588 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
589 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
591 * Parse a latency query answer.
596 gst_query_parse_latency (GstQuery * query, gboolean * live,
597 GstClockTime * min_latency, GstClockTime * max_latency)
599 GstStructure *structure;
601 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
603 structure = GST_QUERY_STRUCTURE (query);
606 g_value_get_boolean (gst_structure_id_get_value (structure,
609 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
610 GST_QUARK (MIN_LATENCY)));
612 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
613 GST_QUARK (MAX_LATENCY)));
617 * gst_query_new_convert:
618 * @src_format: the source #GstFormat for the new query
619 * @value: the value to convert
620 * @dest_format: the target #GstFormat
622 * Constructs a new convert query object. Use gst_query_unref()
623 * when done with it. A convert query is used to ask for a conversion between
624 * one format and another.
626 * Free-function: gst_query_unref
628 * Returns: (transfer full): a #GstQuery
631 gst_query_new_convert (GstFormat src_format, gint64 value,
632 GstFormat dest_format)
635 GstStructure *structure;
637 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
638 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
639 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
640 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
641 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
643 query = gst_query_new (GST_QUERY_CONVERT, structure);
649 * gst_query_set_convert:
650 * @query: a #GstQuery
651 * @src_format: the source #GstFormat
652 * @src_value: the source value
653 * @dest_format: the destination #GstFormat
654 * @dest_value: the destination value
656 * Answer a convert query by setting the requested values.
659 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
660 GstFormat dest_format, gint64 dest_value)
662 GstStructure *structure;
664 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
666 structure = GST_QUERY_STRUCTURE (query);
667 gst_structure_id_set (structure,
668 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
669 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
670 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
671 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
675 * gst_query_parse_convert:
676 * @query: a #GstQuery
677 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
678 * source value, or NULL
679 * @src_value: (out) (allow-none): the storage for the source value, or NULL
680 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
681 * destination value, or NULL
682 * @dest_value: (out) (allow-none): the storage for the destination value,
685 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
686 * and @dest_value may be NULL, in which case that value is omitted.
689 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
690 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
692 GstStructure *structure;
694 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
696 structure = GST_QUERY_STRUCTURE (query);
699 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
700 GST_QUARK (SRC_FORMAT)));
702 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
703 GST_QUARK (SRC_VALUE)));
706 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
707 GST_QUARK (DEST_FORMAT)));
709 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
710 GST_QUARK (DEST_VALUE)));
714 * gst_query_new_segment:
715 * @format: the #GstFormat for the new query
717 * Constructs a new segment query object. Use gst_query_unref()
718 * when done with it. A segment query is used to discover information about the
719 * currently configured segment for playback.
721 * Free-function: gst_query_unref
723 * Returns: (transfer full): a new #GstQuery
726 gst_query_new_segment (GstFormat format)
729 GstStructure *structure;
731 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
732 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
733 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
734 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
735 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
737 query = gst_query_new (GST_QUERY_SEGMENT, structure);
743 * gst_query_set_segment:
744 * @query: a #GstQuery
745 * @rate: the rate of the segment
746 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
747 * @start_value: the start value
748 * @stop_value: the stop value
750 * Answer a segment query by setting the requested values. The normal
751 * playback segment of a pipeline is 0 to duration at the default rate of
752 * 1.0. If a seek was performed on the pipeline to play a different
753 * segment, this query will return the range specified in the last seek.
755 * @start_value and @stop_value will respectively contain the configured
756 * playback range start and stop values expressed in @format.
757 * The values are always between 0 and the duration of the media and
758 * @start_value <= @stop_value. @rate will contain the playback rate. For
759 * negative rates, playback will actually happen from @stop_value to
763 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
764 gint64 start_value, gint64 stop_value)
766 GstStructure *structure;
768 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
770 structure = GST_QUERY_STRUCTURE (query);
771 gst_structure_id_set (structure,
772 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
773 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
774 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
775 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
779 * gst_query_parse_segment:
780 * @query: a #GstQuery
781 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
782 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
784 * @start_value: (out) (allow-none): the storage for the start value, or NULL
785 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
787 * Parse a segment query answer. Any of @rate, @format, @start_value, and
788 * @stop_value may be NULL, which will cause this value to be omitted.
790 * See gst_query_set_segment() for an explanation of the function arguments.
793 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
794 gint64 * start_value, gint64 * stop_value)
796 GstStructure *structure;
798 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
800 structure = GST_QUERY_STRUCTURE (query);
802 *rate = g_value_get_double (gst_structure_id_get_value (structure,
806 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
807 GST_QUARK (FORMAT)));
809 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
810 GST_QUARK (START_VALUE)));
812 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
813 GST_QUARK (STOP_VALUE)));
817 * gst_query_new_custom:
818 * @type: the query type
819 * @structure: a structure for the query
821 * Constructs a new custom query object. Use gst_query_unref()
824 * Free-function: gst_query_unref
826 * Returns: (transfer full): a new #GstQuery
829 gst_query_new_custom (GstQueryType type, GstStructure * structure)
831 g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
832 g_return_val_if_fail (structure != NULL, NULL);
834 return gst_query_new (type, structure);
838 * gst_query_get_structure:
839 * @query: a #GstQuery
841 * Get the structure of a query.
843 * Returns: (transfer none): the #GstStructure of the query. The structure is
844 * still owned by the query and will therefore be freed when the query
848 gst_query_get_structure (GstQuery * query)
850 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
852 return GST_QUERY_STRUCTURE (query);
856 * gst_query_writable_structure:
857 * @query: a #GstQuery
859 * Get the structure of a query.
861 * Returns: (transfer none): the #GstStructure of the query. The structure is
862 * still owned by the query and will therefore be freed when the query
866 gst_query_writable_structure (GstQuery * query)
868 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
869 g_return_val_if_fail (gst_query_is_writable (query), NULL);
871 return GST_QUERY_STRUCTURE (query);
875 * gst_query_new_seeking:
876 * @format: the default #GstFormat for the new query
878 * Constructs a new query object for querying seeking properties of
881 * Free-function: gst_query_unref
883 * Returns: (transfer full): a new #GstQuery
886 gst_query_new_seeking (GstFormat format)
889 GstStructure *structure;
891 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
892 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
893 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
894 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
895 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
897 query = gst_query_new (GST_QUERY_SEEKING, structure);
903 * gst_query_set_seeking:
904 * @query: a #GstQuery
905 * @format: the format to set for the @segment_start and @segment_end values
906 * @seekable: the seekable flag to set
907 * @segment_start: the segment_start to set
908 * @segment_end: the segment_end to set
910 * Set the seeking query result fields in @query.
913 gst_query_set_seeking (GstQuery * query, GstFormat format,
914 gboolean seekable, gint64 segment_start, gint64 segment_end)
916 GstStructure *structure;
918 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
919 g_return_if_fail (gst_query_is_writable (query));
921 structure = GST_QUERY_STRUCTURE (query);
922 gst_structure_id_set (structure,
923 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
924 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
925 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
926 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
930 * gst_query_parse_seeking:
931 * @query: a GST_QUERY_SEEKING type query #GstQuery
932 * @format: (out) (allow-none): the format to set for the @segment_start
933 * and @segment_end values, or NULL
934 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
935 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
936 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
938 * Parse a seeking query, writing the format into @format, and
939 * other results into the passed parameters, if the respective parameters
943 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
944 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
946 GstStructure *structure;
948 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
950 structure = GST_QUERY_STRUCTURE (query);
953 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
954 GST_QUARK (FORMAT)));
956 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
957 GST_QUARK (SEEKABLE)));
959 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
960 GST_QUARK (SEGMENT_START)));
962 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
963 GST_QUARK (SEGMENT_END)));
967 ensure_array (GstStructure * s, GQuark quark)
972 value = gst_structure_id_get_value (s, quark);
974 array = (GValueArray *) g_value_get_boxed (value);
976 GValue new_array_val = { 0, };
978 array = g_value_array_new (0);
980 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
981 g_value_take_boxed (&new_array_val, array);
983 gst_structure_id_take_value (s, quark, &new_array_val);
989 * gst_query_new_formats:
991 * Constructs a new query object for querying formats of
994 * Free-function: gst_query_unref
996 * Returns: (transfer full): a new #GstQuery
1001 gst_query_new_formats (void)
1004 GstStructure *structure;
1006 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
1007 query = gst_query_new (GST_QUERY_FORMATS, structure);
1013 gst_query_list_add_format (GValue * list, GstFormat format)
1015 GValue item = { 0, };
1017 g_value_init (&item, GST_TYPE_FORMAT);
1018 g_value_set_enum (&item, format);
1019 gst_value_list_append_value (list, &item);
1020 g_value_unset (&item);
1024 * gst_query_set_formats:
1025 * @query: a #GstQuery
1026 * @n_formats: the number of formats to set.
1027 * @...: A number of @GstFormats equal to @n_formats.
1029 * Set the formats query result fields in @query. The number of formats passed
1030 * must be equal to @n_formats.
1033 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1036 GValue list = { 0, };
1038 GstStructure *structure;
1040 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1041 g_return_if_fail (gst_query_is_writable (query));
1043 g_value_init (&list, GST_TYPE_LIST);
1045 va_start (ap, n_formats);
1046 for (i = 0; i < n_formats; i++) {
1047 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1051 structure = GST_QUERY_STRUCTURE (query);
1052 gst_structure_set_value (structure, "formats", &list);
1054 g_value_unset (&list);
1059 * gst_query_set_formatsv:
1060 * @query: a #GstQuery
1061 * @n_formats: the number of formats to set.
1062 * @formats: (in) (array length=n_formats): an array containing @n_formats
1063 * @GstFormat values.
1065 * Set the formats query result fields in @query. The number of formats passed
1066 * in the @formats array must be equal to @n_formats.
1071 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1072 const GstFormat * formats)
1074 GValue list = { 0, };
1076 GstStructure *structure;
1078 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1079 g_return_if_fail (gst_query_is_writable (query));
1081 g_value_init (&list, GST_TYPE_LIST);
1082 for (i = 0; i < n_formats; i++) {
1083 gst_query_list_add_format (&list, formats[i]);
1085 structure = GST_QUERY_STRUCTURE (query);
1086 gst_structure_set_value (structure, "formats", &list);
1088 g_value_unset (&list);
1092 * gst_query_parse_n_formats:
1093 * @query: a #GstQuery
1094 * @n_formats: (out): the number of formats in this query.
1096 * Parse the number of formats in the formats @query.
1101 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1103 GstStructure *structure;
1105 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1110 structure = GST_QUERY_STRUCTURE (query);
1111 list = gst_structure_get_value (structure, "formats");
1115 *n_formats = gst_value_list_get_size (list);
1120 * gst_query_parse_nth_format:
1121 * @query: a #GstQuery
1122 * @nth: (out): the nth format to retrieve.
1123 * @format: (out): a pointer to store the nth format
1125 * Parse the format query and retrieve the @nth format from it into
1126 * @format. If the list contains less elements than @nth, @format will be
1127 * set to GST_FORMAT_UNDEFINED.
1130 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1132 GstStructure *structure;
1134 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1139 structure = GST_QUERY_STRUCTURE (query);
1140 list = gst_structure_get_value (structure, "formats");
1142 *format = GST_FORMAT_UNDEFINED;
1144 if (nth < gst_value_list_get_size (list)) {
1146 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1148 *format = GST_FORMAT_UNDEFINED;
1154 * gst_query_new_buffering:
1155 * @format: the default #GstFormat for the new query
1157 * Constructs a new query object for querying the buffering status of
1160 * Free-function: gst_query_unref
1162 * Returns: (transfer full): a new #GstQuery
1167 gst_query_new_buffering (GstFormat format)
1170 GstStructure *structure;
1172 /* by default, we configure the answer as no buffering with a 100% buffering
1174 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1175 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1176 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1177 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1178 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1179 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1180 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1181 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1182 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1183 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1184 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1186 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1192 * gst_query_set_buffering_percent:
1193 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1194 * @busy: if buffering is busy
1195 * @percent: a buffering percent
1197 * Set the percentage of buffered data. This is a value between 0 and 100.
1198 * The @busy indicator is %TRUE when the buffering is in progress.
1203 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1205 GstStructure *structure;
1207 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1208 g_return_if_fail (gst_query_is_writable (query));
1209 g_return_if_fail (percent >= 0 && percent <= 100);
1211 structure = GST_QUERY_STRUCTURE (query);
1212 gst_structure_id_set (structure,
1213 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1214 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1218 * gst_query_parse_buffering_percent:
1219 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1220 * @busy: (out) (allow-none): if buffering is busy, or NULL
1221 * @percent: (out) (allow-none): a buffering percent, or NULL
1223 * Get the percentage of buffered data. This is a value between 0 and 100.
1224 * The @busy indicator is %TRUE when the buffering is in progress.
1229 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1232 GstStructure *structure;
1234 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1236 structure = GST_QUERY_STRUCTURE (query);
1238 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1241 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1242 GST_QUARK (BUFFER_PERCENT)));
1246 * gst_query_set_buffering_stats:
1247 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1248 * @mode: a buffering mode
1249 * @avg_in: the average input rate
1250 * @avg_out: the average output rate
1251 * @buffering_left: amount of buffering time left
1253 * Configures the buffering stats values in @query.
1258 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1259 gint avg_in, gint avg_out, gint64 buffering_left)
1261 GstStructure *structure;
1263 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1264 g_return_if_fail (gst_query_is_writable (query));
1266 structure = GST_QUERY_STRUCTURE (query);
1267 gst_structure_id_set (structure,
1268 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1269 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1270 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1271 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1275 * gst_query_parse_buffering_stats:
1276 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1277 * @mode: (out) (allow-none): a buffering mode, or NULL
1278 * @avg_in: (out) (allow-none): the average input rate, or NULL
1279 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1280 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1282 * Extracts the buffering stats values from @query.
1287 gst_query_parse_buffering_stats (GstQuery * query,
1288 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1289 gint64 * buffering_left)
1291 GstStructure *structure;
1293 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1295 structure = GST_QUERY_STRUCTURE (query);
1297 *mode = (GstBufferingMode)
1298 g_value_get_enum (gst_structure_id_get_value (structure,
1299 GST_QUARK (BUFFERING_MODE)));
1301 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1302 GST_QUARK (AVG_IN_RATE)));
1304 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1305 GST_QUARK (AVG_OUT_RATE)));
1308 g_value_get_int64 (gst_structure_id_get_value (structure,
1309 GST_QUARK (BUFFERING_LEFT)));
1314 * gst_query_set_buffering_range:
1315 * @query: a #GstQuery
1316 * @format: the format to set for the @start and @stop values
1317 * @start: the start to set
1318 * @stop: the stop to set
1319 * @estimated_total: estimated total amount of download time
1321 * Set the available query result fields in @query.
1326 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1327 gint64 start, gint64 stop, gint64 estimated_total)
1329 GstStructure *structure;
1331 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1332 g_return_if_fail (gst_query_is_writable (query));
1334 structure = GST_QUERY_STRUCTURE (query);
1335 gst_structure_id_set (structure,
1336 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1337 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1338 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1339 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1343 * gst_query_parse_buffering_range:
1344 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1345 * @format: (out) (allow-none): the format to set for the @segment_start
1346 * and @segment_end values, or NULL
1347 * @start: (out) (allow-none): the start to set, or NULL
1348 * @stop: (out) (allow-none): the stop to set, or NULL
1349 * @estimated_total: (out) (allow-none): estimated total amount of download
1352 * Parse an available query, writing the format into @format, and
1353 * other results into the passed parameters, if the respective parameters
1359 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1360 gint64 * start, gint64 * stop, gint64 * estimated_total)
1362 GstStructure *structure;
1364 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1366 structure = GST_QUERY_STRUCTURE (query);
1369 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1370 GST_QUARK (FORMAT)));
1372 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1373 GST_QUARK (START_VALUE)));
1375 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1376 GST_QUARK (STOP_VALUE)));
1377 if (estimated_total)
1379 g_value_get_int64 (gst_structure_id_get_value (structure,
1380 GST_QUARK (ESTIMATED_TOTAL)));
1384 * gst_query_add_buffering_range:
1385 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1386 * @start: start position of the range
1387 * @stop: stop position of the range
1389 * Set the buffering-ranges array field in @query. The current last
1390 * start position of the array should be inferior to @start.
1392 * Returns: a #gboolean indicating if the range was added or not.
1397 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1400 GValue value = { 0 };
1401 GstStructure *structure;
1403 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1404 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1406 if (G_UNLIKELY (start >= stop))
1409 structure = GST_QUERY_STRUCTURE (query);
1410 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES));
1411 if (array->n_values > 1) {
1412 GValue *last_array_value;
1414 last_array_value = g_value_array_get_nth (array, array->n_values - 1);
1415 if (G_UNLIKELY (start <= gst_value_get_int64_range_min (last_array_value)))
1419 g_value_init (&value, GST_TYPE_INT64_RANGE);
1420 gst_value_set_int64_range (&value, start, stop);
1421 g_value_array_append (array, &value);
1422 /* skip the g_value_unset(&value) here, we know it's not needed */
1428 * gst_query_get_n_buffering_ranges:
1429 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1431 * Retrieve the number of values currently stored in the
1432 * buffered-ranges array of the query's structure.
1434 * Returns: the range array size as a #guint.
1439 gst_query_get_n_buffering_ranges (GstQuery * query)
1442 GstStructure *structure;
1444 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1446 structure = GST_QUERY_STRUCTURE (query);
1447 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES));
1449 return array->n_values;
1454 * gst_query_parse_nth_buffering_range:
1455 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1456 * @index: position in the buffered-ranges array to read
1457 * @start: (out) (allow-none): the start position to set, or NULL
1458 * @stop: (out) (allow-none): the stop position to set, or NULL
1460 * Parse an available query and get the start and stop values stored
1461 * at the @index of the buffered ranges array.
1463 * Returns: a #gboolean indicating if the parsing succeeded.
1468 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1469 gint64 * start, gint64 * stop)
1472 const GValue *value;
1473 gboolean ret = FALSE;
1474 GstStructure *structure;
1476 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1478 structure = GST_QUERY_STRUCTURE (query);
1479 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES));
1481 if ((value = g_value_array_get_nth (array, index))) {
1483 *start = gst_value_get_int64_range_min (value);
1485 *stop = gst_value_get_int64_range_max (value);
1494 * gst_query_new_uri:
1496 * Constructs a new query URI query object. Use gst_query_unref()
1497 * when done with it. An URI query is used to query the current URI
1498 * that is used by the source or sink.
1500 * Free-function: gst_query_unref
1502 * Returns: (transfer full): a new #GstQuery
1507 gst_query_new_uri (void)
1510 GstStructure *structure;
1512 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1513 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1515 query = gst_query_new (GST_QUERY_URI, structure);
1521 * gst_query_set_uri:
1522 * @query: a #GstQuery with query type GST_QUERY_URI
1523 * @uri: the URI to set
1525 * Answer a URI query by setting the requested URI.
1530 gst_query_set_uri (GstQuery * query, const gchar * uri)
1532 GstStructure *structure;
1534 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1535 g_return_if_fail (gst_query_is_writable (query));
1536 g_return_if_fail (gst_uri_is_valid (uri));
1538 structure = GST_QUERY_STRUCTURE (query);
1539 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1543 * gst_query_parse_uri:
1544 * @query: a #GstQuery
1545 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1548 * Parse an URI query, writing the URI into @uri as a newly
1549 * allocated string, if the respective parameters are non-NULL.
1550 * Free the string with g_free() after usage.
1555 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1557 GstStructure *structure;
1559 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1561 structure = GST_QUERY_STRUCTURE (query);
1563 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1568 * gst_query_new_allocation:
1569 * @caps: the negotiated caps
1570 * @need_pool: return a pool
1572 * Constructs a new query object for querying the allocation properties.
1574 * Free-function: gst_query_unref
1576 * Returns: (transfer full): a new #GstQuery
1579 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1582 GstStructure *structure;
1584 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1585 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1586 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1587 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1588 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1589 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1590 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1591 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1592 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1594 query = gst_query_new (GST_QUERY_ALLOCATION, structure);
1600 * gst_query_parse_allocation:
1601 * @query: a #GstQuery
1602 * @caps: (out callee-allocates) (allow-none): The #GstCaps
1603 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1605 * Parse an allocation query, writing the requested caps in @caps and
1606 * whether a pool is needed in @need_pool, if the respective parameters
1610 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1611 gboolean * need_pool)
1613 GstStructure *structure;
1615 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1617 structure = GST_QUERY_STRUCTURE (query);
1618 gst_structure_id_get (structure,
1619 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1620 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1624 * gst_query_set_allocation_params:
1625 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1627 * @min_buffers: the min buffers
1628 * @max_buffers: the max buffers
1629 * @prefix: the prefix
1630 * @alignment: the alignment
1631 * @pool: the #GstBufferPool
1633 * Set the allocation parameters in @query.
1636 gst_query_set_allocation_params (GstQuery * query, guint size,
1637 guint min_buffers, guint max_buffers, guint prefix,
1638 guint alignment, GstBufferPool * pool)
1640 GstStructure *structure;
1642 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1643 g_return_if_fail (gst_query_is_writable (query));
1644 g_return_if_fail (((alignment + 1) & alignment) == 0);
1645 g_return_if_fail (size != 0 || pool == NULL);
1647 structure = GST_QUERY_STRUCTURE (query);
1648 gst_structure_id_set (structure,
1649 GST_QUARK (SIZE), G_TYPE_UINT, size,
1650 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1651 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1652 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1653 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1654 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1658 * gst_query_parse_allocation_params:
1659 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1661 * @min_buffers: the min buffers
1662 * @max_buffers: the max buffers
1663 * @prefix: the prefix
1664 * @alignment: the alignment
1665 * @pool: the #GstBufferPool
1667 * Get the allocation parameters in @query.
1670 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1671 guint * min_buffers, guint * max_buffers, guint * prefix,
1672 guint * alignment, GstBufferPool ** pool)
1674 GstStructure *structure;
1676 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1678 structure = GST_QUERY_STRUCTURE (query);
1679 gst_structure_id_get (structure,
1680 GST_QUARK (SIZE), G_TYPE_UINT, size,
1681 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1682 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1683 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1684 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1685 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1689 * gst_query_add_allocation_meta:
1690 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1691 * @api: the metadata API
1693 * Add @api as aone of the supported metadata API to @query.
1696 gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
1699 GValue api_value = { 0 };
1700 GstStructure *structure;
1702 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1703 g_return_if_fail (api != NULL);
1704 g_return_if_fail (gst_query_is_writable (query));
1706 structure = GST_QUERY_STRUCTURE (query);
1707 array = ensure_array (structure, GST_QUARK (META));
1709 g_value_init (&api_value, G_TYPE_STRING);
1710 g_value_set_string (&api_value, api);
1711 g_value_array_append (array, &api_value);
1712 g_value_unset (&api_value);
1716 * gst_query_get_n_allocation_metas:
1717 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1719 * Retrieve the number of values currently stored in the
1720 * meta API array of the query's structure.
1722 * Returns: the metadata API array size as a #guint.
1725 gst_query_get_n_allocation_metas (GstQuery * query)
1728 GstStructure *structure;
1730 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1732 structure = GST_QUERY_STRUCTURE (query);
1733 array = ensure_array (structure, GST_QUARK (META));
1735 return array->n_values;
1739 * gst_query_parse_nth_allocation_meta:
1740 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1741 * @index: position in the metadata API array to read
1743 * Parse an available query and get the metadata API
1744 * at @index of the metadata API array.
1746 * Returns: a #gchar of the metadata API at @index.
1749 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1753 const gchar *ret = NULL;
1754 GstStructure *structure;
1756 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1758 structure = GST_QUERY_STRUCTURE (query);
1759 array = ensure_array (structure, GST_QUARK (META));
1761 if ((value = g_value_array_get_nth (array, index)))
1762 ret = g_value_get_string (value);
1768 * gst_query_has_allocation_meta:
1769 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1770 * @api: the metadata API
1772 * Check if @query has metadata @api set.
1774 * Returns: TRUE when @api is in the list of metadata.
1777 gst_query_has_allocation_meta (GstQuery * query, const gchar * api)
1781 GstStructure *structure;
1784 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1785 g_return_val_if_fail (api != NULL, FALSE);
1787 structure = GST_QUERY_STRUCTURE (query);
1788 array = ensure_array (structure, GST_QUARK (META));
1790 for (i = 0; i < array->n_values; i++) {
1791 value = g_value_array_get_nth (array, i);
1792 if (!strcmp (api, g_value_get_string (value)))
1799 * gst_query_add_allocation_memory:
1800 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1801 * @alloc: the memory allocator
1803 * Add @alloc as a supported memory allocator.
1806 gst_query_add_allocation_memory (GstQuery * query, const gchar * alloc)
1809 GValue value = { 0 };
1810 GstStructure *structure;
1812 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1813 g_return_if_fail (gst_query_is_writable (query));
1815 structure = GST_QUERY_STRUCTURE (query);
1816 array = ensure_array (structure, GST_QUARK (ALLOCATOR));
1818 g_value_init (&value, G_TYPE_STRING);
1819 g_value_set_string (&value, alloc);
1820 g_value_array_append (array, &value);
1821 g_value_unset (&value);
1825 * gst_query_get_n_allocation_memories:
1826 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1828 * Retrieve the number of values currently stored in the
1829 * allocator array of the query's structure.
1831 * If no memory allocator is specified, the downstream element can handle
1832 * the default memory allocator.
1834 * Returns: the allocator array size as a #guint.
1837 gst_query_get_n_allocation_memories (GstQuery * query)
1840 GstStructure *structure;
1842 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1844 structure = GST_QUERY_STRUCTURE (query);
1845 array = ensure_array (structure, GST_QUARK (ALLOCATOR));
1847 return array->n_values;
1851 * gst_query_parse_nth_allocation_memory:
1852 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1853 * @index: position in the allocator array to read
1855 * Parse an available query and get the alloctor
1856 * at @index of the allocator array.
1858 * Returns: the name of the allocator at @index.
1861 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1865 const gchar *ret = NULL;
1866 GstStructure *structure;
1868 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1870 structure = GST_QUERY_STRUCTURE (query);
1871 array = ensure_array (structure, GST_QUARK (ALLOCATOR));
1873 if ((value = g_value_array_get_nth (array, index)))
1874 ret = g_value_get_string (value);
1880 * gst_query_new_scheduling:
1882 * Constructs a new query object for querying the scheduling properties.
1884 * Free-function: gst_query_unref
1886 * Returns: (transfer full): a new #GstQuery
1889 gst_query_new_scheduling (void)
1892 GstStructure *structure;
1894 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1895 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1896 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1897 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1898 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1899 query = gst_query_new (GST_QUERY_SCHEDULING, structure);
1905 * gst_query_set_scheduling:
1906 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1907 * @flags: #GstSchedulingFlags
1908 * @minsize: the suggested minimum size of pull requests
1909 * @maxsize: the suggested maximum size of pull requests
1910 * @align: the suggested alignment of pull requests
1912 * Set the scheduling properties.
1915 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1916 gint minsize, gint maxsize, gint align)
1918 GstStructure *structure;
1920 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1921 g_return_if_fail (gst_query_is_writable (query));
1923 structure = GST_QUERY_STRUCTURE (query);
1924 gst_structure_id_set (structure,
1925 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1926 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1927 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1928 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1932 * gst_query_parse_scheduling:
1933 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1934 * @flags: #GstSchedulingFlags
1935 * @minsize: the suggested minimum size of pull requests
1936 * @maxsize: the suggested maximum size of pull requests:
1937 * @align: the suggested alignment of pull requests
1939 * Set the scheduling properties.
1942 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
1943 gint * minsize, gint * maxsize, gint * align)
1945 GstStructure *structure;
1947 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1949 structure = GST_QUERY_STRUCTURE (query);
1950 gst_structure_id_get (structure,
1951 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1952 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1953 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1954 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1958 * gst_query_add_scheduling_mode:
1959 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1960 * @mode: a #GstPadMode
1962 * Add @mode as aone of the supported scheduling modes to @query.
1965 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
1968 GValue value = { 0 };
1969 GstStructure *structure;
1971 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1972 g_return_if_fail (gst_query_is_writable (query));
1974 structure = GST_QUERY_STRUCTURE (query);
1975 array = ensure_array (structure, GST_QUARK (MODES));
1977 g_value_init (&value, GST_TYPE_PAD_MODE);
1978 g_value_set_enum (&value, mode);
1979 g_value_array_append (array, &value);
1980 g_value_unset (&value);
1984 * gst_query_get_n_scheduling_modes:
1985 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
1987 * Retrieve the number of values currently stored in the
1988 * scheduling mode array of the query's structure.
1990 * Returns: the scheduling mode array size as a #guint.
1993 gst_query_get_n_scheduling_modes (GstQuery * query)
1996 GstStructure *structure;
1998 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2000 structure = GST_QUERY_STRUCTURE (query);
2001 array = ensure_array (structure, GST_QUARK (MODES));
2003 return array->n_values;
2007 * gst_query_parse_nth_scheduling_mode:
2008 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2009 * @index: position in the scheduling modes array to read
2011 * Parse an available query and get the scheduling mode
2012 * at @index of the scheduling modes array.
2014 * Returns: a #GstPadMode of the scheduling mode at @index.
2017 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2021 GstPadMode ret = GST_PAD_MODE_NONE;
2022 GstStructure *structure;
2024 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, ret);
2026 structure = GST_QUERY_STRUCTURE (query);
2027 array = ensure_array (structure, GST_QUARK (MODES));
2029 if ((value = g_value_array_get_nth (array, index)))
2030 ret = g_value_get_enum (value);
2036 * gst_query_has_scheduling_mode:
2037 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2038 * @mode: the scheduling mode
2040 * Check if @query has scheduling mode set.
2042 * Returns: TRUE when @mode is in the list of scheduling modes.
2045 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2049 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));
2057 for (i = 0; i < array->n_values; i++) {
2058 value = g_value_array_get_nth (array, i);
2059 if (mode == g_value_get_enum (value))
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);