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:
41 * <title>Query duration on a pipeline</title>
45 * query = gst_query_new_duration (GST_FORMAT_TIME);
46 * res = gst_element_query (pipeline, query);
49 * gst_query_parse_duration (query, NULL, &duration);
50 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
53 * g_print ("duration query failed...");
55 * gst_query_unref (query);
59 * Last reviewed on 2012-03-29 (0.11.3)
63 #include "gst_private.h"
67 #include "gstenumtypes.h"
70 #include "gstbufferpool.h"
72 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
73 #define GST_CAT_DEFAULT gst_query_debug
75 static GType _gst_query_type = 0;
81 GstStructure *structure;
84 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
94 static GstQueryQuarks query_quarks[] = {
95 {GST_QUERY_UNKNOWN, "unknown", 0},
96 {GST_QUERY_POSITION, "position", 0},
97 {GST_QUERY_DURATION, "duration", 0},
98 {GST_QUERY_LATENCY, "latency", 0},
99 {GST_QUERY_JITTER, "jitter", 0},
100 {GST_QUERY_RATE, "rate", 0},
101 {GST_QUERY_SEEKING, "seeking", 0},
102 {GST_QUERY_SEGMENT, "segment", 0},
103 {GST_QUERY_CONVERT, "convert", 0},
104 {GST_QUERY_FORMATS, "formats", 0},
105 {GST_QUERY_BUFFERING, "buffering", 0},
106 {GST_QUERY_CUSTOM, "custom", 0},
107 {GST_QUERY_URI, "uri", 0},
108 {GST_QUERY_ALLOCATION, "allocation", 0},
109 {GST_QUERY_SCHEDULING, "scheduling", 0},
110 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
111 {GST_QUERY_CAPS, "caps", 0},
112 {GST_QUERY_DRAIN, "drain", 0},
113 {GST_QUERY_CONTEXT, "context", 0},
118 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
121 _priv_gst_query_initialize (void)
125 _gst_query_type = gst_query_get_type ();
127 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
129 for (i = 0; query_quarks[i].name; i++) {
130 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
135 * gst_query_type_get_name:
136 * @type: the query type
138 * Get a printable name for the given query type. Do not modify or free.
140 * Returns: a reference to the static name of the query.
143 gst_query_type_get_name (GstQueryType type)
147 for (i = 0; query_quarks[i].name; i++) {
148 if (type == query_quarks[i].type)
149 return query_quarks[i].name;
155 * gst_query_type_to_quark:
156 * @type: the query type
158 * Get the unique quark for the given query type.
160 * Returns: the quark associated with the query type
163 gst_query_type_to_quark (GstQueryType type)
167 for (i = 0; query_quarks[i].name; i++) {
168 if (type == query_quarks[i].type)
169 return query_quarks[i].quark;
175 * gst_query_type_get_flags:
176 * @type: a #GstQueryType
178 * Gets the #GstQueryTypeFlags associated with @type.
180 * Returns: a #GstQueryTypeFlags.
183 gst_query_type_get_flags (GstQueryType type)
185 GstQueryTypeFlags ret;
187 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
193 _gst_query_free (GstQuery * query)
197 g_return_if_fail (query != NULL);
199 s = GST_QUERY_STRUCTURE (query);
201 gst_structure_set_parent_refcount (s, NULL);
202 gst_structure_free (s);
205 g_slice_free1 (sizeof (GstQueryImpl), query);
209 _gst_query_copy (GstQuery * query)
214 s = GST_QUERY_STRUCTURE (query);
216 s = gst_structure_copy (s);
218 copy = gst_query_new_custom (query->type, s);
224 * gst_query_new_position:
225 * @format: the default #GstFormat for the new query
227 * Constructs a new query stream position query object. Use gst_query_unref()
228 * when done with it. A position query is used to query the current position
229 * of playback in the streams, in some format.
231 * Free-function: gst_query_unref
233 * Returns: (transfer full): a new #GstQuery
236 gst_query_new_position (GstFormat format)
239 GstStructure *structure;
241 structure = gst_structure_new_id (GST_QUARK (QUERY_POSITION),
242 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
243 GST_QUARK (CURRENT), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
245 query = gst_query_new_custom (GST_QUERY_POSITION, structure);
251 * gst_query_set_position:
252 * @query: a #GstQuery with query type GST_QUERY_POSITION
253 * @format: the requested #GstFormat
254 * @cur: the position to set
256 * Answer a position query by setting the requested value in the given format.
259 gst_query_set_position (GstQuery * query, GstFormat format, gint64 cur)
263 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
265 s = GST_QUERY_STRUCTURE (query);
266 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
267 GST_QUARK (FORMAT))));
269 gst_structure_id_set (s,
270 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
271 GST_QUARK (CURRENT), G_TYPE_INT64, cur, NULL);
275 * gst_query_parse_position:
276 * @query: a #GstQuery
277 * @format: (out) (allow-none): the storage for the #GstFormat of the
278 * position values (may be NULL)
279 * @cur: (out) (allow-none): the storage for the current position (may be NULL)
281 * Parse a position query, writing the format into @format, and the position
282 * into @cur, if the respective parameters are non-NULL.
285 gst_query_parse_position (GstQuery * query, GstFormat * format, gint64 * cur)
287 GstStructure *structure;
289 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_POSITION);
291 structure = GST_QUERY_STRUCTURE (query);
294 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
295 GST_QUARK (FORMAT)));
297 *cur = g_value_get_int64 (gst_structure_id_get_value (structure,
298 GST_QUARK (CURRENT)));
303 * gst_query_new_duration:
304 * @format: the #GstFormat for this duration query
306 * Constructs a new stream duration query object to query in the given format.
307 * Use gst_query_unref() when done with it. A duration query will give the
308 * total length of the stream.
310 * Free-function: gst_query_unref
312 * Returns: (transfer full): a new #GstQuery
315 gst_query_new_duration (GstFormat format)
318 GstStructure *structure;
320 structure = gst_structure_new_id (GST_QUARK (QUERY_DURATION),
321 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
322 GST_QUARK (DURATION), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
324 query = gst_query_new_custom (GST_QUERY_DURATION, structure);
330 * gst_query_set_duration:
331 * @query: a #GstQuery
332 * @format: the #GstFormat for the duration
333 * @duration: the duration of the stream
335 * Answer a duration query by setting the requested value in the given format.
338 gst_query_set_duration (GstQuery * query, GstFormat format, gint64 duration)
342 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
344 s = GST_QUERY_STRUCTURE (query);
345 g_return_if_fail (format == g_value_get_enum (gst_structure_id_get_value (s,
346 GST_QUARK (FORMAT))));
347 gst_structure_id_set (s, GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
348 GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
352 * gst_query_parse_duration:
353 * @query: a #GstQuery
354 * @format: (out) (allow-none): the storage for the #GstFormat of the duration
356 * @duration: (out) (allow-none): the storage for the total duration, or NULL.
358 * Parse a duration query answer. Write the format of the duration into @format,
359 * and the value into @duration, if the respective variables are non-NULL.
362 gst_query_parse_duration (GstQuery * query, GstFormat * format,
365 GstStructure *structure;
367 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_DURATION);
369 structure = GST_QUERY_STRUCTURE (query);
372 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
373 GST_QUARK (FORMAT)));
375 *duration = g_value_get_int64 (gst_structure_id_get_value (structure,
376 GST_QUARK (DURATION)));
380 * gst_query_new_latency:
382 * Constructs a new latency query object.
383 * Use gst_query_unref() when done with it. A latency query is usually performed
384 * by sinks to compensate for additional latency introduced by elements in the
387 * Free-function: gst_query_unref
389 * Returns: (transfer full): a #GstQuery
392 gst_query_new_latency (void)
395 GstStructure *structure;
397 structure = gst_structure_new_id (GST_QUARK (QUERY_LATENCY),
398 GST_QUARK (LIVE), G_TYPE_BOOLEAN, FALSE,
399 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (0),
400 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, G_GUINT64_CONSTANT (-1), NULL);
402 query = gst_query_new_custom (GST_QUERY_LATENCY, structure);
408 * gst_query_set_latency:
409 * @query: a #GstQuery
410 * @live: if there is a live element upstream
411 * @min_latency: the minimal latency of the upstream elements
412 * @max_latency: the maximal latency of the upstream elements
414 * Answer a latency query by setting the requested values in the given format.
417 gst_query_set_latency (GstQuery * query, gboolean live,
418 GstClockTime min_latency, GstClockTime max_latency)
420 GstStructure *structure;
422 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
424 structure = GST_QUERY_STRUCTURE (query);
425 gst_structure_id_set (structure,
426 GST_QUARK (LIVE), G_TYPE_BOOLEAN, live,
427 GST_QUARK (MIN_LATENCY), G_TYPE_UINT64, min_latency,
428 GST_QUARK (MAX_LATENCY), G_TYPE_UINT64, max_latency, NULL);
432 * gst_query_parse_latency:
433 * @query: a #GstQuery
434 * @live: (out) (allow-none): storage for live or NULL
435 * @min_latency: (out) (allow-none): the storage for the min latency or NULL
436 * @max_latency: (out) (allow-none): the storage for the max latency or NULL
438 * Parse a latency query answer.
441 gst_query_parse_latency (GstQuery * query, gboolean * live,
442 GstClockTime * min_latency, GstClockTime * max_latency)
444 GstStructure *structure;
446 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_LATENCY);
448 structure = GST_QUERY_STRUCTURE (query);
451 g_value_get_boolean (gst_structure_id_get_value (structure,
454 *min_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
455 GST_QUARK (MIN_LATENCY)));
457 *max_latency = g_value_get_uint64 (gst_structure_id_get_value (structure,
458 GST_QUARK (MAX_LATENCY)));
462 * gst_query_new_convert:
463 * @src_format: the source #GstFormat for the new query
464 * @value: the value to convert
465 * @dest_format: the target #GstFormat
467 * Constructs a new convert query object. Use gst_query_unref()
468 * when done with it. A convert query is used to ask for a conversion between
469 * one format and another.
471 * Free-function: gst_query_unref
473 * Returns: (transfer full): a #GstQuery
476 gst_query_new_convert (GstFormat src_format, gint64 value,
477 GstFormat dest_format)
480 GstStructure *structure;
482 structure = gst_structure_new_id (GST_QUARK (QUERY_CONVERT),
483 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
484 GST_QUARK (SRC_VALUE), G_TYPE_INT64, value,
485 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
486 GST_QUARK (DEST_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
488 query = gst_query_new_custom (GST_QUERY_CONVERT, structure);
494 * gst_query_set_convert:
495 * @query: a #GstQuery
496 * @src_format: the source #GstFormat
497 * @src_value: the source value
498 * @dest_format: the destination #GstFormat
499 * @dest_value: the destination value
501 * Answer a convert query by setting the requested values.
504 gst_query_set_convert (GstQuery * query, GstFormat src_format, gint64 src_value,
505 GstFormat dest_format, gint64 dest_value)
507 GstStructure *structure;
509 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
511 structure = GST_QUERY_STRUCTURE (query);
512 gst_structure_id_set (structure,
513 GST_QUARK (SRC_FORMAT), GST_TYPE_FORMAT, src_format,
514 GST_QUARK (SRC_VALUE), G_TYPE_INT64, src_value,
515 GST_QUARK (DEST_FORMAT), GST_TYPE_FORMAT, dest_format,
516 GST_QUARK (DEST_VALUE), G_TYPE_INT64, dest_value, NULL);
520 * gst_query_parse_convert:
521 * @query: a #GstQuery
522 * @src_format: (out) (allow-none): the storage for the #GstFormat of the
523 * source value, or NULL
524 * @src_value: (out) (allow-none): the storage for the source value, or NULL
525 * @dest_format: (out) (allow-none): the storage for the #GstFormat of the
526 * destination value, or NULL
527 * @dest_value: (out) (allow-none): the storage for the destination value,
530 * Parse a convert query answer. Any of @src_format, @src_value, @dest_format,
531 * and @dest_value may be NULL, in which case that value is omitted.
534 gst_query_parse_convert (GstQuery * query, GstFormat * src_format,
535 gint64 * src_value, GstFormat * dest_format, gint64 * dest_value)
537 GstStructure *structure;
539 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONVERT);
541 structure = GST_QUERY_STRUCTURE (query);
544 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
545 GST_QUARK (SRC_FORMAT)));
547 *src_value = g_value_get_int64 (gst_structure_id_get_value (structure,
548 GST_QUARK (SRC_VALUE)));
551 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
552 GST_QUARK (DEST_FORMAT)));
554 *dest_value = g_value_get_int64 (gst_structure_id_get_value (structure,
555 GST_QUARK (DEST_VALUE)));
559 * gst_query_new_segment:
560 * @format: the #GstFormat for the new query
562 * Constructs a new segment query object. Use gst_query_unref()
563 * when done with it. A segment query is used to discover information about the
564 * currently configured segment for playback.
566 * Free-function: gst_query_unref
568 * Returns: (transfer full): a new #GstQuery
571 gst_query_new_segment (GstFormat format)
574 GstStructure *structure;
576 structure = gst_structure_new_id (GST_QUARK (QUERY_SEGMENT),
577 GST_QUARK (RATE), G_TYPE_DOUBLE, (gdouble) 0.0,
578 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
579 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
580 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
582 query = gst_query_new_custom (GST_QUERY_SEGMENT, structure);
588 * gst_query_set_segment:
589 * @query: a #GstQuery
590 * @rate: the rate of the segment
591 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
592 * @start_value: the start value
593 * @stop_value: the stop value
595 * Answer a segment query by setting the requested values. The normal
596 * playback segment of a pipeline is 0 to duration at the default rate of
597 * 1.0. If a seek was performed on the pipeline to play a different
598 * segment, this query will return the range specified in the last seek.
600 * @start_value and @stop_value will respectively contain the configured
601 * playback range start and stop values expressed in @format.
602 * The values are always between 0 and the duration of the media and
603 * @start_value <= @stop_value. @rate will contain the playback rate. For
604 * negative rates, playback will actually happen from @stop_value to
608 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
609 gint64 start_value, gint64 stop_value)
611 GstStructure *structure;
613 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
615 structure = GST_QUERY_STRUCTURE (query);
616 gst_structure_id_set (structure,
617 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
618 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
619 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
620 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
624 * gst_query_parse_segment:
625 * @query: a #GstQuery
626 * @rate: (out) (allow-none): the storage for the rate of the segment, or NULL
627 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
629 * @start_value: (out) (allow-none): the storage for the start value, or NULL
630 * @stop_value: (out) (allow-none): the storage for the stop value, or NULL
632 * Parse a segment query answer. Any of @rate, @format, @start_value, and
633 * @stop_value may be NULL, which will cause this value to be omitted.
635 * See gst_query_set_segment() for an explanation of the function arguments.
638 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
639 gint64 * start_value, gint64 * stop_value)
641 GstStructure *structure;
643 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
645 structure = GST_QUERY_STRUCTURE (query);
647 *rate = g_value_get_double (gst_structure_id_get_value (structure,
651 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
652 GST_QUARK (FORMAT)));
654 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
655 GST_QUARK (START_VALUE)));
657 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
658 GST_QUARK (STOP_VALUE)));
662 * gst_query_new_custom:
663 * @type: the query type
664 * @structure: a structure for the query
666 * Constructs a new custom query object. Use gst_query_unref()
669 * Free-function: gst_query_unref
671 * Returns: (transfer full): a new #GstQuery
674 gst_query_new_custom (GstQueryType type, GstStructure * structure)
678 query = g_slice_new0 (GstQueryImpl);
680 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
683 /* structure must not have a parent */
684 if (!gst_structure_set_parent_refcount (structure,
685 &query->query.mini_object.refcount))
689 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
690 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
691 (GstMiniObjectFreeFunction) _gst_query_free);
693 GST_QUERY_TYPE (query) = type;
694 GST_QUERY_STRUCTURE (query) = structure;
696 return GST_QUERY_CAST (query);
701 g_slice_free1 (sizeof (GstQueryImpl), query);
702 g_warning ("structure is already owned by another object");
708 * gst_query_get_structure:
709 * @query: a #GstQuery
711 * Get the structure of a query.
713 * Returns: (transfer none): the #GstStructure of the query. The structure is
714 * still owned by the query and will therefore be freed when the query
718 gst_query_get_structure (GstQuery * query)
720 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
722 return GST_QUERY_STRUCTURE (query);
726 * gst_query_writable_structure:
727 * @query: a #GstQuery
729 * Get the structure of a query. This method should be called with a writable
730 * @query so that the returned structure is guranteed to be writable.
732 * Returns: (transfer none): the #GstStructure of the query. The structure is
733 * still owned by the query and will therefore be freed when the query
737 gst_query_writable_structure (GstQuery * query)
739 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
740 g_return_val_if_fail (gst_query_is_writable (query), NULL);
742 return GST_QUERY_STRUCTURE (query);
746 * gst_query_new_seeking:
747 * @format: the default #GstFormat for the new query
749 * Constructs a new query object for querying seeking properties of
752 * Free-function: gst_query_unref
754 * Returns: (transfer full): a new #GstQuery
757 gst_query_new_seeking (GstFormat format)
760 GstStructure *structure;
762 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
763 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
764 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
765 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
766 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
768 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
774 * gst_query_set_seeking:
775 * @query: a #GstQuery
776 * @format: the format to set for the @segment_start and @segment_end values
777 * @seekable: the seekable flag to set
778 * @segment_start: the segment_start to set
779 * @segment_end: the segment_end to set
781 * Set the seeking query result fields in @query.
784 gst_query_set_seeking (GstQuery * query, GstFormat format,
785 gboolean seekable, gint64 segment_start, gint64 segment_end)
787 GstStructure *structure;
789 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
790 g_return_if_fail (gst_query_is_writable (query));
792 structure = GST_QUERY_STRUCTURE (query);
793 gst_structure_id_set (structure,
794 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
795 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
796 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
797 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
801 * gst_query_parse_seeking:
802 * @query: a GST_QUERY_SEEKING type query #GstQuery
803 * @format: (out) (allow-none): the format to set for the @segment_start
804 * and @segment_end values, or NULL
805 * @seekable: (out) (allow-none): the seekable flag to set, or NULL
806 * @segment_start: (out) (allow-none): the segment_start to set, or NULL
807 * @segment_end: (out) (allow-none): the segment_end to set, or NULL
809 * Parse a seeking query, writing the format into @format, and
810 * other results into the passed parameters, if the respective parameters
814 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
815 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
817 GstStructure *structure;
819 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
821 structure = GST_QUERY_STRUCTURE (query);
824 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
825 GST_QUARK (FORMAT)));
827 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
828 GST_QUARK (SEEKABLE)));
830 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
831 GST_QUARK (SEGMENT_START)));
833 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
834 GST_QUARK (SEGMENT_END)));
838 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
839 GDestroyNotify clear_func)
844 value = gst_structure_id_get_value (s, quark);
846 array = (GArray *) g_value_get_boxed (value);
848 GValue new_array_val = { 0, };
850 array = g_array_new (FALSE, TRUE, element_size);
852 g_array_set_clear_func (array, clear_func);
854 g_value_init (&new_array_val, G_TYPE_ARRAY);
855 g_value_take_boxed (&new_array_val, array);
857 gst_structure_id_take_value (s, quark, &new_array_val);
863 * gst_query_new_formats:
865 * Constructs a new query object for querying formats of
868 * Free-function: gst_query_unref
870 * Returns: (transfer full): a new #GstQuery
873 gst_query_new_formats (void)
876 GstStructure *structure;
878 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
879 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
885 gst_query_list_add_format (GValue * list, GstFormat format)
887 GValue item = { 0, };
889 g_value_init (&item, GST_TYPE_FORMAT);
890 g_value_set_enum (&item, format);
891 gst_value_list_append_value (list, &item);
892 g_value_unset (&item);
896 * gst_query_set_formats:
897 * @query: a #GstQuery
898 * @n_formats: the number of formats to set.
899 * @...: A number of @GstFormats equal to @n_formats.
901 * Set the formats query result fields in @query. The number of formats passed
902 * must be equal to @n_formats.
905 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
908 GValue list = { 0, };
910 GstStructure *structure;
912 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
913 g_return_if_fail (gst_query_is_writable (query));
915 g_value_init (&list, GST_TYPE_LIST);
917 va_start (ap, n_formats);
918 for (i = 0; i < n_formats; i++) {
919 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
923 structure = GST_QUERY_STRUCTURE (query);
924 gst_structure_set_value (structure, "formats", &list);
926 g_value_unset (&list);
931 * gst_query_set_formatsv:
932 * @query: a #GstQuery
933 * @n_formats: the number of formats to set.
934 * @formats: (in) (array length=n_formats): an array containing @n_formats
937 * Set the formats query result fields in @query. The number of formats passed
938 * in the @formats array must be equal to @n_formats.
941 gst_query_set_formatsv (GstQuery * query, gint n_formats,
942 const GstFormat * formats)
944 GValue list = { 0, };
946 GstStructure *structure;
948 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
949 g_return_if_fail (gst_query_is_writable (query));
951 g_value_init (&list, GST_TYPE_LIST);
952 for (i = 0; i < n_formats; i++) {
953 gst_query_list_add_format (&list, formats[i]);
955 structure = GST_QUERY_STRUCTURE (query);
956 gst_structure_set_value (structure, "formats", &list);
958 g_value_unset (&list);
962 * gst_query_parse_n_formats:
963 * @query: a #GstQuery
964 * @n_formats: (out) (allow-none): the number of formats in this query.
966 * Parse the number of formats in the formats @query.
969 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
971 GstStructure *structure;
973 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
978 structure = GST_QUERY_STRUCTURE (query);
979 list = gst_structure_get_value (structure, "formats");
983 *n_formats = gst_value_list_get_size (list);
988 * gst_query_parse_nth_format:
989 * @query: a #GstQuery
990 * @nth: (out): the nth format to retrieve.
991 * @format: (out) (allow-none): a pointer to store the nth format
993 * Parse the format query and retrieve the @nth format from it into
994 * @format. If the list contains less elements than @nth, @format will be
995 * set to GST_FORMAT_UNDEFINED.
998 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1000 GstStructure *structure;
1002 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1007 structure = GST_QUERY_STRUCTURE (query);
1008 list = gst_structure_get_value (structure, "formats");
1010 *format = GST_FORMAT_UNDEFINED;
1012 if (nth < gst_value_list_get_size (list)) {
1014 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1016 *format = GST_FORMAT_UNDEFINED;
1022 * gst_query_new_buffering:
1023 * @format: the default #GstFormat for the new query
1025 * Constructs a new query object for querying the buffering status of
1028 * Free-function: gst_query_unref
1030 * Returns: (transfer full): a new #GstQuery
1033 gst_query_new_buffering (GstFormat format)
1036 GstStructure *structure;
1038 /* by default, we configure the answer as no buffering with a 100% buffering
1040 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1041 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1042 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1043 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1044 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1045 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1046 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1047 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1048 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1049 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1050 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1052 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1058 * gst_query_set_buffering_percent:
1059 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1060 * @busy: if buffering is busy
1061 * @percent: a buffering percent
1063 * Set the percentage of buffered data. This is a value between 0 and 100.
1064 * The @busy indicator is %TRUE when the buffering is in progress.
1067 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1069 GstStructure *structure;
1071 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1072 g_return_if_fail (gst_query_is_writable (query));
1073 g_return_if_fail (percent >= 0 && percent <= 100);
1075 structure = GST_QUERY_STRUCTURE (query);
1076 gst_structure_id_set (structure,
1077 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1078 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1082 * gst_query_parse_buffering_percent:
1083 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1084 * @busy: (out) (allow-none): if buffering is busy, or NULL
1085 * @percent: (out) (allow-none): a buffering percent, or NULL
1087 * Get the percentage of buffered data. This is a value between 0 and 100.
1088 * The @busy indicator is %TRUE when the buffering is in progress.
1091 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1094 GstStructure *structure;
1096 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1098 structure = GST_QUERY_STRUCTURE (query);
1100 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1103 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1104 GST_QUARK (BUFFER_PERCENT)));
1108 * gst_query_set_buffering_stats:
1109 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1110 * @mode: a buffering mode
1111 * @avg_in: the average input rate
1112 * @avg_out: the average output rate
1113 * @buffering_left: amount of buffering time left in milliseconds
1115 * Configures the buffering stats values in @query.
1118 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1119 gint avg_in, gint avg_out, gint64 buffering_left)
1121 GstStructure *structure;
1123 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1124 g_return_if_fail (gst_query_is_writable (query));
1126 structure = GST_QUERY_STRUCTURE (query);
1127 gst_structure_id_set (structure,
1128 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1129 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1130 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1131 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1135 * gst_query_parse_buffering_stats:
1136 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1137 * @mode: (out) (allow-none): a buffering mode, or NULL
1138 * @avg_in: (out) (allow-none): the average input rate, or NULL
1139 * @avg_out: (out) (allow-none): the average output rat, or NULLe
1140 * @buffering_left: (out) (allow-none): amount of buffering time left in
1141 * milliseconds, or NULL
1143 * Extracts the buffering stats values from @query.
1146 gst_query_parse_buffering_stats (GstQuery * query,
1147 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1148 gint64 * buffering_left)
1150 GstStructure *structure;
1152 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1154 structure = GST_QUERY_STRUCTURE (query);
1156 *mode = (GstBufferingMode)
1157 g_value_get_enum (gst_structure_id_get_value (structure,
1158 GST_QUARK (BUFFERING_MODE)));
1160 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1161 GST_QUARK (AVG_IN_RATE)));
1163 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1164 GST_QUARK (AVG_OUT_RATE)));
1167 g_value_get_int64 (gst_structure_id_get_value (structure,
1168 GST_QUARK (BUFFERING_LEFT)));
1172 * gst_query_set_buffering_range:
1173 * @query: a #GstQuery
1174 * @format: the format to set for the @start and @stop values
1175 * @start: the start to set
1176 * @stop: the stop to set
1177 * @estimated_total: estimated total amount of download time remaining in
1180 * Set the available query result fields in @query.
1183 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1184 gint64 start, gint64 stop, gint64 estimated_total)
1186 GstStructure *structure;
1188 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1189 g_return_if_fail (gst_query_is_writable (query));
1191 structure = GST_QUERY_STRUCTURE (query);
1192 gst_structure_id_set (structure,
1193 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1194 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1195 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1196 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1200 * gst_query_parse_buffering_range:
1201 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1202 * @format: (out) (allow-none): the format to set for the @segment_start
1203 * and @segment_end values, or NULL
1204 * @start: (out) (allow-none): the start to set, or NULL
1205 * @stop: (out) (allow-none): the stop to set, or NULL
1206 * @estimated_total: (out) (allow-none): estimated total amount of download
1207 * time remaining in miliseconds, or NULL
1209 * Parse an available query, writing the format into @format, and
1210 * other results into the passed parameters, if the respective parameters
1214 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1215 gint64 * start, gint64 * stop, gint64 * estimated_total)
1217 GstStructure *structure;
1219 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1221 structure = GST_QUERY_STRUCTURE (query);
1224 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1225 GST_QUARK (FORMAT)));
1227 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1228 GST_QUARK (START_VALUE)));
1230 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1231 GST_QUARK (STOP_VALUE)));
1232 if (estimated_total)
1234 g_value_get_int64 (gst_structure_id_get_value (structure,
1235 GST_QUARK (ESTIMATED_TOTAL)));
1238 /* GstQueryBufferingRange: internal struct for GArray */
1243 } GstQueryBufferingRange;
1246 * gst_query_add_buffering_range:
1247 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1248 * @start: start position of the range
1249 * @stop: stop position of the range
1251 * Set the buffering-ranges array field in @query. The current last
1252 * start position of the array should be inferior to @start.
1254 * Returns: a #gboolean indicating if the range was added or not.
1257 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1259 GstQueryBufferingRange range;
1260 GstStructure *structure;
1263 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1264 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1266 if (G_UNLIKELY (start >= stop))
1269 structure = GST_QUERY_STRUCTURE (query);
1270 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1271 sizeof (GstQueryBufferingRange), NULL);
1273 if (array->len > 1) {
1274 GstQueryBufferingRange *last;
1276 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1278 if (G_UNLIKELY (start <= last->start))
1282 range.start = start;
1284 g_array_append_val (array, range);
1290 * gst_query_get_n_buffering_ranges:
1291 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1293 * Retrieve the number of values currently stored in the
1294 * buffered-ranges array of the query's structure.
1296 * Returns: the range array size as a #guint.
1299 gst_query_get_n_buffering_ranges (GstQuery * query)
1301 GstStructure *structure;
1304 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1306 structure = GST_QUERY_STRUCTURE (query);
1307 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1308 sizeof (GstQueryBufferingRange), NULL);
1315 * gst_query_parse_nth_buffering_range:
1316 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1317 * @index: position in the buffered-ranges array to read
1318 * @start: (out) (allow-none): the start position to set, or NULL
1319 * @stop: (out) (allow-none): the stop position to set, or NULL
1321 * Parse an available query and get the start and stop values stored
1322 * at the @index of the buffered ranges array.
1324 * Returns: a #gboolean indicating if the parsing succeeded.
1327 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1328 gint64 * start, gint64 * stop)
1330 GstQueryBufferingRange *range;
1331 GstStructure *structure;
1334 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1336 structure = GST_QUERY_STRUCTURE (query);
1338 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1339 sizeof (GstQueryBufferingRange), NULL);
1340 g_return_val_if_fail (index < array->len, FALSE);
1342 range = &g_array_index (array, GstQueryBufferingRange, index);
1345 *start = range->start;
1347 *stop = range->stop;
1354 * gst_query_new_uri:
1356 * Constructs a new query URI query object. Use gst_query_unref()
1357 * when done with it. An URI query is used to query the current URI
1358 * that is used by the source or sink.
1360 * Free-function: gst_query_unref
1362 * Returns: (transfer full): a new #GstQuery
1365 gst_query_new_uri (void)
1368 GstStructure *structure;
1370 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1371 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1373 query = gst_query_new_custom (GST_QUERY_URI, structure);
1379 * gst_query_set_uri:
1380 * @query: a #GstQuery with query type GST_QUERY_URI
1381 * @uri: the URI to set
1383 * Answer a URI query by setting the requested URI.
1386 gst_query_set_uri (GstQuery * query, const gchar * uri)
1388 GstStructure *structure;
1390 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1391 g_return_if_fail (gst_query_is_writable (query));
1392 g_return_if_fail (gst_uri_is_valid (uri));
1394 structure = GST_QUERY_STRUCTURE (query);
1395 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1399 * gst_query_parse_uri:
1400 * @query: a #GstQuery
1401 * @uri: (out) (transfer full) (allow-none): the storage for the current URI
1404 * Parse an URI query, writing the URI into @uri as a newly
1405 * allocated string, if the respective parameters are non-NULL.
1406 * Free the string with g_free() after usage.
1409 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1411 GstStructure *structure;
1413 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1415 structure = GST_QUERY_STRUCTURE (query);
1417 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1422 * gst_query_set_uri_redirection:
1423 * @query: a #GstQuery with query type GST_QUERY_URI
1424 * @uri: the URI to set
1426 * Answer a URI query by setting the requested URI redirection.
1429 gst_query_set_uri_redirection (GstQuery * query, const gchar * uri)
1431 GstStructure *structure;
1433 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1434 g_return_if_fail (gst_query_is_writable (query));
1435 g_return_if_fail (gst_uri_is_valid (uri));
1437 structure = GST_QUERY_STRUCTURE (query);
1438 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
1439 G_TYPE_STRING, uri, NULL);
1443 * gst_query_parse_uri_redirection:
1444 * @query: a #GstQuery
1445 * @uri: (out) (transfer full) (allow-none): the storage for the redirect URI
1448 * Parse an URI query, writing the URI into @uri as a newly
1449 * allocated string, if the respective parameters are non-NULL.
1450 * Free the string with g_free() after usage.
1453 gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
1455 GstStructure *structure;
1457 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1459 structure = GST_QUERY_STRUCTURE (query);
1460 gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION), uri, NULL);
1464 * gst_query_new_allocation:
1465 * @caps: the negotiated caps
1466 * @need_pool: return a pool
1468 * Constructs a new query object for querying the allocation properties.
1470 * Free-function: gst_query_unref
1472 * Returns: (transfer full): a new #GstQuery
1475 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1478 GstStructure *structure;
1480 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1481 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1482 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1484 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1490 * gst_query_parse_allocation:
1491 * @query: a #GstQuery
1492 * @caps: (out) (transfer none) (allow-none): The #GstCaps
1493 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1495 * Parse an allocation query, writing the requested caps in @caps and
1496 * whether a pool is needed in @need_pool, if the respective parameters
1500 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1501 gboolean * need_pool)
1503 GstStructure *structure;
1505 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1507 structure = GST_QUERY_STRUCTURE (query);
1509 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1512 gst_structure_id_get (structure,
1513 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1518 GstBufferPool *pool;
1525 allocation_pool_free (AllocationPool * ap)
1528 gst_object_unref (ap->pool);
1532 * gst_query_add_allocation_pool:
1533 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1534 * @pool: the #GstBufferPool
1536 * @min_buffers: the min buffers
1537 * @max_buffers: the max buffers
1539 * Set the pool parameters in @query.
1542 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1543 guint size, guint min_buffers, guint max_buffers)
1546 GstStructure *structure;
1549 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1550 g_return_if_fail (gst_query_is_writable (query));
1551 g_return_if_fail (size != 0);
1553 structure = GST_QUERY_STRUCTURE (query);
1554 array = ensure_array (structure, GST_QUARK (POOL),
1555 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1557 if ((ap.pool = pool))
1558 gst_object_ref (pool);
1560 ap.min_buffers = min_buffers;
1561 ap.max_buffers = max_buffers;
1563 g_array_append_val (array, ap);
1568 * gst_query_get_n_allocation_pools:
1569 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1571 * Retrieve the number of values currently stored in the
1572 * pool array of the query's structure.
1574 * Returns: the pool array size as a #guint.
1577 gst_query_get_n_allocation_pools (GstQuery * query)
1580 GstStructure *structure;
1582 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1584 structure = GST_QUERY_STRUCTURE (query);
1585 array = ensure_array (structure, GST_QUARK (POOL),
1586 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1592 * gst_query_parse_nth_allocation_pool:
1593 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1594 * @index: index to parse
1595 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1596 * @size: (out) (allow-none): the size
1597 * @min_buffers: (out) (allow-none): the min buffers
1598 * @max_buffers: (out) (allow-none): the max buffers
1600 * Get the pool parameters in @query.
1602 * Unref @pool with gst_object_unref() when it's not needed any more.
1605 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1606 GstBufferPool ** pool, guint * size, guint * min_buffers,
1607 guint * max_buffers)
1610 GstStructure *structure;
1613 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1615 structure = GST_QUERY_STRUCTURE (query);
1616 array = ensure_array (structure, GST_QUARK (POOL),
1617 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1618 g_return_if_fail (index < array->len);
1620 ap = &g_array_index (array, AllocationPool, index);
1623 if ((*pool = ap->pool))
1624 gst_object_ref (*pool);
1628 *min_buffers = ap->min_buffers;
1630 *max_buffers = ap->max_buffers;
1634 * gst_query_set_nth_allocation_pool:
1635 * @index: index to modify
1636 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1637 * @pool: the #GstBufferPool
1639 * @min_buffers: the min buffers
1640 * @max_buffers: the max buffers
1642 * Set the pool parameters in @query.
1645 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1646 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1649 GstStructure *structure;
1650 AllocationPool *oldap, ap;
1652 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1654 structure = GST_QUERY_STRUCTURE (query);
1655 array = ensure_array (structure, GST_QUARK (POOL),
1656 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1657 g_return_if_fail (index < array->len);
1659 oldap = &g_array_index (array, AllocationPool, index);
1660 allocation_pool_free (oldap);
1662 if ((ap.pool = pool))
1663 gst_object_ref (pool);
1665 ap.min_buffers = min_buffers;
1666 ap.max_buffers = max_buffers;
1667 g_array_index (array, AllocationPool, index) = ap;
1671 * gst_query_remove_nth_allocation_pool:
1672 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1673 * @index: position in the allocation pool array to remove
1675 * Remove the allocation pool at @index of the allocation pool array.
1680 gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
1683 GstStructure *structure;
1685 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1686 g_return_if_fail (gst_query_is_writable (query));
1688 structure = GST_QUERY_STRUCTURE (query);
1690 ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
1691 (GDestroyNotify) allocation_pool_free);
1692 g_return_if_fail (index < array->len);
1694 g_array_remove_index (array, index);
1700 GstStructure *params;
1704 allocation_meta_free (AllocationMeta * am)
1707 gst_structure_free (am->params);
1711 * gst_query_add_allocation_meta:
1712 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1713 * @api: the metadata API
1714 * @params: (transfer none) (allow-none): API specific parameters
1716 * Add @api with @params as one of the supported metadata API to @query.
1719 gst_query_add_allocation_meta (GstQuery * query, GType api,
1720 const GstStructure * params)
1723 GstStructure *structure;
1726 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1727 g_return_if_fail (api != 0);
1728 g_return_if_fail (gst_query_is_writable (query));
1730 structure = GST_QUERY_STRUCTURE (query);
1732 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1733 (GDestroyNotify) allocation_meta_free);
1736 am.params = (params ? gst_structure_copy (params) : NULL);
1738 g_array_append_val (array, am);
1742 * gst_query_get_n_allocation_metas:
1743 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1745 * Retrieve the number of values currently stored in the
1746 * meta API array of the query's structure.
1748 * Returns: the metadata API array size as a #guint.
1751 gst_query_get_n_allocation_metas (GstQuery * query)
1754 GstStructure *structure;
1756 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1758 structure = GST_QUERY_STRUCTURE (query);
1760 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1761 (GDestroyNotify) allocation_meta_free);
1767 * gst_query_parse_nth_allocation_meta:
1768 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1769 * @index: position in the metadata API array to read
1770 * @params: (out) (transfer none) (allow-none): API specific flags
1772 * Parse an available query and get the metadata API
1773 * at @index of the metadata API array.
1775 * Returns: a #GType of the metadata API at @index.
1778 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1779 const GstStructure ** params)
1782 GstStructure *structure;
1785 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1787 structure = GST_QUERY_STRUCTURE (query);
1789 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1790 (GDestroyNotify) allocation_meta_free);
1792 g_return_val_if_fail (index < array->len, 0);
1794 am = &g_array_index (array, AllocationMeta, index);
1797 *params = am->params;
1803 * gst_query_remove_nth_allocation_meta:
1804 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1805 * @index: position in the metadata API array to remove
1807 * Remove the metadata API at @index of the metadata API array.
1810 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1813 GstStructure *structure;
1815 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1816 g_return_if_fail (gst_query_is_writable (query));
1818 structure = GST_QUERY_STRUCTURE (query);
1820 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1821 (GDestroyNotify) allocation_meta_free);
1822 g_return_if_fail (index < array->len);
1824 g_array_remove_index (array, index);
1828 * gst_query_find_allocation_meta:
1829 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1830 * @api: the metadata API
1831 * @index: (out) (transfer none) (allow-none): the index
1833 * Check if @query has metadata @api set. When this function returns TRUE,
1834 * @index will contain the index where the requested API and the flags can be
1837 * Returns: TRUE when @api is in the list of metadata.
1840 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1843 GstStructure *structure;
1846 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1847 g_return_val_if_fail (api != 0, FALSE);
1849 structure = GST_QUERY_STRUCTURE (query);
1851 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1852 (GDestroyNotify) allocation_meta_free);
1855 for (i = 0; i < len; i++) {
1856 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1857 if (am->api == api) {
1868 GstAllocator *allocator;
1869 GstAllocationParams params;
1873 allocation_param_free (AllocationParam * ap)
1876 gst_object_unref (ap->allocator);
1880 * gst_query_add_allocation_param:
1881 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1882 * @allocator: (transfer none) (allow-none): the memory allocator
1883 * @params: (transfer none) (allow-none): a #GstAllocationParams
1885 * Add @allocator and its @params as a supported memory allocator.
1888 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
1889 const GstAllocationParams * params)
1892 GstStructure *structure;
1895 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1896 g_return_if_fail (gst_query_is_writable (query));
1897 g_return_if_fail (allocator != NULL || params != NULL);
1899 structure = GST_QUERY_STRUCTURE (query);
1900 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1901 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1903 if ((ap.allocator = allocator))
1904 gst_object_ref (allocator);
1906 ap.params = *params;
1908 gst_allocation_params_init (&ap.params);
1910 g_array_append_val (array, ap);
1914 * gst_query_get_n_allocation_params:
1915 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1917 * Retrieve the number of values currently stored in the
1918 * allocator params array of the query's structure.
1920 * If no memory allocator is specified, the downstream element can handle
1921 * the default memory allocator. The first memory allocator in the query
1922 * should be generic and allow mapping to system memory, all following
1923 * allocators should be ordered by preference with the preferred one first.
1925 * Returns: the allocator array size as a #guint.
1928 gst_query_get_n_allocation_params (GstQuery * query)
1931 GstStructure *structure;
1933 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1935 structure = GST_QUERY_STRUCTURE (query);
1936 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1937 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1943 * gst_query_parse_nth_allocation_param:
1944 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1945 * @index: position in the allocator array to read
1946 * @allocator: (out) (transfer full) (allow-none): variable to hold the result
1947 * @params: (out) (allow-none): parameters for the allocator
1949 * Parse an available query and get the alloctor and its params
1950 * at @index of the allocator array.
1953 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
1954 GstAllocator ** allocator, GstAllocationParams * params)
1957 GstStructure *structure;
1958 AllocationParam *ap;
1960 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1962 structure = GST_QUERY_STRUCTURE (query);
1963 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1964 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1965 g_return_if_fail (index < array->len);
1967 ap = &g_array_index (array, AllocationParam, index);
1970 if ((*allocator = ap->allocator))
1971 gst_object_ref (*allocator);
1973 *params = ap->params;
1977 * gst_query_set_nth_allocation_param:
1978 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1979 * @index: position in the allocator array to set
1980 * @allocator: (transfer none) (allow-none): new allocator to set
1981 * @params: (transfer none) (allow-none): parameters for the allocator
1983 * Parse an available query and get the alloctor and its params
1984 * at @index of the allocator array.
1987 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
1988 GstAllocator * allocator, const GstAllocationParams * params)
1991 GstStructure *structure;
1992 AllocationParam *old, ap;
1994 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1996 structure = GST_QUERY_STRUCTURE (query);
1997 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
1998 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
1999 g_return_if_fail (index < array->len);
2001 old = &g_array_index (array, AllocationParam, index);
2002 allocation_param_free (old);
2004 if ((ap.allocator = allocator))
2005 gst_object_ref (allocator);
2007 ap.params = *params;
2009 gst_allocation_params_init (&ap.params);
2011 g_array_index (array, AllocationParam, index) = ap;
2015 * gst_query_remove_nth_allocation_param:
2016 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2017 * @index: position in the allocation param array to remove
2019 * Remove the allocation param at @index of the allocation param array.
2024 gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
2027 GstStructure *structure;
2029 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2030 g_return_if_fail (gst_query_is_writable (query));
2032 structure = GST_QUERY_STRUCTURE (query);
2034 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
2035 (GDestroyNotify) allocation_param_free);
2036 g_return_if_fail (index < array->len);
2038 g_array_remove_index (array, index);
2042 * gst_query_new_scheduling:
2044 * Constructs a new query object for querying the scheduling properties.
2046 * Free-function: gst_query_unref
2048 * Returns: (transfer full): a new #GstQuery
2051 gst_query_new_scheduling (void)
2054 GstStructure *structure;
2056 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
2057 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
2058 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
2059 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
2060 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
2061 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2067 * gst_query_set_scheduling:
2068 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2069 * @flags: #GstSchedulingFlags
2070 * @minsize: the suggested minimum size of pull requests
2071 * @maxsize: the suggested maximum size of pull requests
2072 * @align: the suggested alignment of pull requests
2074 * Set the scheduling properties.
2077 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2078 gint minsize, gint maxsize, gint align)
2080 GstStructure *structure;
2082 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2083 g_return_if_fail (gst_query_is_writable (query));
2085 structure = GST_QUERY_STRUCTURE (query);
2086 gst_structure_id_set (structure,
2087 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2088 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2089 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2090 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2094 * gst_query_parse_scheduling:
2095 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2096 * @flags: (out) (allow-none): #GstSchedulingFlags
2097 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
2098 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
2099 * @align: (out) (allow-none): the suggested alignment of pull requests
2101 * Set the scheduling properties.
2104 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2105 gint * minsize, gint * maxsize, gint * align)
2107 GstStructure *structure;
2109 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2111 structure = GST_QUERY_STRUCTURE (query);
2112 gst_structure_id_get (structure,
2113 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2114 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2115 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2116 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2120 * gst_query_add_scheduling_mode:
2121 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2122 * @mode: a #GstPadMode
2124 * Add @mode as aone of the supported scheduling modes to @query.
2127 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2129 GstStructure *structure;
2132 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2133 g_return_if_fail (gst_query_is_writable (query));
2135 structure = GST_QUERY_STRUCTURE (query);
2137 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2139 g_array_append_val (array, mode);
2143 * gst_query_get_n_scheduling_modes:
2144 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2146 * Retrieve the number of values currently stored in the
2147 * scheduling mode array of the query's structure.
2149 * Returns: the scheduling mode array size as a #guint.
2152 gst_query_get_n_scheduling_modes (GstQuery * query)
2155 GstStructure *structure;
2157 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2159 structure = GST_QUERY_STRUCTURE (query);
2161 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2167 * gst_query_parse_nth_scheduling_mode:
2168 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2169 * @index: position in the scheduling modes array to read
2171 * Parse an available query and get the scheduling mode
2172 * at @index of the scheduling modes array.
2174 * Returns: a #GstPadMode of the scheduling mode at @index.
2177 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2179 GstStructure *structure;
2182 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2185 structure = GST_QUERY_STRUCTURE (query);
2187 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2188 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2190 return g_array_index (array, GstPadMode, index);
2194 * gst_query_has_scheduling_mode:
2195 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2196 * @mode: the scheduling mode
2198 * Check if @query has scheduling mode set.
2202 * When checking if upstream supports pull mode, it is usually not
2203 * enough to just check for GST_PAD_MODE_PULL with this function, you
2204 * also want to check whether the scheduling flags returned by
2205 * gst_query_parse_scheduling() have the seeking flag set (meaning
2206 * random access is supported, not only sequential pulls).
2210 * Returns: TRUE when @mode is in the list of scheduling modes.
2213 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2215 GstStructure *structure;
2219 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2221 structure = GST_QUERY_STRUCTURE (query);
2223 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2226 for (i = 0; i < len; i++) {
2227 if (mode == g_array_index (array, GstPadMode, i))
2234 * gst_query_has_scheduling_mode_with_flags:
2235 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2236 * @mode: the scheduling mode
2237 * @flags: #GstSchedulingFlags
2239 * Check if @query has scheduling mode set and @flags is set in
2240 * query scheduling flags.
2242 * Returns: TRUE when @mode is in the list of scheduling modes
2243 * and @flags are compatible with query flags.
2246 gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
2247 GstSchedulingFlags flags)
2249 GstSchedulingFlags sched_flags;
2251 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2253 gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
2255 return ((flags & sched_flags) == flags) &&
2256 gst_query_has_scheduling_mode (query, mode);
2260 * gst_query_new_accept_caps:
2261 * @caps: a fixed #GstCaps
2263 * Constructs a new query object for querying if @caps are accepted.
2265 * Free-function: gst_query_unref
2267 * Returns: (transfer full): a new #GstQuery
2270 gst_query_new_accept_caps (GstCaps * caps)
2273 GstStructure *structure;
2275 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2277 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2278 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2279 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2280 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2286 * gst_query_parse_accept_caps:
2287 * @query: The query to parse
2288 * @caps: (out) (transfer none): A pointer to the caps
2290 * Get the caps from @query. The caps remains valid as long as @query remains
2294 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2296 GstStructure *structure;
2298 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2299 g_return_if_fail (caps != NULL);
2301 structure = GST_QUERY_STRUCTURE (query);
2302 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2307 * gst_query_set_accept_caps_result:
2308 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2309 * @result: the result to set
2311 * Set @result as the result for the @query.
2314 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2316 GstStructure *structure;
2318 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2319 g_return_if_fail (gst_query_is_writable (query));
2321 structure = GST_QUERY_STRUCTURE (query);
2322 gst_structure_id_set (structure,
2323 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2327 * gst_query_parse_accept_caps_result:
2328 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2329 * @result: location for the result
2331 * Parse the result from @query and store in @result.
2334 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2336 GstStructure *structure;
2338 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2340 structure = GST_QUERY_STRUCTURE (query);
2341 gst_structure_id_get (structure,
2342 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2346 * gst_query_new_caps:
2349 * Constructs a new query object for querying the caps.
2351 * The CAPS query should return the allowable caps for a pad in the context
2352 * of the element's state, its link to other elements, and the devices or files
2353 * it has opened. These caps must be a subset of the pad template caps. In the
2354 * NULL state with no links, the CAPS query should ideally return the same caps
2355 * as the pad template. In rare circumstances, an object property can affect
2356 * the caps returned by the CAPS query, but this is discouraged.
2358 * For most filters, the caps returned by CAPS query is directly affected by the
2359 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2360 * the srcpad's getcaps function is directly related to the stream data. Again,
2361 * the CAPS query should return the most specific caps it reasonably can, since this
2362 * helps with autoplugging.
2364 * The @filter is used to restrict the result caps, only the caps matching
2365 * @filter should be returned from the CAPS query. Specifying a filter might
2366 * greatly reduce the amount of processing an element needs to do.
2368 * Free-function: gst_query_unref
2370 * Returns: (transfer full): a new #GstQuery
2373 gst_query_new_caps (GstCaps * filter)
2376 GstStructure *structure;
2378 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2379 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2380 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2381 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2387 * gst_query_parse_caps:
2388 * @query: The query to parse
2389 * @filter: (out) (transfer none): A pointer to the caps filter
2391 * Get the filter from the caps @query. The caps remains valid as long as
2392 * @query remains valid.
2395 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2397 GstStructure *structure;
2399 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2400 g_return_if_fail (filter != NULL);
2402 structure = GST_QUERY_STRUCTURE (query);
2403 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2404 GST_QUARK (FILTER)));
2408 * gst_query_set_caps_result:
2409 * @query: The query to use
2410 * @caps: (in): A pointer to the caps
2412 * Set the @caps result in @query.
2415 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2417 GstStructure *structure;
2419 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2420 g_return_if_fail (gst_query_is_writable (query));
2422 structure = GST_QUERY_STRUCTURE (query);
2423 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2427 * gst_query_parse_caps_result:
2428 * @query: The query to parse
2429 * @caps: (out) (transfer none): A pointer to the caps
2431 * Get the caps result from @query. The caps remains valid as long as
2432 * @query remains valid.
2435 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2437 GstStructure *structure;
2439 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2440 g_return_if_fail (caps != NULL);
2442 structure = GST_QUERY_STRUCTURE (query);
2443 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2449 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2450 GstCapsIntersectMode mode)
2452 GstCaps *res, *caps = NULL;
2454 gst_query_parse_caps_result (query, &caps);
2455 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2456 gst_query_set_caps_result (query, res);
2457 gst_caps_unref (res);
2462 * gst_query_new_drain:
2464 * Constructs a new query object for querying the drain state.
2466 * Free-function: gst_query_unref
2468 * Returns: (transfer full): a new #GstQuery
2471 gst_query_new_drain (void)
2474 GstStructure *structure;
2476 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2477 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2483 * gst_query_new_context:
2485 * Constructs a new query object for querying the pipeline-local context.
2487 * Free-function: gst_query_unref
2489 * Returns: (transfer full): a new #GstQuery
2494 gst_query_new_context (void)
2497 GstStructure *structure;
2499 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_CONTEXT));
2500 query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
2506 * gst_query_set_context:
2507 * @query: a #GstQuery with query type GST_QUERY_CONTEXT
2508 * @context: the requested #GstContext
2510 * Answer a context query by setting the requested context.
2515 gst_query_set_context (GstQuery * query, GstContext * context)
2519 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2521 s = GST_QUERY_STRUCTURE (query);
2523 gst_structure_id_set (s,
2524 GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2528 * gst_query_parse_context:
2529 * @query: The query to parse
2530 * @context: (out) (transfer none): A pointer to store the #GstContext
2532 * Get the context from the context @query. The context remains valid as long as
2533 * @query remains valid.
2538 gst_query_parse_context (GstQuery * query, GstContext ** context)
2540 GstStructure *structure;
2543 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2544 g_return_if_fail (context != NULL);
2546 structure = GST_QUERY_STRUCTURE (query);
2547 v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
2549 *context = g_value_get_boxed (v);
2555 free_array_string (gpointer ptr)
2557 gchar *str = *(gchar **) ptr;
2562 * gst_query_add_context_type:
2563 * @query: a GST_QUERY_CONTEXT type query
2564 * @context_type: a context type
2566 * Add a new context type to @query.
2571 gst_query_add_context_type (GstQuery * query, const gchar * context_type)
2573 GstStructure *structure;
2577 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2578 g_return_if_fail (gst_query_is_writable (query));
2580 structure = GST_QUERY_STRUCTURE (query);
2581 array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
2582 sizeof (gchar *), free_array_string);
2584 copy = g_strdup (context_type);
2585 g_array_append_val (array, copy);
2589 * gst_query_get_n_context_types:
2590 * @query: a GST_QUERY_CONTEXT type query
2592 * Retrieve the number of values currently stored in the
2593 * context-types array of the query's structure.
2595 * Returns: the context-types array size as a #guint.
2600 gst_query_get_n_context_types (GstQuery * query)
2602 GstStructure *structure;
2605 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, 0);
2607 structure = GST_QUERY_STRUCTURE (query);
2608 array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
2609 sizeof (gchar *), free_array_string);
2615 * gst_query_parse_nth_context_type:
2616 * @query: a GST_QUERY_CONTEXT type query
2617 * @context_type: (out) (transfer none) (allow-none): the context type, or NULL
2619 * Parse a context type from an existing GST_QUERY_CONTEXT query
2622 * Returns: a #gboolean indicating if the parsing succeeded.
2627 gst_query_parse_nth_context_type (GstQuery * query, guint index,
2628 const gchar ** context_type)
2630 GstStructure *structure;
2633 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2635 structure = GST_QUERY_STRUCTURE (query);
2637 array = ensure_array (structure, GST_QUARK (CONTEXT_TYPES),
2638 sizeof (gchar *), free_array_string);
2639 g_return_val_if_fail (index < array->len, FALSE);
2642 *context_type = g_array_index (array, gchar *, index);
2648 * gst_query_has_context_type:
2649 * @query: a GST_QUERY_CONTEXT type query
2650 * @context_type: the context type
2652 * Check if @query is asking for @context_type.
2654 * Returns: %TRUE if @context_type is requested.
2659 gst_query_has_context_type (GstQuery * query, const gchar * context_type)
2663 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2664 g_return_val_if_fail (context_type != NULL, FALSE);
2666 n = gst_query_get_n_context_types (query);
2667 for (i = 0; i < n; i++) {
2670 if (gst_query_parse_nth_context_type (query, i, &tmp) &&
2671 strcmp (tmp, context_type) == 0)