Add new TOC 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  *
6  * gstquery.h: GstQuery API declaration
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24
25 #ifndef __GST_QUERY_H__
26 #define __GST_QUERY_H__
27
28 #include <glib.h>
29
30 #include <gst/gstiterator.h>
31 #include <gst/gstminiobject.h>
32 #include <gst/gststructure.h>
33 #include <gst/gstformat.h>
34
35 G_BEGIN_DECLS
36
37 /**
38  * GstQueryType:
39  * @GST_QUERY_NONE: invalid query type
40  * @GST_QUERY_POSITION: current position in stream
41  * @GST_QUERY_DURATION: total duration of the stream
42  * @GST_QUERY_LATENCY: latency of stream
43  * @GST_QUERY_JITTER: current jitter of stream
44  * @GST_QUERY_RATE: current rate of the stream
45  * @GST_QUERY_SEEKING: seeking capabilities
46  * @GST_QUERY_SEGMENT: segment start/stop positions
47  * @GST_QUERY_CONVERT: convert values between formats
48  * @GST_QUERY_FORMATS: query supported formats for convert
49  * @GST_QUERY_BUFFERING: query available media for efficient seeking. Since
50  * 0.10.20.
51  * @GST_QUERY_CUSTOM: a custom application or element defined query. Since
52  * 0.10.22.
53  * @GST_QUERY_URI: query the URI of the source or sink. Since 0.10.22.
54  * @GST_QUERY_TOC: query the full table of contents (TOC) with the marker
55  * for an entry which can be used to extend received TOC. Since 0.10.37.
56  *
57  * Standard predefined Query types
58  */
59 /* NOTE: don't forget to update the table in gstquery.c when changing
60  * this enum */
61 typedef enum {
62   GST_QUERY_NONE = 0,
63   GST_QUERY_POSITION,
64   GST_QUERY_DURATION,
65   GST_QUERY_LATENCY,
66   GST_QUERY_JITTER,     /* not in draft-query, necessary? */
67   GST_QUERY_RATE,
68   GST_QUERY_SEEKING,
69   GST_QUERY_SEGMENT,
70   GST_QUERY_CONVERT,
71   GST_QUERY_FORMATS,
72   GST_QUERY_BUFFERING,
73   GST_QUERY_CUSTOM,
74   GST_QUERY_URI,
75   GST_QUERY_TOC
76 } GstQueryType;
77
78 /**
79  * GstBufferingMode:
80  * @GST_BUFFERING_STREAM: a small amount of data is buffered
81  * @GST_BUFFERING_DOWNLOAD: the stream is being downloaded
82  * @GST_BUFFERING_TIMESHIFT: the stream is being downloaded in a ringbuffer
83  * @GST_BUFFERING_LIVE: the stream is a live stream
84  *
85  * The different types of buffering methods.
86  */
87 typedef enum {
88   GST_BUFFERING_STREAM,
89   GST_BUFFERING_DOWNLOAD,
90   GST_BUFFERING_TIMESHIFT,
91   GST_BUFFERING_LIVE
92 } GstBufferingMode;
93
94 typedef struct _GstQueryTypeDefinition GstQueryTypeDefinition;
95 typedef struct _GstQuery GstQuery;
96 typedef struct _GstQueryClass GstQueryClass;
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)                      (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_QUERY))
117 #define GST_IS_QUERY_CLASS(klass)              (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_QUERY))
118 #define GST_QUERY_GET_CLASS(obj)               (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_QUERY, GstQueryClass))
119 #define GST_QUERY(obj)                         (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_QUERY, GstQuery))
120 #define GST_QUERY_CAST(obj)                    ((GstQuery*)(obj)) /* only since 0.10.23 */
121 #define GST_QUERY_CLASS(klass)                 (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_QUERY, GstQueryClass))
122
123
124 /**
125  * GST_QUERY_TYPE:
126  * @query: the query to query
127  *
128  * Get the #GstQueryType of the query.
129  */
130 #define GST_QUERY_TYPE(query)  (((GstQuery*)(query))->type)
131
132 /**
133  * GST_QUERY_TYPE_NAME:
134  * @query: the query to query
135  *
136  * Get a constant string representation of the #GstQueryType of the query.
137  *
138  * Since: 0.10.4
139  */
140 #define GST_QUERY_TYPE_NAME(query) (gst_query_type_get_name(GST_QUERY_TYPE(query)))
141
142
143 /**
144  * GstQuery:
145  * @mini_object: The parent #GstMiniObject type
146  * @type: the #GstQueryType
147  * @structure: the #GstStructure containing the query details.
148  *
149  * The #GstQuery structure.
150  */
151 struct _GstQuery
152 {
153   GstMiniObject mini_object;
154
155   /*< public > *//* with COW */
156   GstQueryType type;
157
158   GstStructure *structure;
159
160   /*< private >*/
161   gpointer _gst_reserved;
162 };
163
164 struct _GstQueryClass {
165   GstMiniObjectClass mini_object_class;
166
167   /*< private >*/
168   gpointer _gst_reserved[GST_PADDING];
169 };
170
171 const gchar*    gst_query_type_get_name        (GstQueryType query);
172 GQuark          gst_query_type_to_quark        (GstQueryType query);
173
174 GType           gst_query_get_type             (void);
175
176 /* register a new query */
177 GstQueryType    gst_query_type_register        (const gchar *nick,
178                                                 const gchar *description);
179 GstQueryType    gst_query_type_get_by_nick     (const gchar *nick);
180
181 /* check if a query is in an array of querys */
182 gboolean        gst_query_types_contains       (const GstQueryType *types,
183                                                 GstQueryType type);
184
185 /* query for query details */
186
187 const GstQueryTypeDefinition*
188                 gst_query_type_get_details         (GstQueryType type);
189 GstIterator*    gst_query_type_iterate_definitions (void) G_GNUC_MALLOC;
190
191 /* refcounting */
192 /**
193  * gst_query_ref:
194  * @q: a #GstQuery to increase the refcount of.
195  *
196  * Increases the refcount of the given query by one.
197  *
198  * Returns: @q
199  */
200 #ifdef _FOOL_GTK_DOC_
201 G_INLINE_FUNC GstQuery * gst_query_ref (GstQuery * q);
202 #endif
203
204 static inline GstQuery *
205 gst_query_ref (GstQuery * q)
206 {
207   return GST_QUERY_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (q)));
208 }
209
210 /**
211  * gst_query_unref:
212  * @q: a #GstQuery to decrease the refcount of.
213  *
214  * Decreases the refcount of the query. If the refcount reaches 0, the query
215  * will be freed.
216  */
217 #ifdef _FOOL_GTK_DOC_
218 G_INLINE_FUNC void gst_query_unref (GstQuery * q);
219 #endif
220
221 static inline void
222 gst_query_unref (GstQuery * q)
223 {
224   gst_mini_object_unref (GST_MINI_OBJECT_CAST (q));
225 }
226
227 /* copy query */
228 /**
229  * gst_query_copy:
230  * @q: a #GstQuery to copy.
231  *
232  * Copies the given query using the copy function of the parent #GstStructure.
233  *
234  * Free-function: gst_query_unref
235  *
236  * Returns: (transfer full): a new copy of @q.
237  */
238 #ifdef _FOOL_GTK_DOC_
239 G_INLINE_FUNC GstQuery * gst_query_copy (const GstQuery * q);
240 #endif
241
242 static inline GstQuery *
243 gst_query_copy (const GstQuery * q)
244 {
245   return GST_QUERY_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (q)));
246 }
247
248 /**
249  * gst_query_make_writable:
250  * @q: (transfer full): a #GstQuery to make writable
251  *
252  * Makes a writable query from the given query.
253  *
254  * Returns: (transfer full): a new writable query (possibly same as @q)
255  */
256 #define         gst_query_make_writable(q)      GST_QUERY_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (q)))
257
258 /* position query */
259 GstQuery*       gst_query_new_position          (GstFormat format) G_GNUC_MALLOC;
260 void            gst_query_set_position          (GstQuery *query, GstFormat format, gint64 cur);
261 void            gst_query_parse_position        (GstQuery *query, GstFormat *format, gint64 *cur);
262
263 /* duration query */
264 GstQuery*       gst_query_new_duration          (GstFormat format) G_GNUC_MALLOC;
265 void            gst_query_set_duration          (GstQuery *query, GstFormat format, gint64 duration);
266 void            gst_query_parse_duration        (GstQuery *query, GstFormat *format, gint64 *duration);
267
268 /* latency query */
269 GstQuery*       gst_query_new_latency           (void) G_GNUC_MALLOC;
270 void            gst_query_set_latency           (GstQuery *query, gboolean live, GstClockTime min_latency,
271                                                  GstClockTime max_latency);
272 void            gst_query_parse_latency         (GstQuery *query, gboolean *live, GstClockTime *min_latency,
273                                                  GstClockTime *max_latency);
274
275 /* convert query */
276 GstQuery*       gst_query_new_convert           (GstFormat src_format, gint64 value, GstFormat dest_format) G_GNUC_MALLOC;
277 void            gst_query_set_convert           (GstQuery *query, GstFormat src_format, gint64 src_value,
278                                                  GstFormat dest_format, gint64 dest_value);
279 void            gst_query_parse_convert         (GstQuery *query, GstFormat *src_format, gint64 *src_value,
280                                                  GstFormat *dest_format, gint64 *dest_value);
281 /* segment query */
282 GstQuery*       gst_query_new_segment           (GstFormat format) G_GNUC_MALLOC;
283 void            gst_query_set_segment           (GstQuery *query, gdouble rate, GstFormat format,
284                                                  gint64 start_value, gint64 stop_value);
285 void            gst_query_parse_segment         (GstQuery *query, gdouble *rate, GstFormat *format,
286                                                  gint64 *start_value, gint64 *stop_value);
287
288 /* application specific query */
289 GstQuery *      gst_query_new_application       (GstQueryType type,
290                                                  GstStructure *structure) G_GNUC_MALLOC;
291 GstStructure *  gst_query_get_structure         (GstQuery *query);
292
293 /* seeking query */
294 GstQuery*       gst_query_new_seeking           (GstFormat format) G_GNUC_MALLOC;
295 void            gst_query_set_seeking           (GstQuery *query, GstFormat format,
296                                                  gboolean seekable,
297                                                  gint64 segment_start,
298                                                  gint64 segment_end);
299 void            gst_query_parse_seeking         (GstQuery *query, GstFormat *format,
300                                                  gboolean *seekable,
301                                                  gint64 *segment_start,
302                                                  gint64 *segment_end);
303 /* formats query */
304 GstQuery*       gst_query_new_formats           (void) G_GNUC_MALLOC;
305 void            gst_query_set_formats           (GstQuery *query, gint n_formats, ...);
306 void            gst_query_set_formatsv          (GstQuery *query, gint n_formats, const GstFormat *formats);
307 void            gst_query_parse_formats_length  (GstQuery *query, guint *n_formats);
308 void            gst_query_parse_formats_nth     (GstQuery *query, guint nth, GstFormat *format);
309
310 /* buffering query */
311 GstQuery*       gst_query_new_buffering           (GstFormat format) G_GNUC_MALLOC;
312 void            gst_query_set_buffering_percent   (GstQuery *query, gboolean busy, gint percent);
313 void            gst_query_parse_buffering_percent (GstQuery *query, gboolean *busy, gint *percent);
314
315 void            gst_query_set_buffering_stats     (GstQuery *query, GstBufferingMode mode,
316                                                    gint avg_in, gint avg_out,
317                                                    gint64 buffering_left);
318 void            gst_query_parse_buffering_stats    (GstQuery *query, GstBufferingMode *mode,
319                                                    gint *avg_in, gint *avg_out,
320                                                    gint64 *buffering_left);
321
322 void            gst_query_set_buffering_range     (GstQuery *query, GstFormat format,
323                                                    gint64 start, gint64 stop,
324                                                    gint64 estimated_total);
325 void            gst_query_parse_buffering_range   (GstQuery *query, GstFormat *format,
326                                                    gint64 *start, gint64 *stop,
327                                                    gint64 *estimated_total);
328 gboolean        gst_query_add_buffering_range     (GstQuery *query,
329                                                    gint64 start, gint64 stop);
330
331 guint           gst_query_get_n_buffering_ranges  (GstQuery *query);
332
333 gboolean        gst_query_parse_nth_buffering_range (GstQuery *query,
334                                                      guint index, gint64 *start,
335                                                      gint64 *stop);
336
337 /* URI query */
338 GstQuery *      gst_query_new_uri                 (void) G_GNUC_MALLOC;
339 void            gst_query_parse_uri               (GstQuery *query, gchar **uri);
340 void            gst_query_set_uri                 (GstQuery *query, const gchar *uri);
341
342 /* TOC query */
343 GstQuery *      gst_query_new_toc                 (void);
344 void            gst_query_set_toc                 (GstQuery *query, GstToc *toc, const gchar *extend_uid);
345 void            gst_query_parse_toc               (GstQuery *query, GstToc **toc, gchar **extend_uid);
346
347 G_END_DECLS
348
349 #endif /* __GST_QUERY_H__ */
350