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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
27 * @short_description: Provide functions to create queries, and to set and parse
29 * @see_also: #GstPad, #GstElement
31 * Queries can be performed on pads (gst_pad_query()) and elements
32 * (gst_element_query()). Please note that some queries might need a running
35 * Queries can be created using the gst_query_new_*() functions.
36 * Query values can be set using gst_query_set_*(), and parsed using
37 * gst_query_parse_*() helpers.
39 * The following example shows how to query the duration of a pipeline:
40 * |[<!-- language="C" -->
43 * query = gst_query_new_duration (GST_FORMAT_TIME);
44 * res = gst_element_query (pipeline, query);
47 * gst_query_parse_duration (query, NULL, &duration);
48 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
50 * g_print ("duration query failed...");
52 * gst_query_unref (query);
57 #include "gst_private.h"
61 #include "gstenumtypes.h"
64 #include "gstbufferpool.h"
65 #ifdef TIZEN_PROFILE_TV
69 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
70 #define GST_CAT_DEFAULT gst_query_debug
72 GType _gst_query_type = 0;
78 GstStructure *structure;
81 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
91 static GstQueryQuarks query_quarks[] = {
92 {GST_QUERY_UNKNOWN, "unknown", 0},
93 {GST_QUERY_POSITION, "position", 0},
94 {GST_QUERY_DURATION, "duration", 0},
95 {GST_QUERY_LATENCY, "latency", 0},
96 {GST_QUERY_JITTER, "jitter", 0},
97 {GST_QUERY_RATE, "rate", 0},
98 {GST_QUERY_SEEKING, "seeking", 0},
99 {GST_QUERY_SEGMENT, "segment", 0},
100 {GST_QUERY_CONVERT, "convert", 0},
101 {GST_QUERY_FORMATS, "formats", 0},
102 {GST_QUERY_BUFFERING, "buffering", 0},
103 {GST_QUERY_CUSTOM, "custom", 0},
104 {GST_QUERY_URI, "uri", 0},
105 {GST_QUERY_ALLOCATION, "allocation", 0},
106 {GST_QUERY_SCHEDULING, "scheduling", 0},
107 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
108 {GST_QUERY_CAPS, "caps", 0},
109 {GST_QUERY_DRAIN, "drain", 0},
110 {GST_QUERY_CONTEXT, "context", 0},
111 {GST_QUERY_BITRATE, "bitrate", 0},
112 #ifdef TIZEN_PROFILE_TV
113 {GST_QUERY_RESOURCE, "resource", 0},
118 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
121 _priv_gst_query_initialize (void)
125 _gst_query_type = gst_query_get_type ();
127 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
129 for (i = 0; query_quarks[i].name; i++) {
130 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
135 * gst_query_type_get_name:
136 * @type: the query type
138 * Get a printable name for the given query type. Do not modify or free.
140 * Returns: a reference to the static name of the query.
143 gst_query_type_get_name (GstQueryType type)
147 for (i = 0; query_quarks[i].name; i++) {
148 if (type == query_quarks[i].type)
149 return query_quarks[i].name;
155 * gst_query_type_to_quark:
156 * @type: the query type
158 * Get the unique quark for the given query type.
160 * Returns: the quark associated with the query type
163 gst_query_type_to_quark (GstQueryType type)
167 for (i = 0; query_quarks[i].name; i++) {
168 if (type == query_quarks[i].type)
169 return query_quarks[i].quark;
175 * gst_query_type_get_flags:
176 * @type: a #GstQueryType
178 * Gets the #GstQueryTypeFlags associated with @type.
180 * Returns: a #GstQueryTypeFlags.
183 gst_query_type_get_flags (GstQueryType type)
185 GstQueryTypeFlags ret;
187 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
193 _gst_query_free (GstQuery * query)
197 g_return_if_fail (query != NULL);
199 s = GST_QUERY_STRUCTURE (query);
201 gst_structure_set_parent_refcount (s, NULL);
202 gst_structure_free (s);
205 memset (query, 0xff, sizeof (GstQueryImpl));
208 g_slice_free1 (sizeof (GstQueryImpl), query);
212 _gst_query_copy (GstQuery * query)
217 s = GST_QUERY_STRUCTURE (query);
219 s = gst_structure_copy (s);
221 copy = gst_query_new_custom (query->type, s);
227 * gst_query_new_position:
228 * @format: the default #GstFormat for the new query
230 * Constructs a new query stream position query object. Use gst_query_unref()
231 * when done with it. A position query is used to query the current position
232 * of playback in the streams, in some format.
234 * Free-function: gst_query_unref()
236 * Returns: (transfer full): a new #GstQuery
239 gst_query_new_position (GstFormat format)
242 GstStructure *structure;
244 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
245 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
246 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
248 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
254 * gst_query_set_position:
255 * @query: a #GstQuery with query type GST_QUERY_POSITION
256 * @format: the requested #GstFormat
257 * @cur: the position to set
259 * Answer a position query by setting the requested value in the given format.
262 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
266 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
268 s = GST_QUERY_STRUCTURE (query);
269 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
270 GST_QUARK (FORMAT))));
272 gst_structure_id_set (s,
273 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
274 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
278 * gst_query_parse_position:
279 * @query: a #GstQuery
280 * @format: (out) (allow-none): the storage for the #GstFormat of the
281 * position values (may be %NULL)
282 * @cur: (out) (allow-none): the storage for the current position (may be %NULL)
284 * Parse a position query, writing the format into @format, and the position
285 * into @cur, if the respective parameters are non-%NULL.
288 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
290 GstStructure *structure;
292 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
294 structure = GST_QUERY_STRUCTURE (query);
297 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
298 GST_QUARK (FORMAT)));
300 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
301 GST_QUARK (CURRENT)));
306 * gst_query_new_duration:
307 * @format: the #GstFormat for this duration query
309 * Constructs a new stream duration query object to query in the given format.
310 * Use gst_query_unref() when done with it. A duration query will give the
311 * total length of the stream.
313 * Free-function: gst_query_unref()
315 * Returns: (transfer full): a new #GstQuery
318 gst_query_new_duration (GstFormat format)
321 GstStructure *structure;
323 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
324 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
325 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
327 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
333 * gst_query_set_duration:
334 * @query: a #GstQuery
335 * @format: the #GstFormat for the duration
336 * @duration: the duration of the stream
338 * Answer a duration query by setting the requested value in the given format.
341 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
345 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
347 s = GST_QUERY_STRUCTURE (query);
348 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
349 GST_QUARK (FORMAT))));
350 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
351 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
355 * gst_query_parse_duration:
356 * @query: a #GstQuery
357 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
359 * @duration: (out) (allow-none): the storage for the total duration, or %NULL.
361 * Parse a duration query answer. Write the format of the duration into @format,
362 * and the value into @duration, if the respective variables are non-%NULL.
365 gst_query_parse_duration (GstQuery * query, GstFormat * format,
368 GstStructure *structure;
370 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
372 structure = GST_QUERY_STRUCTURE (query);
375 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
376 GST_QUARK (FORMAT)));
378 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
379 GST_QUARK (DURATION)));
383 * gst_query_new_latency:
385 * Constructs a new latency query object.
386 * Use gst_query_unref() when done with it. A latency query is usually performed
387 * by sinks to compensate for additional latency introduced by elements in the
390 * Free-function: gst_query_unref()
392 * Returns: (transfer full): a #GstQuery
395 gst_query_new_latency (void)
398 GstStructure *structure;
400 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
401 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
402 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
403 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, GST_CLOCK_TIME_NONE, NULL);
405 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
411 * gst_query_set_latency:
412 * @query: a #GstQuery
413 * @live: if there is a live element upstream
414 * @min_latency: the minimal latency of the upstream elements
415 * @max_latency: the maximal latency of the upstream elements
417 * 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);
426 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
428 structure = GST_QUERY_STRUCTURE (query);
429 gst_structure_id_set (structure,
430 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
431 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
432 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
436 * gst_query_parse_latency:
437 * @query: a #GstQuery
438 * @live: (out) (allow-none): storage for live or %NULL
439 * @min_latency: (out) (allow-none): the storage for the min latency or %NULL
440 * @max_latency: (out) (allow-none): the storage for the max latency or %NULL
442 * Parse a latency query answer.
445 gst_query_parse_latency (GstQuery * query, gboolean * live,
446 GstClockTime * min_latency, GstClockTime * max_latency)
448 GstStructure *structure;
450 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
452 structure = GST_QUERY_STRUCTURE (query);
455 g_value_get_boolean (gst_structure_id_get_value (structure,
458 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
459 GST_QUARK (MIN_LATENCY)));
461 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
462 GST_QUARK (MAX_LATENCY)));
466 * gst_query_new_convert:
467 * @src_format: the source #GstFormat for the new query
468 * @value: the value to convert
469 * @dest_format: the target #GstFormat
471 * Constructs a new convert query object. Use gst_query_unref()
472 * when done with it. A convert query is used to ask for a conversion between
473 * one format and another.
475 * Free-function: gst_query_unref()
477 * Returns: (transfer full): a #GstQuery
480 gst_query_new_convert (GstFormat src_format, gint64 value,
481 GstFormat dest_format)
484 GstStructure *structure;
486 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
487 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
488 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
489 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
490 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
492 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
498 * gst_query_set_convert:
499 * @query: a #GstQuery
500 * @src_format: the source #GstFormat
501 * @src_value: the source value
502 * @dest_format: the destination #GstFormat
503 * @dest_value: the destination value
505 * Answer a convert query by setting the requested values.
508 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
509 GstFormat dest_format, gint64 dest_value)
511 GstStructure *structure;
513 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
515 structure = GST_QUERY_STRUCTURE (query);
516 gst_structure_id_set (structure,
517 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
518 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
519 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
520 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
524 * gst_query_parse_convert:
525 * @query: a #GstQuery
526 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
527 * source value, or %NULL
528 * @src_value: (out) (allow-none): the storage for the source value, or %NULL
529 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
530 * destination value, or %NULL
531 * @dest_value: (out) (allow-none): the storage for the destination value,
534 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
535 * and @dest_value may be %NULL, in which case that value is omitted.
538 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
539 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
541 GstStructure *structure;
543 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
545 structure = GST_QUERY_STRUCTURE (query);
548 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
549 GST_QUARK (SRC_FORMAT)));
551 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
552 GST_QUARK (SRC_VALUE)));
555 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
556 GST_QUARK (DEST_FORMAT)));
558 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
559 GST_QUARK (DEST_VALUE)));
563 * gst_query_new_segment:
564 * @format: the #GstFormat for the new query
566 * Constructs a new segment query object. Use gst_query_unref()
567 * when done with it. A segment query is used to discover information about the
568 * currently configured segment for playback.
570 * Free-function: gst_query_unref()
572 * Returns: (transfer full): a new #GstQuery
575 gst_query_new_segment (GstFormat format)
578 GstStructure *structure;
580 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
581 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
582 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
583 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
584 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
586 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
591 #ifdef TIZEN_PROFILE_TV
593 * gst_query_new_resource:
594 * @resources: pointer to store the resources
596 * Constructs a new query stream position query object. Use
598 * when done with it. A resource query is used to query the resources used
599 * by the element/bin/pipelein
601 * Free-function: gst_query_unref
603 * Returns: (transfer full): a new #GstQuery
606 gst_query_new_resource (gchar * resources)
609 GstStructure *structure;
611 structure = gst_structure_new_id (GST_QUARK (QUERY_RESOURCE),
612 GST_QUARK (QUERY_RESOURCE), G_TYPE_POINTER, resources, NULL);
614 query = gst_query_new_custom (GST_QUERY_RESOURCE, structure);
620 * gst_query_add_resource:
621 * @query: a #GstQuery
622 * @resource: resource data to add
625 gst_query_add_resource (GstQuery * query, gint resource_id)
627 gchar *resource_info;
628 resource_info = gst_query_parse_resource (query);
629 sprintf (resource_info, "%d", resource_id);
632 /* gst_query_parse_resources:
633 * @query: a #GstQuery
634 * @resources: (out) the storage for the resource
638 gst_query_parse_resource (GstQuery * query)
640 GstStructure *structure;
642 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_RESOURCE, NULL);
644 structure = GST_QUERY_STRUCTURE (query);
645 resources = g_value_get_pointer (gst_structure_id_get_value (structure,
646 GST_QUARK (QUERY_RESOURCE)));
652 * gst_query_set_segment:
653 * @query: a #GstQuery
654 * @rate: the rate of the segment
655 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
656 * @start_value: the start value
657 * @stop_value: the stop value
659 * Answer a segment query by setting the requested values. The normal
660 * playback segment of a pipeline is 0 to duration at the default rate of
661 * 1.0. If a seek was performed on the pipeline to play a different
662 * segment, this query will return the range specified in the last seek.
664 * @start_value and @stop_value will respectively contain the configured
665 * playback range start and stop values expressed in @format.
666 * The values are always between 0 and the duration of the media and
667 * @start_value <= @stop_value. @rate will contain the playback rate. For
668 * negative rates, playback will actually happen from @stop_value to
672 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
673 gint64 start_value, gint64 stop_value)
675 GstStructure *structure;
677 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
679 structure = GST_QUERY_STRUCTURE (query);
680 gst_structure_id_set (structure,
681 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
682 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
683 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
684 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
688 * gst_query_parse_segment:
689 * @query: a #GstQuery
690 * @rate: (out) (allow-none): the storage for the rate of the segment, or %NULL
691 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
693 * @start_value: (out) (allow-none): the storage for the start value, or %NULL
694 * @stop_value: (out) (allow-none): the storage for the stop value, or %NULL
696 * Parse a segment query answer. Any of @rate, @format, @start_value, and
697 * @stop_value may be %NULL, which will cause this value to be omitted.
699 * See gst_query_set_segment() for an explanation of the function arguments.
702 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
703 gint64 * start_value, gint64 * stop_value)
705 GstStructure *structure;
707 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
709 structure = GST_QUERY_STRUCTURE (query);
711 *rate = g_value_get_double (gst_structure_id_get_value (structure,
715 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
716 GST_QUARK (FORMAT)));
718 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
719 GST_QUARK (START_VALUE)));
721 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
722 GST_QUARK (STOP_VALUE)));
726 * gst_query_new_custom:
727 * @type: the query type
728 * @structure: (allow-none) (transfer full): a structure for the query
730 * Constructs a new custom query object. Use gst_query_unref()
733 * Free-function: gst_query_unref()
735 * Returns: (transfer full) (nullable): a new #GstQuery
738 gst_query_new_custom (GstQueryType type, GstStructure * structure)
742 query = g_slice_new0 (GstQueryImpl);
744 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
747 /* structure must not have a parent */
748 if (!gst_structure_set_parent_refcount (structure,
749 &query->query.mini_object.refcount))
753 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
754 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
755 (GstMiniObjectFreeFunction) _gst_query_free);
757 GST_QUERY_TYPE (query) = type;
758 GST_QUERY_STRUCTURE (query) = structure;
760 return GST_QUERY_CAST (query);
765 g_slice_free1 (sizeof (GstQueryImpl), query);
766 g_warning ("structure is already owned by another object");
772 * gst_query_get_structure:
773 * @query: a #GstQuery
775 * Get the structure of a query.
777 * Returns: (transfer none) (nullable): the #GstStructure of the query. The
778 * structure is still owned by the query and will therefore be freed when the
782 gst_query_get_structure (GstQuery * query)
784 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
786 return GST_QUERY_STRUCTURE (query);
790 * gst_query_writable_structure:
791 * @query: a #GstQuery
793 * Get the structure of a query. This method should be called with a writable
794 * @query so that the returned structure is guaranteed to be writable.
796 * Returns: (transfer none): the #GstStructure of the query. The structure is
797 * still owned by the query and will therefore be freed when the query
801 gst_query_writable_structure (GstQuery * query)
803 GstStructure *structure;
805 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
806 g_return_val_if_fail (gst_query_is_writable (query), NULL);
808 structure = GST_QUERY_STRUCTURE (query);
810 if (structure == NULL) {
812 gst_structure_new_id_empty (gst_query_type_to_quark (GST_QUERY_TYPE
814 gst_structure_set_parent_refcount (structure, &query->mini_object.refcount);
815 GST_QUERY_STRUCTURE (query) = structure;
821 * gst_query_new_seeking:
822 * @format: the default #GstFormat for the new query
824 * Constructs a new query object for querying seeking properties of
827 * Free-function: gst_query_unref()
829 * Returns: (transfer full): a new #GstQuery
832 gst_query_new_seeking (GstFormat format)
835 GstStructure *structure;
837 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
838 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
839 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
840 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
841 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
843 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
849 * gst_query_set_seeking:
850 * @query: a #GstQuery
851 * @format: the format to set for the @segment_start and @segment_end values
852 * @seekable: the seekable flag to set
853 * @segment_start: the segment_start to set
854 * @segment_end: the segment_end to set
856 * Set the seeking query result fields in @query.
859 gst_query_set_seeking (GstQuery * query, GstFormat format,
860 gboolean seekable, gint64 segment_start, gint64 segment_end)
862 GstStructure *structure;
864 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
865 g_return_if_fail (gst_query_is_writable (query));
867 structure = GST_QUERY_STRUCTURE (query);
868 gst_structure_id_set (structure,
869 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
870 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
871 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
872 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
876 * gst_query_parse_seeking:
877 * @query: a GST_QUERY_SEEKING type query #GstQuery
878 * @format: (out) (allow-none): the format to set for the @segment_start
879 * and @segment_end values, or %NULL
880 * @seekable: (out) (allow-none): the seekable flag to set, or %NULL
881 * @segment_start: (out) (allow-none): the segment_start to set, or %NULL
882 * @segment_end: (out) (allow-none): the segment_end to set, or %NULL
884 * Parse a seeking query, writing the format into @format, and
885 * other results into the passed parameters, if the respective parameters
889 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
890 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
892 GstStructure *structure;
894 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
896 structure = GST_QUERY_STRUCTURE (query);
899 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
900 GST_QUARK (FORMAT)));
902 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
903 GST_QUARK (SEEKABLE)));
905 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
906 GST_QUARK (SEGMENT_START)));
908 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
909 GST_QUARK (SEGMENT_END)));
913 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
914 GDestroyNotify clear_func)
919 value = gst_structure_id_get_value (s, quark);
921 array = (GArray *) g_value_get_boxed (value);
923 GValue new_array_val = { 0, };
925 array = g_array_new (FALSE, TRUE, element_size);
927 g_array_set_clear_func (array, clear_func);
929 g_value_init (&new_array_val, G_TYPE_ARRAY);
930 g_value_take_boxed (&new_array_val, array);
932 gst_structure_id_take_value (s, quark, &new_array_val);
938 * gst_query_new_formats:
940 * Constructs a new query object for querying formats of
943 * Free-function: gst_query_unref()
945 * Returns: (transfer full): a new #GstQuery
948 gst_query_new_formats (void)
951 GstStructure *structure;
953 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
954 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
960 gst_query_list_add_format (GValue * list, GstFormat format)
962 GValue item = { 0, };
964 g_value_init (&item, GST_TYPE_FORMAT);
965 g_value_set_enum (&item, format);
966 gst_value_list_append_value (list, &item);
967 g_value_unset (&item);
971 * gst_query_set_formats:
972 * @query: a #GstQuery
973 * @n_formats: the number of formats to set.
974 * @...: A number of @GstFormats equal to @n_formats.
976 * Set the formats query result fields in @query. The number of formats passed
977 * must be equal to @n_formats.
980 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
983 GValue list = { 0, };
985 GstStructure *structure;
987 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
988 g_return_if_fail (gst_query_is_writable (query));
990 g_value_init (&list, GST_TYPE_LIST);
992 va_start (ap, n_formats);
993 for (i = 0; i < n_formats; i++) {
994 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
998 structure = GST_QUERY_STRUCTURE (query);
999 gst_structure_set_value (structure, "formats", &list);
1001 g_value_unset (&list);
1006 * gst_query_set_formatsv:
1007 * @query: a #GstQuery
1008 * @n_formats: the number of formats to set.
1009 * @formats: (in) (array length=n_formats): an array containing @n_formats
1010 * @GstFormat values.
1012 * Set the formats query result fields in @query. The number of formats passed
1013 * in the @formats array must be equal to @n_formats.
1016 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1017 const GstFormat * formats)
1019 GValue list = { 0, };
1021 GstStructure *structure;
1023 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1024 g_return_if_fail (gst_query_is_writable (query));
1026 g_value_init (&list, GST_TYPE_LIST);
1027 for (i = 0; i < n_formats; i++) {
1028 gst_query_list_add_format (&list, formats[i]);
1030 structure = GST_QUERY_STRUCTURE (query);
1031 gst_structure_set_value (structure, "formats", &list);
1033 g_value_unset (&list);
1037 * gst_query_parse_n_formats:
1038 * @query: a #GstQuery
1039 * @n_formats: (out) (allow-none): the number of formats in this query.
1041 * Parse the number of formats in the formats @query.
1044 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1046 GstStructure *structure;
1048 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1053 structure = GST_QUERY_STRUCTURE (query);
1054 list = gst_structure_get_value (structure, "formats");
1058 *n_formats = gst_value_list_get_size (list);
1063 * gst_query_parse_nth_format:
1064 * @query: a #GstQuery
1065 * @nth: the nth format to retrieve.
1066 * @format: (out) (allow-none): a pointer to store the nth format
1068 * Parse the format query and retrieve the @nth format from it into
1069 * @format. If the list contains less elements than @nth, @format will be
1070 * set to GST_FORMAT_UNDEFINED.
1073 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1075 GstStructure *structure;
1077 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1082 structure = GST_QUERY_STRUCTURE (query);
1083 list = gst_structure_get_value (structure, "formats");
1085 *format = GST_FORMAT_UNDEFINED;
1087 if (nth < gst_value_list_get_size (list)) {
1089 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1091 *format = GST_FORMAT_UNDEFINED;
1097 * gst_query_new_buffering:
1098 * @format: the default #GstFormat for the new query
1100 * Constructs a new query object for querying the buffering status of
1103 * Free-function: gst_query_unref()
1105 * Returns: (transfer full): a new #GstQuery
1108 gst_query_new_buffering (GstFormat format)
1111 GstStructure *structure;
1113 /* by default, we configure the answer as no buffering with a 100% buffering
1115 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1116 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1117 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1118 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1119 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1120 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1121 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1122 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1123 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1124 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1125 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1127 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1133 * gst_query_set_buffering_percent:
1134 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1135 * @busy: if buffering is busy
1136 * @percent: a buffering percent
1138 * Set the percentage of buffered data. This is a value between 0 and 100.
1139 * The @busy indicator is %TRUE when the buffering is in progress.
1142 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1144 GstStructure *structure;
1146 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1147 g_return_if_fail (gst_query_is_writable (query));
1148 g_return_if_fail (percent >= 0 && percent <= 100);
1150 structure = GST_QUERY_STRUCTURE (query);
1151 gst_structure_id_set (structure,
1152 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1153 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1157 * gst_query_parse_buffering_percent:
1158 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1159 * @busy: (out) (allow-none): if buffering is busy, or %NULL
1160 * @percent: (out) (allow-none): a buffering percent, or %NULL
1162 * Get the percentage of buffered data. This is a value between 0 and 100.
1163 * The @busy indicator is %TRUE when the buffering is in progress.
1166 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1169 GstStructure *structure;
1171 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1173 structure = GST_QUERY_STRUCTURE (query);
1175 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1178 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1179 GST_QUARK (BUFFER_PERCENT)));
1183 * gst_query_set_buffering_stats:
1184 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1185 * @mode: a buffering mode
1186 * @avg_in: the average input rate
1187 * @avg_out: the average output rate
1188 * @buffering_left: amount of buffering time left in milliseconds
1190 * Configures the buffering stats values in @query.
1193 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1194 gint avg_in, gint avg_out, gint64 buffering_left)
1196 GstStructure *structure;
1198 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1199 g_return_if_fail (gst_query_is_writable (query));
1201 structure = GST_QUERY_STRUCTURE (query);
1202 gst_structure_id_set (structure,
1203 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1204 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1205 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1206 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1210 * gst_query_parse_buffering_stats:
1211 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1212 * @mode: (out) (allow-none): a buffering mode, or %NULL
1213 * @avg_in: (out) (allow-none): the average input rate, or %NULL
1214 * @avg_out: (out) (allow-none): the average output rat, or %NULL
1215 * @buffering_left: (out) (allow-none): amount of buffering time left in
1216 * milliseconds, or %NULL
1218 * Extracts the buffering stats values from @query.
1221 gst_query_parse_buffering_stats (GstQuery * query,
1222 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1223 gint64 * buffering_left)
1225 GstStructure *structure;
1227 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1229 structure = GST_QUERY_STRUCTURE (query);
1231 *mode = (GstBufferingMode)
1232 g_value_get_enum (gst_structure_id_get_value (structure,
1233 GST_QUARK (BUFFERING_MODE)));
1235 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1236 GST_QUARK (AVG_IN_RATE)));
1238 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1239 GST_QUARK (AVG_OUT_RATE)));
1242 g_value_get_int64 (gst_structure_id_get_value (structure,
1243 GST_QUARK (BUFFERING_LEFT)));
1247 * gst_query_set_buffering_range:
1248 * @query: a #GstQuery
1249 * @format: the format to set for the @start and @stop values
1250 * @start: the start to set
1251 * @stop: the stop to set
1252 * @estimated_total: estimated total amount of download time remaining in
1255 * Set the available query result fields in @query.
1258 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1259 gint64 start, gint64 stop, gint64 estimated_total)
1261 GstStructure *structure;
1263 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1264 g_return_if_fail (gst_query_is_writable (query));
1266 structure = GST_QUERY_STRUCTURE (query);
1267 gst_structure_id_set (structure,
1268 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1269 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1270 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1271 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1275 * gst_query_parse_buffering_range:
1276 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1277 * @format: (out) (allow-none): the format to set for the @segment_start
1278 * and @segment_end values, or %NULL
1279 * @start: (out) (allow-none): the start to set, or %NULL
1280 * @stop: (out) (allow-none): the stop to set, or %NULL
1281 * @estimated_total: (out) (allow-none): estimated total amount of download
1282 * time remaining in milliseconds, or %NULL
1284 * Parse an available query, writing the format into @format, and
1285 * other results into the passed parameters, if the respective parameters
1289 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1290 gint64 * start, gint64 * stop, gint64 * estimated_total)
1292 GstStructure *structure;
1294 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1296 structure = GST_QUERY_STRUCTURE (query);
1299 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1300 GST_QUARK (FORMAT)));
1302 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1303 GST_QUARK (START_VALUE)));
1305 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1306 GST_QUARK (STOP_VALUE)));
1307 if (estimated_total)
1309 g_value_get_int64 (gst_structure_id_get_value (structure,
1310 GST_QUARK (ESTIMATED_TOTAL)));
1313 /* GstQueryBufferingRange: internal struct for GArray */
1318 } GstQueryBufferingRange;
1321 * gst_query_add_buffering_range:
1322 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1323 * @start: start position of the range
1324 * @stop: stop position of the range
1326 * Set the buffering-ranges array field in @query. The current last
1327 * start position of the array should be inferior to @start.
1329 * Returns: a #gboolean indicating if the range was added or not.
1332 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1334 GstQueryBufferingRange range;
1335 GstStructure *structure;
1338 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1339 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1341 if (G_UNLIKELY (start >= stop))
1344 structure = GST_QUERY_STRUCTURE (query);
1345 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1346 sizeof (GstQueryBufferingRange), NULL);
1348 if (array->len > 1) {
1349 GstQueryBufferingRange *last;
1351 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1353 if (G_UNLIKELY (start <= last->start))
1357 range.start = start;
1359 g_array_append_val (array, range);
1365 * gst_query_get_n_buffering_ranges:
1366 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1368 * Retrieve the number of values currently stored in the
1369 * buffered-ranges array of the query's structure.
1371 * Returns: the range array size as a #guint.
1374 gst_query_get_n_buffering_ranges (GstQuery * query)
1376 GstStructure *structure;
1379 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1381 structure = GST_QUERY_STRUCTURE (query);
1382 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1383 sizeof (GstQueryBufferingRange), NULL);
1390 * gst_query_parse_nth_buffering_range:
1391 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1392 * @index: position in the buffered-ranges array to read
1393 * @start: (out) (allow-none): the start position to set, or %NULL
1394 * @stop: (out) (allow-none): the stop position to set, or %NULL
1396 * Parse an available query and get the start and stop values stored
1397 * at the @index of the buffered ranges array.
1399 * Returns: a #gboolean indicating if the parsing succeeded.
1402 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1403 gint64 * start, gint64 * stop)
1405 GstQueryBufferingRange *range;
1406 GstStructure *structure;
1409 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1411 structure = GST_QUERY_STRUCTURE (query);
1413 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1414 sizeof (GstQueryBufferingRange), NULL);
1415 g_return_val_if_fail (index < array->len, FALSE);
1417 range = &g_array_index (array, GstQueryBufferingRange, index);
1420 *start = range->start;
1422 *stop = range->stop;
1429 * gst_query_new_uri:
1431 * Constructs a new query URI query object. Use gst_query_unref()
1432 * when done with it. An URI query is used to query the current URI
1433 * that is used by the source or sink.
1435 * Free-function: gst_query_unref()
1437 * Returns: (transfer full): a new #GstQuery
1440 gst_query_new_uri (void)
1443 GstStructure *structure;
1445 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1446 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1448 query = gst_query_new_custom (GST_QUERY_URI, structure);
1454 * gst_query_set_uri:
1455 * @query: a #GstQuery with query type GST_QUERY_URI
1456 * @uri: the URI to set
1458 * Answer a URI query by setting the requested URI.
1461 gst_query_set_uri (GstQuery * query, const gchar * uri)
1463 GstStructure *structure;
1465 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1466 g_return_if_fail (gst_query_is_writable (query));
1467 g_return_if_fail (gst_uri_is_valid (uri));
1469 structure = GST_QUERY_STRUCTURE (query);
1470 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1474 * gst_query_parse_uri:
1475 * @query: a #GstQuery
1476 * @uri: (out) (transfer full) (allow-none): the storage for the current URI
1479 * Parse an URI query, writing the URI into @uri as a newly
1480 * allocated string, if the respective parameters are non-%NULL.
1481 * Free the string with g_free() after usage.
1484 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1486 GstStructure *structure;
1488 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1490 structure = GST_QUERY_STRUCTURE (query);
1492 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1497 * gst_query_set_uri_redirection:
1498 * @query: a #GstQuery with query type GST_QUERY_URI
1499 * @uri: the URI to set
1501 * Answer a URI query by setting the requested URI redirection.
1506 gst_query_set_uri_redirection (GstQuery * query, const gchar * uri)
1508 GstStructure *structure;
1510 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1511 g_return_if_fail (gst_query_is_writable (query));
1512 g_return_if_fail (gst_uri_is_valid (uri));
1514 structure = GST_QUERY_STRUCTURE (query);
1515 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
1516 G_TYPE_STRING, uri, NULL);
1520 * gst_query_parse_uri_redirection:
1521 * @query: a #GstQuery
1522 * @uri: (out) (transfer full) (allow-none): the storage for the redirect URI
1525 * Parse an URI query, writing the URI into @uri as a newly
1526 * allocated string, if the respective parameters are non-%NULL.
1527 * Free the string with g_free() after usage.
1532 gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
1534 GstStructure *structure;
1536 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1538 structure = GST_QUERY_STRUCTURE (query);
1540 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION),
1541 G_TYPE_STRING, uri, NULL))
1547 * gst_query_set_uri_redirection_permanent:
1548 * @query: a #GstQuery with query type %GST_QUERY_URI
1549 * @permanent: whether the redirect is permanent or not
1551 * Answer a URI query by setting the requested URI redirection
1552 * to permanent or not.
1557 gst_query_set_uri_redirection_permanent (GstQuery * query, gboolean permanent)
1559 GstStructure *structure;
1561 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1562 g_return_if_fail (gst_query_is_writable (query));
1564 structure = GST_QUERY_STRUCTURE (query);
1565 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1566 G_TYPE_BOOLEAN, permanent, NULL);
1570 * gst_query_parse_uri_redirection_permanent:
1571 * @query: a #GstQuery
1572 * @permanent: (out) (allow-none): if the URI redirection is permanent
1575 * Parse an URI query, and set @permanent to %TRUE if there is a redirection
1576 * and it should be considered permanent. If a redirection is permanent,
1577 * applications should update their internal storage of the URI, otherwise
1578 * they should make all future requests to the original URI.
1583 gst_query_parse_uri_redirection_permanent (GstQuery * query,
1584 gboolean * permanent)
1586 GstStructure *structure;
1588 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1590 structure = GST_QUERY_STRUCTURE (query);
1592 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1593 G_TYPE_BOOLEAN, permanent, NULL))
1599 * gst_query_new_allocation:
1600 * @caps: the negotiated caps
1601 * @need_pool: return a pool
1603 * Constructs a new query object for querying the allocation properties.
1605 * Free-function: gst_query_unref()
1607 * Returns: (transfer full): a new #GstQuery
1610 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1613 GstStructure *structure;
1615 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1616 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1617 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1619 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1625 * gst_query_parse_allocation:
1626 * @query: a #GstQuery
1627 * @caps: (out) (transfer none) (allow-none): The #GstCaps
1628 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1630 * Parse an allocation query, writing the requested caps in @caps and
1631 * whether a pool is needed in @need_pool, if the respective parameters
1634 * Pool details can be retrieved using gst_query_get_n_allocation_pools() and
1635 * gst_query_parse_nth_allocation_pool().
1638 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1639 gboolean * need_pool)
1641 GstStructure *structure;
1643 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1645 structure = GST_QUERY_STRUCTURE (query);
1647 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1650 gst_structure_id_get (structure,
1651 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1656 GstBufferPool *pool;
1663 allocation_pool_free (AllocationPool * ap)
1666 gst_object_unref (ap->pool);
1670 * gst_query_add_allocation_pool:
1671 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1672 * @pool: (transfer none) (allow-none): the #GstBufferPool
1673 * @size: the buffer size
1674 * @min_buffers: the min buffers
1675 * @max_buffers: the max buffers
1677 * Set the pool parameters in @query.
1680 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1681 guint size, guint min_buffers, guint max_buffers)
1684 GstStructure *structure;
1687 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1688 g_return_if_fail (gst_query_is_writable (query));
1690 structure = GST_QUERY_STRUCTURE (query);
1691 array = ensure_array (structure, GST_QUARK (POOL),
1692 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1694 if ((ap.pool = pool))
1695 gst_object_ref (pool);
1697 ap.min_buffers = min_buffers;
1698 ap.max_buffers = max_buffers;
1700 g_array_append_val (array, ap);
1704 * gst_query_get_n_allocation_pools:
1705 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1707 * Retrieve the number of values currently stored in the
1708 * pool array of the query's structure.
1710 * Returns: the pool array size as a #guint.
1713 gst_query_get_n_allocation_pools (GstQuery * query)
1716 GstStructure *structure;
1718 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1720 structure = GST_QUERY_STRUCTURE (query);
1721 array = ensure_array (structure, GST_QUARK (POOL),
1722 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1728 * gst_query_parse_nth_allocation_pool:
1729 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1730 * @index: index to parse
1731 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1732 * @size: (out) (allow-none): the buffer size
1733 * @min_buffers: (out) (allow-none): the min buffers
1734 * @max_buffers: (out) (allow-none): the max buffers
1736 * Get the pool parameters in @query.
1738 * Unref @pool with gst_object_unref() when it's not needed any more.
1741 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1742 GstBufferPool ** pool, guint * size, guint * min_buffers,
1743 guint * max_buffers)
1746 GstStructure *structure;
1749 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1751 structure = GST_QUERY_STRUCTURE (query);
1752 array = ensure_array (structure, GST_QUARK (POOL),
1753 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1754 g_return_if_fail (index < array->len);
1756 ap = &g_array_index (array, AllocationPool, index);
1759 if ((*pool = ap->pool))
1760 gst_object_ref (*pool);
1764 *min_buffers = ap->min_buffers;
1766 *max_buffers = ap->max_buffers;
1770 * gst_query_set_nth_allocation_pool:
1771 * @index: index to modify
1772 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1773 * @pool: (transfer none) (allow-none): the #GstBufferPool
1774 * @size: the buffer size
1775 * @min_buffers: the min buffers
1776 * @max_buffers: the max buffers
1778 * Set the pool parameters in @query.
1781 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1782 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1785 GstStructure *structure;
1786 AllocationPool *oldap, ap;
1788 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1790 structure = GST_QUERY_STRUCTURE (query);
1791 array = ensure_array (structure, GST_QUARK (POOL),
1792 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1793 g_return_if_fail (index < array->len);
1795 oldap = &g_array_index (array, AllocationPool, index);
1796 allocation_pool_free (oldap);
1798 if ((ap.pool = pool))
1799 gst_object_ref (pool);
1801 ap.min_buffers = min_buffers;
1802 ap.max_buffers = max_buffers;
1803 g_array_index (array, AllocationPool, index) = ap;
1807 * gst_query_remove_nth_allocation_pool:
1808 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1809 * @index: position in the allocation pool array to remove
1811 * Remove the allocation pool at @index of the allocation pool array.
1816 gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
1819 GstStructure *structure;
1821 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1822 g_return_if_fail (gst_query_is_writable (query));
1824 structure = GST_QUERY_STRUCTURE (query);
1826 ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
1827 (GDestroyNotify) allocation_pool_free);
1828 g_return_if_fail (index < array->len);
1830 g_array_remove_index (array, index);
1836 GstStructure *params;
1840 allocation_meta_free (AllocationMeta * am)
1843 gst_structure_free (am->params);
1847 * gst_query_add_allocation_meta:
1848 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1849 * @api: the metadata API
1850 * @params: (transfer none) (allow-none): API specific parameters
1852 * Add @api with @params as one of the supported metadata API to @query.
1855 gst_query_add_allocation_meta (GstQuery * query, GType api,
1856 const GstStructure * params)
1859 GstStructure *structure;
1862 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1863 g_return_if_fail (api != 0);
1864 g_return_if_fail (gst_query_is_writable (query));
1866 structure = GST_QUERY_STRUCTURE (query);
1868 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1869 (GDestroyNotify) allocation_meta_free);
1872 am.params = (params ? gst_structure_copy (params) : NULL);
1874 g_array_append_val (array, am);
1878 * gst_query_get_n_allocation_metas:
1879 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1881 * Retrieve the number of values currently stored in the
1882 * meta API array of the query's structure.
1884 * Returns: the metadata API array size as a #guint.
1887 gst_query_get_n_allocation_metas (GstQuery * query)
1890 GstStructure *structure;
1892 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1894 structure = GST_QUERY_STRUCTURE (query);
1896 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1897 (GDestroyNotify) allocation_meta_free);
1903 * gst_query_parse_nth_allocation_meta:
1904 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1905 * @index: position in the metadata API array to read
1906 * @params: (out) (transfer none) (allow-none): API specific parameters
1908 * Parse an available query and get the metadata API
1909 * at @index of the metadata API array.
1911 * Returns: a #GType of the metadata API at @index.
1914 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1915 const GstStructure ** params)
1918 GstStructure *structure;
1921 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1923 structure = GST_QUERY_STRUCTURE (query);
1925 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1926 (GDestroyNotify) allocation_meta_free);
1928 g_return_val_if_fail (index < array->len, 0);
1930 am = &g_array_index (array, AllocationMeta, index);
1933 *params = am->params;
1939 * gst_query_remove_nth_allocation_meta:
1940 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1941 * @index: position in the metadata API array to remove
1943 * Remove the metadata API at @index of the metadata API array.
1946 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1949 GstStructure *structure;
1951 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1952 g_return_if_fail (gst_query_is_writable (query));
1954 structure = GST_QUERY_STRUCTURE (query);
1956 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1957 (GDestroyNotify) allocation_meta_free);
1958 g_return_if_fail (index < array->len);
1960 g_array_remove_index (array, index);
1964 * gst_query_find_allocation_meta:
1965 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1966 * @api: the metadata API
1967 * @index: (out) (transfer none) (allow-none): the index
1969 * Check if @query has metadata @api set. When this function returns %TRUE,
1970 * @index will contain the index where the requested API and the parameters
1973 * Returns: %TRUE when @api is in the list of metadata.
1976 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1979 GstStructure *structure;
1982 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1983 g_return_val_if_fail (api != 0, FALSE);
1985 structure = GST_QUERY_STRUCTURE (query);
1987 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1988 (GDestroyNotify) allocation_meta_free);
1991 for (i = 0; i < len; i++) {
1992 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1993 if (am->api == api) {
2004 GstAllocator *allocator;
2005 GstAllocationParams params;
2009 allocation_param_free (AllocationParam * ap)
2012 gst_object_unref (ap->allocator);
2016 * gst_query_add_allocation_param:
2017 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2018 * @allocator: (transfer none) (allow-none): the memory allocator
2019 * @params: (transfer none) (allow-none): a #GstAllocationParams
2021 * Add @allocator and its @params as a supported memory allocator.
2024 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
2025 const GstAllocationParams * params)
2028 GstStructure *structure;
2031 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2032 g_return_if_fail (gst_query_is_writable (query));
2033 g_return_if_fail (allocator != NULL || params != NULL);
2035 structure = GST_QUERY_STRUCTURE (query);
2036 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2037 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2039 if ((ap.allocator = allocator))
2040 gst_object_ref (allocator);
2042 ap.params = *params;
2044 gst_allocation_params_init (&ap.params);
2046 g_array_append_val (array, ap);
2050 * gst_query_get_n_allocation_params:
2051 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2053 * Retrieve the number of values currently stored in the
2054 * allocator params array of the query's structure.
2056 * If no memory allocator is specified, the downstream element can handle
2057 * the default memory allocator. The first memory allocator in the query
2058 * should be generic and allow mapping to system memory, all following
2059 * allocators should be ordered by preference with the preferred one first.
2061 * Returns: the allocator array size as a #guint.
2064 gst_query_get_n_allocation_params (GstQuery * query)
2067 GstStructure *structure;
2069 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
2071 structure = GST_QUERY_STRUCTURE (query);
2072 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2073 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2079 * gst_query_parse_nth_allocation_param:
2080 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2081 * @index: position in the allocator array to read
2082 * @allocator: (out) (transfer full) (allow-none): variable to hold the result
2083 * @params: (out) (allow-none): parameters for the allocator
2085 * Parse an available query and get the allocator and its params
2086 * at @index of the allocator array.
2089 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
2090 GstAllocator ** allocator, GstAllocationParams * params)
2093 GstStructure *structure;
2094 AllocationParam *ap;
2096 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2098 structure = GST_QUERY_STRUCTURE (query);
2099 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2100 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2101 g_return_if_fail (index < array->len);
2103 ap = &g_array_index (array, AllocationParam, index);
2106 if ((*allocator = ap->allocator))
2107 gst_object_ref (*allocator);
2109 *params = ap->params;
2113 * gst_query_set_nth_allocation_param:
2114 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2115 * @index: position in the allocator array to set
2116 * @allocator: (transfer none) (allow-none): new allocator to set
2117 * @params: (transfer none) (allow-none): parameters for the allocator
2119 * Parse an available query and get the allocator and its params
2120 * at @index of the allocator array.
2123 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
2124 GstAllocator * allocator, const GstAllocationParams * params)
2127 GstStructure *structure;
2128 AllocationParam *old, ap;
2130 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2132 structure = GST_QUERY_STRUCTURE (query);
2133 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2134 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2135 g_return_if_fail (index < array->len);
2137 old = &g_array_index (array, AllocationParam, index);
2138 allocation_param_free (old);
2140 if ((ap.allocator = allocator))
2141 gst_object_ref (allocator);
2143 ap.params = *params;
2145 gst_allocation_params_init (&ap.params);
2147 g_array_index (array, AllocationParam, index) = ap;
2151 * gst_query_remove_nth_allocation_param:
2152 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2153 * @index: position in the allocation param array to remove
2155 * Remove the allocation param at @index of the allocation param array.
2160 gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
2163 GstStructure *structure;
2165 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2166 g_return_if_fail (gst_query_is_writable (query));
2168 structure = GST_QUERY_STRUCTURE (query);
2170 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
2171 (GDestroyNotify) allocation_param_free);
2172 g_return_if_fail (index < array->len);
2174 g_array_remove_index (array, index);
2178 * gst_query_new_scheduling:
2180 * Constructs a new query object for querying the scheduling properties.
2182 * Free-function: gst_query_unref()
2184 * Returns: (transfer full): a new #GstQuery
2187 gst_query_new_scheduling (void)
2190 GstStructure *structure;
2192 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
2193 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
2194 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
2195 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
2196 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
2197 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2203 * gst_query_set_scheduling:
2204 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2205 * @flags: #GstSchedulingFlags
2206 * @minsize: the suggested minimum size of pull requests
2207 * @maxsize: the suggested maximum size of pull requests
2208 * @align: the suggested alignment of pull requests
2210 * Set the scheduling properties.
2213 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2214 gint minsize, gint maxsize, gint align)
2216 GstStructure *structure;
2218 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2219 g_return_if_fail (gst_query_is_writable (query));
2221 structure = GST_QUERY_STRUCTURE (query);
2222 gst_structure_id_set (structure,
2223 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2224 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2225 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2226 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2230 * gst_query_parse_scheduling:
2231 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2232 * @flags: (out) (allow-none): #GstSchedulingFlags
2233 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
2234 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
2235 * @align: (out) (allow-none): the suggested alignment of pull requests
2237 * Set the scheduling properties.
2240 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2241 gint * minsize, gint * maxsize, gint * align)
2243 GstStructure *structure;
2245 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2247 structure = GST_QUERY_STRUCTURE (query);
2248 gst_structure_id_get (structure,
2249 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2250 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2251 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2252 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2256 * gst_query_add_scheduling_mode:
2257 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2258 * @mode: a #GstPadMode
2260 * Add @mode as one of the supported scheduling modes to @query.
2263 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2265 GstStructure *structure;
2268 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2269 g_return_if_fail (gst_query_is_writable (query));
2271 structure = GST_QUERY_STRUCTURE (query);
2273 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2275 g_array_append_val (array, mode);
2279 * gst_query_get_n_scheduling_modes:
2280 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2282 * Retrieve the number of values currently stored in the
2283 * scheduling mode array of the query's structure.
2285 * Returns: the scheduling mode array size as a #guint.
2288 gst_query_get_n_scheduling_modes (GstQuery * query)
2291 GstStructure *structure;
2293 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2295 structure = GST_QUERY_STRUCTURE (query);
2297 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2303 * gst_query_parse_nth_scheduling_mode:
2304 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2305 * @index: position in the scheduling modes array to read
2307 * Parse an available query and get the scheduling mode
2308 * at @index of the scheduling modes array.
2310 * Returns: a #GstPadMode of the scheduling mode at @index.
2313 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2315 GstStructure *structure;
2318 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2321 structure = GST_QUERY_STRUCTURE (query);
2323 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2324 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2326 return g_array_index (array, GstPadMode, index);
2330 * gst_query_has_scheduling_mode:
2331 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2332 * @mode: the scheduling mode
2334 * Check if @query has scheduling mode set.
2336 * > When checking if upstream supports pull mode, it is usually not
2337 * > enough to just check for GST_PAD_MODE_PULL with this function, you
2338 * > also want to check whether the scheduling flags returned by
2339 * > gst_query_parse_scheduling() have the seeking flag set (meaning
2340 * > random access is supported, not only sequential pulls).
2342 * Returns: %TRUE when @mode is in the list of scheduling modes.
2345 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2347 GstStructure *structure;
2351 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2353 structure = GST_QUERY_STRUCTURE (query);
2355 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2358 for (i = 0; i < len; i++) {
2359 if (mode == g_array_index (array, GstPadMode, i))
2366 * gst_query_has_scheduling_mode_with_flags:
2367 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2368 * @mode: the scheduling mode
2369 * @flags: #GstSchedulingFlags
2371 * Check if @query has scheduling mode set and @flags is set in
2372 * query scheduling flags.
2374 * Returns: %TRUE when @mode is in the list of scheduling modes
2375 * and @flags are compatible with query flags.
2378 gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
2379 GstSchedulingFlags flags)
2381 GstSchedulingFlags sched_flags;
2383 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2385 gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
2387 return ((flags & sched_flags) == flags) &&
2388 gst_query_has_scheduling_mode (query, mode);
2392 * gst_query_new_accept_caps:
2393 * @caps: a fixed #GstCaps
2395 * Constructs a new query object for querying if @caps are accepted.
2397 * Free-function: gst_query_unref()
2399 * Returns: (transfer full): a new #GstQuery
2402 gst_query_new_accept_caps (GstCaps * caps)
2405 GstStructure *structure;
2407 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2409 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2410 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2411 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2412 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2418 * gst_query_parse_accept_caps:
2419 * @query: The query to parse
2420 * @caps: (out) (transfer none): A pointer to the caps
2422 * Get the caps from @query. The caps remains valid as long as @query remains
2426 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2428 GstStructure *structure;
2430 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2431 g_return_if_fail (caps != NULL);
2433 structure = GST_QUERY_STRUCTURE (query);
2434 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2439 * gst_query_set_accept_caps_result:
2440 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2441 * @result: the result to set
2443 * Set @result as the result for the @query.
2446 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2448 GstStructure *structure;
2450 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2451 g_return_if_fail (gst_query_is_writable (query));
2453 structure = GST_QUERY_STRUCTURE (query);
2454 gst_structure_id_set (structure,
2455 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2459 * gst_query_parse_accept_caps_result:
2460 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2461 * @result: (out) (allow-none): location for the result
2463 * Parse the result from @query and store in @result.
2466 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2468 GstStructure *structure;
2470 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2472 structure = GST_QUERY_STRUCTURE (query);
2473 gst_structure_id_get (structure,
2474 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2478 * gst_query_new_caps:
2481 * Constructs a new query object for querying the caps.
2483 * The CAPS query should return the allowable caps for a pad in the context
2484 * of the element's state, its link to other elements, and the devices or files
2485 * it has opened. These caps must be a subset of the pad template caps. In the
2486 * NULL state with no links, the CAPS query should ideally return the same caps
2487 * as the pad template. In rare circumstances, an object property can affect
2488 * the caps returned by the CAPS query, but this is discouraged.
2490 * For most filters, the caps returned by CAPS query is directly affected by the
2491 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2492 * the srcpad's getcaps function is directly related to the stream data. Again,
2493 * the CAPS query should return the most specific caps it reasonably can, since this
2494 * helps with autoplugging.
2496 * The @filter is used to restrict the result caps, only the caps matching
2497 * @filter should be returned from the CAPS query. Specifying a filter might
2498 * greatly reduce the amount of processing an element needs to do.
2500 * Free-function: gst_query_unref()
2502 * Returns: (transfer full): a new #GstQuery
2505 gst_query_new_caps (GstCaps * filter)
2508 GstStructure *structure;
2510 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2511 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2512 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2513 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2519 * gst_query_parse_caps:
2520 * @query: The query to parse
2521 * @filter: (out) (transfer none): A pointer to the caps filter
2523 * Get the filter from the caps @query. The caps remains valid as long as
2524 * @query remains valid.
2527 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2529 GstStructure *structure;
2531 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2532 g_return_if_fail (filter != NULL);
2534 structure = GST_QUERY_STRUCTURE (query);
2535 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2536 GST_QUARK (FILTER)));
2540 * gst_query_set_caps_result:
2541 * @query: The query to use
2542 * @caps: (in): A pointer to the caps
2544 * Set the @caps result in @query.
2547 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2549 GstStructure *structure;
2551 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2552 g_return_if_fail (gst_query_is_writable (query));
2554 structure = GST_QUERY_STRUCTURE (query);
2555 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2559 * gst_query_parse_caps_result:
2560 * @query: The query to parse
2561 * @caps: (out) (transfer none): A pointer to the caps
2563 * Get the caps result from @query. The caps remains valid as long as
2564 * @query remains valid.
2567 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2569 GstStructure *structure;
2571 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2572 g_return_if_fail (caps != NULL);
2574 structure = GST_QUERY_STRUCTURE (query);
2575 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2581 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2582 GstCapsIntersectMode mode)
2584 GstCaps *res, *caps = NULL;
2586 gst_query_parse_caps_result (query, &caps);
2587 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2588 gst_query_set_caps_result (query, res);
2589 gst_caps_unref (res);
2594 * gst_query_new_drain:
2596 * Constructs a new query object for querying the drain state.
2598 * Free-function: gst_query_unref()
2600 * Returns: (transfer full): a new #GstQuery
2603 gst_query_new_drain (void)
2606 GstStructure *structure;
2608 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2609 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2615 * gst_query_new_context:
2616 * @context_type: Context type to query
2618 * Constructs a new query object for querying the pipeline-local context.
2620 * Free-function: gst_query_unref()
2622 * Returns: (transfer full): a new #GstQuery
2627 gst_query_new_context (const gchar * context_type)
2630 GstStructure *structure;
2632 g_return_val_if_fail (context_type != NULL, NULL);
2634 structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
2635 GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2636 query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
2642 * gst_query_set_context:
2643 * @query: a #GstQuery with query type GST_QUERY_CONTEXT
2644 * @context: the requested #GstContext
2646 * Answer a context query by setting the requested context.
2651 gst_query_set_context (GstQuery * query, GstContext * context)
2654 const gchar *context_type;
2656 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2658 gst_query_parse_context_type (query, &context_type);
2659 g_return_if_fail (strcmp (gst_context_get_context_type (context),
2660 context_type) == 0);
2662 s = GST_QUERY_STRUCTURE (query);
2664 gst_structure_id_set (s,
2665 GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2669 * gst_query_parse_context:
2670 * @query: The query to parse
2671 * @context: (out) (transfer none): A pointer to store the #GstContext
2673 * Get the context from the context @query. The context remains valid as long as
2674 * @query remains valid.
2679 gst_query_parse_context (GstQuery * query, GstContext ** context)
2681 GstStructure *structure;
2684 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2685 g_return_if_fail (context != NULL);
2687 structure = GST_QUERY_STRUCTURE (query);
2688 v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
2690 *context = g_value_get_boxed (v);
2696 * gst_query_parse_context_type:
2697 * @query: a GST_QUERY_CONTEXT type query
2698 * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
2700 * Parse a context type from an existing GST_QUERY_CONTEXT query.
2702 * Returns: a #gboolean indicating if the parsing succeeded.
2707 gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
2709 GstStructure *structure;
2710 const GValue *value;
2712 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2714 structure = GST_QUERY_STRUCTURE (query);
2717 value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2718 *context_type = g_value_get_string (value);
2725 * gst_query_new_bitrate:
2727 * Constructs a new query object for querying the bitrate.
2729 * Free-function: gst_query_unref()
2731 * Returns: (transfer full): a new #GstQuery
2736 gst_query_new_bitrate (void)
2739 GstStructure *structure;
2741 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_BITRATE));
2742 query = gst_query_new_custom (GST_QUERY_BITRATE, structure);
2748 * gst_query_set_bitrate:
2749 * @query: a GST_QUERY_BITRATE type #GstQuery
2750 * @nominal_bitrate: the nominal bitrate in bits per second
2752 * Set the results of a bitrate query. The nominal bitrate is the average
2753 * bitrate expected over the length of the stream as advertised in file
2754 * headers (or similar).
2759 gst_query_set_bitrate (GstQuery * query, guint nominal_bitrate)
2763 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
2765 s = GST_QUERY_STRUCTURE (query);
2767 gst_structure_id_set (s,
2768 GST_QUARK (NOMINAL_BITRATE), G_TYPE_UINT, nominal_bitrate, NULL);
2772 * gst_query_parse_bitrate:
2773 * @query: a GST_QUERY_BITRATE type #GstQuery
2774 * @nominal_bitrate: (out) (allow-none): The resulting bitrate in bits per second
2776 * Get the results of a bitrate query. See also gst_query_set_bitrate().
2781 gst_query_parse_bitrate (GstQuery * query, guint * nominal_bitrate)
2783 GstStructure *structure;
2784 const GValue *value;
2786 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
2788 structure = GST_QUERY_STRUCTURE (query);
2790 if (nominal_bitrate) {
2791 value = gst_structure_id_get_value (structure, GST_QUARK (NOMINAL_BITRATE));
2792 *nominal_bitrate = g_value_get_uint (value);