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