docs/gst/gstreamer-sections.txt: Reworked query docs.
[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  *
50  * Standard predefined Query types
51  */
52 /* NOTE: don't forget to update the table in gstquery.c when changing
53  * this enum */
54 typedef enum {
55   GST_QUERY_NONE = 0,
56   GST_QUERY_POSITION,
57   GST_QUERY_DURATION,
58   GST_QUERY_LATENCY,
59   GST_QUERY_JITTER,     /* not in draft-query, necessary? */
60   GST_QUERY_RATE,
61   GST_QUERY_SEEKING,
62   GST_QUERY_SEGMENT,
63   GST_QUERY_CONVERT,
64   GST_QUERY_FORMATS
65 } GstQueryType;
66
67 /**
68  * GST_QUERY_TYPE_RATE_DEN:
69  *
70  * Rates are relative to this value
71  */
72 #define GST_QUERY_TYPE_RATE_DEN          G_GINT64_CONSTANT (1000000)
73
74 typedef struct _GstQueryTypeDefinition GstQueryTypeDefinition;
75 typedef struct _GstQuery GstQuery;
76 typedef struct _GstQueryClass GstQueryClass;
77
78 /**
79  * GstQueryTypeDefinition:
80  * @value: the unique id of the Query type
81  * @nick: a short nick
82  * @description: a longer description of the query type
83  * @quark: the quark for the nick
84  *
85  * A Query Type definition
86  */
87 struct _GstQueryTypeDefinition
88 {
89   GstQueryType   value;
90   gchar         *nick;
91   gchar         *description;
92   GQuark         quark;
93 };
94
95 #define GST_TYPE_QUERY                          (gst_query_get_type())
96 #define GST_IS_QUERY(obj)                      (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_QUERY))
97 #define GST_IS_QUERY_CLASS(klass)              (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_QUERY))
98 #define GST_QUERY_GET_CLASS(obj)               (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_QUERY, GstQueryClass))
99 #define GST_QUERY(obj)                         (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_QUERY, GstQuery))
100 #define GST_QUERY_CLASS(klass)                 (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_QUERY, GstQueryClass))
101
102 /**
103  * GST_QUERY_TYPE:
104  * @query: the query to query
105  *
106  * Get the #GstQueryType of the query.
107  */
108 #define GST_QUERY_TYPE(query)  (((GstQuery*)(query))->type)
109
110 /**
111  * GST_QUERY_TYPE_NAME:
112  * @query: the query to query
113  *
114  * Get a constant string representation of the #GstQueryType of the query.
115  *
116  * Since: 0.10.4
117  */
118 #define GST_QUERY_TYPE_NAME(query) (gst_query_type_get_name(GST_QUERY_TYPE(query)))
119
120
121 /**
122  * GstQuery:
123  * @mini_object: The parent #GstMiniObject type
124  * @type: the #GstQueryType
125  * @structure: the #GstStructure containing the query details.
126  *
127  * The #GstQuery structure.
128  */
129 struct _GstQuery
130 {
131   GstMiniObject mini_object;
132
133   /*< public > *//* with COW */
134   GstQueryType type;
135
136   GstStructure *structure;
137
138   /*< private > */
139   gpointer _gst_reserved;
140 };
141
142 struct _GstQueryClass {
143   GstMiniObjectClass mini_object_class;
144
145   /*< private > */
146   gpointer _gst_reserved[GST_PADDING];
147 };
148
149 void            _gst_query_initialize          (void);
150
151 const gchar*    gst_query_type_get_name        (GstQueryType query);
152 GQuark          gst_query_type_to_quark        (GstQueryType query);
153
154 GType           gst_query_get_type             (void);
155
156 /* register a new query */
157 GstQueryType    gst_query_type_register        (const gchar *nick,
158                                                 const gchar *description);
159 GstQueryType    gst_query_type_get_by_nick     (const gchar *nick);
160
161 /* check if a query is in an array of querys */
162 gboolean        gst_query_types_contains       (const GstQueryType *types,
163                                                 GstQueryType type);
164
165 /* query for query details */
166
167 G_CONST_RETURN GstQueryTypeDefinition*
168                 gst_query_type_get_details         (GstQueryType type);
169 GstIterator*    gst_query_type_iterate_definitions (void);
170
171 /* refcounting */
172 /**
173  * gst_query_ref:
174  * @q: a #GstQuery to increase the refcount of.
175  *
176  * Increases the refcount of the given query by one.
177  */
178 #define         gst_query_ref(q)                GST_QUERY (gst_mini_object_ref (GST_MINI_OBJECT (q)))
179 /**
180  * gst_query_unref:
181  * @q: a #GstQuery to decrease the refcount of.
182  *
183  * Decreases the refcount of the query. If the refcount reaches 0, the query
184  * will be freed.
185  */
186 #define         gst_query_unref(q)              gst_mini_object_unref (GST_MINI_OBJECT (q))
187
188 /* copy query */
189 /**
190  * gst_query_copy:
191  * @q: a #GstQuery to copy.
192  *
193  * Copies the given query using the copy function of the parent #GstData
194  * structure.
195  */
196 #define         gst_query_copy(q)               GST_QUERY (gst_mini_object_copy (GST_MINI_OBJECT (q)))
197 /**
198  * gst_query_make_writable:
199  * @q: a #GstQuery to make writable
200  *
201  * Makes a writable query from the given query.
202  */
203 #define         gst_query_make_writable(q)      GST_QUERY (gst_mini_object_make_writable (GST_MINI_OBJECT (q)))
204
205 /* position query */
206 GstQuery*       gst_query_new_position          (GstFormat format);
207 void            gst_query_set_position          (GstQuery *query, GstFormat format, gint64 cur);
208 void            gst_query_parse_position        (GstQuery *query, GstFormat *format, gint64 *cur);
209
210 /* duration query */
211 GstQuery*       gst_query_new_duration          (GstFormat format);
212 void            gst_query_set_duration          (GstQuery *query, GstFormat format, gint64 duration);
213 void            gst_query_parse_duration        (GstQuery *query, GstFormat *format, gint64 *duration);
214
215 /* convert query */
216 GstQuery*       gst_query_new_convert           (GstFormat src_format, gint64 value, GstFormat dest_format);
217 void            gst_query_set_convert           (GstQuery *query, GstFormat src_format, gint64 src_value,
218                                                  GstFormat dest_format, gint64 dest_value);
219 void            gst_query_parse_convert         (GstQuery *query, GstFormat *src_format, gint64 *src_value,
220                                                  GstFormat *dest_format, gint64 *dest_value);
221 /* segment query */
222 GstQuery*       gst_query_new_segment           (GstFormat format);
223 void            gst_query_set_segment           (GstQuery *query, gdouble rate, GstFormat format,
224                                                  gint64 start_value, gint64 stop_value);
225 void            gst_query_parse_segment         (GstQuery *query, gdouble *rate, GstFormat *format,
226                                                  gint64 *start_value, gint64 *stop_value);
227
228
229 /* application specific query */
230 GstQuery *      gst_query_new_application       (GstQueryType type,
231                                                  GstStructure *structure);
232
233
234 GstStructure *  gst_query_get_structure         (GstQuery *query);
235
236 /* moved from old gstqueryutils.h */
237 GstQuery*       gst_query_new_seeking           (GstFormat format);
238 void            gst_query_set_seeking           (GstQuery *query, GstFormat format,
239                                                  gboolean seekable,
240                                                  gint64 segment_start,
241                                                  gint64 segment_end);
242 void            gst_query_parse_seeking         (GstQuery *query, GstFormat *format,
243                                                  gboolean *seekable,
244                                                  gint64 *segment_start,
245                                                  gint64 *segment_end);
246
247 GstQuery*       gst_query_new_formats           (void);
248 void            gst_query_set_formats           (GstQuery *query, gint n_formats, ...);
249 void            gst_query_set_formatsv          (GstQuery *query, gint n_formats, GstFormat *formats);
250 void            gst_query_parse_formats_length  (GstQuery *query, guint *n_formats);
251 void            gst_query_parse_formats_nth     (GstQuery *query, guint nth, GstFormat *format);
252
253 G_END_DECLS
254
255 #endif /* __GST_QUERY_H__ */
256