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"
|
|
|
|
|
2002-07-08 19:07:30 +00:00
|
|
|
#include "gstlog.h"
|
2001-01-19 00:02:53 +00:00
|
|
|
#include "gsttypefind.h"
|
|
|
|
|
2001-12-14 22:59:21 +00:00
|
|
|
/* #define GST_DEBUG_ENABLED */
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
GstElementDetails gst_type_find_details = {
|
2001-01-19 00:02:53 +00:00
|
|
|
"TypeFind",
|
2002-04-20 21:42:53 +00:00
|
|
|
"Generic",
|
2002-09-29 18:12:52 +00:00
|
|
|
"LGPL",
|
2002-04-20 21:42:53 +00:00
|
|
|
"Finds the media type of a stream",
|
2001-01-19 00:02:53 +00:00
|
|
|
VERSION,
|
2002-10-29 17:36:41 +00:00
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>,"
|
2001-01-19 00:02:53 +00:00
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* TypeFind signals and args */
|
|
|
|
enum {
|
|
|
|
HAVE_TYPE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_CAPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-10-29 17:36:41 +00:00
|
|
|
static void gst_type_find_class_init (GstTypeFindClass *klass);
|
2002-04-11 20:35:18 +00:00
|
|
|
static void gst_type_find_init (GstTypeFind *typefind);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2002-10-29 17:36:41 +00:00
|
|
|
static void gst_type_find_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gst_type_find_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
static void gst_type_find_chain (GstPad *pad, GstBuffer *buf);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-04-11 20:35:18 +00:00
|
|
|
static guint gst_type_find_signals[LAST_SIGNAL] = { 0 };
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
GType
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_get_type (void)
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType typefind_type = 0;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
if (!typefind_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static const GTypeInfo typefind_info = {
|
2001-01-19 00:02:53 +00:00
|
|
|
sizeof(GstTypeFindClass),
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-04-11 20:35:18 +00:00
|
|
|
(GClassInitFunc)gst_type_find_class_init,
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstTypeFind),
|
|
|
|
0,
|
2002-04-11 20:35:18 +00:00
|
|
|
(GInstanceInitFunc)gst_type_find_init,
|
2001-09-14 22:16:47 +00:00
|
|
|
NULL
|
2001-01-19 00:02:53 +00:00
|
|
|
};
|
2001-06-25 01:20:11 +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
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_class_init (GstTypeFindClass *klass)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class = (GObjectClass*)klass;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +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
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_signals[HAVE_TYPE] =
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_new ("have_type", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
|
2001-06-25 01:20:11 +00:00
|
|
|
G_STRUCT_OFFSET (GstTypeFindClass, have_type), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_type_find_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_get_property);
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_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);
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_pad_set_chain_function (typefind->sinkpad, gst_type_find_chain);
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
2002-10-29 17:36:41 +00:00
|
|
|
gst_type_find_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
g_return_if_fail (GST_IS_TYPE_FIND (object));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
typefind = GST_TYPE_FIND (object);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +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
|
2002-10-29 17:36:41 +00:00
|
|
|
gst_type_find_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
g_return_if_fail (GST_IS_TYPE_FIND (object));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
typefind = GST_TYPE_FIND (object);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-01-19 00:02:53 +00:00
|
|
|
case ARG_CAPS:
|
2001-06-25 01:20:11 +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
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_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);
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
typefind = GST_TYPE_FIND (GST_OBJECT_PARENT (pad));
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"got buffer of %d bytes in '%s'",
|
2001-01-29 00:06:02 +00:00
|
|
|
GST_BUFFER_SIZE (buf), GST_OBJECT_NAME (typefind));
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2002-04-19 19:49:41 +00:00
|
|
|
type_list = (GList *) gst_type_get_list ();
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
while (type_list) {
|
2001-08-21 20:16:48 +00:00
|
|
|
GSList *factories;
|
2002-10-29 17:36:41 +00:00
|
|
|
type = (GstType *) type_list->data;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
factories = type->factories;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
while (factories) {
|
2002-04-11 20:35:18 +00:00
|
|
|
GstTypeFactory *factory = GST_TYPE_FACTORY (factories->data);
|
2001-08-21 20:16:48 +00:00
|
|
|
GstTypeFindFunc typefindfunc = (GstTypeFindFunc)factory->typefindfunc;
|
2001-01-19 00:02:53 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2002-10-29 17:36:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_TYPES, "try type (%p) :%d \"%s\" %p",
|
|
|
|
factory, type->id, type->mime, typefindfunc);
|
2001-08-21 20:16:48 +00:00
|
|
|
if (typefindfunc && (caps = typefindfunc (buf, factory))) {
|
2002-10-29 17:36:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_TYPES, "found type: %d \"%s\" \"%s\"",
|
|
|
|
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
|
|
|
|
2002-09-10 08:52:58 +00:00
|
|
|
if (gst_pad_try_set_caps (pad, caps) <= 0) {
|
2002-01-13 22:22:42 +00:00
|
|
|
g_warning ("typefind: found type but peer didn't accept it");
|
|
|
|
}
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-22 23:19:17 +00:00
|
|
|
{
|
2002-03-05 08:28:22 +00:00
|
|
|
/* int oldstate = GST_STATE(typefind);*/
|
2001-12-22 23:19:17 +00:00
|
|
|
gst_object_ref (GST_OBJECT (typefind));
|
2002-04-11 20:35:18 +00:00
|
|
|
g_signal_emit (G_OBJECT (typefind), gst_type_find_signals[HAVE_TYPE], 0,
|
2001-01-19 00:02:53 +00:00
|
|
|
typefind->caps);
|
2002-02-18 00:40:56 +00:00
|
|
|
/* if (GST_STATE(typefind) != oldstate) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(0, "state changed during signal, aborting");
|
2001-12-24 15:14:03 +00:00
|
|
|
gst_element_interrupt (GST_ELEMENT (typefind));
|
2002-02-18 00:40:56 +00:00
|
|
|
} */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (typefind));
|
|
|
|
|
2001-12-22 23:19:17 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
2001-08-21 20:16:48 +00:00
|
|
|
factories = g_slist_next (factories);
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type_list = g_list_next (type_list);
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|