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"
28 #include "gsttypefind.h"
30 //#define GST_DEBUG_ENABLED
32 GstElementDetails gst_typefind_details = {
35 "Finds the media type",
37 "Erik Walthinsen <omega@cse.ogi.edu>"
38 "Wim Taymans <wim.taymans@chello.be>",
43 /* TypeFind signals and args */
55 static void gst_typefind_class_init (GstTypeFindClass *klass);
56 static void gst_typefind_init (GstTypeFind *typefind);
58 static void gst_typefind_set_property (GObject *object, guint prop_id,
59 const GValue *value, GParamSpec *pspec);
60 static void gst_typefind_get_property (GObject *object, guint prop_id,
61 GValue *value, GParamSpec *pspec);
63 static void gst_typefind_chain (GstPad *pad, GstBuffer *buf);
65 static GstElementClass *parent_class = NULL;
66 static guint gst_typefind_signals[LAST_SIGNAL] = { 0 };
69 gst_typefind_get_type (void)
71 static GType typefind_type = 0;
74 static const GTypeInfo typefind_info = {
75 sizeof(GstTypeFindClass),
78 (GClassInitFunc)gst_typefind_class_init,
83 (GInstanceInitFunc)gst_typefind_init,
85 typefind_type = g_type_register_static (GST_TYPE_ELEMENT, "GstTypeFind", &typefind_info, 0);
91 gst_typefind_class_init (GstTypeFindClass *klass)
93 GObjectClass *gobject_class;
95 gobject_class = (GObjectClass*)klass;
97 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
99 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CAPS,
100 g_param_spec_pointer("caps", "Caps", "Found capabilities", G_PARAM_READABLE));
102 gst_typefind_signals[HAVE_TYPE] =
103 g_signal_new ("have_type", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
104 G_STRUCT_OFFSET (GstTypeFindClass, have_type), NULL, NULL,
105 g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
108 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_typefind_set_property);
109 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_typefind_get_property);
113 gst_typefind_init (GstTypeFind *typefind)
115 typefind->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
116 gst_element_add_pad (GST_ELEMENT (typefind), typefind->sinkpad);
117 gst_pad_set_chain_function (typefind->sinkpad, gst_typefind_chain);
121 gst_typefind_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
123 GstTypeFind *typefind;
125 /* it's not null if we got it, but it might not be ours */
126 g_return_if_fail (GST_IS_TYPEFIND (object));
128 typefind = GST_TYPEFIND (object);
137 gst_typefind_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
139 GstTypeFind *typefind;
141 /* it's not null if we got it, but it might not be ours */
142 g_return_if_fail (GST_IS_TYPEFIND (object));
144 typefind = GST_TYPEFIND (object);
148 g_value_set_pointer(value, typefind->caps);
156 gst_typefind_chain (GstPad *pad, GstBuffer *buf)
158 GstTypeFind *typefind;
162 g_return_if_fail (pad != NULL);
163 g_return_if_fail (GST_IS_PAD (pad));
164 g_return_if_fail (buf != NULL);
166 typefind = GST_TYPEFIND (GST_OBJECT_PARENT (pad));
167 GST_DEBUG (0,"got buffer of %d bytes in '%s'\n",
168 GST_BUFFER_SIZE (buf), GST_OBJECT_NAME (typefind));
170 type_list = gst_type_get_list ();
174 type = (GstType *)type_list->data;
176 factories = type->factories;
179 GstTypeFactory *factory = GST_TYPEFACTORY (factories->data);
180 GstTypeFindFunc typefindfunc = (GstTypeFindFunc)factory->typefindfunc;
183 GST_DEBUG (0,"try type :%d \"%s\"\n", type->id, type->mime);
184 if (typefindfunc && (caps = typefindfunc (buf, factory))) {
185 GST_DEBUG (0,"found type :%d \"%s\" \"%s\"\n", caps->id, type->mime,
186 gst_caps_get_name (caps));
187 typefind->caps = caps;
189 gst_pad_set_caps (pad, caps);
191 { /* FIXME: this should all be in an _emit() wrapper eventually */
192 int oldstate = GST_STATE(typefind);
193 gst_object_ref (GST_OBJECT (typefind));
194 g_signal_emit (G_OBJECT (typefind), gst_typefind_signals[HAVE_TYPE], 0,
196 if (GST_STATE(typefind) != oldstate) {
197 gst_object_unref (GST_OBJECT (typefind));
198 GST_DEBUG(0, "state changed during signal, aborting\n");
199 cothread_switch(cothread_current_main());
201 gst_object_unref (GST_OBJECT (typefind));
206 factories = g_slist_next (factories);
209 type_list = g_list_next (type_list);
212 gst_buffer_unref (buf);