1 | /* GStreamer |
---|
2 | * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> |
---|
3 | * 2000 Wim Taymans <wim.taymans@chello.be> |
---|
4 | * |
---|
5 | * gstindex.h: Header for GstIndex, base class to handle efficient |
---|
6 | * storage or caching of seeking information. |
---|
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 | #ifndef __GST_INDEX_H__ |
---|
25 | #define __GST_INDEX_H__ |
---|
26 | |
---|
27 | #include <gst/gstobject.h> |
---|
28 | #include <gst/gstformat.h> |
---|
29 | #include <gst/gstpluginfeature.h> |
---|
30 | |
---|
31 | G_BEGIN_DECLS |
---|
32 | |
---|
33 | #define GST_TYPE_INDEX (gst_index_get_type ()) |
---|
34 | #define GST_INDEX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_INDEX, GstIndex)) |
---|
35 | #define GST_IS_INDEX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_INDEX)) |
---|
36 | #define GST_INDEX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_INDEX, GstIndexClass)) |
---|
37 | #define GST_IS_INDEX_CLASS(klass) (GST_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_INDEX)) |
---|
38 | #define GST_INDEX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_INDEX, GstIndexClass)) |
---|
39 | |
---|
40 | #define GST_TYPE_INDEX_ENTRY (gst_index_entry_get_type()) |
---|
41 | |
---|
42 | typedef struct _GstIndexEntry GstIndexEntry; |
---|
43 | typedef struct _GstIndexGroup GstIndexGroup; |
---|
44 | typedef struct _GstIndex GstIndex; |
---|
45 | typedef struct _GstIndexClass GstIndexClass; |
---|
46 | |
---|
47 | typedef enum { |
---|
48 | GST_INDEX_UNKNOWN, |
---|
49 | GST_INDEX_CERTAIN, |
---|
50 | GST_INDEX_FUZZY |
---|
51 | } GstIndexCertainty; |
---|
52 | |
---|
53 | typedef enum { |
---|
54 | GST_INDEX_ENTRY_ID, |
---|
55 | GST_INDEX_ENTRY_ASSOCIATION, |
---|
56 | GST_INDEX_ENTRY_OBJECT, |
---|
57 | GST_INDEX_ENTRY_FORMAT |
---|
58 | } GstIndexEntryType; |
---|
59 | |
---|
60 | typedef enum { |
---|
61 | GST_INDEX_LOOKUP_EXACT, |
---|
62 | GST_INDEX_LOOKUP_BEFORE, |
---|
63 | GST_INDEX_LOOKUP_AFTER |
---|
64 | } GstIndexLookupMethod; |
---|
65 | |
---|
66 | #define GST_INDEX_NASSOCS(entry) ((entry)->data.assoc.nassocs) |
---|
67 | #define GST_INDEX_ASSOC_FLAGS(entry) ((entry)->data.assoc.flags) |
---|
68 | #define GST_INDEX_ASSOC_FORMAT(entry,i) ((entry)->data.assoc.assocs[(i)].format) |
---|
69 | #define GST_INDEX_ASSOC_VALUE(entry,i) ((entry)->data.assoc.assocs[(i)].value) |
---|
70 | |
---|
71 | typedef struct _GstIndexAssociation GstIndexAssociation; |
---|
72 | |
---|
73 | struct _GstIndexAssociation { |
---|
74 | GstFormat format; |
---|
75 | gint64 value; |
---|
76 | }; |
---|
77 | |
---|
78 | typedef enum { |
---|
79 | GST_ASSOCIATION_FLAG_NONE = 0, |
---|
80 | GST_ASSOCIATION_FLAG_KEY_UNIT = (1 << 0), |
---|
81 | GST_ASSOCIATION_FLAG_DELTA_UNIT = (1 << 1), |
---|
82 | |
---|
83 | /* new flags should start here */ |
---|
84 | GST_ASSOCIATION_FLAG_LAST = (1 << 8) |
---|
85 | } GstAssocFlags; |
---|
86 | |
---|
87 | #define GST_INDEX_FORMAT_FORMAT(entry) ((entry)->data.format.format) |
---|
88 | #define GST_INDEX_FORMAT_KEY(entry) ((entry)->data.format.key) |
---|
89 | |
---|
90 | #define GST_INDEX_ID_INVALID (-1) |
---|
91 | |
---|
92 | #define GST_INDEX_ID_DESCRIPTION(entry) ((entry)->data.id.description) |
---|
93 | |
---|
94 | struct _GstIndexEntry { |
---|
95 | GstIndexEntryType type; |
---|
96 | gint id; |
---|
97 | |
---|
98 | union { |
---|
99 | struct { |
---|
100 | gchar *description; |
---|
101 | } id; |
---|
102 | struct { |
---|
103 | gint nassocs; |
---|
104 | GstIndexAssociation |
---|
105 | *assocs; |
---|
106 | GstAssocFlags flags; |
---|
107 | } assoc; |
---|
108 | struct { |
---|
109 | gchar *key; |
---|
110 | GType type; |
---|
111 | gpointer object; |
---|
112 | } object; |
---|
113 | struct { |
---|
114 | GstFormat format; |
---|
115 | gchar *key; |
---|
116 | } format; |
---|
117 | } data; |
---|
118 | }; |
---|
119 | |
---|
120 | struct _GstIndexGroup { |
---|
121 | /* unique ID of group in index */ |
---|
122 | gint groupnum; |
---|
123 | |
---|
124 | /* list of entries */ |
---|
125 | GList *entries; |
---|
126 | |
---|
127 | /* the certainty level of the group */ |
---|
128 | GstIndexCertainty certainty; |
---|
129 | |
---|
130 | /* peer group that contains more certain entries */ |
---|
131 | gint peergroup; |
---|
132 | }; |
---|
133 | |
---|
134 | typedef gboolean (*GstIndexFilter) (GstIndex *index, |
---|
135 | GstIndexEntry *entry); |
---|
136 | |
---|
137 | typedef enum { |
---|
138 | GST_INDEX_RESOLVER_CUSTOM, |
---|
139 | GST_INDEX_RESOLVER_GTYPE, |
---|
140 | GST_INDEX_RESOLVER_PATH |
---|
141 | } GstIndexResolverMethod; |
---|
142 | |
---|
143 | typedef gboolean (*GstIndexResolver) (GstIndex *index, |
---|
144 | GstObject *writer, |
---|
145 | gchar **writer_string, |
---|
146 | gpointer user_data); |
---|
147 | typedef enum { |
---|
148 | GST_INDEX_WRITABLE = GST_OBJECT_FLAG_LAST, |
---|
149 | GST_INDEX_READABLE, |
---|
150 | |
---|
151 | GST_INDEX_FLAG_LAST = GST_OBJECT_FLAG_LAST + 8 |
---|
152 | } GstIndexFlags; |
---|
153 | |
---|
154 | #define GST_INDEX_IS_READABLE(obj) (GST_FLAG_IS_SET (obj, GST_INDEX_READABLE)) |
---|
155 | #define GST_INDEX_IS_WRITABLE(obj) (GST_FLAG_IS_SET (obj, GST_INDEX_WRITABLE)) |
---|
156 | |
---|
157 | struct _GstIndex { |
---|
158 | GstObject object; |
---|
159 | |
---|
160 | GList *groups; |
---|
161 | GstIndexGroup *curgroup; |
---|
162 | gint maxgroup; |
---|
163 | |
---|
164 | GstIndexResolverMethod method; |
---|
165 | GstIndexResolver resolver; |
---|
166 | gpointer resolver_user_data; |
---|
167 | |
---|
168 | GstIndexFilter filter; |
---|
169 | gpointer filter_user_data; |
---|
170 | |
---|
171 | GHashTable *writers; |
---|
172 | gint last_id; |
---|
173 | |
---|
174 | gpointer _gst_reserved[GST_PADDING]; |
---|
175 | }; |
---|
176 | |
---|
177 | struct _GstIndexClass { |
---|
178 | GstObjectClass parent_class; |
---|
179 | |
---|
180 | gboolean (*get_writer_id) (GstIndex *index, gint *writer_id, gchar *writer_string); |
---|
181 | |
---|
182 | void (*commit) (GstIndex *index, gint id); |
---|
183 | |
---|
184 | /* abstract methods */ |
---|
185 | void (*add_entry) (GstIndex *index, GstIndexEntry *entry); |
---|
186 | |
---|
187 | GstIndexEntry* (*get_assoc_entry) (GstIndex *index, gint id, |
---|
188 | GstIndexLookupMethod method, GstAssocFlags flags, |
---|
189 | GstFormat format, gint64 value, |
---|
190 | GCompareDataFunc func, |
---|
191 | gpointer user_data); |
---|
192 | /* signals */ |
---|
193 | void (*entry_added) (GstIndex *index, GstIndexEntry *entry); |
---|
194 | |
---|
195 | gpointer _gst_reserved[GST_PADDING]; |
---|
196 | }; |
---|
197 | |
---|
198 | GType gst_index_get_type (void); |
---|
199 | GstIndex* gst_index_new (void); |
---|
200 | void gst_index_commit (GstIndex *index, gint id); |
---|
201 | |
---|
202 | gint gst_index_get_group (GstIndex *index); |
---|
203 | gint gst_index_new_group (GstIndex *index); |
---|
204 | gboolean gst_index_set_group (GstIndex *index, gint groupnum); |
---|
205 | |
---|
206 | void gst_index_set_certainty (GstIndex *index, |
---|
207 | GstIndexCertainty certainty); |
---|
208 | GstIndexCertainty gst_index_get_certainty (GstIndex *index); |
---|
209 | |
---|
210 | void gst_index_set_filter (GstIndex *index, |
---|
211 | GstIndexFilter filter, gpointer user_data); |
---|
212 | void gst_index_set_resolver (GstIndex *index, |
---|
213 | GstIndexResolver resolver, gpointer user_data); |
---|
214 | |
---|
215 | gboolean gst_index_get_writer_id (GstIndex *index, GstObject *writer, gint *id); |
---|
216 | |
---|
217 | GstIndexEntry* gst_index_add_format (GstIndex *index, gint id, GstFormat format); |
---|
218 | GstIndexEntry* gst_index_add_association (GstIndex *index, gint id, GstAssocFlags flags, |
---|
219 | GstFormat format, gint64 value, ...); |
---|
220 | GstIndexEntry* gst_index_add_object (GstIndex *index, gint id, gchar *key, |
---|
221 | GType type, gpointer object); |
---|
222 | GstIndexEntry* gst_index_add_id (GstIndex *index, gint id, |
---|
223 | gchar *description); |
---|
224 | |
---|
225 | GstIndexEntry* gst_index_get_assoc_entry (GstIndex *index, gint id, |
---|
226 | GstIndexLookupMethod method, GstAssocFlags flags, |
---|
227 | GstFormat format, gint64 value); |
---|
228 | GstIndexEntry* gst_index_get_assoc_entry_full (GstIndex *index, gint id, |
---|
229 | GstIndexLookupMethod method, GstAssocFlags flags, |
---|
230 | GstFormat format, gint64 value, |
---|
231 | GCompareDataFunc func, |
---|
232 | gpointer user_data); |
---|
233 | |
---|
234 | /* working with index entries */ |
---|
235 | GType gst_index_entry_get_type (void); |
---|
236 | GstIndexEntry * gst_index_entry_copy (GstIndexEntry *entry); |
---|
237 | void gst_index_entry_free (GstIndexEntry *entry); |
---|
238 | gboolean gst_index_entry_assoc_map (GstIndexEntry *entry, |
---|
239 | GstFormat format, gint64 *value); |
---|
240 | /* |
---|
241 | * creating indexs |
---|
242 | * |
---|
243 | */ |
---|
244 | #define GST_TYPE_INDEX_FACTORY (gst_index_factory_get_type()) |
---|
245 | #define GST_INDEX_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_INDEX_FACTORY, GstIndexFactory)) |
---|
246 | #define GST_IS_INDEX_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_INDEX_FACTORY)) |
---|
247 | #define GST_INDEX_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_INDEX_FACTORY, GstIndexFactoryClass)) |
---|
248 | #define GST_IS_INDEX_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_INDEX_FACTORY)) |
---|
249 | #define GST_INDEX_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_INDEX_FACTORY, GstIndexFactoryClass)) |
---|
250 | |
---|
251 | typedef struct _GstIndexFactory GstIndexFactory; |
---|
252 | typedef struct _GstIndexFactoryClass GstIndexFactoryClass; |
---|
253 | |
---|
254 | struct _GstIndexFactory { |
---|
255 | GstPluginFeature feature; |
---|
256 | |
---|
257 | gchar *longdesc; /* long description of the index (well, don't overdo it..) */ |
---|
258 | GType type; /* unique GType of the index */ |
---|
259 | |
---|
260 | gpointer _gst_reserved[GST_PADDING]; |
---|
261 | }; |
---|
262 | |
---|
263 | struct _GstIndexFactoryClass { |
---|
264 | GstPluginFeatureClass parent; |
---|
265 | |
---|
266 | gpointer _gst_reserved[GST_PADDING]; |
---|
267 | }; |
---|
268 | |
---|
269 | GType gst_index_factory_get_type (void); |
---|
270 | |
---|
271 | GstIndexFactory* gst_index_factory_new (const gchar *name, |
---|
272 | const gchar *longdesc, GType type); |
---|
273 | void gst_index_factory_destroy (GstIndexFactory *factory); |
---|
274 | |
---|
275 | GstIndexFactory* gst_index_factory_find (const gchar *name); |
---|
276 | |
---|
277 | GstIndex* gst_index_factory_create (GstIndexFactory *factory); |
---|
278 | GstIndex* gst_index_factory_make (const gchar *name); |
---|
279 | |
---|
280 | G_END_DECLS |
---|
281 | |
---|
282 | #endif /* __GST_INDEX_H__ */ |
---|