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 (sizeof (GstQueryImpl), 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_new_position:
224 * @format: the default #GstFormat for the new query
226 * Constructs a new query stream position query object. Use gst_query_unref()
227 * when done with it. A position query is used to query the current position
228 * of playback in the streams, in some format.
230 * Free-function: gst_query_unref
232 * Returns: (transfer full): a new #GstQuery
235 gst_query_new_position (GstFormat format)
238 GstStructure *structure;
240 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
241 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
242 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
244 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
250 * gst_query_set_position:
251 * @query: a #GstQuery with query type GST_QUERY_POSITION
252 * @format: the requested #GstFormat
253 * @cur: the position to set
255 * Answer a position query by setting the requested value in the given format.
258 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
262 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
264 s = GST_QUERY_STRUCTURE (query);
265 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
266 GST_QUARK (FORMAT))));
268 gst_structure_id_set (s,
269 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
270 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
274 * gst_query_parse_position:
275 * @query: a #GstQuery
276 * @format: (out) (allow-none): the storage for the #GstFormat of the
277 * position values (may be NULL)
278 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
280 * Parse a position query, writing the format into @format, and the position
281 * into @cur, if the respective parameters are non-NULL.
284 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
286 GstStructure *structure;
288 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
290 structure = GST_QUERY_STRUCTURE (query);
293 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
294 GST_QUARK (FORMAT)));
296 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
297 GST_QUARK (CURRENT)));
302 * gst_query_new_duration:
303 * @format: the #GstFormat for this duration query
305 * Constructs a new stream duration query object to query in the given format.
306 * Use gst_query_unref() when done with it. A duration query will give the
307 * total length of the stream.
309 * Free-function: gst_query_unref
311 * Returns: (transfer full): a new #GstQuery
314 gst_query_new_duration (GstFormat format)
317 GstStructure *structure;
319 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
320 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
321 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
323 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
329 * gst_query_set_duration:
330 * @query: a #GstQuery
331 * @format: the #GstFormat for the duration
332 * @duration: the duration of the stream
334 * Answer a duration query by setting the requested value in the given format.
337 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
341 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
343 s = GST_QUERY_STRUCTURE (query);
344 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
345 GST_QUARK (FORMAT))));
346 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
347 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
351 * gst_query_parse_duration:
352 * @query: a #GstQuery
353 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
355 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
357 * Parse a duration query answer. Write the format of the duration into @format,
358 * and the value into @duration, if the respective variables are non-NULL.
361 gst_query_parse_duration (GstQuery * query, GstFormat * format,
364 GstStructure *structure;
366 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
368 structure = GST_QUERY_STRUCTURE (query);
371 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
372 GST_QUARK (FORMAT)));
374 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
375 GST_QUARK (DURATION)));
379 * gst_query_new_latency:
381 * Constructs a new latency query object.
382 * Use gst_query_unref() when done with it. A latency query is usually performed
383 * by sinks to compensate for additional latency introduced by elements in the
386 * Free-function: gst_query_unref
388 * Returns: (transfer full): a #GstQuery
393 gst_query_new_latency (void)
396 GstStructure *structure;
398 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
399 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
400 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
401 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
403 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
409 * gst_query_set_latency:
410 * @query: a #GstQuery
411 * @live: if there is a live element upstream
412 * @min_latency: the minimal latency of the upstream elements
413 * @max_latency: the maximal latency of the upstream elements
415 * Answer a latency query by setting the requested values in the given format.
420 gst_query_set_latency (GstQuery * query, gboolean live,
421 GstClockTime min_latency, GstClockTime max_latency)
423 GstStructure *structure;
425 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
427 structure = GST_QUERY_STRUCTURE (query);
428 gst_structure_id_set (structure,
429 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
430 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
431 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
435 * gst_query_parse_latency:
436 * @query: a #GstQuery
437 * @live: (out) (allow-none): storage for live or NULL
438 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
439 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
441 * Parse a latency query answer.
446 gst_query_parse_latency (GstQuery * query, gboolean * live,
447 GstClockTime * min_latency, GstClockTime * max_latency)
449 GstStructure *structure;
451 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
453 structure = GST_QUERY_STRUCTURE (query);
456 g_value_get_boolean (gst_structure_id_get_value (structure,
459 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
460 GST_QUARK (MIN_LATENCY)));
462 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
463 GST_QUARK (MAX_LATENCY)));
467 * gst_query_new_convert:
468 * @src_format: the source #GstFormat for the new query
469 * @value: the value to convert
470 * @dest_format: the target #GstFormat
472 * Constructs a new convert query object. Use gst_query_unref()
473 * when done with it. A convert query is used to ask for a conversion between
474 * one format and another.
476 * Free-function: gst_query_unref
478 * Returns: (transfer full): a #GstQuery
481 gst_query_new_convert (GstFormat src_format, gint64 value,
482 GstFormat dest_format)
485 GstStructure *structure;
487 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
488 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
489 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
490 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
491 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
493 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
499 * gst_query_set_convert:
500 * @query: a #GstQuery
501 * @src_format: the source #GstFormat
502 * @src_value: the source value
503 * @dest_format: the destination #GstFormat
504 * @dest_value: the destination value
506 * Answer a convert query by setting the requested values.
509 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
510 GstFormat dest_format, gint64 dest_value)
512 GstStructure *structure;
514 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
516 structure = GST_QUERY_STRUCTURE (query);
517 gst_structure_id_set (structure,
518 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
519 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
520 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
521 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
525 * gst_query_parse_convert:
526 * @query: a #GstQuery
527 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
528 * source value, or NULL
529 * @src_value: (out) (allow-none): the storage for the source value, or NULL
530 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
531 * destination value, or NULL
532 * @dest_value: (out) (allow-none): the storage for the destination value,
535 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
536 * and @dest_value may be NULL, in which case that value is omitted.
539 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
540 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
542 GstStructure *structure;
544 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
546 structure = GST_QUERY_STRUCTURE (query);
549 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
550 GST_QUARK (SRC_FORMAT)));
552 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
553 GST_QUARK (SRC_VALUE)));
556 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
557 GST_QUARK (DEST_FORMAT)));
559 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
560 GST_QUARK (DEST_VALUE)));
564 * gst_query_new_segment:
565 * @format: the #GstFormat for the new query
567 * Constructs a new segment query object. Use gst_query_unref()
568 * when done with it. A segment query is used to discover information about the
569 * currently configured segment for playback.
571 * Free-function: gst_query_unref
573 * Returns: (transfer full): a new #GstQuery
576 gst_query_new_segment (GstFormat format)
579 GstStructure *structure;
581 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
582 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
583 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
584 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
585 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
587 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
593 * gst_query_set_segment:
594 * @query: a #GstQuery
595 * @rate: the rate of the segment
596 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
597 * @start_value: the start value
598 * @stop_value: the stop value
600 * Answer a segment query by setting the requested values. The normal
601 * playback segment of a pipeline is 0 to duration at the default rate of
602 * 1.0. If a seek was performed on the pipeline to play a different
603 * segment, this query will return the range specified in the last seek.
605 * @start_value and @stop_value will respectively contain the configured
606 * playback range start and stop values expressed in @format.
607 * The values are always between 0 and the duration of the media and
608 * @start_value <= @stop_value. @rate will contain the playback rate. For
609 * negative rates, playback will actually happen from @stop_value to
613 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
614 gint64 start_value, gint64 stop_value)
616 GstStructure *structure;
618 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
620 structure = GST_QUERY_STRUCTURE (query);
621 gst_structure_id_set (structure,
622 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
623 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
624 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
625 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
629 * gst_query_parse_segment:
630 * @query: a #GstQuery
631 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
632 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
634 * @start_value: (out) (allow-none): the storage for the start value, or NULL
635 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
637 * Parse a segment query answer. Any of @rate, @format, @start_value, and
638 * @stop_value may be NULL, which will cause this value to be omitted.
640 * See gst_query_set_segment() for an explanation of the function arguments.
643 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
644 gint64 * start_value, gint64 * stop_value)
646 GstStructure *structure;
648 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
650 structure = GST_QUERY_STRUCTURE (query);
652 *rate = g_value_get_double (gst_structure_id_get_value (structure,
656 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
657 GST_QUARK (FORMAT)));
659 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
660 GST_QUARK (START_VALUE)));
662 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
663 GST_QUARK (STOP_VALUE)));
667 * gst_query_new_custom:
668 * @type: the query type
669 * @structure: a structure for the query
671 * Constructs a new custom query object. Use gst_query_unref()
674 * Free-function: gst_query_unref
676 * Returns: (transfer full): a new #GstQuery
679 gst_query_new_custom (GstQueryType type, GstStructure * structure)
683 query = g_slice_new0 (GstQueryImpl);
685 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
688 /* structure must not have a parent */
689 if (!gst_structure_set_parent_refcount (structure,
690 &query->query.mini_object.refcount))
694 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
695 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
696 (GstMiniObjectFreeFunction) _gst_query_free);
698 GST_QUERY_TYPE (query) = type;
699 GST_QUERY_STRUCTURE (query) = structure;
701 return GST_QUERY_CAST (query);
706 g_slice_free1 (sizeof (GstQueryImpl), query);
707 g_warning ("structure is already owned by another object");
713 * gst_query_get_structure:
714 * @query: a #GstQuery
716 * Get the structure of a query.
718 * Returns: (transfer none): the #GstStructure of the query. The structure is
719 * still owned by the query and will therefore be freed when the query
723 gst_query_get_structure (GstQuery * query)
725 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
727 return GST_QUERY_STRUCTURE (query);
731 * gst_query_writable_structure:
732 * @query: a #GstQuery
734 * Get the structure of a query. This method should be called with a writable
735 * @query so that the returned structure is guranteed to be writable.
737 * Returns: (transfer none): the #GstStructure of the query. The structure is
738 * still owned by the query and will therefore be freed when the query
742 gst_query_writable_structure (GstQuery * query)
744 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
745 g_return_val_if_fail (gst_query_is_writable (query), NULL);
747 return GST_QUERY_STRUCTURE (query);
751 * gst_query_new_seeking:
752 * @format: the default #GstFormat for the new query
754 * Constructs a new query object for querying seeking properties of
757 * Free-function: gst_query_unref
759 * Returns: (transfer full): a new #GstQuery
762 gst_query_new_seeking (GstFormat format)
765 GstStructure *structure;
767 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
768 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
769 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
770 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
771 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
773 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
779 * gst_query_set_seeking:
780 * @query: a #GstQuery
781 * @format: the format to set for the @segment_start and @segment_end values
782 * @seekable: the seekable flag to set
783 * @segment_start: the segment_start to set
784 * @segment_end: the segment_end to set
786 * Set the seeking query result fields in @query.
789 gst_query_set_seeking (GstQuery * query, GstFormat format,
790 gboolean seekable, gint64 segment_start, gint64 segment_end)
792 GstStructure *structure;
794 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
795 g_return_if_fail (gst_query_is_writable (query));
797 structure = GST_QUERY_STRUCTURE (query);
798 gst_structure_id_set (structure,
799 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
800 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
801 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
802 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
806 * gst_query_parse_seeking:
807 * @query: a GST_QUERY_SEEKING type query #GstQuery
808 * @format: (out) (allow-none): the format to set for the @segment_start
809 * and @segment_end values, or NULL
810 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
811 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
812 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
814 * Parse a seeking query, writing the format into @format, and
815 * other results into the passed parameters, if the respective parameters
819 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
820 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
822 GstStructure *structure;
824 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
826 structure = GST_QUERY_STRUCTURE (query);
829 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
830 GST_QUARK (FORMAT)));
832 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
833 GST_QUARK (SEEKABLE)));
835 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
836 GST_QUARK (SEGMENT_START)));
838 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
839 GST_QUARK (SEGMENT_END)));
843 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
844 GDestroyNotify clear_func)
849 value = gst_structure_id_get_value (s, quark);
851 array = (GArray *) g_value_get_boxed (value);
853 GValue new_array_val = { 0, };
855 array = g_array_new (FALSE, TRUE, element_size);
857 g_array_set_clear_func (array, clear_func);
859 g_value_init (&new_array_val, G_TYPE_ARRAY);
860 g_value_take_boxed (&new_array_val, array);
862 gst_structure_id_take_value (s, quark, &new_array_val);
868 * gst_query_new_formats:
870 * Constructs a new query object for querying formats of
873 * Free-function: gst_query_unref
875 * Returns: (transfer full): a new #GstQuery
880 gst_query_new_formats (void)
883 GstStructure *structure;
885 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
886 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
892 gst_query_list_add_format (GValue * list, GstFormat format)
894 GValue item = { 0, };
896 g_value_init (&item, GST_TYPE_FORMAT);
897 g_value_set_enum (&item, format);
898 gst_value_list_append_value (list, &item);
899 g_value_unset (&item);
903 * gst_query_set_formats:
904 * @query: a #GstQuery
905 * @n_formats: the number of formats to set.
906 * @...: A number of @GstFormats equal to @n_formats.
908 * Set the formats query result fields in @query. The number of formats passed
909 * must be equal to @n_formats.
912 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
915 GValue list = { 0, };
917 GstStructure *structure;
919 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
920 g_return_if_fail (gst_query_is_writable (query));
922 g_value_init (&list, GST_TYPE_LIST);
924 va_start (ap, n_formats);
925 for (i = 0; i < n_formats; i++) {
926 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
930 structure = GST_QUERY_STRUCTURE (query);
931 gst_structure_set_value (structure, "formats", &list);
933 g_value_unset (&list);
938 * gst_query_set_formatsv:
939 * @query: a #GstQuery
940 * @n_formats: the number of formats to set.
941 * @formats: (in) (array length=n_formats): an array containing @n_formats
944 * Set the formats query result fields in @query. The number of formats passed
945 * in the @formats array must be equal to @n_formats.
950 gst_query_set_formatsv (GstQuery * query, gint n_formats,
951 const GstFormat * formats)
953 GValue list = { 0, };
955 GstStructure *structure;
957 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
958 g_return_if_fail (gst_query_is_writable (query));
960 g_value_init (&list, GST_TYPE_LIST);
961 for (i = 0; i < n_formats; i++) {
962 gst_query_list_add_format (&list, formats[i]);
964 structure = GST_QUERY_STRUCTURE (query);
965 gst_structure_set_value (structure, "formats", &list);
967 g_value_unset (&list);
971 * gst_query_parse_n_formats:
972 * @query: a #GstQuery
973 * @n_formats: (out) (allow-none): the number of formats in this query.
975 * Parse the number of formats in the formats @query.
980 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
982 GstStructure *structure;
984 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
989 structure = GST_QUERY_STRUCTURE (query);
990 list = gst_structure_get_value (structure, "formats");
994 *n_formats = gst_value_list_get_size (list);
999 * gst_query_parse_nth_format:
1000 * @query: a #GstQuery
1001 * @nth: (out): the nth format to retrieve.
1002 * @format: (out) (allow-none): a pointer to store the nth format
1004 * Parse the format query and retrieve the @nth format from it into
1005 * @format. If the list contains less elements than @nth, @format will be
1006 * set to GST_FORMAT_UNDEFINED.
1009 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1011 GstStructure *structure;
1013 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1018 structure = GST_QUERY_STRUCTURE (query);
1019 list = gst_structure_get_value (structure, "formats");
1021 *format = GST_FORMAT_UNDEFINED;
1023 if (nth < gst_value_list_get_size (list)) {
1025 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1027 *format = GST_FORMAT_UNDEFINED;
1033 * gst_query_new_buffering:
1034 * @format: the default #GstFormat for the new query
1036 * Constructs a new query object for querying the buffering status of
1039 * Free-function: gst_query_unref
1041 * Returns: (transfer full): a new #GstQuery
1046 gst_query_new_buffering (GstFormat format)
1049 GstStructure *structure;
1051 /* by default, we configure the answer as no buffering with a 100% buffering
1053 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1054 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1055 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1056 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1057 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1058 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1059 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1060 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1061 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1062 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1063 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1065 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1071 * gst_query_set_buffering_percent:
1072 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1073 * @busy: if buffering is busy
1074 * @percent: a buffering percent
1076 * Set the percentage of buffered data. This is a value between 0 and 100.
1077 * The @busy indicator is %TRUE when the buffering is in progress.
1082 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1084 GstStructure *structure;
1086 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1087 g_return_if_fail (gst_query_is_writable (query));
1088 g_return_if_fail (percent >= 0 && percent <= 100);
1090 structure = GST_QUERY_STRUCTURE (query);
1091 gst_structure_id_set (structure,
1092 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1093 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1097 * gst_query_parse_buffering_percent:
1098 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1099 * @busy: (out) (allow-none): if buffering is busy, or NULL
1100 * @percent: (out) (allow-none): a buffering percent, or NULL
1102 * Get the percentage of buffered data. This is a value between 0 and 100.
1103 * The @busy indicator is %TRUE when the buffering is in progress.
1108 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1111 GstStructure *structure;
1113 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1115 structure = GST_QUERY_STRUCTURE (query);
1117 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1120 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1121 GST_QUARK (BUFFER_PERCENT)));
1125 * gst_query_set_buffering_stats:
1126 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1127 * @mode: a buffering mode
1128 * @avg_in: the average input rate
1129 * @avg_out: the average output rate
1130 * @buffering_left: amount of buffering time left
1132 * Configures the buffering stats values in @query.
1137 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1138 gint avg_in, gint avg_out, gint64 buffering_left)
1140 GstStructure *structure;
1142 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1143 g_return_if_fail (gst_query_is_writable (query));
1145 structure = GST_QUERY_STRUCTURE (query);
1146 gst_structure_id_set (structure,
1147 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1148 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1149 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1150 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1154 * gst_query_parse_buffering_stats:
1155 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1156 * @mode: (out) (allow-none): a buffering mode, or NULL
1157 * @avg_in: (out) (allow-none): the average input rate, or NULL
1158 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1159 * @buffering_left: (out) (allow-none): amount of buffering time left, or NULL
1161 * Extracts the buffering stats values from @query.
1166 gst_query_parse_buffering_stats (GstQuery * query,
1167 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1168 gint64 * buffering_left)
1170 GstStructure *structure;
1172 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1174 structure = GST_QUERY_STRUCTURE (query);
1176 *mode = (GstBufferingMode)
1177 g_value_get_enum (gst_structure_id_get_value (structure,
1178 GST_QUARK (BUFFERING_MODE)));
1180 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1181 GST_QUARK (AVG_IN_RATE)));
1183 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1184 GST_QUARK (AVG_OUT_RATE)));
1187 g_value_get_int64 (gst_structure_id_get_value (structure,
1188 GST_QUARK (BUFFERING_LEFT)));
1192 * gst_query_set_buffering_range:
1193 * @query: a #GstQuery
1194 * @format: the format to set for the @start and @stop values
1195 * @start: the start to set
1196 * @stop: the stop to set
1197 * @estimated_total: estimated total amount of download time
1199 * Set the available query result fields in @query.
1204 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1205 gint64 start, gint64 stop, gint64 estimated_total)
1207 GstStructure *structure;
1209 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1210 g_return_if_fail (gst_query_is_writable (query));
1212 structure = GST_QUERY_STRUCTURE (query);
1213 gst_structure_id_set (structure,
1214 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1215 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1216 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1217 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1221 * gst_query_parse_buffering_range:
1222 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1223 * @format: (out) (allow-none): the format to set for the @segment_start
1224 * and @segment_end values, or NULL
1225 * @start: (out) (allow-none): the start to set, or NULL
1226 * @stop: (out) (allow-none): the stop to set, or NULL
1227 * @estimated_total: (out) (allow-none): estimated total amount of download
1230 * Parse an available query, writing the format into @format, and
1231 * other results into the passed parameters, if the respective parameters
1237 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1238 gint64 * start, gint64 * stop, gint64 * estimated_total)
1240 GstStructure *structure;
1242 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1244 structure = GST_QUERY_STRUCTURE (query);
1247 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1248 GST_QUARK (FORMAT)));
1250 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1251 GST_QUARK (START_VALUE)));
1253 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1254 GST_QUARK (STOP_VALUE)));
1255 if (estimated_total)
1257 g_value_get_int64 (gst_structure_id_get_value (structure,
1258 GST_QUARK (ESTIMATED_TOTAL)));
1261 /* GstQueryBufferingRange: internal struct for GArray */
1266 } GstQueryBufferingRange;
1269 * gst_query_add_buffering_range:
1270 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1271 * @start: start position of the range
1272 * @stop: stop position of the range
1274 * Set the buffering-ranges array field in @query. The current last
1275 * start position of the array should be inferior to @start.
1277 * Returns: a #gboolean indicating if the range was added or not.
1282 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1284 GstQueryBufferingRange range;
1285 GstStructure *structure;
1288 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1289 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1291 if (G_UNLIKELY (start >= stop))
1294 structure = GST_QUERY_STRUCTURE (query);
1295 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1296 sizeof (GstQueryBufferingRange), NULL);
1298 if (array->len > 1) {
1299 GstQueryBufferingRange *last;
1301 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1303 if (G_UNLIKELY (start <= last->start))
1307 range.start = start;
1309 g_array_append_val (array, range);
1315 * gst_query_get_n_buffering_ranges:
1316 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1318 * Retrieve the number of values currently stored in the
1319 * buffered-ranges array of the query's structure.
1321 * Returns: the range array size as a #guint.
1326 gst_query_get_n_buffering_ranges (GstQuery * query)
1328 GstStructure *structure;
1331 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1333 structure = GST_QUERY_STRUCTURE (query);
1334 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1335 sizeof (GstQueryBufferingRange), NULL);
1342 * gst_query_parse_nth_buffering_range:
1343 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1344 * @index: position in the buffered-ranges array to read
1345 * @start: (out) (allow-none): the start position to set, or NULL
1346 * @stop: (out) (allow-none): the stop position to set, or NULL
1348 * Parse an available query and get the start and stop values stored
1349 * at the @index of the buffered ranges array.
1351 * Returns: a #gboolean indicating if the parsing succeeded.
1356 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1357 gint64 * start, gint64 * stop)
1359 GstQueryBufferingRange *range;
1360 GstStructure *structure;
1363 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1365 structure = GST_QUERY_STRUCTURE (query);
1367 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1368 sizeof (GstQueryBufferingRange), NULL);
1369 g_return_val_if_fail (index < array->len, FALSE);
1371 range = &g_array_index (array, GstQueryBufferingRange, index);
1374 *start = range->start;
1376 *stop = range->stop;
1383 * gst_query_new_uri:
1385 * Constructs a new query URI query object. Use gst_query_unref()
1386 * when done with it. An URI query is used to query the current URI
1387 * that is used by the source or sink.
1389 * Free-function: gst_query_unref
1391 * Returns: (transfer full): a new #GstQuery
1396 gst_query_new_uri (void)
1399 GstStructure *structure;
1401 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1402 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1404 query = gst_query_new_custom (GST_QUERY_URI, structure);
1410 * gst_query_set_uri:
1411 * @query: a #GstQuery with query type GST_QUERY_URI
1412 * @uri: the URI to set
1414 * Answer a URI query by setting the requested URI.
1419 gst_query_set_uri (GstQuery * query, const gchar * uri)
1421 GstStructure *structure;
1423 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1424 g_return_if_fail (gst_query_is_writable (query));
1425 g_return_if_fail (gst_uri_is_valid (uri));
1427 structure = GST_QUERY_STRUCTURE (query);
1428 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1432 * gst_query_parse_uri:
1433 * @query: a #GstQuery
1434 * @uri: (out callee-allocates) (allow-none): the storage for the current URI
1437 * Parse an URI query, writing the URI into @uri as a newly
1438 * allocated string, if the respective parameters are non-NULL.
1439 * Free the string with g_free() after usage.
1444 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1446 GstStructure *structure;
1448 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1450 structure = GST_QUERY_STRUCTURE (query);
1452 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1457 * gst_query_new_allocation:
1458 * @caps: the negotiated caps
1459 * @need_pool: return a pool
1461 * Constructs a new query object for querying the allocation properties.
1463 * Free-function: gst_query_unref
1465 * Returns: (transfer full): a new #GstQuery
1468 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1471 GstStructure *structure;
1473 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1474 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1475 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1477 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1483 * gst_query_parse_allocation:
1484 * @query: a #GstQuery
1485 * @caps: (out) (transfer none) (allow-none): The #GstCaps
1486 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1488 * Parse an allocation query, writing the requested caps in @caps and
1489 * whether a pool is needed in @need_pool, if the respective parameters
1493 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1494 gboolean * need_pool)
1496 GstStructure *structure;
1498 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1500 structure = GST_QUERY_STRUCTURE (query);
1502 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1505 gst_structure_id_get (structure,
1506 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1511 GstBufferPool *pool;
1518 allocation_pool_free (AllocationPool * ap)
1521 gst_object_unref (ap->pool);
1525 * gst_query_add_allocation_pool:
1526 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1527 * @pool: the #GstBufferPool
1529 * @min_buffers: the min buffers
1530 * @max_buffers: the max buffers
1532 * Set the pool parameters in @query.
1535 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1536 guint size, guint min_buffers, guint max_buffers)
1539 GstStructure *structure;
1542 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1543 g_return_if_fail (gst_query_is_writable (query));
1544 g_return_if_fail (size != 0);
1546 structure = GST_QUERY_STRUCTURE (query);
1547 array = ensure_array (structure, GST_QUARK (POOL),
1548 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1550 if ((ap.pool = pool))
1551 gst_object_ref (pool);
1553 ap.min_buffers = min_buffers;
1554 ap.max_buffers = max_buffers;
1556 g_array_append_val (array, ap);
1561 * gst_query_get_n_allocation_pools:
1562 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1564 * Retrieve the number of values currently stored in the
1565 * pool array of the query's structure.
1567 * Returns: the pool array size as a #guint.
1570 gst_query_get_n_allocation_pools (GstQuery * query)
1573 GstStructure *structure;
1575 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1577 structure = GST_QUERY_STRUCTURE (query);
1578 array = ensure_array (structure, GST_QUARK (POOL),
1579 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1585 * gst_query_parse_nth_allocation_pool:
1586 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1587 * @index: index to parse
1588 * @pool: (out) (allow-none) (transfer none): the #GstBufferPool
1589 * @size: (out) (allow-none): the size
1590 * @min_buffers: (out) (allow-none): the min buffers
1591 * @max_buffers: (out) (allow-none): the max buffers
1593 * Get the pool parameters in @query.
1596 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1597 GstBufferPool ** pool, guint * size, guint * min_buffers,
1598 guint * max_buffers)
1601 GstStructure *structure;
1604 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1606 structure = GST_QUERY_STRUCTURE (query);
1607 array = ensure_array (structure, GST_QUARK (POOL),
1608 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1609 g_return_if_fail (index < array->len);
1611 ap = &g_array_index (array, AllocationPool, index);
1614 if ((*pool = ap->pool))
1615 gst_object_ref (*pool);
1619 *min_buffers = ap->min_buffers;
1621 *max_buffers = ap->max_buffers;
1625 * gst_query_set_nth_allocation_pool:
1626 * @index: index to modify
1627 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1628 * @pool: the #GstBufferPool
1630 * @min_buffers: the min buffers
1631 * @max_buffers: the max buffers
1633 * Set the pool parameters in @query.
1636 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1637 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1640 GstStructure *structure;
1641 AllocationPool *oldap, ap;
1643 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1645 structure = GST_QUERY_STRUCTURE (query);
1646 array = ensure_array (structure, GST_QUARK (POOL),
1647 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1648 g_return_if_fail (index < array->len);
1650 oldap = &g_array_index (array, AllocationPool, index);
1651 allocation_pool_free (oldap);
1653 if ((ap.pool = pool))
1654 gst_object_ref (pool);
1656 ap.min_buffers = min_buffers;
1657 ap.max_buffers = max_buffers;
1658 g_array_index (array, AllocationPool, index) = ap;
1664 GstStructure *params;
1668 allocation_meta_free (AllocationMeta * am)
1671 gst_structure_free (am->params);
1675 * gst_query_add_allocation_meta:
1676 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1677 * @api: the metadata API
1678 * @params: (transfer full) (allow-none): API specific parameters
1680 * Add @api with @params as one of the supported metadata API to @query.
1683 gst_query_add_allocation_meta (GstQuery * query, GType api,
1684 GstStructure * params)
1687 GstStructure *structure;
1690 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1691 g_return_if_fail (api != 0);
1692 g_return_if_fail (gst_query_is_writable (query));
1694 structure = GST_QUERY_STRUCTURE (query);
1696 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1697 (GDestroyNotify) allocation_meta_free);
1702 g_array_append_val (array, am);
1706 * gst_query_get_n_allocation_metas:
1707 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1709 * Retrieve the number of values currently stored in the
1710 * meta API array of the query's structure.
1712 * Returns: the metadata API array size as a #guint.
1715 gst_query_get_n_allocation_metas (GstQuery * query)
1718 GstStructure *structure;
1720 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1722 structure = GST_QUERY_STRUCTURE (query);
1724 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1725 (GDestroyNotify) allocation_meta_free);
1731 * gst_query_parse_nth_allocation_meta:
1732 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1733 * @index: position in the metadata API array to read
1734 * @params: (out) (allow-none): API specific flags
1736 * Parse an available query and get the metadata API
1737 * at @index of the metadata API array.
1739 * Returns: a #GType of the metadata API at @index.
1742 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1743 const GstStructure ** params)
1746 GstStructure *structure;
1749 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1751 structure = GST_QUERY_STRUCTURE (query);
1753 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1754 (GDestroyNotify) allocation_meta_free);
1756 g_return_val_if_fail (index < array->len, 0);
1758 am = &g_array_index (array, AllocationMeta, index);
1761 *params = am->params;
1767 * gst_query_remove_nth_allocation_meta:
1768 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1769 * @index: position in the metadata API array to remove
1771 * Remove the metadata API at @index of the metadata API array.
1774 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1777 GstStructure *structure;
1779 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1780 g_return_if_fail (gst_query_is_writable (query));
1782 structure = GST_QUERY_STRUCTURE (query);
1784 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1785 (GDestroyNotify) allocation_meta_free);
1786 g_return_if_fail (index < array->len);
1788 g_array_remove_index (array, index);
1792 * gst_query_find_allocation_meta:
1793 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1794 * @api: the metadata API
1795 * @index: (out) (allow-none): the index
1797 * Check if @query has metadata @api set. When this function returns TRUE,
1798 * @index will contain the index where the requested API and the flags can be
1801 * Returns: TRUE when @api is in the list of metadata.
1804 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1807 GstStructure *structure;
1810 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1811 g_return_val_if_fail (api != 0, FALSE);
1813 structure = GST_QUERY_STRUCTURE (query);
1815 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1816 (GDestroyNotify) allocation_meta_free);
1819 for (i = 0; i < len; i++) {
1820 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1821 if (am->api == api) {
1832 GstAllocator *allocator;
1833 GstAllocationParams params;
1837 allocation_param_free (AllocationParam * ap)
1840 gst_object_unref (ap->allocator);
1844 * gst_query_add_allocation_param:
1845 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1846 * @allocator: (transfer none) (allow-none): the memory allocator
1847 * @params: (transfer none) (allow-none): a #GstAllocationParams
1849 * Add @allocator and its @params as a supported memory allocator.
1852 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1853 const GstAllocationParams * params)
1856 GstStructure *structure;
1859 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1860 g_return_if_fail (gst_query_is_writable (query));
1861 g_return_if_fail (allocator != NULL || params != NULL);
1863 structure = GST_QUERY_STRUCTURE (query);
1864 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1865 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1867 if ((ap.allocator = allocator))
1868 gst_object_ref (allocator);
1870 ap.params = *params;
1872 gst_allocation_params_init (&ap.params);
1874 g_array_append_val (array, ap);
1878 * gst_query_get_n_allocation_params:
1879 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1881 * Retrieve the number of values currently stored in the
1882 * allocator params array of the query's structure.
1884 * If no memory allocator is specified, the downstream element can handle
1885 * the default memory allocator.
1887 * Returns: the allocator array size as a #guint.
1890 gst_query_get_n_allocation_params (GstQuery * query)
1893 GstStructure *structure;
1895 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1897 structure = GST_QUERY_STRUCTURE (query);
1898 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1899 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1905 * gst_query_parse_nth_allocation_param:
1906 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1907 * @index: position in the allocator array to read
1908 * @allocator: (out) (transfer none) (allow-none): variable to hold the result
1909 * @params: (out) (allow-none): parameters for the allocator
1911 * Parse an available query and get the alloctor and its params
1912 * at @index of the allocator array.
1915 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
1916 GstAllocator ** allocator, GstAllocationParams * params)
1919 GstStructure *structure;
1920 AllocationParam *ap;
1922 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1924 structure = GST_QUERY_STRUCTURE (query);
1925 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1926 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1927 g_return_if_fail (index < array->len);
1929 ap = &g_array_index (array, AllocationParam, index);
1932 if ((*allocator = ap->allocator))
1933 gst_object_ref (*allocator);
1935 *params = ap->params;
1939 * gst_query_set_nth_allocation_param:
1940 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1941 * @index: position in the allocator array to set
1942 * @allocator: (transfer none) (allow-none): new allocator to set
1943 * @params: (transfer none) (allow-none): parameters for the allocator
1945 * Parse an available query and get the alloctor and its params
1946 * at @index of the allocator array.
1949 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
1950 GstAllocator * allocator, const GstAllocationParams * params)
1953 GstStructure *structure;
1954 AllocationParam *old, ap;
1956 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1958 structure = GST_QUERY_STRUCTURE (query);
1959 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1960 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1961 g_return_if_fail (index < array->len);
1963 old = &g_array_index (array, AllocationParam, index);
1964 allocation_param_free (old);
1966 if ((ap.allocator = allocator))
1967 gst_object_ref (allocator);
1969 ap.params = *params;
1971 gst_allocation_params_init (&ap.params);
1973 g_array_index (array, AllocationParam, index) = ap;
1977 * gst_query_new_scheduling:
1979 * Constructs a new query object for querying the scheduling properties.
1981 * Free-function: gst_query_unref
1983 * Returns: (transfer full): a new #GstQuery
1986 gst_query_new_scheduling (void)
1989 GstStructure *structure;
1991 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
1992 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
1993 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
1994 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
1995 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
1996 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2002 * gst_query_set_scheduling:
2003 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2004 * @flags: #GstSchedulingFlags
2005 * @minsize: the suggested minimum size of pull requests
2006 * @maxsize: the suggested maximum size of pull requests
2007 * @align: the suggested alignment of pull requests
2009 * Set the scheduling properties.
2012 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2013 gint minsize, gint maxsize, gint align)
2015 GstStructure *structure;
2017 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2018 g_return_if_fail (gst_query_is_writable (query));
2020 structure = GST_QUERY_STRUCTURE (query);
2021 gst_structure_id_set (structure,
2022 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2023 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2024 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2025 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2029 * gst_query_parse_scheduling:
2030 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2031 * @flags: (out) (allow-none): #GstSchedulingFlags
2032 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
2033 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
2034 * @align: (out) (allow-none): the suggested alignment of pull requests
2036 * Set the scheduling properties.
2039 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2040 gint * minsize, gint * maxsize, gint * align)
2042 GstStructure *structure;
2044 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2046 structure = GST_QUERY_STRUCTURE (query);
2047 gst_structure_id_get (structure,
2048 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2049 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2050 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2051 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2055 * gst_query_add_scheduling_mode:
2056 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2057 * @mode: a #GstPadMode
2059 * Add @mode as aone of the supported scheduling modes to @query.
2062 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2064 GstStructure *structure;
2067 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2068 g_return_if_fail (gst_query_is_writable (query));
2070 structure = GST_QUERY_STRUCTURE (query);
2072 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2074 g_array_append_val (array, mode);
2078 * gst_query_get_n_scheduling_modes:
2079 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2081 * Retrieve the number of values currently stored in the
2082 * scheduling mode array of the query's structure.
2084 * Returns: the scheduling mode array size as a #guint.
2087 gst_query_get_n_scheduling_modes (GstQuery * query)
2090 GstStructure *structure;
2092 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2094 structure = GST_QUERY_STRUCTURE (query);
2096 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2102 * gst_query_parse_nth_scheduling_mode:
2103 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2104 * @index: position in the scheduling modes array to read
2106 * Parse an available query and get the scheduling mode
2107 * at @index of the scheduling modes array.
2109 * Returns: a #GstPadMode of the scheduling mode at @index.
2112 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2114 GstStructure *structure;
2117 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2120 structure = GST_QUERY_STRUCTURE (query);
2122 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2123 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2125 return g_array_index (array, GstPadMode, index);
2129 * gst_query_has_scheduling_mode:
2130 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2131 * @mode: the scheduling mode
2133 * Check if @query has scheduling mode set.
2135 * Returns: TRUE when @mode is in the list of scheduling modes.
2138 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2140 GstStructure *structure;
2144 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2146 structure = GST_QUERY_STRUCTURE (query);
2148 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2151 for (i = 0; i < len; i++) {
2152 if (mode == g_array_index (array, GstPadMode, i))
2159 * gst_query_new_accept_caps:
2160 * @caps: a fixed #GstCaps
2162 * Constructs a new query object for querying if @caps are accepted.
2164 * Free-function: gst_query_unref
2166 * Returns: (transfer full): a new #GstQuery
2169 gst_query_new_accept_caps (GstCaps * caps)
2172 GstStructure *structure;
2174 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2176 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2177 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2178 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2179 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2185 * gst_query_parse_accept_caps:
2186 * @query: The query to parse
2187 * @caps: (out): A pointer to the caps
2189 * Get the caps from @query. The caps remains valid as long as @query remains
2193 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2195 GstStructure *structure;
2197 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2198 g_return_if_fail (caps != NULL);
2200 structure = GST_QUERY_STRUCTURE (query);
2201 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2206 * gst_query_set_accept_caps_result:
2207 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2208 * @result: the result to set
2210 * Set @result as the result for the @query.
2213 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2215 GstStructure *structure;
2217 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2218 g_return_if_fail (gst_query_is_writable (query));
2220 structure = GST_QUERY_STRUCTURE (query);
2221 gst_structure_id_set (structure,
2222 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2226 * gst_query_parse_accept_caps_result:
2227 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2228 * @result: location for the result
2230 * Parse the result from @query and store in @result.
2233 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2235 GstStructure *structure;
2237 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2239 structure = GST_QUERY_STRUCTURE (query);
2240 gst_structure_id_get (structure,
2241 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2245 * gst_query_new_caps:
2248 * Constructs a new query object for querying the caps.
2250 * The CAPS query should return the allowable caps for a pad in the context
2251 * of the element's state, its link to other elements, and the devices or files
2252 * it has opened. These caps must be a subset of the pad template caps. In the
2253 * NULL state with no links, the CAPS query should ideally return the same caps
2254 * as the pad template. In rare circumstances, an object property can affect
2255 * the caps returned by the CAPS query, but this is discouraged.
2257 * For most filters, the caps returned by CAPS query is directly affected by the
2258 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2259 * the srcpad's getcaps function is directly related to the stream data. Again,
2260 * the CAPS query should return the most specific caps it reasonably can, since this
2261 * helps with autoplugging.
2263 * The @filter is used to restrict the result caps, only the caps matching
2264 * @filter should be returned from the CAPS query. Specifying a filter might
2265 * greatly reduce the amount of processing an element needs to do.
2267 * Free-function: gst_query_unref
2269 * Returns: (transfer full): a new #GstQuery
2272 gst_query_new_caps (GstCaps * filter)
2275 GstStructure *structure;
2277 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2278 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2279 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2280 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2286 * gst_query_parse_caps:
2287 * @query: The query to parse
2288 * @filter: (out): A pointer to the caps filter
2290 * Get the filter from the caps @query. The caps remains valid as long as
2291 * @query remains valid.
2294 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2296 GstStructure *structure;
2298 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2299 g_return_if_fail (filter != NULL);
2301 structure = GST_QUERY_STRUCTURE (query);
2302 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2303 GST_QUARK (FILTER)));
2307 * gst_query_set_caps_result:
2308 * @query: The query to use
2309 * @caps: (in): A pointer to the caps
2311 * Set the @caps result in @query.
2314 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2316 GstStructure *structure;
2318 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2319 g_return_if_fail (gst_query_is_writable (query));
2321 structure = GST_QUERY_STRUCTURE (query);
2322 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2326 * gst_query_parse_caps_result:
2327 * @query: The query to parse
2328 * @caps: (out): A pointer to the caps
2330 * Get the caps result from @query. The caps remains valid as long as
2331 * @query remains valid.
2334 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2336 GstStructure *structure;
2338 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2339 g_return_if_fail (caps != NULL);
2341 structure = GST_QUERY_STRUCTURE (query);
2342 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2348 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2349 GstCapsIntersectMode mode)
2351 GstCaps *res, *caps = NULL;
2353 gst_query_parse_caps_result (query, &caps);
2354 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2355 gst_query_set_caps_result (query, res);
2356 gst_caps_unref (res);
2361 * gst_query_new_drain:
2363 * Constructs a new query object for querying the drain state.
2365 * Free-function: gst_query_unref
2367 * Returns: (transfer full): a new #GstQuery
2370 gst_query_new_drain (void)
2373 GstStructure *structure;
2375 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2376 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);