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