mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
merge TYPEFIND branch. Major changes:
Original commit message from CVS: merge TYPEFIND branch. Major changes: - totally reworked type(find) system - all typefind functions are in gst/typefind now - more typefind functions then before - some plugins might fail to compile now because I don't have them installed and they a) require bytestream or b) haven't had their typefind fixed. Please fix those plugins and put the typefind functions into gst/typefind if they don't have dependencies
This commit is contained in:
parent
c92678bb20
commit
98063f8cd3
3 changed files with 26 additions and 50 deletions
|
@ -42,6 +42,9 @@ extern URLProtocol gstreamer_protocol;
|
||||||
static gboolean
|
static gboolean
|
||||||
plugin_init (GModule *module, GstPlugin *plugin)
|
plugin_init (GModule *module, GstPlugin *plugin)
|
||||||
{
|
{
|
||||||
|
if (!gst_library_load ("gstbytestream"))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
avcodec_init ();
|
avcodec_init ();
|
||||||
avcodec_register_all ();
|
avcodec_register_all ();
|
||||||
av_register_all ();
|
av_register_all ();
|
||||||
|
|
|
@ -54,7 +54,6 @@ typedef struct _GstFFMpegDemuxClassParams {
|
||||||
GstPadTemplate *sinktempl;
|
GstPadTemplate *sinktempl;
|
||||||
GstPadTemplate *videosrctempl;
|
GstPadTemplate *videosrctempl;
|
||||||
GstPadTemplate *audiosrctempl;
|
GstPadTemplate *audiosrctempl;
|
||||||
GstPluginFeature *typefind_feature;
|
|
||||||
} GstFFMpegDemuxClassParams;
|
} GstFFMpegDemuxClassParams;
|
||||||
|
|
||||||
typedef struct _GstFFMpegDemuxClass GstFFMpegDemuxClass;
|
typedef struct _GstFFMpegDemuxClass GstFFMpegDemuxClass;
|
||||||
|
@ -66,7 +65,6 @@ struct _GstFFMpegDemuxClass {
|
||||||
GstPadTemplate *sinktempl;
|
GstPadTemplate *sinktempl;
|
||||||
GstPadTemplate *videosrctempl;
|
GstPadTemplate *videosrctempl;
|
||||||
GstPadTemplate *audiosrctempl;
|
GstPadTemplate *audiosrctempl;
|
||||||
GstPluginFeature *typefind_feature;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GST_TYPE_FFMPEGDEC \
|
#define GST_TYPE_FFMPEGDEC \
|
||||||
|
@ -90,7 +88,7 @@ enum {
|
||||||
/* FILL ME */
|
/* FILL ME */
|
||||||
};
|
};
|
||||||
|
|
||||||
static GHashTable *global_plugins, *typefind;
|
static GHashTable *global_plugins;
|
||||||
|
|
||||||
/* A number of functon prototypes are given so we can refer to them later. */
|
/* A number of functon prototypes are given so we can refer to them later. */
|
||||||
static void gst_ffmpegdemux_class_init (GstFFMpegDemuxClass *klass);
|
static void gst_ffmpegdemux_class_init (GstFFMpegDemuxClass *klass);
|
||||||
|
@ -122,7 +120,6 @@ gst_ffmpegdemux_class_init (GstFFMpegDemuxClass *klass)
|
||||||
GINT_TO_POINTER (G_OBJECT_CLASS_TYPE (gobject_class)));
|
GINT_TO_POINTER (G_OBJECT_CLASS_TYPE (gobject_class)));
|
||||||
|
|
||||||
klass->in_plugin = params->in_plugin;
|
klass->in_plugin = params->in_plugin;
|
||||||
klass->typefind_feature = params->typefind_feature;
|
|
||||||
klass->videosrctempl = params->videosrctempl;
|
klass->videosrctempl = params->videosrctempl;
|
||||||
klass->audiosrctempl = params->audiosrctempl;
|
klass->audiosrctempl = params->audiosrctempl;
|
||||||
klass->sinktempl = params->sinktempl;
|
klass->sinktempl = params->sinktempl;
|
||||||
|
@ -160,45 +157,32 @@ gst_ffmpegdemux_dispose (GObject *object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstCaps*
|
#define GST_FFMPEG_TYPE_FIND_SIZE 4096
|
||||||
gst_ffmpegdemux_typefind (GstByteStream *bs,
|
static void
|
||||||
gpointer priv)
|
gst_ffmpegdemux_type_find (GstTypeFind *tf, gpointer priv)
|
||||||
{
|
{
|
||||||
GstFFMpegDemuxClassParams *params;
|
guint8 *data;
|
||||||
AVInputFormat *in_plugin;
|
GstFFMpegDemuxClassParams *params = (GstFFMpegDemuxClassParams *) priv;
|
||||||
|
AVInputFormat *in_plugin = params->in_plugin;
|
||||||
gint res = 0;
|
gint res = 0;
|
||||||
gint required = AVPROBE_SCORE_MAX * 0.8; /* 80% certainty enough? */
|
|
||||||
gint size_required = 4096;
|
|
||||||
GstBuffer *buf = NULL;
|
|
||||||
|
|
||||||
params = g_hash_table_lookup (typefind, priv);
|
|
||||||
|
|
||||||
in_plugin = params->in_plugin;
|
|
||||||
|
|
||||||
if (in_plugin->read_probe &&
|
if (in_plugin->read_probe &&
|
||||||
gst_bytestream_peek (bs, &buf, size_required) == size_required) {
|
(data = gst_type_find_peek (tf, 0, GST_FFMPEG_TYPE_FIND_SIZE)) != NULL) {
|
||||||
AVProbeData probe_data;
|
AVProbeData probe_data;
|
||||||
|
|
||||||
probe_data.filename = "";
|
probe_data.filename = "";
|
||||||
probe_data.buf = GST_BUFFER_DATA (buf);
|
probe_data.buf = data;
|
||||||
probe_data.buf_size = GST_BUFFER_SIZE (buf);
|
probe_data.buf_size = GST_FFMPEG_TYPE_FIND_SIZE;
|
||||||
|
|
||||||
res = in_plugin->read_probe (&probe_data);
|
res = in_plugin->read_probe (&probe_data);
|
||||||
if (res >= required) {
|
res = res * GST_TYPE_FIND_MAXIMUM / AVPROBE_SCORE_MAX;
|
||||||
GstCaps *caps;
|
if (res > 0) {
|
||||||
caps = GST_PAD_TEMPLATE_CAPS (params->sinktempl);
|
GstCaps *caps = GST_PAD_TEMPLATE_CAPS (params->sinktempl);
|
||||||
/* make sure we still hold a refcount to this caps */
|
/* make sure we still hold a refcount to this caps */
|
||||||
gst_caps_ref (caps);
|
gst_caps_ref (caps);
|
||||||
gst_buffer_unref (buf);
|
gst_type_find_suggest (tf, res, caps);
|
||||||
return caps;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf != NULL) {
|
|
||||||
gst_buffer_unref (buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -362,8 +346,6 @@ gboolean
|
||||||
gst_ffmpegdemux_register (GstPlugin *plugin)
|
gst_ffmpegdemux_register (GstPlugin *plugin)
|
||||||
{
|
{
|
||||||
GstElementFactory *factory;
|
GstElementFactory *factory;
|
||||||
GstTypeFactory *type_factory;
|
|
||||||
GstTypeDefinition *type_definition;
|
|
||||||
GTypeInfo typeinfo = {
|
GTypeInfo typeinfo = {
|
||||||
sizeof(GstFFMpegDemuxClass),
|
sizeof(GstFFMpegDemuxClass),
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -380,11 +362,11 @@ gst_ffmpegdemux_register (GstPlugin *plugin)
|
||||||
AVInputFormat *in_plugin;
|
AVInputFormat *in_plugin;
|
||||||
GstFFMpegDemuxClassParams *params;
|
GstFFMpegDemuxClassParams *params;
|
||||||
AVCodec *in_codec;
|
AVCodec *in_codec;
|
||||||
|
gchar **extensions;
|
||||||
|
|
||||||
in_plugin = first_iformat;
|
in_plugin = first_iformat;
|
||||||
|
|
||||||
global_plugins = g_hash_table_new (NULL, NULL);
|
global_plugins = g_hash_table_new (NULL, NULL);
|
||||||
typefind = g_hash_table_new (NULL, NULL);
|
|
||||||
|
|
||||||
while (in_plugin) {
|
while (in_plugin) {
|
||||||
gchar *type_name;
|
gchar *type_name;
|
||||||
|
@ -456,20 +438,9 @@ gst_ffmpegdemux_register (GstPlugin *plugin)
|
||||||
factory = gst_element_factory_new(type_name,type,details);
|
factory = gst_element_factory_new(type_name,type,details);
|
||||||
g_return_val_if_fail(factory != NULL, FALSE);
|
g_return_val_if_fail(factory != NULL, FALSE);
|
||||||
|
|
||||||
/* typefind info */
|
|
||||||
type_definition = g_new0 (GstTypeDefinition, 1);
|
|
||||||
type_definition->name = g_strdup_printf ("fftype_%s",
|
|
||||||
in_plugin->name);
|
|
||||||
type_definition->mime = g_strdup (gst_caps_get_mime (sinkcaps));
|
|
||||||
type_definition->exts = g_strdup (in_plugin->extensions);
|
|
||||||
type_definition->typefindfunc = gst_ffmpegdemux_typefind;
|
|
||||||
|
|
||||||
type_factory = gst_type_factory_new (type_definition);
|
|
||||||
|
|
||||||
/* create a cache for these properties */
|
/* create a cache for these properties */
|
||||||
params = g_new0 (GstFFMpegDemuxClassParams, 1);
|
params = g_new0 (GstFFMpegDemuxClassParams, 1);
|
||||||
params->in_plugin = in_plugin;
|
params->in_plugin = in_plugin;
|
||||||
params->typefind_feature = GST_PLUGIN_FEATURE (type_factory);
|
|
||||||
params->sinktempl = gst_pad_template_new ("sink", GST_PAD_SINK,
|
params->sinktempl = gst_pad_template_new ("sink", GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
sinkcaps, NULL);
|
sinkcaps, NULL);
|
||||||
|
@ -488,19 +459,21 @@ gst_ffmpegdemux_register (GstPlugin *plugin)
|
||||||
gst_element_factory_add_pad_template (factory,
|
gst_element_factory_add_pad_template (factory,
|
||||||
params->videosrctempl);
|
params->videosrctempl);
|
||||||
|
|
||||||
|
/* typefind registering */
|
||||||
|
extensions = g_strsplit (in_plugin->extensions, " ", 0);
|
||||||
|
gst_type_find_factory_register (plugin, g_strdup_printf ("fftype_%s", in_plugin->name),
|
||||||
|
GST_ELEMENT_RANK_MARGINAL, gst_ffmpegdemux_type_find,
|
||||||
|
extensions, GST_CAPS_ANY, params);
|
||||||
|
g_strfreev (extensions);
|
||||||
|
|
||||||
g_hash_table_insert (global_plugins,
|
g_hash_table_insert (global_plugins,
|
||||||
GINT_TO_POINTER (type),
|
GINT_TO_POINTER (type),
|
||||||
(gpointer) params);
|
(gpointer) params);
|
||||||
|
|
||||||
g_hash_table_insert (typefind,
|
|
||||||
(gpointer) type_factory,
|
|
||||||
(gpointer) params);
|
|
||||||
|
|
||||||
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_MARGINAL);
|
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_MARGINAL);
|
||||||
|
|
||||||
/* The very last thing is to register the elementfactory with the plugin. */
|
/* The very last thing is to register the elementfactory with the plugin. */
|
||||||
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
||||||
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type_factory));
|
|
||||||
|
|
||||||
next:
|
next:
|
||||||
in_plugin = in_plugin->next;
|
in_plugin = in_plugin->next;
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/gstbytestream.h>
|
#include <gst/bytestream.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GstProtocolInfo GstProtocolInfo;
|
typedef struct _GstProtocolInfo GstProtocolInfo;
|
||||||
|
|
Loading…
Reference in a new issue