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:
42 * query = gst_query_new_duration (GST_FORMAT_TIME);
43 * res = gst_element_query (pipeline, query);
46 * gst_query_parse_duration (query, NULL, &duration);
47 * g_print ("duration = %"GST_TIME_FORMAT, GST_TIME_ARGS (duration));
49 * g_print ("duration query failed...");
51 * gst_query_unref (query);
56 #include "gst_private.h"
60 #include "gstenumtypes.h"
63 #include "gstbufferpool.h"
64 #ifdef TIZEN_PROFILE_TV
68 GST_DEBUG_CATEGORY_STATIC (gst_query_debug);
69 #define GST_CAT_DEFAULT gst_query_debug
71 GType _gst_query_type = 0;
77 GstStructure *structure;
80 #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure)
90 static GstQueryQuarks query_quarks[] = {
91 {GST_QUERY_UNKNOWN, "unknown", 0},
92 {GST_QUERY_POSITION, "position", 0},
93 {GST_QUERY_DURATION, "duration", 0},
94 {GST_QUERY_LATENCY, "latency", 0},
95 {GST_QUERY_JITTER, "jitter", 0},
96 {GST_QUERY_RATE, "rate", 0},
97 {GST_QUERY_SEEKING, "seeking", 0},
98 {GST_QUERY_SEGMENT, "segment", 0},
99 {GST_QUERY_CONVERT, "convert", 0},
100 {GST_QUERY_FORMATS, "formats", 0},
101 {GST_QUERY_BUFFERING, "buffering", 0},
102 {GST_QUERY_CUSTOM, "custom", 0},
103 {GST_QUERY_URI, "uri", 0},
104 {GST_QUERY_ALLOCATION, "allocation", 0},
105 {GST_QUERY_SCHEDULING, "scheduling", 0},
106 {GST_QUERY_ACCEPT_CAPS, "accept-caps", 0},
107 {GST_QUERY_CAPS, "caps", 0},
108 {GST_QUERY_DRAIN, "drain", 0},
109 {GST_QUERY_CONTEXT, "context", 0},
110 #ifdef TIZEN_PROFILE_TV
111 {GST_QUERY_RESOURCE, "resource", 0},
116 GST_DEFINE_MINI_OBJECT_TYPE (GstQuery, gst_query);
119 _priv_gst_query_initialize (void)
123 _gst_query_type = gst_query_get_type ();
125 GST_DEBUG_CATEGORY_INIT (gst_query_debug, "query", 0, "query system");
127 for (i = 0; query_quarks[i].name; i++) {
128 query_quarks[i].quark = g_quark_from_static_string (query_quarks[i].name);
133 * gst_query_type_get_name:
134 * @type: the query type
136 * Get a printable name for the given query type. Do not modify or free.
138 * Returns: a reference to the static name of the query.
141 gst_query_type_get_name (GstQueryType type)
145 for (i = 0; query_quarks[i].name; i++) {
146 if (type == query_quarks[i].type)
147 return query_quarks[i].name;
153 * gst_query_type_to_quark:
154 * @type: the query type
156 * Get the unique quark for the given query type.
158 * Returns: the quark associated with the query type
161 gst_query_type_to_quark (GstQueryType type)
165 for (i = 0; query_quarks[i].name; i++) {
166 if (type == query_quarks[i].type)
167 return query_quarks[i].quark;
173 * gst_query_type_get_flags:
174 * @type: a #GstQueryType
176 * Gets the #GstQueryTypeFlags associated with @type.
178 * Returns: a #GstQueryTypeFlags.
181 gst_query_type_get_flags (GstQueryType type)
183 GstQueryTypeFlags ret;
185 ret = type & ((1 << GST_QUERY_NUM_SHIFT) - 1);
191 _gst_query_free (GstQuery * query)
195 g_return_if_fail (query != NULL);
197 s = GST_QUERY_STRUCTURE (query);
199 gst_structure_set_parent_refcount (s, NULL);
200 gst_structure_free (s);
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, G_GUINT64_CONSTANT (-1), 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);
586 #ifdef TIZEN_PROFILE_TV
588 * gst_query_new_resource:
589 * @resources: pointer to store the resources
591 * Constructs a new query stream position query object. Use
593 * when done with it. A resource query is used to query the resources used
594 * by the element/bin/pipelein
596 * Free-function: gst_query_unref
598 * Returns: (transfer full): a new #GstQuery
601 gst_query_new_resource (gchar * resources)
604 GstStructure *structure;
606 structure = gst_structure_new_id (GST_QUARK (QUERY_RESOURCE),
607 GST_QUARK (QUERY_RESOURCE), G_TYPE_POINTER, resources, NULL);
609 query = gst_query_new_custom (GST_QUERY_RESOURCE, structure);
615 * gst_query_add_resource:
616 * @query: a #GstQuery
617 * @resource: resource data to add
620 gst_query_add_resource (GstQuery * query, gint resource_id)
622 gchar *resource_info;
623 resource_info = gst_query_parse_resource (query);
624 sprintf (resource_info, "%d", resource_id);
627 /* gst_query_parse_resources:
628 * @query: a #GstQuery
629 * @resources: (out) the storage for the resource
633 gst_query_parse_resource (GstQuery * query)
635 GstStructure *structure;
637 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_RESOURCE);
639 structure = GST_QUERY_STRUCTURE (query);
640 resources = g_value_get_pointer (gst_structure_id_get_value (structure,
641 GST_QUARK (QUERY_RESOURCE)));
647 * gst_query_set_segment:
648 * @query: a #GstQuery
649 * @rate: the rate of the segment
650 * @format: the #GstFormat of the segment values (@start_value and @stop_value)
651 * @start_value: the start value
652 * @stop_value: the stop value
654 * Answer a segment query by setting the requested values. The normal
655 * playback segment of a pipeline is 0 to duration at the default rate of
656 * 1.0. If a seek was performed on the pipeline to play a different
657 * segment, this query will return the range specified in the last seek.
659 * @start_value and @stop_value will respectively contain the configured
660 * playback range start and stop values expressed in @format.
661 * The values are always between 0 and the duration of the media and
662 * @start_value <= @stop_value. @rate will contain the playback rate. For
663 * negative rates, playback will actually happen from @stop_value to
667 gst_query_set_segment (GstQuery * query, gdouble rate, GstFormat format,
668 gint64 start_value, gint64 stop_value)
670 GstStructure *structure;
672 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
674 structure = GST_QUERY_STRUCTURE (query);
675 gst_structure_id_set (structure,
676 GST_QUARK (RATE), G_TYPE_DOUBLE, rate,
677 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
678 GST_QUARK (START_VALUE), G_TYPE_INT64, start_value,
679 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop_value, NULL);
683 * gst_query_parse_segment:
684 * @query: a #GstQuery
685 * @rate: (out) (allow-none): the storage for the rate of the segment, or %NULL
686 * @format: (out) (allow-none): the storage for the #GstFormat of the values,
688 * @start_value: (out) (allow-none): the storage for the start value, or %NULL
689 * @stop_value: (out) (allow-none): the storage for the stop value, or %NULL
691 * Parse a segment query answer. Any of @rate, @format, @start_value, and
692 * @stop_value may be %NULL, which will cause this value to be omitted.
694 * See gst_query_set_segment() for an explanation of the function arguments.
697 gst_query_parse_segment (GstQuery * query, gdouble * rate, GstFormat * format,
698 gint64 * start_value, gint64 * stop_value)
700 GstStructure *structure;
702 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEGMENT);
704 structure = GST_QUERY_STRUCTURE (query);
706 *rate = g_value_get_double (gst_structure_id_get_value (structure,
710 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
711 GST_QUARK (FORMAT)));
713 *start_value = g_value_get_int64 (gst_structure_id_get_value (structure,
714 GST_QUARK (START_VALUE)));
716 *stop_value = g_value_get_int64 (gst_structure_id_get_value (structure,
717 GST_QUARK (STOP_VALUE)));
721 * gst_query_new_custom:
722 * @type: the query type
723 * @structure: (allow-none) (transfer full): a structure for the query
725 * Constructs a new custom query object. Use gst_query_unref()
728 * Free-function: gst_query_unref
730 * Returns: (transfer full): a new #GstQuery
733 gst_query_new_custom (GstQueryType type, GstStructure * structure)
737 query = g_slice_new0 (GstQueryImpl);
739 GST_DEBUG ("creating new query %p %s", query, gst_query_type_get_name (type));
742 /* structure must not have a parent */
743 if (!gst_structure_set_parent_refcount (structure,
744 &query->query.mini_object.refcount))
748 gst_mini_object_init (GST_MINI_OBJECT_CAST (query), 0, _gst_query_type,
749 (GstMiniObjectCopyFunction) _gst_query_copy, NULL,
750 (GstMiniObjectFreeFunction) _gst_query_free);
752 GST_QUERY_TYPE (query) = type;
753 GST_QUERY_STRUCTURE (query) = structure;
755 return GST_QUERY_CAST (query);
760 g_slice_free1 (sizeof (GstQueryImpl), query);
761 g_warning ("structure is already owned by another object");
767 * gst_query_get_structure:
768 * @query: a #GstQuery
770 * Get the structure of a query.
772 * Returns: (transfer none): the #GstStructure of the query. The structure is
773 * still owned by the query and will therefore be freed when the query
777 gst_query_get_structure (GstQuery * query)
779 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
781 return GST_QUERY_STRUCTURE (query);
785 * gst_query_writable_structure:
786 * @query: a #GstQuery
788 * Get the structure of a query. This method should be called with a writable
789 * @query so that the returned structure is guaranteed to be writable.
791 * Returns: (transfer none): the #GstStructure of the query. The structure is
792 * still owned by the query and will therefore be freed when the query
796 gst_query_writable_structure (GstQuery * query)
798 g_return_val_if_fail (GST_IS_QUERY (query), NULL);
799 g_return_val_if_fail (gst_query_is_writable (query), NULL);
801 return GST_QUERY_STRUCTURE (query);
805 * gst_query_new_seeking:
806 * @format: the default #GstFormat for the new query
808 * Constructs a new query object for querying seeking properties of
811 * Free-function: gst_query_unref
813 * Returns: (transfer full): a new #GstQuery
816 gst_query_new_seeking (GstFormat format)
819 GstStructure *structure;
821 structure = gst_structure_new_id (GST_QUARK (QUERY_SEEKING),
822 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
823 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, FALSE,
824 GST_QUARK (SEGMENT_START), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
825 GST_QUARK (SEGMENT_END), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
827 query = gst_query_new_custom (GST_QUERY_SEEKING, structure);
833 * gst_query_set_seeking:
834 * @query: a #GstQuery
835 * @format: the format to set for the @segment_start and @segment_end values
836 * @seekable: the seekable flag to set
837 * @segment_start: the segment_start to set
838 * @segment_end: the segment_end to set
840 * Set the seeking query result fields in @query.
843 gst_query_set_seeking (GstQuery * query, GstFormat format,
844 gboolean seekable, gint64 segment_start, gint64 segment_end)
846 GstStructure *structure;
848 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
849 g_return_if_fail (gst_query_is_writable (query));
851 structure = GST_QUERY_STRUCTURE (query);
852 gst_structure_id_set (structure,
853 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
854 GST_QUARK (SEEKABLE), G_TYPE_BOOLEAN, seekable,
855 GST_QUARK (SEGMENT_START), G_TYPE_INT64, segment_start,
856 GST_QUARK (SEGMENT_END), G_TYPE_INT64, segment_end, NULL);
860 * gst_query_parse_seeking:
861 * @query: a GST_QUERY_SEEKING type query #GstQuery
862 * @format: (out) (allow-none): the format to set for the @segment_start
863 * and @segment_end values, or %NULL
864 * @seekable: (out) (allow-none): the seekable flag to set, or %NULL
865 * @segment_start: (out) (allow-none): the segment_start to set, or %NULL
866 * @segment_end: (out) (allow-none): the segment_end to set, or %NULL
868 * Parse a seeking query, writing the format into @format, and
869 * other results into the passed parameters, if the respective parameters
873 gst_query_parse_seeking (GstQuery * query, GstFormat * format,
874 gboolean * seekable, gint64 * segment_start, gint64 * segment_end)
876 GstStructure *structure;
878 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SEEKING);
880 structure = GST_QUERY_STRUCTURE (query);
883 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
884 GST_QUARK (FORMAT)));
886 *seekable = g_value_get_boolean (gst_structure_id_get_value (structure,
887 GST_QUARK (SEEKABLE)));
889 *segment_start = g_value_get_int64 (gst_structure_id_get_value (structure,
890 GST_QUARK (SEGMENT_START)));
892 *segment_end = g_value_get_int64 (gst_structure_id_get_value (structure,
893 GST_QUARK (SEGMENT_END)));
897 ensure_array (GstStructure * s, GQuark quark, gsize element_size,
898 GDestroyNotify clear_func)
903 value = gst_structure_id_get_value (s, quark);
905 array = (GArray *) g_value_get_boxed (value);
907 GValue new_array_val = { 0, };
909 array = g_array_new (FALSE, TRUE, element_size);
911 g_array_set_clear_func (array, clear_func);
913 g_value_init (&new_array_val, G_TYPE_ARRAY);
914 g_value_take_boxed (&new_array_val, array);
916 gst_structure_id_take_value (s, quark, &new_array_val);
922 * gst_query_new_formats:
924 * Constructs a new query object for querying formats of
927 * Free-function: gst_query_unref
929 * Returns: (transfer full): a new #GstQuery
932 gst_query_new_formats (void)
935 GstStructure *structure;
937 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_FORMATS));
938 query = gst_query_new_custom (GST_QUERY_FORMATS, structure);
944 gst_query_list_add_format (GValue * list, GstFormat format)
946 GValue item = { 0, };
948 g_value_init (&item, GST_TYPE_FORMAT);
949 g_value_set_enum (&item, format);
950 gst_value_list_append_value (list, &item);
951 g_value_unset (&item);
955 * gst_query_set_formats:
956 * @query: a #GstQuery
957 * @n_formats: the number of formats to set.
958 * @...: A number of @GstFormats equal to @n_formats.
960 * Set the formats query result fields in @query. The number of formats passed
961 * must be equal to @n_formats.
964 gst_query_set_formats (GstQuery * query, gint n_formats, ...)
967 GValue list = { 0, };
969 GstStructure *structure;
971 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
972 g_return_if_fail (gst_query_is_writable (query));
974 g_value_init (&list, GST_TYPE_LIST);
976 va_start (ap, n_formats);
977 for (i = 0; i < n_formats; i++) {
978 gst_query_list_add_format (&list, va_arg (ap, GstFormat));
982 structure = GST_QUERY_STRUCTURE (query);
983 gst_structure_set_value (structure, "formats", &list);
985 g_value_unset (&list);
990 * gst_query_set_formatsv:
991 * @query: a #GstQuery
992 * @n_formats: the number of formats to set.
993 * @formats: (in) (array length=n_formats): an array containing @n_formats
996 * Set the formats query result fields in @query. The number of formats passed
997 * in the @formats array must be equal to @n_formats.
1000 gst_query_set_formatsv (GstQuery * query, gint n_formats,
1001 const GstFormat * formats)
1003 GValue list = { 0, };
1005 GstStructure *structure;
1007 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1008 g_return_if_fail (gst_query_is_writable (query));
1010 g_value_init (&list, GST_TYPE_LIST);
1011 for (i = 0; i < n_formats; i++) {
1012 gst_query_list_add_format (&list, formats[i]);
1014 structure = GST_QUERY_STRUCTURE (query);
1015 gst_structure_set_value (structure, "formats", &list);
1017 g_value_unset (&list);
1021 * gst_query_parse_n_formats:
1022 * @query: a #GstQuery
1023 * @n_formats: (out) (allow-none): the number of formats in this query.
1025 * Parse the number of formats in the formats @query.
1028 gst_query_parse_n_formats (GstQuery * query, guint * n_formats)
1030 GstStructure *structure;
1032 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1037 structure = GST_QUERY_STRUCTURE (query);
1038 list = gst_structure_get_value (structure, "formats");
1042 *n_formats = gst_value_list_get_size (list);
1047 * gst_query_parse_nth_format:
1048 * @query: a #GstQuery
1049 * @nth: (out): the nth format to retrieve.
1050 * @format: (out) (allow-none): a pointer to store the nth format
1052 * Parse the format query and retrieve the @nth format from it into
1053 * @format. If the list contains less elements than @nth, @format will be
1054 * set to GST_FORMAT_UNDEFINED.
1057 gst_query_parse_nth_format (GstQuery * query, guint nth, GstFormat * format)
1059 GstStructure *structure;
1061 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_FORMATS);
1066 structure = GST_QUERY_STRUCTURE (query);
1067 list = gst_structure_get_value (structure, "formats");
1069 *format = GST_FORMAT_UNDEFINED;
1071 if (nth < gst_value_list_get_size (list)) {
1073 (GstFormat) g_value_get_enum (gst_value_list_get_value (list, nth));
1075 *format = GST_FORMAT_UNDEFINED;
1081 * gst_query_new_buffering:
1082 * @format: the default #GstFormat for the new query
1084 * Constructs a new query object for querying the buffering status of
1087 * Free-function: gst_query_unref
1089 * Returns: (transfer full): a new #GstQuery
1092 gst_query_new_buffering (GstFormat format)
1095 GstStructure *structure;
1097 /* by default, we configure the answer as no buffering with a 100% buffering
1099 structure = gst_structure_new_id (GST_QUARK (QUERY_BUFFERING),
1100 GST_QUARK (BUSY), G_TYPE_BOOLEAN, FALSE,
1101 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, 100,
1102 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, GST_BUFFERING_STREAM,
1103 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, -1,
1104 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, -1,
1105 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, G_GINT64_CONSTANT (0),
1106 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1107 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1108 GST_QUARK (START_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1),
1109 GST_QUARK (STOP_VALUE), G_TYPE_INT64, G_GINT64_CONSTANT (-1), NULL);
1111 query = gst_query_new_custom (GST_QUERY_BUFFERING, structure);
1117 * gst_query_set_buffering_percent:
1118 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1119 * @busy: if buffering is busy
1120 * @percent: a buffering percent
1122 * Set the percentage of buffered data. This is a value between 0 and 100.
1123 * The @busy indicator is %TRUE when the buffering is in progress.
1126 gst_query_set_buffering_percent (GstQuery * query, gboolean busy, gint percent)
1128 GstStructure *structure;
1130 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1131 g_return_if_fail (gst_query_is_writable (query));
1132 g_return_if_fail (percent >= 0 && percent <= 100);
1134 structure = GST_QUERY_STRUCTURE (query);
1135 gst_structure_id_set (structure,
1136 GST_QUARK (BUSY), G_TYPE_BOOLEAN, busy,
1137 GST_QUARK (BUFFER_PERCENT), G_TYPE_INT, percent, NULL);
1141 * gst_query_parse_buffering_percent:
1142 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1143 * @busy: (out) (allow-none): if buffering is busy, or %NULL
1144 * @percent: (out) (allow-none): a buffering percent, or %NULL
1146 * Get the percentage of buffered data. This is a value between 0 and 100.
1147 * The @busy indicator is %TRUE when the buffering is in progress.
1150 gst_query_parse_buffering_percent (GstQuery * query, gboolean * busy,
1153 GstStructure *structure;
1155 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1157 structure = GST_QUERY_STRUCTURE (query);
1159 *busy = g_value_get_boolean (gst_structure_id_get_value (structure,
1162 *percent = g_value_get_int (gst_structure_id_get_value (structure,
1163 GST_QUARK (BUFFER_PERCENT)));
1167 * gst_query_set_buffering_stats:
1168 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1169 * @mode: a buffering mode
1170 * @avg_in: the average input rate
1171 * @avg_out: the average output rate
1172 * @buffering_left: amount of buffering time left in milliseconds
1174 * Configures the buffering stats values in @query.
1177 gst_query_set_buffering_stats (GstQuery * query, GstBufferingMode mode,
1178 gint avg_in, gint avg_out, gint64 buffering_left)
1180 GstStructure *structure;
1182 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1183 g_return_if_fail (gst_query_is_writable (query));
1185 structure = GST_QUERY_STRUCTURE (query);
1186 gst_structure_id_set (structure,
1187 GST_QUARK (BUFFERING_MODE), GST_TYPE_BUFFERING_MODE, mode,
1188 GST_QUARK (AVG_IN_RATE), G_TYPE_INT, avg_in,
1189 GST_QUARK (AVG_OUT_RATE), G_TYPE_INT, avg_out,
1190 GST_QUARK (BUFFERING_LEFT), G_TYPE_INT64, buffering_left, NULL);
1194 * gst_query_parse_buffering_stats:
1195 * @query: A valid #GstQuery of type GST_QUERY_BUFFERING.
1196 * @mode: (out) (allow-none): a buffering mode, or %NULL
1197 * @avg_in: (out) (allow-none): the average input rate, or %NULL
1198 * @avg_out: (out) (allow-none): the average output rat, or %NULL
1199 * @buffering_left: (out) (allow-none): amount of buffering time left in
1200 * milliseconds, or %NULL
1202 * Extracts the buffering stats values from @query.
1205 gst_query_parse_buffering_stats (GstQuery * query,
1206 GstBufferingMode * mode, gint * avg_in, gint * avg_out,
1207 gint64 * buffering_left)
1209 GstStructure *structure;
1211 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1213 structure = GST_QUERY_STRUCTURE (query);
1215 *mode = (GstBufferingMode)
1216 g_value_get_enum (gst_structure_id_get_value (structure,
1217 GST_QUARK (BUFFERING_MODE)));
1219 *avg_in = g_value_get_int (gst_structure_id_get_value (structure,
1220 GST_QUARK (AVG_IN_RATE)));
1222 *avg_out = g_value_get_int (gst_structure_id_get_value (structure,
1223 GST_QUARK (AVG_OUT_RATE)));
1226 g_value_get_int64 (gst_structure_id_get_value (structure,
1227 GST_QUARK (BUFFERING_LEFT)));
1231 * gst_query_set_buffering_range:
1232 * @query: a #GstQuery
1233 * @format: the format to set for the @start and @stop values
1234 * @start: the start to set
1235 * @stop: the stop to set
1236 * @estimated_total: estimated total amount of download time remaining in
1239 * Set the available query result fields in @query.
1242 gst_query_set_buffering_range (GstQuery * query, GstFormat format,
1243 gint64 start, gint64 stop, gint64 estimated_total)
1245 GstStructure *structure;
1247 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1248 g_return_if_fail (gst_query_is_writable (query));
1250 structure = GST_QUERY_STRUCTURE (query);
1251 gst_structure_id_set (structure,
1252 GST_QUARK (FORMAT), GST_TYPE_FORMAT, format,
1253 GST_QUARK (START_VALUE), G_TYPE_INT64, start,
1254 GST_QUARK (STOP_VALUE), G_TYPE_INT64, stop,
1255 GST_QUARK (ESTIMATED_TOTAL), G_TYPE_INT64, estimated_total, NULL);
1259 * gst_query_parse_buffering_range:
1260 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1261 * @format: (out) (allow-none): the format to set for the @segment_start
1262 * and @segment_end values, or %NULL
1263 * @start: (out) (allow-none): the start to set, or %NULL
1264 * @stop: (out) (allow-none): the stop to set, or %NULL
1265 * @estimated_total: (out) (allow-none): estimated total amount of download
1266 * time remaining in milliseconds, or %NULL
1268 * Parse an available query, writing the format into @format, and
1269 * other results into the passed parameters, if the respective parameters
1273 gst_query_parse_buffering_range (GstQuery * query, GstFormat * format,
1274 gint64 * start, gint64 * stop, gint64 * estimated_total)
1276 GstStructure *structure;
1278 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING);
1280 structure = GST_QUERY_STRUCTURE (query);
1283 (GstFormat) g_value_get_enum (gst_structure_id_get_value (structure,
1284 GST_QUARK (FORMAT)));
1286 *start = g_value_get_int64 (gst_structure_id_get_value (structure,
1287 GST_QUARK (START_VALUE)));
1289 *stop = g_value_get_int64 (gst_structure_id_get_value (structure,
1290 GST_QUARK (STOP_VALUE)));
1291 if (estimated_total)
1293 g_value_get_int64 (gst_structure_id_get_value (structure,
1294 GST_QUARK (ESTIMATED_TOTAL)));
1297 /* GstQueryBufferingRange: internal struct for GArray */
1302 } GstQueryBufferingRange;
1305 * gst_query_add_buffering_range:
1306 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1307 * @start: start position of the range
1308 * @stop: stop position of the range
1310 * Set the buffering-ranges array field in @query. The current last
1311 * start position of the array should be inferior to @start.
1313 * Returns: a #gboolean indicating if the range was added or not.
1316 gst_query_add_buffering_range (GstQuery * query, gint64 start, gint64 stop)
1318 GstQueryBufferingRange range;
1319 GstStructure *structure;
1322 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1323 g_return_val_if_fail (gst_query_is_writable (query), FALSE);
1325 if (G_UNLIKELY (start >= stop))
1328 structure = GST_QUERY_STRUCTURE (query);
1329 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1330 sizeof (GstQueryBufferingRange), NULL);
1332 if (array->len > 1) {
1333 GstQueryBufferingRange *last;
1335 last = &g_array_index (array, GstQueryBufferingRange, array->len - 1);
1337 if (G_UNLIKELY (start <= last->start))
1341 range.start = start;
1343 g_array_append_val (array, range);
1349 * gst_query_get_n_buffering_ranges:
1350 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1352 * Retrieve the number of values currently stored in the
1353 * buffered-ranges array of the query's structure.
1355 * Returns: the range array size as a #guint.
1358 gst_query_get_n_buffering_ranges (GstQuery * query)
1360 GstStructure *structure;
1363 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, 0);
1365 structure = GST_QUERY_STRUCTURE (query);
1366 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1367 sizeof (GstQueryBufferingRange), NULL);
1374 * gst_query_parse_nth_buffering_range:
1375 * @query: a GST_QUERY_BUFFERING type query #GstQuery
1376 * @index: position in the buffered-ranges array to read
1377 * @start: (out) (allow-none): the start position to set, or %NULL
1378 * @stop: (out) (allow-none): the stop position to set, or %NULL
1380 * Parse an available query and get the start and stop values stored
1381 * at the @index of the buffered ranges array.
1383 * Returns: a #gboolean indicating if the parsing succeeded.
1386 gst_query_parse_nth_buffering_range (GstQuery * query, guint index,
1387 gint64 * start, gint64 * stop)
1389 GstQueryBufferingRange *range;
1390 GstStructure *structure;
1393 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_BUFFERING, FALSE);
1395 structure = GST_QUERY_STRUCTURE (query);
1397 array = ensure_array (structure, GST_QUARK (BUFFERING_RANGES),
1398 sizeof (GstQueryBufferingRange), NULL);
1399 g_return_val_if_fail (index < array->len, FALSE);
1401 range = &g_array_index (array, GstQueryBufferingRange, index);
1404 *start = range->start;
1406 *stop = range->stop;
1413 * gst_query_new_uri:
1415 * Constructs a new query URI query object. Use gst_query_unref()
1416 * when done with it. An URI query is used to query the current URI
1417 * that is used by the source or sink.
1419 * Free-function: gst_query_unref
1421 * Returns: (transfer full): a new #GstQuery
1424 gst_query_new_uri (void)
1427 GstStructure *structure;
1429 structure = gst_structure_new_id (GST_QUARK (QUERY_URI),
1430 GST_QUARK (URI), G_TYPE_STRING, NULL, NULL);
1432 query = gst_query_new_custom (GST_QUERY_URI, structure);
1438 * gst_query_set_uri:
1439 * @query: a #GstQuery with query type GST_QUERY_URI
1440 * @uri: the URI to set
1442 * Answer a URI query by setting the requested URI.
1445 gst_query_set_uri (GstQuery * query, const gchar * uri)
1447 GstStructure *structure;
1449 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1450 g_return_if_fail (gst_query_is_writable (query));
1451 g_return_if_fail (gst_uri_is_valid (uri));
1453 structure = GST_QUERY_STRUCTURE (query);
1454 gst_structure_id_set (structure, GST_QUARK (URI), G_TYPE_STRING, uri, NULL);
1458 * gst_query_parse_uri:
1459 * @query: a #GstQuery
1460 * @uri: (out) (transfer full) (allow-none): the storage for the current URI
1463 * Parse an URI query, writing the URI into @uri as a newly
1464 * allocated string, if the respective parameters are non-%NULL.
1465 * Free the string with g_free() after usage.
1468 gst_query_parse_uri (GstQuery * query, gchar ** uri)
1470 GstStructure *structure;
1472 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1474 structure = GST_QUERY_STRUCTURE (query);
1476 *uri = g_value_dup_string (gst_structure_id_get_value (structure,
1481 * gst_query_set_uri_redirection:
1482 * @query: a #GstQuery with query type GST_QUERY_URI
1483 * @uri: the URI to set
1485 * Answer a URI query by setting the requested URI redirection.
1490 gst_query_set_uri_redirection (GstQuery * query, const gchar * uri)
1492 GstStructure *structure;
1494 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1495 g_return_if_fail (gst_query_is_writable (query));
1496 g_return_if_fail (gst_uri_is_valid (uri));
1498 structure = GST_QUERY_STRUCTURE (query);
1499 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION),
1500 G_TYPE_STRING, uri, NULL);
1504 * gst_query_parse_uri_redirection:
1505 * @query: a #GstQuery
1506 * @uri: (out) (transfer full) (allow-none): the storage for the redirect URI
1509 * Parse an URI query, writing the URI into @uri as a newly
1510 * allocated string, if the respective parameters are non-%NULL.
1511 * Free the string with g_free() after usage.
1516 gst_query_parse_uri_redirection (GstQuery * query, gchar ** uri)
1518 GstStructure *structure;
1520 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1522 structure = GST_QUERY_STRUCTURE (query);
1524 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION),
1525 G_TYPE_STRING, uri, NULL))
1531 * gst_query_set_uri_redirection_permanent:
1532 * @query: a #GstQuery with query type %GST_QUERY_URI
1533 * @permanent: whether the redirect is permanent or not
1535 * Answer a URI query by setting the requested URI redirection
1536 * to permanent or not.
1541 gst_query_set_uri_redirection_permanent (GstQuery * query, gboolean permanent)
1543 GstStructure *structure;
1545 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1546 g_return_if_fail (gst_query_is_writable (query));
1548 structure = GST_QUERY_STRUCTURE (query);
1549 gst_structure_id_set (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1550 G_TYPE_BOOLEAN, permanent, NULL);
1554 * gst_query_parse_uri_redirection_permanent:
1555 * @query: a #GstQuery
1556 * @permanent: (out) (allow-none): if the URI redirection is permanent
1559 * Parse an URI query, and set @permanent to %TRUE if there is a redirection
1560 * and it should be considered permanent. If a redirection is permanent,
1561 * applications should update their internal storage of the URI, otherwise
1562 * they should make all future requests to the original URI.
1567 gst_query_parse_uri_redirection_permanent (GstQuery * query,
1568 gboolean * permanent)
1570 GstStructure *structure;
1572 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_URI);
1574 structure = GST_QUERY_STRUCTURE (query);
1576 if (!gst_structure_id_get (structure, GST_QUARK (URI_REDIRECTION_PERMANENT),
1577 G_TYPE_BOOLEAN, permanent, NULL))
1583 * gst_query_new_allocation:
1584 * @caps: the negotiated caps
1585 * @need_pool: return a pool
1587 * Constructs a new query object for querying the allocation properties.
1589 * Free-function: gst_query_unref
1591 * Returns: (transfer full): a new #GstQuery
1594 gst_query_new_allocation (GstCaps * caps, gboolean need_pool)
1597 GstStructure *structure;
1599 structure = gst_structure_new_id (GST_QUARK (QUERY_ALLOCATION),
1600 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
1601 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1603 query = gst_query_new_custom (GST_QUERY_ALLOCATION, structure);
1609 * gst_query_parse_allocation:
1610 * @query: a #GstQuery
1611 * @caps: (out) (transfer none) (allow-none): The #GstCaps
1612 * @need_pool: (out) (allow-none): Whether a #GstBufferPool is needed
1614 * Parse an allocation query, writing the requested caps in @caps and
1615 * whether a pool is needed in @need_pool, if the respective parameters
1619 gst_query_parse_allocation (GstQuery * query, GstCaps ** caps,
1620 gboolean * need_pool)
1622 GstStructure *structure;
1624 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1626 structure = GST_QUERY_STRUCTURE (query);
1628 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
1631 gst_structure_id_get (structure,
1632 GST_QUARK (NEED_POOL), G_TYPE_BOOLEAN, need_pool, NULL);
1637 GstBufferPool *pool;
1644 allocation_pool_free (AllocationPool * ap)
1647 gst_object_unref (ap->pool);
1651 * gst_query_add_allocation_pool:
1652 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1653 * @pool: (transfer none) (allow-none): the #GstBufferPool
1655 * @min_buffers: the min buffers
1656 * @max_buffers: the max buffers
1658 * Set the pool parameters in @query.
1661 gst_query_add_allocation_pool (GstQuery * query, GstBufferPool * pool,
1662 guint size, guint min_buffers, guint max_buffers)
1665 GstStructure *structure;
1668 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1669 g_return_if_fail (gst_query_is_writable (query));
1671 structure = GST_QUERY_STRUCTURE (query);
1672 array = ensure_array (structure, GST_QUARK (POOL),
1673 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1675 if ((ap.pool = pool))
1676 gst_object_ref (pool);
1678 ap.min_buffers = min_buffers;
1679 ap.max_buffers = max_buffers;
1681 g_array_append_val (array, ap);
1686 * gst_query_get_n_allocation_pools:
1687 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1689 * Retrieve the number of values currently stored in the
1690 * pool array of the query's structure.
1692 * Returns: the pool array size as a #guint.
1695 gst_query_get_n_allocation_pools (GstQuery * query)
1698 GstStructure *structure;
1700 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1702 structure = GST_QUERY_STRUCTURE (query);
1703 array = ensure_array (structure, GST_QUARK (POOL),
1704 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1710 * gst_query_parse_nth_allocation_pool:
1711 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1712 * @index: index to parse
1713 * @pool: (out) (allow-none) (transfer full): the #GstBufferPool
1714 * @size: (out) (allow-none): the size
1715 * @min_buffers: (out) (allow-none): the min buffers
1716 * @max_buffers: (out) (allow-none): the max buffers
1718 * Get the pool parameters in @query.
1720 * Unref @pool with gst_object_unref() when it's not needed any more.
1723 gst_query_parse_nth_allocation_pool (GstQuery * query, guint index,
1724 GstBufferPool ** pool, guint * size, guint * min_buffers,
1725 guint * max_buffers)
1728 GstStructure *structure;
1731 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1733 structure = GST_QUERY_STRUCTURE (query);
1734 array = ensure_array (structure, GST_QUARK (POOL),
1735 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1736 g_return_if_fail (index < array->len);
1738 ap = &g_array_index (array, AllocationPool, index);
1741 if ((*pool = ap->pool))
1742 gst_object_ref (*pool);
1746 *min_buffers = ap->min_buffers;
1748 *max_buffers = ap->max_buffers;
1752 * gst_query_set_nth_allocation_pool:
1753 * @index: index to modify
1754 * @query: A valid #GstQuery of type GST_QUERY_ALLOCATION.
1755 * @pool: (transfer none) (allow-none): the #GstBufferPool
1757 * @min_buffers: the min buffers
1758 * @max_buffers: the max buffers
1760 * Set the pool parameters in @query.
1763 gst_query_set_nth_allocation_pool (GstQuery * query, guint index,
1764 GstBufferPool * pool, guint size, guint min_buffers, guint max_buffers)
1767 GstStructure *structure;
1768 AllocationPool *oldap, ap;
1770 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1772 structure = GST_QUERY_STRUCTURE (query);
1773 array = ensure_array (structure, GST_QUARK (POOL),
1774 sizeof (AllocationPool), (GDestroyNotify) allocation_pool_free);
1775 g_return_if_fail (index < array->len);
1777 oldap = &g_array_index (array, AllocationPool, index);
1778 allocation_pool_free (oldap);
1780 if ((ap.pool = pool))
1781 gst_object_ref (pool);
1783 ap.min_buffers = min_buffers;
1784 ap.max_buffers = max_buffers;
1785 g_array_index (array, AllocationPool, index) = ap;
1789 * gst_query_remove_nth_allocation_pool:
1790 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1791 * @index: position in the allocation pool array to remove
1793 * Remove the allocation pool at @index of the allocation pool array.
1798 gst_query_remove_nth_allocation_pool (GstQuery * query, guint index)
1801 GstStructure *structure;
1803 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1804 g_return_if_fail (gst_query_is_writable (query));
1806 structure = GST_QUERY_STRUCTURE (query);
1808 ensure_array (structure, GST_QUARK (POOL), sizeof (AllocationPool),
1809 (GDestroyNotify) allocation_pool_free);
1810 g_return_if_fail (index < array->len);
1812 g_array_remove_index (array, index);
1818 GstStructure *params;
1822 allocation_meta_free (AllocationMeta * am)
1825 gst_structure_free (am->params);
1829 * gst_query_add_allocation_meta:
1830 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1831 * @api: the metadata API
1832 * @params: (transfer none) (allow-none): API specific parameters
1834 * Add @api with @params as one of the supported metadata API to @query.
1837 gst_query_add_allocation_meta (GstQuery * query, GType api,
1838 const GstStructure * params)
1841 GstStructure *structure;
1844 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1845 g_return_if_fail (api != 0);
1846 g_return_if_fail (gst_query_is_writable (query));
1848 structure = GST_QUERY_STRUCTURE (query);
1850 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1851 (GDestroyNotify) allocation_meta_free);
1854 am.params = (params ? gst_structure_copy (params) : NULL);
1856 g_array_append_val (array, am);
1860 * gst_query_get_n_allocation_metas:
1861 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1863 * Retrieve the number of values currently stored in the
1864 * meta API array of the query's structure.
1866 * Returns: the metadata API array size as a #guint.
1869 gst_query_get_n_allocation_metas (GstQuery * query)
1872 GstStructure *structure;
1874 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1876 structure = GST_QUERY_STRUCTURE (query);
1878 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1879 (GDestroyNotify) allocation_meta_free);
1885 * gst_query_parse_nth_allocation_meta:
1886 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1887 * @index: position in the metadata API array to read
1888 * @params: (out) (transfer none) (allow-none): API specific flags
1890 * Parse an available query and get the metadata API
1891 * at @index of the metadata API array.
1893 * Returns: a #GType of the metadata API at @index.
1896 gst_query_parse_nth_allocation_meta (GstQuery * query, guint index,
1897 const GstStructure ** params)
1900 GstStructure *structure;
1903 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
1905 structure = GST_QUERY_STRUCTURE (query);
1907 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1908 (GDestroyNotify) allocation_meta_free);
1910 g_return_val_if_fail (index < array->len, 0);
1912 am = &g_array_index (array, AllocationMeta, index);
1915 *params = am->params;
1921 * gst_query_remove_nth_allocation_meta:
1922 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1923 * @index: position in the metadata API array to remove
1925 * Remove the metadata API at @index of the metadata API array.
1928 gst_query_remove_nth_allocation_meta (GstQuery * query, guint index)
1931 GstStructure *structure;
1933 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
1934 g_return_if_fail (gst_query_is_writable (query));
1936 structure = GST_QUERY_STRUCTURE (query);
1938 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1939 (GDestroyNotify) allocation_meta_free);
1940 g_return_if_fail (index < array->len);
1942 g_array_remove_index (array, index);
1946 * gst_query_find_allocation_meta:
1947 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
1948 * @api: the metadata API
1949 * @index: (out) (transfer none) (allow-none): the index
1951 * Check if @query has metadata @api set. When this function returns %TRUE,
1952 * @index will contain the index where the requested API and the flags can be
1955 * Returns: %TRUE when @api is in the list of metadata.
1958 gst_query_find_allocation_meta (GstQuery * query, GType api, guint * index)
1961 GstStructure *structure;
1964 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, FALSE);
1965 g_return_val_if_fail (api != 0, FALSE);
1967 structure = GST_QUERY_STRUCTURE (query);
1969 ensure_array (structure, GST_QUARK (META), sizeof (AllocationMeta),
1970 (GDestroyNotify) allocation_meta_free);
1973 for (i = 0; i < len; i++) {
1974 AllocationMeta *am = &g_array_index (array, AllocationMeta, i);
1975 if (am->api == api) {
1986 GstAllocator *allocator;
1987 GstAllocationParams params;
1991 allocation_param_free (AllocationParam * ap)
1994 gst_object_unref (ap->allocator);
1998 * gst_query_add_allocation_param:
1999 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2000 * @allocator: (transfer none) (allow-none): the memory allocator
2001 * @params: (transfer none) (allow-none): a #GstAllocationParams
2003 * Add @allocator and its @params as a supported memory allocator.
2006 gst_query_add_allocation_param (GstQuery * query, GstAllocator * allocator,
2007 const GstAllocationParams * params)
2010 GstStructure *structure;
2013 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2014 g_return_if_fail (gst_query_is_writable (query));
2015 g_return_if_fail (allocator != NULL || params != NULL);
2017 structure = GST_QUERY_STRUCTURE (query);
2018 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2019 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2021 if ((ap.allocator = allocator))
2022 gst_object_ref (allocator);
2024 ap.params = *params;
2026 gst_allocation_params_init (&ap.params);
2028 g_array_append_val (array, ap);
2032 * gst_query_get_n_allocation_params:
2033 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2035 * Retrieve the number of values currently stored in the
2036 * allocator params array of the query's structure.
2038 * If no memory allocator is specified, the downstream element can handle
2039 * the default memory allocator. The first memory allocator in the query
2040 * should be generic and allow mapping to system memory, all following
2041 * allocators should be ordered by preference with the preferred one first.
2043 * Returns: the allocator array size as a #guint.
2046 gst_query_get_n_allocation_params (GstQuery * query)
2049 GstStructure *structure;
2051 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION, 0);
2053 structure = GST_QUERY_STRUCTURE (query);
2054 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2055 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2061 * gst_query_parse_nth_allocation_param:
2062 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2063 * @index: position in the allocator array to read
2064 * @allocator: (out) (transfer full) (allow-none): variable to hold the result
2065 * @params: (out) (allow-none): parameters for the allocator
2067 * Parse an available query and get the allocator and its params
2068 * at @index of the allocator array.
2071 gst_query_parse_nth_allocation_param (GstQuery * query, guint index,
2072 GstAllocator ** allocator, GstAllocationParams * params)
2075 GstStructure *structure;
2076 AllocationParam *ap;
2078 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2080 structure = GST_QUERY_STRUCTURE (query);
2081 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2082 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2083 g_return_if_fail (index < array->len);
2085 ap = &g_array_index (array, AllocationParam, index);
2088 if ((*allocator = ap->allocator))
2089 gst_object_ref (*allocator);
2091 *params = ap->params;
2095 * gst_query_set_nth_allocation_param:
2096 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2097 * @index: position in the allocator array to set
2098 * @allocator: (transfer none) (allow-none): new allocator to set
2099 * @params: (transfer none) (allow-none): parameters for the allocator
2101 * Parse an available query and get the allocator and its params
2102 * at @index of the allocator array.
2105 gst_query_set_nth_allocation_param (GstQuery * query, guint index,
2106 GstAllocator * allocator, const GstAllocationParams * params)
2109 GstStructure *structure;
2110 AllocationParam *old, ap;
2112 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2114 structure = GST_QUERY_STRUCTURE (query);
2115 array = ensure_array (structure, GST_QUARK (ALLOCATOR),
2116 sizeof (AllocationParam), (GDestroyNotify) allocation_param_free);
2117 g_return_if_fail (index < array->len);
2119 old = &g_array_index (array, AllocationParam, index);
2120 allocation_param_free (old);
2122 if ((ap.allocator = allocator))
2123 gst_object_ref (allocator);
2125 ap.params = *params;
2127 gst_allocation_params_init (&ap.params);
2129 g_array_index (array, AllocationParam, index) = ap;
2133 * gst_query_remove_nth_allocation_param:
2134 * @query: a GST_QUERY_ALLOCATION type query #GstQuery
2135 * @index: position in the allocation param array to remove
2137 * Remove the allocation param at @index of the allocation param array.
2142 gst_query_remove_nth_allocation_param (GstQuery * query, guint index)
2145 GstStructure *structure;
2147 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ALLOCATION);
2148 g_return_if_fail (gst_query_is_writable (query));
2150 structure = GST_QUERY_STRUCTURE (query);
2152 ensure_array (structure, GST_QUARK (ALLOCATOR), sizeof (AllocationParam),
2153 (GDestroyNotify) allocation_param_free);
2154 g_return_if_fail (index < array->len);
2156 g_array_remove_index (array, index);
2160 * gst_query_new_scheduling:
2162 * Constructs a new query object for querying the scheduling properties.
2164 * Free-function: gst_query_unref
2166 * Returns: (transfer full): a new #GstQuery
2169 gst_query_new_scheduling (void)
2172 GstStructure *structure;
2174 structure = gst_structure_new_id (GST_QUARK (QUERY_SCHEDULING),
2175 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, 0,
2176 GST_QUARK (MINSIZE), G_TYPE_INT, 1,
2177 GST_QUARK (MAXSIZE), G_TYPE_INT, -1,
2178 GST_QUARK (ALIGN), G_TYPE_INT, 0, NULL);
2179 query = gst_query_new_custom (GST_QUERY_SCHEDULING, structure);
2185 * gst_query_set_scheduling:
2186 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2187 * @flags: #GstSchedulingFlags
2188 * @minsize: the suggested minimum size of pull requests
2189 * @maxsize: the suggested maximum size of pull requests
2190 * @align: the suggested alignment of pull requests
2192 * Set the scheduling properties.
2195 gst_query_set_scheduling (GstQuery * query, GstSchedulingFlags flags,
2196 gint minsize, gint maxsize, gint align)
2198 GstStructure *structure;
2200 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2201 g_return_if_fail (gst_query_is_writable (query));
2203 structure = GST_QUERY_STRUCTURE (query);
2204 gst_structure_id_set (structure,
2205 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2206 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2207 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2208 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2212 * gst_query_parse_scheduling:
2213 * @query: A valid #GstQuery of type GST_QUERY_SCHEDULING.
2214 * @flags: (out) (allow-none): #GstSchedulingFlags
2215 * @minsize: (out) (allow-none): the suggested minimum size of pull requests
2216 * @maxsize: (out) (allow-none): the suggested maximum size of pull requests:
2217 * @align: (out) (allow-none): the suggested alignment of pull requests
2219 * Set the scheduling properties.
2222 gst_query_parse_scheduling (GstQuery * query, GstSchedulingFlags * flags,
2223 gint * minsize, gint * maxsize, gint * align)
2225 GstStructure *structure;
2227 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2229 structure = GST_QUERY_STRUCTURE (query);
2230 gst_structure_id_get (structure,
2231 GST_QUARK (FLAGS), GST_TYPE_SCHEDULING_FLAGS, flags,
2232 GST_QUARK (MINSIZE), G_TYPE_INT, minsize,
2233 GST_QUARK (MAXSIZE), G_TYPE_INT, maxsize,
2234 GST_QUARK (ALIGN), G_TYPE_INT, align, NULL);
2238 * gst_query_add_scheduling_mode:
2239 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2240 * @mode: a #GstPadMode
2242 * Add @mode as one of the supported scheduling modes to @query.
2245 gst_query_add_scheduling_mode (GstQuery * query, GstPadMode mode)
2247 GstStructure *structure;
2250 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING);
2251 g_return_if_fail (gst_query_is_writable (query));
2253 structure = GST_QUERY_STRUCTURE (query);
2255 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2257 g_array_append_val (array, mode);
2261 * gst_query_get_n_scheduling_modes:
2262 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2264 * Retrieve the number of values currently stored in the
2265 * scheduling mode array of the query's structure.
2267 * Returns: the scheduling mode array size as a #guint.
2270 gst_query_get_n_scheduling_modes (GstQuery * query)
2273 GstStructure *structure;
2275 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, 0);
2277 structure = GST_QUERY_STRUCTURE (query);
2279 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2285 * gst_query_parse_nth_scheduling_mode:
2286 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2287 * @index: position in the scheduling modes array to read
2289 * Parse an available query and get the scheduling mode
2290 * at @index of the scheduling modes array.
2292 * Returns: a #GstPadMode of the scheduling mode at @index.
2295 gst_query_parse_nth_scheduling_mode (GstQuery * query, guint index)
2297 GstStructure *structure;
2300 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING,
2303 structure = GST_QUERY_STRUCTURE (query);
2305 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2306 g_return_val_if_fail (index < array->len, GST_PAD_MODE_NONE);
2308 return g_array_index (array, GstPadMode, index);
2312 * gst_query_has_scheduling_mode:
2313 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2314 * @mode: the scheduling mode
2316 * Check if @query has scheduling mode set.
2320 * When checking if upstream supports pull mode, it is usually not
2321 * enough to just check for GST_PAD_MODE_PULL with this function, you
2322 * also want to check whether the scheduling flags returned by
2323 * gst_query_parse_scheduling() have the seeking flag set (meaning
2324 * random access is supported, not only sequential pulls).
2328 * Returns: %TRUE when @mode is in the list of scheduling modes.
2331 gst_query_has_scheduling_mode (GstQuery * query, GstPadMode mode)
2333 GstStructure *structure;
2337 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2339 structure = GST_QUERY_STRUCTURE (query);
2341 ensure_array (structure, GST_QUARK (MODES), sizeof (GstPadMode), NULL);
2344 for (i = 0; i < len; i++) {
2345 if (mode == g_array_index (array, GstPadMode, i))
2352 * gst_query_has_scheduling_mode_with_flags:
2353 * @query: a GST_QUERY_SCHEDULING type query #GstQuery
2354 * @mode: the scheduling mode
2355 * @flags: #GstSchedulingFlags
2357 * Check if @query has scheduling mode set and @flags is set in
2358 * query scheduling flags.
2360 * Returns: %TRUE when @mode is in the list of scheduling modes
2361 * and @flags are compatible with query flags.
2364 gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
2365 GstSchedulingFlags flags)
2367 GstSchedulingFlags sched_flags;
2369 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_SCHEDULING, FALSE);
2371 gst_query_parse_scheduling (query, &sched_flags, NULL, NULL, NULL);
2373 return ((flags & sched_flags) == flags) &&
2374 gst_query_has_scheduling_mode (query, mode);
2378 * gst_query_new_accept_caps:
2379 * @caps: a fixed #GstCaps
2381 * Constructs a new query object for querying if @caps are accepted.
2383 * Free-function: gst_query_unref
2385 * Returns: (transfer full): a new #GstQuery
2388 gst_query_new_accept_caps (GstCaps * caps)
2391 GstStructure *structure;
2393 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
2395 structure = gst_structure_new_id (GST_QUARK (QUERY_ACCEPT_CAPS),
2396 GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
2397 GST_QUARK (RESULT), G_TYPE_BOOLEAN, FALSE, NULL);
2398 query = gst_query_new_custom (GST_QUERY_ACCEPT_CAPS, structure);
2404 * gst_query_parse_accept_caps:
2405 * @query: The query to parse
2406 * @caps: (out) (transfer none): A pointer to the caps
2408 * Get the caps from @query. The caps remains valid as long as @query remains
2412 gst_query_parse_accept_caps (GstQuery * query, GstCaps ** caps)
2414 GstStructure *structure;
2416 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2417 g_return_if_fail (caps != NULL);
2419 structure = GST_QUERY_STRUCTURE (query);
2420 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2425 * gst_query_set_accept_caps_result:
2426 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2427 * @result: the result to set
2429 * Set @result as the result for the @query.
2432 gst_query_set_accept_caps_result (GstQuery * query, gboolean result)
2434 GstStructure *structure;
2436 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2437 g_return_if_fail (gst_query_is_writable (query));
2439 structure = GST_QUERY_STRUCTURE (query);
2440 gst_structure_id_set (structure,
2441 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2445 * gst_query_parse_accept_caps_result:
2446 * @query: a GST_QUERY_ACCEPT_CAPS type query #GstQuery
2447 * @result: location for the result
2449 * Parse the result from @query and store in @result.
2452 gst_query_parse_accept_caps_result (GstQuery * query, gboolean * result)
2454 GstStructure *structure;
2456 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS);
2458 structure = GST_QUERY_STRUCTURE (query);
2459 gst_structure_id_get (structure,
2460 GST_QUARK (RESULT), G_TYPE_BOOLEAN, result, NULL);
2464 * gst_query_new_caps:
2467 * Constructs a new query object for querying the caps.
2469 * The CAPS query should return the allowable caps for a pad in the context
2470 * of the element's state, its link to other elements, and the devices or files
2471 * it has opened. These caps must be a subset of the pad template caps. In the
2472 * NULL state with no links, the CAPS query should ideally return the same caps
2473 * as the pad template. In rare circumstances, an object property can affect
2474 * the caps returned by the CAPS query, but this is discouraged.
2476 * For most filters, the caps returned by CAPS query is directly affected by the
2477 * allowed caps on other pads. For demuxers and decoders, the caps returned by
2478 * the srcpad's getcaps function is directly related to the stream data. Again,
2479 * the CAPS query should return the most specific caps it reasonably can, since this
2480 * helps with autoplugging.
2482 * The @filter is used to restrict the result caps, only the caps matching
2483 * @filter should be returned from the CAPS query. Specifying a filter might
2484 * greatly reduce the amount of processing an element needs to do.
2486 * Free-function: gst_query_unref
2488 * Returns: (transfer full): a new #GstQuery
2491 gst_query_new_caps (GstCaps * filter)
2494 GstStructure *structure;
2496 structure = gst_structure_new_id (GST_QUARK (QUERY_CAPS),
2497 GST_QUARK (FILTER), GST_TYPE_CAPS, filter,
2498 GST_QUARK (CAPS), GST_TYPE_CAPS, NULL, NULL);
2499 query = gst_query_new_custom (GST_QUERY_CAPS, structure);
2505 * gst_query_parse_caps:
2506 * @query: The query to parse
2507 * @filter: (out) (transfer none): A pointer to the caps filter
2509 * Get the filter from the caps @query. The caps remains valid as long as
2510 * @query remains valid.
2513 gst_query_parse_caps (GstQuery * query, GstCaps ** filter)
2515 GstStructure *structure;
2517 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2518 g_return_if_fail (filter != NULL);
2520 structure = GST_QUERY_STRUCTURE (query);
2521 *filter = g_value_get_boxed (gst_structure_id_get_value (structure,
2522 GST_QUARK (FILTER)));
2526 * gst_query_set_caps_result:
2527 * @query: The query to use
2528 * @caps: (in): A pointer to the caps
2530 * Set the @caps result in @query.
2533 gst_query_set_caps_result (GstQuery * query, GstCaps * caps)
2535 GstStructure *structure;
2537 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2538 g_return_if_fail (gst_query_is_writable (query));
2540 structure = GST_QUERY_STRUCTURE (query);
2541 gst_structure_id_set (structure, GST_QUARK (CAPS), GST_TYPE_CAPS, caps, NULL);
2545 * gst_query_parse_caps_result:
2546 * @query: The query to parse
2547 * @caps: (out) (transfer none): A pointer to the caps
2549 * Get the caps result from @query. The caps remains valid as long as
2550 * @query remains valid.
2553 gst_query_parse_caps_result (GstQuery * query, GstCaps ** caps)
2555 GstStructure *structure;
2557 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS);
2558 g_return_if_fail (caps != NULL);
2560 structure = GST_QUERY_STRUCTURE (query);
2561 *caps = g_value_get_boxed (gst_structure_id_get_value (structure,
2567 gst_query_intersect_caps_result (GstQuery * query, GstCaps * filter,
2568 GstCapsIntersectMode mode)
2570 GstCaps *res, *caps = NULL;
2572 gst_query_parse_caps_result (query, &caps);
2573 res = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
2574 gst_query_set_caps_result (query, res);
2575 gst_caps_unref (res);
2580 * gst_query_new_drain:
2582 * Constructs a new query object for querying the drain state.
2584 * Free-function: gst_query_unref
2586 * Returns: (transfer full): a new #GstQuery
2589 gst_query_new_drain (void)
2592 GstStructure *structure;
2594 structure = gst_structure_new_id_empty (GST_QUARK (QUERY_DRAIN));
2595 query = gst_query_new_custom (GST_QUERY_DRAIN, structure);
2601 * gst_query_new_context:
2602 * @context_type: Context type to query
2604 * Constructs a new query object for querying the pipeline-local context.
2606 * Free-function: gst_query_unref
2608 * Returns: (transfer full): a new #GstQuery
2613 gst_query_new_context (const gchar * context_type)
2616 GstStructure *structure;
2618 g_return_val_if_fail (context_type != NULL, NULL);
2620 structure = gst_structure_new_id (GST_QUARK (QUERY_CONTEXT),
2621 GST_QUARK (CONTEXT_TYPE), G_TYPE_STRING, context_type, NULL);
2622 query = gst_query_new_custom (GST_QUERY_CONTEXT, structure);
2628 * gst_query_set_context:
2629 * @query: a #GstQuery with query type GST_QUERY_CONTEXT
2630 * @context: the requested #GstContext
2632 * Answer a context query by setting the requested context.
2637 gst_query_set_context (GstQuery * query, GstContext * context)
2640 const gchar *context_type;
2642 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2644 gst_query_parse_context_type (query, &context_type);
2645 g_return_if_fail (strcmp (gst_context_get_context_type (context),
2646 context_type) == 0);
2648 s = GST_QUERY_STRUCTURE (query);
2650 gst_structure_id_set (s,
2651 GST_QUARK (CONTEXT), GST_TYPE_CONTEXT, context, NULL);
2655 * gst_query_parse_context:
2656 * @query: The query to parse
2657 * @context: (out) (transfer none): A pointer to store the #GstContext
2659 * Get the context from the context @query. The context remains valid as long as
2660 * @query remains valid.
2665 gst_query_parse_context (GstQuery * query, GstContext ** context)
2667 GstStructure *structure;
2670 g_return_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT);
2671 g_return_if_fail (context != NULL);
2673 structure = GST_QUERY_STRUCTURE (query);
2674 v = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT));
2676 *context = g_value_get_boxed (v);
2682 * gst_query_parse_context_type:
2683 * @query: a GST_QUERY_CONTEXT type query
2684 * @context_type: (out) (transfer none) (allow-none): the context type, or %NULL
2686 * Parse a context type from an existing GST_QUERY_CONTEXT query.
2688 * Returns: a #gboolean indicating if the parsing succeeded.
2693 gst_query_parse_context_type (GstQuery * query, const gchar ** context_type)
2695 GstStructure *structure;
2696 const GValue *value;
2698 g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
2700 structure = GST_QUERY_STRUCTURE (query);
2703 value = gst_structure_id_get_value (structure, GST_QUARK (CONTEXT_TYPE));
2704 *context_type = g_value_get_string (value);