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"
66 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
67 #define GST_CAT_DEFAULT gst_query_debug
69 GType _gst_query_type = 0;
75 GstStructure *structure;
78 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
88 static GstQueryQuarks query_quarks[] = {
89 {GST_QUERY_UNKNOWN, "unknown", 0},
90 {GST_QUERY_POSITION, "position", 0},
91 {GST_QUERY_DURATION, "duration", 0},
92 {GST_QUERY_LATENCY, "latency", 0},
93 {GST_QUERY_JITTER, "jitter", 0},
94 {GST_QUERY_RATE, "rate", 0},
95 {GST_QUERY_SEEKING, "seeking", 0},
96 {GST_QUERY_SEGMENT, "segment", 0},
97 {GST_QUERY_CONVERT, "convert", 0},
98 {GST_QUERY_FORMATS, "formats", 0},
99 {GST_QUERY_BUFFERING, "buffering", 0},
100 {GST_QUERY_CUSTOM, "custom", 0},
101 {GST_QUERY_URI, "uri", 0},
102 {GST_QUERY_ALLOCATION, "allocation", 0},
103 {GST_QUERY_SCHEDULING, "scheduling", 0},
104 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
105 {GST_QUERY_CAPS, "caps", 0},
106 {GST_QUERY_DRAIN, "drain", 0},
107 {GST_QUERY_CONTEXT, "context", 0},
108 {GST_QUERY_BITRATE, "bitrate", 0},
113 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
116 _priv_gst_query_initialize (void)
120 _gst_query_type = gst_query_get_type ();
122 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
124 for (i = 0; query_quarks[i].name; i++) {
125 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
130 * gst_query_type_get_name:
131 * @type: the query type
133 * Get a printable name for the given query type. Do not modify or free.
135 * Returns: a reference to the static name of the query.
138 gst_query_type_get_name (GstQueryType type)
142 for (i = 0; query_quarks[i].name; i++) {
143 if (type == query_quarks[i].type)
144 return query_quarks[i].name;
150 * gst_query_type_to_quark:
151 * @type: the query type
153 * Get the unique quark for the given query type.
155 * Returns: the quark associated with the query type
158 gst_query_type_to_quark (GstQueryType type)
162 for (i = 0; query_quarks[i].name; i++) {
163 if (type == query_quarks[i].type)
164 return query_quarks[i].quark;
170 * gst_query_type_get_flags:
171 * @type: a #GstQueryType
173 * Gets the #GstQueryTypeFlags associated with @type.
175 * Returns: a #GstQueryTypeFlags.
178 gst_query_type_get_flags (GstQueryType type)
180 GstQueryTypeFlags ret;
182 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
188 _gst_query_free (GstQuery * query)
192 g_return_if_fail (query != NULL);
194 s = GST_QUERY_STRUCTURE (query);
196 gst_structure_set_parent_refcount (s, NULL);
197 gst_structure_free (s);
200 memset (query, 0xff, sizeof (GstQueryImpl));
203 g_slice_free1 (sizeof (GstQueryImpl), query);
207 _gst_query_copy (GstQuery * query)
212 s = GST_QUERY_STRUCTURE (query);
214 s = gst_structure_copy (s);
216 copy = gst_query_new_custom (query->type, s);
222 * gst_query_new_position:
223 * @format: the default #GstFormat for the new query
225 * Constructs a new query stream position query object. Use gst_query_unref()
226 * when done with it. A position query is used to query the current position
227 * of playback in the streams, in some format.
229 * Free-function: gst_query_unref()
231 * Returns: (transfer full): a new #GstQuery
234 gst_query_new_position (GstFormat format)
237 GstStructure *structure;
239 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
240 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
241 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
243 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
249 * gst_query_set_position:
250 * @query: a #GstQuery with query type GST_QUERY_POSITION
251 * @format: the requested #GstFormat
252 * @cur: the position to set
254 * Answer a position query by setting the requested value in the given format.
257 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
261 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
263 s = GST_QUERY_STRUCTURE (query);
264 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
265 GST_QUARK (FORMAT))));
267 gst_structure_id_set (s,
268 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
269 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
273 * gst_query_parse_position:
274 * @query: a #GstQuery
275 * @format: (out) (allow-none): the storage for the #GstFormat of the
276 * position values (may be %NULL)
277 * @cur: (out) (allow-none): the storage for the current position (may be %NULL)
279 * Parse a position query, writing the format into @format, and the position
280 * into @cur, if the respective parameters are non-%NULL.
283 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
285 GstStructure *structure;
287 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
289 structure = GST_QUERY_STRUCTURE (query);
292 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
293 GST_QUARK (FORMAT)));
295 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
296 GST_QUARK (CURRENT)));
301 * gst_query_new_duration:
302 * @format: the #GstFormat for this duration query
304 * Constructs a new stream duration query object to query in the given format.
305 * Use gst_query_unref() when done with it. A duration query will give the
306 * total length of the stream.
308 * Free-function: gst_query_unref()
310 * Returns: (transfer full): a new #GstQuery
313 gst_query_new_duration (GstFormat format)
316 GstStructure *structure;
318 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
319 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
320 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
322 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
328 * gst_query_set_duration:
329 * @query: a #GstQuery
330 * @format: the #GstFormat for the duration
331 * @duration: the duration of the stream
333 * Answer a duration query by setting the requested value in the given format.
336 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
340 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
342 s = GST_QUERY_STRUCTURE (query);
343 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
344 GST_QUARK (FORMAT))));
345 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
346 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
350 * gst_query_parse_duration:
351 * @query: a #GstQuery
352 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
354 * @duration: (out) (allow-none): the storage for the total duration, or %NULL.
356 * Parse a duration query answer. Write the format of the duration into @format,
357 * and the value into @duration, if the respective variables are non-%NULL.
360 gst_query_parse_duration (GstQuery * query, GstFormat * format,
363 GstStructure *structure;
365 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
367 structure = GST_QUERY_STRUCTURE (query);
370 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
371 GST_QUARK (FORMAT)));
373 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
374 GST_QUARK (DURATION)));
378 * gst_query_new_latency:
380 * Constructs a new latency query object.
381 * Use gst_query_unref() when done with it. A latency query is usually performed
382 * by sinks to compensate for additional latency introduced by elements in the
385 * Free-function: gst_query_unref()
387 * Returns: (transfer full): a #GstQuery
390 gst_query_new_latency (void)
393 GstStructure *structure;
395 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
396 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
397 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
398 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, GST_CLOCK_TIME_NONE, NULL);
400 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
406 * gst_query_set_latency:
407 * @query: a #GstQuery
408 * @live: if there is a live element upstream
409 * @min_latency: the minimal latency of the upstream elements
410 * @max_latency: the maximal latency of the upstream elements
412 * Answer a latency query by setting the requested values in the given format.
415 gst_query_set_latency (GstQuery * query, gboolean live,
416 GstClockTime min_latency, GstClockTime max_latency)
418 GstStructure *structure;
420 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
421 g_return_if_fail (GST_CLOCK_TIME_IS_VALID (min_latency));
423 structure = GST_QUERY_STRUCTURE (query);
424 gst_structure_id_set (structure,
425 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
426 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
427 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
431 * gst_query_parse_latency:
432 * @query: a #GstQuery
433 * @live: (out) (allow-none): storage for live or %NULL
434 * @min_latency: (out) (allow-none): the storage for the min latency or %NULL
435 * @max_latency: (out) (allow-none): the storage for the max latency or %NULL
437 * Parse a latency query answer.
440 gst_query_parse_latency (GstQuery * query, gboolean * live,
441 GstClockTime * min_latency, GstClockTime * max_latency)
443 GstStructure *structure;
445 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
447 structure = GST_QUERY_STRUCTURE (query);
450 g_value_get_boolean (gst_structure_id_get_value (structure,
453 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
454 GST_QUARK (MIN_LATENCY)));
456 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
457 GST_QUARK (MAX_LATENCY)));
461 * gst_query_new_convert:
462 * @src_format: the source #GstFormat for the new query
463 * @value: the value to convert
464 * @dest_format: the target #GstFormat
466 * Constructs a new convert query object. Use gst_query_unref()
467 * when done with it. A convert query is used to ask for a conversion between
468 * one format and another.
470 * Free-function: gst_query_unref()
472 * Returns: (transfer full): a #GstQuery
475 gst_query_new_convert (GstFormat src_format, gint64 value,
476 GstFormat dest_format)
479 GstStructure *structure;
481 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
482 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
483 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
484 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
485 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
487 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
493 * gst_query_set_convert:
494 * @query: a #GstQuery
495 * @src_format: the source #GstFormat
496 * @src_value: the source value
497 * @dest_format: the destination #GstFormat
498 * @dest_value: the destination value
500 * Answer a convert query by setting the requested values.
503 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
504 GstFormat dest_format, gint64 dest_value)
506 GstStructure *structure;
508 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
510 structure = GST_QUERY_STRUCTURE (query);
511 gst_structure_id_set (structure,
512 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
513 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
514 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
515 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
519 * gst_query_parse_convert:
520 * @query: a #GstQuery
521 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
522 * source value, or %NULL
523 * @src_value: (out) (allow-none): the storage for the source value, or %NULL
524 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
525 * destination value, or %NULL
526 * @dest_value: (out) (allow-none): the storage for the destination value,
529 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
530 * and @dest_value may be %NULL, in which case that value is omitted.
533 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
534 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
536 GstStructure *structure;
538 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
540 structure = GST_QUERY_STRUCTURE (query);
543 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
544 GST_QUARK (SRC_FORMAT)));
546 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
547 GST_QUARK (SRC_VALUE)));
550 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
551 GST_QUARK (DEST_FORMAT)));
553 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
554 GST_QUARK (DEST_VALUE)));
558 * gst_query_new_segment:
559 * @format: the #GstFormat for the new query
561 * Constructs a new segment query object. Use gst_query_unref()
562 * when done with it. A segment query is used to discover information about the
563 * currently configured segment for playback.
565 * Free-function: gst_query_unref()
567 * Returns: (transfer full): a new #GstQuery
570 gst_query_new_segment (GstFormat format)
573 GstStructure *structure;
575 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
576 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
577 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
578 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
579 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
581 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
587 * gst_query_set_segment:
588 * @query: a #GstQuery
589 * @rate: the rate of the segment
590 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
591 * @start_value: the start value
592 * @stop_value: the stop value
594 * Answer a segment query by setting the requested values. The normal
595 * playback segment of a pipeline is 0 to duration at the default rate of
596 * 1.0. If a seek was performed on the pipeline to play a different
597 * segment, this query will return the range specified in the last seek.
599 * @start_value and @stop_value will respectively contain the configured
600 * playback range start and stop values expressed in @format.
601 * The values are always between 0 and the duration of the media and
602 * @start_value <= @stop_value. @rate will contain the playback rate. For
603 * negative rates, playback will actually happen from @stop_value to
607 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
608 gint64 start_value, gint64 stop_value)
610 GstStructure *structure;
612 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
614 structure = GST_QUERY_STRUCTURE (query);
615 gst_structure_id_set (structure,
616 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
617 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
618 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
619 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
623 * gst_query_parse_segment:
624 * @query: a #GstQuery
625 * @rate: (out) (allow-none): the storage for the rate of the segment, or %NULL
626 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
628 * @start_value: (out) (allow-none): the storage for the start value, or %NULL
629 * @stop_value: (out) (allow-none): the storage for the stop value, or %NULL
631 * Parse a segment query answer. Any of @rate, @format, @start_value, and
632 * @stop_value may be %NULL, which will cause this value to be omitted.
634 * See gst_query_set_segment() for an explanation of the function arguments.
637 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
638 gint64 * start_value, gint64 * stop_value)
640 GstStructure *structure;
642 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
644 structure = GST_QUERY_STRUCTURE (query);
646 *rate = g_value_get_double (gst_structure_id_get_value (structure,
650 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
651 GST_QUARK (FORMAT)));
653 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
654 GST_QUARK (START_VALUE)));
656 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
657 GST_QUARK (STOP_VALUE)));
661 * gst_query_new_custom:
662 * @type: the query type
663 * @structure: (allow-none) (transfer full): a structure for the query
665 * Constructs a new custom query object. Use gst_query_unref()
668 * Free-function: gst_query_unref()
670 * Returns: (transfer full) (nullable): a new #GstQuery
673 gst_query_new_custom (GstQueryType type, GstStructure * structure)
677 query = g_slice_new0 (GstQueryImpl);
679 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
682 /* structure must not have a parent */
683 if (!gst_structure_set_parent_refcount (structure,
684 &query->query.mini_object.refcount))
688 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
689 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
690 (GstMiniObjectFreeFunction) _gst_query_free);
692 GST_QUERY_TYPE (query) = type;
693 GST_QUERY_STRUCTURE (query) = structure;
695 return GST_QUERY_CAST (query);
700 g_slice_free1 (sizeof (GstQueryImpl), query);
701 g_warning ("structure is already owned by another object");
707 * gst_query_get_structure:
708 * @query: a #GstQuery
710 * Get the structure of a query.
712 * Returns: (transfer none) (nullable): the #GstStructure of the query. The
713 * structure is still owned by the query and will therefore be freed when the
717 gst_query_get_structure (GstQuery * query)
719 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
721 return GST_QUERY_STRUCTURE (query);
725 * gst_query_writable_structure:
726 * @query: a #GstQuery
728 * Get the structure of a query. This method should be called with a writable
729 * @query so that the returned structure is guaranteed to be writable.
731 * Returns: (transfer none): the #GstStructure of the query. The structure is
732 * still owned by the query and will therefore be freed when the query
736 gst_query_writable_structure (GstQuery * query)
738 GstStructure *structure;
740 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
741 g_return_val_if_fail (gst_query_is_writable (query), NULL);
743 structure = GST_QUERY_STRUCTURE (query);
745 if (structure == NULL) {
747 gst_structure_new_id_empty (gst_query_type_to_quark (GST_QUERY_TYPE
749 gst_structure_set_parent_refcount (structure, &query->mini_object.refcount);
750 GST_QUERY_STRUCTURE (query) = structure;
756 * gst_query_new_seeking:
757 * @format: the default #GstFormat for the new query
759 * Constructs a new query object for querying seeking properties of
762 * Free-function: gst_query_unref()
764 * Returns: (transfer full): a new #GstQuery
767 gst_query_new_seeking (GstFormat format)
770 GstStructure *structure;
772 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
773 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
774 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
775 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
776 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
778 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
784 * gst_query_set_seeking:
785 * @query: a #GstQuery
786 * @format: the format to set for the @segment_start and @segment_end values
787 * @seekable: the seekable flag to set
788 * @segment_start: the segment_start to set
789 * @segment_end: the segment_end to set
791 * Set the seeking query result fields in @query.
794 gst_query_set_seeking (GstQuery * query, GstFormat format,
795 gboolean seekable, gint64 segment_start, gint64 segment_end)
797 GstStructure *structure;
799 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
800 g_return_if_fail (gst_query_is_writable (query));
802 structure = GST_QUERY_STRUCTURE (query);
803 gst_structure_id_set (structure,
804 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
805 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
806 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
807 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
811 * gst_query_parse_seeking:
812 * @query: a GST_QUERY_SEEKING type query #GstQuery
813 * @format: (out) (allow-none): the format to set for the @segment_start
814 * and @segment_end values, or %NULL
815 * @seekable: (out) (allow-none): the seekable flag to set, or %NULL
816 * @segment_start: (out) (allow-none): the segment_start to set, or %NULL
817 * @segment_end: (out) (allow-none): the segment_end to set, or %NULL
819 * Parse a seeking query, writing the format into @format, and
820 * other results into the passed parameters, if the respective parameters
824 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
825 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
827 GstStructure *structure;
829 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
831 structure = GST_QUERY_STRUCTURE (query);
834 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
835 GST_QUARK (FORMAT)));
837 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
838 GST_QUARK (SEEKABLE)));
840 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
841 GST_QUARK (SEGMENT_START)));
843 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
844 GST_QUARK (SEGMENT_END)));
848 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
849 GDestroyNotify clear_func)
854 value = gst_structure_id_get_value (s, quark);
856 array = (GArray *) g_value_get_boxed (value);
858 GValue new_array_val = { 0, };
860 array = g_array_new (FALSE, TRUE, element_size);
862 g_array_set_clear_func (array, clear_func);
864 g_value_init (&new_array_val, G_TYPE_ARRAY);
865 g_value_take_boxed (&new_array_val, array);
867 gst_structure_id_take_value (s, quark, &new_array_val);
873 * gst_query_new_formats:
875 * Constructs a new query object for querying formats of
878 * Free-function: gst_query_unref()
880 * Returns: (transfer full): a new #GstQuery
883 gst_query_new_formats (void)
886 GstStructure *structure;
888 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
889 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
895 gst_query_list_add_format (GValue * list, GstFormat format)
897 GValue item = { 0, };
899 g_value_init (&item, GST_TYPE_FORMAT);
900 g_value_set_enum (&item, format);
901 gst_value_list_append_value (list, &item);
902 g_value_unset (&item);
906 * gst_query_set_formats:
907 * @query: a #GstQuery
908 * @n_formats: the number of formats to set.
909 * @...: A number of @GstFormats equal to @n_formats.
911 * Set the formats query result fields in @query. The number of formats passed
912 * must be equal to @n_formats.
915 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
918 GValue list = { 0, };
920 GstStructure *structure;
922 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
923 g_return_if_fail (gst_query_is_writable (query));
925 g_value_init (&list, GST_TYPE_LIST);
927 va_start (ap, n_formats);
928 for (i = 0; i < n_formats; i++) {
929 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
933 structure = GST_QUERY_STRUCTURE (query);
934 gst_structure_set_value (structure, "formats", &list);
936 g_value_unset (&list);
941 * gst_query_set_formatsv:
942 * @query: a #GstQuery
943 * @n_formats: the number of formats to set.
944 * @formats: (in) (array length=n_formats): an array containing @n_formats
947 * Set the formats query result fields in @query. The number of formats passed
948 * in the @formats array must be equal to @n_formats.
951 gst_query_set_formatsv (GstQuery * query, gint n_formats,
952 const GstFormat * formats)
954 GValue list = { 0, };
956 GstStructure *structure;
958 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
959 g_return_if_fail (gst_query_is_writable (query));
961 g_value_init (&list, GST_TYPE_LIST);
962 for (i = 0; i < n_formats; i++) {
963 gst_query_list_add_format (&list, formats[i]);
965 structure = GST_QUERY_STRUCTURE (query);
966 gst_structure_set_value (structure, "formats", &list);
968 g_value_unset (&list);
972 * gst_query_parse_n_formats:
973 * @query: a #GstQuery
974 * @n_formats: (out) (allow-none): the number of formats in this query.
976 * Parse the number of formats in the formats @query.
979 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
981 GstStructure *structure;
983 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
988 structure = GST_QUERY_STRUCTURE (query);
989 list = gst_structure_get_value (structure, "formats");
993 *n_formats = gst_value_list_get_size (list);
998 * gst_query_parse_nth_format:
999 * @query: a #GstQuery
1000 * @nth: the nth format to retrieve.
1001 * @format: (out) (allow-none): a pointer to store the nth format
1003 * Parse the format query and retrieve the @nth format from it into
1004 * @format. If the list contains less elements than @nth, @format will be
1005 * set to GST_FORMAT_UNDEFINED.
1008 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1010 GstStructure *structure;
1012 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1017 structure = GST_QUERY_STRUCTURE (query);
1018 list = gst_structure_get_value (structure, "formats");
1020 *format = GST_FORMAT_UNDEFINED;
1022 if (nth < gst_value_list_get_size (list)) {
1024 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1026 *format = GST_FORMAT_UNDEFINED;
1032 * gst_query_new_buffering:
1033 * @format: the default #GstFormat for the new query
1035 * Constructs a new query object for querying the buffering status of
1038 * Free-function: gst_query_unref()
1040 * Returns: (transfer full): a new #GstQuery
1043 gst_query_new_buffering (GstFormat format)
1046 GstStructure *structure;
1048 /* by default, we configure the answer as no buffering with a 100% buffering
1050 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1051 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1052 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1053 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1054 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1055 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1056 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1057 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1058 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1059 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1060 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1062 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1068 * gst_query_set_buffering_percent:
1069 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1070 * @busy: if buffering is busy
1071 * @percent: a buffering percent
1073 * Set the percentage of buffered data. This is a value between 0 and 100.
1074 * The @busy indicator is %TRUE when the buffering is in progress.
1077 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1079 GstStructure *structure;
1081 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1082 g_return_if_fail (gst_query_is_writable (query));
1083 g_return_if_fail (percent >= 0 && percent <= 100);
1085 structure = GST_QUERY_STRUCTURE (query);
1086 gst_structure_id_set (structure,
1087 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1088 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1092 * gst_query_parse_buffering_percent:
1093 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1094 * @busy: (out) (allow-none): if buffering is busy, or %NULL
1095 * @percent: (out) (allow-none): a buffering percent, or %NULL
1097 * Get the percentage of buffered data. This is a value between 0 and 100.
1098 * The @busy indicator is %TRUE when the buffering is in progress.
1101 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1104 GstStructure *structure;
1106 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1108 structure = GST_QUERY_STRUCTURE (query);
1110 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1113 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1114 GST_QUARK (BUFFER_PERCENT)));
1118 * gst_query_set_buffering_stats:
1119 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1120 * @mode: a buffering mode
1121 * @avg_in: the average input rate
1122 * @avg_out: the average output rate
1123 * @buffering_left: amount of buffering time left in milliseconds
1125 * Configures the buffering stats values in @query.
1128 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1129 gint avg_in, gint avg_out, gint64 buffering_left)
1131 GstStructure *structure;
1133 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1134 g_return_if_fail (gst_query_is_writable (query));
1136 structure = GST_QUERY_STRUCTURE (query);
1137 gst_structure_id_set (structure,
1138 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1139 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1140 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1141 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1145 * gst_query_parse_buffering_stats:
1146 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1147 * @mode: (out) (allow-none): a buffering mode, or %NULL
1148 * @avg_in: (out) (allow-none): the average input rate, or %NULL
1149 * @avg_out: (out) (allow-none): the average output rat, or %NULL
1150 * @buffering_left: (out) (allow-none): amount of buffering time left in
1151 * milliseconds, or %NULL
1153 * Extracts the buffering stats values from @query.
1156 gst_query_parse_buffering_stats (GstQuery * query,
1157 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1158 gint64 * buffering_left)
1160 GstStructure *structure;
1162 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1164 structure = GST_QUERY_STRUCTURE (query);
1166 *mode = (GstBufferingMode)
1167 g_value_get_enum (gst_structure_id_get_value (structure,
1168 GST_QUARK (BUFFERING_MODE)));
1170 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1171 GST_QUARK (AVG_IN_RATE)));
1173 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1174 GST_QUARK (AVG_OUT_RATE)));
1177 g_value_get_int64 (gst_structure_id_get_value (structure,
1178 GST_QUARK (BUFFERING_LEFT)));
1182 * gst_query_set_buffering_range:
1183 * @query: a #GstQuery
1184 * @format: the format to set for the @start and @stop values
1185 * @start: the start to set
1186 * @stop: the stop to set
1187 * @estimated_total: estimated total amount of download time remaining in
1190 * Set the available query result fields in @query.
1193 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1194 gint64 start, gint64 stop, gint64 estimated_total)
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 (FORMAT), GST_TYPE_FORMAT, format,
1204 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1205 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1206 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1210 * gst_query_parse_buffering_range:
1211 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1212 * @format: (out) (allow-none): the format to set for the @segment_start
1213 * and @segment_end values, or %NULL
1214 * @start: (out) (allow-none): the start to set, or %NULL
1215 * @stop: (out) (allow-none): the stop to set, or %NULL
1216 * @estimated_total: (out) (allow-none): estimated total amount of download
1217 * time remaining in milliseconds, or %NULL
1219 * Parse an available query, writing the format into @format, and
1220 * other results into the passed parameters, if the respective parameters
1224 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1225 gint64 * start, gint64 * stop, gint64 * estimated_total)
1227 GstStructure *structure;
1229 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1231 structure = GST_QUERY_STRUCTURE (query);
1234 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1235 GST_QUARK (FORMAT)));
1237 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1238 GST_QUARK (START_VALUE)));
1240 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1241 GST_QUARK (STOP_VALUE)));
1242 if (estimated_total)
1244 g_value_get_int64 (gst_structure_id_get_value (structure,
1245 GST_QUARK (ESTIMATED_TOTAL)));
1248 /* GstQueryBufferingRange: internal struct for GArray */
1253 } GstQueryBufferingRange;
1256 * gst_query_add_buffering_range:
1257 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1258 * @start: start position of the range
1259 * @stop: stop position of the range
1261 * Set the buffering-ranges array field in @query. The current last
1262 * start position of the array should be inferior to @start.
1264 * Returns: a #gboolean indicating if the range was added or not.
1267 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1269 GstQueryBufferingRange range;
1270 GstStructure *structure;
1273 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1274 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1276 if (G_UNLIKELY (start >= stop))
1279 structure = GST_QUERY_STRUCTURE (query);
1280 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1281 sizeof (GstQueryBufferingRange), NULL);
1283 if (array->len > 1) {
1284 GstQueryBufferingRange *last;
1286 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1288 if (G_UNLIKELY (start <= last->start))
1292 range.start = start;
1294 g_array_append_val (array, range);
1300 * gst_query_get_n_buffering_ranges:
1301 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1303 * Retrieve the number of values currently stored in the
1304 * buffered-ranges array of the query's structure.
1306 * Returns: the range array size as a #guint.
1309 gst_query_get_n_buffering_ranges (GstQuery * query)
1311 GstStructure *structure;
1314 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1316 structure = GST_QUERY_STRUCTURE (query);
1317 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1318 sizeof (GstQueryBufferingRange), NULL);
1325 * gst_query_parse_nth_buffering_range:
1326 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1327 * @index: position in the buffered-ranges array to read
1328 * @start: (out) (allow-none): the start position to set, or %NULL
1329 * @stop: (out) (allow-none): the stop position to set, or %NULL
1331 * Parse an available query and get the start and stop values stored
1332 * at the @index of the buffered ranges array.
1334 * Returns: a #gboolean indicating if the parsing succeeded.
1337 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1338 gint64 * start, gint64 * stop)
1340 GstQueryBufferingRange *range;
1341 GstStructure *structure;
1344 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1346 structure = GST_QUERY_STRUCTURE (query);
1348 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1349 sizeof (GstQueryBufferingRange), NULL);
1350 g_return_val_if_fail (index < array->len, FALSE);
1352 range = &g_array_index (array, GstQueryBufferingRange, index);
1355 *start = range->start;
1357 *stop = range->stop;
1364 * gst_query_new_uri:
1366 * Constructs a new query URI query object. Use gst_query_unref()
1367 * when done with it. An URI query is used to query the current URI
1368 * that is used by the source or sink.
1370 * Free-function: gst_query_unref()
1372 * Returns: (transfer full): a new #GstQuery
1375 gst_query_new_uri (void)
1378 GstStructure *structure;
1380 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1381 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1383 query = gst_query_new_custom (GST_QUERY_URI, structure);
1389 * gst_query_set_uri:
1390 * @query: a #GstQuery with query type GST_QUERY_URI
1391 * @uri: the URI to set
1393 * Answer a URI query by setting the requested URI.
1396 gst_query_set_uri (GstQuery * query, const gchar * uri)
1398 GstStructure *structure;
1400 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1401 g_return_if_fail (gst_query_is_writable (query));
1402 g_return_if_fail (gst_uri_is_valid (uri));
1404 structure = GST_QUERY_STRUCTURE (query);
1405 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1409 * gst_query_parse_uri:
1410 * @query: a #GstQuery
1411 * @uri: (out) (transfer full) (allow-none): the storage for the current URI
1414 * Parse an URI query, writing the URI into @uri as a newly
1415 * allocated string, if the respective parameters are non-%NULL.
1416 * Free the string with g_free() after usage.
1419 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1421 GstStructure *structure;
1423 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1425 structure = GST_QUERY_STRUCTURE (query);
1427 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1432 * gst_query_set_uri_redirection:
1433 * @query: a #GstQuery with query type GST_QUERY_URI
1434 * @uri: the URI to set
1436 * Answer a URI query by setting the requested URI redirection.
1441 gst_query_set_uri_redirection (GstQuery * query, const gchar * uri)
1443 GstStructure *structure;
1445 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1446 g_return_if_fail (gst_query_is_writable (query));
1447 g_return_if_fail (gst_uri_is_valid (uri));
1449 structure = GST_QUERY_STRUCTURE (query);
1450 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
1451 G_TYPE_STRING, uri, NULL);
1455 * gst_query_parse_uri_redirection:
1456 * @query: a #GstQuery
1457 * @uri: (out) (transfer full) (allow-none): the storage for the redirect URI
1460 * Parse an URI query, writing the URI into @uri as a newly
1461 * allocated string, if the respective parameters are non-%NULL.
1462 * Free the string with g_free() after usage.
1467 gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
1469 GstStructure *structure;
1471 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1473 structure = GST_QUERY_STRUCTURE (query);
1475 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION),
1476 G_TYPE_STRING, uri, NULL))
1482 * gst_query_set_uri_redirection_permanent:
1483 * @query: a #GstQuery with query type %GST_QUERY_URI
1484 * @permanent: whether the redirect is permanent or not
1486 * Answer a URI query by setting the requested URI redirection
1487 * to permanent or not.
1492 gst_query_set_uri_redirection_permanent (GstQuery * query, gboolean permanent)
1494 GstStructure *structure;
1496 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1497 g_return_if_fail (gst_query_is_writable (query));
1499 structure = GST_QUERY_STRUCTURE (query);
1500 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1501 G_TYPE_BOOLEAN, permanent, NULL);
1505 * gst_query_parse_uri_redirection_permanent:
1506 * @query: a #GstQuery
1507 * @permanent: (out) (allow-none): if the URI redirection is permanent
1510 * Parse an URI query, and set @permanent to %TRUE if there is a redirection
1511 * and it should be considered permanent. If a redirection is permanent,
1512 * applications should update their internal storage of the URI, otherwise
1513 * they should make all future requests to the original URI.
1518 gst_query_parse_uri_redirection_permanent (GstQuery * query,
1519 gboolean * permanent)
1521 GstStructure *structure;
1523 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1525 structure = GST_QUERY_STRUCTURE (query);
1527 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1528 G_TYPE_BOOLEAN, permanent, NULL))
1534 * gst_query_new_allocation:
1535 * @caps: the negotiated caps
1536 * @need_pool: return a pool
1538 * Constructs a new query object for querying the allocation properties.
1540 * Free-function: gst_query_unref()
1542 * Returns: (transfer full): a new #GstQuery
1545 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1548 GstStructure *structure;
1550 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1551 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1552 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1554 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1560 * gst_query_parse_allocation:
1561 * @query: a #GstQuery
1562 * @caps: (out) (transfer none) (allow-none): The #GstCaps
1563 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1565 * Parse an allocation query, writing the requested caps in @caps and
1566 * whether a pool is needed in @need_pool, if the respective parameters
1569 * Pool details can be retrieved using gst_query_get_n_allocation_pools() and
1570 * gst_query_parse_nth_allocation_pool().
1573 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1574 gboolean * need_pool)
1576 GstStructure *structure;
1578 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1580 structure = GST_QUERY_STRUCTURE (query);
1582 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1585 gst_structure_id_get (structure,
1586 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1591 GstBufferPool *pool;
1598 allocation_pool_free (AllocationPool * ap)
1601 gst_object_unref (ap->pool);
1605 * gst_query_add_allocation_pool:
1606 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1607 * @pool: (transfer none) (allow-none): the #GstBufferPool
1608 * @size: the buffer size
1609 * @min_buffers: the min buffers
1610 * @max_buffers: the max buffers
1612 * Set the pool parameters in @query.
1615 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1616 guint size, guint min_buffers, guint max_buffers)
1619 GstStructure *structure;
1622 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1623 g_return_if_fail (gst_query_is_writable (query));
1625 structure = GST_QUERY_STRUCTURE (query);
1626 array = ensure_array (structure, GST_QUARK (POOL),
1627 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1629 if ((ap.pool = pool))
1630 gst_object_ref (pool);
1632 ap.min_buffers = min_buffers;
1633 ap.max_buffers = max_buffers;
1635 g_array_append_val (array, ap);
1639 * gst_query_get_n_allocation_pools:
1640 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1642 * Retrieve the number of values currently stored in the
1643 * pool array of the query's structure.
1645 * Returns: the pool array size as a #guint.
1648 gst_query_get_n_allocation_pools (GstQuery * query)
1651 GstStructure *structure;
1653 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1655 structure = GST_QUERY_STRUCTURE (query);
1656 array = ensure_array (structure, GST_QUARK (POOL),
1657 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1663 * gst_query_parse_nth_allocation_pool:
1664 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1665 * @index: index to parse
1666 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1667 * @size: (out) (allow-none): the buffer size
1668 * @min_buffers: (out) (allow-none): the min buffers
1669 * @max_buffers: (out) (allow-none): the max buffers
1671 * Get the pool parameters in @query.
1673 * Unref @pool with gst_object_unref() when it's not needed any more.
1676 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1677 GstBufferPool ** pool, guint * size, guint * min_buffers,
1678 guint * max_buffers)
1681 GstStructure *structure;
1684 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1686 structure = GST_QUERY_STRUCTURE (query);
1687 array = ensure_array (structure, GST_QUARK (POOL),
1688 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1689 g_return_if_fail (index < array->len);
1691 ap = &g_array_index (array, AllocationPool, index);
1694 if ((*pool = ap->pool))
1695 gst_object_ref (*pool);
1699 *min_buffers = ap->min_buffers;
1701 *max_buffers = ap->max_buffers;
1705 * gst_query_set_nth_allocation_pool:
1706 * @index: index to modify
1707 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1708 * @pool: (transfer none) (allow-none): the #GstBufferPool
1709 * @size: the buffer size
1710 * @min_buffers: the min buffers
1711 * @max_buffers: the max buffers
1713 * Set the pool parameters in @query.
1716 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1717 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1720 GstStructure *structure;
1721 AllocationPool *oldap, ap;
1723 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1725 structure = GST_QUERY_STRUCTURE (query);
1726 array = ensure_array (structure, GST_QUARK (POOL),
1727 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1728 g_return_if_fail (index < array->len);
1730 oldap = &g_array_index (array, AllocationPool, index);
1731 allocation_pool_free (oldap);
1733 if ((ap.pool = pool))
1734 gst_object_ref (pool);
1736 ap.min_buffers = min_buffers;
1737 ap.max_buffers = max_buffers;
1738 g_array_index (array, AllocationPool, index) = ap;
1742 * gst_query_remove_nth_allocation_pool:
1743 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1744 * @index: position in the allocation pool array to remove
1746 * Remove the allocation pool at @index of the allocation pool array.
1751 gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
1754 GstStructure *structure;
1756 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1757 g_return_if_fail (gst_query_is_writable (query));
1759 structure = GST_QUERY_STRUCTURE (query);
1761 ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
1762 (GDestroyNotify) allocation_pool_free);
1763 g_return_if_fail (index < array->len);
1765 g_array_remove_index (array, index);
1771 GstStructure *params;
1775 allocation_meta_free (AllocationMeta * am)
1778 gst_structure_free (am->params);
1782 * gst_query_add_allocation_meta:
1783 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1784 * @api: the metadata API
1785 * @params: (transfer none) (allow-none): API specific parameters
1787 * Add @api with @params as one of the supported metadata API to @query.
1790 gst_query_add_allocation_meta (GstQuery * query, GType api,
1791 const GstStructure * params)
1794 GstStructure *structure;
1797 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1798 g_return_if_fail (api != 0);
1799 g_return_if_fail (gst_query_is_writable (query));
1801 structure = GST_QUERY_STRUCTURE (query);
1803 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1804 (GDestroyNotify) allocation_meta_free);
1807 am.params = (params ? gst_structure_copy (params) : NULL);
1809 g_array_append_val (array, am);
1813 * gst_query_get_n_allocation_metas:
1814 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1816 * Retrieve the number of values currently stored in the
1817 * meta API array of the query's structure.
1819 * Returns: the metadata API array size as a #guint.
1822 gst_query_get_n_allocation_metas (GstQuery * query)
1825 GstStructure *structure;
1827 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1829 structure = GST_QUERY_STRUCTURE (query);
1831 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1832 (GDestroyNotify) allocation_meta_free);
1838 * gst_query_parse_nth_allocation_meta:
1839 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1840 * @index: position in the metadata API array to read
1841 * @params: (out) (transfer none) (allow-none): API specific parameters
1843 * Parse an available query and get the metadata API
1844 * at @index of the metadata API array.
1846 * Returns: a #GType of the metadata API at @index.
1849 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1850 const GstStructure ** params)
1853 GstStructure *structure;
1856 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1858 structure = GST_QUERY_STRUCTURE (query);
1860 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1861 (GDestroyNotify) allocation_meta_free);
1863 g_return_val_if_fail (index < array->len, 0);
1865 am = &g_array_index (array, AllocationMeta, index);
1868 *params = am->params;
1874 * gst_query_remove_nth_allocation_meta:
1875 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1876 * @index: position in the metadata API array to remove
1878 * Remove the metadata API at @index of the metadata API array.
1881 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1884 GstStructure *structure;
1886 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1887 g_return_if_fail (gst_query_is_writable (query));
1889 structure = GST_QUERY_STRUCTURE (query);
1891 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1892 (GDestroyNotify) allocation_meta_free);
1893 g_return_if_fail (index < array->len);
1895 g_array_remove_index (array, index);
1899 * gst_query_find_allocation_meta:
1900 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1901 * @api: the metadata API
1902 * @index: (out) (transfer none) (allow-none): the index
1904 * Check if @query has metadata @api set. When this function returns %TRUE,
1905 * @index will contain the index where the requested API and the parameters
1908 * Returns: %TRUE when @api is in the list of metadata.
1911 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1914 GstStructure *structure;
1917 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1918 g_return_val_if_fail (api != 0, FALSE);
1920 structure = GST_QUERY_STRUCTURE (query);
1922 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1923 (GDestroyNotify) allocation_meta_free);
1926 for (i = 0; i < len; i++) {
1927 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1928 if (am->api == api) {
1939 GstAllocator *allocator;
1940 GstAllocationParams params;
1944 allocation_param_free (AllocationParam * ap)
1947 gst_object_unref (ap->allocator);
1951 * gst_query_add_allocation_param:
1952 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1953 * @allocator: (transfer none) (allow-none): the memory allocator
1954 * @params: (transfer none) (allow-none): a #GstAllocationParams
1956 * Add @allocator and its @params as a supported memory allocator.
1959 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1960 const GstAllocationParams * params)
1963 GstStructure *structure;
1966 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1967 g_return_if_fail (gst_query_is_writable (query));
1968 g_return_if_fail (allocator != NULL || params != NULL);
1970 structure = GST_QUERY_STRUCTURE (query);
1971 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1972 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1974 if ((ap.allocator = allocator))
1975 gst_object_ref (allocator);
1977 ap.params = *params;
1979 gst_allocation_params_init (&ap.params);
1981 g_array_append_val (array, ap);
1985 * gst_query_get_n_allocation_params:
1986 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1988 * Retrieve the number of values currently stored in the
1989 * allocator params array of the query's structure.
1991 * If no memory allocator is specified, the downstream element can handle
1992 * the default memory allocator. The first memory allocator in the query
1993 * should be generic and allow mapping to system memory, all following
1994 * allocators should be ordered by preference with the preferred one first.
1996 * Returns: the allocator array size as a #guint.
1999 gst_query_get_n_allocation_params (GstQuery * query)
2002 GstStructure *structure;
2004 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
2006 structure = GST_QUERY_STRUCTURE (query);
2007 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2008 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2014 * gst_query_parse_nth_allocation_param:
2015 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2016 * @index: position in the allocator array to read
2017 * @allocator: (out) (transfer full) (allow-none): variable to hold the result
2018 * @params: (out) (allow-none): parameters for the allocator
2020 * Parse an available query and get the allocator and its params
2021 * at @index of the allocator array.
2024 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
2025 GstAllocator ** allocator, GstAllocationParams * params)
2028 GstStructure *structure;
2029 AllocationParam *ap;
2031 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2033 structure = GST_QUERY_STRUCTURE (query);
2034 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2035 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2036 g_return_if_fail (index < array->len);
2038 ap = &g_array_index (array, AllocationParam, index);
2041 if ((*allocator = ap->allocator))
2042 gst_object_ref (*allocator);
2044 *params = ap->params;
2048 * gst_query_set_nth_allocation_param:
2049 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2050 * @index: position in the allocator array to set
2051 * @allocator: (transfer none) (allow-none): new allocator to set
2052 * @params: (transfer none) (allow-none): parameters for the allocator
2054 * Parse an available query and get the allocator and its params
2055 * at @index of the allocator array.
2058 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
2059 GstAllocator * allocator, const GstAllocationParams * params)
2062 GstStructure *structure;
2063 AllocationParam *old, ap;
2065 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2067 structure = GST_QUERY_STRUCTURE (query);
2068 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2069 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2070 g_return_if_fail (index < array->len);
2072 old = &g_array_index (array, AllocationParam, index);
2073 allocation_param_free (old);
2075 if ((ap.allocator = allocator))
2076 gst_object_ref (allocator);
2078 ap.params = *params;
2080 gst_allocation_params_init (&ap.params);
2082 g_array_index (array, AllocationParam, index) = ap;
2086 * gst_query_remove_nth_allocation_param:
2087 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2088 * @index: position in the allocation param array to remove
2090 * Remove the allocation param at @index of the allocation param array.
2095 gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
2098 GstStructure *structure;
2100 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2101 g_return_if_fail (gst_query_is_writable (query));
2103 structure = GST_QUERY_STRUCTURE (query);
2105 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
2106 (GDestroyNotify) allocation_param_free);
2107 g_return_if_fail (index < array->len);
2109 g_array_remove_index (array, index);
2113 * gst_query_new_scheduling:
2115 * Constructs a new query object for querying the scheduling properties.
2117 * Free-function: gst_query_unref()
2119 * Returns: (transfer full): a new #GstQuery
2122 gst_query_new_scheduling (void)
2125 GstStructure *structure;
2127 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
2128 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
2129 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
2130 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
2131 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
2132 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2138 * gst_query_set_scheduling:
2139 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2140 * @flags: #GstSchedulingFlags
2141 * @minsize: the suggested minimum size of pull requests
2142 * @maxsize: the suggested maximum size of pull requests
2143 * @align: the suggested alignment of pull requests
2145 * Set the scheduling properties.
2148 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2149 gint minsize, gint maxsize, gint align)
2151 GstStructure *structure;
2153 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2154 g_return_if_fail (gst_query_is_writable (query));
2156 structure = GST_QUERY_STRUCTURE (query);
2157 gst_structure_id_set (structure,
2158 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2159 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2160 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2161 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2165 * gst_query_parse_scheduling:
2166 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2167 * @flags: (out) (allow-none): #GstSchedulingFlags
2168 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
2169 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
2170 * @align: (out) (allow-none): the suggested alignment of pull requests
2172 * Set the scheduling properties.
2175 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2176 gint * minsize, gint * maxsize, gint * align)
2178 GstStructure *structure;
2180 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2182 structure = GST_QUERY_STRUCTURE (query);
2183 gst_structure_id_get (structure,
2184 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2185 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2186 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2187 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2191 * gst_query_add_scheduling_mode:
2192 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2193 * @mode: a #GstPadMode
2195 * Add @mode as one of the supported scheduling modes to @query.
2198 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2200 GstStructure *structure;
2203 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2204 g_return_if_fail (gst_query_is_writable (query));
2206 structure = GST_QUERY_STRUCTURE (query);
2208 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2210 g_array_append_val (array, mode);
2214 * gst_query_get_n_scheduling_modes:
2215 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2217 * Retrieve the number of values currently stored in the
2218 * scheduling mode array of the query's structure.
2220 * Returns: the scheduling mode array size as a #guint.
2223 gst_query_get_n_scheduling_modes (GstQuery * query)
2226 GstStructure *structure;
2228 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2230 structure = GST_QUERY_STRUCTURE (query);
2232 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2238 * gst_query_parse_nth_scheduling_mode:
2239 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2240 * @index: position in the scheduling modes array to read
2242 * Parse an available query and get the scheduling mode
2243 * at @index of the scheduling modes array.
2245 * Returns: a #GstPadMode of the scheduling mode at @index.
2248 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2250 GstStructure *structure;
2253 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2256 structure = GST_QUERY_STRUCTURE (query);
2258 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2259 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2261 return g_array_index (array, GstPadMode, index);
2265 * gst_query_has_scheduling_mode:
2266 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2267 * @mode: the scheduling mode
2269 * Check if @query has scheduling mode set.
2271 * > When checking if upstream supports pull mode, it is usually not
2272 * > enough to just check for GST_PAD_MODE_PULL with this function, you
2273 * > also want to check whether the scheduling flags returned by
2274 * > gst_query_parse_scheduling() have the seeking flag set (meaning
2275 * > random access is supported, not only sequential pulls).
2277 * Returns: %TRUE when @mode is in the list of scheduling modes.
2280 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2282 GstStructure *structure;
2286 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2288 structure = GST_QUERY_STRUCTURE (query);
2290 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2293 for (i = 0; i < len; i++) {
2294 if (mode == g_array_index (array, GstPadMode, i))
2301 * gst_query_has_scheduling_mode_with_flags:
2302 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2303 * @mode: the scheduling mode
2304 * @flags: #GstSchedulingFlags
2306 * Check if @query has scheduling mode set and @flags is set in
2307 * query scheduling flags.
2309 * Returns: %TRUE when @mode is in the list of scheduling modes
2310 * and @flags are compatible with query flags.
2313 gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
2314 GstSchedulingFlags flags)
2316 GstSchedulingFlags sched_flags;
2318 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2320 gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
2322 return ((flags & sched_flags) == flags) &&
2323 gst_query_has_scheduling_mode (query, mode);
2327 * gst_query_new_accept_caps:
2328 * @caps: a fixed #GstCaps
2330 * Constructs a new query object for querying if @caps are accepted.
2332 * Free-function: gst_query_unref()
2334 * Returns: (transfer full): a new #GstQuery
2337 gst_query_new_accept_caps (GstCaps * caps)
2340 GstStructure *structure;
2342 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2344 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2345 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2346 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2347 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2353 * gst_query_parse_accept_caps:
2354 * @query: The query to parse
2355 * @caps: (out) (transfer none): A pointer to the caps
2357 * Get the caps from @query. The caps remains valid as long as @query remains
2361 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2363 GstStructure *structure;
2365 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2366 g_return_if_fail (caps != NULL);
2368 structure = GST_QUERY_STRUCTURE (query);
2369 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2374 * gst_query_set_accept_caps_result:
2375 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2376 * @result: the result to set
2378 * Set @result as the result for the @query.
2381 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2383 GstStructure *structure;
2385 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2386 g_return_if_fail (gst_query_is_writable (query));
2388 structure = GST_QUERY_STRUCTURE (query);
2389 gst_structure_id_set (structure,
2390 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2394 * gst_query_parse_accept_caps_result:
2395 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2396 * @result: (out) (allow-none): location for the result
2398 * Parse the result from @query and store in @result.
2401 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2403 GstStructure *structure;
2405 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2407 structure = GST_QUERY_STRUCTURE (query);
2408 gst_structure_id_get (structure,
2409 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2413 * gst_query_new_caps:
2416 * Constructs a new query object for querying the caps.
2418 * The CAPS query should return the allowable caps for a pad in the context
2419 * of the element's state, its link to other elements, and the devices or files
2420 * it has opened. These caps must be a subset of the pad template caps. In the
2421 * NULL state with no links, the CAPS query should ideally return the same caps
2422 * as the pad template. In rare circumstances, an object property can affect
2423 * the caps returned by the CAPS query, but this is discouraged.
2425 * For most filters, the caps returned by CAPS query is directly affected by the
2426 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2427 * the srcpad's getcaps function is directly related to the stream data. Again,
2428 * the CAPS query should return the most specific caps it reasonably can, since this
2429 * helps with autoplugging.
2431 * The @filter is used to restrict the result caps, only the caps matching
2432 * @filter should be returned from the CAPS query. Specifying a filter might
2433 * greatly reduce the amount of processing an element needs to do.
2435 * Free-function: gst_query_unref()
2437 * Returns: (transfer full): a new #GstQuery
2440 gst_query_new_caps (GstCaps * filter)
2443 GstStructure *structure;
2445 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2446 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2447 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2448 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2454 * gst_query_parse_caps:
2455 * @query: The query to parse
2456 * @filter: (out) (transfer none): A pointer to the caps filter
2458 * Get the filter from the caps @query. The caps remains valid as long as
2459 * @query remains valid.
2462 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2464 GstStructure *structure;
2466 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2467 g_return_if_fail (filter != NULL);
2469 structure = GST_QUERY_STRUCTURE (query);
2470 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2471 GST_QUARK (FILTER)));
2475 * gst_query_set_caps_result:
2476 * @query: The query to use
2477 * @caps: (in): A pointer to the caps
2479 * Set the @caps result in @query.
2482 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2484 GstStructure *structure;
2486 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2487 g_return_if_fail (gst_query_is_writable (query));
2489 structure = GST_QUERY_STRUCTURE (query);
2490 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2494 * gst_query_parse_caps_result:
2495 * @query: The query to parse
2496 * @caps: (out) (transfer none): A pointer to the caps
2498 * Get the caps result from @query. The caps remains valid as long as
2499 * @query remains valid.
2502 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2504 GstStructure *structure;
2506 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2507 g_return_if_fail (caps != NULL);
2509 structure = GST_QUERY_STRUCTURE (query);
2510 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2516 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2517 GstCapsIntersectMode mode)
2519 GstCaps *res, *caps = NULL;
2521 gst_query_parse_caps_result (query, &caps);
2522 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2523 gst_query_set_caps_result (query, res);
2524 gst_caps_unref (res);
2529 * gst_query_new_drain:
2531 * Constructs a new query object for querying the drain state.
2533 * Free-function: gst_query_unref()
2535 * Returns: (transfer full): a new #GstQuery
2538 gst_query_new_drain (void)
2541 GstStructure *structure;
2543 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2544 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2550 * gst_query_new_context:
2551 * @context_type: Context type to query
2553 * Constructs a new query object for querying the pipeline-local context.
2555 * Free-function: gst_query_unref()
2557 * Returns: (transfer full): a new #GstQuery
2562 gst_query_new_context (const gchar * context_type)
2565 GstStructure *structure;
2567 g_return_val_if_fail (context_type != NULL, NULL);
2569 structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
2570 GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2571 query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
2577 * gst_query_set_context:
2578 * @query: a #GstQuery with query type GST_QUERY_CONTEXT
2579 * @context: the requested #GstContext
2581 * Answer a context query by setting the requested context.
2586 gst_query_set_context (GstQuery * query, GstContext * context)
2589 const gchar *context_type;
2591 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2593 gst_query_parse_context_type (query, &context_type);
2594 g_return_if_fail (strcmp (gst_context_get_context_type (context),
2595 context_type) == 0);
2597 s = GST_QUERY_STRUCTURE (query);
2599 gst_structure_id_set (s,
2600 GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2604 * gst_query_parse_context:
2605 * @query: The query to parse
2606 * @context: (out) (transfer none): A pointer to store the #GstContext
2608 * Get the context from the context @query. The context remains valid as long as
2609 * @query remains valid.
2614 gst_query_parse_context (GstQuery * query, GstContext ** context)
2616 GstStructure *structure;
2619 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2620 g_return_if_fail (context != NULL);
2622 structure = GST_QUERY_STRUCTURE (query);
2623 v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
2625 *context = g_value_get_boxed (v);
2631 * gst_query_parse_context_type:
2632 * @query: a GST_QUERY_CONTEXT type query
2633 * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
2635 * Parse a context type from an existing GST_QUERY_CONTEXT query.
2637 * Returns: a #gboolean indicating if the parsing succeeded.
2642 gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
2644 GstStructure *structure;
2645 const GValue *value;
2647 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2649 structure = GST_QUERY_STRUCTURE (query);
2652 value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2653 *context_type = g_value_get_string (value);
2660 * gst_query_new_bitrate:
2662 * Constructs a new query object for querying the bitrate.
2664 * Free-function: gst_query_unref()
2666 * Returns: (transfer full): a new #GstQuery
2671 gst_query_new_bitrate (void)
2674 GstStructure *structure;
2676 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_BITRATE));
2677 query = gst_query_new_custom (GST_QUERY_BITRATE, structure);
2683 * gst_query_set_bitrate:
2684 * @query: a GST_QUERY_BITRATE type #GstQuery
2685 * @nominal_bitrate: the nominal bitrate in bits per second
2687 * Set the results of a bitrate query. The nominal bitrate is the average
2688 * bitrate expected over the length of the stream as advertised in file
2689 * headers (or similar).
2694 gst_query_set_bitrate (GstQuery * query, guint nominal_bitrate)
2698 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
2700 s = GST_QUERY_STRUCTURE (query);
2702 gst_structure_id_set (s,
2703 GST_QUARK (NOMINAL_BITRATE), G_TYPE_UINT, nominal_bitrate, NULL);
2707 * gst_query_parse_bitrate:
2708 * @query: a GST_QUERY_BITRATE type #GstQuery
2709 * @nominal_bitrate: (out) (allow-none): The resulting bitrate in bits per second
2711 * Get the results of a bitrate query. See also gst_query_set_bitrate().
2716 gst_query_parse_bitrate (GstQuery * query, guint * nominal_bitrate)
2718 GstStructure *structure;
2719 const GValue *value;
2721 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BITRATE);
2723 structure = GST_QUERY_STRUCTURE (query);
2725 if (nominal_bitrate) {
2726 value = gst_structure_id_get_value (structure, GST_QUARK (NOMINAL_BITRATE));
2727 *nominal_bitrate = g_value_get_uint (value);