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.
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:
39 * |[<!-- language="C" -->
42 * query = gst_query_new_duration (GST_FORMAT_TIME);
43 * res = gst_element_query (pipeline, query);
46 * gst_query_parse_duration (query, NULL, &duration);
47 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
49 * g_print ("duration query failed...");
51 * gst_query_unref (query);
56 #include "gst_private.h"
60 #include "gstenumtypes.h"
63 #include "gstbufferpool.h"
65 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
66 #define GST_CAT_DEFAULT gst_query_debug
68 GType _gst_query_type = 0;
74 GstStructure *structure;
77 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
87 static GstQueryQuarks query_quarks[] = {
88 {GST_QUERY_UNKNOWN, "unknown", 0},
89 {GST_QUERY_POSITION, "position", 0},
90 {GST_QUERY_DURATION, "duration", 0},
91 {GST_QUERY_LATENCY, "latency", 0},
92 {GST_QUERY_JITTER, "jitter", 0},
93 {GST_QUERY_RATE, "rate", 0},
94 {GST_QUERY_SEEKING, "seeking", 0},
95 {GST_QUERY_SEGMENT, "segment", 0},
96 {GST_QUERY_CONVERT, "convert", 0},
97 {GST_QUERY_FORMATS, "formats", 0},
98 {GST_QUERY_BUFFERING, "buffering", 0},
99 {GST_QUERY_CUSTOM, "custom", 0},
100 {GST_QUERY_URI, "uri", 0},
101 {GST_QUERY_ALLOCATION, "allocation", 0},
102 {GST_QUERY_SCHEDULING, "scheduling", 0},
103 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
104 {GST_QUERY_CAPS, "caps", 0},
105 {GST_QUERY_DRAIN, "drain", 0},
106 {GST_QUERY_CONTEXT, "context", 0},
111 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
114 _priv_gst_query_initialize (void)
118 _gst_query_type = gst_query_get_type ();
120 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
122 for (i = 0; query_quarks[i].name; i++) {
123 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
128 * gst_query_type_get_name:
129 * @type: the query type
131 * Get a printable name for the given query type. Do not modify or free.
133 * Returns: a reference to the static name of the query.
136 gst_query_type_get_name (GstQueryType type)
140 for (i = 0; query_quarks[i].name; i++) {
141 if (type == query_quarks[i].type)
142 return query_quarks[i].name;
148 * gst_query_type_to_quark:
149 * @type: the query type
151 * Get the unique quark for the given query type.
153 * Returns: the quark associated with the query type
156 gst_query_type_to_quark (GstQueryType type)
160 for (i = 0; query_quarks[i].name; i++) {
161 if (type == query_quarks[i].type)
162 return query_quarks[i].quark;
168 * gst_query_type_get_flags:
169 * @type: a #GstQueryType
171 * Gets the #GstQueryTypeFlags associated with @type.
173 * Returns: a #GstQueryTypeFlags.
176 gst_query_type_get_flags (GstQueryType type)
178 GstQueryTypeFlags ret;
180 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
186 _gst_query_free (GstQuery * query)
190 g_return_if_fail (query != NULL);
192 s = GST_QUERY_STRUCTURE (query);
194 gst_structure_set_parent_refcount (s, NULL);
195 gst_structure_free (s);
198 g_slice_free1 (sizeof (GstQueryImpl), query);
202 _gst_query_copy (GstQuery * query)
207 s = GST_QUERY_STRUCTURE (query);
209 s = gst_structure_copy (s);
211 copy = gst_query_new_custom (query->type, s);
217 * gst_query_new_position:
218 * @format: the default #GstFormat for the new query
220 * Constructs a new query stream position query object. Use gst_query_unref()
221 * when done with it. A position query is used to query the current position
222 * of playback in the streams, in some format.
224 * Free-function: gst_query_unref()
226 * Returns: (transfer full): a new #GstQuery
229 gst_query_new_position (GstFormat format)
232 GstStructure *structure;
234 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
235 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
236 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
238 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
244 * gst_query_set_position:
245 * @query: a #GstQuery with query type GST_QUERY_POSITION
246 * @format: the requested #GstFormat
247 * @cur: the position to set
249 * Answer a position query by setting the requested value in the given format.
252 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
256 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
258 s = GST_QUERY_STRUCTURE (query);
259 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
260 GST_QUARK (FORMAT))));
262 gst_structure_id_set (s,
263 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
264 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
268 * gst_query_parse_position:
269 * @query: a #GstQuery
270 * @format: (out) (allow-none): the storage for the #GstFormat of the
271 * position values (may be %NULL)
272 * @cur: (out) (allow-none): the storage for the current position (may be %NULL)
274 * Parse a position query, writing the format into @format, and the position
275 * into @cur, if the respective parameters are non-%NULL.
278 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
280 GstStructure *structure;
282 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
284 structure = GST_QUERY_STRUCTURE (query);
287 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
288 GST_QUARK (FORMAT)));
290 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
291 GST_QUARK (CURRENT)));
296 * gst_query_new_duration:
297 * @format: the #GstFormat for this duration query
299 * Constructs a new stream duration query object to query in the given format.
300 * Use gst_query_unref() when done with it. A duration query will give the
301 * total length of the stream.
303 * Free-function: gst_query_unref()
305 * Returns: (transfer full): a new #GstQuery
308 gst_query_new_duration (GstFormat format)
311 GstStructure *structure;
313 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
314 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
315 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
317 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
323 * gst_query_set_duration:
324 * @query: a #GstQuery
325 * @format: the #GstFormat for the duration
326 * @duration: the duration of the stream
328 * Answer a duration query by setting the requested value in the given format.
331 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
335 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
337 s = GST_QUERY_STRUCTURE (query);
338 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
339 GST_QUARK (FORMAT))));
340 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
341 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
345 * gst_query_parse_duration:
346 * @query: a #GstQuery
347 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
349 * @duration: (out) (allow-none): the storage for the total duration, or %NULL.
351 * Parse a duration query answer. Write the format of the duration into @format,
352 * and the value into @duration, if the respective variables are non-%NULL.
355 gst_query_parse_duration (GstQuery * query, GstFormat * format,
358 GstStructure *structure;
360 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
362 structure = GST_QUERY_STRUCTURE (query);
365 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
366 GST_QUARK (FORMAT)));
368 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
369 GST_QUARK (DURATION)));
373 * gst_query_new_latency:
375 * Constructs a new latency query object.
376 * Use gst_query_unref() when done with it. A latency query is usually performed
377 * by sinks to compensate for additional latency introduced by elements in the
380 * Free-function: gst_query_unref()
382 * Returns: (transfer full): a #GstQuery
385 gst_query_new_latency (void)
388 GstStructure *structure;
390 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
391 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
392 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
393 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, GST_CLOCK_TIME_NONE, NULL);
395 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
401 * gst_query_set_latency:
402 * @query: a #GstQuery
403 * @live: if there is a live element upstream
404 * @min_latency: the minimal latency of the upstream elements
405 * @max_latency: the maximal latency of the upstream elements
407 * Answer a latency query by setting the requested values in the given format.
410 gst_query_set_latency (GstQuery * query, gboolean live,
411 GstClockTime min_latency, GstClockTime max_latency)
413 GstStructure *structure;
415 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
416 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
418 structure = GST_QUERY_STRUCTURE (query);
419 gst_structure_id_set (structure,
420 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
421 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
422 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
426 * gst_query_parse_latency:
427 * @query: a #GstQuery
428 * @live: (out) (allow-none): storage for live or %NULL
429 * @min_latency: (out) (allow-none): the storage for the min latency or %NULL
430 * @max_latency: (out) (allow-none): the storage for the max latency or %NULL
432 * Parse a latency query answer.
435 gst_query_parse_latency (GstQuery * query, gboolean * live,
436 GstClockTime * min_latency, GstClockTime * max_latency)
438 GstStructure *structure;
440 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
442 structure = GST_QUERY_STRUCTURE (query);
445 g_value_get_boolean (gst_structure_id_get_value (structure,
448 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
449 GST_QUARK (MIN_LATENCY)));
451 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
452 GST_QUARK (MAX_LATENCY)));
456 * gst_query_new_convert:
457 * @src_format: the source #GstFormat for the new query
458 * @value: the value to convert
459 * @dest_format: the target #GstFormat
461 * Constructs a new convert query object. Use gst_query_unref()
462 * when done with it. A convert query is used to ask for a conversion between
463 * one format and another.
465 * Free-function: gst_query_unref()
467 * Returns: (transfer full): a #GstQuery
470 gst_query_new_convert (GstFormat src_format, gint64 value,
471 GstFormat dest_format)
474 GstStructure *structure;
476 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
477 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
478 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
479 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
480 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
482 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
488 * gst_query_set_convert:
489 * @query: a #GstQuery
490 * @src_format: the source #GstFormat
491 * @src_value: the source value
492 * @dest_format: the destination #GstFormat
493 * @dest_value: the destination value
495 * Answer a convert query by setting the requested values.
498 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
499 GstFormat dest_format, gint64 dest_value)
501 GstStructure *structure;
503 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
505 structure = GST_QUERY_STRUCTURE (query);
506 gst_structure_id_set (structure,
507 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
508 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
509 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
510 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
514 * gst_query_parse_convert:
515 * @query: a #GstQuery
516 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
517 * source value, or %NULL
518 * @src_value: (out) (allow-none): the storage for the source value, or %NULL
519 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
520 * destination value, or %NULL
521 * @dest_value: (out) (allow-none): the storage for the destination value,
524 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
525 * and @dest_value may be %NULL, in which case that value is omitted.
528 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
529 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
531 GstStructure *structure;
533 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
535 structure = GST_QUERY_STRUCTURE (query);
538 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
539 GST_QUARK (SRC_FORMAT)));
541 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
542 GST_QUARK (SRC_VALUE)));
545 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
546 GST_QUARK (DEST_FORMAT)));
548 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
549 GST_QUARK (DEST_VALUE)));
553 * gst_query_new_segment:
554 * @format: the #GstFormat for the new query
556 * Constructs a new segment query object. Use gst_query_unref()
557 * when done with it. A segment query is used to discover information about the
558 * currently configured segment for playback.
560 * Free-function: gst_query_unref()
562 * Returns: (transfer full): a new #GstQuery
565 gst_query_new_segment (GstFormat format)
568 GstStructure *structure;
570 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
571 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
572 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
573 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
574 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
576 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
582 * gst_query_set_segment:
583 * @query: a #GstQuery
584 * @rate: the rate of the segment
585 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
586 * @start_value: the start value
587 * @stop_value: the stop value
589 * Answer a segment query by setting the requested values. The normal
590 * playback segment of a pipeline is 0 to duration at the default rate of
591 * 1.0. If a seek was performed on the pipeline to play a different
592 * segment, this query will return the range specified in the last seek.
594 * @start_value and @stop_value will respectively contain the configured
595 * playback range start and stop values expressed in @format.
596 * The values are always between 0 and the duration of the media and
597 * @start_value <= @stop_value. @rate will contain the playback rate. For
598 * negative rates, playback will actually happen from @stop_value to
602 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
603 gint64 start_value, gint64 stop_value)
605 GstStructure *structure;
607 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
609 structure = GST_QUERY_STRUCTURE (query);
610 gst_structure_id_set (structure,
611 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
612 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
613 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
614 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
618 * gst_query_parse_segment:
619 * @query: a #GstQuery
620 * @rate: (out) (allow-none): the storage for the rate of the segment, or %NULL
621 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
623 * @start_value: (out) (allow-none): the storage for the start value, or %NULL
624 * @stop_value: (out) (allow-none): the storage for the stop value, or %NULL
626 * Parse a segment query answer. Any of @rate, @format, @start_value, and
627 * @stop_value may be %NULL, which will cause this value to be omitted.
629 * See gst_query_set_segment() for an explanation of the function arguments.
632 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
633 gint64 * start_value, gint64 * stop_value)
635 GstStructure *structure;
637 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
639 structure = GST_QUERY_STRUCTURE (query);
641 *rate = g_value_get_double (gst_structure_id_get_value (structure,
645 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
646 GST_QUARK (FORMAT)));
648 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
649 GST_QUARK (START_VALUE)));
651 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
652 GST_QUARK (STOP_VALUE)));
656 * gst_query_new_custom:
657 * @type: the query type
658 * @structure: (allow-none) (transfer full): a structure for the query
660 * Constructs a new custom query object. Use gst_query_unref()
663 * Free-function: gst_query_unref()
665 * Returns: (transfer full): a new #GstQuery
668 gst_query_new_custom (GstQueryType type, GstStructure * structure)
672 query = g_slice_new0 (GstQueryImpl);
674 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
677 /* structure must not have a parent */
678 if (!gst_structure_set_parent_refcount (structure,
679 &query->query.mini_object.refcount))
683 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
684 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
685 (GstMiniObjectFreeFunction) _gst_query_free);
687 GST_QUERY_TYPE (query) = type;
688 GST_QUERY_STRUCTURE (query) = structure;
690 return GST_QUERY_CAST (query);
695 g_slice_free1 (sizeof (GstQueryImpl), query);
696 g_warning ("structure is already owned by another object");
702 * gst_query_get_structure:
703 * @query: a #GstQuery
705 * Get the structure of a query.
707 * Returns: (transfer none): the #GstStructure of the query. The structure is
708 * still owned by the query and will therefore be freed when the query
712 gst_query_get_structure (GstQuery * query)
714 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
716 return GST_QUERY_STRUCTURE (query);
720 * gst_query_writable_structure:
721 * @query: a #GstQuery
723 * Get the structure of a query. This method should be called with a writable
724 * @query so that the returned structure is guaranteed to be writable.
726 * Returns: (transfer none): the #GstStructure of the query. The structure is
727 * still owned by the query and will therefore be freed when the query
731 gst_query_writable_structure (GstQuery * query)
733 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
734 g_return_val_if_fail (gst_query_is_writable (query), NULL);
736 return GST_QUERY_STRUCTURE (query);
740 * gst_query_new_seeking:
741 * @format: the default #GstFormat for the new query
743 * Constructs a new query object for querying seeking properties of
746 * Free-function: gst_query_unref()
748 * Returns: (transfer full): a new #GstQuery
751 gst_query_new_seeking (GstFormat format)
754 GstStructure *structure;
756 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
757 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
758 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
759 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
760 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
762 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
768 * gst_query_set_seeking:
769 * @query: a #GstQuery
770 * @format: the format to set for the @segment_start and @segment_end values
771 * @seekable: the seekable flag to set
772 * @segment_start: the segment_start to set
773 * @segment_end: the segment_end to set
775 * Set the seeking query result fields in @query.
778 gst_query_set_seeking (GstQuery * query, GstFormat format,
779 gboolean seekable, gint64 segment_start, gint64 segment_end)
781 GstStructure *structure;
783 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
784 g_return_if_fail (gst_query_is_writable (query));
786 structure = GST_QUERY_STRUCTURE (query);
787 gst_structure_id_set (structure,
788 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
789 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
790 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
791 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
795 * gst_query_parse_seeking:
796 * @query: a GST_QUERY_SEEKING type query #GstQuery
797 * @format: (out) (allow-none): the format to set for the @segment_start
798 * and @segment_end values, or %NULL
799 * @seekable: (out) (allow-none): the seekable flag to set, or %NULL
800 * @segment_start: (out) (allow-none): the segment_start to set, or %NULL
801 * @segment_end: (out) (allow-none): the segment_end to set, or %NULL
803 * Parse a seeking query, writing the format into @format, and
804 * other results into the passed parameters, if the respective parameters
808 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
809 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
811 GstStructure *structure;
813 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
815 structure = GST_QUERY_STRUCTURE (query);
818 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
819 GST_QUARK (FORMAT)));
821 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
822 GST_QUARK (SEEKABLE)));
824 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
825 GST_QUARK (SEGMENT_START)));
827 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
828 GST_QUARK (SEGMENT_END)));
832 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
833 GDestroyNotify clear_func)
838 value = gst_structure_id_get_value (s, quark);
840 array = (GArray *) g_value_get_boxed (value);
842 GValue new_array_val = { 0, };
844 array = g_array_new (FALSE, TRUE, element_size);
846 g_array_set_clear_func (array, clear_func);
848 g_value_init (&new_array_val, G_TYPE_ARRAY);
849 g_value_take_boxed (&new_array_val, array);
851 gst_structure_id_take_value (s, quark, &new_array_val);
857 * gst_query_new_formats:
859 * Constructs a new query object for querying formats of
862 * Free-function: gst_query_unref()
864 * Returns: (transfer full): a new #GstQuery
867 gst_query_new_formats (void)
870 GstStructure *structure;
872 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
873 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
879 gst_query_list_add_format (GValue * list, GstFormat format)
881 GValue item = { 0, };
883 g_value_init (&item, GST_TYPE_FORMAT);
884 g_value_set_enum (&item, format);
885 gst_value_list_append_value (list, &item);
886 g_value_unset (&item);
890 * gst_query_set_formats:
891 * @query: a #GstQuery
892 * @n_formats: the number of formats to set.
893 * @...: A number of @GstFormats equal to @n_formats.
895 * Set the formats query result fields in @query. The number of formats passed
896 * must be equal to @n_formats.
899 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
902 GValue list = { 0, };
904 GstStructure *structure;
906 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
907 g_return_if_fail (gst_query_is_writable (query));
909 g_value_init (&list, GST_TYPE_LIST);
911 va_start (ap, n_formats);
912 for (i = 0; i < n_formats; i++) {
913 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
917 structure = GST_QUERY_STRUCTURE (query);
918 gst_structure_set_value (structure, "formats", &list);
920 g_value_unset (&list);
925 * gst_query_set_formatsv:
926 * @query: a #GstQuery
927 * @n_formats: the number of formats to set.
928 * @formats: (in) (array length=n_formats): an array containing @n_formats
931 * Set the formats query result fields in @query. The number of formats passed
932 * in the @formats array must be equal to @n_formats.
935 gst_query_set_formatsv (GstQuery * query, gint n_formats,
936 const GstFormat * formats)
938 GValue list = { 0, };
940 GstStructure *structure;
942 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
943 g_return_if_fail (gst_query_is_writable (query));
945 g_value_init (&list, GST_TYPE_LIST);
946 for (i = 0; i < n_formats; i++) {
947 gst_query_list_add_format (&list, formats[i]);
949 structure = GST_QUERY_STRUCTURE (query);
950 gst_structure_set_value (structure, "formats", &list);
952 g_value_unset (&list);
956 * gst_query_parse_n_formats:
957 * @query: a #GstQuery
958 * @n_formats: (out) (allow-none): the number of formats in this query.
960 * Parse the number of formats in the formats @query.
963 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
965 GstStructure *structure;
967 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
972 structure = GST_QUERY_STRUCTURE (query);
973 list = gst_structure_get_value (structure, "formats");
977 *n_formats = gst_value_list_get_size (list);
982 * gst_query_parse_nth_format:
983 * @query: a #GstQuery
984 * @nth: (out): the nth format to retrieve.
985 * @format: (out) (allow-none): a pointer to store the nth format
987 * Parse the format query and retrieve the @nth format from it into
988 * @format. If the list contains less elements than @nth, @format will be
989 * set to GST_FORMAT_UNDEFINED.
992 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
994 GstStructure *structure;
996 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1001 structure = GST_QUERY_STRUCTURE (query);
1002 list = gst_structure_get_value (structure, "formats");
1004 *format = GST_FORMAT_UNDEFINED;
1006 if (nth < gst_value_list_get_size (list)) {
1008 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1010 *format = GST_FORMAT_UNDEFINED;
1016 * gst_query_new_buffering:
1017 * @format: the default #GstFormat for the new query
1019 * Constructs a new query object for querying the buffering status of
1022 * Free-function: gst_query_unref()
1024 * Returns: (transfer full): a new #GstQuery
1027 gst_query_new_buffering (GstFormat format)
1030 GstStructure *structure;
1032 /* by default, we configure the answer as no buffering with a 100% buffering
1034 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1035 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1036 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1037 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1038 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1039 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1040 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1041 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1042 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1043 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1044 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1046 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1052 * gst_query_set_buffering_percent:
1053 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1054 * @busy: if buffering is busy
1055 * @percent: a buffering percent
1057 * Set the percentage of buffered data. This is a value between 0 and 100.
1058 * The @busy indicator is %TRUE when the buffering is in progress.
1061 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1063 GstStructure *structure;
1065 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1066 g_return_if_fail (gst_query_is_writable (query));
1067 g_return_if_fail (percent >= 0 && percent <= 100);
1069 structure = GST_QUERY_STRUCTURE (query);
1070 gst_structure_id_set (structure,
1071 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1072 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1076 * gst_query_parse_buffering_percent:
1077 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1078 * @busy: (out) (allow-none): if buffering is busy, or %NULL
1079 * @percent: (out) (allow-none): a buffering percent, or %NULL
1081 * Get the percentage of buffered data. This is a value between 0 and 100.
1082 * The @busy indicator is %TRUE when the buffering is in progress.
1085 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1088 GstStructure *structure;
1090 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1092 structure = GST_QUERY_STRUCTURE (query);
1094 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1097 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1098 GST_QUARK (BUFFER_PERCENT)));
1102 * gst_query_set_buffering_stats:
1103 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1104 * @mode: a buffering mode
1105 * @avg_in: the average input rate
1106 * @avg_out: the average output rate
1107 * @buffering_left: amount of buffering time left in milliseconds
1109 * Configures the buffering stats values in @query.
1112 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1113 gint avg_in, gint avg_out, gint64 buffering_left)
1115 GstStructure *structure;
1117 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1118 g_return_if_fail (gst_query_is_writable (query));
1120 structure = GST_QUERY_STRUCTURE (query);
1121 gst_structure_id_set (structure,
1122 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1123 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1124 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1125 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1129 * gst_query_parse_buffering_stats:
1130 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1131 * @mode: (out) (allow-none): a buffering mode, or %NULL
1132 * @avg_in: (out) (allow-none): the average input rate, or %NULL
1133 * @avg_out: (out) (allow-none): the average output rat, or %NULL
1134 * @buffering_left: (out) (allow-none): amount of buffering time left in
1135 * milliseconds, or %NULL
1137 * Extracts the buffering stats values from @query.
1140 gst_query_parse_buffering_stats (GstQuery * query,
1141 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1142 gint64 * buffering_left)
1144 GstStructure *structure;
1146 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1148 structure = GST_QUERY_STRUCTURE (query);
1150 *mode = (GstBufferingMode)
1151 g_value_get_enum (gst_structure_id_get_value (structure,
1152 GST_QUARK (BUFFERING_MODE)));
1154 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1155 GST_QUARK (AVG_IN_RATE)));
1157 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1158 GST_QUARK (AVG_OUT_RATE)));
1161 g_value_get_int64 (gst_structure_id_get_value (structure,
1162 GST_QUARK (BUFFERING_LEFT)));
1166 * gst_query_set_buffering_range:
1167 * @query: a #GstQuery
1168 * @format: the format to set for the @start and @stop values
1169 * @start: the start to set
1170 * @stop: the stop to set
1171 * @estimated_total: estimated total amount of download time remaining in
1174 * Set the available query result fields in @query.
1177 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1178 gint64 start, gint64 stop, gint64 estimated_total)
1180 GstStructure *structure;
1182 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1183 g_return_if_fail (gst_query_is_writable (query));
1185 structure = GST_QUERY_STRUCTURE (query);
1186 gst_structure_id_set (structure,
1187 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1188 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1189 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1190 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1194 * gst_query_parse_buffering_range:
1195 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1196 * @format: (out) (allow-none): the format to set for the @segment_start
1197 * and @segment_end values, or %NULL
1198 * @start: (out) (allow-none): the start to set, or %NULL
1199 * @stop: (out) (allow-none): the stop to set, or %NULL
1200 * @estimated_total: (out) (allow-none): estimated total amount of download
1201 * time remaining in milliseconds, or %NULL
1203 * Parse an available query, writing the format into @format, and
1204 * other results into the passed parameters, if the respective parameters
1208 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1209 gint64 * start, gint64 * stop, gint64 * estimated_total)
1211 GstStructure *structure;
1213 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1215 structure = GST_QUERY_STRUCTURE (query);
1218 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1219 GST_QUARK (FORMAT)));
1221 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1222 GST_QUARK (START_VALUE)));
1224 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1225 GST_QUARK (STOP_VALUE)));
1226 if (estimated_total)
1228 g_value_get_int64 (gst_structure_id_get_value (structure,
1229 GST_QUARK (ESTIMATED_TOTAL)));
1232 /* GstQueryBufferingRange: internal struct for GArray */
1237 } GstQueryBufferingRange;
1240 * gst_query_add_buffering_range:
1241 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1242 * @start: start position of the range
1243 * @stop: stop position of the range
1245 * Set the buffering-ranges array field in @query. The current last
1246 * start position of the array should be inferior to @start.
1248 * Returns: a #gboolean indicating if the range was added or not.
1251 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1253 GstQueryBufferingRange range;
1254 GstStructure *structure;
1257 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1258 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1260 if (G_UNLIKELY (start >= stop))
1263 structure = GST_QUERY_STRUCTURE (query);
1264 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1265 sizeof (GstQueryBufferingRange), NULL);
1267 if (array->len > 1) {
1268 GstQueryBufferingRange *last;
1270 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1272 if (G_UNLIKELY (start <= last->start))
1276 range.start = start;
1278 g_array_append_val (array, range);
1284 * gst_query_get_n_buffering_ranges:
1285 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1287 * Retrieve the number of values currently stored in the
1288 * buffered-ranges array of the query's structure.
1290 * Returns: the range array size as a #guint.
1293 gst_query_get_n_buffering_ranges (GstQuery * query)
1295 GstStructure *structure;
1298 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1300 structure = GST_QUERY_STRUCTURE (query);
1301 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1302 sizeof (GstQueryBufferingRange), NULL);
1309 * gst_query_parse_nth_buffering_range:
1310 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1311 * @index: position in the buffered-ranges array to read
1312 * @start: (out) (allow-none): the start position to set, or %NULL
1313 * @stop: (out) (allow-none): the stop position to set, or %NULL
1315 * Parse an available query and get the start and stop values stored
1316 * at the @index of the buffered ranges array.
1318 * Returns: a #gboolean indicating if the parsing succeeded.
1321 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1322 gint64 * start, gint64 * stop)
1324 GstQueryBufferingRange *range;
1325 GstStructure *structure;
1328 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1330 structure = GST_QUERY_STRUCTURE (query);
1332 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1333 sizeof (GstQueryBufferingRange), NULL);
1334 g_return_val_if_fail (index < array->len, FALSE);
1336 range = &g_array_index (array, GstQueryBufferingRange, index);
1339 *start = range->start;
1341 *stop = range->stop;
1348 * gst_query_new_uri:
1350 * Constructs a new query URI query object. Use gst_query_unref()
1351 * when done with it. An URI query is used to query the current URI
1352 * that is used by the source or sink.
1354 * Free-function: gst_query_unref()
1356 * Returns: (transfer full): a new #GstQuery
1359 gst_query_new_uri (void)
1362 GstStructure *structure;
1364 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1365 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1367 query = gst_query_new_custom (GST_QUERY_URI, structure);
1373 * gst_query_set_uri:
1374 * @query: a #GstQuery with query type GST_QUERY_URI
1375 * @uri: the URI to set
1377 * Answer a URI query by setting the requested URI.
1380 gst_query_set_uri (GstQuery * query, const gchar * uri)
1382 GstStructure *structure;
1384 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1385 g_return_if_fail (gst_query_is_writable (query));
1386 g_return_if_fail (gst_uri_is_valid (uri));
1388 structure = GST_QUERY_STRUCTURE (query);
1389 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1393 * gst_query_parse_uri:
1394 * @query: a #GstQuery
1395 * @uri: (out) (transfer full) (allow-none): the storage for the current URI
1398 * Parse an URI query, writing the URI into @uri as a newly
1399 * allocated string, if the respective parameters are non-%NULL.
1400 * Free the string with g_free() after usage.
1403 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1405 GstStructure *structure;
1407 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1409 structure = GST_QUERY_STRUCTURE (query);
1411 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1416 * gst_query_set_uri_redirection:
1417 * @query: a #GstQuery with query type GST_QUERY_URI
1418 * @uri: the URI to set
1420 * Answer a URI query by setting the requested URI redirection.
1425 gst_query_set_uri_redirection (GstQuery * query, const gchar * uri)
1427 GstStructure *structure;
1429 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1430 g_return_if_fail (gst_query_is_writable (query));
1431 g_return_if_fail (gst_uri_is_valid (uri));
1433 structure = GST_QUERY_STRUCTURE (query);
1434 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
1435 G_TYPE_STRING, uri, NULL);
1439 * gst_query_parse_uri_redirection:
1440 * @query: a #GstQuery
1441 * @uri: (out) (transfer full) (allow-none): the storage for the redirect URI
1444 * Parse an URI query, writing the URI into @uri as a newly
1445 * allocated string, if the respective parameters are non-%NULL.
1446 * Free the string with g_free() after usage.
1451 gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
1453 GstStructure *structure;
1455 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1457 structure = GST_QUERY_STRUCTURE (query);
1459 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION),
1460 G_TYPE_STRING, uri, NULL))
1466 * gst_query_set_uri_redirection_permanent:
1467 * @query: a #GstQuery with query type %GST_QUERY_URI
1468 * @permanent: whether the redirect is permanent or not
1470 * Answer a URI query by setting the requested URI redirection
1471 * to permanent or not.
1476 gst_query_set_uri_redirection_permanent (GstQuery * query, gboolean permanent)
1478 GstStructure *structure;
1480 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1481 g_return_if_fail (gst_query_is_writable (query));
1483 structure = GST_QUERY_STRUCTURE (query);
1484 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1485 G_TYPE_BOOLEAN, permanent, NULL);
1489 * gst_query_parse_uri_redirection_permanent:
1490 * @query: a #GstQuery
1491 * @permanent: (out) (allow-none): if the URI redirection is permanent
1494 * Parse an URI query, and set @permanent to %TRUE if there is a redirection
1495 * and it should be considered permanent. If a redirection is permanent,
1496 * applications should update their internal storage of the URI, otherwise
1497 * they should make all future requests to the original URI.
1502 gst_query_parse_uri_redirection_permanent (GstQuery * query,
1503 gboolean * permanent)
1505 GstStructure *structure;
1507 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1509 structure = GST_QUERY_STRUCTURE (query);
1511 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1512 G_TYPE_BOOLEAN, permanent, NULL))
1518 * gst_query_new_allocation:
1519 * @caps: the negotiated caps
1520 * @need_pool: return a pool
1522 * Constructs a new query object for querying the allocation properties.
1524 * Free-function: gst_query_unref()
1526 * Returns: (transfer full): a new #GstQuery
1529 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1532 GstStructure *structure;
1534 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1535 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1536 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1538 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1544 * gst_query_parse_allocation:
1545 * @query: a #GstQuery
1546 * @caps: (out) (transfer none) (allow-none): The #GstCaps
1547 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1549 * Parse an allocation query, writing the requested caps in @caps and
1550 * whether a pool is needed in @need_pool, if the respective parameters
1553 * Pool details can be retrieved using gst_query_get_n_allocation_pools() and
1554 * gst_query_parse_nth_allocation_pool().
1557 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1558 gboolean * need_pool)
1560 GstStructure *structure;
1562 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1564 structure = GST_QUERY_STRUCTURE (query);
1566 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1569 gst_structure_id_get (structure,
1570 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1575 GstBufferPool *pool;
1582 allocation_pool_free (AllocationPool * ap)
1585 gst_object_unref (ap->pool);
1589 * gst_query_add_allocation_pool:
1590 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1591 * @pool: (transfer none) (allow-none): the #GstBufferPool
1592 * @size: the buffer size
1593 * @min_buffers: the min buffers
1594 * @max_buffers: the max buffers
1596 * Set the pool parameters in @query.
1599 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1600 guint size, guint min_buffers, guint max_buffers)
1603 GstStructure *structure;
1606 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1607 g_return_if_fail (gst_query_is_writable (query));
1609 structure = GST_QUERY_STRUCTURE (query);
1610 array = ensure_array (structure, GST_QUARK (POOL),
1611 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1613 if ((ap.pool = pool))
1614 gst_object_ref (pool);
1616 ap.min_buffers = min_buffers;
1617 ap.max_buffers = max_buffers;
1619 g_array_append_val (array, ap);
1623 * gst_query_get_n_allocation_pools:
1624 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1626 * Retrieve the number of values currently stored in the
1627 * pool array of the query's structure.
1629 * Returns: the pool array size as a #guint.
1632 gst_query_get_n_allocation_pools (GstQuery * query)
1635 GstStructure *structure;
1637 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1639 structure = GST_QUERY_STRUCTURE (query);
1640 array = ensure_array (structure, GST_QUARK (POOL),
1641 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1647 * gst_query_parse_nth_allocation_pool:
1648 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1649 * @index: index to parse
1650 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1651 * @size: (out) (allow-none): the buffer size
1652 * @min_buffers: (out) (allow-none): the min buffers
1653 * @max_buffers: (out) (allow-none): the max buffers
1655 * Get the pool parameters in @query.
1657 * Unref @pool with gst_object_unref() when it's not needed any more.
1660 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1661 GstBufferPool ** pool, guint * size, guint * min_buffers,
1662 guint * max_buffers)
1665 GstStructure *structure;
1668 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1670 structure = GST_QUERY_STRUCTURE (query);
1671 array = ensure_array (structure, GST_QUARK (POOL),
1672 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1673 g_return_if_fail (index < array->len);
1675 ap = &g_array_index (array, AllocationPool, index);
1678 if ((*pool = ap->pool))
1679 gst_object_ref (*pool);
1683 *min_buffers = ap->min_buffers;
1685 *max_buffers = ap->max_buffers;
1689 * gst_query_set_nth_allocation_pool:
1690 * @index: index to modify
1691 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1692 * @pool: (transfer none) (allow-none): the #GstBufferPool
1694 * @min_buffers: the min buffers
1695 * @max_buffers: the max buffers
1697 * Set the pool parameters in @query.
1700 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1701 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1704 GstStructure *structure;
1705 AllocationPool *oldap, ap;
1707 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1709 structure = GST_QUERY_STRUCTURE (query);
1710 array = ensure_array (structure, GST_QUARK (POOL),
1711 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1712 g_return_if_fail (index < array->len);
1714 oldap = &g_array_index (array, AllocationPool, index);
1715 allocation_pool_free (oldap);
1717 if ((ap.pool = pool))
1718 gst_object_ref (pool);
1720 ap.min_buffers = min_buffers;
1721 ap.max_buffers = max_buffers;
1722 g_array_index (array, AllocationPool, index) = ap;
1726 * gst_query_remove_nth_allocation_pool:
1727 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1728 * @index: position in the allocation pool array to remove
1730 * Remove the allocation pool at @index of the allocation pool array.
1735 gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
1738 GstStructure *structure;
1740 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1741 g_return_if_fail (gst_query_is_writable (query));
1743 structure = GST_QUERY_STRUCTURE (query);
1745 ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
1746 (GDestroyNotify) allocation_pool_free);
1747 g_return_if_fail (index < array->len);
1749 g_array_remove_index (array, index);
1755 GstStructure *params;
1759 allocation_meta_free (AllocationMeta * am)
1762 gst_structure_free (am->params);
1766 * gst_query_add_allocation_meta:
1767 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1768 * @api: the metadata API
1769 * @params: (transfer none) (allow-none): API specific parameters
1771 * Add @api with @params as one of the supported metadata API to @query.
1774 gst_query_add_allocation_meta (GstQuery * query, GType api,
1775 const GstStructure * params)
1778 GstStructure *structure;
1781 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1782 g_return_if_fail (api != 0);
1783 g_return_if_fail (gst_query_is_writable (query));
1785 structure = GST_QUERY_STRUCTURE (query);
1787 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1788 (GDestroyNotify) allocation_meta_free);
1791 am.params = (params ? gst_structure_copy (params) : NULL);
1793 g_array_append_val (array, am);
1797 * gst_query_get_n_allocation_metas:
1798 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1800 * Retrieve the number of values currently stored in the
1801 * meta API array of the query's structure.
1803 * Returns: the metadata API array size as a #guint.
1806 gst_query_get_n_allocation_metas (GstQuery * query)
1809 GstStructure *structure;
1811 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1813 structure = GST_QUERY_STRUCTURE (query);
1815 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1816 (GDestroyNotify) allocation_meta_free);
1822 * gst_query_parse_nth_allocation_meta:
1823 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1824 * @index: position in the metadata API array to read
1825 * @params: (out) (transfer none) (allow-none): API specific parameters
1827 * Parse an available query and get the metadata API
1828 * at @index of the metadata API array.
1830 * Returns: a #GType of the metadata API at @index.
1833 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1834 const GstStructure ** params)
1837 GstStructure *structure;
1840 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1842 structure = GST_QUERY_STRUCTURE (query);
1844 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1845 (GDestroyNotify) allocation_meta_free);
1847 g_return_val_if_fail (index < array->len, 0);
1849 am = &g_array_index (array, AllocationMeta, index);
1852 *params = am->params;
1858 * gst_query_remove_nth_allocation_meta:
1859 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1860 * @index: position in the metadata API array to remove
1862 * Remove the metadata API at @index of the metadata API array.
1865 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1868 GstStructure *structure;
1870 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1871 g_return_if_fail (gst_query_is_writable (query));
1873 structure = GST_QUERY_STRUCTURE (query);
1875 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1876 (GDestroyNotify) allocation_meta_free);
1877 g_return_if_fail (index < array->len);
1879 g_array_remove_index (array, index);
1883 * gst_query_find_allocation_meta:
1884 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1885 * @api: the metadata API
1886 * @index: (out) (transfer none) (allow-none): the index
1888 * Check if @query has metadata @api set. When this function returns %TRUE,
1889 * @index will contain the index where the requested API and the parameters
1892 * Returns: %TRUE when @api is in the list of metadata.
1895 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1898 GstStructure *structure;
1901 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1902 g_return_val_if_fail (api != 0, FALSE);
1904 structure = GST_QUERY_STRUCTURE (query);
1906 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1907 (GDestroyNotify) allocation_meta_free);
1910 for (i = 0; i < len; i++) {
1911 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1912 if (am->api == api) {
1923 GstAllocator *allocator;
1924 GstAllocationParams params;
1928 allocation_param_free (AllocationParam * ap)
1931 gst_object_unref (ap->allocator);
1935 * gst_query_add_allocation_param:
1936 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1937 * @allocator: (transfer none) (allow-none): the memory allocator
1938 * @params: (transfer none) (allow-none): a #GstAllocationParams
1940 * Add @allocator and its @params as a supported memory allocator.
1943 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1944 const GstAllocationParams * params)
1947 GstStructure *structure;
1950 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1951 g_return_if_fail (gst_query_is_writable (query));
1952 g_return_if_fail (allocator != NULL || params != NULL);
1954 structure = GST_QUERY_STRUCTURE (query);
1955 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1956 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1958 if ((ap.allocator = allocator))
1959 gst_object_ref (allocator);
1961 ap.params = *params;
1963 gst_allocation_params_init (&ap.params);
1965 g_array_append_val (array, ap);
1969 * gst_query_get_n_allocation_params:
1970 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1972 * Retrieve the number of values currently stored in the
1973 * allocator params array of the query's structure.
1975 * If no memory allocator is specified, the downstream element can handle
1976 * the default memory allocator. The first memory allocator in the query
1977 * should be generic and allow mapping to system memory, all following
1978 * allocators should be ordered by preference with the preferred one first.
1980 * Returns: the allocator array size as a #guint.
1983 gst_query_get_n_allocation_params (GstQuery * query)
1986 GstStructure *structure;
1988 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1990 structure = GST_QUERY_STRUCTURE (query);
1991 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1992 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1998 * gst_query_parse_nth_allocation_param:
1999 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2000 * @index: position in the allocator array to read
2001 * @allocator: (out) (transfer full) (allow-none): variable to hold the result
2002 * @params: (out) (allow-none): parameters for the allocator
2004 * Parse an available query and get the allocator and its params
2005 * at @index of the allocator array.
2008 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
2009 GstAllocator ** allocator, GstAllocationParams * params)
2012 GstStructure *structure;
2013 AllocationParam *ap;
2015 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2017 structure = GST_QUERY_STRUCTURE (query);
2018 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2019 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2020 g_return_if_fail (index < array->len);
2022 ap = &g_array_index (array, AllocationParam, index);
2025 if ((*allocator = ap->allocator))
2026 gst_object_ref (*allocator);
2028 *params = ap->params;
2032 * gst_query_set_nth_allocation_param:
2033 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2034 * @index: position in the allocator array to set
2035 * @allocator: (transfer none) (allow-none): new allocator to set
2036 * @params: (transfer none) (allow-none): parameters for the allocator
2038 * Parse an available query and get the allocator and its params
2039 * at @index of the allocator array.
2042 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
2043 GstAllocator * allocator, const GstAllocationParams * params)
2046 GstStructure *structure;
2047 AllocationParam *old, ap;
2049 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2051 structure = GST_QUERY_STRUCTURE (query);
2052 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2053 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2054 g_return_if_fail (index < array->len);
2056 old = &g_array_index (array, AllocationParam, index);
2057 allocation_param_free (old);
2059 if ((ap.allocator = allocator))
2060 gst_object_ref (allocator);
2062 ap.params = *params;
2064 gst_allocation_params_init (&ap.params);
2066 g_array_index (array, AllocationParam, index) = ap;
2070 * gst_query_remove_nth_allocation_param:
2071 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2072 * @index: position in the allocation param array to remove
2074 * Remove the allocation param at @index of the allocation param array.
2079 gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
2082 GstStructure *structure;
2084 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2085 g_return_if_fail (gst_query_is_writable (query));
2087 structure = GST_QUERY_STRUCTURE (query);
2089 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
2090 (GDestroyNotify) allocation_param_free);
2091 g_return_if_fail (index < array->len);
2093 g_array_remove_index (array, index);
2097 * gst_query_new_scheduling:
2099 * Constructs a new query object for querying the scheduling properties.
2101 * Free-function: gst_query_unref()
2103 * Returns: (transfer full): a new #GstQuery
2106 gst_query_new_scheduling (void)
2109 GstStructure *structure;
2111 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
2112 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
2113 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
2114 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
2115 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
2116 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2122 * gst_query_set_scheduling:
2123 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2124 * @flags: #GstSchedulingFlags
2125 * @minsize: the suggested minimum size of pull requests
2126 * @maxsize: the suggested maximum size of pull requests
2127 * @align: the suggested alignment of pull requests
2129 * Set the scheduling properties.
2132 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2133 gint minsize, gint maxsize, gint align)
2135 GstStructure *structure;
2137 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2138 g_return_if_fail (gst_query_is_writable (query));
2140 structure = GST_QUERY_STRUCTURE (query);
2141 gst_structure_id_set (structure,
2142 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2143 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2144 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2145 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2149 * gst_query_parse_scheduling:
2150 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2151 * @flags: (out) (allow-none): #GstSchedulingFlags
2152 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
2153 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
2154 * @align: (out) (allow-none): the suggested alignment of pull requests
2156 * Set the scheduling properties.
2159 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2160 gint * minsize, gint * maxsize, gint * align)
2162 GstStructure *structure;
2164 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2166 structure = GST_QUERY_STRUCTURE (query);
2167 gst_structure_id_get (structure,
2168 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2169 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2170 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2171 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2175 * gst_query_add_scheduling_mode:
2176 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2177 * @mode: a #GstPadMode
2179 * Add @mode as one of the supported scheduling modes to @query.
2182 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2184 GstStructure *structure;
2187 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2188 g_return_if_fail (gst_query_is_writable (query));
2190 structure = GST_QUERY_STRUCTURE (query);
2192 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2194 g_array_append_val (array, mode);
2198 * gst_query_get_n_scheduling_modes:
2199 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2201 * Retrieve the number of values currently stored in the
2202 * scheduling mode array of the query's structure.
2204 * Returns: the scheduling mode array size as a #guint.
2207 gst_query_get_n_scheduling_modes (GstQuery * query)
2210 GstStructure *structure;
2212 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2214 structure = GST_QUERY_STRUCTURE (query);
2216 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2222 * gst_query_parse_nth_scheduling_mode:
2223 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2224 * @index: position in the scheduling modes array to read
2226 * Parse an available query and get the scheduling mode
2227 * at @index of the scheduling modes array.
2229 * Returns: a #GstPadMode of the scheduling mode at @index.
2232 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2234 GstStructure *structure;
2237 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2240 structure = GST_QUERY_STRUCTURE (query);
2242 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2243 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2245 return g_array_index (array, GstPadMode, index);
2249 * gst_query_has_scheduling_mode:
2250 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2251 * @mode: the scheduling mode
2253 * Check if @query has scheduling mode set.
2257 * When checking if upstream supports pull mode, it is usually not
2258 * enough to just check for GST_PAD_MODE_PULL with this function, you
2259 * also want to check whether the scheduling flags returned by
2260 * gst_query_parse_scheduling() have the seeking flag set (meaning
2261 * random access is supported, not only sequential pulls).
2265 * Returns: %TRUE when @mode is in the list of scheduling modes.
2268 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2270 GstStructure *structure;
2274 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2276 structure = GST_QUERY_STRUCTURE (query);
2278 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2281 for (i = 0; i < len; i++) {
2282 if (mode == g_array_index (array, GstPadMode, i))
2289 * gst_query_has_scheduling_mode_with_flags:
2290 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2291 * @mode: the scheduling mode
2292 * @flags: #GstSchedulingFlags
2294 * Check if @query has scheduling mode set and @flags is set in
2295 * query scheduling flags.
2297 * Returns: %TRUE when @mode is in the list of scheduling modes
2298 * and @flags are compatible with query flags.
2301 gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
2302 GstSchedulingFlags flags)
2304 GstSchedulingFlags sched_flags;
2306 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2308 gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
2310 return ((flags & sched_flags) == flags) &&
2311 gst_query_has_scheduling_mode (query, mode);
2315 * gst_query_new_accept_caps:
2316 * @caps: a fixed #GstCaps
2318 * Constructs a new query object for querying if @caps are accepted.
2320 * Free-function: gst_query_unref()
2322 * Returns: (transfer full): a new #GstQuery
2325 gst_query_new_accept_caps (GstCaps * caps)
2328 GstStructure *structure;
2330 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2332 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2333 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2334 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2335 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2341 * gst_query_parse_accept_caps:
2342 * @query: The query to parse
2343 * @caps: (out) (transfer none): A pointer to the caps
2345 * Get the caps from @query. The caps remains valid as long as @query remains
2349 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2351 GstStructure *structure;
2353 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2354 g_return_if_fail (caps != NULL);
2356 structure = GST_QUERY_STRUCTURE (query);
2357 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2362 * gst_query_set_accept_caps_result:
2363 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2364 * @result: the result to set
2366 * Set @result as the result for the @query.
2369 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2371 GstStructure *structure;
2373 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2374 g_return_if_fail (gst_query_is_writable (query));
2376 structure = GST_QUERY_STRUCTURE (query);
2377 gst_structure_id_set (structure,
2378 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2382 * gst_query_parse_accept_caps_result:
2383 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2384 * @result: location for the result
2386 * Parse the result from @query and store in @result.
2389 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2391 GstStructure *structure;
2393 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2395 structure = GST_QUERY_STRUCTURE (query);
2396 gst_structure_id_get (structure,
2397 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2401 * gst_query_new_caps:
2404 * Constructs a new query object for querying the caps.
2406 * The CAPS query should return the allowable caps for a pad in the context
2407 * of the element's state, its link to other elements, and the devices or files
2408 * it has opened. These caps must be a subset of the pad template caps. In the
2409 * NULL state with no links, the CAPS query should ideally return the same caps
2410 * as the pad template. In rare circumstances, an object property can affect
2411 * the caps returned by the CAPS query, but this is discouraged.
2413 * For most filters, the caps returned by CAPS query is directly affected by the
2414 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2415 * the srcpad's getcaps function is directly related to the stream data. Again,
2416 * the CAPS query should return the most specific caps it reasonably can, since this
2417 * helps with autoplugging.
2419 * The @filter is used to restrict the result caps, only the caps matching
2420 * @filter should be returned from the CAPS query. Specifying a filter might
2421 * greatly reduce the amount of processing an element needs to do.
2423 * Free-function: gst_query_unref()
2425 * Returns: (transfer full): a new #GstQuery
2428 gst_query_new_caps (GstCaps * filter)
2431 GstStructure *structure;
2433 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2434 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2435 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2436 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2442 * gst_query_parse_caps:
2443 * @query: The query to parse
2444 * @filter: (out) (transfer none): A pointer to the caps filter
2446 * Get the filter from the caps @query. The caps remains valid as long as
2447 * @query remains valid.
2450 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2452 GstStructure *structure;
2454 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2455 g_return_if_fail (filter != NULL);
2457 structure = GST_QUERY_STRUCTURE (query);
2458 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2459 GST_QUARK (FILTER)));
2463 * gst_query_set_caps_result:
2464 * @query: The query to use
2465 * @caps: (in): A pointer to the caps
2467 * Set the @caps result in @query.
2470 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2472 GstStructure *structure;
2474 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2475 g_return_if_fail (gst_query_is_writable (query));
2477 structure = GST_QUERY_STRUCTURE (query);
2478 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2482 * gst_query_parse_caps_result:
2483 * @query: The query to parse
2484 * @caps: (out) (transfer none): A pointer to the caps
2486 * Get the caps result from @query. The caps remains valid as long as
2487 * @query remains valid.
2490 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2492 GstStructure *structure;
2494 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2495 g_return_if_fail (caps != NULL);
2497 structure = GST_QUERY_STRUCTURE (query);
2498 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2504 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2505 GstCapsIntersectMode mode)
2507 GstCaps *res, *caps = NULL;
2509 gst_query_parse_caps_result (query, &caps);
2510 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2511 gst_query_set_caps_result (query, res);
2512 gst_caps_unref (res);
2517 * gst_query_new_drain:
2519 * Constructs a new query object for querying the drain state.
2521 * Free-function: gst_query_unref()
2523 * Returns: (transfer full): a new #GstQuery
2526 gst_query_new_drain (void)
2529 GstStructure *structure;
2531 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2532 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2538 * gst_query_new_context:
2539 * @context_type: Context type to query
2541 * Constructs a new query object for querying the pipeline-local context.
2543 * Free-function: gst_query_unref()
2545 * Returns: (transfer full): a new #GstQuery
2550 gst_query_new_context (const gchar * context_type)
2553 GstStructure *structure;
2555 g_return_val_if_fail (context_type != NULL, NULL);
2557 structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
2558 GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2559 query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
2565 * gst_query_set_context:
2566 * @query: a #GstQuery with query type GST_QUERY_CONTEXT
2567 * @context: the requested #GstContext
2569 * Answer a context query by setting the requested context.
2574 gst_query_set_context (GstQuery * query, GstContext * context)
2577 const gchar *context_type;
2579 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2581 gst_query_parse_context_type (query, &context_type);
2582 g_return_if_fail (strcmp (gst_context_get_context_type (context),
2583 context_type) == 0);
2585 s = GST_QUERY_STRUCTURE (query);
2587 gst_structure_id_set (s,
2588 GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2592 * gst_query_parse_context:
2593 * @query: The query to parse
2594 * @context: (out) (transfer none): A pointer to store the #GstContext
2596 * Get the context from the context @query. The context remains valid as long as
2597 * @query remains valid.
2602 gst_query_parse_context (GstQuery * query, GstContext ** context)
2604 GstStructure *structure;
2607 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2608 g_return_if_fail (context != NULL);
2610 structure = GST_QUERY_STRUCTURE (query);
2611 v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
2613 *context = g_value_get_boxed (v);
2619 * gst_query_parse_context_type:
2620 * @query: a GST_QUERY_CONTEXT type query
2621 * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
2623 * Parse a context type from an existing GST_QUERY_CONTEXT query.
2625 * Returns: a #gboolean indicating if the parsing succeeded.
2630 gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
2632 GstStructure *structure;
2633 const GValue *value;
2635 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2637 structure = GST_QUERY_STRUCTURE (query);
2640 value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2641 *context_type = g_value_get_string (value);