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 */
25 #ifndef __GST_QUERY_H__
26 #define __GST_QUERY_H__
28 #include <glib.h>
30 #include <gst/gstiterator.h>
31 #include <gst/gstminiobject.h>
32 #include <gst/gststructure.h>
33 #include <gst/gstformat.h>
35 G_BEGIN_DECLS
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 *
55 * Standard predefined Query types
56 */
57 /* NOTE: don't forget to update the table in gstquery.c when changing
58 * this enum */
59 typedef enum {
60 GST_QUERY_NONE = 0,
61 GST_QUERY_POSITION,
62 GST_QUERY_DURATION,
63 GST_QUERY_LATENCY,
64 GST_QUERY_JITTER, /* not in draft-query, necessary? */
65 GST_QUERY_RATE,
66 GST_QUERY_SEEKING,
67 GST_QUERY_SEGMENT,
68 GST_QUERY_CONVERT,
69 GST_QUERY_FORMATS,
70 GST_QUERY_BUFFERING,
71 GST_QUERY_CUSTOM,
72 GST_QUERY_URI
73 } GstQueryType;
75 /**
76 * GstBufferingMode:
77 * @GST_BUFFERING_STREAM: a small amount of data is buffered
78 * @GST_BUFFERING_DOWNLOAD: the stream is being downloaded
79 * @GST_BUFFERING_TIMESHIFT: the stream is being downloaded in a ringbuffer
80 * @GST_BUFFERING_LIVE: the stream is a live stream
81 *
82 * The different types of buffering methods.
83 */
84 typedef enum {
85 GST_BUFFERING_STREAM,
86 GST_BUFFERING_DOWNLOAD,
87 GST_BUFFERING_TIMESHIFT,
88 GST_BUFFERING_LIVE
89 } GstBufferingMode;
91 typedef struct _GstQueryTypeDefinition GstQueryTypeDefinition;
92 typedef struct _GstQuery GstQuery;
93 typedef struct _GstQueryClass GstQueryClass;
95 /**
96 * GstQueryTypeDefinition:
97 * @value: the unique id of the Query type
98 * @nick: a short nick
99 * @description: a longer description of the query type
100 * @quark: the quark for the nick
101 *
102 * A Query Type definition
103 */
104 struct _GstQueryTypeDefinition
105 {
106 GstQueryType value;
107 const gchar *nick;
108 const gchar *description;
109 GQuark quark;
110 };
112 #define GST_TYPE_QUERY (gst_query_get_type())
113 #define GST_IS_QUERY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_QUERY))
114 #define GST_IS_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_QUERY))
115 #define GST_QUERY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_QUERY, GstQueryClass))
116 #define GST_QUERY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_QUERY, GstQuery))
117 #define GST_QUERY_CAST(obj) ((GstQuery*)(obj)) /* only since 0.10.23 */
118 #define GST_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_QUERY, GstQueryClass))
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)
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)))
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;
152 /*< public > *//* with COW */
153 GstQueryType type;
155 GstStructure *structure;
157 /*< private >*/
158 gpointer _gst_reserved;
159 };
161 struct _GstQueryClass {
162 GstMiniObjectClass mini_object_class;
164 /*< private >*/
165 gpointer _gst_reserved[GST_PADDING];
166 };
168 const gchar* gst_query_type_get_name (GstQueryType query);
169 GQuark gst_query_type_to_quark (GstQueryType query);
171 GType gst_query_get_type (void);
173 /* register a new query */
174 GstQueryType gst_query_type_register (const gchar *nick,
175 const gchar *description);
176 GstQueryType gst_query_type_get_by_nick (const gchar *nick);
178 /* check if a query is in an array of querys */
179 gboolean gst_query_types_contains (const GstQueryType *types,
180 GstQueryType type);
182 /* query for query details */
184 const GstQueryTypeDefinition*
185 gst_query_type_get_details (GstQueryType type);
186 GstIterator* gst_query_type_iterate_definitions (void) G_GNUC_MALLOC;
188 /* refcounting */
189 /**
190 * gst_query_ref:
191 * @q: a #GstQuery to increase the refcount of.
192 *
193 * Increases the refcount of the given query by one.
194 *
195 * Returns: @q
196 */
197 #ifdef _FOOL_GTK_DOC_
198 G_INLINE_FUNC GstQuery * gst_query_ref (GstQuery * q);
199 #endif
201 static inline GstQuery *
202 gst_query_ref (GstQuery * q)
203 {
204 return GST_QUERY_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (q)));
205 }
207 /**
208 * gst_query_unref:
209 * @q: a #GstQuery to decrease the refcount of.
210 *
211 * Decreases the refcount of the query. If the refcount reaches 0, the query
212 * will be freed.
213 */
214 #ifdef _FOOL_GTK_DOC_
215 G_INLINE_FUNC void gst_query_unref (GstQuery * q);
216 #endif
218 static inline void
219 gst_query_unref (GstQuery * q)
220 {
221 gst_mini_object_unref (GST_MINI_OBJECT_CAST (q));
222 }
224 /* copy query */
225 /**
226 * gst_query_copy:
227 * @q: a #GstQuery to copy.
228 *
229 * Copies the given query using the copy function of the parent #GstStructure.
230 *
231 * Free-function: gst_query_unref
232 *
233 * Returns: (transfer full): a new copy of @q.
234 */
235 #ifdef _FOOL_GTK_DOC_
236 G_INLINE_FUNC GstQuery * gst_query_copy (const GstQuery * q);
237 #endif
239 static inline GstQuery *
240 gst_query_copy (const GstQuery * q)
241 {
242 return GST_QUERY_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (q)));
243 }
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)))
255 /* position query */
256 GstQuery* gst_query_new_position (GstFormat format) G_GNUC_MALLOC;
257 void gst_query_set_position (GstQuery *query, GstFormat format, gint64 cur);
258 void gst_query_parse_position (GstQuery *query, GstFormat *format, gint64 *cur);
260 /* duration query */
261 GstQuery* gst_query_new_duration (GstFormat format) G_GNUC_MALLOC;
262 void gst_query_set_duration (GstQuery *query, GstFormat format, gint64 duration);
263 void gst_query_parse_duration (GstQuery *query, GstFormat *format, gint64 *duration);
265 /* latency query */
266 GstQuery* gst_query_new_latency (void) G_GNUC_MALLOC;
267 void gst_query_set_latency (GstQuery *query, gboolean live, GstClockTime min_latency,
268 GstClockTime max_latency);
269 void gst_query_parse_latency (GstQuery *query, gboolean *live, GstClockTime *min_latency,
270 GstClockTime *max_latency);
272 /* convert query */
273 GstQuery* gst_query_new_convert (GstFormat src_format, gint64 value, GstFormat dest_format) G_GNUC_MALLOC;
274 void gst_query_set_convert (GstQuery *query, GstFormat src_format, gint64 src_value,
275 GstFormat dest_format, gint64 dest_value);
276 void gst_query_parse_convert (GstQuery *query, GstFormat *src_format, gint64 *src_value,
277 GstFormat *dest_format, gint64 *dest_value);
278 /* segment query */
279 GstQuery* gst_query_new_segment (GstFormat format) G_GNUC_MALLOC;
280 void gst_query_set_segment (GstQuery *query, gdouble rate, GstFormat format,
281 gint64 start_value, gint64 stop_value);
282 void gst_query_parse_segment (GstQuery *query, gdouble *rate, GstFormat *format,
283 gint64 *start_value, gint64 *stop_value);
285 /* application specific query */
286 GstQuery * gst_query_new_application (GstQueryType type,
287 GstStructure *structure) G_GNUC_MALLOC;
288 GstStructure * gst_query_get_structure (GstQuery *query);
290 /* seeking query */
291 GstQuery* gst_query_new_seeking (GstFormat format) G_GNUC_MALLOC;
292 void gst_query_set_seeking (GstQuery *query, GstFormat format,
293 gboolean seekable,
294 gint64 segment_start,
295 gint64 segment_end);
296 void gst_query_parse_seeking (GstQuery *query, GstFormat *format,
297 gboolean *seekable,
298 gint64 *segment_start,
299 gint64 *segment_end);
300 /* formats query */
301 GstQuery* gst_query_new_formats (void) G_GNUC_MALLOC;
302 void gst_query_set_formats (GstQuery *query, gint n_formats, ...);
303 void gst_query_set_formatsv (GstQuery *query, gint n_formats, const GstFormat *formats);
304 void gst_query_parse_formats_length (GstQuery *query, guint *n_formats);
305 void gst_query_parse_formats_nth (GstQuery *query, guint nth, GstFormat *format);
307 /* buffering query */
308 GstQuery* gst_query_new_buffering (GstFormat format) G_GNUC_MALLOC;
309 void gst_query_set_buffering_percent (GstQuery *query, gboolean busy, gint percent);
310 void gst_query_parse_buffering_percent (GstQuery *query, gboolean *busy, gint *percent);
312 void gst_query_set_buffering_stats (GstQuery *query, GstBufferingMode mode,
313 gint avg_in, gint avg_out,
314 gint64 buffering_left);
315 void gst_query_parse_buffering_stats (GstQuery *query, GstBufferingMode *mode,
316 gint *avg_in, gint *avg_out,
317 gint64 *buffering_left);
319 void gst_query_set_buffering_range (GstQuery *query, GstFormat format,
320 gint64 start, gint64 stop,
321 gint64 estimated_total);
322 void gst_query_parse_buffering_range (GstQuery *query, GstFormat *format,
323 gint64 *start, gint64 *stop,
324 gint64 *estimated_total);
325 gboolean gst_query_add_buffering_range (GstQuery *query,
326 gint64 start, gint64 stop);
328 guint gst_query_get_n_buffering_ranges (GstQuery *query);
330 gboolean gst_query_parse_nth_buffering_range (GstQuery *query,
331 guint index, gint64 *start,
332 gint64 *stop);
334 /* URI query */
335 GstQuery * gst_query_new_uri (void) G_GNUC_MALLOC;
336 void gst_query_parse_uri (GstQuery *query, gchar **uri);
337 void gst_query_set_uri (GstQuery *query, const gchar *uri);
339 G_END_DECLS
341 #endif /* __GST_QUERY_H__ */