2001-01-19 00:02:53 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gsttypefind.c:
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "gst_private.h"
|
|
|
|
|
|
|
|
#include "gsttype.h"
|
|
|
|
|
|
|
|
#include "gsttypefind.h"
|
|
|
|
|
|
|
|
//#define GST_DEBUG_ENABLED
|
|
|
|
|
|
|
|
GstElementDetails gst_typefind_details = {
|
|
|
|
"TypeFind",
|
|
|
|
"TypeFind",
|
|
|
|
"Finds the media type",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>"
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* TypeFind signals and args */
|
|
|
|
enum {
|
|
|
|
HAVE_TYPE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_CAPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void gst_typefind_class_init (GstTypeFindClass *klass);
|
|
|
|
static void gst_typefind_init (GstTypeFind *typefind);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
static void gst_typefind_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_typefind_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void gst_typefind_chain (GstPad *pad, GstBuffer *buf);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
static guint gst_typefind_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
GType
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_typefind_get_type (void)
|
|
|
|
{
|
2001-06-13 21:52:36 +00:00
|
|
|
static GType typefind_type = 0;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
if (!typefind_type) {
|
2001-06-13 21:52:36 +00:00
|
|
|
static const GTypeInfo typefind_info = {
|
2001-01-19 00:02:53 +00:00
|
|
|
sizeof(GstTypeFindClass),
|
2001-06-13 21:52:36 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_typefind_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstTypeFind),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_typefind_init,
|
2001-01-19 00:02:53 +00:00
|
|
|
};
|
2001-06-13 21:52:36 +00:00
|
|
|
typefind_type = g_type_register_static (GST_TYPE_ELEMENT, "GstTypeFind", &typefind_info, 0);
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
return typefind_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_typefind_class_init (GstTypeFindClass *klass)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
2001-06-13 21:52:36 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
gobject_class = (GObjectClass*)klass;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CAPS,
|
|
|
|
g_param_spec_pointer("caps", "Caps", "Found capabilities", G_PARAM_READABLE));
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
gst_typefind_signals[HAVE_TYPE] =
|
2001-06-13 21:52:36 +00:00
|
|
|
g_signal_newc ("have_type", G_OBJECT_TYPE(gobject_class), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstTypeFindClass, have_type), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_POINTER);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
gobject_class->set_property = gst_typefind_set_property;
|
|
|
|
gobject_class->get_property = gst_typefind_get_property;
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
|
|
|
gst_typefind_init (GstTypeFind *typefind)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
typefind->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (typefind), typefind->sinkpad);
|
|
|
|
gst_pad_set_chain_function (typefind->sinkpad, gst_typefind_chain);
|
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
2001-06-13 21:52:36 +00:00
|
|
|
gst_typefind_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_TYPEFIND (object));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-01-19 00:02:53 +00:00
|
|
|
typefind = GST_TYPEFIND (object);
|
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
switch (prop_id) {
|
2001-01-19 00:02:53 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
2001-06-13 21:52:36 +00:00
|
|
|
gst_typefind_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_TYPEFIND (object));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-01-19 00:02:53 +00:00
|
|
|
typefind = GST_TYPEFIND (object);
|
|
|
|
|
2001-06-13 21:52:36 +00:00
|
|
|
switch (prop_id) {
|
2001-01-19 00:02:53 +00:00
|
|
|
case ARG_CAPS:
|
2001-06-13 21:52:36 +00:00
|
|
|
g_value_set_pointer(value, typefind->caps);
|
2001-01-19 00:02:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
|
|
|
gst_typefind_chain (GstPad *pad, GstBuffer *buf)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
|
|
|
GList *type_list;
|
|
|
|
GstType *type;
|
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
typefind = GST_TYPEFIND (GST_OBJECT_PARENT (pad));
|
2001-01-19 00:02:53 +00:00
|
|
|
GST_DEBUG (0,"got buffer of %d bytes in '%s'\n",
|
2001-01-29 00:06:02 +00:00
|
|
|
GST_BUFFER_SIZE (buf), GST_OBJECT_NAME (typefind));
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
type_list = gst_type_get_list ();
|
|
|
|
|
|
|
|
while (type_list) {
|
|
|
|
GSList *funcs;
|
|
|
|
type = (GstType *)type_list->data;
|
|
|
|
|
|
|
|
funcs = type->typefindfuncs;
|
|
|
|
|
|
|
|
while (funcs) {
|
|
|
|
GstTypeFindFunc typefindfunc = (GstTypeFindFunc)funcs->data;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
GST_DEBUG (0,"try type :%d \"%s\"\n", type->id, type->mime);
|
|
|
|
if (typefindfunc && (caps = typefindfunc (buf, type))) {
|
2001-05-25 21:00:07 +00:00
|
|
|
GST_DEBUG (0,"found type :%d \"%s\" \"%s\"\n", caps->id, type->mime,
|
|
|
|
gst_caps_get_name (caps));
|
2001-01-19 00:02:53 +00:00
|
|
|
typefind->caps = caps;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
gst_pad_set_caps (pad, caps);
|
|
|
|
|
|
|
|
{ /* FIXME: this should all be in an _emit() wrapper eventually */
|
|
|
|
int oldstate = GST_STATE(typefind);
|
|
|
|
gst_object_ref (GST_OBJECT (typefind));
|
2001-06-13 21:52:36 +00:00
|
|
|
g_signal_emit (G_OBJECT (typefind), gst_typefind_signals[HAVE_TYPE], 0,
|
2001-01-19 00:02:53 +00:00
|
|
|
typefind->caps);
|
2001-05-25 21:00:07 +00:00
|
|
|
if (GST_STATE(typefind) != oldstate) {
|
|
|
|
gst_object_unref (GST_OBJECT (typefind));
|
|
|
|
GST_DEBUG(0, "state changed during signal, aborting\n");
|
|
|
|
cothread_switch(cothread_current_main());
|
|
|
|
}
|
|
|
|
gst_object_unref (GST_OBJECT (typefind));
|
|
|
|
}
|
|
|
|
|
2001-01-19 00:02:53 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
funcs = g_slist_next (funcs);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_list = g_list_next (type_list);
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|