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"
72 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
73 #define GST_CAT_DEFAULT gst_query_debug
75 static GType _gst_query_type = 0;
77 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
78 static GList *_gst_queries = NULL;
79 static GHashTable *_nick_to_query = NULL;
80 static GHashTable *_query_type_to_nick = NULL;
81 static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */
83 static GstQueryTypeDefinition standard_definitions[] = {
84 {GST_QUERY_POSITION, "position", "Current position", 0},
85 {GST_QUERY_DURATION, "duration", "Total duration", 0},
86 {GST_QUERY_LATENCY, "latency", "Latency", 0},
87 {GST_QUERY_JITTER, "jitter", "Jitter", 0},
88 {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
89 {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
90 {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
91 {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
92 {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
93 {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
94 {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
95 {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
100 _gst_query_initialize (void)
102 GstQueryTypeDefinition *standards = standard_definitions;
104 GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
106 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
108 g_static_mutex_lock (&mutex);
109 if (_nick_to_query == NULL) {
110 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
111 _query_type_to_nick = g_hash_table_new (NULL, NULL);
114 while (standards->nick) {
115 standards->quark = g_quark_from_static_string (standards->nick);
116 g_hash_table_insert (_nick_to_query, (gpointer) standards->nick, standards);
117 g_hash_table_insert (_query_type_to_nick,
118 GINT_TO_POINTER (standards->value), standards);
120 _gst_queries = g_list_append (_gst_queries, standards);
124 g_static_mutex_unlock (&mutex);
126 gst_query_get_type ();
130 * gst_query_type_get_name:
131 * @query: the query type
133 * Get a printable name for the given query type. Do not modify or free.
135 * Returns: a reference to the static name of the query.
138 gst_query_type_get_name (GstQueryType query)
140 const GstQueryTypeDefinition *def;
142 def = gst_query_type_get_details (query);
148 * gst_query_type_to_quark:
149 * @query: the query type
151 * Get the unique quark for the given query type.
153 * Returns: the quark associated with the query type
156 gst_query_type_to_quark (GstQueryType query)
158 const GstQueryTypeDefinition *def;
160 def = gst_query_type_get_details (query);
166 gst_query_get_type (void)
168 if (G_UNLIKELY (_gst_query_type == 0)) {
169 _gst_query_type = gst_mini_object_register ("GstQuery");
171 return _gst_query_type;
176 * gst_query_type_register:
177 * @nick: The nick of the new query
178 * @description: The description of the new query
180 * Create a new GstQueryType based on the nick or return an
181 * already registered query with that nick
183 * Returns: A new GstQueryType or an already registered query
184 * with the same nick.
187 gst_query_type_register (const gchar * nick, const gchar * description)
189 GstQueryTypeDefinition *query;
192 g_return_val_if_fail (nick != NULL, 0);
193 g_return_val_if_fail (description != NULL, 0);
195 lookup = gst_query_type_get_by_nick (nick);
196 if (lookup != GST_QUERY_NONE)
199 query = g_slice_new (GstQueryTypeDefinition);
200 query->value = _n_values;
201 query->nick = g_strdup (nick);
202 query->description = g_strdup (description);
203 query->quark = g_quark_from_static_string (query->nick);
205 g_static_mutex_lock (&mutex);
206 g_hash_table_insert (_nick_to_query, (gpointer) query->nick, query);
207 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
209 _gst_queries = g_list_append (_gst_queries, query);
211 g_static_mutex_unlock (&mutex);
217 * gst_query_type_get_by_nick:
218 * @nick: The nick of the query
220 * Get the query type registered with @nick.
222 * Returns: The query registered with @nick or #GST_QUERY_NONE
223 * if the query was not registered.
226 gst_query_type_get_by_nick (const gchar * nick)
228 GstQueryTypeDefinition *query;
230 g_return_val_if_fail (nick != NULL, 0);
232 g_static_mutex_lock (&mutex);
233 query = g_hash_table_lookup (_nick_to_query, nick);
234 g_static_mutex_unlock (&mutex);
239 return GST_QUERY_NONE;
243 * gst_query_types_contains:
244 * @types: The query array to search
245 * @type: the #GstQueryType to find
247 * See if the given #GstQueryType is inside the @types query types array.
249 * Returns: TRUE if the type is found inside the array
252 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
268 * gst_query_type_get_details:
269 * @type: a #GstQueryType
271 * Get details about the given #GstQueryType.
273 * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
275 const GstQueryTypeDefinition *
276 gst_query_type_get_details (GstQueryType type)
278 const GstQueryTypeDefinition *result;
280 g_static_mutex_lock (&mutex);
281 result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
282 g_static_mutex_unlock (&mutex);
288 * gst_query_type_iterate_definitions:
290 * Get a #GstIterator of all the registered query types. The definitions
291 * iterated over are read only.
293 * Free-function: gst_iterator_free
295 * Returns: (transfer full): a #GstIterator of #GstQueryTypeDefinition.
298 gst_query_type_iterate_definitions (void)
302 g_static_mutex_lock (&mutex);
303 /* FIXME: register a boxed type for GstQueryTypeDefinition */
304 result = gst_iterator_new_list (G_TYPE_POINTER,
305 g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries,
307 g_static_mutex_unlock (&mutex);
313 _gst_query_free (GstQuery * query)
315 g_return_if_fail (query != NULL);
317 if (query->structure) {
318 gst_structure_set_parent_refcount (query->structure, NULL);
319 gst_structure_free (query->structure);
322 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
325 static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
328 _gst_query_copy (GstQuery * query)
332 copy = gst_query_new (query->type, query->structure);
338 gst_query_new (GstQueryType type, GstStructure * structure)
342 query = g_slice_new0 (GstQuery);
344 gst_mini_object_init (GST_MINI_OBJECT_CAST (query),
345 _gst_query_type, sizeof (GstQuery));
347 query->mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
348 query->mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
350 GST_DEBUG ("creating new query %p %d", query, type);
353 query->structure = structure;
356 gst_structure_set_parent_refcount (query->structure,
357 &query->mini_object.refcount);
363 * gst_query_new_position:
364 * @format: the default #GstFormat for the new query
366 * Constructs a new query stream position query object. Use gst_query_unref()
367 * when done with it. A position query is used to query the current position
368 * of playback in the streams, in some format.
370 * Free-function: gst_query_unref
372 * Returns: (transfer full): a new #GstQuery
375 gst_query_new_position (GstFormat format)
378 GstStructure *structure;
380 structure = gst_structure_id_new (GST_QUARK (QUERY_POSITION),
381 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
382 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
384 query = gst_query_new (GST_QUERY_POSITION, structure);
390 * gst_query_set_position:
391 * @query: a #GstQuery with query type GST_QUERY_POSITION
392 * @format: the requested #GstFormat
393 * @cur: the position to set
395 * Answer a position query by setting the requested value in the given format.
398 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
400 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
402 gst_structure_id_set (query->structure,
403 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
404 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
408 * gst_query_parse_position:
409 * @query: a #GstQuery
410 * @format: (out) (allow-none): the storage for the #GstFormat of the
411 * position values (may be NULL)
412 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
414 * Parse a position query, writing the format into @format, and the position
415 * into @cur, if the respective parameters are non-NULL.
418 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
420 GstStructure *structure;
422 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
424 structure = query->structure;
426 *format = g_value_get_enum (gst_structure_id_get_value (structure,
427 GST_QUARK (FORMAT)));
429 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
430 GST_QUARK (CURRENT)));
435 * gst_query_new_duration:
436 * @format: the #GstFormat for this duration query
438 * Constructs a new stream duration query object to query in the given format.
439 * Use gst_query_unref() when done with it. A duration query will give the
440 * total length of the stream.
442 * Free-function: gst_query_unref
444 * Returns: (transfer full): a new #GstQuery
447 gst_query_new_duration (GstFormat format)
450 GstStructure *structure;
452 structure = gst_structure_id_new (GST_QUARK (QUERY_DURATION),
453 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
454 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
456 query = gst_query_new (GST_QUERY_DURATION, structure);
462 * gst_query_set_duration:
463 * @query: a #GstQuery
464 * @format: the #GstFormat for the duration
465 * @duration: the duration of the stream
467 * Answer a duration query by setting the requested value in the given format.
470 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
472 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
474 gst_structure_id_set (query->structure,
475 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
476 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
480 * gst_query_parse_duration:
481 * @query: a #GstQuery
482 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
484 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
486 * Parse a duration query answer. Write the format of the duration into @format,
487 * and the value into @duration, if the respective variables are non-NULL.
490 gst_query_parse_duration (GstQuery * query, GstFormat * format,
493 GstStructure *structure;
495 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
497 structure = query->structure;
499 *format = g_value_get_enum (gst_structure_id_get_value (structure,
500 GST_QUARK (FORMAT)));
502 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
503 GST_QUARK (DURATION)));
507 * gst_query_new_latency:
509 * Constructs a new latency query object.
510 * Use gst_query_unref() when done with it. A latency query is usually performed
511 * by sinks to compensate for additional latency introduced by elements in the
514 * Free-function: gst_query_unref
516 * Returns: (transfer full): a #GstQuery
521 gst_query_new_latency (void)
524 GstStructure *structure;
526 structure = gst_structure_id_new (GST_QUARK (QUERY_LATENCY),
527 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
528 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
529 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
531 query = gst_query_new (GST_QUERY_LATENCY, structure);
537 * gst_query_set_latency:
538 * @query: a #GstQuery
539 * @live: if there is a live element upstream
540 * @min_latency: the minimal latency of the live element
541 * @max_latency: the maximal latency of the live element
543 * Answer a latency query by setting the requested values in the given format.
548 gst_query_set_latency (GstQuery * query, gboolean live,
549 GstClockTime min_latency, GstClockTime max_latency)
551 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
553 gst_structure_id_set (query->structure,
554 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
555 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
556 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
560 * gst_query_parse_latency:
561 * @query: a #GstQuery
562 * @live: (out) (allow-none): storage for live or NULL
563 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
564 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
566 * Parse a latency query answer.
571 gst_query_parse_latency (GstQuery * query, gboolean * live,
572 GstClockTime * min_latency, GstClockTime * max_latency)
574 GstStructure *structure;
576 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
578 structure = query->structure;
581 g_value_get_boolean (gst_structure_id_get_value (structure,
584 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
585 GST_QUARK (MIN_LATENCY)));
587 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
588 GST_QUARK (MAX_LATENCY)));
592 * gst_query_new_convert:
593 * @src_format: the source #GstFormat for the new query
594 * @value: the value to convert
595 * @dest_format: the target #GstFormat
597 * Constructs a new convert query object. Use gst_query_unref()
598 * when done with it. A convert query is used to ask for a conversion between
599 * one format and another.
601 * Free-function: gst_query_unref
603 * Returns: (transfer full): a #GstQuery
606 gst_query_new_convert (GstFormat src_format, gint64 value,
607 GstFormat dest_format)
610 GstStructure *structure;
612 structure = gst_structure_id_new (GST_QUARK (QUERY_CONVERT),
613 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
614 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
615 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
616 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
618 query = gst_query_new (GST_QUERY_CONVERT, structure);
624 * gst_query_set_convert:
625 * @query: a #GstQuery
626 * @src_format: the source #GstFormat
627 * @src_value: the source value
628 * @dest_format: the destination #GstFormat
629 * @dest_value: the destination value
631 * Answer a convert query by setting the requested values.
634 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
635 GstFormat dest_format, gint64 dest_value)
637 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
639 gst_structure_id_set (query->structure,
640 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
641 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
642 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
643 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
647 * gst_query_parse_convert:
648 * @query: a #GstQuery
649 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
650 * source value, or NULL
651 * @src_value: (out) (allow-none): the storage for the source value, or NULL
652 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
653 * destination value, or NULL
654 * @dest_value: (out) (allow-none): the storage for the destination value,
657 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
658 * and @dest_value may be NULL, in which case that value is omitted.
661 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
662 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
664 GstStructure *structure;
666 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
668 structure = query->structure;
670 *src_format = g_value_get_enum (gst_structure_id_get_value (structure,
671 GST_QUARK (SRC_FORMAT)));
673 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
674 GST_QUARK (SRC_VALUE)));
676 *dest_format = g_value_get_enum (gst_structure_id_get_value (structure,
677 GST_QUARK (DEST_FORMAT)));
679 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
680 GST_QUARK (DEST_VALUE)));
684 * gst_query_new_segment:
685 * @format: the #GstFormat for the new query
687 * Constructs a new segment query object. Use gst_query_unref()
688 * when done with it. A segment query is used to discover information about the
689 * currently configured segment for playback.
691 * Free-function: gst_query_unref
693 * Returns: (transfer full): a new #GstQuery
696 gst_query_new_segment (GstFormat format)
699 GstStructure *structure;
701 structure = gst_structure_id_new (GST_QUARK (QUERY_SEGMENT),
702 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
703 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
704 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
705 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
707 query = gst_query_new (GST_QUERY_SEGMENT, structure);
713 * gst_query_set_segment:
714 * @query: a #GstQuery
715 * @rate: the rate of the segment
716 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
717 * @start_value: the start value
718 * @stop_value: the stop value
720 * Answer a segment query by setting the requested values. The normal
721 * playback segment of a pipeline is 0 to duration at the default rate of
722 * 1.0. If a seek was performed on the pipeline to play a different
723 * segment, this query will return the range specified in the last seek.
725 * @start_value and @stop_value will respectively contain the configured
726 * playback range start and stop values expressed in @format.
727 * The values are always between 0 and the duration of the media and
728 * @start_value <= @stop_value. @rate will contain the playback rate. For
729 * negative rates, playback will actually happen from @stop_value to
733 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
734 gint64 start_value, gint64 stop_value)
736 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
738 gst_structure_id_set (query->structure,
739 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
740 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
741 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
742 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
746 * gst_query_parse_segment:
747 * @query: a #GstQuery
748 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
749 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
751 * @start_value: (out) (allow-none): the storage for the start value, or NULL
752 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
754 * Parse a segment query answer. Any of @rate, @format, @start_value, and
755 * @stop_value may be NULL, which will cause this value to be omitted.
757 * See gst_query_set_segment() for an explanation of the function arguments.
760 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
761 gint64 * start_value, gint64 * stop_value)
763 GstStructure *structure;
765 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
767 structure = query->structure;
769 *rate = g_value_get_double (gst_structure_id_get_value (structure,
772 *format = g_value_get_enum (gst_structure_id_get_value (structure,
773 GST_QUARK (FORMAT)));
775 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
776 GST_QUARK (START_VALUE)));
778 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
779 GST_QUARK (STOP_VALUE)));
783 * gst_query_new_application:
784 * @type: the query type
785 * @structure: a structure for the query
787 * Constructs a new custom application query object. Use gst_query_unref()
790 * Free-function: gst_query_unref
792 * Returns: (transfer full): a new #GstQuery
795 gst_query_new_application (GstQueryType type, GstStructure * structure)
797 g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
798 g_return_val_if_fail (structure != NULL, NULL);
800 return gst_query_new (type, structure);
804 * gst_query_get_structure:
805 * @query: a #GstQuery
807 * Get the structure of a query.
809 * Returns: (transfer none): the #GstStructure of the query. The structure is
810 * still owned by the query and will therefore be freed when the query
814 gst_query_get_structure (GstQuery * query)
816 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
818 return query->structure;
822 * gst_query_new_seeking:
823 * @format: the default #GstFormat for the new query
825 * Constructs a new query object for querying seeking properties of
828 * Free-function: gst_query_unref
830 * Returns: (transfer full): a new #GstQuery
833 gst_query_new_seeking (GstFormat format)
836 GstStructure *structure;
838 structure = gst_structure_id_new (GST_QUARK (QUERY_SEEKING),
839 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
840 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
841 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
842 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
844 query = gst_query_new (GST_QUERY_SEEKING, structure);
850 * gst_query_set_seeking:
851 * @query: a #GstQuery
852 * @format: the format to set for the @segment_start and @segment_end values
853 * @seekable: the seekable flag to set
854 * @segment_start: the segment_start to set
855 * @segment_end: the segment_end to set
857 * Set the seeking query result fields in @query.
860 gst_query_set_seeking (GstQuery * query, GstFormat format,
861 gboolean seekable, gint64 segment_start, gint64 segment_end)
863 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
865 gst_structure_id_set (query->structure,
866 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
867 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
868 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
869 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
873 * gst_query_parse_seeking:
874 * @query: a GST_QUERY_SEEKING type query #GstQuery
875 * @format: (out) (allow-none): the format to set for the @segment_start
876 * and @segment_end values, or NULL
877 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
878 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
879 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
881 * Parse a seeking query, writing the format into @format, and
882 * other results into the passed parameters, if the respective parameters
886 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
887 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
889 GstStructure *structure;
891 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
893 structure = query->structure;
895 *format = g_value_get_enum (gst_structure_id_get_value (structure,
896 GST_QUARK (FORMAT)));
898 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
899 GST_QUARK (SEEKABLE)));
901 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
902 GST_QUARK (SEGMENT_START)));
904 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
905 GST_QUARK (SEGMENT_END)));
909 * gst_query_new_formats:
911 * Constructs a new query object for querying formats of
914 * Free-function: gst_query_unref
916 * Returns: (transfer full): a new #GstQuery
921 gst_query_new_formats (void)
924 GstStructure *structure;
926 structure = gst_structure_id_empty_new (GST_QUARK (QUERY_FORMATS));
927 query = gst_query_new (GST_QUERY_FORMATS, structure);
933 gst_query_list_add_format (GValue * list, GstFormat format)
935 GValue item = { 0, };
937 g_value_init (&item, GST_TYPE_FORMAT);
938 g_value_set_enum (&item, format);
939 gst_value_list_append_value (list, &item);
940 g_value_unset (&item);
944 * gst_query_set_formats:
945 * @query: a #GstQuery
946 * @n_formats: the number of formats to set.
947 * @...: A number of @GstFormats equal to @n_formats.
949 * Set the formats query result fields in @query. The number of formats passed
950 * must be equal to @n_formats.
953 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
956 GValue list = { 0, };
959 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
961 g_value_init (&list, GST_TYPE_LIST);
963 va_start (ap, n_formats);
964 for (i = 0; i < n_formats; i++) {
965 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
969 gst_structure_set_value (query->structure, "formats", &list);
971 g_value_unset (&list);
976 * gst_query_set_formatsv:
977 * @query: a #GstQuery
978 * @n_formats: the number of formats to set.
979 * @formats: (in) (array length=n_formats): an array containing @n_formats
982 * Set the formats query result fields in @query. The number of formats passed
983 * in the @formats array must be equal to @n_formats.
988 gst_query_set_formatsv (GstQuery * query, gint n_formats,
989 const GstFormat * formats)
991 GValue list = { 0, };
994 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
996 g_value_init (&list, GST_TYPE_LIST);
997 for (i = 0; i < n_formats; i++) {
998 gst_query_list_add_format (&list, formats[i]);
1000 gst_structure_set_value (query->structure, "formats", &list);
1002 g_value_unset (&list);
1006 * gst_query_parse_formats_length:
1007 * @query: a #GstQuery
1008 * @n_formats: (out): the number of formats in this query.
1010 * Parse the number of formats in the formats @query.
1015 gst_query_parse_formats_length (GstQuery * query, guint * n_formats)
1017 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1022 list = gst_structure_get_value (query->structure, "formats");
1026 *n_formats = gst_value_list_get_size (list);
1031 * gst_query_parse_formats_nth:
1032 * @query: a #GstQuery
1033 * @nth: (out): the nth format to retrieve.
1034 * @format: (out): a pointer to store the nth format
1036 * Parse the format query and retrieve the @nth format from it into
1037 * @format. If the list contains less elements than @nth, @format will be
1038 * set to GST_FORMAT_UNDEFINED.
1043 gst_query_parse_formats_nth (GstQuery * query, guint nth, GstFormat * format)
1045 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1050 list = gst_structure_get_value (query->structure, "formats");
1052 *format = GST_FORMAT_UNDEFINED;
1054 if (nth < gst_value_list_get_size (list)) {
1055 *format = g_value_get_enum (gst_value_list_get_value (list, nth));
1057 *format = GST_FORMAT_UNDEFINED;
1063 * gst_query_new_buffering
1064 * @format: the default #GstFormat for the new query
1066 * Constructs a new query object for querying the buffering status of
1069 * Free-function: gst_query_new
1071 * Returns: (transfer full): a new #GstQuery
1076 gst_query_new_buffering (GstFormat format)
1079 GstStructure *structure;
1081 /* by default, we configure the answer as no buffering with a 100% buffering
1083 structure = gst_structure_id_new (GST_QUARK (QUERY_BUFFERING),
1084 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1085 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1086 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1087 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1088 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1089 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1090 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1091 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1092 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1093 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1095 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1101 * gst_query_set_buffering_percent
1102 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1103 * @busy: if buffering is busy
1104 * @percent: a buffering percent
1106 * Set the percentage of buffered data. This is a value between 0 and 100.
1107 * The @busy indicator is %TRUE when the buffering is in progress.
1112 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1114 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1115 g_return_if_fail (percent >= 0 && percent <= 100);
1117 gst_structure_id_set (query->structure,
1118 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1119 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1123 * gst_query_parse_buffering_percent
1124 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1125 * @busy: (out) (allow-none): if buffering is busy, or NULL
1126 * @percent: (out) (allow-none): a buffering percent, or NULL
1128 * Get the percentage of buffered data. This is a value between 0 and 100.
1129 * The @busy indicator is %TRUE when the buffering is in progress.
1134 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1137 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1140 *busy = g_value_get_boolean (gst_structure_id_get_value (query->structure,
1143 *percent = g_value_get_int (gst_structure_id_get_value (query->structure,
1144 GST_QUARK (BUFFER_PERCENT)));
1148 * gst_query_set_buffering_stats:
1149 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1150 * @mode: a buffering mode
1151 * @avg_in: the average input rate
1152 * @avg_out: the average output rate
1153 * @buffering_left: amount of buffering time left
1155 * Configures the buffering stats values in @query.
1160 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1161 gint avg_in, gint avg_out, gint64 buffering_left)
1163 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1165 gst_structure_id_set (query->structure,
1166 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1167 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1168 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1169 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1173 * gst_query_parse_buffering_stats:
1174 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1175 * @mode: (out) (allow-none): a buffering mode, or NULL
1176 * @avg_in: (out) (allow-none): the average input rate, or NULL
1177 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1178 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1180 * Extracts the buffering stats values from @query.
1185 gst_query_parse_buffering_stats (GstQuery * query,
1186 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1187 gint64 * buffering_left)
1189 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1192 *mode = g_value_get_enum (gst_structure_id_get_value (query->structure,
1193 GST_QUARK (BUFFERING_MODE)));
1195 *avg_in = g_value_get_int (gst_structure_id_get_value (query->structure,
1196 GST_QUARK (AVG_IN_RATE)));
1198 *avg_out = g_value_get_int (gst_structure_id_get_value (query->structure,
1199 GST_QUARK (AVG_OUT_RATE)));
1202 g_value_get_int64 (gst_structure_id_get_value (query->structure,
1203 GST_QUARK (BUFFERING_LEFT)));
1208 * gst_query_set_buffering_range:
1209 * @query: a #GstQuery
1210 * @format: the format to set for the @start and @stop values
1211 * @start: the start to set
1212 * @stop: the stop to set
1213 * @estimated_total: estimated total amount of download time
1215 * Set the available query result fields in @query.
1220 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1221 gint64 start, gint64 stop, gint64 estimated_total)
1223 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1225 gst_structure_id_set (query->structure,
1226 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1227 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1228 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1229 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1233 * gst_query_parse_buffering_range:
1234 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1235 * @format: (out) (allow-none): the format to set for the @segment_start
1236 * and @segment_end values, or NULL
1237 * @start: (out) (allow-none): the start to set, or NULL
1238 * @stop: (out) (allow-none): the stop to set, or NULL
1239 * @estimated_total: (out) (allow-none): estimated total amount of download
1242 * Parse an available query, writing the format into @format, and
1243 * other results into the passed parameters, if the respective parameters
1249 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1250 gint64 * start, gint64 * stop, gint64 * estimated_total)
1252 GstStructure *structure;
1254 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1256 structure = query->structure;
1258 *format = g_value_get_enum (gst_structure_id_get_value (structure,
1259 GST_QUARK (FORMAT)));
1261 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1262 GST_QUARK (START_VALUE)));
1264 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1265 GST_QUARK (STOP_VALUE)));
1266 if (estimated_total)
1268 g_value_get_int64 (gst_structure_id_get_value (structure,
1269 GST_QUARK (ESTIMATED_TOTAL)));
1273 * gst_query_add_buffering_range
1274 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1275 * @start: start position of the range
1276 * @stop: stop position of the range
1278 * Set the buffering-ranges array field in @query. The current last
1279 * start position of the array should be inferior to @start.
1281 * Returns: a #gboolean indicating if the range was added or not.
1286 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1289 GValue *last_array_value;
1290 const GValue *value;
1291 GValue range_value = { 0 };
1293 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1295 if (G_UNLIKELY (start >= stop))
1299 gst_structure_id_get_value (query->structure,
1300 GST_QUARK (BUFFERING_RANGES));
1302 array = (GValueArray *) g_value_get_boxed (value);
1303 last_array_value = g_value_array_get_nth (array, array->n_values - 1);
1304 if (G_UNLIKELY (start <= gst_value_get_int64_range_min (last_array_value)))
1307 GValue new_array_val = { 0, };
1309 array = g_value_array_new (0);
1311 g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1312 g_value_take_boxed (&new_array_val, array);
1314 /* set the value array only once, so we then modify (append to) the
1315 * existing value array owned by the GstStructure / the field's GValue */
1316 gst_structure_id_take_value (query->structure, GST_QUARK (BUFFERING_RANGES),
1320 g_value_init (&range_value, GST_TYPE_INT64_RANGE);
1321 gst_value_set_int64_range (&range_value, start, stop);
1322 g_value_array_append (array, &range_value);
1323 /* skip the g_value_unset(&range_value) here, we know it's not needed */
1329 * gst_query_get_n_buffering_ranges
1330 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1332 * Retrieve the number of values currently stored in the
1333 * buffered-ranges array of the query's structure.
1335 * Returns: the range array size as a #guint.
1340 gst_query_get_n_buffering_ranges (GstQuery * query)
1343 const GValue *value;
1346 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1349 gst_structure_id_get_value (query->structure,
1350 GST_QUARK (BUFFERING_RANGES));
1352 array = (GValueArray *) g_value_get_boxed (value);
1353 size = array->n_values;
1360 * gst_query_parse_nth_buffering_range
1361 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1362 * @index: position in the buffered-ranges array to read
1363 * @start: (out) (allow-none): the start position to set, or NULL
1364 * @stop: (out) (allow-none): the stop position to set, or NULL
1366 * Parse an available query and get the start and stop values stored
1367 * at the @index of the buffered ranges array.
1369 * Returns: a #gboolean indicating if the parsing succeeded.
1374 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1375 gint64 * start, gint64 * stop)
1377 const GValue *value;
1378 GValueArray *ranges;
1379 GValue *range_value;
1380 gboolean ret = FALSE;
1382 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1385 gst_structure_id_get_value (query->structure,
1386 GST_QUARK (BUFFERING_RANGES));
1387 ranges = (GValueArray *) g_value_get_boxed (value);
1388 range_value = g_value_array_get_nth (ranges, index);
1391 *start = gst_value_get_int64_range_min (range_value);
1393 *stop = gst_value_get_int64_range_max (range_value);
1402 * gst_query_new_uri:
1404 * Constructs a new query URI query object. Use gst_query_unref()
1405 * when done with it. An URI query is used to query the current URI
1406 * that is used by the source or sink.
1408 * Free-function: gst_query_unref
1410 * Returns: (transfer full): a new #GstQuery
1415 gst_query_new_uri (void)
1418 GstStructure *structure;
1420 structure = gst_structure_id_new (GST_QUARK (QUERY_URI),
1421 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1423 query = gst_query_new (GST_QUERY_URI, structure);
1429 * gst_query_set_uri:
1430 * @query: a #GstQuery with query type GST_QUERY_URI
1431 * @uri: the URI to set
1433 * Answer a URI query by setting the requested URI.
1438 gst_query_set_uri (GstQuery * query, const gchar * uri)
1440 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1441 g_return_if_fail (gst_uri_is_valid (uri));
1443 gst_structure_id_set (query->structure, GST_QUARK (URI), G_TYPE_STRING, uri,
1448 * gst_query_parse_uri:
1449 * @query: a #GstQuery
1450 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1453 * Parse an URI query, writing the URI into @uri as a newly
1454 * allocated string, if the respective parameters are non-NULL.
1455 * Free the string with g_free() after usage.
1460 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1462 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1465 *uri = g_value_dup_string (gst_structure_id_get_value (query->structure,