2002-12-12 22:16:11 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2001 RidgeRun (http://www.ridgerun.com/)
|
|
|
|
* Written by Erik Walthinsen <omega@ridgerun.com>
|
|
|
|
*
|
|
|
|
* gstindex.c: Index for mappings and other data
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2005-10-15 16:01:57 +00:00
|
|
|
|
more docs inlined, splitted gstindex.{c,h}
Original commit message from CVS:
* docs/gst/gstreamer-docs.sgml:
* docs/gst/gstreamer-sections.txt:
* docs/gst/tmpl/.cvsignore:
* gst/Makefile.am:
* gst/gst.h:
* gst/gstbin.c:
* gst/gstelement.h:
* gst/gstindex.c: (gst_index_class_init):
* gst/gstindex.h:
* gst/gstindexfactory.c: (gst_index_factory_get_type),
(gst_index_factory_class_init), (gst_index_factory_init),
(gst_index_factory_finalize), (gst_index_factory_new),
(gst_index_factory_destroy), (gst_index_factory_find),
(gst_index_factory_create), (gst_index_factory_make):
* gst/gstindexfactory.h:
* gst/gstpluginfeature.c:
* gst/gstpluginfeature.h:
* libs/gst/controller/gstcontroller.c: (gst_controller_new_valist):
more docs inlined, splitted gstindex.{c,h}
2005-09-20 20:40:00 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstindex
|
|
|
|
* @short_description: Generate indexes on objects
|
|
|
|
* @see_also: #GstIndexFactory
|
|
|
|
*
|
|
|
|
* GstIndex is used to generate a stream index of one or more elements
|
|
|
|
* in a pipeline.
|
|
|
|
*/
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
#include "gst_private.h"
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2002-12-12 22:16:11 +00:00
|
|
|
#include "gstindex.h"
|
more docs inlined, splitted gstindex.{c,h}
Original commit message from CVS:
* docs/gst/gstreamer-docs.sgml:
* docs/gst/gstreamer-sections.txt:
* docs/gst/tmpl/.cvsignore:
* gst/Makefile.am:
* gst/gst.h:
* gst/gstbin.c:
* gst/gstelement.h:
* gst/gstindex.c: (gst_index_class_init):
* gst/gstindex.h:
* gst/gstindexfactory.c: (gst_index_factory_get_type),
(gst_index_factory_class_init), (gst_index_factory_init),
(gst_index_factory_finalize), (gst_index_factory_new),
(gst_index_factory_destroy), (gst_index_factory_find),
(gst_index_factory_create), (gst_index_factory_make):
* gst/gstindexfactory.h:
* gst/gstpluginfeature.c:
* gst/gstpluginfeature.h:
* libs/gst/controller/gstcontroller.c: (gst_controller_new_valist):
more docs inlined, splitted gstindex.{c,h}
2005-09-20 20:40:00 +00:00
|
|
|
#include "gstindexfactory.h"
|
2004-02-03 03:31:26 +00:00
|
|
|
#include "gstmarshal.h"
|
2005-09-15 00:13:26 +00:00
|
|
|
#include "gstregistry.h"
|
2005-07-18 12:49:53 +00:00
|
|
|
/* for constructing an entry name */
|
|
|
|
#include "gstelement.h"
|
|
|
|
#include "gstpad.h"
|
2009-01-03 18:16:54 +00:00
|
|
|
#include "gstinfo.h"
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
/* Index signals and args */
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-12-12 22:16:11 +00:00
|
|
|
ENTRY_ADDED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-12-12 22:16:11 +00:00
|
|
|
ARG_0,
|
2004-01-30 20:48:13 +00:00
|
|
|
ARG_RESOLVER
|
2004-03-13 15:27:01 +00:00
|
|
|
/* FILL ME */
|
2002-12-12 22:16:11 +00:00
|
|
|
};
|
|
|
|
|
2009-01-03 18:16:54 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (index_debug);
|
|
|
|
#define GST_CAT_DEFAULT index_debug
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_index_class_init (GstIndexClass * klass);
|
|
|
|
static void gst_index_init (GstIndex * index);
|
2008-02-01 16:37:22 +00:00
|
|
|
static void gst_index_finalize (GObject * object);
|
2003-01-05 20:34:24 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_index_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_index_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2003-01-05 20:34:24 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static GstIndexGroup *gst_index_group_new (guint groupnum);
|
2003-01-05 20:34:24 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static gboolean gst_index_path_resolver (GstIndex * index, GstObject * writer,
|
|
|
|
gchar ** writer_string, gpointer data);
|
|
|
|
static gboolean gst_index_gtype_resolver (GstIndex * index, GstObject * writer,
|
|
|
|
gchar ** writer_string, gpointer data);
|
|
|
|
static void gst_index_add_entry (GstIndex * index, GstIndexEntry * entry);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
static GstObject *parent_class = NULL;
|
|
|
|
static guint gst_index_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2003-01-05 20:34:24 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstIndexResolverMethod method;
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexResolver resolver;
|
|
|
|
gpointer user_data;
|
2004-03-15 19:27:17 +00:00
|
|
|
}
|
|
|
|
ResolverEntry;
|
2003-01-05 20:34:24 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static const ResolverEntry resolvers[] = {
|
|
|
|
{GST_INDEX_RESOLVER_CUSTOM, NULL, NULL},
|
|
|
|
{GST_INDEX_RESOLVER_GTYPE, gst_index_gtype_resolver, NULL},
|
|
|
|
{GST_INDEX_RESOLVER_PATH, gst_index_path_resolver, NULL},
|
2003-01-05 20:34:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_TYPE_INDEX_RESOLVER (gst_index_resolver_get_type())
|
|
|
|
static GType
|
|
|
|
gst_index_resolver_get_type (void)
|
|
|
|
{
|
|
|
|
static GType index_resolver_type = 0;
|
2006-05-09 17:58:35 +00:00
|
|
|
static const GEnumValue index_resolver[] = {
|
2008-04-07 13:27:32 +00:00
|
|
|
{GST_INDEX_RESOLVER_CUSTOM, "GST_INDEX_RESOLVER_CUSTOM", "custom"},
|
|
|
|
{GST_INDEX_RESOLVER_GTYPE, "GST_INDEX_RESOLVER_GTYPE", "gtype"},
|
|
|
|
{GST_INDEX_RESOLVER_PATH, "GST_INDEX_RESOLVER_PATH", "path"},
|
2003-01-05 20:34:24 +00:00
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2003-01-05 20:34:24 +00:00
|
|
|
if (!index_resolver_type) {
|
2004-03-13 15:27:01 +00:00
|
|
|
index_resolver_type =
|
2004-03-15 19:27:17 +00:00
|
|
|
g_enum_register_static ("GstIndexResolver", index_resolver);
|
2003-01-05 20:34:24 +00:00
|
|
|
}
|
|
|
|
return index_resolver_type;
|
|
|
|
}
|
|
|
|
|
2003-11-13 02:47:03 +00:00
|
|
|
GType
|
|
|
|
gst_index_entry_get_type (void)
|
|
|
|
{
|
|
|
|
static GType index_entry_type = 0;
|
|
|
|
|
|
|
|
if (!index_entry_type) {
|
|
|
|
index_entry_type = g_boxed_type_register_static ("GstIndexEntry",
|
2004-03-15 19:27:17 +00:00
|
|
|
(GBoxedCopyFunc) gst_index_entry_copy,
|
|
|
|
(GBoxedFreeFunc) gst_index_entry_free);
|
2003-11-13 02:47:03 +00:00
|
|
|
}
|
|
|
|
return index_entry_type;
|
|
|
|
}
|
|
|
|
|
2009-04-04 08:20:36 +00:00
|
|
|
#define _do_init \
|
|
|
|
{ \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (index_debug, "GST_INDEX", GST_DEBUG_BOLD, \
|
|
|
|
"Generic indexing support"); \
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2009-04-04 08:20:36 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstIndex, gst_index, GST_TYPE_OBJECT, _do_init);
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_class_init (GstIndexClass * klass)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
2009-04-04 08:20:36 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
2006-04-08 20:57:31 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
more docs inlined, splitted gstindex.{c,h}
Original commit message from CVS:
* docs/gst/gstreamer-docs.sgml:
* docs/gst/gstreamer-sections.txt:
* docs/gst/tmpl/.cvsignore:
* gst/Makefile.am:
* gst/gst.h:
* gst/gstbin.c:
* gst/gstelement.h:
* gst/gstindex.c: (gst_index_class_init):
* gst/gstindex.h:
* gst/gstindexfactory.c: (gst_index_factory_get_type),
(gst_index_factory_class_init), (gst_index_factory_init),
(gst_index_factory_finalize), (gst_index_factory_new),
(gst_index_factory_destroy), (gst_index_factory_find),
(gst_index_factory_create), (gst_index_factory_make):
* gst/gstindexfactory.h:
* gst/gstpluginfeature.c:
* gst/gstpluginfeature.h:
* libs/gst/controller/gstcontroller.c: (gst_controller_new_valist):
more docs inlined, splitted gstindex.{c,h}
2005-09-20 20:40:00 +00:00
|
|
|
/**
|
|
|
|
* GstIndex::entry-added
|
|
|
|
* @gstindex: the object which received the signal.
|
|
|
|
* @arg1: The entry added to the index.
|
|
|
|
*
|
|
|
|
* Is emitted when a new entry is added to the index.
|
|
|
|
*/
|
2002-12-12 22:16:11 +00:00
|
|
|
gst_index_signals[ENTRY_ADDED] =
|
2004-03-13 15:27:01 +00:00
|
|
|
g_signal_new ("entry-added", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstIndexClass, entry_added), NULL, NULL,
|
|
|
|
gst_marshal_VOID__BOXED, G_TYPE_NONE, 1, GST_TYPE_INDEX_ENTRY);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
2003-01-05 20:34:24 +00:00
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_index_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_index_get_property);
|
2008-02-01 16:37:22 +00:00
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_index_finalize);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
2006-05-11 18:10:34 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_RESOLVER,
|
2004-03-13 15:27:01 +00:00
|
|
|
g_param_spec_enum ("resolver", "Resolver",
|
2004-03-15 19:27:17 +00:00
|
|
|
"Select a predefined object to string mapper",
|
2008-03-22 14:56:17 +00:00
|
|
|
GST_TYPE_INDEX_RESOLVER, GST_INDEX_RESOLVER_PATH,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_init (GstIndex * index)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
index->curgroup = gst_index_group_new (0);
|
2002-12-12 22:16:11 +00:00
|
|
|
index->maxgroup = 0;
|
2004-03-13 15:27:01 +00:00
|
|
|
index->groups = g_list_prepend (NULL, index->curgroup);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
index->writers = g_hash_table_new (NULL, NULL);
|
|
|
|
index->last_id = 0;
|
2002-12-23 00:31:14 +00:00
|
|
|
|
2003-01-05 20:34:24 +00:00
|
|
|
index->method = GST_INDEX_RESOLVER_PATH;
|
|
|
|
index->resolver = resolvers[index->method].resolver;
|
|
|
|
index->resolver_user_data = resolvers[index->method].user_data;
|
2003-01-04 21:57:28 +00:00
|
|
|
|
renamed GST_FLAGS macros to GST_OBJECT_FLAGS moved bitshift from macro to enum definition
Original commit message from CVS:
* check/gst/gstbin.c: (GST_START_TEST):
* docs/gst/gstreamer-sections.txt:
* gst/base/gstbasesink.c: (gst_base_sink_init):
* gst/base/gstbasesrc.c: (gst_base_src_init),
(gst_base_src_get_range), (gst_base_src_check_get_range),
(gst_base_src_start), (gst_base_src_stop):
* gst/base/gstbasesrc.h:
* gst/elements/gstfakesrc.c: (gst_fake_src_set_property):
* gst/gstbin.c: (gst_bin_add_func), (gst_bin_remove_func),
(bin_element_is_sink), (reset_degree), (gst_bin_element_set_state),
(bin_bus_handler):
* gst/gstbin.h:
* gst/gstbuffer.h:
* gst/gstbus.c: (gst_bus_post), (gst_bus_set_flushing):
* gst/gstbus.h:
* gst/gstelement.c: (gst_element_is_locked_state),
(gst_element_set_locked_state), (gst_element_commit_state),
(gst_element_set_state):
* gst/gstelement.h:
* gst/gstindex.c: (gst_index_init):
* gst/gstindex.h:
* gst/gstminiobject.h:
* gst/gstobject.c: (gst_object_init), (gst_object_sink),
(gst_object_set_parent):
* gst/gstobject.h:
* gst/gstpad.c: (gst_pad_set_blocked_async), (gst_pad_is_blocked),
(gst_pad_get_caps_unlocked), (gst_pad_set_caps):
* gst/gstpad.h:
* gst/gstpadtemplate.h:
* gst/gstpipeline.c: (gst_pipeline_provide_clock_func),
(gst_pipeline_use_clock), (gst_pipeline_auto_clock):
* gst/gstpipeline.h:
* gst/indexers/gstfileindex.c: (gst_file_index_load),
(gst_file_index_commit):
* testsuite/bytestream/filepadsink.c: (gst_fp_sink_init):
* testsuite/pad/link.c: (gst_test_src_init),
(gst_test_filter_init), (gst_test_sink_init):
* testsuite/states/locked.c: (main):
renamed GST_FLAGS macros to GST_OBJECT_FLAGS
moved bitshift from macro to enum definition
2005-10-12 14:28:39 +00:00
|
|
|
GST_OBJECT_FLAG_SET (index, GST_INDEX_WRITABLE);
|
|
|
|
GST_OBJECT_FLAG_SET (index, GST_INDEX_READABLE);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("created new index");
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2008-02-01 16:37:22 +00:00
|
|
|
static void
|
|
|
|
gst_index_free_writer (gpointer key, gpointer value, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstIndexEntry *entry = (GstIndexEntry *) value;
|
|
|
|
|
|
|
|
if (entry) {
|
|
|
|
gst_index_entry_free (entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_index_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstIndex *index = GST_INDEX (object);
|
|
|
|
|
|
|
|
if (index->groups) {
|
|
|
|
g_list_foreach (index->groups, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (index->groups);
|
|
|
|
index->groups = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index->writers) {
|
|
|
|
g_hash_table_foreach (index->writers, gst_index_free_writer, NULL);
|
|
|
|
g_hash_table_destroy (index->writers);
|
|
|
|
index->writers = NULL;
|
|
|
|
}
|
2008-02-11 08:53:04 +00:00
|
|
|
|
2008-02-11 17:53:57 +00:00
|
|
|
if (index->filter_user_data && index->filter_user_data_destroy)
|
|
|
|
index->filter_user_data_destroy (index->filter_user_data);
|
|
|
|
|
|
|
|
if (index->resolver_user_data && index->resolver_user_data_destroy)
|
|
|
|
index->resolver_user_data_destroy (index->resolver_user_data);
|
|
|
|
|
2008-02-11 08:53:04 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2008-02-01 16:37:22 +00:00
|
|
|
}
|
|
|
|
|
2003-01-05 20:34:24 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2003-01-05 20:34:24 +00:00
|
|
|
{
|
|
|
|
GstIndex *index;
|
|
|
|
|
|
|
|
index = GST_INDEX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_RESOLVER:
|
|
|
|
index->method = g_value_get_enum (value);
|
|
|
|
index->resolver = resolvers[index->method].resolver;
|
|
|
|
index->resolver_user_data = resolvers[index->method].user_data;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2003-01-05 20:34:24 +00:00
|
|
|
{
|
|
|
|
GstIndex *index;
|
|
|
|
|
|
|
|
index = GST_INDEX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_RESOLVER:
|
|
|
|
g_value_set_enum (value, index->method);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstIndexGroup *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_group_new (guint groupnum)
|
2003-01-05 20:34:24 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexGroup *indexgroup = g_new (GstIndexGroup, 1);
|
2003-01-05 20:34:24 +00:00
|
|
|
|
|
|
|
indexgroup->groupnum = groupnum;
|
|
|
|
indexgroup->entries = NULL;
|
|
|
|
indexgroup->certainty = GST_INDEX_UNKNOWN;
|
|
|
|
indexgroup->peergroup = -1;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DEBUG ("created new index group %d", groupnum);
|
2003-01-05 20:34:24 +00:00
|
|
|
|
|
|
|
return indexgroup;
|
|
|
|
}
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
/**
|
|
|
|
* gst_index_new:
|
|
|
|
*
|
|
|
|
* Create a new tileindex object
|
|
|
|
*
|
|
|
|
* Returns: a new index object
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndex *
|
2003-02-10 20:16:38 +00:00
|
|
|
gst_index_new (void)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
GstIndex *index;
|
|
|
|
|
|
|
|
index = g_object_new (gst_index_get_type (), NULL);
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2002-12-23 00:31:14 +00:00
|
|
|
/**
|
|
|
|
* gst_index_commit:
|
|
|
|
* @index: the index to commit
|
|
|
|
* @id: the writer that commited the index
|
|
|
|
*
|
|
|
|
* Tell the index that the writer with the given id is done
|
|
|
|
* with this index and is not going to write any more entries
|
|
|
|
* to it.
|
|
|
|
*/
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_commit (GstIndex * index, gint id)
|
2002-12-23 00:31:14 +00:00
|
|
|
{
|
|
|
|
GstIndexClass *iclass;
|
|
|
|
|
|
|
|
iclass = GST_INDEX_GET_CLASS (index);
|
|
|
|
|
|
|
|
if (iclass->commit)
|
|
|
|
iclass->commit (index, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
/**
|
|
|
|
* gst_index_get_group:
|
|
|
|
* @index: the index to get the current group from
|
|
|
|
*
|
|
|
|
* Get the id of the current group.
|
|
|
|
*
|
|
|
|
* Returns: the id of the current group.
|
|
|
|
*/
|
|
|
|
gint
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_get_group (GstIndex * index)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
return index->curgroup->groupnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_new_group:
|
|
|
|
* @index: the index to create the new group in
|
|
|
|
*
|
|
|
|
* Create a new group for the given index. It will be
|
|
|
|
* set as the current group.
|
|
|
|
*
|
|
|
|
* Returns: the id of the newly created group.
|
|
|
|
*/
|
|
|
|
gint
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_new_group (GstIndex * index)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
index->curgroup = gst_index_group_new (++index->maxgroup);
|
|
|
|
index->groups = g_list_append (index->groups, index->curgroup);
|
|
|
|
GST_DEBUG ("created new group %d in index", index->maxgroup);
|
2002-12-12 22:16:11 +00:00
|
|
|
return index->maxgroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_set_group:
|
|
|
|
* @index: the index to set the new group in
|
|
|
|
* @groupnum: the groupnumber to set
|
|
|
|
*
|
|
|
|
* Set the current groupnumber to the given argument.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the operation succeeded, FALSE if the group
|
|
|
|
* did not exist.
|
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_set_group (GstIndex * index, gint groupnum)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GstIndexGroup *indexgroup;
|
|
|
|
|
|
|
|
/* first check for null change */
|
|
|
|
if (groupnum == index->curgroup->groupnum)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* else search for the proper group */
|
|
|
|
list = index->groups;
|
|
|
|
while (list) {
|
2004-03-13 15:27:01 +00:00
|
|
|
indexgroup = (GstIndexGroup *) (list->data);
|
|
|
|
list = g_list_next (list);
|
2002-12-12 22:16:11 +00:00
|
|
|
if (indexgroup->groupnum == groupnum) {
|
|
|
|
index->curgroup = indexgroup;
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DEBUG ("switched to index group %d", indexgroup->groupnum);
|
2002-12-12 22:16:11 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* couldn't find the group in question */
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DEBUG ("couldn't find index group %d", groupnum);
|
2002-12-12 22:16:11 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_set_certainty:
|
|
|
|
* @index: the index to set the certainty on
|
|
|
|
* @certainty: the certainty to set
|
|
|
|
*
|
|
|
|
* Set the certainty of the given index.
|
|
|
|
*/
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_set_certainty (GstIndex * index, GstIndexCertainty certainty)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
index->curgroup->certainty = certainty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_get_certainty:
|
|
|
|
* @index: the index to get the certainty of
|
|
|
|
*
|
|
|
|
* Get the certainty of the given index.
|
|
|
|
*
|
|
|
|
* Returns: the certainty of the index.
|
|
|
|
*/
|
|
|
|
GstIndexCertainty
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_get_certainty (GstIndex * index)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
return index->curgroup->certainty;
|
|
|
|
}
|
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
/**
|
|
|
|
* gst_index_set_filter:
|
|
|
|
* @index: the index to register the filter on
|
|
|
|
* @filter: the filter to register
|
|
|
|
* @user_data: data passed to the filter function
|
|
|
|
*
|
|
|
|
* Lets the app register a custom filter function so that
|
|
|
|
* it can select what entries should be stored in the index.
|
|
|
|
*/
|
2002-12-12 22:16:11 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_set_filter (GstIndex * index,
|
|
|
|
GstIndexFilter filter, gpointer user_data)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_INDEX (index));
|
|
|
|
|
2005-11-19 17:26:27 +00:00
|
|
|
gst_index_set_filter_full (index, filter, user_data, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_set_filter_full:
|
|
|
|
* @index: the index to register the filter on
|
|
|
|
* @filter: the filter to register
|
|
|
|
* @user_data: data passed to the filter function
|
|
|
|
* @user_data_destroy: function to call when @user_data is unset
|
|
|
|
*
|
|
|
|
* Lets the app register a custom filter function so that
|
|
|
|
* it can select what entries should be stored in the index.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_index_set_filter_full (GstIndex * index,
|
|
|
|
GstIndexFilter filter, gpointer user_data, GDestroyNotify user_data_destroy)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_INDEX (index));
|
|
|
|
|
|
|
|
if (index->filter_user_data && index->filter_user_data_destroy)
|
|
|
|
index->filter_user_data_destroy (index->filter_user_data);
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
index->filter = filter;
|
|
|
|
index->filter_user_data = user_data;
|
2005-11-19 17:26:27 +00:00
|
|
|
index->filter_user_data_destroy = user_data_destroy;
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
/**
|
|
|
|
* gst_index_set_resolver:
|
|
|
|
* @index: the index to register the resolver on
|
|
|
|
* @resolver: the resolver to register
|
|
|
|
* @user_data: data passed to the resolver function
|
|
|
|
*
|
|
|
|
* Lets the app register a custom function to map index
|
|
|
|
* ids to writer descriptions.
|
|
|
|
*/
|
2002-12-12 22:16:11 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_set_resolver (GstIndex * index,
|
|
|
|
GstIndexResolver resolver, gpointer user_data)
|
2008-02-11 17:53:57 +00:00
|
|
|
{
|
|
|
|
gst_index_set_resolver_full (index, resolver, user_data, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_set_resolver_full:
|
|
|
|
* @index: the index to register the resolver on
|
|
|
|
* @resolver: the resolver to register
|
|
|
|
* @user_data: data passed to the resolver function
|
|
|
|
* @user_data_destroy: destroy function for @user_data
|
|
|
|
*
|
|
|
|
* Lets the app register a custom function to map index
|
|
|
|
* ids to writer descriptions.
|
|
|
|
*
|
|
|
|
* Since: 0.10.18
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_index_set_resolver_full (GstIndex * index, GstIndexResolver resolver,
|
|
|
|
gpointer user_data, GDestroyNotify user_data_destroy)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_INDEX (index));
|
|
|
|
|
2008-02-11 17:53:57 +00:00
|
|
|
if (index->resolver_user_data && index->resolver_user_data_destroy)
|
|
|
|
index->resolver_user_data_destroy (index->resolver_user_data);
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
index->resolver = resolver;
|
|
|
|
index->resolver_user_data = user_data;
|
2008-02-11 17:53:57 +00:00
|
|
|
index->resolver_user_data_destroy = user_data_destroy;
|
2003-01-05 20:34:24 +00:00
|
|
|
index->method = GST_INDEX_RESOLVER_CUSTOM;
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2003-11-13 02:47:03 +00:00
|
|
|
/**
|
|
|
|
* gst_index_entry_copy:
|
|
|
|
* @entry: the entry to copy
|
|
|
|
*
|
|
|
|
* Copies an entry and returns the result.
|
2004-03-30 07:36:19 +00:00
|
|
|
*
|
2004-03-30 09:15:47 +00:00
|
|
|
* Returns: a newly allocated #GstIndexEntry.
|
2003-11-13 02:47:03 +00:00
|
|
|
*/
|
|
|
|
GstIndexEntry *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_entry_copy (GstIndexEntry * entry)
|
2003-11-13 02:47:03 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
return g_memdup (entry, sizeof (*entry));
|
2003-11-13 02:47:03 +00:00
|
|
|
}
|
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
/**
|
|
|
|
* gst_index_entry_free:
|
|
|
|
* @entry: the entry to free
|
|
|
|
*
|
|
|
|
* Free the memory used by the given entry.
|
|
|
|
*/
|
2002-12-12 22:16:11 +00:00
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_entry_free (GstIndexEntry * entry)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
2008-02-01 16:37:22 +00:00
|
|
|
switch (entry->type) {
|
|
|
|
case GST_INDEX_ENTRY_ID:
|
|
|
|
if (entry->data.id.description) {
|
|
|
|
g_free (entry->data.id.description);
|
|
|
|
entry->data.id.description = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_INDEX_ENTRY_ASSOCIATION:
|
|
|
|
if (entry->data.assoc.assocs) {
|
|
|
|
g_free (entry->data.assoc.assocs);
|
|
|
|
entry->data.assoc.assocs = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_INDEX_ENTRY_OBJECT:
|
|
|
|
break;
|
|
|
|
case GST_INDEX_ENTRY_FORMAT:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
g_free (entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_add_format:
|
|
|
|
* @index: the index to add the entry to
|
|
|
|
* @id: the id of the index writer
|
|
|
|
* @format: the format to add to the index
|
|
|
|
*
|
|
|
|
* Adds a format entry into the index. This function is
|
|
|
|
* used to map dynamic GstFormat ids to their original
|
|
|
|
* format key.
|
|
|
|
*
|
|
|
|
* Returns: a pointer to the newly added entry in the index.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexEntry *
|
|
|
|
gst_index_add_format (GstIndex * index, gint id, GstFormat format)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
GstIndexEntry *entry;
|
2004-03-13 15:27:01 +00:00
|
|
|
const GstFormatDefinition *def;
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
|
|
|
|
g_return_val_if_fail (format != 0, NULL);
|
2002-12-23 00:31:14 +00:00
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
|
2002-12-23 00:31:14 +00:00
|
|
|
return NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
entry = g_new0 (GstIndexEntry, 1);
|
|
|
|
entry->type = GST_INDEX_ENTRY_FORMAT;
|
|
|
|
entry->id = id;
|
|
|
|
entry->data.format.format = format;
|
2002-12-19 21:31:03 +00:00
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
def = gst_format_get_details (format);
|
|
|
|
entry->data.format.key = def->nick;
|
2002-12-19 21:31:03 +00:00
|
|
|
|
2004-02-06 18:17:56 +00:00
|
|
|
gst_index_add_entry (index, entry);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_add_id:
|
|
|
|
* @index: the index to add the entry to
|
|
|
|
* @id: the id of the index writer
|
|
|
|
* @description: the description of the index writer
|
|
|
|
*
|
2002-12-14 13:02:16 +00:00
|
|
|
* Add an id entry into the index.
|
|
|
|
*
|
2002-12-12 22:16:11 +00:00
|
|
|
* Returns: a pointer to the newly added entry in the index.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexEntry *
|
|
|
|
gst_index_add_id (GstIndex * index, gint id, gchar * description)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
GstIndexEntry *entry;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
|
|
|
|
g_return_val_if_fail (description != NULL, NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
|
2002-12-23 00:31:14 +00:00
|
|
|
return NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
entry = g_new0 (GstIndexEntry, 1);
|
|
|
|
entry->type = GST_INDEX_ENTRY_ID;
|
|
|
|
entry->id = id;
|
|
|
|
entry->data.id.description = description;
|
|
|
|
|
2004-02-06 18:17:56 +00:00
|
|
|
gst_index_add_entry (index, entry);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_path_resolver (GstIndex * index, GstObject * writer,
|
|
|
|
gchar ** writer_string, gpointer data)
|
2003-01-04 21:57:28 +00:00
|
|
|
{
|
|
|
|
*writer_string = gst_object_get_path_string (writer);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-01-05 20:34:24 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_gtype_resolver (GstIndex * index, GstObject * writer,
|
|
|
|
gchar ** writer_string, gpointer data)
|
2003-01-05 20:34:24 +00:00
|
|
|
{
|
|
|
|
if (GST_IS_PAD (writer)) {
|
2005-03-07 18:27:42 +00:00
|
|
|
GstElement *element =
|
|
|
|
(GstElement *) gst_object_get_parent (GST_OBJECT (writer));
|
2006-06-07 08:38:30 +00:00
|
|
|
gchar *name;
|
2003-01-05 20:34:24 +00:00
|
|
|
|
2006-06-07 08:38:30 +00:00
|
|
|
name = gst_object_get_name (writer);
|
2004-03-13 15:27:01 +00:00
|
|
|
*writer_string = g_strdup_printf ("%s.%s",
|
2006-06-07 08:38:30 +00:00
|
|
|
g_type_name (G_OBJECT_TYPE (element)), name);
|
|
|
|
|
|
|
|
gst_object_unref (element);
|
|
|
|
g_free (name);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
|
|
|
*writer_string =
|
2004-03-15 19:27:17 +00:00
|
|
|
g_strdup_printf ("%s", g_type_name (G_OBJECT_TYPE (writer)));
|
2003-01-05 20:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
/**
|
|
|
|
* gst_index_get_writer_id:
|
|
|
|
* @index: the index to get a unique write id for
|
|
|
|
* @writer: the GstObject to allocate an id for
|
|
|
|
* @id: a pointer to a gint to hold the id
|
|
|
|
*
|
|
|
|
* Before entries can be added to the index, a writer
|
|
|
|
* should obtain a unique id. The methods to add new entries
|
2005-10-15 15:30:24 +00:00
|
|
|
* to the index require this id as an argument.
|
2002-12-12 22:16:11 +00:00
|
|
|
*
|
2005-10-15 15:30:24 +00:00
|
|
|
* The application can implement a custom function to map the writer object
|
2003-01-04 21:57:28 +00:00
|
|
|
* to a string. That string will be used to register or look up an id
|
|
|
|
* in the index.
|
2002-12-12 22:16:11 +00:00
|
|
|
*
|
|
|
|
* Returns: TRUE if the writer would be mapped to an id.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
gboolean
|
|
|
|
gst_index_get_writer_id (GstIndex * index, GstObject * writer, gint * id)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
gchar *writer_string = NULL;
|
|
|
|
GstIndexEntry *entry;
|
2002-12-19 21:31:03 +00:00
|
|
|
GstIndexClass *iclass;
|
2003-01-04 21:57:28 +00:00
|
|
|
gboolean success = FALSE;
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_INDEX (index), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_OBJECT (writer), FALSE);
|
|
|
|
g_return_val_if_fail (id, FALSE);
|
|
|
|
|
|
|
|
*id = -1;
|
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
/* first try to get a previously cached id */
|
2002-12-12 22:16:11 +00:00
|
|
|
entry = g_hash_table_lookup (index->writers, writer);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (entry == NULL) {
|
2002-12-12 22:16:11 +00:00
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
iclass = GST_INDEX_GET_CLASS (index);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
/* let the app make a string */
|
|
|
|
if (index->resolver) {
|
|
|
|
gboolean res;
|
2002-12-19 21:31:03 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
res =
|
2004-03-15 19:27:17 +00:00
|
|
|
index->resolver (index, writer, &writer_string,
|
|
|
|
index->resolver_user_data);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!res)
|
2004-03-15 19:27:17 +00:00
|
|
|
return FALSE;
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
2003-01-04 21:57:28 +00:00
|
|
|
g_warning ("no resolver found");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the index has a resolver, make it map this string to an id */
|
|
|
|
if (iclass->get_writer_id) {
|
|
|
|
success = iclass->get_writer_id (index, id, writer_string);
|
|
|
|
}
|
|
|
|
/* if the index could not resolve, we allocate one ourselves */
|
|
|
|
if (!success) {
|
2003-07-25 03:11:59 +00:00
|
|
|
*id = ++index->last_id;
|
2003-01-04 21:57:28 +00:00
|
|
|
}
|
2002-12-12 22:16:11 +00:00
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
entry = gst_index_add_id (index, *id, writer_string);
|
|
|
|
if (!entry) {
|
|
|
|
/* index is probably not writable, make an entry anyway
|
|
|
|
* to keep it in our cache */
|
|
|
|
entry = g_new0 (GstIndexEntry, 1);
|
|
|
|
entry->type = GST_INDEX_ENTRY_ID;
|
|
|
|
entry->id = *id;
|
|
|
|
entry->data.id.description = writer_string;
|
|
|
|
}
|
|
|
|
g_hash_table_insert (index->writers, writer, entry);
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
2003-01-04 21:57:28 +00:00
|
|
|
*id = entry->id;
|
2003-01-04 16:57:31 +00:00
|
|
|
}
|
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
return TRUE;
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2004-02-06 18:17:56 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_add_entry (GstIndex * index, GstIndexEntry * entry)
|
2004-02-06 18:17:56 +00:00
|
|
|
{
|
|
|
|
GstIndexClass *iclass;
|
|
|
|
|
|
|
|
iclass = GST_INDEX_GET_CLASS (index);
|
|
|
|
|
|
|
|
if (iclass->add_entry) {
|
|
|
|
iclass->add_entry (index, entry);
|
|
|
|
}
|
|
|
|
|
2009-10-03 20:08:54 +00:00
|
|
|
g_signal_emit (index, gst_index_signals[ENTRY_ADDED], 0, entry);
|
2004-02-06 18:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_index_add_associationv:
|
|
|
|
* @index: the index to add the entry to
|
|
|
|
* @id: the id of the index writer
|
|
|
|
* @flags: optinal flags for this entry
|
|
|
|
* @n: number of associations
|
|
|
|
* @list: list of associations
|
|
|
|
*
|
|
|
|
* Associate given format/value pairs with each other.
|
|
|
|
*
|
|
|
|
* Returns: a pointer to the newly added entry in the index.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexEntry *
|
|
|
|
gst_index_add_associationv (GstIndex * index, gint id, GstAssocFlags flags,
|
2006-01-18 09:42:12 +00:00
|
|
|
gint n, const GstIndexAssociation * list)
|
2004-02-06 18:17:56 +00:00
|
|
|
{
|
|
|
|
GstIndexEntry *entry;
|
|
|
|
|
|
|
|
g_return_val_if_fail (n > 0, NULL);
|
|
|
|
g_return_val_if_fail (list != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-02-06 18:17:56 +00:00
|
|
|
if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
|
|
|
|
return NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-02-06 18:17:56 +00:00
|
|
|
entry = g_malloc (sizeof (GstIndexEntry));
|
|
|
|
|
|
|
|
entry->type = GST_INDEX_ENTRY_ASSOCIATION;
|
|
|
|
entry->id = id;
|
|
|
|
entry->data.assoc.flags = flags;
|
2004-03-13 15:27:01 +00:00
|
|
|
entry->data.assoc.assocs = g_memdup (list, sizeof (GstIndexAssociation) * n);
|
2004-02-06 18:17:56 +00:00
|
|
|
entry->data.assoc.nassocs = n;
|
|
|
|
|
|
|
|
gst_index_add_entry (index, entry);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
/**
|
|
|
|
* gst_index_add_association:
|
|
|
|
* @index: the index to add the entry to
|
|
|
|
* @id: the id of the index writer
|
2002-12-14 13:02:16 +00:00
|
|
|
* @flags: optinal flags for this entry
|
2002-12-12 22:16:11 +00:00
|
|
|
* @format: the format of the value
|
2005-10-15 15:30:24 +00:00
|
|
|
* @value: the value
|
2002-12-12 22:16:11 +00:00
|
|
|
* @...: other format/value pairs or 0 to end the list
|
|
|
|
*
|
2004-02-06 18:17:56 +00:00
|
|
|
* Associate given format/value pairs with each other.
|
2002-12-12 22:16:11 +00:00
|
|
|
* Be sure to pass gint64 values to this functions varargs,
|
|
|
|
* you might want to use a gint64 cast to be sure.
|
|
|
|
*
|
|
|
|
* Returns: a pointer to the newly added entry in the index.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexEntry *
|
|
|
|
gst_index_add_association (GstIndex * index, gint id, GstAssocFlags flags,
|
|
|
|
GstFormat format, gint64 value, ...)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
GstIndexEntry *entry;
|
2004-02-06 18:17:56 +00:00
|
|
|
GstIndexAssociation *list;
|
|
|
|
gint n_assocs = 0;
|
2002-12-12 22:16:11 +00:00
|
|
|
GstFormat cur_format;
|
2004-02-06 18:17:56 +00:00
|
|
|
GArray *array;
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
|
|
|
|
g_return_val_if_fail (format != 0, NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
|
2002-12-23 00:31:14 +00:00
|
|
|
return NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
array = g_array_new (FALSE, FALSE, sizeof (GstIndexAssociation));
|
2004-02-06 18:17:56 +00:00
|
|
|
|
2007-08-14 13:43:44 +00:00
|
|
|
{
|
|
|
|
GstIndexAssociation a;
|
|
|
|
|
|
|
|
a.format = format;
|
|
|
|
a.value = value;
|
|
|
|
n_assocs = 1;
|
|
|
|
g_array_append_val (array, a);
|
|
|
|
}
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
va_start (args, value);
|
|
|
|
|
2007-08-14 13:43:44 +00:00
|
|
|
while ((cur_format = va_arg (args, GstFormat))) {
|
2004-02-06 18:17:56 +00:00
|
|
|
GstIndexAssociation a;
|
2002-12-12 22:16:11 +00:00
|
|
|
|
2007-08-14 13:43:44 +00:00
|
|
|
a.format = cur_format;
|
|
|
|
a.value = va_arg (args, gint64);
|
2004-02-06 18:17:56 +00:00
|
|
|
n_assocs++;
|
2007-08-14 13:43:44 +00:00
|
|
|
g_array_append_val (array, a);
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
2007-08-14 13:43:44 +00:00
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
va_end (args);
|
|
|
|
|
2004-02-06 18:17:56 +00:00
|
|
|
list = (GstIndexAssociation *) g_array_free (array, FALSE);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
2004-02-06 18:17:56 +00:00
|
|
|
entry = gst_index_add_associationv (index, id, flags, n_assocs, list);
|
|
|
|
g_free (list);
|
2002-12-12 22:16:11 +00:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
/**
|
|
|
|
* gst_index_add_object:
|
|
|
|
* @index: the index to add the object to
|
|
|
|
* @id: the id of the index writer
|
|
|
|
* @key: a key for the object
|
|
|
|
* @type: the GType of the object
|
|
|
|
* @object: a pointer to the object to add
|
|
|
|
*
|
|
|
|
* Add the given object to the index with the given key.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2005-11-14 11:58:44 +00:00
|
|
|
* This function is not yet implemented.
|
|
|
|
*
|
2002-12-14 13:02:16 +00:00
|
|
|
* Returns: a pointer to the newly added entry in the index.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexEntry *
|
|
|
|
gst_index_add_object (GstIndex * index, gint id, gchar * key,
|
|
|
|
GType type, gpointer object)
|
2002-12-14 13:02:16 +00:00
|
|
|
{
|
2003-01-04 21:57:28 +00:00
|
|
|
if (!GST_INDEX_IS_WRITABLE (index) || id == -1)
|
2002-12-23 00:31:14 +00:00
|
|
|
return NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
static gint
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_compare_func (gconstpointer a, gconstpointer b, gpointer user_data)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
2004-05-20 19:32:34 +00:00
|
|
|
if (a < b)
|
|
|
|
return -1;
|
|
|
|
if (a > b)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
/**
|
|
|
|
* gst_index_get_assoc_entry:
|
|
|
|
* @index: the index to search
|
|
|
|
* @id: the id of the index writer
|
|
|
|
* @method: The lookup method to use
|
2002-12-30 17:42:11 +00:00
|
|
|
* @flags: Flags for the entry
|
2002-12-14 13:02:16 +00:00
|
|
|
* @format: the format of the value
|
|
|
|
* @value: the value to find
|
|
|
|
*
|
|
|
|
* Finds the given format/value in the index
|
|
|
|
*
|
|
|
|
* Returns: the entry associated with the value or NULL if the
|
|
|
|
* value was not found.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexEntry *
|
|
|
|
gst_index_get_assoc_entry (GstIndex * index, gint id,
|
|
|
|
GstIndexLookupMethod method, GstAssocFlags flags,
|
|
|
|
GstFormat format, gint64 value)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
|
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
if (id == -1)
|
|
|
|
return NULL;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return gst_index_get_assoc_entry_full (index, id, method, flags, format,
|
|
|
|
value, gst_index_compare_func, NULL);
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
/**
|
|
|
|
* gst_index_get_assoc_entry_full:
|
|
|
|
* @index: the index to search
|
|
|
|
* @id: the id of the index writer
|
|
|
|
* @method: The lookup method to use
|
2002-12-30 17:42:11 +00:00
|
|
|
* @flags: Flags for the entry
|
2002-12-14 13:02:16 +00:00
|
|
|
* @format: the format of the value
|
|
|
|
* @value: the value to find
|
|
|
|
* @func: the function used to compare entries
|
|
|
|
* @user_data: user data passed to the compare function
|
|
|
|
*
|
|
|
|
* Finds the given format/value in the index with the given
|
|
|
|
* compare function and user_data.
|
|
|
|
*
|
|
|
|
* Returns: the entry associated with the value or NULL if the
|
|
|
|
* value was not found.
|
|
|
|
*/
|
2004-03-13 15:27:01 +00:00
|
|
|
GstIndexEntry *
|
|
|
|
gst_index_get_assoc_entry_full (GstIndex * index, gint id,
|
|
|
|
GstIndexLookupMethod method, GstAssocFlags flags,
|
|
|
|
GstFormat format, gint64 value, GCompareDataFunc func, gpointer user_data)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
2002-12-19 21:31:03 +00:00
|
|
|
GstIndexClass *iclass;
|
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
g_return_val_if_fail (GST_IS_INDEX (index), NULL);
|
|
|
|
|
2003-01-04 21:57:28 +00:00
|
|
|
if (id == -1)
|
|
|
|
return NULL;
|
|
|
|
|
2002-12-19 21:31:03 +00:00
|
|
|
iclass = GST_INDEX_GET_CLASS (index);
|
|
|
|
|
|
|
|
if (iclass->get_assoc_entry)
|
2004-03-13 15:27:01 +00:00
|
|
|
return iclass->get_assoc_entry (index, id, method, flags, format, value,
|
2004-03-15 19:27:17 +00:00
|
|
|
func, user_data);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-12-12 22:16:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-12-14 13:02:16 +00:00
|
|
|
/**
|
|
|
|
* gst_index_entry_assoc_map:
|
|
|
|
* @entry: the index to search
|
|
|
|
* @format: the format of the value the find
|
|
|
|
* @value: a pointer to store the value
|
|
|
|
*
|
|
|
|
* Gets alternative formats associated with the indexentry.
|
|
|
|
*
|
2005-10-15 15:30:24 +00:00
|
|
|
* Returns: TRUE if there was a value associated with the given
|
2002-12-14 13:02:16 +00:00
|
|
|
* format.
|
|
|
|
*/
|
2002-12-12 22:16:11 +00:00
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_index_entry_assoc_map (GstIndexEntry * entry,
|
|
|
|
GstFormat format, gint64 * value)
|
2002-12-12 22:16:11 +00:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (entry != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (value != NULL, FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < GST_INDEX_NASSOCS (entry); i++) {
|
2004-03-13 15:27:01 +00:00
|
|
|
if (GST_INDEX_ASSOC_FORMAT (entry, i) == format) {
|
|
|
|
*value = GST_INDEX_ASSOC_VALUE (entry, i);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-12-12 22:16:11 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|