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: Provide functions to create queries, and to set and parse
28 * @see_also: #GstPad, #GstElement
30 * Queries can be performed on pads (gst_pad_query()) and elements
31 * (gst_element_query()). Please note that some queries might need a running
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.
38 * The following example shows how to query the duration of a pipeline:
41 * <title>Query duration on a pipeline</title>
45 * query = gst_query_new_duration (GST_FORMAT_TIME);
46 * res = gst_element_query (pipeline, query);
49 * gst_query_parse_duration (query, NULL, &duration);
50 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
53 * g_print ("duration query failed...");
55 * gst_query_unref (query);
59 * Last reviewed on 2012-03-29 (0.11.3)
63 #include "gst_private.h"
67 #include "gstenumtypes.h"
70 #include "gstbufferpool.h"
72 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
73 #define GST_CAT_DEFAULT gst_query_debug
75 static GType _gst_query_type = 0;
81 GstStructure *structure;
84 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
94 static GstQueryQuarks query_quarks[] = {
95 {GST_QUERY_UNKNOWN, "unknown", 0},
96 {GST_QUERY_POSITION, "position", 0},
97 {GST_QUERY_DURATION, "duration", 0},
98 {GST_QUERY_LATENCY, "latency", 0},
99 {GST_QUERY_JITTER, "jitter", 0},
100 {GST_QUERY_RATE, "rate", 0},
101 {GST_QUERY_SEEKING, "seeking", 0},
102 {GST_QUERY_SEGMENT, "segment", 0},
103 {GST_QUERY_CONVERT, "convert", 0},
104 {GST_QUERY_FORMATS, "formats", 0},
105 {GST_QUERY_BUFFERING, "buffering", 0},
106 {GST_QUERY_CUSTOM, "custom", 0},
107 {GST_QUERY_URI, "uri", 0},
108 {GST_QUERY_ALLOCATION, "allocation", 0},
109 {GST_QUERY_SCHEDULING, "scheduling", 0},
110 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
111 {GST_QUERY_CAPS, "caps", 0},
112 {GST_QUERY_DRAIN, "drain", 0},
113 {GST_QUERY_TOC, "toc", 0},
118 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
121 _priv_gst_query_initialize (void)
125 _gst_query_type = gst_query_get_type ();
127 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
129 for (i = 0; query_quarks[i].name; i++) {
130 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
135 * gst_query_type_get_name:
136 * @type: the query type
138 * Get a printable name for the given query type. Do not modify or free.
140 * Returns: a reference to the static name of the query.
143 gst_query_type_get_name (GstQueryType type)
147 for (i = 0; query_quarks[i].name; i++) {
148 if (type == query_quarks[i].type)
149 return query_quarks[i].name;
155 * gst_query_type_to_quark:
156 * @type: the query type
158 * Get the unique quark for the given query type.
160 * Returns: the quark associated with the query type
163 gst_query_type_to_quark (GstQueryType type)
167 for (i = 0; query_quarks[i].name; i++) {
168 if (type == query_quarks[i].type)
169 return query_quarks[i].quark;
175 * gst_query_type_get_flags:
176 * @type: a #GstQueryType
178 * Gets the #GstQueryTypeFlags associated with @type.
180 * Returns: a #GstQueryTypeFlags.
183 gst_query_type_get_flags (GstQueryType type)
185 GstQueryTypeFlags ret;
187 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
193 _gst_query_free (GstQuery * query)
197 g_return_if_fail (query != NULL);
199 s = GST_QUERY_STRUCTURE (query);
201 gst_structure_set_parent_refcount (s, NULL);
202 gst_structure_free (s);
205 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
209 _gst_query_copy (GstQuery * query)
214 s = GST_QUERY_STRUCTURE (query);
216 s = gst_structure_copy (s);
218 copy = gst_query_new_custom (query->type, s);
224 gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
226 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
228 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
229 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
231 GST_QUERY_TYPE (query) = type;
235 * gst_query_new_position:
236 * @format: the default #GstFormat for the new query
238 * Constructs a new query stream position query object. Use gst_query_unref()
239 * when done with it. A position query is used to query the current position
240 * of playback in the streams, in some format.
242 * Free-function: gst_query_unref
244 * Returns: (transfer full): a new #GstQuery
247 gst_query_new_position (GstFormat format)
250 GstStructure *structure;
252 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
253 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
254 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
256 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
262 * gst_query_set_position:
263 * @query: a #GstQuery with query type GST_QUERY_POSITION
264 * @format: the requested #GstFormat
265 * @cur: the position to set
267 * Answer a position query by setting the requested value in the given format.
270 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
274 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
276 s = GST_QUERY_STRUCTURE (query);
277 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
278 GST_QUARK (FORMAT))));
280 gst_structure_id_set (s,
281 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
282 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
286 * gst_query_parse_position:
287 * @query: a #GstQuery
288 * @format: (out) (allow-none): the storage for the #GstFormat of the
289 * position values (may be NULL)
290 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
292 * Parse a position query, writing the format into @format, and the position
293 * into @cur, if the respective parameters are non-NULL.
296 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
298 GstStructure *structure;
300 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
302 structure = GST_QUERY_STRUCTURE (query);
305 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
306 GST_QUARK (FORMAT)));
308 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
309 GST_QUARK (CURRENT)));
314 * gst_query_new_duration:
315 * @format: the #GstFormat for this duration query
317 * Constructs a new stream duration query object to query in the given format.
318 * Use gst_query_unref() when done with it. A duration query will give the
319 * total length of the stream.
321 * Free-function: gst_query_unref
323 * Returns: (transfer full): a new #GstQuery
326 gst_query_new_duration (GstFormat format)
329 GstStructure *structure;
331 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
332 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
333 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
335 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
341 * gst_query_set_duration:
342 * @query: a #GstQuery
343 * @format: the #GstFormat for the duration
344 * @duration: the duration of the stream
346 * Answer a duration query by setting the requested value in the given format.
349 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
353 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
355 s = GST_QUERY_STRUCTURE (query);
356 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
357 GST_QUARK (FORMAT))));
358 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
359 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
363 * gst_query_parse_duration:
364 * @query: a #GstQuery
365 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
367 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
369 * Parse a duration query answer. Write the format of the duration into @format,
370 * and the value into @duration, if the respective variables are non-NULL.
373 gst_query_parse_duration (GstQuery * query, GstFormat * format,
376 GstStructure *structure;
378 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
380 structure = GST_QUERY_STRUCTURE (query);
383 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
384 GST_QUARK (FORMAT)));
386 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
387 GST_QUARK (DURATION)));
391 * gst_query_new_latency:
393 * Constructs a new latency query object.
394 * Use gst_query_unref() when done with it. A latency query is usually performed
395 * by sinks to compensate for additional latency introduced by elements in the
398 * Free-function: gst_query_unref
400 * Returns: (transfer full): a #GstQuery
405 gst_query_new_latency (void)
408 GstStructure *structure;
410 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
411 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
412 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
413 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
415 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
421 * gst_query_set_latency:
422 * @query: a #GstQuery
423 * @live: if there is a live element upstream
424 * @min_latency: the minimal latency of the upstream elements
425 * @max_latency: the maximal latency of the upstream elements
427 * Answer a latency query by setting the requested values in the given format.
432 gst_query_set_latency (GstQuery * query, gboolean live,
433 GstClockTime min_latency, GstClockTime max_latency)
435 GstStructure *structure;
437 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
439 structure = GST_QUERY_STRUCTURE (query);
440 gst_structure_id_set (structure,
441 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
442 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
443 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
447 * gst_query_parse_latency:
448 * @query: a #GstQuery
449 * @live: (out) (allow-none): storage for live or NULL
450 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
451 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
453 * Parse a latency query answer.
458 gst_query_parse_latency (GstQuery * query, gboolean * live,
459 GstClockTime * min_latency, GstClockTime * max_latency)
461 GstStructure *structure;
463 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
465 structure = GST_QUERY_STRUCTURE (query);
468 g_value_get_boolean (gst_structure_id_get_value (structure,
471 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
472 GST_QUARK (MIN_LATENCY)));
474 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
475 GST_QUARK (MAX_LATENCY)));
479 * gst_query_new_convert:
480 * @src_format: the source #GstFormat for the new query
481 * @value: the value to convert
482 * @dest_format: the target #GstFormat
484 * Constructs a new convert query object. Use gst_query_unref()
485 * when done with it. A convert query is used to ask for a conversion between
486 * one format and another.
488 * Free-function: gst_query_unref
490 * Returns: (transfer full): a #GstQuery
493 gst_query_new_convert (GstFormat src_format, gint64 value,
494 GstFormat dest_format)
497 GstStructure *structure;
499 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
500 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
501 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
502 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
503 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
505 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
511 * gst_query_set_convert:
512 * @query: a #GstQuery
513 * @src_format: the source #GstFormat
514 * @src_value: the source value
515 * @dest_format: the destination #GstFormat
516 * @dest_value: the destination value
518 * Answer a convert query by setting the requested values.
521 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
522 GstFormat dest_format, gint64 dest_value)
524 GstStructure *structure;
526 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
528 structure = GST_QUERY_STRUCTURE (query);
529 gst_structure_id_set (structure,
530 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
531 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
532 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
533 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
537 * gst_query_parse_convert:
538 * @query: a #GstQuery
539 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
540 * source value, or NULL
541 * @src_value: (out) (allow-none): the storage for the source value, or NULL
542 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
543 * destination value, or NULL
544 * @dest_value: (out) (allow-none): the storage for the destination value,
547 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
548 * and @dest_value may be NULL, in which case that value is omitted.
551 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
552 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
554 GstStructure *structure;
556 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
558 structure = GST_QUERY_STRUCTURE (query);
561 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
562 GST_QUARK (SRC_FORMAT)));
564 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
565 GST_QUARK (SRC_VALUE)));
568 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
569 GST_QUARK (DEST_FORMAT)));
571 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
572 GST_QUARK (DEST_VALUE)));
576 * gst_query_new_segment:
577 * @format: the #GstFormat for the new query
579 * Constructs a new segment query object. Use gst_query_unref()
580 * when done with it. A segment query is used to discover information about the
581 * currently configured segment for playback.
583 * Free-function: gst_query_unref
585 * Returns: (transfer full): a new #GstQuery
588 gst_query_new_segment (GstFormat format)
591 GstStructure *structure;
593 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
594 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
595 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
596 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
597 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
599 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
605 * gst_query_set_segment:
606 * @query: a #GstQuery
607 * @rate: the rate of the segment
608 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
609 * @start_value: the start value
610 * @stop_value: the stop value
612 * Answer a segment query by setting the requested values. The normal
613 * playback segment of a pipeline is 0 to duration at the default rate of
614 * 1.0. If a seek was performed on the pipeline to play a different
615 * segment, this query will return the range specified in the last seek.
617 * @start_value and @stop_value will respectively contain the configured
618 * playback range start and stop values expressed in @format.
619 * The values are always between 0 and the duration of the media and
620 * @start_value <= @stop_value. @rate will contain the playback rate. For
621 * negative rates, playback will actually happen from @stop_value to
625 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
626 gint64 start_value, gint64 stop_value)
628 GstStructure *structure;
630 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
632 structure = GST_QUERY_STRUCTURE (query);
633 gst_structure_id_set (structure,
634 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
635 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
636 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
637 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
641 * gst_query_parse_segment:
642 * @query: a #GstQuery
643 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
644 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
646 * @start_value: (out) (allow-none): the storage for the start value, or NULL
647 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
649 * Parse a segment query answer. Any of @rate, @format, @start_value, and
650 * @stop_value may be NULL, which will cause this value to be omitted.
652 * See gst_query_set_segment() for an explanation of the function arguments.
655 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
656 gint64 * start_value, gint64 * stop_value)
658 GstStructure *structure;
660 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
662 structure = GST_QUERY_STRUCTURE (query);
664 *rate = g_value_get_double (gst_structure_id_get_value (structure,
668 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
669 GST_QUARK (FORMAT)));
671 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
672 GST_QUARK (START_VALUE)));
674 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
675 GST_QUARK (STOP_VALUE)));
679 * gst_query_new_custom:
680 * @type: the query type
681 * @structure: a structure for the query
683 * Constructs a new custom query object. Use gst_query_unref()
686 * Free-function: gst_query_unref
688 * Returns: (transfer full): a new #GstQuery
691 gst_query_new_custom (GstQueryType type, GstStructure * structure)
695 query = g_slice_new0 (GstQueryImpl);
697 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
700 /* structure must not have a parent */
701 if (!gst_structure_set_parent_refcount (structure,
702 &query->query.mini_object.refcount))
705 gst_query_init (query, sizeof (GstQueryImpl), type);
707 GST_QUERY_STRUCTURE (query) = structure;
709 return GST_QUERY_CAST (query);
714 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
715 g_warning ("structure is already owned by another object");
721 * gst_query_get_structure:
722 * @query: a #GstQuery
724 * Get the structure of a query.
726 * Returns: (transfer none): the #GstStructure of the query. The structure is
727 * still owned by the query and will therefore be freed when the query
731 gst_query_get_structure (GstQuery * query)
733 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
735 return GST_QUERY_STRUCTURE (query);
739 * gst_query_writable_structure:
740 * @query: a #GstQuery
742 * Get the structure of a query. This method should be called with a writable
743 * @query so that the returned structure is guranteed to be writable.
745 * Returns: (transfer none): the #GstStructure of the query. The structure is
746 * still owned by the query and will therefore be freed when the query
750 gst_query_writable_structure (GstQuery * query)
752 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
753 g_return_val_if_fail (gst_query_is_writable (query), NULL);
755 return GST_QUERY_STRUCTURE (query);
759 * gst_query_new_seeking:
760 * @format: the default #GstFormat for the new query
762 * Constructs a new query object for querying seeking properties of
765 * Free-function: gst_query_unref
767 * Returns: (transfer full): a new #GstQuery
770 gst_query_new_seeking (GstFormat format)
773 GstStructure *structure;
775 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
776 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
777 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
778 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
779 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
781 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
787 * gst_query_set_seeking:
788 * @query: a #GstQuery
789 * @format: the format to set for the @segment_start and @segment_end values
790 * @seekable: the seekable flag to set
791 * @segment_start: the segment_start to set
792 * @segment_end: the segment_end to set
794 * Set the seeking query result fields in @query.
797 gst_query_set_seeking (GstQuery * query, GstFormat format,
798 gboolean seekable, gint64 segment_start, gint64 segment_end)
800 GstStructure *structure;
802 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
803 g_return_if_fail (gst_query_is_writable (query));
805 structure = GST_QUERY_STRUCTURE (query);
806 gst_structure_id_set (structure,
807 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
808 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
809 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
810 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
814 * gst_query_parse_seeking:
815 * @query: a GST_QUERY_SEEKING type query #GstQuery
816 * @format: (out) (allow-none): the format to set for the @segment_start
817 * and @segment_end values, or NULL
818 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
819 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
820 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
822 * Parse a seeking query, writing the format into @format, and
823 * other results into the passed parameters, if the respective parameters
827 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
828 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
830 GstStructure *structure;
832 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
834 structure = GST_QUERY_STRUCTURE (query);
837 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
838 GST_QUARK (FORMAT)));
840 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
841 GST_QUARK (SEEKABLE)));
843 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
844 GST_QUARK (SEGMENT_START)));
846 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
847 GST_QUARK (SEGMENT_END)));
851 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
852 GDestroyNotify clear_func)
857 value = gst_structure_id_get_value (s, quark);
859 array = (GArray *) g_value_get_boxed (value);
861 GValue new_array_val = { 0, };
863 array = g_array_new (FALSE, TRUE, element_size);
865 g_array_set_clear_func (array, clear_func);
867 g_value_init (&new_array_val, G_TYPE_ARRAY);
868 g_value_take_boxed (&new_array_val, array);
870 gst_structure_id_take_value (s, quark, &new_array_val);
876 * gst_query_new_formats:
878 * Constructs a new query object for querying formats of
881 * Free-function: gst_query_unref
883 * Returns: (transfer full): a new #GstQuery
888 gst_query_new_formats (void)
891 GstStructure *structure;
893 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
894 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
900 gst_query_list_add_format (GValue * list, GstFormat format)
902 GValue item = { 0, };
904 g_value_init (&item, GST_TYPE_FORMAT);
905 g_value_set_enum (&item, format);
906 gst_value_list_append_value (list, &item);
907 g_value_unset (&item);
911 * gst_query_set_formats:
912 * @query: a #GstQuery
913 * @n_formats: the number of formats to set.
914 * @...: A number of @GstFormats equal to @n_formats.
916 * Set the formats query result fields in @query. The number of formats passed
917 * must be equal to @n_formats.
920 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
923 GValue list = { 0, };
925 GstStructure *structure;
927 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
928 g_return_if_fail (gst_query_is_writable (query));
930 g_value_init (&list, GST_TYPE_LIST);
932 va_start (ap, n_formats);
933 for (i = 0; i < n_formats; i++) {
934 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
938 structure = GST_QUERY_STRUCTURE (query);
939 gst_structure_set_value (structure, "formats", &list);
941 g_value_unset (&list);
946 * gst_query_set_formatsv:
947 * @query: a #GstQuery
948 * @n_formats: the number of formats to set.
949 * @formats: (in) (array length=n_formats): an array containing @n_formats
952 * Set the formats query result fields in @query. The number of formats passed
953 * in the @formats array must be equal to @n_formats.
958 gst_query_set_formatsv (GstQuery * query, gint n_formats,
959 const GstFormat * formats)
961 GValue list = { 0, };
963 GstStructure *structure;
965 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
966 g_return_if_fail (gst_query_is_writable (query));
968 g_value_init (&list, GST_TYPE_LIST);
969 for (i = 0; i < n_formats; i++) {
970 gst_query_list_add_format (&list, formats[i]);
972 structure = GST_QUERY_STRUCTURE (query);
973 gst_structure_set_value (structure, "formats", &list);
975 g_value_unset (&list);
979 * gst_query_parse_n_formats:
980 * @query: a #GstQuery
981 * @n_formats: (out) (allow-none): the number of formats in this query.
983 * Parse the number of formats in the formats @query.
988 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
990 GstStructure *structure;
992 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
997 structure = GST_QUERY_STRUCTURE (query);
998 list = gst_structure_get_value (structure, "formats");
1002 *n_formats = gst_value_list_get_size (list);
1007 * gst_query_parse_nth_format:
1008 * @query: a #GstQuery
1009 * @nth: (out): the nth format to retrieve.
1010 * @format: (out) (allow-none): a pointer to store the nth format
1012 * Parse the format query and retrieve the @nth format from it into
1013 * @format. If the list contains less elements than @nth, @format will be
1014 * set to GST_FORMAT_UNDEFINED.
1017 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1019 GstStructure *structure;
1021 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1026 structure = GST_QUERY_STRUCTURE (query);
1027 list = gst_structure_get_value (structure, "formats");
1029 *format = GST_FORMAT_UNDEFINED;
1031 if (nth < gst_value_list_get_size (list)) {
1033 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1035 *format = GST_FORMAT_UNDEFINED;
1041 * gst_query_new_buffering:
1042 * @format: the default #GstFormat for the new query
1044 * Constructs a new query object for querying the buffering status of
1047 * Free-function: gst_query_unref
1049 * Returns: (transfer full): a new #GstQuery
1054 gst_query_new_buffering (GstFormat format)
1057 GstStructure *structure;
1059 /* by default, we configure the answer as no buffering with a 100% buffering
1061 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1062 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1063 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1064 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1065 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1066 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1067 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1068 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1069 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1070 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1071 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1073 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1079 * gst_query_set_buffering_percent:
1080 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1081 * @busy: if buffering is busy
1082 * @percent: a buffering percent
1084 * Set the percentage of buffered data. This is a value between 0 and 100.
1085 * The @busy indicator is %TRUE when the buffering is in progress.
1090 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1092 GstStructure *structure;
1094 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1095 g_return_if_fail (gst_query_is_writable (query));
1096 g_return_if_fail (percent >= 0 && percent <= 100);
1098 structure = GST_QUERY_STRUCTURE (query);
1099 gst_structure_id_set (structure,
1100 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1101 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1105 * gst_query_parse_buffering_percent:
1106 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1107 * @busy: (out) (allow-none): if buffering is busy, or NULL
1108 * @percent: (out) (allow-none): a buffering percent, or NULL
1110 * Get the percentage of buffered data. This is a value between 0 and 100.
1111 * The @busy indicator is %TRUE when the buffering is in progress.
1116 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1119 GstStructure *structure;
1121 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1123 structure = GST_QUERY_STRUCTURE (query);
1125 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1128 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1129 GST_QUARK (BUFFER_PERCENT)));
1133 * gst_query_set_buffering_stats:
1134 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1135 * @mode: a buffering mode
1136 * @avg_in: the average input rate
1137 * @avg_out: the average output rate
1138 * @buffering_left: amount of buffering time left
1140 * Configures the buffering stats values in @query.
1145 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1146 gint avg_in, gint avg_out, gint64 buffering_left)
1148 GstStructure *structure;
1150 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1151 g_return_if_fail (gst_query_is_writable (query));
1153 structure = GST_QUERY_STRUCTURE (query);
1154 gst_structure_id_set (structure,
1155 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1156 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1157 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1158 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1162 * gst_query_parse_buffering_stats:
1163 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1164 * @mode: (out) (allow-none): a buffering mode, or NULL
1165 * @avg_in: (out) (allow-none): the average input rate, or NULL
1166 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1167 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1169 * Extracts the buffering stats values from @query.
1174 gst_query_parse_buffering_stats (GstQuery * query,
1175 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1176 gint64 * buffering_left)
1178 GstStructure *structure;
1180 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1182 structure = GST_QUERY_STRUCTURE (query);
1184 *mode = (GstBufferingMode)
1185 g_value_get_enum (gst_structure_id_get_value (structure,
1186 GST_QUARK (BUFFERING_MODE)));
1188 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1189 GST_QUARK (AVG_IN_RATE)));
1191 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1192 GST_QUARK (AVG_OUT_RATE)));
1195 g_value_get_int64 (gst_structure_id_get_value (structure,
1196 GST_QUARK (BUFFERING_LEFT)));
1200 * gst_query_set_buffering_range:
1201 * @query: a #GstQuery
1202 * @format: the format to set for the @start and @stop values
1203 * @start: the start to set
1204 * @stop: the stop to set
1205 * @estimated_total: estimated total amount of download time
1207 * Set the available query result fields in @query.
1212 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1213 gint64 start, gint64 stop, gint64 estimated_total)
1215 GstStructure *structure;
1217 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1218 g_return_if_fail (gst_query_is_writable (query));
1220 structure = GST_QUERY_STRUCTURE (query);
1221 gst_structure_id_set (structure,
1222 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1223 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1224 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1225 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1229 * gst_query_parse_buffering_range:
1230 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1231 * @format: (out) (allow-none): the format to set for the @segment_start
1232 * and @segment_end values, or NULL
1233 * @start: (out) (allow-none): the start to set, or NULL
1234 * @stop: (out) (allow-none): the stop to set, or NULL
1235 * @estimated_total: (out) (allow-none): estimated total amount of download
1238 * Parse an available query, writing the format into @format, and
1239 * other results into the passed parameters, if the respective parameters
1245 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1246 gint64 * start, gint64 * stop, gint64 * estimated_total)
1248 GstStructure *structure;
1250 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1252 structure = GST_QUERY_STRUCTURE (query);
1255 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1256 GST_QUARK (FORMAT)));
1258 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1259 GST_QUARK (START_VALUE)));
1261 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1262 GST_QUARK (STOP_VALUE)));
1263 if (estimated_total)
1265 g_value_get_int64 (gst_structure_id_get_value (structure,
1266 GST_QUARK (ESTIMATED_TOTAL)));
1269 /* GstQueryBufferingRange: internal struct for GArray */
1274 } GstQueryBufferingRange;
1277 * gst_query_add_buffering_range:
1278 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1279 * @start: start position of the range
1280 * @stop: stop position of the range
1282 * Set the buffering-ranges array field in @query. The current last
1283 * start position of the array should be inferior to @start.
1285 * Returns: a #gboolean indicating if the range was added or not.
1290 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1292 GstQueryBufferingRange range;
1293 GstStructure *structure;
1296 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1297 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1299 if (G_UNLIKELY (start >= stop))
1302 structure = GST_QUERY_STRUCTURE (query);
1303 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1304 sizeof (GstQueryBufferingRange), NULL);
1306 if (array->len > 1) {
1307 GstQueryBufferingRange *last;
1309 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1311 if (G_UNLIKELY (start <= last->start))
1315 range.start = start;
1317 g_array_append_val (array, range);
1323 * gst_query_get_n_buffering_ranges:
1324 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1326 * Retrieve the number of values currently stored in the
1327 * buffered-ranges array of the query's structure.
1329 * Returns: the range array size as a #guint.
1334 gst_query_get_n_buffering_ranges (GstQuery * query)
1336 GstStructure *structure;
1339 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1341 structure = GST_QUERY_STRUCTURE (query);
1342 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1343 sizeof (GstQueryBufferingRange), NULL);
1350 * gst_query_parse_nth_buffering_range:
1351 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1352 * @index: position in the buffered-ranges array to read
1353 * @start: (out) (allow-none): the start position to set, or NULL
1354 * @stop: (out) (allow-none): the stop position to set, or NULL
1356 * Parse an available query and get the start and stop values stored
1357 * at the @index of the buffered ranges array.
1359 * Returns: a #gboolean indicating if the parsing succeeded.
1364 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1365 gint64 * start, gint64 * stop)
1367 GstQueryBufferingRange *range;
1368 GstStructure *structure;
1371 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1373 structure = GST_QUERY_STRUCTURE (query);
1375 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1376 sizeof (GstQueryBufferingRange), NULL);
1377 g_return_val_if_fail (index < array->len, FALSE);
1379 range = &g_array_index (array, GstQueryBufferingRange, index);
1382 *start = range->start;
1384 *stop = range->stop;
1391 * gst_query_new_uri:
1393 * Constructs a new query URI query object. Use gst_query_unref()
1394 * when done with it. An URI query is used to query the current URI
1395 * that is used by the source or sink.
1397 * Free-function: gst_query_unref
1399 * Returns: (transfer full): a new #GstQuery
1404 gst_query_new_uri (void)
1407 GstStructure *structure;
1409 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1410 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1412 query = gst_query_new_custom (GST_QUERY_URI, structure);
1418 * gst_query_set_uri:
1419 * @query: a #GstQuery with query type GST_QUERY_URI
1420 * @uri: the URI to set
1422 * Answer a URI query by setting the requested URI.
1427 gst_query_set_uri (GstQuery * query, const gchar * uri)
1429 GstStructure *structure;
1431 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1432 g_return_if_fail (gst_query_is_writable (query));
1433 g_return_if_fail (gst_uri_is_valid (uri));
1435 structure = GST_QUERY_STRUCTURE (query);
1436 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1440 * gst_query_parse_uri:
1441 * @query: a #GstQuery
1442 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1445 * Parse an URI query, writing the URI into @uri as a newly
1446 * allocated string, if the respective parameters are non-NULL.
1447 * Free the string with g_free() after usage.
1452 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1454 GstStructure *structure;
1456 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1458 structure = GST_QUERY_STRUCTURE (query);
1460 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1465 * gst_query_new_allocation:
1466 * @caps: the negotiated caps
1467 * @need_pool: return a pool
1469 * Constructs a new query object for querying the allocation properties.
1471 * Free-function: gst_query_unref
1473 * Returns: (transfer full): a new #GstQuery
1476 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1479 GstStructure *structure;
1481 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1482 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1483 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1485 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1491 * gst_query_parse_allocation:
1492 * @query: a #GstQuery
1493 * @caps: (out) (transfer none) (allow-none): The #GstCaps
1494 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1496 * Parse an allocation query, writing the requested caps in @caps and
1497 * whether a pool is needed in @need_pool, if the respective parameters
1501 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1502 gboolean * need_pool)
1504 GstStructure *structure;
1506 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1508 structure = GST_QUERY_STRUCTURE (query);
1510 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1513 gst_structure_id_get (structure,
1514 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1519 GstBufferPool *pool;
1526 allocation_pool_free (AllocationPool * ap)
1529 gst_object_unref (ap->pool);
1533 * gst_query_add_allocation_pool:
1534 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1535 * @pool: the #GstBufferPool
1537 * @min_buffers: the min buffers
1538 * @max_buffers: the max buffers
1540 * Set the pool parameters in @query.
1543 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1544 guint size, guint min_buffers, guint max_buffers)
1547 GstStructure *structure;
1550 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1551 g_return_if_fail (gst_query_is_writable (query));
1552 g_return_if_fail (size != 0);
1554 structure = GST_QUERY_STRUCTURE (query);
1555 array = ensure_array (structure, GST_QUARK (POOL),
1556 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1558 if ((ap.pool = pool))
1559 gst_object_ref (pool);
1561 ap.min_buffers = min_buffers;
1562 ap.max_buffers = max_buffers;
1564 g_array_append_val (array, ap);
1569 * gst_query_get_n_allocation_pools:
1570 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1572 * Retrieve the number of values currently stored in the
1573 * pool array of the query's structure.
1575 * Returns: the pool array size as a #guint.
1578 gst_query_get_n_allocation_pools (GstQuery * query)
1581 GstStructure *structure;
1583 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1585 structure = GST_QUERY_STRUCTURE (query);
1586 array = ensure_array (structure, GST_QUARK (POOL),
1587 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1593 * gst_query_parse_nth_allocation_pool:
1594 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1595 * @index: index to parse
1596 * @pool: (out) (allow-none) (transfer none): the #GstBufferPool
1597 * @size: (out) (allow-none): the size
1598 * @min_buffers: (out) (allow-none): the min buffers
1599 * @max_buffers: (out) (allow-none): the max buffers
1601 * Get the pool parameters in @query.
1604 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1605 GstBufferPool ** pool, guint * size, guint * min_buffers,
1606 guint * max_buffers)
1609 GstStructure *structure;
1612 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1614 structure = GST_QUERY_STRUCTURE (query);
1615 array = ensure_array (structure, GST_QUARK (POOL),
1616 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1617 g_return_if_fail (index < array->len);
1619 ap = &g_array_index (array, AllocationPool, index);
1622 if ((*pool = ap->pool))
1623 gst_object_ref (*pool);
1627 *min_buffers = ap->min_buffers;
1629 *max_buffers = ap->max_buffers;
1633 * gst_query_set_nth_allocation_pool:
1634 * @index: index to modify
1635 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1636 * @pool: the #GstBufferPool
1638 * @min_buffers: the min buffers
1639 * @max_buffers: the max buffers
1641 * Set the pool parameters in @query.
1644 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1645 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1648 GstStructure *structure;
1649 AllocationPool *oldap, ap;
1651 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1653 structure = GST_QUERY_STRUCTURE (query);
1654 array = ensure_array (structure, GST_QUARK (POOL),
1655 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1656 g_return_if_fail (index < array->len);
1658 oldap = &g_array_index (array, AllocationPool, index);
1659 allocation_pool_free (oldap);
1661 if ((ap.pool = pool))
1662 gst_object_ref (pool);
1664 ap.min_buffers = min_buffers;
1665 ap.max_buffers = max_buffers;
1666 g_array_index (array, AllocationPool, index) = ap;
1670 * gst_query_add_allocation_meta:
1671 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1672 * @api: the metadata API
1674 * Add @api as aone of the supported metadata API to @query.
1677 gst_query_add_allocation_meta (GstQuery * query, GType api)
1680 GstStructure *structure;
1682 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1683 g_return_if_fail (api != 0);
1684 g_return_if_fail (gst_query_is_writable (query));
1686 structure = GST_QUERY_STRUCTURE (query);
1687 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1689 g_array_append_val (array, api);
1693 * gst_query_get_n_allocation_metas:
1694 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1696 * Retrieve the number of values currently stored in the
1697 * meta API array of the query's structure.
1699 * Returns: the metadata API array size as a #guint.
1702 gst_query_get_n_allocation_metas (GstQuery * query)
1705 GstStructure *structure;
1707 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1709 structure = GST_QUERY_STRUCTURE (query);
1710 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1716 * gst_query_parse_nth_allocation_meta:
1717 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1718 * @index: position in the metadata API array to read
1720 * Parse an available query and get the metadata API
1721 * at @index of the metadata API array.
1723 * Returns: a #GType of the metadata API at @index.
1726 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1729 GstStructure *structure;
1731 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1733 structure = GST_QUERY_STRUCTURE (query);
1734 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1736 g_return_val_if_fail (index < array->len, 0);
1738 return g_array_index (array, GType, index);
1742 * gst_query_remove_nth_allocation_meta:
1743 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1744 * @index: position in the metadata API array to remove
1746 * Remove the metadata API at @index of the metadata API array.
1749 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1752 GstStructure *structure;
1754 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1755 g_return_if_fail (gst_query_is_writable (query));
1757 structure = GST_QUERY_STRUCTURE (query);
1758 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1759 g_return_if_fail (index < array->len);
1761 g_array_remove_index (array, index);
1765 * gst_query_has_allocation_meta:
1766 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1767 * @api: the metadata API
1769 * Check if @query has metadata @api set.
1771 * Returns: TRUE when @api is in the list of metadata.
1774 gst_query_has_allocation_meta (GstQuery * query, GType api)
1777 GstStructure *structure;
1780 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1781 g_return_val_if_fail (api != 0, FALSE);
1783 structure = GST_QUERY_STRUCTURE (query);
1784 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1787 for (i = 0; i < len; i++) {
1788 if (g_array_index (array, GType, i) == api)
1796 GstAllocator *allocator;
1797 GstAllocationParams params;
1801 allocation_param_free (AllocationParam * ap)
1804 gst_allocator_unref (ap->allocator);
1808 * gst_query_add_allocation_param:
1809 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1810 * @allocator: the memory allocator
1811 * @params: a #GstAllocationParams
1813 * Add @allocator and its @params as a supported memory allocator.
1816 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1817 const GstAllocationParams * params)
1820 GstStructure *structure;
1823 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1824 g_return_if_fail (gst_query_is_writable (query));
1825 g_return_if_fail (allocator != NULL || params != NULL);
1827 structure = GST_QUERY_STRUCTURE (query);
1828 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1829 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1831 if ((ap.allocator = allocator))
1832 gst_allocator_ref (allocator);
1834 ap.params = *params;
1836 gst_allocation_params_init (&ap.params);
1838 g_array_append_val (array, ap);
1842 * gst_query_get_n_allocation_params:
1843 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1845 * Retrieve the number of values currently stored in the
1846 * allocator params array of the query's structure.
1848 * If no memory allocator is specified, the downstream element can handle
1849 * the default memory allocator.
1851 * Returns: the allocator array size as a #guint.
1854 gst_query_get_n_allocation_params (GstQuery * query)
1857 GstStructure *structure;
1859 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1861 structure = GST_QUERY_STRUCTURE (query);
1862 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1863 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1869 * gst_query_parse_nth_allocation_param:
1870 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1871 * @index: position in the allocator array to read
1872 * @allocator: (transfer none): variable to hold the result
1873 * @params: parameters for the allocator
1875 * Parse an available query and get the alloctor and its params
1876 * at @index of the allocator array.
1879 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
1880 GstAllocator ** allocator, GstAllocationParams * params)
1883 GstStructure *structure;
1884 AllocationParam *ap;
1886 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1888 structure = GST_QUERY_STRUCTURE (query);
1889 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1890 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1891 g_return_if_fail (index < array->len);
1893 ap = &g_array_index (array, AllocationParam, index);
1896 if ((*allocator = ap->allocator))
1897 gst_allocator_ref (*allocator);
1899 *params = ap->params;
1903 * gst_query_set_nth_allocation_param:
1904 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1905 * @index: position in the allocator array to set
1906 * @allocator: (transfer full): new allocator to set
1907 * @params: parameters for the allocator
1909 * Parse an available query and get the alloctor and its params
1910 * at @index of the allocator array.
1913 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
1914 GstAllocator * allocator, const GstAllocationParams * params)
1917 GstStructure *structure;
1918 AllocationParam *old, ap;
1920 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1922 structure = GST_QUERY_STRUCTURE (query);
1923 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1924 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1925 g_return_if_fail (index < array->len);
1927 old = &g_array_index (array, AllocationParam, index);
1928 allocation_param_free (old);
1930 if ((ap.allocator = allocator))
1931 gst_allocator_ref (allocator);
1933 ap.params = *params;
1935 gst_allocation_params_init (&ap.params);
1937 g_array_index (array, AllocationParam, index) = ap;
1941 * gst_query_new_scheduling:
1943 * Constructs a new query object for querying the scheduling properties.
1945 * Free-function: gst_query_unref
1947 * Returns: (transfer full): a new #GstQuery
1950 gst_query_new_scheduling (void)
1953 GstStructure *structure;
1955 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1956 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1957 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1958 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1959 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1960 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
1966 * gst_query_set_scheduling:
1967 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1968 * @flags: #GstSchedulingFlags
1969 * @minsize: the suggested minimum size of pull requests
1970 * @maxsize: the suggested maximum size of pull requests
1971 * @align: the suggested alignment of pull requests
1973 * Set the scheduling properties.
1976 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1977 gint minsize, gint maxsize, gint align)
1979 GstStructure *structure;
1981 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1982 g_return_if_fail (gst_query_is_writable (query));
1984 structure = GST_QUERY_STRUCTURE (query);
1985 gst_structure_id_set (structure,
1986 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1987 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1988 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1989 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1993 * gst_query_parse_scheduling:
1994 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1995 * @flags: (out) (allow-none): #GstSchedulingFlags
1996 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
1997 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
1998 * @align: (out) (allow-none): the suggested alignment of pull requests
2000 * Set the scheduling properties.
2003 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2004 gint * minsize, gint * maxsize, gint * align)
2006 GstStructure *structure;
2008 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2010 structure = GST_QUERY_STRUCTURE (query);
2011 gst_structure_id_get (structure,
2012 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2013 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2014 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2015 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2019 * gst_query_add_scheduling_mode:
2020 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2021 * @mode: a #GstPadMode
2023 * Add @mode as aone of the supported scheduling modes to @query.
2026 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2028 GstStructure *structure;
2031 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2032 g_return_if_fail (gst_query_is_writable (query));
2034 structure = GST_QUERY_STRUCTURE (query);
2036 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2038 g_array_append_val (array, mode);
2042 * gst_query_get_n_scheduling_modes:
2043 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2045 * Retrieve the number of values currently stored in the
2046 * scheduling mode array of the query's structure.
2048 * Returns: the scheduling mode array size as a #guint.
2051 gst_query_get_n_scheduling_modes (GstQuery * query)
2054 GstStructure *structure;
2056 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2058 structure = GST_QUERY_STRUCTURE (query);
2060 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2066 * gst_query_parse_nth_scheduling_mode:
2067 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2068 * @index: position in the scheduling modes array to read
2070 * Parse an available query and get the scheduling mode
2071 * at @index of the scheduling modes array.
2073 * Returns: a #GstPadMode of the scheduling mode at @index.
2076 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2078 GstStructure *structure;
2081 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2084 structure = GST_QUERY_STRUCTURE (query);
2086 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2087 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2089 return g_array_index (array, GstPadMode, index);
2093 * gst_query_has_scheduling_mode:
2094 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2095 * @mode: the scheduling mode
2097 * Check if @query has scheduling mode set.
2099 * Returns: TRUE when @mode is in the list of scheduling modes.
2102 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2104 GstStructure *structure;
2108 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2110 structure = GST_QUERY_STRUCTURE (query);
2112 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2115 for (i = 0; i < len; i++) {
2116 if (mode == g_array_index (array, GstPadMode, i))
2123 * gst_query_new_accept_caps:
2124 * @caps: a fixed #GstCaps
2126 * Constructs a new query object for querying if @caps are accepted.
2128 * Free-function: gst_query_unref
2130 * Returns: (transfer full): a new #GstQuery
2133 gst_query_new_accept_caps (GstCaps * caps)
2136 GstStructure *structure;
2138 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2140 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2141 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2142 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2143 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2149 * gst_query_parse_accept_caps:
2150 * @query: The query to parse
2151 * @caps: (out): A pointer to the caps
2153 * Get the caps from @query. The caps remains valid as long as @query remains
2157 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2159 GstStructure *structure;
2161 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2162 g_return_if_fail (caps != NULL);
2164 structure = GST_QUERY_STRUCTURE (query);
2165 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2170 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2172 GstStructure *structure;
2174 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2175 g_return_if_fail (gst_query_is_writable (query));
2177 structure = GST_QUERY_STRUCTURE (query);
2178 gst_structure_id_set (structure,
2179 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2183 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2185 GstStructure *structure;
2187 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2189 structure = GST_QUERY_STRUCTURE (query);
2190 gst_structure_id_get (structure,
2191 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2195 * gst_query_new_caps:
2198 * Constructs a new query object for querying the caps.
2200 * The CAPS query should return the* allowable caps for a pad in the context
2201 * of the element's state, its link to other elements, and the devices or files
2202 * it has opened. These caps must be a subset of the pad template caps. In the
2203 * NULL state with no links, the CAPS query should ideally return the same caps
2204 * as the pad template. In rare circumstances, an object property can affect
2205 * the caps returned by the CAPS query, but this is discouraged.
2207 * For most filters, the caps returned by CAPS query is directly affected by the
2208 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2209 * the srcpad's getcaps function is directly related to the stream data. Again,
2210 * the CAPS query should return the most specific caps it reasonably can, since this
2211 * helps with autoplugging.
2213 * Free-function: gst_query_unref
2215 * Returns: (transfer full): a new #GstQuery
2218 gst_query_new_caps (GstCaps * filter)
2221 GstStructure *structure;
2223 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2224 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2225 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2226 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2232 * gst_query_parse_caps:
2233 * @query: The query to parse
2234 * @filter: (out): A pointer to the caps filter
2236 * Get the filter from the caps @query. The caps remains valid as long as
2237 * @query remains valid.
2240 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2242 GstStructure *structure;
2244 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2245 g_return_if_fail (filter != NULL);
2247 structure = GST_QUERY_STRUCTURE (query);
2248 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2249 GST_QUARK (FILTER)));
2253 * gst_query_set_caps_result:
2254 * @query: The query to use
2255 * @caps: (in): A pointer to the caps
2257 * Set the @caps result in @query.
2260 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2262 GstStructure *structure;
2264 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2265 g_return_if_fail (gst_query_is_writable (query));
2267 structure = GST_QUERY_STRUCTURE (query);
2268 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2272 * gst_query_parse_caps_result:
2273 * @query: The query to parse
2274 * @caps: (out): A pointer to the caps
2276 * Get the caps result from @query. The caps remains valid as long as
2277 * @query remains valid.
2280 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2282 GstStructure *structure;
2284 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2285 g_return_if_fail (caps != NULL);
2287 structure = GST_QUERY_STRUCTURE (query);
2288 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2293 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2294 GstCapsIntersectMode mode)
2296 GstCaps *res, *caps = NULL;
2298 gst_query_parse_caps_result (query, &caps);
2299 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2300 gst_query_set_caps_result (query, res);
2301 gst_caps_unref (res);
2305 * gst_query_new_drain:
2307 * Constructs a new query object for querying the drain state.
2309 * Free-function: gst_query_unref
2311 * Returns: (transfer full): a new #GstQuery
2314 gst_query_new_drain (void)
2317 GstStructure *structure;
2319 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2320 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2326 * gst_query_new_toc:
2328 * Constructs a new query TOC query object. Use gst_query_unref()
2329 * when done with it. A TOC query is used to query the full TOC with
2330 * the UID marker for TOC extending (to insert some new entries).
2332 * Returns: A #GstQuery.
2335 gst_query_new_toc (void)
2339 query = gst_query_new (GST_QUERY_TOC, NULL);
2345 * gst_query_set_toc:
2346 * @query: a #GstQuery with query type GST_QUERY_TOC.
2347 * @toc: the GstToc to set.
2348 * @extend_uid: UID which can be used for TOC extending (may be NULL),
2349 * 0 means root TOC level.
2351 * Answer a TOC query by setting appropriate #GstToc structure.
2354 gst_query_set_toc (GstQuery * query, GstToc * toc, const gchar * extend_uid)
2356 GstStructure *structure;
2358 g_return_if_fail (query != NULL);
2359 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_TOC);
2360 g_return_if_fail (toc != NULL);
2362 structure = _gst_toc_to_structure (toc);
2364 g_return_if_fail (structure != NULL);
2366 /* that shouldn't be happen in normal usage */
2367 if (query->structure != NULL)
2368 gst_structure_free (query->structure);
2370 if (extend_uid != NULL)
2371 _gst_toc_structure_set_extend_uid (structure, extend_uid);
2373 query->structure = structure;
2374 gst_structure_set_parent_refcount (query->structure,
2375 &(query->mini_object.refcount));
2379 * gst_query_parse_toc:
2380 * @query: a #GstQuery.
2381 * @toc: (out): the storage for the received TOC (may be NULL).
2382 * @extend_uid: (out): the storage for the received extend UID marker (may be NULL),
2383 * 0 means root TOC level.
2385 * Parse a TOC query, writing the TOC into @toc as a newly
2386 * allocated #GstToc and extend UID into @extend_uid, if the respective parameters
2387 * are non-NULL. Use @extend_uid value to insert new entries into the TOC (@extend_uid will
2388 * act as root entry for newly inserted entries).
2389 * Free @toc with gst_toc_free() and @extend_uid with g_free() after usage.
2392 gst_query_parse_toc (GstQuery * query, GstToc ** toc, gchar ** extend_uid)
2394 const GstStructure *structure;
2396 g_return_if_fail (query != NULL);
2397 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_TOC);
2399 structure = gst_query_get_structure (query);
2401 g_return_if_fail (structure != NULL);
2404 *toc = _gst_toc_from_structure (structure);
2406 if (extend_uid != NULL)
2407 *extend_uid = _gst_toc_structure_get_extend_uid (structure);