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