query: add methods to query allocators
[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 /**
40  * GstQueryType:
41  * @GST_QUERY_NONE: invalid query type
42  * @GST_QUERY_POSITION: current position in stream
43  * @GST_QUERY_DURATION: total duration of the stream
44  * @GST_QUERY_LATENCY: latency of stream
45  * @GST_QUERY_JITTER: current jitter of stream
46  * @GST_QUERY_RATE: current rate of the stream
47  * @GST_QUERY_SEEKING: seeking capabilities
48  * @GST_QUERY_SEGMENT: segment start/stop positions
49  * @GST_QUERY_CONVERT: convert values between formats
50  * @GST_QUERY_FORMATS: query supported formats for convert
51  * @GST_QUERY_BUFFERING: query available media for efficient seeking. Since
52  * 0.10.20.
53  * @GST_QUERY_CUSTOM: a custom application or element defined query. Since
54  * 0.10.22.
55  * @GST_QUERY_URI: query the URI of the source or sink. Since 0.10.22.
56  * @GST_QUERY_ALLOCATION: the buffer allocation properties
57  * @GST_QUERY_SCHEDULING: the scheduling properties
58  *
59  * Standard predefined Query types
60  */
61 /* NOTE: don't forget to update the table in gstquery.c when changing
62  * this enum */
63 typedef enum {
64   GST_QUERY_NONE = 0,
65   GST_QUERY_POSITION,
66   GST_QUERY_DURATION,
67   GST_QUERY_LATENCY,
68   GST_QUERY_JITTER,     /* not in draft-query, necessary? */
69   GST_QUERY_RATE,
70   GST_QUERY_SEEKING,
71   GST_QUERY_SEGMENT,
72   GST_QUERY_CONVERT,
73   GST_QUERY_FORMATS,
74   GST_QUERY_BUFFERING,
75   GST_QUERY_CUSTOM,
76   GST_QUERY_URI,
77   GST_QUERY_ALLOCATION,
78   GST_QUERY_SCHEDULING
79 } GstQueryType;
80
81 /**
82  * GstBufferingMode:
83  * @GST_BUFFERING_STREAM: a small amount of data is buffered
84  * @GST_BUFFERING_DOWNLOAD: the stream is being downloaded
85  * @GST_BUFFERING_TIMESHIFT: the stream is being downloaded in a ringbuffer
86  * @GST_BUFFERING_LIVE: the stream is a live stream
87  *
88  * The different types of buffering methods.
89  */
90 typedef enum {
91   GST_BUFFERING_STREAM,
92   GST_BUFFERING_DOWNLOAD,
93   GST_BUFFERING_TIMESHIFT,
94   GST_BUFFERING_LIVE
95 } GstBufferingMode;
96
97 typedef struct _GstQueryTypeDefinition GstQueryTypeDefinition;
98 typedef struct _GstQuery GstQuery;
99
100 /**
101  * GstQueryTypeDefinition:
102  * @value: the unique id of the Query type
103  * @nick: a short nick
104  * @description: a longer description of the query type
105  * @quark: the quark for the nick
106  *
107  * A Query Type definition
108  */
109 struct _GstQueryTypeDefinition
110 {
111   GstQueryType   value;
112   const gchar   *nick;
113   const gchar   *description;
114   GQuark         quark;
115 };
116
117 #define GST_TYPE_QUERY                         (gst_query_get_type())
118 #define GST_IS_QUERY(obj)                      (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_QUERY))
119 #define GST_QUERY_CAST(obj)                    ((GstQuery*)(obj))
120 #define GST_QUERY(obj)                         (GST_QUERY_CAST(obj))
121
122
123 /**
124  * GST_QUERY_TYPE:
125  * @query: the query to query
126  *
127  * Get the #GstQueryType of the query.
128  */
129 #define GST_QUERY_TYPE(query)  (((GstQuery*)(query))->type)
130
131 /**
132  * GST_QUERY_TYPE_NAME:
133  * @query: the query to query
134  *
135  * Get a constant string representation of the #GstQueryType of the query.
136  *
137  * Since: 0.10.4
138  */
139 #define GST_QUERY_TYPE_NAME(query) (gst_query_type_get_name(GST_QUERY_TYPE(query)))
140
141
142 /**
143  * GstQuery:
144  * @mini_object: The parent #GstMiniObject type
145  * @type: the #GstQueryType
146  *
147  * The #GstQuery structure.
148  */
149 struct _GstQuery
150 {
151   GstMiniObject mini_object;
152
153   /*< public > *//* with COW */
154   GstQueryType type;
155 };
156
157 const gchar*    gst_query_type_get_name        (GstQueryType query);
158 GQuark          gst_query_type_to_quark        (GstQueryType query);
159
160 GType           gst_query_get_type             (void);
161
162 /* register a new query */
163 GstQueryType    gst_query_type_register        (const gchar *nick,
164                                                 const gchar *description);
165 GstQueryType    gst_query_type_get_by_nick     (const gchar *nick);
166
167 /* check if a query is in an array of querys */
168 gboolean        gst_query_types_contains       (const GstQueryType *types,
169                                                 GstQueryType type);
170
171 /* query for query details */
172
173 G_CONST_RETURN GstQueryTypeDefinition*
174                 gst_query_type_get_details         (GstQueryType type);
175 GstIterator*    gst_query_type_iterate_definitions (void);
176
177 /* refcounting */
178 /**
179  * gst_query_ref:
180  * @q: a #GstQuery to increase the refcount of.
181  *
182  * Increases the refcount of the given query by one.
183  *
184  * Returns: @q
185  */
186 #ifdef _FOOL_GTK_DOC_
187 G_INLINE_FUNC GstQuery * gst_query_ref (GstQuery * q);
188 #endif
189
190 static inline GstQuery *
191 gst_query_ref (GstQuery * q)
192 {
193   return GST_QUERY_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (q)));
194 }
195
196 /**
197  * gst_query_unref:
198  * @q: a #GstQuery to decrease the refcount of.
199  *
200  * Decreases the refcount of the query. If the refcount reaches 0, the query
201  * will be freed.
202  */
203 #ifdef _FOOL_GTK_DOC_
204 G_INLINE_FUNC void gst_query_unref (GstQuery * q);
205 #endif
206
207 static inline void
208 gst_query_unref (GstQuery * q)
209 {
210   gst_mini_object_unref (GST_MINI_OBJECT_CAST (q));
211 }
212
213 /* copy query */
214 /**
215  * gst_query_copy:
216  * @q: a #GstQuery to copy.
217  *
218  * Copies the given query using the copy function of the parent #GstStructure.
219  *
220  * Free-function: gst_query_unref
221  *
222  * Returns: (transfer full): a new copy of @q.
223  */
224 #ifdef _FOOL_GTK_DOC_
225 G_INLINE_FUNC GstQuery * gst_query_copy (const GstQuery * q);
226 #endif
227
228 static inline GstQuery *
229 gst_query_copy (const GstQuery * q)
230 {
231   return GST_QUERY_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (q)));
232 }
233
234 /**
235  * gst_query_is_writable:
236  * @q: a #GstQuery
237  *
238  * Tests if you can safely write data into a query's structure.
239  */
240 #define         gst_query_is_writable(q)     gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (q))
241 /**
242  * gst_query_make_writable:
243  * @q: (transfer full): a #GstQuery to make writable
244  *
245  * Makes a writable query from the given query.
246  *
247  * Returns: (transfer full): a new writable query (possibly same as @q)
248  */
249 #define         gst_query_make_writable(q)      GST_QUERY_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (q)))
250 /**
251  * gst_query_replace:
252  * @old_query: (inout) (transfer full): pointer to a pointer to a #GstQuery
253  *     to be replaced.
254  * @new_query: (allow-none) (transfer none): pointer to a #GstQuery that will
255  *     replace the query pointed to by @old_query.
256  *
257  * Modifies a pointer to a #GstQuery to point to a different #GstQuery. The
258  * modification is done atomically (so this is useful for ensuring thread safety
259  * in some cases), and the reference counts are updated appropriately (the old
260  * query is unreffed, the new one is reffed).
261  *
262  * Either @new_query or the #GstQuery pointed to by @old_query may be NULL.
263  */
264 #define         gst_query_replace(old_query,new_query) \
265     gst_mini_object_replace ((GstMiniObject **)(old_query), GST_MINI_OBJECT_CAST (new_query))
266
267
268 /* application specific query */
269 GstQuery *      gst_query_new_custom            (GstQueryType type, GstStructure *structure);
270 const GstStructure *
271                 gst_query_get_structure         (GstQuery *query);
272 GstStructure *  gst_query_writable_structure    (GstQuery *query);
273
274 /* position query */
275 GstQuery*       gst_query_new_position          (GstFormat format);
276 void            gst_query_set_position          (GstQuery *query, GstFormat format, gint64 cur);
277 void            gst_query_parse_position        (GstQuery *query, GstFormat *format, gint64 *cur);
278
279 /* duration query */
280 GstQuery*       gst_query_new_duration          (GstFormat format);
281 void            gst_query_set_duration          (GstQuery *query, GstFormat format, gint64 duration);
282 void            gst_query_parse_duration        (GstQuery *query, GstFormat *format, gint64 *duration);
283
284 /* latency query */
285 GstQuery*       gst_query_new_latency           (void);
286 void            gst_query_set_latency           (GstQuery *query, gboolean live, GstClockTime min_latency,
287                                                  GstClockTime max_latency);
288 void            gst_query_parse_latency         (GstQuery *query, gboolean *live, GstClockTime *min_latency,
289                                                  GstClockTime *max_latency);
290
291 /* convert query */
292 GstQuery*       gst_query_new_convert           (GstFormat src_format, gint64 value, GstFormat dest_format);
293 void            gst_query_set_convert           (GstQuery *query, GstFormat src_format, gint64 src_value,
294                                                  GstFormat dest_format, gint64 dest_value);
295 void            gst_query_parse_convert         (GstQuery *query, GstFormat *src_format, gint64 *src_value,
296                                                  GstFormat *dest_format, gint64 *dest_value);
297 /* segment query */
298 GstQuery*       gst_query_new_segment           (GstFormat format);
299 void            gst_query_set_segment           (GstQuery *query, gdouble rate, GstFormat format,
300                                                  gint64 start_value, gint64 stop_value);
301 void            gst_query_parse_segment         (GstQuery *query, gdouble *rate, GstFormat *format,
302                                                  gint64 *start_value, gint64 *stop_value);
303
304 /* seeking query */
305 GstQuery*       gst_query_new_seeking           (GstFormat format);
306 void            gst_query_set_seeking           (GstQuery *query, GstFormat format,
307                                                  gboolean seekable,
308                                                  gint64 segment_start,
309                                                  gint64 segment_end);
310 void            gst_query_parse_seeking         (GstQuery *query, GstFormat *format,
311                                                  gboolean *seekable,
312                                                  gint64 *segment_start,
313                                                  gint64 *segment_end);
314 /* formats query */
315 GstQuery*       gst_query_new_formats           (void);
316 void            gst_query_set_formats           (GstQuery *query, gint n_formats, ...);
317 void            gst_query_set_formatsv          (GstQuery *query, gint n_formats, const GstFormat *formats);
318 void            gst_query_parse_n_formats       (GstQuery *query, guint *n_formats);
319 void            gst_query_parse_nth_format      (GstQuery *query, guint nth, GstFormat *format);
320
321 /* buffering query */
322 GstQuery*       gst_query_new_buffering           (GstFormat format);
323 void            gst_query_set_buffering_percent   (GstQuery *query, gboolean busy, gint percent);
324 void            gst_query_parse_buffering_percent (GstQuery *query, gboolean *busy, gint *percent);
325
326 void            gst_query_set_buffering_stats     (GstQuery *query, GstBufferingMode mode,
327                                                    gint avg_in, gint avg_out,
328                                                    gint64 buffering_left);
329 void            gst_query_parse_buffering_stats    (GstQuery *query, GstBufferingMode *mode,
330                                                    gint *avg_in, gint *avg_out,
331                                                    gint64 *buffering_left);
332
333 void            gst_query_set_buffering_range     (GstQuery *query, GstFormat format,
334                                                    gint64 start, gint64 stop,
335                                                    gint64 estimated_total);
336 void            gst_query_parse_buffering_range   (GstQuery *query, GstFormat *format,
337                                                    gint64 *start, gint64 *stop,
338                                                    gint64 *estimated_total);
339
340 gboolean        gst_query_add_buffering_range       (GstQuery *query,
341                                                      gint64 start, gint64 stop);
342 guint           gst_query_get_n_buffering_ranges    (GstQuery *query);
343 gboolean        gst_query_parse_nth_buffering_range (GstQuery *query,
344                                                      guint index, gint64 *start,
345                                                      gint64 *stop);
346
347 /* URI query */
348 GstQuery *      gst_query_new_uri                 (void);
349 void            gst_query_parse_uri               (GstQuery *query, gchar **uri);
350 void            gst_query_set_uri                 (GstQuery *query, const gchar *uri);
351
352 /* allocation query */
353 GstQuery *      gst_query_new_allocation          (GstCaps *caps, gboolean need_pool);
354 void            gst_query_parse_allocation        (GstQuery *query, GstCaps **caps, gboolean *need_pool);
355
356 void            gst_query_set_allocation_params   (GstQuery *query, guint size, guint min_buffers,
357                                                    guint max_buffers, guint prefix, guint alignment,
358                                                    GstBufferPool *pool);
359 void            gst_query_parse_allocation_params (GstQuery *query, guint *size, guint *min_buffers,
360                                                    guint *max_buffers, guint *prefix, guint *alignment,
361                                                    GstBufferPool **pool);
362
363 void            gst_query_add_allocation_meta       (GstQuery *query, const gchar *api);
364 guint           gst_query_get_n_allocation_metas    (GstQuery *query);
365 const gchar *   gst_query_parse_nth_allocation_meta (GstQuery *query, guint index);
366
367 void            gst_query_add_allocation_memory       (GstQuery *query, const gchar *alloc);
368 guint           gst_query_get_n_allocation_memories   (GstQuery *query);
369 const gchar *   gst_query_parse_nth_allocation_memory (GstQuery *query, guint index);
370
371 /* scheduling query */
372 GstQuery *      gst_query_new_scheduling          (void);
373
374 void            gst_query_set_scheduling          (GstQuery *query, gboolean pull_mode,
375                                                    gboolean random_access, gboolean sequential,
376                                                    gint minsize, gint maxsize, gint align);
377 void            gst_query_parse_scheduling        (GstQuery *query, gboolean *pull_mode,
378                                                    gboolean *random_access, gboolean *sequential,
379                                                    gint *minsize, gint *maxsize, gint *align);
380
381 G_END_DECLS
382
383 #endif /* __GST_QUERY_H__ */
384