]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gstreamer0-10.git/blob - gst/gstquery.c
query: gst_query_add_buffering_range() optimisations
[glsdk/gstreamer0-10.git] / gst / gstquery.c
1 /* GStreamer
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>
5  *
6  * gstquery.c: GstQueryType registration and Query parsing/creation
7  *
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.
12  *
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.
17  *
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.
22  */
24 /**
25  * SECTION:gstquery
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
29  *
30  * GstQuery functions are used to register a new query types to the gstreamer
31  * core.
32  * Query types can be used to perform queries on pads and elements.
33  *
34  * Queries can be created using the gst_query_new_*() functions.
35  * Query values can be set using gst_query_set_*(), and parsed using
36  * gst_query_parse_*() helpers.
37  *
38  * The following example shows how to query the duration of a pipeline:
39  *
40  * <example>
41  *  <title>Query duration on a pipeline</title>
42  *  <programlisting>
43  *  GstQuery *query;
44  *  gboolean res;
45  *  query = gst_query_new_duration (GST_FORMAT_TIME);
46  *  res = gst_element_query (pipeline, query);
47  *  if (res) {
48  *    gint64 duration;
49  *    gst_query_parse_duration (query, NULL, &amp;duration);
50  *    g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
51  *  }
52  *  else {
53  *    g_print ("duration query failed...");
54  *  }
55  *  gst_query_unref (query);
56  *  </programlisting>
57  * </example>
58  *
59  * Last reviewed on 2006-02-14 (0.10.4)
60  */
62 #include "gst_private.h"
63 #include "gstinfo.h"
64 #include "gstquery.h"
65 #include "gstvalue.h"
66 #include "gstenumtypes.h"
67 #include "gstquark.h"
68 #include "gsturi.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},
97   {0, NULL, NULL, 0}
98 };
100 void
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);
113   }
115   while (standards->nick) {
116     standards->quark = g_quark_from_static_string (standards->nick);
117     g_hash_table_insert (_nick_to_query, (gpointer) 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);
122     standards++;
123     _n_values++;
124   }
125   g_static_mutex_unlock (&mutex);
127   g_type_class_ref (gst_query_get_type ());
130 /**
131  * gst_query_type_get_name:
132  * @query: the query type
133  *
134  * Get a printable name for the given query type. Do not modify or free.
135  *
136  * Returns: a reference to the static name of the query.
137  */
138 const gchar *
139 gst_query_type_get_name (GstQueryType query)
141   const GstQueryTypeDefinition *def;
143   def = gst_query_type_get_details (query);
145   return def->nick;
148 /**
149  * gst_query_type_to_quark:
150  * @query: the query type
151  *
152  * Get the unique quark for the given query type.
153  *
154  * Returns: the quark associated with the query type
155  */
156 GQuark
157 gst_query_type_to_quark (GstQueryType query)
159   const GstQueryTypeDefinition *def;
161   def = gst_query_type_get_details (query);
163   return def->quark;
166 G_DEFINE_TYPE (GstQuery, gst_query, GST_TYPE_MINI_OBJECT);
168 static void
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;
179 static void
180 gst_query_init (GstQuery * query)
184 static void
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);
192   }
194 /*   GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (query)); */
197 static GstQuery *
198 _gst_query_copy (GstQuery * query)
200   GstQuery *copy;
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);
210   }
212   return copy;
217 /**
218  * gst_query_type_register:
219  * @nick: The nick of the new query
220  * @description: The description of the new query
221  *
222  * Create a new GstQueryType based on the nick or return an
223  * already registered query with that nick
224  *
225  * Returns: A new GstQueryType or an already registered query
226  * with the same nick.
227  */
228 GstQueryType
229 gst_query_type_register (const gchar * nick, const gchar * description)
231   GstQueryTypeDefinition *query;
232   GstQueryType lookup;
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)
239     return lookup;
241   query = g_slice_new (GstQueryTypeDefinition);
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, (gpointer) query->nick, query);
249   g_hash_table_insert (_query_type_to_nick, GINT_TO_POINTER (query->value),
250       query);
251   _gst_queries = g_list_append (_gst_queries, query);
252   _n_values++;
253   g_static_mutex_unlock (&mutex);
255   return query->value;
258 /**
259  * gst_query_type_get_by_nick:
260  * @nick: The nick of the query
261  *
262  * Get the query type registered with @nick.
263  *
264  * Returns: The query registered with @nick or #GST_QUERY_NONE
265  * if the query was not registered.
266  */
267 GstQueryType
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);
278   if (query != NULL)
279     return query->value;
280   else
281     return GST_QUERY_NONE;
284 /**
285  * gst_query_types_contains:
286  * @types: The query array to search
287  * @type: the #GstQueryType to find
288  *
289  * See if the given #GstQueryType is inside the @types query types array.
290  *
291  * Returns: TRUE if the type is found inside the array
292  */
293 gboolean
294 gst_query_types_contains (const GstQueryType * types, GstQueryType type)
296   if (!types)
297     return FALSE;
299   while (*types) {
300     if (*types == type)
301       return TRUE;
303     types++;
304   }
305   return FALSE;
309 /**
310  * gst_query_type_get_details:
311  * @type: a #GstQueryType
312  *
313  * Get details about the given #GstQueryType.
314  *
315  * Returns: The #GstQueryTypeDefinition for @type or NULL on failure.
316  */
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);
326   return result;
329 /**
330  * gst_query_type_iterate_definitions:
331  *
332  * Get a #GstIterator of all the registered query types. The definitions
333  * iterated over are read only.
334  *
335  * Returns: A #GstIterator of #GstQueryTypeDefinition.
336  */
337 GstIterator *
338 gst_query_type_iterate_definitions (void)
340   GstIterator *result;
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,
346       NULL, NULL, NULL);
347   g_static_mutex_unlock (&mutex);
349   return result;
352 static GstQuery *
353 gst_query_new (GstQueryType type, GstStructure * structure)
355   GstQuery *query;
357   query = (GstQuery *) gst_mini_object_new (GST_TYPE_QUERY);
359   GST_DEBUG ("creating new query %p %d", query, type);
361   query->type = type;
363   if (structure) {
364     query->structure = structure;
365     gst_structure_set_parent_refcount (query->structure,
366         &query->mini_object.refcount);
367   } else {
368     query->structure = NULL;
369   }
371   return query;
374 /**
375  * gst_query_new_position:
376  * @format: the default #GstFormat for the new query
377  *
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.
381  *
382  * Returns: A #GstQuery
383  */
384 GstQuery *
385 gst_query_new_position (GstFormat format)
387   GstQuery *query;
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);
396   return query;
399 /**
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
404  *
405  * Answer a position query by setting the requested value in the given format.
406  */
407 void
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);
420 /**
421  * gst_query_parse_position:
422  * @query: a #GstQuery
423  * @format: (out): the storage for the #GstFormat of the position values (may be NULL)
424  * @cur: (out): the storage for the current position (may be NULL)
425  *
426  * Parse a position query, writing the format into @format, and the position
427  * into @cur, if the respective parameters are non-NULL.
428  */
429 void
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);
437   if (format)
438     *format = g_value_get_enum (gst_structure_id_get_value (structure,
439             GST_QUARK (FORMAT)));
440   if (cur)
441     *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
442             GST_QUARK (CURRENT)));
446 /**
447  * gst_query_new_duration:
448  * @format: the #GstFormat for this duration query
449  *
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.
453  *
454  * Returns: A #GstQuery
455  */
456 GstQuery *
457 gst_query_new_duration (GstFormat format)
459   GstQuery *query;
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);
468   return query;
471 /**
472  * gst_query_set_duration:
473  * @query: a #GstQuery
474  * @format: the #GstFormat for the duration
475  * @duration: the duration of the stream
476  *
477  * Answer a duration query by setting the requested value in the given format.
478  */
479 void
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);
492 /**
493  * gst_query_parse_duration:
494  * @query: a #GstQuery
495  * @format: (out): the storage for the #GstFormat of the duration value, or NULL.
496  * @duration: (out): the storage for the total duration, or NULL.
497  *
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.
500  */
501 void
502 gst_query_parse_duration (GstQuery * query, GstFormat * format,
503     gint64 * duration)
505   GstStructure *structure;
507   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
509   structure = gst_query_get_structure (query);
510   if (format)
511     *format = g_value_get_enum (gst_structure_id_get_value (structure,
512             GST_QUARK (FORMAT)));
513   if (duration)
514     *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
515             GST_QUARK (DURATION)));
518 /**
519  * gst_query_new_latency:
520  *
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
524  * pipeline.
525  *
526  * Returns: A #GstQuery
527  *
528  * Since: 0.10.12
529  */
530 GstQuery *
531 gst_query_new_latency (void)
533   GstQuery *query;
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);
543   return query;
546 /**
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
552  *
553  * Answer a latency query by setting the requested values in the given format.
554  *
555  * Since: 0.10.12
556  */
557 void
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);
572 /**
573  * gst_query_parse_latency:
574  * @query: a #GstQuery
575  * @live: (out): storage for live or NULL
576  * @min_latency: (out): the storage for the min latency or NULL
577  * @max_latency: (out): the storage for the max latency or NULL
578  *
579  * Parse a latency query answer.
580  *
581  * Since: 0.10.12
582  */
583 void
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);
592   if (live)
593     *live =
594         g_value_get_boolean (gst_structure_id_get_value (structure,
595             GST_QUARK (LIVE)));
596   if (min_latency)
597     *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
598             GST_QUARK (MIN_LATENCY)));
599   if (max_latency)
600     *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
601             GST_QUARK (MAX_LATENCY)));
604 /**
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
609  *
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.
613  *
614  * Returns: A #GstQuery
615  */
616 GstQuery *
617 gst_query_new_convert (GstFormat src_format, gint64 value,
618     GstFormat dest_format)
620   GstQuery *query;
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);
631   return query;
634 /**
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
641  *
642  * Answer a convert query by setting the requested values.
643  */
644 void
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);
660 /**
661  * gst_query_parse_convert:
662  * @query: a #GstQuery
663  * @src_format: (out): the storage for the #GstFormat of the source value, or NULL
664  * @src_value: (out): the storage for the source value, or NULL
665  * @dest_format: (out): the storage for the #GstFormat of the destination value, or NULL
666  * @dest_value: (out): the storage for the destination value, or NULL
667  *
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.
670  */
671 void
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);
680   if (src_format)
681     *src_format = g_value_get_enum (gst_structure_id_get_value (structure,
682             GST_QUARK (SRC_FORMAT)));
683   if (src_value)
684     *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
685             GST_QUARK (SRC_VALUE)));
686   if (dest_format)
687     *dest_format = g_value_get_enum (gst_structure_id_get_value (structure,
688             GST_QUARK (DEST_FORMAT)));
689   if (dest_value)
690     *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
691             GST_QUARK (DEST_VALUE)));
694 /**
695  * gst_query_new_segment:
696  * @format: the #GstFormat for the new query
697  *
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.
701  *
702  * Returns: a #GstQuery
703  */
704 GstQuery *
705 gst_query_new_segment (GstFormat format)
707   GstQuery *query;
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);
718   return query;
721 /**
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
728  *
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.
733  *
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
739  * @start_value.
740  */
741 void
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);
757 /**
758  * gst_query_parse_segment:
759  * @query: a #GstQuery
760  * @rate: (out): the storage for the rate of the segment, or NULL
761  * @format: (out): the storage for the #GstFormat of the values, or NULL
762  * @start_value: (out): the storage for the start value, or NULL
763  * @stop_value: (out): the storage for the stop value, or NULL
764  *
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.
767  *
768  * See gst_query_set_segment() for an explanation of the function arguments.
769  */
770 void
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);
779   if (rate)
780     *rate = g_value_get_double (gst_structure_id_get_value (structure,
781             GST_QUARK (RATE)));
782   if (format)
783     *format = g_value_get_enum (gst_structure_id_get_value (structure,
784             GST_QUARK (FORMAT)));
785   if (start_value)
786     *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
787             GST_QUARK (START_VALUE)));
788   if (stop_value)
789     *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
790             GST_QUARK (STOP_VALUE)));
793 /**
794  * gst_query_new_application:
795  * @type: the query type
796  * @structure: a structure for the query
797  *
798  * Constructs a new custom application query object. Use gst_query_unref()
799  * when done with it.
800  *
801  * Returns: a #GstQuery
802  */
803 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);
812 /**
813  * gst_query_get_structure:
814  * @query: a #GstQuery
815  *
816  * Get the structure of a query.
817  *
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.
820  */
821 GstStructure *
822 gst_query_get_structure (GstQuery * query)
824   g_return_val_if_fail (GST_IS_QUERY (query), NULL);
826   return query->structure;
829 /**
830  * gst_query_new_seeking:
831  * @format: the default #GstFormat for the new query
832  *
833  * Constructs a new query object for querying seeking properties of
834  * the stream.
835  *
836  * Returns: A #GstQuery
837  */
838 GstQuery *
839 gst_query_new_seeking (GstFormat format)
841   GstQuery *query;
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);
852   return query;
855 /**
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
862  *
863  * Set the seeking query result fields in @query.
864  */
865 void
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);
881 /**
882  * gst_query_parse_seeking:
883  * @query: a GST_QUERY_SEEKING type query #GstQuery
884  * @format: (out): the format to set for the @segment_start and @segment_end values
885  * @seekable: (out): the seekable flag to set
886  * @segment_start: (out): the segment_start to set
887  * @segment_end: (out): the segment_end to set
888  *
889  * Parse a seeking query, writing the format into @format, and
890  * other results into the passed parameters, if the respective parameters
891  * are non-NULL
892  */
893 void
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);
902   if (format)
903     *format = g_value_get_enum (gst_structure_id_get_value (structure,
904             GST_QUARK (FORMAT)));
905   if (seekable)
906     *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
907             GST_QUARK (SEEKABLE)));
908   if (segment_start)
909     *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
910             GST_QUARK (SEGMENT_START)));
911   if (segment_end)
912     *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
913             GST_QUARK (SEGMENT_END)));
916 /**
917  * gst_query_new_formats:
918  *
919  * Constructs a new query object for querying formats of
920  * the stream.
921  *
922  * Returns: A #GstQuery
923  *
924  * Since: 0.10.4
925  */
926 GstQuery *
927 gst_query_new_formats (void)
929   GstQuery *query;
930   GstStructure *structure;
932   structure = gst_structure_id_empty_new (GST_QUARK (QUERY_FORMATS));
933   query = gst_query_new (GST_QUERY_FORMATS, structure);
935   return query;
938 static void
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);
949 /**
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.
954  *
955  * Set the formats query result fields in @query. The number of formats passed
956  * must be equal to @n_formats.
957  */
958 void
959 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
961   va_list ap;
962   GValue list = { 0, };
963   GstStructure *structure;
964   gint i;
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));
973   }
974   va_end (ap);
976   structure = gst_query_get_structure (query);
977   gst_structure_set_value (structure, "formats", &list);
979   g_value_unset (&list);
983 /**
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.
988  *
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.
991  *
992  * Since: 0.10.4
993  */
994 void
995 gst_query_set_formatsv (GstQuery * query, gint n_formats, GstFormat * formats)
997   GValue list = { 0, };
998   GstStructure *structure;
999   gint i;
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]);
1006   }
1007   structure = gst_query_get_structure (query);
1008   gst_structure_set_value (structure, "formats", &list);
1010   g_value_unset (&list);
1013 /**
1014  * gst_query_parse_formats_length:
1015  * @query: a #GstQuery
1016  * @n_formats: (out): the number of formats in this query.
1017  *
1018  * Parse the number of formats in the formats @query.
1019  *
1020  * Since: 0.10.4
1021  */
1022 void
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);
1029   if (n_formats) {
1030     const GValue *list;
1032     structure = gst_query_get_structure (query);
1033     list = gst_structure_get_value (structure, "formats");
1034     if (list == NULL)
1035       *n_formats = 0;
1036     else
1037       *n_formats = gst_value_list_get_size (list);
1038   }
1041 /**
1042  * gst_query_parse_formats_nth:
1043  * @query: a #GstQuery
1044  * @nth: (out): the nth format to retrieve.
1045  * @format: (out): a pointer to store the nth format
1046  *
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.
1050  *
1051  * Since: 0.10.4
1052  */
1053 void
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);
1060   if (format) {
1061     const GValue *list;
1063     structure = gst_query_get_structure (query);
1064     list = gst_structure_get_value (structure, "formats");
1065     if (list == NULL) {
1066       *format = GST_FORMAT_UNDEFINED;
1067     } else {
1068       if (nth < gst_value_list_get_size (list)) {
1069         *format = g_value_get_enum (gst_value_list_get_value (list, nth));
1070       } else
1071         *format = GST_FORMAT_UNDEFINED;
1072     }
1073   }
1076 /**
1077  * gst_query_new_buffering
1078  * @format: the default #GstFormat for the new query
1079  *
1080  * Constructs a new query object for querying the buffering status of
1081  * a stream.
1082  *
1083  * Returns: A #GstQuery
1084  *
1085  * Since: 0.10.20
1086  */
1087 GstQuery *
1088 gst_query_new_buffering (GstFormat format)
1090   GstQuery *query;
1091   GstStructure *structure;
1093   /* by default, we configure the answer as no buffering with a 100% buffering
1094    * progress */
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);
1109   return query;
1112 /**
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
1117  *
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.
1120  *
1121  * Since: 0.10.20
1122  */
1123 void
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);
1134 /**
1135  * gst_query_parse_buffering_percent
1136  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1137  * @busy: (out): if buffering is busy
1138  * @percent: (out): a buffering percent
1139  *
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.
1142  *
1143  * Since: 0.10.20
1144  */
1145 void
1146 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1147     gint * percent)
1149   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1151   if (busy)
1152     *busy = g_value_get_boolean (gst_structure_id_get_value (query->structure,
1153             GST_QUARK (BUSY)));
1154   if (percent)
1155     *percent = g_value_get_int (gst_structure_id_get_value (query->structure,
1156             GST_QUARK (BUFFER_PERCENT)));
1159 /**
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
1166  *
1167  * Configures the buffering stats values in @query.
1168  *
1169  * Since: 0.10.20
1170  */
1171 void
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);
1184 /**
1185  * gst_query_parse_buffering_stats:
1186  * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1187  * @mode: (out): a buffering mode
1188  * @avg_in: (out): the average input rate
1189  * @avg_out: (out): the average output rate
1190  * @buffering_left: (out): amount of buffering time left
1191  *
1192  * Extracts the buffering stats values from @query.
1193  *
1194  * Since: 0.10.20
1195  */
1196 void
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);
1203   if (mode)
1204     *mode = g_value_get_enum (gst_structure_id_get_value (query->structure,
1205             GST_QUARK (BUFFERING_MODE)));
1206   if (avg_in)
1207     *avg_in = g_value_get_int (gst_structure_id_get_value (query->structure,
1208             GST_QUARK (AVG_IN_RATE)));
1209   if (avg_out)
1210     *avg_out = g_value_get_int (gst_structure_id_get_value (query->structure,
1211             GST_QUARK (AVG_OUT_RATE)));
1212   if (buffering_left)
1213     *buffering_left =
1214         g_value_get_int64 (gst_structure_id_get_value (query->structure,
1215             GST_QUARK (BUFFERING_LEFT)));
1219 /**
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
1226  *
1227  * Set the available query result fields in @query.
1228  *
1229  * Since: 0.10.20
1230  */
1231 void
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);
1247 /**
1248  * gst_query_parse_buffering_range:
1249  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1250  * @format: (out): the format to set for the @segment_start and @segment_end values
1251  * @start: (out): the start to set
1252  * @stop: (out): the stop to set
1253  * @estimated_total: (out): estimated total amount of download time
1254  *
1255  * Parse an available query, writing the format into @format, and
1256  * other results into the passed parameters, if the respective parameters
1257  * are non-NULL
1258  *
1259  * Since: 0.10.20
1260  */
1261 void
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);
1270   if (format)
1271     *format = g_value_get_enum (gst_structure_id_get_value (structure,
1272             GST_QUARK (FORMAT)));
1273   if (start)
1274     *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1275             GST_QUARK (START_VALUE)));
1276   if (stop)
1277     *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1278             GST_QUARK (STOP_VALUE)));
1279   if (estimated_total)
1280     *estimated_total =
1281         g_value_get_int64 (gst_structure_id_get_value (structure,
1282             GST_QUARK (ESTIMATED_TOTAL)));
1285 /**
1286  * gst_query_add_buffering_range
1287  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1288  * @start: start position of the range
1289  * @stop: stop position of the range
1290  *
1291  * Set the buffering-ranges array field in @query. The current last
1292  * start position of the array should be inferior to @start.
1293  *
1294  * Returns: a #gboolean indicating if the range was added or not.
1295  *
1296  * Since: 0.10.31
1297  */
1298 gboolean
1299 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1301   GstStructure *structure;
1302   GValueArray *array;
1303   GValue *last_array_value;
1304   const GValue *value;
1305   GValue range_value = { 0 };
1306   gboolean ret = FALSE;
1308   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1310   if (start >= stop)
1311     return ret;
1313   g_value_init (&range_value, GST_TYPE_INT64_RANGE);
1314   gst_value_set_int64_range (&range_value, start, stop);
1316   structure = gst_query_get_structure (query);
1317   value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1318   if (value) {
1319     array = (GValueArray *) g_value_get_boxed (value);
1320     last_array_value = g_value_array_get_nth (array, array->n_values - 1);
1321     if (start > gst_value_get_int64_range_min (last_array_value))
1322       ret = TRUE;
1323   } else {
1324     GValue new_array_val = { 0, };
1326     array = g_value_array_new (0);
1328     g_value_init (&new_array_val, G_TYPE_VALUE_ARRAY);
1329     g_value_take_boxed (&new_array_val, array);
1331     /* set the value array only once, so we then modify (append to) the
1332      * existing value array owned by the GstStructure / the field's GValue */
1333     gst_structure_id_take_value (structure, GST_QUARK (BUFFERING_RANGES),
1334         &new_array_val);
1336     ret = TRUE;
1337   }
1339   if (ret) {
1340     g_value_array_append (array, &range_value);
1341   }
1343   g_value_unset (&range_value);
1345   return ret;
1348 /**
1349  * gst_query_get_n_buffering_ranges
1350  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1351  *
1352  * Retrieve the number of values currently stored in the
1353  * buffered-ranges array of the query's structure.
1354  *
1355  * Returns: the range array size as a #guint.
1356  *
1357  * Since: 0.10.31
1358  */
1359 guint
1360 gst_query_get_n_buffering_ranges (GstQuery * query)
1362   GstStructure *structure;
1363   GValueArray *array;
1364   const GValue *value;
1365   guint size = 0;
1367   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1369   structure = gst_query_get_structure (query);
1370   value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1371   if (value) {
1372     array = (GValueArray *) g_value_get_boxed (value);
1373     size = array->n_values;
1374   }
1375   return size;
1379 /**
1380  * gst_query_parse_nth_buffering_range
1381  * @query: a GST_QUERY_BUFFERING type query #GstQuery
1382  * @index: position in the buffered-ranges array to read
1383  * @start: (out): the start position to set
1384  * @stop: (out): the stop position to set
1385  *
1386  * Parse an available query and get the start and stop values stored
1387  * at the @index of the buffered ranges array.
1388  *
1389  * Returns: a #gboolean indicating if the parsing succeeded.
1390  *
1391  * Since: 0.10.31
1392  */
1393 gboolean
1394 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1395     gint64 * start, gint64 * stop)
1397   GstStructure *structure;
1398   const GValue *value;
1399   GValueArray *ranges;
1400   GValue *range_value;
1401   gboolean ret = FALSE;
1403   g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, ret);
1405   structure = gst_query_get_structure (query);
1406   value = gst_structure_id_get_value (structure, GST_QUARK (BUFFERING_RANGES));
1407   ranges = (GValueArray *) g_value_get_boxed (value);
1408   range_value = g_value_array_get_nth (ranges, index);
1409   if (range_value) {
1410     if (start)
1411       *start = gst_value_get_int64_range_min (range_value);
1412     if (stop)
1413       *stop = gst_value_get_int64_range_max (range_value);
1414     ret = TRUE;
1415   }
1417   return ret;
1421 /**
1422  * gst_query_new_uri:
1423  *
1424  * Constructs a new query URI query object. Use gst_query_unref()
1425  * when done with it. An URI query is used to query the current URI
1426  * that is used by the source or sink.
1427  *
1428  * Returns: A #GstQuery
1429  *
1430  * Since: 0.10.22
1431  */
1432 GstQuery *
1433 gst_query_new_uri (void)
1435   GstQuery *query;
1436   GstStructure *structure;
1438   structure = gst_structure_id_new (GST_QUARK (QUERY_URI),
1439       GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1441   query = gst_query_new (GST_QUERY_URI, structure);
1443   return query;
1446 /**
1447  * gst_query_set_uri:
1448  * @query: a #GstQuery with query type GST_QUERY_URI
1449  * @uri: the URI to set
1450  *
1451  * Answer a URI query by setting the requested URI.
1452  *
1453  * Since: 0.10.22
1454  */
1455 void
1456 gst_query_set_uri (GstQuery * query, const gchar * uri)
1458   GstStructure *structure;
1460   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1461   g_return_if_fail (gst_uri_is_valid (uri));
1463   structure = gst_query_get_structure (query);
1464   gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1467 /**
1468  * gst_query_parse_uri:
1469  * @query: a #GstQuery
1470  * @uri: (out): the storage for the current URI (may be NULL)
1471  *
1472  * Parse an URI query, writing the URI into @uri as a newly
1473  * allocated string, if the respective parameters are non-NULL.
1474  * Free the string with g_free() after usage.
1475  *
1476  * Since: 0.10.22
1477  */
1478 void
1479 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1481   GstStructure *structure;
1483   g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1485   structure = gst_query_get_structure (query);
1486   if (uri)
1487     *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1488             GST_QUARK (URI)));