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},
112 _gst_query_initialize (void)
114 GstQueryTypeDefinition *standards = standard_definitions;
116 GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
118 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
120 g_static_mutex_lock (&mutex);
121 if (_nick_to_query == NULL) {
122 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
123 _query_type_to_nick = g_hash_table_new (NULL, NULL);
126 while (standards->nick) {
127 standards->quark = g_quark_from_static_string (standards->nick);
128 g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
129 g_hash_table_insert (_query_type_to_nick,
130 GINT_TO_POINTER (standards->value), standards);
132 _gst_queries = g_list_append (_gst_queries, standards);
136 g_static_mutex_unlock (&mutex);
138 gst_query_get_type ();
142 * gst_query_type_get_name:
143 * @query: the query type
145 * Get a printable name for the given query type. Do not modify or free.
147 * Returns: a reference to the static name of the query.
150 gst_query_type_get_name (GstQueryType query)
152 const GstQueryTypeDefinition *def;
154 def = gst_query_type_get_details (query);
155 g_return_val_if_fail (def != NULL, NULL);
161 * gst_query_type_to_quark:
162 * @query: the query type
164 * Get the unique quark for the given query type.
166 * Returns: the quark associated with the query type
169 gst_query_type_to_quark (GstQueryType query)
171 const GstQueryTypeDefinition *def;
173 def = gst_query_type_get_details (query);
174 g_return_val_if_fail (def != NULL, 0);
180 gst_query_get_type (void)
182 if (G_UNLIKELY (_gst_query_type == 0)) {
183 _gst_query_type = gst_mini_object_register ("GstQuery");
185 return _gst_query_type;
190 * gst_query_type_register:
191 * @nick: The nick of the new query
192 * @description: The description of the new query
194 * Create a new GstQueryType based on the nick or return an
195 * already registered query with that nick
197 * Returns: A new GstQueryType or an already registered query
198 * with the same nick.
201 gst_query_type_register (const gchar * nick, const gchar * description)
203 GstQueryTypeDefinition *query;
206 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
207 g_return_val_if_fail (description != NULL, GST_QUERY_NONE);
209 lookup = gst_query_type_get_by_nick (nick);
210 if (lookup != GST_QUERY_NONE)
213 query = g_slice_new (GstQueryTypeDefinition);
214 query->value = _n_values;
215 query->nick = g_strdup (nick);
216 query->description = g_strdup (description);
217 query->quark = g_quark_from_static_string (query->nick);
219 g_static_mutex_lock (&mutex);
220 g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
221 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
223 _gst_queries = g_list_append (_gst_queries, query);
225 g_static_mutex_unlock (&mutex);
231 * gst_query_type_get_by_nick:
232 * @nick: The nick of the query
234 * Get the query type registered with @nick.
236 * Returns: The query registered with @nick or #GST_QUERY_NONE
237 * if the query was not registered.
240 gst_query_type_get_by_nick (const gchar * nick)
242 GstQueryTypeDefinition *query;
244 g_return_val_if_fail (nick != NULL, GST_QUERY_NONE);
246 g_static_mutex_lock (&mutex);
247 query = g_hash_table_lookup (_nick_to_query, nick);
248 g_static_mutex_unlock (&mutex);
253 return GST_QUERY_NONE;
257 * gst_query_types_contains:
258 * @types: The query array to search
259 * @type: the #GstQueryType to find
261 * See if the given #GstQueryType is inside the @types query types array.
263 * Returns: TRUE if the type is found inside the array
266 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
282 * gst_query_type_get_details:
283 * @type: a #GstQueryType
285 * Get details about the given #GstQueryType.
287 * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
289 const GstQueryTypeDefinition *
290 gst_query_type_get_details (GstQueryType type)
292 const GstQueryTypeDefinition *result;
294 g_static_mutex_lock (&mutex);
295 result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
296 g_static_mutex_unlock (&mutex);
302 * gst_query_type_iterate_definitions:
304 * Get a #GstIterator of all the registered query types. The definitions
305 * iterated over are read only.
307 * Free-function: gst_iterator_free
309 * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
312 gst_query_type_iterate_definitions (void)
316 g_static_mutex_lock (&mutex);
317 /* FIXME: register a boxed type for GstQueryTypeDefinition */
318 result = gst_iterator_new_list (G_TYPE_POINTER,
319 g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries, NULL, NULL);
320 g_static_mutex_unlock (&mutex);
326 _gst_query_free (GstQuery * query)
330 g_return_if_fail (query != NULL);
332 s = GST_QUERY_STRUCTURE (query);
334 gst_structure_set_parent_refcount (s, NULL);
335 gst_structure_free (s);
338 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
341 static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
344 _gst_query_copy (GstQuery * query)
348 copy = gst_query_new (query->type, GST_QUERY_STRUCTURE (query));
354 gst_query_new (GstQueryType type, GstStructure * structure)
358 query = g_slice_new0 (GstQueryImpl);
360 gst_mini_object_init (GST_MINI_OBJECT_CAST (query),
361 _gst_query_type, sizeof (GstQueryImpl));
363 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
364 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
366 GST_DEBUG ("creating new query %p %d", query, type);
368 GST_QUERY_TYPE (query) = type;
369 query->structure = structure;
372 gst_structure_set_parent_refcount (structure,
373 &query->query.mini_object.refcount);
375 return GST_QUERY_CAST (query);
379 * gst_query_new_position:
380 * @format: the default #GstFormat for the new query
382 * Constructs a new query stream position query object. Use gst_query_unref()
383 * when done with it. A position query is used to query the current position
384 * of playback in the streams, in some format.
386 * Free-function: gst_query_unref
388 * Returns: (transfer full): a new #GstQuery
391 gst_query_new_position (GstFormat format)
394 GstStructure *structure;
396 structure = gst_structure_id_new (GST_QUARK (QUERY_POSITION),
397 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
398 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
400 query = gst_query_new (GST_QUERY_POSITION, structure);
406 * gst_query_set_position:
407 * @query: a #GstQuery with query type GST_QUERY_POSITION
408 * @format: the requested #GstFormat
409 * @cur: the position to set
411 * Answer a position query by setting the requested value in the given format.
414 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
416 GstStructure *structure;
418 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
420 structure = GST_QUERY_STRUCTURE (query);
421 gst_structure_id_set (structure,
422 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
423 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
427 * gst_query_parse_position:
428 * @query: a #GstQuery
429 * @format: (out) (allow-none): the storage for the #GstFormat of the
430 * position values (may be NULL)
431 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
433 * Parse a position query, writing the format into @format, and the position
434 * into @cur, if the respective parameters are non-NULL.
437 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
439 GstStructure *structure;
441 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
443 structure = GST_QUERY_STRUCTURE (query);
445 *format = g_value_get_enum (gst_structure_id_get_value (structure,
446 GST_QUARK (FORMAT)));
448 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
449 GST_QUARK (CURRENT)));
454 * gst_query_new_duration:
455 * @format: the #GstFormat for this duration query
457 * Constructs a new stream duration query object to query in the given format.
458 * Use gst_query_unref() when done with it. A duration query will give the
459 * total length of the stream.
461 * Free-function: gst_query_unref
463 * Returns: (transfer full): a new #GstQuery
466 gst_query_new_duration (GstFormat format)
469 GstStructure *structure;
471 structure = gst_structure_id_new (GST_QUARK (QUERY_DURATION),
472 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
473 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
475 query = gst_query_new (GST_QUERY_DURATION, structure);
481 * gst_query_set_duration:
482 * @query: a #GstQuery
483 * @format: the #GstFormat for the duration
484 * @duration: the duration of the stream
486 * Answer a duration query by setting the requested value in the given format.
489 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
491 GstStructure *structure;
493 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
495 structure = GST_QUERY_STRUCTURE (query);
496 gst_structure_id_set (structure,
497 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
498 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
502 * gst_query_parse_duration:
503 * @query: a #GstQuery
504 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
506 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
508 * Parse a duration query answer. Write the format of the duration into @format,
509 * and the value into @duration, if the respective variables are non-NULL.
512 gst_query_parse_duration (GstQuery * query, GstFormat * format,
515 GstStructure *structure;
517 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
519 structure = GST_QUERY_STRUCTURE (query);
521 *format = 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_id_new (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_id_new (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);
698 *src_format = 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)));
704 *dest_format = g_value_get_enum (gst_structure_id_get_value (structure,
705 GST_QUARK (DEST_FORMAT)));
707 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
708 GST_QUARK (DEST_VALUE)));
712 * gst_query_new_segment:
713 * @format: the #GstFormat for the new query
715 * Constructs a new segment query object. Use gst_query_unref()
716 * when done with it. A segment query is used to discover information about the
717 * currently configured segment for playback.
719 * Free-function: gst_query_unref
721 * Returns: (transfer full): a new #GstQuery
724 gst_query_new_segment (GstFormat format)
727 GstStructure *structure;
729 structure = gst_structure_id_new (GST_QUARK (QUERY_SEGMENT),
730 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
731 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
732 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
733 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
735 query = gst_query_new (GST_QUERY_SEGMENT, structure);
741 * gst_query_set_segment:
742 * @query: a #GstQuery
743 * @rate: the rate of the segment
744 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
745 * @start_value: the start value
746 * @stop_value: the stop value
748 * Answer a segment query by setting the requested values. The normal
749 * playback segment of a pipeline is 0 to duration at the default rate of
750 * 1.0. If a seek was performed on the pipeline to play a different
751 * segment, this query will return the range specified in the last seek.
753 * @start_value and @stop_value will respectively contain the configured
754 * playback range start and stop values expressed in @format.
755 * The values are always between 0 and the duration of the media and
756 * @start_value <= @stop_value. @rate will contain the playback rate. For
757 * negative rates, playback will actually happen from @stop_value to
761 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
762 gint64 start_value, gint64 stop_value)
764 GstStructure *structure;
766 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
768 structure = GST_QUERY_STRUCTURE (query);
769 gst_structure_id_set (structure,
770 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
771 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
772 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
773 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
777 * gst_query_parse_segment:
778 * @query: a #GstQuery
779 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
780 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
782 * @start_value: (out) (allow-none): the storage for the start value, or NULL
783 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
785 * Parse a segment query answer. Any of @rate, @format, @start_value, and
786 * @stop_value may be NULL, which will cause this value to be omitted.
788 * See gst_query_set_segment() for an explanation of the function arguments.
791 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
792 gint64 * start_value, gint64 * stop_value)
794 GstStructure *structure;
796 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
798 structure = GST_QUERY_STRUCTURE (query);
800 *rate = g_value_get_double (gst_structure_id_get_value (structure,
803 *format = g_value_get_enum (gst_structure_id_get_value (structure,
804 GST_QUARK (FORMAT)));
806 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
807 GST_QUARK (START_VALUE)));
809 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
810 GST_QUARK (STOP_VALUE)));
814 * gst_query_new_custom:
815 * @type: the query type
816 * @structure: a structure for the query
818 * Constructs a new custom query object. Use gst_query_unref()
821 * Free-function: gst_query_unref
823 * Returns: (transfer full): a new #GstQuery
826 gst_query_new_custom (GstQueryType type, GstStructure * structure)
828 g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
829 g_return_val_if_fail (structure != NULL, NULL);
831 return gst_query_new (type, structure);
835 * gst_query_get_structure:
836 * @query: a #GstQuery
838 * Get the structure of a query.
840 * Returns: (transfer none): the #GstStructure of the query. The structure is
841 * still owned by the query and will therefore be freed when the query
845 gst_query_get_structure (GstQuery * query)
847 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
849 return GST_QUERY_STRUCTURE (query);
853 * gst_query_writable_structure:
854 * @query: a #GstQuery
856 * Get the structure of a query.
858 * Returns: (transfer none): the #GstStructure of the query. The structure is
859 * still owned by the query and will therefore be freed when the query
863 gst_query_writable_structure (GstQuery * query)
865 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
866 g_return_val_if_fail (gst_query_is_writable (query), NULL);
868 return GST_QUERY_STRUCTURE (query);
872 * gst_query_new_seeking:
873 * @format: the default #GstFormat for the new query
875 * Constructs a new query object for querying seeking properties of
878 * Free-function: gst_query_unref
880 * Returns: (transfer full): a new #GstQuery
883 gst_query_new_seeking (GstFormat format)
886 GstStructure *structure;
888 structure = gst_structure_id_new (GST_QUARK (QUERY_SEEKING),
889 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
890 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
891 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
892 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
894 query = gst_query_new (GST_QUERY_SEEKING, structure);
900 * gst_query_set_seeking:
901 * @query: a #GstQuery
902 * @format: the format to set for the @segment_start and @segment_end values
903 * @seekable: the seekable flag to set
904 * @segment_start: the segment_start to set
905 * @segment_end: the segment_end to set
907 * Set the seeking query result fields in @query.
910 gst_query_set_seeking (GstQuery * query, GstFormat format,
911 gboolean seekable, gint64 segment_start, gint64 segment_end)
913 GstStructure *structure;
915 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
916 g_return_if_fail (gst_query_is_writable (query));
918 structure = GST_QUERY_STRUCTURE (query);
919 gst_structure_id_set (structure,
920 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
921 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
922 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
923 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
927 * gst_query_parse_seeking:
928 * @query: a GST_QUERY_SEEKING type query #GstQuery
929 * @format: (out) (allow-none): the format to set for the @segment_start
930 * and @segment_end values, or NULL
931 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
932 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
933 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
935 * Parse a seeking query, writing the format into @format, and
936 * other results into the passed parameters, if the respective parameters
940 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
941 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
943 GstStructure *structure;
945 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
947 structure = GST_QUERY_STRUCTURE (query);
949 *format = g_value_get_enum (gst_structure_id_get_value (structure,
950 GST_QUARK (FORMAT)));
952 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
953 GST_QUARK (SEEKABLE)));
955 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
956 GST_QUARK (SEGMENT_START)));
958 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
959 GST_QUARK (SEGMENT_END)));
963 * gst_query_new_formats:
965 * Constructs a new query object for querying formats of
968 * Free-function: gst_query_unref
970 * Returns: (transfer full): a new #GstQuery
975 gst_query_new_formats (void)
978 GstStructure *structure;
980 structure = gst_structure_id_empty_new (GST_QUARK (QUERY_FORMATS));
981 query = gst_query_new (GST_QUERY_FORMATS, structure);
987 gst_query_list_add_format (GValue * list, GstFormat format)
989 GValue item = { 0, };
991 g_value_init (&item, GST_TYPE_FORMAT);
992 g_value_set_enum (&item, format);
993 gst_value_list_append_value (list, &item);
994 g_value_unset (&item);
998 * gst_query_set_formats:
999 * @query: a #GstQuery
1000 * @n_formats: the number of formats to set.
1001 * @...: A number of @GstFormats equal to @n_formats.
1003 * Set the formats query result fields in @query. The number of formats passed
1004 * must be equal to @n_formats.
1007 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
1010 GValue list = { 0, };
1012 GstStructure *structure;
1014 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1015 g_return_if_fail (gst_query_is_writable (query));
1017 g_value_init (&list, GST_TYPE_LIST);
1019 va_start (ap, n_formats);
1020 for (i = 0; i < n_formats; i++) {
1021 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
1025 structure = GST_QUERY_STRUCTURE (query);
1026 gst_structure_set_value (structure, "formats", &list);
1028 g_value_unset (&list);
1033 * gst_query_set_formatsv:
1034 * @query: a #GstQuery
1035 * @n_formats: the number of formats to set.
1036 * @formats: (in) (array length=n_formats): an array containing @n_formats
1037 * @GstFormat values.
1039 * Set the formats query result fields in @query. The number of formats passed
1040 * in the @formats array must be equal to @n_formats.
1045 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1046 const GstFormat * formats)
1048 GValue list = { 0, };
1050 GstStructure *structure;
1052 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1053 g_return_if_fail (gst_query_is_writable (query));
1055 g_value_init (&list, GST_TYPE_LIST);
1056 for (i = 0; i < n_formats; i++) {
1057 gst_query_list_add_format (&list, formats[i]);
1059 structure = GST_QUERY_STRUCTURE (query);
1060 gst_structure_set_value (structure, "formats", &list);
1062 g_value_unset (&list);
1066 * gst_query_parse_n_formats:
1067 * @query: a #GstQuery
1068 * @n_formats: (out): the number of formats in this query.
1070 * Parse the number of formats in the formats @query.
1075 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1077 GstStructure *structure;
1079 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1084 structure = GST_QUERY_STRUCTURE (query);
1085 list = gst_structure_get_value (structure, "formats");
1089 *n_formats = gst_value_list_get_size (list);
1094 * gst_query_parse_nth_format:
1095 * @query: a #GstQuery
1096 * @nth: (out): the nth format to retrieve.
1097 * @format: (out): a pointer to store the nth format
1099 * Parse the format query and retrieve the @nth format from it into
1100 * @format. If the list contains less elements than @nth, @format will be
1101 * set to GST_FORMAT_UNDEFINED.
1104 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1106 GstStructure *structure;
1108 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1113 structure = GST_QUERY_STRUCTURE (query);
1114 list = gst_structure_get_value (structure, "formats");
1116 *format = GST_FORMAT_UNDEFINED;
1118 if (nth < gst_value_list_get_size (list)) {
1119 *format = g_value_get_enum (gst_value_list_get_value (list, nth));
1121 *format = GST_FORMAT_UNDEFINED;
1127 * gst_query_new_buffering
1128 * @format: the default #GstFormat for the new query
1130 * Constructs a new query object for querying the buffering status of
1133 * Free-function: gst_query_unref
1135 * Returns: (transfer full): a new #GstQuery
1140 gst_query_new_buffering (GstFormat format)
1143 GstStructure *structure;
1145 /* by default, we configure the answer as no buffering with a 100% buffering
1147 structure = gst_structure_id_new (GST_QUARK (QUERY_BUFFERING),
1148 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1149 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1150 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1151 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1152 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1153 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1154 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1155 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1156 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1157 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1159 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1165 * gst_query_set_buffering_percent
1166 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1167 * @busy: if buffering is busy
1168 * @percent: a buffering percent
1170 * Set the percentage of buffered data. This is a value between 0 and 100.
1171 * The @busy indicator is %TRUE when the buffering is in progress.
1176 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1178 GstStructure *structure;
1180 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1181 g_return_if_fail (gst_query_is_writable (query));
1182 g_return_if_fail (percent >= 0 && percent <= 100);
1184 structure = GST_QUERY_STRUCTURE (query);
1185 gst_structure_id_set (structure,
1186 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1187 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1191 * gst_query_parse_buffering_percent
1192 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1193 * @busy: (out) (allow-none): if buffering is busy, or NULL
1194 * @percent: (out) (allow-none): a buffering percent, or NULL
1196 * Get the percentage of buffered data. This is a value between 0 and 100.
1197 * The @busy indicator is %TRUE when the buffering is in progress.
1202 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1205 GstStructure *structure;
1207 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1209 structure = GST_QUERY_STRUCTURE (query);
1211 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1214 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1215 GST_QUARK (BUFFER_PERCENT)));
1219 * gst_query_set_buffering_stats:
1220 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1221 * @mode: a buffering mode
1222 * @avg_in: the average input rate
1223 * @avg_out: the average output rate
1224 * @buffering_left: amount of buffering time left
1226 * Configures the buffering stats values in @query.
1231 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1232 gint avg_in, gint avg_out, gint64 buffering_left)
1234 GstStructure *structure;
1236 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1237 g_return_if_fail (gst_query_is_writable (query));
1239 structure = GST_QUERY_STRUCTURE (query);
1240 gst_structure_id_set (structure,
1241 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1242 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1243 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1244 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1248 * gst_query_parse_buffering_stats:
1249 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1250 * @mode: (out) (allow-none): a buffering mode, or NULL
1251 * @avg_in: (out) (allow-none): the average input rate, or NULL
1252 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1253 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1255 * Extracts the buffering stats values from @query.
1260 gst_query_parse_buffering_stats (GstQuery * query,
1261 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1262 gint64 * buffering_left)
1264 GstStructure *structure;
1266 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1268 structure = GST_QUERY_STRUCTURE (query);
1270 *mode = g_value_get_enum (gst_structure_id_get_value (structure,
1271 GST_QUARK (BUFFERING_MODE)));
1273 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1274 GST_QUARK (AVG_IN_RATE)));
1276 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1277 GST_QUARK (AVG_OUT_RATE)));
1280 g_value_get_int64 (gst_structure_id_get_value (structure,
1281 GST_QUARK (BUFFERING_LEFT)));
1286 * gst_query_set_buffering_range:
1287 * @query: a #GstQuery
1288 * @format: the format to set for the @start and @stop values
1289 * @start: the start to set
1290 * @stop: the stop to set
1291 * @estimated_total: estimated total amount of download time
1293 * Set the available query result fields in @query.
1298 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1299 gint64 start, gint64 stop, gint64 estimated_total)
1301 GstStructure *structure;
1303 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1304 g_return_if_fail (gst_query_is_writable (query));
1306 structure = GST_QUERY_STRUCTURE (query);
1307 gst_structure_id_set (structure,
1308 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1309 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1310 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1311 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1315 * gst_query_parse_buffering_range:
1316 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1317 * @format: (out) (allow-none): the format to set for the @segment_start
1318 * and @segment_end values, or NULL
1319 * @start: (out) (allow-none): the start to set, or NULL
1320 * @stop: (out) (allow-none): the stop to set, or NULL
1321 * @estimated_total: (out) (allow-none): estimated total amount of download
1324 * Parse an available query, writing the format into @format, and
1325 * other results into the passed parameters, if the respective parameters
1331 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1332 gint64 * start, gint64 * stop, gint64 * estimated_total)
1334 GstStructure *structure;
1336 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1338 structure = GST_QUERY_STRUCTURE (query);
1340 *format = g_value_get_enum (gst_structure_id_get_value (structure,
1341 GST_QUARK (FORMAT)));
1343 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1344 GST_QUARK (START_VALUE)));
1346 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1347 GST_QUARK (STOP_VALUE)));
1348 if (estimated_total)
1350 g_value_get_int64 (gst_structure_id_get_value (structure,
1351 GST_QUARK (ESTIMATED_TOTAL)));
1355 * gst_query_add_buffering_range
1356 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1357 * @start: start position of the range
1358 * @stop: stop position of the range
1360 * Set the buffering-ranges array field in @query. The current last
1361 * start position of the array should be inferior to @start.
1363 * Returns: a #gboolean indicating if the range was added or not.
1368 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1371 GValue *last_array_value;
1372 const GValue *value;
1373 GValue range_value = { 0 };
1374 GstStructure *structure;
1376 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1377 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1379 if (G_UNLIKELY (start >= stop))
1382 structure = GST_QUERY_STRUCTURE (query);
1383 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1385 array = (GValueArray *) g_value_get_boxed (value);
1386 last_array_value = g_value_array_get_nth (array, array->n_values - 1);
1387 if (G_UNLIKELY (start <= gst_value_get_int64_range_min (last_array_value)))
1390 GValue new_array_val = { 0, };
1392 array = g_value_array_new (0);
1394 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1395 g_value_take_boxed (&new_array_val, array);
1397 /* set the value array only once, so we then modify (append to) the
1398 * existing value array owned by the GstStructure / the field's GValue */
1399 gst_structure_id_take_value (structure, GST_QUARK (BUFFERING_RANGES),
1403 g_value_init (&range_value, GST_TYPE_INT64_RANGE);
1404 gst_value_set_int64_range (&range_value, start, stop);
1405 g_value_array_append (array, &range_value);
1406 /* skip the g_value_unset(&range_value) here, we know it's not needed */
1412 * gst_query_get_n_buffering_ranges
1413 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1415 * Retrieve the number of values currently stored in the
1416 * buffered-ranges array of the query's structure.
1418 * Returns: the range array size as a #guint.
1423 gst_query_get_n_buffering_ranges (GstQuery * query)
1426 const GValue *value;
1428 GstStructure *structure;
1430 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1432 structure = GST_QUERY_STRUCTURE (query);
1433 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1435 array = (GValueArray *) g_value_get_boxed (value);
1436 size = array->n_values;
1443 * gst_query_parse_nth_buffering_range
1444 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1445 * @index: position in the buffered-ranges array to read
1446 * @start: (out) (allow-none): the start position to set, or NULL
1447 * @stop: (out) (allow-none): the stop position to set, or NULL
1449 * Parse an available query and get the start and stop values stored
1450 * at the @index of the buffered ranges array.
1452 * Returns: a #gboolean indicating if the parsing succeeded.
1457 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1458 gint64 * start, gint64 * stop)
1460 const GValue *value;
1461 GValueArray *ranges;
1462 GValue *range_value;
1463 gboolean ret = FALSE;
1464 GstStructure *structure;
1466 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1468 structure = GST_QUERY_STRUCTURE (query);
1469 value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1470 ranges = (GValueArray *) g_value_get_boxed (value);
1471 range_value = g_value_array_get_nth (ranges, index);
1474 *start = gst_value_get_int64_range_min (range_value);
1476 *stop = gst_value_get_int64_range_max (range_value);
1485 * gst_query_new_uri:
1487 * Constructs a new query URI query object. Use gst_query_unref()
1488 * when done with it. An URI query is used to query the current URI
1489 * that is used by the source or sink.
1491 * Free-function: gst_query_unref
1493 * Returns: (transfer full): a new #GstQuery
1498 gst_query_new_uri (void)
1501 GstStructure *structure;
1503 structure = gst_structure_id_new (GST_QUARK (QUERY_URI),
1504 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1506 query = gst_query_new (GST_QUERY_URI, structure);
1512 * gst_query_set_uri:
1513 * @query: a #GstQuery with query type GST_QUERY_URI
1514 * @uri: the URI to set
1516 * Answer a URI query by setting the requested URI.
1521 gst_query_set_uri (GstQuery * query, const gchar * uri)
1523 GstStructure *structure;
1525 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1526 g_return_if_fail (gst_query_is_writable (query));
1527 g_return_if_fail (gst_uri_is_valid (uri));
1529 structure = GST_QUERY_STRUCTURE (query);
1530 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1534 * gst_query_parse_uri:
1535 * @query: a #GstQuery
1536 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1539 * Parse an URI query, writing the URI into @uri as a newly
1540 * allocated string, if the respective parameters are non-NULL.
1541 * Free the string with g_free() after usage.
1546 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1548 GstStructure *structure;
1550 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1552 structure = GST_QUERY_STRUCTURE (query);
1554 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1559 * gst_query_new_allocation
1560 * @caps: the negotiated caps
1561 * @need_pool: return a pool
1563 * Constructs a new query object for querying the allocation properties.
1565 * Free-function: gst_query_unref
1567 * Returns: (transfer full): a new #GstQuery
1570 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1573 GstStructure *structure;
1575 structure = gst_structure_id_new (GST_QUARK (QUERY_ALLOCATION),
1576 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1577 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool,
1578 GST_QUARK (SIZE), G_TYPE_UINT, 0,
1579 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, 0,
1580 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, 0,
1581 GST_QUARK (PREFIX), G_TYPE_UINT, 0,
1582 GST_QUARK (ALIGN), G_TYPE_UINT, 0,
1583 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, NULL, NULL);
1585 query = gst_query_new (GST_QUERY_ALLOCATION, structure);
1591 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1592 gboolean * need_pool)
1594 GstStructure *structure;
1596 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1598 structure = GST_QUERY_STRUCTURE (query);
1599 gst_structure_id_get (structure,
1600 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1601 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1605 * gst_query_set_allocation_params
1606 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1608 * @min_buffers: the min buffers
1609 * @max_buffers: the max buffers
1610 * @prefix: the prefix
1611 * @alignment: the alignment
1612 * @pool: the #GstBufferPool
1614 * Set the allocation parameters in @query.
1617 gst_query_set_allocation_params (GstQuery * query, guint size,
1618 guint min_buffers, guint max_buffers, guint prefix,
1619 guint alignment, GstBufferPool * pool)
1621 GstStructure *structure;
1623 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1624 g_return_if_fail (gst_query_is_writable (query));
1625 g_return_if_fail (((alignment + 1) & alignment) == 0);
1626 g_return_if_fail (size != 0 || pool == NULL);
1628 structure = GST_QUERY_STRUCTURE (query);
1629 gst_structure_id_set (structure,
1630 GST_QUARK (SIZE), G_TYPE_UINT, size,
1631 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1632 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1633 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1634 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1635 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1639 * gst_query_parse_allocation_params
1640 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1642 * @min_buffers: the min buffers
1643 * @max_buffers: the max buffers
1644 * @prefix: the prefix
1645 * @alignment: the alignment
1646 * @pool: the #GstBufferPool
1648 * Get the allocation parameters in @query.
1651 gst_query_parse_allocation_params (GstQuery * query, guint * size,
1652 guint * min_buffers, guint * max_buffers, guint * prefix,
1653 guint * alignment, GstBufferPool ** pool)
1655 GstStructure *structure;
1657 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1659 structure = GST_QUERY_STRUCTURE (query);
1660 gst_structure_id_get (structure,
1661 GST_QUARK (SIZE), G_TYPE_UINT, size,
1662 GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
1663 GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers,
1664 GST_QUARK (PREFIX), G_TYPE_UINT, prefix,
1665 GST_QUARK (ALIGN), G_TYPE_UINT, alignment,
1666 GST_QUARK (POOL), GST_TYPE_BUFFER_POOL, pool, NULL);
1670 * gst_query_add_allocation_meta
1671 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1672 * @api: the metadata API
1674 * Add @api as aone of the supported metadata API to @query.
1677 gst_query_add_allocation_meta (GstQuery * query, const gchar * api)
1680 const GValue *value;
1681 GValue api_value = { 0 };
1682 GstStructure *structure;
1684 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1685 g_return_if_fail (gst_query_is_writable (query));
1687 structure = GST_QUERY_STRUCTURE (query);
1688 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1690 array = (GValueArray *) g_value_get_boxed (value);
1692 GValue new_array_val = { 0, };
1694 array = g_value_array_new (0);
1696 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1697 g_value_take_boxed (&new_array_val, array);
1699 gst_structure_id_take_value (structure, GST_QUARK (META), &new_array_val);
1702 g_value_init (&api_value, G_TYPE_STRING);
1703 g_value_set_string (&api_value, api);
1704 g_value_array_append (array, &api_value);
1705 g_value_unset (&api_value);
1709 * gst_query_get_n_allocation_metas:
1710 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1712 * Retrieve the number of values currently stored in the
1713 * meta API array of the query's structure.
1715 * Returns: the metadata API array size as a #guint.
1718 gst_query_get_n_allocation_metas (GstQuery * query)
1721 const GValue *value;
1723 GstStructure *structure;
1725 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1727 structure = GST_QUERY_STRUCTURE (query);
1728 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1730 array = (GValueArray *) g_value_get_boxed (value);
1731 size = array->n_values;
1737 * gst_query_parse_nth_allocation_meta
1738 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1739 * @index: position in the metadata API array to read
1741 * Parse an available query and get the metadata API
1742 * at @index of the metadata API array.
1744 * Returns: a #gchar of the metadata API at @index.
1747 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1749 const GValue *value;
1750 const gchar *ret = NULL;
1751 GstStructure *structure;
1753 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1755 structure = GST_QUERY_STRUCTURE (query);
1756 value = gst_structure_id_get_value (structure, GST_QUARK (META));
1761 meta = (GValueArray *) g_value_get_boxed (value);
1762 api_value = g_value_array_get_nth (meta, index);
1765 ret = g_value_get_string (api_value);
1771 * gst_query_add_allocation_memory
1772 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1773 * @alloc: the memory allocator
1775 * Add @alloc as a supported memory allocator.
1778 gst_query_add_allocation_memory (GstQuery * query, const gchar * alloc)
1781 const GValue *value;
1782 GValue alloc_value = { 0 };
1783 GstStructure *structure;
1785 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1786 g_return_if_fail (gst_query_is_writable (query));
1788 structure = GST_QUERY_STRUCTURE (query);
1789 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1791 array = (GValueArray *) g_value_get_boxed (value);
1793 GValue new_array_val = { 0, };
1795 array = g_value_array_new (0);
1797 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1798 g_value_take_boxed (&new_array_val, array);
1800 gst_structure_id_take_value (structure, GST_QUARK (ALLOCATOR),
1804 g_value_init (&alloc_value, G_TYPE_STRING);
1805 g_value_set_string (&alloc_value, alloc);
1806 g_value_array_append (array, &alloc_value);
1807 g_value_unset (&alloc_value);
1811 * gst_query_get_n_allocation_memories:
1812 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1814 * Retrieve the number of values currently stored in the
1815 * allocator array of the query's structure.
1817 * If no memory allocator is specified, the downstream element can handle
1818 * the default memory allocator.
1820 * Returns: the allocator array size as a #guint.
1823 gst_query_get_n_allocation_memories (GstQuery * query)
1826 const GValue *value;
1828 GstStructure *structure;
1830 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1832 structure = GST_QUERY_STRUCTURE (query);
1833 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1835 array = (GValueArray *) g_value_get_boxed (value);
1836 size = array->n_values;
1842 * gst_query_parse_nth_allocation_memory
1843 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1844 * @index: position in the allocator array to read
1846 * Parse an available query and get the alloctor
1847 * at @index of the allocator array.
1849 * Returns: the name of the allocator at @index.
1852 gst_query_parse_nth_allocation_memory (GstQuery * query, guint index)
1854 const GValue *value;
1855 const gchar *ret = NULL;
1856 GstStructure *structure;
1858 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, NULL);
1860 structure = GST_QUERY_STRUCTURE (query);
1861 value = gst_structure_id_get_value (structure, GST_QUARK (ALLOCATOR));
1863 GValueArray *memory;
1864 GValue *alloc_value;
1866 memory = (GValueArray *) g_value_get_boxed (value);
1867 alloc_value = g_value_array_get_nth (memory, index);
1870 ret = g_value_get_string (alloc_value);
1876 * gst_query_new_scheduling
1878 * Constructs a new query object for querying the scheduling properties.
1880 * Free-function: gst_query_unref
1882 * Returns: (transfer full): a new #GstQuery
1885 gst_query_new_scheduling (void)
1888 GstStructure *structure;
1890 structure = gst_structure_id_new (GST_QUARK (QUERY_SCHEDULING),
1891 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, FALSE,
1892 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, FALSE,
1893 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, TRUE,
1894 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1895 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1896 GST_QUARK (ALIGN), G_TYPE_INT, 1, NULL);
1897 query = gst_query_new (GST_QUERY_SCHEDULING, structure);
1903 * gst_query_set_scheduling
1904 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1905 * @pull_mode: if pull mode scheduling is supported
1906 * @random_access: if random access is possible
1907 * @sequential: if sequential access is recommended
1908 * @minsize: the suggested minimum size of pull requests
1909 * @maxsize the suggested maximum size of pull requests:
1910 * @align: the suggested alignment of pull requests
1912 * Set the scheduling properties.
1915 gst_query_set_scheduling (GstQuery * query, gboolean pull_mode,
1916 gboolean random_access, gboolean sequential,
1917 gint minsize, gint maxsize, gint align)
1919 GstStructure *structure;
1921 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1922 g_return_if_fail (gst_query_is_writable (query));
1924 structure = GST_QUERY_STRUCTURE (query);
1925 gst_structure_id_set (structure,
1926 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, pull_mode,
1927 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, random_access,
1928 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, sequential,
1929 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1930 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1931 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1935 * gst_query_parse_scheduling
1936 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1937 * @pull_mode: if pull mode scheduling is supported
1938 * @random_access: if random access is possible
1939 * @sequential: if sequential access is recommended
1940 * @minsize: the suggested minimum size of pull requests
1941 * @maxsize the suggested maximum size of pull requests:
1942 * @align: the suggested alignment of pull requests
1944 * Set the scheduling properties.
1947 gst_query_parse_scheduling (GstQuery * query, gboolean * pull_mode,
1948 gboolean * random_access, gboolean * sequential,
1949 gint * minsize, gint * maxsize, gint * align)
1951 GstStructure *structure;
1953 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1955 structure = GST_QUERY_STRUCTURE (query);
1956 gst_structure_id_get (structure,
1957 GST_QUARK (PULL_MODE), G_TYPE_BOOLEAN, pull_mode,
1958 GST_QUARK (RANDOM_ACCESS), G_TYPE_BOOLEAN, random_access,
1959 GST_QUARK (SEQUENTIAL), G_TYPE_BOOLEAN, sequential,
1960 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1961 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1962 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);