|
Packit |
f546b1 |
/* GStreamer
|
|
Packit |
f546b1 |
* Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* gsttypefind.c: typefinding subsystem
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
f546b1 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
f546b1 |
* License as published by the Free Software Foundation; either
|
|
Packit |
f546b1 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
f546b1 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
f546b1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
f546b1 |
* Library General Public License for more details.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
f546b1 |
* License along with this library; if not, write to the
|
|
Packit |
f546b1 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
f546b1 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
f546b1 |
*/
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/**
|
|
Packit |
f546b1 |
* SECTION:gsttypefind
|
|
Packit |
f546b1 |
* @title: GstTypefind
|
|
Packit |
f546b1 |
* @short_description: Stream type detection
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* The following functions allow you to detect the media type of an unknown
|
|
Packit |
f546b1 |
* stream.
|
|
Packit |
f546b1 |
*/
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
#include "gst_private.h"
|
|
Packit |
f546b1 |
#include "gstinfo.h"
|
|
Packit |
f546b1 |
#include "gsttypefind.h"
|
|
Packit |
f546b1 |
#include "gstregistry.h"
|
|
Packit |
f546b1 |
#include "gsttypefindfactory.h"
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_DEBUG_CATEGORY_EXTERN (type_find_debug);
|
|
Packit |
f546b1 |
#define GST_CAT_DEFAULT type_find_debug
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
G_DEFINE_POINTER_TYPE (GstTypeFind, gst_type_find);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/**
|
|
Packit |
f546b1 |
* gst_type_find_register:
|
|
Packit |
f546b1 |
* @plugin: (allow-none): A #GstPlugin, or %NULL for a static typefind function
|
|
Packit |
f546b1 |
* @name: The name for registering
|
|
Packit |
f546b1 |
* @rank: The rank (or importance) of this typefind function
|
|
Packit |
f546b1 |
* @func: The #GstTypeFindFunction to use
|
|
Packit |
f546b1 |
* @extensions: (allow-none): Optional comma-separated list of extensions
|
|
Packit |
f546b1 |
* that could belong to this type
|
|
Packit |
f546b1 |
* @possible_caps: Optionally the caps that could be returned when typefinding
|
|
Packit |
f546b1 |
* succeeds
|
|
Packit |
f546b1 |
* @data: Optional user data. This user data must be available until the plugin
|
|
Packit |
f546b1 |
* is unloaded.
|
|
Packit |
f546b1 |
* @data_notify: a #GDestroyNotify that will be called on @data when the plugin
|
|
Packit |
f546b1 |
* is unloaded.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* Registers a new typefind function to be used for typefinding. After
|
|
Packit |
f546b1 |
* registering this function will be available for typefinding.
|
|
Packit |
f546b1 |
* This function is typically called during an element's plugin initialization.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* Returns: %TRUE on success, %FALSE otherwise
|
|
Packit |
f546b1 |
*/
|
|
Packit |
f546b1 |
gboolean
|
|
Packit |
f546b1 |
gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank,
|
|
Packit |
f546b1 |
GstTypeFindFunction func, const gchar * extensions,
|
|
Packit |
f546b1 |
GstCaps * possible_caps, gpointer data, GDestroyNotify data_notify)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GstTypeFindFactory *factory;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
g_return_val_if_fail (name != NULL, FALSE);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
GST_INFO ("registering typefind function for %s", name);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
factory = g_object_new (GST_TYPE_TYPE_FIND_FACTORY, NULL);
|
|
Packit |
f546b1 |
GST_DEBUG_OBJECT (factory, "using new typefind factory for %s", name);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
|
|
Packit |
f546b1 |
gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
if (extensions)
|
|
Packit |
f546b1 |
factory->extensions = g_strsplit (extensions, ",", -1);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_caps_replace (&factory->caps, possible_caps);
|
|
Packit |
f546b1 |
factory->function = func;
|
|
Packit |
f546b1 |
factory->user_data = data;
|
|
Packit |
f546b1 |
factory->user_data_notify = data_notify;
|
|
Packit |
f546b1 |
if (plugin && plugin->desc.name) {
|
|
Packit |
f546b1 |
GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name; /* interned string */
|
|
Packit |
f546b1 |
GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin;
|
|
Packit |
f546b1 |
g_object_add_weak_pointer ((GObject *) plugin,
|
|
Packit |
f546b1 |
(gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin);
|
|
Packit |
f546b1 |
} else {
|
|
Packit |
f546b1 |
GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL";
|
|
Packit |
f546b1 |
GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL;
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_registry_add_feature (gst_registry_get (),
|
|
Packit |
f546b1 |
GST_PLUGIN_FEATURE_CAST (factory));
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
return TRUE;
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/*** typefind function interface **********************************************/
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/**
|
|
Packit |
f546b1 |
* gst_type_find_peek:
|
|
Packit |
f546b1 |
* @find: The #GstTypeFind object the function was called with
|
|
Packit |
f546b1 |
* @offset: The offset
|
|
Packit |
f546b1 |
* @size: The number of bytes to return
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* Returns the @size bytes of the stream to identify beginning at offset. If
|
|
Packit |
f546b1 |
* offset is a positive number, the offset is relative to the beginning of the
|
|
Packit |
f546b1 |
* stream, if offset is a negative number the offset is relative to the end of
|
|
Packit |
f546b1 |
* the stream. The returned memory is valid until the typefinding function
|
|
Packit |
f546b1 |
* returns and must not be freed.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* Returns: (transfer none) (array length=size) (nullable): the
|
|
Packit |
f546b1 |
* requested data, or %NULL if that data is not available.
|
|
Packit |
f546b1 |
*/
|
|
Packit |
f546b1 |
const guint8 *
|
|
Packit |
f546b1 |
gst_type_find_peek (GstTypeFind * find, gint64 offset, guint size)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
g_return_val_if_fail (find->peek != NULL, NULL);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
return find->peek (find->data, offset, size);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/**
|
|
Packit |
f546b1 |
* gst_type_find_suggest:
|
|
Packit |
f546b1 |
* @find: The #GstTypeFind object the function was called with
|
|
Packit |
f546b1 |
* @probability: The probability in percent that the suggestion is right
|
|
Packit |
f546b1 |
* @caps: The fixed #GstCaps to suggest
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* If a #GstTypeFindFunction calls this function it suggests the caps with the
|
|
Packit |
f546b1 |
* given probability. A #GstTypeFindFunction may supply different suggestions
|
|
Packit |
f546b1 |
* in one call.
|
|
Packit |
f546b1 |
* It is up to the caller of the #GstTypeFindFunction to interpret these values.
|
|
Packit |
f546b1 |
*/
|
|
Packit |
f546b1 |
void
|
|
Packit |
f546b1 |
gst_type_find_suggest (GstTypeFind * find, guint probability, GstCaps * caps)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
g_return_if_fail (find->suggest != NULL);
|
|
Packit |
f546b1 |
g_return_if_fail (probability <= 100);
|
|
Packit |
f546b1 |
g_return_if_fail (caps != NULL);
|
|
Packit |
f546b1 |
g_return_if_fail (gst_caps_is_fixed (caps));
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
find->suggest (find->data, probability, caps);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/**
|
|
Packit |
f546b1 |
* gst_type_find_suggest_simple:
|
|
Packit |
f546b1 |
* @find: The #GstTypeFind object the function was called with
|
|
Packit |
f546b1 |
* @probability: The probability in percent that the suggestion is right
|
|
Packit |
f546b1 |
* @media_type: the media type of the suggested caps
|
|
Packit |
f546b1 |
* @fieldname: (allow-none): first field of the suggested caps, or %NULL
|
|
Packit |
f546b1 |
* @...: additional arguments to the suggested caps in the same format as the
|
|
Packit |
f546b1 |
* arguments passed to gst_structure_new() (ie. triplets of field name,
|
|
Packit |
f546b1 |
* field GType and field value)
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* If a #GstTypeFindFunction calls this function it suggests the caps with the
|
|
Packit |
f546b1 |
* given probability. A #GstTypeFindFunction may supply different suggestions
|
|
Packit |
f546b1 |
* in one call. It is up to the caller of the #GstTypeFindFunction to interpret
|
|
Packit |
f546b1 |
* these values.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* This function is similar to gst_type_find_suggest(), only that instead of
|
|
Packit |
f546b1 |
* passing a #GstCaps argument you can create the caps on the fly in the same
|
|
Packit |
f546b1 |
* way as you can with gst_caps_new_simple().
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* Make sure you terminate the list of arguments with a %NULL argument and that
|
|
Packit |
f546b1 |
* the values passed have the correct type (in terms of width in bytes when
|
|
Packit |
f546b1 |
* passed to the vararg function - this applies particularly to gdouble and
|
|
Packit |
f546b1 |
* guint64 arguments).
|
|
Packit |
f546b1 |
*/
|
|
Packit |
f546b1 |
void
|
|
Packit |
f546b1 |
gst_type_find_suggest_simple (GstTypeFind * find, guint probability,
|
|
Packit |
f546b1 |
const char *media_type, const char *fieldname, ...)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
GstStructure *structure;
|
|
Packit |
f546b1 |
va_list var_args;
|
|
Packit |
f546b1 |
GstCaps *caps;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
g_return_if_fail (find->suggest != NULL);
|
|
Packit |
f546b1 |
g_return_if_fail (probability <= 100);
|
|
Packit |
f546b1 |
g_return_if_fail (media_type != NULL);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
caps = gst_caps_new_empty ();
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
va_start (var_args, fieldname);
|
|
Packit |
f546b1 |
structure = gst_structure_new_valist (media_type, fieldname, var_args);
|
|
Packit |
f546b1 |
va_end (var_args);
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
gst_caps_append_structure (caps, structure);
|
|
Packit |
f546b1 |
g_return_if_fail (gst_caps_is_fixed (caps));
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
find->suggest (find->data, probability, caps);
|
|
Packit |
f546b1 |
gst_caps_unref (caps);
|
|
Packit |
f546b1 |
}
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
/**
|
|
Packit |
f546b1 |
* gst_type_find_get_length:
|
|
Packit |
f546b1 |
* @find: The #GstTypeFind the function was called with
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* Get the length of the data stream.
|
|
Packit |
f546b1 |
*
|
|
Packit |
f546b1 |
* Returns: The length of the data stream, or 0 if it is not available.
|
|
Packit |
f546b1 |
*/
|
|
Packit |
f546b1 |
guint64
|
|
Packit |
f546b1 |
gst_type_find_get_length (GstTypeFind * find)
|
|
Packit |
f546b1 |
{
|
|
Packit |
f546b1 |
if (find->get_length == NULL)
|
|
Packit |
f546b1 |
return 0;
|
|
Packit |
f546b1 |
|
|
Packit |
f546b1 |
return find->get_length (find->data);
|
|
Packit |
f546b1 |
}
|