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