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},
117 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
120 _priv_gst_query_initialize (void)
124 _gst_query_type = gst_query_get_type ();
126 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
128 for (i = 0; query_quarks[i].name; i++) {
129 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
134 * gst_query_type_get_name:
135 * @type: the query type
137 * Get a printable name for the given query type. Do not modify or free.
139 * Returns: a reference to the static name of the query.
142 gst_query_type_get_name (GstQueryType type)
146 for (i = 0; query_quarks[i].name; i++) {
147 if (type == query_quarks[i].type)
148 return query_quarks[i].name;
154 * gst_query_type_to_quark:
155 * @type: the query type
157 * Get the unique quark for the given query type.
159 * Returns: the quark associated with the query type
162 gst_query_type_to_quark (GstQueryType type)
166 for (i = 0; query_quarks[i].name; i++) {
167 if (type == query_quarks[i].type)
168 return query_quarks[i].quark;
174 * gst_query_type_get_flags:
175 * @type: a #GstQueryType
177 * Gets the #GstQueryTypeFlags associated with @type.
179 * Returns: a #GstQueryTypeFlags.
182 gst_query_type_get_flags (GstQueryType type)
184 GstQueryTypeFlags ret;
186 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
192 _gst_query_free (GstQuery * query)
196 g_return_if_fail (query != NULL);
198 s = GST_QUERY_STRUCTURE (query);
200 gst_structure_set_parent_refcount (s, NULL);
201 gst_structure_free (s);
204 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
208 _gst_query_copy (GstQuery * query)
213 s = GST_QUERY_STRUCTURE (query);
215 s = gst_structure_copy (s);
217 copy = gst_query_new_custom (query->type, s);
223 gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type)
225 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size);
227 query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy;
228 query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free;
230 GST_QUERY_TYPE (query) = type;
234 * gst_query_new_position:
235 * @format: the default #GstFormat for the new query
237 * Constructs a new query stream position query object. Use gst_query_unref()
238 * when done with it. A position query is used to query the current position
239 * of playback in the streams, in some format.
241 * Free-function: gst_query_unref
243 * Returns: (transfer full): a new #GstQuery
246 gst_query_new_position (GstFormat format)
249 GstStructure *structure;
251 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
252 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
253 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
255 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
261 * gst_query_set_position:
262 * @query: a #GstQuery with query type GST_QUERY_POSITION
263 * @format: the requested #GstFormat
264 * @cur: the position to set
266 * Answer a position query by setting the requested value in the given format.
269 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
273 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
275 s = GST_QUERY_STRUCTURE (query);
276 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
277 GST_QUARK (FORMAT))));
279 gst_structure_id_set (s,
280 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
281 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
285 * gst_query_parse_position:
286 * @query: a #GstQuery
287 * @format: (out) (allow-none): the storage for the #GstFormat of the
288 * position values (may be NULL)
289 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
291 * Parse a position query, writing the format into @format, and the position
292 * into @cur, if the respective parameters are non-NULL.
295 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
297 GstStructure *structure;
299 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
301 structure = GST_QUERY_STRUCTURE (query);
304 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
305 GST_QUARK (FORMAT)));
307 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
308 GST_QUARK (CURRENT)));
313 * gst_query_new_duration:
314 * @format: the #GstFormat for this duration query
316 * Constructs a new stream duration query object to query in the given format.
317 * Use gst_query_unref() when done with it. A duration query will give the
318 * total length of the stream.
320 * Free-function: gst_query_unref
322 * Returns: (transfer full): a new #GstQuery
325 gst_query_new_duration (GstFormat format)
328 GstStructure *structure;
330 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
331 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
332 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
334 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
340 * gst_query_set_duration:
341 * @query: a #GstQuery
342 * @format: the #GstFormat for the duration
343 * @duration: the duration of the stream
345 * Answer a duration query by setting the requested value in the given format.
348 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
352 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
354 s = GST_QUERY_STRUCTURE (query);
355 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
356 GST_QUARK (FORMAT))));
357 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
358 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
362 * gst_query_parse_duration:
363 * @query: a #GstQuery
364 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
366 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
368 * Parse a duration query answer. Write the format of the duration into @format,
369 * and the value into @duration, if the respective variables are non-NULL.
372 gst_query_parse_duration (GstQuery * query, GstFormat * format,
375 GstStructure *structure;
377 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
379 structure = GST_QUERY_STRUCTURE (query);
382 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
383 GST_QUARK (FORMAT)));
385 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
386 GST_QUARK (DURATION)));
390 * gst_query_new_latency:
392 * Constructs a new latency query object.
393 * Use gst_query_unref() when done with it. A latency query is usually performed
394 * by sinks to compensate for additional latency introduced by elements in the
397 * Free-function: gst_query_unref
399 * Returns: (transfer full): a #GstQuery
404 gst_query_new_latency (void)
407 GstStructure *structure;
409 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
410 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
411 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
412 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
414 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
420 * gst_query_set_latency:
421 * @query: a #GstQuery
422 * @live: if there is a live element upstream
423 * @min_latency: the minimal latency of the upstream elements
424 * @max_latency: the maximal latency of the upstream elements
426 * Answer a latency query by setting the requested values in the given format.
431 gst_query_set_latency (GstQuery * query, gboolean live,
432 GstClockTime min_latency, GstClockTime max_latency)
434 GstStructure *structure;
436 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
438 structure = GST_QUERY_STRUCTURE (query);
439 gst_structure_id_set (structure,
440 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
441 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
442 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
446 * gst_query_parse_latency:
447 * @query: a #GstQuery
448 * @live: (out) (allow-none): storage for live or NULL
449 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
450 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
452 * Parse a latency query answer.
457 gst_query_parse_latency (GstQuery * query, gboolean * live,
458 GstClockTime * min_latency, GstClockTime * max_latency)
460 GstStructure *structure;
462 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
464 structure = GST_QUERY_STRUCTURE (query);
467 g_value_get_boolean (gst_structure_id_get_value (structure,
470 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
471 GST_QUARK (MIN_LATENCY)));
473 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
474 GST_QUARK (MAX_LATENCY)));
478 * gst_query_new_convert:
479 * @src_format: the source #GstFormat for the new query
480 * @value: the value to convert
481 * @dest_format: the target #GstFormat
483 * Constructs a new convert query object. Use gst_query_unref()
484 * when done with it. A convert query is used to ask for a conversion between
485 * one format and another.
487 * Free-function: gst_query_unref
489 * Returns: (transfer full): a #GstQuery
492 gst_query_new_convert (GstFormat src_format, gint64 value,
493 GstFormat dest_format)
496 GstStructure *structure;
498 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
499 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
500 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
501 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
502 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
504 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
510 * gst_query_set_convert:
511 * @query: a #GstQuery
512 * @src_format: the source #GstFormat
513 * @src_value: the source value
514 * @dest_format: the destination #GstFormat
515 * @dest_value: the destination value
517 * Answer a convert query by setting the requested values.
520 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
521 GstFormat dest_format, gint64 dest_value)
523 GstStructure *structure;
525 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
527 structure = GST_QUERY_STRUCTURE (query);
528 gst_structure_id_set (structure,
529 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
530 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
531 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
532 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
536 * gst_query_parse_convert:
537 * @query: a #GstQuery
538 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
539 * source value, or NULL
540 * @src_value: (out) (allow-none): the storage for the source value, or NULL
541 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
542 * destination value, or NULL
543 * @dest_value: (out) (allow-none): the storage for the destination value,
546 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
547 * and @dest_value may be NULL, in which case that value is omitted.
550 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
551 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
553 GstStructure *structure;
555 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
557 structure = GST_QUERY_STRUCTURE (query);
560 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
561 GST_QUARK (SRC_FORMAT)));
563 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
564 GST_QUARK (SRC_VALUE)));
567 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
568 GST_QUARK (DEST_FORMAT)));
570 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
571 GST_QUARK (DEST_VALUE)));
575 * gst_query_new_segment:
576 * @format: the #GstFormat for the new query
578 * Constructs a new segment query object. Use gst_query_unref()
579 * when done with it. A segment query is used to discover information about the
580 * currently configured segment for playback.
582 * Free-function: gst_query_unref
584 * Returns: (transfer full): a new #GstQuery
587 gst_query_new_segment (GstFormat format)
590 GstStructure *structure;
592 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
593 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
594 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
595 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
596 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
598 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
604 * gst_query_set_segment:
605 * @query: a #GstQuery
606 * @rate: the rate of the segment
607 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
608 * @start_value: the start value
609 * @stop_value: the stop value
611 * Answer a segment query by setting the requested values. The normal
612 * playback segment of a pipeline is 0 to duration at the default rate of
613 * 1.0. If a seek was performed on the pipeline to play a different
614 * segment, this query will return the range specified in the last seek.
616 * @start_value and @stop_value will respectively contain the configured
617 * playback range start and stop values expressed in @format.
618 * The values are always between 0 and the duration of the media and
619 * @start_value <= @stop_value. @rate will contain the playback rate. For
620 * negative rates, playback will actually happen from @stop_value to
624 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
625 gint64 start_value, gint64 stop_value)
627 GstStructure *structure;
629 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
631 structure = GST_QUERY_STRUCTURE (query);
632 gst_structure_id_set (structure,
633 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
634 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
635 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
636 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
640 * gst_query_parse_segment:
641 * @query: a #GstQuery
642 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
643 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
645 * @start_value: (out) (allow-none): the storage for the start value, or NULL
646 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
648 * Parse a segment query answer. Any of @rate, @format, @start_value, and
649 * @stop_value may be NULL, which will cause this value to be omitted.
651 * See gst_query_set_segment() for an explanation of the function arguments.
654 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
655 gint64 * start_value, gint64 * stop_value)
657 GstStructure *structure;
659 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
661 structure = GST_QUERY_STRUCTURE (query);
663 *rate = g_value_get_double (gst_structure_id_get_value (structure,
667 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
668 GST_QUARK (FORMAT)));
670 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
671 GST_QUARK (START_VALUE)));
673 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
674 GST_QUARK (STOP_VALUE)));
678 * gst_query_new_custom:
679 * @type: the query type
680 * @structure: a structure for the query
682 * Constructs a new custom query object. Use gst_query_unref()
685 * Free-function: gst_query_unref
687 * Returns: (transfer full): a new #GstQuery
690 gst_query_new_custom (GstQueryType type, GstStructure * structure)
694 query = g_slice_new0 (GstQueryImpl);
696 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
699 /* structure must not have a parent */
700 if (!gst_structure_set_parent_refcount (structure,
701 &query->query.mini_object.refcount))
704 gst_query_init (query, sizeof (GstQueryImpl), type);
706 GST_QUERY_STRUCTURE (query) = structure;
708 return GST_QUERY_CAST (query);
713 g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
714 g_warning ("structure is already owned by another object");
720 * gst_query_get_structure:
721 * @query: a #GstQuery
723 * Get the structure of a query.
725 * Returns: (transfer none): the #GstStructure of the query. The structure is
726 * still owned by the query and will therefore be freed when the query
730 gst_query_get_structure (GstQuery * query)
732 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
734 return GST_QUERY_STRUCTURE (query);
738 * gst_query_writable_structure:
739 * @query: a #GstQuery
741 * Get the structure of a query. This method should be called with a writable
742 * @query so that the returned structure is guranteed to be writable.
744 * Returns: (transfer none): the #GstStructure of the query. The structure is
745 * still owned by the query and will therefore be freed when the query
749 gst_query_writable_structure (GstQuery * query)
751 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
752 g_return_val_if_fail (gst_query_is_writable (query), NULL);
754 return GST_QUERY_STRUCTURE (query);
758 * gst_query_new_seeking:
759 * @format: the default #GstFormat for the new query
761 * Constructs a new query object for querying seeking properties of
764 * Free-function: gst_query_unref
766 * Returns: (transfer full): a new #GstQuery
769 gst_query_new_seeking (GstFormat format)
772 GstStructure *structure;
774 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
775 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
776 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
777 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
778 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
780 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
786 * gst_query_set_seeking:
787 * @query: a #GstQuery
788 * @format: the format to set for the @segment_start and @segment_end values
789 * @seekable: the seekable flag to set
790 * @segment_start: the segment_start to set
791 * @segment_end: the segment_end to set
793 * Set the seeking query result fields in @query.
796 gst_query_set_seeking (GstQuery * query, GstFormat format,
797 gboolean seekable, gint64 segment_start, gint64 segment_end)
799 GstStructure *structure;
801 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
802 g_return_if_fail (gst_query_is_writable (query));
804 structure = GST_QUERY_STRUCTURE (query);
805 gst_structure_id_set (structure,
806 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
807 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
808 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
809 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
813 * gst_query_parse_seeking:
814 * @query: a GST_QUERY_SEEKING type query #GstQuery
815 * @format: (out) (allow-none): the format to set for the @segment_start
816 * and @segment_end values, or NULL
817 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
818 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
819 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
821 * Parse a seeking query, writing the format into @format, and
822 * other results into the passed parameters, if the respective parameters
826 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
827 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
829 GstStructure *structure;
831 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
833 structure = GST_QUERY_STRUCTURE (query);
836 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
837 GST_QUARK (FORMAT)));
839 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
840 GST_QUARK (SEEKABLE)));
842 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
843 GST_QUARK (SEGMENT_START)));
845 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
846 GST_QUARK (SEGMENT_END)));
850 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
851 GDestroyNotify clear_func)
856 value = gst_structure_id_get_value (s, quark);
858 array = (GArray *) g_value_get_boxed (value);
860 GValue new_array_val = { 0, };
862 array = g_array_new (FALSE, TRUE, element_size);
864 g_array_set_clear_func (array, clear_func);
866 g_value_init (&new_array_val, G_TYPE_ARRAY);
867 g_value_take_boxed (&new_array_val, array);
869 gst_structure_id_take_value (s, quark, &new_array_val);
875 * gst_query_new_formats:
877 * Constructs a new query object for querying formats of
880 * Free-function: gst_query_unref
882 * Returns: (transfer full): a new #GstQuery
887 gst_query_new_formats (void)
890 GstStructure *structure;
892 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
893 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
899 gst_query_list_add_format (GValue * list, GstFormat format)
901 GValue item = { 0, };
903 g_value_init (&item, GST_TYPE_FORMAT);
904 g_value_set_enum (&item, format);
905 gst_value_list_append_value (list, &item);
906 g_value_unset (&item);
910 * gst_query_set_formats:
911 * @query: a #GstQuery
912 * @n_formats: the number of formats to set.
913 * @...: A number of @GstFormats equal to @n_formats.
915 * Set the formats query result fields in @query. The number of formats passed
916 * must be equal to @n_formats.
919 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
922 GValue list = { 0, };
924 GstStructure *structure;
926 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
927 g_return_if_fail (gst_query_is_writable (query));
929 g_value_init (&list, GST_TYPE_LIST);
931 va_start (ap, n_formats);
932 for (i = 0; i < n_formats; i++) {
933 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
937 structure = GST_QUERY_STRUCTURE (query);
938 gst_structure_set_value (structure, "formats", &list);
940 g_value_unset (&list);
945 * gst_query_set_formatsv:
946 * @query: a #GstQuery
947 * @n_formats: the number of formats to set.
948 * @formats: (in) (array length=n_formats): an array containing @n_formats
951 * Set the formats query result fields in @query. The number of formats passed
952 * in the @formats array must be equal to @n_formats.
957 gst_query_set_formatsv (GstQuery * query, gint n_formats,
958 const GstFormat * formats)
960 GValue list = { 0, };
962 GstStructure *structure;
964 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
965 g_return_if_fail (gst_query_is_writable (query));
967 g_value_init (&list, GST_TYPE_LIST);
968 for (i = 0; i < n_formats; i++) {
969 gst_query_list_add_format (&list, formats[i]);
971 structure = GST_QUERY_STRUCTURE (query);
972 gst_structure_set_value (structure, "formats", &list);
974 g_value_unset (&list);
978 * gst_query_parse_n_formats:
979 * @query: a #GstQuery
980 * @n_formats: (out) (allow-none): the number of formats in this query.
982 * Parse the number of formats in the formats @query.
987 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
989 GstStructure *structure;
991 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
996 structure = GST_QUERY_STRUCTURE (query);
997 list = gst_structure_get_value (structure, "formats");
1001 *n_formats = gst_value_list_get_size (list);
1006 * gst_query_parse_nth_format:
1007 * @query: a #GstQuery
1008 * @nth: (out): the nth format to retrieve.
1009 * @format: (out) (allow-none): a pointer to store the nth format
1011 * Parse the format query and retrieve the @nth format from it into
1012 * @format. If the list contains less elements than @nth, @format will be
1013 * set to GST_FORMAT_UNDEFINED.
1016 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1018 GstStructure *structure;
1020 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1025 structure = GST_QUERY_STRUCTURE (query);
1026 list = gst_structure_get_value (structure, "formats");
1028 *format = GST_FORMAT_UNDEFINED;
1030 if (nth < gst_value_list_get_size (list)) {
1032 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1034 *format = GST_FORMAT_UNDEFINED;
1040 * gst_query_new_buffering:
1041 * @format: the default #GstFormat for the new query
1043 * Constructs a new query object for querying the buffering status of
1046 * Free-function: gst_query_unref
1048 * Returns: (transfer full): a new #GstQuery
1053 gst_query_new_buffering (GstFormat format)
1056 GstStructure *structure;
1058 /* by default, we configure the answer as no buffering with a 100% buffering
1060 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1061 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1062 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1063 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1064 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1065 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1066 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1067 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1068 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1069 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1070 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1072 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1078 * gst_query_set_buffering_percent:
1079 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1080 * @busy: if buffering is busy
1081 * @percent: a buffering percent
1083 * Set the percentage of buffered data. This is a value between 0 and 100.
1084 * The @busy indicator is %TRUE when the buffering is in progress.
1089 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1091 GstStructure *structure;
1093 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1094 g_return_if_fail (gst_query_is_writable (query));
1095 g_return_if_fail (percent >= 0 && percent <= 100);
1097 structure = GST_QUERY_STRUCTURE (query);
1098 gst_structure_id_set (structure,
1099 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1100 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1104 * gst_query_parse_buffering_percent:
1105 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1106 * @busy: (out) (allow-none): if buffering is busy, or NULL
1107 * @percent: (out) (allow-none): a buffering percent, or NULL
1109 * Get the percentage of buffered data. This is a value between 0 and 100.
1110 * The @busy indicator is %TRUE when the buffering is in progress.
1115 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1118 GstStructure *structure;
1120 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1122 structure = GST_QUERY_STRUCTURE (query);
1124 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1127 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1128 GST_QUARK (BUFFER_PERCENT)));
1132 * gst_query_set_buffering_stats:
1133 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1134 * @mode: a buffering mode
1135 * @avg_in: the average input rate
1136 * @avg_out: the average output rate
1137 * @buffering_left: amount of buffering time left
1139 * Configures the buffering stats values in @query.
1144 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1145 gint avg_in, gint avg_out, gint64 buffering_left)
1147 GstStructure *structure;
1149 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1150 g_return_if_fail (gst_query_is_writable (query));
1152 structure = GST_QUERY_STRUCTURE (query);
1153 gst_structure_id_set (structure,
1154 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1155 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1156 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1157 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1161 * gst_query_parse_buffering_stats:
1162 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1163 * @mode: (out) (allow-none): a buffering mode, or NULL
1164 * @avg_in: (out) (allow-none): the average input rate, or NULL
1165 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1166 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1168 * Extracts the buffering stats values from @query.
1173 gst_query_parse_buffering_stats (GstQuery * query,
1174 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1175 gint64 * buffering_left)
1177 GstStructure *structure;
1179 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1181 structure = GST_QUERY_STRUCTURE (query);
1183 *mode = (GstBufferingMode)
1184 g_value_get_enum (gst_structure_id_get_value (structure,
1185 GST_QUARK (BUFFERING_MODE)));
1187 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1188 GST_QUARK (AVG_IN_RATE)));
1190 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1191 GST_QUARK (AVG_OUT_RATE)));
1194 g_value_get_int64 (gst_structure_id_get_value (structure,
1195 GST_QUARK (BUFFERING_LEFT)));
1199 * gst_query_set_buffering_range:
1200 * @query: a #GstQuery
1201 * @format: the format to set for the @start and @stop values
1202 * @start: the start to set
1203 * @stop: the stop to set
1204 * @estimated_total: estimated total amount of download time
1206 * Set the available query result fields in @query.
1211 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1212 gint64 start, gint64 stop, gint64 estimated_total)
1214 GstStructure *structure;
1216 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1217 g_return_if_fail (gst_query_is_writable (query));
1219 structure = GST_QUERY_STRUCTURE (query);
1220 gst_structure_id_set (structure,
1221 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1222 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1223 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1224 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1228 * gst_query_parse_buffering_range:
1229 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1230 * @format: (out) (allow-none): the format to set for the @segment_start
1231 * and @segment_end values, or NULL
1232 * @start: (out) (allow-none): the start to set, or NULL
1233 * @stop: (out) (allow-none): the stop to set, or NULL
1234 * @estimated_total: (out) (allow-none): estimated total amount of download
1237 * Parse an available query, writing the format into @format, and
1238 * other results into the passed parameters, if the respective parameters
1244 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1245 gint64 * start, gint64 * stop, gint64 * estimated_total)
1247 GstStructure *structure;
1249 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1251 structure = GST_QUERY_STRUCTURE (query);
1254 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1255 GST_QUARK (FORMAT)));
1257 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1258 GST_QUARK (START_VALUE)));
1260 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1261 GST_QUARK (STOP_VALUE)));
1262 if (estimated_total)
1264 g_value_get_int64 (gst_structure_id_get_value (structure,
1265 GST_QUARK (ESTIMATED_TOTAL)));
1268 /* GstQueryBufferingRange: internal struct for GArray */
1273 } GstQueryBufferingRange;
1276 * gst_query_add_buffering_range:
1277 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1278 * @start: start position of the range
1279 * @stop: stop position of the range
1281 * Set the buffering-ranges array field in @query. The current last
1282 * start position of the array should be inferior to @start.
1284 * Returns: a #gboolean indicating if the range was added or not.
1289 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1291 GstQueryBufferingRange range;
1292 GstStructure *structure;
1295 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1296 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1298 if (G_UNLIKELY (start >= stop))
1301 structure = GST_QUERY_STRUCTURE (query);
1302 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1303 sizeof (GstQueryBufferingRange), NULL);
1305 if (array->len > 1) {
1306 GstQueryBufferingRange *last;
1308 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1310 if (G_UNLIKELY (start <= last->start))
1314 range.start = start;
1316 g_array_append_val (array, range);
1322 * gst_query_get_n_buffering_ranges:
1323 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1325 * Retrieve the number of values currently stored in the
1326 * buffered-ranges array of the query's structure.
1328 * Returns: the range array size as a #guint.
1333 gst_query_get_n_buffering_ranges (GstQuery * query)
1335 GstStructure *structure;
1338 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1340 structure = GST_QUERY_STRUCTURE (query);
1341 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1342 sizeof (GstQueryBufferingRange), NULL);
1349 * gst_query_parse_nth_buffering_range:
1350 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1351 * @index: position in the buffered-ranges array to read
1352 * @start: (out) (allow-none): the start position to set, or NULL
1353 * @stop: (out) (allow-none): the stop position to set, or NULL
1355 * Parse an available query and get the start and stop values stored
1356 * at the @index of the buffered ranges array.
1358 * Returns: a #gboolean indicating if the parsing succeeded.
1363 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1364 gint64 * start, gint64 * stop)
1366 GstQueryBufferingRange *range;
1367 GstStructure *structure;
1370 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1372 structure = GST_QUERY_STRUCTURE (query);
1374 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1375 sizeof (GstQueryBufferingRange), NULL);
1376 g_return_val_if_fail (index < array->len, FALSE);
1378 range = &g_array_index (array, GstQueryBufferingRange, index);
1381 *start = range->start;
1383 *stop = range->stop;
1390 * gst_query_new_uri:
1392 * Constructs a new query URI query object. Use gst_query_unref()
1393 * when done with it. An URI query is used to query the current URI
1394 * that is used by the source or sink.
1396 * Free-function: gst_query_unref
1398 * Returns: (transfer full): a new #GstQuery
1403 gst_query_new_uri (void)
1406 GstStructure *structure;
1408 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1409 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1411 query = gst_query_new_custom (GST_QUERY_URI, structure);
1417 * gst_query_set_uri:
1418 * @query: a #GstQuery with query type GST_QUERY_URI
1419 * @uri: the URI to set
1421 * Answer a URI query by setting the requested URI.
1426 gst_query_set_uri (GstQuery * query, const gchar * uri)
1428 GstStructure *structure;
1430 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1431 g_return_if_fail (gst_query_is_writable (query));
1432 g_return_if_fail (gst_uri_is_valid (uri));
1434 structure = GST_QUERY_STRUCTURE (query);
1435 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1439 * gst_query_parse_uri:
1440 * @query: a #GstQuery
1441 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1444 * Parse an URI query, writing the URI into @uri as a newly
1445 * allocated string, if the respective parameters are non-NULL.
1446 * Free the string with g_free() after usage.
1451 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1453 GstStructure *structure;
1455 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1457 structure = GST_QUERY_STRUCTURE (query);
1459 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1464 * gst_query_new_allocation:
1465 * @caps: the negotiated caps
1466 * @need_pool: return a pool
1468 * Constructs a new query object for querying the allocation properties.
1470 * Free-function: gst_query_unref
1472 * Returns: (transfer full): a new #GstQuery
1475 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1478 GstStructure *structure;
1480 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1481 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1482 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1484 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1490 * gst_query_parse_allocation:
1491 * @query: a #GstQuery
1492 * @caps: (out transfer none) (allow-none): The #GstCaps
1493 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1495 * Parse an allocation query, writing the requested caps in @caps and
1496 * whether a pool is needed in @need_pool, if the respective parameters
1500 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1501 gboolean * need_pool)
1503 GstStructure *structure;
1505 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1507 structure = GST_QUERY_STRUCTURE (query);
1509 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1512 gst_structure_id_get (structure,
1513 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1518 GstBufferPool *pool;
1525 allocation_pool_free (AllocationPool * ap)
1528 gst_object_unref (ap->pool);
1532 * gst_query_add_allocation_pool:
1533 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1534 * @pool: the #GstBufferPool
1536 * @min_buffers: the min buffers
1537 * @max_buffers: the max buffers
1539 * Set the pool parameters in @query.
1542 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1543 guint size, guint min_buffers, guint max_buffers)
1546 GstStructure *structure;
1549 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1550 g_return_if_fail (gst_query_is_writable (query));
1551 g_return_if_fail (size != 0);
1553 structure = GST_QUERY_STRUCTURE (query);
1554 array = ensure_array (structure, GST_QUARK (POOL),
1555 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1557 if ((ap.pool = pool))
1558 gst_object_ref (pool);
1560 ap.min_buffers = min_buffers;
1561 ap.max_buffers = max_buffers;
1563 g_array_append_val (array, ap);
1568 * gst_query_get_n_allocation_pools:
1569 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1571 * Retrieve the number of values currently stored in the
1572 * pool array of the query's structure.
1574 * Returns: the pool array size as a #guint.
1577 gst_query_get_n_allocation_pools (GstQuery * query)
1580 GstStructure *structure;
1582 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1584 structure = GST_QUERY_STRUCTURE (query);
1585 array = ensure_array (structure, GST_QUARK (POOL),
1586 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1592 * gst_query_parse_nth_allocation_pool:
1593 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1594 * @index: index to parse
1595 * @pool: (out) (allow-none) (transfer none): the #GstBufferPool
1596 * @size: (out) (allow-none): the size
1597 * @min_buffers: (out) (allow-none): the min buffers
1598 * @max_buffers: (out) (allow-none): the max buffers
1600 * Get the pool parameters in @query.
1603 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1604 GstBufferPool ** pool, guint * size, guint * min_buffers,
1605 guint * max_buffers)
1608 GstStructure *structure;
1611 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1613 structure = GST_QUERY_STRUCTURE (query);
1614 array = ensure_array (structure, GST_QUARK (POOL),
1615 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1616 g_return_if_fail (index < array->len);
1618 ap = &g_array_index (array, AllocationPool, index);
1621 if ((*pool = ap->pool))
1622 gst_object_ref (*pool);
1626 *min_buffers = ap->min_buffers;
1628 *max_buffers = ap->max_buffers;
1632 * gst_query_set_nth_allocation_pool:
1633 * @index: index to modify
1634 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1635 * @pool: the #GstBufferPool
1637 * @min_buffers: the min buffers
1638 * @max_buffers: the max buffers
1640 * Set the pool parameters in @query.
1643 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1644 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1647 GstStructure *structure;
1648 AllocationPool *oldap, ap;
1650 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1652 structure = GST_QUERY_STRUCTURE (query);
1653 array = ensure_array (structure, GST_QUARK (POOL),
1654 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1655 g_return_if_fail (index < array->len);
1657 oldap = &g_array_index (array, AllocationPool, index);
1658 allocation_pool_free (oldap);
1660 if ((ap.pool = pool))
1661 gst_object_ref (pool);
1663 ap.min_buffers = min_buffers;
1664 ap.max_buffers = max_buffers;
1665 g_array_index (array, AllocationPool, index) = ap;
1669 * gst_query_add_allocation_meta:
1670 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1671 * @api: the metadata API
1673 * Add @api as aone of the supported metadata API to @query.
1676 gst_query_add_allocation_meta (GstQuery * query, GType api)
1679 GstStructure *structure;
1681 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1682 g_return_if_fail (api != 0);
1683 g_return_if_fail (gst_query_is_writable (query));
1685 structure = GST_QUERY_STRUCTURE (query);
1686 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1688 g_array_append_val (array, api);
1692 * gst_query_get_n_allocation_metas:
1693 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1695 * Retrieve the number of values currently stored in the
1696 * meta API array of the query's structure.
1698 * Returns: the metadata API array size as a #guint.
1701 gst_query_get_n_allocation_metas (GstQuery * query)
1704 GstStructure *structure;
1706 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1708 structure = GST_QUERY_STRUCTURE (query);
1709 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1715 * gst_query_parse_nth_allocation_meta:
1716 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1717 * @index: position in the metadata API array to read
1719 * Parse an available query and get the metadata API
1720 * at @index of the metadata API array.
1722 * Returns: a #GType of the metadata API at @index.
1725 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index)
1728 GstStructure *structure;
1730 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1732 structure = GST_QUERY_STRUCTURE (query);
1733 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1735 g_return_val_if_fail (index < array->len, 0);
1737 return g_array_index (array, GType, index);
1741 * gst_query_remove_nth_allocation_meta:
1742 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1743 * @index: position in the metadata API array to remove
1745 * Remove the metadata API at @index of the metadata API array.
1748 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1751 GstStructure *structure;
1753 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1754 g_return_if_fail (gst_query_is_writable (query));
1756 structure = GST_QUERY_STRUCTURE (query);
1757 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1758 g_return_if_fail (index < array->len);
1760 g_array_remove_index (array, index);
1764 * gst_query_has_allocation_meta:
1765 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1766 * @api: the metadata API
1768 * Check if @query has metadata @api set.
1770 * Returns: TRUE when @api is in the list of metadata.
1773 gst_query_has_allocation_meta (GstQuery * query, GType api)
1776 GstStructure *structure;
1779 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1780 g_return_val_if_fail (api != 0, FALSE);
1782 structure = GST_QUERY_STRUCTURE (query);
1783 array = ensure_array (structure, GST_QUARK (META), sizeof (GType), NULL);
1786 for (i = 0; i < len; i++) {
1787 if (g_array_index (array, GType, i) == api)
1795 GstAllocator *allocator;
1796 GstAllocationParams params;
1800 allocation_param_free (AllocationParam * ap)
1803 gst_allocator_unref (ap->allocator);
1807 * gst_query_add_allocation_param:
1808 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1809 * @allocator: the memory allocator
1810 * @params: a #GstAllocationParams
1812 * Add @allocator and its @params as a supported memory allocator.
1815 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1816 const GstAllocationParams * params)
1819 GstStructure *structure;
1822 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1823 g_return_if_fail (gst_query_is_writable (query));
1824 g_return_if_fail (allocator != NULL || params != NULL);
1826 structure = GST_QUERY_STRUCTURE (query);
1827 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1828 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1830 if ((ap.allocator = allocator))
1831 gst_allocator_ref (allocator);
1833 ap.params = *params;
1835 gst_allocation_params_init (&ap.params);
1837 g_array_append_val (array, ap);
1841 * gst_query_get_n_allocation_params:
1842 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1844 * Retrieve the number of values currently stored in the
1845 * allocator params array of the query's structure.
1847 * If no memory allocator is specified, the downstream element can handle
1848 * the default memory allocator.
1850 * Returns: the allocator array size as a #guint.
1853 gst_query_get_n_allocation_params (GstQuery * query)
1856 GstStructure *structure;
1858 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1860 structure = GST_QUERY_STRUCTURE (query);
1861 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1862 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1868 * gst_query_parse_nth_allocation_param:
1869 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1870 * @index: position in the allocator array to read
1871 * @allocator: (transfer none): variable to hold the result
1872 * @params: parameters for the allocator
1874 * Parse an available query and get the alloctor and its params
1875 * at @index of the allocator array.
1878 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
1879 GstAllocator ** allocator, GstAllocationParams * params)
1882 GstStructure *structure;
1883 AllocationParam *ap;
1885 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1887 structure = GST_QUERY_STRUCTURE (query);
1888 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1889 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1890 g_return_if_fail (index < array->len);
1892 ap = &g_array_index (array, AllocationParam, index);
1895 if ((*allocator = ap->allocator))
1896 gst_allocator_ref (*allocator);
1898 *params = ap->params;
1902 * gst_query_set_nth_allocation_param:
1903 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1904 * @index: position in the allocator array to set
1905 * @allocator: (transfer full): new allocator to set
1906 * @params: parameters for the allocator
1908 * Parse an available query and get the alloctor and its params
1909 * at @index of the allocator array.
1912 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
1913 GstAllocator * allocator, const GstAllocationParams * params)
1916 GstStructure *structure;
1917 AllocationParam *old, ap;
1919 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1921 structure = GST_QUERY_STRUCTURE (query);
1922 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1923 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1924 g_return_if_fail (index < array->len);
1926 old = &g_array_index (array, AllocationParam, index);
1927 allocation_param_free (old);
1929 if ((ap.allocator = allocator))
1930 gst_allocator_ref (allocator);
1932 ap.params = *params;
1934 gst_allocation_params_init (&ap.params);
1936 g_array_index (array, AllocationParam, index) = ap;
1940 * gst_query_new_scheduling:
1942 * Constructs a new query object for querying the scheduling properties.
1944 * Free-function: gst_query_unref
1946 * Returns: (transfer full): a new #GstQuery
1949 gst_query_new_scheduling (void)
1952 GstStructure *structure;
1954 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1955 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1956 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1957 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1958 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1959 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
1965 * gst_query_set_scheduling:
1966 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1967 * @flags: #GstSchedulingFlags
1968 * @minsize: the suggested minimum size of pull requests
1969 * @maxsize: the suggested maximum size of pull requests
1970 * @align: the suggested alignment of pull requests
1972 * Set the scheduling properties.
1975 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
1976 gint minsize, gint maxsize, gint align)
1978 GstStructure *structure;
1980 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
1981 g_return_if_fail (gst_query_is_writable (query));
1983 structure = GST_QUERY_STRUCTURE (query);
1984 gst_structure_id_set (structure,
1985 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
1986 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
1987 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
1988 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
1992 * gst_query_parse_scheduling:
1993 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
1994 * @flags: (out) (allow-none): #GstSchedulingFlags
1995 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
1996 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
1997 * @align: (out) (allow-none): the suggested alignment of pull requests
1999 * Set the scheduling properties.
2002 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2003 gint * minsize, gint * maxsize, gint * align)
2005 GstStructure *structure;
2007 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2009 structure = GST_QUERY_STRUCTURE (query);
2010 gst_structure_id_get (structure,
2011 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2012 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2013 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2014 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2018 * gst_query_add_scheduling_mode:
2019 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2020 * @mode: a #GstPadMode
2022 * Add @mode as aone of the supported scheduling modes to @query.
2025 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2027 GstStructure *structure;
2030 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2031 g_return_if_fail (gst_query_is_writable (query));
2033 structure = GST_QUERY_STRUCTURE (query);
2035 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2037 g_array_append_val (array, mode);
2041 * gst_query_get_n_scheduling_modes:
2042 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2044 * Retrieve the number of values currently stored in the
2045 * scheduling mode array of the query's structure.
2047 * Returns: the scheduling mode array size as a #guint.
2050 gst_query_get_n_scheduling_modes (GstQuery * query)
2053 GstStructure *structure;
2055 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2057 structure = GST_QUERY_STRUCTURE (query);
2059 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2065 * gst_query_parse_nth_scheduling_mode:
2066 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2067 * @index: position in the scheduling modes array to read
2069 * Parse an available query and get the scheduling mode
2070 * at @index of the scheduling modes array.
2072 * Returns: a #GstPadMode of the scheduling mode at @index.
2075 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2077 GstStructure *structure;
2080 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2083 structure = GST_QUERY_STRUCTURE (query);
2085 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2086 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2088 return g_array_index (array, GstPadMode, index);
2092 * gst_query_has_scheduling_mode:
2093 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2094 * @mode: the scheduling mode
2096 * Check if @query has scheduling mode set.
2098 * Returns: TRUE when @mode is in the list of scheduling modes.
2101 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2103 GstStructure *structure;
2107 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2109 structure = GST_QUERY_STRUCTURE (query);
2111 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2114 for (i = 0; i < len; i++) {
2115 if (mode == g_array_index (array, GstPadMode, i))
2122 * gst_query_new_accept_caps:
2123 * @caps: a fixed #GstCaps
2125 * Constructs a new query object for querying if @caps are accepted.
2127 * Free-function: gst_query_unref
2129 * Returns: (transfer full): a new #GstQuery
2132 gst_query_new_accept_caps (GstCaps * caps)
2135 GstStructure *structure;
2137 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
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);