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