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>
5 * 2011 Wim Taymans <wim.taymans@gmail.com>
7 * gstquery.h: GstQuery API declaration
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #ifndef __GST_QUERY_H__
27 #define __GST_QUERY_H__
31 #include <gst/gstiterator.h>
32 #include <gst/gstminiobject.h>
33 #include <gst/gststructure.h>
34 #include <gst/gstformat.h>
35 #include <gst/gstpad.h>
36 #include <gst/gstallocator.h>
37 #include <gst/gsttoc.h>
38 #include <gst/gstcontext.h>
42 typedef struct _GstQuery GstQuery;
46 * @GST_QUERY_TYPE_UPSTREAM: Set if the query can travel upstream.
47 * @GST_QUERY_TYPE_DOWNSTREAM: Set if the query can travel downstream.
48 * @GST_QUERY_TYPE_SERIALIZED: Set if the query should be serialized with data
51 * #GstQueryTypeFlags indicate the aspects of the different #GstQueryType
52 * values. You can get the type flags of a #GstQueryType with the
53 * gst_query_type_get_flags() function.
56 GST_QUERY_TYPE_UPSTREAM = 1 << 0,
57 GST_QUERY_TYPE_DOWNSTREAM = 1 << 1,
58 GST_QUERY_TYPE_SERIALIZED = 1 << 2
62 * GST_QUERY_TYPE_BOTH:
64 * The same thing as #GST_QUERY_TYPE_UPSTREAM | #GST_QUERY_TYPE_DOWNSTREAM.
66 #define GST_QUERY_TYPE_BOTH \
67 (GST_QUERY_TYPE_UPSTREAM | GST_QUERY_TYPE_DOWNSTREAM)
69 #define GST_QUERY_NUM_SHIFT (8)
72 * GST_QUERY_MAKE_TYPE:
73 * @num: the query number to create
74 * @flags: the query flags
76 * when making custom query types, use this macro with the num and
79 #define GST_QUERY_MAKE_TYPE(num,flags) \
80 (((num) << GST_QUERY_NUM_SHIFT) | (flags))
82 #define FLAG(name) GST_QUERY_TYPE_##name
87 * @GST_QUERY_UNKNOWN: unknown query type
88 * @GST_QUERY_POSITION: current position in stream
89 * @GST_QUERY_DURATION: total duration of the stream
90 * @GST_QUERY_LATENCY: latency of stream
91 * @GST_QUERY_JITTER: current jitter of stream
92 * @GST_QUERY_RATE: current rate of the stream
93 * @GST_QUERY_SEEKING: seeking capabilities
94 * @GST_QUERY_SEGMENT: segment start/stop positions
95 * @GST_QUERY_CONVERT: convert values between formats
96 * @GST_QUERY_FORMATS: query supported formats for convert
97 * @GST_QUERY_BUFFERING: query available media for efficient seeking.
98 * @GST_QUERY_CUSTOM: a custom application or element defined query.
99 * @GST_QUERY_URI: query the URI of the source or sink.
100 * @GST_QUERY_ALLOCATION: the buffer allocation properties
101 * @GST_QUERY_SCHEDULING: the scheduling properties
102 * @GST_QUERY_ACCEPT_CAPS: the accept caps query
103 * @GST_QUERY_CAPS: the caps query
104 * @GST_QUERY_DRAIN: wait till all serialized data is consumed downstream
105 * @GST_QUERY_CONTEXT: query the pipeline-local context from
106 * downstream or upstream (since 1.2)
108 * Standard predefined Query types
110 /* NOTE: don't forget to update the table in gstquery.c when changing
113 GST_QUERY_UNKNOWN = GST_QUERY_MAKE_TYPE (0, 0),
114 GST_QUERY_POSITION = GST_QUERY_MAKE_TYPE (10, FLAG(BOTH)),
115 GST_QUERY_DURATION = GST_QUERY_MAKE_TYPE (20, FLAG(BOTH)),
116 GST_QUERY_LATENCY = GST_QUERY_MAKE_TYPE (30, FLAG(BOTH)),
117 GST_QUERY_JITTER = GST_QUERY_MAKE_TYPE (40, FLAG(BOTH)),
118 GST_QUERY_RATE = GST_QUERY_MAKE_TYPE (50, FLAG(BOTH)),
119 GST_QUERY_SEEKING = GST_QUERY_MAKE_TYPE (60, FLAG(BOTH)),
120 GST_QUERY_SEGMENT = GST_QUERY_MAKE_TYPE (70, FLAG(BOTH)),
121 GST_QUERY_CONVERT = GST_QUERY_MAKE_TYPE (80, FLAG(BOTH)),
122 GST_QUERY_FORMATS = GST_QUERY_MAKE_TYPE (90, FLAG(BOTH)),
123 GST_QUERY_BUFFERING = GST_QUERY_MAKE_TYPE (110, FLAG(BOTH)),
124 GST_QUERY_CUSTOM = GST_QUERY_MAKE_TYPE (120, FLAG(BOTH)),
125 GST_QUERY_URI = GST_QUERY_MAKE_TYPE (130, FLAG(BOTH)),
126 GST_QUERY_ALLOCATION = GST_QUERY_MAKE_TYPE (140, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)),
127 GST_QUERY_SCHEDULING = GST_QUERY_MAKE_TYPE (150, FLAG(UPSTREAM)),
128 GST_QUERY_ACCEPT_CAPS = GST_QUERY_MAKE_TYPE (160, FLAG(BOTH)),
129 GST_QUERY_CAPS = GST_QUERY_MAKE_TYPE (170, FLAG(BOTH)),
130 GST_QUERY_DRAIN = GST_QUERY_MAKE_TYPE (180, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)),
131 GST_QUERY_CONTEXT = GST_QUERY_MAKE_TYPE (190, FLAG(BOTH))
133 ,GST_QUERY_RESOURCE = GST_QUERY_MAKE_TYPE (200, FLAG (BOTH))
138 GST_EXPORT GType _gst_query_type;
140 #define GST_TYPE_QUERY (_gst_query_type)
141 #define GST_IS_QUERY(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_QUERY))
142 #define GST_QUERY_CAST(obj) ((GstQuery*)(obj))
143 #define GST_QUERY(obj) (GST_QUERY_CAST(obj))
147 * @query: the query to query
149 * Get the #GstQueryType of the query.
151 #define GST_QUERY_TYPE(query) (((GstQuery*)(query))->type)
154 * GST_QUERY_TYPE_NAME:
155 * @query: the query to query
157 * Get a constant string representation of the #GstQueryType of the query.
159 #define GST_QUERY_TYPE_NAME(query) (gst_query_type_get_name(GST_QUERY_TYPE(query)))
162 * GST_QUERY_IS_UPSTREAM:
163 * @ev: the query to query
165 * Check if an query can travel upstream.
167 #define GST_QUERY_IS_UPSTREAM(ev) !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_UPSTREAM)
169 * GST_QUERY_IS_DOWNSTREAM:
170 * @ev: the query to query
172 * Check if an query can travel downstream.
174 #define GST_QUERY_IS_DOWNSTREAM(ev) !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_DOWNSTREAM)
176 * GST_QUERY_IS_SERIALIZED:
177 * @ev: the query to query
179 * Check if an query is serialized with the data stream.
181 #define GST_QUERY_IS_SERIALIZED(ev) !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_SERIALIZED)
186 * @mini_object: The parent #GstMiniObject type
187 * @type: the #GstQueryType
189 * The #GstQuery structure.
193 GstMiniObject mini_object;
195 /*< public > *//* with COW */
199 const gchar* gst_query_type_get_name (GstQueryType type);
200 GQuark gst_query_type_to_quark (GstQueryType type);
202 gst_query_type_get_flags (GstQueryType type);
205 GType gst_query_get_type (void);
210 * @q: a #GstQuery to increase the refcount of.
212 * Increases the refcount of the given query by one.
216 #ifdef _FOOL_GTK_DOC_
217 G_INLINE_FUNC GstQuery * gst_query_ref (GstQuery * q);
220 static inline GstQuery *
221 gst_query_ref (GstQuery * q)
223 return GST_QUERY_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (q)));
228 * @q: a #GstQuery to decrease the refcount of.
230 * Decreases the refcount of the query. If the refcount reaches 0, the query
233 #ifdef _FOOL_GTK_DOC_
234 G_INLINE_FUNC void gst_query_unref (GstQuery * q);
238 gst_query_unref (GstQuery * q)
240 gst_mini_object_unref (GST_MINI_OBJECT_CAST (q));
246 * @q: a #GstQuery to copy.
248 * Copies the given query using the copy function of the parent #GstStructure.
250 * Free-function: gst_query_unref
252 * Returns: (transfer full): a new copy of @q.
254 #ifdef _FOOL_GTK_DOC_
255 G_INLINE_FUNC GstQuery * gst_query_copy (const GstQuery * q);
258 static inline GstQuery *
259 gst_query_copy (const GstQuery * q)
261 return GST_QUERY_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (q)));
265 * gst_query_is_writable:
268 * Tests if you can safely write data into a query's structure.
270 #define gst_query_is_writable(q) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (q))
272 * gst_query_make_writable:
273 * @q: (transfer full): a #GstQuery to make writable
275 * Makes a writable query from the given query.
277 * Returns: (transfer full): a new writable query (possibly same as @q)
279 #define gst_query_make_writable(q) GST_QUERY_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (q)))
282 * @old_query: (inout) (transfer full) (nullable): pointer to a pointer to a
283 * #GstQuery to be replaced.
284 * @new_query: (allow-none) (transfer none): pointer to a #GstQuery that will
285 * replace the query pointed to by @old_query.
287 * Modifies a pointer to a #GstQuery to point to a different #GstQuery. The
288 * modification is done atomically (so this is useful for ensuring thread safety
289 * in some cases), and the reference counts are updated appropriately (the old
290 * query is unreffed, the new one is reffed).
292 * Either @new_query or the #GstQuery pointed to by @old_query may be %NULL.
294 * Returns: %TRUE if @new_query was different from @old_query
296 #ifdef _FOOL_GTK_DOC_
297 G_INLINE_FUNC gboolean gst_query_replace (GstQuery **old_query, GstQuery *new_query);
300 static inline gboolean
301 gst_query_replace (GstQuery **old_query, GstQuery *new_query)
303 return gst_mini_object_replace ((GstMiniObject **) old_query, (GstMiniObject *) new_query);
306 /* application specific query */
307 GstQuery * gst_query_new_custom (GstQueryType type, GstStructure *structure) G_GNUC_MALLOC;
309 gst_query_get_structure (GstQuery *query);
310 GstStructure * gst_query_writable_structure (GstQuery *query);
313 GstQuery* gst_query_new_position (GstFormat format) G_GNUC_MALLOC;
314 void gst_query_set_position (GstQuery *query, GstFormat format, gint64 cur);
315 void gst_query_parse_position (GstQuery *query, GstFormat *format, gint64 *cur);
318 GstQuery* gst_query_new_duration (GstFormat format) G_GNUC_MALLOC;
319 void gst_query_set_duration (GstQuery *query, GstFormat format, gint64 duration);
320 void gst_query_parse_duration (GstQuery *query, GstFormat *format, gint64 *duration);
323 /* resrource query */
324 GstQuery* gst_query_new_resource (gchar * resources) G_GNUC_MALLOC;
325 void gst_query_add_resource (GstQuery * query, gint resource_id);
326 gchar* gst_query_parse_resource (GstQuery * query);
330 GstQuery* gst_query_new_latency (void) G_GNUC_MALLOC;
331 void gst_query_set_latency (GstQuery *query, gboolean live, GstClockTime min_latency,
332 GstClockTime max_latency);
333 void gst_query_parse_latency (GstQuery *query, gboolean *live, GstClockTime *min_latency,
334 GstClockTime *max_latency);
337 GstQuery* gst_query_new_convert (GstFormat src_format, gint64 value, GstFormat dest_format) G_GNUC_MALLOC;
338 void gst_query_set_convert (GstQuery *query, GstFormat src_format, gint64 src_value,
339 GstFormat dest_format, gint64 dest_value);
340 void gst_query_parse_convert (GstQuery *query, GstFormat *src_format, gint64 *src_value,
341 GstFormat *dest_format, gint64 *dest_value);
343 GstQuery* gst_query_new_segment (GstFormat format) G_GNUC_MALLOC;
344 void gst_query_set_segment (GstQuery *query, gdouble rate, GstFormat format,
345 gint64 start_value, gint64 stop_value);
346 void gst_query_parse_segment (GstQuery *query, gdouble *rate, GstFormat *format,
347 gint64 *start_value, gint64 *stop_value);
350 GstQuery* gst_query_new_seeking (GstFormat format) G_GNUC_MALLOC;
351 void gst_query_set_seeking (GstQuery *query, GstFormat format,
353 gint64 segment_start,
355 void gst_query_parse_seeking (GstQuery *query, GstFormat *format,
357 gint64 *segment_start,
358 gint64 *segment_end);
360 GstQuery* gst_query_new_formats (void) G_GNUC_MALLOC;
361 void gst_query_set_formats (GstQuery *query, gint n_formats, ...);
362 void gst_query_set_formatsv (GstQuery *query, gint n_formats, const GstFormat *formats);
363 void gst_query_parse_n_formats (GstQuery *query, guint *n_formats);
364 void gst_query_parse_nth_format (GstQuery *query, guint nth, GstFormat *format);
366 /* buffering query */
369 * @GST_BUFFERING_STREAM: a small amount of data is buffered
370 * @GST_BUFFERING_DOWNLOAD: the stream is being downloaded
371 * @GST_BUFFERING_TIMESHIFT: the stream is being downloaded in a ringbuffer
372 * @GST_BUFFERING_LIVE: the stream is a live stream
374 * The different types of buffering methods.
377 GST_BUFFERING_STREAM,
378 GST_BUFFERING_DOWNLOAD,
379 GST_BUFFERING_TIMESHIFT,
383 GstQuery* gst_query_new_buffering (GstFormat format) G_GNUC_MALLOC;
384 void gst_query_set_buffering_percent (GstQuery *query, gboolean busy, gint percent);
385 void gst_query_parse_buffering_percent (GstQuery *query, gboolean *busy, gint *percent);
387 void gst_query_set_buffering_stats (GstQuery *query, GstBufferingMode mode,
388 gint avg_in, gint avg_out,
389 gint64 buffering_left);
390 void gst_query_parse_buffering_stats (GstQuery *query, GstBufferingMode *mode,
391 gint *avg_in, gint *avg_out,
392 gint64 *buffering_left);
394 void gst_query_set_buffering_range (GstQuery *query, GstFormat format,
395 gint64 start, gint64 stop,
396 gint64 estimated_total);
397 void gst_query_parse_buffering_range (GstQuery *query, GstFormat *format,
398 gint64 *start, gint64 *stop,
399 gint64 *estimated_total);
401 gboolean gst_query_add_buffering_range (GstQuery *query,
402 gint64 start, gint64 stop);
403 guint gst_query_get_n_buffering_ranges (GstQuery *query);
404 gboolean gst_query_parse_nth_buffering_range (GstQuery *query,
405 guint index, gint64 *start,
409 GstQuery * gst_query_new_uri (void) G_GNUC_MALLOC;
410 void gst_query_parse_uri (GstQuery *query, gchar **uri);
411 void gst_query_set_uri (GstQuery *query, const gchar *uri);
412 void gst_query_parse_uri_redirection (GstQuery *query, gchar **uri);
413 void gst_query_set_uri_redirection (GstQuery *query, const gchar *uri);
414 void gst_query_parse_uri_redirection_permanent (GstQuery *query, gboolean * permanent);
415 void gst_query_set_uri_redirection_permanent (GstQuery *query, gboolean permanent);
417 /* allocation query */
418 GstQuery * gst_query_new_allocation (GstCaps *caps, gboolean need_pool) G_GNUC_MALLOC;
419 void gst_query_parse_allocation (GstQuery *query, GstCaps **caps, gboolean *need_pool);
422 void gst_query_add_allocation_pool (GstQuery *query, GstBufferPool *pool,
423 guint size, guint min_buffers,
425 guint gst_query_get_n_allocation_pools (GstQuery *query);
426 void gst_query_parse_nth_allocation_pool (GstQuery *query, guint index,
427 GstBufferPool **pool,
428 guint *size, guint *min_buffers,
430 void gst_query_set_nth_allocation_pool (GstQuery *query, guint index,
432 guint size, guint min_buffers,
434 void gst_query_remove_nth_allocation_pool (GstQuery *query, guint index);
437 void gst_query_add_allocation_param (GstQuery *query, GstAllocator *allocator,
438 const GstAllocationParams *params);
439 guint gst_query_get_n_allocation_params (GstQuery *query);
440 void gst_query_parse_nth_allocation_param (GstQuery *query, guint index,
441 GstAllocator **allocator,
442 GstAllocationParams *params);
443 void gst_query_set_nth_allocation_param (GstQuery *query, guint index,
444 GstAllocator *allocator,
445 const GstAllocationParams *params);
446 void gst_query_remove_nth_allocation_param (GstQuery *query, guint index);
449 void gst_query_add_allocation_meta (GstQuery *query, GType api, const GstStructure *params);
450 guint gst_query_get_n_allocation_metas (GstQuery *query);
451 GType gst_query_parse_nth_allocation_meta (GstQuery *query, guint index,
452 const GstStructure **params);
453 void gst_query_remove_nth_allocation_meta (GstQuery *query, guint index);
454 gboolean gst_query_find_allocation_meta (GstQuery *query, GType api, guint *index);
457 /* scheduling query */
459 * GstSchedulingFlags:
460 * @GST_SCHEDULING_FLAG_SEEKABLE: if seeking is possible
461 * @GST_SCHEDULING_FLAG_SEQUENTIAL: if sequential access is recommended
462 * @GST_SCHEDULING_FLAG_BANDWIDTH_LIMITED: if bandwidth is limited and buffering possible (since 1.2)
464 * The different scheduling flags.
467 GST_SCHEDULING_FLAG_SEEKABLE = (1 << 0),
468 GST_SCHEDULING_FLAG_SEQUENTIAL = (1 << 1),
469 GST_SCHEDULING_FLAG_BANDWIDTH_LIMITED = (1 << 2)
470 } GstSchedulingFlags;
472 GstQuery * gst_query_new_scheduling (void) G_GNUC_MALLOC;
474 void gst_query_set_scheduling (GstQuery *query, GstSchedulingFlags flags,
475 gint minsize, gint maxsize, gint align);
476 void gst_query_parse_scheduling (GstQuery *query, GstSchedulingFlags *flags,
477 gint *minsize, gint *maxsize, gint *align);
479 void gst_query_add_scheduling_mode (GstQuery *query, GstPadMode mode);
480 guint gst_query_get_n_scheduling_modes (GstQuery *query);
481 GstPadMode gst_query_parse_nth_scheduling_mode (GstQuery *query, guint index);
482 gboolean gst_query_has_scheduling_mode (GstQuery *query, GstPadMode mode);
483 gboolean gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
484 GstSchedulingFlags flags);
486 /* accept-caps query */
487 GstQuery * gst_query_new_accept_caps (GstCaps *caps) G_GNUC_MALLOC;
488 void gst_query_parse_accept_caps (GstQuery *query, GstCaps **caps);
489 void gst_query_set_accept_caps_result (GstQuery *query, gboolean result);
490 void gst_query_parse_accept_caps_result (GstQuery *query, gboolean *result);
493 GstQuery * gst_query_new_caps (GstCaps *filter) G_GNUC_MALLOC;
494 void gst_query_parse_caps (GstQuery *query, GstCaps **filter);
496 void gst_query_set_caps_result (GstQuery *query, GstCaps *caps);
497 void gst_query_parse_caps_result (GstQuery *query, GstCaps **caps);
500 GstQuery * gst_query_new_drain (void) G_GNUC_MALLOC;
503 GstQuery * gst_query_new_context (const gchar * context_type) G_GNUC_MALLOC;
504 gboolean gst_query_parse_context_type (GstQuery * query, const gchar ** context_type);
505 void gst_query_set_context (GstQuery *query, GstContext *context);
506 void gst_query_parse_context (GstQuery *query, GstContext **context);
510 #endif /* __GST_QUERY_H__ */