query: register queries like events
[platform/upstream/gstreamer.git] / gst / gstquery.h
1 /* GStreamer
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>
6  *
7  * gstquery.h: GstQuery API declaration
8  *
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.
13  *
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.
18  *
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., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25
26 #ifndef __GST_QUERY_H__
27 #define __GST_QUERY_H__
28
29 #include <glib.h>
30
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
37 G_BEGIN_DECLS
38
39 typedef struct _GstQuery GstQuery;
40
41 /**
42  * GstQueryTypeFlags:
43  * @GST_QUERY_TYPE_UPSTREAM:     Set if the query can travel upstream.
44  * @GST_QUERY_TYPE_DOWNSTREAM:   Set if the query can travel downstream.
45  * @GST_QUERY_TYPE_SERIALIZED:   Set if the query should be serialized with data
46  *                               flow.
47  *
48  * #GstQueryTypeFlags indicate the aspects of the different #GstQueryType
49  * values. You can get the type flags of a #GstQueryType with the
50  * gst_query_type_get_flags() function.
51  */
52 typedef enum {
53   GST_QUERY_TYPE_UPSTREAM       = 1 << 0,
54   GST_QUERY_TYPE_DOWNSTREAM     = 1 << 1,
55   GST_QUERY_TYPE_SERIALIZED     = 1 << 2
56 } GstQueryTypeFlags;
57
58 /**
59  * GST_QUERY_TYPE_BOTH:
60  *
61  * The same thing as #GST_QUERY_TYPE_UPSTREAM | #GST_QUERY_TYPE_DOWNSTREAM.
62  */
63 #define GST_QUERY_TYPE_BOTH \
64     (GST_QUERY_TYPE_UPSTREAM | GST_QUERY_TYPE_DOWNSTREAM)
65
66 #define GST_QUERY_NUM_SHIFT     (8)
67
68 /**
69  * GST_QUERY_MAKE_TYPE:
70  * @num: the query number to create
71  * @idx: the index in the sticky array
72  * @flags: the query flags
73  *
74  * when making custom query types, use this macro with the num and
75  * the given flags
76  */
77 #define GST_QUERY_MAKE_TYPE(num,flags) \
78     (((num) << GST_QUERY_NUM_SHIFT) | (flags))
79
80 #define FLAG(name) GST_QUERY_TYPE_##name
81
82
83 /**
84  * GstQueryType:
85  * @GST_QUERY_UNKNOWN: unknown query type
86  * @GST_QUERY_POSITION: current position in stream
87  * @GST_QUERY_DURATION: total duration of the stream
88  * @GST_QUERY_LATENCY: latency of stream
89  * @GST_QUERY_JITTER: current jitter of stream
90  * @GST_QUERY_RATE: current rate of the stream
91  * @GST_QUERY_SEEKING: seeking capabilities
92  * @GST_QUERY_SEGMENT: segment start/stop positions
93  * @GST_QUERY_CONVERT: convert values between formats
94  * @GST_QUERY_FORMATS: query supported formats for convert
95  * @GST_QUERY_BUFFERING: query available media for efficient seeking. Since
96  * 0.10.20.
97  * @GST_QUERY_CUSTOM: a custom application or element defined query. Since
98  * 0.10.22.
99  * @GST_QUERY_URI: query the URI of the source or sink. Since 0.10.22.
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  *
105  * Standard predefined Query types
106  */
107 /* NOTE: don't forget to update the table in gstquery.c when changing
108  * this enum */
109 typedef enum {
110   GST_QUERY_UNKNOWN      = GST_QUERY_MAKE_TYPE (0, 0),
111   GST_QUERY_POSITION     = GST_QUERY_MAKE_TYPE (10, FLAG(BOTH)),
112   GST_QUERY_DURATION     = GST_QUERY_MAKE_TYPE (20, FLAG(BOTH)),
113   GST_QUERY_LATENCY      = GST_QUERY_MAKE_TYPE (30, FLAG(BOTH)),
114   GST_QUERY_JITTER       = GST_QUERY_MAKE_TYPE (40, FLAG(BOTH)),
115   GST_QUERY_RATE         = GST_QUERY_MAKE_TYPE (50, FLAG(BOTH)),
116   GST_QUERY_SEEKING      = GST_QUERY_MAKE_TYPE (60, FLAG(BOTH)),
117   GST_QUERY_SEGMENT      = GST_QUERY_MAKE_TYPE (70, FLAG(BOTH)),
118   GST_QUERY_CONVERT      = GST_QUERY_MAKE_TYPE (80, FLAG(BOTH)),
119   GST_QUERY_FORMATS      = GST_QUERY_MAKE_TYPE (90, FLAG(BOTH)),
120   GST_QUERY_BUFFERING    = GST_QUERY_MAKE_TYPE (110, FLAG(BOTH)),
121   GST_QUERY_CUSTOM       = GST_QUERY_MAKE_TYPE (120, FLAG(BOTH)),
122   GST_QUERY_URI          = GST_QUERY_MAKE_TYPE (130, FLAG(BOTH)),
123   GST_QUERY_ALLOCATION   = GST_QUERY_MAKE_TYPE (140, FLAG(DOWNSTREAM) | FLAG(SERIALIZED)),
124   GST_QUERY_SCHEDULING   = GST_QUERY_MAKE_TYPE (150, FLAG(UPSTREAM)),
125   GST_QUERY_ACCEPT_CAPS  = GST_QUERY_MAKE_TYPE (160, FLAG(BOTH)),
126   GST_QUERY_CAPS         = GST_QUERY_MAKE_TYPE (170, FLAG(BOTH))
127 } GstQueryType;
128 #undef FLAG
129
130 #define GST_TYPE_QUERY                         (gst_query_get_type())
131 #define GST_IS_QUERY(obj)                      (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_QUERY))
132 #define GST_QUERY_CAST(obj)                    ((GstQuery*)(obj))
133 #define GST_QUERY(obj)                         (GST_QUERY_CAST(obj))
134
135 /**
136  * GST_QUERY_TYPE:
137  * @query: the query to query
138  *
139  * Get the #GstQueryType of the query.
140  */
141 #define GST_QUERY_TYPE(query)  (((GstQuery*)(query))->type)
142
143 /**
144  * GST_QUERY_TYPE_NAME:
145  * @query: the query to query
146  *
147  * Get a constant string representation of the #GstQueryType of the query.
148  *
149  * Since: 0.10.4
150  */
151 #define GST_QUERY_TYPE_NAME(query) (gst_query_type_get_name(GST_QUERY_TYPE(query)))
152
153 /**
154  * GST_QUERY_IS_UPSTREAM:
155  * @ev: the query to query
156  *
157  * Check if an query can travel upstream.
158  */
159 #define GST_QUERY_IS_UPSTREAM(ev)       !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_UPSTREAM)
160 /**
161  * GST_QUERY_IS_DOWNSTREAM:
162  * @ev: the query to query
163  *
164  * Check if an query can travel downstream.
165  */
166 #define GST_QUERY_IS_DOWNSTREAM(ev)     !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_DOWNSTREAM)
167 /**
168  * GST_QUERY_IS_SERIALIZED:
169  * @ev: the query to query
170  *
171  * Check if an query is serialized with the data stream.
172  */
173 #define GST_QUERY_IS_SERIALIZED(ev)     !!(GST_QUERY_TYPE (ev) & GST_QUERY_TYPE_SERIALIZED)
174
175
176 /**
177  * GstQuery:
178  * @mini_object: The parent #GstMiniObject type
179  * @type: the #GstQueryType
180  *
181  * The #GstQuery structure.
182  */
183 struct _GstQuery
184 {
185   GstMiniObject mini_object;
186
187   /*< public > *//* with COW */
188   GstQueryType type;
189 };
190
191 const gchar*    gst_query_type_get_name        (GstQueryType type);
192 GQuark          gst_query_type_to_quark        (GstQueryType type);
193 GstQueryTypeFlags
194                 gst_query_type_get_flags       (GstQueryType type);
195
196
197 GType           gst_query_get_type             (void);
198
199 /* refcounting */
200 /**
201  * gst_query_ref:
202  * @q: a #GstQuery to increase the refcount of.
203  *
204  * Increases the refcount of the given query by one.
205  *
206  * Returns: @q
207  */
208 #ifdef _FOOL_GTK_DOC_
209 G_INLINE_FUNC GstQuery * gst_query_ref (GstQuery * q);
210 #endif
211
212 static inline GstQuery *
213 gst_query_ref (GstQuery * q)
214 {
215   return GST_QUERY_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (q)));
216 }
217
218 /**
219  * gst_query_unref:
220  * @q: a #GstQuery to decrease the refcount of.
221  *
222  * Decreases the refcount of the query. If the refcount reaches 0, the query
223  * will be freed.
224  */
225 #ifdef _FOOL_GTK_DOC_
226 G_INLINE_FUNC void gst_query_unref (GstQuery * q);
227 #endif
228
229 static inline void
230 gst_query_unref (GstQuery * q)
231 {
232   gst_mini_object_unref (GST_MINI_OBJECT_CAST (q));
233 }
234
235 /* copy query */
236 /**
237  * gst_query_copy:
238  * @q: a #GstQuery to copy.
239  *
240  * Copies the given query using the copy function of the parent #GstStructure.
241  *
242  * Free-function: gst_query_unref
243  *
244  * Returns: (transfer full): a new copy of @q.
245  */
246 #ifdef _FOOL_GTK_DOC_
247 G_INLINE_FUNC GstQuery * gst_query_copy (const GstQuery * q);
248 #endif
249
250 static inline GstQuery *
251 gst_query_copy (const GstQuery * q)
252 {
253   return GST_QUERY_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (q)));
254 }
255
256 /**
257  * gst_query_is_writable:
258  * @q: a #GstQuery
259  *
260  * Tests if you can safely write data into a query's structure.
261  */
262 #define         gst_query_is_writable(q)     gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (q))
263 /**
264  * gst_query_make_writable:
265  * @q: (transfer full): a #GstQuery to make writable
266  *
267  * Makes a writable query from the given query.
268  *
269  * Returns: (transfer full): a new writable query (possibly same as @q)
270  */
271 #define         gst_query_make_writable(q)      GST_QUERY_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (q)))
272 /**
273  * gst_query_replace:
274  * @old_query: (inout) (transfer full): pointer to a pointer to a #GstQuery
275  *     to be replaced.
276  * @new_query: (allow-none) (transfer none): pointer to a #GstQuery that will
277  *     replace the query pointed to by @old_query.
278  *
279  * Modifies a pointer to a #GstQuery to point to a different #GstQuery. The
280  * modification is done atomically (so this is useful for ensuring thread safety
281  * in some cases), and the reference counts are updated appropriately (the old
282  * query is unreffed, the new one is reffed).
283  *
284  * Either @new_query or the #GstQuery pointed to by @old_query may be NULL.
285  *
286  * Returns: TRUE if @new_query was different from @old_query
287  */
288 #ifdef _FOOL_GTK_DOC_
289 G_INLINE_FUNC gboolean gst_query_replace (GstQuery **old_query, GstQuery *new_query);
290 #endif
291
292 static inline gboolean
293 gst_query_replace (GstQuery **old_query, GstQuery *new_query)
294 {
295   return gst_mini_object_replace ((GstMiniObject **) old_query, (GstMiniObject *) new_query);
296 }
297
298 /* application specific query */
299 GstQuery *      gst_query_new_custom            (GstQueryType type, GstStructure *structure) G_GNUC_MALLOC;
300 const GstStructure *
301                 gst_query_get_structure         (GstQuery *query);
302 GstStructure *  gst_query_writable_structure    (GstQuery *query);
303
304 /* position query */
305 GstQuery*       gst_query_new_position          (GstFormat format) G_GNUC_MALLOC;
306 void            gst_query_set_position          (GstQuery *query, GstFormat format, gint64 cur);
307 void            gst_query_parse_position        (GstQuery *query, GstFormat *format, gint64 *cur);
308
309 /* duration query */
310 GstQuery*       gst_query_new_duration          (GstFormat format) G_GNUC_MALLOC;
311 void            gst_query_set_duration          (GstQuery *query, GstFormat format, gint64 duration);
312 void            gst_query_parse_duration        (GstQuery *query, GstFormat *format, gint64 *duration);
313
314 /* latency query */
315 GstQuery*       gst_query_new_latency           (void) G_GNUC_MALLOC;
316 void            gst_query_set_latency           (GstQuery *query, gboolean live, GstClockTime min_latency,
317                                                  GstClockTime max_latency);
318 void            gst_query_parse_latency         (GstQuery *query, gboolean *live, GstClockTime *min_latency,
319                                                  GstClockTime *max_latency);
320
321 /* convert query */
322 GstQuery*       gst_query_new_convert           (GstFormat src_format, gint64 value, GstFormat dest_format) G_GNUC_MALLOC;
323 void            gst_query_set_convert           (GstQuery *query, GstFormat src_format, gint64 src_value,
324                                                  GstFormat dest_format, gint64 dest_value);
325 void            gst_query_parse_convert         (GstQuery *query, GstFormat *src_format, gint64 *src_value,
326                                                  GstFormat *dest_format, gint64 *dest_value);
327 /* segment query */
328 GstQuery*       gst_query_new_segment           (GstFormat format) G_GNUC_MALLOC;
329 void            gst_query_set_segment           (GstQuery *query, gdouble rate, GstFormat format,
330                                                  gint64 start_value, gint64 stop_value);
331 void            gst_query_parse_segment         (GstQuery *query, gdouble *rate, GstFormat *format,
332                                                  gint64 *start_value, gint64 *stop_value);
333
334 /* seeking query */
335 GstQuery*       gst_query_new_seeking           (GstFormat format) G_GNUC_MALLOC;
336 void            gst_query_set_seeking           (GstQuery *query, GstFormat format,
337                                                  gboolean seekable,
338                                                  gint64 segment_start,
339                                                  gint64 segment_end);
340 void            gst_query_parse_seeking         (GstQuery *query, GstFormat *format,
341                                                  gboolean *seekable,
342                                                  gint64 *segment_start,
343                                                  gint64 *segment_end);
344 /* formats query */
345 GstQuery*       gst_query_new_formats           (void) G_GNUC_MALLOC;
346 void            gst_query_set_formats           (GstQuery *query, gint n_formats, ...);
347 void            gst_query_set_formatsv          (GstQuery *query, gint n_formats, const GstFormat *formats);
348 void            gst_query_parse_n_formats       (GstQuery *query, guint *n_formats);
349 void            gst_query_parse_nth_format      (GstQuery *query, guint nth, GstFormat *format);
350
351 /* buffering query */
352 /**
353  * GstBufferingMode:
354  * @GST_BUFFERING_STREAM: a small amount of data is buffered
355  * @GST_BUFFERING_DOWNLOAD: the stream is being downloaded
356  * @GST_BUFFERING_TIMESHIFT: the stream is being downloaded in a ringbuffer
357  * @GST_BUFFERING_LIVE: the stream is a live stream
358  *
359  * The different types of buffering methods.
360  */
361 typedef enum {
362   GST_BUFFERING_STREAM,
363   GST_BUFFERING_DOWNLOAD,
364   GST_BUFFERING_TIMESHIFT,
365   GST_BUFFERING_LIVE
366 } GstBufferingMode;
367
368 GstQuery*       gst_query_new_buffering           (GstFormat format) G_GNUC_MALLOC;
369 void            gst_query_set_buffering_percent   (GstQuery *query, gboolean busy, gint percent);
370 void            gst_query_parse_buffering_percent (GstQuery *query, gboolean *busy, gint *percent);
371
372 void            gst_query_set_buffering_stats     (GstQuery *query, GstBufferingMode mode,
373                                                    gint avg_in, gint avg_out,
374                                                    gint64 buffering_left);
375 void            gst_query_parse_buffering_stats    (GstQuery *query, GstBufferingMode *mode,
376                                                    gint *avg_in, gint *avg_out,
377                                                    gint64 *buffering_left);
378
379 void            gst_query_set_buffering_range     (GstQuery *query, GstFormat format,
380                                                    gint64 start, gint64 stop,
381                                                    gint64 estimated_total);
382 void            gst_query_parse_buffering_range   (GstQuery *query, GstFormat *format,
383                                                    gint64 *start, gint64 *stop,
384                                                    gint64 *estimated_total);
385
386 gboolean        gst_query_add_buffering_range       (GstQuery *query,
387                                                      gint64 start, gint64 stop);
388 guint           gst_query_get_n_buffering_ranges    (GstQuery *query);
389 gboolean        gst_query_parse_nth_buffering_range (GstQuery *query,
390                                                      guint index, gint64 *start,
391                                                      gint64 *stop);
392
393 /* URI query */
394 GstQuery *      gst_query_new_uri                 (void) G_GNUC_MALLOC;
395 void            gst_query_parse_uri               (GstQuery *query, gchar **uri);
396 void            gst_query_set_uri                 (GstQuery *query, const gchar *uri);
397
398 /* allocation query */
399 GstQuery *      gst_query_new_allocation          (GstCaps *caps, gboolean need_pool) G_GNUC_MALLOC;
400 void            gst_query_parse_allocation        (GstQuery *query, GstCaps **caps, gboolean *need_pool);
401
402 void            gst_query_set_allocation_params   (GstQuery *query, guint size, guint min_buffers,
403                                                    guint max_buffers, guint prefix, guint alignment,
404                                                    GstBufferPool *pool);
405 void            gst_query_parse_allocation_params (GstQuery *query, guint *size, guint *min_buffers,
406                                                    guint *max_buffers, guint *prefix, guint *alignment,
407                                                    GstBufferPool **pool);
408
409 void            gst_query_add_allocation_meta        (GstQuery *query, GType api);
410 guint           gst_query_get_n_allocation_metas     (GstQuery *query);
411 GType           gst_query_parse_nth_allocation_meta  (GstQuery *query, guint index);
412 void            gst_query_remove_nth_allocation_meta (GstQuery *query, guint index);
413 gboolean        gst_query_has_allocation_meta        (GstQuery *query, GType api);
414
415 void            gst_query_add_allocation_memory       (GstQuery *query, GstAllocator *allocator);
416 guint           gst_query_get_n_allocation_memories   (GstQuery *query);
417 GstAllocator *  gst_query_parse_nth_allocation_memory (GstQuery *query, guint index);
418
419 /* scheduling query */
420 /**
421  * GstSchedulingFlags:
422  * @GST_SCHEDULING_FLAG_SEEKABLE: if seeking is possible
423  * @GST_SCHEDULING_FLAG_SEQUENTIAL: if sequential access is recommended
424  *
425  * The different scheduling flags.
426  */
427 typedef enum {
428   GST_SCHEDULING_FLAG_SEEKABLE      = (1 << 0),
429   GST_SCHEDULING_FLAG_SEQUENTIAL    = (1 << 1)
430 } GstSchedulingFlags;
431
432 GstQuery *      gst_query_new_scheduling          (void) G_GNUC_MALLOC;
433
434 void            gst_query_set_scheduling          (GstQuery *query, GstSchedulingFlags flags,
435                                                    gint minsize, gint maxsize, gint align);
436 void            gst_query_parse_scheduling        (GstQuery *query, GstSchedulingFlags *flags,
437                                                    gint *minsize, gint *maxsize, gint *align);
438
439 void            gst_query_add_scheduling_mode       (GstQuery *query, GstPadMode mode);
440 guint           gst_query_get_n_scheduling_modes    (GstQuery *query);
441 GstPadMode      gst_query_parse_nth_scheduling_mode (GstQuery *query, guint index);
442 gboolean        gst_query_has_scheduling_mode       (GstQuery *query, GstPadMode mode);
443
444 /* accept-caps query */
445 GstQuery *      gst_query_new_accept_caps          (GstCaps *caps) G_GNUC_MALLOC;
446 void            gst_query_parse_accept_caps        (GstQuery *query, GstCaps **caps);
447 void            gst_query_set_accept_caps_result   (GstQuery *query, gboolean result);
448 void            gst_query_parse_accept_caps_result (GstQuery *query, gboolean *result);
449
450 /* caps query */
451 GstQuery *      gst_query_new_caps                 (GstCaps *filter) G_GNUC_MALLOC;
452 void            gst_query_parse_caps               (GstQuery *query, GstCaps **filter);
453
454 void            gst_query_set_caps_result          (GstQuery *query, GstCaps *caps);
455 void            gst_query_parse_caps_result        (GstQuery *query, GstCaps **caps);
456
457 void            gst_query_intersect_caps_result    (GstQuery *query, GstCaps *filter,
458                                                     GstCapsIntersectMode mode);
459
460 G_END_DECLS
461
462 #endif /* __GST_QUERY_H__ */
463