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