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 * gst_query_new_formats:
969 * Constructs a new query object for querying formats of
972 * Free-function: gst_query_unref
974 * Returns: (transfer full): a new #GstQuery
979 gst_query_new_formats (void)
982 GstStructure *structure;
984 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
985 query = gst_query_new (GST_QUERY_FORMATS, structure);
991 gst_query_list_add_format (GValue * list, GstFormat format)
993 GValue item = { 0, };
995 g_value_init (&item, GST_TYPE_FORMAT);
996 g_value_set_enum (&item, format);
997 gst_value_list_append_value (list, &item);
998 g_value_unset (&item);
1002 * gst_query_set_formats:
1003 * @query: a #GstQuery
1004 * @n_formats: the number of formats to set.
1005 * @...: A number of @GstFormats equal to @n_formats.
1007 * Set the formats query result fields in @query. The number of formats passed
1008 * must be equal to @n_formats.
1011 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1014 GValue list = { 0, };
1016 GstStructure *structure;
1018 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1019 g_return_if_fail (gst_query_is_writable (query));
1021 g_value_init (&list, GST_TYPE_LIST);
1023 va_start (ap, n_formats);
1024 for (i = 0; i < n_formats; i++) {
1025 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1029 structure = GST_QUERY_STRUCTURE (query);
1030 gst_structure_set_value (structure, "formats", &list);
1032 g_value_unset (&list);
1037 * gst_query_set_formatsv:
1038 * @query: a #GstQuery
1039 * @n_formats: the number of formats to set.
1040 * @formats: (in) (array length=n_formats): an array containing @n_formats
1041 * @GstFormat values.
1043 * Set the formats query result fields in @query. The number of formats passed
1044 * in the @formats array must be equal to @n_formats.
1049 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1050 const GstFormat * formats)
1052 GValue list = { 0, };
1054 GstStructure *structure;
1056 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1057 g_return_if_fail (gst_query_is_writable (query));
1059 g_value_init (&list, GST_TYPE_LIST);
1060 for (i = 0; i < n_formats; i++) {
1061 gst_query_list_add_format (&list, formats[i]);
1063 structure = GST_QUERY_STRUCTURE (query);
1064 gst_structure_set_value (structure, "formats", &list);
1066 g_value_unset (&list);
1070 * gst_query_parse_n_formats:
1071 * @query: a #GstQuery
1072 * @n_formats: (out): the number of formats in this query.
1074 * Parse the number of formats in the formats @query.
1079 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1081 GstStructure *structure;
1083 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1088 structure = GST_QUERY_STRUCTURE (query);
1089 list = gst_structure_get_value (structure, "formats");
1093 *n_formats = gst_value_list_get_size (list);
1098 * gst_query_parse_nth_format:
1099 * @query: a #GstQuery
1100 * @nth: (out): the nth format to retrieve.
1101 * @format: (out): a pointer to store the nth format
1103 * Parse the format query and retrieve the @nth format from it into
1104 * @format. If the list contains less elements than @nth, @format will be
1105 * set to GST_FORMAT_UNDEFINED.
1108 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
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");
1120 *format = GST_FORMAT_UNDEFINED;
1122 if (nth < gst_value_list_get_size (list)) {
1124 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1126 *format = GST_FORMAT_UNDEFINED;
1132 * gst_query_new_buffering
1133 * @format: the default #GstFormat for the new query
1135 * Constructs a new query object for querying the buffering status of
1138 * Free-function: gst_query_unref
1140 * Returns: (transfer full): a new #GstQuery
1145 gst_query_new_buffering (GstFormat format)
1148 GstStructure *structure;
1150 /* by default, we configure the answer as no buffering with a 100% buffering
1152 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1153 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1154 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1155 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1156 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1157 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1158 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1159 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1160 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1161 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1162 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1164 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1170 * gst_query_set_buffering_percent
1171 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1172 * @busy: if buffering is busy
1173 * @percent: a buffering percent
1175 * Set the percentage of buffered data. This is a value between 0 and 100.
1176 * The @busy indicator is %TRUE when the buffering is in progress.
1181 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1183 GstStructure *structure;
1185 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1186 g_return_if_fail (gst_query_is_writable (query));
1187 g_return_if_fail (percent >= 0 && percent <= 100);
1189 structure = GST_QUERY_STRUCTURE (query);
1190 gst_structure_id_set (structure,
1191 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1192 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1196 * gst_query_parse_buffering_percent
1197 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1198 * @busy: (out) (allow-none): if buffering is busy, or NULL
1199 * @percent: (out) (allow-none): a buffering percent, or NULL
1201 * Get the percentage of buffered data. This is a value between 0 and 100.
1202 * The @busy indicator is %TRUE when the buffering is in progress.
1207 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1210 GstStructure *structure;
1212 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1214 structure = GST_QUERY_STRUCTURE (query);
1216 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1219 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1220 GST_QUARK (BUFFER_PERCENT)));
1224 * gst_query_set_buffering_stats:
1225 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1226 * @mode: a buffering mode
1227 * @avg_in: the average input rate
1228 * @avg_out: the average output rate
1229 * @buffering_left: amount of buffering time left
1231 * Configures the buffering stats values in @query.
1236 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1237 gint avg_in, gint avg_out, gint64 buffering_left)
1239 GstStructure *structure;
1241 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1242 g_return_if_fail (gst_query_is_writable (query));
1244 structure = GST_QUERY_STRUCTURE (query);
1245 gst_structure_id_set (structure,
1246 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1247 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1248 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1249 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1253 * gst_query_parse_buffering_stats:
1254 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1255 * @mode: (out) (allow-none): a buffering mode, or NULL
1256 * @avg_in: (out) (allow-none): the average input rate, or NULL
1257 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1258 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1260 * Extracts the buffering stats values from @query.
1265 gst_query_parse_buffering_stats (GstQuery * query,
1266 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1267 gint64 * buffering_left)
1269 GstStructure *structure;
1271 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1273 structure = GST_QUERY_STRUCTURE (query);
1275 *mode = (GstBufferingMode)
1276 g_value_get_enum (gst_structure_id_get_value (structure,
1277 GST_QUARK (BUFFERING_MODE)));
1279 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1280 GST_QUARK (AVG_IN_RATE)));
1282 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1283 GST_QUARK (AVG_OUT_RATE)));
1286 g_value_get_int64 (gst_structure_id_get_value (structure,
1287 GST_QUARK (BUFFERING_LEFT)));
1292 * gst_query_set_buffering_range:
1293 * @query: a #GstQuery
1294 * @format: the format to set for the @start and @stop values
1295 * @start: the start to set
1296 * @stop: the stop to set
1297 * @estimated_total: estimated total amount of download time
1299 * Set the available query result fields in @query.
1304 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1305 gint64 start, gint64 stop, gint64 estimated_total)
1307 GstStructure *structure;
1309 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1310 g_return_if_fail (gst_query_is_writable (query));
1312 structure = GST_QUERY_STRUCTURE (query);
1313 gst_structure_id_set (structure,
1314 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1315 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1316 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1317 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1321 * gst_query_parse_buffering_range:
1322 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1323 * @format: (out) (allow-none): the format to set for the @segment_start
1324 * and @segment_end values, or NULL
1325 * @start: (out) (allow-none): the start to set, or NULL
1326 * @stop: (out) (allow-none): the stop to set, or NULL
1327 * @estimated_total: (out) (allow-none): estimated total amount of download
1330 * Parse an available query, writing the format into @format, and
1331 * other results into the passed parameters, if the respective parameters
1337 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1338 gint64 * start, gint64 * stop, gint64 * estimated_total)
1340 GstStructure *structure;
1342 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1344 structure = GST_QUERY_STRUCTURE (query);
1347 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1348 GST_QUARK (FORMAT)));
1350 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1351 GST_QUARK (START_VALUE)));
1353 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1354 GST_QUARK (STOP_VALUE)));
1355 if (estimated_total)
1357 g_value_get_int64 (gst_structure_id_get_value (structure,
1358 GST_QUARK (ESTIMATED_TOTAL)));
1362 * gst_query_add_buffering_range
1363 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1364 * @start: start position of the range
1365 * @stop: stop position of the range
1367 * Set the buffering-ranges array field in @query. The current last
1368 * start position of the array should be inferior to @start.
1370 * Returns: a #gboolean indicating if the range was added or not.
1375 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1378 GValue *last_array_value;
1379 const GValue *value;
1380 GValue range_value = { 0 };
1381 GstStructure *structure;
1383 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1384 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1386 if (G_UNLIKELY (start >= stop))
1389 structure = GST_QUERY_STRUCTURE (query);
1390 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1392 array = (GValueArray *) g_value_get_boxed (value);
1393 last_array_value = g_value_array_get_nth (array, array->n_values - 1);
1394 if (G_UNLIKELY (start <= gst_value_get_int64_range_min (last_array_value)))
1397 GValue new_array_val = { 0, };
1399 array = g_value_array_new (0);
1401 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1402 g_value_take_boxed (&new_array_val, array);
1404 /* set the value array only once, so we then modify (append to) the
1405 * existing value array owned by the GstStructure / the field's GValue */
1406 gst_structure_id_take_value (structure, GST_QUARK (BUFFERING_RANGES),
1410 g_value_init (&range_value, GST_TYPE_INT64_RANGE);
1411 gst_value_set_int64_range (&range_value, start, stop);
1412 g_value_array_append (array, &range_value);
1413 /* skip the g_value_unset(&range_value) here, we know it's not needed */
1419 * gst_query_get_n_buffering_ranges
1420 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1422 * Retrieve the number of values currently stored in the
1423 * buffered-ranges array of the query's structure.
1425 * Returns: the range array size as a #guint.
1430 gst_query_get_n_buffering_ranges (GstQuery * query)
1433 const GValue *value;
1435 GstStructure *structure;
1437 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1439 structure = GST_QUERY_STRUCTURE (query);
1440 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1442 array = (GValueArray *) g_value_get_boxed (value);
1443 size = array->n_values;
1450 * gst_query_parse_nth_buffering_range
1451 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1452 * @index: position in the buffered-ranges array to read
1453 * @start: (out) (allow-none): the start position to set, or NULL
1454 * @stop: (out) (allow-none): the stop position to set, or NULL
1456 * Parse an available query and get the start and stop values stored
1457 * at the @index of the buffered ranges array.
1459 * Returns: a #gboolean indicating if the parsing succeeded.
1464 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1465 gint64 * start, gint64 * stop)
1467 const GValue *value;
1468 GValueArray *ranges;
1469 GValue *range_value;
1470 gboolean ret = FALSE;
1471 GstStructure *structure;
1473 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1475 structure = GST_QUERY_STRUCTURE (query);
1476 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1477 ranges = (GValueArray *) g_value_get_boxed (value);
1478 range_value = g_value_array_get_nth (ranges, index);
1481 *start = gst_value_get_int64_range_min (range_value);
1483 *stop = gst_value_get_int64_range_max (range_value);
1492 * gst_query_new_uri:
1494 * Constructs a new query URI query object. Use gst_query_unref()
1495 * when done with it. An URI query is used to query the current URI
1496 * that is used by the source or sink.
1498 * Free-function: gst_query_unref
1500 * Returns: (transfer full): a new #GstQuery
1505 gst_query_new_uri (void)
1508 GstStructure *structure;
1510 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1511 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1513 query = gst_query_new (GST_QUERY_URI, structure);
1519 * gst_query_set_uri:
1520 * @query: a #GstQuery with query type GST_QUERY_URI
1521 * @uri: the URI to set
1523 * Answer a URI query by setting the requested URI.
1528 gst_query_set_uri (GstQuery * query, const gchar * uri)
1530 GstStructure *structure;
1532 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1533 g_return_if_fail (gst_query_is_writable (query));
1534 g_return_if_fail (gst_uri_is_valid (uri));
1536 structure = GST_QUERY_STRUCTURE (query);
1537 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1541 * gst_query_parse_uri:
1542 * @query: a #GstQuery
1543 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1546 * Parse an URI query, writing the URI into @uri as a newly
1547 * allocated string, if the respective parameters are non-NULL.
1548 * Free the string with g_free() after usage.
1553 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1555 GstStructure *structure;
1557 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1559 structure = GST_QUERY_STRUCTURE (query);
1561 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1566 * gst_query_new_allocation
1567 * @caps: the negotiated caps
1568 * @need_pool: return a pool
1570 * Constructs a new query object for querying the allocation properties.
1572 * Free-function: gst_query_unref
1574 * Returns: (transfer full): a new #GstQuery
1577 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1580 GstStructure *structure;
1582 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1583 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1584 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1585 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1586 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1587 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1588 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1589 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1590 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1592 query = gst_query_new (GST_QUERY_ALLOCATION, structure);
1598 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1599 gboolean * need_pool)
1601 GstStructure *structure;
1603 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1605 structure = GST_QUERY_STRUCTURE (query);
1606 gst_structure_id_get (structure,
1607 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1608 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1612 * gst_query_set_allocation_params
1613 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1615 * @min_buffers: the min buffers
1616 * @max_buffers: the max buffers
1617 * @prefix: the prefix
1618 * @alignment: the alignment
1619 * @pool: the #GstBufferPool
1621 * Set the allocation parameters in @query.
1624 gst_query_set_allocation_params (GstQuery * query, guint size,
1625 guint min_buffers, guint max_buffers, guint prefix,
1626 guint alignment, GstBufferPool * pool)
1628 GstStructure *structure;
1630 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1631 g_return_if_fail (gst_query_is_writable (query));
1632 g_return_if_fail (((alignment + 1) & alignment) == 0);
1633 g_return_if_fail (size != 0 || pool == NULL);
1635 structure = GST_QUERY_STRUCTURE (query);
1636 gst_structure_id_set (structure,
1637 GST_QUARK (SIZE), G_TYPE_UINT, size,
1638 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1639 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1640 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1641 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1642 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1646 * gst_query_parse_allocation_params
1647 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1649 * @min_buffers: the min buffers
1650 * @max_buffers: the max buffers
1651 * @prefix: the prefix
1652 * @alignment: the alignment
1653 * @pool: the #GstBufferPool
1655 * Get the allocation parameters in @query.
1658 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1659 guint * min_buffers, guint * max_buffers, guint * prefix,
1660 guint * alignment, GstBufferPool ** pool)
1662 GstStructure *structure;
1664 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1666 structure = GST_QUERY_STRUCTURE (query);
1667 gst_structure_id_get (structure,
1668 GST_QUARK (SIZE), G_TYPE_UINT, size,
1669 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1670 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1671 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1672 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1673 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1677 * gst_query_add_allocation_meta
1678 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1679 * @api: the metadata API
1681 * Add @api as aone of the supported metadata API to @query.
1684 gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
1687 const GValue *value;
1688 GValue api_value = { 0 };
1689 GstStructure *structure;
1691 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1692 g_return_if_fail (api != NULL);
1693 g_return_if_fail (gst_query_is_writable (query));
1695 structure = GST_QUERY_STRUCTURE (query);
1696 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1698 array = (GValueArray *) g_value_get_boxed (value);
1700 GValue new_array_val = { 0, };
1702 array = g_value_array_new (0);
1704 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1705 g_value_take_boxed (&new_array_val, array);
1707 gst_structure_id_take_value (structure, GST_QUARK (META), &new_array_val);
1710 g_value_init (&api_value, G_TYPE_STRING);
1711 g_value_set_string (&api_value, api);
1712 g_value_array_append (array, &api_value);
1713 g_value_unset (&api_value);
1717 * gst_query_get_n_allocation_metas:
1718 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1720 * Retrieve the number of values currently stored in the
1721 * meta API array of the query's structure.
1723 * Returns: the metadata API array size as a #guint.
1726 gst_query_get_n_allocation_metas (GstQuery * query)
1729 const GValue *value;
1731 GstStructure *structure;
1733 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1735 structure = GST_QUERY_STRUCTURE (query);
1736 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1738 array = (GValueArray *) g_value_get_boxed (value);
1739 size = array->n_values;
1745 * gst_query_parse_nth_allocation_meta
1746 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1747 * @index: position in the metadata API array to read
1749 * Parse an available query and get the metadata API
1750 * at @index of the metadata API array.
1752 * Returns: a #gchar of the metadata API at @index.
1755 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1757 const GValue *value;
1758 const gchar *ret = NULL;
1759 GstStructure *structure;
1761 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1763 structure = GST_QUERY_STRUCTURE (query);
1764 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1769 meta = (GValueArray *) g_value_get_boxed (value);
1770 api_value = g_value_array_get_nth (meta, index);
1773 ret = g_value_get_string (api_value);
1779 * gst_query_has_allocation_meta
1780 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1781 * @api: the metadata API
1783 * Check if @query has metadata @api set.
1785 * Returns: TRUE when @api is in the list of metadata.
1788 gst_query_has_allocation_meta (GstQuery * query, const gchar * api)
1790 const GValue *value;
1791 GstStructure *structure;
1793 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1794 g_return_val_if_fail (api != NULL, FALSE);
1796 structure = GST_QUERY_STRUCTURE (query);
1797 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1803 array = (GValueArray *) g_value_get_boxed (value);
1804 for (i = 0; i < array->n_values; i++) {
1805 api_value = g_value_array_get_nth (array, i);
1806 if (!strcmp (api, g_value_get_string (api_value)))
1814 * gst_query_add_allocation_memory
1815 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1816 * @alloc: the memory allocator
1818 * Add @alloc as a supported memory allocator.
1821 gst_query_add_allocation_memory (GstQuery * query, const gchar * alloc)
1824 const GValue *value;
1825 GValue alloc_value = { 0 };
1826 GstStructure *structure;
1828 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1829 g_return_if_fail (gst_query_is_writable (query));
1831 structure = GST_QUERY_STRUCTURE (query);
1832 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1834 array = (GValueArray *) g_value_get_boxed (value);
1836 GValue new_array_val = { 0, };
1838 array = g_value_array_new (0);
1840 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1841 g_value_take_boxed (&new_array_val, array);
1843 gst_structure_id_take_value (structure, GST_QUARK (ALLOCATOR),
1847 g_value_init (&alloc_value, G_TYPE_STRING);
1848 g_value_set_string (&alloc_value, alloc);
1849 g_value_array_append (array, &alloc_value);
1850 g_value_unset (&alloc_value);
1854 * gst_query_get_n_allocation_memories:
1855 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1857 * Retrieve the number of values currently stored in the
1858 * allocator array of the query's structure.
1860 * If no memory allocator is specified, the downstream element can handle
1861 * the default memory allocator.
1863 * Returns: the allocator array size as a #guint.
1866 gst_query_get_n_allocation_memories (GstQuery * query)
1869 const GValue *value;
1871 GstStructure *structure;
1873 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1875 structure = GST_QUERY_STRUCTURE (query);
1876 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1878 array = (GValueArray *) g_value_get_boxed (value);
1879 size = array->n_values;
1885 * gst_query_parse_nth_allocation_memory
1886 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1887 * @index: position in the allocator array to read
1889 * Parse an available query and get the alloctor
1890 * at @index of the allocator array.
1892 * Returns: the name of the allocator at @index.
1895 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1897 const GValue *value;
1898 const gchar *ret = NULL;
1899 GstStructure *structure;
1901 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1903 structure = GST_QUERY_STRUCTURE (query);
1904 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1906 GValueArray *memory;
1907 GValue *alloc_value;
1909 memory = (GValueArray *) g_value_get_boxed (value);
1910 alloc_value = g_value_array_get_nth (memory, index);
1913 ret = g_value_get_string (alloc_value);
1919 * gst_query_new_scheduling
1921 * Constructs a new query object for querying the scheduling properties.
1923 * Free-function: gst_query_unref
1925 * Returns: (transfer full): a new #GstQuery
1928 gst_query_new_scheduling (void)
1931 GstStructure *structure;
1933 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1934 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, FALSE,
1935 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, FALSE,
1936 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, TRUE,
1937 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1938 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1939 GST_QUARK (ALIGN), G_TYPE_INT, 1, NULL);
1940 query = gst_query_new (GST_QUERY_SCHEDULING, structure);
1946 * gst_query_set_scheduling
1947 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1948 * @pull_mode: if pull mode scheduling is supported
1949 * @random_access: if random access is possible
1950 * @sequential: if sequential access is recommended
1951 * @minsize: the suggested minimum size of pull requests
1952 * @maxsize: the suggested maximum size of pull requests
1953 * @align: the suggested alignment of pull requests
1955 * Set the scheduling properties.
1958 gst_query_set_scheduling (GstQuery * query, gboolean pull_mode,
1959 gboolean random_access, gboolean sequential,
1960 gint minsize, gint maxsize, gint align)
1962 GstStructure *structure;
1964 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1965 g_return_if_fail (gst_query_is_writable (query));
1967 structure = GST_QUERY_STRUCTURE (query);
1968 gst_structure_id_set (structure,
1969 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, pull_mode,
1970 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, random_access,
1971 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, sequential,
1972 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1973 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1974 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1978 * gst_query_parse_scheduling
1979 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1980 * @pull_mode: if pull mode scheduling is supported
1981 * @random_access: if random access is possible
1982 * @sequential: if sequential access is recommended
1983 * @minsize: the suggested minimum size of pull requests
1984 * @maxsize: the suggested maximum size of pull requests:
1985 * @align: the suggested alignment of pull requests
1987 * Set the scheduling properties.
1990 gst_query_parse_scheduling (GstQuery * query, gboolean * pull_mode,
1991 gboolean * random_access, gboolean * sequential,
1992 gint * minsize, gint * maxsize, gint * align)
1994 GstStructure *structure;
1996 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1998 structure = GST_QUERY_STRUCTURE (query);
1999 gst_structure_id_get (structure,
2000 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, pull_mode,
2001 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, random_access,
2002 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, sequential,
2003 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2004 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2005 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2009 * gst_query_new_accept_caps
2012 * Constructs a new query object for querying if @caps are accepted.
2014 * Free-function: gst_query_unref
2016 * Returns: (transfer full): a new #GstQuery
2019 gst_query_new_accept_caps (GstCaps * caps)
2022 GstStructure *structure;
2024 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2025 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2026 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2027 query = gst_query_new (GST_QUERY_ACCEPT_CAPS, structure);
2033 * gst_query_parse_accept_caps:
2034 * @query: The query to parse
2035 * @caps: (out): A pointer to the caps
2037 * Get the caps from @query. The caps remains valid as long as @query remains
2041 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2043 GstStructure *structure;
2045 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2047 structure = GST_QUERY_STRUCTURE (query);
2048 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2053 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2055 GstStructure *structure;
2057 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2058 g_return_if_fail (gst_query_is_writable (query));
2060 structure = GST_QUERY_STRUCTURE (query);
2061 gst_structure_id_set (structure,
2062 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2066 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2068 GstStructure *structure;
2070 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2072 structure = GST_QUERY_STRUCTURE (query);
2073 gst_structure_id_get (structure,
2074 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2078 * gst_query_new_caps
2081 * Constructs a new query object for querying the caps.
2083 * The CAPS query should return the* allowable caps for a pad in the context
2084 * of the element's state, its link to other elements, and the devices or files
2085 * it has opened. These caps must be a subset of the pad template caps. In the
2086 * NULL state with no links, the CAPS query should ideally return the same caps
2087 * as the pad template. In rare circumstances, an object property can affect
2088 * the caps returned by the CAPS query, but this is discouraged.
2090 * For most filters, the caps returned by CAPS query is directly affected by the
2091 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2092 * the srcpad's getcaps function is directly related to the stream data. Again,
2093 * the CAPS query should return the most specific caps it reasonably can, since this
2094 * helps with autoplugging.
2096 * Free-function: gst_query_unref
2098 * Returns: (transfer full): a new #GstQuery
2101 gst_query_new_caps (GstCaps * filter)
2104 GstStructure *structure;
2106 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2107 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2108 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2109 query = gst_query_new (GST_QUERY_CAPS, structure);
2115 * gst_query_parse_caps:
2116 * @query: The query to parse
2117 * @filter: (out): A pointer to the caps filter
2119 * Get the filter from the caps @query. The caps remains valid as long as
2120 * @query remains valid.
2123 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2125 GstStructure *structure;
2127 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2129 structure = GST_QUERY_STRUCTURE (query);
2130 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2131 GST_QUARK (FILTER)));
2135 * gst_query_set_caps_result:
2136 * @query: The query to use
2137 * @caps: (in): A pointer to the caps
2139 * Set the @caps result in @query.
2142 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2144 GstStructure *structure;
2146 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2147 g_return_if_fail (gst_query_is_writable (query));
2149 structure = GST_QUERY_STRUCTURE (query);
2150 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2154 * gst_query_parse_caps_result:
2155 * @query: The query to parse
2156 * @caps: (out): A pointer to the caps
2158 * Get the caps result from @query. The caps remains valid as long as
2159 * @query remains valid.
2162 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2164 GstStructure *structure;
2166 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2168 structure = GST_QUERY_STRUCTURE (query);
2169 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2174 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2175 GstCapsIntersectMode mode)
2177 GstCaps *res, *caps;
2179 gst_query_parse_caps_result (query, &caps);
2180 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2181 gst_query_set_caps_result (query, res);
2182 gst_caps_unref (res);