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_NONE, NULL, NULL, 0}
112 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
115 _priv_gst_query_initialize (void)
117 GstQueryTypeDefinition *standards = standard_definitions;
119 GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
121 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
123 g_static_mutex_lock (&mutex);
124 if (_nick_to_query == NULL) {
125 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
126 _query_type_to_nick = g_hash_table_new (NULL, NULL);
129 while (standards->nick) {
130 standards->quark = g_quark_from_static_string (standards->nick);
131 g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
132 g_hash_table_insert (_query_type_to_nick,
133 GINT_TO_POINTER (standards->value), standards);
135 _gst_queries = g_list_append (_gst_queries, standards);
139 g_static_mutex_unlock (&mutex);
141 _gst_query_type = gst_query_get_type ();
145 * gst_query_type_get_name:
146 * @query: the query type
148 * Get a printable name for the given query type. Do not modify or free.
150 * Returns: a reference to the static name of the query.
153 gst_query_type_get_name (GstQueryType query)
155 const GstQueryTypeDefinition *def;
157 def = gst_query_type_get_details (query);
158 g_return_val_if_fail (def != NULL, NULL);
164 * gst_query_type_to_quark:
165 * @query: the query type
167 * Get the unique quark for the given query type.
169 * Returns: the quark associated with the query type
172 gst_query_type_to_quark (GstQueryType query)
174 const GstQueryTypeDefinition *def;
176 def = gst_query_type_get_details (query);
177 g_return_val_if_fail (def != NULL, 0);
183 * gst_query_type_register:
184 * @nick: The nick of the new query
185 * @description: The description of the new query
187 * Create a new GstQueryType based on the nick or return an
188 * already registered query with that nick
190 * Returns: A new GstQueryType or an already registered query
191 * with the same nick.
194 gst_query_type_register (const gchar * nick, const gchar * description)
196 GstQueryTypeDefinition *query;
199 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
200 g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
202 lookup = gst_query_type_get_by_nick (nick);
203 if (lookup != GST_QUERY_NONE)
206 query = g_slice_new (GstQueryTypeDefinition);
207 query->value = (GstQueryType) _n_values;
208 query->nick = g_strdup (nick);
209 query->description = g_strdup (description);
210 query->quark = g_quark_from_static_string (query->nick);
212 g_static_mutex_lock (&mutex);
213 g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
214 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
216 _gst_queries = g_list_append (_gst_queries, query);
218 g_static_mutex_unlock (&mutex);
224 * gst_query_type_get_by_nick:
225 * @nick: The nick of the query
227 * Get the query type registered with @nick.
229 * Returns: The query registered with @nick or #GST_QUERY_NONE
230 * if the query was not registered.
233 gst_query_type_get_by_nick (const gchar * nick)
235 GstQueryTypeDefinition *query;
237 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
239 g_static_mutex_lock (&mutex);
240 query = g_hash_table_lookup (_nick_to_query, nick);
241 g_static_mutex_unlock (&mutex);
246 return GST_QUERY_NONE;
250 * gst_query_types_contains:
251 * @types: The query array to search
252 * @type: the #GstQueryType to find
254 * See if the given #GstQueryType is inside the @types query types array.
256 * Returns: TRUE if the type is found inside the array
259 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
275 * gst_query_type_get_details:
276 * @type: a #GstQueryType
278 * Get details about the given #GstQueryType.
280 * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
282 const GstQueryTypeDefinition *
283 gst_query_type_get_details (GstQueryType type)
285 const GstQueryTypeDefinition *result;
287 g_static_mutex_lock (&mutex);
288 result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
289 g_static_mutex_unlock (&mutex);
295 * gst_query_type_iterate_definitions:
297 * Get a #GstIterator of all the registered query types. The definitions
298 * iterated over are read only.
300 * Free-function: gst_iterator_free
302 * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
305 gst_query_type_iterate_definitions (void)
309 g_static_mutex_lock (&mutex);
310 /* FIXME: register a boxed type for GstQueryTypeDefinition */
311 result = gst_iterator_new_list (G_TYPE_POINTER,
312 g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries, NULL, NULL);
313 g_static_mutex_unlock (&mutex);
319 _gst_query_free (GstQuery * query)
323 g_return_if_fail (query != NULL);
325 s = GST_QUERY_STRUCTURE (query);
327 gst_structure_set_parent_refcount (s, NULL);
328 gst_structure_free (s);
331 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
334 static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
337 _gst_query_copy (GstQuery * query)
341 copy = gst_query_new (query->type, GST_QUERY_STRUCTURE (query));
347 gst_query_new (GstQueryType type, GstStructure * structure)
351 query = g_slice_new0 (GstQueryImpl);
353 gst_mini_object_init (GST_MINI_OBJECT_CAST (query),
354 _gst_query_type, sizeof (GstQueryImpl));
356 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
357 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
359 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
361 GST_QUERY_TYPE (query) = type;
362 query->structure = structure;
365 gst_structure_set_parent_refcount (structure,
366 &query->query.mini_object.refcount);
368 return GST_QUERY_CAST (query);
372 * gst_query_new_position:
373 * @format: the default #GstFormat for the new query
375 * Constructs a new query stream position query object. Use gst_query_unref()
376 * when done with it. A position query is used to query the current position
377 * of playback in the streams, in some format.
379 * Free-function: gst_query_unref
381 * Returns: (transfer full): a new #GstQuery
384 gst_query_new_position (GstFormat format)
387 GstStructure *structure;
389 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
390 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
391 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
393 query = gst_query_new (GST_QUERY_POSITION, structure);
399 * gst_query_set_position:
400 * @query: a #GstQuery with query type GST_QUERY_POSITION
401 * @format: the requested #GstFormat
402 * @cur: the position to set
404 * Answer a position query by setting the requested value in the given format.
407 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
411 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
413 s = GST_QUERY_STRUCTURE (query);
414 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
415 GST_QUARK (FORMAT))));
417 gst_structure_id_set (s,
418 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
419 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
423 * gst_query_parse_position:
424 * @query: a #GstQuery
425 * @format: (out) (allow-none): the storage for the #GstFormat of the
426 * position values (may be NULL)
427 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
429 * Parse a position query, writing the format into @format, and the position
430 * into @cur, if the respective parameters are non-NULL.
433 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
435 GstStructure *structure;
437 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
439 structure = GST_QUERY_STRUCTURE (query);
442 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
443 GST_QUARK (FORMAT)));
445 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
446 GST_QUARK (CURRENT)));
451 * gst_query_new_duration:
452 * @format: the #GstFormat for this duration query
454 * Constructs a new stream duration query object to query in the given format.
455 * Use gst_query_unref() when done with it. A duration query will give the
456 * total length of the stream.
458 * Free-function: gst_query_unref
460 * Returns: (transfer full): a new #GstQuery
463 gst_query_new_duration (GstFormat format)
466 GstStructure *structure;
468 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
469 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
470 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
472 query = gst_query_new (GST_QUERY_DURATION, structure);
478 * gst_query_set_duration:
479 * @query: a #GstQuery
480 * @format: the #GstFormat for the duration
481 * @duration: the duration of the stream
483 * Answer a duration query by setting the requested value in the given format.
486 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
490 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
492 s = GST_QUERY_STRUCTURE (query);
493 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
494 GST_QUARK (FORMAT))));
495 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
496 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
500 * gst_query_parse_duration:
501 * @query: a #GstQuery
502 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
504 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
506 * Parse a duration query answer. Write the format of the duration into @format,
507 * and the value into @duration, if the respective variables are non-NULL.
510 gst_query_parse_duration (GstQuery * query, GstFormat * format,
513 GstStructure *structure;
515 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
517 structure = GST_QUERY_STRUCTURE (query);
520 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
521 GST_QUARK (FORMAT)));
523 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
524 GST_QUARK (DURATION)));
528 * gst_query_new_latency:
530 * Constructs a new latency query object.
531 * Use gst_query_unref() when done with it. A latency query is usually performed
532 * by sinks to compensate for additional latency introduced by elements in the
535 * Free-function: gst_query_unref
537 * Returns: (transfer full): a #GstQuery
542 gst_query_new_latency (void)
545 GstStructure *structure;
547 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
548 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
549 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
550 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
552 query = gst_query_new (GST_QUERY_LATENCY, structure);
558 * gst_query_set_latency:
559 * @query: a #GstQuery
560 * @live: if there is a live element upstream
561 * @min_latency: the minimal latency of the live element
562 * @max_latency: the maximal latency of the live element
564 * Answer a latency query by setting the requested values in the given format.
569 gst_query_set_latency (GstQuery * query, gboolean live,
570 GstClockTime min_latency, GstClockTime max_latency)
572 GstStructure *structure;
574 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
576 structure = GST_QUERY_STRUCTURE (query);
577 gst_structure_id_set (structure,
578 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
579 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
580 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
584 * gst_query_parse_latency:
585 * @query: a #GstQuery
586 * @live: (out) (allow-none): storage for live or NULL
587 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
588 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
590 * Parse a latency query answer.
595 gst_query_parse_latency (GstQuery * query, gboolean * live,
596 GstClockTime * min_latency, GstClockTime * max_latency)
598 GstStructure *structure;
600 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
602 structure = GST_QUERY_STRUCTURE (query);
605 g_value_get_boolean (gst_structure_id_get_value (structure,
608 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
609 GST_QUARK (MIN_LATENCY)));
611 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
612 GST_QUARK (MAX_LATENCY)));
616 * gst_query_new_convert:
617 * @src_format: the source #GstFormat for the new query
618 * @value: the value to convert
619 * @dest_format: the target #GstFormat
621 * Constructs a new convert query object. Use gst_query_unref()
622 * when done with it. A convert query is used to ask for a conversion between
623 * one format and another.
625 * Free-function: gst_query_unref
627 * Returns: (transfer full): a #GstQuery
630 gst_query_new_convert (GstFormat src_format, gint64 value,
631 GstFormat dest_format)
634 GstStructure *structure;
636 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
637 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
638 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
639 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
640 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
642 query = gst_query_new (GST_QUERY_CONVERT, structure);
648 * gst_query_set_convert:
649 * @query: a #GstQuery
650 * @src_format: the source #GstFormat
651 * @src_value: the source value
652 * @dest_format: the destination #GstFormat
653 * @dest_value: the destination value
655 * Answer a convert query by setting the requested values.
658 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
659 GstFormat dest_format, gint64 dest_value)
661 GstStructure *structure;
663 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
665 structure = GST_QUERY_STRUCTURE (query);
666 gst_structure_id_set (structure,
667 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
668 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
669 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
670 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
674 * gst_query_parse_convert:
675 * @query: a #GstQuery
676 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
677 * source value, or NULL
678 * @src_value: (out) (allow-none): the storage for the source value, or NULL
679 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
680 * destination value, or NULL
681 * @dest_value: (out) (allow-none): the storage for the destination value,
684 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
685 * and @dest_value may be NULL, in which case that value is omitted.
688 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
689 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
691 GstStructure *structure;
693 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
695 structure = GST_QUERY_STRUCTURE (query);
698 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
699 GST_QUARK (SRC_FORMAT)));
701 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
702 GST_QUARK (SRC_VALUE)));
705 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
706 GST_QUARK (DEST_FORMAT)));
708 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
709 GST_QUARK (DEST_VALUE)));
713 * gst_query_new_segment:
714 * @format: the #GstFormat for the new query
716 * Constructs a new segment query object. Use gst_query_unref()
717 * when done with it. A segment query is used to discover information about the
718 * currently configured segment for playback.
720 * Free-function: gst_query_unref
722 * Returns: (transfer full): a new #GstQuery
725 gst_query_new_segment (GstFormat format)
728 GstStructure *structure;
730 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
731 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
732 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
733 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
734 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
736 query = gst_query_new (GST_QUERY_SEGMENT, structure);
742 * gst_query_set_segment:
743 * @query: a #GstQuery
744 * @rate: the rate of the segment
745 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
746 * @start_value: the start value
747 * @stop_value: the stop value
749 * Answer a segment query by setting the requested values. The normal
750 * playback segment of a pipeline is 0 to duration at the default rate of
751 * 1.0. If a seek was performed on the pipeline to play a different
752 * segment, this query will return the range specified in the last seek.
754 * @start_value and @stop_value will respectively contain the configured
755 * playback range start and stop values expressed in @format.
756 * The values are always between 0 and the duration of the media and
757 * @start_value <= @stop_value. @rate will contain the playback rate. For
758 * negative rates, playback will actually happen from @stop_value to
762 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
763 gint64 start_value, gint64 stop_value)
765 GstStructure *structure;
767 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
769 structure = GST_QUERY_STRUCTURE (query);
770 gst_structure_id_set (structure,
771 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
772 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
773 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
774 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
778 * gst_query_parse_segment:
779 * @query: a #GstQuery
780 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
781 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
783 * @start_value: (out) (allow-none): the storage for the start value, or NULL
784 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
786 * Parse a segment query answer. Any of @rate, @format, @start_value, and
787 * @stop_value may be NULL, which will cause this value to be omitted.
789 * See gst_query_set_segment() for an explanation of the function arguments.
792 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
793 gint64 * start_value, gint64 * stop_value)
795 GstStructure *structure;
797 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
799 structure = GST_QUERY_STRUCTURE (query);
801 *rate = g_value_get_double (gst_structure_id_get_value (structure,
805 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
806 GST_QUARK (FORMAT)));
808 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
809 GST_QUARK (START_VALUE)));
811 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
812 GST_QUARK (STOP_VALUE)));
816 * gst_query_new_custom:
817 * @type: the query type
818 * @structure: a structure for the query
820 * Constructs a new custom query object. Use gst_query_unref()
823 * Free-function: gst_query_unref
825 * Returns: (transfer full): a new #GstQuery
828 gst_query_new_custom (GstQueryType type, GstStructure * structure)
830 g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
831 g_return_val_if_fail (structure != NULL, NULL);
833 return gst_query_new (type, structure);
837 * gst_query_get_structure:
838 * @query: a #GstQuery
840 * Get the structure of a query.
842 * Returns: (transfer none): the #GstStructure of the query. The structure is
843 * still owned by the query and will therefore be freed when the query
847 gst_query_get_structure (GstQuery * query)
849 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
851 return GST_QUERY_STRUCTURE (query);
855 * gst_query_writable_structure:
856 * @query: a #GstQuery
858 * Get the structure of a query.
860 * Returns: (transfer none): the #GstStructure of the query. The structure is
861 * still owned by the query and will therefore be freed when the query
865 gst_query_writable_structure (GstQuery * query)
867 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
868 g_return_val_if_fail (gst_query_is_writable (query), NULL);
870 return GST_QUERY_STRUCTURE (query);
874 * gst_query_new_seeking:
875 * @format: the default #GstFormat for the new query
877 * Constructs a new query object for querying seeking properties of
880 * Free-function: gst_query_unref
882 * Returns: (transfer full): a new #GstQuery
885 gst_query_new_seeking (GstFormat format)
888 GstStructure *structure;
890 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
891 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
892 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
893 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
894 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
896 query = gst_query_new (GST_QUERY_SEEKING, structure);
902 * gst_query_set_seeking:
903 * @query: a #GstQuery
904 * @format: the format to set for the @segment_start and @segment_end values
905 * @seekable: the seekable flag to set
906 * @segment_start: the segment_start to set
907 * @segment_end: the segment_end to set
909 * Set the seeking query result fields in @query.
912 gst_query_set_seeking (GstQuery * query, GstFormat format,
913 gboolean seekable, gint64 segment_start, gint64 segment_end)
915 GstStructure *structure;
917 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
918 g_return_if_fail (gst_query_is_writable (query));
920 structure = GST_QUERY_STRUCTURE (query);
921 gst_structure_id_set (structure,
922 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
923 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
924 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
925 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
929 * gst_query_parse_seeking:
930 * @query: a GST_QUERY_SEEKING type query #GstQuery
931 * @format: (out) (allow-none): the format to set for the @segment_start
932 * and @segment_end values, or NULL
933 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
934 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
935 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
937 * Parse a seeking query, writing the format into @format, and
938 * other results into the passed parameters, if the respective parameters
942 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
943 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
945 GstStructure *structure;
947 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
949 structure = GST_QUERY_STRUCTURE (query);
952 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
953 GST_QUARK (FORMAT)));
955 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
956 GST_QUARK (SEEKABLE)));
958 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
959 GST_QUARK (SEGMENT_START)));
961 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
962 GST_QUARK (SEGMENT_END)));
966 * gst_query_new_formats:
968 * Constructs a new query object for querying formats of
971 * Free-function: gst_query_unref
973 * Returns: (transfer full): a new #GstQuery
978 gst_query_new_formats (void)
981 GstStructure *structure;
983 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
984 query = gst_query_new (GST_QUERY_FORMATS, structure);
990 gst_query_list_add_format (GValue * list, GstFormat format)
992 GValue item = { 0, };
994 g_value_init (&item, GST_TYPE_FORMAT);
995 g_value_set_enum (&item, format);
996 gst_value_list_append_value (list, &item);
997 g_value_unset (&item);
1001 * gst_query_set_formats:
1002 * @query: a #GstQuery
1003 * @n_formats: the number of formats to set.
1004 * @...: A number of @GstFormats equal to @n_formats.
1006 * Set the formats query result fields in @query. The number of formats passed
1007 * must be equal to @n_formats.
1010 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1013 GValue list = { 0, };
1015 GstStructure *structure;
1017 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1018 g_return_if_fail (gst_query_is_writable (query));
1020 g_value_init (&list, GST_TYPE_LIST);
1022 va_start (ap, n_formats);
1023 for (i = 0; i < n_formats; i++) {
1024 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1028 structure = GST_QUERY_STRUCTURE (query);
1029 gst_structure_set_value (structure, "formats", &list);
1031 g_value_unset (&list);
1036 * gst_query_set_formatsv:
1037 * @query: a #GstQuery
1038 * @n_formats: the number of formats to set.
1039 * @formats: (in) (array length=n_formats): an array containing @n_formats
1040 * @GstFormat values.
1042 * Set the formats query result fields in @query. The number of formats passed
1043 * in the @formats array must be equal to @n_formats.
1048 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1049 const GstFormat * formats)
1051 GValue list = { 0, };
1053 GstStructure *structure;
1055 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1056 g_return_if_fail (gst_query_is_writable (query));
1058 g_value_init (&list, GST_TYPE_LIST);
1059 for (i = 0; i < n_formats; i++) {
1060 gst_query_list_add_format (&list, formats[i]);
1062 structure = GST_QUERY_STRUCTURE (query);
1063 gst_structure_set_value (structure, "formats", &list);
1065 g_value_unset (&list);
1069 * gst_query_parse_n_formats:
1070 * @query: a #GstQuery
1071 * @n_formats: (out): the number of formats in this query.
1073 * Parse the number of formats in the formats @query.
1078 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1080 GstStructure *structure;
1082 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1087 structure = GST_QUERY_STRUCTURE (query);
1088 list = gst_structure_get_value (structure, "formats");
1092 *n_formats = gst_value_list_get_size (list);
1097 * gst_query_parse_nth_format:
1098 * @query: a #GstQuery
1099 * @nth: (out): the nth format to retrieve.
1100 * @format: (out): a pointer to store the nth format
1102 * Parse the format query and retrieve the @nth format from it into
1103 * @format. If the list contains less elements than @nth, @format will be
1104 * set to GST_FORMAT_UNDEFINED.
1107 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1109 GstStructure *structure;
1111 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1116 structure = GST_QUERY_STRUCTURE (query);
1117 list = gst_structure_get_value (structure, "formats");
1119 *format = GST_FORMAT_UNDEFINED;
1121 if (nth < gst_value_list_get_size (list)) {
1123 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1125 *format = GST_FORMAT_UNDEFINED;
1131 * gst_query_new_buffering
1132 * @format: the default #GstFormat for the new query
1134 * Constructs a new query object for querying the buffering status of
1137 * Free-function: gst_query_unref
1139 * Returns: (transfer full): a new #GstQuery
1144 gst_query_new_buffering (GstFormat format)
1147 GstStructure *structure;
1149 /* by default, we configure the answer as no buffering with a 100% buffering
1151 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1152 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1153 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1154 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1155 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1156 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1157 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1158 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1159 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1160 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1161 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1163 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1169 * gst_query_set_buffering_percent
1170 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1171 * @busy: if buffering is busy
1172 * @percent: a buffering percent
1174 * Set the percentage of buffered data. This is a value between 0 and 100.
1175 * The @busy indicator is %TRUE when the buffering is in progress.
1180 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1182 GstStructure *structure;
1184 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1185 g_return_if_fail (gst_query_is_writable (query));
1186 g_return_if_fail (percent >= 0 && percent <= 100);
1188 structure = GST_QUERY_STRUCTURE (query);
1189 gst_structure_id_set (structure,
1190 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1191 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1195 * gst_query_parse_buffering_percent
1196 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1197 * @busy: (out) (allow-none): if buffering is busy, or NULL
1198 * @percent: (out) (allow-none): a buffering percent, or NULL
1200 * Get the percentage of buffered data. This is a value between 0 and 100.
1201 * The @busy indicator is %TRUE when the buffering is in progress.
1206 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1209 GstStructure *structure;
1211 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1213 structure = GST_QUERY_STRUCTURE (query);
1215 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1218 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1219 GST_QUARK (BUFFER_PERCENT)));
1223 * gst_query_set_buffering_stats:
1224 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1225 * @mode: a buffering mode
1226 * @avg_in: the average input rate
1227 * @avg_out: the average output rate
1228 * @buffering_left: amount of buffering time left
1230 * Configures the buffering stats values in @query.
1235 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1236 gint avg_in, gint avg_out, gint64 buffering_left)
1238 GstStructure *structure;
1240 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1241 g_return_if_fail (gst_query_is_writable (query));
1243 structure = GST_QUERY_STRUCTURE (query);
1244 gst_structure_id_set (structure,
1245 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1246 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1247 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1248 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1252 * gst_query_parse_buffering_stats:
1253 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1254 * @mode: (out) (allow-none): a buffering mode, or NULL
1255 * @avg_in: (out) (allow-none): the average input rate, or NULL
1256 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1257 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1259 * Extracts the buffering stats values from @query.
1264 gst_query_parse_buffering_stats (GstQuery * query,
1265 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1266 gint64 * buffering_left)
1268 GstStructure *structure;
1270 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1272 structure = GST_QUERY_STRUCTURE (query);
1274 *mode = (GstBufferingMode)
1275 g_value_get_enum (gst_structure_id_get_value (structure,
1276 GST_QUARK (BUFFERING_MODE)));
1278 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1279 GST_QUARK (AVG_IN_RATE)));
1281 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1282 GST_QUARK (AVG_OUT_RATE)));
1285 g_value_get_int64 (gst_structure_id_get_value (structure,
1286 GST_QUARK (BUFFERING_LEFT)));
1291 * gst_query_set_buffering_range:
1292 * @query: a #GstQuery
1293 * @format: the format to set for the @start and @stop values
1294 * @start: the start to set
1295 * @stop: the stop to set
1296 * @estimated_total: estimated total amount of download time
1298 * Set the available query result fields in @query.
1303 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1304 gint64 start, gint64 stop, gint64 estimated_total)
1306 GstStructure *structure;
1308 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1309 g_return_if_fail (gst_query_is_writable (query));
1311 structure = GST_QUERY_STRUCTURE (query);
1312 gst_structure_id_set (structure,
1313 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1314 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1315 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1316 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1320 * gst_query_parse_buffering_range:
1321 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1322 * @format: (out) (allow-none): the format to set for the @segment_start
1323 * and @segment_end values, or NULL
1324 * @start: (out) (allow-none): the start to set, or NULL
1325 * @stop: (out) (allow-none): the stop to set, or NULL
1326 * @estimated_total: (out) (allow-none): estimated total amount of download
1329 * Parse an available query, writing the format into @format, and
1330 * other results into the passed parameters, if the respective parameters
1336 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1337 gint64 * start, gint64 * stop, gint64 * estimated_total)
1339 GstStructure *structure;
1341 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1343 structure = GST_QUERY_STRUCTURE (query);
1346 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1347 GST_QUARK (FORMAT)));
1349 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1350 GST_QUARK (START_VALUE)));
1352 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1353 GST_QUARK (STOP_VALUE)));
1354 if (estimated_total)
1356 g_value_get_int64 (gst_structure_id_get_value (structure,
1357 GST_QUARK (ESTIMATED_TOTAL)));
1361 * gst_query_add_buffering_range
1362 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1363 * @start: start position of the range
1364 * @stop: stop position of the range
1366 * Set the buffering-ranges array field in @query. The current last
1367 * start position of the array should be inferior to @start.
1369 * Returns: a #gboolean indicating if the range was added or not.
1374 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1377 GValue *last_array_value;
1378 const GValue *value;
1379 GValue range_value = { 0 };
1380 GstStructure *structure;
1382 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1383 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1385 if (G_UNLIKELY (start >= stop))
1388 structure = GST_QUERY_STRUCTURE (query);
1389 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1391 array = (GValueArray *) g_value_get_boxed (value);
1392 last_array_value = g_value_array_get_nth (array, array->n_values - 1);
1393 if (G_UNLIKELY (start <= gst_value_get_int64_range_min (last_array_value)))
1396 GValue new_array_val = { 0, };
1398 array = g_value_array_new (0);
1400 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1401 g_value_take_boxed (&new_array_val, array);
1403 /* set the value array only once, so we then modify (append to) the
1404 * existing value array owned by the GstStructure / the field's GValue */
1405 gst_structure_id_take_value (structure, GST_QUARK (BUFFERING_RANGES),
1409 g_value_init (&range_value, GST_TYPE_INT64_RANGE);
1410 gst_value_set_int64_range (&range_value, start, stop);
1411 g_value_array_append (array, &range_value);
1412 /* skip the g_value_unset(&range_value) here, we know it's not needed */
1418 * gst_query_get_n_buffering_ranges
1419 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1421 * Retrieve the number of values currently stored in the
1422 * buffered-ranges array of the query's structure.
1424 * Returns: the range array size as a #guint.
1429 gst_query_get_n_buffering_ranges (GstQuery * query)
1432 const GValue *value;
1434 GstStructure *structure;
1436 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1438 structure = GST_QUERY_STRUCTURE (query);
1439 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1441 array = (GValueArray *) g_value_get_boxed (value);
1442 size = array->n_values;
1449 * gst_query_parse_nth_buffering_range
1450 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1451 * @index: position in the buffered-ranges array to read
1452 * @start: (out) (allow-none): the start position to set, or NULL
1453 * @stop: (out) (allow-none): the stop position to set, or NULL
1455 * Parse an available query and get the start and stop values stored
1456 * at the @index of the buffered ranges array.
1458 * Returns: a #gboolean indicating if the parsing succeeded.
1463 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1464 gint64 * start, gint64 * stop)
1466 const GValue *value;
1467 GValueArray *ranges;
1468 GValue *range_value;
1469 gboolean ret = FALSE;
1470 GstStructure *structure;
1472 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1474 structure = GST_QUERY_STRUCTURE (query);
1475 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1476 ranges = (GValueArray *) g_value_get_boxed (value);
1477 range_value = g_value_array_get_nth (ranges, index);
1480 *start = gst_value_get_int64_range_min (range_value);
1482 *stop = gst_value_get_int64_range_max (range_value);
1491 * gst_query_new_uri:
1493 * Constructs a new query URI query object. Use gst_query_unref()
1494 * when done with it. An URI query is used to query the current URI
1495 * that is used by the source or sink.
1497 * Free-function: gst_query_unref
1499 * Returns: (transfer full): a new #GstQuery
1504 gst_query_new_uri (void)
1507 GstStructure *structure;
1509 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1510 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1512 query = gst_query_new (GST_QUERY_URI, structure);
1518 * gst_query_set_uri:
1519 * @query: a #GstQuery with query type GST_QUERY_URI
1520 * @uri: the URI to set
1522 * Answer a URI query by setting the requested URI.
1527 gst_query_set_uri (GstQuery * query, const gchar * uri)
1529 GstStructure *structure;
1531 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1532 g_return_if_fail (gst_query_is_writable (query));
1533 g_return_if_fail (gst_uri_is_valid (uri));
1535 structure = GST_QUERY_STRUCTURE (query);
1536 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1540 * gst_query_parse_uri:
1541 * @query: a #GstQuery
1542 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1545 * Parse an URI query, writing the URI into @uri as a newly
1546 * allocated string, if the respective parameters are non-NULL.
1547 * Free the string with g_free() after usage.
1552 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1554 GstStructure *structure;
1556 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1558 structure = GST_QUERY_STRUCTURE (query);
1560 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1565 * gst_query_new_allocation
1566 * @caps: the negotiated caps
1567 * @need_pool: return a pool
1569 * Constructs a new query object for querying the allocation properties.
1571 * Free-function: gst_query_unref
1573 * Returns: (transfer full): a new #GstQuery
1576 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1579 GstStructure *structure;
1581 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1582 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1583 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1584 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1585 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1586 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1587 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1588 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1589 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1591 query = gst_query_new (GST_QUERY_ALLOCATION, structure);
1597 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1598 gboolean * need_pool)
1600 GstStructure *structure;
1602 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1604 structure = GST_QUERY_STRUCTURE (query);
1605 gst_structure_id_get (structure,
1606 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1607 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1611 * gst_query_set_allocation_params
1612 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1614 * @min_buffers: the min buffers
1615 * @max_buffers: the max buffers
1616 * @prefix: the prefix
1617 * @alignment: the alignment
1618 * @pool: the #GstBufferPool
1620 * Set the allocation parameters in @query.
1623 gst_query_set_allocation_params (GstQuery * query, guint size,
1624 guint min_buffers, guint max_buffers, guint prefix,
1625 guint alignment, GstBufferPool * pool)
1627 GstStructure *structure;
1629 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1630 g_return_if_fail (gst_query_is_writable (query));
1631 g_return_if_fail (((alignment + 1) & alignment) == 0);
1632 g_return_if_fail (size != 0 || pool == NULL);
1634 structure = GST_QUERY_STRUCTURE (query);
1635 gst_structure_id_set (structure,
1636 GST_QUARK (SIZE), G_TYPE_UINT, size,
1637 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1638 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1639 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1640 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1641 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1645 * gst_query_parse_allocation_params
1646 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1648 * @min_buffers: the min buffers
1649 * @max_buffers: the max buffers
1650 * @prefix: the prefix
1651 * @alignment: the alignment
1652 * @pool: the #GstBufferPool
1654 * Get the allocation parameters in @query.
1657 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1658 guint * min_buffers, guint * max_buffers, guint * prefix,
1659 guint * alignment, GstBufferPool ** pool)
1661 GstStructure *structure;
1663 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1665 structure = GST_QUERY_STRUCTURE (query);
1666 gst_structure_id_get (structure,
1667 GST_QUARK (SIZE), G_TYPE_UINT, size,
1668 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1669 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1670 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1671 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1672 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1676 * gst_query_add_allocation_meta
1677 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1678 * @api: the metadata API
1680 * Add @api as aone of the supported metadata API to @query.
1683 gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
1686 const GValue *value;
1687 GValue api_value = { 0 };
1688 GstStructure *structure;
1690 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1691 g_return_if_fail (api != NULL);
1692 g_return_if_fail (gst_query_is_writable (query));
1694 structure = GST_QUERY_STRUCTURE (query);
1695 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1697 array = (GValueArray *) g_value_get_boxed (value);
1699 GValue new_array_val = { 0, };
1701 array = g_value_array_new (0);
1703 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1704 g_value_take_boxed (&new_array_val, array);
1706 gst_structure_id_take_value (structure, GST_QUARK (META), &new_array_val);
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 const GValue *value;
1730 GstStructure *structure;
1732 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1734 structure = GST_QUERY_STRUCTURE (query);
1735 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1737 array = (GValueArray *) g_value_get_boxed (value);
1738 size = array->n_values;
1744 * gst_query_parse_nth_allocation_meta
1745 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1746 * @index: position in the metadata API array to read
1748 * Parse an available query and get the metadata API
1749 * at @index of the metadata API array.
1751 * Returns: a #gchar of the metadata API at @index.
1754 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1756 const GValue *value;
1757 const gchar *ret = NULL;
1758 GstStructure *structure;
1760 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1762 structure = GST_QUERY_STRUCTURE (query);
1763 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1768 meta = (GValueArray *) g_value_get_boxed (value);
1769 api_value = g_value_array_get_nth (meta, index);
1772 ret = g_value_get_string (api_value);
1778 * gst_query_has_allocation_meta
1779 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1780 * @api: the metadata API
1782 * Check if @query has metadata @api set.
1784 * Returns: TRUE when @api is in the list of metadata.
1787 gst_query_has_allocation_meta (GstQuery * query, const gchar * api)
1789 const GValue *value;
1790 GstStructure *structure;
1792 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1793 g_return_val_if_fail (api != NULL, FALSE);
1795 structure = GST_QUERY_STRUCTURE (query);
1796 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1802 array = (GValueArray *) g_value_get_boxed (value);
1803 for (i = 0; i < array->n_values; i++) {
1804 api_value = g_value_array_get_nth (array, i);
1805 if (!strcmp (api, g_value_get_string (api_value)))
1813 * gst_query_add_allocation_memory
1814 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1815 * @alloc: the memory allocator
1817 * Add @alloc as a supported memory allocator.
1820 gst_query_add_allocation_memory (GstQuery * query, const gchar * alloc)
1823 const GValue *value;
1824 GValue alloc_value = { 0 };
1825 GstStructure *structure;
1827 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1828 g_return_if_fail (gst_query_is_writable (query));
1830 structure = GST_QUERY_STRUCTURE (query);
1831 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1833 array = (GValueArray *) g_value_get_boxed (value);
1835 GValue new_array_val = { 0, };
1837 array = g_value_array_new (0);
1839 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1840 g_value_take_boxed (&new_array_val, array);
1842 gst_structure_id_take_value (structure, GST_QUARK (ALLOCATOR),
1846 g_value_init (&alloc_value, G_TYPE_STRING);
1847 g_value_set_string (&alloc_value, alloc);
1848 g_value_array_append (array, &alloc_value);
1849 g_value_unset (&alloc_value);
1853 * gst_query_get_n_allocation_memories:
1854 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1856 * Retrieve the number of values currently stored in the
1857 * allocator array of the query's structure.
1859 * If no memory allocator is specified, the downstream element can handle
1860 * the default memory allocator.
1862 * Returns: the allocator array size as a #guint.
1865 gst_query_get_n_allocation_memories (GstQuery * query)
1868 const GValue *value;
1870 GstStructure *structure;
1872 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1874 structure = GST_QUERY_STRUCTURE (query);
1875 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1877 array = (GValueArray *) g_value_get_boxed (value);
1878 size = array->n_values;
1884 * gst_query_parse_nth_allocation_memory
1885 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1886 * @index: position in the allocator array to read
1888 * Parse an available query and get the alloctor
1889 * at @index of the allocator array.
1891 * Returns: the name of the allocator at @index.
1894 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1896 const GValue *value;
1897 const gchar *ret = NULL;
1898 GstStructure *structure;
1900 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1902 structure = GST_QUERY_STRUCTURE (query);
1903 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1905 GValueArray *memory;
1906 GValue *alloc_value;
1908 memory = (GValueArray *) g_value_get_boxed (value);
1909 alloc_value = g_value_array_get_nth (memory, index);
1912 ret = g_value_get_string (alloc_value);
1918 * gst_query_new_scheduling
1920 * Constructs a new query object for querying the scheduling properties.
1922 * Free-function: gst_query_unref
1924 * Returns: (transfer full): a new #GstQuery
1927 gst_query_new_scheduling (void)
1930 GstStructure *structure;
1932 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1933 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, FALSE,
1934 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, FALSE,
1935 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, TRUE,
1936 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1937 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1938 GST_QUARK (ALIGN), G_TYPE_INT, 1, NULL);
1939 query = gst_query_new (GST_QUERY_SCHEDULING, structure);
1945 * gst_query_set_scheduling
1946 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1947 * @pull_mode: if pull mode scheduling is supported
1948 * @random_access: if random access is possible
1949 * @sequential: if sequential access is recommended
1950 * @minsize: the suggested minimum size of pull requests
1951 * @maxsize: the suggested maximum size of pull requests
1952 * @align: the suggested alignment of pull requests
1954 * Set the scheduling properties.
1957 gst_query_set_scheduling (GstQuery * query, gboolean pull_mode,
1958 gboolean random_access, gboolean sequential,
1959 gint minsize, gint maxsize, gint align)
1961 GstStructure *structure;
1963 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1964 g_return_if_fail (gst_query_is_writable (query));
1966 structure = GST_QUERY_STRUCTURE (query);
1967 gst_structure_id_set (structure,
1968 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, pull_mode,
1969 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, random_access,
1970 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, sequential,
1971 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1972 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1973 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1977 * gst_query_parse_scheduling
1978 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1979 * @pull_mode: if pull mode scheduling is supported
1980 * @random_access: if random access is possible
1981 * @sequential: if sequential access is recommended
1982 * @minsize: the suggested minimum size of pull requests
1983 * @maxsize: the suggested maximum size of pull requests:
1984 * @align: the suggested alignment of pull requests
1986 * Set the scheduling properties.
1989 gst_query_parse_scheduling (GstQuery * query, gboolean * pull_mode,
1990 gboolean * random_access, gboolean * sequential,
1991 gint * minsize, gint * maxsize, gint * align)
1993 GstStructure *structure;
1995 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1997 structure = GST_QUERY_STRUCTURE (query);
1998 gst_structure_id_get (structure,
1999 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, pull_mode,
2000 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, random_access,
2001 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, sequential,
2002 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2003 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2004 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2008 * gst_query_new_accept_caps
2011 * Constructs a new query object for querying if @caps are accepted.
2013 * Free-function: gst_query_unref
2015 * Returns: (transfer full): a new #GstQuery
2018 gst_query_new_accept_caps (GstCaps * caps)
2021 GstStructure *structure;
2023 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2024 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2025 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2026 query = gst_query_new (GST_QUERY_ACCEPT_CAPS, structure);
2032 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2034 GstStructure *structure;
2036 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2038 structure = GST_QUERY_STRUCTURE (query);
2039 gst_structure_id_get (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2043 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2045 GstStructure *structure;
2047 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2048 g_return_if_fail (gst_query_is_writable (query));
2050 structure = GST_QUERY_STRUCTURE (query);
2051 gst_structure_id_set (structure,
2052 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2056 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2058 GstStructure *structure;
2060 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2062 structure = GST_QUERY_STRUCTURE (query);
2063 gst_structure_id_get (structure,
2064 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);