2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include "gst_private.h"
29 #include "gsttypefind.h"
31 /* #define GST_DEBUG_ENABLED */
33 GstElementDetails gst_type_find_details = {
37 "Finds the media type of a stream",
39 "Erik Walthinsen <omega@cse.ogi.edu>,"
40 "Wim Taymans <wim.taymans@chello.be>",
45 /* TypeFind signals and args */
57 static void gst_type_find_class_init (GstTypeFindClass *klass);
58 static void gst_type_find_init (GstTypeFind *typefind);
60 static void gst_type_find_set_property (GObject *object, guint prop_id,
63 static void gst_type_find_get_property (GObject *object, guint prop_id,
67 static void gst_type_find_chain (GstPad *pad, GstBuffer *buf);
69 static GstElementClass *parent_class = NULL;
70 static guint gst_type_find_signals[LAST_SIGNAL] = { 0 };
73 gst_type_find_get_type (void)
75 static GType typefind_type = 0;
78 static const GTypeInfo typefind_info = {
79 sizeof(GstTypeFindClass),
82 (GClassInitFunc)gst_type_find_class_init,
87 (GInstanceInitFunc)gst_type_find_init,
90 typefind_type = g_type_register_static (GST_TYPE_ELEMENT, "GstTypeFind", &typefind_info, 0);
96 gst_type_find_class_init (GstTypeFindClass *klass)
98 GObjectClass *gobject_class;
100 gobject_class = (GObjectClass*)klass;
102 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
104 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CAPS,
105 g_param_spec_pointer("caps", "Caps", "Found capabilities", G_PARAM_READABLE));
107 gst_type_find_signals[HAVE_TYPE] =
108 g_signal_new ("have_type", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
109 G_STRUCT_OFFSET (GstTypeFindClass, have_type), NULL, NULL,
110 g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
113 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_type_find_set_property);
114 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_get_property);
118 gst_type_find_init (GstTypeFind *typefind)
120 typefind->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
121 gst_element_add_pad (GST_ELEMENT (typefind), typefind->sinkpad);
122 gst_pad_set_chain_function (typefind->sinkpad, gst_type_find_chain);
126 gst_type_find_set_property (GObject *object, guint prop_id,
127 const GValue *value, GParamSpec *pspec)
129 GstTypeFind *typefind;
131 g_return_if_fail (GST_IS_TYPE_FIND (object));
133 typefind = GST_TYPE_FIND (object);
142 gst_type_find_get_property (GObject *object, guint prop_id,
143 GValue *value, GParamSpec *pspec)
145 GstTypeFind *typefind;
147 g_return_if_fail (GST_IS_TYPE_FIND (object));
149 typefind = GST_TYPE_FIND (object);
153 g_value_set_pointer(value, typefind->caps);
161 gst_type_find_chain (GstPad *pad, GstBuffer *buf)
163 GstTypeFind *typefind;
167 g_return_if_fail (pad != NULL);
168 g_return_if_fail (GST_IS_PAD (pad));
169 g_return_if_fail (buf != NULL);
171 typefind = GST_TYPE_FIND (GST_OBJECT_PARENT (pad));
172 GST_DEBUG (0,"got buffer of %d bytes in '%s'",
173 GST_BUFFER_SIZE (buf), GST_OBJECT_NAME (typefind));
175 type_list = (GList *) gst_type_get_list ();
179 type = (GstType *) type_list->data;
181 factories = type->factories;
184 GstTypeFactory *factory = GST_TYPE_FACTORY (factories->data);
185 GstTypeFindFunc typefindfunc = (GstTypeFindFunc)factory->typefindfunc;
188 GST_DEBUG (GST_CAT_TYPES, "try type (%p) :%d \"%s\" %p",
189 factory, type->id, type->mime, typefindfunc);
190 if (typefindfunc && (caps = typefindfunc (buf, factory))) {
191 GST_DEBUG (GST_CAT_TYPES, "found type: %d \"%s\" \"%s\"",
192 caps->id, type->mime, gst_caps_get_name (caps));
193 typefind->caps = caps;
195 if (gst_pad_try_set_caps (pad, caps) <= 0) {
196 g_warning ("typefind: found type but peer didn't accept it");
200 /* int oldstate = GST_STATE(typefind);*/
201 gst_object_ref (GST_OBJECT (typefind));
202 g_signal_emit (G_OBJECT (typefind), gst_type_find_signals[HAVE_TYPE], 0,
204 /* if (GST_STATE(typefind) != oldstate) {
205 GST_DEBUG(0, "state changed during signal, aborting");
206 gst_element_interrupt (GST_ELEMENT (typefind));
208 gst_object_unref (GST_OBJECT (typefind));
213 factories = g_slist_next (factories);
216 type_list = g_list_next (type_list);
219 gst_buffer_unref (buf);