don't break docs build
[platform/upstream/gstreamer.git] / gst / gstindex.c
1 /* GStreamer
2  * Copyright (C) 2001 RidgeRun (http://www.ridgerun.com/)
3  * Written by Erik Walthinsen <omega@ridgerun.com>
4  *
5  * gstindex.c: Index for mappings and other data
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 /**
23  * SECTION:gstindex
24  * @short_description: Generate indexes on objects
25  * @see_also: #GstIndexFactory
26  *
27  * GstIndex is used to generate a stream index of one or more elements
28  * in a pipeline.
29  */
30
31 #include "gst_private.h"
32
33 #include "gstinfo.h"
34 #include "gstindex.h"
35 #include "gstindexfactory.h"
36 #include "gstmarshal.h"
37 #include "gstregistry.h"
38 /* for constructing an entry name */
39 #include "gstelement.h"
40 #include "gstpad.h"
41
42 /* Index signals and args */
43 enum
44 {
45   ENTRY_ADDED,
46   LAST_SIGNAL
47 };
48
49 enum
50 {
51   ARG_0,
52   ARG_RESOLVER
53       /* FILL ME */
54 };
55
56 static void gst_index_class_init (GstIndexClass * klass);
57 static void gst_index_init (GstIndex * index);
58
59 static void gst_index_set_property (GObject * object, guint prop_id,
60     const GValue * value, GParamSpec * pspec);
61 static void gst_index_get_property (GObject * object, guint prop_id,
62     GValue * value, GParamSpec * pspec);
63
64 static GstIndexGroup *gst_index_group_new (guint groupnum);
65
66 static gboolean gst_index_path_resolver (GstIndex * index, GstObject * writer,
67     gchar ** writer_string, gpointer data);
68 static gboolean gst_index_gtype_resolver (GstIndex * index, GstObject * writer,
69     gchar ** writer_string, gpointer data);
70 static void gst_index_add_entry (GstIndex * index, GstIndexEntry * entry);
71
72 static GstObject *parent_class = NULL;
73 static guint gst_index_signals[LAST_SIGNAL] = { 0 };
74
75 typedef struct
76 {
77   GstIndexResolverMethod method;
78   GstIndexResolver resolver;
79   gpointer user_data;
80 }
81 ResolverEntry;
82
83 static const ResolverEntry resolvers[] = {
84   {GST_INDEX_RESOLVER_CUSTOM, NULL, NULL},
85   {GST_INDEX_RESOLVER_GTYPE, gst_index_gtype_resolver, NULL},
86   {GST_INDEX_RESOLVER_PATH, gst_index_path_resolver, NULL},
87 };
88
89 #define GST_TYPE_INDEX_RESOLVER (gst_index_resolver_get_type())
90 static GType
91 gst_index_resolver_get_type (void)
92 {
93   static GType index_resolver_type = 0;
94   static GEnumValue index_resolver[] = {
95     {GST_INDEX_RESOLVER_CUSTOM, "GST_INDEX_RESOLVER_CUSTOM",
96         "Use a custom resolver"},
97     {GST_INDEX_RESOLVER_GTYPE, "GST_INDEX_RESOLVER_GTYPE",
98         "Resolve an object to its GType[.padname]"},
99     {GST_INDEX_RESOLVER_PATH, "GST_INDEX_RESOLVER_PATH",
100         "Resolve an object to its path in the pipeline"},
101     {0, NULL, NULL},
102   };
103
104   if (!index_resolver_type) {
105     index_resolver_type =
106         g_enum_register_static ("GstIndexResolver", index_resolver);
107   }
108   return index_resolver_type;
109 }
110
111 GType
112 gst_index_entry_get_type (void)
113 {
114   static GType index_entry_type = 0;
115
116   if (!index_entry_type) {
117     index_entry_type = g_boxed_type_register_static ("GstIndexEntry",
118         (GBoxedCopyFunc) gst_index_entry_copy,
119         (GBoxedFreeFunc) gst_index_entry_free);
120   }
121   return index_entry_type;
122 }
123
124
125 GType
126 gst_index_get_type (void)
127 {
128   static GType index_type = 0;
129
130   if (!index_type) {
131     static const GTypeInfo index_info = {
132       sizeof (GstIndexClass),
133       NULL,
134       NULL,
135       (GClassInitFunc) gst_index_class_init,
136       NULL,
137       NULL,
138       sizeof (GstIndex),
139       0,
140       (GInstanceInitFunc) gst_index_init,
141       NULL
142     };
143
144     index_type =
145         g_type_register_static (GST_TYPE_OBJECT, "GstIndex", &index_info, 0);
146   }
147   return index_type;
148 }
149
150 static void
151 gst_index_class_init (GstIndexClass * klass)
152 {
153   GObjectClass *gobject_class;
154   GstElementClass *gstelement_class;
155
156   gobject_class = (GObjectClass *) klass;
157   gstelement_class = (GstElementClass *) klass;
158
159   parent_class = g_type_class_ref (GST_TYPE_OBJECT);
160
161   /**
162    * GstIndex::entry-added
163    * @gstindex: the object which received the signal.
164    * @arg1: The entry added to the index.
165    *
166    * Is emitted when a new entry is added to the index.
167    */
168   gst_index_signals[ENTRY_ADDED] =
169       g_signal_new ("entry-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
170       G_STRUCT_OFFSET (GstIndexClass, entry_added), NULL, NULL,
171       gst_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_INDEX_ENTRY);
172
173   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_index_set_property);
174   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_index_get_property);
175
176   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RESOLVER,
177       g_param_spec_enum ("resolver", "Resolver",
178           "Select a predefined object to string mapper",
179           GST_TYPE_INDEX_RESOLVER, GST_INDEX_RESOLVER_PATH, G_PARAM_READWRITE));
180 }
181
182 static void
183 gst_index_init (GstIndex * index)
184 {
185   index->curgroup = gst_index_group_new (0);
186   index->maxgroup = 0;
187   index->groups = g_list_prepend (NULL, index->curgroup);
188
189   index->writers = g_hash_table_new (NULL, NULL);
190   index->last_id = 0;
191
192   index->method = GST_INDEX_RESOLVER_PATH;
193   index->resolver = resolvers[index->method].resolver;
194   index->resolver_user_data = resolvers[index->method].user_data;
195
196   GST_FLAG_SET (index, GST_INDEX_WRITABLE);
197   GST_FLAG_SET (index, GST_INDEX_READABLE);
198
199   GST_DEBUG ("created new index");
200 }
201
202 static void
203 gst_index_set_property (GObject * object, guint prop_id,
204     const GValue * value, GParamSpec * pspec)
205 {
206   GstIndex *index;
207
208   index = GST_INDEX (object);
209
210   switch (prop_id) {
211     case ARG_RESOLVER:
212       index->method = g_value_get_enum (value);
213       index->resolver = resolvers[index->method].resolver;
214       index->resolver_user_data = resolvers[index->method].user_data;
215       break;
216     default:
217       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
218       break;
219   }
220 }
221
222 static void
223 gst_index_get_property (GObject * object, guint prop_id,
224     GValue * value, GParamSpec * pspec)
225 {
226   GstIndex *index;
227
228   index = GST_INDEX (object);
229
230   switch (prop_id) {
231     case ARG_RESOLVER:
232       g_value_set_enum (value, index->method);
233       break;
234     default:
235       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
236       break;
237   }
238 }
239
240 static GstIndexGroup *
241 gst_index_group_new (guint groupnum)
242 {
243   GstIndexGroup *indexgroup = g_new (GstIndexGroup, 1);
244
245   indexgroup->groupnum = groupnum;
246   indexgroup->entries = NULL;
247   indexgroup->certainty = GST_INDEX_UNKNOWN;
248   indexgroup->peergroup = -1;
249
250   GST_DEBUG ("created new index group %d", groupnum);
251
252   return indexgroup;
253 }
254
255 /**
256  * gst_index_new:
257  *
258  * Create a new tileindex object
259  *
260  * Returns: a new index object
261  */
262 GstIndex *
263 gst_index_new (void)
264 {
265   GstIndex *index;
266
267   index = g_object_new (gst_index_get_type (), NULL);
268
269   return index;
270 }
271
272 /**
273  * gst_index_commit:
274  * @index: the index to commit
275  * @id: the writer that commited the index
276  *
277  * Tell the index that the writer with the given id is done
278  * with this index and is not going to write any more entries
279  * to it.
280  */
281 void
282 gst_index_commit (GstIndex * index, gint id)
283 {
284   GstIndexClass *iclass;
285
286   iclass = GST_INDEX_GET_CLASS (index);
287
288   if (iclass->commit)
289     iclass->commit (index, id);
290 }
291
292
293 /**
294  * gst_index_get_group:
295  * @index: the index to get the current group from
296  *
297  * Get the id of the current group.
298  *
299  * Returns: the id of the current group.
300  */
301 gint
302 gst_index_get_group (GstIndex * index)
303 {
304   return index->curgroup->groupnum;
305 }
306
307 /**
308  * gst_index_new_group:
309  * @index: the index to create the new group in
310  *
311  * Create a new group for the given index. It will be
312  * set as the current group.
313  *
314  * Returns: the id of the newly created group.
315  */
316 gint
317 gst_index_new_group (GstIndex * index)
318 {
319   index->curgroup = gst_index_group_new (++index->maxgroup);
320   index->groups = g_list_append (index->groups, index->curgroup);
321   GST_DEBUG ("created new group %d in index", index->maxgroup);
322   return index->maxgroup;
323 }
324
325 /**
326  * gst_index_set_group:
327  * @index: the index to set the new group in
328  * @groupnum: the groupnumber to set
329  *
330  * Set the current groupnumber to the given argument.
331  *
332  * Returns: TRUE if the operation succeeded, FALSE if the group
333  * did not exist.
334  */
335 gboolean
336 gst_index_set_group (GstIndex * index, gint groupnum)
337 {
338   GList *list;
339   GstIndexGroup *indexgroup;
340
341   /* first check for null change */
342   if (groupnum == index->curgroup->groupnum)
343     return TRUE;
344
345   /* else search for the proper group */
346   list = index->groups;
347   while (list) {
348     indexgroup = (GstIndexGroup *) (list->data);
349     list = g_list_next (list);
350     if (indexgroup->groupnum == groupnum) {
351       index->curgroup = indexgroup;
352       GST_DEBUG ("switched to index group %d", indexgroup->groupnum);
353       return TRUE;
354     }
355   }
356
357   /* couldn't find the group in question */
358   GST_DEBUG ("couldn't find index group %d", groupnum);
359   return FALSE;
360 }
361
362 /**
363  * gst_index_set_certainty:
364  * @index: the index to set the certainty on
365  * @certainty: the certainty to set
366  *
367  * Set the certainty of the given index.
368  */
369 void
370 gst_index_set_certainty (GstIndex * index, GstIndexCertainty certainty)
371 {
372   index->curgroup->certainty = certainty;
373 }
374
375 /**
376  * gst_index_get_certainty:
377  * @index: the index to get the certainty of
378  *
379  * Get the certainty of the given index.
380  *
381  * Returns: the certainty of the index.
382  */
383 GstIndexCertainty
384 gst_index_get_certainty (GstIndex * index)
385 {
386   return index->curgroup->certainty;
387 }
388
389 /**
390  * gst_index_set_filter:
391  * @index: the index to register the filter on
392  * @filter: the filter to register
393  * @user_data: data passed to the filter function
394  *
395  * Lets the app register a custom filter function so that
396  * it can select what entries should be stored in the index.
397  */
398 void
399 gst_index_set_filter (GstIndex * index,
400     GstIndexFilter filter, gpointer user_data)
401 {
402   g_return_if_fail (GST_IS_INDEX (index));
403
404   index->filter = filter;
405   index->filter_user_data = user_data;
406 }
407
408 /**
409  * gst_index_set_resolver:
410  * @index: the index to register the resolver on
411  * @resolver: the resolver to register
412  * @user_data: data passed to the resolver function
413  *
414  * Lets the app register a custom function to map index
415  * ids to writer descriptions.
416  */
417 void
418 gst_index_set_resolver (GstIndex * index,
419     GstIndexResolver resolver, gpointer user_data)
420 {
421   g_return_if_fail (GST_IS_INDEX (index));
422
423   index->resolver = resolver;
424   index->resolver_user_data = user_data;
425   index->method = GST_INDEX_RESOLVER_CUSTOM;
426 }
427
428 /**
429  * gst_index_entry_copy:
430  * @entry: the entry to copy
431  *
432  * Copies an entry and returns the result.
433  *
434  * Returns: a newly allocated #GstIndexEntry.
435  */
436 GstIndexEntry *
437 gst_index_entry_copy (GstIndexEntry * entry)
438 {
439   return g_memdup (entry, sizeof (*entry));
440 }
441
442 /**
443  * gst_index_entry_free:
444  * @entry: the entry to free
445  *
446  * Free the memory used by the given entry.
447  */
448 void
449 gst_index_entry_free (GstIndexEntry * entry)
450 {
451   g_free (entry);
452 }
453
454 /**
455  * gst_index_add_format:
456  * @index: the index to add the entry to
457  * @id: the id of the index writer
458  * @format: the format to add to the index
459  *
460  * Adds a format entry into the index. This function is
461  * used to map dynamic GstFormat ids to their original
462  * format key.
463  *
464  * Returns: a pointer to the newly added entry in the index.
465  */
466 GstIndexEntry *
467 gst_index_add_format (GstIndex * index, gint id, GstFormat format)
468 {
469   GstIndexEntry *entry;
470   const GstFormatDefinition *def;
471
472   g_return_val_if_fail (GST_IS_INDEX (index), NULL);
473   g_return_val_if_fail (format != 0, NULL);
474
475   if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
476     return NULL;
477
478   entry = g_new0 (GstIndexEntry, 1);
479   entry->type = GST_INDEX_ENTRY_FORMAT;
480   entry->id = id;
481   entry->data.format.format = format;
482
483   def = gst_format_get_details (format);
484   entry->data.format.key = def->nick;
485
486   gst_index_add_entry (index, entry);
487
488   return entry;
489 }
490
491 /**
492  * gst_index_add_id:
493  * @index: the index to add the entry to
494  * @id: the id of the index writer
495  * @description: the description of the index writer
496  *
497  * Add an id entry into the index.
498  *
499  * Returns: a pointer to the newly added entry in the index.
500  */
501 GstIndexEntry *
502 gst_index_add_id (GstIndex * index, gint id, gchar * description)
503 {
504   GstIndexEntry *entry;
505
506   g_return_val_if_fail (GST_IS_INDEX (index), NULL);
507   g_return_val_if_fail (description != NULL, NULL);
508
509   if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
510     return NULL;
511
512   entry = g_new0 (GstIndexEntry, 1);
513   entry->type = GST_INDEX_ENTRY_ID;
514   entry->id = id;
515   entry->data.id.description = description;
516
517   gst_index_add_entry (index, entry);
518
519   return entry;
520 }
521
522 static gboolean
523 gst_index_path_resolver (GstIndex * index, GstObject * writer,
524     gchar ** writer_string, gpointer data)
525 {
526   *writer_string = gst_object_get_path_string (writer);
527
528   return TRUE;
529 }
530
531 static gboolean
532 gst_index_gtype_resolver (GstIndex * index, GstObject * writer,
533     gchar ** writer_string, gpointer data)
534 {
535   if (GST_IS_PAD (writer)) {
536     GstElement *element =
537         (GstElement *) gst_object_get_parent (GST_OBJECT (writer));
538
539     *writer_string = g_strdup_printf ("%s.%s",
540         g_type_name (G_OBJECT_TYPE (element)), gst_object_get_name (writer));
541   } else {
542     *writer_string =
543         g_strdup_printf ("%s", g_type_name (G_OBJECT_TYPE (writer)));
544   }
545
546   return TRUE;
547 }
548
549 /**
550  * gst_index_get_writer_id:
551  * @index: the index to get a unique write id for
552  * @writer: the GstObject to allocate an id for
553  * @id: a pointer to a gint to hold the id
554  *
555  * Before entries can be added to the index, a writer
556  * should obtain a unique id. The methods to add new entries
557  * to the index require this id as an argument. 
558  *
559  * The application can implement a custom function to map the writer object 
560  * to a string. That string will be used to register or look up an id
561  * in the index.
562  *
563  * Returns: TRUE if the writer would be mapped to an id.
564  */
565 gboolean
566 gst_index_get_writer_id (GstIndex * index, GstObject * writer, gint * id)
567 {
568   gchar *writer_string = NULL;
569   GstIndexEntry *entry;
570   GstIndexClass *iclass;
571   gboolean success = FALSE;
572
573   g_return_val_if_fail (GST_IS_INDEX (index), FALSE);
574   g_return_val_if_fail (GST_IS_OBJECT (writer), FALSE);
575   g_return_val_if_fail (id, FALSE);
576
577   *id = -1;
578
579   /* first try to get a previously cached id */
580   entry = g_hash_table_lookup (index->writers, writer);
581   if (entry == NULL) {
582
583     iclass = GST_INDEX_GET_CLASS (index);
584
585     /* let the app make a string */
586     if (index->resolver) {
587       gboolean res;
588
589       res =
590           index->resolver (index, writer, &writer_string,
591           index->resolver_user_data);
592       if (!res)
593         return FALSE;
594     } else {
595       g_warning ("no resolver found");
596       return FALSE;
597     }
598
599     /* if the index has a resolver, make it map this string to an id */
600     if (iclass->get_writer_id) {
601       success = iclass->get_writer_id (index, id, writer_string);
602     }
603     /* if the index could not resolve, we allocate one ourselves */
604     if (!success) {
605       *id = ++index->last_id;
606     }
607
608     entry = gst_index_add_id (index, *id, writer_string);
609     if (!entry) {
610       /* index is probably not writable, make an entry anyway
611        * to keep it in our cache */
612       entry = g_new0 (GstIndexEntry, 1);
613       entry->type = GST_INDEX_ENTRY_ID;
614       entry->id = *id;
615       entry->data.id.description = writer_string;
616     }
617     g_hash_table_insert (index->writers, writer, entry);
618   } else {
619     *id = entry->id;
620   }
621
622   return TRUE;
623 }
624
625 static void
626 gst_index_add_entry (GstIndex * index, GstIndexEntry * entry)
627 {
628   GstIndexClass *iclass;
629
630   iclass = GST_INDEX_GET_CLASS (index);
631
632   if (iclass->add_entry) {
633     iclass->add_entry (index, entry);
634   }
635
636   g_signal_emit (G_OBJECT (index), gst_index_signals[ENTRY_ADDED], 0, entry);
637 }
638
639 /**
640  * gst_index_add_associationv:
641  * @index: the index to add the entry to
642  * @id: the id of the index writer
643  * @flags: optinal flags for this entry
644  * @n: number of associations
645  * @list: list of associations
646  * @...: other format/value pairs or 0 to end the list
647  *
648  * Associate given format/value pairs with each other.
649  *
650  * Returns: a pointer to the newly added entry in the index.
651  */
652 GstIndexEntry *
653 gst_index_add_associationv (GstIndex * index, gint id, GstAssocFlags flags,
654     int n, const GstIndexAssociation * list)
655 {
656   GstIndexEntry *entry;
657
658   g_return_val_if_fail (n > 0, NULL);
659   g_return_val_if_fail (list != NULL, NULL);
660   g_return_val_if_fail (GST_IS_INDEX (index), NULL);
661
662   if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
663     return NULL;
664
665   entry = g_malloc (sizeof (GstIndexEntry));
666
667   entry->type = GST_INDEX_ENTRY_ASSOCIATION;
668   entry->id = id;
669   entry->data.assoc.flags = flags;
670   entry->data.assoc.assocs = g_memdup (list, sizeof (GstIndexAssociation) * n);
671   entry->data.assoc.nassocs = n;
672
673   gst_index_add_entry (index, entry);
674
675   return entry;
676 }
677
678 /**
679  * gst_index_add_association:
680  * @index: the index to add the entry to
681  * @id: the id of the index writer
682  * @flags: optinal flags for this entry
683  * @format: the format of the value
684  * @value: the value 
685  * @...: other format/value pairs or 0 to end the list
686  *
687  * Associate given format/value pairs with each other.
688  * Be sure to pass gint64 values to this functions varargs,
689  * you might want to use a gint64 cast to be sure.
690  *
691  * Returns: a pointer to the newly added entry in the index.
692  */
693 GstIndexEntry *
694 gst_index_add_association (GstIndex * index, gint id, GstAssocFlags flags,
695     GstFormat format, gint64 value, ...)
696 {
697   va_list args;
698   GstIndexEntry *entry;
699   GstIndexAssociation *list;
700   gint n_assocs = 0;
701   GstFormat cur_format;
702   GArray *array;
703
704   g_return_val_if_fail (GST_IS_INDEX (index), NULL);
705   g_return_val_if_fail (format != 0, NULL);
706
707   if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
708     return NULL;
709
710   array = g_array_new (FALSE, FALSE, sizeof (GstIndexAssociation));
711
712   va_start (args, value);
713
714   cur_format = format;
715   n_assocs = 0;
716   while (cur_format) {
717     GstIndexAssociation a;
718
719     n_assocs++;
720     cur_format = va_arg (args, GstFormat);
721     if (cur_format) {
722       a.format = cur_format;
723       a.value = va_arg (args, gint64);
724
725       g_array_append_val (array, a);
726     }
727   }
728   va_end (args);
729
730   list = (GstIndexAssociation *) g_array_free (array, FALSE);
731
732   entry = gst_index_add_associationv (index, id, flags, n_assocs, list);
733   g_free (list);
734
735   return entry;
736 }
737
738 /**
739  * gst_index_add_object:
740  * @index: the index to add the object to
741  * @id: the id of the index writer
742  * @key: a key for the object
743  * @type: the GType of the object
744  * @object: a pointer to the object to add
745  *
746  * Add the given object to the index with the given key.
747  * 
748  * Returns: a pointer to the newly added entry in the index.
749  */
750 GstIndexEntry *
751 gst_index_add_object (GstIndex * index, gint id, gchar * key,
752     GType type, gpointer object)
753 {
754   if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
755     return NULL;
756
757   return NULL;
758 }
759
760 static gint
761 gst_index_compare_func (gconstpointer a, gconstpointer b, gpointer user_data)
762 {
763   if (a < b)
764     return -1;
765   if (a > b)
766     return 1;
767   return 0;
768 }
769
770 /**
771  * gst_index_get_assoc_entry:
772  * @index: the index to search
773  * @id: the id of the index writer
774  * @method: The lookup method to use
775  * @flags: Flags for the entry
776  * @format: the format of the value
777  * @value: the value to find
778  *
779  * Finds the given format/value in the index
780  *
781  * Returns: the entry associated with the value or NULL if the
782  *   value was not found.
783  */
784 GstIndexEntry *
785 gst_index_get_assoc_entry (GstIndex * index, gint id,
786     GstIndexLookupMethod method, GstAssocFlags flags,
787     GstFormat format, gint64 value)
788 {
789   g_return_val_if_fail (GST_IS_INDEX (index), NULL);
790
791   if (id == -1)
792     return NULL;
793
794   return gst_index_get_assoc_entry_full (index, id, method, flags, format,
795       value, gst_index_compare_func, NULL);
796 }
797
798 /**
799  * gst_index_get_assoc_entry_full:
800  * @index: the index to search
801  * @id: the id of the index writer
802  * @method: The lookup method to use
803  * @flags: Flags for the entry
804  * @format: the format of the value
805  * @value: the value to find
806  * @func: the function used to compare entries
807  * @user_data: user data passed to the compare function
808  *
809  * Finds the given format/value in the index with the given
810  * compare function and user_data.
811  *
812  * Returns: the entry associated with the value or NULL if the
813  *   value was not found.
814  */
815 GstIndexEntry *
816 gst_index_get_assoc_entry_full (GstIndex * index, gint id,
817     GstIndexLookupMethod method, GstAssocFlags flags,
818     GstFormat format, gint64 value, GCompareDataFunc func, gpointer user_data)
819 {
820   GstIndexClass *iclass;
821
822   g_return_val_if_fail (GST_IS_INDEX (index), NULL);
823
824   if (id == -1)
825     return NULL;
826
827   iclass = GST_INDEX_GET_CLASS (index);
828
829   if (iclass->get_assoc_entry)
830     return iclass->get_assoc_entry (index, id, method, flags, format, value,
831         func, user_data);
832
833   return NULL;
834 }
835
836 /**
837  * gst_index_entry_assoc_map:
838  * @entry: the index to search
839  * @format: the format of the value the find
840  * @value: a pointer to store the value
841  *
842  * Gets alternative formats associated with the indexentry.
843  *
844  * Returns: TRUE if there was a value associated with the given 
845  * format.
846  */
847 gboolean
848 gst_index_entry_assoc_map (GstIndexEntry * entry,
849     GstFormat format, gint64 * value)
850 {
851   gint i;
852
853   g_return_val_if_fail (entry != NULL, FALSE);
854   g_return_val_if_fail (value != NULL, FALSE);
855
856   for (i = 0; i < GST_INDEX_NASSOCS (entry); i++) {
857     if (GST_INDEX_ASSOC_FORMAT (entry, i) == format) {
858       *value = GST_INDEX_ASSOC_VALUE (entry, i);
859       return TRUE;
860     }
861   }
862   return FALSE;
863 }