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