2001-01-19 00:02:53 +00:00
|
|
|
/* GStreamer
|
2003-10-28 20:25:30 +00:00
|
|
|
* Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
2001-01-19 00:02:53 +00:00
|
|
|
*
|
gst/: splitted gsttypefind into gsttypefind, gsttypefindfactory
Original commit message from CVS:
* gst/Makefile.am:
* gst/elements/gstbufferstore.h:
* gst/elements/gsttypefindelement.c:
* gst/elements/gsttypefindelement.h:
* gst/gst.h:
* gst/gsttypefind.c:
* gst/gsttypefind.h:
* gst/gsttypefindfactory.c: (gst_type_find_factory_get_type),
(gst_type_find_factory_class_init), (gst_type_find_factory_init),
(gst_type_find_factory_dispose),
(gst_type_find_factory_unload_thyself),
(gst_type_find_load_plugin), (gst_type_find_factory_get_list),
(gst_type_find_factory_get_caps),
(gst_type_find_factory_get_extensions),
(gst_type_find_factory_call_function):
* gst/gsttypefindfactory.h:
* gst/registries/gstlibxmlregistry.c:
* gst/registries/gstxmlregistry.c:
splitted gsttypefind into gsttypefind, gsttypefindfactory
2005-09-07 12:35:23 +00:00
|
|
|
* gsttypefind.c: typefinding subsystem
|
2001-01-19 00:02:53 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2001-01-19 00:02:53 +00:00
|
|
|
*/
|
2005-10-15 16:01:57 +00:00
|
|
|
|
2005-09-06 22:03:01 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gsttypefind
|
|
|
|
* @short_description: Stream type detection
|
|
|
|
*
|
2005-11-09 16:44:40 +00:00
|
|
|
* The following functions allow you to detect the media type of an unknown
|
|
|
|
* stream.
|
|
|
|
*
|
|
|
|
* Last reviewed on 2005-11-09 (0.9.4)
|
2005-09-06 22:03:01 +00:00
|
|
|
*/
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2004-05-03 16:03:24 +00:00
|
|
|
#include "gst_private.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2001-01-19 00:02:53 +00:00
|
|
|
#include "gsttypefind.h"
|
2005-09-15 00:13:26 +00:00
|
|
|
#include "gstregistry.h"
|
gst/: splitted gsttypefind into gsttypefind, gsttypefindfactory
Original commit message from CVS:
* gst/Makefile.am:
* gst/elements/gstbufferstore.h:
* gst/elements/gsttypefindelement.c:
* gst/elements/gsttypefindelement.h:
* gst/gst.h:
* gst/gsttypefind.c:
* gst/gsttypefind.h:
* gst/gsttypefindfactory.c: (gst_type_find_factory_get_type),
(gst_type_find_factory_class_init), (gst_type_find_factory_init),
(gst_type_find_factory_dispose),
(gst_type_find_factory_unload_thyself),
(gst_type_find_load_plugin), (gst_type_find_factory_get_list),
(gst_type_find_factory_get_caps),
(gst_type_find_factory_get_extensions),
(gst_type_find_factory_call_function):
* gst/gsttypefindfactory.h:
* gst/registries/gstlibxmlregistry.c:
* gst/registries/gstxmlregistry.c:
splitted gsttypefind into gsttypefind, gsttypefindfactory
2005-09-07 12:35:23 +00:00
|
|
|
#include "gsttypefindfactory.h"
|
2003-10-28 20:25:30 +00:00
|
|
|
|
Makefile.am: Add check-exports target and run it as part of 'make check' (see #499140 and #493983).
Original commit message from CVS:
* Makefile.am:
Add check-exports target and run it as part of 'make check'
(see #499140 and #493983).
* gst/gst_private.h:
* gst/gstelementfactory.h:
* gst/gstghostpad.c: (gst_proxy_pad_class_init):
* gst/gstinfo.c: (_priv_gst_in_valgrind), (_gst_debug_init),
(_priv_gst_in_valgrind):
* gst/gstinfo.h: (GstLogFunction):
* gst/gsttypefind.c: (type_find_debug), (GST_CAT_DEFAULT),
(gst_type_find_register):
* gst/gsttypefindfactory.c: (type_find_debug), (GST_CAT_DEFAULT),
(gst_type_find_factory_get_type):
* libs/gst/controller/gstcontroller.c: (GST_CAT_DEFAULT),
(GST_CAT_DEFAULT), (parent_class), (priv_gst_controller_key),
(gst_controller_new_valist), (gst_controller_new_list),
(_gst_controller_dispose), (_gst_controller_class_init):
* libs/gst/controller/gstcontrolsource.c: (GST_CAT_DEFAULT):
* libs/gst/controller/gsthelper.c: (GST_CAT_DEFAULT),
(GST_CAT_DEFAULT), (gst_object_uncontrol_properties),
(gst_object_get_controller), (gst_object_set_controller),
(gst_object_suggest_next_sync), (gst_object_sync_values),
(gst_object_set_control_source), (gst_object_get_control_source),
(gst_object_get_value_arrays), (gst_object_get_value_array),
(gst_object_get_control_rate), (gst_object_set_control_rate):
* libs/gst/controller/gstinterpolation.c: (GST_CAT_DEFAULT):
* libs/gst/controller/lib.c: (GST_CAT_DEFAULT):
Make some functions that should be static static; rename some
private symbols so that they don't get exported; add some FIXME
comments so we can move accidentally exported functions into
our private section in 0.11.
* win32/common/libgstreamer.def:
Add gst_utils_get_timestamp().
2007-12-12 23:20:00 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (type_find_debug);
|
|
|
|
#define GST_CAT_DEFAULT type_find_debug
|
2003-10-28 20:25:30 +00:00
|
|
|
|
2012-01-28 14:35:51 +00:00
|
|
|
G_DEFINE_POINTER_TYPE (GstTypeFind, gst_type_find);
|
2006-05-18 14:25:00 +00:00
|
|
|
|
2003-10-28 20:25:30 +00:00
|
|
|
/**
|
2003-10-31 19:32:47 +00:00
|
|
|
* gst_type_find_register:
|
2012-07-10 09:46:41 +00:00
|
|
|
* @plugin: A #GstPlugin, or NULL for a static typefind function
|
2005-11-09 16:44:40 +00:00
|
|
|
* @name: The name for registering
|
|
|
|
* @rank: The rank (or importance) of this typefind function
|
|
|
|
* @func: The #GstTypeFindFunction to use
|
2012-02-02 01:30:12 +00:00
|
|
|
* @extensions: (allow-none): Optional comma-separated list of extensions
|
|
|
|
* that could belong to this type
|
2006-05-24 09:00:47 +00:00
|
|
|
* @possible_caps: Optionally the caps that could be returned when typefinding
|
|
|
|
* succeeds
|
2005-11-09 16:44:40 +00:00
|
|
|
* @data: Optional user data. This user data must be available until the plugin
|
2005-12-06 19:29:15 +00:00
|
|
|
* is unloaded.
|
2005-11-29 23:56:20 +00:00
|
|
|
* @data_notify: a #GDestroyNotify that will be called on @data when the plugin
|
2005-12-06 19:29:15 +00:00
|
|
|
* is unloaded.
|
2003-10-28 20:25:30 +00:00
|
|
|
*
|
2005-10-15 15:30:24 +00:00
|
|
|
* Registers a new typefind function to be used for typefinding. After
|
2003-10-28 20:25:30 +00:00
|
|
|
* registering this function will be available for typefinding.
|
|
|
|
* This function is typically called during an element's plugin initialization.
|
|
|
|
*
|
|
|
|
* Returns: TRUE on success, FALSE otherwise
|
|
|
|
*/
|
2003-10-31 19:32:47 +00:00
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank,
|
2012-02-02 01:30:12 +00:00
|
|
|
GstTypeFindFunction func, const gchar * extensions,
|
2011-12-20 12:13:04 +00:00
|
|
|
GstCaps * possible_caps, gpointer data, GDestroyNotify data_notify)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
2003-10-28 20:25:30 +00:00
|
|
|
GstTypeFindFactory *factory;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
2003-10-28 20:25:30 +00:00
|
|
|
|
|
|
|
GST_INFO ("registering typefind function for %s", name);
|
2005-09-16 03:46:14 +00:00
|
|
|
|
2009-10-28 08:26:32 +00:00
|
|
|
factory = g_object_newv (GST_TYPE_TYPE_FIND_FACTORY, 0, NULL);
|
2005-09-16 03:46:14 +00:00
|
|
|
GST_DEBUG_OBJECT (factory, "using new typefind factory for %s", name);
|
|
|
|
g_assert (GST_IS_TYPE_FIND_FACTORY (factory));
|
2003-01-17 20:41:04 +00:00
|
|
|
|
2009-11-02 07:28:20 +00:00
|
|
|
gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
|
|
|
|
gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
|
2008-10-31 14:24:49 +00:00
|
|
|
|
2012-02-02 01:30:12 +00:00
|
|
|
if (factory->extensions) {
|
2003-10-28 20:25:30 +00:00
|
|
|
g_strfreev (factory->extensions);
|
2012-02-02 01:30:12 +00:00
|
|
|
factory->extensions = NULL;
|
|
|
|
}
|
|
|
|
if (extensions)
|
|
|
|
factory->extensions = g_strsplit (extensions, ",", -1);
|
2008-10-31 14:24:49 +00:00
|
|
|
|
2011-12-20 12:13:04 +00:00
|
|
|
gst_caps_replace (&factory->caps, possible_caps);
|
2003-10-28 20:25:30 +00:00
|
|
|
factory->function = func;
|
|
|
|
factory->user_data = data;
|
2005-11-29 23:56:20 +00:00
|
|
|
factory->user_data_notify = data_notify;
|
2007-12-21 20:58:23 +00:00
|
|
|
if (plugin && plugin->desc.name) {
|
2009-11-02 07:28:20 +00:00
|
|
|
GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name; /* interned string */
|
2011-04-24 08:53:39 +00:00
|
|
|
GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
|
|
|
|
g_object_add_weak_pointer ((GObject *) plugin,
|
|
|
|
(gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
|
2007-12-21 20:58:23 +00:00
|
|
|
} else {
|
2009-11-02 07:28:20 +00:00
|
|
|
GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
|
2011-04-24 08:53:39 +00:00
|
|
|
GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
|
2007-12-21 20:58:23 +00:00
|
|
|
}
|
2009-11-02 07:28:20 +00:00
|
|
|
GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
|
2005-09-18 06:59:25 +00:00
|
|
|
|
2012-01-02 02:22:51 +00:00
|
|
|
gst_registry_add_feature (gst_registry_get (),
|
2009-11-02 08:48:51 +00:00
|
|
|
GST_PLUGIN_FEATURE_CAST (factory));
|
2003-10-28 20:25:30 +00:00
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
return TRUE;
|
2003-01-17 20:41:04 +00:00
|
|
|
}
|
|
|
|
|
2003-10-28 20:25:30 +00:00
|
|
|
/*** typefind function interface **********************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_type_find_peek:
|
2005-11-09 16:44:40 +00:00
|
|
|
* @find: The #GstTypeFind object the function was called with
|
|
|
|
* @offset: The offset
|
|
|
|
* @size: The number of bytes to return
|
2003-10-28 20:25:30 +00:00
|
|
|
*
|
2005-11-09 16:44:40 +00:00
|
|
|
* Returns the @size bytes of the stream to identify beginning at offset. If
|
|
|
|
* offset is a positive number, the offset is relative to the beginning of the
|
|
|
|
* stream, if offset is a negative number the offset is relative to the end of
|
|
|
|
* the stream. The returned memory is valid until the typefinding function
|
|
|
|
* returns and must not be freed.
|
2003-10-28 20:25:30 +00:00
|
|
|
*
|
2010-12-07 18:35:04 +00:00
|
|
|
* Returns: (transfer none) (array length=size): the requested data, or NULL
|
|
|
|
* if that data is not available.
|
2003-10-28 20:25:30 +00:00
|
|
|
*/
|
2011-03-21 17:13:55 +00:00
|
|
|
const guint8 *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_type_find_peek (GstTypeFind * find, gint64 offset, guint size)
|
2003-01-17 20:41:04 +00:00
|
|
|
{
|
2003-10-28 20:25:30 +00:00
|
|
|
g_return_val_if_fail (find->peek != NULL, NULL);
|
|
|
|
|
|
|
|
return find->peek (find->data, offset, size);
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-10-28 20:25:30 +00:00
|
|
|
/**
|
|
|
|
* gst_type_find_suggest:
|
2005-11-09 16:44:40 +00:00
|
|
|
* @find: The #GstTypeFind object the function was called with
|
|
|
|
* @probability: The probability in percent that the suggestion is right
|
|
|
|
* @caps: The fixed #GstCaps to suggest
|
2003-10-28 20:25:30 +00:00
|
|
|
*
|
2005-11-09 16:44:40 +00:00
|
|
|
* If a #GstTypeFindFunction calls this function it suggests the caps with the
|
|
|
|
* given probability. A #GstTypeFindFunction may supply different suggestions
|
2003-10-28 20:25:30 +00:00
|
|
|
* in one call.
|
2005-11-09 16:44:40 +00:00
|
|
|
* It is up to the caller of the #GstTypeFindFunction to interpret these values.
|
2003-10-28 20:25:30 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-03-10 08:25:43 +00:00
|
|
|
gst_type_find_suggest (GstTypeFind * find, guint probability, GstCaps * caps)
|
2003-10-28 20:25:30 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (find->suggest != NULL);
|
|
|
|
g_return_if_fail (probability <= 100);
|
|
|
|
g_return_if_fail (caps != NULL);
|
2003-12-22 01:39:35 +00:00
|
|
|
g_return_if_fail (gst_caps_is_fixed (caps));
|
2003-10-28 20:25:30 +00:00
|
|
|
|
|
|
|
find->suggest (find->data, probability, caps);
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2008-05-19 10:46:44 +00:00
|
|
|
/**
|
|
|
|
* gst_type_find_suggest_simple:
|
|
|
|
* @find: The #GstTypeFind object the function was called with
|
|
|
|
* @probability: The probability in percent that the suggestion is right
|
|
|
|
* @media_type: the media type of the suggested caps
|
|
|
|
* @fieldname: first field of the suggested caps, or NULL
|
|
|
|
* @...: additional arguments to the suggested caps in the same format as the
|
|
|
|
* arguments passed to gst_structure_new() (ie. triplets of field name,
|
|
|
|
* field GType and field value)
|
|
|
|
*
|
|
|
|
* If a #GstTypeFindFunction calls this function it suggests the caps with the
|
|
|
|
* given probability. A #GstTypeFindFunction may supply different suggestions
|
|
|
|
* in one call. It is up to the caller of the #GstTypeFindFunction to interpret
|
|
|
|
* these values.
|
|
|
|
*
|
|
|
|
* This function is similar to gst_type_find_suggest(), only that instead of
|
|
|
|
* passing a #GstCaps argument you can create the caps on the fly in the same
|
|
|
|
* way as you can with gst_caps_new_simple().
|
|
|
|
*
|
|
|
|
* Make sure you terminate the list of arguments with a NULL argument and that
|
|
|
|
* the values passed have the correct type (in terms of width in bytes when
|
|
|
|
* passed to the vararg function - this applies particularly to gdouble and
|
|
|
|
* guint64 arguments).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_type_find_suggest_simple (GstTypeFind * find, guint probability,
|
|
|
|
const char *media_type, const char *fieldname, ...)
|
|
|
|
{
|
|
|
|
GstStructure *structure;
|
|
|
|
va_list var_args;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
g_return_if_fail (find->suggest != NULL);
|
|
|
|
g_return_if_fail (probability <= 100);
|
|
|
|
g_return_if_fail (media_type != NULL);
|
|
|
|
|
|
|
|
caps = gst_caps_new_empty ();
|
|
|
|
|
|
|
|
va_start (var_args, fieldname);
|
|
|
|
structure = gst_structure_new_valist (media_type, fieldname, var_args);
|
|
|
|
va_end (var_args);
|
|
|
|
|
|
|
|
gst_caps_append_structure (caps, structure);
|
|
|
|
g_return_if_fail (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
find->suggest (find->data, probability, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
2003-10-28 20:25:30 +00:00
|
|
|
/**
|
|
|
|
* gst_type_find_get_length:
|
2005-11-09 16:44:40 +00:00
|
|
|
* @find: The #GstTypeFind the function was called with
|
2003-10-28 20:25:30 +00:00
|
|
|
*
|
|
|
|
* Get the length of the data stream.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
2005-11-09 16:44:40 +00:00
|
|
|
* Returns: The length of the data stream, or 0 if it is not available.
|
2003-10-28 20:25:30 +00:00
|
|
|
*/
|
|
|
|
guint64
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_type_find_get_length (GstTypeFind * find)
|
2003-10-28 20:25:30 +00:00
|
|
|
{
|
|
|
|
if (find->get_length == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
return find->get_length (find->data);
|
2003-10-28 20:25:30 +00:00
|
|
|
}
|