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 a new query types to the gstreamer
32 * Query types can be used to perform queries on pads and elements.
34 * Queries can be created using the gst_query_new_xxx() functions.
35 * Query values can be set using gst_query_set_xxx(), and parsed using
36 * gst_query_parse_xxx() helpers.
38 * The following example shows how to query the duration of a pipeline:
41 * <title>Query duration on a pipeline</title>
45 * query = gst_query_new_duration (GST_FORMAT_TIME);
46 * res = gst_element_query (pipeline, query);
49 * gst_query_parse_duration (query, NULL, &duration);
50 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
53 * g_print ("duration query failed...");
55 * gst_query_unref (query);
59 * Last reviewed on 2006-02-14 (0.10.4)
62 #include "gst_private.h"
66 #include "gstenumtypes.h"
70 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
71 #define GST_CAT_DEFAULT gst_query_debug
73 static void gst_query_finalize (GstQuery * query);
74 static GstQuery *_gst_query_copy (GstQuery * query);
76 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
77 static GList *_gst_queries = NULL;
78 static GHashTable *_nick_to_query = NULL;
79 static GHashTable *_query_type_to_nick = NULL;
80 static guint32 _n_values = 1; /* we start from 1 because 0 reserved for NONE */
82 static GstMiniObjectClass *parent_class = NULL;
84 static GstQueryTypeDefinition standard_definitions[] = {
85 {GST_QUERY_POSITION, "position", "Current position", 0},
86 {GST_QUERY_DURATION, "duration", "Total duration", 0},
87 {GST_QUERY_LATENCY, "latency", "Latency", 0},
88 {GST_QUERY_JITTER, "jitter", "Jitter", 0},
89 {GST_QUERY_RATE, "rate", "Configured rate 1000000 = 1", 0},
90 {GST_QUERY_SEEKING, "seeking", "Seeking capabilities and parameters", 0},
91 {GST_QUERY_SEGMENT, "segment", "currently configured segment", 0},
92 {GST_QUERY_CONVERT, "convert", "Converting between formats", 0},
93 {GST_QUERY_FORMATS, "formats", "Supported formats for conversion", 0},
94 {GST_QUERY_BUFFERING, "buffering", "Buffering status", 0},
95 {GST_QUERY_CUSTOM, "custom", "Custom query", 0},
96 {GST_QUERY_URI, "uri", "URI of the source or sink", 0},
101 _gst_query_initialize (void)
103 GstQueryTypeDefinition *standards = standard_definitions;
105 GST_CAT_INFO (GST_CAT_GST_INIT, "init queries");
107 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
109 g_static_mutex_lock (&mutex);
110 if (_nick_to_query == NULL) {
111 _nick_to_query = g_hash_table_new (g_str_hash, g_str_equal);
112 _query_type_to_nick = g_hash_table_new (NULL, NULL);
115 while (standards->nick) {
116 standards->quark = g_quark_from_static_string (standards->nick);
117 g_hash_table_insert (_nick_to_query, standards->nick, standards);
118 g_hash_table_insert (_query_type_to_nick,
119 GINT_TO_POINTER (standards->value), standards);
121 _gst_queries = g_list_append (_gst_queries, standards);
125 g_static_mutex_unlock (&mutex);
127 g_type_class_ref (gst_query_get_type ());
131 * gst_query_type_get_name:
132 * @query: the query type
134 * Get a printable name for the given query type. Do not modify or free.
136 * Returns: a reference to the static name of the query.
139 gst_query_type_get_name (GstQueryType query)
141 const GstQueryTypeDefinition *def;
143 def = gst_query_type_get_details (query);
149 * gst_query_type_to_quark:
150 * @query: the query type
152 * Get the unique quark for the given query type.
154 * Returns: the quark associated with the query type
157 gst_query_type_to_quark (GstQueryType query)
159 const GstQueryTypeDefinition *def;
161 def = gst_query_type_get_details (query);
166 G_DEFINE_TYPE (GstQuery, gst_query, GST_TYPE_MINI_OBJECT);
169 gst_query_class_init (GstQueryClass * klass)
171 parent_class = g_type_class_peek_parent (klass);
173 klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
174 klass->mini_object_class.finalize =
175 (GstMiniObjectFinalizeFunction) gst_query_finalize;
180 gst_query_init (GstQuery * query)
185 gst_query_finalize (GstQuery * query)
187 g_return_if_fail (query != NULL);
189 if (query->structure) {
190 gst_structure_set_parent_refcount (query->structure, NULL);
191 gst_structure_free (query->structure);
194 GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (query));
198 _gst_query_copy (GstQuery * query)
202 copy = (GstQuery *) gst_mini_object_new (GST_TYPE_QUERY);
204 copy->type = query->type;
206 if (query->structure) {
207 copy->structure = gst_structure_copy (query->structure);
208 gst_structure_set_parent_refcount (copy->structure,
209 &query->mini_object.refcount);
218 * gst_query_type_register:
219 * @nick: The nick of the new query
220 * @description: The description of the new query
222 * Create a new GstQueryType based on the nick or return an
223 * already registered query with that nick
225 * Returns: A new GstQueryType or an already registered query
226 * with the same nick.
229 gst_query_type_register (const gchar * nick, const gchar * description)
231 GstQueryTypeDefinition *query;
234 g_return_val_if_fail (nick != NULL, 0);
235 g_return_val_if_fail (description != NULL, 0);
237 lookup = gst_query_type_get_by_nick (nick);
238 if (lookup != GST_QUERY_NONE)
241 query = g_new0 (GstQueryTypeDefinition, 1);
242 query->value = _n_values;
243 query->nick = g_strdup (nick);
244 query->description = g_strdup (description);
245 query->quark = g_quark_from_static_string (query->nick);
247 g_static_mutex_lock (&mutex);
248 g_hash_table_insert (_nick_to_query, query->nick, query);
249 g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
251 _gst_queries = g_list_append (_gst_queries, query);
253 g_static_mutex_unlock (&mutex);
259 * gst_query_type_get_by_nick:
260 * @nick: The nick of the query
262 * Get the query type registered with @nick.
264 * Returns: The query registered with @nick or #GST_QUERY_NONE
265 * if the query was not registered.
268 gst_query_type_get_by_nick (const gchar * nick)
270 GstQueryTypeDefinition *query;
272 g_return_val_if_fail (nick != NULL, 0);
274 g_static_mutex_lock (&mutex);
275 query = g_hash_table_lookup (_nick_to_query, nick);
276 g_static_mutex_unlock (&mutex);
281 return GST_QUERY_NONE;
285 * gst_query_types_contains:
286 * @types: The query array to search
287 * @type: the #GstQueryType to find
289 * See if the given #GstQueryType is inside the @types query types array.
291 * Returns: TRUE if the type is found inside the array
294 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
310 * gst_query_type_get_details:
311 * @type: a #GstQueryType
313 * Get details about the given #GstQueryType.
315 * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
317 const GstQueryTypeDefinition *
318 gst_query_type_get_details (GstQueryType type)
320 const GstQueryTypeDefinition *result;
322 g_static_mutex_lock (&mutex);
323 result = g_hash_table_lookup (_query_type_to_nick, GINT_TO_POINTER (type));
324 g_static_mutex_unlock (&mutex);
330 * gst_query_type_iterate_definitions:
332 * Get a #GstIterator of all the registered query types. The definitions
333 * iterated over are read only.
335 * Returns: A #GstIterator of #GstQueryTypeDefinition.
338 gst_query_type_iterate_definitions (void)
342 g_static_mutex_lock (&mutex);
343 /* FIXME: register a boxed type for GstQueryTypeDefinition */
344 result = gst_iterator_new_list (G_TYPE_POINTER,
345 g_static_mutex_get_mutex (&mutex), &_n_values, &_gst_queries,
347 g_static_mutex_unlock (&mutex);
353 gst_query_new (GstQueryType type, GstStructure * structure)
357 query = (GstQuery *) gst_mini_object_new (GST_TYPE_QUERY);
359 GST_DEBUG ("creating new query %p %d", query, type);
364 query->structure = structure;
365 gst_structure_set_parent_refcount (query->structure,
366 &query->mini_object.refcount);
368 query->structure = NULL;
375 * gst_query_new_position:
376 * @format: the default #GstFormat for the new query
378 * Constructs a new query stream position query object. Use gst_query_unref()
379 * when done with it. A position query is used to query the current position
380 * of playback in the streams, in some format.
382 * Returns: A #GstQuery
385 gst_query_new_position (GstFormat format)
388 GstStructure *structure;
390 structure = gst_structure_id_new (GST_QUARK (QUERY_POSITION),
391 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
392 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
394 query = gst_query_new (GST_QUERY_POSITION, structure);
400 * gst_query_set_position:
401 * @query: a #GstQuery with query type GST_QUERY_POSITION
402 * @format: the requested #GstFormat
403 * @cur: the position to set
405 * Answer a position query by setting the requested value in the given format.
408 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
410 GstStructure *structure;
412 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
414 structure = gst_query_get_structure (query);
415 gst_structure_id_set (structure,
416 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
417 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
421 * gst_query_parse_position:
422 * @query: a #GstQuery
423 * @format: the storage for the #GstFormat of the position values (may be NULL)
424 * @cur: the storage for the current position (may be NULL)
426 * Parse a position query, writing the format into @format, and the position
427 * into @cur, if the respective parameters are non-NULL.
430 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
432 GstStructure *structure;
434 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
436 structure = gst_query_get_structure (query);
438 *format = g_value_get_enum (gst_structure_id_get_value (structure,
439 GST_QUARK (FORMAT)));
441 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
442 GST_QUARK (CURRENT)));
447 * gst_query_new_duration:
448 * @format: the #GstFormat for this duration query
450 * Constructs a new stream duration query object to query in the given format.
451 * Use gst_query_unref() when done with it. A duration query will give the
452 * total length of the stream.
454 * Returns: A #GstQuery
457 gst_query_new_duration (GstFormat format)
460 GstStructure *structure;
462 structure = gst_structure_id_new (GST_QUARK (QUERY_DURATION),
463 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
464 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
466 query = gst_query_new (GST_QUERY_DURATION, structure);
472 * gst_query_set_duration:
473 * @query: a #GstQuery
474 * @format: the #GstFormat for the duration
475 * @duration: the duration of the stream
477 * Answer a duration query by setting the requested value in the given format.
480 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
482 GstStructure *structure;
484 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
486 structure = gst_query_get_structure (query);
487 gst_structure_id_set (structure,
488 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
489 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
493 * gst_query_parse_duration:
494 * @query: a #GstQuery
495 * @format: the storage for the #GstFormat of the duration value, or NULL.
496 * @duration: the storage for the total duration, or NULL.
498 * Parse a duration query answer. Write the format of the duration into @format,
499 * and the value into @duration, if the respective variables are non-NULL.
502 gst_query_parse_duration (GstQuery * query, GstFormat * format,
505 GstStructure *structure;
507 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
509 structure = gst_query_get_structure (query);
511 *format = g_value_get_enum (gst_structure_id_get_value (structure,
512 GST_QUARK (FORMAT)));
514 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
515 GST_QUARK (DURATION)));
519 * gst_query_new_latency:
521 * Constructs a new latency query object.
522 * Use gst_query_unref() when done with it. A latency query is usually performed
523 * by sinks to compensate for additional latency introduced by elements in the
526 * Returns: A #GstQuery
531 gst_query_new_latency (void)
534 GstStructure *structure;
536 structure = gst_structure_id_new (GST_QUARK (QUERY_LATENCY),
537 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
538 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
539 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
541 query = gst_query_new (GST_QUERY_LATENCY, structure);
547 * gst_query_set_latency:
548 * @query: a #GstQuery
549 * @live: if there is a live element upstream
550 * @min_latency: the minimal latency of the live element
551 * @max_latency: the maximal latency of the live element
553 * Answer a latency query by setting the requested values in the given format.
558 gst_query_set_latency (GstQuery * query, gboolean live,
559 GstClockTime min_latency, GstClockTime max_latency)
561 GstStructure *structure;
563 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
565 structure = gst_query_get_structure (query);
566 gst_structure_id_set (structure,
567 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
568 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
569 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
573 * gst_query_parse_latency:
574 * @query: a #GstQuery
575 * @live: storage for live or NULL
576 * @min_latency: the storage for the min latency or NULL
577 * @max_latency: the storage for the max latency or NULL
579 * Parse a latency query answer.
584 gst_query_parse_latency (GstQuery * query, gboolean * live,
585 GstClockTime * min_latency, GstClockTime * max_latency)
587 GstStructure *structure;
589 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
591 structure = gst_query_get_structure (query);
594 g_value_get_boolean (gst_structure_id_get_value (structure,
597 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
598 GST_QUARK (MIN_LATENCY)));
600 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
601 GST_QUARK (MAX_LATENCY)));
605 * gst_query_new_convert:
606 * @src_format: the source #GstFormat for the new query
607 * @value: the value to convert
608 * @dest_format: the target #GstFormat
610 * Constructs a new convert query object. Use gst_query_unref()
611 * when done with it. A convert query is used to ask for a conversion between
612 * one format and another.
614 * Returns: A #GstQuery
617 gst_query_new_convert (GstFormat src_format, gint64 value,
618 GstFormat dest_format)
621 GstStructure *structure;
623 structure = gst_structure_id_new (GST_QUARK (QUERY_CONVERT),
624 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
625 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
626 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
627 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
629 query = gst_query_new (GST_QUERY_CONVERT, structure);
635 * gst_query_set_convert:
636 * @query: a #GstQuery
637 * @src_format: the source #GstFormat
638 * @src_value: the source value
639 * @dest_format: the destination #GstFormat
640 * @dest_value: the destination value
642 * Answer a convert query by setting the requested values.
645 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
646 GstFormat dest_format, gint64 dest_value)
648 GstStructure *structure;
650 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
652 structure = gst_query_get_structure (query);
653 gst_structure_id_set (structure,
654 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
655 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
656 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
657 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
661 * gst_query_parse_convert:
662 * @query: a #GstQuery
663 * @src_format: the storage for the #GstFormat of the source value, or NULL
664 * @src_value: the storage for the source value, or NULL
665 * @dest_format: the storage for the #GstFormat of the destination value, or NULL
666 * @dest_value: the storage for the destination value, or NULL
668 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
669 * and @dest_value may be NULL, in which case that value is omitted.
672 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
673 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
675 GstStructure *structure;
677 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
679 structure = gst_query_get_structure (query);
681 *src_format = g_value_get_enum (gst_structure_id_get_value (structure,
682 GST_QUARK (SRC_FORMAT)));
684 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
685 GST_QUARK (SRC_VALUE)));
687 *dest_format = g_value_get_enum (gst_structure_id_get_value (structure,
688 GST_QUARK (DEST_FORMAT)));
690 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
691 GST_QUARK (DEST_VALUE)));
695 * gst_query_new_segment:
696 * @format: the #GstFormat for the new query
698 * Constructs a new segment query object. Use gst_query_unref()
699 * when done with it. A segment query is used to discover information about the
700 * currently configured segment for playback.
702 * Returns: a #GstQuery
705 gst_query_new_segment (GstFormat format)
708 GstStructure *structure;
710 structure = gst_structure_id_new (GST_QUARK (QUERY_SEGMENT),
711 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
712 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
713 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
714 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
716 query = gst_query_new (GST_QUERY_SEGMENT, structure);
722 * gst_query_set_segment:
723 * @query: a #GstQuery
724 * @rate: the rate of the segment
725 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
726 * @start_value: the start value
727 * @stop_value: the stop value
729 * Answer a segment query by setting the requested values. The normal
730 * playback segment of a pipeline is 0 to duration at the default rate of
731 * 1.0. If a seek was performed on the pipeline to play a different
732 * segment, this query will return the range specified in the last seek.
734 * @start_value and @stop_value will respectively contain the configured
735 * playback range start and stop values expressed in @format.
736 * The values are always between 0 and the duration of the media and
737 * @start_value <= @stop_value. @rate will contain the playback rate. For
738 * negative rates, playback will actually happen from @stop_value to
742 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
743 gint64 start_value, gint64 stop_value)
745 GstStructure *structure;
747 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
749 structure = gst_query_get_structure (query);
750 gst_structure_id_set (structure,
751 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
752 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
753 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
754 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
758 * gst_query_parse_segment:
759 * @query: a #GstQuery
760 * @rate: the storage for the rate of the segment, or NULL
761 * @format: the storage for the #GstFormat of the values, or NULL
762 * @start_value: the storage for the start value, or NULL
763 * @stop_value: the storage for the stop value, or NULL
765 * Parse a segment query answer. Any of @rate, @format, @start_value, and
766 * @stop_value may be NULL, which will cause this value to be omitted.
768 * See gst_query_set_segment() for an explanation of the function arguments.
771 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
772 gint64 * start_value, gint64 * stop_value)
774 GstStructure *structure;
776 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
778 structure = gst_query_get_structure (query);
780 *rate = g_value_get_double (gst_structure_id_get_value (structure,
783 *format = g_value_get_enum (gst_structure_id_get_value (structure,
784 GST_QUARK (FORMAT)));
786 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
787 GST_QUARK (START_VALUE)));
789 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
790 GST_QUARK (STOP_VALUE)));
794 * gst_query_new_application:
795 * @type: the query type
796 * @structure: a structure for the query
798 * Constructs a new custom application query object. Use gst_query_unref()
801 * Returns: a #GstQuery
804 gst_query_new_application (GstQueryType type, GstStructure * structure)
806 g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
807 g_return_val_if_fail (structure != NULL, NULL);
809 return gst_query_new (type, structure);
813 * gst_query_get_structure:
814 * @query: a #GstQuery
816 * Get the structure of a query.
818 * Returns: The #GstStructure of the query. The structure is still owned
819 * by the query and will therefore be freed when the query is unreffed.
822 gst_query_get_structure (GstQuery * query)
824 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
826 return query->structure;
830 * gst_query_new_seeking:
831 * @format: the default #GstFormat for the new query
833 * Constructs a new query object for querying seeking properties of
836 * Returns: A #GstQuery
839 gst_query_new_seeking (GstFormat format)
842 GstStructure *structure;
844 structure = gst_structure_id_new (GST_QUARK (QUERY_SEEKING),
845 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
846 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
847 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
848 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
850 query = gst_query_new (GST_QUERY_SEEKING, structure);
856 * gst_query_set_seeking:
857 * @query: a #GstQuery
858 * @format: the format to set for the @segment_start and @segment_end values
859 * @seekable: the seekable flag to set
860 * @segment_start: the segment_start to set
861 * @segment_end: the segment_end to set
863 * Set the seeking query result fields in @query.
866 gst_query_set_seeking (GstQuery * query, GstFormat format,
867 gboolean seekable, gint64 segment_start, gint64 segment_end)
869 GstStructure *structure;
871 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
873 structure = gst_query_get_structure (query);
874 gst_structure_id_set (structure,
875 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
876 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
877 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
878 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
882 * gst_query_parse_seeking:
883 * @query: a GST_QUERY_SEEKING type query #GstQuery
884 * @format: the format to set for the @segment_start and @segment_end values
885 * @seekable: the seekable flag to set
886 * @segment_start: the segment_start to set
887 * @segment_end: the segment_end to set
889 * Parse a seeking query, writing the format into @format, and
890 * other results into the passed parameters, if the respective parameters
894 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
895 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
897 GstStructure *structure;
899 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
901 structure = gst_query_get_structure (query);
903 *format = g_value_get_enum (gst_structure_id_get_value (structure,
904 GST_QUARK (FORMAT)));
906 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
907 GST_QUARK (SEEKABLE)));
909 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
910 GST_QUARK (SEGMENT_START)));
912 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
913 GST_QUARK (SEGMENT_END)));
917 * gst_query_new_formats:
919 * Constructs a new query object for querying formats of
922 * Returns: A #GstQuery
927 gst_query_new_formats (void)
930 GstStructure *structure;
932 structure = gst_structure_id_empty_new (GST_QUARK (QUERY_FORMATS));
933 query = gst_query_new (GST_QUERY_FORMATS, structure);
939 gst_query_list_add_format (GValue * list, GstFormat format)
941 GValue item = { 0, };
943 g_value_init (&item, GST_TYPE_FORMAT);
944 g_value_set_enum (&item, format);
945 gst_value_list_append_value (list, &item);
946 g_value_unset (&item);
950 * gst_query_set_formats:
951 * @query: a #GstQuery
952 * @n_formats: the number of formats to set.
953 * @...: A number of @GstFormats equal to @n_formats.
955 * Set the formats query result fields in @query. The number of formats passed
956 * must be equal to @n_formats.
959 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
962 GValue list = { 0, };
963 GstStructure *structure;
966 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
968 g_value_init (&list, GST_TYPE_LIST);
970 va_start (ap, n_formats);
971 for (i = 0; i < n_formats; i++) {
972 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
976 structure = gst_query_get_structure (query);
977 gst_structure_set_value (structure, "formats", &list);
979 g_value_unset (&list);
984 * gst_query_set_formatsv:
985 * @query: a #GstQuery
986 * @n_formats: the number of formats to set.
987 * @formats: An array containing @n_formats @GstFormat values.
989 * Set the formats query result fields in @query. The number of formats passed
990 * in the @formats array must be equal to @n_formats.
995 gst_query_set_formatsv (GstQuery * query, gint n_formats, GstFormat * formats)
997 GValue list = { 0, };
998 GstStructure *structure;
1001 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1003 g_value_init (&list, GST_TYPE_LIST);
1004 for (i = 0; i < n_formats; i++) {
1005 gst_query_list_add_format (&list, formats[i]);
1007 structure = gst_query_get_structure (query);
1008 gst_structure_set_value (structure, "formats", &list);
1010 g_value_unset (&list);
1014 * gst_query_parse_formats_length:
1015 * @query: a #GstQuery
1016 * @n_formats: the number of formats in this query.
1018 * Parse the number of formats in the formats @query.
1023 gst_query_parse_formats_length (GstQuery * query, guint * n_formats)
1025 GstStructure *structure;
1027 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1032 structure = gst_query_get_structure (query);
1033 list = gst_structure_get_value (structure, "formats");
1037 *n_formats = gst_value_list_get_size (list);
1042 * gst_query_parse_formats_nth:
1043 * @query: a #GstQuery
1044 * @nth: the nth format to retrieve.
1045 * @format: a pointer to store the nth format
1047 * Parse the format query and retrieve the @nth format from it into
1048 * @format. If the list contains less elements than @nth, @format will be
1049 * set to GST_FORMAT_UNDEFINED.
1054 gst_query_parse_formats_nth (GstQuery * query, guint nth, GstFormat * format)
1056 GstStructure *structure;
1058 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1063 structure = gst_query_get_structure (query);
1064 list = gst_structure_get_value (structure, "formats");
1066 *format = GST_FORMAT_UNDEFINED;
1068 if (nth < gst_value_list_get_size (list)) {
1069 *format = g_value_get_enum (gst_value_list_get_value (list, nth));
1071 *format = GST_FORMAT_UNDEFINED;
1077 * gst_query_new_buffering
1078 * @format: the default #GstFormat for the new query
1080 * Constructs a new query object for querying the buffering status of
1083 * Returns: A #GstQuery
1088 gst_query_new_buffering (GstFormat format)
1091 GstStructure *structure;
1093 /* by default, we configure the answer as no buffering with a 100% buffering
1095 structure = gst_structure_id_new (GST_QUARK (QUERY_BUFFERING),
1096 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1097 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1098 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1099 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1100 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1101 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1102 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1103 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1104 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1105 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1107 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1113 * gst_query_set_buffering_percent
1114 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1115 * @busy: if buffering is busy
1116 * @percent: a buffering percent
1118 * Set the percentage of buffered data. This is a value between 0 and 100.
1119 * The @busy indicator is %TRUE when the buffering is in progress.
1124 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1126 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1127 g_return_if_fail (percent >= 0 && percent <= 100);
1129 gst_structure_id_set (query->structure,
1130 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1131 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1135 * gst_query_parse_buffering_percent
1136 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1137 * @busy: if buffering is busy
1138 * @percent: a buffering percent
1140 * Get the percentage of buffered data. This is a value between 0 and 100.
1141 * The @busy indicator is %TRUE when the buffering is in progress.
1146 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1149 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1152 *busy = g_value_get_boolean (gst_structure_id_get_value (query->structure,
1155 *percent = g_value_get_int (gst_structure_id_get_value (query->structure,
1156 GST_QUARK (BUFFER_PERCENT)));
1160 * gst_query_set_buffering_stats:
1161 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1162 * @mode: a buffering mode
1163 * @avg_in: the average input rate
1164 * @avg_out: the average output rate
1165 * @buffering_left: amount of buffering time left
1167 * Configures the buffering stats values in @query.
1172 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1173 gint avg_in, gint avg_out, gint64 buffering_left)
1175 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1177 gst_structure_id_set (query->structure,
1178 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1179 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1180 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1181 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1185 * gst_query_parse_buffering_stats:
1186 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1187 * @mode: a buffering mode
1188 * @avg_in: the average input rate
1189 * @avg_out: the average output rate
1190 * @buffering_left: amount of buffering time left
1192 * Extracts the buffering stats values from @query.
1197 gst_query_parse_buffering_stats (GstQuery * query,
1198 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1199 gint64 * buffering_left)
1201 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1204 *mode = g_value_get_enum (gst_structure_id_get_value (query->structure,
1205 GST_QUARK (BUFFERING_MODE)));
1207 *avg_in = g_value_get_int (gst_structure_id_get_value (query->structure,
1208 GST_QUARK (AVG_IN_RATE)));
1210 *avg_out = g_value_get_int (gst_structure_id_get_value (query->structure,
1211 GST_QUARK (AVG_OUT_RATE)));
1214 g_value_get_int64 (gst_structure_id_get_value (query->structure,
1215 GST_QUARK (BUFFERING_LEFT)));
1220 * gst_query_set_buffering_range:
1221 * @query: a #GstQuery
1222 * @format: the format to set for the @start and @stop values
1223 * @start: the start to set
1224 * @stop: the stop to set
1225 * @estimated_total: estimated total amount of download time
1227 * Set the available query result fields in @query.
1232 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1233 gint64 start, gint64 stop, gint64 estimated_total)
1235 GstStructure *structure;
1237 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1239 structure = gst_query_get_structure (query);
1240 gst_structure_id_set (structure,
1241 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1242 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1243 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1244 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1248 * gst_query_parse_buffering_range:
1249 * @query: a GST_QUERY_SEEKING type query #GstQuery
1250 * @format: the format to set for the @segment_start and @segment_end values
1251 * @start: the start to set
1252 * @stop: the stop to set
1253 * @estimated_total: estimated total amount of download time
1255 * Parse an available query, writing the format into @format, and
1256 * other results into the passed parameters, if the respective parameters
1262 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1263 gint64 * start, gint64 * stop, gint64 * estimated_total)
1265 GstStructure *structure;
1267 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1269 structure = gst_query_get_structure (query);
1271 *format = g_value_get_enum (gst_structure_id_get_value (structure,
1272 GST_QUARK (FORMAT)));
1274 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1275 GST_QUARK (START_VALUE)));
1277 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1278 GST_QUARK (STOP_VALUE)));
1279 if (estimated_total)
1281 g_value_get_int64 (gst_structure_id_get_value (structure,
1282 GST_QUARK (ESTIMATED_TOTAL)));
1286 * gst_query_new_uri:
1288 * Constructs a new query URI query object. Use gst_query_unref()
1289 * when done with it. An URI query is used to query the current URI
1290 * that is used by the source or sink.
1292 * Returns: A #GstQuery
1297 gst_query_new_uri (void)
1300 GstStructure *structure;
1302 structure = gst_structure_id_new (GST_QUARK (QUERY_URI),
1303 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1305 query = gst_query_new (GST_QUERY_URI, structure);
1311 * gst_query_set_uri:
1312 * @query: a #GstQuery with query type GST_QUERY_URI
1313 * @uri: the URI to set
1315 * Answer a URI query by setting the requested URI.
1320 gst_query_set_uri (GstQuery * query, const gchar * uri)
1322 GstStructure *structure;
1324 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1325 g_return_if_fail (gst_uri_is_valid (uri));
1327 structure = gst_query_get_structure (query);
1328 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1332 * gst_query_parse_uri:
1333 * @query: a #GstQuery
1334 * @uri: the storage for the current URI (may be NULL)
1336 * Parse an URI query, writing the URI into @uri as a newly
1337 * allocated string, if the respective parameters are non-NULL.
1338 * Free the string with g_free() after usage.
1343 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1345 GstStructure *structure;
1347 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1349 structure = gst_query_get_structure (query);
1351 *uri = g_value_dup_string (gst_structure_id_get_value (structure,