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_empty_new ("GstQueryPosition");
391 gst_structure_id_set (structure,
392 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
393 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
395 query = gst_query_new (GST_QUERY_POSITION, structure);
401 * gst_query_set_position:
402 * @query: a #GstQuery with query type GST_QUERY_POSITION
403 * @format: the requested #GstFormat
404 * @cur: the position to set
406 * Answer a position query by setting the requested value in the given format.
409 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
411 GstStructure *structure;
413 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
415 structure = gst_query_get_structure (query);
416 gst_structure_id_set (structure,
417 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
418 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
422 * gst_query_parse_position:
423 * @query: a #GstQuery
424 * @format: the storage for the #GstFormat of the position values (may be NULL)
425 * @cur: the storage for the current position (may be NULL)
427 * Parse a position query, writing the format into @format, and the position
428 * into @cur, if the respective parameters are non-NULL.
431 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
433 GstStructure *structure;
435 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
437 structure = gst_query_get_structure (query);
439 *format = g_value_get_enum (gst_structure_id_get_value (structure,
440 GST_QUARK (FORMAT)));
442 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
443 GST_QUARK (CURRENT)));
448 * gst_query_new_duration:
449 * @format: the #GstFormat for this duration query
451 * Constructs a new stream duration query object to query in the given format.
452 * Use gst_query_unref() when done with it. A duration query will give the
453 * total length of the stream.
455 * Returns: A #GstQuery
458 gst_query_new_duration (GstFormat format)
461 GstStructure *structure;
463 structure = gst_structure_empty_new ("GstQueryDuration");
464 gst_structure_id_set (structure,
465 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
466 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
468 query = gst_query_new (GST_QUERY_DURATION, structure);
474 * gst_query_set_duration:
475 * @query: a #GstQuery
476 * @format: the #GstFormat for the duration
477 * @duration: the duration of the stream
479 * Answer a duration query by setting the requested value in the given format.
482 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
484 GstStructure *structure;
486 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
488 structure = gst_query_get_structure (query);
489 gst_structure_id_set (structure,
490 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
491 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
495 * gst_query_parse_duration:
496 * @query: a #GstQuery
497 * @format: the storage for the #GstFormat of the duration value, or NULL.
498 * @duration: the storage for the total duration, or NULL.
500 * Parse a duration query answer. Write the format of the duration into @format,
501 * and the value into @duration, if the respective variables are non-NULL.
504 gst_query_parse_duration (GstQuery * query, GstFormat * format,
507 GstStructure *structure;
509 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
511 structure = gst_query_get_structure (query);
513 *format = g_value_get_enum (gst_structure_id_get_value (structure,
514 GST_QUARK (FORMAT)));
516 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
517 GST_QUARK (DURATION)));
521 * gst_query_new_latency:
523 * Constructs a new latency query object.
524 * Use gst_query_unref() when done with it. A latency query is usually performed
525 * by sinks to compensate for additional latency introduced by elements in the
528 * Returns: A #GstQuery
533 gst_query_new_latency (void)
536 GstStructure *structure;
538 structure = gst_structure_empty_new ("GstQueryLatency");
539 gst_structure_id_set (structure,
540 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
541 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
542 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
544 query = gst_query_new (GST_QUERY_LATENCY, structure);
550 * gst_query_set_latency:
551 * @query: a #GstQuery
552 * @live: if there is a live element upstream
553 * @min_latency: the minimal latency of the live element
554 * @max_latency: the maximal latency of the live element
556 * Answer a latency query by setting the requested values in the given format.
561 gst_query_set_latency (GstQuery * query, gboolean live,
562 GstClockTime min_latency, GstClockTime max_latency)
564 GstStructure *structure;
566 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
568 structure = gst_query_get_structure (query);
569 gst_structure_id_set (structure,
570 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
571 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
572 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
576 * gst_query_parse_latency:
577 * @query: a #GstQuery
578 * @live: storage for live or NULL
579 * @min_latency: the storage for the min latency or NULL
580 * @max_latency: the storage for the max latency or NULL
582 * Parse a latency query answer.
587 gst_query_parse_latency (GstQuery * query, gboolean * live,
588 GstClockTime * min_latency, GstClockTime * max_latency)
590 GstStructure *structure;
592 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
594 structure = gst_query_get_structure (query);
597 g_value_get_boolean (gst_structure_id_get_value (structure,
600 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
601 GST_QUARK (MIN_LATENCY)));
603 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
604 GST_QUARK (MAX_LATENCY)));
608 * gst_query_new_convert:
609 * @src_format: the source #GstFormat for the new query
610 * @value: the value to convert
611 * @dest_format: the target #GstFormat
613 * Constructs a new convert query object. Use gst_query_unref()
614 * when done with it. A convert query is used to ask for a conversion between
615 * one format and another.
617 * Returns: A #GstQuery
620 gst_query_new_convert (GstFormat src_format, gint64 value,
621 GstFormat dest_format)
624 GstStructure *structure;
626 structure = gst_structure_empty_new ("GstQueryConvert");
627 gst_structure_id_set (structure,
628 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
629 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
630 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
631 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
633 query = gst_query_new (GST_QUERY_CONVERT, structure);
639 * gst_query_set_convert:
640 * @query: a #GstQuery
641 * @src_format: the source #GstFormat
642 * @src_value: the source value
643 * @dest_format: the destination #GstFormat
644 * @dest_value: the destination value
646 * Answer a convert query by setting the requested values.
649 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
650 GstFormat dest_format, gint64 dest_value)
652 GstStructure *structure;
654 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
656 structure = gst_query_get_structure (query);
657 gst_structure_id_set (structure,
658 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
659 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
660 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
661 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
665 * gst_query_parse_convert:
666 * @query: a #GstQuery
667 * @src_format: the storage for the #GstFormat of the source value, or NULL
668 * @src_value: the storage for the source value, or NULL
669 * @dest_format: the storage for the #GstFormat of the destination value, or NULL
670 * @dest_value: the storage for the destination value, or NULL
672 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
673 * and @dest_value may be NULL, in which case that value is omitted.
676 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
677 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
679 GstStructure *structure;
681 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
683 structure = gst_query_get_structure (query);
685 *src_format = g_value_get_enum (gst_structure_id_get_value (structure,
686 GST_QUARK (SRC_FORMAT)));
688 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
689 GST_QUARK (SRC_VALUE)));
691 *dest_format = g_value_get_enum (gst_structure_id_get_value (structure,
692 GST_QUARK (DEST_FORMAT)));
694 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
695 GST_QUARK (DEST_VALUE)));
699 * gst_query_new_segment:
700 * @format: the #GstFormat for the new query
702 * Constructs a new segment query object. Use gst_query_unref()
703 * when done with it. A segment query is used to discover information about the
704 * currently configured segment for playback.
706 * Returns: a #GstQuery
709 gst_query_new_segment (GstFormat format)
712 GstStructure *structure;
714 structure = gst_structure_empty_new ("GstQuerySegment");
715 gst_structure_id_set (structure,
716 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
717 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
718 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
719 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
721 query = gst_query_new (GST_QUERY_SEGMENT, structure);
727 * gst_query_set_segment:
728 * @query: a #GstQuery
729 * @rate: the rate of the segment
730 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
731 * @start_value: the start value
732 * @stop_value: the stop value
734 * Answer a segment query by setting the requested values. The normal
735 * playback segment of a pipeline is 0 to duration at the default rate of
736 * 1.0. If a seek was performed on the pipeline to play a different
737 * segment, this query will return the range specified in the last seek.
739 * @start_value and @stop_value will respectively contain the configured
740 * playback range start and stop values expressed in @format.
741 * The values are always between 0 and the duration of the media and
742 * @start_value <= @stop_value. @rate will contain the playback rate. For
743 * negative rates, playback will actually happen from @stop_value to
747 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
748 gint64 start_value, gint64 stop_value)
750 GstStructure *structure;
752 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
754 structure = gst_query_get_structure (query);
755 gst_structure_id_set (structure,
756 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
757 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
758 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
759 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
763 * gst_query_parse_segment:
764 * @query: a #GstQuery
765 * @rate: the storage for the rate of the segment, or NULL
766 * @format: the storage for the #GstFormat of the values, or NULL
767 * @start_value: the storage for the start value, or NULL
768 * @stop_value: the storage for the stop value, or NULL
770 * Parse a segment query answer. Any of @rate, @format, @start_value, and
771 * @stop_value may be NULL, which will cause this value to be omitted.
773 * See gst_query_set_segment() for an explanation of the function arguments.
776 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
777 gint64 * start_value, gint64 * stop_value)
779 GstStructure *structure;
781 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
783 structure = gst_query_get_structure (query);
785 *rate = g_value_get_double (gst_structure_id_get_value (structure,
788 *format = g_value_get_enum (gst_structure_id_get_value (structure,
789 GST_QUARK (FORMAT)));
791 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
792 GST_QUARK (START_VALUE)));
794 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
795 GST_QUARK (STOP_VALUE)));
799 * gst_query_new_application:
800 * @type: the query type
801 * @structure: a structure for the query
803 * Constructs a new custom application query object. Use gst_query_unref()
806 * Returns: a #GstQuery
809 gst_query_new_application (GstQueryType type, GstStructure * structure)
811 g_return_val_if_fail (gst_query_type_get_details (type) != NULL, NULL);
812 g_return_val_if_fail (structure != NULL, NULL);
814 return gst_query_new (type, structure);
818 * gst_query_get_structure:
819 * @query: a #GstQuery
821 * Get the structure of a query.
823 * Returns: The #GstStructure of the query. The structure is still owned
824 * by the query and will therefore be freed when the query is unreffed.
827 gst_query_get_structure (GstQuery * query)
829 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
831 return query->structure;
835 * gst_query_new_seeking (GstFormat *format)
836 * @format: the default #GstFormat for the new query
838 * Constructs a new query object for querying seeking properties of
841 * Returns: A #GstQuery
844 gst_query_new_seeking (GstFormat format)
847 GstStructure *structure;
849 structure = gst_structure_empty_new ("GstQuerySeeking");
850 gst_structure_id_set (structure,
851 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
852 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
853 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
854 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
856 query = gst_query_new (GST_QUERY_SEEKING, structure);
862 * gst_query_set_seeking:
863 * @query: a #GstQuery
864 * @format: the format to set for the @segment_start and @segment_end values
865 * @seekable: the seekable flag to set
866 * @segment_start: the segment_start to set
867 * @segment_end: the segment_end to set
869 * Set the seeking query result fields in @query.
872 gst_query_set_seeking (GstQuery * query, GstFormat format,
873 gboolean seekable, gint64 segment_start, gint64 segment_end)
875 GstStructure *structure;
877 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
879 structure = gst_query_get_structure (query);
880 gst_structure_id_set (structure,
881 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
882 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
883 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
884 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
888 * gst_query_parse_seeking:
889 * @query: a GST_QUERY_SEEKING type query #GstQuery
890 * @format: the format to set for the @segment_start and @segment_end values
891 * @seekable: the seekable flag to set
892 * @segment_start: the segment_start to set
893 * @segment_end: the segment_end to set
895 * Parse a seeking query, writing the format into @format, and
896 * other results into the passed parameters, if the respective parameters
900 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
901 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
903 GstStructure *structure;
905 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
907 structure = gst_query_get_structure (query);
909 *format = g_value_get_enum (gst_structure_id_get_value (structure,
910 GST_QUARK (FORMAT)));
912 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
913 GST_QUARK (SEEKABLE)));
915 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
916 GST_QUARK (SEGMENT_START)));
918 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
919 GST_QUARK (SEGMENT_END)));
923 * gst_query_new_formats:
925 * Constructs a new query object for querying formats of
928 * Returns: A #GstQuery
933 gst_query_new_formats (void)
936 GstStructure *structure;
938 structure = gst_structure_new ("GstQueryFormats", NULL);
939 query = gst_query_new (GST_QUERY_FORMATS, structure);
945 gst_query_list_add_format (GValue * list, GstFormat format)
947 GValue item = { 0, };
949 g_value_init (&item, GST_TYPE_FORMAT);
950 g_value_set_enum (&item, format);
951 gst_value_list_append_value (list, &item);
952 g_value_unset (&item);
956 * gst_query_set_formats:
957 * @query: a #GstQuery
958 * @n_formats: the number of formats to set.
959 * @...: A number of @GstFormats equal to @n_formats.
961 * Set the formats query result fields in @query. The number of formats passed
962 * must be equal to @n_formats.
965 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
968 GValue list = { 0, };
969 GstStructure *structure;
972 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
974 g_value_init (&list, GST_TYPE_LIST);
976 va_start (ap, n_formats);
977 for (i = 0; i < n_formats; i++) {
978 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
982 structure = gst_query_get_structure (query);
983 gst_structure_set_value (structure, "formats", &list);
985 g_value_unset (&list);
990 * gst_query_set_formatsv:
991 * @query: a #GstQuery
992 * @n_formats: the number of formats to set.
993 * @formats: An array containing @n_formats @GstFormat values.
995 * Set the formats query result fields in @query. The number of formats passed
996 * in the @formats array must be equal to @n_formats.
1001 gst_query_set_formatsv (GstQuery * query, gint n_formats, GstFormat * formats)
1003 GValue list = { 0, };
1004 GstStructure *structure;
1007 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1009 g_value_init (&list, GST_TYPE_LIST);
1010 for (i = 0; i < n_formats; i++) {
1011 gst_query_list_add_format (&list, formats[i]);
1013 structure = gst_query_get_structure (query);
1014 gst_structure_set_value (structure, "formats", &list);
1016 g_value_unset (&list);
1020 * gst_query_parse_formats_length:
1021 * @query: a #GstQuery
1022 * @n_formats: the number of formats in this query.
1024 * Parse the number of formats in the formats @query.
1029 gst_query_parse_formats_length (GstQuery * query, guint * n_formats)
1031 GstStructure *structure;
1033 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1038 structure = gst_query_get_structure (query);
1039 list = gst_structure_get_value (structure, "formats");
1043 *n_formats = gst_value_list_get_size (list);
1048 * gst_query_parse_formats_nth:
1049 * @query: a #GstQuery
1050 * @nth: the nth format to retrieve.
1051 * @format: a pointer to store the nth format
1053 * Parse the format query and retrieve the @nth format from it into
1054 * @format. If the list contains less elements than @nth, @format will be
1055 * set to GST_FORMAT_UNDEFINED.
1060 gst_query_parse_formats_nth (GstQuery * query, guint nth, GstFormat * format)
1062 GstStructure *structure;
1064 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1069 structure = gst_query_get_structure (query);
1070 list = gst_structure_get_value (structure, "formats");
1072 *format = GST_FORMAT_UNDEFINED;
1074 if (nth < gst_value_list_get_size (list)) {
1075 *format = g_value_get_enum (gst_value_list_get_value (list, nth));
1077 *format = GST_FORMAT_UNDEFINED;
1083 * gst_query_new_buffering
1084 * @format: the default #GstFormat for the new query
1086 * Constructs a new query object for querying the buffering status of
1089 * Returns: A #GstQuery
1094 gst_query_new_buffering (GstFormat format)
1097 GstStructure *structure;
1099 structure = gst_structure_empty_new ("GstQueryBuffering");
1100 /* by default, we configure the answer as no buffering with a 100% buffering
1102 gst_structure_id_set (structure,
1103 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1104 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1105 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1106 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1107 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1108 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1109 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1110 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1111 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1112 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1114 query = gst_query_new (GST_QUERY_BUFFERING, structure);
1120 * gst_query_set_buffering_percent
1121 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1122 * @busy: if buffering is busy
1123 * @percent: a buffering percent
1125 * Set the percentage of buffered data. This is a value between 0 and 100.
1126 * The @busy indicator is %TRUE when the buffering is in progress.
1131 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1133 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1134 g_return_if_fail (percent >= 0 && percent <= 100);
1136 gst_structure_id_set (query->structure,
1137 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1138 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1142 * gst_query_parse_buffering_percent
1143 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1144 * @busy: if buffering is busy
1145 * @percent: a buffering percent
1147 * Get the percentage of buffered data. This is a value between 0 and 100.
1148 * The @busy indicator is %TRUE when the buffering is in progress.
1153 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1156 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1159 *busy = g_value_get_boolean (gst_structure_id_get_value (query->structure,
1162 *percent = g_value_get_int (gst_structure_id_get_value (query->structure,
1163 GST_QUARK (BUFFER_PERCENT)));
1167 * gst_query_set_buffering_stats:
1168 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1169 * @mode: a buffering mode
1170 * @avg_in: the average input rate
1171 * @avg_out: the average output rate
1172 * @buffering_left: amount of buffering time left
1174 * Configures the buffering stats values in @query.
1179 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1180 gint avg_in, gint avg_out, gint64 buffering_left)
1182 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1184 gst_structure_id_set (query->structure,
1185 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1186 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1187 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1188 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1192 * gst_query_parse_buffering_stats:
1193 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1194 * @mode: a buffering mode
1195 * @avg_in: the average input rate
1196 * @avg_out: the average output rate
1197 * @buffering_left: amount of buffering time left
1199 * Extracts the buffering stats values from @query.
1204 gst_query_parse_buffering_stats (GstQuery * query,
1205 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1206 gint64 * buffering_left)
1208 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1211 *mode = g_value_get_enum (gst_structure_id_get_value (query->structure,
1212 GST_QUARK (BUFFERING_MODE)));
1214 *avg_in = g_value_get_int (gst_structure_id_get_value (query->structure,
1215 GST_QUARK (AVG_IN_RATE)));
1217 *avg_out = g_value_get_int (gst_structure_id_get_value (query->structure,
1218 GST_QUARK (AVG_OUT_RATE)));
1221 g_value_get_int64 (gst_structure_id_get_value (query->structure,
1222 GST_QUARK (BUFFERING_LEFT)));
1227 * gst_query_set_buffering_range:
1228 * @query: a #GstQuery
1229 * @format: the format to set for the @start and @stop values
1230 * @start: the start to set
1231 * @stop: the stop to set
1232 * @estimated_total: estimated total amount of download time
1234 * Set the available query result fields in @query.
1239 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1240 gint64 start, gint64 stop, gint64 estimated_total)
1242 GstStructure *structure;
1244 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1246 structure = gst_query_get_structure (query);
1247 gst_structure_id_set (structure,
1248 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1249 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1250 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1251 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1255 * gst_query_parse_buffering_range:
1256 * @query: a GST_QUERY_SEEKING type query #GstQuery
1257 * @format: the format to set for the @segment_start and @segment_end values
1258 * @start: the start to set
1259 * @stop: the stop to set
1260 * @estimated_total: estimated total amount of download time
1262 * Parse an available query, writing the format into @format, and
1263 * other results into the passed parameters, if the respective parameters
1269 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1270 gint64 * start, gint64 * stop, gint64 * estimated_total)
1272 GstStructure *structure;
1274 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1276 structure = gst_query_get_structure (query);
1278 *format = g_value_get_enum (gst_structure_id_get_value (structure,
1279 GST_QUARK (FORMAT)));
1281 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1282 GST_QUARK (START_VALUE)));
1284 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1285 GST_QUARK (STOP_VALUE)));
1286 if (estimated_total)
1288 g_value_get_int64 (gst_structure_id_get_value (structure,
1289 GST_QUARK (ESTIMATED_TOTAL)));
1293 * gst_query_new_uri:
1295 * Constructs a new query URI query object. Use gst_query_unref()
1296 * when done with it. An URI query is used to query the current URI
1297 * that is used by the source or sink.
1299 * Returns: A #GstQuery
1304 gst_query_new_uri (void)
1307 GstStructure *structure;
1309 structure = gst_structure_empty_new ("GstQueryURI");
1310 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1312 query = gst_query_new (GST_QUERY_URI, structure);
1318 * gst_query_set_uri:
1319 * @query: a #GstQuery with query type GST_QUERY_URI
1320 * @uri: the URI to set
1322 * Answer a URI query by setting the requested URI.
1327 gst_query_set_uri (GstQuery * query, const gchar * uri)
1329 GstStructure *structure;
1331 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1332 g_return_if_fail (gst_uri_is_valid (uri));
1334 structure = gst_query_get_structure (query);
1335 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1339 * gst_query_parse_uri:
1340 * @query: a #GstQuery
1341 * @uri: the storage for the current URI (may be NULL)
1343 * Parse an URI query, writing the URI into @uri as a newly
1344 * allocated string, if the respective parameters are non-NULL.
1345 * Free the string with g_free() after usage.
1350 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1352 GstStructure *structure;
1354 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1356 structure = gst_query_get_structure (query);
1358 *uri = g_value_dup_string (gst_structure_id_get_value (structure,