2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
4 * 2005 Wim Taymans <wim@fluendo.com>
6 * gstquery.c: GstQueryType registration and Query parsing/creation
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * @short_description: Dynamically register new query types. Provide functions
27 * to create queries, and to set and parse values in them.
28 * @see_also: #GstPad, #GstElement
30 * GstQuery functions are used to register new query types to the gstreamer
32 * Queries can be performed on pads (gst_pad_query()) and elements
33 * (gst_element_query()). Please note that some queries might need a running
36 * Queries can be created using the gst_query_new_*() functions.
37 * Query values can be set using gst_query_set_*(), and parsed using
38 * gst_query_parse_*() helpers.
40 * The following example shows how to query the duration of a pipeline:
43 * <title>Query duration on a pipeline</title>
47 * query = gst_query_new_duration (GST_FORMAT_TIME);
48 * res = gst_element_query (pipeline, query);
51 * gst_query_parse_duration (query, NULL, &duration);
52 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
55 * g_print ("duration query failed...");
57 * gst_query_unref (query);
61 * Last reviewed on 2006-02-14 (0.10.4)
65 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
66 * with newer GLib versions (>= 2.31.0) */
67 #define GLIB_DISABLE_DEPRECATION_WARNINGS
69 #include "gst_private.h"
73 #include "gstenumtypes.h"
76 #include "gstbufferpool.h"
78 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
79 #define GST_CAT_DEFAULT gst_query_debug
81 static GType _gst_query_type = 0;
87 GstStructure *structure;
90 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
100 static GstQueryQuarks query_quarks[] = {
101 {GST_QUERY_UNKNOWN, "unknown", 0},
102 {GST_QUERY_POSITION, "position", 0},
103 {GST_QUERY_DURATION, "duration", 0},
104 {GST_QUERY_LATENCY, "latency", 0},
105 {GST_QUERY_JITTER, "jitter", 0},
106 {GST_QUERY_RATE, "rate", 0},
107 {GST_QUERY_SEEKING, "seeking", 0},
108 {GST_QUERY_SEGMENT, "segment", 0},
109 {GST_QUERY_CONVERT, "convert", 0},
110 {GST_QUERY_FORMATS, "formats", 0},
111 {GST_QUERY_BUFFERING, "buffering", 0},
112 {GST_QUERY_CUSTOM, "custom", 0},
113 {GST_QUERY_URI, "uri", 0},
114 {GST_QUERY_ALLOCATION, "allocation", 0},
115 {GST_QUERY_SCHEDULING, "scheduling", 0},
116 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
117 {GST_QUERY_CAPS, "caps", 0},
118 {GST_QUERY_DRAIN, "drain", 0},
123 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
126 _priv_gst_query_initialize (void)
130 _gst_query_type = gst_query_get_type ();
132 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
134 for (i = 0; query_quarks[i].name; i++) {
135 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
140 * gst_query_type_get_name:
141 * @type: the query type
143 * Get a printable name for the given query type. Do not modify or free.
145 * Returns: a reference to the static name of the query.
148 gst_query_type_get_name (GstQueryType type)
152 for (i = 0; query_quarks[i].name; i++) {
153 if (type == query_quarks[i].type)
154 return query_quarks[i].name;
160 * gst_query_type_to_quark:
161 * @type: the query type
163 * Get the unique quark for the given query type.
165 * Returns: the quark associated with the query type
168 gst_query_type_to_quark (GstQueryType type)
172 for (i = 0; query_quarks[i].name; i++) {
173 if (type == query_quarks[i].type)
174 return query_quarks[i].quark;
180 * gst_query_type_get_flags:
181 * @type: a #GstQueryType
183 * Gets the #GstQueryTypeFlags associated with @type.
185 * Returns: a #GstQueryTypeFlags.
188 gst_query_type_get_flags (GstQueryType type)
190 GstQueryTypeFlags ret;
192 ret = type & ((1 << GST_EVENT_NUM_SHIFT) - 1);
198 _gst_query_free (GstQuery * query)
202 g_return_if_fail (query != NULL);
204 s = GST_QUERY_STRUCTURE (query);
206 gst_structure_set_parent_refcount (s, NULL);
207 gst_structure_free (s);
210 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
214 _gst_query_copy (GstQuery * query)
219 s = GST_QUERY_STRUCTURE (query);
221 s = gst_structure_copy (s);
223 copy = gst_query_new_custom (query->type, s);
229 gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
231 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
233 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
234 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
236 GST_EVENT_TYPE (query) = type;
240 * gst_query_new_position:
241 * @format: the default #GstFormat for the new query
243 * Constructs a new query stream position query object. Use gst_query_unref()
244 * when done with it. A position query is used to query the current position
245 * of playback in the streams, in some format.
247 * Free-function: gst_query_unref
249 * Returns: (transfer full): a new #GstQuery
252 gst_query_new_position (GstFormat format)
255 GstStructure *structure;
257 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
258 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
259 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
261 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
267 * gst_query_set_position:
268 * @query: a #GstQuery with query type GST_QUERY_POSITION
269 * @format: the requested #GstFormat
270 * @cur: the position to set
272 * Answer a position query by setting the requested value in the given format.
275 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
279 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
281 s = GST_QUERY_STRUCTURE (query);
282 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
283 GST_QUARK (FORMAT))));
285 gst_structure_id_set (s,
286 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
287 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
291 * gst_query_parse_position:
292 * @query: a #GstQuery
293 * @format: (out) (allow-none): the storage for the #GstFormat of the
294 * position values (may be NULL)
295 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
297 * Parse a position query, writing the format into @format, and the position
298 * into @cur, if the respective parameters are non-NULL.
301 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
303 GstStructure *structure;
305 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
307 structure = GST_QUERY_STRUCTURE (query);
310 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
311 GST_QUARK (FORMAT)));
313 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
314 GST_QUARK (CURRENT)));
319 * gst_query_new_duration:
320 * @format: the #GstFormat for this duration query
322 * Constructs a new stream duration query object to query in the given format.
323 * Use gst_query_unref() when done with it. A duration query will give the
324 * total length of the stream.
326 * Free-function: gst_query_unref
328 * Returns: (transfer full): a new #GstQuery
331 gst_query_new_duration (GstFormat format)
334 GstStructure *structure;
336 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
337 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
338 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
340 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
346 * gst_query_set_duration:
347 * @query: a #GstQuery
348 * @format: the #GstFormat for the duration
349 * @duration: the duration of the stream
351 * Answer a duration query by setting the requested value in the given format.
354 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
358 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
360 s = GST_QUERY_STRUCTURE (query);
361 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
362 GST_QUARK (FORMAT))));
363 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
364 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
368 * gst_query_parse_duration:
369 * @query: a #GstQuery
370 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
372 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
374 * Parse a duration query answer. Write the format of the duration into @format,
375 * and the value into @duration, if the respective variables are non-NULL.
378 gst_query_parse_duration (GstQuery * query, GstFormat * format,
381 GstStructure *structure;
383 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
385 structure = GST_QUERY_STRUCTURE (query);
388 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
389 GST_QUARK (FORMAT)));
391 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
392 GST_QUARK (DURATION)));
396 * gst_query_new_latency:
398 * Constructs a new latency query object.
399 * Use gst_query_unref() when done with it. A latency query is usually performed
400 * by sinks to compensate for additional latency introduced by elements in the
403 * Free-function: gst_query_unref
405 * Returns: (transfer full): a #GstQuery
410 gst_query_new_latency (void)
413 GstStructure *structure;
415 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
416 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
417 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
418 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
420 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
426 * gst_query_set_latency:
427 * @query: a #GstQuery
428 * @live: if there is a live element upstream
429 * @min_latency: the minimal latency of the upstream elements
430 * @max_latency: the maximal latency of the upstream elements
432 * Answer a latency query by setting the requested values in the given format.
437 gst_query_set_latency (GstQuery * query, gboolean live,
438 GstClockTime min_latency, GstClockTime max_latency)
440 GstStructure *structure;
442 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
444 structure = GST_QUERY_STRUCTURE (query);
445 gst_structure_id_set (structure,
446 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
447 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
448 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
452 * gst_query_parse_latency:
453 * @query: a #GstQuery
454 * @live: (out) (allow-none): storage for live or NULL
455 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
456 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
458 * Parse a latency query answer.
463 gst_query_parse_latency (GstQuery * query, gboolean * live,
464 GstClockTime * min_latency, GstClockTime * max_latency)
466 GstStructure *structure;
468 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
470 structure = GST_QUERY_STRUCTURE (query);
473 g_value_get_boolean (gst_structure_id_get_value (structure,
476 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
477 GST_QUARK (MIN_LATENCY)));
479 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
480 GST_QUARK (MAX_LATENCY)));
484 * gst_query_new_convert:
485 * @src_format: the source #GstFormat for the new query
486 * @value: the value to convert
487 * @dest_format: the target #GstFormat
489 * Constructs a new convert query object. Use gst_query_unref()
490 * when done with it. A convert query is used to ask for a conversion between
491 * one format and another.
493 * Free-function: gst_query_unref
495 * Returns: (transfer full): a #GstQuery
498 gst_query_new_convert (GstFormat src_format, gint64 value,
499 GstFormat dest_format)
502 GstStructure *structure;
504 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
505 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
506 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
507 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
508 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
510 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
516 * gst_query_set_convert:
517 * @query: a #GstQuery
518 * @src_format: the source #GstFormat
519 * @src_value: the source value
520 * @dest_format: the destination #GstFormat
521 * @dest_value: the destination value
523 * Answer a convert query by setting the requested values.
526 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
527 GstFormat dest_format, gint64 dest_value)
529 GstStructure *structure;
531 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
533 structure = GST_QUERY_STRUCTURE (query);
534 gst_structure_id_set (structure,
535 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
536 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
537 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
538 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
542 * gst_query_parse_convert:
543 * @query: a #GstQuery
544 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
545 * source value, or NULL
546 * @src_value: (out) (allow-none): the storage for the source value, or NULL
547 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
548 * destination value, or NULL
549 * @dest_value: (out) (allow-none): the storage for the destination value,
552 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
553 * and @dest_value may be NULL, in which case that value is omitted.
556 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
557 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
559 GstStructure *structure;
561 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
563 structure = GST_QUERY_STRUCTURE (query);
566 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
567 GST_QUARK (SRC_FORMAT)));
569 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
570 GST_QUARK (SRC_VALUE)));
573 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
574 GST_QUARK (DEST_FORMAT)));
576 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
577 GST_QUARK (DEST_VALUE)));
581 * gst_query_new_segment:
582 * @format: the #GstFormat for the new query
584 * Constructs a new segment query object. Use gst_query_unref()
585 * when done with it. A segment query is used to discover information about the
586 * currently configured segment for playback.
588 * Free-function: gst_query_unref
590 * Returns: (transfer full): a new #GstQuery
593 gst_query_new_segment (GstFormat format)
596 GstStructure *structure;
598 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
599 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
600 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
601 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
602 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
604 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
610 * gst_query_set_segment:
611 * @query: a #GstQuery
612 * @rate: the rate of the segment
613 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
614 * @start_value: the start value
615 * @stop_value: the stop value
617 * Answer a segment query by setting the requested values. The normal
618 * playback segment of a pipeline is 0 to duration at the default rate of
619 * 1.0. If a seek was performed on the pipeline to play a different
620 * segment, this query will return the range specified in the last seek.
622 * @start_value and @stop_value will respectively contain the configured
623 * playback range start and stop values expressed in @format.
624 * The values are always between 0 and the duration of the media and
625 * @start_value <= @stop_value. @rate will contain the playback rate. For
626 * negative rates, playback will actually happen from @stop_value to
630 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
631 gint64 start_value, gint64 stop_value)
633 GstStructure *structure;
635 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
637 structure = GST_QUERY_STRUCTURE (query);
638 gst_structure_id_set (structure,
639 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
640 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
641 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
642 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
646 * gst_query_parse_segment:
647 * @query: a #GstQuery
648 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
649 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
651 * @start_value: (out) (allow-none): the storage for the start value, or NULL
652 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
654 * Parse a segment query answer. Any of @rate, @format, @start_value, and
655 * @stop_value may be NULL, which will cause this value to be omitted.
657 * See gst_query_set_segment() for an explanation of the function arguments.
660 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
661 gint64 * start_value, gint64 * stop_value)
663 GstStructure *structure;
665 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
667 structure = GST_QUERY_STRUCTURE (query);
669 *rate = g_value_get_double (gst_structure_id_get_value (structure,
673 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
674 GST_QUARK (FORMAT)));
676 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
677 GST_QUARK (START_VALUE)));
679 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
680 GST_QUARK (STOP_VALUE)));
684 * gst_query_new_custom:
685 * @type: the query type
686 * @structure: a structure for the query
688 * Constructs a new custom query object. Use gst_query_unref()
691 * Free-function: gst_query_unref
693 * Returns: (transfer full): a new #GstQuery
696 gst_query_new_custom (GstQueryType type, GstStructure * structure)
700 query = g_slice_new0 (GstQueryImpl);
702 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
705 /* structure must not have a parent */
706 if (!gst_structure_set_parent_refcount (structure,
707 &query->query.mini_object.refcount))
710 gst_query_init (query, sizeof (GstQueryImpl), type);
712 GST_QUERY_STRUCTURE (query) = structure;
714 return GST_QUERY_CAST (query);
719 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
720 g_warning ("structure is already owned by another object");
726 * gst_query_get_structure:
727 * @query: a #GstQuery
729 * Get the structure of a query.
731 * Returns: (transfer none): the #GstStructure of the query. The structure is
732 * still owned by the query and will therefore be freed when the query
736 gst_query_get_structure (GstQuery * query)
738 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
740 return GST_QUERY_STRUCTURE (query);
744 * gst_query_writable_structure:
745 * @query: a #GstQuery
747 * Get the structure of a query. This method should be called with a writable
748 * @query so that the returned structure is guranteed to be writable.
750 * Returns: (transfer none): the #GstStructure of the query. The structure is
751 * still owned by the query and will therefore be freed when the query
755 gst_query_writable_structure (GstQuery * query)
757 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
758 g_return_val_if_fail (gst_query_is_writable (query), NULL);
760 return GST_QUERY_STRUCTURE (query);
764 * gst_query_new_seeking:
765 * @format: the default #GstFormat for the new query
767 * Constructs a new query object for querying seeking properties of
770 * Free-function: gst_query_unref
772 * Returns: (transfer full): a new #GstQuery
775 gst_query_new_seeking (GstFormat format)
778 GstStructure *structure;
780 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
781 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
782 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
783 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
784 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
786 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
792 * gst_query_set_seeking:
793 * @query: a #GstQuery
794 * @format: the format to set for the @segment_start and @segment_end values
795 * @seekable: the seekable flag to set
796 * @segment_start: the segment_start to set
797 * @segment_end: the segment_end to set
799 * Set the seeking query result fields in @query.
802 gst_query_set_seeking (GstQuery * query, GstFormat format,
803 gboolean seekable, gint64 segment_start, gint64 segment_end)
805 GstStructure *structure;
807 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
808 g_return_if_fail (gst_query_is_writable (query));
810 structure = GST_QUERY_STRUCTURE (query);
811 gst_structure_id_set (structure,
812 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
813 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
814 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
815 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
819 * gst_query_parse_seeking:
820 * @query: a GST_QUERY_SEEKING type query #GstQuery
821 * @format: (out) (allow-none): the format to set for the @segment_start
822 * and @segment_end values, or NULL
823 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
824 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
825 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
827 * Parse a seeking query, writing the format into @format, and
828 * other results into the passed parameters, if the respective parameters
832 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
833 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
835 GstStructure *structure;
837 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
839 structure = GST_QUERY_STRUCTURE (query);
842 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
843 GST_QUARK (FORMAT)));
845 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
846 GST_QUARK (SEEKABLE)));
848 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
849 GST_QUARK (SEGMENT_START)));
851 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
852 GST_QUARK (SEGMENT_END)));
856 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
857 GDestroyNotify clear_func)
862 value = gst_structure_id_get_value (s, quark);
864 array = (GArray *) g_value_get_boxed (value);
866 GValue new_array_val = { 0, };
868 array = g_array_new (FALSE, TRUE, element_size);
870 g_array_set_clear_func (array, clear_func);
872 g_value_init (&new_array_val, G_TYPE_ARRAY);
873 g_value_take_boxed (&new_array_val, array);
875 gst_structure_id_take_value (s, quark, &new_array_val);
881 * gst_query_new_formats:
883 * Constructs a new query object for querying formats of
886 * Free-function: gst_query_unref
888 * Returns: (transfer full): a new #GstQuery
893 gst_query_new_formats (void)
896 GstStructure *structure;
898 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
899 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
905 gst_query_list_add_format (GValue * list, GstFormat format)
907 GValue item = { 0, };
909 g_value_init (&item, GST_TYPE_FORMAT);
910 g_value_set_enum (&item, format);
911 gst_value_list_append_value (list, &item);
912 g_value_unset (&item);
916 * gst_query_set_formats:
917 * @query: a #GstQuery
918 * @n_formats: the number of formats to set.
919 * @...: A number of @GstFormats equal to @n_formats.
921 * Set the formats query result fields in @query. The number of formats passed
922 * must be equal to @n_formats.
925 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
928 GValue list = { 0, };
930 GstStructure *structure;
932 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
933 g_return_if_fail (gst_query_is_writable (query));
935 g_value_init (&list, GST_TYPE_LIST);
937 va_start (ap, n_formats);
938 for (i = 0; i < n_formats; i++) {
939 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
943 structure = GST_QUERY_STRUCTURE (query);
944 gst_structure_set_value (structure, "formats", &list);
946 g_value_unset (&list);
951 * gst_query_set_formatsv:
952 * @query: a #GstQuery
953 * @n_formats: the number of formats to set.
954 * @formats: (in) (array length=n_formats): an array containing @n_formats
957 * Set the formats query result fields in @query. The number of formats passed
958 * in the @formats array must be equal to @n_formats.
963 gst_query_set_formatsv (GstQuery * query, gint n_formats,
964 const GstFormat * formats)
966 GValue list = { 0, };
968 GstStructure *structure;
970 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
971 g_return_if_fail (gst_query_is_writable (query));
973 g_value_init (&list, GST_TYPE_LIST);
974 for (i = 0; i < n_formats; i++) {
975 gst_query_list_add_format (&list, formats[i]);
977 structure = GST_QUERY_STRUCTURE (query);
978 gst_structure_set_value (structure, "formats", &list);
980 g_value_unset (&list);
984 * gst_query_parse_n_formats:
985 * @query: a #GstQuery
986 * @n_formats: (out) (allow-none): the number of formats in this query.
988 * Parse the number of formats in the formats @query.
993 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
995 GstStructure *structure;
997 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1002 structure = GST_QUERY_STRUCTURE (query);
1003 list = gst_structure_get_value (structure, "formats");
1007 *n_formats = gst_value_list_get_size (list);
1012 * gst_query_parse_nth_format:
1013 * @query: a #GstQuery
1014 * @nth: (out): the nth format to retrieve.
1015 * @format: (out) (allow-none): a pointer to store the nth format
1017 * Parse the format query and retrieve the @nth format from it into
1018 * @format. If the list contains less elements than @nth, @format will be
1019 * set to GST_FORMAT_UNDEFINED.
1022 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1024 GstStructure *structure;
1026 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1031 structure = GST_QUERY_STRUCTURE (query);
1032 list = gst_structure_get_value (structure, "formats");
1034 *format = GST_FORMAT_UNDEFINED;
1036 if (nth < gst_value_list_get_size (list)) {
1038 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1040 *format = GST_FORMAT_UNDEFINED;
1046 * gst_query_new_buffering:
1047 * @format: the default #GstFormat for the new query
1049 * Constructs a new query object for querying the buffering status of
1052 * Free-function: gst_query_unref
1054 * Returns: (transfer full): a new #GstQuery
1059 gst_query_new_buffering (GstFormat format)
1062 GstStructure *structure;
1064 /* by default, we configure the answer as no buffering with a 100% buffering
1066 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1067 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1068 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1069 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1070 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1071 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1072 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1073 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1074 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1075 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1076 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1078 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1084 * gst_query_set_buffering_percent:
1085 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1086 * @busy: if buffering is busy
1087 * @percent: a buffering percent
1089 * Set the percentage of buffered data. This is a value between 0 and 100.
1090 * The @busy indicator is %TRUE when the buffering is in progress.
1095 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1097 GstStructure *structure;
1099 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1100 g_return_if_fail (gst_query_is_writable (query));
1101 g_return_if_fail (percent >= 0 && percent <= 100);
1103 structure = GST_QUERY_STRUCTURE (query);
1104 gst_structure_id_set (structure,
1105 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1106 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1110 * gst_query_parse_buffering_percent:
1111 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1112 * @busy: (out) (allow-none): if buffering is busy, or NULL
1113 * @percent: (out) (allow-none): a buffering percent, or NULL
1115 * Get the percentage of buffered data. This is a value between 0 and 100.
1116 * The @busy indicator is %TRUE when the buffering is in progress.
1121 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1124 GstStructure *structure;
1126 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1128 structure = GST_QUERY_STRUCTURE (query);
1130 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1133 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1134 GST_QUARK (BUFFER_PERCENT)));
1138 * gst_query_set_buffering_stats:
1139 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1140 * @mode: a buffering mode
1141 * @avg_in: the average input rate
1142 * @avg_out: the average output rate
1143 * @buffering_left: amount of buffering time left
1145 * Configures the buffering stats values in @query.
1150 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1151 gint avg_in, gint avg_out, gint64 buffering_left)
1153 GstStructure *structure;
1155 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1156 g_return_if_fail (gst_query_is_writable (query));
1158 structure = GST_QUERY_STRUCTURE (query);
1159 gst_structure_id_set (structure,
1160 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1161 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1162 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1163 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1167 * gst_query_parse_buffering_stats:
1168 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1169 * @mode: (out) (allow-none): a buffering mode, or NULL
1170 * @avg_in: (out) (allow-none): the average input rate, or NULL
1171 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1172 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1174 * Extracts the buffering stats values from @query.
1179 gst_query_parse_buffering_stats (GstQuery * query,
1180 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1181 gint64 * buffering_left)
1183 GstStructure *structure;
1185 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1187 structure = GST_QUERY_STRUCTURE (query);
1189 *mode = (GstBufferingMode)
1190 g_value_get_enum (gst_structure_id_get_value (structure,
1191 GST_QUARK (BUFFERING_MODE)));
1193 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1194 GST_QUARK (AVG_IN_RATE)));
1196 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1197 GST_QUARK (AVG_OUT_RATE)));
1200 g_value_get_int64 (gst_structure_id_get_value (structure,
1201 GST_QUARK (BUFFERING_LEFT)));
1205 * gst_query_set_buffering_range:
1206 * @query: a #GstQuery
1207 * @format: the format to set for the @start and @stop values
1208 * @start: the start to set
1209 * @stop: the stop to set
1210 * @estimated_total: estimated total amount of download time
1212 * Set the available query result fields in @query.
1217 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1218 gint64 start, gint64 stop, gint64 estimated_total)
1220 GstStructure *structure;
1222 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1223 g_return_if_fail (gst_query_is_writable (query));
1225 structure = GST_QUERY_STRUCTURE (query);
1226 gst_structure_id_set (structure,
1227 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1228 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1229 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1230 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1234 * gst_query_parse_buffering_range:
1235 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1236 * @format: (out) (allow-none): the format to set for the @segment_start
1237 * and @segment_end values, or NULL
1238 * @start: (out) (allow-none): the start to set, or NULL
1239 * @stop: (out) (allow-none): the stop to set, or NULL
1240 * @estimated_total: (out) (allow-none): estimated total amount of download
1243 * Parse an available query, writing the format into @format, and
1244 * other results into the passed parameters, if the respective parameters
1250 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1251 gint64 * start, gint64 * stop, gint64 * estimated_total)
1253 GstStructure *structure;
1255 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1257 structure = GST_QUERY_STRUCTURE (query);
1260 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1261 GST_QUARK (FORMAT)));
1263 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1264 GST_QUARK (START_VALUE)));
1266 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1267 GST_QUARK (STOP_VALUE)));
1268 if (estimated_total)
1270 g_value_get_int64 (gst_structure_id_get_value (structure,
1271 GST_QUARK (ESTIMATED_TOTAL)));
1274 /* GstQueryBufferingRange: internal struct for GArray */
1279 } GstQueryBufferingRange;
1282 * gst_query_add_buffering_range:
1283 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1284 * @start: start position of the range
1285 * @stop: stop position of the range
1287 * Set the buffering-ranges array field in @query. The current last
1288 * start position of the array should be inferior to @start.
1290 * Returns: a #gboolean indicating if the range was added or not.
1295 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1297 GstQueryBufferingRange range;
1298 GstStructure *structure;
1301 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1302 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1304 if (G_UNLIKELY (start >= stop))
1307 structure = GST_QUERY_STRUCTURE (query);
1308 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1309 sizeof (GstQueryBufferingRange), NULL);
1311 if (array->len > 1) {
1312 GstQueryBufferingRange *last;
1314 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1316 if (G_UNLIKELY (start <= last->start))
1320 range.start = start;
1322 g_array_append_val (array, range);
1328 * gst_query_get_n_buffering_ranges:
1329 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1331 * Retrieve the number of values currently stored in the
1332 * buffered-ranges array of the query's structure.
1334 * Returns: the range array size as a #guint.
1339 gst_query_get_n_buffering_ranges (GstQuery * query)
1341 GstStructure *structure;
1344 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1346 structure = GST_QUERY_STRUCTURE (query);
1347 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1348 sizeof (GstQueryBufferingRange), NULL);
1355 * gst_query_parse_nth_buffering_range:
1356 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1357 * @index: position in the buffered-ranges array to read
1358 * @start: (out) (allow-none): the start position to set, or NULL
1359 * @stop: (out) (allow-none): the stop position to set, or NULL
1361 * Parse an available query and get the start and stop values stored
1362 * at the @index of the buffered ranges array.
1364 * Returns: a #gboolean indicating if the parsing succeeded.
1369 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1370 gint64 * start, gint64 * stop)
1372 GstQueryBufferingRange *range;
1373 GstStructure *structure;
1376 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1378 structure = GST_QUERY_STRUCTURE (query);
1380 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1381 sizeof (GstQueryBufferingRange), NULL);
1382 g_return_val_if_fail (index < array->len, FALSE);
1384 range = &g_array_index (array, GstQueryBufferingRange, index);
1387 *start = range->start;
1389 *stop = range->stop;
1396 * gst_query_new_uri:
1398 * Constructs a new query URI query object. Use gst_query_unref()
1399 * when done with it. An URI query is used to query the current URI
1400 * that is used by the source or sink.
1402 * Free-function: gst_query_unref
1404 * Returns: (transfer full): a new #GstQuery
1409 gst_query_new_uri (void)
1412 GstStructure *structure;
1414 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1415 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1417 query = gst_query_new_custom (GST_QUERY_URI, structure);
1423 * gst_query_set_uri:
1424 * @query: a #GstQuery with query type GST_QUERY_URI
1425 * @uri: the URI to set
1427 * Answer a URI query by setting the requested URI.
1432 gst_query_set_uri (GstQuery * query, const gchar * uri)
1434 GstStructure *structure;
1436 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1437 g_return_if_fail (gst_query_is_writable (query));
1438 g_return_if_fail (gst_uri_is_valid (uri));
1440 structure = GST_QUERY_STRUCTURE (query);
1441 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1445 * gst_query_parse_uri:
1446 * @query: a #GstQuery
1447 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1450 * Parse an URI query, writing the URI into @uri as a newly
1451 * allocated string, if the respective parameters are non-NULL.
1452 * Free the string with g_free() after usage.
1457 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1459 GstStructure *structure;
1461 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1463 structure = GST_QUERY_STRUCTURE (query);
1465 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1470 * gst_query_new_allocation:
1471 * @caps: the negotiated caps
1472 * @need_pool: return a pool
1474 * Constructs a new query object for querying the allocation properties.
1476 * Free-function: gst_query_unref
1478 * Returns: (transfer full): a new #GstQuery
1481 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1484 GstStructure *structure;
1486 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1487 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1488 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1490 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1496 * gst_query_parse_allocation:
1497 * @query: a #GstQuery
1498 * @caps: (out callee-allocates) (allow-none): The #GstCaps
1499 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1501 * Parse an allocation query, writing the requested caps in @caps and
1502 * whether a pool is needed in @need_pool, if the respective parameters
1506 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1507 gboolean * need_pool)
1509 GstStructure *structure;
1511 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1513 structure = GST_QUERY_STRUCTURE (query);
1514 gst_structure_id_get (structure,
1515 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1516 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1521 GstBufferPool *pool;
1528 allocation_pool_free (AllocationPool * ap)
1531 gst_object_unref (ap->pool);
1535 * gst_query_add_allocation_pool:
1536 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1537 * @pool: the #GstBufferPool
1539 * @min_buffers: the min buffers
1540 * @max_buffers: the max buffers
1542 * Set the pool parameters in @query.
1545 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1546 guint size, guint min_buffers, guint max_buffers)
1549 GstStructure *structure;
1552 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1553 g_return_if_fail (gst_query_is_writable (query));
1554 g_return_if_fail (size != 0);
1556 structure = GST_QUERY_STRUCTURE (query);
1557 array = ensure_array (structure, GST_QUARK (POOL),
1558 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1560 if ((ap.pool = pool))
1561 gst_object_ref (pool);
1563 ap.min_buffers = min_buffers;
1564 ap.max_buffers = max_buffers;
1566 g_array_append_val (array, ap);
1571 * gst_query_get_n_allocation_pools:
1572 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1574 * Retrieve the number of values currently stored in the
1575 * pool array of the query's structure.
1577 * Returns: the pool array size as a #guint.
1580 gst_query_get_n_allocation_pools (GstQuery * query)
1583 GstStructure *structure;
1585 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1587 structure = GST_QUERY_STRUCTURE (query);
1588 array = ensure_array (structure, GST_QUARK (POOL),
1589 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1595 * gst_query_parse_nth_allocation_pool:
1596 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1597 * @pool: (out) (allow-none) (transfer none): the #GstBufferPool
1598 * @size: (out) (allow-none): the size
1599 * @min_buffers: (out) (allow-none): the min buffers
1600 * @max_buffers: (out) (allow-none): the max buffers
1602 * Get the pool parameters in @query.
1605 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1606 GstBufferPool ** pool, guint * size, guint * min_buffers,
1607 guint * max_buffers)
1610 GstStructure *structure;
1613 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1615 structure = GST_QUERY_STRUCTURE (query);
1616 array = ensure_array (structure, GST_QUARK (POOL),
1617 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1618 g_return_if_fail (index < array->len);
1620 ap = &g_array_index (array, AllocationPool, index);
1623 if ((*pool = ap->pool))
1624 gst_object_ref (*pool);
1628 *min_buffers = ap->min_buffers;
1630 *max_buffers = ap->max_buffers;
1634 * gst_query_set_nth_allocation_pool:
1635 * @index: index to modify
1636 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1637 * @pool: the #GstBufferPool
1639 * @min_buffers: the min buffers
1640 * @max_buffers: the max buffers
1642 * Set the pool parameters in @query.
1645 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1646 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1649 GstStructure *structure;
1650 AllocationPool *oldap, ap;
1652 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1654 structure = GST_QUERY_STRUCTURE (query);
1655 array = ensure_array (structure, GST_QUARK (POOL),
1656 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1657 g_return_if_fail (index < array->len);
1659 oldap = &g_array_index (array, AllocationPool, index);
1660 allocation_pool_free (oldap);
1662 if ((ap.pool = pool))
1663 gst_object_ref (pool);
1665 ap.min_buffers = min_buffers;
1666 ap.max_buffers = max_buffers;
1667 g_array_index (array, AllocationPool, index) = ap;
1671 * gst_query_add_allocation_meta:
1672 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1673 * @api: the metadata API
1675 * Add @api as aone of the supported metadata API to @query.
1678 gst_query_add_allocation_meta (GstQuery * query, GType api)
1681 GstStructure *structure;
1683 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1684 g_return_if_fail (api != 0);
1685 g_return_if_fail (gst_query_is_writable (query));
1687 structure = GST_QUERY_STRUCTURE (query);
1688 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1690 g_array_append_val (array, api);
1694 * gst_query_get_n_allocation_metas:
1695 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1697 * Retrieve the number of values currently stored in the
1698 * meta API array of the query's structure.
1700 * Returns: the metadata API array size as a #guint.
1703 gst_query_get_n_allocation_metas (GstQuery * query)
1706 GstStructure *structure;
1708 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1710 structure = GST_QUERY_STRUCTURE (query);
1711 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1717 * gst_query_parse_nth_allocation_meta:
1718 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1719 * @index: position in the metadata API array to read
1721 * Parse an available query and get the metadata API
1722 * at @index of the metadata API array.
1724 * Returns: a #GType of the metadata API at @index.
1727 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1730 GstStructure *structure;
1732 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1734 structure = GST_QUERY_STRUCTURE (query);
1735 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1737 g_return_val_if_fail (index < array->len, 0);
1739 return g_array_index (array, GType, index);
1743 * gst_query_remove_nth_allocation_meta:
1744 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1745 * @index: position in the metadata API array to remove
1747 * Remove the metadata API at @index of the metadata API array.
1750 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1753 GstStructure *structure;
1755 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1756 g_return_if_fail (gst_query_is_writable (query));
1758 structure = GST_QUERY_STRUCTURE (query);
1759 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1760 g_return_if_fail (index < array->len);
1762 g_array_remove_index (array, index);
1766 * gst_query_has_allocation_meta:
1767 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1768 * @api: the metadata API
1770 * Check if @query has metadata @api set.
1772 * Returns: TRUE when @api is in the list of metadata.
1775 gst_query_has_allocation_meta (GstQuery * query, GType api)
1778 GstStructure *structure;
1781 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1782 g_return_val_if_fail (api != 0, FALSE);
1784 structure = GST_QUERY_STRUCTURE (query);
1785 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1788 for (i = 0; i < len; i++) {
1789 if (g_array_index (array, GType, i) == api)
1797 GstAllocator *allocator;
1798 GstAllocationParams params;
1802 allocation_param_free (AllocationParam * ap)
1805 gst_allocator_unref (ap->allocator);
1809 * gst_query_add_allocation_param:
1810 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1811 * @allocator: the memory allocator
1812 * @params: a #GstAllocationParams
1814 * Add @allocator and its @params as a supported memory allocator.
1817 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1818 const GstAllocationParams * params)
1821 GstStructure *structure;
1824 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1825 g_return_if_fail (gst_query_is_writable (query));
1826 g_return_if_fail (allocator != NULL || params != NULL);
1828 structure = GST_QUERY_STRUCTURE (query);
1829 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1830 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1832 if ((ap.allocator = allocator))
1833 gst_allocator_ref (allocator);
1835 ap.params = *params;
1837 gst_allocation_params_init (&ap.params);
1839 g_array_append_val (array, ap);
1843 * gst_query_get_n_allocation_params:
1844 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1846 * Retrieve the number of values currently stored in the
1847 * allocator params array of the query's structure.
1849 * If no memory allocator is specified, the downstream element can handle
1850 * the default memory allocator.
1852 * Returns: the allocator array size as a #guint.
1855 gst_query_get_n_allocation_params (GstQuery * query)
1858 GstStructure *structure;
1860 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1862 structure = GST_QUERY_STRUCTURE (query);
1863 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1864 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1870 * gst_query_parse_nth_allocation_param:
1871 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1872 * @index: position in the allocator array to read
1873 * @allocator: (transfer none): variable to hold the result
1874 * @params: parameters for the allocator
1876 * Parse an available query and get the alloctor and its params
1877 * at @index of the allocator array.
1880 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
1881 GstAllocator ** allocator, GstAllocationParams * params)
1884 GstStructure *structure;
1885 AllocationParam *ap;
1887 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1889 structure = GST_QUERY_STRUCTURE (query);
1890 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1891 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1892 g_return_if_fail (index < array->len);
1894 ap = &g_array_index (array, AllocationParam, index);
1897 if ((*allocator = ap->allocator))
1898 gst_allocator_ref (*allocator);
1900 *params = ap->params;
1904 * gst_query_set_nth_allocation_param:
1905 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1906 * @index: position in the allocator array to set
1907 * @allocator: (transfer full): new allocator to set
1908 * @params: parameters for the allocator
1910 * Parse an available query and get the alloctor and its params
1911 * at @index of the allocator array.
1914 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
1915 GstAllocator * allocator, const GstAllocationParams * params)
1918 GstStructure *structure;
1919 AllocationParam *old, ap;
1921 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1923 structure = GST_QUERY_STRUCTURE (query);
1924 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1925 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1926 g_return_if_fail (index < array->len);
1928 old = &g_array_index (array, AllocationParam, index);
1929 allocation_param_free (old);
1931 if ((ap.allocator = allocator))
1932 gst_allocator_ref (allocator);
1934 ap.params = *params;
1936 gst_allocation_params_init (&ap.params);
1938 g_array_index (array, AllocationParam, index) = ap;
1942 * gst_query_new_scheduling:
1944 * Constructs a new query object for querying the scheduling properties.
1946 * Free-function: gst_query_unref
1948 * Returns: (transfer full): a new #GstQuery
1951 gst_query_new_scheduling (void)
1954 GstStructure *structure;
1956 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1957 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1958 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1959 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1960 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1961 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
1967 * gst_query_set_scheduling:
1968 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1969 * @flags: #GstSchedulingFlags
1970 * @minsize: the suggested minimum size of pull requests
1971 * @maxsize: the suggested maximum size of pull requests
1972 * @align: the suggested alignment of pull requests
1974 * Set the scheduling properties.
1977 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1978 gint minsize, gint maxsize, gint align)
1980 GstStructure *structure;
1982 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1983 g_return_if_fail (gst_query_is_writable (query));
1985 structure = GST_QUERY_STRUCTURE (query);
1986 gst_structure_id_set (structure,
1987 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1988 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1989 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1990 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1994 * gst_query_parse_scheduling:
1995 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1996 * @flags: (out) (allow-none): #GstSchedulingFlags
1997 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
1998 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
1999 * @align: (out) (allow-none): the suggested alignment of pull requests
2001 * Set the scheduling properties.
2004 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2005 gint * minsize, gint * maxsize, gint * align)
2007 GstStructure *structure;
2009 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2011 structure = GST_QUERY_STRUCTURE (query);
2012 gst_structure_id_get (structure,
2013 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2014 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2015 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2016 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2020 * gst_query_add_scheduling_mode:
2021 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2022 * @mode: a #GstPadMode
2024 * Add @mode as aone of the supported scheduling modes to @query.
2027 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2029 GstStructure *structure;
2032 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2033 g_return_if_fail (gst_query_is_writable (query));
2035 structure = GST_QUERY_STRUCTURE (query);
2037 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2039 g_array_append_val (array, mode);
2043 * gst_query_get_n_scheduling_modes:
2044 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2046 * Retrieve the number of values currently stored in the
2047 * scheduling mode array of the query's structure.
2049 * Returns: the scheduling mode array size as a #guint.
2052 gst_query_get_n_scheduling_modes (GstQuery * query)
2055 GstStructure *structure;
2057 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2059 structure = GST_QUERY_STRUCTURE (query);
2061 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2067 * gst_query_parse_nth_scheduling_mode:
2068 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2069 * @index: position in the scheduling modes array to read
2071 * Parse an available query and get the scheduling mode
2072 * at @index of the scheduling modes array.
2074 * Returns: a #GstPadMode of the scheduling mode at @index.
2077 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2079 GstStructure *structure;
2082 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2085 structure = GST_QUERY_STRUCTURE (query);
2087 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2088 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2090 return g_array_index (array, GstPadMode, index);
2094 * gst_query_has_scheduling_mode:
2095 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2096 * @mode: the scheduling mode
2098 * Check if @query has scheduling mode set.
2100 * Returns: TRUE when @mode is in the list of scheduling modes.
2103 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2105 GstStructure *structure;
2109 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2111 structure = GST_QUERY_STRUCTURE (query);
2113 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2116 for (i = 0; i < len; i++) {
2117 if (mode == g_array_index (array, GstPadMode, i))
2124 * gst_query_new_accept_caps:
2127 * Constructs a new query object for querying if @caps are accepted.
2129 * Free-function: gst_query_unref
2131 * Returns: (transfer full): a new #GstQuery
2134 gst_query_new_accept_caps (GstCaps * caps)
2137 GstStructure *structure;
2139 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2140 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2141 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2142 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2148 * gst_query_parse_accept_caps:
2149 * @query: The query to parse
2150 * @caps: (out): A pointer to the caps
2152 * Get the caps from @query. The caps remains valid as long as @query remains
2156 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2158 GstStructure *structure;
2160 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2161 g_return_if_fail (caps != NULL);
2163 structure = GST_QUERY_STRUCTURE (query);
2164 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2169 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2171 GstStructure *structure;
2173 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2174 g_return_if_fail (gst_query_is_writable (query));
2176 structure = GST_QUERY_STRUCTURE (query);
2177 gst_structure_id_set (structure,
2178 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2182 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2184 GstStructure *structure;
2186 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2188 structure = GST_QUERY_STRUCTURE (query);
2189 gst_structure_id_get (structure,
2190 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2194 * gst_query_new_caps:
2197 * Constructs a new query object for querying the caps.
2199 * The CAPS query should return the* allowable caps for a pad in the context
2200 * of the element's state, its link to other elements, and the devices or files
2201 * it has opened. These caps must be a subset of the pad template caps. In the
2202 * NULL state with no links, the CAPS query should ideally return the same caps
2203 * as the pad template. In rare circumstances, an object property can affect
2204 * the caps returned by the CAPS query, but this is discouraged.
2206 * For most filters, the caps returned by CAPS query is directly affected by the
2207 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2208 * the srcpad's getcaps function is directly related to the stream data. Again,
2209 * the CAPS query should return the most specific caps it reasonably can, since this
2210 * helps with autoplugging.
2212 * Free-function: gst_query_unref
2214 * Returns: (transfer full): a new #GstQuery
2217 gst_query_new_caps (GstCaps * filter)
2220 GstStructure *structure;
2222 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2223 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2224 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2225 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2231 * gst_query_parse_caps:
2232 * @query: The query to parse
2233 * @filter: (out): A pointer to the caps filter
2235 * Get the filter from the caps @query. The caps remains valid as long as
2236 * @query remains valid.
2239 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2241 GstStructure *structure;
2243 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2244 g_return_if_fail (filter != NULL);
2246 structure = GST_QUERY_STRUCTURE (query);
2247 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2248 GST_QUARK (FILTER)));
2252 * gst_query_set_caps_result:
2253 * @query: The query to use
2254 * @caps: (in): A pointer to the caps
2256 * Set the @caps result in @query.
2259 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2261 GstStructure *structure;
2263 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2264 g_return_if_fail (gst_query_is_writable (query));
2266 structure = GST_QUERY_STRUCTURE (query);
2267 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2271 * gst_query_parse_caps_result:
2272 * @query: The query to parse
2273 * @caps: (out): A pointer to the caps
2275 * Get the caps result from @query. The caps remains valid as long as
2276 * @query remains valid.
2279 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2281 GstStructure *structure;
2283 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2284 g_return_if_fail (caps != NULL);
2286 structure = GST_QUERY_STRUCTURE (query);
2287 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2292 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2293 GstCapsIntersectMode mode)
2295 GstCaps *res, *caps = NULL;
2297 gst_query_parse_caps_result (query, &caps);
2298 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2299 gst_query_set_caps_result (query, res);
2300 gst_caps_unref (res);
2304 * gst_query_new_drain:
2306 * Constructs a new query object for querying the drain state.
2308 * Free-function: gst_query_unref
2310 * Returns: (transfer full): a new #GstQuery
2313 gst_query_new_drain (void)
2316 GstStructure *structure;
2318 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2319 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);