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__
30 #include <glib-object.h>
31 #include <gst/gstconfig.h>
35 typedef struct _GstQuery GstQuery;
37 #include <gst/gstminiobject.h>
41 * @GST_QUERY_TYPE_UPSTREAM: Set if the query can travel upstream.
42 * @GST_QUERY_TYPE_DOWNSTREAM: Set if the query can travel downstream.
43 * @GST_QUERY_TYPE_SERIALIZED: Set if the query should be serialized with data
46 * #GstQueryTypeFlags indicate the aspects of the different #GstQueryType
47 * values. You can get the type flags of a #GstQueryType with the
48 * gst_query_type_get_flags() function.
51 GST_QUERY_TYPE_UPSTREAM = 1 << 0,
52 GST_QUERY_TYPE_DOWNSTREAM = 1 << 1,
53 GST_QUERY_TYPE_SERIALIZED = 1 << 2
57 * GST_QUERY_TYPE_BOTH: (value 3) (type GstQueryTypeFlags)
59 * The same thing as #GST_QUERY_TYPE_UPSTREAM | #GST_QUERY_TYPE_DOWNSTREAM.
61 #define GST_QUERY_TYPE_BOTH \
62 ((GstQueryTypeFlags)(GST_QUERY_TYPE_UPSTREAM | GST_QUERY_TYPE_DOWNSTREAM))
64 #define GST_QUERY_NUM_SHIFT (8)
67 * GST_QUERY_MAKE_TYPE:
68 * @num: the query number to create
69 * @flags: the query flags
71 * when making custom query types, use this macro with the num and
74 #define GST_QUERY_MAKE_TYPE(num,flags) \
75 (((num) << GST_QUERY_NUM_SHIFT) | (flags))
77 #define _FLAG(name) GST_QUERY_TYPE_##name
82 * @GST_QUERY_UNKNOWN: unknown query type
83 * @GST_QUERY_POSITION: current position in stream
84 * @GST_QUERY_DURATION: total duration of the stream
85 * @GST_QUERY_LATENCY: latency of stream
86 * @GST_QUERY_JITTER: current jitter of stream
87 * @GST_QUERY_RATE: current rate of the stream
88 * @GST_QUERY_SEEKING: seeking capabilities
89 * @GST_QUERY_SEGMENT: segment start/stop positions
90 * @GST_QUERY_CONVERT: convert values between formats
91 * @GST_QUERY_FORMATS: query supported formats for convert
92 * @GST_QUERY_BUFFERING: query available media for efficient seeking.
93 * @GST_QUERY_CUSTOM: a custom application or element defined query.
94 * @GST_QUERY_URI: query the URI of the source or sink.
95 * @GST_QUERY_ALLOCATION: the buffer allocation properties
96 * @GST_QUERY_SCHEDULING: the scheduling properties
97 * @GST_QUERY_ACCEPT_CAPS: the accept caps query
98 * @GST_QUERY_CAPS: the caps query
99 * @GST_QUERY_DRAIN: wait till all serialized data is consumed downstream
100 * @GST_QUERY_CONTEXT: query the pipeline-local context from
101 * downstream or upstream (since 1.2)
102 * @GST_QUERY_BITRATE: the bitrate query (since 1.16)
104 * Standard predefined Query types
106 /* NOTE: don't forget to update the table in gstquery.c when changing
109 GST_QUERY_UNKNOWN = GST_QUERY_MAKE_TYPE (0, 0),
110 GST_QUERY_POSITION = GST_QUERY_MAKE_TYPE (10, _FLAG(BOTH)),
111 GST_QUERY_DURATION = GST_QUERY_MAKE_TYPE (20, _FLAG(BOTH)),
112 GST_QUERY_LATENCY = GST_QUERY_MAKE_TYPE (30, _FLAG(BOTH)),
113 GST_QUERY_JITTER = GST_QUERY_MAKE_TYPE (40, _FLAG(BOTH)),
114 GST_QUERY_RATE = GST_QUERY_MAKE_TYPE (50, _FLAG(BOTH)),
115 GST_QUERY_SEEKING = GST_QUERY_MAKE_TYPE (60, _FLAG(BOTH)),
116 GST_QUERY_SEGMENT = GST_QUERY_MAKE_TYPE (70, _FLAG(BOTH)),
117 GST_QUERY_CONVERT = GST_QUERY_MAKE_TYPE (80, _FLAG(BOTH)),
118 GST_QUERY_FORMATS = GST_QUERY_MAKE_TYPE (90, _FLAG(BOTH)),
119 GST_QUERY_BUFFERING = GST_QUERY_MAKE_TYPE (110, _FLAG(BOTH)),
120 GST_QUERY_CUSTOM = GST_QUERY_MAKE_TYPE (120, _FLAG(BOTH)),
121 GST_QUERY_URI = GST_QUERY_MAKE_TYPE (130, _FLAG(BOTH)),
122 GST_QUERY_ALLOCATION = GST_QUERY_MAKE_TYPE (140, _FLAG(DOWNSTREAM) | _FLAG(SERIALIZED)),
123 GST_QUERY_SCHEDULING = GST_QUERY_MAKE_TYPE (150, _FLAG(UPSTREAM)),
124 GST_QUERY_ACCEPT_CAPS = GST_QUERY_MAKE_TYPE (160, _FLAG(BOTH)),
125 GST_QUERY_CAPS = GST_QUERY_MAKE_TYPE (170, _FLAG(BOTH)),
126 GST_QUERY_DRAIN = GST_QUERY_MAKE_TYPE (180, _FLAG(DOWNSTREAM) | _FLAG(SERIALIZED)),
127 GST_QUERY_CONTEXT = GST_QUERY_MAKE_TYPE (190, _FLAG(BOTH)),
128 GST_QUERY_BITRATE = GST_QUERY_MAKE_TYPE (200, _FLAG(DOWNSTREAM)),
132 GST_API GType _gst_query_type;
134 #define GST_TYPE_QUERY (_gst_query_type)
135 #define GST_IS_QUERY(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_QUERY))
136 #define GST_QUERY_CAST(obj) ((GstQuery*)(obj))
137 #define GST_QUERY(obj) (GST_QUERY_CAST(obj))
141 * @query: the query to query
143 * Get the #GstQueryType of the query.
145 #define GST_QUERY_TYPE(query) (((GstQuery*)(query))->type)
148 * GST_QUERY_TYPE_NAME:
149 * @query: the query to query
151 * Get a constant string representation of the #GstQueryType of the query.
153 #define GST_QUERY_TYPE_NAME(query) (gst_query_type_get_name(GST_QUERY_TYPE(query)))
156 * GST_QUERY_IS_UPSTREAM:
157 * @ev: the query to query
159 * Check if an query can travel upstream.
161 #define GST_QUERY_IS_UPSTREAM(ev) !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_UPSTREAM)
163 * GST_QUERY_IS_DOWNSTREAM:
164 * @ev: the query to query
166 * Check if an query can travel downstream.
168 #define GST_QUERY_IS_DOWNSTREAM(ev) !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_DOWNSTREAM)
170 * GST_QUERY_IS_SERIALIZED:
171 * @ev: the query to query
173 * Check if an query is serialized with the data stream.
175 #define GST_QUERY_IS_SERIALIZED(ev) !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_SERIALIZED)
180 * @mini_object: The parent #GstMiniObject type
181 * @type: the #GstQueryType
183 * The #GstQuery structure.
187 GstMiniObject mini_object;
189 /*< public > *//* with COW */
195 * @GST_BUFFERING_STREAM: a small amount of data is buffered
196 * @GST_BUFFERING_DOWNLOAD: the stream is being downloaded
197 * @GST_BUFFERING_TIMESHIFT: the stream is being downloaded in a ringbuffer
198 * @GST_BUFFERING_LIVE: the stream is a live stream
200 * The different types of buffering methods.
203 GST_BUFFERING_STREAM,
204 GST_BUFFERING_DOWNLOAD,
205 GST_BUFFERING_TIMESHIFT,
209 #include <gst/gstiterator.h>
210 #include <gst/gststructure.h>
211 #include <gst/gstformat.h>
212 #include <gst/gstpad.h>
213 #include <gst/gstallocator.h>
214 #include <gst/gsttoc.h>
215 #include <gst/gstcontext.h>
218 const gchar* gst_query_type_get_name (GstQueryType type);
221 GQuark gst_query_type_to_quark (GstQueryType type);
225 gst_query_type_get_flags (GstQueryType type);
229 GType gst_query_get_type (void);
231 #ifndef GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS
233 static inline GstQuery *
234 gst_query_ref (GstQuery * q)
236 return GST_QUERY_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (q)));
240 gst_query_unref (GstQuery * q)
242 gst_mini_object_unref (GST_MINI_OBJECT_CAST (q));
246 gst_clear_query (GstQuery ** query_ptr)
248 gst_clear_mini_object ((GstMiniObject **) query_ptr);
252 static inline GstQuery *
253 gst_query_copy (const GstQuery * q)
255 return GST_QUERY_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (q)));
257 #else /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */
259 GstQuery * gst_query_ref (GstQuery * q);
262 void gst_query_unref (GstQuery * q);
265 void gst_clear_query (GstQuery ** query_ptr);
268 GstQuery * gst_query_copy (const GstQuery * q);
269 #endif /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */
272 * gst_query_is_writable:
275 * Tests if you can safely write data into a query's structure.
277 #define gst_query_is_writable(q) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (q))
279 * gst_query_make_writable:
280 * @q: (transfer full): a #GstQuery to make writable
282 * Makes a writable query from the given query.
284 * Returns: (transfer full): a new writable query (possibly same as @q)
286 #define gst_query_make_writable(q) GST_QUERY_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (q)))
288 #ifndef GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS
289 static inline gboolean
290 gst_query_replace (GstQuery **old_query, GstQuery *new_query)
292 return gst_mini_object_replace ((GstMiniObject **) old_query, (GstMiniObject *) new_query);
295 static inline gboolean
296 gst_query_take (GstQuery **old_query, GstQuery *new_query)
298 return gst_mini_object_take ((GstMiniObject **) old_query,
299 (GstMiniObject *) new_query);
301 #else /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */
303 gboolean gst_query_replace (GstQuery ** old_query,
304 GstQuery * new_query);
307 gboolean gst_query_take (GstQuery ** old_query,
308 GstQuery * new_query);
309 #endif /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */
311 /* application specific query */
314 GstQuery * gst_query_new_custom (GstQueryType type, GstStructure *structure) G_GNUC_MALLOC;
318 gst_query_get_structure (GstQuery *query);
321 GstStructure * gst_query_writable_structure (GstQuery *query);
326 GstQuery* gst_query_new_position (GstFormat format) G_GNUC_MALLOC;
329 void gst_query_set_position (GstQuery *query, GstFormat format, gint64 cur);
332 void gst_query_parse_position (GstQuery *query, GstFormat *format, gint64 *cur);
337 GstQuery* gst_query_new_duration (GstFormat format) G_GNUC_MALLOC;
340 void gst_query_set_duration (GstQuery *query, GstFormat format, gint64 duration);
343 void gst_query_parse_duration (GstQuery *query, GstFormat *format, gint64 *duration);
348 GstQuery* gst_query_new_latency (void) G_GNUC_MALLOC;
351 void gst_query_set_latency (GstQuery *query, gboolean live, GstClockTime min_latency,
352 GstClockTime max_latency);
355 void gst_query_parse_latency (GstQuery *query, gboolean *live, GstClockTime *min_latency,
356 GstClockTime *max_latency);
361 GstQuery* gst_query_new_convert (GstFormat src_format, gint64 value, GstFormat dest_format) G_GNUC_MALLOC;
364 void gst_query_set_convert (GstQuery *query, GstFormat src_format, gint64 src_value,
365 GstFormat dest_format, gint64 dest_value);
368 void gst_query_parse_convert (GstQuery *query, GstFormat *src_format, gint64 *src_value,
369 GstFormat *dest_format, gint64 *dest_value);
373 GstQuery* gst_query_new_segment (GstFormat format) G_GNUC_MALLOC;
376 void gst_query_set_segment (GstQuery *query, gdouble rate, GstFormat format,
377 gint64 start_value, gint64 stop_value);
380 void gst_query_parse_segment (GstQuery *query, gdouble *rate, GstFormat *format,
381 gint64 *start_value, gint64 *stop_value);
386 GstQuery* gst_query_new_seeking (GstFormat format) G_GNUC_MALLOC;
389 void gst_query_set_seeking (GstQuery *query, GstFormat format,
391 gint64 segment_start,
395 void gst_query_parse_seeking (GstQuery *query, GstFormat *format,
397 gint64 *segment_start,
398 gint64 *segment_end);
402 GstQuery* gst_query_new_formats (void) G_GNUC_MALLOC;
405 void gst_query_set_formats (GstQuery *query, gint n_formats, ...);
408 void gst_query_set_formatsv (GstQuery *query, gint n_formats, const GstFormat *formats);
411 void gst_query_parse_n_formats (GstQuery *query, guint *n_formats);
414 void gst_query_parse_nth_format (GstQuery *query, guint nth, GstFormat *format);
416 /* buffering query */
419 GstQuery* gst_query_new_buffering (GstFormat format) G_GNUC_MALLOC;
422 void gst_query_set_buffering_percent (GstQuery *query, gboolean busy, gint percent);
425 void gst_query_parse_buffering_percent (GstQuery *query, gboolean *busy, gint *percent);
428 void gst_query_set_buffering_stats (GstQuery *query, GstBufferingMode mode,
429 gint avg_in, gint avg_out,
430 gint64 buffering_left);
433 void gst_query_parse_buffering_stats (GstQuery *query, GstBufferingMode *mode,
434 gint *avg_in, gint *avg_out,
435 gint64 *buffering_left);
438 void gst_query_set_buffering_range (GstQuery *query, GstFormat format,
439 gint64 start, gint64 stop,
440 gint64 estimated_total);
443 void gst_query_parse_buffering_range (GstQuery *query, GstFormat *format,
444 gint64 *start, gint64 *stop,
445 gint64 *estimated_total);
448 gboolean gst_query_add_buffering_range (GstQuery *query,
449 gint64 start, gint64 stop);
452 guint gst_query_get_n_buffering_ranges (GstQuery *query);
455 gboolean gst_query_parse_nth_buffering_range (GstQuery *query,
456 guint index, gint64 *start,
462 GstQuery * gst_query_new_uri (void) G_GNUC_MALLOC;
465 void gst_query_parse_uri (GstQuery *query, gchar **uri);
468 void gst_query_set_uri (GstQuery *query, const gchar *uri);
471 void gst_query_parse_uri_redirection (GstQuery *query, gchar **uri);
474 void gst_query_set_uri_redirection (GstQuery *query, const gchar *uri);
477 void gst_query_parse_uri_redirection_permanent (GstQuery *query, gboolean * permanent);
480 void gst_query_set_uri_redirection_permanent (GstQuery *query, gboolean permanent);
482 /* allocation query */
485 GstQuery * gst_query_new_allocation (GstCaps *caps, gboolean need_pool) G_GNUC_MALLOC;
488 void gst_query_parse_allocation (GstQuery *query, GstCaps **caps, gboolean *need_pool);
493 void gst_query_add_allocation_pool (GstQuery *query, GstBufferPool *pool,
494 guint size, guint min_buffers,
498 guint gst_query_get_n_allocation_pools (GstQuery *query);
501 void gst_query_parse_nth_allocation_pool (GstQuery *query, guint index,
502 GstBufferPool **pool,
503 guint *size, guint *min_buffers,
507 void gst_query_set_nth_allocation_pool (GstQuery *query, guint index,
509 guint size, guint min_buffers,
513 void gst_query_remove_nth_allocation_pool (GstQuery *query, guint index);
518 void gst_query_add_allocation_param (GstQuery *query, GstAllocator *allocator,
519 const GstAllocationParams *params);
522 guint gst_query_get_n_allocation_params (GstQuery *query);
525 void gst_query_parse_nth_allocation_param (GstQuery *query, guint index,
526 GstAllocator **allocator,
527 GstAllocationParams *params);
530 void gst_query_set_nth_allocation_param (GstQuery *query, guint index,
531 GstAllocator *allocator,
532 const GstAllocationParams *params);
535 void gst_query_remove_nth_allocation_param (GstQuery *query, guint index);
540 void gst_query_add_allocation_meta (GstQuery *query, GType api, const GstStructure *params);
543 guint gst_query_get_n_allocation_metas (GstQuery *query);
546 GType gst_query_parse_nth_allocation_meta (GstQuery *query, guint index,
547 const GstStructure **params);
550 void gst_query_remove_nth_allocation_meta (GstQuery *query, guint index);
553 gboolean gst_query_find_allocation_meta (GstQuery *query, GType api, guint *index);
556 /* scheduling query */
558 * GstSchedulingFlags:
559 * @GST_SCHEDULING_FLAG_SEEKABLE: if seeking is possible
560 * @GST_SCHEDULING_FLAG_SEQUENTIAL: if sequential access is recommended
561 * @GST_SCHEDULING_FLAG_BANDWIDTH_LIMITED: if bandwidth is limited and buffering possible (since 1.2)
563 * The different scheduling flags.
566 GST_SCHEDULING_FLAG_SEEKABLE = (1 << 0),
567 GST_SCHEDULING_FLAG_SEQUENTIAL = (1 << 1),
568 GST_SCHEDULING_FLAG_BANDWIDTH_LIMITED = (1 << 2)
569 } GstSchedulingFlags;
572 GstQuery * gst_query_new_scheduling (void) G_GNUC_MALLOC;
575 void gst_query_set_scheduling (GstQuery *query, GstSchedulingFlags flags,
576 gint minsize, gint maxsize, gint align);
579 void gst_query_parse_scheduling (GstQuery *query, GstSchedulingFlags *flags,
580 gint *minsize, gint *maxsize, gint *align);
583 void gst_query_add_scheduling_mode (GstQuery *query, GstPadMode mode);
586 guint gst_query_get_n_scheduling_modes (GstQuery *query);
589 GstPadMode gst_query_parse_nth_scheduling_mode (GstQuery *query, guint index);
592 gboolean gst_query_has_scheduling_mode (GstQuery *query, GstPadMode mode);
595 gboolean gst_query_has_scheduling_mode_with_flags (GstQuery * query, GstPadMode mode,
596 GstSchedulingFlags flags);
598 /* accept-caps query */
601 GstQuery * gst_query_new_accept_caps (GstCaps *caps) G_GNUC_MALLOC;
604 void gst_query_parse_accept_caps (GstQuery *query, GstCaps **caps);
607 void gst_query_set_accept_caps_result (GstQuery *query, gboolean result);
610 void gst_query_parse_accept_caps_result (GstQuery *query, gboolean *result);
615 GstQuery * gst_query_new_caps (GstCaps *filter) G_GNUC_MALLOC;
618 void gst_query_parse_caps (GstQuery *query, GstCaps **filter);
621 void gst_query_set_caps_result (GstQuery *query, GstCaps *caps);
624 void gst_query_parse_caps_result (GstQuery *query, GstCaps **caps);
629 GstQuery * gst_query_new_drain (void) G_GNUC_MALLOC;
634 GstQuery * gst_query_new_context (const gchar * context_type) G_GNUC_MALLOC;
637 gboolean gst_query_parse_context_type (GstQuery * query, const gchar ** context_type);
640 void gst_query_set_context (GstQuery *query, GstContext *context);
643 void gst_query_parse_context (GstQuery *query, GstContext **context);
648 GstQuery * gst_query_new_bitrate (void) G_GNUC_MALLOC;
651 void gst_query_set_bitrate (GstQuery * query, guint nominal_bitrate);
654 void gst_query_parse_bitrate (GstQuery * query, guint * nominal_bitrate);
656 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstQuery, gst_query_unref)
660 #endif /* __GST_QUERY_H__ */